@coasys/ad4m 0.10.0 → 0.10.1-multi-user-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 (72) hide show
  1. package/lib/index.cjs +3730 -906
  2. package/lib/index.js +3722 -902
  3. package/lib/src/Ad4mClient.js +2 -1
  4. package/lib/src/Literal.js +4 -1
  5. package/lib/src/agent/Agent.d.ts +12 -0
  6. package/lib/src/agent/Agent.js +48 -0
  7. package/lib/src/agent/AgentClient.d.ts +3 -1
  8. package/lib/src/agent/AgentClient.js +23 -0
  9. package/lib/src/ai/AIClient.d.ts +8 -2
  10. package/lib/src/ai/AIClient.js +25 -14
  11. package/lib/src/ai/AIResolver.d.ts +25 -6
  12. package/lib/src/ai/AIResolver.js +102 -18
  13. package/lib/src/index.d.ts +4 -3
  14. package/lib/src/index.js +4 -3
  15. package/lib/src/language/Language.d.ts +12 -1
  16. package/lib/src/model/Ad4mModel.d.ts +622 -0
  17. package/lib/src/model/Ad4mModel.js +1118 -0
  18. package/lib/src/{subject → model}/Subject.d.ts +2 -2
  19. package/lib/src/{subject → model}/Subject.js +18 -18
  20. package/lib/src/model/decorators.d.ts +502 -0
  21. package/lib/src/model/decorators.js +683 -0
  22. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +2 -2
  23. package/lib/src/neighbourhood/NeighbourhoodClient.js +13 -10
  24. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -2
  25. package/lib/src/neighbourhood/NeighbourhoodProxy.js +4 -4
  26. package/lib/src/neighbourhood/NeighbourhoodProxy.test.d.ts +1 -0
  27. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +73 -0
  28. package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +2 -2
  29. package/lib/src/neighbourhood/NeighbourhoodResolver.js +6 -4
  30. package/lib/src/perspectives/PerspectiveClient.d.ts +23 -11
  31. package/lib/src/perspectives/PerspectiveClient.js +147 -51
  32. package/lib/src/perspectives/PerspectiveProxy.d.ts +494 -54
  33. package/lib/src/perspectives/PerspectiveProxy.js +684 -67
  34. package/lib/src/perspectives/PerspectiveResolver.d.ts +24 -9
  35. package/lib/src/perspectives/PerspectiveResolver.js +151 -46
  36. package/lib/src/runtime/RuntimeClient.d.ts +11 -2
  37. package/lib/src/runtime/RuntimeClient.js +94 -0
  38. package/lib/src/runtime/RuntimeResolver.d.ts +36 -1
  39. package/lib/src/runtime/RuntimeResolver.js +193 -0
  40. package/lib/src/schema.gql +65 -16
  41. package/lib/src/typeDefs.js +65 -16
  42. package/package.json +4 -3
  43. package/src/Ad4mClient.test.ts +51 -19
  44. package/src/Ad4mClient.ts +3 -1
  45. package/src/Literal.ts +4 -1
  46. package/src/agent/Agent.ts +36 -0
  47. package/src/agent/AgentClient.ts +30 -0
  48. package/src/ai/AIClient.ts +35 -14
  49. package/src/ai/AIResolver.ts +78 -16
  50. package/src/index.ts +4 -3
  51. package/src/language/Language.ts +16 -4
  52. package/src/model/Ad4mModel.ts +1279 -0
  53. package/src/{subject → model}/Subject.ts +16 -16
  54. package/src/{subject/SDNADecorators.ts → model/decorators.ts} +384 -50
  55. package/src/neighbourhood/NeighbourhoodClient.ts +13 -10
  56. package/src/neighbourhood/NeighbourhoodProxy.test.ts +100 -0
  57. package/src/neighbourhood/NeighbourhoodProxy.ts +4 -4
  58. package/src/neighbourhood/NeighbourhoodResolver.ts +2 -2
  59. package/src/perspectives/PerspectiveClient.ts +156 -51
  60. package/src/perspectives/PerspectiveProxy.ts +766 -82
  61. package/src/perspectives/PerspectiveResolver.ts +134 -23
  62. package/src/runtime/RuntimeClient.ts +104 -2
  63. package/src/runtime/RuntimeResolver.ts +126 -1
  64. package/lib/src/subject/SDNADecorators.d.ts +0 -188
  65. package/lib/src/subject/SDNADecorators.js +0 -360
  66. package/lib/src/subject/SubjectEntity.d.ts +0 -102
  67. package/lib/src/subject/SubjectEntity.js +0 -267
  68. package/src/subject/SubjectEntity.ts +0 -315
  69. package/yarn-error.log +0 -90
  70. /package/lib/src/{subject → model}/util.d.ts +0 -0
  71. /package/lib/src/{subject → model}/util.js +0 -0
  72. /package/src/{subject → model}/util.ts +0 -0
@@ -170,33 +170,37 @@ export class NeighbourhoodClient {
170
170
  }));
