@coasys/ad4m 0.13.0-test-2 → 0.13.0-test-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +2805 -10556
- package/lib/index.js +2513 -10322
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +29 -13
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +10 -21
- package/lib/src/agent/AgentClient.js +75 -427
- package/lib/src/agent/AgentStatus.js +2 -37
- package/lib/src/ai/AIClient.d.ts +12 -4
- package/lib/src/ai/AIClient.js +81 -285
- package/lib/src/ai/AITypes.d.ts +55 -0
- package/lib/src/ai/AITypes.js +18 -0
- package/lib/src/ai/Tasks.js +10 -133
- package/lib/src/apiClient.d.ts +52 -0
- package/lib/src/apiClient.js +231 -0
- package/lib/src/expression/Expression.d.ts +1 -1
- package/lib/src/expression/Expression.js +13 -122
- package/lib/src/expression/ExpressionClient.d.ts +3 -3
- package/lib/src/expression/ExpressionClient.js +13 -76
- package/lib/src/expression/ExpressionRef.js +2 -25
- package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkRequest.js +1 -0
- package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/api/AddSdnaRequest.js +2 -0
- package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/api/AuthInfoInput.js +1 -0
- package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/api/CapabilityInput.js +1 -0
- package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/CommitBatchRequest.js +2 -0
- package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/api/ComputeLogEntry.js +2 -0
- package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/api/EmbedRequest.js +2 -0
- package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/api/EntanglementProofInput.js +2 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/api/ExportRequest.d.ts +5 -0
- package/lib/src/generated/api/ExportRequest.js +2 -0
- package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/api/ExpressionProof.js +2 -0
- package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/api/ExpressionProofInput.js +2 -0
- package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendsListRequest.js +2 -0
- package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/api/ImportAgentRequest.js +2 -0
- package/lib/src/generated/api/ImportRequest.d.ts +4 -0
- package/lib/src/generated/api/ImportRequest.js +2 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/api/LanguageMetaInput.js +2 -0
- package/lib/src/generated/api/Link.d.ts +5 -0
- package/lib/src/generated/api/Link.js +2 -0
- package/lib/src/generated/api/LinkExpression.d.ts +10 -0
- package/lib/src/generated/api/LinkExpression.js +1 -0
- package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/api/LinkExpressionInput.js +1 -0
- package/lib/src/generated/api/LinkInput.d.ts +5 -0
- package/lib/src/generated/api/LinkInput.js +2 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/api/LinkMutations.d.ts +6 -0
- package/lib/src/generated/api/LinkMutations.js +1 -0
- package/lib/src/generated/api/LinkStatus.d.ts +1 -0
- package/lib/src/generated/api/LinkStatus.js +2 -0
- package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/LockAgentRequest.js +2 -0
- package/lib/src/generated/api/ModelType.d.ts +1 -0
- package/lib/src/generated/api/ModelType.js +2 -0
- package/lib/src/generated/api/NotificationInput.d.ts +10 -0
- package/lib/src/generated/api/NotificationInput.js +2 -0
- package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/api/OpenLinkRequest.js +2 -0
- package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveInput.js +1 -0
- package/lib/src/generated/api/PromptRequest.d.ts +4 -0
- package/lib/src/generated/api/PromptRequest.js +2 -0
- package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/api/QueryRequest.d.ts +7 -0
- package/lib/src/generated/api/QueryRequest.js +2 -0
- package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/ResourceInput.d.ts +4 -0
- package/lib/src/generated/api/ResourceInput.js +2 -0
- package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/api/SetStatusRequest.js +2 -0
- package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/SignMessageRequest.js +2 -0
- package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/UserStatistics.d.ts +9 -0
- package/lib/src/generated/api/UserStatistics.js +2 -0
- package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/api/VerificationRequestResult.js +2 -0
- package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +42 -0
- package/lib/src/generated/api/index.js +7 -0
- package/lib/src/index.d.ts +6 -2
- package/lib/src/index.js +6 -2
- package/lib/src/jestSetup.d.ts +0 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.js +2 -21
- package/lib/src/language/Language.d.ts +26 -214
- package/lib/src/language/Language.js +32 -72
- package/lib/src/language/LanguageClient.d.ts +2 -2
- package/lib/src/language/LanguageClient.js +15 -105
- package/lib/src/language/LanguageHandle.js +2 -41
- package/lib/src/language/LanguageMeta.js +4 -75
- package/lib/src/language/LanguageRef.js +2 -25
- package/lib/src/links/Links.js +14 -111
- package/lib/src/model/Ad4mModel.d.ts +81 -38
- package/lib/src/model/Ad4mModel.js +651 -408
- package/lib/src/model/Ad4mModel.test.js +488 -750
- package/lib/src/model/ModelQueryBuilder.d.ts +28 -21
- package/lib/src/model/ModelQueryBuilder.js +160 -195
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration-batching.test.d.ts +7 -0
- package/lib/src/model/hydration-batching.test.js +456 -0
- package/lib/src/model/hydration.d.ts +8 -60
- package/lib/src/model/hydration.js +41 -541
- package/lib/src/model/index.d.ts +0 -4
- package/lib/src/model/index.js +0 -4
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-sparql.d.ts +36 -22
- package/lib/src/model/query-sparql.js +188 -53
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +312 -0
- package/lib/src/model/query-utils.js +4 -0
- package/lib/src/model/shacl-gen.js +4 -0
- package/lib/src/model/subscription-delta.test.d.ts +24 -0
- package/lib/src/model/subscription-delta.test.js +180 -0
- package/lib/src/model/subscription-pool.js +48 -2
- package/lib/src/model/types.d.ts +58 -1
- package/lib/src/model/types.js +4 -1
- package/lib/src/neighbourhood/Neighbourhood.js +4 -32
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
- package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
- package/lib/src/perspectives/LinkQuery.js +2 -42
- package/lib/src/perspectives/Perspective.d.ts +1 -1
- package/lib/src/perspectives/Perspective.js +10 -52
- package/lib/src/perspectives/PerspectiveClient.d.ts +12 -15
- package/lib/src/perspectives/PerspectiveClient.js +168 -400
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +95 -71
- package/lib/src/perspectives/PerspectiveProxy.js +288 -310
- package/lib/src/runtime/RuntimeClient.d.ts +6 -6
- package/lib/src/runtime/RuntimeClient.js +93 -467
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/shacl/SHACLShape.d.ts +7 -0
- package/lib/src/shacl/SHACLShape.js +19 -0
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -628
- package/package.json +9 -24
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1182 -1288
- package/src/Ad4mClient.ts +30 -15
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +112 -526
- package/src/agent/AgentStatus.ts +0 -12
- package/src/ai/AIClient.ts +96 -296
- package/src/ai/AITypes.ts +66 -0
- package/src/ai/Tasks.ts +0 -52
- package/src/apiClient.ts +283 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +14 -77
- package/src/expression/ExpressionRef.ts +0 -6
- package/src/generated/api/AIModelLoadingStatus.ts +3 -0
- package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
- package/src/generated/api/AddLinkRequest.ts +4 -0
- package/src/generated/api/AddLinksBulkRequest.ts +4 -0
- package/src/generated/api/AddSdnaRequest.ts +3 -0
- package/src/generated/api/ApplyTemplateRequest.ts +3 -0
- package/src/generated/api/AuthInfoInput.ts +4 -0
- package/src/generated/api/CapabilityInput.ts +4 -0
- package/src/generated/api/CommitBatchRequest.ts +3 -0
- package/src/generated/api/ComputeLogEntry.ts +3 -0
- package/src/generated/api/CreateExpressionRequest.ts +3 -0
- package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
- package/src/generated/api/CreateSubjectRequest.ts +3 -0
- package/src/generated/api/EmbedRequest.ts +3 -0
- package/src/generated/api/EntanglementProofInput.ts +3 -0
- package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
- package/src/generated/api/ExportRequest.ts +3 -0
- package/src/generated/api/ExpressionManyRequest.ts +3 -0
- package/src/generated/api/ExpressionProof.ts +3 -0
- package/src/generated/api/ExpressionProofInput.ts +3 -0
- package/src/generated/api/FriendSendMessageRequest.ts +3 -0
- package/src/generated/api/FriendsListRequest.ts +3 -0
- package/src/generated/api/GenerateAgentRequest.ts +3 -0
- package/src/generated/api/GenerateJwtRequest.ts +3 -0
- package/src/generated/api/GetSubjectDataRequest.ts +3 -0
- package/src/generated/api/ImportAgentRequest.ts +3 -0
- package/src/generated/api/ImportRequest.ts +3 -0
- package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
- package/src/generated/api/LanguageMetaInput.ts +3 -0
- package/src/generated/api/Link.ts +3 -0
- package/src/generated/api/LinkExpression.ts +6 -0
- package/src/generated/api/LinkExpressionInput.ts +6 -0
- package/src/generated/api/LinkInput.ts +3 -0
- package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
- package/src/generated/api/LinkMutations.ts +5 -0
- package/src/generated/api/LinkStatus.ts +3 -0
- package/src/generated/api/LockAgentRequest.ts +3 -0
- package/src/generated/api/ModelType.ts +3 -0
- package/src/generated/api/NotificationInput.ts +3 -0
- package/src/generated/api/OpenLinkRequest.ts +3 -0
- package/src/generated/api/PermitCapabilityRequest.ts +3 -0
- package/src/generated/api/PerspectiveInput.ts +4 -0
- package/src/generated/api/PromptRequest.ts +3 -0
- package/src/generated/api/PublishLanguageRequest.ts +4 -0
- package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
- package/src/generated/api/QueryRequest.ts +6 -0
- package/src/generated/api/RemoveLinkRequest.ts +4 -0
- package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
- package/src/generated/api/ResourceInput.ts +3 -0
- package/src/generated/api/SetDefaultModelRequest.ts +4 -0
- package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
- package/src/generated/api/SetMultiUserRequest.ts +3 -0
- package/src/generated/api/SetStatusRequest.ts +3 -0
- package/src/generated/api/SignMessageRequest.ts +3 -0
- package/src/generated/api/TrustedAgentsRequest.ts +3 -0
- package/src/generated/api/UnlockAgentRequest.ts +3 -0
- package/src/generated/api/UpdateLinkRequest.ts +5 -0
- package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
- package/src/generated/api/UserStatistics.ts +3 -0
- package/src/generated/api/VerificationRequestResult.ts +3 -0
- package/src/generated/api/VerifySignatureRequest.ts +3 -0
- package/src/generated/api/WriteSettingsRequest.ts +3 -0
- package/src/generated/api/index.ts +49 -0
- package/src/index.ts +6 -2
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +50 -292
- package/src/language/LanguageClient.ts +21 -132
- package/src/language/LanguageHandle.ts +0 -14
- package/src/language/LanguageMeta.ts +0 -29
- package/src/language/LanguageRef.ts +0 -7
- package/src/links/Links.ts +0 -37
- package/src/model/Ad4mModel.test.ts +827 -808
- package/src/model/Ad4mModel.ts +676 -457
- package/src/model/ModelQueryBuilder.ts +199 -217
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +17 -572
- package/src/model/index.ts +0 -4
- package/src/model/query-sparql.test.ts +360 -0
- package/src/model/query-sparql.ts +203 -56
- package/src/model/query-utils.ts +4 -0
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +62 -1
- package/src/neighbourhood/Neighbourhood.ts +0 -9
- package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
- package/src/perspectives/LinkQuery.ts +0 -15
- package/src/perspectives/Perspective.ts +1 -12
- package/src/perspectives/PerspectiveClient.test.ts +262 -0
- package/src/perspectives/PerspectiveClient.ts +227 -412
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +41 -0
- package/src/perspectives/PerspectiveProxy.ts +325 -348
- package/src/runtime/RuntimeClient.ts +112 -474
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLShape.test.ts +94 -0
- package/src/shacl/SHACLShape.ts +27 -0
- package/src/typeDefs.ts +3 -5
- package/tsconfig.json +3 -7
- package/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/lib/src/model/surreal-utils.d.ts +0 -42
- package/lib/src/model/surreal-utils.js +0 -128
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +0 -75
- package/src/PubSub.ts +0 -17
- package/src/agent/AgentResolver.ts +0 -263
- package/src/ai/AIResolver.ts +0 -372
- package/src/buildSchema.ts +0 -43
- package/src/expression/ExpressionResolver.ts +0 -64
- package/src/language/LanguageContext.ts +0 -37
- package/src/language/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/hydration-batch.ts +0 -205
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-sparql-batch.ts +0 -301
- package/src/model/subscription-pool.ts +0 -163
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -364
- package/src/runtime/RuntimeResolver.ts +0 -749
- package/src/unwrapApolloResult.ts +0 -16
- package/tsconfig-browser.json +0 -82
|
@@ -619,26 +619,18 @@ describe("Ad4mModel.queryToSPARQL()", () => {
|
|
|
619
619
|
expect(norm).toContain("&&");
|
|
620
620
|
});
|
|
621
621
|
// ---- ORDER BY, LIMIT, OFFSET are JS post-processed ----
|
|
622
|
-
it("should
|
|
623
|
-
const query = await Recipe.queryToSPARQL(mockPerspective, { order: { name: "ASC" } });
|
|
622
|
+
it("should include ORDER BY/LIMIT/OFFSET in SPARQL pagination subquery", async () => {
|
|
623
|
+
const query = await Recipe.queryToSPARQL(mockPerspective, { order: { name: "ASC" }, limit: 10, offset: 5 });
|
|
624
624
|
const norm = normalizeQuery(query);
|
|
625
625
|
expect(norm).toContain("SELECT ?source");
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
expect(norm).toContain("SELECT ?source");
|
|
632
|
-
expect(norm).not.toContain("LIMIT");
|
|
633
|
-
});
|
|
634
|
-
it("should not include OFFSET in SPARQL (JS post-processed)", async () => {
|
|
635
|
-
const query = await Recipe.queryToSPARQL(mockPerspective, { offset: 5 });
|
|
636
|
-
const norm = normalizeQuery(query);
|
|
637
|
-
expect(norm).toContain("SELECT ?source");
|
|
638
|
-
expect(norm).not.toContain("OFFSET");
|
|
626
|
+
// SPARQL-level pagination via subquery
|
|
627
|
+
expect(norm).toContain("ORDER BY");
|
|
628
|
+
expect(norm).toContain("LIMIT 10");
|
|
629
|
+
expect(norm).toContain("OFFSET 5");
|
|
630
|
+
expect(norm).toContain("SELECT DISTINCT ?source");
|
|
639
631
|
});
|
|
640
632
|
});
|
|
641
|
-
describe("Ad4mModel
|
|
633
|
+
describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
642
634
|
// Test Recipe model
|
|
643
635
|
let Recipe = class Recipe extends Ad4mModel {
|
|
644
636
|
constructor() {
|
|
@@ -663,9 +655,10 @@ describe("Ad4mModel.instancesFromQueryResult() and SPARQL integration", () => {
|
|
|
663
655
|
Recipe = __decorate([
|
|
664
656
|
Model({ name: "Recipe" })
|
|
665
657
|
], Recipe);
|
|
666
|
-
// Mock perspective with
|
|
658
|
+
// Mock perspective with querySparql, modelQuery, and infer methods
|
|
667
659
|
const mockPerspective = {
|
|
668
660
|
querySparql: jest.fn(),
|
|
661
|
+
modelQuery: jest.fn(),
|
|
669
662
|
infer: jest.fn(),
|
|
670
663
|
uuid: 'test-perspective-uuid',
|
|
671
664
|
stringOrTemplateObjectToSubjectClassName: jest.fn().mockResolvedValue('Recipe')
|
|
@@ -673,246 +666,137 @@ describe("Ad4mModel.instancesFromQueryResult() and SPARQL integration", () => {
|
|
|
673
666
|
beforeEach(() => {
|
|
674
667
|
jest.clearAllMocks();
|
|
675
668
|
});
|
|
676
|
-
it("should convert empty query results correctly", async () => {
|
|
677
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, {}, []);
|
|
678
|
-
expect(result.results).toEqual([]);
|
|
679
|
-
expect(result.totalCount).toBe(0);
|
|
680
|
-
});
|
|
681
|
-
it("should convert query results to model instances", async () => {
|
|
682
|
-
const queryResults = [
|
|
683
|
-
{
|
|
684
|
-
source: "node:abc123",
|
|
685
|
-
source_uri: "literal:recipe1",
|
|
686
|
-
links: [
|
|
687
|
-
{ predicate: "recipe://name", target: "Pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
688
|
-
{ predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
689
|
-
{ predicate: "recipe://ingredient", target: "pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
690
|
-
{ predicate: "recipe://ingredient", target: "tomato", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
691
|
-
{ predicate: "recipe://ingredient", target: "cheese", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
692
|
-
]
|
|
693
|
-
},
|
|
694
|
-
{
|
|
695
|
-
source: "node:def456",
|
|
696
|
-
source_uri: "literal:recipe2",
|
|
697
|
-
links: [
|
|
698
|
-
{ predicate: "recipe://name", target: "Pizza", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
699
|
-
{ predicate: "recipe://rating", target: "4", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
700
|
-
{ predicate: "recipe://ingredient", target: "dough", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
701
|
-
{ predicate: "recipe://ingredient", target: "cheese", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
702
|
-
{ predicate: "recipe://ingredient", target: "tomato", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" }
|
|
703
|
-
]
|
|
704
|
-
}
|
|
705
|
-
];
|
|
706
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, {}, queryResults);
|
|
707
|
-
expect(result.results).toHaveLength(2);
|
|
708
|
-
expect(result.totalCount).toBe(2);
|
|
709
|
-
const recipe1 = result.results[0];
|
|
710
|
-
expect(recipe1).toBeInstanceOf(Recipe);
|
|
711
|
-
expect(recipe1.name).toBe("Pasta");
|
|
712
|
-
expect(recipe1.rating).toBe(5);
|
|
713
|
-
expect(recipe1.ingredients).toEqual(["pasta", "tomato", "cheese"]);
|
|
714
|
-
const recipe2 = result.results[1];
|
|
715
|
-
expect(recipe2).toBeInstanceOf(Recipe);
|
|
716
|
-
expect(recipe2.name).toBe("Pizza");
|
|
717
|
-
expect(recipe2.rating).toBe(4);
|
|
718
|
-
});
|
|
719
|
-
it("should filter properties when query specifies properties", async () => {
|
|
720
|
-
const queryResults = [
|
|
721
|
-
{
|
|
722
|
-
source: "node:abc123",
|
|
723
|
-
source_uri: "literal:recipe1",
|
|
724
|
-
links: [
|
|
725
|
-
{ predicate: "recipe://name", target: "Pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
726
|
-
{ predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
727
|
-
{ predicate: "recipe://ingredient", target: "pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
728
|
-
{ predicate: "recipe://ingredient", target: "tomato", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
729
|
-
]
|
|
730
|
-
}
|
|
731
|
-
];
|
|
732
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, { properties: ["name"] }, queryResults);
|
|
733
|
-
expect(result.results).toHaveLength(1);
|
|
734
|
-
const recipe = result.results[0];
|
|
735
|
-
expect(recipe.name).toBe("Pasta");
|
|
736
|
-
// rating and ingredients should be removed since only "name" was requested
|
|
737
|
-
expect(recipe.rating).toBeUndefined();
|
|
738
|
-
expect(recipe.ingredients).toBeUndefined();
|
|
739
|
-
// author, createdAt, updatedAt are also stripped unless explicitly requested
|
|
740
|
-
expect(recipe.author).toBeUndefined();
|
|
741
|
-
expect(recipe.timestamp).toBeUndefined();
|
|
742
|
-
});
|
|
743
|
-
it("should filter properties when query specifies properties", async () => {
|
|
744
|
-
const queryResults = [
|
|
745
|
-
{
|
|
746
|
-
source: "node:abc123",
|
|
747
|
-
source_uri: "literal:recipe1",
|
|
748
|
-
links: [
|
|
749
|
-
{ predicate: "recipe://name", target: "Pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
750
|
-
{ predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
751
|
-
{ predicate: "recipe://ingredient", target: "pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
752
|
-
{ predicate: "recipe://ingredient", target: "tomato", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
753
|
-
]
|
|
754
|
-
}
|
|
755
|
-
];
|
|
756
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, { properties: ["name"] }, queryResults);
|
|
757
|
-
expect(result.results).toHaveLength(1);
|
|
758
|
-
const recipe = result.results[0];
|
|
759
|
-
expect(recipe.name).toBe("Pasta");
|
|
760
|
-
// rating and ingredients should be removed since only "name" was requested
|
|
761
|
-
expect(recipe.rating).toBeUndefined();
|
|
762
|
-
});
|
|
763
|
-
it("should handle results missing base field", async () => {
|
|
764
|
-
const queryResults = [
|
|
765
|
-
{
|
|
766
|
-
links: [
|
|
767
|
-
{ predicate: "recipe://name", target: "Pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
768
|
-
{ predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
769
|
-
]
|
|
770
|
-
// Missing source field
|
|
771
|
-
}
|
|
772
|
-
];
|
|
773
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, {}, queryResults);
|
|
774
|
-
// Should filter out the invalid result (or handle gracefully)
|
|
775
|
-
expect(result.results).toHaveLength(0);
|
|
776
|
-
expect(result.totalCount).toBe(0);
|
|
777
|
-
});
|
|
778
669
|
it("should use SPARQL when engine is 'sparql' in findAll()", async () => {
|
|
779
|
-
//
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
670
|
+
// modelQuery returns already-hydrated instances from the Rust executor
|
|
671
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
672
|
+
instances: [
|
|
673
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
674
|
+
],
|
|
675
|
+
totalCount: 1
|
|
676
|
+
});
|
|
786
677
|
const results = await Recipe.findAll(mockPerspective, {}, 'sparql');
|
|
787
|
-
expect(mockPerspective.
|
|
678
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
788
679
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
789
680
|
expect(results).toHaveLength(1);
|
|
790
681
|
expect(results[0].name).toBe("Pasta");
|
|
791
682
|
});
|
|
792
|
-
it("should
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
mockPerspective.infer.mockResolvedValue(prologResults);
|
|
683
|
+
it("should route through modelQuery when engine is 'prolog' in findAll() (prolog is now no-op)", async () => {
|
|
684
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
685
|
+
instances: [
|
|
686
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
687
|
+
],
|
|
688
|
+
totalCount: 1
|
|
689
|
+
});
|
|
800
690
|
const results = await Recipe.findAll(mockPerspective, {}, false);
|
|
801
|
-
expect(mockPerspective.
|
|
802
|
-
expect(mockPerspective.
|
|
691
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
692
|
+
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
803
693
|
expect(results).toHaveLength(1);
|
|
804
694
|
});
|
|
805
695
|
it("should use SPARQL when engine is 'sparql' in findAllAndCount()", async () => {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
const { results, totalCount } = await Recipe.findAllAndCount(mockPerspective, {}
|
|
813
|
-
expect(mockPerspective.
|
|
696
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
697
|
+
instances: [
|
|
698
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
699
|
+
],
|
|
700
|
+
totalCount: 1
|
|
701
|
+
});
|
|
702
|
+
const { results, totalCount } = await Recipe.findAllAndCount(mockPerspective, {});
|
|
703
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
814
704
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
815
705
|
expect(results).toHaveLength(1);
|
|
816
706
|
expect(totalCount).toBe(1);
|
|
817
707
|
});
|
|
818
708
|
it("should use SPARQL when engine is 'sparql' in paginate()", async () => {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
const page = await Recipe.paginate(mockPerspective, 10, 1, {}
|
|
826
|
-
expect(mockPerspective.
|
|
709
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
710
|
+
instances: [
|
|
711
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
712
|
+
],
|
|
713
|
+
totalCount: 1
|
|
714
|
+
});
|
|
715
|
+
const page = await Recipe.paginate(mockPerspective, 10, 1, {});
|
|
716
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
827
717
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
828
718
|
expect(page.results).toHaveLength(1);
|
|
829
719
|
expect(page.pageSize).toBe(10);
|
|
830
720
|
expect(page.pageNumber).toBe(1);
|
|
721
|
+
expect(page.totalCount).toBe(1);
|
|
831
722
|
});
|
|
832
|
-
it("should use SPARQL
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
]).flat()
|
|
840
|
-
];
|
|
841
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
842
|
-
const count = await Recipe.count(mockPerspective, {}, 'sparql');
|
|
843
|
-
expect(mockPerspective.querySparql).toHaveBeenCalledTimes(1);
|
|
723
|
+
it("should use SPARQL in count()", async () => {
|
|
724
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
725
|
+
instances: [],
|
|
726
|
+
totalCount: 5
|
|
727
|
+
});
|
|
728
|
+
const count = await Recipe.count(mockPerspective, {});
|
|
729
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
844
730
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
845
731
|
expect(count).toBe(5);
|
|
846
732
|
});
|
|
847
|
-
it("should
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
733
|
+
it("should return count from modelQuery", async () => {
|
|
734
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
735
|
+
instances: [],
|
|
736
|
+
totalCount: 10
|
|
737
|
+
});
|
|
738
|
+
const count = await Recipe.count(mockPerspective, {});
|
|
739
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
852
740
|
expect(mockPerspective.querySparql).not.toHaveBeenCalled();
|
|
853
741
|
expect(count).toBe(10);
|
|
854
742
|
});
|
|
855
743
|
it("should use SPARQL when engine is 'sparql' in ModelQueryBuilder.get()", async () => {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
744
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
745
|
+
instances: [
|
|
746
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
747
|
+
],
|
|
748
|
+
totalCount: 1
|
|
749
|
+
});
|
|
862
750
|
const results = await Recipe.query(mockPerspective)
|
|
863
751
|
.where({ name: "Pasta" })
|
|
864
752
|
.engine('sparql')
|
|
865
753
|
.get();
|
|
866
|
-
expect(mockPerspective.
|
|
754
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
867
755
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
868
756
|
expect(results).toHaveLength(1);
|
|
869
757
|
expect(results[0].name).toBe("Pasta");
|
|
870
758
|
});
|
|
871
|
-
it("should use
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
mockPerspective.infer.mockResolvedValue(prologResults);
|
|
759
|
+
it("should use modelQuery when .engine('prolog') is called (engine is now a no-op)", async () => {
|
|
760
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
761
|
+
instances: [
|
|
762
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
763
|
+
],
|
|
764
|
+
totalCount: 1
|
|
765
|
+
});
|
|
879
766
|
const results = await Recipe.query(mockPerspective)
|
|
880
767
|
.where({ name: "Pasta" })
|
|
881
768
|
.engine('prolog')
|
|
882
769
|
.get();
|
|
883
|
-
|
|
884
|
-
expect(mockPerspective.
|
|
770
|
+
// engine('prolog') is now a no-op — everything goes through modelQuery
|
|
771
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
772
|
+
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
885
773
|
expect(results).toHaveLength(1);
|
|
886
774
|
});
|
|
887
775
|
it("should use SPARQL when engine is 'sparql' in ModelQueryBuilder.count()", async () => {
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
893
|
-
]).flat()
|
|
894
|
-
];
|
|
895
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
776
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
777
|
+
instances: [],
|
|
778
|
+
totalCount: 3
|
|
779
|
+
});
|
|
896
780
|
const count = await Recipe.query(mockPerspective)
|
|
897
781
|
.where({ rating: { gt: 4 } })
|
|
898
782
|
.engine('sparql')
|
|
899
783
|
.count();
|
|
900
|
-
expect(mockPerspective.
|
|
784
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
901
785
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
902
786
|
expect(count).toBe(3);
|
|
903
787
|
});
|
|
904
788
|
it("should use SPARQL when engine is 'sparql' in ModelQueryBuilder.paginate()", async () => {
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
789
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
790
|
+
instances: [
|
|
791
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
792
|
+
],
|
|
793
|
+
totalCount: 1
|
|
794
|
+
});
|
|
911
795
|
const page = await Recipe.query(mockPerspective)
|
|
912
796
|
.where({ rating: { gt: 3 } })
|
|
913
797
|
.engine('sparql')
|
|
914
798
|
.paginate(10, 1);
|
|
915
|
-
expect(mockPerspective.
|
|
799
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
916
800
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
917
801
|
expect(page.results).toHaveLength(1);
|
|
918
802
|
expect(page.pageSize).toBe(10);
|
|
@@ -947,6 +831,7 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
947
831
|
// Mock perspective
|
|
948
832
|
const mockPerspective = {
|
|
949
833
|
querySparql: jest.fn(),
|
|
834
|
+
modelQuery: jest.fn(),
|
|
950
835
|
infer: jest.fn(),
|
|
951
836
|
uuid: 'test-perspective-uuid',
|
|
952
837
|
stringOrTemplateObjectToSubjectClassName: jest.fn().mockResolvedValue('Recipe')
|
|
@@ -954,128 +839,78 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
954
839
|
beforeEach(() => {
|
|
955
840
|
jest.clearAllMocks();
|
|
956
841
|
});
|
|
957
|
-
it("should apply
|
|
958
|
-
//
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
]).flat()
|
|
964
|
-
];
|
|
965
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
842
|
+
it("should apply filtering for gt operator on properties in SPARQL count()", async () => {
|
|
843
|
+
// With the new modelQuery endpoint, filtering happens server-side in Rust
|
|
844
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
845
|
+
instances: [],
|
|
846
|
+
totalCount: 2
|
|
847
|
+
});
|
|
966
848
|
// Count recipes with rating > 3 (should match 2 recipes: rating 4 and 5)
|
|
967
|
-
const count = await Recipe.count(mockPerspective, { where: { rating: { gt: 3 } } }
|
|
968
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
969
|
-
const findAllResults = await Recipe.findAll(mockPerspective, { where: { rating: { gt: 3 } } }, 'sparql');
|
|
849
|
+
const count = await Recipe.count(mockPerspective, { where: { rating: { gt: 3 } } });
|
|
970
850
|
expect(count).toBe(2);
|
|
971
|
-
expect(
|
|
972
|
-
});
|
|
973
|
-
it("should apply
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: `${i + 1}`, author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
979
|
-
]).flat()
|
|
980
|
-
];
|
|
981
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
851
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalled();
|
|
852
|
+
});
|
|
853
|
+
it("should apply filtering for between operator on properties in SPARQL count()", async () => {
|
|
854
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
855
|
+
instances: [],
|
|
856
|
+
totalCount: 3
|
|
857
|
+
});
|
|
982
858
|
// Count recipes with rating between 2 and 4 (should match 3 recipes: rating 2, 3, 4)
|
|
983
|
-
const count = await Recipe.count(mockPerspective, { where: { rating: { between: [2, 4] } } }
|
|
984
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
985
|
-
const findAllResults = await Recipe.findAll(mockPerspective, { where: { rating: { between: [2, 4] } } }, 'sparql');
|
|
859
|
+
const count = await Recipe.count(mockPerspective, { where: { rating: { between: [2, 4] } } });
|
|
986
860
|
expect(count).toBe(3);
|
|
987
|
-
expect(
|
|
988
|
-
});
|
|
989
|
-
it("should apply
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: `2023-01-0${i + 1}T00:00:00Z` }
|
|
995
|
-
]).flat()
|
|
996
|
-
];
|
|
997
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
998
|
-
// Count recipes with timestamp > 2023-01-03 (should match 2 recipes: 2023-01-04 and 2023-01-05)
|
|
861
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalled();
|
|
862
|
+
});
|
|
863
|
+
it("should apply filtering for timestamp gt operator in SPARQL count()", async () => {
|
|
864
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
865
|
+
instances: [],
|
|
866
|
+
totalCount: 2
|
|
867
|
+
});
|
|
999
868
|
const targetTimestamp = new Date("2023-01-03T00:00:00Z").getTime();
|
|
1000
|
-
const count = await Recipe.count(mockPerspective, { where: { timestamp: { gt: targetTimestamp } } }
|
|
1001
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
1002
|
-
const findAllResults = await Recipe.findAll(mockPerspective, { where: { timestamp: { gt: targetTimestamp } } }, 'sparql');
|
|
869
|
+
const count = await Recipe.count(mockPerspective, { where: { timestamp: { gt: targetTimestamp } } });
|
|
1003
870
|
expect(count).toBe(2);
|
|
1004
|
-
expect(
|
|
1005
|
-
});
|
|
1006
|
-
it("should apply
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: `2023-01-0${i + 1}T00:00:00Z` }
|
|
1012
|
-
]).flat()
|
|
1013
|
-
];
|
|
1014
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
1015
|
-
// Count recipes with timestamp between 2023-01-02 and 2023-01-04
|
|
871
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalled();
|
|
872
|
+
});
|
|
873
|
+
it("should apply filtering for timestamp between operator in SPARQL count()", async () => {
|
|
874
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
875
|
+
instances: [],
|
|
876
|
+
totalCount: 3
|
|
877
|
+
});
|
|
1016
878
|
const startTimestamp = new Date("2023-01-02T00:00:00Z").getTime();
|
|
1017
879
|
const endTimestamp = new Date("2023-01-04T00:00:00Z").getTime();
|
|
1018
880
|
const count = await Recipe.count(mockPerspective, {
|
|
1019
881
|
where: { timestamp: { between: [startTimestamp, endTimestamp] } }
|
|
1020
|
-
}
|
|
1021
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
1022
|
-
const findAllResults = await Recipe.findAll(mockPerspective, {
|
|
1023
|
-
where: { timestamp: { between: [startTimestamp, endTimestamp] } }
|
|
1024
|
-
}, 'sparql');
|
|
882
|
+
});
|
|
1025
883
|
expect(count).toBe(3);
|
|
1026
|
-
expect(
|
|
1027
|
-
});
|
|
1028
|
-
it("should apply
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
1034
|
-
]).flat(),
|
|
1035
|
-
...Array.from({ length: 2 }, (_, i) => [
|
|
1036
|
-
{ source: `literal:recipe${i + 4}`, predicate: "recipe://name", target: `Recipe ${i + 4}`, author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
1037
|
-
{ source: `literal:recipe${i + 4}`, predicate: "recipe://rating", target: "5", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" }
|
|
1038
|
-
]).flat()
|
|
1039
|
-
];
|
|
1040
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
884
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalled();
|
|
885
|
+
});
|
|
886
|
+
it("should apply filtering for author filtering in SPARQL count()", async () => {
|
|
887
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
888
|
+
instances: [],
|
|
889
|
+
totalCount: 3
|
|
890
|
+
});
|
|
1041
891
|
// Count recipes by Alice (should match 3 recipes)
|
|
1042
|
-
const count = await Recipe.count(mockPerspective, { where: { author: "did:key:alice" } }
|
|
1043
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
1044
|
-
const findAllResults = await Recipe.findAll(mockPerspective, { where: { author: "did:key:alice" } }, 'sparql');
|
|
892
|
+
const count = await Recipe.count(mockPerspective, { where: { author: "did:key:alice" } });
|
|
1045
893
|
expect(count).toBe(3);
|
|
1046
|
-
expect(
|
|
1047
|
-
});
|
|
1048
|
-
it("should apply
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: `${i + 1}`, author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
1054
|
-
]).flat()
|
|
1055
|
-
];
|
|
1056
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
894
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalled();
|
|
895
|
+
});
|
|
896
|
+
it("should apply filtering in ModelQueryBuilder.count() with gt operator", async () => {
|
|
897
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
898
|
+
instances: [],
|
|
899
|
+
totalCount: 2
|
|
900
|
+
});
|
|
1057
901
|
// Count recipes with rating > 3 using ModelQueryBuilder
|
|
1058
902
|
const count = await Recipe.query(mockPerspective)
|
|
1059
903
|
.where({ rating: { gt: 3 } })
|
|
1060
904
|
.engine('sparql')
|
|
1061
905
|
.count();
|
|
1062
|
-
// Verify count matches the number of instances that would be returned by get()
|
|
1063
|
-
const getResults = await Recipe.query(mockPerspective)
|
|
1064
|
-
.where({ rating: { gt: 3 } })
|
|
1065
|
-
.engine('sparql')
|
|
1066
|
-
.get();
|
|
1067
906
|
expect(count).toBe(2);
|
|
1068
|
-
expect(
|
|
1069
|
-
});
|
|
1070
|
-
it("should apply
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: `2023-01-0${i + 1}T00:00:00Z` }
|
|
1076
|
-
]).flat()
|
|
1077
|
-
];
|
|
1078
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
907
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalled();
|
|
908
|
+
});
|
|
909
|
+
it("should apply filtering in ModelQueryBuilder.count() with timestamp between", async () => {
|
|
910
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
911
|
+
instances: [],
|
|
912
|
+
totalCount: 3
|
|
913
|
+
});
|
|
1079
914
|
const startTimestamp = new Date("2023-01-02T00:00:00Z").getTime();
|
|
1080
915
|
const endTimestamp = new Date("2023-01-04T00:00:00Z").getTime();
|
|
1081
916
|
// Count using ModelQueryBuilder
|
|
@@ -1083,96 +918,8 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
1083
918
|
.where({ timestamp: { between: [startTimestamp, endTimestamp] } })
|
|
1084
919
|
.engine('sparql')
|
|
1085
920
|
.count();
|
|
1086
|
-
// Verify count matches the number of instances that would be returned by get()
|
|
1087
|
-
const getResults = await Recipe.query(mockPerspective)
|
|
1088
|
-
.where({ timestamp: { between: [startTimestamp, endTimestamp] } })
|
|
1089
|
-
.engine('sparql')
|
|
1090
|
-
.get();
|
|
1091
|
-
expect(count).toBe(3);
|
|
1092
|
-
expect(count).toBe(getResults.length);
|
|
1093
|
-
});
|
|
1094
|
-
it("should handle count() with Prolog for gt operator (legacy)", async () => {
|
|
1095
|
-
const prologResults = [{ TotalCount: 2 }];
|
|
1096
|
-
mockPerspective.infer.mockResolvedValue(prologResults);
|
|
1097
|
-
const count = await Recipe.count(mockPerspective, { where: { rating: { gt: 3 } } }, false);
|
|
1098
|
-
expect(mockPerspective.infer).toHaveBeenCalledTimes(1);
|
|
1099
|
-
expect(mockPerspective.querySparql).not.toHaveBeenCalled();
|
|
1100
|
-
expect(count).toBe(2);
|
|
1101
|
-
});
|
|
1102
|
-
it("should handle count() with Prolog for timestamp between (legacy)", async () => {
|
|
1103
|
-
const prologResults = [{ TotalCount: 3 }];
|
|
1104
|
-
mockPerspective.infer.mockResolvedValue(prologResults);
|
|
1105
|
-
const startTimestamp = new Date("2023-01-02T00:00:00Z").getTime();
|
|
1106
|
-
const endTimestamp = new Date("2023-01-04T00:00:00Z").getTime();
|
|
1107
|
-
const count = await Recipe.count(mockPerspective, { where: { timestamp: { between: [startTimestamp, endTimestamp] } } }, false);
|
|
1108
|
-
expect(mockPerspective.infer).toHaveBeenCalledTimes(1);
|
|
1109
|
-
expect(mockPerspective.querySparql).not.toHaveBeenCalled();
|
|
1110
921
|
expect(count).toBe(3);
|
|
1111
|
-
|
|
1112
|
-
});
|
|
1113
|
-
// ──────────────────────────────────────────────────────────
|
|
1114
|
-
// Batch SPARQL query builder tests
|
|
1115
|
-
// ──────────────────────────────────────────────────────────
|
|
1116
|
-
import { buildBatchSPARQLQuery } from "./query-sparql-batch";
|
|
1117
|
-
describe("buildBatchSPARQLQuery", () => {
|
|
1118
|
-
let Author = class Author extends Ad4mModel {
|
|
1119
|
-
};
|
|
1120
|
-
__decorate([
|
|
1121
|
-
Property({ through: "author://name", required: true }),
|
|
1122
|
-
__metadata("design:type", String)
|
|
1123
|
-
], Author.prototype, "name", void 0);
|
|
1124
|
-
Author = __decorate([
|
|
1125
|
-
Model({ name: "Author" })
|
|
1126
|
-
], Author);
|
|
1127
|
-
let Book = class Book extends Ad4mModel {
|
|
1128
|
-
};
|
|
1129
|
-
__decorate([
|
|
1130
|
-
Property({ through: "book://title", required: true }),
|
|
1131
|
-
__metadata("design:type", String)
|
|
1132
|
-
], Book.prototype, "title", void 0);
|
|
1133
|
-
__decorate([
|
|
1134
|
-
HasMany(() => Author, { through: "book://author" }),
|
|
1135
|
-
__metadata("design:type", Array)
|
|
1136
|
-
], Book.prototype, "authors", void 0);
|
|
1137
|
-
Book = __decorate([
|
|
1138
|
-
Model({ name: "Book" })
|
|
1139
|
-
], Book);
|
|
1140
|
-
it("should generate UNION branches for depth 0 and depth 1 includes", () => {
|
|
1141
|
-
const metadata = Book.getModelMetadata();
|
|
1142
|
-
const query = { include: { authors: true } };
|
|
1143
|
-
const sparql = buildBatchSPARQLQuery(metadata, query, Book);
|
|
1144
|
-
expect(sparql).toContain("?depth");
|
|
1145
|
-
expect(sparql).toContain("?parentBase");
|
|
1146
|
-
expect(sparql).toContain("?relationName");
|
|
1147
|
-
expect(sparql).toContain("UNION");
|
|
1148
|
-
expect(sparql).toContain("BIND(\"0\" AS ?depth)");
|
|
1149
|
-
expect(sparql).toContain("BIND(\"1\" AS ?depth)");
|
|
1150
|
-
expect(sparql).toContain("book://author");
|
|
1151
|
-
});
|
|
1152
|
-
it("should include parent filter when query.parent is specified", () => {
|
|
1153
|
-
const metadata = Book.getModelMetadata();
|
|
1154
|
-
const query = {
|
|
1155
|
-
parent: { id: "flux://library1", predicate: "library://books" },
|
|
1156
|
-
include: { authors: true },
|
|
1157
|
-
};
|
|
1158
|
-
const sparql = buildBatchSPARQLQuery(metadata, query, Book);
|
|
1159
|
-
expect(sparql).toContain("flux://library1");
|
|
1160
|
-
expect(sparql).toContain("library://books");
|
|
1161
|
-
});
|
|
1162
|
-
it("should include where filter for simple equality", () => {
|
|
1163
|
-
const metadata = Book.getModelMetadata();
|
|
1164
|
-
const query = {
|
|
1165
|
-
where: { title: "My Book" },
|
|
1166
|
-
include: { authors: true },
|
|
1167
|
-
};
|
|
1168
|
-
const sparql = buildBatchSPARQLQuery(metadata, query, Book);
|
|
1169
|
-
// For literal-stored properties, SPARQL only has a JOIN (no FILTER value) — filtering in JS
|
|
1170
|
-
expect(sparql).toContain("book://title");
|
|
1171
|
-
expect(sparql).toContain("root_wTarget_eq_title");
|
|
1172
|
-
});
|
|
1173
|
-
it("should throw when include is empty", () => {
|
|
1174
|
-
const metadata = Book.getModelMetadata();
|
|
1175
|
-
expect(() => buildBatchSPARQLQuery(metadata, {}, Book)).toThrow("requires query.include");
|
|
922
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalled();
|
|
1176
923
|
});
|
|
1177
924
|
});
|
|
1178
925
|
describe("SPARQL comparison filters", () => {
|
|
@@ -1211,7 +958,7 @@ describe("SPARQL comparison filters", () => {
|
|
|
1211
958
|
// ──────────────────────────────────────────────────────────
|
|
1212
959
|
// SPARQL Direct Triple Pattern & IRI Tests
|
|
1213
960
|
// ──────────────────────────────────────────────────────────
|
|
1214
|
-
import { buildSPARQLQuery,
|
|
961
|
+
import { buildSPARQLQuery, formatSPARQLValue } from "./query-sparql";
|
|
1215
962
|
describe("SPARQL direct triple pattern generation", () => {
|
|
1216
963
|
let Channel = class Channel extends Ad4mModel {
|
|
1217
964
|
constructor() {
|
|
@@ -1259,68 +1006,20 @@ describe("SPARQL direct triple pattern generation", () => {
|
|
|
1259
1006
|
expect(query).toContain("<flux://name>");
|
|
1260
1007
|
expect(query).toMatch(/\?source\s+<flux:\/\/name>\s+\?cfTarget_name/);
|
|
1261
1008
|
});
|
|
1262
|
-
it("uses
|
|
1009
|
+
it("uses RDF 1.2 reifier pattern for author/timestamp", async () => {
|
|
1263
1010
|
const query = await Channel.queryToSPARQL(mockPersp, {});
|
|
1264
|
-
expect(query).toContain("
|
|
1265
|
-
expect(query).toContain("?
|
|
1266
|
-
expect(query).toContain("?
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
expect(query).not.toContain("BIND(<<");
|
|
1271
|
-
expect(query).not.toContain("?ann ");
|
|
1011
|
+
expect(query).toContain("<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies>");
|
|
1012
|
+
expect(query).toContain("?source ?predicate ?target .");
|
|
1013
|
+
expect(query).toContain("?_reifier <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<( ?source ?predicate ?target )>>");
|
|
1014
|
+
expect(query).toContain("?_reifier <ad4m://ontology/author> ?author");
|
|
1015
|
+
expect(query).toContain("?_reifier <ad4m://ontology/timestamp> ?timestamp");
|
|
1016
|
+
expect(query).not.toContain("GRAPH");
|
|
1272
1017
|
});
|
|
1273
1018
|
it("uses FILTER(isIRI(?source)) to exclude non-IRI subjects", async () => {
|
|
1274
1019
|
const query = await Channel.queryToSPARQL(mockPersp, {});
|
|
1275
1020
|
expect(query).toContain("FILTER(isIRI(?source)");
|
|
1276
1021
|
});
|
|
1277
1022
|
});
|
|
1278
|
-
describe("SPARQL IRI formatting", () => {
|
|
1279
|
-
it("wraps AD4M URIs in angle brackets", () => {
|
|
1280
|
-
const query = buildSPARQLGetDataQuery("ad4m://test123");
|
|
1281
|
-
expect(query).toContain("<ad4m://test123>");
|
|
1282
|
-
});
|
|
1283
|
-
it("wraps literal: URIs in angle brackets", () => {
|
|
1284
|
-
const query = buildSPARQLGetDataQuery("literal:string:foo");
|
|
1285
|
-
expect(query).toContain("<literal:string:foo>");
|
|
1286
|
-
});
|
|
1287
|
-
it("wraps flux:// URIs in angle brackets", () => {
|
|
1288
|
-
const query = buildSPARQLGetDataQuery("flux://has_channel");
|
|
1289
|
-
expect(query).toContain("<flux://has_channel>");
|
|
1290
|
-
});
|
|
1291
|
-
it("wraps did:key URIs in angle brackets", () => {
|
|
1292
|
-
const query = buildSPARQLGetDataQuery("did:key:z6MkhaXg");
|
|
1293
|
-
expect(query).toContain("<did:key:z6MkhaXg>");
|
|
1294
|
-
});
|
|
1295
|
-
});
|
|
1296
|
-
describe("groupSPARQLResults", () => {
|
|
1297
|
-
it("groups flat rows by source URI", () => {
|
|
1298
|
-
const rows = [
|
|
1299
|
-
{ source: "ad4m://a", predicate: "p1", target: "t1", author: "auth1", timestamp: "ts1" },
|
|
1300
|
-
{ source: "ad4m://a", predicate: "p2", target: "t2", author: "auth1", timestamp: "ts1" },
|
|
1301
|
-
{ source: "ad4m://b", predicate: "p1", target: "t3", author: "auth2", timestamp: "ts2" },
|
|
1302
|
-
];
|
|
1303
|
-
const grouped = groupSPARQLResults(rows);
|
|
1304
|
-
expect(grouped).toHaveLength(2);
|
|
1305
|
-
const aGroup = grouped.find(g => g.source_uri === "ad4m://a");
|
|
1306
|
-
expect(aGroup).toBeDefined();
|
|
1307
|
-
expect(aGroup.links).toHaveLength(2);
|
|
1308
|
-
const bGroup = grouped.find(g => g.source_uri === "ad4m://b");
|
|
1309
|
-
expect(bGroup).toBeDefined();
|
|
1310
|
-
expect(bGroup.links).toHaveLength(1);
|
|
1311
|
-
});
|
|
1312
|
-
it("returns empty array for empty input", () => {
|
|
1313
|
-
expect(groupSPARQLResults([])).toEqual([]);
|
|
1314
|
-
});
|
|
1315
|
-
it("preserves metadata in grouped links", () => {
|
|
1316
|
-
const rows = [
|
|
1317
|
-
{ source: "x", predicate: "p", target: "t", author: "did:key:z6Mk", timestamp: "2024-01-01T00:00:00Z" },
|
|
1318
|
-
];
|
|
1319
|
-
const grouped = groupSPARQLResults(rows);
|
|
1320
|
-
expect(grouped[0].links[0].author).toBe("did:key:z6Mk");
|
|
1321
|
-
expect(grouped[0].links[0].timestamp).toBe("2024-01-01T00:00:00Z");
|
|
1322
|
-
});
|
|
1323
|
-
});
|
|
1324
1023
|
describe("formatSPARQLValue", () => {
|
|
1325
1024
|
it("wraps strings in double quotes", () => {
|
|
1326
1025
|
expect(formatSPARQLValue("hello")).toBe('"hello"');
|
|
@@ -1335,7 +1034,7 @@ describe("formatSPARQLValue", () => {
|
|
|
1335
1034
|
// ──────────────────────────────────────────────────────────
|
|
1336
1035
|
// Comprehensive SPARQL migration unit tests
|
|
1337
1036
|
// ──────────────────────────────────────────────────────────
|
|
1338
|
-
import { matchesCondition
|
|
1037
|
+
import { matchesCondition } from "./hydration";
|
|
1339
1038
|
import { Literal } from "../Literal";
|
|
1340
1039
|
// Helper: create literal URLs using JSON encoding (which handles all types including booleans)
|
|
1341
1040
|
function literalUrl(value) {
|
|
@@ -1433,207 +1132,6 @@ describe("matchesCondition()", () => {
|
|
|
1433
1132
|
expect(matchesCondition(undefined, { not: "hello" })).toBe(true);
|
|
1434
1133
|
});
|
|
1435
1134
|
});
|
|
1436
|
-
describe("hydrateFromLinks()", () => {
|
|
1437
|
-
// Create a mock perspective that won't be called for literal properties
|
|
1438
|
-
const mockPerspective = {};
|
|
1439
|
-
let HydrationTest = class HydrationTest extends Ad4mModel {
|
|
1440
|
-
constructor() {
|
|
1441
|
-
super(...arguments);
|
|
1442
|
-
this.name = "";
|
|
1443
|
-
this.score = 0;
|
|
1444
|
-
this.active = false;
|
|
1445
|
-
}
|
|
1446
|
-
};
|
|
1447
|
-
__decorate([
|
|
1448
|
-
Property({ through: "test://name", resolveLanguage: "literal" }),
|
|
1449
|
-
__metadata("design:type", String)
|
|
1450
|
-
], HydrationTest.prototype, "name", void 0);
|
|
1451
|
-
__decorate([
|
|
1452
|
-
Property({ through: "test://score", resolveLanguage: "literal" }),
|
|
1453
|
-
__metadata("design:type", Number)
|
|
1454
|
-
], HydrationTest.prototype, "score", void 0);
|
|
1455
|
-
__decorate([
|
|
1456
|
-
Property({ through: "test://active", resolveLanguage: "literal" }),
|
|
1457
|
-
__metadata("design:type", Boolean)
|
|
1458
|
-
], HydrationTest.prototype, "active", void 0);
|
|
1459
|
-
HydrationTest = __decorate([
|
|
1460
|
-
Model({ name: "HydrationTest" })
|
|
1461
|
-
], HydrationTest);
|
|
1462
|
-
const metadata = HydrationTest.getModelMetadata();
|
|
1463
|
-
it("hydrates all properties when requestedProperties is undefined", async () => {
|
|
1464
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1465
|
-
const links = [
|
|
1466
|
-
{ predicate: "test://name", target: literalUrl("Alice"), author: "did:test", timestamp: "1000" },
|
|
1467
|
-
{ predicate: "test://score", target: literalUrl(42), author: "did:test", timestamp: "1000" },
|
|
1468
|
-
{ predicate: "test://active", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1469
|
-
];
|
|
1470
|
-
await hydrateFromLinks(instance, links, metadata, mockPerspective, undefined);
|
|
1471
|
-
expect(instance.name).toBe("Alice");
|
|
1472
|
-
expect(instance.score).toBe(42);
|
|
1473
|
-
expect(instance.active).toBe(true);
|
|
1474
|
-
});
|
|
1475
|
-
it("hydrates only requested properties when requestedProperties is provided", async () => {
|
|
1476
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1477
|
-
const links = [
|
|
1478
|
-
{ predicate: "test://name", target: literalUrl("Alice"), author: "did:test", timestamp: "1000" },
|
|
1479
|
-
{ predicate: "test://score", target: literalUrl(42), author: "did:test", timestamp: "1000" },
|
|
1480
|
-
{ predicate: "test://active", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1481
|
-
];
|
|
1482
|
-
await hydrateFromLinks(instance, links, metadata, mockPerspective, ["name"]);
|
|
1483
|
-
expect(instance.name).toBe("Alice");
|
|
1484
|
-
// score and active should remain at defaults since not requested
|
|
1485
|
-
expect(instance.score).toBe(0);
|
|
1486
|
-
expect(instance.active).toBe(false);
|
|
1487
|
-
});
|
|
1488
|
-
it("hydrates where-clause + projection properties when both are in requestedProperties", async () => {
|
|
1489
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1490
|
-
const links = [
|
|
1491
|
-
{ predicate: "test://name", target: literalUrl("Recipe 2"), author: "did:test", timestamp: "1000" },
|
|
1492
|
-
{ predicate: "test://active", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1493
|
-
];
|
|
1494
|
-
// Simulate merged hydration props: projection ["active"] + where clause props ["name"]
|
|
1495
|
-
await hydrateFromLinks(instance, links, metadata, mockPerspective, ["active", "name"]);
|
|
1496
|
-
expect(instance.name).toBe("Recipe 2");
|
|
1497
|
-
expect(instance.active).toBe(true);
|
|
1498
|
-
});
|
|
1499
|
-
it("sets author and timestamps from links", async () => {
|
|
1500
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1501
|
-
const links = [
|
|
1502
|
-
{ predicate: "test://name", target: literalUrl("Bob"), author: "did:author1", timestamp: "1000" },
|
|
1503
|
-
{ predicate: "test://score", target: literalUrl(10), author: "did:author2", timestamp: "2000" },
|
|
1504
|
-
];
|
|
1505
|
-
await hydrateFromLinks(instance, links, metadata, mockPerspective);
|
|
1506
|
-
expect(instance.author).toBe("did:author1");
|
|
1507
|
-
expect(instance.createdAt).toBe(1000);
|
|
1508
|
-
expect(instance.updatedAt).toBe(2000);
|
|
1509
|
-
});
|
|
1510
|
-
it("handles empty links array", async () => {
|
|
1511
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1512
|
-
await hydrateFromLinks(instance, [], metadata, mockPerspective);
|
|
1513
|
-
expect(instance.name).toBe("");
|
|
1514
|
-
expect(instance.score).toBe(0);
|
|
1515
|
-
});
|
|
1516
|
-
});
|
|
1517
|
-
describe("instancesFromQueryResult — where + properties interaction", () => {
|
|
1518
|
-
const mockPerspective = {
|
|
1519
|
-
get: jest.fn().mockResolvedValue([]),
|
|
1520
|
-
querySparql: jest.fn().mockResolvedValue([]),
|
|
1521
|
-
getExpression: jest.fn().mockResolvedValue(null),
|
|
1522
|
-
};
|
|
1523
|
-
let Recipe = class Recipe extends Ad4mModel {
|
|
1524
|
-
constructor() {
|
|
1525
|
-
super(...arguments);
|
|
1526
|
-
this.name = "";
|
|
1527
|
-
this.booleanTest = false;
|
|
1528
|
-
this.score = 0;
|
|
1529
|
-
}
|
|
1530
|
-
};
|
|
1531
|
-
__decorate([
|
|
1532
|
-
Property({ through: "recipe://name", resolveLanguage: "literal", required: true }),
|
|
1533
|
-
__metadata("design:type", String)
|
|
1534
|
-
], Recipe.prototype, "name", void 0);
|
|
1535
|
-
__decorate([
|
|
1536
|
-
Property({ through: "recipe://booleanTest", resolveLanguage: "literal" }),
|
|
1537
|
-
__metadata("design:type", Boolean)
|
|
1538
|
-
], Recipe.prototype, "booleanTest", void 0);
|
|
1539
|
-
__decorate([
|
|
1540
|
-
Property({ through: "recipe://score", resolveLanguage: "literal" }),
|
|
1541
|
-
__metadata("design:type", Number)
|
|
1542
|
-
], Recipe.prototype, "score", void 0);
|
|
1543
|
-
Recipe = __decorate([
|
|
1544
|
-
Model({ name: "Recipe" })
|
|
1545
|
-
], Recipe);
|
|
1546
|
-
it("should filter by where clause property even when not in properties projection", async () => {
|
|
1547
|
-
// Simulate SPARQL result with two recipes
|
|
1548
|
-
const grouped = [
|
|
1549
|
-
{
|
|
1550
|
-
source_uri: "expr:recipe1",
|
|
1551
|
-
links: [
|
|
1552
|
-
{ predicate: "recipe://name", target: literalUrl("Recipe 1"), author: "did:test", timestamp: "1000" },
|
|
1553
|
-
{ predicate: "recipe://booleanTest", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1554
|
-
],
|
|
1555
|
-
},
|
|
1556
|
-
{
|
|
1557
|
-
source_uri: "expr:recipe2",
|
|
1558
|
-
links: [
|
|
1559
|
-
{ predicate: "recipe://name", target: literalUrl("Recipe 2"), author: "did:test", timestamp: "1000" },
|
|
1560
|
-
{ predicate: "recipe://booleanTest", target: literalUrl(false), author: "did:test", timestamp: "1000" },
|
|
1561
|
-
],
|
|
1562
|
-
},
|
|
1563
|
-
];
|
|
1564
|
-
const query = { where: { name: "Recipe 2" }, properties: ["booleanTest"] };
|
|
1565
|
-
const { results } = await Recipe.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1566
|
-
expect(results.length).toBe(1);
|
|
1567
|
-
expect(results[0].booleanTest).toBe(false);
|
|
1568
|
-
// name should be deleted after filtering since it wasn't in properties projection
|
|
1569
|
-
expect(results[0].name).toBeUndefined();
|
|
1570
|
-
});
|
|
1571
|
-
it("should delete unrequested properties AFTER where-filtering", async () => {
|
|
1572
|
-
const grouped = [
|
|
1573
|
-
{
|
|
1574
|
-
source_uri: "expr:recipe1",
|
|
1575
|
-
links: [
|
|
1576
|
-
{ predicate: "recipe://name", target: literalUrl("Recipe 1"), author: "did:test", timestamp: "1000" },
|
|
1577
|
-
{ predicate: "recipe://score", target: literalUrl(99), author: "did:test", timestamp: "1000" },
|
|
1578
|
-
],
|
|
1579
|
-
},
|
|
1580
|
-
];
|
|
1581
|
-
const query = { where: { name: "Recipe 1" }, properties: ["score"] };
|
|
1582
|
-
const { results } = await Recipe.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1583
|
-
expect(results.length).toBe(1);
|
|
1584
|
-
expect(results[0].score).toBe(99);
|
|
1585
|
-
// name was used for filtering but should be deleted from final result
|
|
1586
|
-
expect(results[0].name).toBeUndefined();
|
|
1587
|
-
});
|
|
1588
|
-
it("should return all properties when no projection is specified", async () => {
|
|
1589
|
-
const grouped = [
|
|
1590
|
-
{
|
|
1591
|
-
source_uri: "expr:recipe1",
|
|
1592
|
-
links: [
|
|
1593
|
-
{ predicate: "recipe://name", target: literalUrl("Test"), author: "did:test", timestamp: "1000" },
|
|
1594
|
-
{ predicate: "recipe://booleanTest", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1595
|
-
{ predicate: "recipe://score", target: literalUrl(50), author: "did:test", timestamp: "1000" },
|
|
1596
|
-
],
|
|
1597
|
-
},
|
|
1598
|
-
];
|
|
1599
|
-
const query = { where: { name: "Test" } };
|
|
1600
|
-
const { results } = await Recipe.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1601
|
-
expect(results.length).toBe(1);
|
|
1602
|
-
expect(results[0].name).toBe("Test");
|
|
1603
|
-
expect(results[0].booleanTest).toBe(true);
|
|
1604
|
-
expect(results[0].score).toBe(50);
|
|
1605
|
-
});
|
|
1606
|
-
});
|
|
1607
|
-
describe("groupSPARQLResults()", () => {
|
|
1608
|
-
it("groups rows by source", () => {
|
|
1609
|
-
const rows = [
|
|
1610
|
-
{ source: "a", predicate: "p1", target: "t1", author: "auth", timestamp: "ts1" },
|
|
1611
|
-
{ source: "a", predicate: "p2", target: "t2", author: "auth", timestamp: "ts2" },
|
|
1612
|
-
{ source: "b", predicate: "p1", target: "t3", author: "auth", timestamp: "ts3" },
|
|
1613
|
-
];
|
|
1614
|
-
const grouped = groupSPARQLResults(rows);
|
|
1615
|
-
expect(grouped.length).toBe(2);
|
|
1616
|
-
const groupA = grouped.find(g => g.source_uri === "a");
|
|
1617
|
-
const groupB = grouped.find(g => g.source_uri === "b");
|
|
1618
|
-
expect(groupA.links.length).toBe(2);
|
|
1619
|
-
expect(groupB.links.length).toBe(1);
|
|
1620
|
-
});
|
|
1621
|
-
it("handles empty input", () => {
|
|
1622
|
-
expect(groupSPARQLResults([])).toEqual([]);
|
|
1623
|
-
});
|
|
1624
|
-
it("preserves link metadata", () => {
|
|
1625
|
-
const rows = [
|
|
1626
|
-
{ source: "x", predicate: "pred", target: "tgt", author: "did:auth", timestamp: "2024-01-01" },
|
|
1627
|
-
];
|
|
1628
|
-
const grouped = groupSPARQLResults(rows);
|
|
1629
|
-
expect(grouped[0].links[0]).toEqual({
|
|
1630
|
-
predicate: "pred",
|
|
1631
|
-
target: "tgt",
|
|
1632
|
-
author: "did:auth",
|
|
1633
|
-
timestamp: "2024-01-01",
|
|
1634
|
-
});
|
|
1635
|
-
});
|
|
1636
|
-
});
|
|
1637
1135
|
describe("buildSPARQLQuery edge cases", () => {
|
|
1638
1136
|
let FlagModel = class FlagModel extends Ad4mModel {
|
|
1639
1137
|
constructor() {
|
|
@@ -1699,85 +1197,6 @@ describe("buildSPARQLQuery edge cases", () => {
|
|
|
1699
1197
|
expect(sparql).toContain("expr:123");
|
|
1700
1198
|
});
|
|
1701
1199
|
});
|
|
1702
|
-
describe("sparse fieldset property deletion timing", () => {
|
|
1703
|
-
const mockPerspective = {
|
|
1704
|
-
get: jest.fn().mockResolvedValue([]),
|
|
1705
|
-
querySparql: jest.fn().mockResolvedValue([]),
|
|
1706
|
-
getExpression: jest.fn().mockResolvedValue(null),
|
|
1707
|
-
};
|
|
1708
|
-
let TimingTest = class TimingTest extends Ad4mModel {
|
|
1709
|
-
constructor() {
|
|
1710
|
-
super(...arguments);
|
|
1711
|
-
this.a = "";
|
|
1712
|
-
this.b = "";
|
|
1713
|
-
this.c = "";
|
|
1714
|
-
}
|
|
1715
|
-
};
|
|
1716
|
-
__decorate([
|
|
1717
|
-
Property({ through: "timing://a", resolveLanguage: "literal" }),
|
|
1718
|
-
__metadata("design:type", String)
|
|
1719
|
-
], TimingTest.prototype, "a", void 0);
|
|
1720
|
-
__decorate([
|
|
1721
|
-
Property({ through: "timing://b", resolveLanguage: "literal" }),
|
|
1722
|
-
__metadata("design:type", String)
|
|
1723
|
-
], TimingTest.prototype, "b", void 0);
|
|
1724
|
-
__decorate([
|
|
1725
|
-
Property({ through: "timing://c", resolveLanguage: "literal" }),
|
|
1726
|
-
__metadata("design:type", String)
|
|
1727
|
-
], TimingTest.prototype, "c", void 0);
|
|
1728
|
-
TimingTest = __decorate([
|
|
1729
|
-
Model({ name: "TimingTest" })
|
|
1730
|
-
], TimingTest);
|
|
1731
|
-
it("where-clause properties are available during filtering but deleted after", async () => {
|
|
1732
|
-
const grouped = [
|
|
1733
|
-
{
|
|
1734
|
-
source_uri: "expr:1",
|
|
1735
|
-
links: [
|
|
1736
|
-
{ predicate: "timing://a", target: literalUrl("match"), author: "did:test", timestamp: "1000" },
|
|
1737
|
-
{ predicate: "timing://b", target: literalUrl("keep"), author: "did:test", timestamp: "1000" },
|
|
1738
|
-
{ predicate: "timing://c", target: literalUrl("ignore"), author: "did:test", timestamp: "1000" },
|
|
1739
|
-
],
|
|
1740
|
-
},
|
|
1741
|
-
{
|
|
1742
|
-
source_uri: "expr:2",
|
|
1743
|
-
links: [
|
|
1744
|
-
{ predicate: "timing://a", target: literalUrl("no-match"), author: "did:test", timestamp: "1000" },
|
|
1745
|
-
{ predicate: "timing://b", target: literalUrl("skip"), author: "did:test", timestamp: "1000" },
|
|
1746
|
-
{ predicate: "timing://c", target: literalUrl("skip"), author: "did:test", timestamp: "1000" },
|
|
1747
|
-
],
|
|
1748
|
-
},
|
|
1749
|
-
];
|
|
1750
|
-
// properties projection asks for "b" only, where clause filters on "a"
|
|
1751
|
-
const query = { where: { a: "match" }, properties: ["b"] };
|
|
1752
|
-
const { results } = await TimingTest.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1753
|
-
// Only the matching instance should survive
|
|
1754
|
-
expect(results.length).toBe(1);
|
|
1755
|
-
// "b" was requested — should be present
|
|
1756
|
-
expect(results[0].b).toBe("keep");
|
|
1757
|
-
// "a" was used for filtering but not in projection — should be deleted
|
|
1758
|
-
expect(results[0].a).toBeUndefined();
|
|
1759
|
-
// "c" was not requested — should be deleted
|
|
1760
|
-
expect(results[0].c).toBeUndefined();
|
|
1761
|
-
});
|
|
1762
|
-
it("properties not in projection are undefined after instancesFromQueryResult", async () => {
|
|
1763
|
-
const grouped = [
|
|
1764
|
-
{
|
|
1765
|
-
source_uri: "expr:1",
|
|
1766
|
-
links: [
|
|
1767
|
-
{ predicate: "timing://a", target: literalUrl("val-a"), author: "did:test", timestamp: "1000" },
|
|
1768
|
-
{ predicate: "timing://b", target: literalUrl("val-b"), author: "did:test", timestamp: "1000" },
|
|
1769
|
-
{ predicate: "timing://c", target: literalUrl("val-c"), author: "did:test", timestamp: "1000" },
|
|
1770
|
-
],
|
|
1771
|
-
},
|
|
1772
|
-
];
|
|
1773
|
-
const query = { properties: ["a"] };
|
|
1774
|
-
const { results } = await TimingTest.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1775
|
-
expect(results.length).toBe(1);
|
|
1776
|
-
expect(results[0].a).toBe("val-a");
|
|
1777
|
-
expect(results[0].b).toBeUndefined();
|
|
1778
|
-
expect(results[0].c).toBeUndefined();
|
|
1779
|
-
});
|
|
1780
|
-
});
|
|
1781
1200
|
// ── Batch hydration for reverse relations (3.4) ─────────────────────────────
|
|
1782
1201
|
describe("Batch hydration for reverse relations", () => {
|
|
1783
1202
|
it("batch hydration should correctly group targets by parent instance ID", () => {
|
|
@@ -1889,24 +1308,26 @@ describe("Push-down FILTER for literal equality", () => {
|
|
|
1889
1308
|
Model({ name: "FilterTest" })
|
|
1890
1309
|
], FilterTest);
|
|
1891
1310
|
const normalizeQuery = (q) => q.replace(/\s+/g, " ").trim();
|
|
1892
|
-
it("SPARQL query for where: { name: 'Alice' } should
|
|
1311
|
+
it("SPARQL query for where: { name: 'Alice' } should use <ad4m://fn/parse_literal> FILTER", async () => {
|
|
1893
1312
|
const query = await FilterTest.queryToSPARQL(mockPerspective, { where: { name: "Alice" } });
|
|
1894
1313
|
const norm = normalizeQuery(query);
|
|
1895
|
-
// JOIN pattern exists
|
|
1314
|
+
// JOIN pattern exists
|
|
1896
1315
|
expect(norm).toContain("?wTarget_name");
|
|
1897
|
-
//
|
|
1316
|
+
// parse_literal push-down FILTER is present (using correct SPARQL IRI syntax)
|
|
1317
|
+
expect(norm).toContain("ad4m://fn/parse_literal");
|
|
1898
1318
|
expect(norm).not.toContain("fn::parse_literal");
|
|
1899
1319
|
});
|
|
1900
|
-
it("SPARQL query for where: { name: ['Alice', 'Bob'] } should
|
|
1320
|
+
it("SPARQL query for where: { name: ['Alice', 'Bob'] } should use <ad4m://fn/parse_literal> IN FILTER", async () => {
|
|
1901
1321
|
const query = await FilterTest.queryToSPARQL(mockPerspective, { where: { name: ["Alice", "Bob"] } });
|
|
1902
1322
|
const norm = normalizeQuery(query);
|
|
1903
1323
|
expect(norm).toContain("?wTarget_name");
|
|
1324
|
+
expect(norm).toContain("ad4m://fn/parse_literal");
|
|
1904
1325
|
expect(norm).not.toContain("fn::parse_literal");
|
|
1905
1326
|
});
|
|
1906
1327
|
it("SPARQL query for where: { rating: { gt: 5 } } should NOT include parse_literal FILTER", async () => {
|
|
1907
1328
|
const query = await FilterTest.queryToSPARQL(mockPerspective, { where: { rating: { gt: 5 } } });
|
|
1908
1329
|
const norm = normalizeQuery(query);
|
|
1909
|
-
expect(norm).not.toContain("
|
|
1330
|
+
expect(norm).not.toContain("parse_literal");
|
|
1910
1331
|
});
|
|
1911
1332
|
it("literal property where clause adds JOIN for JS post-filter", async () => {
|
|
1912
1333
|
const query = await FilterTest.queryToSPARQL(mockPerspective, { where: { name: "Alice" } });
|
|
@@ -2097,17 +1518,30 @@ describe("Native SPARQL getter evaluation", () => {
|
|
|
2097
1518
|
// ── Subscribe callback timing ──────────────────────────────────────────
|
|
2098
1519
|
describe("ModelQueryBuilder subscribe callback timing", () => {
|
|
2099
1520
|
it("subscribe should not invoke callback synchronously before Promise resolves", async () => {
|
|
2100
|
-
// This test verifies that
|
|
2101
|
-
//
|
|
2102
|
-
|
|
1521
|
+
// This test verifies that subscribe() uses the Rust model subscription endpoint
|
|
1522
|
+
// and properly handles the subscription lifecycle.
|
|
1523
|
+
const mockSubscriptionId = "test-sub-123";
|
|
1524
|
+
let updateCallback = null;
|
|
1525
|
+
const mockClient = {
|
|
1526
|
+
modelSubscribe: jest.fn().mockResolvedValue({
|
|
1527
|
+
subscriptionId: mockSubscriptionId,
|
|
1528
|
+
result: { instances: [], totalCount: 0 },
|
|
1529
|
+
}),
|
|
1530
|
+
subscribeToQueryUpdates: jest.fn().mockImplementation((_id, cb) => {
|
|
1531
|
+
updateCallback = cb;
|
|
1532
|
+
return () => { }; // unsubscribe function
|
|
1533
|
+
}),
|
|
1534
|
+
keepAliveQuery: jest.fn().mockResolvedValue(true),
|
|
1535
|
+
disposeQuerySubscription: jest.fn().mockResolvedValue(true),
|
|
1536
|
+
};
|
|
2103
1537
|
const mockPerspective = {
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
dispose: jest.fn(),
|
|
1538
|
+
uuid: "test-uuid",
|
|
1539
|
+
client: mockClient,
|
|
1540
|
+
modelSubscribe: jest.fn().mockImplementation(async (className, queryJson, shapeJson) => {
|
|
1541
|
+
return mockClient.modelSubscribe("test-uuid", className, queryJson, shapeJson);
|
|
2109
1542
|
}),
|
|
2110
|
-
|
|
1543
|
+
getLinks: jest.fn().mockResolvedValue([]),
|
|
1544
|
+
modelQuery: jest.fn().mockResolvedValue({ instances: [], totalCount: 0 }),
|
|
2111
1545
|
};
|
|
2112
1546
|
const { Ad4mModel, Model, Property, Flag } = require("./index");
|
|
2113
1547
|
let TimingTest = class TimingTest extends Ad4mModel {
|
|
@@ -2139,11 +1573,192 @@ describe("ModelQueryBuilder subscribe callback timing", () => {
|
|
|
2139
1573
|
// At this point the Promise hasn't resolved yet
|
|
2140
1574
|
// The callback should NOT have fired synchronously
|
|
2141
1575
|
expect(callbackInvokedBeforeResolve).toBe(false);
|
|
2142
|
-
await promise;
|
|
1576
|
+
const initialResults = await promise;
|
|
2143
1577
|
promiseResolved = true;
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
1578
|
+
expect(initialResults).toEqual([]);
|
|
1579
|
+
expect(mockPerspective.modelSubscribe).toHaveBeenCalled();
|
|
1580
|
+
});
|
|
1581
|
+
});
|
|
1582
|
+
describe("ModelQueryBuilder paginateSubscribe", () => {
|
|
1583
|
+
it("paginateSubscribe should use a single query with count: true", async () => {
|
|
1584
|
+
const mockSubscriptionId = "paginate-sub-123";
|
|
1585
|
+
const mockClient = {
|
|
1586
|
+
modelSubscribe: jest.fn().mockResolvedValue({
|
|
1587
|
+
subscriptionId: mockSubscriptionId,
|
|
1588
|
+
result: { instances: [], totalCount: 0 },
|
|
1589
|
+
}),
|
|
1590
|
+
subscribeToQueryUpdates: jest.fn().mockImplementation((_id, _cb) => {
|
|
1591
|
+
return () => { };
|
|
1592
|
+
}),
|
|
1593
|
+
keepAliveQuery: jest.fn().mockResolvedValue(true),
|
|
1594
|
+
disposeQuerySubscription: jest.fn().mockResolvedValue(true),
|
|
1595
|
+
};
|
|
1596
|
+
const mockPerspective = {
|
|
1597
|
+
uuid: "test-uuid",
|
|
1598
|
+
client: mockClient,
|
|
1599
|
+
modelSubscribe: jest.fn().mockImplementation(async (className, queryJson, shapeJson) => {
|
|
1600
|
+
return mockClient.modelSubscribe("test-uuid", className, queryJson, shapeJson);
|
|
1601
|
+
}),
|
|
1602
|
+
modelQuery: jest.fn().mockResolvedValue({ instances: [{ id: "item1", type: "test://paginate" }], totalCount: 42 }),
|
|
1603
|
+
};
|
|
1604
|
+
const { Ad4mModel, Model, Flag, Property } = require("./index");
|
|
1605
|
+
let PaginateTest = class PaginateTest extends Ad4mModel {
|
|
1606
|
+
constructor() {
|
|
1607
|
+
super(...arguments);
|
|
1608
|
+
this.type = "test://paginate";
|
|
1609
|
+
this.name = "";
|
|
1610
|
+
}
|
|
1611
|
+
};
|
|
1612
|
+
__decorate([
|
|
1613
|
+
Flag({ through: "test://type", value: "test://paginate" }),
|
|
1614
|
+
__metadata("design:type", String)
|
|
1615
|
+
], PaginateTest.prototype, "type", void 0);
|
|
1616
|
+
__decorate([
|
|
1617
|
+
Property({ through: "test://name" }),
|
|
1618
|
+
__metadata("design:type", String)
|
|
1619
|
+
], PaginateTest.prototype, "name", void 0);
|
|
1620
|
+
PaginateTest = __decorate([
|
|
1621
|
+
Model({ name: "PaginateTest" })
|
|
1622
|
+
], PaginateTest);
|
|
1623
|
+
const builder = PaginateTest.query(mockPerspective);
|
|
1624
|
+
const result = await builder.paginateSubscribe(10, 1, () => { });
|
|
1625
|
+
// Should return paginated result structure
|
|
1626
|
+
expect(result).toHaveProperty("results");
|
|
1627
|
+
expect(result).toHaveProperty("totalCount");
|
|
1628
|
+
expect(result).toHaveProperty("pageSize", 10);
|
|
1629
|
+
expect(result).toHaveProperty("pageNumber", 1);
|
|
1630
|
+
// modelQuery should be called exactly once (not twice — no separate count query)
|
|
1631
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
1632
|
+
// The query should have count: true
|
|
1633
|
+
const callArgs = mockPerspective.modelQuery.mock.calls[0];
|
|
1634
|
+
const queryJson = JSON.parse(callArgs[1]);
|
|
1635
|
+
expect(queryJson.count).toBe(true);
|
|
1636
|
+
expect(queryJson.limit).toBe(10);
|
|
1637
|
+
expect(queryJson.offset).toBe(0);
|
|
1638
|
+
});
|
|
1639
|
+
it("paginateSubscribe should skip isInit messages from subscription", async () => {
|
|
1640
|
+
const mockSubscriptionId = "paginate-init-sub";
|
|
1641
|
+
let capturedCallback = null;
|
|
1642
|
+
const mockClient = {
|
|
1643
|
+
modelSubscribe: jest.fn().mockResolvedValue({
|
|
1644
|
+
subscriptionId: mockSubscriptionId,
|
|
1645
|
+
result: { instances: [], totalCount: 0 },
|
|
1646
|
+
}),
|
|
1647
|
+
subscribeToQueryUpdates: jest.fn().mockImplementation((_id, cb) => {
|
|
1648
|
+
capturedCallback = cb;
|
|
1649
|
+
return () => { };
|
|
1650
|
+
}),
|
|
1651
|
+
keepAliveQuery: jest.fn().mockResolvedValue(true),
|
|
1652
|
+
disposeQuerySubscription: jest.fn().mockResolvedValue(true),
|
|
1653
|
+
};
|
|
1654
|
+
let modelQueryCallCount = 0;
|
|
1655
|
+
const mockPerspective = {
|
|
1656
|
+
uuid: "test-uuid",
|
|
1657
|
+
client: mockClient,
|
|
1658
|
+
modelSubscribe: jest.fn().mockImplementation(async (className, queryJson, shapeJson) => {
|
|
1659
|
+
return mockClient.modelSubscribe("test-uuid", className, queryJson, shapeJson);
|
|
1660
|
+
}),
|
|
1661
|
+
modelQuery: jest.fn().mockImplementation(async () => {
|
|
1662
|
+
modelQueryCallCount++;
|
|
1663
|
+
return { instances: [], totalCount: 0 };
|
|
1664
|
+
}),
|
|
1665
|
+
};
|
|
1666
|
+
const { Ad4mModel, Model, Flag, Property } = require("./index");
|
|
1667
|
+
let InitGuardTest = class InitGuardTest extends Ad4mModel {
|
|
1668
|
+
constructor() {
|
|
1669
|
+
super(...arguments);
|
|
1670
|
+
this.type = "test://init";
|
|
1671
|
+
this.name = "";
|
|
1672
|
+
}
|
|
1673
|
+
};
|
|
1674
|
+
__decorate([
|
|
1675
|
+
Flag({ through: "test://type", value: "test://init" }),
|
|
1676
|
+
__metadata("design:type", String)
|
|
1677
|
+
], InitGuardTest.prototype, "type", void 0);
|
|
1678
|
+
__decorate([
|
|
1679
|
+
Property({ through: "test://name" }),
|
|
1680
|
+
__metadata("design:type", String)
|
|
1681
|
+
], InitGuardTest.prototype, "name", void 0);
|
|
1682
|
+
InitGuardTest = __decorate([
|
|
1683
|
+
Model({ name: "InitGuardTest" })
|
|
1684
|
+
], InitGuardTest);
|
|
1685
|
+
const userCallback = jest.fn();
|
|
1686
|
+
const builder = InitGuardTest.query(mockPerspective);
|
|
1687
|
+
await builder.paginateSubscribe(10, 1, userCallback);
|
|
1688
|
+
// Reset the count after initial fetch
|
|
1689
|
+
const initialCallCount = modelQueryCallCount;
|
|
1690
|
+
// Simulate an isInit message from subscription
|
|
1691
|
+
expect(capturedCallback).not.toBeNull();
|
|
1692
|
+
capturedCallback({ isInit: true });
|
|
1693
|
+
// Wait for any async processing
|
|
1694
|
+
await new Promise(r => setTimeout(r, 50));
|
|
1695
|
+
// modelQuery should NOT have been called again (isInit was filtered)
|
|
1696
|
+
expect(modelQueryCallCount).toBe(initialCallCount);
|
|
1697
|
+
// User callback should NOT have been invoked by isInit
|
|
1698
|
+
expect(userCallback).not.toHaveBeenCalled();
|
|
1699
|
+
});
|
|
1700
|
+
it("paginateSubscribe should re-fetch on real subscription updates", async () => {
|
|
1701
|
+
const mockSubscriptionId = "paginate-update-sub";
|
|
1702
|
+
let capturedCallback = null;
|
|
1703
|
+
const mockClient = {
|
|
1704
|
+
modelSubscribe: jest.fn().mockResolvedValue({
|
|
1705
|
+
subscriptionId: mockSubscriptionId,
|
|
1706
|
+
result: { instances: [], totalCount: 0 },
|
|
1707
|
+
}),
|
|
1708
|
+
subscribeToQueryUpdates: jest.fn().mockImplementation((_id, cb) => {
|
|
1709
|
+
capturedCallback = cb;
|
|
1710
|
+
return () => { };
|
|
1711
|
+
}),
|
|
1712
|
+
keepAliveQuery: jest.fn().mockResolvedValue(true),
|
|
1713
|
+
disposeQuerySubscription: jest.fn().mockResolvedValue(true),
|
|
1714
|
+
};
|
|
1715
|
+
let modelQueryCallCount = 0;
|
|
1716
|
+
const mockPerspective = {
|
|
1717
|
+
uuid: "test-uuid",
|
|
1718
|
+
client: mockClient,
|
|
1719
|
+
modelSubscribe: jest.fn().mockImplementation(async (className, queryJson, shapeJson) => {
|
|
1720
|
+
return mockClient.modelSubscribe("test-uuid", className, queryJson, shapeJson);
|
|
1721
|
+
}),
|
|
1722
|
+
modelQuery: jest.fn().mockImplementation(async () => {
|
|
1723
|
+
modelQueryCallCount++;
|
|
1724
|
+
return { instances: [{ id: "new-item", type: "test://update" }], totalCount: 1 };
|
|
1725
|
+
}),
|
|
1726
|
+
};
|
|
1727
|
+
const { Ad4mModel, Model, Flag, Property } = require("./index");
|
|
1728
|
+
let UpdateTest = class UpdateTest extends Ad4mModel {
|
|
1729
|
+
constructor() {
|
|
1730
|
+
super(...arguments);
|
|
1731
|
+
this.type = "test://update";
|
|
1732
|
+
this.name = "";
|
|
1733
|
+
}
|
|
1734
|
+
};
|
|
1735
|
+
__decorate([
|
|
1736
|
+
Flag({ through: "test://type", value: "test://update" }),
|
|
1737
|
+
__metadata("design:type", String)
|
|
1738
|
+
], UpdateTest.prototype, "type", void 0);
|
|
1739
|
+
__decorate([
|
|
1740
|
+
Property({ through: "test://name" }),
|
|
1741
|
+
__metadata("design:type", String)
|
|
1742
|
+
], UpdateTest.prototype, "name", void 0);
|
|
1743
|
+
UpdateTest = __decorate([
|
|
1744
|
+
Model({ name: "UpdateTest" })
|
|
1745
|
+
], UpdateTest);
|
|
1746
|
+
const userCallback = jest.fn();
|
|
1747
|
+
const builder = UpdateTest.query(mockPerspective);
|
|
1748
|
+
await builder.paginateSubscribe(10, 1, userCallback);
|
|
1749
|
+
const initialCallCount = modelQueryCallCount;
|
|
1750
|
+
// Simulate a real subscription update (not isInit)
|
|
1751
|
+
capturedCallback({ instances: [{ id: "new-item" }], totalCount: 1 });
|
|
1752
|
+
// Wait for async processing
|
|
1753
|
+
await new Promise(r => setTimeout(r, 100));
|
|
1754
|
+
// modelQuery should have been called again for the re-fetch
|
|
1755
|
+
expect(modelQueryCallCount).toBeGreaterThan(initialCallCount);
|
|
1756
|
+
// User callback should have been invoked with paginated results
|
|
1757
|
+
expect(userCallback).toHaveBeenCalled();
|
|
1758
|
+
const callArg = userCallback.mock.calls[0][0];
|
|
1759
|
+
expect(callArg).toHaveProperty("totalCount");
|
|
1760
|
+
expect(callArg).toHaveProperty("pageSize", 10);
|
|
1761
|
+
expect(callArg).toHaveProperty("pageNumber", 1);
|
|
2147
1762
|
});
|
|
2148
1763
|
});
|
|
2149
1764
|
// ============================================================================
|
|
@@ -2315,3 +1930,126 @@ describe("Lazy Conformance Filters", () => {
|
|
|
2315
1930
|
expect(shacl.name).toBe("LazyParent2");
|
|
2316
1931
|
});
|
|
2317
1932
|
});
|
|
1933
|
+
// ──────────────────────────────────────────────────────────
|
|
1934
|
+
// deepQuery opt-in — getter evaluation on collection queries
|
|
1935
|
+
// ──────────────────────────────────────────────────────────
|
|
1936
|
+
describe("deepQuery opt-in — getter evaluation", () => {
|
|
1937
|
+
let DeepQueryTestMessage = class DeepQueryTestMessage extends Ad4mModel {
|
|
1938
|
+
constructor() {
|
|
1939
|
+
super(...arguments);
|
|
1940
|
+
this.type = "";
|
|
1941
|
+
this.body = "";
|
|
1942
|
+
this.isPopular = false;
|
|
1943
|
+
this.reactions = [];
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1946
|
+
__decorate([
|
|
1947
|
+
Flag({ through: "flux://entry_type", value: "flux://message" }),
|
|
1948
|
+
__metadata("design:type", String)
|
|
1949
|
+
], DeepQueryTestMessage.prototype, "type", void 0);
|
|
1950
|
+
__decorate([
|
|
1951
|
+
Property({ through: "flux://body", resolveLanguage: "literal" }),
|
|
1952
|
+
__metadata("design:type", String)
|
|
1953
|
+
], DeepQueryTestMessage.prototype, "body", void 0);
|
|
1954
|
+
__decorate([
|
|
1955
|
+
Property({
|
|
1956
|
+
through: "flux://has_reply",
|
|
1957
|
+
getter: `SELECT ?target WHERE { ?source <flux://has_reply> ?target . } LIMIT 1`,
|
|
1958
|
+
}),
|
|
1959
|
+
__metadata("design:type", String)
|
|
1960
|
+
], DeepQueryTestMessage.prototype, "replyingTo", void 0);
|
|
1961
|
+
__decorate([
|
|
1962
|
+
ReadOnly({
|
|
1963
|
+
through: "flux://is_popular",
|
|
1964
|
+
getter: `ASK WHERE { ?source <flux://is_popular> "true" . }`,
|
|
1965
|
+
}),
|
|
1966
|
+
__metadata("design:type", Boolean)
|
|
1967
|
+
], DeepQueryTestMessage.prototype, "isPopular", void 0);
|
|
1968
|
+
__decorate([
|
|
1969
|
+
HasMany({ through: "flux://reaction" }),
|
|
1970
|
+
__metadata("design:type", Array)
|
|
1971
|
+
], DeepQueryTestMessage.prototype, "reactions", void 0);
|
|
1972
|
+
DeepQueryTestMessage = __decorate([
|
|
1973
|
+
Model({ name: "DeepQueryTestMessage" })
|
|
1974
|
+
], DeepQueryTestMessage);
|
|
1975
|
+
let sparqlCalls;
|
|
1976
|
+
const mockPerspective = {
|
|
1977
|
+
uuid: "test-uuid",
|
|
1978
|
+
modelQuery: jest.fn(async (className, queryJson, shapeJson) => {
|
|
1979
|
+
// Return a basic result for the single-instance getData() path
|
|
1980
|
+
const query = JSON.parse(queryJson);
|
|
1981
|
+
const id = query?.where?.id;
|
|
1982
|
+
if (id) {
|
|
1983
|
+
return {
|
|
1984
|
+
instances: [{ id, body: "Hello" }],
|
|
1985
|
+
totalCount: 1,
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1988
|
+
return { instances: [], totalCount: 0 };
|
|
1989
|
+
}),
|
|
1990
|
+
querySparql: jest.fn(async (q) => {
|
|
1991
|
+
sparqlCalls.push(q);
|
|
1992
|
+
return [];
|
|
1993
|
+
}),
|
|
1994
|
+
get: jest.fn().mockResolvedValue([]),
|
|
1995
|
+
getExpression: jest.fn().mockResolvedValue(null),
|
|
1996
|
+
stringOrTemplateObjectToSubjectClassName: jest.fn().mockResolvedValue("DeepQueryTestMessage"),
|
|
1997
|
+
};
|
|
1998
|
+
beforeEach(() => {
|
|
1999
|
+
sparqlCalls = [];
|
|
2000
|
+
mockPerspective.querySparql.mockClear();
|
|
2001
|
+
mockPerspective.get.mockClear();
|
|
2002
|
+
});
|
|
2003
|
+
function makeInstances(count) {
|
|
2004
|
+
return Array.from({ length: count }, (_, i) => new DeepQueryTestMessage(mockPerspective, `flux://msg-${i}`));
|
|
2005
|
+
}
|
|
2006
|
+
it("single-instance get() delegates getter evaluation to Rust (no JS-side SPARQL)", async () => {
|
|
2007
|
+
const instance = new DeepQueryTestMessage(mockPerspective, "flux://msg-single");
|
|
2008
|
+
mockPerspective.querySparql.mockImplementation(async (q) => {
|
|
2009
|
+
sparqlCalls.push(q);
|
|
2010
|
+
if (q.includes("flux://msg-single") && !q.includes("flux://has_reply") && !q.includes("flux://is_popular")) {
|
|
2011
|
+
return [
|
|
2012
|
+
{ source: "flux://msg-single", predicate: "flux://entry_type", target: "flux://message", author: "did:key:a", timestamp: "3000" },
|
|
2013
|
+
{ source: "flux://msg-single", predicate: "flux://body", target: "literal:string:Hello", author: "did:key:a", timestamp: "3000" },
|
|
2014
|
+
];
|
|
2015
|
+
}
|
|
2016
|
+
return [];
|
|
2017
|
+
});
|
|
2018
|
+
await instance.get();
|
|
2019
|
+
// Getter evaluation now happens Rust-side via evaluate_getters() — no JS SPARQL calls
|
|
2020
|
+
const getterCalls = sparqlCalls.filter((q) => q.includes("flux://has_reply") || q.includes("flux://is_popular"));
|
|
2021
|
+
expect(getterCalls.length).toBe(0);
|
|
2022
|
+
});
|
|
2023
|
+
describe("Ad4mModel.evaluateGetters()", () => {
|
|
2024
|
+
it("resolves getters for a batch of instances", async () => {
|
|
2025
|
+
const instances = makeInstances(4);
|
|
2026
|
+
sparqlCalls = [];
|
|
2027
|
+
await DeepQueryTestMessage.evaluateGetters(instances.slice(0, 2), mockPerspective, ["replyingTo"]);
|
|
2028
|
+
const replyCalls = sparqlCalls.filter((q) => q.includes("flux://has_reply"));
|
|
2029
|
+
expect(replyCalls.length).toBe(2);
|
|
2030
|
+
const popularCalls = sparqlCalls.filter((q) => q.includes("flux://is_popular"));
|
|
2031
|
+
expect(popularCalls.length).toBe(0);
|
|
2032
|
+
});
|
|
2033
|
+
it("evaluates all getters when propertyNames is omitted", async () => {
|
|
2034
|
+
const instances = makeInstances(2);
|
|
2035
|
+
sparqlCalls = [];
|
|
2036
|
+
await DeepQueryTestMessage.evaluateGetters(instances, mockPerspective);
|
|
2037
|
+
const replyCalls = sparqlCalls.filter((q) => q.includes("flux://has_reply"));
|
|
2038
|
+
const popularCalls = sparqlCalls.filter((q) => q.includes("flux://is_popular"));
|
|
2039
|
+
expect(replyCalls.length).toBe(2);
|
|
2040
|
+
expect(popularCalls.length).toBe(2);
|
|
2041
|
+
});
|
|
2042
|
+
it("handles empty array gracefully", async () => {
|
|
2043
|
+
sparqlCalls = [];
|
|
2044
|
+
await DeepQueryTestMessage.evaluateGetters([], mockPerspective);
|
|
2045
|
+
expect(sparqlCalls.length).toBe(0);
|
|
2046
|
+
});
|
|
2047
|
+
});
|
|
2048
|
+
describe("deepQuery via ModelQueryBuilder", () => {
|
|
2049
|
+
it("deepQuery() method sets deepQuery flag on queryParams", () => {
|
|
2050
|
+
const builder = DeepQueryTestMessage.query(mockPerspective);
|
|
2051
|
+
builder.deepQuery();
|
|
2052
|
+
expect(builder.queryParams.deepQuery).toBe(true);
|
|
2053
|
+
});
|
|
2054
|
+
});
|
|
2055
|
+
});
|