@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
|
@@ -13,17 +13,29 @@ var _QuerySubscriptionProxy_instances, _QuerySubscriptionProxy_uuid, _QuerySubsc
|
|
|
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
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
|
|
@@ -104,22 +116,31 @@ export class QuerySubscriptionProxy {
|
|
|
104
116
|
let initialResult;
|
|
105
117
|
initialResult = await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
106
118
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_subscriptionId, initialResult.subscriptionId, "f");
|
|
107
|
-
// Process the initial result immediately for fast UX
|
|
108
|
-
|
|
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) {
|
|
109
124
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_latestResult, initialResult.result, "f");
|
|
110
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
|
+
}
|
|
111
131
|
}
|
|
112
132
|
else {
|
|
113
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");
|
|
114
143
|
}
|
|
115
|
-
// Set up timeout for retry
|
|
116
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initTimeoutId, setTimeout(() => {
|
|
117
|
-
console.error('Subscription initialization timed out after 30 seconds. Resubscribing...');
|
|
118
|
-
// Recursively retry subscription, catching any errors
|
|
119
|
-
this.subscribe().catch(error => {
|
|
120
|
-
console.error('Error during subscription retry after timeout:', error);
|
|
121
|
-
});
|
|
122
|
-
}, 30000), "f");
|
|
123
144
|
// Subscribe to query updates
|
|
124
145
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_unsubscribe, __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(__classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"), (updateResult) => {
|
|
125
146
|
// Clear timeout on first message
|
|
@@ -242,7 +263,7 @@ export class QuerySubscriptionProxy {
|
|
|
242
263
|
*
|
|
243
264
|
* This method:
|
|
244
265
|
* 1. Stops the keepalive timer
|
|
245
|
-
* 2. Unsubscribes from
|
|
266
|
+
* 2. Unsubscribes from subscription updates
|
|
246
267
|
* 3. Clears all registered callbacks
|
|
247
268
|
* 4. Cleans up any pending initialization timeout
|
|
248
269
|
*
|
|
@@ -317,6 +338,8 @@ _QuerySubscriptionProxy_uuid = new WeakMap(), _QuerySubscriptionProxy_subscripti
|
|
|
317
338
|
* ```
|
|
318
339
|
*/
|
|
319
340
|
export class PerspectiveProxy {
|
|
341
|
+
/** @internal Exposed for ModelQueryBuilder subscription management */
|
|
342
|
+
get client() { return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f"); }
|
|
320
343
|
/**
|
|
321
344
|
* Creates a new PerspectiveProxy instance.
|
|
322
345
|
* Note: Don't create this directly, use ad4m.perspective.add() instead.
|
|
@@ -351,6 +374,21 @@ export class PerspectiveProxy {
|
|
|
351
374
|
__classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addPerspectiveLinkUpdatedListener(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, "f"));
|
|
352
375
|
__classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addPerspectiveSyncStateChangeListener(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, __classPrivateFieldGet(this, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, "f"));
|
|
353
376
|
}
|
|
377
|
+
/** Update the proxy's internal handle and public fields in-place.
|
|
378
|
+
* Keeps the same object reference so all holders see the update. */
|
|
379
|
+
updateHandle(handle) {
|
|
380
|
+
if (handle.uuid !== __classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid) {
|
|
381
|
+
throw new Error(`PerspectiveProxy.updateHandle: UUID mismatch — proxy is bound to "${__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid}" but received handle with UUID "${handle.uuid}". ` +
|
|
382
|
+
`This would silently diverge from listeners registered under the original UUID.`);
|
|
383
|
+
}
|
|
384
|
+
__classPrivateFieldSet(this, _PerspectiveProxy_handle, handle, "f");
|
|
385
|
+
this.uuid = handle.uuid;
|
|
386
|
+
this.name = handle.name;
|
|
387
|
+
this.owners = handle.owners;
|
|
388
|
+
this.sharedUrl = handle.sharedUrl;
|
|
389
|
+
this.neighbourhood = handle.neighbourhood;
|
|
390
|
+
this.state = handle.state;
|
|
391
|
+
}
|
|
354
392
|
/**
|
|
355
393
|
* Escapes special regex characters in a string to prevent ReDoS attacks
|
|
356
394
|
* and regex injection when building dynamic regular expressions.
|
|
@@ -502,6 +540,33 @@ export class PerspectiveProxy {
|
|
|
502
540
|
setCachedResult(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query, result);
|
|
503
541
|
return result;
|
|
504
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Execute a model query — the executor-side replacement for SPARQL query building + JS hydration.
|
|
545
|
+
*
|
|
546
|
+
* @param className - The model class name (e.g. "Recipe")
|
|
547
|
+
* @param queryJson - Structured query as JSON string
|
|
548
|
+
* @param shapeJson - Optional shape metadata JSON from the model class
|
|
549
|
+
* @returns Object with `instances` array and `totalCount`
|
|
550
|
+
*/
|
|
551
|
+
async modelQuery(className, queryJson, shapeJson) {
|
|
552
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Subscribe to model query changes. Builds trigger SPARQL from the model shape
|
|
556
|
+
* internally in Rust, registers a subscription, runs the initial query, and
|
|
557
|
+
* pushes updated results when relevant links change.
|
|
558
|
+
*
|
|
559
|
+
* The subscription reuses the same GraphQL subscription channel as subscribeQuery().
|
|
560
|
+
* Use keepAliveQuery() / disposeQuerySubscription() with the returned subscriptionId.
|
|
561
|
+
*
|
|
562
|
+
* @param className - The model class name
|
|
563
|
+
* @param queryJson - JSON-serialized query parameters (same as modelQuery)
|
|
564
|
+
* @param shapeJson - Optional shape metadata JSON from the model class
|
|
565
|
+
* @returns Object with `subscriptionId` and initial `result`
|
|
566
|
+
*/
|
|
567
|
+
async modelSubscribe(className, queryJson, shapeJson) {
|
|
568
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
|
|
569
|
+
}
|
|
505
570
|
/**
|
|
506
571
|
* Adds a new link to the perspective.
|
|
507
572
|
*
|
|
@@ -969,7 +1034,7 @@ export class PerspectiveProxy {
|
|
|
969
1034
|
* Adds Social DNA code to the perspective.
|
|
970
1035
|
*
|
|
971
1036
|
* **Recommended:** Use {@link addShacl} instead, which accepts the `SHACLShape` type directly.
|
|
972
|
-
* This method is primarily for the
|
|
1037
|
+
* This method is primarily for the RPC API layer and legacy Prolog code.
|
|
973
1038
|
*
|
|
974
1039
|
* @param name - Unique name for this SDNA definition
|
|
975
1040
|
* @param sdnaCode - Prolog SDNA code (legacy, can be empty string if shaclJson provided)
|
|
@@ -1204,7 +1269,7 @@ export class PerspectiveProxy {
|
|
|
1204
1269
|
*/
|
|
1205
1270
|
async subjectClasses() {
|
|
1206
1271
|
try {
|
|
1207
|
-
// Query SHACL class links directly — no need for a separate
|
|
1272
|
+
// Query SHACL class links directly — no need for a separate RPC endpoint
|
|
1208
1273
|
const classLinks = await this.get(new LinkQuery({
|
|
1209
1274
|
predicate: "rdf://type",
|
|
1210
1275
|
target: "ad4m://SubjectClass"
|
|
@@ -1277,7 +1342,9 @@ export class PerspectiveProxy {
|
|
|
1277
1342
|
if (batchId) {
|
|
1278
1343
|
return exprAddr;
|
|
1279
1344
|
}
|
|
1280
|
-
|
|
1345
|
+
// Return the expression address directly — callers should use Ad4mModel or
|
|
1346
|
+
// getSubjectData() to interact with the created instance.
|
|
1347
|
+
return exprAddr;
|
|
1281
1348
|
}
|
|
1282
1349
|
async getSubjectData(subjectClass, exprAddr) {
|
|
1283
1350
|
if (typeof subjectClass === "string") {
|
|
@@ -1353,7 +1420,7 @@ export class PerspectiveProxy {
|
|
|
1353
1420
|
async isSubjectInstance(expression, subjectClass) {
|
|
1354
1421
|
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
|
|
1355
1422
|
// Get metadata from SHACL links
|
|
1356
|
-
const metadata = await this.
|
|
1423
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1357
1424
|
if (!metadata) {
|
|
1358
1425
|
console.warn(`isSubjectInstance: No SHACL metadata found for class ${className}`);
|
|
1359
1426
|
return false;
|
|
@@ -1363,49 +1430,19 @@ export class PerspectiveProxy {
|
|
|
1363
1430
|
const links = await this.get(new LinkQuery({ source: expression }));
|
|
1364
1431
|
return links.length > 0;
|
|
1365
1432
|
}
|
|
1366
|
-
//
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
query = new LinkQuery({ source: expression, predicate: triple.predicate });
|
|
1374
|
-
}
|
|
1375
|
-
const links = await this.get(query);
|
|
1376
|
-
if (!links || links.length === 0) {
|
|
1377
|
-
return false;
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
return true;
|
|
1381
|
-
}
|
|
1382
|
-
/** For an existing subject instance (existing in the perspective's links)
|
|
1383
|
-
* this function returns a proxy object that can be used to access the subject's
|
|
1384
|
-
* properties and methods.
|
|
1385
|
-
*
|
|
1386
|
-
* @param base URI of the subject's root expression
|
|
1387
|
-
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
1388
|
-
* with the properties of the subject class. In the latter case, the first subject class
|
|
1389
|
-
* that matches the given properties will be used.
|
|
1390
|
-
*/
|
|
1391
|
-
async getSubjectProxy(base, subjectClass) {
|
|
1392
|
-
if (!await this.isSubjectInstance(base, subjectClass)) {
|
|
1393
|
-
throw `Expression ${base} is not a subject instance of given class: ${JSON.stringify(subjectClass)}`;
|
|
1394
|
-
}
|
|
1395
|
-
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
|
|
1396
|
-
let subject = new Subject(this, base, className);
|
|
1397
|
-
await subject.init();
|
|
1398
|
-
return subject;
|
|
1433
|
+
// Build a single SPARQL ASK query with all required triple patterns
|
|
1434
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1435
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1436
|
+
return `<${expression}> <${t.predicate}> ${target} .`;
|
|
1437
|
+
}).join('\n ');
|
|
1438
|
+
const result = await this.querySparql(`ASK WHERE {\n ${patterns}\n}`);
|
|
1439
|
+
return result === true;
|
|
1399
1440
|
}
|
|
1400
1441
|
/**
|
|
1401
1442
|
* Gets subject class metadata from SHACL links using SHACLShape.fromLinks().
|
|
1402
1443
|
* Retrieves the SHACL shape and extracts metadata for instance queries.
|
|
1403
1444
|
*/
|
|
1404
1445
|
async getSubjectClassMetadata(className) {
|
|
1405
|
-
return this.getSubjectClassMetadataFromSDNA(className);
|
|
1406
|
-
}
|
|
1407
|
-
/** @deprecated Use getSubjectClassMetadata() */
|
|
1408
|
-
async getSubjectClassMetadataFromSDNA(className) {
|
|
1409
1446
|
try {
|
|
1410
1447
|
// Use getShacl() to retrieve the shape via SHACLShape.fromLinks()
|
|
1411
1448
|
const shape = await this.getShacl(className);
|
|
@@ -1472,214 +1509,15 @@ export class PerspectiveProxy {
|
|
|
1472
1509
|
const sources = new Set(allLinks.map(l => l.data.source));
|
|
1473
1510
|
return Array.from(sources).map(s => ({ base: s }));
|
|
1474
1511
|
}
|
|
1475
|
-
//
|
|
1476
|
-
const
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
query = new LinkQuery({ predicate: first.predicate });
|
|
1483
|
-
}
|
|
1484
|
-
const candidateLinks = await this.get(query);
|
|
1485
|
-
let candidates = [...new Set(candidateLinks.map(l => l.data.source))];
|
|
1486
|
-
// Filter by remaining required triples
|
|
1487
|
-
for (let i = 1; i < metadata.requiredTriples.length; i++) {
|
|
1488
|
-
const triple = metadata.requiredTriples[i];
|
|
1489
|
-
const remaining = [];
|
|
1490
|
-
for (const expr of candidates) {
|
|
1491
|
-
let q;
|
|
1492
|
-
if (triple.target) {
|
|
1493
|
-
q = new LinkQuery({ source: expr, predicate: triple.predicate, target: triple.target });
|
|
1494
|
-
}
|
|
1495
|
-
else {
|
|
1496
|
-
q = new LinkQuery({ source: expr, predicate: triple.predicate });
|
|
1497
|
-
}
|
|
1498
|
-
const links = await this.get(q);
|
|
1499
|
-
if (links.length > 0)
|
|
1500
|
-
remaining.push(expr);
|
|
1501
|
-
}
|
|
1502
|
-
candidates = remaining;
|
|
1503
|
-
}
|
|
1504
|
-
return candidates.map(c => ({ base: c }));
|
|
1505
|
-
}
|
|
1506
|
-
/**
|
|
1507
|
-
* Gets a property value using SPARQL when Prolog fails.
|
|
1508
|
-
* This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
|
|
1509
|
-
*/
|
|
1510
|
-
async getPropertyValueViaSparql(baseExpression, className, propertyName) {
|
|
1511
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1512
|
-
if (!metadata) {
|
|
1513
|
-
return undefined;
|
|
1514
|
-
}
|
|
1515
|
-
const propMeta = metadata.properties.get(propertyName);
|
|
1516
|
-
if (!propMeta) {
|
|
1517
|
-
return undefined;
|
|
1518
|
-
}
|
|
1519
|
-
const links = await this.get(new LinkQuery({ source: baseExpression, predicate: propMeta.predicate }));
|
|
1520
|
-
if (!links || links.length === 0) {
|
|
1521
|
-
return undefined;
|
|
1522
|
-
}
|
|
1523
|
-
const value = links[0].data.target;
|
|
1524
|
-
// Handle expression resolution if needed
|
|
1525
|
-
if (propMeta.resolveLanguage && value) {
|
|
1526
|
-
try {
|
|
1527
|
-
const expression = await this.getExpression(value);
|
|
1528
|
-
try {
|
|
1529
|
-
return JSON.parse(expression.data);
|
|
1530
|
-
}
|
|
1531
|
-
catch (e) {
|
|
1532
|
-
return expression.data;
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
catch (err) {
|
|
1536
|
-
return value;
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
return value;
|
|
1540
|
-
}
|
|
1541
|
-
/**
|
|
1542
|
-
* Gets relation values using SPARQL when Prolog fails.
|
|
1543
|
-
* This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
|
|
1544
|
-
* Note: This is used by Subject.ts (legacy pattern). Ad4mModel.ts uses getModelMetadata() instead.
|
|
1545
|
-
*/
|
|
1546
|
-
async getRelationValuesViaSparql(baseExpression, className, relationName) {
|
|
1547
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1548
|
-
if (!metadata) {
|
|
1549
|
-
return [];
|
|
1550
|
-
}
|
|
1551
|
-
const relMeta = metadata.relations.get(relationName);
|
|
1552
|
-
if (!relMeta) {
|
|
1553
|
-
return [];
|
|
1554
|
-
}
|
|
1555
|
-
const links = await this.get(new LinkQuery({ source: baseExpression, predicate: relMeta.predicate }));
|
|
1556
|
-
if (!links || links.length === 0) {
|
|
1557
|
-
return [];
|
|
1558
|
-
}
|
|
1559
|
-
// Sort by timestamp ascending
|
|
1560
|
-
links.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
1561
|
-
let values = links.map(l => l.data.target).filter(v => v !== "" && v !== '');
|
|
1562
|
-
// Apply condition filtering if present
|
|
1563
|
-
if (relMeta.condition && values.length > 0) {
|
|
1564
|
-
try {
|
|
1565
|
-
const filteredValues = [];
|
|
1566
|
-
for (const value of values) {
|
|
1567
|
-
let condition = relMeta.condition
|
|
1568
|
-
.replace(/\$perspective/g, `'${this.uuid}'`)
|
|
1569
|
-
.replace(/\$base/g, `'${baseExpression}'`)
|
|
1570
|
-
.replace(/Target/g, `'${value.replace(/'/g, "\\'")}'`);
|
|
1571
|
-
// Parse condition to extract link query parameters
|
|
1572
|
-
// Conditions typically look like: WHERE in.uri = 'X' AND predicate = 'Y' AND out.uri = 'Z'
|
|
1573
|
-
// or: array::len(SELECT * FROM link WHERE ...) > 0
|
|
1574
|
-
// Convert to queryLinks calls
|
|
1575
|
-
const sourceMatch = condition.match(/in\.uri\s*=\s*'([^']+)'/);
|
|
1576
|
-
const predicateMatch = condition.match(/predicate\s*=\s*'([^']+)'/);
|
|
1577
|
-
const targetMatch = condition.match(/out\.uri\s*=\s*'([^']+)'/);
|
|
1578
|
-
if (sourceMatch || predicateMatch || targetMatch) {
|
|
1579
|
-
const linkQuery = {};
|
|
1580
|
-
if (sourceMatch)
|
|
1581
|
-
linkQuery.source = sourceMatch[1];
|
|
1582
|
-
if (predicateMatch)
|
|
1583
|
-
linkQuery.predicate = predicateMatch[1];
|
|
1584
|
-
if (targetMatch)
|
|
1585
|
-
linkQuery.target = targetMatch[1];
|
|
1586
|
-
const matchingLinks = await this.get(new LinkQuery(linkQuery));
|
|
1587
|
-
if (matchingLinks.length > 0) {
|
|
1588
|
-
filteredValues.push(value);
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
else {
|
|
1592
|
-
// Can't parse condition, include by default
|
|
1593
|
-
filteredValues.push(value);
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
values = filteredValues;
|
|
1597
|
-
}
|
|
1598
|
-
catch (error) {
|
|
1599
|
-
console.warn(`Failed to apply condition filter for ${relationName}:`, error);
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
// Apply instance filter if present - batch-check all values at once
|
|
1603
|
-
if (relMeta.instanceFilter) {
|
|
1604
|
-
try {
|
|
1605
|
-
const filterMetadata = await this.getSubjectClassMetadataFromSDNA(relMeta.instanceFilter);
|
|
1606
|
-
if (!filterMetadata) {
|
|
1607
|
-
// Fallback to sequential checks if metadata isn't available
|
|
1608
|
-
return this.filterInstancesSequential(values, relMeta.instanceFilter);
|
|
1609
|
-
}
|
|
1610
|
-
return await this.batchCheckSubjectInstances(values, filterMetadata);
|
|
1611
|
-
}
|
|
1612
|
-
catch (err) {
|
|
1613
|
-
// Fallback to sequential checks on error
|
|
1614
|
-
return this.filterInstancesSequential(values, relMeta.instanceFilter);
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
return values;
|
|
1618
|
-
}
|
|
1619
|
-
/**
|
|
1620
|
-
* Batch-checks multiple expressions against subject class metadata using a single or limited SPARQL queries.
|
|
1621
|
-
* This avoids N+1 query problems by checking all values at once.
|
|
1622
|
-
*/
|
|
1623
|
-
async batchCheckSubjectInstances(expressions, metadata) {
|
|
1624
|
-
if (expressions.length === 0) {
|
|
1512
|
+
// Build a single SPARQL SELECT with all required triple patterns joined
|
|
1513
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1514
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1515
|
+
return `?base <${t.predicate}> ${target} .`;
|
|
1516
|
+
}).join('\n ');
|
|
1517
|
+
const results = await this.querySparql(`SELECT DISTINCT ?base WHERE {\n ${patterns}\n}`);
|
|
1518
|
+
if (!Array.isArray(results))
|
|
1625
1519
|
return [];
|
|
1626
|
-
}
|
|
1627
|
-
// If no required triples, check which expressions have any links
|
|
1628
|
-
if (metadata.requiredTriples.length === 0) {
|
|
1629
|
-
const results = [];
|
|
1630
|
-
for (const expr of expressions) {
|
|
1631
|
-
const links = await this.get(new LinkQuery({ source: expr }));
|
|
1632
|
-
if (links.length > 0)
|
|
1633
|
-
results.push(expr);
|
|
1634
|
-
}
|
|
1635
|
-
return results;
|
|
1636
|
-
}
|
|
1637
|
-
// For each required triple, find which expressions match
|
|
1638
|
-
const validExpressionSets = [];
|
|
1639
|
-
for (const triple of metadata.requiredTriples) {
|
|
1640
|
-
const matchingExprs = new Set();
|
|
1641
|
-
for (const expr of expressions) {
|
|
1642
|
-
let query;
|
|
1643
|
-
if (triple.target) {
|
|
1644
|
-
query = new LinkQuery({ source: expr, predicate: triple.predicate, target: triple.target });
|
|
1645
|
-
}
|
|
1646
|
-
else {
|
|
1647
|
-
query = new LinkQuery({ source: expr, predicate: triple.predicate });
|
|
1648
|
-
}
|
|
1649
|
-
const links = await this.get(query);
|
|
1650
|
-
if (links.length > 0)
|
|
1651
|
-
matchingExprs.add(expr);
|
|
1652
|
-
}
|
|
1653
|
-
validExpressionSets.push(matchingExprs);
|
|
1654
|
-
}
|
|
1655
|
-
// Find intersection: expressions that passed ALL required triple checks
|
|
1656
|
-
if (validExpressionSets.length === 0) {
|
|
1657
|
-
return expressions;
|
|
1658
|
-
}
|
|
1659
|
-
const firstSet = validExpressionSets[0];
|
|
1660
|
-
const validExpressions = expressions.filter(expr => {
|
|
1661
|
-
return validExpressionSets.every(set => set.has(expr));
|
|
1662
|
-
});
|
|
1663
|
-
return validExpressions;
|
|
1664
|
-
}
|
|
1665
|
-
/**
|
|
1666
|
-
* Fallback sequential instance checking when batch checking isn't available.
|
|
1667
|
-
*/
|
|
1668
|
-
async filterInstancesSequential(values, instanceFilter) {
|
|
1669
|
-
const filteredValues = [];
|
|
1670
|
-
for (const value of values) {
|
|
1671
|
-
try {
|
|
1672
|
-
const isInstance = await this.isSubjectInstance(value, instanceFilter);
|
|
1673
|
-
if (isInstance) {
|
|
1674
|
-
filteredValues.push(value);
|
|
1675
|
-
}
|
|
1676
|
-
}
|
|
1677
|
-
catch (err) {
|
|
1678
|
-
// Skip values that fail instance check
|
|
1679
|
-
continue;
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
return filteredValues;
|
|
1520
|
+
return results.map((row) => ({ base: row.base }));
|
|
1683
1521
|
}
|
|
1684
1522
|
/** Returns all subject instances of the given subject class as proxy objects.
|
|
1685
1523
|
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
@@ -1704,7 +1542,7 @@ export class PerspectiveProxy {
|
|
|
1704
1542
|
for (let className of classes) {
|
|
1705
1543
|
//console.log(`getAllSubjectInstances: Processing class ${className}`);
|
|
1706
1544
|
// Query SDNA for metadata, then query SPARQL for instances
|
|
1707
|
-
const metadata = await this.
|
|
1545
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1708
1546
|
//console.log(`getAllSubjectInstances: Got metadata for ${className}:`, metadata);
|
|
1709
1547
|
if (metadata) {
|
|
1710
1548
|
const results = await this.findInstancesByMetadata(metadata);
|
|
@@ -1721,9 +1559,9 @@ export class PerspectiveProxy {
|
|
|
1721
1559
|
await instance.get();
|
|
1722
1560
|
}
|
|
1723
1561
|
else {
|
|
1724
|
-
//
|
|
1725
|
-
|
|
1726
|
-
|
|
1562
|
+
// Return plain data for string-based lookups
|
|
1563
|
+
const data = await this.getSubjectData(className, result.base);
|
|
1564
|
+
instance = { id: result.base, ...data };
|
|
1727
1565
|
}
|
|
1728
1566
|
instances.push(instance);
|
|
1729
1567
|
//console.log(`getAllSubjectInstances: Successfully created subject for ${result.base}`);
|
|
@@ -1740,39 +1578,6 @@ export class PerspectiveProxy {
|
|
|
1740
1578
|
//console.log(`getAllSubjectInstances: Returning ${instances.length} instances`);
|
|
1741
1579
|
return instances;
|
|
1742
1580
|
}
|
|
1743
|
-
/** Returns all subject proxies of the given subject class as proxy objects.
|
|
1744
|
-
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
1745
|
-
* with the properties of the subject class. In the latter case, all subject classes
|
|
1746
|
-
* that match the given properties will be used.
|
|
1747
|
-
*/
|
|
1748
|
-
async getAllSubjectProxies(subjectClass) {
|
|
1749
|
-
let classes = [];
|
|
1750
|
-
if (typeof subjectClass === "string") {
|
|
1751
|
-
classes = [subjectClass];
|
|
1752
|
-
}
|
|
1753
|
-
else {
|
|
1754
|
-
classes = await this.subjectClassesByTemplate(subjectClass);
|
|
1755
|
-
}
|
|
1756
|
-
let instances = [];
|
|
1757
|
-
for (let className of classes) {
|
|
1758
|
-
// Query SDNA for metadata, then query SPARQL for instances
|
|
1759
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1760
|
-
if (metadata) {
|
|
1761
|
-
const results = await this.findInstancesByMetadata(metadata);
|
|
1762
|
-
for (const result of results || []) {
|
|
1763
|
-
try {
|
|
1764
|
-
let subject = new Subject(this, result.base, className);
|
|
1765
|
-
await subject.init();
|
|
1766
|
-
instances.push(subject);
|
|
1767
|
-
}
|
|
1768
|
-
catch (e) {
|
|
1769
|
-
// Skip subjects that fail to initialize
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
return instances;
|
|
1775
|
-
}
|
|
1776
1581
|
/**
|
|
1777
1582
|
* Find a subject class by matching an object's properties/relations against SHACL shapes.
|
|
1778
1583
|
* Queries SHACL links client-side to find a class whose properties contain all required ones.
|
|
@@ -1803,23 +1608,24 @@ export class PerspectiveProxy {
|
|
|
1803
1608
|
if (properties.length === 0 && relations.length === 0) {
|
|
1804
1609
|
return null;
|
|
1805
1610
|
}
|
|
1806
|
-
//
|
|
1807
|
-
const
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1611
|
+
// Single SPARQL query to get all class shapes with their properties and collections
|
|
1612
|
+
const results = await this.querySparql(`
|
|
1613
|
+
SELECT ?shape ?predicate ?target WHERE {
|
|
1614
|
+
{ ?shape <rdf://type> <ad4m://SubjectClass> . BIND(<rdf://type> AS ?predicate) BIND(<ad4m://SubjectClass> AS ?target) }
|
|
1615
|
+
UNION
|
|
1616
|
+
{ ?shape <sh://property> ?target . BIND(<sh://property> AS ?predicate) }
|
|
1617
|
+
UNION
|
|
1618
|
+
{ ?shape <sh://collection> ?target . BIND(<sh://collection> AS ?predicate) }
|
|
1619
|
+
}
|
|
1620
|
+
`);
|
|
1621
|
+
if (!Array.isArray(results) || results.length === 0)
|
|
1816
1622
|
return null;
|
|
1817
1623
|
// Build a map of className -> { properties, relations }
|
|
1818
1624
|
const classShapes = new Map();
|
|
1819
1625
|
// First pass: find all subject classes
|
|
1820
1626
|
for (const r of results) {
|
|
1821
1627
|
if (r.predicate === 'rdf://type' && r.target === 'ad4m://SubjectClass') {
|
|
1822
|
-
const source = r.
|
|
1628
|
+
const source = r.shape;
|
|
1823
1629
|
const sepIdx = source.indexOf('://');
|
|
1824
1630
|
if (sepIdx < 0)
|
|
1825
1631
|
continue;
|
|
@@ -1834,7 +1640,7 @@ export class PerspectiveProxy {
|
|
|
1834
1640
|
if (r.predicate === 'sh://property' || r.predicate === 'sh://collection') {
|
|
1835
1641
|
// Match shape source to class (e.g., "recipe://RecipeShape" -> "Recipe")
|
|
1836
1642
|
for (const [className, shape] of classShapes) {
|
|
1837
|
-
if (r.
|
|
1643
|
+
if (r.shape.endsWith(`${className}Shape`)) {
|
|
1838
1644
|
const dotIdx = r.target.lastIndexOf('.');
|
|
1839
1645
|
if (dotIdx < 0)
|
|
1840
1646
|
continue;
|
|
@@ -1940,6 +1746,178 @@ export class PerspectiveProxy {
|
|
|
1940
1746
|
clearEnsuredSubjectClasses() {
|
|
1941
1747
|
__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").clear();
|
|
1942
1748
|
}
|
|
1749
|
+
/**
|
|
1750
|
+
* Returns a list of all class names that have been registered as SHACL
|
|
1751
|
+
* subject classes in this perspective (via `ensureSDNASubjectClass` or `addSdna`).
|
|
1752
|
+
*
|
|
1753
|
+
* @returns Array of class name strings (e.g. `["Channel", "Message", "Task"]`)
|
|
1754
|
+
*/
|
|
1755
|
+
async listRegisteredClasses() {
|
|
1756
|
+
const results = await this.querySparql(`SELECT DISTINCT ?class WHERE { ?class <rdf://type> <ad4m://SubjectClass> . }`);
|
|
1757
|
+
if (!Array.isArray(results))
|
|
1758
|
+
return [];
|
|
1759
|
+
return results.map((row) => {
|
|
1760
|
+
const uri = row.class || '';
|
|
1761
|
+
// Extract class name from URI like "recipe://Recipe" or "flux://Channel"
|
|
1762
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1763
|
+
if (hashIdx >= 0)
|
|
1764
|
+
return uri.substring(hashIdx + 1);
|
|
1765
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1766
|
+
if (slashIdx >= 0)
|
|
1767
|
+
return uri.substring(slashIdx + 1);
|
|
1768
|
+
return uri;
|
|
1769
|
+
}).filter(Boolean);
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Returns the SHACL shape metadata for a registered class, including
|
|
1773
|
+
* property names, predicates, datatypes, and cardinality constraints.
|
|
1774
|
+
*
|
|
1775
|
+
* @param className - The name of the registered class
|
|
1776
|
+
* @returns Shape metadata or `null` if the class is not registered
|
|
1777
|
+
*/
|
|
1778
|
+
async getClassShape(className) {
|
|
1779
|
+
// Find the shape URI for this class
|
|
1780
|
+
const safeName = className.replace(/['"\\]/g, '');
|
|
1781
|
+
const shapeResults = await this.querySparql(`SELECT ?shapeUri ?targetClass WHERE {
|
|
1782
|
+
?targetClass <rdf://type> <ad4m://SubjectClass> .
|
|
1783
|
+
?targetClass <ad4m://shape> ?shapeUri .
|
|
1784
|
+
FILTER(STRENDS(STR(?targetClass), "/${safeName}") || STRENDS(STR(?targetClass), "#${safeName}"))
|
|
1785
|
+
} LIMIT 1`);
|
|
1786
|
+
if (!Array.isArray(shapeResults) || shapeResults.length === 0)
|
|
1787
|
+
return null;
|
|
1788
|
+
const shapeUri = shapeResults[0].shapeUri;
|
|
1789
|
+
const classUri = shapeResults[0].targetClass;
|
|
1790
|
+
// Query all properties for this shape, including sh:in
|
|
1791
|
+
const propResults = await this.querySparql(`SELECT ?propShape ?path ?datatype ?minCount ?maxCount ?writable ?propType ?shIn WHERE {
|
|
1792
|
+
<${shapeUri}> <sh://property> ?propShape .
|
|
1793
|
+
?propShape <sh://path> ?path .
|
|
1794
|
+
?propShape <rdf://type> ?propType .
|
|
1795
|
+
OPTIONAL { ?propShape <sh://datatype> ?datatype }
|
|
1796
|
+
OPTIONAL { ?propShape <sh://minCount> ?minCount }
|
|
1797
|
+
OPTIONAL { ?propShape <sh://maxCount> ?maxCount }
|
|
1798
|
+
OPTIONAL { ?propShape <ad4m://writable> ?writable }
|
|
1799
|
+
OPTIONAL { ?propShape <sh://in> ?shIn }
|
|
1800
|
+
}`);
|
|
1801
|
+
const properties = (Array.isArray(propResults) ? propResults : []).map((row) => {
|
|
1802
|
+
// Extract property name from shape URI like "recipe://Recipe.name"
|
|
1803
|
+
const propUri = row.propShape || '';
|
|
1804
|
+
const dotIdx = propUri.lastIndexOf('.');
|
|
1805
|
+
const name = dotIdx >= 0 ? propUri.substring(dotIdx + 1) : propUri;
|
|
1806
|
+
const minCount = parseInt(row.minCount || '0', 10);
|
|
1807
|
+
const isCollection = row.propType === 'ad4m://CollectionShape';
|
|
1808
|
+
const writable = row.writable === 'true' || row.writable === 'literal:true';
|
|
1809
|
+
// Parse sh:in values if present
|
|
1810
|
+
let options;
|
|
1811
|
+
if (row.shIn) {
|
|
1812
|
+
try {
|
|
1813
|
+
let raw = row.shIn;
|
|
1814
|
+
// Strip literal: prefix if present, and URI-decode for robustness
|
|
1815
|
+
if (raw.startsWith('literal:string:')) {
|
|
1816
|
+
raw = decodeURIComponent(raw.substring('literal:string:'.length));
|
|
1817
|
+
}
|
|
1818
|
+
options = JSON.parse(raw);
|
|
1819
|
+
}
|
|
1820
|
+
catch { /* ignore parse errors */ }
|
|
1821
|
+
}
|
|
1822
|
+
return {
|
|
1823
|
+
name,
|
|
1824
|
+
predicate: row.path || '',
|
|
1825
|
+
datatype: row.datatype || undefined,
|
|
1826
|
+
required: minCount > 0,
|
|
1827
|
+
collection: isCollection,
|
|
1828
|
+
writable,
|
|
1829
|
+
...(options && options.length > 0 ? { options } : {}),
|
|
1830
|
+
};
|
|
1831
|
+
});
|
|
1832
|
+
return { className: safeName, shapeUri, properties };
|
|
1833
|
+
}
|
|
1834
|
+
/**
|
|
1835
|
+
* Detects which registered subject classes a given instance conforms to,
|
|
1836
|
+
* based on its stored triples matching the class shapes' required properties.
|
|
1837
|
+
*
|
|
1838
|
+
* @param baseExpression - The instance's base expression / subject URI
|
|
1839
|
+
* @returns Array of class names the instance matches
|
|
1840
|
+
*/
|
|
1841
|
+
async getInstanceClasses(baseExpression) {
|
|
1842
|
+
const safeId = baseExpression.replace(/['"\\]/g, '');
|
|
1843
|
+
// Get all registered classes and their required conformance properties
|
|
1844
|
+
const results = await this.querySparql(`SELECT DISTINCT ?class WHERE {
|
|
1845
|
+
?class <rdf://type> <ad4m://SubjectClass> .
|
|
1846
|
+
?class <ad4m://shape> ?shape .
|
|
1847
|
+
?shape <sh://property> ?propShape .
|
|
1848
|
+
?propShape <sh://minCount> ?mc .
|
|
1849
|
+
FILTER(?mc >= 1)
|
|
1850
|
+
?propShape <sh://path> ?path .
|
|
1851
|
+
<${safeId}> ?path ?_val .
|
|
1852
|
+
}`);
|
|
1853
|
+
if (!Array.isArray(results))
|
|
1854
|
+
return [];
|
|
1855
|
+
return results.map((row) => {
|
|
1856
|
+
const uri = row.class || '';
|
|
1857
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1858
|
+
if (hashIdx >= 0)
|
|
1859
|
+
return uri.substring(hashIdx + 1);
|
|
1860
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1861
|
+
if (slashIdx >= 0)
|
|
1862
|
+
return uri.substring(slashIdx + 1);
|
|
1863
|
+
return uri;
|
|
1864
|
+
}).filter(Boolean);
|
|
1865
|
+
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Returns all named options (sh:in values) for a registered class, grouped by property.
|
|
1868
|
+
*
|
|
1869
|
+
* @param className - The name of the registered class
|
|
1870
|
+
* @returns Record mapping property name → array of { value, label } options
|
|
1871
|
+
*/
|
|
1872
|
+
async getNamedOptions(className) {
|
|
1873
|
+
const shape = await this.getClassShape(className);
|
|
1874
|
+
if (!shape)
|
|
1875
|
+
return {};
|
|
1876
|
+
const result = {};
|
|
1877
|
+
for (const prop of shape.properties) {
|
|
1878
|
+
if (prop.options && prop.options.length > 0) {
|
|
1879
|
+
result[prop.name] = prop.options;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
return result;
|
|
1883
|
+
}
|
|
1884
|
+
/**
|
|
1885
|
+
* Adds a named option (sh:in value) to a property of a registered class.
|
|
1886
|
+
* This appends to the existing sh:in list stored on the property shape.
|
|
1887
|
+
*
|
|
1888
|
+
* @param className - The registered class name
|
|
1889
|
+
* @param propertyName - The property to add the option to
|
|
1890
|
+
* @param value - The RDF value for the option
|
|
1891
|
+
* @param label - Optional human-readable label
|
|
1892
|
+
*/
|
|
1893
|
+
async addNamedOption(className, propertyName, value, label) {
|
|
1894
|
+
const shape = await this.getClassShape(className);
|
|
1895
|
+
if (!shape)
|
|
1896
|
+
throw new Error(`Class "${className}" not found`);
|
|
1897
|
+
const prop = shape.properties.find(p => p.name === propertyName);
|
|
1898
|
+
if (!prop)
|
|
1899
|
+
throw new Error(`Property "${propertyName}" not found on class "${className}"`);
|
|
1900
|
+
// Build the property shape URI
|
|
1901
|
+
const ns = extractNamespaceFromUri(shape.shapeUri);
|
|
1902
|
+
const propShapeId = `${ns}${className}.${propertyName}`;
|
|
1903
|
+
// Get existing options
|
|
1904
|
+
const existing = prop.options || [];
|
|
1905
|
+
// Don't add duplicates
|
|
1906
|
+
if (existing.some(o => o.value === value))
|
|
1907
|
+
return;
|
|
1908
|
+
const updated = [...existing, { value, ...(label ? { label } : {}) }];
|
|
1909
|
+
// Remove old sh:in link if exists by querying for it
|
|
1910
|
+
const oldLinks = await this.get(new LinkQuery({ source: propShapeId, predicate: "sh://in" }));
|
|
1911
|
+
for (const oldLink of oldLinks) {
|
|
1912
|
+
await this.remove(oldLink);
|
|
1913
|
+
}
|
|
1914
|
+
// Add new sh:in link
|
|
1915
|
+
await this.add(new Link({
|
|
1916
|
+
source: propShapeId,
|
|
1917
|
+
predicate: "sh://in",
|
|
1918
|
+
target: `literal:string:${JSON.stringify(updated)}`
|
|
1919
|
+
}));
|
|
1920
|
+
}
|
|
1943
1921
|
getNeighbourhoodProxy() {
|
|
1944
1922
|
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getNeighbourhoodProxy(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
1945
1923
|
}
|