171
171
  return neighbourhoodSendSignalU;
172
172
  }
173
- async sendBroadcast(perspectiveUUID, payload) {
173
+ async sendBroadcast(perspectiveUUID, payload, loopback = false) {
174
174
  const { neighbourhoodSendBroadcast } = unwrapApolloResult(await __classPrivateFieldGet(this, _NeighbourhoodClient_apolloClient, "f").mutate({
175
175
  mutation: gql `mutation neighbourhoodSendBroadcast(
176
176
  $perspectiveUUID: String!,
177
- $payload: PerspectiveInput!
177
+ $payload: PerspectiveInput!,
178
+ $loopback: Boolean
178
179
  ) {
179
180
  neighbourhoodSendBroadcast(
180
181
  perspectiveUUID: $perspectiveUUID,
181
- payload: $payload
182
+ payload: $payload,
183
+ loopback: $loopback
182
184
  )
183
185
  }`,
184
- variables: { perspectiveUUID, payload }
186
+ variables: { perspectiveUUID, payload, loopback }
185
187
  }));
186
188
  return neighbourhoodSendBroadcast;
187
189
  }
188
- async sendBroadcastU(perspectiveUUID, payload) {
190
+ async sendBroadcastU(perspectiveUUID, payload, loopback = false) {
189
191
  const { neighbourhoodSendBroadcastU } = unwrapApolloResult(await __classPrivateFieldGet(this, _NeighbourhoodClient_apolloClient, "f").mutate({
190
192
  mutation: gql `mutation neighbourhoodSendBroadcastU(
191
193
  $perspectiveUUID: String!,
192
- $payload: PerspectiveUnsignedInput!
194
+ $payload: PerspectiveUnsignedInput!,
195
+ $loopback: Boolean
193
196
  ) {
194
197
  neighbourhoodSendBroadcastU(
195
198
  perspectiveUUID: $perspectiveUUID,
196
- payload: $payload
199
+ payload: $payload,
200
+ loopback: $loopback
197
201
  )
198
202
  }`,
199
- variables: { perspectiveUUID, payload }
203
+ variables: { perspectiveUUID, payload, loopback }
200
204
  }));
201
205
  return neighbourhoodSendBroadcastU;
202
206
  }
@@ -237,10 +241,10 @@ export class NeighbourhoodClient {
237
241
  let handlersForPerspective = __classPrivateFieldGet(this, _NeighbourhoodClient_signalHandlers, "f").get(perspectiveUUID);
238
242
  if (!handlersForPerspective) {
239
243
  handlersForPerspective = [];
244
+ __classPrivateFieldGet(this, _NeighbourhoodClient_signalHandlers, "f").set(perspectiveUUID, handlersForPerspective);
240
245
  await this.subscribeToSignals(perspectiveUUID);
241
246
  }
242
247
  handlersForPerspective.push(handler);
243
- __classPrivateFieldGet(this, _NeighbourhoodClient_signalHandlers, "f").set(perspectiveUUID, handlersForPerspective);
244
248
  }
245
249
  removeSignalHandler(perspectiveUUID, handler) {
246
250
  const handlersForPerspective = __classPrivateFieldGet(this, _NeighbourhoodClient_signalHandlers, "f").get(perspectiveUUID);
@@ -250,7 +254,6 @@ export class NeighbourhoodClient {
250
254
  handlersForPerspective.splice(index, 1);
251
255
  }
252
256
  }
253
- __classPrivateFieldGet(this, _NeighbourhoodClient_signalHandlers, "f").set(perspectiveUUID, handlersForPerspective);
254
257
  }
255
258
  }
256
259
  _NeighbourhoodClient_apolloClient = new WeakMap(), _NeighbourhoodClient_signalHandlers = new WeakMap();
@@ -12,8 +12,8 @@ export declare class NeighbourhoodProxy {
12
12
  setOnlineStatusU(status: PerspectiveUnsignedInput): Promise<boolean>;
13
13
  sendSignal(remoteAgentDid: string, payload: Perspective): Promise<boolean>;
14
14
  sendSignalU(remoteAgentDid: string, payload: PerspectiveUnsignedInput): Promise<boolean>;
15
- sendBroadcast(payload: Perspective): Promise<boolean>;
16
- sendBroadcastU(payload: PerspectiveUnsignedInput): Promise<boolean>;
15
+ sendBroadcast(payload: Perspective, loopback?: boolean): Promise<boolean>;
16
+ sendBroadcastU(payload: PerspectiveUnsignedInput, loopback?: boolean): Promise<boolean>;
17
17
  addSignalHandler(handler: (payload: PerspectiveExpression) => void): Promise<void>;
18
18
  removeSignalHandler(handler: (payload: PerspectiveExpression) => void): void;
19
19
  }
