@ai-matrx/records 0.99.32 → 0.99.33

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/{client-CrwedBYU.d.ts → client-CSfkP7Xf.d.ts} +5 -74
  3. package/dist/{client-D1EwyWfh.d.cts → client-jKf1Z-kp.d.cts} +5 -74
  4. package/dist/core/index.cjs +149 -105
  5. package/dist/core/index.cjs.map +1 -1
  6. package/dist/core/index.d.cts +9 -331
  7. package/dist/core/index.d.ts +9 -331
  8. package/dist/core/index.js +149 -105
  9. package/dist/core/index.js.map +1 -1
  10. package/dist/data/index.cjs +280 -236
  11. package/dist/data/index.cjs.map +1 -1
  12. package/dist/data/index.d.cts +3 -2
  13. package/dist/data/index.d.ts +3 -2
  14. package/dist/data/index.js +280 -236
  15. package/dist/data/index.js.map +1 -1
  16. package/dist/{declareTable-CC5rTTIA.d.ts → declareTable-0emxEewn.d.ts} +1 -1
  17. package/dist/{declareTable-BIIt0Wqt.d.cts → declareTable-800bwUn3.d.cts} +1 -1
  18. package/dist/door-call/index.cjs +1287 -0
  19. package/dist/door-call/index.cjs.map +1 -0
  20. package/dist/door-call/index.d.cts +20 -0
  21. package/dist/door-call/index.d.ts +20 -0
  22. package/dist/door-call/index.js +1264 -0
  23. package/dist/door-call/index.js.map +1 -0
  24. package/dist/{doors-D1yAs0a0.d.cts → doors-BgjRUdxw.d.cts} +13 -1
  25. package/dist/{doors-D2z3kH2i.d.ts → doors-D7_jEKtg.d.ts} +13 -1
  26. package/dist/index.d.cts +5 -4
  27. package/dist/index.d.ts +5 -4
  28. package/dist/{objectOrganization-DazBoDAq.d.cts → objectOrganization-B5YFGVUB.d.cts} +1 -1
  29. package/dist/{objectOrganization-D1ox3gUx.d.ts → objectOrganization-DozoVIxS.d.ts} +1 -1
  30. package/dist/pickListDoors-C-_eAEGL.d.cts +135 -0
  31. package/dist/pickListDoors-DgWVnNRI.d.ts +135 -0
  32. package/dist/questions/index.d.cts +3 -2
  33. package/dist/questions/index.d.ts +3 -2
  34. package/dist/react/index.cjs +363 -319
  35. package/dist/react/index.cjs.map +1 -1
  36. package/dist/react/index.d.cts +37 -22
  37. package/dist/react/index.d.ts +37 -22
  38. package/dist/react/index.js +363 -319
  39. package/dist/react/index.js.map +1 -1
  40. package/dist/scopes/index.cjs +7 -0
  41. package/dist/scopes/index.cjs.map +1 -1
  42. package/dist/scopes/index.d.cts +2 -2
  43. package/dist/scopes/index.d.ts +2 -2
  44. package/dist/scopes/index.js +7 -0
  45. package/dist/scopes/index.js.map +1 -1
  46. package/dist/setup/index.cjs +289 -245
  47. package/dist/setup/index.cjs.map +1 -1
  48. package/dist/setup/index.d.cts +4 -3
  49. package/dist/setup/index.d.ts +4 -3
  50. package/dist/setup/index.js +289 -245
  51. package/dist/setup/index.js.map +1 -1
  52. package/dist/table-logic-BPquabNN.d.ts +328 -0
  53. package/dist/table-logic-CTh6lwaq.d.cts +328 -0
  54. package/dist/typed-table/index.cjs +280 -236
  55. package/dist/typed-table/index.cjs.map +1 -1
  56. package/dist/typed-table/index.d.cts +4 -3
  57. package/dist/typed-table/index.d.ts +4 -3
  58. package/dist/typed-table/index.js +280 -236
  59. package/dist/typed-table/index.js.map +1 -1
  60. package/dist/views/index.d.cts +3 -2
  61. package/dist/views/index.d.ts +3 -2
  62. package/package.json +13 -3
