@coasys/ad4m 0.13.0-test-6 → 0.13.0-test-7

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.
Files changed (39) hide show
  1. package/lib/index.cjs +111 -36
  2. package/lib/index.js +111 -36
  3. package/lib/src/model/Ad4mModel.d.ts +15 -0
  4. package/lib/src/model/Ad4mModel.js +94 -28
  5. package/lib/src/model/Ad4mModel.test.js +1434 -688
  6. package/lib/src/model/ModelQueryBuilder.js +17 -8
  7. package/lib/src/model/Subject.js +6 -6
  8. package/lib/src/model/hydration-batch.d.ts +34 -0
  9. package/lib/src/model/hydration-batch.js +147 -0
  10. package/lib/src/model/hydration-batching.test.d.ts +7 -0
  11. package/lib/src/model/hydration-batching.test.js +456 -0
  12. package/lib/src/model/model-manifest.d.ts +41 -0
  13. package/lib/src/model/model-manifest.js +11 -0
  14. package/lib/src/model/query-cache.test.d.ts +1 -0
  15. package/lib/src/model/query-cache.test.js +43 -0
  16. package/lib/src/model/query-sparql-batch.d.ts +17 -0
  17. package/lib/src/model/query-sparql-batch.js +260 -0
  18. package/lib/src/model/query-sparql.test.d.ts +1 -0
  19. package/lib/src/model/query-sparql.test.js +312 -0
  20. package/lib/src/model/relation-filtering.test.js +15 -15
  21. package/lib/src/model/subscription-delta.test.d.ts +24 -0
  22. package/lib/src/model/subscription-delta.test.js +180 -0
  23. package/lib/src/model/subscription-pool.d.ts +39 -0
  24. package/lib/src/model/subscription-pool.js +165 -0
  25. package/lib/src/perspectives/PerspectiveClient.test.d.ts +1 -0
  26. package/lib/src/perspectives/PerspectiveClient.test.js +224 -0
  27. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -1
  28. package/lib/src/perspectives/PerspectiveResolver.js +0 -11
  29. package/lib/src/runtime/RuntimeResolver.d.ts +28 -1
  30. package/lib/src/runtime/RuntimeResolver.js +197 -4
  31. package/lib/src/schema.gql +27 -1
  32. package/lib/src/shacl/SHACLShape.test.js +82 -0
  33. package/package.json +8 -11
  34. package/src/model/Ad4mModel.ts +97 -26
  35. package/src/model/ModelQueryBuilder.ts +17 -7
  36. package/lib/src/model/query-surreal.d.ts +0 -44
  37. package/lib/src/model/query-surreal.js +0 -249
  38. package/lib/src/model/surreal-utils.d.ts +0 -42
  39. package/lib/src/model/surreal-utils.js +0 -128
