@coasys/ad4m 0.11.2-dev.5 → 0.12.0-dev-whisper-lang

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 CHANGED
@@ -5791,6 +5791,7 @@ class PerspectiveProxy {
5791
5791
  const collName = result.Coll;
5792
5792
  let predicate = null;
5793
5793
  let instanceFilter = undefined;
5794
+ let condition = undefined;
5794
5795
  // Try to extract predicate from collection_adder first
5795
5796
  const adderResults = await this.infer(`subject_class("${className}", C), collection_adder(C, "${collName}", Adder)`);
5796
5797
  if (adderResults && adderResults.length > 0) {
@@ -5800,6 +5801,8 @@ class PerspectiveProxy {
5800
5801
  predicate = predicateMatch[1] || predicateMatch[2];
5801
5802
  }
5802
5803
  }
5804
+ // Note: condition is not stored in SDNA, it's read from class metadata
5805
+ // It will be populated by augmentMetadataWithCollectionOptions() when needed
5803
5806
  // Parse collection_getter from SDNA to extract predicate and instanceFilter
5804
5807
  // Format 1 (findall): collection_getter(c, Base, "comments", List) :- findall(C, triple(Base, "todo://comment", C), List).
5805
5808
  // Format 2 (setof): collection_getter(c, Base, "messages", List) :- setof(Target, (triple(Base, "flux://entry_type", Target), ...), List).
@@ -5835,7 +5838,7 @@ class PerspectiveProxy {
5835
5838
  }
5836
5839
  }
5837
5840
  if (predicate) {
5838
- collections.set(collName, { predicate, instanceFilter });
5841
+ collections.set(collName, { predicate, instanceFilter, condition });
5839
5842
  }
5840
5843
  }
5841
5844
  }
