@coasys/ad4m 0.8.0-fix → 0.8.1
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 +229 -229
- package/jest.config.js +5 -5
- package/jsdoc.json +27 -27
- package/lib/index.cjs +4522 -4571
- package/lib/index.js +4522 -4571
- package/lib/shims/type-graphql.d.ts +32 -32
- package/lib/shims/type-graphql.js +70 -70
- package/lib/src/Ad4mClient.d.ts +26 -26
- package/lib/src/Ad4mClient.js +66 -66
- package/lib/src/Address.d.ts +1 -1
- package/lib/src/Address.js +1 -1
- package/lib/src/DID.d.ts +1 -1
- package/lib/src/DID.js +1 -1
- package/lib/src/Exception.d.ts +6 -6
- package/lib/src/Exception.js +7 -7
- package/lib/src/Literal.d.ts +7 -7
- package/lib/src/Literal.js +76 -76
- package/lib/src/PubSub.d.ts +14 -14
- package/lib/src/PubSub.js +14 -14
- package/lib/src/SmartLiteral.d.ts +12 -12
- package/lib/src/SmartLiteral.js +74 -74
- package/lib/src/agent/Agent.d.ts +104 -104
- package/lib/src/agent/Agent.js +337 -337
- package/lib/src/agent/AgentClient.d.ts +57 -57
- package/lib/src/agent/AgentClient.js +431 -431
- package/lib/src/agent/AgentResolver.d.ts +30 -30
- package/lib/src/agent/AgentResolver.js +325 -325
- package/lib/src/agent/AgentStatus.d.ts +8 -8
- package/lib/src/agent/AgentStatus.js +61 -61
- package/lib/src/buildSchema.d.ts +1 -1
- package/lib/src/buildSchema.js +36 -36
- package/lib/src/expression/Expression.d.ts +28 -28
- package/lib/src/expression/Expression.js +143 -143
- package/lib/src/expression/ExpressionClient.d.ts +13 -13
- package/lib/src/expression/ExpressionClient.js +102 -102
- package/lib/src/expression/ExpressionRef.d.ts +9 -9
- package/lib/src/expression/ExpressionRef.js +67 -67
- package/lib/src/expression/ExpressionResolver.d.ts +10 -10
- package/lib/src/expression/ExpressionResolver.js +106 -106
- package/lib/src/index.d.ts +30 -30
- package/lib/src/index.js +30 -30
- package/lib/src/jestSetup.d.ts +1 -1
- package/lib/src/jestSetup.js +1 -1
- package/lib/src/language/Icon.d.ts +4 -4
- package/lib/src/language/Icon.js +24 -24
- package/lib/src/language/Language.d.ts +195 -195
- package/lib/src/language/Language.js +79 -79
- package/lib/src/language/LanguageClient.d.ts +17 -17
- package/lib/src/language/LanguageClient.js +137 -137
- package/lib/src/language/LanguageContext.d.ts +37 -37
- package/lib/src/language/LanguageContext.js +2 -2
- package/lib/src/language/LanguageHandle.d.ts +9 -9
- package/lib/src/language/LanguageHandle.js +41 -41
- package/lib/src/language/LanguageMeta.d.ts +35 -35
- package/lib/src/language/LanguageMeta.js +89 -89
- package/lib/src/language/LanguageRef.d.ts +6 -6
- package/lib/src/language/LanguageRef.js +30 -30
- package/lib/src/language/LanguageResolver.d.ts +19 -19
- package/lib/src/language/LanguageResolver.js +143 -143
- package/lib/src/links/Links.d.ts +39 -39
- package/lib/src/links/Links.js +148 -148
- package/lib/src/links/Links.test.d.ts +1 -1
- package/lib/src/links/Links.test.js +33 -33
- package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -10
- package/lib/src/neighbourhood/Neighbourhood.js +38 -38
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -25
- package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -256
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -19
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -54
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -24
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -180
- package/lib/src/perspectives/LinkQuery.d.ts +11 -11
- package/lib/src/perspectives/LinkQuery.js +80 -80
- package/lib/src/perspectives/Perspective.d.ts +38 -38
- package/lib/src/perspectives/Perspective.js +144 -144
- package/lib/src/perspectives/Perspective.test.d.ts +1 -1
- package/lib/src/perspectives/Perspective.test.js +20 -20
- package/lib/src/perspectives/PerspectiveClient.d.ts +55 -54
- package/lib/src/perspectives/PerspectiveClient.js +418 -410
- package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveDiff.js +33 -33
- package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -16
- package/lib/src/perspectives/PerspectiveHandle.js +59 -59
- package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -178
- package/lib/src/perspectives/PerspectiveProxy.js +501 -540
- package/lib/src/perspectives/PerspectiveResolver.d.ts +38 -37
- package/lib/src/perspectives/PerspectiveResolver.js +376 -362
- package/lib/src/runtime/RuntimeClient.d.ts +33 -33
- package/lib/src/runtime/RuntimeClient.js +263 -263
- package/lib/src/runtime/RuntimeResolver.d.ts +47 -47
- package/lib/src/runtime/RuntimeResolver.js +328 -328
- package/lib/src/schema.gql +1 -0
- package/lib/src/subject/SDNADecorators.d.ts +45 -45
- package/lib/src/subject/SDNADecorators.js +250 -250
- package/lib/src/subject/Subject.d.ts +7 -7
- package/lib/src/subject/Subject.js +160 -160
- package/lib/src/subject/SubjectEntity.d.ts +31 -31
- package/lib/src/subject/SubjectEntity.js +250 -250
- package/lib/src/subject/util.d.ts +12 -12
- package/lib/src/subject/util.js +73 -73
- package/lib/src/typeDefs.d.ts +1 -1
- package/lib/src/typeDefs.js +1 -0
- package/lib/src/unwrapApolloResult.d.ts +2 -2
- package/lib/src/unwrapApolloResult.js +14 -12
- package/lib/src/utils.d.ts +2 -2
- package/lib/src/utils.js +21 -21
- package/package.json +61 -61
- package/rollup.config.js +26 -26
- package/shims/type-graphql.ts +75 -75
- package/src/Ad4mClient.test.ts +1089 -1084
- package/src/Ad4mClient.ts +62 -62
- package/src/Address.ts +1 -1
- package/src/Exception.ts +6 -6
- package/src/Literal.test.ts +30 -30
- package/src/Literal.ts +80 -80
- package/src/PubSub.ts +13 -13
- package/src/SmartLiteral.ts +74 -74
- package/src/agent/Agent.ts +293 -293
- package/src/agent/AgentClient.ts +531 -531
- package/src/agent/AgentResolver.ts +263 -263
- package/src/agent/AgentStatus.ts +43 -43
- package/src/buildSchema.ts +41 -41
- package/src/expression/Expression.ts +99 -99
- package/src/expression/ExpressionClient.ts +98 -98
- package/src/expression/ExpressionRef.ts +62 -62
- package/src/expression/ExpressionResolver.ts +63 -63
- package/src/index.ts +30 -30
- package/src/language/Icon.ts +10 -10
- package/src/language/Language.ts +266 -266
- package/src/language/LanguageClient.ts +159 -159
- package/src/language/LanguageContext.ts +37 -37
- package/src/language/LanguageHandle.ts +23 -23
- package/src/language/LanguageMeta.ts +69 -69
- package/src/language/LanguageRef.ts +18 -18
- package/src/language/LanguageResolver.ts +98 -98
- package/src/links/Links.test.ts +39 -39
- package/src/links/Links.ts +107 -107
- package/src/neighbourhood/Neighbourhood.ts +22 -22
- package/src/neighbourhood/NeighbourhoodClient.ts +275 -275
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -58
- package/src/neighbourhood/NeighbourhoodResolver.ts +99 -99
- package/src/perspectives/LinkQuery.ts +65 -65
- package/src/perspectives/Perspective.test.ts +22 -22
- package/src/perspectives/Perspective.ts +118 -118
- package/src/perspectives/PerspectiveClient.ts +452 -443
- package/src/perspectives/PerspectiveDiff.ts +15 -15
- package/src/perspectives/PerspectiveHandle.ts +39 -39
- package/src/perspectives/PerspectiveProxy.ts +576 -610
- package/src/perspectives/PerspectiveResolver.ts +224 -219
- package/src/runtime/RuntimeClient.ts +282 -282
- package/src/runtime/RuntimeResolver.ts +192 -192
- package/src/subject/SDNADecorators.ts +333 -333
- package/src/subject/Subject.ts +152 -152
- package/src/subject/SubjectEntity.ts +291 -291
- package/src/subject/util.ts +84 -84
- package/src/typeDefs.ts +5 -5
- package/src/unwrapApolloResult.ts +15 -13
- package/src/utils.ts +25 -25
- package/tsconfig-browser.json +82 -82
- package/tsconfig.json +80 -80
- package/yarn-error.log +0 -22814
|
@@ -1,444 +1,453 @@
|
|
|
1
|
-
import { ApolloClient, gql } from "@apollo/client/core";
|
|
2
|
-
import { ExpressionRendered } from "../expression/Expression";
|
|
3
|
-
import { ExpressionClient } from "../expression/ExpressionClient";
|
|
4
|
-
import { Link, LinkExpressionInput, LinkExpression, LinkInput, LinkMutations, LinkExpressionMutations } from "../links/Links";
|
|
5
|
-
import { NeighbourhoodClient } from "../neighbourhood/NeighbourhoodClient";
|
|
6
|
-
import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
|
|
7
|
-
import unwrapApolloResult from "../unwrapApolloResult";
|
|
8
|
-
import { LinkQuery } from "./LinkQuery";
|
|
9
|
-
import { Perspective } from "./Perspective";
|
|
10
|
-
import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
|
|
11
|
-
import { LinkStatus, PerspectiveProxy } from './PerspectiveProxy';
|
|
12
|
-
|
|
13
|
-
const LINK_EXPRESSION_FIELDS = `
|
|
14
|
-
author
|
|
15
|
-
timestamp
|
|
16
|
-
status
|
|
17
|
-
data { source, predicate, target }
|
|
18
|
-
proof { valid, invalid, signature, key }
|
|
19
|
-
`
|
|
20
|
-
|
|
21
|
-
const PERSPECTIVE_HANDLE_FIELDS = `
|
|
22
|
-
uuid
|
|
23
|
-
name
|
|
24
|
-
sharedUrl
|
|
25
|
-
state
|
|
26
|
-
neighbourhood {
|
|
27
|
-
data {
|
|
28
|
-
linkLanguage
|
|
29
|
-
meta {
|
|
30
|
-
links
|
|
31
|
-
{
|
|
32
|
-
author
|
|
33
|
-
timestamp
|
|
34
|
-
data { source, predicate, target }
|
|
35
|
-
proof { valid, invalid, signature, key }
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
author
|
|
40
|
-
}
|
|
41
|
-
`
|
|
42
|
-
|
|
43
|
-
export type PerspectiveHandleCallback = (perspective: PerspectiveHandle) => null
|
|
44
|
-
export type UuidCallback = (uuid: string) => null
|
|
45
|
-
export type LinkCallback = (link: LinkExpression) => null
|
|
46
|
-
export type SyncStateChangeCallback = (state: PerspectiveState) => null
|
|
47
|
-
|
|
48
|
-
export class PerspectiveClient {
|
|
49
|
-
#apolloClient: ApolloClient<any>
|
|
50
|
-
#perspectiveAddedCallbacks: PerspectiveHandleCallback[]
|
|
51
|
-
#perspectiveUpdatedCallbacks: PerspectiveHandleCallback[]
|
|
52
|
-
#perspectiveRemovedCallbacks: UuidCallback[]
|
|
53
|
-
#perspectiveSyncStateChangeCallbacks: SyncStateChangeCallback[]
|
|
54
|
-
#expressionClient?: ExpressionClient
|
|
55
|
-
#neighbourhoodClient?: NeighbourhoodClient
|
|
56
|
-
|
|
57
|
-
constructor(client: ApolloClient<any>, subscribe: boolean = true) {
|
|
58
|
-
this.#apolloClient = client
|
|
59
|
-
this.#perspectiveAddedCallbacks = []
|
|
60
|
-
this.#perspectiveUpdatedCallbacks = []
|
|
61
|
-
this.#perspectiveRemovedCallbacks = []
|
|
62
|
-
this.#perspectiveSyncStateChangeCallbacks = []
|
|
63
|
-
|
|
64
|
-
if(subscribe) {
|
|
65
|
-
this.subscribePerspectiveAdded()
|
|
66
|
-
this.subscribePerspectiveUpdated()
|
|
67
|
-
this.subscribePerspectiveRemoved()
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
setExpressionClient(client: ExpressionClient) {
|
|
72
|
-
this.#expressionClient = client
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
setNeighbourhoodClient(client: NeighbourhoodClient) {
|
|
76
|
-
this.#neighbourhoodClient = client
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async all(): Promise<PerspectiveProxy[]> {
|
|
80
|
-
const { perspectives } = unwrapApolloResult(await this.#apolloClient.query({
|
|
81
|
-
query: gql`query perspectives {
|
|
82
|
-
perspectives {
|
|
83
|
-
${PERSPECTIVE_HANDLE_FIELDS}
|
|
84
|
-
}
|
|
85
|
-
}`
|
|
86
|
-
}))
|
|
87
|
-
return perspectives.map(handle => new PerspectiveProxy(handle, this))
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async byUUID(uuid: string): Promise<PerspectiveProxy|null> {
|
|
91
|
-
const { perspective } = unwrapApolloResult(await this.#apolloClient.query({
|
|
92
|
-
query: gql`query perspective($uuid: String!) {
|
|
93
|
-
perspective(uuid: $uuid) {
|
|
94
|
-
${PERSPECTIVE_HANDLE_FIELDS}
|
|
95
|
-
}
|
|
96
|
-
}`,
|
|
97
|
-
variables: { uuid }
|
|
98
|
-
}))
|
|
99
|
-
if(!perspective) return null
|
|
100
|
-
return new PerspectiveProxy(perspective, this)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async snapshotByUUID(uuid: string): Promise<Perspective|null> {
|
|
104
|
-
const { perspectiveSnapshot } = unwrapApolloResult(await this.#apolloClient.query({
|
|
105
|
-
query: gql`query perspectiveSnapshot($uuid: String!) {
|
|
106
|
-
perspectiveSnapshot(uuid: $uuid) {
|
|
107
|
-
links { ${LINK_EXPRESSION_FIELDS} }
|
|
108
|
-
}
|
|
109
|
-
}`,
|
|
110
|
-
variables: { uuid }
|
|
111
|
-
}))
|
|
112
|
-
return perspectiveSnapshot
|
|
113
|
-
}
|
|
114
|
-
async publishSnapshotByUUID(uuid: string): Promise<string|null> {
|
|
115
|
-
const { perspectivePublishSnapshot } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
116
|
-
mutation: gql`mutation perspectivePublishSnapshot($uuid: String!) {
|
|
117
|
-
perspectivePublishSnapshot(uuid: $uuid)
|
|
118
|
-
}`,
|
|
119
|
-
variables: { uuid }
|
|
120
|
-
}))
|
|
121
|
-
return perspectivePublishSnapshot
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]> {
|
|
125
|
-
const { perspectiveQueryLinks } = unwrapApolloResult(await this.#apolloClient.query({
|
|
126
|
-
query: gql`query perspectiveQueryLinks($uuid: String!, $query: LinkQuery!) {
|
|
127
|
-
perspectiveQueryLinks(query: $query, uuid: $uuid) {
|
|
128
|
-
${LINK_EXPRESSION_FIELDS}
|
|
129
|
-
}
|
|
130
|
-
}`,
|
|
131
|
-
variables: { uuid, query }
|
|
132
|
-
}))
|
|
133
|
-
return perspectiveQueryLinks
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async queryProlog(uuid: string, query: string): Promise<any> {
|
|
137
|
-
const { perspectiveQueryProlog } = unwrapApolloResult(await this.#apolloClient.query({
|
|
138
|
-
query: gql`query perspectiveQueryProlog($uuid: String!, $query: String!) {
|
|
139
|
-
perspectiveQueryProlog(uuid: $uuid, query: $query)
|
|
140
|
-
}`,
|
|
141
|
-
variables: { uuid, query }
|
|
142
|
-
}))
|
|
143
|
-
|
|
144
|
-
return JSON.parse(perspectiveQueryProlog)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async add(name: string): Promise<PerspectiveProxy> {
|
|
148
|
-
const { perspectiveAdd } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
149
|
-
mutation: gql`mutation perspectiveAdd($name: String!) {
|
|
150
|
-
perspectiveAdd(name: $name) {
|
|
151
|
-
${PERSPECTIVE_HANDLE_FIELDS}
|
|
152
|
-
}
|
|
153
|
-
}`,
|
|
154
|
-
variables: { name }
|
|
155
|
-
}))
|
|
156
|
-
return new PerspectiveProxy(perspectiveAdd, this)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async update(uuid: string, name: string): Promise<PerspectiveProxy> {
|
|
160
|
-
const { perspectiveUpdate } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
161
|
-
mutation: gql`mutation perspectiveUpdate($uuid: String!, $name: String!) {
|
|
162
|
-
perspectiveUpdate(uuid: $uuid, name: $name) {
|
|
163
|
-
${PERSPECTIVE_HANDLE_FIELDS}
|
|
164
|
-
}
|
|
165
|
-
}`,
|
|
166
|
-
variables: { uuid, name }
|
|
167
|
-
}))
|
|
168
|
-
return new PerspectiveProxy(perspectiveUpdate, this)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async remove(uuid: string): Promise<{perspectiveRemove: boolean}> {
|
|
172
|
-
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
173
|
-
mutation: gql`mutation perspectiveRemove($uuid: String!) {
|
|
174
|
-
perspectiveRemove(uuid: $uuid)
|
|
175
|
-
}`,
|
|
176
|
-
variables: { uuid }
|
|
177
|
-
}))
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async addLink(uuid: string, link: Link, status?: LinkStatus): Promise<LinkExpression> {
|
|
181
|
-
const { perspectiveAddLink } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
182
|
-
mutation: gql`mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String){
|
|
183
|
-
perspectiveAddLink(link: $link, uuid: $uuid, status: $status) {
|
|
184
|
-
${LINK_EXPRESSION_FIELDS}
|
|
185
|
-
}
|
|
186
|
-
}`,
|
|
187
|
-
variables: { uuid, link, status }
|
|
188
|
-
}))
|
|
189
|
-
return perspectiveAddLink
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async addLinks(uuid: string, links: Link[], status?: LinkStatus): Promise<LinkExpression[]> {
|
|
193
|
-
const { perspectiveAddLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
194
|
-
mutation: gql`mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String){
|
|
195
|
-
perspectiveAddLinks(links: $links, uuid: $uuid, status: $status) {
|
|
196
|
-
${LINK_EXPRESSION_FIELDS}
|
|
197
|
-
}
|
|
198
|
-
}`,
|
|
199
|
-
variables: { uuid, links, status }
|
|
200
|
-
}))
|
|
201
|
-
return perspectiveAddLinks
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async removeLinks(uuid: string, links: LinkExpressionInput[]): Promise<LinkExpression[]> {
|
|
205
|
-
const { perspectiveRemoveLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
206
|
-
mutation: gql`mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]!){
|
|
207
|
-
perspectiveRemoveLinks(links: $links, uuid: $uuid) {
|
|
208
|
-
${LINK_EXPRESSION_FIELDS}
|
|
209
|
-
}
|
|
210
|
-
}`,
|
|
211
|
-
variables: { uuid, links }
|
|
212
|
-
}))
|
|
213
|
-
return perspectiveRemoveLinks
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
async linkMutations(uuid: string, mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations> {
|
|
217
|
-
const { perspectiveLinkMutations } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
218
|
-
mutation: gql`mutation perspectiveLinkMutations($uuid: String!, $mutations: LinkMutations!, $status: String){
|
|
219
|
-
perspectiveLinkMutations(mutations: $mutations, uuid: $uuid, status: $status) {
|
|
220
|
-
additions {
|
|
221
|
-
${LINK_EXPRESSION_FIELDS}
|
|
222
|
-
}
|
|
223
|
-
removals {
|
|
224
|
-
${LINK_EXPRESSION_FIELDS}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}`,
|
|
228
|
-
variables: { uuid, mutations, status }
|
|
229
|
-
}))
|
|
230
|
-
return perspectiveLinkMutations
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async addLinkExpression(uuid: string, link: LinkExpressionInput, status?: LinkStatus): Promise<LinkExpression> {
|
|
234
|
-
const { perspectiveAddLinkExpression } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
235
|
-
mutation: gql`mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String){
|
|
236
|
-
perspectiveAddLinkExpression(link: $link, uuid: $uuid, status: $status) {
|
|
237
|
-
${LINK_EXPRESSION_FIELDS}
|
|
238
|
-
}
|
|
239
|
-
}`,
|
|
240
|
-
variables: { uuid, link }
|
|
241
|
-
}))
|
|
242
|
-
return perspectiveAddLinkExpression
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: LinkInput): Promise<LinkExpression> {
|
|
246
|
-
delete oldLink.__typename
|
|
247
|
-
delete oldLink.data.__typename
|
|
248
|
-
delete oldLink.proof.__typename
|
|
249
|
-
const { perspectiveUpdateLink } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
250
|
-
mutation: gql`mutation perspectiveUpdateLink(
|
|
251
|
-
$uuid: String!,
|
|
252
|
-
$newLink: LinkInput!
|
|
253
|
-
$oldLink: LinkExpressionInput!
|
|
254
|
-
){
|
|
255
|
-
perspectiveUpdateLink(
|
|
256
|
-
newLink: $newLink,
|
|
257
|
-
oldLink: $oldLink,
|
|
258
|
-
uuid: $uuid
|
|
259
|
-
) {
|
|
260
|
-
${LINK_EXPRESSION_FIELDS}
|
|
261
|
-
}
|
|
262
|
-
}`,
|
|
263
|
-
variables: { uuid, oldLink, newLink }
|
|
264
|
-
}))
|
|
265
|
-
|
|
266
|
-
if (!perspectiveUpdateLink.status) {
|
|
267
|
-
delete perspectiveUpdateLink.status
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return perspectiveUpdateLink
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
async removeLink(uuid: string, link: LinkExpressionInput): Promise<{perspectiveRemoveLink: boolean}> {
|
|
274
|
-
delete link.__typename
|
|
275
|
-
delete link.data.__typename
|
|
276
|
-
delete link.proof.__typename
|
|
277
|
-
delete link.status
|
|
278
|
-
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
279
|
-
mutation: gql`mutation perspectiveRemoveLink($link: LinkExpressionInput!, $uuid: String!) {
|
|
280
|
-
perspectiveRemoveLink(link: $link, uuid: $uuid)
|
|
281
|
-
}`,
|
|
282
|
-
variables: { uuid, link }
|
|
283
|
-
}))
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
//
|
|
296
|
-
|
|
297
|
-
this.#
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
this.#
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
})
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
1
|
+
import { ApolloClient, gql } from "@apollo/client/core";
|
|
2
|
+
import { ExpressionRendered } from "../expression/Expression";
|
|
3
|
+
import { ExpressionClient } from "../expression/ExpressionClient";
|
|
4
|
+
import { Link, LinkExpressionInput, LinkExpression, LinkInput, LinkMutations, LinkExpressionMutations } from "../links/Links";
|
|
5
|
+
import { NeighbourhoodClient } from "../neighbourhood/NeighbourhoodClient";
|
|
6
|
+
import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
|
|
7
|
+
import unwrapApolloResult from "../unwrapApolloResult";
|
|
8
|
+
import { LinkQuery } from "./LinkQuery";
|
|
9
|
+
import { Perspective } from "./Perspective";
|
|
10
|
+
import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
|
|
11
|
+
import { LinkStatus, PerspectiveProxy } from './PerspectiveProxy';
|
|
12
|
+
|
|
13
|
+
const LINK_EXPRESSION_FIELDS = `
|
|
14
|
+
author
|
|
15
|
+
timestamp
|
|
16
|
+
status
|
|
17
|
+
data { source, predicate, target }
|
|
18
|
+
proof { valid, invalid, signature, key }
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
const PERSPECTIVE_HANDLE_FIELDS = `
|
|
22
|
+
uuid
|
|
23
|
+
name
|
|
24
|
+
sharedUrl
|
|
25
|
+
state
|
|
26
|
+
neighbourhood {
|
|
27
|
+
data {
|
|
28
|
+
linkLanguage
|
|
29
|
+
meta {
|
|
30
|
+
links
|
|
31
|
+
{
|
|
32
|
+
author
|
|
33
|
+
timestamp
|
|
34
|
+
data { source, predicate, target }
|
|
35
|
+
proof { valid, invalid, signature, key }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
author
|
|
40
|
+
}
|
|
41
|
+
`
|
|
42
|
+
|
|
43
|
+
export type PerspectiveHandleCallback = (perspective: PerspectiveHandle) => null
|
|
44
|
+
export type UuidCallback = (uuid: string) => null
|
|
45
|
+
export type LinkCallback = (link: LinkExpression) => null
|
|
46
|
+
export type SyncStateChangeCallback = (state: PerspectiveState) => null
|
|
47
|
+
|
|
48
|
+
export class PerspectiveClient {
|
|
49
|
+
#apolloClient: ApolloClient<any>
|
|
50
|
+
#perspectiveAddedCallbacks: PerspectiveHandleCallback[]
|
|
51
|
+
#perspectiveUpdatedCallbacks: PerspectiveHandleCallback[]
|
|
52
|
+
#perspectiveRemovedCallbacks: UuidCallback[]
|
|
53
|
+
#perspectiveSyncStateChangeCallbacks: SyncStateChangeCallback[]
|
|
54
|
+
#expressionClient?: ExpressionClient
|
|
55
|
+
#neighbourhoodClient?: NeighbourhoodClient
|
|
56
|
+
|
|
57
|
+
constructor(client: ApolloClient<any>, subscribe: boolean = true) {
|
|
58
|
+
this.#apolloClient = client
|
|
59
|
+
this.#perspectiveAddedCallbacks = []
|
|
60
|
+
this.#perspectiveUpdatedCallbacks = []
|
|
61
|
+
this.#perspectiveRemovedCallbacks = []
|
|
62
|
+
this.#perspectiveSyncStateChangeCallbacks = []
|
|
63
|
+
|
|
64
|
+
if(subscribe) {
|
|
65
|
+
this.subscribePerspectiveAdded()
|
|
66
|
+
this.subscribePerspectiveUpdated()
|
|
67
|
+
this.subscribePerspectiveRemoved()
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
setExpressionClient(client: ExpressionClient) {
|
|
72
|
+
this.#expressionClient = client
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
setNeighbourhoodClient(client: NeighbourhoodClient) {
|
|
76
|
+
this.#neighbourhoodClient = client
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async all(): Promise<PerspectiveProxy[]> {
|
|
80
|
+
const { perspectives } = unwrapApolloResult(await this.#apolloClient.query({
|
|
81
|
+
query: gql`query perspectives {
|
|
82
|
+
perspectives {
|
|
83
|
+
${PERSPECTIVE_HANDLE_FIELDS}
|
|
84
|
+
}
|
|
85
|
+
}`
|
|
86
|
+
}))
|
|
87
|
+
return perspectives.map(handle => new PerspectiveProxy(handle, this))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async byUUID(uuid: string): Promise<PerspectiveProxy|null> {
|
|
91
|
+
const { perspective } = unwrapApolloResult(await this.#apolloClient.query({
|
|
92
|
+
query: gql`query perspective($uuid: String!) {
|
|
93
|
+
perspective(uuid: $uuid) {
|
|
94
|
+
${PERSPECTIVE_HANDLE_FIELDS}
|
|
95
|
+
}
|
|
96
|
+
}`,
|
|
97
|
+
variables: { uuid }
|
|
98
|
+
}))
|
|
99
|
+
if(!perspective) return null
|
|
100
|
+
return new PerspectiveProxy(perspective, this)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async snapshotByUUID(uuid: string): Promise<Perspective|null> {
|
|
104
|
+
const { perspectiveSnapshot } = unwrapApolloResult(await this.#apolloClient.query({
|
|
105
|
+
query: gql`query perspectiveSnapshot($uuid: String!) {
|
|
106
|
+
perspectiveSnapshot(uuid: $uuid) {
|
|
107
|
+
links { ${LINK_EXPRESSION_FIELDS} }
|
|
108
|
+
}
|
|
109
|
+
}`,
|
|
110
|
+
variables: { uuid }
|
|
111
|
+
}))
|
|
112
|
+
return perspectiveSnapshot
|
|
113
|
+
}
|
|
114
|
+
async publishSnapshotByUUID(uuid: string): Promise<string|null> {
|
|
115
|
+
const { perspectivePublishSnapshot } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
116
|
+
mutation: gql`mutation perspectivePublishSnapshot($uuid: String!) {
|
|
117
|
+
perspectivePublishSnapshot(uuid: $uuid)
|
|
118
|
+
}`,
|
|
119
|
+
variables: { uuid }
|
|
120
|
+
}))
|
|
121
|
+
return perspectivePublishSnapshot
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]> {
|
|
125
|
+
const { perspectiveQueryLinks } = unwrapApolloResult(await this.#apolloClient.query({
|
|
126
|
+
query: gql`query perspectiveQueryLinks($uuid: String!, $query: LinkQuery!) {
|
|
127
|
+
perspectiveQueryLinks(query: $query, uuid: $uuid) {
|
|
128
|
+
${LINK_EXPRESSION_FIELDS}
|
|
129
|
+
}
|
|
130
|
+
}`,
|
|
131
|
+
variables: { uuid, query }
|
|
132
|
+
}))
|
|
133
|
+
return perspectiveQueryLinks
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
async queryProlog(uuid: string, query: string): Promise<any> {
|
|
137
|
+
const { perspectiveQueryProlog } = unwrapApolloResult(await this.#apolloClient.query({
|
|
138
|
+
query: gql`query perspectiveQueryProlog($uuid: String!, $query: String!) {
|
|
139
|
+
perspectiveQueryProlog(uuid: $uuid, query: $query)
|
|
140
|
+
}`,
|
|
141
|
+
variables: { uuid, query }
|
|
142
|
+
}))
|
|
143
|
+
|
|
144
|
+
return JSON.parse(perspectiveQueryProlog)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async add(name: string): Promise<PerspectiveProxy> {
|
|
148
|
+
const { perspectiveAdd } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
149
|
+
mutation: gql`mutation perspectiveAdd($name: String!) {
|
|
150
|
+
perspectiveAdd(name: $name) {
|
|
151
|
+
${PERSPECTIVE_HANDLE_FIELDS}
|
|
152
|
+
}
|
|
153
|
+
}`,
|
|
154
|
+
variables: { name }
|
|
155
|
+
}))
|
|
156
|
+
return new PerspectiveProxy(perspectiveAdd, this)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async update(uuid: string, name: string): Promise<PerspectiveProxy> {
|
|
160
|
+
const { perspectiveUpdate } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
161
|
+
mutation: gql`mutation perspectiveUpdate($uuid: String!, $name: String!) {
|
|
162
|
+
perspectiveUpdate(uuid: $uuid, name: $name) {
|
|
163
|
+
${PERSPECTIVE_HANDLE_FIELDS}
|
|
164
|
+
}
|
|
165
|
+
}`,
|
|
166
|
+
variables: { uuid, name }
|
|
167
|
+
}))
|
|
168
|
+
return new PerspectiveProxy(perspectiveUpdate, this)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async remove(uuid: string): Promise<{perspectiveRemove: boolean}> {
|
|
172
|
+
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
173
|
+
mutation: gql`mutation perspectiveRemove($uuid: String!) {
|
|
174
|
+
perspectiveRemove(uuid: $uuid)
|
|
175
|
+
}`,
|
|
176
|
+
variables: { uuid }
|
|
177
|
+
}))
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async addLink(uuid: string, link: Link, status?: LinkStatus): Promise<LinkExpression> {
|
|
181
|
+
const { perspectiveAddLink } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
182
|
+
mutation: gql`mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String){
|
|
183
|
+
perspectiveAddLink(link: $link, uuid: $uuid, status: $status) {
|
|
184
|
+
${LINK_EXPRESSION_FIELDS}
|
|
185
|
+
}
|
|
186
|
+
}`,
|
|
187
|
+
variables: { uuid, link, status }
|
|
188
|
+
}))
|
|
189
|
+
return perspectiveAddLink
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async addLinks(uuid: string, links: Link[], status?: LinkStatus): Promise<LinkExpression[]> {
|
|
193
|
+
const { perspectiveAddLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
194
|
+
mutation: gql`mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String){
|
|
195
|
+
perspectiveAddLinks(links: $links, uuid: $uuid, status: $status) {
|
|
196
|
+
${LINK_EXPRESSION_FIELDS}
|
|
197
|
+
}
|
|
198
|
+
}`,
|
|
199
|
+
variables: { uuid, links, status }
|
|
200
|
+
}))
|
|
201
|
+
return perspectiveAddLinks
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async removeLinks(uuid: string, links: LinkExpressionInput[]): Promise<LinkExpression[]> {
|
|
205
|
+
const { perspectiveRemoveLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
206
|
+
mutation: gql`mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]!){
|
|
207
|
+
perspectiveRemoveLinks(links: $links, uuid: $uuid) {
|
|
208
|
+
${LINK_EXPRESSION_FIELDS}
|
|
209
|
+
}
|
|
210
|
+
}`,
|
|
211
|
+
variables: { uuid, links }
|
|
212
|
+
}))
|
|
213
|
+
return perspectiveRemoveLinks
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async linkMutations(uuid: string, mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations> {
|
|
217
|
+
const { perspectiveLinkMutations } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
218
|
+
mutation: gql`mutation perspectiveLinkMutations($uuid: String!, $mutations: LinkMutations!, $status: String){
|
|
219
|
+
perspectiveLinkMutations(mutations: $mutations, uuid: $uuid, status: $status) {
|
|
220
|
+
additions {
|
|
221
|
+
${LINK_EXPRESSION_FIELDS}
|
|
222
|
+
}
|
|
223
|
+
removals {
|
|
224
|
+
${LINK_EXPRESSION_FIELDS}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}`,
|
|
228
|
+
variables: { uuid, mutations, status }
|
|
229
|
+
}))
|
|
230
|
+
return perspectiveLinkMutations
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async addLinkExpression(uuid: string, link: LinkExpressionInput, status?: LinkStatus): Promise<LinkExpression> {
|
|
234
|
+
const { perspectiveAddLinkExpression } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
235
|
+
mutation: gql`mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String){
|
|
236
|
+
perspectiveAddLinkExpression(link: $link, uuid: $uuid, status: $status) {
|
|
237
|
+
${LINK_EXPRESSION_FIELDS}
|
|
238
|
+
}
|
|
239
|
+
}`,
|
|
240
|
+
variables: { uuid, link }
|
|
241
|
+
}))
|
|
242
|
+
return perspectiveAddLinkExpression
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: LinkInput): Promise<LinkExpression> {
|
|
246
|
+
delete oldLink.__typename
|
|
247
|
+
delete oldLink.data.__typename
|
|
248
|
+
delete oldLink.proof.__typename
|
|
249
|
+
const { perspectiveUpdateLink } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
250
|
+
mutation: gql`mutation perspectiveUpdateLink(
|
|
251
|
+
$uuid: String!,
|
|
252
|
+
$newLink: LinkInput!
|
|
253
|
+
$oldLink: LinkExpressionInput!
|
|
254
|
+
){
|
|
255
|
+
perspectiveUpdateLink(
|
|
256
|
+
newLink: $newLink,
|
|
257
|
+
oldLink: $oldLink,
|
|
258
|
+
uuid: $uuid
|
|
259
|
+
) {
|
|
260
|
+
${LINK_EXPRESSION_FIELDS}
|
|
261
|
+
}
|
|
262
|
+
}`,
|
|
263
|
+
variables: { uuid, oldLink, newLink }
|
|
264
|
+
}))
|
|
265
|
+
|
|
266
|
+
if (!perspectiveUpdateLink.status) {
|
|
267
|
+
delete perspectiveUpdateLink.status
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return perspectiveUpdateLink
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async removeLink(uuid: string, link: LinkExpressionInput): Promise<{perspectiveRemoveLink: boolean}> {
|
|
274
|
+
delete link.__typename
|
|
275
|
+
delete link.data.__typename
|
|
276
|
+
delete link.proof.__typename
|
|
277
|
+
delete link.status
|
|
278
|
+
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
279
|
+
mutation: gql`mutation perspectiveRemoveLink($link: LinkExpressionInput!, $uuid: String!) {
|
|
280
|
+
perspectiveRemoveLink(link: $link, uuid: $uuid)
|
|
281
|
+
}`,
|
|
282
|
+
variables: { uuid, link }
|
|
283
|
+
}))
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
async addSdna(uuid: string, name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom"): Promise<boolean> {
|
|
287
|
+
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
288
|
+
mutation: gql`mutation perspectiveAddSdna($uuid: String!, $name: String!, $sdnaCode: String!, $sdnaType: String!) {
|
|
289
|
+
perspectiveAddSdna(uuid: $uuid, name: $name, sdnaCode: $sdnaCode, sdnaType: $sdnaType)
|
|
290
|
+
}`,
|
|
291
|
+
variables: { uuid, name, sdnaCode, sdnaType }
|
|
292
|
+
})).perspectiveAddSdna
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ExpressionClient functions, needed for Subjects:
|
|
296
|
+
async getExpression(expressionURI: string): Promise<ExpressionRendered> {
|
|
297
|
+
return await this.#expressionClient.get(expressionURI)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async createExpression(content: any, languageAddress: string): Promise<string> {
|
|
301
|
+
return await this.#expressionClient.create(content, languageAddress)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Subscriptions:
|
|
305
|
+
addPerspectiveAddedListener(cb: PerspectiveHandleCallback) {
|
|
306
|
+
this.#perspectiveAddedCallbacks.push(cb)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
subscribePerspectiveAdded() {
|
|
310
|
+
this.#apolloClient.subscribe({
|
|
311
|
+
query: gql` subscription {
|
|
312
|
+
perspectiveAdded { ${PERSPECTIVE_HANDLE_FIELDS} }
|
|
313
|
+
}
|
|
314
|
+
`}).subscribe({
|
|
315
|
+
next: result => {
|
|
316
|
+
this.#perspectiveAddedCallbacks.forEach(cb => {
|
|
317
|
+
cb(result.data.perspectiveAdded)
|
|
318
|
+
})
|
|
319
|
+
},
|
|
320
|
+
error: (e) => console.error(e)
|
|
321
|
+
})
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
addPerspectiveUpdatedListener(cb: PerspectiveHandleCallback) {
|
|
325
|
+
this.#perspectiveUpdatedCallbacks.push(cb)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
subscribePerspectiveUpdated() {
|
|
329
|
+
this.#apolloClient.subscribe({
|
|
330
|
+
query: gql` subscription {
|
|
331
|
+
perspectiveUpdated { ${PERSPECTIVE_HANDLE_FIELDS} }
|
|
332
|
+
}
|
|
333
|
+
`}).subscribe({
|
|
334
|
+
next: result => {
|
|
335
|
+
this.#perspectiveUpdatedCallbacks.forEach(cb => {
|
|
336
|
+
cb(result.data.perspectiveUpdated)
|
|
337
|
+
})
|
|
338
|
+
},
|
|
339
|
+
error: (e) => console.error(e)
|
|
340
|
+
})
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
addPerspectiveSyncedListener(cb: SyncStateChangeCallback) {
|
|
344
|
+
this.#perspectiveSyncStateChangeCallbacks.push(cb)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
async addPerspectiveSyncStateChangeListener(uuid: String, cb: SyncStateChangeCallback[]): Promise<void> {
|
|
348
|
+
this.#apolloClient.subscribe({
|
|
349
|
+
query: gql` subscription {
|
|
350
|
+
perspectiveSyncStateChange(uuid: "${uuid}")
|
|
351
|
+
}
|
|
352
|
+
`}).subscribe({
|
|
353
|
+
next: result => {
|
|
354
|
+
cb.forEach(c => {
|
|
355
|
+
c(result.data.perspectiveSyncStateChange)
|
|
356
|
+
})
|
|
357
|
+
},
|
|
358
|
+
error: (e) => console.error(e)
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
addPerspectiveRemovedListener(cb: UuidCallback) {
|
|
365
|
+
this.#perspectiveRemovedCallbacks.push(cb)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
subscribePerspectiveRemoved() {
|
|
369
|
+
this.#apolloClient.subscribe({
|
|
370
|
+
query: gql` subscription {
|
|
371
|
+
perspectiveRemoved
|
|
372
|
+
}
|
|
373
|
+
`}).subscribe({
|
|
374
|
+
next: result => {
|
|
375
|
+
this.#perspectiveRemovedCallbacks.forEach(cb => {
|
|
376
|
+
cb(result.data.perspectiveRemoved)
|
|
377
|
+
})
|
|
378
|
+
},
|
|
379
|
+
error: (e) => console.error(e)
|
|
380
|
+
})
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
async addPerspectiveLinkAddedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
|
|
384
|
+
this.#apolloClient.subscribe({
|
|
385
|
+
query: gql` subscription {
|
|
386
|
+
perspectiveLinkAdded(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
|
|
387
|
+
}
|
|
388
|
+
`}).subscribe({
|
|
389
|
+
next: result => {
|
|
390
|
+
cb.forEach(c => {
|
|
391
|
+
c(result.data.perspectiveLinkAdded)
|
|
392
|
+
})
|
|
393
|
+
},
|
|
394
|
+
error: (e) => console.error(e)
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
async addPerspectiveLinkRemovedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
|
|
401
|
+
this.#apolloClient.subscribe({
|
|
402
|
+
query: gql` subscription {
|
|
403
|
+
perspectiveLinkRemoved(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
|
|
404
|
+
}
|
|
405
|
+
`}).subscribe({
|
|
406
|
+
next: result => {
|
|
407
|
+
cb.forEach(c => {
|
|
408
|
+
if (!result.data.perspectiveLinkRemoved.status) {
|
|
409
|
+
delete result.data.perspectiveLinkRemoved.status
|
|
410
|
+
}
|
|
411
|
+
c(result.data.perspectiveLinkRemoved)
|
|
412
|
+
})
|
|
413
|
+
},
|
|
414
|
+
error: (e) => console.error(e)
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void> {
|
|
421
|
+
this.#apolloClient.subscribe({
|
|
422
|
+
query: gql` subscription {
|
|
423
|
+
perspectiveLinkUpdated(uuid: "${uuid}") {
|
|
424
|
+
oldLink {
|
|
425
|
+
${LINK_EXPRESSION_FIELDS}
|
|
426
|
+
}
|
|
427
|
+
newLink {
|
|
428
|
+
${LINK_EXPRESSION_FIELDS}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
`}).subscribe({
|
|
433
|
+
next: result => {
|
|
434
|
+
cb.forEach(c => {
|
|
435
|
+
if (!result.data.perspectiveLinkUpdated.newLink.status) {
|
|
436
|
+
delete result.data.perspectiveLinkUpdated.newLink.status
|
|
437
|
+
}
|
|
438
|
+
if (!result.data.perspectiveLinkUpdated.oldLink.status) {
|
|
439
|
+
delete result.data.perspectiveLinkUpdated.oldLink.status
|
|
440
|
+
}
|
|
441
|
+
c(result.data.perspectiveLinkUpdated)
|
|
442
|
+
})
|
|
443
|
+
},
|
|
444
|
+
error: (e) => console.error(e)
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
await new Promise<void>(resolve => setTimeout(resolve, 500))
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy {
|
|
451
|
+
return new NeighbourhoodProxy(this.#neighbourhoodClient, uuid)
|
|
452
|
+
}
|
|
444
453
|
}
|