@coasys/ad4m 0.12.0-rc1-dev.2 → 0.12.0-rc1-dev.4

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 +6893 -5884
  3. package/lib/index.js +6889 -5872
  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 +3760 -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 +4386 -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,7 +1,6 @@
1
1
  import { ApolloClient, gql } from "@apollo/client/core";
2
2
  import { PerspectiveInput } from "../perspectives/Perspective";
3
3
  import unwrapApolloResult from "../unwrapApolloResult";
4
- import { isSocketCloseError } from "../utils";
5
4
  import {
6
5
  Agent,
7
6
  Apps,
@@ -88,16 +87,16 @@ export type AgentAppsUpdatedCallback = () => null;
88
87
  * as well as updating the publicly shared Agent expression.
89
88
  */
90
89
  export class AgentClient {
91
- private _apolloClient: ApolloClient<any>;
92
- private _appsChangedCallback: AgentAppsUpdatedCallback[];
93
- private _updatedCallbacks: AgentUpdatedCallback[];
94
- private _agentStatusChangedCallbacks: AgentStatusChangedCallback[];
90
+ #apolloClient: ApolloClient<any>;
91
+ #appsChangedCallback: AgentAppsUpdatedCallback[];
92
+ #updatedCallbacks: AgentUpdatedCallback[];
93
+ #agentStatusChangedCallbacks: AgentStatusChangedCallback[];
95
94
 
96
95
  constructor(client: ApolloClient<any>, subscribe: boolean = true) {
97
- this._apolloClient = client;
98
- this._updatedCallbacks = [];
99
- this._agentStatusChangedCallbacks = [];
100
- this._appsChangedCallback = [];
96
+ this.#apolloClient = client;
97
+ this.#updatedCallbacks = [];
98
+ this.#agentStatusChangedCallbacks = [];
99
+ this.#appsChangedCallback = [];
101
100
 
102
101
  if (subscribe) {
103
102
  this.subscribeAgentUpdated();
@@ -114,9 +113,9 @@ export class AgentClient {
114
113
  */
115
114
  async me(): Promise<Agent> {
116
115
  const { agent } = unwrapApolloResult(
117
- await this._apolloClient.query({
116
+ await this.#apolloClient.query({
118
117
  query: gql`query agent { agent { ${AGENT_SUBITEMS} } }`,
119
- }),
118
+ })
120
119
  );
121
120
  let agentObject = new Agent(agent.did, agent.perspective);
122
121
  agentObject.directMessageLanguage = agent.directMessageLanguage;
@@ -125,20 +124,20 @@ export class AgentClient {
125
124
 
126
125
  async status(): Promise<AgentStatus> {
127
126
  const { agentStatus } = unwrapApolloResult(
128
- await this._apolloClient.query({
127
+ await this.#apolloClient.query({
129
128
  query: gql`query agentStatus {
130
129
  agentStatus {
131
130
  ${AGENT_STATUS_FIELDS}
132
131
  }
133
132
  }`,
134
- }),
133
+ })
135
134
  );
136
135
  return new AgentStatus(agentStatus);
137
136
  }
138
137
 
139
138
  async generate(passphrase: string): Promise<AgentStatus> {
140
139
  const { agentGenerate } = unwrapApolloResult(
141
- await this._apolloClient.mutate({
140
+ await this.#apolloClient.mutate({
142
141
  mutation: gql`mutation agentGenerate(
143
142
  $passphrase: String!
144
143
  ) {
@@ -147,7 +146,7 @@ export class AgentClient {
147
146
  }
148
147
  }`,
149
148
  variables: { passphrase },
150
- }),
149
+ })
151
150
  );
152
151
  return new AgentStatus(agentGenerate);
153
152
  }
@@ -155,7 +154,7 @@ export class AgentClient {
155
154
  async import(args: InitializeArgs): Promise<AgentStatus> {
156
155
  let { did, didDocument, keystore, passphrase } = args;
157
156
  const { agentImport } = unwrapApolloResult(
158
- await this._apolloClient.mutate({
157
+ await this.#apolloClient.mutate({
159
158
  mutation: gql`mutation agentImport(
160
159
  $did: String!,
161
160
  $didDocument: String!,
@@ -167,49 +166,49 @@ export class AgentClient {
167
166
  }
168
167
  }`,
169
168
  variables: { did, didDocument, keystore, passphrase },
170
- }),
169
+ })
171
170
  );
172
171
  return new AgentStatus(agentImport);
173
172
  }