@@ -5911,6 +5914,7 @@ class PerspectiveProxy {
5911
5914
  /**
5912
5915
  * Gets collection values using SurrealDB when Prolog fails.
5913
5916
  * This is used as a fallback in SdnaOnly mode where link data isn't in Prolog.
5917
+ * Note: This is used by Subject.ts (legacy pattern). Ad4mModel.ts uses getModelMetadata() instead.
5914
5918
  */
5915
5919
  async getCollectionValuesViaSurreal(baseExpression, className, collectionName) {
5916
5920
  const metadata = await this.getSubjectClassMetadataFromSDNA(className);
@@ -5929,6 +5933,31 @@ class PerspectiveProxy {
5929
5933
  return [];
5930
5934
  }
5931
5935
  let values = result.map(r => r.value).filter(v => v !== "" && v !== '');
5936
+ // Apply condition filtering if present
5937
+ if (collMeta.condition && values.length > 0) {
5938
+ try {
5939
+ const filteredValues = [];
5940
+ for (const value of values) {
5941
+ let condition = collMeta.condition
5942
+ .replace(/\$perspective/g, `'${this.uuid}'`)
5943
+ .replace(/\$base/g, `'${baseExpression}'`)
5944
+ .replace(/Target/g, `'${value.replace(/'/g, "\\'")}'`);
5945
+ // If condition starts with WHERE, wrap in array length check
5946
+ if (condition.trim().startsWith('WHERE')) {
5947
+ condition = `array::len(SELECT * FROM link ${condition}) > 0`;
5948
+ }
5949
+ const filterResult = await this.querySurrealDB(`RETURN ${condition}`);
5950
+ const isTrue = filterResult === true || (Array.isArray(filterResult) && filterResult.length > 0 && filterResult[0] === true);
5951
+ if (isTrue) {
5952
+ filteredValues.push(value);
5953
+ }
5954
+ }
5955
+ values = filteredValues;
5956
+ }
5957
+ catch (error) {
5958
+ console.warn(`Failed to apply condition filter for ${collectionName}:`, error);
5959
+ }
5960
+ }
5932
5961
  // Apply instance filter if present - batch-check all values at once
5933
5962
  if (collMeta.instanceFilter) {
5934
5963
  try {
@@ -5970,11 +5999,13 @@ class PerspectiveProxy {
5970
5999
  if (triple.target) {
5971
6000
  // Flag: must match both predicate AND exact target value
5972
6001
  const escapedTarget = escapeSurrealString(triple.target);
5973
- checkQuery = `SELECT in.uri AS uri FROM link WHERE in.uri IN [${escapedExpressions}] AND predicate = '${escapedPredicate}' AND out.uri = '${escapedTarget}' GROUP BY in.uri`;
6002
+ // Note: Removed GROUP BY because it was causing SurrealDB to only return one result
6003
+ checkQuery = `SELECT in.uri AS uri FROM link WHERE in.uri IN [${escapedExpressions}] AND predicate = '${escapedPredicate}' AND out.uri = '${escapedTarget}'`;
5974
6004
  }
5975
6005
  else {
5976
6006
  // Property: just check predicate exists
5977
- checkQuery = `SELECT in.uri AS uri FROM link WHERE in.uri IN [${escapedExpressions}] AND predicate = '${escapedPredicate}' GROUP BY in.uri`;
6007
+ // Note: Removed GROUP BY because it was causing SurrealDB to only return one result
6008
+ checkQuery = `SELECT in.uri AS uri FROM link WHERE in.uri IN [${escapedExpressions}] AND predicate = '${escapedPredicate}'`;
5978
6009
  }
5979
6010
  const result = await this.querySurrealDB(checkQuery);
5980
6011
  validExpressionSets.push(new Set(result.map(r => r.uri)));
@@ -15818,16 +15849,17 @@ class AIClient {
15818
15849
  const decompressed = JSON.parse(pako.inflate(compressed, { to: 'string' }));
15819
15850
  return decompressed;
15820
15851
  }
15821
- async openTranscriptionStream(modelId, streamCallback, params) {
15852
+ async openTranscriptionStream(modelId, streamCallback, params, language) {
15822
15853
  const { aiOpenTranscriptionStream } = unwrapApolloResult(await __classPrivateFieldGet$3(this, _AIClient_apolloClient, "f").mutate({
15823
15854
  mutation: gql `
15824
- mutation AiOpenTranscriptionStream($modelId: String!, $params: VoiceActivityParamsInput) {
15825
- aiOpenTranscriptionStream(modelId: $modelId, params: $params)
15855
+ mutation AiOpenTranscriptionStream($modelId: String!, $params: VoiceActivityParamsInput, $language: String) {
15856
+ aiOpenTranscriptionStream(modelId: $modelId, params: $params, language: $language)
15826
15857
  }
15827
15858
  `,
15828
15859
  variables: {
15829
15860
  modelId,
15830
- params
15861
+ params,
15862
+ language
15831
15863
  }
15832
15864
  }));
15833
15865
  const subscription = __classPrivateFieldGet$3(this, _AIClient_apolloClient, "f").subscribe({
@@ -16461,14 +16493,14 @@ function hasLink(predicate) {
16461
16493
  * static async findByName(perspective: PerspectiveProxy): Promise<Recipe[]> { return [] }
16462
16494
  *
16463
16495
  * // Get highly rated recipes using a custom condition
16464
- * @InstanceQuery({ condition: "triple(Instance, 'recipe://rating', Rating), Rating > 4" })
16496
+ * @InstanceQuery({ prologCondition: "triple(Instance, 'recipe://rating', Rating), Rating > 4" })
16465
16497
  * static async topRated(perspective: PerspectiveProxy): Promise<Recipe[]> { return [] }
16466
16498
  * }
16467
16499
  * ```
16468
16500
  *
16469
16501
  * @param {Object} [options] - Query options
16470
16502
  * @param {object} [options.where] - Object with property-value pairs to match
16471
- * @param {string} [options.condition] - Custom Prolog condition for more complex queries
16503
+ * @param {string} [options.prologCondition] - Custom Prolog condition for more complex queries
16472
16504
  */
16473
16505
  function InstanceQuery(options) {
16474
16506
  return function (target, key, descriptor) {
@@ -16487,8 +16519,8 @@ function InstanceQuery(options) {
16487
16519
  query += `, property_getter(C, Instance, "${prop}", "${value}")`;
16488
16520
  }
16489
16521
  }
16490
- if (options && options.condition) {
16491
- query += ', ' + options.condition;
16522
+ if (options && options.prologCondition) {
16523
+ query += ', ' + options.prologCondition;
16492
16524
  }
16493
16525
  // Try Prolog first
16494
16526
  try {
@@ -16608,8 +16640,8 @@ function InstanceQuery(options) {
16608
16640
  * @param {boolean} [opts.required] - Whether the property must have a value
16609
16641
  * @param {boolean} [opts.writable=true] - Whether the property can be modified
16610
16642
  * @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
16611
- * @param {string} [opts.getter] - Custom Prolog code for getting the property value
16612
- * @param {string} [opts.setter] - Custom Prolog code for setting the property value
16643
+ * @param {string} [opts.prologGetter] - Custom Prolog code for getting the property value
16644
+ * @param {string} [opts.prologSetter] - Custom Prolog code for setting the property value
16613
16645
  * @param {boolean} [opts.local] - Whether the property should only be stored locally
16614
16646
  */
16615
16647
  function Optional(opts) {
@@ -16620,8 +16652,8 @@ function Optional(opts) {
16620
16652
  if (opts.required && !opts.initial) {
16621
16653
  throw new Error("SubjectProperty requires an 'initial' option if 'required' is true");
16622
16654
  }
16623
- if (!opts.through && !opts.getter) {
16624
- throw new Error("SubjectProperty requires either 'through' or 'getter' option");
16655
+ if (!opts.through && !opts.prologGetter) {
16656
+ throw new Error("SubjectProperty requires either 'through' or 'prologGetter' option");
16625
16657
  }
16626
16658
  target["__properties"] = target["__properties"] || {};
16627
16659
  target["__properties"][key] = target["__properties"][key] || {};
@@ -16747,13 +16779,20 @@ function Flag(opts) {
16747
16779
  * })
16748
16780
  * comments: string[] = [];
16749
16781
  *
16750
- * // Collection with custom filter condition
16782
+ * // Collection with custom Prolog filter condition
16751
16783
  * @Collection({
16752
16784
  * through: "recipe://step",
16753
- * where: { condition: `triple(Target, "step://order", Order), Order < 3` }
16785
+ * where: { prologCondition: `triple(Target, "step://order", Order), Order < 3` }
16754
16786
  * })
16755
16787
  * firstSteps: string[] = [];
16756
16788
  *
16789
+ * // Collection with custom SurrealDB filter condition
16790
+ * @Collection({
16791
+ * through: "recipe://entries",
16792
+ * where: { condition: `WHERE in.uri = Target AND predicate = 'recipe://has_ingredient' AND out.uri = 'recipe://test')`
16793
+ * })
16794
+ * ingredients: string[] = [];
16795
+ *
16757
16796
  * // Local-only collection not shared with network
16758
16797
  * @Collection({
16759
16798
  * through: "recipe://note",
@@ -16773,7 +16812,7 @@ function Flag(opts) {
16773
16812
  * @param {string} opts.through - The predicate URI for collection links
16774
16813
  * @param {WhereOptions} [opts.where] - Filter conditions for collection values
16775
16814
  * @param {any} [opts.where.isInstance] - Model class to filter instances by
16776
- * @param {string} [opts.where.condition] - Custom Prolog condition for filtering
16815
+ * @param {string} [opts.where.prologCondition] - Custom Prolog condition for filtering
16777
16816
  * @param {boolean} [opts.local] - Whether collection links are stored locally only
16778
16817
  */
16779
16818
  function Collection(opts) {
@@ -16873,13 +16912,13 @@ function ModelOptions(opts) {
16873
16912
  let properties = obj.__properties || {};
16874
16913
  for (let property in properties) {
16875
16914
  let propertyCode = `property(${uuid}, "${property}").\n`;
16876
- let { through, initial, required, resolveLanguage, writable, flag, getter, setter, local } = properties[property];
16915
+ let { through, initial, required, resolveLanguage, writable, flag, prologGetter, prologSetter, local } = properties[property];
16877
16916
  if (resolveLanguage) {
16878
16917
  propertyCode += `property_resolve(${uuid}, "${property}").\n`;
16879
16918
  propertyCode += `property_resolve_language(${uuid}, "${property}", "${resolveLanguage}").\n`;
16880
16919
  }
16881
- if (getter) {
16882
- propertyCode += `property_getter(${uuid}, Base, "${property}", Value) :- ${getter}.\n`;
16920
+ if (prologGetter) {
16921
+ propertyCode += `property_getter(${uuid}, Base, "${property}", Value) :- ${prologGetter}.\n`;
16883
16922
  }
16884
16923
  else if (through) {
16885
16924
  propertyCode += `property_getter(${uuid}, Base, "${property}", Value) :- triple(Base, "${through}", Value).\n`;
@@ -16892,8 +16931,8 @@ function ModelOptions(opts) {
16892
16931
  }
16893
16932
  }
16894
16933
  }
16895
- if (setter) {
16896
- propertyCode += `property_setter(${uuid}, "${property}", Actions) :- ${setter}.\n`;
16934
+ if (prologSetter) {
16935
+ propertyCode += `property_setter(${uuid}, "${property}", Actions) :- ${prologSetter}.\n`;
16897
16936
  }
16898
16937
  else if (writable && through) {
16899
16938
  let setter = obj[propertyNameToSetterName(property)];
@@ -16931,8 +16970,8 @@ function ModelOptions(opts) {
16931
16970
  let { through, where, local } = collections[collection];
16932
16971
  if (through) {
16933
16972
  if (where) {
16934
- if (!where.isInstance && !where.condition) {
16935
- throw "'where' needs one of 'isInstance' or 'condition'";
16973
+ if (!where.isInstance && !where.prologCondition && !where.condition) {
16974
+ throw "'where' needs one of 'isInstance', 'prologCondition', or 'condition'";
16936
16975
  }
16937
16976
  let conditions = [];
16938
16977
  if (where.isInstance) {
@@ -16945,11 +16984,19 @@ function ModelOptions(opts) {
16945
16984
  }
16946
16985
  conditions.push(`instance(OtherClass, Target), subject_class("${otherClass}", OtherClass)`);
16947
16986
  }
16948
- if (where.condition) {
16949
- conditions.push(where.condition);
16987
+ if (where.prologCondition) {
16988
+ conditions.push(where.prologCondition);
16989
+ }
16990
+ // If there are Prolog conditions (isInstance or prologCondition), use setof with conditions
16991
+ // If only condition is present, use simple findall (SurrealDB will filter later)
16992
+ if (conditions.length > 0) {
16993
+ const conditionString = conditions.join(", ");
16994
+ collectionCode += `collection_getter(${uuid}, Base, "${collection}", List) :- setof(Target, (triple(Base, "${through}", Target), ${conditionString}), List).\n`;
16995
+ }
16996
+ else {
16997
+ // Only SurrealDB condition present (no Prolog filtering)
16998
+ collectionCode += `collection_getter(${uuid}, Base, "${collection}", List) :- findall(C, triple(Base, "${through}", C), List).\n`;
16950
16999
  }
16951
- const conditionString = conditions.join(", ");
16952
- collectionCode += `collection_getter(${uuid}, Base, "${collection}", List) :- setof(Target, (triple(Base, "${through}", Target), ${conditionString}), List).\n`;
16953
17000
  }
16954
17001
  else {
16955
17002
  collectionCode += `collection_getter(${uuid}, Base, "${collection}", List) :- findall(C, triple(Base, "${through}", C), List).\n`;
@@ -17051,8 +17098,8 @@ function ModelOptions(opts) {
17051
17098
  * @param {string} opts.through - The predicate URI for the property
17052
17099
  * @param {string} [opts.initial] - Initial value (defaults to "literal://string:uninitialized")
17053
17100
  * @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
17054
- * @param {string} [opts.getter] - Custom Prolog code for getting the property value
17055
- * @param {string} [opts.setter] - Custom Prolog code for setting the property value
17101
+ * @param {string} [opts.prologGetter] - Custom Prolog code for getting the property value
17102
+ * @param {string} [opts.prologSetter] - Custom Prolog code for setting the property value
17056
17103
  * @param {boolean} [opts.local] - Whether the property should only be stored locally
17057
17104
  */
17058
17105
  function Property(opts) {
@@ -17115,7 +17162,7 @@ function Property(opts) {
17115
17162
  * @param {string} opts.through - The predicate URI for the property
17116
17163
  * @param {string} [opts.initial] - Initial value (if property should have one)
17117
17164
  * @param {string} [opts.resolveLanguage] - Language to use for value resolution (e.g. "literal")
17118
- * @param {string} [opts.getter] - Custom Prolog code for getting the property value
17165
+ * @param {string} [opts.prologGetter] - Custom Prolog code for getting the property value
17119
17166
  * @param {boolean} [opts.local] - Whether the property should only be stored locally
17120
17167
  */
17121
17168
  function ReadOnly(opts) {
@@ -17436,7 +17483,7 @@ type Mutation {
17436
17483
  aiCloseTranscriptionStream(streamId: String!): String!
17437
17484
  aiEmbed(modelId: String!, text: String!): String!
17438
17485
  aiFeedTranscriptionStream(audio: [Float!]!, streamIds: [String!]!): String!
17439
- aiOpenTranscriptionStream(modelId: String!, params: VoiceActivityParamsInput): String!
17486
+ aiOpenTranscriptionStream(language: String, modelId: String!, params: VoiceActivityParamsInput): String!
17440
17487
  aiPrompt(prompt: String!, taskId: String!): String!
17441
17488
  aiRemoveModel(modelId: String!): Boolean!
17442
17489
  aiRemoveTask(taskId: String!): AITask!
@@ -18922,9 +18969,9 @@ class Ad4mModel {
18922
18969
  writable: options.writable || false,
18923
18970
  ...(options.initial !== undefined && { initial: options.initial }),
18924
18971
  ...(options.resolveLanguage !== undefined && { resolveLanguage: options.resolveLanguage }),
18972
+ ...(options.prologGetter !== undefined && { prologGetter: options.prologGetter }),
18925
18973
  ...(options.getter !== undefined && { getter: options.getter }),
18926
- ...(options.surrealGetter !== undefined && { surrealGetter: options.surrealGetter }),
18927
- ...(options.setter !== undefined && { setter: options.setter }),
18974
+ ...(options.prologSetter !== undefined && { prologSetter: options.prologSetter }),
18928
18975
  ...(options.local !== undefined && { local: options.local }),
18929
18976
  ...(options.transform !== undefined && { transform: options.transform }),
18930
18977
  ...(options.flag !== undefined && { flag: options.flag })
@@ -18940,7 +18987,7 @@ class Ad4mModel {
18940
18987
  predicate: options.through || "",
18941
18988
  ...(options.where !== undefined && { where: options.where }),
18942
18989
  ...(options.local !== undefined && { local: options.local }),
18943
- ...(options.surrealGetter !== undefined && { surrealGetter: options.surrealGetter })
18990
+ ...(options.getter !== undefined && { getter: options.getter })
18944
18991
  };
18945
18992
  }
18946
18993
  // Fallback: If both structures are empty but a JSON schema is attached, derive from it
@@ -19051,9 +19098,9 @@ class Ad4mModel {
19051
19098
  if (metadata.writable === false) {
19052
19099
  throw new Error(`Property "${key}" is read-only and cannot be written`);
19053
19100
  }
19054
- if (metadata.setter) {
19055
- // Custom setter - throw error for now (Phase 2)
19056
- throw new Error(`Custom setter for property "${key}" not yet supported without Prolog. ` +
19101
+ if (metadata.prologSetter) {
19102
+ // Custom Prolog setter - throw error for now (Phase 2)
19103
+ throw new Error(`Custom Prolog setter for property "${key}" not yet supported without Prolog. ` +
19057
19104
  `Use standard @Property decorator or enable Prolog for custom setters.`);
19058
19105
  }
19059
19106
  if (!metadata.through) {
@@ -19183,10 +19230,10 @@ class Ad4mModel {
19183
19230
  let maxTimestamp = null;
19184
19231
  let latestAuthor = null;
19185
19232
  let originalAuthor = null;
19186
- // Process properties (skip those with surrealGetter)
19233
+ // Process properties (skip those with custom getter)
19187
19234
  for (const [propName, propMeta] of Object.entries(metadata.properties)) {
19188
- if (propMeta.surrealGetter)
19189
- continue; // Handle via surrealGetter evaluation
19235
+ if (propMeta.getter)
19236
+ continue; // Handle via custom getter evaluation
19190
19237
  const matching = links.filter((l) => l.predicate === propMeta.predicate);
19191
19238
  if (matching.length > 0) {
19192
19239
  // "Latest wins" semantics: select the last element since links are ordered ASC.
@@ -19238,14 +19285,44 @@ class Ad4mModel {
19238
19285
  this[propName] = value;
19239
19286
  }
19240
19287
  }
19241
- // Process collections (skip those with surrealGetter)
19288
+ // Process collections (skip those with custom getter)
19242
19289
  for (const [collName, collMeta] of Object.entries(metadata.collections)) {
19243
- if (collMeta.surrealGetter)
19244
- continue; // Handle via surrealGetter evaluation
19290
+ if (collMeta.getter)
19291
+ continue; // Handle via custom getter evaluation
19245
19292
  const matching = links.filter((l) => l.predicate === collMeta.predicate);
19246
19293
  // Collections preserve chronological order: links are sorted ASC by timestamp,
19247
19294
  // so the collection reflects the order in which items were added (oldest to newest).
19248
19295
  let values = matching.map((l) => l.target);
19296
+ // Apply where.condition filtering if present
19297
+ if (collMeta.where?.condition && values.length > 0) {
19298
+ try {
19299
+ // Filter values by evaluating condition for each value
19300
+ const filteredValues = [];
19301
+ for (const value of values) {
19302
+ let condition = collMeta.where.condition
19303
+ .replace(/\$perspective/g, `'${__classPrivateFieldGet(this, _Ad4mModel_perspective, "f").uuid}'`)
19304
+ .replace(/\$base/g, `'${__classPrivateFieldGet(this, _Ad4mModel_baseExpression, "f")}'`)
19305
+ .replace(/Target/g, `'${value.replace(/'/g, "\\'")}'`);
19306
+ // If condition starts with WHERE, wrap it in array length check pattern
19307
+ // Using array::len() to properly count matching links
19308
+ if (condition.trim().startsWith('WHERE')) {
19309
+ condition = `array::len(SELECT * FROM link ${condition}) > 0`;
19310
+ }
19311
+ const filterQuery = `RETURN ${condition}`;
19312
+ const result = await __classPrivateFieldGet(this, _Ad4mModel_perspective, "f").querySurrealDB(filterQuery);
19313
+ // RETURN can return the value directly or in an array
19314
+ const isTrue = result === true || (Array.isArray(result) && result.length > 0 && result[0] === true);
19315
+ if (isTrue) {
19316
+ filteredValues.push(value);
19317
+ }
19318
+ }
19319
+ values = filteredValues;
19320
+ }
19321
+ catch (error) {
19322
+ console.warn(`Failed to apply condition filter for ${collName}:`, error);
19323
+ // Keep unfiltered values on error
19324
+ }
19325
+ }
19249
19326
  // Apply where.isInstance filtering if present
19250
19327
  if (collMeta.where?.isInstance && values.length > 0) {
19251
19328
  try {
@@ -19275,11 +19352,11 @@ class Ad4mModel {
19275
19352
  }
19276
19353
  }
19277
19354
  // Evaluate SurrealQL getters
19278
- await ctor.evaluateSurrealGettersForInstance(this, __classPrivateFieldGet(this, _Ad4mModel_perspective, "f"), metadata);
19279
- // Apply where.isInstance filtering to surrealGetter collections
19280
- // (non-surrealGetter collections were already filtered above)
19355
+ await ctor.evaluateCustomGettersForInstance(this, __classPrivateFieldGet(this, _Ad4mModel_perspective, "f"), metadata);
19356
+ // Apply where.isInstance filtering to getter collections
19357
+ // (non-getter collections were already filtered above)
19281
19358
  for (const [collName, collMeta] of Object.entries(metadata.collections)) {
19282
- if (collMeta.surrealGetter && collMeta.where?.isInstance && this[collName]?.length > 0) {
19359
+ if (collMeta.getter && collMeta.where?.isInstance && this[collName]?.length > 0) {
19283
19360
  try {
19284
19361
  const className = typeof collMeta.where.isInstance === 'string'
19285
19362
  ? collMeta.where.isInstance
@@ -19327,14 +19404,14 @@ class Ad4mModel {
19327
19404
  * Evaluates custom SurrealQL getters for properties and collections on a specific instance.
19328
19405
  * @private
19329
19406
  */
19330
- static async evaluateSurrealGettersForInstance(instance, perspective, metadata) {
19407
+ static async evaluateCustomGettersForInstance(instance, perspective, metadata) {
19331
19408
  const safeBaseExpression = this.formatSurrealValue(instance.baseExpression);
19332
- // Evaluate property surrealGetters
19409
+ // Evaluate property getters
19333
19410
  for (const [propName, propMeta] of Object.entries(metadata.properties)) {
19334
- if (propMeta.surrealGetter) {
19411
+ if (propMeta.getter) {
19335
19412
  try {
19336
19413
  // Replace 'Base' placeholder with actual base expression
19337
- const query = propMeta.surrealGetter.replace(/Base/g, safeBaseExpression);
19414
+ const query = propMeta.getter.replace(/Base/g, safeBaseExpression);
19338
19415
  // Query from node table to have graph traversal context
19339
19416
  const result = await perspective.querySurrealDB(`SELECT (${query}) AS value FROM node WHERE uri = ${safeBaseExpression}`);
19340
19417
  if (result && result.length > 0 && result[0].value !== undefined && result[0].value !== null && result[0].value !== 'None' && result[0].value !== '') {
@@ -19342,16 +19419,16 @@ class Ad4mModel {
19342
19419
  }
19343
19420
  }
19344
19421
  catch (error) {
19345
- console.warn(`Failed to evaluate surrealGetter for ${propName}:`, error);
19422
+ console.warn(`Failed to evaluate getter for ${propName}:`, error);
19346
19423
  }
19347
19424
  }
19348
19425
  }
19349
- // Evaluate collection surrealGetters
19426
+ // Evaluate collection getters
19350
19427
  for (const [collName, collMeta] of Object.entries(metadata.collections)) {
19351
- if (collMeta.surrealGetter) {
19428
+ if (collMeta.getter) {
19352
19429
  try {
19353
19430
  // Replace 'Base' placeholder with actual base expression
19354
- const query = collMeta.surrealGetter.replace(/Base/g, safeBaseExpression);
19431
+ const query = collMeta.getter.replace(/Base/g, safeBaseExpression);
19355
19432
  // Query from node table to have graph traversal context
19356
19433
  const result = await perspective.querySurrealDB(`SELECT (${query}) AS value FROM node WHERE uri = ${safeBaseExpression}`);
19357
19434
  if (result && result.length > 0 && result[0].value !== undefined && result[0].value !== null) {
@@ -19363,7 +19440,7 @@ class Ad4mModel {
19363
19440
  }
19364
19441
  }
19365
19442
  catch (error) {
19366
- console.warn(`Failed to evaluate surrealGetter for ${collName}:`, error);
19443
+ console.warn(`Failed to evaluate getter for ${collName}:`, error);
19367
19444
  }
19368
19445
  }
19369
19446
  }
@@ -19929,11 +20006,11 @@ WHERE ${whereConditions.join(' AND ')}
19929
20006
  latestAuthor = link.author;
19930
20007
  }
19931
20008
  }
19932
- // Find matching property (skip those with surrealGetter)
20009
+ // Find matching property (skip those with getter)
19933
20010
  let foundProperty = false;
19934
20011
  for (const [propName, propMeta] of Object.entries(metadata.properties)) {
19935
- if (propMeta.surrealGetter)
19936
- continue; // Handle via surrealGetter evaluation
20012
+ if (propMeta.getter)
20013
+ continue; // Handle via getter evaluation
19937
20014
  if (propMeta.predicate === predicate) {
19938
20015
  // For properties, take the first value (or we could use timestamp to get latest)
19939
20016
  // Note: Empty objects {} are truthy, so we need to check for them explicitly
@@ -20003,11 +20080,11 @@ WHERE ${whereConditions.join(' AND ')}
20003
20080
  break;
20004
20081
  }
20005
20082
  }
20006
- // If not a property, check if it's a collection (skip those with surrealGetter)
20083
+ // If not a property, check if it's a collection (skip those with getter)
20007
20084
  if (!foundProperty) {
20008
20085
  for (const [collName, collMeta] of Object.entries(metadata.collections)) {
20009
- if (collMeta.surrealGetter)
20010
- continue; // Handle via surrealGetter evaluation
20086
+ if (collMeta.getter)
20087
+ continue; // Handle via getter evaluation
20011
20088
  if (collMeta.predicate === predicate) {
20012
20089
  // For collections, accumulate all values with their timestamps and indices for sorting
20013
20090
  if (!instance[collName]) {
@@ -20110,10 +20187,10 @@ WHERE ${whereConditions.join(' AND ')}
20110
20187
  console.error(`Failed to process SurrealDB instance ${base}:`, error);
20111
20188
  }
20112
20189
  }
20113
- // Evaluate SurrealQL getters for all instances (single pass)
20190
+ // Evaluate custom getters for all instances (single pass)
20114
20191
  // This populates collection values needed for where.isInstance filtering
20115
20192
  for (const instance of instances) {
20116
- await this.evaluateSurrealGettersForInstance(instance, perspective, metadata);
20193
+ await this.evaluateCustomGettersForInstance(instance, perspective, metadata);
20117
20194
  }
20118
20195
  // Filter collections by where.isInstance if specified
20119
20196
  // Do this after initial evaluation so collection values exist for filtering