@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,276 +1,276 @@
|
|
|
1
|
-
import { ApolloClient, ApolloQueryResult, gql } from "@apollo/client/core"
|
|
2
|
-
import { Address } from "../Address"
|
|
3
|
-
import { DID } from "../DID"
|
|
4
|
-
import { OnlineAgent, TelepresenceSignalCallback } from "../language/Language"
|
|
5
|
-
import { Perspective, PerspectiveUnsignedInput } from "../perspectives/Perspective"
|
|
6
|
-
import { PerspectiveHandle } from "../perspectives/PerspectiveHandle"
|
|
7
|
-
import unwrapApolloResult from "../unwrapApolloResult"
|
|
8
|
-
import { NeighbourhoodProxy } from "./NeighbourhoodProxy"
|
|
9
|
-
|
|
10
|
-
export class NeighbourhoodClient {
|
|
11
|
-
#apolloClient: ApolloClient<any>
|
|
12
|
-
#signalHandlers: Map<string, TelepresenceSignalCallback[]> = new Map()
|
|
13
|
-
|
|
14
|
-
constructor(client: ApolloClient<any>) {
|
|
15
|
-
this.#apolloClient = client
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async publishFromPerspective(
|
|
19
|
-
perspectiveUUID: string,
|
|
20
|
-
linkLanguage: Address,
|
|
21
|
-
meta: Perspective
|
|
22
|
-
): Promise<string> {
|
|
23
|
-
const { neighbourhoodPublishFromPerspective } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
24
|
-
mutation: gql`mutation neighbourhoodPublishFromPerspective(
|
|
25
|
-
$linkLanguage: String!,
|
|
26
|
-
$meta: PerspectiveInput!,
|
|
27
|
-
$perspectiveUUID: String!
|
|
28
|
-
) {
|
|
29
|
-
neighbourhoodPublishFromPerspective(
|
|
30
|
-
linkLanguage: $linkLanguage,
|
|
31
|
-
meta: $meta,
|
|
32
|
-
perspectiveUUID: $perspectiveUUID
|
|
33
|
-
)
|
|
34
|
-
}`,
|
|
35
|
-
variables: { perspectiveUUID, linkLanguage, meta: meta}
|
|
36
|
-
}))
|
|
37
|
-
return neighbourhoodPublishFromPerspective
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async joinFromUrl(url: string): Promise<PerspectiveHandle> {
|
|
41
|
-
const { neighbourhoodJoinFromUrl } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
42
|
-
mutation: gql`mutation neighbourhoodJoinFromUrl($url: String!) {
|
|
43
|
-
neighbourhoodJoinFromUrl(url: $url) {
|
|
44
|
-
uuid
|
|
45
|
-
name
|
|
46
|
-
sharedUrl
|
|
47
|
-
state
|
|
48
|
-
neighbourhood {
|
|
49
|
-
data {
|
|
50
|
-
linkLanguage
|
|
51
|
-
meta {
|
|
52
|
-
links
|
|
53
|
-
{
|
|
54
|
-
author
|
|
55
|
-
timestamp
|
|
56
|
-
data { source, predicate, target }
|
|
57
|
-
proof { valid, invalid, signature, key }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
author
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}`,
|
|
65
|
-
variables: { url }
|
|
66
|
-
}))
|
|
67
|
-
return neighbourhoodJoinFromUrl
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async otherAgents(perspectiveUUID: string): Promise<DID[]> {
|
|
71
|
-
const { neighbourhoodOtherAgents } = unwrapApolloResult(await this.#apolloClient.query({
|
|
72
|
-
query: gql`query neighbourhoodOtherAgents($perspectiveUUID: String!) {
|
|
73
|
-
neighbourhoodOtherAgents(perspectiveUUID: $perspectiveUUID)
|
|
74
|
-
}`,
|
|
75
|
-
variables: { perspectiveUUID }
|
|
76
|
-
}))
|
|
77
|
-
return neighbourhoodOtherAgents
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async hasTelepresenceAdapter(perspectiveUUID: string): Promise<boolean> {
|
|
81
|
-
const { neighbourhoodHasTelepresenceAdapter } = unwrapApolloResult(await this.#apolloClient.query({
|
|
82
|
-
query: gql`query neighbourhoodHasTelepresenceAdapter($perspectiveUUID: String!) {
|
|
83
|
-
neighbourhoodHasTelepresenceAdapter(perspectiveUUID: $perspectiveUUID)
|
|
84
|
-
}`,
|
|
85
|
-
variables: { perspectiveUUID }
|
|
86
|
-
}))
|
|
87
|
-
return neighbourhoodHasTelepresenceAdapter
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async onlineAgents(perspectiveUUID: string): Promise<OnlineAgent[]> {
|
|
91
|
-
const { neighbourhoodOnlineAgents } = unwrapApolloResult(await this.#apolloClient.query({
|
|
92
|
-
query: gql`query neighbourhoodOnlineAgents($perspectiveUUID: String!) {
|
|
93
|
-
neighbourhoodOnlineAgents(perspectiveUUID: $perspectiveUUID) {
|
|
94
|
-
did
|
|
95
|
-
status {
|
|
96
|
-
author
|
|
97
|
-
timestamp
|
|
98
|
-
data {
|
|
99
|
-
links {
|
|
100
|
-
author
|
|
101
|
-
timestamp
|
|
102
|
-
data { source, predicate, target }
|
|
103
|
-
proof { valid, invalid, signature, key }
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
proof { valid, invalid, signature, key }
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}`,
|
|
110
|
-
variables: { perspectiveUUID }
|
|
111
|
-
}))
|
|
112
|
-
return neighbourhoodOnlineAgents
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async setOnlineStatus(perspectiveUUID: string, status: Perspective): Promise<boolean> {
|
|
116
|
-
const { neighbourhoodSetOnlineStatus } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
117
|
-
mutation: gql`mutation neighbourhoodSetOnlineStatus(
|
|
118
|
-
$perspectiveUUID: String!,
|
|
119
|
-
$status: PerspectiveInput!
|
|
120
|
-
) {
|
|
121
|
-
neighbourhoodSetOnlineStatus(
|
|
122
|
-
perspectiveUUID: $perspectiveUUID,
|
|
123
|
-
status: $status
|
|
124
|
-
)
|
|
125
|
-
}`,
|
|
126
|
-
variables: { perspectiveUUID, status }
|
|
127
|
-
}))
|
|
128
|
-
|
|
129
|
-
return neighbourhoodSetOnlineStatus
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async setOnlineStatusU(perspectiveUUID: string, status: PerspectiveUnsignedInput): Promise<boolean> {
|
|
133
|
-
const { neighbourhoodSetOnlineStatusU } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
134
|
-
mutation: gql`mutation neighbourhoodSetOnlineStatusU(
|
|
135
|
-
$perspectiveUUID: String!,
|
|
136
|
-
$status: PerspectiveUnsignedInput!
|
|
137
|
-
) {
|
|
138
|
-
neighbourhoodSetOnlineStatusU(
|
|
139
|
-
perspectiveUUID: $perspectiveUUID,
|
|
140
|
-
status: $status
|
|
141
|
-
)
|
|
142
|
-
}`,
|
|
143
|
-
variables: { perspectiveUUID, status }
|
|
144
|
-
}))
|
|
145
|
-
|
|
146
|
-
return neighbourhoodSetOnlineStatusU
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async sendSignal(perspectiveUUID: string, remoteAgentDid: string, payload: Perspective): Promise<boolean> {
|
|
150
|
-
const { neighbourhoodSendSignal } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
151
|
-
mutation: gql`mutation neighbourhoodSendSignal(
|
|
152
|
-
$perspectiveUUID: String!,
|
|
153
|
-
$remoteAgentDid: String!,
|
|
154
|
-
$payload: PerspectiveInput!
|
|
155
|
-
) {
|
|
156
|
-
neighbourhoodSendSignal(
|
|
157
|
-
perspectiveUUID: $perspectiveUUID,
|
|
158
|
-
remoteAgentDid: $remoteAgentDid,
|
|
159
|
-
payload: $payload
|
|
160
|
-
)
|
|
161
|
-
}`,
|
|
162
|
-
variables: { perspectiveUUID, remoteAgentDid, payload }
|
|
163
|
-
}))
|
|
164
|
-
|
|
165
|
-
return neighbourhoodSendSignal
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async sendSignalU(perspectiveUUID: string, remoteAgentDid: string, payload: PerspectiveUnsignedInput): Promise<boolean> {
|
|
169
|
-
const { neighbourhoodSendSignalU } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
170
|
-
mutation: gql`mutation neighbourhoodSendSignalU(
|
|
171
|
-
$perspectiveUUID: String!,
|
|
172
|
-
$remoteAgentDid: String!,
|
|
173
|
-
$payload: PerspectiveUnsignedInput!
|
|
174
|
-
) {
|
|
175
|
-
neighbourhoodSendSignalU(
|
|
176
|
-
perspectiveUUID: $perspectiveUUID,
|
|
177
|
-
remoteAgentDid: $remoteAgentDid,
|
|
178
|
-
payload: $payload
|
|
179
|
-
)
|
|
180
|
-
}`,
|
|
181
|
-
variables: { perspectiveUUID, remoteAgentDid, payload }
|
|
182
|
-
}))
|
|
183
|
-
|
|
184
|
-
return neighbourhoodSendSignalU
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
async sendBroadcast(perspectiveUUID: string, payload: Perspective): Promise<boolean> {
|
|
188
|
-
const { neighbourhoodSendBroadcast } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
189
|
-
mutation: gql`mutation neighbourhoodSendBroadcast(
|
|
190
|
-
$perspectiveUUID: String!,
|
|
191
|
-
$payload: PerspectiveInput!
|
|
192
|
-
) {
|
|
193
|
-
neighbourhoodSendBroadcast(
|
|
194
|
-
perspectiveUUID: $perspectiveUUID,
|
|
195
|
-
payload: $payload
|
|
196
|
-
)
|
|
197
|
-
}`,
|
|
198
|
-
variables: { perspectiveUUID, payload }
|
|
199
|
-
}))
|
|
200
|
-
|
|
201
|
-
return neighbourhoodSendBroadcast
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async sendBroadcastU(perspectiveUUID: string, payload: PerspectiveUnsignedInput): Promise<boolean> {
|
|
205
|
-
const { neighbourhoodSendBroadcastU } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
206
|
-
mutation: gql`mutation neighbourhoodSendBroadcastU(
|
|
207
|
-
$perspectiveUUID: String!,
|
|
208
|
-
$payload: PerspectiveUnsignedInput!
|
|
209
|
-
) {
|
|
210
|
-
neighbourhoodSendBroadcastU(
|
|
211
|
-
perspectiveUUID: $perspectiveUUID,
|
|
212
|
-
payload: $payload
|
|
213
|
-
)
|
|
214
|
-
}`,
|
|
215
|
-
variables: { perspectiveUUID, payload }
|
|
216
|
-
}))
|
|
217
|
-
|
|
218
|
-
return neighbourhoodSendBroadcastU
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
dispatchSignal(perspectiveUUID:string, signal: any) {
|
|
222
|
-
const handlers = this.#signalHandlers.get(perspectiveUUID)
|
|
223
|
-
if (handlers) {
|
|
224
|
-
handlers.forEach(handler => handler(signal))
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
async subscribeToSignals(perspectiveUUID: string): Promise<void> {
|
|
229
|
-
const that = this
|
|
230
|
-
await this.#apolloClient.subscribe({
|
|
231
|
-
query: gql`subscription neighbourhoodSignal($perspectiveUUID: String!) {
|
|
232
|
-
neighbourhoodSignal(perspectiveUUID: $perspectiveUUID) {
|
|
233
|
-
author
|
|
234
|
-
timestamp
|
|
235
|
-
data {
|
|
236
|
-
links
|
|
237
|
-
{
|
|
238
|
-
author
|
|
239
|
-
timestamp
|
|
240
|
-
data { source, predicate, target }
|
|
241
|
-
proof { valid, invalid, signature, key }
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
proof { valid, invalid, signature, key }
|
|
245
|
-
}
|
|
246
|
-
}`,
|
|
247
|
-
variables: { perspectiveUUID }
|
|
248
|
-
}).subscribe({
|
|
249
|
-
next: (result: ApolloQueryResult<any>) => {
|
|
250
|
-
const { neighbourhoodSignal } = unwrapApolloResult(result)
|
|
251
|
-
that.dispatchSignal(perspectiveUUID, neighbourhoodSignal)
|
|
252
|
-
}
|
|
253
|
-
})
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async addSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): Promise<void> {
|
|
257
|
-
let handlersForPerspective = this.#signalHandlers.get(perspectiveUUID)
|
|
258
|
-
if (!handlersForPerspective) {
|
|
259
|
-
handlersForPerspective = []
|
|
260
|
-
await this.subscribeToSignals(perspectiveUUID)
|
|
261
|
-
}
|
|
262
|
-
handlersForPerspective.push(handler)
|
|
263
|
-
this.#signalHandlers.set(perspectiveUUID, handlersForPerspective)
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
removeSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): void {
|
|
267
|
-
const handlersForPerspective = this.#signalHandlers.get(perspectiveUUID)
|
|
268
|
-
if (handlersForPerspective) {
|
|
269
|
-
const index = handlersForPerspective.indexOf(handler)
|
|
270
|
-
if (index > -1) {
|
|
271
|
-
handlersForPerspective.splice(index, 1)
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
this.#signalHandlers.set(perspectiveUUID, handlersForPerspective)
|
|
275
|
-
}
|
|
1
|
+
import { ApolloClient, ApolloQueryResult, gql } from "@apollo/client/core"
|
|
2
|
+
import { Address } from "../Address"
|
|
3
|
+
import { DID } from "../DID"
|
|
4
|
+
import { OnlineAgent, TelepresenceSignalCallback } from "../language/Language"
|
|
5
|
+
import { Perspective, PerspectiveUnsignedInput } from "../perspectives/Perspective"
|
|
6
|
+
import { PerspectiveHandle } from "../perspectives/PerspectiveHandle"
|
|
7
|
+
import unwrapApolloResult from "../unwrapApolloResult"
|
|
8
|
+
import { NeighbourhoodProxy } from "./NeighbourhoodProxy"
|
|
9
|
+
|
|
10
|
+
export class NeighbourhoodClient {
|
|
11
|
+
#apolloClient: ApolloClient<any>
|
|
12
|
+
#signalHandlers: Map<string, TelepresenceSignalCallback[]> = new Map()
|
|
13
|
+
|
|
14
|
+
constructor(client: ApolloClient<any>) {
|
|
15
|
+
this.#apolloClient = client
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async publishFromPerspective(
|
|
19
|
+
perspectiveUUID: string,
|
|
20
|
+
linkLanguage: Address,
|
|
21
|
+
meta: Perspective
|
|
22
|
+
): Promise<string> {
|
|
23
|
+
const { neighbourhoodPublishFromPerspective } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
24
|
+
mutation: gql`mutation neighbourhoodPublishFromPerspective(
|
|
25
|
+
$linkLanguage: String!,
|
|
26
|
+
$meta: PerspectiveInput!,
|
|
27
|
+
$perspectiveUUID: String!
|
|
28
|
+
) {
|
|
29
|
+
neighbourhoodPublishFromPerspective(
|
|
30
|
+
linkLanguage: $linkLanguage,
|
|
31
|
+
meta: $meta,
|
|
32
|
+
perspectiveUUID: $perspectiveUUID
|
|
33
|
+
)
|
|
34
|
+
}`,
|
|
35
|
+
variables: { perspectiveUUID, linkLanguage, meta: meta}
|
|
36
|
+
}))
|
|
37
|
+
return neighbourhoodPublishFromPerspective
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async joinFromUrl(url: string): Promise<PerspectiveHandle> {
|
|
41
|
+
const { neighbourhoodJoinFromUrl } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
42
|
+
mutation: gql`mutation neighbourhoodJoinFromUrl($url: String!) {
|
|
43
|
+
neighbourhoodJoinFromUrl(url: $url) {
|
|
44
|
+
uuid
|
|
45
|
+
name
|
|
46
|
+
sharedUrl
|
|
47
|
+
state
|
|
48
|
+
neighbourhood {
|
|
49
|
+
data {
|
|
50
|
+
linkLanguage
|
|
51
|
+
meta {
|
|
52
|
+
links
|
|
53
|
+
{
|
|
54
|
+
author
|
|
55
|
+
timestamp
|
|
56
|
+
data { source, predicate, target }
|
|
57
|
+
proof { valid, invalid, signature, key }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
author
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}`,
|
|
65
|
+
variables: { url }
|
|
66
|
+
}))
|
|
67
|
+
return neighbourhoodJoinFromUrl
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async otherAgents(perspectiveUUID: string): Promise<DID[]> {
|
|
71
|
+
const { neighbourhoodOtherAgents } = unwrapApolloResult(await this.#apolloClient.query({
|
|
72
|
+
query: gql`query neighbourhoodOtherAgents($perspectiveUUID: String!) {
|
|
73
|
+
neighbourhoodOtherAgents(perspectiveUUID: $perspectiveUUID)
|
|
74
|
+
}`,
|
|
75
|
+
variables: { perspectiveUUID }
|
|
76
|
+
}))
|
|
77
|
+
return neighbourhoodOtherAgents
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async hasTelepresenceAdapter(perspectiveUUID: string): Promise<boolean> {
|
|
81
|
+
const { neighbourhoodHasTelepresenceAdapter } = unwrapApolloResult(await this.#apolloClient.query({
|
|
82
|
+
query: gql`query neighbourhoodHasTelepresenceAdapter($perspectiveUUID: String!) {
|
|
83
|
+
neighbourhoodHasTelepresenceAdapter(perspectiveUUID: $perspectiveUUID)
|
|
84
|
+
}`,
|
|
85
|
+
variables: { perspectiveUUID }
|
|
86
|
+
}))
|
|
87
|
+
return neighbourhoodHasTelepresenceAdapter
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async onlineAgents(perspectiveUUID: string): Promise<OnlineAgent[]> {
|
|
91
|
+
const { neighbourhoodOnlineAgents } = unwrapApolloResult(await this.#apolloClient.query({
|
|
92
|
+
query: gql`query neighbourhoodOnlineAgents($perspectiveUUID: String!) {
|
|
93
|
+
neighbourhoodOnlineAgents(perspectiveUUID: $perspectiveUUID) {
|
|
94
|
+
did
|
|
95
|
+
status {
|
|
96
|
+
author
|
|
97
|
+
timestamp
|
|
98
|
+
data {
|
|
99
|
+
links {
|
|
100
|
+
author
|
|
101
|
+
timestamp
|
|
102
|
+
data { source, predicate, target }
|
|
103
|
+
proof { valid, invalid, signature, key }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
proof { valid, invalid, signature, key }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}`,
|
|
110
|
+
variables: { perspectiveUUID }
|
|
111
|
+
}))
|
|
112
|
+
return neighbourhoodOnlineAgents
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async setOnlineStatus(perspectiveUUID: string, status: Perspective): Promise<boolean> {
|
|
116
|
+
const { neighbourhoodSetOnlineStatus } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
117
|
+
mutation: gql`mutation neighbourhoodSetOnlineStatus(
|
|
118
|
+
$perspectiveUUID: String!,
|
|
119
|
+
$status: PerspectiveInput!
|
|
120
|
+
) {
|
|
121
|
+
neighbourhoodSetOnlineStatus(
|
|
122
|
+
perspectiveUUID: $perspectiveUUID,
|
|
123
|
+
status: $status
|
|
124
|
+
)
|
|
125
|
+
}`,
|
|
126
|
+
variables: { perspectiveUUID, status }
|
|
127
|
+
}))
|
|
128
|
+
|
|
129
|
+
return neighbourhoodSetOnlineStatus
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async setOnlineStatusU(perspectiveUUID: string, status: PerspectiveUnsignedInput): Promise<boolean> {
|
|
133
|
+
const { neighbourhoodSetOnlineStatusU } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
134
|
+
mutation: gql`mutation neighbourhoodSetOnlineStatusU(
|
|
135
|
+
$perspectiveUUID: String!,
|
|
136
|
+
$status: PerspectiveUnsignedInput!
|
|
137
|
+
) {
|
|
138
|
+
neighbourhoodSetOnlineStatusU(
|
|
139
|
+
perspectiveUUID: $perspectiveUUID,
|
|
140
|
+
status: $status
|
|
141
|
+
)
|
|
142
|
+
}`,
|
|
143
|
+
variables: { perspectiveUUID, status }
|
|
144
|
+
}))
|
|
145
|
+
|
|
146
|
+
return neighbourhoodSetOnlineStatusU
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async sendSignal(perspectiveUUID: string, remoteAgentDid: string, payload: Perspective): Promise<boolean> {
|
|
150
|
+
const { neighbourhoodSendSignal } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
151
|
+
mutation: gql`mutation neighbourhoodSendSignal(
|
|
152
|
+
$perspectiveUUID: String!,
|
|
153
|
+
$remoteAgentDid: String!,
|
|
154
|
+
$payload: PerspectiveInput!
|
|
155
|
+
) {
|
|
156
|
+
neighbourhoodSendSignal(
|
|
157
|
+
perspectiveUUID: $perspectiveUUID,
|
|
158
|
+
remoteAgentDid: $remoteAgentDid,
|
|
159
|
+
payload: $payload
|
|
160
|
+
)
|
|
161
|
+
}`,
|
|
162
|
+
variables: { perspectiveUUID, remoteAgentDid, payload }
|
|
163
|
+
}))
|
|
164
|
+
|
|
165
|
+
return neighbourhoodSendSignal
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async sendSignalU(perspectiveUUID: string, remoteAgentDid: string, payload: PerspectiveUnsignedInput): Promise<boolean> {
|
|
169
|
+
const { neighbourhoodSendSignalU } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
170
|
+
mutation: gql`mutation neighbourhoodSendSignalU(
|
|
171
|
+
$perspectiveUUID: String!,
|
|
172
|
+
$remoteAgentDid: String!,
|
|
173
|
+
$payload: PerspectiveUnsignedInput!
|
|
174
|
+
) {
|
|
175
|
+
neighbourhoodSendSignalU(
|
|
176
|
+
perspectiveUUID: $perspectiveUUID,
|
|
177
|
+
remoteAgentDid: $remoteAgentDid,
|
|
178
|
+
payload: $payload
|
|
179
|
+
)
|
|
180
|
+
}`,
|
|
181
|
+
variables: { perspectiveUUID, remoteAgentDid, payload }
|
|
182
|
+
}))
|
|
183
|
+
|
|
184
|
+
return neighbourhoodSendSignalU
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async sendBroadcast(perspectiveUUID: string, payload: Perspective): Promise<boolean> {
|
|
188
|
+
const { neighbourhoodSendBroadcast } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
189
|
+
mutation: gql`mutation neighbourhoodSendBroadcast(
|
|
190
|
+
$perspectiveUUID: String!,
|
|
191
|
+
$payload: PerspectiveInput!
|
|
192
|
+
) {
|
|
193
|
+
neighbourhoodSendBroadcast(
|
|
194
|
+
perspectiveUUID: $perspectiveUUID,
|
|
195
|
+
payload: $payload
|
|
196
|
+
)
|
|
197
|
+
}`,
|
|
198
|
+
variables: { perspectiveUUID, payload }
|
|
199
|
+
}))
|
|
200
|
+
|
|
201
|
+
return neighbourhoodSendBroadcast
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async sendBroadcastU(perspectiveUUID: string, payload: PerspectiveUnsignedInput): Promise<boolean> {
|
|
205
|
+
const { neighbourhoodSendBroadcastU } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
206
|
+
mutation: gql`mutation neighbourhoodSendBroadcastU(
|
|
207
|
+
$perspectiveUUID: String!,
|
|
208
|
+
$payload: PerspectiveUnsignedInput!
|
|
209
|
+
) {
|
|
210
|
+
neighbourhoodSendBroadcastU(
|
|
211
|
+
perspectiveUUID: $perspectiveUUID,
|
|
212
|
+
payload: $payload
|
|
213
|
+
)
|
|
214
|
+
}`,
|
|
215
|
+
variables: { perspectiveUUID, payload }
|
|
216
|
+
}))
|
|
217
|
+
|
|
218
|
+
return neighbourhoodSendBroadcastU
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
dispatchSignal(perspectiveUUID:string, signal: any) {
|
|
222
|
+
const handlers = this.#signalHandlers.get(perspectiveUUID)
|
|
223
|
+
if (handlers) {
|
|
224
|
+
handlers.forEach(handler => handler(signal))
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async subscribeToSignals(perspectiveUUID: string): Promise<void> {
|
|
229
|
+
const that = this
|
|
230
|
+
await this.#apolloClient.subscribe({
|
|
231
|
+
query: gql`subscription neighbourhoodSignal($perspectiveUUID: String!) {
|
|
232
|
+
neighbourhoodSignal(perspectiveUUID: $perspectiveUUID) {
|
|
233
|
+
author
|
|
234
|
+
timestamp
|
|
235
|
+
data {
|
|
236
|
+
links
|
|
237
|
+
{
|
|
238
|
+
author
|
|
239
|
+
timestamp
|
|
240
|
+
data { source, predicate, target }
|
|
241
|
+
proof { valid, invalid, signature, key }
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
proof { valid, invalid, signature, key }
|
|
245
|
+
}
|
|
246
|
+
}`,
|
|
247
|
+
variables: { perspectiveUUID }
|
|
248
|
+
}).subscribe({
|
|
249
|
+
next: (result: ApolloQueryResult<any>) => {
|
|
250
|
+
const { neighbourhoodSignal } = unwrapApolloResult(result)
|
|
251
|
+
that.dispatchSignal(perspectiveUUID, neighbourhoodSignal)
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
async addSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): Promise<void> {
|
|
257
|
+
let handlersForPerspective = this.#signalHandlers.get(perspectiveUUID)
|
|
258
|
+
if (!handlersForPerspective) {
|
|
259
|
+
handlersForPerspective = []
|
|
260
|
+
await this.subscribeToSignals(perspectiveUUID)
|
|
261
|
+
}
|
|
262
|
+
handlersForPerspective.push(handler)
|
|
263
|
+
this.#signalHandlers.set(perspectiveUUID, handlersForPerspective)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
removeSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): void {
|
|
267
|
+
const handlersForPerspective = this.#signalHandlers.get(perspectiveUUID)
|
|
268
|
+
if (handlersForPerspective) {
|
|
269
|
+
const index = handlersForPerspective.indexOf(handler)
|
|
270
|
+
if (index > -1) {
|
|
271
|
+
handlersForPerspective.splice(index, 1)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
this.#signalHandlers.set(perspectiveUUID, handlersForPerspective)
|
|
275
|
+
}
|
|
276
276
|
}
|