@coasys/ad4m 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/lib/index.cjs +214 -145
- package/lib/index.js +205 -146
- package/lib/src/Ad4mClient.d.ts +1 -0
- package/lib/src/Ad4mClient.js +1 -1
- package/lib/src/ai/AIClient.js +1 -1
- package/lib/src/apiClient.d.ts +4 -1
- package/lib/src/apiClient.js +6 -1
- package/lib/src/index.d.ts +3 -0
- package/lib/src/index.js +3 -0
- package/lib/src/model/Ad4mModel.d.ts +0 -15
- package/lib/src/model/Ad4mModel.js +2 -118
- package/lib/src/model/ModelQueryBuilder.js +12 -22
- package/lib/src/model/decorators.d.ts +7 -4
- package/lib/src/model/shacl-gen.js +5 -1
- package/lib/src/model/types.d.ts +2 -1
- package/lib/src/shacl/NodeExpression.d.ts +44 -0
- package/lib/src/shacl/NodeExpression.js +39 -0
- package/lib/src/shacl/SHACLShape.d.ts +5 -0
- package/lib/src/shacl/SHACLShape.js +32 -1
- package/lib/src/shacl/builders.d.ts +58 -0
- package/lib/src/shacl/builders.js +76 -0
- package/lib/src/shacl/index.d.ts +36 -0
- package/lib/src/shacl/index.js +33 -0
- package/package.json +1 -1
- package/src/Ad4mClient.ts +2 -2
- package/src/ai/AIClient.ts +1 -1
- package/src/apiClient.ts +8 -1
- package/src/index.ts +3 -0
- package/src/model/Ad4mModel.test.ts +10 -10
- package/src/model/Ad4mModel.ts +2 -113
- package/src/model/ModelQueryBuilder.ts +12 -23
- package/src/model/decorators.ts +7 -4
- package/src/model/shacl-gen.ts +6 -1
- package/src/model/types.ts +2 -1
- package/src/shacl/NodeExpression.ts +54 -0
- package/src/shacl/SHACLShape.test.ts +62 -0
- package/src/shacl/SHACLShape.ts +48 -1
- package/src/shacl/builders.ts +86 -0
- package/src/shacl/index.ts +72 -0
package/lib/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ function nextId() {
|
|
|
23
23
|
return String(++_idCounter);
|
|
24
24
|
}
|
|
25
25
|
class ApiClient {
|
|
26
|
-
constructor(baseUrl, token, webSocketImpl) {
|
|
26
|
+
constructor(baseUrl, token, webSocketImpl, fetchImpl) {
|
|
27
27
|
// ── WebSocket RPC core ──────────────────────────────────────────────────
|
|
28
28
|
this._ws = null;
|
|
29
29
|
this._wsCallbacks = new Set();
|
|
@@ -37,9 +37,14 @@ class ApiClient {
|
|
|
37
37
|
this.baseUrl = baseUrl;
|
|
38
38
|
this.token = token;
|
|
39
39
|
this._webSocketImpl = webSocketImpl;
|
|
40
|
+
this._fetchImpl = fetchImpl;
|
|
40
41
|
}
|
|
41
42
|
getBaseUrl() { return this.baseUrl; }
|
|
42
43
|
getToken() { return this.token; }
|
|
44
|
+
/** Perform an HTTP request, using an injected fetch implementation if provided. */
|
|
45
|
+
doFetch(url, init) {
|
|
46
|
+
return this._fetchImpl ? this._fetchImpl(url, init) : fetch(url, init);
|
|
47
|
+
}
|
|
43
48
|
setToken(token) {
|
|
44
49
|
this.token = token;
|
|
45
50
|
}
|
|
@@ -958,6 +963,46 @@ function buildSDNA(subjectName, obj, properties, allRelationsMeta) {
|
|
|
958
963
|
};
|
|
959
964
|
}
|
|
960
965
|
|
|
966
|
+
/**
|
|
967
|
+
* SHACL-AF Node Expressions for property transforms.
|
|
968
|
+
*
|
|
969
|
+
* A `NodeExpression` is a JSON-serializable tree that describes how to transform
|
|
970
|
+
* a resolved property value. Unlike JS lambdas, these are portable, inspectable,
|
|
971
|
+
* and can be executed in the Rust model query engine.
|
|
972
|
+
*
|
|
973
|
+
* Each expression is a tagged union that evaluates to a `Value` (JSON-compatible).
|
|
974
|
+
*/
|
|
975
|
+
/**
|
|
976
|
+
* Type guard to check if a value is a valid NodeExpression.
|
|
977
|
+
*/
|
|
978
|
+
function isNodeExpression(v) {
|
|
979
|
+
if (typeof v !== 'object' || v === null)
|
|
980
|
+
return false;
|
|
981
|
+
const obj = v;
|
|
982
|
+
const type = obj.type;
|
|
983
|
+
switch (type) {
|
|
984
|
+
case 'focus':
|
|
985
|
+
return typeof obj.type === 'string';
|
|
986
|
+
case 'literal':
|
|
987
|
+
return typeof obj.value === 'string' || typeof obj.value === 'number' || typeof obj.value === 'boolean';
|
|
988
|
+
case 'path':
|
|
989
|
+
return typeof obj.predicate === 'string';
|
|
990
|
+
case 'exists':
|
|
991
|
+
return isNodeExpression(obj.expr);
|
|
992
|
+
case 'if':
|
|
993
|
+
return isNodeExpression(obj.cond) && isNodeExpression(obj.then) &&
|
|
994
|
+
(obj.else === undefined || isNodeExpression(obj.else));
|
|
995
|
+
case 'concat':
|
|
996
|
+
return Array.isArray(obj.args) && obj.args.every(isNodeExpression);
|
|
997
|
+
case 'coalesce':
|
|
998
|
+
return Array.isArray(obj.args) && obj.args.every(isNodeExpression);
|
|
999
|
+
case 'function':
|
|
1000
|
+
return typeof obj.iri === 'string' && Array.isArray(obj.args) && obj.args.every(isNodeExpression);
|
|
1001
|
+
default:
|
|
1002
|
+
return false;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
961
1006
|
/**
|
|
962
1007
|
* Extract namespace from a URI
|
|
963
1008
|
* Examples:
|
|
@@ -1288,7 +1333,7 @@ class SHACLShape {
|
|
|
1288
1333
|
target: `literal:${prop.writable}`
|
|
1289
1334
|
});
|
|
1290
1335
|
}
|
|
1291
|
-
if (prop.resolveLanguage) {
|
|
1336
|
+
if (prop.resolveLanguage != null) {
|
|
1292
1337
|
links.push({
|
|
1293
1338
|
source: propShapeId,
|
|
1294
1339
|
predicate: "ad4m://resolveLanguage",
|
|
@@ -1380,6 +1425,13 @@ class SHACLShape {
|
|
|
1380
1425
|
target: `literal:${prop.filter}`
|
|
1381
1426
|
});
|
|
1382
1427
|
}
|
|
1428
|
+
if (prop.transform && typeof prop.transform === 'object') {
|
|
1429
|
+
links.push({
|
|
1430
|
+
source: propShapeId,
|
|
1431
|
+
predicate: "ad4m://transform",
|
|
1432
|
+
target: `literal:string:${JSON.stringify(prop.transform)}`
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1383
1435
|
}
|
|
1384
1436
|
return links;
|
|
1385
1437
|
}
|
|
@@ -1599,6 +1651,22 @@ class SHACLShape {
|
|
|
1599
1651
|
val = val.substring(8);
|
|
1600
1652
|
prop.filter = val === 'true';
|
|
1601
1653
|
}
|
|
1654
|
+
const transformLink = links.find(l => l.source === propShapeId && l.predicate === "ad4m://transform");
|
|
1655
|
+
if (transformLink) {
|
|
1656
|
+
const jsonStr = transformLink.target.replace(/^literal:\/\/string:|^literal:string:/, '');
|
|
1657
|
+
try {
|
|
1658
|
+
const parsed = JSON.parse(jsonStr);
|
|
1659
|
+
if (!isNodeExpression(parsed)) {
|
|
1660
|
+
throw new Error(`Invalid transform for property ${propShapeId}: ` +
|
|
1661
|
+
`payload is not a valid NodeExpression. Received: ${jsonStr}`);
|
|
1662
|
+
}
|
|
1663
|
+
prop.transform = parsed;
|
|
1664
|
+
}
|
|
1665
|
+
catch (e) {
|
|
1666
|
+
throw new Error(`Failed to deserialize transform for property ${propShapeId}: ` +
|
|
1667
|
+
`${e instanceof Error ? e.message : String(e)}. Payload: ${jsonStr}`);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1602
1670
|
shape.addProperty(prop);
|
|
1603
1671
|
}
|
|
1604
1672
|
return shape;
|
|
@@ -1640,6 +1708,7 @@ class SHACLShape {
|
|
|
1640
1708
|
where_filter: p.whereFilter,
|
|
1641
1709
|
where_predicates: p.wherePredicates,
|
|
1642
1710
|
filter: p.filter,
|
|
1711
|
+
transform: p.transform,
|
|
1643
1712
|
})),
|
|
1644
1713
|
constructor_actions: this.constructor_actions,
|
|
1645
1714
|
destructor_actions: this.destructor_actions,
|
|
@@ -1653,6 +1722,11 @@ class SHACLShape {
|
|
|
1653
1722
|
? new SHACLShape(json.node_shape_uri, json.target_class)
|
|
1654
1723
|
: new SHACLShape(json.target_class);
|
|
1655
1724
|
for (const p of json.properties || []) {
|
|
1725
|
+
// Validate transform if present
|
|
1726
|
+
if (p.transform && !isNodeExpression(p.transform)) {
|
|
1727
|
+
throw new Error(`Invalid transform for property ${p.name}: ` +
|
|
1728
|
+
`payload is not a valid NodeExpression. Received: ${JSON.stringify(p.transform)}`);
|
|
1729
|
+
}
|
|
1656
1730
|
shape.addProperty({
|
|
1657
1731
|
path: p.path,
|
|
1658
1732
|
name: p.name,
|
|
@@ -1679,6 +1753,7 @@ class SHACLShape {
|
|
|
1679
1753
|
whereFilter: p.where_filter,
|
|
1680
1754
|
wherePredicates: p.where_predicates,
|
|
1681
1755
|
filter: p.filter,
|
|
1756
|
+
transform: p.transform,
|
|
1682
1757
|
});
|
|
1683
1758
|
}
|
|
1684
1759
|
if (json.constructor_actions) {
|
|
@@ -1805,7 +1880,7 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
|
|
|
1805
1880
|
if (propMeta.writable !== undefined) {
|
|
1806
1881
|
propShape.writable = propMeta.writable;
|
|
1807
1882
|
}
|
|
1808
|
-
if (propMeta.resolveLanguage) {
|
|
1883
|
+
if (propMeta.resolveLanguage != null) {
|
|
1809
1884
|
propShape.resolveLanguage = propMeta.resolveLanguage;
|
|
1810
1885
|
}
|
|
1811
1886
|
// Explicit getter SPARQL — the executor evaluates this when
|
|
@@ -1814,6 +1889,10 @@ function buildSHACL(subjectName, target, properties, allRelationsMeta, conforman
|
|
|
1814
1889
|
if (propMeta.getter) {
|
|
1815
1890
|
propShape.getter = propMeta.getter;
|
|
1816
1891
|
}
|
|
1892
|
+
// Serializable transform expression (SHACL-AF Node Expression)
|
|
1893
|
+
if (propMeta.transform) {
|
|
1894
|
+
propShape.transform = propMeta.transform;
|
|
1895
|
+
}
|
|
1817
1896
|
// ── Setter actions ──────────────────────────────────────────────
|
|
1818
1897
|
if (propMeta.prologSetter) {
|
|
1819
1898
|
console.warn(`[SHACL Generation] Custom Prolog setter for property '${propName}' in class '${subjectName}' is not yet supported. ` +
|
|
@@ -13796,7 +13875,7 @@ class AIClient {
|
|
|
13796
13875
|
// Use slice to get only the relevant portion of the underlying ArrayBuffer
|
|
13797
13876
|
// (Float32Array may be a view over a larger buffer)
|
|
13798
13877
|
const bodyBuffer = typedAudio.buffer.slice(typedAudio.byteOffset, typedAudio.byteOffset + typedAudio.byteLength);
|
|
13799
|
-
const response = await
|
|
13878
|
+
const response = await __classPrivateFieldGet$2(this, _AIClient_apiClient, "f").doFetch(`${baseUrl}/api/v1/ai/transcription/feed`, {
|
|
13800
13879
|
method: 'POST',
|
|
13801
13880
|
headers: {
|
|
13802
13881
|
'Content-Type': 'application/octet-stream',
|
|
@@ -14963,14 +15042,8 @@ class ModelQueryBuilder {
|
|
|
14963
15042
|
const parseResults = (raw) => {
|
|
14964
15043
|
return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
|
|
14965
15044
|
};
|
|
14966
|
-
//
|
|
14967
|
-
|
|
14968
|
-
const resolveAndReturn = async (instances) => {
|
|
14969
|
-
await ctor.resolveNonLiteralProps(this.perspective, instances);
|
|
14970
|
-
return instances;
|
|
14971
|
-
};
|
|
14972
|
-
// Parse initial results (with non-literal resolution)
|
|
14973
|
-
const initialResults = await resolveAndReturn(parseResults(initialModelResult));
|
|
15045
|
+
// Transforms are now applied by the Rust executor during hydration
|
|
15046
|
+
const initialResults = parseResults(initialModelResult);
|
|
14974
15047
|
// Track last emitted result fingerprint to suppress duplicate callbacks
|
|
14975
15048
|
let lastResultFingerprint = null;
|
|
14976
15049
|
const buildFingerprint = (results) => {
|
|
@@ -14983,20 +15056,16 @@ class ModelQueryBuilder {
|
|
|
14983
15056
|
// When Rust re-runs the model query and finds changed results, it pushes them.
|
|
14984
15057
|
const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
|
|
14985
15058
|
try {
|
|
14986
|
-
const
|
|
14987
|
-
console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${
|
|
14988
|
-
|
|
14989
|
-
|
|
14990
|
-
|
|
14991
|
-
|
|
14992
|
-
|
|
14993
|
-
|
|
14994
|
-
|
|
14995
|
-
|
|
14996
|
-
callback(results);
|
|
14997
|
-
}).catch((e) => {
|
|
14998
|
-
console.error('Model subscription update resolve error:', e);
|
|
14999
|
-
});
|
|
15059
|
+
const results = parseResults(rawResult);
|
|
15060
|
+
console.debug(`[ModelQueryBuilder.subscribe] Update received for ${subscriptionId}: ${results.length} instances`);
|
|
15061
|
+
const fp = buildFingerprint(results);
|
|
15062
|
+
if (fp === lastResultFingerprint) {
|
|
15063
|
+
console.debug(`[ModelQueryBuilder.subscribe] Fingerprint unchanged, skipping callback`);
|
|
15064
|
+
return;
|
|
15065
|
+
}
|
|
15066
|
+
console.debug(`[ModelQueryBuilder.subscribe] Fingerprint changed, calling callback with ${results.length} results`);
|
|
15067
|
+
lastResultFingerprint = fp;
|
|
15068
|
+
callback(results);
|
|
15000
15069
|
}
|
|
15001
15070
|
catch (e) {
|
|
15002
15071
|
console.error('Model subscription update parse error:', e);
|
|
@@ -15351,48 +15420,6 @@ function normalizeValue(value) {
|
|
|
15351
15420
|
return value;
|
|
15352
15421
|
}
|
|
15353
15422
|
|
|
15354
|
-
// ---------------------------------------------------------------------------
|
|
15355
|
-
// Default decoder for file-storage (non-literal resolveLanguage) properties
|
|
15356
|
-
// ---------------------------------------------------------------------------
|
|
15357
|
-
/**
|
|
15358
|
-
* When the Rust executor resolves a non-literal expression it may return a
|
|
15359
|
-
* `FileData`-shaped object (`{ data_base64, file_type, ... }`) rather than a
|
|
15360
|
-
* raw URI string. If the model class has no custom `transform` registered
|
|
15361
|
-
* (e.g. it was synthesised from a SHACL shape at runtime) we still want to
|
|
15362
|
-
* decode the content rather than passing raw `FileData` to callers.
|
|
15363
|
-
*
|
|
15364
|
-
* Decoding rules (mirrors the JS `decodeFileAsJson` / `decodeFileAsString` helpers):
|
|
15365
|
-
* - `application/json` (default when `file_type` is absent) → JSON.parse
|
|
15366
|
-
* - anything else → raw decoded string
|
|
15367
|
-
*
|
|
15368
|
-
* If `resolved` is not a `FileData` object the value is returned unchanged so
|
|
15369
|
-
* that callers can use this as a safe unconditional fallback.
|
|
15370
|
-
*/
|
|
15371
|
-
function defaultFileDecode(resolved) {
|
|
15372
|
-
if (resolved !== null &&
|
|
15373
|
-
typeof resolved === 'object' &&
|
|
15374
|
-
'data_base64' in resolved) {
|
|
15375
|
-
const fd = resolved;
|
|
15376
|
-
let raw;
|
|
15377
|
-
try {
|
|
15378
|
-
raw = atob(fd.data_base64);
|
|
15379
|
-
}
|
|
15380
|
-
catch {
|
|
15381
|
-
return resolved; // malformed base64 — keep as-is
|
|
15382
|
-
}
|
|
15383
|
-
const isJson = !fd.file_type || fd.file_type === 'application/json';
|
|
15384
|
-
if (isJson) {
|
|
15385
|
-
try {
|
|
15386
|
-
return JSON.parse(raw);
|
|
15387
|
-
}
|
|
15388
|
-
catch {
|
|
15389
|
-
return raw;
|
|
15390
|
-
}
|
|
15391
|
-
}
|
|
15392
|
-
return raw;
|
|
15393
|
-
}
|
|
15394
|
-
return resolved;
|
|
15395
|
-
}
|
|
15396
15423
|
// ---------------------------------------------------------------------------
|
|
15397
15424
|
// Helpers for Rust-side include resolution
|
|
15398
15425
|
// ---------------------------------------------------------------------------
|
|
@@ -15440,24 +15467,6 @@ function jsonToModelInstance(ModelClass, perspective, json, include, properties)
|
|
|
15440
15467
|
}
|
|
15441
15468
|
instance[key] = value;
|
|
15442
15469
|
}
|
|
15443
|
-
// Apply property transform functions from decorators (only for literal-resolved
|
|
15444
|
-
// or no-resolveLanguage properties; non-literal properties are resolved + transformed
|
|
15445
|
-
// asynchronously in executeModelQuery).
|
|
15446
|
-
try {
|
|
15447
|
-
const propsMeta = getPropertiesMetadata(ModelClass);
|
|
15448
|
-
for (const [propName, opts] of Object.entries(propsMeta)) {
|
|
15449
|
-
const o = opts;
|
|
15450
|
-
if (typeof o.transform !== 'function' || !(propName in json))
|
|
15451
|
-
continue;
|
|
15452
|
-
// Skip non-literal resolveLanguage props — they need async expression resolution first
|
|
15453
|
-
if (o.resolveLanguage != null && o.resolveLanguage !== 'literal')
|
|
15454
|
-
continue;
|
|
15455
|
-
instance[propName] = o.transform(instance[propName]);
|
|
15456
|
-
}
|
|
15457
|
-
}
|
|
15458
|
-
catch (e) {
|
|
15459
|
-
console.debug('jsonToModelInstance: transform metadata unavailable:', e);
|
|
15460
|
-
}
|
|
15461
15470
|
// Recursively convert included relation values to class instances
|
|
15462
15471
|
if (include) {
|
|
15463
15472
|
const relMeta = getRelationsMetadata(ModelClass);
|
|
@@ -15695,8 +15704,8 @@ class Ad4mModel {
|
|
|
15695
15704
|
...(options.getter !== undefined && { getter: options.getter }),
|
|
15696
15705
|
...(options.prologSetter !== undefined && { prologSetter: options.prologSetter }),
|
|
15697
15706
|
...(options.local !== undefined && { local: options.local }),
|
|
15698
|
-
...(options.
|
|
15699
|
-
...(options.
|
|
15707
|
+
...(options.flag !== undefined && { flag: options.flag }),
|
|
15708
|
+
...(options.transform !== undefined && { transform: options.transform })
|
|
15700
15709
|
};
|
|
15701
15710
|
}
|
|
15702
15711
|
// Extract relations (relations) from WeakMap registry
|
|
@@ -16173,57 +16182,6 @@ class Ad4mModel {
|
|
|
16173
16182
|
return [];
|
|
16174
16183
|
return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
|
|
16175
16184
|
}
|
|
16176
|
-
/**
|
|
16177
|
-
* Resolve non-literal (file-language) properties on an array of already-constructed
|
|
16178
|
-
* model instances. Handles two cases:
|
|
16179
|
-
*
|
|
16180
|
-
* 1. The Rust executor returned a raw URI string → fetch via `getExpression` then apply transform.
|
|
16181
|
-
* 2. The Rust executor already resolved the expression and returned a `FileData` object
|
|
16182
|
-
* (happens when the perspective backend eagerly fetches file content) → apply transform
|
|
16183
|
-
* (or `defaultFileDecode` if no transform is registered on the class, e.g. for SHACL-
|
|
16184
|
-
* synthesised model classes).
|
|
16185
|
-
*
|
|
16186
|
-
* Extracted as a public static so `ModelQueryBuilder.subscribe()` can reuse it without
|
|
16187
|
-
* duplicating logic or introducing a circular dependency.
|
|
16188
|
-
* @internal
|
|
16189
|
-
*/
|
|
16190
|
-
static async resolveNonLiteralProps(perspective, instances) {
|
|
16191
|
-
const propsMeta = getPropertiesMetadata(this);
|
|
16192
|
-
const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null &&
|
|
16193
|
-
opts.resolveLanguage !== 'literal');
|
|
16194
|
-
if (resolveProps.length === 0)
|
|
16195
|
-
return;
|
|
16196
|
-
await Promise.all(instances.map(async (inst) => {
|
|
16197
|
-
for (const [propName, opts] of resolveProps) {
|
|
16198
|
-
const val = inst[propName];
|
|
16199
|
-
const transform = opts.transform;
|
|
16200
|
-
const applyTransform = (resolved) => typeof transform === 'function' ? transform(resolved) : defaultFileDecode(resolved);
|
|
16201
|
-
if (typeof val === 'string' && val && !val.startsWith('literal:')) {
|
|
16202
|
-
// Case 1: raw URI — fetch from language runtime
|
|
16203
|
-
try {
|
|
16204
|
-
const expression = await perspective.getExpression(val);
|
|
16205
|
-
if (expression) {
|
|
16206
|
-
let resolved;
|
|
16207
|
-
try {
|
|
16208
|
-
resolved = JSON.parse(expression.data);
|
|
16209
|
-
}
|
|
16210
|
-
catch {
|
|
16211
|
-
resolved = expression.data;
|
|
16212
|
-
}
|
|
16213
|
-
inst[propName] = applyTransform(resolved);
|
|
16214
|
-
}
|
|
16215
|
-
}
|
|
16216
|
-
catch (e) {
|
|
16217
|
-
console.debug(`resolveNonLiteralProps: resolution failed for '${propName}':`, e);
|
|
16218
|
-
}
|
|
16219
|
-
}
|
|
16220
|
-
else if (val !== null && val !== undefined && typeof val === 'object') {
|
|
16221
|
-
// Case 2: already resolved by Rust — apply transform / default decode
|
|
16222
|
-
inst[propName] = applyTransform(val);
|
|
16223
|
-
}
|
|
16224
|
-
}
|
|
16225
|
-
}));
|
|
16226
|
-
}
|
|
16227
16185
|
// instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
|
|
16228
16186
|
/**
|
|
16229
16187
|
* Execute a model query via the executor-side endpoint.
|
|
@@ -16243,11 +16201,6 @@ class Ad4mModel {
|
|
|
16243
16201
|
const instances = result.instances.map((json) => {
|
|
16244
16202
|
return jsonToModelInstance(this, perspective, json, query.include, query.properties);
|
|
16245
16203
|
});
|
|
16246
|
-
// Resolve non-literal expressions (e.g. file languages where the stored
|
|
16247
|
-
// value is a content-addressed hash that must be fetched from the language
|
|
16248
|
-
// runtime). The Rust endpoint may return either a raw target URI (string)
|
|
16249
|
-
// or an already-resolved FileData object — both cases are handled here.
|
|
16250
|
-
await this.resolveNonLiteralProps(perspective, instances);
|
|
16251
16204
|
// Take snapshots for dirty tracking (exclude $-prefixed projection keys)
|
|
16252
16205
|
const snapshotRelations = query.include
|
|
16253
16206
|
? Object.fromEntries(Object.entries(query.include).filter(([k]) => !k.startsWith('$')))
|
|
@@ -17263,7 +17216,7 @@ class Ad4mClient {
|
|
|
17263
17216
|
_Ad4mClient_aiClient.set(this, void 0);
|
|
17264
17217
|
__classPrivateFieldSet$1(this, _Ad4mClient_baseUrl, baseUrl, "f");
|
|
17265
17218
|
__classPrivateFieldSet$1(this, _Ad4mClient_token, token, "f");
|
|
17266
|
-
__classPrivateFieldSet$1(this, _Ad4mClient_apiClient, new ApiClient(baseUrl, token, options?.webSocketImpl), "f");
|
|
17219
|
+
__classPrivateFieldSet$1(this, _Ad4mClient_apiClient, new ApiClient(baseUrl, token, options?.webSocketImpl, options?.fetchImpl), "f");
|
|
17267
17220
|
__classPrivateFieldSet$1(this, _Ad4mClient_agentClient, new AgentClient(baseUrl, token, subscribe, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17268
17221
|
__classPrivateFieldSet$1(this, _Ad4mClient_expressionClient, new ExpressionClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
17269
17222
|
__classPrivateFieldSet$1(this, _Ad4mClient_languageClient, new LanguageClient(baseUrl, token, __classPrivateFieldGet$1(this, _Ad4mClient_apiClient, "f")), "f");
|
|
@@ -18044,6 +17997,112 @@ class ModelInput {
|
|
|
18044
17997
|
class VoiceActivityParamsInput {
|
|
18045
17998
|
}
|
|
18046
17999
|
|
|
18000
|
+
/**
|
|
18001
|
+
* Builder functions for SHACL-AF Node Expressions.
|
|
18002
|
+
*
|
|
18003
|
+
* These functions construct JSON-serializable expression trees for property transforms.
|
|
18004
|
+
* All builders return frozen objects to prevent accidental mutation.
|
|
18005
|
+
*/
|
|
18006
|
+
/**
|
|
18007
|
+
* Identity expression: pass the focus node through unchanged.
|
|
18008
|
+
*/
|
|
18009
|
+
function focus() {
|
|
18010
|
+
return Object.freeze({ type: 'focus' });
|
|
18011
|
+
}
|
|
18012
|
+
/**
|
|
18013
|
+
* Literal constant expression.
|
|
18014
|
+
*/
|
|
18015
|
+
function literal(value) {
|
|
18016
|
+
return Object.freeze({ type: 'literal', value });
|
|
18017
|
+
}
|
|
18018
|
+
/**
|
|
18019
|
+
* Path expression: navigate to a property on the resolved object.
|
|
18020
|
+
* The predicate can be a full IRI (e.g., "file_storage://data_base64")
|
|
18021
|
+
* or a simple property name. The Rust evaluator will strip the namespace.
|
|
18022
|
+
*/
|
|
18023
|
+
function path(predicate) {
|
|
18024
|
+
return Object.freeze({ type: 'path', predicate });
|
|
18025
|
+
}
|
|
18026
|
+
/**
|
|
18027
|
+
* Existence check: returns true if the inner expression is non-null and non-empty.
|
|
18028
|
+
*/
|
|
18029
|
+
function exists(expr) {
|
|
18030
|
+
return Object.freeze({ type: 'exists', expr });
|
|
18031
|
+
}
|
|
18032
|
+
/**
|
|
18033
|
+
* Conditional expression with optional else branch.
|
|
18034
|
+
* Returns a chainable builder that supports `.then()` and `.else()`.
|
|
18035
|
+
*/
|
|
18036
|
+
function ifExpr(cond) {
|
|
18037
|
+
return {
|
|
18038
|
+
then: (thenExpr) => ({
|
|
18039
|
+
else: (elseExpr) => {
|
|
18040
|
+
return Object.freeze({
|
|
18041
|
+
type: 'if',
|
|
18042
|
+
cond,
|
|
18043
|
+
then: thenExpr,
|
|
18044
|
+
...(elseExpr !== undefined && { else: elseExpr }),
|
|
18045
|
+
});
|
|
18046
|
+
},
|
|
18047
|
+
// Allow chaining without explicit else()
|
|
18048
|
+
toExpression: () => Object.freeze({
|
|
18049
|
+
type: 'if',
|
|
18050
|
+
cond,
|
|
18051
|
+
then: thenExpr,
|
|
18052
|
+
}),
|
|
18053
|
+
}),
|
|
18054
|
+
};
|
|
18055
|
+
}
|
|
18056
|
+
/**
|
|
18057
|
+
* String concatenation: joins evaluated arguments as strings.
|
|
18058
|
+
* Null/undefined arguments are skipped.
|
|
18059
|
+
*/
|
|
18060
|
+
function concat(...args) {
|
|
18061
|
+
return Object.freeze({ type: 'concat', args });
|
|
18062
|
+
}
|
|
18063
|
+
/**
|
|
18064
|
+
* Coalesce: returns the first non-null evaluated argument.
|
|
18065
|
+
*/
|
|
18066
|
+
function coalesce(...args) {
|
|
18067
|
+
return Object.freeze({ type: 'coalesce', args });
|
|
18068
|
+
}
|
|
18069
|
+
/**
|
|
18070
|
+
* Function call: invoke a named transform function by IRI.
|
|
18071
|
+
* Primarily used for built-in functions like "ad4m://fn/defaultFileDecode".
|
|
18072
|
+
*/
|
|
18073
|
+
function fn(iri, args = []) {
|
|
18074
|
+
return Object.freeze({ type: 'function', iri, args });
|
|
18075
|
+
}
|
|
18076
|
+
|
|
18077
|
+
/**
|
|
18078
|
+
* SHACL-AF Transform DSL — public API
|
|
18079
|
+
*
|
|
18080
|
+
* Re-exports builder functions and provides common built-in transforms.
|
|
18081
|
+
*/
|
|
18082
|
+
/**
|
|
18083
|
+
* Built-in transform: FileData → data: URI
|
|
18084
|
+
*
|
|
18085
|
+
* Converts a file stored via FILE_STORAGE_LANGUAGE into a data: URL.
|
|
18086
|
+
* If the object has a `data_base64` field, returns:
|
|
18087
|
+
* `data:{file_type};base64,{data_base64}`
|
|
18088
|
+
* Otherwise passes through the input unchanged.
|
|
18089
|
+
*
|
|
18090
|
+
* This is the Rust equivalent of the JS `defaultFileDecode` function.
|
|
18091
|
+
*
|
|
18092
|
+
* Usage:
|
|
18093
|
+
* ```typescript
|
|
18094
|
+
* @Property({
|
|
18095
|
+
* through: 'we://image',
|
|
18096
|
+
* resolveLanguage: FILE_STORAGE_LANGUAGE,
|
|
18097
|
+
* transform: fileToDataUri,
|
|
18098
|
+
* })
|
|
18099
|
+
* avatar?: string;
|
|
18100
|
+
* ```
|
|
18101
|
+
*/
|
|
18102
|
+
const fileToDataUri = ifExpr(exists(path('file_storage://data_base64')))
|
|
18103
|
+
.then(concat(literal('data:'), coalesce(path('file_storage://file_type'), literal('image/png')), literal(';base64,'), path('file_storage://data_base64')))
|
|
18104
|
+
.else(focus());
|
|
18105
|
+
|
|
18047
18106
|
exports.AIClient = AIClient;
|
|
18048
18107
|
exports.AIModel = Model;
|
|
18049
18108
|
exports.AIModelLoadingStatus = AIModelLoadingStatus;
|
|
@@ -18157,12 +18216,18 @@ exports.buildSPARQLQuery = buildSPARQLQuery;
|
|
|
18157
18216
|
exports.buildWhereCondition = buildWhereCondition;
|
|
18158
18217
|
exports.capSentence = capSentence;
|
|
18159
18218
|
exports.clearQueryCache = clearQueryCache;
|
|
18219
|
+
exports.coalesce = coalesce;
|
|
18160
18220
|
exports.compileWhereClause = compileWhereClause;
|
|
18221
|
+
exports.concat = concat;
|
|
18161
18222
|
exports.createPersistentCache = createPersistentCache;
|
|
18162
18223
|
exports.determineNamespace = determineNamespace;
|
|
18163
18224
|
exports.determinePredicate = determinePredicate;
|
|
18164
18225
|
exports.escapeQueryString = escapeQueryString;
|
|
18226
|
+
exports.exists = exists;
|
|
18165
18227
|
exports.exprRef2String = exprRef2String;
|
|
18228
|
+
exports.fileToDataUri = fileToDataUri;
|
|
18229
|
+
exports.fn = fn;
|
|
18230
|
+
exports.focus = focus;
|
|
18166
18231
|
exports.formatList = formatList;
|
|
18167
18232
|
exports.formatQueryValue = formatQueryValue;
|
|
18168
18233
|
exports.formatSPARQLValue = formatSPARQLValue;
|
|
@@ -18173,15 +18238,18 @@ exports.getPropertiesMetadata = getPropertiesMetadata;
|
|
|
18173
18238
|
exports.getPropertyOption = getPropertyOption;
|
|
18174
18239
|
exports.getRelationsMetadata = getRelationsMetadata;
|
|
18175
18240
|
exports.hasJsOnlyWhereFilters = hasJsOnlyWhereFilters;
|
|
18241
|
+
exports.ifExpr = ifExpr;
|
|
18176
18242
|
exports.invalidatePerspectiveCache = invalidatePerspectiveCache;
|
|
18177
18243
|
exports.isArrayType = isArrayType;
|
|
18178
18244
|
exports.isExpression = isExpression;
|
|
18179
18245
|
exports.isIncludeProjection = isIncludeProjection;
|
|
18180
18246
|
exports.isLink = isLink;
|
|
18247
|
+
exports.isNodeExpression = isNodeExpression;
|
|
18181
18248
|
exports.isNumericType = isNumericType;
|
|
18182
18249
|
exports.isObjectType = isObjectType;
|
|
18183
18250
|
exports.isSchemaType = isSchemaType;
|
|
18184
18251
|
exports.linkEqual = linkEqual;
|
|
18252
|
+
exports.literal = literal;
|
|
18185
18253
|
exports.normalizeNamespaceString = normalizeNamespaceString;
|
|
18186
18254
|
exports.normalizeSchemaType = normalizeSchemaType;
|
|
18187
18255
|
exports.normalizeValue = normalizeValue;
|
|
@@ -18190,6 +18258,7 @@ exports.parseLit = parseLit;
|
|
|
18190
18258
|
exports.parseLitBoolean = parseLitBoolean;
|
|
18191
18259
|
exports.parseLitNumber = parseLitNumber;
|
|
18192
18260
|
exports.parseSparqlCount = parseSparqlCount;
|
|
18261
|
+
exports.path = path;
|
|
18193
18262
|
exports.queryCacheSize = queryCacheSize;
|
|
18194
18263
|
exports.resolveParentPredicate = resolveParentPredicate;
|
|
18195
18264
|
exports.setCachedResult = setCachedResult;
|