@coasys/ad4m 0.8.0 → 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.
- package/lib/index.cjs +19 -47
- package/lib/index.js +8081 -0
- package/lib/shims/reflect-metadata.js +0 -0
- package/lib/shims/type-graphql.js +70 -0
- package/lib/src/Ad4mClient.js +66 -0
- package/lib/src/Address.js +1 -0
- package/lib/src/DID.js +1 -0
- package/lib/src/Exception.js +7 -0
- package/lib/src/Literal.js +76 -0
- package/lib/src/PubSub.js +14 -0
- package/lib/src/SmartLiteral.js +74 -0
- package/lib/src/agent/Agent.js +337 -0
- package/lib/src/agent/AgentClient.js +431 -0
- package/lib/src/agent/AgentResolver.js +325 -0
- package/lib/src/agent/AgentStatus.js +61 -0
- package/lib/src/buildSchema.js +36 -0
- package/lib/src/expression/Expression.js +143 -0
- package/lib/src/expression/ExpressionClient.js +102 -0
- package/lib/src/expression/ExpressionRef.js +67 -0
- package/lib/src/expression/ExpressionResolver.js +106 -0
- package/lib/src/index.js +30 -0
- package/lib/src/jestSetup.js +1 -0
- package/lib/src/language/Icon.js +24 -0
- package/lib/src/language/Language.js +79 -0
- package/lib/src/language/LanguageClient.js +137 -0
- package/lib/src/language/LanguageContext.js +2 -0
- package/lib/src/language/LanguageHandle.js +41 -0
- package/lib/src/language/LanguageMeta.js +89 -0
- package/lib/src/language/LanguageRef.js +30 -0
- package/lib/src/language/LanguageResolver.js +143 -0
- package/lib/src/links/Links.js +148 -0
- package/lib/src/links/Links.test.js +33 -0
- package/lib/src/neighbourhood/Neighbourhood.js +38 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.js +256 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +54 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +180 -0
- package/lib/src/perspectives/LinkQuery.js +80 -0
- package/lib/src/perspectives/Perspective.js +144 -0
- package/lib/src/perspectives/Perspective.test.js +20 -0
- package/lib/src/perspectives/PerspectiveClient.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveClient.js +418 -0
- package/lib/src/perspectives/PerspectiveDiff.js +33 -0
- package/lib/src/perspectives/PerspectiveHandle.js +59 -0
- package/lib/src/perspectives/PerspectiveProxy.d.ts +8 -8
- package/lib/src/perspectives/PerspectiveProxy.js +501 -0
- package/lib/src/perspectives/PerspectiveResolver.d.ts +1 -0
- package/lib/src/perspectives/PerspectiveResolver.js +376 -0
- package/lib/src/runtime/RuntimeClient.js +263 -0
- package/lib/src/runtime/RuntimeResolver.js +328 -0
- package/lib/src/schema.gql +1 -0
- package/lib/src/subject/SDNADecorators.js +250 -0
- package/lib/src/subject/Subject.js +160 -0
- package/lib/src/subject/SubjectEntity.js +250 -0
- package/lib/src/subject/util.js +73 -0
- package/lib/src/typeDefs.js +380 -0
- package/lib/src/unwrapApolloResult.js +14 -0
- package/lib/src/utils.js +21 -0
- package/package.json +2 -1
- package/src/Ad4mClient.test.ts +5 -0
- package/src/perspectives/PerspectiveClient.ts +9 -0
- package/src/perspectives/PerspectiveProxy.ts +22 -56
- package/src/perspectives/PerspectiveResolver.ts +5 -0
- package/src/unwrapApolloResult.ts +3 -1
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
|
|
2
|
+
export const typeDefsString = `
|
|
3
|
+
type Agent {
|
|
4
|
+
did: String!
|
|
5
|
+
directMessageLanguage: String
|
|
6
|
+
perspective: Perspective
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type AgentSignature {
|
|
10
|
+
publicKey: String!
|
|
11
|
+
signature: String!
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type AgentStatus {
|
|
15
|
+
did: String
|
|
16
|
+
didDocument: String
|
|
17
|
+
error: String
|
|
18
|
+
isInitialized: Boolean!
|
|
19
|
+
isUnlocked: Boolean!
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Apps {
|
|
23
|
+
auth: AuthInfo!
|
|
24
|
+
requestId: String!
|
|
25
|
+
revoked: Boolean
|
|
26
|
+
token: String!
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type AuthInfo {
|
|
30
|
+
appDesc: String!
|
|
31
|
+
appIconPath: String
|
|
32
|
+
appName: String!
|
|
33
|
+
appUrl: String!
|
|
34
|
+
capabilities: [Capability!]!
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
input AuthInfoInput {
|
|
38
|
+
appDesc: String!
|
|
39
|
+
appDomain: String!
|
|
40
|
+
appIconPath: String
|
|
41
|
+
appName: String!
|
|
42
|
+
appUrl: String
|
|
43
|
+
capabilities: [CapabilityInput!]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type Capability {
|
|
47
|
+
can: [String!]!
|
|
48
|
+
with: Resource!
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
input CapabilityInput {
|
|
52
|
+
can: [String!]!
|
|
53
|
+
with: ResourceInput!
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
scalar DateTime
|
|
57
|
+
|
|
58
|
+
type EntanglementProof {
|
|
59
|
+
deviceKey: String!
|
|
60
|
+
deviceKeySignedByDid: String!
|
|
61
|
+
deviceKeyType: String!
|
|
62
|
+
did: String!
|
|
63
|
+
didSignedByDeviceKey: String
|
|
64
|
+
didSigningKeyId: String!
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
input EntanglementProofInput {
|
|
68
|
+
deviceKey: String!
|
|
69
|
+
deviceKeySignedByDid: String!
|
|
70
|
+
deviceKeyType: String!
|
|
71
|
+
did: String!
|
|
72
|
+
didSignedByDeviceKey: String!
|
|
73
|
+
didSigningKeyId: String!
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type ExceptionInfo {
|
|
77
|
+
addon: String
|
|
78
|
+
message: String!
|
|
79
|
+
title: String!
|
|
80
|
+
type: Float!
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
type ExpressionProof {
|
|
84
|
+
invalid: Boolean
|
|
85
|
+
key: String
|
|
86
|
+
signature: String
|
|
87
|
+
valid: Boolean
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
input ExpressionProofInput {
|
|
91
|
+
invalid: Boolean
|
|
92
|
+
key: String
|
|
93
|
+
signature: String
|
|
94
|
+
valid: Boolean
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
type ExpressionRendered {
|
|
98
|
+
author: String!
|
|
99
|
+
data: String!
|
|
100
|
+
icon: Icon!
|
|
101
|
+
language: LanguageRef!
|
|
102
|
+
proof: ExpressionProof!
|
|
103
|
+
timestamp: String!
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type Icon {
|
|
107
|
+
code: String!
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
input InteractionCall {
|
|
111
|
+
name: String!
|
|
112
|
+
parametersStringified: String!
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
type InteractionMeta {
|
|
116
|
+
label: String!
|
|
117
|
+
name: String!
|
|
118
|
+
parameters: [InteractionParameter!]!
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type InteractionParameter {
|
|
122
|
+
name: String!
|
|
123
|
+
type: String!
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type LanguageHandle {
|
|
127
|
+
address: String!
|
|
128
|
+
constructorIcon: Icon
|
|
129
|
+
icon: Icon
|
|
130
|
+
name: String!
|
|
131
|
+
settings: String
|
|
132
|
+
settingsIcon: Icon
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
type LanguageMeta {
|
|
136
|
+
address: String!
|
|
137
|
+
author: String!
|
|
138
|
+
description: String
|
|
139
|
+
name: String!
|
|
140
|
+
possibleTemplateParams: [String!]
|
|
141
|
+
sourceCodeLink: String
|
|
142
|
+
templateAppliedParams: String
|
|
143
|
+
templateSourceLanguageAddress: String
|
|
144
|
+
templated: Boolean
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
input LanguageMetaInput {
|
|
148
|
+
description: String = ""
|
|
149
|
+
name: String!
|
|
150
|
+
possibleTemplateParams: [String!]
|
|
151
|
+
sourceCodeLink: String
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type LanguageRef {
|
|
155
|
+
address: String!
|
|
156
|
+
name: String!
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type Link {
|
|
160
|
+
predicate: String
|
|
161
|
+
source: String!
|
|
162
|
+
target: String!
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
type LinkExpression {
|
|
166
|
+
author: String!
|
|
167
|
+
data: Link!
|
|
168
|
+
proof: ExpressionProof!
|
|
169
|
+
status: String
|
|
170
|
+
timestamp: String!
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
input LinkExpressionInput {
|
|
174
|
+
author: String!
|
|
175
|
+
data: LinkInput!
|
|
176
|
+
proof: ExpressionProofInput!
|
|
177
|
+
status: String = "shared"
|
|
178
|
+
timestamp: String!
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
type LinkExpressionMutations {
|
|
182
|
+
additions: [LinkExpression!]!
|
|
183
|
+
removals: [LinkExpression!]!
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
type LinkExpressionUpdated {
|
|
187
|
+
newLink: LinkExpression!
|
|
188
|
+
oldLink: LinkExpression!
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
input LinkInput {
|
|
192
|
+
predicate: String
|
|
193
|
+
source: String!
|
|
194
|
+
target: String!
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
input LinkMutations {
|
|
198
|
+
additions: [LinkInput!]!
|
|
199
|
+
removals: [LinkExpressionInput!]!
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
input LinkQuery {
|
|
203
|
+
fromDate: DateTime
|
|
204
|
+
limit: Float
|
|
205
|
+
predicate: String
|
|
206
|
+
source: String
|
|
207
|
+
target: String
|
|
208
|
+
untilDate: DateTime
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type Mutation {
|
|
212
|
+
addTrustedAgents(agents: [String!]!): [String!]!
|
|
213
|
+
agentAddEntanglementProofs(proofs: [EntanglementProofInput!]!): [EntanglementProof!]!
|
|
214
|
+
agentDeleteEntanglementProofs(proofs: [EntanglementProofInput!]!): [EntanglementProof!]!
|
|
215
|
+
agentEntanglementProofPreFlight(deviceKey: String!, deviceKeyType: String!): EntanglementProof!
|
|
216
|
+
agentGenerate(passphrase: String!): AgentStatus!
|
|
217
|
+
agentGenerateJwt(rand: String!, requestId: String!): String!
|
|
218
|
+
agentImport(did: String!, didDocument: String!, keystore: String!, passphrase: String!): AgentStatus!
|
|
219
|
+
agentLock(passphrase: String!): AgentStatus!
|
|
220
|
+
agentPermitCapability(auth: String!): String!
|
|
221
|
+
agentRemoveApp(requestId: String!): [Apps!]!
|
|
222
|
+
agentRequestCapability(authInfo: AuthInfoInput!): String!
|
|
223
|
+
agentRevokeToken(requestId: String!): [Apps!]!
|
|
224
|
+
agentSignMessage(message: String!): AgentSignature!
|
|
225
|
+
agentUnlock(holochain: Boolean!, passphrase: String!): AgentStatus!
|
|
226
|
+
agentUpdateDirectMessageLanguage(directMessageLanguage: String!): Agent!
|
|
227
|
+
agentUpdatePublicPerspective(perspective: PerspectiveInput!): Agent!
|
|
228
|
+
deleteTrustedAgents(agents: [String!]!): [String!]!
|
|
229
|
+
expressionCreate(content: String!, languageAddress: String!): String!
|
|
230
|
+
expressionInteract(interactionCall: InteractionCall!, url: String!): String
|
|
231
|
+
languageApplyTemplateAndPublish(sourceLanguageHash: String!, templateData: String!): LanguageRef!
|
|
232
|
+
languagePublish(languageMeta: LanguageMetaInput!, languagePath: String!): LanguageMeta!
|
|
233
|
+
languageRemove(address: String!): Boolean!
|
|
234
|
+
languageWriteSettings(languageAddress: String!, settings: String!): Boolean!
|
|
235
|
+
neighbourhoodJoinFromUrl(url: String!): PerspectiveHandle!
|
|
236
|
+
neighbourhoodPublishFromPerspective(linkLanguage: String!, meta: PerspectiveInput!, perspectiveUUID: String!): String!
|
|
237
|
+
neighbourhoodSendBroadcast(payload: PerspectiveInput!, perspectiveUUID: String!): Boolean!
|
|
238
|
+
neighbourhoodSendBroadcastU(payload: PerspectiveUnsignedInput!, perspectiveUUID: String!): Boolean!
|
|
239
|
+
neighbourhoodSendSignal(payload: PerspectiveInput!, perspectiveUUID: String!, remoteAgentDid: String!): Boolean!
|
|
240
|
+
neighbourhoodSendSignalU(payload: PerspectiveUnsignedInput!, perspectiveUUID: String!, remoteAgentDid: String!): Boolean!
|
|
241
|
+
neighbourhoodSetOnlineStatus(perspectiveUUID: String!, status: PerspectiveInput!): Boolean!
|
|
242
|
+
neighbourhoodSetOnlineStatusU(perspectiveUUID: String!, status: PerspectiveUnsignedInput!): Boolean!
|
|
243
|
+
perspectiveAdd(name: String!): PerspectiveHandle!
|
|
244
|
+
perspectiveAddLink(link: LinkInput!, status: String = "shared", uuid: String!): LinkExpression!
|
|
245
|
+
perspectiveAddLinkExpression(link: LinkExpressionInput!, status: String, uuid: String!): LinkExpression!
|
|
246
|
+
perspectiveAddLinks(links: [LinkInput!]!, status: String, uuid: String!): [LinkExpression!]!
|
|
247
|
+
perspectiveAddSdna(name: String!, sdnaCode: String!, sdnaType: String!, uuid: String!): Boolean!
|
|
248
|
+
perspectiveLinkMutations(mutations: LinkMutations!, status: String, uuid: String!): LinkExpressionMutations!
|
|
249
|
+
perspectivePublishSnapshot(uuid: String!): String
|
|
250
|
+
perspectiveRemove(uuid: String!): Boolean!
|
|
251
|
+
perspectiveRemoveLink(link: LinkExpressionInput!, uuid: String!): Boolean!
|
|
252
|
+
perspectiveRemoveLinks(links: [LinkExpressionInput!]!, uuid: String!): [LinkExpression!]!
|
|
253
|
+
perspectiveUpdate(name: String!, uuid: String!): PerspectiveHandle
|
|
254
|
+
perspectiveUpdateLink(newLink: LinkInput!, oldLink: LinkExpressionInput!, uuid: String!): LinkExpression!
|
|
255
|
+
runtimeAddFriends(dids: [String!]!): [String!]!
|
|
256
|
+
runtimeAddKnownLinkLanguageTemplates(addresses: [String!]!): [String!]!
|
|
257
|
+
runtimeFriendSendMessage(did: String!, message: PerspectiveInput!): Boolean!
|
|
258
|
+
runtimeHcAddAgentInfos(agentInfos: String!): Boolean!
|
|
259
|
+
runtimeOpenLink(url: String!): Boolean!
|
|
260
|
+
runtimeQuit: Boolean!
|
|
261
|
+
runtimeRemoveFriends(dids: [String!]!): [String!]!
|
|
262
|
+
runtimeRemoveKnownLinkLanguageTemplates(addresses: [String!]!): [String!]!
|
|
263
|
+
runtimeSetStatus(status: PerspectiveInput!): Boolean!
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
type Neighbourhood {
|
|
267
|
+
linkLanguage: String!
|
|
268
|
+
meta: Perspective!
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
type NeighbourhoodExpression {
|
|
272
|
+
author: String!
|
|
273
|
+
data: Neighbourhood!
|
|
274
|
+
proof: ExpressionProof!
|
|
275
|
+
timestamp: String!
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
type OnlineAgent {
|
|
279
|
+
did: String!
|
|
280
|
+
status: PerspectiveExpression!
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
type Perspective {
|
|
284
|
+
links: [LinkExpression!]!
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
type PerspectiveExpression {
|
|
288
|
+
author: String!
|
|
289
|
+
data: Perspective!
|
|
290
|
+
proof: ExpressionProof!
|
|
291
|
+
timestamp: String!
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
type PerspectiveHandle {
|
|
295
|
+
name: String!
|
|
296
|
+
neighbourhood: NeighbourhoodExpression
|
|
297
|
+
sharedUrl: String
|
|
298
|
+
state: String!
|
|
299
|
+
uuid: String!
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
input PerspectiveInput {
|
|
303
|
+
links: [LinkExpressionInput!]!
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
input PerspectiveUnsignedInput {
|
|
307
|
+
links: [LinkInput!] = []
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
type Query {
|
|
311
|
+
agent: Agent!
|
|
312
|
+
agentByDID(did: String!): Agent
|
|
313
|
+
agentGetApps: [Apps!]!
|
|
314
|
+
agentGetEntanglementProofs: [EntanglementProof!]!
|
|
315
|
+
agentIsLocked: Boolean!
|
|
316
|
+
agentStatus: AgentStatus!
|
|
317
|
+
expression(url: String!): ExpressionRendered
|
|
318
|
+
expressionInteractions(url: String!): [InteractionMeta!]!
|
|
319
|
+
expressionMany(urls: [String!]!): [ExpressionRendered]!
|
|
320
|
+
expressionRaw(url: String!): String
|
|
321
|
+
getTrustedAgents: [String!]!
|
|
322
|
+
language(address: String!): LanguageHandle
|
|
323
|
+
languageMeta(address: String!): LanguageMeta!
|
|
324
|
+
languageSource(address: String!): String!
|
|
325
|
+
languages(filter: String): [LanguageHandle!]!
|
|
326
|
+
neighbourhoodHasTelepresenceAdapter(perspectiveUUID: String!): Boolean!
|
|
327
|
+
neighbourhoodOnlineAgents(perspectiveUUID: String!): [OnlineAgent!]!
|
|
328
|
+
neighbourhoodOtherAgents(perspectiveUUID: String!): [String!]!
|
|
329
|
+
perspective(uuid: String!): PerspectiveHandle
|
|
330
|
+
perspectiveQueryLinks(query: LinkQuery!, uuid: String!): [LinkExpression!]
|
|
331
|
+
perspectiveQueryProlog(query: String!, uuid: String!): String!
|
|
332
|
+
perspectiveSnapshot(uuid: String!): Perspective
|
|
333
|
+
perspectives: [PerspectiveHandle!]!
|
|
334
|
+
runtimeFriendStatus(did: String!): PerspectiveExpression
|
|
335
|
+
runtimeFriends: [String!]!
|
|
336
|
+
runtimeHcAgentInfos: String!
|
|
337
|
+
runtimeInfo: RuntimeInfo!
|
|
338
|
+
runtimeKnownLinkLanguageTemplates: [String!]!
|
|
339
|
+
runtimeMessageInbox(filter: String): [PerspectiveExpression!]!
|
|
340
|
+
runtimeMessageOutbox(filter: String): [SentMessage!]!
|
|
341
|
+
runtimeVerifyStringSignedByDid(data: String!, did: String!, didSigningKeyId: String!, signedData: String!): Boolean!
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
type Resource {
|
|
345
|
+
domain: String!
|
|
346
|
+
pointers: [String!]!
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
input ResourceInput {
|
|
350
|
+
domain: String!
|
|
351
|
+
pointers: [String!]!
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
type RuntimeInfo {
|
|
355
|
+
ad4mExecutorVersion: String!
|
|
356
|
+
isInitialized: Boolean!
|
|
357
|
+
isUnlocked: Boolean!
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
type SentMessage {
|
|
361
|
+
message: PerspectiveExpression!
|
|
362
|
+
recipient: String!
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
type Subscription {
|
|
366
|
+
agentAppsChanged: [Apps!]
|
|
367
|
+
agentStatusChanged: AgentStatus
|
|
368
|
+
agentUpdated: Agent
|
|
369
|
+
exceptionOccurred: ExceptionInfo
|
|
370
|
+
neighbourhoodSignal(perspectiveUUID: String!): PerspectiveExpression
|
|
371
|
+
perspectiveAdded: PerspectiveHandle
|
|
372
|
+
perspectiveLinkAdded(uuid: String!): LinkExpression
|
|
373
|
+
perspectiveLinkRemoved(uuid: String!): LinkExpression
|
|
374
|
+
perspectiveLinkUpdated(uuid: String!): LinkExpressionUpdated
|
|
375
|
+
perspectiveRemoved: String
|
|
376
|
+
perspectiveSyncStateChange(uuid: String!): String!
|
|
377
|
+
perspectiveUpdated: PerspectiveHandle
|
|
378
|
+
runtimeMessageReceived: PerspectiveExpression
|
|
379
|
+
}
|
|
380
|
+
`
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function unwrapApolloResult(result) {
|
|
2
|
+
if (!result) {
|
|
3
|
+
throw "Got no result from Apollo";
|
|
4
|
+
}
|
|
5
|
+
//@ts-ignore
|
|
6
|
+
if (result.error) {
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
throw result.error;
|
|
9
|
+
}
|
|
10
|
+
if (result.errors) {
|
|
11
|
+
throw result.errors;
|
|
12
|
+
}
|
|
13
|
+
return result.data;
|
|
14
|
+
}
|
package/lib/src/utils.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function formatList(list) {
|
|
2
|
+
if (!list?.length) {
|
|
3
|
+
return "";
|
|
4
|
+
}
|
|
5
|
+
if (list.length === 1) {
|
|
6
|
+
return list.toString();
|
|
7
|
+
}
|
|
8
|
+
if (list.length === 2) {
|
|
9
|
+
return list.join(' and ');
|
|
10
|
+
}
|
|
11
|
+
return list.slice(0, -1).join(', ') + ', and ' + list.slice(-1);
|
|
12
|
+
}
|
|
13
|
+
;
|
|
14
|
+
export function capSentence(cap) {
|
|
15
|
+
const can = cap.can.includes("*") ? ["READ", "WRITE", "UPDATE"] : cap.can;
|
|
16
|
+
const domain = cap.with.domain === "*" ? "" : cap.with.domain;
|
|
17
|
+
const pointers = cap.with.pointers.includes("*")
|
|
18
|
+
? ["all AD4M data"]
|
|
19
|
+
: cap.with.pointers;
|
|
20
|
+
return `${formatList(can)} your ${domain} actions, with access to ${formatList(pointers)}`;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"module": "lib/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"private": false,
|
|
8
9
|
"scripts": {
|
|
9
10
|
"build": "patch-package && tsc && pnpm run buildSchema && pnpm run bundle",
|
|
10
11
|
"buildSchema": "node --es-module-specifier-resolution=node lib/src/buildSchema.js",
|
|
@@ -56,5 +57,5 @@
|
|
|
56
57
|
"typescript": "^4.6.2",
|
|
57
58
|
"ws": "8.13.0"
|
|
58
59
|
},
|
|
59
|
-
"version": "0.8.
|
|
60
|
+
"version": "0.8.1"
|
|
60
61
|
}
|
package/src/Ad4mClient.test.ts
CHANGED
|
@@ -787,6 +787,11 @@ describe('Ad4mClient', () => {
|
|
|
787
787
|
const r = await ad4mClient.perspective.removeLink('00001', {author: '', timestamp: '', proof: {signature: '', key: ''}, data:{source: 'root', target: 'none'}})
|
|
788
788
|
expect(r).toBeTruthy()
|
|
789
789
|
})
|
|
790
|
+
|
|
791
|
+
it('addSdna() smoke test', async () => {
|
|
792
|
+
const r = await ad4mClient.perspective.addSdna('00001', "Test", 'subject_class("Test", test)', 'subject_class');
|
|
793
|
+
expect(r).toBeTruthy()
|
|
794
|
+
})
|
|
790
795
|
})
|
|
791
796
|
|
|
792
797
|
describe('.runtime', () => {
|
|
@@ -283,6 +283,15 @@ export class PerspectiveClient {
|
|
|
283
283
|
}))
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
async addSdna(uuid: string, name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom"): Promise<boolean> {
|
|
287
|
+
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
288
|
+
mutation: gql`mutation perspectiveAddSdna($uuid: String!, $name: String!, $sdnaCode: String!, $sdnaType: String!) {
|
|
289
|
+
perspectiveAddSdna(uuid: $uuid, name: $name, sdnaCode: $sdnaCode, sdnaType: $sdnaType)
|
|
290
|
+
}`,
|
|
291
|
+
variables: { uuid, name, sdnaCode, sdnaType }
|
|
292
|
+
})).perspectiveAddSdna
|
|
293
|
+
}
|
|
294
|
+
|
|
286
295
|
// ExpressionClient functions, needed for Subjects:
|
|
287
296
|
async getExpression(expressionURI: string): Promise<ExpressionRendered> {
|
|
288
297
|
return await this.#expressionClient.get(expressionURI)
|
|
@@ -25,6 +25,21 @@ interface Parameter {
|
|
|
25
25
|
* a reference to the PerspectiveClient object that created it.
|
|
26
26
|
*/
|
|
27
27
|
export class PerspectiveProxy {
|
|
28
|
+
/** Unique ID of the perspective */
|
|
29
|
+
uuid: string;
|
|
30
|
+
|
|
31
|
+
/** Given name of the perspective */
|
|
32
|
+
name: string;
|
|
33
|
+
|
|
34
|
+
/** If the perspective is shared as a Neighbourhood, this is the Neighbourhood URL */
|
|
35
|
+
sharedUrl: string|null;
|
|
36
|
+
|
|
37
|
+
/** If the perspective is shared as a Neighbourhood, this is the Neighbourhood Expression */
|
|
38
|
+
neighbourhood: NeighbourhoodExpression|null;
|
|
39
|
+
|
|
40
|
+
/** Returns the state of the perspective **/
|
|
41
|
+
state: PerspectiveState|null;
|
|
42
|
+
|
|
28
43
|
#handle: PerspectiveHandle
|
|
29
44
|
#client: PerspectiveClient
|
|
30
45
|
#perspectiveLinkAddedCallbacks: LinkCallback[]
|
|
@@ -39,6 +54,11 @@ export class PerspectiveProxy {
|
|
|
39
54
|
this.#perspectiveSyncStateChangeCallbacks = []
|
|
40
55
|
this.#handle = handle
|
|
41
56
|
this.#client = ad4m
|
|
57
|
+
this.uuid = this.#handle.uuid;
|
|
58
|
+
this.name = this.#handle.name;
|
|
59
|
+
this.sharedUrl = this.#handle.sharedUrl;
|
|
60
|
+
this.neighbourhood = this.#handle.neighbourhood;
|
|
61
|
+
this.state = this.#handle.state;
|
|
42
62
|
this.#client.addPerspectiveLinkAddedListener(this.#handle.uuid, this.#perspectiveLinkAddedCallbacks)
|
|
43
63
|
this.#client.addPerspectiveLinkRemovedListener(this.#handle.uuid, this.#perspectiveLinkRemovedCallbacks)
|
|
44
64
|
this.#client.addPerspectiveLinkUpdatedListener(this.#handle.uuid, this.#perspectiveLinkUpdatedCallbacks)
|
|
@@ -97,31 +117,6 @@ export class PerspectiveProxy {
|
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
|
|
100
|
-
/** Unique ID of the perspective */
|
|
101
|
-
get uuid(): string {
|
|
102
|
-
return this.#handle.uuid
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** Given name of the perspective */
|
|
106
|
-
get name(): string {
|
|
107
|
-
return this.#handle.name
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** If the perspective is shared as a Neighbourhood, this is the Neighbourhood URL */
|
|
111
|
-
get sharedUrl(): string|void {
|
|
112
|
-
return this.#handle.sharedUrl
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** If the perspective is shared as a Neighbourhood, this is the Neighbourhood Expression */
|
|
116
|
-
get neighbourhood(): NeighbourhoodExpression|void {
|
|
117
|
-
return this.#handle.neighbourhood
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** Returns the state of the perspective **/
|
|
121
|
-
get state(): PerspectiveState {
|
|
122
|
-
return this.#handle.state
|
|
123
|
-
}
|
|
124
|
-
|
|
125
120
|
/** Returns all the links of this perspective that matches the LinkQuery */
|
|
126
121
|
async get(query: LinkQuery): Promise<LinkExpression[]> {
|
|
127
122
|
return await this.#client.queryLinks(this.#handle.uuid, query)
|
|
@@ -332,37 +327,8 @@ export class PerspectiveProxy {
|
|
|
332
327
|
}
|
|
333
328
|
|
|
334
329
|
/** Adds the given Social DNA code to the perspective's SDNA code */
|
|
335
|
-
async addSdna(name: string, sdnaCode: string,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (type === 'subject_class') predicate = "ad4m://has_subject_class"
|
|
339
|
-
else if (type === 'flow') predicate = "ad4m://has_flow"
|
|
340
|
-
|
|
341
|
-
const literalName = Literal.from(name).toUrl();
|
|
342
|
-
|
|
343
|
-
const links = await this.get(new LinkQuery({
|
|
344
|
-
source: "ad4m://self",
|
|
345
|
-
predicate,
|
|
346
|
-
target: literalName
|
|
347
|
-
}))
|
|
348
|
-
|
|
349
|
-
const sdnaLinks: any[] = []
|
|
350
|
-
|
|
351
|
-
if (links.length === 0) {
|
|
352
|
-
sdnaLinks.push(new Link({
|
|
353
|
-
source: "ad4m://self",
|
|
354
|
-
predicate,
|
|
355
|
-
target: literalName
|
|
356
|
-
}));
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
sdnaLinks.push(new Link({
|
|
360
|
-
source: literalName,
|
|
361
|
-
predicate: "ad4m://sdna",
|
|
362
|
-
target: Literal.from(sdnaCode).toUrl()
|
|
363
|
-
}))
|
|
364
|
-
|
|
365
|
-
await this.addLinks(sdnaLinks);
|
|
330
|
+
async addSdna(name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom") {
|
|
331
|
+
return this.#client.addSdna(this.#handle.uuid, name, sdnaCode, sdnaType)
|
|
366
332
|
}
|
|
367
333
|
|
|
368
334
|
/** Returns all the Subject classes defined in this perspectives SDNA */
|
|
@@ -181,6 +181,11 @@ export default class PerspectiveResolver {
|
|
|
181
181
|
pubSub.publish(LINK_REMOVED_TOPIC)
|
|
182
182
|
return true
|
|
183
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
|
+
}
|
|
184
189
|
|
|
185
190
|
@Subscription({topics: PERSPECTIVE_ADDED_TOPIC, nullable: true})
|
|
186
191
|
perspectiveAdded(): PerspectiveHandle {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { ApolloQueryResult, FetchResult } from "@apollo/client/core"
|
|
2
2
|
|
|
3
3
|
export default function unwrapApolloResult(result: ApolloQueryResult<any> | FetchResult<any>) {
|
|
4
|
-
|
|
4
|
+
if(!result) {
|
|
5
|
+
throw "Got no result from Apollo"
|
|
6
|
+
}
|
|
5
7
|
//@ts-ignore
|
|
6
8
|
if(result.error) {
|
|
7
9
|
//@ts-ignore
|