@ai-matrx/records 0.99.32 → 0.99.34

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
@@ -5730,6 +5730,99 @@ function isWritingDoor(door) {
5730
5730
  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);
5731
5731
  }
5732
5732
 
5733
+ // src/core/doorCall.ts
5734
+ var DEFAULT_DOOR_SCHEMA = "custom";
5735
+ function canonicalArgs(value) {
5736
+ return JSON.stringify(
5737
+ value,
5738
+ (_key, held) => held && typeof held === "object" && !Array.isArray(held) ? Object.fromEntries(Object.keys(held).sort().map((k) => [k, held[k]])) : held
5739
+ );
5740
+ }
5741
+ var A_PERSONS_REFUSAL = /* @__PURE__ */ new Set([
5742
+ "refused_by_rule",
5743
+ "stale_write",
5744
+ "invalid_argument",
5745
+ "already_exists",
5746
+ "missing_reference"
5747
+ ]);
5748
+ function isAPersonsRefusal(code) {
5749
+ return A_PERSONS_REFUSAL.has(code);
5750
+ }
5751
+ function recordsErrorSink(onError) {
5752
+ return onError ?? ((e) => {
5753
+ const line = `[@ai-matrx/records] ${e.where}: ${e.code} \u2014 ${e.message}${e.hint ? ` (${e.hint})` : ""}`;
5754
+ if (isAPersonsRefusal(e.code)) console.info(line);
5755
+ else console.error(line);
5756
+ });
5757
+ }
5758
+ function doorAbsentRefusal(name, owedBy) {
5759
+ return {
5760
+ code: "door_absent",
5761
+ message: `The record store has no door \`custom.${name}\` yet, so this call was not made. Nothing was read and nothing was written.`,
5762
+ 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\`.`
5763
+ };
5764
+ }
5765
+ function primedDoorAnswer(door, args) {
5766
+ const look = LOOK_WRITES[door];
5767
+ if (look) {
5768
+ dropPrimedDoorAnswers(look);
5769
+ return null;
5770
+ }
5771
+ if (isWritingDoor(door)) {
5772
+ dropPrimedDoorAnswers();
5773
+ return null;
5774
+ }
5775
+ return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
5776
+ }
5777
+ function createDoorCall(options) {
5778
+ const { dataSource, doorReady: doorReady2, held, wrote } = options;
5779
+ const schema = options.schema ?? DEFAULT_DOOR_SCHEMA;
5780
+ const scream = recordsErrorSink(options.onError);
5781
+ const absent = options.absent ?? ((door) => doorAbsentRefusal(door));
5782
+ const readsInFlight = /* @__PURE__ */ new Map();
5783
+ const say = (refusal, where) => scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
5784
+ return async function callDoor(door, args, where, opts) {
5785
+ const primed = primedDoorAnswer(door, args);
5786
+ if (primed) return ok(primed.data);
5787
+ if (held) {
5788
+ const bundled = await held(door, args);
5789
+ if (bundled) return ok(bundled.data);
5790
+ }
5791
+ if (doorReady2 && !doorReady2(door)) {
5792
+ const refusal = absent(door);
5793
+ say(refusal, where);
5794
+ return err(refusal);
5795
+ }
5796
+ const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
5797
+ const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
5798
+ const response = await (flying ?? (() => {
5799
+ const call = Promise.resolve(dataSource.rpc(`${door}`, args, { schema }));
5800
+ if (flightKey) {
5801
+ readsInFlight.set(flightKey, call);
5802
+ const forget = () => {
5803
+ if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
5804
+ };
5805
+ call.then(forget, forget);
5806
+ }
5807
+ return call;
5808
+ })());
5809
+ if (response.error) {
5810
+ const code = response.error.code;
5811
+ const refusal = !doorReady2 && (code === "PGRST202" || code === "42883") ? absent(door) : mapPgError(response.error, where);
5812
+ if (opts?.quiet) console.info(`[@ai-matrx/records] ${where}: ${refusal.code} - ${refusal.message}`);
5813
+ else say(refusal, where);
5814
+ return err(refusal);
5815
+ }
5816
+ if (isWritingDoor(door) || LOOK_WRITES[door]) {
5817
+ const tableId = args["p_table_id"];
5818
+ wrote?.(door, args);
5819
+ forgetPrimedTablePageBundlesOf(typeof tableId === "string" ? tableId : null);
5820
+ dropPrimedDoorAnswers(LOOK_WRITES[door]);
5821
+ }
5822
+ return ok(response.data);
5823
+ };
5824
+ }
5825
+
5733
5826
  // src/core/recordChanges.ts
5734
5827
  import { globalSlot as globalSlot2 } from "@ai-matrx/kit/global-slot";
5735
5828
  var listeners = globalSlot2("ai-matrx.records.record-change-listeners", () => /* @__PURE__ */ new Set());
@@ -6481,11 +6574,51 @@ function createScopeDoors(call) {
6481
6574
  source_type: String(envelope.data?.source_type ?? cell.source_type ?? "ai_enriched")
6482
6575
  }
6483
6576
  };
