@coasys/ad4m-connect 0.13.0-postmessage-ws-proxy.4 → 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/web.js CHANGED
@@ -1438,7 +1438,7 @@ function nextId() {
1438
1438
  return String(++_idCounter);
1439
1439
  }
1440
1440
  var ApiClient = class {
1441
- constructor(baseUrl, token, webSocketImpl) {
1441
+ constructor(baseUrl, token, webSocketImpl, fetchImpl) {
1442
1442
  this._ws = null;
1443
1443
  this._wsCallbacks = /* @__PURE__ */ new Set();
1444
1444
  this._pendingCalls = /* @__PURE__ */ new Map();
@@ -1451,6 +1451,7 @@ var ApiClient = class {
1451
1451
  this.baseUrl = baseUrl;
1452
1452
  this.token = token;
1453
1453
  this._webSocketImpl = webSocketImpl;
1454
+ this._fetchImpl = fetchImpl;
1454
1455
  }
1455
1456
  getBaseUrl() {
1456
1457
  return this.baseUrl;
@@ -1458,14 +1459,17 @@ var ApiClient = class {
1458
1459
  getToken() {
1459
1460
  return this.token;
1460
1461
  }
1462
+ doFetch(url, init) {
1463
+ return this._fetchImpl ? this._fetchImpl(url, init) : fetch(url, init);
1464
+ }
1461
1465
  setToken(token) {
1462
1466
  this.token = token;
1463
1467
  }
1464
1468
  _getWsUrl() {
1465
1469
  const wsBase = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://");
1466
1470
  const tokenParam = this.token ? `token=${encodeURIComponent(this.token)}` : "";
1467
- const path = "/api/v1/ws";
1468
- return tokenParam ? `${wsBase}${path}?${tokenParam}` : `${wsBase}${path}`;
1471
+ const path2 = "/api/v1/ws";
1472
+ return tokenParam ? `${wsBase}${path2}?${tokenParam}` : `${wsBase}${path2}`;
1469
1473
  }
1470
1474
  _ensureWs() {
1471
1475
  if (this._ws && (this._ws.readyState === 1 || this._ws.readyState === 0)) {
@@ -1890,9 +1894,9 @@ var Literal = class {
1890
1894
  __classPrivateFieldSet$b(l5, _Literal_url, url, "f");
1891
1895
  return l5;
1892
1896
  }
1893
- static from(literal) {
1897
+ static from(literal2) {
1894
1898
  const l5 = new Literal();
1895
- __classPrivateFieldSet$b(l5, _Literal_literal, literal, "f");
1899
+ __classPrivateFieldSet$b(l5, _Literal_literal, literal2, "f");
1896
1900
  return l5;
1897
1901
  }
1898
1902
  toUrl() {
@@ -2099,6 +2103,32 @@ function buildSDNA(subjectName, obj, properties, allRelationsMeta) {
2099
2103
  name: subjectName
2100
2104
  };
2101
2105
  }
2106
+ function isNodeExpression(v2) {
2107
+ if (typeof v2 !== "object" || v2 === null)
2108
+ return false;
2109
+ const obj = v2;
2110
+ const type = obj.type;
2111
+ switch (type) {
2112
+ case "focus":
2113
+ return typeof obj.type === "string";
2114
+ case "literal":
2115
+ return typeof obj.value === "string" || typeof obj.value === "number" || typeof obj.value === "boolean";
2116
+ case "path":
2117
+ return typeof obj.predicate === "string";
2118
+ case "exists":
2119
+ return isNodeExpression(obj.expr);
2120
+ case "if":
2121
+ return isNodeExpression(obj.cond) && isNodeExpression(obj.then) && (obj.else === void 0 || isNodeExpression(obj.else));
2122
+ case "concat":
2123
+ return Array.isArray(obj.args) && obj.args.every(isNodeExpression);
2124
+ case "coalesce":
2125
+ return Array.isArray(obj.args) && obj.args.every(isNodeExpression);
2126
+ case "function":
2127
+ return typeof obj.iri === "string" && Array.isArray(obj.args) && obj.args.every(isNodeExpression);
2128
+ default:
2129
+ return false;
2130
+ }
2131
+ }
2102
2132
  function extractNamespace(uri) {
2103
2133
  const hashIndex = uri.lastIndexOf("#");
2104
2134
  if (hashIndex !== -1) {
@@ -2359,7 +2389,7 @@ var SHACLShape = class {
2359
2389
  target: `literal:${prop.writable}`
2360
2390
  });
2361
2391
  }
2362
- if (prop.resolveLanguage) {
2392
+ if (prop.resolveLanguage != null) {
2363
2393
  links.push({
2364
2394
  source: propShapeId,
2365
2395
  predicate: "ad4m://resolveLanguage",
@@ -2450,6 +2480,13 @@ var SHACLShape = class {
2450
2480
  target: `literal:${prop.filter}`
2451
2481
  });
2452
2482
  }
2483
+ if (prop.transform && typeof prop.transform === "object") {
2484
+ links.push({
2485
+ source: propShapeId,
2486
+ predicate: "ad4m://transform",
2487
+ target: `literal:string:${JSON.stringify(prop.transform)}`
2488
+ });
2489
+ }
2453
2490
  }
2454
2491
  return links;
2455
2492
  }
@@ -2632,6 +2669,19 @@ var SHACLShape = class {
2632
2669
  val = val.substring(8);
2633
2670
  prop.filter = val === "true";
2634
2671
  }
2672
+ const transformLink = links.find((l5) => l5.source === propShapeId && l5.predicate === "ad4m://transform");
2673
+ if (transformLink) {
2674
+ const jsonStr = transformLink.target.replace(/^literal:\/\/string:|^literal:string:/, "");
2675
+ try {
2676
+ const parsed = JSON.parse(jsonStr);
2677
+ if (!isNodeExpression(parsed)) {
2678
+ throw new Error(`Invalid transform for property ${propShapeId}: payload is not a valid NodeExpression. Received: ${jsonStr}`);
2679
+ }
2680
+ prop.transform = parsed;
2681
+ } catch (e7) {
2682
+ throw new Error(`Failed to deserialize transform for property ${propShapeId}: ${e7 instanceof Error ? e7.message : String(e7)}. Payload: ${jsonStr}`);
2683
+ }
2684
+ }
2635
2685
  shape.addProperty(prop);
2636
2686
  }
2637
2687
  return shape;
@@ -2666,7 +2716,8 @@ var SHACLShape = class {
2666
2716
  target_class_name: p2.targetClassName,
2667
2717
  where_filter: p2.whereFilter,
2668
2718
  where_predicates: p2.wherePredicates,
2669
- filter: p2.filter
2719
+ filter: p2.filter,
2720
+ transform: p2.transform
2670
2721
  })),
2671
2722
  constructor_actions: this.constructor_actions,
2672
2723
  destructor_actions: this.destructor_actions
@@ -2675,6 +2726,9 @@ var SHACLShape = class {
2675
2726
  static fromJSON(json) {
2676
2727
  const shape = json.node_shape_uri ? new SHACLShape(json.node_shape_uri, json.target_class) : new SHACLShape(json.target_class);
2677
2728
  for (const p2 of json.properties || []) {
2729
+ if (p2.transform && !isNodeExpression(p2.transform)) {
2730
+ throw new Error(`Invalid transform for property ${p2.name}: payload is not a valid NodeExpression. Received: ${JSON.stringify(p2.transform)}`);
2731
+ }
2678
2732
  shape.addProperty({
2679
2733
  path: p2.path,
2680
2734
  name: p2.name,
@@ -2700,7 +2754,8 @@ var SHACLShape = class {
2700
2754
  targetClassName: p2.target_class_name,
2701
2755
  whereFilter: p2.where_filter,
2702
2756
  wherePredicates: p2.where_predicates,
2703
- filter: p2.filter
2757
+ filter: p2.filter,
2758
+ transform: p2.transform
2704
2759
  });
2705
2760
  }
2706
2761
  if (json.constructor_actions) {
@@ -2788,12 +2843,15 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
2788
2843
  if (propMeta.writable !== void 0) {
2789
2844
  propShape.writable = propMeta.writable;
2790
2845
  }
2791
- if (propMeta.resolveLanguage) {
2846
+ if (propMeta.resolveLanguage != null) {
2792
2847
  propShape.resolveLanguage = propMeta.resolveLanguage;
2793
2848
  }
2794
2849
  if (propMeta.getter) {
2795
2850
  propShape.getter = propMeta.getter;
2796
2851
  }
2852
+ if (propMeta.transform) {
2853
+ propShape.transform = propMeta.transform;
2854
+ }
2797
2855
  if (propMeta.prologSetter) {
2798
2856
  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.`);
2799
2857
  } else if (propMeta.writable && propMeta.through) {
@@ -9625,8 +9683,8 @@ function normalizeNamespaceString(namespace) {
9625
9683
  return "";
9626
9684
  if (namespace.includes("://")) {
9627
9685
  const [scheme, rest] = namespace.split("://");
9628
- const path = (rest || "").replace(/\/+$/, "");
9629
- return `${scheme}://${path}`;
9686
+ const path2 = (rest || "").replace(/\/+$/, "");
9687
+ return `${scheme}://${path2}`;
9630
9688
  } else {
9631
9689
  return namespace.replace(/\/+$/, "");
9632
9690
  }
@@ -10224,11 +10282,7 @@ var ModelQueryBuilder = class {
10224
10282
  const parseResults = (raw) => {
10225
10283
  return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
10226
10284
  };
10227
- const resolveAndReturn = async (instances) => {
10228
- await ctor.resolveNonLiteralProps(this.perspective, instances);
10229
- return instances;
10230
- };
10231
- const initialResults = await resolveAndReturn(parseResults(initialModelResult));
10285
+ const initialResults = parseResults(initialModelResult);
10232
10286
  let lastResultFingerprint = null;
10233
10287
  const buildFingerprint = (results) => {
10234
10288
  if (results.length === 0)
@@ -10238,20 +10292,16 @@ var ModelQueryBuilder = class {
10238
10292
  lastResultFingerprint = buildFingerprint(initialResults);
10239
10293
  const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
10240
10294
  try {
10241
- const parsed = parseResults(rawResult);
10242
- console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${parsed.length} instances`);
10243
- resolveAndReturn(parsed).then((results) => {
10244
- const fp = buildFingerprint(results);
10245
- if (fp === lastResultFingerprint) {
10246
- console.debug(`[ModelQueryBuilder.subscribe] Fingerprint unchanged, skipping callback`);
10247
- return;
10248
- }
10249
- console.debug(`[ModelQueryBuilder.subscribe] Fingerprint changed, calling callback with ${results.length} results`);
10250
- lastResultFingerprint = fp;
10251
- callback(results);
10252
- }).catch((e7) => {
10253
- console.error("Model subscription update resolve error:", e7);
10254
- });
10295
+ const results = parseResults(rawResult);
10296
+ console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${results.length} instances`);
10297
+ const fp = buildFingerprint(results);
10298
+ if (fp === lastResultFingerprint) {
10299
+ console.debug(`[ModelQueryBuilder.subscribe] Fingerprint unchanged, skipping callback`);
10300
+ return;
10301
+ }
10302
+ console.debug(`[ModelQueryBuilder.subscribe] Fingerprint changed, calling callback with ${results.length} results`);
10303
+ lastResultFingerprint = fp;
10304
+ callback(results);
10255
10305
  } catch (e7) {
10256
10306
  console.error("Model subscription update parse error:", e7);
10257
10307
  }
@@ -10465,27 +10515,6 @@ function normalizeValue(value) {
10465
10515
  }
10466
10516
  return value;
10467
10517
  }
10468
- function defaultFileDecode(resolved) {
10469
- if (resolved !== null && typeof resolved === "object" && "data_base64" in resolved) {
10470
- const fd = resolved;
10471
- let raw;
10472
- try {
10473
- raw = atob(fd.data_base64);
10474
- } catch {
10475
- return resolved;
10476
- }
10477
- const isJson = !fd.file_type || fd.file_type === "application/json";
10478
- if (isJson) {
10479
- try {
10480
- return JSON.parse(raw);
10481
- } catch {
10482
- return raw;
10483
- }
10484
- }
10485
- return raw;
10486
- }
10487
- return resolved;
10488
- }
10489
10518
  function jsonToModelInstance(ModelClass, perspective, json, include, properties) {
10490
10519
  const instance = new ModelClass(perspective, json.id || json.baseExpression);
10491
10520
  if (properties) {
@@ -10519,19 +10548,6 @@ function jsonToModelInstance(ModelClass, perspective, json, include, properties)
10519
10548
  }
10520
10549
  instance[key] = value;
10521
10550
  }
10522
- try {
10523
- const propsMeta = getPropertiesMetadata(ModelClass);
10524
- for (const [propName, opts] of Object.entries(propsMeta)) {
10525
- const o6 = opts;
10526
- if (typeof o6.transform !== "function" || !(propName in json))
10527
- continue;
10528
- if (o6.resolveLanguage != null && o6.resolveLanguage !== "literal")
10529
- continue;
10530
- instance[propName] = o6.transform(instance[propName]);
10531
- }
10532
- } catch (e7) {
10533
- console.debug("jsonToModelInstance: transform metadata unavailable:", e7);
10534
- }
10535
10551
  if (include) {
10536
10552
  const relMeta = getRelationsMetadata(ModelClass);
10537
10553
  for (const [relName, includeVal] of Object.entries(include)) {
@@ -10605,8 +10621,8 @@ var Ad4mModel = class {
10605
10621
  ...options.getter !== void 0 && { getter: options.getter },
10606
10622
  ...options.prologSetter !== void 0 && { prologSetter: options.prologSetter },
10607
10623
  ...options.local !== void 0 && { local: options.local },
10608
- ...options.transform !== void 0 && { transform: options.transform },
10609
- ...options.flag !== void 0 && { flag: options.flag }
10624
+ ...options.flag !== void 0 && { flag: options.flag },
10625
+ ...options.transform !== void 0 && { transform: options.transform }
10610
10626
  };
10611
10627
  }
10612
10628
  const relationsMetadata = {};
@@ -10908,44 +10924,12 @@ var Ad4mModel = class {
10908
10924
  return [];
10909
10925
  return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
10910
10926
  }
10911
- static async resolveNonLiteralProps(perspective, instances) {
10912
- const propsMeta = getPropertiesMetadata(this);
10913
- const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null && opts.resolveLanguage !== "literal");
10914
- if (resolveProps.length === 0)
10915
- return;
10916
- await Promise.all(instances.map(async (inst) => {
10917
- for (const [propName, opts] of resolveProps) {
10918
- const val = inst[propName];
10919
- const transform = opts.transform;
10920
- const applyTransform = (resolved) => typeof transform === "function" ? transform(resolved) : defaultFileDecode(resolved);
10921
- if (typeof val === "string" && val && !val.startsWith("literal:")) {
10922
- try {
10923
- const expression = await perspective.getExpression(val);
10924
- if (expression) {
10925
- let resolved;
10926
- try {
10927
- resolved = JSON.parse(expression.data);
10928
- } catch {
10929
- resolved = expression.data;
10930
- }
10931
- inst[propName] = applyTransform(resolved);
10932
- }
10933
- } catch (e7) {
10934
- console.debug(`resolveNonLiteralProps: resolution failed for '${propName}':`, e7);
10935
- }
10936
- } else if (val !== null && val !== void 0 && typeof val === "object") {
10937
- inst[propName] = applyTransform(val);
10938
- }
10939
- }
10940
- }));
10941
- }
10942
10927
  static async executeModelQuery(perspective, query = {}, classNameOverride) {
10943
10928
  const { className, queryJson } = this.prepareModelQueryParams(query, classNameOverride);
10944
10929
  const result = await perspective.modelQuery(className, queryJson);
10945
10930
  const instances = result.instances.map((json) => {
10946
10931
  return jsonToModelInstance(this, perspective, json, query.include, query.properties);
10947
10932
  });
10948
- await this.resolveNonLiteralProps(perspective, instances);
10949
10933
  const snapshotRelations = query.include ? Object.fromEntries(Object.entries(query.include).filter(([k2]) => !k2.startsWith("$"))) : void 0;
10950
10934
  for (const inst of instances) {
10951
10935
  inst.takeSnapshot(snapshotRelations && Object.keys(snapshotRelations).length > 0 ? snapshotRelations : void 0);
@@ -11408,6 +11392,44 @@ var _SmartLiteral_base;
11408
11392
  _SmartLiteral_perspective = /* @__PURE__ */ new WeakMap(), _SmartLiteral_base = /* @__PURE__ */ new WeakMap();
11409
11393
  var NeighbourhoodExpression = class extends ExpressionGeneric() {
11410
11394
  };
11395
+ function focus() {
11396
+ return Object.freeze({ type: "focus" });
11397
+ }
11398
+ function literal(value) {
11399
+ return Object.freeze({ type: "literal", value });
11400
+ }
11401
+ function path(predicate) {
11402
+ return Object.freeze({ type: "path", predicate });
11403
+ }
11404
+ function exists(expr) {
11405
+ return Object.freeze({ type: "exists", expr });
11406
+ }
11407
+ function ifExpr(cond) {
11408
+ return {
11409
+ then: (thenExpr) => ({
11410
+ else: (elseExpr) => {
11411
+ return Object.freeze({
11412
+ type: "if",
11413
+ cond,
11414
+ then: thenExpr,
11415
+ ...elseExpr !== void 0 && { else: elseExpr }
11416
+ });
11417
+ },
11418
+ toExpression: () => Object.freeze({
11419
+ type: "if",
11420
+ cond,
11421
+ then: thenExpr
11422
+ })
11423
+ })
11424
+ };
11425
+ }
11426
+ function concat(...args) {
11427
+ return Object.freeze({ type: "concat", args });
11428
+ }
11429
+ function coalesce(...args) {
11430
+ return Object.freeze({ type: "coalesce", args });
11431
+ }
11432
+ 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());
11411
11433
 
11412
11434
  // src/components/views/LocalAuthentication.ts
11413
11435
  var LocalAuthentication = class extends s4 {