package/lib/index.cjs CHANGED
@@ -14930,8 +14930,14 @@ class ModelQueryBuilder {
14930
14930
  const parseResults = (raw) => {
14931
14931
  return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
14932
14932
  };
14933
- // Parse initial results
14934
- const initialResults = parseResults(initialModelResult);
14933
+ // Resolve non-literal (file-language) properties — handles both raw URI strings
14934
+ // and already-resolved FileData objects returned by the Rust executor.
14935
+ const resolveAndReturn = async (instances) => {
14936
+ await ctor.resolveNonLiteralProps(this.perspective, instances);
14937
+ return instances;
14938
+ };
14939
+ // Parse initial results (with non-literal resolution)
14940
+ const initialResults = await resolveAndReturn(parseResults(initialModelResult));
14935
14941
  // Track last emitted result fingerprint to suppress duplicate callbacks
14936
14942
  let lastResultFingerprint = null;
14937
14943
  const buildFingerprint = (results) => {
@@ -14944,12 +14950,15 @@ class ModelQueryBuilder {
14944
14950
  // When Rust re-runs the model query and finds changed results, it pushes them.
14945
14951
  const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
14946
14952
  try {
14947
- const results = parseResults(rawResult);
14948
- const fp = buildFingerprint(results);
14949
- if (fp === lastResultFingerprint)
14950
- return;
14951
- lastResultFingerprint = fp;
14952
- callback(results);
14953
+ resolveAndReturn(parseResults(rawResult)).then((results) => {
14954
+ const fp = buildFingerprint(results);
14955
+ if (fp === lastResultFingerprint)
14956
+ return;
14957
+ lastResultFingerprint = fp;
14958
+ callback(results);
14959
+ }).catch((e) => {
14960
+ console.error('Model subscription update resolve error:', e);
14961
+ });
14953
14962
  }
14954
14963
  catch (e) {
14955
14964
  console.error('Model subscription update parse error:', e);
@@ -15215,6 +15224,48 @@ function normalizeValue(value) {
15215
15224
  return value;
15216
15225
  }
15217
15226
 
15227
+ // ---------------------------------------------------------------------------
15228
+ // Default decoder for file-storage (non-literal resolveLanguage) properties
15229
+ // ---------------------------------------------------------------------------
15230
+ /**
15231
+ * When the Rust executor resolves a non-literal expression it may return a
15232
+ * `FileData`-shaped object (`{ data_base64, file_type, ... }`) rather than a
15233
+ * raw URI string. If the model class has no custom `transform` registered
15234
+ * (e.g. it was synthesised from a SHACL shape at runtime) we still want to
15235
+ * decode the content rather than passing raw `FileData` to callers.
15236
+ *
15237
+ * Decoding rules (mirrors the JS `decodeFileAsJson` / `decodeFileAsString` helpers):
15238
+ * - `application/json` (default when `file_type` is absent) → JSON.parse
15239
+ * - anything else → raw decoded string
15240
+ *
15241
+ * If `resolved` is not a `FileData` object the value is returned unchanged so
15242
+ * that callers can use this as a safe unconditional fallback.
15243
+ */
15244
+ function defaultFileDecode(resolved) {
15245
+ if (resolved !== null &&
15246
+ typeof resolved === 'object' &&
15247
+ 'data_base64' in resolved) {
15248
+ const fd = resolved;
15249
+ let raw;
15250
+ try {
15251
+ raw = atob(fd.data_base64);
15252
+ }
15253
+ catch {
15254
+ return resolved; // malformed base64 — keep as-is
15255
+ }
15256
+ const isJson = !fd.file_type || fd.file_type === 'application/json';
15257
+ if (isJson) {
15258
+ try {
15259
+ return JSON.parse(raw);
15260
+ }
15261
+ catch {
15262
+ return raw;
15263
+ }
15264
+ }
15265
+ return raw;
15266
+ }
15267
+ return resolved;
15268
+ }
15218
15269
  // ---------------------------------------------------------------------------
15219
15270
  // Helpers for Rust-side include resolution
15220
15271
  // ---------------------------------------------------------------------------
@@ -16031,6 +16082,55 @@ class Ad4mModel {
16031
16082
  return [];
16032
16083
  return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
16033
16084
  }
16085
+ /**
16086
+ * Resolve non-literal (file-language) properties on an array of already-constructed
16087
+ * model instances. Handles two cases:
16088
+ *
16089
+ * 1. The Rust executor returned a raw URI string → fetch via `getExpression` then apply transform.
16090
+ * 2. The Rust executor already resolved the expression and returned a `FileData` object
16091
+ * (happens when the perspective backend eagerly fetches file content) → apply transform
16092
+ * (or `defaultFileDecode` if no transform is registered on the class, e.g. for SHACL-
16093
+ * synthesised model classes).
16094
+ *
16095
+ * Extracted as a public static so `ModelQueryBuilder.subscribe()` can reuse it without
16096
+ * duplicating logic or introducing a circular dependency.
16097
+ * @internal
16098
+ */
16099
+ static async resolveNonLiteralProps(perspective, instances) {
16100
+ const propsMeta = getPropertiesMetadata(this);
16101
+ const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null &&
16102
+ opts.resolveLanguage !== 'literal');
16103
+ if (resolveProps.length === 0)
16104
+ return;
16105
+ await Promise.all(instances.map(async (inst) => {
16106
+ for (const [propName, opts] of resolveProps) {
16107
+ const val = inst[propName];
16108
+ const transform = opts.transform;
16109
+ const applyTransform = (resolved) => typeof transform === 'function' ? transform(resolved) : defaultFileDecode(resolved);
16110
+ if (typeof val === 'string' && val && !val.startsWith('literal:')) {
16111
+ // Case 1: raw URI — fetch from language runtime
16112
+ try {
16113
+ const expression = await perspective.getExpression(val);
16114
+ if (expression) {
16115
+ let resolved;
16116
+ try {
16117
+ resolved = JSON.parse(expression.data);
16118
+ }
16119
+ catch {
16120
+ resolved = expression.data;
16121
+ }
16122
+ inst[propName] = applyTransform(resolved);
16123
+ }
16124
+ }
16125
+ catch (_) { /* resolution failed — keep raw value */ }
16126
+ }
16127
+ else if (val !== null && val !== undefined && typeof val === 'object') {
16128
+ // Case 2: already resolved by Rust — apply transform / default decode
16129
+ inst[propName] = applyTransform(val);
16130
+ }
16131
+ }
16132
+ }));
16133
+ }
16034
16134
  // instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
16035
16135
  /**
16036
16136
  * Execute a model query via the executor-side endpoint.
@@ -16187,34 +16287,9 @@ class Ad4mModel {
16187
16287
  });
16188
16288
  // Resolve non-literal expressions (e.g. file languages where the stored
16189
16289
  // value is a content-addressed hash that must be fetched from the language
16190
- // runtime). The Rust endpoint returns raw target URIs; we resolve them here.
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
- await Promise.all(instances.map(async (inst) => {
16196
- for (const [propName, opts] of resolveProps) {
16197
- const val = inst[propName];
16198
- if (typeof val !== 'string' || !val || val.startsWith('literal:'))
16199
- continue;
16200
- try {
16201
- const expression = await perspective.getExpression(val);
16202
- if (expression) {
16203
- let resolved;
16204
- try {
16205
- resolved = JSON.parse(expression.data);
16206
- }
16207
- catch {
16208
- resolved = expression.data;
16209
- }
16210
- const transform = opts.transform;
16211
- inst[propName] = typeof transform === 'function' ? transform(resolved) : resolved;
16212
- }
16213
- }
16214
- catch (_) { /* resolution failed — keep raw value */ }
16215
- }
16216
- }));
16217
- }
16290
+ // runtime). The Rust endpoint may return either a raw target URI (string)
16291
+ // or an already-resolved FileData object — both cases are handled here.
16292
+ await this.resolveNonLiteralProps(perspective, instances);
16218
16293
  // Take snapshots for dirty tracking
