@origintrail-official/dkg-query 0.0.1-dev.1773506972.23bf9c0

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 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 2018 OriginTrail
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,29 @@
1
+ # @origintrail-official/dkg-query
2
+
3
+ SPARQL query engine for DKG V9. Provides paranet-scoped querying, Knowledge Asset resolution by UAL, and read-only query validation.
4
+
5
+ ## Features
6
+
7
+ - **DKGQueryEngine** — execute SPARQL SELECT, CONSTRUCT, ASK, and DESCRIBE queries against local triple stores
8
+ - **Paranet scoping** — queries are automatically scoped to the correct named graphs for a given paranet
9
+ - **KA resolution** — resolve a UAL to its constituent triples, metadata, and provenance
10
+ - **QueryHandler** — P2P protocol handler for serving remote SPARQL queries from other nodes
11
+ - **SPARQL guard** — `validateReadOnlySparql()` ensures incoming queries are read-only (no INSERT, DELETE, LOAD, etc.)
12
+
13
+ ## Usage
14
+
15
+ ```typescript
16
+ import { DKGQueryEngine } from '@origintrail-official/dkg-query';
17
+
18
+ const engine = new DKGQueryEngine(store);
19
+
20
+ const results = await engine.query({
21
+ sparql: 'SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10',
22
+ paranetId: 'urn:paranet:example',
23
+ });
24
+ ```
25
+
26
+ ## Internal Dependencies
27
+
28
+ - `@origintrail-official/dkg-core` — configuration, logging, protocol streams
29
+ - `@origintrail-official/dkg-storage` — triple store access for query execution
@@ -0,0 +1,24 @@
1
+ import type { TripleStore, Quad } from '@origintrail-official/dkg-storage';
2
+ import type { QueryResult, QueryOptions, QueryEngine } from './query-engine.js';
3
+ /**
4
+ * Local-only query engine that executes SPARQL against this node's own
5
+ * triple store. No remote query capability — by design (Spec §1.6 Store
6
+ * Isolation). All data must arrive via protocol messages (publish, access,
7
+ * sync) before it can be queried here.
8
+ */
9
+ export declare class DKGQueryEngine implements QueryEngine {
10
+ private readonly store;
11
+ private readonly graphManager;
12
+ constructor(store: TripleStore);
13
+ query(sparql: string, options?: QueryOptions): Promise<QueryResult>;
14
+ resolveKA(ual: string): Promise<{
15
+ rootEntity: string;
16
+ paranetId: string;
17
+ quads: Quad[];
18
+ }>;
19
+ /**
20
+ * Execute a query across all locally-stored paranets.
21
+ */
22
+ queryAllParanets(sparql: string): Promise<QueryResult>;
23
+ }
24
+ //# sourceMappingURL=dkg-query-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dkg-query-engine.d.ts","sourceRoot":"","sources":["../src/dkg-query-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,IAAI,EAAmC,MAAM,mCAAmC,CAAC;AAE5G,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhF;;;;;GAKG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAe;gBAEhC,KAAK,EAAE,WAAW;IAKxB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;IA4CnE,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QACpC,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,IAAI,EAAE,CAAC;KACf,CAAC;IA+CF;;OAEG;IACG,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAW7D"}
@@ -0,0 +1,184 @@
1
+ import { GraphManager } from '@origintrail-official/dkg-storage';
2
+ import { paranetDataGraphUri, paranetWorkspaceGraphUri, assertSafeIri, escapeSparqlLiteral } from '@origintrail-official/dkg-core';
3
+ import { validateReadOnlySparql } from './sparql-guard.js';
4
+ /**
5
+ * Local-only query engine that executes SPARQL against this node's own
6
+ * triple store. No remote query capability — by design (Spec §1.6 Store
7
+ * Isolation). All data must arrive via protocol messages (publish, access,
8
+ * sync) before it can be queried here.
9
+ */
10
+ export class DKGQueryEngine {
11
+ store;
12
+ graphManager;
13
+ constructor(store) {
14
+ this.store = store;
15
+ this.graphManager = new GraphManager(store);
16
+ }
17
+ async query(sparql, options) {
18
+ const guard = validateReadOnlySparql(sparql);
19
+ if (!guard.safe) {
20
+ throw new Error(`SPARQL rejected: ${guard.reason}`);
21
+ }
22
+ let effectiveSparql = sparql;
23
+ if (options?.paranetId && !sparql.toLowerCase().includes('from ')) {
24
+ const dataGraph = paranetDataGraphUri(options.paranetId);
25
+ const workspaceGraph = paranetWorkspaceGraphUri(options.paranetId);
26
+ if (options.includeWorkspace) {
27
+ const dataSparql = wrapWithGraph(sparql, dataGraph);
28
+ const workspaceSparql = wrapWithGraph(sparql, workspaceGraph);
29
+ const dataResult = await this.store.query(dataSparql);
30
+ const wsResult = await this.store.query(workspaceSparql);
31
+ return mergeWorkspaceAndDataResults(dataResult, wsResult);
32
+ }
33
+ if (options.graphSuffix === '_workspace') {
34
+ effectiveSparql = wrapWithGraph(sparql, workspaceGraph);
35
+ }
36
+ else {
37
+ effectiveSparql = wrapWithGraph(sparql, dataGraph);
38
+ }
39
+ }
40
+ const result = await this.store.query(effectiveSparql);
41
+ if (result.type === 'bindings') {
42
+ return { bindings: result.bindings };
43
+ }
44
+ if (result.type === 'quads') {
45
+ return {
46
+ bindings: [],
47
+ quads: result.quads,
48
+ };
49
+ }
50
+ if (result.type === 'boolean') {
51
+ return {
52
+ bindings: [{ result: String(result.value) }],
53
+ };
54
+ }
55
+ return { bindings: [] };
56
+ }
57
+ async resolveKA(ual) {
58
+ // Look up KA metadata across all meta graphs
59
+ const metaResult = await this.store.query(`SELECT ?rootEntity ?paranet WHERE {
60
+ GRAPH ?g {
61
+ ?ka <http://dkg.io/ontology/rootEntity> ?rootEntity .
62
+ ?ka <http://dkg.io/ontology/partOf> <${assertSafeIri(ual)}> .
63
+ <${assertSafeIri(ual)}> <http://dkg.io/ontology/paranet> ?paranet .
64
+ }
65
+ }`);
66
+ if (metaResult.type !== 'bindings' || metaResult.bindings.length === 0) {
67
+ throw new Error(`KA not found for UAL: ${ual}`);
68
+ }
69
+ const rootEntity = metaResult.bindings[0]['rootEntity'];
70
+ const paranetUri = metaResult.bindings[0]['paranet'];
71
+ const paranetId = paranetUri.replace('did:dkg:paranet:', '');
72
+ const dataGraph = paranetDataGraphUri(paranetId);
73
+ // Fetch all triples for this entity
74
+ const dataResult = await this.store.query(`SELECT ?s ?p ?o WHERE {
75
+ GRAPH <${assertSafeIri(dataGraph)}> {
76
+ ?s ?p ?o .
77
+ FILTER(
78
+ ?s = <${assertSafeIri(rootEntity)}>
79
+ || STRSTARTS(STR(?s), "${escapeSparqlLiteral(rootEntity)}/.well-known/genid/")
80
+ )
81
+ }
82
+ }`);
83
+ const quads = dataResult.type === 'bindings'
84
+ ? dataResult.bindings.map((row) => ({
85
+ subject: row['s'],
86
+ predicate: row['p'],
87
+ object: row['o'],
88
+ graph: dataGraph,
89
+ }))
90
+ : [];
91
+ return { rootEntity, paranetId, quads };
92
+ }
93
+ /**
94
+ * Execute a query across all locally-stored paranets.
95
+ */
96
+ async queryAllParanets(sparql) {
97
+ const paranets = await this.graphManager.listParanets();
98
+ const allBindings = [];
99
+ for (const paranetId of paranets) {
100
+ const result = await this.query(sparql, { paranetId });
101
+ allBindings.push(...result.bindings);
102
+ }
103
+ return { bindings: allBindings };
104
+ }
105
+ }
106
+ /**
107
+ * Wraps a SELECT query to scope it to a named graph.
108
+ * If the query already uses GRAPH patterns, returns it unchanged.
109
+ */
110
+ function wrapWithGraph(sparql, graphUri) {
111
+ if (sparql.toLowerCase().includes('graph '))
112
+ return sparql;
113
+ const whereIdx = sparql.search(/WHERE\s*\{/i);
114
+ if (whereIdx === -1)
115
+ return sparql;
116
+ const braceStart = sparql.indexOf('{', whereIdx);
117
+ let depth = 0;
118
+ let braceEnd = -1;
119
+ for (let i = braceStart; i < sparql.length; i++) {
120
+ if (sparql[i] === '{')
121
+ depth++;
122
+ else if (sparql[i] === '}') {
123
+ depth--;
124
+ if (depth === 0) {
125
+ braceEnd = i;
126
+ break;
127
+ }
128
+ }
129
+ }
130
+ if (braceEnd === -1)
131
+ return sparql;
132
+ const before = sparql.slice(0, braceStart + 1);
133
+ const inner = sparql.slice(braceStart + 1, braceEnd);
134
+ const after = sparql.slice(braceEnd);
135
+ return `${before} GRAPH <${graphUri}> { ${inner} } ${after}`;
136
+ }
137
+ function mergeWorkspaceAndDataResults(dataResult, wsResult) {
138
+ if (dataResult.type === 'quads' || wsResult.type === 'quads') {
139
+ const mergedQuads = dedupeQuads([
140
+ ...(dataResult.type === 'quads' ? dataResult.quads : []),
141
+ ...(wsResult.type === 'quads' ? wsResult.quads : []),
142
+ ]);
143
+ return { bindings: [], quads: mergedQuads };
144
+ }
145
+ if (dataResult.type === 'boolean' || wsResult.type === 'boolean') {
146
+ const value = (dataResult.type === 'boolean' ? dataResult.value : false)
147
+ || (wsResult.type === 'boolean' ? wsResult.value : false);
148
+ return { bindings: [{ result: String(value) }] };
149
+ }
150
+ const mergedBindings = dedupeBindings([
151
+ ...(dataResult.type === 'bindings' ? dataResult.bindings : []),
152
+ ...(wsResult.type === 'bindings' ? wsResult.bindings : []),
153
+ ]);
154
+ return { bindings: mergedBindings };
155
+ }
156
+ function dedupeBindings(bindings) {
157
+ const seen = new Set();
158
+ const out = [];
159
+ for (const row of bindings) {
160
+ const key = bindingKey(row);
161
+ if (seen.has(key))
162
+ continue;
163
+ seen.add(key);
164
+ out.push(row);
165
+ }
166
+ return out;
167
+ }
168
+ function bindingKey(row) {
169
+ const entries = Object.entries(row).sort(([a], [b]) => a.localeCompare(b));
170
+ return JSON.stringify(entries);
171
+ }
172
+ function dedupeQuads(quads) {
173
+ const seen = new Set();
174
+ const out = [];
175
+ for (const q of quads) {
176
+ const key = `${q.subject}\u0000${q.predicate}\u0000${q.object}\u0000${q.graph}`;
177
+ if (seen.has(key))
178
+ continue;
179
+ seen.add(key);
180
+ out.push(q);
181
+ }
182
+ return out;
183
+ }
184
+ //# sourceMappingURL=dkg-query-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dkg-query-engine.js","sourceRoot":"","sources":["../src/dkg-query-engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAuB,wBAAwB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACxJ,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACR,KAAK,CAAc;IACnB,YAAY,CAAe;IAE5C,YAAY,KAAkB;QAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,IAAI,YAAY,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,MAAc,EAAE,OAAsB;QAChD,MAAM,KAAK,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,oBAAoB,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,eAAe,GAAG,MAAM,CAAC;QAE7B,IAAI,OAAO,EAAE,SAAS,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAClE,MAAM,SAAS,GAAG,mBAAmB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACzD,MAAM,cAAc,GAAG,wBAAwB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACnE,IA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Aa,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,GAAG,GAAW,EAAE,CAAC;IACvB,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,SAAS,SAAS,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC;QAChF,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACd,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACd,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './query-engine.js';
2
+ export * from './query-types.js';
3
+ export { DKGQueryEngine } from './dkg-query-engine.js';
4
+ export { QueryHandler } from './query-handler.js';
5
+ export { validateReadOnlySparql, type SparqlGuardResult } from './sparql-guard.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './query-engine.js';
2
+ export * from './query-types.js';
3
+ export { DKGQueryEngine } from './dkg-query-engine.js';
4
+ export { QueryHandler } from './query-handler.js';
5
+ export { validateReadOnlySparql } from './sparql-guard.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAA0B,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Quad } from '@origintrail-official/dkg-storage';
2
+ export interface QueryResult {
3
+ bindings: Array<Record<string, string>>;
4
+ quads?: Quad[];
5
+ }
6
+ export interface QueryOptions {
7
+ paranetId?: string;
8
+ timeout?: number;
9
+ /** When set to '_workspace', query runs over the paranet's workspace graph only. */
10
+ graphSuffix?: '_workspace';
11
+ /** When true and paranetId is set, query runs over both data and workspace graphs (union). */
12
+ includeWorkspace?: boolean;
13
+ }
14
+ export interface QueryEngine {
15
+ query(sparql: string, options?: QueryOptions): Promise<QueryResult>;
16
+ resolveKA(ual: string): Promise<{
17
+ rootEntity: string;
18
+ paranetId: string;
19
+ quads: Quad[];
20
+ }>;
21
+ }
22
+ //# sourceMappingURL=query-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-engine.d.ts","sourceRoot":"","sources":["../src/query-engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mCAAmC,CAAC;AAE9D,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,8FAA8F;IAC9F,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACpE,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC,CAAC;CAC3F"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=query-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-engine.js","sourceRoot":"","sources":["../src/query-engine.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import type { PeerId } from '@origintrail-official/dkg-core';
2
+ import type { DKGQueryEngine } from './dkg-query-engine.js';
3
+ import type { QueryRequest, QueryResponse, QueryAccessConfig } from './query-types.js';
4
+ /**
5
+ * Handles incoming cross-agent query requests over the
6
+ * /dkg/query/2.0.0 libp2p protocol.
7
+ *
8
+ * Evaluates access policy, rate limits, dispatches to the local query
9
+ * engine, and enforces result size limits.
10
+ */
11
+ export declare class QueryHandler {
12
+ private readonly queryEngine;
13
+ private readonly config;
14
+ private readonly rateBuckets;
15
+ private readonly defaultRatePerMinute;
16
+ constructor(queryEngine: DKGQueryEngine, config: QueryAccessConfig);
17
+ /**
18
+ * StreamHandler-compatible entry point.
19
+ * Decodes the request JSON, processes it, returns response JSON.
20
+ */
21
+ get handler(): (data: Uint8Array, peerId: PeerId) => Promise<Uint8Array>;
22
+ handle(request: QueryRequest, peerId: string): Promise<QueryResponse>;
23
+ private checkAccess;
24
+ private hasAnyPublicParanet;
25
+ private checkRateLimit;
26
+ private lookupByUAL;
27
+ private lookupByType;
28
+ private lookupEntityTriples;
29
+ private executeSparql;
30
+ private enforceResultSize;
31
+ }
32
+ //# sourceMappingURL=query-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-handler.d.ts","sourceRoot":"","sources":["../src/query-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAI7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,iBAAiB,EAIlB,MAAM,kBAAkB,CAAC;AAa1B;;;;;;GAMG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAiB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAiC;IAC7D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAS;gBAElC,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,iBAAiB;IAMlE;;;OAGG;IACH,IAAI,OAAO,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAavE;IAEK,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAoD3E,OAAO,CAAC,WAAW;IAiDnB,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,cAAc;YAsBR,WAAW;YA6BX,YAAY;YAyBZ,mBAAmB;YA0BnB,aAAa;IA2D3B,OAAO,CAAC,iBAAiB;CAW1B"}
@@ -0,0 +1,281 @@
1
+ import { paranetDataGraphUri, assertSafeIri } from '@origintrail-official/dkg-core';
2
+ import { stripLiteralsAndComments } from './sparql-utils.js';
3
+ import { validateReadOnlySparql } from './sparql-guard.js';
4
+ const DEFAULT_LIMIT = 100;
5
+ const MAX_LIMIT = 1000;
6
+ const DEFAULT_TIMEOUT_MS = 5000;
7
+ const MAX_TIMEOUT_MS = 30000;
8
+ const MAX_RESULT_BYTES = 1_048_576; // 1 MB
9
+ /**
10
+ * Handles incoming cross-agent query requests over the
11
+ * /dkg/query/2.0.0 libp2p protocol.
12
+ *
13
+ * Evaluates access policy, rate limits, dispatches to the local query
14
+ * engine, and enforces result size limits.
15
+ */
16
+ export class QueryHandler {
17
+ queryEngine;
18
+ config;
19
+ rateBuckets = new Map();
20
+ defaultRatePerMinute;
21
+ constructor(queryEngine, config) {
22
+ this.queryEngine = queryEngine;
23
+ this.config = config;
24
+ this.defaultRatePerMinute = config.rateLimitPerMinute ?? 60;
25
+ }
26
+ /**
27
+ * StreamHandler-compatible entry point.
28
+ * Decodes the request JSON, processes it, returns response JSON.
29
+ */
30
+ get handler() {
31
+ return async (data, peerId) => {
32
+ let request;
33
+ try {
34
+ const text = new TextDecoder().decode(data);
35
+ request = JSON.parse(text);
36
+ }
37
+ catch {
38
+ return encode(errorResponse('', 'ERROR', 'Invalid request: malformed JSON'));
39
+ }
40
+ const response = await this.handle(request, peerId.toString());
41
+ return encode(response);
42
+ };
43
+ }
44
+ async handle(request, peerId) {
45
+ const opId = request.operationId ?? '';
46
+ // Validate request structure
47
+ if (request.lookupType === undefined || request.lookupType === null) {
48
+ return errorResponse(opId, 'ERROR', 'Invalid request: missing lookupType');
49
+ }
50
+ // Resolve paranet (ENTITY_BY_UAL doesn't need it upfront)
51
+ const paranetId = request.paranetId;
52
+ if (request.lookupType !== 'ENTITY_BY_UAL' && !paranetId) {
53
+ return errorResponse(opId, 'ERROR', 'Invalid request: paranetId is required for this lookup type');
54
+ }
55
+ // Access policy check
56
+ const accessResult = this.checkAccess(request.lookupType, paranetId, peerId);
57
+ if (accessResult)
58
+ return { ...accessResult, operationId: opId };
59
+ // Rate limit check
60
+ const rateResult = this.checkRateLimit(peerId);
61
+ if (rateResult)
62
+ return { ...rateResult, operationId: opId };
63
+ // Dispatch to lookup handler
64
+ try {
65
+ const limit = Math.min(request.limit ?? DEFAULT_LIMIT, MAX_LIMIT);
66
+ const timeout = Math.min(request.timeout ?? DEFAULT_TIMEOUT_MS, MAX_TIMEOUT_MS);
67
+ let response;
68
+ switch (request.lookupType) {
69
+ case 'ENTITY_BY_UAL':
70
+ response = await this.lookupByUAL(opId, request.ual);
71
+ break;
72
+ case 'ENTITIES_BY_TYPE':
73
+ response = await this.lookupByType(opId, paranetId, request.rdfType, limit);
74
+ break;
75
+ case 'ENTITY_TRIPLES':
76
+ response = await this.lookupEntityTriples(opId, paranetId, request.entityUri);
77
+ break;
78
+ case 'SPARQL_QUERY':
79
+ response = await this.executeSparql(opId, paranetId, request.sparql, limit, timeout);
80
+ break;
81
+ default:
82
+ response = errorResponse(opId, 'UNSUPPORTED_LOOKUP', `Unknown lookup type: ${request.lookupType}`);
83
+ }
84
+ return this.enforceResultSize(response);
85
+ }
86
+ catch (err) {
87
+ return errorResponse(opId, 'ERROR', 'Internal error processing query');
88
+ }
89
+ }
90
+ checkAccess(lookupType, paranetId, peerId) {
91
+ const defaultPolicy = this.config.defaultPolicy ?? 'deny';
92
+ // For ENTITY_BY_UAL, we skip paranet-level check (UAL resolves internally)
93
+ if (lookupType === 'ENTITY_BY_UAL') {
94
+ if (defaultPolicy === 'deny' && !this.hasAnyPublicParanet()) {
95
+ return errorResponse('', 'ACCESS_DENIED', 'No paranets are queryable on this node');
96
+ }
97
+ return null;
98
+ }
99
+ const paranetConfig = this.config.paranets?.[paranetId];
100
+ if (!paranetConfig) {
101
+ if (defaultPolicy === 'deny') {
102
+ return errorResponse('', 'ACCESS_DENIED', `Paranet '${paranetId}' is not queryable`);
103
+ }
104
+ // defaultPolicy is 'public' — allow with default lookup types
105
+ return null;
106
+ }
107
+ // Check peer access
108
+ if (paranetConfig.policy === 'deny') {
109
+ return errorResponse('', 'ACCESS_DENIED', `Paranet '${paranetId}' is not queryable`);
110
+ }
111
+ if (paranetConfig.policy === 'allowList') {
112
+ if (!paranetConfig.allowedPeers?.includes(peerId)) {
113
+ return errorResponse('', 'ACCESS_DENIED', 'Your peer ID is not in the allow list');
114
+ }
115
+ }
116
+ // Check lookup type
117
+ if (paranetConfig.allowedLookupTypes?.length) {
118
+ if (!paranetConfig.allowedLookupTypes.includes(lookupType)) {
119
+ return errorResponse('', 'UNSUPPORTED_LOOKUP', `Lookup type '${lookupType}' is not allowed for paranet '${paranetId}'`);
120
+ }
121
+ }
122
+ // Check SPARQL specifically
123
+ if (lookupType === 'SPARQL_QUERY' && !paranetConfig.sparqlEnabled) {
124
+ return errorResponse('', 'UNSUPPORTED_LOOKUP', `SPARQL queries are not enabled for paranet '${paranetId}'`);
125
+ }
126
+ return null;
127
+ }
128
+ hasAnyPublicParanet() {
129
+ if (this.config.defaultPolicy === 'public')
130
+ return true;
131
+ if (!this.config.paranets)
132
+ return false;
133
+ return Object.values(this.config.paranets).some(p => p.policy === 'public');
134
+ }
135
+ checkRateLimit(peerId) {
136
+ const now = Date.now();
137
+ let bucket = this.rateBuckets.get(peerId);
138
+ if (!bucket || now >= bucket.resetAt) {
139
+ bucket = { count: 0, resetAt: now + 60_000 };
140
+ this.rateBuckets.set(peerId, bucket);
141
+ }
142
+ bucket.count++;
143
+ if (bucket.count > this.defaultRatePerMinute) {
144
+ const retryAfter = Math.ceil((bucket.resetAt - now) / 1000);
145
+ return errorResponse('', 'RATE_LIMITED', `Rate limit exceeded. Retry after ${retryAfter} seconds`);
146
+ }
147
+ return null;
148
+ }
149
+ async lookupByUAL(opId, ual) {
150
+ if (!ual) {
151
+ return errorResponse(opId, 'ERROR', 'Invalid request: missing ual');
152
+ }
153
+ try {
154
+ const resolved = await this.queryEngine.resolveKA(ual);
155
+ const ntriples = resolved.quads
156
+ .map(q => `<${q.subject}> <${q.predicate}> ${formatObject(q.object)} .`)
157
+ .join('\n');
158
+ return {
159
+ operationId: opId,
160
+ status: 'OK',
161
+ ntriples,
162
+ truncated: false,
163
+ resultCount: resolved.quads.length,
164
+ };
165
+ }
166
+ catch {
167
+ return {
168
+ operationId: opId,
169
+ status: 'OK',
170
+ ntriples: '',
171
+ truncated: false,
172
+ resultCount: 0,
173
+ };
174
+ }
175
+ }
176
+ async lookupByType(opId, paranetId, rdfType, limit) {
177
+ if (!rdfType) {
178
+ return errorResponse(opId, 'ERROR', 'Invalid request: missing rdfType');
179
+ }
180
+ const dataGraph = paranetDataGraphUri(paranetId);
181
+ const sparql = `SELECT DISTINCT ?entity WHERE { GRAPH <${assertSafeIri(dataGraph)}> { ?entity a <${assertSafeIri(rdfType)}> } } LIMIT ${limit}`;
182
+ const result = await this.queryEngine.query(sparql);
183
+ const entityUris = result.bindings.map(b => b['entity']);
184
+ return {
185
+ operationId: opId,
186
+ status: 'OK',
187
+ entityUris,
188
+ truncated: entityUris.length >= limit,
189
+ resultCount: entityUris.length,
190
+ };
191
+ }
192
+ async lookupEntityTriples(opId, paranetId, entityUri) {
193
+ if (!entityUri) {
194
+ return errorResponse(opId, 'ERROR', 'Invalid request: missing entityUri');
195
+ }
196
+ const dataGraph = paranetDataGraphUri(paranetId);
197
+ const sparql = `SELECT ?p ?o WHERE { GRAPH <${assertSafeIri(dataGraph)}> { <${assertSafeIri(entityUri)}> ?p ?o } }`;
198
+ const result = await this.queryEngine.query(sparql);
199
+ const ntriples = result.bindings
200
+ .map(b => `<${entityUri}> <${b['p']}> ${formatObject(b['o'])} .`)
201
+ .join('\n');
202
+ return {
203
+ operationId: opId,
204
+ status: 'OK',
205
+ ntriples,
206
+ truncated: false,
207
+ resultCount: result.bindings.length,
208
+ };
209
+ }
210
+ async executeSparql(opId, paranetId, sparql, limit, timeout) {
211
+ if (!sparql) {
212
+ return errorResponse(opId, 'ERROR', 'Invalid request: missing sparql');
213
+ }
214
+ // Strip string literals and comments so regexes don't false-positive
215
+ // on keywords inside quoted values or variable names like ?graph.
216
+ const stripped = stripLiteralsAndComments(sparql);
217
+ if (/\bSERVICE\b/i.test(stripped)) {
218
+ return errorResponse(opId, 'ERROR', 'SERVICE clauses are not allowed in remote queries');
219
+ }
220
+ if (/\bGRAPH\s+/i.test(stripped)) {
221
+ return errorResponse(opId, 'ERROR', 'Explicit GRAPH clauses are not allowed in remote queries — queries are automatically scoped to the target paranet');
222
+ }
223
+ if (/\bFROM\s+/i.test(stripped)) {
224
+ return errorResponse(opId, 'ERROR', 'FROM/FROM NAMED clauses are not allowed in remote queries — queries are automatically scoped to the target paranet');
225
+ }
226
+ const guard = validateReadOnlySparql(sparql);
227
+ if (!guard.safe) {
228
+ return errorResponse(opId, 'ERROR', `SPARQL rejected: ${guard.reason}`);
229
+ }
230
+ // Execute with timeout
231
+ const result = await Promise.race([
232
+ this.queryEngine.query(sparql, { paranetId }),
233
+ new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), timeout)),
234
+ ]).catch(err => {
235
+ if (err.message === 'timeout') {
236
+ return { _timeout: true };
237
+ }
238
+ throw err;
239
+ });
240
+ if (result._timeout) {
241
+ return errorResponse(opId, 'GAS_LIMIT_EXCEEDED', `Query exceeded time limit (${timeout}ms)`);
242
+ }
243
+ const bindings = result.bindings.slice(0, limit);
244
+ return {
245
+ operationId: opId,
246
+ status: 'OK',
247
+ bindings: JSON.stringify(bindings),
248
+ truncated: result.bindings.length > limit,
249
+ resultCount: result.bindings.length,
250
+ };
251
+ }
252
+ enforceResultSize(response) {
253
+ const serialized = JSON.stringify(response);
254
+ if (serialized.length <= MAX_RESULT_BYTES)
255
+ return response;
256
+ return {
257
+ ...response,
258
+ truncated: true,
259
+ ntriples: response.ntriples?.slice(0, MAX_RESULT_BYTES) ?? response.ntriples,
260
+ bindings: response.bindings?.slice(0, MAX_RESULT_BYTES) ?? response.bindings,
261
+ };
262
+ }
263
+ }
264
+ function errorResponse(opId, status, error) {
265
+ return {
266
+ operationId: opId,
267
+ status,
268
+ truncated: false,
269
+ resultCount: 0,
270
+ error,
271
+ };
272
+ }
273
+ function formatObject(value) {
274
+ if (value.startsWith('"') || value.startsWith("'"))
275
+ return value;
276
+ return `<${value}>`;
277
+ }
278
+ function encode(response) {
279
+ return new TextEncoder().encode(JSON.stringify(response));
280
+ }
281
+ //# sourceMappingURL=query-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-handler.js","sourceRoot":"","sources":["../src/query-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAuB,MAAM,gCAAgC,CAAC;AACzG,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAW3D,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,gBAAgB,GAAG,SAAS,CAAC,CAAC,OAAO;AAO3C;;;;;;GAMG;AACH,MAAM,OAAO,YAAY;IACN,WAAW,CAAiB;IAC5B,MAAM,CAAoB;IAC1B,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC5C,oBAAoB,CAAS;IAE9C,YAAY,WAA2B,EAAE,MAAyB;QAChE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,kBAAkB,IAAI,EAAE,CAAC;IAC9D,CAAC;IAED;;;OAGG;IACH,IAAI,OAAO;QACT,OAAO,KAAK,EAAE,IAAgB,EAAE,MAAc,EAAuB,EAAE;YACrE,IAAI,OAAqB,CAAC;YAC1B,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC5C,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAiB,CAAC;YAC7C,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,MAAM,CAAC,a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mB,EAAE,KAAa;IACrE,OAAO;QACL,WAAW,EAAE,IAAI;QACjB,MAAM;QACN,SAAS,EAAE,KAAK;QAChB,WAAW,EAAE,CAAC;QACd,KAAK;KACN,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACjE,OAAO,IAAI,KAAK,GAAG,CAAC;AACtB,CAAC;AAED,SAAS,MAAM,CAAC,QAAuB;IACrC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,38 @@
1
+ export type LookupType = 'ENTITY_BY_UAL' | 'ENTITIES_BY_TYPE' | 'ENTITY_TRIPLES' | 'SPARQL_QUERY';
2
+ export type QueryStatus = 'OK' | 'ERROR' | 'ACCESS_DENIED' | 'RATE_LIMITED' | 'NOT_FOUND' | 'GAS_LIMIT_EXCEEDED' | 'UNSUPPORTED_LOOKUP';
3
+ export interface QueryRequest {
4
+ operationId: string;
5
+ lookupType: LookupType;
6
+ paranetId?: string;
7
+ ual?: string;
8
+ entityUri?: string;
9
+ rdfType?: string;
10
+ sparql?: string;
11
+ limit?: number;
12
+ timeout?: number;
13
+ }
14
+ export interface QueryResponse {
15
+ operationId: string;
16
+ status: QueryStatus;
17
+ ntriples?: string;
18
+ bindings?: string;
19
+ entityUris?: string[];
20
+ truncated: boolean;
21
+ resultCount: number;
22
+ gasConsumed?: number;
23
+ error?: string;
24
+ }
25
+ export interface ParanetQueryPolicy {
26
+ policy: 'deny' | 'public' | 'allowList';
27
+ allowedPeers?: string[];
28
+ allowedLookupTypes?: LookupType[];
29
+ sparqlEnabled?: boolean;
30
+ sparqlTimeout?: number;
31
+ sparqlMaxResults?: number;
32
+ }
33
+ export interface QueryAccessConfig {
34
+ defaultPolicy: 'deny' | 'public';
35
+ paranets?: Record<string, ParanetQueryPolicy>;
36
+ rateLimitPerMinute?: number;
37
+ }
38
+ //# sourceMappingURL=query-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-types.d.ts","sourceRoot":"","sources":["../src/query-types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAClB,eAAe,GACf,kBAAkB,GAClB,gBAAgB,GAChB,cAAc,CAAC;AAEnB,MAAM,MAAM,WAAW,GACnB,IAAI,GACJ,OAAO,GACP,eAAe,GACf,cAAc,GACd,WAAW,GACX,oBAAoB,GACpB,oBAAoB,CAAC;AAEzB,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAC;IACxC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,kBAAkB,CAAC,EAAE,UAAU,EAAE,CAAC;IAClC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,GAAG,QAAQ,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAC9C,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=query-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-types.js","sourceRoot":"","sources":["../src/query-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * SPARQL query safety guard.
3
+ *
4
+ * The DKG controls writes exclusively via the publish/update protocol.
5
+ * All user-facing SPARQL must be read-only (SELECT, CONSTRUCT, ASK, DESCRIBE).
6
+ * This module rejects any SPARQL that attempts mutation operations.
7
+ */
8
+ export interface SparqlGuardResult {
9
+ safe: boolean;
10
+ reason?: string;
11
+ }
12
+ /**
13
+ * Validates that a SPARQL query is read-only.
14
+ * Returns `{ safe: true }` for SELECT/CONSTRUCT/ASK/DESCRIBE.
15
+ * Returns `{ safe: false, reason }` for anything that could mutate data.
16
+ */
17
+ export declare function validateReadOnlySparql(sparql: string): SparqlGuardResult;
18
+ //# sourceMappingURL=sparql-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparql-guard.d.ts","sourceRoot":"","sources":["../src/sparql-guard.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwBH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAqBxE"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * SPARQL query safety guard.
3
+ *
4
+ * The DKG controls writes exclusively via the publish/update protocol.
5
+ * All user-facing SPARQL must be read-only (SELECT, CONSTRUCT, ASK, DESCRIBE).
6
+ * This module rejects any SPARQL that attempts mutation operations.
7
+ */
8
+ import { stripLiteralsAndComments } from './sparql-utils.js';
9
+ const MUTATING_KEYWORDS = [
10
+ 'INSERT',
11
+ 'DELETE',
12
+ 'LOAD',
13
+ 'CLEAR',
14
+ 'DROP',
15
+ 'CREATE',
16
+ 'COPY',
17
+ 'MOVE',
18
+ 'ADD',
19
+ ];
20
+ const MUTATING_PATTERN = new RegExp(`\\b(${MUTATING_KEYWORDS.join('|')})\\b`, 'i');
21
+ // Matches the query form keyword after optional PREFIX/BASE preamble
22
+ const READ_ONLY_FORMS = /^\s*(?:(?:PREFIX|BASE)\s+[^\n]*\n\s*)*(SELECT|CONSTRUCT|ASK|DESCRIBE)\b/i;
23
+ /**
24
+ * Validates that a SPARQL query is read-only.
25
+ * Returns `{ safe: true }` for SELECT/CONSTRUCT/ASK/DESCRIBE.
26
+ * Returns `{ safe: false, reason }` for anything that could mutate data.
27
+ */
28
+ export function validateReadOnlySparql(sparql) {
29
+ const stripped = stripLiteralsAndComments(sparql);
30
+ if (!READ_ONLY_FORMS.test(stripped)) {
31
+ return {
32
+ safe: false,
33
+ reason: `Query must start with SELECT, CONSTRUCT, ASK, or DESCRIBE. ` +
34
+ `Mutations must go through the publish/update protocol.`,
35
+ };
36
+ }
37
+ const match = MUTATING_PATTERN.exec(stripped);
38
+ if (match) {
39
+ return {
40
+ safe: false,
41
+ reason: `Query contains mutating keyword "${match[1]}". ` +
42
+ `Use the publish() or update() API to modify data.`,
43
+ };
44
+ }
45
+ return { safe: true };
46
+ }
47
+ //# sourceMappingURL=sparql-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparql-guard.js","sourceRoot":"","sources":["../src/sparql-guard.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,MAAM,iBAAiB,GAAG;IACxB,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,QAAQ;IACR,MAAM;IACN,MAAM;IACN,KAAK;CACG,CAAC;AAEX,MAAM,gBAAgB,GAAG,IAAI,MAAM,CACjC,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EACxC,GAAG,CACJ,CAAC;AAEF,qEAAqE;AACrE,MAAM,eAAe,GAAG,0EAA0E,CAAC;AAOnG;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAc;IACnD,MAAM,QAAQ,GAAG,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAElD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpC,OAAO;YACL,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,6DAA6D;gBACnE,wDAAwD;SAC3D,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,KAAK,EAAE,CAAC;QACV,OAAO;YACL,IAAI,EAAE,KAAK;YACX,MAAM,EAAE,oCAAoC,KAAK,CAAC,CAAC,CAAC,KAAK;gBACvD,mDAAmD;SACtD,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Linear-time state-machine that replaces string literals, IRIs, and
3
+ * line comments with spaces so keyword regexes only see "code" tokens.
4
+ *
5
+ * Handles: triple-quoted strings ("""/'''), regular strings ("/'),
6
+ * IRIs (<...> only when preceded by whitespace/start — not comparison
7
+ * operators like `< 1`), and line comments (# outside strings/IRIs).
8
+ *
9
+ * No regex backtracking — O(n) single pass, immune to ReDoS.
10
+ */
11
+ export declare function stripLiteralsAndComments(sparql: string): string;
12
+ //# sourceMappingURL=sparql-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparql-utils.d.ts","sourceRoot":"","sources":["../src/sparql-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAmE/D"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Linear-time state-machine that replaces string literals, IRIs, and
3
+ * line comments with spaces so keyword regexes only see "code" tokens.
4
+ *
5
+ * Handles: triple-quoted strings ("""/'''), regular strings ("/'),
6
+ * IRIs (<...> only when preceded by whitespace/start — not comparison
7
+ * operators like `< 1`), and line comments (# outside strings/IRIs).
8
+ *
9
+ * No regex backtracking — O(n) single pass, immune to ReDoS.
10
+ */
11
+ export function stripLiteralsAndComments(sparql) {
12
+ const out = new Array(sparql.length);
13
+ let i = 0;
14
+ const n = sparql.length;
15
+ while (i < n) {
16
+ const ch = sparql[i];
17
+ if ((ch === '"' || ch === "'") &&
18
+ sparql[i + 1] === ch &&
19
+ sparql[i + 2] === ch) {
20
+ const start = i;
21
+ i += 3;
22
+ while (i < n) {
23
+ if (sparql[i] === '\\') {
24
+ i += 2;
25
+ continue;
26
+ }
27
+ if (sparql[i] === ch && sparql[i + 1] === ch && sparql[i + 2] === ch) {
28
+ i += 3;
29
+ break;
30
+ }
31
+ i++;
32
+ }
33
+ for (let j = start; j < i && j < n; j++)
34
+ out[j] = ' ';
35
+ continue;
36
+ }
37
+ if (ch === '"' || ch === "'") {
38
+ const start = i;
39
+ i++;
40
+ while (i < n) {
41
+ if (sparql[i] === '\\') {
42
+ i += 2;
43
+ continue;
44
+ }
45
+ if (sparql[i] === ch) {
46
+ i++;
47
+ break;
48
+ }
49
+ i++;
50
+ }
51
+ for (let j = start; j < i && j < n; j++)
52
+ out[j] = ' ';
53
+ continue;
54
+ }
55
+ if (ch === '<') {
56
+ const prev = i > 0 ? sparql[i - 1] : '';
57
+ const isComparison = prev && (/[a-zA-Z0-9?$_]/.test(prev) || prev === ')' || prev === ']');
58
+ if (!isComparison) {
59
+ const next = sparql[i + 1];
60
+ if (next && (/[a-zA-Z]/.test(next) || next === '#' || next === '/' || next === '.' || next === '_')) {
61
+ const start = i;
62
+ i++;
63
+ while (i < n && sparql[i] !== '>' && sparql[i] !== '\n')
64
+ i++;
65
+ if (i < n && sparql[i] === '>')
66
+ i++;
67
+ for (let j = start; j < i; j++)
68
+ out[j] = ' ';
69
+ continue;
70
+ }
71
+ }
72
+ }
73
+ if (ch === '#') {
74
+ const start = i;
75
+ while (i < n && sparql[i] !== '\n')
76
+ i++;
77
+ for (let j = start; j < i; j++)
78
+ out[j] = ' ';
79
+ continue;
80
+ }
81
+ out[i] = ch;
82
+ i++;
83
+ }
84
+ return out.join('');
85
+ }
86
+ //# sourceMappingURL=sparql-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sparql-utils.js","sourceRoot":"","sources":["../src/sparql-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAc;IACrD,MAAM,GAAG,GAAG,IAAI,KAAK,CAAS,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IAExB,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACb,MAAM,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QAErB,IACE,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,CAAC;YAC1B,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE;YACpB,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EACpB,CAAC;YACD,MAAM,KAAK,GAAG,CAAC,CAAC;YAChB,CAAC,IAAI,CAAC,CAAC;YACP,OAAO,CAAC,GAAG,CAAC,EAAE,CAA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G,CAAC,EAAE,CAAC,EAAE;gBAAE,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YAC7C,SAAS;QACX,CAAC;QAED,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,EAAE,CAAC;IACN,CAAC;IAED,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACtB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@origintrail-official/dkg-query",
3
+ "version": "0.0.1-dev.1773506972.23bf9c0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "dependencies": {
8
+ "@origintrail-official/dkg-core": "0.0.1-dev.1773506972.23bf9c0",
9
+ "@origintrail-official/dkg-storage": "0.0.1-dev.1773506972.23bf9c0"
10
+ },
11
+ "devDependencies": {
12
+ "@vitest/coverage-v8": "^4.0.18",
13
+ "vitest": "^4.0.18"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "license": "Apache-2.0",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/OriginTrail/dkg-v9.git",
27
+ "directory": "packages/query"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "test": "vitest run",
32
+ "test:coverage": "vitest run --coverage",
33
+ "clean": "rm -rf dist tsconfig.tsbuildinfo"
34
+ }
35
+ }