@coasys/ad4m 0.12.0-rc1-dev.2 → 0.12.0-rc1-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/jest.config.js +10 -3
  2. package/lib/index.cjs +6893 -5884
  3. package/lib/index.js +6889 -5872
  4. package/lib/src/Ad4mClient.d.ts +9 -16
  5. package/lib/src/Ad4mClient.js +46 -25
  6. package/lib/src/Literal.d.ts +1 -2
  7. package/lib/src/Literal.js +38 -35
  8. package/lib/src/SmartLiteral.d.ts +1 -2
  9. package/lib/src/SmartLiteral.js +30 -15
  10. package/lib/src/agent/AgentClient.d.ts +1 -4
  11. package/lib/src/agent/AgentClient.js +79 -99
  12. package/lib/src/ai/AIClient.d.ts +1 -2
  13. package/lib/src/ai/AIClient.js +224 -220
  14. package/lib/src/expression/ExpressionClient.d.ts +1 -1
  15. package/lib/src/expression/ExpressionClient.js +73 -86
  16. package/lib/src/index.d.ts +1 -1
  17. package/lib/src/index.js +1 -1
  18. package/lib/src/language/LanguageClient.d.ts +1 -1
  19. package/lib/src/language/LanguageClient.js +52 -52
  20. package/lib/src/model/Ad4mModel.d.ts +1351 -144
  21. package/lib/src/model/Ad4mModel.js +3760 -228
  22. package/lib/src/model/Ad4mModel.test.js +522 -979
  23. package/lib/src/model/Subject.d.ts +3 -3
  24. package/lib/src/model/Subject.js +25 -25
  25. package/lib/src/model/decorators.d.ts +444 -100
  26. package/lib/src/model/decorators.js +686 -321
  27. package/lib/src/model/util.d.ts +6 -6
  28. package/lib/src/model/util.js +24 -24
  29. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +1 -5
  30. package/lib/src/neighbourhood/NeighbourhoodClient.js +179 -242
  31. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +1 -2
  32. package/lib/src/neighbourhood/NeighbourhoodProxy.js +28 -13
  33. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +5 -1
  34. package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
  35. package/lib/src/perspectives/PerspectiveClient.js +240 -316
  36. package/lib/src/perspectives/PerspectiveProxy.d.ts +99 -61
  37. package/lib/src/perspectives/PerspectiveProxy.js +485 -832
  38. package/lib/src/runtime/RuntimeClient.d.ts +1 -5
  39. package/lib/src/runtime/RuntimeClient.js +238 -412
  40. package/lib/src/shacl/SHACLFlow.test.js +105 -164
  41. package/lib/src/shacl/SHACLShape.d.ts +12 -17
  42. package/lib/src/shacl/SHACLShape.js +115 -128
  43. package/lib/src/shacl/SHACLShape.test.js +176 -244
  44. package/lib/src/shims/reflect-metadata.d.ts +0 -0
  45. package/lib/src/shims/type-graphql.d.ts +32 -0
  46. package/lib/src/src/Ad4mClient.d.ts +28 -0
  47. package/lib/src/src/Address.d.ts +1 -0
  48. package/lib/src/src/DID.d.ts +1 -0
  49. package/lib/src/src/Exception.d.ts +7 -0
  50. package/lib/src/src/Literal.d.ts +7 -0
  51. package/lib/src/src/PubSub.d.ts +17 -0
  52. package/lib/src/src/SmartLiteral.d.ts +12 -0
  53. package/lib/src/src/agent/Agent.d.ts +110 -0
  54. package/lib/src/src/agent/AgentClient.d.ts +62 -0
  55. package/lib/src/src/agent/AgentResolver.d.ts +30 -0
  56. package/lib/src/src/agent/AgentStatus.d.ts +8 -0
  57. package/lib/src/src/ai/AIClient.d.ts +32 -0
  58. package/lib/src/src/ai/AIResolver.d.ts +75 -0
  59. package/lib/src/src/ai/Tasks.d.ts +37 -0
  60. package/lib/src/src/buildSchema.d.ts +1 -0
  61. package/lib/src/src/expression/Expression.d.ts +28 -0
  62. package/lib/src/src/expression/ExpressionClient.d.ts +13 -0
  63. package/lib/src/src/expression/ExpressionRef.d.ts +9 -0
  64. package/lib/src/src/expression/ExpressionResolver.d.ts +10 -0
  65. package/lib/src/src/index.d.ts +35 -0
  66. package/lib/src/src/jestSetup.d.ts +1 -0
  67. package/lib/src/src/language/Icon.d.ts +4 -0
  68. package/lib/src/src/language/Language.d.ts +206 -0
  69. package/lib/src/src/language/LanguageClient.d.ts +17 -0
  70. package/lib/src/src/language/LanguageContext.d.ts +37 -0
  71. package/lib/src/src/language/LanguageHandle.d.ts +9 -0
  72. package/lib/src/src/language/LanguageMeta.d.ts +35 -0
  73. package/lib/src/src/language/LanguageRef.d.ts +6 -0
  74. package/lib/src/src/language/LanguageResolver.d.ts +19 -0
  75. package/lib/src/src/links/Links.d.ts +39 -0
  76. package/lib/src/src/links/Links.test.d.ts +1 -0
  77. package/lib/src/src/model/Ad4mModel.d.ts +1438 -0
  78. package/lib/src/src/model/Ad4mModel.test.d.ts +1 -0
  79. package/lib/src/src/model/Subject.d.ts +25 -0
  80. package/lib/src/src/model/decorators.d.ts +545 -0
  81. package/lib/src/src/model/util.d.ts +12 -0
  82. package/lib/src/src/neighbourhood/Neighbourhood.d.ts +10 -0
  83. package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
  84. package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
  85. package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
  86. package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
  87. package/lib/src/src/perspectives/LinkQuery.d.ts +11 -0
  88. package/lib/src/src/perspectives/Perspective.d.ts +38 -0
  89. package/lib/src/src/perspectives/Perspective.test.d.ts +1 -0
  90. package/lib/src/src/perspectives/PerspectiveClient.d.ts +97 -0
  91. package/lib/src/src/perspectives/PerspectiveDiff.d.ts +9 -0
  92. package/lib/src/src/perspectives/PerspectiveHandle.d.ts +18 -0
  93. package/lib/src/src/perspectives/PerspectiveProxy.d.ts +865 -0
  94. package/lib/src/src/perspectives/PerspectiveResolver.d.ts +57 -0
  95. package/lib/src/src/runtime/RuntimeClient.d.ts +56 -0
  96. package/lib/src/src/runtime/RuntimeResolver.d.ts +132 -0
  97. package/lib/src/src/shacl/SHACLFlow.d.ts +171 -0
  98. package/lib/src/src/shacl/SHACLFlow.test.d.ts +1 -0
  99. package/lib/src/src/shacl/SHACLShape.d.ts +117 -0
  100. package/lib/src/src/shacl/SHACLShape.test.d.ts +1 -0
  101. package/lib/src/src/typeDefs.d.ts +1 -0
  102. package/lib/src/src/unwrapApolloResult.d.ts +2 -0
  103. package/lib/src/src/utils.d.ts +25 -0
  104. package/lib/src/utils.d.ts +0 -8
  105. package/lib/src/utils.js +7 -21
  106. package/package.json +15 -14
  107. package/src/Ad4mClient.test.ts +1315 -1564
  108. package/src/Ad4mClient.ts +54 -55
  109. package/src/Literal.test.ts +26 -45
  110. package/src/Literal.ts +66 -82
  111. package/src/SmartLiteral.ts +58 -74
  112. package/src/agent/AgentClient.ts +99 -144
  113. package/src/ai/AIClient.ts +359 -409
  114. package/src/expression/ExpressionClient.ts +96 -142
  115. package/src/index.ts +1 -1
  116. package/src/language/LanguageClient.ts +113 -137
  117. package/src/model/Ad4mModel.test.ts +616 -1114
  118. package/src/model/Ad4mModel.ts +4386 -451
  119. package/src/model/Subject.ts +159 -0
  120. package/src/model/decorators.ts +1168 -667
  121. package/src/model/util.ts +54 -53
  122. package/src/neighbourhood/NeighbourhoodClient.ts +266 -392
  123. package/src/neighbourhood/NeighbourhoodProxy.test.ts +7 -3
  124. package/src/neighbourhood/NeighbourhoodProxy.ts +40 -58
  125. package/src/perspectives/PerspectiveClient.ts +540 -779
  126. package/src/perspectives/PerspectiveProxy.ts +2067 -2860
  127. package/src/runtime/RuntimeClient.ts +476 -775
  128. package/src/shacl/SHACLFlow.test.ts +129 -196
  129. package/src/shacl/SHACLShape.test.ts +190 -284
  130. package/src/shacl/SHACLShape.ts +200 -224
  131. package/src/utils.ts +17 -31
  132. package/tsconfig.json +10 -9
  133. package/src/model/IMPROVEMENTS.md +0 -482
  134. package/src/model/PREDICATE_COLLISION_FIX.md +0 -651
  135. package/src/model/README.md +0 -317
  136. package/src/model/SHACL_MUTATION_DECOUPLING.md +0 -356
  137. package/src/model/SUBSCRIPTION_STRATEGY.md +0 -317
  138. package/src/model/TC39_STAGE_3_DECORATORS.md +0 -609
  139. package/src/model/mutation.ts +0 -461
  140. package/src/model/parentUtils.ts +0 -91
  141. package/src/model/prolog/generatePrologFacts.ts +0 -176
  142. package/src/model/prolog/index.ts +0 -1
  143. package/src/model/query/ModelQueryBuilder.ts +0 -173
  144. package/src/model/query/fetchInstance.ts +0 -181
  145. package/src/model/query/hydration.ts +0 -273
  146. package/src/model/query/operations.ts +0 -510
  147. package/src/model/query/snapshot.ts +0 -126
  148. package/src/model/query/surrealCompiler.ts +0 -376
  149. package/src/model/schema/fromJSONSchema.ts +0 -411
  150. package/src/model/schema/metadata.ts +0 -148
  151. package/src/model/subscription.ts +0 -307
  152. package/src/model/transaction.ts +0 -60
  153. package/src/model/types.ts +0 -207
