forked from comunica/comunica
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab39568
commit 945c504
Showing
18 changed files
with
230 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/expression-evaluator/lib/functions/NamedExtension.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// TODO: this thing will be it's own actor but it's just a little special. | ||
// It will also be the only consumer of the context items: | ||
// KeysInitQuery.extensionFunctions and KeysInitQuery.extensionFunctionCreator | ||
import type { IEvalContext } from '@comunica/types'; | ||
import type { AsyncExtensionFunction } from '../evaluators/ContextualizedEvaluator'; | ||
import type * as E from '../expressions'; | ||
import { ExtensionFunctionError } from '../util/Errors'; | ||
import { FunctionDefinition } from './Core'; | ||
|
||
export class NamedExtension extends FunctionDefinition { | ||
// TODO: the context should be checked in the test part of the actor. | ||
// The fact that this can be done is async now is a nice feature! | ||
// It means that named function definitions could be queried over the web! | ||
// TODO: when all is done, this should be injected in some way! | ||
protected arity = Number.POSITIVE_INFINITY; | ||
public constructor(private readonly name: string, private readonly functionDefinition: AsyncExtensionFunction) { | ||
super(); | ||
} | ||
|
||
public apply = async({ args, exprEval, mapping }: IEvalContext): Promise<E.TermExpression> => { | ||
const evaluatedArgs: E.Term[] = await Promise.all(args.map(arg => exprEval.evaluateAsInternal(arg, mapping))); | ||
try { | ||
return exprEval.transformer.transformRDFTermUnsafe( | ||
await this.functionDefinition(evaluatedArgs.map(term => term.toRDF())), | ||
); | ||
} catch (error: unknown) { | ||
throw new ExtensionFunctionError(this.name, error); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.