@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,259 +1,341 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _NeighbourhoodClient_apolloClient, _NeighbourhoodClient_signalHandlers;
|
|
13
1
|
import { gql } from "@apollo/client/core";
|
|
14
2
|
import unwrapApolloResult from "../unwrapApolloResult";
|
|
3
|
+
import { isSocketCloseError } from "../utils";
|
|
15
4
|
export class NeighbourhoodClient {
|
|
16
5
|
constructor(client) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
this._signalHandlers = new Map();
|
|
7
|
+
this._signalSubscriptions = new Map();
|
|
8
|
+
this._apolloClient = client;
|
|
20
9
|
}
|
|
21
10
|
async publishFromPerspective(perspectiveUUID, linkLanguage, meta) {
|
|
22
|
-
const { neighbourhoodPublishFromPerspective } = unwrapApolloResult(await
|
|
23
|
-
mutation: gql `
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
const { neighbourhoodPublishFromPerspective } = unwrapApolloResult(await this._apolloClient.mutate({
|
|
12
|
+
mutation: gql `
|
|
13
|
+
mutation neighbourhoodPublishFromPerspective(
|
|
14
|
+
$linkLanguage: String!
|
|
15
|
+
$meta: PerspectiveInput!
|
|
16
|
+
$perspectiveUUID: String!
|
|
17
|
+
) {
|
|
18
|
+
neighbourhoodPublishFromPerspective(
|
|
19
|
+
linkLanguage: $linkLanguage
|
|
20
|
+
meta: $meta
|
|
21
|
+
perspectiveUUID: $perspectiveUUID
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
`,
|
|
25
|
+
variables: { perspectiveUUID, linkLanguage, meta: meta },
|
|
35
26
|
}));
|
|
36
27
|
return neighbourhoodPublishFromPerspective;
|
|
37
28
|
}
|
|
38
29
|
async joinFromUrl(url) {
|
|
39
|
-
const { neighbourhoodJoinFromUrl } = unwrapApolloResult(await
|
|
40
|
-
mutation: gql `
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
30
|
+
const { neighbourhoodJoinFromUrl } = unwrapApolloResult(await this._apolloClient.mutate({
|
|
31
|
+
mutation: gql `
|
|
32
|
+
mutation neighbourhoodJoinFromUrl($url: String!) {
|
|
33
|
+
neighbourhoodJoinFromUrl(url: $url) {
|
|
34
|
+
uuid
|
|
35
|
+
name
|
|
36
|
+
sharedUrl
|
|
37
|
+
state
|
|
38
|
+
neighbourhood {
|
|
39
|
+
data {
|
|
40
|
+
linkLanguage
|
|
41
|
+
meta {
|
|
42
|
+
links {
|
|
43
|
+
author
|
|
44
|
+
timestamp
|
|
45
|
+
data {
|
|
46
|
+
source
|
|
47
|
+
predicate
|
|
48
|
+
target
|
|
49
|
+
}
|
|
50
|
+
proof {
|
|
51
|
+
valid
|
|
52
|
+
invalid
|
|
53
|
+
signature
|
|
54
|
+
key
|
|
55
|
+
}
|
|
60
56
|
}
|
|
57
|
+
}
|
|
61
58
|
}
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
author
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`,
|
|
64
|
+
variables: { url },
|
|
64
65
|
}));
|
|
65
66
|
return neighbourhoodJoinFromUrl;
|
|
66
67
|
}
|
|
67
68
|
async otherAgents(perspectiveUUID) {
|
|
68
|
-
const { neighbourhoodOtherAgents } = unwrapApolloResult(await
|
|
69
|
-
query: gql `
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
const { neighbourhoodOtherAgents } = unwrapApolloResult(await this._apolloClient.query({
|
|
70
|
+
query: gql `
|
|
71
|
+
query neighbourhoodOtherAgents($perspectiveUUID: String!) {
|
|
72
|
+
neighbourhoodOtherAgents(perspectiveUUID: $perspectiveUUID)
|
|
73
|
+
}
|
|
74
|
+
`,
|
|
75
|
+
variables: { perspectiveUUID },
|
|
73
76
|
}));
|
|
74
77
|
return neighbourhoodOtherAgents;
|
|
75
78
|
}
|
|
76
79
|
async hasTelepresenceAdapter(perspectiveUUID) {
|
|
77
|
-
const { neighbourhoodHasTelepresenceAdapter } = unwrapApolloResult(await
|
|
78
|
-
query: gql `
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
const { neighbourhoodHasTelepresenceAdapter } = unwrapApolloResult(await this._apolloClient.query({
|
|
81
|
+
query: gql `
|
|
82
|
+
query neighbourhoodHasTelepresenceAdapter($perspectiveUUID: String!) {
|
|
83
|
+
neighbourhoodHasTelepresenceAdapter(
|
|
84
|
+
perspectiveUUID: $perspectiveUUID
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
`,
|
|
88
|
+
variables: { perspectiveUUID },
|
|
82
89
|
}));
|
|
83
90
|
return neighbourhoodHasTelepresenceAdapter;
|
|
84
91
|
}
|
|
85
92
|
async onlineAgents(perspectiveUUID) {
|
|
86
|
-
const { neighbourhoodOnlineAgents } = unwrapApolloResult(await
|
|
87
|
-
query: gql `
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
const { neighbourhoodOnlineAgents } = unwrapApolloResult(await this._apolloClient.query({
|
|
94
|
+
query: gql `
|
|
95
|
+
query neighbourhoodOnlineAgents($perspectiveUUID: String!) {
|
|
96
|
+
neighbourhoodOnlineAgents(perspectiveUUID: $perspectiveUUID) {
|
|
97
|
+
did
|
|
98
|
+
status {
|
|
99
|
+
author
|
|
100
|
+
timestamp
|
|
101
|
+
data {
|
|
102
|
+
links {
|
|
103
|
+
author
|
|
104
|
+
timestamp
|
|
105
|
+
data {
|
|
106
|
+
source
|
|
107
|
+
predicate
|
|
108
|
+
target
|
|
109
|
+
}
|
|
110
|
+
proof {
|
|
111
|
+
valid
|
|
112
|
+
invalid
|
|
113
|
+
signature
|
|
114
|
+
key
|
|
102
115
|
}
|
|
116
|
+
}
|
|
103
117
|
}
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
proof {
|
|
119
|
+
valid
|
|
120
|
+
invalid
|
|
121
|
+
signature
|
|
122
|
+
key
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
`,
|
|
128
|
+
variables: { perspectiveUUID },
|
|
106
129
|
}));
|
|
107
130
|
return neighbourhoodOnlineAgents;
|
|
108
131
|
}
|
|
109
132
|
async setOnlineStatus(perspectiveUUID, status) {
|
|
110
|
-
const { neighbourhoodSetOnlineStatus } = unwrapApolloResult(await
|
|
111
|
-
mutation: gql `
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
133
|
+
const { neighbourhoodSetOnlineStatus } = unwrapApolloResult(await this._apolloClient.mutate({
|
|
134
|
+
mutation: gql `
|
|
135
|
+
mutation neighbourhoodSetOnlineStatus(
|
|
136
|
+
$perspectiveUUID: String!
|
|
137
|
+
$status: PerspectiveInput!
|
|
138
|
+
) {
|
|
139
|
+
neighbourhoodSetOnlineStatus(
|
|
140
|
+
perspectiveUUID: $perspectiveUUID
|
|
141
|
+
status: $status
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
`,
|
|
145
|
+
variables: { perspectiveUUID, status },
|
|
121
146
|
}));
|
|
122
147
|
return neighbourhoodSetOnlineStatus;
|
|
123
148
|
}
|
|
124
149
|
async setOnlineStatusU(perspectiveUUID, status) {
|
|
125
|
-
const { neighbourhoodSetOnlineStatusU } = unwrapApolloResult(await
|
|
126
|
-
mutation: gql `
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
150
|
+
const { neighbourhoodSetOnlineStatusU } = unwrapApolloResult(await this._apolloClient.mutate({
|
|
151
|
+
mutation: gql `
|
|
152
|
+
mutation neighbourhoodSetOnlineStatusU(
|
|
153
|
+
$perspectiveUUID: String!
|
|
154
|
+
$status: PerspectiveUnsignedInput!
|
|
155
|
+
) {
|
|
156
|
+
neighbourhoodSetOnlineStatusU(
|
|
157
|
+
perspectiveUUID: $perspectiveUUID
|
|
158
|
+
status: $status
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
`,
|
|
162
|
+
variables: { perspectiveUUID, status },
|
|
136
163
|
}));
|
|
137
164
|
return neighbourhoodSetOnlineStatusU;
|
|
138
165
|
}
|
|
139
166
|
async sendSignal(perspectiveUUID, remoteAgentDid, payload) {
|
|
140
|
-
const { neighbourhoodSendSignal } = unwrapApolloResult(await
|
|
141
|
-
mutation: gql `
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
167
|
+
const { neighbourhoodSendSignal } = unwrapApolloResult(await this._apolloClient.mutate({
|
|
168
|
+
mutation: gql `
|
|
169
|
+
mutation neighbourhoodSendSignal(
|
|
170
|
+
$perspectiveUUID: String!
|
|
171
|
+
$remoteAgentDid: String!
|
|
172
|
+
$payload: PerspectiveInput!
|
|
173
|
+
) {
|
|
174
|
+
neighbourhoodSendSignal(
|
|
175
|
+
perspectiveUUID: $perspectiveUUID
|
|
176
|
+
remoteAgentDid: $remoteAgentDid
|
|
177
|
+
payload: $payload
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
`,
|
|
181
|
+
variables: { perspectiveUUID, remoteAgentDid, payload },
|
|
153
182
|
}));
|
|
154
183
|
return neighbourhoodSendSignal;
|
|
155
184
|
}
|
|
156
185
|
async sendSignalU(perspectiveUUID, remoteAgentDid, payload) {
|
|
157
|
-
const { neighbourhoodSendSignalU } = unwrapApolloResult(await
|
|
158
|
-
mutation: gql `
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
186
|
+
const { neighbourhoodSendSignalU } = unwrapApolloResult(await this._apolloClient.mutate({
|
|
187
|
+
mutation: gql `
|
|
188
|
+
mutation neighbourhoodSendSignalU(
|
|
189
|
+
$perspectiveUUID: String!
|
|
190
|
+
$remoteAgentDid: String!
|
|
191
|
+
$payload: PerspectiveUnsignedInput!
|
|
192
|
+
) {
|
|
193
|
+
neighbourhoodSendSignalU(
|
|
194
|
+
perspectiveUUID: $perspectiveUUID
|
|
195
|
+
remoteAgentDid: $remoteAgentDid
|
|
196
|
+
payload: $payload
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
`,
|
|
200
|
+
variables: { perspectiveUUID, remoteAgentDid, payload },
|
|
170
201
|
}));
|
|
171
202
|
return neighbourhoodSendSignalU;
|
|
172
203
|
}
|
|
173
204
|
async sendBroadcast(perspectiveUUID, payload, loopback = false) {
|
|
174
|
-
const { neighbourhoodSendBroadcast } = unwrapApolloResult(await
|
|
175
|
-
mutation: gql `
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
205
|
+
const { neighbourhoodSendBroadcast } = unwrapApolloResult(await this._apolloClient.mutate({
|
|
206
|
+
mutation: gql `
|
|
207
|
+
mutation neighbourhoodSendBroadcast(
|
|
208
|
+
$perspectiveUUID: String!
|
|
209
|
+
$payload: PerspectiveInput!
|
|
210
|
+
$loopback: Boolean
|
|
211
|
+
) {
|
|
212
|
+
neighbourhoodSendBroadcast(
|
|
213
|
+
perspectiveUUID: $perspectiveUUID
|
|
214
|
+
payload: $payload
|
|
215
|
+
loopback: $loopback
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
`,
|
|
219
|
+
variables: { perspectiveUUID, payload, loopback },
|
|
187
220
|
}));
|
|
188
221
|
return neighbourhoodSendBroadcast;
|
|
189
222
|
}
|
|
190
223
|
async sendBroadcastU(perspectiveUUID, payload, loopback = false) {
|
|
191
|
-
const { neighbourhoodSendBroadcastU } = unwrapApolloResult(await
|
|
192
|
-
mutation: gql `
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
224
|
+
const { neighbourhoodSendBroadcastU } = unwrapApolloResult(await this._apolloClient.mutate({
|
|
225
|
+
mutation: gql `
|
|
226
|
+
mutation neighbourhoodSendBroadcastU(
|
|
227
|
+
$perspectiveUUID: String!
|
|
228
|
+
$payload: PerspectiveUnsignedInput!
|
|
229
|
+
$loopback: Boolean
|
|
230
|
+
) {
|
|
231
|
+
neighbourhoodSendBroadcastU(
|
|
232
|
+
perspectiveUUID: $perspectiveUUID
|
|
233
|
+
payload: $payload
|
|
234
|
+
loopback: $loopback
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
`,
|
|
238
|
+
variables: { perspectiveUUID, payload, loopback },
|
|
204
239
|
}));
|
|
205
240
|
return neighbourhoodSendBroadcastU;
|
|
206
241
|
}
|
|
207
242
|
dispatchSignal(perspectiveUUID, signal) {
|
|
208
|
-
const handlers =
|
|
243
|
+
const handlers = this._signalHandlers.get(perspectiveUUID);
|
|
209
244
|
if (handlers) {
|
|
210
|
-
|
|
245
|
+
for (const handler of handlers) {
|
|
246
|
+
try {
|
|
247
|
+
handler(signal);
|
|
248
|
+
}
|
|
249
|
+
catch (e) {
|
|
250
|
+
console.error("Error in signal handler:", e);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
211
253
|
}
|
|
212
254
|
}
|
|
213
255
|
async subscribeToSignals(perspectiveUUID) {
|
|
214
256
|
const that = this;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
257
|
+
const sub = this._apolloClient
|
|
258
|
+
.subscribe({
|
|
259
|
+
query: gql `
|
|
260
|
+
subscription neighbourhoodSignal($perspectiveUUID: String!) {
|
|
261
|
+
neighbourhoodSignal(perspectiveUUID: $perspectiveUUID) {
|
|
262
|
+
author
|
|
263
|
+
timestamp
|
|
264
|
+
data {
|
|
265
|
+
links {
|
|
266
|
+
author
|
|
267
|
+
timestamp
|
|
268
|
+
data {
|
|
269
|
+
source
|
|
270
|
+
predicate
|
|
271
|
+
target
|
|
272
|
+
}
|
|
273
|
+
proof {
|
|
274
|
+
valid
|
|
275
|
+
invalid
|
|
276
|
+
signature
|
|
277
|
+
key
|
|
278
|
+
}
|
|
230
279
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
280
|
+
}
|
|
281
|
+
proof {
|
|
282
|
+
valid
|
|
283
|
+
invalid
|
|
284
|
+
signature
|
|
285
|
+
key
|
|
286
|
+
}
|
|
237
287
|
}
|
|
288
|
+
}
|
|
289
|
+
`,
|
|
290
|
+
variables: { perspectiveUUID },
|
|
291
|
+
})
|
|
292
|
+
.subscribe({
|
|
293
|
+
next: (result) => {
|
|
294
|
+
try {
|
|
295
|
+
const { neighbourhoodSignal } = unwrapApolloResult(result);
|
|
296
|
+
that.dispatchSignal(perspectiveUUID, neighbourhoodSignal);
|
|
297
|
+
}
|
|
298
|
+
catch (e) {
|
|
299
|
+
console.error("Error in signal subscription:", e);
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
error: (e) => {
|
|
303
|
+
if (!isSocketCloseError(e))
|
|
304
|
+
console.error("neighbourhoodSignal subscription error:", e);
|
|
305
|
+
},
|
|
238
306
|
});
|
|
307
|
+
this._signalSubscriptions.set(perspectiveUUID, sub);
|
|
239
308
|
}
|
|
240
309
|
async addSignalHandler(perspectiveUUID, handler) {
|
|
241
|
-
let handlersForPerspective =
|
|
310
|
+
let handlersForPerspective = this._signalHandlers.get(perspectiveUUID);
|
|
242
311
|
if (!handlersForPerspective) {
|
|
243
312
|
handlersForPerspective = [];
|
|
244
|
-
|
|
313
|
+
this._signalHandlers.set(perspectiveUUID, handlersForPerspective);
|
|
314
|
+
// Push handler BEFORE subscribing so it's available when signals arrive
|
|
315
|
+
handlersForPerspective.push(handler);
|
|
245
316
|
await this.subscribeToSignals(perspectiveUUID);
|
|
246
317
|
}
|
|
247
|
-
|
|
318
|
+
else {
|
|
319
|
+
handlersForPerspective.push(handler);
|
|
320
|
+
}
|
|
248
321
|
}
|
|
249
322
|
removeSignalHandler(perspectiveUUID, handler) {
|
|
250
|
-
const handlersForPerspective =
|
|
323
|
+
const handlersForPerspective = this._signalHandlers.get(perspectiveUUID);
|
|
251
324
|
if (handlersForPerspective) {
|
|
252
325
|
const index = handlersForPerspective.indexOf(handler);
|
|
253
326
|
if (index > -1) {
|
|
254
327
|
handlersForPerspective.splice(index, 1);
|
|
255
328
|
}
|
|
329
|
+
// Intentionally keep the Apollo subscription and the handlers-map entry alive
|
|
330
|
+
// even when the array becomes empty. This prevents an unnecessary re-subscription
|
|
331
|
+
// if a new handler is added shortly after (the empty array makes addSignalHandler
|
|
332
|
+
// skip subscribeToSignals). For explicit teardown use unsubscribeFromPerspective().
|
|
256
333
|
}
|
|
257
334
|
}
|
|
335
|
+
/** Fully tears down the Apollo subscription for a perspective UUID. */
|
|
336
|
+
unsubscribeFromPerspective(perspectiveUUID) {
|
|
337
|
+
this._signalSubscriptions.get(perspectiveUUID)?.unsubscribe();
|
|
338
|
+
this._signalSubscriptions.delete(perspectiveUUID);
|
|
339
|
+
this._signalHandlers.delete(perspectiveUUID);
|
|
340
|
+
}
|
|
258
341
|
}
|
|
259
|
-
_NeighbourhoodClient_apolloClient = new WeakMap(), _NeighbourhoodClient_signalHandlers = new WeakMap();
|
|
@@ -3,7 +3,8 @@ import { OnlineAgent } from "../language/Language";
|
|
|
3
3
|
import { Perspective, PerspectiveExpression, PerspectiveUnsignedInput } from "../perspectives/Perspective";
|
|
4
4
|
import { NeighbourhoodClient } from "./NeighbourhoodClient";
|
|
5
5
|
export declare class NeighbourhoodProxy {
|
|
6
|
-
|
|
6
|
+
private _client;
|
|
7
|
+
private _pID;
|
|
7
8
|
constructor(client: NeighbourhoodClient, pID: string);
|
|
8
9
|
otherAgents(): Promise<DID[]>;
|
|
9
10
|
hasTelepresenceAdapter(): Promise<boolean>;
|
|
@@ -1,54 +1,39 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _NeighbourhoodProxy_client, _NeighbourhoodProxy_pID;
|
|
13
1
|
export class NeighbourhoodProxy {
|
|
14
2
|
constructor(client, pID) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
__classPrivateFieldSet(this, _NeighbourhoodProxy_client, client, "f");
|
|
18
|
-
__classPrivateFieldSet(this, _NeighbourhoodProxy_pID, pID, "f");
|
|
3
|
+
this._client = client;
|
|
4
|
+
this._pID = pID;
|
|
19
5
|
}
|
|
20
6
|
async otherAgents() {
|
|
21
|
-
return await
|
|
7
|
+
return await this._client.otherAgents(this._pID);
|
|
22
8
|
}
|
|
23
9
|
async hasTelepresenceAdapter() {
|
|
24
|
-
return await
|
|
10
|
+
return await this._client.hasTelepresenceAdapter(this._pID);
|
|
25
11
|
}
|
|
26
12
|
async onlineAgents() {
|
|
27
|
-
return await
|
|
13
|
+
return await this._client.onlineAgents(this._pID);
|
|
28
14
|
}
|
|
29
15
|
async setOnlineStatus(status) {
|
|
30
|
-
return await
|
|
16
|
+
return await this._client.setOnlineStatus(this._pID, status);
|
|
31
17
|
}
|
|
32
18
|
async setOnlineStatusU(status) {
|
|
33
|
-
return await
|
|
19
|
+
return await this._client.setOnlineStatusU(this._pID, status);
|
|
34
20
|
}
|
|
35
21
|
async sendSignal(remoteAgentDid, payload) {
|
|
36
|
-
return await
|
|
22
|
+
return await this._client.sendSignal(this._pID, remoteAgentDid, payload);
|
|
37
23
|
}
|
|
38
24
|
async sendSignalU(remoteAgentDid, payload) {
|
|
39
|
-
return await
|
|
25
|
+
return await this._client.sendSignalU(this._pID, remoteAgentDid, payload);
|
|
40
26
|
}
|
|
41
27
|
async sendBroadcast(payload, loopback = false) {
|
|
42
|
-
return await
|
|
28
|
+
return await this._client.sendBroadcast(this._pID, payload, loopback);
|
|
43
29
|
}
|
|
44
30
|
async sendBroadcastU(payload, loopback = false) {
|
|
45
|
-
return await
|
|
31
|
+
return await this._client.sendBroadcastU(this._pID, payload, loopback);
|
|
46
32
|
}
|
|
47
33
|
async addSignalHandler(handler) {
|
|
48
|
-
await
|
|
34
|
+
await this._client.addSignalHandler(this._pID, handler);
|
|
49
35
|
}
|
|
50
36
|
removeSignalHandler(handler) {
|
|
51
|
-
|
|
37
|
+
this._client.removeSignalHandler(this._pID, handler);
|
|
52
38
|
}
|
|
53
39
|
}
|
|
54
|
-
_NeighbourhoodProxy_client = new WeakMap(), _NeighbourhoodProxy_pID = new WeakMap();
|
|
@@ -33,11 +33,7 @@ describe("NeighbourhoodProxy", () => {
|
|
|
33
33
|
const subscriptions = [];
|
|
34
34
|
const subscribe = (args) => {
|
|
35
35
|
subscriptions.push(args);
|
|
36
|
-
|
|
37
|
-
setTimeout(() => {
|
|
38
|
-
resolve({});
|
|
39
|
-
}, 10);
|
|
40
|
-
});
|
|
36
|
+
return { unsubscribe: () => { } };
|
|
41
37
|
};
|
|
42
38
|
const mockApolloClient = {
|
|
43
39
|
subscribe: () => ({
|