@ai-matrx/records 0.29.0 → 0.36.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,116 @@
1
1
  # Changelog — @ai-matrx/records
2
2
 
3
+ ## 0.36.0
4
+
5
+ Republish of 0.35.0's contents. 0.35.0 never reached npm: its gate was red on
6
+ this package's OWN live-doors fixture, which wrote an undeclared column `n` into
7
+ its probe table — refused, correctly, by `custom._undeclared_key_guard` (23514,
8
+ REC-1 / REC-51) the moment lane FIELD-TRUTH landed it. The door had not
9
+ regressed; the fixture was writing a column nobody had declared. Fixed at the
10
+ fixture, never at the guard.
11
+
12
+ ## 0.35.0
13
+
14
+ **A gate a screen can read back, and a preview of what it would do today.**
15
+
16
+ A stage gate was saved as one Rule whose expression is an `or` of four arms, and
17
+ that compiled form was the only copy of it. `pipelineRead` handed a settings
18
+ screen the gate's name and its sentence and nothing else — so an editor built on
19
+ it would open the Birchwood Avenue renovation's "$5,000 needs a second quote"
20
+ rule with a BLANK condition and overwrite it the first time somebody pressed
21
+ Save.
22
+
23
+ `PipelineRule` now carries `when` and `demands` as they were written, and
24
+ `on_fail` — so an approval gate can never read back as a refusal.
25
+
26
+ `pipelineGatePreview({ table_id, stage, gate })` answers the one question
27
+ somebody writing a rule that refuses their colleagues' work actually has: of the
28
+ cards on this board today, how many would this turn away, and which three. It
29
+ takes the GATE rather than a rule id, because the whole point is judging one
30
+ that has not been saved. The store compiles it with the same compiler
31
+ `pipelineDeclare` uses, so this count and the refusal at the door cannot
32
+ disagree at the edge of the condition — which is the only place anybody looks.
33
+
34
+ **`PT428` is a real answer and this package called it `internal`.** The release
35
+ gate's live refusal census found it. A gate whose `on_fail` is
36
+ `require_approval` files the request and leaves the record where it was; a
37
+ caller meets that code whenever the move went through the ordinary write door.
38
+ It gets its own `needs_approval` code rather than joining `refused_by_rule`,
39
+ because the work was neither rejected nor done — a screen that drew it as a
40
+ refusal would tell somebody their work was turned down while it is being
41
+ considered.
42
+
43
+ **The door mirror had gone stale, twice.** `store.generated.ts` claimed
44
+ `pipeline_pending` was absent while the store had it, which is what turned the
45
+ 0.32.0 publish red; 0.34.0 then went red on `pipeline_gate_preview` the same
46
+ way, because the regenerated file was lost to a merge in the shared checkout
47
+ before it was committed. Regenerated from the live store and committed with the
48
+ change it describes: 538 doors, 25 rule node kinds — which picks up
49
+ `sibling_count`, the node a second-quote demand is written with.
50
+
51
+ That census is the guard working, and it has now been the thing that found a
52
+ missing door or a missing refusal class six times. It is worth saying why it
53
+ keeps firing: this package mirrors a store several lanes are landing on at once,
54
+ so a mirror regenerated ten minutes before a commit is already a claim about the
55
+ past.
56
+
57
+ ## 0.33.0
58
+
59
+ **One closed door beside a record took the record away.**
60
+
61
+ Cedar Ridge Dental's own owner opened a staff record in his own organization and
62
+ read "You do not have access to this" — above a version history, a running
63
+ onboarding checklist and a comment box that had all loaded perfectly. Reported
64
+ twice: by lane SCREENS-2 on that practice, and by crew E2, who asked the doors
65
+ from that very seat and found the record read answering correctly. It was never
66
+ the store.
67
+
68
+ `recordRead({ withComputed: true })` makes a second call, to
69
+ `custom.computed_provenance` — which Rule produced which worked-out value (FLD-9),
70
+ a footnote beside the record. Measured on the live catalogue, 2026-09-21:
71
+ `read_record` t, `record_history` t, `field_history` t, `computed_provenance` **f**.
72
+ That footnote's refusal was returned AS THE RECORD'S. `Peek` is the one caller
73
+ that asks with provenance, which is exactly why the record page refused and every
74
+ other panel on it did not.
75
+
76
+ A decorative read may never fail the primary one — and may not fail silently
77
+ either. The record comes back, `computed` is empty, and the new
78
+ `RecordRead.computedUnavailable` carries what the footnote's door said, so a
79
+ screen can say it could not look rather than draw nothing and mean two different
80
+ things by it. `src/__tests__/a-footnote-never-takes-the-record.test.ts` — three
81
+ clauses, two red on 0.32.0's bytes.
82
+
83
+ **Consumer action:** none. `computedUnavailable` is optional, and `null` when the
84
+ footnote read fine or was never asked for.
85
+
86
+ ## 0.30.0
87
+
88
+ **The chair's two rulings on the no-fake-data law, made structural.**
89
+
90
+ Both are things crews ACTUALLY shipped under the law on the day it was written, so
91
+ they are now refusals rather than advice in a README.
92
+
93
+ `suffixed-mailbox` — a mailbox whose name-shaped local part ends in a bare counter
94
+ (`linda.reyes0@`, `wei.singh.m34@`) is a generated row wearing a person's name, and
95
+ a whole column of them reads to the owner as one fake person repeated. People in a
96
+ template are fictional but REALISTIC, holding mailboxes on the fictional business's
97
+ own domain. The pattern is narrow on purpose — two or more words joined by `.` `_`
98
+ `-` AND a trailing counter — so the real mailboxes a business has (`support365@`,
99
+ `ap2@`, `frontdesk@`) are left alone, and the suite asserts both halves.
100
+
101
+ `fixture-in-name`, plus a name-field check in the validator — "test fixture" is a
102
+ CLASSIFICATION the organization carries in its kind/metadata (`test_fixture: true`
103
+ in its settings, which is also how cleanup finds it), never part of a name. The
104
+ validator now reads the business name, its legal name, every table's name and both
105
+ its labels, the form's name and the pipeline's name, and refuses the parenthesised
106
+ suffix, the bare words, and the `Fixture …` PREFIX — which the whole-document junk
107
+ sweep cannot see, because there the word is simply the first word of a name. The
108
+ settings key itself is exempt, since that is where the classification belongs.
109
+
110
+ Both patterns ship in `./use-cases`, so aidream's guard, matrx-frontend's guard and
111
+ this library's own validator can never disagree about what junk means.
112
+
113
+
3
114
  ## 0.28.0
