@coasys/ad4m 0.10.0 → 0.10.1-dev-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 +3785 -843
- package/lib/index.js +3777 -839
- package/lib/src/Ad4mClient.js +2 -1
- package/lib/src/Literal.js +4 -1
- package/lib/src/ai/AIClient.d.ts +8 -2
- package/lib/src/ai/AIClient.js +25 -14
- package/lib/src/ai/AIResolver.d.ts +25 -6
- package/lib/src/ai/AIResolver.js +102 -18
- package/lib/src/index.d.ts +4 -3
- package/lib/src/index.js +4 -3
- package/lib/src/model/Ad4mModel.d.ts +730 -0
- package/lib/src/model/Ad4mModel.js +1399 -0
- package/lib/src/{subject → model}/Subject.d.ts +2 -2
- package/lib/src/{subject → model}/Subject.js +18 -18
- package/lib/src/model/decorators.d.ts +502 -0
- package/lib/src/model/decorators.js +683 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodClient.js +13 -10
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +4 -4
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +73 -0
- package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +2 -2
- package/lib/src/neighbourhood/NeighbourhoodResolver.js +6 -4
- package/lib/src/perspectives/PerspectiveClient.d.ts +23 -11
- package/lib/src/perspectives/PerspectiveClient.js +147 -51
- package/lib/src/perspectives/PerspectiveProxy.d.ts +494 -54
- package/lib/src/perspectives/PerspectiveProxy.js +684 -67
- package/lib/src/perspectives/PerspectiveResolver.d.ts +24 -9
- package/lib/src/perspectives/PerspectiveResolver.js +151 -46
- package/lib/src/runtime/RuntimeClient.d.ts +8 -2
- package/lib/src/runtime/RuntimeClient.js +64 -0
- package/lib/src/runtime/RuntimeResolver.d.ts +27 -1
- package/lib/src/runtime/RuntimeResolver.js +138 -0
- package/lib/src/schema.gql +55 -16
- package/lib/src/typeDefs.js +55 -16
- package/package.json +4 -3
- package/src/Ad4mClient.test.ts +51 -19
- package/src/Ad4mClient.ts +3 -1
- package/src/Literal.ts +4 -1
- package/src/ai/AIClient.ts +35 -14
- package/src/ai/AIResolver.ts +78 -16
- package/src/index.ts +4 -3
- package/src/model/Ad4mModel.ts +1651 -0
- package/src/{subject → model}/Subject.ts +16 -16
- package/src/{subject/SDNADecorators.ts → model/decorators.ts} +384 -50
- package/src/neighbourhood/NeighbourhoodClient.ts +13 -10
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +100 -0
- package/src/neighbourhood/NeighbourhoodProxy.ts +4 -4
- package/src/neighbourhood/NeighbourhoodResolver.ts +2 -2
- package/src/perspectives/PerspectiveClient.ts +156 -51
- package/src/perspectives/PerspectiveProxy.ts +766 -82
- package/src/perspectives/PerspectiveResolver.ts +134 -23
- package/src/runtime/RuntimeClient.ts +71 -2
- package/src/runtime/RuntimeResolver.ts +91 -1
- package/lib/src/subject/SDNADecorators.d.ts +0 -188
- package/lib/src/subject/SDNADecorators.js +0 -360
- package/lib/src/subject/SubjectEntity.d.ts +0 -102
- package/lib/src/subject/SubjectEntity.js +0 -267
- package/src/subject/SubjectEntity.ts +0 -315
- package/yarn-error.log +0 -90
- /package/lib/src/{subject → model}/util.d.ts +0 -0
- /package/lib/src/{subject → model}/util.js +0 -0
- /package/src/{subject → model}/util.ts +0 -0
|
@@ -184,35 +184,39 @@ export class NeighbourhoodClient {
|
|
|
184
184
|
return neighbourhoodSendSignalU
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
-
async sendBroadcast(perspectiveUUID: string, payload: Perspective): Promise<boolean> {
|
|
187
|
+
async sendBroadcast(perspectiveUUID: string, payload: Perspective, loopback: boolean = false): Promise<boolean> {
|
|
188
188
|
const { neighbourhoodSendBroadcast } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
189
189
|
mutation: gql`mutation neighbourhoodSendBroadcast(
|
|
190
190
|
$perspectiveUUID: String!,
|
|
191
|
-
$payload: PerspectiveInput
|
|
191
|
+
$payload: PerspectiveInput!,
|
|
192
|
+
$loopback: Boolean
|
|
192
193
|
) {
|
|
193
194
|
neighbourhoodSendBroadcast(
|
|
194
195
|
perspectiveUUID: $perspectiveUUID,
|
|
195
|
-
payload: $payload
|
|
196
|
+
payload: $payload,
|
|
197
|
+
loopback: $loopback
|
|
196
198
|
)
|
|
197
199
|
}`,
|
|
198
|
-
variables: { perspectiveUUID, payload }
|
|
200
|
+
variables: { perspectiveUUID, payload, loopback }
|
|
199
201
|
}))
|
|
200
202
|
|
|
201
203
|
return neighbourhoodSendBroadcast
|
|
202
204
|
}
|
|
203
205
|
|
|
204
|
-
async sendBroadcastU(perspectiveUUID: string, payload: PerspectiveUnsignedInput): Promise<boolean> {
|
|
206
|
+
async sendBroadcastU(perspectiveUUID: string, payload: PerspectiveUnsignedInput, loopback: boolean = false): Promise<boolean> {
|
|
205
207
|
const { neighbourhoodSendBroadcastU } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
206
208
|
mutation: gql`mutation neighbourhoodSendBroadcastU(
|
|
207
209
|
$perspectiveUUID: String!,
|
|
208
|
-
$payload: PerspectiveUnsignedInput
|
|
210
|
+
$payload: PerspectiveUnsignedInput!,
|
|
211
|
+
$loopback: Boolean
|
|
209
212
|
) {
|
|
210
213
|
neighbourhoodSendBroadcastU(
|
|
211
214
|
perspectiveUUID: $perspectiveUUID,
|
|
212
|
-
payload: $payload
|
|
215
|
+
payload: $payload,
|
|
216
|
+
loopback: $loopback
|
|
213
217
|
)
|
|
214
218
|
}`,
|
|
215
|
-
variables: { perspectiveUUID, payload }
|
|
219
|
+
variables: { perspectiveUUID, payload, loopback }
|
|
216
220
|
}))
|
|
217
221
|
|
|
218
222
|
return neighbourhoodSendBroadcastU
|
|
@@ -257,10 +261,10 @@ export class NeighbourhoodClient {
|
|
|
257
261
|
let handlersForPerspective = this.#signalHandlers.get(perspectiveUUID)
|
|
258
262
|
if (!handlersForPerspective) {
|
|
259
263
|
handlersForPerspective = []
|
|
264
|
+
this.#signalHandlers.set(perspectiveUUID, handlersForPerspective)
|
|
260
265
|
await this.subscribeToSignals(perspectiveUUID)
|
|
261
266
|
}
|
|
262
267
|
handlersForPerspective.push(handler)
|
|
263
|
-
this.#signalHandlers.set(perspectiveUUID, handlersForPerspective)
|
|
264
268
|
}
|
|
265
269
|
|
|
266
270
|
removeSignalHandler(perspectiveUUID: string, handler: TelepresenceSignalCallback): void {
|
|
@@ -271,6 +275,5 @@ export class NeighbourhoodClient {
|
|
|
271
275
|
handlersForPerspective.splice(index, 1)
|
|
272
276
|
}
|
|
273
277
|
}
|
|
274
|
-
this.#signalHandlers.set(perspectiveUUID, handlersForPerspective)
|
|
275
278
|
}
|
|
276
279
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { NeighbourhoodClient } from "./NeighbourhoodClient";
|
|
2
|
+
import { NeighbourhoodProxy } from "./NeighbourhoodProxy";
|
|
3
|
+
|
|
4
|
+
describe("NeighbourhoodProxy", () => {
|
|
5
|
+
it("should add multiple signal handlers", async () => {
|
|
6
|
+
const neighbourhoodURI = "did://123";
|
|
7
|
+
|
|
8
|
+
const mockApolloClient = {
|
|
9
|
+
subscribe: () => ({
|
|
10
|
+
subscribe: () =>
|
|
11
|
+
new Promise((resolve) => {
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
resolve({});
|
|
14
|
+
}, 10);
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
} as any;
|
|
18
|
+
|
|
19
|
+
const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
|
|
20
|
+
const neighbourhoodProxy = new NeighbourhoodProxy(
|
|
21
|
+
neighbourhoodClient,
|
|
22
|
+
neighbourhoodURI
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
let callbacks = 0;
|
|
26
|
+
|
|
27
|
+
const handler1 = () => {
|
|
28
|
+
callbacks++;
|
|
29
|
+
};
|
|
30
|
+
const handler2 = () => {
|
|
31
|
+
callbacks++;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Add multiple signal handlers in paralell
|
|
35
|
+
const promise = neighbourhoodProxy.addSignalHandler(handler1);
|
|
36
|
+
neighbourhoodProxy.addSignalHandler(handler2);
|
|
37
|
+
await promise;
|
|
38
|
+
|
|
39
|
+
neighbourhoodClient.dispatchSignal(neighbourhoodURI, true);
|
|
40
|
+
|
|
41
|
+
expect(callbacks).toBe(2);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should not add multiple subscriptions when removing and adding another signal handler", async () => {
|
|
45
|
+
const neighbourhoodURI = "did://123";
|
|
46
|
+
|
|
47
|
+
const subscriptions = [];
|
|
48
|
+
const subscribe = (args: { next: (result: any) => void }) => {
|
|
49
|
+
subscriptions.push(args);
|
|
50
|
+
new Promise((resolve) => {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
resolve({});
|
|
53
|
+
}, 10);
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const mockApolloClient = {
|
|
58
|
+
subscribe: () => ({
|
|
59
|
+
subscribe,
|
|
60
|
+
}),
|
|
61
|
+
} as any;
|
|
62
|
+
|
|
63
|
+
const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
|
|
64
|
+
const neighbourhoodProxy = new NeighbourhoodProxy(
|
|
65
|
+
neighbourhoodClient,
|
|
66
|
+
neighbourhoodURI
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
let callbacks1 = 0;
|
|
70
|
+
let callbacks2 = 0;
|
|
71
|
+
|
|
72
|
+
const handler1 = () => {
|
|
73
|
+
callbacks1++;
|
|
74
|
+
};
|
|
75
|
+
const handler2 = () => {
|
|
76
|
+
callbacks2++;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Add signal handler 1
|
|
80
|
+
await neighbourhoodProxy.addSignalHandler(handler1);
|
|
81
|
+
|
|
82
|
+
// Remove signal handler 2
|
|
83
|
+
neighbourhoodProxy.removeSignalHandler(handler1);
|
|
84
|
+
|
|
85
|
+
// Add signal handler 2
|
|
86
|
+
await neighbourhoodProxy.addSignalHandler(handler2);
|
|
87
|
+
|
|
88
|
+
// Check that only one subscription was added
|
|
89
|
+
expect(subscriptions.length).toBe(1);
|
|
90
|
+
|
|
91
|
+
// mock trigger signal event
|
|
92
|
+
for (const subscription of subscriptions) {
|
|
93
|
+
subscription.next({ data: { signal: { neighbourhoodSignal: true } } });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Check that only our second callback was called
|
|
97
|
+
expect(callbacks1).toBe(0);
|
|
98
|
+
expect(callbacks2).toBe(1);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -40,12 +40,12 @@ export class NeighbourhoodProxy {
|
|
|
40
40
|
return await this.#client.sendSignalU(this.#pID, remoteAgentDid, payload)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
async sendBroadcast(payload: Perspective): Promise<boolean> {
|
|
44
|
-
return await this.#client.sendBroadcast(this.#pID, payload)
|
|
43
|
+
async sendBroadcast(payload: Perspective, loopback: boolean = false): Promise<boolean> {
|
|
44
|
+
return await this.#client.sendBroadcast(this.#pID, payload, loopback)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
async sendBroadcastU(payload: PerspectiveUnsignedInput): Promise<boolean> {
|
|
48
|
-
return await this.#client.sendBroadcastU(this.#pID, payload)
|
|
47
|
+
async sendBroadcastU(payload: PerspectiveUnsignedInput, loopback: boolean = false): Promise<boolean> {
|
|
48
|
+
return await this.#client.sendBroadcastU(this.#pID, payload, loopback)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
async addSignalHandler(handler: (payload: PerspectiveExpression) => void): Promise<void> {
|
|
@@ -84,12 +84,12 @@ export default class NeighbourhoodResolver {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
@Mutation()
|
|
87
|
-
neighbourhoodSendBroadcast(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('payload') signal: PerspectiveInput): boolean {
|
|
87
|
+
neighbourhoodSendBroadcast(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('payload') signal: PerspectiveInput, @Arg('loopback', { nullable: true }) loopback?: boolean): boolean {
|
|
88
88
|
return true
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
@Mutation()
|
|
92
|
-
neighbourhoodSendBroadcastU(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('payload') signal: PerspectiveUnsignedInput): boolean {
|
|
92
|
+
neighbourhoodSendBroadcastU(@Arg('perspectiveUUID') perspectiveUUID: string, @Arg('payload') signal: PerspectiveUnsignedInput, @Arg('loopback', { nullable: true }) loopback?: boolean): boolean {
|
|
93
93
|
return true
|
|
94
94
|
}
|
|
95
95
|
|
|
@@ -9,6 +9,8 @@ import { LinkQuery } from "./LinkQuery";
|
|
|
9
9
|
import { Perspective } from "./Perspective";
|
|
10
10
|
import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
|
|
11
11
|
import { LinkStatus, PerspectiveProxy } from './PerspectiveProxy';
|
|
12
|
+
import { AIClient } from "../ai/AIClient";
|
|
13
|
+
import { AllInstancesResult } from "../model/Ad4mModel";
|
|
12
14
|
|
|
13
15
|
const LINK_EXPRESSION_FIELDS = `
|
|
14
16
|
author
|
|
@@ -53,6 +55,7 @@ export class PerspectiveClient {
|
|
|
53
55
|
#perspectiveSyncStateChangeCallbacks: SyncStateChangeCallback[]
|
|
54
56
|
#expressionClient?: ExpressionClient
|
|
55
57
|
#neighbourhoodClient?: NeighbourhoodClient
|
|
58
|
+
#aiClient?: AIClient
|
|
56
59
|
|
|
57
60
|
constructor(client: ApolloClient<any>, subscribe: boolean = true) {
|
|
58
61
|
this.#apolloClient = client
|
|
@@ -76,6 +79,14 @@ export class PerspectiveClient {
|
|
|
76
79
|
this.#neighbourhoodClient = client
|
|
77
80
|
}
|
|
78
81
|
|
|
82
|
+
setAIClient(client: AIClient) {
|
|
83
|
+
this.#aiClient = client
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get aiClient(): AIClient {
|
|
87
|
+
return this.#aiClient
|
|
88
|
+
}
|
|
89
|
+
|
|
79
90
|
async all(): Promise<PerspectiveProxy[]> {
|
|
80
91
|
const { perspectives } = unwrapApolloResult(await this.#apolloClient.query({
|
|
81
92
|
query: gql`query perspectives {
|
|
@@ -144,6 +155,89 @@ export class PerspectiveClient {
|
|
|
144
155
|
return JSON.parse(perspectiveQueryProlog)
|
|
145
156
|
}
|
|
146
157
|
|
|
158
|
+
async subscribeQuery(uuid: string, query: string): Promise<{ subscriptionId: string, result: AllInstancesResult, isInit?: boolean }> {
|
|
159
|
+
const { perspectiveSubscribeQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
160
|
+
mutation: gql`mutation perspectiveSubscribeQuery($uuid: String!, $query: String!) {
|
|
161
|
+
perspectiveSubscribeQuery(uuid: $uuid, query: $query) {
|
|
162
|
+
subscriptionId
|
|
163
|
+
result
|
|
164
|
+
}
|
|
165
|
+
}`,
|
|
166
|
+
variables: { uuid, query }
|
|
167
|
+
}))
|
|
168
|
+
const { subscriptionId, result } = perspectiveSubscribeQuery
|
|
169
|
+
let finalResult = result;
|
|
170
|
+
let isInit = false;
|
|
171
|
+
if(finalResult.startsWith("#init#")) {
|
|
172
|
+
finalResult = finalResult.substring(6)
|
|
173
|
+
isInit = true;
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
finalResult = JSON.parse(finalResult)
|
|
177
|
+
} catch (e) {
|
|
178
|
+
console.error('Error parsing perspectiveSubscribeQuery result:', e)
|
|
179
|
+
}
|
|
180
|
+
return { subscriptionId, result: finalResult, isInit }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
subscribeToQueryUpdates(subscriptionId: string, onData: (result: AllInstancesResult) => void): () => void {
|
|
184
|
+
const subscription = this.#apolloClient.subscribe({
|
|
185
|
+
query: gql`
|
|
186
|
+
subscription perspectiveQuerySubscription($subscriptionId: String!) {
|
|
187
|
+
perspectiveQuerySubscription(subscriptionId: $subscriptionId)
|
|
188
|
+
}
|
|
189
|
+
`,
|
|
190
|
+
variables: {
|
|
191
|
+
subscriptionId
|
|
192
|
+
}
|
|
193
|
+
}).subscribe({
|
|
194
|
+
next: (result) => {
|
|
195
|
+
if (result.data && result.data.perspectiveQuerySubscription) {
|
|
196
|
+
let finalResult = result.data.perspectiveQuerySubscription;
|
|
197
|
+
let isInit = false;
|
|
198
|
+
if(finalResult.startsWith("#init#")) {
|
|
199
|
+
finalResult = finalResult.substring(6)
|
|
200
|
+
isInit = true;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
finalResult = JSON.parse(finalResult)
|
|
204
|
+
if(isInit && typeof finalResult === 'object') {
|
|
205
|
+
finalResult.isInit = true;
|
|
206
|
+
}
|
|
207
|
+
} catch (e) {
|
|
208
|
+
console.error('Error parsing perspectiveQuerySubscription:', e)
|
|
209
|
+
}
|
|
210
|
+
onData(finalResult);
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
error: (e) => console.error('Error in query subscription:', e)
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return () => subscription.unsubscribe();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async keepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
220
|
+
const { perspectiveKeepAliveQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
221
|
+
mutation: gql`mutation perspectiveKeepAliveQuery($uuid: String!, $subscriptionId: String!) {
|
|
222
|
+
perspectiveKeepAliveQuery(uuid: $uuid, subscriptionId: $subscriptionId)
|
|
223
|
+
}`,
|
|
224
|
+
variables: { uuid, subscriptionId }
|
|
225
|
+
}))
|
|
226
|
+
|
|
227
|
+
return perspectiveKeepAliveQuery
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async disposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
231
|
+
const { perspectiveDisposeQuerySubscription } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
232
|
+
mutation: gql`mutation perspectiveDisposeQuerySubscription($uuid: String!, $subscriptionId: String!) {
|
|
233
|
+
perspectiveDisposeQuerySubscription(uuid: $uuid, subscriptionId: $subscriptionId)
|
|
234
|
+
}`,
|
|
235
|
+
variables: { uuid, subscriptionId }
|
|
236
|
+
}))
|
|
237
|
+
|
|
238
|
+
return perspectiveDisposeQuerySubscription
|
|
239
|
+
}
|
|
240
|
+
|
|
147
241
|
async add(name: string): Promise<PerspectiveProxy> {
|
|
148
242
|
const { perspectiveAdd } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
149
243
|
mutation: gql`mutation perspectiveAdd($name: String!) {
|
|
@@ -177,38 +271,38 @@ export class PerspectiveClient {
|
|
|
177
271
|
}))
|
|
178
272
|
}
|
|
179
273
|
|
|
180
|
-
async addLink(uuid: string, link: Link, status?:
|
|
274
|
+
async addLink(uuid: string, link: Link, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
|
|
181
275
|
const { perspectiveAddLink } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
182
|
-
mutation: gql`mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String){
|
|
183
|
-
perspectiveAddLink(link: $link,
|
|
276
|
+
mutation: gql`mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String!, $batchId: String) {
|
|
277
|
+
perspectiveAddLink(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
|
|
184
278
|
${LINK_EXPRESSION_FIELDS}
|
|
185
279
|
}
|
|
186
280
|
}`,
|
|
187
|
-
variables: { uuid, link, status }
|
|
281
|
+
variables: { uuid, link, status, batchId }
|
|
188
282
|
}))
|
|
189
283
|
return perspectiveAddLink
|
|
190
284
|
}
|
|
191
285
|
|
|
192
|
-
async addLinks(uuid: string, links: Link[], status?:
|
|
286
|
+
async addLinks(uuid: string, links: Link[], status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression[]> {
|
|
193
287
|
const { perspectiveAddLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
194
|
-
mutation: gql`mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String){
|
|
195
|
-
perspectiveAddLinks(links: $links,
|
|
288
|
+
mutation: gql`mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String!, $batchId: String) {
|
|
289
|
+
perspectiveAddLinks(uuid: $uuid, links: $links, status: $status, batchId: $batchId) {
|
|
196
290
|
${LINK_EXPRESSION_FIELDS}
|
|
197
291
|
}
|
|
198
292
|
}`,
|
|
199
|
-
variables: { uuid, links, status }
|
|
293
|
+
variables: { uuid, links, status, batchId }
|
|
200
294
|
}))
|
|
201
295
|
return perspectiveAddLinks
|
|
202
296
|
}
|
|
203
297
|
|
|
204
|
-
async removeLinks(uuid: string, links: LinkExpressionInput[]): Promise<LinkExpression[]> {
|
|
298
|
+
async removeLinks(uuid: string, links: LinkExpressionInput[], batchId?: string): Promise<LinkExpression[]> {
|
|
205
299
|
const { perspectiveRemoveLinks } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
206
|
-
mutation: gql`mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]
|
|
207
|
-
perspectiveRemoveLinks(links: $links,
|
|
300
|
+
mutation: gql`mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]!, $batchId: String) {
|
|
301
|
+
perspectiveRemoveLinks(uuid: $uuid, links: $links, batchId: $batchId) {
|
|
208
302
|
${LINK_EXPRESSION_FIELDS}
|
|
209
303
|
}
|
|
210
304
|
}`,
|
|
211
|
-
variables: { uuid, links }
|
|
305
|
+
variables: { uuid, links, batchId }
|
|
212
306
|
}))
|
|
213
307
|
return perspectiveRemoveLinks
|
|
214
308
|
}
|
|
@@ -230,83 +324,67 @@ export class PerspectiveClient {
|
|
|
230
324
|
return perspectiveLinkMutations
|
|
231
325
|
}
|
|
232
326
|
|
|
233
|
-
async addLinkExpression(uuid: string, link:
|
|
327
|
+
async addLinkExpression(uuid: string, link: LinkExpression, status: LinkStatus = 'shared', batchId?: string): Promise<LinkExpression> {
|
|
234
328
|
const { perspectiveAddLinkExpression } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
235
|
-
mutation: gql`mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String){
|
|
236
|
-
perspectiveAddLinkExpression(link: $link,
|
|
329
|
+
mutation: gql`mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String!, $batchId: String) {
|
|
330
|
+
perspectiveAddLinkExpression(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
|
|
237
331
|
${LINK_EXPRESSION_FIELDS}
|
|
238
332
|
}
|
|
239
333
|
}`,
|
|
240
|
-
variables: { uuid, link }
|
|
334
|
+
variables: { uuid, link, status, batchId }
|
|
241
335
|
}))
|
|
242
336
|
return perspectiveAddLinkExpression
|
|
243
337
|
}
|
|
244
338
|
|
|
245
|
-
async updateLink(uuid: string, oldLink: LinkExpressionInput, newLink:
|
|
246
|
-
delete oldLink.__typename
|
|
247
|
-
delete oldLink.data.__typename
|
|
248
|
-
delete oldLink.proof.__typename
|
|
339
|
+
async updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: Link, batchId?: string): Promise<LinkExpression> {
|
|
249
340
|
const { perspectiveUpdateLink } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
250
|
-
mutation: gql`mutation perspectiveUpdateLink(
|
|
251
|
-
$uuid:
|
|
252
|
-
$newLink: LinkInput!
|
|
253
|
-
$oldLink: LinkExpressionInput!
|
|
254
|
-
){
|
|
255
|
-
perspectiveUpdateLink(
|
|
256
|
-
newLink: $newLink,
|
|
257
|
-
oldLink: $oldLink,
|
|
258
|
-
uuid: $uuid
|
|
259
|
-
) {
|
|
341
|
+
mutation: gql`mutation perspectiveUpdateLink($uuid: String!, $oldLink: LinkExpressionInput!, $newLink: LinkInput!, $batchId: String) {
|
|
342
|
+
perspectiveUpdateLink(uuid: $uuid, oldLink: $oldLink, newLink: $newLink, batchId: $batchId) {
|
|
260
343
|
${LINK_EXPRESSION_FIELDS}
|
|
261
344
|
}
|
|
262
345
|
}`,
|
|
263
|
-
variables: { uuid, oldLink, newLink }
|
|
346
|
+
variables: { uuid, oldLink, newLink, batchId }
|
|
264
347
|
}))
|
|
265
|
-
|
|
266
|
-
if (!perspectiveUpdateLink.status) {
|
|
267
|
-
delete perspectiveUpdateLink.status
|
|
268
|
-
}
|
|
269
|
-
|
|
270
348
|
return perspectiveUpdateLink
|
|
271
349
|
}
|
|
272
350
|
|
|
273
|
-
async removeLink(uuid: string, link: LinkExpressionInput): Promise<
|
|
351
|
+
async removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean> {
|
|
274
352
|
delete link.__typename
|
|
275
353
|
delete link.data.__typename
|
|
276
354
|
delete link.proof.__typename
|
|
277
355
|
delete link.status
|
|
278
|
-
|
|
279
|
-
mutation: gql`mutation perspectiveRemoveLink($link: LinkExpressionInput!, $uuid: String
|
|
280
|
-
perspectiveRemoveLink(link: $link, uuid: $uuid)
|
|
356
|
+
const { perspectiveRemoveLink } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
357
|
+
mutation: gql`mutation perspectiveRemoveLink($link: LinkExpressionInput!, $uuid: String!, $batchId: String) {
|
|
358
|
+
perspectiveRemoveLink(link: $link, uuid: $uuid, batchId: $batchId)
|
|
281
359
|
}`,
|
|
282
|
-
variables: { uuid, link }
|
|
360
|
+
variables: { uuid, link, batchId }
|
|
283
361
|
}))
|
|
362
|
+
return perspectiveRemoveLink
|
|
284
363
|
}
|
|
285
364
|
|
|
286
365
|
async addSdna(uuid: string, name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom"): Promise<boolean> {
|
|
287
366
|
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
288
367
|
mutation: gql`mutation perspectiveAddSdna($uuid: String!, $name: String!, $sdnaCode: String!, $sdnaType: String!) {
|
|
289
368
|
perspectiveAddSdna(uuid: $uuid, name: $name, sdnaCode: $sdnaCode, sdnaType: $sdnaType)
|
|
290
|
-
}`,
|
|
291
|
-
variables: { uuid, name, sdnaCode, sdnaType }
|
|
369
|
+
}`, variables: { uuid, name, sdnaCode, sdnaType }
|
|
292
370
|
})).perspectiveAddSdna
|
|
293
371
|
}
|
|
294
372
|
|
|
295
|
-
async executeCommands(uuid: string, commands: string, expression: string, parameters: string): Promise<boolean> {
|
|
373
|
+
async executeCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Promise<boolean> {
|
|
296
374
|
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
297
|
-
mutation: gql`mutation perspectiveExecuteCommands($uuid: String!, $commands: String!, $expression: String!, $parameters: String) {
|
|
298
|
-
perspectiveExecuteCommands(uuid: $uuid, commands: $commands, expression: $expression, parameters: $parameters)
|
|
375
|
+
mutation: gql`mutation perspectiveExecuteCommands($uuid: String!, $commands: String!, $expression: String!, $parameters: String, $batchId: String) {
|
|
376
|
+
perspectiveExecuteCommands(uuid: $uuid, commands: $commands, expression: $expression, parameters: $parameters, batchId: $batchId)
|
|
299
377
|
}`,
|
|
300
|
-
variables: { uuid, commands, expression, parameters }
|
|
378
|
+
variables: { uuid, commands, expression, parameters, batchId }
|
|
301
379
|
})).perspectiveExecuteCommands
|
|
302
380
|
}
|
|
303
381
|
|
|
304
|
-
async createSubject(uuid: string, subjectClass: string, expressionAddress: string): Promise<boolean> {
|
|
382
|
+
async createSubject(uuid: string, subjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Promise<boolean> {
|
|
305
383
|
return unwrapApolloResult(await this.#apolloClient.mutate({
|
|
306
|
-
mutation: gql`mutation perspectiveCreateSubject($uuid: String!, $subjectClass: String!, $expressionAddress: String
|
|
307
|
-
perspectiveCreateSubject(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress)
|
|
384
|
+
mutation: gql`mutation perspectiveCreateSubject($uuid: String!, $subjectClass: String!, $expressionAddress: String!, $initialValues: String, $batchId: String) {
|
|
385
|
+
perspectiveCreateSubject(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress, initialValues: $initialValues, batchId: $batchId)
|
|
308
386
|
}`,
|
|
309
|
-
variables: { uuid, subjectClass, expressionAddress }
|
|
387
|
+
variables: { uuid, subjectClass, expressionAddress, initialValues, batchId }
|
|
310
388
|
})).perspectiveCreateSubject
|
|
311
389
|
}
|
|
312
390
|
|
|
@@ -477,4 +555,31 @@ export class PerspectiveClient {
|
|
|
477
555
|
getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy {
|
|
478
556
|
return new NeighbourhoodProxy(this.#neighbourhoodClient, uuid)
|
|
479
557
|
}
|
|
558
|
+
|
|
559
|
+
async createBatch(uuid: string): Promise<string> {
|
|
560
|
+
const { perspectiveCreateBatch } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
561
|
+
mutation: gql`mutation perspectiveCreateBatch($uuid: String!) {
|
|
562
|
+
perspectiveCreateBatch(uuid: $uuid)
|
|
563
|
+
}`,
|
|
564
|
+
variables: { uuid }
|
|
565
|
+
}))
|
|
566
|
+
return perspectiveCreateBatch
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
async commitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations> {
|
|
570
|
+
const { perspectiveCommitBatch } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
571
|
+
mutation: gql`mutation perspectiveCommitBatch($uuid: String!, $batchId: String!) {
|
|
572
|
+
perspectiveCommitBatch(uuid: $uuid, batchId: $batchId) {
|
|
573
|
+
additions {
|
|
574
|
+
${LINK_EXPRESSION_FIELDS}
|
|
575
|
+
}
|
|
576
|
+
removals {
|
|
577
|
+
${LINK_EXPRESSION_FIELDS}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
}`,
|
|
581
|
+
variables: { uuid, batchId }
|
|
582
|
+
}))
|
|
583
|
+
return perspectiveCommitBatch
|
|
584
|
+
}
|
|
480
585
|
}
|