@comunica/bus-query-operation 3.3.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
- import type { BindingsFactory } from '@comunica/bindings-factory';
2
1
  import type { IActorArgs, IActorTest, IAction, Mediate } from '@comunica/core';
3
2
  import { Actor } from '@comunica/core';
4
- import type { IQueryOperationResult, IQueryOperationResultBindings, IQueryOperationResultBoolean, IQueryOperationResultQuads, IQueryOperationResultVoid, Bindings, IActionContext, FunctionArgumentsCache, IQuerySourceWrapper, FragmentSelectorShape } from '@comunica/types';
3
+ import type { IQueryOperationResult, Bindings, IActionContext, FunctionArgumentsCache } from '@comunica/types';
5
4
  import type * as RDF from '@rdfjs/types';
6
5
  import type { Algebra } from 'sparqlalgebrajs';
7
6
  /**
@@ -15,102 +14,13 @@ import type { Algebra } from 'sparqlalgebrajs';
15
14
  * @see IActionQueryOperation
16
15
  * @see IQueryOperationResult
17
16
  */
18
- export declare abstract class ActorQueryOperation extends Actor<IActionQueryOperation, IActorTest, IQueryOperationResult> {
17
+ export declare abstract class ActorQueryOperation<TS = undefined> extends Actor<IActionQueryOperation, IActorTest, IQueryOperationResult, TS> {
19
18
  /**
20
- * @param args - @defaultNested {<default_bus> a <cbqo:components/BusQueryOperation.jsonld#BusQueryOperation>} bus
19
+ * @param args -
20
+ * \ @defaultNested {<default_bus> a <cbqo:components/BusQueryOperation.jsonld#BusQueryOperation>} bus
21
+ * \ @defaultNested {Query operation processing failed: none of the configured actors were able to handle the operation type ${action.operation.type}} busFailMessage
21
22
  */
22
- protected constructor(args: IActorQueryOperationArgs);
23
- /**
24
- * Safely cast a query operation output to a bindings output.
25
- * This will throw a runtime error if the output is of the incorrect type.
26
- * @param {IQueryOperationResult} output A query operation output.
27
- * @return {IQueryOperationResultBindings} A bindings query operation output.
28
- */
29
- static getSafeBindings(output: IQueryOperationResult): IQueryOperationResultBindings;
30
- /**
31
- * Safely cast a query operation output to a quads output.
32
- * This will throw a runtime error if the output is of the incorrect type.
33
- * @param {IQueryOperationResult} output A query operation output.
34
- * @return {IQueryOperationResultQuads} A quads query operation output.
35
- */
36
- static getSafeQuads(output: IQueryOperationResult): IQueryOperationResultQuads;
37
- /**
38
- * Safely cast a query operation output to a boolean output.
39
- * This will throw a runtime error if the output is of the incorrect type.
40
- * @param {IQueryOperationResult} output A query operation output.
41
- * @return {IQueryOperationResultBoolean} A boolean query operation output.
42
- */
43
- static getSafeBoolean(output: IQueryOperationResult): IQueryOperationResultBoolean;
44
- /**
45
- * Safely cast a query operation output to a void output.
46
- * This will throw a runtime error if the output is of the incorrect type.
47
- * @param {IQueryOperationResult} output A query operation output.
48
- * @return {IQueryOperationResultVoid} A void query operation output.
49
- */
50
- static getSafeVoid(output: IQueryOperationResult): IQueryOperationResultVoid;
51
- /**
52
- * Throw an error if the output type does not match the expected type.
53
- * @param {IQueryOperationResult} output A query operation output.
54
- * @param {string} expectedType The expected output type.
55
- */
56
- static validateQueryOutput(output: IQueryOperationResult, expectedType: IQueryOperationResult['type']): void;
57
- protected static getBaseExpressionContext(context: IActionContext): IBaseExpressionContext;
58
- /**
59
- * Create an options object that can be used to construct a expression-evaluator synchronous evaluator.
60
- * @param context An action context.
61
- * @param _mediatorQueryOperation An optional query query operation mediator.
62
- * If defined, the existence resolver will be defined as `exists`.
63
- */
64
- static getExpressionContext(context: IActionContext, _mediatorQueryOperation?: MediatorQueryOperation): ISyncExpressionContext;
65
- /**
66
- * Create an options object that can be used to construct a expression-evaluator asynchronous evaluator.
67
- * @param context An action context.
68
- * @param mediatorQueryOperation A query query operation mediator for resolving `exists`.
69
- * @param bindingsFactory The bindings factory.
70
- */
71
- static getAsyncExpressionContext(context: IActionContext, mediatorQueryOperation: MediatorQueryOperation, bindingsFactory: BindingsFactory): IAsyncExpressionContext;
72
- /**
73
- * Create an existence resolver for usage within an expression context.
74
- * @param context An action context.
75
- * @param mediatorQueryOperation A query operation mediator.
76
- * @param bindingsFactory The bindings factory.
77
- */
78
- static createExistenceResolver(context: IActionContext, mediatorQueryOperation: MediatorQueryOperation, bindingsFactory: BindingsFactory): (expr: Algebra.ExistenceExpression, bindings: Bindings) => Promise<boolean>;
79
- /**
80
- * Throw an error if the context contains the readOnly flag.
81
- * @param context An action context.
82
- */
83
- static throwOnReadOnly(context: IActionContext): void;
84
- /**
85
- * Obtain the query source attached to the given operation.
86
- * @param operation An algebra operation.
87
- */
88
- static getOperationSource(operation: Algebra.Operation): IQuerySourceWrapper | undefined;
89
- /**
90
- * Assign a source wrapper to the given operation.
91
- * The operation is copied and returned.
92
- * @param operation An operation.
93
- * @param source A source wrapper.
94
- */
95
- static assignOperationSource<O extends Algebra.Operation>(operation: O, source: IQuerySourceWrapper): O;
96
- /**
97
- * Remove the source wrapper from the given operation.
98
- * The operation is mutated.
99
- * @param operation An operation.
100
- */
101
- static removeOperationSource(operation: Algebra.Operation): void;
102
- /**
103
- * Check if the given shape accepts the given query operation.
104
- * @param shape A shape to test the query operation against.
105
- * @param operation A query operation to test.
106
- * @param options Additional options to consider.
107
- * @param options.joinBindings If additional bindings will be pushed down to the source for joining.
108
- * @param options.filterBindings If additional bindings will be pushed down to the source for filtering.
109
- */
110
- static doesShapeAcceptOperation(shape: FragmentSelectorShape, operation: Algebra.Operation, options?: {
111
- joinBindings?: boolean;
112
- filterBindings?: boolean;
113
- }): boolean;
23
+ protected constructor(args: IActorQueryOperationArgs<TS>);
114
24
  }
115
25
  export interface IActionQueryOperation extends IAction {
116
26
  /**
@@ -118,13 +28,14 @@ export interface IActionQueryOperation extends IAction {
118
28
  */
119
29
  operation: Algebra.Operation;
120
30
  }
121
- export type IActorQueryOperationArgs = IActorArgs<IActionQueryOperation, IActorTest, IQueryOperationResult>;
31
+ export type IActorQueryOperationArgs<TS = undefined> = IActorArgs<IActionQueryOperation, IActorTest, IQueryOperationResult, TS>;
122
32
  export type MediatorQueryOperation = Mediate<IActionQueryOperation, IQueryOperationResult>;
123
33
  export interface IBaseExpressionContext {
124
34
  now?: Date;
125
35
  baseIRI?: string;
126
36
  extensionFunctionCreator?: (functionNamedNode: RDF.NamedNode) => ((args: RDF.Term[]) => Promise<RDF.Term>) | undefined;
127
37
  functionArgumentsCache?: FunctionArgumentsCache;
38
+ actionContext: IActionContext;
128
39
  }
129
40
  export interface ISyncExpressionContext extends IBaseExpressionContext {
130
41
  bnode: (input?: string | undefined) => RDF.BlankNode;
@@ -133,3 +44,7 @@ export interface IAsyncExpressionContext extends IBaseExpressionContext {
133
44
  bnode: (input?: string | undefined) => Promise<RDF.BlankNode>;
134
45
  exists?: (expr: Algebra.ExistenceExpression, bindings: Bindings) => Promise<boolean>;
135
46
  }
47
+ export type FragmentSelectorShapeTestFlags = {
48
+ joinBindings?: boolean;
49
+ filterBindings?: boolean;
50
+ };
@@ -1,17 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActorQueryOperation = void 0;
4
- const context_entries_1 = require("@comunica/context-entries");
5
4
  const core_1 = require("@comunica/core");
6
- const data_factory_1 = require("@comunica/data-factory");
7
- const Bindings_1 = require("./Bindings");
8
- /**
9
- * A counter that keeps track blank node generated through BNODE() SPARQL
10
- * expressions.
11
- *
12
- * @type {number}
13
- */
14
- let bnodeCounter = 0;
15
5
  /**
16
6
  * A comunica actor for query-operation events.
17
7
  *
@@ -24,184 +14,16 @@ let bnodeCounter = 0;
24
14
  * @see IQueryOperationResult
25
15
  */
26
16
  class ActorQueryOperation extends core_1.Actor {
17
+ /* eslint-disable max-len */
27
18
  /**
28
- * @param args - @defaultNested {<default_bus> a <cbqo:components/BusQueryOperation.jsonld#BusQueryOperation>} bus
19
+ * @param args -
20
+ * \ @defaultNested {<default_bus> a <cbqo:components/BusQueryOperation.jsonld#BusQueryOperation>} bus
21
+ * \ @defaultNested {Query operation processing failed: none of the configured actors were able to handle the operation type ${action.operation.type}} busFailMessage
29
22
  */
23
+ /* eslint-enable max-len */
30
24
  constructor(args) {
31
25
  super(args);
32
26
  }
33
- /**
34
- * Safely cast a query operation output to a bindings output.
35
- * This will throw a runtime error if the output is of the incorrect type.
36
- * @param {IQueryOperationResult} output A query operation output.
37
- * @return {IQueryOperationResultBindings} A bindings query operation output.
38
- */
39
- static getSafeBindings(output) {
40
- ActorQueryOperation.validateQueryOutput(output, 'bindings');
41
- return output;
42
- }
43
- /**
44
- * Safely cast a query operation output to a quads output.
45
- * This will throw a runtime error if the output is of the incorrect type.
46
- * @param {IQueryOperationResult} output A query operation output.
47
- * @return {IQueryOperationResultQuads} A quads query operation output.
48
- */
49
- static getSafeQuads(output) {
50
- ActorQueryOperation.validateQueryOutput(output, 'quads');
51
- return output;
52
- }
53
- /**
54
- * Safely cast a query operation output to a boolean output.
55
- * This will throw a runtime error if the output is of the incorrect type.
56
- * @param {IQueryOperationResult} output A query operation output.
57
- * @return {IQueryOperationResultBoolean} A boolean query operation output.
58
- */
59
- static getSafeBoolean(output) {
60
- ActorQueryOperation.validateQueryOutput(output, 'boolean');
61
- return output;
62
- }
63
- /**
64
- * Safely cast a query operation output to a void output.
65
- * This will throw a runtime error if the output is of the incorrect type.
66
- * @param {IQueryOperationResult} output A query operation output.
67
- * @return {IQueryOperationResultVoid} A void query operation output.
68
- */
69
- static getSafeVoid(output) {
70
- ActorQueryOperation.validateQueryOutput(output, 'void');
71
- return output;
72
- }
73
- /**
74
- * Throw an error if the output type does not match the expected type.
75
- * @param {IQueryOperationResult} output A query operation output.
76
- * @param {string} expectedType The expected output type.
77
- */
78
- static validateQueryOutput(output, expectedType) {
79
- if (output.type !== expectedType) {
80
- throw new Error(`Invalid query output type: Expected '${expectedType}' but got '${output.type}'`);
81
- }
82
- }
83
- static getBaseExpressionContext(context) {
84
- const now = context.get(context_entries_1.KeysInitQuery.queryTimestamp);
85
- const baseIRI = context.get(context_entries_1.KeysInitQuery.baseIRI);
86
- const functionArgumentsCache = context.get(context_entries_1.KeysInitQuery.functionArgumentsCache) ?? {};
87
- // Handle two variants of providing extension functions
88
- if (context.has(context_entries_1.KeysInitQuery.extensionFunctionCreator) && context.has(context_entries_1.KeysInitQuery.extensionFunctions)) {
89
- throw new Error('Illegal simultaneous usage of extensionFunctionCreator and extensionFunctions in context');
90
- }
91
- let extensionFunctionCreator = context
92
- .get(context_entries_1.KeysInitQuery.extensionFunctionCreator);
93
- // Convert dictionary-based variant to callback
94
- const extensionFunctions = context
95
- .get(context_entries_1.KeysInitQuery.extensionFunctions);
96
- if (extensionFunctions) {
97
- extensionFunctionCreator = functionNamedNode => extensionFunctions[functionNamedNode.value];
98
- }
99
- return { now, baseIRI, extensionFunctionCreator, functionArgumentsCache };
100
- }
101
- /**
102
- * Create an options object that can be used to construct a expression-evaluator synchronous evaluator.
103
- * @param context An action context.
104
- * @param _mediatorQueryOperation An optional query query operation mediator.
105
- * If defined, the existence resolver will be defined as `exists`.
106
- */
107
- static getExpressionContext(context, _mediatorQueryOperation) {
108
- return {
109
- ...this.getBaseExpressionContext(context),
110
- bnode: (input) => new data_factory_1.BlankNodeBindingsScoped(input ?? `BNODE_${bnodeCounter++}`),
111
- };
112
- }
113
- /**
114
- * Create an options object that can be used to construct a expression-evaluator asynchronous evaluator.
115
- * @param context An action context.
116
- * @param mediatorQueryOperation A query query operation mediator for resolving `exists`.
117
- * @param bindingsFactory The bindings factory.
118
- */
119
- static getAsyncExpressionContext(context, mediatorQueryOperation, bindingsFactory) {
120
- return {
121
- ...this.getBaseExpressionContext(context),
122
- bnode: (input) => Promise.resolve(new data_factory_1.BlankNodeBindingsScoped(input ?? `BNODE_${bnodeCounter++}`)),
123
- exists: ActorQueryOperation.createExistenceResolver(context, mediatorQueryOperation, bindingsFactory),
124
- };
125
- }
126
- /**
127
- * Create an existence resolver for usage within an expression context.
128
- * @param context An action context.
129
- * @param mediatorQueryOperation A query operation mediator.
130
- * @param bindingsFactory The bindings factory.
131
- */
132
- static createExistenceResolver(context, mediatorQueryOperation, bindingsFactory) {
133
- return async (expr, bindings) => {
134
- const operation = (0, Bindings_1.materializeOperation)(expr.input, bindings, bindingsFactory);
135
- const outputRaw = await mediatorQueryOperation.mediate({ operation, context });
136
- const output = ActorQueryOperation.getSafeBindings(outputRaw);
137
- return expr.not !== ((await output.bindingsStream.take(1).toArray()).length === 1);
138
- };
139
- }
140
- /**
141
- * Throw an error if the context contains the readOnly flag.
142
- * @param context An action context.
143
- */
144
- static throwOnReadOnly(context) {
145
- if (context.get(context_entries_1.KeysQueryOperation.readOnly)) {
146
- throw new Error(`Attempted a write operation in read-only mode`);
147
- }
148
- }
149
- /**
150
- * Obtain the query source attached to the given operation.
151
- * @param operation An algebra operation.
152
- */
153
- static getOperationSource(operation) {
154
- return operation.metadata?.scopedSource;
155
- }
156
- /**
157
- * Assign a source wrapper to the given operation.
158
- * The operation is copied and returned.
159
- * @param operation An operation.
160
- * @param source A source wrapper.
161
- */
162
- static assignOperationSource(operation, source) {
163
- operation = { ...operation };
164
- operation.metadata = operation.metadata ? { ...operation.metadata } : {};
165
- operation.metadata.scopedSource = source;
166
- return operation;
167
- }
168
- /**
169
- * Remove the source wrapper from the given operation.
170
- * The operation is mutated.
171
- * @param operation An operation.
172
- */
173
- static removeOperationSource(operation) {
174
- delete operation.metadata?.scopedSource;
175
- if (operation.metadata && Object.keys(operation.metadata).length === 0) {
176
- delete operation.metadata;
177
- }
178
- }
179
- /**
180
- * Check if the given shape accepts the given query operation.
181
- * @param shape A shape to test the query operation against.
182
- * @param operation A query operation to test.
183
- * @param options Additional options to consider.
184
- * @param options.joinBindings If additional bindings will be pushed down to the source for joining.
185
- * @param options.filterBindings If additional bindings will be pushed down to the source for filtering.
186
- */
187
- static doesShapeAcceptOperation(shape, operation, options) {
188
- if (shape.type === 'conjunction') {
189
- return shape.children.every(child => ActorQueryOperation.doesShapeAcceptOperation(child, operation, options));
190
- }
191
- if (shape.type === 'disjunction') {
192
- return shape.children.some(child => ActorQueryOperation.doesShapeAcceptOperation(child, operation, options));
193
- }
194
- if (shape.type === 'arity') {
195
- return ActorQueryOperation.doesShapeAcceptOperation(shape.child, operation, options);
196
- }
197
- if ((options?.joinBindings && !shape.joinBindings) ?? (options?.filterBindings && !shape.filterBindings)) {
198
- return false;
199
- }
200
- if (shape.operation.operationType === 'type') {
201
- return shape.operation.type === 'project' || shape.operation.type === operation.type;
202
- }
203
- return shape.operation.pattern.type === operation.type;
204
- }
205
27
  }
206
28
  exports.ActorQueryOperation = ActorQueryOperation;
207
29
  //# sourceMappingURL=ActorQueryOperation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ActorQueryOperation.js","sourceRoot":"","sources":["ActorQueryOperation.ts"],"names":[],"mappings":";;;AACA,+DAA8E;AAE9E,yCAAuC;AACvC,yDAAiE;AAejE,yCAAkD;AAElD;;;;;GAKG;AACH,IAAI,YAAY,GAAG,CAAC,CAAC;AAErB;;;;;;;;;;GAUG;AACH,MAAsB,mBAAoB,SAAQ,YAA+D;IAC/G;;OAEG;IACH,YAAsB,IAA8B;QAClD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,eAAe,CAAC,MAA6B;QACzD,mBAAmB,CAAC,mBAAmB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAC5D,OAAuC,MAAM,CAAC;IAChD,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,YAAY,CAAC,MAA6B;QACtD,mBAAmB,CAAC,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACzD,OAAoC,MAAM,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAAC,MAA6B;QACxD,mBAAmB,CAAC,mBAAmB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAC3D,OAAsC,MAAM,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,MAA6B;QACrD,mBAAmB,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD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H,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAAC,wBAAwB,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;QAC/G,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC3B,OAAO,mBAAmB,CAAC,wBAAwB,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACvF,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,YAAY,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;YACzG,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,KAAK,CAAC,SAAS,CAAC,aAAa,KAAK,MAAM,EAAE,CAAC;YAC7C,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC;QACvF,CAAC;QACD,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC;IACzD,CAAC;CACF;AAzND,kDAyNC","sourcesContent":["import type { BindingsFactory } from '@comunica/bindings-factory';\nimport { KeysInitQuery, KeysQueryOperation } from '@comunica/context-entries';\nimport type { IActorArgs, IActorTest, IAction, Mediate } from '@comunica/core';\nimport { Actor } from '@comunica/core';\nimport { BlankNodeBindingsScoped } from '@comunica/data-factory';\nimport type {\n IQueryOperationResult,\n IQueryOperationResultBindings,\n IQueryOperationResultBoolean,\n IQueryOperationResultQuads,\n IQueryOperationResultVoid,\n Bindings,\n IActionContext,\n FunctionArgumentsCache,\n IQuerySourceWrapper,\n FragmentSelectorShape,\n} from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { Algebra } from 'sparqlalgebrajs';\nimport { materializeOperation } from './Bindings';\n\n/**\n * A counter that keeps track blank node generated through BNODE() SPARQL\n * expressions.\n *\n * @type {number}\n */\nlet bnodeCounter = 0;\n\n/**\n * A comunica actor for query-operation events.\n *\n * Actor types:\n * * Input: IActionQueryOperation: A SPARQL Algebra operation.\n * * Test: <none>\n * * Output: IActorQueryOperationOutput: A bindings stream.\n *\n * @see IActionQueryOperation\n * @see IQueryOperationResult\n */\nexport abstract class ActorQueryOperation extends Actor<IActionQueryOperation, IActorTest, IQueryOperationResult> {\n /**\n * @param args - @defaultNested {<default_bus> a <cbqo:components/BusQueryOperation.jsonld#BusQueryOperation>} bus\n */\n protected constructor(args: IActorQueryOperationArgs) {\n super(args);\n }\n\n /**\n * Safely cast a query operation output to a bindings output.\n * This will throw a runtime error if the output is of the incorrect type.\n * @param {IQueryOperationResult} output A query operation output.\n * @return {IQueryOperationResultBindings} A bindings query operation output.\n */\n public static getSafeBindings(output: IQueryOperationResult): IQueryOperationResultBindings {\n ActorQueryOperation.validateQueryOutput(output, 'bindings');\n return <IQueryOperationResultBindings> output;\n }\n\n /**\n * Safely cast a query operation output to a quads output.\n * This will throw a runtime error if the output is of the incorrect type.\n * @param {IQueryOperationResult} output A query operation output.\n * @return {IQueryOperationResultQuads} A quads query operation output.\n */\n public static getSafeQuads(output: IQueryOperationResult): IQueryOperationResultQuads {\n ActorQueryOperation.validateQueryOutput(output, 'quads');\n return <IQueryOperationResultQuads> output;\n }\n\n /**\n * Safely cast a query operation output to a boolean output.\n * This will throw a runtime error if the output is of the incorrect type.\n * @param {IQueryOperationResult} output A query operation output.\n * @return {IQueryOperationResultBoolean} A boolean query operation output.\n */\n public static getSafeBoolean(output: IQueryOperationResult): IQueryOperationResultBoolean {\n ActorQueryOperation.validateQueryOutput(output, 'boolean');\n return <IQueryOperationResultBoolean> output;\n }\n\n /**\n * Safely cast a query operation output to a void output.\n * This will throw a runtime error if the output is of the incorrect type.\n * @param {IQueryOperationResult} output A query operation output.\n * @return {IQueryOperationResultVoid} A void query operation output.\n */\n public static getSafeVoid(output: IQueryOperationResult): IQueryOperationResultVoid {\n ActorQueryOperation.validateQueryOutput(output, 'void');\n return <IQueryOperationResultVoid> output;\n }\n\n /**\n * Throw an error if the output type does not match the expected type.\n * @param {IQueryOperationResult} output A query operation output.\n * @param {string} expectedType The expected output type.\n */\n public static validateQueryOutput(output: IQueryOperationResult, expectedType: IQueryOperationResult['type']): void {\n if (output.type !== expectedType) {\n throw new Error(`Invalid query output type: Expected '${expectedType}' but got '${output.type}'`);\n }\n }\n\n protected static getBaseExpressionContext(context: IActionContext): IBaseExpressionContext {\n const now: Date | undefined = context.get(KeysInitQuery.queryTimestamp);\n const baseIRI: string | undefined = context.get(KeysInitQuery.baseIRI);\n const functionArgumentsCache: FunctionArgumentsCache = context.get(KeysInitQuery.functionArgumentsCache) ?? {};\n\n // Handle two variants of providing extension functions\n if (context.has(KeysInitQuery.extensionFunctionCreator) && context.has(KeysInitQuery.extensionFunctions)) {\n throw new Error('Illegal simultaneous usage of extensionFunctionCreator and extensionFunctions in context');\n }\n let extensionFunctionCreator: ((functionNamedNode: RDF.NamedNode) =>\n ((args: RDF.Term[]) => Promise<RDF.Term>) | undefined) | undefined = context\n .get(KeysInitQuery.extensionFunctionCreator);\n // Convert dictionary-based variant to callback\n const extensionFunctions: (Record<string, (args: RDF.Term[]) => Promise<RDF.Term>>) | undefined = context\n .get(KeysInitQuery.extensionFunctions);\n if (extensionFunctions) {\n extensionFunctionCreator = functionNamedNode => extensionFunctions[functionNamedNode.value];\n }\n\n return { now, baseIRI, extensionFunctionCreator, functionArgumentsCache };\n }\n\n /**\n * Create an options object that can be used to construct a expression-evaluator synchronous evaluator.\n * @param context An action context.\n * @param _mediatorQueryOperation An optional query query operation mediator.\n * If defined, the existence resolver will be defined as `exists`.\n */\n public static getExpressionContext(context: IActionContext, _mediatorQueryOperation?: MediatorQueryOperation):\n ISyncExpressionContext {\n return {\n ...this.getBaseExpressionContext(context),\n bnode: (input?: string) => new BlankNodeBindingsScoped(input ?? `BNODE_${bnodeCounter++}`),\n };\n }\n\n /**\n * Create an options object that can be used to construct a expression-evaluator asynchronous evaluator.\n * @param context An action context.\n * @param mediatorQueryOperation A query query operation mediator for resolving `exists`.\n * @param bindingsFactory The bindings factory.\n */\n public static getAsyncExpressionContext(\n context: IActionContext,\n mediatorQueryOperation: MediatorQueryOperation,\n bindingsFactory: BindingsFactory,\n ):\n IAsyncExpressionContext {\n return {\n ...this.getBaseExpressionContext(context),\n bnode: (input?: string) => Promise.resolve(new BlankNodeBindingsScoped(input ?? `BNODE_${bnodeCounter++}`)),\n exists: ActorQueryOperation.createExistenceResolver(context, mediatorQueryOperation, bindingsFactory),\n };\n }\n\n /**\n * Create an existence resolver for usage within an expression context.\n * @param context An action context.\n * @param mediatorQueryOperation A query operation mediator.\n * @param bindingsFactory The bindings factory.\n */\n public static createExistenceResolver(\n context: IActionContext,\n mediatorQueryOperation: MediatorQueryOperation,\n bindingsFactory: BindingsFactory,\n ):\n (expr: Algebra.ExistenceExpression, bindings: Bindings) => Promise<boolean> {\n return async(expr, bindings) => {\n const operation = materializeOperation(expr.input, bindings, bindingsFactory);\n\n const outputRaw = await mediatorQueryOperation.mediate({ operation, context });\n const output = ActorQueryOperation.getSafeBindings(outputRaw);\n return expr.not !== ((await output.bindingsStream.take(1).toArray()).length === 1);\n };\n }\n\n /**\n * Throw an error if the context contains the readOnly flag.\n * @param context An action context.\n */\n public static throwOnReadOnly(context: IActionContext): void {\n if (context.get(KeysQueryOperation.readOnly)) {\n throw new Error(`Attempted a write operation in read-only mode`);\n }\n }\n\n /**\n * Obtain the query source attached to the given operation.\n * @param operation An algebra operation.\n */\n public static getOperationSource(operation: Algebra.Operation): IQuerySourceWrapper | undefined {\n return <IQuerySourceWrapper> operation.metadata?.scopedSource;\n }\n\n /**\n * Assign a source wrapper to the given operation.\n * The operation is copied and returned.\n * @param operation An operation.\n * @param source A source wrapper.\n */\n public static assignOperationSource<O extends Algebra.Operation>(operation: O, source: IQuerySourceWrapper): O {\n operation = { ...operation };\n operation.metadata = operation.metadata ? { ...operation.metadata } : {};\n operation.metadata.scopedSource = source;\n return operation;\n }\n\n /**\n * Remove the source wrapper from the given operation.\n * The operation is mutated.\n * @param operation An operation.\n */\n public static removeOperationSource(operation: Algebra.Operation): void {\n delete operation.metadata?.scopedSource;\n if (operation.metadata && Object.keys(operation.metadata).length === 0) {\n delete operation.metadata;\n }\n }\n\n /**\n * Check if the given shape accepts the given query operation.\n * @param shape A shape to test the query operation against.\n * @param operation A query operation to test.\n * @param options Additional options to consider.\n * @param options.joinBindings If additional bindings will be pushed down to the source for joining.\n * @param options.filterBindings If additional bindings will be pushed down to the source for filtering.\n */\n public static doesShapeAcceptOperation(\n shape: FragmentSelectorShape,\n operation: Algebra.Operation,\n options?: {\n joinBindings?: boolean;\n filterBindings?: boolean;\n },\n ): boolean {\n if (shape.type === 'conjunction') {\n return shape.children.every(child => ActorQueryOperation.doesShapeAcceptOperation(child, operation, options));\n }\n if (shape.type === 'disjunction') {\n return shape.children.some(child => ActorQueryOperation.doesShapeAcceptOperation(child, operation, options));\n }\n if (shape.type === 'arity') {\n return ActorQueryOperation.doesShapeAcceptOperation(shape.child, operation, options);\n }\n\n if ((options?.joinBindings && !shape.joinBindings) ?? (options?.filterBindings && !shape.filterBindings)) {\n return false;\n }\n\n if (shape.operation.operationType === 'type') {\n return shape.operation.type === 'project' || shape.operation.type === operation.type;\n }\n return shape.operation.pattern.type === operation.type;\n }\n}\n\nexport interface IActionQueryOperation extends IAction {\n /**\n * The query operation to handle.\n */\n operation: Algebra.Operation;\n}\n\nexport type IActorQueryOperationArgs = IActorArgs<IActionQueryOperation, IActorTest, IQueryOperationResult>;\n\nexport type MediatorQueryOperation = Mediate<IActionQueryOperation, IQueryOperationResult>;\n\nexport interface IBaseExpressionContext {\n now?: Date;\n baseIRI?: string;\n extensionFunctionCreator?: (functionNamedNode: RDF.NamedNode) =>\n ((args: RDF.Term[]) => Promise<RDF.Term>) | undefined;\n functionArgumentsCache?: FunctionArgumentsCache;\n}\n\nexport interface ISyncExpressionContext extends IBaseExpressionContext {\n bnode: (input?: string | undefined) => RDF.BlankNode;\n}\n\nexport interface IAsyncExpressionContext extends IBaseExpressionContext {\n bnode: (input?: string | undefined) => Promise<RDF.BlankNode>;\n exists?: (expr: Algebra.ExistenceExpression, bindings: Bindings) => Promise<boolean>;\n}\n"]}
1
+ {"version":3,"file":"ActorQueryOperation.js","sourceRoot":"","sources":["ActorQueryOperation.ts"],"names":[],"mappings":";;;AACA,yCAAuC;AAUvC;;;;;;;;;;GAUG;AACH,MAAsB,mBACpB,SAAQ,YAAmE;IAC3E,4BAA4B;IAC5B;;;;OAIG;IACH,2BAA2B;IAC3B,YAAsB,IAAkC;QACtD,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;CACF;AAZD,kDAYC","sourcesContent":["import type { IActorArgs, IActorTest, IAction, Mediate } from '@comunica/core';\nimport { Actor } from '@comunica/core';\nimport type {\n IQueryOperationResult,\n Bindings,\n IActionContext,\n FunctionArgumentsCache,\n} from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { Algebra } from 'sparqlalgebrajs';\n\n/**\n * A comunica actor for query-operation events.\n *\n * Actor types:\n * * Input: IActionQueryOperation: A SPARQL Algebra operation.\n * * Test: <none>\n * * Output: IActorQueryOperationOutput: A bindings stream.\n *\n * @see IActionQueryOperation\n * @see IQueryOperationResult\n */\nexport abstract class ActorQueryOperation<TS = undefined>\n extends Actor<IActionQueryOperation, IActorTest, IQueryOperationResult, TS> {\n /* eslint-disable max-len */\n /**\n * @param args -\n * \\ @defaultNested {<default_bus> a <cbqo:components/BusQueryOperation.jsonld#BusQueryOperation>} bus\n * \\ @defaultNested {Query operation processing failed: none of the configured actors were able to handle the operation type ${action.operation.type}} busFailMessage\n */\n /* eslint-enable max-len */\n protected constructor(args: IActorQueryOperationArgs<TS>) {\n super(args);\n }\n}\n\nexport interface IActionQueryOperation extends IAction {\n /**\n * The query operation to handle.\n */\n operation: Algebra.Operation;\n}\n\nexport type IActorQueryOperationArgs<TS = undefined> = IActorArgs<\n IActionQueryOperation,\nIActorTest,\nIQueryOperationResult,\nTS\n>;\n\nexport type MediatorQueryOperation = Mediate<IActionQueryOperation, IQueryOperationResult>;\n\nexport interface IBaseExpressionContext {\n now?: Date;\n baseIRI?: string;\n extensionFunctionCreator?: (functionNamedNode: RDF.NamedNode) =>\n ((args: RDF.Term[]) => Promise<RDF.Term>) | undefined;\n functionArgumentsCache?: FunctionArgumentsCache;\n actionContext: IActionContext;\n}\n\nexport interface ISyncExpressionContext extends IBaseExpressionContext {\n bnode: (input?: string | undefined) => RDF.BlankNode;\n}\n\nexport interface IAsyncExpressionContext extends IBaseExpressionContext {\n bnode: (input?: string | undefined) => Promise<RDF.BlankNode>;\n exists?: (expr: Algebra.ExistenceExpression, bindings: Bindings) => Promise<boolean>;\n}\n\nexport type FragmentSelectorShapeTestFlags = {\n joinBindings?: boolean;\n filterBindings?: boolean;\n};\n"]}
@@ -1,4 +1,4 @@
1
- import type { IActorTest } from '@comunica/core';
1
+ import type { IActorTest, TestResult } from '@comunica/core';
2
2
  import type { IQueryOperationResult, IActionContext } from '@comunica/types';
3
3
  import type { Algebra } from 'sparqlalgebrajs';
4
4
  import type { IActionQueryOperation, IActorQueryOperationArgs } from './ActorQueryOperation';
@@ -6,11 +6,11 @@ import { ActorQueryOperation } from './ActorQueryOperation';
6
6
  /**
7
7
  * A base implementation for query operation actors for a specific operation type.
8
8
  */
9
- export declare abstract class ActorQueryOperationTyped<O extends Algebra.Operation> extends ActorQueryOperation {
9
+ export declare abstract class ActorQueryOperationTyped<O extends Algebra.Operation, TS = undefined> extends ActorQueryOperation<TS> {
10
10
  readonly operationName: string;
11
- protected constructor(args: IActorQueryOperationArgs, operationName: string);
12
- test(action: IActionQueryOperation): Promise<IActorTest>;
13
- run(action: IActionQueryOperation): Promise<IQueryOperationResult>;
14
- protected abstract testOperation(operation: O, context: IActionContext): Promise<IActorTest>;
15
- protected abstract runOperation(operation: O, context: IActionContext): Promise<IQueryOperationResult>;
11
+ protected constructor(args: IActorQueryOperationArgs<TS>, operationName: string);
12
+ test(action: IActionQueryOperation): Promise<TestResult<IActorTest, TS>>;
13
+ run(action: IActionQueryOperation, sideData: TS): Promise<IQueryOperationResult>;
14
+ protected abstract testOperation(operation: O, context: IActionContext): Promise<TestResult<IActorTest, TS>>;
15
+ protected abstract runOperation(operation: O, context: IActionContext, sideData: TS): Promise<IQueryOperationResult>;
16
16
  }
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ActorQueryOperationTyped = void 0;
4
4
  const context_entries_1 = require("@comunica/context-entries");
5
- const metadata_1 = require("@comunica/metadata");
5
+ const core_1 = require("@comunica/core");
6
+ const utils_metadata_1 = require("@comunica/utils-metadata");
6
7
  const ActorQueryOperation_1 = require("./ActorQueryOperation");
7
8
  /**
8
9
  * A base implementation for query operation actors for a specific operation type.
@@ -16,15 +17,15 @@ class ActorQueryOperationTyped extends ActorQueryOperation_1.ActorQueryOperation
16
17
  }
17
18
  async test(action) {
18
19
  if (!action.operation) {
19
- throw new Error('Missing field \'operation\' in a query operation action.');
20
+ return (0, core_1.failTest)('Missing field \'operation\' in a query operation action.');
20
21
  }
21
22
  if (action.operation.type !== this.operationName) {
22
- throw new Error(`Actor ${this.name} only supports ${this.operationName} operations, but got ${action.operation.type}`);
23
+ return (0, core_1.failTest)(`Actor ${this.name} only supports ${this.operationName} operations, but got ${action.operation.type}`);
23
24
  }
24
25
  const operation = action.operation;
25
26
  return this.testOperation(operation, action.context);
26
27
  }
27
- async run(action) {
28
+ async run(action, sideData) {
28
29
  // Log to physical plan
29
30
  const physicalQueryPlanLogger = action.context
30
31
  .get(context_entries_1.KeysInitQuery.physicalQueryPlanLogger);
@@ -34,9 +35,9 @@ class ActorQueryOperationTyped extends ActorQueryOperation_1.ActorQueryOperation
34
35
  }
35
36
  const operation = action.operation;
36
37
  const subContext = action.context.set(context_entries_1.KeysQueryOperation.operation, operation);
37
- const output = await this.runOperation(operation, subContext);
38
+ const output = await this.runOperation(operation, subContext, sideData);
38
39
  if ('metadata' in output) {
39
- output.metadata = (0, metadata_1.cachifyMetadata)(output.metadata);
40
+ output.metadata = (0, utils_metadata_1.cachifyMetadata)(output.metadata);
40
41
  }
41
42
  return output;
42
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ActorQueryOperationTyped.js","sourceRoot":"","sources":["ActorQueryOperationTyped.ts"],"names":[],"mappings":";;;AAAA,+DAA8E;AAE9E,iDAAqD;AAUrD,+DAA4D;AAE5D;;GAEG;AACH,MAAsB,wBAAsD,SAAQ,yCAAmB;IAGrG,YAAsB,IAA8B,EAAE,aAAqB;QACzE,KAAK,CAAO,EAAE,GAAG,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAA6B;QAC7C,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAC9E,CAAC;QACD,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,kBAAkB,IAAI,CAAC,aAAa,wBACpE,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,MAAM,SAAS,GAAU,MAAM,CAAC,SAAS,CAAC;QAC1C,OAAO,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,MAA6B;QAC5C,uBAAuB;QACvB,MAAM,uBAAuB,GAAyC,MAAM,CAAC,OAAO;aACjF,GAAG,CAAC,+BAAa,CAAC,uBAAuB,CAAC,CAAC;QAC9C,IAAI,uBAAuB,EAAE,CAAC;YAC5B,uBAAuB,CAAC,YAAY,CAClC,MAAM,CAAC,SAAS,CAAC,IAAI,EACrB,SAAS,EACT,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,qBAAqB,CAAC,EACvD,IAAI,CAAC,IAAI,EACT,EAAE,CACH,CAAC;YACF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,qBAAqB,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC7F,CAAC;QAED,MAAM,SAAS,GAAU,MAAM,CAAC,SAAS,CAAC;QAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,oCAAkB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAC/E,MAAM,MAAM,GAA0B,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACrF,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;YACzB,MAAM,CAAC,QAAQ,GACb,IAAA,0BAAe,EAA8E,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CAMF;AApDD,4DAoDC","sourcesContent":["import { KeysInitQuery, KeysQueryOperation } from '@comunica/context-entries';\nimport type { IActorTest } from '@comunica/core';\nimport { cachifyMetadata } from '@comunica/metadata';\nimport type {\n IQueryOperationResult,\n IPhysicalQueryPlanLogger,\n IActionContext,\n IMetadata,\n} from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { Algebra } from 'sparqlalgebrajs';\nimport type { IActionQueryOperation, IActorQueryOperationArgs } from './ActorQueryOperation';\nimport { ActorQueryOperation } from './ActorQueryOperation';\n\n/**\n * A base implementation for query operation actors for a specific operation type.\n */\nexport abstract class ActorQueryOperationTyped<O extends Algebra.Operation> extends ActorQueryOperation {\n public readonly operationName: string;\n\n protected constructor(args: IActorQueryOperationArgs, operationName: string) {\n super(<any> { ...args, operationName });\n if (!this.operationName) {\n throw new Error('A valid \"operationName\" argument must be provided.');\n }\n }\n\n public async test(action: IActionQueryOperation): Promise<IActorTest> {\n if (!action.operation) {\n throw new Error('Missing field \\'operation\\' in a query operation action.');\n }\n if (action.operation.type !== this.operationName) {\n throw new Error(`Actor ${this.name} only supports ${this.operationName} operations, but got ${\n action.operation.type}`);\n }\n const operation: O = <O> action.operation;\n return this.testOperation(operation, action.context);\n }\n\n public async run(action: IActionQueryOperation): Promise<IQueryOperationResult> {\n // Log to physical plan\n const physicalQueryPlanLogger: IPhysicalQueryPlanLogger | undefined = action.context\n .get(KeysInitQuery.physicalQueryPlanLogger);\n if (physicalQueryPlanLogger) {\n physicalQueryPlanLogger.logOperation(\n action.operation.type,\n undefined,\n action.operation,\n action.context.get(KeysInitQuery.physicalQueryPlanNode),\n this.name,\n {},\n );\n action.context = action.context.set(KeysInitQuery.physicalQueryPlanNode, action.operation);\n }\n\n const operation: O = <O> action.operation;\n const subContext = action.context.set(KeysQueryOperation.operation, operation);\n const output: IQueryOperationResult = await this.runOperation(operation, subContext);\n if ('metadata' in output) {\n output.metadata = <any>\n cachifyMetadata<IMetadata<RDF.QuadTermName | RDF.Variable>, RDF.QuadTermName | RDF.Variable>(output.metadata);\n }\n return output;\n }\n\n protected abstract testOperation(operation: O, context: IActionContext): Promise<IActorTest>;\n\n protected abstract runOperation(operation: O, context: IActionContext):\n Promise<IQueryOperationResult>;\n}\n"]}
1
+ {"version":3,"file":"ActorQueryOperationTyped.js","sourceRoot":"","sources":["ActorQueryOperationTyped.ts"],"names":[],"mappings":";;;AAAA,+DAA8E;AAE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E,CACH,CAAC;YACF,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,+BAAa,CAAC,qBAAqB,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC7F,CAAC;QAED,MAAM,SAAS,GAAU,MAAM,CAAC,SAAS,CAAC;QAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,oCAAkB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAC/E,MAAM,MAAM,GAA0B,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC/F,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;YACzB,MAAM,CAAC,QAAQ,GACb,IAAA,gCAAe,EAA8E,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClH,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CAMF;AAvDD,4DAuDC","sourcesContent":["import { KeysInitQuery, KeysQueryOperation } from '@comunica/context-entries';\nimport type { IActorTest, TestResult } from '@comunica/core';\nimport { failTest } from '@comunica/core';\nimport type {\n IQueryOperationResult,\n IPhysicalQueryPlanLogger,\n IActionContext,\n IMetadata,\n} from '@comunica/types';\nimport { cachifyMetadata } from '@comunica/utils-metadata';\nimport type * as RDF from '@rdfjs/types';\nimport type { Algebra } from 'sparqlalgebrajs';\nimport type { IActionQueryOperation, IActorQueryOperationArgs } from './ActorQueryOperation';\nimport { ActorQueryOperation } from './ActorQueryOperation';\n\n/**\n * A base implementation for query operation actors for a specific operation type.\n */\nexport abstract class ActorQueryOperationTyped<\n O extends Algebra.Operation,\nTS = undefined,\n> extends ActorQueryOperation<TS> {\n public readonly operationName: string;\n\n protected constructor(args: IActorQueryOperationArgs<TS>, operationName: string) {\n super(<any> { ...args, operationName });\n if (!this.operationName) {\n throw new Error('A valid \"operationName\" argument must be provided.');\n }\n }\n\n public async test(action: IActionQueryOperation): Promise<TestResult<IActorTest, TS>> {\n if (!action.operation) {\n return failTest('Missing field \\'operation\\' in a query operation action.');\n }\n if (action.operation.type !== this.operationName) {\n return failTest(`Actor ${this.name} only supports ${this.operationName} operations, but got ${\n action.operation.type}`);\n }\n const operation: O = <O> action.operation;\n return this.testOperation(operation, action.context);\n }\n\n public async run(action: IActionQueryOperation, sideData: TS): Promise<IQueryOperationResult> {\n // Log to physical plan\n const physicalQueryPlanLogger: IPhysicalQueryPlanLogger | undefined = action.context\n .get(KeysInitQuery.physicalQueryPlanLogger);\n if (physicalQueryPlanLogger) {\n physicalQueryPlanLogger.logOperation(\n action.operation.type,\n undefined,\n action.operation,\n action.context.get(KeysInitQuery.physicalQueryPlanNode),\n this.name,\n {},\n );\n action.context = action.context.set(KeysInitQuery.physicalQueryPlanNode, action.operation);\n }\n\n const operation: O = <O> action.operation;\n const subContext = action.context.set(KeysQueryOperation.operation, operation);\n const output: IQueryOperationResult = await this.runOperation(operation, subContext, sideData);\n if ('metadata' in output) {\n output.metadata = <any>\n cachifyMetadata<IMetadata<RDF.QuadTermName | RDF.Variable>, RDF.QuadTermName | RDF.Variable>(output.metadata);\n }\n return output;\n }\n\n protected abstract testOperation(operation: O, context: IActionContext): Promise<TestResult<IActorTest, TS>>;\n\n protected abstract runOperation(operation: O, context: IActionContext, sideData: TS):\n Promise<IQueryOperationResult>;\n}\n"]}
@@ -4,10 +4,10 @@ import { ActorQueryOperationTyped } from './ActorQueryOperationTyped';
4
4
  /**
5
5
  * A base implementation for query operation actors for a specific operation type that have a query operation mediator.
6
6
  */
7
- export declare abstract class ActorQueryOperationTypedMediated<O extends Algebra.Operation> extends ActorQueryOperationTyped<O> implements IActorQueryOperationTypedMediatedArgs {
7
+ export declare abstract class ActorQueryOperationTypedMediated<O extends Algebra.Operation, TS = undefined> extends ActorQueryOperationTyped<O, TS> implements IActorQueryOperationTypedMediatedArgs<TS> {
8
8
  readonly mediatorQueryOperation: MediatorQueryOperation;
9
- constructor(args: IActorQueryOperationTypedMediatedArgs, operationName: string);
9
+ constructor(args: IActorQueryOperationTypedMediatedArgs<TS>, operationName: string);
10
10
  }
11
- export interface IActorQueryOperationTypedMediatedArgs extends IActorQueryOperationArgs {
11
+ export interface IActorQueryOperationTypedMediatedArgs<TS = undefined> extends IActorQueryOperationArgs<TS> {
12
12
  mediatorQueryOperation: MediatorQueryOperation;
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ActorQueryOperationTypedMediated.js","sourceRoot":"","sources":["ActorQueryOperationTypedMediated.ts"],"names":[],"mappings":";;;AAEA,yEAAsE;AAEtE;;GAEG;AACH,MAAsB,gCAA8D,SAAQ,mDAA2B;IAIrH,YAAmB,IAA2C,EAAE,aAAqB;QACnF,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC7B,CAAC;CACF;AAPD,4EAOC","sourcesContent":["import type { Algebra } from 'sparqlalgebrajs';\nimport type { IActorQueryOperationArgs, MediatorQueryOperation } from './ActorQueryOperation';\nimport { ActorQueryOperationTyped } from './ActorQueryOperationTyped';\n\n/**\n * A base implementation for query operation actors for a specific operation type that have a query operation mediator.\n */\nexport abstract class ActorQueryOperationTypedMediated<O extends Algebra.Operation> extends ActorQueryOperationTyped<O>\n implements IActorQueryOperationTypedMediatedArgs {\n public readonly mediatorQueryOperation: MediatorQueryOperation;\n\n public constructor(args: IActorQueryOperationTypedMediatedArgs, operationName: string) {\n super(args, operationName);\n }\n}\n\nexport interface IActorQueryOperationTypedMediatedArgs extends IActorQueryOperationArgs {\n mediatorQueryOperation: MediatorQueryOperation;\n}\n"]}
1
+ {"version":3,"file":"ActorQueryOperationTypedMediated.js","sourceRoot":"","sources":["ActorQueryOperationTypedMediated.ts"],"names":[],"mappings":";;;AAEA,yEAAsE;AAEtE;;GAEG;AACH,MAAsB,gCAGpB,SAAQ,mDAA+B;IAIvC,YAAmB,IAA+C,EAAE,aAAqB;QACvF,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC7B,CAAC;CACF;AAVD,4EAUC","sourcesContent":["import type { Algebra } from 'sparqlalgebrajs';\nimport type { IActorQueryOperationArgs, MediatorQueryOperation } from './ActorQueryOperation';\nimport { ActorQueryOperationTyped } from './ActorQueryOperationTyped';\n\n/**\n * A base implementation for query operation actors for a specific operation type that have a query operation mediator.\n */\nexport abstract class ActorQueryOperationTypedMediated<\n O extends Algebra.Operation,\nTS = undefined,\n> extends ActorQueryOperationTyped<O, TS>\n implements IActorQueryOperationTypedMediatedArgs<TS> {\n public readonly mediatorQueryOperation: MediatorQueryOperation;\n\n public constructor(args: IActorQueryOperationTypedMediatedArgs<TS>, operationName: string) {\n super(args, operationName);\n }\n}\n\nexport interface IActorQueryOperationTypedMediatedArgs<TS = undefined> extends IActorQueryOperationArgs<TS> {\n mediatorQueryOperation: MediatorQueryOperation;\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -1,7 +1,4 @@
1
1
  export * from './ActorQueryOperation';
2
2
  export * from './ActorQueryOperationTyped';
3
3
  export * from './ActorQueryOperationTypedMediated';
4
- export * from './Bindings';
5
4
  export * from './BusQueryOperation';
6
- export * from './ClosableIterator';
7
- export * from './ClosableTransformIterator';
package/lib/index.js CHANGED
@@ -17,8 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./ActorQueryOperation"), exports);
18
18
  __exportStar(require("./ActorQueryOperationTyped"), exports);
19
19
  __exportStar(require("./ActorQueryOperationTypedMediated"), exports);
20
- __exportStar(require("./Bindings"), exports);
21
20
  __exportStar(require("./BusQueryOperation"), exports);
22
- __exportStar(require("./ClosableIterator"), exports);
23
- __exportStar(require("./ClosableTransformIterator"), exports);
24
21
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,6DAA2C;AAC3C,qEAAmD;AACnD,6CAA2B;AAC3B,sDAAoC;AACpC,qDAAmC;AACnC,8DAA4C","sourcesContent":["export * from './ActorQueryOperation';\nexport * from './ActorQueryOperationTyped';\nexport * from './ActorQueryOperationTypedMediated';\nexport * from './Bindings';\nexport * from './BusQueryOperation';\nexport * from './ClosableIterator';\nexport * from './ClosableTransformIterator';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,6DAA2C;AAC3C,qEAAmD;AACnD,sDAAoC","sourcesContent":["export * from './ActorQueryOperation';\nexport * from './ActorQueryOperationTyped';\nexport * from './ActorQueryOperationTypedMediated';\nexport * from './BusQueryOperation';\n"]}
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@comunica/bus-query-operation",
3
- "version": "3.3.0",
3
+ "version": "4.0.1",
4
4
  "description": "A comunica bus for query-operation events.",
5
5
  "lsd:module": true,
6
6
  "license": "MIT",
7
+ "funding": {
8
+ "type": "opencollective",
9
+ "url": "https://opencollective.com/comunica-association"
10
+ },
7
11
  "homepage": "https://comunica.dev/",
8
12
  "repository": {
9
13
  "type": "git",
@@ -36,18 +40,12 @@
36
40
  "build:components": "componentsjs-generator"
37
41
  },
38
42
  "dependencies": {
39
- "@comunica/bindings-factory": "^3.3.0",
40
- "@comunica/context-entries": "^3.3.0",
41
- "@comunica/core": "^3.3.0",
42
- "@comunica/data-factory": "^3.1.0",
43
- "@comunica/metadata": "^3.3.0",
44
- "@comunica/types": "^3.3.0",
43
+ "@comunica/context-entries": "^4.0.1",
44
+ "@comunica/core": "^4.0.1",
45
+ "@comunica/types": "^4.0.1",
46
+ "@comunica/utils-metadata": "^4.0.1",
45
47
  "@rdfjs/types": "*",
46
- "asynciterator": "^3.9.0",
47
- "rdf-data-factory": "^1.1.2",
48
- "rdf-string": "^1.6.1",
49
- "rdf-terms": "^1.11.0",
50
- "sparqlalgebrajs": "^4.3.7"
48
+ "sparqlalgebrajs": "^4.3.8"
51
49
  },
52
- "gitHead": "02bde397d206f1f5a523643a6a604c89e792e2f9"
50
+ "gitHead": "67831ba79e45ea1ced41fe3f83c5d6e8802dbeaa"
53
51
  }
package/lib/Bindings.d.ts DELETED
@@ -1,38 +0,0 @@
1
- import type { BindingsFactory } from '@comunica/bindings-factory';
2
- import type { Bindings } from '@comunica/types';
3
- import type * as RDF from '@rdfjs/types';
4
- import type { Algebra } from 'sparqlalgebrajs';
5
- /**
6
- * Materialize a term with the given binding.
7
- *
8
- * If the given term is a variable,
9
- * and that variable exist in the given bindings object,
10
- * the value of that binding is returned.
11
- * In all other cases, the term itself is returned.
12
- *
13
- * @param {RDF.Term} term A term.
14
- * @param {Bindings} bindings A bindings object.
15
- * @return {RDF.Term} The materialized term.
16
- */
17
- export declare function materializeTerm(term: RDF.Term, bindings: Bindings): RDF.Term;
18
- /**
19
- * Materialize the given operation (recursively) with the given bindings.
20
- * Essentially, the variables in the given operation
21
- * which don't appear in the projection operation will be replaced
22
- * by the terms bound to the variables in the given bindings.
23
- * @param {Algebra.Operation} operation SPARQL algebra operation.
24
- * And the variables that appear in the projection operation
25
- * will be added to a new values operation.
26
- * @param {Bindings} bindings A bindings object.
27
- * @param bindingsFactory The bindings factory.
28
- * @param options Options for materializations.
29
- * @param options.strictTargetVariables If target variable bindings (such as on SELECT or BIND) should not be allowed.
30
- * @param options.bindFilter If filter expressions should be materialized.
31
- * @param options.originalBindings The bindings object as it was at the top level call of materializeOperation.
32
- * @return Algebra.Operation A new operation materialized with the given bindings.
33
- */
34
- export declare function materializeOperation(operation: Algebra.Operation, bindings: Bindings, bindingsFactory: BindingsFactory, options?: {
35
- strictTargetVariables?: boolean;
36
- bindFilter?: boolean;
37
- originalBindings?: Bindings;
38
- }): Algebra.Operation;