@coasys/ad4m 0.12.0-rc1-dev.2 → 0.12.0-rc1-dev.3
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/jest.config.js +10 -3
- package/lib/index.cjs +6872 -5886
- package/lib/index.js +6868 -5874
- package/lib/src/Ad4mClient.d.ts +9 -16
- package/lib/src/Ad4mClient.js +46 -25
- package/lib/src/Literal.d.ts +1 -2
- package/lib/src/Literal.js +38 -35
- package/lib/src/SmartLiteral.d.ts +1 -2
- package/lib/src/SmartLiteral.js +30 -15
- package/lib/src/agent/AgentClient.d.ts +1 -4
- package/lib/src/agent/AgentClient.js +79 -99
- package/lib/src/ai/AIClient.d.ts +1 -2
- package/lib/src/ai/AIClient.js +224 -220
- package/lib/src/expression/ExpressionClient.d.ts +1 -1
- package/lib/src/expression/ExpressionClient.js +73 -86
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/language/LanguageClient.d.ts +1 -1
- package/lib/src/language/LanguageClient.js +52 -52
- package/lib/src/model/Ad4mModel.d.ts +1351 -144
- package/lib/src/model/Ad4mModel.js +3737 -228
- package/lib/src/model/Ad4mModel.test.js +522 -979
- package/lib/src/model/Subject.d.ts +3 -3
- package/lib/src/model/Subject.js +25 -25
- package/lib/src/model/decorators.d.ts +444 -100
- package/lib/src/model/decorators.js +686 -321
- package/lib/src/model/util.d.ts +6 -6
- package/lib/src/model/util.js +24 -24
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +1 -5
- package/lib/src/neighbourhood/NeighbourhoodClient.js +179 -242
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +1 -2
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +28 -13
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +5 -1
- package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveClient.js +240 -316
- package/lib/src/perspectives/PerspectiveProxy.d.ts +99 -61
- package/lib/src/perspectives/PerspectiveProxy.js +485 -832
- package/lib/src/runtime/RuntimeClient.d.ts +1 -5
- package/lib/src/runtime/RuntimeClient.js +238 -412
- package/lib/src/shacl/SHACLFlow.test.js +105 -164
- package/lib/src/shacl/SHACLShape.d.ts +12 -17
- package/lib/src/shacl/SHACLShape.js +115 -128
- package/lib/src/shacl/SHACLShape.test.js +176 -244
- package/lib/src/shims/reflect-metadata.d.ts +0 -0
- package/lib/src/shims/type-graphql.d.ts +32 -0
- package/lib/src/src/Ad4mClient.d.ts +28 -0
- package/lib/src/src/Address.d.ts +1 -0
- package/lib/src/src/DID.d.ts +1 -0
- package/lib/src/src/Exception.d.ts +7 -0
- package/lib/src/src/Literal.d.ts +7 -0
- package/lib/src/src/PubSub.d.ts +17 -0
- package/lib/src/src/SmartLiteral.d.ts +12 -0
- package/lib/src/src/agent/Agent.d.ts +110 -0
- package/lib/src/src/agent/AgentClient.d.ts +62 -0
- package/lib/src/src/agent/AgentResolver.d.ts +30 -0
- package/lib/src/src/agent/AgentStatus.d.ts +8 -0
- package/lib/src/src/ai/AIClient.d.ts +32 -0
- package/lib/src/src/ai/AIResolver.d.ts +75 -0
- package/lib/src/src/ai/Tasks.d.ts +37 -0
- package/lib/src/src/buildSchema.d.ts +1 -0
- package/lib/src/src/expression/Expression.d.ts +28 -0
- package/lib/src/src/expression/ExpressionClient.d.ts +13 -0
- package/lib/src/src/expression/ExpressionRef.d.ts +9 -0
- package/lib/src/src/expression/ExpressionResolver.d.ts +10 -0
- package/lib/src/src/index.d.ts +35 -0
- package/lib/src/src/jestSetup.d.ts +1 -0
- package/lib/src/src/language/Icon.d.ts +4 -0
- package/lib/src/src/language/Language.d.ts +206 -0
- package/lib/src/src/language/LanguageClient.d.ts +17 -0
- package/lib/src/src/language/LanguageContext.d.ts +37 -0
- package/lib/src/src/language/LanguageHandle.d.ts +9 -0
- package/lib/src/src/language/LanguageMeta.d.ts +35 -0
- package/lib/src/src/language/LanguageRef.d.ts +6 -0
- package/lib/src/src/language/LanguageResolver.d.ts +19 -0
- package/lib/src/src/links/Links.d.ts +39 -0
- package/lib/src/src/links/Links.test.d.ts +1 -0
- package/lib/src/src/model/Ad4mModel.d.ts +1438 -0
- package/lib/src/src/model/Ad4mModel.test.d.ts +1 -0
- package/lib/src/src/model/Subject.d.ts +25 -0
- package/lib/src/src/model/decorators.d.ts +545 -0
- package/lib/src/src/model/util.d.ts +12 -0
- package/lib/src/src/neighbourhood/Neighbourhood.d.ts +10 -0
- package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
- package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
- package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
- package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
- package/lib/src/src/perspectives/LinkQuery.d.ts +11 -0
- package/lib/src/src/perspectives/Perspective.d.ts +38 -0
- package/lib/src/src/perspectives/Perspective.test.d.ts +1 -0
- package/lib/src/src/perspectives/PerspectiveClient.d.ts +97 -0
- package/lib/src/src/perspectives/PerspectiveDiff.d.ts +9 -0
- package/lib/src/src/perspectives/PerspectiveHandle.d.ts +18 -0
- package/lib/src/src/perspectives/PerspectiveProxy.d.ts +865 -0
- package/lib/src/src/perspectives/PerspectiveResolver.d.ts +57 -0
- package/lib/src/src/runtime/RuntimeClient.d.ts +56 -0
- package/lib/src/src/runtime/RuntimeResolver.d.ts +132 -0
- package/lib/src/src/shacl/SHACLFlow.d.ts +171 -0
- package/lib/src/src/shacl/SHACLFlow.test.d.ts +1 -0
- package/lib/src/src/shacl/SHACLShape.d.ts +117 -0
- package/lib/src/src/shacl/SHACLShape.test.d.ts +1 -0
- package/lib/src/src/typeDefs.d.ts +1 -0
- package/lib/src/src/unwrapApolloResult.d.ts +2 -0
- package/lib/src/src/utils.d.ts +25 -0
- package/lib/src/utils.d.ts +0 -8
- package/lib/src/utils.js +7 -21
- package/package.json +15 -14
- package/src/Ad4mClient.test.ts +1315 -1564
- package/src/Ad4mClient.ts +54 -55
- package/src/Literal.test.ts +26 -45
- package/src/Literal.ts +66 -82
- package/src/SmartLiteral.ts +58 -74
- package/src/agent/AgentClient.ts +99 -144
- package/src/ai/AIClient.ts +359 -409
- package/src/expression/ExpressionClient.ts +96 -142
- package/src/index.ts +1 -1
- package/src/language/LanguageClient.ts +113 -137
- package/src/model/Ad4mModel.test.ts +616 -1114
- package/src/model/Ad4mModel.ts +4361 -451
- package/src/model/Subject.ts +159 -0
- package/src/model/decorators.ts +1168 -667
- package/src/model/util.ts +54 -53
- package/src/neighbourhood/NeighbourhoodClient.ts +266 -392
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +7 -3
- package/src/neighbourhood/NeighbourhoodProxy.ts +40 -58
- package/src/perspectives/PerspectiveClient.ts +540 -779
- package/src/perspectives/PerspectiveProxy.ts +2067 -2860
- package/src/runtime/RuntimeClient.ts +476 -775
- package/src/shacl/SHACLFlow.test.ts +129 -196
- package/src/shacl/SHACLShape.test.ts +190 -284
- package/src/shacl/SHACLShape.ts +200 -224
- package/src/utils.ts +17 -31
- package/tsconfig.json +10 -9
- package/src/model/IMPROVEMENTS.md +0 -482
- package/src/model/PREDICATE_COLLISION_FIX.md +0 -651
- package/src/model/README.md +0 -317
- package/src/model/SHACL_MUTATION_DECOUPLING.md +0 -356
- package/src/model/SUBSCRIPTION_STRATEGY.md +0 -317
- package/src/model/TC39_STAGE_3_DECORATORS.md +0 -609
- package/src/model/mutation.ts +0 -461
- package/src/model/parentUtils.ts +0 -91
- package/src/model/prolog/generatePrologFacts.ts +0 -176
- package/src/model/prolog/index.ts +0 -1
- package/src/model/query/ModelQueryBuilder.ts +0 -173
- package/src/model/query/fetchInstance.ts +0 -181
- package/src/model/query/hydration.ts +0 -273
- package/src/model/query/operations.ts +0 -510
- package/src/model/query/snapshot.ts +0 -126
- package/src/model/query/surrealCompiler.ts +0 -376
- package/src/model/schema/fromJSONSchema.ts +0 -411
- package/src/model/schema/metadata.ts +0 -148
- package/src/model/subscription.ts +0 -307
- package/src/model/transaction.ts +0 -60
- package/src/model/types.ts +0 -207
|
@@ -1,421 +1,295 @@
|
|
|
1
|
-
import { ApolloClient, gql, FetchResult } from "@apollo/client/core"
|
|
2
|
-
import { Address } from "../Address"
|
|
3
|
-
import { DID } from "../DID"
|
|
4
|
-
import { OnlineAgent, TelepresenceSignalCallback } from "../language/Language"
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "
|
|
9
|
-
import { PerspectiveHandle } from "../perspectives/PerspectiveHandle";
|
|
10
|
-
import unwrapApolloResult from "../unwrapApolloResult";
|
|
11
|
-
import { isSocketCloseError } from "../utils";
|
|
1
|
+
import { ApolloClient, gql, FetchResult } 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"
|
|
12
9
|
|
|
13
10
|
export class NeighbourhoodClient {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
new Map();
|
|
17
|
-
private _signalSubscriptions: Map<string, { unsubscribe(): void }> =
|
|
18
|
-
new Map();
|
|
11
|
+
#apolloClient: ApolloClient<any>
|
|
12
|
+
#signalHandlers: Map<string, TelepresenceSignalCallback[]> = new Map()
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
constructor(client: ApolloClient<any>) {
|
|
15
|
+
this.#apolloClient = client
|
|
16
|
+
}
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}),
|
|
46
|
-
);
|
|
47
|
-
return neighbourhoodPublishFromPerspective;
|
|
48
|
-
}
|
|
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
|
+
}
|
|
49
39
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
proof {
|
|
73
|
-
valid
|
|
74
|
-
invalid
|
|
75
|
-
signature
|
|
76
|
-
key
|
|
77
|
-
}
|
|
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
|
|
78
62
|
}
|
|
79
|
-
}
|
|
80
63
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
variables: { url },
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
89
|
-
return neighbourhoodJoinFromUrl;
|
|
90
|
-
}
|
|
64
|
+
}`,
|
|
65
|
+
variables: { url }
|
|
66
|
+
}))
|
|
67
|
+
return neighbourhoodJoinFromUrl
|
|
68
|
+
}
|
|
91
69
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
return neighbourhoodOtherAgents;
|
|
104
|
-
}
|
|
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
|
+
}
|
|
105
79
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`,
|
|
116
|
-
variables: { perspectiveUUID },
|
|
117
|
-
}),
|
|
118
|
-
);
|
|
119
|
-
return neighbourhoodHasTelepresenceAdapter;
|
|
120
|
-
}
|
|
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
|
+
}
|
|
121
89
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
target
|
|
140
|
-
}
|
|
141
|
-
proof {
|
|
142
|
-
valid
|
|
143
|
-
invalid
|
|
144
|
-
signature
|
|
145
|
-
key
|
|
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 }
|
|
146
107
|
}
|
|
147
|
-
}
|
|
148
108
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
`,
|
|
159
|
-
variables: { perspectiveUUID },
|
|
160
|
-
}),
|
|
161
|
-
);
|
|
162
|
-
return neighbourhoodOnlineAgents;
|
|
163
|
-
}
|
|
109
|
+
}`,
|
|
110
|
+
variables: { perspectiveUUID }
|
|
111
|
+
}))
|
|
112
|
+
return neighbourhoodOnlineAgents
|
|
113
|
+
}
|
|
164
114
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
status: $status
|
|
179
|
-
)
|
|
180
|
-
}
|
|
181
|
-
`,
|
|
182
|
-
variables: { perspectiveUUID, status },
|
|
183
|
-
}),
|
|
184
|
-
);
|
|
185
|
-
return neighbourhoodSetOnlineStatus;
|
|
186
|
-
}
|
|
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
|
+
}))
|
|
187
128
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
status: PerspectiveUnsignedInput,
|
|
191
|
-
): Promise<boolean> {
|
|
192
|
-
const { neighbourhoodSetOnlineStatusU } = unwrapApolloResult(
|
|
193
|
-
await this._apolloClient.mutate({
|
|
194
|
-
mutation: gql`
|
|
195
|
-
mutation neighbourhoodSetOnlineStatusU(
|
|
196
|
-
$perspectiveUUID: String!
|
|
197
|
-
$status: PerspectiveUnsignedInput!
|
|
198
|
-
) {
|
|
199
|
-
neighbourhoodSetOnlineStatusU(
|
|
200
|
-
perspectiveUUID: $perspectiveUUID
|
|
201
|
-
status: $status
|
|
202
|
-
)
|
|
203
|
-
}
|
|
204
|
-
`,
|
|
205
|
-
variables: { perspectiveUUID, status },
|
|
206
|
-
}),
|
|
207
|
-
);
|
|
208
|
-
return neighbourhoodSetOnlineStatusU;
|
|
209
|
-
}
|
|
129
|
+
return neighbourhoodSetOnlineStatus
|
|
130
|
+
}
|
|
210
131
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
neighbourhoodSendSignal(
|
|
225
|
-
perspectiveUUID: $perspectiveUUID
|
|
226
|
-
remoteAgentDid: $remoteAgentDid
|
|
227
|
-
payload: $payload
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
`,
|
|
231
|
-
variables: { perspectiveUUID, remoteAgentDid, payload },
|
|
232
|
-
}),
|
|
233
|
-
);
|
|
234
|
-
return neighbourhoodSendSignal;
|
|
235
|
-
}
|
|
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
|
+
}))
|
|
236
145
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
remoteAgentDid: string,
|
|
240
|
-
payload: PerspectiveUnsignedInput,
|
|
241
|
-
): Promise<boolean> {
|
|
242
|
-
const { neighbourhoodSendSignalU } = unwrapApolloResult(
|
|
243
|
-
await this._apolloClient.mutate({
|
|
244
|
-
mutation: gql`
|
|
245
|
-
mutation neighbourhoodSendSignalU(
|
|
246
|
-
$perspectiveUUID: String!
|
|
247
|
-
$remoteAgentDid: String!
|
|
248
|
-
$payload: PerspectiveUnsignedInput!
|
|
249
|
-
) {
|
|
250
|
-
neighbourhoodSendSignalU(
|
|
251
|
-
perspectiveUUID: $perspectiveUUID
|
|
252
|
-
remoteAgentDid: $remoteAgentDid
|
|
253
|
-
payload: $payload
|
|
254
|
-
)
|
|
255
|
-
}
|
|
256
|
-
`,
|
|
257
|
-
variables: { perspectiveUUID, remoteAgentDid, payload },
|
|
258
|
-
}),
|
|
259
|
-
);
|
|
260
|
-
return neighbourhoodSendSignalU;
|
|
261
|
-
}
|
|
146
|
+
return neighbourhoodSetOnlineStatusU
|
|
147
|
+
}
|
|
262
148
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
payload: $payload
|
|
279
|
-
loopback: $loopback
|
|
280
|
-
)
|
|
281
|
-
}
|
|
282
|
-
`,
|
|
283
|
-
variables: { perspectiveUUID, payload, loopback },
|
|
284
|
-
}),
|
|
285
|
-
);
|
|
286
|
-
return neighbourhoodSendBroadcast;
|
|
287
|
-
}
|
|
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
|
+
}))
|
|
288
164
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
payload: PerspectiveUnsignedInput,
|
|
292
|
-
loopback: boolean = false,
|
|
293
|
-
): Promise<boolean> {
|
|
294
|
-
const { neighbourhoodSendBroadcastU } = unwrapApolloResult(
|
|
295
|
-
await this._apolloClient.mutate({
|
|
296
|
-
mutation: gql`
|
|
297
|
-
mutation neighbourhoodSendBroadcastU(
|
|
298
|
-
$perspectiveUUID: String!
|
|
299
|
-
$payload: PerspectiveUnsignedInput!
|
|
300
|
-
$loopback: Boolean
|
|
301
|
-
) {
|
|
302
|
-
neighbourhoodSendBroadcastU(
|
|
303
|
-
perspectiveUUID: $perspectiveUUID
|
|
304
|
-
payload: $payload
|
|
305
|
-
loopback: $loopback
|
|
306
|
-
)
|
|
307
|
-
}
|
|
308
|
-
`,
|
|
309
|
-
variables: { perspectiveUUID, payload, loopback },
|
|
310
|
-
}),
|
|
311
|
-
);
|
|
312
|
-
return neighbourhoodSendBroadcastU;
|
|
313
|
-
}
|
|
165
|
+
return neighbourhoodSendSignal
|
|
166
|
+
}
|
|
314
167
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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
|
|
325
185
|
}
|
|
326
|
-
}
|
|
327
186
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
187
|
+
async sendBroadcast(perspectiveUUID: string, payload: Perspective, loopback: boolean = false): Promise<boolean> {
|
|
188
|
+
const { neighbourhoodSendBroadcast } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
189
|
+
mutation: gql`mutation neighbourhoodSendBroadcast(
|
|
190
|
+
$perspectiveUUID: String!,
|
|
191
|
+
$payload: PerspectiveInput!,
|
|
192
|
+
$loopback: Boolean
|
|
193
|
+
) {
|
|
194
|
+
neighbourhoodSendBroadcast(
|
|
195
|
+
perspectiveUUID: $perspectiveUUID,
|
|
196
|
+
payload: $payload,
|
|
197
|
+
loopback: $loopback
|
|
198
|
+
)
|
|
199
|
+
}`,
|
|
200
|
+
variables: { perspectiveUUID, payload, loopback }
|
|
201
|
+
}))
|
|
202
|
+
|
|
203
|
+
return neighbourhoodSendBroadcast
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async sendBroadcastU(perspectiveUUID: string, payload: PerspectiveUnsignedInput, loopback: boolean = false): Promise<boolean> {
|
|
207
|
+
const { neighbourhoodSendBroadcastU } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
208
|
+
mutation: gql`mutation neighbourhoodSendBroadcastU(
|
|
209
|
+
$perspectiveUUID: String!,
|
|
210
|
+
$payload: PerspectiveUnsignedInput!,
|
|
211
|
+
$loopback: Boolean
|
|
212
|
+
) {
|
|
213
|
+
neighbourhoodSendBroadcastU(
|
|
214
|
+
perspectiveUUID: $perspectiveUUID,
|
|
215
|
+
payload: $payload,
|
|
216
|
+
loopback: $loopback
|
|
217
|
+
)
|
|
218
|
+
}`,
|
|
219
|
+
variables: { perspectiveUUID, payload, loopback }
|
|
220
|
+
}))
|
|
221
|
+
|
|
222
|
+
return neighbourhoodSendBroadcastU
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
dispatchSignal(perspectiveUUID:string, signal: any) {
|
|
226
|
+
const handlers = this.#signalHandlers.get(perspectiveUUID)
|
|
227
|
+
if (handlers) {
|
|
228
|
+
for (const handler of handlers) {
|
|
229
|
+
try {
|
|
230
|
+
handler(signal)
|
|
231
|
+
} catch(e) {
|
|
232
|
+
console.error("Error in signal handler:", e)
|
|
352
233
|
}
|
|
353
|
-
}
|
|
354
|
-
proof {
|
|
355
|
-
valid
|
|
356
|
-
invalid
|
|
357
|
-
signature
|
|
358
|
-
key
|
|
359
|
-
}
|
|
360
234
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
variables: { perspectiveUUID },
|
|
364
|
-
})
|
|
365
|
-
.subscribe({
|
|
366
|
-
next: (result: FetchResult<any>) => {
|
|
367
|
-
try {
|
|
368
|
-
const { neighbourhoodSignal } = unwrapApolloResult(result);
|
|
369
|
-
that.dispatchSignal(perspectiveUUID, neighbourhoodSignal);
|
|
370
|
-
} catch (e) {
|
|
371
|
-
console.error("Error in signal subscription:", e);
|
|
372
|
-
}
|
|
373
|
-
},
|
|
374
|
-
error: (e) => {
|
|
375
|
-
if (!isSocketCloseError(e))
|
|
376
|
-
console.error("neighbourhoodSignal subscription error:", e);
|
|
377
|
-
},
|
|
378
|
-
});
|
|
379
|
-
this._signalSubscriptions.set(perspectiveUUID, sub);
|
|
380
|
-
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
381
237
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
238
|
+
async subscribeToSignals(perspectiveUUID: string): Promise<void> {
|
|
239
|
+
const that = this
|
|
240
|
+
this.#apolloClient.subscribe({
|
|
241
|
+
query: gql`subscription neighbourhoodSignal($perspectiveUUID: String!) {
|
|
242
|
+
neighbourhoodSignal(perspectiveUUID: $perspectiveUUID) {
|
|
243
|
+
author
|
|
244
|
+
timestamp
|
|
245
|
+
data {
|
|
246
|
+
links
|
|
247
|
+
{
|
|
248
|
+
author
|
|
249
|
+
timestamp
|
|
250
|
+
data { source, predicate, target }
|
|
251
|
+
proof { valid, invalid, signature, key }
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
proof { valid, invalid, signature, key }
|
|
255
|
+
}
|
|
256
|
+
}`,
|
|
257
|
+
variables: { perspectiveUUID }
|
|
258
|
+
}).subscribe({
|
|
259
|
+
next: (result: FetchResult<any>) => {
|
|
260
|
+
try {
|
|
261
|
+
const { neighbourhoodSignal } = unwrapApolloResult(result)
|
|
262
|
+
that.dispatchSignal(perspectiveUUID, neighbourhoodSignal)
|
|
263
|
+
} catch(e) {
|
|
264
|
+
console.error("Error in signal subscription:", e)
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
error: (err: any) => {
|
|
268
|
+
console.error("Signal subscription error for perspective", perspectiveUUID, err)
|
|
269
|
+
}
|
|
270
|
+
})
|
|
395
271
|
}
|
|
396
|
-
}
|
|
397
272
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
// even when the array becomes empty. This prevents an unnecessary re-subscription
|
|
410
|
-
// if a new handler is added shortly after (the empty array makes addSignalHandler
|
|
411
|
-
// skip subscribeToSignals). For explicit teardown use unsubscribeFromPerspective().
|
|
273
|
+
async addSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): Promise<void> {
|
|
274
|
+
let handlersForPerspective = this.#signalHandlers.get(perspectiveUUID)
|
|
275
|
+
if (!handlersForPerspective) {
|
|
276
|
+
handlersForPerspective = []
|
|
277
|
+
this.#signalHandlers.set(perspectiveUUID, handlersForPerspective)
|
|
278
|
+
// Push handler BEFORE subscribing so it's available when signals arrive
|
|
279
|
+
handlersForPerspective.push(handler)
|
|
280
|
+
await this.subscribeToSignals(perspectiveUUID)
|
|
281
|
+
} else {
|
|
282
|
+
handlersForPerspective.push(handler)
|
|
283
|
+
}
|
|
412
284
|
}
|
|
413
|
-
}
|
|
414
285
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
286
|
+
removeSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): void {
|
|
287
|
+
const handlersForPerspective = this.#signalHandlers.get(perspectiveUUID)
|
|
288
|
+
if (handlersForPerspective) {
|
|
289
|
+
const index = handlersForPerspective.indexOf(handler)
|
|
290
|
+
if (index > -1) {
|
|
291
|
+
handlersForPerspective.splice(index, 1)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
421
295
|
}
|