@coasys/ad4m 0.8.0-fix → 0.8.1

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 (161) hide show
  1. package/README.md +229 -229
  2. package/jest.config.js +5 -5
  3. package/jsdoc.json +27 -27
  4. package/lib/index.cjs +4522 -4571
  5. package/lib/index.js +4522 -4571
  6. package/lib/shims/type-graphql.d.ts +32 -32
  7. package/lib/shims/type-graphql.js +70 -70
  8. package/lib/src/Ad4mClient.d.ts +26 -26
  9. package/lib/src/Ad4mClient.js +66 -66
  10. package/lib/src/Address.d.ts +1 -1
  11. package/lib/src/Address.js +1 -1
  12. package/lib/src/DID.d.ts +1 -1
  13. package/lib/src/DID.js +1 -1
  14. package/lib/src/Exception.d.ts +6 -6
  15. package/lib/src/Exception.js +7 -7
  16. package/lib/src/Literal.d.ts +7 -7
  17. package/lib/src/Literal.js +76 -76
  18. package/lib/src/PubSub.d.ts +14 -14
  19. package/lib/src/PubSub.js +14 -14
  20. package/lib/src/SmartLiteral.d.ts +12 -12
  21. package/lib/src/SmartLiteral.js +74 -74
  22. package/lib/src/agent/Agent.d.ts +104 -104
  23. package/lib/src/agent/Agent.js +337 -337
  24. package/lib/src/agent/AgentClient.d.ts +57 -57
  25. package/lib/src/agent/AgentClient.js +431 -431
  26. package/lib/src/agent/AgentResolver.d.ts +30 -30
  27. package/lib/src/agent/AgentResolver.js +325 -325
  28. package/lib/src/agent/AgentStatus.d.ts +8 -8
  29. package/lib/src/agent/AgentStatus.js +61 -61
  30. package/lib/src/buildSchema.d.ts +1 -1
  31. package/lib/src/buildSchema.js +36 -36
  32. package/lib/src/expression/Expression.d.ts +28 -28
  33. package/lib/src/expression/Expression.js +143 -143
  34. package/lib/src/expression/ExpressionClient.d.ts +13 -13
  35. package/lib/src/expression/ExpressionClient.js +102 -102
  36. package/lib/src/expression/ExpressionRef.d.ts +9 -9
  37. package/lib/src/expression/ExpressionRef.js +67 -67
  38. package/lib/src/expression/ExpressionResolver.d.ts +10 -10
  39. package/lib/src/expression/ExpressionResolver.js +106 -106
  40. package/lib/src/index.d.ts +30 -30
  41. package/lib/src/index.js +30 -30
  42. package/lib/src/jestSetup.d.ts +1 -1
  43. package/lib/src/jestSetup.js +1 -1
  44. package/lib/src/language/Icon.d.ts +4 -4
  45. package/lib/src/language/Icon.js +24 -24
  46. package/lib/src/language/Language.d.ts +195 -195
  47. package/lib/src/language/Language.js +79 -79
  48. package/lib/src/language/LanguageClient.d.ts +17 -17
  49. package/lib/src/language/LanguageClient.js +137 -137
  50. package/lib/src/language/LanguageContext.d.ts +37 -37
  51. package/lib/src/language/LanguageContext.js +2 -2
  52. package/lib/src/language/LanguageHandle.d.ts +9 -9
  53. package/lib/src/language/LanguageHandle.js +41 -41
  54. package/lib/src/language/LanguageMeta.d.ts +35 -35
  55. package/lib/src/language/LanguageMeta.js +89 -89
  56. package/lib/src/language/LanguageRef.d.ts +6 -6
  57. package/lib/src/language/LanguageRef.js +30 -30
  58. package/lib/src/language/LanguageResolver.d.ts +19 -19
  59. package/lib/src/language/LanguageResolver.js +143 -143
  60. package/lib/src/links/Links.d.ts +39 -39
  61. package/lib/src/links/Links.js +148 -148
  62. package/lib/src/links/Links.test.d.ts +1 -1
  63. package/lib/src/links/Links.test.js +33 -33
  64. package/lib/src/neighbourhood/Neighbourhood.d.ts +10 -10
  65. package/lib/src/neighbourhood/Neighbourhood.js +38 -38
  66. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +25 -25
  67. package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -256
  68. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +19 -19
  69. package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -54
  70. package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +24 -24
  71. package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -180
  72. package/lib/src/perspectives/LinkQuery.d.ts +11 -11
  73. package/lib/src/perspectives/LinkQuery.js +80 -80
  74. package/lib/src/perspectives/Perspective.d.ts +38 -38
  75. package/lib/src/perspectives/Perspective.js +144 -144
  76. package/lib/src/perspectives/Perspective.test.d.ts +1 -1
  77. package/lib/src/perspectives/Perspective.test.js +20 -20
  78. package/lib/src/perspectives/PerspectiveClient.d.ts +55 -54
  79. package/lib/src/perspectives/PerspectiveClient.js +418 -410
  80. package/lib/src/perspectives/PerspectiveDiff.d.ts +9 -9
  81. package/lib/src/perspectives/PerspectiveDiff.js +33 -33
  82. package/lib/src/perspectives/PerspectiveHandle.d.ts +16 -16
  83. package/lib/src/perspectives/PerspectiveHandle.js +59 -59
  84. package/lib/src/perspectives/PerspectiveProxy.d.ts +178 -178
  85. package/lib/src/perspectives/PerspectiveProxy.js +501 -540
  86. package/lib/src/perspectives/PerspectiveResolver.d.ts +38 -37
  87. package/lib/src/perspectives/PerspectiveResolver.js +376 -362
  88. package/lib/src/runtime/RuntimeClient.d.ts +33 -33
  89. package/lib/src/runtime/RuntimeClient.js +263 -263
  90. package/lib/src/runtime/RuntimeResolver.d.ts +47 -47
  91. package/lib/src/runtime/RuntimeResolver.js +328 -328
  92. package/lib/src/schema.gql +1 -0
  93. package/lib/src/subject/SDNADecorators.d.ts +45 -45
  94. package/lib/src/subject/SDNADecorators.js +250 -250
  95. package/lib/src/subject/Subject.d.ts +7 -7
  96. package/lib/src/subject/Subject.js +160 -160
  97. package/lib/src/subject/SubjectEntity.d.ts +31 -31
  98. package/lib/src/subject/SubjectEntity.js +250 -250
  99. package/lib/src/subject/util.d.ts +12 -12
  100. package/lib/src/subject/util.js +73 -73
  101. package/lib/src/typeDefs.d.ts +1 -1
  102. package/lib/src/typeDefs.js +1 -0
  103. package/lib/src/unwrapApolloResult.d.ts +2 -2
  104. package/lib/src/unwrapApolloResult.js +14 -12
  105. package/lib/src/utils.d.ts +2 -2
  106. package/lib/src/utils.js +21 -21
  107. package/package.json +61 -61
  108. package/rollup.config.js +26 -26
  109. package/shims/type-graphql.ts +75 -75
  110. package/src/Ad4mClient.test.ts +1089 -1084
  111. package/src/Ad4mClient.ts +62 -62
  112. package/src/Address.ts +1 -1
  113. package/src/Exception.ts +6 -6
  114. package/src/Literal.test.ts +30 -30
  115. package/src/Literal.ts +80 -80
  116. package/src/PubSub.ts +13 -13
  117. package/src/SmartLiteral.ts +74 -74
  118. package/src/agent/Agent.ts +293 -293
  119. package/src/agent/AgentClient.ts +531 -531
  120. package/src/agent/AgentResolver.ts +263 -263
  121. package/src/agent/AgentStatus.ts +43 -43
  122. package/src/buildSchema.ts +41 -41
  123. package/src/expression/Expression.ts +99 -99
  124. package/src/expression/ExpressionClient.ts +98 -98
  125. package/src/expression/ExpressionRef.ts +62 -62
  126. package/src/expression/ExpressionResolver.ts +63 -63
  127. package/src/index.ts +30 -30
  128. package/src/language/Icon.ts +10 -10
  129. package/src/language/Language.ts +266 -266
  130. package/src/language/LanguageClient.ts +159 -159
  131. package/src/language/LanguageContext.ts +37 -37
  132. package/src/language/LanguageHandle.ts +23 -23
  133. package/src/language/LanguageMeta.ts +69 -69
  134. package/src/language/LanguageRef.ts +18 -18
  135. package/src/language/LanguageResolver.ts +98 -98
  136. package/src/links/Links.test.ts +39 -39
  137. package/src/links/Links.ts +107 -107
  138. package/src/neighbourhood/Neighbourhood.ts +22 -22
  139. package/src/neighbourhood/NeighbourhoodClient.ts +275 -275
  140. package/src/neighbourhood/NeighbourhoodProxy.ts +58 -58
  141. package/src/neighbourhood/NeighbourhoodResolver.ts +99 -99
  142. package/src/perspectives/LinkQuery.ts +65 -65
  143. package/src/perspectives/Perspective.test.ts +22 -22
  144. package/src/perspectives/Perspective.ts +118 -118
  145. package/src/perspectives/PerspectiveClient.ts +452 -443
  146. package/src/perspectives/PerspectiveDiff.ts +15 -15
  147. package/src/perspectives/PerspectiveHandle.ts +39 -39
  148. package/src/perspectives/PerspectiveProxy.ts +576 -610
  149. package/src/perspectives/PerspectiveResolver.ts +224 -219
  150. package/src/runtime/RuntimeClient.ts +282 -282
  151. package/src/runtime/RuntimeResolver.ts +192 -192
  152. package/src/subject/SDNADecorators.ts +333 -333
  153. package/src/subject/Subject.ts +152 -152
  154. package/src/subject/SubjectEntity.ts +291 -291
  155. package/src/subject/util.ts +84 -84
  156. package/src/typeDefs.ts +5 -5
  157. package/src/unwrapApolloResult.ts +15 -13
  158. package/src/utils.ts +25 -25
  159. package/tsconfig-browser.json +82 -82
  160. package/tsconfig.json +80 -80
  161. package/yarn-error.log +0 -22814
