@coasys/ad4m 0.13.0-postmessage-ws-proxy.0 → 0.13.0-postmessage-ws-proxy.5
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 +825 -653
- package/lib/index.js +812 -654
- package/lib/src/Ad4mClient.d.ts +1 -0
- package/lib/src/Ad4mClient.js +1 -1
- package/lib/src/ai/AIClient.js +1 -1
- package/lib/src/apiClient.d.ts +4 -1
- package/lib/src/apiClient.js +6 -1
- package/lib/src/index.d.ts +4 -0
- package/lib/src/index.js +4 -0
- package/lib/src/model/Ad4mModel.d.ts +9 -32
- package/lib/src/model/Ad4mModel.js +36 -266
- package/lib/src/model/ModelQueryBuilder.d.ts +5 -10
- package/lib/src/model/ModelQueryBuilder.js +20 -36
- package/lib/src/model/decorators.d.ts +7 -4
- package/lib/src/model/shacl-gen.js +120 -47
- package/lib/src/model/types.d.ts +140 -4
- 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/NodeExpression.d.ts +44 -0
- package/lib/src/shacl/NodeExpression.js +39 -0
- package/lib/src/shacl/SHACLShape.d.ts +23 -0
- package/lib/src/shacl/SHACLShape.js +115 -1
- package/lib/src/shacl/builders.d.ts +58 -0
- package/lib/src/shacl/builders.js +76 -0
- package/lib/src/shacl/index.d.ts +36 -0
- package/lib/src/shacl/index.js +33 -0
- package/package.json +8 -11
- package/src/Ad4mClient.ts +2 -2
- package/src/ai/AIClient.ts +1 -1
- package/src/apiClient.ts +8 -1
- package/src/index.ts +4 -0
- package/src/model/Ad4mModel.test.ts +33 -74
- package/src/model/Ad4mModel.ts +54 -272
- package/src/model/ModelQueryBuilder.ts +29 -46
- package/src/model/decorators.ts +7 -4
- package/src/model/relation-filtering.test.ts +46 -39
- package/src/model/shacl-gen.ts +128 -54
- package/src/model/shacl-roundtrip.test.ts +197 -0
- package/src/model/types-typed-query.test.ts +360 -0
- package/src/model/types.ts +196 -4
- package/src/perspectives/PerspectiveClient.ts +6 -8
- package/src/perspectives/PerspectiveProxy.ts +13 -13
- package/src/perspectives/SparqlBindings.ts +79 -0
- package/src/shacl/NodeExpression.ts +54 -0
- package/src/shacl/SHACLShape.test.ts +172 -0
- package/src/shacl/SHACLShape.ts +173 -1
- package/src/shacl/builders.ts +86 -0
- package/src/shacl/index.ts +72 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHACL-AF Transform DSL — public API
|
|
3
|
+
*
|
|
4
|
+
* Re-exports builder functions and provides common built-in transforms.
|
|
5
|
+
*/
|
|
6
|
+
import { focus, literal, path, exists, ifExpr, concat, coalesce, fn, } from './builders';
|
|
7
|
+
export { isNodeExpression } from './NodeExpression';
|
|
8
|
+
export { focus, literal, path, exists, ifExpr, concat, coalesce, fn, };
|
|
9
|
+
/**
|
|
10
|
+
* Built-in transform: FileData → data: URI
|
|
11
|
+
*
|
|
12
|
+
* Converts a file stored via FILE_STORAGE_LANGUAGE into a data: URL.
|
|
13
|
+
* If the object has a `data_base64` field, returns:
|
|
14
|
+
* `data:{file_type};base64,{data_base64}`
|
|
15
|
+
* Otherwise passes through the input unchanged.
|
|
16
|
+
*
|
|
17
|
+
* This is the Rust equivalent of the JS `defaultFileDecode` function.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* @Property({
|
|
22
|
+
* through: 'we://image',
|
|
23
|
+
* resolveLanguage: FILE_STORAGE_LANGUAGE,
|
|
24
|
+
* transform: fileToDataUri,
|
|
25
|
+
* })
|
|
26
|
+
* avatar?: string;
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export const fileToDataUri = ifExpr(exists(path('file_storage://data_base64')))
|
|
30
|
+
.then(concat(literal('data:'), coalesce(path('file_storage://file_type'), literal('image/png')), literal(';base64,'), path('file_storage://data_base64')))
|
|
31
|
+
.else(focus());
|
|
32
|
+
// Re-export SHACL types for convenience
|
|
33
|
+
export { SHACLShape, } from './SHACLShape';
|
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.5",
|
|
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/Ad4mClient.ts
CHANGED
|
@@ -33,11 +33,11 @@ export class Ad4mClient {
|
|
|
33
33
|
baseUrl: string,
|
|
34
34
|
token?: string,
|
|
35
35
|
subscribe: boolean = true,
|
|
36
|
-
options?: { webSocketImpl?: new (url: string) => WebSocket }
|
|
36
|
+
options?: { webSocketImpl?: new (url: string) => WebSocket; fetchImpl?: typeof fetch }
|
|
37
37
|
) {
|
|
38
38
|
this.#baseUrl = baseUrl
|
|
39
39
|
this.#token = token
|
|
40
|
-
this.#apiClient = new ApiClient(baseUrl, token, options?.webSocketImpl)
|
|
40
|
+
this.#apiClient = new ApiClient(baseUrl, token, options?.webSocketImpl, options?.fetchImpl)
|
|
41
41
|
this.#agentClient = new AgentClient(baseUrl, token, subscribe, this.#apiClient)
|
|
42
42
|
this.#expressionClient = new ExpressionClient(baseUrl, token, this.#apiClient)
|
|
43
43
|
this.#languageClient = new LanguageClient(baseUrl, token, this.#apiClient)
|
package/src/ai/AIClient.ts
CHANGED
|
@@ -156,7 +156,7 @@ export class AIClient {
|
|
|
156
156
|
typedAudio.byteOffset + typedAudio.byteLength
|
|
157
157
|
);
|
|
158
158
|
|
|
159
|
-
const response = await
|
|
159
|
+
const response = await this.#apiClient.doFetch(`${baseUrl}/api/v1/ai/transcription/feed`, {
|
|
160
160
|
method: 'POST',
|
|
161
161
|
headers: {
|
|
162
162
|
'Content-Type': 'application/octet-stream',
|
package/src/apiClient.ts
CHANGED
|
@@ -44,16 +44,23 @@ export class ApiClient {
|
|
|
44
44
|
private baseUrl: string
|
|
45
45
|
private token?: string
|
|
46
46
|
private readonly _webSocketImpl?: new (url: string) => WebSocket
|
|
47
|
+
private readonly _fetchImpl?: typeof fetch
|
|
47
48
|
|
|
48
|
-
constructor(baseUrl: string, token?: string, webSocketImpl?: new (url: string) => WebSocket) {
|
|
49
|
+
constructor(baseUrl: string, token?: string, webSocketImpl?: new (url: string) => WebSocket, fetchImpl?: typeof fetch) {
|
|
49
50
|
this.baseUrl = baseUrl
|
|
50
51
|
this.token = token
|
|
51
52
|
this._webSocketImpl = webSocketImpl
|
|
53
|
+
this._fetchImpl = fetchImpl
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
getBaseUrl(): string { return this.baseUrl }
|
|
55
57
|
getToken(): string | undefined { return this.token }
|
|
56
58
|
|
|
59
|
+
/** Perform an HTTP request, using an injected fetch implementation if provided. */
|
|
60
|
+
doFetch(url: string, init: RequestInit): Promise<Response> {
|
|
61
|
+
return this._fetchImpl ? this._fetchImpl(url, init) : fetch(url, init)
|
|
62
|
+
}
|
|
63
|
+
|
|
57
64
|
setToken(token: string) {
|
|
58
65
|
this.token = token
|
|
59
66
|
}
|
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";
|
|
@@ -33,6 +34,9 @@ export * from "./runtime/RuntimeTypes"
|
|
|
33
34
|
export { Model as AIModel, ModelApi, TokenizerSource, LocalModel, ModelType, ModelApiInput, TokenizerSourceInput, LocalModelInput, ModelInput, VoiceActivityParamsInput } from "./ai/AITypes"
|
|
34
35
|
export * from './shacl/SHACLShape'
|
|
35
36
|
export { SHACLFlow, FlowState, FlowTransition, LinkPattern, FlowableCondition } from './shacl/SHACLFlow'
|
|
37
|
+
export * from './shacl/NodeExpression'
|
|
38
|
+
export * from './shacl/builders'
|
|
39
|
+
export { fileToDataUri } from './shacl/index'
|
|
36
40
|
export * from "./generated/api";
|
|
37
41
|
export { RpcError } from "./apiClient";
|
|
38
42
|
/** @deprecated Use `RpcError` instead. */
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Ad4mModel } from "./Ad4mModel";
|
|
2
2
|
import { isIncludeProjection } from "./types";
|
|
3
3
|
import { Model, Property, Optional, ReadOnly, HasMany, HasOne, Flag } from "./decorators";
|
|
4
|
+
import { path } from "../shacl/builders";
|
|
4
5
|
|
|
5
6
|
describe("Ad4mModel.getModelMetadata()", () => {
|
|
6
7
|
it("should extract basic model metadata with className", () => {
|
|
@@ -79,24 +80,23 @@ describe("Ad4mModel.getModelMetadata()", () => {
|
|
|
79
80
|
expect(metadata.relations.local.local).toBe(true);
|
|
80
81
|
});
|
|
81
82
|
|
|
82
|
-
it("should
|
|
83
|
+
it("should support NodeExpression transforms in properties", () => {
|
|
84
|
+
// Transforms are now NodeExpression objects, not callable functions
|
|
85
|
+
// The fileToDataUri and other builders are exported from @coasys/ad4m
|
|
86
|
+
const transform = path("test://prefix");
|
|
87
|
+
|
|
83
88
|
@Model({ name: "TransformModel" })
|
|
84
89
|
class TransformModel extends Ad4mModel {
|
|
85
|
-
@Optional({
|
|
90
|
+
@Optional({
|
|
86
91
|
through: "test://data",
|
|
87
|
-
transform
|
|
92
|
+
transform
|
|
88
93
|
})
|
|
89
94
|
data: string = "";
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
const metadata = TransformModel.getModelMetadata();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
expect(typeof metadata.properties.data.transform).toBe("function");
|
|
96
|
-
|
|
97
|
-
// Test the transform function
|
|
98
|
-
const transformed = metadata.properties.data.transform!("test");
|
|
99
|
-
expect(transformed).toBe("TEST");
|
|
98
|
+
expect(metadata.properties.data).toBeDefined();
|
|
99
|
+
expect(metadata.properties.data.transform).toEqual(transform);
|
|
100
100
|
});
|
|
101
101
|
|
|
102
102
|
it("should extract custom getter and setter from property metadata", () => {
|
|
@@ -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 ---
|