@@ -6079,6 +6079,99 @@ function isWritingDoor(door) {
6079
6079
  return /(_declare|_set(_|$)|_update|_write|_delete|_restore|_archive|_upsert|_reparent|_change|_duplicate|_move|_decide|_run$|_submit|_publish|_import_|_start$|_complete|_sign$|_add$|_retire|_propose|_promote|_land$|_pin$|_mute|_snooze|_unsnooze|_clear|_unclear|_revoke|_issue|_bind|_unbind|_apply|_backfill|_sync$|_decorate|_designate|_ensure|^migrate_|^set_table_|^home_add|^capture_|^claim_|^record_stage|^anon_|^io_import_|^io_comment_resolve|^enrich_(declare|land|pin)|^field_(declare|duplicate|propose|restore|retire|update)|^table_(declare|ensure|from_example|move|sync)|^value_restore|^relation_own)/.test(door);
6080
6080
  }
6081
6081
 
6082
+ // src/core/doorCall.ts
6083
+ var DEFAULT_DOOR_SCHEMA = "custom";
6084
+ function canonicalArgs(value) {
6085
+ return JSON.stringify(
6086
+ value,
6087
+ (_key, held) => held && typeof held === "object" && !Array.isArray(held) ? Object.fromEntries(Object.keys(held).sort().map((k) => [k, held[k]])) : held
6088
+ );
6089
+ }
6090
+ var A_PERSONS_REFUSAL = /* @__PURE__ */ new Set([
6091
+ "refused_by_rule",
6092
+ "stale_write",
6093
+ "invalid_argument",
6094
+ "already_exists",
6095
+ "missing_reference"
6096
+ ]);
6097
+ function isAPersonsRefusal(code) {
6098
+ return A_PERSONS_REFUSAL.has(code);
6099
+ }
6100
+ function recordsErrorSink(onError) {
6101
+ return onError ?? ((e) => {
6102
+ const line = `[@ai-matrx/records] ${e.where}: ${e.code} \u2014 ${e.message}${e.hint ? ` (${e.hint})` : ""}`;
6103
+ if (isAPersonsRefusal(e.code)) console.info(line);
6104
+ else console.error(line);
6105
+ });
6106
+ }
6107
+ function doorAbsentRefusal(name, owedBy) {
6108
+ return {
6109
+ code: "door_absent",
6110
+ message: `The record store has no door \`custom.${name}\` yet, so this call was not made. Nothing was read and nothing was written.`,
6111
+ hint: owedBy ? `That door is ${owedBy}. Until it lands, this call refuses rather than guessing: an empty answer here would read like "there is nothing", which is a different sentence.` : `No lane in the build book claims this door. Either the name is wrong, or the door was removed from the store and this package has not been regenerated \u2014 run \`pnpm records:generate\`.`
6112
+ };
6113
+ }
6114
+ function primedDoorAnswer(door, args) {
6115
+ const look = LOOK_WRITES[door];
6116
+ if (look) {
6117
+ dropPrimedDoorAnswers(look);
6118
+ return null;
6119
+ }
6120
+ if (isWritingDoor(door)) {
6121
+ dropPrimedDoorAnswers();
6122
+ return null;
6123
+ }
6124
+ return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
6125
+ }
6126
+ function createDoorCall(options) {
6127
+ const { dataSource, doorReady: doorReady2, held, wrote } = options;
6128
+ const schema = options.schema ?? DEFAULT_DOOR_SCHEMA;
6129
+ const scream = recordsErrorSink(options.onError);
6130
+ const absent = options.absent ?? ((door) => doorAbsentRefusal(door));
6131
+ const readsInFlight = /* @__PURE__ */ new Map();
6132
+ const say = (refusal, where) => scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
6133
+ return async function callDoor(door, args, where, opts) {
6134
+ const primed = primedDoorAnswer(door, args);
6135
+ if (primed) return ok(primed.data);
6136
+ if (held) {
6137
+ const bundled = await held(door, args);
6138
+ if (bundled) return ok(bundled.data);
6139
+ }
6140
+ if (doorReady2 && !doorReady2(door)) {
6141
+ const refusal = absent(door);
6142
+ say(refusal, where);
6143
+ return err(refusal);
6144
+ }
6145
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
6146
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
6147
+ const response = await (flying ?? (() => {
6148
+ const call = Promise.resolve(dataSource.rpc(`${door}`, args, { schema }));
6149
+ if (flightKey) {
6150
+ readsInFlight.set(flightKey, call);
6151
+ const forget = () => {
6152
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
6153
+ };
6154
+ call.then(forget, forget);
6155
+ }
6156
+ return call;
6157
+ })());
6158
+ if (response.error) {
6159
+ const code = response.error.code;
6160
+ const refusal = !doorReady2 && (code === "PGRST202" || code === "42883") ? absent(door) : mapPgError(response.error, where);
6161
+ if (opts?.quiet) console.info(`[@ai-matrx/records] ${where}: ${refusal.code} - ${refusal.message}`);
6162
+ else say(refusal, where);
6163
+ return err(refusal);
6164
+ }
6165
+ if (isWritingDoor(door) || LOOK_WRITES[door]) {
6166
+ const tableId = args["p_table_id"];
6167
+ wrote?.(door, args);
6168
+ forgetPrimedTablePageBundlesOf(typeof tableId === "string" ? tableId : null);
6169
+ dropPrimedDoorAnswers(LOOK_WRITES[door]);
6170
+ }
6171
+ return ok(response.data);
6172
+ };
6173
+ }
6174
+
6082
6175
  // src/core/recordChanges.ts
