@coasys/ad4m 0.13.0-test-3 → 0.13.0-test-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -25
- package/jest-setup.ts +1 -1
- package/lib/index.cjs +2406 -11070
- package/lib/index.js +2209 -10925
- package/lib/src/Ad4mClient.d.ts +7 -3
- package/lib/src/Ad4mClient.js +29 -13
- package/lib/src/agent/Agent.js +26 -272
- package/lib/src/agent/AgentClient.d.ts +10 -21
- package/lib/src/agent/AgentClient.js +75 -427
- package/lib/src/agent/AgentStatus.js +2 -37
- package/lib/src/ai/AIClient.d.ts +12 -4
- package/lib/src/ai/AIClient.js +81 -285
- package/lib/src/ai/AITypes.d.ts +55 -0
- package/lib/src/ai/AITypes.js +18 -0
- package/lib/src/ai/Tasks.js +10 -133
- package/lib/src/apiClient.d.ts +52 -0
- package/lib/src/apiClient.js +231 -0
- package/lib/src/expression/Expression.d.ts +1 -1
- package/lib/src/expression/Expression.js +13 -122
- package/lib/src/expression/ExpressionClient.d.ts +3 -3
- package/lib/src/expression/ExpressionClient.js +13 -76
- package/lib/src/expression/ExpressionRef.js +2 -25
- package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
- package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
- package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinkRequest.js +1 -0
- package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
- package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
- package/lib/src/generated/api/AddSdnaRequest.js +2 -0
- package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
- package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
- package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
- package/lib/src/generated/api/AuthInfoInput.js +1 -0
- package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
- package/lib/src/generated/api/CapabilityInput.js +1 -0
- package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/CommitBatchRequest.js +2 -0
- package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
- package/lib/src/generated/api/ComputeLogEntry.js +2 -0
- package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
- package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
- package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
- package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
- package/lib/src/generated/api/EmbedRequest.js +2 -0
- package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
- package/lib/src/generated/api/EntanglementProofInput.js +2 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
- package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
- package/lib/src/generated/api/ExportRequest.d.ts +5 -0
- package/lib/src/generated/api/ExportRequest.js +2 -0
- package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
- package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
- package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
- package/lib/src/generated/api/ExpressionProof.js +2 -0
- package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
- package/lib/src/generated/api/ExpressionProofInput.js +2 -0
- package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
- package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
- package/lib/src/generated/api/FriendsListRequest.js +2 -0
- package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
- package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
- package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
- package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
- package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
- package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
- package/lib/src/generated/api/ImportAgentRequest.js +2 -0
- package/lib/src/generated/api/ImportRequest.d.ts +4 -0
- package/lib/src/generated/api/ImportRequest.js +2 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
- package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
- package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
- package/lib/src/generated/api/LanguageMetaInput.js +2 -0
- package/lib/src/generated/api/Link.d.ts +5 -0
- package/lib/src/generated/api/Link.js +2 -0
- package/lib/src/generated/api/LinkExpression.d.ts +10 -0
- package/lib/src/generated/api/LinkExpression.js +1 -0
- package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
- package/lib/src/generated/api/LinkExpressionInput.js +1 -0
- package/lib/src/generated/api/LinkInput.d.ts +5 -0
- package/lib/src/generated/api/LinkInput.js +2 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
- package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
- package/lib/src/generated/api/LinkMutations.d.ts +6 -0
- package/lib/src/generated/api/LinkMutations.js +1 -0
- package/lib/src/generated/api/LinkStatus.d.ts +1 -0
- package/lib/src/generated/api/LinkStatus.js +2 -0
- package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
- package/lib/src/generated/api/LockAgentRequest.js +2 -0
- package/lib/src/generated/api/ModelType.d.ts +1 -0
- package/lib/src/generated/api/ModelType.js +2 -0
- package/lib/src/generated/api/NotificationInput.d.ts +10 -0
- package/lib/src/generated/api/NotificationInput.js +2 -0
- package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
- package/lib/src/generated/api/OpenLinkRequest.js +2 -0
- package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
- package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
- package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveInput.js +1 -0
- package/lib/src/generated/api/PromptRequest.d.ts +4 -0
- package/lib/src/generated/api/PromptRequest.js +2 -0
- package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
- package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
- package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
- package/lib/src/generated/api/QueryRequest.d.ts +7 -0
- package/lib/src/generated/api/QueryRequest.js +2 -0
- package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
- package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
- package/lib/src/generated/api/ResourceInput.d.ts +4 -0
- package/lib/src/generated/api/ResourceInput.js +2 -0
- package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
- package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
- package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
- package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
- package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
- package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
- package/lib/src/generated/api/SetStatusRequest.js +2 -0
- package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
- package/lib/src/generated/api/SignMessageRequest.js +2 -0
- package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
- package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
- package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
- package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
- package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
- package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
- package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
- package/lib/src/generated/api/UserStatistics.d.ts +9 -0
- package/lib/src/generated/api/UserStatistics.js +2 -0
- package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
- package/lib/src/generated/api/VerificationRequestResult.js +2 -0
- package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
- package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
- package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
- package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +42 -0
- package/lib/src/generated/api/index.js +7 -0
- package/lib/src/index.d.ts +6 -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 +57 -38
- package/lib/src/model/Ad4mModel.js +594 -460
- package/lib/src/model/Ad4mModel.test.js +371 -815
- package/lib/src/model/ModelQueryBuilder.d.ts +9 -21
- package/lib/src/model/ModelQueryBuilder.js +138 -217
- package/lib/src/model/decorators.d.ts +22 -0
- package/lib/src/model/decorators.js +7 -0
- package/lib/src/model/hydration.d.ts +7 -60
- package/lib/src/model/hydration.js +7 -716
- 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/shacl-gen.js +4 -0
- package/lib/src/model/types.d.ts +47 -38
- package/lib/src/model/types.js +4 -1
- package/lib/src/neighbourhood/Neighbourhood.js +4 -32
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
- package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
- package/lib/src/perspectives/LinkQuery.js +2 -42
- package/lib/src/perspectives/Perspective.d.ts +1 -1
- package/lib/src/perspectives/Perspective.js +10 -52
- package/lib/src/perspectives/PerspectiveClient.d.ts +12 -17
- package/lib/src/perspectives/PerspectiveClient.js +169 -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 +92 -71
- package/lib/src/perspectives/PerspectiveProxy.js +273 -310
- package/lib/src/runtime/RuntimeClient.d.ts +6 -6
- package/lib/src/runtime/RuntimeClient.js +93 -467
- package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
- package/lib/src/runtime/RuntimeTypes.js +45 -0
- package/lib/src/shacl/SHACLShape.d.ts +7 -0
- package/lib/src/shacl/SHACLShape.js +19 -0
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/lib/src/typeDefs.js +3 -628
- package/package.json +9 -24
- package/rollup.config.js +0 -7
- package/src/Ad4mClient.test.ts +1179 -1340
- package/src/Ad4mClient.ts +30 -15
- package/src/agent/Agent.ts +0 -99
- package/src/agent/AgentClient.ts +112 -526
- package/src/agent/AgentStatus.ts +0 -12
- package/src/ai/AIClient.ts +96 -296
- package/src/ai/AITypes.ts +66 -0
- package/src/ai/Tasks.ts +0 -52
- package/src/apiClient.ts +283 -0
- package/src/expression/Expression.ts +3 -43
- package/src/expression/ExpressionClient.ts +14 -77
- package/src/expression/ExpressionRef.ts +0 -6
- package/src/generated/api/AIModelLoadingStatus.ts +3 -0
- package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
- package/src/generated/api/AddLinkRequest.ts +4 -0
- package/src/generated/api/AddLinksBulkRequest.ts +4 -0
- package/src/generated/api/AddSdnaRequest.ts +3 -0
- package/src/generated/api/ApplyTemplateRequest.ts +3 -0
- package/src/generated/api/AuthInfoInput.ts +4 -0
- package/src/generated/api/CapabilityInput.ts +4 -0
- package/src/generated/api/CommitBatchRequest.ts +3 -0
- package/src/generated/api/ComputeLogEntry.ts +3 -0
- package/src/generated/api/CreateExpressionRequest.ts +3 -0
- package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
- package/src/generated/api/CreateSubjectRequest.ts +3 -0
- package/src/generated/api/EmbedRequest.ts +3 -0
- package/src/generated/api/EntanglementProofInput.ts +3 -0
- package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
- package/src/generated/api/ExportRequest.ts +3 -0
- package/src/generated/api/ExpressionManyRequest.ts +3 -0
- package/src/generated/api/ExpressionProof.ts +3 -0
- package/src/generated/api/ExpressionProofInput.ts +3 -0
- package/src/generated/api/FriendSendMessageRequest.ts +3 -0
- package/src/generated/api/FriendsListRequest.ts +3 -0
- package/src/generated/api/GenerateAgentRequest.ts +3 -0
- package/src/generated/api/GenerateJwtRequest.ts +3 -0
- package/src/generated/api/GetSubjectDataRequest.ts +3 -0
- package/src/generated/api/ImportAgentRequest.ts +3 -0
- package/src/generated/api/ImportRequest.ts +3 -0
- package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
- package/src/generated/api/LanguageMetaInput.ts +3 -0
- package/src/generated/api/Link.ts +3 -0
- package/src/generated/api/LinkExpression.ts +6 -0
- package/src/generated/api/LinkExpressionInput.ts +6 -0
- package/src/generated/api/LinkInput.ts +3 -0
- package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
- package/src/generated/api/LinkMutations.ts +5 -0
- package/src/generated/api/LinkStatus.ts +3 -0
- package/src/generated/api/LockAgentRequest.ts +3 -0
- package/src/generated/api/ModelType.ts +3 -0
- package/src/generated/api/NotificationInput.ts +3 -0
- package/src/generated/api/OpenLinkRequest.ts +3 -0
- package/src/generated/api/PermitCapabilityRequest.ts +3 -0
- package/src/generated/api/PerspectiveInput.ts +4 -0
- package/src/generated/api/PromptRequest.ts +3 -0
- package/src/generated/api/PublishLanguageRequest.ts +4 -0
- package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
- package/src/generated/api/QueryRequest.ts +6 -0
- package/src/generated/api/RemoveLinkRequest.ts +4 -0
- package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
- package/src/generated/api/ResourceInput.ts +3 -0
- package/src/generated/api/SetDefaultModelRequest.ts +4 -0
- package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
- package/src/generated/api/SetMultiUserRequest.ts +3 -0
- package/src/generated/api/SetStatusRequest.ts +3 -0
- package/src/generated/api/SignMessageRequest.ts +3 -0
- package/src/generated/api/TrustedAgentsRequest.ts +3 -0
- package/src/generated/api/UnlockAgentRequest.ts +3 -0
- package/src/generated/api/UpdateLinkRequest.ts +5 -0
- package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
- package/src/generated/api/UserStatistics.ts +3 -0
- package/src/generated/api/VerificationRequestResult.ts +3 -0
- package/src/generated/api/VerifySignatureRequest.ts +3 -0
- package/src/generated/api/WriteSettingsRequest.ts +3 -0
- package/src/generated/api/index.ts +49 -0
- package/src/index.ts +6 -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 +708 -876
- package/src/model/Ad4mModel.ts +613 -508
- package/src/model/ModelQueryBuilder.ts +178 -244
- package/src/model/decorators.ts +29 -0
- package/src/model/hydration.ts +9 -766
- 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/shacl-gen.ts +5 -0
- package/src/model/types.ts +51 -39
- 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 +228 -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 +307 -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,175 @@ 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
|
+
}
|
|
265
188
|
|
|
266
|
-
|
|
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 modelSubscribe(uuid: string, className: string, queryJson: string, shapeJson?: string): Promise<{ subscriptionId: string, result: any }> {
|
|
197
|
+
const response = await this.#apiClient.call<{ subscription_id: string, result: string }>(
|
|
198
|
+
'perspective.modelSubscribe', { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson }
|
|
199
|
+
)
|
|
200
|
+
return {
|
|
201
|
+
subscriptionId: response.subscription_id,
|
|
202
|
+
result: JSON.parse(response.result)
|
|
203
|
+
}
|
|
267
204
|
}
|
|
268
205
|
|
|
269
206
|
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)
|
|
207
|
+
const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.create', { name })
|
|
208
|
+
return new PerspectiveProxy(handle, this)
|
|
279
209
|
}
|
|
280
210
|
|
|
281
211
|
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)
|
|
212
|
+
const handle = await this.#apiClient.call<PerspectiveHandle>('perspective.update', { uuid, name })
|
|
213
|
+
return new PerspectiveProxy(handle, this)
|
|
293
214
|
}
|
|
294
215
|
|
|
295
216
|
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
|
-
}))
|
|
217
|
+
const result = await this.#apiClient.call<boolean>('perspective.remove', { uuid })
|
|
218
|
+
return { perspectiveRemove: result }
|
|
303
219
|
}
|
|
304
220
|
|
|
305
221
|
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
|
|
222
|
+
return this.#apiClient.call<LinkExpression>(
|
|
223
|
+
'perspective.addLink', { uuid, link, status, batchId }
|
|
224
|
+
)
|
|
315
225
|
}
|
|
316
226
|
|
|
317
227
|
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
|
|
228
|
+
return this.#apiClient.call<LinkExpression[]>(
|
|
229
|
+
'perspective.addLinks', { uuid, links, status, batchId }
|
|
230
|
+
)
|
|
327
231
|
}
|
|
328
232
|
|
|
329
233
|
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
|
|
234
|
+
return this.#apiClient.call<LinkExpression[]>(
|
|
235
|
+
'perspective.removeLinks', { uuid, links, batchId }
|
|
236
|
+
)
|
|
339
237
|
}
|
|
340
238
|
|
|
341
239
|
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
|
|
240
|
+
return this.#apiClient.call<LinkExpressionMutations>(
|
|
241
|
+
'perspective.linkMutations', { uuid, mutations, status }
|
|
242
|
+
)
|
|
356
243
|
}
|
|
357
244
|
|
|
358
245
|
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
|
|
246
|
+
return this.#apiClient.call<LinkExpression>(
|
|
247
|
+
'perspective.addLinkExpression', { uuid, link, status, batchId }
|
|
248
|
+
)
|
|
368
249
|
}
|
|
369
250
|
|
|
370
251
|
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
|
|
252
|
+
return this.#apiClient.call<LinkExpression>(
|
|
253
|
+
'perspective.updateLink', { uuid, oldLink, newLink, batchId }
|
|
254
|
+
)
|
|
380
255
|
}
|
|
381
256
|
|
|
382
257
|
async removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean> {
|
|
@@ -384,68 +259,42 @@ export class PerspectiveClient {
|
|
|
384
259
|
delete link.data.__typename
|
|
385
260
|
delete link.proof.__typename
|
|
386
261
|
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
|
-
*/
|
|
262
|
+
return this.#apiClient.call<boolean>(
|
|
263
|
+
'perspective.removeLink', { uuid, link, batchId }
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
406
267
|
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
|
|
268
|
+
return this.#apiClient.call<boolean>(
|
|
269
|
+
'perspective.addSdna', { uuid, name, sdnaCode: sdnaCode || "", sdnaType, shaclJson }
|
|
270
|
+
)
|
|
413
271
|
}
|
|
414
272
|
|
|
415
273
|
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
|
|
274
|
+
return this.#apiClient.call<boolean>(
|
|
275
|
+
'perspective.executeCommands', { uuid, commands, expression, parameters, batchId }
|
|
276
|
+
)
|
|
422
277
|
}
|
|
423
278
|
|
|
424
279
|
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
|
|
280
|
+
return this.#apiClient.call<boolean>(
|
|
281
|
+
'perspective.createSubject', { uuid, subjectClass, expressionAddress, initialValues, batchId }
|
|
282
|
+
)
|
|
431
283
|
}
|
|
432
284
|
|
|
433
285
|
async getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string> {
|
|
434
|
-
return
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}`,
|
|
438
|
-
variables: { uuid, subjectClass, expressionAddress }
|
|
439
|
-
})).perspectiveGetSubjectData
|
|
286
|
+
return this.#apiClient.call<string>(
|
|
287
|
+
'perspective.getSubjectData', { uuid, subjectClass, expressionAddress }
|
|
288
|
+
)
|
|
440
289
|
}
|
|
441
290
|
|
|
442
291
|
// ExpressionClient functions, needed for Subjects:
|
|
443
292
|
async getExpression(expressionURI: string): Promise<ExpressionRendered> {
|
|
444
|
-
return await this.#expressionClient
|
|
293
|
+
return await this.#expressionClient!.get(expressionURI)
|
|
445
294
|
}
|
|
446
295
|
|
|
447
|
-
async createExpression(content:
|
|
448
|
-
return await this.#expressionClient
|
|
296
|
+
async createExpression(content: unknown, languageAddress: string): Promise<string> {
|
|
297
|
+
return await this.#expressionClient!.create(content, languageAddress)
|
|
449
298
|
}
|
|
450
299
|
|
|
451
300
|
// Subscriptions:
|
|
@@ -454,21 +303,12 @@ export class PerspectiveClient {
|
|
|
454
303
|
}
|
|
455
304
|
|
|
456
305
|
subscribePerspectiveAdded() {
|
|
457
|
-
this.#
|
|
458
|
-
|
|
459
|
-
|
|
306
|
+
const unsub = this.#apiClient.subscribe((data) => {
|
|
307
|
+
if (data.type === 'perspective-added') {
|
|
308
|
+
this.#perspectiveAddedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
|
|
460
309
|
}
|
|
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
310
|
})
|
|
311
|
+
this.#unsubscribers.push(unsub)
|
|
472
312
|
}
|
|
473
313
|
|
|
474
314
|
addPerspectiveUpdatedListener(cb: PerspectiveHandleCallback) {
|
|
@@ -476,22 +316,12 @@ export class PerspectiveClient {
|
|
|
476
316
|
}
|
|
477
317
|
|
|
478
318
|
subscribePerspectiveUpdated() {
|
|
479
|
-
this.#
|
|
480
|
-
|
|
481
|
-
|
|
319
|
+
const unsub = this.#apiClient.subscribe((data) => {
|
|
320
|
+
if (data.type === 'perspective-updated') {
|
|
321
|
+
this.#perspectiveUpdatedCallbacks.forEach(cb => cb(data.perspective as PerspectiveHandle))
|
|
482
322
|
}
|
|
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
323
|
})
|
|
324
|
+
this.#unsubscribers.push(unsub)
|
|
495
325
|
}
|
|
496
326
|
|
|
497
327
|
addPerspectiveSyncedListener(cb: SyncStateChangeCallback) {
|
|
@@ -499,19 +329,14 @@ export class PerspectiveClient {
|
|
|
499
329
|
}
|
|
500
330
|
|
|
501
331
|
async addPerspectiveSyncStateChangeListener(uuid: String, cb: SyncStateChangeCallback[]): Promise<void> {
|
|
502
|
-
this.#
|
|
503
|
-
|
|
504
|
-
|
|
332
|
+
const unsub = this.#apiClient.subscribe(
|
|
333
|
+
(data) => {
|
|
334
|
+
if (data.type === 'sync-state-change' && data.uuid === uuid) {
|
|
335
|
+
cb.forEach(c => c(data.state as PerspectiveState))
|
|
336
|
+
}
|
|
505
337
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
cb.forEach(c => {
|
|
509
|
-
c(result.data.perspectiveSyncStateChange)
|
|
510
|
-
})
|
|
511
|
-
},
|
|
512
|
-
error: (e) => console.error(e)
|
|
513
|
-
})
|
|
514
|
-
|
|
338
|
+
)
|
|
339
|
+
this.#unsubscribers.push(unsub)
|
|
515
340
|
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
516
341
|
}
|
|
517
342
|
|
|
@@ -520,118 +345,79 @@ export class PerspectiveClient {
|
|
|
520
345
|
}
|
|
521
346
|
|
|
522
347
|
subscribePerspectiveRemoved() {
|
|
523
|
-
this.#
|
|
524
|
-
|
|
525
|
-
|
|
348
|
+
const unsub = this.#apiClient.subscribe((data) => {
|
|
349
|
+
if (data.type === 'perspective-removed') {
|
|
350
|
+
this.#perspectiveRemovedCallbacks.forEach(cb => cb(data.uuid as string))
|
|
526
351
|
}
|
|
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
352
|
})
|
|
353
|
+
this.#unsubscribers.push(unsub)
|
|
538
354
|
}
|
|
539
355
|
|
|
540
356
|
async addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
|
|
541
|
-
this.#
|
|
542
|
-
|
|
543
|
-
|
|
357
|
+
const unsub = this.#apiClient.subscribe(
|
|
358
|
+
(data) => {
|
|
359
|
+
if (data.type === 'link-added' && data.perspectiveUuid === uuid) {
|
|
360
|
+
cb.forEach(c => c(data.link as LinkExpression))
|
|
361
|
+
}
|
|
544
362
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
},
|
|
551
|
-
error: (e) => console.error(e)
|
|
552
|
-
})
|
|
553
|
-
|
|
554
|
-
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
363
|
+
)
|
|
364
|
+
let existing = this.#linkUnsubscribers.get(uuid as string) || []
|
|
365
|
+
existing.push(unsub)
|
|
366
|
+
this.#linkUnsubscribers.set(uuid as string, existing)
|
|
367
|
+
await this.#apiClient.waitForSubscription()
|
|
555
368
|
}
|
|
556
369
|
|
|
557
370
|
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
|
|
371
|
+
const unsub = this.#apiClient.subscribe(
|
|
372
|
+
(data) => {
|
|
373
|
+
if (data.type === 'link-removed' && data.perspectiveUuid === uuid) {
|
|
374
|
+
const link = data.link as LinkExpression & { status?: unknown }
|
|
375
|
+
if (!link.status) {
|
|
376
|
+
delete link.status
|
|
567
377
|
}
|
|
568
|
-
c(
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
378
|
+
cb.forEach(c => c(link))
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
)
|
|
382
|
+
let existing = this.#linkUnsubscribers.get(uuid as string) || []
|
|
383
|
+
existing.push(unsub)
|
|
384
|
+
this.#linkUnsubscribers.set(uuid as string, existing)
|
|
385
|
+
await this.#apiClient.waitForSubscription()
|
|
575
386
|
}
|
|
576
387
|
|
|
577
388
|
async addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
|
|
578
|
-
this.#
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
389
|
+
const unsub = this.#apiClient.subscribe(
|
|
390
|
+
(data) => {
|
|
391
|
+
if (data.type === 'link-updated' && data.perspectiveUuid === uuid) {
|
|
392
|
+
const newLink = data.newLink as LinkExpression & { status?: unknown }
|
|
393
|
+
const oldLink = data.oldLink as LinkExpression & { status?: unknown }
|
|
394
|
+
if (!newLink.status) {
|
|
395
|
+
delete newLink.status
|
|
583
396
|
}
|
|
584
|
-
|
|
585
|
-
|
|
397
|
+
if (!oldLink.status) {
|
|
398
|
+
delete oldLink.status
|
|
586
399
|
}
|
|
400
|
+
cb.forEach(c => c(data as unknown as LinkExpression))
|
|
587
401
|
}
|
|
588
402
|
}
|
|
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))
|
|
403
|
+
)
|
|
404
|
+
let existing = this.#linkUnsubscribers.get(uuid as string) || []
|
|
405
|
+
existing.push(unsub)
|
|
406
|
+
this.#linkUnsubscribers.set(uuid as string, existing)
|
|
407
|
+
await this.#apiClient.waitForSubscription()
|
|
605
408
|
}
|
|
606
409
|
|
|
607
410
|
getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy {
|
|
608
|
-
return new NeighbourhoodProxy(this.#neighbourhoodClient
|
|
411
|
+
return new NeighbourhoodProxy(this.#neighbourhoodClient!, uuid)
|
|
609
412
|
}
|
|
610
413
|
|
|
611
414
|
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
|
|
415
|
+
return this.#apiClient.call<string>('perspective.createBatch', { uuid })
|
|
619
416
|
}
|
|
620
417
|
|
|
621
418
|
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
|
|
419
|
+
return this.#apiClient.call<LinkExpressionMutations>(
|
|
420
|
+
'perspective.commitBatch', { uuid, batchId }
|
|
421
|
+
)
|
|
636
422
|
}
|
|
637
|
-
}
|
|
423
|
+
}
|