@comunica/actor-query-operation-from-quad 3.2.2 → 3.2.4-alpha.47.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,6 +54,10 @@
|
|
|
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"
|
|
57
61
|
}
|
|
58
62
|
]
|
|
59
63
|
},
|
|
@@ -68,6 +72,10 @@
|
|
|
68
72
|
{
|
|
69
73
|
"@type": "ParameterRangeGenericTypeReference",
|
|
70
74
|
"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"
|
|
71
79
|
}
|
|
72
80
|
]
|
|
73
81
|
},
|
|
@@ -77,6 +85,20 @@
|
|
|
77
85
|
},
|
|
78
86
|
"comment": "The bus this actor subscribes to."
|
|
79
87
|
},
|
|
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
|
+
},
|
|
80
102
|
{
|
|
81
103
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_beforeActors",
|
|
82
104
|
"range": {
|
|
@@ -99,6 +121,10 @@
|
|
|
99
121
|
{
|
|
100
122
|
"@type": "ParameterRangeGenericTypeReference",
|
|
101
123
|
"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"
|
|
102
128
|
}
|
|
103
129
|
]
|
|
104
130
|
}
|
|
@@ -112,10 +138,6 @@
|
|
|
112
138
|
}
|
|
113
139
|
],
|
|
114
140
|
"memberFields": [
|
|
115
|
-
{
|
|
116
|
-
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_FACTORY",
|
|
117
|
-
"memberFieldName": "FACTORY"
|
|
118
|
-
},
|
|
119
141
|
{
|
|
120
142
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad__member_ALGEBRA_TYPES",
|
|
121
143
|
"memberFieldName": "ALGEBRA_TYPES"
|
|
@@ -179,6 +201,12 @@
|
|
|
179
201
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_bus"
|
|
180
202
|
}
|
|
181
203
|
},
|
|
204
|
+
{
|
|
205
|
+
"keyRaw": "busFailMessage",
|
|
206
|
+
"value": {
|
|
207
|
+
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_busFailMessage"
|
|
208
|
+
}
|
|
209
|
+
},
|
|
182
210
|
{
|
|
183
211
|
"keyRaw": "beforeActors",
|
|
184
212
|
"value": {
|
|
@@ -17,6 +17,9 @@
|
|
|
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
|
+
},
|
|
20
23
|
"args_beforeActors": {
|
|
21
24
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_beforeActors",
|
|
22
25
|
"@container": "@list"
|
|
@@ -30,6 +33,9 @@
|
|
|
30
33
|
"bus": {
|
|
31
34
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_bus"
|
|
32
35
|
},
|
|
36
|
+
"busFailMessage": {
|
|
37
|
+
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_busFailMessage"
|
|
38
|
+
},
|
|
33
39
|
"beforeActors": {
|
|
34
40
|
"@id": "caqofq:components/ActorQueryOperationFromQuad.jsonld#ActorQueryOperationFromQuad_args_beforeActors",
|
|
35
41
|
"@container": "@list"
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';
|
|
2
2
|
import { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';
|
|
3
|
-
import type { IActorTest } from '@comunica/core';
|
|
3
|
+
import type { IActorTest, TestResult } from '@comunica/core';
|
|
4
4
|
import type { IActionContext, IQueryOperationResult } from '@comunica/types';
|
|
5
5
|
import type * as RDF from '@rdfjs/types';
|
|
6
|
-
import { Algebra } from 'sparqlalgebrajs';
|
|
6
|
+
import { Algebra, Factory } 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;
|
|
12
11
|
private static readonly ALGEBRA_TYPES;
|
|
13
12
|
constructor(args: IActorQueryOperationTypedMediatedArgs);
|
|
14
13
|
/**
|
|
@@ -21,32 +20,40 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
21
20
|
/**
|
|
22
21
|
* Recursively transform the given operation to use the given graphs as default graph
|
|
23
22
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
23
|
+
* @package
|
|
24
|
+
* @param algebraFactory The algebra factory.
|
|
24
25
|
* @param {Operation} operation An operation.
|
|
25
26
|
* @param {RDF.Term[]} defaultGraphs Graph terms.
|
|
26
27
|
* @return {Operation} A new operation.
|
|
27
28
|
*/
|
|
28
|
-
static applyOperationDefaultGraph(operation: Algebra.Operation, defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
29
|
+
static applyOperationDefaultGraph(algebraFactory: Factory, operation: Algebra.Operation, defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
29
30
|
/**
|
|
30
31
|
* Recursively transform the given operation to use the given graphs as named graph
|
|
31
32
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
33
|
+
* @package
|
|
34
|
+
* @param algebraFactory The algebra factory.
|
|
32
35
|
* @param {Operation} operation An operation.
|
|
33
36
|
* @param {RDF.Term[]} namedGraphs Graph terms.
|
|
34
37
|
* @param {RDF.Term[]} defaultGraphs Default graph terms.
|
|
35
38
|
* @return {Operation} A new operation.
|
|
36
39
|
*/
|
|
37
|
-
static applyOperationNamedGraph(operation: Algebra.Operation, namedGraphs: RDF.NamedNode[], defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
40
|
+
static applyOperationNamedGraph(algebraFactory: Factory, operation: Algebra.Operation, namedGraphs: RDF.NamedNode[], defaultGraphs: RDF.Term[]): Algebra.Operation;
|
|
38
41
|
/**
|
|
39
42
|
* Transform the given array of operations into a join operation.
|
|
43
|
+
* @package
|
|
44
|
+
* @param algebraFactory The algebra factory.
|
|
40
45
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
41
46
|
* @return {Join} A join operation.
|
|
42
47
|
*/
|
|
43
|
-
static joinOperations(operations: Algebra.Operation[]): Algebra.Operation;
|
|
48
|
+
static joinOperations(algebraFactory: Factory, operations: Algebra.Operation[]): Algebra.Operation;
|
|
44
49
|
/**
|
|
45
50
|
* Transform the given array of operations into a union operation.
|
|
51
|
+
* @package
|
|
52
|
+
* @param algebraFactory The algebra factory.
|
|
46
53
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
47
54
|
* @return {Union} A union operation.
|
|
48
55
|
*/
|
|
49
|
-
static unionOperations(operations: Algebra.Operation[]): Algebra.Operation;
|
|
56
|
+
static unionOperations(algebraFactory: Factory, operations: Algebra.Operation[]): Algebra.Operation;
|
|
50
57
|
/**
|
|
51
58
|
* Transform an operation based on the default and named graphs in the pattern.
|
|
52
59
|
*
|
|
@@ -56,10 +63,12 @@ export declare class ActorQueryOperationFromQuad extends ActorQueryOperationType
|
|
|
56
63
|
* FROM NAMED indicates which named graphs are available.
|
|
57
64
|
* This will rewrite the query so that only triples from the given named graphs can be selected.
|
|
58
65
|
*
|
|
66
|
+
* @package
|
|
67
|
+
* @param algebraFactory The algebra factory.
|
|
59
68
|
* @param {From} pattern A from operation.
|
|
60
69
|
* @return {Operation} The transformed operation.
|
|
61
70
|
*/
|
|
62
|
-
static createOperation(pattern: Algebra.From): Algebra.Operation;
|
|
63
|
-
testOperation(_operation: Algebra.From, _context: IActionContext): Promise<IActorTest
|
|
71
|
+
static createOperation(algebraFactory: Factory, pattern: Algebra.From): Algebra.Operation;
|
|
72
|
+
testOperation(_operation: Algebra.From, _context: IActionContext): Promise<TestResult<IActorTest>>;
|
|
64
73
|
runOperation(operationOriginal: Algebra.From, context: IActionContext): Promise<IQueryOperationResult>;
|
|
65
74
|
}
|
|
@@ -2,6 +2,8 @@
|
|
|
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");
|
|
5
7
|
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
6
8
|
/**
|
|
7
9
|
* A comunica From Query Operation Actor.
|
|
@@ -40,23 +42,26 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
40
42
|
/**
|
|
41
43
|
* Recursively transform the given operation to use the given graphs as default graph
|
|
42
44
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
45
|
+
* @package
|
|
46
|
+
* @param algebraFactory The algebra factory.
|
|
43
47
|
* @param {Operation} operation An operation.
|
|
44
48
|
* @param {RDF.Term[]} defaultGraphs Graph terms.
|
|
45
49
|
* @return {Operation} A new operation.
|
|
46
50
|
*/
|
|
47
|
-
static applyOperationDefaultGraph(operation, defaultGraphs) {
|
|
51
|
+
static applyOperationDefaultGraph(algebraFactory, operation, defaultGraphs) {
|
|
48
52
|
// If the operation is a BGP or Path, change the graph.
|
|
49
53
|
if ((operation.type === 'bgp' && operation.patterns.length > 0) ||
|
|
50
54
|
operation.type === 'path' ||
|
|
51
55
|
operation.type === 'pattern') {
|
|
52
56
|
if (operation.type === 'bgp') {
|
|
53
|
-
return ActorQueryOperationFromQuad
|
|
57
|
+
return ActorQueryOperationFromQuad
|
|
58
|
+
.joinOperations(algebraFactory, operation.patterns.map((pattern) => {
|
|
54
59
|
if (pattern.graph.termType !== 'DefaultGraph') {
|
|
55
|
-
return
|
|
60
|
+
return algebraFactory.createBgp([pattern]);
|
|
56
61
|
}
|
|
57
|
-
const bgps = defaultGraphs.map((graph) =>
|
|
62
|
+
const bgps = defaultGraphs.map((graph) => algebraFactory.createBgp([Object.assign(algebraFactory
|
|
58
63
|
.createPattern(pattern.subject, pattern.predicate, pattern.object, graph), { metadata: pattern.metadata })]));
|
|
59
|
-
return ActorQueryOperationFromQuad.unionOperations(bgps);
|
|
64
|
+
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, bgps);
|
|
60
65
|
}));
|
|
61
66
|
}
|
|
62
67
|
if (operation.graph.termType !== 'DefaultGraph') {
|
|
@@ -64,25 +69,27 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
64
69
|
}
|
|
65
70
|
const paths = defaultGraphs.map((graph) => {
|
|
66
71
|
if (operation.type === 'path') {
|
|
67
|
-
return
|
|
72
|
+
return algebraFactory
|
|
68
73
|
.createPath(operation.subject, operation.predicate, operation.object, graph);
|
|
69
74
|
}
|
|
70
|
-
return Object.assign(
|
|
75
|
+
return Object.assign(algebraFactory
|
|
71
76
|
.createPattern(operation.subject, operation.predicate, operation.object, graph), { metadata: operation.metadata });
|
|
72
77
|
});
|
|
73
|
-
return ActorQueryOperationFromQuad.unionOperations(paths);
|
|
78
|
+
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, paths);
|
|
74
79
|
}
|
|
75
|
-
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this.applyOperationDefaultGraph(subOperation, defaultGraphs));
|
|
80
|
+
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this.applyOperationDefaultGraph(algebraFactory, subOperation, defaultGraphs));
|
|
76
81
|
}
|
|
77
82
|
/**
|
|
78
83
|
* Recursively transform the given operation to use the given graphs as named graph
|
|
79
84
|
* This will (possibly) create a new operation and not modify the given operation.
|
|
85
|
+
* @package
|
|
86
|
+
* @param algebraFactory The algebra factory.
|
|
80
87
|
* @param {Operation} operation An operation.
|
|
81
88
|
* @param {RDF.Term[]} namedGraphs Graph terms.
|
|
82
89
|
* @param {RDF.Term[]} defaultGraphs Default graph terms.
|
|
83
90
|
* @return {Operation} A new operation.
|
|
84
91
|
*/
|
|
85
|
-
static applyOperationNamedGraph(operation, namedGraphs, defaultGraphs) {
|
|
92
|
+
static applyOperationNamedGraph(algebraFactory, operation, namedGraphs, defaultGraphs) {
|
|
86
93
|
// If the operation is a BGP or Path, change the graph.
|
|
87
94
|
if ((operation.type === 'bgp' && operation.patterns.length > 0) ||
|
|
88
95
|
operation.type === 'path' ||
|
|
@@ -99,26 +106,26 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
99
106
|
// If the pattern graph is a variable, replace the graph and bind the variable using VALUES
|
|
100
107
|
const bindings = {};
|
|
101
108
|
bindings[`?${patternGraph.value}`] = graph;
|
|
102
|
-
const values =
|
|
109
|
+
const values = algebraFactory
|
|
103
110
|
.createValues([patternGraph], [bindings]);
|
|
104
111
|
let pattern;
|
|
105
112
|
if (operation.type === 'bgp') {
|
|
106
|
-
pattern =
|
|
107
|
-
.createBgp(operation.patterns.map((pat) =>
|
|
113
|
+
pattern = algebraFactory
|
|
114
|
+
.createBgp(operation.patterns.map((pat) => algebraFactory
|
|
108
115
|
.createPattern(pat.subject, pat.predicate, pat.object, graph)));
|
|
109
116
|
}
|
|
110
117
|
else if (operation.type === 'path') {
|
|
111
|
-
pattern =
|
|
118
|
+
pattern = algebraFactory
|
|
112
119
|
.createPath(operation.subject, operation.predicate, operation.object, graph);
|
|
113
120
|
}
|
|
114
121
|
else {
|
|
115
|
-
pattern =
|
|
122
|
+
pattern = algebraFactory
|
|
116
123
|
.createPattern(operation.subject, operation.predicate, operation.object, graph);
|
|
117
124
|
}
|
|
118
|
-
return
|
|
125
|
+
return algebraFactory.createJoin([values, pattern]);
|
|
119
126
|
}
|
|
120
127
|
// If the pattern graph is a variable, take the union of the pattern applied to each available named graph
|
|
121
|
-
return ActorQueryOperationFromQuad.unionOperations(namedGraphs.map((graph) => ActorQueryOperationFromQuad.applyOperationNamedGraph(operation, [graph], defaultGraphs)));
|
|
128
|
+
return ActorQueryOperationFromQuad.unionOperations(algebraFactory, namedGraphs.map((graph) => ActorQueryOperationFromQuad.applyOperationNamedGraph(algebraFactory, operation, [graph], defaultGraphs)));
|
|
122
129
|
}
|
|
123
130
|
// The pattern's graph is defined (including the default graphs)
|
|
124
131
|
const isNamedGraphAvailable = [...namedGraphs, ...defaultGraphs].some((namedGraph) => namedGraph.equals(patternGraph));
|
|
@@ -129,33 +136,38 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
129
136
|
// No-op if the pattern's graph was not selected in a FROM NAMED.
|
|
130
137
|
return { type: sparqlalgebrajs_1.Algebra.types.BGP, patterns: [] };
|
|
131
138
|
}
|
|
132
|
-
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this
|
|
139
|
+
return ActorQueryOperationFromQuad.copyOperation(operation, (subOperation) => this
|
|
140
|
+
.applyOperationNamedGraph(algebraFactory, subOperation, namedGraphs, defaultGraphs));
|
|
133
141
|
}
|
|
134
142
|
/**
|
|
135
143
|
* Transform the given array of operations into a join operation.
|
|
144
|
+
* @package
|
|
145
|
+
* @param algebraFactory The algebra factory.
|
|
136
146
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
137
147
|
* @return {Join} A join operation.
|
|
138
148
|
*/
|
|
139
|
-
static joinOperations(operations) {
|
|
149
|
+
static joinOperations(algebraFactory, operations) {
|
|
140
150
|
if (operations.length === 1) {
|
|
141
151
|
return operations[0];
|
|
142
152
|
}
|
|
143
153
|
if (operations.length > 1) {
|
|
144
|
-
return
|
|
154
|
+
return algebraFactory.createJoin(operations);
|
|
145
155
|
}
|
|
146
156
|
throw new Error('A join can only be applied on at least one operation');
|
|
147
157
|
}
|
|
148
158
|
/**
|
|
149
159
|
* Transform the given array of operations into a union operation.
|
|
160
|
+
* @package
|
|
161
|
+
* @param algebraFactory The algebra factory.
|
|
150
162
|
* @param {Operation[]} operations An array of operations, must contain at least one operation.
|
|
151
163
|
* @return {Union} A union operation.
|
|
152
164
|
*/
|
|
153
|
-
static unionOperations(operations) {
|
|
165
|
+
static unionOperations(algebraFactory, operations) {
|
|
154
166
|
if (operations.length === 1) {
|
|
155
167
|
return operations[0];
|
|
156
168
|
}
|
|
157
169
|
if (operations.length > 1) {
|
|
158
|
-
return
|
|
170
|
+
return algebraFactory.createUnion(operations);
|
|
159
171
|
}
|
|
160
172
|
throw new Error('A union can only be applied on at least one operation');
|
|
161
173
|
}
|
|
@@ -168,28 +180,32 @@ class ActorQueryOperationFromQuad extends bus_query_operation_1.ActorQueryOperat
|
|
|
168
180
|
* FROM NAMED indicates which named graphs are available.
|
|
169
181
|
* This will rewrite the query so that only triples from the given named graphs can be selected.
|
|
170
182
|
*
|
|
183
|
+
* @package
|
|
184
|
+
* @param algebraFactory The algebra factory.
|
|
171
185
|
* @param {From} pattern A from operation.
|
|
172
186
|
* @return {Operation} The transformed operation.
|
|
173
187
|
*/
|
|
174
|
-
static createOperation(pattern) {
|
|
188
|
+
static createOperation(algebraFactory, pattern) {
|
|
175
189
|
let operation = pattern.input;
|
|
176
190
|
if (pattern.default.length > 0) {
|
|
177
|
-
operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(operation, pattern.default);
|
|
191
|
+
operation = ActorQueryOperationFromQuad.applyOperationDefaultGraph(algebraFactory, operation, pattern.default);
|
|
178
192
|
}
|
|
179
193
|
if (pattern.named.length > 0 || pattern.default.length > 0) {
|
|
180
|
-
operation = ActorQueryOperationFromQuad
|
|
194
|
+
operation = ActorQueryOperationFromQuad
|
|
195
|
+
.applyOperationNamedGraph(algebraFactory, operation, pattern.named, pattern.default);
|
|
181
196
|
}
|
|
182
197
|
return operation;
|
|
183
198
|
}
|
|
184
199
|
async testOperation(_operation, _context) {
|
|
185
|
-
return
|
|
200
|
+
return (0, core_1.passTestVoid)();
|
|
186
201
|
}
|
|
187
202
|
async runOperation(operationOriginal, context) {
|
|
188
|
-
const
|
|
203
|
+
const dataFactory = context.getSafe(context_entries_1.KeysInitQuery.dataFactory);
|
|
204
|
+
const algebraFactory = new sparqlalgebrajs_1.Factory(dataFactory);
|
|
205
|
+
const operation = ActorQueryOperationFromQuad.createOperation(algebraFactory, operationOriginal);
|
|
189
206
|
return this.mediatorQueryOperation.mediate({ operation, context });
|
|
190
207
|
}
|
|
191
208
|
}
|
|
192
209
|
exports.ActorQueryOperationFromQuad = ActorQueryOperationFromQuad;
|
|
193
|
-
ActorQueryOperationFromQuad.FACTORY = new sparqlalgebrajs_1.Factory();
|
|
194
210
|
ActorQueryOperationFromQuad.ALGEBRA_TYPES = Object.keys(sparqlalgebrajs_1.Algebra.types).map(key => sparqlalgebrajs_1.Algebra.types[key]);
|
|
195
211
|
//# sourceMappingURL=ActorQueryOperationFromQuad.js.map
|
|
@@ -1 +1 @@
|
|
|
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,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,U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C/B,SAAS,GAAG,2BAA2B,CAAC,0BAA0B,CAAC,SAAS,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QACjG,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC3D,SAAS,GAAG,2BAA2B,CAAC,wBAAwB,CAAC,SAAS,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC9G,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,UAAwB,EAAE,QAAwB;QAC3E,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,YAAY,CACvB,iBAA+B,EAC/B,OAAuB;QAEvB,MAAM,SAAS,GAAsB,2BAA2B,CAAC,eAAe,CAAC,iBAAiB,CAAC,CAAC;QACpG,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;;AAlOH,kEAmOC;AAlOyB,mCAAO,GAAY,IAAI,yBAAO,EAAE,CAAC;AACjC,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 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"]}
|
|
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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,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"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-query-operation-from-quad",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.4-alpha.47.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
|
+
},
|
|
7
11
|
"homepage": "https://comunica.dev/",
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
@@ -37,11 +41,12 @@
|
|
|
37
41
|
"build:components": "componentsjs-generator"
|
|
38
42
|
},
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"@comunica/bus-query-operation": "
|
|
41
|
-
"@comunica/
|
|
42
|
-
"@comunica/
|
|
44
|
+
"@comunica/bus-query-operation": "3.2.4-alpha.47.0",
|
|
45
|
+
"@comunica/context-entries": "3.2.4-alpha.47.0",
|
|
46
|
+
"@comunica/core": "3.2.4-alpha.47.0",
|
|
47
|
+
"@comunica/types": "3.2.4-alpha.47.0",
|
|
43
48
|
"@rdfjs/types": "*",
|
|
44
|
-
"sparqlalgebrajs": "^4.3.
|
|
49
|
+
"sparqlalgebrajs": "^4.3.8"
|
|
45
50
|
},
|
|
46
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "85bd4c5cf07dfc293ebbc3a1416b70e2db8bfc48"
|
|
47
52
|
}
|