6083
6176
  var import_global_slot2 = require("@ai-matrx/kit/global-slot");
6084
6177
  var listeners = (0, import_global_slot2.globalSlot)("ai-matrx.records.record-change-listeners", () => /* @__PURE__ */ new Set());
@@ -6830,11 +6923,51 @@ function createScopeDoors(call) {
6830
6923
  source_type: String(envelope.data?.source_type ?? cell.source_type ?? "ai_enriched")
6831
6924
  }
6832
6925
  };
6926
+ },
6927
+ tableProvision({ organization_id, item_id, scope_id, home_id }) {
6928
+ return call(
6929
+ "scope_table_provision",
6930
+ { p_organization_id: organization_id, p_item_id: item_id, p_scope_id: scope_id, p_home_id: home_id ?? null },
6931
+ "scopeTableProvision"
6932
+ );
6833
6933
  }
6834
6934
  };
6835
6935
  return doors;
6836
6936
  }
6837
6937
 
6938
+ // src/core/pickListDoors.ts
6939
+ var PICK_LIST_DOORS = {
6940
+ pickListGet: "pick_list_get",
6941
+ pickListForSelection: "pick_list_for_selection",
6942
+ pickListUpdate: "pick_list_update"
6943
+ };
6944
+ function createPickListDoors(callDoor) {
6945
+ return {
6946
+ async pickListGet({ list_id }) {
6947
+ return callDoor(PICK_LIST_DOORS.pickListGet, { p_list_id: list_id }, "pickListGet");
6948
+ },
6949
+ async pickListForSelection({ list_id }) {
6950
+ return callDoor(
6951
+ PICK_LIST_DOORS.pickListForSelection,
6952
+ { p_list_id: list_id },
6953
+ "pickListForSelection"
6954
+ );
6955
+ },
6956
+ async pickListUpdate({ list_id, list_name, description, items }) {
6957
+ return callDoor(
6958
+ PICK_LIST_DOORS.pickListUpdate,
6959
+ {
6960
+ p_list_id: list_id,
6961
+ p_list_name: list_name ?? null,
6962
+ p_description: description ?? null,
6963
+ p_items: items ? [...items] : null
6964
+ },
6965
+ "pickListUpdate"
6966
+ );
6967
+ }
6968
+ };
6969
+ }
6970
+
6838
6971
  // src/core/keysetCursor.ts
