@ai-matrx/records 0.86.2 → 0.87.1

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.
@@ -94,8 +94,9 @@ function optionsTableOf(field) {
94
94
  return typeof id === "string" && id ? id : null;
95
95
  }
96
96
  async function readTableShape(client, tableId) {
97
- const fields = await client.fields({ table_id: tableId });
97
+ const [fields, table] = await Promise.all([client.fields({ table_id: tableId }), client.tableRead({ table_id: tableId, organization_id: client.config.organizationId })]);
98
98
  if (!fields.ok) return fields;
99
+ const titleField = table.ok ? table.data?.title_field ?? null : null;
99
100
  const choiceFields = fields.data.filter((f) => optionsTableOf(f) !== null);
100
101
  const options = await Promise.all(choiceFields.map((f) => client.fieldOptions({ field_id: f.id })));
101
102
  const choicesById = /* @__PURE__ */ new Map();
@@ -119,8 +120,10 @@ async function readTableShape(client, tableId) {
119
120
  type,
120
121
  origin: "custom",
121
122
  required: Boolean(field.required),
123
+ multi: field.multi === true,
122
124
  readOnly: COMPUTED_TYPES.has(field.type) || field.source === "formula" || field.compute_on !== null && field.compute_on !== void 0
123
125
  };
126
+ if (titleField !== null && (titleField === field.key || titleField === field.id)) column.title = true;
124
127
  const choices = choicesById.get(field.id);
125
128
  if (choices) column.choices = choices;
126
129
  if (field.type === "relation" && field.relation_target) column.linksTo = [field.relation_target];
@@ -273,7 +276,8 @@ function isWritingDoor(door) {
273
276
  }
274
277
 
275
278
  // src/core/recordChanges.ts
276
- var listeners = /* @__PURE__ */ new Set();
279
+ var import_global_slot = require("@ai-matrx/kit/global-slot");
280
+ var listeners = (0, import_global_slot.globalSlot)("ai-matrx.records.record-change-listeners", () => /* @__PURE__ */ new Set());
277
281
  function announceRecordChanged(recordId) {
278
282
  for (const listener of [...listeners]) {
279
283
  try {
@@ -283,7 +287,7 @@ function announceRecordChanged(recordId) {
283
287
  }
284
288
  }
285
289
  }
286
- var removed = /* @__PURE__ */ new Set();
290
+ var removed = (0, import_global_slot.globalSlot)("ai-matrx.records.removed-records", () => /* @__PURE__ */ new Set());
287
291
  function markRecordRemoved(recordId) {
288
292
  removed.add(recordId);
289
293
  }
@@ -294,7 +298,7 @@ function onRecordChanged(listener) {
294
298
  listeners.add(listener);
295
299
  return () => listeners.delete(listener);
296
300
  }
297
- var tableListeners = /* @__PURE__ */ new Set();
301
+ var tableListeners = (0, import_global_slot.globalSlot)("ai-matrx.records.table-structure-listeners", () => /* @__PURE__ */ new Set());
298
302
  function announceTableStructureChanged(tableId) {
299
303
  for (const listener of [...tableListeners]) {
300
304
  try {
@@ -610,9 +614,10 @@ function sourceArchivedOf(value) {
610
614
  }
611
615
 
612
616
  // src/ops.ts
617
+ var import_global_slot2 = require("@ai-matrx/kit/global-slot");
613
618
  var REMEMBER_MS = 3e4;
614
619
  var REMEMBER_MAX = 500;
615
- var ours = /* @__PURE__ */ new Map();
620
+ var ours = (0, import_global_slot2.globalSlot)("ai-matrx.records.op-ledger", () => /* @__PURE__ */ new Map());
616
621
  function trim(now) {
617
622
  for (const [id, at] of ours) {
618
623
  if (now - at <= REMEMBER_MS) break;
@@ -6423,7 +6428,15 @@ function createTableDataPort({ client, aliases }) {
6423
6428
  const binding = bindingOf(alias);
6424
6429
  if (!binding) return noSuchAlias(alias);
6425
6430
  const shape = await shapeOf(alias, binding);
6426
- return shape.ok ? { ok: true, data: shape.data.columns } : shape;
6431
+ if (!shape.ok) return shape;
6432
+ return {
6433
+ ok: true,
6434
+ data: shape.data.columns.map((c) => {
6435
+ const target = c.type === "relation" && c.linksTo?.length === 1 ? c.linksTo[0] : null;
6436
+ const served = target ? Object.entries(aliases).find(([, b]) => b.tableId === target)?.[0] : void 0;
6437
+ return served ? { ...c, linksToSource: served } : c;
6438
+ })
6439
+ };
6427
6440
  },
6428
6441
  async list(alias, q = {}, cursor) {
6429
6442
  const binding = bindingOf(alias);