@_linked/core 2.9.0 → 2.10.0-next.20260630061713
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/CHANGELOG.md +57 -0
- package/README.md +102 -59
- package/lib/cjs/expressions/ExpressionNode.d.ts +2 -1
- package/lib/cjs/expressions/ExpressionNode.js +4 -0
- package/lib/cjs/expressions/ExpressionNode.js.map +1 -1
- package/lib/cjs/index.d.ts +12 -1
- package/lib/cjs/index.js +26 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/IDataset.d.ts +5 -3
- package/lib/cjs/package.json +7 -1
- package/lib/cjs/queries/ContextRef.d.ts +21 -0
- package/lib/cjs/queries/ContextRef.js +58 -0
- package/lib/cjs/queries/ContextRef.js.map +1 -0
- package/lib/cjs/queries/CreateBuilder.d.ts +20 -4
- package/lib/cjs/queries/CreateBuilder.js +43 -11
- package/lib/cjs/queries/CreateBuilder.js.map +1 -1
- package/lib/cjs/queries/CreateQuery.d.ts +16 -13
- package/lib/cjs/queries/CreateQuery.js +0 -17
- package/lib/cjs/queries/CreateQuery.js.map +1 -1
- package/lib/cjs/queries/DeleteBuilder.d.ts +19 -4
- package/lib/cjs/queries/DeleteBuilder.js +82 -29
- package/lib/cjs/queries/DeleteBuilder.js.map +1 -1
- package/lib/cjs/queries/DeleteQuery.d.ts +16 -13
- package/lib/cjs/queries/DeleteQuery.js +0 -17
- package/lib/cjs/queries/DeleteQuery.js.map +1 -1
- package/lib/cjs/queries/IRLower.js +48 -3
- package/lib/cjs/queries/IRLower.js.map +1 -1
- package/lib/cjs/queries/IntermediateRepresentation.d.ts +12 -2
- package/lib/cjs/queries/MutationQuery.d.ts +9 -0
- package/lib/cjs/queries/MutationQuery.js +27 -0
- package/lib/cjs/queries/MutationQuery.js.map +1 -1
- package/lib/cjs/queries/MutationSerialization.d.ts +103 -0
- package/lib/cjs/queries/MutationSerialization.js +161 -0
- package/lib/cjs/queries/MutationSerialization.js.map +1 -0
- package/lib/cjs/queries/QueryBuilder.d.ts +44 -33
- package/lib/cjs/queries/QueryBuilder.js +55 -43
- package/lib/cjs/queries/QueryBuilder.js.map +1 -1
- package/lib/cjs/queries/QueryBuilderSerialization.js +16 -5
- package/lib/cjs/queries/QueryBuilderSerialization.js.map +1 -1
- package/lib/cjs/queries/QueryContext.d.ts +36 -0
- package/lib/cjs/queries/QueryContext.js +96 -12
- package/lib/cjs/queries/QueryContext.js.map +1 -1
- package/lib/cjs/queries/SelectQuery.d.ts +16 -7
- package/lib/cjs/queries/SelectQuery.js +22 -13
- package/lib/cjs/queries/SelectQuery.js.map +1 -1
- package/lib/cjs/queries/UpdateBuilder.d.ts +23 -5
- package/lib/cjs/queries/UpdateBuilder.js +102 -43
- package/lib/cjs/queries/UpdateBuilder.js.map +1 -1
- package/lib/cjs/queries/UpdateQuery.d.ts +14 -12
- package/lib/cjs/queries/UpdateQuery.js +0 -20
- package/lib/cjs/queries/UpdateQuery.js.map +1 -1
- package/lib/cjs/queries/fromJSON.d.ts +16 -0
- package/lib/cjs/queries/fromJSON.js +41 -0
- package/lib/cjs/queries/fromJSON.js.map +1 -0
- package/lib/cjs/queries/lower.d.ts +28 -0
- package/lib/cjs/queries/lower.js +115 -0
- package/lib/cjs/queries/lower.js.map +1 -0
- package/lib/cjs/queries/lowerMutationJSON.d.ts +12 -0
- package/lib/cjs/queries/lowerMutationJSON.js +135 -0
- package/lib/cjs/queries/lowerMutationJSON.js.map +1 -0
- package/lib/cjs/queries/mutationLowerSpec.d.ts +32 -0
- package/lib/cjs/queries/mutationLowerSpec.js +8 -0
- package/lib/cjs/queries/mutationLowerSpec.js.map +1 -0
- package/lib/cjs/queries/wireVersion.d.ts +7 -0
- package/lib/cjs/queries/wireVersion.js +25 -0
- package/lib/cjs/queries/wireVersion.js.map +1 -0
- package/lib/cjs/shapes/Shape.d.ts +4 -3
- package/lib/cjs/shapes/Shape.js.map +1 -1
- package/lib/cjs/sparql/SparqlDataset.js +22 -17
- package/lib/cjs/sparql/SparqlDataset.js.map +1 -1
- package/lib/cjs/sparql/irToAlgebra.js +20 -5
- package/lib/cjs/sparql/irToAlgebra.js.map +1 -1
- package/lib/cjs/test-helpers/query-capture-store.js +8 -4
- package/lib/cjs/test-helpers/query-capture-store.js.map +1 -1
- package/lib/cjs/utils/LinkedStorage.d.ts +1 -1
- package/lib/cjs/utils/LinkedStorage.js +20 -7
- package/lib/cjs/utils/LinkedStorage.js.map +1 -1
- package/lib/esm/expressions/ExpressionNode.d.ts +2 -1
- package/lib/esm/expressions/ExpressionNode.js +4 -0
- package/lib/esm/expressions/ExpressionNode.js.map +1 -1
- package/lib/esm/index.d.ts +12 -1
- package/lib/esm/index.js +10 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/IDataset.d.ts +5 -3
- package/lib/esm/package.json +7 -1
- package/lib/esm/queries/ContextRef.d.ts +21 -0
- package/lib/esm/queries/ContextRef.js +52 -0
- package/lib/esm/queries/ContextRef.js.map +1 -0
- package/lib/esm/queries/CreateBuilder.d.ts +20 -4
- package/lib/esm/queries/CreateBuilder.js +43 -11
- package/lib/esm/queries/CreateBuilder.js.map +1 -1
- package/lib/esm/queries/CreateQuery.d.ts +16 -13
- package/lib/esm/queries/CreateQuery.js +1 -15
- package/lib/esm/queries/CreateQuery.js.map +1 -1
- package/lib/esm/queries/DeleteBuilder.d.ts +19 -4
- package/lib/esm/queries/DeleteBuilder.js +82 -29
- package/lib/esm/queries/DeleteBuilder.js.map +1 -1
- package/lib/esm/queries/DeleteQuery.d.ts +16 -13
- package/lib/esm/queries/DeleteQuery.js +1 -15
- package/lib/esm/queries/DeleteQuery.js.map +1 -1
- package/lib/esm/queries/IRLower.js +48 -3
- package/lib/esm/queries/IRLower.js.map +1 -1
- package/lib/esm/queries/IntermediateRepresentation.d.ts +12 -2
- package/lib/esm/queries/MutationQuery.d.ts +9 -0
- package/lib/esm/queries/MutationQuery.js +27 -0
- package/lib/esm/queries/MutationQuery.js.map +1 -1
- package/lib/esm/queries/MutationSerialization.d.ts +103 -0
- package/lib/esm/queries/MutationSerialization.js +155 -0
- package/lib/esm/queries/MutationSerialization.js.map +1 -0
- package/lib/esm/queries/QueryBuilder.d.ts +44 -33
- package/lib/esm/queries/QueryBuilder.js +55 -42
- package/lib/esm/queries/QueryBuilder.js.map +1 -1
- package/lib/esm/queries/QueryBuilderSerialization.js +16 -5
- package/lib/esm/queries/QueryBuilderSerialization.js.map +1 -1
- package/lib/esm/queries/QueryContext.d.ts +36 -0
- package/lib/esm/queries/QueryContext.js +92 -11
- package/lib/esm/queries/QueryContext.js.map +1 -1
- package/lib/esm/queries/SelectQuery.d.ts +16 -7
- package/lib/esm/queries/SelectQuery.js +22 -13
- package/lib/esm/queries/SelectQuery.js.map +1 -1
- package/lib/esm/queries/UpdateBuilder.d.ts +23 -5
- package/lib/esm/queries/UpdateBuilder.js +102 -43
- package/lib/esm/queries/UpdateBuilder.js.map +1 -1
- package/lib/esm/queries/UpdateQuery.d.ts +14 -12
- package/lib/esm/queries/UpdateQuery.js +1 -18
- package/lib/esm/queries/UpdateQuery.js.map +1 -1
- package/lib/esm/queries/fromJSON.d.ts +16 -0
- package/lib/esm/queries/fromJSON.js +38 -0
- package/lib/esm/queries/fromJSON.js.map +1 -0
- package/lib/esm/queries/lower.d.ts +28 -0
- package/lib/esm/queries/lower.js +112 -0
- package/lib/esm/queries/lower.js.map +1 -0
- package/lib/esm/queries/lowerMutationJSON.d.ts +12 -0
- package/lib/esm/queries/lowerMutationJSON.js +131 -0
- package/lib/esm/queries/lowerMutationJSON.js.map +1 -0
- package/lib/esm/queries/mutationLowerSpec.d.ts +32 -0
- package/lib/esm/queries/mutationLowerSpec.js +7 -0
- package/lib/esm/queries/mutationLowerSpec.js.map +1 -0
- package/lib/esm/queries/wireVersion.d.ts +7 -0
- package/lib/esm/queries/wireVersion.js +21 -0
- package/lib/esm/queries/wireVersion.js.map +1 -0
- package/lib/esm/shapes/Shape.d.ts +4 -3
- package/lib/esm/shapes/Shape.js.map +1 -1
- package/lib/esm/sparql/SparqlDataset.js +22 -17
- package/lib/esm/sparql/SparqlDataset.js.map +1 -1
- package/lib/esm/sparql/irToAlgebra.js +20 -5
- package/lib/esm/sparql/irToAlgebra.js.map +1 -1
- package/lib/esm/test-helpers/query-capture-store.js +8 -4
- package/lib/esm/test-helpers/query-capture-store.js.map +1 -1
- package/lib/esm/utils/LinkedStorage.d.ts +1 -1
- package/lib/esm/utils/LinkedStorage.js +20 -7
- package/lib/esm/utils/LinkedStorage.js.map +1 -1
- package/package.json +7 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { resolveShape } from './resolveShape.js';
|
|
2
|
-
import {
|
|
2
|
+
import { MutationQueryFactory } from './MutationQuery.js';
|
|
3
3
|
import { getQueryDispatch } from './queryDispatch.js';
|
|
4
|
+
import { WIRE_VERSION, assertWireVersion } from './wireVersion.js';
|
|
5
|
+
import { PendingQueryContext, getQueryContext, UnresolvedContextError } from './QueryContext.js';
|
|
6
|
+
import { encodeContextRef, isContextRefJSON } from './ContextRef.js';
|
|
4
7
|
import { processWhereClause } from './SelectQuery.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { canonicalizeWhere } from './IRCanonicalize.js';
|
|
8
|
-
import { lowerWhereToIR } from './IRLower.js';
|
|
8
|
+
import { encodeNodeData, decodeNodeDataToRaw } from './MutationSerialization.js';
|
|
9
|
+
import { serializeWherePath, deserializeWherePath } from './QueryBuilderSerialization.js';
|
|
9
10
|
/**
|
|
10
11
|
* An immutable, fluent builder for update mutations.
|
|
11
12
|
*
|
|
@@ -21,14 +22,21 @@ import { lowerWhereToIR } from './IRLower.js';
|
|
|
21
22
|
*/
|
|
22
23
|
export class UpdateBuilder {
|
|
23
24
|
constructor(init) {
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Build & execute
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
/** Discriminator for the free `lower()` function and dataset routing. */
|
|
29
|
+
this.__queryKind = 'update';
|
|
24
30
|
this._shape = init.shape;
|
|
25
31
|
this._data = init.data;
|
|
26
32
|
this._targetId = init.targetId;
|
|
27
33
|
this._mode = init.mode;
|
|
28
34
|
this._whereFn = init.whereFn;
|
|
35
|
+
this._where = init.where;
|
|
36
|
+
this._targetContextName = init.targetContextName;
|
|
29
37
|
}
|
|
30
38
|
clone(overrides = {}) {
|
|
31
|
-
return new UpdateBuilder(Object.assign({ shape: this._shape, data: this._data, targetId: this._targetId, mode: this._mode, whereFn: this._whereFn }, overrides));
|
|
39
|
+
return new UpdateBuilder(Object.assign({ shape: this._shape, data: this._data, targetId: this._targetId, mode: this._mode, whereFn: this._whereFn, where: this._where, targetContextName: this._targetContextName }, overrides));
|
|
32
40
|
}
|
|
33
41
|
// ---------------------------------------------------------------------------
|
|
34
42
|
// Static constructors
|
|
@@ -37,13 +45,33 @@ export class UpdateBuilder {
|
|
|
37
45
|
const resolved = resolveShape(shape);
|
|
38
46
|
return new UpdateBuilder({ shape: resolved });
|
|
39
47
|
}
|
|
48
|
+
/** Reconstruct an UpdateBuilder from its DSL-JSON (inverse of `toJSON`). */
|
|
49
|
+
static fromJSON(json) {
|
|
50
|
+
assertWireVersion(json.v);
|
|
51
|
+
const resolved = resolveShape(json.shape);
|
|
52
|
+
const data = decodeNodeDataToRaw(json.data);
|
|
53
|
+
if (json.mode === 'for') {
|
|
54
|
+
if (isContextRefJSON(json.targetId)) {
|
|
55
|
+
return new UpdateBuilder({ shape: resolved, data, targetContextName: json.targetId.$ctx, mode: 'for' });
|
|
56
|
+
}
|
|
57
|
+
return new UpdateBuilder({ shape: resolved, data, targetId: json.targetId, mode: 'for' });
|
|
58
|
+
}
|
|
59
|
+
if (json.mode === 'forAll') {
|
|
60
|
+
return new UpdateBuilder({ shape: resolved, data, mode: 'forAll' });
|
|
61
|
+
}
|
|
62
|
+
const where = deserializeWherePath(resolved.shape, json.where);
|
|
63
|
+
return new UpdateBuilder({ shape: resolved, data, mode: 'where', where });
|
|
64
|
+
}
|
|
40
65
|
// ---------------------------------------------------------------------------
|
|
41
66
|
// Fluent API
|
|
42
67
|
// ---------------------------------------------------------------------------
|
|
43
68
|
/** Target a specific entity by ID. */
|
|
44
69
|
for(id) {
|
|
70
|
+
if (id instanceof PendingQueryContext) {
|
|
71
|
+
return this.clone({ targetContextName: id.contextName, targetId: undefined, mode: 'for' });
|
|
72
|
+
}
|
|
45
73
|
const resolvedId = typeof id === 'string' ? id : id.id;
|
|
46
|
-
return this.clone({ targetId: resolvedId, mode: 'for' });
|
|
74
|
+
return this.clone({ targetId: resolvedId, targetContextName: undefined, mode: 'for' });
|
|
47
75
|
}
|
|
48
76
|
/** Update all instances of this shape type. Returns void. */
|
|
49
77
|
forAll() {
|
|
@@ -56,59 +84,90 @@ export class UpdateBuilder {
|
|
|
56
84
|
set(data) {
|
|
57
85
|
return this.clone({ data });
|
|
58
86
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
87
|
+
/** The shape this query targets — the routing key datasets/`LinkedStorage` use. */
|
|
88
|
+
get shape() {
|
|
89
|
+
return this._shape.shape;
|
|
90
|
+
}
|
|
91
|
+
/** @internal The IR-free lowering spec consumed by `lower()`. Validates inputs. */
|
|
92
|
+
_lowerSpec() {
|
|
93
|
+
var _a;
|
|
64
94
|
if (!this._data) {
|
|
65
|
-
throw new Error('UpdateBuilder requires .set(data) before .
|
|
95
|
+
throw new Error('UpdateBuilder requires .set(data) before it can be lowered. Specify what to update.');
|
|
66
96
|
}
|
|
67
97
|
const mode = this._mode || (this._targetId ? 'for' : undefined);
|
|
68
98
|
if (mode === 'forAll') {
|
|
69
|
-
return this.
|
|
99
|
+
return { shapeClass: this._shape, data: this._data, mode: 'forAll' };
|
|
70
100
|
}
|
|
71
101
|
if (mode === 'where') {
|
|
72
|
-
if (!this._whereFn) {
|
|
102
|
+
if (!this._whereFn && !this._where) {
|
|
73
103
|
throw new Error('UpdateBuilder.where() requires a condition callback.');
|
|
74
104
|
}
|
|
75
|
-
|
|
105
|
+
const wherePath = (_a = this._where) !== null && _a !== void 0 ? _a : processWhereClause(this._whereFn, this._shape);
|
|
106
|
+
return { shapeClass: this._shape, data: this._data, mode: 'where', wherePath };
|
|
76
107
|
}
|
|
77
|
-
// Default: ID-based update
|
|
78
|
-
|
|
79
|
-
|
|
108
|
+
// Default: ID-based update (target id may come from a query context)
|
|
109
|
+
const targetId = this._resolveTargetId();
|
|
110
|
+
if (!targetId) {
|
|
111
|
+
if (this._targetContextName) {
|
|
112
|
+
throw new UnresolvedContextError(this._targetContextName);
|
|
113
|
+
}
|
|
114
|
+
throw new Error('UpdateBuilder requires .for(id), .forAll(), or .where() before it can be lowered.');
|
|
80
115
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
116
|
+
return { shapeClass: this._shape, data: this._data, mode: 'for', targetId };
|
|
117
|
+
}
|
|
118
|
+
/** Resolve the target id from an explicit id or a query-context reference. */
|
|
119
|
+
_resolveTargetId() {
|
|
120
|
+
var _a;
|
|
121
|
+
if (this._targetId)
|
|
122
|
+
return this._targetId;
|
|
123
|
+
if (this._targetContextName)
|
|
124
|
+
return (_a = getQueryContext(this._targetContextName)) === null || _a === void 0 ? void 0 : _a.id;
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Serialize this update mutation to lightweight DSL-JSON. Normalizes the update
|
|
129
|
+
* data through the IR-free factory base (handles the expression-callback form
|
|
130
|
+
* of `.set()`), and serializes the where clause for `where`-mode updates.
|
|
131
|
+
*/
|
|
132
|
+
toJSON() {
|
|
133
|
+
var _a;
|
|
134
|
+
if (!this._data) {
|
|
135
|
+
throw new Error('UpdateBuilder requires .set(data) before .toJSON().');
|
|
136
|
+
}
|
|
137
|
+
const mode = this._mode || (this._targetId ? 'for' : undefined);
|
|
138
|
+
if (!mode) {
|
|
139
|
+
throw new Error('UpdateBuilder requires .for(id), .forAll(), or .where() before .toJSON().');
|
|
140
|
+
}
|
|
141
|
+
const fields = new MutationQueryFactory().describe(this._shape.shape, this._data);
|
|
142
|
+
const json = {
|
|
143
|
+
v: WIRE_VERSION,
|
|
144
|
+
op: 'update',
|
|
145
|
+
shape: this._shape.shape.id,
|
|
146
|
+
mode,
|
|
147
|
+
data: encodeNodeData(fields),
|
|
148
|
+
};
|
|
149
|
+
if (mode === 'for') {
|
|
150
|
+
if (this._targetContextName)
|
|
151
|
+
json.targetId = encodeContextRef(this._targetContextName);
|
|
152
|
+
else
|
|
153
|
+
json.targetId = this._targetId;
|
|
154
|
+
}
|
|
155
|
+
if (mode === 'where') {
|
|
156
|
+
const wherePath = (_a = this._where) !== null && _a !== void 0 ? _a : (this._whereFn ? processWhereClause(this._whereFn, this._shape) : undefined);
|
|
157
|
+
if (!wherePath) {
|
|
158
|
+
throw new Error('UpdateBuilder.where() requires a condition callback.');
|
|
159
|
+
}
|
|
160
|
+
json.where = serializeWherePath(wherePath);
|
|
97
161
|
}
|
|
98
|
-
return
|
|
99
|
-
shape: this._shape.shape,
|
|
100
|
-
updates: description,
|
|
101
|
-
where,
|
|
102
|
-
wherePatterns,
|
|
103
|
-
});
|
|
162
|
+
return json;
|
|
104
163
|
}
|
|
105
164
|
/** Execute the mutation. */
|
|
106
165
|
exec() {
|
|
107
166
|
const mode = this._mode || (this._targetId ? 'for' : undefined);
|
|
108
167
|
if (mode === 'forAll' || mode === 'where') {
|
|
109
|
-
return getQueryDispatch().updateQuery(this
|
|
168
|
+
return getQueryDispatch().updateQuery(this).then(() => undefined);
|
|
110
169
|
}
|
|
111
|
-
return getQueryDispatch().updateQuery(this
|
|
170
|
+
return getQueryDispatch().updateQuery(this);
|
|
112
171
|
}
|
|
113
172
|
// ---------------------------------------------------------------------------
|
|
114
173
|
// Promise interface
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateBuilder.js","sourceRoot":"","sources":["../../../src/queries/UpdateBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"UpdateBuilder.js","sourceRoot":"","sources":["../../../src/queries/UpdateBuilder.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAE,sBAAsB,EAAC,MAAM,mBAAmB,CAAC;AAC/F,OAAO,EAAC,gBAAgB,EAAE,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAmC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AAEtF,OAAO,EAAC,cAAc,EAAE,mBAAmB,EAA0B,MAAM,4BAA4B,CAAC;AACxG,OAAO,EAAC,kBAAkB,EAAE,oBAAoB,EAAC,MAAM,gCAAgC,CAAC;AAoBxF;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,aAAa;IAWxB,YAAoB,IAA0B;QAgF9C,8EAA8E;QAC9E,kBAAkB;QAClB,8EAA8E;QAE9E,yEAAyE;QAChE,gBAAW,GAAG,QAAiB,CAAC;QApFvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,IAAI,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O,gBAAgB,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAe,CAAC;QAClF,CAAC;QACD,OAAO,gBAAgB,EAAE,CAAC,WAAW,CAAC,IAAI,CAAe,CAAC;IAC5D,CAAC;IAED,8EAA8E;IAC9E,oBAAoB;IACpB,8EAA8E;IAE9E,IAAI,CACF,WAAqE,EACrE,UAAuE;QAEvE,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CACH,UAAqE;QAErE,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,CAAC,SAA+B;QACrC,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,eAAe,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { Shape, type ShapeConstructor } from '../shapes/Shape.js';
|
|
2
|
-
import { type NodeDescriptionValue, NodeReferenceValue, type UpdatePartial } from './QueryFactory.js';
|
|
3
|
-
import { MutationQueryFactory } from './MutationQuery.js';
|
|
4
1
|
import type { IRUpdateMutation, IRUpdateWhereMutation } from './IntermediateRepresentation.js';
|
|
2
|
+
import type { NodeShape } from '../shapes/SHACL.js';
|
|
3
|
+
import type { UpdateMutationJSON } from './MutationSerialization.js';
|
|
4
|
+
import type { UpdateLowerSpec } from './mutationLowerSpec.js';
|
|
5
5
|
/**
|
|
6
|
-
* The
|
|
7
|
-
*
|
|
6
|
+
* The closed, read-only update query a dataset receives (implemented by
|
|
7
|
+
* `UpdateBuilder`). The IR is `IRUpdateQuery`, produced by `lower(query)` — the
|
|
8
|
+
* IR construction lives in the IR tier, not here, so this module stays IR-free.
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
build(): UpdateQuery;
|
|
10
|
+
export interface UpdateQuery {
|
|
11
|
+
readonly __queryKind: 'update';
|
|
12
|
+
readonly shape: NodeShape;
|
|
13
|
+
toJSON(): UpdateMutationJSON;
|
|
14
|
+
/** @internal IR-free lowering spec consumed by `lower()`. */
|
|
15
|
+
_lowerSpec(): UpdateLowerSpec;
|
|
16
16
|
}
|
|
17
|
+
/** The lowered IR for an update mutation (what `lower()` produces). */
|
|
18
|
+
export type IRUpdateQuery = IRUpdateMutation | IRUpdateWhereMutation;
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { MutationQueryFactory } from './MutationQuery.js';
|
|
3
|
-
import { buildCanonicalUpdateMutationIR } from './IRMutation.js';
|
|
4
|
-
export class UpdateQueryFactory extends MutationQueryFactory {
|
|
5
|
-
constructor(shapeClass, id, updateObjectOrFn) {
|
|
6
|
-
super();
|
|
7
|
-
this.shapeClass = shapeClass;
|
|
8
|
-
this.id = toNodeReference(id).id;
|
|
9
|
-
this.fields = this.convertUpdateObject(updateObjectOrFn, this.shapeClass.shape);
|
|
10
|
-
}
|
|
11
|
-
build() {
|
|
12
|
-
return buildCanonicalUpdateMutationIR({
|
|
13
|
-
id: this.id,
|
|
14
|
-
shape: this.shapeClass.shape,
|
|
15
|
-
updates: this.fields,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
export {};
|
|
19
2
|
//# sourceMappingURL=UpdateQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateQuery.js","sourceRoot":"","sources":["../../../src/queries/UpdateQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"UpdateQuery.js","sourceRoot":"","sources":["../../../src/queries/UpdateQuery.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kind-detecting `fromJSON` — rehydrate any query DSL-JSON back into its builder.
|
|
3
|
+
*
|
|
4
|
+
* Mutation envelopes carry an `op` discriminator; select envelopes
|
|
5
|
+
* (`QueryBuilderJSON`) do not. This is the inbound boundary helper: a receiving
|
|
6
|
+
* process turns wire JSON into a live query with `fromJSON(json).exec()` (the
|
|
7
|
+
* existing generic dispatch), no per-op routing needed.
|
|
8
|
+
*/
|
|
9
|
+
import { SelectBuilder, type QueryBuilderJSON } from './QueryBuilder.js';
|
|
10
|
+
import { CreateBuilder } from './CreateBuilder.js';
|
|
11
|
+
import { UpdateBuilder } from './UpdateBuilder.js';
|
|
12
|
+
import { DeleteBuilder } from './DeleteBuilder.js';
|
|
13
|
+
import type { MutationJSON } from './MutationSerialization.js';
|
|
14
|
+
/** Any query in its wire (DSL-JSON) form. */
|
|
15
|
+
export type QueryJSON = QueryBuilderJSON | MutationJSON;
|
|
16
|
+
export declare function fromJSON(json: QueryJSON): SelectBuilder | CreateBuilder | UpdateBuilder | DeleteBuilder;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Kind-detecting `fromJSON` — rehydrate any query DSL-JSON back into its builder.
|
|
8
|
+
*
|
|
9
|
+
* Mutation envelopes carry an `op` discriminator; select envelopes
|
|
10
|
+
* (`QueryBuilderJSON`) do not. This is the inbound boundary helper: a receiving
|
|
11
|
+
* process turns wire JSON into a live query with `fromJSON(json).exec()` (the
|
|
12
|
+
* existing generic dispatch), no per-op routing needed.
|
|
13
|
+
*/
|
|
14
|
+
import { SelectBuilder } from './QueryBuilder.js';
|
|
15
|
+
import { CreateBuilder } from './CreateBuilder.js';
|
|
16
|
+
import { UpdateBuilder } from './UpdateBuilder.js';
|
|
17
|
+
import { DeleteBuilder } from './DeleteBuilder.js';
|
|
18
|
+
import { assertWireVersion } from './wireVersion.js';
|
|
19
|
+
export function fromJSON(json) {
|
|
20
|
+
assertWireVersion(json === null || json === void 0 ? void 0 : json.v);
|
|
21
|
+
if (json && typeof json === 'object' && 'op' in json) {
|
|
22
|
+
switch (json.op) {
|
|
23
|
+
case 'create':
|
|
24
|
+
return CreateBuilder.fromJSON(json);
|
|
25
|
+
case 'update':
|
|
26
|
+
return UpdateBuilder.fromJSON(json);
|
|
27
|
+
case 'delete':
|
|
28
|
+
return DeleteBuilder.fromJSON(json);
|
|
29
|
+
default:
|
|
30
|
+
// An `op` is present but not one we know — a malformed/corrupted or
|
|
31
|
+
// future-versioned mutation envelope. Fail loud rather than silently
|
|
32
|
+
// reinterpreting it as a select query.
|
|
33
|
+
throw new Error(`Unknown query op "${String(json.op)}" in DSL-JSON envelope.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return SelectBuilder.fromJSON(json);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=fromJSON.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fromJSON.js","sourceRoot":"","sources":["../../../src/queries/fromJSON.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,OAAO,EAAC,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AAKnD,MAAM,UAAU,QAAQ,CACtB,IAAe;IAEf,iBAAiB,CAAE,IAAsB,aAAtB,IAAI,uBAAJ,IAAI,CAAoB,CAAC,CAAC,CAAC;IAC9C,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACrD,QAAQ,IAAI,CAAC,EAAE,EAAE,CAAC;YAChB,KAAK,QAAQ;gBACX,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtC,KAAK,QAAQ;gBACX,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtC,KAAK,QAAQ;gBACX,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACtC;gBACE,oEAAoE;gBACpE,qEAAqE;gBACrE,uCAAuC;gBACvC,MAAM,IAAI,KAAK,CACb,qBAAqB,MAAM,CAAE,IAAsB,CAAC,EAAE,CAAC,yBAAyB,CACjF,CAAC;QACN,CAAC;IACH,CAAC;IACD,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAwB,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IRSelectQuery } from './IntermediateRepresentation.js';
|
|
2
|
+
import type { IRCreateQuery } from './CreateQuery.js';
|
|
3
|
+
import type { IRUpdateQuery } from './UpdateQuery.js';
|
|
4
|
+
import type { IRDeleteQuery } from './DeleteQuery.js';
|
|
5
|
+
import type { CreateLowerSpec, UpdateLowerSpec, DeleteLowerSpec } from './mutationLowerSpec.js';
|
|
6
|
+
/** A select query that can be lowered (the select builder). */
|
|
7
|
+
export type LowerableSelect = {
|
|
8
|
+
readonly __queryKind: 'select';
|
|
9
|
+
toRawInput(): any;
|
|
10
|
+
};
|
|
11
|
+
/** A mutation query that can be lowered (the mutation builders). */
|
|
12
|
+
export type LowerableCreate = {
|
|
13
|
+
readonly __queryKind: 'create';
|
|
14
|
+
_lowerSpec(): CreateLowerSpec;
|
|
15
|
+
};
|
|
16
|
+
export type LowerableUpdate = {
|
|
17
|
+
readonly __queryKind: 'update';
|
|
18
|
+
_lowerSpec(): UpdateLowerSpec;
|
|
19
|
+
};
|
|
20
|
+
export type LowerableDelete = {
|
|
21
|
+
readonly __queryKind: 'delete';
|
|
22
|
+
_lowerSpec(): DeleteLowerSpec;
|
|
23
|
+
};
|
|
24
|
+
export type LowerableQuery = LowerableSelect | LowerableCreate | LowerableUpdate | LowerableDelete;
|
|
25
|
+
export declare function lower(query: LowerableSelect): IRSelectQuery;
|
|
26
|
+
export declare function lower(query: LowerableCreate): IRCreateQuery;
|
|
27
|
+
export declare function lower(query: LowerableUpdate): IRUpdateQuery;
|
|
28
|
+
export declare function lower(query: LowerableDelete): IRDeleteQuery;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* `lower(query)` — turn a live query (builder) into its canonical IR algebra.
|
|
8
|
+
*
|
|
9
|
+
* This is the single, **free** lowering entry point, and the *only* place the
|
|
10
|
+
* canonical-IR pipeline (`IRPipeline` / `IRMutation` / `IRLower` / …) is reached
|
|
11
|
+
* from. The builders are deliberately IR-free: they hand `lower()` a plain
|
|
12
|
+
* "lowering spec" (`mutationLowerSpec`) or raw select input, and all IR
|
|
13
|
+
* construction happens here. A client that authors/serializes/forwards queries
|
|
14
|
+
* but never calls `lower()` therefore tree-shakes the entire IR pipeline away.
|
|
15
|
+
* The IR is an implementation detail of stores that want it (e.g. SPARQL) — not
|
|
16
|
+
* the contract.
|
|
17
|
+
*/
|
|
18
|
+
import { buildSelectQuery } from './IRPipeline.js';
|
|
19
|
+
import { MutationQueryFactory } from './MutationQuery.js';
|
|
20
|
+
import { isSetModificationValue } from './QueryFactory.js';
|
|
21
|
+
import { PendingQueryContext } from './QueryContext.js';
|
|
22
|
+
import { resolveContextId } from './ContextRef.js';
|
|
23
|
+
import { buildCanonicalCreateMutationIR, buildCanonicalUpdateMutationIR, buildCanonicalUpdateWhereMutationIR, buildCanonicalDeleteMutationIR, buildCanonicalDeleteAllMutationIR, buildCanonicalDeleteWhereMutationIR, } from './IRMutation.js';
|
|
24
|
+
import { toWhere } from './IRDesugar.js';
|
|
25
|
+
import { canonicalizeWhere } from './IRCanonicalize.js';
|
|
26
|
+
import { lowerWhereToIR } from './IRLower.js';
|
|
27
|
+
/** Lower a pre-evaluated where path to its canonical IR fragment. */
|
|
28
|
+
function lowerWherePath(where) {
|
|
29
|
+
return lowerWhereToIR(canonicalizeWhere(toWhere(where)));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolve any query-context reference carried as a mutation field value. The
|
|
33
|
+
* builder preserves a live `PendingQueryContext` through normalization (so it can
|
|
34
|
+
* serialize as `{$ctx}`); at lowering a mutation must hit a concrete node, so the
|
|
35
|
+
* context is resolved here and an unset one throws `UnresolvedContextError`.
|
|
36
|
+
*/
|
|
37
|
+
function resolveValueContexts(val) {
|
|
38
|
+
if (val instanceof PendingQueryContext) {
|
|
39
|
+
return { id: resolveContextId(val.contextName, true) };
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(val)) {
|
|
42
|
+
return val.map(resolveValueContexts);
|
|
43
|
+
}
|
|
44
|
+
if (val && typeof val === 'object') {
|
|
45
|
+
if (isSetModificationValue(val)) {
|
|
46
|
+
const mod = val;
|
|
47
|
+
const out = {};
|
|
48
|
+
if (mod.$add)
|
|
49
|
+
out.$add = mod.$add.map(resolveValueContexts);
|
|
50
|
+
if (mod.$remove)
|
|
51
|
+
out.$remove = mod.$remove.map(resolveValueContexts);
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
if ('fields' in val) {
|
|
55
|
+
return resolveDescriptionContexts(val);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return val;
|
|
59
|
+
}
|
|
60
|
+
/** Deep-resolve context references in a normalized node description (returns a new copy). */
|
|
61
|
+
function resolveDescriptionContexts(desc) {
|
|
62
|
+
return Object.assign(Object.assign({}, desc), { fields: desc.fields.map((f) => (Object.assign(Object.assign({}, f), { val: resolveValueContexts(f.val) }))) });
|
|
63
|
+
}
|
|
64
|
+
function lowerCreate(spec) {
|
|
65
|
+
const description = resolveDescriptionContexts(new MutationQueryFactory().describe(spec.shapeClass.shape, spec.data, true));
|
|
66
|
+
return buildCanonicalCreateMutationIR({ shape: spec.shapeClass.shape, description });
|
|
67
|
+
}
|
|
68
|
+
function lowerUpdate(spec) {
|
|
69
|
+
const shape = spec.shapeClass.shape;
|
|
70
|
+
const updates = resolveDescriptionContexts(new MutationQueryFactory().describe(shape, spec.data));
|
|
71
|
+
if (spec.mode === 'for') {
|
|
72
|
+
return buildCanonicalUpdateMutationIR({ id: spec.targetId, shape, updates });
|
|
73
|
+
}
|
|
74
|
+
// forAll / where
|
|
75
|
+
const lowered = spec.wherePath ? lowerWherePath(spec.wherePath) : undefined;
|
|
76
|
+
return buildCanonicalUpdateWhereMutationIR({
|
|
77
|
+
shape,
|
|
78
|
+
updates,
|
|
79
|
+
where: lowered === null || lowered === void 0 ? void 0 : lowered.where,
|
|
80
|
+
wherePatterns: lowered === null || lowered === void 0 ? void 0 : lowered.wherePatterns,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function lowerDelete(spec) {
|
|
84
|
+
const shape = spec.shapeClass.shape;
|
|
85
|
+
if (spec.mode === 'all') {
|
|
86
|
+
return buildCanonicalDeleteAllMutationIR({ shape });
|
|
87
|
+
}
|
|
88
|
+
if (spec.mode === 'where') {
|
|
89
|
+
const { where, wherePatterns } = lowerWherePath(spec.wherePath);
|
|
90
|
+
return buildCanonicalDeleteWhereMutationIR({ shape, where, wherePatterns });
|
|
91
|
+
}
|
|
92
|
+
// Resolve any context-ref ids ({$ctx}) against the live map — a delete must hit
|
|
93
|
+
// a concrete node, so an unresolved one throws (never a silent `{id: undefined}`).
|
|
94
|
+
const resolvedIds = spec.ids.map((id) => id instanceof PendingQueryContext
|
|
95
|
+
? { id: resolveContextId(id.contextName, true) }
|
|
96
|
+
: id);
|
|
97
|
+
const ids = new MutationQueryFactory().normalizeNodeRefs(resolvedIds);
|
|
98
|
+
return buildCanonicalDeleteMutationIR({ shape, ids });
|
|
99
|
+
}
|
|
100
|
+
export function lower(query) {
|
|
101
|
+
switch (query.__queryKind) {
|
|
102
|
+
case 'select':
|
|
103
|
+
return buildSelectQuery(query.toRawInput());
|
|
104
|
+
case 'create':
|
|
105
|
+
return lowerCreate(query._lowerSpec());
|
|
106
|
+
case 'update':
|
|
107
|
+
return lowerUpdate(query._lowerSpec());
|
|
108
|
+
case 'delete':
|
|
109
|
+
return lowerDelete(query._lowerSpec());
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=lower.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lower.js","sourceRoot":"","sources":["../../../src/queries/lower.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AACH,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAC,sBAAsB,EAA4B,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,8BAA8B,EAC9B,8BAA8B,EAC9B,mCAAmC,EACnC,8BAA8B,EAC9B,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,OAAO,EAAC,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAwB5C,qEAAqE;AACrE,SAAS,cAAc,CAAC,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|
|
2
|
+
import type { IRCreateQuery } from './CreateQuery.js';
|
|
3
|
+
import type { IRUpdateQuery } from './UpdateQuery.js';
|
|
4
|
+
import type { IRDeleteQuery } from './DeleteQuery.js';
|
|
5
|
+
import { type MutationJSON, type MutationNodeDataJSON } from './MutationSerialization.js';
|
|
6
|
+
/** Rebuild a normalized node description from JSON, resolving labels via the shape. */
|
|
7
|
+
export declare function decodeNodeData(json: MutationNodeDataJSON): NodeDescriptionValue;
|
|
8
|
+
/**
|
|
9
|
+
* Lower a mutation DSL-JSON envelope to the canonical IR mutation the dataset
|
|
10
|
+
* expects. Mirrors the IR that `lower()` produces from the live builder.
|
|
11
|
+
*/
|
|
12
|
+
export declare function lowerMutationJSON(json: MutationJSON): IRCreateQuery | IRUpdateQuery | IRDeleteQuery;
|