16219
16294
  const snapshotRelations = queryInput.include;
16220
16295
  for (const inst of instances) {
package/lib/index.js CHANGED
@@ -14926,8 +14926,14 @@ class ModelQueryBuilder {
14926
14926
  const parseResults = (raw) => {
14927
14927
  return ctor.parseModelResult(this.perspective, raw, this.queryParams.include, this.queryParams.properties);
14928
14928
  };
14929
- // Parse initial results
14930
- const initialResults = parseResults(initialModelResult);
14929
+ // Resolve non-literal (file-language) properties — handles both raw URI strings
14930
+ // and already-resolved FileData objects returned by the Rust executor.
14931
+ const resolveAndReturn = async (instances) => {
14932
+ await ctor.resolveNonLiteralProps(this.perspective, instances);
14933
+ return instances;
14934
+ };
14935
+ // Parse initial results (with non-literal resolution)
14936
+ const initialResults = await resolveAndReturn(parseResults(initialModelResult));
14931
14937
  // Track last emitted result fingerprint to suppress duplicate callbacks
14932
14938
  let lastResultFingerprint = null;
14933
14939
  const buildFingerprint = (results) => {
@@ -14940,12 +14946,15 @@ class ModelQueryBuilder {
14940
14946
  // When Rust re-runs the model query and finds changed results, it pushes them.
14941
14947
  const unsubscribe = this.perspective.client.subscribeToQueryUpdates(subscriptionId, (rawResult) => {
14942
14948
  try {
14943
- const results = parseResults(rawResult);
14944
- const fp = buildFingerprint(results);
14945
- if (fp === lastResultFingerprint)
14946
- return;
14947
- lastResultFingerprint = fp;
14948
- callback(results);
14949
+ resolveAndReturn(parseResults(rawResult)).then((results) => {
14950
+ const fp = buildFingerprint(results);
14951
+ if (fp === lastResultFingerprint)
14952
+ return;
14953
+ lastResultFingerprint = fp;
14954
+ callback(results);
14955
+ }).catch((e) => {
14956
+ console.error('Model subscription update resolve error:', e);
14957
+ });
14949
14958
  }
14950
14959
  catch (e) {
14951
14960
  console.error('Model subscription update parse error:', e);
@@ -15211,6 +15220,48 @@ function normalizeValue(value) {
15211
15220
  return value;
15212
15221
  }
15213
15222
 
15223
+ // ---------------------------------------------------------------------------
15224
+ // Default decoder for file-storage (non-literal resolveLanguage) properties
15225
+ // ---------------------------------------------------------------------------
15226
+ /**
15227
+ * When the Rust executor resolves a non-literal expression it may return a
15228
+ * `FileData`-shaped object (`{ data_base64, file_type, ... }`) rather than a
15229
+ * raw URI string. If the model class has no custom `transform` registered
15230
+ * (e.g. it was synthesised from a SHACL shape at runtime) we still want to
15231
+ * decode the content rather than passing raw `FileData` to callers.
15232
+ *
15233
+ * Decoding rules (mirrors the JS `decodeFileAsJson` / `decodeFileAsString` helpers):
15234
+ * - `application/json` (default when `file_type` is absent) → JSON.parse
15235
+ * - anything else → raw decoded string
15236
+ *
15237
+ * If `resolved` is not a `FileData` object the value is returned unchanged so
15238
+ * that callers can use this as a safe unconditional fallback.
15239
+ */
15240
+ function defaultFileDecode(resolved) {
15241
+ if (resolved !== null &&
15242
+ typeof resolved === 'object' &&
15243
+ 'data_base64' in resolved) {
15244
+ const fd = resolved;
15245
+ let raw;
15246
+ try {
15247
+ raw = atob(fd.data_base64);
15248
+ }
15249
+ catch {
15250
+ return resolved; // malformed base64 — keep as-is
15251
+ }
15252
+ const isJson = !fd.file_type || fd.file_type === 'application/json';
15253
+ if (isJson) {
15254
+ try {
15255
+ return JSON.parse(raw);
15256
+ }
15257
+ catch {
15258
+ return raw;
15259
+ }
15260
+ }
15261
+ return raw;
15262
+ }
15263
+ return resolved;
15264
+ }
15214
15265
  // ---------------------------------------------------------------------------
15215
15266
  // Helpers for Rust-side include resolution
15216
15267
  // ---------------------------------------------------------------------------
@@ -16027,6 +16078,55 @@ class Ad4mModel {
16027
16078
  return [];
16028
16079
  return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
16029
16080
  }
16081
+ /**
16082
+ * Resolve non-literal (file-language) properties on an array of already-constructed
16083
+ * model instances. Handles two cases:
16084
+ *
16085
+ * 1. The Rust executor returned a raw URI string → fetch via `getExpression` then apply transform.
16086
+ * 2. The Rust executor already resolved the expression and returned a `FileData` object
16087
+ * (happens when the perspective backend eagerly fetches file content) → apply transform
16088
+ * (or `defaultFileDecode` if no transform is registered on the class, e.g. for SHACL-
16089
+ * synthesised model classes).
16090
+ *
16091
+ * Extracted as a public static so `ModelQueryBuilder.subscribe()` can reuse it without
16092
+ * duplicating logic or introducing a circular dependency.
16093
+ * @internal
16094
+ */
16095
+ static async resolveNonLiteralProps(perspective, instances) {
16096
+ const propsMeta = getPropertiesMetadata(this);
16097
+ const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null &&
16098
+ opts.resolveLanguage !== 'literal');
16099
+ if (resolveProps.length === 0)
16100
+ return;
16101
+ await Promise.all(instances.map(async (inst) => {
16102
+ for (const [propName, opts] of resolveProps) {
16103
+ const val = inst[propName];
16104
+ const transform = opts.transform;
16105
+ const applyTransform = (resolved) => typeof transform === 'function' ? transform(resolved) : defaultFileDecode(resolved);
16106
+ if (typeof val === 'string' && val && !val.startsWith('literal:')) {
16107
+ // Case 1: raw URI — fetch from language runtime
16108
+ try {
16109
+ const expression = await perspective.getExpression(val);
16110
+ if (expression) {
16111
+ let resolved;
16112
+ try {
16113
+ resolved = JSON.parse(expression.data);
16114
+ }
16115
+ catch {
16116
+ resolved = expression.data;
16117
+ }
16118
+ inst[propName] = applyTransform(resolved);
16119
+ }
16120
+ }
16121
+ catch (_) { /* resolution failed — keep raw value */ }
16122
+ }
16123
+ else if (val !== null && val !== undefined && typeof val === 'object') {
16124
+ // Case 2: already resolved by Rust — apply transform / default decode
16125
+ inst[propName] = applyTransform(val);
16126
+ }
16127
+ }
16128
+ }));
16129
+ }
16030
16130
  // instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
16031
16131
  /**
16032
16132
  * Execute a model query via the executor-side endpoint.
@@ -16183,34 +16283,9 @@ class Ad4mModel {
16183
16283
  });
16184
16284
  // Resolve non-literal expressions (e.g. file languages where the stored
16185
16285
  // value is a content-addressed hash that must be fetched from the language
16186
- // runtime). The Rust endpoint returns raw target URIs; we resolve them here.
16187
- const propsMeta = getPropertiesMetadata(this);
16188
- const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null &&
16189
- opts.resolveLanguage !== 'literal');
16190
- if (resolveProps.length > 0) {
16191
- await Promise.all(instances.map(async (inst) => {
16192
- for (const [propName, opts] of resolveProps) {
16193
- const val = inst[propName];
16194
- if (typeof val !== 'string' || !val || val.startsWith('literal:'))
16195
- continue;
16196
- try {
16197
- const expression = await perspective.getExpression(val);
16198
- if (expression) {
16199
- let resolved;
16200
- try {
16201
- resolved = JSON.parse(expression.data);
16202
- }
16203
- catch {
16204
- resolved = expression.data;
16205
- }
16206
- const transform = opts.transform;
16207
- inst[propName] = typeof transform === 'function' ? transform(resolved) : resolved;
16208
- }
16209
- }
16210
- catch (_) { /* resolution failed — keep raw value */ }
16211
- }
16212
- }));
16213
- }
16286
+ // runtime). The Rust endpoint may return either a raw target URI (string)
16287
+ // or an already-resolved FileData object — both cases are handled here.
16288
+ await this.resolveNonLiteralProps(perspective, instances);
16214
16289
  // Take snapshots for dirty tracking
