@ai-matrx/records-ui 0.4.3 → 0.5.4

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
@@ -872,17 +872,18 @@ async function ensureSystemTable(client, spec) {
872
872
  if (found) {
873
873
  const grown = await addMissingFields(client, spec, found.id);
874
874
  if (!grown.ok) return grown;
875
+ const levelled = await reconcileFieldShapes(client, spec, found.id);
876
+ if (!levelled.ok) return levelled;
875
877
  return { ok: true, data: found.id };
876
878
  }
877
879
  let settle = () => void 0;
878
880
  let fail = () => void 0;
879
- inFlight.set(
880
- cacheKey,
881
- new Promise((resolve, reject) => {
882
- settle = resolve;
883
- fail = reject;
884
- })
885
- );
881
+ const pending = new Promise((resolve, reject) => {
882
+ settle = resolve;
883
+ fail = reject;
884
+ });
885
+ pending.catch(() => void 0);
886
+ inFlight.set(cacheKey, pending);
886
887
  const declared = await declare(client, spec);
887
888
  if (declared.ok) settle(declared.data);
888
889
  else {
@@ -911,6 +912,22 @@ async function addMissingFields(client, spec, tableId) {
911
912
  }
912
913
  return { ok: true, data: true };
913
914
  }
915
+ async function reconcileFieldShapes(client, spec, tableId) {
916
+ const held = await client.fields({ table_id: tableId });
917
+ if (!held.ok) return held;
918
+ const byKey = new Map(held.data.map((f) => [f.key, f]));
919
+ for (const field of spec.fields) {
920
+ const have = byKey.get(field.key);
921
+ if (!have) continue;
922
+ const patch = {};
923
+ if (have.type !== field.type) patch.type = field.type;
924
+ if (have.multi !== (field.multi ?? false)) patch.multi = field.multi ?? false;
925
+ if (Object.keys(patch).length === 0) continue;
926
+ const written = await client.recordUpdate({ record_id: have.id, patch });
927
+ if (!written.ok) return written;
928
+ }
929
+ return { ok: true, data: true };
930
+ }
914
931
  function fieldDocument(field, tableId) {
915
932
  return {
916
933
  key: field.key,