@grafctory/data-sparql 0.16.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 +72 -0
- package/dist/construct.d.ts +24 -0
- package/dist/construct.d.ts.map +1 -0
- package/dist/construct.js +51 -0
- package/dist/construct.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/select.d.ts +23 -0
- package/dist/select.d.ts.map +1 -0
- package/dist/select.js +51 -0
- package/dist/select.js.map +1 -0
- package/dist/update.d.ts +22 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +53 -0
- package/dist/update.js.map +1 -0
- package/dist/upload.d.ts +44 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +87 -0
- package/dist/upload.js.map +1 -0
- package/package.json +66 -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,72 @@
|
|
|
1
|
+
# @grafctory/data-sparql
|
|
2
|
+
|
|
3
|
+
[![npm][npm-badge]][npm] [![Grafctory][grafctory-badge]][grafctory]
|
|
4
|
+
|
|
5
|
+
[npm-badge]: https://img.shields.io/npm/v/@grafctory/data-sparql
|
|
6
|
+
[npm]: https://www.npmjs.com/package/@grafctory/data-sparql
|
|
7
|
+
[grafctory-badge]: https://img.shields.io/badge/part%20of-Grafctory-blue
|
|
8
|
+
[grafctory]: https://github.com/grafctory
|
|
9
|
+
|
|
10
|
+
SPARQL processing tasks for [@grafctory/data].
|
|
11
|
+
|
|
12
|
+
Provides ready-made [@grafctory/flow] steps for working with SPARQL repositories in
|
|
13
|
+
pipelines run by the [@grafctory/gear] job executor.
|
|
14
|
+
|
|
15
|
+
[@grafctory/data]: https://github.com/grafctory/data
|
|
16
|
+
[@grafctory/flow]: https://github.com/grafctory/flow
|
|
17
|
+
[@grafctory/gear]: https://github.com/grafctory/gear
|
|
18
|
+
[@grafctory/wire-sparql]: https://grafctory.github.io/wire/modules/_grafctory_wire-sparql.html
|
|
19
|
+
|
|
20
|
+
# Installation
|
|
21
|
+
|
|
22
|
+
```shell
|
|
23
|
+
npm install @grafctory/gear # the job executor
|
|
24
|
+
npm install @grafctory/data-sparql # this package
|
|
25
|
+
npm install @grafctory/wire-sparql-<backend> # repository connector for the target engine
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
> [!IMPORTANT]
|
|
29
|
+
>
|
|
30
|
+
> Node.js 22 or later is required.
|
|
31
|
+
|
|
32
|
+
> [!WARNING]
|
|
33
|
+
>
|
|
34
|
+
> TypeScript consumers must use `"moduleResolution": "nodenext"/"node16"/"bundler"` in `tsconfig.json`.
|
|
35
|
+
> The legacy `"node"` resolver is not supported.
|
|
36
|
+
|
|
37
|
+
Repositories are reached through the backend connectors listed by [@grafctory/wire-sparql]: install the one for the
|
|
38
|
+
engine the pipeline targets, together with any peer dependency that the connector itself requires.
|
|
39
|
+
|
|
40
|
+
# Usage
|
|
41
|
+
|
|
42
|
+
| Task | Description |
|
|
43
|
+
|----------------------------|---------------------------------|
|
|
44
|
+
| [`select()`][select] | SPARQL `SELECT` query runner |
|
|
45
|
+
| [`construct()`][construct] | SPARQL `CONSTRUCT` query runner |
|
|
46
|
+
| [`update()`][update] | SPARQL Update request runner |
|
|
47
|
+
| [`upload()`][upload] | RDF graph uploader |
|
|
48
|
+
|
|
49
|
+
[select]: https://grafctory.github.io/data/functions/_grafctory_data-sparql.select.html
|
|
50
|
+
|
|
51
|
+
[construct]: https://grafctory.github.io/data/functions/_grafctory_data-sparql.construct.html
|
|
52
|
+
|
|
53
|
+
[update]: https://grafctory.github.io/data/functions/_grafctory_data-sparql.update.html
|
|
54
|
+
|
|
55
|
+
[upload]: https://grafctory.github.io/data/functions/_grafctory_data-sparql.upload.html
|
|
56
|
+
|
|
57
|
+
[createRepository]: https://grafctory.github.io/data/functions/_grafctory_data-sparql.createRepository.html
|
|
58
|
+
|
|
59
|
+
The repository service has no default: a job binds a repository connector to [`createRepository()`][createRepository]
|
|
60
|
+
once, and every task or sink given no repository of its own then reads from or writes to the repository it reaches.
|
|
61
|
+
|
|
62
|
+
# Support
|
|
63
|
+
|
|
64
|
+
- open an [issue](https://github.com/grafctory/data/issues) to report a problem or to suggest a new feature
|
|
65
|
+
- start a [discussion](https://github.com/grafctory/data/discussions) to ask a how-to question or to share an idea
|
|
66
|
+
|
|
67
|
+
# License
|
|
68
|
+
|
|
69
|
+
This project is licensed under the Apache 2.0 License –
|
|
70
|
+
see [LICENSE](https://github.com/grafctory/data?tab=Apache-2.0-1-ov-file) file for details.
|
|
71
|
+
|
|
72
|
+
<sub>Grafctory™ is a trademark of Metreeca srl.</sub>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Task } from "@grafctory/flow";
|
|
2
|
+
import type { Graph } from "@grafctory/trio";
|
|
3
|
+
import type { Repository, SPARQL } from "@grafctory/wire-sparql";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a task running a feed of SPARQL `CONSTRUCT` queries against a SPARQL repository.
|
|
6
|
+
*
|
|
7
|
+
* The task emits the graph built by each query, in query order, ready to be stored by an {@link upload} sink. Every
|
|
8
|
+
* query runs on its own, outside any transaction, so successive queries may observe different states of a repository
|
|
9
|
+
* that is updated by other clients or by other steps of the same pipeline while the feed is being consumed.
|
|
10
|
+
*
|
|
11
|
+
* @param repository The target repository; defaults to the {@link createRepository} service
|
|
12
|
+
*
|
|
13
|
+
* @returns A task converting a feed of `CONSTRUCT` queries into the feed of graphs they build
|
|
14
|
+
*
|
|
15
|
+
* @throws {@link !Error Error} If `repository` is omitted, and either no execution is running or the running one binds
|
|
16
|
+
* no repository to {@link createRepository}, as {@link service} defines
|
|
17
|
+
*
|
|
18
|
+
* @throws {@link !Error Error} While the feed is consumed, whatever the source reports while producing queries, or
|
|
19
|
+
* whatever the repository reports while running them
|
|
20
|
+
*
|
|
21
|
+
* @group Factories
|
|
22
|
+
*/
|
|
23
|
+
export declare function construct(repository?: Repository): Task<SPARQL, Graph>;
|
|
24
|
+
//# sourceMappingURL=construct.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"construct.d.ts","sourceRoot":"","sources":["../src/construct.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AASjE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CActE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 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 { clip, tidy } from "@grafctory/core/strings";
|
|
17
|
+
import { map } from "@grafctory/flow/tasks";
|
|
18
|
+
import { service } from "@grafctory/gear";
|
|
19
|
+
import { log, report, time } from "@grafctory/tape";
|
|
20
|
+
import { createRepository } from "./index.js";
|
|
21
|
+
const logger = log(import.meta.url);
|
|
22
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
/**
|
|
24
|
+
* Creates a task running a feed of SPARQL `CONSTRUCT` queries against a SPARQL repository.
|
|
25
|
+
*
|
|
26
|
+
* The task emits the graph built by each query, in query order, ready to be stored by an {@link upload} sink. Every
|
|
27
|
+
* query runs on its own, outside any transaction, so successive queries may observe different states of a repository
|
|
28
|
+
* that is updated by other clients or by other steps of the same pipeline while the feed is being consumed.
|
|
29
|
+
*
|
|
30
|
+
* @param repository The target repository; defaults to the {@link createRepository} service
|
|
31
|
+
*
|
|
32
|
+
* @returns A task converting a feed of `CONSTRUCT` queries into the feed of graphs they build
|
|
33
|
+
*
|
|
34
|
+
* @throws {@link !Error Error} If `repository` is omitted, and either no execution is running or the running one binds
|
|
35
|
+
* no repository to {@link createRepository}, as {@link service} defines
|
|
36
|
+
*
|
|
37
|
+
* @throws {@link !Error Error} While the feed is consumed, whatever the source reports while producing queries, or
|
|
38
|
+
* whatever the repository reports while running them
|
|
39
|
+
*
|
|
40
|
+
* @group Factories
|
|
41
|
+
*/
|
|
42
|
+
export function construct(repository) {
|
|
43
|
+
const $repository = repository ?? service(createRepository);
|
|
44
|
+
return map(query => {
|
|
45
|
+
logger.info `construct <${clip(tidy(query), 50)}>`;
|
|
46
|
+
return time(() => $repository.construct(query), (triples, elapsed) => {
|
|
47
|
+
logger.info `constructed <${report(triples.length)}> triples in <${report(elapsed)}> ms`;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=construct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"construct.js","sourceRoot":"","sources":["../src/construct.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAGpC,wHAAwH;AAExH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,UAAuB;IAEhD,MAAM,WAAW,GAAG,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE5D,OAAO,GAAG,CAAC,KAAK,CAAC,EAAE;QAElB,MAAM,CAAC,IAAI,CAAA,cAAc,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC;QAElD,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;YACpE,MAAM,CAAC,IAAI,CAAA,gBAAgB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACzF,CAAC,CAAC,CAAC;IAEJ,CAAC,CAAC,CAAC;AAEJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPARQL processing tasks.
|
|
3
|
+
*
|
|
4
|
+
* Provides ready-made {@link https://github.com/grafctory/flow @grafctory/flow} steps for working with SPARQL
|
|
5
|
+
* repositories in pipelines run by the {@link https://github.com/grafctory/gear @grafctory/gear} executor.
|
|
6
|
+
*
|
|
7
|
+
* A job binds a repository connector to {@link createRepository} once, and steps use that one unless given their own.
|
|
8
|
+
*
|
|
9
|
+
* @module index
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://www.w3.org/TR/sparql11-overview/ SPARQL 1.1 Overview}
|
|
12
|
+
*/
|
|
13
|
+
import type { Repository } from "@grafctory/wire-sparql";
|
|
14
|
+
/**
|
|
15
|
+
* Creates the default repository.
|
|
16
|
+
*
|
|
17
|
+
* Identifies the repository service the tasks and sinks of this package target.
|
|
18
|
+
*
|
|
19
|
+
* > [!IMPORTANT]
|
|
20
|
+
* >
|
|
21
|
+
* > No default is provided: a job must bind a repository connector before creating tasks that rely on it.
|
|
22
|
+
*
|
|
23
|
+
* @returns Never: the repository service has no default implementation
|
|
24
|
+
*
|
|
25
|
+
* @throws {@link !Error Error} Always, as no repository connector is bound to the service in the enclosing execution
|
|
26
|
+
*/
|
|
27
|
+
export declare function createRepository(): Repository;
|
|
28
|
+
export * from "./select.js";
|
|
29
|
+
export * from "./construct.js";
|
|
30
|
+
export * from "./update.js";
|
|
31
|
+
export * from "./upload.js";
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKzD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,IAAI,UAAU,CAI7C;AAKD,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 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
|
+
/**
|
|
18
|
+
* Creates the default repository.
|
|
19
|
+
*
|
|
20
|
+
* Identifies the repository service the tasks and sinks of this package target.
|
|
21
|
+
*
|
|
22
|
+
* > [!IMPORTANT]
|
|
23
|
+
* >
|
|
24
|
+
* > No default is provided: a job must bind a repository connector before creating tasks that rely on it.
|
|
25
|
+
*
|
|
26
|
+
* @returns Never: the repository service has no default implementation
|
|
27
|
+
*
|
|
28
|
+
* @throws {@link !Error Error} Always, as no repository connector is bound to the service in the enclosing execution
|
|
29
|
+
*/
|
|
30
|
+
export function createRepository() {
|
|
31
|
+
throw new Error("undefined repository service");
|
|
32
|
+
}
|
|
33
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
34
|
+
export * from "./select.js";
|
|
35
|
+
export * from "./construct.js";
|
|
36
|
+
export * from "./update.js";
|
|
37
|
+
export * from "./upload.js";
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkBH,wHAAwH;AAExH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB;IAE/B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;AAEjD,CAAC;AAGD,wHAAwH;AAExH,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
package/dist/select.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Task } from "@grafctory/flow";
|
|
2
|
+
import type { Repository, SPARQL, Tuple } from "@grafctory/wire-sparql";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a task running a feed of SPARQL `SELECT` queries against a SPARQL repository.
|
|
5
|
+
*
|
|
6
|
+
* The task emits the tuples matched by each query as a single feed, in query order. Every query runs on its own,
|
|
7
|
+
* outside any transaction, so successive queries may observe different states of a repository that is updated by other
|
|
8
|
+
* clients or by other steps of the same pipeline while the feed is being consumed.
|
|
9
|
+
*
|
|
10
|
+
* @param repository The target repository; defaults to the {@link createRepository} service
|
|
11
|
+
*
|
|
12
|
+
* @returns A task converting a feed of `SELECT` queries into the feed of tuples they match
|
|
13
|
+
*
|
|
14
|
+
* @throws {@link !Error Error} If `repository` is omitted, and either no execution is running or the running one binds
|
|
15
|
+
* no repository to {@link createRepository}, as {@link service} defines
|
|
16
|
+
*
|
|
17
|
+
* @throws {@link !Error Error} While the feed is consumed, whatever the source reports while producing queries, or
|
|
18
|
+
* whatever the repository reports while running them
|
|
19
|
+
*
|
|
20
|
+
* @group Factories
|
|
21
|
+
*/
|
|
22
|
+
export declare function select(repository?: Repository): Task<SPARQL, Tuple>;
|
|
23
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../src/select.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AASxE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAcnE"}
|
package/dist/select.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 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 { clip, tidy } from "@grafctory/core/strings";
|
|
17
|
+
import { flat, map } from "@grafctory/flow/tasks";
|
|
18
|
+
import { service } from "@grafctory/gear";
|
|
19
|
+
import { log, report, time } from "@grafctory/tape";
|
|
20
|
+
import { createRepository } from "./index.js";
|
|
21
|
+
const logger = log(import.meta.url);
|
|
22
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
23
|
+
/**
|
|
24
|
+
* Creates a task running a feed of SPARQL `SELECT` queries against a SPARQL repository.
|
|
25
|
+
*
|
|
26
|
+
* The task emits the tuples matched by each query as a single feed, in query order. Every query runs on its own,
|
|
27
|
+
* outside any transaction, so successive queries may observe different states of a repository that is updated by other
|
|
28
|
+
* clients or by other steps of the same pipeline while the feed is being consumed.
|
|
29
|
+
*
|
|
30
|
+
* @param repository The target repository; defaults to the {@link createRepository} service
|
|
31
|
+
*
|
|
32
|
+
* @returns A task converting a feed of `SELECT` queries into the feed of tuples they match
|
|
33
|
+
*
|
|
34
|
+
* @throws {@link !Error Error} If `repository` is omitted, and either no execution is running or the running one binds
|
|
35
|
+
* no repository to {@link createRepository}, as {@link service} defines
|
|
36
|
+
*
|
|
37
|
+
* @throws {@link !Error Error} While the feed is consumed, whatever the source reports while producing queries, or
|
|
38
|
+
* whatever the repository reports while running them
|
|
39
|
+
*
|
|
40
|
+
* @group Factories
|
|
41
|
+
*/
|
|
42
|
+
export function select(repository) {
|
|
43
|
+
const $repository = repository ?? service(createRepository);
|
|
44
|
+
return flat(map(query => {
|
|
45
|
+
logger.info `select <${clip(tidy(query), 50)}>`;
|
|
46
|
+
return time(() => $repository.select(query), (tuples, elapsed) => {
|
|
47
|
+
logger.info `selected <${report(tuples.length)}> tuples in <${report(elapsed)}> ms`;
|
|
48
|
+
});
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../src/select.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAGpC,wHAAwH;AAExH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,MAAM,CAAC,UAAuB;IAE7C,MAAM,WAAW,GAAG,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE5D,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QAEvB,MAAM,CAAC,IAAI,CAAA,WAAW,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC;QAE/C,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE;YAChE,MAAM,CAAC,IAAI,CAAA,aAAa,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACpF,CAAC,CAAC,CAAC;IAEJ,CAAC,CAAC,CAAC,CAAC;AAEL,CAAC"}
|
package/dist/update.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Sink } from "@grafctory/flow";
|
|
2
|
+
import type { Repository, SPARQL } from "@grafctory/wire-sparql";
|
|
3
|
+
/**
|
|
4
|
+
* Creates a sink applying a feed of SPARQL Update requests to a SPARQL repository.
|
|
5
|
+
*
|
|
6
|
+
* The sink applies the requests one at a time, in feed order, and resolves to their count. Every request runs on its
|
|
7
|
+
* own, outside any transaction: a failing request rejects the sink, but the requests before it stay applied.
|
|
8
|
+
*
|
|
9
|
+
* @param repository The target repository; defaults to the {@link createRepository} service
|
|
10
|
+
*
|
|
11
|
+
* @returns A sink applying each request in the feed and resolving to the number of applied requests
|
|
12
|
+
*
|
|
13
|
+
* @throws {@link !Error Error} If `repository` is omitted, and either no execution is running or the running one binds
|
|
14
|
+
* no repository to {@link createRepository}, as {@link service} defines
|
|
15
|
+
*
|
|
16
|
+
* @throws {@link !Error Error} While the feed is consumed, whatever the source reports while producing requests, or
|
|
17
|
+
* whatever the repository reports while applying them
|
|
18
|
+
*
|
|
19
|
+
* @group Factories
|
|
20
|
+
*/
|
|
21
|
+
export declare function update(repository?: Repository): Sink<SPARQL, number>;
|
|
22
|
+
//# sourceMappingURL=update.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAQ,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAMlD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AASjE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBpE"}
|
package/dist/update.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 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 { clip, tidy } from "@grafctory/core/strings";
|
|
17
|
+
import { pipe } from "@grafctory/flow";
|
|
18
|
+
import { items } from "@grafctory/flow/feeds";
|
|
19
|
+
import { count } from "@grafctory/flow/sinks";
|
|
20
|
+
import { map } from "@grafctory/flow/tasks";
|
|
21
|
+
import { service } from "@grafctory/gear";
|
|
22
|
+
import { log, report, time } from "@grafctory/tape";
|
|
23
|
+
import { createRepository } from "./index.js";
|
|
24
|
+
const logger = log(import.meta.url);
|
|
25
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
26
|
+
/**
|
|
27
|
+
* Creates a sink applying a feed of SPARQL Update requests to a SPARQL repository.
|
|
28
|
+
*
|
|
29
|
+
* The sink applies the requests one at a time, in feed order, and resolves to their count. Every request runs on its
|
|
30
|
+
* own, outside any transaction: a failing request rejects the sink, but the requests before it stay applied.
|
|
31
|
+
*
|
|
32
|
+
* @param repository The target repository; defaults to the {@link createRepository} service
|
|
33
|
+
*
|
|
34
|
+
* @returns A sink applying each request in the feed and resolving to the number of applied requests
|
|
35
|
+
*
|
|
36
|
+
* @throws {@link !Error Error} If `repository` is omitted, and either no execution is running or the running one binds
|
|
37
|
+
* no repository to {@link createRepository}, as {@link service} defines
|
|
38
|
+
*
|
|
39
|
+
* @throws {@link !Error Error} While the feed is consumed, whatever the source reports while producing requests, or
|
|
40
|
+
* whatever the repository reports while applying them
|
|
41
|
+
*
|
|
42
|
+
* @group Factories
|
|
43
|
+
*/
|
|
44
|
+
export function update(repository) {
|
|
45
|
+
const $repository = repository ?? service(createRepository);
|
|
46
|
+
return feed => pipe(items(feed)(map(request => {
|
|
47
|
+
logger.info `update <${clip(tidy(request), 50)}>`;
|
|
48
|
+
return time(() => $repository.update(request), (_, elapsed) => {
|
|
49
|
+
logger.info `updated in <${report(elapsed)}> ms`;
|
|
50
|
+
});
|
|
51
|
+
}))(count()));
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=update.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../src/update.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAa,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAGpC,wHAAwH;AAExH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAC,UAAuB;IAE7C,MAAM,WAAW,GAAG,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE5D,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAClB,KAAK,CAAC,IAAI,CAAC,CACV,GAAG,CAAC,OAAO,CAAC,EAAE;QAEd,MAAM,CAAC,IAAI,CAAA,WAAW,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC;QAEjD,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE;YAC7D,MAAM,CAAC,IAAI,CAAA,eAAe,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACjD,CAAC,CAAC,CAAC;IAEJ,CAAC,CAAC,CAAC,CACF,KAAK,EAAE,CAAC,CACT,CAAC;AAEH,CAAC"}
|
package/dist/upload.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { IRI } from "@grafctory/core/resource";
|
|
2
|
+
import { type Sink } from "@grafctory/flow";
|
|
3
|
+
import type { Graph } from "@grafctory/trio";
|
|
4
|
+
import type { Repository } from "@grafctory/wire-sparql";
|
|
5
|
+
/**
|
|
6
|
+
* Creates a sink storing a feed of RDF graphs into a SPARQL repository.
|
|
7
|
+
*
|
|
8
|
+
* The sink adds the statements of every graph to the target graph, then resolves to the total number of statements it
|
|
9
|
+
* stored. With `clear` set, the target graph is emptied first, so that after the upload it holds exactly the statements
|
|
10
|
+
* in the feed; an empty feed then leaves the target graph empty rather than untouched.
|
|
11
|
+
*
|
|
12
|
+
* By default the upload is atomic: the sink collects the whole feed in memory, then stores it, clearing included, in a
|
|
13
|
+
* single repository transaction. On repositories supporting transactions, a failure leaves the target graph as it was
|
|
14
|
+
* before the upload; the transaction stays open only while statements are written, however slowly the feed is produced.
|
|
15
|
+
*
|
|
16
|
+
* With `batch` set, the sink stores each graph as soon as it arrives, in its own request and outside any transaction.
|
|
17
|
+
* Memory use stays bounded on feeds of any length, but a failure leaves the graphs stored so far in place, and an
|
|
18
|
+
* overwriting upload may leave the target graph cleared or only partially loaded.
|
|
19
|
+
*
|
|
20
|
+
* @param options The upload options
|
|
21
|
+
* @param options.clear Whether to overwrite the target graph, removing its existing statements before the upload;
|
|
22
|
+
* defaults to `false`, adding the uploaded statements to the ones the target graph already holds
|
|
23
|
+
* @param options.batch Whether to store each graph as it arrives, trading atomicity for bounded memory use;
|
|
24
|
+
* defaults to `false`, storing the whole feed in a single repository transaction
|
|
25
|
+
* @param options.repository The target repository; defaults to the {@link createRepository} service
|
|
26
|
+
* @param options.context The target named graph; defaults to the default graph
|
|
27
|
+
*
|
|
28
|
+
* @returns A sink storing each graph in the feed into the target graph and resolving to the number of stored statements
|
|
29
|
+
*
|
|
30
|
+
* @throws {@link !Error Error} If `options.repository` is omitted, and either no execution is running or the running
|
|
31
|
+
* one binds no repository to {@link createRepository}, as {@link service} defines
|
|
32
|
+
*
|
|
33
|
+
* @throws {@link !Error Error} While the feed is consumed, whatever the source reports while producing graphs, or
|
|
34
|
+
* whatever the repository reports while storing them
|
|
35
|
+
*
|
|
36
|
+
* @group Factories
|
|
37
|
+
*/
|
|
38
|
+
export declare function upload({ clear, batch, repository, context }?: {
|
|
39
|
+
readonly clear?: boolean;
|
|
40
|
+
readonly batch?: boolean;
|
|
41
|
+
readonly repository?: Repository;
|
|
42
|
+
readonly context?: IRI;
|
|
43
|
+
}): Sink<Graph, number>;
|
|
44
|
+
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAQ,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAMlD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,wBAAwB,CAAC;AAS3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,MAAM,CAAC,EAEtB,KAAa,EACb,KAAa,EAEb,UAAU,EACV,OAAO,EAEP,GAAE;IAEF,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAEzB,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC;CAElB,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CA8D3B"}
|
package/dist/upload.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © 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 { pipe } from "@grafctory/flow";
|
|
17
|
+
import { items } from "@grafctory/flow/feeds";
|
|
18
|
+
import { reduce, toArray } from "@grafctory/flow/sinks";
|
|
19
|
+
import { flat } from "@grafctory/flow/tasks";
|
|
20
|
+
import { service } from "@grafctory/gear";
|
|
21
|
+
import { log, report, time } from "@grafctory/tape";
|
|
22
|
+
import { createRepository } from "./index.js";
|
|
23
|
+
const logger = log(import.meta.url);
|
|
24
|
+
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
25
|
+
/**
|
|
26
|
+
* Creates a sink storing a feed of RDF graphs into a SPARQL repository.
|
|
27
|
+
*
|
|
28
|
+
* The sink adds the statements of every graph to the target graph, then resolves to the total number of statements it
|
|
29
|
+
* stored. With `clear` set, the target graph is emptied first, so that after the upload it holds exactly the statements
|
|
30
|
+
* in the feed; an empty feed then leaves the target graph empty rather than untouched.
|
|
31
|
+
*
|
|
32
|
+
* By default the upload is atomic: the sink collects the whole feed in memory, then stores it, clearing included, in a
|
|
33
|
+
* single repository transaction. On repositories supporting transactions, a failure leaves the target graph as it was
|
|
34
|
+
* before the upload; the transaction stays open only while statements are written, however slowly the feed is produced.
|
|
35
|
+
*
|
|
36
|
+
* With `batch` set, the sink stores each graph as soon as it arrives, in its own request and outside any transaction.
|
|
37
|
+
* Memory use stays bounded on feeds of any length, but a failure leaves the graphs stored so far in place, and an
|
|
38
|
+
* overwriting upload may leave the target graph cleared or only partially loaded.
|
|
39
|
+
*
|
|
40
|
+
* @param options The upload options
|
|
41
|
+
* @param options.clear Whether to overwrite the target graph, removing its existing statements before the upload;
|
|
42
|
+
* defaults to `false`, adding the uploaded statements to the ones the target graph already holds
|
|
43
|
+
* @param options.batch Whether to store each graph as it arrives, trading atomicity for bounded memory use;
|
|
44
|
+
* defaults to `false`, storing the whole feed in a single repository transaction
|
|
45
|
+
* @param options.repository The target repository; defaults to the {@link createRepository} service
|
|
46
|
+
* @param options.context The target named graph; defaults to the default graph
|
|
47
|
+
*
|
|
48
|
+
* @returns A sink storing each graph in the feed into the target graph and resolving to the number of stored statements
|
|
49
|
+
*
|
|
50
|
+
* @throws {@link !Error Error} If `options.repository` is omitted, and either no execution is running or the running
|
|
51
|
+
* one binds no repository to {@link createRepository}, as {@link service} defines
|
|
52
|
+
*
|
|
53
|
+
* @throws {@link !Error Error} While the feed is consumed, whatever the source reports while producing graphs, or
|
|
54
|
+
* whatever the repository reports while storing them
|
|
55
|
+
*
|
|
56
|
+
* @group Factories
|
|
57
|
+
*/
|
|
58
|
+
export function upload({ clear = false, batch = false, repository, context } = {}) {
|
|
59
|
+
const $repository = repository ?? service(createRepository);
|
|
60
|
+
const $context = context ?? "default graph";
|
|
61
|
+
return feed => time(async () => {
|
|
62
|
+
if (batch) { // an undefined count means nothing was written yet, so an overwrite stores the first graph
|
|
63
|
+
const count = await pipe(items(feed)(reduce((count, statements) => write($repository, statements, count), undefined)));
|
|
64
|
+
return count ?? (clear ? store($repository, []) : 0);
|
|
65
|
+
}
|
|
66
|
+
else { // drain the feed outside the transaction, so a slow feed never holds it open
|
|
67
|
+
const statements = await pipe((feed)(flat())(toArray()));
|
|
68
|
+
return $repository.execute(async (repository) => clear
|
|
69
|
+
? store(repository, statements)
|
|
70
|
+
: merge(repository, statements));
|
|
71
|
+
}
|
|
72
|
+
}, (count, elapsed) => {
|
|
73
|
+
logger.info `uploaded <${report(count)}> statements to <${$context}> in <${report(elapsed)}> ms`;
|
|
74
|
+
});
|
|
75
|
+
async function write(repository, statements, count) {
|
|
76
|
+
return (count ?? 0) + await (clear && count === undefined ? store : merge)(repository, statements);
|
|
77
|
+
}
|
|
78
|
+
async function merge(repository, statements) {
|
|
79
|
+
await repository.merge(statements, context);
|
|
80
|
+
return statements.length;
|
|
81
|
+
}
|
|
82
|
+
async function store(repository, statements) {
|
|
83
|
+
await repository.store(statements, context);
|
|
84
|
+
return statements.length;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=upload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.js","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,IAAI,EAAa,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAGpC,wHAAwH;AAExH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,UAAU,MAAM,CAAC,EAEtB,KAAK,GAAG,KAAK,EACb,KAAK,GAAG,KAAK,EAEb,UAAU,EACV,OAAO,KAUJ,EAAE;IAEL,MAAM,WAAW,GAAG,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,OAAO,IAAI,eAAe,CAAC;IAE5C,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;QAE9B,IAAK,KAAK,EAAG,CAAC,CAAC,2FAA2F;YAEzG,MAAM,KAAK,GAAG,MAAM,IAAI,CACvB,KAAK,CAAC,IAAI,CAAC,CACV,MAAM,CAA4B,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CACxD,KAAK,CAAC,WAAW,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,SAAS,CAChD,CAAC,CACF,CAAC;YAEF,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAEtD,CAAC;aAAM,CAAC,CAAC,6EAA6E;YAErF,MAAM,UAAU,GAAG,MAAM,IAAI,CAC5B,CAAC,IAAI,CAAC,CACL,IAAI,EAAE,CAAC,CACP,OAAO,EAAE,CAAC,CACX,CAAC;YAEF,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,EAAC,UAAU,EAAC,EAAE,CAAC,KAAK;gBACnD,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC;gBAC/B,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,CAC/B,CAAC;QAEH,CAAC;IAEF,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QAErB,MAAM,CAAC,IAAI,CAAA,aAAa,MAAM,CAAC,KAAK,CAAC,oBAAoB,QAAQ,SAAS,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;IAEjG,CAAC,CAAC,CAAC;IAGH,KAAK,UAAU,KAAK,CAAC,UAA4B,EAAE,UAAiB,EAAE,KAAyB;QAE9F,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,GAAC,MAAM,CAAC,KAAK,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAElG,CAAC;IAED,KAAK,UAAU,KAAK,CAAC,UAA4B,EAAE,UAAiB;QAEnE,MAAM,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE5C,OAAO,UAAU,CAAC,MAAM,CAAC;IAE1B,CAAC;IAED,KAAK,UAAU,KAAK,CAAC,UAA4B,EAAE,UAAiB;QAEnE,MAAM,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE5C,OAAO,UAAU,CAAC,MAAM,CAAC;IAE1B,CAAC;AAEF,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@grafctory/data-sparql",
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"description": "SPARQL processing tasks for @grafctory/data.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"pipeline",
|
|
8
|
+
"etl",
|
|
9
|
+
"data-integration",
|
|
10
|
+
"rdf",
|
|
11
|
+
"sparql"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://grafctory.github.io/data/",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/grafctory/data/issues",
|
|
16
|
+
"email": "info@grafctory.dev"
|
|
17
|
+
},
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "Metreeca",
|
|
21
|
+
"email": "info@metreeca.com",
|
|
22
|
+
"url": "https://www.metreeca.com/"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/grafctory/data.git",
|
|
27
|
+
"directory": "packages/data-sparql"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"@grafctory/source": "./src/index.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE",
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=22.22.0"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"clean": "ush rm dist docs node_modules",
|
|
47
|
+
"build": "ush rm dist && tsc -p tsconfig.build.json",
|
|
48
|
+
"check": "npx vitest --typecheck run"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@grafctory/core": "^0.14.0",
|
|
52
|
+
"@grafctory/flow": "^0.13.0",
|
|
53
|
+
"@grafctory/tape": "^0.13.0",
|
|
54
|
+
"@grafctory/trio": "^0.3.0",
|
|
55
|
+
"@grafctory/wire-sparql": "^0.13.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@grafctory/gear": "^0.6.0",
|
|
59
|
+
"@types/node": "^25.9.3",
|
|
60
|
+
"typescript": "^6.0.3",
|
|
61
|
+
"vitest": "^4.1.12"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"@grafctory/gear": "^0.6.0"
|
|
65
|
+
}
|
|
66
|
+
}
|