@@ -38,11 +38,11 @@ export class NeighbourhoodProxy {
38
38
  async sendSignalU(remoteAgentDid, payload) {
39
39
  return await __classPrivateFieldGet(this, _NeighbourhoodProxy_client, "f").sendSignalU(__classPrivateFieldGet(this, _NeighbourhoodProxy_pID, "f"), remoteAgentDid, payload);
40
40
  }
41
- async sendBroadcast(payload) {
42
- return await __classPrivateFieldGet(this, _NeighbourhoodProxy_client, "f").sendBroadcast(__classPrivateFieldGet(this, _NeighbourhoodProxy_pID, "f"), payload);
41
+ async sendBroadcast(payload, loopback = false) {
42
+ return await __classPrivateFieldGet(this, _NeighbourhoodProxy_client, "f").sendBroadcast(__classPrivateFieldGet(this, _NeighbourhoodProxy_pID, "f"), payload, loopback);
43
43
  }
44
- async sendBroadcastU(payload) {
45
- return await __classPrivateFieldGet(this, _NeighbourhoodProxy_client, "f").sendBroadcastU(__classPrivateFieldGet(this, _NeighbourhoodProxy_pID, "f"), payload);
44
+ async sendBroadcastU(payload, loopback = false) {
45
+ return await __classPrivateFieldGet(this, _NeighbourhoodProxy_client, "f").sendBroadcastU(__classPrivateFieldGet(this, _NeighbourhoodProxy_pID, "f"), payload, loopback);
46
46
  }
47
47
  async addSignalHandler(handler) {
48
48
  await __classPrivateFieldGet(this, _NeighbourhoodProxy_client, "f").addSignalHandler(__classPrivateFieldGet(this, _NeighbourhoodProxy_pID, "f"), handler);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,73 @@
1
+ import { NeighbourhoodClient } from "./NeighbourhoodClient";
2
+ import { NeighbourhoodProxy } from "./NeighbourhoodProxy";
3
+ describe("NeighbourhoodProxy", () => {
4
+ it("should add multiple signal handlers", async () => {
5
+ const neighbourhoodURI = "did://123";
6
+ const mockApolloClient = {
7
+ subscribe: () => ({
8
+ subscribe: () => new Promise((resolve) => {
9
+ setTimeout(() => {
10
+ resolve({});
11
+ }, 10);
12
+ }),
13
+ }),
14
+ };
15
+ const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
16
+ const neighbourhoodProxy = new NeighbourhoodProxy(neighbourhoodClient, neighbourhoodURI);
17
+ let callbacks = 0;
18
+ const handler1 = () => {
19
+ callbacks++;
20
+ };
21
+ const handler2 = () => {
22
+ callbacks++;
23
+ };
24
+ // Add multiple signal handlers in paralell
25
+ const promise = neighbourhoodProxy.addSignalHandler(handler1);
26
+ neighbourhoodProxy.addSignalHandler(handler2);
27
+ await promise;
28
+ neighbourhoodClient.dispatchSignal(neighbourhoodURI, true);
29
+ expect(callbacks).toBe(2);
30
+ });
31
+ it("should not add multiple subscriptions when removing and adding another signal handler", async () => {
32
+ const neighbourhoodURI = "did://123";
33
+ const subscriptions = [];
34
+ const subscribe = (args) => {
35
+ subscriptions.push(args);
36
+ new Promise((resolve) => {
37
+ setTimeout(() => {
38
+ resolve({});
39
+ }, 10);
40
+ });
41
+ };
42
+ const mockApolloClient = {
43
+ subscribe: () => ({
44
+ subscribe,
45
+ }),
46
+ };
47
+ const neighbourhoodClient = new NeighbourhoodClient(mockApolloClient);
48
+ const neighbourhoodProxy = new NeighbourhoodProxy(neighbourhoodClient, neighbourhoodURI);
49
+ let callbacks1 = 0;
50
+ let callbacks2 = 0;
51
+ const handler1 = () => {
52
+ callbacks1++;
53
+ };
54
+ const handler2 = () => {
55
+ callbacks2++;
56
+ };
57
+ // Add signal handler 1
58
+ await neighbourhoodProxy.addSignalHandler(handler1);
59
+ // Remove signal handler 2
60
+ neighbourhoodProxy.removeSignalHandler(handler1);
61
+ // Add signal handler 2
62
+ await neighbourhoodProxy.addSignalHandler(handler2);
63
+ // Check that only one subscription was added
64
+ expect(subscriptions.length).toBe(1);
65
+ // mock trigger signal event
66
+ for (const subscription of subscriptions) {
67
+ subscription.next({ data: { signal: { neighbourhoodSignal: true } } });
68
+ }
69
+ // Check that only our second callback was called
70
+ expect(callbacks1).toBe(0);
71
+ expect(callbacks2).toBe(1);
72
+ });
73
+ });
@@ -18,7 +18,7 @@ export default class NeighbourhoodResolver {
18
18
  neighbourhoodSetOnlineStatusU(perspectiveUUID: string, status: PerspectiveUnsignedInput): boolean;
19
19
  neighbourhoodSendSignal(perspectiveUUID: string, recipient: DID, signal: PerspectiveInput): boolean;
20
20
  neighbourhoodSendSignalU(perspectiveUUID: string, recipient: DID, signal: PerspectiveUnsignedInput): boolean;
21
- neighbourhoodSendBroadcast(perspectiveUUID: string, signal: PerspectiveInput): boolean;
22
- neighbourhoodSendBroadcastU(perspectiveUUID: string, signal: PerspectiveUnsignedInput): boolean;
21
+ neighbourhoodSendBroadcast(perspectiveUUID: string, signal: PerspectiveInput, loopback?: boolean): boolean;
22
+ neighbourhoodSendBroadcastU(perspectiveUUID: string, signal: PerspectiveUnsignedInput, loopback?: boolean): boolean;
23
23
  neighbourhoodSignal(pID: string): PerspectiveExpression;
24
24
  }
@@ -69,10 +69,10 @@ let NeighbourhoodResolver = class NeighbourhoodResolver {
69
69
  neighbourhoodSendSignalU(perspectiveUUID, recipient, signal) {
70
70
  return true;
71
71
  }
72
- neighbourhoodSendBroadcast(perspectiveUUID, signal) {
72
+ neighbourhoodSendBroadcast(perspectiveUUID, signal, loopback) {
73
73
  return true;
74
74
  }
75
- neighbourhoodSendBroadcastU(perspectiveUUID, signal) {
75
+ neighbourhoodSendBroadcastU(perspectiveUUID, signal, loopback) {
76
76
  return true;
77
77
  }
78
78
  neighbourhoodSignal(pID) {
@@ -155,16 +155,18 @@ __decorate([
155
155
  Mutation(),
156
156
  __param(0, Arg('perspectiveUUID')),
157
157
  __param(1, Arg('payload')),
158
+ __param(2, Arg('loopback', { nullable: true })),
158
159
  __metadata("design:type", Function),
159
- __metadata("design:paramtypes", [String, PerspectiveInput]),
160
+ __metadata("design:paramtypes", [String, PerspectiveInput, Boolean]),
160
161
  __metadata("design:returntype", Boolean)
161
162
  ], NeighbourhoodResolver.prototype, "neighbourhoodSendBroadcast", null);
162
163
  __decorate([
163
164
  Mutation(),
164
165
  __param(0, Arg('perspectiveUUID')),
165
166
  __param(1, Arg('payload')),
167
+ __param(2, Arg('loopback', { nullable: true })),
166
168
  __metadata("design:type", Function),
167
- __metadata("design:paramtypes", [String, PerspectiveUnsignedInput]),
169
+ __metadata("design:paramtypes", [String, PerspectiveUnsignedInput, Boolean]),
168
170
  __metadata("design:returntype", Boolean)
169
171
  ], NeighbourhoodResolver.prototype, "neighbourhoodSendBroadcastU", null);
170
172
  __decorate([
@@ -1,13 +1,15 @@
1
1
  import { ApolloClient } from "@apollo/client/core";
2
2
  import { ExpressionRendered } from "../expression/Expression";
3
3
  import { ExpressionClient } from "../expression/ExpressionClient";
4
- import { Link, LinkExpressionInput, LinkExpression, LinkInput, LinkMutations, LinkExpressionMutations } from "../links/Links";
4
+ import { Link, LinkExpressionInput, LinkExpression, LinkMutations, LinkExpressionMutations } from "../links/Links";
5
5
  import { NeighbourhoodClient } from "../neighbourhood/NeighbourhoodClient";
6
6
  import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
7
7
  import { LinkQuery } from "./LinkQuery";
8
8
  import { Perspective } from "./Perspective";
9
9
  import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
10
10
  import { LinkStatus, PerspectiveProxy } from './PerspectiveProxy';
11
+ import { AIClient } from "../ai/AIClient";
12
+ import { AllInstancesResult } from "../model/Ad4mModel";
11
13
  export type PerspectiveHandleCallback = (perspective: PerspectiveHandle) => null;
12
14
  export type UuidCallback = (uuid: string) => null;
13
15
  export type LinkCallback = (link: LinkExpression) => null;
@@ -17,29 +19,37 @@ export declare class PerspectiveClient {
17
19
  constructor(client: ApolloClient<any>, subscribe?: boolean);
18
20
  setExpressionClient(client: ExpressionClient): void;
19
21
  setNeighbourhoodClient(client: NeighbourhoodClient): void;
22
+ setAIClient(client: AIClient): void;
23
+ get aiClient(): AIClient;
20
24
  all(): Promise<PerspectiveProxy[]>;
21
25
  byUUID(uuid: string): Promise<PerspectiveProxy | null>;
22
26
  snapshotByUUID(uuid: string): Promise<Perspective | null>;
23
27
  publishSnapshotByUUID(uuid: string): Promise<string | null>;
24
28
  queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]>;
25
29
  queryProlog(uuid: string, query: string): Promise<any>;
30
+ subscribeQuery(uuid: string, query: string): Promise<{
31
+ subscriptionId: string;
32
+ result: AllInstancesResult;
33
+ isInit?: boolean;
34
+ }>;
35
+ subscribeToQueryUpdates(subscriptionId: string, onData: (result: AllInstancesResult) => void): () => void;
36
+ keepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean>;
37
+ disposeQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean>;
26
38
  add(name: string): Promise<PerspectiveProxy>;
27
39
  update(uuid: string, name: string): Promise<PerspectiveProxy>;
28
40
  remove(uuid: string): Promise<{
29
41
  perspectiveRemove: boolean;
30
42
  }>;
31
- addLink(uuid: string, link: Link, status?: LinkStatus): Promise<LinkExpression>;
32
- addLinks(uuid: string, links: Link[], status?: LinkStatus): Promise<LinkExpression[]>;
33
- removeLinks(uuid: string, links: LinkExpressionInput[]): Promise<LinkExpression[]>;
43
+ addLink(uuid: string, link: Link, status?: LinkStatus, batchId?: string): Promise<LinkExpression>;
44
+ addLinks(uuid: string, links: Link[], status?: LinkStatus, batchId?: string): Promise<LinkExpression[]>;
45
+ removeLinks(uuid: string, links: LinkExpressionInput[], batchId?: string): Promise<LinkExpression[]>;
34
46
  linkMutations(uuid: string, mutations: LinkMutations, status?: LinkStatus): Promise<LinkExpressionMutations>;
35
- addLinkExpression(uuid: string, link: LinkExpressionInput, status?: LinkStatus): Promise<LinkExpression>;
36
- updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: LinkInput): Promise<LinkExpression>;
37
- removeLink(uuid: string, link: LinkExpressionInput): Promise<{
38
- perspectiveRemoveLink: boolean;
39
- }>;
47
+ addLinkExpression(uuid: string, link: LinkExpression, status?: LinkStatus, batchId?: string): Promise<LinkExpression>;
48
+ updateLink(uuid: string, oldLink: LinkExpressionInput, newLink: Link, batchId?: string): Promise<LinkExpression>;
49
+ removeLink(uuid: string, link: LinkExpressionInput, batchId?: string): Promise<boolean>;
40
50
  addSdna(uuid: string, name: string, sdnaCode: string, sdnaType: "subject_class" | "flow" | "custom"): Promise<boolean>;
41
- executeCommands(uuid: string, commands: string, expression: string, parameters: string): Promise<boolean>;
42
- createSubject(uuid: string, subjectClass: string, expressionAddress: string): Promise<boolean>;
51
+ executeCommands(uuid: string, commands: string, expression: string, parameters: string, batchId?: string): Promise<boolean>;
52
+ createSubject(uuid: string, subjectClass: string, expressionAddress: string, initialValues?: string, batchId?: string): Promise<boolean>;
43
53
  getSubjectData(uuid: string, subjectClass: string, expressionAddress: string): Promise<string>;
44
54
  getExpression(expressionURI: string): Promise<ExpressionRendered>;
45
55
  createExpression(content: any, languageAddress: string): Promise<string>;
@@ -55,4 +65,6 @@ export declare class PerspectiveClient {
55
65
  addPerspectiveLinkRemovedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
56
66
  addPerspectiveLinkUpdatedListener(uuid: String, cb: LinkCallback[]): Promise<void>;
57
67
  getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy;
68
+ createBatch(uuid: string): Promise<string>;
69
+ commitBatch(uuid: string, batchId: string): Promise<LinkExpressionMutations>;
58
70
  }
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _PerspectiveClient_apolloClient, _PerspectiveClient_perspectiveAddedCallbacks, _PerspectiveClient_perspectiveUpdatedCallbacks, _PerspectiveClient_perspectiveRemovedCallbacks, _PerspectiveClient_perspectiveSyncStateChangeCallbacks, _PerspectiveClient_expressionClient, _PerspectiveClient_neighbourhoodClient;
12
+ var _PerspectiveClient_apolloClient, _PerspectiveClient_perspectiveAddedCallbacks, _PerspectiveClient_perspectiveUpdatedCallbacks, _PerspectiveClient_perspectiveRemovedCallbacks, _PerspectiveClient_perspectiveSyncStateChangeCallbacks, _PerspectiveClient_expressionClient, _PerspectiveClient_neighbourhoodClient, _PerspectiveClient_aiClient;
13
13
  import { gql } from "@apollo/client/core";
14
14
  import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
15
15
  import unwrapApolloResult from "../unwrapApolloResult";
@@ -51,6 +51,7 @@ export class PerspectiveClient {
51
51
  _PerspectiveClient_perspectiveSyncStateChangeCallbacks.set(this, void 0);
52
52
  _PerspectiveClient_expressionClient.set(this, void 0);
53
53
  _PerspectiveClient_neighbourhoodClient.set(this, void 0);
54
+ _PerspectiveClient_aiClient.set(this, void 0);
54
55
  __classPrivateFieldSet(this, _PerspectiveClient_apolloClient, client, "f");
55
56
  __classPrivateFieldSet(this, _PerspectiveClient_perspectiveAddedCallbacks, [], "f");
56
57
  __classPrivateFieldSet(this, _PerspectiveClient_perspectiveUpdatedCallbacks, [], "f");
@@ -68,6 +69,12 @@ export class PerspectiveClient {
68
69
  setNeighbourhoodClient(client) {
69
70
  __classPrivateFieldSet(this, _PerspectiveClient_neighbourhoodClient, client, "f");
70
71
  }
72
+ setAIClient(client) {
73
+ __classPrivateFieldSet(this, _PerspectiveClient_aiClient, client, "f");
74
+ }
75
+ get aiClient() {
76
+ return __classPrivateFieldGet(this, _PerspectiveClient_aiClient, "f");
77
+ }
71
78
  async all() {
72
79
  const { perspectives } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").query({
73
80
  query: gql `query perspectives {
@@ -131,6 +138,84 @@ export class PerspectiveClient {
131
138
  }));
132
139
  return JSON.parse(perspectiveQueryProlog);
133
140
  }
141
+ async subscribeQuery(uuid, query) {
142
+ const { perspectiveSubscribeQuery } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
143
+ mutation: gql `mutation perspectiveSubscribeQuery($uuid: String!, $query: String!) {
144
+ perspectiveSubscribeQuery(uuid: $uuid, query: $query) {
145
+ subscriptionId
146
+ result
147
+ }
148
+ }`,
149
+ variables: { uuid, query }
150
+ }));
151
+ const { subscriptionId, result } = perspectiveSubscribeQuery;
152
+ let finalResult = result;
153
+ let isInit = false;
154
+ if (finalResult.startsWith("#init#")) {
155
+ finalResult = finalResult.substring(6);
156
+ isInit = true;
157
+ }
158
+ try {
159
+ finalResult = JSON.parse(finalResult);
160
+ }
161
+ catch (e) {
162
+ console.error('Error parsing perspectiveSubscribeQuery result:', e);
163
+ }
164
+ return { subscriptionId, result: finalResult, isInit };
165
+ }
166
+ subscribeToQueryUpdates(subscriptionId, onData) {
167
+ const subscription = __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").subscribe({
168
+ query: gql `
169
+ subscription perspectiveQuerySubscription($subscriptionId: String!) {
170
+ perspectiveQuerySubscription(subscriptionId: $subscriptionId)
171
+ }
172
+ `,
173
+ variables: {
174
+ subscriptionId
175
+ }
176
+ }).subscribe({
177
+ next: (result) => {
178
+ if (result.data && result.data.perspectiveQuerySubscription) {
179
+ let finalResult = result.data.perspectiveQuerySubscription;
180
+ let isInit = false;
181
+ if (finalResult.startsWith("#init#")) {
182
+ finalResult = finalResult.substring(6);
183
+ isInit = true;
184
+ }
185
+ try {
186
+ finalResult = JSON.parse(finalResult);
187
+ if (isInit && typeof finalResult === 'object') {
188
+ finalResult.isInit = true;
189
+ }
190
+ }
191
+ catch (e) {
192
+ console.error('Error parsing perspectiveQuerySubscription:', e);
193
+ }
194
+ onData(finalResult);
195
+ }
196
+ },
197
+ error: (e) => console.error('Error in query subscription:', e)
198
+ });
199
+ return () => subscription.unsubscribe();
200
+ }
201
+ async keepAliveQuery(uuid, subscriptionId) {
202
+ const { perspectiveKeepAliveQuery } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
203
+ mutation: gql `mutation perspectiveKeepAliveQuery($uuid: String!, $subscriptionId: String!) {
204
+ perspectiveKeepAliveQuery(uuid: $uuid, subscriptionId: $subscriptionId)
205
+ }`,
206
+ variables: { uuid, subscriptionId }
207
+ }));
208
+ return perspectiveKeepAliveQuery;
209
+ }
210
+ async disposeQuerySubscription(uuid, subscriptionId) {
211
+ const { perspectiveDisposeQuerySubscription } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
212
+ mutation: gql `mutation perspectiveDisposeQuerySubscription($uuid: String!, $subscriptionId: String!) {
213
+ perspectiveDisposeQuerySubscription(uuid: $uuid, subscriptionId: $subscriptionId)
214
+ }`,
215
+ variables: { uuid, subscriptionId }
216
+ }));
217
+ return perspectiveDisposeQuerySubscription;
218
+ }
134
219
  async add(name) {
135
220
  const { perspectiveAdd } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
136
221
  mutation: gql `mutation perspectiveAdd($name: String!) {
@@ -161,36 +246,36 @@ export class PerspectiveClient {
161
246
  variables: { uuid }
162
247
  }));
163
248
  }
164
- async addLink(uuid, link, status) {
249
+ async addLink(uuid, link, status = 'shared', batchId) {
165
250
  const { perspectiveAddLink } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
166
- mutation: gql `mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String){
167
- perspectiveAddLink(link: $link, uuid: $uuid, status: $status) {
251
+ mutation: gql `mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String!, $batchId: String) {
252
+ perspectiveAddLink(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
168
253
  ${LINK_EXPRESSION_FIELDS}
169
254
  }
170
255
  }`,
171
- variables: { uuid, link, status }
256
+ variables: { uuid, link, status, batchId }
172
257
  }));
173
258
  return perspectiveAddLink;
174
259
  }
175
- async addLinks(uuid, links, status) {
260
+ async addLinks(uuid, links, status = 'shared', batchId) {
176
261
  const { perspectiveAddLinks } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
177
- mutation: gql `mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String){
178
- perspectiveAddLinks(links: $links, uuid: $uuid, status: $status) {
262
+ mutation: gql `mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String!, $batchId: String) {
263
+ perspectiveAddLinks(uuid: $uuid, links: $links, status: $status, batchId: $batchId) {
179
264
  ${LINK_EXPRESSION_FIELDS}
180
265
  }
181
266
  }`,
182
- variables: { uuid, links, status }
267
+ variables: { uuid, links, status, batchId }
183
268
  }));
184
269
  return perspectiveAddLinks;
185
270
  }
186
- async removeLinks(uuid, links) {
271
+ async removeLinks(uuid, links, batchId) {
187
272
  const { perspectiveRemoveLinks } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
188
- mutation: gql `mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]!){
189
- perspectiveRemoveLinks(links: $links, uuid: $uuid) {
273
+ mutation: gql `mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]!, $batchId: String) {
274
+ perspectiveRemoveLinks(uuid: $uuid, links: $links, batchId: $batchId) {
190
275
  ${LINK_EXPRESSION_FIELDS}
191
276
  }
192
277
  }`,
193
- variables: { uuid, links }
278
+ variables: { uuid, links, batchId }
194
279
  }));
195
280
  return perspectiveRemoveLinks;
196
281
  }
@@ -210,76 +295,62 @@ export class PerspectiveClient {
210
295
  }));
211
296
  return perspectiveLinkMutations;
212
297
  }
213
- async addLinkExpression(uuid, link, status) {
298
+ async addLinkExpression(uuid, link, status = 'shared', batchId) {
214
299
  const { perspectiveAddLinkExpression } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
215
- mutation: gql `mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String){
216
- perspectiveAddLinkExpression(link: $link, uuid: $uuid, status: $status) {
300
+ mutation: gql `mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String!, $batchId: String) {
301
+ perspectiveAddLinkExpression(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
217
302
  ${LINK_EXPRESSION_FIELDS}
218
303
  }
219
304
  }`,
220
- variables: { uuid, link }
305
+ variables: { uuid, link, status, batchId }
221
306
  }));
222
307
  return perspectiveAddLinkExpression;
223
308
  }
224
- async updateLink(uuid, oldLink, newLink) {
225
- delete oldLink.__typename;
226
- delete oldLink.data.__typename;
227
- delete oldLink.proof.__typename;
309
+ async updateLink(uuid, oldLink, newLink, batchId) {
228
310
  const { perspectiveUpdateLink } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
229
- mutation: gql `mutation perspectiveUpdateLink(
230
- $uuid: String!,
231
- $newLink: LinkInput!
232
- $oldLink: LinkExpressionInput!
233
- ){
234
- perspectiveUpdateLink(
235
- newLink: $newLink,
236
- oldLink: $oldLink,
237
- uuid: $uuid
238
- ) {
311
+ mutation: gql `mutation perspectiveUpdateLink($uuid: String!, $oldLink: LinkExpressionInput!, $newLink: LinkInput!, $batchId: String) {
312
+ perspectiveUpdateLink(uuid: $uuid, oldLink: $oldLink, newLink: $newLink, batchId: $batchId) {
239
313
  ${LINK_EXPRESSION_FIELDS}
240
314
  }
241
315
  }`,
242
- variables: { uuid, oldLink, newLink }
316
+ variables: { uuid, oldLink, newLink, batchId }
243
317
  }));
244
- if (!perspectiveUpdateLink.status) {
245
- delete perspectiveUpdateLink.status;
246
- }
247
318
  return perspectiveUpdateLink;
248
319
  }
249
- async removeLink(uuid, link) {
320
+ async removeLink(uuid, link, batchId) {
250
321
  delete link.__typename;
251
322
  delete link.data.__typename;
252
323
  delete link.proof.__typename;
253
324
  delete link.status;
254
- return unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
255
- mutation: gql `mutation perspectiveRemoveLink($link: LinkExpressionInput!, $uuid: String!) {
256
- perspectiveRemoveLink(link: $link, uuid: $uuid)
325
+ const { perspectiveRemoveLink } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
326
+ mutation: gql `mutation perspectiveRemoveLink($link: LinkExpressionInput!, $uuid: String!, $batchId: String) {
327
+ perspectiveRemoveLink(link: $link, uuid: $uuid, batchId: $batchId)
257
328
  }`,
258
- variables: { uuid, link }
329
+ variables: { uuid, link, batchId }
259
330
  }));
331
+ return perspectiveRemoveLink;
260
332
  }
261
333
  async addSdna(uuid, name, sdnaCode, sdnaType) {
262
334
  return unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
263
335
  mutation: gql `mutation perspectiveAddSdna($uuid: String!, $name: String!, $sdnaCode: String!, $sdnaType: String!) {
264
336
  perspectiveAddSdna(uuid: $uuid, name: $name, sdnaCode: $sdnaCode, sdnaType: $sdnaType)
265
- }`,
266
- variables: { uuid, name, sdnaCode, sdnaType }
337
+ }`, variables: { uuid, name, sdnaCode, sdnaType }
267
338
  })).perspectiveAddSdna;
268
339
  }
269
- async executeCommands(uuid, commands, expression, parameters) {
340
+ async executeCommands(uuid, commands, expression, parameters, batchId) {
270
341
  return unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
271
- mutation: gql `mutation perspectiveExecuteCommands($uuid: String!, $commands: String!, $expression: String!, $parameters: String) {
272
- perspectiveExecuteCommands(uuid: $uuid, commands: $commands, expression: $expression, parameters: $parameters)
342
+ mutation: gql `mutation perspectiveExecuteCommands($uuid: String!, $commands: String!, $expression: String!, $parameters: String, $batchId: String) {
343
+ perspectiveExecuteCommands(uuid: $uuid, commands: $commands, expression: $expression, parameters: $parameters, batchId: $batchId)
273
344
  }`,
274
- variables: { uuid, commands, expression, parameters }
345
+ variables: { uuid, commands, expression, parameters, batchId }
275
346
  })).perspectiveExecuteCommands;
276
347
  }
277
- async createSubject(uuid, subjectClass, expressionAddress) {
348
+ async createSubject(uuid, subjectClass, expressionAddress, initialValues, batchId) {
278
349
  return unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
279
- mutation: gql `mutation perspectiveCreateSubject($uuid: String!, $subjectClass: String!, $expressionAddress: String!) {
280
- perspectiveCreateSubject(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress)
350
+ mutation: gql `mutation perspectiveCreateSubject($uuid: String!, $subjectClass: String!, $expressionAddress: String!, $initialValues: String, $batchId: String) {
351
+ perspectiveCreateSubject(uuid: $uuid, subjectClass: $subjectClass, expressionAddress: $expressionAddress, initialValues: $initialValues, batchId: $batchId)
281
352
  }`,
282
- variables: { uuid, subjectClass, expressionAddress }
353
+ variables: { uuid, subjectClass, expressionAddress, initialValues, batchId }
283
354
  })).perspectiveCreateSubject;
284
355
  }
285
356
  async getSubjectData(uuid, subjectClass, expressionAddress) {
@@ -438,5 +509,30 @@ export class PerspectiveClient {
438
509
  getNeighbourhoodProxy(uuid) {
439
510
  return new NeighbourhoodProxy(__classPrivateFieldGet(this, _PerspectiveClient_neighbourhoodClient, "f"), uuid);
440
511
  }
512
+ async createBatch(uuid) {
513
+ const { perspectiveCreateBatch } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
514
+ mutation: gql `mutation perspectiveCreateBatch($uuid: String!) {
515
+ perspectiveCreateBatch(uuid: $uuid)
516
+ }`,
517
+ variables: { uuid }
518
+ }));
519
+ return perspectiveCreateBatch;
520
+ }
521
+ async commitBatch(uuid, batchId) {
522
+ const { perspectiveCommitBatch } = unwrapApolloResult(await __classPrivateFieldGet(this, _PerspectiveClient_apolloClient, "f").mutate({
523
+ mutation: gql `mutation perspectiveCommitBatch($uuid: String!, $batchId: String!) {
524
+ perspectiveCommitBatch(uuid: $uuid, batchId: $batchId) {
525
+ additions {
526
+ ${LINK_EXPRESSION_FIELDS}
527
+ }
528
+ removals {
529
+ ${LINK_EXPRESSION_FIELDS}
530
+ }
531
+ }
532
+ }`,
533
+ variables: { uuid, batchId }
534
+ }));
535
+ return perspectiveCommitBatch;
536
+ }
441
537
  }
442
- _PerspectiveClient_apolloClient = new WeakMap(), _PerspectiveClient_perspectiveAddedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveUpdatedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveRemovedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveSyncStateChangeCallbacks = new WeakMap(), _PerspectiveClient_expressionClient = new WeakMap(), _PerspectiveClient_neighbourhoodClient = new WeakMap();
538
+ _PerspectiveClient_apolloClient = new WeakMap(), _PerspectiveClient_perspectiveAddedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveUpdatedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveRemovedCallbacks = new WeakMap(), _PerspectiveClient_perspectiveSyncStateChangeCallbacks = new WeakMap(), _PerspectiveClient_expressionClient = new WeakMap(), _PerspectiveClient_neighbourhoodClient = new WeakMap(), _PerspectiveClient_aiClient = new WeakMap();