@coasys/ad4m-connect 0.13.0-postmessage-ws-proxy.1 → 0.13.0-postmessage-ws-proxy.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/dist/core.js CHANGED
@@ -83,7 +83,7 @@ var _PostMessageWebSocket = class {
83
83
  this._connectTimeout = null;
84
84
  this._targetOrigin = targetOrigin;
85
85
  this._messageHandler = (e) => {
86
- var _a, _b, _c, _d;
86
+ var _a, _b, _c, _d, _e;
87
87
  if (e.source !== window.parent)
88
88
  return;
89
89
  if (e.origin !== this._targetOrigin)
@@ -103,13 +103,16 @@ var _PostMessageWebSocket = class {
103
103
  }
104
104
  if (msg.type === "AD4M_PROXY_WS_ERROR") {
105
105
  this._clearConnectTimeout();
106
+ this.readyState = _PostMessageWebSocket.CLOSED;
107
+ window.removeEventListener("message", this._messageHandler);
106
108
  (_c = this.onerror) == null ? void 0 : _c.call(this, new Event("error"));
109
+ (_d = this.onclose) == null ? void 0 : _d.call(this, new CloseEvent("close", { code: 1006, reason: "WebSocket error", wasClean: false }));
107
110
  return;
108
111
  }
109
112
  if (msg.type === "AD4M_PROXY_WS_CLOSED") {
110
113
  this._clearConnectTimeout();
111
114
  this.readyState = 3;
112
- (_d = this.onclose) == null ? void 0 : _d.call(
115
+ (_e = this.onclose) == null ? void 0 : _e.call(
113
116
  this,
114
117
  new CloseEvent("close", {
115
118
  code: typeof msg.code === "number" ? msg.code : 1e3,
@@ -1147,6 +1150,41 @@ var SHACLShape = class {
1147
1150
  target: `literal:string:${JSON.stringify(prop.in)}`
1148
1151
  });
1149
1152
  }
1153
+ if (prop.relationKind) {
1154
+ links.push({
1155
+ source: propShapeId,
1156
+ predicate: "ad4m://relationKind",
1157
+ target: `literal:string:${prop.relationKind}`
1158
+ });
1159
+ }
1160
+ if (prop.targetClassName) {
1161
+ links.push({
1162
+ source: propShapeId,
1163
+ predicate: "ad4m://targetClassName",
1164
+ target: `literal:string:${prop.targetClassName}`
1165
+ });
1166
+ }
1167
+ if (prop.whereFilter !== void 0 && prop.whereFilter !== null) {
1168
+ links.push({
1169
+ source: propShapeId,
1170
+ predicate: "ad4m://whereFilter",
1171
+ target: `literal:string:${JSON.stringify(prop.whereFilter)}`
1172
+ });
1173
+ }
1174
+ if (prop.wherePredicates && Object.keys(prop.wherePredicates).length > 0) {
1175
+ links.push({
1176
+ source: propShapeId,
1177
+ predicate: "ad4m://wherePredicates",
1178
+ target: `literal:string:${JSON.stringify(prop.wherePredicates)}`
1179
+ });
1180
+ }
1181
+ if (prop.filter !== void 0) {
1182
+ links.push({
1183
+ source: propShapeId,
1184
+ predicate: "ad4m://filter",
1185
+ target: `literal:${prop.filter}`
1186
+ });
1187
+ }
1150
1188
  }
1151
1189
  return links;
1152
1190
  }
@@ -1295,6 +1333,40 @@ var SHACLShape = class {
1295
1333
  } catch (e) {
1296
1334
  }
1297
1335
  }
1336
+ const relationKindLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://relationKind");
1337
+ if (relationKindLink) {
1338
+ const val = relationKindLink.target.replace(/^literal:\/\/string:|^literal:string:/, "");
1339
+ if (val === "hasMany" || val === "hasOne" || val === "belongsToOne" || val === "belongsToMany") {
1340
+ prop.relationKind = val;
1341
+ }
1342
+ }
1343
+ const targetClassNameLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://targetClassName");
1344
+ if (targetClassNameLink) {
1345
+ prop.targetClassName = targetClassNameLink.target.replace(/^literal:\/\/string:|^literal:string:/, "");
1346
+ }
1347
+ const whereFilterLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://whereFilter");
1348
+ if (whereFilterLink) {
1349
+ try {
1350
+ const jsonStr = whereFilterLink.target.replace(/^literal:\/\/string:|^literal:string:/, "");
1351
+ prop.whereFilter = JSON.parse(jsonStr);
1352
+ } catch (e) {
1353
+ }
1354
+ }
1355
+ const wherePredicatesLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://wherePredicates");
1356
+ if (wherePredicatesLink) {
1357
+ try {
1358
+ const jsonStr = wherePredicatesLink.target.replace(/^literal:\/\/string:|^literal:string:/, "");
1359
+ prop.wherePredicates = JSON.parse(jsonStr);
1360
+ } catch (e) {
1361
+ }
1362
+ }
1363
+ const filterLink = links.find((l) => l.source === propShapeId && l.predicate === "ad4m://filter");
1364
+ if (filterLink) {
1365
+ let val = filterLink.target.replace(/^literal:\/\/|^literal:/, "");
1366
+ if (val.startsWith("boolean:"))
1367
+ val = val.substring(8);
1368
+ prop.filter = val === "true";
1369
+ }
1298
1370
  shape.addProperty(prop);
1299
1371
  }
1300
1372
  return shape;
@@ -1324,7 +1396,12 @@ var SHACLShape = class {
1324
1396
  getter: p.getter,
1325
1397
  conformance_conditions: p.conformanceConditions,
1326
1398
  class: p.class,
1327
- in: p.in
1399
+ in: p.in,
1400
+ relation_kind: p.relationKind,
1401
+ target_class_name: p.targetClassName,
1402
+ where_filter: p.whereFilter,
1403
+ where_predicates: p.wherePredicates,
1404
+ filter: p.filter
1328
1405
  })),