16215
16290
  const snapshotRelations = queryInput.include;
16216
16291
  for (const inst of instances) {
@@ -313,6 +313,21 @@ export declare class Ad4mModel {
313
313
  * @internal
314
314
  */
315
315
  static parseModelResult<T extends Ad4mModel>(this: typeof Ad4mModel & (new (...args: any[]) => T), perspective: PerspectiveProxy, raw: any, include?: IncludeMap, properties?: string[]): T[];
316
+ /**
317
+ * Resolve non-literal (file-language) properties on an array of already-constructed
318
+ * model instances. Handles two cases:
319
+ *
320
+ * 1. The Rust executor returned a raw URI string → fetch via `getExpression` then apply transform.
321
+ * 2. The Rust executor already resolved the expression and returned a `FileData` object
322
+ * (happens when the perspective backend eagerly fetches file content) → apply transform
323
+ * (or `defaultFileDecode` if no transform is registered on the class, e.g. for SHACL-
324
+ * synthesised model classes).
325
+ *
326
+ * Extracted as a public static so `ModelQueryBuilder.subscribe()` can reuse it without
327
+ * duplicating logic or introducing a circular dependency.
328
+ * @internal
329
+ */
330
+ static resolveNonLiteralProps<T extends Ad4mModel>(this: typeof Ad4mModel & (new (...args: any[]) => T), perspective: PerspectiveProxy, instances: T[]): Promise<void>;
316
331
  /**
317
332
  * Execute a model query via the executor-side endpoint.
318
333
  *
@@ -9,6 +9,48 @@ import { buildSPARQLQuery } from "./query-sparql";
9
9
  import { ModelQueryBuilder } from "./ModelQueryBuilder";
10
10
  import { normalizeValue, } from "./hydration";
11
11
  // ---------------------------------------------------------------------------
12
+ // Default decoder for file-storage (non-literal resolveLanguage) properties
13
+ // ---------------------------------------------------------------------------
14
+ /**
15
+ * When the Rust executor resolves a non-literal expression it may return a
16
+ * `FileData`-shaped object (`{ data_base64, file_type, ... }`) rather than a
17
+ * raw URI string. If the model class has no custom `transform` registered
18
+ * (e.g. it was synthesised from a SHACL shape at runtime) we still want to
19
+ * decode the content rather than passing raw `FileData` to callers.
20
+ *
21
+ * Decoding rules (mirrors the JS `decodeFileAsJson` / `decodeFileAsString` helpers):
22
+ * - `application/json` (default when `file_type` is absent) → JSON.parse
23
+ * - anything else → raw decoded string
24
+ *
25
+ * If `resolved` is not a `FileData` object the value is returned unchanged so
26
+ * that callers can use this as a safe unconditional fallback.
27
+ */
28
+ function defaultFileDecode(resolved) {
29
+ if (resolved !== null &&
30
+ typeof resolved === 'object' &&
31
+ 'data_base64' in resolved) {
32
+ const fd = resolved;
33
+ let raw;
34
+ try {
35
+ raw = atob(fd.data_base64);
36
+ }
37
+ catch {
38
+ return resolved; // malformed base64 — keep as-is
39
+ }
40
+ const isJson = !fd.file_type || fd.file_type === 'application/json';
41
+ if (isJson) {
42
+ try {
43
+ return JSON.parse(raw);
44
+ }
45
+ catch {
46
+ return raw;
47
+ }
48
+ }
49
+ return raw;
50
+ }
51
+ return resolved;
52
+ }
53
+ // ---------------------------------------------------------------------------
12
54
  // Helpers for Rust-side include resolution
13
55
  // ---------------------------------------------------------------------------
14
56
  /**
@@ -824,6 +866,55 @@ export class Ad4mModel {
824
866
  return [];
825
867
  return arr.map((json) => jsonToModelInstance(this, perspective, json, include, properties));
826
868
  }
869
+ /**
870
+ * Resolve non-literal (file-language) properties on an array of already-constructed
871
+ * model instances. Handles two cases:
872
+ *
873
+ * 1. The Rust executor returned a raw URI string → fetch via `getExpression` then apply transform.
874
+ * 2. The Rust executor already resolved the expression and returned a `FileData` object
875
+ * (happens when the perspective backend eagerly fetches file content) → apply transform
876
+ * (or `defaultFileDecode` if no transform is registered on the class, e.g. for SHACL-
877
+ * synthesised model classes).
878
+ *
879
+ * Extracted as a public static so `ModelQueryBuilder.subscribe()` can reuse it without
880
+ * duplicating logic or introducing a circular dependency.
881
+ * @internal
882
+ */
883
+ static async resolveNonLiteralProps(perspective, instances) {
884
+ const propsMeta = getPropertiesMetadata(this);
885
+ const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null &&
886
+ opts.resolveLanguage !== 'literal');
887
+ if (resolveProps.length === 0)
888
+ return;
889
+ await Promise.all(instances.map(async (inst) => {
890
+ for (const [propName, opts] of resolveProps) {
891
+ const val = inst[propName];
892
+ const transform = opts.transform;
893
+ const applyTransform = (resolved) => typeof transform === 'function' ? transform(resolved) : defaultFileDecode(resolved);
894
+ if (typeof val === 'string' && val && !val.startsWith('literal:')) {
895
+ // Case 1: raw URI — fetch from language runtime
896
+ try {
897
+ const expression = await perspective.getExpression(val);
898
+ if (expression) {
899
+ let resolved;
900
+ try {
901
+ resolved = JSON.parse(expression.data);
902
+ }
903
+ catch {
904
+ resolved = expression.data;
905
+ }
906
+ inst[propName] = applyTransform(resolved);
907
+ }
908
+ }
909
+ catch (_) { /* resolution failed — keep raw value */ }
910
+ }
911
+ else if (val !== null && val !== undefined && typeof val === 'object') {
912
+ // Case 2: already resolved by Rust — apply transform / default decode
913
+ inst[propName] = applyTransform(val);
914
+ }
915
+ }
916
+ }));
917
+ }
827
918
  // instancesFromQueryResult — removed (superseded by Rust executeModelQuery pipeline)
828
919
  /**
829
920
  * Execute a model query via the executor-side endpoint.
@@ -980,34 +1071,9 @@ export class Ad4mModel {
980
1071
  });
981
1072
  // Resolve non-literal expressions (e.g. file languages where the stored
982
1073
  // value is a content-addressed hash that must be fetched from the language
983
- // runtime). The Rust endpoint returns raw target URIs; we resolve them here.
984
- const propsMeta = getPropertiesMetadata(this);
985
- const resolveProps = Object.entries(propsMeta).filter(([, opts]) => opts.resolveLanguage != null &&
986
- opts.resolveLanguage !== 'literal');
987
- if (resolveProps.length > 0) {
988
- await Promise.all(instances.map(async (inst) => {
989
- for (const [propName, opts] of resolveProps) {
990
- const val = inst[propName];
991
- if (typeof val !== 'string' || !val || val.startsWith('literal:'))
992
- continue;
993
- try {
994
- const expression = await perspective.getExpression(val);
995
- if (expression) {
996
- let resolved;
997
- try {
998
- resolved = JSON.parse(expression.data);
999
- }
1000
- catch {
1001
- resolved = expression.data;
1002
- }
1003
- const transform = opts.transform;
1004
- inst[propName] = typeof transform === 'function' ? transform(resolved) : resolved;
1005
- }
1006
- }
1007
- catch (_) { /* resolution failed — keep raw value */ }
1008
- }
1009
- }));
1010
- }
1074
+ // runtime). The Rust endpoint may return either a raw target URI (string)
1075
+ // or an already-resolved FileData object — both cases are handled here.
1076
+ await this.resolveNonLiteralProps(perspective, instances);
1011
1077
  // Take snapshots for dirty tracking
1012
1078
  const snapshotRelations = queryInput.include;
1013
1079
  for (const inst of instances) {