@coasys/ad4m-connect 0.13.0-postmessage-ws-proxy.3 → 0.13.0-postmessage-ws-proxy.5
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/dist/PostMessageFetch.d.ts +12 -0
- package/dist/core.js +223 -104
- package/dist/core.js.map +4 -4
- package/dist/index.js +204 -104
- package/dist/index.js.map +4 -4
- package/dist/web.js +120 -98
- package/dist/web.js.map +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxies an HTTP fetch request through window.parent via postMessage.
|
|
3
|
+
*
|
|
4
|
+
* Used in embedded proxy mode where the iframe cannot reach the AD4M executor
|
|
5
|
+
* directly (e.g. when hosted on a different origin inside WE). The parent
|
|
6
|
+
* receives the AD4M_PROXY_HTTP_REQUEST message, performs the real fetch, and
|
|
7
|
+
* replies with AD4M_PROXY_HTTP_RESPONSE / AD4M_PROXY_HTTP_ERROR.
|
|
8
|
+
*
|
|
9
|
+
* The request URL may use the placeholder origin 'http://proxy' — the parent
|
|
10
|
+
* replaces it with the real executor base URL before fetching.
|
|
11
|
+
*/
|
|
12
|
+
export declare function makePostMessageFetch(targetOrigin: string): typeof fetch;
|
package/dist/core.js
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b ||= {})
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1
20
|
var __async = (__this, __arguments, generator) => {
|
|
2
21
|
return new Promise((resolve, reject) => {
|
|
3
22
|
var fulfilled = (value) => {
|
|
@@ -156,6 +175,79 @@ PostMessageWebSocket.CLOSING = 2;
|
|
|
156
175
|
PostMessageWebSocket.CLOSED = 3;
|
|
157
176
|
PostMessageWebSocket.CONNECT_TIMEOUT_MS = 3e4;
|
|
158
177
|
|
|
178
|
+
// src/PostMessageFetch.ts
|
|
179
|
+
var _idCounter = 0;
|
|
180
|
+
var PROXY_FETCH_TIMEOUT_MS = 6e4;
|
|
181
|
+
function serialiseHeaders(headers) {
|
|
182
|
+
if (!headers)
|
|
183
|
+
return {};
|
|
184
|
+
if (headers instanceof Headers) {
|
|
185
|
+
const out = {};
|
|
186
|
+
headers.forEach((v, k) => {
|
|
187
|
+
out[k] = v;
|
|
188
|
+
});
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
if (Array.isArray(headers)) {
|
|
192
|
+
return Object.fromEntries(headers);
|
|
193
|
+
}
|
|
194
|
+
return __spreadValues({}, headers);
|
|
195
|
+
}
|
|
196
|
+
function makePostMessageFetch(targetOrigin) {
|
|
197
|
+
return function postMessageFetch(input, init) {
|
|
198
|
+
return __async(this, null, function* () {
|
|
199
|
+
var _a;
|
|
200
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
201
|
+
const method = (_a = init == null ? void 0 : init.method) != null ? _a : "GET";
|
|
202
|
+
const headers = serialiseHeaders(init == null ? void 0 : init.headers);
|
|
203
|
+
const id = String(++_idCounter);
|
|
204
|
+
let bodyBuffer = null;
|
|
205
|
+
if ((init == null ? void 0 : init.body) instanceof ArrayBuffer) {
|
|
206
|
+
const b = init.body;
|
|
207
|
+
bodyBuffer = b.slice(0);
|
|
208
|
+
}
|
|
209
|
+
return new Promise((resolve, reject) => {
|
|
210
|
+
let timer = null;
|
|
211
|
+
const cleanup = () => {
|
|
212
|
+
window.removeEventListener("message", handler);
|
|
213
|
+
if (timer)
|
|
214
|
+
clearTimeout(timer);
|
|
215
|
+
};
|
|
216
|
+
const handler = (event) => {
|
|
217
|
+
if (event.source !== window.parent)
|
|
218
|
+
return;
|
|
219
|
+
if (event.origin !== targetOrigin)
|
|
220
|
+
return;
|
|
221
|
+
if (!event.data || event.data.id !== id)
|
|
222
|
+
return;
|
|
223
|
+
if (event.data.type === "AD4M_PROXY_HTTP_RESPONSE") {
|
|
224
|
+
cleanup();
|
|
225
|
+
const { status, statusText, body } = event.data;
|
|
226
|
+
resolve(new Response(body != null ? body : null, { status, statusText }));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (event.data.type === "AD4M_PROXY_HTTP_ERROR") {
|
|
230
|
+
cleanup();
|
|
231
|
+
reject(new TypeError(event.data.message || "Failed to fetch"));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
window.addEventListener("message", handler);
|
|
236
|
+
timer = setTimeout(() => {
|
|
237
|
+
cleanup();
|
|
238
|
+
reject(new TypeError(`AD4M proxy HTTP request timed out after ${PROXY_FETCH_TIMEOUT_MS}ms`));
|
|
239
|
+
}, PROXY_FETCH_TIMEOUT_MS);
|
|
240
|
+
const msg = { type: "AD4M_PROXY_HTTP_REQUEST", id, url, method, headers };
|
|
241
|
+
if (bodyBuffer) {
|
|
242
|
+
window.parent.postMessage(__spreadProps(__spreadValues({}, msg), { body: bodyBuffer }), targetOrigin, [bodyBuffer]);
|
|
243
|
+
} else {
|
|
244
|
+
window.parent.postMessage(__spreadProps(__spreadValues({}, msg), { body: null }), targetOrigin);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
159
251
|
// ../core/lib/index.js
|
|
160
252
|
var RpcError = class extends Error {
|
|
161
253
|
constructor(status, body) {
|
|
@@ -168,12 +260,12 @@ var RpcError = class extends Error {
|
|
|
168
260
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
169
261
|
var MAX_RECONNECT_DELAY_MS = 3e4;
|
|
170
262
|
var INITIAL_RECONNECT_DELAY_MS = 500;
|
|
171
|
-
var
|
|
263
|
+
var _idCounter2 = 0;
|
|
172
264
|
function nextId() {
|
|
173
|
-
return String(++
|
|
265
|
+
return String(++_idCounter2);
|
|
174
266
|
}
|
|
175
267
|
var ApiClient = class {
|
|
176
|
-
constructor(baseUrl, token, webSocketImpl) {
|
|
268
|
+
constructor(baseUrl, token, webSocketImpl, fetchImpl) {
|
|
177
269
|
this._ws = null;
|
|
178
270
|
this._wsCallbacks = /* @__PURE__ */ new Set();
|
|
179
271
|
this._pendingCalls = /* @__PURE__ */ new Map();
|
|
@@ -186,6 +278,7 @@ var ApiClient = class {
|
|
|
186
278
|
this.baseUrl = baseUrl;
|
|
187
279
|
this.token = token;
|
|
188
280
|
this._webSocketImpl = webSocketImpl;
|
|
281
|
+
this._fetchImpl = fetchImpl;
|
|
189
282
|
}
|
|
190
283
|
getBaseUrl() {
|
|
191
284
|
return this.baseUrl;
|
|
@@ -193,14 +286,17 @@ var ApiClient = class {
|
|
|
193
286
|
getToken() {
|
|
194
287
|
return this.token;
|
|
195
288
|
}
|
|
289
|
+
doFetch(url, init) {
|
|
290
|
+
return this._fetchImpl ? this._fetchImpl(url, init) : fetch(url, init);
|
|
291
|
+
}
|
|
196
292
|
setToken(token) {
|
|
197
293
|
this.token = token;
|
|
198
294
|
}
|
|
199
295
|
_getWsUrl() {
|
|
200
296
|
const wsBase = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://");
|
|
201
297
|
const tokenParam = this.token ? `token=${encodeURIComponent(this.token)}` : "";
|
|
202
|
-
const
|
|
203
|
-
return tokenParam ? `${wsBase}${
|
|
298
|
+
const path2 = "/api/v1/ws";
|
|
299
|
+
return tokenParam ? `${wsBase}${path2}?${tokenParam}` : `${wsBase}${path2}`;
|
|
204
300
|
}
|
|
205
301
|
_ensureWs() {
|
|
206
302
|
if (this._ws && (this._ws.readyState === 1 || this._ws.readyState === 0)) {
|
|
@@ -625,9 +721,9 @@ var Literal = class {
|
|
|
625
721
|
__classPrivateFieldSet$b(l, _Literal_url, url, "f");
|
|
626
722
|
return l;
|
|
627
723
|
}
|
|
628
|
-
static from(
|
|
724
|
+
static from(literal2) {
|
|
629
725
|
const l = new Literal();
|
|
630
|
-
__classPrivateFieldSet$b(l, _Literal_literal,
|
|
726
|
+
__classPrivateFieldSet$b(l, _Literal_literal, literal2, "f");
|
|
631
727
|
return l;
|
|
632
728
|
}
|
|
633
729
|
toUrl() {
|
|
@@ -834,6 +930,32 @@ function buildSDNA(subjectName, obj, properties, allRelationsMeta) {
|
|
|
834
930
|
name: subjectName
|
|
835
931
|
};
|
|
836
932
|
}
|
|
933
|
+
function isNodeExpression(v) {
|
|
934
|
+
if (typeof v !== "object" || v === null)
|
|
935
|
+
return false;
|
|
936
|
+
const obj = v;
|
|
937
|
+
const type = obj.type;
|
|
938
|
+
switch (type) {
|
|
939
|
+
case "focus":
|
|
940
|
+
return typeof obj.type === "string";
|
|
941
|
+
case "literal":
|
|
942
|
+
return typeof obj.value === "string" || typeof obj.value === "number" || typeof obj.value === "boolean";
|
|
943
|
+
case "path":
|
|
944
|
+
return typeof obj.predicate === "string";
|
|
945
|
+
case "exists":
|
|
946
|
+
return isNodeExpression(obj.expr);
|
|
947
|
+
case "if":
|
|
948
|
+
return isNodeExpression(obj.cond) && isNodeExpression(obj.then) && (obj.else === void 0 || isNodeExpression(obj.else));
|
|
949
|
+
case "concat":
|
|
950
|
+
return Array.isArray(obj.args) && obj.args.every(isNodeExpression);
|
|
951
|
+
case "coalesce":
|
|
952
|
+
return Array.isArray(obj.args) && obj.args.every(isNodeExpression);
|
|
953
|
+
case "function":
|
|
954
|
+
return typeof obj.iri === "string" && Array.isArray(obj.args) && obj.args.every(isNodeExpression);
|
|
955
|
+
default:
|
|
956
|
+
return false;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
837
959
|
function extractNamespace(uri) {
|
|
838
960
|
const hashIndex = uri.lastIndexOf("#");
|
|
839
961
|
if (hashIndex !== -1) {
|
|
@@ -1094,7 +1216,7 @@ var SHACLShape = class {
|
|
|
1094
1216
|
target: `literal:${prop.writable}`
|
|
1095
1217
|
});
|
|
1096
1218
|
}
|
|
1097
|
-
if (prop.resolveLanguage) {
|
|
1219
|
+
if (prop.resolveLanguage != null) {
|
|
1098
1220
|
links.push({
|
|
1099
1221
|
source: propShapeId,
|
|
1100
1222
|
predicate: "ad4m://resolveLanguage",
|
|
@@ -1185,6 +1307,13 @@ var SHACLShape = class {
|
|
|
1185
1307
|
target: `literal:${prop.filter}`
|
|
1186
1308
|
});
|
|
1187
1309
|
}
|
|
1310
|
+
if (prop.transform && typeof prop.transform === "object") {
|
|
1311
|
+
links.push({
|
|
1312
|
+
source: propShapeId,
|
|
1313
|
+
predicate: "ad4m://transform",
|
|
1314
|
+
target: `literal:string:${JSON.stringify(prop.transform)}`
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1188
1317
|
}
|
|
1189
1318
|
return links;
|
|
1190
1319
|
}
|
|
@@ -1367,6 +1496,19 @@ var SHACLShape = class {
|
|
|
1367
1496
|
val = val.substring(8);
|
|
1368
1497
|
prop.filter = val === "true";
|
|
1369
1498
|
}
|
|
1499
|
+
const transformLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://transform");
|
|
1500
|
+
if (transformLink) {
|
|
1501
|
+
const jsonStr = transformLink.target.replace(/^literal:\/\/string:|^literal:string:/, "");
|
|
1502
|
+
try {
|
|
1503
|
+
const parsed = JSON.parse(jsonStr);
|
|
1504
|
+
if (!isNodeExpression(parsed)) {
|
|
1505
|
+
throw new Error(`Invalid transform for property ${propShapeId}: payload is not a valid NodeExpression. Received: ${jsonStr}`);
|
|
1506
|
+
}
|
|
1507
|
+
prop.transform = parsed;
|
|
1508
|
+
} catch (e) {
|
|
1509
|
+
throw new Error(`Failed to deserialize transform for property ${propShapeId}: ${e instanceof Error ? e.message : String(e)}. Payload: ${jsonStr}`);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1370
1512
|
shape.addProperty(prop);
|
|
1371
1513
|
}
|
|
1372
1514
|
return shape;
|
|
@@ -1401,7 +1543,8 @@ var SHACLShape = class {
|
|
|
1401
1543
|
target_class_name: p.targetClassName,
|
|
1402
1544
|
where_filter: p.whereFilter,
|
|
1403
1545
|
where_predicates: p.wherePredicates,
|
|
1404
|
-
filter: p.filter
|
|
1546
|
+
filter: p.filter,
|
|
1547
|
+
transform: p.transform
|
|
1405
1548
|
})),
|
|
1406
1549
|
constructor_actions: this.constructor_actions,
|
|
1407
1550
|
destructor_actions: this.destructor_actions
|
|
@@ -1410,6 +1553,9 @@ var SHACLShape = class {
|
|
|
1410
1553
|
static fromJSON(json) {
|
|
1411
1554
|
const shape = json.node_shape_uri ? new SHACLShape(json.node_shape_uri, json.target_class) : new SHACLShape(json.target_class);
|
|
1412
1555
|
for (const p of json.properties || []) {
|
|
1556
|
+
if (p.transform && !isNodeExpression(p.transform)) {
|
|
1557
|
+
throw new Error(`Invalid transform for property ${p.name}: payload is not a valid NodeExpression. Received: ${JSON.stringify(p.transform)}`);
|
|
1558
|
+
}
|
|
1413
1559
|
shape.addProperty({
|
|
1414
1560
|
path: p.path,
|
|
1415
1561
|
name: p.name,
|
|
@@ -1435,7 +1581,8 @@ var SHACLShape = class {
|
|
|
1435
1581
|
targetClassName: p.target_class_name,
|
|
1436
1582
|
whereFilter: p.where_filter,
|
|
1437
1583
|
wherePredicates: p.where_predicates,
|
|
1438
|
-
filter: p.filter
|
|
1584
|
+
filter: p.filter,
|
|
1585
|
+
transform: p.transform
|
|
1439
1586
|
});
|
|
1440
1587
|
}
|
|
1441
1588
|
if (json.constructor_actions) {
|
|
@@ -1523,12 +1670,15 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
|
|
|
1523
1670
|
if (propMeta.writable !== void 0) {
|
|
1524
1671
|
propShape.writable = propMeta.writable;
|
|
1525
1672
|
}
|
|
1526
|
-
if (propMeta.resolveLanguage) {
|
|
1673
|
+
if (propMeta.resolveLanguage != null) {
|
|
1527
1674
|
propShape.resolveLanguage = propMeta.resolveLanguage;
|
|
1528
1675
|
}
|
|
1529
1676
|
if (propMeta.getter) {
|
|
1530
1677
|
propShape.getter = propMeta.getter;
|
|
1531
1678
|
}
|
|
1679
|
+
if (propMeta.transform) {
|
|
1680
|
+
propShape.transform = propMeta.transform;
|
|
1681
|
+
}
|
|
1532
1682
|
if (propMeta.prologSetter) {
|
|
1533
1683
|
console.warn(`[SHACL Generation] Custom Prolog setter for property '${propName}' in class '${subjectName}' is not yet supported. The property will be created without setter actions. Consider using standard writable properties or provide explicit SHACL JSON.`);
|
|
1534
1684
|
} else if (propMeta.writable && propMeta.through) {
|
|
@@ -8883,7 +9033,7 @@ var AIClient = class {
|
|
|
8883
9033
|
const baseUrl = __classPrivateFieldGet$2(this, _AIClient_apiClient, "f").getBaseUrl();
|
|
8884
9034
|
const token = __classPrivateFieldGet$2(this, _AIClient_apiClient, "f").getToken();
|
|
8885
9035
|
const bodyBuffer = typedAudio.buffer.slice(typedAudio.byteOffset, typedAudio.byteOffset + typedAudio.byteLength);
|
|
8886
|
-
const response = await
|
|
9036
|
+
const response = await __classPrivateFieldGet$2(this, _AIClient_apiClient, "f").doFetch(`${baseUrl}/api/v1/ai/transcription/feed`, {
|
|
8887
9037
|
method: "POST",
|
|
8888
9038
|
headers: {
|
|
8889
9039
|
"Content-Type": "application/octet-stream",
|
|
@@ -8923,8 +9073,8 @@ function normalizeNamespaceString(namespace) {
|
|
|
8923
9073
|
return "";
|
|
8924
9074
|
if (namespace.includes("://")) {
|
|
8925
9075
|
const [scheme, rest] = namespace.split("://");
|
|
8926
|
-
const
|
|
8927
|
-
return `${scheme}://${
|
|
9076
|
+
const path2 = (rest || "").replace(/\/+$/, "");
|
|
9077
|
+
return `${scheme}://${path2}`;
|
|
8928
9078
|
} else {
|
|
8929
9079
|
return namespace.replace(/\/+$/, "");
|
|
8930
9080
|
}
|
|
@@ -9522,11 +9672,7 @@ var ModelQueryBuilder = class {
|
|
|
9522
9672
|
const parseResults = (raw) => {
|
|
9523
9673
|
return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
|
|
9524
9674
|
};
|
|
9525
|
-
const
|
|
9526
|
-
await ctor.resolveNonLiteralProps(this.perspective, instances);
|
|
9527
|
-
return instances;
|
|
9528
|
-
};
|
|
9529
|
-
const initialResults = await resolveAndReturn(parseResults(initialModelResult));
|
|
9675
|
+
const initialResults = parseResults(initialModelResult);
|
|
9530
9676
|
let lastResultFingerprint = null;
|
|
9531
9677
|
const buildFingerprint = (results) => {
|
|
9532
9678
|
if (results.length === 0)
|
|
@@ -9536,20 +9682,16 @@ var ModelQueryBuilder = class {
|
|
|
9536
9682
|
lastResultFingerprint = buildFingerprint(initialResults);
|
|
9537
9683
|
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
9538
9684
|
try {
|
|
9539
|
-
const
|
|
9540
|
-
console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
callback(results);
|
|
9550
|
-
}).catch((e) => {
|
|
9551
|
-
console.error("Model subscription update resolve error:", e);
|
|
9552
|
-
});
|
|
9685
|
+
const results = parseResults(rawResult);
|
|
9686
|
+
console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${results.length} instances`);
|
|
9687
|
+
const fp = buildFingerprint(results);
|
|
9688
|
+
if (fp === lastResultFingerprint) {
|
|
9689
|
+
console.debug(`[ModelQueryBuilder.subscribe] Fingerprint unchanged, skipping callback`);
|
|
9690
|
+
return;
|
|
9691
|
+
}
|
|
9692
|
+
console.debug(`[ModelQueryBuilder.subscribe] Fingerprint changed, calling callback with ${results.length} results`);
|
|
9693
|
+
lastResultFingerprint = fp;
|
|
9694
|
+
callback(results);
|
|
9553
9695
|
} catch (e) {
|
|
9554
9696
|
console.error("Model subscription update parse error:", e);
|
|
9555
9697
|
}
|
|
@@ -9763,27 +9905,6 @@ function normalizeValue(value) {
|
|
|
9763
9905
|
}
|
|
9764
9906
|
return value;
|
|
9765
9907
|
}
|
|
9766
|
-
function defaultFileDecode(resolved) {
|
|
9767
|
-
if (resolved !== null && typeof resolved === "object" && "data_base64" in resolved) {
|
|
9768
|
-
const fd = resolved;
|
|
9769
|
-
let raw;
|
|
9770
|
-
try {
|
|
9771
|
-
raw = atob(fd.data_base64);
|
|
9772
|
-
} catch {
|
|
9773
|
-
return resolved;
|
|
9774
|
-
}
|
|
9775
|
-
const isJson = !fd.file_type || fd.file_type === "application/json";
|
|
9776
|
-
if (isJson) {
|
|
9777
|
-
try {
|
|
9778
|
-
return JSON.parse(raw);
|
|
9779
|
-
} catch {
|
|
9780
|
-
return raw;
|
|
9781
|
-
}
|
|
9782
|
-
}
|
|
9783
|
-
return raw;
|
|
9784
|
-
}
|
|
9785
|
-
return resolved;
|
|
9786
|
-
}
|
|
9787
9908
|
function jsonToModelInstance(ModelClass, perspective, json, include, properties) {
|
|
9788
9909
|
const instance = new ModelClass(perspective, json.id || json.baseExpression);
|
|
9789
9910
|
if (properties) {
|
|
@@ -9817,19 +9938,6 @@ function jsonToModelInstance(ModelClass, perspective, json, include, properties)
|
|
|
9817
9938
|
}
|
|
9818
9939
|
instance[key] = value;
|
|
9819
9940
|
}
|
|
9820
|
-
try {
|
|
9821
|
-
const propsMeta = getPropertiesMetadata(ModelClass);
|
|
9822
|
-
for (const [propName, opts] of Object.entries(propsMeta)) {
|
|
9823
|
-
const o = opts;
|
|
9824
|
-
if (typeof o.transform !== "function" || !(propName in json))
|
|
9825
|
-
continue;
|
|
9826
|
-
if (o.resolveLanguage != null && o.resolveLanguage !== "literal")
|
|
9827
|
-
continue;
|
|
9828
|
-
instance[propName] = o.transform(instance[propName]);
|
|
9829
|
-
}
|
|
9830
|
-
} catch (e) {
|
|
9831
|
-
console.debug("jsonToModelInstance: transform metadata unavailable:", e);
|
|
9832
|
-
}
|
|
9833
9941
|
if (include) {
|
|
9834
9942
|
const relMeta = getRelationsMetadata(ModelClass);
|
|
9835
9943
|
for (const [relName, includeVal] of Object.entries(include)) {
|
|
@@ -9903,8 +10011,8 @@ var Ad4mModel = class {
|
|
|
9903
10011
|
...options.getter !== void 0 && { getter: options.getter },
|
|
9904
10012
|
...options.prologSetter !== void 0 && { prologSetter: options.prologSetter },
|
|
9905
10013
|
...options.local !== void 0 && { local: options.local },
|
|
9906
|
-
...options.
|
|
9907
|
-
...options.
|
|
10014
|
+
...options.flag !== void 0 && { flag: options.flag },
|
|
10015
|
+
...options.transform !== void 0 && { transform: options.transform }
|
|
9908
10016
|
};
|
|
9909
10017
|
}
|
|
9910
10018
|
const relationsMetadata = {};
|
|
@@ -10206,44 +10314,12 @@ var Ad4mModel = class {
|
|
|
10206
10314
|
return [];
|
|
10207
10315
|
return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
|
|
10208
10316
|
}
|
|
10209
|
-
static async resolveNonLiteralProps(perspective, instances) {
|
|
10210
|
-
const propsMeta = getPropertiesMetadata(this);
|
|
10211
|
-
const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null && opts.resolveLanguage !== "literal");
|
|
10212
|
-
if (resolveProps.length === 0)
|
|
10213
|
-
return;
|
|
10214
|
-
await Promise.all(instances.map(async (inst) => {
|
|
10215
|
-
for (const [propName, opts] of resolveProps) {
|
|
10216
|
-
const val = inst[propName];
|
|
10217
|
-
const transform = opts.transform;
|
|
10218
|
-
const applyTransform = (resolved) => typeof transform === "function" ? transform(resolved) : defaultFileDecode(resolved);
|
|
10219
|
-
if (typeof val === "string" && val && !val.startsWith("literal:")) {
|
|
10220
|
-
try {
|
|
10221
|
-
const expression = await perspective.getExpression(val);
|
|
10222
|
-
if (expression) {
|
|
10223
|
-
let resolved;
|
|
10224
|
-
try {
|
|
10225
|
-
resolved = JSON.parse(expression.data);
|
|
10226
|
-
} catch {
|
|
10227
|
-
resolved = expression.data;
|
|
10228
|
-
}
|
|
10229
|
-
inst[propName] = applyTransform(resolved);
|
|
10230
|
-
}
|
|
10231
|
-
} catch (e) {
|
|
10232
|
-
console.debug(`resolveNonLiteralProps: resolution failed for '${propName}':`, e);
|
|
10233
|
-
}
|
|
10234
|
-
} else if (val !== null && val !== void 0 && typeof val === "object") {
|
|
10235
|
-
inst[propName] = applyTransform(val);
|
|
10236
|
-
}
|
|
10237
|
-
}
|
|
10238
|
-
}));
|
|
10239
|
-
}
|
|
10240
10317
|
static async executeModelQuery(perspective, query = {}, classNameOverride) {
|
|
10241
10318
|
const { className, queryJson } = this.prepareModelQueryParams(query, classNameOverride);
|
|
10242
10319
|
const result = await perspective.modelQuery(className, queryJson);
|
|
10243
10320
|
const instances = result.instances.map((json) => {
|
|
10244
10321
|
return jsonToModelInstance(this, perspective, json, query.include, query.properties);
|
|
10245
10322
|
});
|
|
10246
|
-
await this.resolveNonLiteralProps(perspective, instances);
|
|
10247
10323
|
const snapshotRelations = query.include ? Object.fromEntries(Object.entries(query.include).filter(([k]) => !k.startsWith("$"))) : void 0;
|
|
10248
10324
|
for (const inst of instances) {
|
|
10249
10325
|
inst.takeSnapshot(snapshotRelations && Object.keys(snapshotRelations).length > 0 ? snapshotRelations : void 0);
|
|
@@ -10709,7 +10785,7 @@ var Ad4mClient = class {
|
|
|
10709
10785
|
_Ad4mClient_aiClient.set(this, void 0);
|
|
10710
10786
|
__classPrivateFieldSet$1(this, _Ad4mClient_baseUrl, baseUrl, "f");
|
|
10711
10787
|
__classPrivateFieldSet$1(this, _Ad4mClient_token, token, "f");
|
|
10712
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_apiClient, new ApiClient(baseUrl, token, options?.webSocketImpl), "f");
|
|
10788
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_apiClient, new ApiClient(baseUrl, token, options?.webSocketImpl, options?.fetchImpl), "f");
|
|
10713
10789
|
__classPrivateFieldSet$1(this, _Ad4mClient_agentClient, new AgentClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
10714
10790
|
__classPrivateFieldSet$1(this, _Ad4mClient_expressionClient, new ExpressionClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
10715
10791
|
__classPrivateFieldSet$1(this, _Ad4mClient_languageClient, new LanguageClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
@@ -10787,6 +10863,44 @@ var _SmartLiteral_base;
|
|
|
10787
10863
|
_SmartLiteral_perspective = /* @__PURE__ */ new WeakMap(), _SmartLiteral_base = /* @__PURE__ */ new WeakMap();
|
|
10788
10864
|
var NeighbourhoodExpression = class extends ExpressionGeneric() {
|
|
10789
10865
|
};
|
|
10866
|
+
function focus() {
|
|
10867
|
+
return Object.freeze({ type: "focus" });
|
|
10868
|
+
}
|
|
10869
|
+
function literal(value) {
|
|
10870
|
+
return Object.freeze({ type: "literal", value });
|
|
10871
|
+
}
|
|
10872
|
+
function path(predicate) {
|
|
10873
|
+
return Object.freeze({ type: "path", predicate });
|
|
10874
|
+
}
|
|
10875
|
+
function exists(expr) {
|
|
10876
|
+
return Object.freeze({ type: "exists", expr });
|
|
10877
|
+
}
|
|
10878
|
+
function ifExpr(cond) {
|
|
10879
|
+
return {
|
|
10880
|
+
then: (thenExpr) => ({
|
|
10881
|
+
else: (elseExpr) => {
|
|
10882
|
+
return Object.freeze({
|
|
10883
|
+
type: "if",
|
|
10884
|
+
cond,
|
|
10885
|
+
then: thenExpr,
|
|
10886
|
+
...elseExpr !== void 0 && { else: elseExpr }
|
|
10887
|
+
});
|
|
10888
|
+
},
|
|
10889
|
+
toExpression: () => Object.freeze({
|
|
10890
|
+
type: "if",
|
|
10891
|
+
cond,
|
|
10892
|
+
then: thenExpr
|
|
10893
|
+
})
|
|
10894
|
+
})
|
|
10895
|
+
};
|
|
10896
|
+
}
|
|
10897
|
+
function concat(...args) {
|
|
10898
|
+
return Object.freeze({ type: "concat", args });
|
|
10899
|
+
}
|
|
10900
|
+
function coalesce(...args) {
|
|
10901
|
+
return Object.freeze({ type: "coalesce", args });
|
|
10902
|
+
}
|
|
10903
|
+
var fileToDataUri = ifExpr(exists(path("file_storage://data_base64"))).then(concat(literal("data:"), coalesce(path("file_storage://file_type"), literal("image/png")), literal(";base64,"), path("file_storage://data_base64"))).else(focus());
|
|
10790
10904
|
|
|
10791
10905
|
// ../node_modules/.pnpm/auto-bind@5.0.1/node_modules/auto-bind/index.js
|
|
10792
10906
|
var getAllProperties = (object) => {
|
|
@@ -11136,13 +11250,18 @@ var Ad4mConnect = class extends EventTarget {
|
|
|
11136
11250
|
throw new Error("AD4M proxy mode requires a non-opaque parent origin. Ensure the host iframe is not sandboxed without allow-same-origin.");
|
|
11137
11251
|
}
|
|
11138
11252
|
const parentOrigin = event.origin;
|
|
11139
|
-
|
|
11253
|
+
class WsImpl extends PostMessageWebSocket {
|
|
11254
|
+
constructor(url) {
|
|
11255
|
+
super(url, parentOrigin);
|
|
11256
|
+
}
|
|
11257
|
+
}
|
|
11258
|
+
const fetchImpl = makePostMessageFetch(parentOrigin);
|
|
11140
11259
|
this.notifyConnectionChange("connecting");
|
|
11141
11260
|
this.ad4mClient = new Ad4mClient(
|
|
11142
11261
|
"http://proxy",
|
|
11143
11262
|
normalizedToken,
|
|
11144
11263
|
false,
|
|
11145
|
-
{ webSocketImpl:
|
|
11264
|
+
{ webSocketImpl: WsImpl, fetchImpl }
|
|
11146
11265
|
);
|
|
11147
11266
|
this.notifyConnectionChange("connected");
|
|
11148
11267
|
yield this.checkAuth();
|