174
173
 
175
174
  async lock(passphrase: string): Promise<AgentStatus> {
176
175
  const { agentLock } = unwrapApolloResult(
177
- await this._apolloClient.mutate({
176
+ await this.#apolloClient.mutate({
178
177
  mutation: gql`mutation agentLock($passphrase: String!) {
179
178
  agentLock(passphrase: $passphrase) {
180
179
  ${AGENT_STATUS_FIELDS}
181
180
  }
182
181
  }`,
183
182
  variables: { passphrase },
184
- }),
183
+ })
185
184
  );
186
185
  return new AgentStatus(agentLock);
187
186
  }
188
187
 
189
188
  async unlock(passphrase: string, holochain = true): Promise<AgentStatus> {
190
189
  const { agentUnlock } = unwrapApolloResult(
191
- await this._apolloClient.mutate({
190
+ await this.#apolloClient.mutate({
192
191
  mutation: gql`mutation agentUnlock($passphrase: String!, $holochain: Boolean!) {
193
192
  agentUnlock(passphrase: $passphrase, holochain: $holochain) {
194
193
  ${AGENT_STATUS_FIELDS}
195
194
  }
196
195
  }`,
197
196
  variables: { passphrase, holochain },
198
- }),
197
+ })
199
198
  );
200
199
  return new AgentStatus(agentUnlock);
201
200
  }
202
201
 
203
202
  async byDID(did: string): Promise<Agent> {
204
203
  const { agentByDID } = unwrapApolloResult(
205
- await this._apolloClient.query({
204
+ await this.#apolloClient.query({
206
205
  query: gql`query agentByDID($did: String!) {
207
206
  agentByDID(did: $did) {
208
207
  ${AGENT_SUBITEMS}
209
208
  }
210
209
  }`,
211
210
  variables: { did },
212
- }),
211
+ })
213
212
  );
214
213
  return agentByDID as Agent;
215
214
  }
@@ -225,14 +224,14 @@ export class AgentClient {
225
224
  });
226
225
 
227
226
  const { agentUpdatePublicPerspective } = unwrapApolloResult(
228
- await this._apolloClient.mutate({
227
+ await this.#apolloClient.mutate({
229
228
  mutation: gql`mutation agentUpdatePublicPerspective($perspective: PerspectiveInput!) {
230
229
  agentUpdatePublicPerspective(perspective: $perspective) {
231
230
  ${AGENT_SUBITEMS}
232
231
  }
233
232
  }`,
234
233
  variables: { perspective: cleanedPerspective },
235
- }),
234
+ })
236
235
  );
237
236
  const a = agentUpdatePublicPerspective;
238
237
  const agent = new Agent(a.did, a.perspective);
@@ -241,12 +240,12 @@ export class AgentClient {
241
240
  }
242
241
 
