@ai-matrx/records 0.58.0 → 0.58.2

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.cjs CHANGED
@@ -122,12 +122,15 @@ __export(src_exports, {
122
122
  memoryStore: () => memoryStore,
123
123
  mintClientKey: () => mintClientKey,
124
124
  mintOpId: () => mintOpId,
125
+ moveConsequence: () => moveConsequence,
125
126
  moveInOrder: () => moveInOrder,
126
127
  offeredAsContext: () => offeredAsContext,
127
128
  ok: () => ok,
128
129
  openCaptureQueue: () => openCaptureQueue,
129
130
  optionKey: () => optionKey,
130
131
  optionLabel: () => optionLabel,
132
+ parseTableHome: () => parseTableHome,
133
+ parseTableMoved: () => parseTableMoved,
131
134
  portalArchiveConsequence: () => portalArchiveConsequence,
132
135
  portalConfirmLine: () => portalConfirmLine,
133
136
  portalPath: () => portalPath,
@@ -803,6 +806,66 @@ function keptTableHref(fact, hrefs) {
803
806
  }
804
807
  return hrefs.table(fact.table_id);
805
808
  }
809
+ function countOf(value) {
810
+ return typeof value === "number" && Number.isFinite(value) ? value : 0;
811
+ }
812
+ function wordsOf(value) {
813
+ return typeof value === "string" && value.length > 0 ? value : null;
814
+ }
815
+ function parseTableHome(raw) {
816
+ if (!raw || typeof raw !== "object") return null;
817
+ const row = raw;
818
+ const table = row.table;
819
+ const org = row.organization;
820
+ if (!table || !org || !wordsOf(table.id) || !wordsOf(org.id) || !wordsOf(org.name)) return null;
821
+ const carries = row.carries ?? {};
822
+ const destinations = Array.isArray(row.destinations) ? row.destinations : [];
823
+ return {
824
+ table: { id: String(table.id), name: wordsOf(table.name) ?? "This table", version: countOf(table.version) },
825
+ organization: { id: String(org.id), name: String(org.name) },
826
+ mayMove: row.may_move === true,
827
+ whyNot: wordsOf(row.why_not),
828
+ heldBy: Array.isArray(row.held_by) ? row.held_by.filter((s) => typeof s === "string") : [],
829
+ destinations: destinations.filter((d) => !!d && typeof d === "object" && !!wordsOf(d.id)).map((d) => ({
830
+ id: String(d.id),
831
+ name: wordsOf(d.name) ?? "An organization",
832
+ role: wordsOf(d.role) ?? "member",
833
+ ok: d.ok === true,
834
+ why: wordsOf(d.why)
835
+ })),
836
+ carries: {
837
+ fields: countOf(carries.fields),
838
+ records: countOf(carries.records),
839
+ inTrash: countOf(carries.in_trash),
840
+ choiceLists: countOf(carries.choice_lists),
841
+ withIt: countOf(carries.with_it),
842
+ tablesInside: countOf(carries.tables_inside),
843
+ linksAcross: countOf(carries.links_across)
844
+ }
845
+ };
846
+ }
847
+ function parseTableMoved(raw) {
848
+ const row = raw ?? {};
849
+ const to = row.to ?? {};
850
+ const from = row.from ?? {};
851
+ const table = row.table ?? {};
852
+ if (row.moved !== true || !wordsOf(to.id)) return null;
853
+ return {
854
+ to: { id: String(to.id), name: wordsOf(to.name) ?? "the new organization" },
855
+ from: { id: wordsOf(from.id) ?? "", name: wordsOf(from.name) ?? "its old organization" },
856
+ tableName: wordsOf(table.name) ?? "The table"
857
+ };
858
+ }
859
+ function plural(n, one, many) {
860
+ return `${n} ${n === 1 ? one : many}`;
861
+ }
862
+ function moveConsequence(home, to) {
863
+ const c = home.carries;
864
+ const parts = [plural(c.fields, "column", "columns"), plural(c.records, "row", "rows")];
865
+ if (c.inTrash > 0) parts.push(`${c.inTrash} in the trash`);
866
+ const extra = c.choiceLists + c.withIt;
867
+ return `${home.table.name} moves to ${to.name} with its ${parts.join(", ")}` + (c.tablesInside > 0 ? `, the ${plural(c.tablesInside, "table", "tables")} that live${c.tablesInside === 1 ? "s" : ""} inside it or its rows (with their own rows)` : "") + (extra > 0 ? `, and ${plural(extra, "thing", "things")} built only on it (choice lists, rules, dashboards, templates)` : "") + `, its comments, forms, saved views and history. ` + (c.linksAcross > 0 ? `${plural(c.linksAcross, "link", "links")} to rows that stay in ${home.organization.name} keep${c.linksAcross === 1 ? "s" : ""} pointing there, across the two organizations. ` : "") + `People who see it only because they are in ${home.organization.name} stop seeing it; people it was shared with by name keep it. You can move it back from the same place.`;
868
+ }
806
869
 
807
870
  // src/capture-queue.ts
808
871
  var DB_NAME = "matrx-capture";
@@ -872,7 +935,7 @@ function memoryStore() {
872
935
  setMeta: async (key, value) => void meta.set(key, value)
873
936
  };
874
937
  }
875
- function countOf(items) {
938
+ function countOf2(items) {
876
939
  const c = { waiting: 0, sending: 0, refused: 0, landed: 0 };
877
940
  for (const i of items) c[i.state] += 1;
878
941
  return c;
@@ -889,7 +952,7 @@ function openCaptureQueue(opts) {
889
952
  const announce = async () => {
890
953
  if (!opts.onChange) return;
891
954
  const items = await store.all();
892
- opts.onChange(countOf(items), items);
955
+ opts.onChange(countOf2(items), items);
893
956
  };
894
957
  const oldestFirst = (items) => items.slice().sort((a, b) => a.captured_at.localeCompare(b.captured_at));
895
958
  const queue = {
@@ -918,7 +981,7 @@ function openCaptureQueue(opts) {
918
981
  return key;
919
982
  },
920
983
  list: () => store.all().then(oldestFirst),
921
- counts: () => store.all().then(countOf),
984
+ counts: () => store.all().then(countOf2),
922
985
  async sync() {
923
986
  if (syncing) return syncing;
924
987
  syncing = (async () => {