@coasys/ad4m 0.12.0-rc1-dev.1 → 0.12.0-rc1-dev.3
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 +8 -1
- package/lib/index.cjs +13793 -12854
- package/lib/index.js +13782 -12851
- package/lib/src/Ad4mClient.test.d.ts +1 -0
- package/lib/src/Ad4mClient.test.js +1204 -0
- package/lib/src/Literal.test.d.ts +1 -0
- package/lib/src/Literal.test.js +41 -0
- package/lib/src/model/Ad4mModel.d.ts +528 -101
- package/lib/src/model/Ad4mModel.js +1670 -748
- package/lib/src/model/Ad4mModel.test.js +140 -156
- package/lib/src/model/Subject.d.ts +3 -3
- package/lib/src/model/Subject.js +25 -25
- package/lib/src/model/decorators.d.ts +259 -247
- package/lib/src/model/decorators.js +379 -422
- 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.d.ts +6 -6
- package/lib/src/model/util.js +22 -22
- package/lib/src/neighbourhood/NeighbourhoodClient.js +31 -12
- package/lib/src/perspectives/PerspectiveProxy.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveProxy.js +63 -51
- package/lib/src/shacl/SHACLShape.d.ts +9 -0
- package/lib/src/shacl/SHACLShape.js +28 -4
- 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/package.json +20 -24
- package/src/model/Ad4mModel.test.ts +132 -149
- package/src/model/Ad4mModel.ts +1930 -784
- package/src/model/Subject.ts +24 -24
- package/src/model/decorators.ts +626 -482
- package/src/model/util.ts +22 -22
- package/src/neighbourhood/NeighbourhoodClient.ts +32 -16
- package/src/perspectives/PerspectiveProxy.ts +69 -55
- package/src/shacl/SHACLShape.ts +33 -4
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { Ad4mModel } from "./Ad4mModel";
|
|
2
|
-
import {
|
|
2
|
+
import { Model, Property, Optional, ReadOnly, HasMany, Flag } from "./decorators";
|
|
3
3
|
|
|
4
4
|
describe("Ad4mModel.getModelMetadata()", () => {
|
|
5
5
|
it("should extract basic model metadata with className", () => {
|
|
6
|
-
@
|
|
6
|
+
@Model({ name: "SimpleModel" })
|
|
7
7
|
class SimpleModel extends Ad4mModel {}
|
|
8
8
|
|
|
9
9
|
const metadata = SimpleModel.getModelMetadata();
|
|
10
10
|
|
|
11
11
|
expect(metadata.className).toBe("SimpleModel");
|
|
12
12
|
expect(metadata.properties).toEqual({});
|
|
13
|
-
expect(metadata.
|
|
13
|
+
expect(metadata.relations).toEqual({});
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("should extract property metadata with all fields", () => {
|
|
17
|
-
@
|
|
17
|
+
@Model({ name: "PropertyModel" })
|
|
18
18
|
class PropertyModel extends Ad4mModel {
|
|
19
19
|
@Property({ through: "test://name", resolveLanguage: "literal" })
|
|
20
20
|
name: string = "";
|
|
21
21
|
|
|
22
|
-
@Optional({ through: "test://optional"
|
|
22
|
+
@Optional({ through: "test://optional" })
|
|
23
23
|
optional: string = "";
|
|
24
24
|
|
|
25
25
|
@ReadOnly({ through: "test://readonly", prologGetter: "custom_getter" })
|
|
@@ -36,17 +36,17 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
36
36
|
|
|
37
37
|
// Verify "name" property
|
|
38
38
|
expect(metadata.properties.name.predicate).toBe("test://name");
|
|
39
|
-
expect(metadata.properties.name.required).toBe(
|
|
40
|
-
expect(metadata.properties.name.
|
|
39
|
+
expect(metadata.properties.name.required).toBe(false);
|
|
40
|
+
expect(metadata.properties.name.readOnly).toBe(false);
|
|
41
41
|
expect(metadata.properties.name.resolveLanguage).toBe("literal");
|
|
42
42
|
|
|
43
43
|
// Verify "optional" property
|
|
44
44
|
expect(metadata.properties.optional.predicate).toBe("test://optional");
|
|
45
|
-
expect(metadata.properties.optional.
|
|
45
|
+
expect(metadata.properties.optional.readOnly).toBe(false);
|
|
46
46
|
|
|
47
47
|
// Verify "readonly" property
|
|
48
48
|
expect(metadata.properties.readonly.predicate).toBe("test://readonly");
|
|
49
|
-
expect(metadata.properties.readonly.
|
|
49
|
+
expect(metadata.properties.readonly.readOnly).toBe(true);
|
|
50
50
|
expect(metadata.properties.readonly.prologGetter).toBe("custom_getter");
|
|
51
51
|
|
|
52
52
|
// Verify "type" property (flag)
|
|
@@ -55,42 +55,31 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
55
55
|
expect(metadata.properties.type.initial).toBe("test://flag");
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
it("should extract
|
|
59
|
-
@
|
|
60
|
-
class
|
|
61
|
-
@
|
|
58
|
+
it("should extract relation metadata with various options", () => {
|
|
59
|
+
@Model({ name: "RelationModel" })
|
|
60
|
+
class RelationModel extends Ad4mModel {
|
|
61
|
+
@HasMany({ through: "test://items" })
|
|
62
62
|
items: string[] = [];
|
|
63
63
|
|
|
64
|
-
@
|
|
65
|
-
through: "test://filtered",
|
|
66
|
-
where: { condition: "triple(Target, 'test://active', 'true')" }
|
|
67
|
-
})
|
|
68
|
-
filtered: string[] = [];
|
|
69
|
-
|
|
70
|
-
@Collection({ through: "test://local", local: true })
|
|
64
|
+
@HasMany({ through: "test://local", local: true })
|
|
71
65
|
local: string[] = [];
|
|
72
66
|
}
|
|
73
67
|
|
|
74
|
-
const metadata =
|
|
68
|
+
const metadata = RelationModel.getModelMetadata();
|
|
75
69
|
|
|
76
|
-
// Should have
|
|
77
|
-
expect(Object.keys(metadata.
|
|
70
|
+
// Should have 2 relations
|
|
71
|
+
expect(Object.keys(metadata.relations)).toHaveLength(2);
|
|
78
72
|
|
|
79
|
-
// Verify "items"
|
|
80
|
-
expect(metadata.
|
|
81
|
-
expect(metadata.collections.items.where).toBeUndefined();
|
|
73
|
+
// Verify "items" relation
|
|
74
|
+
expect(metadata.relations.items.predicate).toBe("test://items");
|
|
82
75
|
|
|
83
|
-
// Verify "
|
|
84
|
-
expect(metadata.
|
|
85
|
-
expect(metadata.
|
|
86
|
-
|
|
87
|
-
// Verify "local" collection
|
|
88
|
-
expect(metadata.collections.local.predicate).toBe("test://local");
|
|
89
|
-
expect(metadata.collections.local.local).toBe(true);
|
|
76
|
+
// Verify "local" relation
|
|
77
|
+
expect(metadata.relations.local.predicate).toBe("test://local");
|
|
78
|
+
expect(metadata.relations.local.local).toBe(true);
|
|
90
79
|
});
|
|
91
80
|
|
|
92
81
|
it("should extract transform function from property metadata", () => {
|
|
93
|
-
@
|
|
82
|
+
@Model({ name: "TransformModel" })
|
|
94
83
|
class TransformModel extends Ad4mModel {
|
|
95
84
|
@Optional({
|
|
96
85
|
through: "test://data",
|
|
@@ -110,7 +99,7 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
110
99
|
});
|
|
111
100
|
|
|
112
101
|
it("should extract custom getter and setter from property metadata", () => {
|
|
113
|
-
@
|
|
102
|
+
@Model({ name: "CustomModel" })
|
|
114
103
|
class CustomModel extends Ad4mModel {
|
|
115
104
|
@Optional({
|
|
116
105
|
through: "test://computed",
|
|
@@ -128,34 +117,35 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
128
117
|
expect(metadata.properties.computed.prologSetter).toContain("setSingleTarget");
|
|
129
118
|
});
|
|
130
119
|
|
|
131
|
-
it("should handle
|
|
132
|
-
@
|
|
120
|
+
it("should handle relation with typed target relation", () => {
|
|
121
|
+
@Model({ name: "Comment" })
|
|
133
122
|
class Comment extends Ad4mModel {}
|
|
134
123
|
|
|
135
|
-
@
|
|
124
|
+
@Model({ name: "Post" })
|
|
136
125
|
class Post extends Ad4mModel {
|
|
137
|
-
@
|
|
126
|
+
@HasMany({
|
|
138
127
|
through: "post://comment",
|
|
139
|
-
|
|
128
|
+
target: () => Comment
|
|
140
129
|
})
|
|
141
130
|
comments: string[] = [];
|
|
142
131
|
}
|
|
143
132
|
|
|
144
133
|
const metadata = Post.getModelMetadata();
|
|
145
134
|
|
|
146
|
-
// Assert
|
|
147
|
-
expect(metadata.
|
|
135
|
+
// Assert relation exists with correct predicate
|
|
136
|
+
expect(metadata.relations.comments).toBeDefined();
|
|
137
|
+
expect(metadata.relations.comments.predicate).toBe("post://comment");
|
|
148
138
|
});
|
|
149
139
|
|
|
150
|
-
it("should throw error for class without @
|
|
140
|
+
it("should throw error for class without @Model decorator", () => {
|
|
151
141
|
class NoDecoratorModel extends Ad4mModel {}
|
|
152
142
|
|
|
153
143
|
// Assert that calling getModelMetadata throws an error
|
|
154
|
-
expect(() => NoDecoratorModel.getModelMetadata()).toThrow("Model class must be decorated with @
|
|
144
|
+
expect(() => NoDecoratorModel.getModelMetadata()).toThrow("Model class must be decorated with @Model");
|
|
155
145
|
});
|
|
156
146
|
|
|
157
|
-
it("should handle complex model with mixed property and
|
|
158
|
-
@
|
|
147
|
+
it("should handle complex model with mixed property and relation types", () => {
|
|
148
|
+
@Model({ name: "Recipe" })
|
|
159
149
|
class Recipe extends Ad4mModel {
|
|
160
150
|
@Property({ through: "recipe://name", resolveLanguage: "literal" })
|
|
161
151
|
name: string = "";
|
|
@@ -166,10 +156,10 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
166
156
|
@ReadOnly({ through: "recipe://rating", prologGetter: "avg_rating(Base, Value)" })
|
|
167
157
|
rating: number = 0;
|
|
168
158
|
|
|
169
|
-
@
|
|
159
|
+
@HasMany({ through: "recipe://ingredient" })
|
|
170
160
|
ingredients: string[] = [];
|
|
171
161
|
|
|
172
|
-
@
|
|
162
|
+
@HasMany({ through: "recipe://step", local: true })
|
|
173
163
|
steps: string[] = [];
|
|
174
164
|
}
|
|
175
165
|
|
|
@@ -184,10 +174,10 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
184
174
|
expect(metadata.properties.description).toBeDefined();
|
|
185
175
|
expect(metadata.properties.rating).toBeDefined();
|
|
186
176
|
|
|
187
|
-
// Assert
|
|
188
|
-
expect(Object.keys(metadata.
|
|
189
|
-
expect(metadata.
|
|
190
|
-
expect(metadata.
|
|
177
|
+
// Assert relations has 2 entries
|
|
178
|
+
expect(Object.keys(metadata.relations)).toHaveLength(2);
|
|
179
|
+
expect(metadata.relations.ingredients).toBeDefined();
|
|
180
|
+
expect(metadata.relations.steps).toBeDefined();
|
|
191
181
|
|
|
192
182
|
// Verify all metadata fields are correctly extracted
|
|
193
183
|
expect(metadata.properties.name.predicate).toBe("recipe://name");
|
|
@@ -195,9 +185,9 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
195
185
|
expect(metadata.properties.description.predicate).toBe("recipe://description");
|
|
196
186
|
expect(metadata.properties.rating.predicate).toBe("recipe://rating");
|
|
197
187
|
expect(metadata.properties.rating.prologGetter).toBe("avg_rating(Base, Value)");
|
|
198
|
-
expect(metadata.
|
|
199
|
-
expect(metadata.
|
|
200
|
-
expect(metadata.
|
|
188
|
+
expect(metadata.relations.ingredients.predicate).toBe("recipe://ingredient");
|
|
189
|
+
expect(metadata.relations.steps.predicate).toBe("recipe://step");
|
|
190
|
+
expect(metadata.relations.steps.local).toBe(true);
|
|
201
191
|
});
|
|
202
192
|
});
|
|
203
193
|
|
|
@@ -230,7 +220,7 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
230
220
|
expect(metadata.properties.name).toBeDefined();
|
|
231
221
|
expect(metadata.properties.name.predicate).toBe("product://name");
|
|
232
222
|
expect(metadata.properties.name.required).toBe(true);
|
|
233
|
-
expect(metadata.properties.name.
|
|
223
|
+
expect(metadata.properties.name.readOnly).toBe(false);
|
|
234
224
|
expect(metadata.properties.name.resolveLanguage).toBe("literal");
|
|
235
225
|
|
|
236
226
|
expect(metadata.properties.price).toBeDefined();
|
|
@@ -243,7 +233,7 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
243
233
|
expect(metadata.properties.description.required).toBe(false);
|
|
244
234
|
});
|
|
245
235
|
|
|
246
|
-
it("should extract
|
|
236
|
+
it("should extract relations from a model created via fromJSONSchema with arrays", () => {
|
|
247
237
|
const schema = {
|
|
248
238
|
title: "Post",
|
|
249
239
|
type: "object",
|
|
@@ -271,13 +261,13 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
271
261
|
// Verify className
|
|
272
262
|
expect(metadata.className).toBe("Post");
|
|
273
263
|
|
|
274
|
-
// Verify
|
|
275
|
-
expect(Object.keys(metadata.
|
|
276
|
-
expect(metadata.
|
|
277
|
-
expect(metadata.
|
|
264
|
+
// Verify relations are extracted
|
|
265
|
+
expect(Object.keys(metadata.relations).length).toBeGreaterThan(0);
|
|
266
|
+
expect(metadata.relations.tags).toBeDefined();
|
|
267
|
+
expect(metadata.relations.tags.predicate).toBe("post://tags");
|
|
278
268
|
|
|
279
|
-
expect(metadata.
|
|
280
|
-
expect(metadata.
|
|
269
|
+
expect(metadata.relations.comments).toBeDefined();
|
|
270
|
+
expect(metadata.relations.comments.predicate).toBe("post://comments");
|
|
281
271
|
|
|
282
272
|
// Verify properties (should include at least title)
|
|
283
273
|
expect(metadata.properties.title).toBeDefined();
|
|
@@ -321,7 +311,7 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
321
311
|
// Verify x-ad4m metadata is respected
|
|
322
312
|
expect(metadata.properties.name.predicate).toBe("foaf://name");
|
|
323
313
|
expect(metadata.properties.name.resolveLanguage).toBe("literal");
|
|
324
|
-
expect(metadata.properties.name.
|
|
314
|
+
expect(metadata.properties.name.readOnly).toBe(false);
|
|
325
315
|
expect(metadata.properties.name.required).toBe(true);
|
|
326
316
|
|
|
327
317
|
expect(metadata.properties.email.predicate).toBe("foaf://mbox");
|
|
@@ -403,16 +393,16 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
403
393
|
expect(metadata.properties.published.predicate).toBe("article://published");
|
|
404
394
|
expect(metadata.properties.published.required).toBe(true);
|
|
405
395
|
|
|
406
|
-
// Verify
|
|
407
|
-
expect(metadata.
|
|
408
|
-
expect(metadata.
|
|
396
|
+
// Verify relations
|
|
397
|
+
expect(metadata.relations.authors).toBeDefined();
|
|
398
|
+
expect(metadata.relations.authors.predicate).toBe("article://authors");
|
|
409
399
|
|
|
410
|
-
expect(metadata.
|
|
411
|
-
expect(metadata.
|
|
412
|
-
expect(metadata.
|
|
400
|
+
expect(metadata.relations.tags).toBeDefined();
|
|
401
|
+
expect(metadata.relations.tags.predicate).toBe("article://tags");
|
|
402
|
+
expect(metadata.relations.tags.local).toBe(true);
|
|
413
403
|
});
|
|
414
404
|
|
|
415
|
-
it("should handle models with
|
|
405
|
+
it("should handle models with no properties (open-world, no auto-flag)", () => {
|
|
416
406
|
const schema = {
|
|
417
407
|
title: "EmptyModel",
|
|
418
408
|
type: "object",
|
|
@@ -429,11 +419,14 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
429
419
|
// Should have className
|
|
430
420
|
expect(metadata.className).toBe("EmptyModel");
|
|
431
421
|
|
|
432
|
-
// Should have
|
|
433
|
-
|
|
434
|
-
expect(metadata.properties.__ad4m_type
|
|
435
|
-
|
|
436
|
-
|
|
422
|
+
// Should NOT have an auto-generated __ad4m_type property —
|
|
423
|
+
// models with all-optional properties use open-world structural matching.
|
|
424
|
+
expect(metadata.properties.__ad4m_type).toBeUndefined();
|
|
425
|
+
|
|
426
|
+
// SHACL shape should still be valid with empty constructor/destructor
|
|
427
|
+
const { shape } = (EmptyModelClass as any).generateSHACL();
|
|
428
|
+
expect(shape.constructor_actions).toEqual([]);
|
|
429
|
+
expect(shape.destructor_actions).toEqual([]);
|
|
437
430
|
});
|
|
438
431
|
});
|
|
439
432
|
|
|
@@ -446,16 +439,16 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
446
439
|
return query.replace(/\s+/g, ' ').trim();
|
|
447
440
|
}
|
|
448
441
|
|
|
449
|
-
// Test Recipe model
|
|
450
|
-
@
|
|
442
|
+
// Test Recipe model — explicit required: true to test required-property query filters
|
|
443
|
+
@Model({ name: "Recipe" })
|
|
451
444
|
class Recipe extends Ad4mModel {
|
|
452
|
-
@Property({ through: "recipe://name" })
|
|
445
|
+
@Property({ through: "recipe://name", required: true })
|
|
453
446
|
name: string = "";
|
|
454
447
|
|
|
455
|
-
@Property({ through: "recipe://rating" })
|
|
448
|
+
@Property({ through: "recipe://rating", required: true })
|
|
456
449
|
rating: number = 0;
|
|
457
450
|
|
|
458
|
-
@
|
|
451
|
+
@HasMany({ through: "recipe://ingredient" })
|
|
459
452
|
ingredients: string[] = [];
|
|
460
453
|
}
|
|
461
454
|
|
|
@@ -465,7 +458,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
465
458
|
expect(query).toContain("id AS source");
|
|
466
459
|
expect(query).toContain("uri AS source_uri");
|
|
467
460
|
expect(query).toContain("FROM node");
|
|
468
|
-
expect(query).toContain("->link
|
|
461
|
+
expect(query).toContain("->link AS links");
|
|
469
462
|
expect(query).toContain("WHERE");
|
|
470
463
|
// Should have graph traversal filters for required properties
|
|
471
464
|
expect(query).toContain("count(->link[WHERE");
|
|
@@ -475,17 +468,17 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
475
468
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: "Pasta" } });
|
|
476
469
|
|
|
477
470
|
// Should have graph traversal filters for required properties and user filter
|
|
478
|
-
expect(query).toContain("count(->link[WHERE
|
|
479
|
-
expect(query).toContain("count(->link[WHERE
|
|
480
|
-
expect(query).toContain("count(->link[WHERE
|
|
471
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name']) > 0");
|
|
472
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://rating']) > 0");
|
|
473
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
481
474
|
});
|
|
482
475
|
|
|
483
476
|
it("should generate query with multiple property filters", async () => {
|
|
484
477
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: "Pasta", rating: 5 } });
|
|
485
478
|
|
|
486
479
|
expect(query).toContain("WHERE");
|
|
487
|
-
expect(query).toContain("count(->link[WHERE
|
|
488
|
-
expect(query).toContain("count(->link[WHERE
|
|
480
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
481
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://rating' AND fn::parse_literal(out.uri) = 5]) > 0");
|
|
489
482
|
expect(query).toContain("AND");
|
|
490
483
|
});
|
|
491
484
|
|
|
@@ -521,14 +514,14 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
521
514
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: { not: "Salad" } } });
|
|
522
515
|
|
|
523
516
|
// Not operator uses graph traversal with count = 0
|
|
524
|
-
expect(query).toContain("count(->link[WHERE
|
|
517
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Salad']) = 0");
|
|
525
518
|
});
|
|
526
519
|
|
|
527
520
|
it("should handle not operator with array (NOT IN)", async () => {
|
|
528
521
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: { not: ["Salad", "Soup"] } } });
|
|
529
522
|
|
|
530
523
|
// Not operator with array uses graph traversal with count = 0
|
|
531
|
-
expect(query).toContain("count(->link[WHERE
|
|
524
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) IN ['Salad', 'Soup']]) = 0");
|
|
532
525
|
});
|
|
533
526
|
|
|
534
527
|
it("should handle between operator (filtered in JavaScript, not SQL)", async () => {
|
|
@@ -564,8 +557,8 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
564
557
|
expect(query).not.toContain("SELECT source FROM node");
|
|
565
558
|
});
|
|
566
559
|
|
|
567
|
-
it.skip("should handle contains operator on special field (
|
|
568
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
560
|
+
it.skip("should handle contains operator on special field (id)", async () => {
|
|
561
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { contains: "test" } } });
|
|
569
562
|
|
|
570
563
|
expect(query).toContain("WHERE source CONTAINS 'test'");
|
|
571
564
|
});
|
|
@@ -573,7 +566,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
573
566
|
it("should handle array values (IN clause)", async () => {
|
|
574
567
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: ["Pasta", "Pizza"] } });
|
|
575
568
|
|
|
576
|
-
expect(query).toContain("count(->link[WHERE
|
|
569
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) IN ['Pasta', 'Pizza']]) > 0");
|
|
577
570
|
});
|
|
578
571
|
|
|
579
572
|
it.skip("should handle special fields (author, timestamp) without subqueries", async () => {
|
|
@@ -618,7 +611,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
618
611
|
|
|
619
612
|
// WHERE clause uses graph traversal filters
|
|
620
613
|
expect(query).toContain("WHERE");
|
|
621
|
-
expect(query).toContain("count(->link[WHERE
|
|
614
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
622
615
|
// Comparison operators (gt) are filtered in JavaScript, not SQL
|
|
623
616
|
expect(query).not.toContain("out.uri > 4");
|
|
624
617
|
expect(query).not.toContain("target > 4");
|
|
@@ -632,24 +625,24 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
632
625
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { properties: ["name"] });
|
|
633
626
|
|
|
634
627
|
// With array::group(), all link data is selected, filtering happens in instancesFromSurrealResult
|
|
635
|
-
expect(query).toContain("->link
|
|
628
|
+
expect(query).toContain("->link AS links");
|
|
636
629
|
|
|
637
630
|
});
|
|
638
631
|
|
|
639
|
-
it("should
|
|
640
|
-
@
|
|
641
|
-
class
|
|
642
|
-
@
|
|
632
|
+
it("should select all link data for relations", async () => {
|
|
633
|
+
@Model({ name: "MultiRelationModel" })
|
|
634
|
+
class MultiRelationModel extends Ad4mModel {
|
|
635
|
+
@HasMany({ through: "test://coll1" })
|
|
643
636
|
coll1: string[] = [];
|
|
644
637
|
|
|
645
|
-
@
|
|
638
|
+
@HasMany({ through: "test://coll2" })
|
|
646
639
|
coll2: string[] = [];
|
|
647
640
|
}
|
|
648
641
|
|
|
649
|
-
const query = await
|
|
642
|
+
const query = await MultiRelationModel.queryToSurrealQL(mockPerspective, {});
|
|
650
643
|
|
|
651
|
-
// With array::group(), all link data is selected
|
|
652
|
-
expect(query).toContain("->link
|
|
644
|
+
// With array::group(), all link data is selected
|
|
645
|
+
expect(query).toContain("->link AS links");
|
|
653
646
|
|
|
654
647
|
});
|
|
655
648
|
|
|
@@ -664,8 +657,8 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
664
657
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { rating: 5 } });
|
|
665
658
|
|
|
666
659
|
// Numeric values should not have quotes around them
|
|
667
|
-
expect(query).toContain("out.uri = 5");
|
|
668
|
-
expect(query).not.toContain("out.uri = '5'");
|
|
660
|
+
expect(query).toContain("fn::parse_literal(out.uri) = 5");
|
|
661
|
+
expect(query).not.toContain("fn::parse_literal(out.uri) = '5'");
|
|
669
662
|
});
|
|
670
663
|
|
|
671
664
|
it("should handle complex nested query (comparisons, ORDER BY, LIMIT handled in JS)", async () => {
|
|
@@ -682,7 +675,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
682
675
|
const normalized = normalizeQuery(query);
|
|
683
676
|
|
|
684
677
|
// Verify graph traversal filters are present
|
|
685
|
-
expect(normalized).toContain("count(->link[WHERE
|
|
678
|
+
expect(normalized).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
686
679
|
// Comparison operators (gte, lte) are filtered in JavaScript, not SQL
|
|
687
680
|
expect(normalized).not.toContain("out.uri >= 4");
|
|
688
681
|
expect(normalized).not.toContain("target >= 4");
|
|
@@ -709,51 +702,51 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
709
702
|
|
|
710
703
|
// Should have WHERE clause filtering for required properties using graph traversal
|
|
711
704
|
expect(query).toContain("WHERE");
|
|
712
|
-
expect(query).toContain("count(->link[WHERE
|
|
713
|
-
expect(query).toContain("count(->link[WHERE
|
|
705
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name']) > 0");
|
|
706
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://rating']) > 0");
|
|
714
707
|
expect(query).not.toContain("ORDER BY");
|
|
715
708
|
expect(query).not.toContain("START");
|
|
716
709
|
});
|
|
717
710
|
|
|
718
|
-
it("should handle
|
|
719
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
711
|
+
it("should handle id special field", async () => {
|
|
712
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: "literal://test" } });
|
|
720
713
|
|
|
721
714
|
expect(query).toContain("uri = 'literal://test'");
|
|
722
715
|
});
|
|
723
716
|
|
|
724
|
-
it("should handle
|
|
725
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
717
|
+
it("should handle id special field with array (IN clause)", async () => {
|
|
718
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: ["literal://test1", "literal://test2"] } });
|
|
726
719
|
|
|
727
720
|
expect(query).toContain("uri IN ['literal://test1', 'literal://test2']");
|
|
728
721
|
});
|
|
729
722
|
|
|
730
|
-
it("should handle
|
|
731
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
723
|
+
it("should handle id special field with not operator", async () => {
|
|
724
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { not: "literal://test" } } });
|
|
732
725
|
|
|
733
726
|
expect(query).toContain("uri != 'literal://test'");
|
|
734
727
|
});
|
|
735
728
|
|
|
736
|
-
it("should handle
|
|
737
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
729
|
+
it("should handle id special field with not operator and array (NOT IN)", async () => {
|
|
730
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { not: ["literal://test1", "literal://test2"] } } });
|
|
738
731
|
|
|
739
732
|
expect(query).toContain("uri NOT IN ['literal://test1', 'literal://test2']");
|
|
740
733
|
});
|
|
741
734
|
|
|
742
|
-
it("should handle
|
|
743
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
735
|
+
it("should handle id special field with between operator", async () => {
|
|
736
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { between: ["literal://a", "literal://z"] } } } as any);
|
|
744
737
|
|
|
745
738
|
const normalized = normalizeQuery(query);
|
|
746
739
|
expect(normalized).toContain("uri >= 'literal://a' AND uri <= 'literal://z'");
|
|
747
740
|
});
|
|
748
741
|
|
|
749
|
-
it("should handle
|
|
750
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
742
|
+
it("should handle id special field with gt operator", async () => {
|
|
743
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { gt: "literal://m" } } } as any);
|
|
751
744
|
|
|
752
745
|
expect(query).toContain("uri > 'literal://m'");
|
|
753
746
|
});
|
|
754
747
|
|
|
755
|
-
it("should handle
|
|
756
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
748
|
+
it("should handle id special field with gte and lte operators", async () => {
|
|
749
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { gte: "literal://a", lte: "literal://z" } } } as any);
|
|
757
750
|
|
|
758
751
|
const normalized = normalizeQuery(query);
|
|
759
752
|
expect(normalized).toContain("uri >= 'literal://a'");
|
|
@@ -793,7 +786,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
793
786
|
|
|
794
787
|
const normalized = normalizeQuery(query);
|
|
795
788
|
// Regular properties use graph traversal filters
|
|
796
|
-
expect(normalized).toContain("count(->link[WHERE
|
|
789
|
+
expect(normalized).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
797
790
|
// Comparison operators (gt) are filtered in JavaScript, not SQL
|
|
798
791
|
expect(normalized).not.toContain("out.uri > 4");
|
|
799
792
|
expect(normalized).not.toContain("target > 4");
|
|
@@ -802,7 +795,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
802
795
|
});
|
|
803
796
|
|
|
804
797
|
it("should handle boolean values", async () => {
|
|
805
|
-
@
|
|
798
|
+
@Model({ name: "Task" })
|
|
806
799
|
class Task extends Ad4mModel {
|
|
807
800
|
@Property({ through: "task://completed" })
|
|
808
801
|
completed: boolean = false;
|
|
@@ -810,13 +803,13 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
810
803
|
|
|
811
804
|
const query = await Task.queryToSurrealQL(mockPerspective, { where: { completed: true } });
|
|
812
805
|
|
|
813
|
-
expect(query).toContain("out.uri = true");
|
|
806
|
+
expect(query).toContain("fn::parse_literal(out.uri) = true");
|
|
814
807
|
});
|
|
815
808
|
|
|
816
809
|
it("should handle array of numbers", async () => {
|
|
817
810
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { rating: [4, 5] } });
|
|
818
811
|
|
|
819
|
-
expect(query).toContain("count(->link[WHERE
|
|
812
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://rating' AND fn::parse_literal(out.uri) IN [4, 5]]) > 0");
|
|
820
813
|
});
|
|
821
814
|
|
|
822
815
|
it("should skip unknown properties in where clause", async () => {
|
|
@@ -846,26 +839,18 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
846
839
|
expect(query).not.toContain("ORDER BY");
|
|
847
840
|
});
|
|
848
841
|
|
|
849
|
-
it("should generate query with only properties
|
|
850
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { properties: ["name", "rating"]
|
|
842
|
+
it("should generate query with only properties specified", async () => {
|
|
843
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { properties: ["name", "rating"] });
|
|
851
844
|
|
|
852
845
|
// With array::group(), all link data is selected, filtering happens in instancesFromSurrealResult
|
|
853
|
-
expect(query).toContain("->link
|
|
854
|
-
|
|
855
|
-
});
|
|
856
|
-
|
|
857
|
-
it("should generate query with only collections, no properties", async () => {
|
|
858
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { properties: [], collections: ["ingredients"] });
|
|
859
|
-
|
|
860
|
-
// With array::group(), all link data is selected, filtering happens in instancesFromSurrealResult
|
|
861
|
-
expect(query).toContain("->link[WHERE perspective = $perspective] AS links");
|
|
846
|
+
expect(query).toContain("->link AS links");
|
|
862
847
|
|
|
863
848
|
});
|
|
864
849
|
});
|
|
865
850
|
|
|
866
851
|
describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", () => {
|
|
867
852
|
// Test Recipe model
|
|
868
|
-
@
|
|
853
|
+
@Model({ name: "Recipe" })
|
|
869
854
|
class Recipe extends Ad4mModel {
|
|
870
855
|
@Property({ through: "recipe://name" })
|
|
871
856
|
name: string = "";
|
|
@@ -873,7 +858,7 @@ describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", ()
|
|
|
873
858
|
@Property({ through: "recipe://rating" })
|
|
874
859
|
rating: number = 0;
|
|
875
860
|
|
|
876
|
-
@
|
|
861
|
+
@HasMany({ through: "recipe://ingredient" })
|
|
877
862
|
ingredients: string[] = [];
|
|
878
863
|
}
|
|
879
864
|
|
|
@@ -965,13 +950,12 @@ describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", ()
|
|
|
965
950
|
// rating and ingredients should be removed since only "name" was requested
|
|
966
951
|
expect(recipe.rating).toBeUndefined();
|
|
967
952
|
expect(recipe.ingredients).toBeUndefined();
|
|
968
|
-
// author
|
|
969
|
-
expect(recipe.author).
|
|
970
|
-
|
|
971
|
-
expect(recipe.timestamp).toBe(new Date("2023-01-01T00:00:00Z").getTime());
|
|
953
|
+
// author, createdAt, updatedAt are also stripped unless explicitly requested
|
|
954
|
+
expect(recipe.author).toBeUndefined();
|
|
955
|
+
expect(recipe.timestamp).toBeUndefined();
|
|
972
956
|
});
|
|
973
957
|
|
|
974
|
-
it("should filter
|
|
958
|
+
it("should filter properties when query specifies properties", async () => {
|
|
975
959
|
const surrealResults = [
|
|
976
960
|
{
|
|
977
961
|
source: "node:abc123",
|
|
@@ -987,15 +971,14 @@ describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", ()
|
|
|
987
971
|
|
|
988
972
|
const result = await Recipe.instancesFromSurrealResult(
|
|
989
973
|
mockPerspective,
|
|
990
|
-
{
|
|
974
|
+
{ properties: ["name"] },
|
|
991
975
|
surrealResults
|
|
992
976
|
);
|
|
993
977
|
|
|
994
978
|
expect(result.results).toHaveLength(1);
|
|
995
979
|
const recipe = result.results[0];
|
|
996
|
-
expect(recipe.
|
|
997
|
-
//
|
|
998
|
-
expect(recipe.name).toBeUndefined();
|
|
980
|
+
expect(recipe.name).toBe("Pasta");
|
|
981
|
+
// rating and ingredients should be removed since only "name" was requested
|
|
999
982
|
expect(recipe.rating).toBeUndefined();
|
|
1000
983
|
});
|
|
1001
984
|
|
|
@@ -1231,7 +1214,7 @@ describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", ()
|
|
|
1231
1214
|
|
|
1232
1215
|
describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
1233
1216
|
// Test Recipe model
|
|
1234
|
-
@
|
|
1217
|
+
@Model({ name: "Recipe" })
|
|
1235
1218
|
class Recipe extends Ad4mModel {
|
|
1236
1219
|
@Property({ through: "recipe://name" })
|
|
1237
1220
|
name: string = "";
|
|
@@ -1239,7 +1222,7 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
1239
1222
|
@Property({ through: "recipe://rating" })
|
|
1240
1223
|
rating: number = 0;
|
|
1241
1224
|
|
|
1242
|
-
@
|
|
1225
|
+
@HasMany({ through: "recipe://ingredient" })
|
|
1243
1226
|
ingredients: string[] = [];
|
|
1244
1227
|
}
|
|
1245
1228
|
|