@coasys/ad4m 0.12.0-rc1-dev → 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 -6044
  3. package/lib/index.js +5977 -6038
  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 -2797
  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 -3247
  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
@@ -1,24 +1,26 @@
1
- import { SHACLShape, SHACLPropertyShape, AD4MAction } from './SHACLShape';
1
+ import { SHACLShape, SHACLPropertyShape, AD4MAction } from "./SHACLShape";
2
2
 
3
- describe('SHACLShape', () => {
4
- describe('toLinks()', () => {
5
- it('creates basic shape links', () => {
6
- const shape = new SHACLShape('recipe://Recipe');
3
+ describe("SHACLShape", () => {
4
+ describe("toLinks()", () => {
5
+ it("creates basic shape links", () => {
6
+ const shape = new SHACLShape("recipe://Recipe");
7
7
  const links = shape.toLinks();
8
8
 
9
9
  // Should have targetClass link
10
- const targetClassLink = links.find(l => l.predicate === 'sh://targetClass');
10
+ const targetClassLink = links.find(
11
+ (l) => l.predicate === "sh://targetClass",
12
+ );
11
13
  expect(targetClassLink).toBeDefined();
12
- expect(targetClassLink!.source).toBe('recipe://RecipeShape');
13
- expect(targetClassLink!.target).toBe('recipe://Recipe');
14
+ expect(targetClassLink!.source).toBe("recipe://RecipeShape");
15
+ expect(targetClassLink!.target).toBe("recipe://Recipe");
14
16
  });
15
17
 
16
- it('creates property shape links with named URIs', () => {
17
- const shape = new SHACLShape('recipe://Recipe');
18
+ it("creates property shape links with named URIs", () => {
19
+ const shape = new SHACLShape("recipe://Recipe");
18
20
  const prop: SHACLPropertyShape = {
19
- name: 'name',
20
- path: 'recipe://name',
21
- datatype: 'xsd:string',
21
+ name: "name",
22
+ path: "recipe://name",
23
+ datatype: "xsd:string",
22
24
  minCount: 1,
23
25
  maxCount: 1,
24
26
  };
@@ -26,293 +28,351 @@ describe('SHACLShape', () => {
26
28
  const links = shape.toLinks();
27
29
 
28
30
  // Property shape should use named URI
29
- const propLink = links.find(l => l.predicate === 'sh://property');
31
+ const propLink = links.find((l) => l.predicate === "sh://property");
30
32
  expect(propLink).toBeDefined();
31
- expect(propLink!.target).toBe('recipe://Recipe.name'); // Named URI, not blank node
33
+ expect(propLink!.target).toBe("recipe://Recipe.name"); // Named URI, not blank node
32
34
 
33
35
  // Path link
34
- const pathLink = links.find(l =>
35
- l.source === 'recipe://Recipe.name' && l.predicate === 'sh://path'
36
+ const pathLink = links.find(
37
+ (l) =>
38
+ l.source === "recipe://Recipe.name" && l.predicate === "sh://path",
36
39
  );
37
40
  expect(pathLink).toBeDefined();
38
- expect(pathLink!.target).toBe('recipe://name');
41
+ expect(pathLink!.target).toBe("recipe://name");
39
42
 
40
43
  // Datatype link
41
- const datatypeLink = links.find(l =>
42
- l.source === 'recipe://Recipe.name' && l.predicate === 'sh://datatype'
44
+ const datatypeLink = links.find(
45
+ (l) =>
46
+ l.source === "recipe://Recipe.name" &&
47
+ l.predicate === "sh://datatype",
43
48
  );
44
49
  expect(datatypeLink).toBeDefined();
45
- expect(datatypeLink!.target).toBe('xsd:string');
50
+ expect(datatypeLink!.target).toBe("xsd:string");
46
51
 
47
52
  // Cardinality links
48
- const minCountLink = links.find(l =>
49
- l.source === 'recipe://Recipe.name' && l.predicate === 'sh://minCount'
53
+ const minCountLink = links.find(
54
+ (l) =>
55
+ l.source === "recipe://Recipe.name" &&
56
+ l.predicate === "sh://minCount",
50
57
  );
51
58
  expect(minCountLink).toBeDefined();
52
- expect(minCountLink!.target).toContain('1');
59
+ expect(minCountLink!.target).toContain("1");
53
60
 
54
- const maxCountLink = links.find(l =>
55
- l.source === 'recipe://Recipe.name' && l.predicate === 'sh://maxCount'
61
+ const maxCountLink = links.find(
62
+ (l) =>
63
+ l.source === "recipe://Recipe.name" &&
64
+ l.predicate === "sh://maxCount",
56
65
  );
57
66
  expect(maxCountLink).toBeDefined();
58
- expect(maxCountLink!.target).toContain('1');
67
+ expect(maxCountLink!.target).toContain("1");
59
68
  });
60
69
 
61
- it('creates action links', () => {
62
- const shape = new SHACLShape('recipe://Recipe');
70
+ it("creates action links", () => {
71
+ const shape = new SHACLShape("recipe://Recipe");
63
72
  const setterAction: AD4MAction = {
64
- action: 'addLink',
65
- source: 'this',
66
- predicate: 'recipe://name',
67
- target: 'value',
73
+ action: "addLink",
74
+ source: "this",
75
+ predicate: "recipe://name",
76
+ target: "value",
68
77
  };
69
78
  const prop: SHACLPropertyShape = {
70
- name: 'title',
71
- path: 'recipe://title',
79
+ name: "title",
80
+ path: "recipe://title",
72
81
  setter: [setterAction],
73
82
  };
74
83
  shape.addProperty(prop);
75
84
  const links = shape.toLinks();
76
85
 
77
86
  // Setter action link
78
- const setterLink = links.find(l =>
79
- l.source === 'recipe://Recipe.title' && l.predicate === 'ad4m://setter'
87
+ const setterLink = links.find(
88
+ (l) =>
89
+ l.source === "recipe://Recipe.title" &&
90
+ l.predicate === "ad4m://setter",
80
91
  );
81
92
  expect(setterLink).toBeDefined();
82
- expect(setterLink!.target).toContain('addLink');
93
+ expect(setterLink!.target).toContain("addLink");
83
94
  });
84
95
 
85
- it('includes constructor and destructor actions', () => {
86
- const shape = new SHACLShape('recipe://Recipe');
87
- shape.constructor_actions = [{
88
- action: 'addLink',
89
- source: 'this',
90
- predicate: 'ad4m://type',
91
- target: 'recipe://Recipe',
92
- }];
93
- shape.destructor_actions = [{
94
- action: 'removeLink',
95
- source: 'this',
96
- predicate: 'ad4m://type',
97
- target: 'recipe://Recipe',
98
- }];
96
+ it("includes constructor and destructor actions", () => {
97
+ const shape = new SHACLShape("recipe://Recipe");
98
+ shape.constructor_actions = [
99
+ {
100
+ action: "addLink",
101
+ source: "this",
102
+ predicate: "ad4m://type",
103
+ target: "recipe://Recipe",
104
+ },
105
+ ];
106
+ shape.destructor_actions = [
107
+ {
108
+ action: "removeLink",
109
+ source: "this",
110
+ predicate: "ad4m://type",
111
+ target: "recipe://Recipe",
112
+ },
113
+ ];
99
114
  const links = shape.toLinks();
100
115
 
101
- const constructorLink = links.find(l => l.predicate === 'ad4m://constructor');
116
+ const constructorLink = links.find(
117
+ (l) => l.predicate === "ad4m://constructor",
118
+ );
102
119
  expect(constructorLink).toBeDefined();
103
- expect(constructorLink!.target).toContain('addLink');
120
+ expect(constructorLink!.target).toContain("addLink");
104
121
 
105
- const destructorLink = links.find(l => l.predicate === 'ad4m://destructor');
122
+ const destructorLink = links.find(
123
+ (l) => l.predicate === "ad4m://destructor",
124
+ );
106
125
  expect(destructorLink).toBeDefined();
107
- expect(destructorLink!.target).toContain('removeLink');
126
+ expect(destructorLink!.target).toContain("removeLink");
108
127
  });
109
128
  });
110
129
 
111
- describe('fromLinks()', () => {
112
- it('reconstructs shape from links', () => {
113
- const originalShape = new SHACLShape('recipe://Recipe');
130
+ describe("fromLinks()", () => {
131
+ it("reconstructs shape from links", () => {
132
+ const originalShape = new SHACLShape("recipe://Recipe");
114
133
  originalShape.addProperty({
115
- name: 'name',
116
- path: 'recipe://name',
117
- datatype: 'xsd:string',
134
+ name: "name",
135
+ path: "recipe://name",
136
+ datatype: "xsd:string",
118
137
  minCount: 1,
119
138
  });
120
-
139
+
121
140
  const links = originalShape.toLinks();
122
- const reconstructed = SHACLShape.fromLinks(links, 'recipe://RecipeShape');
141
+ const reconstructed = SHACLShape.fromLinks(links, "recipe://RecipeShape");
123
142
 
124
- expect(reconstructed.targetClass).toBe('recipe://Recipe');
143
+ expect(reconstructed.targetClass).toBe("recipe://Recipe");
125
144
  expect(reconstructed.properties.length).toBe(1);
126
- expect(reconstructed.properties[0].path).toBe('recipe://name');
127
- expect(reconstructed.properties[0].datatype).toBe('xsd:string');
145
+ expect(reconstructed.properties[0].path).toBe("recipe://name");
146
+ expect(reconstructed.properties[0].datatype).toBe("xsd:string");
128
147
  expect(reconstructed.properties[0].minCount).toBe(1);
129
148
  });
130
149
 
131
- it('handles multiple properties', () => {
132
- const originalShape = new SHACLShape('recipe://Recipe');
150
+ it("handles multiple properties", () => {
151
+ const originalShape = new SHACLShape("recipe://Recipe");
133
152
  originalShape.addProperty({
134
- name: 'name',
135
- path: 'recipe://name',
136
- datatype: 'xsd:string',
153
+ name: "name",
154
+ path: "recipe://name",
155
+ datatype: "xsd:string",
137
156
  });
138
157
  originalShape.addProperty({
139
- name: 'servings',
140
- path: 'recipe://servings',
141
- datatype: 'xsd:integer',
158
+ name: "servings",
159
+ path: "recipe://servings",
160
+ datatype: "xsd:integer",
142
161
  });
143
-
162
+
144
163
  const links = originalShape.toLinks();
145
- const reconstructed = SHACLShape.fromLinks(links, 'recipe://RecipeShape');
164
+ const reconstructed = SHACLShape.fromLinks(links, "recipe://RecipeShape");
146
165
 
147
166
  expect(reconstructed.properties.length).toBe(2);
148
- const nameProp = reconstructed.properties.find(p => p.path === 'recipe://name');
149
- const servingsProp = reconstructed.properties.find(p => p.path === 'recipe://servings');
167
+ const nameProp = reconstructed.properties.find(
168
+ (p) => p.path === "recipe://name",
169
+ );
170
+ const servingsProp = reconstructed.properties.find(
171
+ (p) => p.path === "recipe://servings",
172
+ );
150
173
  expect(nameProp).toBeDefined();
151
174
  expect(servingsProp).toBeDefined();
152
- expect(nameProp!.datatype).toBe('xsd:string');
153
- expect(servingsProp!.datatype).toBe('xsd:integer');
175
+ expect(nameProp!.datatype).toBe("xsd:string");
176
+ expect(servingsProp!.datatype).toBe("xsd:integer");
154
177
  });
155
178
 
156
- it('reconstructs action arrays', () => {
157
- const originalShape = new SHACLShape('recipe://Recipe');
179
+ it("reconstructs action arrays", () => {
180
+ const originalShape = new SHACLShape("recipe://Recipe");
158
181
  const setterAction: AD4MAction = {
159
- action: 'addLink',
160
- source: 'this',
161
- predicate: 'recipe://name',
162
- target: 'value',
182
+ action: "addLink",
183
+ source: "this",
184
+ predicate: "recipe://name",
185
+ target: "value",
163
186
  };
164
187
  originalShape.addProperty({
165
- name: 'name',
166
- path: 'recipe://name',
188
+ name: "name",
189
+ path: "recipe://name",
167
190
  setter: [setterAction],
168
191
  });
169
-
192
+
170
193
  const links = originalShape.toLinks();
171
- const reconstructed = SHACLShape.fromLinks(links, 'recipe://RecipeShape');
194
+ const reconstructed = SHACLShape.fromLinks(links, "recipe://RecipeShape");
172
195
 
173
196
  expect(reconstructed.properties[0].setter).toBeDefined();
174
197
  expect(reconstructed.properties[0].setter!.length).toBe(1);
175
- expect(reconstructed.properties[0].setter![0].action).toBe('addLink');
198
+ expect(reconstructed.properties[0].setter![0].action).toBe("addLink");
176
199
  });
177
200
  });
178
201
 
179
- describe('round-trip serialization', () => {
180
- it('preserves all property attributes', () => {
181
- const original = new SHACLShape('test://Model');
202
+ describe("round-trip serialization", () => {
203
+ it("preserves all property attributes", () => {
204
+ const original = new SHACLShape("test://Model");
182
205
  original.addProperty({
183
- name: 'field',
184
- path: 'test://field',
185
- datatype: 'xsd:string',
186
- nodeKind: 'Literal',
206
+ name: "field",
207
+ path: "test://field",
208
+ datatype: "xsd:string",
209
+ nodeKind: "Literal",
187
210
  minCount: 0,
188
211
  maxCount: 5,
189
- pattern: '^[a-z]+$',
212
+ pattern: "^[a-z]+$",
190
213
  minInclusive: 10,
191
214
  maxInclusive: 100,
192
- hasValue: 'expectedValue',
193
- resolveLanguage: 'test://language',
215
+ hasValue: "expectedValue",
216
+ resolveLanguage: "test://language",
194
217
  local: true,
195
- writable: true,
196
- setter: [{ action: 'addLink', source: 'this', predicate: 'test://field', target: 'value' }],
197
- adder: [{ action: 'addLink', source: 'this', predicate: 'test://items', target: 'value' }],
198
- remover: [{ action: 'removeLink', source: 'this', predicate: 'test://items', target: 'value' }],
218
+ setter: [
219
+ {
220
+ action: "addLink",
221
+ source: "this",
222
+ predicate: "test://field",
223
+ target: "value",
224
+ },
225
+ ],
226
+ adder: [
227
+ {
228
+ action: "addLink",
229
+ source: "this",
230
+ predicate: "test://items",
231
+ target: "value",
232
+ },
233
+ ],
234
+ remover: [
235
+ {
236
+ action: "removeLink",
237
+ source: "this",
238
+ predicate: "test://items",
239
+ target: "value",
240
+ },
241
+ ],
199
242
  });
200
243
 
201
244
  const links = original.toLinks();
202
- const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
245
+ const reconstructed = SHACLShape.fromLinks(links, "test://ModelShape");
203
246
 
204
247
  const prop = reconstructed.properties[0];
205
- expect(prop.path).toBe('test://field');
206
- expect(prop.datatype).toBe('xsd:string');
207
- expect(prop.nodeKind).toBe('Literal');
248
+ expect(prop.path).toBe("test://field");
249
+ expect(prop.datatype).toBe("xsd:string");
250
+ expect(prop.nodeKind).toBe("Literal");
208
251
  expect(prop.minCount).toBe(0);
209
252
  expect(prop.maxCount).toBe(5);
210
- expect(prop.pattern).toBe('^[a-z]+$');
253
+ expect(prop.pattern).toBe("^[a-z]+$");
211
254
  expect(prop.minInclusive).toBe(10);
212
255
  expect(prop.maxInclusive).toBe(100);
213
- expect(prop.hasValue).toBe('expectedValue');
214
- expect(prop.resolveLanguage).toBe('test://language');
256
+ expect(prop.hasValue).toBe("expectedValue");
257
+ expect(prop.resolveLanguage).toBe("test://language");
215
258
  expect(prop.local).toBe(true);
216
- expect(prop.writable).toBe(true);
259
+ expect(prop.readOnly).toBeFalsy();
217
260
  expect(prop.setter).toBeDefined();
218
261
  expect(prop.adder).toBeDefined();
219
262
  expect(prop.remover).toBeDefined();
220
263
  });
221
264
 
222
- it('preserves constructor and destructor actions', () => {
223
- const original = new SHACLShape('test://Model');
265
+ it("preserves constructor and destructor actions", () => {
266
+ const original = new SHACLShape("test://Model");
224
267
  original.constructor_actions = [
225
- { action: 'addLink', source: 'this', predicate: 'rdf://type', target: 'test://Model' }
268
+ {
269
+ action: "addLink",
270
+ source: "this",
271
+ predicate: "rdf://type",
272
+ target: "test://Model",
273
+ },
226
274
  ];
227
275
  original.destructor_actions = [
228
- { action: 'removeLink', source: 'this', predicate: 'rdf://type', target: 'test://Model' }
276
+ {
277
+ action: "removeLink",
278
+ source: "this",
279
+ predicate: "rdf://type",
280
+ target: "test://Model",
281
+ },
229
282
  ];
230
283
 
231
284
  const links = original.toLinks();
232
- const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
285
+ const reconstructed = SHACLShape.fromLinks(links, "test://ModelShape");
233
286
 
234
287
  expect(reconstructed.constructor_actions).toBeDefined();
235
288
  expect(reconstructed.constructor_actions!.length).toBe(1);
236
- expect(reconstructed.constructor_actions![0].action).toBe('addLink');
289
+ expect(reconstructed.constructor_actions![0].action).toBe("addLink");
237
290
 
238
291
  expect(reconstructed.destructor_actions).toBeDefined();
239
292
  expect(reconstructed.destructor_actions!.length).toBe(1);
240
- expect(reconstructed.destructor_actions![0].action).toBe('removeLink');
293
+ expect(reconstructed.destructor_actions![0].action).toBe("removeLink");
241
294
  });
242
295
  });
243
296
 
244
- describe('edge cases', () => {
245
- it('handles empty shape', () => {
246
- const shape = new SHACLShape('test://Empty');
297
+ describe("edge cases", () => {
298
+ it("handles empty shape", () => {
299
+ const shape = new SHACLShape("test://Empty");
247
300
  const links = shape.toLinks();
248
-
301
+
249
302
  expect(links.length).toBeGreaterThanOrEqual(1); // At least targetClass link
250
-
251
- const reconstructed = SHACLShape.fromLinks(links, 'test://EmptyShape');
252
- expect(reconstructed.targetClass).toBe('test://Empty');
303
+
304
+ const reconstructed = SHACLShape.fromLinks(links, "test://EmptyShape");
305
+ expect(reconstructed.targetClass).toBe("test://Empty");
253
306
  expect(reconstructed.properties.length).toBe(0);
254
307
  });
255
308
 
256
- it('handles URI with hash fragment', () => {
257
- const shape = new SHACLShape('https://example.com/vocab#Recipe');
309
+ it("handles URI with hash fragment", () => {
310
+ const shape = new SHACLShape("https://example.com/vocab#Recipe");
258
311
  const links = shape.toLinks();
259
-
260
- const targetClassLink = links.find(l => l.predicate === 'sh://targetClass');
261
- expect(targetClassLink!.source).toBe('https://example.com/vocab#RecipeShape');
312
+
313
+ const targetClassLink = links.find(
314
+ (l) => l.predicate === "sh://targetClass",
315
+ );
316
+ expect(targetClassLink!.source).toBe(
317
+ "https://example.com/vocab#RecipeShape",
318
+ );
262
319
  });
263
320
 
264
- it('falls back to blank nodes when property has no name', () => {
265
- const shape = new SHACLShape('test://Model');
321
+ it("falls back to blank nodes when property has no name", () => {
322
+ const shape = new SHACLShape("test://Model");
266
323
  shape.addProperty({
267
- path: 'test://unnamed',
324
+ path: "test://unnamed",
268
325
  // No name property
269
326
  });
270
327
  const links = shape.toLinks();
271
-
272
- const propLink = links.find(l => l.predicate === 'sh://property');
328
+
329
+ const propLink = links.find((l) => l.predicate === "sh://property");
273
330
  expect(propLink).toBeDefined();
274
331
  // Should use blank node format when no name provided
275
332
  expect(propLink!.target).toMatch(/_:propShape\d+|test:\/\/Model\./);
276
333
  });
277
334
  });
278
335
 
279
- describe('toJSON/fromJSON', () => {
280
- it('serializes and deserializes basic shape', () => {
281
- const original = new SHACLShape('recipe://Recipe');
336
+ describe("toJSON/fromJSON", () => {
337
+ it("serializes and deserializes basic shape", () => {
338
+ const original = new SHACLShape("recipe://Recipe");
282
339
  original.addProperty({
283
- name: 'name',
284
- path: 'recipe://name',
285
- datatype: 'xsd:string',
340
+ name: "name",
341
+ path: "recipe://name",
342
+ datatype: "xsd:string",
286
343
  minCount: 1,
287
344
  });
288
345
 
289
346
  const json = original.toJSON();
290
347
  const reconstructed = SHACLShape.fromJSON(json);
291
348
 
292
- expect(reconstructed.targetClass).toBe('recipe://Recipe');
349
+ expect(reconstructed.targetClass).toBe("recipe://Recipe");
293
350
  expect(reconstructed.properties.length).toBe(1);
294
- expect(reconstructed.properties[0].name).toBe('name');
295
- expect(reconstructed.properties[0].path).toBe('recipe://name');
296
- expect(reconstructed.properties[0].datatype).toBe('xsd:string');
351
+ expect(reconstructed.properties[0].name).toBe("name");
352
+ expect(reconstructed.properties[0].path).toBe("recipe://name");
353
+ expect(reconstructed.properties[0].datatype).toBe("xsd:string");
297
354
  expect(reconstructed.properties[0].minCount).toBe(1);
298
355
  });
299
356
 
300
- it('preserves nodeShapeUri in round-trip', () => {
301
- const original = new SHACLShape('custom://CustomShape', 'recipe://Recipe');
357
+ it("preserves nodeShapeUri in round-trip", () => {
358
+ const original = new SHACLShape(
359
+ "custom://CustomShape",
360
+ "recipe://Recipe",
361
+ );
302
362
 
303
363
  const json = original.toJSON();
304
364
  const reconstructed = SHACLShape.fromJSON(json);
305
365
 
306
- expect(reconstructed.nodeShapeUri).toBe('custom://CustomShape');
307
- expect(reconstructed.targetClass).toBe('recipe://Recipe');
366
+ expect(reconstructed.nodeShapeUri).toBe("custom://CustomShape");
367
+ expect(reconstructed.targetClass).toBe("recipe://Recipe");
308
368
  });
309
369
 
310
- it('preserves minInclusive and maxInclusive', () => {
311
- const original = new SHACLShape('test://Model');
370
+ it("preserves minInclusive and maxInclusive", () => {
371
+ const original = new SHACLShape("test://Model");
312
372
  original.addProperty({
313
- name: 'rating',
314
- path: 'test://rating',
315
- datatype: 'xsd:integer',
373
+ name: "rating",
374
+ path: "test://rating",
375
+ datatype: "xsd:integer",
316
376
  minInclusive: 1,
317
377
  maxInclusive: 5,
318
378
  });
@@ -324,74 +384,108 @@ describe('SHACLShape', () => {
324
384
  expect(reconstructed.properties[0].maxInclusive).toBe(5);
325
385
  });
326
386
 
327
- it('preserves resolveLanguage', () => {
328
- const original = new SHACLShape('test://Model');
387
+ it("preserves resolveLanguage", () => {
388
+ const original = new SHACLShape("test://Model");
329
389
  original.addProperty({
330
- name: 'content',
331
- path: 'test://content',
332
- resolveLanguage: 'literal',
390
+ name: "content",
391
+ path: "test://content",
392
+ resolveLanguage: "literal",
333
393
  });
334
394
 
335
395
  const json = original.toJSON();
336
396
  const reconstructed = SHACLShape.fromJSON(json);
337
397
 
338
- expect(reconstructed.properties[0].resolveLanguage).toBe('literal');
398
+ expect(reconstructed.properties[0].resolveLanguage).toBe("literal");
339
399
  });
340
400
 
341
- it('preserves constructor and destructor actions', () => {
342
- const original = new SHACLShape('test://Model');
401
+ it("preserves constructor and destructor actions", () => {
402
+ const original = new SHACLShape("test://Model");
343
403
  original.constructor_actions = [
344
- { action: 'addLink', source: 'this', predicate: 'rdf://type', target: 'test://Model' }
404
+ {
405
+ action: "addLink",
406
+ source: "this",
407
+ predicate: "rdf://type",
408
+ target: "test://Model",
409
+ },
345
410
  ];
346
411
  original.destructor_actions = [
347
- { action: 'removeLink', source: 'this', predicate: 'rdf://type', target: 'test://Model' }
412
+ {
413
+ action: "removeLink",
414
+ source: "this",
415
+ predicate: "rdf://type",
416
+ target: "test://Model",
417
+ },
348
418
  ];
349
419
 
350
420
  const json = original.toJSON();
351
421
  const reconstructed = SHACLShape.fromJSON(json);
352
422
 
353
- expect(reconstructed.constructor_actions).toEqual(original.constructor_actions);
354
- expect(reconstructed.destructor_actions).toEqual(original.destructor_actions);
423
+ expect(reconstructed.constructor_actions).toEqual(
424
+ original.constructor_actions,
425
+ );
426
+ expect(reconstructed.destructor_actions).toEqual(
427
+ original.destructor_actions,
428
+ );
355
429
  });
356
430
 
357
- it('preserves all property attributes', () => {
358
- const original = new SHACLShape('test://Model');
431
+ it("preserves all property attributes", () => {
432
+ const original = new SHACLShape("test://Model");
359
433
  original.addProperty({
360
- name: 'field',
361
- path: 'test://field',
362
- datatype: 'xsd:string',
363
- nodeKind: 'Literal',
434
+ name: "field",
435
+ path: "test://field",
436
+ datatype: "xsd:string",
437
+ nodeKind: "Literal",
364
438
  minCount: 0,
365
439
  maxCount: 5,
366
440
  minInclusive: 0,
367
441
  maxInclusive: 100,
368
- pattern: '^[a-z]+$',
369
- hasValue: 'default',
442
+ pattern: "^[a-z]+$",
443
+ hasValue: "default",
370
444
  local: true,
371
- writable: true,
372
- resolveLanguage: 'literal',
373
- setter: [{ action: 'addLink', source: 'this', predicate: 'test://field', target: 'value' }],
374
- adder: [{ action: 'addLink', source: 'this', predicate: 'test://items', target: 'value' }],
375
- remover: [{ action: 'removeLink', source: 'this', predicate: 'test://items', target: 'value' }],
445
+ resolveLanguage: "literal",
446
+ setter: [
447
+ {
448
+ action: "addLink",
449
+ source: "this",
450
+ predicate: "test://field",
451
+ target: "value",
452
+ },
453
+ ],
454
+ adder: [
455
+ {
456
+ action: "addLink",
457
+ source: "this",
458
+ predicate: "test://items",
459
+ target: "value",
460
+ },
461
+ ],
462
+ remover: [
463
+ {
464
+ action: "removeLink",
465
+ source: "this",
466
+ predicate: "test://items",
467
+ target: "value",
468
+ },
469
+ ],
376
470
  });
377
471
 
378
472
  const json = original.toJSON();
379
473
  const reconstructed = SHACLShape.fromJSON(json);
380
474
 
381
475
  const prop = reconstructed.properties[0];
382
- expect(prop.name).toBe('field');
383
- expect(prop.path).toBe('test://field');
384
- expect(prop.datatype).toBe('xsd:string');
385
- expect(prop.nodeKind).toBe('Literal');
476
+ expect(prop.name).toBe("field");
477
+ expect(prop.path).toBe("test://field");
478
+ expect(prop.datatype).toBe("xsd:string");
479
+ expect(prop.nodeKind).toBe("Literal");
386
480
  expect(prop.minCount).toBe(0);
387
481
  expect(prop.maxCount).toBe(5);
388
482
  expect(prop.minInclusive).toBe(0);
389
483
  expect(prop.maxInclusive).toBe(100);
390
- expect(prop.pattern).toBe('^[a-z]+$');
391
- expect(prop.hasValue).toBe('default');
484
+ expect(prop.pattern).toBe("^[a-z]+$");
485
+ expect(prop.hasValue).toBe("default");
392
486
  expect(prop.local).toBe(true);
393
- expect(prop.writable).toBe(true);
394
- expect(prop.resolveLanguage).toBe('literal');
487
+ expect(prop.readOnly).toBeFalsy();
488
+ expect(prop.resolveLanguage).toBe("literal");
395
489
  expect(prop.setter).toEqual(original.properties[0].setter);
396
490
  expect(prop.adder).toEqual(original.properties[0].adder);
397
491
  expect(prop.remover).toEqual(original.properties[0].remover);