@@ -1,283 +1,283 @@
1
- import { ApolloClient, gql } from "@apollo/client/core"
2
- import { Perspective, PerspectiveExpression } from "../perspectives/Perspective"
3
- import unwrapApolloResult from "../unwrapApolloResult"
4
- import { RuntimeInfo, ExceptionInfo, SentMessage } from "./RuntimeResolver"
5
-
6
- const PERSPECTIVE_EXPRESSION_FIELDS = `
7
- author
8
- timestamp
9
- data {
10
- links {
11
- author
12
- timestamp
13
- data { source, predicate, target }
14
- proof { valid, invalid, signature, key }
15
- }
16
- }
17
- proof { valid, invalid, signature, key }
18
- `
19
-
20
- export type MessageCallback = (message: PerspectiveExpression) => null
21
- export type ExceptionCallback = (info: ExceptionInfo) => null
22
-
23
- export class RuntimeClient {
24
- #apolloClient: ApolloClient<any>
25
- #messageReceivedCallbacks: MessageCallback[]
26
- #exceptionOccurredCallbacks: ExceptionCallback[]
27
-
28
- constructor(client: ApolloClient<any>, subscribe: boolean = true) {
29
- this.#apolloClient = client
30
- this.#messageReceivedCallbacks = []
31
- this.#exceptionOccurredCallbacks = []
32
-
33
- if(subscribe) {
34
- this.subscribeMessageReceived()
35
- this.subscribeExceptionOccurred()
36
- }
37
- }
38
-
39
- async info(): Promise<RuntimeInfo> {
40
- const { runtimeInfo } = unwrapApolloResult(await this.#apolloClient.query({
41
- query: gql`query runtimeInfo {
42
- runtimeInfo {
43
- ad4mExecutorVersion,
44
- isInitialized,
45
- isUnlocked
46
- }
47
- }`,
48
- }));
49
- return runtimeInfo
50
- }
51
-
52
- async quit(): Promise<Boolean> {
53
- const result = unwrapApolloResult(await this.#apolloClient.mutate({
54
- mutation: gql`mutation runtimeQuit { runtimeQuit }`
55
- }))
56
-
57
- return result.runtimeQuit
58
- }
59
-
60
- async openLink(url: string): Promise<Boolean> {
61
- const { runtimeOpenLink } = unwrapApolloResult(await this.#apolloClient.mutate({
62
- mutation: gql`mutation runtimeOpenLink($url: String!) {
63
- runtimeOpenLink(url: $url)
64
- }`,
65
- variables: { url }
66
- }))
67
- return runtimeOpenLink
68
- }
69
-
70
- async addTrustedAgents(agents: string[]): Promise<string[]> {
71
- const { addTrustedAgents } = unwrapApolloResult(await this.#apolloClient.mutate({
72
- mutation: gql`mutation addTrustedAgents($agents: [String!]!) {
73
- addTrustedAgents(agents: $agents)
74
- }`,
75
- variables: { agents }
76
- }))
77
- return addTrustedAgents
78
- }
79
-
80
- async deleteTrustedAgents(agents: string[]): Promise<string[]> {
81
- const { deleteTrustedAgents } = unwrapApolloResult(await this.#apolloClient.mutate({
82
- mutation: gql`mutation deleteTrustedAgents($agents: [String!]!) {
83
- deleteTrustedAgents(agents: $agents)
84
- }`,
85
- variables: { agents }
86
- }))
87
- return deleteTrustedAgents
88
- }
89
-
90
- async getTrustedAgents(): Promise<string[]> {
91
- const { getTrustedAgents } = unwrapApolloResult(await this.#apolloClient.query({
92
- query: gql`query getTrustedAgents {
93
- getTrustedAgents
94
- }`,
95
- }))
96
- return getTrustedAgents
97
- }
98
-
99
- async addKnownLinkLanguageTemplates(addresses: string[]): Promise<string[]> {
100
- const { runtimeAddKnownLinkLanguageTemplates } = unwrapApolloResult(await this.#apolloClient.mutate({
101
- mutation: gql`mutation runtimeAddKnownLinkLanguageTemplates($addresses: [String!]!) {
102
- runtimeAddKnownLinkLanguageTemplates(addresses: $addresses)
103
- }`,
104
- variables: { addresses }
105
- }))
106
- return runtimeAddKnownLinkLanguageTemplates
107
- }
108
-
109
- async removeKnownLinkLanguageTemplates(addresses: string[]): Promise<string[]> {
110
- const { runtimeRemoveKnownLinkLanguageTemplates } = unwrapApolloResult(await this.#apolloClient.mutate({
111
- mutation: gql`mutation runtimeRemoveKnownLinkLanguageTemplates($addresses: [String!]!) {
112
- runtimeRemoveKnownLinkLanguageTemplates(addresses: $addresses)
113
- }`,
114
- variables: { addresses }
115
- }))
116
- return runtimeRemoveKnownLinkLanguageTemplates
117
- }
118
-
119
- async knownLinkLanguageTemplates(): Promise<string[]> {
120
- const { runtimeKnownLinkLanguageTemplates } = unwrapApolloResult(await this.#apolloClient.query({
121
- query: gql`query runtimeKnownLinkLanguageTemplates {
122
- runtimeKnownLinkLanguageTemplates
123
- }`,
124
- }))
125
- return runtimeKnownLinkLanguageTemplates
126
- }
127
-
128
- async addFriends(dids: string[]): Promise<string[]> {
129
- const { runtimeAddFriends } = unwrapApolloResult(await this.#apolloClient.mutate({
130
- mutation: gql`mutation runtimeAddFriends($dids: [String!]!) {
131
- runtimeAddFriends(dids: $dids)
132
- }`,
133
- variables: { dids }
134
- }))
135
- return runtimeAddFriends
136
- }
137
-
138
- async removeFriends(dids: string[]): Promise<string[]> {
139
- const { runtimeRemoveFriends } = unwrapApolloResult(await this.#apolloClient.mutate({
140
- mutation: gql`mutation runtimeRemoveFriends($dids: [String!]!) {
141
- runtimeRemoveFriends(dids: $dids)
142
- }`,
143
- variables: { dids }
144
- }))
145
- return runtimeRemoveFriends
146
- }
147
-
148
- async friends(): Promise<string[]> {
149
- const { runtimeFriends } = unwrapApolloResult(await this.#apolloClient.query({
150
- query: gql`query runtimeFriends {
151
- runtimeFriends
152
- }`,
153
- }))
154
- return runtimeFriends
155
- }
156
-
157
- async hcAgentInfos(): Promise<String> {
158
- const { runtimeHcAgentInfos } = unwrapApolloResult(await this.#apolloClient.query({
159
- query: gql`query runtimeHcAgentInfos {
160
- runtimeHcAgentInfos
161
- }`,
162
- }))
163
- return runtimeHcAgentInfos
164
- }
165
-
166
- async hcAddAgentInfos(agentInfos: String): Promise<void> {
167
- const { runtimeHcAddAgentInfos } = unwrapApolloResult(await this.#apolloClient.mutate({
168
- mutation: gql`mutation runtimeHcAddAgentInfos($agentInfos: String!) {
169
- runtimeHcAddAgentInfos(agentInfos: $agentInfos)
170
- }`,
171
- variables: { agentInfos }
172
- }))
173
- return runtimeHcAddAgentInfos
174
- }
175
-
176
- async verifyStringSignedByDid(did: string, didSigningKeyId: string, data: string, signedData: string): Promise<boolean> {
177
- const { runtimeVerifyStringSignedByDid } = unwrapApolloResult(await this.#apolloClient.mutate({
178
- mutation: gql`query runtimeVerifyStringSignedByDid($did: String!, $didSigningKeyId: String!, $data: String!, $signedData: String!) {
179
- runtimeVerifyStringSignedByDid(did: $did, didSigningKeyId: $didSigningKeyId, data: $data, signedData: $signedData)
180
- }`,
181
- variables: { did, didSigningKeyId, data, signedData }
182
- }))
183
- return runtimeVerifyStringSignedByDid
184
- }
185
-
186
- async setStatus(perspective: Perspective): Promise<boolean> {
187
- const { runtimeSetStatus } = unwrapApolloResult(await this.#apolloClient.mutate({
188
- mutation: gql`mutation runtimeSetStatus($status: PerspectiveInput!) {
189
- runtimeSetStatus(status: $status)
190
- }`,
191
- variables: { status: perspective }
192
- }))
193
- return runtimeSetStatus
194
- }
195
-
196
- async friendStatus(did: string): Promise<PerspectiveExpression> {
197
- const { runtimeFriendStatus } = unwrapApolloResult(await this.#apolloClient.query({
198
- query: gql`query runtimeFriendStatus($did: String!) {
199
- runtimeFriendStatus(did: $did) { ${PERSPECTIVE_EXPRESSION_FIELDS} }
200
- }`,
201
- variables: { did }
202
- }))
203
- return runtimeFriendStatus
204
- }
205
-
206
- async friendSendMessage(did: string, message: Perspective): Promise<boolean> {
207
- const { runtimeFriendSendMessage } = unwrapApolloResult(await this.#apolloClient.mutate({
208
- mutation: gql`mutation runtimeFriendSendMessage($did: String!, $message: PerspectiveInput!) {
209
- runtimeFriendSendMessage(did: $did, message: $message)
210
- }`,
211
- variables: { did, message }
212
- }))
213
- return runtimeFriendSendMessage
214
- }
215
-
216
- async messageInbox(filter?: string): Promise<PerspectiveExpression[]> {
217
- const { runtimeMessageInbox } = unwrapApolloResult(await this.#apolloClient.query({
218
- query: gql`query runtimeMessageInbox($filter: String) {
219
- runtimeMessageInbox(filter: $filter) { ${PERSPECTIVE_EXPRESSION_FIELDS} }
220
- }`,
221
- variables: { filter }
222
- }))
223
- return runtimeMessageInbox
224
- }
225
-
226
- async messageOutbox(filter?: string): Promise<SentMessage[]> {
227
- const { runtimeMessageOutbox } = unwrapApolloResult(await this.#apolloClient.query({
228
- query: gql`query runtimeMessageOutbox($filter: String) {
229
- runtimeMessageOutbox(filter: $filter) {
230
- recipient,
231
- message {
232
- ${PERSPECTIVE_EXPRESSION_FIELDS}
233
- }
234
- }
235
- }`,
236
- variables: { filter }
237
- }))
238
- return runtimeMessageOutbox
239
- }
240
-
241
- addMessageCallback(cb: MessageCallback) {
242
- this.#messageReceivedCallbacks.push(cb)
243
- }
244
-
245
- subscribeMessageReceived() {
246
- this.#apolloClient.subscribe({
247
- query: gql` subscription {
248
- runtimeMessageReceived { ${PERSPECTIVE_EXPRESSION_FIELDS} }
249
- }
250
- `}).subscribe({
251
- next: result => {
252
- this.#messageReceivedCallbacks.forEach(cb => {
253
- cb(result.data.runtimeMessageReceived)
254
- })
255
- },
256
- error: (e) => console.error(e)
257
- })
258
- }
259
-
260
- addExceptionCallback(cb: ExceptionCallback) {
261
- this.#exceptionOccurredCallbacks.push(cb)
262
- }
263
-
264
- subscribeExceptionOccurred() {
265
- this.#apolloClient.subscribe({
266
- query: gql` subscription {
267
- exceptionOccurred {
268
- title
269
- message
270
- type
271
- addon
272
- }
273
- }`
274
- }).subscribe({
275
- next: result => {
276
- this.#exceptionOccurredCallbacks.forEach(cb => {
277
- cb(result.data.exceptionOccurred)
278
- })
279
- },
280
- error: (e) => console.error(e)
281
- })
282
- }
1
+ import { ApolloClient, gql } from "@apollo/client/core"
2
+ import { Perspective, PerspectiveExpression } from "../perspectives/Perspective"
3
+ import unwrapApolloResult from "../unwrapApolloResult"
4
+ import { RuntimeInfo, ExceptionInfo, SentMessage } from "./RuntimeResolver"
5
+
6
+ const PERSPECTIVE_EXPRESSION_FIELDS = `
7
+ author
8
+ timestamp
9
+ data {
10
+ links {
11
+ author
12
+ timestamp
13
+ data { source, predicate, target }
14
+ proof { valid, invalid, signature, key }
15
+ }
16
+ }
17
+ proof { valid, invalid, signature, key }
18
+ `
19
+
20
+ export type MessageCallback = (message: PerspectiveExpression) => null
21
+ export type ExceptionCallback = (info: ExceptionInfo) => null
22
+
23
+ export class RuntimeClient {
24
+ #apolloClient: ApolloClient<any>
25
+ #messageReceivedCallbacks: MessageCallback[]
26
+ #exceptionOccurredCallbacks: ExceptionCallback[]
27
+
28
+ constructor(client: ApolloClient<any>, subscribe: boolean = true) {
29
+ this.#apolloClient = client
30
+ this.#messageReceivedCallbacks = []
31
+ this.#exceptionOccurredCallbacks = []
32
+
33
+ if(subscribe) {
34
+ this.subscribeMessageReceived()
35
+ this.subscribeExceptionOccurred()
36
+ }
37
+ }
38
+
39
+ async info(): Promise<RuntimeInfo> {
40
+ const { runtimeInfo } = unwrapApolloResult(await this.#apolloClient.query({
41
+ query: gql`query runtimeInfo {
42
+ runtimeInfo {
43
+ ad4mExecutorVersion,
44
+ isInitialized,
45
+ isUnlocked
46
+ }
47
+ }`,
48
+ }));
49
+ return runtimeInfo
50
+ }
51
+
52
+ async quit(): Promise<Boolean> {
53
+ const result = unwrapApolloResult(await this.#apolloClient.mutate({
54
+ mutation: gql`mutation runtimeQuit { runtimeQuit }`
55
+ }))
56
+
57
+ return result.runtimeQuit
58
+ }
59
+
60
+ async openLink(url: string): Promise<Boolean> {
61
+ const { runtimeOpenLink } = unwrapApolloResult(await this.#apolloClient.mutate({
62
+ mutation: gql`mutation runtimeOpenLink($url: String!) {
63
+ runtimeOpenLink(url: $url)
64
+ }`,
65
+ variables: { url }
66
+ }))
67
+ return runtimeOpenLink
68
+ }
69
+
70
+ async addTrustedAgents(agents: string[]): Promise<string[]> {
71
+ const { addTrustedAgents } = unwrapApolloResult(await this.#apolloClient.mutate({
72
+ mutation: gql`mutation addTrustedAgents($agents: [String!]!) {
73
+ addTrustedAgents(agents: $agents)
74
+ }`,
75
+ variables: { agents }
76
+ }))
77
+ return addTrustedAgents
78
+ }
79
+
80
+ async deleteTrustedAgents(agents: string[]): Promise<string[]> {
81
+ const { deleteTrustedAgents } = unwrapApolloResult(await this.#apolloClient.mutate({
82
+ mutation: gql`mutation deleteTrustedAgents($agents: [String!]!) {
83
+ deleteTrustedAgents(agents: $agents)
84
+ }`,
85
+ variables: { agents }
86
+ }))
87
+ return deleteTrustedAgents
88
+ }
89
+
90
+ async getTrustedAgents(): Promise<string[]> {
91
+ const { getTrustedAgents } = unwrapApolloResult(await this.#apolloClient.query({
92
+ query: gql`query getTrustedAgents {
93
+ getTrustedAgents
94
+ }`,
95
+ }))
96
+ return getTrustedAgents
97
+ }
98
+
99
+ async addKnownLinkLanguageTemplates(addresses: string[]): Promise<string[]> {
100
+ const { runtimeAddKnownLinkLanguageTemplates } = unwrapApolloResult(await this.#apolloClient.mutate({
101
+ mutation: gql`mutation runtimeAddKnownLinkLanguageTemplates($addresses: [String!]!) {
102
+ runtimeAddKnownLinkLanguageTemplates(addresses: $addresses)
103
+ }`,
104
+ variables: { addresses }
105
+ }))
106
+ return runtimeAddKnownLinkLanguageTemplates
107
+ }
108
+
109
+ async removeKnownLinkLanguageTemplates(addresses: string[]): Promise<string[]> {
110
+ const { runtimeRemoveKnownLinkLanguageTemplates } = unwrapApolloResult(await this.#apolloClient.mutate({
111
+ mutation: gql`mutation runtimeRemoveKnownLinkLanguageTemplates($addresses: [String!]!) {
112
+ runtimeRemoveKnownLinkLanguageTemplates(addresses: $addresses)
113
+ }`,
114
+ variables: { addresses }
115
+ }))
116
+ return runtimeRemoveKnownLinkLanguageTemplates
117
+ }
118
+
119
+ async knownLinkLanguageTemplates(): Promise<string[]> {
120
+ const { runtimeKnownLinkLanguageTemplates } = unwrapApolloResult(await this.#apolloClient.query({
121
+ query: gql`query runtimeKnownLinkLanguageTemplates {
122
+ runtimeKnownLinkLanguageTemplates
123
+ }`,
124
+ }))
125
+ return runtimeKnownLinkLanguageTemplates
126
+ }
127
+
128
+ async addFriends(dids: string[]): Promise<string[]> {
129
+ const { runtimeAddFriends } = unwrapApolloResult(await this.#apolloClient.mutate({
130
+ mutation: gql`mutation runtimeAddFriends($dids: [String!]!) {
131
+ runtimeAddFriends(dids: $dids)
132
+ }`,
133
+ variables: { dids }
134
+ }))
135
+ return runtimeAddFriends
136
+ }
137
+
138
+ async removeFriends(dids: string[]): Promise<string[]> {
139
+ const { runtimeRemoveFriends } = unwrapApolloResult(await this.#apolloClient.mutate({
140
+ mutation: gql`mutation runtimeRemoveFriends($dids: [String!]!) {
141
+ runtimeRemoveFriends(dids: $dids)
142
+ }`,
143
+ variables: { dids }
144
+ }))
145
+ return runtimeRemoveFriends
146
+ }
147
+
148
+ async friends(): Promise<string[]> {
149
+ const { runtimeFriends } = unwrapApolloResult(await this.#apolloClient.query({
150
+ query: gql`query runtimeFriends {
151
+ runtimeFriends
152
+ }`,
153
+ }))
154
+ return runtimeFriends
155
+ }
156
+
157
+ async hcAgentInfos(): Promise<String> {
158
+ const { runtimeHcAgentInfos } = unwrapApolloResult(await this.#apolloClient.query({
159
+ query: gql`query runtimeHcAgentInfos {
160
+ runtimeHcAgentInfos
161
+ }`,
162
+ }))
163
+ return runtimeHcAgentInfos
164
+ }
165
+
166
+ async hcAddAgentInfos(agentInfos: String): Promise<void> {
167
+ const { runtimeHcAddAgentInfos } = unwrapApolloResult(await this.#apolloClient.mutate({
168
+ mutation: gql`mutation runtimeHcAddAgentInfos($agentInfos: String!) {
169
+ runtimeHcAddAgentInfos(agentInfos: $agentInfos)
170
+ }`,
171
+ variables: { agentInfos }
172
+ }))
173
+ return runtimeHcAddAgentInfos
174
+ }
175
+
176
+ async verifyStringSignedByDid(did: string, didSigningKeyId: string, data: string, signedData: string): Promise<boolean> {
177
+ const { runtimeVerifyStringSignedByDid } = unwrapApolloResult(await this.#apolloClient.mutate({
178
+ mutation: gql`query runtimeVerifyStringSignedByDid($did: String!, $didSigningKeyId: String!, $data: String!, $signedData: String!) {
179
+ runtimeVerifyStringSignedByDid(did: $did, didSigningKeyId: $didSigningKeyId, data: $data, signedData: $signedData)
180
+ }`,
181
+ variables: { did, didSigningKeyId, data, signedData }
182
+ }))
183
+ return runtimeVerifyStringSignedByDid
184
+ }
185
+
186
+ async setStatus(perspective: Perspective): Promise<boolean> {
187
+ const { runtimeSetStatus } = unwrapApolloResult(await this.#apolloClient.mutate({
188
+ mutation: gql`mutation runtimeSetStatus($status: PerspectiveInput!) {
189
+ runtimeSetStatus(status: $status)
190
+ }`,
191
+ variables: { status: perspective }
192
+ }))
193
+ return runtimeSetStatus
194
+ }
195
+
196
+ async friendStatus(did: string): Promise<PerspectiveExpression> {
197
+ const { runtimeFriendStatus } = unwrapApolloResult(await this.#apolloClient.query({
198
+ query: gql`query runtimeFriendStatus($did: String!) {
199
+ runtimeFriendStatus(did: $did) { ${PERSPECTIVE_EXPRESSION_FIELDS} }
200
+ }`,
201
+ variables: { did }
202
+ }))
203
+ return runtimeFriendStatus
204
+ }
205
+
206
+ async friendSendMessage(did: string, message: Perspective): Promise<boolean> {
207
+ const { runtimeFriendSendMessage } = unwrapApolloResult(await this.#apolloClient.mutate({
208
+ mutation: gql`mutation runtimeFriendSendMessage($did: String!, $message: PerspectiveInput!) {
209
+ runtimeFriendSendMessage(did: $did, message: $message)
210
+ }`,
211
+ variables: { did, message }
212
+ }))
213
+ return runtimeFriendSendMessage
214
+ }
215
+
216
+ async messageInbox(filter?: string): Promise<PerspectiveExpression[]> {
217
+ const { runtimeMessageInbox } = unwrapApolloResult(await this.#apolloClient.query({
218
+ query: gql`query runtimeMessageInbox($filter: String) {
219
+ runtimeMessageInbox(filter: $filter) { ${PERSPECTIVE_EXPRESSION_FIELDS} }
220
+ }`,
221
+ variables: { filter }
222
+ }))
223
+ return runtimeMessageInbox
224
+ }
225
+
226
+ async messageOutbox(filter?: string): Promise<SentMessage[]> {
227
+ const { runtimeMessageOutbox } = unwrapApolloResult(await this.#apolloClient.query({
228
+ query: gql`query runtimeMessageOutbox($filter: String) {
229
+ runtimeMessageOutbox(filter: $filter) {
230
+ recipient,
231
+ message {
232
+ ${PERSPECTIVE_EXPRESSION_FIELDS}
233
+ }
234
+ }
235
+ }`,
236
+ variables: { filter }
237
+ }))
238
+ return runtimeMessageOutbox
239
+ }
240
+
241
+ addMessageCallback(cb: MessageCallback) {
242
+ this.#messageReceivedCallbacks.push(cb)
243
+ }
244
+
245
+ subscribeMessageReceived() {
246
+ this.#apolloClient.subscribe({
247
+ query: gql` subscription {
248
+ runtimeMessageReceived { ${PERSPECTIVE_EXPRESSION_FIELDS} }
249
+ }
250
+ `}).subscribe({
251
+ next: result => {
252
+ this.#messageReceivedCallbacks.forEach(cb => {
253
+ cb(result.data.runtimeMessageReceived)
254
+ })
255
+ },
256
+ error: (e) => console.error(e)
257
+ })
258
+ }
259
+
260
+ addExceptionCallback(cb: ExceptionCallback) {
261
+ this.#exceptionOccurredCallbacks.push(cb)
262
+ }
263
+
264
+ subscribeExceptionOccurred() {
265
+ this.#apolloClient.subscribe({
266
+ query: gql` subscription {
267
+ exceptionOccurred {
268
+ title
269
+ message
270
+ type
271
+ addon
272
+ }
273
+ }`
274
+ }).subscribe({
275
+ next: result => {
276
+ this.#exceptionOccurredCallbacks.forEach(cb => {
277
+ cb(result.data.exceptionOccurred)
278
+ })
279
+ },
280
+ error: (e) => console.error(e)
281
+ })
282
+ }
283
283
  }