@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
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiClient, RpcError } from "../apiClient";
|
|
2
2
|
import { ExpressionRendered } from "../expression/Expression";
|
|
3
3
|
import { ExpressionClient } from "../expression/ExpressionClient";
|
|
4
|
-
import { Link, LinkExpressionInput, LinkExpression,
|
|
4
|
+
import { Link, LinkExpressionInput, LinkExpression, LinkMutations, LinkExpressionMutations } from "../links/Links";
|
|
5
5
|
import { NeighbourhoodClient } from "../neighbourhood/NeighbourhoodClient";
|
|
6
6
|
import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
|
|
7
|
-
import unwrapApolloResult from "../unwrapApolloResult";
|
|
8
7
|
import { LinkQuery } from "./LinkQuery";
|
|
9
8
|
import { Perspective } from "./Perspective";
|
|
10
9
|
import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
|
|
@@ -12,44 +11,37 @@ import { LinkStatus, PerspectiveProxy } from './PerspectiveProxy';
|
|
|
12
11
|
import { AIClient } from "../ai/AIClient";
|
|
13
12
|
import { AllInstancesResult } from "../model/types";
|
|
14
13
|
|
|
15
|
-
const LINK_EXPRESSION_FIELDS = `
|
|
16
|
-
author
|
|
17
|
-
timestamp
|
|
18
|
-
status
|
|
19
|
-
data { source, predicate, target }
|
|
20
|
-
proof { valid, invalid, signature, key }
|
|
21
|
-
`
|
|
22
|
-
|
|
23
|
-
const PERSPECTIVE_HANDLE_FIELDS = `
|
|
24
|
-
uuid
|
|
25
|
-
name
|
|
26
|
-
sharedUrl
|
|
27
|
-
state
|
|
28
|
-
owners
|
|
29
|
-
neighbourhood {
|
|
30
|
-
data {
|
|
31
|
-
linkLanguage
|
|
32
|
-
meta {
|
|
33
|
-
links
|
|
34
|
-
{
|
|
35
|
-
author
|
|
36
|
-
timestamp
|
|
37
|
-
data { source, predicate, target }
|
|
38
|
-
proof { valid, invalid, signature, key }
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
author
|
|
43
|
-
}
|
|
44
|
-
`
|
|
45
|
-
|
|
46
14
|
export type PerspectiveHandleCallback = (perspective: PerspectiveHandle) => null
|
|
47
15
|
export type UuidCallback = (uuid: string) => null
|
|
48
16
|
export type LinkCallback = (link: LinkExpression) => null
|
|
49
17
|
export type SyncStateChangeCallback = (state: PerspectiveState) => null
|
|
50
18
|
|
|
19
|
+
function normalizeQueryResult(raw: unknown, errorContext: string): { result: AllInstancesResult; isInit: boolean } {
|
|
20
|
+
let finalResult: unknown = raw
|
|
21
|
+
let isInit = false
|
|
22
|
+
|
|
23
|
+
if (typeof finalResult === 'string' && finalResult.startsWith('#init#')) {
|
|
24
|
+
finalResult = finalResult.substring(6)
|
|
25
|
+
isInit = true
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof finalResult === 'string') {
|
|
29
|
+
try {
|
|
30
|
+
finalResult = JSON.parse(finalResult)
|
|
31
|
+
} catch (e) {
|
|
32
|
+
console.error(errorContext, e)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isInit && typeof finalResult === 'object' && finalResult !== null) {
|
|
37
|
+
(finalResult as Record<string, unknown>).isInit = true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return { result: finalResult as AllInstancesResult, isInit }
|
|
41
|
+
}
|
|
42
|
+
|
|
51
43
|
export class PerspectiveClient {
|
|
52
|
-
#
|
|
44
|
+
#apiClient: ApiClient
|
|
53
45
|
#perspectiveAddedCallbacks: PerspectiveHandleCallback[]
|
|
54
46
|
#perspectiveUpdatedCallbacks: PerspectiveHandleCallback[]
|
|
55
47
|
#perspectiveRemovedCallbacks: UuidCallback[]
|
|
@@ -57,14 +49,19 @@ export class PerspectiveClient {
|
|
|
57
49
|
#expressionClient?: ExpressionClient
|
|
58
50
|
#neighbourhoodClient?: NeighbourhoodClient
|
|
59
51
|
#aiClient?: AIClient
|
|
60
|
-
#
|
|
52
|
+
#unsubscribers: (() => void)[]
|
|
53
|
+
#linkUnsubscribers: Map<string, (() => void)[]>
|
|
54
|
+
#querySubscriptionUnsubscribers: Map<string, () => void>
|
|
61
55
|
|
|
62
|
-
constructor(
|
|
63
|
-
this.#
|
|
56
|
+
constructor(baseUrl: string, token?: string, subscribe: boolean = true, sharedApiClient?: ApiClient) {
|
|
57
|
+
this.#apiClient = sharedApiClient || new ApiClient(baseUrl, token)
|
|
64
58
|
this.#perspectiveAddedCallbacks = []
|
|
65
59
|
this.#perspectiveUpdatedCallbacks = []
|
|
66
60
|
this.#perspectiveRemovedCallbacks = []
|
|
67
61
|
this.#perspectiveSyncStateChangeCallbacks = []
|
|
62
|
+
this.#unsubscribers = []
|
|
63
|
+
this.#linkUnsubscribers = new Map()
|
|
64
|
+
this.#querySubscriptionUnsubscribers = new Map()
|
|
68
65
|
|
|
69
66
|
if(subscribe) {
|
|
70
67
|
this.subscribePerspectiveAdded()
|
|
@@ -73,18 +70,6 @@ export class PerspectiveClient {
|
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
72
|
|
|
76
|
-
/** Get or create a proxy for a UUID. If the proxy exists in cache, update its handle and return it. */
|
|
77
|
-
private getOrCreateProxy(handle: PerspectiveHandle): PerspectiveProxy {
|
|
78
|
-
const existing = this.#proxyCache.get(handle.uuid)
|
|
79
|
-
if (existing) {
|
|
80
|
-
existing.updateHandle(handle)
|
|
81
|
-
return existing
|
|
82
|
-
}
|
|
83
|
-
const proxy = new PerspectiveProxy(handle, this)
|
|
84
|
-
this.#proxyCache.set(handle.uuid, proxy)
|
|
85
|
-
return proxy
|
|
86
|
-
}
|
|
87
|
-
|
|
88
73
|
setExpressionClient(client: ExpressionClient) {
|
|
89
74
|
this.#expressionClient = client
|
|
90
75
|
}
|
|
@@ -98,285 +83,194 @@ export class PerspectiveClient {
|
|
|
98
83
|
}
|
|
99
84
|
|
|
100
85
|
get aiClient(): AIClient {
|
|
101
|
-
return this.#aiClient
|
|
86
|
+
return this.#aiClient!
|
|
102
87
|
}
|
|
103
88
|
|
|
104
89
|
async all(): Promise<PerspectiveProxy[]> {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
perspectives {
|
|
108
|
-
${PERSPECTIVE_HANDLE_FIELDS}
|
|
109
|
-
}
|
|
110
|
-
}`
|
|
111
|
-
}))
|
|
112
|
-
return perspectives.map(handle => this.getOrCreateProxy(handle))
|
|
90
|
+
const perspectives = await this.#apiClient.call<PerspectiveHandle[]>('perspective.all')
|
|
91
|
+
return perspectives.map(handle => new PerspectiveProxy(handle, this))
|
|
113
92
|
}
|
|
114
93
|
|
|
115
94
|
async byUUID(uuid: string): Promise<PerspectiveProxy|null> {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}`,
|
|
125
|
-
variables: { uuid }
|
|
126
|
-
}))
|
|
127
|
-
if(!perspective) return null
|
|
128
|
-
return this.getOrCreateProxy(perspective)
|
|
95
|
+
try {
|
|
96
|
+
const perspective = await this.#apiClient.call<PerspectiveHandle>('perspective.get', { uuid })
|
|
97
|
+
if(!perspective) return null
|
|
98
|
+
return new PerspectiveProxy(perspective, this)
|
|
99
|
+
} catch(e) {
|
|
100
|
+
if (e instanceof RpcError && e.status === 404) return null
|
|
101
|
+
throw e
|
|
102
|
+
}
|
|
129
103
|
}
|
|
130
104
|
|
|
131
105
|
async snapshotByUUID(uuid: string): Promise<Perspective|null> {
|
|
132
|
-
|
|
133
|
-
query: gql`query perspectiveSnapshot($uuid: String!) {
|
|
134
|
-
perspectiveSnapshot(uuid: $uuid) {
|
|
135
|
-
links { ${LINK_EXPRESSION_FIELDS} }
|
|
136
|
-
}
|
|
137
|
-
}`,
|
|
138
|
-
variables: { uuid }
|
|
139
|
-
}))
|
|
140
|
-
return perspectiveSnapshot
|
|
106
|
+
return this.#apiClient.call<Perspective|null>('perspective.snapshot', { uuid })
|
|
141
107
|
}
|
|
108
|
+
|
|
142
109
|
async publishSnapshotByUUID(uuid: string): Promise<string|null> {
|
|
143
|
-
|
|
144
|
-
mutation: gql`mutation perspectivePublishSnapshot($uuid: String!) {
|
|
145
|
-
perspectivePublishSnapshot(uuid: $uuid)
|
|
146
|
-
}`,
|
|
147
|
-
variables: { uuid }
|
|
148
|
-
}))
|
|
149
|
-
return perspectivePublishSnapshot
|
|
110
|
+
return this.#apiClient.call<string|null>('perspective.publishSnapshot', { uuid })
|
|
150
111
|
}
|
|
151
112
|
|
|
152
113
|
async queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]> {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
return perspectiveQueryLinks
|
|
114
|
+
const params: Record<string, unknown> = { uuid }
|
|
115
|
+
if (query.source) params.source = query.source
|
|
116
|
+
if (query.predicate) params.predicate = query.predicate
|
|
117
|
+
if (query.target) params.target = query.target
|
|
118
|
+
if (query.fromDate) params.fromDate = query.fromDate instanceof Date ? query.fromDate.toISOString() : String(query.fromDate)
|
|
119
|
+
if (query.untilDate) params.untilDate = query.untilDate instanceof Date ? query.untilDate.toISOString() : String(query.untilDate)
|
|
120
|
+
if (query.limit !== undefined) params.limit = query.limit
|
|
121
|
+
return this.#apiClient.call<LinkExpression[]>('perspective.queryLinks', params)
|
|
162
122
|
}
|
|
163
123
|
|
|
164
|
-
async queryProlog(uuid: string, query: string): Promise<
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}`,
|
|
169
|
-
variables: { uuid, query }
|
|
170
|
-
}))
|
|
124
|
+
async queryProlog(uuid: string, query: string): Promise<unknown> {
|
|
125
|
+
const result = await this.#apiClient.call<string>('perspective.queryProlog', { uuid, query })
|
|
126
|
+
return JSON.parse(result)
|
|
127
|
+
}
|
|
171
128
|
|
|
172
|
-
|
|
129
|
+
async querySparql(uuid: string, query: string): Promise<unknown> {
|
|
130
|
+
const result = await this.#apiClient.call<string>('perspective.querySparql', { uuid, engine: 'sparql', query })
|
|
131
|
+
return JSON.parse(result)
|
|
173
132
|
}
|
|
174
133
|
|
|
175
|
-
async
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
134
|
+
async subscribeQuery(uuid: string, query: string): Promise<{ subscriptionId: string, result: AllInstancesResult, isInit?: boolean }> {
|
|
135
|
+
const response = await this.#apiClient.call<{ subscriptionId: string, result: unknown }>(
|
|
136
|
+
'perspective.subscribeQuery', { uuid, query }
|
|
137
|
+
)
|
|
138
|
+
const { subscriptionId, result } = response
|
|
139
|
+
const normalized = normalizeQueryResult(result, 'Error parsing subscribeQuery result:')
|
|
140
|
+
return { subscriptionId, result: normalized.result, isInit: normalized.isInit }
|
|
141
|
+
}
|
|
182
142
|
|
|
183
|
-
|
|
143
|
+
async perspectiveKeepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
144
|
+
return this.#apiClient.call<boolean>(
|
|
145
|
+
'perspective.keepAliveQuery', { uuid, subscriptionId }
|
|
146
|
+
)
|
|
184
147
|
}
|
|
185
148
|
|
|
186
|
-
async
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
subscriptionId
|
|
191
|
-
result
|
|
192
|
-
}
|
|
193
|
-
}`,
|
|
194
|
-
variables: { uuid, query }
|
|
195
|
-
}))
|
|
196
|
-
const { subscriptionId, result } = perspectiveSubscribeQuery
|
|
197
|
-
let finalResult = result;
|
|
198
|
-
let isInit = false;
|
|
199
|
-
if(finalResult.startsWith("#init#")) {
|
|
200
|
-
finalResult = finalResult.substring(6)
|
|
201
|
-
isInit = true;
|
|
202
|
-
}
|
|
203
|
-
try {
|
|
204
|
-
finalResult = JSON.parse(finalResult)
|
|
205
|
-
} catch (e) {
|
|
206
|
-
console.error('Error parsing perspectiveSubscribeQuery result:', e)
|
|
207
|
-
}
|
|
208
|
-
return { subscriptionId, result: finalResult, isInit }
|
|
149
|
+
async perspectiveDisposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
150
|
+
return this.#apiClient.call<boolean>(
|
|
151
|
+
'perspective.disposeQuery', { uuid, subscriptionId }
|
|
152
|
+
)
|
|
209
153
|
}
|
|
210
154
|
|
|
211
155
|
subscribeToQueryUpdates(subscriptionId: string, onData: (result: AllInstancesResult) => void): () => void {
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
subscriptionId
|
|
220
|
-
}
|
|
221
|
-
}).subscribe({
|
|
222
|
-
next: (result) => {
|
|
223
|
-
if (result.data && result.data.perspectiveQuerySubscription) {
|
|
224
|
-
let finalResult = result.data.perspectiveQuerySubscription;
|
|
225
|
-
let isInit = false;
|
|
226
|
-
if(finalResult.startsWith("#init#")) {
|
|
227
|
-
finalResult = finalResult.substring(6)
|
|
228
|
-
isInit = true;
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
finalResult = JSON.parse(finalResult)
|
|
232
|
-
if(isInit && typeof finalResult === 'object') {
|
|
233
|
-
finalResult.isInit = true;
|
|
234
|
-
}
|
|
235
|
-
} catch (e) {
|
|
236
|
-
console.error('Error parsing perspectiveQuerySubscription:', e)
|
|
237
|
-
}
|
|
238
|
-
onData(finalResult);
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
error: (e) => console.error('Error in query subscription:', e)
|
|
242
|
-
});
|
|
156
|
+
const unsub = this.#apiClient.subscribe(
|
|
157
|
+
(data) => {
|
|
158
|
+
const event = data as Record<string, unknown>
|
|
159
|
+
if (event.type !== 'query-subscription-update') return
|
|
160
|
+
|
|
161
|
+
const eventSubscriptionId = event.subscriptionId || event.subscription_id
|
|
162
|
+
if (eventSubscriptionId !== subscriptionId) return
|
|
243
163
|
|
|
244
|
-
|
|
164
|
+
const normalized = normalizeQueryResult(event.result, 'Error parsing query subscription:')
|
|
165
|
+
onData(normalized.result)
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
this.#querySubscriptionUnsubscribers.set(subscriptionId, unsub)
|
|
169
|
+
return unsub
|
|
245
170
|
}
|
|
246
171
|
|
|
247
172
|
async keepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}`,
|
|
252
|
-
variables: { uuid, subscriptionId }
|
|
253
|
-
}))
|
|
254
|
-
|
|
255
|
-
return perspectiveKeepAliveQuery
|
|
173
|
+
return this.#apiClient.call<boolean>(
|
|
174
|
+
'perspective.keepAliveQuery', { uuid, subscriptionId }
|
|
175
|
+
)
|
|
256
176
|
}
|
|
257
177
|
|
|
258
178
|
async disposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
179
|
+
const unsub = this.#querySubscriptionUnsubscribers.get(subscriptionId)
|
|
180
|
+
if (unsub) {
|
|
181
|
+
unsub()
|
|
182
|
+
this.#querySubscriptionUnsubscribers.delete(subscriptionId)
|
|
183
|
+
}
|
|
184
|
+
return this.#apiClient.call<boolean>(
|
|
185
|
+
'perspective.disposeQuery', { uuid, subscriptionId }
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async modelQuery(uuid: string, className: string, queryJson: string, shapeJson?: string): Promise<any> {
|
|
190
|
+
const resultJson = await this.#apiClient.call<string>(
|
|
191
|
+
'perspective.modelQuery', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson }
|
|
192
|
+
)
|
|
193
|
+
return JSON.parse(resultJson)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async evaluateGetters(
|
|
197
|
+
uuid: string,
|
|
198
|
+
className: string,
|
|
199
|
+
instanceIds: string[],
|
|
200
|
+
shapeJson: string,
|
|
201
|
+
propertyNames?: string[],
|
|
202
|
+
): Promise<Record<string, Record<string, any>>> {
|
|
203
|
+
const resultJson = await this.#apiClient.call<string>(
|
|
204
|
+
'perspective.evaluateGetters', {
|
|
205
|
+
uuid,
|
|
206
|
+
class_name: className,
|
|
207
|
+
instance_ids: instanceIds,
|
|
208
|
+
shape_json: shapeJson,
|
|
209
|
+
...(propertyNames && { property_names: propertyNames }),
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
return JSON.parse(resultJson)
|
|
213
|
+
}
|
|
265
214
|
|
|
266
|
-
|
|
215
|
+
async modelSubscribe(uuid: string, className: string, queryJson: string, shapeJson?: string): Promise<{ subscriptionId: string, result: any }> {
|
|
216
|
+
const response = await this.#apiClient.call<{ subscription_id: string, result: string }>(
|
|
217
|
+
'perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson }
|
|
218
|
+
)
|
|
219
|
+
return {
|
|
220
|
+
subscriptionId: response.subscription_id,
|
|
221
|
+
result: JSON.parse(response.result)
|
|
222
|
+
}
|
|
267
223
|
}
|
|
268
224
|
|
|
269
225
|
async add(name: string): Promise<PerspectiveProxy> {
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
perspectiveAdd(name: $name) {
|
|
273
|
-
${PERSPECTIVE_HANDLE_FIELDS}
|
|
274
|
-
}
|
|
275
|
-
}`,
|
|
276
|
-
variables: { name }
|
|
277
|
-
}))
|
|
278
|
-
return this.getOrCreateProxy(perspectiveAdd)
|
|
226
|
+
const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.create', { name })
|
|
227
|
+
return new PerspectiveProxy(handle, this)
|
|
279
228
|
}
|
|
280
229
|
|
|
281
230
|
async update(uuid: string, name: string): Promise<PerspectiveProxy> {
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
perspectiveUpdate(uuid: $uuid, name: $name) {
|
|
285
|
-
${PERSPECTIVE_HANDLE_FIELDS}
|
|
286
|
-
}
|
|
287
|
-
}`,
|
|
288
|
-
variables: { uuid, name }
|
|
289
|
-
}))
|
|
290
|
-
// Evict stale proxy — getOrCreateProxy will create a fresh one with updated handle
|
|
291
|
-
this.#proxyCache.delete(uuid)
|
|
292
|
-
return this.getOrCreateProxy(perspectiveUpdate)
|
|
231
|
+
const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.update', { uuid, name })
|
|
232
|
+
return new PerspectiveProxy(handle, this)
|
|
293
233
|
}
|
|
294
234
|
|
|
295
235
|
async remove(uuid: string): Promise<{perspectiveRemove: boolean}> {
|
|
296
|
-
this.#
|
|
297
|
-
return
|
|
298
|
-
mutation: gql`mutation perspectiveRemove($uuid: String!) {
|
|
299
|
-
perspectiveRemove(uuid: $uuid)
|
|
300
|
-
}`,
|
|
301
|
-
variables: { uuid }
|
|
302
|
-
}))
|
|
236
|
+
const result = await this.#apiClient.call<boolean>('perspective.remove', { uuid })
|
|
237
|
+
return { perspectiveRemove: result }
|
|
303
238
|
}
|
|
304
239
|
|
|
305
240
|
async addLink(uuid: string, link: Link, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
${LINK_EXPRESSION_FIELDS}
|
|
310
|
-
}
|
|
311
|
-
}`,
|
|
312
|
-
variables: { uuid, link, status, batchId }
|
|
313
|
-
}))
|
|
314
|
-
return perspectiveAddLink
|
|
241
|
+
return this.#apiClient.call<LinkExpression>(
|
|
242
|
+
'perspective.addLink', { uuid, link, status, batchId }
|
|
243
|
+
)
|
|
315
244
|
}
|
|
316
245
|
|
|
317
246
|
async addLinks(uuid: string, links: Link[], status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression[]> {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
${LINK_EXPRESSION_FIELDS}
|
|
322
|
-
}
|
|
323
|
-
}`,
|
|
324
|
-
variables: { uuid, links, status, batchId }
|
|
325
|
-
}))
|
|
326
|
-
return perspectiveAddLinks
|
|
247
|
+
return this.#apiClient.call<LinkExpression[]>(
|
|
248
|
+
'perspective.addLinks', { uuid, links, status, batchId }
|
|
249
|
+
)
|
|
327
250
|
}
|
|
328
251
|
|
|
329
252
|
async removeLinks(uuid: string, links: LinkExpressionInput[], batchId?: string): Promise<LinkExpression[]> {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
${LINK_EXPRESSION_FIELDS}
|
|
334
|
-
}
|
|
335
|
-
}`,
|
|
336
|
-
variables: { uuid, links, batchId }
|
|
337
|
-
}))
|
|
338
|
-
return perspectiveRemoveLinks
|
|
253
|
+
return this.#apiClient.call<LinkExpression[]>(
|
|
254
|
+
'perspective.removeLinks', { uuid, links, batchId }
|
|
255
|
+
)
|
|
339
256
|
}
|
|
340
257
|
|
|
341
258
|
async linkMutations(uuid: string, mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations> {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
additions {
|
|
346
|
-
${LINK_EXPRESSION_FIELDS}
|
|
347
|
-
}
|
|
348
|
-
removals {
|
|
349
|
-
${LINK_EXPRESSION_FIELDS}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}`,
|
|
353
|
-
variables: { uuid, mutations, status }
|
|
354
|
-
}))
|
|
355
|
-
return perspectiveLinkMutations
|
|
259
|
+
return this.#apiClient.call<LinkExpressionMutations>(
|
|
260
|
+
'perspective.linkMutations', { uuid, mutations, status }
|
|
261
|
+
)
|
|
356
262
|
}
|
|
357
263
|
|
|
358
264
|
async addLinkExpression(uuid: string, link: LinkExpression, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
${LINK_EXPRESSION_FIELDS}
|
|
363
|
-
}
|
|
364
|
-
}`,
|
|
365
|
-
variables: { uuid, link, status, batchId }
|
|
366
|
-
}))
|
|
367
|
-
return perspectiveAddLinkExpression
|
|
265
|
+
return this.#apiClient.call<LinkExpression>(
|
|
266
|
+
'perspective.addLinkExpression', { uuid, link, status, batchId }
|
|
267
|
+
)
|
|
368
268
|
}
|
|
369
269
|
|
|
370
270
|
async updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: Link, batchId?: string): Promise<LinkExpression> {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
${LINK_EXPRESSION_FIELDS}
|
|
375
|
-
}
|
|
376
|
-
}`,
|
|
377
|
-
variables: { uuid, oldLink, newLink, batchId }
|
|
378
|
-
}))
|
|
379
|
-
return perspectiveUpdateLink
|
|
271
|
+
return this.#apiClient.call<LinkExpression>(
|
|
272
|
+
'perspective.updateLink', { uuid, oldLink, newLink, batchId }
|
|
273
|
+
)
|
|
380
274
|
}
|
|
381
275
|
|
|
382
276
|
async removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean> {
|
|
@@ -384,68 +278,42 @@ export class PerspectiveClient {
|
|
|
384
278
|
delete link.data.__typename
|
|
385
279
|
delete link.proof.__typename
|
|
386
280
|
delete link.status
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}))
|
|
393
|
-
return perspectiveRemoveLink
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Adds Social DNA code to a perspective.
|
|
398
|
-
*
|
|
399
|
-
* Preferred usage: pass shaclJson (from SHACLShape.toJSON()) as the primary schema definition.
|
|
400
|
-
* The sdnaCode parameter is kept for backward compatibility but SHACL is the source of truth
|
|
401
|
-
* for all SDNA operations. Prolog engines remain available for complex queries.
|
|
402
|
-
*
|
|
403
|
-
* @param sdnaCode - Legacy Prolog code (pass empty string when using shaclJson)
|
|
404
|
-
* @param shaclJson - SHACL JSON string from SHACLShape.toJSON() (recommended)
|
|
405
|
-
*/
|
|
281
|
+
return this.#apiClient.call<boolean>(
|
|
282
|
+
'perspective.removeLink', { uuid, link, batchId }
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
|
|
406
286
|
async addSdna(uuid: string, name: string, sdnaCode: string | undefined, sdnaType: "subject_class" | "flow" | "custom", shaclJson?: string): Promise<boolean> {
|
|
407
|
-
return
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
}`,
|
|
411
|
-
variables: { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
|
|
412
|
-
})).perspectiveAddSdna
|
|
287
|
+
return this.#apiClient.call<boolean>(
|
|
288
|
+
'perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
|
|
289
|
+
)
|
|
413
290
|
}
|
|
414
291
|
|
|
415
292
|
async executeCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Promise<boolean> {
|
|
416
|
-
return
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}`,
|
|
420
|
-
variables: { uuid, commands, expression, parameters, batchId }
|
|
421
|
-
})).perspectiveExecuteCommands
|
|
293
|
+
return this.#apiClient.call<boolean>(
|
|
294
|
+
'perspective.executeCommands', { uuid, commands, expression, parameters, batchId }
|
|
295
|
+
)
|
|
422
296
|
}
|
|
423
297
|
|
|
424
298
|
async createSubject(uuid: string, subjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Promise<boolean> {
|
|
425
|
-
return
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}`,
|
|
429
|
-
variables: { uuid, subjectClass, expressionAddress, initialValues, batchId }
|
|
430
|
-
})).perspectiveCreateSubject
|
|
299
|
+
return this.#apiClient.call<boolean>(
|
|
300
|
+
'perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId }
|
|
301
|
+
)
|
|
431
302
|
}
|
|
432
303
|
|
|
433
304
|
async getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string> {
|
|
434
|
-
return
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}`,
|
|
438
|
-
variables: { uuid, subjectClass, expressionAddress }
|
|
439
|
-
})).perspectiveGetSubjectData
|
|
305
|
+
return this.#apiClient.call<string>(
|
|
306
|
+
'perspective.getSubjectData', { uuid, subjectClass, expressionAddress }
|
|
307
|
+
)
|
|
440
308
|
}
|
|
441
309
|
|
|
442
310
|
// ExpressionClient functions, needed for Subjects:
|
|
443
311
|
async getExpression(expressionURI: string): Promise<ExpressionRendered> {
|
|
444
|
-
return await this.#expressionClient
|
|
312
|
+
return await this.#expressionClient!.get(expressionURI)
|
|
445
313
|
}
|
|
446
314
|
|
|
447
|
-
async createExpression(content:
|
|
448
|
-
return await this.#expressionClient
|
|
315
|
+
async createExpression(content: unknown, languageAddress: string): Promise<string> {
|
|
316
|
+
return await this.#expressionClient!.create(content, languageAddress)
|
|
449
317
|
}
|
|
450
318
|
|
|
451
319
|
// Subscriptions:
|
|
@@ -454,21 +322,12 @@ export class PerspectiveClient {
|
|
|
454
322
|
}
|
|
455
323
|
|
|
456
324
|
subscribePerspectiveAdded() {
|
|
457
|
-
this.#
|
|
458
|
-
|
|
459
|
-
|
|
325
|
+
const unsub = this.#apiClient.subscribe((data) => {
|
|
326
|
+
if (data.type === 'perspective-added') {
|
|
327
|
+
this.#perspectiveAddedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
|
|
460
328
|
}
|
|
461
|
-
`}).subscribe({
|
|
462
|
-
next: result => {
|
|
463
|
-
const handle = result.data.perspectiveAdded
|
|
464
|
-
this.#perspectiveAddedCallbacks.forEach(cb => {
|
|
465
|
-
cb(handle)
|
|
466
|
-
})
|
|
467
|
-
// Populate cache so subsequent byUUID() calls get a hit
|
|
468
|
-
this.getOrCreateProxy(handle)
|
|
469
|
-
},
|
|
470
|
-
error: (e) => console.error(e)
|
|
471
329
|
})
|
|
330
|
+
this.#unsubscribers.push(unsub)
|
|
472
331
|
}
|
|
473
332
|
|
|
474
333
|
addPerspectiveUpdatedListener(cb: PerspectiveHandleCallback) {
|
|
@@ -476,22 +335,12 @@ export class PerspectiveClient {
|
|
|
476
335
|
}
|
|
477
336
|
|
|
478
337
|
subscribePerspectiveUpdated() {
|
|
479
|
-
this.#
|
|
480
|
-
|
|
481
|
-
|
|
338
|
+
const unsub = this.#apiClient.subscribe((data) => {
|
|
339
|
+
if (data.type === 'perspective-updated') {
|
|
340
|
+
this.#perspectiveUpdatedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
|
|
482
341
|
}
|
|
483
|
-
`}).subscribe({
|
|
484
|
-
next: result => {
|
|
485
|
-
const handle = result.data.perspectiveUpdated
|
|
486
|
-
this.#perspectiveUpdatedCallbacks.forEach(cb => {
|
|
487
|
-
cb(handle)
|
|
488
|
-
})
|
|
489
|
-
// Evict stale proxy and create fresh one with updated handle
|
|
490
|
-
this.#proxyCache.delete(handle.uuid)
|
|
491
|
-
this.getOrCreateProxy(handle)
|
|
492
|
-
},
|
|
493
|
-
error: (e) => console.error(e)
|
|
494
342
|
})
|
|
343
|
+
this.#unsubscribers.push(unsub)
|
|
495
344
|
}
|
|
496
345
|
|
|
497
346
|
addPerspectiveSyncedListener(cb: SyncStateChangeCallback) {
|
|
@@ -499,19 +348,14 @@ export class PerspectiveClient {
|
|
|
499
348
|
}
|
|
500
349
|
|
|
501
350
|
async addPerspectiveSyncStateChangeListener(uuid: String, cb: SyncStateChangeCallback[]): Promise<void> {
|
|
502
|
-
this.#
|
|
503
|
-
|
|
504
|
-
|
|
351
|
+
const unsub = this.#apiClient.subscribe(
|
|
352
|
+
(data) => {
|
|
353
|
+
if (data.type === 'sync-state-change' && data.uuid === uuid) {
|
|
354
|
+
cb.forEach(c => c(data.state as PerspectiveState))
|
|
355
|
+
}
|
|
505
356
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
cb.forEach(c => {
|
|
509
|
-
c(result.data.perspectiveSyncStateChange)
|
|
510
|
-
})
|
|
511
|
-
},
|
|
512
|
-
error: (e) => console.error(e)
|
|
513
|
-
})
|
|
514
|
-
|
|
357
|
+
)
|
|
358
|
+
this.#unsubscribers.push(unsub)
|
|
515
359
|
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
516
360
|
}
|
|
517
361
|
|
|
@@ -520,118 +364,79 @@ export class PerspectiveClient {
|
|
|
520
364
|
}
|
|
521
365
|
|
|
522
366
|
subscribePerspectiveRemoved() {
|
|
523
|
-
this.#
|
|
524
|
-
|
|
525
|
-
|
|
367
|
+
const unsub = this.#apiClient.subscribe((data) => {
|
|
368
|
+
if (data.type === 'perspective-removed') {
|
|
369
|
+
this.#perspectiveRemovedCallbacks.forEach(cb => cb(data.uuid as string))
|
|
526
370
|
}
|
|
527
|
-
`}).subscribe({
|
|
528
|
-
next: result => {
|
|
529
|
-
const uuid = result.data.perspectiveRemoved
|
|
530
|
-
this.#perspectiveRemovedCallbacks.forEach(cb => {
|
|
531
|
-
cb(uuid)
|
|
532
|
-
})
|
|
533
|
-
// Evict from cache
|
|
534
|
-
this.#proxyCache.delete(uuid)
|
|
535
|
-
},
|
|
536
|
-
error: (e) => console.error(e)
|
|
537
371
|
})
|
|
372
|
+
this.#unsubscribers.push(unsub)
|
|
538
373
|
}
|
|
539
374
|
|
|
540
375
|
async addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
|
|
541
|
-
this.#
|
|
542
|
-
|
|
543
|
-
|
|
376
|
+
const unsub = this.#apiClient.subscribe(
|
|
377
|
+
(data) => {
|
|
378
|
+
if (data.type === 'link-added' && data.perspectiveUuid === uuid) {
|
|
379
|
+
cb.forEach(c => c(data.link as LinkExpression))
|
|
380
|
+
}
|
|
544
381
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
},
|
|
551
|
-
error: (e) => console.error(e)
|
|
552
|
-
})
|
|
553
|
-
|
|
554
|
-
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
382
|
+
)
|
|
383
|
+
let existing = this.#linkUnsubscribers.get(uuid as string) || []
|
|
384
|
+
existing.push(unsub)
|
|
385
|
+
this.#linkUnsubscribers.set(uuid as string, existing)
|
|
386
|
+
await this.#apiClient.waitForSubscription()
|
|
555
387
|
}
|
|
556
388
|
|
|
557
389
|
async addPerspectiveLinkRemovedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
|
|
558
|
-
this.#
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
cb.forEach(c => {
|
|
565
|
-
if (!result.data.perspectiveLinkRemoved.status) {
|
|
566
|
-
delete result.data.perspectiveLinkRemoved.status
|
|
390
|
+
const unsub = this.#apiClient.subscribe(
|
|
391
|
+
(data) => {
|
|
392
|
+
if (data.type === 'link-removed' && data.perspectiveUuid === uuid) {
|
|
393
|
+
const link = data.link as LinkExpression & { status?: unknown }
|
|
394
|
+
if (!link.status) {
|
|
395
|
+
delete link.status
|
|
567
396
|
}
|
|
568
|
-
c(
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
397
|
+
cb.forEach(c => c(link))
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
)
|
|
401
|
+
let existing = this.#linkUnsubscribers.get(uuid as string) || []
|
|
402
|
+
existing.push(unsub)
|
|
403
|
+
this.#linkUnsubscribers.set(uuid as string, existing)
|
|
404
|
+
await this.#apiClient.waitForSubscription()
|
|
575
405
|
}
|
|
576
406
|
|
|
577
407
|
async addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
|
|
578
|
-
this.#
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
408
|
+
const unsub = this.#apiClient.subscribe(
|
|
409
|
+
(data) => {
|
|
410
|
+
if (data.type === 'link-updated' && data.perspectiveUuid === uuid) {
|
|
411
|
+
const newLink = data.newLink as LinkExpression & { status?: unknown }
|
|
412
|
+
const oldLink = data.oldLink as LinkExpression & { status?: unknown }
|
|
413
|
+
if (!newLink.status) {
|
|
414
|
+
delete newLink.status
|
|
583
415
|
}
|
|
584
|
-
|
|
585
|
-
|
|
416
|
+
if (!oldLink.status) {
|
|
417
|
+
delete oldLink.status
|
|
586
418
|
}
|
|
419
|
+
cb.forEach(c => c(data as unknown as LinkExpression))
|
|
587
420
|
}
|
|
588
421
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
if (!result.data.perspectiveLinkUpdated.oldLink.status) {
|
|
596
|
-
delete result.data.perspectiveLinkUpdated.oldLink.status
|
|
597
|
-
}
|
|
598
|
-
c(result.data.perspectiveLinkUpdated)
|
|
599
|
-
})
|
|
600
|
-
},
|
|
601
|
-
error: (e) => console.error(e)
|
|
602
|
-
})
|
|
603
|
-
|
|
604
|
-
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
422
|
+
)
|
|
423
|
+
let existing = this.#linkUnsubscribers.get(uuid as string) || []
|
|
424
|
+
existing.push(unsub)
|
|
425
|
+
this.#linkUnsubscribers.set(uuid as string, existing)
|
|
426
|
+
await this.#apiClient.waitForSubscription()
|
|
605
427
|
}
|
|
606
428
|
|
|
607
429
|
getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy {
|
|
608
|
-
return new NeighbourhoodProxy(this.#neighbourhoodClient
|
|
430
|
+
return new NeighbourhoodProxy(this.#neighbourhoodClient!, uuid)
|
|
609
431
|
}
|
|
610
432
|
|
|
611
433
|
async createBatch(uuid: string): Promise<string> {
|
|
612
|
-
|
|
613
|
-
mutation: gql`mutation perspectiveCreateBatch($uuid: String!) {
|
|
614
|
-
perspectiveCreateBatch(uuid: $uuid)
|
|
615
|
-
}`,
|
|
616
|
-
variables: { uuid }
|
|
617
|
-
}))
|
|
618
|
-
return perspectiveCreateBatch
|
|
434
|
+
return this.#apiClient.call<string>('perspective.createBatch', { uuid })
|
|
619
435
|
}
|
|
620
436
|
|
|
621
437
|
async commitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations> {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
additions {
|
|
626
|
-
${LINK_EXPRESSION_FIELDS}
|
|
627
|
-
}
|
|
628
|
-
removals {
|
|
629
|
-
${LINK_EXPRESSION_FIELDS}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}`,
|
|
633
|
-
variables: { uuid, batchId }
|
|
634
|
-
}))
|
|
635
|
-
return perspectiveCommitBatch
|
|
438
|
+
return this.#apiClient.call<LinkExpressionMutations>(
|
|
439
|
+
'perspective.commitBatch', { uuid, batchId }
|
|
440
|
+
)
|
|
636
441
|
}
|
|
637
|
-
}
|
|
442
|
+
}
|