@coasys/ad4m 0.12.0-rc1-dev → 0.12.0-rc1-dev.2
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/jest.config.js +4 -4
- package/lib/index.cjs +5999 -6044
- package/lib/index.js +5977 -6038
- package/lib/src/Ad4mClient.d.ts +16 -9
- package/lib/src/Ad4mClient.js +25 -46
- package/lib/src/Ad4mClient.test.d.ts +1 -0
- package/lib/src/Ad4mClient.test.js +1204 -0
- package/lib/src/Literal.d.ts +2 -1
- package/lib/src/Literal.js +35 -38
- package/lib/src/Literal.test.d.ts +1 -0
- package/lib/src/Literal.test.js +41 -0
- package/lib/src/SmartLiteral.d.ts +2 -1
- package/lib/src/SmartLiteral.js +15 -30
- package/lib/src/agent/AgentClient.d.ts +4 -1
- package/lib/src/agent/AgentClient.js +99 -79
- package/lib/src/ai/AIClient.d.ts +2 -1
- package/lib/src/ai/AIClient.js +220 -224
- package/lib/src/expression/ExpressionClient.d.ts +1 -1
- package/lib/src/expression/ExpressionClient.js +86 -73
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/language/LanguageClient.d.ts +1 -1
- package/lib/src/language/LanguageClient.js +52 -52
- package/lib/src/model/Ad4mModel.d.ts +157 -937
- package/lib/src/model/Ad4mModel.js +212 -2797
- package/lib/src/model/Ad4mModel.test.js +1002 -561
- package/lib/src/model/decorators.d.ts +94 -426
- package/lib/src/model/decorators.js +333 -741
- package/lib/src/model/mutation.d.ts +81 -0
- package/lib/src/model/mutation.js +317 -0
- package/lib/src/model/parentUtils.d.ts +32 -0
- package/lib/src/model/parentUtils.js +64 -0
- package/lib/src/model/prolog/generatePrologFacts.d.ts +36 -0
- package/lib/src/model/prolog/generatePrologFacts.js +139 -0
- package/lib/src/model/prolog/index.d.ts +1 -0
- package/lib/src/model/prolog/index.js +1 -0
- package/lib/src/model/query/ModelQueryBuilder.d.ts +82 -0
- package/lib/src/model/query/ModelQueryBuilder.js +115 -0
- package/lib/src/model/query/QueryBuilder.d.ts +101 -0
- package/lib/src/model/query/QueryBuilder.js +193 -0
- package/lib/src/model/query/SurrealQueryBuilder.d.ts +48 -0
- package/lib/src/model/query/SurrealQueryBuilder.js +371 -0
- package/lib/src/model/query/fetchInstance.d.ts +24 -0
- package/lib/src/model/query/fetchInstance.js +144 -0
- package/lib/src/model/query/hydration.d.ts +54 -0
- package/lib/src/model/query/hydration.js +214 -0
- package/lib/src/model/query/operations.d.ts +59 -0
- package/lib/src/model/query/operations.js +384 -0
- package/lib/src/model/query/snapshot.d.ts +59 -0
- package/lib/src/model/query/snapshot.js +106 -0
- package/lib/src/model/query/surrealCompiler.d.ts +42 -0
- package/lib/src/model/query/surrealCompiler.js +304 -0
- package/lib/src/model/schema/fromJSONSchema.d.ts +67 -0
- package/lib/src/model/schema/fromJSONSchema.js +264 -0
- package/lib/src/model/schema/metadata.d.ts +15 -0
- package/lib/src/model/schema/metadata.js +112 -0
- package/lib/src/model/subscription.d.ts +47 -0
- package/lib/src/model/subscription.js +231 -0
- package/lib/src/model/transaction.d.ts +27 -0
- package/lib/src/model/transaction.js +32 -0
- package/lib/src/model/types.d.ts +195 -0
- package/lib/src/model/types.js +8 -0
- package/lib/src/model/util.js +7 -7
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +5 -1
- package/lib/src/neighbourhood/NeighbourhoodClient.js +263 -181
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +2 -1
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +13 -28
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +1 -5
- package/lib/src/perspectives/PerspectiveClient.d.ts +9 -9
- package/lib/src/perspectives/PerspectiveClient.js +316 -240
- package/lib/src/perspectives/PerspectiveProxy.d.ts +54 -92
- package/lib/src/perspectives/PerspectiveProxy.js +803 -444
- package/lib/src/runtime/RuntimeClient.d.ts +5 -1
- package/lib/src/runtime/RuntimeClient.js +412 -238
- package/lib/src/shacl/SHACLFlow.test.js +164 -105
- package/lib/src/shacl/SHACLShape.d.ts +17 -3
- package/lib/src/shacl/SHACLShape.js +127 -90
- package/lib/src/shacl/SHACLShape.test.js +244 -176
- package/lib/src/utils.d.ts +8 -0
- package/lib/src/utils.js +21 -7
- package/package.json +8 -13
- package/src/Ad4mClient.test.ts +1564 -1315
- package/src/Ad4mClient.ts +55 -54
- package/src/Literal.test.ts +45 -26
- package/src/Literal.ts +82 -66
- package/src/SmartLiteral.ts +74 -58
- package/src/agent/AgentClient.ts +144 -99
- package/src/ai/AIClient.ts +409 -359
- package/src/expression/ExpressionClient.ts +142 -96
- package/src/index.ts +1 -1
- package/src/language/LanguageClient.ts +137 -113
- package/src/model/Ad4mModel.test.ts +1128 -647
- package/src/model/Ad4mModel.ts +485 -3247
- package/src/model/IMPROVEMENTS.md +482 -0
- package/src/model/PREDICATE_COLLISION_FIX.md +651 -0
- package/src/model/README.md +317 -0
- package/src/model/SHACL_MUTATION_DECOUPLING.md +356 -0
- package/src/model/SUBSCRIPTION_STRATEGY.md +317 -0
- package/src/model/TC39_STAGE_3_DECORATORS.md +609 -0
- package/src/model/decorators.ts +689 -1046
- package/src/model/mutation.ts +461 -0
- package/src/model/parentUtils.ts +91 -0
- package/src/model/prolog/generatePrologFacts.ts +176 -0
- package/src/model/prolog/index.ts +1 -0
- package/src/model/query/ModelQueryBuilder.ts +173 -0
- package/src/model/query/fetchInstance.ts +181 -0
- package/src/model/query/hydration.ts +273 -0
- package/src/model/query/operations.ts +510 -0
- package/src/model/query/snapshot.ts +126 -0
- package/src/model/query/surrealCompiler.ts +376 -0
- package/src/model/schema/fromJSONSchema.ts +411 -0
- package/src/model/schema/metadata.ts +148 -0
- package/src/model/subscription.ts +307 -0
- package/src/model/transaction.ts +60 -0
- package/src/model/types.ts +207 -0
- package/src/model/util.ts +47 -48
- package/src/neighbourhood/NeighbourhoodClient.ts +393 -251
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +3 -7
- package/src/neighbourhood/NeighbourhoodProxy.ts +58 -40
- package/src/perspectives/PerspectiveClient.ts +779 -540
- package/src/perspectives/PerspectiveProxy.ts +2860 -2053
- package/src/runtime/RuntimeClient.ts +775 -476
- package/src/shacl/SHACLFlow.test.ts +196 -129
- package/src/shacl/SHACLShape.test.ts +284 -190
- package/src/shacl/SHACLShape.ts +225 -172
- package/src/utils.ts +31 -17
- package/tsconfig.json +9 -10
- package/src/model/Subject.ts +0 -159
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
import { ApolloClient, gql } from "@apollo/client/core";
|
|
2
2
|
import { ExpressionRendered } from "../expression/Expression";
|
|
3
3
|
import { ExpressionClient } from "../expression/ExpressionClient";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Link,
|
|
6
|
+
LinkExpressionInput,
|
|
7
|
+
LinkExpression,
|
|
8
|
+
LinkInput,
|
|
9
|
+
LinkMutations,
|
|
10
|
+
LinkExpressionMutations,
|
|
11
|
+
} from "../links/Links";
|
|
5
12
|
import { NeighbourhoodClient } from "../neighbourhood/NeighbourhoodClient";
|
|
6
13
|
import { NeighbourhoodProxy } from "../neighbourhood/NeighbourhoodProxy";
|
|
7
14
|
import unwrapApolloResult from "../unwrapApolloResult";
|
|
8
15
|
import { LinkQuery } from "./LinkQuery";
|
|
9
16
|
import { Perspective } from "./Perspective";
|
|
10
17
|
import { PerspectiveHandle, PerspectiveState } from "./PerspectiveHandle";
|
|
11
|
-
import { LinkStatus, PerspectiveProxy } from
|
|
18
|
+
import { LinkStatus, PerspectiveProxy } from "./PerspectiveProxy";
|
|
12
19
|
import { AIClient } from "../ai/AIClient";
|
|
13
20
|
import { AllInstancesResult } from "../model/Ad4mModel";
|
|
21
|
+
import { isSocketCloseError } from "../utils";
|
|
14
22
|
|
|
15
23
|
const LINK_EXPRESSION_FIELDS = `
|
|
16
24
|
author
|
|
@@ -18,7 +26,7 @@ timestamp
|
|
|
18
26
|
status
|
|
19
27
|
data { source, predicate, target }
|
|
20
28
|
proof { valid, invalid, signature, key }
|
|
21
|
-
|
|
29
|
+
`;
|
|
22
30
|
|
|
23
31
|
const PERSPECTIVE_HANDLE_FIELDS = `
|
|
24
32
|
uuid
|
|
@@ -41,343 +49,393 @@ neighbourhood {
|
|
|
41
49
|
}
|
|
42
50
|
author
|
|
43
51
|
}
|
|
44
|
-
|
|
52
|
+
`;
|
|
45
53
|
|
|
46
|
-
export type PerspectiveHandleCallback = (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export type
|
|
54
|
+
export type PerspectiveHandleCallback = (
|
|
55
|
+
perspective: PerspectiveHandle,
|
|
56
|
+
) => null;
|
|
57
|
+
export type UuidCallback = (uuid: string) => null;
|
|
58
|
+
export type LinkCallback = (link: LinkExpression) => null;
|
|
59
|
+
export type SyncStateChangeCallback = (state: PerspectiveState) => null;
|
|
50
60
|
|
|
51
61
|
export class PerspectiveClient {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
62
|
+
private _apolloClient: ApolloClient<any>;
|
|
63
|
+
private _perspectiveAddedCallbacks: PerspectiveHandleCallback[];
|
|
64
|
+
private _perspectiveUpdatedCallbacks: PerspectiveHandleCallback[];
|
|
65
|
+
private _perspectiveRemovedCallbacks: UuidCallback[];
|
|
66
|
+
private _perspectiveSyncStateChangeCallbacks: SyncStateChangeCallback[];
|
|
67
|
+
private _expressionClient?: ExpressionClient;
|
|
68
|
+
private _neighbourhoodClient?: NeighbourhoodClient;
|
|
69
|
+
private _aiClient?: AIClient;
|
|
70
|
+
|
|
71
|
+
constructor(client: ApolloClient<any>, subscribe: boolean = true) {
|
|
72
|
+
this._apolloClient = client;
|
|
73
|
+
this._perspectiveAddedCallbacks = [];
|
|
74
|
+
this._perspectiveUpdatedCallbacks = [];
|
|
75
|
+
this._perspectiveRemovedCallbacks = [];
|
|
76
|
+
this._perspectiveSyncStateChangeCallbacks = [];
|
|
77
|
+
|
|
78
|
+
if (subscribe) {
|
|
79
|
+
this.subscribePerspectiveAdded();
|
|
80
|
+
this.subscribePerspectiveUpdated();
|
|
81
|
+
this.subscribePerspectiveRemoved();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setExpressionClient(client: ExpressionClient) {
|
|
86
|
+
this._expressionClient = client;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
setNeighbourhoodClient(client: NeighbourhoodClient) {
|
|
90
|
+
this._neighbourhoodClient = client;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setAIClient(client: AIClient) {
|
|
94
|
+
this._aiClient = client;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get aiClient(): AIClient {
|
|
98
|
+
return this._aiClient;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async all(): Promise<PerspectiveProxy[]> {
|
|
102
|
+
const { perspectives } = unwrapApolloResult(
|
|
103
|
+
await this._apolloClient.query({
|
|
104
|
+
query: gql`query perspectives {
|
|
94
105
|
perspectives {
|
|
95
106
|
${PERSPECTIVE_HANDLE_FIELDS}
|
|
96
107
|
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
108
|
+
}`,
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
return perspectives.map((handle) => new PerspectiveProxy(handle, this));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async byUUID(uuid: string): Promise<PerspectiveProxy | null> {
|
|
115
|
+
const { perspective } = unwrapApolloResult(
|
|
116
|
+
await this._apolloClient.query({
|
|
117
|
+
query: gql`query perspective($uuid: String!) {
|
|
105
118
|
perspective(uuid: $uuid) {
|
|
106
119
|
${PERSPECTIVE_HANDLE_FIELDS}
|
|
107
120
|
}
|
|
108
121
|
}`,
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
variables: { uuid },
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
if (!perspective) return null;
|
|
126
|
+
return new PerspectiveProxy(perspective, this);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async snapshotByUUID(uuid: string): Promise<Perspective | null> {
|
|
130
|
+
const { perspectiveSnapshot } = unwrapApolloResult(
|
|
131
|
+
await this._apolloClient.query({
|
|
132
|
+
query: gql`query perspectiveSnapshot($uuid: String!) {
|
|
118
133
|
perspectiveSnapshot(uuid: $uuid) {
|
|
119
134
|
links { ${LINK_EXPRESSION_FIELDS} }
|
|
120
135
|
}
|
|
121
136
|
}`,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
variables: { uuid },
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
140
|
+
return perspectiveSnapshot;
|
|
141
|
+
}
|
|
142
|
+
async publishSnapshotByUUID(uuid: string): Promise<string | null> {
|
|
143
|
+
const { perspectivePublishSnapshot } = unwrapApolloResult(
|
|
144
|
+
await this._apolloClient.mutate({
|
|
145
|
+
mutation: gql`
|
|
146
|
+
mutation perspectivePublishSnapshot($uuid: String!) {
|
|
147
|
+
perspectivePublishSnapshot(uuid: $uuid)
|
|
148
|
+
}
|
|
149
|
+
`,
|
|
150
|
+
variables: { uuid },
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
return perspectivePublishSnapshot;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async queryLinks(uuid: string, query: LinkQuery): Promise<LinkExpression[]> {
|
|
157
|
+
const { perspectiveQueryLinks } = unwrapApolloResult(
|
|
158
|
+
await this._apolloClient.query({
|
|
159
|
+
query: gql`query perspectiveQueryLinks($uuid: String!, $query: LinkQuery!) {
|
|
139
160
|
perspectiveQueryLinks(query: $query, uuid: $uuid) {
|
|
140
161
|
${LINK_EXPRESSION_FIELDS}
|
|
141
162
|
}
|
|
142
163
|
}`,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
async perspectiveSubscribeSurrealQuery(uuid: string, query: string): Promise<{ subscriptionId: string, result: AllInstancesResult, isInit?: boolean }> {
|
|
205
|
-
const { perspectiveSubscribeSurrealQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
206
|
-
mutation: gql`mutation perspectiveSubscribeSurrealQuery($uuid: String!, $query: String!) {
|
|
207
|
-
perspectiveSubscribeSurrealQuery(uuid: $uuid, query: $query) {
|
|
208
|
-
subscriptionId
|
|
209
|
-
result
|
|
210
|
-
}
|
|
211
|
-
}`,
|
|
212
|
-
variables: { uuid, query }
|
|
213
|
-
}))
|
|
214
|
-
const { subscriptionId, result } = perspectiveSubscribeSurrealQuery
|
|
215
|
-
let finalResult = result;
|
|
216
|
-
let isInit = false;
|
|
217
|
-
if(finalResult.startsWith("#init#")) {
|
|
218
|
-
finalResult = finalResult.substring(6)
|
|
219
|
-
isInit = true;
|
|
220
|
-
}
|
|
221
|
-
try {
|
|
222
|
-
finalResult = JSON.parse(finalResult)
|
|
223
|
-
} catch (e) {
|
|
224
|
-
console.error('Error parsing perspectiveSubscribeSurrealQuery result:', e)
|
|
225
|
-
}
|
|
226
|
-
return { subscriptionId, result: finalResult, isInit }
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async perspectiveKeepAliveSurrealQuery(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
230
|
-
const { perspectiveKeepAliveSurrealQuery } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
231
|
-
mutation: gql`mutation perspectiveKeepAliveSurrealQuery($uuid: String!, $subscriptionId: String!) {
|
|
232
|
-
perspectiveKeepAliveSurrealQuery(uuid: $uuid, subscriptionId: $subscriptionId)
|
|
233
|
-
}`,
|
|
234
|
-
variables: { uuid, subscriptionId }
|
|
235
|
-
}))
|
|
236
|
-
|
|
237
|
-
return perspectiveKeepAliveSurrealQuery
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
async perspectiveDisposeSurrealQuerySubscription(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
241
|
-
const { perspectiveDisposeSurrealQuerySubscription } = unwrapApolloResult(await this.#apolloClient.mutate({
|
|
242
|
-
mutation: gql`mutation perspectiveDisposeSurrealQuerySubscription($uuid: String!, $subscriptionId: String!) {
|
|
243
|
-
perspectiveDisposeSurrealQuerySubscription(uuid: $uuid, subscriptionId: $subscriptionId)
|
|
244
|
-
}`,
|
|
245
|
-
variables: { uuid, subscriptionId }
|
|
246
|
-
}))
|
|
247
|
-
|
|
248
|
-
return perspectiveDisposeSurrealQuerySubscription
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
subscribeToQueryUpdates(subscriptionId: string, onData: (result: AllInstancesResult) => void): () => void {
|
|
252
|
-
const subscription = this.#apolloClient.subscribe({
|
|
253
|
-
query: gql`
|
|
254
|
-
subscription perspectiveQuerySubscription($subscriptionId: String!) {
|
|
255
|
-
perspectiveQuerySubscription(subscriptionId: $subscriptionId)
|
|
256
|
-
}
|
|
257
|
-
`,
|
|
258
|
-
variables: {
|
|
259
|
-
subscriptionId
|
|
164
|
+
variables: { uuid, query },
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
return perspectiveQueryLinks;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async queryProlog(uuid: string, query: string): Promise<any> {
|
|
171
|
+
const { perspectiveQueryProlog } = unwrapApolloResult(
|
|
172
|
+
await this._apolloClient.query({
|
|
173
|
+
query: gql`
|
|
174
|
+
query perspectiveQueryProlog($uuid: String!, $query: String!) {
|
|
175
|
+
perspectiveQueryProlog(uuid: $uuid, query: $query)
|
|
176
|
+
}
|
|
177
|
+
`,
|
|
178
|
+
variables: { uuid, query },
|
|
179
|
+
}),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
return JSON.parse(perspectiveQueryProlog);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Executes a read-only SurrealQL query against a perspective's link cache.
|
|
187
|
+
*
|
|
188
|
+
* Security: Only SELECT, RETURN, and other read-only queries are permitted.
|
|
189
|
+
* Mutating operations (DELETE, UPDATE, INSERT, etc.) are blocked.
|
|
190
|
+
*
|
|
191
|
+
* Note: GraphQL field name is "perspectiveQuerySurrealDb" (lowercase "b" in "Db")
|
|
192
|
+
* as generated from Rust method "perspective_query_surreal_db"
|
|
193
|
+
*/
|
|
194
|
+
async querySurrealDB(uuid: string, query: string): Promise<any> {
|
|
195
|
+
const { perspectiveQuerySurrealDb } = unwrapApolloResult(
|
|
196
|
+
await this._apolloClient.query({
|
|
197
|
+
query: gql`
|
|
198
|
+
query perspectiveQuerySurrealDb($uuid: String!, $query: String!) {
|
|
199
|
+
perspectiveQuerySurrealDb(uuid: $uuid, query: $query)
|
|
200
|
+
}
|
|
201
|
+
`,
|
|
202
|
+
variables: { uuid, query },
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
return JSON.parse(perspectiveQuerySurrealDb);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async subscribeQuery(
|
|
210
|
+
uuid: string,
|
|
211
|
+
query: string,
|
|
212
|
+
): Promise<{
|
|
213
|
+
subscriptionId: string;
|
|
214
|
+
result: AllInstancesResult;
|
|
215
|
+
isInit?: boolean;
|
|
216
|
+
}> {
|
|
217
|
+
const { perspectiveSubscribeQuery } = unwrapApolloResult(
|
|
218
|
+
await this._apolloClient.mutate({
|
|
219
|
+
mutation: gql`
|
|
220
|
+
mutation perspectiveSubscribeQuery($uuid: String!, $query: String!) {
|
|
221
|
+
perspectiveSubscribeQuery(uuid: $uuid, query: $query) {
|
|
222
|
+
subscriptionId
|
|
223
|
+
result
|
|
260
224
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
225
|
+
}
|
|
226
|
+
`,
|
|
227
|
+
variables: { uuid, query },
|
|
228
|
+
}),
|
|
229
|
+
);
|
|
230
|
+
const { subscriptionId, result } = perspectiveSubscribeQuery;
|
|
231
|
+
let finalResult = result;
|
|
232
|
+
let isInit = false;
|
|
233
|
+
if (finalResult.startsWith("#init#")) {
|
|
234
|
+
finalResult = finalResult.substring(6);
|
|
235
|
+
isInit = true;
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
finalResult = JSON.parse(finalResult);
|
|
239
|
+
} catch (e) {
|
|
240
|
+
console.error("Error parsing perspectiveSubscribeQuery result:", e);
|
|
241
|
+
}
|
|
242
|
+
return { subscriptionId, result: finalResult, isInit };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
subscribeToQueryUpdates(
|
|
246
|
+
subscriptionId: string,
|
|
247
|
+
onData: (result: AllInstancesResult) => void,
|
|
248
|
+
): () => void {
|
|
249
|
+
const subscription = this._apolloClient
|
|
250
|
+
.subscribe({
|
|
251
|
+
query: gql`
|
|
252
|
+
subscription perspectiveQuerySubscription($subscriptionId: String!) {
|
|
253
|
+
perspectiveQuerySubscription(subscriptionId: $subscriptionId)
|
|
254
|
+
}
|
|
255
|
+
`,
|
|
256
|
+
variables: {
|
|
257
|
+
subscriptionId,
|
|
258
|
+
},
|
|
259
|
+
})
|
|
260
|
+
.subscribe({
|
|
261
|
+
next: (result) => {
|
|
262
|
+
if (result.data && result.data.perspectiveQuerySubscription) {
|
|
263
|
+
let finalResult = result.data.perspectiveQuerySubscription;
|
|
264
|
+
let isInit = false;
|
|
265
|
+
if (finalResult.startsWith("#init#")) {
|
|
266
|
+
finalResult = finalResult.substring(6);
|
|
267
|
+
isInit = true;
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
finalResult = JSON.parse(finalResult);
|
|
271
|
+
if (isInit && typeof finalResult === "object") {
|
|
272
|
+
finalResult.isInit = true;
|
|
273
|
+
}
|
|
274
|
+
} catch (e) {
|
|
275
|
+
console.error("Error parsing perspectiveQuerySubscription:", e);
|
|
276
|
+
}
|
|
277
|
+
onData(finalResult);
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
error: (e) => {
|
|
281
|
+
if (!isSocketCloseError(e))
|
|
282
|
+
console.error("Error in query subscription:", e);
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
return () => subscription.unsubscribe();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async keepAliveQuery(uuid: string, subscriptionId: string): Promise<boolean> {
|
|
290
|
+
const { perspectiveKeepAliveQuery } = unwrapApolloResult(
|
|
291
|
+
await this._apolloClient.mutate({
|
|
292
|
+
mutation: gql`
|
|
293
|
+
mutation perspectiveKeepAliveQuery(
|
|
294
|
+
$uuid: String!
|
|
295
|
+
$subscriptionId: String!
|
|
296
|
+
) {
|
|
297
|
+
perspectiveKeepAliveQuery(
|
|
298
|
+
uuid: $uuid
|
|
299
|
+
subscriptionId: $subscriptionId
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
`,
|
|
303
|
+
variables: { uuid, subscriptionId },
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
return perspectiveKeepAliveQuery;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async disposeQuerySubscription(
|
|
311
|
+
uuid: string,
|
|
312
|
+
subscriptionId: string,
|
|
313
|
+
): Promise<boolean> {
|
|
314
|
+
const { perspectiveDisposeQuerySubscription } = unwrapApolloResult(
|
|
315
|
+
await this._apolloClient.mutate({
|
|
316
|
+
mutation: gql`
|
|
317
|
+
mutation perspectiveDisposeQuerySubscription(
|
|
318
|
+
$uuid: String!
|
|
319
|
+
$subscriptionId: String!
|
|
320
|
+
) {
|
|
321
|
+
perspectiveDisposeQuerySubscription(
|
|
322
|
+
uuid: $uuid
|
|
323
|
+
subscriptionId: $subscriptionId
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
`,
|
|
327
|
+
variables: { uuid, subscriptionId },
|
|
328
|
+
}),
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
return perspectiveDisposeQuerySubscription;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
async add(name: string): Promise<PerspectiveProxy> {
|
|
335
|
+
const { perspectiveAdd } = unwrapApolloResult(
|
|
336
|
+
await this._apolloClient.mutate({
|
|
337
|
+
mutation: gql`mutation perspectiveAdd($name: String!) {
|
|
312
338
|
perspectiveAdd(name: $name) {
|
|
313
339
|
${PERSPECTIVE_HANDLE_FIELDS}
|
|
314
340
|
}
|
|
315
341
|
}`,
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
342
|
+
variables: { name },
|
|
343
|
+
}),
|
|
344
|
+
);
|
|
345
|
+
return new PerspectiveProxy(perspectiveAdd, this);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async update(uuid: string, name: string): Promise<PerspectiveProxy> {
|
|
349
|
+
const { perspectiveUpdate } = unwrapApolloResult(
|
|
350
|
+
await this._apolloClient.mutate({
|
|
351
|
+
mutation: gql`mutation perspectiveUpdate($uuid: String!, $name: String!) {
|
|
324
352
|
perspectiveUpdate(uuid: $uuid, name: $name) {
|
|
325
353
|
${PERSPECTIVE_HANDLE_FIELDS}
|
|
326
354
|
}
|
|
327
355
|
}`,
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
356
|
+
variables: { uuid, name },
|
|
357
|
+
}),
|
|
358
|
+
);
|
|
359
|
+
return new PerspectiveProxy(perspectiveUpdate, this);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async remove(uuid: string): Promise<{ perspectiveRemove: boolean }> {
|
|
363
|
+
return unwrapApolloResult(
|
|
364
|
+
await this._apolloClient.mutate({
|
|
365
|
+
mutation: gql`
|
|
366
|
+
mutation perspectiveRemove($uuid: String!) {
|
|
367
|
+
perspectiveRemove(uuid: $uuid)
|
|
368
|
+
}
|
|
369
|
+
`,
|
|
370
|
+
variables: { uuid },
|
|
371
|
+
}),
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async addLink(
|
|
376
|
+
uuid: string,
|
|
377
|
+
link: Link,
|
|
378
|
+
status: LinkStatus = "shared",
|
|
379
|
+
batchId?: string,
|
|
380
|
+
): Promise<LinkExpression> {
|
|
381
|
+
const { perspectiveAddLink } = unwrapApolloResult(
|
|
382
|
+
await this._apolloClient.mutate({
|
|
383
|
+
mutation: gql`mutation perspectiveAddLink($uuid: String!, $link: LinkInput!, $status: String!, $batchId: String) {
|
|
345
384
|
perspectiveAddLink(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
|
|
346
385
|
${LINK_EXPRESSION_FIELDS}
|
|
347
386
|
}
|
|
348
387
|
}`,
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
388
|
+
variables: { uuid, link, status, batchId },
|
|
389
|
+
}),
|
|
390
|
+
);
|
|
391
|
+
return perspectiveAddLink;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async addLinks(
|
|
395
|
+
uuid: string,
|
|
396
|
+
links: Link[],
|
|
397
|
+
status: LinkStatus = "shared",
|
|
398
|
+
batchId?: string,
|
|
399
|
+
): Promise<LinkExpression[]> {
|
|
400
|
+
const { perspectiveAddLinks } = unwrapApolloResult(
|
|
401
|
+
await this._apolloClient.mutate({
|
|
402
|
+
mutation: gql`mutation perspectiveAddLinks($uuid: String!, $links: [LinkInput!]!, $status: String!, $batchId: String) {
|
|
357
403
|
perspectiveAddLinks(uuid: $uuid, links: $links, status: $status, batchId: $batchId) {
|
|
358
404
|
${LINK_EXPRESSION_FIELDS}
|
|
359
405
|
}
|
|
360
406
|
}`,
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
407
|
+
variables: { uuid, links, status, batchId },
|
|
408
|
+
}),
|
|
409
|
+
);
|
|
410
|
+
return perspectiveAddLinks;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async removeLinks(
|
|
414
|
+
uuid: string,
|
|
415
|
+
links: LinkExpressionInput[],
|
|
416
|
+
batchId?: string,
|
|
417
|
+
): Promise<LinkExpression[]> {
|
|
418
|
+
const { perspectiveRemoveLinks } = unwrapApolloResult(
|
|
419
|
+
await this._apolloClient.mutate({
|
|
420
|
+
mutation: gql`mutation perspectiveRemoveLinks($uuid: String!, $links: [LinkExpressionInput!]!, $batchId: String) {
|
|
369
421
|
perspectiveRemoveLinks(uuid: $uuid, links: $links, batchId: $batchId) {
|
|
370
422
|
${LINK_EXPRESSION_FIELDS}
|
|
371
423
|
}
|
|
372
424
|
}`,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
425
|
+
variables: { uuid, links, batchId },
|
|
426
|
+
}),
|
|
427
|
+
);
|
|
428
|
+
return perspectiveRemoveLinks;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async linkMutations(
|
|
432
|
+
uuid: string,
|
|
433
|
+
mutations: LinkMutations,
|
|
434
|
+
status?: LinkStatus,
|
|
435
|
+
): Promise<LinkExpressionMutations> {
|
|
436
|
+
const { perspectiveLinkMutations } = unwrapApolloResult(
|
|
437
|
+
await this._apolloClient.mutate({
|
|
438
|
+
mutation: gql`mutation perspectiveLinkMutations($uuid: String!, $mutations: LinkMutations!, $status: String){
|
|
381
439
|
perspectiveLinkMutations(mutations: $mutations, uuid: $uuid, status: $status) {
|
|
382
440
|
additions {
|
|
383
441
|
${LINK_EXPRESSION_FIELDS}
|
|
@@ -387,223 +445,391 @@ export class PerspectiveClient {
|
|
|
387
445
|
}
|
|
388
446
|
}
|
|
389
447
|
}`,
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
448
|
+
variables: { uuid, mutations, status },
|
|
449
|
+
}),
|
|
450
|
+
);
|
|
451
|
+
return perspectiveLinkMutations;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
async addLinkExpression(
|
|
455
|
+
uuid: string,
|
|
456
|
+
link: LinkExpression,
|
|
457
|
+
status: LinkStatus = "shared",
|
|
458
|
+
batchId?: string,
|
|
459
|
+
): Promise<LinkExpression> {
|
|
460
|
+
const { perspectiveAddLinkExpression } = unwrapApolloResult(
|
|
461
|
+
await this._apolloClient.mutate({
|
|
462
|
+
mutation: gql`mutation perspectiveAddLinkExpression($uuid: String!, $link: LinkExpressionInput!, $status: String!, $batchId: String) {
|
|
398
463
|
perspectiveAddLinkExpression(uuid: $uuid, link: $link, status: $status, batchId: $batchId) {
|
|
399
464
|
${LINK_EXPRESSION_FIELDS}
|
|
400
465
|
}
|
|
401
466
|
}`,
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
467
|
+
variables: { uuid, link, status, batchId },
|
|
468
|
+
}),
|
|
469
|
+
);
|
|
470
|
+
return perspectiveAddLinkExpression;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
async updateLink(
|
|
474
|
+
uuid: string,
|
|
475
|
+
oldLink: LinkExpressionInput,
|
|
476
|
+
newLink: Link,
|
|
477
|
+
batchId?: string,
|
|
478
|
+
): Promise<LinkExpression> {
|
|
479
|
+
const { perspectiveUpdateLink } = unwrapApolloResult(
|
|
480
|
+
await this._apolloClient.mutate({
|
|
481
|
+
mutation: gql`mutation perspectiveUpdateLink($uuid: String!, $oldLink: LinkExpressionInput!, $newLink: LinkInput!, $batchId: String) {
|
|
410
482
|
perspectiveUpdateLink(uuid: $uuid, oldLink: $oldLink, newLink: $newLink, batchId: $batchId) {
|
|
411
483
|
${LINK_EXPRESSION_FIELDS}
|
|
412
484
|
}
|
|
413
485
|
}`,
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
486
|
+
variables: { uuid, oldLink, newLink, batchId },
|
|
487
|
+
}),
|
|
488
|
+
);
|
|
489
|
+
return perspectiveUpdateLink;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
async removeLink(
|
|
493
|
+
uuid: string,
|
|
494
|
+
link: LinkExpressionInput,
|
|
495
|
+
batchId?: string,
|
|
496
|
+
): Promise<boolean> {
|
|
497
|
+
delete link.__typename;
|
|
498
|
+
delete link.data.__typename;
|
|
499
|
+
delete link.proof.__typename;
|
|
500
|
+
delete link.status;
|
|
501
|
+
const { perspectiveRemoveLink } = unwrapApolloResult(
|
|
502
|
+
await this._apolloClient.mutate({
|
|
503
|
+
mutation: gql`
|
|
504
|
+
mutation perspectiveRemoveLink(
|
|
505
|
+
$link: LinkExpressionInput!
|
|
506
|
+
$uuid: String!
|
|
507
|
+
$batchId: String
|
|
508
|
+
) {
|
|
509
|
+
perspectiveRemoveLink(link: $link, uuid: $uuid, batchId: $batchId)
|
|
510
|
+
}
|
|
511
|
+
`,
|
|
512
|
+
variables: { uuid, link, batchId },
|
|
513
|
+
}),
|
|
514
|
+
);
|
|
515
|
+
return perspectiveRemoveLink;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Adds Social DNA code to a perspective.
|
|
520
|
+
*
|
|
521
|
+
* Preferred usage: pass shaclJson (from SHACLShape.toJSON()) as the primary schema definition.
|
|
522
|
+
* The sdnaCode parameter is kept for backward compatibility but SHACL is the source of truth
|
|
523
|
+
* for all SDNA operations. Prolog engines remain available for complex queries.
|
|
524
|
+
*
|
|
525
|
+
* @param sdnaCode - Legacy Prolog code (pass empty string when using shaclJson)
|
|
526
|
+
* @param shaclJson - SHACL JSON string from SHACLShape.toJSON() (recommended)
|
|
527
|
+
*/
|
|
528
|
+
async addSdna(
|
|
529
|
+
uuid: string,
|
|
530
|
+
name: string,
|
|
531
|
+
sdnaCode: string | undefined,
|
|
532
|
+
sdnaType: "subject_class" | "flow" | "custom",
|
|
533
|
+
shaclJson?: string,
|
|
534
|
+
): Promise<boolean> {
|
|
535
|
+
return unwrapApolloResult(
|
|
536
|
+
await this._apolloClient.mutate({
|
|
537
|
+
mutation: gql`
|
|
538
|
+
mutation perspectiveAddSdna(
|
|
539
|
+
$uuid: String!
|
|
540
|
+
$name: String!
|
|
541
|
+
$sdnaCode: String
|
|
542
|
+
$sdnaType: String!
|
|
543
|
+
$shaclJson: String
|
|
544
|
+
) {
|
|
545
|
+
perspectiveAddSdna(
|
|
546
|
+
uuid: $uuid
|
|
547
|
+
name: $name
|
|
548
|
+
sdnaCode: $sdnaCode
|
|
549
|
+
sdnaType: $sdnaType
|
|
550
|
+
shaclJson: $shaclJson
|
|
551
|
+
)
|
|
552
|
+
}
|
|
553
|
+
`,
|
|
554
|
+
variables: {
|
|
555
|
+
uuid,
|
|
556
|
+
name,
|
|
557
|
+
sdnaCode: sdnaCode || "",
|
|
558
|
+
sdnaType,
|
|
559
|
+
shaclJson,
|
|
560
|
+
},
|
|
561
|
+
}),
|
|
562
|
+
).perspectiveAddSdna;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
async executeCommands(
|
|
566
|
+
uuid: string,
|
|
567
|
+
commands: string,
|
|
568
|
+
expression: string,
|
|
569
|
+
parameters: string,
|
|
570
|
+
batchId?: string,
|
|
571
|
+
): Promise<boolean> {
|
|
572
|
+
return unwrapApolloResult(
|
|
573
|
+
await this._apolloClient.mutate({
|
|
574
|
+
mutation: gql`
|
|
575
|
+
mutation perspectiveExecuteCommands(
|
|
576
|
+
$uuid: String!
|
|
577
|
+
$commands: String!
|
|
578
|
+
$expression: String!
|
|
579
|
+
$parameters: String
|
|
580
|
+
$batchId: String
|
|
581
|
+
) {
|
|
582
|
+
perspectiveExecuteCommands(
|
|
583
|
+
uuid: $uuid
|
|
584
|
+
commands: $commands
|
|
585
|
+
expression: $expression
|
|
586
|
+
parameters: $parameters
|
|
587
|
+
batchId: $batchId
|
|
588
|
+
)
|
|
589
|
+
}
|
|
590
|
+
`,
|
|
591
|
+
variables: { uuid, commands, expression, parameters, batchId },
|
|
592
|
+
}),
|
|
593
|
+
).perspectiveExecuteCommands;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
async createSubject(
|
|
597
|
+
uuid: string,
|
|
598
|
+
subjectClass: string,
|
|
599
|
+
expressionAddress: string,
|
|
600
|
+
initialValues?: string,
|
|
601
|
+
batchId?: string,
|
|
602
|
+
): Promise<boolean> {
|
|
603
|
+
return unwrapApolloResult(
|
|
604
|
+
await this._apolloClient.mutate({
|
|
605
|
+
mutation: gql`
|
|
606
|
+
mutation perspectiveCreateSubject(
|
|
607
|
+
$uuid: String!
|
|
608
|
+
$subjectClass: String!
|
|
609
|
+
$expressionAddress: String!
|
|
610
|
+
$initialValues: String
|
|
611
|
+
$batchId: String
|
|
612
|
+
) {
|
|
613
|
+
perspectiveCreateSubject(
|
|
614
|
+
uuid: $uuid
|
|
615
|
+
subjectClass: $subjectClass
|
|
616
|
+
expressionAddress: $expressionAddress
|
|
617
|
+
initialValues: $initialValues
|
|
618
|
+
batchId: $batchId
|
|
619
|
+
)
|
|
620
|
+
}
|
|
621
|
+
`,
|
|
622
|
+
variables: {
|
|
623
|
+
uuid,
|
|
624
|
+
subjectClass,
|
|
625
|
+
expressionAddress,
|
|
626
|
+
initialValues,
|
|
627
|
+
batchId,
|
|
628
|
+
},
|
|
629
|
+
}),
|
|
630
|
+
).perspectiveCreateSubject;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
async getSubjectData(
|
|
634
|
+
uuid: string,
|
|
635
|
+
subjectClass: string,
|
|
636
|
+
expressionAddress: string,
|
|
637
|
+
): Promise<string> {
|
|
638
|
+
return unwrapApolloResult(
|
|
639
|
+
await this._apolloClient.mutate({
|
|
640
|
+
mutation: gql`
|
|
641
|
+
mutation perspectiveGetSubjectData(
|
|
642
|
+
$uuid: String!
|
|
643
|
+
$subjectClass: String!
|
|
644
|
+
$expressionAddress: String!
|
|
645
|
+
) {
|
|
646
|
+
perspectiveGetSubjectData(
|
|
647
|
+
uuid: $uuid
|
|
648
|
+
subjectClass: $subjectClass
|
|
649
|
+
expressionAddress: $expressionAddress
|
|
650
|
+
)
|
|
651
|
+
}
|
|
652
|
+
`,
|
|
653
|
+
variables: { uuid, subjectClass, expressionAddress },
|
|
654
|
+
}),
|
|
655
|
+
).perspectiveGetSubjectData;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// ExpressionClient functions, needed for Subjects:
|
|
659
|
+
async getExpression(expressionURI: string): Promise<ExpressionRendered> {
|
|
660
|
+
return await this._expressionClient.get(expressionURI);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
async createExpression(
|
|
664
|
+
content: any,
|
|
665
|
+
languageAddress: string,
|
|
666
|
+
): Promise<string> {
|
|
667
|
+
return await this._expressionClient.create(content, languageAddress);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// Subscriptions:
|
|
671
|
+
addPerspectiveAddedListener(cb: PerspectiveHandleCallback) {
|
|
672
|
+
this._perspectiveAddedCallbacks.push(cb);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
subscribePerspectiveAdded() {
|
|
676
|
+
this._apolloClient
|
|
677
|
+
.subscribe({
|
|
678
|
+
query: gql` subscription {
|
|
496
679
|
perspectiveAdded { ${PERSPECTIVE_HANDLE_FIELDS} }
|
|
497
680
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
681
|
+
`,
|
|
682
|
+
})
|
|
683
|
+
.subscribe({
|
|
684
|
+
next: (result) => {
|
|
685
|
+
this._perspectiveAddedCallbacks.forEach((cb) => {
|
|
686
|
+
cb(result.data.perspectiveAdded);
|
|
687
|
+
});
|
|
688
|
+
},
|
|
689
|
+
error: (e) => {
|
|
690
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
691
|
+
},
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
addPerspectiveUpdatedListener(cb: PerspectiveHandleCallback) {
|
|
696
|
+
this._perspectiveUpdatedCallbacks.push(cb);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
subscribePerspectiveUpdated() {
|
|
700
|
+
this._apolloClient
|
|
701
|
+
.subscribe({
|
|
702
|
+
query: gql` subscription {
|
|
515
703
|
perspectiveUpdated { ${PERSPECTIVE_HANDLE_FIELDS} }
|
|
516
704
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
705
|
+
`,
|
|
706
|
+
})
|
|
707
|
+
.subscribe({
|
|
708
|
+
next: (result) => {
|
|
709
|
+
this._perspectiveUpdatedCallbacks.forEach((cb) => {
|
|
710
|
+
cb(result.data.perspectiveUpdated);
|
|
711
|
+
});
|
|
712
|
+
},
|
|
713
|
+
error: (e) => {
|
|
714
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
715
|
+
},
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
addPerspectiveSyncedListener(cb: SyncStateChangeCallback) {
|
|
720
|
+
this._perspectiveSyncStateChangeCallbacks.push(cb);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
async addPerspectiveSyncStateChangeListener(
|
|
724
|
+
uuid: String,
|
|
725
|
+
cb: SyncStateChangeCallback[],
|
|
726
|
+
): Promise<void> {
|
|
727
|
+
this._apolloClient
|
|
728
|
+
.subscribe({
|
|
729
|
+
query: gql` subscription {
|
|
534
730
|
perspectiveSyncStateChange(uuid: "${uuid}")
|
|
535
731
|
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
732
|
+
`,
|
|
733
|
+
})
|
|
734
|
+
.subscribe({
|
|
735
|
+
next: (result) => {
|
|
736
|
+
cb.forEach((c) => {
|
|
737
|
+
c(result.data.perspectiveSyncStateChange);
|
|
738
|
+
});
|
|
739
|
+
},
|
|
740
|
+
error: (e) => {
|
|
741
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
742
|
+
},
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 500));
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
addPerspectiveRemovedListener(cb: UuidCallback) {
|
|
749
|
+
this._perspectiveRemovedCallbacks.push(cb);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
subscribePerspectiveRemoved() {
|
|
753
|
+
this._apolloClient
|
|
754
|
+
.subscribe({
|
|
755
|
+
query: gql`
|
|
756
|
+
subscription {
|
|
757
|
+
perspectiveRemoved
|
|
758
|
+
}
|
|
759
|
+
`,
|
|
760
|
+
})
|
|
761
|
+
.subscribe({
|
|
762
|
+
next: (result) => {
|
|
763
|
+
this._perspectiveRemovedCallbacks.forEach((cb) => {
|
|
764
|
+
cb(result.data.perspectiveRemoved);
|
|
765
|
+
});
|
|
766
|
+
},
|
|
767
|
+
error: (e) => {
|
|
768
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
769
|
+
},
|
|
770
|
+
});
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
async addPerspectiveLinkAddedListener(
|
|
774
|
+
uuid: String,
|
|
775
|
+
cb: LinkCallback[],
|
|
776
|
+
): Promise<void> {
|
|
777
|
+
this._apolloClient
|
|
778
|
+
.subscribe({
|
|
779
|
+
query: gql` subscription {
|
|
570
780
|
perspectiveLinkAdded(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
|
|
571
781
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
782
|
+
`,
|
|
783
|
+
})
|
|
784
|
+
.subscribe({
|
|
785
|
+
next: (result) => {
|
|
786
|
+
cb.forEach((c) => {
|
|
787
|
+
c(result.data.perspectiveLinkAdded);
|
|
788
|
+
});
|
|
789
|
+
},
|
|
790
|
+
error: (e) => {
|
|
791
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
792
|
+
},
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 500));
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
async addPerspectiveLinkRemovedListener(
|
|
799
|
+
uuid: String,
|
|
800
|
+
cb: LinkCallback[],
|
|
801
|
+
): Promise<void> {
|
|
802
|
+
this._apolloClient
|
|
803
|
+
.subscribe({
|
|
804
|
+
query: gql` subscription {
|
|
587
805
|
perspectiveLinkRemoved(uuid: "${uuid}") { ${LINK_EXPRESSION_FIELDS} }
|
|
588
806
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
807
|
+
`,
|
|
808
|
+
})
|
|
809
|
+
.subscribe({
|
|
810
|
+
next: (result) => {
|
|
811
|
+
cb.forEach((c) => {
|
|
812
|
+
if (!result.data.perspectiveLinkRemoved.status) {
|
|
813
|
+
delete result.data.perspectiveLinkRemoved.status;
|
|
814
|
+
}
|
|
815
|
+
c(result.data.perspectiveLinkRemoved);
|
|
816
|
+
});
|
|
817
|
+
},
|
|
818
|
+
error: (e) => {
|
|
819
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
820
|
+
},
|
|
821
|
+
});
|
|
822
|
+
|
|
823
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 500));
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
async addPerspectiveLinkUpdatedListener(
|
|
827
|
+
uuid: String,
|
|
828
|
+
cb: LinkCallback[],
|
|
829
|
+
): Promise<void> {
|
|
830
|
+
this._apolloClient
|
|
831
|
+
.subscribe({
|
|
832
|
+
query: gql` subscription {
|
|
607
833
|
perspectiveLinkUpdated(uuid: "${uuid}") {
|
|
608
834
|
oldLink {
|
|
609
835
|
${LINK_EXPRESSION_FIELDS}
|
|
@@ -613,41 +839,53 @@ export class PerspectiveClient {
|
|
|
613
839
|
}
|
|
614
840
|
}
|
|
615
841
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
842
|
+
`,
|
|
843
|
+
})
|
|
844
|
+
.subscribe({
|
|
845
|
+
next: (result) => {
|
|
846
|
+
cb.forEach((c) => {
|
|
847
|
+
if (!result.data.perspectiveLinkUpdated.newLink.status) {
|
|
848
|
+
delete result.data.perspectiveLinkUpdated.newLink.status;
|
|
849
|
+
}
|
|
850
|
+
if (!result.data.perspectiveLinkUpdated.oldLink.status) {
|
|
851
|
+
delete result.data.perspectiveLinkUpdated.oldLink.status;
|
|
852
|
+
}
|
|
853
|
+
c(result.data.perspectiveLinkUpdated);
|
|
854
|
+
});
|
|
855
|
+
},
|
|
856
|
+
error: (e) => {
|
|
857
|
+
if (!isSocketCloseError(e)) console.error(e);
|
|
858
|
+
},
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
await new Promise<void>((resolve) => setTimeout(resolve, 500));
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
getNeighbourhoodProxy(uuid: string): NeighbourhoodProxy {
|
|
865
|
+
return new NeighbourhoodProxy(this._neighbourhoodClient, uuid);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
async createBatch(uuid: string): Promise<string> {
|
|
869
|
+
const { perspectiveCreateBatch } = unwrapApolloResult(
|
|
870
|
+
await this._apolloClient.mutate({
|
|
871
|
+
mutation: gql`
|
|
872
|
+
mutation perspectiveCreateBatch($uuid: String!) {
|
|
873
|
+
perspectiveCreateBatch(uuid: $uuid)
|
|
874
|
+
}
|
|
875
|
+
`,
|
|
876
|
+
variables: { uuid },
|
|
877
|
+
}),
|
|
878
|
+
);
|
|
879
|
+
return perspectiveCreateBatch;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
async commitBatch(
|
|
883
|
+
uuid: string,
|
|
884
|
+
batchId: string,
|
|
885
|
+
): Promise<LinkExpressionMutations> {
|
|
886
|
+
const { perspectiveCommitBatch } = unwrapApolloResult(
|
|
887
|
+
await this._apolloClient.mutate({
|
|
888
|
+
mutation: gql`mutation perspectiveCommitBatch($uuid: String!, $batchId: String!) {
|
|
651
889
|
perspectiveCommitBatch(uuid: $uuid, batchId: $batchId) {
|
|
652
890
|
additions {
|
|
653
891
|
${LINK_EXPRESSION_FIELDS}
|
|
@@ -657,8 +895,9 @@ export class PerspectiveClient {
|
|
|
657
895
|
}
|
|
658
896
|
}
|
|
659
897
|
}`,
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
}
|
|
898
|
+
variables: { uuid, batchId },
|
|
899
|
+
}),
|
|
900
|
+
);
|
|
901
|
+
return perspectiveCommitBatch;
|
|
902
|
+
}
|
|
903
|
+
}
|