@comunica/actor-query-operation-from-quad 3.2.4-alpha.47.0 → 3.3.0
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.
|
@@ -54,10 +54,6 @@
|
|
|
54
54
|
{
|
|
55
55
|
"@type": "ParameterRangeGenericTypeReference",
|
|
56
56
|
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
"@type": "ParameterRangeGenericTypeReference",
|
|
60
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
61
57
|
}
|
|
62
58
|
]
|
|
63
59
|
},
|
|
@@ -72,10 +68,6 @@
|
|
|
72
68
|
{
|
|
73
69
|
"@type": "ParameterRangeGenericTypeReference",
|
|
74
70
|
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
"@type": "ParameterRangeGenericTypeReference",
|
|
78
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
79
71
|
}
|
|
80
72
|
]
|
|
81
73
|
},
|
|
@@ -85,20 +77,6 @@
|
|
|
85
77
|
},
|
|
86
78
|
"comment": "The bus this actor subscribes to."
|
|
87
79
|
},
|
|
88
|
-
{
|
|
89
|
-
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_busFailMessage",
|
|
90
|
-
"range": {
|
|
91
|
-
"@type": "ParameterRangeUnion",
|
|
92
|
-
"parameterRangeElements": [
|
|
93
|
-
"xsd:string",
|
|
94
|
-
{
|
|
95
|
-
"@type": "ParameterRangeUndefined"
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
},
|
|
99
|
-
"default": "Query operation processing failed: none of the configured actors were able to handle the operation type ${action.operation.type}",
|
|
100
|
-
"comment": "The message that will be configured in the bus for reporting failures. This message may be a template string that contains references to the executed `action`. For example, the following templated string is allowed: \"RDF dereferencing failed: no actors could handle ${action.handle.mediaType}\""
|
|
101
|
-
},
|
|
102
80
|
{
|
|
103
81
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_beforeActors",
|
|
104
82
|
"range": {
|
|
@@ -121,10 +99,6 @@
|
|
|
121
99
|
{
|
|
122
100
|
"@type": "ParameterRangeGenericTypeReference",
|
|
123
101
|
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
"@type": "ParameterRangeGenericTypeReference",
|
|
127
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
128
102
|
}
|
|
129
103
|
]
|
|
130
104
|
}
|
|
@@ -138,6 +112,10 @@
|
|
|
138
112
|
}
|
|
139
113
|
],
|
|
140
114
|
"memberFields": [
|
|
115
|
+
{
|
|
116
|
+
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_FACTORY",
|
|
117
|
+
"memberFieldName": "FACTORY"
|
|
118
|
+
},
|
|
141
119
|
{
|
|
142
120
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_ALGEBRA_TYPES",
|
|
143
121
|
"memberFieldName": "ALGEBRA_TYPES"
|
|
@@ -201,12 +179,6 @@
|
|
|
201
179
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_bus"
|
|
202
180
|
}
|
|
203
181
|
},
|
|
204
|
-
{
|
|
205
|
-
"keyRaw": "busFailMessage",
|
|
206
|
-
"value": {
|
|
207
|
-
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_busFailMessage"
|
|
208
|
-
}
|
|
209
|
-
},
|
|
210
182
|
{
|
|
211
183
|
"keyRaw": "beforeActors",
|
|
212
184
|
"value": {
|
|
@@ -17,9 +17,6 @@
|
|
|
17
17
|
"args_bus": {
|
|
18
18
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_bus"
|
|
19
19
|
},
|
|
20
|
-
"args_busFailMessage": {
|
|
21
|
-
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_busFailMessage"
|
|
22
|
-
},
|
|
23
20
|
"args_beforeActors": {
|
|
24
21
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_beforeActors",
|
|
25
22
|
"@container": "@list"
|
|
@@ -33,9 +30,6 @@
|
|
|
33
30
|
"bus": {
|
|
34
31
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_bus"
|
|
35
32
|
},
|
|
36
|
-
"busFailMessage": {
|
|
37
|
-
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_busFailMessage"
|
|
38
|
-
},
|
|
39
33
|
"beforeActors": {
|
|
40
34
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_beforeActors",
|
|
41
35
|
"@container": "@list"
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';
|
|
2
2
|
import { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';
|
|
3
|
-
import type { IActorTest
|
|
3
|
+
import type { IActorTest } from '@comunica/core';
|
|
4
4
|
import type { IActionContext, IQueryOperationResult } from '@comunica/types';
|
|
5
5
|
import type * as RDF from '@rdfjs/types';
|
|
6
|
-
import { Algebra
|
|
6
|
+
import { Algebra } from 'sparqlalgebrajs';
|
|
7
7
|
/**
|
|
8
8
|
* A comunica From Query Operation Actor.
|
|
9
9
|
*/
|
|
10
10
|
export declare class ActorQueryOperationFromQuad extends ActorQueryOperationTypedMediated<Algebra.From> {
|
|
11
|
+
private static readonly FACTORY;
|
|
11
12
|
private static readonly ALGEBRA_TYPES;
|
|
12
13
|
constructor(args: IActorQueryOperationTypedMediatedArgs);
|
|
13
14
|
/**
|
|
@@ -20,40 +21,32 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
20
21
|
/**
|
|
21
22
|
* Recursively transform the given operation to use the given graphs as default graph
|
|
22
23
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
23
|
-
* @package
|
|
24
|
-
* @param algebraFactory The algebra factory.
|
|
25
24
|
* @param {Operation} operation An operation.
|
|
26
25
|
* @param {RDF.Term[]} defaultGraphs Graph terms.
|
|
27
26
|
* @return {Operation} A new operation.
|
|
28
27
|
*/
|
|
29
|
-
static applyOperationDefaultGraph(
|
|
28
|
+
static applyOperationDefaultGraph(operation: Algebra.Operation, defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
30
29
|
/**
|
|
31
30
|
* Recursively transform the given operation to use the given graphs as named graph
|
|
32
31
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
33
|
-
* @package
|
|
34
|
-
* @param algebraFactory The algebra factory.
|
|
35
32
|
* @param {Operation} operation An operation.
|
|
36
33
|
* @param {RDF.Term[]} namedGraphs Graph terms.
|
|
37
34
|
* @param {RDF.Term[]} defaultGraphs Default graph terms.
|
|
38
35
|
* @return {Operation} A new operation.
|
|
39
36
|
*/
|
|
40
|
-
static applyOperationNamedGraph(
|
|
37
|
+
static applyOperationNamedGraph(operation: Algebra.Operation, namedGraphs: RDF.NamedNode[], defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
41
38
|
/**
|
|
42
39
|
* Transform the given array of operations into a join operation.
|
|
43
|
-
* @package
|
|
44
|
-
* @param algebraFactory The algebra factory.
|
|
45
40
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
46
41
|
* @return {Join} A join operation.
|
|
47
42
|
*/
|
|
48
|
-
static joinOperations(
|
|
43
|
+
static joinOperations(operations: Algebra.Operation[]): Algebra.Operation;
|
|
49
44
|
/**
|
|
50
45
|
* Transform the given array of operations into a union operation.
|
|
51
|
-
* @package
|
|
52
|
-
* @param algebraFactory The algebra factory.
|
|
53
46
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
54
47
|
* @return {Union} A union operation.
|
|
55
48
|
*/
|
|
56
|
-
static unionOperations(
|
|
49
|
+
static unionOperations(operations: Algebra.Operation[]): Algebra.Operation;
|
|
57
50
|
/**
|
|
58
51
|
* Transform an operation based on the default and named graphs in the pattern.
|
|
59
52
|
*
|
|
@@ -63,12 +56,10 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
63
56
|
* FROM NAMED indicates which named graphs are available.
|
|
64
57
|
* This will rewrite the query so that only triples from the given named graphs can be selected.
|
|
65
58
|
*
|
|
66
|
-
* @package
|
|
67
|
-
* @param algebraFactory The algebra factory.
|
|
68
59
|
* @param {From} pattern A from operation.
|
|
69
60
|
* @return {Operation} The transformed operation.
|
|
70
61
|
*/
|
|
71
|
-
static createOperation(
|
|
72
|
-
testOperation(_operation: Algebra.From, _context: IActionContext): Promise<
|
|
62
|
+
static createOperation(pattern: Algebra.From): Algebra.Operation;
|
|
63
|
+
testOperation(_operation: Algebra.From, _context: IActionContext): Promise<IActorTest>;
|
|
73
64
|
runOperation(operationOriginal: Algebra.From, context: IActionContext): Promise<IQueryOperationResult>;
|
|
74
65
|
}
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActorQueryOperationFromQuad = void 0;
|
|
4
4
|
const bus_query_operation_1 = require("@comunica/bus-query-operation");
|
|
5
|
-
const context_entries_1 = require("@comunica/context-entries");
|
|
6
|
-
const core_1 = require("@comunica/core");
|
|
7
5
|
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
8
6
|
/**
|
|
9
7
|
* A comunica From Query Operation Actor.
|
|
@@ -42,26 +40,23 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
42
40
|
/**
|
|
43
41
|
* Recursively transform the given operation to use the given graphs as default graph
|
|
44
42
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
45
|
-
* @package
|
|
46
|
-
* @param algebraFactory The algebra factory.
|
|
47
43
|
* @param {Operation} operation An operation.
|
|
48
44
|
* @param {RDF.Term[]} defaultGraphs Graph terms.
|
|
49
45
|
* @return {Operation} A new operation.
|
|
50
46
|
*/
|
|
51
|
-
static applyOperationDefaultGraph(
|
|
47
|
+
static applyOperationDefaultGraph(operation, defaultGraphs) {
|
|
52
48
|
// If the operation is a BGP or Path, change the graph.
|
|
53
49
|
if ((operation.type === 'bgp' && operation.patterns.length > 0) ||
|
|
54
50
|
operation.type === 'path' ||
|
|
55
51
|
operation.type === 'pattern') {
|
|
56
52
|
if (operation.type === 'bgp') {
|
|
57
|
-
return ActorQueryOperationFromQuad
|
|
58
|
-
.joinOperations(algebraFactory, operation.patterns.map((pattern) => {
|
|
53
|
+
return ActorQueryOperationFromQuad.joinOperations(operation.patterns.map((pattern) => {
|
|
59
54
|
if (pattern.graph.termType !== 'DefaultGraph') {
|
|
60
|
-
return
|
|
55
|
+
return ActorQueryOperationFromQuad.FACTORY.createBgp([pattern]);
|
|
61
56
|
}
|
|
62
|
-
const bgps = defaultGraphs.map((graph) =>
|
|
57
|
+
const bgps = defaultGraphs.map((graph) => ActorQueryOperationFromQuad.FACTORY.createBgp([Object.assign(ActorQueryOperationFromQuad.FACTORY
|
|
63
58
|
.createPattern(pattern.subject, pattern.predicate, pattern.object, graph), { metadata: pattern.metadata })]));
|
|
64
|
-
return ActorQueryOperationFromQuad.unionOperations(
|
|
59
|
+
return ActorQueryOperationFromQuad.unionOperations(bgps);
|
|
65
60
|
}));
|
|
66
61
|
}
|
|
67
62
|
if (operation.graph.termType !== 'DefaultGraph') {
|
|
@@ -69,27 +64,25 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
69
64
|
}
|
|
70
65
|
const paths = defaultGraphs.map((graph) => {
|
|
71
66
|
if (operation.type === 'path') {
|
|
72
|
-
return
|
|
67
|
+
return ActorQueryOperationFromQuad.FACTORY
|
|
73
68
|
.createPath(operation.subject, operation.predicate, operation.object, graph);
|
|
74
69
|
}
|
|
75
|
-
return Object.assign(
|
|
70
|
+
return Object.assign(ActorQueryOperationFromQuad.FACTORY
|
|
76
71
|
.createPattern(operation.subject, operation.predicate, operation.object, graph), { metadata: operation.metadata });
|
|
77
72
|
});
|
|
78
|
-
return ActorQueryOperationFromQuad.unionOperations(
|
|
73
|
+
return ActorQueryOperationFromQuad.unionOperations(paths);
|
|
79
74
|
}
|
|
80
|
-
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this.applyOperationDefaultGraph(
|
|
75
|
+
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this.applyOperationDefaultGraph(subOperation, defaultGraphs));
|
|
81
76
|
}
|
|
82
77
|
/**
|
|
83
78
|
* Recursively transform the given operation to use the given graphs as named graph
|
|
84
79
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
85
|
-
* @package
|
|
86
|
-
* @param algebraFactory The algebra factory.
|
|
87
80
|
* @param {Operation} operation An operation.
|
|
88
81
|
* @param {RDF.Term[]} namedGraphs Graph terms.
|
|
89
82
|
* @param {RDF.Term[]} defaultGraphs Default graph terms.
|
|
90
83
|
* @return {Operation} A new operation.
|
|
91
84
|
*/
|
|
92
|
-
static applyOperationNamedGraph(
|
|
85
|
+
static applyOperationNamedGraph(operation, namedGraphs, defaultGraphs) {
|
|
93
86
|
// If the operation is a BGP or Path, change the graph.
|
|
94
87
|
if ((operation.type === 'bgp' && operation.patterns.length > 0) ||
|
|
95
88
|
operation.type === 'path' ||
|
|
@@ -106,26 +99,26 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
106
99
|
// If the pattern graph is a variable, replace the graph and bind the variable using VALUES
|
|
107
100
|
const bindings = {};
|
|
108
101
|
bindings[`?${patternGraph.value}`] = graph;
|
|
109
|
-
const values =
|
|
102
|
+
const values = ActorQueryOperationFromQuad.FACTORY
|
|
110
103
|
.createValues([patternGraph], [bindings]);
|
|
111
104
|
let pattern;
|
|
112
105
|
if (operation.type === 'bgp') {
|
|
113
|
-
pattern =
|
|
114
|
-
.createBgp(operation.patterns.map((pat) =>
|
|
106
|
+
pattern = ActorQueryOperationFromQuad.FACTORY
|
|
107
|
+
.createBgp(operation.patterns.map((pat) => ActorQueryOperationFromQuad.FACTORY
|
|
115
108
|
.createPattern(pat.subject, pat.predicate, pat.object, graph)));
|
|
116
109
|
}
|
|
117
110
|
else if (operation.type === 'path') {
|
|
118
|
-
pattern =
|
|
111
|
+
pattern = ActorQueryOperationFromQuad.FACTORY
|
|
119
112
|
.createPath(operation.subject, operation.predicate, operation.object, graph);
|
|
120
113
|
}
|
|
121
114
|
else {
|
|
122
|
-
pattern =
|
|
115
|
+
pattern = ActorQueryOperationFromQuad.FACTORY
|
|
123
116
|
.createPattern(operation.subject, operation.predicate, operation.object, graph);
|
|
124
117
|
}
|
|
125
|
-
return
|
|
118
|
+
return ActorQueryOperationFromQuad.FACTORY.createJoin([values, pattern]);
|
|
126
119
|
}
|
|
127
120
|
// If the pattern graph is a variable, take the union of the pattern applied to each available named graph
|
|
128
|
-
return ActorQueryOperationFromQuad.unionOperations(
|
|
121
|
+
return ActorQueryOperationFromQuad.unionOperations(namedGraphs.map((graph) => ActorQueryOperationFromQuad.applyOperationNamedGraph(operation, [graph], defaultGraphs)));
|
|
129
122
|
}
|
|
130
123
|
// The pattern's graph is defined (including the default graphs)
|
|
131
124
|
const isNamedGraphAvailable = [...namedGraphs, ...defaultGraphs].some((namedGraph) => namedGraph.equals(patternGraph));
|
|
@@ -136,38 +129,33 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
136
129
|
// No-op if the pattern's graph was not selected in a FROM NAMED.
|
|
137
130
|
return { type: sparqlalgebrajs_1.Algebra.types.BGP, patterns: [] };
|
|
138
131
|
}
|
|
139
|
-
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this
|
|
140
|
-
.applyOperationNamedGraph(algebraFactory, subOperation, namedGraphs, defaultGraphs));
|
|
132
|
+
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this.applyOperationNamedGraph(subOperation, namedGraphs, defaultGraphs));
|
|
141
133
|
}
|
|
142
134
|
/**
|
|
143
135
|
* Transform the given array of operations into a join operation.
|
|
144
|
-
* @package
|
|
145
|
-
* @param algebraFactory The algebra factory.
|
|
146
136
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
147
137
|
* @return {Join} A join operation.
|
|
148
138
|
*/
|
|
149
|
-
static joinOperations(
|
|
139
|
+
static joinOperations(operations) {
|
|
150
140
|
if (operations.length === 1) {
|
|
151
141
|
return operations[0];
|
|
152
142
|
}
|
|
153
143
|
if (operations.length > 1) {
|
|
154
|
-
return
|
|
144
|
+
return ActorQueryOperationFromQuad.FACTORY.createJoin(operations);
|
|
155
145
|
}
|
|
156
146
|
throw new Error('A join can only be applied on at least one operation');
|
|
157
147
|
}
|
|
158
148
|
/**
|
|
159
149
|
* Transform the given array of operations into a union operation.
|
|
160
|
-
* @package
|
|
161
|
-
* @param algebraFactory The algebra factory.
|
|
162
150
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
163
151
|
* @return {Union} A union operation.
|
|
164
152
|
*/
|
|
165
|
-
static unionOperations(
|
|
153
|
+
static unionOperations(operations) {
|
|
166
154
|
if (operations.length === 1) {
|
|
167
155
|
return operations[0];
|
|
168
156
|
}
|
|
169
157
|
if (operations.length > 1) {
|
|
170
|
-
return
|
|
158
|
+
return ActorQueryOperationFromQuad.FACTORY.createUnion(operations);
|
|
171
159
|
}
|
|
172
160
|
throw new Error('A union can only be applied on at least one operation');
|
|
173
161
|
}
|
|
@@ -180,32 +168,28 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
180
168
|
* FROM NAMED indicates which named graphs are available.
|
|
181
169
|
* This will rewrite the query so that only triples from the given named graphs can be selected.
|
|
182
170
|
*
|
|
183
|
-
* @package
|
|
184
|
-
* @param algebraFactory The algebra factory.
|
|
185
171
|
* @param {From} pattern A from operation.
|
|
186
172
|
* @return {Operation} The transformed operation.
|
|
187
173
|
*/
|
|
188
|
-
static createOperation(
|
|
174
|
+
static createOperation(pattern) {
|
|
189
175
|
let operation = pattern.input;
|
|
190
176
|
if (pattern.default.length > 0) {
|
|
191
|
-
operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(
|
|
177
|
+
operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(operation, pattern.default);
|
|
192
178
|
}
|
|
193
179
|
if (pattern.named.length > 0 || pattern.default.length > 0) {
|
|
194
|
-
operation = ActorQueryOperationFromQuad
|
|
195
|
-
.applyOperationNamedGraph(algebraFactory, operation, pattern.named, pattern.default);
|
|
180
|
+
operation = ActorQueryOperationFromQuad.applyOperationNamedGraph(operation, pattern.named, pattern.default);
|
|
196
181
|
}
|
|
197
182
|
return operation;
|
|
198
183
|
}
|
|
199
184
|
async testOperation(_operation, _context) {
|
|
200
|
-
return
|
|
185
|
+
return true;
|
|
201
186
|
}
|
|
202
187
|
async runOperation(operationOriginal, context) {
|
|
203
|
-
const
|
|
204
|
-
const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
|
|
205
|
-
const operation = ActorQueryOperationFromQuad.createOperation(algebraFactory, operationOriginal);
|
|
188
|
+
const operation = ActorQueryOperationFromQuad.createOperation(operationOriginal);
|
|
206
189
|
return this.mediatorQueryOperation.mediate({ operation, context });
|
|
207
190
|
}
|
|
208
191
|
}
|
|
209
192
|
exports.ActorQueryOperationFromQuad = ActorQueryOperationFromQuad;
|
|
193
|
+
ActorQueryOperationFromQuad.FACTORY = new sparqlalgebrajs_1.Factory();
|
|
210
194
|
ActorQueryOperationFromQuad.ALGEBRA_TYPES = Object.keys(sparqlalgebrajs_1.Algebra.types).map(key => sparqlalgebrajs_1.Algebra.types[key]);
|
|
211
195
|
//# sourceMappingURL=ActorQueryOperationFromQuad.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorQueryOperationFromQuad.js","sourceRoot":"","sources":["ActorQueryOperationFromQuad.ts"],"names":[],"mappings":";;;AACA,uEAAiF;AACjF,+DAA0D;AAE1D,yCAA8C;AAG9C,qDAAmD;AAEnD;;GAEG;AACH,MAAa,2BAA4B,SAAQ,sDAA8C;IAG7F,YAAmB,IAA2C;QAC5D,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,aAAa,CACzB,SAA4B,EAC5B,WAAmE;QAEnE,MAAM,eAAe,GAA4B,EAAE,CAAC;QACpD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,KAAK,UAAU,EAAE,CAAC;gBACxD,yGAAyG;gBACzG,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;oBACxB,eAAe,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;gBACxC,CAAC;qBAAM,CAAC;oBACN,eAAe,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAA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B,CAAC,cAAc,EAAE,SAAS,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACzF,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,UAAwB,EAAE,QAAwB;QAC3E,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,YAAY,CACvB,iBAA+B,EAC/B,OAAuB;QAEvB,MAAM,WAAW,GAAwB,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAAC;QACpF,MAAM,cAAc,GAAG,IAAI,yBAAO,CAAC,WAAW,CAAC,CAAC;QAEhD,MAAM,SAAS,GAAsB,2BAA2B,CAAC,eAAe,CAAC,cAAc,EAAE,iBAAiB,CAAC,CAAC;QACpH,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;;AAvPH,kEAwPC;AAvPyB,yCAAa,GAAa,MAAM,CAAC,IAAI,CAAC,yBAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAQ,yBAAO,CAAC,KAAM,CAAC,GAAG,CAAC,CAAC,CAAC","sourcesContent":["import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';\nimport { KeysInitQuery } from '@comunica/context-entries';\nimport type { IActorTest, TestResult } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport type { ComunicaDataFactory, IActionContext, IQueryOperationResult } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\n\n/**\n * A comunica From Query Operation Actor.\n */\nexport class ActorQueryOperationFromQuad extends ActorQueryOperationTypedMediated<Algebra.From> {\n private static readonly ALGEBRA_TYPES: string[] = Object.keys(Algebra.types).map(key => (<any> Algebra.types)[key]);\n\n public constructor(args: IActorQueryOperationTypedMediatedArgs) {\n super(args, 'from');\n }\n\n /**\n * Create a deep copy of the given operation.\n * @param {Operation} operation An operation.\n * @param {(subOperation: Operation) => Operation} recursiveCb A callback for recursive operation calls.\n * @return {Operation} The copied operation.\n */\n public static copyOperation(\n operation: Algebra.Operation,\n recursiveCb: (subOperation: Algebra.Operation) => Algebra.Operation,\n ): Algebra.Operation {\n const copiedOperation: Algebra.Operation = <any> {};\n for (const key of Object.keys(operation)) {\n if (Array.isArray(operation[key]) && key !== 'template') {\n // We exclude the 'template' entry, as we don't want to modify the template value of construct operations\n if (key === 'variables') {\n copiedOperation[key] = operation[key];\n } else {\n copiedOperation[key] = operation[key].map(recursiveCb);\n }\n } else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(operation[key].type)) {\n copiedOperation[key] = recursiveCb(operation[key]);\n } else {\n copiedOperation[key] = operation[key];\n }\n }\n return copiedOperation;\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as default graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} defaultGraphs Graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationDefaultGraph(\n algebraFactory: Factory,\n operation: Algebra.Operation,\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n if (operation.type === 'bgp') {\n return ActorQueryOperationFromQuad\n .joinOperations(algebraFactory, operation.patterns.map((pattern: Algebra.Pattern) => {\n if (pattern.graph.termType !== 'DefaultGraph') {\n return algebraFactory.createBgp([ pattern ]);\n }\n const bgps = defaultGraphs.map((graph: RDF.Term) =>\n algebraFactory.createBgp([ Object.assign(\n algebraFactory\n .createPattern(pattern.subject, pattern.predicate, pattern.object, graph),\n { metadata: pattern.metadata },\n ) ]));\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, bgps);\n }));\n }\n if (operation.graph.termType !== 'DefaultGraph') {\n return operation;\n }\n const paths = defaultGraphs.map(\n (graph: RDF.Term) => {\n if (operation.type === 'path') {\n return algebraFactory\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n }\n return Object.assign(algebraFactory\n .createPattern(\n operation.subject,\n operation.predicate,\n operation.object,\n graph,\n ), { metadata: operation.metadata });\n },\n );\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);\n }\n\n return ActorQueryOperationFromQuad.copyOperation(\n operation,\n (subOperation: Algebra.Operation) => this.applyOperationDefaultGraph(algebraFactory, subOperation, defaultGraphs),\n );\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as named graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} namedGraphs Graph terms.\n * @param {RDF.Term[]} defaultGraphs Default graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationNamedGraph(\n algebraFactory: Factory,\n operation: Algebra.Operation,\n namedGraphs: RDF.NamedNode[],\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n const patternGraph: RDF.Term = operation.type === 'bgp' ? operation.patterns[0].graph : operation.graph;\n if (patternGraph.termType === 'DefaultGraph') {\n // SPARQL spec (8.2) describes that when FROM NAMED's are used without a FROM, the default graph must be empty.\n // The FROMs are transformed before this step to a named node, so this will not apply to this case anymore.\n return { type: Algebra.types.BGP, patterns: []};\n }\n if (patternGraph.termType === 'Variable') {\n if (namedGraphs.length === 1) {\n const graph: RDF.NamedNode = namedGraphs[0];\n // If the pattern graph is a variable, replace the graph and bind the variable using VALUES\n const bindings: Record<string, RDF.Literal | RDF.NamedNode> = {};\n bindings[`?${patternGraph.value}`] = graph;\n const values: Algebra.Values = algebraFactory\n .createValues([ patternGraph ], [ bindings ]);\n\n let pattern: Algebra.Operation;\n if (operation.type === 'bgp') {\n pattern = algebraFactory\n .createBgp(operation.patterns.map((pat: Algebra.Pattern) => algebraFactory\n .createPattern(pat.subject, pat.predicate, pat.object, graph)));\n } else if (operation.type === 'path') {\n pattern = algebraFactory\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n } else {\n pattern = algebraFactory\n .createPattern(operation.subject, operation.predicate, operation.object, graph);\n }\n\n return algebraFactory.createJoin([ values, pattern ]);\n }\n // If the pattern graph is a variable, take the union of the pattern applied to each available named graph\n return ActorQueryOperationFromQuad.unionOperations(algebraFactory, namedGraphs.map(\n (graph: RDF.NamedNode) => ActorQueryOperationFromQuad.applyOperationNamedGraph(\n algebraFactory,\n operation,\n [ graph ],\n defaultGraphs,\n ),\n ));\n }\n // The pattern's graph is defined (including the default graphs)\n const isNamedGraphAvailable: boolean = [ ...namedGraphs, ...defaultGraphs ].some(\n (namedGraph: RDF.Term) => namedGraph.equals(patternGraph),\n );\n if (isNamedGraphAvailable) {\n // Return the pattern as-is if the pattern's graph was selected in a FROM NAMED\n return operation;\n }\n // No-op if the pattern's graph was not selected in a FROM NAMED.\n return { type: Algebra.types.BGP, patterns: []};\n }\n\n return ActorQueryOperationFromQuad.copyOperation(\n operation,\n (subOperation: Algebra.Operation) => this\n .applyOperationNamedGraph(algebraFactory, subOperation, namedGraphs, defaultGraphs),\n );\n }\n\n /**\n * Transform the given array of operations into a join operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Join} A join operation.\n */\n public static joinOperations(algebraFactory: Factory, operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return algebraFactory.createJoin(operations);\n }\n throw new Error('A join can only be applied on at least one operation');\n }\n\n /**\n * Transform the given array of operations into a union operation.\n * @package\n * @param algebraFactory The algebra factory.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Union} A union operation.\n */\n public static unionOperations(algebraFactory: Factory, operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return algebraFactory.createUnion(operations);\n }\n throw new Error('A union can only be applied on at least one operation');\n }\n\n /**\n * Transform an operation based on the default and named graphs in the pattern.\n *\n * FROM sets the default graph.\n * If multiple are available, take the union of the operation for all of them at quad-pattern level.\n *\n * FROM NAMED indicates which named graphs are available.\n * This will rewrite the query so that only triples from the given named graphs can be selected.\n *\n * @package\n * @param algebraFactory The algebra factory.\n * @param {From} pattern A from operation.\n * @return {Operation} The transformed operation.\n */\n public static createOperation(algebraFactory: Factory, pattern: Algebra.From): Algebra.Operation {\n let operation: Algebra.Operation = pattern.input;\n if (pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(algebraFactory, operation, pattern.default);\n }\n if (pattern.named.length > 0 || pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad\n .applyOperationNamedGraph(algebraFactory, operation, pattern.named, pattern.default);\n }\n return operation;\n }\n\n public async testOperation(_operation: Algebra.From, _context: IActionContext): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n public async runOperation(\n operationOriginal: Algebra.From,\n context: IActionContext,\n ): Promise<IQueryOperationResult> {\n const dataFactory: ComunicaDataFactory = context.getSafe(KeysInitQuery.dataFactory);\n const algebraFactory = new Factory(dataFactory);\n\n const operation: Algebra.Operation = ActorQueryOperationFromQuad.createOperation(algebraFactory, operationOriginal);\n return this.mediatorQueryOperation.mediate({ operation, context });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActorQueryOperationFromQuad.js","sourceRoot":"","sources":["ActorQueryOperationFromQuad.ts"],"names":[],"mappings":";;;AACA,uEAAiF;AAIjF,qDAAmD;AAEnD;;GAEG;AACH,MAAa,2BAA4B,SAAQ,sDAA8C;IAI7F,YAAmB,I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AG,CAAC,CAAC,CAAC","sourcesContent":["import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';\nimport type { IActorTest } from '@comunica/core';\nimport type { IActionContext, IQueryOperationResult } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\n\n/**\n * A comunica From Query Operation Actor.\n */\nexport class ActorQueryOperationFromQuad extends ActorQueryOperationTypedMediated<Algebra.From> {\n private static readonly FACTORY: Factory = new Factory();\n private static readonly ALGEBRA_TYPES: string[] = Object.keys(Algebra.types).map(key => (<any> Algebra.types)[key]);\n\n public constructor(args: IActorQueryOperationTypedMediatedArgs) {\n super(args, 'from');\n }\n\n /**\n * Create a deep copy of the given operation.\n * @param {Operation} operation An operation.\n * @param {(subOperation: Operation) => Operation} recursiveCb A callback for recursive operation calls.\n * @return {Operation} The copied operation.\n */\n public static copyOperation(\n operation: Algebra.Operation,\n recursiveCb: (subOperation: Algebra.Operation) => Algebra.Operation,\n ): Algebra.Operation {\n const copiedOperation: Algebra.Operation = <any> {};\n for (const key of Object.keys(operation)) {\n if (Array.isArray(operation[key]) && key !== 'template') {\n // We exclude the 'template' entry, as we don't want to modify the template value of construct operations\n if (key === 'variables') {\n copiedOperation[key] = operation[key];\n } else {\n copiedOperation[key] = operation[key].map(recursiveCb);\n }\n } else if (ActorQueryOperationFromQuad.ALGEBRA_TYPES.includes(operation[key].type)) {\n copiedOperation[key] = recursiveCb(operation[key]);\n } else {\n copiedOperation[key] = operation[key];\n }\n }\n return copiedOperation;\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as default graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} defaultGraphs Graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationDefaultGraph(operation: Algebra.Operation, defaultGraphs: RDF.Term[]): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n if (operation.type === 'bgp') {\n return ActorQueryOperationFromQuad.joinOperations(operation.patterns.map((pattern: Algebra.Pattern) => {\n if (pattern.graph.termType !== 'DefaultGraph') {\n return ActorQueryOperationFromQuad.FACTORY.createBgp([ pattern ]);\n }\n const bgps = defaultGraphs.map((graph: RDF.Term) =>\n ActorQueryOperationFromQuad.FACTORY.createBgp([ Object.assign(\n ActorQueryOperationFromQuad.FACTORY\n .createPattern(pattern.subject, pattern.predicate, pattern.object, graph),\n { metadata: pattern.metadata },\n ) ]));\n return ActorQueryOperationFromQuad.unionOperations(bgps);\n }));\n }\n if (operation.graph.termType !== 'DefaultGraph') {\n return operation;\n }\n const paths = defaultGraphs.map(\n (graph: RDF.Term) => {\n if (operation.type === 'path') {\n return ActorQueryOperationFromQuad.FACTORY\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n }\n return Object.assign(ActorQueryOperationFromQuad.FACTORY\n .createPattern(\n operation.subject,\n operation.predicate,\n operation.object,\n graph,\n ), { metadata: operation.metadata });\n },\n );\n return ActorQueryOperationFromQuad.unionOperations(paths);\n }\n\n return ActorQueryOperationFromQuad.copyOperation(\n operation,\n (subOperation: Algebra.Operation) => this.applyOperationDefaultGraph(subOperation, defaultGraphs),\n );\n }\n\n /**\n * Recursively transform the given operation to use the given graphs as named graph\n * This will (possibly) create a new operation and not modify the given operation.\n * @param {Operation} operation An operation.\n * @param {RDF.Term[]} namedGraphs Graph terms.\n * @param {RDF.Term[]} defaultGraphs Default graph terms.\n * @return {Operation} A new operation.\n */\n public static applyOperationNamedGraph(\n operation: Algebra.Operation,\n namedGraphs: RDF.NamedNode[],\n defaultGraphs: RDF.Term[],\n ): Algebra.Operation {\n // If the operation is a BGP or Path, change the graph.\n if ((operation.type === 'bgp' && operation.patterns.length > 0) ||\n operation.type === 'path' ||\n operation.type === 'pattern') {\n const patternGraph: RDF.Term = operation.type === 'bgp' ? operation.patterns[0].graph : operation.graph;\n if (patternGraph.termType === 'DefaultGraph') {\n // SPARQL spec (8.2) describes that when FROM NAMED's are used without a FROM, the default graph must be empty.\n // The FROMs are transformed before this step to a named node, so this will not apply to this case anymore.\n return { type: Algebra.types.BGP, patterns: []};\n }\n if (patternGraph.termType === 'Variable') {\n if (namedGraphs.length === 1) {\n const graph: RDF.NamedNode = namedGraphs[0];\n // If the pattern graph is a variable, replace the graph and bind the variable using VALUES\n const bindings: Record<string, RDF.Literal | RDF.NamedNode> = {};\n bindings[`?${patternGraph.value}`] = graph;\n const values: Algebra.Values = ActorQueryOperationFromQuad.FACTORY\n .createValues([ patternGraph ], [ bindings ]);\n\n let pattern: Algebra.Operation;\n if (operation.type === 'bgp') {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createBgp(operation.patterns.map((pat: Algebra.Pattern) => ActorQueryOperationFromQuad.FACTORY\n .createPattern(pat.subject, pat.predicate, pat.object, graph)));\n } else if (operation.type === 'path') {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createPath(operation.subject, operation.predicate, operation.object, graph);\n } else {\n pattern = ActorQueryOperationFromQuad.FACTORY\n .createPattern(operation.subject, operation.predicate, operation.object, graph);\n }\n\n return ActorQueryOperationFromQuad.FACTORY.createJoin([ values, pattern ]);\n }\n // If the pattern graph is a variable, take the union of the pattern applied to each available named graph\n return ActorQueryOperationFromQuad.unionOperations(namedGraphs.map(\n (graph: RDF.NamedNode) => ActorQueryOperationFromQuad.applyOperationNamedGraph(\n operation,\n [ graph ],\n defaultGraphs,\n ),\n ));\n }\n // The pattern's graph is defined (including the default graphs)\n const isNamedGraphAvailable: boolean = [ ...namedGraphs, ...defaultGraphs ].some(\n (namedGraph: RDF.Term) => namedGraph.equals(patternGraph),\n );\n if (isNamedGraphAvailable) {\n // Return the pattern as-is if the pattern's graph was selected in a FROM NAMED\n return operation;\n }\n // No-op if the pattern's graph was not selected in a FROM NAMED.\n return { type: Algebra.types.BGP, patterns: []};\n }\n\n return ActorQueryOperationFromQuad.copyOperation(\n operation,\n (subOperation: Algebra.Operation) => this.applyOperationNamedGraph(subOperation, namedGraphs, defaultGraphs),\n );\n }\n\n /**\n * Transform the given array of operations into a join operation.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Join} A join operation.\n */\n public static joinOperations(operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return ActorQueryOperationFromQuad.FACTORY.createJoin(operations);\n }\n throw new Error('A join can only be applied on at least one operation');\n }\n\n /**\n * Transform the given array of operations into a union operation.\n * @param {Operation[]} operations An array of operations, must contain at least one operation.\n * @return {Union} A union operation.\n */\n public static unionOperations(operations: Algebra.Operation[]): Algebra.Operation {\n if (operations.length === 1) {\n return operations[0];\n }\n if (operations.length > 1) {\n return ActorQueryOperationFromQuad.FACTORY.createUnion(operations);\n }\n throw new Error('A union can only be applied on at least one operation');\n }\n\n /**\n * Transform an operation based on the default and named graphs in the pattern.\n *\n * FROM sets the default graph.\n * If multiple are available, take the union of the operation for all of them at quad-pattern level.\n *\n * FROM NAMED indicates which named graphs are available.\n * This will rewrite the query so that only triples from the given named graphs can be selected.\n *\n * @param {From} pattern A from operation.\n * @return {Operation} The transformed operation.\n */\n public static createOperation(pattern: Algebra.From): Algebra.Operation {\n let operation: Algebra.Operation = pattern.input;\n if (pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(operation, pattern.default);\n }\n if (pattern.named.length > 0 || pattern.default.length > 0) {\n operation = ActorQueryOperationFromQuad.applyOperationNamedGraph(operation, pattern.named, pattern.default);\n }\n return operation;\n }\n\n public async testOperation(_operation: Algebra.From, _context: IActionContext): Promise<IActorTest> {\n return true;\n }\n\n public async runOperation(\n operationOriginal: Algebra.From,\n context: IActionContext,\n ): Promise<IQueryOperationResult> {\n const operation: Algebra.Operation = ActorQueryOperationFromQuad.createOperation(operationOriginal);\n return this.mediatorQueryOperation.mediate({ operation, context });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-query-operation-from-quad",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "A from query-operation actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"funding": {
|
|
8
|
-
"type": "opencollective",
|
|
9
|
-
"url": "https://opencollective.com/comunica-association"
|
|
10
|
-
},
|
|
11
7
|
"homepage": "https://comunica.dev/",
|
|
12
8
|
"repository": {
|
|
13
9
|
"type": "git",
|
|
@@ -41,12 +37,11 @@
|
|
|
41
37
|
"build:components": "componentsjs-generator"
|
|
42
38
|
},
|
|
43
39
|
"dependencies": {
|
|
44
|
-
"@comunica/bus-query-operation": "3.
|
|
45
|
-
"@comunica/
|
|
46
|
-
"@comunica/
|
|
47
|
-
"@comunica/types": "3.2.4-alpha.47.0",
|
|
40
|
+
"@comunica/bus-query-operation": "^3.3.0",
|
|
41
|
+
"@comunica/core": "^3.3.0",
|
|
42
|
+
"@comunica/types": "^3.3.0",
|
|
48
43
|
"@rdfjs/types": "*",
|
|
49
|
-
"sparqlalgebrajs": "^4.3.
|
|
44
|
+
"sparqlalgebrajs": "^4.3.7"
|
|
50
45
|
},
|
|
51
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "02bde397d206f1f5a523643a6a604c89e792e2f9"
|
|
52
47
|
}
|