4
115
 
5
116
  **The owner's side of a booking page — the one method that was standing between
@@ -61,6 +61,8 @@ __export(core_exports, {
61
61
  RETIRED_ACTOR_WORDS: () => RETIRED_ACTOR_WORDS,
62
62
  RULE_NODE_KINDS: () => RULE_NODE_KINDS,
63
63
  RULE_USES: () => RULE_USES,
64
+ STAGE_RULE_ENFORCEMENT: () => STAGE_RULE_ENFORCEMENT,
65
+ STAGE_RULE_ON_FAIL: () => STAGE_RULE_ON_FAIL,
64
66
  STORAGE_MODES: () => STORAGE_MODES,
65
67
  STORE_DOORS: () => STORE_DOORS,
66
68
  STORE_KNOBS: () => STORE_KNOBS,
@@ -247,6 +249,8 @@ function looksLikeAnId(value) {
247
249
 
248
250
  // src/pipeline.ts
249
251
  var PIPELINE_RULE_KINDS = ["moves", "requires", "who", "limit", "entry"];
252
+ var STAGE_RULE_ON_FAIL = ["refuse", "require_approval"];
253
+ var STAGE_RULE_ENFORCEMENT = ["refuse", "warn"];
250
254
  function mayDrag(level) {
251
255
  return level === "editor" || level === "admin" || level === "owner";
252
256
  }
@@ -566,6 +570,7 @@ var RULE_USES = ["validate", "compute", "membership", "applicability"];
566
570
  var PER_VALUE_ACCESS_WORDS = ["visibility", "access", "share", "acl", "permission", "permissions", "secret"];
567
571
  var PARITY_FIELD_TYPES = [
568
572
  { parity_type: "attachment", behavior: "relation", made_of: "REC-31: a File record reached through a relation, target the kernel `File` Table" },
573
+ { parity_type: "checkbox", behavior: "boolean", made_of: "a ticked or unticked answer, stored as a REAL boolean \u2014 and a record that never answered holds neither, so filters and group-by see three states, not two" },
569
574
  { parity_type: "currency", behavior: "range", made_of: "FLD-N-1: a number whose UNIT is the currency and whose format is currency \u2014 on the Field, never in presentation" },
570
575
  { parity_type: "datetime", behavior: "range", made_of: "a range of kind date or datetime \u2014 the dated modifier says the VALUES are dated, which is a different question" },
571
576
  { parity_type: "email", behavior: "text", made_of: "text whose format is email" },
@@ -602,6 +607,7 @@ var RULE_NODE_KINDS = [
602
607
  { node: "parent_field", evaluated_by: "W1-RULE-APPLY" },
603
608
  { node: "present", evaluated_by: "W1-RULE" },
604
609
  { node: "previous", evaluated_by: "PIPELINES" },
610
+ { node: "sibling_count", evaluated_by: "STAGE-RULES" },
605
611
  { node: "stage_count", evaluated_by: "PIPELINES" },
606
612
  { node: "sub", evaluated_by: "W1-RULE" }
607
613
  ];
@@ -620,6 +626,8 @@ var STORE_DOORS = [
620
626
  { name: "absence_reasons", args: "", returns: "text[]", security: "invoker" },
621
627
  { name: "actor_vocabulary", args: "", returns: "text[]", security: "invoker" },
622
628
  { name: "actor_word", args: "p_declared text", returns: "text", security: "invoker" },
629
+ { name: "addressed_cap", args: "p_user_id uuid, p_type text, p_id uuid, p_organization_id uuid DEFAULT NULL::uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "permission_level", security: "definer" },
630
+ { name: "addressed_cap_specific", args: "p_user_id uuid, p_type text, p_id uuid, p_organization_id uuid DEFAULT NULL::uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "permission_level", security: "definer" },
623
631
  { name: "agent_change_approval", args: "p_organization uuid, p_conversation uuid DEFAULT NULL::uuid, p_table uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
624
632
  { name: "agent_context", args: "p_organization_id uuid, p_table_id uuid, p_limit integer DEFAULT 50", returns: "jsonb", security: "invoker" },
625
633
  { name: "agent_table_claim", args: "p_organization uuid, p_table uuid, p_conversation uuid DEFAULT NULL::uuid", returns: "void", security: "definer" },
@@ -793,7 +801,7 @@ var STORE_DOORS = [
793
801
  { name: "entity_records_find", args: "p_organization_id uuid, p_token text, p_key text, p_value jsonb DEFAULT NULL::jsonb, p_limit integer DEFAULT 50, p_offset integer DEFAULT 0", returns: "jsonb", security: "invoker" },
794
802
  { name: "entity_table", args: "p_token text", returns: "TABLE(token text, schema_name text, table_name text, type text, title_column text, label text, has_organization boolean, has_deleted_at boolean)", security: "invoker" },
795
803
  { name: "entity_value_write", args: "p_organization_id uuid, p_token text, p_record_id uuid, p_patch jsonb", returns: "jsonb", security: "invoker" },
796
- { name: "export_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "definer" },
804
+ { name: "export_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
797
805
  { name: "export_records", args: "p_organization_id uuid, p_table_id uuid, p_limit integer DEFAULT 1000", returns: "TABLE(id uuid, document jsonb)", security: "invoker" },
798
806
  { name: "external_foreign_table_findings", args: "", returns: "SETOF text", security: "definer" },
799
807
  { name: "external_history_event", args: "p_organization_id uuid, p_link_id uuid, p_operation text", returns: "bigint", security: "definer" },
@@ -873,6 +881,9 @@ var STORE_DOORS = [
873
881
  { name: "io_proposal_reject", args: "p_organization_id uuid, p_import_id uuid, p_column text", returns: "boolean", security: "definer" },
874
882
  { name: "io_proposal_spec", args: "p_proposal jsonb", returns: "jsonb", security: "invoker" },
875
883
  { name: "io_record_changed", args: "", returns: "trigger", security: "definer" },
884
+ { name: "io_record_changed_stmt_delete", args: "", returns: "trigger", security: "definer" },
885
+ { name: "io_record_changed_stmt_insert", args: "", returns: "trigger", security: "definer" },
886
+ { name: "io_record_changed_stmt_update", args: "", returns: "trigger", security: "definer" },
876
887
  { name: "io_relation_candidate", args: "p_organization_id uuid, p_table_id uuid, p_words text[]", returns: "uuid", security: "invoker" },
877
888
  { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "integer", security: "definer" },
878
889
  { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_author jsonb", returns: "integer", security: "definer" },
@@ -881,6 +892,8 @@ var STORE_DOORS = [
881
892
  { name: "io_value_shape", args: "p_envelope jsonb", returns: "jsonb", security: "invoker" },
882
893
  { name: "is_a_retirement", args: "p_old_deleted timestamp with time zone, p_new_deleted timestamp with time zone, p_old_data jsonb, p_new_data jsonb, p_old_table uuid, p_new_table uuid, p_old_org uuid, p_new_org uuid, p_old_class text, p_new_class text", returns: "boolean", security: "invoker" },
883
894
  { name: "ladder_replanners", args: "p_roots text[] DEFAULT ARRAY['custom.has_visibility'::text, 'custom.effective_level'::text, 'custom.reaches_directly'::text, 'custom.visible_set'::text]", returns: "TABLE(fn text, lang text, why text, remedy text)", security: "definer" },
895
+ { name: "level_floor", args: "", returns: "permission_level", security: "definer" },
896
+ { name: "levels_raised_by_a_less_specific_rung", args: "", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, member_email text, record_id uuid, addressed_level permission_level, answered_level permission_level)", security: "definer" },
884
897
  { name: "list_door_disagreements", args: "p_pretend text DEFAULT NULL::text, p_only_organization uuid DEFAULT NULL::uuid, p_sample integer DEFAULT 200", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, table_id uuid, record_id uuid, door text, why text)", security: "invoker" },
885
898
  { name: "list_door_disagreements", args: "p_pretend text, p_only_organization uuid, p_sample integer, p_exhaustive boolean", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, table_id uuid, record_id uuid, door text, why text)", security: "invoker" },
886
899
  { name: "lookup_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb", returns: "jsonb", security: "invoker" },
@@ -911,9 +924,9 @@ var STORE_DOORS = [
911
924
  { name: "organization_references", args: "p_kind text, p_organization_id uuid, p_row jsonb", returns: "TABLE(site text, what text, ref_id uuid, openable boolean)", security: "invoker" },
912
925
  { name: "owning_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "invoker" },
913
926
  { name: "owning_table_gone", args: "p_organization_id uuid, p_record_id uuid", returns: "boolean", security: "invoker" },
914
- { name: "page_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "definer" },
927
+ { name: "page_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
915
928
  { name: "page_contract", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
916
- { name: "page_size", args: "p_organization_id uuid, p_door text, p_limit integer, p_default integer DEFAULT NULL::integer, p_ceiling integer DEFAULT NULL::integer", returns: "integer", security: "definer" },
929
+ { name: "page_size", args: "p_organization_id uuid, p_door text, p_limit integer, p_default integer DEFAULT NULL::integer, p_ceiling integer DEFAULT NULL::integer", returns: "integer", security: "invoker" },
917
930
  { name: "parity_field_types", args: "", returns: "TABLE(parity_type text, behavior text, made_of text)", security: "invoker" },
918
931
  { name: "parity_type", args: "p_field_data jsonb", returns: "text", security: "invoker" },
919
932
  { name: "parity_values", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, parity_type text, behavior text, unit text, format text, value jsonb, value_version integer, actor text, written_at timestamp with time zone)", security: "invoker" },
@@ -922,7 +935,9 @@ var STORE_DOORS = [
922
935
  { name: "pin_agent_cells", args: "p_new jsonb, p_old jsonb, p_agent_keys text[]", returns: "jsonb", security: "invoker" },
923
936
  { name: "pipeline_board", args: "p_organization_id uuid, p_table_id uuid, p_measure text DEFAULT NULL::text", returns: "TABLE(stage_key text, stage_label text, stage_position integer, cards bigint, total numeric, wip_limit integer, over_limit boolean)", security: "definer" },
924
937
  { name: "pipeline_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
938
+ { name: "pipeline_gate_preview", args: "p_organization_id uuid, p_table_id uuid, p_stage text, p_gate jsonb", returns: "jsonb", security: "definer" },
925
939
  { name: "pipeline_move", args: "p_organization_id uuid, p_record_id uuid, p_to text, p_also jsonb DEFAULT '{}'::jsonb, p_expected_version integer DEFAULT NULL::integer", returns: "jsonb", security: "definer" },
940
+ { name: "pipeline_pending", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
926
941
  { name: "pipeline_read", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
927
942
  { name: "pipeline_transition_refusal", args: "p_organization_id uuid, p_record_id uuid, p_to text", returns: "jsonb", security: "definer" },
928
943
  { name: "portal_admits", args: "p_organization_id uuid, p_user_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "definer" },
@@ -989,6 +1004,7 @@ var STORE_DOORS = [
989
1004
  { name: "record_carrying_edges", args: "p_id uuid, p_data_class text, p_data jsonb, p_deleted_at timestamp with time zone", returns: "TABLE(container_id uuid, item_id uuid, edge_role text)", security: "invoker" },
990
1005
  { name: "record_delete", args: "p_organization_id uuid, p_record_id uuid", returns: "timestamp with time zone", security: "definer" },
991
1006
  { name: "record_history", args: "p_organization_id uuid, p_record_id uuid, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(version integer, occurred_at timestamp with time zone, operation text, operation_label text, actor jsonb, changes jsonb, migration_id uuid, undoable boolean)", security: "definer" },
1007
+ { name: "record_platform_keys", args: "", returns: "text[]", security: "invoker" },
992
1008
  { name: "record_relation_edges", args: "p_organization_id uuid, p_id uuid, p_table_id uuid, p_data_class text, p_data jsonb, p_deleted_at timestamp with time zone", returns: "TABLE(target_id uuid, edge_role text, field_id uuid, ord integer)", security: "invoker" },
993
1009
  { name: "record_reparent", args: "p_organization_id uuid, p_record_id uuid, p_parent_id uuid", returns: "void", security: "definer" },
994
1010
  { name: "record_resolve", args: "p_organization_id uuid, p_id uuid", returns: "jsonb", security: "definer" },
@@ -997,12 +1013,14 @@ var STORE_DOORS = [
997
1013
  { name: "record_restore_version", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "jsonb", security: "definer" },
998
1014
  { name: "record_restore_version", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_author jsonb", returns: "jsonb", security: "definer" },
999
1015
  { name: "record_scope_context", args: "p_organization_id uuid, p_record_id uuid, p_relations integer DEFAULT 12, p_history integer DEFAULT 15, p_siblings integer DEFAULT 8", returns: "jsonb", security: "definer" },
1016
+ { name: "record_stage_pending", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
1000
1017
  { name: "record_state_as_of", args: "p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(state jsonb, replayed boolean)", security: "definer" },
1001
1018
  { name: "record_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
1002
1019
  { name: "record_update", args: "p_organization_id uuid, p_record_id uuid, p_patch jsonb, p_expected_version integer DEFAULT NULL::integer", returns: "integer", security: "definer" },
1003
1020
  { name: "record_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1004
1021
  { name: "record_values_versioned", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, value jsonb, value_version integer, source jsonb, absent_reason text, actor text, on_behalf_of text, written_at timestamp with time zone, alternates jsonb)", security: "definer" },
1005
1022
  { name: "record_write", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb", returns: "uuid", security: "definer" },
1023
+ { name: "record_write_many", args: "p_organization_id uuid, p_table_id uuid, p_rows jsonb[], p_ids uuid[] DEFAULT NULL::uuid[]", returns: "uuid[]", security: "definer" },
1006
1024
  { name: "refusals_claiming_a_level_never_asked", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
1007
1025
  { name: "relation_carry", args: "p_organization_id uuid, p_container_id uuid, p_item_id uuid", returns: "uuid", security: "definer" },
1008
1026
  { name: "relation_edges_withdraw", args: "p_organization_id uuid, p_field_ids uuid[], p_why text", returns: "integer", security: "definer" },
@@ -1059,6 +1077,8 @@ var STORE_DOORS = [
1059
1077
  { name: "size_refusal", args: "p_organization_id uuid, p_data jsonb", returns: "text", security: "invoker" },
1060
1078
  { name: "source_next_pointer", args: "p_sources jsonb", returns: "text", security: "invoker" },
1061
1079
  { name: "source_pointer", args: "p_sources jsonb, p_source jsonb", returns: "text", security: "invoker" },
1080
+ { name: "stage_rule_enforcement", args: "p_organization_id uuid", returns: "text", security: "invoker" },
1081
+ { name: "stage_rule_on_fail_kinds", args: "", returns: "TABLE(behaviour text, note text)", security: "invoker" },
1062
1082
  { name: "stamp_value_envelopes", args: "p_data jsonb, p_actor text, p_on_behalf_of text, p_at timestamp with time zone", returns: "jsonb", security: "invoker" },
1063
1083
  { name: "storage_modes", args: "", returns: "text[]", security: "invoker" },
1064
1084
  { name: "store_is_open", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "invoker" },
@@ -1069,6 +1089,7 @@ var STORE_DOORS = [
1069
1089
  { name: "subscriptions", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(rule_id uuid, name text, table_id uuid, saved_view_id uuid, cadence text, schedule text, quiet_hours jsonb, channel text, recipient_user_id uuid, event_key text, muted boolean, mine boolean, i_may_mute boolean, last_sent_at timestamp with time zone, next_digest_at timestamp with time zone)", security: "definer" },
1070
1090
  { name: "table_capacity", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
1071
1091
  { name: "table_carries_its_rows", args: "p_user_id uuid, p_table_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "boolean", security: "definer" },
1092
+ { name: "table_column_source", args: "p_organization_id uuid, p_table_id uuid", returns: "text", security: "invoker" },
1072
1093
  { name: "table_contents", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(record_id uuid, kind text, goes_at integer)", security: "invoker" },
1073
1094
  { name: "table_declare", args: "p_organization_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
1074
1095
  { name: "table_has_a_visible_record", args: "p_user uuid, p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "definer" },
@@ -1083,6 +1104,7 @@ var STORE_DOORS = [
1083
1104
  { name: "tables_at_home", args: "p_organization_id uuid, p_home_ids uuid[]", returns: "TABLE(table_id uuid, home_record_id uuid, kind text)", security: "definer" },
1084
1105
  { name: "tables_described_without_asking", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
1085
1106
  { name: "trg_associations_bump_visibility", args: "", returns: "trigger", security: "definer" },
1107
+ { name: "undeclared_keys", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb", returns: "text[]", security: "invoker" },
1086
1108
  { name: "validate_custom_fields", args: "p_token text, p_organization_id uuid, p_values jsonb", returns: "void", security: "invoker" },
1087
1109
  { name: "validate_value_envelope", args: "p_organization_id uuid, p_fields custom.record[], p_data jsonb", returns: "void", security: "invoker" },
1088
1110
  { name: "validate_values", args: "p_organization_id uuid, p_fields custom.record[], p_values jsonb, p_record_type text DEFAULT NULL::text", returns: "void", security: "invoker" },
@@ -1094,6 +1116,8 @@ var STORE_DOORS = [
1094
1116
  { name: "value_restore", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_version integer", returns: "jsonb", security: "definer" },
1095
1117
  { name: "value_restore", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_version integer, p_author jsonb", returns: "jsonb", security: "definer" },
1096
1118
  { name: "value_versions", args: "p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
1119
+ { name: "view_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
1120
+ { name: "views", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(view_id uuid, name text, table_id uuid, filters jsonb, definition jsonb, created_at timestamp with time zone)", security: "definer" },
1097
1121
  { name: "visibility_ancestors", args: "p_item_type text, p_item_id uuid", returns: "TABLE(container_type text, container_id uuid, depth integer, max_level permission_level)", security: "definer" },
1098
1122
  { name: "visibility_as_of", args: "p_organization_id uuid, p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(principal_kind text, principal_id uuid, level permission_level, through_kind text, through_id uuid, reason text, replayed boolean, held_from timestamp with time zone, held_to timestamp with time zone)", security: "definer" },
1099
1123
  { name: "visibility_cache_rebuild", args: "", returns: "integer", security: "definer" },
@@ -1181,6 +1205,7 @@ var STORE_KNOBS = [
1181
1205
  { key: "sandbox_message_bytes", value: "65536", type: "integer" },
1182
1206
  { key: "sandbox_org_components", value: "true", type: "boolean" },
1183
1207
  { key: "signup_provisioning_guard", value: "false", type: "boolean" },
1208
+ { key: "stage_rule_enforcement", value: '"refuse"', type: "enum" },
1184
1209
  { key: "system_enabled", value: "false", type: "boolean" },
1185
1210
  { key: "table_record_ceiling", value: "150000", type: "integer" },
1186
1211
  { key: "value_max_bytes", value: "100000", type: "integer" },
@@ -1190,19 +1215,20 @@ var STORE_REFUSAL_CODES = [
1190
1215
  { code: "02000", raised_by: "_checklist_instantiate,checklist_declare,checklist_run,checklist_step_complete,checklist_step_refusal,checklist_template_shape,conversation_scope_bind,dashboard_delete,dashboard_run,doc_letterhead,doc_render_body,doc_render_document,doc_render_read,doc_sign,doc_signature_intact,doc_signature_read,doc_template_delete,doc_template_read,doc_template_save,enrich_pin,entity_field_retire,entity_field_update,entity_record_read,entity_value_write,external_history_event,external_rows,external_stub_upsert,external_writes_set,io_restore,migrate_delete,migrate_extract_parent,migrate_merge,migrate_reclass,migrate_rename,migrate_reparent,migrate_retype,migrate_split,migrate_undo,organization_clear,portal_card,portal_declare,portal_invite,portal_preview,portal_principal_bind,portal_revoke,read_record,record_delete,record_restore,record_restore_preview,record_table,record_update,relation_uncarry,share_access,share_grant,share_lane_set,share_people,share_revoke,sign_request_cancel,sign_request_create,sign_request_remind,sign_request_unchanged,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_assign,work_record_states,work_set_state" },
1191
1216
  { code: "0A000", raised_by: "checklist_step_complete,external_rows,external_source_declare,external_write_through,promote_field,promoted_index_expr,promoted_query_sql,promoted_read,rule_eval,work_assign" },
1192
1217
  { code: "22003", raised_by: "context_resolve" },
1193
- { code: "22004", raised_by: "_entity_custom_fields_guard,_value_envelope,actor_word,agg_assert_key,agg_sql,anon_capture,anon_token_issue,anon_write,assert_client_may_reach,booking_declare,capture_submit,checklist_declare,context_resolve,dashboard_block_normalize,dashboard_declare,dashboard_window_sql,doc_render_write,doc_sign,doc_signature_write,doc_template_save,enrich_land,enrich_normalize,external_history_event,external_rows,external_source_declare,external_stub_upsert,external_write_through,external_writes_set,field_history,form_declare,form_submit,home_add,io_comment_write,io_import_begin,io_infer_column,io_outbox_drain,io_restore,migrate_choice_keys,migrate_purge,migrate_reclass,migrate_split,migrate_undo,organization_clear,organization_contents,pipeline_declare,portal_declare,portal_invite,portal_principal_bind,provenance_retention_days,provenance_write,query_across_homes,query_by_coordinates,query_rollup,record_delete,record_reparent,record_resolve,record_restore,record_update,record_write,relation_carry,relation_own,rule_declare,share_grant,sign_request_create,sign_request_sign,subscription_declare,table_declare,value_restore,work_approval_decide,work_approval_request,work_template_declare" },
1218
+ { code: "22004", raised_by: "_entity_custom_fields_guard,_value_envelope,actor_word,agg_assert_key,agg_sql,anon_capture,anon_token_issue,anon_write,assert_client_may_reach,booking_declare,capture_submit,checklist_declare,context_resolve,dashboard_block_normalize,dashboard_declare,dashboard_window_sql,doc_render_write,doc_sign,doc_signature_write,doc_template_save,enrich_land,enrich_normalize,external_history_event,external_rows,external_source_declare,external_stub_upsert,external_write_through,external_writes_set,field_history,form_declare,form_submit,home_add,io_comment_write,io_import_begin,io_infer_column,io_outbox_drain,io_restore,migrate_choice_keys,migrate_purge,migrate_reclass,migrate_split,migrate_undo,organization_clear,organization_contents,pipeline_declare,pipeline_gate_preview,portal_declare,portal_invite,portal_principal_bind,provenance_retention_days,provenance_write,query_across_homes,query_by_coordinates,query_rollup,record_delete,record_reparent,record_resolve,record_restore,record_update,record_write,record_write_many,relation_carry,relation_own,rule_declare,share_grant,sign_request_create,sign_request_sign,subscription_declare,table_declare,value_restore,view_declare,work_approval_decide,work_approval_request,work_template_declare" },
1194
1219
  { code: "22007", raised_by: "dashboard_window_sql" },
1195
1220
  { code: "22012", raised_by: "rule_eval" },
1196
- { code: "22023", raised_by: "_booking_availability,_entity_custom_fields_guard,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,booking_declare,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,enrich_declare,enrich_land,enrich_normalize,enrich_pin,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,io_import_begin,io_import_finish,io_import_plan,io_import_report,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,page_size,pin_agent_cells,pipeline_move,portal_declare,provenance_write,query_by_coordinates,query_rollup,record_update,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,sign_request_create,sign_request_sign,subscription_declare,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
1197
- { code: "23503", raised_by: "_booking_availability,_checklist_instantiate,_containment_guard,_field_document_for,_pipeline_stage_key,_record_rule_uses,agg_digest_assemble,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,booking_cancel,booking_confirm,booking_declare,booking_hold,booking_reschedule,capture_publish,checklist_declare,checklist_steps_table,comment_write,dashboard_declare,delete_rule,doc_sign,doc_template_save,enrich_declare,enrich_due,enrich_land,form_declare,form_submit,home_add,inbound_declare,inbound_mail_land,inbound_set,io_comment_write,io_import_begin,io_import_finish,io_import_report,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,pipeline_board,pipeline_declare,pipeline_move,pipeline_read,pipeline_transition_refusal,promote_field,promote_table,record_applicability,record_reparent,relation_carry,relation_own,resolve_first_match,rule_applies,rule_declare,rule_eval,rule_members,rule_run,sign_request_create,subscription_mute,subscription_preview,work_set_state,work_take_assignment,work_template_instantiate" },
1221
+ { code: "22023", raised_by: "_booking_availability,_entity_custom_fields_guard,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,booking_declare,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,enrich_declare,enrich_land,enrich_normalize,enrich_pin,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,io_export,io_import_begin,io_import_finish,io_import_plan,io_import_report,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,page_size,pin_agent_cells,pipeline_move,portal_declare,provenance_write,query_by_coordinates,query_rollup,record_update,record_write_many,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,sign_request_create,sign_request_sign,subscription_declare,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
1222
+ { code: "23503", raised_by: "_booking_availability,_checklist_instantiate,_containment_guard,_field_document_for,_pipeline_stage_key,_record_rule_uses,agg_digest_assemble,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,booking_cancel,booking_confirm,booking_declare,booking_hold,booking_reschedule,capture_publish,checklist_declare,checklist_steps_table,comment_write,dashboard_declare,delete_rule,doc_sign,doc_template_save,enrich_declare,enrich_due,enrich_land,form_declare,form_submit,home_add,inbound_declare,inbound_mail_land,inbound_set,io_comment_write,io_import_begin,io_import_finish,io_import_report,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,pipeline_board,pipeline_declare,pipeline_move,pipeline_read,pipeline_transition_refusal,promote_field,promote_table,record_applicability,record_reparent,relation_carry,relation_own,resolve_first_match,rule_applies,rule_declare,rule_eval,rule_members,rule_run,sign_request_create,subscription_mute,subscription_preview,view_declare,work_set_state,work_take_assignment,work_template_instantiate" },
1198
1223
  { code: "23505", raised_by: "_unique_rule_holds,doc_sign,doc_signature_write,entity_field_declare,field_declare,home_add,inbound_declare,io_proposal_accept,relation_carry,relation_own,share_grant,sign_request_cancel,sign_request_create,work_approval_decide,work_slot_hold" },
1199
- { code: "23514", raised_by: "_checklist_instantiate,_checklist_step_guard,_containment_guard,_dated_values_guard,_derived_fields,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_shape_guard,_value_envelope,_work_shape_guard,_workdoors_approval_guard,assert_entity_is_organization_scoped,capture_publish,capture_sheet_declare,checklist_declare,checklist_step_complete,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,io_import_rows,migrate_merge,relation_carry,relation_own,sign_request_create,sign_request_sign,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
1224
+ { code: "23514", raised_by: "_checklist_instantiate,_checklist_step_guard,_claimed_column_guard,_containment_guard,_dated_values_guard,_derived_fields,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_columns_word_guard,_table_shape_guard,_undeclared_key_guard,_value_envelope,_work_shape_guard,_workdoors_approval_guard,assert_entity_is_organization_scoped,capture_publish,capture_sheet_declare,checklist_declare,checklist_step_complete,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,io_import_rows,migrate_merge,relation_carry,relation_own,sign_request_create,sign_request_sign,table_declare,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
1200
1225
  { code: "40001", raised_by: "has_visibility_at" },
1201
1226
  { code: "42501", raised_by: "_doc_render_immutable,_doc_signature_immutable,_field_definition_write,_field_write_door,_rule_definition_write,_store_door,anon_capture,anon_inbound_land,anon_publish,anon_token_issue,anon_token_verify,anon_write,assert_client_may_change,assert_client_may_open,assert_client_may_reach,assert_may_know_table,assert_organization_admin,assert_store_door,booking_confirm,booking_declare,booking_hold,capture_submit,checklist_run,comment_write,conversation_scope_bind,conversation_scope_unbind,enrich_declare,enrich_due,enrich_land,enrich_normalize,entity_field_declare,entity_field_retire,entity_field_update,entity_value_write,external_write_through,form_declare,form_submit,inbound_mail_land,io_comment_resolve,io_comment_write,io_import_begin,io_import_finish,io_restore,migrate_purge,migrate_reclass,my_levels,organization_clear,portal_declare,portal_invitation,portal_invite,portal_principal_bind,promote_table,query_visibility_parity,read_record,read_records,record_table,share_grant,subscription_mute,subscription_preview,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_person" },
1202
1227
  { code: "42703", raised_by: "entity_table,portal_declare" },
1203
1228
  { code: "53400", raised_by: "anon_rate_take,delete_cascade_closure,enrich_due,enrich_land,promote_field" },
1204
1229
  { code: "54001", raised_by: "record_delete" },
1205
- { code: "PT409", raised_by: "record_update" }
1230
+ { code: "PT409", raised_by: "record_update" },
1231
+ { code: "PT428", raised_by: "_record_rule_uses" }
1206
1232
  ];
1207
1233
  var ENTITY_TOKENS = [
1208
1234
  "access_delta_probe",
@@ -1866,6 +1892,7 @@ var ENTITY_TOKENS = [
1866
1892
  "plan_node_artifact",
1867
1893
  "plan_node_step",
1868
1894
  "plan_profile",
1895
+ "platform_action_request",
1869
1896
  "platform_actor_session",
1870
1897
  "platform_actor_token",
1871
1898
  "platform_actor_token_event",
@@ -2372,6 +2399,14 @@ var DOORS = {
2372
2399
  pipelineTransitionRefusal: "pipeline_transition_refusal",
2373
2400
  pipelineMove: "pipeline_move",
2374
2401
  tableStageField: "table_stage_field",
2402
+ // STAGE-RULES. A gate can refuse or it can hand the change to the approvals queue; the
2403
+ // closed list is the store's, the knob is the organization's, and what is WAITING on a
2404
+ // card has to be askable or a card that did not move looks like a card nobody dragged.
2405
+ stageRuleOnFailKinds: "stage_rule_on_fail_kinds",
2406
+ stageRuleEnforcement: "stage_rule_enforcement",
2407
+ recordStagePending: "record_stage_pending",
2408
+ pipelinePending: "pipeline_pending",
2409
+ pipelineGatePreview: "pipeline_gate_preview",
2375
2410
  ruleMembers: "rule_members",
2376
2411
  ruleMembership: "rule_membership",
2377
2412
  ruleRun: "rule_run",
@@ -2698,7 +2733,17 @@ var BY_SQLSTATE = {
2698
2733
  // the grants not copied, land here.
2699
2734
  PGRST202: "store_not_served",
2700
2735
  PGRST205: "store_not_served",
2701
- PGRST301: "door"
2736
+ PGRST301: "door",
2737
+ // PT428 — NOT A FAILURE, and the release gate's live census is what found it
2738
+ // missing: the store raises it and this package answered `internal`, which is
2739
+ // the one classification that tells a screen nothing. A stage gate whose
2740
+ // `on_fail` is `require_approval` files the request and leaves the record
2741
+ // where it was; the transaction is rolled back to the pipeline's own block, so
2742
+ // "nothing was written" is a fact rather than a promise. Landed by lane
2743
+ // STAGE-RULES; mapped here by STAGE-RULES-2 the day after, when the census
2744
+ // caught it — the sixth time that census has been the thing that found a
2745
+ // refusal class rather than a person guessing one.
2746
+ PT428: "needs_approval"
2702
2747
  };
2703
2748
  var MAPPED_SQLSTATES = Object.keys(BY_SQLSTATE);
2704
2749
  function parseDetail(details) {
@@ -2877,16 +2922,17 @@ function createRecordsClient(config) {
2877
2922
  if (!door.ok) return err(door.error);
2878
2923
  const { document, hidden } = unfold(door.data);
2879
2924
  let computed = [];
2925
+ let computedUnavailable = null;
2880
2926
  if (withComputed) {
2881
2927
  const provenance = await callDoor(
2882
2928
  DOORS.computedProvenance,
2883
2929
  { p_organization_id: org, p_record_id: record_id },
2884
2930
  "recordRead.computed"
2885
2931
  );
2886
- if (!provenance.ok) return err(provenance.error);
2887
- computed = provenance.data ?? [];
2932
+ if (provenance.ok) computed = provenance.data ?? [];
2933
+ else computedUnavailable = provenance.error;
2888
2934
  }
2889
- return ok({ record_id, document, hidden, computed });
2935
+ return ok({ record_id, document, hidden, computed, computedUnavailable });
2890
2936
  },
2891
2937
  async list({ table_id, limit = 50, offset = 0 }) {
2892
2938
  const door = await callDoor(
@@ -3225,6 +3271,41 @@ function createRecordsClient(config) {
3225
3271
  "tableStageField"
3226
3272
  );
3227
3273
  },
3274
+ async stageRuleOnFailKinds() {
3275
+ return callDoor(
3276
+ DOORS.stageRuleOnFailKinds,
3277
+ {},
3278
+ "stageRuleOnFailKinds"
3279
+ );
3280
+ },
3281
+ async stageRuleEnforcement() {
3282
+ return callDoor(
3283
+ DOORS.stageRuleEnforcement,
3284
+ { p_organization_id: org },
3285
+ "stageRuleEnforcement"
3286
+ );
3287
+ },
3288
+ async recordStagePending({ record_id }) {
3289
+ return callDoor(
3290
+ DOORS.recordStagePending,
3291
+ { p_organization_id: org, p_record_id: record_id },
3292
+ "recordStagePending"
3293
+ );
3294
+ },
3295
+ async pipelinePending({ table_id }) {
3296
+ return callDoor(
3297
+ DOORS.pipelinePending,
3298
+ { p_organization_id: org, p_table_id: table_id },
3299
+ "pipelinePending"
3300
+ );
3301
+ },
3302
+ async pipelineGatePreview({ table_id, stage, gate }) {
3303
+ return callDoor(
3304
+ DOORS.pipelineGatePreview,
3305
+ { p_organization_id: org, p_table_id: table_id, p_stage: stage, p_gate: gate },
3306
+ "pipelineGatePreview"
3307
+ );
3308
+ },
3228
3309
  async ruleMembers({ rule_id }) {
3229
3310
  return callDoor(
3230
3311
  DOORS.ruleMembers,