1329
1406
  constructor_actions: this.constructor_actions,
1330
1407
  destructor_actions: this.destructor_actions
@@ -1353,7 +1430,12 @@ var SHACLShape = class {
1353
1430
  getter: p.getter,
1354
1431
  conformanceConditions: p.conformance_conditions,
1355
1432
  class: p.class,
1356
- in: p.in
1433
+ in: p.in,
1434
+ relationKind: p.relation_kind,
1435
+ targetClassName: p.target_class_name,
1436
+ whereFilter: p.where_filter,
1437
+ wherePredicates: p.where_predicates,
1438
+ filter: p.filter
1357
1439
  });
1358
1440
  }
1359
1441
  if (json.constructor_actions) {
@@ -1370,96 +1452,9 @@ var SHACLShape = class {
1370
1452
  return shape;
1371
1453
  }
1372
1454
  };
1373
- function escapeQueryString(value) {
1374
- return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
1375
- }
1376
- function buildWhereCondition(predicate, condition, opts) {
1377
- const escapedPredicate = escapeQueryString(predicate);
1378
- const isLiteral = !opts?.resolveLanguage || opts.resolveLanguage === "literal";
1379
- const varSuffix = opts?.varIndex ?? 0;
1380
- function formatValue(v) {
1381
- if (typeof v === "string") {
1382
- return isLiteral ? `<literal:string:${escapeQueryString(v)}>` : `<${escapeQueryString(v)}>`;
1383
- }
1384
- return `<literal:string:${v}>`;
1385
- }
1386
- function formatLiteralFilter(varName, v) {
1387
- const raw = escapeQueryString(String(v));
1388
- const encoded = encodeURIComponent(String(v)).replace(/!/g, "%21").replace(/'/g, "%27").replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/\*/g, "%2A");
1389
- if (typeof v === "string") {
1390
- return `FILTER(STR(${varName}) = "${raw}" || STR(${varName}) = "literal:string:${encoded}")`;
1391
- } else if (typeof v === "number") {
1392
- return `FILTER(STR(${varName}) = "${v}" || STR(${varName}) = "literal:number:${v}")`;
1393
- } else if (typeof v === "boolean") {
1394
- return `FILTER(STR(${varName}) = "${v}" || STR(${varName}) = "literal:boolean:${v}")`;
1395
- }
1396
- return `FILTER(STR(${varName}) = "${raw}")`;
1397
- }
1398
- if (Array.isArray(condition)) {
1399
- if (isLiteral) {
1400
- const varName = `?_wc${varSuffix}`;
1401
- const inValues = condition.flatMap((v) => {
1402
- const raw = escapeQueryString(String(v));
1403
- const encoded = encodeURIComponent(String(v)).replace(/!/g, "%21").replace(/'/g, "%27").replace(/\(/g, "%28").replace(/\)/g, "%29").replace(/\*/g, "%2A");
1404
- return [`"${raw}"`, `"literal:string:${encoded}"`];
1405
- }).join(", ");
1406
- return `?target <${escapedPredicate}> ${varName} . FILTER(STR(${varName}) IN (${inValues}))`;
1407
- }
1408
- const formattedValues = condition.map(formatValue).join(", ");
1409
- return `FILTER EXISTS { ?target <${escapedPredicate}> ?_val . FILTER(?_val IN (${formattedValues})) }`;
1410
- } else if (typeof condition === "object" && condition !== null) {
1411
- const ops = condition;
1412
- const parts = [];
1413
- if (ops.not !== void 0) {
1414
- if (Array.isArray(ops.not)) {
1415
- const formattedValues = ops.not.map((v) => formatValue(v)).join(", ");
1416
- parts.push(`FILTER NOT EXISTS { ?target <${escapedPredicate}> ?_nval . FILTER(?_nval IN (${formattedValues})) }`);
1417
- } else {
1418
- parts.push(`FILTER NOT EXISTS { ?target <${escapedPredicate}> ${formatValue(ops.not)} }`);
1419
- }
1420
- }
1421
- const hasComparisonOps = ops.gt !== void 0 || ops.gte !== void 0 || ops.lt !== void 0 || ops.lte !== void 0 || ops.between !== void 0 || ops.contains !== void 0;
1422
- if (hasComparisonOps) {
1423
- parts.push(`FILTER EXISTS { ?target <${escapedPredicate}> ?_cmp }`);
1424
- }
1425
- return parts.join(" ");
1426
- } else {
1427
- if (isLiteral) {
1428
- const varName = `?_wc${varSuffix}`;
1429
- return `?target <${escapedPredicate}> ${varName} . ${formatLiteralFilter(varName, condition)}`;
1430
- }
1431
- return `?target <${escapedPredicate}> ${formatValue(condition)} .`;
1432
- }
1433
- }
1434
- function compileWhereClause(where, metadata) {
1435
- const conditions = [];
1436
- for (const [propertyName, condition] of Object.entries(where)) {
1437
- if (["id", "author", "timestamp"].includes(propertyName))
1438
- continue;
1439
- let predicate;
1440
- let resolveLanguage;
1441
- if (metadata) {
1442
- const propMeta = metadata.properties[propertyName];
1443
- if (propMeta) {
1444
- predicate = propMeta.predicate;
1445
- resolveLanguage = propMeta.resolveLanguage;
1446
- } else {
1447
- predicate = propertyName;
1448
- }
1449
- } else {
1450
- predicate = propertyName;
1451
- }
1452
- const cond = buildWhereCondition(predicate, condition, { resolveLanguage, varIndex: conditions.length });
1453
- if (cond) {
1454
- conditions.push(cond);
1455
- }
1456
- }
1457
- return conditions;
1458
- }
1459
1455
  function buildSHACL(subjectName, target, properties, allRelationsMeta, conformanceFilterFn) {
1460
1456
  const obj = target.prototype;
1461
1457
  let namespace = "ad4m://";
1462
- const relations = Object.fromEntries(Object.entries(allRelationsMeta).filter(([, r]) => r.kind === "hasMany" || r.kind === "belongsToMany"));
1463
1458
  if (Object.keys(properties).length > 0) {
1464
1459
  const firstProp = properties[Object.keys(properties)[0]];
1465
1460
  if (firstProp.through) {
@@ -1468,8 +1463,8 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
1468
1463
  namespace = match[1];
1469
1464
  }
1470
1465
  }
1471
- } else if (Object.keys(relations).length > 0) {
1472
- const firstRel = relations[Object.keys(relations)[0]];
1466
+ } else if (Object.keys(allRelationsMeta).length > 0) {
1467
+ const firstRel = allRelationsMeta[Object.keys(allRelationsMeta)[0]];
1473
1468
  if (firstRel.predicate) {
1474
1469
  const match = firstRel.predicate.match(/^([^:]+:\/\/)/);
1475
1470
  if (match) {
@@ -1531,6 +1526,9 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
1531
1526
  if (propMeta.resolveLanguage) {
1532
1527
  propShape.resolveLanguage = propMeta.resolveLanguage;
1533
1528
  }
1529
+ if (propMeta.getter) {
1530
+ propShape.getter = propMeta.getter;
1531
+ }
1534
1532
  if (propMeta.prologSetter) {
1535
1533
  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.`);
1536
1534
  } else if (propMeta.writable && propMeta.through) {
@@ -1562,46 +1560,47 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
1562
1560
  }
1563
1561
  shape.addProperty(propShape);
1564
1562
  }
1565
- for (const relName in relations) {
1566
- const relMeta = relations[relName];
1567
- if (!relMeta.predicate)
1563
+ for (const relName in allRelationsMeta) {
1564
+ const relMeta = allRelationsMeta[relName];
1565
+ if (!relMeta.predicate && !relMeta.getter)
1568
1566
  continue;
1567
+ const synthesizedPath = relMeta.predicate || `ad4m://getter/${subjectName}/${relName}`;
1569
1568
  const relShape = {
1570
1569
  name: relName,
1571
- path: relMeta.predicate
1570
+ path: synthesizedPath
1572
1571
  };
1573
1572
  relShape.nodeKind = "IRI";
1573
+ relShape.relationKind = relMeta.kind;
1574
+ if (relMeta.kind === "hasOne" || relMeta.kind === "belongsToOne") {
1575
+ relShape.maxCount = 1;
1576
+ } else if (relMeta.maxCount !== void 0) {
1577
+ relShape.maxCount = relMeta.maxCount;
1578
+ }
1579
+ if (relMeta.filter === false) {
1580
+ relShape.filter = false;
1581
+ }
1574
1582
  if (relMeta.local !== void 0) {
1575
1583
  relShape.local = relMeta.local;
1576
1584
  }
1577
- relShape.adder = [{
1578
- action: "addLink",
1579
- source: "this",
1580
- predicate: relMeta.predicate,
1581
- target: "value",
1582
- ...relMeta.local && { local: true }
1583
- }];
1584
- relShape.remover = [{
1585
- action: "removeLink",
1586
- source: "this",
1587
- predicate: relMeta.predicate,
1588
- target: "value",
1589
- ...relMeta.local && { local: true }
1590
- }];
1585
+ if (relMeta.predicate) {
1586
+ relShape.adder = [{
1587
+ action: "addLink",
1588
+ source: "this",
1589
+ predicate: relMeta.predicate,
1590
+ target: "value",
1591
+ ...relMeta.local && { local: true }
1592
+ }];
1593
+ relShape.remover = [{
1594
+ action: "removeLink",
1595
+ source: "this",
1596
+ predicate: relMeta.predicate,
1597
+ target: "value",
1598
+ ...relMeta.local && { local: true }
1599
+ }];
1600
+ }
1591
1601
  if (relMeta.getter) {
1592
1602
  relShape.getter = relMeta.getter;
1593
- } else if (relMeta.where) {
1594
- try {
1595
- const TargetClass = relMeta.target?.();
1596
- const targetMetadata = TargetClass ? TargetClass.getModelMetadata?.() ?? null : null;
1597
- const conditions = compileWhereClause(relMeta.where, targetMetadata);
1598
- if (conditions.length > 0) {
1599
- const escapedPredicate = escapeQueryString(relMeta.predicate);
1600
- relShape.getter = `SELECT ?target WHERE { <Base> <${escapedPredicate}> ?target . ${conditions.join(" ")} }`;
1601
- }
1602
- } catch (e) {
1603
- }
1604
- } else if (relMeta.target && relMeta.filter !== false) {
1603
+ } else if (relMeta.target && relMeta.filter !== false && relMeta.kind !== "belongsToOne" && relMeta.kind !== "belongsToMany") {
1605
1604
  const targetThunk = relMeta.target;
1606
1605
  const predicate = relMeta.predicate;
1607
1606
  let resolved = false;
@@ -1653,6 +1652,37 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
1653
1652
  if (targetSHACL?.shape?.nodeShapeUri) {
1654
1653
  relShape.class = targetSHACL.shape.nodeShapeUri;
1655
1654
  }
1655
+ if (targetSHACL?.name) {
1656
+ relShape.targetClassName = targetSHACL.name;
1657
+ } else {
1658
+ const targetProto = TargetClass.prototype;
1659
+ if (targetProto?.className) {
1660
+ relShape.targetClassName = targetProto.className;
1661
+ }
1662
+ }
1663
+ } catch (e) {
1664
+ console.warn(`[shacl-gen] Failed to resolve target class for relation "${subjectName}.${relName}": ${e instanceof Error ? e.message : String(e)}`);
1665
+ }
1666
+ }
1667
+ if (relMeta.where) {
1668
+ relShape.whereFilter = relMeta.where;
1669
+ try {
1670
+ const TargetClass = relMeta.target?.();
1671
+ const targetMetadata = TargetClass ? TargetClass.getModelMetadata?.() ?? null : null;
1672
+ if (targetMetadata?.properties) {
1673
+ const predicates = {};
1674
+ for (const propName of Object.keys(relMeta.where)) {
1675
+ if (["id", "author", "timestamp"].includes(propName))
1676
+ continue;
1677
+ const propMeta = targetMetadata.properties[propName];
1678
+ if (propMeta?.predicate) {
1679
+ predicates[propName] = propMeta.predicate;
1680
+ }
1681
+ }
1682
+ if (Object.keys(predicates).length > 0) {
1683
+ relShape.wherePredicates = predicates;
1684
+ }
1685
+ }
1656
1686
  } catch (e) {
1657
1687
  }
1658
1688
  }
@@ -1665,6 +1695,9 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
1665
1695
  name: subjectName
1666
1696
  };
1667
1697
  }
1698
+ function escapeQueryString(value) {
1699
+ return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
1700
+ }
1668
1701
  var propertyRegistry = /* @__PURE__ */ new WeakMap();
1669
1702
  var relationRegistry = /* @__PURE__ */ new WeakMap();
1670
1703
  var propertiesMetadataCache = /* @__PURE__ */ new WeakMap();
@@ -2291,14 +2324,14 @@ var PerspectiveProxy = class {
2291
2324
  setCachedResult(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, query, result);
2292
2325
  return result;
2293
2326
  }
2294
- async modelQuery(className, queryJson, shapeJson) {
2295
- return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
2327
+ async modelQuery(className, queryJson) {
2328
+ return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson);
2296
2329
  }
2297
- async evaluateGetters(className, instanceIds, shapeJson, propertyNames) {
2298
- return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").evaluateGetters(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, instanceIds, shapeJson, propertyNames);
2330
+ async evaluateGetters(className, instanceIds, propertyNames) {
2331
+ return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").evaluateGetters(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, instanceIds, propertyNames);
2299
2332
  }
2300
- async modelSubscribe(className, queryJson, shapeJson) {
2301
- return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, shapeJson);
2333
+ async modelSubscribe(className, queryJson) {
2334
+ return await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").modelSubscribe(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson);
2302
2335
  }
2303
2336
  async add(link, status = "shared", batchId) {
2304
2337
  const result = await __classPrivateFieldGet$a(this, _PerspectiveProxy_client, "f").addLink(__classPrivateFieldGet$a(this, _PerspectiveProxy_handle, "f").uuid, link, status, batchId);
@@ -3345,22 +3378,21 @@ var PerspectiveClient = class {
3345
3378
  }
3346
3379
  return __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call("perspective.disposeQuery", { uuid, subscriptionId });
3347
3380
  }
3348
- async modelQuery(uuid, className, queryJson, shapeJson) {
3349
- const resultJson = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call("perspective.modelQuery", { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson });
3381
+ async modelQuery(uuid, className, queryJson) {
3382
+ const resultJson = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call("perspective.modelQuery", { uuid, class_name: className, query_json: queryJson });
3350
3383
  return JSON.parse(resultJson);
3351
3384
  }
3352
- async evaluateGetters(uuid, className, instanceIds, shapeJson, propertyNames) {
3385
+ async evaluateGetters(uuid, className, instanceIds, propertyNames) {
3353
3386
  const resultJson = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call("perspective.evaluateGetters", {
3354
3387
  uuid,
3355
3388
  class_name: className,
3356
3389
  instance_ids: instanceIds,
3357
- shape_json: shapeJson,
3358
3390
  ...propertyNames && { property_names: propertyNames }
3359
3391
  });
3360
3392
  return JSON.parse(resultJson);
3361
3393
  }
3362
- async modelSubscribe(uuid, className, queryJson, shapeJson) {
3363
- const response = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call("perspective.modelSubscribe", { uuid, class_name: className, query_json: queryJson, shape_json: shapeJson });
3394
+ async modelSubscribe(uuid, className, queryJson) {
3395
+ const response = await __classPrivateFieldGet$9(this, _PerspectiveClient_apiClient, "f").call("perspective.modelSubscribe", { uuid, class_name: className, query_json: queryJson });
3364
3396
  return {
3365
3397
  subscriptionId: response.subscription_id,
3366
3398
  result: JSON.parse(response.result)
@@ -9465,9 +9497,6 @@ var ModelQueryBuilder = class {
9465
9497
  this.modelClassName = className;
9466
9498
  return this;
9467
9499
  }
9468
- engine(_eng) {
9469
- return this;
9470
- }
9471
9500
  async get() {
9472
9501
  return await this.executeSparqlQuery();
9473
9502
  }
@@ -9488,8 +9517,8 @@ var ModelQueryBuilder = class {
9488
9517
  async subscribe(callback) {
9489
9518
  this.dispose();
9490
9519
  const ctor = this.ctor;
9491
- const { className, queryJson, shapeJson } = ctor.prepareModelQueryParams(this.queryParams, this.modelClassName);
9492
- const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
9520
+ const { className, queryJson } = ctor.prepareModelQueryParams(this.queryParams, this.modelClassName);
9521
+ const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson);
9493
9522
  const parseResults = (raw) => {
9494
9523
  return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
9495
9524
  };
@@ -9586,8 +9615,8 @@ var ModelQueryBuilder = class {
9586
9615
  async countSubscribe(callback) {
9587
9616
  this.dispose();
9588
9617
  const countParams = { ...this.queryParams, limit: 0 };
9589
- const { className, queryJson, shapeJson } = this.ctor.prepareModelQueryParams(countParams, this.modelClassName);
9590
- const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
9618
+ const { className, queryJson } = this.ctor.prepareModelQueryParams(countParams, this.modelClassName);
9619
+ const { subscriptionId, result: initialModelResult } = await this.perspective.modelSubscribe(className, queryJson);
9591
9620
  const parseCount = (raw) => {
9592
9621
  const data = typeof raw === "string" ? JSON.parse(raw) : raw;
9593
9622
  return data.totalCount ?? 0;
@@ -9662,8 +9691,8 @@ var ModelQueryBuilder = class {
9662
9691
  const subscriptionParams = { ...this.queryParams || {} };
9663
9692
  delete subscriptionParams.limit;
9664
9693
  delete subscriptionParams.offset;
9665
- const { className, queryJson, shapeJson } = ctor.prepareModelQueryParams(subscriptionParams, this.modelClassName);
9666
- const { subscriptionId } = await this.perspective.modelSubscribe(className, queryJson, shapeJson);
9694
+ const { className, queryJson } = ctor.prepareModelQueryParams(subscriptionParams, this.modelClassName);
9695
+ const { subscriptionId } = await this.perspective.modelSubscribe(className, queryJson);
9667
9696
  const paginatedQuery = {
9668
9697
  ...this.queryParams || {},
9669
9698
  limit: pageSize,
@@ -9755,34 +9784,6 @@ function defaultFileDecode(resolved) {
9755
9784
  }
9756
9785
  return resolved;
9757
9786
  }
9758
- function enrichShapeForIncludes(metadata, include, allRelMeta) {
9759
- for (const [relName, includeVal] of Object.entries(include)) {
9760
- if (!includeVal)
9761
- continue;
9762
- const meta = allRelMeta[relName];
9763
- if (!meta?.target)
9764
- continue;
9765
- const TargetClass = meta.target();
9766
- const targetMeta = JSON.parse(JSON.stringify(TargetClass.getModelMetadata()));
9767
- if (!metadata.relations[relName]) {
9768
- metadata.relations[relName] = {
9769
- name: relName,
9770
- predicate: meta.predicate,
9771
- direction: meta.kind === "belongsToMany" || meta.kind === "belongsToOne" ? "reverse" : "forward"
9772
- };
9773
- }
9774
- const rel = metadata.relations[relName];
9775
- rel.kind = meta.kind;
9776
- rel.maxCount = meta.maxCount;
9777
- rel.targetShape = targetMeta;
9778
- rel.targetClassName = targetMeta.className;
9779
- const nested = typeof includeVal === "object" && includeVal !== null ? includeVal.include : void 0;
9780
- if (nested) {
9781
- const targetRelMeta = getRelationsMetadata(TargetClass);
9782
- enrichShapeForIncludes(targetMeta, nested, targetRelMeta);
9783
- }
9784
- }
9785
- }
9786
9787
  function jsonToModelInstance(ModelClass, perspective, json, include, properties) {
9787
9788
  const instance = new ModelClass(perspective, json.id || json.baseExpression);
9788
9789
  if (properties) {
@@ -10165,12 +10166,12 @@ var Ad4mModel = class {
10165
10166
  const allRelMeta = getRelationsMetadata(this);
10166
10167
  for (const [, proj] of Object.entries(projections)) {
10167
10168
  const relMeta = allRelMeta[proj.from];
10168
- if (!proj.targetShape && relMeta?.target) {
10169
+ if (!proj.targetClassName && relMeta?.target) {
10169
10170
  try {
10170
10171
  const TargetClass = relMeta.target();
10171
10172
  const targetMeta = TargetClass.getModelMetadata?.();
10172
- if (targetMeta) {
10173
- proj.targetShape = targetMeta;
10173
+ if (targetMeta?.className) {
10174
+ proj.targetClassName = targetMeta.className;
10174
10175
  }
10175
10176
  } catch (e) {
10176
10177
  console.debug(`prepareModelQueryParams: target class unavailable for projection:`, e);
@@ -10192,56 +10193,9 @@ var Ad4mModel = class {
10192
10193
  if (query.count !== void 0)
10193
10194
  queryInput.count = query.count;
10194
10195
  queryInput.deepQuery = query.deepQuery ?? true;
10195
- if (queryInput.include) {
10196
- const allRelMeta = getRelationsMetadata(this);
10197
- enrichShapeForIncludes(metadata, queryInput.include, allRelMeta);
10198
- }
10199
- {
10200
- const allRelMeta = getRelationsMetadata(this);
10201
- for (const [relName, relMeta] of Object.entries(metadata.relations)) {
10202
- const rel = relMeta;
10203
- if (rel.getter || rel.direction === "reverse" || rel.filter === false)
10204
- continue;
10205
- const meta = allRelMeta[relName];
10206
- if (!meta?.target)
10207
- continue;
10208
- try {
10209
- const TargetClass = meta.target();
10210
- const filter = buildConformanceFilter(meta.predicate, TargetClass);
10211
- if (filter) {
10212
- rel.getter = filter.getter;
10213
- }
10214
- if (rel.where) {
10215
- try {
10216
- const targetMetadata = TargetClass.getModelMetadata?.() ?? null;
10217
- if (targetMetadata) {
10218
- const predicates = {};
10219
- for (const propName of Object.keys(rel.where)) {
10220
- if (["id", "author", "timestamp"].includes(propName))
10221
- continue;
10222
- const propMeta = targetMetadata.properties[propName];
10223
- if (propMeta?.predicate) {
10224
- predicates[propName] = propMeta.predicate;
10225
- }
10226
- }
10227
- if (Object.keys(predicates).length > 0) {
10228
- rel.whereFilter = rel.where;
10229
- rel.wherePredicates = predicates;
10230
- }
10231
- }
10232
- } catch (e) {
10233
- console.debug(`prepareModelQueryParams: target metadata unavailable for relation '${relName}':`, e);
10234
- }
10235
- }
10236
- } catch (e) {
10237
- console.debug(`prepareModelQueryParams: target class unavailable for relation '${relName}':`, e);
10238
- }
10239
- }
10240
- }
10241
10196
  return {
10242
10197
  className,
10243
10198
  queryJson: JSON.stringify(queryInput),
10244
- shapeJson: JSON.stringify(metadata),
10245
10199
  metadata
10246
10200
  };
10247
10201
  }
@@ -10284,8 +10238,8 @@ var Ad4mModel = class {
10284
10238
  }));
10285
10239
  }
10286
10240
  static async executeModelQuery(perspective, query = {}, classNameOverride) {
10287
- const { className, queryJson, shapeJson } = this.prepareModelQueryParams(query, classNameOverride);
10288
- const result = await perspective.modelQuery(className, queryJson, shapeJson);
10241
+ const { className, queryJson } = this.prepareModelQueryParams(query, classNameOverride);
10242
+ const result = await perspective.modelQuery(className, queryJson);
10289
10243
  const instances = result.instances.map((json) => {
10290
10244
  return jsonToModelInstance(this, perspective, json, query.include, query.properties);
10291
10245
  });
@@ -10299,28 +10253,30 @@ var Ad4mModel = class {
10299
10253
  totalCount: result.totalCount
10300
10254
  };
10301
10255
  }
10302
- static async findAll(perspective, query = {}, _engine) {
10303
- if (query.properties && query.properties.length === 0) {
10256
+ static async findAll(perspective, query) {
10257
+ const q = query ?? {};
10258
+ if (q.properties && q.properties.length === 0) {
10304
10259
  throw new Error("properties[] must not be empty \u2014 omit the field to return all properties, or specify at least one field name");
10305
10260
  }
10306
- const { results } = await this.executeModelQuery(perspective, query);
10261
+ const { results } = await this.executeModelQuery(perspective, q);
10307
10262
  return results;
10308
10263
  }
10309
- static async findOne(perspective, query = {}, _engine) {
10310
- const limitedQuery = { ...query, limit: 1 };
10264
+ static async findOne(perspective, query) {
10265
+ const limitedQuery = { ...query ?? {}, limit: 1 };
10311
10266
  const results = await this.findAll(perspective, limitedQuery);
10312
10267
  return results[0] ?? null;
10313
10268
  }
10314
- static async findAllAndCount(perspective, query = {}, _engine) {
10315
- return await this.executeModelQuery(perspective, query);
10269
+ static async findAllAndCount(perspective, query) {
10270
+ const out = await this.executeModelQuery(perspective, query ?? {});
10271
+ return out;
10316
10272
  }
10317
- static async paginate(perspective, pageSize, pageNumber, query, _engine) {
10318
- const paginationQuery = { ...query || {}, limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
10273
+ static async paginate(perspective, pageSize, pageNumber, query) {
10274
+ const paginationQuery = { ...query ?? {}, limit: pageSize, offset: pageSize * (pageNumber - 1), count: true };
10319
10275
  const { results, totalCount } = await this.executeModelQuery(perspective, paginationQuery);
10320
10276
  return { results, totalCount, pageSize, pageNumber };
10321
10277
  }
10322
- static async count(perspective, query = {}) {
10323
- const { totalCount } = await this.executeModelQuery(perspective, { ...query, limit: 0 });
10278
+ static async count(perspective, query) {
10279
+ const { totalCount } = await this.executeModelQuery(perspective, { ...query ?? {}, limit: 0 });
10324
10280
  return totalCount;
10325
10281
  }
10326
10282
  async setProperty(key, value, batchId) {
@@ -10516,26 +10472,8 @@ var Ad4mModel = class {
10516
10472
  if (instances.length === 0)
10517
10473
  return;
10518
10474
  const metadata = this.getModelMetadata();
10519
- const allRelMeta = getRelationsMetadata(this);
10520
- for (const [relName, relMeta] of Object.entries(metadata.relations)) {
10521
- const rel = relMeta;
10522
- if (rel.getter || rel.direction === "reverse" || rel.filter === false)
10523
- continue;
10524
- const meta = allRelMeta[relName];
10525
- if (!meta?.target)
10526
- continue;
10527
- try {
10528
- const TargetClass = meta.target();
10529
- const filter = buildConformanceFilter(meta.predicate, TargetClass);
10530
- if (filter)
10531
- rel.getter = filter.getter;
10532
- } catch (e) {
10533
- console.debug(`evaluateGetters: target class unavailable for relation '${relName}':`, e);
10534
- }
10535
- }
10536
- const shapeJson = JSON.stringify(metadata);
10537
10475
  const instanceIds = instances.map((inst) => inst.id || inst._baseExpression);
10538
- const result = await perspective.evaluateGetters(metadata.className, instanceIds, shapeJson, propertyNames);
10476
+ const result = await perspective.evaluateGetters(metadata.className, instanceIds, propertyNames);
10539
10477
  const evaluatedPropertyNames = [];
10540
10478
  for (const [propName, propMeta] of Object.entries(metadata.properties)) {
10541
10479
  if (propMeta.getter) {
@@ -10669,7 +10607,7 @@ var Ad4mModel = class {
10669
10607
  return result;
10670
10608
  }
10671
10609
  static query(perspective, query) {
10672
- return new ModelQueryBuilder(perspective, this, query);
10610
+ return new ModelQueryBuilder(perspective, this, query ?? {});
10673
10611
  }
10674
10612
  static fromJSONSchema(schema, options) {
10675
10613
  return buildModelFromJSONSchema(this, schema, options);