243
242
  async mutatePublicPerspective(mutations: LinkMutations): Promise<Agent> {
244
- const perspectiveClient = new PerspectiveClient(this._apolloClient);
245
- const agentClient = new AgentClient(this._apolloClient);
243
+ const perspectiveClient = new PerspectiveClient(this.#apolloClient);
244
+ const agentClient = new AgentClient(this.#apolloClient);
246
245
 
247
246
  //Create the proxy perspective and load existing links
248
247
  const proxyPerspective = await perspectiveClient.add(
249
- "Agent Perspective Proxy",
248
+ "Agent Perspective Proxy"
250
249
  );
251
250
  const agentMe = await agentClient.me();
252
251
 
@@ -272,17 +271,17 @@ export class AgentClient {
272
271
  }
273
272
 
274
273
  async updateDirectMessageLanguage(
275
- directMessageLanguage: string,
274
+ directMessageLanguage: string
276
275
  ): Promise<Agent> {
277
276
  const { agentUpdateDirectMessageLanguage } = unwrapApolloResult(
278
- await this._apolloClient.mutate({
277
+ await this.#apolloClient.mutate({
279
278
  mutation: gql`mutation agentUpdateDirectMessageLanguage($directMessageLanguage: String!) {
280
279
  agentUpdateDirectMessageLanguage(directMessageLanguage: $directMessageLanguage) {
281
280
  ${AGENT_SUBITEMS}
282
281
  }
283
282
  }`,
284
283
  variables: { directMessageLanguage },
285
- }),
284
+ })
286
285
  );
287
286
  const a = agentUpdateDirectMessageLanguage;
288
287
  const agent = new Agent(a.did, a.perspective);
@@ -291,77 +290,77 @@ export class AgentClient {
291
290
  }
292
291
 
293
292
  async addEntanglementProofs(
294
- proofs: EntanglementProofInput[],
293
+ proofs: EntanglementProofInput[]
295
294
  ): Promise<EntanglementProof[]> {
296
295
  const { agentAddEntanglementProofs } = unwrapApolloResult(
297
- await this._apolloClient.mutate({
296
+ await this.#apolloClient.mutate({
298
297
  mutation: gql`mutation agentAddEntanglementProofs($proofs: [EntanglementProofInput!]!) {
299
298
  agentAddEntanglementProofs(proofs: $proofs) {
300
299
  ${ENTANGLEMENT_PROOF_FIELDS}
301
300
  }
302
301
  }`,
303
302
  variables: { proofs },
304
- }),
303
+ })
305
304
  );
306
305
  return agentAddEntanglementProofs;
307
306
  }
308
307
 
309
308
  async deleteEntanglementProofs(
310
- proofs: EntanglementProofInput[],
309
+ proofs: EntanglementProofInput[]
311
310
  ): Promise<EntanglementProof[]> {
312
311
  const { agentDeleteEntanglementProofs } = unwrapApolloResult(
313
- await this._apolloClient.mutate({
312
+ await this.#apolloClient.mutate({
314
313
  mutation: gql`mutation agentDeleteEntanglementProofs($proofs: [EntanglementProofInput!]!) {
315
314
  agentDeleteEntanglementProofs(proofs: $proofs) {
316
315
  ${ENTANGLEMENT_PROOF_FIELDS}
317
316
  }
318
317
  }`,
319
318
  variables: { proofs },
320
- }),
319
+ })
321
320
  );
322
321
  return agentDeleteEntanglementProofs;
323
322
  }
324
323
 
325
324
  async getEntanglementProofs(): Promise<string[]> {
326
325
  const { agentGetEntanglementProofs } = unwrapApolloResult(
327
- await this._apolloClient.query({
326
+ await this.#apolloClient.query({
328
327
  query: gql`query agentGetEntanglementProofs {
329
328
  agentGetEntanglementProofs {
330
329
  ${ENTANGLEMENT_PROOF_FIELDS}
331
330
  }
332
331
  }`,
333
- }),
332
+ })
334
333
  );
335
334
  return agentGetEntanglementProofs;
336
335
  }
337
336
 
338
337
  async entanglementProofPreFlight(
339
338
  deviceKey: string,
340
- deviceKeyType: string,
339
+ deviceKeyType: string
341
340
  ): Promise<EntanglementProof> {
342
341
  const { agentEntanglementProofPreFlight } = unwrapApolloResult(
343
- await this._apolloClient.mutate({
342
+ await this.#apolloClient.mutate({
344
343
  mutation: gql`mutation agentEntanglementProofPreFlight($deviceKey: String!, $deviceKeyType: String!) {
345
344
  agentEntanglementProofPreFlight(deviceKey: $deviceKey, deviceKeyType: $deviceKeyType) {
346
345
  ${ENTANGLEMENT_PROOF_FIELDS}
347
346
  }
348
347
  }`,
349
348
  variables: { deviceKey, deviceKeyType },
350
- }),
349
+ })
351
350
  );
352
351
  return agentEntanglementProofPreFlight;
