@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.
Files changed (67) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +115 -2
  3. package/dist/detail/decode.d.ts +40 -0
  4. package/dist/detail/decode.d.ts.map +1 -0
  5. package/dist/detail/decode.js +160 -0
  6. package/dist/detail/decode.js.map +1 -0
  7. package/dist/detail/encode.d.ts +45 -0
  8. package/dist/detail/encode.d.ts.map +1 -0
  9. package/dist/detail/encode.js +104 -0
  10. package/dist/detail/encode.js.map +1 -0
  11. package/dist/detail/index.d.ts +19 -0
  12. package/dist/detail/index.d.ts.map +1 -0
  13. package/dist/detail/index.js +61 -0
  14. package/dist/detail/index.js.map +1 -0
  15. package/dist/detail/schema.d.ts +86 -0
  16. package/dist/detail/schema.d.ts.map +1 -0
  17. package/dist/detail/schema.js +89 -0
  18. package/dist/detail/schema.js.map +1 -0
  19. package/dist/detect/encode.d.ts +23 -0
  20. package/dist/detect/encode.d.ts.map +1 -0
  21. package/dist/detect/encode.js +30 -0
  22. package/dist/detect/encode.js.map +1 -0
  23. package/dist/detect/index.d.ts +23 -0
  24. package/dist/detect/index.d.ts.map +1 -0
  25. package/dist/detect/index.js +37 -0
  26. package/dist/detect/index.js.map +1 -0
  27. package/dist/index.d.ts +56 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +158 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/modify/encode.d.ts +17 -0
  32. package/dist/modify/encode.d.ts.map +1 -0
  33. package/dist/modify/encode.js +233 -0
  34. package/dist/modify/encode.js.map +1 -0
  35. package/dist/modify/index.d.ts +21 -0
  36. package/dist/modify/index.d.ts.map +1 -0
  37. package/dist/modify/index.js +50 -0
  38. package/dist/modify/index.js.map +1 -0
  39. package/dist/patterns.d.ts +199 -0
  40. package/dist/patterns.d.ts.map +1 -0
  41. package/dist/patterns.js +321 -0
  42. package/dist/patterns.js.map +1 -0
  43. package/dist/select/decode.d.ts +20 -0
  44. package/dist/select/decode.d.ts.map +1 -0
  45. package/dist/select/decode.js +134 -0
  46. package/dist/select/decode.js.map +1 -0
  47. package/dist/select/encode.d.ts +86 -0
  48. package/dist/select/encode.d.ts.map +1 -0
  49. package/dist/select/encode.js +647 -0
  50. package/dist/select/encode.js.map +1 -0
  51. package/dist/select/index.d.ts +19 -0
  52. package/dist/select/index.d.ts.map +1 -0
  53. package/dist/select/index.js +62 -0
  54. package/dist/select/index.js.map +1 -0
  55. package/dist/select/schema.d.ts +75 -0
  56. package/dist/select/schema.d.ts.map +1 -0
  57. package/dist/select/schema.js +84 -0
  58. package/dist/select/schema.js.map +1 -0
  59. package/dist/spine.d.ts +167 -0
  60. package/dist/spine.d.ts.map +1 -0
  61. package/dist/spine.js +180 -0
  62. package/dist/spine.js.map +1 -0
  63. package/dist/terms.d.ts +116 -0
  64. package/dist/terms.d.ts.map +1 -0
  65. package/dist/terms.js +251 -0
  66. package/dist/terms.js.map +1 -0
  67. package/package.json +66 -4
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Shape-aware SPARQL emitters.
3
+ *
4
+ * The graph patterns and expressions every pass composes its clauses from: the stored edge of a property, the
5
+ * clause gating a union variant, the test telling a plain string apart, the expression applying a transform pipe,
6
+ * and the patterns settling localised text. Each emitter renders one shape-level notion into SPARQL text and knows
7
+ * nothing of the pass calling it, so the passes differ only in how they assemble clauses from them, and a connector
8
+ * for another query language reimplements this module alone, leaving the spine, the codecs and the drivers as they are.
9
+ *
10
+ * **Localised text.** A localised label is coalesced where it is consumed (§6.2). The select pass filters, sorts
11
+ * and projects on the label, so {@link coalesced} and {@link folded} settle it in SPARQL under the request's
12
+ * language priority; the detail pass only returns it, and under a locale placeholder returns every tag, so it reads
13
+ * the raw tagged values and coalesces them in the decoder through the tag-priority reader of `terms.ts`. Both halves
14
+ * apply the same priority: the first tag of the request's locale the property carries a value under wins.
15
+ *
16
+ * @module
17
+ */
18
+ import { type Property } from "@grafctory/blue/resource";
19
+ import { type Shape } from "@grafctory/blue/value";
20
+ import { type Lazy } from "@grafctory/core";
21
+ import type { Tag } from "@grafctory/core/language";
22
+ import type { Scope } from "@grafctory/core/scope";
23
+ import { type Transform } from "@grafctory/qest/model";
24
+ import { type Named, type Subject, type Term } from "@grafctory/trio";
25
+ import type { SPARQL, Variable } from "@grafctory/wire-sparql";
26
+ /**
27
+ * The stored edge a node is reached through.
28
+ */
29
+ export type Edge = {
30
+ /**
31
+ * The subject holding the property: a variable, or the IRI of the request entry.
32
+ */
33
+ readonly owner: Variable | Named;
34
+ /**
35
+ * The property the edge stores.
36
+ */
37
+ readonly property: Property;
38
+ /**
39
+ * The variable bound to the stored object, which is the node value itself unless the node coalesces or folds text.
40
+ */
41
+ readonly object: Variable;
42
+ };
43
+ /**
44
+ * Generates the SPARQL triple pattern matching the stored edge from `source` to `target` through a
45
+ * {@link Property | property}, in whichever of its declared directions the two ends can be stated.
46
+ *
47
+ * Both declared directions store the value, so either one connects the pair. The forward direction is used if the
48
+ * property declares one and `source` may stand in subject position; otherwise the reverse direction is used if
49
+ * `target` may, a literal never standing as the subject of a stored triple whatever the property declares.
50
+ *
51
+ * @param edge The edge to match, as a `[source, property, target]` tuple
52
+ *
53
+ * @returns The generated triple pattern, or the empty fragment if neither direction applies
54
+ *
55
+ * @see {@link https://www.w3.org/TR/sparql11-query/#QSynTriples SPARQL 1.1 Triple Patterns}
56
+ */
57
+ export declare function link([source, property, target]: readonly [Variable | Term, Property, Variable | Term]): SPARQL;
58
+ /**
59
+ * Generates the SPARQL triple pattern for a {@link Property | property}'s forward direction.
60
+ *
61
+ * The pattern reads `subject forward object`. The reverse-direction counterpart is {@link reverse}.
62
+ *
63
+ * @param edge The edge to render, as a `[subject, property, object]` tuple
64
+ *
65
+ * @returns The generated triple pattern, or the empty fragment if the property declares no `forward` predicate
66
+ *
67
+ * @see {@link https://www.w3.org/TR/sparql11-query/#QSynTriples SPARQL 1.1 Triple Patterns}
68
+ */
69
+ export declare function forward([subject, property, object]: readonly [Variable | Subject, Property, Variable | Term]): SPARQL;
70
+ /**
71
+ * Generates the SPARQL triple pattern for a {@link Property | property}'s reverse direction.
72
+ *
73
+ * The edge is stated in forward order and the pattern swaps its ends, reading `subject reverse object`. The forward
74
+ * object becomes the subject of the stored triple, so it is constrained to a variable, a blank node or an IRI, and
75
+ * a literal object cannot be stated this way at all. The forward-direction counterpart is {@link forward}.
76
+ *
77
+ * @param edge The edge to render, in forward order, as an `[object, property, subject]` tuple
78
+ *
79
+ * @returns The generated triple pattern, or the empty fragment if the property declares no `reverse` predicate
80
+ *
81
+ * @see {@link https://www.w3.org/TR/sparql11-query/#QSynTriples SPARQL 1.1 Triple Patterns}
82
+ */
83
+ export declare function reverse([object, property, subject]: readonly [Variable | Term, Property, Variable | Subject]): SPARQL;
84
+ /**
85
+ * Renders the subject an edge hangs off: a variable or the IRI of the request entry.
86
+ *
87
+ * @param owner The edge subject to render
88
+ *
89
+ * @returns The rendered subject
90
+ */
91
+ export declare function anchor(owner: Variable | Named): SPARQL;
92
+ /**
93
+ * Generates the SPARQL clause admitting only the values belonging to a union variant.
94
+ *
95
+ * A classed resource or reference variant is gated by its stored `rdf:type` triple, and a classless one by an IRI
96
+ * test. A literal variant is gated by a `filter` over its {@link admission} test. Union variants are disjoint by
97
+ * contract, so at most one variant admits a given value and a stored value never surfaces under two of them.
98
+ *
99
+ * @param anchor The variable holding the value
100
+ * @param shape The variant to gate on
101
+ *
102
+ * @returns The gating triple pattern or `filter`
103
+ *
104
+ * @throws {@link !RangeError RangeError} If `shape` is a union shape
105
+ */
106
+ export declare function membership(anchor: Variable, shape: Shape): SPARQL;
107
+ /**
108
+ * Generates the SPARQL test admitting a value into a literal variant of a union (§5.5).
109
+ *
110
+ * The test is the expression form of the {@link membership} gate. It composes into larger filter expressions where a
111
+ * clause cannot go, such as the branch guard keeping incompatible variants out of an aggregate (Appendix A.4.5). A
112
+ * localised `dictionary` variant differs from a plain `string` one by its language tag, so no value passes both tests.
113
+ *
114
+ * @param value The expression holding the value
115
+ * @param shape The literal variant to test for
116
+ *
117
+ * @returns The boolean expression holding when `value` belongs to `shape`
118
+ *
119
+ * @throws {@link !RangeError RangeError} If `shape` is a reference, resource or union shape: membership in a reference
120
+ * or resource variant depends on the stored class, and is gated by {@link membership} as a graph pattern instead
121
+ */
122
+ export declare function admission(value: SPARQL, shape: Shape): SPARQL;
123
+ /**
124
+ * Generates the SPARQL patterns binding the values a range describes, with no edge reaching them.
125
+ *
126
+ * Binds every stored instance of the classes the range variants declare, as the extension a virtual collection reads.
127
+ * Each variant contributes a `union` arm through its {@link membership}. Literal and classless variants bind nothing,
128
+ * as only an edge reaches them, so a range declaring no class leaves a virtual collection empty.
129
+ *
130
+ * @param anchor The variable holding the value
131
+ * @param shape The range to bind, possibly a union
132
+ *
133
+ * @returns The binding patterns, one arm per variant
134
+ */
135
+ export declare function extension(anchor: Variable, shape: Lazy<Shape>): SPARQL;
136
+ /**
137
+ * Generates the SPARQL test admitting a plain string value.
138
+ *
139
+ * A plain string is a literal carrying neither a language tag nor a boolean or numeric datatype. Stored strings,
140
+ * temporal values the backend leaves opaque, and coalesced localised labels (§6.2) all pass the test.
141
+ *
142
+ * @param value The expression to test
143
+ *
144
+ * @returns The boolean expression holding when `value` is a plain string
145
+ */
146
+ export declare function textual(value: SPARQL): SPARQL;
147
+ /**
148
+ * Generates the patterns binding a localised property's coalesced label (§6.2).
149
+ *
150
+ * The first tag of the request's language priority the property carries wins, and the values under it come back as
151
+ * plain strings, so every construct downstream reads an ordinary `xsd:string`. Only language-tagged values are text: a
152
+ * plain string a sibling string variant stores never passes. An owner carrying no value under any priority tag binds
153
+ * nothing, as every owner does under an empty priority, which is taken literally rather than defaulted (§6.2).
154
+ *
155
+ * The patterns return one row per value under the winning tag and bind only where the owner is bound, so they nest
156
+ * safely inside any group at any depth, `optional` groups included. The winning tag is settled by presence alone
157
+ * (Appendix A.5): a property carrying several strings per tag never multiplies its rows by the values under other tags.
158
+ *
159
+ * @param scope The variable scope allocating the probe the priority is settled with
160
+ * @param edge The edge storing the localised values
161
+ * @param target The variable the label is bound to
162
+ * @param locale The request's language priority, most preferred first
163
+ *
164
+ * @returns The patterns binding the label to `target`
165
+ */
166
+ export declare function coalesced(scope: Scope<Variable>, edge: Edge, target: SPARQL, locale: readonly Tag[]): readonly SPARQL[];
167
+ /**
168
+ * Generates the patterns binding a property mixing text with other variants, folded (§3.2).
169
+ *
170
+ * A tagged value passes under the winning tag of the request's language priority alone, as a plain string; any
171
+ * other stored value, a plain string or a node among them, passes as it is, so one column carries every variant.
172
+ *
173
+ * @param scope The variable scope allocating the probe the priority is settled with
174
+ * @param edge The edge storing the mixed values
175
+ * @param shape The range of the stored values, possibly a union
176
+ * @param target The variable the folded value is bound to
177
+ * @param locale The request's language priority, most preferred first
178
+ *
179
+ * @returns The patterns binding the folded value to `target`
180
+ */
181
+ export declare function folded(scope: Scope<Variable>, edge: Edge, shape: Lazy<Shape>, target: SPARQL, locale: readonly Tag[]): readonly SPARQL[];
182
+ /**
183
+ * Generates the SPARQL expression applying a transform `pipe` to an `anchor` expression (§5.8.2).
184
+ *
185
+ * The trailing transform applies to `anchor` first and the leading transform is outermost. Each {@link Transform}
186
+ * maps to its SPARQL aggregate or scalar function unchanged, so aggregates keep their SPARQL 1.1 §18.5.1 semantics:
187
+ * strict engines void an aggregate fed an unbound or mistyped value, and an empty group averages to `0`. Callers
188
+ * must feed aggregates bound values only, never an empty group, and only values in the domain of the aggregate: the
189
+ * {@link admission} test keeps out the variants of a union outside it (QEST Appendix A.4.2, A.4.3, A.4.5).
190
+ *
191
+ * @param anchor The expression the pipe transforms, typically a value variable
192
+ * @param pipe The transforms to compose, leading (outermost) first
193
+ *
194
+ * @returns The SPARQL expression applying `pipe` to `anchor`, or `anchor` itself when `pipe` is empty
195
+ *
196
+ * @see {@link https://www.w3.org/TR/sparql11-query/#aggregates SPARQL 1.1 Aggregates}
197
+ */
198
+ export declare function expression(anchor: SPARQL, pipe: readonly Transform[]): SPARQL;
199
+ //# sourceMappingURL=patterns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../src/patterns.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAExE,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAY,KAAK,IAAI,EAAO,MAAM,iBAAiB,CAAC;AAE3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAS,KAAK,KAAK,EAAO,KAAK,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAgD/D;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG;IAElB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,CAAC;IAEjC;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;CAE1B,CAAC;AAKF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,QAAQ,GAAG,IAAI,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC,GAAG,MAAM,CAa9G;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC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SAAS,GAAG,EAAE,GACpB,SAAS,MAAM,EAAE,CAiBnB;AA2BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAoF7E"}
@@ -0,0 +1,321 @@
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
+ * Shape-aware SPARQL emitters.
18
+ *
19
+ * The graph patterns and expressions every pass composes its clauses from: the stored edge of a property, the
20
+ * clause gating a union variant, the test telling a plain string apart, the expression applying a transform pipe,
21
+ * and the patterns settling localised text. Each emitter renders one shape-level notion into SPARQL text and knows
22
+ * nothing of the pass calling it, so the passes differ only in how they assemble clauses from them, and a connector
23
+ * for another query language reimplements this module alone, leaving the spine, the codecs and the drivers as they are.
24
+ *
25
+ * **Localised text.** A localised label is coalesced where it is consumed (§6.2). The select pass filters, sorts
26
+ * and projects on the label, so {@link coalesced} and {@link folded} settle it in SPARQL under the request's
27
+ * language priority; the detail pass only returns it, and under a locale placeholder returns every tag, so it reads
28
+ * the raw tagged values and coalesces them in the decoder through the tag-priority reader of `terms.ts`. Both halves
29
+ * apply the same priority: the first tag of the request's locale the property carries a value under wins.
30
+ *
31
+ * @module
32
+ */
33
+ import { getShapeClass } from "@grafctory/blue/resource";
34
+ import { getShapeBranches } from "@grafctory/blue/union";
35
+ import { isString, opt } from "@grafctory/core";
36
+ import { xsd } from "@grafctory/core/datatype";
37
+ import { named, rdf } from "@grafctory/trio";
38
+ import { abs, and, avg, bind, boolean, ceil, coalesce, count, datatype, day, eq, exists, filter, floor, hours, iif, isIRI, isLiteral, isNumeric, lang, lcase, max, min, minutes, month, ne, nil, not, or, pattern, reference, round, seconds, str, string, strlen, sum, term, ucase, union, variable, year } from "@grafctory/wire-sparql/builder";
39
+ //// Edges ////////////////////////////////////////////////////////////////////////////////////////////////////////////
40
+ /**
41
+ * Generates the SPARQL triple pattern matching the stored edge from `source` to `target` through a
42
+ * {@link Property | property}, in whichever of its declared directions the two ends can be stated.
43
+ *
44
+ * Both declared directions store the value, so either one connects the pair. The forward direction is used if the
45
+ * property declares one and `source` may stand in subject position; otherwise the reverse direction is used if
46
+ * `target` may, a literal never standing as the subject of a stored triple whatever the property declares.
47
+ *
48
+ * @param edge The edge to match, as a `[source, property, target]` tuple
49
+ *
50
+ * @returns The generated triple pattern, or the empty fragment if neither direction applies
51
+ *
52
+ * @see {@link https://www.w3.org/TR/sparql11-query/#QSynTriples SPARQL 1.1 Triple Patterns}
53
+ */
54
+ export function link([source, property, target]) {
55
+ const forward = property.forward;
56
+ const reverse = property.reverse;
57
+ return forward !== undefined && isAnchor(source) ? pattern([source, named(forward), target])
58
+ : reverse !== undefined && isAnchor(target) ? pattern([target, named(reverse), source])
59
+ : nil();
60
+ function isAnchor(value) {
61
+ return isString(value) || value.kind === "blank" || value.kind === "named";
62
+ }
63
+ }
64
+ /**
65
+ * Generates the SPARQL triple pattern for a {@link Property | property}'s forward direction.
66
+ *
67
+ * The pattern reads `subject forward object`. The reverse-direction counterpart is {@link reverse}.
68
+ *
69
+ * @param edge The edge to render, as a `[subject, property, object]` tuple
70
+ *
71
+ * @returns The generated triple pattern, or the empty fragment if the property declares no `forward` predicate
72
+ *
73
+ * @see {@link https://www.w3.org/TR/sparql11-query/#QSynTriples SPARQL 1.1 Triple Patterns}
74
+ */
75
+ export function forward([subject, property, object]) {
76
+ return opt(property.forward, forward => pattern([subject, named(forward), object]), nil());
77
+ }
78
+ /**
79
+ * Generates the SPARQL triple pattern for a {@link Property | property}'s reverse direction.
80
+ *
81
+ * The edge is stated in forward order and the pattern swaps its ends, reading `subject reverse object`. The forward
82
+ * object becomes the subject of the stored triple, so it is constrained to a variable, a blank node or an IRI, and
83
+ * a literal object cannot be stated this way at all. The forward-direction counterpart is {@link forward}.
84
+ *
85
+ * @param edge The edge to render, in forward order, as an `[object, property, subject]` tuple
86
+ *
87
+ * @returns The generated triple pattern, or the empty fragment if the property declares no `reverse` predicate
88
+ *
89
+ * @see {@link https://www.w3.org/TR/sparql11-query/#QSynTriples SPARQL 1.1 Triple Patterns}
90
+ */
91
+ export function reverse([object, property, subject]) {
92
+ return opt(property.reverse, reverse => pattern([subject, named(reverse), object]), nil());
93
+ }
94
+ /**
95
+ * Renders the subject an edge hangs off: a variable or the IRI of the request entry.
96
+ *
97
+ * @param owner The edge subject to render
98
+ *
99
+ * @returns The rendered subject
100
+ */
101
+ export function anchor(owner) {
102
+ return isString(owner) ? variable(owner) : term(owner);
103
+ }
104
+ //// Variants /////////////////////////////////////////////////////////////////////////////////////////////////////////
105
+ /**
106
+ * Generates the SPARQL clause admitting only the values belonging to a union variant.
107
+ *
108
+ * A classed resource or reference variant is gated by its stored `rdf:type` triple, and a classless one by an IRI
109
+ * test. A literal variant is gated by a `filter` over its {@link admission} test. Union variants are disjoint by
110
+ * contract, so at most one variant admits a given value and a stored value never surfaces under two of them.
111
+ *
112
+ * @param anchor The variable holding the value
113
+ * @param shape The variant to gate on
114
+ *
115
+ * @returns The gating triple pattern or `filter`
116
+ *
117
+ * @throws {@link !RangeError RangeError} If `shape` is a union shape
118
+ */
119
+ export function membership(anchor, shape) {
120
+ const value = variable(anchor);
121
+ switch (shape.kind) {
122
+ case "boolean":
123
+ case "number":
124
+ case "string":
125
+ case "dictionary":
126
+ return filter(admission(value, shape));
127
+ case "reference":
128
+ case "resource":
129
+ return opt(getShapeClass(shape), clazz => pattern([anchor, named(rdf.type), named(clazz)]), () => filter(isIRI(value)));
130
+ case "union": // a range variant is always a flattened branch, never a union
131
+ throw new RangeError(`unsupported union variant`);
132
+ }
133
+ }
134
+ /**
135
+ * Generates the SPARQL test admitting a value into a literal variant of a union (§5.5).
136
+ *
137
+ * The test is the expression form of the {@link membership} gate. It composes into larger filter expressions where a
138
+ * clause cannot go, such as the branch guard keeping incompatible variants out of an aggregate (Appendix A.4.5). A
139
+ * localised `dictionary` variant differs from a plain `string` one by its language tag, so no value passes both tests.
140
+ *
141
+ * @param value The expression holding the value
142
+ * @param shape The literal variant to test for
143
+ *
144
+ * @returns The boolean expression holding when `value` belongs to `shape`
145
+ *
146
+ * @throws {@link !RangeError RangeError} If `shape` is a reference, resource or union shape: membership in a reference
147
+ * or resource variant depends on the stored class, and is gated by {@link membership} as a graph pattern instead
148
+ */
149
+ export function admission(value, shape) {
150
+ switch (shape.kind) {
151
+ case "boolean":
152
+ return and(isLiteral(value), eq(datatype(value), reference(xsd.boolean)));
153
+ case "number":
154
+ return isNumeric(value);
155
+ case "string":
156
+ return textual(value);
157
+ case "dictionary":
158
+ return and(isLiteral(value), ne(lang(value), string("")));
159
+ case "reference":
160
+ case "resource":
161
+ case "union":
162
+ throw new RangeError(`unsupported ${shape.kind} variant`);
163
+ }
164
+ }
165
+ /**
166
+ * Generates the SPARQL patterns binding the values a range describes, with no edge reaching them.
167
+ *
168
+ * Binds every stored instance of the classes the range variants declare, as the extension a virtual collection reads.
169
+ * Each variant contributes a `union` arm through its {@link membership}. Literal and classless variants bind nothing,
170
+ * as only an edge reaches them, so a range declaring no class leaves a virtual collection empty.
171
+ *
172
+ * @param anchor The variable holding the value
173
+ * @param shape The range to bind, possibly a union
174
+ *
175
+ * @returns The binding patterns, one arm per variant
176
+ */
177
+ export function extension(anchor, shape) {
178
+ return union(getShapeBranches(shape).map(variant => membership(anchor, variant)));
179
+ }
180
+ /**
181
+ * Generates the SPARQL test admitting a plain string value.
182
+ *
183
+ * A plain string is a literal carrying neither a language tag nor a boolean or numeric datatype. Stored strings,
184
+ * temporal values the backend leaves opaque, and coalesced localised labels (§6.2) all pass the test.
185
+ *
186
+ * @param value The expression to test
187
+ *
188
+ * @returns The boolean expression holding when `value` is a plain string
189
+ */
190
+ export function textual(value) {
191
+ return and(isLiteral(value), eq(lang(value), string("")), ne(datatype(value), reference(xsd.boolean)), not(isNumeric(value)));
192
+ }
193
+ //// Localised Text ///////////////////////////////////////////////////////////////////////////////////////////////////
194
+ /**
195
+ * Generates the patterns binding a localised property's coalesced label (§6.2).
196
+ *
197
+ * The first tag of the request's language priority the property carries wins, and the values under it come back as
198
+ * plain strings, so every construct downstream reads an ordinary `xsd:string`. Only language-tagged values are text: a
199
+ * plain string a sibling string variant stores never passes. An owner carrying no value under any priority tag binds
200
+ * nothing, as every owner does under an empty priority, which is taken literally rather than defaulted (§6.2).
201
+ *
202
+ * The patterns return one row per value under the winning tag and bind only where the owner is bound, so they nest
203
+ * safely inside any group at any depth, `optional` groups included. The winning tag is settled by presence alone
204
+ * (Appendix A.5): a property carrying several strings per tag never multiplies its rows by the values under other tags.
205
+ *
206
+ * @param scope The variable scope allocating the probe the priority is settled with
207
+ * @param edge The edge storing the localised values
208
+ * @param target The variable the label is bound to
209
+ * @param locale The request's language priority, most preferred first
210
+ *
211
+ * @returns The patterns binding the label to `target`
212
+ */
213
+ export function coalesced(scope, edge, target, locale) {
214
+ const { owner, property, object } = edge;
215
+ const raw = variable(object);
216
+ return [
217
+ link([owner, property, object]),
218
+ filter(winning(scope, edge, lang(raw), locale)),
219
+ bind(str(raw), target)
220
+ ];
221
+ }
222
+ /**
223
+ * Generates the patterns binding a property mixing text with other variants, folded (§3.2).
224
+ *
225
+ * A tagged value passes under the winning tag of the request's language priority alone, as a plain string; any
226
+ * other stored value, a plain string or a node among them, passes as it is, so one column carries every variant.
227
+ *
228
+ * @param scope The variable scope allocating the probe the priority is settled with
229
+ * @param edge The edge storing the mixed values
230
+ * @param shape The range of the stored values, possibly a union
231
+ * @param target The variable the folded value is bound to
232
+ * @param locale The request's language priority, most preferred first
233
+ *
234
+ * @returns The patterns binding the folded value to `target`
235
+ */
236
+ export function folded(scope, edge, shape, target, locale) {
237
+ const { owner, property, object } = edge;
238
+ const raw = variable(object);
239
+ // reading the tag of a node is an error, which only a range admitting a node has to guard against
240
+ const nodes = getShapeBranches(shape).some(variant => variant.kind === "reference" || variant.kind === "resource");
241
+ const tag = nodes ? coalesce(lang(raw), string("")) : lang(raw);
242
+ return [
243
+ link([owner, property, object]),
244
+ filter(or(eq(tag, string("")), winning(scope, edge, tag, locale))),
245
+ bind(iif(eq(tag, string("")), raw, str(raw)), target)
246
+ ];
247
+ }
248
+ /**
249
+ * Generates the condition holding if `tag` is the one the request's language priority picks for a property's text.
250
+ *
251
+ * A priority tag wins if the owner has no value under any tag ranked ahead of it. Under an empty priority, no tag
252
+ * wins, so the condition never holds and an owner binds no localised value at all.
253
+ */
254
+ function winning(scope, { owner, property }, tag, locale) {
255
+ const probe = scope.resolve();
256
+ return locale.length === 0 ? boolean(false) : or(locale.map((candidate, index) => and(eq(tag, string(candidate)), locale.slice(0, index).map(ahead => not(present(ahead))))));
257
+ function present(ahead) {
258
+ return exists(link([owner, property, probe]), filter(eq(lang(variable(probe)), string(ahead))));
259
+ }
260
+ }
261
+ //// Transforms ///////////////////////////////////////////////////////////////////////////////////////////////////////
262
+ /**
263
+ * Generates the SPARQL expression applying a transform `pipe` to an `anchor` expression (§5.8.2).
264
+ *
265
+ * The trailing transform applies to `anchor` first and the leading transform is outermost. Each {@link Transform}
266
+ * maps to its SPARQL aggregate or scalar function unchanged, so aggregates keep their SPARQL 1.1 §18.5.1 semantics:
267
+ * strict engines void an aggregate fed an unbound or mistyped value, and an empty group averages to `0`. Callers
268
+ * must feed aggregates bound values only, never an empty group, and only values in the domain of the aggregate: the
269
+ * {@link admission} test keeps out the variants of a union outside it (QEST Appendix A.4.2, A.4.3, A.4.5).
270
+ *
271
+ * @param anchor The expression the pipe transforms, typically a value variable
272
+ * @param pipe The transforms to compose, leading (outermost) first
273
+ *
274
+ * @returns The SPARQL expression applying `pipe` to `anchor`, or `anchor` itself when `pipe` is empty
275
+ *
276
+ * @see {@link https://www.w3.org/TR/sparql11-query/#aggregates SPARQL 1.1 Aggregates}
277
+ */
278
+ export function expression(anchor, pipe) {
279
+ return pipe.reduceRight((expression, transform) => apply(expression, transform), anchor);
280
+ function apply(expression, transform) {
281
+ switch (transform) {
282
+ case "count":
283
+ return count(expression);
284
+ case "sum":
285
+ return sum(expression);
286
+ case "min":
287
+ return min(expression);
288
+ case "max":
289
+ return max(expression);
290
+ case "avg":
291
+ return avg(expression);
292
+ case "length":
293
+ return strlen(expression);
294
+ case "lower":
295
+ return lcase(expression);
296
+ case "upper":
297
+ return ucase(expression);
298
+ case "abs":
299
+ return abs(expression);
300
+ case "floor":
301
+ return floor(expression);
302
+ case "ceil":
303
+ return ceil(expression);
304
+ case "round":
305
+ return round(expression);
306
+ case "year":
307
+ return year(expression);
308
+ case "month":
309
+ return month(expression);
310
+ case "day":
311
+ return day(expression);
312
+ case "hours":
313
+ return hours(expression);
314
+ case "minutes":
315
+ return minutes(expression);
316
+ case "seconds":
317
+ return seconds(expression);
318
+ }
319
+ }
320
+ }
321
+ //# sourceMappingURL=patterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.js","sourceRoot":"","sources":["../src/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,aAAa,EAAiB,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAa,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAI/C,OAAO,EAAE,KAAK,EAAc,GAAG,EAA2B,MAAM,iBAAiB,CAAC;AAElF,OAAO,EACN,GAAG,EACH,GAAG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AC;YAE1B,KAAK,MAAM;gBAEV,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC;YAEzB,KAAK,OAAO;gBAEX,OAAO,KAAK,CAAC,UAAU,CAAC,CAAC;YAE1B,KAAK,MAAM;gBAEV,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC;YAEzB,KAAK,OAAO;gBAEX,OAAO,KAAK,CAAC,UAAU,CAAC,CAAC;YAE1B,KAAK,KAAK;gBAET,OAAO,GAAG,CAAC,UAAU,CAAC,CAAC;YAExB,KAAK,OAAO;gBAEX,OAAO,KAAK,CAAC,UAAU,CAAC,CAAC;YAE1B,KAAK,SAAS;gBAEb,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;YAE5B,KAAK,SAAS;gBAEb,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;QAE7B,CAAC;IAEF,CAAC;AAEF,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { Scope } from "@grafctory/core/scope";
2
+ import type { Deferred, Select } from "@grafctory/keep/batching";
3
+ import type { Value } from "@grafctory/qest/state";
4
+ import type { Tuple, Variable } from "@grafctory/wire-sparql";
5
+ import { type Decoded } from "../spine.js";
6
+ import type { Group } from "./encode.js";
7
+ /**
8
+ * Decodes one batched select request from its own `select` solution rows.
9
+ *
10
+ * @param scope The variable scope shared with the encoder, recovering the group's tuple slots
11
+ * @param group The group the request belongs to, which must be the very record handed to the encoder: its columns
12
+ * are keyed on the record's identity, so a copy or a fresh equivalent would resolve to different variables
13
+ * @param item The request to decode
14
+ * @param rows The solution rows binding the request's own entry, in solution order
15
+ *
16
+ * @returns The decoded collection, one value per row in row order, a row resolving to no value left out, depending
17
+ * on the detail requests its resource cells read their content from, in cell order
18
+ */
19
+ export declare function decode(scope: Scope<Variable>, group: Group, { request: { locale } }: Deferred<Select>, rows: readonly Tuple[]): Decoded<readonly Value[]>;
20
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/select/decode.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,KAAK,EAAU,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAO,KAAK,OAAO,EAAwB,MAAM,aAAa,CAAC;AACtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAIzC;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,EACtB,KAAK,EAAE,KAAK,EACZ,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,EACzC,IAAI,EAAE,SAAS,KAAK,EAAE,GACpB,OAAO,CAAC,SAAS,KAAK,EAAE,CAAC,CAyH3B"}