@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.
Files changed (128) hide show
  1. package/jest.config.js +4 -4
  2. package/lib/index.cjs +5999 -6046
  3. package/lib/index.js +5977 -6040
  4. package/lib/src/Ad4mClient.d.ts +16 -9
  5. package/lib/src/Ad4mClient.js +25 -46
  6. package/lib/src/Ad4mClient.test.d.ts +1 -0
  7. package/lib/src/Ad4mClient.test.js +1204 -0
  8. package/lib/src/Literal.d.ts +2 -1
  9. package/lib/src/Literal.js +35 -38
  10. package/lib/src/Literal.test.d.ts +1 -0
  11. package/lib/src/Literal.test.js +41 -0
  12. package/lib/src/SmartLiteral.d.ts +2 -1
  13. package/lib/src/SmartLiteral.js +15 -30
  14. package/lib/src/agent/AgentClient.d.ts +4 -1
  15. package/lib/src/agent/AgentClient.js +99 -79
  16. package/lib/src/ai/AIClient.d.ts +2 -1
  17. package/lib/src/ai/AIClient.js +220 -224
  18. package/lib/src/expression/ExpressionClient.d.ts +1 -1
  19. package/lib/src/expression/ExpressionClient.js +86 -73
  20. package/lib/src/index.d.ts +1 -1
  21. package/lib/src/index.js +1 -1
  22. package/lib/src/language/LanguageClient.d.ts +1 -1
  23. package/lib/src/language/LanguageClient.js +52 -52
  24. package/lib/src/model/Ad4mModel.d.ts +157 -937
  25. package/lib/src/model/Ad4mModel.js +212 -2799
  26. package/lib/src/model/Ad4mModel.test.js +1002 -561
  27. package/lib/src/model/decorators.d.ts +94 -426
  28. package/lib/src/model/decorators.js +333 -741
  29. package/lib/src/model/mutation.d.ts +81 -0
  30. package/lib/src/model/mutation.js +317 -0
  31. package/lib/src/model/parentUtils.d.ts +32 -0
  32. package/lib/src/model/parentUtils.js +64 -0
  33. package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
  34. package/lib/src/model/prolog/generatePrologFacts.js +139 -0
  35. package/lib/src/model/prolog/index.d.ts +1 -0
  36. package/lib/src/model/prolog/index.js +1 -0
  37. package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
  38. package/lib/src/model/query/ModelQueryBuilder.js +115 -0
  39. package/lib/src/model/query/QueryBuilder.d.ts +101 -0
  40. package/lib/src/model/query/QueryBuilder.js +193 -0
  41. package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
  42. package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
  43. package/lib/src/model/query/fetchInstance.d.ts +24 -0
  44. package/lib/src/model/query/fetchInstance.js +144 -0
  45. package/lib/src/model/query/hydration.d.ts +54 -0
  46. package/lib/src/model/query/hydration.js +214 -0
  47. package/lib/src/model/query/operations.d.ts +59 -0
  48. package/lib/src/model/query/operations.js +384 -0
  49. package/lib/src/model/query/snapshot.d.ts +59 -0
  50. package/lib/src/model/query/snapshot.js +106 -0
  51. package/lib/src/model/query/surrealCompiler.d.ts +42 -0
  52. package/lib/src/model/query/surrealCompiler.js +304 -0
  53. package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
  54. package/lib/src/model/schema/fromJSONSchema.js +264 -0
  55. package/lib/src/model/schema/metadata.d.ts +15 -0
  56. package/lib/src/model/schema/metadata.js +112 -0
  57. package/lib/src/model/subscription.d.ts +47 -0
  58. package/lib/src/model/subscription.js +231 -0
  59. package/lib/src/model/transaction.d.ts +27 -0
  60. package/lib/src/model/transaction.js +32 -0
  61. package/lib/src/model/types.d.ts +195 -0
  62. package/lib/src/model/types.js +8 -0
  63. package/lib/src/model/util.js +7 -7
  64. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +5 -1
  65. package/lib/src/neighbourhood/NeighbourhoodClient.js +263 -181
  66. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -1
  67. package/lib/src/neighbourhood/NeighbourhoodProxy.js +13 -28
  68. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +1 -5
  69. package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
  70. package/lib/src/perspectives/PerspectiveClient.js +316 -240
  71. package/lib/src/perspectives/PerspectiveProxy.d.ts +54 -92
  72. package/lib/src/perspectives/PerspectiveProxy.js +803 -444
  73. package/lib/src/runtime/RuntimeClient.d.ts +5 -1
  74. package/lib/src/runtime/RuntimeClient.js +412 -238
  75. package/lib/src/shacl/SHACLFlow.test.js +164 -105
  76. package/lib/src/shacl/SHACLShape.d.ts +17 -3
  77. package/lib/src/shacl/SHACLShape.js +127 -90
  78. package/lib/src/shacl/SHACLShape.test.js +244 -176
  79. package/lib/src/utils.d.ts +8 -0
  80. package/lib/src/utils.js +21 -7
  81. package/package.json +8 -13
  82. package/src/Ad4mClient.test.ts +1564 -1315
  83. package/src/Ad4mClient.ts +55 -54
  84. package/src/Literal.test.ts +45 -26
  85. package/src/Literal.ts +82 -66
  86. package/src/SmartLiteral.ts +74 -58
  87. package/src/agent/AgentClient.ts +144 -99
  88. package/src/ai/AIClient.ts +409 -359
  89. package/src/expression/ExpressionClient.ts +142 -96
  90. package/src/index.ts +1 -1
  91. package/src/language/LanguageClient.ts +137 -113
  92. package/src/model/Ad4mModel.test.ts +1128 -647
  93. package/src/model/Ad4mModel.ts +485 -3249
  94. package/src/model/IMPROVEMENTS.md +482 -0
  95. package/src/model/PREDICATE_COLLISION_FIX.md +651 -0
  96. package/src/model/README.md +317 -0
  97. package/src/model/SHACL_MUTATION_DECOUPLING.md +356 -0
  98. package/src/model/SUBSCRIPTION_STRATEGY.md +317 -0
  99. package/src/model/TC39_STAGE_3_DECORATORS.md +609 -0
  100. package/src/model/decorators.ts +689 -1046
  101. package/src/model/mutation.ts +461 -0
  102. package/src/model/parentUtils.ts +91 -0
  103. package/src/model/prolog/generatePrologFacts.ts +176 -0
  104. package/src/model/prolog/index.ts +1 -0
  105. package/src/model/query/ModelQueryBuilder.ts +173 -0
  106. package/src/model/query/fetchInstance.ts +181 -0
  107. package/src/model/query/hydration.ts +273 -0
  108. package/src/model/query/operations.ts +510 -0
  109. package/src/model/query/snapshot.ts +126 -0
  110. package/src/model/query/surrealCompiler.ts +376 -0
  111. package/src/model/schema/fromJSONSchema.ts +411 -0
  112. package/src/model/schema/metadata.ts +148 -0
  113. package/src/model/subscription.ts +307 -0
  114. package/src/model/transaction.ts +60 -0
  115. package/src/model/types.ts +207 -0
  116. package/src/model/util.ts +47 -48
  117. package/src/neighbourhood/NeighbourhoodClient.ts +393 -251
  118. package/src/neighbourhood/NeighbourhoodProxy.test.ts +3 -7
  119. package/src/neighbourhood/NeighbourhoodProxy.ts +58 -40
  120. package/src/perspectives/PerspectiveClient.ts +779 -540
  121. package/src/perspectives/PerspectiveProxy.ts +2860 -2053
  122. package/src/runtime/RuntimeClient.ts +775 -476
  123. package/src/shacl/SHACLFlow.test.ts +196 -129
  124. package/src/shacl/SHACLShape.test.ts +284 -190
  125. package/src/shacl/SHACLShape.ts +225 -172
  126. package/src/utils.ts +31 -17
  127. package/tsconfig.json +9 -10
  128. package/src/model/Subject.ts +0 -159
