@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,265 +1,303 @@
|
|
|
1
|
-
import { SHACLShape } from
|
|
2
|
-
describe(
|
|
3
|
-
describe(
|
|
4
|
-
it(
|
|
5
|
-
const shape = new SHACLShape(
|
|
1
|
+
import { SHACLShape } from "./SHACLShape";
|
|
2
|
+
describe("SHACLShape", () => {
|
|
3
|
+
describe("toLinks()", () => {
|
|
4
|
+
it("creates basic shape links", () => {
|
|
5
|
+
const shape = new SHACLShape("recipe://Recipe");
|
|
6
6
|
const links = shape.toLinks();
|
|
7
7
|
// Should have targetClass link
|
|
8
|
-
const targetClassLink = links.find(l => l.predicate ===
|
|
8
|
+
const targetClassLink = links.find((l) => l.predicate === "sh://targetClass");
|
|
9
9
|
expect(targetClassLink).toBeDefined();
|
|
10
|
-
expect(targetClassLink.source).toBe(
|
|
11
|
-
expect(targetClassLink.target).toBe(
|
|
10
|
+
expect(targetClassLink.source).toBe("recipe://RecipeShape");
|
|
11
|
+
expect(targetClassLink.target).toBe("recipe://Recipe");
|
|
12
12
|
});
|
|
13
|
-
it(
|
|
14
|
-
const shape = new SHACLShape(
|
|
13
|
+
it("creates property shape links with named URIs", () => {
|
|
14
|
+
const shape = new SHACLShape("recipe://Recipe");
|
|
15
15
|
const prop = {
|
|
16
|
-
name:
|
|
17
|
-
path:
|
|
18
|
-
datatype:
|
|
16
|
+
name: "name",
|
|
17
|
+
path: "recipe://name",
|
|
18
|
+
datatype: "xsd:string",
|
|
19
19
|
minCount: 1,
|
|
20
20
|
maxCount: 1,
|
|
21
21
|
};
|
|
22
22
|
shape.addProperty(prop);
|
|
23
23
|
const links = shape.toLinks();
|
|
24
24
|
// Property shape should use named URI
|
|
25
|
-
const propLink = links.find(l => l.predicate ===
|
|
25
|
+
const propLink = links.find((l) => l.predicate === "sh://property");
|
|
26
26
|
expect(propLink).toBeDefined();
|
|
27
|
-
expect(propLink.target).toBe(
|
|
27
|
+
expect(propLink.target).toBe("recipe://Recipe.name"); // Named URI, not blank node
|
|
28
28
|
// Path link
|
|
29
|
-
const pathLink = links.find(l => l.source ===
|
|
29
|
+
const pathLink = links.find((l) => l.source === "recipe://Recipe.name" && l.predicate === "sh://path");
|
|
30
30
|
expect(pathLink).toBeDefined();
|
|
31
|
-
expect(pathLink.target).toBe(
|
|
31
|
+
expect(pathLink.target).toBe("recipe://name");
|
|
32
32
|
// Datatype link
|
|
33
|
-
const datatypeLink = links.find(l => l.source ===
|
|
33
|
+
const datatypeLink = links.find((l) => l.source === "recipe://Recipe.name" &&
|
|
34
|
+
l.predicate === "sh://datatype");
|
|
34
35
|
expect(datatypeLink).toBeDefined();
|
|
35
|
-
expect(datatypeLink.target).toBe(
|
|
36
|
+
expect(datatypeLink.target).toBe("xsd:string");
|
|
36
37
|
// Cardinality links
|
|
37
|
-
const minCountLink = links.find(l => l.source ===
|
|
38
|
+
const minCountLink = links.find((l) => l.source === "recipe://Recipe.name" &&
|
|
39
|
+
l.predicate === "sh://minCount");
|
|
38
40
|
expect(minCountLink).toBeDefined();
|
|
39
|
-
expect(minCountLink.target).toContain(
|
|
40
|
-
const maxCountLink = links.find(l => l.source ===
|
|
41
|
+
expect(minCountLink.target).toContain("1");
|
|
42
|
+
const maxCountLink = links.find((l) => l.source === "recipe://Recipe.name" &&
|
|
43
|
+
l.predicate === "sh://maxCount");
|
|
41
44
|
expect(maxCountLink).toBeDefined();
|
|
42
|
-
expect(maxCountLink.target).toContain(
|
|
45
|
+
expect(maxCountLink.target).toContain("1");
|
|
43
46
|
});
|
|
44
|
-
it(
|
|
45
|
-
const shape = new SHACLShape(
|
|
47
|
+
it("creates action links", () => {
|
|
48
|
+
const shape = new SHACLShape("recipe://Recipe");
|
|
46
49
|
const setterAction = {
|
|
47
|
-
action:
|
|
48
|
-
source:
|
|
49
|
-
predicate:
|
|
50
|
-
target:
|
|
50
|
+
action: "addLink",
|
|
51
|
+
source: "this",
|
|
52
|
+
predicate: "recipe://name",
|
|
53
|
+
target: "value",
|
|
51
54
|
};
|
|
52
55
|
const prop = {
|
|
53
|
-
name:
|
|
54
|
-
path:
|
|
56
|
+
name: "title",
|
|
57
|
+
path: "recipe://title",
|
|
55
58
|
setter: [setterAction],
|
|
56
59
|
};
|
|
57
60
|
shape.addProperty(prop);
|
|
58
61
|
const links = shape.toLinks();
|
|
59
62
|
// Setter action link
|
|
60
|
-
const setterLink = links.find(l => l.source ===
|
|
63
|
+
const setterLink = links.find((l) => l.source === "recipe://Recipe.title" &&
|
|
64
|
+
l.predicate === "ad4m://setter");
|
|
61
65
|
expect(setterLink).toBeDefined();
|
|
62
|
-
expect(setterLink.target).toContain(
|
|
66
|
+
expect(setterLink.target).toContain("addLink");
|
|
63
67
|
});
|
|
64
|
-
it(
|
|
65
|
-
const shape = new SHACLShape(
|
|
66
|
-
shape.constructor_actions = [
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
it("includes constructor and destructor actions", () => {
|
|
69
|
+
const shape = new SHACLShape("recipe://Recipe");
|
|
70
|
+
shape.constructor_actions = [
|
|
71
|
+
{
|
|
72
|
+
action: "addLink",
|
|
73
|
+
source: "this",
|
|
74
|
+
predicate: "ad4m://type",
|
|
75
|
+
target: "recipe://Recipe",
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
shape.destructor_actions = [
|
|
79
|
+
{
|
|
80
|
+
action: "removeLink",
|
|
81
|
+
source: "this",
|
|
82
|
+
predicate: "ad4m://type",
|
|
83
|
+
target: "recipe://Recipe",
|
|
84
|
+
},
|
|
85
|
+
];
|
|
78
86
|
const links = shape.toLinks();
|
|
79
|
-
const constructorLink = links.find(l => l.predicate ===
|
|
87
|
+
const constructorLink = links.find((l) => l.predicate === "ad4m://constructor");
|
|
80
88
|
expect(constructorLink).toBeDefined();
|
|
81
|
-
expect(constructorLink.target).toContain(
|
|
82
|
-
const destructorLink = links.find(l => l.predicate ===
|
|
89
|
+
expect(constructorLink.target).toContain("addLink");
|
|
90
|
+
const destructorLink = links.find((l) => l.predicate === "ad4m://destructor");
|
|
83
91
|
expect(destructorLink).toBeDefined();
|
|
84
|
-
expect(destructorLink.target).toContain(
|
|
92
|
+
expect(destructorLink.target).toContain("removeLink");
|
|
85
93
|
});
|
|
86
94
|
});
|
|
87
|
-
describe(
|
|
88
|
-
it(
|
|
89
|
-
const originalShape = new SHACLShape(
|
|
95
|
+
describe("fromLinks()", () => {
|
|
96
|
+
it("reconstructs shape from links", () => {
|
|
97
|
+
const originalShape = new SHACLShape("recipe://Recipe");
|
|
90
98
|
originalShape.addProperty({
|
|
91
|
-
name:
|
|
92
|
-
path:
|
|
93
|
-
datatype:
|
|
99
|
+
name: "name",
|
|
100
|
+
path: "recipe://name",
|
|
101
|
+
datatype: "xsd:string",
|
|
94
102
|
minCount: 1,
|
|
95
103
|
});
|
|
96
104
|
const links = originalShape.toLinks();
|
|
97
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
98
|
-
expect(reconstructed.targetClass).toBe(
|
|
105
|
+
const reconstructed = SHACLShape.fromLinks(links, "recipe://RecipeShape");
|
|
106
|
+
expect(reconstructed.targetClass).toBe("recipe://Recipe");
|
|
99
107
|
expect(reconstructed.properties.length).toBe(1);
|
|
100
|
-
expect(reconstructed.properties[0].path).toBe(
|
|
101
|
-
expect(reconstructed.properties[0].datatype).toBe(
|
|
108
|
+
expect(reconstructed.properties[0].path).toBe("recipe://name");
|
|
109
|
+
expect(reconstructed.properties[0].datatype).toBe("xsd:string");
|
|
102
110
|
expect(reconstructed.properties[0].minCount).toBe(1);
|
|
103
111
|
});
|
|
104
|
-
it(
|
|
105
|
-
const originalShape = new SHACLShape(
|
|
112
|
+
it("handles multiple properties", () => {
|
|
113
|
+
const originalShape = new SHACLShape("recipe://Recipe");
|
|
106
114
|
originalShape.addProperty({
|
|
107
|
-
name:
|
|
108
|
-
path:
|
|
109
|
-
datatype:
|
|
115
|
+
name: "name",
|
|
116
|
+
path: "recipe://name",
|
|
117
|
+
datatype: "xsd:string",
|
|
110
118
|
});
|
|
111
119
|
originalShape.addProperty({
|
|
112
|
-
name:
|
|
113
|
-
path:
|
|
114
|
-
datatype:
|
|
120
|
+
name: "servings",
|
|
121
|
+
path: "recipe://servings",
|
|
122
|
+
datatype: "xsd:integer",
|
|
115
123
|
});
|
|
116
124
|
const links = originalShape.toLinks();
|
|
117
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
125
|
+
const reconstructed = SHACLShape.fromLinks(links, "recipe://RecipeShape");
|
|
118
126
|
expect(reconstructed.properties.length).toBe(2);
|
|
119
|
-
const nameProp = reconstructed.properties.find(p => p.path ===
|
|
120
|
-
const servingsProp = reconstructed.properties.find(p => p.path ===
|
|
127
|
+
const nameProp = reconstructed.properties.find((p) => p.path === "recipe://name");
|
|
128
|
+
const servingsProp = reconstructed.properties.find((p) => p.path === "recipe://servings");
|
|
121
129
|
expect(nameProp).toBeDefined();
|
|
122
130
|
expect(servingsProp).toBeDefined();
|
|
123
|
-
expect(nameProp.datatype).toBe(
|
|
124
|
-
expect(servingsProp.datatype).toBe(
|
|
131
|
+
expect(nameProp.datatype).toBe("xsd:string");
|
|
132
|
+
expect(servingsProp.datatype).toBe("xsd:integer");
|
|
125
133
|
});
|
|
126
|
-
it(
|
|
127
|
-
const originalShape = new SHACLShape(
|
|
134
|
+
it("reconstructs action arrays", () => {
|
|
135
|
+
const originalShape = new SHACLShape("recipe://Recipe");
|
|
128
136
|
const setterAction = {
|
|
129
|
-
action:
|
|
130
|
-
source:
|
|
131
|
-
predicate:
|
|
132
|
-
target:
|
|
137
|
+
action: "addLink",
|
|
138
|
+
source: "this",
|
|
139
|
+
predicate: "recipe://name",
|
|
140
|
+
target: "value",
|
|
133
141
|
};
|
|
134
142
|
originalShape.addProperty({
|
|
135
|
-
name:
|
|
136
|
-
path:
|
|
143
|
+
name: "name",
|
|
144
|
+
path: "recipe://name",
|
|
137
145
|
setter: [setterAction],
|
|
138
146
|
});
|
|
139
147
|
const links = originalShape.toLinks();
|
|
140
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
148
|
+
const reconstructed = SHACLShape.fromLinks(links, "recipe://RecipeShape");
|
|
141
149
|
expect(reconstructed.properties[0].setter).toBeDefined();
|
|
142
150
|
expect(reconstructed.properties[0].setter.length).toBe(1);
|
|
143
|
-
expect(reconstructed.properties[0].setter[0].action).toBe(
|
|
151
|
+
expect(reconstructed.properties[0].setter[0].action).toBe("addLink");
|
|
144
152
|
});
|
|
145
153
|
});
|
|
146
|
-
describe(
|
|
147
|
-
it(
|
|
148
|
-
const original = new SHACLShape(
|
|
154
|
+
describe("round-trip serialization", () => {
|
|
155
|
+
it("preserves all property attributes", () => {
|
|
156
|
+
const original = new SHACLShape("test://Model");
|
|
149
157
|
original.addProperty({
|
|
150
|
-
name:
|
|
151
|
-
path:
|
|
152
|
-
datatype:
|
|
153
|
-
nodeKind:
|
|
158
|
+
name: "field",
|
|
159
|
+
path: "test://field",
|
|
160
|
+
datatype: "xsd:string",
|
|
161
|
+
nodeKind: "Literal",
|
|
154
162
|
minCount: 0,
|
|
155
163
|
maxCount: 5,
|
|
156
|
-
pattern:
|
|
164
|
+
pattern: "^[a-z]+$",
|
|
157
165
|
minInclusive: 10,
|
|
158
166
|
maxInclusive: 100,
|
|
159
|
-
hasValue:
|
|
160
|
-
resolveLanguage:
|
|
167
|
+
hasValue: "expectedValue",
|
|
168
|
+
resolveLanguage: "test://language",
|
|
161
169
|
local: true,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
170
|
+
setter: [
|
|
171
|
+
{
|
|
172
|
+
action: "addLink",
|
|
173
|
+
source: "this",
|
|
174
|
+
predicate: "test://field",
|
|
175
|
+
target: "value",
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
adder: [
|
|
179
|
+
{
|
|
180
|
+
action: "addLink",
|
|
181
|
+
source: "this",
|
|
182
|
+
predicate: "test://items",
|
|
183
|
+
target: "value",
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
remover: [
|
|
187
|
+
{
|
|
188
|
+
action: "removeLink",
|
|
189
|
+
source: "this",
|
|
190
|
+
predicate: "test://items",
|
|
191
|
+
target: "value",
|
|
192
|
+
},
|
|
193
|
+
],
|
|
166
194
|
});
|
|
167
195
|
const links = original.toLinks();
|
|
168
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
196
|
+
const reconstructed = SHACLShape.fromLinks(links, "test://ModelShape");
|
|
169
197
|
const prop = reconstructed.properties[0];
|
|
170
|
-
expect(prop.path).toBe(
|
|
171
|
-
expect(prop.datatype).toBe(
|
|
172
|
-
expect(prop.nodeKind).toBe(
|
|
198
|
+
expect(prop.path).toBe("test://field");
|
|
199
|
+
expect(prop.datatype).toBe("xsd:string");
|
|
200
|
+
expect(prop.nodeKind).toBe("Literal");
|
|
173
201
|
expect(prop.minCount).toBe(0);
|
|
174
202
|
expect(prop.maxCount).toBe(5);
|
|
175
|
-
expect(prop.pattern).toBe(
|
|
203
|
+
expect(prop.pattern).toBe("^[a-z]+$");
|
|
176
204
|
expect(prop.minInclusive).toBe(10);
|
|
177
205
|
expect(prop.maxInclusive).toBe(100);
|
|
178
|
-
expect(prop.hasValue).toBe(
|
|
179
|
-
expect(prop.resolveLanguage).toBe(
|
|
206
|
+
expect(prop.hasValue).toBe("expectedValue");
|
|
207
|
+
expect(prop.resolveLanguage).toBe("test://language");
|
|
180
208
|
expect(prop.local).toBe(true);
|
|
181
|
-
expect(prop.
|
|
209
|
+
expect(prop.readOnly).toBeFalsy();
|
|
182
210
|
expect(prop.setter).toBeDefined();
|
|
183
211
|
expect(prop.adder).toBeDefined();
|
|
184
212
|
expect(prop.remover).toBeDefined();
|
|
185
213
|
});
|
|
186
|
-
it(
|
|
187
|
-
const original = new SHACLShape(
|
|
214
|
+
it("preserves constructor and destructor actions", () => {
|
|
215
|
+
const original = new SHACLShape("test://Model");
|
|
188
216
|
original.constructor_actions = [
|
|
189
|
-
{
|
|
217
|
+
{
|
|
218
|
+
action: "addLink",
|
|
219
|
+
source: "this",
|
|
220
|
+
predicate: "rdf://type",
|
|
221
|
+
target: "test://Model",
|
|
222
|
+
},
|
|
190
223
|
];
|
|
191
224
|
original.destructor_actions = [
|
|
192
|
-
{
|
|
225
|
+
{
|
|
226
|
+
action: "removeLink",
|
|
227
|
+
source: "this",
|
|
228
|
+
predicate: "rdf://type",
|
|
229
|
+
target: "test://Model",
|
|
230
|
+
},
|
|
193
231
|
];
|
|
194
232
|
const links = original.toLinks();
|
|
195
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
233
|
+
const reconstructed = SHACLShape.fromLinks(links, "test://ModelShape");
|
|
196
234
|
expect(reconstructed.constructor_actions).toBeDefined();
|
|
197
235
|
expect(reconstructed.constructor_actions.length).toBe(1);
|
|
198
|
-
expect(reconstructed.constructor_actions[0].action).toBe(
|
|
236
|
+
expect(reconstructed.constructor_actions[0].action).toBe("addLink");
|
|
199
237
|
expect(reconstructed.destructor_actions).toBeDefined();
|
|
200
238
|
expect(reconstructed.destructor_actions.length).toBe(1);
|
|
201
|
-
expect(reconstructed.destructor_actions[0].action).toBe(
|
|
239
|
+
expect(reconstructed.destructor_actions[0].action).toBe("removeLink");
|
|
202
240
|
});
|
|
203
241
|
});
|
|
204
|
-
describe(
|
|
205
|
-
it(
|
|
206
|
-
const shape = new SHACLShape(
|
|
242
|
+
describe("edge cases", () => {
|
|
243
|
+
it("handles empty shape", () => {
|
|
244
|
+
const shape = new SHACLShape("test://Empty");
|
|
207
245
|
const links = shape.toLinks();
|
|
208
246
|
expect(links.length).toBeGreaterThanOrEqual(1); // At least targetClass link
|
|
209
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
210
|
-
expect(reconstructed.targetClass).toBe(
|
|
247
|
+
const reconstructed = SHACLShape.fromLinks(links, "test://EmptyShape");
|
|
248
|
+
expect(reconstructed.targetClass).toBe("test://Empty");
|
|
211
249
|
expect(reconstructed.properties.length).toBe(0);
|
|
212
250
|
});
|
|
213
|
-
it(
|
|
214
|
-
const shape = new SHACLShape(
|
|
251
|
+
it("handles URI with hash fragment", () => {
|
|
252
|
+
const shape = new SHACLShape("https://example.com/vocab#Recipe");
|
|
215
253
|
const links = shape.toLinks();
|
|
216
|
-
const targetClassLink = links.find(l => l.predicate ===
|
|
217
|
-
expect(targetClassLink.source).toBe(
|
|
254
|
+
const targetClassLink = links.find((l) => l.predicate === "sh://targetClass");
|
|
255
|
+
expect(targetClassLink.source).toBe("https://example.com/vocab#RecipeShape");
|
|
218
256
|
});
|
|
219
|
-
it(
|
|
220
|
-
const shape = new SHACLShape(
|
|
257
|
+
it("falls back to blank nodes when property has no name", () => {
|
|
258
|
+
const shape = new SHACLShape("test://Model");
|
|
221
259
|
shape.addProperty({
|
|
222
|
-
path:
|
|
260
|
+
path: "test://unnamed",
|
|
223
261
|
// No name property
|
|
224
262
|
});
|
|
225
263
|
const links = shape.toLinks();
|
|
226
|
-
const propLink = links.find(l => l.predicate ===
|
|
264
|
+
const propLink = links.find((l) => l.predicate === "sh://property");
|
|
227
265
|
expect(propLink).toBeDefined();
|
|
228
266
|
// Should use blank node format when no name provided
|
|
229
267
|
expect(propLink.target).toMatch(/_:propShape\d+|test:\/\/Model\./);
|
|
230
268
|
});
|
|
231
269
|
});
|
|
232
|
-
describe(
|
|
233
|
-
it(
|
|
234
|
-
const original = new SHACLShape(
|
|
270
|
+
describe("toJSON/fromJSON", () => {
|
|
271
|
+
it("serializes and deserializes basic shape", () => {
|
|
272
|
+
const original = new SHACLShape("recipe://Recipe");
|
|
235
273
|
original.addProperty({
|
|
236
|
-
name:
|
|
237
|
-
path:
|
|
238
|
-
datatype:
|
|
274
|
+
name: "name",
|
|
275
|
+
path: "recipe://name",
|
|
276
|
+
datatype: "xsd:string",
|
|
239
277
|
minCount: 1,
|
|
240
278
|
});
|
|
241
279
|
const json = original.toJSON();
|
|
242
280
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
243
|
-
expect(reconstructed.targetClass).toBe(
|
|
281
|
+
expect(reconstructed.targetClass).toBe("recipe://Recipe");
|
|
244
282
|
expect(reconstructed.properties.length).toBe(1);
|
|
245
|
-
expect(reconstructed.properties[0].name).toBe(
|
|
246
|
-
expect(reconstructed.properties[0].path).toBe(
|
|
247
|
-
expect(reconstructed.properties[0].datatype).toBe(
|
|
283
|
+
expect(reconstructed.properties[0].name).toBe("name");
|
|
284
|
+
expect(reconstructed.properties[0].path).toBe("recipe://name");
|
|
285
|
+
expect(reconstructed.properties[0].datatype).toBe("xsd:string");
|
|
248
286
|
expect(reconstructed.properties[0].minCount).toBe(1);
|
|
249
287
|
});
|
|
250
|
-
it(
|
|
251
|
-
const original = new SHACLShape(
|
|
288
|
+
it("preserves nodeShapeUri in round-trip", () => {
|
|
289
|
+
const original = new SHACLShape("custom://CustomShape", "recipe://Recipe");
|
|
252
290
|
const json = original.toJSON();
|
|
253
291
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
254
|
-
expect(reconstructed.nodeShapeUri).toBe(
|
|
255
|
-
expect(reconstructed.targetClass).toBe(
|
|
292
|
+
expect(reconstructed.nodeShapeUri).toBe("custom://CustomShape");
|
|
293
|
+
expect(reconstructed.targetClass).toBe("recipe://Recipe");
|
|
256
294
|
});
|
|
257
|
-
it(
|
|
258
|
-
const original = new SHACLShape(
|
|
295
|
+
it("preserves minInclusive and maxInclusive", () => {
|
|
296
|
+
const original = new SHACLShape("test://Model");
|
|
259
297
|
original.addProperty({
|
|
260
|
-
name:
|
|
261
|
-
path:
|
|
262
|
-
datatype:
|
|
298
|
+
name: "rating",
|
|
299
|
+
path: "test://rating",
|
|
300
|
+
datatype: "xsd:integer",
|
|
263
301
|
minInclusive: 1,
|
|
264
302
|
maxInclusive: 5,
|
|
265
303
|
});
|
|
@@ -268,66 +306,96 @@ describe('SHACLShape', () => {
|
|
|
268
306
|
expect(reconstructed.properties[0].minInclusive).toBe(1);
|
|
269
307
|
expect(reconstructed.properties[0].maxInclusive).toBe(5);
|
|
270
308
|
});
|
|
271
|
-
it(
|
|
272
|
-
const original = new SHACLShape(
|
|
309
|
+
it("preserves resolveLanguage", () => {
|
|
310
|
+
const original = new SHACLShape("test://Model");
|
|
273
311
|
original.addProperty({
|
|
274
|
-
name:
|
|
275
|
-
path:
|
|
276
|
-
resolveLanguage:
|
|
312
|
+
name: "content",
|
|
313
|
+
path: "test://content",
|
|
314
|
+
resolveLanguage: "literal",
|
|
277
315
|
});
|
|
278
316
|
const json = original.toJSON();
|
|
279
317
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
280
|
-
expect(reconstructed.properties[0].resolveLanguage).toBe(
|
|
318
|
+
expect(reconstructed.properties[0].resolveLanguage).toBe("literal");
|
|
281
319
|
});
|
|
282
|
-
it(
|
|
283
|
-
const original = new SHACLShape(
|
|
320
|
+
it("preserves constructor and destructor actions", () => {
|
|
321
|
+
const original = new SHACLShape("test://Model");
|
|
284
322
|
original.constructor_actions = [
|
|
285
|
-
{
|
|
323
|
+
{
|
|
324
|
+
action: "addLink",
|
|
325
|
+
source: "this",
|
|
326
|
+
predicate: "rdf://type",
|
|
327
|
+
target: "test://Model",
|
|
328
|
+
},
|
|
286
329
|
];
|
|
287
330
|
original.destructor_actions = [
|
|
288
|
-
{
|
|
331
|
+
{
|
|
332
|
+
action: "removeLink",
|
|
333
|
+
source: "this",
|
|
334
|
+
predicate: "rdf://type",
|
|
335
|
+
target: "test://Model",
|
|
336
|
+
},
|
|
289
337
|
];
|
|
290
338
|
const json = original.toJSON();
|
|
291
339
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
292
340
|
expect(reconstructed.constructor_actions).toEqual(original.constructor_actions);
|
|
293
341
|
expect(reconstructed.destructor_actions).toEqual(original.destructor_actions);
|
|
294
342
|
});
|
|
295
|
-
it(
|
|
296
|
-
const original = new SHACLShape(
|
|
343
|
+
it("preserves all property attributes", () => {
|
|
344
|
+
const original = new SHACLShape("test://Model");
|
|
297
345
|
original.addProperty({
|
|
298
|
-
name:
|
|
299
|
-
path:
|
|
300
|
-
datatype:
|
|
301
|
-
nodeKind:
|
|
346
|
+
name: "field",
|
|
347
|
+
path: "test://field",
|
|
348
|
+
datatype: "xsd:string",
|
|
349
|
+
nodeKind: "Literal",
|
|
302
350
|
minCount: 0,
|
|
303
351
|
maxCount: 5,
|
|
304
352
|
minInclusive: 0,
|
|
305
353
|
maxInclusive: 100,
|
|
306
|
-
pattern:
|
|
307
|
-
hasValue:
|
|
354
|
+
pattern: "^[a-z]+$",
|
|
355
|
+
hasValue: "default",
|
|
308
356
|
local: true,
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
357
|
+
resolveLanguage: "literal",
|
|
358
|
+
setter: [
|
|
359
|
+
{
|
|
360
|
+
action: "addLink",
|
|
361
|
+
source: "this",
|
|
362
|
+
predicate: "test://field",
|
|
363
|
+
target: "value",
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
adder: [
|
|
367
|
+
{
|
|
368
|
+
action: "addLink",
|
|
369
|
+
source: "this",
|
|
370
|
+
predicate: "test://items",
|
|
371
|
+
target: "value",
|
|
372
|
+
},
|
|
373
|
+
],
|
|
374
|
+
remover: [
|
|
375
|
+
{
|
|
376
|
+
action: "removeLink",
|
|
377
|
+
source: "this",
|
|
378
|
+
predicate: "test://items",
|
|
379
|
+
target: "value",
|
|
380
|
+
},
|
|
381
|
+
],
|
|
314
382
|
});
|
|
315
383
|
const json = original.toJSON();
|
|
316
384
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
317
385
|
const prop = reconstructed.properties[0];
|
|
318
|
-
expect(prop.name).toBe(
|
|
319
|
-
expect(prop.path).toBe(
|
|
320
|
-
expect(prop.datatype).toBe(
|
|
321
|
-
expect(prop.nodeKind).toBe(
|
|
386
|
+
expect(prop.name).toBe("field");
|
|
387
|
+
expect(prop.path).toBe("test://field");
|
|
388
|
+
expect(prop.datatype).toBe("xsd:string");
|
|
389
|
+
expect(prop.nodeKind).toBe("Literal");
|
|
322
390
|
expect(prop.minCount).toBe(0);
|
|
323
391
|
expect(prop.maxCount).toBe(5);
|
|
324
392
|
expect(prop.minInclusive).toBe(0);
|
|
325
393
|
expect(prop.maxInclusive).toBe(100);
|
|
326
|
-
expect(prop.pattern).toBe(
|
|
327
|
-
expect(prop.hasValue).toBe(
|
|
394
|
+
expect(prop.pattern).toBe("^[a-z]+$");
|
|
395
|
+
expect(prop.hasValue).toBe("default");
|
|
328
396
|
expect(prop.local).toBe(true);
|
|
329
|
-
expect(prop.
|
|
330
|
-
expect(prop.resolveLanguage).toBe(
|
|
397
|
+
expect(prop.readOnly).toBeFalsy();
|
|
398
|
+
expect(prop.resolveLanguage).toBe("literal");
|
|
331
399
|
expect(prop.setter).toEqual(original.properties[0].setter);
|
|
332
400
|
expect(prop.adder).toEqual(original.properties[0].adder);
|
|
333
401
|
expect(prop.remover).toEqual(original.properties[0].remover);
|
package/lib/src/utils.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket close code 1006 (abnormal closure) is emitted on every active
|
|
3
|
+
* GraphQL subscription when the server process shuts down — it simply means
|
|
4
|
+
* the server didn't send a clean close frame. This is expected at the end
|
|
5
|
+
* of every test run and whenever the executor is stopped, so it must not be
|
|
6
|
+
* treated as an application error. All other errors are still surfaced.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isSocketCloseError(e: any): boolean;
|
|
1
9
|
export declare function formatList(list: any): any;
|
|
2
10
|
export declare function capSentence(cap: any): string;
|
|
3
11
|
/**
|