@ai-matrx/records 0.11.0 → 0.17.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.
@@ -81,11 +81,59 @@ function highestLevel(left, right) {
81
81
  return ORDINAL[left] >= ORDINAL[right] ? left : right;
82
82
  }
83
83
 
84
+ // src/choice.ts
85
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
86
+ function optionKey(option) {
87
+ const stored = option.metadata?.["option_key"];
88
+ if (typeof stored === "string" && stored.trim() !== "") return stored;
89
+ return choiceSlug(optionLabel(option));
90
+ }
91
+ function optionLabel(option) {
92
+ const doc = option.data;
93
+ const title = doc?.["title"] ?? doc?.["name"];
94
+ if (typeof title === "string" && title.trim() !== "") return title;
95
+ return "Unnamed choice";
96
+ }
97
+ function choiceSlug(word) {
98
+ const slug = word.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 55);
99
+ return slug === "" ? "choice" : slug;
100
+ }
101
+ function isTheChosen(option, value) {
102
+ if (typeof value !== "string") return false;
103
+ const asked = value.trim().toLowerCase();
104
+ if (asked === "") return false;
105
+ return asked === optionKey(option).toLowerCase() || asked === optionLabel(option).toLowerCase() || asked === option.id.toLowerCase();
106
+ }
107
+ function choiceValuesOf(value) {
108
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
109
+ if (typeof value === "string" && value !== "") return [value];
110
+ return [];
111
+ }
112
+ function choicesOf(document, fieldKeyOrId) {
113
+ const block = document?.["_choices"];
114
+ if (!block || typeof block !== "object") return [];
115
+ const entry = block[fieldKeyOrId];
116
+ if (!entry) return [];
117
+ const list = Array.isArray(entry) ? entry : [entry];
118
+ return list.filter((x) => !!x && typeof x === "object" && typeof x.key === "string");
119
+ }
120
+ function holdsARetiredChoice(document, fieldKeyOrId) {
121
+ return choicesOf(document, fieldKeyOrId).some((c) => c.retired === true);
122
+ }
123
+ function looksLikeAnId(value) {
124
+ return typeof value === "string" && UUID.test(value);
125
+ }
126
+
84
127
  // src/rule.ts
85
128
  function publicFormPath(formId) {
86
129
  return `/f/${formId}`;
87
130
  }
88
131
 
132
+ // src/portal.ts
133
+ function portalPath(slug) {
134
+ return `/portal/c/${slug}`;
135
+ }
136
+
89
137
  // src/aggregate.ts
