@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
|
@@ -8,18 +8,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Ad4mModel } from "./Ad4mModel";
|
|
11
|
-
import {
|
|
11
|
+
import { Model, Property, Optional, ReadOnly, HasMany, Flag } from "./decorators";
|
|
12
12
|
describe("Ad4mModel.getModelMetadata()", () => {
|
|
13
13
|
it("should extract basic model metadata with className", () => {
|
|
14
14
|
let SimpleModel = class SimpleModel extends Ad4mModel {
|
|
15
15
|
};
|
|
16
16
|
SimpleModel = __decorate([
|
|
17
|
-
|
|
17
|
+
Model({ name: "SimpleModel" })
|
|
18
18
|
], SimpleModel);
|
|
19
19
|
const metadata = SimpleModel.getModelMetadata();
|
|
20
20
|
expect(metadata.className).toBe("SimpleModel");
|
|
21
21
|
expect(metadata.properties).toEqual({});
|
|
22
|
-
expect(metadata.
|
|
22
|
+
expect(metadata.relations).toEqual({});
|
|
23
23
|
});
|
|
24
24
|
it("should extract property metadata with all fields", () => {
|
|
25
25
|
let PropertyModel = class PropertyModel extends Ad4mModel {
|
|
@@ -36,7 +36,7 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
36
36
|
__metadata("design:type", String)
|
|
37
37
|
], PropertyModel.prototype, "name", void 0);
|
|
38
38
|
__decorate([
|
|
39
|
-
Optional({ through: "test://optional"
|
|
39
|
+
Optional({ through: "test://optional" }),
|
|
40
40
|
__metadata("design:type", String)
|
|
41
41
|
], PropertyModel.prototype, "optional", void 0);
|
|
42
42
|
__decorate([
|
|
@@ -48,67 +48,55 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
48
48
|
__metadata("design:type", String)
|
|
49
49
|
], PropertyModel.prototype, "type", void 0);
|
|
50
50
|
PropertyModel = __decorate([
|
|
51
|
-
|
|
51
|
+
Model({ name: "PropertyModel" })
|
|
52
52
|
], PropertyModel);
|
|
53
53
|
const metadata = PropertyModel.getModelMetadata();
|
|
54
54
|
// Should have 4 properties
|
|
55
55
|
expect(Object.keys(metadata.properties)).toHaveLength(4);
|
|
56
56
|
// Verify "name" property
|
|
57
57
|
expect(metadata.properties.name.predicate).toBe("test://name");
|
|
58
|
-
expect(metadata.properties.name.required).toBe(
|
|
59
|
-
expect(metadata.properties.name.
|
|
58
|
+
expect(metadata.properties.name.required).toBe(false);
|
|
59
|
+
expect(metadata.properties.name.readOnly).toBe(false);
|
|
60
60
|
expect(metadata.properties.name.resolveLanguage).toBe("literal");
|
|
61
61
|
// Verify "optional" property
|
|
62
62
|
expect(metadata.properties.optional.predicate).toBe("test://optional");
|
|
63
|
-
expect(metadata.properties.optional.
|
|
63
|
+
expect(metadata.properties.optional.readOnly).toBe(false);
|
|
64
64
|
// Verify "readonly" property
|
|
65
65
|
expect(metadata.properties.readonly.predicate).toBe("test://readonly");
|
|
66
|
-
expect(metadata.properties.readonly.
|
|
66
|
+
expect(metadata.properties.readonly.readOnly).toBe(true);
|
|
67
67
|
expect(metadata.properties.readonly.prologGetter).toBe("custom_getter");
|
|
68
68
|
// Verify "type" property (flag)
|
|
69
69
|
expect(metadata.properties.type.predicate).toBe("test://type");
|
|
70
70
|
expect(metadata.properties.type.flag).toBe(true);
|
|
71
71
|
expect(metadata.properties.type.initial).toBe("test://flag");
|
|
72
72
|
});
|
|
73
|
-
it("should extract
|
|
74
|
-
let
|
|
73
|
+
it("should extract relation metadata with various options", () => {
|
|
74
|
+
let RelationModel = class RelationModel extends Ad4mModel {
|
|
75
75
|
constructor() {
|
|
76
76
|
super(...arguments);
|
|
77
77
|
this.items = [];
|
|
78
|
-
this.filtered = [];
|
|
79
78
|
this.local = [];
|
|
80
79
|
}
|
|
81
80
|
};
|
|
82
81
|
__decorate([
|
|
83
|
-
|
|
84
|
-
__metadata("design:type", Array)
|
|
85
|
-
], CollectionModel.prototype, "items", void 0);
|
|
86
|
-
__decorate([
|
|
87
|
-
Collection({
|
|
88
|
-
through: "test://filtered",
|
|
89
|
-
where: { condition: "triple(Target, 'test://active', 'true')" }
|
|
90
|
-
}),
|
|
82
|
+
HasMany({ through: "test://items" }),
|
|
91
83
|
__metadata("design:type", Array)
|
|
92
|
-
],
|
|
84
|
+
], RelationModel.prototype, "items", void 0);
|
|
93
85
|
__decorate([
|
|
94
|
-
|
|
86
|
+
HasMany({ through: "test://local", local: true }),
|
|
95
87
|
__metadata("design:type", Array)
|
|
96
|
-
],
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
],
|
|
100
|
-
const metadata =
|
|
101
|
-
// Should have
|
|
102
|
-
expect(Object.keys(metadata.
|
|
103
|
-
// Verify "items"
|
|
104
|
-
expect(metadata.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
expect(metadata.
|
|
108
|
-
expect(metadata.collections.filtered.where?.condition).toBe("triple(Target, 'test://active', 'true')");
|
|
109
|
-
// Verify "local" collection
|
|
110
|
-
expect(metadata.collections.local.predicate).toBe("test://local");
|
|
111
|
-
expect(metadata.collections.local.local).toBe(true);
|
|
88
|
+
], RelationModel.prototype, "local", void 0);
|
|
89
|
+
RelationModel = __decorate([
|
|
90
|
+
Model({ name: "RelationModel" })
|
|
91
|
+
], RelationModel);
|
|
92
|
+
const metadata = RelationModel.getModelMetadata();
|
|
93
|
+
// Should have 2 relations
|
|
94
|
+
expect(Object.keys(metadata.relations)).toHaveLength(2);
|
|
95
|
+
// Verify "items" relation
|
|
96
|
+
expect(metadata.relations.items.predicate).toBe("test://items");
|
|
97
|
+
// Verify "local" relation
|
|
98
|
+
expect(metadata.relations.local.predicate).toBe("test://local");
|
|
99
|
+
expect(metadata.relations.local.local).toBe(true);
|
|
112
100
|
});
|
|
113
101
|
it("should extract transform function from property metadata", () => {
|
|
114
102
|
let TransformModel = class TransformModel extends Ad4mModel {
|
|
@@ -125,7 +113,7 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
125
113
|
__metadata("design:type", String)
|
|
126
114
|
], TransformModel.prototype, "data", void 0);
|
|
127
115
|
TransformModel = __decorate([
|
|
128
|
-
|
|
116
|
+
Model({ name: "TransformModel" })
|
|
129
117
|
], TransformModel);
|
|
130
118
|
const metadata = TransformModel.getModelMetadata();
|
|
131
119
|
// Assert transform is a function
|
|
@@ -150,7 +138,7 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
150
138
|
__metadata("design:type", Number)
|
|
151
139
|
], CustomModel.prototype, "computed", void 0);
|
|
152
140
|
CustomModel = __decorate([
|
|
153
|
-
|
|
141
|
+
Model({ name: "CustomModel" })
|
|
154
142
|
], CustomModel);
|
|
155
143
|
const metadata = CustomModel.getModelMetadata();
|
|
156
144
|
// Assert prologGetter and prologSetter contain the custom code
|
|
@@ -158,11 +146,11 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
158
146
|
expect(metadata.properties.computed.prologSetter).toContain("Value is V / 2");
|
|
159
147
|
expect(metadata.properties.computed.prologSetter).toContain("setSingleTarget");
|
|
160
148
|
});
|
|
161
|
-
it("should handle
|
|
149
|
+
it("should handle relation with typed target relation", () => {
|
|
162
150
|
let Comment = class Comment extends Ad4mModel {
|
|
163
151
|
};
|
|
164
152
|
Comment = __decorate([
|
|
165
|
-
|
|
153
|
+
Model({ name: "Comment" })
|
|
166
154
|
], Comment);
|
|
167
155
|
let Post = class Post extends Ad4mModel {
|
|
168
156
|
constructor() {
|
|
@@ -171,26 +159,27 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
171
159
|
}
|
|
172
160
|
};
|
|
173
161
|
__decorate([
|
|
174
|
-
|
|
162
|
+
HasMany({
|
|
175
163
|
through: "post://comment",
|
|
176
|
-
|
|
164
|
+
target: () => Comment
|
|
177
165
|
}),
|
|
178
166
|
__metadata("design:type", Array)
|
|
179
167
|
], Post.prototype, "comments", void 0);
|
|
180
168
|
Post = __decorate([
|
|
181
|
-
|
|
169
|
+
Model({ name: "Post" })
|
|
182
170
|
], Post);
|
|
183
171
|
const metadata = Post.getModelMetadata();
|
|
184
|
-
// Assert
|
|
185
|
-
expect(metadata.
|
|
172
|
+
// Assert relation exists with correct predicate
|
|
173
|
+
expect(metadata.relations.comments).toBeDefined();
|
|
174
|
+
expect(metadata.relations.comments.predicate).toBe("post://comment");
|
|
186
175
|
});
|
|
187
|
-
it("should throw error for class without @
|
|
176
|
+
it("should throw error for class without @Model decorator", () => {
|
|
188
177
|
class NoDecoratorModel extends Ad4mModel {
|
|
189
178
|
}
|
|
190
179
|
// Assert that calling getModelMetadata throws an error
|
|
191
|
-
expect(() => NoDecoratorModel.getModelMetadata()).toThrow("Model class must be decorated with @
|
|
180
|
+
expect(() => NoDecoratorModel.getModelMetadata()).toThrow("Model class must be decorated with @Model");
|
|
192
181
|
});
|
|
193
|
-
it("should handle complex model with mixed property and
|
|
182
|
+
it("should handle complex model with mixed property and relation types", () => {
|
|
194
183
|
let Recipe = class Recipe extends Ad4mModel {
|
|
195
184
|
constructor() {
|
|
196
185
|
super(...arguments);
|
|
@@ -214,15 +203,15 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
214
203
|
__metadata("design:type", Number)
|
|
215
204
|
], Recipe.prototype, "rating", void 0);
|
|
216
205
|
__decorate([
|
|
217
|
-
|
|
206
|
+
HasMany({ through: "recipe://ingredient" }),
|
|
218
207
|
__metadata("design:type", Array)
|
|
219
208
|
], Recipe.prototype, "ingredients", void 0);
|
|
220
209
|
__decorate([
|
|
221
|
-
|
|
210
|
+
HasMany({ through: "recipe://step", local: true }),
|
|
222
211
|
__metadata("design:type", Array)
|
|
223
212
|
], Recipe.prototype, "steps", void 0);
|
|
224
213
|
Recipe = __decorate([
|
|
225
|
-
|
|
214
|
+
Model({ name: "Recipe" })
|
|
226
215
|
], Recipe);
|
|
227
216
|
const metadata = Recipe.getModelMetadata();
|
|
228
217
|
// Assert className
|
|
@@ -232,19 +221,19 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
232
221
|
expect(metadata.properties.name).toBeDefined();
|
|
233
222
|
expect(metadata.properties.description).toBeDefined();
|
|
234
223
|
expect(metadata.properties.rating).toBeDefined();
|
|
235
|
-
// Assert
|
|
236
|
-
expect(Object.keys(metadata.
|
|
237
|
-
expect(metadata.
|
|
238
|
-
expect(metadata.
|
|
224
|
+
// Assert relations has 2 entries
|
|
225
|
+
expect(Object.keys(metadata.relations)).toHaveLength(2);
|
|
226
|
+
expect(metadata.relations.ingredients).toBeDefined();
|
|
227
|
+
expect(metadata.relations.steps).toBeDefined();
|
|
239
228
|
// Verify all metadata fields are correctly extracted
|
|
240
229
|
expect(metadata.properties.name.predicate).toBe("recipe://name");
|
|
241
230
|
expect(metadata.properties.name.resolveLanguage).toBe("literal");
|
|
242
231
|
expect(metadata.properties.description.predicate).toBe("recipe://description");
|
|
243
232
|
expect(metadata.properties.rating.predicate).toBe("recipe://rating");
|
|
244
233
|
expect(metadata.properties.rating.prologGetter).toBe("avg_rating(Base, Value)");
|
|
245
|
-
expect(metadata.
|
|
246
|
-
expect(metadata.
|
|
247
|
-
expect(metadata.
|
|
234
|
+
expect(metadata.relations.ingredients.predicate).toBe("recipe://ingredient");
|
|
235
|
+
expect(metadata.relations.steps.predicate).toBe("recipe://step");
|
|
236
|
+
expect(metadata.relations.steps.local).toBe(true);
|
|
248
237
|
});
|
|
249
238
|
});
|
|
250
239
|
describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
@@ -272,7 +261,7 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
272
261
|
expect(metadata.properties.name).toBeDefined();
|
|
273
262
|
expect(metadata.properties.name.predicate).toBe("product://name");
|
|
274
263
|
expect(metadata.properties.name.required).toBe(true);
|
|
275
|
-
expect(metadata.properties.name.
|
|
264
|
+
expect(metadata.properties.name.readOnly).toBe(false);
|
|
276
265
|
expect(metadata.properties.name.resolveLanguage).toBe("literal");
|
|
277
266
|
expect(metadata.properties.price).toBeDefined();
|
|
278
267
|
expect(metadata.properties.price.predicate).toBe("product://price");
|
|
@@ -282,7 +271,7 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
282
271
|
expect(metadata.properties.description.predicate).toBe("product://description");
|
|
283
272
|
expect(metadata.properties.description.required).toBe(false);
|
|
284
273
|
});
|
|
285
|
-
it("should extract
|
|
274
|
+
it("should extract relations from a model created via fromJSONSchema with arrays", () => {
|
|
286
275
|
const schema = {
|
|
287
276
|
title: "Post",
|
|
288
277
|
type: "object",
|
|
@@ -306,12 +295,12 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
306
295
|
const metadata = PostClass.getModelMetadata();
|
|
307
296
|
// Verify className
|
|
308
297
|
expect(metadata.className).toBe("Post");
|
|
309
|
-
// Verify
|
|
310
|
-
expect(Object.keys(metadata.
|
|
311
|
-
expect(metadata.
|
|
312
|
-
expect(metadata.
|
|
313
|
-
expect(metadata.
|
|
314
|
-
expect(metadata.
|
|
298
|
+
// Verify relations are extracted
|
|
299
|
+
expect(Object.keys(metadata.relations).length).toBeGreaterThan(0);
|
|
300
|
+
expect(metadata.relations.tags).toBeDefined();
|
|
301
|
+
expect(metadata.relations.tags.predicate).toBe("post://tags");
|
|
302
|
+
expect(metadata.relations.comments).toBeDefined();
|
|
303
|
+
expect(metadata.relations.comments.predicate).toBe("post://comments");
|
|
315
304
|
// Verify properties (should include at least title)
|
|
316
305
|
expect(metadata.properties.title).toBeDefined();
|
|
317
306
|
expect(metadata.properties.title.predicate).toBe("post://title");
|
|
@@ -350,7 +339,7 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
350
339
|
// Verify x-ad4m metadata is respected
|
|
351
340
|
expect(metadata.properties.name.predicate).toBe("foaf://name");
|
|
352
341
|
expect(metadata.properties.name.resolveLanguage).toBe("literal");
|
|
353
|
-
expect(metadata.properties.name.
|
|
342
|
+
expect(metadata.properties.name.readOnly).toBe(false);
|
|
354
343
|
expect(metadata.properties.name.required).toBe(true);
|
|
355
344
|
expect(metadata.properties.email.predicate).toBe("foaf://mbox");
|
|
356
345
|
expect(metadata.properties.email.local).toBe(true);
|
|
@@ -419,14 +408,14 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
419
408
|
expect(metadata.properties.published).toBeDefined();
|
|
420
409
|
expect(metadata.properties.published.predicate).toBe("article://published");
|
|
421
410
|
expect(metadata.properties.published.required).toBe(true);
|
|
422
|
-
// Verify
|
|
423
|
-
expect(metadata.
|
|
424
|
-
expect(metadata.
|
|
425
|
-
expect(metadata.
|
|
426
|
-
expect(metadata.
|
|
427
|
-
expect(metadata.
|
|
428
|
-
});
|
|
429
|
-
it("should handle models with
|
|
411
|
+
// Verify relations
|
|
412
|
+
expect(metadata.relations.authors).toBeDefined();
|
|
413
|
+
expect(metadata.relations.authors.predicate).toBe("article://authors");
|
|
414
|
+
expect(metadata.relations.tags).toBeDefined();
|
|
415
|
+
expect(metadata.relations.tags.predicate).toBe("article://tags");
|
|
416
|
+
expect(metadata.relations.tags.local).toBe(true);
|
|
417
|
+
});
|
|
418
|
+
it("should handle models with no properties (open-world, no auto-flag)", () => {
|
|
430
419
|
const schema = {
|
|
431
420
|
title: "EmptyModel",
|
|
432
421
|
type: "object",
|
|
@@ -439,11 +428,13 @@ describe("Ad4mModel.fromJSONSchema() with getModelMetadata()", () => {
|
|
|
439
428
|
const metadata = EmptyModelClass.getModelMetadata();
|
|
440
429
|
// Should have className
|
|
441
430
|
expect(metadata.className).toBe("EmptyModel");
|
|
442
|
-
// Should have
|
|
443
|
-
|
|
444
|
-
expect(metadata.properties.__ad4m_type
|
|
445
|
-
|
|
446
|
-
|
|
431
|
+
// Should NOT have an auto-generated __ad4m_type property —
|
|
432
|
+
// models with all-optional properties use open-world structural matching.
|
|
433
|
+
expect(metadata.properties.__ad4m_type).toBeUndefined();
|
|
434
|
+
// SHACL shape should still be valid with empty constructor/destructor
|
|
435
|
+
const { shape } = EmptyModelClass.generateSHACL();
|
|
436
|
+
expect(shape.constructor_actions).toEqual([]);
|
|
437
|
+
expect(shape.destructor_actions).toEqual([]);
|
|
447
438
|
});
|
|
448
439
|
});
|
|
449
440
|
describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
@@ -453,7 +444,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
453
444
|
function normalizeQuery(query) {
|
|
454
445
|
return query.replace(/\s+/g, ' ').trim();
|
|
455
446
|
}
|
|
456
|
-
// Test Recipe model
|
|
447
|
+
// Test Recipe model — explicit required: true to test required-property query filters
|
|
457
448
|
let Recipe = class Recipe extends Ad4mModel {
|
|
458
449
|
constructor() {
|
|
459
450
|
super(...arguments);
|
|
@@ -463,26 +454,26 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
463
454
|
}
|
|
464
455
|
};
|
|
465
456
|
__decorate([
|
|
466
|
-
Property({ through: "recipe://name" }),
|
|
457
|
+
Property({ through: "recipe://name", required: true }),
|
|
467
458
|
__metadata("design:type", String)
|
|
468
459
|
], Recipe.prototype, "name", void 0);
|
|
469
460
|
__decorate([
|
|
470
|
-
Property({ through: "recipe://rating" }),
|
|
461
|
+
Property({ through: "recipe://rating", required: true }),
|
|
471
462
|
__metadata("design:type", Number)
|
|
472
463
|
], Recipe.prototype, "rating", void 0);
|
|
473
464
|
__decorate([
|
|
474
|
-
|
|
465
|
+
HasMany({ through: "recipe://ingredient" }),
|
|
475
466
|
__metadata("design:type", Array)
|
|
476
467
|
], Recipe.prototype, "ingredients", void 0);
|
|
477
468
|
Recipe = __decorate([
|
|
478
|
-
|
|
469
|
+
Model({ name: "Recipe" })
|
|
479
470
|
], Recipe);
|
|
480
471
|
it("should generate basic query with no filters", async () => {
|
|
481
472
|
const query = await Recipe.queryToSurrealQL(mockPerspective, {});
|
|
482
473
|
expect(query).toContain("id AS source");
|
|
483
474
|
expect(query).toContain("uri AS source_uri");
|
|
484
475
|
expect(query).toContain("FROM node");
|
|
485
|
-
expect(query).toContain("->link
|
|
476
|
+
expect(query).toContain("->link AS links");
|
|
486
477
|
expect(query).toContain("WHERE");
|
|
487
478
|
// Should have graph traversal filters for required properties
|
|
488
479
|
expect(query).toContain("count(->link[WHERE");
|
|
@@ -490,15 +481,15 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
490
481
|
it("should generate query with simple property filter", async () => {
|
|
491
482
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: "Pasta" } });
|
|
492
483
|
// Should have graph traversal filters for required properties and user filter
|
|
493
|
-
expect(query).toContain("count(->link[WHERE
|
|
494
|
-
expect(query).toContain("count(->link[WHERE
|
|
495
|
-
expect(query).toContain("count(->link[WHERE
|
|
484
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name']) > 0");
|
|
485
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://rating']) > 0");
|
|
486
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
496
487
|
});
|
|
497
488
|
it("should generate query with multiple property filters", async () => {
|
|
498
489
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: "Pasta", rating: 5 } });
|
|
499
490
|
expect(query).toContain("WHERE");
|
|
500
|
-
expect(query).toContain("count(->link[WHERE
|
|
501
|
-
expect(query).toContain("count(->link[WHERE
|
|
491
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
492
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://rating' AND fn::parse_literal(out.uri) = 5]) > 0");
|
|
502
493
|
expect(query).toContain("AND");
|
|
503
494
|
});
|
|
504
495
|
it("should handle gt operator (filtered in JavaScript, not SQL)", async () => {
|
|
@@ -525,12 +516,12 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
525
516
|
it("should handle not operator with single value", async () => {
|
|
526
517
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: { not: "Salad" } } });
|
|
527
518
|
// Not operator uses graph traversal with count = 0
|
|
528
|
-
expect(query).toContain("count(->link[WHERE
|
|
519
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Salad']) = 0");
|
|
529
520
|
});
|
|
530
521
|
it("should handle not operator with array (NOT IN)", async () => {
|
|
531
522
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: { not: ["Salad", "Soup"] } } });
|
|
532
523
|
// Not operator with array uses graph traversal with count = 0
|
|
533
|
-
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");
|
|
534
525
|
});
|
|
535
526
|
it("should handle between operator (filtered in JavaScript, not SQL)", async () => {
|
|
536
527
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { rating: { between: [3, 5] } } });
|
|
@@ -557,13 +548,13 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
557
548
|
// Should not use a subquery pattern
|
|
558
549
|
expect(query).not.toContain("SELECT source FROM node");
|
|
559
550
|
});
|
|
560
|
-
it.skip("should handle contains operator on special field (
|
|
561
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
551
|
+
it.skip("should handle contains operator on special field (id)", async () => {
|
|
552
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { contains: "test" } } });
|
|
562
553
|
expect(query).toContain("WHERE source CONTAINS 'test'");
|
|
563
554
|
});
|
|
564
555
|
it("should handle array values (IN clause)", async () => {
|
|
565
556
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: ["Pasta", "Pizza"] } });
|
|
566
|
-
expect(query).toContain("count(->link[WHERE
|
|
557
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) IN ['Pasta', 'Pizza']]) > 0");
|
|
567
558
|
});
|
|
568
559
|
it.skip("should handle special fields (author, timestamp) without subqueries", async () => {
|
|
569
560
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { author: "did:key:alice" } });
|
|
@@ -598,7 +589,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
598
589
|
});
|
|
599
590
|
// WHERE clause uses graph traversal filters
|
|
600
591
|
expect(query).toContain("WHERE");
|
|
601
|
-
expect(query).toContain("count(->link[WHERE
|
|
592
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
602
593
|
// Comparison operators (gt) are filtered in JavaScript, not SQL
|
|
603
594
|
expect(query).not.toContain("out.uri > 4");
|
|
604
595
|
expect(query).not.toContain("target > 4");
|
|
@@ -610,10 +601,10 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
610
601
|
it("should only select requested properties", async () => {
|
|
611
602
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { properties: ["name"] });
|
|
612
603
|
// With array::group(), all link data is selected, filtering happens in instancesFromSurrealResult
|
|
613
|
-
expect(query).toContain("->link
|
|
604
|
+
expect(query).toContain("->link AS links");
|
|
614
605
|
});
|
|
615
|
-
it("should
|
|
616
|
-
let
|
|
606
|
+
it("should select all link data for relations", async () => {
|
|
607
|
+
let MultiRelationModel = class MultiRelationModel extends Ad4mModel {
|
|
617
608
|
constructor() {
|
|
618
609
|
super(...arguments);
|
|
619
610
|
this.coll1 = [];
|
|
@@ -621,19 +612,19 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
621
612
|
}
|
|
622
613
|
};
|
|
623
614
|
__decorate([
|
|
624
|
-
|
|
615
|
+
HasMany({ through: "test://coll1" }),
|
|
625
616
|
__metadata("design:type", Array)
|
|
626
|
-
],
|
|
617
|
+
], MultiRelationModel.prototype, "coll1", void 0);
|
|
627
618
|
__decorate([
|
|
628
|
-
|
|
619
|
+
HasMany({ through: "test://coll2" }),
|
|
629
620
|
__metadata("design:type", Array)
|
|
630
|
-
],
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
],
|
|
634
|
-
const query = await
|
|
635
|
-
// With array::group(), all link data is selected
|
|
636
|
-
expect(query).toContain("->link
|
|
621
|
+
], MultiRelationModel.prototype, "coll2", void 0);
|
|
622
|
+
MultiRelationModel = __decorate([
|
|
623
|
+
Model({ name: "MultiRelationModel" })
|
|
624
|
+
], MultiRelationModel);
|
|
625
|
+
const query = await MultiRelationModel.queryToSurrealQL(mockPerspective, {});
|
|
626
|
+
// With array::group(), all link data is selected
|
|
627
|
+
expect(query).toContain("->link AS links");
|
|
637
628
|
});
|
|
638
629
|
it("should escape single quotes in string values", async () => {
|
|
639
630
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { name: "O'Brien's Recipe" } });
|
|
@@ -643,8 +634,8 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
643
634
|
it("should handle numeric values without quotes", async () => {
|
|
644
635
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { rating: 5 } });
|
|
645
636
|
// Numeric values should not have quotes around them
|
|
646
|
-
expect(query).toContain("out.uri = 5");
|
|
647
|
-
expect(query).not.toContain("out.uri = '5'");
|
|
637
|
+
expect(query).toContain("fn::parse_literal(out.uri) = 5");
|
|
638
|
+
expect(query).not.toContain("fn::parse_literal(out.uri) = '5'");
|
|
648
639
|
});
|
|
649
640
|
it("should handle complex nested query (comparisons, ORDER BY, LIMIT handled in JS)", async () => {
|
|
650
641
|
const query = await Recipe.queryToSurrealQL(mockPerspective, {
|
|
@@ -658,7 +649,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
658
649
|
});
|
|
659
650
|
const normalized = normalizeQuery(query);
|
|
660
651
|
// Verify graph traversal filters are present
|
|
661
|
-
expect(normalized).toContain("count(->link[WHERE
|
|
652
|
+
expect(normalized).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
662
653
|
// Comparison operators (gte, lte) are filtered in JavaScript, not SQL
|
|
663
654
|
expect(normalized).not.toContain("out.uri >= 4");
|
|
664
655
|
expect(normalized).not.toContain("target >= 4");
|
|
@@ -680,38 +671,38 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
680
671
|
expect(query).toContain("FROM node");
|
|
681
672
|
// Should have WHERE clause filtering for required properties using graph traversal
|
|
682
673
|
expect(query).toContain("WHERE");
|
|
683
|
-
expect(query).toContain("count(->link[WHERE
|
|
684
|
-
expect(query).toContain("count(->link[WHERE
|
|
674
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://name']) > 0");
|
|
675
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://rating']) > 0");
|
|
685
676
|
expect(query).not.toContain("ORDER BY");
|
|
686
677
|
expect(query).not.toContain("START");
|
|
687
678
|
});
|
|
688
|
-
it("should handle
|
|
689
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
679
|
+
it("should handle id special field", async () => {
|
|
680
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: "literal://test" } });
|
|
690
681
|
expect(query).toContain("uri = 'literal://test'");
|
|
691
682
|
});
|
|
692
|
-
it("should handle
|
|
693
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
683
|
+
it("should handle id special field with array (IN clause)", async () => {
|
|
684
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: ["literal://test1", "literal://test2"] } });
|
|
694
685
|
expect(query).toContain("uri IN ['literal://test1', 'literal://test2']");
|
|
695
686
|
});
|
|
696
|
-
it("should handle
|
|
697
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
687
|
+
it("should handle id special field with not operator", async () => {
|
|
688
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { not: "literal://test" } } });
|
|
698
689
|
expect(query).toContain("uri != 'literal://test'");
|
|
699
690
|
});
|
|
700
|
-
it("should handle
|
|
701
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
691
|
+
it("should handle id special field with not operator and array (NOT IN)", async () => {
|
|
692
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { not: ["literal://test1", "literal://test2"] } } });
|
|
702
693
|
expect(query).toContain("uri NOT IN ['literal://test1', 'literal://test2']");
|
|
703
694
|
});
|
|
704
|
-
it("should handle
|
|
705
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
695
|
+
it("should handle id special field with between operator", async () => {
|
|
696
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { between: ["literal://a", "literal://z"] } } });
|
|
706
697
|
const normalized = normalizeQuery(query);
|
|
707
698
|
expect(normalized).toContain("uri >= 'literal://a' AND uri <= 'literal://z'");
|
|
708
699
|
});
|
|
709
|
-
it("should handle
|
|
710
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
700
|
+
it("should handle id special field with gt operator", async () => {
|
|
701
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { gt: "literal://m" } } });
|
|
711
702
|
expect(query).toContain("uri > 'literal://m'");
|
|
712
703
|
});
|
|
713
|
-
it("should handle
|
|
714
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: {
|
|
704
|
+
it("should handle id special field with gte and lte operators", async () => {
|
|
705
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { id: { gte: "literal://a", lte: "literal://z" } } });
|
|
715
706
|
const normalized = normalizeQuery(query);
|
|
716
707
|
expect(normalized).toContain("uri >= 'literal://a'");
|
|
717
708
|
expect(normalized).toContain("uri <= 'literal://z'");
|
|
@@ -744,7 +735,7 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
744
735
|
});
|
|
745
736
|
const normalized = normalizeQuery(query);
|
|
746
737
|
// Regular properties use graph traversal filters
|
|
747
|
-
expect(normalized).toContain("count(->link[WHERE
|
|
738
|
+
expect(normalized).toContain("count(->link[WHERE predicate = 'recipe://name' AND fn::parse_literal(out.uri) = 'Pasta']) > 0");
|
|
748
739
|
// Comparison operators (gt) are filtered in JavaScript, not SQL
|
|
749
740
|
expect(normalized).not.toContain("out.uri > 4");
|
|
750
741
|
expect(normalized).not.toContain("target > 4");
|
|
@@ -763,14 +754,14 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
763
754
|
__metadata("design:type", Boolean)
|
|
764
755
|
], Task.prototype, "completed", void 0);
|
|
765
756
|
Task = __decorate([
|
|
766
|
-
|
|
757
|
+
Model({ name: "Task" })
|
|
767
758
|
], Task);
|
|
768
759
|
const query = await Task.queryToSurrealQL(mockPerspective, { where: { completed: true } });
|
|
769
|
-
expect(query).toContain("out.uri = true");
|
|
760
|
+
expect(query).toContain("fn::parse_literal(out.uri) = true");
|
|
770
761
|
});
|
|
771
762
|
it("should handle array of numbers", async () => {
|
|
772
763
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { rating: [4, 5] } });
|
|
773
|
-
expect(query).toContain("count(->link[WHERE
|
|
764
|
+
expect(query).toContain("count(->link[WHERE predicate = 'recipe://rating' AND fn::parse_literal(out.uri) IN [4, 5]]) > 0");
|
|
774
765
|
});
|
|
775
766
|
it("should skip unknown properties in where clause", async () => {
|
|
776
767
|
const query = await Recipe.queryToSurrealQL(mockPerspective, { where: { unknownProp: "value" } });
|
|
@@ -792,15 +783,10 @@ describe("Ad4mModel.queryToSurrealQL()", () => {
|
|
|
792
783
|
expect(query).toContain("FROM node");
|
|
793
784
|
expect(query).not.toContain("ORDER BY");
|
|
794
785
|
});
|
|
795
|
-
it("should generate query with only properties
|
|
796
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { properties: ["name", "rating"]
|
|
797
|
-
// With array::group(), all link data is selected, filtering happens in instancesFromSurrealResult
|
|
798
|
-
expect(query).toContain("->link[WHERE perspective = $perspective] AS links");
|
|
799
|
-
});
|
|
800
|
-
it("should generate query with only collections, no properties", async () => {
|
|
801
|
-
const query = await Recipe.queryToSurrealQL(mockPerspective, { properties: [], collections: ["ingredients"] });
|
|
786
|
+
it("should generate query with only properties specified", async () => {
|
|
787
|
+
const query = await Recipe.queryToSurrealQL(mockPerspective, { properties: ["name", "rating"] });
|
|
802
788
|
// With array::group(), all link data is selected, filtering happens in instancesFromSurrealResult
|
|
803
|
-
expect(query).toContain("->link
|
|
789
|
+
expect(query).toContain("->link AS links");
|
|
804
790
|
});
|
|
805
791
|
});
|
|
806
792
|
describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", () => {
|
|
@@ -822,11 +808,11 @@ describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", ()
|
|
|
822
808
|
__metadata("design:type", Number)
|
|
823
809
|
], Recipe.prototype, "rating", void 0);
|
|
824
810
|
__decorate([
|
|
825
|
-
|
|
811
|
+
HasMany({ through: "recipe://ingredient" }),
|
|
826
812
|
__metadata("design:type", Array)
|
|
827
813
|
], Recipe.prototype, "ingredients", void 0);
|
|
828
814
|
Recipe = __decorate([
|
|
829
|
-
|
|
815
|
+
Model({ name: "Recipe" })
|
|
830
816
|
], Recipe);
|
|
831
817
|
// Mock perspective with both querySurrealDB and infer methods
|
|
832
818
|
const mockPerspective = {
|
|
@@ -901,12 +887,11 @@ describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", ()
|
|
|
901
887
|
// rating and ingredients should be removed since only "name" was requested
|
|
902
888
|
expect(recipe.rating).toBeUndefined();
|
|
903
889
|
expect(recipe.ingredients).toBeUndefined();
|
|
904
|
-
// author
|
|
905
|
-
expect(recipe.author).
|
|
906
|
-
|
|
907
|
-
expect(recipe.timestamp).toBe(new Date("2023-01-01T00:00:00Z").getTime());
|
|
890
|
+
// author, createdAt, updatedAt are also stripped unless explicitly requested
|
|
891
|
+
expect(recipe.author).toBeUndefined();
|
|
892
|
+
expect(recipe.timestamp).toBeUndefined();
|
|
908
893
|
});
|
|
909
|
-
it("should filter
|
|
894
|
+
it("should filter properties when query specifies properties", async () => {
|
|
910
895
|
const surrealResults = [
|
|
911
896
|
{
|
|
912
897
|
source: "node:abc123",
|
|
@@ -919,12 +904,11 @@ describe("Ad4mModel.instancesFromSurrealResult() and SurrealDB integration", ()
|
|
|
919
904
|
]
|
|
920
905
|
}
|
|
921
906
|
];
|
|
922
|
-
const result = await Recipe.instancesFromSurrealResult(mockPerspective, {
|
|
907
|
+
const result = await Recipe.instancesFromSurrealResult(mockPerspective, { properties: ["name"] }, surrealResults);
|
|
923
908
|
expect(result.results).toHaveLength(1);
|
|
924
909
|
const recipe = result.results[0];
|
|
925
|
-
expect(recipe.
|
|
926
|
-
//
|
|
927
|
-
expect(recipe.name).toBeUndefined();
|
|
910
|
+
expect(recipe.name).toBe("Pasta");
|
|
911
|
+
// rating and ingredients should be removed since only "name" was requested
|
|
928
912
|
expect(recipe.rating).toBeUndefined();
|
|
929
913
|
});
|
|
930
914
|
it("should handle results missing base field", async () => {
|
|
@@ -1135,11 +1119,11 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
1135
1119
|
__metadata("design:type", Number)
|
|
1136
1120
|
], Recipe.prototype, "rating", void 0);
|
|
1137
1121
|
__decorate([
|
|
1138
|
-
|
|
1122
|
+
HasMany({ through: "recipe://ingredient" }),
|
|
1139
1123
|
__metadata("design:type", Array)
|
|
1140
1124
|
], Recipe.prototype, "ingredients", void 0);
|
|
1141
1125
|
Recipe = __decorate([
|
|
1142
|
-
|
|
1126
|
+
Model({ name: "Recipe" })
|
|
1143
1127
|
], Recipe);
|
|
1144
1128
|
// Mock perspective
|
|
1145
1129
|
const mockPerspective = {
|