@coasys/ad4m 0.12.0 → 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 +7444 -13939
- package/lib/index.js +5322 -11888
- 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 -373
- 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 +34 -6
- package/lib/src/runtime/RuntimeClient.js +131 -362
- package/lib/src/runtime/RuntimeResolver.d.ts +28 -1
- package/lib/src/runtime/RuntimeResolver.js +197 -4
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/schema.gql +27 -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 -602
- 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 -465
- 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 +166 -369
- 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 -617
- package/src/unwrapApolloResult.ts +0 -16
- package/tsconfig-browser.json +0 -82
|
@@ -9,21 +9,33 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _QuerySubscriptionProxy_instances, _QuerySubscriptionProxy_uuid, _QuerySubscriptionProxy_subscriptionId, _QuerySubscriptionProxy_client, _QuerySubscriptionProxy_callbacks, _QuerySubscriptionProxy_keepaliveTimer, _QuerySubscriptionProxy_unsubscribe, _QuerySubscriptionProxy_latestResult, _QuerySubscriptionProxy_disposed, _QuerySubscriptionProxy_initialized, _QuerySubscriptionProxy_initResolve, _QuerySubscriptionProxy_initReject, _QuerySubscriptionProxy_initTimeoutId, _QuerySubscriptionProxy_query, _QuerySubscriptionProxy_notifyCallbacks, _PerspectiveProxy_handle, _PerspectiveProxy_client, _PerspectiveProxy_perspectiveLinkAddedCallbacks, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks;
|
|
12
|
+
var _QuerySubscriptionProxy_instances, _QuerySubscriptionProxy_uuid, _QuerySubscriptionProxy_subscriptionId, _QuerySubscriptionProxy_client, _QuerySubscriptionProxy_callbacks, _QuerySubscriptionProxy_keepaliveTimer, _QuerySubscriptionProxy_unsubscribe, _QuerySubscriptionProxy_latestResult, _QuerySubscriptionProxy_disposed, _QuerySubscriptionProxy_initialized, _QuerySubscriptionProxy_initResolve, _QuerySubscriptionProxy_initReject, _QuerySubscriptionProxy_initTimeoutId, _QuerySubscriptionProxy_query, _QuerySubscriptionProxy_notifyCallbacks, _PerspectiveProxy_handle, _PerspectiveProxy_client, _PerspectiveProxy_perspectiveLinkAddedCallbacks, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, _PerspectiveProxy_ensuredSubjectClasses;
|
|
13
13
|
import { Link } from "../links/Links";
|
|
14
14
|
import { LinkQuery } from "./LinkQuery";
|
|
15
15
|
import { Literal } from "../Literal";
|
|
16
|
-
import { Subject } from "../model/Subject";
|
|
17
16
|
import { getPropertiesMetadata, getRelationsMetadata } from "../model/decorators";
|
|
18
|
-
import {
|
|
17
|
+
import { getCachedResult, setCachedResult, invalidatePerspectiveCache } from "../model/query-cache";
|
|
19
18
|
import { SHACLShape } from "../shacl/SHACLShape";
|
|
20
19
|
import { SHACLFlow } from "../shacl/SHACLFlow";
|
|
20
|
+
/** Extract namespace prefix from a URI (everything up to and including the last / or #) */
|
|
21
|
+
function extractNamespaceFromUri(uri) {
|
|
22
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
23
|
+
if (hashIdx >= 0)
|
|
24
|
+
return uri.substring(0, hashIdx + 1);
|
|
25
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
26
|
+
if (slashIdx >= 0)
|
|
27
|
+
return uri.substring(0, slashIdx + 1);
|
|
28
|
+
const colonIdx = uri.lastIndexOf(':');
|
|
29
|
+
if (colonIdx >= 0)
|
|
30
|
+
return uri.substring(0, colonIdx + 1);
|
|
31
|
+
return uri;
|
|
32
|
+
}
|
|
21
33
|
/** Proxy object for a subscribed Prolog query that provides real-time updates
|
|
22
34
|
*
|
|
23
35
|
* This class handles:
|
|
24
36
|
* - Keeping the subscription alive by sending periodic keepalive signals
|
|
25
37
|
* - Managing callbacks for result updates
|
|
26
|
-
* - Subscribing to query updates via
|
|
38
|
+
* - Subscribing to query updates via WebSocket subscriptions
|
|
27
39
|
* - Maintaining the latest query result
|
|
28
40
|
* - Ensuring subscription is fully initialized before allowing access
|
|
29
41
|
* - Cleaning up resources when disposed
|
|
@@ -72,7 +84,6 @@ export class QuerySubscriptionProxy {
|
|
|
72
84
|
_QuerySubscriptionProxy_initReject.set(this, void 0);
|
|
73
85
|
_QuerySubscriptionProxy_initTimeoutId.set(this, void 0);
|
|
74
86
|
_QuerySubscriptionProxy_query.set(this, void 0);
|
|
75
|
-
this.isSurrealDB = false;
|
|
76
87
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_uuid, uuid, "f");
|
|
77
88
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_query, query, "f");
|
|
78
89
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_client, client, "f");
|
|
@@ -103,29 +114,33 @@ export class QuerySubscriptionProxy {
|
|
|
103
114
|
try {
|
|
104
115
|
// Initialize the query subscription
|
|
105
116
|
let initialResult;
|
|
106
|
-
|
|
107
|
-
initialResult = await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").perspectiveSubscribeSurrealQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
initialResult = await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
111
|
-
}
|
|
117
|
+
initialResult = await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
112
118
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_subscriptionId, initialResult.subscriptionId, "f");
|
|
113
|
-
// Process the initial result immediately for fast UX
|
|
114
|
-
|
|
119
|
+
// Process the initial result immediately for fast UX.
|
|
120
|
+
// The subscribeQuery() RPC call already returns the initial result,
|
|
121
|
+
// so treat that as successful initialization instead of waiting for a
|
|
122
|
+
// follow-up WebSocket update that may never arrive until the query changes.
|
|
123
|
+
if (initialResult.result !== undefined) {
|
|
115
124
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_latestResult, initialResult.result, "f");
|
|
116
125
|
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, initialResult.result);
|
|
126
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f")) {
|
|
127
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f").call(this, true);
|
|
128
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initResolve, undefined, "f");
|
|
129
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
130
|
+
}
|
|
117
131
|
}
|
|
118
132
|
else {
|
|
119
133
|
console.warn('⚠️ No initial result returned from subscribeQuery!');
|
|
134
|
+
// Only keep the initialization timeout when the backend did not
|
|
135
|
+
// provide an initial result up front.
|
|
136
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initTimeoutId, setTimeout(() => {
|
|
137
|
+
console.error('Subscription initialization timed out after 30 seconds. Resubscribing...');
|
|
138
|
+
// Recursively retry subscription, catching any errors
|
|
139
|
+
this.subscribe().catch(error => {
|
|
140
|
+
console.error('Error during subscription retry after timeout:', error);
|
|
141
|
+
});
|
|
142
|
+
}, 30000), "f");
|
|
120
143
|
}
|
|
121
|
-
// Set up timeout for retry
|
|
122
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initTimeoutId, setTimeout(() => {
|
|
123
|
-
console.error('Subscription initialization timed out after 30 seconds. Resubscribing...');
|
|
124
|
-
// Recursively retry subscription, catching any errors
|
|
125
|
-
this.subscribe().catch(error => {
|
|
126
|
-
console.error('Error during subscription retry after timeout:', error);
|
|
127
|
-
});
|
|
128
|
-
}, 30000), "f");
|
|
129
144
|
// Subscribe to query updates
|
|
130
145
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_unsubscribe, __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(__classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"), (updateResult) => {
|
|
131
146
|
// Clear timeout on first message
|
|
@@ -139,9 +154,6 @@ export class QuerySubscriptionProxy {
|
|
|
139
154
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initResolve, undefined, "f"); // Prevent double-resolve
|
|
140
155
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
141
156
|
}
|
|
142
|
-
// Skip duplicate init messages
|
|
143
|
-
if (updateResult.isInit && __classPrivateFieldGet(this, _QuerySubscriptionProxy_latestResult, "f"))
|
|
144
|
-
return;
|
|
145
157
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_latestResult, updateResult, "f");
|
|
146
158
|
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, updateResult);
|
|
147
159
|
}), "f");
|
|
@@ -161,12 +173,7 @@ export class QuerySubscriptionProxy {
|
|
|
161
173
|
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f"))
|
|
162
174
|
return;
|
|
163
175
|
try {
|
|
164
|
-
|
|
165
|
-
await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").perspectiveKeepAliveSurrealQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"));
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").keepAliveQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"));
|
|
169
|
-
}
|
|
176
|
+
await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").keepAliveQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"));
|
|
170
177
|
}
|
|
171
178
|
catch (e) {
|
|
172
179
|
console.error('Error in keepalive:', e);
|
|
@@ -253,7 +260,7 @@ export class QuerySubscriptionProxy {
|
|
|
253
260
|
*
|
|
254
261
|
* This method:
|
|
255
262
|
* 1. Stops the keepalive timer
|
|
256
|
-
* 2. Unsubscribes from
|
|
263
|
+
* 2. Unsubscribes from subscription updates
|
|
257
264
|
* 3. Clears all registered callbacks
|
|
258
265
|
* 4. Cleans up any pending initialization timeout
|
|
259
266
|
*
|
|
@@ -273,14 +280,8 @@ export class QuerySubscriptionProxy {
|
|
|
273
280
|
}
|
|
274
281
|
// Tell the backend to dispose of the subscription
|
|
275
282
|
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f")) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
.catch(e => console.error('Error disposing surreal query subscription:', e));
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
__classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").disposeQuerySubscription(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"))
|
|
282
|
-
.catch(e => console.error('Error disposing query subscription:', e));
|
|
283
|
-
}
|
|
283
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").disposeQuerySubscription(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"))
|
|
284
|
+
.catch(e => console.error('Error disposing query subscription:', e));
|
|
284
285
|
}
|
|
285
286
|
}
|
|
286
287
|
}
|
|
@@ -334,6 +335,8 @@ _QuerySubscriptionProxy_uuid = new WeakMap(), _QuerySubscriptionProxy_subscripti
|
|
|
334
335
|
* ```
|
|
335
336
|
*/
|
|
336
337
|
export class PerspectiveProxy {
|
|
338
|
+
/** @internal Exposed for ModelQueryBuilder subscription management */
|
|
339
|
+
get client() { return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f"); }
|
|
337
340
|
/**
|
|
338
341
|
* Creates a new PerspectiveProxy instance.
|
|
339
342
|
* Note: Don't create this directly, use ad4m.perspective.add() instead.
|
|
@@ -345,6 +348,12 @@ export class PerspectiveProxy {
|
|
|
345
348
|
_PerspectiveProxy_perspectiveLinkRemovedCallbacks.set(this, void 0);
|
|
346
349
|
_PerspectiveProxy_perspectiveLinkUpdatedCallbacks.set(this, void 0);
|
|
347
350
|
_PerspectiveProxy_perspectiveSyncStateChangeCallbacks.set(this, void 0);
|
|
351
|
+
_PerspectiveProxy_ensuredSubjectClasses.set(this, new Set()
|
|
352
|
+
/**
|
|
353
|
+
* Creates a new PerspectiveProxy instance.
|
|
354
|
+
* Note: Don't create this directly, use ad4m.perspective.add() instead.
|
|
355
|
+
*/
|
|
356
|
+
);
|
|
348
357
|
__classPrivateFieldSet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, [], "f");
|
|
349
358
|
__classPrivateFieldSet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, [], "f");
|
|
350
359
|
__classPrivateFieldSet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, [], "f");
|
|
@@ -362,6 +371,21 @@ export class PerspectiveProxy {
|
|
|
362
371
|
__classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addPerspectiveLinkUpdatedListener(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f"));
|
|
363
372
|
__classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addPerspectiveSyncStateChangeListener(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f"));
|
|
364
373
|
}
|
|
374
|
+
/** Update the proxy's internal handle and public fields in-place.
|
|
375
|
+
* Keeps the same object reference so all holders see the update. */
|
|
376
|
+
updateHandle(handle) {
|
|
377
|
+
if (handle.uuid !== __classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid) {
|
|
378
|
+
throw new Error(`PerspectiveProxy.updateHandle: UUID mismatch — proxy is bound to "${__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid}" but received handle with UUID "${handle.uuid}". ` +
|
|
379
|
+
`This would silently diverge from listeners registered under the original UUID.`);
|
|
380
|
+
}
|
|
381
|
+
__classPrivateFieldSet(this, _PerspectiveProxy_handle, handle, "f");
|
|
382
|
+
this.uuid = handle.uuid;
|
|
383
|
+
this.name = handle.name;
|
|
384
|
+
this.owners = handle.owners;
|
|
385
|
+
this.sharedUrl = handle.sharedUrl;
|
|
386
|
+
this.neighbourhood = handle.neighbourhood;
|
|
387
|
+
this.state = handle.state;
|
|
388
|
+
}
|
|
365
389
|
/**
|
|
366
390
|
* Escapes special regex characters in a string to prevent ReDoS attacks
|
|
367
391
|
* and regex injection when building dynamic regular expressions.
|
|
@@ -435,7 +459,9 @@ export class PerspectiveProxy {
|
|
|
435
459
|
* @param batchId - Optional batch ID to group this operation with others
|
|
436
460
|
*/
|
|
437
461
|
async executeAction(actions, expression, parameters, batchId) {
|
|
438
|
-
|
|
462
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").executeCommands(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, JSON.stringify(actions), expression, JSON.stringify(parameters), batchId);
|
|
463
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
464
|
+
return result;
|
|
439
465
|
}
|
|
440
466
|
/**
|
|
441
467
|
* Retrieves links from the perspective that match the given query.
|
|
@@ -488,34 +514,71 @@ export class PerspectiveProxy {
|
|
|
488
514
|
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").queryProlog(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
489
515
|
}
|
|
490
516
|
/**
|
|
491
|
-
* Executes a
|
|
492
|
-
* This allows powerful SQL-like queries on the link data stored in
|
|
517
|
+
* Executes a SPARQL query against the perspective's link cache.
|
|
518
|
+
* This allows powerful SQL-like queries on the link data stored in SPARQL.
|
|
493
519
|
*
|
|
494
520
|
* **Security Note:** Only read-only queries (SELECT, RETURN, etc.) are permitted.
|
|
495
521
|
* Mutating operations (DELETE, UPDATE, INSERT, CREATE, DROP, DEFINE, etc.) are
|
|
496
522
|
* blocked for security reasons. Use the perspective's add/remove methods to modify links.
|
|
497
523
|
*
|
|
498
|
-
* @param query -
|
|
524
|
+
* @param query - SPARQL query string (read-only operations only)
|
|
499
525
|
* @returns Query results as parsed JSON
|
|
500
526
|
*
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
*
|
|
527
|
+
* Executes a SPARQL query against the perspective's RDF (Oxigraph) store.
|
|
528
|
+
*
|
|
529
|
+
* @param query - SPARQL query string
|
|
530
|
+
* @returns Query results as parsed JSON
|
|
531
|
+
*/
|
|
532
|
+
async querySparql(query) {
|
|
533
|
+
const cached = getCachedResult(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
534
|
+
if (cached !== undefined)
|
|
535
|
+
return cached;
|
|
536
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").querySparql(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
537
|
+
setCachedResult(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query, result);
|
|
538
|
+
return result;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Execute a model query — the executor-side replacement for SPARQL query building + JS hydration.
|
|
542
|
+
*
|
|
543
|
+
* @param className - The model class name (e.g. "Recipe")
|
|
544
|
+
* @param queryJson - Structured query as JSON string
|
|
545
|
+
* @param shapeJson - Optional shape metadata JSON from the model class
|
|
546
|
+
* @returns Object with `instances` array and `totalCount`
|
|
547
|
+
*/
|
|
548
|
+
async modelQuery(className, queryJson, shapeJson) {
|
|
549
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Evaluate property getters for a batch of instances in a single RPC call.
|
|
553
|
+
* Returns a map of `{ instanceId: { prop: value, ... } }`.
|
|
554
|
+
*
|
|
555
|
+
* Use this instead of `Ad4mModel.evaluateGetters()` for lazy-loading
|
|
556
|
+
* getter-backed properties on visible items (e.g. `replyingTo` on messages).
|
|
557
|
+
*
|
|
558
|
+
* @param className - The model class name (e.g. "Message")
|
|
559
|
+
* @param instanceIds - Array of instance base expression URIs
|
|
560
|
+
* @param shapeJson - Shape metadata JSON from the model class
|
|
561
|
+
* @param propertyNames - Optional subset of property names to evaluate
|
|
562
|
+
* @returns Map of instance ID → evaluated property values
|
|
516
563
|
*/
|
|
517
|
-
async
|
|
518
|
-
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").
|
|
564
|
+
async evaluateGetters(className, instanceIds, shapeJson, propertyNames) {
|
|
565
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").evaluateGetters(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, instanceIds, shapeJson, propertyNames);
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Subscribe to model query changes. Builds trigger SPARQL from the model shape
|
|
569
|
+
* internally in Rust, registers a subscription, runs the initial query, and
|
|
570
|
+
* pushes updated results when relevant links change.
|
|
571
|
+
*
|
|
572
|
+
* The subscription reuses the same GraphQL subscription channel as subscribeQuery().
|
|
573
|
+
* Use keepAliveQuery() / disposeQuerySubscription() with the returned subscriptionId.
|
|
574
|
+
*
|
|
575
|
+
* @param className - The model class name
|
|
576
|
+
* @param queryJson - JSON-serialized query parameters (same as modelQuery)
|
|
577
|
+
* @param shapeJson - Optional shape metadata JSON from the model class
|
|
578
|
+
* @returns Object with `subscriptionId` and initial `result`
|
|
579
|
+
*/
|
|
580
|
+
async modelSubscribe(className, queryJson, shapeJson) {
|
|
581
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
|
|
519
582
|
}
|
|
520
583
|
/**
|
|
521
584
|
* Adds a new link to the perspective.
|
|
@@ -543,7 +606,9 @@ export class PerspectiveProxy {
|
|
|
543
606
|
* ```
|
|
544
607
|
*/
|
|
545
608
|
async add(link, status = 'shared', batchId) {
|
|
546
|
-
|
|
609
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addLink(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, link, status, batchId);
|
|
610
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
611
|
+
return result;
|
|
547
612
|
}
|
|
548
613
|
/**
|
|
549
614
|
* Adds multiple links to the perspective in a single operation.
|
|
@@ -555,7 +620,9 @@ export class PerspectiveProxy {
|
|
|
555
620
|
* @returns Array of created LinkExpressions
|
|
556
621
|
*/
|
|
557
622
|
async addLinks(links, status = 'shared', batchId) {
|
|
558
|
-
|
|
623
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addLinks(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, links, status, batchId);
|
|
624
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
625
|
+
return result;
|
|
559
626
|
}
|
|
560
627
|
/**
|
|
561
628
|
* Removes multiple links from the perspective.
|
|
@@ -565,7 +632,9 @@ export class PerspectiveProxy {
|
|
|
565
632
|
* @returns Array of removed LinkExpressions
|
|
566
633
|
*/
|
|
567
634
|
async removeLinks(links, batchId) {
|
|
568
|
-
|
|
635
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").removeLinks(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, links, batchId);
|
|
636
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
637
|
+
return result;
|
|
569
638
|
}
|
|
570
639
|
/**
|
|
571
640
|
* Applies a set of link mutations (adds and removes) in a single operation.
|
|
@@ -576,7 +645,9 @@ export class PerspectiveProxy {
|
|
|
576
645
|
* @returns Object containing results of the mutations
|
|
577
646
|
*/
|
|
578
647
|
async linkMutations(mutations, status = 'shared') {
|
|
579
|
-
|
|
648
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").linkMutations(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, mutations, status);
|
|
649
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
650
|
+
return result;
|
|
580
651
|
}
|
|
581
652
|
/**
|
|
582
653
|
* Adds a pre-signed LinkExpression to the perspective.
|
|
@@ -597,7 +668,9 @@ export class PerspectiveProxy {
|
|
|
597
668
|
* @param batchId - Optional batch ID to group this operation with others
|
|
598
669
|
*/
|
|
599
670
|
async update(oldLink, newLink, batchId) {
|
|
600
|
-
|
|
671
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").updateLink(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, oldLink, newLink, batchId);
|
|
672
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
673
|
+
return result;
|
|
601
674
|
}
|
|
602
675
|
/**
|
|
603
676
|
* Removes a link from the perspective.
|
|
@@ -606,7 +679,9 @@ export class PerspectiveProxy {
|
|
|
606
679
|
* @param batchId - Optional batch ID to group this operation with others
|
|
607
680
|
*/
|
|
608
681
|
async remove(link, batchId) {
|
|
609
|
-
|
|
682
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").removeLink(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, link, batchId);
|
|
683
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
684
|
+
return result;
|
|
610
685
|
}
|
|
611
686
|
/** Creates a new batch for grouping operations */
|
|
612
687
|
async createBatch() {
|
|
@@ -614,7 +689,9 @@ export class PerspectiveProxy {
|
|
|
614
689
|
}
|
|
615
690
|
/** Commits a batch of operations */
|
|
616
691
|
async commitBatch(batchId) {
|
|
617
|
-
|
|
692
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").commitBatch(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, batchId);
|
|
693
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
694
|
+
return result;
|
|
618
695
|
}
|
|
619
696
|
/**
|
|
620
697
|
* Retrieves and renders an Expression referenced in this perspective.
|
|
@@ -689,17 +766,30 @@ export class PerspectiveProxy {
|
|
|
689
766
|
async removeListener(type, cb) {
|
|
690
767
|
if (type === 'link-added') {
|
|
691
768
|
const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").indexOf(cb);
|
|
692
|
-
|
|
769
|
+
if (index >= 0)
|
|
770
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").splice(index, 1);
|
|
693
771
|
}
|
|
694
772
|
else if (type === 'link-removed') {
|
|
695
773
|
const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").indexOf(cb);
|
|
696
|
-
|
|
774
|
+
if (index >= 0)
|
|
775
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").splice(index, 1);
|
|
697
776
|
}
|
|
698
777
|
else if (type === 'link-updated') {
|
|
699
778
|
const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").indexOf(cb);
|
|
700
|
-
|
|
779
|
+
if (index >= 0)
|
|
780
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").splice(index, 1);
|
|
701
781
|
}
|
|
702
782
|
}
|
|
783
|
+
/** Clean up all subscriptions registered by this proxy.
|
|
784
|
+
* Call this when the proxy is no longer needed to prevent subscription leaks.
|
|
785
|
+
* After calling dispose(), the proxy should not be used. */
|
|
786
|
+
dispose() {
|
|
787
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_client, "f").removeAllListeners(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
788
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").length = 0;
|
|
789
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").length = 0;
|
|
790
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").length = 0;
|
|
791
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f").length = 0;
|
|
792
|
+
}
|
|
703
793
|
/**
|
|
704
794
|
* Creates a snapshot of the current perspective state.
|
|
705
795
|
* Useful for backup or sharing.
|
|
@@ -970,7 +1060,7 @@ export class PerspectiveProxy {
|
|
|
970
1060
|
* Adds Social DNA code to the perspective.
|
|
971
1061
|
*
|
|
972
1062
|
* **Recommended:** Use {@link addShacl} instead, which accepts the `SHACLShape` type directly.
|
|
973
|
-
* This method is primarily for the
|
|
1063
|
+
* This method is primarily for the RPC API layer and legacy Prolog code.
|
|
974
1064
|
*
|
|
975
1065
|
* @param name - Unique name for this SDNA definition
|
|
976
1066
|
* @param sdnaCode - Prolog SDNA code (legacy, can be empty string if shaclJson provided)
|
|
@@ -989,6 +1079,47 @@ export class PerspectiveProxy {
|
|
|
989
1079
|
async addSdna(name, sdnaCode, sdnaType, shaclJson) {
|
|
990
1080
|
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addSdna(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, name, sdnaCode, sdnaType, shaclJson);
|
|
991
1081
|
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Batch variant of addSdna — registers multiple SDNA entries in a single RPC call.
|
|
1084
|
+
* Acquires the Rust-side mutex once for the entire batch.
|
|
1085
|
+
*/
|
|
1086
|
+
async addSdnaAll(entries) {
|
|
1087
|
+
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addSdnaBatch(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, entries);
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* Batch-registers multiple model classes as SHACL subject classes in a single RPC call.
|
|
1091
|
+
* Skips classes already registered on this perspective instance.
|
|
1092
|
+
*/
|
|
1093
|
+
async ensureSubjectClasses(jsClasses) {
|
|
1094
|
+
const entries = [];
|
|
1095
|
+
for (const jsClass of jsClasses) {
|
|
1096
|
+
const className = jsClass.className || jsClass.prototype?.className || jsClass.name;
|
|
1097
|
+
if (__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").has(className))
|
|
1098
|
+
continue;
|
|
1099
|
+
if (!jsClass.generateSHACL) {
|
|
1100
|
+
throw new Error(`Class ${jsClass.name} must have generateSHACL(). Use @Model decorator.`);
|
|
1101
|
+
}
|
|
1102
|
+
const { shape } = jsClass.generateSHACL();
|
|
1103
|
+
entries.push({
|
|
1104
|
+
name: className,
|
|
1105
|
+
sdnaType: 'subject_class',
|
|
1106
|
+
shaclJson: JSON.stringify(shape.toJSON()),
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
if (entries.length === 0)
|
|
1110
|
+
return;
|
|
1111
|
+
await this.addSdnaAll(entries);
|
|
1112
|
+
for (const entry of entries) {
|
|
1113
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").add(entry.name);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Adds a subject class to the perspective.
|
|
1118
|
+
* Alias for addSdna() with sdnaType='subject_class'.
|
|
1119
|
+
*/
|
|
1120
|
+
async addSubjectClass(name, shaclJson) {
|
|
1121
|
+
return this.addSdna(name, '', 'subject_class', shaclJson);
|
|
1122
|
+
}
|
|
992
1123
|
/**
|
|
993
1124
|
* **Recommended way to add SDNA schemas.**
|
|
994
1125
|
*
|
|
@@ -1020,7 +1151,7 @@ export class PerspectiveProxy {
|
|
|
1020
1151
|
// Serialize shape to links
|
|
1021
1152
|
const shapeLinks = shape.toLinks();
|
|
1022
1153
|
// Create name -> shape mapping links
|
|
1023
|
-
const nameMapping = Literal.fromUrl(`literal
|
|
1154
|
+
const nameMapping = Literal.fromUrl(`literal:string:shacl://${name}`);
|
|
1024
1155
|
const allLinks = [
|
|
1025
1156
|
...shapeLinks.map(l => new Link({
|
|
1026
1157
|
source: l.source,
|
|
@@ -1046,7 +1177,7 @@ export class PerspectiveProxy {
|
|
|
1046
1177
|
*/
|
|
1047
1178
|
async getShacl(name) {
|
|
1048
1179
|
// Find the shape URI from the name mapping
|
|
1049
|
-
const nameMapping = Literal.fromUrl(`literal
|
|
1180
|
+
const nameMapping = Literal.fromUrl(`literal:string:shacl://${name}`);
|
|
1050
1181
|
const shapeUriLinks = await this.get(new LinkQuery({
|
|
1051
1182
|
source: nameMapping.toUrl(),
|
|
1052
1183
|
predicate: "ad4m://shacl_shape_uri"
|
|
@@ -1055,22 +1186,25 @@ export class PerspectiveProxy {
|
|
|
1055
1186
|
return null;
|
|
1056
1187
|
}
|
|
1057
1188
|
const shapeUri = shapeUriLinks[0].data.target;
|
|
1058
|
-
const escapedShapeUri = escapeSurrealString(shapeUri);
|
|
1059
1189
|
// First get property shape URIs so we can query everything in one go
|
|
1060
1190
|
const propertyLinks = await this.get(new LinkQuery({
|
|
1061
1191
|
source: shapeUri,
|
|
1062
1192
|
predicate: "sh://property"
|
|
1063
1193
|
}));
|
|
1064
|
-
//
|
|
1194
|
+
// Fetch all links from the shape and its property shapes
|
|
1065
1195
|
const sourceUris = [shapeUri, ...propertyLinks.map(l => l.data.target)];
|
|
1066
|
-
const
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1196
|
+
const allLinks = [];
|
|
1197
|
+
for (const uri of sourceUris) {
|
|
1198
|
+
const links = await this.get(new LinkQuery({ source: uri }));
|
|
1199
|
+
for (const l of links) {
|
|
1200
|
+
allLinks.push({
|
|
1201
|
+
source: l.data.source,
|
|
1202
|
+
predicate: l.data.predicate,
|
|
1203
|
+
target: l.data.target
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
const shapeLinks = allLinks;
|
|
1074
1208
|
return SHACLShape.fromLinks(shapeLinks, shapeUri);
|
|
1075
1209
|
}
|
|
1076
1210
|
/**
|
|
@@ -1172,19 +1306,20 @@ export class PerspectiveProxy {
|
|
|
1172
1306
|
return null;
|
|
1173
1307
|
}
|
|
1174
1308
|
const flowUri = flowUriLinks[0].data.target;
|
|
1175
|
-
const escapedFlowUri = escapeSurrealString(flowUri);
|
|
1176
1309
|
// Compute alternate prefix for state/transition URIs
|
|
1177
1310
|
const alternatePrefix = flowUri.endsWith('Flow')
|
|
1178
1311
|
? flowUri.slice(0, -4) + '.'
|
|
1179
1312
|
: flowUri + '.';
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1313
|
+
// Fetch flow links using SPARQL to match flowUri source OR alternatePrefix sources
|
|
1314
|
+
const sparqlQuery = `SELECT ?s ?p ?o WHERE {
|
|
1315
|
+
?s ?p ?o .
|
|
1316
|
+
FILTER(?s = <${flowUri}> || STRSTARTS(STR(?s), "${alternatePrefix}"))
|
|
1317
|
+
}`;
|
|
1318
|
+
const sparqlResult = await this.querySparql(sparqlQuery);
|
|
1319
|
+
const flowLinks = (sparqlResult || []).map((r) => ({
|
|
1320
|
+
source: r.s,
|
|
1321
|
+
predicate: r.p,
|
|
1322
|
+
target: r.o
|
|
1188
1323
|
}));
|
|
1189
1324
|
return SHACLFlow.fromLinks(flowLinks, flowUri);
|
|
1190
1325
|
}
|
|
@@ -1194,7 +1329,7 @@ export class PerspectiveProxy {
|
|
|
1194
1329
|
*/
|
|
1195
1330
|
async subjectClasses() {
|
|
1196
1331
|
try {
|
|
1197
|
-
// Query SHACL class links directly — no need for a separate
|
|
1332
|
+
// Query SHACL class links directly — no need for a separate RPC endpoint
|
|
1198
1333
|
const classLinks = await this.get(new LinkQuery({
|
|
1199
1334
|
predicate: "rdf://type",
|
|
1200
1335
|
target: "ad4m://SubjectClass"
|
|
@@ -1267,7 +1402,9 @@ export class PerspectiveProxy {
|
|
|
1267
1402
|
if (batchId) {
|
|
1268
1403
|
return exprAddr;
|
|
1269
1404
|
}
|
|
1270
|
-
|
|
1405
|
+
// Return the expression address directly — callers should use Ad4mModel or
|
|
1406
|
+
// getSubjectData() to interact with the created instance.
|
|
1407
|
+
return exprAddr;
|
|
1271
1408
|
}
|
|
1272
1409
|
async getSubjectData(subjectClass, exprAddr) {
|
|
1273
1410
|
if (typeof subjectClass === "string") {
|
|
@@ -1293,8 +1430,8 @@ export class PerspectiveProxy {
|
|
|
1293
1430
|
const links = await this.get(new LinkQuery({ predicate }));
|
|
1294
1431
|
for (const link of links) {
|
|
1295
1432
|
if (shapePattern.test(link.data.source)) {
|
|
1296
|
-
// Parse actions from literal
|
|
1297
|
-
const prefix = "literal
|
|
1433
|
+
// Parse actions from literal:string:{json}
|
|
1434
|
+
const prefix = "literal:string:";
|
|
1298
1435
|
if (link.data.target.startsWith(prefix)) {
|
|
1299
1436
|
const jsonStr = link.data.target.slice(prefix.length);
|
|
1300
1437
|
// Decode URL-encoded JSON if needed, with fallback for raw % characters
|
|
@@ -1343,70 +1480,29 @@ export class PerspectiveProxy {
|
|
|
1343
1480
|
async isSubjectInstance(expression, subjectClass) {
|
|
1344
1481
|
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
|
|
1345
1482
|
// Get metadata from SHACL links
|
|
1346
|
-
const metadata = await this.
|
|
1483
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1347
1484
|
if (!metadata) {
|
|
1348
1485
|
console.warn(`isSubjectInstance: No SHACL metadata found for class ${className}`);
|
|
1349
1486
|
return false;
|
|
1350
1487
|
}
|
|
1351
1488
|
// If no required triples, any expression with links is an instance
|
|
1352
1489
|
if (metadata.requiredTriples.length === 0) {
|
|
1353
|
-
const
|
|
1354
|
-
|
|
1355
|
-
const result = await this.querySurrealDB(checkQuery);
|
|
1356
|
-
const count = result[0]?.count ?? 0;
|
|
1357
|
-
const countValue = typeof count === 'object' && count?.Int !== undefined ? count.Int : count;
|
|
1358
|
-
return countValue > 0;
|
|
1359
|
-
}
|
|
1360
|
-
// Check if the expression has all required triples (predicate + optional exact target)
|
|
1361
|
-
for (const triple of metadata.requiredTriples) {
|
|
1362
|
-
const escapedExpression = escapeSurrealString(expression);
|
|
1363
|
-
const escapedPredicate = escapeSurrealString(triple.predicate);
|
|
1364
|
-
let checkQuery;
|
|
1365
|
-
if (triple.target) {
|
|
1366
|
-
// Flag: must match both predicate AND exact target value
|
|
1367
|
-
const escapedTarget = escapeSurrealString(triple.target);
|
|
1368
|
-
checkQuery = `SELECT count() AS count FROM link WHERE in.uri = '${escapedExpression}' AND predicate = '${escapedPredicate}' AND out.uri = '${escapedTarget}'`;
|
|
1369
|
-
}
|
|
1370
|
-
else {
|
|
1371
|
-
// Property: just check predicate exists
|
|
1372
|
-
checkQuery = `SELECT count() AS count FROM link WHERE in.uri = '${escapedExpression}' AND predicate = '${escapedPredicate}'`;
|
|
1373
|
-
}
|
|
1374
|
-
const result = await this.querySurrealDB(checkQuery);
|
|
1375
|
-
if (!result || result.length === 0) {
|
|
1376
|
-
return false;
|
|
1377
|
-
}
|
|
1378
|
-
const count = result[0]?.count ?? 0;
|
|
1379
|
-
// Handle potential object response like {Int: 0}
|
|
1380
|
-
const countValue = typeof count === 'object' && count?.Int !== undefined ? count.Int : count;
|
|
1381
|
-
if (countValue === 0) {
|
|
1382
|
-
return false;
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
return true;
|
|
1386
|
-
}
|
|
1387
|
-
/** For an existing subject instance (existing in the perspective's links)
|
|
1388
|
-
* this function returns a proxy object that can be used to access the subject's
|
|
1389
|
-
* properties and methods.
|
|
1390
|
-
*
|
|
1391
|
-
* @param base URI of the subject's root expression
|
|
1392
|
-
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
1393
|
-
* with the properties of the subject class. In the latter case, the first subject class
|
|
1394
|
-
* that matches the given properties will be used.
|
|
1395
|
-
*/
|
|
1396
|
-
async getSubjectProxy(base, subjectClass) {
|
|
1397
|
-
if (!await this.isSubjectInstance(base, subjectClass)) {
|
|
1398
|
-
throw `Expression ${base} is not a subject instance of given class: ${JSON.stringify(subjectClass)}`;
|
|
1490
|
+
const links = await this.get(new LinkQuery({ source: expression }));
|
|
1491
|
+
return links.length > 0;
|
|
1399
1492
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1493
|
+
// Build a single SPARQL ASK query with all required triple patterns
|
|
1494
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1495
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1496
|
+
return `<${expression}> <${t.predicate}> ${target} .`;
|
|
1497
|
+
}).join('\n ');
|
|
1498
|
+
const result = await this.querySparql(`ASK WHERE {\n ${patterns}\n}`);
|
|
1499
|
+
return result === true;
|
|
1404
1500
|
}
|
|
1405
1501
|
/**
|
|
1406
1502
|
* Gets subject class metadata from SHACL links using SHACLShape.fromLinks().
|
|
1407
1503
|
* Retrieves the SHACL shape and extracts metadata for instance queries.
|
|
1408
1504
|
*/
|
|
1409
|
-
async
|
|
1505
|
+
async getSubjectClassMetadata(className) {
|
|
1410
1506
|
try {
|
|
1411
1507
|
// Use getShacl() to retrieve the shape via SHACLShape.fromLinks()
|
|
1412
1508
|
const shape = await this.getShacl(className);
|
|
@@ -1460,193 +1556,28 @@ export class PerspectiveProxy {
|
|
|
1460
1556
|
}
|
|
1461
1557
|
}
|
|
1462
1558
|
/**
|
|
1463
|
-
* Generates a
|
|
1559
|
+
* Generates a SPARQL query to find instances based on class metadata.
|
|
1464
1560
|
*/
|
|
1465
|
-
generateSurrealInstanceQuery(metadata) {
|
|
1466
|
-
if (metadata.requiredTriples.length === 0) {
|
|
1467
|
-
// No required triples - any node with links is an instance
|
|
1468
|
-
return `SELECT DISTINCT uri AS base FROM node WHERE count(->link) > 0`;
|
|
1469
|
-
}
|
|
1470
|
-
// Generate WHERE conditions for each required triple (predicate + optional exact target)
|
|
1471
|
-
const whereConditions = metadata.requiredTriples.map(triple => {
|
|
1472
|
-
const escapedPredicate = escapeSurrealString(triple.predicate);
|
|
1473
|
-
if (triple.target) {
|
|
1474
|
-
// Flag: must match both predicate AND exact target value
|
|
1475
|
-
const escapedTarget = escapeSurrealString(triple.target);
|
|
1476
|
-
return `count(->link[WHERE predicate = '${escapedPredicate}' AND out.uri = '${escapedTarget}']) > 0`;
|
|
1477
|
-
}
|
|
1478
|
-
else {
|
|
1479
|
-
// Property: just check predicate exists
|
|
1480
|
-
return `count(->link[WHERE predicate = '${escapedPredicate}']) > 0`;
|
|
1481
|
-
}
|
|
1482
|
-
}).join(' AND ');
|
|
1483
|
-
return `SELECT uri AS base FROM node WHERE ${whereConditions}`;
|
|
1484
|
-
}
|
|
1485
1561
|
/**
|
|
1486
|
-
*
|
|
1487
|
-
*
|
|
1562
|
+
* Finds all instances matching subject class metadata by querying links.
|
|
1563
|
+
* Returns base URIs of matching instances.
|
|
1488
1564
|
*/
|
|
1489
|
-
async
|
|
1490
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1491
|
-
if (!metadata) {
|
|
1492
|
-
return undefined;
|
|
1493
|
-
}
|
|
1494
|
-
const propMeta = metadata.properties.get(propertyName);
|
|
1495
|
-
if (!propMeta) {
|
|
1496
|
-
return undefined;
|
|
1497
|
-
}
|
|
1498
|
-
const escapedBaseExpression = escapeSurrealString(baseExpression);
|
|
1499
|
-
const escapedPredicate = escapeSurrealString(propMeta.predicate);
|
|
1500
|
-
const query = `SELECT out.uri AS value FROM link WHERE in.uri = '${escapedBaseExpression}' AND predicate = '${escapedPredicate}' LIMIT 1`;
|
|
1501
|
-
const result = await this.querySurrealDB(query);
|
|
1502
|
-
if (!result || result.length === 0) {
|
|
1503
|
-
return undefined;
|
|
1504
|
-
}
|
|
1505
|
-
const value = result[0].value;
|
|
1506
|
-
// Handle expression resolution if needed
|
|
1507
|
-
if (propMeta.resolveLanguage && value) {
|
|
1508
|
-
try {
|
|
1509
|
-
const expression = await this.getExpression(value);
|
|
1510
|
-
try {
|
|
1511
|
-
return JSON.parse(expression.data);
|
|
1512
|
-
}
|
|
1513
|
-
catch (e) {
|
|
1514
|
-
return expression.data;
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
catch (err) {
|
|
1518
|
-
return value;
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
return value;
|
|
1522
|
-
}
|
|
1523
|
-
/**
|
|
1524
|
-
* Gets relation values using SurrealDB when Prolog fails.
|
|
1525
|
-
* This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
|
|
1526
|
-
* Note: This is used by Subject.ts (legacy pattern). Ad4mModel.ts uses getModelMetadata() instead.
|
|
1527
|
-
*/
|
|
1528
|
-
async getRelationValuesViaSurreal(baseExpression, className, relationName) {
|
|
1529
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1530
|
-
if (!metadata) {
|
|
1531
|
-
return [];
|
|
1532
|
-
}
|
|
1533
|
-
const relMeta = metadata.relations.get(relationName);
|
|
1534
|
-
if (!relMeta) {
|
|
1535
|
-
return [];
|
|
1536
|
-
}
|
|
1537
|
-
const escapedBaseExpression = escapeSurrealString(baseExpression);
|
|
1538
|
-
const escapedPredicate = escapeSurrealString(relMeta.predicate);
|
|
1539
|
-
const query = `SELECT out.uri AS value, timestamp FROM link WHERE in.uri = '${escapedBaseExpression}' AND predicate = '${escapedPredicate}' ORDER BY timestamp ASC`;
|
|
1540
|
-
const result = await this.querySurrealDB(query);
|
|
1541
|
-
if (!result || result.length === 0) {
|
|
1542
|
-
return [];
|
|
1543
|
-
}
|
|
1544
|
-
let values = result.map(r => r.value).filter(v => v !== "" && v !== '');
|
|
1545
|
-
// Apply condition filtering if present
|
|
1546
|
-
if (relMeta.condition && values.length > 0) {
|
|
1547
|
-
try {
|
|
1548
|
-
const filteredValues = [];
|
|
1549
|
-
for (const value of values) {
|
|
1550
|
-
let condition = relMeta.condition
|
|
1551
|
-
.replace(/\$perspective/g, `'${this.uuid}'`)
|
|
1552
|
-
.replace(/\$base/g, `'${baseExpression}'`)
|
|
1553
|
-
.replace(/Target/g, `'${value.replace(/'/g, "\\'")}'`);
|
|
1554
|
-
// If condition starts with WHERE, wrap in array length check
|
|
1555
|
-
if (condition.trim().startsWith('WHERE')) {
|
|
1556
|
-
condition = `array::len(SELECT * FROM link ${condition}) > 0`;
|
|
1557
|
-
}
|
|
1558
|
-
const filterResult = await this.querySurrealDB(`RETURN ${condition}`);
|
|
1559
|
-
const isTrue = filterResult === true || (Array.isArray(filterResult) && filterResult.length > 0 && filterResult[0] === true);
|
|
1560
|
-
if (isTrue) {
|
|
1561
|
-
filteredValues.push(value);
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
values = filteredValues;
|
|
1565
|
-
}
|
|
1566
|
-
catch (error) {
|
|
1567
|
-
console.warn(`Failed to apply condition filter for ${relationName}:`, error);
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
// Apply instance filter if present - batch-check all values at once
|
|
1571
|
-
if (relMeta.instanceFilter) {
|
|
1572
|
-
try {
|
|
1573
|
-
const filterMetadata = await this.getSubjectClassMetadataFromSDNA(relMeta.instanceFilter);
|
|
1574
|
-
if (!filterMetadata) {
|
|
1575
|
-
// Fallback to sequential checks if metadata isn't available
|
|
1576
|
-
return this.filterInstancesSequential(values, relMeta.instanceFilter);
|
|
1577
|
-
}
|
|
1578
|
-
return await this.batchCheckSubjectInstances(values, filterMetadata);
|
|
1579
|
-
}
|
|
1580
|
-
catch (err) {
|
|
1581
|
-
// Fallback to sequential checks on error
|
|
1582
|
-
return this.filterInstancesSequential(values, relMeta.instanceFilter);
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
return values;
|
|
1586
|
-
}
|
|
1587
|
-
/**
|
|
1588
|
-
* Batch-checks multiple expressions against subject class metadata using a single or limited SurrealDB queries.
|
|
1589
|
-
* This avoids N+1 query problems by checking all values at once.
|
|
1590
|
-
*/
|
|
1591
|
-
async batchCheckSubjectInstances(expressions, metadata) {
|
|
1592
|
-
if (expressions.length === 0) {
|
|
1593
|
-
return [];
|
|
1594
|
-
}
|
|
1595
|
-
// If no required triples, check which expressions have any links
|
|
1565
|
+
async findInstancesByMetadata(metadata) {
|
|
1596
1566
|
if (metadata.requiredTriples.length === 0) {
|
|
1597
|
-
|
|
1598
|
-
const
|
|
1599
|
-
const
|
|
1600
|
-
return
|
|
1601
|
-
}
|
|
1602
|
-
//
|
|
1603
|
-
const
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
// Note: Removed GROUP BY because it was causing SurrealDB to only return one result
|
|
1612
|
-
checkQuery = `SELECT in.uri AS uri FROM link WHERE in.uri IN [${escapedExpressions}] AND predicate = '${escapedPredicate}' AND out.uri = '${escapedTarget}'`;
|
|
1613
|
-
}
|
|
1614
|
-
else {
|
|
1615
|
-
// Property: just check predicate exists
|
|
1616
|
-
// Note: Removed GROUP BY because it was causing SurrealDB to only return one result
|
|
1617
|
-
checkQuery = `SELECT in.uri AS uri FROM link WHERE in.uri IN [${escapedExpressions}] AND predicate = '${escapedPredicate}'`;
|
|
1618
|
-
}
|
|
1619
|
-
const result = await this.querySurrealDB(checkQuery);
|
|
1620
|
-
validExpressionSets.push(new Set(result.map(r => r.uri)));
|
|
1621
|
-
}
|
|
1622
|
-
// Find intersection: expressions that passed ALL required triple checks
|
|
1623
|
-
if (validExpressionSets.length === 0) {
|
|
1624
|
-
return expressions;
|
|
1625
|
-
}
|
|
1626
|
-
const firstSet = validExpressionSets[0];
|
|
1627
|
-
const validExpressions = expressions.filter(expr => {
|
|
1628
|
-
return validExpressionSets.every(set => set.has(expr));
|
|
1629
|
-
});
|
|
1630
|
-
return validExpressions;
|
|
1631
|
-
}
|
|
1632
|
-
/**
|
|
1633
|
-
* Fallback sequential instance checking when batch checking isn't available.
|
|
1634
|
-
*/
|
|
1635
|
-
async filterInstancesSequential(values, instanceFilter) {
|
|
1636
|
-
const filteredValues = [];
|
|
1637
|
-
for (const value of values) {
|
|
1638
|
-
try {
|
|
1639
|
-
const isInstance = await this.isSubjectInstance(value, instanceFilter);
|
|
1640
|
-
if (isInstance) {
|
|
1641
|
-
filteredValues.push(value);
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
catch (err) {
|
|
1645
|
-
// Skip values that fail instance check
|
|
1646
|
-
continue;
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
return filteredValues;
|
|
1567
|
+
// No required triples - return all unique sources that have any link
|
|
1568
|
+
const allLinks = await this.get(new LinkQuery({}));
|
|
1569
|
+
const sources = new Set(allLinks.map(l => l.data.source));
|
|
1570
|
+
return Array.from(sources).map(s => ({ base: s }));
|
|
1571
|
+
}
|
|
1572
|
+
// Build a single SPARQL SELECT with all required triple patterns joined
|
|
1573
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1574
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1575
|
+
return `?base <${t.predicate}> ${target} .`;
|
|
1576
|
+
}).join('\n ');
|
|
1577
|
+
const results = await this.querySparql(`SELECT DISTINCT ?base WHERE {\n ${patterns}\n}`);
|
|
1578
|
+
if (!Array.isArray(results))
|
|
1579
|
+
return [];
|
|
1580
|
+
return results.map((row) => ({ base: row.base }));
|
|
1650
1581
|
}
|
|
1651
1582
|
/** Returns all subject instances of the given subject class as proxy objects.
|
|
1652
1583
|
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
@@ -1670,13 +1601,12 @@ export class PerspectiveProxy {
|
|
|
1670
1601
|
let instances = [];
|
|
1671
1602
|
for (let className of classes) {
|
|
1672
1603
|
//console.log(`getAllSubjectInstances: Processing class ${className}`);
|
|
1673
|
-
// Query SDNA for metadata, then query
|
|
1674
|
-
const metadata = await this.
|
|
1604
|
+
// Query SDNA for metadata, then query SPARQL for instances
|
|
1605
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1675
1606
|
//console.log(`getAllSubjectInstances: Got metadata for ${className}:`, metadata);
|
|
1676
1607
|
if (metadata) {
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
// console.log(`getAllSubjectInstances: SurrealDB returned ${results?.length || 0} results`);
|
|
1608
|
+
const results = await this.findInstancesByMetadata(metadata);
|
|
1609
|
+
// console.log(`getAllSubjectInstances: SPARQL returned ${results?.length || 0} results`);
|
|
1680
1610
|
for (const result of results || []) {
|
|
1681
1611
|
//console.log(`getAllSubjectInstances: Creating subject for base ${result.base}`);
|
|
1682
1612
|
try {
|
|
@@ -1689,9 +1619,9 @@ export class PerspectiveProxy {
|
|
|
1689
1619
|
await instance.get();
|
|
1690
1620
|
}
|
|
1691
1621
|
else {
|
|
1692
|
-
//
|
|
1693
|
-
|
|
1694
|
-
|
|
1622
|
+
// Return plain data for string-based lookups
|
|
1623
|
+
const data = await this.getSubjectData(className, result.base);
|
|
1624
|
+
instance = { id: result.base, ...data };
|
|
1695
1625
|
}
|
|
1696
1626
|
instances.push(instance);
|
|
1697
1627
|
//console.log(`getAllSubjectInstances: Successfully created subject for ${result.base}`);
|
|
@@ -1708,40 +1638,6 @@ export class PerspectiveProxy {
|
|
|
1708
1638
|
//console.log(`getAllSubjectInstances: Returning ${instances.length} instances`);
|
|
1709
1639
|
return instances;
|
|
1710
1640
|
}
|
|
1711
|
-
/** Returns all subject proxies of the given subject class as proxy objects.
|
|
1712
|
-
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
1713
|
-
* with the properties of the subject class. In the latter case, all subject classes
|
|
1714
|
-
* that match the given properties will be used.
|
|
1715
|
-
*/
|
|
1716
|
-
async getAllSubjectProxies(subjectClass) {
|
|
1717
|
-
let classes = [];
|
|
1718
|
-
if (typeof subjectClass === "string") {
|
|
1719
|
-
classes = [subjectClass];
|
|
1720
|
-
}
|
|
1721
|
-
else {
|
|
1722
|
-
classes = await this.subjectClassesByTemplate(subjectClass);
|
|
1723
|
-
}
|
|
1724
|
-
let instances = [];
|
|
1725
|
-
for (let className of classes) {
|
|
1726
|
-
// Query SDNA for metadata, then query SurrealDB for instances
|
|
1727
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1728
|
-
if (metadata) {
|
|
1729
|
-
const surrealQuery = this.generateSurrealInstanceQuery(metadata);
|
|
1730
|
-
const results = await this.querySurrealDB(surrealQuery);
|
|
1731
|
-
for (const result of results || []) {
|
|
1732
|
-
try {
|
|
1733
|
-
let subject = new Subject(this, result.base, className);
|
|
1734
|
-
await subject.init();
|
|
1735
|
-
instances.push(subject);
|
|
1736
|
-
}
|
|
1737
|
-
catch (e) {
|
|
1738
|
-
// Skip subjects that fail to initialize
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
return instances;
|
|
1744
|
-
}
|
|
1745
1641
|
/**
|
|
1746
1642
|
* Find a subject class by matching an object's properties/relations against SHACL shapes.
|
|
1747
1643
|
* Queries SHACL links client-side to find a class whose properties contain all required ones.
|
|
@@ -1772,22 +1668,24 @@ export class PerspectiveProxy {
|
|
|
1772
1668
|
if (properties.length === 0 && relations.length === 0) {
|
|
1773
1669
|
return null;
|
|
1774
1670
|
}
|
|
1775
|
-
// Single
|
|
1776
|
-
const
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1671
|
+
// Single SPARQL query to get all class shapes with their properties and collections
|
|
1672
|
+
const results = await this.querySparql(`
|
|
1673
|
+
SELECT ?shape ?predicate ?target WHERE {
|
|
1674
|
+
{ ?shape <rdf://type> <ad4m://SubjectClass> . BIND(<rdf://type> AS ?predicate) BIND(<ad4m://SubjectClass> AS ?target) }
|
|
1675
|
+
UNION
|
|
1676
|
+
{ ?shape <sh://property> ?target . BIND(<sh://property> AS ?predicate) }
|
|
1677
|
+
UNION
|
|
1678
|
+
{ ?shape <sh://collection> ?target . BIND(<sh://collection> AS ?predicate) }
|
|
1679
|
+
}
|
|
1680
|
+
`);
|
|
1681
|
+
if (!Array.isArray(results) || results.length === 0)
|
|
1784
1682
|
return null;
|
|
1785
1683
|
// Build a map of className -> { properties, relations }
|
|
1786
1684
|
const classShapes = new Map();
|
|
1787
1685
|
// First pass: find all subject classes
|
|
1788
1686
|
for (const r of results) {
|
|
1789
1687
|
if (r.predicate === 'rdf://type' && r.target === 'ad4m://SubjectClass') {
|
|
1790
|
-
const source = r.
|
|
1688
|
+
const source = r.shape;
|
|
1791
1689
|
const sepIdx = source.indexOf('://');
|
|
1792
1690
|
if (sepIdx < 0)
|
|
1793
1691
|
continue;
|
|
@@ -1802,7 +1700,7 @@ export class PerspectiveProxy {
|
|
|
1802
1700
|
if (r.predicate === 'sh://property' || r.predicate === 'sh://collection') {
|
|
1803
1701
|
// Match shape source to class (e.g., "recipe://RecipeShape" -> "Recipe")
|
|
1804
1702
|
for (const [className, shape] of classShapes) {
|
|
1805
|
-
if (r.
|
|
1703
|
+
if (r.shape.endsWith(`${className}Shape`)) {
|
|
1806
1704
|
const dotIdx = r.target.lastIndexOf('.');
|
|
1807
1705
|
if (dotIdx < 0)
|
|
1808
1706
|
continue;
|
|
@@ -1878,8 +1776,15 @@ export class PerspectiveProxy {
|
|
|
1878
1776
|
* static generateSDNA() function and adds it to the perspective's SDNA.
|
|
1879
1777
|
*/
|
|
1880
1778
|
async ensureSDNASubjectClass(jsClass) {
|
|
1779
|
+
return this.ensureSubjectClass(jsClass);
|
|
1780
|
+
}
|
|
1781
|
+
/** Takes a JS class (its constructor) and ensures the SHACL subject class exists. */
|
|
1782
|
+
async ensureSubjectClass(jsClass) {
|
|
1881
1783
|
// Get the class name from the JS class
|
|
1882
1784
|
const className = jsClass.className || jsClass.prototype?.className || jsClass.name;
|
|
1785
|
+
// Skip if already registered for this perspective instance
|
|
1786
|
+
if (__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").has(className))
|
|
1787
|
+
return;
|
|
1883
1788
|
// Note: Duplicate checking is handled on the Rust side in add_sdna
|
|
1884
1789
|
// Generate SHACL SDNA (Prolog-free)
|
|
1885
1790
|
if (!jsClass.generateSHACL) {
|
|
@@ -1892,6 +1797,186 @@ export class PerspectiveProxy {
|
|
|
1892
1797
|
// Pass SHACL JSON to backend (Prolog-free)
|
|
1893
1798
|
// Backend stores SHACL links directly
|
|
1894
1799
|
await this.addSdna(className, '', 'subject_class', shaclJson);
|
|
1800
|
+
// Mark as registered for this perspective instance
|
|
1801
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").add(className);
|
|
1802
|
+
}
|
|
1803
|
+
/** Clear the per-instance ensured subject class cache.
|
|
1804
|
+
* Call this after wiping a perspective's links so that
|
|
1805
|
+
* subsequent register() calls re-add SHACL definitions. */
|
|
1806
|
+
clearEnsuredSubjectClasses() {
|
|
1807
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").clear();
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Returns a list of all class names that have been registered as SHACL
|
|
1811
|
+
* subject classes in this perspective (via `ensureSDNASubjectClass` or `addSdna`).
|
|
1812
|
+
*
|
|
1813
|
+
* @returns Array of class name strings (e.g. `["Channel", "Message", "Task"]`)
|
|
1814
|
+
*/
|
|
1815
|
+
async listRegisteredClasses() {
|
|
1816
|
+
const results = await this.querySparql(`SELECT DISTINCT ?class WHERE { ?class <rdf://type> <ad4m://SubjectClass> . }`);
|
|
1817
|
+
if (!Array.isArray(results))
|
|
1818
|
+
return [];
|
|
1819
|
+
return results.map((row) => {
|
|
1820
|
+
const uri = row.class || '';
|
|
1821
|
+
// Extract class name from URI like "recipe://Recipe" or "flux://Channel"
|
|
1822
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1823
|
+
if (hashIdx >= 0)
|
|
1824
|
+
return uri.substring(hashIdx + 1);
|
|
1825
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1826
|
+
if (slashIdx >= 0)
|
|
1827
|
+
return uri.substring(slashIdx + 1);
|
|
1828
|
+
return uri;
|
|
1829
|
+
}).filter(Boolean);
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* Returns the SHACL shape metadata for a registered class, including
|
|
1833
|
+
* property names, predicates, datatypes, and cardinality constraints.
|
|
1834
|
+
*
|
|
1835
|
+
* @param className - The name of the registered class
|
|
1836
|
+
* @returns Shape metadata or `null` if the class is not registered
|
|
1837
|
+
*/
|
|
1838
|
+
async getClassShape(className) {
|
|
1839
|
+
// Find the shape URI for this class
|
|
1840
|
+
const safeName = className.replace(/['"\\]/g, '');
|
|
1841
|
+
const shapeResults = await this.querySparql(`SELECT ?shapeUri ?targetClass WHERE {
|
|
1842
|
+
?targetClass <rdf://type> <ad4m://SubjectClass> .
|
|
1843
|
+
?targetClass <ad4m://shape> ?shapeUri .
|
|
1844
|
+
FILTER(STRENDS(STR(?targetClass), "/${safeName}") || STRENDS(STR(?targetClass), "#${safeName}"))
|
|
1845
|
+
} LIMIT 1`);
|
|
1846
|
+
if (!Array.isArray(shapeResults) || shapeResults.length === 0)
|
|
1847
|
+
return null;
|
|
1848
|
+
const shapeUri = shapeResults[0].shapeUri;
|
|
1849
|
+
const classUri = shapeResults[0].targetClass;
|
|
1850
|
+
// Query all properties for this shape, including sh:in
|
|
1851
|
+
const propResults = await this.querySparql(`SELECT ?propShape ?path ?datatype ?minCount ?maxCount ?writable ?propType ?shIn WHERE {
|
|
1852
|
+
<${shapeUri}> <sh://property> ?propShape .
|
|
1853
|
+
?propShape <sh://path> ?path .
|
|
1854
|
+
?propShape <rdf://type> ?propType .
|
|
1855
|
+
OPTIONAL { ?propShape <sh://datatype> ?datatype }
|
|
1856
|
+
OPTIONAL { ?propShape <sh://minCount> ?minCount }
|
|
1857
|
+
OPTIONAL { ?propShape <sh://maxCount> ?maxCount }
|
|
1858
|
+
OPTIONAL { ?propShape <ad4m://writable> ?writable }
|
|
1859
|
+
OPTIONAL { ?propShape <sh://in> ?shIn }
|
|
1860
|
+
}`);
|
|
1861
|
+
const properties = (Array.isArray(propResults) ? propResults : []).map((row) => {
|
|
1862
|
+
// Extract property name from shape URI like "recipe://Recipe.name"
|
|
1863
|
+
const propUri = row.propShape || '';
|
|
1864
|
+
const dotIdx = propUri.lastIndexOf('.');
|
|
1865
|
+
const name = dotIdx >= 0 ? propUri.substring(dotIdx + 1) : propUri;
|
|
1866
|
+
const minCount = parseInt(row.minCount || '0', 10);
|
|
1867
|
+
const isCollection = row.propType === 'ad4m://CollectionShape';
|
|
1868
|
+
const writable = row.writable === 'true' || row.writable === 'literal:true';
|
|
1869
|
+
// Parse sh:in values if present
|
|
1870
|
+
let options;
|
|
1871
|
+
if (row.shIn) {
|
|
1872
|
+
try {
|
|
1873
|
+
let raw = row.shIn;
|
|
1874
|
+
// Strip literal: prefix if present, and URI-decode for robustness
|
|
1875
|
+
if (raw.startsWith('literal:string:')) {
|
|
1876
|
+
raw = decodeURIComponent(raw.substring('literal:string:'.length));
|
|
1877
|
+
}
|
|
1878
|
+
options = JSON.parse(raw);
|
|
1879
|
+
}
|
|
1880
|
+
catch { /* ignore parse errors */ }
|
|
1881
|
+
}
|
|
1882
|
+
return {
|
|
1883
|
+
name,
|
|
1884
|
+
predicate: row.path || '',
|
|
1885
|
+
datatype: row.datatype || undefined,
|
|
1886
|
+
required: minCount > 0,
|
|
1887
|
+
collection: isCollection,
|
|
1888
|
+
writable,
|
|
1889
|
+
...(options && options.length > 0 ? { options } : {}),
|
|
1890
|
+
};
|
|
1891
|
+
});
|
|
1892
|
+
return { className: safeName, shapeUri, properties };
|
|
1893
|
+
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Detects which registered subject classes a given instance conforms to,
|
|
1896
|
+
* based on its stored triples matching the class shapes' required properties.
|
|
1897
|
+
*
|
|
1898
|
+
* @param baseExpression - The instance's base expression / subject URI
|
|
1899
|
+
* @returns Array of class names the instance matches
|
|
1900
|
+
*/
|
|
1901
|
+
async getInstanceClasses(baseExpression) {
|
|
1902
|
+
const safeId = baseExpression.replace(/['"\\]/g, '');
|
|
1903
|
+
// Get all registered classes and their required conformance properties
|
|
1904
|
+
const results = await this.querySparql(`SELECT DISTINCT ?class WHERE {
|
|
1905
|
+
?class <rdf://type> <ad4m://SubjectClass> .
|
|
1906
|
+
?class <ad4m://shape> ?shape .
|
|
1907
|
+
?shape <sh://property> ?propShape .
|
|
1908
|
+
?propShape <sh://minCount> ?mc .
|
|
1909
|
+
FILTER(?mc >= 1)
|
|
1910
|
+
?propShape <sh://path> ?path .
|
|
1911
|
+
<${safeId}> ?path ?_val .
|
|
1912
|
+
}`);
|
|
1913
|
+
if (!Array.isArray(results))
|
|
1914
|
+
return [];
|
|
1915
|
+
return results.map((row) => {
|
|
1916
|
+
const uri = row.class || '';
|
|
1917
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1918
|
+
if (hashIdx >= 0)
|
|
1919
|
+
return uri.substring(hashIdx + 1);
|
|
1920
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1921
|
+
if (slashIdx >= 0)
|
|
1922
|
+
return uri.substring(slashIdx + 1);
|
|
1923
|
+
return uri;
|
|
1924
|
+
}).filter(Boolean);
|
|
1925
|
+
}
|
|
1926
|
+
/**
|
|
1927
|
+
* Returns all named options (sh:in values) for a registered class, grouped by property.
|
|
1928
|
+
*
|
|
1929
|
+
* @param className - The name of the registered class
|
|
1930
|
+
* @returns Record mapping property name → array of { value, label } options
|
|
1931
|
+
*/
|
|
1932
|
+
async getNamedOptions(className) {
|
|
1933
|
+
const shape = await this.getClassShape(className);
|
|
1934
|
+
if (!shape)
|
|
1935
|
+
return {};
|
|
1936
|
+
const result = {};
|
|
1937
|
+
for (const prop of shape.properties) {
|
|
1938
|
+
if (prop.options && prop.options.length > 0) {
|
|
1939
|
+
result[prop.name] = prop.options;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
return result;
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* Adds a named option (sh:in value) to a property of a registered class.
|
|
1946
|
+
* This appends to the existing sh:in list stored on the property shape.
|
|
1947
|
+
*
|
|
1948
|
+
* @param className - The registered class name
|
|
1949
|
+
* @param propertyName - The property to add the option to
|
|
1950
|
+
* @param value - The RDF value for the option
|
|
1951
|
+
* @param label - Optional human-readable label
|
|
1952
|
+
*/
|
|
1953
|
+
async addNamedOption(className, propertyName, value, label) {
|
|
1954
|
+
const shape = await this.getClassShape(className);
|
|
1955
|
+
if (!shape)
|
|
1956
|
+
throw new Error(`Class "${className}" not found`);
|
|
1957
|
+
const prop = shape.properties.find(p => p.name === propertyName);
|
|
1958
|
+
if (!prop)
|
|
1959
|
+
throw new Error(`Property "${propertyName}" not found on class "${className}"`);
|
|
1960
|
+
// Build the property shape URI
|
|
1961
|
+
const ns = extractNamespaceFromUri(shape.shapeUri);
|
|
1962
|
+
const propShapeId = `${ns}${className}.${propertyName}`;
|
|
1963
|
+
// Get existing options
|
|
1964
|
+
const existing = prop.options || [];
|
|
1965
|
+
// Don't add duplicates
|
|
1966
|
+
if (existing.some(o => o.value === value))
|
|
1967
|
+
return;
|
|
1968
|
+
const updated = [...existing, { value, ...(label ? { label } : {}) }];
|
|
1969
|
+
// Remove old sh:in link if exists by querying for it
|
|
1970
|
+
const oldLinks = await this.get(new LinkQuery({ source: propShapeId, predicate: "sh://in" }));
|
|
1971
|
+
for (const oldLink of oldLinks) {
|
|
1972
|
+
await this.remove(oldLink);
|
|
1973
|
+
}
|
|
1974
|
+
// Add new sh:in link
|
|
1975
|
+
await this.add(new Link({
|
|
1976
|
+
source: propShapeId,
|
|
1977
|
+
predicate: "sh://in",
|
|
1978
|
+
target: `literal:string:${JSON.stringify(updated)}`
|
|
1979
|
+
}));
|
|
1895
1980
|
}
|
|
1896
1981
|
getNeighbourhoodProxy() {
|
|
1897
1982
|
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getNeighbourhoodProxy(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
@@ -1961,7 +2046,7 @@ export class PerspectiveProxy {
|
|
|
1961
2046
|
return subscriptionProxy;
|
|
1962
2047
|
}
|
|
1963
2048
|
/**
|
|
1964
|
-
* Creates a subscription for a
|
|
2049
|
+
* Creates a subscription for a SPARQL query that updates in real-time.
|
|
1965
2050
|
*
|
|
1966
2051
|
* This method:
|
|
1967
2052
|
* 1. Creates the subscription on the Rust side
|
|
@@ -1976,12 +2061,12 @@ export class PerspectiveProxy {
|
|
|
1976
2061
|
* when dispose() is called. Make sure to call dispose() when you're done to
|
|
1977
2062
|
* prevent memory leaks and ensure proper cleanup of resources.
|
|
1978
2063
|
*
|
|
1979
|
-
|
|
2064
|
+
/** Subscribe to a query with live updates via the SPARQL subscription endpoint.
|
|
2065
|
+
* @param query - Query string
|
|
1980
2066
|
* @returns Initialized QuerySubscriptionProxy instance
|
|
1981
2067
|
*/
|
|
1982
|
-
async
|
|
2068
|
+
async subscribeQuery(query) {
|
|
1983
2069
|
const subscriptionProxy = new QuerySubscriptionProxy(this.uuid, query, __classPrivateFieldGet(this, _PerspectiveProxy_client, "f"));
|
|
1984
|
-
subscriptionProxy.isSurrealDB = true;
|
|
1985
2070
|
// Start the subscription on the Rust side first to get the real subscription ID
|
|
1986
2071
|
await subscriptionProxy.subscribe();
|
|
1987
2072
|
// Wait for the initial result
|
|
@@ -1989,4 +2074,4 @@ export class PerspectiveProxy {
|
|
|
1989
2074
|
return subscriptionProxy;
|
|
1990
2075
|
}
|
|
1991
2076
|
}
|
|
1992
|
-
_PerspectiveProxy_handle = new WeakMap(), _PerspectiveProxy_client = new WeakMap(), _PerspectiveProxy_perspectiveLinkAddedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveLinkRemovedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveLinkUpdatedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveSyncStateChangeCallbacks = new WeakMap();
|
|
2077
|
+
_PerspectiveProxy_handle = new WeakMap(), _PerspectiveProxy_client = new WeakMap(), _PerspectiveProxy_perspectiveLinkAddedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveLinkRemovedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveLinkUpdatedCallbacks = new WeakMap(), _PerspectiveProxy_perspectiveSyncStateChangeCallbacks = new WeakMap(), _PerspectiveProxy_ensuredSubjectClasses = new WeakMap();
|