@grafctory/keep-sparql 0.0.0-stage → 0.14.2
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/LICENSE +201 -0
- package/README.md +115 -2
- package/dist/detail/decode.d.ts +40 -0
- package/dist/detail/decode.d.ts.map +1 -0
- package/dist/detail/decode.js +160 -0
- package/dist/detail/decode.js.map +1 -0
- package/dist/detail/encode.d.ts +45 -0
- package/dist/detail/encode.d.ts.map +1 -0
- package/dist/detail/encode.js +104 -0
- package/dist/detail/encode.js.map +1 -0
- package/dist/detail/index.d.ts +19 -0
- package/dist/detail/index.d.ts.map +1 -0
- package/dist/detail/index.js +61 -0
- package/dist/detail/index.js.map +1 -0
- package/dist/detail/schema.d.ts +86 -0
- package/dist/detail/schema.d.ts.map +1 -0
- package/dist/detail/schema.js +89 -0
- package/dist/detail/schema.js.map +1 -0
- package/dist/detect/encode.d.ts +23 -0
- package/dist/detect/encode.d.ts.map +1 -0
- package/dist/detect/encode.js +30 -0
- package/dist/detect/encode.js.map +1 -0
- package/dist/detect/index.d.ts +23 -0
- package/dist/detect/index.d.ts.map +1 -0
- package/dist/detect/index.js +37 -0
- package/dist/detect/index.js.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +158 -0
- package/dist/index.js.map +1 -0
- package/dist/modify/encode.d.ts +17 -0
- package/dist/modify/encode.d.ts.map +1 -0
- package/dist/modify/encode.js +233 -0
- package/dist/modify/encode.js.map +1 -0
- package/dist/modify/index.d.ts +21 -0
- package/dist/modify/index.d.ts.map +1 -0
- package/dist/modify/index.js +50 -0
- package/dist/modify/index.js.map +1 -0
- package/dist/patterns.d.ts +199 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +321 -0
- package/dist/patterns.js.map +1 -0
- package/dist/select/decode.d.ts +20 -0
- package/dist/select/decode.d.ts.map +1 -0
- package/dist/select/decode.js +134 -0
- package/dist/select/decode.js.map +1 -0
- package/dist/select/encode.d.ts +86 -0
- package/dist/select/encode.d.ts.map +1 -0
- package/dist/select/encode.js +647 -0
- package/dist/select/encode.js.map +1 -0
- package/dist/select/index.d.ts +19 -0
- package/dist/select/index.d.ts.map +1 -0
- package/dist/select/index.js +62 -0
- package/dist/select/index.js.map +1 -0
- package/dist/select/schema.d.ts +75 -0
- package/dist/select/schema.d.ts.map +1 -0
- package/dist/select/schema.js +84 -0
- package/dist/select/schema.js.map +1 -0
- package/dist/spine.d.ts +167 -0
- package/dist/spine.d.ts.map +1 -0
- package/dist/spine.js +180 -0
- package/dist/spine.js.map +1 -0
- package/dist/terms.d.ts +116 -0
- package/dist/terms.d.ts.map +1 -0
- package/dist/terms.js +251 -0
- package/dist/terms.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,647 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025-2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Select-pass query encoder.
|
|
18
|
+
*
|
|
19
|
+
* Folds the queued {@link Select} requests sharing one plan into one SPARQL `select` query. The owners are bound
|
|
20
|
+
* together, so the collections of every owner in a batch cost one query rather than one query per owner. Encoder and
|
|
21
|
+
* decoder share only the group record, its schema and the {@link Scope} allocating variables, so they agree on every
|
|
22
|
+
* column the query projects, and the decoder reads every column off the rows exactly as the encoder bound it.
|
|
23
|
+
*
|
|
24
|
+
* The query is assembled clause by clause from the {@link Group | group}'s {@link Flake | query plan}, covering only
|
|
25
|
+
* the nodes the query reads: the projection head, the graph patterns, the row filters, the group filters, the
|
|
26
|
+
* ordering and the window. Three switches, each settled once per group, decide how the clauses compose:
|
|
27
|
+
*
|
|
28
|
+
* - the **form** (QEST §5.8.2.1): `grouped` when a projection binding aggregates, the rows being groups; else
|
|
29
|
+
* `ungrouped`, the rows being members, rendered as `itemised` when a criterion aggregates, since SPARQL has no
|
|
30
|
+
* per-item reduction and the members are grouped in a subselect, then projected as distinct rows (§5.2);
|
|
31
|
+
* - the **arms**: one `values` block binding every owner, or, for a windowed plan over several owners, one
|
|
32
|
+
* subselect arm per owner, each windowing its own members, under an outer query restating the ordering, since a
|
|
33
|
+
* `limit` spans every owner bound in a query and would otherwise cut the pooled rows of every owner at once;
|
|
34
|
+
* - the **whole**-collection aggregation (§5.2): a keyless aggregation keeps an owner without members, so the
|
|
35
|
+
* member edge turns optional and the owner row survives an empty member set.
|
|
36
|
+
*
|
|
37
|
+
* Every reduced value is aggregated in a subselect of its own, over the members carrying it in a variant the
|
|
38
|
+
* aggregate accepts. Neither a missing value nor one held in an incompatible variant of a union therefore voids the
|
|
39
|
+
* aggregate (QEST Appendix A.4.2, A.4.5). Strict engines, Oxigraph and Jena among them, read SPARQL 1.1 §18.5.1 as
|
|
40
|
+
* voiding `min`, `max`, `sum` and `avg` over an unbound or mistyped input. A group whose members all lack the value
|
|
41
|
+
* leaves `min`, `max` and `avg` unbound, while `count` and `sum` come to `0` as the protocol requires.
|
|
42
|
+
*
|
|
43
|
+
* The contract shared with the decoder is stated in `src/index.md`.
|
|
44
|
+
*
|
|
45
|
+
* @module
|
|
46
|
+
*/
|
|
47
|
+
import { getShapeClass } from "@grafctory/blue/resource";
|
|
48
|
+
import { getBoundBranch, getShapeBranches } from "@grafctory/blue/union";
|
|
49
|
+
import { sh } from "@grafctory/blue/value";
|
|
50
|
+
import { error, isNumber, opt } from "@grafctory/core";
|
|
51
|
+
import { unique } from "@grafctory/core/arrays";
|
|
52
|
+
import { xsd } from "@grafctory/core/datatype";
|
|
53
|
+
import { getFlakeEntries, getFlakeFocusing, getFlakeGrouping, getFlakeOrdering, getFlakeProjections, getFlakeTransforms, hasDictionaryOptions, hasNullOptions, isComputedFlake, isConstrainedFlake, isGroupingFlake, isRequiredFlake } from "@grafctory/keep-flake";
|
|
54
|
+
import { getOrderDirection, isAggregate, Transforms } from "@grafctory/qest/model";
|
|
55
|
+
import { named, rdf } from "@grafctory/trio";
|
|
56
|
+
import { all as wildcard, and, as, asc, bind, boolean, coalesce, contains, datatype, desc, distinct, eq, exists, filter, fragment, group as block, groupBy, gt, gte, having, iif, isBound, isIn, isLiteral, isNumeric, lang, lcase, limit, lt, lte, ne, nexists, nil, not, number, offset, optional, or, orderBy, pattern, reference, select, str, string, term, union, values, variable, where } from "@grafctory/wire-sparql/builder";
|
|
57
|
+
import { admission, anchor, coalesced, expression, extension, folded, link, membership, textual } from "../patterns.js";
|
|
58
|
+
import { optionsToTerms, valueToTerm } from "../terms.js";
|
|
59
|
+
import { column, columns as derive } from "./schema.js";
|
|
60
|
+
/**
|
|
61
|
+
* The term standing for an absent grouping key in the join variables, which no stored key resolves to.
|
|
62
|
+
*/
|
|
63
|
+
const absent = named("urn:x-metreeca:keep:absent");
|
|
64
|
+
/**
|
|
65
|
+
* The temporal datatypes compared as typed values (§3). Any other temporal form is ordered as an opaque string.
|
|
66
|
+
*/
|
|
67
|
+
const temporals = [xsd.dateTime, xsd.date, xsd.time];
|
|
68
|
+
/**
|
|
69
|
+
* The processing-type tiers ranking a sort key, lowest first (§5.7.5).
|
|
70
|
+
*
|
|
71
|
+
* Each tier states both the condition its values meet and the range variants storing them, so a key is tested only
|
|
72
|
+
* for the tiers its range admits. The last tier takes every value the others reject: its condition is never evaluated.
|
|
73
|
+
*/
|
|
74
|
+
const tiers = [
|
|
75
|
+
{
|
|
76
|
+
holds: value => eq(datatype(value), reference(xsd.boolean)),
|
|
77
|
+
admits: variant => variant.kind === "boolean",
|
|
78
|
+
typed: false
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
holds: isNumeric,
|
|
82
|
+
admits: variant => variant.kind === "number",
|
|
83
|
+
typed: true
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
holds: value => isIn(datatype(value), temporals.map(reference)),
|
|
87
|
+
admits: variant => variant.kind === "string" && temporals.some(temporal => temporal === variant.datatype),
|
|
88
|
+
typed: true
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
holds: () => boolean(true),
|
|
92
|
+
admits: variant => variant.kind === "dictionary" || variant.kind === "string"
|
|
93
|
+
&& variant.datatype !== sh.IRI && !temporals.some(temporal => temporal === variant.datatype),
|
|
94
|
+
typed: false
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
/**
|
|
98
|
+
* Encodes the batched `select` query covering every request of a group.
|
|
99
|
+
*
|
|
100
|
+
* @param scope The variable scope shared with the decoder, allocating the group's solution slots
|
|
101
|
+
* @param group The group to encode, pairing the requests sharing a {@link Flake | query plan} with that plan
|
|
102
|
+
*
|
|
103
|
+
* @returns The batched `select` query covering every request in `group`
|
|
104
|
+
*/
|
|
105
|
+
export function encode(scope, group) {
|
|
106
|
+
const context = settle(scope, group);
|
|
107
|
+
const { flake, items } = group;
|
|
108
|
+
// a `limit` spans every owner bound in a query, so a windowed plan over several owners runs one arm per
|
|
109
|
+
// owner, each windowing its own members, under an outer query restating the ordering over their union: the
|
|
110
|
+
// arms project the ordering keys the outer query reads, which an unprojected key would leave unbound
|
|
111
|
+
return (isNumber(flake.offset) || isNumber(flake.limit)) && items.length > 1
|
|
112
|
+
? select(wildcard(), where(union(items.map(item => query(context, [item], true)))), orderBy(asc(variable(context.owner)), ordering(context)))
|
|
113
|
+
: query(context, items, false);
|
|
114
|
+
}
|
|
115
|
+
//// Context //////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
116
|
+
/**
|
|
117
|
+
* Settles the context of a group's query once, so every clause reads the same variables, form, cells, keys and
|
|
118
|
+
* reductions rather than deriving them again from the plan on its own, possibly differently from the others.
|
|
119
|
+
*/
|
|
120
|
+
function settle(scope, group) {
|
|
121
|
+
const { flake, schema } = group;
|
|
122
|
+
const read = reader(flake);
|
|
123
|
+
const root = scope.resolve(flake);
|
|
124
|
+
const reductions = reducing(scope, flake, read);
|
|
125
|
+
// a query whose projection aggregates is one grouped select; one reduced per item alone (§5.8.2.1)
|
|
126
|
+
// groups by the member in a subselect, which the query then projects as distinct rows (§5.2)
|
|
127
|
+
const form = reductions.length === 0 ? "ungrouped"
|
|
128
|
+
: isGroupingFlake(flake) ? "grouped"
|
|
129
|
+
: "itemised";
|
|
130
|
+
// a query reducing nothing groups by nothing, so it has no key to bind, join or order by
|
|
131
|
+
const keys = form === "ungrouped" ? [] : grouping(flake);
|
|
132
|
+
const joins = keys
|
|
133
|
+
.flatMap(key => shard(schema, key).map(candidate => column(scope, candidate)))
|
|
134
|
+
.map((key) => [key, scope.resolve()]);
|
|
135
|
+
// an aggregate over the whole collection has a value on an empty collection too (§5.2): a keyless
|
|
136
|
+
// aggregation yields one group whatever its input, but grouped by owner it keeps an owner's group only
|
|
137
|
+
// if a row of that owner survives an empty member set, so the members become optional under the owner
|
|
138
|
+
// binding; the reductions read their own subselects, which the surviving row never enters
|
|
139
|
+
return {
|
|
140
|
+
scope, group,
|
|
141
|
+
owner: scope.resolve(group),
|
|
142
|
+
root,
|
|
143
|
+
read,
|
|
144
|
+
form,
|
|
145
|
+
whole: form !== "ungrouped" && keys.length === 0,
|
|
146
|
+
cells: [...schema.keys()],
|
|
147
|
+
keys,
|
|
148
|
+
reductions,
|
|
149
|
+
joins
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The test telling the nodes a query reads: those it constrains, orders or focuses, and, under a projection,
|
|
154
|
+
* those it projects, or some stage or branch beneath them. The entries of a plain template name the content
|
|
155
|
+
* the detail pass re-fetches for each member and are not read here, so a template never widens the member query.
|
|
156
|
+
*/
|
|
157
|
+
function reader(flake) {
|
|
158
|
+
return flake.drain?.form === "projection" ? isRead : isConstrainedFlake;
|
|
159
|
+
function isRead(node) {
|
|
160
|
+
return node.drain?.alias !== undefined
|
|
161
|
+
|| isConstrainedFlake(node)
|
|
162
|
+
|| getFlakeTransforms(node).some(isRead)
|
|
163
|
+
|| getFlakeEntries(node).some(isRead);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The cells a reducing query groups by (§5.8.2.1): the non-aggregate bindings where the projection itself
|
|
168
|
+
* aggregates; else the member, with the bindings and the non-aggregate sort and focus keys the query orders
|
|
169
|
+
* the items by, so a selection aggregate reduces per item and the keys stay available to the ordering clause.
|
|
170
|
+
*/
|
|
171
|
+
function grouping(flake) {
|
|
172
|
+
const keyed = [
|
|
173
|
+
...(flake.drain?.form === "projection" ? getFlakeProjections(flake) : []),
|
|
174
|
+
...getFlakeFocusing(flake).filter(node => !isReduction(node)),
|
|
175
|
+
...getFlakeOrdering(flake).filter(node => !isReduction(node))
|
|
176
|
+
];
|
|
177
|
+
return isGroupingFlake(flake) ? getFlakeGrouping(flake)
|
|
178
|
+
: [flake, ...unique(keyed).filter(node => node !== flake)];
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* The reductions a query reads, one per reduced value and branch guard. Each stage reducing the value under the guard
|
|
182
|
+
* gets a subselect column of its own. A stage whose aggregate accepts no variant of the value, as `min`/`max`/`sum`/
|
|
183
|
+
* `avg` over references, is left out and its cell stays unbound (Appendix A.4.1). `count` accepts every value, so it
|
|
184
|
+
* still reduces references, counting them by presence alone, and takes no branch guard (§5.8.2.1).
|
|
185
|
+
*/
|
|
186
|
+
function reducing(scope, flake, read) {
|
|
187
|
+
const stages = reduced(flake, scope.resolve(flake)).map(([stage, origin, guard]) => ({ stage, origin, guard, key: `${origin} ${guard}` }));
|
|
188
|
+
return stages
|
|
189
|
+
.filter(({ key }, index) => stages.findIndex(stage => stage.key === key) === index)
|
|
190
|
+
.map(({ origin, guard, key }) => ({
|
|
191
|
+
origin,
|
|
192
|
+
guard,
|
|
193
|
+
stages: stages
|
|
194
|
+
.filter(stage => stage.key === key)
|
|
195
|
+
.map(({ stage }) => [stage, scope.resolve()])
|
|
196
|
+
}));
|
|
197
|
+
function reduced(node, origin) {
|
|
198
|
+
return [
|
|
199
|
+
...getFlakeTransforms(node).filter(read).flatMap(stage => [
|
|
200
|
+
...opt(stage.pipe.find(isAggregate), aggregate => reduction(stage, aggregate), []),
|
|
201
|
+
...reduced(stage, origin)
|
|
202
|
+
]),
|
|
203
|
+
...getFlakeEntries(node).filter(read).flatMap(branch => reduced(branch, scope.resolve(branch)))
|
|
204
|
+
];
|
|
205
|
+
/**
|
|
206
|
+
* The stage paired with its origin and branch guard, or nothing if its aggregate accepts no variant of the
|
|
207
|
+
* value. The guard admits the variants the aggregate accepts, and is empty if the aggregate accepts them all.
|
|
208
|
+
* A localised variant reaches the reduction coalesced to a string (§6.2), so its guard is the string test.
|
|
209
|
+
*/
|
|
210
|
+
function reduction(stage, aggregate) {
|
|
211
|
+
const variants = getShapeBranches(node.range.shape);
|
|
212
|
+
const admitted = accepted(node, aggregate);
|
|
213
|
+
return admitted.length === 0 ? [] : [[stage, origin, admitted.length === variants.length ? nil()
|
|
214
|
+
: or(...admitted.map(variant => variant.kind === "dictionary"
|
|
215
|
+
? textual(variable(origin))
|
|
216
|
+
: admission(variable(origin), variant)))
|
|
217
|
+
]];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//// Query ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
222
|
+
/**
|
|
223
|
+
* The query over the owners of `items`: the owners bound in a `values` block, the member edge, the patterns the
|
|
224
|
+
* query reads, the reduction subselects, and the clauses projecting, filtering, grouping, ordering and slicing the
|
|
225
|
+
* members. A `nested` query also projects the ordering keys, so the enclosing query can order its rows.
|
|
226
|
+
*/
|
|
227
|
+
function query(context, items, nested) {
|
|
228
|
+
const { group: { flake }, owner, form, whole } = context;
|
|
229
|
+
const binding = values([variable(owner)], items.map(({ request }) => [term(named(request.entry))]));
|
|
230
|
+
const rows = select(head(context, nested), where(binding, whole ? optional(...body(context)) : fragment(...body(context)), joins(context), ...reductions(context, binding)), groupings(context), havings(context), form === "itemised" ? nil() : orderBy(asc(variable(owner)), ordering(context)), form === "itemised" ? nil() : slicing(flake));
|
|
231
|
+
return form === "itemised"
|
|
232
|
+
? select(distinct(...projection(context, nested)), where(rows), orderBy(asc(variable(owner)), ordering(context)), slicing(flake))
|
|
233
|
+
: rows;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* The projection head: the owner, the grouping keys and the reductions of a grouped or itemised query, else the
|
|
237
|
+
* owner and the distinct cells, the owner always projected, as the column the spine hands each request its rows by.
|
|
238
|
+
*/
|
|
239
|
+
function head(context, nested) {
|
|
240
|
+
const { scope, owner, form, keys, reductions } = context;
|
|
241
|
+
return form === "ungrouped"
|
|
242
|
+
? distinct(...projection(context, nested))
|
|
243
|
+
: [variable(owner), ...keys.flatMap(key => columns(context, key)), ...reductions.flatMap(({ stages }) => stages.map(([stage, column]) => as(reduced(stage, column), variable(scope.resolve(stage)))))];
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The columns a query returns: the owner and the cells, plus the ordering keys the enclosing query of a `nested`
|
|
247
|
+
* arm reads, which an arm leaving them unprojected would hand to the outer ordering unbound, misordering the rows.
|
|
248
|
+
*/
|
|
249
|
+
function projection(context, nested) {
|
|
250
|
+
const { owner, cells } = context;
|
|
251
|
+
const head = [variable(owner), ...cells.flatMap(cell => columns(context, cell))];
|
|
252
|
+
return [...head, ...(nested ? ordered(context, head) : [])];
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* The ordering keys {@link ordering} reads that `head` leaves unprojected: the focus and sort keys, and the
|
|
256
|
+
* member itself as the tiebreak of an ungrouped query; a reducing key is projected by the grouped head, and
|
|
257
|
+
* the member of a projection is left out, as projecting it would keep apart rows the projection collapses.
|
|
258
|
+
*/
|
|
259
|
+
function ordered(context, head) {
|
|
260
|
+
const { scope, group: { flake }, form } = context;
|
|
261
|
+
const keyed = [
|
|
262
|
+
...getFlakeFocusing(flake),
|
|
263
|
+
...getFlakeOrdering(flake).filter(node => !isReduction(node)),
|
|
264
|
+
...(form !== "ungrouped" || flake.drain?.form === "projection" ? [] : [flake])
|
|
265
|
+
];
|
|
266
|
+
return unique(keyed.map(node => variable(scope.resolve(node)))).filter(key => !head.includes(key));
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* The patterns binding everything the query reads, in `where` clause order: the member edge, or the extension of the
|
|
270
|
+
* range for a virtual collection, the patterns and shards under the member, the admitted variants and the row filters.
|
|
271
|
+
*/
|
|
272
|
+
function body(context) {
|
|
273
|
+
const { group: { flake, field, virtual }, owner, root } = context;
|
|
274
|
+
const edge = { owner, property: field, object: root };
|
|
275
|
+
return [
|
|
276
|
+
virtual ? extension(root, flake.range.shape) : link([edge.owner, edge.property, edge.object]),
|
|
277
|
+
patterns(context, flake, root),
|
|
278
|
+
shards(context, flake, edge),
|
|
279
|
+
admitted(context),
|
|
280
|
+
...filters(context, flake, root)
|
|
281
|
+
];
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* The binds of the join variables of a reducing query, one per key column, each binding the key or the absent
|
|
285
|
+
* sentinel. The query and every reduction subselect state the same binds after the member pattern, so both sides
|
|
286
|
+
* match on the same values and a group lacking a key joins its own reductions and no other group's.
|
|
287
|
+
*/
|
|
288
|
+
function joins({ joins }) {
|
|
289
|
+
return fragment(joins.map(([key, join]) => bind(coalesce(variable(key), term(absent)), variable(join))));
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The reduction subselects of a reducing query, one per reduced value and branch guard (Appendix A.4.2). Each
|
|
293
|
+
* restates the owner `binding` and the member pattern, admits only the members carrying the value in a variant the
|
|
294
|
+
* stages accept, and reduces them per owner and join variables. The query left-joins each subselect on the owner and
|
|
295
|
+
* the join variables. A group lacking the value thus reads its reductions as unbound: it neither loses its row nor
|
|
296
|
+
* borrows the values of another group, since the join variables of two groups never match, even for an absent key.
|
|
297
|
+
*/
|
|
298
|
+
function reductions(context, binding) {
|
|
299
|
+
const { owner, reductions, joins: joined } = context;
|
|
300
|
+
return reductions.map(({ origin, guard, stages }) => optional(block(select([
|
|
301
|
+
variable(owner),
|
|
302
|
+
...joined.map(([, join]) => variable(join)),
|
|
303
|
+
...stages.map(([stage, column]) => as(expression(variable(origin), stage.pipe), variable(column)))
|
|
304
|
+
], where(binding, ...body(context), joins(context), filter(and(isBound(variable(origin)), guard))), groupBy(variable(owner), joined.map(([, join]) => variable(join)))))));
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The `group by` clause of a grouped or itemised query: the owner, the grouping keys and the reduced columns, listed
|
|
308
|
+
* although the keys settle them, since a grouped head may project a grouped variable alone.
|
|
309
|
+
*/
|
|
310
|
+
function groupings(context) {
|
|
311
|
+
const { owner, form, keys, reductions } = context;
|
|
312
|
+
return form === "ungrouped" ? nil() : groupBy(variable(owner), keys.flatMap(key => columns(context, key)), reductions.flatMap(({ stages }) => stages.map(([, column]) => variable(column))));
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* The `having` clause of a grouped or itemised query: the conditions the reducing stages state over their
|
|
316
|
+
* reduced values, and the `!` conditions over them (§5.7.3), which only hold once the groups have been reduced.
|
|
317
|
+
*/
|
|
318
|
+
function havings(context) {
|
|
319
|
+
const { form, reductions } = context;
|
|
320
|
+
return form === "ungrouped" ? nil() : having(reductions.flatMap(({ stages }) => stages.flatMap(([stage, column]) => [
|
|
321
|
+
...conditions(stage, reduced(stage, column)),
|
|
322
|
+
...opt(stage.all, options => [conjunction(reduced(stage, column), optionsToTerms(options, stage.range))], [])
|
|
323
|
+
])));
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* The ordering of one request's rows (§5.7.4, §5.7.5): the focus boosts first, then the sort keys by
|
|
327
|
+
* precedence, each ranked by processing-type tier before its value, then the grouping keys or the member
|
|
328
|
+
* itself as a tiebreak, so paging stays stable across queries whatever the backend's own solution order.
|
|
329
|
+
*/
|
|
330
|
+
function ordering(context) {
|
|
331
|
+
const { scope, group: { flake }, root, form, keys } = context;
|
|
332
|
+
const tiebreak = form === "ungrouped"
|
|
333
|
+
? [variable(root)]
|
|
334
|
+
: keys.flatMap(key => columns(context, key));
|
|
335
|
+
return fragment(getFlakeFocusing(flake).map(node => asc(iif(any(variable(scope.resolve(node)), optionsToTerms(node.focus, node.range)), number(0), number(1)))), getFlakeOrdering(flake).flatMap(node => sortable(node).map(getOrderDirection(node.order) < 0 ? desc : asc)), tiebreak.map(asc));
|
|
336
|
+
/**
|
|
337
|
+
* The expressions ordering the rows by one sort key: the rank of its tier, then its value within the tier.
|
|
338
|
+
*
|
|
339
|
+
* Only the tiers admitted by the key's range are told apart, and a key confined to a single tier is ordered by its
|
|
340
|
+
* value alone. A range storing nodes fits no tier, so its key is tested for every tier, like an untyped value.
|
|
341
|
+
*/
|
|
342
|
+
function sortable(node) {
|
|
343
|
+
const value = variable(scope.resolve(node));
|
|
344
|
+
const variants = getShapeBranches(node.range.shape);
|
|
345
|
+
const literal = variants.every(variant => tiers.some(tier => tier.admits(variant)));
|
|
346
|
+
const ranked = tiers.filter(tier => !literal || variants.some(tier.admits));
|
|
347
|
+
const typed = ranked.filter(tier => tier.typed);
|
|
348
|
+
return [
|
|
349
|
+
...(ranked.length > 1 ? [rank(ranked)] : []),
|
|
350
|
+
typed.length === 0 ? str(value)
|
|
351
|
+
: typed.length === ranked.length ? value
|
|
352
|
+
: iif(or(typed.map(tier => tier.holds(value))), value, str(value))
|
|
353
|
+
];
|
|
354
|
+
function rank([tier, ...rest]) {
|
|
355
|
+
const index = number(tiers.indexOf(tier));
|
|
356
|
+
return rest.length === 0 ? index : iif(tier.holds(value), index, rank(rest));
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* The window of one request's rows (§5.7.6).
|
|
362
|
+
*/
|
|
363
|
+
function slicing(flake) {
|
|
364
|
+
return fragment(isNumber(flake.offset) ? offset(flake.offset) : nil(), isNumber(flake.limit) ? limit(flake.limit) : nil());
|
|
365
|
+
}
|
|
366
|
+
//// Cells ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
367
|
+
/**
|
|
368
|
+
* The projected columns of a cell, as the schema declares them: one per requested variant for a cell
|
|
369
|
+
* retrieved as a union (§5.5), so the decoder reads the variant off the column that bound; otherwise the
|
|
370
|
+
* cell's single column, carrying its stored value, its coalesced label or its owner as the schema states.
|
|
371
|
+
*/
|
|
372
|
+
function columns(context, cell) {
|
|
373
|
+
return shard(context.group.schema, cell).map(candidate => variable(column(context.scope, candidate)));
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* The schema columns of a cell; a node the schema does not return, a grouping or ordering key the query
|
|
377
|
+
* reads without returning it, takes the columns the schema would derive for it.
|
|
378
|
+
*/
|
|
379
|
+
function shard(schema, cell) {
|
|
380
|
+
return schema.get(cell) ?? derive(cell);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* The value of a reducing stage, read off its subselect `column`. A group whose members all lack the value has no
|
|
384
|
+
* subselect row, so the column stays unbound: `count` and `sum` restore it to `0`, as the protocol requires over an
|
|
385
|
+
* empty set (§5.2, Appendix A.4.3), and any other aggregate leaves it unbound, its empty value being undefined.
|
|
386
|
+
*/
|
|
387
|
+
function reduced(stage, column) {
|
|
388
|
+
// a scalar leading the pipe is applied in the subselect, so the restored `0` stands for the scalar over an
|
|
389
|
+
// empty sum or count: every numeric scalar admitted on them (abs, floor, ceil, round) maps `0` to `0`
|
|
390
|
+
const aggregate = stage.pipe.find(isAggregate);
|
|
391
|
+
return aggregate === "count" || aggregate === "sum"
|
|
392
|
+
? coalesce(variable(column), number(0))
|
|
393
|
+
: variable(column);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* The filter admitting only members of the variants the query retrieves (§5.5): a member resolving
|
|
397
|
+
* through an unrequested variant binds no shard and is not a member of the retrieved collection.
|
|
398
|
+
*/
|
|
399
|
+
function admitted(context) {
|
|
400
|
+
const { group: { flake } } = context;
|
|
401
|
+
const drain = flake.drain;
|
|
402
|
+
return drain?.form === "union" && drain.variants.size < getShapeBranches(flake.range.shape).length
|
|
403
|
+
? filter(or(...columns(context, flake).map(isBound)))
|
|
404
|
+
: nil();
|
|
405
|
+
}
|
|
406
|
+
//// Patterns /////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
407
|
+
/**
|
|
408
|
+
* The graph patterns binding everything the query reads under a node whose value `value` holds: the
|
|
409
|
+
* scalar transform stages and the branches the query reads, each nested inside its own edge and
|
|
410
|
+
* followed by its shards, so a branch binds only where its owner does and never fans out on its own.
|
|
411
|
+
*/
|
|
412
|
+
function patterns(context, node, value) {
|
|
413
|
+
const { scope, group: { locale, schema }, read, cells, keys } = context;
|
|
414
|
+
return fragment(stages(node, value), ...getFlakeEntries(node).filter(read).map(branch => step(node, branch, value)));
|
|
415
|
+
/**
|
|
416
|
+
* The binds of the scalar transform stages hanging off a node, each applying its whole pipe to the
|
|
417
|
+
* node value; a reducing stage binds nothing here, being projected and filtered post-aggregation.
|
|
418
|
+
*/
|
|
419
|
+
function stages(node, origin) {
|
|
420
|
+
return fragment(...getFlakeTransforms(node).filter(read).map(stage => isReduction(stage) ? nil() : fragment(bind(expression(origin, stage.pipe), variable(scope.resolve(stage))), stages(stage, origin))));
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* The patterns reaching one branch off its owner. A marker binds the owner itself (`id`) or its declared
|
|
424
|
+
* class (`type`). A localised property binds its coalesced label, or its raw tagged values under tagged
|
|
425
|
+
* options. A property mixing text with other variants binds its stored values folded (§3.2). Any other
|
|
426
|
+
* property binds its stored edge. The branch's own patterns nest inside the edge, which stays optional
|
|
427
|
+
* unless a constraint requires the path to exist, so a member lacking the path still yields its row.
|
|
428
|
+
*
|
|
429
|
+
* A locale placeholder states how a localised property is returned, never what a criterion on it reads
|
|
430
|
+
* (§5.4). The property then also binds its owner to a column of its own, and binds no value if nothing
|
|
431
|
+
* reads one, as no criterion or stage would ever filter, sort or compute on it.
|
|
432
|
+
*/
|
|
433
|
+
function step(parent, branch, owner) {
|
|
434
|
+
const value = scope.resolve(branch);
|
|
435
|
+
const entry = branch.entry;
|
|
436
|
+
const required = isRequiredFlake(branch) && !hasNullOptions(branch);
|
|
437
|
+
const valued = isConstrainedFlake(branch) || getFlakeTransforms(branch).some(read);
|
|
438
|
+
if (entry.kind === "id") {
|
|
439
|
+
return fragment(bind(variable(owner), variable(value)), patterns(context, branch, value));
|
|
440
|
+
}
|
|
441
|
+
else if (entry.kind === "type" && (branch.any !== undefined || branch.all !== undefined || branch.focus !== undefined)) {
|
|
442
|
+
// set matching reads the stored class lineage, so a supertype option spans its subtypes (§5.7.3)
|
|
443
|
+
return reached(pattern([owner, named(rdf.type), value]));
|
|
444
|
+
}
|
|
445
|
+
else if (entry.kind === "type") {
|
|
446
|
+
// any other read yields the one class the owner's shape declares, never the lineage
|
|
447
|
+
const classes = getShapeBranches(parent.range.shape).flatMap(variant => opt(getShapeClass(variant), clazz => [reference(clazz)], []));
|
|
448
|
+
return fragment(optional(pattern([owner, named(rdf.type), value]), filter(isIn(variable(value), classes))), patterns(context, branch, value));
|
|
449
|
+
}
|
|
450
|
+
else if (isLocalised(branch) && branch.drain?.form === "locale" && !valued) {
|
|
451
|
+
return owned();
|
|
452
|
+
}
|
|
453
|
+
else if (isLocalised(branch) && !hasDictionaryOptions(branch)) {
|
|
454
|
+
const edge = { owner, property: entry, object: scope.resolve() };
|
|
455
|
+
return reached(coalesced(scope, edge, variable(value), locale), edge);
|
|
456
|
+
}
|
|
457
|
+
else if (isMixed(branch)) {
|
|
458
|
+
const edge = { owner, property: entry, object: scope.resolve() };
|
|
459
|
+
return reached(folded(scope, edge, branch.range.shape, variable(value), locale), edge);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
const edge = { owner, property: entry, object: value };
|
|
463
|
+
return reached(link([owner, entry, value]), edge);
|
|
464
|
+
}
|
|
465
|
+
function reached(reach, edge) {
|
|
466
|
+
return fragment(required ? fragment(reach, patterns(context, branch, value)) : optional(reach, patterns(context, branch, value)), edge === undefined ? nil() : shards(context, branch, edge), owned());
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* The owner columns of a localised branch returned under a locale placeholder, which the decoder expands
|
|
470
|
+
* into the tag-range map the placeholder asks for. A branch retrieved as a union binds them in its shards.
|
|
471
|
+
*/
|
|
472
|
+
function owned() {
|
|
473
|
+
const returned = branch.drain?.form === "locale" && (cells.includes(branch) || keys.includes(branch));
|
|
474
|
+
return fragment((returned ? shard(schema, branch) : [])
|
|
475
|
+
.filter(({ form }) => form === "owner")
|
|
476
|
+
.map(candidate => bind(variable(owner), variable(column(scope, candidate)))));
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* The shards of a cell retrieved as a union (§5.5): one optional arm per requested variant, restating
|
|
482
|
+
* the edge on its stored object so the arm binds within its own group, gated by the variant's
|
|
483
|
+
* {@link membership} and binding the variant column. A localised variant binds its coalesced label
|
|
484
|
+
* (§6.2) or, under a locale placeholder, the owning resource the decoder expands. The arms stand beside
|
|
485
|
+
* the edge rather than inside it, so a folded or coalesced edge admitting no value under the request
|
|
486
|
+
* priority leaves the variant columns to bind on their own, and a member of another variant still surfaces.
|
|
487
|
+
* The root of a virtual collection has no edge to restate, so its membership alone gates each arm.
|
|
488
|
+
*
|
|
489
|
+
* Only a cell the query returns or groups by binds its arms: no clause reads the variant columns of other nodes.
|
|
490
|
+
*/
|
|
491
|
+
function shards(context, node, edge) {
|
|
492
|
+
const { scope, group: { flake, locale, virtual, schema }, cells, keys } = context;
|
|
493
|
+
const { owner, property, object } = edge;
|
|
494
|
+
const held = !virtual || node !== flake;
|
|
495
|
+
const projected = cells.includes(node) || keys.includes(node);
|
|
496
|
+
const columned = node.drain?.form === "union" && !isComputedFlake(node) && projected;
|
|
497
|
+
return !columned ? nil() : fragment(...shard(schema, node).map(candidate => {
|
|
498
|
+
const target = variable(column(scope, candidate));
|
|
499
|
+
return candidate.form === "owner"
|
|
500
|
+
? optional(link([owner, property, object]), filter(and(isLiteral(variable(object)), ne(lang(variable(object)), string("")))), bind(anchor(owner), target))
|
|
501
|
+
: candidate.form === "label"
|
|
502
|
+
? optional(coalesced(scope, edge, target, locale))
|
|
503
|
+
: optional(held ? link([owner, property, object]) : nil(), membership(object, candidate.variant), bind(variable(object), target));
|
|
504
|
+
}));
|
|
505
|
+
}
|
|
506
|
+
//// Filters //////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
507
|
+
/**
|
|
508
|
+
* The row filters under a node: its own constraints on `value`, then those of the scalar stages and
|
|
509
|
+
* branches the query reads; a reducing stage filters groups instead, through {@link conditions}.
|
|
510
|
+
*/
|
|
511
|
+
function filters(context, node, value) {
|
|
512
|
+
const { scope, group: { flake }, root, read } = context;
|
|
513
|
+
return [
|
|
514
|
+
...conditions(node, variable(value)).map(filter),
|
|
515
|
+
...conjunctions(node),
|
|
516
|
+
...getFlakeTransforms(node).filter(read).flatMap(stage => isReduction(stage) ? [] : filters(context, stage, scope.resolve(stage))),
|
|
517
|
+
...getFlakeEntries(node).filter(read).flatMap(branch => filters(context, branch, scope.resolve(branch)))
|
|
518
|
+
];
|
|
519
|
+
/**
|
|
520
|
+
* The `!` filters of a node (§5.7.3): every option must be carried by some value the node's
|
|
521
|
+
* expression resolves to, each probed by an `exists` re-walking the node's path from the member
|
|
522
|
+
* with fresh variables, so a multi-valued path is tested across its whole value set; a `null`
|
|
523
|
+
* option requires the path to resolve to nothing, probed by a `not exists` over the same path.
|
|
524
|
+
*/
|
|
525
|
+
function conjunctions(node) {
|
|
526
|
+
return opt(node.all, options => {
|
|
527
|
+
const { anchor, path } = node.path.reduce(({ at, anchor, path }, name) => {
|
|
528
|
+
const branch = (at.entries ?? {})[name];
|
|
529
|
+
const target = scope.resolve();
|
|
530
|
+
return branch.entry.kind === "id" ? { at: branch, anchor, path }
|
|
531
|
+
: branch.entry.kind === "type" ? {
|
|
532
|
+
at: branch,
|
|
533
|
+
anchor: target,
|
|
534
|
+
path: [...path, pattern([anchor, named(rdf.type), target])]
|
|
535
|
+
}
|
|
536
|
+
: { at: branch, anchor: target, path: [...path, link([anchor, branch.entry, target])] };
|
|
537
|
+
}, { at: flake, anchor: root, path: [] });
|
|
538
|
+
const value = expression(anchor, node.pipe);
|
|
539
|
+
return optionsToTerms(options, node.range).map(option => option === null ? filter(nexists(path))
|
|
540
|
+
: path.length === 0 ? filter(any(value, [option]))
|
|
541
|
+
: filter(exists(path, filter(any(value, [option])))));
|
|
542
|
+
}, []);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* The conditions a node's comparison, text-search and `?` constraints state over `value`, each resolving
|
|
547
|
+
* the operand against the node's range (§5.7).
|
|
548
|
+
*/
|
|
549
|
+
function conditions(node, value) {
|
|
550
|
+
return [
|
|
551
|
+
...opt(node.lt, bound => [comparison(lt, bound)], []),
|
|
552
|
+
...opt(node.gt, bound => [comparison(gt, bound)], []),
|
|
553
|
+
...opt(node.lte, bound => [comparison(lte, bound)], []),
|
|
554
|
+
...opt(node.gte, bound => [comparison(gte, bound)], []),
|
|
555
|
+
...opt(node.like, keywords => [like(value, keywords)], []),
|
|
556
|
+
...opt(node.any, options => [any(value, optionsToTerms(options, node.range))], [])
|
|
557
|
+
];
|
|
558
|
+
/**
|
|
559
|
+
* A comparison in the variant the bound singles out (§5.7.1), the other variants failing the guard
|
|
560
|
+
* (Appendix A.4.5): a boolean compares by its false < true rank; a string-kind variant, a coalesced
|
|
561
|
+
* localised label included, lexically, which also orders the ISO temporal forms a backend leaves opaque;
|
|
562
|
+
* any other by the bound's typed term, which a mismatched type never satisfies.
|
|
563
|
+
*/
|
|
564
|
+
function comparison(relate, bound) {
|
|
565
|
+
const variant = getBoundBranch(bound, getShapeBranches(node.range.shape))
|
|
566
|
+
?? error(new RangeError(`unresolved range variant for value <${String(bound)}>`));
|
|
567
|
+
return variant.kind === "boolean"
|
|
568
|
+
? and(isLiteral(value), eq(datatype(value), reference(xsd.boolean)), relate(iif(value, number(1), number(0)), bound ? number(1) : number(0)))
|
|
569
|
+
: (variant.kind === "string" && variant.datatype !== sh.IRI) || variant.kind === "dictionary"
|
|
570
|
+
? and(textual(value), relate(str(value), string(String(bound))))
|
|
571
|
+
: relate(value, term(valueToTerm(bound, variant)));
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* The text-search condition (§5.7.2): every whitespace-separated token of `keywords` is a case-insensitive
|
|
576
|
+
* substring of `value`, in any order, so a search matches a label however its words are arranged in it.
|
|
577
|
+
*/
|
|
578
|
+
function like(value, keywords) {
|
|
579
|
+
return and(...keywords
|
|
580
|
+
.toLowerCase()
|
|
581
|
+
.split(/\s+/)
|
|
582
|
+
.filter(token => token.length > 0)
|
|
583
|
+
.map(token => contains(lcase(value), string(token))));
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* The `?` condition (§5.7.3): `value` is one of `options`, a `null` option admitting an unbound value.
|
|
587
|
+
*/
|
|
588
|
+
function any(value, options) {
|
|
589
|
+
if (options.length === 0) {
|
|
590
|
+
return boolean(true);
|
|
591
|
+
}
|
|
592
|
+
else { // an empty option set is elided (§5)
|
|
593
|
+
const positive = options.filter(option => option !== null);
|
|
594
|
+
const negative = options.some(option => option === null);
|
|
595
|
+
const present = positive.length === 1
|
|
596
|
+
? eq(value, term(positive[0]))
|
|
597
|
+
: isIn(value, positive.map(term));
|
|
598
|
+
return coalesce(negative ? or(not(isBound(value)), present) : present, boolean(false) // a type mismatch is a non-match, not an error
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* The `!` condition over a single reduced value (§5.7.3): every option must equal it, so only a singleton
|
|
604
|
+
* set is satisfiable; a `null` option requires it unbound.
|
|
605
|
+
*/
|
|
606
|
+
function conjunction(value, options) {
|
|
607
|
+
if (options.length === 0) {
|
|
608
|
+
return boolean(true);
|
|
609
|
+
}
|
|
610
|
+
else { // an empty option set is elided (§5)
|
|
611
|
+
return and(options.some(option => option === null) ? not(isBound(value)) : nil(), ...options.flatMap(option => option === null ? [] : [any(value, [option])]));
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
//// Nodes ////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
615
|
+
/**
|
|
616
|
+
* Checks whether a transform stage reduces a group: it applies an aggregate, or wraps one in scalar
|
|
617
|
+
* transforms, so its value exists only after grouping and is projected and filtered rather than bound.
|
|
618
|
+
*/
|
|
619
|
+
function isReduction(stage) {
|
|
620
|
+
return stage.pipe.some(isAggregate);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Checks whether a branch resolves to localised text alone.
|
|
624
|
+
*/
|
|
625
|
+
function isLocalised(branch) {
|
|
626
|
+
return getShapeBranches(branch.range.shape).every(variant => variant.kind === "dictionary");
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Checks whether a branch resolves to localised text among other variants, as a path crossing a union whose
|
|
630
|
+
* variants declare the same property as text and as a plain value does (§5.8.1).
|
|
631
|
+
*/
|
|
632
|
+
function isMixed(branch) {
|
|
633
|
+
return !isLocalised(branch) && getShapeBranches(branch.range.shape).some(variant => variant.kind === "dictionary");
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* The variants of a node's range in the domain of an `aggregate` (§5.8.2): every variant for `count`, the literal
|
|
637
|
+
* variants for `min` and `max`, the number variants for `sum` and `avg`. A marker (an IRI-typed string), a
|
|
638
|
+
* reference and a resource lie outside every domain but `count`'s. A localised variant counts as a literal one,
|
|
639
|
+
* since the query reads it coalesced to a plain string (§6.2), which `min` and `max` order as any other string.
|
|
640
|
+
*/
|
|
641
|
+
function accepted(node, aggregate) {
|
|
642
|
+
const { accepts } = Transforms[aggregate];
|
|
643
|
+
return getShapeBranches(node.range.shape).filter(variant => accepts === "any" || (accepts === "numeric" ? variant.kind === "number"
|
|
644
|
+
: variant.kind === "boolean" || variant.kind === "number" || variant.kind === "dictionary"
|
|
645
|
+
|| (variant.kind === "string" && variant.datatype !== sh.IRI)));
|
|
646
|
+
}
|
|
647
|
+
//# sourceMappingURL=encode.js.map
|