@coasys/ad4m 0.13.0-test-3 → 0.13.0-test-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/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +6717 -15519
- package/lib/index.js +4811 -13662
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +39 -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 -1
- package/lib/src/index.js +6 -1
- 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 +1 -1
- package/lib/src/language/Language.js +10 -76
- 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 +76 -44
- package/lib/src/model/Ad4mModel.js +635 -479
- package/lib/src/model/Ad4mModel.test.js +371 -815
- package/lib/src/model/ModelQueryBuilder.d.ts +15 -27
- package/lib/src/model/ModelQueryBuilder.js +163 -224
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration.d.ts +3 -93
- package/lib/src/model/hydration.js +3 -970
- 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 +4 -67
- package/lib/src/model/query-sparql.js +26 -322
- package/lib/src/model/query-sparql.test.js +35 -218
- package/lib/src/model/query-utils.d.ts +1 -0
- package/lib/src/model/query-utils.js +46 -1
- package/lib/src/model/shacl-gen.js +4 -0
- package/lib/src/model/types.d.ts +51 -43
- 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 +13 -17
- package/lib/src/perspectives/PerspectiveClient.js +179 -429
- package/lib/src/perspectives/PerspectiveClient.test.js +55 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +106 -71
- package/lib/src/perspectives/PerspectiveProxy.js +289 -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 +6 -18
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1179 -1340
- package/src/Ad4mClient.ts +40 -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 -1
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +2 -23
- 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 +766 -1173
- package/src/model/Ad4mModel.ts +664 -529
- package/src/model/ModelQueryBuilder.ts +203 -251
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +3 -1037
- package/src/model/index.ts +0 -4
- package/src/model/query-sparql.test.ts +34 -242
- package/src/model/query-sparql.ts +27 -337
- package/src/model/query-utils.ts +47 -2
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +55 -44
- 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 +206 -148
- package/src/perspectives/PerspectiveClient.ts +247 -442
- 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 +331 -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/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/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/hydration-batch.ts +0 -205
- package/src/model/hydration-batching.test.ts +0 -563
- 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-delta.test.ts +0 -207
- package/src/model/subscription-pool.ts +0 -211
- 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
|
@@ -630,7 +630,7 @@ describe("Ad4mModel.queryToSPARQL()", () => {
|
|
|
630
630
|
expect(norm).toContain("SELECT DISTINCT ?source");
|
|
631
631
|
});
|
|
632
632
|
});
|
|
633
|
-
describe("Ad4mModel
|
|
633
|
+
describe("Ad4mModel query methods (modelQuery integration)", () => {
|
|
634
634
|
// Test Recipe model
|
|
635
635
|
let Recipe = class Recipe extends Ad4mModel {
|
|
636
636
|
constructor() {
|
|
@@ -655,9 +655,10 @@ describe("Ad4mModel.instancesFromQueryResult() and SPARQL integration", () => {
|
|
|
655
655
|
Recipe = __decorate([
|
|
656
656
|
Model({ name: "Recipe" })
|
|
657
657
|
], Recipe);
|
|
658
|
-
// Mock perspective with
|
|
658
|
+
// Mock perspective with querySparql, modelQuery, and infer methods
|
|
659
659
|
const mockPerspective = {
|
|
660
660
|
querySparql: jest.fn(),
|
|
661
|
+
modelQuery: jest.fn(),
|
|
661
662
|
infer: jest.fn(),
|
|
662
663
|
uuid: 'test-perspective-uuid',
|
|
663
664
|
stringOrTemplateObjectToSubjectClassName: jest.fn().mockResolvedValue('Recipe')
|
|
@@ -665,245 +666,137 @@ describe("Ad4mModel.instancesFromQueryResult() and SPARQL integration", () => {
|
|
|
665
666
|
beforeEach(() => {
|
|
666
667
|
jest.clearAllMocks();
|
|
667
668
|
});
|
|
668
|
-
it("should convert empty query results correctly", async () => {
|
|
669
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, {}, []);
|
|
670
|
-
expect(result.results).toEqual([]);
|
|
671
|
-
expect(result.totalCount).toBe(0);
|
|
672
|
-
});
|
|
673
|
-
it("should convert query results to model instances", async () => {
|
|
674
|
-
const queryResults = [
|
|
675
|
-
{
|
|
676
|
-
source: "node:abc123",
|
|
677
|
-
source_uri: "literal:recipe1",
|
|
678
|
-
links: [
|
|
679
|
-
{ predicate: "recipe://name", target: "Pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
680
|
-
{ predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
681
|
-
{ predicate: "recipe://ingredient", target: "pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
682
|
-
{ predicate: "recipe://ingredient", target: "tomato", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
683
|
-
{ predicate: "recipe://ingredient", target: "cheese", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
684
|
-
]
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
source: "node:def456",
|
|
688
|
-
source_uri: "literal:recipe2",
|
|
689
|
-
links: [
|
|
690
|
-
{ predicate: "recipe://name", target: "Pizza", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
691
|
-
{ predicate: "recipe://rating", target: "4", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
692
|
-
{ predicate: "recipe://ingredient", target: "dough", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
693
|
-
{ predicate: "recipe://ingredient", target: "cheese", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
694
|
-
{ predicate: "recipe://ingredient", target: "tomato", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" }
|
|
695
|
-
]
|
|
696
|
-
}
|
|
697
|
-
];
|
|
698
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, {}, queryResults);
|
|
699
|
-
expect(result.results).toHaveLength(2);
|
|
700
|
-
expect(result.totalCount).toBe(2);
|
|
701
|
-
const recipe1 = result.results[0];
|
|
702
|
-
expect(recipe1).toBeInstanceOf(Recipe);
|
|
703
|
-
expect(recipe1.name).toBe("Pasta");
|
|
704
|
-
expect(recipe1.rating).toBe(5);
|
|
705
|
-
expect(recipe1.ingredients).toEqual(["pasta", "tomato", "cheese"]);
|
|
706
|
-
const recipe2 = result.results[1];
|
|
707
|
-
expect(recipe2).toBeInstanceOf(Recipe);
|
|
708
|
-
expect(recipe2.name).toBe("Pizza");
|
|
709
|
-
expect(recipe2.rating).toBe(4);
|
|
710
|
-
});
|
|
711
|
-
it("should filter properties when query specifies properties", async () => {
|
|
712
|
-
const queryResults = [
|
|
713
|
-
{
|
|
714
|
-
source: "node:abc123",
|
|
715
|
-
source_uri: "literal:recipe1",
|
|
716
|
-
links: [
|
|
717
|
-
{ predicate: "recipe://name", target: "Pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
718
|
-
{ predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
719
|
-
{ predicate: "recipe://ingredient", target: "pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
720
|
-
{ predicate: "recipe://ingredient", target: "tomato", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
721
|
-
]
|
|
722
|
-
}
|
|
723
|
-
];
|
|
724
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, { properties: ["name"] }, queryResults);
|
|
725
|
-
expect(result.results).toHaveLength(1);
|
|
726
|
-
const recipe = result.results[0];
|
|
727
|
-
expect(recipe.name).toBe("Pasta");
|
|
728
|
-
// rating and ingredients should be removed since only "name" was requested
|
|
729
|
-
expect(recipe.rating).toBeUndefined();
|
|
730
|
-
expect(recipe.ingredients).toBeUndefined();
|
|
731
|
-
// author, createdAt, updatedAt are also stripped unless explicitly requested
|
|
732
|
-
expect(recipe.author).toBeUndefined();
|
|
733
|
-
expect(recipe.timestamp).toBeUndefined();
|
|
734
|
-
});
|
|
735
|
-
it("should filter properties when query specifies properties", async () => {
|
|
736
|
-
const queryResults = [
|
|
737
|
-
{
|
|
738
|
-
source: "node:abc123",
|
|
739
|
-
source_uri: "literal:recipe1",
|
|
740
|
-
links: [
|
|
741
|
-
{ predicate: "recipe://name", target: "Pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
742
|
-
{ predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
743
|
-
{ predicate: "recipe://ingredient", target: "pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
744
|
-
{ predicate: "recipe://ingredient", target: "tomato", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
745
|
-
]
|
|
746
|
-
}
|
|
747
|
-
];
|
|
748
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, { properties: ["name"] }, queryResults);
|
|
749
|
-
expect(result.results).toHaveLength(1);
|
|
750
|
-
const recipe = result.results[0];
|
|
751
|
-
expect(recipe.name).toBe("Pasta");
|
|
752
|
-
// rating and ingredients should be removed since only "name" was requested
|
|
753
|
-
expect(recipe.rating).toBeUndefined();
|
|
754
|
-
});
|
|
755
|
-
it("should handle results missing base field", async () => {
|
|
756
|
-
const queryResults = [
|
|
757
|
-
{
|
|
758
|
-
links: [
|
|
759
|
-
{ predicate: "recipe://name", target: "Pasta", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" },
|
|
760
|
-
{ predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
761
|
-
]
|
|
762
|
-
// Missing source field
|
|
763
|
-
}
|
|
764
|
-
];
|
|
765
|
-
const result = await Recipe.instancesFromQueryResult(mockPerspective, {}, queryResults);
|
|
766
|
-
// Should filter out the invalid result (or handle gracefully)
|
|
767
|
-
expect(result.results).toHaveLength(0);
|
|
768
|
-
expect(result.totalCount).toBe(0);
|
|
769
|
-
});
|
|
770
669
|
it("should use SPARQL when engine is 'sparql' in findAll()", async () => {
|
|
771
|
-
//
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
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
|
+
});
|
|
778
677
|
const results = await Recipe.findAll(mockPerspective, {}, 'sparql');
|
|
779
|
-
expect(mockPerspective.
|
|
678
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
780
679
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
781
680
|
expect(results).toHaveLength(1);
|
|
782
681
|
expect(results[0].name).toBe("Pasta");
|
|
783
682
|
});
|
|
784
|
-
it("should
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
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
|
+
});
|
|
792
690
|
const results = await Recipe.findAll(mockPerspective, {}, false);
|
|
793
|
-
expect(mockPerspective.
|
|
794
|
-
expect(mockPerspective.
|
|
691
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
692
|
+
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
795
693
|
expect(results).toHaveLength(1);
|
|
796
694
|
});
|
|
797
695
|
it("should use SPARQL when engine is 'sparql' in findAllAndCount()", async () => {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
const { results, totalCount } = await Recipe.findAllAndCount(mockPerspective, {}
|
|
805
|
-
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);
|
|
806
704
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
807
705
|
expect(results).toHaveLength(1);
|
|
808
706
|
expect(totalCount).toBe(1);
|
|
809
707
|
});
|
|
810
708
|
it("should use SPARQL when engine is 'sparql' in paginate()", async () => {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
mockPerspective
|
|
818
|
-
|
|
819
|
-
.mockResolvedValueOnce([{ count: 1 }]);
|
|
820
|
-
// Include order to trigger SPARQL-level pagination (data + count queries)
|
|
821
|
-
const page = await Recipe.paginate(mockPerspective, 10, 1, { order: { name: 'ASC' } }, 'sparql');
|
|
822
|
-
// paginate now issues 2 SPARQL queries: data + count
|
|
823
|
-
expect(mockPerspective.querySparql).toHaveBeenCalledTimes(2);
|
|
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);
|
|
824
717
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
825
718
|
expect(page.results).toHaveLength(1);
|
|
826
719
|
expect(page.pageSize).toBe(10);
|
|
827
720
|
expect(page.pageNumber).toBe(1);
|
|
828
721
|
expect(page.totalCount).toBe(1);
|
|
829
722
|
});
|
|
830
|
-
it("should use SPARQL
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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);
|
|
835
730
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
836
731
|
expect(count).toBe(5);
|
|
837
732
|
});
|
|
838
|
-
it("should
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
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);
|
|
843
740
|
expect(mockPerspective.querySparql).not.toHaveBeenCalled();
|
|
844
741
|
expect(count).toBe(10);
|
|
845
742
|
});
|
|
846
743
|
it("should use SPARQL when engine is 'sparql' in ModelQueryBuilder.get()", async () => {
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
744
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
745
|
+
instances: [
|
|
746
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
747
|
+
],
|
|
748
|
+
totalCount: 1
|
|
749
|
+
});
|
|
853
750
|
const results = await Recipe.query(mockPerspective)
|
|
854
751
|
.where({ name: "Pasta" })
|
|
855
752
|
.engine('sparql')
|
|
856
753
|
.get();
|
|
857
|
-
expect(mockPerspective.
|
|
754
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
858
755
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
859
756
|
expect(results).toHaveLength(1);
|
|
860
757
|
expect(results[0].name).toBe("Pasta");
|
|
861
758
|
});
|
|
862
|
-
it("should use
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
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
|
+
});
|
|
870
766
|
const results = await Recipe.query(mockPerspective)
|
|
871
767
|
.where({ name: "Pasta" })
|
|
872
768
|
.engine('prolog')
|
|
873
769
|
.get();
|
|
874
|
-
|
|
875
|
-
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();
|
|
876
773
|
expect(results).toHaveLength(1);
|
|
877
774
|
});
|
|
878
775
|
it("should use SPARQL when engine is 'sparql' in ModelQueryBuilder.count()", async () => {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
884
|
-
]).flat()
|
|
885
|
-
];
|
|
886
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
776
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
777
|
+
instances: [],
|
|
778
|
+
totalCount: 3
|
|
779
|
+
});
|
|
887
780
|
const count = await Recipe.query(mockPerspective)
|
|
888
781
|
.where({ rating: { gt: 4 } })
|
|
889
782
|
.engine('sparql')
|
|
890
783
|
.count();
|
|
891
|
-
expect(mockPerspective.
|
|
784
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
892
785
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
893
786
|
expect(count).toBe(3);
|
|
894
787
|
});
|
|
895
788
|
it("should use SPARQL when engine is 'sparql' in ModelQueryBuilder.paginate()", async () => {
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
789
|
+
mockPerspective.modelQuery.mockResolvedValue({
|
|
790
|
+
instances: [
|
|
791
|
+
{ id: "literal:recipe1", name: "Pasta", rating: 5, ingredients: ["pasta"] }
|
|
792
|
+
],
|
|
793
|
+
totalCount: 1
|
|
794
|
+
});
|
|
902
795
|
const page = await Recipe.query(mockPerspective)
|
|
903
796
|
.where({ rating: { gt: 3 } })
|
|
904
797
|
.engine('sparql')
|
|
905
798
|
.paginate(10, 1);
|
|
906
|
-
expect(mockPerspective.
|
|
799
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalledTimes(1);
|
|
907
800
|
expect(mockPerspective.infer).not.toHaveBeenCalled();
|
|
908
801
|
expect(page.results).toHaveLength(1);
|
|
909
802
|
expect(page.pageSize).toBe(10);
|
|
@@ -938,6 +831,7 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
938
831
|
// Mock perspective
|
|
939
832
|
const mockPerspective = {
|
|
940
833
|
querySparql: jest.fn(),
|
|
834
|
+
modelQuery: jest.fn(),
|
|
941
835
|
infer: jest.fn(),
|
|
942
836
|
uuid: 'test-perspective-uuid',
|
|
943
837
|
stringOrTemplateObjectToSubjectClassName: jest.fn().mockResolvedValue('Recipe')
|
|
@@ -945,128 +839,78 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
945
839
|
beforeEach(() => {
|
|
946
840
|
jest.clearAllMocks();
|
|
947
841
|
});
|
|
948
|
-
it("should apply
|
|
949
|
-
//
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
]).flat()
|
|
955
|
-
];
|
|
956
|
-
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
|
+
});
|
|
957
848
|
// Count recipes with rating > 3 (should match 2 recipes: rating 4 and 5)
|
|
958
|
-
const count = await Recipe.count(mockPerspective, { where: { rating: { gt: 3 } } }
|
|
959
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
960
|
-
const findAllResults = await Recipe.findAll(mockPerspective, { where: { rating: { gt: 3 } } }, 'sparql');
|
|
849
|
+
const count = await Recipe.count(mockPerspective, { where: { rating: { gt: 3 } } });
|
|
961
850
|
expect(count).toBe(2);
|
|
962
|
-
expect(
|
|
963
|
-
});
|
|
964
|
-
it("should apply
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: `${i + 1}`, author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
970
|
-
]).flat()
|
|
971
|
-
];
|
|
972
|
-
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
|
+
});
|
|
973
858
|
// Count recipes with rating between 2 and 4 (should match 3 recipes: rating 2, 3, 4)
|
|
974
|
-
const count = await Recipe.count(mockPerspective, { where: { rating: { between: [2, 4] } } }
|
|
975
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
976
|
-
const findAllResults = await Recipe.findAll(mockPerspective, { where: { rating: { between: [2, 4] } } }, 'sparql');
|
|
859
|
+
const count = await Recipe.count(mockPerspective, { where: { rating: { between: [2, 4] } } });
|
|
977
860
|
expect(count).toBe(3);
|
|
978
|
-
expect(
|
|
979
|
-
});
|
|
980
|
-
it("should apply
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: `2023-01-0${i + 1}T00:00:00Z` }
|
|
986
|
-
]).flat()
|
|
987
|
-
];
|
|
988
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
989
|
-
// 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
|
+
});
|
|
990
868
|
const targetTimestamp = new Date("2023-01-03T00:00:00Z").getTime();
|
|
991
|
-
const count = await Recipe.count(mockPerspective, { where: { timestamp: { gt: targetTimestamp } } }
|
|
992
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
993
|
-
const findAllResults = await Recipe.findAll(mockPerspective, { where: { timestamp: { gt: targetTimestamp } } }, 'sparql');
|
|
869
|
+
const count = await Recipe.count(mockPerspective, { where: { timestamp: { gt: targetTimestamp } } });
|
|
994
870
|
expect(count).toBe(2);
|
|
995
|
-
expect(
|
|
996
|
-
});
|
|
997
|
-
it("should apply
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: `2023-01-0${i + 1}T00:00:00Z` }
|
|
1003
|
-
]).flat()
|
|
1004
|
-
];
|
|
1005
|
-
mockPerspective.querySparql.mockResolvedValue(queryResults);
|
|
1006
|
-
// 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
|
+
});
|
|
1007
878
|
const startTimestamp = new Date("2023-01-02T00:00:00Z").getTime();
|
|
1008
879
|
const endTimestamp = new Date("2023-01-04T00:00:00Z").getTime();
|
|
1009
880
|
const count = await Recipe.count(mockPerspective, {
|
|
1010
881
|
where: { timestamp: { between: [startTimestamp, endTimestamp] } }
|
|
1011
|
-
}
|
|
1012
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
1013
|
-
const findAllResults = await Recipe.findAll(mockPerspective, {
|
|
1014
|
-
where: { timestamp: { between: [startTimestamp, endTimestamp] } }
|
|
1015
|
-
}, 'sparql');
|
|
882
|
+
});
|
|
1016
883
|
expect(count).toBe(3);
|
|
1017
|
-
expect(
|
|
1018
|
-
});
|
|
1019
|
-
it("should apply
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
1025
|
-
]).flat(),
|
|
1026
|
-
...Array.from({ length: 2 }, (_, i) => [
|
|
1027
|
-
{ source: `literal:recipe${i + 4}`, predicate: "recipe://name", target: `Recipe ${i + 4}`, author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" },
|
|
1028
|
-
{ source: `literal:recipe${i + 4}`, predicate: "recipe://rating", target: "5", author: "did:key:bob", timestamp: "2023-01-02T00:00:00Z" }
|
|
1029
|
-
]).flat()
|
|
1030
|
-
];
|
|
1031
|
-
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
|
+
});
|
|
1032
891
|
// Count recipes by Alice (should match 3 recipes)
|
|
1033
|
-
const count = await Recipe.count(mockPerspective, { where: { author: "did:key:alice" } }
|
|
1034
|
-
// Verify count matches the number of instances that would be returned by findAll
|
|
1035
|
-
const findAllResults = await Recipe.findAll(mockPerspective, { where: { author: "did:key:alice" } }, 'sparql');
|
|
892
|
+
const count = await Recipe.count(mockPerspective, { where: { author: "did:key:alice" } });
|
|
1036
893
|
expect(count).toBe(3);
|
|
1037
|
-
expect(
|
|
1038
|
-
});
|
|
1039
|
-
it("should apply
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: `${i + 1}`, author: "did:key:alice", timestamp: "2023-01-01T00:00:00Z" }
|
|
1045
|
-
]).flat()
|
|
1046
|
-
];
|
|
1047
|
-
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
|
+
});
|
|
1048
901
|
// Count recipes with rating > 3 using ModelQueryBuilder
|
|
1049
902
|
const count = await Recipe.query(mockPerspective)
|
|
1050
903
|
.where({ rating: { gt: 3 } })
|
|
1051
904
|
.engine('sparql')
|
|
1052
905
|
.count();
|
|
1053
|
-
// Verify count matches the number of instances that would be returned by get()
|
|
1054
|
-
const getResults = await Recipe.query(mockPerspective)
|
|
1055
|
-
.where({ rating: { gt: 3 } })
|
|
1056
|
-
.engine('sparql')
|
|
1057
|
-
.get();
|
|
1058
906
|
expect(count).toBe(2);
|
|
1059
|
-
expect(
|
|
1060
|
-
});
|
|
1061
|
-
it("should apply
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
{ source: `literal:recipe${i + 1}`, predicate: "recipe://rating", target: "5", author: "did:key:alice", timestamp: `2023-01-0${i + 1}T00:00:00Z` }
|
|
1067
|
-
]).flat()
|
|
1068
|
-
];
|
|
1069
|
-
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
|
+
});
|
|
1070
914
|
const startTimestamp = new Date("2023-01-02T00:00:00Z").getTime();
|
|
1071
915
|
const endTimestamp = new Date("2023-01-04T00:00:00Z").getTime();
|
|
1072
916
|
// Count using ModelQueryBuilder
|
|
@@ -1074,96 +918,8 @@ describe("Ad4mModel.count() with advanced where conditions", () => {
|
|
|
1074
918
|
.where({ timestamp: { between: [startTimestamp, endTimestamp] } })
|
|
1075
919
|
.engine('sparql')
|
|
1076
920
|
.count();
|
|
1077
|
-
// Verify count matches the number of instances that would be returned by get()
|
|
1078
|
-
const getResults = await Recipe.query(mockPerspective)
|
|
1079
|
-
.where({ timestamp: { between: [startTimestamp, endTimestamp] } })
|
|
1080
|
-
.engine('sparql')
|
|
1081
|
-
.get();
|
|
1082
|
-
expect(count).toBe(3);
|
|
1083
|
-
expect(count).toBe(getResults.length);
|
|
1084
|
-
});
|
|
1085
|
-
it("should handle count() with Prolog for gt operator (legacy)", async () => {
|
|
1086
|
-
const prologResults = [{ TotalCount: 2 }];
|
|
1087
|
-
mockPerspective.infer.mockResolvedValue(prologResults);
|
|
1088
|
-
const count = await Recipe.count(mockPerspective, { where: { rating: { gt: 3 } } }, false);
|
|
1089
|
-
expect(mockPerspective.infer).toHaveBeenCalledTimes(1);
|
|
1090
|
-
expect(mockPerspective.querySparql).not.toHaveBeenCalled();
|
|
1091
|
-
expect(count).toBe(2);
|
|
1092
|
-
});
|
|
1093
|
-
it("should handle count() with Prolog for timestamp between (legacy)", async () => {
|
|
1094
|
-
const prologResults = [{ TotalCount: 3 }];
|
|
1095
|
-
mockPerspective.infer.mockResolvedValue(prologResults);
|
|
1096
|
-
const startTimestamp = new Date("2023-01-02T00:00:00Z").getTime();
|
|
1097
|
-
const endTimestamp = new Date("2023-01-04T00:00:00Z").getTime();
|
|
1098
|
-
const count = await Recipe.count(mockPerspective, { where: { timestamp: { between: [startTimestamp, endTimestamp] } } }, false);
|
|
1099
|
-
expect(mockPerspective.infer).toHaveBeenCalledTimes(1);
|
|
1100
|
-
expect(mockPerspective.querySparql).not.toHaveBeenCalled();
|
|
1101
921
|
expect(count).toBe(3);
|
|
1102
|
-
|
|
1103
|
-
});
|
|
1104
|
-
// ──────────────────────────────────────────────────────────
|
|
1105
|
-
// Batch SPARQL query builder tests
|
|
1106
|
-
// ──────────────────────────────────────────────────────────
|
|
1107
|
-
import { buildBatchSPARQLQuery } from "./query-sparql-batch";
|
|
1108
|
-
describe("buildBatchSPARQLQuery", () => {
|
|
1109
|
-
let Author = class Author extends Ad4mModel {
|
|
1110
|
-
};
|
|
1111
|
-
__decorate([
|
|
1112
|
-
Property({ through: "author://name", required: true }),
|
|
1113
|
-
__metadata("design:type", String)
|
|
1114
|
-
], Author.prototype, "name", void 0);
|
|
1115
|
-
Author = __decorate([
|
|
1116
|
-
Model({ name: "Author" })
|
|
1117
|
-
], Author);
|
|
1118
|
-
let Book = class Book extends Ad4mModel {
|
|
1119
|
-
};
|
|
1120
|
-
__decorate([
|
|
1121
|
-
Property({ through: "book://title", required: true }),
|
|
1122
|
-
__metadata("design:type", String)
|
|
1123
|
-
], Book.prototype, "title", void 0);
|
|
1124
|
-
__decorate([
|
|
1125
|
-
HasMany(() => Author, { through: "book://author" }),
|
|
1126
|
-
__metadata("design:type", Array)
|
|
1127
|
-
], Book.prototype, "authors", void 0);
|
|
1128
|
-
Book = __decorate([
|
|
1129
|
-
Model({ name: "Book" })
|
|
1130
|
-
], Book);
|
|
1131
|
-
it("should generate UNION branches for depth 0 and depth 1 includes", () => {
|
|
1132
|
-
const metadata = Book.getModelMetadata();
|
|
1133
|
-
const query = { include: { authors: true } };
|
|
1134
|
-
const sparql = buildBatchSPARQLQuery(metadata, query, Book);
|
|
1135
|
-
expect(sparql).toContain("?depth");
|
|
1136
|
-
expect(sparql).toContain("?parentBase");
|
|
1137
|
-
expect(sparql).toContain("?relationName");
|
|
1138
|
-
expect(sparql).toContain("UNION");
|
|
1139
|
-
expect(sparql).toContain("BIND(\"0\" AS ?depth)");
|
|
1140
|
-
expect(sparql).toContain("BIND(\"1\" AS ?depth)");
|
|
1141
|
-
expect(sparql).toContain("book://author");
|
|
1142
|
-
});
|
|
1143
|
-
it("should include parent filter when query.parent is specified", () => {
|
|
1144
|
-
const metadata = Book.getModelMetadata();
|
|
1145
|
-
const query = {
|
|
1146
|
-
parent: { id: "flux://library1", predicate: "library://books" },
|
|
1147
|
-
include: { authors: true },
|
|
1148
|
-
};
|
|
1149
|
-
const sparql = buildBatchSPARQLQuery(metadata, query, Book);
|
|
1150
|
-
expect(sparql).toContain("flux://library1");
|
|
1151
|
-
expect(sparql).toContain("library://books");
|
|
1152
|
-
});
|
|
1153
|
-
it("should include where filter for simple equality", () => {
|
|
1154
|
-
const metadata = Book.getModelMetadata();
|
|
1155
|
-
const query = {
|
|
1156
|
-
where: { title: "My Book" },
|
|
1157
|
-
include: { authors: true },
|
|
1158
|
-
};
|
|
1159
|
-
const sparql = buildBatchSPARQLQuery(metadata, query, Book);
|
|
1160
|
-
// For literal-stored properties, SPARQL only has a JOIN (no FILTER value) — filtering in JS
|
|
1161
|
-
expect(sparql).toContain("book://title");
|
|
1162
|
-
expect(sparql).toContain("root_wTarget_eq_title");
|
|
1163
|
-
});
|
|
1164
|
-
it("should throw when include is empty", () => {
|
|
1165
|
-
const metadata = Book.getModelMetadata();
|
|
1166
|
-
expect(() => buildBatchSPARQLQuery(metadata, {}, Book)).toThrow("requires query.include");
|
|
922
|
+
expect(mockPerspective.modelQuery).toHaveBeenCalled();
|
|
1167
923
|
});
|
|
1168
924
|
});
|
|
1169
925
|
describe("SPARQL comparison filters", () => {
|
|
@@ -1202,7 +958,7 @@ describe("SPARQL comparison filters", () => {
|
|
|
1202
958
|
// ──────────────────────────────────────────────────────────
|
|
1203
959
|
// SPARQL Direct Triple Pattern & IRI Tests
|
|
1204
960
|
// ──────────────────────────────────────────────────────────
|
|
1205
|
-
import { buildSPARQLQuery,
|
|
961
|
+
import { buildSPARQLQuery, formatSPARQLValue } from "./query-sparql";
|
|
1206
962
|
describe("SPARQL direct triple pattern generation", () => {
|
|
1207
963
|
let Channel = class Channel extends Ad4mModel {
|
|
1208
964
|
constructor() {
|
|
@@ -1250,68 +1006,20 @@ describe("SPARQL direct triple pattern generation", () => {
|
|
|
1250
1006
|
expect(query).toContain("<flux://name>");
|
|
1251
1007
|
expect(query).toMatch(/\?source\s+<flux:\/\/name>\s+\?cfTarget_name/);
|
|
1252
1008
|
});
|
|
1253
|
-
it("uses
|
|
1254
|
-
const query = await Channel.queryToSPARQL(mockPersp, {});
|
|
1255
|
-
expect(query).toContain("GRAPH ?linkGraph { ?source ?predicate ?target . }");
|
|
1256
|
-
expect(query).toContain("?linkGraph <ad4m://ontology/author> ?author");
|
|
1257
|
-
expect(query).toContain("?linkGraph <ad4m://ontology/timestamp> ?timestamp");
|
|
1258
|
-
});
|
|
1259
|
-
it("does NOT contain RDF-star BIND(<< >> AS ?ann) pattern", async () => {
|
|
1009
|
+
it("uses RDF 1.2 reifier pattern for author/timestamp", async () => {
|
|
1260
1010
|
const query = await Channel.queryToSPARQL(mockPersp, {});
|
|
1261
|
-
expect(query).
|
|
1262
|
-
expect(query).
|
|
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");
|
|
1263
1017
|
});
|
|
1264
1018
|
it("uses FILTER(isIRI(?source)) to exclude non-IRI subjects", async () => {
|
|
1265
1019
|
const query = await Channel.queryToSPARQL(mockPersp, {});
|
|
1266
1020
|
expect(query).toContain("FILTER(isIRI(?source)");
|
|
1267
1021
|
});
|
|
1268
1022
|
});
|
|
1269
|
-
describe("SPARQL IRI formatting", () => {
|
|
1270
|
-
it("wraps AD4M URIs in angle brackets", () => {
|
|
1271
|
-
const query = buildSPARQLGetDataQuery("ad4m://test123");
|
|
1272
|
-
expect(query).toContain("<ad4m://test123>");
|
|
1273
|
-
});
|
|
1274
|
-
it("wraps literal: URIs in angle brackets", () => {
|
|
1275
|
-
const query = buildSPARQLGetDataQuery("literal:string:foo");
|
|
1276
|
-
expect(query).toContain("<literal:string:foo>");
|
|
1277
|
-
});
|
|
1278
|
-
it("wraps flux:// URIs in angle brackets", () => {
|
|
1279
|
-
const query = buildSPARQLGetDataQuery("flux://has_channel");
|
|
1280
|
-
expect(query).toContain("<flux://has_channel>");
|
|
1281
|
-
});
|
|
1282
|
-
it("wraps did:key URIs in angle brackets", () => {
|
|
1283
|
-
const query = buildSPARQLGetDataQuery("did:key:z6MkhaXg");
|
|
1284
|
-
expect(query).toContain("<did:key:z6MkhaXg>");
|
|
1285
|
-
});
|
|
1286
|
-
});
|
|
1287
|
-
describe("groupSPARQLResults", () => {
|
|
1288
|
-
it("groups flat rows by source URI", () => {
|
|
1289
|
-
const rows = [
|
|
1290
|
-
{ source: "ad4m://a", predicate: "p1", target: "t1", author: "auth1", timestamp: "ts1" },
|
|
1291
|
-
{ source: "ad4m://a", predicate: "p2", target: "t2", author: "auth1", timestamp: "ts1" },
|
|
1292
|
-
{ source: "ad4m://b", predicate: "p1", target: "t3", author: "auth2", timestamp: "ts2" },
|
|
1293
|
-
];
|
|
1294
|
-
const grouped = groupSPARQLResults(rows);
|
|
1295
|
-
expect(grouped).toHaveLength(2);
|
|
1296
|
-
const aGroup = grouped.find(g => g.source_uri === "ad4m://a");
|
|
1297
|
-
expect(aGroup).toBeDefined();
|
|
1298
|
-
expect(aGroup.links).toHaveLength(2);
|
|
1299
|
-
const bGroup = grouped.find(g => g.source_uri === "ad4m://b");
|
|
1300
|
-
expect(bGroup).toBeDefined();
|
|
1301
|
-
expect(bGroup.links).toHaveLength(1);
|
|
1302
|
-
});
|
|
1303
|
-
it("returns empty array for empty input", () => {
|
|
1304
|
-
expect(groupSPARQLResults([])).toEqual([]);
|
|
1305
|
-
});
|
|
1306
|
-
it("preserves metadata in grouped links", () => {
|
|
1307
|
-
const rows = [
|
|
1308
|
-
{ source: "x", predicate: "p", target: "t", author: "did:key:z6Mk", timestamp: "2024-01-01T00:00:00Z" },
|
|
1309
|
-
];
|
|
1310
|
-
const grouped = groupSPARQLResults(rows);
|
|
1311
|
-
expect(grouped[0].links[0].author).toBe("did:key:z6Mk");
|
|
1312
|
-
expect(grouped[0].links[0].timestamp).toBe("2024-01-01T00:00:00Z");
|
|
1313
|
-
});
|
|
1314
|
-
});
|
|
1315
1023
|
describe("formatSPARQLValue", () => {
|
|
1316
1024
|
it("wraps strings in double quotes", () => {
|
|
1317
1025
|
expect(formatSPARQLValue("hello")).toBe('"hello"');
|
|
@@ -1326,7 +1034,7 @@ describe("formatSPARQLValue", () => {
|
|
|
1326
1034
|
// ──────────────────────────────────────────────────────────
|
|
1327
1035
|
// Comprehensive SPARQL migration unit tests
|
|
1328
1036
|
// ──────────────────────────────────────────────────────────
|
|
1329
|
-
import { matchesCondition
|
|
1037
|
+
import { matchesCondition } from "./hydration";
|
|
1330
1038
|
import { Literal } from "../Literal";
|
|
1331
1039
|
// Helper: create literal URLs using JSON encoding (which handles all types including booleans)
|
|
1332
1040
|
function literalUrl(value) {
|
|
@@ -1424,207 +1132,6 @@ describe("matchesCondition()", () => {
|
|
|
1424
1132
|
expect(matchesCondition(undefined, { not: "hello" })).toBe(true);
|
|
1425
1133
|
});
|
|
1426
1134
|
});
|
|
1427
|
-
describe("hydrateFromLinks()", () => {
|
|
1428
|
-
// Create a mock perspective that won't be called for literal properties
|
|
1429
|
-
const mockPerspective = {};
|
|
1430
|
-
let HydrationTest = class HydrationTest extends Ad4mModel {
|
|
1431
|
-
constructor() {
|
|
1432
|
-
super(...arguments);
|
|
1433
|
-
this.name = "";
|
|
1434
|
-
this.score = 0;
|
|
1435
|
-
this.active = false;
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
__decorate([
|
|
1439
|
-
Property({ through: "test://name", resolveLanguage: "literal" }),
|
|
1440
|
-
__metadata("design:type", String)
|
|
1441
|
-
], HydrationTest.prototype, "name", void 0);
|
|
1442
|
-
__decorate([
|
|
1443
|
-
Property({ through: "test://score", resolveLanguage: "literal" }),
|
|
1444
|
-
__metadata("design:type", Number)
|
|
1445
|
-
], HydrationTest.prototype, "score", void 0);
|
|
1446
|
-
__decorate([
|
|
1447
|
-
Property({ through: "test://active", resolveLanguage: "literal" }),
|
|
1448
|
-
__metadata("design:type", Boolean)
|
|
1449
|
-
], HydrationTest.prototype, "active", void 0);
|
|
1450
|
-
HydrationTest = __decorate([
|
|
1451
|
-
Model({ name: "HydrationTest" })
|
|
1452
|
-
], HydrationTest);
|
|
1453
|
-
const metadata = HydrationTest.getModelMetadata();
|
|
1454
|
-
it("hydrates all properties when requestedProperties is undefined", async () => {
|
|
1455
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1456
|
-
const links = [
|
|
1457
|
-
{ predicate: "test://name", target: literalUrl("Alice"), author: "did:test", timestamp: "1000" },
|
|
1458
|
-
{ predicate: "test://score", target: literalUrl(42), author: "did:test", timestamp: "1000" },
|
|
1459
|
-
{ predicate: "test://active", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1460
|
-
];
|
|
1461
|
-
await hydrateFromLinks(instance, links, metadata, mockPerspective, undefined);
|
|
1462
|
-
expect(instance.name).toBe("Alice");
|
|
1463
|
-
expect(instance.score).toBe(42);
|
|
1464
|
-
expect(instance.active).toBe(true);
|
|
1465
|
-
});
|
|
1466
|
-
it("hydrates only requested properties when requestedProperties is provided", async () => {
|
|
1467
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1468
|
-
const links = [
|
|
1469
|
-
{ predicate: "test://name", target: literalUrl("Alice"), author: "did:test", timestamp: "1000" },
|
|
1470
|
-
{ predicate: "test://score", target: literalUrl(42), author: "did:test", timestamp: "1000" },
|
|
1471
|
-
{ predicate: "test://active", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1472
|
-
];
|
|
1473
|
-
await hydrateFromLinks(instance, links, metadata, mockPerspective, ["name"]);
|
|
1474
|
-
expect(instance.name).toBe("Alice");
|
|
1475
|
-
// score and active should remain at defaults since not requested
|
|
1476
|
-
expect(instance.score).toBe(0);
|
|
1477
|
-
expect(instance.active).toBe(false);
|
|
1478
|
-
});
|
|
1479
|
-
it("hydrates where-clause + projection properties when both are in requestedProperties", async () => {
|
|
1480
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1481
|
-
const links = [
|
|
1482
|
-
{ predicate: "test://name", target: literalUrl("Recipe 2"), author: "did:test", timestamp: "1000" },
|
|
1483
|
-
{ predicate: "test://active", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1484
|
-
];
|
|
1485
|
-
// Simulate merged hydration props: projection ["active"] + where clause props ["name"]
|
|
1486
|
-
await hydrateFromLinks(instance, links, metadata, mockPerspective, ["active", "name"]);
|
|
1487
|
-
expect(instance.name).toBe("Recipe 2");
|
|
1488
|
-
expect(instance.active).toBe(true);
|
|
1489
|
-
});
|
|
1490
|
-
it("sets author and timestamps from links", async () => {
|
|
1491
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1492
|
-
const links = [
|
|
1493
|
-
{ predicate: "test://name", target: literalUrl("Bob"), author: "did:author1", timestamp: "1000" },
|
|
1494
|
-
{ predicate: "test://score", target: literalUrl(10), author: "did:author2", timestamp: "2000" },
|
|
1495
|
-
];
|
|
1496
|
-
await hydrateFromLinks(instance, links, metadata, mockPerspective);
|
|
1497
|
-
expect(instance.author).toBe("did:author1");
|
|
1498
|
-
expect(instance.createdAt).toBe(1000);
|
|
1499
|
-
expect(instance.updatedAt).toBe(2000);
|
|
1500
|
-
});
|
|
1501
|
-
it("handles empty links array", async () => {
|
|
1502
|
-
const instance = new HydrationTest(mockPerspective);
|
|
1503
|
-
await hydrateFromLinks(instance, [], metadata, mockPerspective);
|
|
1504
|
-
expect(instance.name).toBe("");
|
|
1505
|
-
expect(instance.score).toBe(0);
|
|
1506
|
-
});
|
|
1507
|
-
});
|
|
1508
|
-
describe("instancesFromQueryResult — where + properties interaction", () => {
|
|
1509
|
-
const mockPerspective = {
|
|
1510
|
-
get: jest.fn().mockResolvedValue([]),
|
|
1511
|
-
querySparql: jest.fn().mockResolvedValue([]),
|
|
1512
|
-
getExpression: jest.fn().mockResolvedValue(null),
|
|
1513
|
-
};
|
|
1514
|
-
let Recipe = class Recipe extends Ad4mModel {
|
|
1515
|
-
constructor() {
|
|
1516
|
-
super(...arguments);
|
|
1517
|
-
this.name = "";
|
|
1518
|
-
this.booleanTest = false;
|
|
1519
|
-
this.score = 0;
|
|
1520
|
-
}
|
|
1521
|
-
};
|
|
1522
|
-
__decorate([
|
|
1523
|
-
Property({ through: "recipe://name", resolveLanguage: "literal", required: true }),
|
|
1524
|
-
__metadata("design:type", String)
|
|
1525
|
-
], Recipe.prototype, "name", void 0);
|
|
1526
|
-
__decorate([
|
|
1527
|
-
Property({ through: "recipe://booleanTest", resolveLanguage: "literal" }),
|
|
1528
|
-
__metadata("design:type", Boolean)
|
|
1529
|
-
], Recipe.prototype, "booleanTest", void 0);
|
|
1530
|
-
__decorate([
|
|
1531
|
-
Property({ through: "recipe://score", resolveLanguage: "literal" }),
|
|
1532
|
-
__metadata("design:type", Number)
|
|
1533
|
-
], Recipe.prototype, "score", void 0);
|
|
1534
|
-
Recipe = __decorate([
|
|
1535
|
-
Model({ name: "Recipe" })
|
|
1536
|
-
], Recipe);
|
|
1537
|
-
it("should filter by where clause property even when not in properties projection", async () => {
|
|
1538
|
-
// Simulate SPARQL result with two recipes
|
|
1539
|
-
const grouped = [
|
|
1540
|
-
{
|
|
1541
|
-
source_uri: "expr:recipe1",
|
|
1542
|
-
links: [
|
|
1543
|
-
{ predicate: "recipe://name", target: literalUrl("Recipe 1"), author: "did:test", timestamp: "1000" },
|
|
1544
|
-
{ predicate: "recipe://booleanTest", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1545
|
-
],
|
|
1546
|
-
},
|
|
1547
|
-
{
|
|
1548
|
-
source_uri: "expr:recipe2",
|
|
1549
|
-
links: [
|
|
1550
|
-
{ predicate: "recipe://name", target: literalUrl("Recipe 2"), author: "did:test", timestamp: "1000" },
|
|
1551
|
-
{ predicate: "recipe://booleanTest", target: literalUrl(false), author: "did:test", timestamp: "1000" },
|
|
1552
|
-
],
|
|
1553
|
-
},
|
|
1554
|
-
];
|
|
1555
|
-
const query = { where: { name: "Recipe 2" }, properties: ["booleanTest"] };
|
|
1556
|
-
const { results } = await Recipe.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1557
|
-
expect(results.length).toBe(1);
|
|
1558
|
-
expect(results[0].booleanTest).toBe(false);
|
|
1559
|
-
// name should be deleted after filtering since it wasn't in properties projection
|
|
1560
|
-
expect(results[0].name).toBeUndefined();
|
|
1561
|
-
});
|
|
1562
|
-
it("should delete unrequested properties AFTER where-filtering", async () => {
|
|
1563
|
-
const grouped = [
|
|
1564
|
-
{
|
|
1565
|
-
source_uri: "expr:recipe1",
|
|
1566
|
-
links: [
|
|
1567
|
-
{ predicate: "recipe://name", target: literalUrl("Recipe 1"), author: "did:test", timestamp: "1000" },
|
|
1568
|
-
{ predicate: "recipe://score", target: literalUrl(99), author: "did:test", timestamp: "1000" },
|
|
1569
|
-
],
|
|
1570
|
-
},
|
|
1571
|
-
];
|
|
1572
|
-
const query = { where: { name: "Recipe 1" }, properties: ["score"] };
|
|
1573
|
-
const { results } = await Recipe.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1574
|
-
expect(results.length).toBe(1);
|
|
1575
|
-
expect(results[0].score).toBe(99);
|
|
1576
|
-
// name was used for filtering but should be deleted from final result
|
|
1577
|
-
expect(results[0].name).toBeUndefined();
|
|
1578
|
-
});
|
|
1579
|
-
it("should return all properties when no projection is specified", async () => {
|
|
1580
|
-
const grouped = [
|
|
1581
|
-
{
|
|
1582
|
-
source_uri: "expr:recipe1",
|
|
1583
|
-
links: [
|
|
1584
|
-
{ predicate: "recipe://name", target: literalUrl("Test"), author: "did:test", timestamp: "1000" },
|
|
1585
|
-
{ predicate: "recipe://booleanTest", target: literalUrl(true), author: "did:test", timestamp: "1000" },
|
|
1586
|
-
{ predicate: "recipe://score", target: literalUrl(50), author: "did:test", timestamp: "1000" },
|
|
1587
|
-
],
|
|
1588
|
-
},
|
|
1589
|
-
];
|
|
1590
|
-
const query = { where: { name: "Test" } };
|
|
1591
|
-
const { results } = await Recipe.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1592
|
-
expect(results.length).toBe(1);
|
|
1593
|
-
expect(results[0].name).toBe("Test");
|
|
1594
|
-
expect(results[0].booleanTest).toBe(true);
|
|
1595
|
-
expect(results[0].score).toBe(50);
|
|
1596
|
-
});
|
|
1597
|
-
});
|
|
1598
|
-
describe("groupSPARQLResults()", () => {
|
|
1599
|
-
it("groups rows by source", () => {
|
|
1600
|
-
const rows = [
|
|
1601
|
-
{ source: "a", predicate: "p1", target: "t1", author: "auth", timestamp: "ts1" },
|
|
1602
|
-
{ source: "a", predicate: "p2", target: "t2", author: "auth", timestamp: "ts2" },
|
|
1603
|
-
{ source: "b", predicate: "p1", target: "t3", author: "auth", timestamp: "ts3" },
|
|
1604
|
-
];
|
|
1605
|
-
const grouped = groupSPARQLResults(rows);
|
|
1606
|
-
expect(grouped.length).toBe(2);
|
|
1607
|
-
const groupA = grouped.find(g => g.source_uri === "a");
|
|
1608
|
-
const groupB = grouped.find(g => g.source_uri === "b");
|
|
1609
|
-
expect(groupA.links.length).toBe(2);
|
|
1610
|
-
expect(groupB.links.length).toBe(1);
|
|
1611
|
-
});
|
|
1612
|
-
it("handles empty input", () => {
|
|
1613
|
-
expect(groupSPARQLResults([])).toEqual([]);
|
|
1614
|
-
});
|
|
1615
|
-
it("preserves link metadata", () => {
|
|
1616
|
-
const rows = [
|
|
1617
|
-
{ source: "x", predicate: "pred", target: "tgt", author: "did:auth", timestamp: "2024-01-01" },
|
|
1618
|
-
];
|
|
1619
|
-
const grouped = groupSPARQLResults(rows);
|
|
1620
|
-
expect(grouped[0].links[0]).toEqual({
|
|
1621
|
-
predicate: "pred",
|
|
1622
|
-
target: "tgt",
|
|
1623
|
-
author: "did:auth",
|
|
1624
|
-
timestamp: "2024-01-01",
|
|
1625
|
-
});
|
|
1626
|
-
});
|
|
1627
|
-
});
|
|
1628
1135
|
describe("buildSPARQLQuery edge cases", () => {
|
|
1629
1136
|
let FlagModel = class FlagModel extends Ad4mModel {
|
|
1630
1137
|
constructor() {
|
|
@@ -1690,85 +1197,6 @@ describe("buildSPARQLQuery edge cases", () => {
|
|
|
1690
1197
|
expect(sparql).toContain("expr:123");
|
|
1691
1198
|
});
|
|
1692
1199
|
});
|
|
1693
|
-
describe("sparse fieldset property deletion timing", () => {
|
|
1694
|
-
const mockPerspective = {
|
|
1695
|
-
get: jest.fn().mockResolvedValue([]),
|
|
1696
|
-
querySparql: jest.fn().mockResolvedValue([]),
|
|
1697
|
-
getExpression: jest.fn().mockResolvedValue(null),
|
|
1698
|
-
};
|
|
1699
|
-
let TimingTest = class TimingTest extends Ad4mModel {
|
|
1700
|
-
constructor() {
|
|
1701
|
-
super(...arguments);
|
|
1702
|
-
this.a = "";
|
|
1703
|
-
this.b = "";
|
|
1704
|
-
this.c = "";
|
|
1705
|
-
}
|
|
1706
|
-
};
|
|
1707
|
-
__decorate([
|
|
1708
|
-
Property({ through: "timing://a", resolveLanguage: "literal" }),
|
|
1709
|
-
__metadata("design:type", String)
|
|
1710
|
-
], TimingTest.prototype, "a", void 0);
|
|
1711
|
-
__decorate([
|
|
1712
|
-
Property({ through: "timing://b", resolveLanguage: "literal" }),
|
|
1713
|
-
__metadata("design:type", String)
|
|
1714
|
-
], TimingTest.prototype, "b", void 0);
|
|
1715
|
-
__decorate([
|
|
1716
|
-
Property({ through: "timing://c", resolveLanguage: "literal" }),
|
|
1717
|
-
__metadata("design:type", String)
|
|
1718
|
-
], TimingTest.prototype, "c", void 0);
|
|
1719
|
-
TimingTest = __decorate([
|
|
1720
|
-
Model({ name: "TimingTest" })
|
|
1721
|
-
], TimingTest);
|
|
1722
|
-
it("where-clause properties are available during filtering but deleted after", async () => {
|
|
1723
|
-
const grouped = [
|
|
1724
|
-
{
|
|
1725
|
-
source_uri: "expr:1",
|
|
1726
|
-
links: [
|
|
1727
|
-
{ predicate: "timing://a", target: literalUrl("match"), author: "did:test", timestamp: "1000" },
|
|
1728
|
-
{ predicate: "timing://b", target: literalUrl("keep"), author: "did:test", timestamp: "1000" },
|
|
1729
|
-
{ predicate: "timing://c", target: literalUrl("ignore"), author: "did:test", timestamp: "1000" },
|
|
1730
|
-
],
|
|
1731
|
-
},
|
|
1732
|
-
{
|
|
1733
|
-
source_uri: "expr:2",
|
|
1734
|
-
links: [
|
|
1735
|
-
{ predicate: "timing://a", target: literalUrl("no-match"), author: "did:test", timestamp: "1000" },
|
|
1736
|
-
{ predicate: "timing://b", target: literalUrl("skip"), author: "did:test", timestamp: "1000" },
|
|
1737
|
-
{ predicate: "timing://c", target: literalUrl("skip"), author: "did:test", timestamp: "1000" },
|
|
1738
|
-
],
|
|
1739
|
-
},
|
|
1740
|
-
];
|
|
1741
|
-
// properties projection asks for "b" only, where clause filters on "a"
|
|
1742
|
-
const query = { where: { a: "match" }, properties: ["b"] };
|
|
1743
|
-
const { results } = await TimingTest.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1744
|
-
// Only the matching instance should survive
|
|
1745
|
-
expect(results.length).toBe(1);
|
|
1746
|
-
// "b" was requested — should be present
|
|
1747
|
-
expect(results[0].b).toBe("keep");
|
|
1748
|
-
// "a" was used for filtering but not in projection — should be deleted
|
|
1749
|
-
expect(results[0].a).toBeUndefined();
|
|
1750
|
-
// "c" was not requested — should be deleted
|
|
1751
|
-
expect(results[0].c).toBeUndefined();
|
|
1752
|
-
});
|
|
1753
|
-
it("properties not in projection are undefined after instancesFromQueryResult", async () => {
|
|
1754
|
-
const grouped = [
|
|
1755
|
-
{
|
|
1756
|
-
source_uri: "expr:1",
|
|
1757
|
-
links: [
|
|
1758
|
-
{ predicate: "timing://a", target: literalUrl("val-a"), author: "did:test", timestamp: "1000" },
|
|
1759
|
-
{ predicate: "timing://b", target: literalUrl("val-b"), author: "did:test", timestamp: "1000" },
|
|
1760
|
-
{ predicate: "timing://c", target: literalUrl("val-c"), author: "did:test", timestamp: "1000" },
|
|
1761
|
-
],
|
|
1762
|
-
},
|
|
1763
|
-
];
|
|
1764
|
-
const query = { properties: ["a"] };
|
|
1765
|
-
const { results } = await TimingTest.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
1766
|
-
expect(results.length).toBe(1);
|
|
1767
|
-
expect(results[0].a).toBe("val-a");
|
|
1768
|
-
expect(results[0].b).toBeUndefined();
|
|
1769
|
-
expect(results[0].c).toBeUndefined();
|
|
1770
|
-
});
|
|
1771
|
-
});
|
|
1772
1200
|
// ── Batch hydration for reverse relations (3.4) ─────────────────────────────
|
|
1773
1201
|
describe("Batch hydration for reverse relations", () => {
|
|
1774
1202
|
it("batch hydration should correctly group targets by parent instance ID", () => {
|
|
@@ -2090,17 +1518,30 @@ describe("Native SPARQL getter evaluation", () => {
|
|
|
2090
1518
|
// ── Subscribe callback timing ──────────────────────────────────────────
|
|
2091
1519
|
describe("ModelQueryBuilder subscribe callback timing", () => {
|
|
2092
1520
|
it("subscribe should not invoke callback synchronously before Promise resolves", async () => {
|
|
2093
|
-
// This test verifies that
|
|
2094
|
-
//
|
|
2095
|
-
|
|
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
|
+
};
|
|
2096
1537
|
const mockPerspective = {
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
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);
|
|
2102
1542
|
}),
|
|
2103
|
-
|
|
1543
|
+
getLinks: jest.fn().mockResolvedValue([]),
|
|
1544
|
+
modelQuery: jest.fn().mockResolvedValue({ instances: [], totalCount: 0 }),
|
|
2104
1545
|
};
|
|
2105
1546
|
const { Ad4mModel, Model, Property, Flag } = require("./index");
|
|
2106
1547
|
let TimingTest = class TimingTest extends Ad4mModel {
|
|
@@ -2132,11 +1573,192 @@ describe("ModelQueryBuilder subscribe callback timing", () => {
|
|
|
2132
1573
|
// At this point the Promise hasn't resolved yet
|
|
2133
1574
|
// The callback should NOT have fired synchronously
|
|
2134
1575
|
expect(callbackInvokedBeforeResolve).toBe(false);
|
|
2135
|
-
await promise;
|
|
1576
|
+
const initialResults = await promise;
|
|
2136
1577
|
promiseResolved = true;
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
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);
|
|
2140
1762
|
});
|
|
2141
1763
|
});
|
|
2142
1764
|
// ============================================================================
|
|
@@ -2309,63 +1931,6 @@ describe("Lazy Conformance Filters", () => {
|
|
|
2309
1931
|
});
|
|
2310
1932
|
});
|
|
2311
1933
|
// ──────────────────────────────────────────────────────────
|
|
2312
|
-
// instancesFromQueryResult — SPARQL vs JS pagination behaviour
|
|
2313
|
-
// ──────────────────────────────────────────────────────────
|
|
2314
|
-
describe("instancesFromQueryResult — SPARQL vs JS pagination", () => {
|
|
2315
|
-
let PaginationTestChannel = class PaginationTestChannel extends Ad4mModel {
|
|
2316
|
-
constructor() {
|
|
2317
|
-
super(...arguments);
|
|
2318
|
-
this.type = "";
|
|
2319
|
-
this.name = "";
|
|
2320
|
-
}
|
|
2321
|
-
};
|
|
2322
|
-
__decorate([
|
|
2323
|
-
Flag({ through: "flux://entry_type", value: "flux://channel" }),
|
|
2324
|
-
__metadata("design:type", String)
|
|
2325
|
-
], PaginationTestChannel.prototype, "type", void 0);
|
|
2326
|
-
__decorate([
|
|
2327
|
-
Property({ through: "flux://name", resolveLanguage: "literal" }),
|
|
2328
|
-
__metadata("design:type", String)
|
|
2329
|
-
], PaginationTestChannel.prototype, "name", void 0);
|
|
2330
|
-
PaginationTestChannel = __decorate([
|
|
2331
|
-
Model({ name: "PaginationTestChannel" })
|
|
2332
|
-
], PaginationTestChannel);
|
|
2333
|
-
const mockPerspective = {
|
|
2334
|
-
uuid: "test-uuid",
|
|
2335
|
-
querySparql: jest.fn().mockResolvedValue([]),
|
|
2336
|
-
get: jest.fn().mockResolvedValue([]),
|
|
2337
|
-
getExpression: jest.fn().mockResolvedValue(null),
|
|
2338
|
-
};
|
|
2339
|
-
it("does NOT slice results when SPARQL pagination was applied", async () => {
|
|
2340
|
-
const grouped = Array.from({ length: 5 }, (_, i) => ({
|
|
2341
|
-
source_uri: `flux://ch-${i}`,
|
|
2342
|
-
links: [
|
|
2343
|
-
{ predicate: "flux://entry_type", target: "flux://channel", author: "did:key:a", timestamp: String(1000 + i) },
|
|
2344
|
-
{ predicate: "flux://name", target: `literal:string:Channel${i}`, author: "did:key:a", timestamp: String(1000 + i) },
|
|
2345
|
-
],
|
|
2346
|
-
}));
|
|
2347
|
-
// Include order to trigger SPARQL-level pagination (subquery with ORDER BY)
|
|
2348
|
-
const query = { limit: 5, offset: 10, order: { name: 'ASC' } };
|
|
2349
|
-
const result = await PaginationTestChannel.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
2350
|
-
// sparqlPaginated = true (limit+offset+order present, no JS-only where filters),
|
|
2351
|
-
// so JS should NOT re-slice — all 5 items come through as-is.
|
|
2352
|
-
expect(result.results.length).toBe(5);
|
|
2353
|
-
expect(result.totalCount).toBe(5);
|
|
2354
|
-
});
|
|
2355
|
-
it("applies JS-level slicing as fallback when JS-only filters exist", async () => {
|
|
2356
|
-
const grouped = Array.from({ length: 10 }, (_, i) => ({
|
|
2357
|
-
source_uri: `flux://ch-${i}`,
|
|
2358
|
-
links: [
|
|
2359
|
-
{ predicate: "flux://entry_type", target: "flux://channel", author: "did:key:a", timestamp: String(1000 + i) },
|
|
2360
|
-
{ predicate: "flux://name", target: `literal:string:Ch${i}`, author: "did:key:a", timestamp: String(1000 + i) },
|
|
2361
|
-
],
|
|
2362
|
-
}));
|
|
2363
|
-
const query = { limit: 3, offset: 0, where: { author: "did:key:a" } };
|
|
2364
|
-
const result = await PaginationTestChannel.instancesFromQueryResult(mockPerspective, query, grouped);
|
|
2365
|
-
expect(result.results.length).toBe(3);
|
|
2366
|
-
});
|
|
2367
|
-
});
|
|
2368
|
-
// ──────────────────────────────────────────────────────────
|
|
2369
1934
|
// deepQuery opt-in — getter evaluation on collection queries
|
|
2370
1935
|
// ──────────────────────────────────────────────────────────
|
|
2371
1936
|
describe("deepQuery opt-in — getter evaluation", () => {
|
|
@@ -2410,6 +1975,18 @@ describe("deepQuery opt-in — getter evaluation", () => {
|
|
|
2410
1975
|
let sparqlCalls;
|
|
2411
1976
|
const mockPerspective = {
|
|
2412
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
|
+
}),
|
|
2413
1990
|
querySparql: jest.fn(async (q) => {
|
|
2414
1991
|
sparqlCalls.push(q);
|
|
2415
1992
|
return [];
|
|
@@ -2423,30 +2000,10 @@ describe("deepQuery opt-in — getter evaluation", () => {
|
|
|
2423
2000
|
mockPerspective.querySparql.mockClear();
|
|
2424
2001
|
mockPerspective.get.mockClear();
|
|
2425
2002
|
});
|
|
2426
|
-
function
|
|
2427
|
-
return Array.from({ length: count }, (_, i) => ({
|
|
2428
|
-
source_uri: `flux://msg-${i}`,
|
|
2429
|
-
links: [
|
|
2430
|
-
{ predicate: "flux://entry_type", target: "flux://message", author: "did:key:a", timestamp: String(2000 + i) },
|
|
2431
|
-
{ predicate: "flux://body", target: `literal:string:Hello${i}`, author: "did:key:a", timestamp: String(2000 + i) },
|
|
2432
|
-
],
|
|
2433
|
-
}));
|
|
2003
|
+
function makeInstances(count) {
|
|
2004
|
+
return Array.from({ length: count }, (_, i) => new DeepQueryTestMessage(mockPerspective, `flux://msg-${i}`));
|
|
2434
2005
|
}
|
|
2435
|
-
it("
|
|
2436
|
-
const grouped = makeMessageRows(5);
|
|
2437
|
-
const result = await DeepQueryTestMessage.instancesFromQueryResult(mockPerspective, {}, grouped);
|
|
2438
|
-
expect(result.results.length).toBe(5);
|
|
2439
|
-
const getterCalls = sparqlCalls.filter((q) => q.includes("flux://has_reply") || q.includes("flux://is_popular"));
|
|
2440
|
-
expect(getterCalls.length).toBe(0);
|
|
2441
|
-
});
|
|
2442
|
-
it("evaluates getter properties when deepQuery is true", async () => {
|
|
2443
|
-
const grouped = makeMessageRows(3);
|
|
2444
|
-
const result = await DeepQueryTestMessage.instancesFromQueryResult(mockPerspective, { deepQuery: true }, grouped);
|
|
2445
|
-
expect(result.results.length).toBe(3);
|
|
2446
|
-
const getterCalls = sparqlCalls.filter((q) => q.includes("flux://has_reply") || q.includes("flux://is_popular"));
|
|
2447
|
-
expect(getterCalls.length).toBe(6); // 3 instances × 2 getters
|
|
2448
|
-
});
|
|
2449
|
-
it("single-instance get() still evaluates getters by default", async () => {
|
|
2006
|
+
it("single-instance get() delegates getter evaluation to Rust (no JS-side SPARQL)", async () => {
|
|
2450
2007
|
const instance = new DeepQueryTestMessage(mockPerspective, "flux://msg-single");
|
|
2451
2008
|
mockPerspective.querySparql.mockImplementation(async (q) => {
|
|
2452
2009
|
sparqlCalls.push(q);
|
|
@@ -2459,25 +2016,24 @@ describe("deepQuery opt-in — getter evaluation", () => {
|
|
|
2459
2016
|
return [];
|
|
2460
2017
|
});
|
|
2461
2018
|
await instance.get();
|
|
2019
|
+
// Getter evaluation now happens Rust-side via evaluate_getters() — no JS SPARQL calls
|
|
2462
2020
|
const getterCalls = sparqlCalls.filter((q) => q.includes("flux://has_reply") || q.includes("flux://is_popular"));
|
|
2463
|
-
expect(getterCalls.length).toBe(
|
|
2021
|
+
expect(getterCalls.length).toBe(0);
|
|
2464
2022
|
});
|
|
2465
2023
|
describe("Ad4mModel.evaluateGetters()", () => {
|
|
2466
2024
|
it("resolves getters for a batch of instances", async () => {
|
|
2467
|
-
const
|
|
2468
|
-
const result = await DeepQueryTestMessage.instancesFromQueryResult(mockPerspective, {}, grouped);
|
|
2025
|
+
const instances = makeInstances(4);
|
|
2469
2026
|
sparqlCalls = [];
|
|
2470
|
-
await DeepQueryTestMessage.evaluateGetters(
|
|
2027
|
+
await DeepQueryTestMessage.evaluateGetters(instances.slice(0, 2), mockPerspective, ["replyingTo"]);
|
|
2471
2028
|
const replyCalls = sparqlCalls.filter((q) => q.includes("flux://has_reply"));
|
|
2472
2029
|
expect(replyCalls.length).toBe(2);
|
|
2473
2030
|
const popularCalls = sparqlCalls.filter((q) => q.includes("flux://is_popular"));
|
|
2474
2031
|
expect(popularCalls.length).toBe(0);
|
|
2475
2032
|
});
|
|
2476
2033
|
it("evaluates all getters when propertyNames is omitted", async () => {
|
|
2477
|
-
const
|
|
2478
|
-
const result = await DeepQueryTestMessage.instancesFromQueryResult(mockPerspective, {}, grouped);
|
|
2034
|
+
const instances = makeInstances(2);
|
|
2479
2035
|
sparqlCalls = [];
|
|
2480
|
-
await DeepQueryTestMessage.evaluateGetters(
|
|
2036
|
+
await DeepQueryTestMessage.evaluateGetters(instances, mockPerspective);
|
|
2481
2037
|
const replyCalls = sparqlCalls.filter((q) => q.includes("flux://has_reply"));
|
|
2482
2038
|
const popularCalls = sparqlCalls.filter((q) => q.includes("flux://is_popular"));
|
|
2483
2039
|
expect(replyCalls.length).toBe(2);
|