@comunica/bus-query-operation 2.10.0 → 3.0.1-alpha.43.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.
- package/README.md +2 -2
- package/components/ActorQueryOperation.jsonld +28 -16
- package/components/ActorQueryOperationTyped.jsonld +11 -11
- package/components/ActorQueryOperationTypedMediated.jsonld +11 -11
- package/components/BusQueryOperation.jsonld +3 -3
- package/components/components.jsonld +1 -1
- package/components/context.jsonld +1 -1
- package/lib/ActorQueryOperation.d.ts +38 -9
- package/lib/ActorQueryOperation.js +58 -25
- package/lib/ActorQueryOperation.js.map +1 -1
- package/lib/ActorQueryOperationTyped.js +2 -2
- package/lib/ActorQueryOperationTyped.js.map +1 -1
- package/lib/Bindings.d.ts +2 -1
- package/lib/Bindings.js +22 -8
- package/lib/Bindings.js.map +1 -1
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -17,12 +17,12 @@ $ yarn add @comunica/bus-query-operation
|
|
|
17
17
|
|
|
18
18
|
## Bus usage
|
|
19
19
|
|
|
20
|
-
* **Context**: `"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^
|
|
20
|
+
* **Context**: `"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^3.0.0/components/context.jsonld"`
|
|
21
21
|
* **Bus name**: `ActorQueryOperation:_default_bus`
|
|
22
22
|
|
|
23
23
|
## Creating actors on this bus
|
|
24
24
|
|
|
25
|
-
Actors extending [`ActorQueryOperation`](https://comunica.github.io/comunica/classes/
|
|
25
|
+
Actors extending [`ActorQueryOperation`](https://comunica.github.io/comunica/classes/_comunica_bus_query_operation.ActorQueryOperation.html) or [`ActorQueryOperationTyped`](https://comunica.github.io/comunica/classes/_comunica_bus_query_operation.ActorQueryOperationTyped.html) are automatically subscribed to this bus.
|
|
26
26
|
|
|
27
27
|
It is recommended to extend from `ActorQueryOperationTyped` if your actor supports a single query operation,
|
|
28
28
|
as the bus will be able to handle this actor more efficiently.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
5
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/types/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^3.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^3.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/types/^3.0.0/components/context.jsonld"
|
|
6
6
|
],
|
|
7
7
|
"@id": "npmd:@comunica/bus-query-operation",
|
|
8
8
|
"components": [
|
|
@@ -51,29 +51,29 @@
|
|
|
51
51
|
"genericTypeInstances": [
|
|
52
52
|
{
|
|
53
53
|
"@type": "ParameterRangeGenericTypeReference",
|
|
54
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
54
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
55
55
|
},
|
|
56
56
|
{
|
|
57
57
|
"@type": "ParameterRangeGenericTypeReference",
|
|
58
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
58
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
61
|
"@type": "ParameterRangeGenericTypeReference",
|
|
62
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
62
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
63
63
|
}
|
|
64
64
|
]
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
"@type": "ParameterRangeGenericTypeReference",
|
|
68
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
68
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
"@type": "ParameterRangeGenericTypeReference",
|
|
72
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
72
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
73
73
|
},
|
|
74
74
|
{
|
|
75
75
|
"@type": "ParameterRangeGenericTypeReference",
|
|
76
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
76
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
77
77
|
}
|
|
78
78
|
]
|
|
79
79
|
},
|
|
@@ -96,15 +96,15 @@
|
|
|
96
96
|
"genericTypeInstances": [
|
|
97
97
|
{
|
|
98
98
|
"@type": "ParameterRangeGenericTypeReference",
|
|
99
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
99
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
"@type": "ParameterRangeGenericTypeReference",
|
|
103
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
103
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
104
104
|
},
|
|
105
105
|
{
|
|
106
106
|
"@type": "ParameterRangeGenericTypeReference",
|
|
107
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
107
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
108
108
|
}
|
|
109
109
|
]
|
|
110
110
|
}
|
|
@@ -138,10 +138,6 @@
|
|
|
138
138
|
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation__member_getSafeVoid",
|
|
139
139
|
"memberFieldName": "getSafeVoid"
|
|
140
140
|
},
|
|
141
|
-
{
|
|
142
|
-
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation__member_cachifyMetadata",
|
|
143
|
-
"memberFieldName": "cachifyMetadata"
|
|
144
|
-
},
|
|
145
141
|
{
|
|
146
142
|
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation__member_validateQueryOutput",
|
|
147
143
|
"memberFieldName": "validateQueryOutput"
|
|
@@ -165,6 +161,22 @@
|
|
|
165
161
|
{
|
|
166
162
|
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation__member_throwOnReadOnly",
|
|
167
163
|
"memberFieldName": "throwOnReadOnly"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation__member_getOperationSource",
|
|
167
|
+
"memberFieldName": "getOperationSource"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation__member_assignOperationSource",
|
|
171
|
+
"memberFieldName": "assignOperationSource"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation__member_removeOperationSource",
|
|
175
|
+
"memberFieldName": "removeOperationSource"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation__member_doesShapeAcceptOperation",
|
|
179
|
+
"memberFieldName": "doesShapeAcceptOperation"
|
|
168
180
|
}
|
|
169
181
|
],
|
|
170
182
|
"constructorArguments": [
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^3.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^3.0.0/components/context.jsonld"
|
|
5
5
|
],
|
|
6
6
|
"@id": "npmd:@comunica/bus-query-operation",
|
|
7
7
|
"components": [
|
|
@@ -112,29 +112,29 @@
|
|
|
112
112
|
"genericTypeInstances": [
|
|
113
113
|
{
|
|
114
114
|
"@type": "ParameterRangeGenericTypeReference",
|
|
115
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
115
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
116
116
|
},
|
|
117
117
|
{
|
|
118
118
|
"@type": "ParameterRangeGenericTypeReference",
|
|
119
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
119
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
122
|
"@type": "ParameterRangeGenericTypeReference",
|
|
123
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
123
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
124
124
|
}
|
|
125
125
|
]
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
128
|
"@type": "ParameterRangeGenericTypeReference",
|
|
129
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
129
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
130
130
|
},
|
|
131
131
|
{
|
|
132
132
|
"@type": "ParameterRangeGenericTypeReference",
|
|
133
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
133
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
136
|
"@type": "ParameterRangeGenericTypeReference",
|
|
137
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
137
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
138
138
|
}
|
|
139
139
|
]
|
|
140
140
|
},
|
|
@@ -157,15 +157,15 @@
|
|
|
157
157
|
"genericTypeInstances": [
|
|
158
158
|
{
|
|
159
159
|
"@type": "ParameterRangeGenericTypeReference",
|
|
160
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
160
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
161
161
|
},
|
|
162
162
|
{
|
|
163
163
|
"@type": "ParameterRangeGenericTypeReference",
|
|
164
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
164
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
165
165
|
},
|
|
166
166
|
{
|
|
167
167
|
"@type": "ParameterRangeGenericTypeReference",
|
|
168
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
168
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
169
169
|
}
|
|
170
170
|
]
|
|
171
171
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^3.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^3.0.0/components/context.jsonld"
|
|
5
5
|
],
|
|
6
6
|
"@id": "npmd:@comunica/bus-query-operation",
|
|
7
7
|
"components": [
|
|
@@ -126,29 +126,29 @@
|
|
|
126
126
|
"genericTypeInstances": [
|
|
127
127
|
{
|
|
128
128
|
"@type": "ParameterRangeGenericTypeReference",
|
|
129
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
129
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
130
130
|
},
|
|
131
131
|
{
|
|
132
132
|
"@type": "ParameterRangeGenericTypeReference",
|
|
133
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
133
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
136
|
"@type": "ParameterRangeGenericTypeReference",
|
|
137
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
137
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
138
138
|
}
|
|
139
139
|
]
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
142
|
"@type": "ParameterRangeGenericTypeReference",
|
|
143
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
143
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
144
144
|
},
|
|
145
145
|
{
|
|
146
146
|
"@type": "ParameterRangeGenericTypeReference",
|
|
147
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
147
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
148
148
|
},
|
|
149
149
|
{
|
|
150
150
|
"@type": "ParameterRangeGenericTypeReference",
|
|
151
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
151
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
152
152
|
}
|
|
153
153
|
]
|
|
154
154
|
},
|
|
@@ -171,15 +171,15 @@
|
|
|
171
171
|
"genericTypeInstances": [
|
|
172
172
|
{
|
|
173
173
|
"@type": "ParameterRangeGenericTypeReference",
|
|
174
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
174
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
175
175
|
},
|
|
176
176
|
{
|
|
177
177
|
"@type": "ParameterRangeGenericTypeReference",
|
|
178
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
178
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
179
179
|
},
|
|
180
180
|
{
|
|
181
181
|
"@type": "ParameterRangeGenericTypeReference",
|
|
182
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
182
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^3.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
183
183
|
}
|
|
184
184
|
]
|
|
185
185
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
5
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/types/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^3.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^3.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/types/^3.0.0/components/context.jsonld"
|
|
6
6
|
],
|
|
7
7
|
"@id": "npmd:@comunica/bus-query-operation",
|
|
8
8
|
"components": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^3.0.0/components/context.jsonld"
|
|
4
4
|
],
|
|
5
5
|
"@id": "npmd:@comunica/bus-query-operation",
|
|
6
6
|
"@type": "Module",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld",
|
|
4
4
|
{
|
|
5
5
|
"npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
|
|
6
|
-
"cbqo": "npmd:@comunica/bus-query-operation/^
|
|
6
|
+
"cbqo": "npmd:@comunica/bus-query-operation/^3.0.0/",
|
|
7
7
|
"ActorQueryOperation": {
|
|
8
8
|
"@id": "cbqo:components/ActorQueryOperation.jsonld#ActorQueryOperation",
|
|
9
9
|
"@prefix": true,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { BindingsFactory } from '@comunica/bindings-factory';
|
|
1
2
|
import type { IActorArgs, IActorTest, IAction, Mediate } from '@comunica/core';
|
|
2
3
|
import { Actor } from '@comunica/core';
|
|
3
|
-
import type { IQueryOperationResult, IQueryOperationResultBindings, IQueryOperationResultBoolean, IQueryOperationResultQuads, IQueryOperationResultVoid, Bindings,
|
|
4
|
+
import type { IQueryOperationResult, IQueryOperationResultBindings, IQueryOperationResultBoolean, IQueryOperationResultQuads, IQueryOperationResultVoid, Bindings, IActionContext, FunctionArgumentsCache, IQuerySourceWrapper, FragmentSelectorShape } from '@comunica/types';
|
|
4
5
|
import type * as RDF from '@rdfjs/types';
|
|
5
6
|
import type { Algebra } from 'sparqlalgebrajs';
|
|
6
7
|
/**
|
|
@@ -47,12 +48,6 @@ export declare abstract class ActorQueryOperation extends Actor<IActionQueryOper
|
|
|
47
48
|
* @return {IQueryOperationResultVoid} A void query operation output.
|
|
48
49
|
*/
|
|
49
50
|
static getSafeVoid(output: IQueryOperationResult): IQueryOperationResultVoid;
|
|
50
|
-
/**
|
|
51
|
-
* Convert a metadata callback to a lazy callback where the response value is cached.
|
|
52
|
-
* @param {() => Promise<IMetadata>} metadata A metadata callback
|
|
53
|
-
* @return {() => Promise<{[p: string]: any}>} The callback where the response will be cached.
|
|
54
|
-
*/
|
|
55
|
-
static cachifyMetadata<M extends IMetadata<T>, T extends RDF.Variable | RDF.QuadTermName>(metadata: () => Promise<M>): () => Promise<M>;
|
|
56
51
|
/**
|
|
57
52
|
* Throw an error if the output type does not match the expected type.
|
|
58
53
|
* @param {IQueryOperationResult} output A query operation output.
|
|
@@ -72,18 +67,52 @@ export declare abstract class ActorQueryOperation extends Actor<IActionQueryOper
|
|
|
72
67
|
* @param context An action context.
|
|
73
68
|
* @param mediatorQueryOperation A query query operation mediator for resolving `exists`.
|
|
74
69
|
*/
|
|
75
|
-
static getAsyncExpressionContext(context: IActionContext, mediatorQueryOperation: MediatorQueryOperation): IAsyncExpressionContext;
|
|
70
|
+
static getAsyncExpressionContext(context: IActionContext, mediatorQueryOperation: MediatorQueryOperation, bindingsFactory: BindingsFactory): IAsyncExpressionContext;
|
|
76
71
|
/**
|
|
77
72
|
* Create an existence resolver for usage within an expression context.
|
|
78
73
|
* @param context An action context.
|
|
79
74
|
* @param mediatorQueryOperation A query operation mediator.
|
|
80
75
|
*/
|
|
81
|
-
static createExistenceResolver(context: IActionContext, mediatorQueryOperation: MediatorQueryOperation): (expr: Algebra.ExistenceExpression, bindings: Bindings) => Promise<boolean>;
|
|
76
|
+
static createExistenceResolver(context: IActionContext, mediatorQueryOperation: MediatorQueryOperation, bindingsFactory: BindingsFactory): (expr: Algebra.ExistenceExpression, bindings: Bindings) => Promise<boolean>;
|
|
82
77
|
/**
|
|
83
78
|
* Throw an error if the context contains the readOnly flag.
|
|
84
79
|
* @param context An action context.
|
|
85
80
|
*/
|
|
86
81
|
static throwOnReadOnly(context: IActionContext): void;
|
|
82
|
+
/**
|
|
83
|
+
* Obtain the query source attached to the given operation.
|
|
84
|
+
* @param operation An algebra operation.
|
|
85
|
+
*/
|
|
86
|
+
static getOperationSource(operation: Algebra.Operation): IQuerySourceWrapper | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Assign a source wrapper to the given operation.
|
|
89
|
+
* The operation is copied and returned.
|
|
90
|
+
* @param operation An operation.
|
|
91
|
+
* @param source A source wrapper.
|
|
92
|
+
*/
|
|
93
|
+
static assignOperationSource<O extends Algebra.Operation>(operation: O, source: IQuerySourceWrapper): O;
|
|
94
|
+
/**
|
|
95
|
+
* Remove the source wrapper from the given operation.
|
|
96
|
+
* The operation is mutated.
|
|
97
|
+
* @param operation An operation.
|
|
98
|
+
*/
|
|
99
|
+
static removeOperationSource(operation: Algebra.Operation): void;
|
|
100
|
+
/**
|
|
101
|
+
* Check if the given shape accepts the given query operation.
|
|
102
|
+
* @param shape A shape to test the query operation against.
|
|
103
|
+
* @param operation A query operation to test.
|
|
104
|
+
* @param options Additional options to consider.
|
|
105
|
+
*/
|
|
106
|
+
static doesShapeAcceptOperation(shape: FragmentSelectorShape, operation: Algebra.Operation, options?: {
|
|
107
|
+
/**
|
|
108
|
+
* If additional bindings will be pushed down to the source for joining.
|
|
109
|
+
*/
|
|
110
|
+
joinBindings?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* If additional bindings will be pushed down to the source for filtering.
|
|
113
|
+
*/
|
|
114
|
+
filterBindings?: boolean;
|
|
115
|
+
}): boolean;
|
|
87
116
|
}
|
|
88
117
|
export interface IActionQueryOperation extends IAction {
|
|
89
118
|
/**
|
|
@@ -70,27 +70,6 @@ class ActorQueryOperation extends core_1.Actor {
|
|
|
70
70
|
ActorQueryOperation.validateQueryOutput(output, 'void');
|
|
71
71
|
return output;
|
|
72
72
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Convert a metadata callback to a lazy callback where the response value is cached.
|
|
75
|
-
* @param {() => Promise<IMetadata>} metadata A metadata callback
|
|
76
|
-
* @return {() => Promise<{[p: string]: any}>} The callback where the response will be cached.
|
|
77
|
-
*/
|
|
78
|
-
static cachifyMetadata(metadata) {
|
|
79
|
-
let lastReturn;
|
|
80
|
-
return () => {
|
|
81
|
-
if (!lastReturn) {
|
|
82
|
-
lastReturn = metadata();
|
|
83
|
-
lastReturn
|
|
84
|
-
.then(lastReturnValue => lastReturnValue.state.addInvalidateListener(() => {
|
|
85
|
-
lastReturn = undefined;
|
|
86
|
-
}))
|
|
87
|
-
.catch(() => {
|
|
88
|
-
// Ignore error
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return lastReturn;
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
73
|
/**
|
|
95
74
|
* Throw an error if the output type does not match the expected type.
|
|
96
75
|
* @param {IQueryOperationResult} output A query operation output.
|
|
@@ -136,11 +115,11 @@ class ActorQueryOperation extends core_1.Actor {
|
|
|
136
115
|
* @param context An action context.
|
|
137
116
|
* @param mediatorQueryOperation A query query operation mediator for resolving `exists`.
|
|
138
117
|
*/
|
|
139
|
-
static getAsyncExpressionContext(context, mediatorQueryOperation) {
|
|
118
|
+
static getAsyncExpressionContext(context, mediatorQueryOperation, bindingsFactory) {
|
|
140
119
|
return {
|
|
141
120
|
...this.getBaseExpressionContext(context),
|
|
142
121
|
bnode: (input) => Promise.resolve(new data_factory_1.BlankNodeBindingsScoped(input || `BNODE_${bnodeCounter++}`)),
|
|
143
|
-
exists: ActorQueryOperation.createExistenceResolver(context, mediatorQueryOperation),
|
|
122
|
+
exists: ActorQueryOperation.createExistenceResolver(context, mediatorQueryOperation, bindingsFactory),
|
|
144
123
|
};
|
|
145
124
|
}
|
|
146
125
|
/**
|
|
@@ -148,9 +127,9 @@ class ActorQueryOperation extends core_1.Actor {
|
|
|
148
127
|
* @param context An action context.
|
|
149
128
|
* @param mediatorQueryOperation A query operation mediator.
|
|
150
129
|
*/
|
|
151
|
-
static createExistenceResolver(context, mediatorQueryOperation) {
|
|
130
|
+
static createExistenceResolver(context, mediatorQueryOperation, bindingsFactory) {
|
|
152
131
|
return async (expr, bindings) => {
|
|
153
|
-
const operation = (0, Bindings_1.materializeOperation)(expr.input, bindings);
|
|
132
|
+
const operation = (0, Bindings_1.materializeOperation)(expr.input, bindings, bindingsFactory);
|
|
154
133
|
const outputRaw = await mediatorQueryOperation.mediate({ operation, context });
|
|
155
134
|
const output = ActorQueryOperation.getSafeBindings(outputRaw);
|
|
156
135
|
return new Promise((resolve, reject) => {
|
|
@@ -175,6 +154,60 @@ class ActorQueryOperation extends core_1.Actor {
|
|
|
175
154
|
throw new Error(`Attempted a write operation in read-only mode`);
|
|
176
155
|
}
|
|
177
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Obtain the query source attached to the given operation.
|
|
159
|
+
* @param operation An algebra operation.
|
|
160
|
+
*/
|
|
161
|
+
static getOperationSource(operation) {
|
|
162
|
+
return operation.metadata?.scopedSource;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Assign a source wrapper to the given operation.
|
|
166
|
+
* The operation is copied and returned.
|
|
167
|
+
* @param operation An operation.
|
|
168
|
+
* @param source A source wrapper.
|
|
169
|
+
*/
|
|
170
|
+
static assignOperationSource(operation, source) {
|
|
171
|
+
operation = { ...operation };
|
|
172
|
+
operation.metadata = operation.metadata ? { ...operation.metadata } : {};
|
|
173
|
+
operation.metadata.scopedSource = source;
|
|
174
|
+
return operation;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Remove the source wrapper from the given operation.
|
|
178
|
+
* The operation is mutated.
|
|
179
|
+
* @param operation An operation.
|
|
180
|
+
*/
|
|
181
|
+
static removeOperationSource(operation) {
|
|
182
|
+
delete operation.metadata?.scopedSource;
|
|
183
|
+
if (operation.metadata && Object.keys(operation.metadata).length === 0) {
|
|
184
|
+
delete operation.metadata;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Check if the given shape accepts the given query operation.
|
|
189
|
+
* @param shape A shape to test the query operation against.
|
|
190
|
+
* @param operation A query operation to test.
|
|
191
|
+
* @param options Additional options to consider.
|
|
192
|
+
*/
|
|
193
|
+
static doesShapeAcceptOperation(shape, operation, options) {
|
|
194
|
+
if (shape.type === 'conjunction') {
|
|
195
|
+
return shape.children.every(child => ActorQueryOperation.doesShapeAcceptOperation(child, operation, options));
|
|
196
|
+
}
|
|
197
|
+
if (shape.type === 'disjunction') {
|
|
198
|
+
return shape.children.some(child => ActorQueryOperation.doesShapeAcceptOperation(child, operation, options));
|
|
199
|
+
}
|
|
200
|
+
if (shape.type === 'arity') {
|
|
201
|
+
return ActorQueryOperation.doesShapeAcceptOperation(shape.child, operation, options);
|
|
202
|
+
}
|
|
203
|
+
if ((options?.joinBindings && !shape.joinBindings) || options?.filterBindings && !shape.filterBindings) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (shape.operation.operationType === 'type') {
|
|
207
|
+
return shape.operation.type === 'project' || shape.operation.type === operation.type;
|
|
208
|
+
}
|
|
209
|
+
return shape.operation.pattern.type === operation.type;
|
|
210
|
+
}
|
|
178
211
|
}
|
|
179
212
|
exports.ActorQueryOperation = ActorQueryOperation;
|
|
180
213
|
//# sourceMappingURL=ActorQueryOperation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorQueryOperation.js","sourceRoot":"","sources":["ActorQueryOperation.ts"],"names":[],"mappings":";;;AAAA,+DAA8E;AAE9E,yCAAuC;AACvC,yDAAiE;AAWjE,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;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C,CAAC,MAAe,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QAC5D,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,eAAe,CAAC,OAAuB;QACnD,IAAI,OAAO,CAAC,GAAG,CAAC,oCAAkB,CAAC,QAAQ,CAAC,EAAE;YAC5C,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SAClE;IACH,CAAC;CACF;AAjLD,kDAiLC","sourcesContent":["import { 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 { IQueryOperationResult,\n IQueryOperationResultBindings,\n IQueryOperationResultBoolean,\n IQueryOperationResultQuads,\n IQueryOperationResultVoid,\n Bindings,\n IMetadata, IActionContext,\n FunctionArgumentsCache } 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 * Convert a metadata callback to a lazy callback where the response value is cached.\n * @param {() => Promise<IMetadata>} metadata A metadata callback\n * @return {() => Promise<{[p: string]: any}>} The callback where the response will be cached.\n */\n public static cachifyMetadata<M extends IMetadata<T>, T extends RDF.Variable | RDF.QuadTermName>(\n metadata: () => Promise<M>,\n ): () => Promise<M> {\n let lastReturn: Promise<M> | undefined;\n return () => {\n if (!lastReturn) {\n lastReturn = metadata();\n lastReturn\n .then(lastReturnValue => lastReturnValue.state.addInvalidateListener(() => {\n lastReturn = undefined;\n }))\n .catch(() => {\n // Ignore error\n });\n }\n return lastReturn;\n };\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 */\n public static getAsyncExpressionContext(context: IActionContext, mediatorQueryOperation: MediatorQueryOperation):\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),\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 */\n public static createExistenceResolver(context: IActionContext, mediatorQueryOperation: MediatorQueryOperation):\n (expr: Algebra.ExistenceExpression, bindings: Bindings) => Promise<boolean> {\n return async(expr, bindings) => {\n const operation = materializeOperation(expr.input, bindings);\n\n const outputRaw = await mediatorQueryOperation.mediate({ operation, context });\n const output = ActorQueryOperation.getSafeBindings(outputRaw);\n\n return new Promise(\n (resolve, reject) => {\n output.bindingsStream.on('end', () => {\n resolve(false);\n });\n\n output.bindingsStream.on('error', reject);\n\n output.bindingsStream.on('data', () => {\n output.bindingsStream.close();\n resolve(true);\n });\n },\n )\n .then((exists: boolean) => expr.not ? !exists : exists);\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\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,+DAA8E;AAE9E,yCAAuC;AACvC,yDAAiE;AAWjE,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,OAAmC,MAAM,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,mBAAmB,CAAC,MAA6B,EAAE,YAA2C;QAC1G,IAAI,MAAM,CAA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AwB,CACpC,KAA4B,EAC5B,SAA4B,EAC5B,OASC;QAED,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE;YAChC,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAAC,wBAAwB,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;SAC/G;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,aAAa,EAAE;YAChC,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,mBAAmB,CAAC,wBAAwB,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;SAC9G;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;YAC1B,OAAO,mBAAmB,CAAC,wBAAwB,CAAC,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;SACtF;QAED,IAAI,CAAC,OAAO,EAAE,YAAY,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,OAAO,EAAE,cAAc,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;YACtG,OAAO,KAAK,CAAC;SACd;QAED,IAAI,KAAK,CAAC,SAAS,CAAC,aAAa,KAAK,MAAM,EAAE;YAC5C,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC;SACtF;QACD,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAC;IACzD,CAAC;CACF;AAtOD,kDAsOC","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 { IQueryOperationResult,\n IQueryOperationResultBindings,\n IQueryOperationResultBoolean,\n IQueryOperationResultQuads,\n IQueryOperationResultVoid,\n Bindings, IActionContext,\n FunctionArgumentsCache, IQuerySourceWrapper,\n FragmentSelectorShape } 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 */\n public static getAsyncExpressionContext(context: IActionContext,\n mediatorQueryOperation: MediatorQueryOperation,\n bindingsFactory: BindingsFactory):\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 */\n public static createExistenceResolver(context: IActionContext,\n mediatorQueryOperation: MediatorQueryOperation,\n bindingsFactory: BindingsFactory):\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\n return new Promise(\n (resolve, reject) => {\n output.bindingsStream.on('end', () => {\n resolve(false);\n });\n\n output.bindingsStream.on('error', reject);\n\n output.bindingsStream.on('data', () => {\n output.bindingsStream.close();\n resolve(true);\n });\n },\n )\n .then((exists: boolean) => expr.not ? !exists : exists);\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 */\n public static doesShapeAcceptOperation(\n shape: FragmentSelectorShape,\n operation: Algebra.Operation,\n options?: {\n /**\n * If additional bindings will be pushed down to the source for joining.\n */\n joinBindings?: boolean;\n /**\n * If additional bindings will be pushed down to the source for filtering.\n */\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"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
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
6
|
const ActorQueryOperation_1 = require("./ActorQueryOperation");
|
|
6
7
|
/**
|
|
7
8
|
* A base implementation for query operation actors for a specific operation type.
|
|
@@ -35,8 +36,7 @@ class ActorQueryOperationTyped extends ActorQueryOperation_1.ActorQueryOperation
|
|
|
35
36
|
const subContext = action.context.set(context_entries_1.KeysQueryOperation.operation, operation);
|
|
36
37
|
const output = await this.runOperation(operation, subContext);
|
|
37
38
|
if ('metadata' in output) {
|
|
38
|
-
output.metadata =
|
|
39
|
-
.cachifyMetadata(output.metadata);
|
|
39
|
+
output.metadata = (0, metadata_1.cachifyMetadata)(output.metadata);
|
|
40
40
|
}
|
|
41
41
|
return output;
|
|
42
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorQueryOperationTyped.js","sourceRoot":"","sources":["ActorQueryOperationTyped.ts"],"names":[],"mappings":";;;AAAA,+DAA8E;
|
|
1
|
+
{"version":3,"file":"ActorQueryOperationTyped.js","sourceRoot":"","sources":["ActorQueryOperationTyped.ts"],"names":[],"mappings":";;;AAAA,+DAA8E;AAE9E,iDAAqD;AASrD,+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;YACvB,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;SACvE;IACH,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAA6B;QAC7C,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;SAC7E;QACD,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,aAAa,EAAE;YAChD,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,kBAAkB,IAAI,CAAC,aAAa,wBACpE,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;SAC5B;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;YAC3B,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;SAC5F;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;YACxB,MAAM,CAAC,QAAQ,GACb,IAAA,0BAAe,EAA8E,MAAM,CAAC,QAAQ,CAAC,CAAC;SACjH;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, 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"]}
|
package/lib/Bindings.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BindingsFactory } from '@comunica/bindings-factory';
|
|
1
2
|
import type { Bindings } from '@comunica/types';
|
|
2
3
|
import type * as RDF from '@rdfjs/types';
|
|
3
4
|
import type { Algebra } from 'sparqlalgebrajs';
|
|
@@ -23,7 +24,7 @@ export declare function materializeTerm(term: RDF.Term, bindings: Bindings): RDF
|
|
|
23
24
|
* @param options Options for materializations.
|
|
24
25
|
* @return Algebra.Operation A new operation materialized with the given bindings.
|
|
25
26
|
*/
|
|
26
|
-
export declare function materializeOperation(operation: Algebra.Operation, bindings: Bindings, options?: {
|
|
27
|
+
export declare function materializeOperation(operation: Algebra.Operation, bindings: Bindings, bindingsFactory: BindingsFactory, options?: {
|
|
27
28
|
/**
|
|
28
29
|
* If target variable bindings (such as on SELECT or BIND) should not be allowed.
|
|
29
30
|
*/
|
package/lib/Bindings.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.materializeOperation = exports.materializeTerm = void 0;
|
|
4
|
-
const
|
|
4
|
+
const rdf_data_factory_1 = require("rdf-data-factory");
|
|
5
5
|
const rdf_string_1 = require("rdf-string");
|
|
6
6
|
const rdf_terms_1 = require("rdf-terms");
|
|
7
7
|
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
8
|
-
const
|
|
8
|
+
const DF = new rdf_data_factory_1.DataFactory();
|
|
9
|
+
const TRUE = DF.literal('true', DF.namedNode('http://www.w3.org/2001/XMLSchema#boolean'));
|
|
9
10
|
/**
|
|
10
11
|
* Materialize a term with the given binding.
|
|
11
12
|
*
|
|
@@ -40,7 +41,7 @@ exports.materializeTerm = materializeTerm;
|
|
|
40
41
|
* @param options Options for materializations.
|
|
41
42
|
* @return Algebra.Operation A new operation materialized with the given bindings.
|
|
42
43
|
*/
|
|
43
|
-
function materializeOperation(operation, bindings, options = {}) {
|
|
44
|
+
function materializeOperation(operation, bindings, bindingsFactory, options = {}) {
|
|
44
45
|
options = {
|
|
45
46
|
strictTargetVariables: 'strictTargetVariables' in options ? options.strictTargetVariables : false,
|
|
46
47
|
bindFilter: 'bindFilter' in options ? options.bindFilter : true,
|
|
@@ -51,14 +52,14 @@ function materializeOperation(operation, bindings, options = {}) {
|
|
|
51
52
|
// The predicate expression will be recursed.
|
|
52
53
|
return {
|
|
53
54
|
recurse: false,
|
|
54
|
-
result: factory.createPath(materializeTerm(op.subject, bindings), op.predicate, materializeTerm(op.object, bindings), materializeTerm(op.graph, bindings)),
|
|
55
|
+
result: Object.assign(factory.createPath(materializeTerm(op.subject, bindings), op.predicate, materializeTerm(op.object, bindings), materializeTerm(op.graph, bindings)), { metadata: op.metadata }),
|
|
55
56
|
};
|
|
56
57
|
},
|
|
57
58
|
pattern(op, factory) {
|
|
58
59
|
// Materialize variables in the quad pattern.
|
|
59
60
|
return {
|
|
60
61
|
recurse: false,
|
|
61
|
-
result: factory.createPattern(materializeTerm(op.subject, bindings), materializeTerm(op.predicate, bindings), materializeTerm(op.object, bindings), materializeTerm(op.graph, bindings)),
|
|
62
|
+
result: Object.assign(factory.createPattern(materializeTerm(op.subject, bindings), materializeTerm(op.predicate, bindings), materializeTerm(op.object, bindings), materializeTerm(op.graph, bindings)), { metadata: op.metadata }),
|
|
62
63
|
};
|
|
63
64
|
},
|
|
64
65
|
extend(op) {
|
|
@@ -72,7 +73,7 @@ function materializeOperation(operation, bindings, options = {}) {
|
|
|
72
73
|
else {
|
|
73
74
|
return {
|
|
74
75
|
recurse: true,
|
|
75
|
-
result: materializeOperation(op.input, bindings, options),
|
|
76
|
+
result: materializeOperation(op.input, bindings, bindingsFactory, options),
|
|
76
77
|
};
|
|
77
78
|
}
|
|
78
79
|
}
|
|
@@ -120,7 +121,7 @@ function materializeOperation(operation, bindings, options = {}) {
|
|
|
120
121
|
const variables = op.variables.filter(variable => !bindings.has(variable));
|
|
121
122
|
// Only include projected variables in the sub-bindings that will be passed down recursively.
|
|
122
123
|
// If we don't do this, we may be binding variables that may have the same label, but are not considered equal.
|
|
123
|
-
const subBindings =
|
|
124
|
+
const subBindings = bindingsFactory.bindings(op.variables.map(variable => {
|
|
124
125
|
const binding = bindings.get(variable);
|
|
125
126
|
if (binding) {
|
|
126
127
|
return [variable, binding];
|
|
@@ -130,7 +131,7 @@ function materializeOperation(operation, bindings, options = {}) {
|
|
|
130
131
|
}).filter(entry => Boolean(entry)));
|
|
131
132
|
return {
|
|
132
133
|
recurse: false,
|
|
133
|
-
result: factory.createProject(materializeOperation(op.input, subBindings, options), variables),
|
|
134
|
+
result: factory.createProject(materializeOperation(op.input, subBindings, bindingsFactory, options), variables),
|
|
134
135
|
};
|
|
135
136
|
},
|
|
136
137
|
values(op, factory) {
|
|
@@ -185,6 +186,19 @@ function materializeOperation(operation, bindings, options = {}) {
|
|
|
185
186
|
result: factory.createTermExpression(materializeTerm(op.term, bindings)),
|
|
186
187
|
};
|
|
187
188
|
}
|
|
189
|
+
if (op.expressionType === 'operator') {
|
|
190
|
+
if (op.operator === 'bound' && op.args.length === 1 && op.args[0].expressionType === 'term' &&
|
|
191
|
+
[...bindings.keys()].some(variable => op.args[0].term.equals(variable))) {
|
|
192
|
+
return {
|
|
193
|
+
recurse: false,
|
|
194
|
+
result: factory.createTermExpression(TRUE),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return {
|
|
198
|
+
recurse: true,
|
|
199
|
+
result: op,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
188
202
|
if (op.expressionType === 'aggregate' &&
|
|
189
203
|
'variable' in op &&
|
|
190
204
|
bindings.has(op.variable)) {
|
package/lib/Bindings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Bindings.js","sourceRoot":"","sources":["Bindings.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAG7D,2CAA0C;AAC1C,yCAA4D;AAE5D,qDAAuC;AAEvC,MAAM,EAAE,GAAG,IAAI,kCAAe,EAAE,CAAC;AAEjC;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAAC,IAAc,EAAE,QAAkB;IAChE,IAAI,IAAI,CAAC,QAAQ,KAAK,UAAU,EAAE;QAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,KAAK,EAAE;YACT,OAAO,KAAK,CAAC;SACd;KACF;IACD,IAAI,IAAI,CAAC,QAAQ,KAAK,MAAM,IAAI,IAAA,2BAAe,EAAC,IAAI,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,KAAK,U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AO,CAAC,YAAY,CAC1B,SAAS,EACT,aAAa,CACd;iBACF,CAAC;aACH;YACD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC;QACD,UAAU,CAAC,EAAsB,EAAE,OAAgB;YACjD,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE;gBACvB,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,EAAE;iBACX,CAAC;aACH;YAED,IAAI,EAAE,CAAC,cAAc,KAAK,MAAM,EAAE;gBAChC,gCAAgC;gBAChC,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,OAAO,CAAC,oBAAoB,CAAC,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;iBACzE,CAAC;aACH;YACD,IAAI,EAAE,CAAC,cAAc,KAAK,WAAW;gBACnC,UAAU,IAAI,EAAE;gBAChB,QAAQ,CAAC,GAAG,CAAgB,EAAE,CAAC,QAAQ,CAAC,EAAE;gBAC1C,2CAA2C;gBAC3C,yGAAyG;gBACzG,uCAAuC;gBACvC,IAAI,OAAO,CAAC,qBAAqB,EAAE;oBACjC,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAA,yBAAY,EAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,UAAU,aAAa,CAAC,CAAC;iBAChG;qBAAM;oBACL,OAAO;wBACL,OAAO,EAAE,IAAI;wBACb,MAAM,EAAE,EAAE;qBACX,CAAC;iBACH;aACF;YACD,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AA9MD,oDA8MC","sourcesContent":["import { BindingsFactory } from '@comunica/bindings-factory';\nimport type { Bindings } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { termToString } from 'rdf-string';\nimport { mapTermsNested, someTermsNested } from 'rdf-terms';\nimport type { Algebra, Factory } from 'sparqlalgebrajs';\nimport { Util } from 'sparqlalgebrajs';\n\nconst BF = new BindingsFactory();\n\n/**\n * Materialize a term with the given binding.\n *\n * If the given term is a variable,\n * and that variable exist in the given bindings object,\n * the value of that binding is returned.\n * In all other cases, the term itself is returned.\n *\n * @param {RDF.Term} term A term.\n * @param {Bindings} bindings A bindings object.\n * @return {RDF.Term} The materialized term.\n */\nexport function materializeTerm(term: RDF.Term, bindings: Bindings): RDF.Term {\n if (term.termType === 'Variable') {\n const value = bindings.get(term);\n if (value) {\n return value;\n }\n }\n if (term.termType === 'Quad' && someTermsNested(term, value => value.termType === 'Variable')) {\n return mapTermsNested(term, subTerm => materializeTerm(subTerm, bindings));\n }\n return term;\n}\n\n/**\n * Materialize the given operation (recursively) with the given bindings.\n * Essentially, all variables in the given operation will be replaced\n * by the terms bound to the variables in the given bindings.\n * @param {Operation} operation SPARQL algebra operation.\n * @param {Bindings} bindings A bindings object.\n * @param options Options for materializations.\n * @return Algebra.Operation A new operation materialized with the given bindings.\n */\nexport function materializeOperation(\n operation: Algebra.Operation,\n bindings: Bindings,\n options: {\n /**\n * If target variable bindings (such as on SELECT or BIND) should not be allowed.\n */\n strictTargetVariables?: boolean;\n /**\n * If filter expressions should be materialized\n */\n bindFilter?: boolean;\n } = {},\n): Algebra.Operation {\n options = {\n strictTargetVariables: 'strictTargetVariables' in options ? options.strictTargetVariables : false,\n bindFilter: 'bindFilter' in options ? options.bindFilter : true,\n };\n\n return Util.mapOperation(operation, {\n path(op: Algebra.Path, factory: Factory) {\n // Materialize variables in a path expression.\n // The predicate expression will be recursed.\n return {\n recurse: false,\n result: factory.createPath(\n materializeTerm(op.subject, bindings),\n op.predicate,\n materializeTerm(op.object, bindings),\n materializeTerm(op.graph, bindings),\n ),\n };\n },\n pattern(op: Algebra.Pattern, factory: Factory) {\n // Materialize variables in the quad pattern.\n return {\n recurse: false,\n result: factory.createPattern(\n materializeTerm(op.subject, bindings),\n materializeTerm(op.predicate, bindings),\n materializeTerm(op.object, bindings),\n materializeTerm(op.graph, bindings),\n ),\n };\n },\n extend(op: Algebra.Extend) {\n // Materialize an extend operation.\n // If strictTargetVariables is true, we throw if the extension target variable is attempted to be bound.\n // Otherwise, we remove the extend operation.\n if (bindings.has(op.variable)) {\n if (options.strictTargetVariables) {\n throw new Error(`Tried to bind variable ${termToString(op.variable)} in a BIND operator.`);\n } else {\n return {\n recurse: true,\n result: materializeOperation(op.input, bindings, options),\n };\n }\n }\n return {\n recurse: true,\n result: op,\n };\n },\n group(op: Algebra.Group, factory: Factory) {\n // Materialize a group operation.\n // If strictTargetVariables is true, we throw if the group target variable is attempted to be bound.\n // Otherwise, we just filter out the bound variables.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a GROUP BY operator.`);\n }\n }\n return {\n recurse: true,\n result: op,\n };\n }\n const variables = op.variables.filter(variable => !bindings.has(variable));\n return {\n recurse: true,\n result: factory.createGroup(\n op.input,\n variables,\n op.aggregates,\n ),\n };\n },\n project(op: Algebra.Project, factory: Factory) {\n // Materialize a project operation.\n // If strictTargetVariables is true, we throw if the project target variable is attempted to be bound.\n // Otherwise, we just filter out the bound variables.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a SELECT operator.`);\n }\n }\n return {\n recurse: true,\n result: op,\n };\n }\n\n const variables = op.variables.filter(variable => !bindings.has(variable));\n\n // Only include projected variables in the sub-bindings that will be passed down recursively.\n // If we don't do this, we may be binding variables that may have the same label, but are not considered equal.\n const subBindings = BF.bindings(<[RDF.Variable, RDF.Term][]> op.variables.map(variable => {\n const binding = bindings.get(variable);\n if (binding) {\n return [ variable, binding ];\n }\n // eslint-disable-next-line no-useless-return\n return;\n }).filter(entry => Boolean(entry)));\n\n return {\n recurse: false,\n result: factory.createProject(\n materializeOperation(\n op.input,\n subBindings,\n options,\n ),\n variables,\n ),\n };\n },\n values(op: Algebra.Values, factory: Factory) {\n // Materialize a values operation.\n // If strictTargetVariables is true, we throw if the values target variable is attempted to be bound.\n // Otherwise, we just filter out the bound variables and their bindings.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a VALUES operator.`);\n }\n }\n } else {\n const variables = op.variables.filter(variable => !bindings.has(variable));\n const valueBindings: Record<string, RDF.Literal | RDF.NamedNode>[] = <any> op.bindings.map(binding => {\n const newBinding = { ...binding };\n let valid = true;\n bindings.forEach((value: RDF.NamedNode, key: RDF.Variable) => {\n const keyString = termToString(key);\n if (keyString in newBinding) {\n if (!value.equals(newBinding[keyString])) {\n // If the value of the binding is not equal, remove this binding completely from the VALUES clause\n valid = false;\n }\n delete newBinding[keyString];\n }\n });\n return valid ? newBinding : undefined;\n }).filter(Boolean);\n return {\n recurse: true,\n result: factory.createValues(\n variables,\n valueBindings,\n ),\n };\n }\n return {\n recurse: false,\n result: op,\n };\n },\n expression(op: Algebra.Expression, factory: Factory) {\n if (!options.bindFilter) {\n return {\n recurse: false,\n result: op,\n };\n }\n\n if (op.expressionType === 'term') {\n // Materialize a term expression\n return {\n recurse: false,\n result: factory.createTermExpression(materializeTerm(op.term, bindings)),\n };\n }\n if (op.expressionType === 'aggregate' &&\n 'variable' in op &&\n bindings.has(<RDF.Variable> op.variable)) {\n // Materialize a bound aggregate operation.\n // If strictTargetVariables is true, we throw if the expression target variable is attempted to be bound.\n // Otherwise, we ignore this operation.\n if (options.strictTargetVariables) {\n throw new Error(`Tried to bind ${termToString(op.variable)} in a ${op.aggregator} aggregate.`);\n } else {\n return {\n recurse: true,\n result: op,\n };\n }\n }\n return {\n recurse: true,\n result: op,\n };\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Bindings.js","sourceRoot":"","sources":["Bindings.ts"],"names":[],"mappings":";;;AAGA,uDAA+C;AAC/C,2CAA0C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@comunica/bindings-factory';\nimport type { Bindings } from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport { DataFactory } from 'rdf-data-factory';\nimport { termToString } from 'rdf-string';\nimport { mapTermsNested, someTermsNested } from 'rdf-terms';\nimport type { Algebra, Factory } from 'sparqlalgebrajs';\nimport { Util } from 'sparqlalgebrajs';\n\nconst DF = new DataFactory();\n\nconst TRUE = DF.literal('true', DF.namedNode('http://www.w3.org/2001/XMLSchema#boolean'));\n\n/**\n * Materialize a term with the given binding.\n *\n * If the given term is a variable,\n * and that variable exist in the given bindings object,\n * the value of that binding is returned.\n * In all other cases, the term itself is returned.\n *\n * @param {RDF.Term} term A term.\n * @param {Bindings} bindings A bindings object.\n * @return {RDF.Term} The materialized term.\n */\nexport function materializeTerm(term: RDF.Term, bindings: Bindings): RDF.Term {\n if (term.termType === 'Variable') {\n const value = bindings.get(term);\n if (value) {\n return value;\n }\n }\n if (term.termType === 'Quad' && someTermsNested(term, value => value.termType === 'Variable')) {\n return mapTermsNested(term, subTerm => materializeTerm(subTerm, bindings));\n }\n return term;\n}\n\n/**\n * Materialize the given operation (recursively) with the given bindings.\n * Essentially, all variables in the given operation will be replaced\n * by the terms bound to the variables in the given bindings.\n * @param {Operation} operation SPARQL algebra operation.\n * @param {Bindings} bindings A bindings object.\n * @param options Options for materializations.\n * @return Algebra.Operation A new operation materialized with the given bindings.\n */\nexport function materializeOperation(\n operation: Algebra.Operation,\n bindings: Bindings,\n bindingsFactory: BindingsFactory,\n options: {\n /**\n * If target variable bindings (such as on SELECT or BIND) should not be allowed.\n */\n strictTargetVariables?: boolean;\n /**\n * If filter expressions should be materialized\n */\n bindFilter?: boolean;\n } = {},\n): Algebra.Operation {\n options = {\n strictTargetVariables: 'strictTargetVariables' in options ? options.strictTargetVariables : false,\n bindFilter: 'bindFilter' in options ? options.bindFilter : true,\n };\n\n return Util.mapOperation(operation, {\n path(op: Algebra.Path, factory: Factory) {\n // Materialize variables in a path expression.\n // The predicate expression will be recursed.\n return {\n recurse: false,\n result: Object.assign(factory.createPath(\n materializeTerm(op.subject, bindings),\n op.predicate,\n materializeTerm(op.object, bindings),\n materializeTerm(op.graph, bindings),\n ), { metadata: op.metadata }),\n };\n },\n pattern(op: Algebra.Pattern, factory: Factory) {\n // Materialize variables in the quad pattern.\n return {\n recurse: false,\n result: Object.assign(factory.createPattern(\n materializeTerm(op.subject, bindings),\n materializeTerm(op.predicate, bindings),\n materializeTerm(op.object, bindings),\n materializeTerm(op.graph, bindings),\n ), { metadata: op.metadata }),\n };\n },\n extend(op: Algebra.Extend) {\n // Materialize an extend operation.\n // If strictTargetVariables is true, we throw if the extension target variable is attempted to be bound.\n // Otherwise, we remove the extend operation.\n if (bindings.has(op.variable)) {\n if (options.strictTargetVariables) {\n throw new Error(`Tried to bind variable ${termToString(op.variable)} in a BIND operator.`);\n } else {\n return {\n recurse: true,\n result: materializeOperation(op.input, bindings, bindingsFactory, options),\n };\n }\n }\n return {\n recurse: true,\n result: op,\n };\n },\n group(op: Algebra.Group, factory: Factory) {\n // Materialize a group operation.\n // If strictTargetVariables is true, we throw if the group target variable is attempted to be bound.\n // Otherwise, we just filter out the bound variables.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a GROUP BY operator.`);\n }\n }\n return {\n recurse: true,\n result: op,\n };\n }\n const variables = op.variables.filter(variable => !bindings.has(variable));\n return {\n recurse: true,\n result: factory.createGroup(\n op.input,\n variables,\n op.aggregates,\n ),\n };\n },\n project(op: Algebra.Project, factory: Factory) {\n // Materialize a project operation.\n // If strictTargetVariables is true, we throw if the project target variable is attempted to be bound.\n // Otherwise, we just filter out the bound variables.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a SELECT operator.`);\n }\n }\n return {\n recurse: true,\n result: op,\n };\n }\n\n const variables = op.variables.filter(variable => !bindings.has(variable));\n\n // Only include projected variables in the sub-bindings that will be passed down recursively.\n // If we don't do this, we may be binding variables that may have the same label, but are not considered equal.\n const subBindings = bindingsFactory.bindings(<[RDF.Variable, RDF.Term][]> op.variables.map(variable => {\n const binding = bindings.get(variable);\n if (binding) {\n return [ variable, binding ];\n }\n // eslint-disable-next-line no-useless-return\n return;\n }).filter(entry => Boolean(entry)));\n\n return {\n recurse: false,\n result: factory.createProject(\n materializeOperation(\n op.input,\n subBindings,\n bindingsFactory,\n options,\n ),\n variables,\n ),\n };\n },\n values(op: Algebra.Values, factory: Factory) {\n // Materialize a values operation.\n // If strictTargetVariables is true, we throw if the values target variable is attempted to be bound.\n // Otherwise, we just filter out the bound variables and their bindings.\n if (options.strictTargetVariables) {\n for (const variable of op.variables) {\n if (bindings.has(variable)) {\n throw new Error(`Tried to bind variable ${termToString(variable)} in a VALUES operator.`);\n }\n }\n } else {\n const variables = op.variables.filter(variable => !bindings.has(variable));\n const valueBindings: Record<string, RDF.Literal | RDF.NamedNode>[] = <any> op.bindings.map(binding => {\n const newBinding = { ...binding };\n let valid = true;\n bindings.forEach((value: RDF.NamedNode, key: RDF.Variable) => {\n const keyString = termToString(key);\n if (keyString in newBinding) {\n if (!value.equals(newBinding[keyString])) {\n // If the value of the binding is not equal, remove this binding completely from the VALUES clause\n valid = false;\n }\n delete newBinding[keyString];\n }\n });\n return valid ? newBinding : undefined;\n }).filter(Boolean);\n return {\n recurse: true,\n result: factory.createValues(\n variables,\n valueBindings,\n ),\n };\n }\n return {\n recurse: false,\n result: op,\n };\n },\n expression(op: Algebra.Expression, factory: Factory) {\n if (!options.bindFilter) {\n return {\n recurse: false,\n result: op,\n };\n }\n\n if (op.expressionType === 'term') {\n // Materialize a term expression\n return {\n recurse: false,\n result: factory.createTermExpression(materializeTerm(op.term, bindings)),\n };\n }\n if (op.expressionType === 'operator') {\n if (op.operator === 'bound' && op.args.length === 1 && op.args[0].expressionType === 'term' &&\n [ ...bindings.keys() ].some(variable => op.args[0].term.equals(variable))) {\n return {\n recurse: false,\n result: factory.createTermExpression(TRUE),\n };\n }\n return {\n recurse: true,\n result: op,\n };\n }\n if (op.expressionType === 'aggregate' &&\n 'variable' in op &&\n bindings.has(<RDF.Variable> op.variable)) {\n // Materialize a bound aggregate operation.\n // If strictTargetVariables is true, we throw if the expression target variable is attempted to be bound.\n // Otherwise, we ignore this operation.\n if (options.strictTargetVariables) {\n throw new Error(`Tried to bind ${termToString(op.variable)} in a ${op.aggregator} aggregate.`);\n } else {\n return {\n recurse: true,\n result: op,\n };\n }\n }\n return {\n recurse: true,\n result: op,\n };\n },\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/bus-query-operation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1-alpha.43.0",
|
|
4
4
|
"description": "A comunica bus for query-operation events.",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -31,21 +31,23 @@
|
|
|
31
31
|
"lib/**/*.js.map"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@comunica/bindings-factory": "
|
|
35
|
-
"@comunica/context-entries": "
|
|
36
|
-
"@comunica/core": "
|
|
37
|
-
"@comunica/data-factory": "
|
|
38
|
-
"@comunica/
|
|
34
|
+
"@comunica/bindings-factory": "3.0.1-alpha.43.0",
|
|
35
|
+
"@comunica/context-entries": "3.0.1-alpha.43.0",
|
|
36
|
+
"@comunica/core": "3.0.1-alpha.43.0",
|
|
37
|
+
"@comunica/data-factory": "3.0.1-alpha.43.0",
|
|
38
|
+
"@comunica/metadata": "3.0.1-alpha.43.0",
|
|
39
|
+
"@comunica/types": "3.0.1-alpha.43.0",
|
|
39
40
|
"@rdfjs/types": "*",
|
|
40
41
|
"asynciterator": "^3.8.1",
|
|
42
|
+
"rdf-data-factory": "^1.1.2",
|
|
41
43
|
"rdf-string": "^1.6.1",
|
|
42
44
|
"rdf-terms": "^1.11.0",
|
|
43
|
-
"sparqlalgebrajs": "^4.
|
|
45
|
+
"sparqlalgebrajs": "^4.3.3"
|
|
44
46
|
},
|
|
45
47
|
"scripts": {
|
|
46
48
|
"build": "npm run build:ts && npm run build:components",
|
|
47
49
|
"build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
|
|
48
50
|
"build:components": "componentsjs-generator"
|
|
49
51
|
},
|
|
50
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "d11e44cf07d4699f9d2c51d5851b5ed443de1997"
|
|
51
53
|
}
|