6577
+ },
6578
+ tableProvision({ organization_id, item_id, scope_id, home_id }) {
6579
+ return call(
6580
+ "scope_table_provision",
6581
+ { p_organization_id: organization_id, p_item_id: item_id, p_scope_id: scope_id, p_home_id: home_id ?? null },
6582
+ "scopeTableProvision"
6583
+ );
6484
6584
  }
6485
6585
  };
6486
6586
  return doors;
6487
6587
  }
6488
6588
 
6589
+ // src/core/pickListDoors.ts
6590
+ var PICK_LIST_DOORS = {
6591
+ pickListGet: "pick_list_get",
6592
+ pickListForSelection: "pick_list_for_selection",
6593
+ pickListUpdate: "pick_list_update"
6594
+ };
6595
+ function createPickListDoors(callDoor) {
6596
+ return {
6597
+ async pickListGet({ list_id }) {
6598
+ return callDoor(PICK_LIST_DOORS.pickListGet, { p_list_id: list_id }, "pickListGet");
6599
+ },
6600
+ async pickListForSelection({ list_id }) {
6601
+ return callDoor(
6602
+ PICK_LIST_DOORS.pickListForSelection,
6603
+ { p_list_id: list_id },
6604
+ "pickListForSelection"
6605
+ );
6606
+ },
6607
+ async pickListUpdate({ list_id, list_name, description, items }) {
6608
+ return callDoor(
6609
+ PICK_LIST_DOORS.pickListUpdate,
6610
+ {
6611
+ p_list_id: list_id,
6612
+ p_list_name: list_name ?? null,
6613
+ p_description: description ?? null,
6614
+ p_items: items ? [...items] : null
6615
+ },
6616
+ "pickListUpdate"
6617
+ );
6618
+ }
6619
+ };
6620
+ }
6621
+
6489
6622
  // src/core/keysetCursor.ts