6839
6972
  function utf8ToBinary(text2) {
6840
6973
  let out = "";
@@ -6949,12 +7082,7 @@ function doorReady(config, name) {
6949
7082
  return DOOR_NAMES.has(name) || Boolean(config?.knownDoors?.includes(name));
6950
7083
  }
6951
7084
  function doorAbsent(name) {
6952
- const owed = OWED_BY[name];
6953
- return {
6954
- code: "door_absent",
6955
- message: `The record store has no door \`custom.${name}\` yet, so this call was not made. Nothing was read and nothing was written.`,
6956
- hint: owed ? `That door is ${owed}. Until it lands, this call refuses rather than guessing: an empty answer here would read like "there is nothing", which is a different sentence.` : `No lane in the build book claims this door. Either the name is wrong, or the door was removed from the store and this package has not been regenerated \u2014 run \`pnpm records:generate\`.`
6957
- };
7085
+ return doorAbsentRefusal(name, OWED_BY[name]);
6958
7086
  }
6959
7087
  var DOORS = {
6960
7088
  // THE READ DOOR (DOOR-1). Every read of a record's values goes through these
@@ -7725,29 +7853,6 @@ function intersectIds(sets) {
7725
7853
 
7726
7854
  // src/core/client.ts
7727
7855
  var DEFAULT_SCHEMA = "custom";
7728
- function canonicalArgs(value) {
7729
- return JSON.stringify(
7730
- value,
7731
- (_key, held) => held && typeof held === "object" && !Array.isArray(held) ? Object.fromEntries(Object.keys(held).sort().map((k) => [k, held[k]])) : held
7732
- );
7733
- }
7734
- var A_PERSONS_REFUSAL = /* @__PURE__ */ new Set([
7735
- "refused_by_rule",
7736
- "stale_write",
7737
- "invalid_argument",
7738
- "already_exists",
7739
- "missing_reference"
7740
- ]);
7741
- function isAPersonsRefusal(code) {
7742
- return A_PERSONS_REFUSAL.has(code);
7743
- }
7744
- function sink(config) {
7745
- return config.onError ?? ((e) => {
7746
- const line = `[@ai-matrx/records] ${e.where}: ${e.code} \u2014 ${e.message}${e.hint ? ` (${e.hint})` : ""}`;
7747
- if (isAPersonsRefusal(e.code)) console.info(line);
7748
- else console.error(line);
7749
- });
7750
- }
7751
7856
  function withTableFacts(tables, facts, me) {
7752
7857
  if (!facts) return [...tables];
7753
7858
  const byId = new Map(facts.map((f) => [f.table_id, f]));
@@ -7775,7 +7880,7 @@ function createRecordsClient(given) {
7775
7880
  const org = config.organizationId;
7776
7881
  const ledger = config.opLedger ?? defaultOpLedger;
7777
7882
  const mintOp = () => ledger.mint();
7778
- const scream = sink(config);
7883
+ const scream = recordsErrorSink(config.onError);
7779
7884
  const BUNDLE_TTL_MS = 1e4;
7780
7885
  const BUNDLE_OPENERS = /* @__PURE__ */ new Set(["applicable_fields", "views", "view_look_read", "table_decorations", "row_actions", "reverse_columns", "record_change_actions", "grid_layout", "io_imports"]);
7781
7886
  const bundleParts = /* @__PURE__ */ new Map();
@@ -7917,56 +8022,20 @@ function createRecordsClient(given) {
7917
8022
  bundleAsked.delete(tableId);
7918
8023
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
7919
8024
  }
7920
- function primedFor(door, args) {
7921
- const look = LOOK_WRITES[door];
7922
- if (look) {
7923
- dropPrimedDoorAnswers(look);
7924
- return null;
7925
- }
7926
- if (isWritingDoor(door)) {
7927
- dropPrimedDoorAnswers();
7928
- return null;
7929
- }
7930
- return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
7931
- }
7932
- const readsInFlight = /* @__PURE__ */ new Map();
7933
- async function callDoor(door, args, where, opts) {
7934
- const primed = primedFor(door, args);
7935
- if (primed) return ok(primed.data);
7936
- const bundled = await fromBundle(door, args);
7937
- if (bundled) return ok(bundled.data);
7938
- if (!doorReady(config, door)) {
7939
- const refusal = doorAbsent(door);
7940
- scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
7941
- return err(refusal);
7942
- }
7943
- const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
7944
- const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
7945
- const response = await (flying ?? (() => {
7946
- const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
7947
- if (flightKey) {
7948
- readsInFlight.set(flightKey, call);
7949
- const forget = () => {
7950
- if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
7951
- };
7952
- call.then(forget, forget);
7953
- }
7954
- return call;
7955
- })());
7956
- if (response.error) {
7957
- const refusal = mapPgError(response.error, where);
7958
- if (opts?.quiet) console.info(`[@ai-matrx/records] ${where}: ${refusal.code} - ${refusal.message}`);
7959
- else scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
7960
- return err(refusal);
7961
- }
7962
- if (isWritingDoor(door) || LOOK_WRITES[door]) {
8025
+ const primedFor = primedDoorAnswer;
8026
+ const callDoor = createDoorCall({
8027
+ dataSource: config.dataSource,
8028
+ schema,
8029
+ onError: scream,
8030
+ doorReady: (door) => doorReady(config, door),
8031
+ absent: doorAbsent,
8032
+ held: fromBundle,
8033
+ wrote: (_door, args) => {
7963
8034
  const tableId = args["p_table_id"];
7964
8035
  bundleDrop(typeof tableId === "string" ? tableId : null);
7965
- forgetPrimedTablePageBundlesOf(typeof tableId === "string" ? tableId : null);
7966
- dropPrimedDoorAnswers(LOOK_WRITES[door]);
7967
8036
  }
7968
- return ok(response.data);
7969
- }
8037
+ });
8038
+ const scopes = createScopeDoors(callDoor);
7970
8039
  function structureMoved(tableId, result) {
7971
8040
  if (result.ok) {
7972
8041
  bundleDrop(tableId);
@@ -8165,7 +8234,7 @@ function createRecordsClient(given) {
8165
8234
  const unavailableReason = (error) => `${error.message}${error.hint ? ` ${error.hint}` : ""}`;
8166
8235
  const client = {
8167
8236
  config,
8168
- scopes: createScopeDoors(callDoor),
8237
+ scopes,
8169
8238
  async recordWrite({ table_id, data }) {
8170
8239
  const result = await callDoor(
8171
8240
  DOORS.recordWrite,
@@ -8864,28 +8933,7 @@ function createRecordsClient(given) {
8864
8933
  "fieldOptions"
8865
8934
  );
8866
8935
  },
8867
- async pickListGet({ list_id }) {
8868
- return callDoor(DOORS.pickListGet, { p_list_id: list_id }, "pickListGet");
8869
- },
8870
- async pickListForSelection({ list_id }) {
8871
- return callDoor(
8872
- DOORS.pickListForSelection,
8873
- { p_list_id: list_id },
8874
- "pickListForSelection"
8875
- );
8876
- },
8877
- async pickListUpdate({ list_id, list_name, description, items }) {
8878
- return callDoor(
8879
- DOORS.pickListUpdate,
8880
- {
8881
- p_list_id: list_id,
8882
- p_list_name: list_name ?? null,
8883
- p_description: description ?? null,
8884
- p_items: items ? [...items] : null
8885
- },
8886
- "pickListUpdate"
8887
- );
8888
- },
8936
+ ...createPickListDoors(callDoor),
8889
8937
  async fieldChoiceUsage({ field_id }) {
8890
8938
  const result = await callDoor(
8891
8939
  DOORS.fieldChoiceUsage,
@@ -11419,11 +11467,7 @@ function createRecordsClient(given) {
11419
11467
  );
11420
11468
  },
11421
11469
  async scopeTableProvision({ home_id, item_id, scope_id }) {
11422
- return callDoor(
11423
- DOORS.scopeTableProvision,
11424
- { p_organization_id: org, p_item_id: item_id, p_scope_id: scope_id, p_home_id: home_id ?? null },
11425
- "scopeTableProvision"
11426
- );
11470
+ return scopes.tableProvision({ organization_id: org, item_id, scope_id, home_id: home_id ?? null });
11427
11471
  },
11428
11472
  async tableRowCounts({ table_ids }) {
11429
11473
  return callDoor(