@@ -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, "\\\\") // Backslash must be first
41
+ .replace(/\\/g, '\\\\') // Backslash must be first
42
42
  .replace(/"/g, '\\"') // Double quotes
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
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
  }
@@ -99,21 +99,24 @@ export class SHACLShape {
99
99
  this.nodeShapeUri = `${namespace}${localName}Shape`;
100
100
  }
101
101
  this.properties = [];
102
+ this.parentShapes = [];
102
103
  }
103
104
  /**
104
- * Add a property constraint to this shape
105
+ * Add a parent shape reference (sh:node) for model inheritance.
106
+ * When a @Model class extends another @Model, the child shape
107
+ * references the parent shape so SHACL validators can walk the
108
+ * class hierarchy.
105
109
  */
106
- addProperty(prop) {
107
- this.properties.push(prop);
110
+ addParentShape(parentShapeUri) {
111
+ if (!this.parentShapes.includes(parentShapeUri)) {
112
+ this.parentShapes.push(parentShapeUri);
113
+ }
108
114
  }
109
115
  /**
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
116
+ * Add a property constraint to this shape
113
117
  */
114
- addParentShape(parentShapeUri) {
115
- this.parentShapes = this.parentShapes ?? [];
116
- this.parentShapes.push(parentShapeUri);
118
+ addProperty(prop) {
119
+ this.properties.push(prop);
117
120
  }
118
121
  /**
119
122
  * Set constructor actions for this shape
@@ -140,23 +143,16 @@ export class SHACLShape {
140
143
  if (this.targetClass) {
141
144
  turtle += ` sh:targetClass <${this.targetClass}> ;\n`;
142
145
  }
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
- }
146
+ // Emit sh:node references for parent shapes (model inheritance)
147
+ for (const parentUri of this.parentShapes) {
148
+ turtle += ` sh:node <${parentUri}> ;\n`;
148
149
  }
149
150
  // Add property shapes
150
151
  for (let i = 0; i < this.properties.length; i++) {
151
152
  const prop = this.properties[i];
152
153
  const isLast = i === this.properties.length - 1;
153
154
  turtle += ` sh:property [\n`;
154
- if (prop.inversePath) {
155
- turtle += ` sh:path [ sh:inversePath <${prop.path}> ] ;\n`;
156
- }
157
- else {
158
- turtle += ` sh:path <${prop.path}> ;\n`;
159
- }
155
+ turtle += ` sh:path <${prop.path}> ;\n`;
160
156
  if (prop.datatype) {
161
157
  turtle += ` sh:datatype <${prop.datatype}> ;\n`;
162
158
  }
@@ -185,11 +181,11 @@ export class SHACLShape {
185
181
  if (prop.local !== undefined) {
186
182
  turtle += ` ad4m:local ${prop.local} ;\n`;
187
183
  }
188
- if (prop.readOnly !== undefined) {
189
- turtle += ` ad4m:readOnly ${prop.readOnly} ;\n`;
184
+ if (prop.writable !== undefined) {
185
+ turtle += ` ad4m:writable ${prop.writable} ;\n`;
190
186
  }
191
187
  // Remove trailing semicolon and close bracket
192
- turtle = turtle.slice(0, -2) + "\n";
188
+ turtle = turtle.slice(0, -2) + '\n';
193
189
  turtle += isLast ? ` ] .\n` : ` ] ;\n`;
194
190
  }
195
191
  return turtle;
@@ -204,43 +200,32 @@ export class SHACLShape {
204
200
  links.push({
205
201
  source: this.nodeShapeUri,
206
202
  predicate: "rdf://type",
207
- target: "sh://NodeShape",
203
+ target: "sh://NodeShape"
208
204
  });
209
205
  // Target class
210
206
  if (this.targetClass) {
211
207
  links.push({
212
208
  source: this.nodeShapeUri,
213
209
  predicate: "sh://targetClass",
214
- target: this.targetClass,
210
+ target: this.targetClass
215
211
  });
216
212
  }
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) {
213
+ // Constructor actions — always emit, even for an empty array.
214
+ // An empty `[]` tells the executor the shape is valid but has no
215
+ // required initial links (all-optional model with no @Flag).
216
+ if (this.constructor_actions) {
232
217
  links.push({
233
218
  source: this.nodeShapeUri,
234
219
  predicate: "ad4m://constructor",
235
- target: `literal://string:${JSON.stringify(this.constructor_actions)}`,
220
+ target: `literal://string:${JSON.stringify(this.constructor_actions)}`
236
221
  });
237
222
  }
238
- // Destructor actions
239
- if (this.destructor_actions && this.destructor_actions.length > 0) {
223
+ // Destructor actions — same rationale as constructor.
224
+ if (this.destructor_actions) {
240
225
  links.push({
241
226
  source: this.nodeShapeUri,
242
227
  predicate: "ad4m://destructor",
243
- target: `literal://string:${JSON.stringify(this.destructor_actions)}`,
228
+ target: `literal://string:${JSON.stringify(this.destructor_actions)}`
244
229
  });
245
230
  }
246
231
  // Property shapes (each gets a named URI: {namespace}/{ClassName}.{propertyName})
@@ -263,69 +248,69 @@ export class SHACLShape {
263
248
  links.push({
264
249
  source: this.nodeShapeUri,
265
250
  predicate: "sh://property",
266
- target: propShapeId,
251
+ target: propShapeId
267
252
  });
268
- // Property path (forward or inverse)
253
+ // Property path
269
254
  links.push({
270
255
  source: propShapeId,
271
- predicate: prop.inversePath ? "sh://inversePath" : "sh://path",
272
- target: prop.path,
256
+ predicate: "sh://path",
257
+ target: prop.path
273
258
  });
274
259
  // Constraints
275
260
  if (prop.datatype) {
276
261
  links.push({
277
262
  source: propShapeId,
278
263
  predicate: "sh://datatype",
279
- target: prop.datatype,
264
+ target: prop.datatype
280
265
  });
281
266
  }
282
267
  if (prop.nodeKind) {
283
268
  links.push({
284
269
  source: propShapeId,
285
270
  predicate: "sh://nodeKind",
286
- target: `sh://${prop.nodeKind}`,
271
+ target: `sh://${prop.nodeKind}`
287
272
  });
288
273
  }
289
274
  if (prop.minCount !== undefined) {
290
275
  links.push({
291
276
  source: propShapeId,
292
277
  predicate: "sh://minCount",
293
- target: `literal://${prop.minCount}^^xsd:integer`,
278
+ target: `literal://${prop.minCount}^^xsd:integer`
294
279
  });
295
280
  }
296
281
  if (prop.maxCount !== undefined) {
297
282
  links.push({
298
283
  source: propShapeId,
299
284
  predicate: "sh://maxCount",
300
- target: `literal://${prop.maxCount}^^xsd:integer`,
285
+ target: `literal://${prop.maxCount}^^xsd:integer`
301
286
  });
302
287
  }
303
288
  if (prop.pattern) {
304
289
  links.push({
305
290
  source: propShapeId,
306
291
  predicate: "sh://pattern",
307
- target: `literal://${prop.pattern}`,
292
+ target: `literal://${prop.pattern}`
308
293
  });
309
294
  }
310
295
  if (prop.minInclusive !== undefined) {
311
296
  links.push({
312
297
  source: propShapeId,
313
298
  predicate: "sh://minInclusive",
314
- target: `literal://${prop.minInclusive}`,
299
+ target: `literal://${prop.minInclusive}`
315
300
  });
316
301
  }
317
302
  if (prop.maxInclusive !== undefined) {
318
303
  links.push({
319
304
  source: propShapeId,
320
305
  predicate: "sh://maxInclusive",
321
- target: `literal://${prop.maxInclusive}`,
306
+ target: `literal://${prop.maxInclusive}`
322
307
  });
323
308
  }
324
309
  if (prop.hasValue) {
325
310
  links.push({
326
311
  source: propShapeId,
327
312
  predicate: "sh://hasValue",
328
- target: `literal://${prop.hasValue}`,
313
+ target: `literal://${prop.hasValue}`
329
314
  });
330
315
  }
331
316
  // AD4M-specific metadata
@@ -333,21 +318,21 @@ export class SHACLShape {
333
318
  links.push({
334
319
  source: propShapeId,
335
320
  predicate: "ad4m://local",
336
- target: `literal://${prop.local}`,
321
+ target: `literal://${prop.local}`
337
322
  });
338
323
  }
339
- if (prop.readOnly !== undefined) {
324
+ if (prop.writable !== undefined) {
340
325
  links.push({
341
326
  source: propShapeId,
342
- predicate: "ad4m://readOnly",
343
- target: `literal://${prop.readOnly}`,
327
+ predicate: "ad4m://writable",
328
+ target: `literal://${prop.writable}`
344
329
  });
345
330
  }
346
331
  if (prop.resolveLanguage) {
347
332
  links.push({
348
333
  source: propShapeId,
349
334
  predicate: "ad4m://resolveLanguage",
350
- target: `literal://string:${prop.resolveLanguage}`,
335
+ target: `literal://string:${prop.resolveLanguage}`
351
336
  });
352
337
  }
353
338
  // AD4M-specific actions
@@ -355,21 +340,21 @@ export class SHACLShape {
355
340
  links.push({
356
341
  source: propShapeId,
357
342
  predicate: "ad4m://setter",
358
- target: `literal://string:${JSON.stringify(prop.setter)}`,
343
+ target: `literal://string:${JSON.stringify(prop.setter)}`
359
344
  });
360
345
  }
361
346
  if (prop.adder && prop.adder.length > 0) {
362
347
  links.push({
363
348
  source: propShapeId,
364
349
  predicate: "ad4m://adder",
365
- target: `literal://string:${JSON.stringify(prop.adder)}`,
350
+ target: `literal://string:${JSON.stringify(prop.adder)}`
366
351
  });
367
352
  }
368
353
  if (prop.remover && prop.remover.length > 0) {
369
354
  links.push({
370
355
  source: propShapeId,
371
356
  predicate: "ad4m://remover",
372
- target: `literal://string:${JSON.stringify(prop.remover)}`,
357
+ target: `literal://string:${JSON.stringify(prop.remover)}`
373
358
  });
374
359
  }
375
360
  }
@@ -380,13 +365,13 @@ export class SHACLShape {
380
365
  */
381
366
  static fromLinks(links, shapeUri) {
382
367
  // Find target class
383
- const targetClassLink = links.find((l) => l.source === shapeUri && l.predicate === "sh://targetClass");
368
+ const targetClassLink = links.find(l => l.source === shapeUri && l.predicate === "sh://targetClass");
384
369
  const shape = new SHACLShape(shapeUri, targetClassLink?.target);
385
370
  // Find constructor actions
386
- const constructorLink = links.find((l) => l.source === shapeUri && l.predicate === "ad4m://constructor");
371
+ const constructorLink = links.find(l => l.source === shapeUri && l.predicate === "ad4m://constructor");
387
372
  if (constructorLink) {
388
373
  try {
389
- const jsonStr = constructorLink.target.replace("literal://string:", "");
374
+ const jsonStr = constructorLink.target.replace('literal://string:', '');
390
375
  shape.constructor_actions = JSON.parse(jsonStr);
391
376
  }
392
377
  catch (e) {
@@ -394,10 +379,10 @@ export class SHACLShape {
394
379
  }
395
380
  }
396
381
  // Find destructor actions
397
- const destructorLink = links.find((l) => l.source === shapeUri && l.predicate === "ad4m://destructor");
382
+ const destructorLink = links.find(l => l.source === shapeUri && l.predicate === "ad4m://destructor");
398
383
  if (destructorLink) {
399
384
  try {
400
- const jsonStr = destructorLink.target.replace("literal://string:", "");
385
+ const jsonStr = destructorLink.target.replace('literal://string:', '');
401
386
  shape.destructor_actions = JSON.parse(jsonStr);
402
387
  }
403
388
  catch (e) {
@@ -405,124 +390,120 @@ export class SHACLShape {
405
390
  }
406
391
  }
407
392
  // Find all property shapes
408
- const propShapeLinks = links.filter((l) => l.source === shapeUri && l.predicate === "sh://property");
393
+ const propShapeLinks = links.filter(l => l.source === shapeUri && l.predicate === "sh://property");
409
394
  for (const propLink of propShapeLinks) {
410
395
  const propShapeId = propLink.target;
411
396
  // Reconstruct property from its links
412
- const pathLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://path");
397
+ const pathLink = links.find(l => l.source === propShapeId && l.predicate === "sh://path");
413
398
  if (!pathLink)
414
399
  continue;
415
400
  // Extract property name from propShapeId if it's a named URI
416
401
  // Format: {namespace}{ClassName}.{propertyName}
417
402
  let propertyName;
418
- if (!propShapeId.startsWith("_:")) {
419
- const lastDotIndex = propShapeId.lastIndexOf(".");
403
+ if (!propShapeId.startsWith('_:')) {
404
+ const lastDotIndex = propShapeId.lastIndexOf('.');
420
405
  if (lastDotIndex !== -1) {
421
406
  propertyName = propShapeId.substring(lastDotIndex + 1);
422
407
  }
423
408
  }
424
409
  const prop = {
425
410
  name: propertyName,
426
- path: pathLink.target,
411
+ path: pathLink.target
427
412
  };
428
413
  // Extract constraints
429
- const datatypeLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://datatype");
414
+ const datatypeLink = links.find(l => l.source === propShapeId && l.predicate === "sh://datatype");
430
415
  if (datatypeLink)
431
416
  prop.datatype = datatypeLink.target;
432
- const nodeKindLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://nodeKind");
417
+ const nodeKindLink = links.find(l => l.source === propShapeId && l.predicate === "sh://nodeKind");
433
418
  if (nodeKindLink) {
434
- prop.nodeKind = nodeKindLink.target.replace("sh://", "");
419
+ prop.nodeKind = nodeKindLink.target.replace('sh://', '');
435
420
  }
436
- const minCountLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://minCount");
421
+ const minCountLink = links.find(l => l.source === propShapeId && l.predicate === "sh://minCount");
437
422
  if (minCountLink) {
438
423
  // Handle both formats: literal://5^^xsd:integer and literal://number:5
439
- let val = minCountLink.target
440
- .replace("literal://", "")
441
- .replace(/\^\^.*$/, "");
442
- if (val.startsWith("number:"))
424
+ let val = minCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
425
+ if (val.startsWith('number:'))
443
426
  val = val.substring(7);
444
427
  prop.minCount = parseInt(val);
445
428
  }
446
- const maxCountLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://maxCount");
429
+ const maxCountLink = links.find(l => l.source === propShapeId && l.predicate === "sh://maxCount");
447
430
  if (maxCountLink) {
448
431
  // Handle both formats: literal://5^^xsd:integer and literal://number:5
449
- let val = maxCountLink.target
450
- .replace("literal://", "")
451
- .replace(/\^\^.*$/, "");
452
- if (val.startsWith("number:"))
432
+ let val = maxCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
433
+ if (val.startsWith('number:'))
453
434
  val = val.substring(7);
454
435
  prop.maxCount = parseInt(val);
455
436
  }
456
- const patternLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://pattern");
437
+ const patternLink = links.find(l => l.source === propShapeId && l.predicate === "sh://pattern");
457
438
  if (patternLink) {
458
- prop.pattern = patternLink.target.replace("literal://", "");
439
+ prop.pattern = patternLink.target.replace('literal://', '');
459
440
  }
460
- const minInclusiveLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://minInclusive");
441
+ const minInclusiveLink = links.find(l => l.source === propShapeId && l.predicate === "sh://minInclusive");
461
442
  if (minInclusiveLink) {
462
443
  // Handle both formats: literal://5 and literal://number:5
463
- let val = minInclusiveLink.target.replace("literal://", "");
464
- if (val.startsWith("number:"))
444
+ let val = minInclusiveLink.target.replace('literal://', '');
445
+ if (val.startsWith('number:'))
465
446
  val = val.substring(7);
466
447
  prop.minInclusive = parseFloat(val);
467
448
  }
468
- const maxInclusiveLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://maxInclusive");
449
+ const maxInclusiveLink = links.find(l => l.source === propShapeId && l.predicate === "sh://maxInclusive");
469
450
  if (maxInclusiveLink) {
470
451
  // Handle both formats: literal://5 and literal://number:5
471
- let val = maxInclusiveLink.target.replace("literal://", "");
472
- if (val.startsWith("number:"))
452
+ let val = maxInclusiveLink.target.replace('literal://', '');
453
+ if (val.startsWith('number:'))
473
454
  val = val.substring(7);
474
455
  prop.maxInclusive = parseFloat(val);
475
456
  }
476
- const hasValueLink = links.find((l) => l.source === propShapeId && l.predicate === "sh://hasValue");
457
+ const hasValueLink = links.find(l => l.source === propShapeId && l.predicate === "sh://hasValue");
477
458
  if (hasValueLink) {
478
- prop.hasValue = hasValueLink.target.replace("literal://", "");
459
+ prop.hasValue = hasValueLink.target.replace('literal://', '');
479
460
  }
480
461
  // AD4M-specific
481
- const localLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://local");
462
+ const localLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://local");
482
463
  if (localLink) {
483
464
  // Handle both formats: literal://true and literal://boolean:true
484
- let val = localLink.target.replace("literal://", "");
485
- if (val.startsWith("boolean:"))
465
+ let val = localLink.target.replace('literal://', '');
466
+ if (val.startsWith('boolean:'))
486
467
  val = val.substring(8);
487
- prop.local = val === "true";
468
+ prop.local = val === 'true';
488
469
  }
489
- const readOnlyLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://readOnly");
490
- if (readOnlyLink) {
470
+ const writableLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://writable");
471
+ if (writableLink) {
491
472
  // Handle both formats: literal://true and literal://boolean:true
492
- let val = readOnlyLink.target.replace("literal://", "");
493
- if (val.startsWith("boolean:"))
473
+ let val = writableLink.target.replace('literal://', '');
474
+ if (val.startsWith('boolean:'))
494
475
  val = val.substring(8);
495
- prop.readOnly = val === "true";
476
+ prop.writable = val === 'true';
496
477
  }
497
- const resolveLangLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://resolveLanguage");
478
+ const resolveLangLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://resolveLanguage");
498
479
  if (resolveLangLink) {
499
- prop.resolveLanguage = resolveLangLink.target.replace("literal://string:", "");
480
+ prop.resolveLanguage = resolveLangLink.target.replace('literal://string:', '');
500
481
  }
501
482
  // Parse action arrays
502
- const setterLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://setter");
483
+ const setterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://setter");
503
484
  if (setterLink) {
504
485
  try {
505
- const jsonStr = setterLink.target.replace("literal://string:", "");
486
+ const jsonStr = setterLink.target.replace('literal://string:', '');
506
487
  prop.setter = JSON.parse(jsonStr);
507
488
  }
508
489
  catch (e) {
509
490
  // Ignore parse errors
510
491
  }
511
492
  }
512
- const adderLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://adder");
493
+ const adderLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://adder");
513
494
  if (adderLink) {
514
495
  try {
515
- const jsonStr = adderLink.target.replace("literal://string:", "");
496
+ const jsonStr = adderLink.target.replace('literal://string:', '');
516
497
  prop.adder = JSON.parse(jsonStr);
517
498
  }
518
499
  catch (e) {
519
500
  // Ignore parse errors
520
501
  }
521
502
  }
522
- const removerLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://remover");
503
+ const removerLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://remover");
523
504
  if (removerLink) {
524
505
  try {
525
- const jsonStr = removerLink.target.replace("literal://string:", "");
506
+ const jsonStr = removerLink.target.replace('literal://string:', '');
526
507
  prop.remover = JSON.parse(jsonStr);
527
508
  }
528
509
  catch (e) {
@@ -543,7 +524,8 @@ export class SHACLShape {
543
524
  return {
544
525
  node_shape_uri: this.nodeShapeUri,
545
526
  target_class: this.targetClass,
546
- properties: this.properties.map((p) => ({
527
+ parent_shapes: this.parentShapes.length > 0 ? this.parentShapes : undefined,
528
+ properties: this.properties.map(p => ({
547
529
  path: p.path,
548
530
  name: p.name,
549
531
  datatype: p.datatype,
@@ -555,7 +537,7 @@ export class SHACLShape {
555
537
  pattern: p.pattern,
556
538
  has_value: p.hasValue,
557
539
  local: p.local,
558
- read_only: p.readOnly,
540
+ writable: p.writable,
559
541
  resolve_language: p.resolveLanguage,
560
542
  setter: p.setter,
561
543
  adder: p.adder,
@@ -585,7 +567,7 @@ export class SHACLShape {
585
567
  pattern: p.pattern,
586
568
  hasValue: p.has_value,
587
569
  local: p.local,
588
- readOnly: p.read_only,
570
+ writable: p.writable,
589
571
  resolveLanguage: p.resolve_language,
590
572
  setter: p.setter,
591
573
  adder: p.adder,
@@ -598,6 +580,11 @@ export class SHACLShape {
598
580
  if (json.destructor_actions) {
599
581
  shape.destructor_actions = json.destructor_actions;
600
582
  }
583
+ if (json.parent_shapes) {
584
+ for (const ps of json.parent_shapes) {
585
+ shape.addParentShape(ps);
586
+ }
587
+ }
601
588
  return shape;
602
589
  }
603
590
  }