@coasys/ad4m 0.12.1-dev → 0.13.0-postmessage-ws-proxy.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +8677 -15318
- package/lib/index.js +14507 -21223
- 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 +8 -2
- package/lib/src/index.js +8 -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 +143 -63
- package/lib/src/model/Ad4mModel.js +583 -425
- package/lib/src/model/Ad4mModel.test.js +1434 -688
- package/lib/src/model/ModelQueryBuilder.d.ts +61 -45
- package/lib/src/model/ModelQueryBuilder.js +315 -157
- 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 +154 -57
- 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 +195 -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 +188 -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 +157 -78
- package/lib/src/perspectives/PerspectiveProxy.js +475 -389
- package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveResolver.js +0 -11
- package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
- package/lib/src/perspectives/SparqlBindings.js +65 -0
- 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 +26 -1
- package/lib/src/shacl/SHACLShape.js +140 -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 +9 -24
- 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 +8 -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 +1664 -792
- package/src/model/Ad4mModel.ts +664 -499
- package/src/model/ModelQueryBuilder.ts +362 -183
- 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 +60 -53
- package/src/model/sdna.ts +1 -1
- package/src/model/shacl-gen.ts +163 -64
- package/src/model/shacl-roundtrip.test.ts +197 -0
- package/src/model/types-typed-query.test.ts +360 -0
- package/src/model/types.ts +256 -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 +252 -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/SparqlBindings.ts +79 -0
- 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 +204 -0
- package/src/shacl/SHACLShape.ts +191 -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
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { buildSPARQLOrderLimitOffset, buildSPARQLQuery, hasJsOnlyWhereFilters } from './query-sparql';
|
|
2
|
+
// Minimal stubs for ModelMetadata — buildSPARQLOrderLimitOffset only uses the query arg
|
|
3
|
+
const emptyMetadata = { properties: {}, relations: {} };
|
|
4
|
+
// Metadata with a required (non-literal) property and a literal-stored property
|
|
5
|
+
const richMetadata = {
|
|
6
|
+
properties: {
|
|
7
|
+
name: {
|
|
8
|
+
name: 'name',
|
|
9
|
+
predicate: 'flux://name',
|
|
10
|
+
required: true,
|
|
11
|
+
resolveLanguage: 'literal',
|
|
12
|
+
},
|
|
13
|
+
category: {
|
|
14
|
+
name: 'category',
|
|
15
|
+
predicate: 'flux://category',
|
|
16
|
+
required: true,
|
|
17
|
+
resolveLanguage: 'did:lang:abc', // non-literal → URI stored
|
|
18
|
+
},
|
|
19
|
+
description: {
|
|
20
|
+
name: 'description',
|
|
21
|
+
predicate: 'flux://description',
|
|
22
|
+
initial: 'literal://string:empty',
|
|
23
|
+
resolveLanguage: 'literal',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
relations: {},
|
|
27
|
+
};
|
|
28
|
+
const emptyRelations = {};
|
|
29
|
+
describe('hasJsOnlyWhereFilters', () => {
|
|
30
|
+
it('returns false when no where clause', () => {
|
|
31
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, undefined)).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
it('returns false when where has literal-stored property with equality filter (pushed to SPARQL)', () => {
|
|
34
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { name: 'Pasta' })).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
it('returns true when where has literal-stored property with comparison operator', () => {
|
|
37
|
+
// gt/lt/gte/lte/between/contains remain JS-only
|
|
38
|
+
const meta = { properties: { rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' } }, relations: {} };
|
|
39
|
+
expect(hasJsOnlyWhereFilters(meta, emptyRelations, { rating: { gt: 5 } })).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
it('returns false when where only has non-literal property filter', () => {
|
|
42
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { category: 'some://uri' })).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
it('returns true when where has author filter', () => {
|
|
45
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { author: 'did:key:abc' })).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it('returns true when where has timestamp filter', () => {
|
|
48
|
+
expect(hasJsOnlyWhereFilters(richMetadata, emptyRelations, { timestamp: { gt: 100 } })).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
it('returns true for belongsToOne reverse relation', () => {
|
|
51
|
+
const relMeta = { parent: { kind: 'belongsToOne', predicate: 'flux://parent' } };
|
|
52
|
+
const meta = { properties: { parent: { name: 'parent', predicate: 'flux://parent' } }, relations: {} };
|
|
53
|
+
expect(hasJsOnlyWhereFilters(meta, relMeta, { parent: 'some://id' })).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('buildSPARQLQuery — SPARQL-level pagination via subquery', () => {
|
|
57
|
+
const modelClass = {};
|
|
58
|
+
it('includes LIMIT/OFFSET in a pagination subquery when query has them and no JS-only filters', () => {
|
|
59
|
+
const query = { limit: 10, offset: 0, where: { category: 'some://uri' } };
|
|
60
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
61
|
+
// SPARQL should contain LIMIT inside the pagination subquery
|
|
62
|
+
expect(sparql).toContain('LIMIT 10');
|
|
63
|
+
// The outer query should still exist
|
|
64
|
+
expect(sparql).toContain('SELECT ?source ?predicate ?target');
|
|
65
|
+
// Should have a subquery pattern
|
|
66
|
+
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
67
|
+
});
|
|
68
|
+
it('does NOT include LIMIT/OFFSET when JS-only where filters exist', () => {
|
|
69
|
+
// author is a JS-only filter
|
|
70
|
+
const query = { limit: 10, offset: 0, where: { author: 'did:key:abc' } };
|
|
71
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
72
|
+
expect(sparql).not.toContain('LIMIT');
|
|
73
|
+
expect(sparql).not.toContain('OFFSET');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('buildSPARQLOrderLimitOffset', () => {
|
|
77
|
+
it('always returns empty string (pagination uses subquery pattern instead)', () => {
|
|
78
|
+
expect(buildSPARQLOrderLimitOffset(emptyMetadata, {})).toBe('');
|
|
79
|
+
expect(buildSPARQLOrderLimitOffset(emptyMetadata, { limit: 50 })).toBe('');
|
|
80
|
+
expect(buildSPARQLOrderLimitOffset(emptyMetadata, { limit: 50, offset: 100 })).toBe('');
|
|
81
|
+
expect(buildSPARQLOrderLimitOffset(emptyMetadata, { order: { timestamp: 'DESC' } })).toBe('');
|
|
82
|
+
expect(buildSPARQLOrderLimitOffset(emptyMetadata, {
|
|
83
|
+
order: { timestamp: 'DESC' },
|
|
84
|
+
limit: 50,
|
|
85
|
+
offset: 100,
|
|
86
|
+
})).toBe('');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('buildSPARQLQuery — parse_literal push-down filters', () => {
|
|
90
|
+
const modelClass = {};
|
|
91
|
+
it('generates parse_literal FILTER for equality on literal property', () => {
|
|
92
|
+
const query = { where: { name: 'Alice' } };
|
|
93
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
94
|
+
expect(sparql).toContain('<ad4m://fn/parse_literal>');
|
|
95
|
+
expect(sparql).toContain('STR(<ad4m://fn/parse_literal>(?wTarget_name)) = "Alice"');
|
|
96
|
+
});
|
|
97
|
+
it('generates parse_literal IN FILTER for array on literal property', () => {
|
|
98
|
+
const query = { where: { name: ['Alice', 'Bob'] } };
|
|
99
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
100
|
+
expect(sparql).toContain('STR(<ad4m://fn/parse_literal>(?wTarget_name)) IN ("Alice", "Bob")');
|
|
101
|
+
});
|
|
102
|
+
it('generates parse_literal NOT FILTER for not condition', () => {
|
|
103
|
+
const query = { where: { name: { not: 'deleted' } } };
|
|
104
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
105
|
+
expect(sparql).toContain('STR(<ad4m://fn/parse_literal>(?wTarget_name)) != "deleted"');
|
|
106
|
+
});
|
|
107
|
+
it('does NOT use parse_literal for comparison operators (gt/lt)', () => {
|
|
108
|
+
const meta = {
|
|
109
|
+
properties: {
|
|
110
|
+
rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' },
|
|
111
|
+
},
|
|
112
|
+
relations: {},
|
|
113
|
+
};
|
|
114
|
+
const query = { where: { rating: { gt: 5 } } };
|
|
115
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
116
|
+
expect(sparql).not.toContain('parse_literal');
|
|
117
|
+
expect(sparql).toContain('?wTarget_cmp_rating');
|
|
118
|
+
});
|
|
119
|
+
it('does NOT use parse_literal for non-literal properties', () => {
|
|
120
|
+
const query = { where: { category: 'some://uri' } };
|
|
121
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
122
|
+
expect(sparql).not.toContain('parse_literal');
|
|
123
|
+
expect(sparql).toContain('<some://uri>');
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('buildSPARQLQuery — structural correctness', () => {
|
|
127
|
+
const modelClass = {};
|
|
128
|
+
it('generates valid SPARQL with parent filter', () => {
|
|
129
|
+
const query = {
|
|
130
|
+
limit: 50,
|
|
131
|
+
offset: 0,
|
|
132
|
+
parent: { id: 'flux://channel-123', predicate: 'flux://has_message' },
|
|
133
|
+
where: { category: 'some://uri' },
|
|
134
|
+
};
|
|
135
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
136
|
+
expect(sparql).toContain('<flux://channel-123>');
|
|
137
|
+
// SPARQL-level pagination via subquery
|
|
138
|
+
expect(sparql).toContain('LIMIT 50');
|
|
139
|
+
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
140
|
+
});
|
|
141
|
+
it('does not allow injection through where clause IRI values', () => {
|
|
142
|
+
const query = {
|
|
143
|
+
where: { category: 'some://uri"> . } UNION { SELECT * WHERE { ?s ?p ?o' },
|
|
144
|
+
};
|
|
145
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
146
|
+
// Value should be wrapped in angle brackets as an IRI
|
|
147
|
+
expect(sparql).toContain('<some://uri');
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
describe('buildSPARQLQuery — NOT with array push-down', () => {
|
|
151
|
+
const modelClass = {};
|
|
152
|
+
it('generates NOT IN filter for NOT with array of values', () => {
|
|
153
|
+
const query = { where: { name: { not: ['deleted', 'archived'] } } };
|
|
154
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
155
|
+
// Should use NOT IN with parse_literal for literal properties
|
|
156
|
+
expect(sparql).toContain('NOT IN');
|
|
157
|
+
expect(sparql).toContain('"deleted"');
|
|
158
|
+
expect(sparql).toContain('"archived"');
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe('buildSPARQLQuery — mixed push-down + JS-only', () => {
|
|
162
|
+
const modelClass = {};
|
|
163
|
+
const mixedMeta = {
|
|
164
|
+
properties: {
|
|
165
|
+
name: { name: 'name', predicate: 'flux://name', required: true, resolveLanguage: 'literal' },
|
|
166
|
+
rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' },
|
|
167
|
+
},
|
|
168
|
+
relations: {},
|
|
169
|
+
};
|
|
170
|
+
it('pushes equality to SPARQL but keeps gt as JS-only', () => {
|
|
171
|
+
const query = { where: { name: 'Alice', rating: { gt: 5 } } };
|
|
172
|
+
const sparql = buildSPARQLQuery(mixedMeta, emptyRelations, query, modelClass);
|
|
173
|
+
// name equality should be pushed to SPARQL
|
|
174
|
+
expect(sparql).toContain('parse_literal');
|
|
175
|
+
expect(sparql).toContain('Alice');
|
|
176
|
+
// hasJsOnlyWhereFilters should return true because of rating.gt
|
|
177
|
+
expect(hasJsOnlyWhereFilters(mixedMeta, emptyRelations, query.where)).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
describe('buildSPARQLQuery — non-literal and flag properties', () => {
|
|
181
|
+
const modelClass = {};
|
|
182
|
+
it('does NOT use parse_literal for non-literal (resolveLanguage) properties', () => {
|
|
183
|
+
const meta = {
|
|
184
|
+
properties: {
|
|
185
|
+
avatar: { name: 'avatar', predicate: 'flux://avatar', required: true, resolveLanguage: 'did:lang:some-language' },
|
|
186
|
+
},
|
|
187
|
+
relations: {},
|
|
188
|
+
};
|
|
189
|
+
const query = { where: { avatar: 'https://example.com/pic.jpg' } };
|
|
190
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
191
|
+
expect(sparql).not.toContain('parse_literal');
|
|
192
|
+
});
|
|
193
|
+
it('does NOT use parse_literal for flag properties', () => {
|
|
194
|
+
const meta = {
|
|
195
|
+
properties: {
|
|
196
|
+
isPublic: { name: 'isPublic', predicate: 'flux://isPublic', flag: true, initial: 'flux://true' },
|
|
197
|
+
},
|
|
198
|
+
relations: {},
|
|
199
|
+
};
|
|
200
|
+
const query = { where: { isPublic: 'flux://true' } };
|
|
201
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
202
|
+
expect(sparql).not.toContain('parse_literal');
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
describe('buildSPARQLQuery — IRI correctness', () => {
|
|
206
|
+
const modelClass = {};
|
|
207
|
+
it('uses <ad4m://fn/parse_literal> IRI, not fn::parse_literal SurrealDB syntax', () => {
|
|
208
|
+
const query = { where: { name: 'test' } };
|
|
209
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
210
|
+
expect(sparql).toContain('<ad4m://fn/parse_literal>');
|
|
211
|
+
expect(sparql).not.toContain('fn::parse_literal');
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
// ──────────────────────────────────────────────────────────
|
|
215
|
+
// SPARQL-level pagination (LIMIT/OFFSET in generated queries)
|
|
216
|
+
// ──────────────────────────────────────────────────────────
|
|
217
|
+
describe('SPARQL-level pagination', () => {
|
|
218
|
+
const modelClass = {};
|
|
219
|
+
it('includes LIMIT in SPARQL when query specifies limit', () => {
|
|
220
|
+
const query = { limit: 30 };
|
|
221
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
222
|
+
expect(sparql).toContain('LIMIT 30');
|
|
223
|
+
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
224
|
+
});
|
|
225
|
+
it('includes OFFSET in SPARQL when query specifies offset > 0', () => {
|
|
226
|
+
const query = { limit: 20, offset: 40 };
|
|
227
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
228
|
+
expect(sparql).toContain('LIMIT 20');
|
|
229
|
+
expect(sparql).toContain('OFFSET 40');
|
|
230
|
+
});
|
|
231
|
+
it('does NOT include OFFSET when offset is 0', () => {
|
|
232
|
+
const query = { limit: 10, offset: 0 };
|
|
233
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
234
|
+
expect(sparql).toContain('LIMIT 10');
|
|
235
|
+
expect(sparql).not.toContain('OFFSET');
|
|
236
|
+
});
|
|
237
|
+
it('includes ORDER BY in subquery when query.order is specified', () => {
|
|
238
|
+
const query = { limit: 10, order: { name: 'DESC' } };
|
|
239
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
240
|
+
expect(sparql).toContain('ORDER BY DESC(');
|
|
241
|
+
expect(sparql).toContain('LIMIT 10');
|
|
242
|
+
});
|
|
243
|
+
it('does NOT default to ORDER BY timestamp when paginating without explicit order', () => {
|
|
244
|
+
const query = { limit: 30 };
|
|
245
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
246
|
+
expect(sparql).not.toContain('ORDER BY');
|
|
247
|
+
expect(sparql).not.toContain('pg_minTs');
|
|
248
|
+
});
|
|
249
|
+
it('does NOT push pagination to SPARQL when JS-only where filters exist (author)', () => {
|
|
250
|
+
const query = { limit: 10, where: { author: 'did:key:abc' } };
|
|
251
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
252
|
+
expect(sparql).not.toContain('LIMIT');
|
|
253
|
+
expect(sparql).not.toContain('OFFSET');
|
|
254
|
+
});
|
|
255
|
+
it('does NOT push pagination to SPARQL when JS-only where filters exist (gt operator)', () => {
|
|
256
|
+
const meta = {
|
|
257
|
+
properties: {
|
|
258
|
+
rating: { name: 'rating', predicate: 'flux://rating', required: true, resolveLanguage: 'literal' },
|
|
259
|
+
},
|
|
260
|
+
relations: {},
|
|
261
|
+
};
|
|
262
|
+
const query = { limit: 10, where: { rating: { gt: 5 } } };
|
|
263
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
264
|
+
expect(sparql).not.toContain('LIMIT');
|
|
265
|
+
});
|
|
266
|
+
it('wraps pagination in a subquery (outer SELECT fetches all links for the page)', () => {
|
|
267
|
+
const query = { limit: 5, offset: 10 };
|
|
268
|
+
const sparql = buildSPARQLQuery(emptyMetadata, emptyRelations, query, modelClass);
|
|
269
|
+
expect(sparql).toContain('SELECT ?source ?predicate ?target ?author ?timestamp');
|
|
270
|
+
expect(sparql).toContain('SELECT DISTINCT ?source');
|
|
271
|
+
expect(sparql).toContain('LIMIT 5');
|
|
272
|
+
expect(sparql).toContain('OFFSET 10');
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
describe('buildSPARQLQuery — set-difference patterns', () => {
|
|
276
|
+
const modelClass = {};
|
|
277
|
+
// Subgroups are grandchildren of channels (channel → conversation → subgroup).
|
|
278
|
+
// Never assume direct child relationships in set-difference queries.
|
|
279
|
+
// A global EXISTS pattern (no parent scoping) should match items regardless of depth.
|
|
280
|
+
it('generates global EXISTS without parent scoping when no parent filter', () => {
|
|
281
|
+
const meta = {
|
|
282
|
+
properties: {
|
|
283
|
+
status: { name: 'status', predicate: 'flux://status', required: true, resolveLanguage: 'literal' },
|
|
284
|
+
},
|
|
285
|
+
relations: {},
|
|
286
|
+
};
|
|
287
|
+
const query = { where: { status: 'active' } };
|
|
288
|
+
const sparql = buildSPARQLQuery(meta, emptyRelations, query, modelClass);
|
|
289
|
+
// Without a parent filter, the query should not scope to any specific parent
|
|
290
|
+
// This ensures grandchildren (items at any depth) are matched
|
|
291
|
+
expect(sparql).not.toContain('flux://has_child');
|
|
292
|
+
expect(sparql).toContain('SELECT ?source ?predicate ?target');
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
describe('buildSPARQLQuery — RDF 1.2 reifier patterns', () => {
|
|
296
|
+
const modelClass = {};
|
|
297
|
+
it('uses rdf:reifies instead of GRAPH for link metadata', () => {
|
|
298
|
+
const query = { limit: 10 };
|
|
299
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
300
|
+
expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies>');
|
|
301
|
+
expect(sparql).toContain('<http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<(');
|
|
302
|
+
expect(sparql).toContain('?_reifier');
|
|
303
|
+
expect(sparql).not.toContain('GRAPH');
|
|
304
|
+
expect(sparql).not.toContain('?linkGraph');
|
|
305
|
+
});
|
|
306
|
+
it('binds author and timestamp on the reifier node', () => {
|
|
307
|
+
const query = {};
|
|
308
|
+
const sparql = buildSPARQLQuery(richMetadata, emptyRelations, query, modelClass);
|
|
309
|
+
expect(sparql).toContain('?_reifier <ad4m://ontology/author> ?author');
|
|
310
|
+
expect(sparql).toContain('?_reifier <ad4m://ontology/timestamp> ?timestamp');
|
|
311
|
+
});
|
|
312
|
+
});
|
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared
|
|
2
|
+
* Shared query compilation utilities.
|
|
3
3
|
*
|
|
4
4
|
* These functions are used by both the runtime query builder (`Ad4mModel`) and
|
|
5
5
|
* the compile-time SHACL generator (`decorators.ts`).
|
|
6
|
+
*
|
|
7
|
+
* All output uses native SPARQL syntax.
|
|
6
8
|
*/
|
|
7
9
|
import type { WhereCondition, Where, ModelMetadata } from "./types";
|
|
8
10
|
/**
|
|
9
|
-
* Format a JavaScript value for embedding in a
|
|
11
|
+
* Format a JavaScript value for embedding in a query expression.
|
|
10
12
|
*
|
|
11
13
|
* - Strings are single-quoted with backslash / quote / newline escaping
|
|
12
14
|
* - Numbers and booleans are passed through as-is
|
|
13
15
|
* - Arrays are recursed
|
|
14
16
|
*/
|
|
15
|
-
export declare function
|
|
17
|
+
export declare function formatQueryValue(value: any): string;
|
|
16
18
|
/**
|
|
17
|
-
* Compile a single Where condition for a property into a
|
|
18
|
-
*
|
|
19
|
+
* Compile a single Where condition for a property into a SPARQL triple pattern
|
|
20
|
+
* that can be embedded in a getter's WHERE clause.
|
|
19
21
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
+
* The generated pattern operates on `?target` — e.g.:
|
|
23
|
+
* `?target <pred> <value> .`
|
|
24
|
+
* `FILTER EXISTS { ?target <pred> ?_v0 }`
|
|
22
25
|
*
|
|
23
26
|
* @param predicate - The predicate URI for the property
|
|
24
27
|
* @param condition - The Where condition value
|
|
25
28
|
* @param opts - Optional settings (e.g. `resolveLanguage`)
|
|
26
|
-
* @returns A single
|
|
29
|
+
* @returns A single SPARQL condition string
|
|
27
30
|
*/
|
|
28
31
|
export declare function buildWhereCondition(predicate: string, condition: WhereCondition, opts?: {
|
|
29
32
|
resolveLanguage?: string;
|
|
33
|
+
varIndex?: number;
|
|
30
34
|
}): string;
|
|
31
35
|
/**
|
|
32
|
-
* Compile a full `Where` clause to an array of
|
|
36
|
+
* Compile a full `Where` clause to an array of SPARQL condition strings.
|
|
33
37
|
*
|
|
34
38
|
* When `metadata` is provided, property names are resolved to predicates
|
|
35
39
|
* using the model's property metadata. When `metadata` is `null`, property
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared query compilation utilities.
|
|
3
|
+
*
|
|
4
|
+
* These functions are used by both the runtime query builder (`Ad4mModel`) and
|
|
5
|
+
* the compile-time SHACL generator (`decorators.ts`).
|
|
6
|
+
*
|
|
7
|
+
* All output uses native SPARQL syntax.
|
|
8
|
+
*/
|
|
9
|
+
import { escapeQueryString } from "../utils";
|
|
10
|
+
/**
|
|
11
|
+
* Format a JavaScript value for embedding in a query expression.
|
|
12
|
+
*
|
|
13
|
+
* - Strings are single-quoted with backslash / quote / newline escaping
|
|
14
|
+
* - Numbers and booleans are passed through as-is
|
|
15
|
+
* - Arrays are recursed
|
|
16
|
+
*/
|
|
17
|
+
export function formatQueryValue(value) {
|
|
18
|
+
if (typeof value === 'string') {
|
|
19
|
+
// Escape backslashes first, then single quotes and other special characters
|
|
20
|
+
const escaped = value
|
|
21
|
+
.replace(/\\/g, '\\\\') // Backslash -> \\
|
|
22
|
+
.replace(/'/g, "\\'") // Single quote -> \'
|
|
23
|
+
.replace(/"/g, '\\"') // Double quote -> \"
|
|
24
|
+
.replace(/\n/g, '\\n') // Newline -> \n
|
|
25
|
+
.replace(/\r/g, '\\r') // Carriage return -> \r
|
|
26
|
+
.replace(/\t/g, '\\t'); // Tab -> \t
|
|
27
|
+
return `'${escaped}'`;
|
|
28
|
+
}
|
|
29
|
+
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
30
|
+
return String(value);
|
|
31
|
+
}
|
|
32
|
+
else if (Array.isArray(value)) {
|
|
33
|
+
return `[${value.map(v => formatQueryValue(v)).join(', ')}]`;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return String(value);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Compile a single Where condition for a property into a SPARQL triple pattern
|
|
41
|
+
* that can be embedded in a getter's WHERE clause.
|
|
42
|
+
*
|
|
43
|
+
* The generated pattern operates on `?target` — e.g.:
|
|
44
|
+
* `?target <pred> <value> .`
|
|
45
|
+
* `FILTER EXISTS { ?target <pred> ?_v0 }`
|
|
46
|
+
*
|
|
47
|
+
* @param predicate - The predicate URI for the property
|
|
48
|
+
* @param condition - The Where condition value
|
|
49
|
+
* @param opts - Optional settings (e.g. `resolveLanguage`)
|
|
50
|
+
* @returns A single SPARQL condition string
|
|
51
|
+
*/
|
|
52
|
+
export function buildWhereCondition(predicate, condition, opts) {
|
|
53
|
+
const escapedPredicate = escapeQueryString(predicate);
|
|
54
|
+
// For literal-resolved properties, we match against the raw IRI (which is a literal: URI)
|
|
55
|
+
// For language-resolved properties, we match against the plain URI
|
|
56
|
+
// For literal-resolved properties, values are stored as IRIs like <literal:string:VALUE>
|
|
57
|
+
// For language-resolved properties, values are plain URIs
|
|
58
|
+
const isLiteral = !opts?.resolveLanguage || opts.resolveLanguage === 'literal';
|
|
59
|
+
const varSuffix = opts?.varIndex ?? 0;
|
|
60
|
+
function formatValue(v) {
|
|
61
|
+
if (typeof v === 'string') {
|
|
62
|
+
return isLiteral
|
|
63
|
+
? `<literal:string:${escapeQueryString(v)}>`
|
|
64
|
+
: `<${escapeQueryString(v)}>`;
|
|
65
|
+
}
|
|
66
|
+
// Numbers/booleans — also stored as literal:string: in AD4M
|
|
67
|
+
return `<literal:string:${v}>`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* For literal properties, generate a FILTER-based match that handles both
|
|
71
|
+
* the raw value and the literal-encoded value. This mirrors the Rust
|
|
72
|
+
* `build_projection_where_patterns` approach which uses:
|
|
73
|
+
* FILTER(STR(?var) = "value" || STR(?var) = "literal:string:encodedValue")
|
|
74
|
+
* This is more robust than exact IRI matching because it handles edge cases
|
|
75
|
+
* where the stored format might vary.
|
|
76
|
+
*/
|
|
77
|
+
function formatLiteralFilter(varName, v) {
|
|
78
|
+
const raw = escapeQueryString(String(v));
|
|
79
|
+
const encoded = encodeURIComponent(String(v))
|
|
80
|
+
.replace(/!/g, '%21')
|
|
81
|
+
.replace(/'/g, '%27')
|
|
82
|
+
.replace(/\(/g, '%28')
|
|
83
|
+
.replace(/\)/g, '%29')
|
|
84
|
+
.replace(/\*/g, '%2A');
|
|
85
|
+
if (typeof v === 'string') {
|
|
86
|
+
return `FILTER(STR(${varName}) = "${raw}" || STR(${varName}) = "literal:string:${encoded}")`;
|
|
87
|
+
}
|
|
88
|
+
else if (typeof v === 'number') {
|
|
89
|
+
return `FILTER(STR(${varName}) = "${v}" || STR(${varName}) = "literal:number:${v}")`;
|
|
90
|
+
}
|
|
91
|
+
else if (typeof v === 'boolean') {
|
|
92
|
+
return `FILTER(STR(${varName}) = "${v}" || STR(${varName}) = "literal:boolean:${v}")`;
|
|
93
|
+
}
|
|
94
|
+
return `FILTER(STR(${varName}) = "${raw}")`;
|
|
95
|
+
}
|
|
96
|
+
if (Array.isArray(condition)) {
|
|
97
|
+
// Array values → FILTER IN
|
|
98
|
+
if (isLiteral) {
|
|
99
|
+
const varName = `?_wc${varSuffix}`;
|
|
100
|
+
const inValues = condition.flatMap(v => {
|
|
101
|
+
const raw = escapeQueryString(String(v));
|
|
102
|
+
const encoded = encodeURIComponent(String(v))
|
|
103
|
+
.replace(/!/g, '%21').replace(/'/g, '%27')
|
|
104
|
+
.replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');
|
|
105
|
+
return [`"${raw}"`, `"literal:string:${encoded}"`];
|
|
106
|
+
}).join(', ');
|
|
107
|
+
return `?target <${escapedPredicate}> ${varName} . FILTER(STR(${varName}) IN (${inValues}))`;
|
|
108
|
+
}
|
|
109
|
+
const formattedValues = condition.map(formatValue).join(', ');
|
|
110
|
+
return `FILTER EXISTS { ?target <${escapedPredicate}> ?_val . FILTER(?_val IN (${formattedValues})) }`;
|
|
111
|
+
}
|
|
112
|
+
else if (typeof condition === 'object' && condition !== null) {
|
|
113
|
+
// Operator object
|
|
114
|
+
const ops = condition;
|
|
115
|
+
const parts = [];
|
|
116
|
+
if (ops.not !== undefined) {
|
|
117
|
+
if (Array.isArray(ops.not)) {
|
|
118
|
+
const formattedValues = ops.not.map((v) => formatValue(v)).join(', ');
|
|
119
|
+
// FILTER NOT EXISTS here is scoped to a specific predicate, not a global scan,
|
|
120
|
+
// so O(N²) behavior is bounded by the number of values for this property.
|
|
121
|
+
parts.push(`FILTER NOT EXISTS { ?target <${escapedPredicate}> ?_nval . FILTER(?_nval IN (${formattedValues})) }`);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// FILTER NOT EXISTS here is scoped to a specific predicate, not a global scan,
|
|
125
|
+
// so O(N²) behavior is bounded by the number of values for this property.
|
|
126
|
+
parts.push(`FILTER NOT EXISTS { ?target <${escapedPredicate}> ${formatValue(ops.not)} }`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Comparison operators — ensure property exists
|
|
130
|
+
const hasComparisonOps = ops.gt !== undefined || ops.gte !== undefined ||
|
|
131
|
+
ops.lt !== undefined || ops.lte !== undefined ||
|
|
132
|
+
ops.between !== undefined || ops.contains !== undefined;
|
|
133
|
+
if (hasComparisonOps) {
|
|
134
|
+
parts.push(`FILTER EXISTS { ?target <${escapedPredicate}> ?_cmp }`);
|
|
135
|
+
}
|
|
136
|
+
return parts.join(' ');
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// Simple equality
|
|
140
|
+
if (isLiteral) {
|
|
141
|
+
// Use FILTER matching (mirrors Rust build_projection_where_patterns)
|
|
142
|
+
// to handle both raw values and literal-encoded IRIs robustly.
|
|
143
|
+
const varName = `?_wc${varSuffix}`;
|
|
144
|
+
return `?target <${escapedPredicate}> ${varName} . ${formatLiteralFilter(varName, condition)}`;
|
|
145
|
+
}
|
|
146
|
+
return `?target <${escapedPredicate}> ${formatValue(condition)} .`;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Compile a full `Where` clause to an array of SPARQL condition strings.
|
|
151
|
+
*
|
|
152
|
+
* When `metadata` is provided, property names are resolved to predicates
|
|
153
|
+
* using the model's property metadata. When `metadata` is `null`, property
|
|
154
|
+
* names are treated as raw predicate URIs.
|
|
155
|
+
*
|
|
156
|
+
* Only handles **regular properties** — special fields (`id`, `author`,
|
|
157
|
+
* `timestamp`) and relation fields are skipped (they are only relevant at
|
|
158
|
+
* runtime query time, not for compile-time getter generation).
|
|
159
|
+
*/
|
|
160
|
+
export function compileWhereClause(where, metadata) {
|
|
161
|
+
const conditions = [];
|
|
162
|
+
for (const [propertyName, condition] of Object.entries(where)) {
|
|
163
|
+
// Skip special fields that don't apply at compile time
|
|
164
|
+
if (['id', 'author', 'timestamp'].includes(propertyName))
|
|
165
|
+
continue;
|
|
166
|
+
let predicate;
|
|
167
|
+
let resolveLanguage;
|
|
168
|
+
if (metadata) {
|
|
169
|
+
const propMeta = metadata.properties[propertyName];
|
|
170
|
+
if (propMeta) {
|
|
171
|
+
predicate = propMeta.predicate;
|
|
172
|
+
resolveLanguage = propMeta.resolveLanguage;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// Property not found in metadata — treat name as raw predicate URI
|
|
176
|
+
predicate = propertyName;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
// No metadata — treat name as raw predicate URI
|
|
181
|
+
predicate = propertyName;
|
|
182
|
+
}
|
|
183
|
+
const cond = buildWhereCondition(predicate, condition, { resolveLanguage, varIndex: conditions.length });
|
|
184
|
+
if (cond) {
|
|
185
|
+
conditions.push(cond);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return conditions;
|
|
189
|
+
}
|