@coasys/ad4m 0.13.0-test-2 → 0.13.0-test-4
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 +2805 -10556
- package/lib/index.js +2513 -10322
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +29 -13
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +10 -21
- package/lib/src/agent/AgentClient.js +75 -427
- 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 +52 -0
- package/lib/src/apiClient.js +231 -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 +3 -3
- package/lib/src/expression/ExpressionClient.js +13 -76
- package/lib/src/expression/ExpressionRef.js +2 -25
- 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 +6 -2
- package/lib/src/index.js +6 -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 -214
- 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 +81 -38
- package/lib/src/model/Ad4mModel.js +651 -408
- package/lib/src/model/Ad4mModel.test.js +488 -750
- package/lib/src/model/ModelQueryBuilder.d.ts +28 -21
- package/lib/src/model/ModelQueryBuilder.js +160 -195
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -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 +8 -60
- package/lib/src/model/hydration.js +41 -541
- package/lib/src/model/index.d.ts +0 -4
- package/lib/src/model/index.js +0 -4
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-sparql.d.ts +36 -22
- package/lib/src/model/query-sparql.js +188 -53
- 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/query-utils.js +4 -0
- package/lib/src/model/shacl-gen.js +4 -0
- 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.js +48 -2
- package/lib/src/model/types.d.ts +58 -1
- package/lib/src/model/types.js +4 -1
- 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 +12 -15
- package/lib/src/perspectives/PerspectiveClient.js +168 -400
- 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 +95 -71
- package/lib/src/perspectives/PerspectiveProxy.js +288 -310
- package/lib/src/runtime/RuntimeClient.d.ts +6 -6
- package/lib/src/runtime/RuntimeClient.js +93 -467
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/shacl/SHACLShape.d.ts +7 -0
- package/lib/src/shacl/SHACLShape.js +19 -0
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -628
- package/package.json +9 -24
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1182 -1288
- package/src/Ad4mClient.ts +30 -15
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +112 -526
- 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 +283 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +14 -77
- package/src/expression/ExpressionRef.ts +0 -6
- 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 +6 -2
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +50 -292
- 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 +827 -808
- package/src/model/Ad4mModel.ts +676 -457
- package/src/model/ModelQueryBuilder.ts +199 -217
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +17 -572
- package/src/model/index.ts +0 -4
- package/src/model/query-sparql.test.ts +360 -0
- package/src/model/query-sparql.ts +203 -56
- package/src/model/query-utils.ts +4 -0
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +62 -1
- 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 +227 -412
- package/src/perspectives/PerspectiveDiff.ts +0 -8
- package/src/perspectives/PerspectiveHandle.ts +1 -12
- package/src/perspectives/PerspectiveProxy.test.ts +41 -0
- package/src/perspectives/PerspectiveProxy.ts +325 -348
- package/src/runtime/RuntimeClient.ts +112 -474
- package/src/runtime/RuntimeTypes.ts +144 -0
- package/src/shacl/SHACLShape.test.ts +94 -0
- package/src/shacl/SHACLShape.ts +27 -0
- package/src/typeDefs.ts +3 -5
- 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.d.ts +0 -42
- 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/hydration-batch.ts +0 -205
- package/src/model/prolog-facts.ts +0 -145
- package/src/model/query-prolog.ts +0 -148
- package/src/model/query-sparql-batch.ts +0 -301
- package/src/model/subscription-pool.ts +0 -163
- package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
- package/src/perspectives/PerspectiveResolver.ts +0 -364
- package/src/runtime/RuntimeResolver.ts +0 -749
- package/src/unwrapApolloResult.ts +0 -16
- package/tsconfig-browser.json +0 -82
|
@@ -4,13 +4,11 @@ import { LinkQuery } from "./LinkQuery";
|
|
|
4
4
|
import { PerspectiveHandle, PerspectiveState } from './PerspectiveHandle'
|
|
5
5
|
import { Perspective } from "./Perspective";
|
|
6
6
|
import { Literal } from "../Literal";
|
|
7
|
-
import { Subject } from "../model/Subject";
|
|
8
7
|
import { ExpressionRendered } from "../expression/Expression";
|
|
9
8
|
import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
|
|
10
9
|
import { NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
|
|
11
10
|
import { AIClient } from "../ai/AIClient";
|
|
12
|
-
|
|
13
|
-
import { gql } from "@apollo/client/core";
|
|
11
|
+
|
|
14
12
|
import { getPropertiesMetadata, getRelationsMetadata } from "../model/decorators";
|
|
15
13
|
import { getCachedResult, setCachedResult, invalidatePerspectiveCache } from "../model/query-cache";
|
|
16
14
|
import { AllInstancesResult } from "../model/types";
|
|
@@ -20,9 +18,19 @@ import { SHACLFlow, LinkPattern } from "../shacl/SHACLFlow";
|
|
|
20
18
|
|
|
21
19
|
type QueryCallback = (result: AllInstancesResult) => void;
|
|
22
20
|
|
|
21
|
+
/** Extract namespace prefix from a URI (everything up to and including the last / or #) */
|
|
22
|
+
function extractNamespaceFromUri(uri: string): string {
|
|
23
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
24
|
+
if (hashIdx >= 0) return uri.substring(0, hashIdx + 1);
|
|
25
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
26
|
+
if (slashIdx >= 0) return uri.substring(0, slashIdx + 1);
|
|
27
|
+
const colonIdx = uri.lastIndexOf(':');
|
|
28
|
+
if (colonIdx >= 0) return uri.substring(0, colonIdx + 1);
|
|
29
|
+
return uri;
|
|
30
|
+
}
|
|
23
31
|
|
|
24
32
|
|
|
25
|
-
// Generic
|
|
33
|
+
// Generic unsubscribe interface for event subscriptions
|
|
26
34
|
interface Unsubscribable {
|
|
27
35
|
unsubscribe(): void;
|
|
28
36
|
}
|
|
@@ -32,7 +40,7 @@ interface Unsubscribable {
|
|
|
32
40
|
* This class handles:
|
|
33
41
|
* - Keeping the subscription alive by sending periodic keepalive signals
|
|
34
42
|
* - Managing callbacks for result updates
|
|
35
|
-
* - Subscribing to query updates via
|
|
43
|
+
* - Subscribing to query updates via WebSocket subscriptions
|
|
36
44
|
* - Maintaining the latest query result
|
|
37
45
|
* - Ensuring subscription is fully initialized before allowing access
|
|
38
46
|
* - Cleaning up resources when disposed
|
|
@@ -119,22 +127,32 @@ export class QuerySubscriptionProxy {
|
|
|
119
127
|
initialResult = await this.#client.subscribeQuery(this.#uuid, this.#query);
|
|
120
128
|
this.#subscriptionId = initialResult.subscriptionId;
|
|
121
129
|
|
|
122
|
-
// Process the initial result immediately for fast UX
|
|
123
|
-
|
|
130
|
+
// Process the initial result immediately for fast UX.
|
|
131
|
+
// The subscribeQuery() RPC call already returns the initial result,
|
|
132
|
+
// so treat that as successful initialization instead of waiting for a
|
|
133
|
+
// follow-up WebSocket update that may never arrive until the query changes.
|
|
134
|
+
if (initialResult.result !== undefined) {
|
|
124
135
|
this.#latestResult = initialResult.result;
|
|
125
136
|
this.#notifyCallbacks(initialResult.result);
|
|
137
|
+
|
|
138
|
+
if (this.#initResolve) {
|
|
139
|
+
this.#initResolve(true);
|
|
140
|
+
this.#initResolve = undefined;
|
|
141
|
+
this.#initReject = undefined;
|
|
142
|
+
}
|
|
126
143
|
} else {
|
|
127
144
|
console.warn('⚠️ No initial result returned from subscribeQuery!');
|
|
128
|
-
}
|
|
129
145
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
// Only keep the initialization timeout when the backend did not
|
|
147
|
+
// provide an initial result up front.
|
|
148
|
+
this.#initTimeoutId = setTimeout(() => {
|
|
149
|
+
console.error('Subscription initialization timed out after 30 seconds. Resubscribing...');
|
|
150
|
+
// Recursively retry subscription, catching any errors
|
|
151
|
+
this.subscribe().catch(error => {
|
|
152
|
+
console.error('Error during subscription retry after timeout:', error);
|
|
153
|
+
});
|
|
154
|
+
}, 30000);
|
|
155
|
+
}
|
|
138
156
|
|
|
139
157
|
// Subscribe to query updates
|
|
140
158
|
this.#unsubscribe = this.#client.subscribeToQueryUpdates(
|
|
@@ -281,7 +299,7 @@ export class QuerySubscriptionProxy {
|
|
|
281
299
|
*
|
|
282
300
|
* This method:
|
|
283
301
|
* 1. Stops the keepalive timer
|
|
284
|
-
* 2. Unsubscribes from
|
|
302
|
+
* 2. Unsubscribes from subscription updates
|
|
285
303
|
* 3. Clears all registered callbacks
|
|
286
304
|
* 4. Cleans up any pending initialization timeout
|
|
287
305
|
*
|
|
@@ -376,6 +394,10 @@ export class PerspectiveProxy {
|
|
|
376
394
|
|
|
377
395
|
#handle: PerspectiveHandle
|
|
378
396
|
#client: PerspectiveClient
|
|
397
|
+
|
|
398
|
+
/** @internal Exposed for ModelQueryBuilder subscription management */
|
|
399
|
+
get client(): PerspectiveClient { return this.#client; }
|
|
400
|
+
|
|
379
401
|
#perspectiveLinkAddedCallbacks: LinkCallback[]
|
|
380
402
|
#perspectiveLinkRemovedCallbacks: LinkCallback[]
|
|
381
403
|
#perspectiveLinkUpdatedCallbacks: LinkCallback[]
|
|
@@ -405,6 +427,24 @@ export class PerspectiveProxy {
|
|
|
405
427
|
this.#client.addPerspectiveSyncStateChangeListener(this.#handle.uuid, this.#perspectiveSyncStateChangeCallbacks)
|
|
406
428
|
}
|
|
407
429
|
|
|
430
|
+
/** Update the proxy's internal handle and public fields in-place.
|
|
431
|
+
* Keeps the same object reference so all holders see the update. */
|
|
432
|
+
updateHandle(handle: PerspectiveHandle): void {
|
|
433
|
+
if (handle.uuid !== this.#handle.uuid) {
|
|
434
|
+
throw new Error(
|
|
435
|
+
`PerspectiveProxy.updateHandle: UUID mismatch — proxy is bound to "${this.#handle.uuid}" but received handle with UUID "${handle.uuid}". ` +
|
|
436
|
+
`This would silently diverge from listeners registered under the original UUID.`
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
this.#handle = handle;
|
|
440
|
+
this.uuid = handle.uuid;
|
|
441
|
+
this.name = handle.name;
|
|
442
|
+
this.owners = handle.owners;
|
|
443
|
+
this.sharedUrl = handle.sharedUrl;
|
|
444
|
+
this.neighbourhood = handle.neighbourhood;
|
|
445
|
+
this.state = handle.state;
|
|
446
|
+
}
|
|
447
|
+
|
|
408
448
|
/**
|
|
409
449
|
* Escapes special regex characters in a string to prevent ReDoS attacks
|
|
410
450
|
* and regex injection when building dynamic regular expressions.
|
|
@@ -560,6 +600,35 @@ export class PerspectiveProxy {
|
|
|
560
600
|
return result;
|
|
561
601
|
}
|
|
562
602
|
|
|
603
|
+
/**
|
|
604
|
+
* Execute a model query — the executor-side replacement for SPARQL query building + JS hydration.
|
|
605
|
+
*
|
|
606
|
+
* @param className - The model class name (e.g. "Recipe")
|
|
607
|
+
* @param queryJson - Structured query as JSON string
|
|
608
|
+
* @param shapeJson - Optional shape metadata JSON from the model class
|
|
609
|
+
* @returns Object with `instances` array and `totalCount`
|
|
610
|
+
*/
|
|
611
|
+
async modelQuery(className: string, queryJson: string, shapeJson?: string): Promise<{ instances: any[], totalCount: number }> {
|
|
612
|
+
return await this.#client.modelQuery(this.#handle.uuid, className, queryJson, shapeJson);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Subscribe to model query changes. Builds trigger SPARQL from the model shape
|
|
617
|
+
* internally in Rust, registers a subscription, runs the initial query, and
|
|
618
|
+
* pushes updated results when relevant links change.
|
|
619
|
+
*
|
|
620
|
+
* The subscription reuses the same GraphQL subscription channel as subscribeQuery().
|
|
621
|
+
* Use keepAliveQuery() / disposeQuerySubscription() with the returned subscriptionId.
|
|
622
|
+
*
|
|
623
|
+
* @param className - The model class name
|
|
624
|
+
* @param queryJson - JSON-serialized query parameters (same as modelQuery)
|
|
625
|
+
* @param shapeJson - Optional shape metadata JSON from the model class
|
|
626
|
+
* @returns Object with `subscriptionId` and initial `result`
|
|
627
|
+
*/
|
|
628
|
+
async modelSubscribe(className: string, queryJson: string, shapeJson?: string): Promise<{ subscriptionId: string, result: any }> {
|
|
629
|
+
return await this.#client.modelSubscribe(this.#handle.uuid, className, queryJson, shapeJson);
|
|
630
|
+
}
|
|
631
|
+
|
|
563
632
|
/**
|
|
564
633
|
* Adds a new link to the perspective.
|
|
565
634
|
*
|
|
@@ -1052,7 +1121,7 @@ export class PerspectiveProxy {
|
|
|
1052
1121
|
* Adds Social DNA code to the perspective.
|
|
1053
1122
|
*
|
|
1054
1123
|
* **Recommended:** Use {@link addShacl} instead, which accepts the `SHACLShape` type directly.
|
|
1055
|
-
* This method is primarily for the
|
|
1124
|
+
* This method is primarily for the RPC API layer and legacy Prolog code.
|
|
1056
1125
|
*
|
|
1057
1126
|
* @param name - Unique name for this SDNA definition
|
|
1058
1127
|
* @param sdnaCode - Prolog SDNA code (legacy, can be empty string if shaclJson provided)
|
|
@@ -1313,7 +1382,7 @@ export class PerspectiveProxy {
|
|
|
1313
1382
|
*/
|
|
1314
1383
|
async subjectClasses(): Promise<string[]> {
|
|
1315
1384
|
try {
|
|
1316
|
-
// Query SHACL class links directly — no need for a separate
|
|
1385
|
+
// Query SHACL class links directly — no need for a separate RPC endpoint
|
|
1317
1386
|
const classLinks = await this.get(new LinkQuery({
|
|
1318
1387
|
predicate: "rdf://type",
|
|
1319
1388
|
target: "ad4m://SubjectClass"
|
|
@@ -1405,7 +1474,9 @@ export class PerspectiveProxy {
|
|
|
1405
1474
|
return exprAddr as B extends undefined ? T : string;
|
|
1406
1475
|
}
|
|
1407
1476
|
|
|
1408
|
-
|
|
1477
|
+
// Return the expression address directly — callers should use Ad4mModel or
|
|
1478
|
+
// getSubjectData() to interact with the created instance.
|
|
1479
|
+
return exprAddr as unknown as B extends undefined ? T : string;
|
|
1409
1480
|
}
|
|
1410
1481
|
|
|
1411
1482
|
async getSubjectData<T>(subjectClass: T, exprAddr: string): Promise<T> {
|
|
@@ -1487,7 +1558,7 @@ export class PerspectiveProxy {
|
|
|
1487
1558
|
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass)
|
|
1488
1559
|
|
|
1489
1560
|
// Get metadata from SHACL links
|
|
1490
|
-
const metadata = await this.
|
|
1561
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1491
1562
|
if (!metadata) {
|
|
1492
1563
|
console.warn(`isSubjectInstance: No SHACL metadata found for class ${className}`);
|
|
1493
1564
|
return false;
|
|
@@ -1499,44 +1570,17 @@ export class PerspectiveProxy {
|
|
|
1499
1570
|
return links.length > 0;
|
|
1500
1571
|
}
|
|
1501
1572
|
|
|
1502
|
-
//
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
} else {
|
|
1508
|
-
query = new LinkQuery({ source: expression, predicate: triple.predicate });
|
|
1509
|
-
}
|
|
1510
|
-
const links = await this.get(query);
|
|
1573
|
+
// Build a single SPARQL ASK query with all required triple patterns
|
|
1574
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1575
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1576
|
+
return `<${expression}> <${t.predicate}> ${target} .`;
|
|
1577
|
+
}).join('\n ');
|
|
1511
1578
|
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
|
-
return true;
|
|
1579
|
+
const result = await this.querySparql(`ASK WHERE {\n ${patterns}\n}`);
|
|
1580
|
+
return result === true;
|
|
1518
1581
|
}
|
|
1519
1582
|
|
|
1520
1583
|
|
|
1521
|
-
/** For an existing subject instance (existing in the perspective's links)
|
|
1522
|
-
* this function returns a proxy object that can be used to access the subject's
|
|
1523
|
-
* properties and methods.
|
|
1524
|
-
*
|
|
1525
|
-
* @param base URI of the subject's root expression
|
|
1526
|
-
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
1527
|
-
* with the properties of the subject class. In the latter case, the first subject class
|
|
1528
|
-
* that matches the given properties will be used.
|
|
1529
|
-
*/
|
|
1530
|
-
async getSubjectProxy<T>(base: string, subjectClass: T): Promise<T> {
|
|
1531
|
-
if(!await this.isSubjectInstance(base, subjectClass)) {
|
|
1532
|
-
throw `Expression ${base} is not a subject instance of given class: ${JSON.stringify(subjectClass)}`
|
|
1533
|
-
}
|
|
1534
|
-
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass)
|
|
1535
|
-
let subject = new Subject(this, base, className)
|
|
1536
|
-
await subject.init()
|
|
1537
|
-
return subject as unknown as T
|
|
1538
|
-
}
|
|
1539
|
-
|
|
1540
1584
|
/**
|
|
1541
1585
|
* Gets subject class metadata from SHACL links using SHACLShape.fromLinks().
|
|
1542
1586
|
* Retrieves the SHACL shape and extracts metadata for instance queries.
|
|
@@ -1546,16 +1590,6 @@ export class PerspectiveProxy {
|
|
|
1546
1590
|
requiredTriples: Array<{predicate: string, target?: string}>,
|
|
1547
1591
|
properties: Map<string, { predicate: string, resolveLanguage?: string }>,
|
|
1548
1592
|
relations: Map<string, { predicate: string, instanceFilter?: string, condition?: string }>
|
|
1549
|
-
} | null> {
|
|
1550
|
-
return this.getSubjectClassMetadataFromSDNA(className);
|
|
1551
|
-
}
|
|
1552
|
-
|
|
1553
|
-
/** @deprecated Use getSubjectClassMetadata() */
|
|
1554
|
-
async getSubjectClassMetadataFromSDNA(className: string): Promise<{
|
|
1555
|
-
requiredPredicates: string[],
|
|
1556
|
-
requiredTriples: Array<{predicate: string, target?: string}>,
|
|
1557
|
-
properties: Map<string, { predicate: string, resolveLanguage?: string }>,
|
|
1558
|
-
relations: Map<string, { predicate: string, instanceFilter?: string, condition?: string }>
|
|
1559
1593
|
} | null> {
|
|
1560
1594
|
try {
|
|
1561
1595
|
// Use getShacl() to retrieve the shape via SHACLShape.fromLinks()
|
|
@@ -1611,6 +1645,7 @@ export class PerspectiveProxy {
|
|
|
1611
1645
|
return null;
|
|
1612
1646
|
}
|
|
1613
1647
|
}
|
|
1648
|
+
|
|
1614
1649
|
/**
|
|
1615
1650
|
* Generates a SPARQL query to find instances based on class metadata.
|
|
1616
1651
|
*/
|
|
@@ -1631,239 +1666,17 @@ export class PerspectiveProxy {
|
|
|
1631
1666
|
return Array.from(sources).map(s => ({ base: s }));
|
|
1632
1667
|
}
|
|
1633
1668
|
|
|
1634
|
-
//
|
|
1635
|
-
const
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
} else {
|
|
1640
|
-
query = new LinkQuery({ predicate: first.predicate });
|
|
1641
|
-
}
|
|
1642
|
-
const candidateLinks = await this.get(query);
|
|
1643
|
-
let candidates = [...new Set(candidateLinks.map(l => l.data.source))];
|
|
1644
|
-
|
|
1645
|
-
// Filter by remaining required triples
|
|
1646
|
-
for (let i = 1; i < metadata.requiredTriples.length; i++) {
|
|
1647
|
-
const triple = metadata.requiredTriples[i];
|
|
1648
|
-
const remaining: string[] = [];
|
|
1649
|
-
for (const expr of candidates) {
|
|
1650
|
-
let q: LinkQuery;
|
|
1651
|
-
if (triple.target) {
|
|
1652
|
-
q = new LinkQuery({ source: expr, predicate: triple.predicate, target: triple.target });
|
|
1653
|
-
} else {
|
|
1654
|
-
q = new LinkQuery({ source: expr, predicate: triple.predicate });
|
|
1655
|
-
}
|
|
1656
|
-
const links = await this.get(q);
|
|
1657
|
-
if (links.length > 0) remaining.push(expr);
|
|
1658
|
-
}
|
|
1659
|
-
candidates = remaining;
|
|
1660
|
-
}
|
|
1661
|
-
|
|
1662
|
-
return candidates.map(c => ({ base: c }));
|
|
1663
|
-
}
|
|
1669
|
+
// Build a single SPARQL SELECT with all required triple patterns joined
|
|
1670
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1671
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1672
|
+
return `?base <${t.predicate}> ${target} .`;
|
|
1673
|
+
}).join('\n ');
|
|
1664
1674
|
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1671
|
-
if (!metadata) {
|
|
1672
|
-
return undefined;
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
const propMeta = metadata.properties.get(propertyName);
|
|
1676
|
-
if (!propMeta) {
|
|
1677
|
-
return undefined;
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
const links = await this.get(new LinkQuery({ source: baseExpression, predicate: propMeta.predicate }));
|
|
1681
|
-
|
|
1682
|
-
if (!links || links.length === 0) {
|
|
1683
|
-
return undefined;
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
const value = links[0].data.target;
|
|
1687
|
-
|
|
1688
|
-
// Handle expression resolution if needed
|
|
1689
|
-
if (propMeta.resolveLanguage && value) {
|
|
1690
|
-
try {
|
|
1691
|
-
const expression = await this.getExpression(value);
|
|
1692
|
-
try {
|
|
1693
|
-
return JSON.parse(expression.data);
|
|
1694
|
-
} catch (e) {
|
|
1695
|
-
return expression.data;
|
|
1696
|
-
}
|
|
1697
|
-
} catch (err) {
|
|
1698
|
-
return value;
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1701
|
-
|
|
1702
|
-
return value;
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
/**
|
|
1706
|
-
* Gets relation values using SPARQL when Prolog fails.
|
|
1707
|
-
* This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
|
|
1708
|
-
* Note: This is used by Subject.ts (legacy pattern). Ad4mModel.ts uses getModelMetadata() instead.
|
|
1709
|
-
*/
|
|
1710
|
-
async getRelationValuesViaSparql(baseExpression: string, className: string, relationName: string): Promise<any[]> {
|
|
1711
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1712
|
-
if (!metadata) {
|
|
1713
|
-
return [];
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
const relMeta = metadata.relations.get(relationName);
|
|
1717
|
-
if (!relMeta) {
|
|
1718
|
-
return [];
|
|
1719
|
-
}
|
|
1720
|
-
|
|
1721
|
-
const links = await this.get(new LinkQuery({ source: baseExpression, predicate: relMeta.predicate }));
|
|
1722
|
-
|
|
1723
|
-
if (!links || links.length === 0) {
|
|
1724
|
-
return [];
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
// Sort by timestamp ascending
|
|
1728
|
-
links.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
1729
|
-
|
|
1730
|
-
let values = links.map(l => l.data.target).filter(v => v !== "" && v !== '');
|
|
1731
|
-
|
|
1732
|
-
// Apply condition filtering if present
|
|
1733
|
-
if (relMeta.condition && values.length > 0) {
|
|
1734
|
-
try {
|
|
1735
|
-
const filteredValues: string[] = [];
|
|
1736
|
-
|
|
1737
|
-
for (const value of values) {
|
|
1738
|
-
let condition = relMeta.condition
|
|
1739
|
-
.replace(/\$perspective/g, `'${this.uuid}'`)
|
|
1740
|
-
.replace(/\$base/g, `'${baseExpression}'`)
|
|
1741
|
-
.replace(/Target/g, `'${value.replace(/'/g, "\\'")}'`);
|
|
1742
|
-
|
|
1743
|
-
// Parse condition to extract link query parameters
|
|
1744
|
-
// Conditions typically look like: WHERE in.uri = 'X' AND predicate = 'Y' AND out.uri = 'Z'
|
|
1745
|
-
// or: array::len(SELECT * FROM link WHERE ...) > 0
|
|
1746
|
-
// Convert to queryLinks calls
|
|
1747
|
-
const sourceMatch = condition.match(/in\.uri\s*=\s*'([^']+)'/);
|
|
1748
|
-
const predicateMatch = condition.match(/predicate\s*=\s*'([^']+)'/);
|
|
1749
|
-
const targetMatch = condition.match(/out\.uri\s*=\s*'([^']+)'/);
|
|
1750
|
-
|
|
1751
|
-
if (sourceMatch || predicateMatch || targetMatch) {
|
|
1752
|
-
const linkQuery: any = {};
|
|
1753
|
-
if (sourceMatch) linkQuery.source = sourceMatch[1];
|
|
1754
|
-
if (predicateMatch) linkQuery.predicate = predicateMatch[1];
|
|
1755
|
-
if (targetMatch) linkQuery.target = targetMatch[1];
|
|
1756
|
-
|
|
1757
|
-
const matchingLinks = await this.get(new LinkQuery(linkQuery));
|
|
1758
|
-
if (matchingLinks.length > 0) {
|
|
1759
|
-
filteredValues.push(value);
|
|
1760
|
-
}
|
|
1761
|
-
} else {
|
|
1762
|
-
// Can't parse condition, include by default
|
|
1763
|
-
filteredValues.push(value);
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
values = filteredValues;
|
|
1768
|
-
} catch (error) {
|
|
1769
|
-
console.warn(`Failed to apply condition filter for ${relationName}:`, error);
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
|
|
1773
|
-
// Apply instance filter if present - batch-check all values at once
|
|
1774
|
-
if (relMeta.instanceFilter) {
|
|
1775
|
-
try {
|
|
1776
|
-
const filterMetadata = await this.getSubjectClassMetadataFromSDNA(relMeta.instanceFilter);
|
|
1777
|
-
if (!filterMetadata) {
|
|
1778
|
-
// Fallback to sequential checks if metadata isn't available
|
|
1779
|
-
return this.filterInstancesSequential(values, relMeta.instanceFilter);
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
return await this.batchCheckSubjectInstances(values, filterMetadata);
|
|
1783
|
-
} catch (err) {
|
|
1784
|
-
// Fallback to sequential checks on error
|
|
1785
|
-
return this.filterInstancesSequential(values, relMeta.instanceFilter);
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
return values;
|
|
1790
|
-
}
|
|
1791
|
-
|
|
1792
|
-
/**
|
|
1793
|
-
* Batch-checks multiple expressions against subject class metadata using a single or limited SPARQL queries.
|
|
1794
|
-
* This avoids N+1 query problems by checking all values at once.
|
|
1795
|
-
*/
|
|
1796
|
-
async batchCheckSubjectInstances(
|
|
1797
|
-
expressions: string[],
|
|
1798
|
-
metadata: {
|
|
1799
|
-
requiredPredicates: string[],
|
|
1800
|
-
requiredTriples: Array<{predicate: string, target?: string}>,
|
|
1801
|
-
properties: Map<string, { predicate: string, resolveLanguage?: string }>,
|
|
1802
|
-
relations: Map<string, { predicate: string, instanceFilter?: string, condition?: string }>
|
|
1803
|
-
}
|
|
1804
|
-
): Promise<string[]> {
|
|
1805
|
-
if (expressions.length === 0) {
|
|
1806
|
-
return [];
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
// If no required triples, check which expressions have any links
|
|
1810
|
-
if (metadata.requiredTriples.length === 0) {
|
|
1811
|
-
const results: string[] = [];
|
|
1812
|
-
for (const expr of expressions) {
|
|
1813
|
-
const links = await this.get(new LinkQuery({ source: expr }));
|
|
1814
|
-
if (links.length > 0) results.push(expr);
|
|
1815
|
-
}
|
|
1816
|
-
return results;
|
|
1817
|
-
}
|
|
1818
|
-
|
|
1819
|
-
// For each required triple, find which expressions match
|
|
1820
|
-
const validExpressionSets: Set<string>[] = [];
|
|
1821
|
-
|
|
1822
|
-
for (const triple of metadata.requiredTriples) {
|
|
1823
|
-
const matchingExprs = new Set<string>();
|
|
1824
|
-
for (const expr of expressions) {
|
|
1825
|
-
let query: LinkQuery;
|
|
1826
|
-
if (triple.target) {
|
|
1827
|
-
query = new LinkQuery({ source: expr, predicate: triple.predicate, target: triple.target });
|
|
1828
|
-
} else {
|
|
1829
|
-
query = new LinkQuery({ source: expr, predicate: triple.predicate });
|
|
1830
|
-
}
|
|
1831
|
-
const links = await this.get(query);
|
|
1832
|
-
if (links.length > 0) matchingExprs.add(expr);
|
|
1833
|
-
}
|
|
1834
|
-
validExpressionSets.push(matchingExprs);
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
// Find intersection: expressions that passed ALL required triple checks
|
|
1838
|
-
if (validExpressionSets.length === 0) {
|
|
1839
|
-
return expressions;
|
|
1840
|
-
}
|
|
1841
|
-
|
|
1842
|
-
const firstSet = validExpressionSets[0];
|
|
1843
|
-
const validExpressions = expressions.filter(expr => {
|
|
1844
|
-
return validExpressionSets.every(set => set.has(expr));
|
|
1845
|
-
});
|
|
1846
|
-
|
|
1847
|
-
return validExpressions;
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
/**
|
|
1851
|
-
* Fallback sequential instance checking when batch checking isn't available.
|
|
1852
|
-
*/
|
|
1853
|
-
private async filterInstancesSequential(values: string[], instanceFilter: string): Promise<string[]> {
|
|
1854
|
-
const filteredValues = [];
|
|
1855
|
-
for (const value of values) {
|
|
1856
|
-
try {
|
|
1857
|
-
const isInstance = await this.isSubjectInstance(value, instanceFilter);
|
|
1858
|
-
if (isInstance) {
|
|
1859
|
-
filteredValues.push(value);
|
|
1860
|
-
}
|
|
1861
|
-
} catch (err) {
|
|
1862
|
-
// Skip values that fail instance check
|
|
1863
|
-
continue;
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
return filteredValues;
|
|
1675
|
+
const results = await this.querySparql(
|
|
1676
|
+
`SELECT DISTINCT ?base WHERE {\n ${patterns}\n}`
|
|
1677
|
+
);
|
|
1678
|
+
if (!Array.isArray(results)) return [];
|
|
1679
|
+
return results.map((row: any) => ({ base: row.base }));
|
|
1867
1680
|
}
|
|
1868
1681
|
|
|
1869
1682
|
/** Returns all subject instances of the given subject class as proxy objects.
|
|
@@ -1888,7 +1701,7 @@ export class PerspectiveProxy {
|
|
|
1888
1701
|
for(let className of classes) {
|
|
1889
1702
|
//console.log(`getAllSubjectInstances: Processing class ${className}`);
|
|
1890
1703
|
// Query SDNA for metadata, then query SPARQL for instances
|
|
1891
|
-
const metadata = await this.
|
|
1704
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1892
1705
|
//console.log(`getAllSubjectInstances: Got metadata for ${className}:`, metadata);
|
|
1893
1706
|
if (metadata) {
|
|
1894
1707
|
const results = await this.findInstancesByMetadata(metadata);
|
|
@@ -1906,9 +1719,9 @@ export class PerspectiveProxy {
|
|
|
1906
1719
|
// Load the instance data from links
|
|
1907
1720
|
await instance.get();
|
|
1908
1721
|
} else {
|
|
1909
|
-
//
|
|
1910
|
-
|
|
1911
|
-
|
|
1722
|
+
// Return plain data for string-based lookups
|
|
1723
|
+
const data = await this.getSubjectData(className, result.base);
|
|
1724
|
+
instance = { id: result.base, ...data };
|
|
1912
1725
|
}
|
|
1913
1726
|
instances.push(instance as unknown as T);
|
|
1914
1727
|
//console.log(`getAllSubjectInstances: Successfully created subject for ${result.base}`);
|
|
@@ -1924,41 +1737,6 @@ export class PerspectiveProxy {
|
|
|
1924
1737
|
return instances
|
|
1925
1738
|
}
|
|
1926
1739
|
|
|
1927
|
-
/** Returns all subject proxies of the given subject class as proxy objects.
|
|
1928
|
-
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
1929
|
-
* with the properties of the subject class. In the latter case, all subject classes
|
|
1930
|
-
* that match the given properties will be used.
|
|
1931
|
-
*/
|
|
1932
|
-
async getAllSubjectProxies<T>(subjectClass: T): Promise<T[]> {
|
|
1933
|
-
let classes = []
|
|
1934
|
-
if(typeof subjectClass === "string") {
|
|
1935
|
-
classes = [subjectClass]
|
|
1936
|
-
} else {
|
|
1937
|
-
classes = await this.subjectClassesByTemplate(subjectClass as object)
|
|
1938
|
-
}
|
|
1939
|
-
|
|
1940
|
-
let instances = []
|
|
1941
|
-
for(let className of classes) {
|
|
1942
|
-
// Query SDNA for metadata, then query SPARQL for instances
|
|
1943
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1944
|
-
if (metadata) {
|
|
1945
|
-
const results = await this.findInstancesByMetadata(metadata);
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
for (const result of results || []) {
|
|
1949
|
-
try {
|
|
1950
|
-
let subject = new Subject(this, result.base, className);
|
|
1951
|
-
await subject.init();
|
|
1952
|
-
instances.push(subject as unknown as T);
|
|
1953
|
-
} catch (e) {
|
|
1954
|
-
// Skip subjects that fail to initialize
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
return instances
|
|
1960
|
-
}
|
|
1961
|
-
|
|
1962
1740
|
|
|
1963
1741
|
/**
|
|
1964
1742
|
* Find a subject class by matching an object's properties/relations against SHACL shapes.
|
|
@@ -1994,16 +1772,17 @@ export class PerspectiveProxy {
|
|
|
1994
1772
|
return null;
|
|
1995
1773
|
}
|
|
1996
1774
|
|
|
1997
|
-
//
|
|
1998
|
-
const
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
1775
|
+
// Single SPARQL query to get all class shapes with their properties and collections
|
|
1776
|
+
const results = await this.querySparql(`
|
|
1777
|
+
SELECT ?shape ?predicate ?target WHERE {
|
|
1778
|
+
{ ?shape <rdf://type> <ad4m://SubjectClass> . BIND(<rdf://type> AS ?predicate) BIND(<ad4m://SubjectClass> AS ?target) }
|
|
1779
|
+
UNION
|
|
1780
|
+
{ ?shape <sh://property> ?target . BIND(<sh://property> AS ?predicate) }
|
|
1781
|
+
UNION
|
|
1782
|
+
{ ?shape <sh://collection> ?target . BIND(<sh://collection> AS ?predicate) }
|
|
1783
|
+
}
|
|
1784
|
+
`);
|
|
1785
|
+
if (!Array.isArray(results) || results.length === 0) return null;
|
|
2007
1786
|
|
|
2008
1787
|
// Build a map of className -> { properties, relations }
|
|
2009
1788
|
const classShapes: Map<string, { shapeUri: string, properties: string[], relations: string[] }> = new Map();
|
|
@@ -2011,7 +1790,7 @@ export class PerspectiveProxy {
|
|
|
2011
1790
|
// First pass: find all subject classes
|
|
2012
1791
|
for (const r of results) {
|
|
2013
1792
|
if (r.predicate === 'rdf://type' && r.target === 'ad4m://SubjectClass') {
|
|
2014
|
-
const source = r.
|
|
1793
|
+
const source = r.shape;
|
|
2015
1794
|
const sepIdx = source.indexOf('://');
|
|
2016
1795
|
if (sepIdx < 0) continue;
|
|
2017
1796
|
const className = source.substring(sepIdx + 3).split('/').pop();
|
|
@@ -2025,7 +1804,7 @@ export class PerspectiveProxy {
|
|
|
2025
1804
|
if (r.predicate === 'sh://property' || r.predicate === 'sh://collection') {
|
|
2026
1805
|
// Match shape source to class (e.g., "recipe://RecipeShape" -> "Recipe")
|
|
2027
1806
|
for (const [className, shape] of classShapes) {
|
|
2028
|
-
if (r.
|
|
1807
|
+
if (r.shape.endsWith(`${className}Shape`)) {
|
|
2029
1808
|
const dotIdx = r.target.lastIndexOf('.');
|
|
2030
1809
|
if (dotIdx < 0) continue;
|
|
2031
1810
|
const name = r.target.substring(dotIdx + 1);
|
|
@@ -2142,6 +1921,204 @@ export class PerspectiveProxy {
|
|
|
2142
1921
|
this.#ensuredSubjectClasses.clear();
|
|
2143
1922
|
}
|
|
2144
1923
|
|
|
1924
|
+
/**
|
|
1925
|
+
* Returns a list of all class names that have been registered as SHACL
|
|
1926
|
+
* subject classes in this perspective (via `ensureSDNASubjectClass` or `addSdna`).
|
|
1927
|
+
*
|
|
1928
|
+
* @returns Array of class name strings (e.g. `["Channel", "Message", "Task"]`)
|
|
1929
|
+
*/
|
|
1930
|
+
async listRegisteredClasses(): Promise<string[]> {
|
|
1931
|
+
const results = await this.querySparql(
|
|
1932
|
+
`SELECT DISTINCT ?class WHERE { ?class <rdf://type> <ad4m://SubjectClass> . }`
|
|
1933
|
+
);
|
|
1934
|
+
if (!Array.isArray(results)) return [];
|
|
1935
|
+
return results.map((row: any) => {
|
|
1936
|
+
const uri: string = row.class || '';
|
|
1937
|
+
// Extract class name from URI like "recipe://Recipe" or "flux://Channel"
|
|
1938
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1939
|
+
if (hashIdx >= 0) return uri.substring(hashIdx + 1);
|
|
1940
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1941
|
+
if (slashIdx >= 0) return uri.substring(slashIdx + 1);
|
|
1942
|
+
return uri;
|
|
1943
|
+
}).filter(Boolean);
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
/**
|
|
1947
|
+
* Returns the SHACL shape metadata for a registered class, including
|
|
1948
|
+
* property names, predicates, datatypes, and cardinality constraints.
|
|
1949
|
+
*
|
|
1950
|
+
* @param className - The name of the registered class
|
|
1951
|
+
* @returns Shape metadata or `null` if the class is not registered
|
|
1952
|
+
*/
|
|
1953
|
+
async getClassShape(className: string): Promise<{
|
|
1954
|
+
className: string;
|
|
1955
|
+
shapeUri: string;
|
|
1956
|
+
properties: Array<{
|
|
1957
|
+
name: string;
|
|
1958
|
+
predicate: string;
|
|
1959
|
+
datatype?: string;
|
|
1960
|
+
required: boolean;
|
|
1961
|
+
collection: boolean;
|
|
1962
|
+
writable: boolean;
|
|
1963
|
+
options?: Array<{ value: string; label?: string }>;
|
|
1964
|
+
}>;
|
|
1965
|
+
} | null> {
|
|
1966
|
+
// Find the shape URI for this class
|
|
1967
|
+
const safeName = className.replace(/['"\\]/g, '');
|
|
1968
|
+
const shapeResults = await this.querySparql(
|
|
1969
|
+
`SELECT ?shapeUri ?targetClass WHERE {
|
|
1970
|
+
?targetClass <rdf://type> <ad4m://SubjectClass> .
|
|
1971
|
+
?targetClass <ad4m://shape> ?shapeUri .
|
|
1972
|
+
FILTER(STRENDS(STR(?targetClass), "/${safeName}") || STRENDS(STR(?targetClass), "#${safeName}"))
|
|
1973
|
+
} LIMIT 1`
|
|
1974
|
+
);
|
|
1975
|
+
if (!Array.isArray(shapeResults) || shapeResults.length === 0) return null;
|
|
1976
|
+
|
|
1977
|
+
const shapeUri = shapeResults[0].shapeUri;
|
|
1978
|
+
const classUri = shapeResults[0].targetClass;
|
|
1979
|
+
|
|
1980
|
+
// Query all properties for this shape, including sh:in
|
|
1981
|
+
const propResults = await this.querySparql(
|
|
1982
|
+
`SELECT ?propShape ?path ?datatype ?minCount ?maxCount ?writable ?propType ?shIn WHERE {
|
|
1983
|
+
<${shapeUri}> <sh://property> ?propShape .
|
|
1984
|
+
?propShape <sh://path> ?path .
|
|
1985
|
+
?propShape <rdf://type> ?propType .
|
|
1986
|
+
OPTIONAL { ?propShape <sh://datatype> ?datatype }
|
|
1987
|
+
OPTIONAL { ?propShape <sh://minCount> ?minCount }
|
|
1988
|
+
OPTIONAL { ?propShape <sh://maxCount> ?maxCount }
|
|
1989
|
+
OPTIONAL { ?propShape <ad4m://writable> ?writable }
|
|
1990
|
+
OPTIONAL { ?propShape <sh://in> ?shIn }
|
|
1991
|
+
}`
|
|
1992
|
+
);
|
|
1993
|
+
|
|
1994
|
+
const properties = (Array.isArray(propResults) ? propResults : []).map((row: any) => {
|
|
1995
|
+
// Extract property name from shape URI like "recipe://Recipe.name"
|
|
1996
|
+
const propUri: string = row.propShape || '';
|
|
1997
|
+
const dotIdx = propUri.lastIndexOf('.');
|
|
1998
|
+
const name = dotIdx >= 0 ? propUri.substring(dotIdx + 1) : propUri;
|
|
1999
|
+
|
|
2000
|
+
const minCount = parseInt(row.minCount || '0', 10);
|
|
2001
|
+
const isCollection = row.propType === 'ad4m://CollectionShape';
|
|
2002
|
+
const writable = row.writable === 'true' || row.writable === 'literal:true';
|
|
2003
|
+
|
|
2004
|
+
// Parse sh:in values if present
|
|
2005
|
+
let options: Array<{ value: string; label?: string }> | undefined;
|
|
2006
|
+
if (row.shIn) {
|
|
2007
|
+
try {
|
|
2008
|
+
let raw = row.shIn;
|
|
2009
|
+
// Strip literal: prefix if present, and URI-decode for robustness
|
|
2010
|
+
if (raw.startsWith('literal:string:')) {
|
|
2011
|
+
raw = decodeURIComponent(raw.substring('literal:string:'.length));
|
|
2012
|
+
}
|
|
2013
|
+
options = JSON.parse(raw);
|
|
2014
|
+
} catch { /* ignore parse errors */ }
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
return {
|
|
2018
|
+
name,
|
|
2019
|
+
predicate: row.path || '',
|
|
2020
|
+
datatype: row.datatype || undefined,
|
|
2021
|
+
required: minCount > 0,
|
|
2022
|
+
collection: isCollection,
|
|
2023
|
+
writable,
|
|
2024
|
+
...(options && options.length > 0 ? { options } : {}),
|
|
2025
|
+
};
|
|
2026
|
+
});
|
|
2027
|
+
|
|
2028
|
+
return { className: safeName, shapeUri, properties };
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
/**
|
|
2032
|
+
* Detects which registered subject classes a given instance conforms to,
|
|
2033
|
+
* based on its stored triples matching the class shapes' required properties.
|
|
2034
|
+
*
|
|
2035
|
+
* @param baseExpression - The instance's base expression / subject URI
|
|
2036
|
+
* @returns Array of class names the instance matches
|
|
2037
|
+
*/
|
|
2038
|
+
async getInstanceClasses(baseExpression: string): Promise<string[]> {
|
|
2039
|
+
const safeId = baseExpression.replace(/['"\\]/g, '');
|
|
2040
|
+
// Get all registered classes and their required conformance properties
|
|
2041
|
+
const results = await this.querySparql(
|
|
2042
|
+
`SELECT DISTINCT ?class WHERE {
|
|
2043
|
+
?class <rdf://type> <ad4m://SubjectClass> .
|
|
2044
|
+
?class <ad4m://shape> ?shape .
|
|
2045
|
+
?shape <sh://property> ?propShape .
|
|
2046
|
+
?propShape <sh://minCount> ?mc .
|
|
2047
|
+
FILTER(?mc >= 1)
|
|
2048
|
+
?propShape <sh://path> ?path .
|
|
2049
|
+
<${safeId}> ?path ?_val .
|
|
2050
|
+
}`
|
|
2051
|
+
);
|
|
2052
|
+
if (!Array.isArray(results)) return [];
|
|
2053
|
+
return results.map((row: any) => {
|
|
2054
|
+
const uri: string = row.class || '';
|
|
2055
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
2056
|
+
if (hashIdx >= 0) return uri.substring(hashIdx + 1);
|
|
2057
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
2058
|
+
if (slashIdx >= 0) return uri.substring(slashIdx + 1);
|
|
2059
|
+
return uri;
|
|
2060
|
+
}).filter(Boolean);
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
/**
|
|
2064
|
+
* Returns all named options (sh:in values) for a registered class, grouped by property.
|
|
2065
|
+
*
|
|
2066
|
+
* @param className - The name of the registered class
|
|
2067
|
+
* @returns Record mapping property name → array of { value, label } options
|
|
2068
|
+
*/
|
|
2069
|
+
async getNamedOptions(className: string): Promise<Record<string, Array<{ value: string; label?: string }>>> {
|
|
2070
|
+
const shape = await this.getClassShape(className);
|
|
2071
|
+
if (!shape) return {};
|
|
2072
|
+
const result: Record<string, Array<{ value: string; label?: string }>> = {};
|
|
2073
|
+
for (const prop of shape.properties) {
|
|
2074
|
+
if (prop.options && prop.options.length > 0) {
|
|
2075
|
+
result[prop.name] = prop.options;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
return result;
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
/**
|
|
2082
|
+
* Adds a named option (sh:in value) to a property of a registered class.
|
|
2083
|
+
* This appends to the existing sh:in list stored on the property shape.
|
|
2084
|
+
*
|
|
2085
|
+
* @param className - The registered class name
|
|
2086
|
+
* @param propertyName - The property to add the option to
|
|
2087
|
+
* @param value - The RDF value for the option
|
|
2088
|
+
* @param label - Optional human-readable label
|
|
2089
|
+
*/
|
|
2090
|
+
async addNamedOption(className: string, propertyName: string, value: string, label?: string): Promise<void> {
|
|
2091
|
+
const shape = await this.getClassShape(className);
|
|
2092
|
+
if (!shape) throw new Error(`Class "${className}" not found`);
|
|
2093
|
+
|
|
2094
|
+
const prop = shape.properties.find(p => p.name === propertyName);
|
|
2095
|
+
if (!prop) throw new Error(`Property "${propertyName}" not found on class "${className}"`);
|
|
2096
|
+
|
|
2097
|
+
// Build the property shape URI
|
|
2098
|
+
const ns = extractNamespaceFromUri(shape.shapeUri);
|
|
2099
|
+
const propShapeId = `${ns}${className}.${propertyName}`;
|
|
2100
|
+
|
|
2101
|
+
// Get existing options
|
|
2102
|
+
const existing = prop.options || [];
|
|
2103
|
+
// Don't add duplicates
|
|
2104
|
+
if (existing.some(o => o.value === value)) return;
|
|
2105
|
+
|
|
2106
|
+
const updated = [...existing, { value, ...(label ? { label } : {}) }];
|
|
2107
|
+
|
|
2108
|
+
// Remove old sh:in link if exists by querying for it
|
|
2109
|
+
const oldLinks = await this.get(new LinkQuery({ source: propShapeId, predicate: "sh://in" }));
|
|
2110
|
+
for (const oldLink of oldLinks) {
|
|
2111
|
+
await this.remove(oldLink);
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
// Add new sh:in link
|
|
2115
|
+
await this.add(new Link({
|
|
2116
|
+
source: propShapeId,
|
|
2117
|
+
predicate: "sh://in",
|
|
2118
|
+
target: `literal:string:${JSON.stringify(updated)}`
|
|
2119
|
+
}));
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2145
2122
|
getNeighbourhoodProxy(): NeighbourhoodProxy {
|
|
2146
2123
|
return this.#client.getNeighbourhoodProxy(this.#handle.uuid)
|
|
2147
2124
|
}
|