@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,193 +1,193 @@
1
- import { Arg, Mutation, Resolver, Query, Subscription, ObjectType, Field } from "type-graphql";
2
- import { Perspective, PerspectiveExpression, PerspectiveInput } from "../perspectives/Perspective";
3
- import { ExpressionProof } from "../expression/Expression";
4
- import { LinkExpression } from "../links/Links";
5
- import { ExceptionType } from "../Exception";
6
- import { RUNTIME_MESSAGED_RECEIVED_TOPIC, EXCEPTION_OCCURRED_TOPIC } from '../PubSub';
7
-
8
- const testLink = new LinkExpression()
9
- testLink.author = "did:ad4m:test"
10
- testLink.timestamp = Date.now()
11
- testLink.data = {
12
- source: 'root',
13
- target: 'neighbourhood://Qm12345'
14
- }
15
- testLink.proof = {
16
- signature: '',
17
- key: '',
18
- valid: true
19
- }
20
-
21
- const testPerspectiveExpression = new PerspectiveExpression()
22
- testPerspectiveExpression.author = 'did:ad4m:test'
23
- testPerspectiveExpression.timestamp = Date.now().toString()
24
- testPerspectiveExpression.proof = new ExpressionProof('', '')
25
- testPerspectiveExpression.data = new Perspective([testLink])
26
-
27
- @ObjectType()
28
- export class SentMessage {
29
- @Field()
30
- recipient: string;
31
- @Field()
32
- message: PerspectiveExpression;
33
- }
34
-
35
- @ObjectType()
36
- export class RuntimeInfo {
37
- @Field()
38
- ad4mExecutorVersion: string;
39
- @Field()
40
- isInitialized: Boolean;
41
- @Field()
42
- isUnlocked: Boolean;
43
- }
44
-
45
- @ObjectType()
46
- export class ExceptionInfo {
47
- @Field()
48
- title: string;
49
- @Field()
50
- message: string;
51
- @Field()
52
- type: ExceptionType;
53
- @Field({ nullable: true })
54
- addon?: string;
55
- }
56
-
57
- /**
58
- * Resolver classes are used here to define the GraphQL schema
59
- * (through the type-graphql annotations)
60
- * and are spawned in the client tests in Ad4mClient.test.ts.
61
- * For the latter, they return test fixtures.
62
- */
63
- @Resolver()
64
- export default class RuntimeResolver {
65
- @Mutation(returns => Boolean)
66
- runtimeQuit(): Boolean {
67
- return true
68
- }
69
-
70
- @Mutation(returns => Boolean)
71
- runtimeOpenLink(@Arg('url') url: string): Boolean {
72
- return true
73
- }
74
-
75
- @Query(returns => RuntimeInfo)
76
- runtimeInfo(): RuntimeInfo {
77
- return {
78
- ad4mExecutorVersion: "x.x.x",
79
- isInitialized: true,
80
- isUnlocked: true
81
- } as RuntimeInfo
82
- }
83
-
84
- @Mutation(returns => [String])
85
- addTrustedAgents(@Arg("agents", type => [String]) agents: string[]): string[] {
86
- return agents
87
- }
88
-
89
- @Mutation(returns => [String])
90
- deleteTrustedAgents(@Arg("agents", type => [String]) agents: string[]): string[] {
91
- return []
92
- }
93
-
94
- @Query(returns => [String])
95
- getTrustedAgents(): string[] {
96
- return ["agentPubKey"]
97
- }
98
-
99
- @Query(returns => [String])
100
- runtimeKnownLinkLanguageTemplates(): string[] {
101
- return ["Qm12345abcdef"]
102
- }
103
-
104
- @Mutation(returns => [String])
105
- runtimeAddKnownLinkLanguageTemplates(@Arg("addresses", type => [String]) addresses: string[]): string[] {
106
- return addresses
107
- }
108
-
109
- @Mutation(returns => [String])
110
- runtimeRemoveKnownLinkLanguageTemplates(@Arg("addresses", type => [String]) addresses: string[]): string[] {
111
- return []
112
- }
113
-
114
- @Query(returns => [String])
115
- runtimeFriends(): string[] {
116
- return ["did:test:friend"]
117
- }
118
-
119
- @Mutation(returns => [String])
120
- runtimeAddFriends(@Arg("dids", type => [String]) dids: string[]): string[] {
121
- return dids
122
- }
123
-
124
- @Mutation(returns => [String])
125
- runtimeRemoveFriends(@Arg("dids", type => [String]) dids: string[]): string[] {
126
- return []
127
- }
128
-
129
- @Query()
130
- runtimeHcAgentInfos(): String {
131
- return JSON.stringify([{"agent":{"type":"Buffer","data":[9,191,231,58,255,107,202,55,206,57,9,103,17,34,206,195,207,114,5,73,77,198,56,136,17,227,242,231,194,135,128,48,170,189,119,186]},"signature":{"type":"Buffer","data":[195,143,170,36,234,123,255,85,188,138,124,2,91,18,53,231,44,41,240,8,80,131,100,150,165,125,146,90,17,200,190,129,114,211,11,146,150,128,198,199,79,118,157,101,194,68,58,245,98,182,79,139,140,41,143,129,8,136,87,77,180,231,218,11]},"agent_info":{"type":"Buffer","data":[134,165,115,112,97,99,101,196,36,203,165,212,173,24,215,165,196,25,145,248,113,246,139,205,182,241,138,57,0,26,8,217,179,23,126,59,136,128,213,110,225,173,72,197,95,165,97,103,101,110,116,196,36,9,191,231,58,255,107,202,55,206,57,9,103,17,34,206,195,207,114,5,73,77,198,56,136,17,227,242,231,194,135,128,48,170,189,119,186,164,117,114,108,115,145,217,99,107,105,116,115,117,110,101,45,112,114,111,120,121,58,47,47,101,83,52,86,112,54,109,118,80,48,122,116,85,101,104,114,117,113,89,52,102,66,53,101,69,98,121,48,69,66,100,89,84,50,95,67,48,69,112,77,111,76,111,47,107,105,116,115,117,110,101,45,113,117,105,99,47,104,47,49,57,50,46,49,54,56,46,49,55,56,46,54,48,47,112,47,55,55,52,52,47,45,45,172,115,105,103,110,101,100,95,97,116,95,109,115,207,0,0,1,123,233,104,189,50,176,101,120,112,105,114,101,115,95,97,102,116,101,114,95,109,115,206,0,18,79,128,169,109,101,116,97,95,105,110,102,111,196,34,129,187,100,104,116,95,115,116,111,114,97,103,101,95,97,114,99,95,104,97,108,102,95,108,101,110,103,116,104,206,128,0,0,1]}},{"agent":{"type":"Buffer","data":[98,187,145,48,115,209,94,143,31,153,102,69,138,29,133,213,34,52,39,164,157,139,178,111,23,33,118,250,28,155,78,246,128,49,179,38]},"signature":{"type":"Buffer","data":[233,192,38,3,59,248,124,231,57,255,40,154,50,60,119,252,68,198,154,109,175,155,106,217,211,155,109,223,249,91,221,210,17,132,72,230,11,230,247,119,72,244,145,91,75,7,67,5,130,151,44,231,52,220,28,154,212,82,58,90,203,211,236,4]},"agent_info":{"type":"Buffer","data":[134,165,115,112,97,99,101,196,36,203,165,212,173,24,215,165,196,25,145,248,113,246,139,205,182,241,138,57,0,26,8,217,179,23,126,59,136,128,213,110,225,173,72,197,95,165,97,103,101,110,116,196,36,98,187,145,48,115,209,94,143,31,153,102,69,138,29,133,213,34,52,39,164,157,139,178,111,23,33,118,250,28,155,78,246,128,49,179,38,164,117,114,108,115,145,217,99,107,105,116,115,117,110,101,45,112,114,111,120,121,58,47,47,55,101,77,106,48,73,83,72,56,56,81,56,45,89,51,74,89,70,53,76,72,57,83,54,68,119,71,73,49,88,45,115,87,53,68,104,66,87,121,71,119,78,115,47,107,105,116,115,117,110,101,45,113,117,105,99,47,104,47,49,57,50,46,49,54,56,46,49,55,56,46,54,48,47,112,47,55,55,52,52,47,45,45,172,115,105,103,110,101,100,95,97,116,95,109,115,207,0,0,1,123,233,103,45,197,176,101,120,112,105,114,101,115,95,97,102,116,101,114,95,109,115,206,0,18,79,128,169,109,101,116,97,95,105,110,102,111,196,34,129,187,100,104,116,95,115,116,111,114,97,103,101,95,97,114,99,95,104,97,108,102,95,108,101,110,103,116,104,206,128,0,0,1]}},{"agent":{"type":"Buffer","data":[181,101,115,45,214,127,198,153,159,184,30,87,67,224,208,184,203,176,130,158,236,127,153,125,243,183,188,167,154,25,118,254,101,145,210,109]},"signature":{"type":"Buffer","data":[88,189,229,122,44,171,194,156,90,79,148,49,207,224,34,199,219,88,24,243,103,127,123,41,87,171,127,92,6,216,198,171,26,226,237,217,122,78,98,146,55,255,68,240,202,83,58,140,147,185,3,66,15,216,210,22,99,197,73,234,120,17,74,1]},"agent_info":{"type":"Buffer","data":[134,165,115,112,97,99,101,196,36,203,165,212,173,24,215,165,196,25,145,248,113,246,139,205,182,241,138,57,0,26,8,217,179,23,126,59,136,128,213,110,225,173,72,197,95,165,97,103,101,110,116,196,36,181,101,115,45,214,127,198,153,159,184,30,87,67,224,208,184,203,176,130,158,236,127,153,125,243,183,188,167,154,25,118,254,101,145,210,109,164,117,114,108,115,145,217,99,107,105,116,115,117,110,101,45,112,114,111,120,121,58,47,47,114,70,71,83,100,113,104,101,68,107,70,70,56,69,102,109,45,69,116,55,119,81,101,120,83,88,55,65,112,69,51,89,86,99,45,120,102,52,104,106,77,115,77,47,107,105,116,115,117,110,101,45,113,117,105,99,47,104,47,49,57,50,46,49,54,56,46,49,55,56,46,54,48,47,112,47,55,55,52,52,47,45,45,172,115,105,103,110,101,100,95,97,116,95,109,115,207,0,0,1,123,233,113,23,220,176,101,120,112,105,114,101,115,95,97,102,116,101,114,95,109,115,206,0,18,79,128,169,109,101,116,97,95,105,110,102,111,196,34,129,187,100,104,116,95,115,116,111,114,97,103,101,95,97,114,99,95,104,97,108,102,95,108,101,110,103,116,104,206,128,0,0,1]}},{"agent":{"type":"Buffer","data":[3,171,237,107,186,245,165,47,237,235,211,49,245,62,113,53,255,252,223,226,75,118,148,187,23,53,70,174,160,184,64,63,94,210,227,56]},"signature":{"type":"Buffer","data":[129,12,55,104,239,121,138,2,86,106,136,51,219,79,170,8,195,69,81,188,225,192,247,196,54,39,164,110,75,39,240,56,245,189,154,77,72,11,97,250,202,149,242,97,128,28,47,164,236,104,136,82,212,246,44,143,132,119,255,135,112,11,20,13]},"agent_info":{"type":"Buffer","data":[134,165,115,112,97,99,101,196,36,203,165,212,173,24,215,165,196,25,145,248,113,246,139,205,182,241,138,57,0,26,8,217,179,23,126,59,136,128,213,110,225,173,72,197,95,165,97,103,101,110,116,196,36,3,171,237,107,186,245,165,47,237,235,211,49,245,62,113,53,255,252,223,226,75,118,148,187,23,53,70,174,160,184,64,63,94,210,227,56,164,117,114,108,115,145,217,97,107,105,116,115,117,110,101,45,112,114,111,120,121,58,47,47,104,121,112,115,86,121,103,117,80,84,115,53,118,73,80,65,102,97,112,90,88,113,117,84,115,79,80,100,67,81,79,79,117,103,57,51,82,103,106,95,114,85,73,47,107,105,116,115,117,110,101,45,113,117,105,99,47,104,47,49,54,53,46,50,50,46,51,50,46,49,49,47,112,47,53,55,55,57,47,45,45,172,115,105,103,110,101,100,95,97,116,95,109,115,207,0,0,1,123,233,113,188,123,176,101,120,112,105,114,101,115,95,97,102,116,101,114,95,109,115,206,0,18,79,128,169,109,101,116,97,95,105,110,102,111,196,34,129,187,100,104,116,95,115,116,111,114,97,103,101,95,97,114,99,95,104,97,108,102,95,108,101,110,103,116,104,206,128,0,0,1]}}])
132
- }
133
-
134
- @Mutation(returns => Boolean)
135
- runtimeHcAddAgentInfos(@Arg("agentInfos", type => String) agentInfos): boolean {
136
- return true
137
- }
138
-
139
- @Query(returns => Boolean)
140
- runtimeVerifyStringSignedByDid(
141
- @Arg("did", type => String) did: string,
142
- @Arg("didSigningKeyId", type => String) didSigningKeyId: string,
143
- @Arg("data", type => String) data: string,
144
- @Arg("signedData", type => String) signedData: string) {
145
- return true
146
- }
147
-
148
- @Mutation()
149
- runtimeSetStatus(@Arg("status", type => PerspectiveInput) status: Perspective): boolean {
150
- return true
151
- }
152
-
153
- @Query({nullable: true})
154
- runtimeFriendStatus(@Arg("did", type => String) did: string): PerspectiveExpression {
155
- return testPerspectiveExpression
156
- }
157
-
158
- @Mutation()
159
- runtimeFriendSendMessage(
160
- @Arg("did", type => String) did: string,
161
- @Arg("message", type => PerspectiveInput) message: PerspectiveInput
162
- ): boolean {
163
- return true
164
- }
165
-
166
- @Query(returns => [PerspectiveExpression])
167
- runtimeMessageInbox(@Arg("filter", type => String, {nullable: true }) filter?: string): PerspectiveExpression[] {
168
- return [testPerspectiveExpression]
169
- }
170
-
171
- @Query(returns => [SentMessage])
172
- runtimeMessageOutbox(@Arg("filter", type => String, {nullable: true }) filter?: string): SentMessage[] {
173
- return [{
174
- recipient: "did:test:recipient",
175
- message: testPerspectiveExpression
176
- } as SentMessage]
177
- }
178
-
179
-
180
- @Subscription({topics: RUNTIME_MESSAGED_RECEIVED_TOPIC, nullable: true})
181
- runtimeMessageReceived(): PerspectiveExpression {
182
- return testPerspectiveExpression
183
- }
184
-
185
- @Subscription({topics: EXCEPTION_OCCURRED_TOPIC, nullable: true})
186
- exceptionOccurred(): ExceptionInfo {
187
- return {
188
- title: "Test title",
189
- message: "Test message",
190
- type: ExceptionType.LanguageIsNotLoaded,
191
- }
192
- }
1
+ import { Arg, Mutation, Resolver, Query, Subscription, ObjectType, Field } from "type-graphql";
2
+ import { Perspective, PerspectiveExpression, PerspectiveInput } from "../perspectives/Perspective";
3
+ import { ExpressionProof } from "../expression/Expression";
4
+ import { LinkExpression } from "../links/Links";
5
+ import { ExceptionType } from "../Exception";
6
+ import { RUNTIME_MESSAGED_RECEIVED_TOPIC, EXCEPTION_OCCURRED_TOPIC } from '../PubSub';
7
+
8
+ const testLink = new LinkExpression()
9
+ testLink.author = "did:ad4m:test"
10
+ testLink.timestamp = Date.now()
11
+ testLink.data = {
12
+ source: 'root',
13
+ target: 'neighbourhood://Qm12345'
14
+ }
15
+ testLink.proof = {
16
+ signature: '',
17
+ key: '',
18
+ valid: true
19
+ }
20
+
21
+ const testPerspectiveExpression = new PerspectiveExpression()
22
+ testPerspectiveExpression.author = 'did:ad4m:test'
23
+ testPerspectiveExpression.timestamp = Date.now().toString()
24
+ testPerspectiveExpression.proof = new ExpressionProof('', '')
25
+ testPerspectiveExpression.data = new Perspective([testLink])
26
+
27
+ @ObjectType()
28
+ export class SentMessage {
29
+ @Field()
30
+ recipient: string;
31
+ @Field()
32
+ message: PerspectiveExpression;
33
+ }
34
+
35
+ @ObjectType()
36
+ export class RuntimeInfo {
37
+ @Field()
38
+ ad4mExecutorVersion: string;
39
+ @Field()
40
+ isInitialized: Boolean;
41
+ @Field()
42
+ isUnlocked: Boolean;
43
+ }
44
+
45
+ @ObjectType()
46
+ export class ExceptionInfo {
47
+ @Field()
48
+ title: string;
49
+ @Field()
50
+ message: string;
51
+ @Field()
52
+ type: ExceptionType;
53
+ @Field({ nullable: true })
54
+ addon?: string;
55
+ }
56
+
57
+ /**
58
+ * Resolver classes are used here to define the GraphQL schema
59
+ * (through the type-graphql annotations)
60
+ * and are spawned in the client tests in Ad4mClient.test.ts.
61
+ * For the latter, they return test fixtures.
62
+ */
63
+ @Resolver()
64
+ export default class RuntimeResolver {
65
+ @Mutation(returns => Boolean)
66
+ runtimeQuit(): Boolean {
67
+ return true
68
+ }
69
+
70
+ @Mutation(returns => Boolean)
71
+ runtimeOpenLink(@Arg('url') url: string): Boolean {
72
+ return true
73
+ }
74
+
75
+ @Query(returns => RuntimeInfo)
76
+ runtimeInfo(): RuntimeInfo {
77
+ return {
78
+ ad4mExecutorVersion: "x.x.x",
79
+ isInitialized: true,
80
+ isUnlocked: true
81
+ } as RuntimeInfo
82
+ }
83
+
84
+ @Mutation(returns => [String])
85
+ addTrustedAgents(@Arg("agents", type => [String]) agents: string[]): string[] {
86
+ return agents
87
+ }
88
+
89
+ @Mutation(returns => [String])
90
+ deleteTrustedAgents(@Arg("agents", type => [String]) agents: string[]): string[] {
91
+ return []
92
+ }
93
+
94
+ @Query(returns => [String])
95
+ getTrustedAgents(): string[] {
96
+ return ["agentPubKey"]
97
+ }
98
+
99
+ @Query(returns => [String])
100
+ runtimeKnownLinkLanguageTemplates(): string[] {
101
+ return ["Qm12345abcdef"]
102
+ }
103
+
104
+ @Mutation(returns => [String])
105
+ runtimeAddKnownLinkLanguageTemplates(@Arg("addresses", type => [String]) addresses: string[]): string[] {
106
+ return addresses
107
+ }
108
+
109
+ @Mutation(returns => [String])
110
+ runtimeRemoveKnownLinkLanguageTemplates(@Arg("addresses", type => [String]) addresses: string[]): string[] {
111
+ return []
112
+ }
113
+
114
+ @Query(returns => [String])
115
+ runtimeFriends(): string[] {
116
+ return ["did:test:friend"]
117
+ }
118
+
119
+ @Mutation(returns => [String])
120
+ runtimeAddFriends(@Arg("dids", type => [String]) dids: string[]): string[] {
121
+ return dids
122
+ }
123
+
124
+ @Mutation(returns => [String])
125
+ runtimeRemoveFriends(@Arg("dids", type => [String]) dids: string[]): string[] {
126
+ return []
127
+ }
128
+
129
+ @Query()
130
+ runtimeHcAgentInfos(): String {
131
+ return JSON.stringify([{"agent":{"type":"Buffer","data":[9,191,231,58,255,107,202,55,206,57,9,103,17,34,206,195,207,114,5,73,77,198,56,136,17,227,242,231,194,135,128,48,170,189,119,186]},"signature":{"type":"Buffer","data":[195,143,170,36,234,123,255,85,188,138,124,2,91,18,53,231,44,41,240,8,80,131,100,150,165,125,146,90,17,200,190,129,114,211,11,146,150,128,198,199,79,118,157,101,194,68,58,245,98,182,79,139,140,41,143,129,8,136,87,77,180,231,218,11]},"agent_info":{"type":"Buffer","data":[134,165,115,112,97,99,101,196,36,203,165,212,173,24,215,165,196,25,145,248,113,246,139,205,182,241,138,57,0,26,8,217,179,23,126,59,136,128,213,110,225,173,72,197,95,165,97,103,101,110,116,196,36,9,191,231,58,255,107,202,55,206,57,9,103,17,34,206,195,207,114,5,73,77,198,56,136,17,227,242,231,194,135,128,48,170,189,119,186,164,117,114,108,115,145,217,99,107,105,116,115,117,110,101,45,112,114,111,120,121,58,47,47,101,83,52,86,112,54,109,118,80,48,122,116,85,101,104,114,117,113,89,52,102,66,53,101,69,98,121,48,69,66,100,89,84,50,95,67,48,69,112,77,111,76,111,47,107,105,116,115,117,110,101,45,113,117,105,99,47,104,47,49,57,50,46,49,54,56,46,49,55,56,46,54,48,47,112,47,55,55,52,52,47,45,45,172,115,105,103,110,101,100,95,97,116,95,109,115,207,0,0,1,123,233,104,189,50,176,101,120,112,105,114,101,115,95,97,102,116,101,114,95,109,115,206,0,18,79,128,169,109,101,116,97,95,105,110,102,111,196,34,129,187,100,104,116,95,115,116,111,114,97,103,101,95,97,114,99,95,104,97,108,102,95,108,101,110,103,116,104,206,128,0,0,1]}},{"agent":{"type":"Buffer","data":[98,187,145,48,115,209,94,143,31,153,102,69,138,29,133,213,34,52,39,164,157,139,178,111,23,33,118,250,28,155,78,246,128,49,179,38]},"signature":{"type":"Buffer","data":[233,192,38,3,59,248,124,231,57,255,40,154,50,60,119,252,68,198,154,109,175,155,106,217,211,155,109,223,249,91,221,210,17,132,72,230,11,230,247,119,72,244,145,91,75,7,67,5,130,151,44,231,52,220,28,154,212,82,58,90,203,211,236,4]},"agent_info":{"type":"Buffer","data":[134,165,115,112,97,99,101,196,36,203,165,212,173,24,215,165,196,25,145,248,113,246,139,205,182,241,138,57,0,26,8,217,179,23,126,59,136,128,213,110,225,173,72,197,95,165,97,103,101,110,116,196,36,98,187,145,48,115,209,94,143,31,153,102,69,138,29,133,213,34,52,39,164,157,139,178,111,23,33,118,250,28,155,78,246,128,49,179,38,164,117,114,108,115,145,217,99,107,105,116,115,117,110,101,45,112,114,111,120,121,58,47,47,55,101,77,106,48,73,83,72,56,56,81,56,45,89,51,74,89,70,53,76,72,57,83,54,68,119,71,73,49,88,45,115,87,53,68,104,66,87,121,71,119,78,115,47,107,105,116,115,117,110,101,45,113,117,105,99,47,104,47,49,57,50,46,49,54,56,46,49,55,56,46,54,48,47,112,47,55,55,52,52,47,45,45,172,115,105,103,110,101,100,95,97,116,95,109,115,207,0,0,1,123,233,103,45,197,176,101,120,112,105,114,101,115,95,97,102,116,101,114,95,109,115,206,0,18,79,128,169,109,101,116,97,95,105,110,102,111,196,34,129,187,100,104,116,95,115,116,111,114,97,103,101,95,97,114,99,95,104,97,108,102,95,108,101,110,103,116,104,206,128,0,0,1]}},{"agent":{"type":"Buffer","data":[181,101,115,45,214,127,198,153,159,184,30,87,67,224,208,184,203,176,130,158,236,127,153,125,243,183,188,167,154,25,118,254,101,145,210,109]},"signature":{"type":"Buffer","data":[88,189,229,122,44,171,194,156,90,79,148,49,207,224,34,199,219,88,24,243,103,127,123,41,87,171,127,92,6,216,198,171,26,226,237,217,122,78,98,146,55,255,68,240,202,83,58,140,147,185,3,66,15,216,210,22,99,197,73,234,120,17,74,1]},"agent_info":{"type":"Buffer","data":[134,165,115,112,97,99,101,196,36,203,165,212,173,24,215,165,196,25,145,248,113,246,139,205,182,241,138,57,0,26,8,217,179,23,126,59,136,128,213,110,225,173,72,197,95,165,97,103,101,110,116,196,36,181,101,115,45,214,127,198,153,159,184,30,87,67,224,208,184,203,176,130,158,236,127,153,125,243,183,188,167,154,25,118,254,101,145,210,109,164,117,114,108,115,145,217,99,107,105,116,115,117,110,101,45,112,114,111,120,121,58,47,47,114,70,71,83,100,113,104,101,68,107,70,70,56,69,102,109,45,69,116,55,119,81,101,120,83,88,55,65,112,69,51,89,86,99,45,120,102,52,104,106,77,115,77,47,107,105,116,115,117,110,101,45,113,117,105,99,47,104,47,49,57,50,46,49,54,56,46,49,55,56,46,54,48,47,112,47,55,55,52,52,47,45,45,172,115,105,103,110,101,100,95,97,116,95,109,115,207,0,0,1,123,233,113,23,220,176,101,120,112,105,114,101,115,95,97,102,116,101,114,95,109,115,206,0,18,79,128,169,109,101,116,97,95,105,110,102,111,196,34,129,187,100,104,116,95,115,116,111,114,97,103,101,95,97,114,99,95,104,97,108,102,95,108,101,110,103,116,104,206,128,0,0,1]}},{"agent":{"type":"Buffer","data":[3,171,237,107,186,245,165,47,237,235,211,49,245,62,113,53,255,252,223,226,75,118,148,187,23,53,70,174,160,184,64,63,94,210,227,56]},"signature":{"type":"Buffer","data":[129,12,55,104,239,121,138,2,86,106,136,51,219,79,170,8,195,69,81,188,225,192,247,196,54,39,164,110,75,39,240,56,245,189,154,77,72,11,97,250,202,149,242,97,128,28,47,164,236,104,136,82,212,246,44,143,132,119,255,135,112,11,20,13]},"agent_info":{"type":"Buffer","data":[134,165,115,112,97,99,101,196,36,203,165,212,173,24,215,165,196,25,145,248,113,246,139,205,182,241,138,57,0,26,8,217,179,23,126,59,136,128,213,110,225,173,72,197,95,165,97,103,101,110,116,196,36,3,171,237,107,186,245,165,47,237,235,211,49,245,62,113,53,255,252,223,226,75,118,148,187,23,53,70,174,160,184,64,63,94,210,227,56,164,117,114,108,115,145,217,97,107,105,116,115,117,110,101,45,112,114,111,120,121,58,47,47,104,121,112,115,86,121,103,117,80,84,115,53,118,73,80,65,102,97,112,90,88,113,117,84,115,79,80,100,67,81,79,79,117,103,57,51,82,103,106,95,114,85,73,47,107,105,116,115,117,110,101,45,113,117,105,99,47,104,47,49,54,53,46,50,50,46,51,50,46,49,49,47,112,47,53,55,55,57,47,45,45,172,115,105,103,110,101,100,95,97,116,95,109,115,207,0,0,1,123,233,113,188,123,176,101,120,112,105,114,101,115,95,97,102,116,101,114,95,109,115,206,0,18,79,128,169,109,101,116,97,95,105,110,102,111,196,34,129,187,100,104,116,95,115,116,111,114,97,103,101,95,97,114,99,95,104,97,108,102,95,108,101,110,103,116,104,206,128,0,0,1]}}])
132
+ }
133
+
134
+ @Mutation(returns => Boolean)
135
+ runtimeHcAddAgentInfos(@Arg("agentInfos", type => String) agentInfos): boolean {
136
+ return true
137
+ }
138
+
139
+ @Query(returns => Boolean)
140
+ runtimeVerifyStringSignedByDid(
141
+ @Arg("did", type => String) did: string,
142
+ @Arg("didSigningKeyId", type => String) didSigningKeyId: string,
143
+ @Arg("data", type => String) data: string,
144
+ @Arg("signedData", type => String) signedData: string) {
145
+ return true
146
+ }
147
+
148
+ @Mutation()
149
+ runtimeSetStatus(@Arg("status", type => PerspectiveInput) status: Perspective): boolean {
150
+ return true
151
+ }
152
+
153
+ @Query({nullable: true})
154
+ runtimeFriendStatus(@Arg("did", type => String) did: string): PerspectiveExpression {
155
+ return testPerspectiveExpression
156
+ }
157
+
158
+ @Mutation()
159
+ runtimeFriendSendMessage(
160
+ @Arg("did", type => String) did: string,
161
+ @Arg("message", type => PerspectiveInput) message: PerspectiveInput
162
+ ): boolean {
163
+ return true
164
+ }
165
+
166
+ @Query(returns => [PerspectiveExpression])
167
+ runtimeMessageInbox(@Arg("filter", type => String, {nullable: true }) filter?: string): PerspectiveExpression[] {
168
+ return [testPerspectiveExpression]
169
+ }
170
+
171
+ @Query(returns => [SentMessage])
172
+ runtimeMessageOutbox(@Arg("filter", type => String, {nullable: true }) filter?: string): SentMessage[] {
173
+ return [{
174
+ recipient: "did:test:recipient",
175
+ message: testPerspectiveExpression
176
+ } as SentMessage]
177
+ }
178
+
179
+
180
+ @Subscription({topics: RUNTIME_MESSAGED_RECEIVED_TOPIC, nullable: true})
181
+ runtimeMessageReceived(): PerspectiveExpression {
182
+ return testPerspectiveExpression
183
+ }
184
+
185
+ @Subscription({topics: EXCEPTION_OCCURRED_TOPIC, nullable: true})
186
+ exceptionOccurred(): ExceptionInfo {
187
+ return {
188
+ title: "Test title",
189
+ message: "Test message",
190
+ type: ExceptionType.LanguageIsNotLoaded,
191
+ }
192
+ }
193
193
  }