@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
package/dist/index.js ADDED
@@ -0,0 +1,158 @@
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
+ * SPARQL 1.1 repository connector.
18
+ *
19
+ * Turns any SPARQL 1.1 {@link Repository} into a fully featured {@link Store}, so shape-driven retrieval and
20
+ * persistence run against a graph backend without hand-written queries. A ready-made connector from the
21
+ * {@link https://github.com/grafctory/wire @grafctory/wire} collection (Oxigraph, generic HTTP endpoints, RDF4J, …)
22
+ * covers the common backends; a new backend is supported by implementing {@link Repository} directly.
23
+ *
24
+ * **Wiring a Connector**
25
+ *
26
+ * A ready-made connector is passed to {@link createSPARQLStore} to obtain a store:
27
+ *
28
+ * ```typescript
29
+ * import { createSPARQLStore } from "@grafctory/keep-sparql";
30
+ * import { createOxiRepository } from "@grafctory/wire-sparql-oxigraph";
31
+ *
32
+ * const store = createSPARQLStore(createOxiRepository());
33
+ *
34
+ * await store.create({
35
+ * entry: "http://example.com/products/",
36
+ * shape: CatalogueShape,
37
+ * model: { products: {} },
38
+ * state: { name: "Widget", price: 9.99 }
39
+ * });
40
+ * ```
41
+ *
42
+ * **Implementing a Connector**
43
+ *
44
+ * A new SPARQL backend is supported by implementing a {@link @grafctory/wire-sparql!Repository | Repository}. The
45
+ * repository exchanges {@link @grafctory/wire-sparql!SPARQL | SPARQL} text and
46
+ * {@link @grafctory/wire-sparql!Tuple | Tuple} solution rows, whose values are `@grafctory/trio`
47
+ * {@link @grafctory/trio!Term | Term} values. Backend node values are lifted into terms with the
48
+ * {@link @grafctory/trio!named | named}, {@link @grafctory/trio!tagged | tagged} and {@link @grafctory/trio!typed | typed}
49
+ * constructors. The reference implementation in `@grafctory/wire-sparql-oxigraph` follows this pattern:
50
+ *
51
+ * ```typescript
52
+ * import { named, tagged, type Term, typed } from "@grafctory/trio";
53
+ * import { type Repository } from "@grafctory/wire-sparql";
54
+ *
55
+ * function decode(node: BackendNode): Term {
56
+ * return node.kind === "iri" ? named(node.iri)
57
+ * : node.kind === "language" ? tagged(node.text, node.language)
58
+ * : typed(node.text, node.datatype);
59
+ * }
60
+ *
61
+ * export function createMyRepository(): Repository {
62
+ * // ... satisfy ask/select/construct/update/execute/close against the backend
63
+ * }
64
+ * ```
65
+ *
66
+ * @see {@link https://www.w3.org/TR/sparql11-query/ SPARQL 1.1 Query Language}
67
+ * @see {@link https://www.w3.org/TR/sparql11-update/ SPARQL 1.1 Update}
68
+ * @see {@link https://www.w3.org/TR/rdf11-concepts/ RDF 1.1 Concepts and Abstract Syntax}
69
+ *
70
+ * @group Connectors
71
+ *
72
+ * @module index
73
+ */
74
+ import { assert } from "@grafctory/core";
75
+ import { createBatchingStore } from "@grafctory/keep/batching";
76
+ import { createManagingStore } from "@grafctory/keep/managing";
77
+ import { createValidatingStore } from "@grafctory/keep/validating";
78
+ import { log } from "@grafctory/tape";
79
+ import { createBufferingRepository, createLoggingRepository } from "@grafctory/wire-sparql";
80
+ import { detail } from "./detail/index.js";
81
+ import { detect } from "./detect/index.js";
82
+ import { modify } from "./modify/index.js";
83
+ import { select } from "./select/index.js";
84
+ const logger = log(import.meta.url);
85
+ /**
86
+ * The default {@link SPARQLStoreOptions.batch | batch} cap.
87
+ */
88
+ const Batch = 500;
89
+ /**
90
+ * The default {@link SPARQLStoreOptions.burst | burst} cap.
91
+ */
92
+ const Burst = 8;
93
+ /**
94
+ * Checks whether a value is an admissible cap: a non-negative integer.
95
+ */
96
+ function isCap(value) {
97
+ return Number.isInteger(value) && value >= 0;
98
+ }
99
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100
+ /**
101
+ * Creates a SPARQL store backed by a {@link Repository}.
102
+ *
103
+ * Every data call runs in its own {@link Repository.execute | repository transaction}, so concurrent calls share no
104
+ * transaction state. Inside {@link Store.execute | execute}, the task receives a {@link StoreClient} bound to a single
105
+ * repository transaction: its mutations are buffered and flushed to the repository as one update when the task
106
+ * completes, then committed with the transaction. Queries within the task do not observe the task's own pending
107
+ * mutations, so a read depending on a write must run in a separate `execute` call.
108
+ *
109
+ * > [!IMPORTANT]
110
+ * > **Transaction Isolation** — Determined by the supplied {@link Repository}: native transactions keep the reads of
111
+ * > an `execute` task consistent, while its mutations are always buffered and applied as a single update on commit.
112
+ *
113
+ * > [!IMPORTANT]
114
+ * > **Mutation Events** — Limited to mutations issued through this store; mutations from other clients on the
115
+ * > underlying repository are not observed.
116
+ *
117
+ * > [!IMPORTANT]
118
+ * > **Embedded Resources** — Named by IRIs in the repository, never by blank nodes. The store skolemises the
119
+ * > embedded resources it writes, and a graph loaded by other means must be skolemised before the store reads it. A
120
+ * > blank node found where an embedded resource is expected fails the whole retrieval with a
121
+ * > {@link !RangeError RangeError}, so no embedded resource and none of the content requested under it ever goes
122
+ * > silently missing from a retrieved result, whatever tool loaded the graph into the repository.
123
+ *
124
+ * @param repository - The repository for SPARQL query, update, and transaction execution
125
+ * @param options - The caps on how the store queries the repository
126
+ *
127
+ * @returns An immutable {@link Store}
128
+ *
129
+ * @throws {@link !TypeError TypeError} If a cap is not a non-negative integer
130
+ */
131
+ export function createSPARQLStore(repository, { batch = Batch, burst = Burst } = {}) {
132
+ const $batch = assert(batch, isCap, `illegal batch cap <${batch}>`);
133
+ const $burst = assert(burst, isCap, `illegal burst cap <${burst}>`);
134
+ const buffering = createBufferingRepository(createLoggingRepository(repository, message => logger.debug `${message}`));
135
+ return createManagingStore({
136
+ execute: task => buffering.execute(async (repository) => task(store(repository))),
137
+ close: () => buffering.close()
138
+ });
139
+ /**
140
+ * The limit a cap declares to the batching layer: none for a lifted cap.
141
+ */
142
+ function cap(value) {
143
+ return value > 0 ? value : undefined;
144
+ }
145
+ function store(client) {
146
+ return createValidatingStore(createBatchingStore({
147
+ detect: (batch, broker) => detect(batch, client, broker),
148
+ detail: (batch, broker) => detail(batch, client, broker),
149
+ select: (batch, broker) => select(batch, client, broker),
150
+ modify: (batch) => modify(batch, client)
151
+ }, {
152
+ limit: { detail: cap($batch), select: cap($batch), burst: cap($burst) }
153
+ }), {
154
+ trusted: true
155
+ });
156
+ }
157
+ }
158
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AAEH,OAAO,EAAE,MAAM,EAAE,MAA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1,17 @@
1
+ import type { Scope } from "@grafctory/core/scope";
2
+ import { type Flake } from "@grafctory/keep-flake";
3
+ import type { Deferred, Modify } from "@grafctory/keep/batching";
4
+ import { type SPARQL, type Variable } from "@grafctory/wire-sparql";
5
+ /**
6
+ * Encodes a single SPARQL update covering every request in the batch.
7
+ *
8
+ * @param scope The variable allocator shared across every request's cleanup walk, keyed on
9
+ * {@link Branch} identity
10
+ * @param batch The batched root entries paired with their {@link Flake | mutation plans}
11
+ *
12
+ * @returns The batched SPARQL update
13
+ */
14
+ export declare function encode(scope: Scope<Variable>, batch: readonly (Deferred<Modify> & {
15
+ readonly flake: Flake;
16
+ })[]): SPARQL;
17
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/modify/encode.ts"],"names":[],"mappings":"AA4CA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAe,KAAK,KAAK,EAAqC,MAAM,uBAAuB,CAAC;AACnG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAGjE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAgEpE;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,EACtB,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,EAAE,GAC9D,MAAM,CA2KR"}
@@ -0,0 +1,233 @@
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
+ * Modify-pass SPARQL update encoder.
18
+ *
19
+ * Folds a batch of {@link Modify} requests into one SPARQL 1.1 update applied in submission order:
20
+ *
21
+ * - a request carrying a `link` inserts the membership edge alone, leaving the entry's own state untouched;
22
+ * - a request carrying a `state` clears the entry's owned triples and inserts the supplied state;
23
+ * - a request with no `state` deletes the entry together with its embedded and captive descendants.
24
+ *
25
+ * The request's {@link Flake | plan} drives every structural decision. Forward and reverse predicates are both
26
+ * written, foreign properties are left untouched, and embedded resources are written recursively while references
27
+ * are written as links.
28
+ *
29
+ * Clearing and deleting walk the plan once each into the {@link Step | steps} reaching the edges they act on, and
30
+ * every clause of the operation is read off those steps, so the `delete` template of a clearing update and the
31
+ * `where` arms binding it can never drift apart. Clearing an entry scales with the number of triples it owns,
32
+ * embedded resources included, rather than with the product of the values of its multi-valued properties, so
33
+ * updating a richly described resource stays fast however many keywords, documents or reviews it carries.
34
+ *
35
+ * @see {@link https://www.w3.org/TR/sparql11-update/ SPARQL 1.1 Update}
36
+ *
37
+ * @module
38
+ */
39
+ import { getStateEntries } from "@grafctory/blue/resource";
40
+ import { getShapeBranches, getStateBranch } from "@grafctory/blue/union";
41
+ import { eager } from "@grafctory/blue/value";
42
+ import { isObject } from "@grafctory/core";
43
+ import { getFlakeVariant, isPropertyBranch } from "@grafctory/keep-flake";
44
+ import { named, rdf } from "@grafctory/trio";
45
+ import { data, deleet, fragment, group, insert as create, nil, pattern, reference, union, update, values, variable, where } from "@grafctory/wire-sparql/builder";
46
+ import { forward, reverse } from "../patterns.js";
47
+ import { valuesToTerms } from "../terms.js";
48
+ /**
49
+ * Encodes a single SPARQL update covering every request in the batch.
50
+ *
51
+ * @param scope The variable allocator shared across every request's cleanup walk, keyed on
52
+ * {@link Branch} identity
53
+ * @param batch The batched root entries paired with their {@link Flake | mutation plans}
54
+ *
55
+ * @returns The batched SPARQL update
56
+ */
57
+ export function encode(scope, batch) {
58
+ return update(...batch.map(({ request: { entry, state, link }, flake }) => link !== undefined ? attach(entry, link)
59
+ : state === undefined ? remove(entry, flake)
60
+ : insert(entry, flake, state)));
61
+ function attach(entry, { property, item }) {
62
+ // the membership edge alone, in both directions the property declares: the entry's own state is left as it is
63
+ return create(data(forward([named(entry), property, named(item)]), reverse([named(entry), property, named(item)])));
64
+ }
65
+ /**
66
+ * Clears the edges the entry owns and inserts the supplied state. The clearing `delete` template and its
67
+ * `where` arms come from the same steps: one arm per owned edge, each starting with the edges leading to it,
68
+ * so matched rows add up across edges instead of multiplying and the update stays linear in the triples. An
69
+ * arm matches the edge in whichever direction it is stored, so an edge a graph loaded by other means carries
70
+ * in one direction only is cleared too, and the template retracts both directions of what matched.
71
+ */
72
+ function insert(entry, flake, state) {
73
+ const owned = steps(scope, [], named(entry), flake, isOwn, isEmbedding);
74
+ return update(deleet(group(...owned.map(step => fragment(...edges(step)))), where(union(...owned.map(step => fragment(...step.path, either(step)))))), create(data(content(entry, flake, state))));
75
+ }
76
+ /**
77
+ * Deletes every triple incident on the entry and on the embedded and captive resources under it: one arm per
78
+ * cascading edge binds the cascaded resource to the wildcard subject, so the wildcard patterns match its
79
+ * triples as they match the entry's own. The arm reaches the cascaded resource through whichever direction of
80
+ * the edge is stored, so a resource linked in one direction only is deleted with its captor too.
81
+ */
82
+ function remove(entry, flake) {
83
+ const root = scope.resolve();
84
+ // wildcard patterns matching every triple incident on `?root` (outgoing then incoming),
85
+ // resolved once so the same variables bind in both the `delete` template and the `where` match
86
+ const wildcard = [
87
+ pattern([root, scope.resolve(), scope.resolve()]),
88
+ pattern([scope.resolve(), scope.resolve(), root])
89
+ ];
90
+ const cascaded = steps(scope, [], named(entry), flake, isCascading, () => true).flatMap(step => "branch" in step ? [fragment(...step.path, either({ ...step, object: root }))] : []);
91
+ return deleet(group(...wildcard), where(union(values([variable(root)], [[reference(entry)]]), ...cascaded), union(...wildcard)));
92
+ }
93
+ /**
94
+ * The stored edges a step reaches: the `rdf:type` triple of a resource, or the forward and reverse edges of a
95
+ * property, in the directions it declares, so a `delete` template built from them retracts both of them at once.
96
+ */
97
+ function edges(step) {
98
+ return "shape" in step
99
+ ? [classed(step)]
100
+ : [forward([step.subject, step.branch.entry, step.object]), reverse([step.subject, step.branch.entry, step.object])];
101
+ }
102
+ /**
103
+ * The pattern matching a step's edge in whichever direction it is stored: the `rdf:type` triple of a resource, or
104
+ * the stored directions of a property as alternatives, so a property declaring both matches a pair carrying either.
105
+ */
106
+ function either(step) {
107
+ return "shape" in step
108
+ ? classed(step)
109
+ : stored(step.subject, step.branch.entry, step.object);
110
+ }
111
+ /**
112
+ * The `rdf:type` triple a resource step reaches, its class bound to the variable keyed on the resource shape.
113
+ */
114
+ function classed({ subject, shape }) {
115
+ return pattern([subject, named(rdf.type), scope.resolve(shape)]);
116
+ }
117
+ /**
118
+ * The triples inserting a state under its entry: the class lineage and the facts of every entry the state
119
+ * carries, embedded resources recursively; nothing for a state satisfying no variant of the plan's shape.
120
+ */
121
+ function content(entry, flake, state) {
122
+ const shape = getStateBranch(state, getShapeBranches(flake.range.shape));
123
+ return shape === undefined || shape.kind !== "resource" ? nil() : record(named(entry), shape, state);
124
+ function record(entry, shape, state) {
125
+ // denormalise the class lineage as `rdf:type` triples (own `class` plus inherited `classes`),
126
+ // so an exact-match query on any supertype reaches the instance (class-lineage retrieval)
127
+ return fragment(shape.class !== undefined ? pattern([entry, named(rdf.type), named(shape.class)]) : nil(), ...(shape.classes ?? []).map(clazz => pattern([entry, named(rdf.type), named(clazz)])), ...getStateEntries(shape, state).flatMap(({ property, shape, value }) => facts(property, value, shape)));
128
+ function facts(property, values, shape) {
129
+ switch (shape.kind) {
130
+ case "boolean":
131
+ case "number":
132
+ case "string":
133
+ case "dictionary":
134
+ return valuesToTerms(values, shape).map(term => forward([entry, property, term]));
135
+ case "reference":
136
+ if (property.foreign === true) {
137
+ return [];
138
+ }
139
+ else {
140
+ return valuesToTerms(values, shape).filter(node => node.kind === "named").flatMap(node => [
141
+ forward([entry, property, node]),
142
+ reverse([entry, property, node])
143
+ ]);
144
+ }
145
+ case "resource":
146
+ if (!isObject(values)) {
147
+ return [];
148
+ }
149
+ else {
150
+ return valuesToTerms(values, shape).filter(node => node.kind === "named").flatMap(node => [
151
+ forward([entry, property, node]),
152
+ reverse([entry, property, node]),
153
+ record(node, shape, values)
154
+ ]);
155
+ }
156
+ case "union": // a range variant is always a flattened branch, never a union
157
+ throw new RangeError(`unsupported union variant`);
158
+ }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ /**
164
+ * Walks a plan into the steps reaching the edges it owns under `subject`: the stored type of each resource variant
165
+ * declaring one, then, for each property `admits`, its stored edge, followed by the steps under the resource it
166
+ * reaches where `descends` holds. Each step carries the edges leading to its subject, keyed on branch identity, so
167
+ * an arm built from it binds every variable on its own and the same edge takes the same variable in every clause.
168
+ */
169
+ function steps(scope, path, subject, flake, admits, descends) {
170
+ return getShapeBranches(flake.range.shape).flatMap(shape => shape.kind !== "resource" ? [] : [
171
+ ...(isTyped(shape) ? [{ path, subject, shape }] : []),
172
+ ...getFlakeVariant(flake, shape).flatMap((branch) => {
173
+ if (isPropertyBranch(branch) && admits(branch.entry)) {
174
+ const object = scope.resolve(branch);
175
+ const reach = stored(subject, branch.entry, object);
176
+ return reach === nil() ? [] : [
177
+ { path, subject, branch, object },
178
+ ...(descends(branch.entry) ? steps(scope, [...path, reach], object, branch, admits, descends) : [])
179
+ ];
180
+ }
181
+ else {
182
+ return [];
183
+ }
184
+ })
185
+ ]);
186
+ }
187
+ /**
188
+ * The pattern matching a property's edge in whichever direction it is stored: its declared directions as alternatives,
189
+ * so a pair stored in one direction only still matches; the empty fragment for a property declaring none.
190
+ */
191
+ function stored(subject, property, object) {
192
+ const directions = [forward([subject, property, object]), reverse([subject, property, object])]
193
+ .filter(direction => direction !== nil());
194
+ return directions.length === 0 ? nil()
195
+ : directions.length === 1 ? directions[0]
196
+ : union(...directions);
197
+ }
198
+ /**
199
+ * Checks whether a shape owns the `rdf:type` triples of the resources it describes.
200
+ *
201
+ * A `type` member activates only on a shape declaring its own target class, so a common supershape may factor the
202
+ * member without contributing a type: the class-less shapes inheriting it carry no type of their own and their
203
+ * stored `rdf:type` triples are left to whichever shape declared them, untouched by a clearing update under them.
204
+ */
205
+ function isTyped(shape) {
206
+ return shape.kind === "union" ? getShapeBranches(shape).some(isTyped)
207
+ : shape.kind === "resource" && shape.class !== undefined;
208
+ }
209
+ /**
210
+ * Checks whether a property's edges belong to the resource holding it, so a clearing update retracts them: every
211
+ * property but a foreign one, which reads edges another property owns and a clearing update must leave as they are.
212
+ */
213
+ function isOwn(property) {
214
+ return property.foreign !== true;
215
+ }
216
+ /**
217
+ * Checks whether a property embeds the resources it reaches, so a clearing update descends into their edges: a
218
+ * captive or plain reference keeps its own state, and only its link is retracted.
219
+ */
220
+ function isEmbedding(property) {
221
+ return getShapeBranches(property.range.shape).some(variant => variant.kind === "resource");
222
+ }
223
+ /**
224
+ * Checks whether the resources a property reaches are deleted together with the resource holding it: embedded
225
+ * resources, which have no lifecycle of their own, and captive references, cascade-deleted by contract.
226
+ */
227
+ function isCascading(property) {
228
+ return property.captive === true || embedded(eager(property.range.shape));
229
+ function embedded(shape) {
230
+ return shape.kind === "union" ? getShapeBranches(shape).some(embedded) : shape.kind === "resource";
231
+ }
232
+ }
233
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/modify/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAqC,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CA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S,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,SAAS,KAAK,CAAC,QAAkB;IAChC,OAAO,QAAQ,CAAC,OAAO,KAAK,IAAI,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,QAAkB;IACtC,OAAO,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AAC5F,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAAC,QAAkB;IAEtC,OAAO,QAAQ,CAAC,OAAO,KAAK,IAAI,IAAI,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAE1E,SAAS,QAAQ,CAAC,KAAY;QAC7B,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;IACpG,CAAC;AAEF,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { Deferred, Modify } from "@grafctory/keep/batching";
2
+ import type { RepositoryClient } from "@grafctory/wire-sparql";
3
+ /**
4
+ * Applies a batch of {@link Modify} requests against a repository as a single update.
5
+ *
6
+ * A request carrying a `link` asserts the membership edge from its entry to an item. A request carrying a `state`
7
+ * creates or replaces the entry, and a request with no `state` removes it. The backend applies the requests in
8
+ * submission order ({@link https://www.w3.org/TR/sparql11-update/#updateLanguage SPARQL 1.1 Update §3}) and, where
9
+ * supported, atomically.
10
+ *
11
+ * Every request is applied unconditionally: the batching layer has already rejected any request whose `state`
12
+ * carries an `id` other than its `entry` (§4.1). Each {@link Deferred} resolves to its entry once the update
13
+ * completes, and a backend failure rejects every request of the batch, since the one update carried them all.
14
+ *
15
+ * @param batch The modify requests to apply
16
+ * @param client The repository the mutations are applied against
17
+ *
18
+ * @returns A promise settling once the batched update has been applied
19
+ */
20
+ export declare function modify(batch: readonly Deferred<Modify>[], client: RepositoryClient): Promise<void>;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/modify/index.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK/D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,EAAE,EAClC,MAAM,EAAE,gBAAgB,GACtB,OAAO,CAAC,IAAI,CAAC,CAcf"}
@@ -0,0 +1,50 @@
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
+ * Modify-pass driver.
18
+ *
19
+ * Applies every queued {@link Modify} request in a batch as a single SPARQL update against the repository.
20
+ *
21
+ * @module index
22
+ */
23
+ import { createFlake } from "@grafctory/keep-flake";
24
+ import { write } from "../spine.js";
25
+ import { encode } from "./encode.js";
26
+ /**
27
+ * Applies a batch of {@link Modify} requests against a repository as a single update.
28
+ *
29
+ * A request carrying a `link` asserts the membership edge from its entry to an item. A request carrying a `state`
30
+ * creates or replaces the entry, and a request with no `state` removes it. The backend applies the requests in
31
+ * submission order ({@link https://www.w3.org/TR/sparql11-update/#updateLanguage SPARQL 1.1 Update §3}) and, where
32
+ * supported, atomically.
33
+ *
34
+ * Every request is applied unconditionally: the batching layer has already rejected any request whose `state`
35
+ * carries an `id` other than its `entry` (§4.1). Each {@link Deferred} resolves to its entry once the update
36
+ * completes, and a backend failure rejects every request of the batch, since the one update carried them all.
37
+ *
38
+ * @param batch The modify requests to apply
39
+ * @param client The repository the mutations are applied against
40
+ *
41
+ * @returns A promise settling once the batched update has been applied
42
+ */
43
+ export function modify(batch, client) {
44
+ const items = batch.map(item => ({ ...item, flake: createFlake(item.request.shape) }));
45
+ return write(batch, client, {
46
+ encode: scope => encode(scope, items),
47
+ decode: (_, { request: { entry } }) => entry
48
+ });
49
+ }
50
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/modify/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,MAAM,CACrB,KAAkC,EAClC,MAAwB;IAGxB,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAC9B,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CACrD,CAAC;IAEF,OAAO,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE;QAE3B,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC;QAErC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,KAAK;KAE5C,CAAC,CAAC;AAEJ,CAAC"}