90
138
  function measureKey(measure) {
91
139
  return measure.op === "count" ? "count" : `${measure.op}_${measure.key ?? ""}`;
@@ -200,7 +248,24 @@ var STORE_DOORS = [
200
248
  { name: "caller_role", args: "", returns: "name", security: "invoker" },
201
249
  { name: "carrying_edges_in", args: "p_organization_id uuid", returns: "TABLE(container_type text, container_id uuid, item_type text, item_id uuid, conveys_max permission_level)", security: "definer" },
202
250
  { name: "carrying_edges_of", args: "p_item_type text, p_item_id uuid", returns: "TABLE(container_type text, container_id uuid, conveys_max permission_level)", security: "definer" },
251
+ { name: "choice_census", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
252
+ { name: "choice_field_map", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "invoker" },
253
+ { name: "choice_filter_normalize", args: "p_map jsonb, p_filter jsonb", returns: "jsonb", security: "invoker" },
254
+ { name: "choice_key_for", args: "p_organization_id uuid, p_options_table_id uuid, p_title text, p_exclude uuid DEFAULT NULL::uuid", returns: "text", security: "invoker" },
255
+ { name: "choice_key_of", args: "p_field jsonb, p_token text", returns: "text", security: "invoker" },
256
+ { name: "choice_options", args: "p_organization_id uuid, p_options_table_id uuid", returns: "jsonb", security: "invoker" },
257
+ { name: "choice_render", args: "p_organization_id uuid, p_table_id uuid, p_doc jsonb", returns: "jsonb", security: "invoker" },
258
+ { name: "choice_render_groups", args: "p_map jsonb, p_groups jsonb", returns: "jsonb", security: "invoker" },
259
+ { name: "choice_render_note", args: "p_field jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
260
+ { name: "choice_render_value", args: "p_field jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
261
+ { name: "choice_slug", args: "p_word text", returns: "text", security: "invoker" },
262
+ { name: "choice_synonyms", args: "p_organization_id uuid, p_table_id uuid, p_token text", returns: "text[]", security: "invoker" },
263
+ { name: "choice_synonyms_in", args: "p_map jsonb, p_token text", returns: "text[]", security: "invoker" },
264
+ { name: "choice_words", args: "p_field jsonb", returns: "text", security: "invoker" },
203
265
  { name: "client_write_grants", args: "", returns: "TABLE(role_name text, object_name text, privilege text)", security: "invoker" },
266
+ { name: "comment_mention_deliver", args: "p_organization_id uuid, p_record_id uuid, p_table_id uuid, p_comment_id uuid, p_recipient uuid, p_author_name text, p_record_title text, p_body text", returns: "uuid", security: "definer" },
267
+ { name: "comment_thread", args: "p_organization_id uuid, p_record_id uuid, p_include_resolved boolean DEFAULT false", returns: "jsonb", security: "definer" },
268
+ { name: "comment_write", args: "p_organization_id uuid, p_record_id uuid, p_body text, p_anchor jsonb DEFAULT '{}'::jsonb, p_parent_comment_id uuid DEFAULT NULL::uuid, p_mentions uuid[] DEFAULT NULL::uuid[]", returns: "jsonb", security: "definer" },
204
269
  { name: "computed_provenance", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, value jsonb, rule_id uuid, rule_version integer, computed_at timestamp with time zone)", security: "invoker" },
205
270
  { name: "containment_chain", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(ancestor_id uuid, depth integer)", security: "invoker" },
206
271
  { name: "containment_depth_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
@@ -208,6 +273,17 @@ var STORE_DOORS = [
208
273
  { name: "containment_parent", args: "p_data jsonb", returns: "uuid", security: "invoker" },
209
274
  { name: "cross_organization_links_open", args: "p_source_organization_id uuid, p_target_organization_id uuid", returns: "boolean", security: "invoker" },
210
275
  { name: "custom_fields_tables", args: "", returns: "TABLE(token text, schema_name text, table_name text)", security: "invoker" },
276
+ { name: "dashboard_block_normalize", args: "p_organization_id uuid, p_subject_table_id uuid, p_block jsonb", returns: "jsonb", security: "definer" },
277
+ { name: "dashboard_class", args: "", returns: "text", security: "invoker" },
278
+ { name: "dashboard_declare", args: "p_organization_id uuid, p_table_id uuid, p_name text, p_blocks jsonb DEFAULT '[]'::jsonb, p_presentation jsonb DEFAULT '{}'::jsonb, p_dashboard_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
279
+ { name: "dashboard_delete", args: "p_organization_id uuid, p_dashboard_id uuid", returns: "boolean", security: "definer" },
280
+ { name: "dashboard_field_keys", args: "p_organization_id uuid, p_table_id uuid", returns: "text[]", security: "definer" },
281
+ { name: "dashboard_kinds", args: "", returns: "text[]", security: "invoker" },
282
+ { name: "dashboard_moment_sql", args: "p_key text", returns: "text", security: "invoker" },
283
+ { name: "dashboard_run", args: "p_organization_id uuid, p_dashboard_id uuid, p_filter jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
284
+ { name: "dashboard_stuck", args: "p_organization_id uuid, p_table_id uuid, p_state_key text, p_days integer DEFAULT 14, p_filter jsonb DEFAULT '{}'::jsonb, p_limit integer DEFAULT 50, p_required text DEFAULT 'viewer'::text", returns: "TABLE(record_id uuid, title text, state text, last_changed_at timestamp with time zone, days_unchanged numeric, measured_from text)", security: "definer" },
285
+ { name: "dashboard_window_sql", args: "p_key text, p_window jsonb", returns: "text", security: "invoker" },
286
+ { name: "dashboards", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(dashboard_id uuid, table_id uuid, name text, blocks jsonb, presentation jsonb, block_count integer, version integer, created_at timestamp with time zone, updated_at timestamp with time zone)", security: "definer" },
211
287
  { name: "delete_cascade_closure", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid[]", security: "invoker" },
212
288
  { name: "delete_preview", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
213
289
  { name: "delete_rule", args: "p_organization_id uuid, p_record_id uuid, p_apply boolean DEFAULT true", returns: "jsonb", security: "definer" },
@@ -222,13 +298,17 @@ var STORE_DOORS = [
222
298
  { name: "doc_render_document", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
223
299
  { name: "doc_render_read", args: "p_organization_id uuid, p_render_id uuid", returns: "jsonb", security: "definer" },
224
300
  { name: "doc_render_write", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid, p_table_id uuid, p_template_version integer, p_body text, p_content_hash text", returns: "uuid", security: "definer" },
301
+ { name: "doc_renders", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(render_id uuid, template_id uuid, record_id uuid, table_id uuid, template_version integer, body text, content_hash text, rendered_at timestamp with time zone)", security: "definer" },
225
302
  { name: "doc_sign", args: "p_organization_id uuid, p_render_id uuid, p_field_key text, p_signer_name text, p_signer_user_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
226
303
  { name: "doc_signature_field_ok", args: "p_field_data jsonb", returns: "boolean", security: "invoker" },
227
304
  { name: "doc_signature_intact", args: "p_organization_id uuid, p_signature_id uuid", returns: "jsonb", security: "invoker" },
228
305
  { name: "doc_signature_read", args: "p_organization_id uuid, p_signature_id uuid", returns: "jsonb", security: "definer" },
229
306
  { name: "doc_signature_write", args: "p_organization_id uuid, p_render_id uuid, p_record_id uuid, p_field_key text, p_signer_name text, p_signer_user_id uuid, p_document_hash text, p_document_version integer", returns: "uuid", security: "definer" },
307
+ { name: "doc_signatures", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(signature_id uuid, render_id uuid, record_id uuid, field_key text, signer_name text, signer_user_id uuid, signed_at timestamp with time zone, document_hash text, document_version integer)", security: "definer" },
308
+ { name: "doc_template_delete", args: "p_organization_id uuid, p_template_id uuid", returns: "boolean", security: "definer" },
230
309
  { name: "doc_template_read", args: "p_organization_id uuid, p_template_id uuid", returns: "jsonb", security: "definer" },
231
310
  { name: "doc_template_save", args: "p_organization_id uuid, p_table_id uuid, p_name text, p_body text, p_template_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
311
+ { name: "doc_templates", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(template_id uuid, renders_table_id uuid, name text, body text, template_version integer, token_count bigint, updated_at timestamp with time zone)", security: "definer" },
232
312
  { name: "doc_token_pattern", args: "", returns: "text", security: "invoker" },
233
313
  { name: "doc_tokens", args: "p_body text", returns: "TABLE(ordinal integer, raw text, field_id uuid)", security: "invoker" },
234
314
  { name: "doc_unresolved_tokens", args: "p_organization_id uuid, p_table_id uuid, p_body text", returns: "TABLE(raw text, field_id uuid, why text)", security: "invoker" },
@@ -257,6 +337,7 @@ var STORE_DOORS = [
257
337
  { name: "field_behaviour", args: "p_field_data jsonb", returns: "text", security: "invoker" },
258
338
  { name: "field_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
259
339
  { name: "field_dependants", args: "p_organization_id uuid, p_field_id uuid", returns: "TABLE(kind text, dependant_id uuid, label text, how text)", security: "definer" },
340
+ { name: "field_history", args: "p_organization_id uuid, p_table_id uuid, p_field_key text, p_limit integer DEFAULT 100, p_offset integer DEFAULT 0, p_record_id uuid DEFAULT NULL::uuid", returns: "TABLE(record_id uuid, record_title text, version integer, occurred_at timestamp with time zone, operation_label text, actor jsonb, before jsonb, after jsonb)", security: "definer" },
260
341
  { name: "field_kernel_id", args: "", returns: "uuid", security: "invoker" },
261
342
  { name: "field_options", args: "p_organization_id uuid, p_field_id uuid", returns: "SETOF custom.record", security: "definer" },
262
343
  { name: "field_retire", args: "p_organization_id uuid, p_field_id uuid", returns: "boolean", security: "definer" },
@@ -275,7 +356,11 @@ var STORE_DOORS = [
275
356
  { name: "has_visibility", args: "p_user_id uuid, p_type text, p_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "boolean", security: "definer" },
276
357
  { name: "has_visibility_at", args: "p_user_id uuid, p_type text, p_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level, p_organization_id uuid DEFAULT NULL::uuid, p_min_version bigint DEFAULT NULL::bigint", returns: "boolean", security: "definer" },
277
358
  { name: "hidden_field_notice", args: "p_field custom.record, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "invoker" },
359
+ { name: "history_actor", args: "p_tier text, p_document jsonb, p_actor_id uuid, p_people jsonb", returns: "jsonb", security: "invoker" },
360
+ { name: "history_changes", args: "p_organization_id uuid, p_table_id uuid, p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
361
+ { name: "history_people", args: "p_organization_id uuid, p_ids uuid[]", returns: "jsonb", security: "definer" },
278
362
  { name: "history_prune", args: "p_organization_id uuid, p_scope text DEFAULT 'values'::text, p_table_id uuid DEFAULT NULL::uuid, p_dry_run boolean DEFAULT true", returns: "jsonb", security: "definer" },
363
+ { name: "history_restore_body", args: "p_current jsonb, p_target jsonb, p_field_key text DEFAULT NULL::text", returns: "jsonb", security: "invoker" },
279
364
  { name: "history_retention", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
280
365
  { name: "history_retention_floor_raise", args: "p_organization_id uuid, p_days integer", returns: "integer", security: "definer" },
281
366
  { name: "history_retention_set", args: "p_organization_id uuid, p_table_id uuid, p_days integer", returns: "integer", security: "definer" },
@@ -304,16 +389,20 @@ var STORE_DOORS = [
304
389
  { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "integer", security: "definer" },
305
390
  { name: "io_revisions", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(version integer, changed_at timestamp with time zone, changed_by uuid, summary text, operation text, changed_fields jsonb)", security: "definer" },
306
391
  { 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" },
392
+ { 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" },
393
+ { 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" },
307
394
  { name: "lookup_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb", returns: "jsonb", security: "invoker" },
308
395
  { name: "mask_document", args: "p_document jsonb, p_visible_keys text[], p_notices jsonb, p_by_id boolean DEFAULT false, p_key_ids jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
309
396
  { name: "mask_document", args: "p_document jsonb, p_visible_keys text[], p_notices jsonb, p_by_id boolean DEFAULT false, p_key_ids jsonb DEFAULT '{}'::jsonb, p_declared_keys text[] DEFAULT NULL::text[]", returns: "jsonb", security: "invoker" },
310
397
  { name: "merge_field_kernel_id", args: "", returns: "uuid", security: "invoker" },
398
+ { name: "migrate_choice_keys", args: "p_organization_id uuid, p_table_id uuid, p_dry_run boolean DEFAULT false", returns: "jsonb", security: "definer" },
311
399
  { name: "migrate_delete", args: "p_organization_id uuid, p_record_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
312
400
  { name: "migrate_demote", args: "p_organization_id uuid, p_table_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
313
401
  { name: "migrate_extract_parent", args: "p_organization_id uuid, p_id uuid, p_parent_table_id uuid, p_moved_keys text[], p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
314
402
  { name: "migrate_merge", args: "p_organization_id uuid, p_winner_id uuid, p_loser_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
315
403
  { name: "migrate_promote", args: "p_organization_id uuid, p_table_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
316
404
  { name: "migrate_purge", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_dry_run boolean DEFAULT true", returns: "jsonb", security: "definer" },
405
+ { name: "migrate_reclass", args: "p_organization_id uuid, p_id uuid, p_to text DEFAULT 'field'::text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
317
406
  { name: "migrate_rename", args: "p_organization_id uuid, p_id uuid, p_to text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
318
407
  { name: "migrate_reparent", args: "p_organization_id uuid, p_id uuid, p_parent_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
319
408
  { name: "migrate_retype", args: "p_organization_id uuid, p_id uuid, p_to text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
@@ -333,6 +422,20 @@ var STORE_DOORS = [
333
422
  { 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" },
334
423
  { name: "per_value_access_words", args: "", returns: "text[]", security: "invoker" },
335
424
  { name: "person_kernel_id", args: "", returns: "uuid", security: "invoker" },
425
+ { name: "portal_admits", args: "p_organization_id uuid, p_user_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "definer" },
426
+ { name: "portal_card", args: "p_organization_id uuid, p_portal_id uuid", returns: "jsonb", security: "definer" },
427
+ { name: "portal_declare", args: "p_organization_id uuid, p_title text, p_client_table_id uuid, p_tables jsonb, p_portal_id uuid DEFAULT NULL::uuid, p_slug text DEFAULT NULL::text, p_sign_in_method text DEFAULT 'magic_link'::text", returns: "uuid", security: "definer" },
428
+ { name: "portal_field_map", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(field_id uuid, field_key text, field_type text, points_at uuid)", security: "definer" },
429
+ { name: "portal_invitation", args: "p_slug text, p_email text", returns: "jsonb", security: "definer" },
430
+ { name: "portal_invite", args: "p_organization_id uuid, p_portal_id uuid, p_client_record_id uuid, p_email text, p_user_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
431
+ { name: "portal_me", args: "", returns: "jsonb", security: "definer" },
432
+ { name: "portal_preview", args: "p_organization_id uuid, p_portal_id uuid, p_principal_id uuid, p_table_id uuid", returns: "TABLE(record_id uuid, title text)", security: "definer" },
433
+ { name: "portal_principal_bind", args: "p_organization_id uuid, p_principal_id uuid, p_user_id uuid", returns: "jsonb", security: "definer" },
434
+ { name: "portal_public", args: "p_slug text", returns: "jsonb", security: "definer" },
435
+ { name: "portal_record_title", args: "p_organization_id uuid, p_record_id uuid", returns: "text", security: "definer" },
436
+ { name: "portal_revoke", args: "p_organization_id uuid, p_portal_id uuid, p_principal_id uuid", returns: "jsonb", security: "definer" },
437
+ { name: "portal_slug", args: "p_organization_id uuid, p_title text, p_portal_id uuid DEFAULT NULL::uuid", returns: "text", security: "definer" },
438
+ { name: "portals", args: "p_organization_id uuid", returns: "TABLE(portal_id uuid, title text, slug text, client_table_id uuid, client_table text, is_active boolean, tables integer, invited integer, signed_in integer, sign_in_method text, opened_at timestamp with time zone)", security: "definer" },
336
439
  { name: "presentation_kernel_id", args: "", returns: "uuid", security: "invoker" },
337
440
  { name: "promote_field", args: "p_organization_id uuid, p_table_id uuid, p_field_id uuid", returns: "jsonb", security: "invoker" },
338
441
  { name: "promote_table", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
@@ -378,15 +481,20 @@ var STORE_DOORS = [
378
481
  { name: "record_card", args: "p_viewer uuid, p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
379
482
  { 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" },
380
483
  { name: "record_delete", args: "p_organization_id uuid, p_record_id uuid", returns: "timestamp with time zone", security: "definer" },
484
+ { 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" },
381
485
  { 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" },
382
486
  { name: "record_reparent", args: "p_organization_id uuid, p_record_id uuid, p_parent_id uuid", returns: "void", security: "definer" },
383
487
  { name: "record_resolve", args: "p_organization_id uuid, p_id uuid", returns: "jsonb", security: "definer" },
384
488
  { name: "record_restore", args: "p_organization_id uuid, p_record_id uuid", returns: "void", security: "definer" },
489
+ { name: "record_restore_preview", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_field_key text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
490
+ { name: "record_restore_version", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "jsonb", security: "definer" },
385
491
  { name: "record_state_as_of", args: "p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(state jsonb, replayed boolean)", security: "definer" },
492
+ { name: "record_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
386
493
  { 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" },
387
494
  { name: "record_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
388
495
  { 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" },
389
496
  { name: "record_write", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb", returns: "uuid", security: "definer" },
497
+ { name: "refusals_claiming_a_level_never_asked", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
390
498
  { name: "relation_carry", args: "p_organization_id uuid, p_container_id uuid, p_item_id uuid", returns: "uuid", security: "definer" },
391
499
  { name: "relation_edges_withdraw", args: "p_organization_id uuid, p_field_ids uuid[], p_why text", returns: "integer", security: "definer" },
392
500
  { name: "relation_own", args: "p_organization_id uuid, p_owner_id uuid, p_target_id uuid", returns: "uuid", security: "definer" },
@@ -432,7 +540,11 @@ var STORE_DOORS = [
432
540
  { 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" },
433
541
  { name: "storage_modes", args: "", returns: "text[]", security: "invoker" },
434
542
  { name: "store_is_open", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "invoker" },
543
+ { name: "subscription_cadences", args: "p_organization_id uuid", returns: "text[]", security: "definer" },
544
+ { name: "subscription_mute", args: "p_organization_id uuid, p_rule_id uuid, p_muted boolean DEFAULT true", returns: "boolean", security: "definer" },
545
+ { 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, channel text, recipient_user_id uuid, event_key text, muted boolean, mine boolean, i_may_mute boolean)", security: "definer" },
435
546
  { name: "table_capacity", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
547
+ { 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" },
436
548
  { name: "table_contents", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(record_id uuid, kind text, goes_at integer)", security: "invoker" },
437
549
  { name: "table_declare", args: "p_organization_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
438
550
  { name: "table_has_a_visible_record", args: "p_user uuid, p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "definer" },
@@ -454,6 +566,7 @@ var STORE_DOORS = [
454
566
  { name: "value_envelope_ok", args: "p_data jsonb", returns: "boolean", security: "invoker" },
455
567
  { name: "value_envelope_refusal", args: "p_data jsonb", returns: "text", security: "invoker" },
456
568
  { name: "value_read", args: "p_organization_id uuid, p_record_id uuid, p_key text", 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" },
569
+ { name: "value_restore", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_version integer", returns: "jsonb", security: "definer" },
457
570
  { name: "value_versions", args: "p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
458
571
  { 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" },
459
572
  { 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" },
@@ -466,6 +579,7 @@ var STORE_DOORS = [
466
579
  { name: "widget_kernel_id", args: "", returns: "uuid", security: "invoker" },
467
580
  { name: "work_approval_approvers", args: "p_organization_id uuid, p_subject_id uuid, p_approver_id uuid DEFAULT NULL::uuid", returns: "TABLE(user_id uuid, name text, why text)", security: "definer" },
468
581
  { name: "work_approval_decide", args: "p_organization_id uuid, p_approval_id uuid, p_approve boolean, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
582
+ { name: "work_approval_kinds", args: "", returns: "text[]", security: "invoker" },
469
583
  { name: "work_approval_may_decide", args: "p_organization_id uuid, p_approval_id uuid", returns: "boolean", security: "definer" },
470
584
  { name: "work_approval_read", args: "p_organization_id uuid, p_approval_id uuid", returns: "jsonb", security: "definer" },
471
585
  { name: "work_approval_request", args: "p_organization_id uuid, p_subject_id uuid, p_change jsonb, p_note text DEFAULT NULL::text, p_approver_id uuid DEFAULT NULL::uuid, p_origin text DEFAULT 'person'::text, p_conversation_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
@@ -485,6 +599,7 @@ var STORE_DOORS = [
485
599
  { name: "work_slot_index_name", args: "p_table_id uuid", returns: "text", security: "invoker" },
486
600
  { name: "work_slot_release", args: "p_organization_id uuid, p_hold_id uuid", returns: "boolean", security: "definer" },
487
601
  { name: "work_slots_declare", args: "p_organization_id uuid, p_name text, p_slug text, p_home_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
602
+ { name: "work_state_id", args: "p_organization_id uuid, p_table_id uuid, p_value text", returns: "uuid", security: "invoker" },
488
603
  { name: "work_states", args: "", returns: "TABLE(sort integer, name text, terminal boolean, next text[])", security: "invoker" },
489
604
  { name: "work_take_assignment", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
490
605
  { name: "work_template_declare", args: "p_organization_id uuid, p_name text, p_graph jsonb", returns: "uuid", security: "definer" },
@@ -502,6 +617,7 @@ var STORE_KNOBS = [
502
617
  { key: "code_paths_enabled", value: "false", type: "boolean" },
503
618
  { key: "consumer_chat_seeding_enabled", value: "false", type: "boolean" },
504
619
  { key: "consumer_checkout_enabled", value: "false", type: "boolean" },
620
+ { key: "consumer_context_enabled", value: "false", type: "boolean" },
505
621
  { key: "consumer_education_enabled", value: "false", type: "boolean" },
506
622
  { key: "consumer_extension_enabled", value: "false", type: "boolean" },
507
623
  { key: "consumer_grid_enabled", value: "false", type: "boolean" },
@@ -533,17 +649,18 @@ var STORE_KNOBS = [
533
649
  { key: "world_publish_enabled", value: "false", type: "boolean" }
534
650
  ];
535
651
  var STORE_REFUSAL_CODES = [
536
- { code: "02000", raised_by: "doc_render_body,doc_render_document,doc_render_read,doc_sign,doc_signature_intact,doc_signature_read,doc_template_read,doc_template_save,entity_field_retire,entity_field_update,entity_record_read,entity_value_write,external_history_event,external_rows,external_stub_upsert,external_writes_set,migrate_delete,migrate_extract_parent,migrate_merge,migrate_rename,migrate_reparent,migrate_retype,migrate_split,migrate_undo,organization_clear,read_record,record_delete,record_restore,record_update,relation_uncarry,share_access,share_grant,share_lane_set,share_people,share_revoke,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_assign,work_record_states,work_set_state" },
537
- { code: "0A000", raised_by: "external_rows,external_source_declare,external_write_through,promote_field,promoted_index_expr,promoted_query_sql,promoted_read,rule_eval,work_assign,work_slots_declare" },
538
- { 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,doc_render_write,doc_sign,doc_signature_write,doc_template_save,external_history_event,external_rows,external_source_declare,external_stub_upsert,external_write_through,external_writes_set,form_declare,form_submit,home_add,io_comment_write,io_import_open,io_outbox_drain,io_restore,migrate_purge,migrate_split,migrate_undo,organization_clear,organization_contents,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,table_declare,work_approval_decide,work_approval_request,work_template_declare" },
652
+ { code: "02000", raised_by: "dashboard_delete,dashboard_run,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,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,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_assign,work_record_states,work_set_state" },
653
+ { code: "0A000", raised_by: "external_rows,external_source_declare,external_write_through,promote_field,promoted_index_expr,promoted_query_sql,promoted_read,rule_eval,work_assign" },
654
+ { 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,dashboard_block_normalize,dashboard_declare,dashboard_window_sql,doc_render_write,doc_sign,doc_signature_write,doc_template_save,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_open,io_outbox_drain,io_restore,migrate_choice_keys,migrate_purge,migrate_reclass,migrate_split,migrate_undo,organization_clear,organization_contents,portal_declare,portal_invite,portal_principal_bind,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,table_declare,value_restore,work_approval_decide,work_approval_request,work_template_declare" },
655
+ { code: "22007", raised_by: "dashboard_window_sql" },
539
656
  { code: "22012", raised_by: "rule_eval" },
540
- { code: "22023", raised_by: "_entity_custom_fields_guard,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,containment_parent,doc_render_body,doc_render_write,doc_signature_write,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,io_import_open,io_proposal_accept,migrate_merge,my_levels,organization_clear,query_by_coordinates,query_rollup,record_update,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
541
- { code: "23503", raised_by: "_containment_guard,_field_document_for,_record_rule_uses,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,delete_rule,doc_sign,doc_template_save,form_declare,form_submit,home_add,io_comment_write,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,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,work_set_state,work_take_assignment,work_template_instantiate" },
657
+ { code: "22023", raised_by: "_entity_custom_fields_guard,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,io_import_open,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,portal_declare,query_by_coordinates,query_rollup,record_update,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
658
+ { code: "23503", raised_by: "_containment_guard,_field_document_for,_record_rule_uses,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,comment_write,dashboard_declare,delete_rule,doc_sign,doc_template_save,form_declare,form_submit,home_add,io_comment_write,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,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,subscription_mute,work_set_state,work_take_assignment,work_template_instantiate" },
542
659
  { code: "23505", raised_by: "_unique_rule_holds,doc_sign,doc_signature_write,entity_field_declare,field_declare,home_add,io_proposal_accept,relation_carry,relation_own,share_grant,work_approval_decide,work_slot_hold" },
543
- { code: "23514", raised_by: "_containment_guard,_dated_values_guard,_derived_fields,_entity_custom_fields_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,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,migrate_merge,relation_carry,relation_own,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
660
+ { code: "23514", raised_by: "_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,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,migrate_merge,relation_carry,relation_own,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
544
661
  { code: "40001", raised_by: "has_visibility_at" },
545
- { 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,entity_field_declare,entity_field_retire,entity_field_update,entity_value_write,external_write_through,form_declare,form_submit,io_comment_resolve,io_comment_write,io_restore,migrate_purge,my_levels,organization_clear,promote_table,query_visibility_parity,read_record,read_records,share_grant,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_person" },
546
- { code: "42703", raised_by: "entity_table" },
662
+ { 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,comment_write,entity_field_declare,entity_field_retire,entity_field_update,entity_value_write,external_write_through,form_declare,form_submit,io_comment_resolve,io_comment_write,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,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_person" },
663
+ { code: "42703", raised_by: "entity_table,portal_declare" },
547
664
  { code: "53400", raised_by: "anon_rate_take,delete_cascade_closure,promote_field" },
548
665
  { code: "54001", raised_by: "record_delete" },
549
666
  { code: "PT409", raised_by: "record_update" }
@@ -1719,6 +1836,32 @@ var DOORS = {
1719
1836
  // are server-lane doors and a browser never calls them.
1720
1837
  forms: "forms",
1721
1838
  formDeclare: "form_declare",
1839
+ // THE CLIENT PORTAL, OWNER'S SIDE (VIS-31 / PORTAL). A portal is how somebody
1840
+ // with NO membership is let in to see the records that name them. `portals`
1841
+ // lists them, `portalCard` opens one, `portalDeclare` states what it exposes,
1842
+ // `portalInvite` and `portalRevoke` are the two acts on a person, and
1843
+ // `portalPreview` is "view as this client" — it asks `custom.visible_set` for
1844
+ // HER user id, the same call `custom.read_records` makes when she opens the
1845
+ // page, so the preview cannot disagree with what she sees. The CLIENT-side
1846
+ // pair (`custom.portal_public`, `custom.portal_invitation`, `custom.portal_me`)
1847
+ // is deliberately absent here: those belong to the outsider's own shell.
1848
+ portals: "portals",
1849
+ portalCard: "portal_card",
1850
+ portalDeclare: "portal_declare",
1851
+ portalInvite: "portal_invite",
1852
+ portalRevoke: "portal_revoke",
1853
+ portalPreview: "portal_preview",
1854
+ // SCR-16 — the canvas. A dashboard is a record in the presentation kernel
1855
+ // whose blocks are saved SPECS for the eighth verb; `dashboardRun` walks them
1856
+ // under the CALLER'S principal, so nothing here is precomputed and nothing is
1857
+ // summed in a browser. `dashboardStuck` is the seventh block kind on its own,
1858
+ // because "what has not moved in fourteen days" is a question a screen asks
1859
+ // outside a canvas too.
1860
+ dashboards: "dashboards",
1861
+ dashboardDeclare: "dashboard_declare",
1862
+ dashboardRun: "dashboard_run",
1863
+ dashboardStuck: "dashboard_stuck",
1864
+ dashboardDelete: "dashboard_delete",
1722
1865
  // The eighth verb (AGT-N-8): a grouped, bucketed, filtered count/sum/avg/
1723
1866
  // min/max computed INSIDE the read door's own query, so a chart shows exactly
1724
1867
  // the rows this person may see and never fetches the ones they may not.
@@ -1729,6 +1872,16 @@ var DOORS = {
1729
1872
  // over a saved view. There is no subscription TABLE and no second notifier.
1730
1873
  aggSubscriptions: "agg_subscriptions",
1731
1874
  aggSubscriptionCadences: "agg_subscription_cadences",
1875
+ // The OWNER's side of DOOR-18. `agg_subscriptions` is the notifier's reader
1876
+ // and is not client-callable; these two are what a person reaches: what am I
1877
+ // being told about, and switch this one off. A form's notify Rule is one of
1878
+ // these rows, so "tell me when a patient arrives" can also be un-told.
1879
+ subscriptions: "subscriptions",
1880
+ subscriptionMute: "subscription_mute",
1881
+ // The cadence CATALOGUE a person's screen may ask for. `agg_subscription_cadences`
1882
+ // above is the notifier's own and holds no client grant; this door delegates to
1883
+ // it, so a picker and the digest runner can never offer different words.
1884
+ subscriptionCadences: "subscription_cadences",
1732
1885
  // The doc doors: a template is saved, a render is written once and frozen,
1733
1886
  // and a signature is checked against the exact bytes that were signed.
1734
1887
  docTemplateSave: "doc_template_save",
@@ -1738,6 +1891,15 @@ var DOORS = {
1738
1891
  docUnresolvedTokens: "doc_unresolved_tokens",
1739
1892
  docSign: "doc_sign",
1740
1893
  docSignatureIntact: "doc_signature_intact",
1894
+ // THE PLURAL ACTS. Until 2026-09-20 this package read `custom.doc_template`,
1895
+ // `custom.doc_render` and `custom.doc_signature` with a direct PostgREST
1896
+ // `.from()`, and all three hold NO client SELECT — so every list in product #5
1897
+ // opened on "permission denied for view doc_template". A list is a DOOR, never
1898
+ // a grant on the thing behind it (DOORS-TWO).
1899
+ docTemplates: "doc_templates",
1900
+ docTemplateDelete: "doc_template_delete",
1901
+ docRenders: "doc_renders",
1902
+ docSignatures: "doc_signatures",
1741
1903
  // THE ANONYMOUS LANE (W4-ANON). It landed, and it landed as SEVEN doors
1742
1904
  // rather than the one this package had guessed at: a token is issued and
1743
1905
  // verified separately from the write it authorises, a form is published
@@ -1833,6 +1995,14 @@ var BY_SQLSTATE = {
1833
1995
  // caught it raised by a door this package did not know about — which is the
1834
1996
  // suite working, and is why the map is a census rather than a guess.
1835
1997
  "42703": "invalid_argument",
1998
+ // 22007 — a date or a time the store could not read as one. It is raised by
1999
+ // `custom.dashboard_window_sql`, which is handed a window a caller wrote
2000
+ // ("last 30 days", a literal date), so the class is again "the call named
2001
+ // something the shape does not accept" and the store's own sentence names the
2002
+ // text it could not read. Added 2026-09-20 (lane SCREEN-BREAK) after the
2003
+ // live-door census caught it — the same way 42703 arrived, which is the
2004
+ // census working rather than a guess.
2005
+ "22007": "invalid_argument",
1836
2006
  "02000": "not_found",
1837
2007
  "23503": "missing_reference",
1838
2008
  "23505": "already_exists",
@@ -2202,9 +2372,11 @@ function createRecordsClient(config) {
2202
2372
  );
2203
2373
  if (!applicable.ok) return err(applicable.error);
2204
2374
  const rows = applicable.data ?? [];
2205
- return ok(
2206
- rows.map((row) => ({ id: row.id, ...row.data }))
2375
+ const fields = rows.map((row) => ({ id: row.id, ...row.data }));
2376
+ fields.sort(
2377
+ (a, b) => (a.sort ?? 0) - (b.sort ?? 0) || (a.label ?? "").localeCompare(b.label ?? "")
2207
2378
  );
2379
+ return ok(fields);
2208
2380
  },
2209
2381
  async fieldOptions({ field_id }) {
2210
2382
  return callDoor(
@@ -2378,6 +2550,65 @@ function createRecordsClient(config) {
2378
2550
  "formDeclare"
2379
2551
  );
2380
2552
  },
2553
+ async portals() {
2554
+ return callDoor(DOORS.portals, { p_organization_id: org }, "portals");
2555
+ },
2556
+ async portalCard({ portal_id }) {
2557
+ return callDoor(
2558
+ DOORS.portalCard,
2559
+ { p_organization_id: org, p_portal_id: portal_id },
2560
+ "portalCard"
2561
+ );
2562
+ },
2563
+ async portalDeclare(args) {
2564
+ return callDoor(
2565
+ DOORS.portalDeclare,
2566
+ {
2567
+ p_organization_id: org,
2568
+ p_title: args.title,
2569
+ p_client_table_id: args.client_table_id,
2570
+ p_tables: args.tables,
2571
+ p_portal_id: args.portal_id ?? null,
2572
+ p_slug: args.slug ?? null,
2573
+ p_sign_in_method: args.sign_in_method ?? "magic_link"
2574
+ },
2575
+ "portalDeclare"
2576
+ );
2577
+ },
2578
+ async portalInvite(args) {
2579
+ return callDoor(
2580
+ DOORS.portalInvite,
2581
+ {
2582
+ p_organization_id: org,
2583
+ p_portal_id: args.portal_id,
2584
+ p_client_record_id: args.client_record_id,
2585
+ p_email: args.email,
2586
+ // ALWAYS null from a client. See the interface comment: an invitation
2587
+ // confers nothing until the person follows their own sign-in link.
2588
+ p_user_id: null
2589
+ },
2590
+ "portalInvite"
2591
+ );
2592
+ },
2593
+ async portalRevoke({ portal_id, principal_id }) {
2594
+ return callDoor(
2595
+ DOORS.portalRevoke,
2596
+ { p_organization_id: org, p_portal_id: portal_id, p_principal_id: principal_id },
2597
+ "portalRevoke"
2598
+ );
2599
+ },
2600
+ async portalPreview({ portal_id, principal_id, table_id }) {
2601
+ return callDoor(
2602
+ DOORS.portalPreview,
2603
+ {
2604
+ p_organization_id: org,
2605
+ p_portal_id: portal_id,
2606
+ p_principal_id: principal_id,
2607
+ p_table_id: table_id
2608
+ },
2609
+ "portalPreview"
2610
+ );
2611
+ },
2381
2612
  async ruleRun({ rule_id, values, context }) {
2382
2613
  return callDoor(
2383
2614
  DOORS.ruleRun,
@@ -2402,6 +2633,55 @@ function createRecordsClient(config) {
2402
2633
  "ruleEval"
2403
2634
  );
2404
2635
  },
2636
+ async dashboards(args) {
2637
+ return callDoor(
2638
+ DOORS.dashboards,
2639
+ { p_organization_id: org, p_table_id: args?.table_id ?? null },
2640
+ "dashboards"
2641
+ );
2642
+ },
2643
+ async dashboardDeclare(args) {
2644
+ return callDoor(
2645
+ DOORS.dashboardDeclare,
2646
+ {
2647
+ p_organization_id: org,
2648
+ p_table_id: args.table_id,
2649
+ p_name: args.name,
2650
+ p_blocks: args.blocks ?? [],
2651
+ p_presentation: args.presentation ?? {},
2652
+ p_dashboard_id: args.dashboard_id ?? null
2653
+ },
2654
+ "dashboardDeclare"
2655
+ );
2656
+ },
2657
+ async dashboardRun({ dashboard_id, filter }) {
2658
+ return callDoor(
2659
+ DOORS.dashboardRun,
2660
+ { p_organization_id: org, p_dashboard_id: dashboard_id, p_filter: filter ?? {} },
2661
+ "dashboardRun"
2662
+ );
2663
+ },
2664
+ async dashboardStuck({ table_id, state_key, days, filter, limit }) {
2665
+ return callDoor(
2666
+ DOORS.dashboardStuck,
2667
+ {
2668
+ p_organization_id: org,
2669
+ p_table_id: table_id,
2670
+ p_state_key: state_key,
2671
+ p_days: days ?? 14,
2672
+ p_filter: filter ?? {},
2673
+ p_limit: limit ?? 50
2674
+ },
2675
+ "dashboardStuck"
2676
+ );
2677
+ },
2678
+ async dashboardDelete({ dashboard_id }) {
2679
+ return callDoor(
2680
+ DOORS.dashboardDelete,
2681
+ { p_organization_id: org, p_dashboard_id: dashboard_id },
2682
+ "dashboardDelete"
2683
+ );
2684
+ },
2405
2685
  async recordAggregate({ table_id, groupBy, measures, bucket, filter, limit }) {
2406
2686
  return callDoor(
2407
2687
  DOORS.recordAggregate,
@@ -2437,6 +2717,27 @@ function createRecordsClient(config) {
2437
2717
  async aggSubscriptionCadences() {
2438
2718
  return callDoor(DOORS.aggSubscriptionCadences, {}, "aggSubscriptionCadences");
2439
2719
  },
2720
+ async subscriptionCadences() {
2721
+ return callDoor(
2722
+ DOORS.subscriptionCadences,
2723
+ { p_organization_id: org },
2724
+ "subscriptionCadences"
2725
+ );
2726
+ },
2727
+ async subscriptions(args) {
2728
+ return callDoor(
2729
+ DOORS.subscriptions,
2730
+ { p_organization_id: org, p_table_id: args?.table_id ?? null },
2731
+ "subscriptions"
2732
+ );
2733
+ },
2734
+ async subscriptionMute({ rule_id, muted }) {
2735
+ return callDoor(
2736
+ DOORS.subscriptionMute,
2737
+ { p_organization_id: org, p_rule_id: rule_id, p_muted: muted },
2738
+ "subscriptionMute"
2739
+ );
2740
+ },
2440
2741
  async docTemplateSave({ table_id, name, body, template_id }) {
2441
2742
  return callDoor(
2442
2743
  DOORS.docTemplateSave,
@@ -2487,32 +2788,52 @@ function createRecordsClient(config) {
2487
2788
  "docSign"
2488
2789
  );
2489
2790
  },
2791
+ // A LIST IS A DOOR, NEVER A GRANT ON THE THING BEHIND IT. These three used to
2792
+ // read `custom.doc_template`, `custom.doc_render` and `custom.doc_signature`
2793
+ // with a direct PostgREST `.from()`, and none of the three holds a client
2794
+ // SELECT — so a person could save a template they could never list and
2795
+ // render a document they could never find again, and every document screen
2796
+ // opened on "permission denied for view doc_template". The doors below
2797
+ // narrow inside the definer, after the ladder has spoken (DOORS-TWO).
2490
2798
  async docTemplates({ table_id }) {
2491
- const response = await config.dataSource.schema(schema).from("doc_template").select("*").eq("organization_id", org).eq("renders_table_id", table_id).order("name");
2492
- if (response.error) {
2493
- const refusal = mapPgError(response.error, "docTemplates");
2494
- scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where: "docTemplates" });
2495
- return err(refusal);
2496
- }
2497
- return ok(response.data ?? []);
2799
+ const answered = await callDoor(
2800
+ DOORS.docTemplates,
2801
+ { p_organization_id: org, p_table_id: table_id },
2802
+ "docTemplates"
2803
+ );
2804
+ if (!answered.ok) return answered;
2805
+ return ok(
2806
+ answered.data.map((row) => ({ ...row, id: row["template_id"] }))
2807
+ );
2808
+ },
2809
+ async docTemplateDelete({ template_id }) {
2810
+ return callDoor(
2811
+ DOORS.docTemplateDelete,
2812
+ { p_organization_id: org, p_template_id: template_id },
2813
+ "docTemplateDelete"
2814
+ );
2498
2815
  },
2499
2816
  async docRenders({ record_id }) {
2500
- const response = await config.dataSource.schema(schema).from("doc_render").select("*").eq("organization_id", org).eq("record_id", record_id).is("deleted_at", null).order("rendered_at", { ascending: false });
2501
- if (response.error) {
2502
- const refusal = mapPgError(response.error, "docRenders");
2503
- scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where: "docRenders" });
2504
- return err(refusal);
2505
- }
2506
- return ok(response.data ?? []);
2817
+ const answered = await callDoor(
2818
+ DOORS.docRenders,
2819
+ { p_organization_id: org, p_record_id: record_id },
2820
+ "docRenders"
2821
+ );
2822
+ if (!answered.ok) return answered;
2823
+ return ok(
2824
+ answered.data.map((row) => ({ ...row, id: row["render_id"] }))
2825
+ );
2507
2826
  },
2508
2827
  async docSignatures({ record_id }) {
2509
- const response = await config.dataSource.schema(schema).from("doc_signature").select("*").eq("organization_id", org).eq("record_id", record_id).is("deleted_at", null).order("signed_at", { ascending: false });
2510
- if (response.error) {
2511
- const refusal = mapPgError(response.error, "docSignatures");
2512
- scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where: "docSignatures" });
2513
- return err(refusal);
2514
- }
2515
- return ok(response.data ?? []);
2828
+ const answered = await callDoor(
2829
+ DOORS.docSignatures,
2830
+ { p_organization_id: org, p_record_id: record_id },
2831
+ "docSignatures"
2832
+ );
2833
+ if (!answered.ok) return answered;
2834
+ return ok(
2835
+ answered.data.map((row) => ({ ...row, id: row["signature_id"] }))
2836
+ );
2516
2837
  },
2517
2838
  async recordValuesVersioned({ record_id }) {
2518
2839
  return readValues(record_id);
@@ -3040,7 +3361,7 @@ function pgJsonbText(value) {
3040
3361
  return JSON.stringify(value);
3041
3362
  }
3042
3363
  var jsonBytes = (value) => new TextEncoder().encode(pgJsonbText(value)).length;
3043
- var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3364
+ var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3044
3365
  function labelOf(field) {
3045
3366
  return field.label && field.label.length > 0 ? field.label : field.key;
3046
3367
  }
@@ -3150,7 +3471,7 @@ function predictValueRefusals(fields, values, recordType) {
3150
3471
  message: `${label} takes one of its choices, and it was given a ${jsonType(item)}`,
3151
3472
  hint: "FLD-5 / FLD-6: a list field stores the id of the option RECORD, because every pick-list is already a Table."
3152
3473
  });
3153
- } else if (!UUID.test(item)) {
3474
+ } else if (!UUID2.test(item)) {
3154
3475
  found.push({
3155
3476
  ...base,
3156
3477
  message: `${label} was given a choice that is not one of its choices`,
@@ -3160,7 +3481,7 @@ function predictValueRefusals(fields, values, recordType) {
3160
3481
  } else if (field.type === "relation") {
3161
3482
  if (typeof item !== "string") {
3162
3483
  found.push({ ...base, message: `${label} points at a record, and it was given a ${jsonType(item)}`, hint: "FLD-1: relation." });
3163
- } else if (!UUID.test(item)) {
3484
+ } else if (!UUID2.test(item)) {
3164
3485
  found.push({
3165
3486
  ...base,
3166
3487
  message: `${label} points at something that is not there`,
@@ -3492,6 +3813,9 @@ export {
3492
3813
  asWriteConflict,
3493
3814
  atLeast,
3494
3815
  cellText,
3816
+ choiceSlug,
3817
+ choiceValuesOf,
3818
+ choicesOf,
3495
3819
  createRecordsClient,
3496
3820
  doorAbsent,
3497
3821
  doorCensus,
@@ -3500,15 +3824,21 @@ export {
3500
3824
  exportCsv,
3501
3825
  exportXlsx,
3502
3826
  highestLevel,
3827
+ holdsARetiredChoice,
3503
3828
  importCsv,
3504
3829
  importXlsx,
3505
3830
  intersectIds,
3506
3831
  isRecordsErr,
3832
+ isTheChosen,
3833
+ looksLikeAnId,
3507
3834
  mapPgError,
3508
3835
  measureKey,
3509
3836
  ok,
3837
+ optionKey,
3838
+ optionLabel,
3510
3839
  parseCsv,
3511
3840
  planQuery,
3841
+ portalPath,
3512
3842
  predictEnvelopeRefusal,
3513
3843
  predictSizeRefusal,
3514
3844
  predictValueRefusals,