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