@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.
Files changed (67) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +115 -2
  3. package/dist/detail/decode.d.ts +40 -0
  4. package/dist/detail/decode.d.ts.map +1 -0
  5. package/dist/detail/decode.js +160 -0
  6. package/dist/detail/decode.js.map +1 -0
  7. package/dist/detail/encode.d.ts +45 -0
  8. package/dist/detail/encode.d.ts.map +1 -0
  9. package/dist/detail/encode.js +104 -0
  10. package/dist/detail/encode.js.map +1 -0
  11. package/dist/detail/index.d.ts +19 -0
  12. package/dist/detail/index.d.ts.map +1 -0
  13. package/dist/detail/index.js +61 -0
  14. package/dist/detail/index.js.map +1 -0
  15. package/dist/detail/schema.d.ts +86 -0
  16. package/dist/detail/schema.d.ts.map +1 -0
  17. package/dist/detail/schema.js +89 -0
  18. package/dist/detail/schema.js.map +1 -0
  19. package/dist/detect/encode.d.ts +23 -0
  20. package/dist/detect/encode.d.ts.map +1 -0
  21. package/dist/detect/encode.js +30 -0
  22. package/dist/detect/encode.js.map +1 -0
  23. package/dist/detect/index.d.ts +23 -0
  24. package/dist/detect/index.d.ts.map +1 -0
  25. package/dist/detect/index.js +37 -0
  26. package/dist/detect/index.js.map +1 -0
  27. package/dist/index.d.ts +56 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +158 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/modify/encode.d.ts +17 -0
  32. package/dist/modify/encode.d.ts.map +1 -0
  33. package/dist/modify/encode.js +233 -0
  34. package/dist/modify/encode.js.map +1 -0
  35. package/dist/modify/index.d.ts +21 -0
  36. package/dist/modify/index.d.ts.map +1 -0
  37. package/dist/modify/index.js +50 -0
  38. package/dist/modify/index.js.map +1 -0
  39. package/dist/patterns.d.ts +199 -0
  40. package/dist/patterns.d.ts.map +1 -0
  41. package/dist/patterns.js +321 -0
  42. package/dist/patterns.js.map +1 -0
  43. package/dist/select/decode.d.ts +20 -0
  44. package/dist/select/decode.d.ts.map +1 -0
  45. package/dist/select/decode.js +134 -0
  46. package/dist/select/decode.js.map +1 -0
  47. package/dist/select/encode.d.ts +86 -0
  48. package/dist/select/encode.d.ts.map +1 -0
  49. package/dist/select/encode.js +647 -0
  50. package/dist/select/encode.js.map +1 -0
  51. package/dist/select/index.d.ts +19 -0
  52. package/dist/select/index.d.ts.map +1 -0
  53. package/dist/select/index.js +62 -0
  54. package/dist/select/index.js.map +1 -0
  55. package/dist/select/schema.d.ts +75 -0
  56. package/dist/select/schema.d.ts.map +1 -0
  57. package/dist/select/schema.js +84 -0
  58. package/dist/select/schema.js.map +1 -0
  59. package/dist/spine.d.ts +167 -0
  60. package/dist/spine.d.ts.map +1 -0
  61. package/dist/spine.js +180 -0
  62. package/dist/spine.js.map +1 -0
  63. package/dist/terms.d.ts +116 -0
  64. package/dist/terms.d.ts.map +1 -0
  65. package/dist/terms.js +251 -0
  66. package/dist/terms.js.map +1 -0
  67. package/package.json +66 -4
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,116 @@
1
- # Temporary Holding Version
1
+ # @grafctory/keep-sparql
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@grafctory/keep-sparql)](https://www.npmjs.com/package/@grafctory/keep-sparql)
4
+
5
+ SPARQL 1.1 repository connector for the [@grafctory/keep](https://github.com/grafctory/keep) model-driven linked data
6
+ storage framework.
7
+
8
+ Translates @grafctory/keep storage operations into SPARQL queries and updates against a pluggable graph backend.
9
+ Application developers can pick one of the [ready-made connectors](https://github.com/grafctory/wire#installation) or
10
+ implement the [@grafctory/wire-sparql](https://github.com/grafctory/wire/tree/main/packages/wire-sparql) `Repository`
11
+ interface to support a new SPARQL backend.
12
+
13
+ > [!IMPORTANT]
14
+ > **Transaction Isolation** — Determined by the supplied `Repository`: each connector documents the level it provides
15
+ > on its factory function. Mutations issued within a store transaction are always buffered and applied as a single
16
+ > update on commit.
17
+
18
+ > [!IMPORTANT]
19
+ > **Mutation Events** — Limited to mutations issued through the store; mutations from other clients on the underlying
20
+ > repository are not observed.
21
+
22
+ > [!IMPORTANT]
23
+ > **Embedded Resources** — Named by IRIs in the repository, never by blank nodes. The store skolemises the embedded
24
+ > resources it writes, and a graph loaded by other means must be skolemised before the store reads it. A blank node
25
+ > found where an embedded resource is expected fails the whole retrieval with a `RangeError`, so no embedded resource
26
+ > and none of the content requested under it ever goes silently missing from a retrieved result.
27
+
28
+ # Installation
29
+
30
+ Install the framework together with a backend connector from the
31
+ [@grafctory/wire](https://github.com/grafctory/wire) SPARQL connector collection:
32
+
33
+ ```shell
34
+ npm install @grafctory/keep-sparql
35
+ npm install @grafctory/wire-sparql-oxigraph # or another backend connector
36
+ ```
37
+
38
+ # Usage
39
+
40
+ > [!NOTE]
41
+ >
42
+ > This section introduces essential concepts; for complete coverage, see the
43
+ > [API reference](https://grafctory.github.io/keep/modules/_grafctory_keep-sparql.html).
44
+
45
+ ## Wiring a Store
46
+
47
+ Pass any [@grafctory/wire-sparql](https://github.com/grafctory/wire/tree/main/packages/wire-sparql) `Repository`
48
+ connector to `createSPARQLStore` to obtain a fully functional `Store`:
49
+
50
+ ```typescript
51
+ import { createSPARQLStore } from "@grafctory/keep-sparql";
52
+ import { createOxiRepository } from "@grafctory/wire-sparql-oxigraph";
53
+
54
+ const store = createSPARQLStore(createOxiRepository());
55
+
56
+ const product = await store.lookup({
57
+ entry: "http://example.com/products/1",
58
+ shape: ProductShape,
59
+ model: {
60
+ name: {},
61
+ price: {}
62
+ }
63
+ });
64
+ ```
65
+
66
+ The store caps how it queries the repository: `batch` is the most entries one query binds (default `500`) and `burst`
67
+ the most queries in flight at once (default `8`); `0` lifts a cap. Lower them for a backend behind a gateway with a
68
+ short request limit or a tight connection pool, and raise them where the backend takes more and a round trip costs more
69
+ than a larger query, as it does over a slow link to a remote backend serving few clients:
70
+
71
+ ```typescript
72
+ const store = createSPARQLStore(createOxiRepository(), { batch: 200, burst: 4 });
73
+ ```
74
+
75
+ ## Implementing a Connector
76
+
77
+ A backend connector is a [@grafctory/wire-sparql](https://github.com/grafctory/wire/tree/main/packages/wire-sparql)
78
+ `Repository`: implement `ask`, `select`, `construct`, `update`, `execute`, and `close`, lifting backend node values into
79
+ the shared [@grafctory/trio](https://github.com/grafctory/trio) `Term` representation with the `named`, `tagged`, and
80
+ `typed` constructors. `createSPARQLStore` then turns any such connector into a `Store`.
81
+
82
+ See [@grafctory/wire-sparql-oxigraph](https://github.com/grafctory/wire/tree/main/packages/wire-sparql-oxigraph) for a
83
+ complete reference connector.
84
+
85
+ # Verified Backends
86
+
87
+ This SPARQL connector has been exercised against the
88
+ [@grafctory/keep-suite](https://github.com/grafctory/keep/tree/main/packages/components/keep-suite) conformance suite on
89
+ the backends and versions below, through the listed connectors.
90
+
91
+ | Engine | Version | Storage | Connectors |
92
+ |------------------------------|---------|---------------|-------------------------------------------------|
93
+ | [Eclipse RDF4J][rdf4j] | 6.1.0 | MemoryStore | `createHTTPRepository`, `createRDF4JRepository` |
94
+ | [Eclipse RDF4J][rdf4j] | 6.1.0 | NativeStore | `createHTTPRepository`, `createRDF4JRepository` |
95
+ | [Eclipse RDF4J][rdf4j] | 6.1.0 | LmdbStore | `createHTTPRepository`, `createRDF4JRepository` |
96
+ | [Apache Jena Fuseki][fuseki] | 6.2.0 | MemoryDataset | `createHTTPRepository` |
97
+ | [Apache Jena Fuseki][fuseki] | 6.2.0 | TDB1 | `createHTTPRepository` |
98
+ | [Apache Jena Fuseki][fuseki] | 6.2.0 | TDB2 | `createHTTPRepository` |
99
+ | [Oxigraph][oxigraph] | 0.5.13 | in-memory | `createOxiRepository` |
100
+ | [Oxigraph][oxigraph] | 0.5.13 | disk | `createHTTPRepository` |
101
+
102
+ [rdf4j]: https://rdf4j.org/
103
+
104
+ [fuseki]: https://jena.apache.org/
105
+
106
+ [oxigraph]: https://oxigraph.org/
107
+
108
+ # Support
109
+
110
+ - open an [issue](https://github.com/grafctory/keep/issues) to report a problem or to suggest a new feature
111
+ - start a [discussion](https://github.com/grafctory/keep/discussions) to ask a how-to question or to share an idea
112
+
113
+ # License
114
+
115
+ This project is licensed under the Apache 2.0 License –
116
+ see [LICENSE](https://github.com/grafctory/keep?tab=Apache-2.0-1-ov-file) file for details.
@@ -0,0 +1,40 @@
1
+ import type { Scope } from "@grafctory/core/scope";
2
+ import { type Flake } from "@grafctory/keep-flake";
3
+ import type { Deferred, Detail } from "@grafctory/keep/batching";
4
+ import { type Resource } from "@grafctory/qest/state";
5
+ import type { Tuple, Variable } from "@grafctory/wire-sparql";
6
+ import { type Decoded } from "../spine.js";
7
+ import { type Schema } from "./schema.js";
8
+ /**
9
+ * Decodes one batched detail request from its own `select` solution rows.
10
+ *
11
+ * Properties are read off the {@link Schema | columns} the plan schema declares for them, resolved through the
12
+ * {@link Scope} shared with the encoder. Each property reads the first of its columns that bound:
13
+ *
14
+ * - a **value** column yields its literal or reference, recursing into a nested embedded or expanded resource;
15
+ * - a **tagged** column collects the tagged terms across its arm's rows into the tag-keyed dictionary or the
16
+ * coalesced label the model requests, under the request's language priority;
17
+ * - a **union** property has one column per requested variant, so the variant needs no term inspection.
18
+ *
19
+ * Properties with no column resolve without the tuples: `id` and `type` come from the entry and the shape, and
20
+ * each multi-valued property is read off the collection the select request materialising it returns, so the
21
+ * decoded resource depends on one select request per such property and the spine runs them; a collection
22
+ * resolving to no content leaves the property out (§4). The decoder issues no request itself.
23
+ *
24
+ * A `virtual` request reads its own multi-valued properties as virtual collections, gathered by the class their range
25
+ * declares rather than by stored links. Only the top-level resource is virtual: every resource it expands, through a
26
+ * single-valued property or a virtual collection, is decoded as held, with nested collections read off stored links.
27
+ *
28
+ * The request must carry only the solution rows whose subject column binds its own entry. Entries sharing a plan
29
+ * share its columns too, so passing the rows of the whole batch would mix the values of different entries.
30
+ *
31
+ * @param scope The variable scope shared with the encoder
32
+ * @param flake The {@link Flake | detail plan} the batch shares
33
+ * @param schema The table schema of the plan, the columns bound for each property it reads
34
+ * @param item The request to decode
35
+ * @param tuples The solution rows bound to the request's entry
36
+ *
37
+ * @returns The decoded resource, depending on the select requests its multi-valued properties read from
38
+ */
39
+ export declare function decode(scope: Scope<Variable>, flake: Flake, schema: Schema, { request: { virtual, entry, locale } }: Deferred<Detail>, tuples: readonly Tuple[]): Decoded<Resource>;
40
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../src/detail/decode.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAA2B,KAAK,KAAK,EAAiD,MAAM,uBAAuB,CAAC;AAC3H,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAmC,KAAK,QAAQ,EAA2B,MAAM,uBAAuB,CAAC;AAEhH,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAmB,KAAK,OAAO,EAAc,MAAM,aAAa,CAAC;AACxE,OAAO,EAAmB,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAG3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,EACtB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,EAAE,OAAO,EAAE,EAAE,OAAe,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,CAAC,MAAM,CAAC,EACjE,MAAM,EAAE,SAAS,KAAK,EAAE,GACtB,OAAO,CAAC,QAAQ,CAAC,CAoMnB"}
@@ -0,0 +1,160 @@
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 { getShapeBranches } from "@grafctory/blue/union";
17
+ import { eager } from "@grafctory/blue/value";
18
+ import { isArray, isObject, opt } from "@grafctory/core";
19
+ import { unique } from "@grafctory/core/arrays";
20
+ import { isTagRange, matchTag } from "@grafctory/core/language";
21
+ import { equals } from "@grafctory/core/values";
22
+ import { getFlakeVariant, isModelBranch, isQueryBranch } from "@grafctory/keep-flake";
23
+ import { coalesce, termToReference, termToValue } from "../terms.js";
24
+ import { all, collection, map, plain } from "../spine.js";
25
+ import { column, entries } from "./schema.js";
26
+ /**
27
+ * Decodes one batched detail request from its own `select` solution rows.
28
+ *
29
+ * Properties are read off the {@link Schema | columns} the plan schema declares for them, resolved through the
30
+ * {@link Scope} shared with the encoder. Each property reads the first of its columns that bound:
31
+ *
32
+ * - a **value** column yields its literal or reference, recursing into a nested embedded or expanded resource;
33
+ * - a **tagged** column collects the tagged terms across its arm's rows into the tag-keyed dictionary or the
34
+ * coalesced label the model requests, under the request's language priority;
35
+ * - a **union** property has one column per requested variant, so the variant needs no term inspection.
36
+ *
37
+ * Properties with no column resolve without the tuples: `id` and `type` come from the entry and the shape, and
38
+ * each multi-valued property is read off the collection the select request materialising it returns, so the
39
+ * decoded resource depends on one select request per such property and the spine runs them; a collection
40
+ * resolving to no content leaves the property out (§4). The decoder issues no request itself.
41
+ *
42
+ * A `virtual` request reads its own multi-valued properties as virtual collections, gathered by the class their range
43
+ * declares rather than by stored links. Only the top-level resource is virtual: every resource it expands, through a
44
+ * single-valued property or a virtual collection, is decoded as held, with nested collections read off stored links.
45
+ *
46
+ * The request must carry only the solution rows whose subject column binds its own entry. Entries sharing a plan
47
+ * share its columns too, so passing the rows of the whole batch would mix the values of different entries.
48
+ *
49
+ * @param scope The variable scope shared with the encoder
50
+ * @param flake The {@link Flake | detail plan} the batch shares
51
+ * @param schema The table schema of the plan, the columns bound for each property it reads
52
+ * @param item The request to decode
53
+ * @param tuples The solution rows bound to the request's entry
54
+ *
55
+ * @returns The decoded resource, depending on the select requests its multi-valued properties read from
56
+ */
57
+ export function decode(scope, flake, schema, { request: { virtual = false, entry, locale } }, tuples) {
58
+ return decodeResource(entry, flake, tuples);
59
+ function decodeResource(entry, flake, tuples) {
60
+ return merge(getShapeBranches(flake.range.shape).flatMap(variant => variant.kind !== "resource" ? [] : [decodeVariant(entry, variant, getFlakeVariant(flake, variant), tuples, virtual)]));
61
+ }
62
+ /**
63
+ * Decodes the resource `entry` holds under one variant of its shape, with collections virtual if `virtual` is set.
64
+ */
65
+ function decodeVariant(entry, shape, branches, tuples, virtual) {
66
+ return merge(branches.map(branch => {
67
+ const name = branch.path[branch.path.length - 1];
68
+ // a value set resolving to no content is never surfaced as an empty array or map (§4): the owning
69
+ // property is omitted from the decoded resource instead, constrained collections included
70
+ return isQueryBranch(branch) ? collection({ virtual, entry, shape, field: branch.entry, query: branch.drain.query, locale }, values => isEmpty(values) ? {} : { [name]: values })
71
+ : isModelBranch(branch) ? slot(name, decodeProperty(branch, tuples))
72
+ : branch.entry.kind === "id" ? plain({ [name]: entry })
73
+ : plain(opt(shape.class, clazz => ({ [name]: clazz }), {}));
74
+ }));
75
+ }
76
+ /**
77
+ * The value of a single-valued property: read off the first of its schema columns that bound, a localised
78
+ * column as the dictionary or coalesced label the request asks for, any other under the column's variant;
79
+ * a property none of whose columns bound in any row resolves to no value and is left out of the resource.
80
+ */
81
+ function decodeProperty(branch, tuples) {
82
+ const present = (schema.get(branch) ?? [])
83
+ .map(candidate => ({ column: candidate, terms: unique(decodeColumn(column(scope, candidate), tuples), equals) }))
84
+ .find(({ terms }) => terms.length > 0);
85
+ return present === undefined ? plain(undefined)
86
+ : present.column.form === "tagged" ? plain(decodeDictionary(present.column.drain, present.terms, present.column.variant.kind === "dictionary" && present.column.variant.uniqueLang === true))
87
+ : first(decodeValue(present.column.variant, entries(present.column), present.column.drain, present.terms, tuples));
88
+ }
89
+ function decodeDictionary(drain, terms, uniqueLang) {
90
+ const pairs = terms.flatMap((t) => t.kind === "tagged" ? [{ tag: t.language, text: t.text }] : []);
91
+ // §5.4: a tag-range map asks for the property structurally, the atomic leaf `{}` for its coalesced
92
+ // label; the two are told apart by the drain form, `{}` no longer standing for "every tag"
93
+ const ranges = drain?.form === "locale" ? Object.keys(drain.query).filter(isTagRange) : [];
94
+ if (ranges.length > 0) {
95
+ const matching = pairs.filter(({ tag }) => ranges.some(range => matchTag(tag, range)));
96
+ // §5.4: the retrieved entries carry the per-tag cardinality the property declares, which the
97
+ // template does not restate
98
+ return matching.length === 0 ? undefined
99
+ : uniqueLang ? matching.reduce((values, { tag, text }) => ({ ...values, [tag]: text }), {})
100
+ : matching.reduce((values, { tag, text }) => ({ ...values, [tag]: [...(values[tag] ?? []), text] }), {});
101
+ }
102
+ else {
103
+ const texts = coalesce(terms, locale);
104
+ return texts.length === 0 ? undefined
105
+ : uniqueLang ? texts[0]
106
+ : texts;
107
+ }
108
+ }
109
+ function decodeValue(shape, branches, drain, terms, tuples) {
110
+ switch (shape.kind) {
111
+ case "boolean":
112
+ case "number":
113
+ case "string":
114
+ return terms.flatMap(term => opt(termToValue(term, shape), value => [plain(value)], []));
115
+ case "reference":
116
+ // the atomic keeps the bare references; an expanded resource is held as it stands, whatever the
117
+ // request derives, so its collections are read off its links rather than off the class of their range
118
+ return drain?.form === "template"
119
+ ? references().map(entry => decodeVariant(entry, eager(shape.target), branches, tuples, false))
120
+ : references().map(plain);
121
+ case "resource":
122
+ return references().map(entry => decodeVariant(entry, shape, branches, tuples, false));
123
+ case "dictionary": // a localised variant is decoded from its tagged columns, never from a bound column
124
+ throw new RangeError(`unsupported dictionary variant`);
125
+ case "union": // a range variant is always a flattened branch, never a union
126
+ throw new RangeError(`unsupported union variant`);
127
+ }
128
+ function references() {
129
+ return terms.flatMap(term => opt(termToReference(term), entry => [entry], []));
130
+ }
131
+ }
132
+ function decodeColumn(variable, tuples) {
133
+ return tuples.flatMap(tuple => tuple[variable] ?? []);
134
+ }
135
+ function isEmpty(value) {
136
+ return value === undefined
137
+ || isArray(value, [])
138
+ || isObject(value, {});
139
+ }
140
+ /**
141
+ * The resource slot a decoded property fills, or none for a property resolving to no value.
142
+ */
143
+ function slot(name, property) {
144
+ return map(property, value => value === undefined ? {} : { [name]: value });
145
+ }
146
+ /**
147
+ * The first of the decoded values of a single-valued property, with the requests it alone depends on; none where
148
+ * none of the property's columns bound a value in any row the request was handed.
149
+ */
150
+ function first(values) {
151
+ return values.length === 0 ? plain(undefined) : values[0];
152
+ }
153
+ /**
154
+ * Merges decoded resources into one, depending on every request they depend on.
155
+ */
156
+ function merge(resources) {
157
+ return map(all(resources), resources => resources.reduce((merged, resource) => ({ ...merged, ...resource }), {}));
158
+ }
159
+ }
160
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/detail/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAc,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAmB,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;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AAC;IAGD,SAAS,YAAY,CAAC,QAAkB,EAAE,MAAwB;QACjE,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,SAAS,OAAO,CAAC,KAAc;QAC9B,OAAO,KAAK,KAAK,SAAS;eACtB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;eAClB,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACzB,CAAC;IAGD;;OAEG;IACH,SAAS,IAAI,CAAC,IAAgB,EAAE,QAAqC;QACpE,OAAO,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED;;;OAGG;IACH,SAAS,KAAK,CAAC,MAAiC;QAC/C,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACH,SAAS,KAAK,CAAC,SAAuC;QACrD,OAAO,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAW,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CACvF,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE,CAChC,CAAC,CAAC;IACJ,CAAC;AAEF,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Detail-pass SPARQL encoder.
3
+ *
4
+ * Folds a batch's {@link Flake | detail plan} into one `select` whose `where` is a `union` of arms. A `union` sums
5
+ * solutions rather than joining them, so giving each fan-out source its own arm keeps the row count a sum of
6
+ * per-property cardinalities instead of a cross-product. Multi-valued properties go to the select pass, so the only
7
+ * fan-out sources left here are the localised (`dictionary`) leaves and the requested variants of union properties.
8
+ *
9
+ * Every arm reads from the batch's **subject** variable, and a `values` block binds that subject to all the batch's
10
+ * entries. Arms and columns therefore grow with the plan alone, and the query text grows linearly with the entries:
11
+ * expanding a thousand members through one template costs as many arms and columns as expanding a single member.
12
+ *
13
+ * The plan contributes three kinds of arms, each opening with the `values` block:
14
+ *
15
+ * - a **scalar** arm (from `scalars`): the whole plain single-valued subtree (scalars, references, embedded
16
+ * resources), every edge `optional` so one row carries all bound values and an absent one leaves no row out;
17
+ * - a **localised** arm per `dictionary` leaf (from `composites`): the required path to the leaf's parent,
18
+ * then the localised edge binding one tagged-term column, one row per tagged value the leaf carries;
19
+ * - a **variant** arm per requested union variant (from `composites`): the variant's object column gated by
20
+ * its {@link membership} constraint, then the variant's subtree, read as a plain resource arm of its own.
21
+ *
22
+ * Variables come from the {@link Scope} shared with the decoder, so both sides agree on every column. The subject is
23
+ * keyed on the root {@link Flake}, and the rows of one request are those whose subject binds its entry. Every other
24
+ * column is keyed on {@link Branch} identity, paired with the variant shape for a variant column. A plan reading no
25
+ * single-valued property contributes no arm, and the caller must not encode it.
26
+ *
27
+ * @module
28
+ */
29
+ import type { Scope } from "@grafctory/core/scope";
30
+ import { type Flake } from "@grafctory/keep-flake";
31
+ import type { Reference } from "@grafctory/qest/state";
32
+ import { type SPARQL, type Variable } from "@grafctory/wire-sparql";
33
+ import { type Schema } from "./schema.js";
34
+ /**
35
+ * Encodes the batched `select` reading `entries` through one {@link Flake | detail plan}.
36
+ *
37
+ * @param scope The variable allocator shared with the decoder, keyed on the plan node behind each column
38
+ * @param entries The root entries to read, all sharing `flake`
39
+ * @param flake The detail plan the entries share
40
+ * @param schema The table schema of the plan, the columns to bind for each property it reads
41
+ *
42
+ * @returns The batched `select` query
43
+ */
44
+ export declare function encode(scope: Scope<Variable>, entries: readonly Reference[], flake: Flake, schema: Schema): SPARQL;
45
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/detail/encode.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAe,KAAK,KAAK,EAAmB,MAAM,uBAAuB,CAAC;AACjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGpE,OAAO,EAA0C,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAGlF;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,EACtB,OAAO,EAAE,SAAS,SAAS,EAAE,EAC7B,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,GACZ,MAAM,CA2GR"}