@grafctory/keep-sparql 0.0.0-stage → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +115 -2
- package/dist/detail/decode.d.ts +40 -0
- package/dist/detail/decode.d.ts.map +1 -0
- package/dist/detail/decode.js +160 -0
- package/dist/detail/decode.js.map +1 -0
- package/dist/detail/encode.d.ts +45 -0
- package/dist/detail/encode.d.ts.map +1 -0
- package/dist/detail/encode.js +104 -0
- package/dist/detail/encode.js.map +1 -0
- package/dist/detail/index.d.ts +19 -0
- package/dist/detail/index.d.ts.map +1 -0
- package/dist/detail/index.js +61 -0
- package/dist/detail/index.js.map +1 -0
- package/dist/detail/schema.d.ts +86 -0
- package/dist/detail/schema.d.ts.map +1 -0
- package/dist/detail/schema.js +89 -0
- package/dist/detail/schema.js.map +1 -0
- package/dist/detect/encode.d.ts +23 -0
- package/dist/detect/encode.d.ts.map +1 -0
- package/dist/detect/encode.js +30 -0
- package/dist/detect/encode.js.map +1 -0
- package/dist/detect/index.d.ts +23 -0
- package/dist/detect/index.d.ts.map +1 -0
- package/dist/detect/index.js +37 -0
- package/dist/detect/index.js.map +1 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +158 -0
- package/dist/index.js.map +1 -0
- package/dist/modify/encode.d.ts +17 -0
- package/dist/modify/encode.d.ts.map +1 -0
- package/dist/modify/encode.js +233 -0
- package/dist/modify/encode.js.map +1 -0
- package/dist/modify/index.d.ts +21 -0
- package/dist/modify/index.d.ts.map +1 -0
- package/dist/modify/index.js +50 -0
- package/dist/modify/index.js.map +1 -0
- package/dist/patterns.d.ts +199 -0
- package/dist/patterns.d.ts.map +1 -0
- package/dist/patterns.js +321 -0
- package/dist/patterns.js.map +1 -0
- package/dist/select/decode.d.ts +20 -0
- package/dist/select/decode.d.ts.map +1 -0
- package/dist/select/decode.js +134 -0
- package/dist/select/decode.js.map +1 -0
- package/dist/select/encode.d.ts +86 -0
- package/dist/select/encode.d.ts.map +1 -0
- package/dist/select/encode.js +647 -0
- package/dist/select/encode.js.map +1 -0
- package/dist/select/index.d.ts +19 -0
- package/dist/select/index.d.ts.map +1 -0
- package/dist/select/index.js +62 -0
- package/dist/select/index.js.map +1 -0
- package/dist/select/schema.d.ts +75 -0
- package/dist/select/schema.d.ts.map +1 -0
- package/dist/select/schema.js +84 -0
- package/dist/select/schema.js.map +1 -0
- package/dist/spine.d.ts +167 -0
- package/dist/spine.d.ts.map +1 -0
- package/dist/spine.js +180 -0
- package/dist/spine.js.map +1 -0
- package/dist/terms.d.ts +116 -0
- package/dist/terms.d.ts.map +1 -0
- package/dist/terms.js +251 -0
- package/dist/terms.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025-2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { getFlakeEntries } from "@grafctory/keep-flake";
|
|
17
|
+
import { named } from "@grafctory/trio";
|
|
18
|
+
import { all, fragment, optional, select, term, union, values, where } from "@grafctory/wire-sparql/builder";
|
|
19
|
+
import { link, membership } from "../patterns.js";
|
|
20
|
+
import { column, entries as nested } from "./schema.js";
|
|
21
|
+
/**
|
|
22
|
+
* Encodes the batched `select` reading `entries` through one {@link Flake | detail plan}.
|
|
23
|
+
*
|
|
24
|
+
* @param scope The variable allocator shared with the decoder, keyed on the plan node behind each column
|
|
25
|
+
* @param entries The root entries to read, all sharing `flake`
|
|
26
|
+
* @param flake The detail plan the entries share
|
|
27
|
+
* @param schema The table schema of the plan, the columns to bind for each property it reads
|
|
28
|
+
*
|
|
29
|
+
* @returns The batched `select` query
|
|
30
|
+
*/
|
|
31
|
+
export function encode(scope, entries, flake, schema) {
|
|
32
|
+
const subject = scope.resolve(flake);
|
|
33
|
+
// bound inside every arm rather than once outside the union: a `values` joined to the union would leave
|
|
34
|
+
// the scalar arm's leading `optional` evaluated with the subject unbound, a full predicate scan per arm
|
|
35
|
+
const binding = values([subject], entries.map(entry => [term(named(entry))]));
|
|
36
|
+
return select(all(), where(union(...resource([], subject, getFlakeEntries(flake)))));
|
|
37
|
+
/**
|
|
38
|
+
* The arms reading the subtree at `anchor`: its `scalars` and its `composites`, each an independent arm of
|
|
39
|
+
* the enclosing `union`. Every arm is prefixed by `path`, the required edges reaching `anchor`: empty at the
|
|
40
|
+
* subject, a variant's membership-gated reach below it, so an arm returns rows only where that path exists.
|
|
41
|
+
*/
|
|
42
|
+
function resource(path, anchor, entries) {
|
|
43
|
+
return [
|
|
44
|
+
...scalars(path, anchor, entries),
|
|
45
|
+
...composites(path, anchor, entries)
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The single arm reading `anchor`'s scalar properties: `path` followed by the `optional` block of the plain
|
|
50
|
+
* single-valued subtree. The arm is emitted whenever it has clauses, so a bare `path` still binds the edges
|
|
51
|
+
* reaching `anchor` even if `anchor` has no scalar leaf, and a reached resource always surfaces its reference.
|
|
52
|
+
*/
|
|
53
|
+
function scalars(path, anchor, entries) {
|
|
54
|
+
return arm(...path, ...optionals(anchor, entries));
|
|
55
|
+
/**
|
|
56
|
+
* The `optional` clauses of the plain single-valued subtree at `anchor`, one per scalar branch wrapping
|
|
57
|
+
* its edge and nested descent. Composite branches (`dictionary` leaves, unions) are skipped here, since
|
|
58
|
+
* `composites` emits each of them as a standalone arm of the enclosing `union`, beside the scalar arm.
|
|
59
|
+
*/
|
|
60
|
+
function optionals(anchor, entries) {
|
|
61
|
+
return entries.flatMap(branch => scalar(branch).map(scalar => {
|
|
62
|
+
const target = column(scope, scalar);
|
|
63
|
+
return optional(link([anchor, scalar.node.entry, target]), ...optionals(target, nested(scalar)));
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The standalone composite arms under `anchor`, the complement of `scalars`: one arm per `dictionary` leaf
|
|
69
|
+
* and one per requested union variant (each with its own subtree and nested composites), recursing through
|
|
70
|
+
* plain nested resources. Each arm carries `path`, the required edges reaching `anchor`, so it returns rows
|
|
71
|
+
* only if that path exists and never surfaces a value under a resource the entry does not actually reach.
|
|
72
|
+
*/
|
|
73
|
+
function composites(path, anchor, entries) {
|
|
74
|
+
return entries.flatMap(branch => (schema.get(branch) ?? []).flatMap(composite => {
|
|
75
|
+
const target = column(scope, composite);
|
|
76
|
+
const reach = [...path, link([anchor, composite.node.entry, target])];
|
|
77
|
+
return isVariant(composite) ? resource([...reach, membership(target, composite.variant)], target, nested(composite))
|
|
78
|
+
: composite.form === "tagged" ? arm(...reach)
|
|
79
|
+
: composites(reach, target, nested(composite));
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The scalar column of a branch, the one `optionals` binds: a plain single-valued property, neither localised
|
|
84
|
+
* nor union-typed, which is read inside the scalar arm rather than through a composite arm of its own.
|
|
85
|
+
*/
|
|
86
|
+
function scalar(branch) {
|
|
87
|
+
return (schema.get(branch) ?? []).filter(column => column.form === "value" && !isVariant(column));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Checks whether a column binds one requested variant of a union-typed property, gated by its membership.
|
|
91
|
+
*/
|
|
92
|
+
function isVariant({ node }) {
|
|
93
|
+
return node.drain?.form === "union";
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* An arm wrapping the entry binding and `clauses`, or nothing when there are no clauses: a bare binding
|
|
97
|
+
* would return one empty row per entry, and an empty {@link fragment} would surface as a stray `{ }`
|
|
98
|
+
* branch matching everything once the enclosing {@link union} groups the arms.
|
|
99
|
+
*/
|
|
100
|
+
function arm(...clauses) {
|
|
101
|
+
return clauses.length > 0 ? [fragment(binding, ...clauses)] : [];
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/detail/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgCH,OAAO,EAA2B,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEjF,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAC7G,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAe,MAAM,EAAE,OAAO,IAAI,MAAM,EAAe,MAAM,aAAa,CAAC;AAGlF;;;;;;;;;GASG;AACH,MAAM,UAAU,MAAM,CACrB,KAAsB,EACtB,OAA6B,EAC7B,KAAY,EACZ,MAAc;IAGd,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAErC,wGAAwG;IACxG,wGAAwG;IAExG,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9E,OAAO,MAAM,CAAC,GAAG,EAA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,CAAC;AAEF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Broker, Deferred, Detail } from "@grafctory/keep/batching";
|
|
2
|
+
import type { RepositoryClient } from "@grafctory/wire-sparql";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a batch of detail requests through one shared `select` query.
|
|
5
|
+
*
|
|
6
|
+
* The batching layer hands over requests sharing a shape, a structurally equal model and a locale, planned once
|
|
7
|
+
* with {@link createFlake}, so all entries are read together. The query grows with the plan and linearly with the
|
|
8
|
+
* entries, never with their product. A plan reading no single-valued property runs no query. Its requests still
|
|
9
|
+
* resolve: `id` and `type` come from the entry and the shape, multi-valued properties from the select pass.
|
|
10
|
+
*
|
|
11
|
+
* @param batch The queued detail requests to resolve, sharing one plan
|
|
12
|
+
* @param client The repository the query runs against
|
|
13
|
+
* @param broker The channel forwarding multi-valued properties to the select pass
|
|
14
|
+
*
|
|
15
|
+
* @returns A promise settling once every request has been decoded or rejected, without waiting for the select
|
|
16
|
+
* requests materialising multi-valued properties, which run in a later batching round
|
|
17
|
+
*/
|
|
18
|
+
export declare function detail(batch: readonly Deferred<Detail>[], client: RepositoryClient, broker: Broker): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/detail/index.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAO/D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,EAAE,EAClC,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAwBf"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025-2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Detail-pass driver.
|
|
18
|
+
*
|
|
19
|
+
* Materialises every queued {@link Detail} request in a batch with a single `select` query against the repository.
|
|
20
|
+
* Single-valued properties are read from that query, while multi-valued properties are read off the collections
|
|
21
|
+
* the spine materialises through the {@link Broker}, the only channel between passes. The handler returns without
|
|
22
|
+
* waiting for those nested requests, so the select pass serves them in a later batching round of the same run.
|
|
23
|
+
*
|
|
24
|
+
* @module index
|
|
25
|
+
*/
|
|
26
|
+
import { createFlake } from "@grafctory/keep-flake";
|
|
27
|
+
import { read } from "../spine.js";
|
|
28
|
+
import { decode } from "./decode.js";
|
|
29
|
+
import { encode } from "./encode.js";
|
|
30
|
+
import { schema } from "./schema.js";
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a batch of detail requests through one shared `select` query.
|
|
33
|
+
*
|
|
34
|
+
* The batching layer hands over requests sharing a shape, a structurally equal model and a locale, planned once
|
|
35
|
+
* with {@link createFlake}, so all entries are read together. The query grows with the plan and linearly with the
|
|
36
|
+
* entries, never with their product. A plan reading no single-valued property runs no query. Its requests still
|
|
37
|
+
* resolve: `id` and `type` come from the entry and the shape, multi-valued properties from the select pass.
|
|
38
|
+
*
|
|
39
|
+
* @param batch The queued detail requests to resolve, sharing one plan
|
|
40
|
+
* @param client The repository the query runs against
|
|
41
|
+
* @param broker The channel forwarding multi-valued properties to the select pass
|
|
42
|
+
*
|
|
43
|
+
* @returns A promise settling once every request has been decoded or rejected, without waiting for the select
|
|
44
|
+
* requests materialising multi-valued properties, which run in a later batching round
|
|
45
|
+
*/
|
|
46
|
+
export function detail(batch, client, broker) {
|
|
47
|
+
const [{ request: { shape, model } }] = batch;
|
|
48
|
+
// the plan and its schema are derived once and handed to both sides, so they bind and read the same columns
|
|
49
|
+
const flake = createFlake(shape, model);
|
|
50
|
+
const columns = schema(flake);
|
|
51
|
+
return read(batch, client, broker, {
|
|
52
|
+
// a plan binding no column (only id/type or collection slots) runs no query: its requests still reach the
|
|
53
|
+
// decoder, which yields id/type inline and reads collections off the select pass
|
|
54
|
+
encode: scope => columns.size > 0
|
|
55
|
+
? encode(scope, batch.map(({ request }) => request.entry), flake, columns)
|
|
56
|
+
: undefined,
|
|
57
|
+
owner: scope => scope.resolve(flake),
|
|
58
|
+
decode: (scope, item, rows) => decode(scope, flake, columns, item, rows)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/detail/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;GASG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,MAAM,CACrB,KAAkC,EAClC,MAAwB,EACxB,MAAc;IAGd,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC;IAE9C,4GAA4G;IAE5G,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACxC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE9B,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;QAElC,0GAA0G;QAC1G,iFAAiF;QAEjF,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC;YAChC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC;YAC1E,CAAC,CAAC,SAAS;QAEZ,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAEpC,MAAM,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC;KAExE,CAAC,CAAC;AAEJ,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detail-pass table schema.
|
|
3
|
+
*
|
|
4
|
+
* The contract the detail encoder and decoder share: the columns the query binds for each single-valued property
|
|
5
|
+
* the plan reads, and the variable each column is bound to. The encoder binds exactly these columns, the decoder
|
|
6
|
+
* reads exactly them, so a property can neither go unbound nor be read off a column the query never bound. Derived
|
|
7
|
+
* once per batch from the {@link Flake | detail plan} and handed to both sides, it is the pass's own IR: it carries
|
|
8
|
+
* plan nodes and range variants as keys, never variables, which the shared {@link Scope} still allocates.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { Property } from "@grafctory/blue/resource";
|
|
13
|
+
import { type Shape } from "@grafctory/blue/value";
|
|
14
|
+
import type { Scope } from "@grafctory/core/scope";
|
|
15
|
+
import { type Branch, type Drain, type Flake } from "@grafctory/keep-flake";
|
|
16
|
+
import type { Variable } from "@grafctory/wire-sparql";
|
|
17
|
+
/**
|
|
18
|
+
* One bound column of a single-valued property: the terms it binds and how the decoder reads them.
|
|
19
|
+
*/
|
|
20
|
+
export type Column = {
|
|
21
|
+
/**
|
|
22
|
+
* The property branch the column belongs to.
|
|
23
|
+
*/
|
|
24
|
+
readonly node: Branch & {
|
|
25
|
+
readonly entry: Property;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The range variant the column binds: a requested variant of a union-typed property (§5.5), else the single
|
|
29
|
+
* variant of the property's range, under which the decoder reads the terms the column binds.
|
|
30
|
+
*/
|
|
31
|
+
readonly variant: Shape;
|
|
32
|
+
/**
|
|
33
|
+
* The retrieval requested for the column's variant: the variant's own placeholder under a union, else the
|
|
34
|
+
* branch drain, which tells a structural retrieval of a localised variant from its coalesced label (§5.4).
|
|
35
|
+
*/
|
|
36
|
+
readonly drain?: Drain;
|
|
37
|
+
/**
|
|
38
|
+
* How the column is read:
|
|
39
|
+
*
|
|
40
|
+
* - **tagged** — the language-tagged terms of a localised variant, one per solution row, collected into the
|
|
41
|
+
* tag-keyed dictionary or the coalesced label the request asks for (§5.4, §6.2);
|
|
42
|
+
* - **value** — the stored value of the column's variant: a literal, or the reference naming a resource.
|
|
43
|
+
*/
|
|
44
|
+
readonly form: "tagged" | "value";
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The columns of every single-valued property a plan reads, keyed by property branch.
|
|
48
|
+
*/
|
|
49
|
+
export type Schema = ReadonlyMap<Branch, readonly Column[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Derives the table schema of a detail plan.
|
|
52
|
+
*
|
|
53
|
+
* Every single-valued property branch reachable from the root through nested resources and requested union
|
|
54
|
+
* variants is mapped to its columns: one per requested variant for a union-typed property, so the decoder reads
|
|
55
|
+
* the variant off the column that bound, else one under the single variant of the property's range. Markers and
|
|
56
|
+
* multi-valued properties bind no column and are absent from the schema, as the query never reads them.
|
|
57
|
+
*
|
|
58
|
+
* @param flake The detail plan
|
|
59
|
+
*
|
|
60
|
+
* @returns The columns of each single-valued property, keyed by branch
|
|
61
|
+
*/
|
|
62
|
+
export declare function schema(flake: Flake): Schema;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the variable a column is bound to.
|
|
65
|
+
*
|
|
66
|
+
* A column of a union-typed property is keyed on the branch and its variant, so the columns of one property take
|
|
67
|
+
* distinct variables; any other column is keyed on its branch alone, the one variable its property is read from.
|
|
68
|
+
*
|
|
69
|
+
* @param scope The variable scope shared by encoder and decoder
|
|
70
|
+
* @param column The column to resolve
|
|
71
|
+
*
|
|
72
|
+
* @returns The variable bound to `column`
|
|
73
|
+
*/
|
|
74
|
+
export declare function column(scope: Scope<Variable>, { node, variant }: Column): Variable;
|
|
75
|
+
/**
|
|
76
|
+
* Lists the property branches nested under a column.
|
|
77
|
+
*
|
|
78
|
+
* The branches of the resource the column's variant reaches: those its own variant declares for a union-typed
|
|
79
|
+
* property, every branch of the property otherwise; none under a localised variant.
|
|
80
|
+
*
|
|
81
|
+
* @param column The column to descend from
|
|
82
|
+
*
|
|
83
|
+
* @returns The nested branches, in plan order
|
|
84
|
+
*/
|
|
85
|
+
export declare function entries({ node, variant }: Column): readonly Branch[];
|
|
86
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/detail/schema.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAS,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EACN,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,KAAK,EAIV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGvD;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IAEpB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAA;KAAE,CAAC;IAErD;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAEvB;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;CAElC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;AAG5D;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CA2C3C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,GAAG,QAAQ,CAIlF;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAIpE"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025-2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { eager } from "@grafctory/blue/value";
|
|
17
|
+
import { getFlakeEntries, getFlakeVariant, isModelBranch } from "@grafctory/keep-flake";
|
|
18
|
+
/**
|
|
19
|
+
* Derives the table schema of a detail plan.
|
|
20
|
+
*
|
|
21
|
+
* Every single-valued property branch reachable from the root through nested resources and requested union
|
|
22
|
+
* variants is mapped to its columns: one per requested variant for a union-typed property, so the decoder reads
|
|
23
|
+
* the variant off the column that bound, else one under the single variant of the property's range. Markers and
|
|
24
|
+
* multi-valued properties bind no column and are absent from the schema, as the query never reads them.
|
|
25
|
+
*
|
|
26
|
+
* @param flake The detail plan
|
|
27
|
+
*
|
|
28
|
+
* @returns The columns of each single-valued property, keyed by branch
|
|
29
|
+
*/
|
|
30
|
+
export function schema(flake) {
|
|
31
|
+
return new Map(rows(getFlakeEntries(flake)));
|
|
32
|
+
/**
|
|
33
|
+
* The schema rows of the single-valued property branches among `branches` and under their columns.
|
|
34
|
+
*/
|
|
35
|
+
function rows(branches) {
|
|
36
|
+
return branches.filter(isModelBranch).flatMap(branch => {
|
|
37
|
+
const bound = columns(branch);
|
|
38
|
+
return [
|
|
39
|
+
[branch, bound],
|
|
40
|
+
...bound.flatMap(column => rows(entries(column)))
|
|
41
|
+
];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The columns of one property branch: one per requested variant of a union-typed property, else one under the
|
|
46
|
+
* single variant of its range, read as tagged text under a localised variant and as a value otherwise.
|
|
47
|
+
*/
|
|
48
|
+
function columns(branch) {
|
|
49
|
+
const shape = eager(branch.range.shape);
|
|
50
|
+
return shape.kind === "union"
|
|
51
|
+
? (branch.drain?.form === "union" ? [...branch.drain.variants] : []).map(([variant, placeholder]) => ({ node: branch, variant, drain: placeholder, form: form(variant) }))
|
|
52
|
+
: [{ node: branch, variant: shape, drain: branch.drain, form: form(shape) }];
|
|
53
|
+
}
|
|
54
|
+
function form(variant) {
|
|
55
|
+
return variant.kind === "dictionary" ? "tagged" : "value";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the variable a column is bound to.
|
|
60
|
+
*
|
|
61
|
+
* A column of a union-typed property is keyed on the branch and its variant, so the columns of one property take
|
|
62
|
+
* distinct variables; any other column is keyed on its branch alone, the one variable its property is read from.
|
|
63
|
+
*
|
|
64
|
+
* @param scope The variable scope shared by encoder and decoder
|
|
65
|
+
* @param column The column to resolve
|
|
66
|
+
*
|
|
67
|
+
* @returns The variable bound to `column`
|
|
68
|
+
*/
|
|
69
|
+
export function column(scope, { node, variant }) {
|
|
70
|
+
return eager(node.range.shape).kind === "union"
|
|
71
|
+
? scope.resolve(node, variant)
|
|
72
|
+
: scope.resolve(node);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Lists the property branches nested under a column.
|
|
76
|
+
*
|
|
77
|
+
* The branches of the resource the column's variant reaches: those its own variant declares for a union-typed
|
|
78
|
+
* property, every branch of the property otherwise; none under a localised variant.
|
|
79
|
+
*
|
|
80
|
+
* @param column The column to descend from
|
|
81
|
+
*
|
|
82
|
+
* @returns The nested branches, in plan order
|
|
83
|
+
*/
|
|
84
|
+
export function entries({ node, variant }) {
|
|
85
|
+
return variant.kind === "dictionary" ? []
|
|
86
|
+
: eager(node.range.shape).kind === "union" ? getFlakeVariant(node, variant)
|
|
87
|
+
: getFlakeEntries(node);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/detail/schema.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E;YACD,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAE/E,CAAC;IAED,SAAS,IAAI,CAAC,OAAc;QAC3B,OAAO,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAC3D,CAAC;AAEF,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CAAC,KAAsB,EAAE,EAAE,IAAI,EAAE,OAAO,EAAU;IACvE,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,OAAO;QAC9C,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;QAC9B,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAU;IAChD,OAAO,OAAO,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,EAAE;QACxC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC;YAC1E,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect-pass query encoder.
|
|
3
|
+
*
|
|
4
|
+
* Folds a batch of candidate entries into one `select distinct` query returning exactly the entries that are the
|
|
5
|
+
* subject of at least one stored triple. The subject variable is keyed on the batch in the {@link Scope} shared with
|
|
6
|
+
* the driver, which reads the rows of each request off that column and resolves it to true if any row binds it.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { Scope } from "@grafctory/core/scope";
|
|
11
|
+
import type { Deferred, Detect } from "@grafctory/keep/batching";
|
|
12
|
+
import type { SPARQL, Variable } from "@grafctory/wire-sparql";
|
|
13
|
+
/**
|
|
14
|
+
* Encodes the batched existence query for a set of candidate entries.
|
|
15
|
+
*
|
|
16
|
+
* @param scope The variable scope shared with the driver, keying the subject column on `batch`
|
|
17
|
+
* @param batch The candidate items to probe, each carrying the `request` whose `entry` is tested for existence
|
|
18
|
+
*
|
|
19
|
+
* @returns A `select distinct` query projecting the subject variable for every entry that is the
|
|
20
|
+
* subject of at least one stored triple; an entry with no triples returns no row
|
|
21
|
+
*/
|
|
22
|
+
export declare function encode(scope: Scope<Variable>, batch: readonly Deferred<Detect>[]): SPARQL;
|
|
23
|
+
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/detect/encode.ts"],"names":[],"mappings":"AAgBA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAI/D;;;;;;;;GAQG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,EACtB,KAAK,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,EAAE,GAChC,MAAM,CAeR"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025-2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { distinct, edge, reference, select, values, variable, where } from "@grafctory/wire-sparql/builder";
|
|
17
|
+
/**
|
|
18
|
+
* Encodes the batched existence query for a set of candidate entries.
|
|
19
|
+
*
|
|
20
|
+
* @param scope The variable scope shared with the driver, keying the subject column on `batch`
|
|
21
|
+
* @param batch The candidate items to probe, each carrying the `request` whose `entry` is tested for existence
|
|
22
|
+
*
|
|
23
|
+
* @returns A `select distinct` query projecting the subject variable for every entry that is the
|
|
24
|
+
* subject of at least one stored triple; an entry with no triples returns no row
|
|
25
|
+
*/
|
|
26
|
+
export function encode(scope, batch) {
|
|
27
|
+
const subject = scope.resolve(batch);
|
|
28
|
+
return select(distinct(variable(subject)), where(values([variable(subject)], batch.map(({ request }) => [reference(request.entry)])), edge(variable(subject), variable(scope.resolve()), variable(scope.resolve()))));
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../src/detect/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAeH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAG5G;;;;;;;;GAQG;AACH,MAAM,UAAU,MAAM,CACrB,KAAsB,EACtB,KAAkC;IAGlC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAErC,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAC/C,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CACrD,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAC1B,CAAC,EACF,IAAI,CACH,QAAQ,CAAC,OAAO,CAAC,EACjB,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,EACzB,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CACzB,CACD,CAAC,CAAC;AAEJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect-pass driver.
|
|
3
|
+
*
|
|
4
|
+
* Settles every queued {@link Detect} request in a batch with a single existence query against the repository.
|
|
5
|
+
*
|
|
6
|
+
* @module index
|
|
7
|
+
*/
|
|
8
|
+
import type { Broker, Deferred, Detect } from "@grafctory/keep/batching";
|
|
9
|
+
import type { RepositoryClient } from "@grafctory/wire-sparql";
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a batch of detect requests with one existence query.
|
|
12
|
+
*
|
|
13
|
+
* Each request resolves to `true` if its entry is the subject of at least one stored triple, and to `false`
|
|
14
|
+
* otherwise.
|
|
15
|
+
*
|
|
16
|
+
* @param batch The queued detect requests to resolve
|
|
17
|
+
* @param client The repository the existence query runs against
|
|
18
|
+
* @param broker The channel for nested requests, which the pass never issues
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise settling once every request in the batch has been resolved
|
|
21
|
+
*/
|
|
22
|
+
export declare function detect(batch: readonly Deferred<Detect>[], client: RepositoryClient, broker: Broker): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/detect/index.ts"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK/D;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,EAAE,EAClC,MAAM,EAAE,gBAAgB,EACxB,MAAM,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,CAAC,CAWf"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 2025-2026 Metreeca srl
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { plain, read } from "../spine.js";
|
|
17
|
+
import { encode } from "./encode.js";
|
|
18
|
+
/**
|
|
19
|
+
* Resolves a batch of detect requests with one existence query.
|
|
20
|
+
*
|
|
21
|
+
* Each request resolves to `true` if its entry is the subject of at least one stored triple, and to `false`
|
|
22
|
+
* otherwise.
|
|
23
|
+
*
|
|
24
|
+
* @param batch The queued detect requests to resolve
|
|
25
|
+
* @param client The repository the existence query runs against
|
|
26
|
+
* @param broker The channel for nested requests, which the pass never issues
|
|
27
|
+
*
|
|
28
|
+
* @returns A promise settling once every request in the batch has been resolved
|
|
29
|
+
*/
|
|
30
|
+
export function detect(batch, client, broker) {
|
|
31
|
+
return read(batch, client, broker, {
|
|
32
|
+
encode: scope => encode(scope, batch),
|
|
33
|
+
owner: scope => scope.resolve(batch),
|
|
34
|
+
decode: (_, __, rows) => plain(rows.length > 0)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/detect/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CACrB,KAAkC,EAClC,MAAwB,EACxB,MAAc;IAGd,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;QAElC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC;QACrC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAEpC,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;KAE/C,CAAC,CAAC;AAEJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Store } from "@grafctory/keep";
|
|
2
|
+
import { type Repository } from "@grafctory/wire-sparql";
|
|
3
|
+
/**
|
|
4
|
+
* The caps a {@link createSPARQLStore | SPARQL store} declares on how it queries its repository.
|
|
5
|
+
*
|
|
6
|
+
* Both are non-negative integers, and `0` lifts the cap it is set on.
|
|
7
|
+
*/
|
|
8
|
+
export type SPARQLStoreOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* The most entries one query binds through its `values` block, so no query outgrows what the backend accepts
|
|
11
|
+
* however many requests a round accumulates: a larger accumulation reaches the repository as several queries.
|
|
12
|
+
*
|
|
13
|
+
* @defaultValue `500`, measured on the backends the package is verified against
|
|
14
|
+
*/
|
|
15
|
+
readonly batch?: number;
|
|
16
|
+
/**
|
|
17
|
+
* The most queries in flight at once, so a backend with a connection limit, or one charging per concurrent query,
|
|
18
|
+
* is never asked for more than the cap declares, whatever a round accumulates.
|
|
19
|
+
*
|
|
20
|
+
* @defaultValue `8`
|
|
21
|
+
*/
|
|
22
|
+
readonly burst?: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Creates a SPARQL store backed by a {@link Repository}.
|
|
26
|
+
*
|
|
27
|
+
* Every data call runs in its own {@link Repository.execute | repository transaction}, so concurrent calls share no
|
|
28
|
+
* transaction state. Inside {@link Store.execute | execute}, the task receives a {@link StoreClient} bound to a single
|
|
29
|
+
* repository transaction: its mutations are buffered and flushed to the repository as one update when the task
|
|
30
|
+
* completes, then committed with the transaction. Queries within the task do not observe the task's own pending
|
|
31
|
+
* mutations, so a read depending on a write must run in a separate `execute` call.
|
|
32
|
+
*
|
|
33
|
+
* > [!IMPORTANT]
|
|
34
|
+
* > **Transaction Isolation** — Determined by the supplied {@link Repository}: native transactions keep the reads of
|
|
35
|
+
* > an `execute` task consistent, while its mutations are always buffered and applied as a single update on commit.
|
|
36
|
+
*
|
|
37
|
+
* > [!IMPORTANT]
|
|
38
|
+
* > **Mutation Events** — Limited to mutations issued through this store; mutations from other clients on the
|
|
39
|
+
* > underlying repository are not observed.
|
|
40
|
+
*
|
|
41
|
+
* > [!IMPORTANT]
|
|
42
|
+
* > **Embedded Resources** — Named by IRIs in the repository, never by blank nodes. The store skolemises the
|
|
43
|
+
* > embedded resources it writes, and a graph loaded by other means must be skolemised before the store reads it. A
|
|
44
|
+
* > blank node found where an embedded resource is expected fails the whole retrieval with a
|
|
45
|
+
* > {@link !RangeError RangeError}, so no embedded resource and none of the content requested under it ever goes
|
|
46
|
+
* > silently missing from a retrieved result, whatever tool loaded the graph into the repository.
|
|
47
|
+
*
|
|
48
|
+
* @param repository - The repository for SPARQL query, update, and transaction execution
|
|
49
|
+
* @param options - The caps on how the store queries the repository
|
|
50
|
+
*
|
|
51
|
+
* @returns An immutable {@link Store}
|
|
52
|
+
*
|
|
53
|
+
* @throws {@link !TypeError TypeError} If a cap is not a non-negative integer
|
|
54
|
+
*/
|
|
55
|
+
export declare function createSPARQLStore(repository: Repository, { batch, burst }?: SPARQLStoreOptions): Store;
|
|
56
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4EA,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,iBAAiB,CAAC;AAK1D,OAAO,EAGN,KAAK,UAAU,EAEf,MAAM,wBAAwB,CAAC;AAShC;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAEhC;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAExB;;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CAExB,CAAC;AAuBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,EAAE,EAEzD,KAAa,EACb,KAAa,EAEb,GAAE,kBAAuB,GAAG,KAAK,CA8CjC"}
|