@ai-matrx/records-ui 0.115.67 → 0.115.69

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/index.js CHANGED
@@ -28401,24 +28401,31 @@ import {
28401
28401
 
28402
28402
  // src/unfinishedTable.ts
28403
28403
  var UNFINISHED_WINDOW_MS = 24 * 60 * 60 * 1e3;
28404
- async function findUnfinishedTable(client, wantedName, wantedKeys, now = Date.now()) {
28404
+ var FILLED_WINDOW_MS = 15 * 60 * 1e3;
28405
+ async function findUnfinishedTable(client, wantedName, wantedKeys, wantedRows, now = Date.now()) {
28405
28406
  const name = wantedName.trim().toLowerCase();
28406
28407
  if (!name) return null;
28407
28408
  const listed = await client.tableList();
28408
28409
  if (!listed.ok) return null;
28409
- const candidates = listed.data.filter((t) => {
28410
- if (t.is_kernel || t.name.trim().toLowerCase() !== name) return false;
28411
- const made = Date.parse(t.created_at);
28412
- return Number.isFinite(made) && now - made <= UNFINISHED_WINDOW_MS;
28413
- });
28410
+ const named = listed.data.filter((t) => !t.is_kernel && t.name.trim().toLowerCase() === name);
28411
+ if (named.length === 0) return null;
28412
+ const headers = await client.recordHeaders({ ids: named.map((t) => t.id) });
28413
+ if (!headers.ok) return null;
28414
+ const madeAt = /* @__PURE__ */ new Map();
28415
+ for (const h of headers.data) {
28416
+ const at = Date.parse(h.created_at);
28417
+ if (h.mine && h.deleted_at === null && Number.isFinite(at) && now - at <= UNFINISHED_WINDOW_MS) madeAt.set(h.id, at);
28418
+ }
28419
+ const candidates = named.filter((t) => madeAt.has(t.id));
28414
28420
  if (candidates.length === 0) return null;
28415
28421
  const counted = await client.tableRowCounts({ table_ids: candidates.map((t) => t.id) });
28416
28422
  if (!counted.ok) return null;
28417
- const withRows = new Set(counted.data.filter((c) => c.visible_rows > 0).map((c) => c.table_id));
28423
+ const rowsOf2 = new Map(counted.data.map((c) => [c.table_id, c.visible_rows]));
28418
28424
  const wanted = new Set(wantedKeys);
28419
- const ordered = [...candidates].sort((a, b) => Date.parse(b.created_at) - Date.parse(a.created_at));
28425
+ const ordered = [...candidates].sort((a, b) => (madeAt.get(b.id) ?? 0) - (madeAt.get(a.id) ?? 0));
28420
28426
  for (const t of ordered) {
28421
- if (withRows.has(t.id)) continue;
28427
+ const rows = rowsOf2.get(t.id) ?? 0;
28428
+ if (rows > 0 && (rows > wantedRows || now - (madeAt.get(t.id) ?? 0) > FILLED_WINDOW_MS)) continue;
28422
28429
  const read = await client.fields({ table_id: t.id });
28423
28430
  if (!read.ok) continue;
28424
28431
  const have = new Set(read.data.map((f) => f.key));
@@ -30665,7 +30672,7 @@ function SaveToTable({ source, shapeIndex = 0, onOpenTable, onSaved, onClose, ma
30665
30672
  });
30666
30673
  setPhase("making");
30667
30674
  try {
30668
- const earlier = await findUnfinishedTable(client, name ?? proposedName, fields.map((f) => f.key));
30675
+ const earlier = await findUnfinishedTable(client, name ?? proposedName, fields.map((f) => f.key), rows.length);
30669
30676
  let tableName2;
30670
30677
  let newId;
30671
30678
  if (earlier) {