@@ -10,16 +10,16 @@ import { Link } from "../links/Links";
10
10
  */
11
11
  function extractNamespace(uri: string): string {
12
12
  // Handle hash fragments first (highest priority)
13
- const hashIndex = uri.lastIndexOf('#');
13
+ const hashIndex = uri.lastIndexOf("#");
14
14
  if (hashIndex !== -1) {
15
15
  return uri.substring(0, hashIndex + 1);
16
16
  }
17
-
17
+
18
18
  // Handle protocol-style URIs with paths
19
19
  const protocolMatch = uri.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:\/\/)(.*)$/);
20
20
  if (protocolMatch) {
21
21
  const afterScheme = protocolMatch[2];
22
- const lastSlash = afterScheme.lastIndexOf('/');
22
+ const lastSlash = afterScheme.lastIndexOf("/");
23
23
  if (lastSlash !== -1) {
24
24
  // Has path segments - namespace includes up to last slash
25
25
  return protocolMatch[1] + afterScheme.substring(0, lastSlash + 1);
@@ -27,15 +27,15 @@ function extractNamespace(uri: string): string {
27
27
  // Simple protocol URI without path (e.g., "recipe://name")
28
28
  return protocolMatch[1];
29
29
  }
30
-
30
+
31
31
  // Handle colon-separated (namespace:localName)
32
32
  const colonMatch = uri.match(/^([a-zA-Z][a-zA-Z0-9+.-]*:)/);
33
33
  if (colonMatch) {
34
34
  return colonMatch[1];
35
35
  }
36
-
36
+
37
37
  // Fallback: no clear namespace
38
- return '';
38
+ return "";
39
39
  }
40
40
 
41
41
  /**
@@ -44,13 +44,13 @@ function extractNamespace(uri: string): string {
44
44
  */
45
45
  function escapeTurtleString(value: string): string {
46
46
  return value
47
- .replace(/\\/g, '\\\\') // Backslash must be first
48
- .replace(/"/g, '\\"') // Double quotes
49
- .replace(/\n/g, '\\n') // Newlines
50
- .replace(/\r/g, '\\r') // Carriage returns
51
- .replace(/\t/g, '\\t') // Tabs
52
- .replace(/\b/g, '\\b') // Backspace
53
- .replace(/\f/g, '\\f'); // Form feed
47
+ .replace(/\\/g, "\\\\") // Backslash must be first
48
+ .replace(/"/g, '\\"') // Double quotes
49
+ .replace(/\n/g, "\\n") // Newlines
50
+ .replace(/\r/g, "\\r") // Carriage returns
51
+ .replace(/\t/g, "\\t") // Tabs
52
+ .replace(/\b/g, "\\b") // Backspace
53
+ .replace(/\f/g, "\\f"); // Form feed
54
54
  }
55
55
 
56
56
  /**
@@ -63,23 +63,23 @@ function escapeTurtleString(value: string): string {
63
63
  */
64
64
  function extractLocalName(uri: string): string {
65
65
  // Handle hash fragments
66
- const hashIndex = uri.lastIndexOf('#');
66
+ const hashIndex = uri.lastIndexOf("#");
67
67
  if (hashIndex !== -1) {
68
68
  return uri.substring(hashIndex + 1);
69
69
  }
70
-
70
+
71
71
  // Handle slash-based namespaces
72
- const lastSlash = uri.lastIndexOf('/');
72
+ const lastSlash = uri.lastIndexOf("/");
73
73
  if (lastSlash !== -1 && lastSlash < uri.length - 1) {
74
74
  return uri.substring(lastSlash + 1);
75
75
  }
76
-
76
+
77
77
  // Handle colon-separated
78
78
  const colonMatch = uri.match(/^[a-zA-Z][a-zA-Z0-9+.-]*:(.+)$/);
79
79
  if (colonMatch) {
80
80
  return colonMatch[1];
81
81
  }
82
-
82
+
83
83
  // Fallback: entire URI
84
84
  return uri;
85
85
  }
@@ -110,7 +110,7 @@ export interface SHACLPropertyShape {
110
110
  datatype?: string;
111
111
 
112
112
  /** Node kind constraint (IRI, Literal, BlankNode) */
113
- nodeKind?: 'IRI' | 'Literal' | 'BlankNode';
113
+ nodeKind?: "IRI" | "Literal" | "BlankNode";
114
114
 
115
115
  /** Minimum cardinality (required if >= 1) */
116
116
  minCount?: number;
@@ -133,8 +133,8 @@ export interface SHACLPropertyShape {
133
133
  /** AD4M-specific: Local-only property */
134
134
  local?: boolean;
135
135
 
136
- /** AD4M-specific: Writable property */
137
- writable?: boolean;
136
+ /** AD4M-specific: Read-only property (no setter actions) */
137
+ readOnly?: boolean;
138
138
 
139
139
  /** AD4M-specific: Language to resolve property values through */
140
140
  resolveLanguage?: string;
@@ -147,6 +147,9 @@ export interface SHACLPropertyShape {
147
147
 
148
148
  /** AD4M-specific: Remover action for collection properties */
149
149
  remover?: AD4MAction[];
150
+
151
+ /** AD4M-specific: Reverse path traversal — sh:inversePath instead of sh:path */
152
+ inversePath?: boolean;
150
153
  }
151
154
 
152
155
  /**
@@ -163,6 +166,13 @@ export class SHACLShape {
163
166
  /** Property constraints */
164
167
  properties: SHACLPropertyShape[];
165
168
 
169
+ /**
170
+ * Parent shape URIs for SHACL inheritance (sh:node references).
171
+ * When a model class extends another @Model-decorated class, the child shape
172
+ * references the parent shape via sh:node rather than duplicating its properties.
173
+ */
174
+ parentShapes?: string[];
175
+
166
176
  /** AD4M-specific: Constructor actions for creating instances */
167
177
  constructor_actions?: AD4MAction[];
168
178
 
@@ -198,6 +208,16 @@ export class SHACLShape {
198
208
  this.properties.push(prop);
199
209
  }
200
210
 
211
+ /**
212
+ * Add a parent shape reference (sh:node) for SHACL inheritance.
213
+ * The child shape will reference the parent shape instead of duplicating its properties.
214
+ * @param parentShapeUri - URI of the parent SHACL shape
215
+ */
216
+ addParentShape(parentShapeUri: string): void {
217
+ this.parentShapes = this.parentShapes ?? [];
218
+ this.parentShapes.push(parentShapeUri);
219
+ }
220
+
201
221
  /**
202
222
  * Set constructor actions for this shape
203
223
  */
@@ -211,7 +231,7 @@ export class SHACLShape {
211
231
  setDestructorActions(actions: AD4MAction[]): void {
212
232
  this.destructor_actions = actions;
213
233
  }
214
-
234
+
215
235
  /**
216
236
  * Serialize shape to Turtle (RDF) format
217
237
  */
@@ -220,71 +240,82 @@ export class SHACLShape {
220
240
  turtle += `@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n`;
221
241
  turtle += `@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n`;
222
242
  turtle += `@prefix ad4m: <ad4m://> .\n\n`;
223
-
243
+
224
244
  turtle += `<${this.nodeShapeUri}>\n`;
225
245
  turtle += ` a sh:NodeShape ;\n`;
226
-
246
+
227
247
  if (this.targetClass) {
228
248
  turtle += ` sh:targetClass <${this.targetClass}> ;\n`;
229
249
  }
230
-
250
+
251
+ // Emit sh:node references for parent shapes (SHACL inheritance)
252
+ if (this.parentShapes && this.parentShapes.length > 0) {
253
+ for (const parentUri of this.parentShapes) {
254
+ turtle += ` sh:node <${parentUri}> ;\n`;
255
+ }
256
+ }
257
+
231
258
  // Add property shapes
232
259
  for (let i = 0; i < this.properties.length; i++) {
233
260
  const prop = this.properties[i];
234
261
  const isLast = i === this.properties.length - 1;
235
-
262
+
236
263
  turtle += ` sh:property [\n`;
237
- turtle += ` sh:path <${prop.path}> ;\n`;
238
-
264
+ if (prop.inversePath) {
265
+ turtle += ` sh:path [ sh:inversePath <${prop.path}> ] ;\n`;
266
+ } else {
267
+ turtle += ` sh:path <${prop.path}> ;\n`;
268
+ }
269
+
239
270
  if (prop.datatype) {
240
271
  turtle += ` sh:datatype <${prop.datatype}> ;\n`;
241
272
  }
242
-
273
+
243
274
  if (prop.nodeKind) {
244
275
  turtle += ` sh:nodeKind sh:${prop.nodeKind} ;\n`;
245
276
  }
246
-
277
+
247
278
  if (prop.minCount !== undefined) {
248
279
  turtle += ` sh:minCount ${prop.minCount} ;\n`;
249
280
  }
250
-
281
+
251
282
  if (prop.maxCount !== undefined) {
252
283
  turtle += ` sh:maxCount ${prop.maxCount} ;\n`;
253
284
  }
254
-
285
+
255
286
  if (prop.pattern) {
256
287
  turtle += ` sh:pattern "${escapeTurtleString(prop.pattern)}" ;\n`;
257
288
  }
258
-
289
+
259
290
  if (prop.minInclusive !== undefined) {
260
291
  turtle += ` sh:minInclusive ${prop.minInclusive} ;\n`;
261
292
  }
262
-
293
+
263
294
  if (prop.maxInclusive !== undefined) {
264
295
  turtle += ` sh:maxInclusive ${prop.maxInclusive} ;\n`;
265
296
  }
266
-
297
+
267
298
  if (prop.hasValue) {
268
299
  turtle += ` sh:hasValue "${escapeTurtleString(prop.hasValue)}" ;\n`;
269
300
  }
270
-
301
+
271
302
  // AD4M-specific metadata
272
303
  if (prop.local !== undefined) {
273
304
  turtle += ` ad4m:local ${prop.local} ;\n`;
274
305
  }
275
-
276
- if (prop.writable !== undefined) {
277
- turtle += ` ad4m:writable ${prop.writable} ;\n`;
306
+
307
+ if (prop.readOnly !== undefined) {
308
+ turtle += ` ad4m:readOnly ${prop.readOnly} ;\n`;
278
309
  }
279
-
310
+
280
311
  // Remove trailing semicolon and close bracket
281
- turtle = turtle.slice(0, -2) + '\n';
312
+ turtle = turtle.slice(0, -2) + "\n";
282
313
  turtle += isLast ? ` ] .\n` : ` ] ;\n`;
283
314
  }
284
-
315
+
285
316
  return turtle;
286
317
  }
287
-
318
+
288
319
  /**
289
320
  * Serialize shape to AD4M Links (RDF triples)
290
321
  * Stores the shape as a graph of links in a Perspective
@@ -296,7 +327,7 @@ export class SHACLShape {
296
327
  links.push({
297
328
  source: this.nodeShapeUri,
298
329
  predicate: "rdf://type",
299
- target: "sh://NodeShape"
330
+ target: "sh://NodeShape",
300
331
  });
301
332
 
302
333
  // Target class
@@ -304,16 +335,30 @@ export class SHACLShape {
304
335
  links.push({
305
336
  source: this.nodeShapeUri,
306
337
  predicate: "sh://targetClass",
307
- target: this.targetClass
338
+ target: this.targetClass,
308
339
  });
309
340
  }
310
341
 
311
- // Constructor actions
312
- if (this.constructor_actions && this.constructor_actions.length > 0) {
342
+ // Parent shape references (sh:node — SHACL inheritance)
343
+ if (this.parentShapes && this.parentShapes.length > 0) {
344
+ for (const parentUri of this.parentShapes) {
345
+ links.push({
346
+ source: this.nodeShapeUri,
347
+ predicate: "sh://node",
348
+ target: parentUri,
349
+ });
350
+ }
351
+ }
352
+
353
+ // Constructor actions – always emit this link (even for an empty array)
354
+ // so the Rust backend can distinguish "class registered but no init steps"
355
+ // from "class not registered", and create_subject can succeed with 0
356
+ // commands for classes that have no @Flag / initial-valued properties.
357
+ if (this.constructor_actions !== undefined) {
313
358
  links.push({
314
359
  source: this.nodeShapeUri,
315
360
  predicate: "ad4m://constructor",
316
- target: `literal://string:${JSON.stringify(this.constructor_actions)}`
361
+ target: `literal://string:${JSON.stringify(this.constructor_actions)}`,
317
362
  });
318
363
  }
319
364
 
@@ -322,14 +367,14 @@ export class SHACLShape {
322
367
  links.push({
323
368
  source: this.nodeShapeUri,
324
369
  predicate: "ad4m://destructor",
325
- target: `literal://string:${JSON.stringify(this.destructor_actions)}`
370
+ target: `literal://string:${JSON.stringify(this.destructor_actions)}`,
326
371
  });
327
372
  }
328
-
373
+
329
374
  // Property shapes (each gets a named URI: {namespace}/{ClassName}.{propertyName})
330
375
  for (let i = 0; i < this.properties.length; i++) {
331
376
  const prop = this.properties[i];
332
-
377
+
333
378
  // Generate named property shape URI
334
379
  let propShapeId: string;
335
380
  if (prop.name && this.targetClass) {
@@ -342,100 +387,100 @@ export class SHACLShape {
342
387
  // Fallback to blank node if name is missing
343
388
  propShapeId = `_:propShape${i}`;
344
389
  }
345
-
390
+
346
391
  // Link shape to property shape
347
392
  links.push({
348
393
  source: this.nodeShapeUri,
349
394
  predicate: "sh://property",
350
- target: propShapeId
395
+ target: propShapeId,
351
396
  });
352
-
353
- // Property path
397
+
398
+ // Property path (forward or inverse)
354
399
  links.push({
355
400
  source: propShapeId,
356
- predicate: "sh://path",
357
- target: prop.path
401
+ predicate: prop.inversePath ? "sh://inversePath" : "sh://path",
402
+ target: prop.path,
358
403
  });
359
-
404
+
360
405
  // Constraints
361
406
  if (prop.datatype) {
362
407
  links.push({
363
408
  source: propShapeId,
364
409
  predicate: "sh://datatype",
365
- target: prop.datatype
410
+ target: prop.datatype,
366
411
  });
367
412
  }
368
-
413
+
369
414
  if (prop.nodeKind) {
370
415
  links.push({
371
416
  source: propShapeId,
372
417
  predicate: "sh://nodeKind",
373
- target: `sh://${prop.nodeKind}`
418
+ target: `sh://${prop.nodeKind}`,
374
419
  });
375
420
  }
376
-
421
+
377
422
  if (prop.minCount !== undefined) {
378
423
  links.push({
379
424
  source: propShapeId,
380
425
  predicate: "sh://minCount",
381
- target: `literal://${prop.minCount}^^xsd:integer`
426
+ target: `literal://${prop.minCount}^^xsd:integer`,
382
427
  });
383
428
  }
384
-
429
+
385
430
  if (prop.maxCount !== undefined) {
386
431
  links.push({
387
432
  source: propShapeId,
388
433
  predicate: "sh://maxCount",
389
- target: `literal://${prop.maxCount}^^xsd:integer`
434
+ target: `literal://${prop.maxCount}^^xsd:integer`,
390
435
  });
391
436
  }
392
-
437
+
393
438
  if (prop.pattern) {
394
439
  links.push({
395
440
  source: propShapeId,
396
441
  predicate: "sh://pattern",
397
- target: `literal://${prop.pattern}`
442
+ target: `literal://${prop.pattern}`,
398
443
  });
399
444
  }
400
-
445
+
401
446
  if (prop.minInclusive !== undefined) {
402
447
  links.push({
403
448
  source: propShapeId,
404
449
  predicate: "sh://minInclusive",
405
- target: `literal://${prop.minInclusive}`
450
+ target: `literal://${prop.minInclusive}`,
406
451
  });
407
452
  }
408
-
453
+
409
454
  if (prop.maxInclusive !== undefined) {
410
455
  links.push({
411
456
  source: propShapeId,
412
457
  predicate: "sh://maxInclusive",
413
- target: `literal://${prop.maxInclusive}`
458
+ target: `literal://${prop.maxInclusive}`,
414
459
  });
415
460
  }
416
-
461
+
417
462
  if (prop.hasValue) {
418
463
  links.push({
419
464
  source: propShapeId,
420
465
  predicate: "sh://hasValue",
421
- target: `literal://${prop.hasValue}`
466
+ target: `literal://${prop.hasValue}`,
422
467
  });
423
468
  }
424
-
469
+
425
470
  // AD4M-specific metadata
426
471
  if (prop.local !== undefined) {
427
472
  links.push({
428
473
  source: propShapeId,
429
474
  predicate: "ad4m://local",
430
- target: `literal://${prop.local}`
475
+ target: `literal://${prop.local}`,
431
476
  });
432
477
  }
433
-
434
- if (prop.writable !== undefined) {
478
+
479
+ if (prop.readOnly !== undefined) {
435
480
  links.push({
436
481
  source: propShapeId,
437
- predicate: "ad4m://writable",
438
- target: `literal://${prop.writable}`
482
+ predicate: "ad4m://readOnly",
483
+ target: `literal://${prop.readOnly}`,
439
484
  });
440
485
  }
441
486
 
@@ -443,7 +488,7 @@ export class SHACLShape {
443
488
  links.push({
444
489
  source: propShapeId,
445
490
  predicate: "ad4m://resolveLanguage",
446
- target: `literal://string:${prop.resolveLanguage}`
491
+ target: `literal://string:${prop.resolveLanguage}`,
447
492
  });
448
493
  }
449
494
 
@@ -452,7 +497,7 @@ export class SHACLShape {
452
497
  links.push({
453
498
  source: propShapeId,
454
499
  predicate: "ad4m://setter",
455
- target: `literal://string:${JSON.stringify(prop.setter)}`
500
+ target: `literal://string:${JSON.stringify(prop.setter)}`,
456
501
  });
457
502
  }
458
503
 
@@ -460,7 +505,7 @@ export class SHACLShape {
460
505
  links.push({
461
506
  source: propShapeId,
462
507
  predicate: "ad4m://adder",
463
- target: `literal://string:${JSON.stringify(prop.adder)}`
508
+ target: `literal://string:${JSON.stringify(prop.adder)}`,
464
509
  });
465
510
  }
466
511
 
@@ -468,32 +513,32 @@ export class SHACLShape {
468
513
  links.push({
469
514
  source: propShapeId,
470
515
  predicate: "ad4m://remover",
471
- target: `literal://string:${JSON.stringify(prop.remover)}`
516
+ target: `literal://string:${JSON.stringify(prop.remover)}`,
472
517
  });
473
518
  }
474
519
  }
475
520
 
476
521
  return links;
477
522
  }
478
-
523
+
479
524
  /**
480
525
  * Reconstruct shape from AD4M Links
481
526
  */
482
527
  static fromLinks(links: Link[], shapeUri: string): SHACLShape {
483
528
  // Find target class
484
- const targetClassLink = links.find(l =>
485
- l.source === shapeUri && l.predicate === "sh://targetClass"
529
+ const targetClassLink = links.find(
530
+ (l) => l.source === shapeUri && l.predicate === "sh://targetClass",
486
531
  );
487
-
532
+
488
533
  const shape = new SHACLShape(shapeUri, targetClassLink?.target);
489
534
 
490
535
  // Find constructor actions
491
- const constructorLink = links.find(l =>
492
- l.source === shapeUri && l.predicate === "ad4m://constructor"
536
+ const constructorLink = links.find(
537
+ (l) => l.source === shapeUri && l.predicate === "ad4m://constructor",
493
538
  );
494
539
  if (constructorLink) {
495
540
  try {
496
- const jsonStr = constructorLink.target.replace('literal://string:', '');
541
+ const jsonStr = constructorLink.target.replace("literal://string:", "");
497
542
  shape.constructor_actions = JSON.parse(jsonStr);
498
543
  } catch (e) {
499
544
  // Ignore parse errors
@@ -501,12 +546,12 @@ export class SHACLShape {
501
546
  }
502
547
 
503
548
  // Find destructor actions
504
- const destructorLink = links.find(l =>
505
- l.source === shapeUri && l.predicate === "ad4m://destructor"
549
+ const destructorLink = links.find(
550
+ (l) => l.source === shapeUri && l.predicate === "ad4m://destructor",
506
551
  );
507
552
  if (destructorLink) {
508
553
  try {
509
- const jsonStr = destructorLink.target.replace('literal://string:', '');
554
+ const jsonStr = destructorLink.target.replace("literal://string:", "");
510
555
  shape.destructor_actions = JSON.parse(jsonStr);
511
556
  } catch (e) {
512
557
  // Ignore parse errors
@@ -514,161 +559,169 @@ export class SHACLShape {
514
559
  }
515
560
 
516
561
  // Find all property shapes
517
- const propShapeLinks = links.filter(l =>
518
- l.source === shapeUri && l.predicate === "sh://property"
562
+ const propShapeLinks = links.filter(
563
+ (l) => l.source === shapeUri && l.predicate === "sh://property",
519
564
  );
520
-
565
+
521
566
  for (const propLink of propShapeLinks) {
522
567
  const propShapeId = propLink.target;
523
-
568
+
524
569
  // Reconstruct property from its links
525
- const pathLink = links.find(l =>
526
- l.source === propShapeId && l.predicate === "sh://path"
570
+ const pathLink = links.find(
571
+ (l) => l.source === propShapeId && l.predicate === "sh://path",
527
572
  );
528
-
573
+
529
574
  if (!pathLink) continue;
530
-
575
+
531
576
  // Extract property name from propShapeId if it's a named URI
532
577
  // Format: {namespace}{ClassName}.{propertyName}
533
578
  let propertyName: string | undefined;
534
- if (!propShapeId.startsWith('_:')) {
535
- const lastDotIndex = propShapeId.lastIndexOf('.');
579
+ if (!propShapeId.startsWith("_:")) {
580
+ const lastDotIndex = propShapeId.lastIndexOf(".");
536
581
  if (lastDotIndex !== -1) {
537
582
  propertyName = propShapeId.substring(lastDotIndex + 1);
538
583
  }
539
584
  }
540
-
585
+
541
586
  const prop: SHACLPropertyShape = {
542
587
  name: propertyName,
543
- path: pathLink.target
588
+ path: pathLink.target,
544
589
  };
545
-
590
+
546
591
  // Extract constraints
547
- const datatypeLink = links.find(l =>
548
- l.source === propShapeId && l.predicate === "sh://datatype"
592
+ const datatypeLink = links.find(
593
+ (l) => l.source === propShapeId && l.predicate === "sh://datatype",
549
594
  );
550
595
  if (datatypeLink) prop.datatype = datatypeLink.target;
551
-
552
- const nodeKindLink = links.find(l =>
553
- l.source === propShapeId && l.predicate === "sh://nodeKind"
596
+
597
+ const nodeKindLink = links.find(
598
+ (l) => l.source === propShapeId && l.predicate === "sh://nodeKind",
554
599
  );
555
600
  if (nodeKindLink) {
556
- prop.nodeKind = nodeKindLink.target.replace('sh://', '') as any;
601
+ prop.nodeKind = nodeKindLink.target.replace("sh://", "") as any;
557
602
  }
558
-
559
- const minCountLink = links.find(l =>
560
- l.source === propShapeId && l.predicate === "sh://minCount"
603
+
604
+ const minCountLink = links.find(
605
+ (l) => l.source === propShapeId && l.predicate === "sh://minCount",
561
606
  );
562
607
  if (minCountLink) {
563
608
  // Handle both formats: literal://5^^xsd:integer and literal://number:5
564
- let val = minCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
565
- if (val.startsWith('number:')) val = val.substring(7);
609
+ let val = minCountLink.target
610
+ .replace("literal://", "")
611
+ .replace(/\^\^.*$/, "");
612
+ if (val.startsWith("number:")) val = val.substring(7);
566
613
  prop.minCount = parseInt(val);
567
614
  }
568
-
569
- const maxCountLink = links.find(l =>
570
- l.source === propShapeId && l.predicate === "sh://maxCount"
615
+
616
+ const maxCountLink = links.find(
617
+ (l) => l.source === propShapeId && l.predicate === "sh://maxCount",
571
618
  );
572
619
  if (maxCountLink) {
573
620
  // Handle both formats: literal://5^^xsd:integer and literal://number:5
574
- let val = maxCountLink.target.replace('literal://', '').replace(/\^\^.*$/, '');
575
- if (val.startsWith('number:')) val = val.substring(7);
621
+ let val = maxCountLink.target
622
+ .replace("literal://", "")
623
+ .replace(/\^\^.*$/, "");
624
+ if (val.startsWith("number:")) val = val.substring(7);
576
625
  prop.maxCount = parseInt(val);
577
626
  }
578
-
579
- const patternLink = links.find(l =>
580
- l.source === propShapeId && l.predicate === "sh://pattern"
627
+
628
+ const patternLink = links.find(
629
+ (l) => l.source === propShapeId && l.predicate === "sh://pattern",
581
630
  );
582
631
  if (patternLink) {
583
- prop.pattern = patternLink.target.replace('literal://', '');
632
+ prop.pattern = patternLink.target.replace("literal://", "");
584
633
  }
585
-
586
- const minInclusiveLink = links.find(l =>
587
- l.source === propShapeId && l.predicate === "sh://minInclusive"
634
+
635
+ const minInclusiveLink = links.find(
636
+ (l) => l.source === propShapeId && l.predicate === "sh://minInclusive",
588
637
  );
589
638
  if (minInclusiveLink) {
590
639
  // Handle both formats: literal://5 and literal://number:5
591
- let val = minInclusiveLink.target.replace('literal://', '');
592
- if (val.startsWith('number:')) val = val.substring(7);
640
+ let val = minInclusiveLink.target.replace("literal://", "");
641
+ if (val.startsWith("number:")) val = val.substring(7);
593
642
  prop.minInclusive = parseFloat(val);
594
643
  }
595
644
 
596
- const maxInclusiveLink = links.find(l =>
597
- l.source === propShapeId && l.predicate === "sh://maxInclusive"
645
+ const maxInclusiveLink = links.find(
646
+ (l) => l.source === propShapeId && l.predicate === "sh://maxInclusive",
598
647
  );
599
648
  if (maxInclusiveLink) {
600
649
  // Handle both formats: literal://5 and literal://number:5
601
- let val = maxInclusiveLink.target.replace('literal://', '');
602
- if (val.startsWith('number:')) val = val.substring(7);
650
+ let val = maxInclusiveLink.target.replace("literal://", "");
651
+ if (val.startsWith("number:")) val = val.substring(7);
603
652
  prop.maxInclusive = parseFloat(val);
604
653
  }
605
-
606
- const hasValueLink = links.find(l =>
607
- l.source === propShapeId && l.predicate === "sh://hasValue"
654
+
655
+ const hasValueLink = links.find(
656
+ (l) => l.source === propShapeId && l.predicate === "sh://hasValue",
608
657
  );
609
658
  if (hasValueLink) {
610
- prop.hasValue = hasValueLink.target.replace('literal://', '');
659
+ prop.hasValue = hasValueLink.target.replace("literal://", "");
611
660
  }
612
-
661
+
613
662
  // AD4M-specific
614
- const localLink = links.find(l =>
615
- l.source === propShapeId && l.predicate === "ad4m://local"
663
+ const localLink = links.find(
664
+ (l) => l.source === propShapeId && l.predicate === "ad4m://local",
616
665
  );
617
666
  if (localLink) {
618
667
  // Handle both formats: literal://true and literal://boolean:true
619
- let val = localLink.target.replace('literal://', '');
620
- if (val.startsWith('boolean:')) val = val.substring(8);
621
- prop.local = val === 'true';
668
+ let val = localLink.target.replace("literal://", "");
669
+ if (val.startsWith("boolean:")) val = val.substring(8);
670
+ prop.local = val === "true";
622
671
  }
623
-
624
- const writableLink = links.find(l =>
625
- l.source === propShapeId && l.predicate === "ad4m://writable"
672
+
673
+ const readOnlyLink = links.find(
674
+ (l) => l.source === propShapeId && l.predicate === "ad4m://readOnly",
626
675
  );
627
- if (writableLink) {
676
+ if (readOnlyLink) {
628
677
  // Handle both formats: literal://true and literal://boolean:true
629
- let val = writableLink.target.replace('literal://', '');
630
- if (val.startsWith('boolean:')) val = val.substring(8);
631
- prop.writable = val === 'true';
678
+ let val = readOnlyLink.target.replace("literal://", "");
679
+ if (val.startsWith("boolean:")) val = val.substring(8);
680
+ prop.readOnly = val === "true";
632
681
  }
633
682
 
634
- const resolveLangLink = links.find(l =>
635
- l.source === propShapeId && l.predicate === "ad4m://resolveLanguage"
683
+ const resolveLangLink = links.find(
684
+ (l) =>
685
+ l.source === propShapeId && l.predicate === "ad4m://resolveLanguage",
636
686
  );
637
687
  if (resolveLangLink) {
638
- prop.resolveLanguage = resolveLangLink.target.replace('literal://string:', '');
688
+ prop.resolveLanguage = resolveLangLink.target.replace(
689
+ "literal://string:",
690
+ "",
691
+ );
639
692
  }
640
693
 
641
694
  // Parse action arrays
642
- const setterLink = links.find(l =>
643
- l.source === propShapeId && l.predicate === "ad4m://setter"
695
+ const setterLink = links.find(
696
+ (l) => l.source === propShapeId && l.predicate === "ad4m://setter",
644
697
  );
645
698
  if (setterLink) {
646
699
  try {
647
- const jsonStr = setterLink.target.replace('literal://string:', '');
700
+ const jsonStr = setterLink.target.replace("literal://string:", "");
648
701
  prop.setter = JSON.parse(jsonStr);
649
702
  } catch (e) {
650
703
  // Ignore parse errors
651
704
  }
652
705
  }
653
706
 
654
- const adderLink = links.find(l =>
655
- l.source === propShapeId && l.predicate === "ad4m://adder"
707
+ const adderLink = links.find(
708
+ (l) => l.source === propShapeId && l.predicate === "ad4m://adder",
656
709
  );
657
710
  if (adderLink) {
658
711
  try {
659
- const jsonStr = adderLink.target.replace('literal://string:', '');
712
+ const jsonStr = adderLink.target.replace("literal://string:", "");
660
713
  prop.adder = JSON.parse(jsonStr);
661
714
  } catch (e) {
662
715
  // Ignore parse errors
663
716
  }
664
717
  }
665
718
 
666
- const removerLink = links.find(l =>
667
- l.source === propShapeId && l.predicate === "ad4m://remover"
719
+ const removerLink = links.find(
720
+ (l) => l.source === propShapeId && l.predicate === "ad4m://remover",
668
721
  );
669
722
  if (removerLink) {
670
723
  try {
671
- const jsonStr = removerLink.target.replace('literal://string:', '');
724
+ const jsonStr = removerLink.target.replace("literal://string:", "");
672
725
  prop.remover = JSON.parse(jsonStr);
673
726
  } catch (e) {
674
727
  // Ignore parse errors
@@ -677,21 +730,21 @@ export class SHACLShape {
677
730
 
678
731
  shape.addProperty(prop);
679
732
  }
680
-
733
+
681
734
  return shape;
682
735
  }
683
736
 
684
737
  /**
685
738
  * Convert the shape to a JSON-serializable object.
686
739
  * Useful for passing to addSdna() as shaclJson parameter.
687
- *
740
+ *
688
741
  * @returns JSON-serializable object representing the shape
689
742
  */
690
743
  toJSON(): object {
691
744
  return {
692
745
  node_shape_uri: this.nodeShapeUri,
693
746
  target_class: this.targetClass,
694
- properties: this.properties.map(p => ({
747
+ properties: this.properties.map((p) => ({
695
748
  path: p.path,
696
749
  name: p.name,
697
750
  datatype: p.datatype,
@@ -703,7 +756,7 @@ export class SHACLShape {
703
756
  pattern: p.pattern,
704
757
  has_value: p.hasValue,
705
758
  local: p.local,
706
- writable: p.writable,
759
+ read_only: p.readOnly,
707
760
  resolve_language: p.resolveLanguage,
708
761
  setter: p.setter,
709
762
  adder: p.adder,
@@ -721,7 +774,7 @@ export class SHACLShape {
721
774
  const shape = json.node_shape_uri
722
775
  ? new SHACLShape(json.node_shape_uri, json.target_class)
723
776
  : new SHACLShape(json.target_class);
724
-
777
+
725
778
  for (const p of json.properties || []) {
726
779
  shape.addProperty({
727
780
  path: p.path,
@@ -735,21 +788,21 @@ export class SHACLShape {
735
788
  pattern: p.pattern,
736
789
  hasValue: p.has_value,
737
790
  local: p.local,
738
- writable: p.writable,
791
+ readOnly: p.read_only,
739
792
  resolveLanguage: p.resolve_language,
740
793
  setter: p.setter,
741
794
  adder: p.adder,
742
795
  remover: p.remover,
743
796
  });
744
797
  }
745
-
798
+
746
799
  if (json.constructor_actions) {
747
800
  shape.constructor_actions = json.constructor_actions;
748
801
  }
749
802
  if (json.destructor_actions) {
750
803
  shape.destructor_actions = json.destructor_actions;
751
804
  }
752
-
805
+
753
806
  return shape;
754
807
  }
755
808
  }