@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,362 +1,376 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var __param = (this && this.__param) || function (paramIndex, decorator) {
11
- return function (target, key) { decorator(target, key, paramIndex); }
12
- };
13
- import { Arg, Mutation, PubSub, Query, Resolver, Subscription } from "type-graphql";
14
- import { LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations } from "../links/Links";
15
- import { Neighbourhood, NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
16
- import { LinkQuery } from "./LinkQuery";
17
- import { Perspective } from "./Perspective";
18
- import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
19
- import { LINK_ADDED_TOPIC, LINK_REMOVED_TOPIC, LINK_UDATED_TOPIC, PERSPECTIVE_ADDED_TOPIC, PERSPECTIVE_REMOVED_TOPIC, PERSPECTIVE_UPDATED_TOPIC, PERSPECTIVE_SYNC_STATE_CHANGE } from '../PubSub';
20
- export const testLink = new LinkExpression();
21
- testLink.author = "did:ad4m:test";
22
- testLink.timestamp = Date.now();
23
- testLink.data = {
24
- source: 'root',
25
- target: 'neighbourhood://Qm12345'
26
- };
27
- testLink.proof = {
28
- signature: '',
29
- key: '',
30
- valid: true
31
- };
32
- /**
33
- * Resolver classes are used here to define the GraphQL schema
34
- * (through the type-graphql annotations)
35
- * and are spawned in the client tests in Ad4mClient.test.ts.
36
- * For the latter, they return test fixtures.
37
- */
38
- let PerspectiveResolver = class PerspectiveResolver {
39
- perspectives() {
40
- const p1 = new PerspectiveHandle();
41
- p1.name = 'test-perspective-1';
42
- p1.uuid = '00001';
43
- const p2 = new PerspectiveHandle();
44
- p2.name = 'test-perspective-2';
45
- p2.uuid = '00002';
46
- p2.sharedUrl = 'neighbourhood://Qm12345';
47
- const neighbourhood = new NeighbourhoodExpression();
48
- neighbourhood.data = new Neighbourhood("language://Qm12345", new Perspective());
49
- neighbourhood.author = "did:ad4m:test";
50
- neighbourhood.timestamp = Date.now();
51
- neighbourhood.proof = {
52
- signature: '',
53
- key: '',
54
- valid: true
55
- };
56
- p2.neighbourhood = neighbourhood;
57
- p2.state = PerspectiveState.Synced;
58
- return [p1, p2];
59
- }
60
- perspective(uuid) {
61
- return new PerspectiveHandle(uuid, 'test-perspective-1');
62
- }
63
- perspectiveSnapshot(uuid) {
64
- return new Perspective([testLink]);
65
- }
66
- perspectivePublishSnapshot(uuid) {
67
- return 'perspective://Qm12345';
68
- }
69
- perspectiveQueryLinks(uuid, query) {
70
- return [testLink];
71
- }
72
- perspectiveQueryProlog(uuid, query) {
73
- return `[{"X": 1}]`;
74
- }
75
- perspectiveAdd(name, pubSub) {
76
- const perspective = new PerspectiveHandle('00006', name);
77
- pubSub.publish(PERSPECTIVE_ADDED_TOPIC, { perspective });
78
- return new PerspectiveHandle('00006', name);
79
- }
80
- perspectiveUpdate(uuid, name, pubSub) {
81
- const perspective = new PerspectiveHandle(uuid, name);
82
- pubSub.publish(PERSPECTIVE_UPDATED_TOPIC, { perspective });
83
- return new PerspectiveHandle(uuid, name);
84
- }
85
- perspectiveRemove(uuid, pubSub) {
86
- const perspective = new PerspectiveHandle(uuid);
87
- pubSub.publish(PERSPECTIVE_REMOVED_TOPIC, { perspective });
88
- return true;
89
- }
90
- perspectiveAddLink(uuid, link, status, pubSub) {
91
- const l = new LinkExpression();
92
- l.author = 'did:ad4m:test';
93
- l.timestamp = Date.now();
94
- l.proof = testLink.proof;
95
- l.data = link;
96
- l.status = status;
97
- pubSub.publish(LINK_ADDED_TOPIC, { link: l });
98
- pubSub.publish(PERSPECTIVE_SYNC_STATE_CHANGE, PerspectiveState.LinkLanguageInstalledButNotSynced);
99
- return l;
100
- }
101
- perspectiveAddLinks(uuid, links, status, pubSub) {
102
- const l = new LinkExpression();
103
- l.author = 'did:ad4m:test';
104
- l.timestamp = Date.now();
105
- l.proof = testLink.proof;
106
- l.data = links[0];
107
- const l2 = new LinkExpression();
108
- l2.author = 'did:ad4m:test';
109
- l2.timestamp = Date.now();
110
- l2.proof = testLink.proof;
111
- l2.data = links[0];
112
- pubSub.publish(LINK_ADDED_TOPIC, { link: l });
113
- pubSub.publish(LINK_ADDED_TOPIC, { link: l2 });
114
- return [l, l2];
115
- }
116
- perspectiveRemoveLinks(uuid, links, pubSub) {
117
- const l = new LinkExpression();
118
- l.author = 'did:ad4m:test';
119
- l.timestamp = Date.now();
120
- l.proof = testLink.proof;
121
- l.data = links[0].data;
122
- const l2 = new LinkExpression();
123
- l2.author = 'did:ad4m:test';
124
- l2.timestamp = Date.now();
125
- l2.proof = testLink.proof;
126
- l2.data = links[0].data;
127
- pubSub.publish(LINK_REMOVED_TOPIC, { link: l });
128
- pubSub.publish(LINK_ADDED_TOPIC, { link: l2 });
129
- return [l, l2];
130
- }
131
- perspectiveLinkMutations(uuid, mutations, status, pubSub) {
132
- const perspectiveAddLinks = this.perspectiveAddLinks(uuid, mutations.additions, status, pubSub);
133
- const perspectiveRemoveLinks = this.perspectiveRemoveLinks(uuid, mutations.removals, pubSub);
134
- return new LinkExpressionMutations(perspectiveAddLinks, perspectiveRemoveLinks);
135
- }
136
- perspectiveAddLinkExpression(uuid, link, status, pubSub) {
137
- pubSub.publish(LINK_ADDED_TOPIC, { link });
138
- link.status = status;
139
- return link;
140
- }
141
- perspectiveUpdateLink(uuid, oldlink, newlink, pubSub) {
142
- const l = new LinkExpression();
143
- l.author = 'did:ad4m:test';
144
- l.timestamp = Date.now();
145
- l.proof = testLink.proof;
146
- l.data = newlink;
147
- pubSub.publish(LINK_REMOVED_TOPIC, { link: l });
148
- return l;
149
- }
150
- perspectiveRemoveLink(uuid, link, pubSub) {
151
- pubSub.publish(LINK_REMOVED_TOPIC);
152
- return true;
153
- }
154
- perspectiveAdded() {
155
- const perspective = new PerspectiveHandle('00001', 'New Perspective');
156
- return perspective;
157
- }
158
- perspectiveUpdated() {
159
- return new PerspectiveHandle('00001', 'New Perspective');
160
- }
161
- perspectiveRemoved() {
162
- return '00006';
163
- }
164
- perspectiveLinkAdded(uuid) {
165
- return testLink;
166
- }
167
- perspectiveLinkRemoved(uuid) {
168
- return testLink;
169
- }
170
- perspectiveLinkUpdated(uuid) {
171
- return { oldLink: testLink, newLink: testLink };
172
- }
173
- perspectiveSyncStateChange(uuid) {
174
- return PerspectiveState.Synced;
175
- }
176
- };
177
- __decorate([
178
- Query(returns => [PerspectiveHandle]),
179
- __metadata("design:type", Function),
180
- __metadata("design:paramtypes", []),
181
- __metadata("design:returntype", Array)
182
- ], PerspectiveResolver.prototype, "perspectives", null);
183
- __decorate([
184
- Query(returns => PerspectiveHandle, { nullable: true }),
185
- __param(0, Arg('uuid')),
186
- __metadata("design:type", Function),
187
- __metadata("design:paramtypes", [String]),
188
- __metadata("design:returntype", PerspectiveHandle)
189
- ], PerspectiveResolver.prototype, "perspective", null);
190
- __decorate([
191
- Query(returns => Perspective, { nullable: true }),
192
- __param(0, Arg('uuid')),
193
- __metadata("design:type", Function),
194
- __metadata("design:paramtypes", [String]),
195
- __metadata("design:returntype", Perspective)
196
- ], PerspectiveResolver.prototype, "perspectiveSnapshot", null);
197
- __decorate([
198
- Mutation(returns => String, { nullable: true }),
199
- __param(0, Arg('uuid')),
200
- __metadata("design:type", Function),
201
- __metadata("design:paramtypes", [String]),
202
- __metadata("design:returntype", String)
203
- ], PerspectiveResolver.prototype, "perspectivePublishSnapshot", null);
204
- __decorate([
205
- Query(returns => [LinkExpression], { nullable: true }),
206
- __param(0, Arg('uuid')),
207
- __param(1, Arg('query')),
208
- __metadata("design:type", Function),
209
- __metadata("design:paramtypes", [String, LinkQuery]),
210
- __metadata("design:returntype", Array)
211
- ], PerspectiveResolver.prototype, "perspectiveQueryLinks", null);
212
- __decorate([
213
- Query(returns => String),
214
- __param(0, Arg('uuid')),
215
- __param(1, Arg('query')),
216
- __metadata("design:type", Function),
217
- __metadata("design:paramtypes", [String, String]),
218
- __metadata("design:returntype", String)
219
- ], PerspectiveResolver.prototype, "perspectiveQueryProlog", null);
220
- __decorate([
221
- Mutation(returns => PerspectiveHandle),
222
- __param(0, Arg('name')),
223
- __param(1, PubSub()),
224
- __metadata("design:type", Function),
225
- __metadata("design:paramtypes", [String, Object]),
226
- __metadata("design:returntype", PerspectiveHandle)
227
- ], PerspectiveResolver.prototype, "perspectiveAdd", null);
228
- __decorate([
229
- Mutation(returns => PerspectiveHandle, { nullable: true }),
230
- __param(0, Arg('uuid')),
231
- __param(1, Arg('name')),
232
- __param(2, PubSub()),
233
- __metadata("design:type", Function),
234
- __metadata("design:paramtypes", [String, String, Object]),
235
- __metadata("design:returntype", PerspectiveHandle)
236
- ], PerspectiveResolver.prototype, "perspectiveUpdate", null);
237
- __decorate([
238
- Mutation(returns => Boolean),
239
- __param(0, Arg('uuid')),
240
- __param(1, PubSub()),
241
- __metadata("design:type", Function),
242
- __metadata("design:paramtypes", [String, Object]),
243
- __metadata("design:returntype", Boolean)
244
- ], PerspectiveResolver.prototype, "perspectiveRemove", null);
245
- __decorate([
246
- Mutation(returns => LinkExpression),
247
- __param(0, Arg('uuid')),
248
- __param(1, Arg('link')),
249
- __param(2, Arg('status', { nullable: true, defaultValue: 'shared' })),
250
- __param(3, PubSub()),
251
- __metadata("design:type", Function),
252
- __metadata("design:paramtypes", [String, LinkInput, String, Object]),
253
- __metadata("design:returntype", LinkExpression)
254
- ], PerspectiveResolver.prototype, "perspectiveAddLink", null);
255
- __decorate([
256
- Mutation(returns => [LinkExpression]),
257
- __param(0, Arg('uuid')),
258
- __param(1, Arg('links', type => [LinkInput])),
259
- __param(2, Arg('status', { nullable: true })),
260
- __param(3, PubSub()),
261
- __metadata("design:type", Function),
262
- __metadata("design:paramtypes", [String, Array, String, Object]),
263
- __metadata("design:returntype", Array)
264
- ], PerspectiveResolver.prototype, "perspectiveAddLinks", null);
265
- __decorate([
266
- Mutation(returns => [LinkExpression]),
267
- __param(0, Arg('uuid')),
268
- __param(1, Arg('links', type => [LinkExpressionInput])),
269
- __param(2, PubSub()),
270
- __metadata("design:type", Function),
271
- __metadata("design:paramtypes", [String, Array, Object]),
272
- __metadata("design:returntype", Array)
273
- ], PerspectiveResolver.prototype, "perspectiveRemoveLinks", null);
274
- __decorate([
275
- Mutation(returns => LinkExpressionMutations),
276
- __param(0, Arg('uuid')),
277
- __param(1, Arg('mutations')),
278
- __param(2, Arg('status', { nullable: true })),
279
- __param(3, PubSub()),
280
- __metadata("design:type", Function),
281
- __metadata("design:paramtypes", [String, LinkMutations, String, Object]),
282
- __metadata("design:returntype", LinkExpressionMutations)
283
- ], PerspectiveResolver.prototype, "perspectiveLinkMutations", null);
284
- __decorate([
285
- Mutation(returns => LinkExpression),
286
- __param(0, Arg('uuid')),
287
- __param(1, Arg('link')),
288
- __param(2, Arg('status', { nullable: true })),
289
- __param(3, PubSub()),
290
- __metadata("design:type", Function),
291
- __metadata("design:paramtypes", [String, LinkExpressionInput, String, Object]),
292
- __metadata("design:returntype", LinkExpression)
293
- ], PerspectiveResolver.prototype, "perspectiveAddLinkExpression", null);
294
- __decorate([
295
- Mutation(returns => LinkExpression),
296
- __param(0, Arg('uuid')),
297
- __param(1, Arg('oldLink')),
298
- __param(2, Arg('newLink')),
299
- __param(3, PubSub()),
300
- __metadata("design:type", Function),
301
- __metadata("design:paramtypes", [String, LinkExpressionInput, LinkInput, Object]),
302
- __metadata("design:returntype", LinkExpression)
303
- ], PerspectiveResolver.prototype, "perspectiveUpdateLink", null);
304
- __decorate([
305
- Mutation(returns => Boolean),
306
- __param(0, Arg('uuid')),
307
- __param(1, Arg('link')),
308
- __param(2, PubSub()),
309
- __metadata("design:type", Function),
310
- __metadata("design:paramtypes", [String, LinkExpressionInput, Object]),
311
- __metadata("design:returntype", Boolean)
312
- ], PerspectiveResolver.prototype, "perspectiveRemoveLink", null);
313
- __decorate([
314
- Subscription({ topics: PERSPECTIVE_ADDED_TOPIC, nullable: true }),
315
- __metadata("design:type", Function),
316
- __metadata("design:paramtypes", []),
317
- __metadata("design:returntype", PerspectiveHandle)
318
- ], PerspectiveResolver.prototype, "perspectiveAdded", null);
319
- __decorate([
320
- Subscription({ topics: PERSPECTIVE_UPDATED_TOPIC, nullable: true }),
321
- __metadata("design:type", Function),
322
- __metadata("design:paramtypes", []),
323
- __metadata("design:returntype", PerspectiveHandle)
324
- ], PerspectiveResolver.prototype, "perspectiveUpdated", null);
325
- __decorate([
326
- Subscription({ topics: PERSPECTIVE_REMOVED_TOPIC, nullable: true }),
327
- __metadata("design:type", Function),
328
- __metadata("design:paramtypes", []),
329
- __metadata("design:returntype", String)
330
- ], PerspectiveResolver.prototype, "perspectiveRemoved", null);
331
- __decorate([
332
- Subscription({ topics: LINK_ADDED_TOPIC, nullable: true }),
333
- __param(0, Arg('uuid')),
334
- __metadata("design:type", Function),
335
- __metadata("design:paramtypes", [String]),
336
- __metadata("design:returntype", LinkExpression)
337
- ], PerspectiveResolver.prototype, "perspectiveLinkAdded", null);
338
- __decorate([
339
- Subscription({ topics: LINK_REMOVED_TOPIC, nullable: true }),
340
- __param(0, Arg('uuid')),
341
- __metadata("design:type", Function),
342
- __metadata("design:paramtypes", [String]),
343
- __metadata("design:returntype", LinkExpression)
344
- ], PerspectiveResolver.prototype, "perspectiveLinkRemoved", null);
345
- __decorate([
346
- Subscription({ topics: LINK_UDATED_TOPIC, nullable: true }),
347
- __param(0, Arg('uuid')),
348
- __metadata("design:type", Function),
349
- __metadata("design:paramtypes", [String]),
350
- __metadata("design:returntype", LinkExpressionUpdated)
351
- ], PerspectiveResolver.prototype, "perspectiveLinkUpdated", null);
352
- __decorate([
353
- Subscription({ topics: PERSPECTIVE_SYNC_STATE_CHANGE, nullable: false }),
354
- __param(0, Arg('uuid')),
355
- __metadata("design:type", Function),
356
- __metadata("design:paramtypes", [String]),
357
- __metadata("design:returntype", String)
358
- ], PerspectiveResolver.prototype, "perspectiveSyncStateChange", null);
359
- PerspectiveResolver = __decorate([
360
- Resolver()
361
- ], PerspectiveResolver);
362
- export default PerspectiveResolver;
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { Arg, Mutation, PubSub, Query, Resolver, Subscription } from "type-graphql";
14
+ import { LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations } from "../links/Links";
15
+ import { Neighbourhood, NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
16
+ import { LinkQuery } from "./LinkQuery";
17
+ import { Perspective } from "./Perspective";
18
+ import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
19
+ import { LINK_ADDED_TOPIC, LINK_REMOVED_TOPIC, LINK_UDATED_TOPIC, PERSPECTIVE_ADDED_TOPIC, PERSPECTIVE_REMOVED_TOPIC, PERSPECTIVE_UPDATED_TOPIC, PERSPECTIVE_SYNC_STATE_CHANGE } from '../PubSub';
20
+ export const testLink = new LinkExpression();
21
+ testLink.author = "did:ad4m:test";
22
+ testLink.timestamp = Date.now();
23
+ testLink.data = {
24
+ source: 'root',
25
+ target: 'neighbourhood://Qm12345'
26
+ };
27
+ testLink.proof = {
28
+ signature: '',
29
+ key: '',
30
+ valid: true
31
+ };
32
+ /**
33
+ * Resolver classes are used here to define the GraphQL schema
34
+ * (through the type-graphql annotations)
35
+ * and are spawned in the client tests in Ad4mClient.test.ts.
36
+ * For the latter, they return test fixtures.
37
+ */
38
+ let PerspectiveResolver = class PerspectiveResolver {
39
+ perspectives() {
40
+ const p1 = new PerspectiveHandle();
41
+ p1.name = 'test-perspective-1';
42
+ p1.uuid = '00001';
43
+ const p2 = new PerspectiveHandle();
44
+ p2.name = 'test-perspective-2';
45
+ p2.uuid = '00002';
46
+ p2.sharedUrl = 'neighbourhood://Qm12345';
47
+ const neighbourhood = new NeighbourhoodExpression();
48
+ neighbourhood.data = new Neighbourhood("language://Qm12345", new Perspective());
49
+ neighbourhood.author = "did:ad4m:test";
50
+ neighbourhood.timestamp = Date.now();
51
+ neighbourhood.proof = {
52
+ signature: '',
53
+ key: '',
54
+ valid: true
55
+ };
56
+ p2.neighbourhood = neighbourhood;
57
+ p2.state = PerspectiveState.Synced;
58
+ return [p1, p2];
59
+ }
60
+ perspective(uuid) {
61
+ return new PerspectiveHandle(uuid, 'test-perspective-1');
62
+ }
63
+ perspectiveSnapshot(uuid) {
64
+ return new Perspective([testLink]);
65
+ }
66
+ perspectivePublishSnapshot(uuid) {
67
+ return 'perspective://Qm12345';
68
+ }
69
+ perspectiveQueryLinks(uuid, query) {
70
+ return [testLink];
71
+ }
72
+ perspectiveQueryProlog(uuid, query) {
73
+ return `[{"X": 1}]`;
74
+ }
75
+ perspectiveAdd(name, pubSub) {
76
+ const perspective = new PerspectiveHandle('00006', name);
77
+ pubSub.publish(PERSPECTIVE_ADDED_TOPIC, { perspective });
78
+ return new PerspectiveHandle('00006', name);
79
+ }
80
+ perspectiveUpdate(uuid, name, pubSub) {
81
+ const perspective = new PerspectiveHandle(uuid, name);
82
+ pubSub.publish(PERSPECTIVE_UPDATED_TOPIC, { perspective });
83
+ return new PerspectiveHandle(uuid, name);
84
+ }
85
+ perspectiveRemove(uuid, pubSub) {
86
+ const perspective = new PerspectiveHandle(uuid);
87
+ pubSub.publish(PERSPECTIVE_REMOVED_TOPIC, { perspective });
88
+ return true;
89
+ }
90
+ perspectiveAddLink(uuid, link, status, pubSub) {
91
+ const l = new LinkExpression();
92
+ l.author = 'did:ad4m:test';
93
+ l.timestamp = Date.now();
94
+ l.proof = testLink.proof;
95
+ l.data = link;
96
+ l.status = status;
97
+ pubSub.publish(LINK_ADDED_TOPIC, { link: l });
98
+ pubSub.publish(PERSPECTIVE_SYNC_STATE_CHANGE, PerspectiveState.LinkLanguageInstalledButNotSynced);
99
+ return l;
100
+ }
101
+ perspectiveAddLinks(uuid, links, status, pubSub) {
102
+ const l = new LinkExpression();
103
+ l.author = 'did:ad4m:test';
104
+ l.timestamp = Date.now();
105
+ l.proof = testLink.proof;
106
+ l.data = links[0];
107
+ const l2 = new LinkExpression();
108
+ l2.author = 'did:ad4m:test';
109
+ l2.timestamp = Date.now();
110
+ l2.proof = testLink.proof;
111
+ l2.data = links[0];
112
+ pubSub.publish(LINK_ADDED_TOPIC, { link: l });
113
+ pubSub.publish(LINK_ADDED_TOPIC, { link: l2 });
114
+ return [l, l2];
115
+ }
116
+ perspectiveRemoveLinks(uuid, links, pubSub) {
117
+ const l = new LinkExpression();
118
+ l.author = 'did:ad4m:test';
119
+ l.timestamp = Date.now();
120
+ l.proof = testLink.proof;
121
+ l.data = links[0].data;
122
+ const l2 = new LinkExpression();
123
+ l2.author = 'did:ad4m:test';
124
+ l2.timestamp = Date.now();
125
+ l2.proof = testLink.proof;
126
+ l2.data = links[0].data;
127
+ pubSub.publish(LINK_REMOVED_TOPIC, { link: l });
128
+ pubSub.publish(LINK_ADDED_TOPIC, { link: l2 });
129
+ return [l, l2];
130
+ }
131
+ perspectiveLinkMutations(uuid, mutations, status, pubSub) {
132
+ const perspectiveAddLinks = this.perspectiveAddLinks(uuid, mutations.additions, status, pubSub);
133
+ const perspectiveRemoveLinks = this.perspectiveRemoveLinks(uuid, mutations.removals, pubSub);
134
+ return new LinkExpressionMutations(perspectiveAddLinks, perspectiveRemoveLinks);
135
+ }
136
+ perspectiveAddLinkExpression(uuid, link, status, pubSub) {
137
+ pubSub.publish(LINK_ADDED_TOPIC, { link });
138
+ link.status = status;
139
+ return link;
140
+ }
141
+ perspectiveUpdateLink(uuid, oldlink, newlink, pubSub) {
142
+ const l = new LinkExpression();
143
+ l.author = 'did:ad4m:test';
144
+ l.timestamp = Date.now();
145
+ l.proof = testLink.proof;
146
+ l.data = newlink;
147
+ pubSub.publish(LINK_REMOVED_TOPIC, { link: l });
148
+ return l;
149
+ }
150
+ perspectiveRemoveLink(uuid, link, pubSub) {
151
+ pubSub.publish(LINK_REMOVED_TOPIC);
152
+ return true;
153
+ }
154
+ perspectiveAddSdna(uuid, name, sdnaCode, sdnaType, pubSub) {
155
+ return true;
156
+ }
157
+ perspectiveAdded() {
158
+ const perspective = new PerspectiveHandle('00001', 'New Perspective');
159
+ return perspective;
160
+ }
161
+ perspectiveUpdated() {
162
+ return new PerspectiveHandle('00001', 'New Perspective');
163
+ }
164
+ perspectiveRemoved() {
165
+ return '00006';
166
+ }
167
+ perspectiveLinkAdded(uuid) {
168
+ return testLink;
169
+ }
170
+ perspectiveLinkRemoved(uuid) {
171
+ return testLink;
172
+ }
173
+ perspectiveLinkUpdated(uuid) {
174
+ return { oldLink: testLink, newLink: testLink };
175
+ }
176
+ perspectiveSyncStateChange(uuid) {
177
+ return PerspectiveState.Synced;
178
+ }
179
+ };
180
+ __decorate([
181
+ Query(returns => [PerspectiveHandle]),
182
+ __metadata("design:type", Function),
183
+ __metadata("design:paramtypes", []),
184
+ __metadata("design:returntype", Array)
185
+ ], PerspectiveResolver.prototype, "perspectives", null);
186
+ __decorate([
187
+ Query(returns => PerspectiveHandle, { nullable: true }),
188
+ __param(0, Arg('uuid')),
189
+ __metadata("design:type", Function),
190
+ __metadata("design:paramtypes", [String]),
191
+ __metadata("design:returntype", PerspectiveHandle)
192
+ ], PerspectiveResolver.prototype, "perspective", null);
193
+ __decorate([
194
+ Query(returns => Perspective, { nullable: true }),
195
+ __param(0, Arg('uuid')),
196
+ __metadata("design:type", Function),
197
+ __metadata("design:paramtypes", [String]),
198
+ __metadata("design:returntype", Perspective)
199
+ ], PerspectiveResolver.prototype, "perspectiveSnapshot", null);
200
+ __decorate([
201
+ Mutation(returns => String, { nullable: true }),
202
+ __param(0, Arg('uuid')),
203
+ __metadata("design:type", Function),
204
+ __metadata("design:paramtypes", [String]),
205
+ __metadata("design:returntype", String)
206
+ ], PerspectiveResolver.prototype, "perspectivePublishSnapshot", null);
207
+ __decorate([
208
+ Query(returns => [LinkExpression], { nullable: true }),
209
+ __param(0, Arg('uuid')),
210
+ __param(1, Arg('query')),
211
+ __metadata("design:type", Function),
212
+ __metadata("design:paramtypes", [String, LinkQuery]),
213
+ __metadata("design:returntype", Array)
214
+ ], PerspectiveResolver.prototype, "perspectiveQueryLinks", null);
215
+ __decorate([
216
+ Query(returns => String),
217
+ __param(0, Arg('uuid')),
218
+ __param(1, Arg('query')),
219
+ __metadata("design:type", Function),
220
+ __metadata("design:paramtypes", [String, String]),
221
+ __metadata("design:returntype", String)
222
+ ], PerspectiveResolver.prototype, "perspectiveQueryProlog", null);
223
+ __decorate([
224
+ Mutation(returns => PerspectiveHandle),
225
+ __param(0, Arg('name')),
226
+ __param(1, PubSub()),
227
+ __metadata("design:type", Function),
228
+ __metadata("design:paramtypes", [String, Object]),
229
+ __metadata("design:returntype", PerspectiveHandle)
230
+ ], PerspectiveResolver.prototype, "perspectiveAdd", null);
231
+ __decorate([
232
+ Mutation(returns => PerspectiveHandle, { nullable: true }),
233
+ __param(0, Arg('uuid')),
234
+ __param(1, Arg('name')),
235
+ __param(2, PubSub()),
236
+ __metadata("design:type", Function),
237
+ __metadata("design:paramtypes", [String, String, Object]),
238
+ __metadata("design:returntype", PerspectiveHandle)
239
+ ], PerspectiveResolver.prototype, "perspectiveUpdate", null);
240
+ __decorate([
241
+ Mutation(returns => Boolean),
242
+ __param(0, Arg('uuid')),
243
+ __param(1, PubSub()),
244
+ __metadata("design:type", Function),
245
+ __metadata("design:paramtypes", [String, Object]),
246
+ __metadata("design:returntype", Boolean)
247
+ ], PerspectiveResolver.prototype, "perspectiveRemove", null);
248
+ __decorate([
249
+ Mutation(returns => LinkExpression),
250
+ __param(0, Arg('uuid')),
251
+ __param(1, Arg('link')),
252
+ __param(2, Arg('status', { nullable: true, defaultValue: 'shared' })),
253
+ __param(3, PubSub()),
254
+ __metadata("design:type", Function),
255
+ __metadata("design:paramtypes", [String, LinkInput, String, Object]),
256
+ __metadata("design:returntype", LinkExpression)
257
+ ], PerspectiveResolver.prototype, "perspectiveAddLink", null);
258
+ __decorate([
259
+ Mutation(returns => [LinkExpression]),
260
+ __param(0, Arg('uuid')),
261
+ __param(1, Arg('links', type => [LinkInput])),
262
+ __param(2, Arg('status', { nullable: true })),
263
+ __param(3, PubSub()),
264
+ __metadata("design:type", Function),
265
+ __metadata("design:paramtypes", [String, Array, String, Object]),
266
+ __metadata("design:returntype", Array)
267
+ ], PerspectiveResolver.prototype, "perspectiveAddLinks", null);
268
+ __decorate([
269
+ Mutation(returns => [LinkExpression]),
270
+ __param(0, Arg('uuid')),
271
+ __param(1, Arg('links', type => [LinkExpressionInput])),
272
+ __param(2, PubSub()),
273
+ __metadata("design:type", Function),
274
+ __metadata("design:paramtypes", [String, Array, Object]),
275
+ __metadata("design:returntype", Array)
276
+ ], PerspectiveResolver.prototype, "perspectiveRemoveLinks", null);
277
+ __decorate([
278
+ Mutation(returns => LinkExpressionMutations),
279
+ __param(0, Arg('uuid')),
280
+ __param(1, Arg('mutations')),
281
+ __param(2, Arg('status', { nullable: true })),
282
+ __param(3, PubSub()),
283
+ __metadata("design:type", Function),
284
+ __metadata("design:paramtypes", [String, LinkMutations, String, Object]),
285
+ __metadata("design:returntype", LinkExpressionMutations)
286
+ ], PerspectiveResolver.prototype, "perspectiveLinkMutations", null);
287
+ __decorate([
288
+ Mutation(returns => LinkExpression),
289
+ __param(0, Arg('uuid')),
290
+ __param(1, Arg('link')),
291
+ __param(2, Arg('status', { nullable: true })),
292
+ __param(3, PubSub()),
293
+ __metadata("design:type", Function),
294
+ __metadata("design:paramtypes", [String, LinkExpressionInput, String, Object]),
295
+ __metadata("design:returntype", LinkExpression)
296
+ ], PerspectiveResolver.prototype, "perspectiveAddLinkExpression", null);
297
+ __decorate([
298
+ Mutation(returns => LinkExpression),
299
+ __param(0, Arg('uuid')),
300
+ __param(1, Arg('oldLink')),
301
+ __param(2, Arg('newLink')),
302
+ __param(3, PubSub()),
303
+ __metadata("design:type", Function),
304
+ __metadata("design:paramtypes", [String, LinkExpressionInput, LinkInput, Object]),
305
+ __metadata("design:returntype", LinkExpression)
306
+ ], PerspectiveResolver.prototype, "perspectiveUpdateLink", null);
307
+ __decorate([
308
+ Mutation(returns => Boolean),
309
+ __param(0, Arg('uuid')),
310
+ __param(1, Arg('link')),
311
+ __param(2, PubSub()),
312
+ __metadata("design:type", Function),
313
+ __metadata("design:paramtypes", [String, LinkExpressionInput, Object]),
314
+ __metadata("design:returntype", Boolean)
315
+ ], PerspectiveResolver.prototype, "perspectiveRemoveLink", null);
316
+ __decorate([
317
+ Mutation(returns => Boolean),
318
+ __param(0, Arg('uuid')),
319
+ __param(1, Arg('name')),
320
+ __param(2, Arg('sdnaCode')),
321
+ __param(3, Arg('sdnaType')),
322
+ __param(4, PubSub()),
323
+ __metadata("design:type", Function),
324
+ __metadata("design:paramtypes", [String, String, String, String, Object]),
325
+ __metadata("design:returntype", Boolean)
326
+ ], PerspectiveResolver.prototype, "perspectiveAddSdna", null);
327
+ __decorate([
328
+ Subscription({ topics: PERSPECTIVE_ADDED_TOPIC, nullable: true }),
329
+ __metadata("design:type", Function),
330
+ __metadata("design:paramtypes", []),
331
+ __metadata("design:returntype", PerspectiveHandle)
332
+ ], PerspectiveResolver.prototype, "perspectiveAdded", null);
333
+ __decorate([
334
+ Subscription({ topics: PERSPECTIVE_UPDATED_TOPIC, nullable: true }),
335
+ __metadata("design:type", Function),
336
+ __metadata("design:paramtypes", []),
337
+ __metadata("design:returntype", PerspectiveHandle)
338
+ ], PerspectiveResolver.prototype, "perspectiveUpdated", null);
339
+ __decorate([
340
+ Subscription({ topics: PERSPECTIVE_REMOVED_TOPIC, nullable: true }),
341
+ __metadata("design:type", Function),
342
+ __metadata("design:paramtypes", []),
343
+ __metadata("design:returntype", String)
344
+ ], PerspectiveResolver.prototype, "perspectiveRemoved", null);
345
+ __decorate([
346
+ Subscription({ topics: LINK_ADDED_TOPIC, nullable: true }),
347
+ __param(0, Arg('uuid')),
348
+ __metadata("design:type", Function),
349
+ __metadata("design:paramtypes", [String]),
350
+ __metadata("design:returntype", LinkExpression)
351
+ ], PerspectiveResolver.prototype, "perspectiveLinkAdded", null);
352
+ __decorate([
353
+ Subscription({ topics: LINK_REMOVED_TOPIC, nullable: true }),
354
+ __param(0, Arg('uuid')),
355
+ __metadata("design:type", Function),
356
+ __metadata("design:paramtypes", [String]),
357
+ __metadata("design:returntype", LinkExpression)
358
+ ], PerspectiveResolver.prototype, "perspectiveLinkRemoved", null);
359
+ __decorate([
360
+ Subscription({ topics: LINK_UDATED_TOPIC, nullable: true }),
361
+ __param(0, Arg('uuid')),
362
+ __metadata("design:type", Function),
363
+ __metadata("design:paramtypes", [String]),
364
+ __metadata("design:returntype", LinkExpressionUpdated)
365
+ ], PerspectiveResolver.prototype, "perspectiveLinkUpdated", null);
366
+ __decorate([
367
+ Subscription({ topics: PERSPECTIVE_SYNC_STATE_CHANGE, nullable: false }),
368
+ __param(0, Arg('uuid')),
369
+ __metadata("design:type", Function),
370
+ __metadata("design:paramtypes", [String]),
371
+ __metadata("design:returntype", String)
372
+ ], PerspectiveResolver.prototype, "perspectiveSyncStateChange", null);
373
+ PerspectiveResolver = __decorate([
374
+ Resolver()
375
+ ], PerspectiveResolver);
376
+ export default PerspectiveResolver;