@coasys/ad4m 0.12.0-rc1-dev.2 → 0.12.0-rc1-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +10 -3
- package/lib/index.cjs +6893 -5884
- package/lib/index.js +6889 -5872
- package/lib/src/Ad4mClient.d.ts +9 -16
- package/lib/src/Ad4mClient.js +46 -25
- package/lib/src/Literal.d.ts +1 -2
- package/lib/src/Literal.js +38 -35
- package/lib/src/SmartLiteral.d.ts +1 -2
- package/lib/src/SmartLiteral.js +30 -15
- package/lib/src/agent/AgentClient.d.ts +1 -4
- package/lib/src/agent/AgentClient.js +79 -99
- package/lib/src/ai/AIClient.d.ts +1 -2
- package/lib/src/ai/AIClient.js +224 -220
- package/lib/src/expression/ExpressionClient.d.ts +1 -1
- package/lib/src/expression/ExpressionClient.js +73 -86
- 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 +1351 -144
- package/lib/src/model/Ad4mModel.js +3760 -228
- package/lib/src/model/Ad4mModel.test.js +522 -979
- package/lib/src/model/Subject.d.ts +3 -3
- package/lib/src/model/Subject.js +25 -25
- package/lib/src/model/decorators.d.ts +444 -100
- package/lib/src/model/decorators.js +686 -321
- package/lib/src/model/util.d.ts +6 -6
- package/lib/src/model/util.js +24 -24
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +1 -5
- package/lib/src/neighbourhood/NeighbourhoodClient.js +179 -242
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +1 -2
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +28 -13
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +5 -1
- package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveClient.js +240 -316
- package/lib/src/perspectives/PerspectiveProxy.d.ts +99 -61
- package/lib/src/perspectives/PerspectiveProxy.js +485 -832
- package/lib/src/runtime/RuntimeClient.d.ts +1 -5
- package/lib/src/runtime/RuntimeClient.js +238 -412
- package/lib/src/shacl/SHACLFlow.test.js +105 -164
- package/lib/src/shacl/SHACLShape.d.ts +12 -17
- package/lib/src/shacl/SHACLShape.js +115 -128
- package/lib/src/shacl/SHACLShape.test.js +176 -244
- package/lib/src/shims/reflect-metadata.d.ts +0 -0
- package/lib/src/shims/type-graphql.d.ts +32 -0
- package/lib/src/src/Ad4mClient.d.ts +28 -0
- package/lib/src/src/Address.d.ts +1 -0
- package/lib/src/src/DID.d.ts +1 -0
- package/lib/src/src/Exception.d.ts +7 -0
- package/lib/src/src/Literal.d.ts +7 -0
- package/lib/src/src/PubSub.d.ts +17 -0
- package/lib/src/src/SmartLiteral.d.ts +12 -0
- package/lib/src/src/agent/Agent.d.ts +110 -0
- package/lib/src/src/agent/AgentClient.d.ts +62 -0
- package/lib/src/src/agent/AgentResolver.d.ts +30 -0
- package/lib/src/src/agent/AgentStatus.d.ts +8 -0
- package/lib/src/src/ai/AIClient.d.ts +32 -0
- package/lib/src/src/ai/AIResolver.d.ts +75 -0
- package/lib/src/src/ai/Tasks.d.ts +37 -0
- package/lib/src/src/buildSchema.d.ts +1 -0
- package/lib/src/src/expression/Expression.d.ts +28 -0
- package/lib/src/src/expression/ExpressionClient.d.ts +13 -0
- package/lib/src/src/expression/ExpressionRef.d.ts +9 -0
- package/lib/src/src/expression/ExpressionResolver.d.ts +10 -0
- package/lib/src/src/index.d.ts +35 -0
- package/lib/src/src/jestSetup.d.ts +1 -0
- package/lib/src/src/language/Icon.d.ts +4 -0
- package/lib/src/src/language/Language.d.ts +206 -0
- package/lib/src/src/language/LanguageClient.d.ts +17 -0
- package/lib/src/src/language/LanguageContext.d.ts +37 -0
- package/lib/src/src/language/LanguageHandle.d.ts +9 -0
- package/lib/src/src/language/LanguageMeta.d.ts +35 -0
- package/lib/src/src/language/LanguageRef.d.ts +6 -0
- package/lib/src/src/language/LanguageResolver.d.ts +19 -0
- package/lib/src/src/links/Links.d.ts +39 -0
- package/lib/src/src/links/Links.test.d.ts +1 -0
- package/lib/src/src/model/Ad4mModel.d.ts +1438 -0
- package/lib/src/src/model/Ad4mModel.test.d.ts +1 -0
- package/lib/src/src/model/Subject.d.ts +25 -0
- package/lib/src/src/model/decorators.d.ts +545 -0
- package/lib/src/src/model/util.d.ts +12 -0
- package/lib/src/src/neighbourhood/Neighbourhood.d.ts +10 -0
- package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
- package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
- package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
- package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
- package/lib/src/src/perspectives/LinkQuery.d.ts +11 -0
- package/lib/src/src/perspectives/Perspective.d.ts +38 -0
- package/lib/src/src/perspectives/Perspective.test.d.ts +1 -0
- package/lib/src/src/perspectives/PerspectiveClient.d.ts +97 -0
- package/lib/src/src/perspectives/PerspectiveDiff.d.ts +9 -0
- package/lib/src/src/perspectives/PerspectiveHandle.d.ts +18 -0
- package/lib/src/src/perspectives/PerspectiveProxy.d.ts +865 -0
- package/lib/src/src/perspectives/PerspectiveResolver.d.ts +57 -0
- package/lib/src/src/runtime/RuntimeClient.d.ts +56 -0
- package/lib/src/src/runtime/RuntimeResolver.d.ts +132 -0
- package/lib/src/src/shacl/SHACLFlow.d.ts +171 -0
- package/lib/src/src/shacl/SHACLFlow.test.d.ts +1 -0
- package/lib/src/src/shacl/SHACLShape.d.ts +117 -0
- package/lib/src/src/shacl/SHACLShape.test.d.ts +1 -0
- package/lib/src/src/typeDefs.d.ts +1 -0
- package/lib/src/src/unwrapApolloResult.d.ts +2 -0
- package/lib/src/src/utils.d.ts +25 -0
- package/lib/src/utils.d.ts +0 -8
- package/lib/src/utils.js +7 -21
- package/package.json +15 -14
- package/src/Ad4mClient.test.ts +1315 -1564
- package/src/Ad4mClient.ts +54 -55
- package/src/Literal.test.ts +26 -45
- package/src/Literal.ts +66 -82
- package/src/SmartLiteral.ts +58 -74
- package/src/agent/AgentClient.ts +99 -144
- package/src/ai/AIClient.ts +359 -409
- package/src/expression/ExpressionClient.ts +96 -142
- package/src/index.ts +1 -1
- package/src/language/LanguageClient.ts +113 -137
- package/src/model/Ad4mModel.test.ts +616 -1114
- package/src/model/Ad4mModel.ts +4386 -451
- package/src/model/Subject.ts +159 -0
- package/src/model/decorators.ts +1168 -667
- package/src/model/util.ts +54 -53
- package/src/neighbourhood/NeighbourhoodClient.ts +266 -392
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +7 -3
- package/src/neighbourhood/NeighbourhoodProxy.ts +40 -58
- package/src/perspectives/PerspectiveClient.ts +540 -779
- package/src/perspectives/PerspectiveProxy.ts +2067 -2860
- package/src/runtime/RuntimeClient.ts +476 -775
- package/src/shacl/SHACLFlow.test.ts +129 -196
- package/src/shacl/SHACLShape.test.ts +190 -284
- package/src/shacl/SHACLShape.ts +200 -224
- package/src/utils.ts +17 -31
- package/tsconfig.json +10 -9
- package/src/model/IMPROVEMENTS.md +0 -482
- package/src/model/PREDICATE_COLLISION_FIX.md +0 -651
- package/src/model/README.md +0 -317
- package/src/model/SHACL_MUTATION_DECOUPLING.md +0 -356
- package/src/model/SUBSCRIPTION_STRATEGY.md +0 -317
- package/src/model/TC39_STAGE_3_DECORATORS.md +0 -609
- package/src/model/mutation.ts +0 -461
- package/src/model/parentUtils.ts +0 -91
- package/src/model/prolog/generatePrologFacts.ts +0 -176
- package/src/model/prolog/index.ts +0 -1
- package/src/model/query/ModelQueryBuilder.ts +0 -173
- package/src/model/query/fetchInstance.ts +0 -181
- package/src/model/query/hydration.ts +0 -273
- package/src/model/query/operations.ts +0 -510
- package/src/model/query/snapshot.ts +0 -126
- package/src/model/query/surrealCompiler.ts +0 -376
- package/src/model/schema/fromJSONSchema.ts +0 -411
- package/src/model/schema/metadata.ts +0 -148
- package/src/model/subscription.ts +0 -307
- package/src/model/transaction.ts +0 -60
- package/src/model/types.ts +0 -207
|
@@ -1,26 +1,24 @@
|
|
|
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(
|
|
11
|
-
(l) => l.predicate === "sh://targetClass",
|
|
12
|
-
);
|
|
10
|
+
const targetClassLink = links.find(l => l.predicate === 'sh://targetClass');
|
|
13
11
|
expect(targetClassLink).toBeDefined();
|
|
14
|
-
expect(targetClassLink!.source).toBe(
|
|
15
|
-
expect(targetClassLink!.target).toBe(
|
|
12
|
+
expect(targetClassLink!.source).toBe('recipe://RecipeShape');
|
|
13
|
+
expect(targetClassLink!.target).toBe('recipe://Recipe');
|
|
16
14
|
});
|
|
17
15
|
|
|
18
|
-
it(
|
|
19
|
-
const shape = new SHACLShape(
|
|
16
|
+
it('creates property shape links with named URIs', () => {
|
|
17
|
+
const shape = new SHACLShape('recipe://Recipe');
|
|
20
18
|
const prop: SHACLPropertyShape = {
|
|
21
|
-
name:
|
|
22
|
-
path:
|
|
23
|
-
datatype:
|
|
19
|
+
name: 'name',
|
|
20
|
+
path: 'recipe://name',
|
|
21
|
+
datatype: 'xsd:string',
|
|
24
22
|
minCount: 1,
|
|
25
23
|
maxCount: 1,
|
|
26
24
|
};
|
|
@@ -28,351 +26,293 @@ describe("SHACLShape", () => {
|
|
|
28
26
|
const links = shape.toLinks();
|
|
29
27
|
|
|
30
28
|
// Property shape should use named URI
|
|
31
|
-
const propLink = links.find(
|
|
29
|
+
const propLink = links.find(l => l.predicate === 'sh://property');
|
|
32
30
|
expect(propLink).toBeDefined();
|
|
33
|
-
expect(propLink!.target).toBe(
|
|
31
|
+
expect(propLink!.target).toBe('recipe://Recipe.name'); // Named URI, not blank node
|
|
34
32
|
|
|
35
33
|
// Path link
|
|
36
|
-
const pathLink = links.find(
|
|
37
|
-
|
|
38
|
-
l.source === "recipe://Recipe.name" && l.predicate === "sh://path",
|
|
34
|
+
const pathLink = links.find(l =>
|
|
35
|
+
l.source === 'recipe://Recipe.name' && l.predicate === 'sh://path'
|
|
39
36
|
);
|
|
40
37
|
expect(pathLink).toBeDefined();
|
|
41
|
-
expect(pathLink!.target).toBe(
|
|
38
|
+
expect(pathLink!.target).toBe('recipe://name');
|
|
42
39
|
|
|
43
40
|
// Datatype link
|
|
44
|
-
const datatypeLink = links.find(
|
|
45
|
-
|
|
46
|
-
l.source === "recipe://Recipe.name" &&
|
|
47
|
-
l.predicate === "sh://datatype",
|
|
41
|
+
const datatypeLink = links.find(l =>
|
|
42
|
+
l.source === 'recipe://Recipe.name' && l.predicate === 'sh://datatype'
|
|
48
43
|
);
|
|
49
44
|
expect(datatypeLink).toBeDefined();
|
|
50
|
-
expect(datatypeLink!.target).toBe(
|
|
45
|
+
expect(datatypeLink!.target).toBe('xsd:string');
|
|
51
46
|
|
|
52
47
|
// Cardinality links
|
|
53
|
-
const minCountLink = links.find(
|
|
54
|
-
|
|
55
|
-
l.source === "recipe://Recipe.name" &&
|
|
56
|
-
l.predicate === "sh://minCount",
|
|
48
|
+
const minCountLink = links.find(l =>
|
|
49
|
+
l.source === 'recipe://Recipe.name' && l.predicate === 'sh://minCount'
|
|
57
50
|
);
|
|
58
51
|
expect(minCountLink).toBeDefined();
|
|
59
|
-
expect(minCountLink!.target).toContain(
|
|
52
|
+
expect(minCountLink!.target).toContain('1');
|
|
60
53
|
|
|
61
|
-
const maxCountLink = links.find(
|
|
62
|
-
|
|
63
|
-
l.source === "recipe://Recipe.name" &&
|
|
64
|
-
l.predicate === "sh://maxCount",
|
|
54
|
+
const maxCountLink = links.find(l =>
|
|
55
|
+
l.source === 'recipe://Recipe.name' && l.predicate === 'sh://maxCount'
|
|
65
56
|
);
|
|
66
57
|
expect(maxCountLink).toBeDefined();
|
|
67
|
-
expect(maxCountLink!.target).toContain(
|
|
58
|
+
expect(maxCountLink!.target).toContain('1');
|
|
68
59
|
});
|
|
69
60
|
|
|
70
|
-
it(
|
|
71
|
-
const shape = new SHACLShape(
|
|
61
|
+
it('creates action links', () => {
|
|
62
|
+
const shape = new SHACLShape('recipe://Recipe');
|
|
72
63
|
const setterAction: AD4MAction = {
|
|
73
|
-
action:
|
|
74
|
-
source:
|
|
75
|
-
predicate:
|
|
76
|
-
target:
|
|
64
|
+
action: 'addLink',
|
|
65
|
+
source: 'this',
|
|
66
|
+
predicate: 'recipe://name',
|
|
67
|
+
target: 'value',
|
|
77
68
|
};
|
|
78
69
|
const prop: SHACLPropertyShape = {
|
|
79
|
-
name:
|
|
80
|
-
path:
|
|
70
|
+
name: 'title',
|
|
71
|
+
path: 'recipe://title',
|
|
81
72
|
setter: [setterAction],
|
|
82
73
|
};
|
|
83
74
|
shape.addProperty(prop);
|
|
84
75
|
const links = shape.toLinks();
|
|
85
76
|
|
|
86
77
|
// Setter action link
|
|
87
|
-
const setterLink = links.find(
|
|
88
|
-
|
|
89
|
-
l.source === "recipe://Recipe.title" &&
|
|
90
|
-
l.predicate === "ad4m://setter",
|
|
78
|
+
const setterLink = links.find(l =>
|
|
79
|
+
l.source === 'recipe://Recipe.title' && l.predicate === 'ad4m://setter'
|
|
91
80
|
);
|
|
92
81
|
expect(setterLink).toBeDefined();
|
|
93
|
-
expect(setterLink!.target).toContain(
|
|
82
|
+
expect(setterLink!.target).toContain('addLink');
|
|
94
83
|
});
|
|
95
84
|
|
|
96
|
-
it(
|
|
97
|
-
const shape = new SHACLShape(
|
|
98
|
-
shape.constructor_actions = [
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
predicate: "ad4m://type",
|
|
111
|
-
target: "recipe://Recipe",
|
|
112
|
-
},
|
|
113
|
-
];
|
|
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
|
+
}];
|
|
114
99
|
const links = shape.toLinks();
|
|
115
100
|
|
|
116
|
-
const constructorLink = links.find(
|
|
117
|
-
(l) => l.predicate === "ad4m://constructor",
|
|
118
|
-
);
|
|
101
|
+
const constructorLink = links.find(l => l.predicate === 'ad4m://constructor');
|
|
119
102
|
expect(constructorLink).toBeDefined();
|
|
120
|
-
expect(constructorLink!.target).toContain(
|
|
103
|
+
expect(constructorLink!.target).toContain('addLink');
|
|
121
104
|
|
|
122
|
-
const destructorLink = links.find(
|
|
123
|
-
(l) => l.predicate === "ad4m://destructor",
|
|
124
|
-
);
|
|
105
|
+
const destructorLink = links.find(l => l.predicate === 'ad4m://destructor');
|
|
125
106
|
expect(destructorLink).toBeDefined();
|
|
126
|
-
expect(destructorLink!.target).toContain(
|
|
107
|
+
expect(destructorLink!.target).toContain('removeLink');
|
|
127
108
|
});
|
|
128
109
|
});
|
|
129
110
|
|
|
130
|
-
describe(
|
|
131
|
-
it(
|
|
132
|
-
const originalShape = new SHACLShape(
|
|
111
|
+
describe('fromLinks()', () => {
|
|
112
|
+
it('reconstructs shape from links', () => {
|
|
113
|
+
const originalShape = new SHACLShape('recipe://Recipe');
|
|
133
114
|
originalShape.addProperty({
|
|
134
|
-
name:
|
|
135
|
-
path:
|
|
136
|
-
datatype:
|
|
115
|
+
name: 'name',
|
|
116
|
+
path: 'recipe://name',
|
|
117
|
+
datatype: 'xsd:string',
|
|
137
118
|
minCount: 1,
|
|
138
119
|
});
|
|
139
|
-
|
|
120
|
+
|
|
140
121
|
const links = originalShape.toLinks();
|
|
141
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
122
|
+
const reconstructed = SHACLShape.fromLinks(links, 'recipe://RecipeShape');
|
|
142
123
|
|
|
143
|
-
expect(reconstructed.targetClass).toBe(
|
|
124
|
+
expect(reconstructed.targetClass).toBe('recipe://Recipe');
|
|
144
125
|
expect(reconstructed.properties.length).toBe(1);
|
|
145
|
-
expect(reconstructed.properties[0].path).toBe(
|
|
146
|
-
expect(reconstructed.properties[0].datatype).toBe(
|
|
126
|
+
expect(reconstructed.properties[0].path).toBe('recipe://name');
|
|
127
|
+
expect(reconstructed.properties[0].datatype).toBe('xsd:string');
|
|
147
128
|
expect(reconstructed.properties[0].minCount).toBe(1);
|
|
148
129
|
});
|
|
149
130
|
|
|
150
|
-
it(
|
|
151
|
-
const originalShape = new SHACLShape(
|
|
131
|
+
it('handles multiple properties', () => {
|
|
132
|
+
const originalShape = new SHACLShape('recipe://Recipe');
|
|
152
133
|
originalShape.addProperty({
|
|
153
|
-
name:
|
|
154
|
-
path:
|
|
155
|
-
datatype:
|
|
134
|
+
name: 'name',
|
|
135
|
+
path: 'recipe://name',
|
|
136
|
+
datatype: 'xsd:string',
|
|
156
137
|
});
|
|
157
138
|
originalShape.addProperty({
|
|
158
|
-
name:
|
|
159
|
-
path:
|
|
160
|
-
datatype:
|
|
139
|
+
name: 'servings',
|
|
140
|
+
path: 'recipe://servings',
|
|
141
|
+
datatype: 'xsd:integer',
|
|
161
142
|
});
|
|
162
|
-
|
|
143
|
+
|
|
163
144
|
const links = originalShape.toLinks();
|
|
164
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
145
|
+
const reconstructed = SHACLShape.fromLinks(links, 'recipe://RecipeShape');
|
|
165
146
|
|
|
166
147
|
expect(reconstructed.properties.length).toBe(2);
|
|
167
|
-
const nameProp = reconstructed.properties.find(
|
|
168
|
-
|
|
169
|
-
);
|
|
170
|
-
const servingsProp = reconstructed.properties.find(
|
|
171
|
-
(p) => p.path === "recipe://servings",
|
|
172
|
-
);
|
|
148
|
+
const nameProp = reconstructed.properties.find(p => p.path === 'recipe://name');
|
|
149
|
+
const servingsProp = reconstructed.properties.find(p => p.path === 'recipe://servings');
|
|
173
150
|
expect(nameProp).toBeDefined();
|
|
174
151
|
expect(servingsProp).toBeDefined();
|
|
175
|
-
expect(nameProp!.datatype).toBe(
|
|
176
|
-
expect(servingsProp!.datatype).toBe(
|
|
152
|
+
expect(nameProp!.datatype).toBe('xsd:string');
|
|
153
|
+
expect(servingsProp!.datatype).toBe('xsd:integer');
|
|
177
154
|
});
|
|
178
155
|
|
|
179
|
-
it(
|
|
180
|
-
const originalShape = new SHACLShape(
|
|
156
|
+
it('reconstructs action arrays', () => {
|
|
157
|
+
const originalShape = new SHACLShape('recipe://Recipe');
|
|
181
158
|
const setterAction: AD4MAction = {
|
|
182
|
-
action:
|
|
183
|
-
source:
|
|
184
|
-
predicate:
|
|
185
|
-
target:
|
|
159
|
+
action: 'addLink',
|
|
160
|
+
source: 'this',
|
|
161
|
+
predicate: 'recipe://name',
|
|
162
|
+
target: 'value',
|
|
186
163
|
};
|
|
187
164
|
originalShape.addProperty({
|
|
188
|
-
name:
|
|
189
|
-
path:
|
|
165
|
+
name: 'name',
|
|
166
|
+
path: 'recipe://name',
|
|
190
167
|
setter: [setterAction],
|
|
191
168
|
});
|
|
192
|
-
|
|
169
|
+
|
|
193
170
|
const links = originalShape.toLinks();
|
|
194
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
171
|
+
const reconstructed = SHACLShape.fromLinks(links, 'recipe://RecipeShape');
|
|
195
172
|
|
|
196
173
|
expect(reconstructed.properties[0].setter).toBeDefined();
|
|
197
174
|
expect(reconstructed.properties[0].setter!.length).toBe(1);
|
|
198
|
-
expect(reconstructed.properties[0].setter![0].action).toBe(
|
|
175
|
+
expect(reconstructed.properties[0].setter![0].action).toBe('addLink');
|
|
199
176
|
});
|
|
200
177
|
});
|
|
201
178
|
|
|
202
|
-
describe(
|
|
203
|
-
it(
|
|
204
|
-
const original = new SHACLShape(
|
|
179
|
+
describe('round-trip serialization', () => {
|
|
180
|
+
it('preserves all property attributes', () => {
|
|
181
|
+
const original = new SHACLShape('test://Model');
|
|
205
182
|
original.addProperty({
|
|
206
|
-
name:
|
|
207
|
-
path:
|
|
208
|
-
datatype:
|
|
209
|
-
nodeKind:
|
|
183
|
+
name: 'field',
|
|
184
|
+
path: 'test://field',
|
|
185
|
+
datatype: 'xsd:string',
|
|
186
|
+
nodeKind: 'Literal',
|
|
210
187
|
minCount: 0,
|
|
211
188
|
maxCount: 5,
|
|
212
|
-
pattern:
|
|
189
|
+
pattern: '^[a-z]+$',
|
|
213
190
|
minInclusive: 10,
|
|
214
191
|
maxInclusive: 100,
|
|
215
|
-
hasValue:
|
|
216
|
-
resolveLanguage:
|
|
192
|
+
hasValue: 'expectedValue',
|
|
193
|
+
resolveLanguage: 'test://language',
|
|
217
194
|
local: true,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
],
|
|
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' }],
|
|
242
199
|
});
|
|
243
200
|
|
|
244
201
|
const links = original.toLinks();
|
|
245
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
202
|
+
const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
|
|
246
203
|
|
|
247
204
|
const prop = reconstructed.properties[0];
|
|
248
|
-
expect(prop.path).toBe(
|
|
249
|
-
expect(prop.datatype).toBe(
|
|
250
|
-
expect(prop.nodeKind).toBe(
|
|
205
|
+
expect(prop.path).toBe('test://field');
|
|
206
|
+
expect(prop.datatype).toBe('xsd:string');
|
|
207
|
+
expect(prop.nodeKind).toBe('Literal');
|
|
251
208
|
expect(prop.minCount).toBe(0);
|
|
252
209
|
expect(prop.maxCount).toBe(5);
|
|
253
|
-
expect(prop.pattern).toBe(
|
|
210
|
+
expect(prop.pattern).toBe('^[a-z]+$');
|
|
254
211
|
expect(prop.minInclusive).toBe(10);
|
|
255
212
|
expect(prop.maxInclusive).toBe(100);
|
|
256
|
-
expect(prop.hasValue).toBe(
|
|
257
|
-
expect(prop.resolveLanguage).toBe(
|
|
213
|
+
expect(prop.hasValue).toBe('expectedValue');
|
|
214
|
+
expect(prop.resolveLanguage).toBe('test://language');
|
|
258
215
|
expect(prop.local).toBe(true);
|
|
259
|
-
expect(prop.
|
|
216
|
+
expect(prop.writable).toBe(true);
|
|
260
217
|
expect(prop.setter).toBeDefined();
|
|
261
218
|
expect(prop.adder).toBeDefined();
|
|
262
219
|
expect(prop.remover).toBeDefined();
|
|
263
220
|
});
|
|
264
221
|
|
|
265
|
-
it(
|
|
266
|
-
const original = new SHACLShape(
|
|
222
|
+
it('preserves constructor and destructor actions', () => {
|
|
223
|
+
const original = new SHACLShape('test://Model');
|
|
267
224
|
original.constructor_actions = [
|
|
268
|
-
{
|
|
269
|
-
action: "addLink",
|
|
270
|
-
source: "this",
|
|
271
|
-
predicate: "rdf://type",
|
|
272
|
-
target: "test://Model",
|
|
273
|
-
},
|
|
225
|
+
{ action: 'addLink', source: 'this', predicate: 'rdf://type', target: 'test://Model' }
|
|
274
226
|
];
|
|
275
227
|
original.destructor_actions = [
|
|
276
|
-
{
|
|
277
|
-
action: "removeLink",
|
|
278
|
-
source: "this",
|
|
279
|
-
predicate: "rdf://type",
|
|
280
|
-
target: "test://Model",
|
|
281
|
-
},
|
|
228
|
+
{ action: 'removeLink', source: 'this', predicate: 'rdf://type', target: 'test://Model' }
|
|
282
229
|
];
|
|
283
230
|
|
|
284
231
|
const links = original.toLinks();
|
|
285
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
232
|
+
const reconstructed = SHACLShape.fromLinks(links, 'test://ModelShape');
|
|
286
233
|
|
|
287
234
|
expect(reconstructed.constructor_actions).toBeDefined();
|
|
288
235
|
expect(reconstructed.constructor_actions!.length).toBe(1);
|
|
289
|
-
expect(reconstructed.constructor_actions![0].action).toBe(
|
|
236
|
+
expect(reconstructed.constructor_actions![0].action).toBe('addLink');
|
|
290
237
|
|
|
291
238
|
expect(reconstructed.destructor_actions).toBeDefined();
|
|
292
239
|
expect(reconstructed.destructor_actions!.length).toBe(1);
|
|
293
|
-
expect(reconstructed.destructor_actions![0].action).toBe(
|
|
240
|
+
expect(reconstructed.destructor_actions![0].action).toBe('removeLink');
|
|
294
241
|
});
|
|
295
242
|
});
|
|
296
243
|
|
|
297
|
-
describe(
|
|
298
|
-
it(
|
|
299
|
-
const shape = new SHACLShape(
|
|
244
|
+
describe('edge cases', () => {
|
|
245
|
+
it('handles empty shape', () => {
|
|
246
|
+
const shape = new SHACLShape('test://Empty');
|
|
300
247
|
const links = shape.toLinks();
|
|
301
|
-
|
|
248
|
+
|
|
302
249
|
expect(links.length).toBeGreaterThanOrEqual(1); // At least targetClass link
|
|
303
|
-
|
|
304
|
-
const reconstructed = SHACLShape.fromLinks(links,
|
|
305
|
-
expect(reconstructed.targetClass).toBe(
|
|
250
|
+
|
|
251
|
+
const reconstructed = SHACLShape.fromLinks(links, 'test://EmptyShape');
|
|
252
|
+
expect(reconstructed.targetClass).toBe('test://Empty');
|
|
306
253
|
expect(reconstructed.properties.length).toBe(0);
|
|
307
254
|
});
|
|
308
255
|
|
|
309
|
-
it(
|
|
310
|
-
const shape = new SHACLShape(
|
|
256
|
+
it('handles URI with hash fragment', () => {
|
|
257
|
+
const shape = new SHACLShape('https://example.com/vocab#Recipe');
|
|
311
258
|
const links = shape.toLinks();
|
|
312
|
-
|
|
313
|
-
const targetClassLink = links.find(
|
|
314
|
-
|
|
315
|
-
);
|
|
316
|
-
expect(targetClassLink!.source).toBe(
|
|
317
|
-
"https://example.com/vocab#RecipeShape",
|
|
318
|
-
);
|
|
259
|
+
|
|
260
|
+
const targetClassLink = links.find(l => l.predicate === 'sh://targetClass');
|
|
261
|
+
expect(targetClassLink!.source).toBe('https://example.com/vocab#RecipeShape');
|
|
319
262
|
});
|
|
320
263
|
|
|
321
|
-
it(
|
|
322
|
-
const shape = new SHACLShape(
|
|
264
|
+
it('falls back to blank nodes when property has no name', () => {
|
|
265
|
+
const shape = new SHACLShape('test://Model');
|
|
323
266
|
shape.addProperty({
|
|
324
|
-
path:
|
|
267
|
+
path: 'test://unnamed',
|
|
325
268
|
// No name property
|
|
326
269
|
});
|
|
327
270
|
const links = shape.toLinks();
|
|
328
|
-
|
|
329
|
-
const propLink = links.find(
|
|
271
|
+
|
|
272
|
+
const propLink = links.find(l => l.predicate === 'sh://property');
|
|
330
273
|
expect(propLink).toBeDefined();
|
|
331
274
|
// Should use blank node format when no name provided
|
|
332
275
|
expect(propLink!.target).toMatch(/_:propShape\d+|test:\/\/Model\./);
|
|
333
276
|
});
|
|
334
277
|
});
|
|
335
278
|
|
|
336
|
-
describe(
|
|
337
|
-
it(
|
|
338
|
-
const original = new SHACLShape(
|
|
279
|
+
describe('toJSON/fromJSON', () => {
|
|
280
|
+
it('serializes and deserializes basic shape', () => {
|
|
281
|
+
const original = new SHACLShape('recipe://Recipe');
|
|
339
282
|
original.addProperty({
|
|
340
|
-
name:
|
|
341
|
-
path:
|
|
342
|
-
datatype:
|
|
283
|
+
name: 'name',
|
|
284
|
+
path: 'recipe://name',
|
|
285
|
+
datatype: 'xsd:string',
|
|
343
286
|
minCount: 1,
|
|
344
287
|
});
|
|
345
288
|
|
|
346
289
|
const json = original.toJSON();
|
|
347
290
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
348
291
|
|
|
349
|
-
expect(reconstructed.targetClass).toBe(
|
|
292
|
+
expect(reconstructed.targetClass).toBe('recipe://Recipe');
|
|
350
293
|
expect(reconstructed.properties.length).toBe(1);
|
|
351
|
-
expect(reconstructed.properties[0].name).toBe(
|
|
352
|
-
expect(reconstructed.properties[0].path).toBe(
|
|
353
|
-
expect(reconstructed.properties[0].datatype).toBe(
|
|
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');
|
|
354
297
|
expect(reconstructed.properties[0].minCount).toBe(1);
|
|
355
298
|
});
|
|
356
299
|
|
|
357
|
-
it(
|
|
358
|
-
const original = new SHACLShape(
|
|
359
|
-
"custom://CustomShape",
|
|
360
|
-
"recipe://Recipe",
|
|
361
|
-
);
|
|
300
|
+
it('preserves nodeShapeUri in round-trip', () => {
|
|
301
|
+
const original = new SHACLShape('custom://CustomShape', 'recipe://Recipe');
|
|
362
302
|
|
|
363
303
|
const json = original.toJSON();
|
|
364
304
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
365
305
|
|
|
366
|
-
expect(reconstructed.nodeShapeUri).toBe(
|
|
367
|
-
expect(reconstructed.targetClass).toBe(
|
|
306
|
+
expect(reconstructed.nodeShapeUri).toBe('custom://CustomShape');
|
|
307
|
+
expect(reconstructed.targetClass).toBe('recipe://Recipe');
|
|
368
308
|
});
|
|
369
309
|
|
|
370
|
-
it(
|
|
371
|
-
const original = new SHACLShape(
|
|
310
|
+
it('preserves minInclusive and maxInclusive', () => {
|
|
311
|
+
const original = new SHACLShape('test://Model');
|
|
372
312
|
original.addProperty({
|
|
373
|
-
name:
|
|
374
|
-
path:
|
|
375
|
-
datatype:
|
|
313
|
+
name: 'rating',
|
|
314
|
+
path: 'test://rating',
|
|
315
|
+
datatype: 'xsd:integer',
|
|
376
316
|
minInclusive: 1,
|
|
377
317
|
maxInclusive: 5,
|
|
378
318
|
});
|
|
@@ -384,108 +324,74 @@ describe("SHACLShape", () => {
|
|
|
384
324
|
expect(reconstructed.properties[0].maxInclusive).toBe(5);
|
|
385
325
|
});
|
|
386
326
|
|
|
387
|
-
it(
|
|
388
|
-
const original = new SHACLShape(
|
|
327
|
+
it('preserves resolveLanguage', () => {
|
|
328
|
+
const original = new SHACLShape('test://Model');
|
|
389
329
|
original.addProperty({
|
|
390
|
-
name:
|
|
391
|
-
path:
|
|
392
|
-
resolveLanguage:
|
|
330
|
+
name: 'content',
|
|
331
|
+
path: 'test://content',
|
|
332
|
+
resolveLanguage: 'literal',
|
|
393
333
|
});
|
|
394
334
|
|
|
395
335
|
const json = original.toJSON();
|
|
396
336
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
397
337
|
|
|
398
|
-
expect(reconstructed.properties[0].resolveLanguage).toBe(
|
|
338
|
+
expect(reconstructed.properties[0].resolveLanguage).toBe('literal');
|
|
399
339
|
});
|
|
400
340
|
|
|
401
|
-
it(
|
|
402
|
-
const original = new SHACLShape(
|
|
341
|
+
it('preserves constructor and destructor actions', () => {
|
|
342
|
+
const original = new SHACLShape('test://Model');
|
|
403
343
|
original.constructor_actions = [
|
|
404
|
-
{
|
|
405
|
-
action: "addLink",
|
|
406
|
-
source: "this",
|
|
407
|
-
predicate: "rdf://type",
|
|
408
|
-
target: "test://Model",
|
|
409
|
-
},
|
|
344
|
+
{ action: 'addLink', source: 'this', predicate: 'rdf://type', target: 'test://Model' }
|
|
410
345
|
];
|
|
411
346
|
original.destructor_actions = [
|
|
412
|
-
{
|
|
413
|
-
action: "removeLink",
|
|
414
|
-
source: "this",
|
|
415
|
-
predicate: "rdf://type",
|
|
416
|
-
target: "test://Model",
|
|
417
|
-
},
|
|
347
|
+
{ action: 'removeLink', source: 'this', predicate: 'rdf://type', target: 'test://Model' }
|
|
418
348
|
];
|
|
419
349
|
|
|
420
350
|
const json = original.toJSON();
|
|
421
351
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
422
352
|
|
|
423
|
-
expect(reconstructed.constructor_actions).toEqual(
|
|
424
|
-
|
|
425
|
-
);
|
|
426
|
-
expect(reconstructed.destructor_actions).toEqual(
|
|
427
|
-
original.destructor_actions,
|
|
428
|
-
);
|
|
353
|
+
expect(reconstructed.constructor_actions).toEqual(original.constructor_actions);
|
|
354
|
+
expect(reconstructed.destructor_actions).toEqual(original.destructor_actions);
|
|
429
355
|
});
|
|
430
356
|
|
|
431
|
-
it(
|
|
432
|
-
const original = new SHACLShape(
|
|
357
|
+
it('preserves all property attributes', () => {
|
|
358
|
+
const original = new SHACLShape('test://Model');
|
|
433
359
|
original.addProperty({
|
|
434
|
-
name:
|
|
435
|
-
path:
|
|
436
|
-
datatype:
|
|
437
|
-
nodeKind:
|
|
360
|
+
name: 'field',
|
|
361
|
+
path: 'test://field',
|
|
362
|
+
datatype: 'xsd:string',
|
|
363
|
+
nodeKind: 'Literal',
|
|
438
364
|
minCount: 0,
|
|
439
365
|
maxCount: 5,
|
|
440
366
|
minInclusive: 0,
|
|
441
367
|
maxInclusive: 100,
|
|
442
|
-
pattern:
|
|
443
|
-
hasValue:
|
|
368
|
+
pattern: '^[a-z]+$',
|
|
369
|
+
hasValue: 'default',
|
|
444
370
|
local: true,
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
],
|
|
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' }],
|
|
470
376
|
});
|
|
471
377
|
|
|
472
378
|
const json = original.toJSON();
|
|
473
379
|
const reconstructed = SHACLShape.fromJSON(json);
|
|
474
380
|
|
|
475
381
|
const prop = reconstructed.properties[0];
|
|
476
|
-
expect(prop.name).toBe(
|
|
477
|
-
expect(prop.path).toBe(
|
|
478
|
-
expect(prop.datatype).toBe(
|
|
479
|
-
expect(prop.nodeKind).toBe(
|
|
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');
|
|
480
386
|
expect(prop.minCount).toBe(0);
|
|
481
387
|
expect(prop.maxCount).toBe(5);
|
|
482
388
|
expect(prop.minInclusive).toBe(0);
|
|
483
389
|
expect(prop.maxInclusive).toBe(100);
|
|
484
|
-
expect(prop.pattern).toBe(
|
|
485
|
-
expect(prop.hasValue).toBe(
|
|
390
|
+
expect(prop.pattern).toBe('^[a-z]+$');
|
|
391
|
+
expect(prop.hasValue).toBe('default');
|
|
486
392
|
expect(prop.local).toBe(true);
|
|
487
|
-
expect(prop.
|
|
488
|
-
expect(prop.resolveLanguage).toBe(
|
|
393
|
+
expect(prop.writable).toBe(true);
|
|
394
|
+
expect(prop.resolveLanguage).toBe('literal');
|
|
489
395
|
expect(prop.setter).toEqual(original.properties[0].setter);
|
|
490
396
|
expect(prop.adder).toEqual(original.properties[0].adder);
|
|
491
397
|
expect(prop.remover).toEqual(original.properties[0].remover);
|