@coasys/ad4m 0.12.1-dev → 0.13.0-postmessage-ws-proxy.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +5097 -11841
- package/lib/index.js +5289 -12104
- package/lib/src/Ad4mClient.d.ts +9 -3
- package/lib/src/Ad4mClient.js +40 -13
- package/lib/src/Literal.js +6 -5
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +33 -21
- package/lib/src/agent/AgentClient.js +180 -374
- package/lib/src/agent/AgentStatus.js +2 -37
- package/lib/src/ai/AIClient.d.ts +12 -4
- package/lib/src/ai/AIClient.js +81 -285
- package/lib/src/ai/AITypes.d.ts +55 -0
- package/lib/src/ai/AITypes.js +18 -0
- package/lib/src/ai/Tasks.js +10 -133
- package/lib/src/apiClient.d.ts +53 -0
- package/lib/src/apiClient.js +234 -0
- package/lib/src/cache/PersistentCache.d.ts +40 -0
- package/lib/src/cache/PersistentCache.js +139 -0
- package/lib/src/expression/Expression.d.ts +1 -1
- package/lib/src/expression/Expression.js +13 -122
- package/lib/src/expression/ExpressionClient.d.ts +11 -3
- package/lib/src/expression/ExpressionClient.js +120 -75
- package/lib/src/expression/ExpressionRef.js +4 -27
- package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkRequest.js +1 -0
- package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/api/AddSdnaRequest.js +2 -0
- package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/api/AuthInfoInput.js +1 -0
- package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/api/CapabilityInput.js +1 -0
- package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/CommitBatchRequest.js +2 -0
- package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/api/ComputeLogEntry.js +2 -0
- package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/api/EmbedRequest.js +2 -0
- package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/api/EntanglementProofInput.js +2 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/api/ExportRequest.d.ts +5 -0
- package/lib/src/generated/api/ExportRequest.js +2 -0
- package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/api/ExpressionProof.js +2 -0
- package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/api/ExpressionProofInput.js +2 -0
- package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendsListRequest.js +2 -0
- package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/api/ImportAgentRequest.js +2 -0
- package/lib/src/generated/api/ImportRequest.d.ts +4 -0
- package/lib/src/generated/api/ImportRequest.js +2 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/api/LanguageMetaInput.js +2 -0
- package/lib/src/generated/api/Link.d.ts +5 -0
- package/lib/src/generated/api/Link.js +2 -0
- package/lib/src/generated/api/LinkExpression.d.ts +10 -0
- package/lib/src/generated/api/LinkExpression.js +1 -0
- package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/api/LinkExpressionInput.js +1 -0
- package/lib/src/generated/api/LinkInput.d.ts +5 -0
- package/lib/src/generated/api/LinkInput.js +2 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/api/LinkMutations.d.ts +6 -0
- package/lib/src/generated/api/LinkMutations.js +1 -0
- package/lib/src/generated/api/LinkStatus.d.ts +1 -0
- package/lib/src/generated/api/LinkStatus.js +2 -0
- package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/LockAgentRequest.js +2 -0
- package/lib/src/generated/api/ModelType.d.ts +1 -0
- package/lib/src/generated/api/ModelType.js +2 -0
- package/lib/src/generated/api/NotificationInput.d.ts +10 -0
- package/lib/src/generated/api/NotificationInput.js +2 -0
- package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/api/OpenLinkRequest.js +2 -0
- package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveInput.js +1 -0
- package/lib/src/generated/api/PromptRequest.d.ts +4 -0
- package/lib/src/generated/api/PromptRequest.js +2 -0
- package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/api/QueryRequest.d.ts +7 -0
- package/lib/src/generated/api/QueryRequest.js +2 -0
- package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/ResourceInput.d.ts +4 -0
- package/lib/src/generated/api/ResourceInput.js +2 -0
- package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/api/SetStatusRequest.js +2 -0
- package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/SignMessageRequest.js +2 -0
- package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/UserStatistics.d.ts +9 -0
- package/lib/src/generated/api/UserStatistics.js +2 -0
- package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/api/VerificationRequestResult.js +2 -0
- package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +42 -0
- package/lib/src/generated/api/index.js +7 -0
- package/lib/src/index.d.ts +7 -2
- package/lib/src/index.js +7 -2
- package/lib/src/jestSetup.d.ts +0 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.js +2 -21
- package/lib/src/language/Language.d.ts +26 -176
- package/lib/src/language/Language.js +32 -72
- package/lib/src/language/LanguageClient.d.ts +2 -2
- package/lib/src/language/LanguageClient.js +15 -105
- package/lib/src/language/LanguageHandle.js +2 -41
- package/lib/src/language/LanguageMeta.js +4 -75
- package/lib/src/language/LanguageRef.js +2 -25
- package/lib/src/links/Links.js +14 -111
- package/lib/src/model/Ad4mModel.d.ts +150 -62
- package/lib/src/model/Ad4mModel.js +689 -417
- package/lib/src/model/Ad4mModel.test.js +1434 -688
- package/lib/src/model/ModelQueryBuilder.d.ts +59 -38
- package/lib/src/model/ModelQueryBuilder.js +317 -153
- package/lib/src/model/Subject.js +6 -6
- package/lib/src/model/decorators.d.ts +36 -8
- package/lib/src/model/decorators.js +41 -14
- package/lib/src/model/hydration-batch.d.ts +34 -0
- package/lib/src/model/hydration-batch.js +147 -0
- package/lib/src/model/hydration-batching.test.d.ts +7 -0
- package/lib/src/model/hydration-batching.test.js +456 -0
- package/lib/src/model/hydration.d.ts +3 -92
- package/lib/src/model/hydration.js +3 -691
- package/lib/src/model/index.d.ts +3 -4
- package/lib/src/model/index.js +3 -4
- package/lib/src/model/json-schema.js +2 -2
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-cache.d.ts +30 -0
- package/lib/src/model/query-cache.js +66 -0
- package/lib/src/model/query-cache.test.d.ts +1 -0
- package/lib/src/model/query-cache.test.js +43 -0
- package/lib/src/model/query-common.d.ts +1 -1
- package/lib/src/model/query-common.js +1 -1
- package/lib/src/model/query-sparql-batch.d.ts +17 -0
- package/lib/src/model/query-sparql-batch.js +260 -0
- package/lib/src/model/query-sparql.d.ts +51 -0
- package/lib/src/model/query-sparql.js +466 -0
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +312 -0
- package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
- package/lib/src/model/query-utils.js +189 -0
- package/lib/src/model/relation-filtering.test.js +15 -15
- package/lib/src/model/sdna.js +1 -1
- package/lib/src/model/shacl-gen.js +46 -18
- package/lib/src/model/subscription-delta.test.d.ts +24 -0
- package/lib/src/model/subscription-delta.test.js +180 -0
- package/lib/src/model/subscription-pool.d.ts +39 -0
- package/lib/src/model/subscription-pool.js +165 -0
- package/lib/src/model/types.d.ts +60 -5
- package/lib/src/model/types.js +5 -2
- package/lib/src/neighbourhood/Neighbourhood.js +4 -32
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
- package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
- package/lib/src/perspectives/LinkQuery.js +2 -42
- package/lib/src/perspectives/Perspective.d.ts +1 -1
- package/lib/src/perspectives/Perspective.js +10 -52
- package/lib/src/perspectives/PerspectiveClient.d.ts +22 -32
- package/lib/src/perspectives/PerspectiveClient.js +189 -454
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +156 -78
- package/lib/src/perspectives/PerspectiveProxy.js +474 -389
- package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveResolver.js +0 -11
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
- package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
- package/lib/src/runtime/RuntimeClient.d.ts +8 -6
- package/lib/src/runtime/RuntimeClient.js +97 -454
- package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
- package/lib/src/runtime/RuntimeResolver.js +84 -0
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/schema.gql +14 -1
- package/lib/src/shacl/SHACLFlow.d.ts +1 -1
- package/lib/src/shacl/SHACLFlow.js +9 -9
- package/lib/src/shacl/SHACLShape.d.ts +8 -1
- package/lib/src/shacl/SHACLShape.js +57 -38
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -615
- package/lib/src/utils.d.ts +6 -6
- package/lib/src/utils.js +6 -6
- package/package.json +6 -18
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1192 -1288
- package/src/Ad4mClient.ts +46 -15
- package/src/Literal.test.ts +10 -5
- package/src/Literal.ts +6 -5
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +238 -467
- package/src/agent/AgentStatus.ts +0 -12
- package/src/ai/AIClient.ts +96 -296
- package/src/ai/AITypes.ts +66 -0
- package/src/ai/Tasks.ts +0 -52
- package/src/apiClient.ts +287 -0
- package/src/cache/PersistentCache.ts +145 -0
- package/src/cache/cache.test.ts +713 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +148 -77
- package/src/expression/ExpressionRef.ts +2 -8
- package/src/generated/api/AIModelLoadingStatus.ts +3 -0
- package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
- package/src/generated/api/AddLinkRequest.ts +4 -0
- package/src/generated/api/AddLinksBulkRequest.ts +4 -0
- package/src/generated/api/AddSdnaRequest.ts +3 -0
- package/src/generated/api/ApplyTemplateRequest.ts +3 -0
- package/src/generated/api/AuthInfoInput.ts +4 -0
- package/src/generated/api/CapabilityInput.ts +4 -0
- package/src/generated/api/CommitBatchRequest.ts +3 -0
- package/src/generated/api/ComputeLogEntry.ts +3 -0
- package/src/generated/api/CreateExpressionRequest.ts +3 -0
- package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
- package/src/generated/api/CreateSubjectRequest.ts +3 -0
- package/src/generated/api/EmbedRequest.ts +3 -0
- package/src/generated/api/EntanglementProofInput.ts +3 -0
- package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
- package/src/generated/api/ExportRequest.ts +3 -0
- package/src/generated/api/ExpressionManyRequest.ts +3 -0
- package/src/generated/api/ExpressionProof.ts +3 -0
- package/src/generated/api/ExpressionProofInput.ts +3 -0
- package/src/generated/api/FriendSendMessageRequest.ts +3 -0
- package/src/generated/api/FriendsListRequest.ts +3 -0
- package/src/generated/api/GenerateAgentRequest.ts +3 -0
- package/src/generated/api/GenerateJwtRequest.ts +3 -0
- package/src/generated/api/GetSubjectDataRequest.ts +3 -0
- package/src/generated/api/ImportAgentRequest.ts +3 -0
- package/src/generated/api/ImportRequest.ts +3 -0
- package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
- package/src/generated/api/LanguageMetaInput.ts +3 -0
- package/src/generated/api/Link.ts +3 -0
- package/src/generated/api/LinkExpression.ts +6 -0
- package/src/generated/api/LinkExpressionInput.ts +6 -0
- package/src/generated/api/LinkInput.ts +3 -0
- package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
- package/src/generated/api/LinkMutations.ts +5 -0
- package/src/generated/api/LinkStatus.ts +3 -0
- package/src/generated/api/LockAgentRequest.ts +3 -0
- package/src/generated/api/ModelType.ts +3 -0
- package/src/generated/api/NotificationInput.ts +3 -0
- package/src/generated/api/OpenLinkRequest.ts +3 -0
- package/src/generated/api/PermitCapabilityRequest.ts +3 -0
- package/src/generated/api/PerspectiveInput.ts +4 -0
- package/src/generated/api/PromptRequest.ts +3 -0
- package/src/generated/api/PublishLanguageRequest.ts +4 -0
- package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
- package/src/generated/api/QueryRequest.ts +6 -0
- package/src/generated/api/RemoveLinkRequest.ts +4 -0
- package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
- package/src/generated/api/ResourceInput.ts +3 -0
- package/src/generated/api/SetDefaultModelRequest.ts +4 -0
- package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
- package/src/generated/api/SetMultiUserRequest.ts +3 -0
- package/src/generated/api/SetStatusRequest.ts +3 -0
- package/src/generated/api/SignMessageRequest.ts +3 -0
- package/src/generated/api/TrustedAgentsRequest.ts +3 -0
- package/src/generated/api/UnlockAgentRequest.ts +3 -0
- package/src/generated/api/UpdateLinkRequest.ts +5 -0
- package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
- package/src/generated/api/UserStatistics.ts +3 -0
- package/src/generated/api/VerificationRequestResult.ts +3 -0
- package/src/generated/api/VerifySignatureRequest.ts +3 -0
- package/src/generated/api/WriteSettingsRequest.ts +3 -0
- package/src/generated/api/index.ts +49 -0
- package/src/index.ts +7 -2
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +51 -248
- package/src/language/LanguageClient.ts +21 -132
- package/src/language/LanguageHandle.ts +0 -14
- package/src/language/LanguageMeta.ts +0 -29
- package/src/language/LanguageRef.ts +0 -7
- package/src/links/Links.ts +0 -37
- package/src/model/Ad4mModel.test.ts +1690 -777
- package/src/model/Ad4mModel.ts +749 -477
- package/src/model/ModelQueryBuilder.ts +356 -171
- package/src/model/decorators.ts +71 -22
- package/src/model/hydration.ts +3 -772
- package/src/model/index.ts +3 -4
- package/src/model/json-schema.ts +2 -2
- package/src/model/query-cache.test.ts +54 -0
- package/src/model/query-cache.ts +79 -0
- package/src/model/query-common.ts +1 -1
- package/src/model/query-sparql.test.ts +376 -0
- package/src/model/query-sparql.ts +504 -0
- package/src/model/query-utils.ts +209 -0
- package/src/model/relation-filtering.test.ts +15 -15
- package/src/model/sdna.ts +1 -1
- package/src/model/shacl-gen.ts +47 -17
- package/src/model/types.ts +65 -5
- package/src/neighbourhood/Neighbourhood.ts +0 -9
- package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
- package/src/perspectives/LinkQuery.ts +0 -15
- package/src/perspectives/Perspective.ts +1 -12
- package/src/perspectives/PerspectiveClient.test.ts +262 -0
- package/src/perspectives/PerspectiveClient.ts +254 -468
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +125 -0
- package/src/perspectives/PerspectiveProxy.ts +522 -434
- package/src/perspectives/WakerSubscriptionManager.ts +13 -13
- package/src/runtime/RuntimeClient.ts +118 -461
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLFlow.ts +9 -9
- package/src/shacl/SHACLShape.test.ts +94 -0
- package/src/shacl/SHACLShape.ts +66 -39
- package/src/typeDefs.ts +3 -5
- package/src/utils.ts +6 -6
- package/tsconfig.json +3 -7
- package/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/lib/src/model/surreal-utils.js +0 -128
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +0 -75
- package/src/PubSub.ts +0 -17
- package/src/agent/AgentResolver.ts +0 -263
- package/src/ai/AIResolver.ts +0 -372
- package/src/buildSchema.ts +0 -43
- package/src/expression/ExpressionResolver.ts +0 -64
- package/src/language/LanguageContext.ts +0 -37
- package/src/language/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-surreal.ts +0 -280
- package/src/model/surreal-utils.ts +0 -147
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -372
- package/src/runtime/RuntimeResolver.ts +0 -691
- package/src/unwrapApolloResult.ts +0 -16
- package/tsconfig-browser.json +0 -82
package/lib/src/model/index.d.ts
CHANGED
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
export * from "./types";
|
|
9
9
|
export * from "./Ad4mModel";
|
|
10
10
|
export * from "./decorators";
|
|
11
|
-
export * from "./Subject";
|
|
12
11
|
export * from "./query-common";
|
|
13
|
-
export * from "./query-prolog";
|
|
14
|
-
export * from "./prolog-facts";
|
|
15
12
|
export * from "./json-schema";
|
|
16
|
-
export * from "./query-
|
|
13
|
+
export * from "./query-utils";
|
|
14
|
+
export * from "./query-sparql";
|
|
17
15
|
export * from "./hydration";
|
|
18
16
|
export * from "./ModelQueryBuilder";
|
|
19
17
|
export * from "./sdna";
|
|
20
18
|
export * from "./shacl-gen";
|
|
19
|
+
export * from "./query-cache";
|
package/lib/src/model/index.js
CHANGED
|
@@ -8,13 +8,12 @@
|
|
|
8
8
|
export * from "./types";
|
|
9
9
|
export * from "./Ad4mModel";
|
|
10
10
|
export * from "./decorators";
|
|
11
|
-
export * from "./Subject";
|
|
12
11
|
export * from "./query-common";
|
|
13
|
-
export * from "./query-prolog";
|
|
14
|
-
export * from "./prolog-facts";
|
|
15
12
|
export * from "./json-schema";
|
|
16
|
-
export * from "./query-
|
|
13
|
+
export * from "./query-utils";
|
|
14
|
+
export * from "./query-sparql";
|
|
17
15
|
export * from "./hydration";
|
|
18
16
|
export * from "./ModelQueryBuilder";
|
|
19
17
|
export * from "./sdna";
|
|
20
18
|
export * from "./shacl-gen";
|
|
19
|
+
export * from "./query-cache";
|
|
@@ -263,14 +263,14 @@ export function buildModelFromJSONSchema(BaseClass, schema, options) {
|
|
|
263
263
|
}
|
|
264
264
|
// Default resolveLanguage to 'literal' for all remaining property types,
|
|
265
265
|
// matching the @Property decorator behaviour. Without this, string values
|
|
266
|
-
// stored as literal
|
|
266
|
+
// stored as literal: URLs are returned unparsed.
|
|
267
267
|
if (resolveLanguage === undefined || resolveLanguage === null) {
|
|
268
268
|
resolveLanguage = 'literal';
|
|
269
269
|
}
|
|
270
270
|
// If property is required, ensure it has an initial value
|
|
271
271
|
if (isRequired && !initial) {
|
|
272
272
|
if (isObjectType(propertySchema)) {
|
|
273
|
-
initial = 'literal
|
|
273
|
+
initial = 'literal:json:{}';
|
|
274
274
|
}
|
|
275
275
|
else {
|
|
276
276
|
initial = "ad4m://undefined";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the perspective model manifest — a human-readable, AI-friendly summary
|
|
3
|
+
* of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
|
|
4
|
+
*
|
|
5
|
+
* Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
|
|
6
|
+
* injection (`formatManifestForPrompt`) to describe external perspective models
|
|
7
|
+
* to the schema-generation AI.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
/** Normalised description of a single property on a model class. */
|
|
12
|
+
export interface ModelManifestProperty {
|
|
13
|
+
/** Property name as declared in the SHACL shape (e.g. "name", "body", "participants"). */
|
|
14
|
+
name: string;
|
|
15
|
+
/** The exact RDF predicate URI (e.g. "flux://has_name"). */
|
|
16
|
+
predicate: string;
|
|
17
|
+
/** Normalised scalar type; inferred from xsd:/sh: datatype + nodeKind. */
|
|
18
|
+
type: 'string' | 'number' | 'boolean' | 'uri';
|
|
19
|
+
/** `true` when maxCount is absent or > 1 (i.e. returned as an array). */
|
|
20
|
+
isCollection: boolean;
|
|
21
|
+
/** `true` when minCount >= 1. */
|
|
22
|
+
required: boolean;
|
|
23
|
+
writable: boolean;
|
|
24
|
+
/** AD4M language used to resolve the value (e.g. "literal"). */
|
|
25
|
+
resolveLanguage?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Local name of the related model class when this is a typed relation property.
|
|
28
|
+
* Derived from `SHACLPropertyShape.class` by stripping the URI prefix.
|
|
29
|
+
* E.g. `flux://Message` → `"Message"`.
|
|
30
|
+
*/
|
|
31
|
+
relatedModel?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Normalised description of a single model class stored in a perspective. */
|
|
34
|
+
export interface ModelManifestEntry {
|
|
35
|
+
/** Class name — usable directly as the `model` field in a `$query` token. */
|
|
36
|
+
name: string;
|
|
37
|
+
/** The SHACL `targetClass` URI (e.g. "flux://Channel"). */
|
|
38
|
+
targetClass: string;
|
|
39
|
+
/** All data properties (flag/hasValue properties are excluded). */
|
|
40
|
+
properties: ModelManifestProperty[];
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for the perspective model manifest — a human-readable, AI-friendly summary
|
|
3
|
+
* of all Ad4mModel-compatible classes defined in a perspective's SHACL shapes.
|
|
4
|
+
*
|
|
5
|
+
* Used by `PerspectiveProxy.getModelManifest()` and consumed by WE's AI context
|
|
6
|
+
* injection (`formatManifestForPrompt`) to describe external perspective models
|
|
7
|
+
* to the schema-generation AI.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Result TTL Cache
|
|
3
|
+
*
|
|
4
|
+
* Short-lived cache (200ms TTL) for SPARQL query results.
|
|
5
|
+
* Prevents redundant queries during rapid render cycles where
|
|
6
|
+
* multiple components issue the same query within milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* Key: `perspectiveUUID + queryText`
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Get a cached query result if it exists and hasn't expired.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getCachedResult(perspectiveUUID: string, queryText: string): any | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Store a query result in the cache with TTL.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setCachedResult(perspectiveUUID: string, queryText: string, result: any, ttlMs?: number): void;
|
|
18
|
+
/**
|
|
19
|
+
* Invalidate all cache entries for a given perspective.
|
|
20
|
+
* Called after write operations to ensure stale data isn't served.
|
|
21
|
+
*/
|
|
22
|
+
export declare function invalidatePerspectiveCache(perspectiveUUID: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Clear all cache entries (useful for testing).
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearQueryCache(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get the current size of the cache (useful for testing).
|
|
29
|
+
*/
|
|
30
|
+
export declare function queryCacheSize(): number;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Result TTL Cache
|
|
3
|
+
*
|
|
4
|
+
* Short-lived cache (200ms TTL) for SPARQL query results.
|
|
5
|
+
* Prevents redundant queries during rapid render cycles where
|
|
6
|
+
* multiple components issue the same query within milliseconds.
|
|
7
|
+
*
|
|
8
|
+
* Key: `perspectiveUUID + queryText`
|
|
9
|
+
*/
|
|
10
|
+
const cache = new Map();
|
|
11
|
+
const DEFAULT_TTL_MS = 200;
|
|
12
|
+
function makeKey(perspectiveUUID, queryText) {
|
|
13
|
+
return `${perspectiveUUID}:${queryText}`;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get a cached query result if it exists and hasn't expired.
|
|
17
|
+
*/
|
|
18
|
+
export function getCachedResult(perspectiveUUID, queryText) {
|
|
19
|
+
const key = makeKey(perspectiveUUID, queryText);
|
|
20
|
+
const entry = cache.get(key);
|
|
21
|
+
if (!entry)
|
|
22
|
+
return undefined;
|
|
23
|
+
if (Date.now() > entry.expiry) {
|
|
24
|
+
cache.delete(key);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return entry.result;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Store a query result in the cache with TTL.
|
|
31
|
+
*/
|
|
32
|
+
export function setCachedResult(perspectiveUUID, queryText, result, ttlMs = DEFAULT_TTL_MS) {
|
|
33
|
+
// Lazy eviction of expired entries
|
|
34
|
+
const now = Date.now();
|
|
35
|
+
for (const [key, entry] of cache) {
|
|
36
|
+
if (now > entry.expiry) {
|
|
37
|
+
cache.delete(key);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const cacheKey = makeKey(perspectiveUUID, queryText);
|
|
41
|
+
cache.set(cacheKey, { result, expiry: now + ttlMs });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Invalidate all cache entries for a given perspective.
|
|
45
|
+
* Called after write operations to ensure stale data isn't served.
|
|
46
|
+
*/
|
|
47
|
+
export function invalidatePerspectiveCache(perspectiveUUID) {
|
|
48
|
+
const prefix = perspectiveUUID + ':';
|
|
49
|
+
for (const [key] of cache) {
|
|
50
|
+
if (key.startsWith(prefix)) {
|
|
51
|
+
cache.delete(key);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Clear all cache entries (useful for testing).
|
|
57
|
+
*/
|
|
58
|
+
export function clearQueryCache() {
|
|
59
|
+
cache.clear();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the current size of the cache (useful for testing).
|
|
63
|
+
*/
|
|
64
|
+
export function queryCacheSize() {
|
|
65
|
+
return cache.size;
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getCachedResult, setCachedResult, invalidatePerspectiveCache, clearQueryCache, queryCacheSize } from './query-cache';
|
|
2
|
+
describe('query-cache', () => {
|
|
3
|
+
beforeEach(() => {
|
|
4
|
+
clearQueryCache();
|
|
5
|
+
});
|
|
6
|
+
describe('lazy eviction', () => {
|
|
7
|
+
it('should remove expired entries when setting a new one', () => {
|
|
8
|
+
// Insert with a very short TTL
|
|
9
|
+
setCachedResult('p1', 'SELECT ?x', 'result1', 1);
|
|
10
|
+
expect(queryCacheSize()).toBe(1);
|
|
11
|
+
// Wait for expiry
|
|
12
|
+
const start = Date.now();
|
|
13
|
+
while (Date.now() - start < 5) { /* busy wait 5ms */ }
|
|
14
|
+
// Expired entry should still be in the map (not yet evicted)
|
|
15
|
+
// but getCachedResult should return undefined
|
|
16
|
+
expect(getCachedResult('p1', 'SELECT ?x')).toBeUndefined();
|
|
17
|
+
// Setting a new entry should evict the expired one
|
|
18
|
+
setCachedResult('p2', 'SELECT ?y', 'result2', 10000);
|
|
19
|
+
// Only the new entry should remain
|
|
20
|
+
expect(queryCacheSize()).toBe(1);
|
|
21
|
+
expect(getCachedResult('p2', 'SELECT ?y')).toBe('result2');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('invalidatePerspectiveCache', () => {
|
|
25
|
+
it('should remove all entries for a specific perspective', () => {
|
|
26
|
+
setCachedResult('p1', 'query1', 'r1', 10000);
|
|
27
|
+
setCachedResult('p1', 'query2', 'r2', 10000);
|
|
28
|
+
setCachedResult('p2', 'query1', 'r3', 10000);
|
|
29
|
+
expect(queryCacheSize()).toBe(3);
|
|
30
|
+
invalidatePerspectiveCache('p1');
|
|
31
|
+
expect(queryCacheSize()).toBe(1);
|
|
32
|
+
expect(getCachedResult('p1', 'query1')).toBeUndefined();
|
|
33
|
+
expect(getCachedResult('p1', 'query2')).toBeUndefined();
|
|
34
|
+
expect(getCachedResult('p2', 'query1')).toBe('r3');
|
|
35
|
+
});
|
|
36
|
+
it('should not affect other perspectives', () => {
|
|
37
|
+
setCachedResult('p1', 'q', 'r1', 10000);
|
|
38
|
+
setCachedResult('p2', 'q', 'r2', 10000);
|
|
39
|
+
invalidatePerspectiveCache('p3');
|
|
40
|
+
expect(queryCacheSize()).toBe(2);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch SPARQL query builder for Ad4mModel eager-loading (includes).
|
|
3
|
+
*
|
|
4
|
+
* Uses direct triple + named graph storage model.
|
|
5
|
+
* Each AD4M link is stored as: <source> <predicate> <target> in a named graph
|
|
6
|
+
* with metadata in the default graph keyed by graph IRI.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { Query, ModelMetadata } from "./types";
|
|
11
|
+
/**
|
|
12
|
+
* Build a single SPARQL query that fetches root instances plus all
|
|
13
|
+
* included relations in one query using UNION branches.
|
|
14
|
+
*
|
|
15
|
+
* Uses direct triple patterns in named graphs with metadata in default graph.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildBatchSPARQLQuery(rootMetadata: ModelMetadata, query: Query, rootModelClass: any): string;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch SPARQL query builder for Ad4mModel eager-loading (includes).
|
|
3
|
+
*
|
|
4
|
+
* Uses direct triple + named graph storage model.
|
|
5
|
+
* Each AD4M link is stored as: <source> <predicate> <target> in a named graph
|
|
6
|
+
* with metadata in the default graph keyed by graph IRI.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { resolveParentPredicate } from "./query-common";
|
|
11
|
+
import { getRelationsMetadata } from "./decorators";
|
|
12
|
+
import { Literal } from "../Literal";
|
|
13
|
+
// ──────────────────────────────────────────────────────────
|
|
14
|
+
// Helpers
|
|
15
|
+
// ──────────────────────────────────────────────────────────
|
|
16
|
+
function iri(value) {
|
|
17
|
+
return `<${value}>`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if a string value looks like a URI (has a scheme).
|
|
21
|
+
*/
|
|
22
|
+
function looksLikeUri(value) {
|
|
23
|
+
return /^[a-zA-Z][a-zA-Z0-9+\-._]*:/.test(value);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Convert a JS value to its literal: IRI form.
|
|
27
|
+
*/
|
|
28
|
+
function valueToLiteralIri(value) {
|
|
29
|
+
if (typeof value === 'string') {
|
|
30
|
+
if (looksLikeUri(value))
|
|
31
|
+
return value;
|
|
32
|
+
return Literal.from(value).toUrl();
|
|
33
|
+
}
|
|
34
|
+
if (typeof value === 'number')
|
|
35
|
+
return Literal.from(value).toUrl();
|
|
36
|
+
if (typeof value === 'boolean')
|
|
37
|
+
return Literal.from(value).toUrl();
|
|
38
|
+
return Literal.from(String(value)).toUrl();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Determine if a property stores values as literal: IRIs.
|
|
42
|
+
*/
|
|
43
|
+
function isLiteralStoredProperty(propMeta) {
|
|
44
|
+
if (propMeta.flag)
|
|
45
|
+
return false;
|
|
46
|
+
if (propMeta.resolveLanguage && propMeta.resolveLanguage !== "literal")
|
|
47
|
+
return false;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
function buildConformanceJoins(metadata, sourceVar, prefix) {
|
|
51
|
+
const joins = [];
|
|
52
|
+
const filters = [];
|
|
53
|
+
let hasConformance = false;
|
|
54
|
+
for (const [, propMeta] of Object.entries(metadata.properties)) {
|
|
55
|
+
if (propMeta.required) {
|
|
56
|
+
if (propMeta.getter)
|
|
57
|
+
continue;
|
|
58
|
+
hasConformance = true;
|
|
59
|
+
if (propMeta.flag && propMeta.initial) {
|
|
60
|
+
joins.push(`
|
|
61
|
+
${sourceVar} ${iri(propMeta.predicate)} ${iri(propMeta.initial)} .`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
joins.push(`
|
|
65
|
+
${sourceVar} ${iri(propMeta.predicate)} ?${prefix}_cfTarget_${propMeta.name} .`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!hasConformance) {
|
|
70
|
+
for (const [, propMeta] of Object.entries(metadata.properties)) {
|
|
71
|
+
if (propMeta.initial) {
|
|
72
|
+
if (propMeta.flag) {
|
|
73
|
+
joins.push(`
|
|
74
|
+
${sourceVar} ${iri(propMeta.predicate)} ${iri(propMeta.initial)} .`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
joins.push(`
|
|
78
|
+
${sourceVar} ${iri(propMeta.predicate)} ?${prefix}_cfInitAny_${propMeta.name} .`);
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { joins, filters };
|
|
85
|
+
}
|
|
86
|
+
function flattenIncludeTree(parentDepth, parentClass, includeMap, nextDepth) {
|
|
87
|
+
const branches = [];
|
|
88
|
+
const relMeta = getRelationsMetadata(parentClass);
|
|
89
|
+
for (const [relName, includeValue] of Object.entries(includeMap)) {
|
|
90
|
+
const meta = relMeta[relName];
|
|
91
|
+
if (!meta || !meta.target)
|
|
92
|
+
continue;
|
|
93
|
+
const TargetClass = meta.target();
|
|
94
|
+
const targetMetadata = TargetClass.getModelMetadata
|
|
95
|
+
? TargetClass.getModelMetadata()
|
|
96
|
+
: { className: "Unknown", properties: {}, relations: {} };
|
|
97
|
+
const depth = nextDepth.value++;
|
|
98
|
+
const direction = meta.kind === 'belongsToOne' || meta.kind === 'belongsToMany'
|
|
99
|
+
? 'reverse' : 'forward';
|
|
100
|
+
const nestedInclude = typeof includeValue === 'object' && includeValue !== null
|
|
101
|
+
? includeValue.include
|
|
102
|
+
: undefined;
|
|
103
|
+
branches.push({
|
|
104
|
+
depth,
|
|
105
|
+
relationName: relName,
|
|
106
|
+
parentDepth,
|
|
107
|
+
parentPredicate: meta.predicate,
|
|
108
|
+
targetClass: TargetClass,
|
|
109
|
+
targetMetadata,
|
|
110
|
+
includeMap: nestedInclude,
|
|
111
|
+
direction,
|
|
112
|
+
});
|
|
113
|
+
if (nestedInclude) {
|
|
114
|
+
branches.push(...flattenIncludeTree(depth, TargetClass, nestedInclude, nextDepth));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return branches;
|
|
118
|
+
}
|
|
119
|
+
// ──────────────────────────────────────────────────────────
|
|
120
|
+
// Main entry point
|
|
121
|
+
// ──────────────────────────────────────────────────────────
|
|
122
|
+
/**
|
|
123
|
+
* Build a single SPARQL query that fetches root instances plus all
|
|
124
|
+
* included relations in one query using UNION branches.
|
|
125
|
+
*
|
|
126
|
+
* Uses direct triple patterns in named graphs with metadata in default graph.
|
|
127
|
+
*/
|
|
128
|
+
export function buildBatchSPARQLQuery(rootMetadata, query, rootModelClass) {
|
|
129
|
+
const includeMap = query.include;
|
|
130
|
+
if (!includeMap || Object.keys(includeMap).length === 0) {
|
|
131
|
+
throw new Error("buildBatchSPARQLQuery requires query.include to be non-empty");
|
|
132
|
+
}
|
|
133
|
+
const nextDepth = { value: 1 };
|
|
134
|
+
const branches = flattenIncludeTree(0, rootModelClass, includeMap, nextDepth);
|
|
135
|
+
// Root conformance
|
|
136
|
+
const rootConformance = buildConformanceJoins(rootMetadata, "?source", "root");
|
|
137
|
+
const rootJoins = [...rootConformance.joins];
|
|
138
|
+
const rootFilters = [...rootConformance.filters];
|
|
139
|
+
if (query.parent) {
|
|
140
|
+
const parentPredicate = resolveParentPredicate(query.parent, rootModelClass);
|
|
141
|
+
rootJoins.push(`
|
|
142
|
+
${iri(query.parent.id)} ${iri(parentPredicate)} ?source .`);
|
|
143
|
+
}
|
|
144
|
+
if (query.where) {
|
|
145
|
+
for (const [propertyName, condition] of Object.entries(query.where)) {
|
|
146
|
+
if (propertyName === "base" || propertyName === "id") {
|
|
147
|
+
if (Array.isArray(condition)) {
|
|
148
|
+
const formatted = condition.map(v => iri(v)).join(", ");
|
|
149
|
+
rootFilters.push(`?source IN (${formatted})`);
|
|
150
|
+
}
|
|
151
|
+
else if (typeof condition === "string") {
|
|
152
|
+
rootFilters.push(`?source = ${iri(condition)}`);
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (propertyName === "author" || propertyName === "timestamp")
|
|
157
|
+
continue;
|
|
158
|
+
const propMeta = rootMetadata.properties[propertyName];
|
|
159
|
+
if (!propMeta)
|
|
160
|
+
continue;
|
|
161
|
+
const useParseLiteral = isLiteralStoredProperty(propMeta);
|
|
162
|
+
if (typeof condition === "string" || typeof condition === "number" || typeof condition === "boolean") {
|
|
163
|
+
if (useParseLiteral) {
|
|
164
|
+
// For literal-stored properties, just add a join for conformance — filtering is done in JS
|
|
165
|
+
rootJoins.push(`
|
|
166
|
+
?source ${iri(propMeta.predicate)} ?root_wTarget_eq_${propertyName} .`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
rootJoins.push(`
|
|
170
|
+
?source ${iri(propMeta.predicate)} ${iri(String(condition))} .`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (Array.isArray(condition)) {
|
|
174
|
+
if (useParseLiteral) {
|
|
175
|
+
// For literal-stored properties, just add a join for conformance — filtering is done in JS
|
|
176
|
+
rootJoins.push(`
|
|
177
|
+
?source ${iri(propMeta.predicate)} ?root_wTarget_${propertyName} .`);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
const formatted = condition.map(v => iri(v)).join(", ");
|
|
181
|
+
rootJoins.push(`
|
|
182
|
+
?source ${iri(propMeta.predicate)} ?root_wTarget_${propertyName} .`);
|
|
183
|
+
rootFilters.push(`?root_wTarget_${propertyName} IN (${formatted})`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const rootJoinClause = rootJoins.join("\n");
|
|
189
|
+
const rootFilterClause = rootFilters.length > 0
|
|
190
|
+
? `FILTER(\n ${rootFilters.join(" &&\n ")}\n )`
|
|
191
|
+
: "";
|
|
192
|
+
const unionBranches = [];
|
|
193
|
+
// Depth 0: root — direct triple pattern with named graph
|
|
194
|
+
unionBranches.push(`
|
|
195
|
+
{
|
|
196
|
+
${rootJoinClause}
|
|
197
|
+
GRAPH ?linkGraph { ?source ?predicate ?target . }
|
|
198
|
+
FILTER(isIRI(?source) && isIRI(?predicate))
|
|
199
|
+
?linkGraph <ad4m://ontology/author> ?author .
|
|
200
|
+
?linkGraph <ad4m://ontology/timestamp> ?timestamp .
|
|
201
|
+
${rootFilterClause}
|
|
202
|
+
BIND("0" AS ?depth)
|
|
203
|
+
BIND("" AS ?parentBase)
|
|
204
|
+
BIND("" AS ?relationName)
|
|
205
|
+
}
|
|
206
|
+
`);
|
|
207
|
+
// Depth N: include branches
|
|
208
|
+
for (const branch of branches) {
|
|
209
|
+
const childConformance = buildConformanceJoins(branch.targetMetadata, "?source", `d${branch.depth}`);
|
|
210
|
+
const childJoinClause = childConformance.joins.join("\n");
|
|
211
|
+
const childFilterClause = childConformance.filters.length > 0
|
|
212
|
+
? `FILTER(\n ${childConformance.filters.join(" &&\n ")}\n )`
|
|
213
|
+
: "";
|
|
214
|
+
const parentJoinClause = branch.parentDepth === 0 ? rootJoinClause.replace(/\?source/g, '?parentBase') : '';
|
|
215
|
+
const parentFilterClause = branch.parentDepth === 0 ? rootFilterClause.replace(/\?source/g, '?parentBase') : '';
|
|
216
|
+
if (branch.direction === 'forward') {
|
|
217
|
+
// Forward: parent --predicate--> child (source)
|
|
218
|
+
unionBranches.push(`
|
|
219
|
+
{
|
|
220
|
+
# Depth ${branch.depth}: ${branch.relationName} (forward)
|
|
221
|
+
?parentBase ${iri(branch.parentPredicate)} ?source .
|
|
222
|
+
${childJoinClause}
|
|
223
|
+
GRAPH ?linkGraph { ?source ?predicate ?target . }
|
|
224
|
+
FILTER(isIRI(?source) && isIRI(?predicate))
|
|
225
|
+
?linkGraph <ad4m://ontology/author> ?author .
|
|
226
|
+
?linkGraph <ad4m://ontology/timestamp> ?timestamp .
|
|
227
|
+
${childFilterClause}
|
|
228
|
+
${parentJoinClause}
|
|
229
|
+
${parentFilterClause}
|
|
230
|
+
BIND("${branch.depth}" AS ?depth)
|
|
231
|
+
BIND("${branch.relationName}" AS ?relationName)
|
|
232
|
+
}
|
|
233
|
+
`);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Reverse: child (source) --predicate--> parent
|
|
237
|
+
unionBranches.push(`
|
|
238
|
+
{
|
|
239
|
+
# Depth ${branch.depth}: ${branch.relationName} (reverse)
|
|
240
|
+
?source ${iri(branch.parentPredicate)} ?parentBase .
|
|
241
|
+
${childJoinClause}
|
|
242
|
+
GRAPH ?linkGraph { ?source ?predicate ?target . }
|
|
243
|
+
FILTER(isIRI(?source) && isIRI(?predicate))
|
|
244
|
+
?linkGraph <ad4m://ontology/author> ?author .
|
|
245
|
+
?linkGraph <ad4m://ontology/timestamp> ?timestamp .
|
|
246
|
+
${childFilterClause}
|
|
247
|
+
${parentJoinClause}
|
|
248
|
+
${parentFilterClause}
|
|
249
|
+
BIND("${branch.depth}" AS ?depth)
|
|
250
|
+
BIND("${branch.relationName}" AS ?relationName)
|
|
251
|
+
}
|
|
252
|
+
`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return `
|
|
256
|
+
SELECT ?depth ?parentBase ?relationName ?source ?predicate ?target ?author ?timestamp WHERE {
|
|
257
|
+
${unionBranches.join("\n UNION\n")}
|
|
258
|
+
}
|
|
259
|
+
`.trim();
|
|
260
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
import type { RelationMetadataEntry } from "./decorators";
|
|
14
|
+
import type { Where, Query, ModelMetadata } from "./types";
|
|
15
|
+
/**
|
|
16
|
+
* Check whether a `where` clause contains filters that cannot be pushed down
|
|
17
|
+
* to SPARQL and must be evaluated in JS after hydration.
|
|
18
|
+
*
|
|
19
|
+
* JS-only filters include:
|
|
20
|
+
* - Literal-stored properties (equality, comparison, contains, etc.)
|
|
21
|
+
* - Reverse relations (belongsToOne / belongsToMany)
|
|
22
|
+
* - author / timestamp filters (skipped by buildSPARQLWhereFilters)
|
|
23
|
+
*
|
|
24
|
+
* When JS-only filters exist, SPARQL-level LIMIT/OFFSET must NOT be applied
|
|
25
|
+
* because the database would cap the candidate set before JS filters run,
|
|
26
|
+
* potentially discarding matches beyond the LIMIT.
|
|
27
|
+
*/
|
|
28
|
+
export declare function hasJsOnlyWhereFilters(metadata: ModelMetadata, allRelationsMetadata: Record<string, RelationMetadataEntry>, where?: Where): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Format a value as a SPARQL string literal (double-quoted).
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatSPARQLValue(value: any): string;
|
|
33
|
+
/**
|
|
34
|
+
* Build a SPARQL query that returns all links belonging to instances of
|
|
35
|
+
* the given model class, optionally filtered by `where` conditions.
|
|
36
|
+
*
|
|
37
|
+
* Uses direct triple patterns: ?source ?predicate ?target
|
|
38
|
+
* with named graph storage and metadata keyed by graph IRI.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildSPARQLQuery(metadata: ModelMetadata, allRelationsMetadata: Record<string, RelationMetadataEntry>, query: Query, modelClass: any): string;
|
|
41
|
+
/**
|
|
42
|
+
* Build an inner subquery that selects DISTINCT ?source URIs with
|
|
43
|
+
* ORDER BY, LIMIT, and OFFSET applied at the instance level.
|
|
44
|
+
*
|
|
45
|
+
* Because the outer SELECT returns multiple rows per instance (one per link),
|
|
46
|
+
* we cannot apply LIMIT/OFFSET there. Instead this subquery constrains
|
|
47
|
+
* ?source to only the instances on the requested page.
|
|
48
|
+
*
|
|
49
|
+
* @internal — used by buildSPARQLQuery when SPARQL-level pagination is safe.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildPaginationSubquery(joinPatterns: string[], filterExpressions: string[], metadata: ModelMetadata, query: Query): string;
|