@coasys/ad4m 0.12.0-rc1-dev → 0.12.0-rc1-dev.2
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 +4 -4
- package/lib/index.cjs +5999 -6044
- package/lib/index.js +5977 -6038
- package/lib/src/Ad4mClient.d.ts +16 -9
- package/lib/src/Ad4mClient.js +25 -46
- package/lib/src/Ad4mClient.test.d.ts +1 -0
- package/lib/src/Ad4mClient.test.js +1204 -0
- package/lib/src/Literal.d.ts +2 -1
- package/lib/src/Literal.js +35 -38
- package/lib/src/Literal.test.d.ts +1 -0
- package/lib/src/Literal.test.js +41 -0
- package/lib/src/SmartLiteral.d.ts +2 -1
- package/lib/src/SmartLiteral.js +15 -30
- package/lib/src/agent/AgentClient.d.ts +4 -1
- package/lib/src/agent/AgentClient.js +99 -79
- package/lib/src/ai/AIClient.d.ts +2 -1
- package/lib/src/ai/AIClient.js +220 -224
- package/lib/src/expression/ExpressionClient.d.ts +1 -1
- package/lib/src/expression/ExpressionClient.js +86 -73
- 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 +157 -937
- package/lib/src/model/Ad4mModel.js +212 -2797
- package/lib/src/model/Ad4mModel.test.js +1002 -561
- package/lib/src/model/decorators.d.ts +94 -426
- package/lib/src/model/decorators.js +333 -741
- package/lib/src/model/mutation.d.ts +81 -0
- package/lib/src/model/mutation.js +317 -0
- package/lib/src/model/parentUtils.d.ts +32 -0
- package/lib/src/model/parentUtils.js +64 -0
- package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
- package/lib/src/model/prolog/generatePrologFacts.js +139 -0
- package/lib/src/model/prolog/index.d.ts +1 -0
- package/lib/src/model/prolog/index.js +1 -0
- package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
- package/lib/src/model/query/ModelQueryBuilder.js +115 -0
- package/lib/src/model/query/QueryBuilder.d.ts +101 -0
- package/lib/src/model/query/QueryBuilder.js +193 -0
- package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
- package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
- package/lib/src/model/query/fetchInstance.d.ts +24 -0
- package/lib/src/model/query/fetchInstance.js +144 -0
- package/lib/src/model/query/hydration.d.ts +54 -0
- package/lib/src/model/query/hydration.js +214 -0
- package/lib/src/model/query/operations.d.ts +59 -0
- package/lib/src/model/query/operations.js +384 -0
- package/lib/src/model/query/snapshot.d.ts +59 -0
- package/lib/src/model/query/snapshot.js +106 -0
- package/lib/src/model/query/surrealCompiler.d.ts +42 -0
- package/lib/src/model/query/surrealCompiler.js +304 -0
- package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
- package/lib/src/model/schema/fromJSONSchema.js +264 -0
- package/lib/src/model/schema/metadata.d.ts +15 -0
- package/lib/src/model/schema/metadata.js +112 -0
- package/lib/src/model/subscription.d.ts +47 -0
- package/lib/src/model/subscription.js +231 -0
- package/lib/src/model/transaction.d.ts +27 -0
- package/lib/src/model/transaction.js +32 -0
- package/lib/src/model/types.d.ts +195 -0
- package/lib/src/model/types.js +8 -0
- package/lib/src/model/util.js +7 -7
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +5 -1
- package/lib/src/neighbourhood/NeighbourhoodClient.js +263 -181
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -1
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +13 -28
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +1 -5
- package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveClient.js +316 -240
- package/lib/src/perspectives/PerspectiveProxy.d.ts +54 -92
- package/lib/src/perspectives/PerspectiveProxy.js +803 -444
- package/lib/src/runtime/RuntimeClient.d.ts +5 -1
- package/lib/src/runtime/RuntimeClient.js +412 -238
- package/lib/src/shacl/SHACLFlow.test.js +164 -105
- package/lib/src/shacl/SHACLShape.d.ts +17 -3
- package/lib/src/shacl/SHACLShape.js +127 -90
- package/lib/src/shacl/SHACLShape.test.js +244 -176
- package/lib/src/utils.d.ts +8 -0
- package/lib/src/utils.js +21 -7
- package/package.json +8 -13
- package/src/Ad4mClient.test.ts +1564 -1315
- package/src/Ad4mClient.ts +55 -54
- package/src/Literal.test.ts +45 -26
- package/src/Literal.ts +82 -66
- package/src/SmartLiteral.ts +74 -58
- package/src/agent/AgentClient.ts +144 -99
- package/src/ai/AIClient.ts +409 -359
- package/src/expression/ExpressionClient.ts +142 -96
- package/src/index.ts +1 -1
- package/src/language/LanguageClient.ts +137 -113
- package/src/model/Ad4mModel.test.ts +1128 -647
- package/src/model/Ad4mModel.ts +485 -3247
- package/src/model/IMPROVEMENTS.md +482 -0
- package/src/model/PREDICATE_COLLISION_FIX.md +651 -0
- package/src/model/README.md +317 -0
- package/src/model/SHACL_MUTATION_DECOUPLING.md +356 -0
- package/src/model/SUBSCRIPTION_STRATEGY.md +317 -0
- package/src/model/TC39_STAGE_3_DECORATORS.md +609 -0
- package/src/model/decorators.ts +689 -1046
- package/src/model/mutation.ts +461 -0
- package/src/model/parentUtils.ts +91 -0
- package/src/model/prolog/generatePrologFacts.ts +176 -0
- package/src/model/prolog/index.ts +1 -0
- package/src/model/query/ModelQueryBuilder.ts +173 -0
- package/src/model/query/fetchInstance.ts +181 -0
- package/src/model/query/hydration.ts +273 -0
- package/src/model/query/operations.ts +510 -0
- package/src/model/query/snapshot.ts +126 -0
- package/src/model/query/surrealCompiler.ts +376 -0
- package/src/model/schema/fromJSONSchema.ts +411 -0
- package/src/model/schema/metadata.ts +148 -0
- package/src/model/subscription.ts +307 -0
- package/src/model/transaction.ts +60 -0
- package/src/model/types.ts +207 -0
- package/src/model/util.ts +47 -48
- package/src/neighbourhood/NeighbourhoodClient.ts +393 -251
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +3 -7
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -40
- package/src/perspectives/PerspectiveClient.ts +779 -540
- package/src/perspectives/PerspectiveProxy.ts +2860 -2053
- package/src/runtime/RuntimeClient.ts +775 -476
- package/src/shacl/SHACLFlow.test.ts +196 -129
- package/src/shacl/SHACLShape.test.ts +284 -190
- package/src/shacl/SHACLShape.ts +225 -172
- package/src/utils.ts +31 -17
- package/tsconfig.json +9 -10
- package/src/model/Subject.ts +0 -159
|
@@ -1,279 +1,421 @@
|
|
|
1
|
-
import { ApolloClient,
|
|
2
|
-
import { Address } from "../Address"
|
|
3
|
-
import { DID } from "../DID"
|
|
4
|
-
import { OnlineAgent, TelepresenceSignalCallback } from "../language/Language"
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
Perspective,
|
|
7
|
+
PerspectiveUnsignedInput,
|
|
8
|
+
} from "../perspectives/Perspective";
|
|
9
|
+
import { PerspectiveHandle } from "../perspectives/PerspectiveHandle";
|
|
10
|
+
import unwrapApolloResult from "../unwrapApolloResult";
|
|
11
|
+
import { isSocketCloseError } from "../utils";
|
|
9
12
|
|
|
10
13
|
export class NeighbourhoodClient {
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
private _apolloClient: ApolloClient<any>;
|
|
15
|
+
private _signalHandlers: Map<string, TelepresenceSignalCallback[]> =
|
|
16
|
+
new Map();
|
|
17
|
+
private _signalSubscriptions: Map<string, { unsubscribe(): void }> =
|
|
18
|
+
new Map();
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
constructor(client: ApolloClient<any>) {
|
|
21
|
+
this._apolloClient = client;
|
|
22
|
+
}
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
async publishFromPerspective(
|
|
25
|
+
perspectiveUUID: string,
|
|
26
|
+
linkLanguage: Address,
|
|
27
|
+
meta: Perspective,
|
|
28
|
+
): Promise<string> {
|
|
29
|
+
const { neighbourhoodPublishFromPerspective } = unwrapApolloResult(
|
|
30
|
+
await this._apolloClient.mutate({
|
|
31
|
+
mutation: gql`
|
|
32
|
+
mutation neighbourhoodPublishFromPerspective(
|
|
33
|
+
$linkLanguage: String!
|
|
34
|
+
$meta: PerspectiveInput!
|
|
35
|
+
$perspectiveUUID: String!
|
|
36
|
+
) {
|
|
37
|
+
neighbourhoodPublishFromPerspective(
|
|
38
|
+
linkLanguage: $linkLanguage
|
|
39
|
+
meta: $meta
|
|
40
|
+
perspectiveUUID: $perspectiveUUID
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
`,
|
|
44
|
+
variables: { perspectiveUUID, linkLanguage, meta: meta },
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
return neighbourhoodPublishFromPerspective;
|
|
48
|
+
}
|
|
39
49
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
async joinFromUrl(url: string): Promise<PerspectiveHandle> {
|
|
51
|
+
const { neighbourhoodJoinFromUrl } = unwrapApolloResult(
|
|
52
|
+
await this._apolloClient.mutate({
|
|
53
|
+
mutation: gql`
|
|
54
|
+
mutation neighbourhoodJoinFromUrl($url: String!) {
|
|
55
|
+
neighbourhoodJoinFromUrl(url: $url) {
|
|
56
|
+
uuid
|
|
57
|
+
name
|
|
58
|
+
sharedUrl
|
|
59
|
+
state
|
|
60
|
+
neighbourhood {
|
|
61
|
+
data {
|
|
62
|
+
linkLanguage
|
|
63
|
+
meta {
|
|
64
|
+
links {
|
|
65
|
+
author
|
|
66
|
+
timestamp
|
|
67
|
+
data {
|
|
68
|
+
source
|
|
69
|
+
predicate
|
|
70
|
+
target
|
|
71
|
+
}
|
|
72
|
+
proof {
|
|
73
|
+
valid
|
|
74
|
+
invalid
|
|
75
|
+
signature
|
|
76
|
+
key
|
|
77
|
+
}
|
|
62
78
|
}
|
|
79
|
+
}
|
|
63
80
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
author
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
`,
|
|
86
|
+
variables: { url },
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
return neighbourhoodJoinFromUrl;
|
|
90
|
+
}
|
|
69
91
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
async otherAgents(perspectiveUUID: string): Promise<DID[]> {
|
|
93
|
+
const { neighbourhoodOtherAgents } = unwrapApolloResult(
|
|
94
|
+
await this._apolloClient.query({
|
|
95
|
+
query: gql`
|
|
96
|
+
query neighbourhoodOtherAgents($perspectiveUUID: String!) {
|
|
97
|
+
neighbourhoodOtherAgents(perspectiveUUID: $perspectiveUUID)
|
|
98
|
+
}
|
|
99
|
+
`,
|
|
100
|
+
variables: { perspectiveUUID },
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
return neighbourhoodOtherAgents;
|
|
104
|
+
}
|
|
79
105
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
106
|
+
async hasTelepresenceAdapter(perspectiveUUID: string): Promise<boolean> {
|
|
107
|
+
const { neighbourhoodHasTelepresenceAdapter } = unwrapApolloResult(
|
|
108
|
+
await this._apolloClient.query({
|
|
109
|
+
query: gql`
|
|
110
|
+
query neighbourhoodHasTelepresenceAdapter($perspectiveUUID: String!) {
|
|
111
|
+
neighbourhoodHasTelepresenceAdapter(
|
|
112
|
+
perspectiveUUID: $perspectiveUUID
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
`,
|
|
116
|
+
variables: { perspectiveUUID },
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
return neighbourhoodHasTelepresenceAdapter;
|
|
120
|
+
}
|
|
89
121
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
122
|
+
async onlineAgents(perspectiveUUID: string): Promise<OnlineAgent[]> {
|
|
123
|
+
const { neighbourhoodOnlineAgents } = unwrapApolloResult(
|
|
124
|
+
await this._apolloClient.query({
|
|
125
|
+
query: gql`
|
|
126
|
+
query neighbourhoodOnlineAgents($perspectiveUUID: String!) {
|
|
127
|
+
neighbourhoodOnlineAgents(perspectiveUUID: $perspectiveUUID) {
|
|
128
|
+
did
|
|
129
|
+
status {
|
|
130
|
+
author
|
|
131
|
+
timestamp
|
|
132
|
+
data {
|
|
133
|
+
links {
|
|
134
|
+
author
|
|
135
|
+
timestamp
|
|
136
|
+
data {
|
|
137
|
+
source
|
|
138
|
+
predicate
|
|
139
|
+
target
|
|
107
140
|
}
|
|
141
|
+
proof {
|
|
142
|
+
valid
|
|
143
|
+
invalid
|
|
144
|
+
signature
|
|
145
|
+
key
|
|
146
|
+
}
|
|
147
|
+
}
|
|
108
148
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
}
|
|
149
|
+
proof {
|
|
150
|
+
valid
|
|
151
|
+
invalid
|
|
152
|
+
signature
|
|
153
|
+
key
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
`,
|
|
159
|
+
variables: { perspectiveUUID },
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
return neighbourhoodOnlineAgents;
|
|
163
|
+
}
|
|
148
164
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
async setOnlineStatus(
|
|
166
|
+
perspectiveUUID: string,
|
|
167
|
+
status: Perspective,
|
|
168
|
+
): Promise<boolean> {
|
|
169
|
+
const { neighbourhoodSetOnlineStatus } = unwrapApolloResult(
|
|
170
|
+
await this._apolloClient.mutate({
|
|
171
|
+
mutation: gql`
|
|
172
|
+
mutation neighbourhoodSetOnlineStatus(
|
|
173
|
+
$perspectiveUUID: String!
|
|
174
|
+
$status: PerspectiveInput!
|
|
175
|
+
) {
|
|
176
|
+
neighbourhoodSetOnlineStatus(
|
|
177
|
+
perspectiveUUID: $perspectiveUUID
|
|
178
|
+
status: $status
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
`,
|
|
182
|
+
variables: { perspectiveUUID, status },
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
return neighbourhoodSetOnlineStatus;
|
|
186
|
+
}
|
|
164
187
|
|
|
165
|
-
|
|
166
|
-
|
|
188
|
+
async setOnlineStatusU(
|
|
189
|
+
perspectiveUUID: string,
|
|
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
|
+
}
|
|
167
210
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
211
|
+
async sendSignal(
|
|
212
|
+
perspectiveUUID: string,
|
|
213
|
+
remoteAgentDid: string,
|
|
214
|
+
payload: Perspective,
|
|
215
|
+
): Promise<boolean> {
|
|
216
|
+
const { neighbourhoodSendSignal } = unwrapApolloResult(
|
|
217
|
+
await this._apolloClient.mutate({
|
|
218
|
+
mutation: gql`
|
|
219
|
+
mutation neighbourhoodSendSignal(
|
|
220
|
+
$perspectiveUUID: String!
|
|
221
|
+
$remoteAgentDid: String!
|
|
222
|
+
$payload: PerspectiveInput!
|
|
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
|
+
}
|
|
183
236
|
|
|
184
|
-
|
|
185
|
-
|
|
237
|
+
async sendSignalU(
|
|
238
|
+
perspectiveUUID: string,
|
|
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
|
+
}
|
|
186
262
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
263
|
+
async sendBroadcast(
|
|
264
|
+
perspectiveUUID: string,
|
|
265
|
+
payload: Perspective,
|
|
266
|
+
loopback: boolean = false,
|
|
267
|
+
): Promise<boolean> {
|
|
268
|
+
const { neighbourhoodSendBroadcast } = unwrapApolloResult(
|
|
269
|
+
await this._apolloClient.mutate({
|
|
270
|
+
mutation: gql`
|
|
271
|
+
mutation neighbourhoodSendBroadcast(
|
|
272
|
+
$perspectiveUUID: String!
|
|
273
|
+
$payload: PerspectiveInput!
|
|
274
|
+
$loopback: Boolean
|
|
275
|
+
) {
|
|
276
|
+
neighbourhoodSendBroadcast(
|
|
277
|
+
perspectiveUUID: $perspectiveUUID
|
|
278
|
+
payload: $payload
|
|
279
|
+
loopback: $loopback
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
`,
|
|
283
|
+
variables: { perspectiveUUID, payload, loopback },
|
|
284
|
+
}),
|
|
285
|
+
);
|
|
286
|
+
return neighbourhoodSendBroadcast;
|
|
287
|
+
}
|
|
202
288
|
|
|
203
|
-
|
|
204
|
-
|
|
289
|
+
async sendBroadcastU(
|
|
290
|
+
perspectiveUUID: string,
|
|
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
|
+
}
|
|
205
314
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
handlers.forEach(handler => handler(signal))
|
|
315
|
+
dispatchSignal(perspectiveUUID: string, signal: any) {
|
|
316
|
+
const handlers = this._signalHandlers.get(perspectiveUUID);
|
|
317
|
+
if (handlers) {
|
|
318
|
+
for (const handler of handlers) {
|
|
319
|
+
try {
|
|
320
|
+
handler(signal);
|
|
321
|
+
} catch (e) {
|
|
322
|
+
console.error("Error in signal handler:", e);
|
|
229
323
|
}
|
|
324
|
+
}
|
|
230
325
|
}
|
|
326
|
+
}
|
|
231
327
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
328
|
+
async subscribeToSignals(perspectiveUUID: string): Promise<void> {
|
|
329
|
+
const that = this;
|
|
330
|
+
const sub = this._apolloClient
|
|
331
|
+
.subscribe({
|
|
332
|
+
query: gql`
|
|
333
|
+
subscription neighbourhoodSignal($perspectiveUUID: String!) {
|
|
334
|
+
neighbourhoodSignal(perspectiveUUID: $perspectiveUUID) {
|
|
335
|
+
author
|
|
336
|
+
timestamp
|
|
337
|
+
data {
|
|
338
|
+
links {
|
|
339
|
+
author
|
|
340
|
+
timestamp
|
|
341
|
+
data {
|
|
342
|
+
source
|
|
343
|
+
predicate
|
|
344
|
+
target
|
|
345
|
+
}
|
|
346
|
+
proof {
|
|
347
|
+
valid
|
|
348
|
+
invalid
|
|
349
|
+
signature
|
|
350
|
+
key
|
|
351
|
+
}
|
|
249
352
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
353
|
+
}
|
|
354
|
+
proof {
|
|
355
|
+
valid
|
|
356
|
+
invalid
|
|
357
|
+
signature
|
|
358
|
+
key
|
|
359
|
+
}
|
|
256
360
|
}
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
}
|
|
259
381
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
382
|
+
async addSignalHandler(
|
|
383
|
+
perspectiveUUID: string,
|
|
384
|
+
handler: TelepresenceSignalCallback,
|
|
385
|
+
): Promise<void> {
|
|
386
|
+
let handlersForPerspective = this._signalHandlers.get(perspectiveUUID);
|
|
387
|
+
if (!handlersForPerspective) {
|
|
388
|
+
handlersForPerspective = [];
|
|
389
|
+
this._signalHandlers.set(perspectiveUUID, handlersForPerspective);
|
|
390
|
+
// Push handler BEFORE subscribing so it's available when signals arrive
|
|
391
|
+
handlersForPerspective.push(handler);
|
|
392
|
+
await this.subscribeToSignals(perspectiveUUID);
|
|
393
|
+
} else {
|
|
394
|
+
handlersForPerspective.push(handler);
|
|
268
395
|
}
|
|
396
|
+
}
|
|
269
397
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
398
|
+
removeSignalHandler(
|
|
399
|
+
perspectiveUUID: string,
|
|
400
|
+
handler: TelepresenceSignalCallback,
|
|
401
|
+
): void {
|
|
402
|
+
const handlersForPerspective = this._signalHandlers.get(perspectiveUUID);
|
|
403
|
+
if (handlersForPerspective) {
|
|
404
|
+
const index = handlersForPerspective.indexOf(handler);
|
|
405
|
+
if (index > -1) {
|
|
406
|
+
handlersForPerspective.splice(index, 1);
|
|
407
|
+
}
|
|
408
|
+
// Intentionally keep the Apollo subscription and the handlers-map entry alive
|
|
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().
|
|
278
412
|
}
|
|
279
|
-
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/** Fully tears down the Apollo subscription for a perspective UUID. */
|
|
416
|
+
unsubscribeFromPerspective(perspectiveUUID: string): void {
|
|
417
|
+
this._signalSubscriptions.get(perspectiveUUID)?.unsubscribe();
|
|
418
|
+
this._signalSubscriptions.delete(perspectiveUUID);
|
|
419
|
+
this._signalHandlers.delete(perspectiveUUID);
|
|
420
|
+
}
|
|
421
|
+
}
|