6490
6623
  function utf8ToBinary(text2) {
6491
6624
  let out = "";
@@ -6600,12 +6733,7 @@ function doorReady(config, name) {
6600
6733
  return DOOR_NAMES.has(name) || Boolean(config?.knownDoors?.includes(name));
6601
6734
  }
6602
6735
  function doorAbsent(name) {
6603
- const owed = OWED_BY[name];
6604
- return {
6605
- code: "door_absent",
6606
- message: `The record store has no door \`custom.${name}\` yet, so this call was not made. Nothing was read and nothing was written.`,
6607
- 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\`.`
6608
- };
6736
+ return doorAbsentRefusal(name, OWED_BY[name]);
6609
6737
  }
6610
6738
  var DOORS = {
6611
6739
  // THE READ DOOR (DOOR-1). Every read of a record's values goes through these
@@ -7376,29 +7504,6 @@ function intersectIds(sets) {
7376
7504
 
7377
7505
  // src/core/client.ts
7378
7506
  var DEFAULT_SCHEMA = "custom";
7379
- function canonicalArgs(value) {
7380
- return JSON.stringify(
7381
- value,
7382
- (_key, held) => held && typeof held === "object" && !Array.isArray(held) ? Object.fromEntries(Object.keys(held).sort().map((k) => [k, held[k]])) : held
7383
- );
7384
- }
7385
- var A_PERSONS_REFUSAL = /* @__PURE__ */ new Set([
7386
- "refused_by_rule",
7387
- "stale_write",
7388
- "invalid_argument",
7389
- "already_exists",
7390
- "missing_reference"
7391
- ]);
7392
- function isAPersonsRefusal(code) {
7393
- return A_PERSONS_REFUSAL.has(code);
7394
- }
7395
- function sink(config) {
7396
- return config.onError ?? ((e) => {
7397
- const line = `[@ai-matrx/records] ${e.where}: ${e.code} \u2014 ${e.message}${e.hint ? ` (${e.hint})` : ""}`;
7398
- if (isAPersonsRefusal(e.code)) console.info(line);
7399
- else console.error(line);
7400
- });
7401
- }
7402
7507
  function withTableFacts(tables, facts, me) {
7403
7508
  if (!facts) return [...tables];
7404
7509
  const byId = new Map(facts.map((f) => [f.table_id, f]));
@@ -7426,7 +7531,7 @@ function createRecordsClient(given) {
7426
7531
  const org = config.organizationId;
7427
7532
  const ledger = config.opLedger ?? defaultOpLedger;
7428
7533
  const mintOp = () => ledger.mint();
7429
- const scream = sink(config);
7534
+ const scream = recordsErrorSink(config.onError);
7430
7535
  const BUNDLE_TTL_MS = 1e4;
7431
7536
  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"]);
7432
7537
  const bundleParts = /* @__PURE__ */ new Map();
@@ -7568,56 +7673,20 @@ function createRecordsClient(given) {
7568
7673
  bundleAsked.delete(tableId);
7569
7674
  for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
7570
7675
  }
7571
- function primedFor(door, args) {
7572
- const look = LOOK_WRITES[door];
7573
- if (look) {
7574
- dropPrimedDoorAnswers(look);
7575
- return null;
7576
- }
7577
- if (isWritingDoor(door)) {
7578
- dropPrimedDoorAnswers();
7579
- return null;
7580
- }
7581
- return takePrimedDoorAnswer(`${door}|${canonicalArgs(args)}`);
7582
- }
7583
- const readsInFlight = /* @__PURE__ */ new Map();
7584
- async function callDoor(door, args, where, opts) {
7585
- const primed = primedFor(door, args);
7586
- if (primed) return ok(primed.data);
7587
- const bundled = await fromBundle(door, args);
7588
- if (bundled) return ok(bundled.data);
7589
- if (!doorReady(config, door)) {
7590
- const refusal = doorAbsent(door);
7591
- scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
7592
- return err(refusal);
7593
- }
7594
- const flightKey = isWritingDoor(door) ? null : `${door}|${canonicalArgs(args)}`;
7595
- const flying = flightKey ? readsInFlight.get(flightKey) : void 0;
7596
- const response = await (flying ?? (() => {
7597
- const call = Promise.resolve(config.dataSource.rpc(`${door}`, args, { schema }));
7598
- if (flightKey) {
7599
- readsInFlight.set(flightKey, call);
7600
- const forget = () => {
7601
- if (readsInFlight.get(flightKey) === call) readsInFlight.delete(flightKey);
7602
- };
7603
- call.then(forget, forget);
7604
- }
7605
- return call;
7606
- })());
7607
- if (response.error) {
7608
- const refusal = mapPgError(response.error, where);
7609
- if (opts?.quiet) console.info(`[@ai-matrx/records] ${where}: ${refusal.code} - ${refusal.message}`);
7610
- else scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where });
7611
- return err(refusal);
7612
- }
7613
- if (isWritingDoor(door) || LOOK_WRITES[door]) {
7676
+ const primedFor = primedDoorAnswer;
7677
+ const callDoor = createDoorCall({
7678
+ dataSource: config.dataSource,
7679
+ schema,
7680
+ onError: scream,
7681
+ doorReady: (door) => doorReady(config, door),
7682
+ absent: doorAbsent,
7683
+ held: fromBundle,
7684
+ wrote: (_door, args) => {
7614
7685
  const tableId = args["p_table_id"];
7615
7686
  bundleDrop(typeof tableId === "string" ? tableId : null);
7616
- forgetPrimedTablePageBundlesOf(typeof tableId === "string" ? tableId : null);
7617
- dropPrimedDoorAnswers(LOOK_WRITES[door]);
7618
7687
  }
7619
- return ok(response.data);
7620
- }
7688
+ });
7689
+ const scopes = createScopeDoors(callDoor);
7621
7690
  function structureMoved(tableId, result) {
7622
7691
  if (result.ok) {
7623
7692
  bundleDrop(tableId);
@@ -7816,7 +7885,7 @@ function createRecordsClient(given) {
7816
7885
  const unavailableReason = (error) => `${error.message}${error.hint ? ` ${error.hint}` : ""}`;
7817
7886
  const client = {
7818
7887
  config,
7819
- scopes: createScopeDoors(callDoor),
7888
+ scopes,
7820
7889
  async recordWrite({ table_id, data }) {
7821
7890
  const result = await callDoor(
7822
7891
  DOORS.recordWrite,
@@ -8515,28 +8584,7 @@ function createRecordsClient(given) {
8515
8584
  "fieldOptions"
8516
8585
  );
8517
8586
  },
8518
- async pickListGet({ list_id }) {
8519
- return callDoor(DOORS.pickListGet, { p_list_id: list_id }, "pickListGet");
8520
- },
8521
- async pickListForSelection({ list_id }) {
8522
- return callDoor(
8523
- DOORS.pickListForSelection,
8524
- { p_list_id: list_id },
8525
- "pickListForSelection"
8526
- );
8527
- },
8528
- async pickListUpdate({ list_id, list_name, description, items }) {
8529
- return callDoor(
8530
- DOORS.pickListUpdate,
8531
- {
8532
- p_list_id: list_id,
8533
- p_list_name: list_name ?? null,
8534
- p_description: description ?? null,
8535
- p_items: items ? [...items] : null
8536
- },
8537
- "pickListUpdate"
8538
- );
8539
- },
8587
+ ...createPickListDoors(callDoor),
8540
8588
  async fieldChoiceUsage({ field_id }) {
8541
8589
  const result = await callDoor(
8542
8590
  DOORS.fieldChoiceUsage,
@@ -11070,11 +11118,7 @@ function createRecordsClient(given) {
11070
11118
  );
11071
11119
  },
11072
11120
  async scopeTableProvision({ home_id, item_id, scope_id }) {
11073
- return callDoor(
11074
- DOORS.scopeTableProvision,
11075
- { p_organization_id: org, p_item_id: item_id, p_scope_id: scope_id, p_home_id: home_id ?? null },
11076
- "scopeTableProvision"
11077
- );
11121
+ return scopes.tableProvision({ organization_id: org, item_id, scope_id, home_id: home_id ?? null });
11078
11122
  },
11079
11123
  async tableRowCounts({ table_ids }) {
11080
11124
  return callDoor(