353
352
  }
354
353
 
355
354
  addUpdatedListener(listener) {
356
- this._updatedCallbacks.push(listener);
355
+ this.#updatedCallbacks.push(listener);
357
356
  }
358
357
 
359
358
  addAppChangedListener(listener) {
360
- this._appsChangedCallback.push(listener);
359
+ this.#appsChangedCallback.push(listener);
361
360
  }
362
361
 
363
362
  subscribeAgentUpdated() {
364
- this._apolloClient
363
+ this.#apolloClient
365
364
  .subscribe({
366
365
  query: gql` subscription {
367
366
  agentUpdated { ${AGENT_SUBITEMS} }
@@ -371,18 +370,16 @@ export class AgentClient {
371
370
  .subscribe({
372
371
  next: (result) => {
373
372
  const agent = result.data.agentUpdated;
374
- this._updatedCallbacks.forEach((cb) => {
373
+ this.#updatedCallbacks.forEach((cb) => {
375
374
  cb(agent);
376
375
  });
377
376
  },
378
- error: (e) => {
379
- if (!isSocketCloseError(e)) console.error(e);
380
- },
377
+ error: (e) => console.error(e),
381
378
  });
382
379
  }
383
380
 
384
381
  subscribeAppsChanged() {
385
- this._apolloClient
382
+ this.#apolloClient
386
383
  .subscribe({
387
384
  query: gql` subscription {
388
385
  agentAppsChanged {
@@ -393,22 +390,20 @@ export class AgentClient {
393
390
  })
394
391
  .subscribe({
395
392
  next: (result) => {
396
- this._appsChangedCallback.forEach((cb) => {
393
+ this.#appsChangedCallback.forEach((cb) => {
397
394
  cb();
398
395
  });
399
396
  },
400
- error: (e) => {
401
- if (!isSocketCloseError(e)) console.error(e);
402
- },
397
+ error: (e) => console.error(e),
403
398
  });
404
399
  }
405
400
 
406
401
  addAgentStatusChangedListener(listener) {
407
- this._agentStatusChangedCallbacks.push(listener);
402
+ this.#agentStatusChangedCallbacks.push(listener);
408
403
  }
409
404
 
410
405
  subscribeAgentStatusChanged() {
411
- this._apolloClient
406
+ this.#apolloClient
412
407
  .subscribe({
413
408
  query: gql` subscription {
414
409
  agentStatusChanged { ${AGENT_STATUS_FIELDS} }
@@ -418,218 +413,178 @@ export class AgentClient {
418
413
  .subscribe({
419
414
  next: (result) => {
420
415
  const agent = result.data.agentStatusChanged;
421
- this._agentStatusChangedCallbacks.forEach((cb) => {
416
+ this.#agentStatusChangedCallbacks.forEach((cb) => {
422
417
  cb(agent);
423
418
  });
424
419
  },
425
- error: (e) => {
426
- if (!isSocketCloseError(e)) console.error(e);
427
- },
420
+ error: (e) => console.error(e),
428
421
  });
429
422
  }
430
423
 
431
424
  async requestCapability(authInfo: AuthInfoInput): Promise<string> {
432
425
  const { agentRequestCapability } = unwrapApolloResult(
433
- await this._apolloClient.mutate({
426
+ await this.#apolloClient.mutate({
434
427
  mutation: gql`
435
428
  mutation agentRequestCapability($authInfo: AuthInfoInput!) {
436
429
  agentRequestCapability(authInfo: $authInfo)
437
430
  }
438
431
  `,
439
432
  variables: { authInfo },
440
- }),
433
+ })
441
434
  );
442
435
  return agentRequestCapability;
443
436
  }
444
437
 
445
438
  async permitCapability(auth: string): Promise<string> {
446
439
  const { agentPermitCapability } = unwrapApolloResult(
447
- await this._apolloClient.mutate({
440
+ await this.#apolloClient.mutate({
448
441
  mutation: gql`
449
442
  mutation agentPermitCapability($auth: String!) {
450
443
  agentPermitCapability(auth: $auth)
451
444
  }
452
445
  `,
453
446
  variables: { auth },
454
- }),
447
+ })
455
448
  );
456
449
  return agentPermitCapability;
457
450
  }
458
451
 
459
452
  async generateJwt(requestId: string, rand: string): Promise<string> {
460
453
  const { agentGenerateJwt } = unwrapApolloResult(
461
- await this._apolloClient.mutate({
454
+ await this.#apolloClient.mutate({
462
455
  mutation: gql`
463
456
  mutation agentGenerateJwt($requestId: String!, $rand: String!) {
464
457
  agentGenerateJwt(requestId: $requestId, rand: $rand)
465
458
  }
466
459
  `,
467
460
  variables: { requestId, rand },
468
- }),
461
+ })
469
462
  );
470
463
  return agentGenerateJwt;
471
464
  }
472
465
 
473
466
  async getApps(): Promise<Apps[]> {
474
467
  const { agentGetApps } = unwrapApolloResult(
475
- await this._apolloClient.mutate({
468
+ await this.#apolloClient.mutate({
476
469
  mutation: gql`query agentGetApps {
477
470
  agentGetApps {
478
471
  ${Apps_FIELDS}
479
472
  }
480
473
  }`,
481
- }),
474
+ })
482
475
  );
483
476
  return agentGetApps;
484
477
  }
485
478
 
486
479
  async removeApp(requestId: string): Promise<Apps[]> {
487
480
  const { agentRemoveApp } = unwrapApolloResult(
488
- await this._apolloClient.mutate({
481
+ await this.#apolloClient.mutate({
489
482
  mutation: gql`mutation agentRemoveApp($requestId: String!) {
490
483
  agentRemoveApp(requestId: $requestId) {
491
484
  ${Apps_FIELDS}
492
485
  }
493
486
  }`,
494
487
  variables: { requestId },
495
- }),
488
+ })
496
489
  );
497
490
  return agentRemoveApp;
498
491
  }
499
492
 
500
493
  async revokeToken(requestId: string): Promise<Apps[]> {
501
494
  const { agentRevokeToken } = unwrapApolloResult(
502
- await this._apolloClient.mutate({
495
+ await this.#apolloClient.mutate({
503
496
  mutation: gql`mutation agentRevokeToken($requestId: String!) {
504
497
  agentRevokeToken(requestId: $requestId) {
505
498
  ${Apps_FIELDS}
506
499
  }
507
500
  }`,
508
501
  variables: { requestId },
509
- }),
502
+ })
510
503
  );
511
504
  return agentRevokeToken;
512
505
  }
513
506
 
514
507
  async isLocked(): Promise<boolean> {
515
508
  const { agentIsLocked } = unwrapApolloResult(
516
- await this._apolloClient.mutate({
509
+ await this.#apolloClient.mutate({
517
510
  mutation: gql`
518
511
  query agentIsLocked {
519
512
  agentIsLocked
520
513
  }
521
514
  `,
522
- }),
515
+ })
523
516
  );
524
517
  return agentIsLocked;
525
518
  }
526
519
 
527
520
  async signMessage(message: string): Promise<string> {
528
521
  const { agentSignMessage } = unwrapApolloResult(
529
- await this._apolloClient.mutate({
522
+ await this.#apolloClient.mutate({
530
523
  mutation: gql`mutation agentSignMessage($message: String!) {
531
524
  agentSignMessage(message: $message) {
532
525
  ${AGENT_SIGNATURE_FIELDS}
533
526
  }
534
527
  }`,
535
528
  variables: { message },
536
- }),
529
+ })
537
530
  );
538
531
  return agentSignMessage;
539
532
  }
540
533
 
541
534
  // Multi-user methods
542
- async createUser(
543
- email: string,
544
- password: string,
545
- appInfo?: AuthInfoInput,
546
- ): Promise<UserCreationResult> {
535
+ async createUser(email: string, password: string, appInfo?: AuthInfoInput): Promise<UserCreationResult> {
547
536
  const { runtimeCreateUser } = unwrapApolloResult(
548
- await this._apolloClient.mutate({
549
- mutation: gql`
550
- mutation runtimeCreateUser(
551
- $email: String!
552
- $password: String!
553
- $appInfo: AuthInfoInput
554
- ) {
555
- runtimeCreateUser(
556
- email: $email
557
- password: $password
558
- appInfo: $appInfo
559
- ) {
560
- did
561
- success
562
- error
563
- }
537
+ await this.#apolloClient.mutate({
538
+ mutation: gql`mutation runtimeCreateUser($email: String!, $password: String!, $appInfo: AuthInfoInput) {
539
+ runtimeCreateUser(email: $email, password: $password, appInfo: $appInfo) {
540
+ did
541
+ success
542
+ error
564
543
  }
565
- `,
544
+ }`,
566
545
  variables: { email, password, appInfo },
567
- }),
546
+ })
568
547
  );
569
548
  return runtimeCreateUser;
570
549
  }
571
550
 
572
551
  async loginUser(email: string, password: string): Promise<string> {
573
552
  const { runtimeLoginUser } = unwrapApolloResult(
574
- await this._apolloClient.mutate({
575
- mutation: gql`
576
- mutation runtimeLoginUser($email: String!, $password: String!) {
577
- runtimeLoginUser(email: $email, password: $password)
578
- }
579
- `,
553
+ await this.#apolloClient.mutate({
554
+ mutation: gql`mutation runtimeLoginUser($email: String!, $password: String!) {
555
+ runtimeLoginUser(email: $email, password: $password)
556
+ }`,
580
557
  variables: { email, password },
581
- }),
558
+ })
582
559
  );
583
560
  return runtimeLoginUser;
584
561
  }
585
562
 
586
- async requestLoginVerification(
587
- email: string,
588
- appInfo?: AuthInfoInput,
589
- ): Promise<VerificationRequestResult> {
563
+ async requestLoginVerification(email: string, appInfo?: AuthInfoInput): Promise<VerificationRequestResult> {
590
564
  const { runtimeRequestLoginVerification } = unwrapApolloResult(
591
- await this._apolloClient.mutate({
592
- mutation: gql`
593
- mutation runtimeRequestLoginVerification(
594
- $email: String!
595
- $appInfo: AuthInfoInput
596
- ) {
597
- runtimeRequestLoginVerification(email: $email, appInfo: $appInfo) {
598
- success
599
- message
600
- requiresPassword
601
- isExistingUser
602
- }
565
+ await this.#apolloClient.mutate({
566
+ mutation: gql`mutation runtimeRequestLoginVerification($email: String!, $appInfo: AuthInfoInput) {
567
+ runtimeRequestLoginVerification(email: $email, appInfo: $appInfo) {
568
+ success
569
+ message
570
+ requiresPassword
571
+ isExistingUser
603
572
  }
604
- `,
573
+ }`,
605
574
  variables: { email, appInfo },
606
- }),
575
+ })
607
576
  );
608
577
  return runtimeRequestLoginVerification;
609
578
  }
610
579
 
611
- async verifyEmailCode(
612
- email: string,
613
- code: string,
614
- verificationType: string,
615
- ): Promise<string> {
580
+ async verifyEmailCode(email: string, code: string, verificationType: string): Promise<string> {
616
581
  const { runtimeVerifyEmailCode } = unwrapApolloResult(
617
- await this._apolloClient.mutate({
618
- mutation: gql`
619
- mutation runtimeVerifyEmailCode(
620
- $email: String!
621
- $code: String!
622
- $verificationType: String!
623
- ) {
624
- runtimeVerifyEmailCode(
625
- email: $email
626
- code: $code
627
- verificationType: $verificationType
628
- )
629
- }
630
- `,
582
+ await this.#apolloClient.mutate({
583
+ mutation: gql`mutation runtimeVerifyEmailCode($email: String!, $code: String!, $verificationType: String!) {
584
+ runtimeVerifyEmailCode(email: $email, code: $code, verificationType: $verificationType)
585
+ }`,
631
586
  variables: { email, code, verificationType },
632
- }),
587
+ })
633
588
  );
634
589
  return runtimeVerifyEmailCode;
635
590
  }