@coasys/ad4m 0.8.0 → 0.8.2-prerelease

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 (66) hide show
  1. package/lib/index.cjs +29 -53
  2. package/lib/index.js +8085 -0
  3. package/lib/shims/reflect-metadata.js +0 -0
  4. package/lib/shims/type-graphql.js +70 -0
  5. package/lib/src/Ad4mClient.js +66 -0
  6. package/lib/src/Address.js +1 -0
  7. package/lib/src/DID.js +1 -0
  8. package/lib/src/Exception.js +7 -0
  9. package/lib/src/Literal.js +76 -0
  10. package/lib/src/PubSub.js +14 -0
  11. package/lib/src/SmartLiteral.js +74 -0
  12. package/lib/src/agent/Agent.js +337 -0
  13. package/lib/src/agent/AgentClient.js +431 -0
  14. package/lib/src/agent/AgentResolver.js +325 -0
  15. package/lib/src/agent/AgentStatus.js +61 -0
  16. package/lib/src/buildSchema.js +36 -0
  17. package/lib/src/expression/Expression.js +143 -0
  18. package/lib/src/expression/ExpressionClient.js +102 -0
  19. package/lib/src/expression/ExpressionRef.js +67 -0
  20. package/lib/src/expression/ExpressionResolver.js +106 -0
  21. package/lib/src/index.js +30 -0
  22. package/lib/src/jestSetup.js +1 -0
  23. package/lib/src/language/Icon.js +24 -0
  24. package/lib/src/language/Language.js +79 -0
  25. package/lib/src/language/LanguageClient.js +137 -0
  26. package/lib/src/language/LanguageContext.js +2 -0
  27. package/lib/src/language/LanguageHandle.js +41 -0
  28. package/lib/src/language/LanguageMeta.js +89 -0
  29. package/lib/src/language/LanguageRef.js +30 -0
  30. package/lib/src/language/LanguageResolver.js +143 -0
  31. package/lib/src/links/Links.js +148 -0
  32. package/lib/src/links/Links.test.js +33 -0
  33. package/lib/src/neighbourhood/Neighbourhood.js +38 -0
  34. package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -0
  35. package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -0
  36. package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -0
  37. package/lib/src/perspectives/LinkQuery.js +80 -0
  38. package/lib/src/perspectives/Perspective.js +144 -0
  39. package/lib/src/perspectives/Perspective.test.js +20 -0
  40. package/lib/src/perspectives/PerspectiveClient.d.ts +1 -0
  41. package/lib/src/perspectives/PerspectiveClient.js +418 -0
  42. package/lib/src/perspectives/PerspectiveDiff.js +33 -0
  43. package/lib/src/perspectives/PerspectiveHandle.js +59 -0
  44. package/lib/src/perspectives/PerspectiveProxy.d.ts +8 -8
  45. package/lib/src/perspectives/PerspectiveProxy.js +501 -0
  46. package/lib/src/perspectives/PerspectiveResolver.d.ts +1 -0
  47. package/lib/src/perspectives/PerspectiveResolver.js +376 -0
  48. package/lib/src/runtime/RuntimeClient.js +263 -0
  49. package/lib/src/runtime/RuntimeResolver.js +328 -0
  50. package/lib/src/schema.gql +1 -0
  51. package/lib/src/subject/SDNADecorators.js +250 -0
  52. package/lib/src/subject/Subject.js +164 -0
  53. package/lib/src/subject/SubjectEntity.js +250 -0
  54. package/lib/src/subject/util.js +73 -0
  55. package/lib/src/typeDefs.js +380 -0
  56. package/lib/src/unwrapApolloResult.js +14 -0
  57. package/lib/src/utils.js +21 -0
  58. package/package.json +9 -2
  59. package/patches/graphql@15.7.2.patch +39 -0
  60. package/pnpm-workspace.yaml +19 -0
  61. package/src/Ad4mClient.test.ts +5 -0
  62. package/src/perspectives/PerspectiveClient.ts +9 -0
  63. package/src/perspectives/PerspectiveProxy.ts +22 -56
  64. package/src/perspectives/PerspectiveResolver.ts +5 -0
  65. package/src/subject/Subject.ts +9 -6
  66. package/src/unwrapApolloResult.ts +3 -1
