@_linked/core 1.3.0 → 2.0.0-next.20260310082533
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 +113 -10
- package/README.md +209 -14
- package/lib/cjs/index.d.ts +10 -2
- package/lib/cjs/index.js +31 -6
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/package.d.ts +1 -1
- package/lib/cjs/queries/CreateBuilder.d.ts +38 -0
- package/lib/cjs/queries/CreateBuilder.js +100 -0
- package/lib/cjs/queries/CreateBuilder.js.map +1 -0
- package/lib/cjs/queries/CreateQuery.d.ts +3 -3
- package/lib/cjs/queries/CreateQuery.js.map +1 -1
- package/lib/cjs/queries/DeleteBuilder.d.ts +39 -0
- package/lib/cjs/queries/DeleteBuilder.js +85 -0
- package/lib/cjs/queries/DeleteBuilder.js.map +1 -0
- package/lib/cjs/queries/DeleteQuery.d.ts +3 -3
- package/lib/cjs/queries/DeleteQuery.js.map +1 -1
- package/lib/cjs/queries/FieldSet.d.ts +203 -0
- package/lib/cjs/queries/FieldSet.js +533 -0
- package/lib/cjs/queries/FieldSet.js.map +1 -0
- package/lib/cjs/queries/IRDesugar.d.ts +13 -8
- package/lib/cjs/queries/IRDesugar.js +143 -132
- package/lib/cjs/queries/IRDesugar.js.map +1 -1
- package/lib/cjs/queries/IRLower.js +1 -0
- package/lib/cjs/queries/IRLower.js.map +1 -1
- package/lib/cjs/queries/IntermediateRepresentation.d.ts +1 -0
- package/lib/cjs/queries/MutationQuery.d.ts +1 -1
- package/lib/cjs/queries/MutationQuery.js +1 -6
- package/lib/cjs/queries/MutationQuery.js.map +1 -1
- package/lib/cjs/queries/PropertyPath.d.ts +38 -0
- package/lib/cjs/queries/PropertyPath.js +82 -0
- package/lib/cjs/queries/PropertyPath.js.map +1 -0
- package/lib/cjs/queries/ProxiedPathBuilder.d.ts +14 -0
- package/lib/cjs/queries/ProxiedPathBuilder.js +29 -0
- package/lib/cjs/queries/ProxiedPathBuilder.js.map +1 -0
- package/lib/cjs/queries/QueryBuilder.d.ts +141 -0
- package/lib/cjs/queries/QueryBuilder.js +334 -0
- package/lib/cjs/queries/QueryBuilder.js.map +1 -0
- package/lib/cjs/queries/SelectQuery.d.ts +60 -134
- package/lib/cjs/queries/SelectQuery.js +67 -526
- package/lib/cjs/queries/SelectQuery.js.map +1 -1
- package/lib/cjs/queries/UpdateBuilder.d.ts +37 -0
- package/lib/cjs/queries/UpdateBuilder.js +84 -0
- package/lib/cjs/queries/UpdateBuilder.js.map +1 -0
- package/lib/cjs/queries/UpdateQuery.d.ts +3 -3
- package/lib/cjs/queries/UpdateQuery.js.map +1 -1
- package/lib/cjs/queries/WhereCondition.d.ts +18 -0
- package/lib/cjs/queries/WhereCondition.js +3 -0
- package/lib/cjs/queries/WhereCondition.js.map +1 -0
- package/lib/cjs/queries/resolveShape.d.ts +10 -0
- package/lib/cjs/queries/resolveShape.js +23 -0
- package/lib/cjs/queries/resolveShape.js.map +1 -0
- package/lib/cjs/shapes/SHACL.js +7 -5
- package/lib/cjs/shapes/SHACL.js.map +1 -1
- package/lib/cjs/shapes/Shape.d.ts +33 -52
- package/lib/cjs/shapes/Shape.js +36 -56
- package/lib/cjs/shapes/Shape.js.map +1 -1
- package/lib/cjs/sparql/SparqlAlgebra.d.ts +6 -1
- package/lib/cjs/sparql/algebraToString.js +10 -0
- package/lib/cjs/sparql/algebraToString.js.map +1 -1
- package/lib/cjs/sparql/irToAlgebra.js +6 -2
- package/lib/cjs/sparql/irToAlgebra.js.map +1 -1
- package/lib/cjs/test-helpers/query-fixtures.d.ts +568 -3049
- package/lib/cjs/test-helpers/query-fixtures.js +59 -18
- package/lib/cjs/test-helpers/query-fixtures.js.map +1 -1
- package/lib/cjs/test-helpers/test-utils.d.ts +18 -0
- package/lib/cjs/test-helpers/test-utils.js +47 -0
- package/lib/cjs/test-helpers/test-utils.js.map +1 -0
- package/lib/cjs/utils/Package.d.ts +8 -8
- package/lib/cjs/utils/Package.js.map +1 -1
- package/lib/cjs/utils/ShapeClass.d.ts +2 -2
- package/lib/cjs/utils/ShapeClass.js +4 -22
- package/lib/cjs/utils/ShapeClass.js.map +1 -1
- package/lib/esm/index.d.ts +10 -2
- package/lib/esm/index.js +23 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/package.d.ts +1 -1
- package/lib/esm/queries/CreateBuilder.d.ts +38 -0
- package/lib/esm/queries/CreateBuilder.js +96 -0
- package/lib/esm/queries/CreateBuilder.js.map +1 -0
- package/lib/esm/queries/CreateQuery.d.ts +3 -3
- package/lib/esm/queries/CreateQuery.js.map +1 -1
- package/lib/esm/queries/DeleteBuilder.d.ts +39 -0
- package/lib/esm/queries/DeleteBuilder.js +81 -0
- package/lib/esm/queries/DeleteBuilder.js.map +1 -0
- package/lib/esm/queries/DeleteQuery.d.ts +3 -3
- package/lib/esm/queries/DeleteQuery.js.map +1 -1
- package/lib/esm/queries/FieldSet.d.ts +203 -0
- package/lib/esm/queries/FieldSet.js +529 -0
- package/lib/esm/queries/FieldSet.js.map +1 -0
- package/lib/esm/queries/IRDesugar.d.ts +13 -8
- package/lib/esm/queries/IRDesugar.js +143 -132
- package/lib/esm/queries/IRDesugar.js.map +1 -1
- package/lib/esm/queries/IRLower.js +1 -0
- package/lib/esm/queries/IRLower.js.map +1 -1
- package/lib/esm/queries/IntermediateRepresentation.d.ts +1 -0
- package/lib/esm/queries/MutationQuery.d.ts +1 -1
- package/lib/esm/queries/MutationQuery.js +1 -6
- package/lib/esm/queries/MutationQuery.js.map +1 -1
- package/lib/esm/queries/PropertyPath.d.ts +38 -0
- package/lib/esm/queries/PropertyPath.js +77 -0
- package/lib/esm/queries/PropertyPath.js.map +1 -0
- package/lib/esm/queries/ProxiedPathBuilder.d.ts +14 -0
- package/lib/esm/queries/ProxiedPathBuilder.js +26 -0
- package/lib/esm/queries/ProxiedPathBuilder.js.map +1 -0
- package/lib/esm/queries/QueryBuilder.d.ts +141 -0
- package/lib/esm/queries/QueryBuilder.js +330 -0
- package/lib/esm/queries/QueryBuilder.js.map +1 -0
- package/lib/esm/queries/SelectQuery.d.ts +60 -134
- package/lib/esm/queries/SelectQuery.js +61 -515
- package/lib/esm/queries/SelectQuery.js.map +1 -1
- package/lib/esm/queries/UpdateBuilder.d.ts +37 -0
- package/lib/esm/queries/UpdateBuilder.js +80 -0
- package/lib/esm/queries/UpdateBuilder.js.map +1 -0
- package/lib/esm/queries/UpdateQuery.d.ts +3 -3
- package/lib/esm/queries/UpdateQuery.js.map +1 -1
- package/lib/esm/queries/WhereCondition.d.ts +18 -0
- package/lib/esm/queries/WhereCondition.js +2 -0
- package/lib/esm/queries/WhereCondition.js.map +1 -0
- package/lib/esm/queries/resolveShape.d.ts +10 -0
- package/lib/esm/queries/resolveShape.js +20 -0
- package/lib/esm/queries/resolveShape.js.map +1 -0
- package/lib/esm/shapes/SHACL.js +7 -5
- package/lib/esm/shapes/SHACL.js.map +1 -1
- package/lib/esm/shapes/Shape.d.ts +33 -52
- package/lib/esm/shapes/Shape.js +36 -53
- package/lib/esm/shapes/Shape.js.map +1 -1
- package/lib/esm/sparql/SparqlAlgebra.d.ts +6 -1
- package/lib/esm/sparql/algebraToString.js +10 -0
- package/lib/esm/sparql/algebraToString.js.map +1 -1
- package/lib/esm/sparql/irToAlgebra.js +6 -2
- package/lib/esm/sparql/irToAlgebra.js.map +1 -1
- package/lib/esm/test-helpers/query-fixtures.d.ts +568 -3049
- package/lib/esm/test-helpers/query-fixtures.js +59 -18
- package/lib/esm/test-helpers/query-fixtures.js.map +1 -1
- package/lib/esm/test-helpers/test-utils.d.ts +18 -0
- package/lib/esm/test-helpers/test-utils.js +41 -0
- package/lib/esm/test-helpers/test-utils.js.map +1 -0
- package/lib/esm/utils/Package.d.ts +8 -8
- package/lib/esm/utils/Package.js.map +1 -1
- package/lib/esm/utils/ShapeClass.d.ts +2 -2
- package/lib/esm/utils/ShapeClass.js +4 -22
- package/lib/esm/utils/ShapeClass.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,27 +1,122 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0
|
|
4
4
|
|
|
5
|
-
###
|
|
5
|
+
### Major Changes
|
|
6
6
|
|
|
7
|
-
- [#
|
|
7
|
+
- [#23](https://github.com/Semantu/linked/pull/23) [`d2d1eca`](https://github.com/Semantu/linked/commit/d2d1eca3517af11f39348dc83ba5e60703ef86d2) Thanks [@flyon](https://github.com/flyon)! - ## Breaking Changes
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### `Shape.select()` and `Shape.update()` no longer accept an ID as the first argument
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Use `.for(id)` to target a specific entity instead.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
**Select:**
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
```typescript
|
|
16
|
+
// Before
|
|
17
|
+
const result = await Person.select({ id: "..." }, (p) => p.name);
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
// After
|
|
20
|
+
const result = await Person.select((p) => p.name).for({ id: "..." });
|
|
21
|
+
```
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
`.for(id)` unwraps the result type from array to single object, matching the old single-subject overload behavior.
|
|
24
|
+
|
|
25
|
+
**Update:**
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
// Before
|
|
29
|
+
const result = await Person.update({ id: "..." }, { name: "Alice" });
|
|
30
|
+
|
|
31
|
+
// After
|
|
32
|
+
const result = await Person.update({ name: "Alice" }).for({ id: "..." });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`Shape.selectAll(id)` also no longer accepts an id — use `Person.selectAll().for(id)`.
|
|
36
|
+
|
|
37
|
+
### `ShapeType` renamed to `ShapeConstructor`
|
|
38
|
+
|
|
39
|
+
The type alias for concrete Shape subclass constructors has been renamed. Update any imports or references:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
// Before
|
|
43
|
+
import type { ShapeType } from "@_linked/core/shapes/Shape";
|
|
44
|
+
|
|
45
|
+
// After
|
|
46
|
+
import type { ShapeConstructor } from "@_linked/core/shapes/Shape";
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### `QueryString`, `QueryNumber`, `QueryBoolean`, `QueryDate` classes removed
|
|
50
|
+
|
|
51
|
+
These have been consolidated into a single generic `QueryPrimitive<T>` class. If you were using `instanceof` checks against these classes, use `instanceof QueryPrimitive` instead and check the value's type.
|
|
52
|
+
|
|
53
|
+
### Internal IR types removed
|
|
54
|
+
|
|
55
|
+
The following types and functions have been removed from `SelectQuery`. These were internal pipeline types — if you were using them for custom store integrations, the replacement is `FieldSetEntry[]` (available from `FieldSet`):
|
|
56
|
+
|
|
57
|
+
- Types: `SelectPath`, `QueryPath`, `CustomQueryObject`, `SubQueryPaths`, `ComponentQueryPath`
|
|
58
|
+
- Functions: `fieldSetToSelectPath()`, `entryToQueryPath()`
|
|
59
|
+
- Methods: `QueryBuilder.getQueryPaths()`, `BoundComponent.getComponentQueryPaths()`
|
|
60
|
+
- `RawSelectInput.select` field renamed to `RawSelectInput.entries` (type changed from `SelectPath` to `FieldSetEntry[]`)
|
|
61
|
+
|
|
62
|
+
### `getPackageShape()` return type is now nullable
|
|
63
|
+
|
|
64
|
+
Returns `ShapeConstructor | undefined` instead of `typeof Shape`. Code that didn't null-check the return value will now get TypeScript errors.
|
|
65
|
+
|
|
66
|
+
## New Features
|
|
67
|
+
|
|
68
|
+
### `.for(id)` and `.forAll(ids)` chaining
|
|
69
|
+
|
|
70
|
+
Consistent API for targeting entities across select and update operations:
|
|
20
71
|
|
|
21
|
-
|
|
72
|
+
```typescript
|
|
73
|
+
// Single entity (result is unwrapped, not an array)
|
|
74
|
+
await Person.select((p) => p.name).for({ id: "..." });
|
|
75
|
+
await Person.select((p) => p.name).for("https://...");
|
|
76
|
+
|
|
77
|
+
// Multiple specific entities
|
|
78
|
+
await QueryBuilder.from(Person)
|
|
79
|
+
.select((p) => p.name)
|
|
80
|
+
.forAll([{ id: "..." }, { id: "..." }]);
|
|
81
|
+
|
|
82
|
+
// All instances (default — no .for() needed)
|
|
83
|
+
await Person.select((p) => p.name);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Dynamic Query Building with `QueryBuilder` and `FieldSet`
|
|
87
|
+
|
|
88
|
+
Build queries programmatically at runtime — for CMS dashboards, API endpoints, configurable reports. See the [Dynamic Query Building](./README.md#dynamic-query-building) section in the README for full documentation and examples.
|
|
89
|
+
|
|
90
|
+
Key capabilities:
|
|
91
|
+
|
|
92
|
+
- `QueryBuilder.from(Person)` or `QueryBuilder.from('https://schema.org/Person')` — fluent, chainable, immutable query construction
|
|
93
|
+
- `FieldSet.for(Person, ['name', 'knows'])` — composable field selections with `.add()`, `.remove()`, `.pick()`, `FieldSet.merge()`
|
|
94
|
+
- `FieldSet.all(Person, {depth: 2})` — select all decorated properties with optional depth
|
|
95
|
+
- JSON serialization: `query.toJSON()` / `QueryBuilder.fromJSON(json)` and `fieldSet.toJSON()` / `FieldSet.fromJSON(json)`
|
|
96
|
+
- All builders are `PromiseLike` — `await` them directly or call `.build()` to inspect the IR
|
|
97
|
+
|
|
98
|
+
### Mutation Builders
|
|
99
|
+
|
|
100
|
+
`CreateBuilder`, `UpdateBuilder`, and `DeleteBuilder` provide the programmatic equivalent of `Person.create()`, `Person.update()`, and `Person.delete()`, accepting Shape classes or shape IRI strings. See the [Mutation Builders](./README.md#mutation-builders) section in the README.
|
|
101
|
+
|
|
102
|
+
### `PropertyPath` exported
|
|
103
|
+
|
|
104
|
+
The `PropertyPath` value object is now a public export — a type-safe representation of a sequence of property traversals through a shape graph.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { PropertyPath, walkPropertyPath } from "@_linked/core";
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### `ShapeConstructor<S>` type
|
|
111
|
+
|
|
112
|
+
New concrete constructor type for Shape subclasses. Eliminates ~30 `as any` casts across the codebase and provides better type safety at runtime boundaries (builder `.from()` methods, Shape static methods).
|
|
22
113
|
|
|
23
114
|
### Minor Changes
|
|
24
115
|
|
|
116
|
+
- [#20](https://github.com/Semantu/linked/pull/20) [`33e9fb0`](https://github.com/Semantu/linked/commit/33e9fb0205343eca8c84723cbabc3f3342e40be5) Thanks [@flyon](https://github.com/flyon)! - **Breaking:** `QueryParser` has been removed. If you imported `QueryParser` directly, replace with `getQueryDispatch()` from `@_linked/core/queries/queryDispatch`. The Shape DSL (`Shape.select()`, `.create()`, `.update()`, `.delete()`) and `SelectQuery.exec()` are unchanged.
|
|
117
|
+
|
|
118
|
+
**New:** `getQueryDispatch()` and `setQueryDispatch()` are now exported, allowing custom query dispatch implementations (e.g. for testing or alternative storage backends) without subclassing `LinkedStorage`.
|
|
119
|
+
|
|
25
120
|
- [#9](https://github.com/Semantu/linked/pull/9) [`381067b`](https://github.com/Semantu/linked/commit/381067b0fbc25f4a0446c5f8cc0eec57ddded466) Thanks [@flyon](https://github.com/flyon)! - Replaced internal query representation with a canonical backend-agnostic IR AST. `SelectQuery`, `CreateQuery`, `UpdateQuery`, and `DeleteQuery` are now typed IR objects with `kind` discriminators, compact shape/property ID references, and expression trees — replacing the previous ad-hoc nested arrays. The public Shape DSL is unchanged; what changed is what `IQuadStore` implementations receive. Store result types (`ResultRow`, `SelectResult`, `CreateResult`, `UpdateResult`) are now exported. All factories expose `build()` as the primary method. See `documentation/intermediate-representation.md` for the full IR reference and migration guidance.
|
|
26
121
|
|
|
27
122
|
- [#14](https://github.com/Semantu/linked/pull/14) [`b65e156`](https://github.com/Semantu/linked/commit/b65e15688ac173478e58e1dbb9f26dbaf5fc5a37) Thanks [@flyon](https://github.com/flyon)! - Add SPARQL conversion layer — compiles Linked IR queries into executable SPARQL and maps results back to typed DSL objects.
|
|
@@ -78,6 +173,14 @@
|
|
|
78
173
|
|
|
79
174
|
See [SPARQL Algebra Layer docs](./documentation/sparql-algebra.md) for the full type reference, conversion rules, and store implementation guide.
|
|
80
175
|
|
|
176
|
+
### Patch Changes
|
|
177
|
+
|
|
178
|
+
- [#17](https://github.com/Semantu/linked/pull/17) [`0654780`](https://github.com/Semantu/linked/commit/06547807a7bae56e992eba73263f83e092b7788b) Thanks [@flyon](https://github.com/flyon)! - Preserve nested array sub-select branches in canonical IR so `build()` emits complete traversals, projection fields, and `resultMap` entries for nested selections.
|
|
179
|
+
|
|
180
|
+
This fixes cases where nested branches present in `toRawInput().select` were dropped during desugar/lowering (for example nested `friends.select([name, hobby])` branches under another sub-select).
|
|
181
|
+
|
|
182
|
+
Also adds regression coverage for desugar preservation, IR lowering completeness, and updated SPARQL golden output for nested query fixtures.
|
|
183
|
+
|
|
81
184
|
## 1.1.0
|
|
82
185
|
|
|
83
186
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ Linked core gives you a type-safe, schema-parameterized query language and SHACL
|
|
|
7
7
|
|
|
8
8
|
- **Schema-Parameterized Query DSL**: TypeScript-embedded queries driven by your Shape definitions.
|
|
9
9
|
- **Fully Inferred Result Types**: The TypeScript return type of every query is automatically inferred from the selected paths — no manual type annotations needed. Select `p.name` and get `{id: string; name: string}[]`. Select `p.friends.name` and get nested result types. This works for all operations: select, create, update, and delete.
|
|
10
|
+
- **Dynamic Query Building**: Build queries programmatically with `QueryBuilder`, compose field selections with `FieldSet`, and serialize/deserialize queries as JSON — for CMS dashboards, dynamic forms, and API-driven query construction.
|
|
10
11
|
- **Shape Classes (SHACL)**: TypeScript classes that generate SHACL shape metadata.
|
|
11
12
|
- **Object-Oriented Data Operations**: Query, create, update, and delete data using the same Shape-based API.
|
|
12
13
|
- **Storage Routing**: `LinkedStorage` routes query objects to your configured store(s) that implement `IQuadStore`.
|
|
@@ -245,10 +246,9 @@ const allFriends = await Person.select((p) => p.knows.selectAll());
|
|
|
245
246
|
|
|
246
247
|
**3) Apply a simple mutation**
|
|
247
248
|
```typescript
|
|
248
|
-
const
|
|
249
|
-
const updated = await Person.update(myNode, {
|
|
249
|
+
const updated = await Person.update({
|
|
250
250
|
name: 'Alicia',
|
|
251
|
-
});
|
|
251
|
+
}).for({id: 'https://my.app/node1'});
|
|
252
252
|
/* updated: {id: string} & UpdatePartial<Person> */
|
|
253
253
|
```
|
|
254
254
|
|
|
@@ -295,6 +295,10 @@ The query DSL is schema-parameterized: you define your own SHACL shapes, and Lin
|
|
|
295
295
|
- Query context variables
|
|
296
296
|
- Preloading (`preloadFor`) for component-like queries
|
|
297
297
|
- Create / Update / Delete mutations
|
|
298
|
+
- Dynamic query building with `QueryBuilder`
|
|
299
|
+
- Composable field sets with `FieldSet`
|
|
300
|
+
- Mutation builders (`CreateBuilder`, `UpdateBuilder`, `DeleteBuilder`)
|
|
301
|
+
- Query and FieldSet JSON serialization / deserialization
|
|
298
302
|
|
|
299
303
|
### Query examples
|
|
300
304
|
|
|
@@ -317,10 +321,9 @@ const flags = await Person.select((p) => p.isRealPerson);
|
|
|
317
321
|
|
|
318
322
|
#### Target a specific subject
|
|
319
323
|
```typescript
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const
|
|
323
|
-
const missing = await Person.select({id: 'https://my.app/missing'}, (p) => p.name); // null
|
|
324
|
+
/* Result: {id: string; name: string} */
|
|
325
|
+
const one = await Person.select((p) => p.name).for({id: 'https://my.app/node1'});
|
|
326
|
+
const missing = await Person.select((p) => p.name).for({id: 'https://my.app/missing'}); // null
|
|
324
327
|
```
|
|
325
328
|
|
|
326
329
|
#### Multiple paths + nested paths
|
|
@@ -444,10 +447,10 @@ Where UpdatePartial<Shape> reflects the created properties.
|
|
|
444
447
|
|
|
445
448
|
#### Update
|
|
446
449
|
|
|
447
|
-
Update will patch any property that you send as payload and leave the rest untouched.
|
|
450
|
+
Update will patch any property that you send as payload and leave the rest untouched. Chain `.for(id)` to target the entity:
|
|
448
451
|
```typescript
|
|
449
452
|
/* Result: {id: string} & UpdatePartial<Person> */
|
|
450
|
-
const updated = await Person.update({id: 'https://my.app/node1'}
|
|
453
|
+
const updated = await Person.update({name: 'Alicia'}).for({id: 'https://my.app/node1'});
|
|
451
454
|
```
|
|
452
455
|
Returns:
|
|
453
456
|
```json
|
|
@@ -463,9 +466,9 @@ When updating a property that holds multiple values (one that returns an array i
|
|
|
463
466
|
To overwrite all values:
|
|
464
467
|
```typescript
|
|
465
468
|
// Overwrite the full set of "knows" values.
|
|
466
|
-
const overwriteFriends = await Person.update({
|
|
469
|
+
const overwriteFriends = await Person.update({
|
|
467
470
|
knows: [{id: 'https://my.app/person2'}],
|
|
468
|
-
});
|
|
471
|
+
}).for({id: 'https://my.app/person1'});
|
|
469
472
|
```
|
|
470
473
|
The result will contain an object with `updatedTo`, to indicate that previous values were overwritten to this new set of values:
|
|
471
474
|
```json
|
|
@@ -475,17 +478,17 @@ The result will contain an object with `updatedTo`, to indicate that previous va
|
|
|
475
478
|
updatedTo: [{id:"https://my.app/person2"}],
|
|
476
479
|
}
|
|
477
480
|
}
|
|
478
|
-
```
|
|
481
|
+
```
|
|
479
482
|
|
|
480
483
|
To make incremental changes to the current set of values you can provide an object with `add` and/or `remove` keys:
|
|
481
484
|
```typescript
|
|
482
485
|
// Add one value and remove one value without replacing the whole set.
|
|
483
|
-
const addRemoveFriends = await Person.update({
|
|
486
|
+
const addRemoveFriends = await Person.update({
|
|
484
487
|
knows: {
|
|
485
488
|
add: [{id: 'https://my.app/person2'}],
|
|
486
489
|
remove: [{id: 'https://my.app/person3'}],
|
|
487
490
|
},
|
|
488
|
-
});
|
|
491
|
+
}).for({id: 'https://my.app/person1'});
|
|
489
492
|
```
|
|
490
493
|
This returns an object with the added and removed items
|
|
491
494
|
```json
|
|
@@ -559,6 +562,198 @@ Override behavior:
|
|
|
559
562
|
- If an override omits `minCount`, `maxCount`, or `nodeKind`, inherited values are kept.
|
|
560
563
|
- Current scope: compatibility checks for `datatype`, `class`, and `pattern` are not enforced yet.
|
|
561
564
|
|
|
565
|
+
## Dynamic Query Building
|
|
566
|
+
|
|
567
|
+
The DSL (`Person.select(...)`) is ideal when you know shapes at compile time. For apps that need to build queries at runtime — CMS dashboards, configurable reports, API endpoints that accept field selections — use `QueryBuilder` and `FieldSet`.
|
|
568
|
+
|
|
569
|
+
### QueryBuilder
|
|
570
|
+
|
|
571
|
+
`QueryBuilder` provides a fluent, chainable API for constructing queries programmatically. It accepts a Shape class or a shape IRI string.
|
|
572
|
+
|
|
573
|
+
```typescript
|
|
574
|
+
import {QueryBuilder} from '@_linked/core';
|
|
575
|
+
|
|
576
|
+
// From a Shape class
|
|
577
|
+
const query = QueryBuilder.from(Person)
|
|
578
|
+
.select(p => [p.name, p.knows])
|
|
579
|
+
.where(p => p.name.equals('Semmy'))
|
|
580
|
+
.limit(10);
|
|
581
|
+
|
|
582
|
+
// From a shape IRI string (when the Shape class isn't available at compile time)
|
|
583
|
+
const query = QueryBuilder.from('https://schema.org/Person')
|
|
584
|
+
.select(['name', 'knows'])
|
|
585
|
+
.where(p => p.name.equals('Semmy'));
|
|
586
|
+
|
|
587
|
+
// QueryBuilder is PromiseLike — await it directly
|
|
588
|
+
const results = await query;
|
|
589
|
+
|
|
590
|
+
// Or inspect the compiled IR without executing
|
|
591
|
+
const ir = query.build();
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
**Target specific entities:**
|
|
595
|
+
```typescript
|
|
596
|
+
// Single entity — result is unwrapped (not an array)
|
|
597
|
+
const person = await QueryBuilder.from(Person)
|
|
598
|
+
.for({id: 'https://my.app/person1'})
|
|
599
|
+
.select(p => p.name);
|
|
600
|
+
|
|
601
|
+
// Multiple entities
|
|
602
|
+
const people = await QueryBuilder.from(Person)
|
|
603
|
+
.forAll([{id: 'https://my.app/p1'}, {id: 'https://my.app/p2'}])
|
|
604
|
+
.select(p => p.name);
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
**Sorting, limiting, and single results:**
|
|
608
|
+
```typescript
|
|
609
|
+
const topFive = await QueryBuilder.from(Person)
|
|
610
|
+
.select(p => p.name)
|
|
611
|
+
.orderBy(p => p.name, 'ASC')
|
|
612
|
+
.limit(5);
|
|
613
|
+
|
|
614
|
+
const first = await QueryBuilder.from(Person)
|
|
615
|
+
.select(p => p.name)
|
|
616
|
+
.one();
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
**Select with a FieldSet:**
|
|
620
|
+
```typescript
|
|
621
|
+
const fields = FieldSet.for(Person, ['name', 'knows']);
|
|
622
|
+
const results = await QueryBuilder.from(Person).select(fields);
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
### FieldSet — composable field selections
|
|
626
|
+
|
|
627
|
+
`FieldSet` is an independent, reusable object that describes which fields to select from a shape. Create them, compose them, and feed them into queries.
|
|
628
|
+
|
|
629
|
+
**Creating a FieldSet:**
|
|
630
|
+
```typescript
|
|
631
|
+
import {FieldSet} from '@_linked/core';
|
|
632
|
+
|
|
633
|
+
// From a Shape class with string field names
|
|
634
|
+
const fs = FieldSet.for(Person, ['name', 'knows']);
|
|
635
|
+
|
|
636
|
+
// From a Shape class with a type-safe callback
|
|
637
|
+
const fs = FieldSet.for(Person, p => [p.name, p.knows]);
|
|
638
|
+
|
|
639
|
+
// From a shape IRI string (when you only have the shape's IRI)
|
|
640
|
+
const fs = FieldSet.for('https://schema.org/Person', ['name', 'knows']);
|
|
641
|
+
|
|
642
|
+
// Select all decorated properties
|
|
643
|
+
const allFields = FieldSet.all(Person);
|
|
644
|
+
|
|
645
|
+
// Select all properties with depth (includes nested shapes)
|
|
646
|
+
const deep = FieldSet.all(Person, {depth: 2});
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
**Nested fields:**
|
|
650
|
+
```typescript
|
|
651
|
+
// Dot-separated paths for nested properties
|
|
652
|
+
const fs = FieldSet.for(Person, ['name', 'knows.name']);
|
|
653
|
+
|
|
654
|
+
// Object form for nested sub-selections
|
|
655
|
+
const fs = FieldSet.for(Person, [{knows: ['name', 'hobby']}]);
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
**Composing FieldSets:**
|
|
659
|
+
```typescript
|
|
660
|
+
const base = FieldSet.for(Person, ['name']);
|
|
661
|
+
|
|
662
|
+
// Add fields
|
|
663
|
+
const extended = base.add(['knows', 'birthDate']);
|
|
664
|
+
|
|
665
|
+
// Remove fields
|
|
666
|
+
const minimal = extended.remove(['birthDate']);
|
|
667
|
+
|
|
668
|
+
// Pick specific fields
|
|
669
|
+
const picked = extended.pick(['name', 'knows']);
|
|
670
|
+
|
|
671
|
+
// Merge multiple FieldSets
|
|
672
|
+
const merged = FieldSet.merge([fieldSet1, fieldSet2]);
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
**Inspecting a FieldSet:**
|
|
676
|
+
```typescript
|
|
677
|
+
const fs = FieldSet.for(Person, ['name', 'knows']);
|
|
678
|
+
fs.labels(); // ['name', 'knows']
|
|
679
|
+
fs.paths(); // [PropertyPath, PropertyPath]
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
**Use cases:**
|
|
683
|
+
|
|
684
|
+
```typescript
|
|
685
|
+
// Dynamically selected fields from a UI
|
|
686
|
+
const fields = FieldSet.for(Person, userSelectedFields);
|
|
687
|
+
const results = await QueryBuilder.from(Person).select(fields);
|
|
688
|
+
|
|
689
|
+
// API gateway: accept fields as query parameters
|
|
690
|
+
const fields = FieldSet.for(Person, req.query.fields.split(','));
|
|
691
|
+
const results = await QueryBuilder.from(Person).select(fields);
|
|
692
|
+
|
|
693
|
+
// Component composition: merge field sets from child components
|
|
694
|
+
const merged = FieldSet.merge([headerFields, sidebarFields, contentFields]);
|
|
695
|
+
const results = await QueryBuilder.from(Person).select(merged);
|
|
696
|
+
|
|
697
|
+
// Progressive loading: start minimal, add detail on demand
|
|
698
|
+
const summary = FieldSet.for(Person, ['name']);
|
|
699
|
+
const detail = summary.add(['email', 'knows', 'birthDate']);
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
### Mutation Builders
|
|
703
|
+
|
|
704
|
+
The mutation builders are the programmatic equivalent of `Person.create(...)`, `Person.update(...)`, and `Person.delete(...)`. They accept Shape classes or shape IRI strings.
|
|
705
|
+
|
|
706
|
+
```typescript
|
|
707
|
+
import {CreateBuilder, UpdateBuilder, DeleteBuilder} from '@_linked/core';
|
|
708
|
+
|
|
709
|
+
// Create — equivalent to Person.create({name: 'Alice'})
|
|
710
|
+
const created = await CreateBuilder.from(Person)
|
|
711
|
+
.set({name: 'Alice'})
|
|
712
|
+
.withId('https://my.app/alice');
|
|
713
|
+
|
|
714
|
+
// Update — equivalent to Person.update({name: 'Alicia'}).for({id: '...'})
|
|
715
|
+
const updated = await UpdateBuilder.from(Person)
|
|
716
|
+
.for({id: 'https://my.app/alice'})
|
|
717
|
+
.set({name: 'Alicia'});
|
|
718
|
+
|
|
719
|
+
// Delete — equivalent to Person.delete({id: '...'})
|
|
720
|
+
const deleted = await DeleteBuilder.from(Person).for({id: 'https://my.app/alice'});
|
|
721
|
+
|
|
722
|
+
// All builders are PromiseLike — await them or call .build() for the IR
|
|
723
|
+
const ir = CreateBuilder.from(Person).set({name: 'Alice'}).build();
|
|
724
|
+
```
|
|
725
|
+
|
|
726
|
+
### JSON Serialization
|
|
727
|
+
|
|
728
|
+
Queries and FieldSets can be serialized to JSON and reconstructed — useful for saving query configurations, sending them over the wire, or building query editor UIs.
|
|
729
|
+
|
|
730
|
+
```typescript
|
|
731
|
+
// Serialize a QueryBuilder
|
|
732
|
+
const query = QueryBuilder.from(Person)
|
|
733
|
+
.select(p => [p.name, p.knows])
|
|
734
|
+
.where(p => p.name.equals('Semmy'));
|
|
735
|
+
|
|
736
|
+
const json = query.toJSON();
|
|
737
|
+
// json is a plain object — store it, send it, etc.
|
|
738
|
+
|
|
739
|
+
// Reconstruct from JSON
|
|
740
|
+
const restored = QueryBuilder.fromJSON(json);
|
|
741
|
+
const results = await restored;
|
|
742
|
+
|
|
743
|
+
// FieldSet serialization works the same way
|
|
744
|
+
const fs = FieldSet.for(Person, ['name', 'knows']);
|
|
745
|
+
const fsJson = fs.toJSON();
|
|
746
|
+
const restoredFs = FieldSet.fromJSON(fsJson);
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
Example JSON output for `QueryBuilder.from(Person).select(p => p.name).toJSON()`:
|
|
750
|
+
```json
|
|
751
|
+
{
|
|
752
|
+
"shape": "https://schema.org/Person",
|
|
753
|
+
"fields": [{"path": "name"}]
|
|
754
|
+
}
|
|
755
|
+
```
|
|
756
|
+
|
|
562
757
|
## TODO
|
|
563
758
|
|
|
564
759
|
- Allow `preloadFor` to accept another query (not just a component).
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
export { QueryBuilder } from './queries/QueryBuilder.js';
|
|
2
|
+
export { PropertyPath, walkPropertyPath } from './queries/PropertyPath.js';
|
|
3
|
+
export type { WhereCondition, WhereOperator } from './queries/WhereCondition.js';
|
|
4
|
+
export { FieldSet } from './queries/FieldSet.js';
|
|
5
|
+
export type { FieldSetEntry, FieldSetInput, FieldSetJSON, FieldSetFieldJSON } from './queries/FieldSet.js';
|
|
6
|
+
export type { QueryBuilderJSON } from './queries/QueryBuilder.js';
|
|
7
|
+
export { CreateBuilder } from './queries/CreateBuilder.js';
|
|
8
|
+
export { UpdateBuilder } from './queries/UpdateBuilder.js';
|
|
9
|
+
export { DeleteBuilder } from './queries/DeleteBuilder.js';
|
|
10
|
+
export type { LinkedComponentInterface, QueryComponentLike } from './queries/SelectQuery.js';
|
|
3
11
|
export declare function initModularApp(): void;
|
package/lib/cjs/index.js
CHANGED
|
@@ -32,11 +32,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
36
|
+
exports.DeleteBuilder = exports.UpdateBuilder = exports.CreateBuilder = exports.FieldSet = exports.walkPropertyPath = exports.PropertyPath = exports.QueryBuilder = void 0;
|
|
40
37
|
exports.initModularApp = initModularApp;
|
|
41
38
|
/*
|
|
42
39
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
@@ -77,8 +74,29 @@ const lincd = __importStar(require("./ontologies/lincd.js"));
|
|
|
77
74
|
const owl = __importStar(require("./ontologies/owl.js"));
|
|
78
75
|
const npm = __importStar(require("./ontologies/npm.js"));
|
|
79
76
|
const Sparql = __importStar(require("./sparql/index.js"));
|
|
80
|
-
const
|
|
81
|
-
|
|
77
|
+
const QueryBuilderModule = __importStar(require("./queries/QueryBuilder.js"));
|
|
78
|
+
const PropertyPathModule = __importStar(require("./queries/PropertyPath.js"));
|
|
79
|
+
const WhereConditionModule = __importStar(require("./queries/WhereCondition.js"));
|
|
80
|
+
const FieldSetModule = __importStar(require("./queries/FieldSet.js"));
|
|
81
|
+
const CreateBuilderModule = __importStar(require("./queries/CreateBuilder.js"));
|
|
82
|
+
const UpdateBuilderModule = __importStar(require("./queries/UpdateBuilder.js"));
|
|
83
|
+
const DeleteBuilderModule = __importStar(require("./queries/DeleteBuilder.js"));
|
|
84
|
+
// New dynamic query building API (Phase 2)
|
|
85
|
+
var QueryBuilder_js_1 = require("./queries/QueryBuilder.js");
|
|
86
|
+
Object.defineProperty(exports, "QueryBuilder", { enumerable: true, get: function () { return QueryBuilder_js_1.QueryBuilder; } });
|
|
87
|
+
var PropertyPath_js_1 = require("./queries/PropertyPath.js");
|
|
88
|
+
Object.defineProperty(exports, "PropertyPath", { enumerable: true, get: function () { return PropertyPath_js_1.PropertyPath; } });
|
|
89
|
+
Object.defineProperty(exports, "walkPropertyPath", { enumerable: true, get: function () { return PropertyPath_js_1.walkPropertyPath; } });
|
|
90
|
+
// Phase 3a — FieldSet
|
|
91
|
+
var FieldSet_js_1 = require("./queries/FieldSet.js");
|
|
92
|
+
Object.defineProperty(exports, "FieldSet", { enumerable: true, get: function () { return FieldSet_js_1.FieldSet; } });
|
|
93
|
+
// Phase 3b — Mutation builders
|
|
94
|
+
var CreateBuilder_js_1 = require("./queries/CreateBuilder.js");
|
|
95
|
+
Object.defineProperty(exports, "CreateBuilder", { enumerable: true, get: function () { return CreateBuilder_js_1.CreateBuilder; } });
|
|
96
|
+
var UpdateBuilder_js_1 = require("./queries/UpdateBuilder.js");
|
|
97
|
+
Object.defineProperty(exports, "UpdateBuilder", { enumerable: true, get: function () { return UpdateBuilder_js_1.UpdateBuilder; } });
|
|
98
|
+
var DeleteBuilder_js_1 = require("./queries/DeleteBuilder.js");
|
|
99
|
+
Object.defineProperty(exports, "DeleteBuilder", { enumerable: true, get: function () { return DeleteBuilder_js_1.DeleteBuilder; } });
|
|
82
100
|
function initModularApp() {
|
|
83
101
|
let publicFiles = {
|
|
84
102
|
Package,
|
|
@@ -115,6 +133,13 @@ function initModularApp() {
|
|
|
115
133
|
owl,
|
|
116
134
|
npm,
|
|
117
135
|
Sparql,
|
|
136
|
+
QueryBuilderModule,
|
|
137
|
+
PropertyPathModule,
|
|
138
|
+
WhereConditionModule,
|
|
139
|
+
FieldSetModule,
|
|
140
|
+
CreateBuilderModule,
|
|
141
|
+
UpdateBuilderModule,
|
|
142
|
+
DeleteBuilderModule,
|
|
118
143
|
};
|
|
119
144
|
var lincdExport = {};
|
|
120
145
|
for (let fileKey in publicFiles) {
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,wCAwDC;AA1HD;;;;GAIG;AACH,4DAA8C;AAC9C,kFAAoE;AACpE,gFAAkE;AAClE,wEAA0D;AAC1D,kEAAoD;AACpD,kEAAoD;AACpD,yDAA2C;AAC3C,+DAAiD;AACjD,oEAAsD;AACtD,0DAA4C;AAC5C,oDAAsC;AACtC,sEAAwD;AACxD,sEAAwD;AACxD,0EAA4D;AAC5D,sEAAwD;AACxD,sEAAwD;AACxD,0EAA4D;AAC5D,wEAA0D;AAC1D,oGAAsF;AACtF,gEAAkD;AAClD,kEAAoD;AACpD,0DAA4C;AAC5C,uDAAyC;AACzC,6EAA+D;AAC/D,uEAAyD;AACzD,uEAAyD;AACzD,yDAA2C;AAC3C,2DAA6C;AAC7C,yDAA2C;AAC3C,6DAA+C;AAC/C,6DAA+C;AAC/C,yDAA2C;AAC3C,yDAA2C;AAC3C,0DAA4C;AAC5C,8EAAgE;AAChE,8EAAgE;AAChE,kFAAoE;AACpE,sEAAwD;AACxD,gFAAkE;AAClE,gFAAkE;AAClE,gFAAkE;AAClE,2CAA2C;AAC3C,6DAAuD;AAA/C,+GAAA,YAAY,OAAA;AACpB,6DAAyE;AAAjE,+GAAA,YAAY,OAAA;AAAE,mHAAA,gBAAgB,OAAA;AAGtC,sBAAsB;AACtB,qDAA+C;AAAvC,uGAAA,QAAQ,OAAA;AAMhB,+BAA+B;AAC/B,+DAAyD;AAAjD,iHAAA,aAAa,OAAA;AACrB,+DAAyD;AAAjD,iHAAA,aAAa,OAAA;AACrB,+DAAyD;AAAjD,iHAAA,aAAa,OAAA;AAKrB,SAAgB,cAAc;IAC5B,IAAI,WAAW,GAAG;QAChB,OAAO;QACP,kBAAkB;QAClB,iBAAiB;QACjB,aAAa;QACb,OAAO;QACP,OAAO;QACP,KAAK;QACL,QAAQ;QACR,MAAM;QACN,SAAS;QACT,MAAM;QACN,GAAG;QACH,UAAU;QACV,IAAI;QACJ,aAAa;QACb,UAAU;QACV,UAAU;QACV,WAAW;QACX,WAAW;QACX,aAAa;QACb,WAAW;QACX,WAAW;QACX,aAAa;QACb,YAAY;QACZ,0BAA0B;QAC1B,WAAW;QACX,GAAG;QACH,IAAI;QACJ,GAAG;QACH,KAAK;QACL,KAAK;QACL,GAAG;QACH,GAAG;QACH,MAAM;QACN,kBAAkB;QAClB,kBAAkB;QAClB,oBAAoB;QACpB,cAAc;QACd,mBAAmB;QACnB,mBAAmB;QACnB,mBAAmB;KACpB,CAAC;IACF,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,KAAK,IAAI,OAAO,IAAI,WAAW,EAAE,CAAC;QAChC,IAAI,eAAe,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;QAC3C,KAAK,IAAI,SAAS,IAAI,eAAe,EAAE,CAAC;YACtC,WAAW,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC;IAC9C,CAAC;SAAM,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACzC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
|
package/lib/cjs/package.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const linkedShape: {
|
|
2
2
|
<T extends typeof import("./shapes/Shape.js").Shape>(constructor: T): void;
|
|
3
3
|
<T extends typeof import("./shapes/Shape.js").Shape>(config?: import("./utils/Package.js").ShapeConfig): (constructor: T) => void;
|
|
4
|
-
}, linkedUtil: (constructor: any) => any, linkedOntology: (allFileExports: any, nameSpace: (term: string) => import("./utils/NodeReference.js").NodeReferenceValue, suggestedPrefixAndFileName: string, loadDataFunction?: () => Promise<any>, dataSource?: string | string[]) => void, registerPackageExport: (exportedObject: any) => void, registerPackageModule: (_module: any) => void, packageExports: any, getPackageShape: (name: string) =>
|
|
4
|
+
}, linkedUtil: (constructor: any) => any, linkedOntology: (allFileExports: any, nameSpace: (term: string) => import("./utils/NodeReference.js").NodeReferenceValue, suggestedPrefixAndFileName: string, loadDataFunction?: () => Promise<any>, dataSource?: string | string[]) => void, registerPackageExport: (exportedObject: any) => void, registerPackageModule: (_module: any) => void, packageExports: any, getPackageShape: (name: string) => import("./shapes/Shape.js").ShapeConstructor | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Shape, ShapeConstructor } from '../shapes/Shape.js';
|
|
2
|
+
import { UpdatePartial } from './QueryFactory.js';
|
|
3
|
+
import { CreateQuery, CreateResponse } from './CreateQuery.js';
|
|
4
|
+
/**
|
|
5
|
+
* An immutable, fluent builder for create mutations.
|
|
6
|
+
*
|
|
7
|
+
* Every mutation method returns a new CreateBuilder — the original is never modified.
|
|
8
|
+
*
|
|
9
|
+
* Implements PromiseLike so mutations execute on `await`:
|
|
10
|
+
* ```ts
|
|
11
|
+
* const result = await CreateBuilder.from(Person).set({name: 'Alice'});
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Internally delegates to CreateQueryFactory for IR generation.
|
|
15
|
+
*/
|
|
16
|
+
export declare class CreateBuilder<S extends Shape = Shape, U extends UpdatePartial<S> = UpdatePartial<S>> implements PromiseLike<CreateResponse<U>>, Promise<CreateResponse<U>> {
|
|
17
|
+
private readonly _shape;
|
|
18
|
+
private readonly _data?;
|
|
19
|
+
private readonly _fixedId?;
|
|
20
|
+
private constructor();
|
|
21
|
+
private clone;
|
|
22
|
+
/**
|
|
23
|
+
* Create a CreateBuilder for the given shape.
|
|
24
|
+
*/
|
|
25
|
+
static from<S extends Shape>(shape: ShapeConstructor<S> | string): CreateBuilder<S>;
|
|
26
|
+
/** Set the data for the entity to create. */
|
|
27
|
+
set<NewU extends UpdatePartial<S>>(data: NewU): CreateBuilder<S, NewU>;
|
|
28
|
+
/** Pre-assign a node ID for the created entity. */
|
|
29
|
+
withId(id: string): CreateBuilder<S, U>;
|
|
30
|
+
/** Build the IR mutation. Throws if no data was set via .set(). */
|
|
31
|
+
build(): CreateQuery;
|
|
32
|
+
/** Execute the mutation. */
|
|
33
|
+
exec(): Promise<CreateResponse<U>>;
|
|
34
|
+
then<TResult1 = CreateResponse<U>, TResult2 = never>(onfulfilled?: ((value: CreateResponse<U>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
35
|
+
catch<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): Promise<CreateResponse<U> | TResult>;
|
|
36
|
+
finally(onfinally?: (() => void) | null): Promise<CreateResponse<U>>;
|
|
37
|
+
get [Symbol.toStringTag](): string;
|
|
38
|
+
}
|