@_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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.CONTEXT_REF_KEY = void 0;
|
|
9
|
+
exports.encodeContextRef = encodeContextRef;
|
|
10
|
+
exports.isContextRefJSON = isContextRefJSON;
|
|
11
|
+
exports.resolveContextId = resolveContextId;
|
|
12
|
+
/**
|
|
13
|
+
* The unified wire encoding for a *query-context reference*.
|
|
14
|
+
*
|
|
15
|
+
* A context reference is a placeholder for a node id that is not known when the
|
|
16
|
+
* query is authored — e.g. "the currently authenticated user". Instead of
|
|
17
|
+
* resolving it eagerly (which loses the reference and breaks queries built
|
|
18
|
+
* before auth completes), the reference is carried on the wire as a tagged
|
|
19
|
+
* marker and resolved at lowering time against whatever context map is
|
|
20
|
+
* available (client-side React context, server-side auth, …).
|
|
21
|
+
*
|
|
22
|
+
* The same `{$ctx: "<name>"}` marker is used in *every* position a node id can
|
|
23
|
+
* appear: the select subject, the update target, where-clause arguments, and
|
|
24
|
+
* mutation field values. One marker, one resolver, everywhere.
|
|
25
|
+
*/
|
|
26
|
+
const QueryContext_js_1 = require("./QueryContext.js");
|
|
27
|
+
/** The reserved key that tags a context reference in DSL-JSON. */
|
|
28
|
+
exports.CONTEXT_REF_KEY = '$ctx';
|
|
29
|
+
/** Build a context-reference marker for the given context name. */
|
|
30
|
+
function encodeContextRef(name) {
|
|
31
|
+
return { [exports.CONTEXT_REF_KEY]: name };
|
|
32
|
+
}
|
|
33
|
+
/** Type guard: is this value a `{$ctx: "..."}` context-reference marker? */
|
|
34
|
+
function isContextRefJSON(value) {
|
|
35
|
+
return (!!value &&
|
|
36
|
+
typeof value === 'object' &&
|
|
37
|
+
typeof value[exports.CONTEXT_REF_KEY] === 'string' &&
|
|
38
|
+
Object.keys(value).length === 1);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resolve a context name to its node id against the current context map.
|
|
42
|
+
*
|
|
43
|
+
* @param name the context name (e.g. `'user'`)
|
|
44
|
+
* @param required when true, throw {@link UnresolvedContextError} if the context
|
|
45
|
+
* isn't set (the mutation contract — a mutation must not silently target
|
|
46
|
+
* nothing). When false, return `undefined` (the select contract — an
|
|
47
|
+
* unresolved subject simply yields no results, and a reactive layer re-runs
|
|
48
|
+
* the query once the context lands).
|
|
49
|
+
*/
|
|
50
|
+
function resolveContextId(name, required) {
|
|
51
|
+
var _a;
|
|
52
|
+
const id = (_a = (0, QueryContext_js_1.getQueryContext)(name)) === null || _a === void 0 ? void 0 : _a.id;
|
|
53
|
+
if (!id && required) {
|
|
54
|
+
throw new QueryContext_js_1.UnresolvedContextError(name);
|
|
55
|
+
}
|
|
56
|
+
return id;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=ContextRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextRef.js","sourceRoot":"","sources":["../../../src/queries/ContextRef.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AA2BH,4CAEC;AAGD,4CAOC;AAYD,4CASC;AA1DD;;;;;;;;;;;;;GAaG;AACH,uDAA0E;AAE1E,kEAAkE;AACrD,QAAA,eAAe,GAAG,MAAM,CAAC;AAOtC,mEAAmE;AACnE,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,OAAO,EAAC,CAAC,uBAAe,CAAC,EAAE,IAAI,EAAC,CAAC;AACnC,CAAC;AAED,4EAA4E;AAC5E,SAAgB,gBAAgB,CAAC,KAAc;IAC7C,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,OAAQ,KAAiC,CAAC,uBAAe,CAAC,KAAK,QAAQ;QACvE,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,CAAC,MAAM,KAAK,CAAC,CAC1C,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,gBAAgB,CAC9B,IAAY,EACZ,QAAiB;;IAEjB,MAAM,EAAE,GAAG,MAAA,IAAA,iCAAe,EAAC,IAAI,CAAC,0CAAE,EAAE,CAAC;IACrC,IAAI,CAAC,EAAE,IAAI,QAAQ,EAAE,CAAC;QACpB,MAAM,IAAI,wCAAsB,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Shape, type ShapeConstructor } from '../shapes/Shape.js';
|
|
2
2
|
import type { UpdatePartial } from './QueryFactory.js';
|
|
3
|
-
import
|
|
3
|
+
import type { CreateResponse } from './CreateQuery.js';
|
|
4
|
+
import type { NodeShape } from '../shapes/SHACL.js';
|
|
5
|
+
import { type CreateMutationJSON } from './MutationSerialization.js';
|
|
6
|
+
import type { CreateLowerSpec } from './mutationLowerSpec.js';
|
|
4
7
|
/**
|
|
5
8
|
* An immutable, fluent builder for create mutations.
|
|
6
9
|
*
|
|
@@ -11,7 +14,8 @@ import { type CreateQuery, type CreateResponse } from './CreateQuery.js';
|
|
|
11
14
|
* const result = await CreateBuilder.from(Person).set({name: 'Alice'});
|
|
12
15
|
* ```
|
|
13
16
|
*
|
|
14
|
-
*
|
|
17
|
+
* Serialization normalizes through the IR-free factory base; IR is produced by
|
|
18
|
+
* the free `lower()` function (the builder itself imports no IR).
|
|
15
19
|
*/
|
|
16
20
|
export declare class CreateBuilder<S extends Shape = Shape, U extends UpdatePartial<S> = UpdatePartial<S>> implements PromiseLike<CreateResponse<U>>, Promise<CreateResponse<U>> {
|
|
17
21
|
private readonly _shape;
|
|
@@ -23,12 +27,24 @@ export declare class CreateBuilder<S extends Shape = Shape, U extends UpdatePart
|
|
|
23
27
|
* Create a CreateBuilder for the given shape.
|
|
24
28
|
*/
|
|
25
29
|
static from<S extends Shape>(shape: ShapeConstructor<S> | string): CreateBuilder<S>;
|
|
30
|
+
/** Reconstruct a CreateBuilder from its DSL-JSON (inverse of `toJSON`). */
|
|
31
|
+
static fromJSON(json: CreateMutationJSON): CreateBuilder;
|
|
26
32
|
/** Set the data for the entity to create. */
|
|
27
33
|
set<NewU extends UpdatePartial<S>>(data: NewU): CreateBuilder<S, NewU>;
|
|
28
34
|
/** Pre-assign a node ID for the created entity. */
|
|
29
35
|
withId(id: string): CreateBuilder<S, U>;
|
|
30
|
-
/**
|
|
31
|
-
|
|
36
|
+
/** Discriminator for the free `lower()` function and dataset routing. */
|
|
37
|
+
readonly __queryKind: "create";
|
|
38
|
+
/** The shape this query targets — the routing key datasets/`LinkedStorage` use. */
|
|
39
|
+
get shape(): NodeShape;
|
|
40
|
+
/** @internal The IR-free lowering spec consumed by `lower()`. Validates inputs. */
|
|
41
|
+
_lowerSpec(): CreateLowerSpec<S>;
|
|
42
|
+
/**
|
|
43
|
+
* Serialize this create mutation to lightweight DSL-JSON. Normalizes the create
|
|
44
|
+
* data through the IR-free factory base (the same normalization `lower()` runs)
|
|
45
|
+
* so the result is concrete and JSON-safe, then encodes the node description.
|
|
46
|
+
*/
|
|
47
|
+
toJSON(): CreateMutationJSON;
|
|
32
48
|
/** Execute the mutation. */
|
|
33
49
|
exec(): Promise<CreateResponse<U>>;
|
|
34
50
|
then<TResult1 = CreateResponse<U>, TResult2 = never>(onfulfilled?: ((value: CreateResponse<U>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CreateBuilder = void 0;
|
|
4
4
|
const resolveShape_js_1 = require("./resolveShape.js");
|
|
5
|
-
const
|
|
5
|
+
const MutationQuery_js_1 = require("./MutationQuery.js");
|
|
6
6
|
const queryDispatch_js_1 = require("./queryDispatch.js");
|
|
7
|
+
const wireVersion_js_1 = require("./wireVersion.js");
|
|
8
|
+
const MutationSerialization_js_1 = require("./MutationSerialization.js");
|
|
7
9
|
/**
|
|
8
10
|
* An immutable, fluent builder for create mutations.
|
|
9
11
|
*
|
|
@@ -14,10 +16,16 @@ const queryDispatch_js_1 = require("./queryDispatch.js");
|
|
|
14
16
|
* const result = await CreateBuilder.from(Person).set({name: 'Alice'});
|
|
15
17
|
* ```
|
|
16
18
|
*
|
|
17
|
-
*
|
|
19
|
+
* Serialization normalizes through the IR-free factory base; IR is produced by
|
|
20
|
+
* the free `lower()` function (the builder itself imports no IR).
|
|
18
21
|
*/
|
|
19
22
|
class CreateBuilder {
|
|
20
23
|
constructor(init) {
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Build & execute
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
/** Discriminator for the free `lower()` function and dataset routing. */
|
|
28
|
+
this.__queryKind = 'create';
|
|
21
29
|
this._shape = init.shape;
|
|
22
30
|
this._data = init.data;
|
|
23
31
|
this._fixedId = init.fixedId;
|
|
@@ -35,6 +43,11 @@ class CreateBuilder {
|
|
|
35
43
|
const resolved = (0, resolveShape_js_1.resolveShape)(shape);
|
|
36
44
|
return new CreateBuilder({ shape: resolved });
|
|
37
45
|
}
|
|
46
|
+
/** Reconstruct a CreateBuilder from its DSL-JSON (inverse of `toJSON`). */
|
|
47
|
+
static fromJSON(json) {
|
|
48
|
+
(0, wireVersion_js_1.assertWireVersion)(json.v);
|
|
49
|
+
return CreateBuilder.from(json.shape).set((0, MutationSerialization_js_1.decodeNodeDataToRaw)(json.data));
|
|
50
|
+
}
|
|
38
51
|
// ---------------------------------------------------------------------------
|
|
39
52
|
// Fluent API
|
|
40
53
|
// ---------------------------------------------------------------------------
|
|
@@ -46,13 +59,14 @@ class CreateBuilder {
|
|
|
46
59
|
withId(id) {
|
|
47
60
|
return this.clone({ fixedId: id });
|
|
48
61
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
/** The shape this query targets — the routing key datasets/`LinkedStorage` use. */
|
|
63
|
+
get shape() {
|
|
64
|
+
return this._shape.shape;
|
|
65
|
+
}
|
|
66
|
+
/** @internal The IR-free lowering spec consumed by `lower()`. Validates inputs. */
|
|
67
|
+
_lowerSpec() {
|
|
54
68
|
if (!this._data) {
|
|
55
|
-
throw new Error('CreateBuilder requires .set(data) before .
|
|
69
|
+
throw new Error('CreateBuilder requires .set(data) before it can be lowered. Specify what to create.');
|
|
56
70
|
}
|
|
57
71
|
const data = this._data;
|
|
58
72
|
// Validate that required properties (minCount >= 1) are present in data
|
|
@@ -73,12 +87,30 @@ class CreateBuilder {
|
|
|
73
87
|
// Inject __id if fixedId is set
|
|
74
88
|
const dataWithId = this._fixedId
|
|
75
89
|
? Object.assign(Object.assign({}, data), { __id: this._fixedId }) : data;
|
|
76
|
-
|
|
77
|
-
|
|
90
|
+
return { shapeClass: this._shape, data: dataWithId };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Serialize this create mutation to lightweight DSL-JSON. Normalizes the create
|
|
94
|
+
* data through the IR-free factory base (the same normalization `lower()` runs)
|
|
95
|
+
* so the result is concrete and JSON-safe, then encodes the node description.
|
|
96
|
+
*/
|
|
97
|
+
toJSON() {
|
|
98
|
+
if (!this._data) {
|
|
99
|
+
throw new Error('CreateBuilder requires .set(data) before .toJSON().');
|
|
100
|
+
}
|
|
101
|
+
const dataWithId = this._fixedId
|
|
102
|
+
? Object.assign(Object.assign({}, this._data), { __id: this._fixedId }) : this._data;
|
|
103
|
+
const description = new MutationQuery_js_1.MutationQueryFactory().describe(this._shape.shape, dataWithId, true);
|
|
104
|
+
return {
|
|
105
|
+
v: wireVersion_js_1.WIRE_VERSION,
|
|
106
|
+
op: 'create',
|
|
107
|
+
shape: this._shape.shape.id,
|
|
108
|
+
data: (0, MutationSerialization_js_1.encodeNodeData)(description),
|
|
109
|
+
};
|
|
78
110
|
}
|
|
79
111
|
/** Execute the mutation. */
|
|
80
112
|
exec() {
|
|
81
|
-
return (0, queryDispatch_js_1.getQueryDispatch)().createQuery(this
|
|
113
|
+
return (0, queryDispatch_js_1.getQueryDispatch)().createQuery(this);
|
|
82
114
|
}
|
|
83
115
|
// ---------------------------------------------------------------------------
|
|
84
116
|
// Promise interface
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateBuilder.js","sourceRoot":"","sources":["../../../src/queries/CreateBuilder.ts"],"names":[],"mappings":";;;AACA,uDAA+C;
|
|
1
|
+
{"version":3,"file":"CreateBuilder.js","sourceRoot":"","sources":["../../../src/queries/CreateBuilder.ts"],"names":[],"mappings":";;;AACA,uDAA+C;AAG/C,yDAAwD;AACxD,yDAAoD;AACpD,qDAAiE;AAEjE,yEAAwG;AAYxG;;;;;;;;;;;;GAYG;AACH,MAAa,aAAa;IAOxB,YAAoB,IAA0B;QA+C9C,8EAA8E;QAC9E,kBAAkB;QAClB,8EAA8E;QAE9E,yEAAyE;QAChE,gBAAW,GAAG,QAAiB,CAAC;QAnDvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;I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ory } from './MutationQuery.js';
|
|
1
|
+
import type { AddId } from './QueryFactory.js';
|
|
4
2
|
import type { IRCreateMutation } from './IntermediateRepresentation.js';
|
|
3
|
+
import type { NodeShape } from '../shapes/SHACL.js';
|
|
4
|
+
import type { CreateMutationJSON } from './MutationSerialization.js';
|
|
5
|
+
import type { CreateLowerSpec } from './mutationLowerSpec.js';
|
|
5
6
|
/**
|
|
6
|
-
* The
|
|
7
|
-
*
|
|
7
|
+
* The closed, read-only create query a dataset receives (implemented by
|
|
8
|
+
* `CreateBuilder`). The IR is `IRCreateQuery`, produced by `lower(query)` — the
|
|
9
|
+
* IR construction lives in the IR tier, not here, so this module stays IR-free.
|
|
8
10
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
constructor(shapeClass: ShapeConstructor<ShapeType>, updateObjectOrFn: U);
|
|
16
|
-
build(): CreateQuery;
|
|
11
|
+
export interface CreateQuery {
|
|
12
|
+
readonly __queryKind: 'create';
|
|
13
|
+
readonly shape: NodeShape;
|
|
14
|
+
toJSON(): CreateMutationJSON;
|
|
15
|
+
/** @internal IR-free lowering spec consumed by `lower()`. */
|
|
16
|
+
_lowerSpec(): CreateLowerSpec;
|
|
17
17
|
}
|
|
18
|
+
/** The lowered IR for a create mutation (what `lower()` produces). */
|
|
19
|
+
export type IRCreateQuery = IRCreateMutation;
|
|
20
|
+
export type CreateResponse<U> = AddId<U, true>;
|
|
@@ -1,20 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CreateQueryFactory = void 0;
|
|
4
|
-
const MutationQuery_js_1 = require("./MutationQuery.js");
|
|
5
|
-
const IRMutation_js_1 = require("./IRMutation.js");
|
|
6
|
-
class CreateQueryFactory extends MutationQuery_js_1.MutationQueryFactory {
|
|
7
|
-
constructor(shapeClass, updateObjectOrFn) {
|
|
8
|
-
super();
|
|
9
|
-
this.shapeClass = shapeClass;
|
|
10
|
-
this.description = this.convertUpdateObject(updateObjectOrFn, this.shapeClass.shape, true);
|
|
11
|
-
}
|
|
12
|
-
build() {
|
|
13
|
-
return (0, IRMutation_js_1.buildCanonicalCreateMutationIR)({
|
|
14
|
-
shape: this.shapeClass.shape,
|
|
15
|
-
description: this.description,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.CreateQueryFactory = CreateQueryFactory;
|
|
20
3
|
//# sourceMappingURL=CreateQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateQuery.js","sourceRoot":"","sources":["../../../src/queries/CreateQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CreateQuery.js","sourceRoot":"","sources":["../../../src/queries/CreateQuery.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { Shape, type ShapeConstructor } from '../shapes/Shape.js';
|
|
2
|
-
import
|
|
2
|
+
import type { DeleteResponse } from './DeleteQuery.js';
|
|
3
3
|
import type { NodeId } from './MutationQuery.js';
|
|
4
|
+
import type { NodeShape } from '../shapes/SHACL.js';
|
|
4
5
|
import { type WhereClause } from './SelectQuery.js';
|
|
6
|
+
import { type DeleteMutationJSON } from './MutationSerialization.js';
|
|
7
|
+
import type { DeleteLowerSpec } from './mutationLowerSpec.js';
|
|
8
|
+
import { PendingQueryContext } from './QueryContext.js';
|
|
9
|
+
/** A node to delete: a concrete id, a `{id}` ref, or a live query-context reference. */
|
|
10
|
+
export type DeleteId = NodeId | PendingQueryContext;
|
|
5
11
|
/**
|
|
6
12
|
* An immutable, fluent builder for delete mutations.
|
|
7
13
|
*
|
|
@@ -18,15 +24,24 @@ export declare class DeleteBuilder<S extends Shape = Shape, R = DeleteResponse>
|
|
|
18
24
|
private readonly _ids?;
|
|
19
25
|
private readonly _mode?;
|
|
20
26
|
private readonly _whereFn?;
|
|
27
|
+
private readonly _where?;
|
|
21
28
|
private constructor();
|
|
22
29
|
private clone;
|
|
23
|
-
static from<S extends Shape>(shape: ShapeConstructor<S> | string, ids?:
|
|
30
|
+
static from<S extends Shape>(shape: ShapeConstructor<S> | string, ids?: DeleteId | DeleteId[]): DeleteBuilder<S, DeleteResponse>;
|
|
31
|
+
/** Reconstruct a DeleteBuilder from its DSL-JSON (inverse of `toJSON`). */
|
|
32
|
+
static fromJSON(json: DeleteMutationJSON): DeleteBuilder;
|
|
24
33
|
/** Delete all instances of this shape type. Returns void. */
|
|
25
34
|
all(): DeleteBuilder<S, void>;
|
|
26
35
|
/** Delete instances matching a condition. Returns void. */
|
|
27
36
|
where(fn: WhereClause<S>): DeleteBuilder<S, void>;
|
|
28
|
-
/**
|
|
29
|
-
|
|
37
|
+
/** Discriminator for the free `lower()` function and dataset routing. */
|
|
38
|
+
readonly __queryKind: "delete";
|
|
39
|
+
/** The shape this query targets — the routing key datasets/`LinkedStorage` use. */
|
|
40
|
+
get shape(): NodeShape;
|
|
41
|
+
/** @internal The IR-free lowering spec consumed by `lower()`. Validates inputs. */
|
|
42
|
+
_lowerSpec(): DeleteLowerSpec<S>;
|
|
43
|
+
/** Serialize this delete mutation to lightweight DSL-JSON. */
|
|
44
|
+
toJSON(): DeleteMutationJSON;
|
|
30
45
|
/** Execute the mutation. */
|
|
31
46
|
exec(): Promise<R>;
|
|
32
47
|
then<TResult1 = R, TResult2 = never>(onfulfilled?: ((value: R) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DeleteBuilder = void 0;
|
|
4
4
|
const resolveShape_js_1 = require("./resolveShape.js");
|
|
5
|
-
const DeleteQuery_js_1 = require("./DeleteQuery.js");
|
|
6
5
|
const queryDispatch_js_1 = require("./queryDispatch.js");
|
|
6
|
+
const wireVersion_js_1 = require("./wireVersion.js");
|
|
7
7
|
const SelectQuery_js_1 = require("./SelectQuery.js");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const IRLower_js_1 = require("./IRLower.js");
|
|
8
|
+
const QueryBuilderSerialization_js_1 = require("./QueryBuilderSerialization.js");
|
|
9
|
+
const QueryContext_js_1 = require("./QueryContext.js");
|
|
10
|
+
const ContextRef_js_1 = require("./ContextRef.js");
|
|
12
11
|
/**
|
|
13
12
|
* An immutable, fluent builder for delete mutations.
|
|
14
13
|
*
|
|
@@ -22,13 +21,19 @@ const IRLower_js_1 = require("./IRLower.js");
|
|
|
22
21
|
*/
|
|
23
22
|
class DeleteBuilder {
|
|
24
23
|
constructor(init) {
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Build & execute
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
/** Discriminator for the free `lower()` function and dataset routing. */
|
|
28
|
+
this.__queryKind = 'delete';
|
|
25
29
|
this._shape = init.shape;
|
|
26
30
|
this._ids = init.ids;
|
|
27
31
|
this._mode = init.mode;
|
|
28
32
|
this._whereFn = init.whereFn;
|
|
33
|
+
this._where = init.where;
|
|
29
34
|
}
|
|
30
35
|
clone(overrides = {}) {
|
|
31
|
-
return new DeleteBuilder(Object.assign({ shape: this._shape, ids: this._ids, mode: this._mode, whereFn: this._whereFn }, overrides));
|
|
36
|
+
return new DeleteBuilder(Object.assign({ shape: this._shape, ids: this._ids, mode: this._mode, whereFn: this._whereFn, where: this._where }, overrides));
|
|
32
37
|
}
|
|
33
38
|
// ---------------------------------------------------------------------------
|
|
34
39
|
// Static constructors
|
|
@@ -36,11 +41,28 @@ class DeleteBuilder {
|
|
|
36
41
|
static from(shape, ids) {
|
|
37
42
|
const resolved = (0, resolveShape_js_1.resolveShape)(shape);
|
|
38
43
|
if (ids !== undefined) {
|
|
39
|
-
|
|
44
|
+
// Normalize any context reference (unset PendingQueryContext or a resolved
|
|
45
|
+
// context shape) to a {$ctx} marker so set/unset behave identically.
|
|
46
|
+
const idsArray = (Array.isArray(ids) ? ids : [ids]).map((id) => { var _a; return (_a = (0, QueryContext_js_1.asContextRef)(id)) !== null && _a !== void 0 ? _a : id; });
|
|
40
47
|
return new DeleteBuilder({ shape: resolved, ids: idsArray, mode: 'ids' });
|
|
41
48
|
}
|
|
42
49
|
return new DeleteBuilder({ shape: resolved });
|
|
43
50
|
}
|
|
51
|
+
/** Reconstruct a DeleteBuilder from its DSL-JSON (inverse of `toJSON`). */
|
|
52
|
+
static fromJSON(json) {
|
|
53
|
+
(0, wireVersion_js_1.assertWireVersion)(json.v);
|
|
54
|
+
const resolved = (0, resolveShape_js_1.resolveShape)(json.shape);
|
|
55
|
+
if (json.mode === 'ids') {
|
|
56
|
+
// A `{$ctx}` id rehydrates as a live context ref (resolved at lower).
|
|
57
|
+
const ids = json.ids.map((id) => (0, ContextRef_js_1.isContextRefJSON)(id) ? new QueryContext_js_1.PendingQueryContext(id.$ctx) : { id });
|
|
58
|
+
return new DeleteBuilder({ shape: resolved, ids, mode: 'ids' });
|
|
59
|
+
}
|
|
60
|
+
if (json.mode === 'all') {
|
|
61
|
+
return new DeleteBuilder({ shape: resolved, mode: 'all' });
|
|
62
|
+
}
|
|
63
|
+
const where = (0, QueryBuilderSerialization_js_1.deserializeWherePath)(resolved.shape, json.where);
|
|
64
|
+
return new DeleteBuilder({ shape: resolved, mode: 'where', where });
|
|
65
|
+
}
|
|
44
66
|
// ---------------------------------------------------------------------------
|
|
45
67
|
// Fluent API
|
|
46
68
|
// ---------------------------------------------------------------------------
|
|
@@ -52,45 +74,76 @@ class DeleteBuilder {
|
|
|
52
74
|
where(fn) {
|
|
53
75
|
return this.clone({ mode: 'where', whereFn: fn, ids: undefined });
|
|
54
76
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
77
|
+
/** The shape this query targets — the routing key datasets/`LinkedStorage` use. */
|
|
78
|
+
get shape() {
|
|
79
|
+
return this._shape.shape;
|
|
80
|
+
}
|
|
81
|
+
/** @internal The IR-free lowering spec consumed by `lower()`. Validates inputs. */
|
|
82
|
+
_lowerSpec() {
|
|
83
|
+
var _a;
|
|
60
84
|
const mode = this._mode || (this._ids ? 'ids' : undefined);
|
|
61
85
|
if (mode === 'all') {
|
|
62
|
-
return
|
|
63
|
-
shape: this._shape.shape,
|
|
64
|
-
});
|
|
86
|
+
return { shapeClass: this._shape, mode: 'all' };
|
|
65
87
|
}
|
|
66
88
|
if (mode === 'where') {
|
|
67
|
-
|
|
89
|
+
const wherePath = (_a = this._where) !== null && _a !== void 0 ? _a : (this._whereFn ? (0, SelectQuery_js_1.processWhereClause)(this._whereFn, this._shape) : undefined);
|
|
90
|
+
if (!wherePath) {
|
|
68
91
|
throw new Error('DeleteBuilder.where() requires a condition callback.');
|
|
69
92
|
}
|
|
70
|
-
|
|
71
|
-
const desugared = (0, IRDesugar_js_1.toWhere)(wherePath);
|
|
72
|
-
const canonical = (0, IRCanonicalize_js_1.canonicalizeWhere)(desugared);
|
|
73
|
-
const { where, wherePatterns } = (0, IRLower_js_1.lowerWhereToIR)(canonical);
|
|
74
|
-
return (0, IRMutation_js_1.buildCanonicalDeleteWhereMutationIR)({
|
|
75
|
-
shape: this._shape.shape,
|
|
76
|
-
where,
|
|
77
|
-
wherePatterns,
|
|
78
|
-
});
|
|
93
|
+
return { shapeClass: this._shape, mode: 'where', wherePath };
|
|
79
94
|
}
|
|
80
95
|
// Default: ID-based delete
|
|
81
96
|
if (!this._ids || this._ids.length === 0) {
|
|
82
97
|
throw new Error('DeleteBuilder requires at least one ID to delete. Use DeleteBuilder.from(shape, ids), .all(), or .where().');
|
|
83
98
|
}
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
return { shapeClass: this._shape, mode: 'ids', ids: this._ids };
|
|
100
|
+
}
|
|
101
|
+
/** Serialize this delete mutation to lightweight DSL-JSON. */
|
|
102
|
+
toJSON() {
|
|
103
|
+
var _a;
|
|
104
|
+
const shape = this._shape.shape.id;
|
|
105
|
+
const mode = this._mode || (this._ids ? 'ids' : undefined);
|
|
106
|
+
if (mode === 'all') {
|
|
107
|
+
return { v: wireVersion_js_1.WIRE_VERSION, op: 'delete', shape, mode: 'all' };
|
|
108
|
+
}
|
|
109
|
+
if (mode === 'where') {
|
|
110
|
+
const wherePath = (_a = this._where) !== null && _a !== void 0 ? _a : (this._whereFn ? (0, SelectQuery_js_1.processWhereClause)(this._whereFn, this._shape) : undefined);
|
|
111
|
+
if (!wherePath) {
|
|
112
|
+
throw new Error('DeleteBuilder.where() requires a condition callback.');
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
v: wireVersion_js_1.WIRE_VERSION,
|
|
116
|
+
op: 'delete',
|
|
117
|
+
shape,
|
|
118
|
+
mode: 'where',
|
|
119
|
+
where: (0, QueryBuilderSerialization_js_1.serializeWherePath)(wherePath),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
if (!this._ids || this._ids.length === 0) {
|
|
123
|
+
throw new Error('DeleteBuilder requires at least one ID, .all(), or .where() before .toJSON().');
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
v: wireVersion_js_1.WIRE_VERSION,
|
|
127
|
+
op: 'delete',
|
|
128
|
+
shape,
|
|
129
|
+
mode: 'ids',
|
|
130
|
+
ids: this._ids.map((id) =>
|
|
131
|
+
// An unresolved context ref travels as a `{$ctx}` marker; a concrete id
|
|
132
|
+
// (string or `{id}`, incl. a resolved context shape) as a plain string.
|
|
133
|
+
id instanceof QueryContext_js_1.PendingQueryContext
|
|
134
|
+
? (0, ContextRef_js_1.encodeContextRef)(id.contextName)
|
|
135
|
+
: typeof id === 'string'
|
|
136
|
+
? id
|
|
137
|
+
: id.id),
|
|
138
|
+
};
|
|
86
139
|
}
|
|
87
140
|
/** Execute the mutation. */
|
|
88
141
|
exec() {
|
|
89
142
|
const mode = this._mode || (this._ids ? 'ids' : undefined);
|
|
90
143
|
if (mode === 'all' || mode === 'where') {
|
|
91
|
-
return (0, queryDispatch_js_1.getQueryDispatch)().deleteQuery(this
|
|
144
|
+
return (0, queryDispatch_js_1.getQueryDispatch)().deleteQuery(this).then(() => undefined);
|
|
92
145
|
}
|
|
93
|
-
return (0, queryDispatch_js_1.getQueryDispatch)().deleteQuery(this
|
|
146
|
+
return (0, queryDispatch_js_1.getQueryDispatch)().deleteQuery(this);
|
|
94
147
|
}
|
|
95
148
|
// ---------------------------------------------------------------------------
|
|
96
149
|
// Promise interface
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeleteBuilder.js","sourceRoot":"","sources":["../../../src/queries/DeleteBuilder.ts"],"names":[],"mappings":";;;AACA,uDAA+C;
|
|
1
|
+
{"version":3,"file":"DeleteBuilder.js","sourceRoot":"","sources":["../../../src/queries/DeleteBuilder.ts"],"names":[],"mappings":";;;AACA,uDAA+C;AAG/C,yDAAoD;AACpD,qDAAiE;AAEjE,qDAAsF;AAEtF,iFAAwF;AAExF,uDAAoE;AACpE,mDAAmE;AAmBnE;;;;;;;;;;GAUG;AACH,MAAa,aAAa;IASxB,YAAoB,IAA0B;QAuE9C,8EAA8E;QAC9E,kBAAkB;QAClB,8EAA8E;QAE9E,yEAAyE;QAChE,gBAAW,GAAG,QAAiB,CAAC;QA3EvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC;IAC3B,CAAC;IAEO,KAAK,CAAC,YAA2C,EAAE;QACzD,OAAO,IAAI,aAAa,iBACtB,KAAK,EAAE,IAAI,CAAC,MAAM,EAClB,GAAG,EAAE,IAAI,CA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MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACvC,OAAO,IAAA,mCAAgB,GAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAe,CAAC;QAClF,CAAC;QACD,OAAO,IAAA,mCAAgB,GAAE,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;AAjMD,sCAiMC"}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { NodeReferenceValue, type UpdatePartial } from './QueryFactory.js';
|
|
3
|
-
import { MutationQueryFactory, type NodeId } from './MutationQuery.js';
|
|
1
|
+
import type { NodeReferenceValue } from './QueryFactory.js';
|
|
4
2
|
import type { IRDeleteMutation, IRDeleteAllMutation, IRDeleteWhereMutation } from './IntermediateRepresentation.js';
|
|
3
|
+
import type { NodeShape } from '../shapes/SHACL.js';
|
|
4
|
+
import type { DeleteMutationJSON } from './MutationSerialization.js';
|
|
5
|
+
import type { DeleteLowerSpec } from './mutationLowerSpec.js';
|
|
5
6
|
/**
|
|
6
|
-
* The
|
|
7
|
-
*
|
|
7
|
+
* The closed, read-only delete query a dataset receives (implemented by
|
|
8
|
+
* `DeleteBuilder`). The IR is `IRDeleteQuery`, produced by `lower(query)` — the
|
|
9
|
+
* IR construction lives in the IR tier, not here, so this module stays IR-free.
|
|
8
10
|
*/
|
|
9
|
-
export
|
|
11
|
+
export interface DeleteQuery {
|
|
12
|
+
readonly __queryKind: 'delete';
|
|
13
|
+
readonly shape: NodeShape;
|
|
14
|
+
toJSON(): DeleteMutationJSON;
|
|
15
|
+
/** @internal IR-free lowering spec consumed by `lower()`. */
|
|
16
|
+
_lowerSpec(): DeleteLowerSpec;
|
|
17
|
+
}
|
|
18
|
+
/** The lowered IR for a delete mutation (what `lower()` produces). */
|
|
19
|
+
export type IRDeleteQuery = IRDeleteMutation | IRDeleteAllMutation | IRDeleteWhereMutation;
|
|
10
20
|
export type DeleteResponse = {
|
|
11
21
|
/**
|
|
12
22
|
* The IDs of the items that were successfully deleted.
|
|
@@ -25,10 +35,3 @@ export type DeleteResponse = {
|
|
|
25
35
|
*/
|
|
26
36
|
errors?: Record<string, string>;
|
|
27
37
|
};
|
|
28
|
-
export declare class DeleteQueryFactory<ShapeType extends Shape, U extends UpdatePartial<ShapeType>> extends MutationQueryFactory {
|
|
29
|
-
shapeClass: ShapeConstructor<ShapeType>;
|
|
30
|
-
readonly id: string;
|
|
31
|
-
readonly ids: NodeReferenceValue[];
|
|
32
|
-
constructor(shapeClass: ShapeConstructor<ShapeType>, ids: NodeId[] | NodeId);
|
|
33
|
-
build(): DeleteQuery;
|
|
34
|
-
}
|
|
@@ -1,20 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DeleteQueryFactory = void 0;
|
|
4
|
-
const MutationQuery_js_1 = require("./MutationQuery.js");
|
|
5
|
-
const IRMutation_js_1 = require("./IRMutation.js");
|
|
6
|
-
class DeleteQueryFactory extends MutationQuery_js_1.MutationQueryFactory {
|
|
7
|
-
constructor(shapeClass, ids) {
|
|
8
|
-
super();
|
|
9
|
-
this.shapeClass = shapeClass;
|
|
10
|
-
this.ids = this.convertNodeReferences(ids);
|
|
11
|
-
}
|
|
12
|
-
build() {
|
|
13
|
-
return (0, IRMutation_js_1.buildCanonicalDeleteMutationIR)({
|
|
14
|
-
shape: this.shapeClass.shape,
|
|
15
|
-
ids: this.ids,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.DeleteQueryFactory = DeleteQueryFactory;
|
|
20
3
|
//# sourceMappingURL=DeleteQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeleteQuery.js","sourceRoot":"","sources":["../../../src/queries/DeleteQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DeleteQuery.js","sourceRoot":"","sources":["../../../src/queries/DeleteQuery.ts"],"names":[],"mappings":""}
|