@@ -0,0 +1,431 @@
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 _AgentClient_apolloClient, _AgentClient_appsChangedCallback, _AgentClient_updatedCallbacks, _AgentClient_agentStatusChangedCallbacks;
13
+ import { gql } from "@apollo/client/core";
14
+ import unwrapApolloResult from "../unwrapApolloResult";
15
+ import { Agent, } from "./Agent";
16
+ import { AgentStatus } from "./AgentStatus";
17
+ import { PerspectiveClient } from "../perspectives/PerspectiveClient";
18
+ const AGENT_SUBITEMS = `
19
+ did
20
+ directMessageLanguage
21
+ perspective {
22
+ links {
23
+ author, timestamp,
24
+ proof {
25
+ signature, key, valid, invalid
26
+ }
27
+ data {
28
+ source, predicate, target
29
+ }
30
+ }
31
+ }
32
+ `;
33
+ const Apps_FIELDS = `
34
+ requestId
35
+ revoked
36
+ auth {
37
+ appName
38
+ appDesc
39
+ appUrl
40
+ appIconPath
41
+ capabilities {
42
+ with {
43
+ domain
44
+ pointers
45
+ }
46
+ can
47
+ }
48
+ }
49
+ `;
50
+ const AGENT_STATUS_FIELDS = `
51
+ isInitialized
52
+ isUnlocked
53
+ did
54
+ didDocument
55
+ error
56
+ `;
57
+ const ENTANGLEMENT_PROOF_FIELDS = `
58
+ did
59
+ didSigningKeyId
60
+ deviceKeyType
61
+ deviceKey
62
+ deviceKeySignedByDid
63
+ didSignedByDeviceKey
64
+ `;
65
+ const AGENT_SIGNATURE_FIELDS = `
66
+ signature
67
+ publicKey
68
+ `;
69
+ /**
70
+ * Provides access to all functions regarding the local agent,
71
+ * such as generating, locking, unlocking, importing the DID keystore,
72
+ * as well as updating the publicly shared Agent expression.
73
+ */
74
+ export class AgentClient {
75
+ constructor(client, subscribe = true) {
76
+ _AgentClient_apolloClient.set(this, void 0);
77
+ _AgentClient_appsChangedCallback.set(this, void 0);
78
+ _AgentClient_updatedCallbacks.set(this, void 0);
79
+ _AgentClient_agentStatusChangedCallbacks.set(this, void 0);
80
+ __classPrivateFieldSet(this, _AgentClient_apolloClient, client, "f");
81
+ __classPrivateFieldSet(this, _AgentClient_updatedCallbacks, [], "f");
82
+ __classPrivateFieldSet(this, _AgentClient_agentStatusChangedCallbacks, [], "f");
83
+ __classPrivateFieldSet(this, _AgentClient_appsChangedCallback, [], "f");
84
+ if (subscribe) {
85
+ this.subscribeAgentUpdated();
86
+ this.subscribeAgentStatusChanged();
87
+ this.subscribeAppsChanged();
88
+ }
89
+ }
90
+ /**
91
+ * Returns the Agent expression of the local agent as it is shared
92
+ * publicly via the AgentLanguage.
93
+ *
94
+ * I.e. this is the users profile.
95
+ */
96
+ async me() {
97
+ const { agent } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").query({
98
+ query: gql `query agent { agent { ${AGENT_SUBITEMS} } }`,
99
+ }));
100
+ let agentObject = new Agent(agent.did, agent.perspective);
101
+ agentObject.directMessageLanguage = agent.directMessageLanguage;
102
+ return agentObject;
103
+ }
104
+ async status() {
105
+ const { agentStatus } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").query({
106
+ query: gql `query agentStatus {
107
+ agentStatus {
108
+ ${AGENT_STATUS_FIELDS}
109
+ }
110
+ }`,
111
+ }));
112
+ return new AgentStatus(agentStatus);
113
+ }
114
+ async generate(passphrase) {
115
+ const { agentGenerate } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
116
+ mutation: gql `mutation agentGenerate(
117
+ $passphrase: String!
118
+ ) {
119
+ agentGenerate(passphrase: $passphrase) {
120
+ ${AGENT_STATUS_FIELDS}
121
+ }
122
+ }`,
123
+ variables: { passphrase },
124
+ }));
125
+ return new AgentStatus(agentGenerate);
126
+ }
127
+ async import(args) {
128
+ let { did, didDocument, keystore, passphrase } = args;
129
+ const { agentImport } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
130
+ mutation: gql `mutation agentImport(
131
+ $did: String!,
132
+ $didDocument: String!,
133
+ $keystore: String!,
134
+ $passphrase: String!
135
+ ) {
136
+ agentImport(did: $did, didDocument: $didDocument, keystore: $keystore, passphrase: $passphrase) {
137
+ ${AGENT_STATUS_FIELDS}
138
+ }
139
+ }`,
140
+ variables: { did, didDocument, keystore, passphrase },
141
+ }));
142
+ return new AgentStatus(agentImport);
143
+ }
144
+ async lock(passphrase) {
145
+ const { agentLock } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
146
+ mutation: gql `mutation agentLock($passphrase: String!) {
147
+ agentLock(passphrase: $passphrase) {
148
+ ${AGENT_STATUS_FIELDS}
149
+ }
150
+ }`,
151
+ variables: { passphrase },
152
+ }));
153
+ return new AgentStatus(agentLock);
154
+ }
155
+ async unlock(passphrase, holochain = true) {
156
+ const { agentUnlock } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
157
+ mutation: gql `mutation agentUnlock($passphrase: String!, $holochain: Boolean!) {
158
+ agentUnlock(passphrase: $passphrase, holochain: $holochain) {
159
+ ${AGENT_STATUS_FIELDS}
160
+ }
161
+ }`,
162
+ variables: { passphrase, holochain },
163
+ }));
164
+ return new AgentStatus(agentUnlock);
165
+ }
166
+ async byDID(did) {
167
+ const { agentByDID } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").query({
168
+ query: gql `query agentByDID($did: String!) {
169
+ agentByDID(did: $did) {
170
+ ${AGENT_SUBITEMS}
171
+ }
172
+ }`,
173
+ variables: { did },
174
+ }));
175
+ return agentByDID;
176
+ }
177
+ async updatePublicPerspective(perspective) {
178
+ const cleanedPerspective = JSON.parse(JSON.stringify(perspective));
179
+ delete cleanedPerspective.__typename;
180
+ cleanedPerspective.links.forEach((link) => {
181
+ delete link.__typename;
182
+ delete link.data.__typename;
183
+ delete link.proof.__typename;
184
+ delete link.status;
185
+ });
186
+ const { agentUpdatePublicPerspective } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
187
+ mutation: gql `mutation agentUpdatePublicPerspective($perspective: PerspectiveInput!) {
188
+ agentUpdatePublicPerspective(perspective: $perspective) {
189
+ ${AGENT_SUBITEMS}
190
+ }
191
+ }`,
192
+ variables: { perspective: cleanedPerspective },
193
+ }));
194
+ const a = agentUpdatePublicPerspective;
195
+ const agent = new Agent(a.did, a.perspective);
196
+ agent.directMessageLanguage = a.directMessageLanguage;
197
+ return agent;
198
+ }
199
+ async mutatePublicPerspective(mutations) {
200
+ const perspectiveClient = new PerspectiveClient(__classPrivateFieldGet(this, _AgentClient_apolloClient, "f"));
201
+ const agentClient = new AgentClient(__classPrivateFieldGet(this, _AgentClient_apolloClient, "f"));
202
+ //Create the proxy perspective and load existing links
203
+ const proxyPerspective = await perspectiveClient.add("Agent Perspective Proxy");
204
+ const agentMe = await agentClient.me();
205
+ if (agentMe.perspective) {
206
+ await proxyPerspective.loadSnapshot(agentMe.perspective);
207
+ }
208
+ //Make the mutations on the proxy perspective
209
+ for (const addition of mutations.additions) {
210
+ await proxyPerspective.add(addition);
211
+ }
212
+ for (const removal of mutations.removals) {
213
+ await proxyPerspective.remove(removal);
214
+ }
215
+ //Get the snapshot of the proxy perspective
216
+ const snapshot = await proxyPerspective.snapshot();
217
+ //Update the users public perspective
218
+ const agent = await this.updatePublicPerspective(snapshot);
219
+ //Cleanup and return
220
+ await perspectiveClient.remove(proxyPerspective.uuid);
221
+ return agent;
222
+ }
223
+ async updateDirectMessageLanguage(directMessageLanguage) {
224
+ const { agentUpdateDirectMessageLanguage } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
225
+ mutation: gql `mutation agentUpdateDirectMessageLanguage($directMessageLanguage: String!) {
226
+ agentUpdateDirectMessageLanguage(directMessageLanguage: $directMessageLanguage) {
227
+ ${AGENT_SUBITEMS}
228
+ }
229
+ }`,
230
+ variables: { directMessageLanguage },
231
+ }));
232
+ const a = agentUpdateDirectMessageLanguage;
233
+ const agent = new Agent(a.did, a.perspective);
234
+ agent.directMessageLanguage = a.directMessageLanguage;
235
+ return agent;
236
+ }
237
+ async addEntanglementProofs(proofs) {
238
+ const { agentAddEntanglementProofs } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
239
+ mutation: gql `mutation agentAddEntanglementProofs($proofs: [EntanglementProofInput!]!) {
240
+ agentAddEntanglementProofs(proofs: $proofs) {
241
+ ${ENTANGLEMENT_PROOF_FIELDS}
242
+ }
243
+ }`,
244
+ variables: { proofs },
245
+ }));
246
+ return agentAddEntanglementProofs;
247
+ }
248
+ async deleteEntanglementProofs(proofs) {
249
+ const { agentDeleteEntanglementProofs } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
250
+ mutation: gql `mutation agentDeleteEntanglementProofs($proofs: [EntanglementProofInput!]!) {
251
+ agentDeleteEntanglementProofs(proofs: $proofs) {
252
+ ${ENTANGLEMENT_PROOF_FIELDS}
253
+ }
254
+ }`,
255
+ variables: { proofs },
256
+ }));
257
+ return agentDeleteEntanglementProofs;
258
+ }
259
+ async getEntanglementProofs() {
260
+ const { agentGetEntanglementProofs } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").query({
261
+ query: gql `query agentGetEntanglementProofs {
262
+ agentGetEntanglementProofs {
263
+ ${ENTANGLEMENT_PROOF_FIELDS}
264
+ }
265
+ }`,
266
+ }));
267
+ return agentGetEntanglementProofs;
268
+ }
269
+ async entanglementProofPreFlight(deviceKey, deviceKeyType) {
270
+ const { agentEntanglementProofPreFlight } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
271
+ mutation: gql `mutation agentEntanglementProofPreFlight($deviceKey: String!, $deviceKeyType: String!) {
272
+ agentEntanglementProofPreFlight(deviceKey: $deviceKey, deviceKeyType: $deviceKeyType) {
273
+ ${ENTANGLEMENT_PROOF_FIELDS}
274
+ }
275
+ }`,
276
+ variables: { deviceKey, deviceKeyType },
277
+ }));
278
+ return agentEntanglementProofPreFlight;
279
+ }
280
+ addUpdatedListener(listener) {
281
+ __classPrivateFieldGet(this, _AgentClient_updatedCallbacks, "f").push(listener);
282
+ }
283
+ addAppChangedListener(listener) {
284
+ __classPrivateFieldGet(this, _AgentClient_appsChangedCallback, "f").push(listener);
285
+ }
286
+ subscribeAgentUpdated() {
287
+ __classPrivateFieldGet(this, _AgentClient_apolloClient, "f")
288
+ .subscribe({
289
+ query: gql ` subscription {
290
+ agentUpdated { ${AGENT_SUBITEMS} }
291
+ }
292
+ `,
293
+ })
294
+ .subscribe({
295
+ next: (result) => {
296
+ const agent = result.data.agentUpdated;
297
+ __classPrivateFieldGet(this, _AgentClient_updatedCallbacks, "f").forEach((cb) => {
298
+ cb(agent);
299
+ });
300
+ },
301
+ error: (e) => console.error(e),
302
+ });
303
+ }
304
+ subscribeAppsChanged() {
305
+ __classPrivateFieldGet(this, _AgentClient_apolloClient, "f")
306
+ .subscribe({
307
+ query: gql ` subscription {
308
+ agentAppsChanged {
309
+ ${Apps_FIELDS}
310
+ }
311
+ }
312
+ `,
313
+ })
314
+ .subscribe({
315
+ next: (result) => {
316
+ __classPrivateFieldGet(this, _AgentClient_appsChangedCallback, "f").forEach((cb) => {
317
+ cb();
318
+ });
319
+ },
320
+ error: (e) => console.error(e),
321
+ });
322
+ }
323
+ addAgentStatusChangedListener(listener) {
324
+ __classPrivateFieldGet(this, _AgentClient_agentStatusChangedCallbacks, "f").push(listener);
325
+ }
326
+ subscribeAgentStatusChanged() {
327
+ __classPrivateFieldGet(this, _AgentClient_apolloClient, "f")
328
+ .subscribe({
329
+ query: gql ` subscription {
330
+ agentStatusChanged { ${AGENT_STATUS_FIELDS} }
331
+ }
332
+ `,
333
+ })
334
+ .subscribe({
335
+ next: (result) => {
336
+ const agent = result.data.agentStatusChanged;
337
+ __classPrivateFieldGet(this, _AgentClient_agentStatusChangedCallbacks, "f").forEach((cb) => {
338
+ cb(agent);
339
+ });
340
+ },
341
+ error: (e) => console.error(e),
342
+ });
343
+ }
344
+ async requestCapability(authInfo) {
345
+ const { agentRequestCapability } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
346
+ mutation: gql `
347
+ mutation agentRequestCapability($authInfo: AuthInfoInput!) {
348
+ agentRequestCapability(authInfo: $authInfo)
349
+ }
350
+ `,
351
+ variables: { authInfo },
352
+ }));
353
+ return agentRequestCapability;
354
+ }
355
+ async permitCapability(auth) {
356
+ const { agentPermitCapability } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
357
+ mutation: gql `
358
+ mutation agentPermitCapability($auth: String!) {
359
+ agentPermitCapability(auth: $auth)
360
+ }
361
+ `,
362
+ variables: { auth },
363
+ }));
364
+ return agentPermitCapability;
365
+ }
366
+ async generateJwt(requestId, rand) {
367
+ const { agentGenerateJwt } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
368
+ mutation: gql `
369
+ mutation agentGenerateJwt($requestId: String!, $rand: String!) {
370
+ agentGenerateJwt(requestId: $requestId, rand: $rand)
371
+ }
372
+ `,
373
+ variables: { requestId, rand },
374
+ }));
375
+ return agentGenerateJwt;
376
+ }
377
+ async getApps() {
378
+ const { agentGetApps } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
379
+ mutation: gql `query agentGetApps {
380
+ agentGetApps {
381
+ ${Apps_FIELDS}
382
+ }
383
+ }`,
384
+ }));
385
+ return agentGetApps;
386
+ }
387
+ async removeApp(requestId) {
388
+ const { agentRemoveApp } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
389
+ mutation: gql `mutation agentRemoveApp($requestId: String!) {
390
+ agentRemoveApp(requestId: $requestId) {
391
+ ${Apps_FIELDS}
392
+ }
393
+ }`,
394
+ variables: { requestId },
395
+ }));
396
+ return agentRemoveApp;
397
+ }
398
+ async revokeToken(requestId) {
399
+ const { agentRevokeToken } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
400
+ mutation: gql `mutation agentRevokeToken($requestId: String!) {
401
+ agentRevokeToken(requestId: $requestId) {
402
+ ${Apps_FIELDS}
403
+ }
404
+ }`,
405
+ variables: { requestId },
406
+ }));
407
+ return agentRevokeToken;
408
+ }
409
+ async isLocked() {
410
+ const { agentIsLocked } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
411
+ mutation: gql `
412
+ query agentIsLocked {
413
+ agentIsLocked
414
+ }
415
+ `,
416
+ }));
417
+ return agentIsLocked;
418
+ }
419
+ async signMessage(message) {
420
+ const { agentSignMessage } = unwrapApolloResult(await __classPrivateFieldGet(this, _AgentClient_apolloClient, "f").mutate({
421
+ mutation: gql `mutation agentSignMessage($message: String!) {
422
+ agentSignMessage(message: $message) {
423
+ ${AGENT_SIGNATURE_FIELDS}
424
+ }
425
+ }`,
426
+ variables: { message },
427
+ }));
428
+ return agentSignMessage;
429
+ }
430
+ }
431
+ _AgentClient_apolloClient = new WeakMap(), _AgentClient_appsChangedCallback = new WeakMap(), _AgentClient_updatedCallbacks = new WeakMap(), _AgentClient_agentStatusChangedCallbacks = new WeakMap();