@coasys/ad4m 0.12.0-rc1-dev.1 → 0.12.0-rc1-dev.2
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/jest.config.js +4 -4
- package/lib/index.cjs +5999 -6046
- package/lib/index.js +5977 -6040
- package/lib/src/Ad4mClient.d.ts +16 -9
- package/lib/src/Ad4mClient.js +25 -46
- package/lib/src/Ad4mClient.test.d.ts +1 -0
- package/lib/src/Ad4mClient.test.js +1204 -0
- package/lib/src/Literal.d.ts +2 -1
- package/lib/src/Literal.js +35 -38
- package/lib/src/Literal.test.d.ts +1 -0
- package/lib/src/Literal.test.js +41 -0
- package/lib/src/SmartLiteral.d.ts +2 -1
- package/lib/src/SmartLiteral.js +15 -30
- package/lib/src/agent/AgentClient.d.ts +4 -1
- package/lib/src/agent/AgentClient.js +99 -79
- package/lib/src/ai/AIClient.d.ts +2 -1
- package/lib/src/ai/AIClient.js +220 -224
- package/lib/src/expression/ExpressionClient.d.ts +1 -1
- package/lib/src/expression/ExpressionClient.js +86 -73
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/language/LanguageClient.d.ts +1 -1
- package/lib/src/language/LanguageClient.js +52 -52
- package/lib/src/model/Ad4mModel.d.ts +157 -937
- package/lib/src/model/Ad4mModel.js +212 -2799
- package/lib/src/model/Ad4mModel.test.js +1002 -561
- package/lib/src/model/decorators.d.ts +94 -426
- package/lib/src/model/decorators.js +333 -741
- package/lib/src/model/mutation.d.ts +81 -0
- package/lib/src/model/mutation.js +317 -0
- package/lib/src/model/parentUtils.d.ts +32 -0
- package/lib/src/model/parentUtils.js +64 -0
- package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
- package/lib/src/model/prolog/generatePrologFacts.js +139 -0
- package/lib/src/model/prolog/index.d.ts +1 -0
- package/lib/src/model/prolog/index.js +1 -0
- package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
- package/lib/src/model/query/ModelQueryBuilder.js +115 -0
- package/lib/src/model/query/QueryBuilder.d.ts +101 -0
- package/lib/src/model/query/QueryBuilder.js +193 -0
- package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
- package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
- package/lib/src/model/query/fetchInstance.d.ts +24 -0
- package/lib/src/model/query/fetchInstance.js +144 -0
- package/lib/src/model/query/hydration.d.ts +54 -0
- package/lib/src/model/query/hydration.js +214 -0
- package/lib/src/model/query/operations.d.ts +59 -0
- package/lib/src/model/query/operations.js +384 -0
- package/lib/src/model/query/snapshot.d.ts +59 -0
- package/lib/src/model/query/snapshot.js +106 -0
- package/lib/src/model/query/surrealCompiler.d.ts +42 -0
- package/lib/src/model/query/surrealCompiler.js +304 -0
- package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
- package/lib/src/model/schema/fromJSONSchema.js +264 -0
- package/lib/src/model/schema/metadata.d.ts +15 -0
- package/lib/src/model/schema/metadata.js +112 -0
- package/lib/src/model/subscription.d.ts +47 -0
- package/lib/src/model/subscription.js +231 -0
- package/lib/src/model/transaction.d.ts +27 -0
- package/lib/src/model/transaction.js +32 -0
- package/lib/src/model/types.d.ts +195 -0
- package/lib/src/model/types.js +8 -0
- package/lib/src/model/util.js +7 -7
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +5 -1
- package/lib/src/neighbourhood/NeighbourhoodClient.js +263 -181
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -1
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +13 -28
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +1 -5
- package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveClient.js +316 -240
- package/lib/src/perspectives/PerspectiveProxy.d.ts +54 -92
- package/lib/src/perspectives/PerspectiveProxy.js +803 -444
- package/lib/src/runtime/RuntimeClient.d.ts +5 -1
- package/lib/src/runtime/RuntimeClient.js +412 -238
- package/lib/src/shacl/SHACLFlow.test.js +164 -105
- package/lib/src/shacl/SHACLShape.d.ts +17 -3
- package/lib/src/shacl/SHACLShape.js +127 -90
- package/lib/src/shacl/SHACLShape.test.js +244 -176
- package/lib/src/utils.d.ts +8 -0
- package/lib/src/utils.js +21 -7
- package/package.json +8 -13
- package/src/Ad4mClient.test.ts +1564 -1315
- package/src/Ad4mClient.ts +55 -54
- package/src/Literal.test.ts +45 -26
- package/src/Literal.ts +82 -66
- package/src/SmartLiteral.ts +74 -58
- package/src/agent/AgentClient.ts +144 -99
- package/src/ai/AIClient.ts +409 -359
- package/src/expression/ExpressionClient.ts +142 -96
- package/src/index.ts +1 -1
- package/src/language/LanguageClient.ts +137 -113
- package/src/model/Ad4mModel.test.ts +1128 -647
- package/src/model/Ad4mModel.ts +485 -3249
- package/src/model/IMPROVEMENTS.md +482 -0
- package/src/model/PREDICATE_COLLISION_FIX.md +651 -0
- package/src/model/README.md +317 -0
- package/src/model/SHACL_MUTATION_DECOUPLING.md +356 -0
- package/src/model/SUBSCRIPTION_STRATEGY.md +317 -0
- package/src/model/TC39_STAGE_3_DECORATORS.md +609 -0
- package/src/model/decorators.ts +689 -1046
- package/src/model/mutation.ts +461 -0
- package/src/model/parentUtils.ts +91 -0
- package/src/model/prolog/generatePrologFacts.ts +176 -0
- package/src/model/prolog/index.ts +1 -0
- package/src/model/query/ModelQueryBuilder.ts +173 -0
- package/src/model/query/fetchInstance.ts +181 -0
- package/src/model/query/hydration.ts +273 -0
- package/src/model/query/operations.ts +510 -0
- package/src/model/query/snapshot.ts +126 -0
- package/src/model/query/surrealCompiler.ts +376 -0
- package/src/model/schema/fromJSONSchema.ts +411 -0
- package/src/model/schema/metadata.ts +148 -0
- package/src/model/subscription.ts +307 -0
- package/src/model/transaction.ts +60 -0
- package/src/model/types.ts +207 -0
- package/src/model/util.ts +47 -48
- package/src/neighbourhood/NeighbourhoodClient.ts +393 -251
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +3 -7
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -40
- package/src/perspectives/PerspectiveClient.ts +779 -540
- package/src/perspectives/PerspectiveProxy.ts +2860 -2053
- package/src/runtime/RuntimeClient.ts +775 -476
- package/src/shacl/SHACLFlow.test.ts +196 -129
- package/src/shacl/SHACLShape.test.ts +284 -190
- package/src/shacl/SHACLShape.ts +225 -172
- package/src/utils.ts +31 -17
- package/tsconfig.json +9 -10
- package/src/model/Subject.ts +0 -159
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
function extractNamespace(uri) {
|
|
10
10
|
// Handle hash fragments first (highest priority)
|
|
11
|
-
const hashIndex = uri.lastIndexOf(
|
|
11
|
+
const hashIndex = uri.lastIndexOf("#");
|
|
12
12
|
if (hashIndex !== -1) {
|
|
13
13
|
return uri.substring(0, hashIndex + 1);
|
|
14
14
|
}
|
|
@@ -16,7 +16,7 @@ function extractNamespace(uri) {
|
|
|
16
16
|
const protocolMatch = uri.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)(.*)$/);
|
|
17
17
|
if (protocolMatch) {
|
|
18
18
|
const afterScheme = protocolMatch[2];
|
|
19
|
-
const lastSlash = afterScheme.lastIndexOf(
|
|
19
|
+
const lastSlash = afterScheme.lastIndexOf("/");
|
|
20
20
|
if (lastSlash !== -1) {
|
|
21
21
|
// Has path segments - namespace includes up to last slash
|
|
22
22
|
return protocolMatch[1] + afterScheme.substring(0, lastSlash + 1);
|
|
@@ -30,7 +30,7 @@ function extractNamespace(uri) {
|
|
|
30
30
|
return colonMatch[1];
|
|
31
31
|
}
|
|
32
32
|
// Fallback: no clear namespace
|
|
33
|
-
return
|
|
33
|
+
return "";
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Escape special characters for Turtle string literals
|
|
@@ -38,13 +38,13 @@ function extractNamespace(uri) {
|
|
|
38
38
|
*/
|
|
39
39
|
function escapeTurtleString(value) {
|
|
40
40
|
return value
|
|
41
|
-
.replace(/\\/g,
|
|
41
|
+
.replace(/\\/g, "\\\\") // Backslash must be first
|
|
42
42
|
.replace(/"/g, '\\"') // Double quotes
|
|
43
|
-
.replace(/\n/g,
|
|
44
|
-
.replace(/\r/g,
|
|
45
|
-
.replace(/\t/g,
|
|
46
|
-
.replace(/\b/g,
|
|
47
|
-
.replace(/\f/g,
|
|
43
|
+
.replace(/\n/g, "\\n") // Newlines
|
|
44
|
+
.replace(/\r/g, "\\r") // Carriage returns
|
|
45
|
+
.replace(/\t/g, "\\t") // Tabs
|
|
46
|
+
.replace(/\b/g, "\\b") // Backspace
|
|
47
|
+
.replace(/\f/g, "\\f"); // Form feed
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Extract local name from a URI
|
|
@@ -56,12 +56,12 @@ function escapeTurtleString(value) {
|
|
|
56
56
|
*/
|
|
57
57
|
function extractLocalName(uri) {
|
|
58
58
|
// Handle hash fragments
|
|
59
|
-
const hashIndex = uri.lastIndexOf(
|
|
59
|
+
const hashIndex = uri.lastIndexOf("#");
|
|
60
60
|
if (hashIndex !== -1) {
|
|
61
61
|
return uri.substring(hashIndex + 1);
|
|
62
62
|
}
|
|
63
63
|
// Handle slash-based namespaces
|
|
64
|
-
const lastSlash = uri.lastIndexOf(
|
|
64
|
+
const lastSlash = uri.lastIndexOf("/");
|
|
65
65
|
if (lastSlash !== -1 && lastSlash < uri.length - 1) {
|
|
66
66
|
return uri.substring(lastSlash + 1);
|
|
67
67
|
}
|
|
@@ -106,6 +106,15 @@ export class SHACLShape {
|
|
|
106
106
|
addProperty(prop) {
|
|
107
107
|
this.properties.push(prop);
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Add a parent shape reference (sh:node) for SHACL inheritance.
|
|
111
|
+
* The child shape will reference the parent shape instead of duplicating its properties.
|
|
112
|
+
* @param parentShapeUri - URI of the parent SHACL shape
|
|
113
|
+
*/
|
|
114
|
+
addParentShape(parentShapeUri) {
|
|
115
|
+
this.parentShapes = this.parentShapes ?? [];
|
|
116
|
+
this.parentShapes.push(parentShapeUri);
|
|
117
|
+
}
|
|
109
118
|
/**
|
|
110
119
|
* Set constructor actions for this shape
|
|
111
120
|
*/
|
|
@@ -131,12 +140,23 @@ export class SHACLShape {
|
|
|
131
140
|
if (this.targetClass) {
|
|
132
141
|
turtle += ` sh:targetClass <${this.targetClass}> ;\n`;
|
|
133
142
|
}
|
|
143
|
+
// Emit sh:node references for parent shapes (SHACL inheritance)
|
|
144
|
+
if (this.parentShapes && this.parentShapes.length > 0) {
|
|
145
|
+
for (const parentUri of this.parentShapes) {
|
|
146
|
+
turtle += ` sh:node <${parentUri}> ;\n`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
134
149
|
// Add property shapes
|
|
135
150
|
for (let i = 0; i < this.properties.length; i++) {
|
|
136
151
|
const prop = this.properties[i];
|
|
137
152
|
const isLast = i === this.properties.length - 1;
|
|
138
153
|
turtle += ` sh:property [\n`;
|
|
139
|
-
|
|
154
|
+
if (prop.inversePath) {
|
|
155
|
+
turtle += ` sh:path [ sh:inversePath <${prop.path}> ] ;\n`;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
turtle += ` sh:path <${prop.path}> ;\n`;
|
|
159
|
+
}
|
|
140
160
|
if (prop.datatype) {
|
|
141
161
|
turtle += ` sh:datatype <${prop.datatype}> ;\n`;
|
|
142
162
|
}
|
|
@@ -165,11 +185,11 @@ export class SHACLShape {
|
|
|
165
185
|
if (prop.local !== undefined) {
|
|
166
186
|
turtle += ` ad4m:local ${prop.local} ;\n`;
|
|
167
187
|
}
|
|
168
|
-
if (prop.
|
|
169
|
-
turtle += ` ad4m:
|
|
188
|
+
if (prop.readOnly !== undefined) {
|
|
189
|
+
turtle += ` ad4m:readOnly ${prop.readOnly} ;\n`;
|
|
170
190
|
}
|
|
171
191
|
// Remove trailing semicolon and close bracket
|
|
172
|
-
turtle = turtle.slice(0, -2) +
|
|
192
|
+
turtle = turtle.slice(0, -2) + "\n";
|
|
173
193
|
turtle += isLast ? ` ] .\n` : ` ] ;\n`;
|
|
174
194
|
}
|
|
175
195
|
return turtle;
|
|
@@ -184,22 +204,35 @@ export class SHACLShape {
|
|
|
184
204
|
links.push({
|
|
185
205
|
source: this.nodeShapeUri,
|
|
186
206
|
predicate: "rdf://type",
|
|
187
|
-
target: "sh://NodeShape"
|
|
207
|
+
target: "sh://NodeShape",
|
|
188
208
|
});
|
|
189
209
|
// Target class
|
|
190
210
|
if (this.targetClass) {
|
|
191
211
|
links.push({
|
|
192
212
|
source: this.nodeShapeUri,
|
|
193
213
|
predicate: "sh://targetClass",
|
|
194
|
-
target: this.targetClass
|
|
214
|
+
target: this.targetClass,
|
|
195
215
|
});
|
|
196
216
|
}
|
|
197
|
-
//
|
|
198
|
-
if (this.
|
|
217
|
+
// Parent shape references (sh:node — SHACL inheritance)
|
|
218
|
+
if (this.parentShapes && this.parentShapes.length > 0) {
|
|
219
|
+
for (const parentUri of this.parentShapes) {
|
|
220
|
+
links.push({
|
|
221
|
+
source: this.nodeShapeUri,
|
|
222
|
+
predicate: "sh://node",
|
|
223
|
+
target: parentUri,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// Constructor actions – always emit this link (even for an empty array)
|
|
228
|
+
// so the Rust backend can distinguish "class registered but no init steps"
|
|
229
|
+
// from "class not registered", and create_subject can succeed with 0
|
|
230
|
+
// commands for classes that have no @Flag / initial-valued properties.
|
|
231
|
+
if (this.constructor_actions !== undefined) {
|
|
199
232
|
links.push({
|
|
200
233
|
source: this.nodeShapeUri,
|
|
201
234
|
predicate: "ad4m://constructor",
|
|
202
|
-
target: `literal://string:${JSON.stringify(this.constructor_actions)}
|
|
235
|
+
target: `literal://string:${JSON.stringify(this.constructor_actions)}`,
|
|
203
236
|
});
|
|
204
237
|
}
|
|
205
238
|
// Destructor actions
|
|
@@ -207,7 +240,7 @@ export class SHACLShape {
|
|
|
207
240
|
links.push({
|
|
208
241
|
source: this.nodeShapeUri,
|
|
209
242
|
predicate: "ad4m://destructor",
|
|
210
|
-
target: `literal://string:${JSON.stringify(this.destructor_actions)}
|
|
243
|
+
target: `literal://string:${JSON.stringify(this.destructor_actions)}`,
|
|
211
244
|
});
|
|
212
245
|
}
|
|
213
246
|
// Property shapes (each gets a named URI: {namespace}/{ClassName}.{propertyName})
|
|
@@ -230,69 +263,69 @@ export class SHACLShape {
|
|
|
230
263
|
links.push({
|
|
231
264
|
source: this.nodeShapeUri,
|
|
232
265
|
predicate: "sh://property",
|
|
233
|
-
target: propShapeId
|
|
266
|
+
target: propShapeId,
|
|
234
267
|
});
|
|
235
|
-
// Property path
|
|
268
|
+
// Property path (forward or inverse)
|
|
236
269
|
links.push({
|
|
237
270
|
source: propShapeId,
|
|
238
|
-
predicate: "sh://path",
|
|
239
|
-
target: prop.path
|
|
271
|
+
predicate: prop.inversePath ? "sh://inversePath" : "sh://path",
|
|
272
|
+
target: prop.path,
|
|
240
273
|
});
|
|
241
274
|
// Constraints
|
|
242
275
|
if (prop.datatype) {
|
|
243
276
|
links.push({
|
|
244
277
|
source: propShapeId,
|
|
245
278
|
predicate: "sh://datatype",
|
|
246
|
-
target: prop.datatype
|
|
279
|
+
target: prop.datatype,
|
|
247
280
|
});
|
|
248
281
|
}
|
|
249
282
|
if (prop.nodeKind) {
|
|
250
283
|
links.push({
|
|
251
284
|
source: propShapeId,
|
|
252
285
|
predicate: "sh://nodeKind",
|
|
253
|
-
target: `sh://${prop.nodeKind}
|
|
286
|
+
target: `sh://${prop.nodeKind}`,
|
|
254
287
|
});
|
|
255
288
|
}
|
|
256
289
|
if (prop.minCount !== undefined) {
|
|
257
290
|
links.push({
|
|
258
291
|
source: propShapeId,
|
|
259
292
|
predicate: "sh://minCount",
|
|
260
|
-
target: `literal://${prop.minCount}^^xsd:integer
|
|
293
|
+
target: `literal://${prop.minCount}^^xsd:integer`,
|
|
261
294
|
});
|
|
262
295
|
}
|
|
263
296
|
if (prop.maxCount !== undefined) {
|
|
264
297
|
links.push({
|
|
265
298
|
source: propShapeId,
|
|
266
299
|
predicate: "sh://maxCount",
|
|
267
|
-
target: `literal://${prop.maxCount}^^xsd:integer
|
|
300
|
+
target: `literal://${prop.maxCount}^^xsd:integer`,
|
|
268
301
|
});
|
|
269
302
|
}
|
|
270
303
|
if (prop.pattern) {
|
|
271
304
|
links.push({
|
|
272
305
|
source: propShapeId,
|
|
273
306
|
predicate: "sh://pattern",
|
|
274
|
-
target: `literal://${prop.pattern}
|
|
307
|
+
target: `literal://${prop.pattern}`,
|
|
275
308
|
});
|
|
276
309
|
}
|
|
277
310
|
if (prop.minInclusive !== undefined) {
|
|
278
311
|
links.push({
|
|
279
312
|
source: propShapeId,
|
|
280
313
|
predicate: "sh://minInclusive",
|
|
281
|
-
target: `literal://${prop.minInclusive}
|
|
314
|
+
target: `literal://${prop.minInclusive}`,
|
|
282
315
|
});
|
|
283
316
|
}
|
|
284
317
|
if (prop.maxInclusive !== undefined) {
|
|
285
318
|
links.push({
|
|
286
319
|
source: propShapeId,
|
|
287
320
|
predicate: "sh://maxInclusive",
|
|
288
|
-
target: `literal://${prop.maxInclusive}
|
|
321
|
+
target: `literal://${prop.maxInclusive}`,
|
|
289
322
|
});
|
|
290
323
|
}
|
|
291
324
|
if (prop.hasValue) {
|
|
292
325
|
links.push({
|
|
293
326
|
source: propShapeId,
|
|
294
327
|
predicate: "sh://hasValue",
|
|
295
|
-
target: `literal://${prop.hasValue}
|
|
328
|
+
target: `literal://${prop.hasValue}`,
|
|
296
329
|
});
|
|
297
330
|
}
|
|
298
331
|
// AD4M-specific metadata
|
|
@@ -300,21 +333,21 @@ export class SHACLShape {
|
|
|
300
333
|
links.push({
|
|
301
334
|
source: propShapeId,
|
|
302
335
|
predicate: "ad4m://local",
|
|
303
|
-
target: `literal://${prop.local}
|
|
336
|
+
target: `literal://${prop.local}`,
|
|
304
337
|
});
|
|
305
338
|
}
|
|
306
|
-
if (prop.
|
|
339
|
+
if (prop.readOnly !== undefined) {
|
|
307
340
|
links.push({
|
|
308
341
|
source: propShapeId,
|
|
309
|
-
predicate: "ad4m://
|
|
310
|
-
target: `literal://${prop.
|
|
342
|
+
predicate: "ad4m://readOnly",
|
|
343
|
+
target: `literal://${prop.readOnly}`,
|
|
311
344
|
});
|
|
312
345
|
}
|
|
313
346
|
if (prop.resolveLanguage) {
|
|
314
347
|
links.push({
|
|
315
348
|
source: propShapeId,
|
|
316
349
|
predicate: "ad4m://resolveLanguage",
|
|
317
|
-
target: `literal://string:${prop.resolveLanguage}
|
|
350
|
+
target: `literal://string:${prop.resolveLanguage}`,
|
|
318
351
|
});
|
|
319
352
|
}
|
|
320
353
|
// AD4M-specific actions
|
|
@@ -322,21 +355,21 @@ export class SHACLShape {
|
|
|
322
355
|
links.push({
|
|
323
356
|
source: propShapeId,
|
|
324
357
|
predicate: "ad4m://setter",
|
|
325
|
-
target: `literal://string:${JSON.stringify(prop.setter)}
|
|
358
|
+
target: `literal://string:${JSON.stringify(prop.setter)}`,
|
|
326
359
|
});
|
|
327
360
|
}
|
|
328
361
|
if (prop.adder && prop.adder.length > 0) {
|
|
329
362
|
links.push({
|
|
330
363
|
source: propShapeId,
|
|
331
364
|
predicate: "ad4m://adder",
|
|
332
|
-
target: `literal://string:${JSON.stringify(prop.adder)}
|
|
365
|
+
target: `literal://string:${JSON.stringify(prop.adder)}`,
|
|
333
366
|
});
|
|
334
367
|
}
|
|
335
368
|
if (prop.remover && prop.remover.length > 0) {
|
|
336
369
|
links.push({
|
|
337
370
|
source: propShapeId,
|
|
338
371
|
predicate: "ad4m://remover",
|
|
339
|
-
target: `literal://string:${JSON.stringify(prop.remover)}
|
|
372
|
+
target: `literal://string:${JSON.stringify(prop.remover)}`,
|
|
340
373
|
});
|
|
341
374
|
}
|
|
342
375
|
}
|
|
@@ -347,13 +380,13 @@ export class SHACLShape {
|
|
|
347
380
|
*/
|
|
348
381
|
static fromLinks(links, shapeUri) {
|
|
349
382
|
// Find target class
|
|
350
|
-
const targetClassLink = links.find(l => l.source === shapeUri && l.predicate === "sh://targetClass");
|
|
383
|
+
const targetClassLink = links.find((l) => l.source === shapeUri && l.predicate === "sh://targetClass");
|
|
351
384
|
const shape = new SHACLShape(shapeUri, targetClassLink?.target);
|
|
352
385
|
// Find constructor actions
|
|
353
|
-
const constructorLink = links.find(l => l.source === shapeUri && l.predicate === "ad4m://constructor");
|
|
386
|
+
const constructorLink = links.find((l) => l.source === shapeUri && l.predicate === "ad4m://constructor");
|
|
354
387
|
if (constructorLink) {
|
|
355
388
|
try {
|
|
356
|
-
const jsonStr = constructorLink.target.replace(
|
|
389
|
+
const jsonStr = constructorLink.target.replace("literal://string:", "");
|
|
357
390
|
shape.constructor_actions = JSON.parse(jsonStr);
|
|
358
391
|
}
|
|
359
392
|
catch (e) {
|
|
@@ -361,10 +394,10 @@ export class SHACLShape {
|
|
|
361
394
|
}
|
|
362
395
|
}
|
|
363
396
|
// Find destructor actions
|
|
364
|
-
const destructorLink = links.find(l => l.source === shapeUri && l.predicate === "ad4m://destructor");
|
|
397
|
+
const destructorLink = links.find((l) => l.source === shapeUri && l.predicate === "ad4m://destructor");
|
|
365
398
|
if (destructorLink) {
|
|
366
399
|
try {
|
|
367
|
-
const jsonStr = destructorLink.target.replace(
|
|
400
|
+
const jsonStr = destructorLink.target.replace("literal://string:", "");
|
|
368
401
|
shape.destructor_actions = JSON.parse(jsonStr);
|
|
369
402
|
}
|
|
370
403
|
catch (e) {
|
|
@@ -372,120 +405,124 @@ export class SHACLShape {
|
|
|
372
405
|
}
|
|
373
406
|
}
|
|
374
407
|
// Find all property shapes
|
|
375
|
-
const propShapeLinks = links.filter(l => l.source === shapeUri && l.predicate === "sh://property");
|
|
408
|
+
const propShapeLinks = links.filter((l) => l.source === shapeUri && l.predicate === "sh://property");
|
|
376
409
|
for (const propLink of propShapeLinks) {
|
|
377
410
|
const propShapeId = propLink.target;
|
|
378
411
|
// Reconstruct property from its links
|
|
379
|
-
const pathLink = links.find(l => l.source === propShapeId && l.predicate === "sh://path");
|
|
412
|
+
const pathLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://path");
|
|
380
413
|
if (!pathLink)
|
|
381
414
|
continue;
|
|
382
415
|
// Extract property name from propShapeId if it's a named URI
|
|
383
416
|
// Format: {namespace}{ClassName}.{propertyName}
|
|
384
417
|
let propertyName;
|
|
385
|
-
if (!propShapeId.startsWith(
|
|
386
|
-
const lastDotIndex = propShapeId.lastIndexOf(
|
|
418
|
+
if (!propShapeId.startsWith("_:")) {
|
|
419
|
+
const lastDotIndex = propShapeId.lastIndexOf(".");
|
|
387
420
|
if (lastDotIndex !== -1) {
|
|
388
421
|
propertyName = propShapeId.substring(lastDotIndex + 1);
|
|
389
422
|
}
|
|
390
423
|
}
|
|
391
424
|
const prop = {
|
|
392
425
|
name: propertyName,
|
|
393
|
-
path: pathLink.target
|
|
426
|
+
path: pathLink.target,
|
|
394
427
|
};
|
|
395
428
|
// Extract constraints
|
|
396
|
-
const datatypeLink = links.find(l => l.source === propShapeId && l.predicate === "sh://datatype");
|
|
429
|
+
const datatypeLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://datatype");
|
|
397
430
|
if (datatypeLink)
|
|
398
431
|
prop.datatype = datatypeLink.target;
|
|
399
|
-
const nodeKindLink = links.find(l => l.source === propShapeId && l.predicate === "sh://nodeKind");
|
|
432
|
+
const nodeKindLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://nodeKind");
|
|
400
433
|
if (nodeKindLink) {
|
|
401
|
-
prop.nodeKind = nodeKindLink.target.replace(
|
|
434
|
+
prop.nodeKind = nodeKindLink.target.replace("sh://", "");
|
|
402
435
|
}
|
|
403
|
-
const minCountLink = links.find(l => l.source === propShapeId && l.predicate === "sh://minCount");
|
|
436
|
+
const minCountLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://minCount");
|
|
404
437
|
if (minCountLink) {
|
|
405
438
|
// Handle both formats: literal://5^^xsd:integer and literal://number:5
|
|
406
|
-
let val = minCountLink.target
|
|
407
|
-
|
|
439
|
+
let val = minCountLink.target
|
|
440
|
+
.replace("literal://", "")
|
|
441
|
+
.replace(/\^\^.*$/, "");
|
|
442
|
+
if (val.startsWith("number:"))
|
|
408
443
|
val = val.substring(7);
|
|
409
444
|
prop.minCount = parseInt(val);
|
|
410
445
|
}
|
|
411
|
-
const maxCountLink = links.find(l => l.source === propShapeId && l.predicate === "sh://maxCount");
|
|
446
|
+
const maxCountLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://maxCount");
|
|
412
447
|
if (maxCountLink) {
|
|
413
448
|
// Handle both formats: literal://5^^xsd:integer and literal://number:5
|
|
414
|
-
let val = maxCountLink.target
|
|
415
|
-
|
|
449
|
+
let val = maxCountLink.target
|
|
450
|
+
.replace("literal://", "")
|
|
451
|
+
.replace(/\^\^.*$/, "");
|
|
452
|
+
if (val.startsWith("number:"))
|
|
416
453
|
val = val.substring(7);
|
|
417
454
|
prop.maxCount = parseInt(val);
|
|
418
455
|
}
|
|
419
|
-
const patternLink = links.find(l => l.source === propShapeId && l.predicate === "sh://pattern");
|
|
456
|
+
const patternLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://pattern");
|
|
420
457
|
if (patternLink) {
|
|
421
|
-
prop.pattern = patternLink.target.replace(
|
|
458
|
+
prop.pattern = patternLink.target.replace("literal://", "");
|
|
422
459
|
}
|
|
423
|
-
const minInclusiveLink = links.find(l => l.source === propShapeId && l.predicate === "sh://minInclusive");
|
|
460
|
+
const minInclusiveLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://minInclusive");
|
|
424
461
|
if (minInclusiveLink) {
|
|
425
462
|
// Handle both formats: literal://5 and literal://number:5
|
|
426
|
-
let val = minInclusiveLink.target.replace(
|
|
427
|
-
if (val.startsWith(
|
|
463
|
+
let val = minInclusiveLink.target.replace("literal://", "");
|
|
464
|
+
if (val.startsWith("number:"))
|
|
428
465
|
val = val.substring(7);
|
|
429
466
|
prop.minInclusive = parseFloat(val);
|
|
430
467
|
}
|
|
431
|
-
const maxInclusiveLink = links.find(l => l.source === propShapeId && l.predicate === "sh://maxInclusive");
|
|
468
|
+
const maxInclusiveLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://maxInclusive");
|
|
432
469
|
if (maxInclusiveLink) {
|
|
433
470
|
// Handle both formats: literal://5 and literal://number:5
|
|
434
|
-
let val = maxInclusiveLink.target.replace(
|
|
435
|
-
if (val.startsWith(
|
|
471
|
+
let val = maxInclusiveLink.target.replace("literal://", "");
|
|
472
|
+
if (val.startsWith("number:"))
|
|
436
473
|
val = val.substring(7);
|
|
437
474
|
prop.maxInclusive = parseFloat(val);
|
|
438
475
|
}
|
|
439
|
-
const hasValueLink = links.find(l => l.source === propShapeId && l.predicate === "sh://hasValue");
|
|
476
|
+
const hasValueLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://hasValue");
|
|
440
477
|
if (hasValueLink) {
|
|
441
|
-
prop.hasValue = hasValueLink.target.replace(
|
|
478
|
+
prop.hasValue = hasValueLink.target.replace("literal://", "");
|
|
442
479
|
}
|
|
443
480
|
// AD4M-specific
|
|
444
|
-
const localLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://local");
|
|
481
|
+
const localLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://local");
|
|
445
482
|
if (localLink) {
|
|
446
483
|
// Handle both formats: literal://true and literal://boolean:true
|
|
447
|
-
let val = localLink.target.replace(
|
|
448
|
-
if (val.startsWith(
|
|
484
|
+
let val = localLink.target.replace("literal://", "");
|
|
485
|
+
if (val.startsWith("boolean:"))
|
|
449
486
|
val = val.substring(8);
|
|
450
|
-
prop.local = val ===
|
|
487
|
+
prop.local = val === "true";
|
|
451
488
|
}
|
|
452
|
-
const
|
|
453
|
-
if (
|
|
489
|
+
const readOnlyLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://readOnly");
|
|
490
|
+
if (readOnlyLink) {
|
|
454
491
|
// Handle both formats: literal://true and literal://boolean:true
|
|
455
|
-
let val =
|
|
456
|
-
if (val.startsWith(
|
|
492
|
+
let val = readOnlyLink.target.replace("literal://", "");
|
|
493
|
+
if (val.startsWith("boolean:"))
|
|
457
494
|
val = val.substring(8);
|
|
458
|
-
prop.
|
|
495
|
+
prop.readOnly = val === "true";
|
|
459
496
|
}
|
|
460
|
-
const resolveLangLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://resolveLanguage");
|
|
497
|
+
const resolveLangLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://resolveLanguage");
|
|
461
498
|
if (resolveLangLink) {
|
|
462
|
-
prop.resolveLanguage = resolveLangLink.target.replace(
|
|
499
|
+
prop.resolveLanguage = resolveLangLink.target.replace("literal://string:", "");
|
|
463
500
|
}
|
|
464
501
|
// Parse action arrays
|
|
465
|
-
const setterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://setter");
|
|
502
|
+
const setterLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://setter");
|
|
466
503
|
if (setterLink) {
|
|
467
504
|
try {
|
|
468
|
-
const jsonStr = setterLink.target.replace(
|
|
505
|
+
const jsonStr = setterLink.target.replace("literal://string:", "");
|
|
469
506
|
prop.setter = JSON.parse(jsonStr);
|
|
470
507
|
}
|
|
471
508
|
catch (e) {
|
|
472
509
|
// Ignore parse errors
|
|
473
510
|
}
|
|
474
511
|
}
|
|
475
|
-
const adderLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://adder");
|
|
512
|
+
const adderLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://adder");
|
|
476
513
|
if (adderLink) {
|
|
477
514
|
try {
|
|
478
|
-
const jsonStr = adderLink.target.replace(
|
|
515
|
+
const jsonStr = adderLink.target.replace("literal://string:", "");
|
|
479
516
|
prop.adder = JSON.parse(jsonStr);
|
|
480
517
|
}
|
|
481
518
|
catch (e) {
|
|
482
519
|
// Ignore parse errors
|
|
483
520
|
}
|
|
484
521
|
}
|
|
485
|
-
const removerLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://remover");
|
|
522
|
+
const removerLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://remover");
|
|
486
523
|
if (removerLink) {
|
|
487
524
|
try {
|
|
488
|
-
const jsonStr = removerLink.target.replace(
|
|
525
|
+
const jsonStr = removerLink.target.replace("literal://string:", "");
|
|
489
526
|
prop.remover = JSON.parse(jsonStr);
|
|
490
527
|
}
|
|
491
528
|
catch (e) {
|
|
@@ -506,7 +543,7 @@ export class SHACLShape {
|
|
|
506
543
|
return {
|
|
507
544
|
node_shape_uri: this.nodeShapeUri,
|
|
508
545
|
target_class: this.targetClass,
|
|
509
|
-
properties: this.properties.map(p => ({
|
|
546
|
+
properties: this.properties.map((p) => ({
|
|
510
547
|
path: p.path,
|
|
511
548
|
name: p.name,
|
|
512
549
|
datatype: p.datatype,
|
|
@@ -518,7 +555,7 @@ export class SHACLShape {
|
|
|
518
555
|
pattern: p.pattern,
|
|
519
556
|
has_value: p.hasValue,
|
|
520
557
|
local: p.local,
|
|
521
|
-
|
|
558
|
+
read_only: p.readOnly,
|
|
522
559
|
resolve_language: p.resolveLanguage,
|
|
523
560
|
setter: p.setter,
|
|
524
561
|
adder: p.adder,
|
|
@@ -548,7 +585,7 @@ export class SHACLShape {
|
|
|
548
585
|
pattern: p.pattern,
|
|
549
586
|
hasValue: p.has_value,
|
|
550
587
|
local: p.local,
|
|
551
|
-
|
|
588
|
+
readOnly: p.read_only,
|
|
552
589
|
resolveLanguage: p.resolve_language,
|
|
553
590
|
setter: p.setter,
|
|
554
591
|
adder: p.adder,
|