@coasys/ad4m 0.13.0-test-3 → 0.13.0-test-5
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 +6717 -15519
- package/lib/index.js +4811 -13662
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +39 -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 -1
- package/lib/src/index.js +6 -1
- 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 +1 -1
- package/lib/src/language/Language.js +10 -76
- 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 +76 -44
- package/lib/src/model/Ad4mModel.js +635 -479
- package/lib/src/model/Ad4mModel.test.js +371 -815
- package/lib/src/model/ModelQueryBuilder.d.ts +15 -27
- package/lib/src/model/ModelQueryBuilder.js +163 -224
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration.d.ts +3 -93
- package/lib/src/model/hydration.js +3 -970
- 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 +4 -67
- package/lib/src/model/query-sparql.js +26 -322
- package/lib/src/model/query-sparql.test.js +35 -218
- package/lib/src/model/query-utils.d.ts +1 -0
- package/lib/src/model/query-utils.js +46 -1
- package/lib/src/model/shacl-gen.js +4 -0
- package/lib/src/model/types.d.ts +51 -43
- 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 +13 -17
- package/lib/src/perspectives/PerspectiveClient.js +179 -429
- package/lib/src/perspectives/PerspectiveClient.test.js +55 -0
- package/lib/src/perspectives/PerspectiveDiff.js +4 -31
- package/lib/src/perspectives/PerspectiveHandle.js +3 -43
- package/lib/src/perspectives/PerspectiveProxy.d.ts +106 -71
- package/lib/src/perspectives/PerspectiveProxy.js +289 -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 +6 -18
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1179 -1340
- package/src/Ad4mClient.ts +40 -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 -1
- package/src/jestSetup.ts +1 -1
- package/src/language/Icon.ts +0 -4
- package/src/language/Language.ts +2 -23
- 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 +766 -1173
- package/src/model/Ad4mModel.ts +664 -529
- package/src/model/ModelQueryBuilder.ts +203 -251
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +3 -1037
- package/src/model/index.ts +0 -4
- package/src/model/query-sparql.test.ts +34 -242
- package/src/model/query-sparql.ts +27 -337
- package/src/model/query-utils.ts +47 -2
- package/src/model/shacl-gen.ts +5 -0
- package/src/model/types.ts +55 -44
- 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 +206 -148
- package/src/perspectives/PerspectiveClient.ts +247 -442
- 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 +331 -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/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/LanguageResolver.ts +0 -98
- package/src/model/Subject.ts +0 -159
- package/src/model/hydration-batch.ts +0 -205
- package/src/model/hydration-batching.test.ts +0 -563
- 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-delta.test.ts +0 -207
- package/src/model/subscription-pool.ts +0 -211
- 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
|
@@ -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.
|
|
@@ -517,6 +540,49 @@ export class PerspectiveProxy {
|
|
|
517
540
|
setCachedResult(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query, result);
|
|
518
541
|
return result;
|
|
519
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
|
+
* Evaluate property getters for a batch of instances in a single RPC call.
|
|
556
|
+
* Returns a map of `{ instanceId: { prop: value, ... } }`.
|
|
557
|
+
*
|
|
558
|
+
* Use this instead of `Ad4mModel.evaluateGetters()` for lazy-loading
|
|
559
|
+
* getter-backed properties on visible items (e.g. `replyingTo` on messages).
|
|
560
|
+
*
|
|
561
|
+
* @param className - The model class name (e.g. "Message")
|
|
562
|
+
* @param instanceIds - Array of instance base expression URIs
|
|
563
|
+
* @param shapeJson - Shape metadata JSON from the model class
|
|
564
|
+
* @param propertyNames - Optional subset of property names to evaluate
|
|
565
|
+
* @returns Map of instance ID → evaluated property values
|
|
566
|
+
*/
|
|
567
|
+
async evaluateGetters(className, instanceIds, shapeJson, propertyNames) {
|
|
568
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").evaluateGetters(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, instanceIds, shapeJson, propertyNames);
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Subscribe to model query changes. Builds trigger SPARQL from the model shape
|
|
572
|
+
* internally in Rust, registers a subscription, runs the initial query, and
|
|
573
|
+
* pushes updated results when relevant links change.
|
|
574
|
+
*
|
|
575
|
+
* The subscription reuses the same GraphQL subscription channel as subscribeQuery().
|
|
576
|
+
* Use keepAliveQuery() / disposeQuerySubscription() with the returned subscriptionId.
|
|
577
|
+
*
|
|
578
|
+
* @param className - The model class name
|
|
579
|
+
* @param queryJson - JSON-serialized query parameters (same as modelQuery)
|
|
580
|
+
* @param shapeJson - Optional shape metadata JSON from the model class
|
|
581
|
+
* @returns Object with `subscriptionId` and initial `result`
|
|
582
|
+
*/
|
|
583
|
+
async modelSubscribe(className, queryJson, shapeJson) {
|
|
584
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
|
|
585
|
+
}
|
|
520
586
|
/**
|
|
521
587
|
* Adds a new link to the perspective.
|
|
522
588
|
*
|
|
@@ -984,7 +1050,7 @@ export class PerspectiveProxy {
|
|
|
984
1050
|
* Adds Social DNA code to the perspective.
|
|
985
1051
|
*
|
|
986
1052
|
* **Recommended:** Use {@link addShacl} instead, which accepts the `SHACLShape` type directly.
|
|
987
|
-
* This method is primarily for the
|
|
1053
|
+
* This method is primarily for the RPC API layer and legacy Prolog code.
|
|
988
1054
|
*
|
|
989
1055
|
* @param name - Unique name for this SDNA definition
|
|
990
1056
|
* @param sdnaCode - Prolog SDNA code (legacy, can be empty string if shaclJson provided)
|
|
@@ -1219,7 +1285,7 @@ export class PerspectiveProxy {
|
|
|
1219
1285
|
*/
|
|
1220
1286
|
async subjectClasses() {
|
|
1221
1287
|
try {
|
|
1222
|
-
// Query SHACL class links directly — no need for a separate
|
|
1288
|
+
// Query SHACL class links directly — no need for a separate RPC endpoint
|
|
1223
1289
|
const classLinks = await this.get(new LinkQuery({
|
|
1224
1290
|
predicate: "rdf://type",
|
|
1225
1291
|
target: "ad4m://SubjectClass"
|
|
@@ -1292,7 +1358,9 @@ export class PerspectiveProxy {
|
|
|
1292
1358
|
if (batchId) {
|
|
1293
1359
|
return exprAddr;
|
|
1294
1360
|
}
|
|
1295
|
-
|
|
1361
|
+
// Return the expression address directly — callers should use Ad4mModel or
|
|
1362
|
+
// getSubjectData() to interact with the created instance.
|
|
1363
|
+
return exprAddr;
|
|
1296
1364
|
}
|
|
1297
1365
|
async getSubjectData(subjectClass, exprAddr) {
|
|
1298
1366
|
if (typeof subjectClass === "string") {
|
|
@@ -1368,7 +1436,7 @@ export class PerspectiveProxy {
|
|
|
1368
1436
|
async isSubjectInstance(expression, subjectClass) {
|
|
1369
1437
|
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
|
|
1370
1438
|
// Get metadata from SHACL links
|
|
1371
|
-
const metadata = await this.
|
|
1439
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1372
1440
|
if (!metadata) {
|
|
1373
1441
|
console.warn(`isSubjectInstance: No SHACL metadata found for class ${className}`);
|
|
1374
1442
|
return false;
|
|
@@ -1378,49 +1446,19 @@ export class PerspectiveProxy {
|
|
|
1378
1446
|
const links = await this.get(new LinkQuery({ source: expression }));
|
|
1379
1447
|
return links.length > 0;
|
|
1380
1448
|
}
|
|
1381
|
-
//
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
query = new LinkQuery({ source: expression, predicate: triple.predicate });
|
|
1389
|
-
}
|
|
1390
|
-
const links = await this.get(query);
|
|
1391
|
-
if (!links || links.length === 0) {
|
|
1392
|
-
return false;
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
return true;
|
|
1396
|
-
}
|
|
1397
|
-
/** For an existing subject instance (existing in the perspective's links)
|
|
1398
|
-
* this function returns a proxy object that can be used to access the subject's
|
|
1399
|
-
* properties and methods.
|
|
1400
|
-
*
|
|
1401
|
-
* @param base URI of the subject's root expression
|
|
1402
|
-
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
1403
|
-
* with the properties of the subject class. In the latter case, the first subject class
|
|
1404
|
-
* that matches the given properties will be used.
|
|
1405
|
-
*/
|
|
1406
|
-
async getSubjectProxy(base, subjectClass) {
|
|
1407
|
-
if (!await this.isSubjectInstance(base, subjectClass)) {
|
|
1408
|
-
throw `Expression ${base} is not a subject instance of given class: ${JSON.stringify(subjectClass)}`;
|
|
1409
|
-
}
|
|
1410
|
-
let className = await this.stringOrTemplateObjectToSubjectClassName(subjectClass);
|
|
1411
|
-
let subject = new Subject(this, base, className);
|
|
1412
|
-
await subject.init();
|
|
1413
|
-
return subject;
|
|
1449
|
+
// Build a single SPARQL ASK query with all required triple patterns
|
|
1450
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1451
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1452
|
+
return `<${expression}> <${t.predicate}> ${target} .`;
|
|
1453
|
+
}).join('\n ');
|
|
1454
|
+
const result = await this.querySparql(`ASK WHERE {\n ${patterns}\n}`);
|
|
1455
|
+
return result === true;
|
|
1414
1456
|
}
|
|
1415
1457
|
/**
|
|
1416
1458
|
* Gets subject class metadata from SHACL links using SHACLShape.fromLinks().
|
|
1417
1459
|
* Retrieves the SHACL shape and extracts metadata for instance queries.
|
|
1418
1460
|
*/
|
|
1419
1461
|
async getSubjectClassMetadata(className) {
|
|
1420
|
-
return this.getSubjectClassMetadataFromSDNA(className);
|
|
1421
|
-
}
|
|
1422
|
-
/** @deprecated Use getSubjectClassMetadata() */
|
|
1423
|
-
async getSubjectClassMetadataFromSDNA(className) {
|
|
1424
1462
|
try {
|
|
1425
1463
|
// Use getShacl() to retrieve the shape via SHACLShape.fromLinks()
|
|
1426
1464
|
const shape = await this.getShacl(className);
|
|
@@ -1487,214 +1525,15 @@ export class PerspectiveProxy {
|
|
|
1487
1525
|
const sources = new Set(allLinks.map(l => l.data.source));
|
|
1488
1526
|
return Array.from(sources).map(s => ({ base: s }));
|
|
1489
1527
|
}
|
|
1490
|
-
//
|
|
1491
|
-
const
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
query = new LinkQuery({ predicate: first.predicate });
|
|
1498
|
-
}
|
|
1499
|
-
const candidateLinks = await this.get(query);
|
|
1500
|
-
let candidates = [...new Set(candidateLinks.map(l => l.data.source))];
|
|
1501
|
-
// Filter by remaining required triples
|
|
1502
|
-
for (let i = 1; i < metadata.requiredTriples.length; i++) {
|
|
1503
|
-
const triple = metadata.requiredTriples[i];
|
|
1504
|
-
const remaining = [];
|
|
1505
|
-
for (const expr of candidates) {
|
|
1506
|
-
let q;
|
|
1507
|
-
if (triple.target) {
|
|
1508
|
-
q = new LinkQuery({ source: expr, predicate: triple.predicate, target: triple.target });
|
|
1509
|
-
}
|
|
1510
|
-
else {
|
|
1511
|
-
q = new LinkQuery({ source: expr, predicate: triple.predicate });
|
|
1512
|
-
}
|
|
1513
|
-
const links = await this.get(q);
|
|
1514
|
-
if (links.length > 0)
|
|
1515
|
-
remaining.push(expr);
|
|
1516
|
-
}
|
|
1517
|
-
candidates = remaining;
|
|
1518
|
-
}
|
|
1519
|
-
return candidates.map(c => ({ base: c }));
|
|
1520
|
-
}
|
|
1521
|
-
/**
|
|
1522
|
-
* Gets a property value using SPARQL when Prolog fails.
|
|
1523
|
-
* This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
|
|
1524
|
-
*/
|
|
1525
|
-
async getPropertyValueViaSparql(baseExpression, className, propertyName) {
|
|
1526
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1527
|
-
if (!metadata) {
|
|
1528
|
-
return undefined;
|
|
1529
|
-
}
|
|
1530
|
-
const propMeta = metadata.properties.get(propertyName);
|
|
1531
|
-
if (!propMeta) {
|
|
1532
|
-
return undefined;
|
|
1533
|
-
}
|
|
1534
|
-
const links = await this.get(new LinkQuery({ source: baseExpression, predicate: propMeta.predicate }));
|
|
1535
|
-
if (!links || links.length === 0) {
|
|
1536
|
-
return undefined;
|
|
1537
|
-
}
|
|
1538
|
-
const value = links[0].data.target;
|
|
1539
|
-
// Handle expression resolution if needed
|
|
1540
|
-
if (propMeta.resolveLanguage && value) {
|
|
1541
|
-
try {
|
|
1542
|
-
const expression = await this.getExpression(value);
|
|
1543
|
-
try {
|
|
1544
|
-
return JSON.parse(expression.data);
|
|
1545
|
-
}
|
|
1546
|
-
catch (e) {
|
|
1547
|
-
return expression.data;
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
catch (err) {
|
|
1551
|
-
return value;
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
return value;
|
|
1555
|
-
}
|
|
1556
|
-
/**
|
|
1557
|
-
* Gets relation values using SPARQL when Prolog fails.
|
|
1558
|
-
* This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
|
|
1559
|
-
* Note: This is used by Subject.ts (legacy pattern). Ad4mModel.ts uses getModelMetadata() instead.
|
|
1560
|
-
*/
|
|
1561
|
-
async getRelationValuesViaSparql(baseExpression, className, relationName) {
|
|
1562
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1563
|
-
if (!metadata) {
|
|
1564
|
-
return [];
|
|
1565
|
-
}
|
|
1566
|
-
const relMeta = metadata.relations.get(relationName);
|
|
1567
|
-
if (!relMeta) {
|
|
1568
|
-
return [];
|
|
1569
|
-
}
|
|
1570
|
-
const links = await this.get(new LinkQuery({ source: baseExpression, predicate: relMeta.predicate }));
|
|
1571
|
-
if (!links || links.length === 0) {
|
|
1572
|
-
return [];
|
|
1573
|
-
}
|
|
1574
|
-
// Sort by timestamp ascending
|
|
1575
|
-
links.sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
1576
|
-
let values = links.map(l => l.data.target).filter(v => v !== "" && v !== '');
|
|
1577
|
-
// Apply condition filtering if present
|
|
1578
|
-
if (relMeta.condition && values.length > 0) {
|
|
1579
|
-
try {
|
|
1580
|
-
const filteredValues = [];
|
|
1581
|
-
for (const value of values) {
|
|
1582
|
-
let condition = relMeta.condition
|
|
1583
|
-
.replace(/\$perspective/g, `'${this.uuid}'`)
|
|
1584
|
-
.replace(/\$base/g, `'${baseExpression}'`)
|
|
1585
|
-
.replace(/Target/g, `'${value.replace(/'/g, "\\'")}'`);
|
|
1586
|
-
// Parse condition to extract link query parameters
|
|
1587
|
-
// Conditions typically look like: WHERE in.uri = 'X' AND predicate = 'Y' AND out.uri = 'Z'
|
|
1588
|
-
// or: array::len(SELECT * FROM link WHERE ...) > 0
|
|
1589
|
-
// Convert to queryLinks calls
|
|
1590
|
-
const sourceMatch = condition.match(/in\.uri\s*=\s*'([^']+)'/);
|
|
1591
|
-
const predicateMatch = condition.match(/predicate\s*=\s*'([^']+)'/);
|
|
1592
|
-
const targetMatch = condition.match(/out\.uri\s*=\s*'([^']+)'/);
|
|
1593
|
-
if (sourceMatch || predicateMatch || targetMatch) {
|
|
1594
|
-
const linkQuery = {};
|
|
1595
|
-
if (sourceMatch)
|
|
1596
|
-
linkQuery.source = sourceMatch[1];
|
|
1597
|
-
if (predicateMatch)
|
|
1598
|
-
linkQuery.predicate = predicateMatch[1];
|
|
1599
|
-
if (targetMatch)
|
|
1600
|
-
linkQuery.target = targetMatch[1];
|
|
1601
|
-
const matchingLinks = await this.get(new LinkQuery(linkQuery));
|
|
1602
|
-
if (matchingLinks.length > 0) {
|
|
1603
|
-
filteredValues.push(value);
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
else {
|
|
1607
|
-
// Can't parse condition, include by default
|
|
1608
|
-
filteredValues.push(value);
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
values = filteredValues;
|
|
1612
|
-
}
|
|
1613
|
-
catch (error) {
|
|
1614
|
-
console.warn(`Failed to apply condition filter for ${relationName}:`, error);
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
// Apply instance filter if present - batch-check all values at once
|
|
1618
|
-
if (relMeta.instanceFilter) {
|
|
1619
|
-
try {
|
|
1620
|
-
const filterMetadata = await this.getSubjectClassMetadataFromSDNA(relMeta.instanceFilter);
|
|
1621
|
-
if (!filterMetadata) {
|
|
1622
|
-
// Fallback to sequential checks if metadata isn't available
|
|
1623
|
-
return this.filterInstancesSequential(values, relMeta.instanceFilter);
|
|
1624
|
-
}
|
|
1625
|
-
return await this.batchCheckSubjectInstances(values, filterMetadata);
|
|
1626
|
-
}
|
|
1627
|
-
catch (err) {
|
|
1628
|
-
// Fallback to sequential checks on error
|
|
1629
|
-
return this.filterInstancesSequential(values, relMeta.instanceFilter);
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
return values;
|
|
1633
|
-
}
|
|
1634
|
-
/**
|
|
1635
|
-
* Batch-checks multiple expressions against subject class metadata using a single or limited SPARQL queries.
|
|
1636
|
-
* This avoids N+1 query problems by checking all values at once.
|
|
1637
|
-
*/
|
|
1638
|
-
async batchCheckSubjectInstances(expressions, metadata) {
|
|
1639
|
-
if (expressions.length === 0) {
|
|
1528
|
+
// Build a single SPARQL SELECT with all required triple patterns joined
|
|
1529
|
+
const patterns = metadata.requiredTriples.map((t, i) => {
|
|
1530
|
+
const target = t.target ? `<${t.target}>` : `?t${i}`;
|
|
1531
|
+
return `?base <${t.predicate}> ${target} .`;
|
|
1532
|
+
}).join('\n ');
|
|
1533
|
+
const results = await this.querySparql(`SELECT DISTINCT ?base WHERE {\n ${patterns}\n}`);
|
|
1534
|
+
if (!Array.isArray(results))
|
|
1640
1535
|
return [];
|
|
1641
|
-
}
|
|
1642
|
-
// If no required triples, check which expressions have any links
|
|
1643
|
-
if (metadata.requiredTriples.length === 0) {
|
|
1644
|
-
const results = [];
|
|
1645
|
-
for (const expr of expressions) {
|
|
1646
|
-
const links = await this.get(new LinkQuery({ source: expr }));
|
|
1647
|
-
if (links.length > 0)
|
|
1648
|
-
results.push(expr);
|
|
1649
|
-
}
|
|
1650
|
-
return results;
|
|
1651
|
-
}
|
|
1652
|
-
// For each required triple, find which expressions match
|
|
1653
|
-
const validExpressionSets = [];
|
|
1654
|
-
for (const triple of metadata.requiredTriples) {
|
|
1655
|
-
const matchingExprs = new Set();
|
|
1656
|
-
for (const expr of expressions) {
|
|
1657
|
-
let query;
|
|
1658
|
-
if (triple.target) {
|
|
1659
|
-
query = new LinkQuery({ source: expr, predicate: triple.predicate, target: triple.target });
|
|
1660
|
-
}
|
|
1661
|
-
else {
|
|
1662
|
-
query = new LinkQuery({ source: expr, predicate: triple.predicate });
|
|
1663
|
-
}
|
|
1664
|
-
const links = await this.get(query);
|
|
1665
|
-
if (links.length > 0)
|
|
1666
|
-
matchingExprs.add(expr);
|
|
1667
|
-
}
|
|
1668
|
-
validExpressionSets.push(matchingExprs);
|
|
1669
|
-
}
|
|
1670
|
-
// Find intersection: expressions that passed ALL required triple checks
|
|
1671
|
-
if (validExpressionSets.length === 0) {
|
|
1672
|
-
return expressions;
|
|
1673
|
-
}
|
|
1674
|
-
const firstSet = validExpressionSets[0];
|
|
1675
|
-
const validExpressions = expressions.filter(expr => {
|
|
1676
|
-
return validExpressionSets.every(set => set.has(expr));
|
|
1677
|
-
});
|
|
1678
|
-
return validExpressions;
|
|
1679
|
-
}
|
|
1680
|
-
/**
|
|
1681
|
-
* Fallback sequential instance checking when batch checking isn't available.
|
|
1682
|
-
*/
|
|
1683
|
-
async filterInstancesSequential(values, instanceFilter) {
|
|
1684
|
-
const filteredValues = [];
|
|
1685
|
-
for (const value of values) {
|
|
1686
|
-
try {
|
|
1687
|
-
const isInstance = await this.isSubjectInstance(value, instanceFilter);
|
|
1688
|
-
if (isInstance) {
|
|
1689
|
-
filteredValues.push(value);
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
catch (err) {
|
|
1693
|
-
// Skip values that fail instance check
|
|
1694
|
-
continue;
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
return filteredValues;
|
|
1536
|
+
return results.map((row) => ({ base: row.base }));
|
|
1698
1537
|
}
|
|
1699
1538
|
/** Returns all subject instances of the given subject class as proxy objects.
|
|
1700
1539
|
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
@@ -1719,7 +1558,7 @@ export class PerspectiveProxy {
|
|
|
1719
1558
|
for (let className of classes) {
|
|
1720
1559
|
//console.log(`getAllSubjectInstances: Processing class ${className}`);
|
|
1721
1560
|
// Query SDNA for metadata, then query SPARQL for instances
|
|
1722
|
-
const metadata = await this.
|
|
1561
|
+
const metadata = await this.getSubjectClassMetadata(className);
|
|
1723
1562
|
//console.log(`getAllSubjectInstances: Got metadata for ${className}:`, metadata);
|
|
1724
1563
|
if (metadata) {
|
|
1725
1564
|
const results = await this.findInstancesByMetadata(metadata);
|
|
@@ -1736,9 +1575,9 @@ export class PerspectiveProxy {
|
|
|
1736
1575
|
await instance.get();
|
|
1737
1576
|
}
|
|
1738
1577
|
else {
|
|
1739
|
-
//
|
|
1740
|
-
|
|
1741
|
-
|
|
1578
|
+
// Return plain data for string-based lookups
|
|
1579
|
+
const data = await this.getSubjectData(className, result.base);
|
|
1580
|
+
instance = { id: result.base, ...data };
|
|
1742
1581
|
}
|
|
1743
1582
|
instances.push(instance);
|
|
1744
1583
|
//console.log(`getAllSubjectInstances: Successfully created subject for ${result.base}`);
|
|
@@ -1755,39 +1594,6 @@ export class PerspectiveProxy {
|
|
|
1755
1594
|
//console.log(`getAllSubjectInstances: Returning ${instances.length} instances`);
|
|
1756
1595
|
return instances;
|
|
1757
1596
|
}
|
|
1758
|
-
/** Returns all subject proxies of the given subject class as proxy objects.
|
|
1759
|
-
* @param subjectClass Either a string with the name of the subject class, or an object
|
|
1760
|
-
* with the properties of the subject class. In the latter case, all subject classes
|
|
1761
|
-
* that match the given properties will be used.
|
|
1762
|
-
*/
|
|
1763
|
-
async getAllSubjectProxies(subjectClass) {
|
|
1764
|
-
let classes = [];
|
|
1765
|
-
if (typeof subjectClass === "string") {
|
|
1766
|
-
classes = [subjectClass];
|
|
1767
|
-
}
|
|
1768
|
-
else {
|
|
1769
|
-
classes = await this.subjectClassesByTemplate(subjectClass);
|
|
1770
|
-
}
|
|
1771
|
-
let instances = [];
|
|
1772
|
-
for (let className of classes) {
|
|
1773
|
-
// Query SDNA for metadata, then query SPARQL for instances
|
|
1774
|
-
const metadata = await this.getSubjectClassMetadataFromSDNA(className);
|
|
1775
|
-
if (metadata) {
|
|
1776
|
-
const results = await this.findInstancesByMetadata(metadata);
|
|
1777
|
-
for (const result of results || []) {
|
|
1778
|
-
try {
|
|
1779
|
-
let subject = new Subject(this, result.base, className);
|
|
1780
|
-
await subject.init();
|
|
1781
|
-
instances.push(subject);
|
|
1782
|
-
}
|
|
1783
|
-
catch (e) {
|
|
1784
|
-
// Skip subjects that fail to initialize
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
}
|
|
1789
|
-
return instances;
|
|
1790
|
-
}
|
|
1791
1597
|
/**
|
|
1792
1598
|
* Find a subject class by matching an object's properties/relations against SHACL shapes.
|
|
1793
1599
|
* Queries SHACL links client-side to find a class whose properties contain all required ones.
|
|
@@ -1818,23 +1624,24 @@ export class PerspectiveProxy {
|
|
|
1818
1624
|
if (properties.length === 0 && relations.length === 0) {
|
|
1819
1625
|
return null;
|
|
1820
1626
|
}
|
|
1821
|
-
//
|
|
1822
|
-
const
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1627
|
+
// Single SPARQL query to get all class shapes with their properties and collections
|
|
1628
|
+
const results = await this.querySparql(`
|
|
1629
|
+
SELECT ?shape ?predicate ?target WHERE {
|
|
1630
|
+
{ ?shape <rdf://type> <ad4m://SubjectClass> . BIND(<rdf://type> AS ?predicate) BIND(<ad4m://SubjectClass> AS ?target) }
|
|
1631
|
+
UNION
|
|
1632
|
+
{ ?shape <sh://property> ?target . BIND(<sh://property> AS ?predicate) }
|
|
1633
|
+
UNION
|
|
1634
|
+
{ ?shape <sh://collection> ?target . BIND(<sh://collection> AS ?predicate) }
|
|
1635
|
+
}
|
|
1636
|
+
`);
|
|
1637
|
+
if (!Array.isArray(results) || results.length === 0)
|
|
1831
1638
|
return null;
|
|
1832
1639
|
// Build a map of className -> { properties, relations }
|
|
1833
1640
|
const classShapes = new Map();
|
|
1834
1641
|
// First pass: find all subject classes
|
|
1835
1642
|
for (const r of results) {
|
|
1836
1643
|
if (r.predicate === 'rdf://type' && r.target === 'ad4m://SubjectClass') {
|
|
1837
|
-
const source = r.
|
|
1644
|
+
const source = r.shape;
|
|
1838
1645
|
const sepIdx = source.indexOf('://');
|
|
1839
1646
|
if (sepIdx < 0)
|
|
1840
1647
|
continue;
|
|
@@ -1849,7 +1656,7 @@ export class PerspectiveProxy {
|
|
|
1849
1656
|
if (r.predicate === 'sh://property' || r.predicate === 'sh://collection') {
|
|
1850
1657
|
// Match shape source to class (e.g., "recipe://RecipeShape" -> "Recipe")
|
|
1851
1658
|
for (const [className, shape] of classShapes) {
|
|
1852
|
-
if (r.
|
|
1659
|
+
if (r.shape.endsWith(`${className}Shape`)) {
|
|
1853
1660
|
const dotIdx = r.target.lastIndexOf('.');
|
|
1854
1661
|
if (dotIdx < 0)
|
|
1855
1662
|
continue;
|
|
@@ -1955,6 +1762,178 @@ export class PerspectiveProxy {
|
|
|
1955
1762
|
clearEnsuredSubjectClasses() {
|
|
1956
1763
|
__classPrivateFieldGet(this, _PerspectiveProxy_ensuredSubjectClasses, "f").clear();
|
|
1957
1764
|
}
|
|
1765
|
+
/**
|
|
1766
|
+
* Returns a list of all class names that have been registered as SHACL
|
|
1767
|
+
* subject classes in this perspective (via `ensureSDNASubjectClass` or `addSdna`).
|
|
1768
|
+
*
|
|
1769
|
+
* @returns Array of class name strings (e.g. `["Channel", "Message", "Task"]`)
|
|
1770
|
+
*/
|
|
1771
|
+
async listRegisteredClasses() {
|
|
1772
|
+
const results = await this.querySparql(`SELECT DISTINCT ?class WHERE { ?class <rdf://type> <ad4m://SubjectClass> . }`);
|
|
1773
|
+
if (!Array.isArray(results))
|
|
1774
|
+
return [];
|
|
1775
|
+
return results.map((row) => {
|
|
1776
|
+
const uri = row.class || '';
|
|
1777
|
+
// Extract class name from URI like "recipe://Recipe" or "flux://Channel"
|
|
1778
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1779
|
+
if (hashIdx >= 0)
|
|
1780
|
+
return uri.substring(hashIdx + 1);
|
|
1781
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1782
|
+
if (slashIdx >= 0)
|
|
1783
|
+
return uri.substring(slashIdx + 1);
|
|
1784
|
+
return uri;
|
|
1785
|
+
}).filter(Boolean);
|
|
1786
|
+
}
|
|
1787
|
+
/**
|
|
1788
|
+
* Returns the SHACL shape metadata for a registered class, including
|
|
1789
|
+
* property names, predicates, datatypes, and cardinality constraints.
|
|
1790
|
+
*
|
|
1791
|
+
* @param className - The name of the registered class
|
|
1792
|
+
* @returns Shape metadata or `null` if the class is not registered
|
|
1793
|
+
*/
|
|
1794
|
+
async getClassShape(className) {
|
|
1795
|
+
// Find the shape URI for this class
|
|
1796
|
+
const safeName = className.replace(/['"\\]/g, '');
|
|
1797
|
+
const shapeResults = await this.querySparql(`SELECT ?shapeUri ?targetClass WHERE {
|
|
1798
|
+
?targetClass <rdf://type> <ad4m://SubjectClass> .
|
|
1799
|
+
?targetClass <ad4m://shape> ?shapeUri .
|
|
1800
|
+
FILTER(STRENDS(STR(?targetClass), "/${safeName}") || STRENDS(STR(?targetClass), "#${safeName}"))
|
|
1801
|
+
} LIMIT 1`);
|
|
1802
|
+
if (!Array.isArray(shapeResults) || shapeResults.length === 0)
|
|
1803
|
+
return null;
|
|
1804
|
+
const shapeUri = shapeResults[0].shapeUri;
|
|
1805
|
+
const classUri = shapeResults[0].targetClass;
|
|
1806
|
+
// Query all properties for this shape, including sh:in
|
|
1807
|
+
const propResults = await this.querySparql(`SELECT ?propShape ?path ?datatype ?minCount ?maxCount ?writable ?propType ?shIn WHERE {
|
|
1808
|
+
<${shapeUri}> <sh://property> ?propShape .
|
|
1809
|
+
?propShape <sh://path> ?path .
|
|
1810
|
+
?propShape <rdf://type> ?propType .
|
|
1811
|
+
OPTIONAL { ?propShape <sh://datatype> ?datatype }
|
|
1812
|
+
OPTIONAL { ?propShape <sh://minCount> ?minCount }
|
|
1813
|
+
OPTIONAL { ?propShape <sh://maxCount> ?maxCount }
|
|
1814
|
+
OPTIONAL { ?propShape <ad4m://writable> ?writable }
|
|
1815
|
+
OPTIONAL { ?propShape <sh://in> ?shIn }
|
|
1816
|
+
}`);
|
|
1817
|
+
const properties = (Array.isArray(propResults) ? propResults : []).map((row) => {
|
|
1818
|
+
// Extract property name from shape URI like "recipe://Recipe.name"
|
|
1819
|
+
const propUri = row.propShape || '';
|
|
1820
|
+
const dotIdx = propUri.lastIndexOf('.');
|
|
1821
|
+
const name = dotIdx >= 0 ? propUri.substring(dotIdx + 1) : propUri;
|
|
1822
|
+
const minCount = parseInt(row.minCount || '0', 10);
|
|
1823
|
+
const isCollection = row.propType === 'ad4m://CollectionShape';
|
|
1824
|
+
const writable = row.writable === 'true' || row.writable === 'literal:true';
|
|
1825
|
+
// Parse sh:in values if present
|
|
1826
|
+
let options;
|
|
1827
|
+
if (row.shIn) {
|
|
1828
|
+
try {
|
|
1829
|
+
let raw = row.shIn;
|
|
1830
|
+
// Strip literal: prefix if present, and URI-decode for robustness
|
|
1831
|
+
if (raw.startsWith('literal:string:')) {
|
|
1832
|
+
raw = decodeURIComponent(raw.substring('literal:string:'.length));
|
|
1833
|
+
}
|
|
1834
|
+
options = JSON.parse(raw);
|
|
1835
|
+
}
|
|
1836
|
+
catch { /* ignore parse errors */ }
|
|
1837
|
+
}
|
|
1838
|
+
return {
|
|
1839
|
+
name,
|
|
1840
|
+
predicate: row.path || '',
|
|
1841
|
+
datatype: row.datatype || undefined,
|
|
1842
|
+
required: minCount > 0,
|
|
1843
|
+
collection: isCollection,
|
|
1844
|
+
writable,
|
|
1845
|
+
...(options && options.length > 0 ? { options } : {}),
|
|
1846
|
+
};
|
|
1847
|
+
});
|
|
1848
|
+
return { className: safeName, shapeUri, properties };
|
|
1849
|
+
}
|
|
1850
|
+
/**
|
|
1851
|
+
* Detects which registered subject classes a given instance conforms to,
|
|
1852
|
+
* based on its stored triples matching the class shapes' required properties.
|
|
1853
|
+
*
|
|
1854
|
+
* @param baseExpression - The instance's base expression / subject URI
|
|
1855
|
+
* @returns Array of class names the instance matches
|
|
1856
|
+
*/
|
|
1857
|
+
async getInstanceClasses(baseExpression) {
|
|
1858
|
+
const safeId = baseExpression.replace(/['"\\]/g, '');
|
|
1859
|
+
// Get all registered classes and their required conformance properties
|
|
1860
|
+
const results = await this.querySparql(`SELECT DISTINCT ?class WHERE {
|
|
1861
|
+
?class <rdf://type> <ad4m://SubjectClass> .
|
|
1862
|
+
?class <ad4m://shape> ?shape .
|
|
1863
|
+
?shape <sh://property> ?propShape .
|
|
1864
|
+
?propShape <sh://minCount> ?mc .
|
|
1865
|
+
FILTER(?mc >= 1)
|
|
1866
|
+
?propShape <sh://path> ?path .
|
|
1867
|
+
<${safeId}> ?path ?_val .
|
|
1868
|
+
}`);
|
|
1869
|
+
if (!Array.isArray(results))
|
|
1870
|
+
return [];
|
|
1871
|
+
return results.map((row) => {
|
|
1872
|
+
const uri = row.class || '';
|
|
1873
|
+
const hashIdx = uri.lastIndexOf('#');
|
|
1874
|
+
if (hashIdx >= 0)
|
|
1875
|
+
return uri.substring(hashIdx + 1);
|
|
1876
|
+
const slashIdx = uri.lastIndexOf('/');
|
|
1877
|
+
if (slashIdx >= 0)
|
|
1878
|
+
return uri.substring(slashIdx + 1);
|
|
1879
|
+
return uri;
|
|
1880
|
+
}).filter(Boolean);
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* Returns all named options (sh:in values) for a registered class, grouped by property.
|
|
1884
|
+
*
|
|
1885
|
+
* @param className - The name of the registered class
|
|
1886
|
+
* @returns Record mapping property name → array of { value, label } options
|
|
1887
|
+
*/
|
|
1888
|
+
async getNamedOptions(className) {
|
|
1889
|
+
const shape = await this.getClassShape(className);
|
|
1890
|
+
if (!shape)
|
|
1891
|
+
return {};
|
|
1892
|
+
const result = {};
|
|
1893
|
+
for (const prop of shape.properties) {
|
|
1894
|
+
if (prop.options && prop.options.length > 0) {
|
|
1895
|
+
result[prop.name] = prop.options;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
return result;
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Adds a named option (sh:in value) to a property of a registered class.
|
|
1902
|
+
* This appends to the existing sh:in list stored on the property shape.
|
|
1903
|
+
*
|
|
1904
|
+
* @param className - The registered class name
|
|
1905
|
+
* @param propertyName - The property to add the option to
|
|
1906
|
+
* @param value - The RDF value for the option
|
|
1907
|
+
* @param label - Optional human-readable label
|
|
1908
|
+
*/
|
|
1909
|
+
async addNamedOption(className, propertyName, value, label) {
|
|
1910
|
+
const shape = await this.getClassShape(className);
|
|
1911
|
+
if (!shape)
|
|
1912
|
+
throw new Error(`Class "${className}" not found`);
|
|
1913
|
+
const prop = shape.properties.find(p => p.name === propertyName);
|
|
1914
|
+
if (!prop)
|
|
1915
|
+
throw new Error(`Property "${propertyName}" not found on class "${className}"`);
|
|
1916
|
+
// Build the property shape URI
|
|
1917
|
+
const ns = extractNamespaceFromUri(shape.shapeUri);
|
|
1918
|
+
const propShapeId = `${ns}${className}.${propertyName}`;
|
|
1919
|
+
// Get existing options
|
|
1920
|
+
const existing = prop.options || [];
|
|
1921
|
+
// Don't add duplicates
|
|
1922
|
+
if (existing.some(o => o.value === value))
|
|
1923
|
+
return;
|
|
1924
|
+
const updated = [...existing, { value, ...(label ? { label } : {}) }];
|
|
1925
|
+
// Remove old sh:in link if exists by querying for it
|
|
1926
|
+
const oldLinks = await this.get(new LinkQuery({ source: propShapeId, predicate: "sh://in" }));
|
|
1927
|
+
for (const oldLink of oldLinks) {
|
|
1928
|
+
await this.remove(oldLink);
|
|
1929
|
+
}
|
|
1930
|
+
// Add new sh:in link
|
|
1931
|
+
await this.add(new Link({
|
|
1932
|
+
source: propShapeId,
|
|
1933
|
+
predicate: "sh://in",
|
|
1934
|
+
target: `literal:string:${JSON.stringify(updated)}`
|
|
1935
|
+
}));
|
|
1936
|
+
}
|
|
1958
1937
|
getNeighbourhoodProxy() {
|
|
1959
1938
|
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getNeighbourhoodProxy(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
1960
1939
|
}
|