@grafctory/keep-sparql 0.0.0-stage → 0.15.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.
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,134 @@
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 result decoder.
18
+ *
19
+ * Materialises one queued {@link Select} collection from its own solution rows, one member per row, in the returned
20
+ * order. A projection row becomes a record of its bindings, and a plain collection row becomes its member. Every
21
+ * cell is read off the {@link Schema | columns} the group schema declares for it: the first column that bound
22
+ * settles the variant and the form of the value, with no term inspection, so a cell never misreads a stored term.
23
+ *
24
+ * A request reads only the rows carrying its own entry in the owner column of its {@link Group | group}, already
25
+ * ordered and windowed by the server, so the decoder neither sorts nor slices and the row order is the result order.
26
+ *
27
+ * A resource or expanded reference is read off the resource the detail pass materialises for it, as is the owner
28
+ * of a localised property retrieved structurally (§5.4); the decoded collection depends on those requests and the
29
+ * spine runs them. Any other cell coerces its term. The decoder issues no request itself. The contract shared with
30
+ * the encoder is stated in `src/index.md`, next to the clause structure of the query.
31
+ *
32
+ * @module
33
+ */
34
+ import { getShapeTarget } from "@grafctory/blue/reference";
35
+ import { getShapeBranches } from "@grafctory/blue/union";
36
+ import { opt } from "@grafctory/core";
37
+ import { getFlakeProjection, getFlakeTemplate } from "@grafctory/keep-flake";
38
+ import { computedToValue, termToReference, termToValue } from "../terms.js";
39
+ import { all, map, plain, resource } from "../spine.js";
40
+ import { column } from "./schema.js";
41
+ /**
42
+ * Decodes one batched select request from its own `select` solution rows.
43
+ *
44
+ * @param scope The variable scope shared with the encoder, recovering the group's tuple slots
45
+ * @param group The group the request belongs to, which must be the very record handed to the encoder: its columns
46
+ * are keyed on the record's identity, so a copy or a fresh equivalent would resolve to different variables
47
+ * @param item The request to decode
48
+ * @param rows The solution rows binding the request's own entry, in solution order
49
+ *
50
+ * @returns The decoded collection, one value per row in row order, a row resolving to no value left out, depending
51
+ * on the detail requests its resource cells read their content from, in cell order
52
+ */
53
+ export function decode(scope, group, { request: { locale } }, rows) {
54
+ const { flake, schema } = group;
55
+ return map(all(rows.map(row => flake.drain?.form === "projection"
56
+ ? record(flake, row)
57
+ : cell(flake, flake, row))), values => values.flatMap(value => value === undefined ? [] : [value]));
58
+ /**
59
+ * One projection row: every binding the query projects, keyed by its alias, omitting a binding that
60
+ * resolves to no value (§5.2), so a record never carries an alias bound to no value at all.
61
+ */
62
+ function record(root, row) {
63
+ const cells = Object.entries(getFlakeProjection(root)).map(([alias, node]) => map(cell(root, node, row), value => ({ alias, value })));
64
+ return map(all(cells), bindings => Object.fromEntries(bindings.flatMap(({ alias, value }) => value === undefined ? [] : [[alias, value]])));
65
+ }
66
+ /**
67
+ * One cell of a row: the value of the first of its columns that bound, a row binding none of them, as a
68
+ * member of an unrequested variant does, resolving to no value and so left out of the decoded collection.
69
+ */
70
+ function cell(root, node, row) {
71
+ const bound = (schema.get(node) ?? []).flatMap(candidate => opt(row[column(scope, candidate)], term => [{ column: candidate, term }], []));
72
+ return bound.length === 0 ? plain(undefined)
73
+ : value(root, bound[0].column, bound[0].term);
74
+ }
75
+ /**
76
+ * The value a column's bound term stands for, by the column's form: a computed literal is coerced by its datatype;
77
+ * the owner of a localised property retrieved structurally is read off the resource the detail pass expands tag by
78
+ * tag (§5.4); a coalesced label is its string (§6.2); a stored value is coerced under the column's variant, a
79
+ * resource or reference being read off the resource the detail pass materialises where the request asks for its
80
+ * content, and kept as the bare reference naming it where it asks for the reference alone. The content is the
81
+ * template the request states for the cell; for the item itself bound through an empty path (§5.8.1), it is the
82
+ * template folded into the root. A sibling binding descending through the cell asks for no content, so
83
+ * `"v=vendor": {}` beside `"n=vendor.name": {}` keeps `v` a bare reference (grafctory/keep#24).
84
+ */
85
+ function value(root, { node, variant, drain, form }, term) {
86
+ if (form === "computed") {
87
+ return plain(computedToValue(term));
88
+ }
89
+ else if (form === "owner") {
90
+ const name = node.path[node.path.length - 1];
91
+ const owner = owning(root, node);
92
+ const entry = termToReference(term);
93
+ return entry === undefined || owner === undefined || drain?.form !== "locale" ? plain(undefined)
94
+ : resource({ entry, shape: owner, model: { [name]: drain.query }, locale }, resource => opt(resource[name], value => isSingle(value) ? value : undefined, undefined));
95
+ }
96
+ else if (form === "label") {
97
+ return plain(termToValue(term, variant));
98
+ }
99
+ else if (variant.kind === "resource" || variant.kind === "reference") {
100
+ const target = getShapeTarget(variant);
101
+ const model = node.drain?.form === "union" ? getFlakeTemplate(node, variant) : getFlakeTemplate(node);
102
+ const expanded = drain?.form === "template" || Object.keys(model).length > 0;
103
+ const entry = termToReference(term);
104
+ // the member's own content is the detail pass's responsibility, under the template the request stated
105
+ // for it, and is never reconstructed from the returned tuples, which carry the bare reference alone
106
+ return entry === undefined ? plain(undefined)
107
+ : expanded && target !== undefined ? resource({ entry, shape: target, model, locale }, resource => resource)
108
+ : plain(entry);
109
+ }
110
+ else {
111
+ return plain(termToValue(term, variant));
112
+ }
113
+ }
114
+ /**
115
+ * Checks whether a value set holds a single value: a localised property retrieved structurally yields its
116
+ * dictionary, a single value the cell takes as it is, never a list of values to fan out across rows.
117
+ */
118
+ function isSingle(values) {
119
+ return !Array.isArray(values);
120
+ }
121
+ /**
122
+ * The shape the detail pass expands a localised cell's owner under: the first resource the cell's parent
123
+ * range reaches that declares the property as localised, so a localised branch declared by one variant of
124
+ * a crossed union (§5.8.1) is expanded under that variant.
125
+ */
126
+ function owning(root, node) {
127
+ const name = node.path[node.path.length - 1];
128
+ const parent = node.path.slice(0, -1).reduce((at, step) => (at.entries ?? {})[step], root);
129
+ return getShapeBranches(parent.range.shape)
130
+ .flatMap(variant => opt(getShapeTarget(variant), target => [target], []))
131
+ .find(target => opt(target.members[name], member => member.kind === "property" && getShapeBranches(member.range.shape).some(variant => variant.kind === "dictionary"), false));
132
+ }
133
+ }
134
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/select/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,OAAO,EAAc,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAKzF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE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GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,CACjD,MAAM,CAAC,IAAI,KAAK,UAAU,IAAI,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,EAClH,KAAK,CACL,CAAC,CAAC;IAEL,CAAC;AAEF,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Select-pass query encoder.
3
+ *
4
+ * Folds the queued {@link Select} requests sharing one plan into one SPARQL `select` query. The owners are bound
5
+ * together, so the collections of every owner in a batch cost one query rather than one query per owner. Encoder and
6
+ * decoder share only the group record, its schema and the {@link Scope} allocating variables, so they agree on every
7
+ * column the query projects, and the decoder reads every column off the rows exactly as the encoder bound it.
8
+ *
9
+ * The query is assembled clause by clause from the {@link Group | group}'s {@link Flake | query plan}, covering only
10
+ * the nodes the query reads: the projection head, the graph patterns, the row filters, the group filters, the
11
+ * ordering and the window. Three switches, each settled once per group, decide how the clauses compose:
12
+ *
13
+ * - the **form** (QEST §5.8.2.1): `grouped` when a projection binding aggregates, the rows being groups; else
14
+ * `ungrouped`, the rows being members, rendered as `itemised` when a criterion aggregates, since SPARQL has no
15
+ * per-item reduction and the members are grouped in a subselect, then projected as distinct rows (§5.2);
16
+ * - the **arms**: one `values` block binding every owner, or, for a windowed plan over several owners, one
17
+ * subselect arm per owner, each windowing its own members, under an outer query restating the ordering, since a
18
+ * `limit` spans every owner bound in a query and would otherwise cut the pooled rows of every owner at once;
19
+ * - the **whole**-collection aggregation (§5.2): a keyless aggregation keeps an owner without members, so the
20
+ * member edge turns optional and the owner row survives an empty member set.
21
+ *
22
+ * Every reduced value is aggregated in a subselect of its own, over the members carrying it in a variant the
23
+ * aggregate accepts. Neither a missing value nor one held in an incompatible variant of a union therefore voids the
24
+ * aggregate (QEST Appendix A.4.2, A.4.5). Strict engines, Oxigraph and Jena among them, read SPARQL 1.1 §18.5.1 as
25
+ * voiding `min`, `max`, `sum` and `avg` over an unbound or mistyped input. A group whose members all lack the value
26
+ * leaves `min`, `max` and `avg` unbound, while `count` and `sum` come to `0` as the protocol requires.
27
+ *
28
+ * The contract shared with the decoder is stated in `src/index.md`.
29
+ *
30
+ * @module
31
+ */
32
+ import { type Property } from "@grafctory/blue/resource";
33
+ import type { Tag } from "@grafctory/core/language";
34
+ import type { Scope } from "@grafctory/core/scope";
35
+ import { type Flake } from "@grafctory/keep-flake";
36
+ import type { Deferred, Select } from "@grafctory/keep/batching";
37
+ import { type Query, type Slot } from "@grafctory/qest/model";
38
+ import type { SPARQL, Variable } from "@grafctory/wire-sparql";
39
+ import { type Schema } from "./schema.js";
40
+ /**
41
+ * The queued requests sharing one query plan: the same field, a structurally equal query and the same locale.
42
+ *
43
+ * The group is the unit the select pass batches on: its requests share the plan's variables, and the owner column
44
+ * tells them apart by entry. The shared {@link Scope} keys that column on the record's identity, so encoder and
45
+ * decoder must receive the very same records, never copies or fresh equivalents.
46
+ */
47
+ export type Group = {
48
+ /**
49
+ * Whether the requests read a virtual collection, binding its members by class rather than by the owner edge.
50
+ */
51
+ readonly virtual: boolean;
52
+ /**
53
+ * The multi-valued property the requests read.
54
+ */
55
+ readonly field: Property;
56
+ /**
57
+ * The collection query every request states.
58
+ */
59
+ readonly query: Query<Slot>;
60
+ /**
61
+ * The language priority every request states.
62
+ */
63
+ readonly locale: readonly Tag[];
64
+ /**
65
+ * The query plan shared by the requests.
66
+ */
67
+ readonly flake: Flake;
68
+ /**
69
+ * The table schema of the plan, the columns the query projects for each cell it returns.
70
+ */
71
+ readonly schema: Schema;
72
+ /**
73
+ * The requests, each bound to its own entry on the owner column.
74
+ */
75
+ readonly items: readonly Deferred<Select>[];
76
+ };
77
+ /**
78
+ * Encodes the batched `select` query covering every request of a group.
79
+ *
80
+ * @param scope The variable scope shared with the decoder, allocating the group's solution slots
81
+ * @param group The group to encode, pairing the requests sharing a {@link Flake | query plan} with that plan
82
+ *
83
+ * @returns The batched `select` query covering every request in `group`
84
+ */
85
+ export declare function encode(scope: Scope<Variable>, group: Group): SPARQL;
86
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/select/encode.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAiB,KAAK,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAMxE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAEN,KAAK,KAAK,EAaV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAIN,KAAK,KAAK,EACV,KAAK,IAAI,EAET,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAiE/D,OAAO,EAA0C,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAGlF;;;;;;GAMG;AACH,MAAM,MAAM,KAAK,GAAG;IAEnB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAE5B;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,EAAE,CAAC;IAEhC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,KA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