@coasys/ad4m 0.12.1-dev → 0.13.0-postmessage-ws-proxy.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +8677 -15318
- package/lib/index.js +14507 -21223
- package/lib/src/Ad4mClient.d.ts +9 -3
- package/lib/src/Ad4mClient.js +40 -13
- package/lib/src/Literal.js +6 -5
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +33 -21
- package/lib/src/agent/AgentClient.js +180 -374
- package/lib/src/agent/AgentStatus.js +2 -37
- package/lib/src/ai/AIClient.d.ts +12 -4
- package/lib/src/ai/AIClient.js +81 -285
- package/lib/src/ai/AITypes.d.ts +55 -0
- package/lib/src/ai/AITypes.js +18 -0
- package/lib/src/ai/Tasks.js +10 -133
- package/lib/src/apiClient.d.ts +53 -0
- package/lib/src/apiClient.js +234 -0
- package/lib/src/cache/PersistentCache.d.ts +40 -0
- package/lib/src/cache/PersistentCache.js +139 -0
- package/lib/src/expression/Expression.d.ts +1 -1
- package/lib/src/expression/Expression.js +13 -122
- package/lib/src/expression/ExpressionClient.d.ts +11 -3
- package/lib/src/expression/ExpressionClient.js +120 -75
- package/lib/src/expression/ExpressionRef.js +4 -27
- package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkRequest.js +1 -0
- package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/api/AddSdnaRequest.js +2 -0
- package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/api/AuthInfoInput.js +1 -0
- package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/api/CapabilityInput.js +1 -0
- package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/CommitBatchRequest.js +2 -0
- package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/api/ComputeLogEntry.js +2 -0
- package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/api/EmbedRequest.js +2 -0
- package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/api/EntanglementProofInput.js +2 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/api/ExportRequest.d.ts +5 -0
- package/lib/src/generated/api/ExportRequest.js +2 -0
- package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/api/ExpressionProof.js +2 -0
- package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/api/ExpressionProofInput.js +2 -0
- package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendsListRequest.js +2 -0
- package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/api/ImportAgentRequest.js +2 -0
- package/lib/src/generated/api/ImportRequest.d.ts +4 -0
- package/lib/src/generated/api/ImportRequest.js +2 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/api/LanguageMetaInput.js +2 -0
- package/lib/src/generated/api/Link.d.ts +5 -0
- package/lib/src/generated/api/Link.js +2 -0
- package/lib/src/generated/api/LinkExpression.d.ts +10 -0
- package/lib/src/generated/api/LinkExpression.js +1 -0
- package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/api/LinkExpressionInput.js +1 -0
- package/lib/src/generated/api/LinkInput.d.ts +5 -0
- package/lib/src/generated/api/LinkInput.js +2 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/api/LinkMutations.d.ts +6 -0
- package/lib/src/generated/api/LinkMutations.js +1 -0
- package/lib/src/generated/api/LinkStatus.d.ts +1 -0
- package/lib/src/generated/api/LinkStatus.js +2 -0
- package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/LockAgentRequest.js +2 -0
- package/lib/src/generated/api/ModelType.d.ts +1 -0
- package/lib/src/generated/api/ModelType.js +2 -0
- package/lib/src/generated/api/NotificationInput.d.ts +10 -0
- package/lib/src/generated/api/NotificationInput.js +2 -0
- package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/api/OpenLinkRequest.js +2 -0
- package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveInput.js +1 -0
- package/lib/src/generated/api/PromptRequest.d.ts +4 -0
- package/lib/src/generated/api/PromptRequest.js +2 -0
- package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/api/QueryRequest.d.ts +7 -0
- package/lib/src/generated/api/QueryRequest.js +2 -0
- package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/ResourceInput.d.ts +4 -0
- package/lib/src/generated/api/ResourceInput.js +2 -0
- package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/api/SetStatusRequest.js +2 -0
- package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/SignMessageRequest.js +2 -0
- package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/UserStatistics.d.ts +9 -0
- package/lib/src/generated/api/UserStatistics.js +2 -0
- package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/api/VerificationRequestResult.js +2 -0
- package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +42 -0
- package/lib/src/generated/api/index.js +7 -0
- package/lib/src/index.d.ts +8 -2
- package/lib/src/index.js +8 -2
- package/lib/src/jestSetup.d.ts +0 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.js +2 -21
- package/lib/src/language/Language.d.ts +26 -176
- package/lib/src/language/Language.js +32 -72
- package/lib/src/language/LanguageClient.d.ts +2 -2
- package/lib/src/language/LanguageClient.js +15 -105
- package/lib/src/language/LanguageHandle.js +2 -41
- package/lib/src/language/LanguageMeta.js +4 -75
- package/lib/src/language/LanguageRef.js +2 -25
- package/lib/src/links/Links.js +14 -111
- package/lib/src/model/Ad4mModel.d.ts +143 -63
- package/lib/src/model/Ad4mModel.js +583 -425
- package/lib/src/model/Ad4mModel.test.js +1434 -688
- package/lib/src/model/ModelQueryBuilder.d.ts +61 -45
- package/lib/src/model/ModelQueryBuilder.js +315 -157
- package/lib/src/model/Subject.js +6 -6
- package/lib/src/model/decorators.d.ts +36 -8
- package/lib/src/model/decorators.js +41 -14
- package/lib/src/model/hydration-batch.d.ts +34 -0
- package/lib/src/model/hydration-batch.js +147 -0
- package/lib/src/model/hydration-batching.test.d.ts +7 -0
- package/lib/src/model/hydration-batching.test.js +456 -0
- package/lib/src/model/hydration.d.ts +3 -92
- package/lib/src/model/hydration.js +3 -691
- package/lib/src/model/index.d.ts +3 -4
- package/lib/src/model/index.js +3 -4
- package/lib/src/model/json-schema.js +2 -2
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-cache.d.ts +30 -0
- package/lib/src/model/query-cache.js +66 -0
- package/lib/src/model/query-cache.test.d.ts +1 -0
- package/lib/src/model/query-cache.test.js +43 -0
- package/lib/src/model/query-common.d.ts +1 -1
- package/lib/src/model/query-common.js +1 -1
- package/lib/src/model/query-sparql-batch.d.ts +17 -0
- package/lib/src/model/query-sparql-batch.js +260 -0
- package/lib/src/model/query-sparql.d.ts +51 -0
- package/lib/src/model/query-sparql.js +466 -0
- package/lib/src/model/query-sparql.test.d.ts +1 -0
- package/lib/src/model/query-sparql.test.js +312 -0
- package/lib/src/model/{surreal-utils.d.ts → query-utils.d.ts} +13 -9
- package/lib/src/model/query-utils.js +189 -0
- package/lib/src/model/relation-filtering.test.js +15 -15
- package/lib/src/model/sdna.js +1 -1
- package/lib/src/model/shacl-gen.js +154 -57
- package/lib/src/model/subscription-delta.test.d.ts +24 -0
- package/lib/src/model/subscription-delta.test.js +180 -0
- package/lib/src/model/subscription-pool.d.ts +39 -0
- package/lib/src/model/subscription-pool.js +165 -0
- package/lib/src/model/types.d.ts +195 -5
- package/lib/src/model/types.js +5 -2
- package/lib/src/neighbourhood/Neighbourhood.js +4 -32
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
- package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
- package/lib/src/perspectives/LinkQuery.js +2 -42
- package/lib/src/perspectives/Perspective.d.ts +1 -1
- package/lib/src/perspectives/Perspective.js +10 -52
- package/lib/src/perspectives/PerspectiveClient.d.ts +22 -32
- package/lib/src/perspectives/PerspectiveClient.js +188 -454
- package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +157 -78
- package/lib/src/perspectives/PerspectiveProxy.js +475 -389
- package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveResolver.js +0 -11
- package/lib/src/perspectives/SparqlBindings.d.ts +47 -0
- package/lib/src/perspectives/SparqlBindings.js +65 -0
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +3 -3
- package/lib/src/perspectives/WakerSubscriptionManager.js +12 -12
- package/lib/src/runtime/RuntimeClient.d.ts +8 -6
- package/lib/src/runtime/RuntimeClient.js +97 -454
- package/lib/src/runtime/RuntimeResolver.d.ts +14 -0
- package/lib/src/runtime/RuntimeResolver.js +84 -0
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/schema.gql +14 -1
- package/lib/src/shacl/SHACLFlow.d.ts +1 -1
- package/lib/src/shacl/SHACLFlow.js +9 -9
- package/lib/src/shacl/SHACLShape.d.ts +26 -1
- package/lib/src/shacl/SHACLShape.js +140 -38
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -615
- package/lib/src/utils.d.ts +6 -6
- package/lib/src/utils.js +6 -6
- package/package.json +9 -24
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1192 -1288
- package/src/Ad4mClient.ts +46 -15
- package/src/Literal.test.ts +10 -5
- package/src/Literal.ts +6 -5
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +238 -467
- package/src/agent/AgentStatus.ts +0 -12
- package/src/ai/AIClient.ts +96 -296
- package/src/ai/AITypes.ts +66 -0
- package/src/ai/Tasks.ts +0 -52
- package/src/apiClient.ts +287 -0
- package/src/cache/PersistentCache.ts +145 -0
- package/src/cache/cache.test.ts +713 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +148 -77
- package/src/expression/ExpressionRef.ts +2 -8
- package/src/generated/api/AIModelLoadingStatus.ts +3 -0
- package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
- package/src/generated/api/AddLinkRequest.ts +4 -0
- package/src/generated/api/AddLinksBulkRequest.ts +4 -0
- package/src/generated/api/AddSdnaRequest.ts +3 -0
- package/src/generated/api/ApplyTemplateRequest.ts +3 -0
- package/src/generated/api/AuthInfoInput.ts +4 -0
- package/src/generated/api/CapabilityInput.ts +4 -0
- package/src/generated/api/CommitBatchRequest.ts +3 -0
- package/src/generated/api/ComputeLogEntry.ts +3 -0
- package/src/generated/api/CreateExpressionRequest.ts +3 -0
- package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
- package/src/generated/api/CreateSubjectRequest.ts +3 -0
- package/src/generated/api/EmbedRequest.ts +3 -0
- package/src/generated/api/EntanglementProofInput.ts +3 -0
- package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
- package/src/generated/api/ExportRequest.ts +3 -0
- package/src/generated/api/ExpressionManyRequest.ts +3 -0
- package/src/generated/api/ExpressionProof.ts +3 -0
- package/src/generated/api/ExpressionProofInput.ts +3 -0
- package/src/generated/api/FriendSendMessageRequest.ts +3 -0
- package/src/generated/api/FriendsListRequest.ts +3 -0
- package/src/generated/api/GenerateAgentRequest.ts +3 -0
- package/src/generated/api/GenerateJwtRequest.ts +3 -0
- package/src/generated/api/GetSubjectDataRequest.ts +3 -0
- package/src/generated/api/ImportAgentRequest.ts +3 -0
- package/src/generated/api/ImportRequest.ts +3 -0
- package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
- package/src/generated/api/LanguageMetaInput.ts +3 -0
- package/src/generated/api/Link.ts +3 -0
- package/src/generated/api/LinkExpression.ts +6 -0
- package/src/generated/api/LinkExpressionInput.ts +6 -0
- package/src/generated/api/LinkInput.ts +3 -0
- package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
- package/src/generated/api/LinkMutations.ts +5 -0
- package/src/generated/api/LinkStatus.ts +3 -0
- package/src/generated/api/LockAgentRequest.ts +3 -0
- package/src/generated/api/ModelType.ts +3 -0
- package/src/generated/api/NotificationInput.ts +3 -0
- package/src/generated/api/OpenLinkRequest.ts +3 -0
- package/src/generated/api/PermitCapabilityRequest.ts +3 -0
- package/src/generated/api/PerspectiveInput.ts +4 -0
- package/src/generated/api/PromptRequest.ts +3 -0
- package/src/generated/api/PublishLanguageRequest.ts +4 -0
- package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
- package/src/generated/api/QueryRequest.ts +6 -0
- package/src/generated/api/RemoveLinkRequest.ts +4 -0
- package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
- package/src/generated/api/ResourceInput.ts +3 -0
- package/src/generated/api/SetDefaultModelRequest.ts +4 -0
- package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
- package/src/generated/api/SetMultiUserRequest.ts +3 -0
- package/src/generated/api/SetStatusRequest.ts +3 -0
- package/src/generated/api/SignMessageRequest.ts +3 -0
- package/src/generated/api/TrustedAgentsRequest.ts +3 -0
- package/src/generated/api/UnlockAgentRequest.ts +3 -0
- package/src/generated/api/UpdateLinkRequest.ts +5 -0
- package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
- package/src/generated/api/UserStatistics.ts +3 -0
- package/src/generated/api/VerificationRequestResult.ts +3 -0
- package/src/generated/api/VerifySignatureRequest.ts +3 -0
- package/src/generated/api/WriteSettingsRequest.ts +3 -0
- package/src/generated/api/index.ts +49 -0
- package/src/index.ts +8 -2
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +51 -248
- package/src/language/LanguageClient.ts +21 -132
- package/src/language/LanguageHandle.ts +0 -14
- package/src/language/LanguageMeta.ts +0 -29
- package/src/language/LanguageRef.ts +0 -7
- package/src/links/Links.ts +0 -37
- package/src/model/Ad4mModel.test.ts +1664 -792
- package/src/model/Ad4mModel.ts +664 -499
- package/src/model/ModelQueryBuilder.ts +362 -183
- package/src/model/decorators.ts +71 -22
- package/src/model/hydration.ts +3 -772
- package/src/model/index.ts +3 -4
- package/src/model/json-schema.ts +2 -2
- package/src/model/query-cache.test.ts +54 -0
- package/src/model/query-cache.ts +79 -0
- package/src/model/query-common.ts +1 -1
- package/src/model/query-sparql.test.ts +376 -0
- package/src/model/query-sparql.ts +504 -0
- package/src/model/query-utils.ts +209 -0
- package/src/model/relation-filtering.test.ts +60 -53
- package/src/model/sdna.ts +1 -1
- package/src/model/shacl-gen.ts +163 -64
- package/src/model/shacl-roundtrip.test.ts +197 -0
- package/src/model/types-typed-query.test.ts +360 -0
- package/src/model/types.ts +256 -5
- package/src/neighbourhood/Neighbourhood.ts +0 -9
- package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
- package/src/perspectives/LinkQuery.ts +0 -15
- package/src/perspectives/Perspective.ts +1 -12
- package/src/perspectives/PerspectiveClient.test.ts +262 -0
- package/src/perspectives/PerspectiveClient.ts +252 -468
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +125 -0
- package/src/perspectives/PerspectiveProxy.ts +522 -434
- package/src/perspectives/SparqlBindings.ts +79 -0
- package/src/perspectives/WakerSubscriptionManager.ts +13 -13
- package/src/runtime/RuntimeClient.ts +118 -461
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLFlow.ts +9 -9
- package/src/shacl/SHACLShape.test.ts +204 -0
- package/src/shacl/SHACLShape.ts +191 -39
- package/src/typeDefs.ts +3 -5
- package/src/utils.ts +6 -6
- package/tsconfig.json +3 -7
- package/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/lib/src/model/surreal-utils.js +0 -128
- package/shims/reflect-metadata.ts +0 -0
- package/shims/type-graphql.ts +0 -75
- package/src/PubSub.ts +0 -17
- package/src/agent/AgentResolver.ts +0 -263
- package/src/ai/AIResolver.ts +0 -372
- package/src/buildSchema.ts +0 -43
- package/src/expression/ExpressionResolver.ts +0 -64
- package/src/language/LanguageContext.ts +0 -37
- package/src/language/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-surreal.ts +0 -280
- package/src/model/surreal-utils.ts +0 -147
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -372
- package/src/runtime/RuntimeResolver.ts +0 -691
- package/src/unwrapApolloResult.ts +0 -16
- package/tsconfig-browser.json +0 -82
|
@@ -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,72 @@ 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
|
+
* The executor resolves the model's shape from the perspective's SHACL
|
|
544
|
+
* triples (written by `addSdna`). Callers no longer ship shape
|
|
545
|
+
* metadata with the query; the perspective is the source of truth.
|
|
546
|
+
*
|
|
547
|
+
* @param className - The model class name (e.g. "Recipe")
|
|
548
|
+
* @param queryJson - Structured query as JSON string
|
|
549
|
+
* @returns Object with `instances` array and `totalCount`
|
|
516
550
|
*/
|
|
517
|
-
async
|
|
518
|
-
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").
|
|
551
|
+
async modelQuery(className, queryJson) {
|
|
552
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson);
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Evaluate property getters for a batch of instances in a single RPC call.
|
|
556
|
+
* Returns a map of `{ instanceId: { prop: value, ... } }`.
|
|
557
|
+
*
|
|
558
|
+
* Use this instead of `Ad4mModel.evaluateGetters()` for lazy-loading
|
|
559
|
+
* getter-backed properties on visible items (e.g. `replyingTo` on messages).
|
|
560
|
+
*
|
|
561
|
+
* @param className - The model class name (e.g. "Message")
|
|
562
|
+
* @param instanceIds - Array of instance base expression URIs
|
|
563
|
+
* @param propertyNames - Optional subset of property names to evaluate
|
|
564
|
+
* @returns Map of instance ID → evaluated property values
|
|
565
|
+
*/
|
|
566
|
+
async evaluateGetters(className, instanceIds, propertyNames) {
|
|
567
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").evaluateGetters(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, instanceIds, propertyNames);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Subscribe to model query changes. Builds trigger SPARQL from the model shape
|
|
571
|
+
* internally in Rust, registers a subscription, runs the initial query, and
|
|
572
|
+
* pushes updated results when relevant links change.
|
|
573
|
+
*
|
|
574
|
+
* The subscription reuses the same GraphQL subscription channel as subscribeQuery().
|
|
575
|
+
* Use keepAliveQuery() / disposeQuerySubscription() with the returned subscriptionId.
|
|
576
|
+
*
|
|
577
|
+
* @param className - The model class name
|
|
578
|
+
* @param queryJson - JSON-serialized query parameters (same as modelQuery)
|
|
579
|
+
* @returns Object with `subscriptionId` and initial `result`
|
|
580
|
+
*/
|
|
581
|
+
async modelSubscribe(className, queryJson) {
|
|
582
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson);
|
|
519
583
|
}
|
|
520
584
|
/**
|
|
521
585
|
* Adds a new link to the perspective.
|
|
@@ -543,7 +607,9 @@ export class PerspectiveProxy {
|
|
|
543
607
|
* ```
|
|
544
608
|
*/
|
|
545
609
|
async add(link, status = 'shared', batchId) {
|
|
546
|
-
|
|
610
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addLink(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, link, status, batchId);
|
|
611
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
612
|
+
return result;
|
|
547
613
|
}
|
|
548
614
|
/**
|
|
549
615
|
* Adds multiple links to the perspective in a single operation.
|
|
@@ -555,7 +621,9 @@ export class PerspectiveProxy {
|
|
|
555
621
|
* @returns Array of created LinkExpressions
|
|
556
622
|
*/
|
|
557
623
|
async addLinks(links, status = 'shared', batchId) {
|
|
558
|
-
|
|
624
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addLinks(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, links, status, batchId);
|
|
625
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
626
|
+
return result;
|
|
559
627
|
}
|
|
560
628
|
/**
|
|
561
629
|
* Removes multiple links from the perspective.
|
|
@@ -565,7 +633,9 @@ export class PerspectiveProxy {
|
|
|
565
633
|
* @returns Array of removed LinkExpressions
|
|
566
634
|
*/
|
|
567
635
|
async removeLinks(links, batchId) {
|
|
568
|
-
|
|
636
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").removeLinks(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, links, batchId);
|
|
637
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
638
|
+
return result;
|
|
569
639
|
}
|
|
570
640
|
/**
|
|
571
641
|
* Applies a set of link mutations (adds and removes) in a single operation.
|
|
@@ -576,7 +646,9 @@ export class PerspectiveProxy {
|
|
|
576
646
|
* @returns Object containing results of the mutations
|
|
577
647
|
*/
|
|
578
648
|
async linkMutations(mutations, status = 'shared') {
|
|
579
|
-
|
|
649
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").linkMutations(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, mutations, status);
|
|
650
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
651
|
+
return result;
|
|
580
652
|
}
|
|
581
653
|
/**
|
|
582
654
|
* Adds a pre-signed LinkExpression to the perspective.
|
|
@@ -597,7 +669,9 @@ export class PerspectiveProxy {
|
|
|
597
669
|
* @param batchId - Optional batch ID to group this operation with others
|
|
598
670
|
*/
|
|
599
671
|
async update(oldLink, newLink, batchId) {
|
|
600
|
-
|
|
672
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").updateLink(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, oldLink, newLink, batchId);
|
|
673
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
674
|
+
return result;
|
|
601
675
|
}
|
|
602
676
|
/**
|
|
603
677
|
* Removes a link from the perspective.
|
|
@@ -606,7 +680,9 @@ export class PerspectiveProxy {
|
|
|
606
680
|
* @param batchId - Optional batch ID to group this operation with others
|
|
607
681
|
*/
|
|
608
682
|
async remove(link, batchId) {
|
|
609
|
-
|
|
683
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").removeLink(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, link, batchId);
|
|
684
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
685
|
+
return result;
|
|
610
686
|
}
|
|
611
687
|
/** Creates a new batch for grouping operations */
|
|
612
688
|
async createBatch() {
|
|
@@ -614,7 +690,9 @@ export class PerspectiveProxy {
|
|
|
614
690
|
}
|
|
615
691
|
/** Commits a batch of operations */
|
|
616
692
|
async commitBatch(batchId) {
|
|
617
|
-
|
|
693
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").commitBatch(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, batchId);
|
|
694
|
+
invalidatePerspectiveCache(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
695
|
+
return result;
|
|
618
696
|
}
|
|
619
697
|
/**
|
|
620
698
|
* Retrieves and renders an Expression referenced in this perspective.
|
|
@@ -689,17 +767,30 @@ export class PerspectiveProxy {
|
|
|
689
767
|
async removeListener(type, cb) {
|
|
690
768
|
if (type === 'link-added') {
|
|
691
769
|
const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").indexOf(cb);
|
|
692
|
-
|
|
770
|
+
if (index >= 0)
|
|
771
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").splice(index, 1);
|
|
693
772
|
}
|
|
694
773
|
else if (type === 'link-removed') {
|
|
695
774
|
const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").indexOf(cb);
|
|
696
|
-
|
|
775
|
+
if (index >= 0)
|
|
776
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").splice(index, 1);
|
|
697
777
|
}
|
|
698
778
|
else if (type === 'link-updated') {
|
|
699
779
|
const index = __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").indexOf(cb);
|
|
700
|
-
|
|
780
|
+
if (index >= 0)
|
|
781
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").splice(index, 1);
|
|
701
782
|
}
|
|
702
783
|
}
|
|
784
|
+
/** Clean up all subscriptions registered by this proxy.
|
|
785
|
+
* Call this when the proxy is no longer needed to prevent subscription leaks.
|
|
786
|
+
* After calling dispose(), the proxy should not be used. */
|
|
787
|
+
dispose() {
|
|
788
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_client, "f").removeAllListeners(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
789
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkAddedCallbacks, "f").length = 0;
|
|
790
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, "f").length = 0;
|
|
791
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f").length = 0;
|
|
792
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f").length = 0;
|
|
793
|
+
}
|
|
703
794
|
/**
|
|
704
795
|
* Creates a snapshot of the current perspective state.
|
|
705
796
|
* Useful for backup or sharing.
|
|
@@ -970,7 +1061,7 @@ export class PerspectiveProxy {
|
|
|
970
1061
|
* Adds Social DNA code to the perspective.
|
|
971
1062
|
*
|
|
972
1063
|
* **Recommended:** Use {@link addShacl} instead, which accepts the `SHACLShape` type directly.
|
|
973
|
-
* This method is primarily for the
|
|
1064
|
+
* This method is primarily for the RPC API layer and legacy Prolog code.
|
|
974
1065
|
*
|
|
975
1066
|
* @param name - Unique name for this SDNA definition
|
|
976
1067
|
* @param sdnaCode - Prolog SDNA code (legacy, can be empty string if shaclJson provided)
|
|
@@ -989,6 +1080,47 @@ export class PerspectiveProxy {
|
|
|
989
1080
|
async addSdna(name, sdnaCode, sdnaType, shaclJson) {
|
|
990
1081
|
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addSdna(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, name, sdnaCode, sdnaType, shaclJson);
|
|
991
1082
|
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Batch variant of addSdna — registers multiple SDNA entries in a single RPC call.
|
|
1085
|
+
* Acquires the Rust-side mutex once for the entire batch.
|
|
1086
|
+
*/
|
|
1087
|
+
async addSdnaAll(entries) {
|
|
1088
|
+
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addSdnaBatch(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, entries);
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Batch-registers multiple model classes as SHACL subject classes in a single RPC call.
|
|
1092
|
+
* Skips classes already registered on this perspective instance.
|
|
1093
|
+
*/
|
|
1094
|
+
async ensureSubjectClasses(jsClasses) {
|
|
1095
|
+
const entries = [];
|
|
1096
|
+
for (const jsClass of jsClasses) {
|
|
1097
|
+
const className = jsClass.className || jsClass.prototype?.className || jsClass.name;
|
|
1098
|
+
if (__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").has(className))
|
|
1099
|
+
continue;
|
|
1100
|
+
if (!jsClass.generateSHACL) {
|
|
1101
|
+
throw new Error(`Class ${jsClass.name} must have generateSHACL(). Use @Model decorator.`);
|
|
1102
|
+
}
|
|
1103
|
+
const { shape } = jsClass.generateSHACL();
|
|
1104
|
+
entries.push({
|
|
1105
|
+
name: className,
|
|
1106
|
+
sdnaType: 'subject_class',
|
|
1107
|
+
shaclJson: JSON.stringify(shape.toJSON()),
|
|
1108
|
+
});
|
|
1109
|
+
}
|
|
1110
|
+
if (entries.length === 0)
|
|
1111
|
+
return;
|
|
1112
|
+
await this.addSdnaAll(entries);
|
|
1113
|
+
for (const entry of entries) {
|
|
1114
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").add(entry.name);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Adds a subject class to the perspective.
|
|
1119
|
+
* Alias for addSdna() with sdnaType='subject_class'.
|
|
1120
|
+
*/
|
|
1121
|
+
async addSubjectClass(name, shaclJson) {
|
|
1122
|
+
return this.addSdna(name, '', 'subject_class', shaclJson);
|
|
1123
|
+
}
|
|
992
1124
|
/**
|
|
993
1125
|
* **Recommended way to add SDNA schemas.**
|
|
994
1126
|
*
|
|
@@ -1020,7 +1152,7 @@ export class PerspectiveProxy {
|
|
|
1020
1152
|
// Serialize shape to links
|
|
1021
1153
|
const shapeLinks = shape.toLinks();
|
|
1022
1154
|
// Create name -> shape mapping links
|
|
1023
|
-
const nameMapping = Literal.fromUrl(`literal
|
|
1155
|
+
const nameMapping = Literal.fromUrl(`literal:string:shacl://${name}`);
|
|
1024
1156
|
const allLinks = [
|
|
1025
1157
|
...shapeLinks.map(l => new Link({
|
|
1026
1158
|
source: l.source,
|
|
@@ -1046,7 +1178,7 @@ export class PerspectiveProxy {
|
|
|
1046
1178
|
*/
|
|
1047
1179
|
async getShacl(name) {
|
|
1048
1180
|
// Find the shape URI from the name mapping
|
|
1049
|
-
const nameMapping = Literal.fromUrl(`literal
|
|
1181
|
+
const nameMapping = Literal.fromUrl(`literal:string:shacl://${name}`);
|
|
1050
1182
|
const shapeUriLinks = await this.get(new LinkQuery({
|
|
1051
1183
|
source: nameMapping.toUrl(),
|
|
1052
1184
|
predicate: "ad4m://shacl_shape_uri"
|
|
@@ -1055,22 +1187,25 @@ export class PerspectiveProxy {
|
|
|
1055
1187
|
return null;
|
|
1056
1188
|
}
|
|
1057
1189
|
const shapeUri = shapeUriLinks[0].data.target;
|
|
1058
|
-
const escapedShapeUri = escapeSurrealString(shapeUri);
|
|
1059
1190
|
// First get property shape URIs so we can query everything in one go
|
|
1060
1191
|
const propertyLinks = await this.get(new LinkQuery({
|
|
1061
1192
|
source: shapeUri,
|
|
1062
1193
|
predicate: "sh://property"
|
|
1063
1194
|
}));
|
|
1064
|
-
//
|
|
1195
|
+
// Fetch all links from the shape and its property shapes
|
|
1065
1196
|
const sourceUris = [shapeUri, ...propertyLinks.map(l => l.data.target)];
|
|
1066
|
-
const
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1197
|
+
const allLinks = [];
|
|
1198
|
+
for (const uri of sourceUris) {
|
|
1199
|
+
const links = await this.get(new LinkQuery({ source: uri }));
|
|
1200
|
+
for (const l of links) {
|
|
1201
|
+
allLinks.push({
|
|
1202
|
+
source: l.data.source,
|
|
1203
|
+
predicate: l.data.predicate,
|
|
1204
|
+
target: l.data.target
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
const shapeLinks = allLinks;
|
|
1074
1209
|
return SHACLShape.fromLinks(shapeLinks, shapeUri);
|
|
1075
1210
|
}
|
|
1076
1211
|
/**
|
|
@@ -1172,19 +1307,20 @@ export class PerspectiveProxy {
|
|
|
1172
1307
|
return null;
|
|
1173
1308
|
}
|
|
1174
1309
|
const flowUri = flowUriLinks[0].data.target;
|
|
1175
|
-
const escapedFlowUri = escapeSurrealString(flowUri);
|
|
1176
1310
|
// Compute alternate prefix for state/transition URIs
|
|
1177
1311
|
const alternatePrefix = flowUri.endsWith('Flow')
|
|
1178
1312
|
? flowUri.slice(0, -4) + '.'
|
|
1179
1313
|
: flowUri + '.';
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1314
|
+
// Fetch flow links using SPARQL to match flowUri source OR alternatePrefix sources
|
|
1315
|
+
const sparqlQuery = `SELECT ?s ?p ?o WHERE {
|
|
1316
|
+
?s ?p ?o .
|
|
1317
|
+
FILTER(?s = <${flowUri}> || STRSTARTS(STR(?s), "${alternatePrefix}"))
|
|
1318
|
+
}`;
|
|
1319
|
+
const sparqlResult = await this.querySparql(sparqlQuery);
|
|
1320
|
+
const flowLinks = (sparqlResult || []).map((r) => ({
|
|
1321
|
+
source: r.s,
|
|
1322
|
+
predicate: r.p,
|
|
1323
|
+
target: r.o
|
|
1188
1324
|
}));
|
|
1189
1325
|
return SHACLFlow.fromLinks(flowLinks, flowUri);
|
|
1190
1326
|
}
|
|
@@ -1194,7 +1330,7 @@ export class PerspectiveProxy {
|
|
|
1194
1330
|
*/
|
|
1195
1331
|
async subjectClasses() {
|
|
1196
1332
|
try {
|
|
1197
|
-
// Query SHACL class links directly — no need for a separate
|
|
1333
|
+
// Query SHACL class links directly — no need for a separate RPC endpoint
|
|
1198
1334
|
const classLinks = await this.get(new LinkQuery({
|
|
1199
1335
|
predicate: "rdf://type",
|
|
1200
1336
|
target: "ad4m://SubjectClass"
|
|
@@ -1267,7 +1403,9 @@ export class PerspectiveProxy {
|
|
|
1267
1403
|
if (batchId) {
|
|
1268
1404
|
return exprAddr;
|
|
1269
1405
|
}
|
|
1270
|
-
|
|
1406
|
+
// Return the expression address directly — callers should use Ad4mModel or
|
|
1407
|
+
// getSubjectData() to interact with the created instance.
|
|
1408
|
+
return exprAddr;
|
|
1271
1409
|
}
|
|
1272
1410
|
async getSubjectData(subjectClass, exprAddr) {
|
|
1273
1411
|
if (typeof subjectClass === "string") {
|
|
@@ -1293,8 +1431,8 @@ export class PerspectiveProxy {
|
|
|
1293
1431
|
const links = await this.get(new LinkQuery({ predicate }));
|
|
1294
1432
|
for (const link of links) {
|
|
1295
1433
|
if (shapePattern.test(link.data.source)) {
|
|
1296
|
-
// Parse actions from literal
|
|
1297
|
-
const prefix = "literal
|
|
1434
|
+
// Parse actions from literal:string:{json}
|
|
1435
|
+
const prefix = "literal:string:";
|
|
1298
1436
|
if (link.data.target.startsWith(prefix)) {
|
|
1299
1437
|
const jsonStr = link.data.target.slice(prefix.length);
|
|
1300
1438
|
// Decode URL-encoded JSON if needed, with fallback for raw % characters
|
|
@@ -1343,70 +1481,29 @@ export class PerspectiveProxy {
|
|
|
1343
1481
|
async isSubjectInstance(expression, subjectClass) {
|
|
1344
1482
|
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
|
|
1345
1483
|
// Get metadata from SHACL links
|
|
1346
|
-
const metadata = await this.
|
|
1484
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1347
1485
|
if (!metadata) {
|
|
1348
1486
|
console.warn(`isSubjectInstance: No SHACL metadata found for class ${className}`);
|
|
1349
1487
|
return false;
|
|
1350
1488
|
}
|
|
1351
1489
|
// If no required triples, any expression with links is an instance
|
|
1352
1490
|
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)}`;
|
|
1491
|
+
const links = await this.get(new LinkQuery({ source: expression }));
|
|
1492
|
+
return links.length > 0;
|
|
1399
1493
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1494
|
+
// Build a single SPARQL ASK query with all required triple patterns
|
|
1495
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1496
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1497
|
+
return `<${expression}> <${t.predicate}> ${target} .`;
|
|
1498
|
+
}).join('\n ');
|
|
1499
|
+
const result = await this.querySparql(`ASK WHERE {\n ${patterns}\n}`);
|
|
1500
|
+
return result === true;
|
|
1404
1501
|
}
|
|
1405
1502
|
/**
|
|
1406
1503
|
* Gets subject class metadata from SHACL links using SHACLShape.fromLinks().
|
|
1407
1504
|
* Retrieves the SHACL shape and extracts metadata for instance queries.
|
|
1408
1505
|
*/
|
|
1409
|
-
async
|
|
1506
|
+
async getSubjectClassMetadata(className) {
|
|
1410
1507
|
try {
|
|
1411
1508
|
// Use getShacl() to retrieve the shape via SHACLShape.fromLinks()
|
|
1412
1509
|
const shape = await this.getShacl(className);
|
|
@@ -1460,193 +1557,28 @@ export class PerspectiveProxy {
|
|
|
1460
1557
|
}
|
|
1461
1558
|
}
|
|
1462
1559
|
/**
|
|
1463
|
-
* Generates a
|
|
1464
|
-
*/
|
|
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
|
-
/**
|
|
1486
|
-
* Gets a property value using SurrealDB when Prolog fails.
|
|
1487
|
-
* This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
|
|
1560
|
+
* Generates a SPARQL query to find instances based on class metadata.
|
|
1488
1561
|
*/
|
|
1489
|
-
async getPropertyValueViaSurreal(baseExpression, className, propertyName) {
|
|
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
1562
|
/**
|
|
1588
|
-
*
|
|
1589
|
-
*
|
|
1563
|
+
* Finds all instances matching subject class metadata by querying links.
|
|
1564
|
+
* Returns base URIs of matching instances.
|
|
1590
1565
|
*/
|
|
1591
|
-
async
|
|
1592
|
-
if (expressions.length === 0) {
|
|
1593
|
-
return [];
|
|
1594
|
-
}
|
|
1595
|
-
// If no required triples, check which expressions have any links
|
|
1566
|
+
async findInstancesByMetadata(metadata) {
|
|
1596
1567
|
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;
|
|
1568
|
+
// No required triples - return all unique sources that have any link
|
|
1569
|
+
const allLinks = await this.get(new LinkQuery({}));
|
|
1570
|
+
const sources = new Set(allLinks.map(l => l.data.source));
|
|
1571
|
+
return Array.from(sources).map(s => ({ base: s }));
|
|
1572
|
+
}
|
|
1573
|
+
// Build a single SPARQL SELECT with all required triple patterns joined
|
|
1574
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1575
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1576
|
+
return `?base <${t.predicate}> ${target} .`;
|
|
1577
|
+
}).join('\n ');
|
|
1578
|
+
const results = await this.querySparql(`SELECT DISTINCT ?base WHERE {\n ${patterns}\n}`);
|
|
1579
|
+
if (!Array.isArray(results))
|
|
1580
|
+
return [];
|
|
1581
|
+
return results.map((row) => ({ base: row.base }));
|
|
1650
1582
|
}
|
|
1651
1583
|
/** Returns all subject instances of the given subject class as proxy objects.
|
|
1652
1584
|
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
@@ -1670,13 +1602,12 @@ export class PerspectiveProxy {
|
|
|
1670
1602
|
let instances = [];
|
|
1671
1603
|
for (let className of classes) {
|
|
1672
1604
|
//console.log(`getAllSubjectInstances: Processing class ${className}`);
|
|
1673
|
-
// Query SDNA for metadata, then query
|
|
1674
|
-
const metadata = await this.
|
|
1605
|
+
// Query SDNA for metadata, then query SPARQL for instances
|
|
1606
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1675
1607
|
//console.log(`getAllSubjectInstances: Got metadata for ${className}:`, metadata);
|
|
1676
1608
|
if (metadata) {
|
|
1677
|
-
const
|
|
1678
|
-
|
|
1679
|
-
// console.log(`getAllSubjectInstances: SurrealDB returned ${results?.length || 0} results`);
|
|
1609
|
+
const results = await this.findInstancesByMetadata(metadata);
|
|
1610
|
+
// console.log(`getAllSubjectInstances: SPARQL returned ${results?.length || 0} results`);
|
|
1680
1611
|
for (const result of results || []) {
|
|
1681
1612
|
//console.log(`getAllSubjectInstances: Creating subject for base ${result.base}`);
|
|
1682
1613
|
try {
|
|
@@ -1689,9 +1620,9 @@ export class PerspectiveProxy {
|
|
|
1689
1620
|
await instance.get();
|
|
1690
1621
|
}
|
|
1691
1622
|
else {
|
|
1692
|
-
//
|
|
1693
|
-
|
|
1694
|
-
|
|
1623
|
+
// Return plain data for string-based lookups
|
|
1624
|
+
const data = await this.getSubjectData(className, result.base);
|
|
1625
|
+
instance = { id: result.base, ...data };
|
|
1695
1626
|
}
|
|
1696
1627
|
instances.push(instance);
|
|
1697
1628
|
//console.log(`getAllSubjectInstances: Successfully created subject for ${result.base}`);
|
|
@@ -1708,40 +1639,6 @@ export class PerspectiveProxy {
|
|
|
1708
1639
|
//console.log(`getAllSubjectInstances: Returning ${instances.length} instances`);
|
|
1709
1640
|
return instances;
|
|
1710
1641
|
}
|
|
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
1642
|
/**
|
|
1746
1643
|
* Find a subject class by matching an object's properties/relations against SHACL shapes.
|
|
1747
1644
|
* Queries SHACL links client-side to find a class whose properties contain all required ones.
|
|
@@ -1772,22 +1669,24 @@ export class PerspectiveProxy {
|
|
|
1772
1669
|
if (properties.length === 0 && relations.length === 0) {
|
|
1773
1670
|
return null;
|
|
1774
1671
|
}
|
|
1775
|
-
// Single
|
|
1776
|
-
const
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1672
|
+
// Single SPARQL query to get all class shapes with their properties and collections
|
|
1673
|
+
const results = await this.querySparql(`
|
|
1674
|
+
SELECT ?shape ?predicate ?target WHERE {
|
|
1675
|
+
{ ?shape <rdf://type> <ad4m://SubjectClass> . BIND(<rdf://type> AS ?predicate) BIND(<ad4m://SubjectClass> AS ?target) }
|
|
1676
|
+
UNION
|
|
1677
|
+
{ ?shape <sh://property> ?target . BIND(<sh://property> AS ?predicate) }
|
|
1678
|
+
UNION
|
|
1679
|
+
{ ?shape <sh://collection> ?target . BIND(<sh://collection> AS ?predicate) }
|
|
1680
|
+
}
|
|
1681
|
+
`);
|
|
1682
|
+
if (!Array.isArray(results) || results.length === 0)
|
|
1784
1683
|
return null;
|
|
1785
1684
|
// Build a map of className -> { properties, relations }
|
|
1786
1685
|
const classShapes = new Map();
|
|
1787
1686
|
// First pass: find all subject classes
|
|
1788
1687
|
for (const r of results) {
|
|
1789
1688
|
if (r.predicate === 'rdf://type' && r.target === 'ad4m://SubjectClass') {
|
|
1790
|
-
const source = r.
|
|
1689
|
+
const source = r.shape;
|
|
1791
1690
|
const sepIdx = source.indexOf('://');
|
|
1792
1691
|
if (sepIdx < 0)
|
|
1793
1692
|
continue;
|
|
@@ -1802,7 +1701,7 @@ export class PerspectiveProxy {
|
|
|
1802
1701
|
if (r.predicate === 'sh://property' || r.predicate === 'sh://collection') {
|
|
1803
1702
|
// Match shape source to class (e.g., "recipe://RecipeShape" -> "Recipe")
|
|
1804
1703
|
for (const [className, shape] of classShapes) {
|
|
1805
|
-
if (r.
|
|
1704
|
+
if (r.shape.endsWith(`${className}Shape`)) {
|
|
1806
1705
|
const dotIdx = r.target.lastIndexOf('.');
|
|
1807
1706
|
if (dotIdx < 0)
|
|
1808
1707
|
continue;
|
|
@@ -1878,8 +1777,15 @@ export class PerspectiveProxy {
|
|
|
1878
1777
|
* static generateSDNA() function and adds it to the perspective's SDNA.
|
|
1879
1778
|
*/
|
|
1880
1779
|
async ensureSDNASubjectClass(jsClass) {
|
|
1780
|
+
return this.ensureSubjectClass(jsClass);
|
|
1781
|
+
}
|
|
1782
|
+
/** Takes a JS class (its constructor) and ensures the SHACL subject class exists. */
|
|
1783
|
+
async ensureSubjectClass(jsClass) {
|
|
1881
1784
|
// Get the class name from the JS class
|
|
1882
1785
|
const className = jsClass.className || jsClass.prototype?.className || jsClass.name;
|
|
1786
|
+
// Skip if already registered for this perspective instance
|
|
1787
|
+
if (__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").has(className))
|
|
1788
|
+
return;
|
|
1883
1789
|
// Note: Duplicate checking is handled on the Rust side in add_sdna
|
|
1884
1790
|
// Generate SHACL SDNA (Prolog-free)
|
|
1885
1791
|
if (!jsClass.generateSHACL) {
|
|
@@ -1892,6 +1798,186 @@ export class PerspectiveProxy {
|
|
|
1892
1798
|
// Pass SHACL JSON to backend (Prolog-free)
|
|
1893
1799
|
// Backend stores SHACL links directly
|
|
1894
1800
|
await this.addSdna(className, '', 'subject_class', shaclJson);
|
|
1801
|
+
// Mark as registered for this perspective instance
|
|
1802
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").add(className);
|
|
1803
|
+
}
|
|
1804
|
+
/** Clear the per-instance ensured subject class cache.
|
|
1805
|
+
* Call this after wiping a perspective's links so that
|
|
1806
|
+
* subsequent register() calls re-add SHACL definitions. */
|
|
1807
|
+
clearEnsuredSubjectClasses() {
|
|
1808
|
+
__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").clear();
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Returns a list of all class names that have been registered as SHACL
|
|
1812
|
+
* subject classes in this perspective (via `ensureSDNASubjectClass` or `addSdna`).
|
|
1813
|
+
*
|
|
1814
|
+
* @returns Array of class name strings (e.g. `["Channel", "Message", "Task"]`)
|
|
1815
|
+
*/
|
|
1816
|
+
async listRegisteredClasses() {
|
|
1817
|
+
const results = await this.querySparql(`SELECT DISTINCT ?class WHERE { ?class <rdf://type> <ad4m://SubjectClass> . }`);
|
|
1818
|
+
if (!Array.isArray(results))
|
|
1819
|
+
return [];
|
|
1820
|
+
return results.map((row) => {
|
|
1821
|
+
const uri = row.class || '';
|
|
1822
|
+
// Extract class name from URI like "recipe://Recipe" or "flux://Channel"
|
|
1823
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1824
|
+
if (hashIdx >= 0)
|
|
1825
|
+
return uri.substring(hashIdx + 1);
|
|
1826
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1827
|
+
if (slashIdx >= 0)
|
|
1828
|
+
return uri.substring(slashIdx + 1);
|
|
1829
|
+
return uri;
|
|
1830
|
+
}).filter(Boolean);
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* Returns the SHACL shape metadata for a registered class, including
|
|
1834
|
+
* property names, predicates, datatypes, and cardinality constraints.
|
|
1835
|
+
*
|
|
1836
|
+
* @param className - The name of the registered class
|
|
1837
|
+
* @returns Shape metadata or `null` if the class is not registered
|
|
1838
|
+
*/
|
|
1839
|
+
async getClassShape(className) {
|
|
1840
|
+
// Find the shape URI for this class
|
|
1841
|
+
const safeName = className.replace(/['"\\]/g, '');
|
|
1842
|
+
const shapeResults = await this.querySparql(`SELECT ?shapeUri ?targetClass WHERE {
|
|
1843
|
+
?targetClass <rdf://type> <ad4m://SubjectClass> .
|
|
1844
|
+
?targetClass <ad4m://shape> ?shapeUri .
|
|
1845
|
+
FILTER(STRENDS(STR(?targetClass), "/${safeName}") || STRENDS(STR(?targetClass), "#${safeName}"))
|
|
1846
|
+
} LIMIT 1`);
|
|
1847
|
+
if (!Array.isArray(shapeResults) || shapeResults.length === 0)
|
|
1848
|
+
return null;
|
|
1849
|
+
const shapeUri = shapeResults[0].shapeUri;
|
|
1850
|
+
const classUri = shapeResults[0].targetClass;
|
|
1851
|
+
// Query all properties for this shape, including sh:in
|
|
1852
|
+
const propResults = await this.querySparql(`SELECT ?propShape ?path ?datatype ?minCount ?maxCount ?writable ?propType ?shIn WHERE {
|
|
1853
|
+
<${shapeUri}> <sh://property> ?propShape .
|
|
1854
|
+
?propShape <sh://path> ?path .
|
|
1855
|
+
?propShape <rdf://type> ?propType .
|
|
1856
|
+
OPTIONAL { ?propShape <sh://datatype> ?datatype }
|
|
1857
|
+
OPTIONAL { ?propShape <sh://minCount> ?minCount }
|
|
1858
|
+
OPTIONAL { ?propShape <sh://maxCount> ?maxCount }
|
|
1859
|
+
OPTIONAL { ?propShape <ad4m://writable> ?writable }
|
|
1860
|
+
OPTIONAL { ?propShape <sh://in> ?shIn }
|
|
1861
|
+
}`);
|
|
1862
|
+
const properties = (Array.isArray(propResults) ? propResults : []).map((row) => {
|
|
1863
|
+
// Extract property name from shape URI like "recipe://Recipe.name"
|
|
1864
|
+
const propUri = row.propShape || '';
|
|
1865
|
+
const dotIdx = propUri.lastIndexOf('.');
|
|
1866
|
+
const name = dotIdx >= 0 ? propUri.substring(dotIdx + 1) : propUri;
|
|
1867
|
+
const minCount = parseInt(row.minCount || '0', 10);
|
|
1868
|
+
const isCollection = row.propType === 'ad4m://CollectionShape';
|
|
1869
|
+
const writable = row.writable === 'true' || row.writable === 'literal:true';
|
|
1870
|
+
// Parse sh:in values if present
|
|
1871
|
+
let options;
|
|
1872
|
+
if (row.shIn) {
|
|
1873
|
+
try {
|
|
1874
|
+
let raw = row.shIn;
|
|
1875
|
+
// Strip literal: prefix if present, and URI-decode for robustness
|
|
1876
|
+
if (raw.startsWith('literal:string:')) {
|
|
1877
|
+
raw = decodeURIComponent(raw.substring('literal:string:'.length));
|
|
1878
|
+
}
|
|
1879
|
+
options = JSON.parse(raw);
|
|
1880
|
+
}
|
|
1881
|
+
catch { /* ignore parse errors */ }
|
|
1882
|
+
}
|
|
1883
|
+
return {
|
|
1884
|
+
name,
|
|
1885
|
+
predicate: row.path || '',
|
|
1886
|
+
datatype: row.datatype || undefined,
|
|
1887
|
+
required: minCount > 0,
|
|
1888
|
+
collection: isCollection,
|
|
1889
|
+
writable,
|
|
1890
|
+
...(options && options.length > 0 ? { options } : {}),
|
|
1891
|
+
};
|
|
1892
|
+
});
|
|
1893
|
+
return { className: safeName, shapeUri, properties };
|
|
1894
|
+
}
|
|
1895
|
+
/**
|
|
1896
|
+
* Detects which registered subject classes a given instance conforms to,
|
|
1897
|
+
* based on its stored triples matching the class shapes' required properties.
|
|
1898
|
+
*
|
|
1899
|
+
* @param baseExpression - The instance's base expression / subject URI
|
|
1900
|
+
* @returns Array of class names the instance matches
|
|
1901
|
+
*/
|
|
1902
|
+
async getInstanceClasses(baseExpression) {
|
|
1903
|
+
const safeId = baseExpression.replace(/['"\\]/g, '');
|
|
1904
|
+
// Get all registered classes and their required conformance properties
|
|
1905
|
+
const results = await this.querySparql(`SELECT DISTINCT ?class WHERE {
|
|
1906
|
+
?class <rdf://type> <ad4m://SubjectClass> .
|
|
1907
|
+
?class <ad4m://shape> ?shape .
|
|
1908
|
+
?shape <sh://property> ?propShape .
|
|
1909
|
+
?propShape <sh://minCount> ?mc .
|
|
1910
|
+
FILTER(?mc >= 1)
|
|
1911
|
+
?propShape <sh://path> ?path .
|
|
1912
|
+
<${safeId}> ?path ?_val .
|
|
1913
|
+
}`);
|
|
1914
|
+
if (!Array.isArray(results))
|
|
1915
|
+
return [];
|
|
1916
|
+
return results.map((row) => {
|
|
1917
|
+
const uri = row.class || '';
|
|
1918
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1919
|
+
if (hashIdx >= 0)
|
|
1920
|
+
return uri.substring(hashIdx + 1);
|
|
1921
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1922
|
+
if (slashIdx >= 0)
|
|
1923
|
+
return uri.substring(slashIdx + 1);
|
|
1924
|
+
return uri;
|
|
1925
|
+
}).filter(Boolean);
|
|
1926
|
+
}
|
|
1927
|
+
/**
|
|
1928
|
+
* Returns all named options (sh:in values) for a registered class, grouped by property.
|
|
1929
|
+
*
|
|
1930
|
+
* @param className - The name of the registered class
|
|
1931
|
+
* @returns Record mapping property name → array of { value, label } options
|
|
1932
|
+
*/
|
|
1933
|
+
async getNamedOptions(className) {
|
|
1934
|
+
const shape = await this.getClassShape(className);
|
|
1935
|
+
if (!shape)
|
|
1936
|
+
return {};
|
|
1937
|
+
const result = {};
|
|
1938
|
+
for (const prop of shape.properties) {
|
|
1939
|
+
if (prop.options && prop.options.length > 0) {
|
|
1940
|
+
result[prop.name] = prop.options;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
return result;
|
|
1944
|
+
}
|
|
1945
|
+
/**
|
|
1946
|
+
* Adds a named option (sh:in value) to a property of a registered class.
|
|
1947
|
+
* This appends to the existing sh:in list stored on the property shape.
|
|
1948
|
+
*
|
|
1949
|
+
* @param className - The registered class name
|
|
1950
|
+
* @param propertyName - The property to add the option to
|
|
1951
|
+
* @param value - The RDF value for the option
|
|
1952
|
+
* @param label - Optional human-readable label
|
|
1953
|
+
*/
|
|
1954
|
+
async addNamedOption(className, propertyName, value, label) {
|
|
1955
|
+
const shape = await this.getClassShape(className);
|
|
1956
|
+
if (!shape)
|
|
1957
|
+
throw new Error(`Class "${className}" not found`);
|
|
1958
|
+
const prop = shape.properties.find(p => p.name === propertyName);
|
|
1959
|
+
if (!prop)
|
|
1960
|
+
throw new Error(`Property "${propertyName}" not found on class "${className}"`);
|
|
1961
|
+
// Build the property shape URI
|
|
1962
|
+
const ns = extractNamespaceFromUri(shape.shapeUri);
|
|
1963
|
+
const propShapeId = `${ns}${className}.${propertyName}`;
|
|
1964
|
+
// Get existing options
|
|
1965
|
+
const existing = prop.options || [];
|
|
1966
|
+
// Don't add duplicates
|
|
1967
|
+
if (existing.some(o => o.value === value))
|
|
1968
|
+
return;
|
|
1969
|
+
const updated = [...existing, { value, ...(label ? { label } : {}) }];
|
|
1970
|
+
// Remove old sh:in link if exists by querying for it
|
|
1971
|
+
const oldLinks = await this.get(new LinkQuery({ source: propShapeId, predicate: "sh://in" }));
|
|
1972
|
+
for (const oldLink of oldLinks) {
|
|
1973
|
+
await this.remove(oldLink);
|
|
1974
|
+
}
|
|
1975
|
+
// Add new sh:in link
|
|
1976
|
+
await this.add(new Link({
|
|
1977
|
+
source: propShapeId,
|
|
1978
|
+
predicate: "sh://in",
|
|
1979
|
+
target: `literal:string:${JSON.stringify(updated)}`
|
|
1980
|
+
}));
|
|
1895
1981
|
}
|
|
1896
1982
|
getNeighbourhoodProxy() {
|
|
1897
1983
|
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getNeighbourhoodProxy(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
@@ -1961,7 +2047,7 @@ export class PerspectiveProxy {
|
|
|
1961
2047
|
return subscriptionProxy;
|
|
1962
2048
|
}
|
|
1963
2049
|
/**
|
|
1964
|
-
* Creates a subscription for a
|
|
2050
|
+
* Creates a subscription for a SPARQL query that updates in real-time.
|
|
1965
2051
|
*
|
|
1966
2052
|
* This method:
|
|
1967
2053
|
* 1. Creates the subscription on the Rust side
|
|
@@ -1976,12 +2062,12 @@ export class PerspectiveProxy {
|
|
|
1976
2062
|
* when dispose() is called. Make sure to call dispose() when you're done to
|
|
1977
2063
|
* prevent memory leaks and ensure proper cleanup of resources.
|
|
1978
2064
|
*
|
|
1979
|
-
|
|
2065
|
+
/** Subscribe to a query with live updates via the SPARQL subscription endpoint.
|
|
2066
|
+
* @param query - Query string
|
|
1980
2067
|
* @returns Initialized QuerySubscriptionProxy instance
|
|
1981
2068
|
*/
|
|
1982
|
-
async
|
|
2069
|
+
async subscribeQuery(query) {
|
|
1983
2070
|
const subscriptionProxy = new QuerySubscriptionProxy(this.uuid, query, __classPrivateFieldGet(this, _PerspectiveProxy_client, "f"));
|
|
1984
|
-
subscriptionProxy.isSurrealDB = true;
|
|
1985
2071
|
// Start the subscription on the Rust side first to get the real subscription ID
|
|
1986
2072
|
await subscriptionProxy.subscribe();
|
|
1987
2073
|
// Wait for the initial result
|
|
@@ -1989,4 +2075,4 @@ export class PerspectiveProxy {
|
|
|
1989
2075
|
return subscriptionProxy;
|
|
1990
2076
|
}
|
|
1991
2077
|
}
|
|
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();
|
|
2078
|
+
_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();
|