@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.
- package/jest.config.js +4 -4
- package/lib/index.cjs +5999 -6044
- package/lib/index.js +5977 -6038
- package/lib/src/Ad4mClient.d.ts +16 -9
- package/lib/src/Ad4mClient.js +25 -46
- package/lib/src/Ad4mClient.test.d.ts +1 -0
- package/lib/src/Ad4mClient.test.js +1204 -0
- package/lib/src/Literal.d.ts +2 -1
- package/lib/src/Literal.js +35 -38
- package/lib/src/Literal.test.d.ts +1 -0
- package/lib/src/Literal.test.js +41 -0
- package/lib/src/SmartLiteral.d.ts +2 -1
- package/lib/src/SmartLiteral.js +15 -30
- package/lib/src/agent/AgentClient.d.ts +4 -1
- package/lib/src/agent/AgentClient.js +99 -79
- package/lib/src/ai/AIClient.d.ts +2 -1
- package/lib/src/ai/AIClient.js +220 -224
- package/lib/src/expression/ExpressionClient.d.ts +1 -1
- package/lib/src/expression/ExpressionClient.js +86 -73
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/language/LanguageClient.d.ts +1 -1
- package/lib/src/language/LanguageClient.js +52 -52
- package/lib/src/model/Ad4mModel.d.ts +157 -937
- package/lib/src/model/Ad4mModel.js +212 -2797
- package/lib/src/model/Ad4mModel.test.js +1002 -561
- package/lib/src/model/decorators.d.ts +94 -426
- package/lib/src/model/decorators.js +333 -741
- package/lib/src/model/mutation.d.ts +81 -0
- package/lib/src/model/mutation.js +317 -0
- package/lib/src/model/parentUtils.d.ts +32 -0
- package/lib/src/model/parentUtils.js +64 -0
- package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
- package/lib/src/model/prolog/generatePrologFacts.js +139 -0
- package/lib/src/model/prolog/index.d.ts +1 -0
- package/lib/src/model/prolog/index.js +1 -0
- package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
- package/lib/src/model/query/ModelQueryBuilder.js +115 -0
- package/lib/src/model/query/QueryBuilder.d.ts +101 -0
- package/lib/src/model/query/QueryBuilder.js +193 -0
- package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
- package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
- package/lib/src/model/query/fetchInstance.d.ts +24 -0
- package/lib/src/model/query/fetchInstance.js +144 -0
- package/lib/src/model/query/hydration.d.ts +54 -0
- package/lib/src/model/query/hydration.js +214 -0
- package/lib/src/model/query/operations.d.ts +59 -0
- package/lib/src/model/query/operations.js +384 -0
- package/lib/src/model/query/snapshot.d.ts +59 -0
- package/lib/src/model/query/snapshot.js +106 -0
- package/lib/src/model/query/surrealCompiler.d.ts +42 -0
- package/lib/src/model/query/surrealCompiler.js +304 -0
- package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
- package/lib/src/model/schema/fromJSONSchema.js +264 -0
- package/lib/src/model/schema/metadata.d.ts +15 -0
- package/lib/src/model/schema/metadata.js +112 -0
- package/lib/src/model/subscription.d.ts +47 -0
- package/lib/src/model/subscription.js +231 -0
- package/lib/src/model/transaction.d.ts +27 -0
- package/lib/src/model/transaction.js +32 -0
- package/lib/src/model/types.d.ts +195 -0
- package/lib/src/model/types.js +8 -0
- package/lib/src/model/util.js +7 -7
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +5 -1
- package/lib/src/neighbourhood/NeighbourhoodClient.js +263 -181
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -1
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +13 -28
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +1 -5
- package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveClient.js +316 -240
- package/lib/src/perspectives/PerspectiveProxy.d.ts +54 -92
- package/lib/src/perspectives/PerspectiveProxy.js +803 -444
- package/lib/src/runtime/RuntimeClient.d.ts +5 -1
- package/lib/src/runtime/RuntimeClient.js +412 -238
- package/lib/src/shacl/SHACLFlow.test.js +164 -105
- package/lib/src/shacl/SHACLShape.d.ts +17 -3
- package/lib/src/shacl/SHACLShape.js +127 -90
- package/lib/src/shacl/SHACLShape.test.js +244 -176
- package/lib/src/utils.d.ts +8 -0
- package/lib/src/utils.js +21 -7
- package/package.json +8 -13
- package/src/Ad4mClient.test.ts +1564 -1315
- package/src/Ad4mClient.ts +55 -54
- package/src/Literal.test.ts +45 -26
- package/src/Literal.ts +82 -66
- package/src/SmartLiteral.ts +74 -58
- package/src/agent/AgentClient.ts +144 -99
- package/src/ai/AIClient.ts +409 -359
- package/src/expression/ExpressionClient.ts +142 -96
- package/src/index.ts +1 -1
- package/src/language/LanguageClient.ts +137 -113
- package/src/model/Ad4mModel.test.ts +1128 -647
- package/src/model/Ad4mModel.ts +485 -3247
- package/src/model/IMPROVEMENTS.md +482 -0
- package/src/model/PREDICATE_COLLISION_FIX.md +651 -0
- package/src/model/README.md +317 -0
- package/src/model/SHACL_MUTATION_DECOUPLING.md +356 -0
- package/src/model/SUBSCRIPTION_STRATEGY.md +317 -0
- package/src/model/TC39_STAGE_3_DECORATORS.md +609 -0
- package/src/model/decorators.ts +689 -1046
- package/src/model/mutation.ts +461 -0
- package/src/model/parentUtils.ts +91 -0
- package/src/model/prolog/generatePrologFacts.ts +176 -0
- package/src/model/prolog/index.ts +1 -0
- package/src/model/query/ModelQueryBuilder.ts +173 -0
- package/src/model/query/fetchInstance.ts +181 -0
- package/src/model/query/hydration.ts +273 -0
- package/src/model/query/operations.ts +510 -0
- package/src/model/query/snapshot.ts +126 -0
- package/src/model/query/surrealCompiler.ts +376 -0
- package/src/model/schema/fromJSONSchema.ts +411 -0
- package/src/model/schema/metadata.ts +148 -0
- package/src/model/subscription.ts +307 -0
- package/src/model/transaction.ts +60 -0
- package/src/model/types.ts +207 -0
- package/src/model/util.ts +47 -48
- package/src/neighbourhood/NeighbourhoodClient.ts +393 -251
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +3 -7
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -40
- package/src/perspectives/PerspectiveClient.ts +779 -540
- package/src/perspectives/PerspectiveProxy.ts +2860 -2053
- package/src/runtime/RuntimeClient.ts +775 -476
- package/src/shacl/SHACLFlow.test.ts +196 -129
- package/src/shacl/SHACLShape.test.ts +284 -190
- package/src/shacl/SHACLShape.ts +225 -172
- package/src/utils.ts +31 -17
- package/tsconfig.json +9 -10
- package/src/model/Subject.ts +0 -159
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { SHACLShape, SHACLPropertyShape, AD4MAction } from
|
|
1
|
+
import { SHACLShape, SHACLPropertyShape, AD4MAction } from "./SHACLShape";
|
|
2
2
|
|
|
3
|
-
describe(
|
|
4
|
-
describe(
|
|
5
|
-
it(
|
|
6
|
-
const shape = new SHACLShape(
|
|
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(
|
|
10
|
+
const targetClassLink = links.find(
|
|
11
|
+
(l) => l.predicate === "sh://targetClass",
|
|
12
|
+
);
|
|
11
13
|
expect(targetClassLink).toBeDefined();
|
|
12
|
-
expect(targetClassLink!.source).toBe(
|
|
13
|
-
expect(targetClassLink!.target).toBe(
|
|
14
|
+
expect(targetClassLink!.source).toBe("recipe://RecipeShape");
|
|
15
|
+
expect(targetClassLink!.target).toBe("recipe://Recipe");
|
|
14
16
|
});
|
|
15
17
|
|
|
16
|
-
it(
|
|
17
|
-
const shape = new SHACLShape(
|
|
18
|
+
it("creates property shape links with named URIs", () => {
|
|
19
|
+
const shape = new SHACLShape("recipe://Recipe");
|
|
18
20
|
const prop: SHACLPropertyShape = {
|
|
19
|
-
name:
|
|
20
|
-
path:
|
|
21
|
-
datatype:
|
|
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 ===
|
|
31
|
+
const propLink = links.find((l) => l.predicate === "sh://property");
|
|
30
32
|
expect(propLink).toBeDefined();
|
|
31
|
-
expect(propLink!.target).toBe(
|
|
33
|
+
expect(propLink!.target).toBe("recipe://Recipe.name"); // Named URI, not blank node
|
|
32
34
|
|
|
33
35
|
// Path link
|
|
34
|
-
const pathLink = links.find(
|
|
35
|
-
l
|
|
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(
|
|
41
|
+
expect(pathLink!.target).toBe("recipe://name");
|
|
39
42
|
|
|
40
43
|
// Datatype link
|
|
41
|
-
const datatypeLink = links.find(
|
|
42
|
-
l
|
|
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(
|
|
50
|
+
expect(datatypeLink!.target).toBe("xsd:string");
|
|
46
51
|
|
|
47
52
|
// Cardinality links
|
|
48
|
-
const minCountLink = links.find(
|
|
49
|
-
l
|
|
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(
|
|
59
|
+
expect(minCountLink!.target).toContain("1");
|
|
53
60
|
|
|
54
|
-
const maxCountLink = links.find(
|
|
55
|
-
l
|
|
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(
|
|
67
|
+
expect(maxCountLink!.target).toContain("1");
|
|
59
68
|
});
|
|
60
69
|
|
|
61
|
-
it(
|
|
62
|
-
const shape = new SHACLShape(
|
|
70
|
+
it("creates action links", () => {
|
|
71
|
+
const shape = new SHACLShape("recipe://Recipe");
|
|
63
72
|
const setterAction: AD4MAction = {
|
|
64
|
-
action:
|
|
65
|
-
source:
|
|
66
|
-
predicate:
|
|
67
|
-
target:
|
|
73
|
+
action: "addLink",
|
|
74
|
+
source: "this",
|
|
75
|
+
predicate: "recipe://name",
|
|
76
|
+
target: "value",
|
|
68
77
|
};
|
|
69
78
|
const prop: SHACLPropertyShape = {
|
|
70
|
-
name:
|
|
71
|
-
path:
|
|
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(
|
|
79
|
-
l
|
|
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(
|
|
93
|
+
expect(setterLink!.target).toContain("addLink");
|
|
83
94
|
});
|
|
84
95
|
|
|
85
|
-
it(
|
|
86
|
-
const shape = new SHACLShape(
|
|
87
|
-
shape.constructor_actions = [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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(
|
|
116
|
+
const constructorLink = links.find(
|
|
117
|
+
(l) => l.predicate === "ad4m://constructor",
|
|
118
|
+
);
|
|
102
119
|
expect(constructorLink).toBeDefined();
|
|
103
|
-
expect(constructorLink!.target).toContain(
|
|
120
|
+
expect(constructorLink!.target).toContain("addLink");
|
|
104
121
|
|
|
105
|
-
const destructorLink = links.find(
|
|
122
|
+
const destructorLink = links.find(
|
|
123
|
+
(l) => l.predicate === "ad4m://destructor",
|
|
124
|
+
);
|
|
106
125
|
expect(destructorLink).toBeDefined();
|
|
107
|
-
expect(destructorLink!.target).toContain(
|
|
126
|
+
expect(destructorLink!.target).toContain("removeLink");
|
|
108
127
|
});
|
|
109
128
|
});
|
|
110
129
|
|
|
111
|
-
describe(
|
|
112
|
-
it(
|
|
113
|
-
const originalShape = new SHACLShape(
|
|
130
|
+
describe("fromLinks()", () => {
|
|
131
|
+
it("reconstructs shape from links", () => {
|
|
132
|
+
const originalShape = new SHACLShape("recipe://Recipe");
|
|
114
133
|
originalShape.addProperty({
|
|
115
|
-
name:
|
|
116
|
-
path:
|
|
117
|
-
datatype:
|
|
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,
|
|
141
|
+
const reconstructed = SHACLShape.fromLinks(links, "recipe://RecipeShape");
|
|
123
142
|
|
|
124
|
-
expect(reconstructed.targetClass).toBe(
|
|
143
|
+
expect(reconstructed.targetClass).toBe("recipe://Recipe");
|
|
125
144
|
expect(reconstructed.properties.length).toBe(1);
|
|
126
|
-
expect(reconstructed.properties[0].path).toBe(
|
|
127
|
-
expect(reconstructed.properties[0].datatype).toBe(
|
|
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(
|
|
132
|
-
const originalShape = new SHACLShape(
|
|
150
|
+
it("handles multiple properties", () => {
|
|
151
|
+
const originalShape = new SHACLShape("recipe://Recipe");
|
|
133
152
|
originalShape.addProperty({
|
|
134
|
-
name:
|
|
135
|
-
path:
|
|
136
|
-
datatype:
|
|
153
|
+
name: "name",
|
|
154
|
+
path: "recipe://name",
|
|
155
|
+
datatype: "xsd:string",
|
|
137
156
|
});
|
|
138
157
|
originalShape.addProperty({
|
|
139
|
-
name:
|
|
140
|
-
path:
|
|
141
|
-
datatype:
|
|
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,
|
|
164
|
+
const reconstructed = SHACLShape.fromLinks(links, "recipe://RecipeShape");
|
|
146
165
|
|
|
147
166
|
expect(reconstructed.properties.length).toBe(2);
|
|
148
|
-
const nameProp = reconstructed.properties.find(
|
|
149
|
-
|
|
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(
|
|
153
|
-
expect(servingsProp!.datatype).toBe(
|
|
175
|
+
expect(nameProp!.datatype).toBe("xsd:string");
|
|
176
|
+
expect(servingsProp!.datatype).toBe("xsd:integer");
|
|
154
177
|
});
|
|
155
178
|
|
|
156
|
-
it(
|
|
157
|
-
const originalShape = new SHACLShape(
|
|
179
|
+
it("reconstructs action arrays", () => {
|
|
180
|
+
const originalShape = new SHACLShape("recipe://Recipe");
|
|
158
181
|
const setterAction: AD4MAction = {
|
|
159
|
-
action:
|
|
160
|
-
source:
|
|
161
|
-
predicate:
|
|
162
|
-
target:
|
|
182
|
+
action: "addLink",
|
|
183
|
+
source: "this",
|
|
184
|
+
predicate: "recipe://name",
|
|
185
|
+
target: "value",
|
|
163
186
|
};
|
|
164
187
|
originalShape.addProperty({
|
|
165
|
-
name:
|
|
166
|
-
path:
|
|
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,
|
|
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(
|
|
198
|
+
expect(reconstructed.properties[0].setter![0].action).toBe("addLink");
|
|
176
199
|
});
|
|
177
200
|
});
|
|
178
201
|
|
|
179
|
-
describe(
|
|
180
|
-
it(
|
|
181
|
-
const original = new SHACLShape(
|
|
202
|
+
describe("round-trip serialization", () => {
|
|
203
|
+
it("preserves all property attributes", () => {
|
|
204
|
+
const original = new SHACLShape("test://Model");
|
|
182
205
|
original.addProperty({
|
|
183
|
-
name:
|
|
184
|
-
path:
|
|
185
|
-
datatype:
|
|
186
|
-
nodeKind:
|
|
206
|
+
name: "field",
|
|
207
|
+
path: "test://field",
|
|
208
|
+
datatype: "xsd:string",
|
|
209
|
+
nodeKind: "Literal",
|
|
187
210
|
minCount: 0,
|
|
188
211
|
maxCount: 5,
|
|
189
|
-
pattern:
|
|
212
|
+
pattern: "^[a-z]+$",
|
|
190
213
|
minInclusive: 10,
|
|
191
214
|
maxInclusive: 100,
|
|
192
|
-
hasValue:
|
|
193
|
-
resolveLanguage:
|
|
215
|
+
hasValue: "expectedValue",
|
|
216
|
+
resolveLanguage: "test://language",
|
|
194
217
|
local: true,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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,
|
|
245
|
+
const reconstructed = SHACLShape.fromLinks(links, "test://ModelShape");
|
|
203
246
|
|
|
204
247
|
const prop = reconstructed.properties[0];
|
|
205
|
-
expect(prop.path).toBe(
|
|
206
|
-
expect(prop.datatype).toBe(
|
|
207
|
-
expect(prop.nodeKind).toBe(
|
|
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(
|
|
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(
|
|
214
|
-
expect(prop.resolveLanguage).toBe(
|
|
256
|
+
expect(prop.hasValue).toBe("expectedValue");
|
|
257
|
+
expect(prop.resolveLanguage).toBe("test://language");
|
|
215
258
|
expect(prop.local).toBe(true);
|
|
216
|
-
expect(prop.
|
|
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(
|
|
223
|
-
const original = new SHACLShape(
|
|
265
|
+
it("preserves constructor and destructor actions", () => {
|
|
266
|
+
const original = new SHACLShape("test://Model");
|
|
224
267
|
original.constructor_actions = [
|
|
225
|
-
{
|
|
268
|
+
{
|
|
269
|
+
action: "addLink",
|
|
270
|
+
source: "this",
|
|
271
|
+
predicate: "rdf://type",
|
|
272
|
+
target: "test://Model",
|
|
273
|
+
},
|
|
226
274
|
];
|
|
227
275
|
original.destructor_actions = [
|
|
228
|
-
{
|
|
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,
|
|
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(
|
|
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(
|
|
293
|
+
expect(reconstructed.destructor_actions![0].action).toBe("removeLink");
|
|
241
294
|
});
|
|
242
295
|
});
|
|
243
296
|
|
|
244
|
-
describe(
|
|
245
|
-
it(
|
|
246
|
-
const shape = new SHACLShape(
|
|
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,
|
|
252
|
-
expect(reconstructed.targetClass).toBe(
|
|
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(
|
|
257
|
-
const shape = new SHACLShape(
|
|
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(
|
|
261
|
-
|
|
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(
|
|
265
|
-
const shape = new SHACLShape(
|
|
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:
|
|
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 ===
|
|
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(
|
|
280
|
-
it(
|
|
281
|
-
const original = new SHACLShape(
|
|
336
|
+
describe("toJSON/fromJSON", () => {
|
|
337
|
+
it("serializes and deserializes basic shape", () => {
|
|
338
|
+
const original = new SHACLShape("recipe://Recipe");
|
|
282
339
|
original.addProperty({
|
|
283
|
-
name:
|
|
284
|
-
path:
|
|
285
|
-
datatype:
|
|
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(
|
|
349
|
+
expect(reconstructed.targetClass).toBe("recipe://Recipe");
|
|
293
350
|
expect(reconstructed.properties.length).toBe(1);
|
|
294
|
-
expect(reconstructed.properties[0].name).toBe(
|
|
295
|
-
expect(reconstructed.properties[0].path).toBe(
|
|
296
|
-
expect(reconstructed.properties[0].datatype).toBe(
|
|
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(
|
|
301
|
-
const original = new SHACLShape(
|
|
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(
|
|
307
|
-
expect(reconstructed.targetClass).toBe(
|
|
366
|
+
expect(reconstructed.nodeShapeUri).toBe("custom://CustomShape");
|
|
367
|
+
expect(reconstructed.targetClass).toBe("recipe://Recipe");
|
|
308
368
|
});
|
|
309
369
|
|
|
310
|
-
it(
|
|
311
|
-
const original = new SHACLShape(
|
|
370
|
+
it("preserves minInclusive and maxInclusive", () => {
|
|
371
|
+
const original = new SHACLShape("test://Model");
|
|
312
372
|
original.addProperty({
|
|
313
|
-
name:
|
|
314
|
-
path:
|
|
315
|
-
datatype:
|
|
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(
|
|
328
|
-
const original = new SHACLShape(
|
|
387
|
+
it("preserves resolveLanguage", () => {
|
|
388
|
+
const original = new SHACLShape("test://Model");
|
|
329
389
|
original.addProperty({
|
|
330
|
-
name:
|
|
331
|
-
path:
|
|
332
|
-
resolveLanguage:
|
|
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(
|
|
398
|
+
expect(reconstructed.properties[0].resolveLanguage).toBe("literal");
|
|
339
399
|
});
|
|
340
400
|
|
|
341
|
-
it(
|
|
342
|
-
const original = new SHACLShape(
|
|
401
|
+
it("preserves constructor and destructor actions", () => {
|
|
402
|
+
const original = new SHACLShape("test://Model");
|
|
343
403
|
original.constructor_actions = [
|
|
344
|
-
{
|
|
404
|
+
{
|
|
405
|
+
action: "addLink",
|
|
406
|
+
source: "this",
|
|
407
|
+
predicate: "rdf://type",
|
|
408
|
+
target: "test://Model",
|
|
409
|
+
},
|
|
345
410
|
];
|
|
346
411
|
original.destructor_actions = [
|
|
347
|
-
{
|
|
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(
|
|
354
|
-
|
|
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(
|
|
358
|
-
const original = new SHACLShape(
|
|
431
|
+
it("preserves all property attributes", () => {
|
|
432
|
+
const original = new SHACLShape("test://Model");
|
|
359
433
|
original.addProperty({
|
|
360
|
-
name:
|
|
361
|
-
path:
|
|
362
|
-
datatype:
|
|
363
|
-
nodeKind:
|
|
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:
|
|
369
|
-
hasValue:
|
|
442
|
+
pattern: "^[a-z]+$",
|
|
443
|
+
hasValue: "default",
|
|
370
444
|
local: true,
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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(
|
|
383
|
-
expect(prop.path).toBe(
|
|
384
|
-
expect(prop.datatype).toBe(
|
|
385
|
-
expect(prop.nodeKind).toBe(
|
|
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(
|
|
391
|
-
expect(prop.hasValue).toBe(
|
|
484
|
+
expect(prop.pattern).toBe("^[a-z]+$");
|
|
485
|
+
expect(prop.hasValue).toBe("default");
|
|
392
486
|
expect(prop.local).toBe(true);
|
|
393
|
-
expect(prop.
|
|
394
|
-
expect(prop.resolveLanguage).toBe(
|
|
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);
|