@metreeca/keep-sparql 0.10.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 +106 -0
- package/dist/_/_decode.d.ts +20 -0
- package/dist/_/_decode.d.ts.map +1 -0
- package/dist/_/_decode.js +55 -0
- package/dist/_/_decode.js.map +1 -0
- package/dist/_/_encode.d.ts +112 -0
- package/dist/_/_encode.d.ts.map +1 -0
- package/dist/_/_encode.js +262 -0
- package/dist/_/_encode.js.map +1 -0
- package/dist/_/_flake.d.ts +16 -0
- package/dist/_/_flake.d.ts.map +1 -0
- package/dist/_/_flake.js +65 -0
- package/dist/_/_flake.js.map +1 -0
- package/dist/_/_union.d.ts +28 -0
- package/dist/_/_union.d.ts.map +1 -0
- package/dist/_/_union.js +51 -0
- package/dist/_/_union.js.map +1 -0
- package/dist/detect/decode.d.ts +25 -0
- package/dist/detect/decode.d.ts.map +1 -0
- package/dist/detect/decode.js +34 -0
- package/dist/detect/decode.js.map +1 -0
- package/dist/detect/encode.d.ts +25 -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 +17 -0
- package/dist/detect/index.d.ts.map +1 -0
- package/dist/detect/index.js +55 -0
- package/dist/detect/index.js.map +1 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/dist/lookup/decode.d.ts +33 -0
- package/dist/lookup/decode.d.ts.map +1 -0
- package/dist/lookup/decode.js +193 -0
- package/dist/lookup/decode.js.map +1 -0
- package/dist/lookup/encode.d.ts +46 -0
- package/dist/lookup/encode.d.ts.map +1 -0
- package/dist/lookup/encode.js +111 -0
- package/dist/lookup/encode.js.map +1 -0
- package/dist/lookup/index.d.ts +21 -0
- package/dist/lookup/index.d.ts.map +1 -0
- package/dist/lookup/index.js +72 -0
- package/dist/lookup/index.js.map +1 -0
- package/dist/modify/decode.d.ts +22 -0
- package/dist/modify/decode.d.ts.map +1 -0
- package/dist/modify/decode.js +26 -0
- package/dist/modify/decode.js.map +1 -0
- package/dist/modify/encode.d.ts +21 -0
- package/dist/modify/encode.d.ts.map +1 -0
- package/dist/modify/encode.js +184 -0
- package/dist/modify/encode.js.map +1 -0
- package/dist/modify/index.d.ts +22 -0
- package/dist/modify/index.d.ts.map +1 -0
- package/dist/modify/index.js +44 -0
- package/dist/modify/index.js.map +1 -0
- package/dist/select/decode.d.ts +16 -0
- package/dist/select/decode.d.ts.map +1 -0
- package/dist/select/decode.js +229 -0
- package/dist/select/decode.js.map +1 -0
- package/dist/select/encode.d.ts +16 -0
- package/dist/select/encode.d.ts.map +1 -0
- package/dist/select/encode.js +434 -0
- package/dist/select/encode.js.map +1 -0
- package/dist/select/index.d.ts +16 -0
- package/dist/select/index.d.ts.map +1 -0
- package/dist/select/index.js +38 -0
- package/dist/select/index.js.map +1 -0
- package/package.json +68 -0
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
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# @metreeca/keep-sparql
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@metreeca/keep-sparql)
|
|
4
|
+
|
|
5
|
+
SPARQL 1.1 repository connector for the [@metreeca/keep](https://github.com/metreeca/keep) model-driven linked data
|
|
6
|
+
storage framework.
|
|
7
|
+
|
|
8
|
+
Translates @metreeca/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/metreeca/wire#installation) or
|
|
10
|
+
implement the [@metreeca/wire-sparql](https://github.com/metreeca/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`. The framework defers transaction semantics
|
|
15
|
+
> to the backend; each connector documents the level it provides on its factory function.
|
|
16
|
+
|
|
17
|
+
# Installation
|
|
18
|
+
|
|
19
|
+
Install the framework together with a backend connector from the
|
|
20
|
+
[@metreeca/wire](https://github.com/metreeca/wire) SPARQL connector collection:
|
|
21
|
+
|
|
22
|
+
```shell
|
|
23
|
+
npm install @metreeca/keep-sparql
|
|
24
|
+
npm install @metreeca/wire-sparql-oxigraph # or another backend connector
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
# Usage
|
|
28
|
+
|
|
29
|
+
> [!NOTE]
|
|
30
|
+
>
|
|
31
|
+
> This section introduces essential concepts; for complete coverage, see the
|
|
32
|
+
> [API reference](https://metreeca.github.io/keep/modules/_metreeca_keep-sparql.html).
|
|
33
|
+
|
|
34
|
+
## Wiring a Store
|
|
35
|
+
|
|
36
|
+
Pass any [@metreeca/wire-sparql](https://github.com/metreeca/wire/tree/main/packages/wire-sparql) `Repository` connector
|
|
37
|
+
to
|
|
38
|
+
`createSPARQLStore` to obtain a fully functional `Store`:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { createSPARQLStore } from "@metreeca/keep-sparql";
|
|
42
|
+
import { createOxiRepository } from "@metreeca/wire-sparql-oxigraph";
|
|
43
|
+
|
|
44
|
+
const store = createSPARQLStore(createOxiRepository());
|
|
45
|
+
|
|
46
|
+
const product = await store.lookup({
|
|
47
|
+
entry: "http://example.com/products/1",
|
|
48
|
+
shape: ProductShape,
|
|
49
|
+
model: {
|
|
50
|
+
name: "",
|
|
51
|
+
price: 0
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Implementing a Connector
|
|
57
|
+
|
|
58
|
+
A backend connector is a [@metreeca/wire-sparql](https://github.com/metreeca/wire/tree/main/packages/wire-sparql)
|
|
59
|
+
`Repository`: implement `ask`, `select`, `construct`, `update`, `execute`, and optionally `close`, lifting backend node
|
|
60
|
+
values into the shared `Term` representation with the `reference`, `tagged`, and `typed` constructors.
|
|
61
|
+
`@metreeca/keep-sparql` then wraps any such connector into a `Store` via `createSPARQLStore`.
|
|
62
|
+
|
|
63
|
+
See [@metreeca/wire-sparql-oxigraph](https://github.com/metreeca/wire/tree/main/packages/wire-sparql-oxigraph) for a
|
|
64
|
+
complete reference connector.
|
|
65
|
+
|
|
66
|
+
# Verified Backends
|
|
67
|
+
|
|
68
|
+
This SPARQL connector has been exercised against the
|
|
69
|
+
[@metreeca/keep-suite](https://github.com/metreeca/keep/tree/main/packages/keep-suite) conformance suite on the backends
|
|
70
|
+
and versions below.
|
|
71
|
+
|
|
72
|
+
| Engine | Version | Storage |
|
|
73
|
+
|------------------------------|----------------------------------------------------------|---------------|
|
|
74
|
+
| [Eclipse RDF4J][rdf4j] | 5.3.1 | MemoryStore |
|
|
75
|
+
| [Eclipse RDF4J][rdf4j] | 5.3.1 | NativeStore |
|
|
76
|
+
| [Eclipse RDF4J][rdf4j] | 5.3.1 | LmdbStore |
|
|
77
|
+
| [Apache Jena Fuseki][fuseki] | 6.1.0 | MemoryDataset |
|
|
78
|
+
| [Apache Jena Fuseki][fuseki] | 6.1.0 | TDB1 |
|
|
79
|
+
| [Apache Jena Fuseki][fuseki] | 6.1.0 | TDB2 |
|
|
80
|
+
| [Oxigraph][oxigraph] | 0.5.8 | in-memory |
|
|
81
|
+
| [Oxigraph][oxigraph] | 0.5.8 | disk |
|
|
82
|
+
| [QLever][qlever] | [*upcoming*](https://github.com/metreeca/keep/issues/8) | disk |
|
|
83
|
+
| [Fluree][fluree] | [*upcoming*](https://github.com/metreeca/keep/issues/13) | disk |
|
|
84
|
+
| [Virtuoso][virtuoso] | [*upcoming*](https://github.com/metreeca/keep/issues/9) | disk |
|
|
85
|
+
|
|
86
|
+
[rdf4j]: https://rdf4j.org/
|
|
87
|
+
|
|
88
|
+
[fuseki]: https://jena.apache.org/
|
|
89
|
+
|
|
90
|
+
[oxigraph]: https://oxigraph.org/
|
|
91
|
+
|
|
92
|
+
[qlever]: https://qlever.dev/
|
|
93
|
+
|
|
94
|
+
[virtuoso]: https://virtuoso.openlinksw.com/
|
|
95
|
+
|
|
96
|
+
[fluree]: https://flur.ee/
|
|
97
|
+
|
|
98
|
+
# Support
|
|
99
|
+
|
|
100
|
+
- open an [issue](https://github.com/metreeca/keep/issues) to report a problem or to suggest a new feature
|
|
101
|
+
- start a [discussion](https://github.com/metreeca/keep/discussions) to ask a how-to question or to share an idea
|
|
102
|
+
|
|
103
|
+
# License
|
|
104
|
+
|
|
105
|
+
This project is licensed under the Apache 2.0 License –
|
|
106
|
+
see [LICENSE](https://github.com/metreeca/keep?tab=Apache-2.0-1-ov-file) file for details.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Value } from "@metreeca/qest/resource";
|
|
2
|
+
import type { Term } from "@metreeca/trio";
|
|
3
|
+
import type { Tuple, Variable } from "@metreeca/wire-sparql";
|
|
4
|
+
export declare function column(variable: Variable, tuples: readonly Tuple[]): readonly Term[];
|
|
5
|
+
/**
|
|
6
|
+
* Coerces a scalar solution {@link Term} back to the QEST {@link Value} it stands for, the read-side dual of the
|
|
7
|
+
* encoder's write-value typing (§3.3). An IRI keeps its reference identity; a literal collapses to its transport
|
|
8
|
+
* type: an `xsd:boolean` to a boolean, a numeric datatype to a number, and every other datatype (including the
|
|
9
|
+
* `xsd:string` a plain literal carries) to its lexical string, so the many-to-one egress mapping discards the
|
|
10
|
+
* processing-type distinctions not carried on the wire.
|
|
11
|
+
*
|
|
12
|
+
* @param value The solution term to coerce, an IRI reference or a plain/typed literal
|
|
13
|
+
*
|
|
14
|
+
* @returns The decoded value: a reference, boolean, number, or string
|
|
15
|
+
*
|
|
16
|
+
* @throws {RangeError} If `value` is a blank node or a language-tagged literal, neither of which surfaces as a
|
|
17
|
+
* scalar value (a localised property is decoded through the broker, not here)
|
|
18
|
+
*/
|
|
19
|
+
export declare function termToValue(value: Term): Value;
|
|
20
|
+
//# sourceMappingURL=_decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_decode.d.ts","sourceRoot":"","sources":["../../src/_/_decode.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAE7D,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,IAAI,EAAE,CAEpF;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,KAAK,CA0B9C"}
|
|
@@ -0,0 +1,55 @@
|
|
|
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 { isNumeric, xsd } from "@metreeca/core/datatype";
|
|
17
|
+
export function column(variable, tuples) {
|
|
18
|
+
return tuples.flatMap(tuple => tuple[variable] ?? []);
|
|
19
|
+
}
|
|
20
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
21
|
+
/**
|
|
22
|
+
* Coerces a scalar solution {@link Term} back to the QEST {@link Value} it stands for, the read-side dual of the
|
|
23
|
+
* encoder's write-value typing (§3.3). An IRI keeps its reference identity; a literal collapses to its transport
|
|
24
|
+
* type: an `xsd:boolean` to a boolean, a numeric datatype to a number, and every other datatype (including the
|
|
25
|
+
* `xsd:string` a plain literal carries) to its lexical string, so the many-to-one egress mapping discards the
|
|
26
|
+
* processing-type distinctions not carried on the wire.
|
|
27
|
+
*
|
|
28
|
+
* @param value The solution term to coerce, an IRI reference or a plain/typed literal
|
|
29
|
+
*
|
|
30
|
+
* @returns The decoded value: a reference, boolean, number, or string
|
|
31
|
+
*
|
|
32
|
+
* @throws {RangeError} If `value` is a blank node or a language-tagged literal, neither of which surfaces as a
|
|
33
|
+
* scalar value (a localised property is decoded through the broker, not here)
|
|
34
|
+
*/
|
|
35
|
+
export function termToValue(value) {
|
|
36
|
+
if (value.kind === "blank") {
|
|
37
|
+
throw new RangeError(`unsupported blank node <_:${value.label}>`);
|
|
38
|
+
}
|
|
39
|
+
else if (value.kind === "named") {
|
|
40
|
+
return value.iri;
|
|
41
|
+
}
|
|
42
|
+
else if (value.kind === "tagged") {
|
|
43
|
+
throw new RangeError(`unsupported language-tagged literal <${value.text}@${value.language}>`);
|
|
44
|
+
}
|
|
45
|
+
else if (value.datatype === xsd.boolean) {
|
|
46
|
+
return value.text === "true";
|
|
47
|
+
}
|
|
48
|
+
else if (isNumeric(value.datatype)) {
|
|
49
|
+
return Number(value.text);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return value.text;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=_decode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
import { type Property } from "@metreeca/blue/resource";
|
|
2
|
+
import type { RangeShape, ValuesShape } from "@metreeca/blue/value";
|
|
3
|
+
import { type Literal, type Value, type Values } from "@metreeca/qest/resource";
|
|
4
|
+
import { Options, type Transform } from "@metreeca/qest/template";
|
|
5
|
+
import { type Blank, type Named, type Term } from "@metreeca/trio";
|
|
6
|
+
import type { SPARQL, Variable } from "@metreeca/wire-sparql";
|
|
7
|
+
/**
|
|
8
|
+
* The RDF {@link Term} of a comparison bound (`<` / `>` / `<=` / `>=`), typed against the {@link RangeShape |
|
|
9
|
+
* shape} variant it resolves to so the comparison resolves in the target's processing type (§5.7.1).
|
|
10
|
+
* {@link getBoundVariant} routes the bound, relaxing the value-domain facets a bound need not satisfy. A
|
|
11
|
+
* string variant carrying the `sh:IRI` datatype (an id / type entry, or a reference-ranged property) renders
|
|
12
|
+
* an IRI node rather than a literal, told apart from an IRI-shaped literal (a `url`) by datatype alone.
|
|
13
|
+
*/
|
|
14
|
+
export declare function boundToTerm(value: Literal, shape: RangeShape): Term;
|
|
15
|
+
/**
|
|
16
|
+
* Flattens the options of a set-matching or focus constraint to individual match {@link Term | terms}: a
|
|
17
|
+
* localised dictionary set expands to one language-tagged term per language tag (its value, or every element of
|
|
18
|
+
* its value array), a scalar option maps to its term typed by the {@link RangeShape | shape} variant it
|
|
19
|
+
* fits, and an option array maps element-wise. A `null` scalar survives as the absent-value option
|
|
20
|
+
* (§5.7.3).
|
|
21
|
+
*/
|
|
22
|
+
export declare function optionsToTerms(value: Options, shape: RangeShape): readonly (null | Term)[];
|
|
23
|
+
/**
|
|
24
|
+
* Types an operand against its resolved {@link ValuesShape | shape} (§5.7.1). A string shape carrying the
|
|
25
|
+
* `sh:IRI` datatype (an id / type entry, or a reference-ranged property) renders an IRI node rather than a
|
|
26
|
+
* literal, told apart from an IRI-shaped literal (a `url`) by datatype alone.
|
|
27
|
+
*/
|
|
28
|
+
export declare function valueToTerm(value: Value, shape: ValuesShape): Term;
|
|
29
|
+
/**
|
|
30
|
+
* Types a property's write value(s) to the RDF {@link Term | terms} to store, flattening a single value or
|
|
31
|
+
* a value set against the resolved {@link ValuesShape | shape} variant (§5.7.1).
|
|
32
|
+
*
|
|
33
|
+
* Each element is typed by the variant it fits: a boolean, number, or string operand to its datatype-typed
|
|
34
|
+
* literal (a string shape carrying the `sh:IRI` datatype renders an IRI node instead, as in
|
|
35
|
+
* {@link valueToTerm}); a localised dictionary to one plain or language-tagged term per tag (§6); a reference to
|
|
36
|
+
* its IRI as-is; and a nested resource to its declared id when present (a captive resource with its own
|
|
37
|
+
* identity), else a freshly skolemised IRI addressing the embedded sub-resource. Values not fitting the
|
|
38
|
+
* variant are dropped.
|
|
39
|
+
*/
|
|
40
|
+
export declare function valuesToTerms(values: Values, shape: ValuesShape): readonly Term[];
|
|
41
|
+
/**
|
|
42
|
+
* The stored edge connecting `source` to `target` through a {@link Property | property}'s declared
|
|
43
|
+
* predicate. Renders the forward direction when the property declares one and `source` may stand in
|
|
44
|
+
* subject position, else the reverse direction when `target` may; both directions carry the value, so
|
|
45
|
+
* either connects the pair. Yields the empty fragment when neither applies.
|
|
46
|
+
*/
|
|
47
|
+
export declare function link([source, property, target]: readonly [Variable | Term, Property, Variable | Term]): SPARQL;
|
|
48
|
+
/**
|
|
49
|
+
* Generates the SPARQL triple pattern rendering a {@link Property | property}'s forward direction.
|
|
50
|
+
*
|
|
51
|
+
* Emits `subject forward object` when the property declares a `forward` predicate; an undeclared
|
|
52
|
+
* forward direction contributes no pattern, yielding the empty fragment. The reverse-direction
|
|
53
|
+
* counterpart is {@link reverse}.
|
|
54
|
+
*
|
|
55
|
+
* @param edge The edge to render, as a `[subject, property, object]` tuple
|
|
56
|
+
*
|
|
57
|
+
* @returns The generated triple pattern, or the empty fragment when the property declares no forward
|
|
58
|
+
* predicate
|
|
59
|
+
*
|
|
60
|
+
* @see {@link https://www.w3.org/TR/sparql11-query/#QSynTriples SPARQL 1.1 Triple Patterns}
|
|
61
|
+
*/
|
|
62
|
+
export declare function forward([subject, property, object]: readonly [Variable | Blank | Named, Property, Variable | Term]): SPARQL;
|
|
63
|
+
/**
|
|
64
|
+
* Generates the SPARQL triple pattern rendering a {@link Property | property}'s reverse direction.
|
|
65
|
+
*
|
|
66
|
+
* Emits `subject reverse object`, flipping object and subject, when the property declares a `reverse`
|
|
67
|
+
* predicate; an undeclared reverse direction contributes no pattern, yielding the empty fragment. The
|
|
68
|
+
* subject lands in the triple's object position, so it is constrained to an IRI {@link Reference}. The
|
|
69
|
+
* forward-direction counterpart is {@link forward}.
|
|
70
|
+
*
|
|
71
|
+
* @param edge The edge to render, as a `[object, property, subject]` tuple
|
|
72
|
+
*
|
|
73
|
+
* @returns The generated triple pattern, or the empty fragment when the property declares no reverse
|
|
74
|
+
* predicate
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://www.w3.org/TR/sparql11-query/#QSynTriples SPARQL 1.1 Triple Patterns}
|
|
77
|
+
*/
|
|
78
|
+
export declare function reverse([object, property, subject]: readonly [Variable | Term, Property, Variable | Blank | Named]): SPARQL;
|
|
79
|
+
/**
|
|
80
|
+
* The gate binding a union shape's discriminator only for members belonging to it (union.md §Model).
|
|
81
|
+
*
|
|
82
|
+
* A classed node shape is gated by its stored `rdf:type` triple; a plain-string literal by a
|
|
83
|
+
* datatype/kind `filter` (boolean datatype, numeric test, or plain string); a localised `dictionary` shape by
|
|
84
|
+
* the language-tagged literal test, disjoint from the plain string; a classless node shape by the bare
|
|
85
|
+
* IRI-kind test. Under the modeller's disjointness guarantee (union.md §State) at most one shape's arm
|
|
86
|
+
* binds a given value.
|
|
87
|
+
*
|
|
88
|
+
* @param anchor The shape's value variable
|
|
89
|
+
* @param shape The shape to gate on
|
|
90
|
+
*
|
|
91
|
+
* @returns The gating triple pattern or `filter`
|
|
92
|
+
*/
|
|
93
|
+
export declare function membership(anchor: Variable, shape: ValuesShape): SPARQL;
|
|
94
|
+
/**
|
|
95
|
+
* The SPARQL expression applying a transform `pipe` to a value variable.
|
|
96
|
+
*
|
|
97
|
+
* Composes the pipe right-to-left (`reduceRight`), so the pipe's trailing transform applies to `anchor`
|
|
98
|
+
* first and each earlier transform wraps the running expression, leaving the leading transform
|
|
99
|
+
* outermost; an empty pipe yields the bare variable. Each {@link Transform} maps to its SPARQL aggregate
|
|
100
|
+
* (`count`/`sum`/`min`/`max`/`avg`, with the empty-set patch keeping `avg` over no rows unbound rather
|
|
101
|
+
* than erroring, Appendix A.4.3) or scalar function (string, numeric, and date-part).
|
|
102
|
+
*
|
|
103
|
+
* @param anchor The value variable the pipe transforms
|
|
104
|
+
* @param pipe The transforms to compose, leading (outermost) first
|
|
105
|
+
*
|
|
106
|
+
* @returns The SPARQL expression applying `pipe` to `anchor`, or the bare `anchor` variable when `pipe`
|
|
107
|
+
* is empty
|
|
108
|
+
*
|
|
109
|
+
* @see {@link https://www.w3.org/TR/sparql11-query/#aggregates SPARQL 1.1 Aggregates}
|
|
110
|
+
*/
|
|
111
|
+
export declare function expression(anchor: Variable, pipe: readonly Transform[]): SPARQL;
|
|
112
|
+
//# sourceMappingURL=_encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_encode.d.ts","sourceRoot":"","sources":["../../src/_/_encode.ts"],"names":[],"mappings":"AAiBA,OAAO,EAA6B,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnF,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAIpE,OAAO,EAAe,KAAK,OAAO,EAAkB,KAAK,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAC7G,OAAO,EAAE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,KAAK,KAAK,EAAS,KAAK,KAAK,EAAe,KAAK,IAAI,EAAS,MAAM,gBAAgB,CAAC;AAC9F,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,u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