@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
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPARQL query building utilities for Ad4mModel.
|
|
3
|
+
*
|
|
4
|
+
* Uses the RDF 1.2 reifier storage model where each AD4M link is stored as:
|
|
5
|
+
* 1. Direct triple: <source> <predicate> <target> . (default graph)
|
|
6
|
+
* 2. Reifier: <link:HASH> <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<( source predicate target )>> .
|
|
7
|
+
* 3. Metadata: <link:HASH> ad4m://ontology/* "value" . (default graph)
|
|
8
|
+
*
|
|
9
|
+
* All AD4M URIs (source, predicate, target) become RDF IRIs.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { Literal } from "../Literal";
|
|
15
|
+
import { resolveParentPredicate } from "./query-common";
|
|
16
|
+
import type { RelationMetadataEntry } from "./decorators";
|
|
17
|
+
import type { Where, Query, ModelMetadata, PropertyMetadata } from "./types";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Check whether a `where` clause contains filters that cannot be pushed down
|
|
21
|
+
* to SPARQL and must be evaluated in JS after hydration.
|
|
22
|
+
*
|
|
23
|
+
* JS-only filters include:
|
|
24
|
+
* - Literal-stored properties (equality, comparison, contains, etc.)
|
|
25
|
+
* - Reverse relations (belongsToOne / belongsToMany)
|
|
26
|
+
* - author / timestamp filters (skipped by buildSPARQLWhereFilters)
|
|
27
|
+
*
|
|
28
|
+
* When JS-only filters exist, SPARQL-level LIMIT/OFFSET must NOT be applied
|
|
29
|
+
* because the database would cap the candidate set before JS filters run,
|
|
30
|
+
* potentially discarding matches beyond the LIMIT.
|
|
31
|
+
*/
|
|
32
|
+
export function hasJsOnlyWhereFilters(
|
|
33
|
+
metadata: ModelMetadata,
|
|
34
|
+
allRelationsMetadata: Record<string, RelationMetadataEntry>,
|
|
35
|
+
where?: Where,
|
|
36
|
+
): boolean {
|
|
37
|
+
if (!where) return false;
|
|
38
|
+
|
|
39
|
+
for (const [propertyName, condition] of Object.entries(where)) {
|
|
40
|
+
if (propertyName === "base" || propertyName === "id") continue;
|
|
41
|
+
|
|
42
|
+
// author/timestamp filters are handled in JS
|
|
43
|
+
if (propertyName === "author" || propertyName === "timestamp") return true;
|
|
44
|
+
|
|
45
|
+
const propMeta = metadata.properties[propertyName];
|
|
46
|
+
if (!propMeta) continue;
|
|
47
|
+
|
|
48
|
+
// Reverse relations are JS-only
|
|
49
|
+
const relMeta = allRelationsMetadata[propertyName];
|
|
50
|
+
if (relMeta && (relMeta.kind === 'belongsToOne' || relMeta.kind === 'belongsToMany')) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Literal-stored properties: equality/IN/NOT can be pushed to SPARQL via
|
|
55
|
+
// <ad4m://fn/parse_literal>(), but comparison operators (gt/lt/gte/lte/between/contains)
|
|
56
|
+
// must remain JS-only because parse_literal returns strings.
|
|
57
|
+
if (isLiteralStoredProperty(propMeta)) {
|
|
58
|
+
if (typeof condition === 'object' && condition !== null && !Array.isArray(condition)) {
|
|
59
|
+
const ops = condition as any;
|
|
60
|
+
const hasCompOps = ops.gt !== undefined || ops.gte !== undefined ||
|
|
61
|
+
ops.lt !== undefined || ops.lte !== undefined ||
|
|
62
|
+
ops.between !== undefined || ops.contains !== undefined;
|
|
63
|
+
if (hasCompOps) return true;
|
|
64
|
+
// NOT with simple value can be pushed to SPARQL — not JS-only
|
|
65
|
+
}
|
|
66
|
+
// Simple equality and IN filters can be pushed to SPARQL — not JS-only
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Check if a string value looks like a URI (has a scheme).
|
|
75
|
+
*/
|
|
76
|
+
function looksLikeUri(value: string): boolean {
|
|
77
|
+
return /^[a-zA-Z][a-zA-Z0-9+\-._]*:/.test(value);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Convert a JS value to its literal: IRI form, matching how the Rust executor
|
|
82
|
+
* stores property values that don't have a resolveLanguage set.
|
|
83
|
+
* Strings that already look like URIs are returned as-is.
|
|
84
|
+
*/
|
|
85
|
+
function valueToLiteralIri(value: any): string {
|
|
86
|
+
if (typeof value === 'string') {
|
|
87
|
+
if (looksLikeUri(value)) return value;
|
|
88
|
+
return Literal.from(value).toUrl();
|
|
89
|
+
}
|
|
90
|
+
if (typeof value === 'number') {
|
|
91
|
+
return Literal.from(value).toUrl();
|
|
92
|
+
}
|
|
93
|
+
if (typeof value === 'boolean') {
|
|
94
|
+
return Literal.from(value).toUrl();
|
|
95
|
+
}
|
|
96
|
+
return Literal.from(String(value)).toUrl();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Determine if a property stores values as literal: IRIs (needs parse_literal for comparisons).
|
|
101
|
+
* Properties with resolveLanguage === "literal" AND properties without resolveLanguage
|
|
102
|
+
* both store values as literal: URIs. Only properties with a non-literal resolveLanguage
|
|
103
|
+
* (e.g. file storage) or flag properties store raw URIs.
|
|
104
|
+
*/
|
|
105
|
+
function isLiteralStoredProperty(propMeta: PropertyMetadata): boolean {
|
|
106
|
+
if (propMeta.flag) return false;
|
|
107
|
+
// If resolveLanguage is set to something other than "literal", it's a language expression URI
|
|
108
|
+
if (propMeta.resolveLanguage && propMeta.resolveLanguage !== "literal") return false;
|
|
109
|
+
// Everything else (resolveLanguage === "literal" or undefined) stores as literal: URIs
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Escape a string for use as a SPARQL string literal.
|
|
115
|
+
*/
|
|
116
|
+
function escapeSPARQL(value: string): string {
|
|
117
|
+
return value
|
|
118
|
+
.replace(/\\/g, "\\\\")
|
|
119
|
+
.replace(/"/g, '\\"')
|
|
120
|
+
.replace(/\n/g, "\\n")
|
|
121
|
+
.replace(/\r/g, "\\r")
|
|
122
|
+
.replace(/\t/g, "\\t")
|
|
123
|
+
.replace(/\0/g, "")
|
|
124
|
+
.replace(/\f/g, "\\u000C");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Format a value as a SPARQL string literal (double-quoted).
|
|
129
|
+
*/
|
|
130
|
+
export function formatSPARQLValue(value: any): string {
|
|
131
|
+
if (typeof value === "string") {
|
|
132
|
+
return `"${escapeSPARQL(value)}"`;
|
|
133
|
+
}
|
|
134
|
+
return `"${String(value)}"`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Format an AD4M URI as an RDF IRI for use in SPARQL triple patterns.
|
|
139
|
+
* All AD4M link source/predicate/target values become IRIs in angle brackets.
|
|
140
|
+
* The Rust SPARQL service transparently transforms these to valid IRI format.
|
|
141
|
+
*
|
|
142
|
+
* Rejects characters that would break or inject into a SPARQL IRI token,
|
|
143
|
+
* matching the Rust-side `validate_iri()` function.
|
|
144
|
+
*/
|
|
145
|
+
function iri(value: string): string {
|
|
146
|
+
if (/[<>{}" ]/.test(value)) {
|
|
147
|
+
throw new Error(`Invalid IRI component: '${value}'`);
|
|
148
|
+
}
|
|
149
|
+
return `<${value}>`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Map a user-facing property name to the SPARQL variable alias used in the query.
|
|
154
|
+
*
|
|
155
|
+
* Properties appear in the query as:
|
|
156
|
+
* - Required properties: `?cfTarget_${name}`
|
|
157
|
+
* - Where-clause joins: `?wTarget_${name}`
|
|
158
|
+
* - Initial-value fallback: `?cfInitTarget_${name}`
|
|
159
|
+
*
|
|
160
|
+
* For ORDER BY, we prefer the conformance variable (always present for required props),
|
|
161
|
+
* then the where-target variable.
|
|
162
|
+
*/
|
|
163
|
+
function mapPropertyToSPARQLVar(propertyName: string, metadata: ModelMetadata): string {
|
|
164
|
+
const propMeta = metadata.properties[propertyName];
|
|
165
|
+
if (propMeta) {
|
|
166
|
+
if (propMeta.required && !propMeta.getter && !(propMeta.flag && propMeta.initial)) {
|
|
167
|
+
return `?cfTarget_${propertyName}`;
|
|
168
|
+
}
|
|
169
|
+
if (propMeta.initial && !propMeta.flag) {
|
|
170
|
+
return `?cfInitTarget_${propertyName}`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Fallback: where-clause variable or raw name
|
|
174
|
+
return `?wTarget_${propertyName}`;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Build a SPARQL query that returns all links belonging to instances of
|
|
179
|
+
* the given model class, optionally filtered by `where` conditions.
|
|
180
|
+
*
|
|
181
|
+
* Uses direct triple patterns: ?source ?predicate ?target
|
|
182
|
+
* with named graph storage and metadata keyed by graph IRI.
|
|
183
|
+
*/
|
|
184
|
+
export function buildSPARQLQuery(
|
|
185
|
+
metadata: ModelMetadata,
|
|
186
|
+
allRelationsMetadata: Record<string, RelationMetadataEntry>,
|
|
187
|
+
query: Query,
|
|
188
|
+
modelClass: any,
|
|
189
|
+
): string {
|
|
190
|
+
const joinPatterns: string[] = [];
|
|
191
|
+
const filterExpressions: string[] = [];
|
|
192
|
+
|
|
193
|
+
// Parent filter — direct triple pattern
|
|
194
|
+
if (query.parent) {
|
|
195
|
+
const parentPredicate = resolveParentPredicate(query.parent, modelClass);
|
|
196
|
+
joinPatterns.push(`
|
|
197
|
+
${iri(query.parent.id)} ${iri(parentPredicate)} ?source .`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Required property JOIN patterns — direct triple patterns
|
|
201
|
+
let hasConformance = false;
|
|
202
|
+
for (const [, propMeta] of Object.entries(metadata.properties)) {
|
|
203
|
+
if (propMeta.required) {
|
|
204
|
+
if (propMeta.getter) continue;
|
|
205
|
+
hasConformance = true;
|
|
206
|
+
if (propMeta.flag && propMeta.initial) {
|
|
207
|
+
joinPatterns.push(`
|
|
208
|
+
?source ${iri(propMeta.predicate)} ${iri(propMeta.initial)} .`);
|
|
209
|
+
} else {
|
|
210
|
+
joinPatterns.push(`
|
|
211
|
+
?source ${iri(propMeta.predicate)} ?cfTarget_${propMeta.name} .`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Fallback: initial-value JOIN patterns
|
|
217
|
+
if (!hasConformance) {
|
|
218
|
+
for (const [, propMeta] of Object.entries(metadata.properties)) {
|
|
219
|
+
if (propMeta.initial) {
|
|
220
|
+
hasConformance = true;
|
|
221
|
+
if (propMeta.flag) {
|
|
222
|
+
joinPatterns.push(`
|
|
223
|
+
?source ${iri(propMeta.predicate)} ${iri(propMeta.initial)} .`);
|
|
224
|
+
} else {
|
|
225
|
+
joinPatterns.push(`
|
|
226
|
+
?source ${iri(propMeta.predicate)} ?cfInitTarget_${propMeta.name} .`);
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Fallback: open-world structural matching
|
|
234
|
+
// Use a subquery with DISTINCT to avoid row multiplication when the main
|
|
235
|
+
// ?source ?predicate ?target pattern cross-joins with multiple structural matches.
|
|
236
|
+
if (!hasConformance && joinPatterns.length === 0) {
|
|
237
|
+
const knownPredicates: string[] = [];
|
|
238
|
+
for (const [, propMeta] of Object.entries(metadata.properties)) {
|
|
239
|
+
if (propMeta.predicate) {
|
|
240
|
+
knownPredicates.push(iri(propMeta.predicate));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (metadata.relations) {
|
|
244
|
+
for (const [, relMeta] of Object.entries(metadata.relations)) {
|
|
245
|
+
if (relMeta.predicate) {
|
|
246
|
+
knownPredicates.push(iri(relMeta.predicate));
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (knownPredicates.length > 0) {
|
|
251
|
+
joinPatterns.push(`
|
|
252
|
+
{ SELECT DISTINCT ?source WHERE { ?source ?cf_structPred ?cf_structTarget . FILTER(?cf_structPred IN (${knownPredicates.join(", ")})) } }`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Build WHERE clause filters from user query
|
|
257
|
+
const { joins: userJoins, filters: userFilters } = buildSPARQLWhereFilters(metadata, allRelationsMetadata, query.where);
|
|
258
|
+
joinPatterns.push(...userJoins);
|
|
259
|
+
filterExpressions.push(...userFilters);
|
|
260
|
+
|
|
261
|
+
// Main triple pattern — fetches all links for matched sources
|
|
262
|
+
// Direct triple in default graph + RDF 1.2 reifier for link metadata
|
|
263
|
+
// FILTER(isIRI(?source)) excludes non-IRI subjects
|
|
264
|
+
const joinClause = joinPatterns.join("\n");
|
|
265
|
+
const filterClause = filterExpressions.length > 0
|
|
266
|
+
? `FILTER(\n ${filterExpressions.join(" &&\n ")}\n )`
|
|
267
|
+
: "";
|
|
268
|
+
|
|
269
|
+
// Determine if SPARQL-level pagination is safe.
|
|
270
|
+
// When JS-only where filters exist, we must NOT limit at the SPARQL level
|
|
271
|
+
// because the database would cap candidates before JS filters run.
|
|
272
|
+
const canPaginateInSPARQL = !hasJsOnlyWhereFilters(metadata, allRelationsMetadata, query.where)
|
|
273
|
+
&& (query.limit !== undefined || query.offset !== undefined);
|
|
274
|
+
|
|
275
|
+
// Build a pagination subquery that constrains ?source to only the page
|
|
276
|
+
// of interest. This avoids fetching all links for all matching instances.
|
|
277
|
+
const paginationSubquery = canPaginateInSPARQL
|
|
278
|
+
? buildPaginationSubquery(joinPatterns, filterExpressions, metadata, query)
|
|
279
|
+
: '';
|
|
280
|
+
|
|
281
|
+
if (paginationSubquery) {
|
|
282
|
+
// Use the pagination subquery to constrain ?source, then fetch all links
|
|
283
|
+
// for those sources only.
|
|
284
|
+
return `
|
|
285
|
+
|
|
286
|
+
SELECT ?source ?predicate ?target ?author ?timestamp WHERE {
|
|
287
|
+
${paginationSubquery}${joinClause}
|
|
288
|
+
?source ?predicate ?target .
|
|
289
|
+
?_reifier <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<( ?source ?predicate ?target )>> .
|
|
290
|
+
FILTER(isIRI(?source) && isIRI(?predicate))
|
|
291
|
+
?_reifier <ad4m://ontology/author> ?author .
|
|
292
|
+
?_reifier <ad4m://ontology/timestamp> ?timestamp .
|
|
293
|
+
${filterClause}
|
|
294
|
+
}
|
|
295
|
+
`.trim();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return `
|
|
299
|
+
|
|
300
|
+
SELECT ?source ?predicate ?target ?author ?timestamp WHERE {${joinClause}
|
|
301
|
+
?source ?predicate ?target .
|
|
302
|
+
?_reifier <http://www.w3.org/1999/02/22-rdf-syntax-ns#reifies> <<( ?source ?predicate ?target )>> .
|
|
303
|
+
FILTER(isIRI(?source) && isIRI(?predicate))
|
|
304
|
+
?_reifier <ad4m://ontology/author> ?author .
|
|
305
|
+
?_reifier <ad4m://ontology/timestamp> ?timestamp .
|
|
306
|
+
${filterClause}
|
|
307
|
+
}
|
|
308
|
+
`.trim();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Build an inner subquery that selects DISTINCT ?source URIs with
|
|
313
|
+
* ORDER BY, LIMIT, and OFFSET applied at the instance level.
|
|
314
|
+
*
|
|
315
|
+
* Because the outer SELECT returns multiple rows per instance (one per link),
|
|
316
|
+
* we cannot apply LIMIT/OFFSET there. Instead this subquery constrains
|
|
317
|
+
* ?source to only the instances on the requested page.
|
|
318
|
+
*
|
|
319
|
+
* @internal — used by buildSPARQLQuery when SPARQL-level pagination is safe.
|
|
320
|
+
*/
|
|
321
|
+
export function buildPaginationSubquery(
|
|
322
|
+
joinPatterns: string[],
|
|
323
|
+
filterExpressions: string[],
|
|
324
|
+
metadata: ModelMetadata,
|
|
325
|
+
query: Query,
|
|
326
|
+
): string {
|
|
327
|
+
const innerJoin = joinPatterns.join('\n');
|
|
328
|
+
const innerFilter = filterExpressions.length > 0
|
|
329
|
+
? `FILTER(\n ${filterExpressions.join(' &&\n ')}\n )`
|
|
330
|
+
: '';
|
|
331
|
+
|
|
332
|
+
// Build ORDER BY clause from query.order
|
|
333
|
+
let orderByClause = '';
|
|
334
|
+
const orderJoinPatterns: string[] = [];
|
|
335
|
+
if (query.order) {
|
|
336
|
+
const orderTerms = Object.entries(query.order).map(([prop, dir]) => {
|
|
337
|
+
const sparqlVar = mapPropertyToSPARQLVar(prop, metadata);
|
|
338
|
+
// Check if this order property's variable is already bound by existing
|
|
339
|
+
// join patterns. If not, add an OPTIONAL join so ORDER BY is deterministic.
|
|
340
|
+
const varAlreadyBound = innerJoin.includes(sparqlVar);
|
|
341
|
+
if (!varAlreadyBound) {
|
|
342
|
+
const propMeta = metadata.properties[prop];
|
|
343
|
+
if (propMeta && propMeta.predicate && !propMeta.getter) {
|
|
344
|
+
orderJoinPatterns.push(`\n OPTIONAL { ?source <${propMeta.predicate}> ${sparqlVar} . }`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return dir === 'DESC' ? `DESC(${sparqlVar})` : `ASC(${sparqlVar})`;
|
|
348
|
+
});
|
|
349
|
+
if (orderTerms.length > 0) {
|
|
350
|
+
orderByClause = `ORDER BY ${orderTerms.join(' ')}`;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// No default ordering — when no explicit order is specified, results come in
|
|
355
|
+
// natural (insertion) order.
|
|
356
|
+
const tsSelect = '';
|
|
357
|
+
const tsPattern = '';
|
|
358
|
+
|
|
359
|
+
const limitClause = query.limit !== undefined ? `LIMIT ${query.limit}` : '';
|
|
360
|
+
const offsetClause = query.offset !== undefined && query.offset > 0 ? `OFFSET ${query.offset}` : '';
|
|
361
|
+
|
|
362
|
+
return `
|
|
363
|
+
{ SELECT DISTINCT ?source${tsSelect} WHERE {${innerJoin}${orderJoinPatterns.join('')}${tsPattern}
|
|
364
|
+
FILTER(isIRI(?source))
|
|
365
|
+
${innerFilter}
|
|
366
|
+
} ${orderByClause} ${limitClause} ${offsetClause} }\n`;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Build SPARQL FILTER expressions from user `where` conditions.
|
|
371
|
+
* Uses direct triple patterns instead of link-node reification.
|
|
372
|
+
*/
|
|
373
|
+
function buildSPARQLWhereFilters(
|
|
374
|
+
metadata: ModelMetadata,
|
|
375
|
+
_allRelationsMetadata: Record<string, RelationMetadataEntry>,
|
|
376
|
+
where?: Where,
|
|
377
|
+
): { joins: string[]; filters: string[] } {
|
|
378
|
+
if (!where) return { joins: [], filters: [] };
|
|
379
|
+
|
|
380
|
+
const joins: string[] = [];
|
|
381
|
+
const filters: string[] = [];
|
|
382
|
+
|
|
383
|
+
for (const [propertyName, condition] of Object.entries(where)) {
|
|
384
|
+
// 'base' maps to ?source
|
|
385
|
+
if (propertyName === "base" || propertyName === "id") {
|
|
386
|
+
if (Array.isArray(condition)) {
|
|
387
|
+
const formatted = (condition as any[]).map(v => iri(v)).join(", ");
|
|
388
|
+
filters.push(`?source IN (${formatted})`);
|
|
389
|
+
} else if (typeof condition === "object" && condition !== null) {
|
|
390
|
+
const ops = condition as any;
|
|
391
|
+
if (ops.not !== undefined) {
|
|
392
|
+
if (Array.isArray(ops.not)) {
|
|
393
|
+
const formatted = (ops.not as any[]).map(v => iri(v)).join(", ");
|
|
394
|
+
filters.push(`!(?source IN (${formatted}))`);
|
|
395
|
+
} else {
|
|
396
|
+
filters.push(`?source != ${iri(ops.not)}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
} else {
|
|
400
|
+
filters.push(`?source = ${iri(String(condition))}`);
|
|
401
|
+
}
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
if (propertyName === "author" || propertyName === "timestamp") {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const propMeta = metadata.properties[propertyName];
|
|
410
|
+
if (!propMeta) continue;
|
|
411
|
+
|
|
412
|
+
// Skip reverse relations (belongsToOne / belongsToMany) — these are registered as
|
|
413
|
+
// read-only properties but the link direction is reversed (target→source, not source→target).
|
|
414
|
+
// Adding a forward join pattern would match nothing. These are filtered in JS post-filter.
|
|
415
|
+
const relMeta = _allRelationsMetadata[propertyName];
|
|
416
|
+
if (relMeta && (relMeta.kind === 'belongsToOne' || relMeta.kind === 'belongsToMany')) {
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Determine if this property stores values as literal: IRIs
|
|
421
|
+
const useParseLiteral = isLiteralStoredProperty(propMeta);
|
|
422
|
+
|
|
423
|
+
// For literal-stored properties, push equality/IN/NOT filters to SPARQL using
|
|
424
|
+
// <ad4m://fn/parse_literal>() which extracts the raw value from literal: IRIs.
|
|
425
|
+
// The correct SPARQL syntax is <ad4m://fn/parse_literal>(?var) — NOT fn::parse_literal
|
|
426
|
+
// (which was SurrealDB syntax that Oxigraph rejects at parse time).
|
|
427
|
+
// Comparison operators (gt/lt/gte/lte/between/contains) remain JS-only because
|
|
428
|
+
// parse_literal returns strings and numeric/date comparisons would be unreliable.
|
|
429
|
+
// JS post-filter in instancesFromQueryResult remains as a safety net for all cases.
|
|
430
|
+
if (useParseLiteral) {
|
|
431
|
+
if (typeof condition === "object" && condition !== null && !Array.isArray(condition)) {
|
|
432
|
+
const ops = condition as any;
|
|
433
|
+
const hasCompOps = ops.gt !== undefined || ops.gte !== undefined ||
|
|
434
|
+
ops.lt !== undefined || ops.lte !== undefined ||
|
|
435
|
+
ops.between !== undefined || ops.contains !== undefined;
|
|
436
|
+
if (hasCompOps) {
|
|
437
|
+
// Comparison operators: join only, filter in JS
|
|
438
|
+
joins.push(`
|
|
439
|
+
?source ${iri(propMeta.predicate)} ?wTarget_cmp_${propertyName} .`);
|
|
440
|
+
}
|
|
441
|
+
if (ops.not !== undefined) {
|
|
442
|
+
// NOT filter: push down to SPARQL
|
|
443
|
+
joins.push(`
|
|
444
|
+
?source ${iri(propMeta.predicate)} ?wTarget_${propertyName} .`);
|
|
445
|
+
if (Array.isArray(ops.not)) {
|
|
446
|
+
const formatted = (ops.not as any[]).map((v: any) => formatSPARQLValue(v)).join(", ");
|
|
447
|
+
filters.push(`STR(<ad4m://fn/parse_literal>(?wTarget_${propertyName})) NOT IN (${formatted})`);
|
|
448
|
+
} else {
|
|
449
|
+
filters.push(`STR(<ad4m://fn/parse_literal>(?wTarget_${propertyName})) != ${formatSPARQLValue(ops.not)}`);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
} else if (Array.isArray(condition)) {
|
|
453
|
+
// IN filter: push down to SPARQL
|
|
454
|
+
joins.push(`
|
|
455
|
+
?source ${iri(propMeta.predicate)} ?wTarget_${propertyName} .`);
|
|
456
|
+
const formatted = (condition as any[]).map((v: any) => formatSPARQLValue(v)).join(", ");
|
|
457
|
+
filters.push(`STR(<ad4m://fn/parse_literal>(?wTarget_${propertyName})) IN (${formatted})`);
|
|
458
|
+
} else {
|
|
459
|
+
// Simple equality: push down to SPARQL
|
|
460
|
+
joins.push(`
|
|
461
|
+
?source ${iri(propMeta.predicate)} ?wTarget_${propertyName} .`);
|
|
462
|
+
filters.push(`STR(<ad4m://fn/parse_literal>(?wTarget_${propertyName})) = ${formatSPARQLValue(condition)}`);
|
|
463
|
+
}
|
|
464
|
+
} else if (Array.isArray(condition)) {
|
|
465
|
+
const formatted = (condition as any[]).map(v => iri(v)).join(", ");
|
|
466
|
+
joins.push(`
|
|
467
|
+
?source ${iri(propMeta.predicate)} ?wTarget_${propertyName} .`);
|
|
468
|
+
filters.push(`?wTarget_${propertyName} IN (${formatted})`);
|
|
469
|
+
} else if (typeof condition === "object" && condition !== null) {
|
|
470
|
+
const ops = condition as any;
|
|
471
|
+
if (ops.not !== undefined) {
|
|
472
|
+
if (Array.isArray(ops.not)) {
|
|
473
|
+
const formatted = (ops.not as any[]).map(v => iri(v)).join(", ");
|
|
474
|
+
filters.push(`
|
|
475
|
+
NOT EXISTS {
|
|
476
|
+
?source ${iri(propMeta.predicate)} ?wTarget_not_${propertyName} .
|
|
477
|
+
FILTER(?wTarget_not_${propertyName} IN (${formatted}))
|
|
478
|
+
}
|
|
479
|
+
`);
|
|
480
|
+
} else {
|
|
481
|
+
filters.push(`
|
|
482
|
+
NOT EXISTS {
|
|
483
|
+
?source ${iri(propMeta.predicate)} ${iri(ops.not)} .
|
|
484
|
+
}
|
|
485
|
+
`);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const hasCompOps = ops.gt !== undefined || ops.gte !== undefined ||
|
|
490
|
+
ops.lt !== undefined || ops.lte !== undefined ||
|
|
491
|
+
ops.between !== undefined || ops.contains !== undefined;
|
|
492
|
+
if (hasCompOps) {
|
|
493
|
+
joins.push(`
|
|
494
|
+
?source ${iri(propMeta.predicate)} ?wTarget_cmp_${propertyName} .`);
|
|
495
|
+
}
|
|
496
|
+
} else {
|
|
497
|
+
// Simple equality — non-literal property, use exact IRI match
|
|
498
|
+
joins.push(`
|
|
499
|
+
?source ${iri(propMeta.predicate)} ${iri(String(condition))} .`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
return { joins, filters };
|
|
504
|
+
}
|