@coasys/ad4m 0.12.1-dev → 0.13.0-postmessage-ws-proxy.0
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 +5097 -11841
- package/lib/index.js +5289 -12104
- package/lib/src/Ad4mClient.d.ts +9 -3
- package/lib/src/Ad4mClient.js +40 -13
- package/lib/src/Literal.js +6 -5
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +33 -21
- package/lib/src/agent/AgentClient.js +180 -374
- 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 +53 -0
- package/lib/src/apiClient.js +234 -0
- package/lib/src/cache/PersistentCache.d.ts +40 -0
- package/lib/src/cache/PersistentCache.js +139 -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 +11 -3
- package/lib/src/expression/ExpressionClient.js +120 -75
- package/lib/src/expression/ExpressionRef.js +4 -27
- 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 +7 -2
- package/lib/src/index.js +7 -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 -176
- 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 +150 -62
- package/lib/src/model/Ad4mModel.js +689 -417
- package/lib/src/model/Ad4mModel.test.js +1434 -688
- package/lib/src/model/ModelQueryBuilder.d.ts +59 -38
- package/lib/src/model/ModelQueryBuilder.js +317 -153
- package/lib/src/model/Subject.js +6 -6
- package/lib/src/model/decorators.d.ts +36 -8
- package/lib/src/model/decorators.js +41 -14
- package/lib/src/model/hydration-batch.d.ts +34 -0
- package/lib/src/model/hydration-batch.js +147 -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 +3 -92
- package/lib/src/model/hydration.js +3 -691
- package/lib/src/model/index.d.ts +3 -4
- package/lib/src/model/index.js +3 -4
- package/lib/src/model/json-schema.js +2 -2
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-cache.d.ts +30 -0
- package/lib/src/model/query-cache.js +66 -0
- package/lib/src/model/query-cache.test.d.ts +1 -0
- package/lib/src/model/query-cache.test.js +43 -0
- package/lib/src/model/query-common.d.ts +1 -1
- package/lib/src/model/query-common.js +1 -1
- package/lib/src/model/query-sparql-batch.d.ts +17 -0
- package/lib/src/model/query-sparql-batch.js +260 -0
- package/lib/src/model/query-sparql.d.ts +51 -0
- package/lib/src/model/query-sparql.js +466 -0
- 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/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
- package/lib/src/model/query-utils.js +189 -0
- package/lib/src/model/relation-filtering.test.js +15 -15
- package/lib/src/model/sdna.js +1 -1
- package/lib/src/model/shacl-gen.js +46 -18
- 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.d.ts +39 -0
- package/lib/src/model/subscription-pool.js +165 -0
- package/lib/src/model/types.d.ts +60 -5
- package/lib/src/model/types.js +5 -2
- 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 +22 -32
- package/lib/src/perspectives/PerspectiveClient.js +189 -454
- 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 +156 -78
- package/lib/src/perspectives/PerspectiveProxy.js +474 -389
- package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveResolver.js +0 -11
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
- package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
- package/lib/src/runtime/RuntimeClient.d.ts +8 -6
- package/lib/src/runtime/RuntimeClient.js +97 -454
- package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
- package/lib/src/runtime/RuntimeResolver.js +84 -0
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/schema.gql +14 -1
- package/lib/src/shacl/SHACLFlow.d.ts +1 -1
- package/lib/src/shacl/SHACLFlow.js +9 -9
- package/lib/src/shacl/SHACLShape.d.ts +8 -1
- package/lib/src/shacl/SHACLShape.js +57 -38
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -615
- package/lib/src/utils.d.ts +6 -6
- package/lib/src/utils.js +6 -6
- package/package.json +6 -18
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1192 -1288
- package/src/Ad4mClient.ts +46 -15
- package/src/Literal.test.ts +10 -5
- package/src/Literal.ts +6 -5
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +238 -467
- 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 +287 -0
- package/src/cache/PersistentCache.ts +145 -0
- package/src/cache/cache.test.ts +713 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +148 -77
- package/src/expression/ExpressionRef.ts +2 -8
- 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 +7 -2
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +51 -248
- 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 +1690 -777
- package/src/model/Ad4mModel.ts +749 -477
- package/src/model/ModelQueryBuilder.ts +356 -171
- package/src/model/decorators.ts +71 -22
- package/src/model/hydration.ts +3 -772
- package/src/model/index.ts +3 -4
- package/src/model/json-schema.ts +2 -2
- package/src/model/query-cache.test.ts +54 -0
- package/src/model/query-cache.ts +79 -0
- package/src/model/query-common.ts +1 -1
- package/src/model/query-sparql.test.ts +376 -0
- package/src/model/query-sparql.ts +504 -0
- package/src/model/query-utils.ts +209 -0
- package/src/model/relation-filtering.test.ts +15 -15
- package/src/model/sdna.ts +1 -1
- package/src/model/shacl-gen.ts +47 -17
- package/src/model/types.ts +65 -5
- 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 +254 -468
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +125 -0
- package/src/perspectives/PerspectiveProxy.ts +522 -434
- package/src/perspectives/WakerSubscriptionManager.ts +13 -13
- package/src/runtime/RuntimeClient.ts +118 -461
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLFlow.ts +9 -9
- package/src/shacl/SHACLShape.test.ts +94 -0
- package/src/shacl/SHACLShape.ts +66 -39
- package/src/typeDefs.ts +3 -5
- package/src/utils.ts +6 -6
- 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.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/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-surreal.ts +0 -280
- package/src/model/surreal-utils.ts +0 -147
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -372
- package/src/runtime/RuntimeResolver.ts +0 -691
- package/src/unwrapApolloResult.ts +0 -16
- package/tsconfig-browser.json +0 -82
package/src/model/index.ts
CHANGED
|
@@ -9,13 +9,12 @@
|
|
|
9
9
|
export * from "./types";
|
|
10
10
|
export * from "./Ad4mModel";
|
|
11
11
|
export * from "./decorators";
|
|
12
|
-
export * from "./Subject";
|
|
13
12
|
export * from "./query-common";
|
|
14
|
-
export * from "./query-prolog";
|
|
15
|
-
export * from "./prolog-facts";
|
|
16
13
|
export * from "./json-schema";
|
|
17
|
-
export * from "./query-
|
|
14
|
+
export * from "./query-utils";
|
|
15
|
+
export * from "./query-sparql";
|
|
18
16
|
export * from "./hydration";
|
|
19
17
|
export * from "./ModelQueryBuilder";
|
|
20
18
|
export * from "./sdna";
|
|
21
19
|
export * from "./shacl-gen";
|
|
20
|
+
export * from "./query-cache";
|
package/src/model/json-schema.ts
CHANGED
|
@@ -353,7 +353,7 @@ export function buildModelFromJSONSchema(
|
|
|
353
353
|
|
|
354
354
|
// Default resolveLanguage to 'literal' for all remaining property types,
|
|
355
355
|
// matching the @Property decorator behaviour. Without this, string values
|
|
356
|
-
// stored as literal
|
|
356
|
+
// stored as literal: URLs are returned unparsed.
|
|
357
357
|
if (resolveLanguage === undefined || resolveLanguage === null) {
|
|
358
358
|
resolveLanguage = 'literal';
|
|
359
359
|
}
|
|
@@ -361,7 +361,7 @@ export function buildModelFromJSONSchema(
|
|
|
361
361
|
// If property is required, ensure it has an initial value
|
|
362
362
|
if (isRequired && !initial) {
|
|
363
363
|
if (isObjectType(propertySchema)) {
|
|
364
|
-
initial = 'literal
|
|
364
|
+
initial = 'literal:json:{}';
|
|
365
365
|
} else {
|
|
366
366
|
initial = "ad4m://undefined";
|
|
367
367
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getCachedResult, setCachedResult, invalidatePerspectiveCache, clearQueryCache, queryCacheSize } from './query-cache';
|
|
2
|
+
|
|
3
|
+
describe('query-cache', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
clearQueryCache();
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
describe('lazy eviction', () => {
|
|
9
|
+
it('should remove expired entries when setting a new one', () => {
|
|
10
|
+
// Insert with a very short TTL
|
|
11
|
+
setCachedResult('p1', 'SELECT ?x', 'result1', 1);
|
|
12
|
+
expect(queryCacheSize()).toBe(1);
|
|
13
|
+
|
|
14
|
+
// Wait for expiry
|
|
15
|
+
const start = Date.now();
|
|
16
|
+
while (Date.now() - start < 5) { /* busy wait 5ms */ }
|
|
17
|
+
|
|
18
|
+
// Expired entry should still be in the map (not yet evicted)
|
|
19
|
+
// but getCachedResult should return undefined
|
|
20
|
+
expect(getCachedResult('p1', 'SELECT ?x')).toBeUndefined();
|
|
21
|
+
|
|
22
|
+
// Setting a new entry should evict the expired one
|
|
23
|
+
setCachedResult('p2', 'SELECT ?y', 'result2', 10000);
|
|
24
|
+
// Only the new entry should remain
|
|
25
|
+
expect(queryCacheSize()).toBe(1);
|
|
26
|
+
expect(getCachedResult('p2', 'SELECT ?y')).toBe('result2');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('invalidatePerspectiveCache', () => {
|
|
31
|
+
it('should remove all entries for a specific perspective', () => {
|
|
32
|
+
setCachedResult('p1', 'query1', 'r1', 10000);
|
|
33
|
+
setCachedResult('p1', 'query2', 'r2', 10000);
|
|
34
|
+
setCachedResult('p2', 'query1', 'r3', 10000);
|
|
35
|
+
expect(queryCacheSize()).toBe(3);
|
|
36
|
+
|
|
37
|
+
invalidatePerspectiveCache('p1');
|
|
38
|
+
|
|
39
|
+
expect(queryCacheSize()).toBe(1);
|
|
40
|
+
expect(getCachedResult('p1', 'query1')).toBeUndefined();
|
|
41
|
+
expect(getCachedResult('p1', 'query2')).toBeUndefined();
|
|
42
|
+
expect(getCachedResult('p2', 'query1')).toBe('r3');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should not affect other perspectives', () => {
|
|
46
|
+
setCachedResult('p1', 'q', 'r1', 10000);
|
|
47
|
+
setCachedResult('p2', 'q', 'r2', 10000);
|
|
48
|
+
|
|
49
|
+
invalidatePerspectiveCache('p3');
|
|
50
|
+
|
|
51
|
+
expect(queryCacheSize()).toBe(2);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Result TTL Cache
|
|
3
|
+
*
|
|
4
|
+
* Short-lived cache (200ms TTL) for SPARQL query results.
|
|
5
|
+
* Prevents redundant queries during rapid render cycles where
|
|
6
|
+
* multiple components issue the same query within milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* Key: `perspectiveUUID + queryText`
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface CacheEntry {
|
|
12
|
+
result: any;
|
|
13
|
+
expiry: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const cache = new Map<string, CacheEntry>();
|
|
17
|
+
|
|
18
|
+
const DEFAULT_TTL_MS = 200;
|
|
19
|
+
|
|
20
|
+
function makeKey(perspectiveUUID: string, queryText: string): string {
|
|
21
|
+
return `${perspectiveUUID}:${queryText}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Get a cached query result if it exists and hasn't expired.
|
|
26
|
+
*/
|
|
27
|
+
export function getCachedResult(perspectiveUUID: string, queryText: string): any | undefined {
|
|
28
|
+
const key = makeKey(perspectiveUUID, queryText);
|
|
29
|
+
const entry = cache.get(key);
|
|
30
|
+
if (!entry) return undefined;
|
|
31
|
+
if (Date.now() > entry.expiry) {
|
|
32
|
+
cache.delete(key);
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return entry.result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Store a query result in the cache with TTL.
|
|
40
|
+
*/
|
|
41
|
+
export function setCachedResult(perspectiveUUID: string, queryText: string, result: any, ttlMs: number = DEFAULT_TTL_MS): void {
|
|
42
|
+
// Lazy eviction of expired entries
|
|
43
|
+
const now = Date.now();
|
|
44
|
+
for (const [key, entry] of cache) {
|
|
45
|
+
if (now > entry.expiry) {
|
|
46
|
+
cache.delete(key);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const cacheKey = makeKey(perspectiveUUID, queryText);
|
|
51
|
+
cache.set(cacheKey, { result, expiry: now + ttlMs });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Invalidate all cache entries for a given perspective.
|
|
56
|
+
* Called after write operations to ensure stale data isn't served.
|
|
57
|
+
*/
|
|
58
|
+
export function invalidatePerspectiveCache(perspectiveUUID: string): void {
|
|
59
|
+
const prefix = perspectiveUUID + ':';
|
|
60
|
+
for (const [key] of cache) {
|
|
61
|
+
if (key.startsWith(prefix)) {
|
|
62
|
+
cache.delete(key);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Clear all cache entries (useful for testing).
|
|
69
|
+
*/
|
|
70
|
+
export function clearQueryCache(): void {
|
|
71
|
+
cache.clear();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get the current size of the cache (useful for testing).
|
|
76
|
+
*/
|
|
77
|
+
export function queryCacheSize(): number {
|
|
78
|
+
return cache.size;
|
|
79
|
+
}
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { buildSPARQLQuery, buildPaginationSubquery, hasJsOnlyWhereFilters } from './query-sparql';
|
|
2
|
+
|
|
3
|
+
// Minimal stubs for ModelMetadata
|
|
4
|
+
const emptyMetadata: any = { properties: {}, relations: {} };
|
|
5
|
+
|
|
6
|
+
// Metadata with a required (non-literal) property and a literal-stored property
|
|
7
|
+
const richMetadata: any = {
|
|
8
|
+
properties: {
|
|
9
|
+
name: {
|
|
10
|
+
name: 'name',
|
|
11
|
+
predicate: 'flux://name',
|
|
12
|
+
required: true,
|
|
13
|
+
resolveLanguage: 'literal',
|
|
14
|
+
},
|
|
15
|
+
category: {
|
|
16
|
+
name: 'category',
|
|
17
|
+
predicate: 'flux://category',
|
|
18
|
+
required: true,
|
|
19
|
+
resolveLanguage: 'did:lang:abc', // non-literal → URI stored
|
|
20
|
+
},
|
|
21
|
+
description: {
|
|
22
|
+
name: 'description',
|
|
23
|
+
predicate: 'flux://description',
|
|
24
|
+
initial: 'literal://string:empty',
|
|
25
|
+
resolveLanguage: 'literal',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
relations: {},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const emptyRelations: any = {};
|
|
32
|
+
|
|
33
|
+
describe('hasJsOnlyWhereFilters', () => {
|
|
34
|
+
it('returns false when no where clause', () => {
|
|
35
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, undefined)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns false when where has literal-stored property with equality filter (pushed to SPARQL)', () => {
|
|
39
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { name: 'Pasta' })).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('returns true when where has literal-stored property with comparison operator', () => {
|
|
43
|
+
// gt/lt/gte/lte/between/contains remain JS-only
|
|
44
|
+
const meta: any = { properties: { rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' } }, relations: {} };
|
|
45
|
+
expect(hasJsOnlyWhereFilters(meta, emptyRelations, { rating: { gt: 5 } })).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('returns false when where only has non-literal property filter', () => {
|
|
49
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { category: 'some://uri' })).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('returns true when where has author filter', () => {
|
|
53
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { author: 'did:key:abc' })).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('returns true when where has timestamp filter', () => {
|
|
57
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { timestamp: { gt: 100 } })).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('returns true for belongsToOne reverse relation', () => {
|
|
61
|
+
const relMeta: any = { parent: { kind: 'belongsToOne', predicate: 'flux://parent' } };
|
|
62
|
+
const meta: any = { properties: { parent: { name: 'parent', predicate: 'flux://parent' } }, relations: {} };
|
|
63
|
+
expect(hasJsOnlyWhereFilters(meta, relMeta, { parent: 'some://id' })).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
|
|
68
|
+
const modelClass: any = {};
|
|
69
|
+
|
|
70
|
+
it('includes LIMIT/OFFSET in a pagination subquery when query has them and no JS-only filters', () => {
|
|
71
|
+
const query = { limit: 10, offset: 0, where: { category: 'some://uri' } };
|
|
72
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
73
|
+
// SPARQL should contain LIMIT inside the pagination subquery
|
|
74
|
+
expect(sparql).toContain('LIMIT 10');
|
|
75
|
+
// The outer query should still exist
|
|
76
|
+
expect(sparql).toContain('SELECT ?source ?predicate ?target');
|
|
77
|
+
// Should have a subquery pattern
|
|
78
|
+
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('does NOT include LIMIT/OFFSET when JS-only where filters exist', () => {
|
|
82
|
+
// author is a JS-only filter
|
|
83
|
+
const query = { limit: 10, offset: 0, where: { author: 'did:key:abc' } };
|
|
84
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
85
|
+
expect(sparql).not.toContain('LIMIT');
|
|
86
|
+
expect(sparql).not.toContain('OFFSET');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
describe('buildSPARQLQuery — parse_literal push-down filters', () => {
|
|
92
|
+
const modelClass: any = {};
|
|
93
|
+
|
|
94
|
+
it('generates parse_literal FILTER for equality on literal property', () => {
|
|
95
|
+
const query = { where: { name: 'Alice' } };
|
|
96
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
97
|
+
expect(sparql).toContain('<ad4m://fn/parse_literal>');
|
|
98
|
+
expect(sparql).toContain('STR(<ad4m://fn/parse_literal>(?wTarget_name)) = "Alice"');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('generates parse_literal IN FILTER for array on literal property', () => {
|
|
102
|
+
const query = { where: { name: ['Alice', 'Bob'] } };
|
|
103
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
104
|
+
expect(sparql).toContain('STR(<ad4m://fn/parse_literal>(?wTarget_name)) IN ("Alice", "Bob")');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('generates parse_literal NOT FILTER for not condition', () => {
|
|
108
|
+
const query = { where: { name: { not: 'deleted' } } };
|
|
109
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
110
|
+
expect(sparql).toContain('STR(<ad4m://fn/parse_literal>(?wTarget_name)) != "deleted"');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('does NOT use parse_literal for comparison operators (gt/lt)', () => {
|
|
114
|
+
const meta: any = {
|
|
115
|
+
properties: {
|
|
116
|
+
rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' },
|
|
117
|
+
},
|
|
118
|
+
relations: {},
|
|
119
|
+
};
|
|
120
|
+
const query = { where: { rating: { gt: 5 } } };
|
|
121
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
122
|
+
expect(sparql).not.toContain('parse_literal');
|
|
123
|
+
expect(sparql).toContain('?wTarget_cmp_rating');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('does NOT use parse_literal for non-literal properties', () => {
|
|
127
|
+
const query = { where: { category: 'some://uri' } };
|
|
128
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
129
|
+
expect(sparql).not.toContain('parse_literal');
|
|
130
|
+
expect(sparql).toContain('<some://uri>');
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('buildSPARQLQuery — structural correctness', () => {
|
|
135
|
+
const modelClass: any = {};
|
|
136
|
+
|
|
137
|
+
it('generates valid SPARQL with parent filter', () => {
|
|
138
|
+
const query = {
|
|
139
|
+
limit: 50,
|
|
140
|
+
offset: 0,
|
|
141
|
+
parent: { id: 'flux://channel-123', predicate: 'flux://has_message' },
|
|
142
|
+
where: { category: 'some://uri' },
|
|
143
|
+
};
|
|
144
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
145
|
+
expect(sparql).toContain('<flux://channel-123>');
|
|
146
|
+
// SPARQL-level pagination via subquery
|
|
147
|
+
expect(sparql).toContain('LIMIT 50');
|
|
148
|
+
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('rejects injection attempts through where clause IRI values', () => {
|
|
152
|
+
const query = {
|
|
153
|
+
where: { category: 'some://uri"> . } UNION { SELECT * WHERE { ?s ?p ?o' },
|
|
154
|
+
};
|
|
155
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
156
|
+
.toThrow('Invalid IRI component');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('rejects angle brackets in IRI values', () => {
|
|
160
|
+
const query = { where: { category: 'foo<bar>' } };
|
|
161
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
162
|
+
.toThrow('Invalid IRI component');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('rejects curly braces in IRI values', () => {
|
|
166
|
+
const query = { where: { category: 'foo{bar}' } };
|
|
167
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
168
|
+
.toThrow('Invalid IRI component');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('rejects spaces in IRI values', () => {
|
|
172
|
+
const query = { where: { category: 'foo bar' } };
|
|
173
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
174
|
+
.toThrow('Invalid IRI component');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('rejects double quotes in IRI values', () => {
|
|
178
|
+
const query = { where: { category: 'foo"bar' } };
|
|
179
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
180
|
+
.toThrow('Invalid IRI component');
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('allows valid URIs through iri()', () => {
|
|
184
|
+
const query = { where: { category: 'https://example.com/category/food' } };
|
|
185
|
+
expect(() => buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass))
|
|
186
|
+
.not.toThrow();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('buildSPARQLQuery — NOT with array push-down', () => {
|
|
191
|
+
const modelClass: any = {};
|
|
192
|
+
|
|
193
|
+
it('generates NOT IN filter for NOT with array of values', () => {
|
|
194
|
+
const query = { where: { name: { not: ['deleted', 'archived'] } } };
|
|
195
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
196
|
+
// Should use NOT IN with parse_literal for literal properties
|
|
197
|
+
expect(sparql).toContain('NOT IN');
|
|
198
|
+
expect(sparql).toContain('"deleted"');
|
|
199
|
+
expect(sparql).toContain('"archived"');
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('buildSPARQLQuery — mixed push-down + JS-only', () => {
|
|
204
|
+
const modelClass: any = {};
|
|
205
|
+
const mixedMeta: any = {
|
|
206
|
+
properties: {
|
|
207
|
+
name: { name: 'name', predicate: 'flux://name', required: true, resolveLanguage: 'literal' },
|
|
208
|
+
rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' },
|
|
209
|
+
},
|
|
210
|
+
relations: {},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
it('pushes equality to SPARQL but keeps gt as JS-only', () => {
|
|
214
|
+
const query = { where: { name: 'Alice', rating: { gt: 5 } } };
|
|
215
|
+
const sparql = buildSPARQLQuery(mixedMeta, emptyRelations, query, modelClass);
|
|
216
|
+
// name equality should be pushed to SPARQL
|
|
217
|
+
expect(sparql).toContain('parse_literal');
|
|
218
|
+
expect(sparql).toContain('Alice');
|
|
219
|
+
// hasJsOnlyWhereFilters should return true because of rating.gt
|
|
220
|
+
expect(hasJsOnlyWhereFilters(mixedMeta, emptyRelations, query.where)).toBe(true);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe('buildSPARQLQuery — non-literal and flag properties', () => {
|
|
225
|
+
const modelClass: any = {};
|
|
226
|
+
|
|
227
|
+
it('does NOT use parse_literal for non-literal (resolveLanguage) properties', () => {
|
|
228
|
+
const meta: any = {
|
|
229
|
+
properties: {
|
|
230
|
+
avatar: { name: 'avatar', predicate: 'flux://avatar', required: true, resolveLanguage: 'did:lang:some-language' },
|
|
231
|
+
},
|
|
232
|
+
relations: {},
|
|
233
|
+
};
|
|
234
|
+
const query = { where: { avatar: 'https://example.com/pic.jpg' } };
|
|
235
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
236
|
+
expect(sparql).not.toContain('parse_literal');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('does NOT use parse_literal for flag properties', () => {
|
|
240
|
+
const meta: any = {
|
|
241
|
+
properties: {
|
|
242
|
+
isPublic: { name: 'isPublic', predicate: 'flux://isPublic', flag: true, initial: 'flux://true' },
|
|
243
|
+
},
|
|
244
|
+
relations: {},
|
|
245
|
+
};
|
|
246
|
+
const query = { where: { isPublic: 'flux://true' } };
|
|
247
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
248
|
+
expect(sparql).not.toContain('parse_literal');
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
describe('buildSPARQLQuery — IRI correctness', () => {
|
|
253
|
+
const modelClass: any = {};
|
|
254
|
+
|
|
255
|
+
it('uses <ad4m://fn/parse_literal> IRI, not fn::parse_literal SurrealDB syntax', () => {
|
|
256
|
+
const query = { where: { name: 'test' } };
|
|
257
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
258
|
+
expect(sparql).toContain('<ad4m://fn/parse_literal>');
|
|
259
|
+
expect(sparql).not.toContain('fn::parse_literal');
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// ──────────────────────────────────────────────────────────
|
|
264
|
+
// SPARQL-level pagination (LIMIT/OFFSET in generated queries)
|
|
265
|
+
// ──────────────────────────────────────────────────────────
|
|
266
|
+
|
|
267
|
+
describe('SPARQL-level pagination', () => {
|
|
268
|
+
const modelClass: any = {};
|
|
269
|
+
|
|
270
|
+
it('includes LIMIT in SPARQL when query specifies limit', () => {
|
|
271
|
+
const query = { limit: 30 };
|
|
272
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
273
|
+
expect(sparql).toContain('LIMIT 30');
|
|
274
|
+
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('includes OFFSET in SPARQL when query specifies offset > 0', () => {
|
|
278
|
+
const query = { limit: 20, offset: 40 };
|
|
279
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
280
|
+
expect(sparql).toContain('LIMIT 20');
|
|
281
|
+
expect(sparql).toContain('OFFSET 40');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('does NOT include OFFSET when offset is 0', () => {
|
|
285
|
+
const query = { limit: 10, offset: 0 };
|
|
286
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
287
|
+
expect(sparql).toContain('LIMIT 10');
|
|
288
|
+
expect(sparql).not.toContain('OFFSET');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('includes ORDER BY in subquery when query.order is specified', () => {
|
|
292
|
+
const query = { limit: 10, order: { name: 'DESC' as const } };
|
|
293
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
294
|
+
expect(sparql).toContain('ORDER BY DESC(');
|
|
295
|
+
expect(sparql).toContain('LIMIT 10');
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('does NOT default to ORDER BY timestamp when paginating without explicit order', () => {
|
|
299
|
+
const query = { limit: 30 };
|
|
300
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
301
|
+
expect(sparql).not.toContain('ORDER BY');
|
|
302
|
+
expect(sparql).not.toContain('pg_minTs');
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('does NOT push pagination to SPARQL when JS-only where filters exist (author)', () => {
|
|
306
|
+
const query = { limit: 10, where: { author: 'did:key:abc' } };
|
|
307
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
308
|
+
expect(sparql).not.toContain('LIMIT');
|
|
309
|
+
expect(sparql).not.toContain('OFFSET');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('does NOT push pagination to SPARQL when JS-only where filters exist (gt operator)', () => {
|
|
313
|
+
const meta: any = {
|
|
314
|
+
properties: {
|
|
315
|
+
rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' },
|
|
316
|
+
},
|
|
317
|
+
relations: {},
|
|
318
|
+
};
|
|
319
|
+
const query = { limit: 10, where: { rating: { gt: 5 } } };
|
|
320
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
321
|
+
expect(sparql).not.toContain('LIMIT');
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('wraps pagination in a subquery (outer SELECT fetches all links for the page)', () => {
|
|
325
|
+
const query = { limit: 5, offset: 10 };
|
|
326
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
327
|
+
expect(sparql).toContain('SELECT ?source ?predicate ?target ?author ?timestamp');
|
|
328
|
+
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
329
|
+
expect(sparql).toContain('LIMIT 5');
|
|
330
|
+
expect(sparql).toContain('OFFSET 10');
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe('buildSPARQLQuery — set-difference patterns', () => {
|
|
335
|
+
const modelClass: any = {};
|
|
336
|
+
|
|
337
|
+
// Subgroups are grandchildren of channels (channel → conversation → subgroup).
|
|
338
|
+
// Never assume direct child relationships in set-difference queries.
|
|
339
|
+
// A global EXISTS pattern (no parent scoping) should match items regardless of depth.
|
|
340
|
+
it('generates global EXISTS without parent scoping when no parent filter', () => {
|
|
341
|
+
const meta: any = {
|
|
342
|
+
properties: {
|
|
343
|
+
status: { name: 'status', predicate: 'flux://status', required: true, resolveLanguage: 'literal' },
|
|
344
|
+
},
|
|
345
|
+
relations: {},
|
|
346
|
+
};
|
|
347
|
+
const query = { where: { status: 'active' } };
|
|
348
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
349
|
+
// Without a parent filter, the query should not scope to any specific parent
|
|
350
|
+
// This ensures grandchildren (items at any depth) are matched
|
|
351
|
+
expect(sparql).not.toContain('flux://has_child');
|
|
352
|
+
expect(sparql).toContain('SELECT ?source ?predicate ?target');
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
describe('buildSPARQLQuery — RDF 1.2 reifier patterns', () => {
|
|
357
|
+
const modelClass: any = {};
|
|
358
|
+
|
|
359
|
+
it('uses rdf:reifies instead of GRAPH for link metadata', () => {
|
|
360
|
+
const query = { limit: 10 };
|
|
361
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
362
|
+
expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies>');
|
|
363
|
+
expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(');
|
|
364
|
+
expect(sparql).toContain('?_reifier');
|
|
365
|
+
expect(sparql).not.toContain('GRAPH');
|
|
366
|
+
expect(sparql).not.toContain('?linkGraph');
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('binds author and timestamp on the reifier node', () => {
|
|
370
|
+
const query = {};
|
|
371
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
372
|
+
expect(sparql).toContain('?_reifier <ad4m://ontology/author> ?author');
|
|
373
|
+
expect(sparql).toContain('?_reifier <ad4m://ontology/timestamp> ?timestamp');
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
});
|