@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,211 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscription Pool — deduplicates identical SPARQL subscriptions.
|
|
3
|
-
*
|
|
4
|
-
* When multiple UI components subscribe to the same SPARQL query on the same
|
|
5
|
-
* perspective, the pool shares a single `subscribeQuery()` call and distributes
|
|
6
|
-
* results to all registered callbacks. Hydration happens once per result set,
|
|
7
|
-
* then is shared across all subscribers.
|
|
8
|
-
*
|
|
9
|
-
* Key: `perspectiveUUID + sparqlQuery`
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { PerspectiveProxy } from "../perspectives/PerspectiveProxy";
|
|
13
|
-
|
|
14
|
-
type HydrateCallback = (rawResult: any) => Promise<any>;
|
|
15
|
-
type ResultCallback = (hydratedResult: any) => void;
|
|
16
|
-
|
|
17
|
-
interface PoolEntry {
|
|
18
|
-
/** The underlying subscription from perspective.subscribeQuery() */
|
|
19
|
-
subscription: any;
|
|
20
|
-
/** All registered callbacks */
|
|
21
|
-
callbacks: Set<{ onResult: ResultCallback; hydrate: HydrateCallback }>;
|
|
22
|
-
/** Latest raw result (for new subscribers joining late) */
|
|
23
|
-
latestRaw: any;
|
|
24
|
-
/** Latest hydrated result */
|
|
25
|
-
latestHydrated: any;
|
|
26
|
-
/** Whether hydration is in flight */
|
|
27
|
-
hydrating: boolean;
|
|
28
|
-
/** Reference count for disposal */
|
|
29
|
-
refCount: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const pool = new Map<string, PoolEntry>();
|
|
33
|
-
|
|
34
|
-
function makeKey(perspectiveUUID: string, sparqlQuery: string): string {
|
|
35
|
-
return `${perspectiveUUID}::${sparqlQuery}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface PooledSubscription {
|
|
39
|
-
/** The initial (hydrated) result */
|
|
40
|
-
initialResult: any;
|
|
41
|
-
/** Unsubscribe this particular callback from the pool */
|
|
42
|
-
dispose: () => void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Subscribe to a SPARQL query, sharing the underlying subscription
|
|
47
|
-
* with any other subscribers using the same perspective + query.
|
|
48
|
-
*
|
|
49
|
-
* @param perspective - The perspective proxy
|
|
50
|
-
* @param sparqlQuery - The SPARQL query text
|
|
51
|
-
* @param hydrate - Async function that takes raw SPARQL results and returns hydrated results
|
|
52
|
-
* @param onResult - Callback for subsequent result updates (hydrated)
|
|
53
|
-
* @returns PooledSubscription with initial result and dispose function
|
|
54
|
-
*/
|
|
55
|
-
export async function pooledSubscribe(
|
|
56
|
-
perspective: PerspectiveProxy,
|
|
57
|
-
sparqlQuery: string,
|
|
58
|
-
hydrate: HydrateCallback,
|
|
59
|
-
onResult: ResultCallback,
|
|
60
|
-
): Promise<PooledSubscription> {
|
|
61
|
-
const uuid = (perspective as any).uuid || (perspective as any).handle?.uuid || '';
|
|
62
|
-
const key = makeKey(uuid, sparqlQuery);
|
|
63
|
-
|
|
64
|
-
const entry = pool.get(key);
|
|
65
|
-
const subscriber = { onResult, hydrate };
|
|
66
|
-
|
|
67
|
-
if (entry) {
|
|
68
|
-
// Join existing subscription
|
|
69
|
-
entry.callbacks.add(subscriber);
|
|
70
|
-
entry.refCount++;
|
|
71
|
-
|
|
72
|
-
// Hydrate latest result for this new subscriber
|
|
73
|
-
let initialResult: any;
|
|
74
|
-
if (entry.latestHydrated !== undefined) {
|
|
75
|
-
initialResult = entry.latestHydrated;
|
|
76
|
-
} else if (entry.latestRaw !== undefined) {
|
|
77
|
-
initialResult = await hydrate(entry.latestRaw);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
initialResult,
|
|
82
|
-
dispose: () => disposeSubscriber(key, subscriber),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Create new subscription
|
|
87
|
-
const subscription = await perspective.subscribeQuery(sparqlQuery);
|
|
88
|
-
|
|
89
|
-
const newEntry: PoolEntry = {
|
|
90
|
-
subscription,
|
|
91
|
-
callbacks: new Set([subscriber]),
|
|
92
|
-
latestRaw: subscription.result,
|
|
93
|
-
latestHydrated: undefined,
|
|
94
|
-
hydrating: false,
|
|
95
|
-
refCount: 1,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
pool.set(key, newEntry);
|
|
99
|
-
|
|
100
|
-
// Set up shared result handler with delta optimization
|
|
101
|
-
subscription.onResult(async (rawResult: any) => {
|
|
102
|
-
const prevRaw = newEntry.latestRaw;
|
|
103
|
-
newEntry.latestRaw = rawResult;
|
|
104
|
-
newEntry.hydrating = true;
|
|
105
|
-
try {
|
|
106
|
-
const firstSub = newEntry.callbacks.values().next().value;
|
|
107
|
-
if (firstSub) {
|
|
108
|
-
// Delta optimization: if the new result is strictly an addition
|
|
109
|
-
// (all previous rows still present + new rows), only hydrate the
|
|
110
|
-
// new rows and append them to the cached hydrated result.
|
|
111
|
-
const prevArr = Array.isArray(prevRaw) ? prevRaw : [];
|
|
112
|
-
const newArr = Array.isArray(rawResult) ? rawResult : [];
|
|
113
|
-
const prevHydrated = newEntry.latestHydrated;
|
|
114
|
-
|
|
115
|
-
if (
|
|
116
|
-
prevHydrated &&
|
|
117
|
-
Array.isArray(prevHydrated) &&
|
|
118
|
-
newArr.length > prevArr.length &&
|
|
119
|
-
newArr.length - prevArr.length <= 5 // small delta — worth optimizing
|
|
120
|
-
) {
|
|
121
|
-
// Build a set of source URIs from previous results for quick lookup
|
|
122
|
-
const prevSources = new Set(prevArr.map((r: any) => `${r.source}|${r.predicate}|${r.target}`));
|
|
123
|
-
const addedRows = newArr.filter((r: any) => !prevSources.has(`${r.source}|${r.predicate}|${r.target}`));
|
|
124
|
-
|
|
125
|
-
// Check that no rows were removed (pure addition)
|
|
126
|
-
const newSources = new Set(newArr.map((r: any) => `${r.source}|${r.predicate}|${r.target}`));
|
|
127
|
-
const removedRows = prevArr.filter((r: any) => !newSources.has(`${r.source}|${r.predicate}|${r.target}`));
|
|
128
|
-
|
|
129
|
-
if (removedRows.length === 0 && addedRows.length > 0) {
|
|
130
|
-
// Verify ALL added rows have sources not in previous results.
|
|
131
|
-
// If any added row's source matches an existing source, it means
|
|
132
|
-
// an existing instance got new links — we need full rehydration.
|
|
133
|
-
const prevSourceIds = new Set(prevArr.map((r: any) => r.source));
|
|
134
|
-
const allNewSources = addedRows.every((r: any) => !prevSourceIds.has(r.source));
|
|
135
|
-
|
|
136
|
-
if (allNewSources) {
|
|
137
|
-
// Pure addition of new instances — hydrate only the new rows
|
|
138
|
-
try {
|
|
139
|
-
const deltaHydrated = await firstSub.hydrate(addedRows);
|
|
140
|
-
if (Array.isArray(deltaHydrated)) {
|
|
141
|
-
const merged = [...prevHydrated, ...deltaHydrated];
|
|
142
|
-
newEntry.latestHydrated = merged;
|
|
143
|
-
for (const cb of newEntry.callbacks) {
|
|
144
|
-
try { cb.onResult(merged); } catch (e) { /* subscriber error */ }
|
|
145
|
-
}
|
|
146
|
-
return; // Delta path succeeded
|
|
147
|
-
}
|
|
148
|
-
} catch {
|
|
149
|
-
// Delta hydration failed — fall through to full hydration
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Full hydration fallback
|
|
156
|
-
const hydrated = await firstSub.hydrate(rawResult);
|
|
157
|
-
newEntry.latestHydrated = hydrated;
|
|
158
|
-
// Distribute to all callbacks
|
|
159
|
-
for (const cb of newEntry.callbacks) {
|
|
160
|
-
try { cb.onResult(hydrated); } catch (e) { /* subscriber error */ }
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
} finally {
|
|
164
|
-
newEntry.hydrating = false;
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// Hydrate initial result
|
|
169
|
-
const initialResult = await hydrate(subscription.result);
|
|
170
|
-
newEntry.latestHydrated = initialResult;
|
|
171
|
-
|
|
172
|
-
return {
|
|
173
|
-
initialResult,
|
|
174
|
-
dispose: () => disposeSubscriber(key, subscriber),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function disposeSubscriber(key: string, subscriber: { onResult: ResultCallback; hydrate: HydrateCallback }): void {
|
|
179
|
-
const entry = pool.get(key);
|
|
180
|
-
if (!entry) return;
|
|
181
|
-
|
|
182
|
-
entry.callbacks.delete(subscriber);
|
|
183
|
-
entry.refCount--;
|
|
184
|
-
|
|
185
|
-
if (entry.refCount <= 0) {
|
|
186
|
-
// Last subscriber — tear down the underlying subscription
|
|
187
|
-
if (entry.subscription?.dispose) {
|
|
188
|
-
entry.subscription.dispose();
|
|
189
|
-
}
|
|
190
|
-
pool.delete(key);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Clear the entire pool (for testing).
|
|
196
|
-
*/
|
|
197
|
-
export function clearSubscriptionPool(): void {
|
|
198
|
-
for (const entry of pool.values()) {
|
|
199
|
-
if (entry.subscription?.dispose) {
|
|
200
|
-
entry.subscription.dispose();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
pool.clear();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Get the current pool size (for testing).
|
|
208
|
-
*/
|
|
209
|
-
export function subscriptionPoolSize(): number {
|
|
210
|
-
return pool.size;
|
|
211
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { Arg, Mutation, Query, Resolver, Subscription, PubSub } from "type-graphql";
|
|
2
|
-
import { PerspectiveHandle, PerspectiveState } from "../perspectives/PerspectiveHandle";
|
|
3
|
-
import { Perspective, PerspectiveExpression, PerspectiveInput, PerspectiveUnsignedInput } from "../perspectives/Perspective";
|
|
4
|
-
import { DID } from "../DID";
|
|
5
|
-
import { TEST_AGENT_DID } from "../agent/AgentResolver";
|
|
6
|
-
import { OnlineAgent } from "../language/Language";
|
|
7
|
-
import { testLink } from "../perspectives/PerspectiveResolver";
|
|
8
|
-
import { NEIGHBOURHOOD_SIGNAL_RECEIVED_TOPIC, PERSPECTIVE_UPDATED_TOPIC } from "../PubSub";
|
|
9
|
-
|
|
10
|
-
const testPerspectiveExpression = new PerspectiveExpression()
|
|
11
|
-
testPerspectiveExpression.author = TEST_AGENT_DID
|
|
12
|
-
testPerspectiveExpression.timestamp = new Date().toISOString()
|
|
13
|
-
testPerspectiveExpression.data = new Perspective([testLink])
|
|
14
|
-
testPerspectiveExpression.proof = {
|
|
15
|
-
signature: '',
|
|
16
|
-
key: '',
|
|
17
|
-
valid: true
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Resolver classes are used here to define the GraphQL schema
|
|
22
|
-
* (through the type-graphql annotations)
|
|
23
|
-
* and are spawned in the client tests in Ad4mClient.test.ts.
|
|
24
|
-
* For the latter, they return test fixtures.
|
|
25
|
-
*/
|
|
26
|
-
@Resolver()
|
|
27
|
-
export default class NeighbourhoodResolver {
|
|
28
|
-
@Mutation(returns => String)
|
|
29
|
-
neighbourhoodPublishFromPerspective(
|
|
30
|
-
@Arg('perspectiveUUID') perspectiveUUID: string,
|
|
31
|
-
@Arg('linkLanguage') linkLanguage: string,
|
|
32
|
-
@Arg('meta') meta: PerspectiveInput
|
|
33
|
-
): string {
|
|
34
|
-
return "neighbourhood://neighbourhoodAddress"
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@Mutation(returns => PerspectiveHandle)
|
|
38
|
-
neighbourhoodJoinFromUrl(@Arg('url') url: string, @PubSub() pubSub: any): PerspectiveHandle {
|
|
39
|
-
const perspective = new PerspectiveHandle
|
|
40
|
-
perspective.name = "test-perspective"
|
|
41
|
-
perspective.sharedUrl = url
|
|
42
|
-
perspective.uuid = "234234234"
|
|
43
|
-
perspective.state = PerspectiveState.Synced
|
|
44
|
-
pubSub.publish(PERSPECTIVE_UPDATED_TOPIC, { perspective});
|
|
45
|
-
return perspective
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Query(returns => [String])
|
|
49
|
-
neighbourhoodOtherAgents(@Arg('perspectiveUUID') perspectiveUUID: string): DID[] {
|
|
50
|
-
return ['did:test:other']
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@Query()
|
|
54
|
-
neighbourhoodHasTelepresenceAdapter(@Arg('perspectiveUUID') perspectiveUUID: string): boolean {
|
|
55
|
-
return true
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@Query(returns => [OnlineAgent])
|
|
59
|
-
neighbourhoodOnlineAgents(@Arg('perspectiveUUID') perspectiveUUID: string): OnlineAgent[] {
|
|
60
|
-
const onlineAgent = new OnlineAgent()
|
|
61
|
-
onlineAgent.did = 'did:test:online'
|
|
62
|
-
onlineAgent.status = testPerspectiveExpression
|
|
63
|
-
return [onlineAgent]
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@Mutation()
|
|
67
|
-
neighbourhoodSetOnlineStatus(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('status') status: PerspectiveInput): boolean {
|
|
68
|
-
return true
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@Mutation()
|
|
72
|
-
neighbourhoodSetOnlineStatusU(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('status') status: PerspectiveUnsignedInput): boolean {
|
|
73
|
-
return true
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@Mutation()
|
|
77
|
-
neighbourhoodSendSignal(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('remoteAgentDid') recipient: DID, @Arg('payload') signal: PerspectiveInput): boolean {
|
|
78
|
-
return true
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@Mutation()
|
|
82
|
-
neighbourhoodSendSignalU(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('remoteAgentDid') recipient: DID, @Arg('payload') signal: PerspectiveUnsignedInput): boolean {
|
|
83
|
-
return true
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
@Mutation()
|
|
87
|
-
neighbourhoodSendBroadcast(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('payload') signal: PerspectiveInput, @Arg('loopback', { nullable: true }) loopback?: boolean): boolean {
|
|
88
|
-
return true
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
@Mutation()
|
|
92
|
-
neighbourhoodSendBroadcastU(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('payload') signal: PerspectiveUnsignedInput, @Arg('loopback', { nullable: true }) loopback?: boolean): boolean {
|
|
93
|
-
return true
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@Subscription({topics: NEIGHBOURHOOD_SIGNAL_RECEIVED_TOPIC, nullable: true})
|
|
97
|
-
neighbourhoodSignal(@Arg('perspectiveUUID') pID: string): PerspectiveExpression {
|
|
98
|
-
return testPerspectiveExpression
|
|
99
|
-
}
|
|
100
|
-
}
|
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
import { Arg, Mutation, PubSub, Query, Resolver, Root, Subscription, ObjectType, Field } from "type-graphql";
|
|
2
|
-
import { LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations } from "../links/Links";
|
|
3
|
-
import { Neighbourhood, NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
|
|
4
|
-
import { LinkQuery } from "./LinkQuery";
|
|
5
|
-
import { Perspective } from "./Perspective";
|
|
6
|
-
import { LinkStatus } from "./PerspectiveProxy";
|
|
7
|
-
import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
|
|
8
|
-
import { LINK_ADDED_TOPIC, LINK_REMOVED_TOPIC, LINK_UDATED_TOPIC, PERSPECTIVE_ADDED_TOPIC, PERSPECTIVE_REMOVED_TOPIC, PERSPECTIVE_UPDATED_TOPIC, PERSPECTIVE_SYNC_STATE_CHANGE } from '../PubSub'
|
|
9
|
-
|
|
10
|
-
export const testLink = new LinkExpression()
|
|
11
|
-
testLink.author = "did:ad4m:test"
|
|
12
|
-
testLink.timestamp = Date.now()
|
|
13
|
-
testLink.data = {
|
|
14
|
-
source: 'root',
|
|
15
|
-
target: 'neighbourhood://Qm12345'
|
|
16
|
-
}
|
|
17
|
-
testLink.proof = {
|
|
18
|
-
signature: '',
|
|
19
|
-
key: '',
|
|
20
|
-
valid: true
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const PERSPECTIVE_QUERY_SUBSCRIPTION = "PERSPECTIVE_QUERY_SUBSCRIPTION"
|
|
24
|
-
|
|
25
|
-
@ObjectType()
|
|
26
|
-
export class QuerySubscription {
|
|
27
|
-
@Field()
|
|
28
|
-
subscriptionId: string;
|
|
29
|
-
|
|
30
|
-
@Field()
|
|
31
|
-
result: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Resolver classes are used here to define the GraphQL schema
|
|
36
|
-
* (through the type-graphql annotations)
|
|
37
|
-
* and are spawned in the client tests in Ad4mClient.test.ts.
|
|
38
|
-
* For the latter, they return test fixtures.
|
|
39
|
-
*/
|
|
40
|
-
@Resolver()
|
|
41
|
-
export default class PerspectiveResolver {
|
|
42
|
-
@Query(returns => [PerspectiveHandle])
|
|
43
|
-
perspectives(): PerspectiveHandle[] {
|
|
44
|
-
const p1 = new PerspectiveHandle()
|
|
45
|
-
p1.name = 'test-perspective-1'
|
|
46
|
-
p1.uuid = '00001'
|
|
47
|
-
const p2 = new PerspectiveHandle()
|
|
48
|
-
p2.name = 'test-perspective-2'
|
|
49
|
-
p2.uuid = '00002'
|
|
50
|
-
p2.sharedUrl = 'neighbourhood://Qm12345'
|
|
51
|
-
const neighbourhood = new NeighbourhoodExpression();
|
|
52
|
-
neighbourhood.data = new Neighbourhood("language://Qm12345", new Perspective());
|
|
53
|
-
neighbourhood.author = "did:ad4m:test"
|
|
54
|
-
neighbourhood.timestamp = Date.now()
|
|
55
|
-
neighbourhood.proof = {
|
|
56
|
-
signature: '',
|
|
57
|
-
key: '',
|
|
58
|
-
valid: true
|
|
59
|
-
}
|
|
60
|
-
p2.neighbourhood = neighbourhood
|
|
61
|
-
p2.state = PerspectiveState.Synced
|
|
62
|
-
return [p1, p2]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@Query(returns => PerspectiveHandle, {nullable: true})
|
|
66
|
-
perspective(@Arg('uuid') uuid: string): PerspectiveHandle|null {
|
|
67
|
-
return new PerspectiveHandle(uuid, 'test-perspective-1')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@Query(returns => Perspective, {nullable: true})
|
|
71
|
-
perspectiveSnapshot(@Arg('uuid') uuid: string): Perspective|null {
|
|
72
|
-
return new Perspective([testLink])
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@Mutation(returns => String, {nullable: true})
|
|
76
|
-
perspectivePublishSnapshot(@Arg('uuid') uuid: string): String|null {
|
|
77
|
-
return 'perspective://Qm12345'
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
@Query(returns => [LinkExpression], {nullable: true})
|
|
81
|
-
perspectiveQueryLinks(@Arg('uuid') uuid: string, @Arg('query') query: LinkQuery): LinkExpression[] {
|
|
82
|
-
return [testLink]
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
@Query(returns => String)
|
|
86
|
-
async perspectiveQueryProlog(
|
|
87
|
-
@Arg('uuid') uuid: string,
|
|
88
|
-
@Arg('query') query: string
|
|
89
|
-
): Promise<string> {
|
|
90
|
-
return `[{"X": 1}]`
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
@Mutation(returns => QuerySubscription)
|
|
94
|
-
async perspectiveSubscribeQuery(
|
|
95
|
-
@Arg('uuid') uuid: string,
|
|
96
|
-
@Arg('query') query: string
|
|
97
|
-
): Promise<QuerySubscription> {
|
|
98
|
-
const result = `[{"X": 1}]`
|
|
99
|
-
return {
|
|
100
|
-
subscriptionId: "test-subscription-id",
|
|
101
|
-
result: result
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
@Mutation(returns => PerspectiveHandle)
|
|
106
|
-
perspectiveAdd(@Arg('name') name: string, @PubSub() pubSub: any): PerspectiveHandle {
|
|
107
|
-
const perspective = new PerspectiveHandle('00006', name);
|
|
108
|
-
pubSub.publish(PERSPECTIVE_ADDED_TOPIC, { perspective })
|
|
109
|
-
return new PerspectiveHandle('00006', name)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@Mutation(returns => PerspectiveHandle, {nullable: true})
|
|
113
|
-
perspectiveUpdate(@Arg('uuid') uuid: string, @Arg('name') name: string, @PubSub() pubSub: any): PerspectiveHandle {
|
|
114
|
-
const perspective = new PerspectiveHandle(uuid, name);
|
|
115
|
-
pubSub.publish(PERSPECTIVE_UPDATED_TOPIC, { perspective })
|
|
116
|
-
return new PerspectiveHandle(uuid, name)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
@Mutation(returns => Boolean)
|
|
120
|
-
perspectiveRemove(@Arg('uuid') uuid: string, @PubSub() pubSub: any): boolean {
|
|
121
|
-
const perspective = new PerspectiveHandle(uuid);
|
|
122
|
-
pubSub.publish(PERSPECTIVE_REMOVED_TOPIC, { perspective })
|
|
123
|
-
return true
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
@Mutation(returns => String)
|
|
127
|
-
async perspectiveCreateBatch(@Arg('uuid') uuid: string): Promise<string> {
|
|
128
|
-
const perspective = new PerspectiveHandle(uuid)
|
|
129
|
-
return uuid + '-batch-' + Date.now()
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
@Mutation(returns => LinkExpressionMutations)
|
|
133
|
-
async perspectiveCommitBatch(
|
|
134
|
-
@Arg('uuid') uuid: string,
|
|
135
|
-
@Arg('batchId') batchId: string
|
|
136
|
-
): Promise<LinkExpressionMutations> {
|
|
137
|
-
return new LinkExpressionMutations([], [])
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
@Mutation(returns => LinkExpression)
|
|
141
|
-
perspectiveAddLink(
|
|
142
|
-
@Arg('uuid') uuid: string,
|
|
143
|
-
@Arg('link') link: LinkInput,
|
|
144
|
-
@Arg('status', { nullable: true, defaultValue: 'shared' }) status: LinkStatus,
|
|
145
|
-
@Arg('batchId', { nullable: true }) batchId: string,
|
|
146
|
-
@PubSub() pubSub: any
|
|
147
|
-
): LinkExpression {
|
|
148
|
-
const l = new LinkExpression()
|
|
149
|
-
l.author = 'did:ad4m:test'
|
|
150
|
-
l.timestamp = Date.now()
|
|
151
|
-
l.proof = testLink.proof
|
|
152
|
-
l.data = link
|
|
153
|
-
l.status = status
|
|
154
|
-
|
|
155
|
-
pubSub.publish(LINK_ADDED_TOPIC, { link: l })
|
|
156
|
-
pubSub.publish(PERSPECTIVE_SYNC_STATE_CHANGE, PerspectiveState.LinkLanguageInstalledButNotSynced)
|
|
157
|
-
return l
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
@Mutation(returns => [LinkExpression])
|
|
161
|
-
perspectiveAddLinks(
|
|
162
|
-
@Arg('uuid') uuid: string,
|
|
163
|
-
@Arg('links', type => [LinkInput]) links: LinkInput[],
|
|
164
|
-
@Arg('status', { nullable: true, defaultValue: 'shared' }) status: LinkStatus,
|
|
165
|
-
@Arg('batchId', { nullable: true }) batchId: string,
|
|
166
|
-
@PubSub() pubSub: any
|
|
167
|
-
): LinkExpression[] {
|
|
168
|
-
const l = new LinkExpression()
|
|
169
|
-
l.author = 'did:ad4m:test'
|
|
170
|
-
l.timestamp = Date.now()
|
|
171
|
-
l.proof = testLink.proof
|
|
172
|
-
l.data = links[0]
|
|
173
|
-
l.status = status
|
|
174
|
-
|
|
175
|
-
const l2 = new LinkExpression()
|
|
176
|
-
l2.author = 'did:ad4m:test'
|
|
177
|
-
l2.timestamp = Date.now()
|
|
178
|
-
l2.proof = testLink.proof
|
|
179
|
-
l2.data = links[0]
|
|
180
|
-
l2.status = status
|
|
181
|
-
|
|
182
|
-
pubSub.publish(LINK_ADDED_TOPIC, { link: l })
|
|
183
|
-
pubSub.publish(LINK_ADDED_TOPIC, { link: l2 })
|
|
184
|
-
return [l, l2]
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
@Mutation(returns => Boolean)
|
|
188
|
-
perspectiveRemoveLink(
|
|
189
|
-
@Arg('uuid') uuid: string,
|
|
190
|
-
@Arg('link') link: LinkExpressionInput,
|
|
191
|
-
@Arg('batchId', { nullable: true }) batchId: string,
|
|
192
|
-
@PubSub() pubSub: any
|
|
193
|
-
): Boolean {
|
|
194
|
-
const l = new LinkExpression()
|
|
195
|
-
l.author = 'did:ad4m:test'
|
|
196
|
-
l.timestamp = Date.now()
|
|
197
|
-
l.proof = testLink.proof
|
|
198
|
-
l.data = link.data
|
|
199
|
-
pubSub.publish(LINK_REMOVED_TOPIC, { link: l })
|
|
200
|
-
return true
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
@Mutation(returns => [LinkExpression])
|
|
204
|
-
perspectiveRemoveLinks(
|
|
205
|
-
@Arg('uuid') uuid: string,
|
|
206
|
-
@Arg('links', type => [LinkExpressionInput]) links: LinkExpressionInput[],
|
|
207
|
-
@Arg('batchId', { nullable: true }) batchId: string,
|
|
208
|
-
@PubSub() pubSub: any
|
|
209
|
-
): LinkExpression[] {
|
|
210
|
-
const l = new LinkExpression()
|
|
211
|
-
l.author = 'did:ad4m:test'
|
|
212
|
-
l.timestamp = Date.now()
|
|
213
|
-
l.proof = testLink.proof
|
|
214
|
-
l.data = links[0].data
|
|
215
|
-
|
|
216
|
-
const l2 = new LinkExpression()
|
|
217
|
-
l2.author = 'did:ad4m:test'
|
|
218
|
-
l2.timestamp = Date.now()
|
|
219
|
-
l2.proof = testLink.proof
|
|
220
|
-
l2.data = links[0].data
|
|
221
|
-
|
|
222
|
-
pubSub.publish(LINK_REMOVED_TOPIC, { link: l })
|
|
223
|
-
pubSub.publish(LINK_ADDED_TOPIC, { link: l2 })
|
|
224
|
-
return [l, l2]
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
@Mutation(returns => LinkExpressionMutations)
|
|
228
|
-
perspectiveLinkMutations(@Arg('uuid') uuid: string, @Arg('mutations') mutations: LinkMutations, @Arg('status', { nullable: true}) status: LinkStatus, @PubSub() pubSub: any): LinkExpressionMutations {
|
|
229
|
-
const perspectiveAddLinks = this.perspectiveAddLinks(uuid, mutations.additions, status, null, pubSub);
|
|
230
|
-
const perspectiveRemoveLinks = this.perspectiveRemoveLinks(uuid, mutations.removals, null, pubSub);
|
|
231
|
-
return new LinkExpressionMutations(perspectiveAddLinks, perspectiveRemoveLinks)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
@Mutation(returns => LinkExpression)
|
|
235
|
-
perspectiveUpdateLink(
|
|
236
|
-
@Arg('uuid') uuid: string,
|
|
237
|
-
@Arg('oldLink') oldLink: LinkExpressionInput,
|
|
238
|
-
@Arg('newLink') newLink: LinkInput,
|
|
239
|
-
@Arg('batchId', { nullable: true }) batchId: string,
|
|
240
|
-
@PubSub() pubSub: any
|
|
241
|
-
): LinkExpression {
|
|
242
|
-
const l = new LinkExpression()
|
|
243
|
-
l.author = 'did:ad4m:test'
|
|
244
|
-
l.timestamp = Date.now()
|
|
245
|
-
l.proof = testLink.proof
|
|
246
|
-
l.data = newLink
|
|
247
|
-
|
|
248
|
-
pubSub.publish(LINK_REMOVED_TOPIC, { link: l })
|
|
249
|
-
return l
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
@Mutation(returns => LinkExpression)
|
|
253
|
-
perspectiveAddLinkExpression(
|
|
254
|
-
@Arg('uuid') uuid: string,
|
|
255
|
-
@Arg('link') link: LinkExpressionInput,
|
|
256
|
-
@Arg('status', { nullable: true, defaultValue: 'shared' }) status: LinkStatus,
|
|
257
|
-
@Arg('batchId', { nullable: true }) batchId: string,
|
|
258
|
-
@PubSub() pubSub: any
|
|
259
|
-
): LinkExpression {
|
|
260
|
-
pubSub.publish(LINK_ADDED_TOPIC, { link })
|
|
261
|
-
link.status = status;
|
|
262
|
-
return link as LinkExpression
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
@Mutation(returns => Boolean)
|
|
266
|
-
perspectiveAddSdna(@Arg('uuid') uuid: string, @Arg('name') name: string, @Arg('sdnaCode', { nullable: true }) sdnaCode: string, @Arg('sdnaType') sdnaType: string, @Arg('shaclJson', { nullable: true }) shaclJson: string, @PubSub() pubSub: any): Boolean {
|
|
267
|
-
return true
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
@Mutation(returns => Boolean)
|
|
271
|
-
perspectiveExecuteCommands(
|
|
272
|
-
@Arg('uuid') uuid: string,
|
|
273
|
-
@Arg('commands') commands: string,
|
|
274
|
-
@Arg('expression') expression: string,
|
|
275
|
-
@Arg('parameters', type => String, {nullable: true}) parameters: string,
|
|
276
|
-
@Arg('batchId', { nullable: true }) batchId?: string,
|
|
277
|
-
): Boolean {
|
|
278
|
-
return true
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
@Mutation(returns => Boolean)
|
|
282
|
-
perspectiveCreateSubject(
|
|
283
|
-
@Arg('uuid') uuid: string,
|
|
284
|
-
@Arg('subjectClass') SubjectClass: string,
|
|
285
|
-
@Arg('expressionAddress') expressionAddress: string,
|
|
286
|
-
@Arg('initialValues', { nullable: true }) initialValues?: string,
|
|
287
|
-
@Arg('batchId', { nullable: true }) batchId?: string,
|
|
288
|
-
): Boolean {
|
|
289
|
-
return true
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
@Mutation(returns => String)
|
|
293
|
-
perspectiveGetSubjectData(
|
|
294
|
-
@Arg('uuid') uuid: string,
|
|
295
|
-
@Arg('subjectClass') SubjectClass: string,
|
|
296
|
-
@Arg('expressionAddress') expressionAddress: string
|
|
297
|
-
): String {
|
|
298
|
-
return ""
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
@Subscription({topics: PERSPECTIVE_ADDED_TOPIC, nullable: true})
|
|
302
|
-
perspectiveAdded(): PerspectiveHandle {
|
|
303
|
-
const perspective = new PerspectiveHandle('00001', 'New Perspective');
|
|
304
|
-
return perspective
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
@Subscription({topics: PERSPECTIVE_UPDATED_TOPIC, nullable: true})
|
|
308
|
-
perspectiveUpdated(): PerspectiveHandle {
|
|
309
|
-
return new PerspectiveHandle('00001', 'New Perspective')
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
@Subscription({topics: PERSPECTIVE_REMOVED_TOPIC, nullable: true})
|
|
313
|
-
perspectiveRemoved(): string {
|
|
314
|
-
return '00006'
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
@Subscription({topics: LINK_ADDED_TOPIC, nullable: true})
|
|
318
|
-
perspectiveLinkAdded(@Arg('uuid') uuid: string): LinkExpression {
|
|
319
|
-
return testLink
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
@Subscription({topics: LINK_REMOVED_TOPIC, nullable: true})
|
|
323
|
-
perspectiveLinkRemoved(@Arg('uuid') uuid: string): LinkExpression {
|
|
324
|
-
return testLink
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
@Subscription({topics: LINK_UDATED_TOPIC, nullable: true})
|
|
328
|
-
perspectiveLinkUpdated(@Arg('uuid') uuid: string): LinkExpressionUpdated {
|
|
329
|
-
return {oldLink: testLink, newLink: testLink}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
@Subscription({topics: PERSPECTIVE_SYNC_STATE_CHANGE, nullable: false})
|
|
333
|
-
perspectiveSyncStateChange(@Arg('uuid') uuid: string): PerspectiveState {
|
|
334
|
-
return PerspectiveState.Synced
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
@Mutation(returns => Boolean)
|
|
338
|
-
perspectiveKeepAliveQuery(
|
|
339
|
-
@Arg('uuid') uuid: string,
|
|
340
|
-
@Arg('subscriptionId') subscriptionId: string
|
|
341
|
-
): boolean {
|
|
342
|
-
return true
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
@Subscription({
|
|
346
|
-
topics: PERSPECTIVE_QUERY_SUBSCRIPTION,
|
|
347
|
-
filter: ({ payload, args }) =>
|
|
348
|
-
payload.subscriptionId === args.subscriptionId
|
|
349
|
-
})
|
|
350
|
-
perspectiveQuerySubscription(
|
|
351
|
-
@Arg('subscriptionId') subscriptionId: string,
|
|
352
|
-
@Root() payload: { subscriptionId: string, uuid: string, result: string }
|
|
353
|
-
): string {
|
|
354
|
-
return payload.result
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
@Mutation(returns => Boolean)
|
|
358
|
-
async perspectiveDisposeQuerySubscription(
|
|
359
|
-
@Arg('uuid') uuid: string,
|
|
360
|
-
@Arg('subscriptionId') subscriptionId: string
|
|
361
|
-
): Promise<boolean> {
|
|
362
|
-
return true
|
|
363
|
-
}
|
|
364
|
-
}
|