@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,220 +1,225 @@
1
- import { Arg, Mutation, PubSub, Query, Resolver, Subscription } from "type-graphql";
2
- import { LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations } from "../links/Links";
3
- import { Neighbourhood, NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
4
- import { LinkQuery } from "./LinkQuery";
5
- import { Perspective } from "./Perspective";
6
- import { LinkStatus } from "./PerspectiveProxy";
7
- import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
8
- 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'
9
-
10
- export const testLink = new LinkExpression()
11
- testLink.author = "did:ad4m:test"
12
- testLink.timestamp = Date.now()
13
- testLink.data = {
14
- source: 'root',
15
- target: 'neighbourhood://Qm12345'
16
- }
17
- testLink.proof = {
18
- signature: '',
19
- key: '',
20
- valid: true
21
- }
22
-
23
- /**
24
- * Resolver classes are used here to define the GraphQL schema
25
- * (through the type-graphql annotations)
26
- * and are spawned in the client tests in Ad4mClient.test.ts.
27
- * For the latter, they return test fixtures.
28
- */
29
- @Resolver()
30
- export default class PerspectiveResolver {
31
- @Query(returns => [PerspectiveHandle])
32
- perspectives(): PerspectiveHandle[] {
33
- const p1 = new PerspectiveHandle()
34
- p1.name = 'test-perspective-1'
35
- p1.uuid = '00001'
36
- const p2 = new PerspectiveHandle()
37
- p2.name = 'test-perspective-2'
38
- p2.uuid = '00002'
39
- p2.sharedUrl = 'neighbourhood://Qm12345'
40
- const neighbourhood = new NeighbourhoodExpression();
41
- neighbourhood.data = new Neighbourhood("language://Qm12345", new Perspective());
42
- neighbourhood.author = "did:ad4m:test"
43
- neighbourhood.timestamp = Date.now()
44
- neighbourhood.proof = {
45
- signature: '',
46
- key: '',
47
- valid: true
48
- }
49
- p2.neighbourhood = neighbourhood
50
- p2.state = PerspectiveState.Synced
51
- return [p1, p2]
52
- }
53
-
54
- @Query(returns => PerspectiveHandle, {nullable: true})
55
- perspective(@Arg('uuid') uuid: string): PerspectiveHandle|null {
56
- return new PerspectiveHandle(uuid, 'test-perspective-1')
57
- }
58
-
59
- @Query(returns => Perspective, {nullable: true})
60
- perspectiveSnapshot(@Arg('uuid') uuid: string): Perspective|null {
61
- return new Perspective([testLink])
62
- }
63
-
64
- @Mutation(returns => String, {nullable: true})
65
- perspectivePublishSnapshot(@Arg('uuid') uuid: string): String|null {
66
- return 'perspective://Qm12345'
67
- }
68
-
69
- @Query(returns => [LinkExpression], {nullable: true})
70
- perspectiveQueryLinks(@Arg('uuid') uuid: string, @Arg('query') query: LinkQuery): LinkExpression[] {
71
- return [testLink]
72
- }
73
-
74
- @Query(returns => String)
75
- perspectiveQueryProlog(@Arg('uuid') uuid: string, @Arg('query') query: String): string {
76
- return `[{"X": 1}]`
77
- }
78
-
79
- @Mutation(returns => PerspectiveHandle)
80
- perspectiveAdd(@Arg('name') name: string, @PubSub() pubSub: any): PerspectiveHandle {
81
- const perspective = new PerspectiveHandle('00006', name);
82
- pubSub.publish(PERSPECTIVE_ADDED_TOPIC, { perspective })
83
- return new PerspectiveHandle('00006', name)
84
- }
85
-
86
- @Mutation(returns => PerspectiveHandle, {nullable: true})
87
- perspectiveUpdate(@Arg('uuid') uuid: string, @Arg('name') name: string, @PubSub() pubSub: any): PerspectiveHandle {
88
- const perspective = new PerspectiveHandle(uuid, name);
89
- pubSub.publish(PERSPECTIVE_UPDATED_TOPIC, { perspective })
90
- return new PerspectiveHandle(uuid, name)
91
- }
92
-
93
- @Mutation(returns => Boolean)
94
- perspectiveRemove(@Arg('uuid') uuid: string, @PubSub() pubSub: any): boolean {
95
- const perspective = new PerspectiveHandle(uuid);
96
- pubSub.publish(PERSPECTIVE_REMOVED_TOPIC, { perspective })
97
- return true
98
- }
99
-
100
- @Mutation(returns => LinkExpression)
101
- perspectiveAddLink(@Arg('uuid') uuid: string, @Arg('link') link: LinkInput, @Arg('status', { nullable: true, defaultValue: 'shared'}) status: LinkStatus, @PubSub() pubSub: any): LinkExpression {
102
- const l = new LinkExpression()
103
- l.author = 'did:ad4m:test'
104
- l.timestamp = Date.now()
105
- l.proof = testLink.proof
106
- l.data = link
107
- l.status = status
108
-
109
- pubSub.publish(LINK_ADDED_TOPIC, { link: l })
110
- pubSub.publish(PERSPECTIVE_SYNC_STATE_CHANGE, PerspectiveState.LinkLanguageInstalledButNotSynced)
111
- return l
112
- }
113
-
114
- @Mutation(returns => [LinkExpression])
115
- perspectiveAddLinks(@Arg('uuid') uuid: string, @Arg('links', type => [LinkInput]) links: LinkInput[], @Arg('status', { nullable: true}) status: string, @PubSub() pubSub: any): LinkExpression[] {
116
- const l = new LinkExpression()
117
- l.author = 'did:ad4m:test'
118
- l.timestamp = Date.now()
119
- l.proof = testLink.proof
120
- l.data = links[0]
121
-
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]
127
-
128
- pubSub.publish(LINK_ADDED_TOPIC, { link: l })
129
- pubSub.publish(LINK_ADDED_TOPIC, { link: l2 })
130
- return [l, l2]
131
- }
132
-
133
- @Mutation(returns => [LinkExpression])
134
- perspectiveRemoveLinks(@Arg('uuid') uuid: string, @Arg('links', type => [LinkExpressionInput]) links: LinkExpressionInput[], @PubSub() pubSub: any): LinkExpression[] {
135
- const l = new LinkExpression()
136
- l.author = 'did:ad4m:test'
137
- l.timestamp = Date.now()
138
- l.proof = testLink.proof
139
- l.data = links[0].data
140
-
141
- const l2 = new LinkExpression()
142
- l2.author = 'did:ad4m:test'
143
- l2.timestamp = Date.now()
144
- l2.proof = testLink.proof
145
- l2.data = links[0].data
146
-
147
- pubSub.publish(LINK_REMOVED_TOPIC, { link: l })
148
- pubSub.publish(LINK_ADDED_TOPIC, { link: l2 })
149
- return [l, l2]
150
- }
151
-
152
- @Mutation(returns => LinkExpressionMutations)
153
- perspectiveLinkMutations(@Arg('uuid') uuid: string, @Arg('mutations') mutations: LinkMutations, @Arg('status', { nullable: true}) status: LinkStatus, @PubSub() pubSub: any): LinkExpressionMutations {
154
- const perspectiveAddLinks = this.perspectiveAddLinks(uuid, mutations.additions, status, pubSub);
155
- const perspectiveRemoveLinks = this.perspectiveRemoveLinks(uuid, mutations.removals, pubSub);
156
- return new LinkExpressionMutations(perspectiveAddLinks, perspectiveRemoveLinks)
157
- }
158
-
159
- @Mutation(returns => LinkExpression)
160
- perspectiveAddLinkExpression(@Arg('uuid') uuid: string, @Arg('link') link: LinkExpressionInput, @Arg('status', { nullable: true}) status: LinkStatus, @PubSub() pubSub: any): LinkExpression {
161
- pubSub.publish(LINK_ADDED_TOPIC, { link })
162
- link.status = status;
163
- return link as LinkExpression
164
- }
165
-
166
- @Mutation(returns => LinkExpression)
167
- perspectiveUpdateLink(@Arg('uuid') uuid: string, @Arg('oldLink') oldlink: LinkExpressionInput, @Arg('newLink') newlink: LinkInput, @PubSub() pubSub: any): LinkExpression {
168
- const l = new LinkExpression()
169
- l.author = 'did:ad4m:test'
170
- l.timestamp = Date.now()
171
- l.proof = testLink.proof
172
- l.data = newlink
173
-
174
- pubSub.publish(LINK_REMOVED_TOPIC, { link: l })
175
-
176
- return l
177
- }
178
-
179
- @Mutation(returns => Boolean)
180
- perspectiveRemoveLink(@Arg('uuid') uuid: string, @Arg('link') link: LinkExpressionInput, @PubSub() pubSub: any): Boolean {
181
- pubSub.publish(LINK_REMOVED_TOPIC)
182
- return true
183
- }
184
-
185
- @Subscription({topics: PERSPECTIVE_ADDED_TOPIC, nullable: true})
186
- perspectiveAdded(): PerspectiveHandle {
187
- const perspective = new PerspectiveHandle('00001', 'New Perspective');
188
- return perspective
189
- }
190
-
191
- @Subscription({topics: PERSPECTIVE_UPDATED_TOPIC, nullable: true})
192
- perspectiveUpdated(): PerspectiveHandle {
193
- return new PerspectiveHandle('00001', 'New Perspective')
194
- }
195
-
196
- @Subscription({topics: PERSPECTIVE_REMOVED_TOPIC, nullable: true})
197
- perspectiveRemoved(): string {
198
- return '00006'
199
- }
200
-
201
- @Subscription({topics: LINK_ADDED_TOPIC, nullable: true})
202
- perspectiveLinkAdded(@Arg('uuid') uuid: string): LinkExpression {
203
- return testLink
204
- }
205
-
206
- @Subscription({topics: LINK_REMOVED_TOPIC, nullable: true})
207
- perspectiveLinkRemoved(@Arg('uuid') uuid: string): LinkExpression {
208
- return testLink
209
- }
210
-
211
- @Subscription({topics: LINK_UDATED_TOPIC, nullable: true})
212
- perspectiveLinkUpdated(@Arg('uuid') uuid: string): LinkExpressionUpdated {
213
- return {oldLink: testLink, newLink: testLink}
214
- }
215
-
216
- @Subscription({topics: PERSPECTIVE_SYNC_STATE_CHANGE, nullable: false})
217
- perspectiveSyncStateChange(@Arg('uuid') uuid: string): PerspectiveState {
218
- return PerspectiveState.Synced
219
- }
1
+ import { Arg, Mutation, PubSub, Query, Resolver, Subscription } from "type-graphql";
2
+ import { LinkExpression, LinkExpressionInput, LinkExpressionMutations, LinkExpressionUpdated, LinkInput, LinkMutations } from "../links/Links";
3
+ import { Neighbourhood, NeighbourhoodExpression } from "../neighbourhood/Neighbourhood";
4
+ import { LinkQuery } from "./LinkQuery";
5
+ import { Perspective } from "./Perspective";
6
+ import { LinkStatus } from "./PerspectiveProxy";
7
+ import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
8
+ 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'
9
+
10
+ export const testLink = new LinkExpression()
11
+ testLink.author = "did:ad4m:test"
12
+ testLink.timestamp = Date.now()
13
+ testLink.data = {
14
+ source: 'root',
15
+ target: 'neighbourhood://Qm12345'
16
+ }
17
+ testLink.proof = {
18
+ signature: '',
19
+ key: '',
20
+ valid: true
21
+ }
22
+
23
+ /**
24
+ * Resolver classes are used here to define the GraphQL schema
25
+ * (through the type-graphql annotations)
26
+ * and are spawned in the client tests in Ad4mClient.test.ts.
27
+ * For the latter, they return test fixtures.
28
+ */
29
+ @Resolver()
30
+ export default class PerspectiveResolver {
31
+ @Query(returns => [PerspectiveHandle])
32
+ perspectives(): PerspectiveHandle[] {
33
+ const p1 = new PerspectiveHandle()
34
+ p1.name = 'test-perspective-1'
35
+ p1.uuid = '00001'
36
+ const p2 = new PerspectiveHandle()
37
+ p2.name = 'test-perspective-2'
38
+ p2.uuid = '00002'
39
+ p2.sharedUrl = 'neighbourhood://Qm12345'
40
+ const neighbourhood = new NeighbourhoodExpression();
41
+ neighbourhood.data = new Neighbourhood("language://Qm12345", new Perspective());
42
+ neighbourhood.author = "did:ad4m:test"
43
+ neighbourhood.timestamp = Date.now()
44
+ neighbourhood.proof = {
45
+ signature: '',
46
+ key: '',
47
+ valid: true
48
+ }
49
+ p2.neighbourhood = neighbourhood
50
+ p2.state = PerspectiveState.Synced
51
+ return [p1, p2]
52
+ }
53
+
54
+ @Query(returns => PerspectiveHandle, {nullable: true})
55
+ perspective(@Arg('uuid') uuid: string): PerspectiveHandle|null {
56
+ return new PerspectiveHandle(uuid, 'test-perspective-1')
57
+ }
58
+
59
+ @Query(returns => Perspective, {nullable: true})
60
+ perspectiveSnapshot(@Arg('uuid') uuid: string): Perspective|null {
61
+ return new Perspective([testLink])
62
+ }
63
+
64
+ @Mutation(returns => String, {nullable: true})
65
+ perspectivePublishSnapshot(@Arg('uuid') uuid: string): String|null {
66
+ return 'perspective://Qm12345'
67
+ }
68
+
69
+ @Query(returns => [LinkExpression], {nullable: true})
70
+ perspectiveQueryLinks(@Arg('uuid') uuid: string, @Arg('query') query: LinkQuery): LinkExpression[] {
71
+ return [testLink]
72
+ }
73
+
74
+ @Query(returns => String)
75
+ perspectiveQueryProlog(@Arg('uuid') uuid: string, @Arg('query') query: String): string {
76
+ return `[{"X": 1}]`
77
+ }
78
+
79
+ @Mutation(returns => PerspectiveHandle)
80
+ perspectiveAdd(@Arg('name') name: string, @PubSub() pubSub: any): PerspectiveHandle {
81
+ const perspective = new PerspectiveHandle('00006', name);
82
+ pubSub.publish(PERSPECTIVE_ADDED_TOPIC, { perspective })
83
+ return new PerspectiveHandle('00006', name)
84
+ }
85
+
86
+ @Mutation(returns => PerspectiveHandle, {nullable: true})
87
+ perspectiveUpdate(@Arg('uuid') uuid: string, @Arg('name') name: string, @PubSub() pubSub: any): PerspectiveHandle {
88
+ const perspective = new PerspectiveHandle(uuid, name);
89
+ pubSub.publish(PERSPECTIVE_UPDATED_TOPIC, { perspective })
90
+ return new PerspectiveHandle(uuid, name)
91
+ }
92
+
93
+ @Mutation(returns => Boolean)
94
+ perspectiveRemove(@Arg('uuid') uuid: string, @PubSub() pubSub: any): boolean {
95
+ const perspective = new PerspectiveHandle(uuid);
96
+ pubSub.publish(PERSPECTIVE_REMOVED_TOPIC, { perspective })
97
+ return true
98
+ }
99
+
100
+ @Mutation(returns => LinkExpression)
101
+ perspectiveAddLink(@Arg('uuid') uuid: string, @Arg('link') link: LinkInput, @Arg('status', { nullable: true, defaultValue: 'shared'}) status: LinkStatus, @PubSub() pubSub: any): LinkExpression {
102
+ const l = new LinkExpression()
103
+ l.author = 'did:ad4m:test'
104
+ l.timestamp = Date.now()
105
+ l.proof = testLink.proof
106
+ l.data = link
107
+ l.status = status
108
+
109
+ pubSub.publish(LINK_ADDED_TOPIC, { link: l })
110
+ pubSub.publish(PERSPECTIVE_SYNC_STATE_CHANGE, PerspectiveState.LinkLanguageInstalledButNotSynced)
111
+ return l
112
+ }
113
+
114
+ @Mutation(returns => [LinkExpression])
115
+ perspectiveAddLinks(@Arg('uuid') uuid: string, @Arg('links', type => [LinkInput]) links: LinkInput[], @Arg('status', { nullable: true}) status: string, @PubSub() pubSub: any): LinkExpression[] {
116
+ const l = new LinkExpression()
117
+ l.author = 'did:ad4m:test'
118
+ l.timestamp = Date.now()
119
+ l.proof = testLink.proof
120
+ l.data = links[0]
121
+
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]
127
+
128
+ pubSub.publish(LINK_ADDED_TOPIC, { link: l })
129
+ pubSub.publish(LINK_ADDED_TOPIC, { link: l2 })
130
+ return [l, l2]
131
+ }
132
+
133
+ @Mutation(returns => [LinkExpression])
134
+ perspectiveRemoveLinks(@Arg('uuid') uuid: string, @Arg('links', type => [LinkExpressionInput]) links: LinkExpressionInput[], @PubSub() pubSub: any): LinkExpression[] {
135
+ const l = new LinkExpression()
136
+ l.author = 'did:ad4m:test'
137
+ l.timestamp = Date.now()
138
+ l.proof = testLink.proof
139
+ l.data = links[0].data
140
+
141
+ const l2 = new LinkExpression()
142
+ l2.author = 'did:ad4m:test'
143
+ l2.timestamp = Date.now()
144
+ l2.proof = testLink.proof
145
+ l2.data = links[0].data
146
+
147
+ pubSub.publish(LINK_REMOVED_TOPIC, { link: l })
148
+ pubSub.publish(LINK_ADDED_TOPIC, { link: l2 })
149
+ return [l, l2]
150
+ }
151
+
152
+ @Mutation(returns => LinkExpressionMutations)
153
+ perspectiveLinkMutations(@Arg('uuid') uuid: string, @Arg('mutations') mutations: LinkMutations, @Arg('status', { nullable: true}) status: LinkStatus, @PubSub() pubSub: any): LinkExpressionMutations {
154
+ const perspectiveAddLinks = this.perspectiveAddLinks(uuid, mutations.additions, status, pubSub);
155
+ const perspectiveRemoveLinks = this.perspectiveRemoveLinks(uuid, mutations.removals, pubSub);
156
+ return new LinkExpressionMutations(perspectiveAddLinks, perspectiveRemoveLinks)
157
+ }
158
+
159
+ @Mutation(returns => LinkExpression)
160
+ perspectiveAddLinkExpression(@Arg('uuid') uuid: string, @Arg('link') link: LinkExpressionInput, @Arg('status', { nullable: true}) status: LinkStatus, @PubSub() pubSub: any): LinkExpression {
161
+ pubSub.publish(LINK_ADDED_TOPIC, { link })
162
+ link.status = status;
163
+ return link as LinkExpression
164
+ }
165
+
166
+ @Mutation(returns => LinkExpression)
167
+ perspectiveUpdateLink(@Arg('uuid') uuid: string, @Arg('oldLink') oldlink: LinkExpressionInput, @Arg('newLink') newlink: LinkInput, @PubSub() pubSub: any): LinkExpression {
168
+ const l = new LinkExpression()
169
+ l.author = 'did:ad4m:test'
170
+ l.timestamp = Date.now()
171
+ l.proof = testLink.proof
172
+ l.data = newlink
173
+
174
+ pubSub.publish(LINK_REMOVED_TOPIC, { link: l })
175
+
176
+ return l
177
+ }
178
+
179
+ @Mutation(returns => Boolean)
180
+ perspectiveRemoveLink(@Arg('uuid') uuid: string, @Arg('link') link: LinkExpressionInput, @PubSub() pubSub: any): Boolean {
181
+ pubSub.publish(LINK_REMOVED_TOPIC)
182
+ return true
183
+ }
184
+
185
+ @Mutation(returns => Boolean)
186
+ perspectiveAddSdna(@Arg('uuid') uuid: string, @Arg('name') name: string, @Arg('sdnaCode') sdnaCode: string, @Arg('sdnaType') sdnaType: string, @PubSub() pubSub: any): Boolean {
187
+ return true
188
+ }
189
+
190
+ @Subscription({topics: PERSPECTIVE_ADDED_TOPIC, nullable: true})
191
+ perspectiveAdded(): PerspectiveHandle {
192
+ const perspective = new PerspectiveHandle('00001', 'New Perspective');
193
+ return perspective
194
+ }
195
+
196
+ @Subscription({topics: PERSPECTIVE_UPDATED_TOPIC, nullable: true})
197
+ perspectiveUpdated(): PerspectiveHandle {
198
+ return new PerspectiveHandle('00001', 'New Perspective')
199
+ }
200
+
201
+ @Subscription({topics: PERSPECTIVE_REMOVED_TOPIC, nullable: true})
202
+ perspectiveRemoved(): string {
203
+ return '00006'
204
+ }
205
+
206
+ @Subscription({topics: LINK_ADDED_TOPIC, nullable: true})
207
+ perspectiveLinkAdded(@Arg('uuid') uuid: string): LinkExpression {
208
+ return testLink
209
+ }
210
+
211
+ @Subscription({topics: LINK_REMOVED_TOPIC, nullable: true})
212
+ perspectiveLinkRemoved(@Arg('uuid') uuid: string): LinkExpression {
213
+ return testLink
214
+ }
215
+
216
+ @Subscription({topics: LINK_UDATED_TOPIC, nullable: true})
217
+ perspectiveLinkUpdated(@Arg('uuid') uuid: string): LinkExpressionUpdated {
218
+ return {oldLink: testLink, newLink: testLink}
219
+ }
220
+
221
+ @Subscription({topics: PERSPECTIVE_SYNC_STATE_CHANGE, nullable: false})
222
+ perspectiveSyncStateChange(@Arg('uuid') uuid: string): PerspectiveState {
223
+ return PerspectiveState.Synced
224
+ }
220
225
  }