@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.
Files changed (153) hide show
  1. package/jest.config.js +10 -3
  2. package/lib/index.cjs +6872 -5886
  3. package/lib/index.js +6868 -5874
  4. package/lib/src/Ad4mClient.d.ts +9 -16
  5. package/lib/src/Ad4mClient.js +46 -25
  6. package/lib/src/Literal.d.ts +1 -2
  7. package/lib/src/Literal.js +38 -35
  8. package/lib/src/SmartLiteral.d.ts +1 -2
  9. package/lib/src/SmartLiteral.js +30 -15
  10. package/lib/src/agent/AgentClient.d.ts +1 -4
  11. package/lib/src/agent/AgentClient.js +79 -99
  12. package/lib/src/ai/AIClient.d.ts +1 -2
  13. package/lib/src/ai/AIClient.js +224 -220
  14. package/lib/src/expression/ExpressionClient.d.ts +1 -1
  15. package/lib/src/expression/ExpressionClient.js +73 -86
  16. package/lib/src/index.d.ts +1 -1
  17. package/lib/src/index.js +1 -1
  18. package/lib/src/language/LanguageClient.d.ts +1 -1
  19. package/lib/src/language/LanguageClient.js +52 -52
  20. package/lib/src/model/Ad4mModel.d.ts +1351 -144
  21. package/lib/src/model/Ad4mModel.js +3737 -228
  22. package/lib/src/model/Ad4mModel.test.js +522 -979
  23. package/lib/src/model/Subject.d.ts +3 -3
  24. package/lib/src/model/Subject.js +25 -25
  25. package/lib/src/model/decorators.d.ts +444 -100
  26. package/lib/src/model/decorators.js +686 -321
  27. package/lib/src/model/util.d.ts +6 -6
  28. package/lib/src/model/util.js +24 -24
  29. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +1 -5
  30. package/lib/src/neighbourhood/NeighbourhoodClient.js +179 -242
  31. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +1 -2
  32. package/lib/src/neighbourhood/NeighbourhoodProxy.js +28 -13
  33. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +5 -1
  34. package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
  35. package/lib/src/perspectives/PerspectiveClient.js +240 -316
  36. package/lib/src/perspectives/PerspectiveProxy.d.ts +99 -61
  37. package/lib/src/perspectives/PerspectiveProxy.js +485 -832
  38. package/lib/src/runtime/RuntimeClient.d.ts +1 -5
  39. package/lib/src/runtime/RuntimeClient.js +238 -412
  40. package/lib/src/shacl/SHACLFlow.test.js +105 -164
  41. package/lib/src/shacl/SHACLShape.d.ts +12 -17
  42. package/lib/src/shacl/SHACLShape.js +115 -128
  43. package/lib/src/shacl/SHACLShape.test.js +176 -244
  44. package/lib/src/shims/reflect-metadata.d.ts +0 -0
  45. package/lib/src/shims/type-graphql.d.ts +32 -0
  46. package/lib/src/src/Ad4mClient.d.ts +28 -0
  47. package/lib/src/src/Address.d.ts +1 -0
  48. package/lib/src/src/DID.d.ts +1 -0
  49. package/lib/src/src/Exception.d.ts +7 -0
  50. package/lib/src/src/Literal.d.ts +7 -0
  51. package/lib/src/src/PubSub.d.ts +17 -0
  52. package/lib/src/src/SmartLiteral.d.ts +12 -0
  53. package/lib/src/src/agent/Agent.d.ts +110 -0
  54. package/lib/src/src/agent/AgentClient.d.ts +62 -0
  55. package/lib/src/src/agent/AgentResolver.d.ts +30 -0
  56. package/lib/src/src/agent/AgentStatus.d.ts +8 -0
  57. package/lib/src/src/ai/AIClient.d.ts +32 -0
  58. package/lib/src/src/ai/AIResolver.d.ts +75 -0
  59. package/lib/src/src/ai/Tasks.d.ts +37 -0
  60. package/lib/src/src/buildSchema.d.ts +1 -0
  61. package/lib/src/src/expression/Expression.d.ts +28 -0
  62. package/lib/src/src/expression/ExpressionClient.d.ts +13 -0
  63. package/lib/src/src/expression/ExpressionRef.d.ts +9 -0
  64. package/lib/src/src/expression/ExpressionResolver.d.ts +10 -0
  65. package/lib/src/src/index.d.ts +35 -0
  66. package/lib/src/src/jestSetup.d.ts +1 -0
  67. package/lib/src/src/language/Icon.d.ts +4 -0
  68. package/lib/src/src/language/Language.d.ts +206 -0
  69. package/lib/src/src/language/LanguageClient.d.ts +17 -0
  70. package/lib/src/src/language/LanguageContext.d.ts +37 -0
  71. package/lib/src/src/language/LanguageHandle.d.ts +9 -0
  72. package/lib/src/src/language/LanguageMeta.d.ts +35 -0
  73. package/lib/src/src/language/LanguageRef.d.ts +6 -0
  74. package/lib/src/src/language/LanguageResolver.d.ts +19 -0
  75. package/lib/src/src/links/Links.d.ts +39 -0
  76. package/lib/src/src/links/Links.test.d.ts +1 -0
  77. package/lib/src/src/model/Ad4mModel.d.ts +1438 -0
  78. package/lib/src/src/model/Ad4mModel.test.d.ts +1 -0
  79. package/lib/src/src/model/Subject.d.ts +25 -0
  80. package/lib/src/src/model/decorators.d.ts +545 -0
  81. package/lib/src/src/model/util.d.ts +12 -0
  82. package/lib/src/src/neighbourhood/Neighbourhood.d.ts +10 -0
  83. package/lib/src/src/neighbourhood/NeighbourhoodClient.d.ts +25 -0
  84. package/lib/src/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -0
  85. package/lib/src/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
  86. package/lib/src/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -0
  87. package/lib/src/src/perspectives/LinkQuery.d.ts +11 -0
  88. package/lib/src/src/perspectives/Perspective.d.ts +38 -0
  89. package/lib/src/src/perspectives/Perspective.test.d.ts +1 -0
  90. package/lib/src/src/perspectives/PerspectiveClient.d.ts +97 -0
  91. package/lib/src/src/perspectives/PerspectiveDiff.d.ts +9 -0
  92. package/lib/src/src/perspectives/PerspectiveHandle.d.ts +18 -0
  93. package/lib/src/src/perspectives/PerspectiveProxy.d.ts +865 -0
  94. package/lib/src/src/perspectives/PerspectiveResolver.d.ts +57 -0
  95. package/lib/src/src/runtime/RuntimeClient.d.ts +56 -0
  96. package/lib/src/src/runtime/RuntimeResolver.d.ts +132 -0
  97. package/lib/src/src/shacl/SHACLFlow.d.ts +171 -0
  98. package/lib/src/src/shacl/SHACLFlow.test.d.ts +1 -0
  99. package/lib/src/src/shacl/SHACLShape.d.ts +117 -0
  100. package/lib/src/src/shacl/SHACLShape.test.d.ts +1 -0
  101. package/lib/src/src/typeDefs.d.ts +1 -0
  102. package/lib/src/src/unwrapApolloResult.d.ts +2 -0
  103. package/lib/src/src/utils.d.ts +25 -0
  104. package/lib/src/utils.d.ts +0 -8
  105. package/lib/src/utils.js +7 -21
  106. package/package.json +15 -14
  107. package/src/Ad4mClient.test.ts +1315 -1564
  108. package/src/Ad4mClient.ts +54 -55
  109. package/src/Literal.test.ts +26 -45
  110. package/src/Literal.ts +66 -82
  111. package/src/SmartLiteral.ts +58 -74
  112. package/src/agent/AgentClient.ts +99 -144
  113. package/src/ai/AIClient.ts +359 -409
  114. package/src/expression/ExpressionClient.ts +96 -142
  115. package/src/index.ts +1 -1
  116. package/src/language/LanguageClient.ts +113 -137
  117. package/src/model/Ad4mModel.test.ts +616 -1114
  118. package/src/model/Ad4mModel.ts +4361 -451
  119. package/src/model/Subject.ts +159 -0
  120. package/src/model/decorators.ts +1168 -667
  121. package/src/model/util.ts +54 -53
  122. package/src/neighbourhood/NeighbourhoodClient.ts +266 -392
  123. package/src/neighbourhood/NeighbourhoodProxy.test.ts +7 -3
  124. package/src/neighbourhood/NeighbourhoodProxy.ts +40 -58
  125. package/src/perspectives/PerspectiveClient.ts +540 -779
  126. package/src/perspectives/PerspectiveProxy.ts +2067 -2860
  127. package/src/runtime/RuntimeClient.ts +476 -775
  128. package/src/shacl/SHACLFlow.test.ts +129 -196
  129. package/src/shacl/SHACLShape.test.ts +190 -284
  130. package/src/shacl/SHACLShape.ts +200 -224
  131. package/src/utils.ts +17 -31
  132. package/tsconfig.json +10 -9
  133. package/src/model/IMPROVEMENTS.md +0 -482
  134. package/src/model/PREDICATE_COLLISION_FIX.md +0 -651
  135. package/src/model/README.md +0 -317
  136. package/src/model/SHACL_MUTATION_DECOUPLING.md +0 -356
  137. package/src/model/SUBSCRIPTION_STRATEGY.md +0 -317
  138. package/src/model/TC39_STAGE_3_DECORATORS.md +0 -609
  139. package/src/model/mutation.ts +0 -461
  140. package/src/model/parentUtils.ts +0 -91
  141. package/src/model/prolog/generatePrologFacts.ts +0 -176
  142. package/src/model/prolog/index.ts +0 -1
  143. package/src/model/query/ModelQueryBuilder.ts +0 -173
  144. package/src/model/query/fetchInstance.ts +0 -181
  145. package/src/model/query/hydration.ts +0 -273
  146. package/src/model/query/operations.ts +0 -510
  147. package/src/model/query/snapshot.ts +0 -126
  148. package/src/model/query/surrealCompiler.ts +0 -376
  149. package/src/model/schema/fromJSONSchema.ts +0 -411
  150. package/src/model/schema/metadata.ts +0 -148
  151. package/src/model/subscription.ts +0 -307
  152. package/src/model/transaction.ts +0 -60
  153. 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
- Perspective,
7
- PerspectiveUnsignedInput,
8
- } from "../perspectives/Perspective";
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
- private _apolloClient: ApolloClient<any>;
15
- private _signalHandlers: Map<string, TelepresenceSignalCallback[]> =
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
- constructor(client: ApolloClient<any>) {
21
- this._apolloClient = client;
22
- }
14
+ constructor(client: ApolloClient<any>) {
15
+ this.#apolloClient = client
16
+ }
23
17
 
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
- }
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
- 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
- }
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
- author
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
- 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
- }
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
- 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
- }
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
- 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
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
- proof {
150
- valid
151
- invalid
152
- signature
153
- key
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
- 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
- }
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
- 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
- }
129
+ return neighbourhoodSetOnlineStatus
130
+ }
210
131
 
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
- }
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
- 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
- }
146
+ return neighbourhoodSetOnlineStatusU
147
+ }
262
148
 
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
- }
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
- 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
- }
165
+ return neighbourhoodSendSignal
166
+ }
314
167
 
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);
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
- 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
- }
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
- 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);
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
- 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().
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
- /** 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
- }
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
  }