@coasys/ad4m 0.13.0-postmessage-ws-proxy.0 → 0.13.0-postmessage-ws-proxy.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/lib/index.cjs +564 -461
- package/lib/index.js +561 -462
- package/lib/src/index.d.ts +1 -0
- package/lib/src/index.js +1 -0
- package/lib/src/model/Ad4mModel.d.ts +9 -17
- package/lib/src/model/Ad4mModel.js +34 -148
- package/lib/src/model/ModelQueryBuilder.d.ts +5 -10
- package/lib/src/model/ModelQueryBuilder.js +8 -14
- package/lib/src/model/shacl-gen.js +115 -46
- package/lib/src/model/types.d.ts +138 -3
- package/lib/src/perspectives/PerspectiveClient.d.ts +4 -4
- package/lib/src/perspectives/PerspectiveClient.js +5 -6
- package/lib/src/perspectives/PerspectiveProxy.d.ts +8 -7
- package/lib/src/perspectives/PerspectiveProxy.js +10 -9
- package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
- package/lib/src/perspectives/SparqlBindings.js +65 -0
- package/lib/src/shacl/SHACLShape.d.ts +18 -0
- package/lib/src/shacl/SHACLShape.js +83 -0
- package/package.json +8 -11
- package/src/index.ts +1 -0
- package/src/model/Ad4mModel.test.ts +23 -64
- package/src/model/Ad4mModel.ts +52 -159
- package/src/model/ModelQueryBuilder.ts +17 -23
- package/src/model/relation-filtering.test.ts +46 -39
- package/src/model/shacl-gen.ts +122 -53
- package/src/model/shacl-roundtrip.test.ts +197 -0
- package/src/model/types-typed-query.test.ts +360 -0
- package/src/model/types.ts +194 -3
- package/src/perspectives/PerspectiveClient.ts +6 -8
- package/src/perspectives/PerspectiveProxy.ts +13 -13
- package/src/perspectives/SparqlBindings.ts +79 -0
- package/src/shacl/SHACLShape.test.ts +110 -0
- package/src/shacl/SHACLShape.ts +125 -0
|
@@ -76,6 +76,24 @@ export interface SHACLPropertyShape {
|
|
|
76
76
|
value: string;
|
|
77
77
|
label?: string;
|
|
78
78
|
}>;
|
|
79
|
+
/** AD4M-specific: kind of relation this property describes.
|
|
80
|
+
* Drives direction (forward/reverse), scalar-vs-collection rendering,
|
|
81
|
+
* and default max-count. */
|
|
82
|
+
relationKind?: 'hasMany' | 'hasOne' | 'belongsToOne' | 'belongsToMany';
|
|
83
|
+
/** AD4M-specific: target class name (local-name) for a relation property.
|
|
84
|
+
* Complements `class` (the SHACL node-shape URI) by providing the bare
|
|
85
|
+
* model class name used by the executor to look up the target shape
|
|
86
|
+
* through the perspective's shape cache. */
|
|
87
|
+
targetClassName?: string;
|
|
88
|
+
/** AD4M-specific: post-getter where-clause filter for a relation property. */
|
|
89
|
+
whereFilter?: any;
|
|
90
|
+
/** AD4M-specific: predicate-IRI lookup map for `whereFilter` keys
|
|
91
|
+
* (property name → predicate URI on the target class). */
|
|
92
|
+
wherePredicates?: Record<string, string>;
|
|
93
|
+
/** AD4M-specific: whether conformance/type filtering is enabled for this
|
|
94
|
+
* relation. `false` opts out of DB-level type filtering while keeping
|
|
95
|
+
* hydration via `include`. */
|
|
96
|
+
filter?: boolean;
|
|
79
97
|
}
|
|
80
98
|
/**
|
|
81
99
|
* SHACL Node Shape
|
|
@@ -385,6 +385,41 @@ export class SHACLShape {
|
|
|
385
385
|
target: `literal:string:${JSON.stringify(prop.in)}`
|
|
386
386
|
});
|
|
387
387
|
}
|
|
388
|
+
if (prop.relationKind) {
|
|
389
|
+
links.push({
|
|
390
|
+
source: propShapeId,
|
|
391
|
+
predicate: "ad4m://relationKind",
|
|
392
|
+
target: `literal:string:${prop.relationKind}`
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
if (prop.targetClassName) {
|
|
396
|
+
links.push({
|
|
397
|
+
source: propShapeId,
|
|
398
|
+
predicate: "ad4m://targetClassName",
|
|
399
|
+
target: `literal:string:${prop.targetClassName}`
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
if (prop.whereFilter !== undefined && prop.whereFilter !== null) {
|
|
403
|
+
links.push({
|
|
404
|
+
source: propShapeId,
|
|
405
|
+
predicate: "ad4m://whereFilter",
|
|
406
|
+
target: `literal:string:${JSON.stringify(prop.whereFilter)}`
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
if (prop.wherePredicates && Object.keys(prop.wherePredicates).length > 0) {
|
|
410
|
+
links.push({
|
|
411
|
+
source: propShapeId,
|
|
412
|
+
predicate: "ad4m://wherePredicates",
|
|
413
|
+
target: `literal:string:${JSON.stringify(prop.wherePredicates)}`
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
if (prop.filter !== undefined) {
|
|
417
|
+
links.push({
|
|
418
|
+
source: propShapeId,
|
|
419
|
+
predicate: "ad4m://filter",
|
|
420
|
+
target: `literal:${prop.filter}`
|
|
421
|
+
});
|
|
422
|
+
}
|
|
388
423
|
}
|
|
389
424
|
return links;
|
|
390
425
|
}
|
|
@@ -566,6 +601,44 @@ export class SHACLShape {
|
|
|
566
601
|
// Ignore parse errors
|
|
567
602
|
}
|
|
568
603
|
}
|
|
604
|
+
const relationKindLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://relationKind");
|
|
605
|
+
if (relationKindLink) {
|
|
606
|
+
const val = relationKindLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
607
|
+
if (val === 'hasMany' || val === 'hasOne' || val === 'belongsToOne' || val === 'belongsToMany') {
|
|
608
|
+
prop.relationKind = val;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const targetClassNameLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://targetClassName");
|
|
612
|
+
if (targetClassNameLink) {
|
|
613
|
+
prop.targetClassName = targetClassNameLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
614
|
+
}
|
|
615
|
+
const whereFilterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://whereFilter");
|
|
616
|
+
if (whereFilterLink) {
|
|
617
|
+
try {
|
|
618
|
+
const jsonStr = whereFilterLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
619
|
+
prop.whereFilter = JSON.parse(jsonStr);
|
|
620
|
+
}
|
|
621
|
+
catch (e) {
|
|
622
|
+
// Ignore parse errors
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
const wherePredicatesLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://wherePredicates");
|
|
626
|
+
if (wherePredicatesLink) {
|
|
627
|
+
try {
|
|
628
|
+
const jsonStr = wherePredicatesLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
629
|
+
prop.wherePredicates = JSON.parse(jsonStr);
|
|
630
|
+
}
|
|
631
|
+
catch (e) {
|
|
632
|
+
// Ignore parse errors
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
const filterLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://filter");
|
|
636
|
+
if (filterLink) {
|
|
637
|
+
let val = filterLink.target.replace(/^literal:\/\/|^literal:/, '');
|
|
638
|
+
if (val.startsWith('boolean:'))
|
|
639
|
+
val = val.substring(8);
|
|
640
|
+
prop.filter = val === 'true';
|
|
641
|
+
}
|
|
569
642
|
shape.addProperty(prop);
|
|
570
643
|
}
|
|
571
644
|
return shape;
|
|
@@ -602,6 +675,11 @@ export class SHACLShape {
|
|
|
602
675
|
conformance_conditions: p.conformanceConditions,
|
|
603
676
|
class: p.class,
|
|
604
677
|
in: p.in,
|
|
678
|
+
relation_kind: p.relationKind,
|
|
679
|
+
target_class_name: p.targetClassName,
|
|
680
|
+
where_filter: p.whereFilter,
|
|
681
|
+
where_predicates: p.wherePredicates,
|
|
682
|
+
filter: p.filter,
|
|
605
683
|
})),
|
|
606
684
|
constructor_actions: this.constructor_actions,
|
|
607
685
|
destructor_actions: this.destructor_actions,
|
|
@@ -636,6 +714,11 @@ export class SHACLShape {
|
|
|
636
714
|
conformanceConditions: p.conformance_conditions,
|
|
637
715
|
class: p.class,
|
|
638
716
|
in: p.in,
|
|
717
|
+
relationKind: p.relation_kind,
|
|
718
|
+
targetClassName: p.target_class_name,
|
|
719
|
+
whereFilter: p.where_filter,
|
|
720
|
+
wherePredicates: p.where_predicates,
|
|
721
|
+
filter: p.filter,
|
|
639
722
|
});
|
|
640
723
|
}
|
|
641
724
|
if (json.constructor_actions) {
|
package/package.json
CHANGED
|
@@ -5,12 +5,6 @@
|
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "patch-package && tsc && pnpm run bundle",
|
|
10
|
-
"bundle": "rollup -c rollup.config.js",
|
|
11
|
-
"test": "jest --forceExit",
|
|
12
|
-
"generate:api-types": "cd ../rust-executor && TS_RS_EXPORT_DIR=../core/src/generated/api/ cargo test --lib 2>/dev/null && echo \"API types generated to core/src/generated/api/\""
|
|
13
|
-
},
|
|
14
8
|
"repository": {
|
|
15
9
|
"type": "git",
|
|
16
10
|
"url": "git+https://github.com/coasys/ad4m.git"
|
|
@@ -54,8 +48,11 @@
|
|
|
54
48
|
"ws": "8.13.0"
|
|
55
49
|
},
|
|
56
50
|
"patchedDependencies": {},
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
"version": "0.13.0-postmessage-ws-proxy.3",
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "patch-package && tsc && pnpm run bundle",
|
|
54
|
+
"bundle": "rollup -c rollup.config.js",
|
|
55
|
+
"test": "jest --forceExit",
|
|
56
|
+
"generate:api-types": "cd ../rust-executor && TS_RS_EXPORT_DIR=../core/src/generated/api/ cargo test --lib 2>/dev/null && echo \"API types generated to core/src/generated/api/\""
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -16,6 +16,7 @@ export * from "./Literal";
|
|
|
16
16
|
export * from "./perspectives/Perspective";
|
|
17
17
|
export * from "./perspectives/PerspectiveHandle";
|
|
18
18
|
export * from "./perspectives/PerspectiveProxy";
|
|
19
|
+
export * from "./perspectives/SparqlBindings";
|
|
19
20
|
export * from "./perspectives/WakerSubscriptionManager";
|
|
20
21
|
export * from "./perspectives/PerspectiveDiff";
|
|
21
22
|
export * from "./perspectives/LinkQuery";
|
|
@@ -645,8 +645,7 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
645
645
|
jest.clearAllMocks();
|
|
646
646
|
});
|
|
647
647
|
|
|
648
|
-
it("
|
|
649
|
-
// modelQuery returns already-hydrated instances from the Rust executor
|
|
648
|
+
it("routes findAll() through modelQuery", async () => {
|
|
650
649
|
mockPerspective.modelQuery.mockResolvedValue({
|
|
651
650
|
instances: [
|
|
652
651
|
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
@@ -654,7 +653,7 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
654
653
|
totalCount: 1
|
|
655
654
|
});
|
|
656
655
|
|
|
657
|
-
const results = await Recipe.findAll(mockPerspective
|
|
656
|
+
const results = await Recipe.findAll(mockPerspective);
|
|
658
657
|
|
|
659
658
|
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
660
659
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
@@ -662,21 +661,6 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
662
661
|
expect(results[0].name).toBe("Pasta");
|
|
663
662
|
});
|
|
664
663
|
|
|
665
|
-
it("should route through modelQuery when engine is 'prolog' in findAll() (prolog is now no-op)", async () => {
|
|
666
|
-
mockPerspective.modelQuery.mockResolvedValue({
|
|
667
|
-
instances: [
|
|
668
|
-
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
669
|
-
],
|
|
670
|
-
totalCount: 1
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
const results = await Recipe.findAll(mockPerspective, {}, false);
|
|
674
|
-
|
|
675
|
-
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
676
|
-
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
677
|
-
expect(results).toHaveLength(1);
|
|
678
|
-
});
|
|
679
|
-
|
|
680
664
|
it("should use SPARQL when engine is 'sparql' in findAllAndCount()", async () => {
|
|
681
665
|
mockPerspective.modelQuery.mockResolvedValue({
|
|
682
666
|
instances: [
|
|
@@ -737,7 +721,7 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
737
721
|
expect(count).toBe(10);
|
|
738
722
|
});
|
|
739
723
|
|
|
740
|
-
it("
|
|
724
|
+
it("routes ModelQueryBuilder.get() through modelQuery", async () => {
|
|
741
725
|
mockPerspective.modelQuery.mockResolvedValue({
|
|
742
726
|
instances: [
|
|
743
727
|
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
@@ -747,7 +731,6 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
747
731
|
|
|
748
732
|
const results = await Recipe.query(mockPerspective)
|
|
749
733
|
.where({ name: "Pasta" })
|
|
750
|
-
.engine('sparql')
|
|
751
734
|
.get();
|
|
752
735
|
|
|
753
736
|
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
@@ -756,26 +739,7 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
756
739
|
expect(results[0].name).toBe("Pasta");
|
|
757
740
|
});
|
|
758
741
|
|
|
759
|
-
it("
|
|
760
|
-
mockPerspective.modelQuery.mockResolvedValue({
|
|
761
|
-
instances: [
|
|
762
|
-
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
763
|
-
],
|
|
764
|
-
totalCount: 1
|
|
765
|
-
});
|
|
766
|
-
|
|
767
|
-
const results = await Recipe.query(mockPerspective)
|
|
768
|
-
.where({ name: "Pasta" })
|
|
769
|
-
.engine('prolog')
|
|
770
|
-
.get();
|
|
771
|
-
|
|
772
|
-
// engine('prolog') is now a no-op — everything goes through modelQuery
|
|
773
|
-
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
774
|
-
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
775
|
-
expect(results).toHaveLength(1);
|
|
776
|
-
});
|
|
777
|
-
|
|
778
|
-
it("should use SPARQL when engine is 'sparql' in ModelQueryBuilder.count()", async () => {
|
|
742
|
+
it("routes ModelQueryBuilder.count() through modelQuery", async () => {
|
|
779
743
|
mockPerspective.modelQuery.mockResolvedValue({
|
|
780
744
|
instances: [],
|
|
781
745
|
totalCount: 3
|
|
@@ -783,7 +747,6 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
783
747
|
|
|
784
748
|
const count = await Recipe.query(mockPerspective)
|
|
785
749
|
.where({ rating: { gt: 4 } })
|
|
786
|
-
.engine('sparql')
|
|
787
750
|
.count();
|
|
788
751
|
|
|
789
752
|
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
@@ -791,7 +754,7 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
791
754
|
expect(count).toBe(3);
|
|
792
755
|
});
|
|
793
756
|
|
|
794
|
-
it("
|
|
757
|
+
it("routes ModelQueryBuilder.paginate() through modelQuery", async () => {
|
|
795
758
|
mockPerspective.modelQuery.mockResolvedValue({
|
|
796
759
|
instances: [
|
|
797
760
|
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
@@ -801,7 +764,6 @@ describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
|
801
764
|
|
|
802
765
|
const page = await Recipe.query(mockPerspective)
|
|
803
766
|
.where({ rating: { gt: 3 } })
|
|
804
|
-
.engine('sparql')
|
|
805
767
|
.paginate(10, 1);
|
|
806
768
|
|
|
807
769
|
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
@@ -917,7 +879,6 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
917
879
|
// Count recipes with rating > 3 using ModelQueryBuilder
|
|
918
880
|
const count = await Recipe.query(mockPerspective)
|
|
919
881
|
.where({ rating: { gt: 3 } })
|
|
920
|
-
.engine('sparql')
|
|
921
882
|
.count();
|
|
922
883
|
|
|
923
884
|
expect(count).toBe(2);
|
|
@@ -936,7 +897,6 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
936
897
|
// Count using ModelQueryBuilder
|
|
937
898
|
const count = await Recipe.query(mockPerspective)
|
|
938
899
|
.where({ timestamp: { between: [startTimestamp, endTimestamp] } })
|
|
939
|
-
.engine('sparql')
|
|
940
900
|
.count();
|
|
941
901
|
|
|
942
902
|
expect(count).toBe(3);
|
|
@@ -1330,8 +1290,8 @@ describe("ModelQueryBuilder subscribe callback timing", () => {
|
|
|
1330
1290
|
const mockPerspective = {
|
|
1331
1291
|
uuid: "test-uuid",
|
|
1332
1292
|
client: mockClient,
|
|
1333
|
-
modelSubscribe: jest.fn().mockImplementation(async (className: string, queryJson: string
|
|
1334
|
-
return mockClient.modelSubscribe("test-uuid", className, queryJson
|
|
1293
|
+
modelSubscribe: jest.fn().mockImplementation(async (className: string, queryJson: string) => {
|
|
1294
|
+
return mockClient.modelSubscribe("test-uuid", className, queryJson);
|
|
1335
1295
|
}),
|
|
1336
1296
|
getLinks: jest.fn().mockResolvedValue([]),
|
|
1337
1297
|
modelQuery: jest.fn().mockResolvedValue({ instances: [], totalCount: 0 }),
|
|
@@ -1388,8 +1348,8 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
|
|
|
1388
1348
|
const mockPerspective = {
|
|
1389
1349
|
uuid: "test-uuid",
|
|
1390
1350
|
client: mockClient,
|
|
1391
|
-
modelSubscribe: jest.fn().mockImplementation(async (className: string, queryJson: string
|
|
1392
|
-
return mockClient.modelSubscribe("test-uuid", className, queryJson
|
|
1351
|
+
modelSubscribe: jest.fn().mockImplementation(async (className: string, queryJson: string) => {
|
|
1352
|
+
return mockClient.modelSubscribe("test-uuid", className, queryJson);
|
|
1393
1353
|
}),
|
|
1394
1354
|
modelQuery: jest.fn().mockResolvedValue({ instances: [{ id: "item1", type: "test://paginate" }], totalCount: 42 }),
|
|
1395
1355
|
} as any;
|
|
@@ -1445,8 +1405,8 @@ describe("ModelQueryBuilder paginateSubscribe", () => {
|
|
|
1445
1405
|
const mockPerspective = {
|
|
1446
1406
|
uuid: "test-uuid",
|
|
1447
1407
|
client: mockClient,
|
|
1448
|
-
modelSubscribe: jest.fn().mockImplementation(async (className: string, queryJson: string
|
|
1449
|
-
return mockClient.modelSubscribe("test-uuid", className, queryJson
|
|
1408
|
+
modelSubscribe: jest.fn().mockImplementation(async (className: string, queryJson: string) => {
|
|
1409
|
+
return mockClient.modelSubscribe("test-uuid", className, queryJson);
|
|
1450
1410
|
}),
|
|
1451
1411
|
modelQuery: jest.fn().mockImplementation(async () => {
|
|
1452
1412
|
modelQueryCallCount++;
|
|
@@ -1530,8 +1490,8 @@ describe("ModelQueryBuilder keepalive recovery", () => {
|
|
|
1530
1490
|
uuid: "test-uuid",
|
|
1531
1491
|
client: mockClient,
|
|
1532
1492
|
modelSubscribe: jest.fn().mockImplementation(
|
|
1533
|
-
async (className: string, queryJson: string
|
|
1534
|
-
mockClient.modelSubscribe("test-uuid", className, queryJson
|
|
1493
|
+
async (className: string, queryJson: string) =>
|
|
1494
|
+
mockClient.modelSubscribe("test-uuid", className, queryJson)
|
|
1535
1495
|
),
|
|
1536
1496
|
modelQuery: jest.fn().mockResolvedValue({ instances: [], totalCount: 0 }),
|
|
1537
1497
|
getLinks: jest.fn().mockResolvedValue([]),
|
|
@@ -1821,7 +1781,7 @@ describe("deepQuery — getter evaluation", () => {
|
|
|
1821
1781
|
let sparqlCalls: string[];
|
|
1822
1782
|
const mockPerspective: any = {
|
|
1823
1783
|
uuid: "test-uuid",
|
|
1824
|
-
modelQuery: jest.fn(async (className: string, queryJson: string
|
|
1784
|
+
modelQuery: jest.fn(async (className: string, queryJson: string) => {
|
|
1825
1785
|
// Return a basic result for the single-instance getData() path
|
|
1826
1786
|
const query = JSON.parse(queryJson);
|
|
1827
1787
|
const id = query?.where?.id;
|
|
@@ -1833,7 +1793,7 @@ describe("deepQuery — getter evaluation", () => {
|
|
|
1833
1793
|
}
|
|
1834
1794
|
return { instances: [], totalCount: 0 };
|
|
1835
1795
|
}),
|
|
1836
|
-
evaluateGetters: jest.fn(async (className: string, instanceIds: string[],
|
|
1796
|
+
evaluateGetters: jest.fn(async (className: string, instanceIds: string[], propertyNames?: string[]) => {
|
|
1837
1797
|
// Return empty results by default — tests can override this mock
|
|
1838
1798
|
const result: Record<string, Record<string, any>> = {};
|
|
1839
1799
|
return result;
|
|
@@ -1890,7 +1850,7 @@ describe("deepQuery — getter evaluation", () => {
|
|
|
1890
1850
|
|
|
1891
1851
|
// Should make exactly 1 RPC call via perspective.evaluateGetters
|
|
1892
1852
|
expect(mockPerspective.evaluateGetters).toHaveBeenCalledTimes(1);
|
|
1893
|
-
const [className, instanceIds,
|
|
1853
|
+
const [className, instanceIds, propertyNames] = mockPerspective.evaluateGetters.mock.calls[0];
|
|
1894
1854
|
expect(className).toBe("DeepQueryTestMessage");
|
|
1895
1855
|
expect(instanceIds).toEqual(["flux://msg-0", "flux://msg-1"]);
|
|
1896
1856
|
expect(propertyNames).toEqual(["replyingTo"]);
|
|
@@ -1904,7 +1864,7 @@ describe("deepQuery — getter evaluation", () => {
|
|
|
1904
1864
|
await DeepQueryTestMessage.evaluateGetters(instances, mockPerspective);
|
|
1905
1865
|
|
|
1906
1866
|
expect(mockPerspective.evaluateGetters).toHaveBeenCalledTimes(1);
|
|
1907
|
-
const [className, instanceIds,
|
|
1867
|
+
const [className, instanceIds, propertyNames] = mockPerspective.evaluateGetters.mock.calls[0];
|
|
1908
1868
|
expect(className).toBe("DeepQueryTestMessage");
|
|
1909
1869
|
expect(instanceIds).toEqual(["flux://msg-0", "flux://msg-1"]);
|
|
1910
1870
|
expect(propertyNames).toBeUndefined();
|
|
@@ -2254,7 +2214,7 @@ describe("IncludeProjection type guard and key splitting", () => {
|
|
|
2254
2214
|
expect(qi.include?.comments).toBe(true);
|
|
2255
2215
|
});
|
|
2256
2216
|
|
|
2257
|
-
it("
|
|
2217
|
+
it("tags projection with targetClassName when relation target is registered", async () => {
|
|
2258
2218
|
await Post.findAll(mockPerspective, {
|
|
2259
2219
|
include: {
|
|
2260
2220
|
$signalCount: { from: "signals", count: true },
|
|
@@ -2264,12 +2224,11 @@ describe("IncludeProjection type guard and key splitting", () => {
|
|
|
2264
2224
|
const [, queryJson] = mockPerspective.modelQuery.mock.calls[0];
|
|
2265
2225
|
const qi = JSON.parse(queryJson);
|
|
2266
2226
|
|
|
2267
|
-
//
|
|
2268
|
-
|
|
2269
|
-
expect(qi.projections?.$signalCount?.targetShape?.className).toBe("Signal");
|
|
2227
|
+
// targetClassName drives the executor's cache lookup for the target shape.
|
|
2228
|
+
expect(qi.projections?.$signalCount?.targetClassName).toBe("Signal");
|
|
2270
2229
|
});
|
|
2271
2230
|
|
|
2272
|
-
it("leaves
|
|
2231
|
+
it("leaves targetClassName absent when relation has no target decorator", async () => {
|
|
2273
2232
|
await Post.findAll(mockPerspective, {
|
|
2274
2233
|
include: {
|
|
2275
2234
|
$commentCount: { from: "comments", count: true },
|
|
@@ -2279,8 +2238,8 @@ describe("IncludeProjection type guard and key splitting", () => {
|
|
|
2279
2238
|
const [, queryJson] = mockPerspective.modelQuery.mock.calls[0];
|
|
2280
2239
|
const qi = JSON.parse(queryJson);
|
|
2281
2240
|
|
|
2282
|
-
// 'comments' HasMany has no target() thunk → no
|
|
2283
|
-
expect(qi.projections?.$commentCount?.
|
|
2241
|
+
// 'comments' HasMany has no target() thunk → no targetClassName
|
|
2242
|
+
expect(qi.projections?.$commentCount?.targetClassName).toBeUndefined();
|
|
2284
2243
|
});
|
|
2285
2244
|
|
|
2286
2245
|
// --- result passthrough ---
|