@ai-matrx/records 0.8.0 → 0.16.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.
@@ -145,6 +145,20 @@ var STORE_DOORS = [
145
145
  { name: "caller_role", args: "", returns: "name", security: "invoker" },
146
146
  { 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" },
147
147
  { 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" },
148
+ { name: "choice_census", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
149
+ { name: "choice_field_map", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "invoker" },
150
+ { name: "choice_filter_normalize", args: "p_map jsonb, p_filter jsonb", returns: "jsonb", security: "invoker" },
151
+ { 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" },
152
+ { name: "choice_key_of", args: "p_field jsonb, p_token text", returns: "text", security: "invoker" },
153
+ { name: "choice_options", args: "p_organization_id uuid, p_options_table_id uuid", returns: "jsonb", security: "invoker" },
154
+ { name: "choice_render", args: "p_organization_id uuid, p_table_id uuid, p_doc jsonb", returns: "jsonb", security: "invoker" },
155
+ { name: "choice_render_groups", args: "p_map jsonb, p_groups jsonb", returns: "jsonb", security: "invoker" },
156
+ { name: "choice_render_note", args: "p_field jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
157
+ { name: "choice_render_value", args: "p_field jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
158
+ { name: "choice_slug", args: "p_word text", returns: "text", security: "invoker" },
159
+ { name: "choice_synonyms", args: "p_organization_id uuid, p_table_id uuid, p_token text", returns: "text[]", security: "invoker" },
160
+ { name: "choice_synonyms_in", args: "p_map jsonb, p_token text", returns: "text[]", security: "invoker" },
161
+ { name: "choice_words", args: "p_field jsonb", returns: "text", security: "invoker" },
148
162
  { name: "client_write_grants", args: "", returns: "TABLE(role_name text, object_name text, privilege text)", security: "invoker" },
149
163
  { 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" },
150
164
  { name: "containment_chain", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(ancestor_id uuid, depth integer)", security: "invoker" },
@@ -153,6 +167,17 @@ var STORE_DOORS = [
153
167
  { name: "containment_parent", args: "p_data jsonb", returns: "uuid", security: "invoker" },
154
168
  { name: "cross_organization_links_open", args: "p_source_organization_id uuid, p_target_organization_id uuid", returns: "boolean", security: "invoker" },
155
169
  { name: "custom_fields_tables", args: "", returns: "TABLE(token text, schema_name text, table_name text)", security: "invoker" },
170
+ { name: "dashboard_block_normalize", args: "p_organization_id uuid, p_subject_table_id uuid, p_block jsonb", returns: "jsonb", security: "definer" },
171
+ { name: "dashboard_class", args: "", returns: "text", security: "invoker" },
172
+ { 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" },
173
+ { name: "dashboard_delete", args: "p_organization_id uuid, p_dashboard_id uuid", returns: "boolean", security: "definer" },
174
+ { name: "dashboard_field_keys", args: "p_organization_id uuid, p_table_id uuid", returns: "text[]", security: "definer" },
175
+ { name: "dashboard_kinds", args: "", returns: "text[]", security: "invoker" },
176
+ { name: "dashboard_moment_sql", args: "p_key text", returns: "text", security: "invoker" },
177
+ { name: "dashboard_run", args: "p_organization_id uuid, p_dashboard_id uuid, p_filter jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
178
+ { 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" },
179
+ { name: "dashboard_window_sql", args: "p_key text, p_window jsonb", returns: "text", security: "invoker" },
180
+ { 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" },
156
181
  { name: "delete_cascade_closure", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid[]", security: "invoker" },
157
182
  { name: "delete_preview", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
158
183
  { name: "delete_rule", args: "p_organization_id uuid, p_record_id uuid, p_apply boolean DEFAULT true", returns: "jsonb", security: "definer" },
@@ -249,16 +274,20 @@ var STORE_DOORS = [
249
274
  { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "integer", security: "definer" },
250
275
  { 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" },
251
276
  { 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" },
277
+ { 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" },
278
+ { 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" },
252
279
  { name: "lookup_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb", returns: "jsonb", security: "invoker" },
253
280
  { 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" },
254
281
  { 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" },
255
282
  { name: "merge_field_kernel_id", args: "", returns: "uuid", security: "invoker" },
283
+ { name: "migrate_choice_keys", args: "p_organization_id uuid, p_table_id uuid, p_dry_run boolean DEFAULT false", returns: "jsonb", security: "definer" },
256
284
  { name: "migrate_delete", args: "p_organization_id uuid, p_record_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
257
285
  { name: "migrate_demote", args: "p_organization_id uuid, p_table_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
258
286
  { 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" },
259
287
  { 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" },
260
288
  { name: "migrate_promote", args: "p_organization_id uuid, p_table_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
261
289
  { 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" },
290
+ { 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" },
262
291
  { name: "migrate_rename", args: "p_organization_id uuid, p_id uuid, p_to text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
263
292
  { 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" },
264
293
  { name: "migrate_retype", args: "p_organization_id uuid, p_id uuid, p_to text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
@@ -278,6 +307,20 @@ var STORE_DOORS = [
278
307
  { 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" },
279
308
  { name: "per_value_access_words", args: "", returns: "text[]", security: "invoker" },
280
309
  { name: "person_kernel_id", args: "", returns: "uuid", security: "invoker" },
310
+ { name: "portal_admits", args: "p_organization_id uuid, p_user_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "definer" },
311
+ { name: "portal_card", args: "p_organization_id uuid, p_portal_id uuid", returns: "jsonb", security: "definer" },
312
+ { 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" },
313
+ { 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" },
314
+ { name: "portal_invitation", args: "p_slug text, p_email text", returns: "jsonb", security: "definer" },
315
+ { 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" },
316
+ { name: "portal_me", args: "", returns: "jsonb", security: "definer" },
317
+ { 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" },
318
+ { name: "portal_principal_bind", args: "p_organization_id uuid, p_principal_id uuid, p_user_id uuid", returns: "jsonb", security: "definer" },
319
+ { name: "portal_public", args: "p_slug text", returns: "jsonb", security: "definer" },
320
+ { name: "portal_record_title", args: "p_organization_id uuid, p_record_id uuid", returns: "text", security: "definer" },
321
+ { name: "portal_revoke", args: "p_organization_id uuid, p_portal_id uuid, p_principal_id uuid", returns: "jsonb", security: "definer" },
322
+ { name: "portal_slug", args: "p_organization_id uuid, p_title text, p_portal_id uuid DEFAULT NULL::uuid", returns: "text", security: "definer" },
323
+ { 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" },
281
324
  { name: "presentation_kernel_id", args: "", returns: "uuid", security: "invoker" },
282
325
  { name: "promote_field", args: "p_organization_id uuid, p_table_id uuid, p_field_id uuid", returns: "jsonb", security: "invoker" },
283
326
  { name: "promote_table", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
@@ -328,10 +371,12 @@ var STORE_DOORS = [
328
371
  { name: "record_resolve", args: "p_organization_id uuid, p_id uuid", returns: "jsonb", security: "definer" },
329
372
  { name: "record_restore", args: "p_organization_id uuid, p_record_id uuid", returns: "void", security: "definer" },
330
373
  { name: "record_state_as_of", args: "p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(state jsonb, replayed boolean)", security: "definer" },
374
+ { name: "record_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
331
375
  { 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" },
332
376
  { name: "record_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
333
377
  { 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" },
334
378
  { name: "record_write", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb", returns: "uuid", security: "definer" },
379
+ { name: "refusals_claiming_a_level_never_asked", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
335
380
  { name: "relation_carry", args: "p_organization_id uuid, p_container_id uuid, p_item_id uuid", returns: "uuid", security: "definer" },
336
381
  { name: "relation_edges_withdraw", args: "p_organization_id uuid, p_field_ids uuid[], p_why text", returns: "integer", security: "definer" },
337
382
  { name: "relation_own", args: "p_organization_id uuid, p_owner_id uuid, p_target_id uuid", returns: "uuid", security: "definer" },
@@ -377,7 +422,10 @@ var STORE_DOORS = [
377
422
  { 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" },
378
423
  { name: "storage_modes", args: "", returns: "text[]", security: "invoker" },
379
424
  { name: "store_is_open", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "invoker" },
425
+ { name: "subscription_mute", args: "p_organization_id uuid, p_rule_id uuid, p_muted boolean DEFAULT true", returns: "boolean", security: "definer" },
426
+ { 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" },
380
427
  { name: "table_capacity", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
428
+ { 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" },
381
429
  { name: "table_contents", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(record_id uuid, kind text, goes_at integer)", security: "invoker" },
382
430
  { name: "table_declare", args: "p_organization_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
383
431
  { name: "table_has_a_visible_record", args: "p_user uuid, p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "definer" },
@@ -411,6 +459,7 @@ var STORE_DOORS = [
411
459
  { name: "widget_kernel_id", args: "", returns: "uuid", security: "invoker" },
412
460
  { 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" },
413
461
  { 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" },
462
+ { name: "work_approval_kinds", args: "", returns: "text[]", security: "invoker" },
414
463
  { name: "work_approval_may_decide", args: "p_organization_id uuid, p_approval_id uuid", returns: "boolean", security: "definer" },
415
464
  { name: "work_approval_read", args: "p_organization_id uuid, p_approval_id uuid", returns: "jsonb", security: "definer" },
416
465
  { 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" },
@@ -430,6 +479,7 @@ var STORE_DOORS = [
430
479
  { name: "work_slot_index_name", args: "p_table_id uuid", returns: "text", security: "invoker" },
431
480
  { name: "work_slot_release", args: "p_organization_id uuid, p_hold_id uuid", returns: "boolean", security: "definer" },
432
481
  { 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" },
482
+ { name: "work_state_id", args: "p_organization_id uuid, p_table_id uuid, p_value text", returns: "uuid", security: "invoker" },
433
483
  { name: "work_states", args: "", returns: "TABLE(sort integer, name text, terminal boolean, next text[])", security: "invoker" },
434
484
  { name: "work_take_assignment", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
435
485
  { name: "work_template_declare", args: "p_organization_id uuid, p_name text, p_graph jsonb", returns: "uuid", security: "definer" },
@@ -478,17 +528,18 @@ var STORE_KNOBS = [
478
528
  { key: "world_publish_enabled", value: "false", type: "boolean" }
479
529
  ];
480
530
  var STORE_REFUSAL_CODES = [
481
- { 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" },
482
- { 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" },
483
- { 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" },
531
+ { 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_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_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_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" },
532
+ { 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" },
533
+ { 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,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,work_approval_decide,work_approval_request,work_template_declare" },
534
+ { code: "22007", raised_by: "dashboard_window_sql" },
484
535
  { code: "22012", raised_by: "rule_eval" },
485
- { 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" },
486
- { 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" },
536
+ { 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,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" },
537
+ { 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,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" },
487
538
  { 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" },
488
- { 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" },
539
+ { 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" },
489
540
  { code: "40001", raised_by: "has_visibility_at" },
490
- { 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" },
491
- { code: "42703", raised_by: "entity_table" },
541
+ { 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,migrate_reclass,my_levels,organization_clear,portal_declare,portal_invitation,portal_invite,portal_principal_bind,promote_table,query_visibility_parity,read_record,read_records,share_grant,subscription_mute,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_person" },
542
+ { code: "42703", raised_by: "entity_table,portal_declare" },
492
543
  { code: "53400", raised_by: "anon_rate_take,delete_cascade_closure,promote_field" },
493
544
  { code: "54001", raised_by: "record_delete" },
494
545
  { code: "PT409", raised_by: "record_update" }
@@ -1598,6 +1649,24 @@ var DOORS = {
1598
1649
  fieldDeclare: "field_declare",
1599
1650
  fieldUpdate: "field_update",
1600
1651
  fieldRetire: "field_retire",
1652
+ // CUSTOM FIELDS ON A STANDARD BUSINESS TABLE. Every door above is keyed by a
1653
+ // custom Table's uuid, and a standard table has no Table record - so until
1654
+ // 2026-09-20 `custom.applicable_fields(org, 'party', null)` answered `22P02
1655
+ // invalid input syntax for uuid` and there was no other way in. These are
1656
+ // keyed by the REGISTRY TOKEN instead, and they are one set for all 643
1657
+ // tables the registry types Entity or Detail. The three value doors are
1658
+ // SECURITY INVOKER in the database on purpose: the standard table's own
1659
+ // row-level security is what decides who may read and write its rows, and a
1660
+ // definer wrapper would replace it with a second access system.
1661
+ entityTable: "entity_table",
1662
+ entityFields: "entity_fields",
1663
+ entityFieldDeclare: "entity_field_declare",
1664
+ entityFieldUpdate: "entity_field_update",
1665
+ entityFieldRetire: "entity_field_retire",
1666
+ entityFieldRights: "entity_field_rights",
1667
+ entityRecordRead: "entity_record_read",
1668
+ entityValueWrite: "entity_value_write",
1669
+ entityRecordsFind: "entity_records_find",
1601
1670
  tableCapacity: "table_capacity",
1602
1671
  tableStorage: "table_storage",
1603
1672
  promoteTable: "promote_table",
@@ -1646,6 +1715,32 @@ var DOORS = {
1646
1715
  // are server-lane doors and a browser never calls them.
1647
1716
  forms: "forms",
1648
1717
  formDeclare: "form_declare",
1718
+ // THE CLIENT PORTAL, OWNER'S SIDE (VIS-31 / PORTAL). A portal is how somebody
1719
+ // with NO membership is let in to see the records that name them. `portals`
1720
+ // lists them, `portalCard` opens one, `portalDeclare` states what it exposes,
1721
+ // `portalInvite` and `portalRevoke` are the two acts on a person, and
1722
+ // `portalPreview` is "view as this client" — it asks `custom.visible_set` for
1723
+ // HER user id, the same call `custom.read_records` makes when she opens the
1724
+ // page, so the preview cannot disagree with what she sees. The CLIENT-side
1725
+ // pair (`custom.portal_public`, `custom.portal_invitation`, `custom.portal_me`)
1726
+ // is deliberately absent here: those belong to the outsider's own shell.
1727
+ portals: "portals",
1728
+ portalCard: "portal_card",
1729
+ portalDeclare: "portal_declare",
1730
+ portalInvite: "portal_invite",
1731
+ portalRevoke: "portal_revoke",
1732
+ portalPreview: "portal_preview",
1733
+ // SCR-16 — the canvas. A dashboard is a record in the presentation kernel
1734
+ // whose blocks are saved SPECS for the eighth verb; `dashboardRun` walks them
1735
+ // under the CALLER'S principal, so nothing here is precomputed and nothing is
1736
+ // summed in a browser. `dashboardStuck` is the seventh block kind on its own,
1737
+ // because "what has not moved in fourteen days" is a question a screen asks
1738
+ // outside a canvas too.
1739
+ dashboards: "dashboards",
1740
+ dashboardDeclare: "dashboard_declare",
1741
+ dashboardRun: "dashboard_run",
1742
+ dashboardStuck: "dashboard_stuck",
1743
+ dashboardDelete: "dashboard_delete",
1649
1744
  // The eighth verb (AGT-N-8): a grouped, bucketed, filtered count/sum/avg/
1650
1745
  // min/max computed INSIDE the read door's own query, so a chart shows exactly
1651
1746
  // the rows this person may see and never fetches the ones they may not.
@@ -1656,6 +1751,12 @@ var DOORS = {
1656
1751
  // over a saved view. There is no subscription TABLE and no second notifier.
1657
1752
  aggSubscriptions: "agg_subscriptions",
1658
1753
  aggSubscriptionCadences: "agg_subscription_cadences",
1754
+ // The OWNER's side of DOOR-18. `agg_subscriptions` is the notifier's reader
1755
+ // and is not client-callable; these two are what a person reaches: what am I
1756
+ // being told about, and switch this one off. A form's notify Rule is one of
1757
+ // these rows, so "tell me when a patient arrives" can also be un-told.
1758
+ subscriptions: "subscriptions",
1759
+ subscriptionMute: "subscription_mute",
1659
1760
  // The doc doors: a template is saved, a render is written once and frozen,
1660
1761
  // and a signature is checked against the exact bytes that were signed.
1661
1762
  docTemplateSave: "doc_template_save",
@@ -1704,6 +1805,23 @@ var DOORS = {
1704
1805
  workSlotRelease: "work_slot_release",
1705
1806
  workSlotHolds: "work_slot_holds",
1706
1807
  workSlotExpire: "work_slot_expire",
1808
+ // THE WORK LAYER'S OWN DOORS (lane WORK-DOORS, 2026-09-20). Until this lane
1809
+ // all nineteen `custom.work_*` functions were SECURITY INVOKER with no client
1810
+ // grant: REC-69, REC-70 and REC-71 were live in the store and unreachable
1811
+ // from a browser. These are the verbs a person actually uses.
1812
+ workPerson: "work_person",
1813
+ workAssign: "work_assign",
1814
+ workRecordStates: "work_record_states",
1815
+ workSetState: "work_set_state",
1816
+ workList: "work_list",
1817
+ workTemplates: "work_templates",
1818
+ /** THE ONE QUEUE: assignments, approvals and the agent's proposals together. */
1819
+ workInbox: "work_inbox",
1820
+ workApprovalApprovers: "work_approval_approvers",
1821
+ workApprovalRequest: "work_approval_request",
1822
+ workApprovalMayDecide: "work_approval_may_decide",
1823
+ workApprovalDecide: "work_approval_decide",
1824
+ workApprovalRead: "work_approval_read",
1707
1825
  // Declared here BECAUSE they do not exist yet: naming them is what makes the
1708
1826
  // absence visible to `pnpm check:store-registry` and to the suite.
1709
1827
  metadataSearch: "metadata_search",
@@ -1735,6 +1853,14 @@ var BY_SQLSTATE = {
1735
1853
  // caught it raised by a door this package did not know about — which is the
1736
1854
  // suite working, and is why the map is a census rather than a guess.
1737
1855
  "42703": "invalid_argument",
1856
+ // 22007 — a date or a time the store could not read as one. It is raised by
1857
+ // `custom.dashboard_window_sql`, which is handed a window a caller wrote
1858
+ // ("last 30 days", a literal date), so the class is again "the call named
1859
+ // something the shape does not accept" and the store's own sentence names the
1860
+ // text it could not read. Added 2026-09-20 (lane SCREEN-BREAK) after the
1861
+ // live-door census caught it — the same way 42703 arrived, which is the
1862
+ // census working rather than a guess.
1863
+ "22007": "invalid_argument",
1738
1864
  "02000": "not_found",
1739
1865
  "23503": "missing_reference",
1740
1866
  "23505": "already_exists",
@@ -2104,9 +2230,11 @@ function createRecordsClient(config) {
2104
2230
  );
2105
2231
  if (!applicable.ok) return err(applicable.error);
2106
2232
  const rows = applicable.data ?? [];
2107
- return ok(
2108
- rows.map((row) => ({ id: row.id, ...row.data }))
2233
+ const fields = rows.map((row) => ({ id: row.id, ...row.data }));
2234
+ fields.sort(
2235
+ (a, b) => (a.sort ?? 0) - (b.sort ?? 0) || (a.label ?? "").localeCompare(b.label ?? "")
2109
2236
  );
2237
+ return ok(fields);
2110
2238
  },
2111
2239
  async fieldOptions({ field_id }) {
2112
2240
  return callDoor(
@@ -2129,6 +2257,88 @@ function createRecordsClient(config) {
2129
2257
  "fieldDeclare"
2130
2258
  );
2131
2259
  },
2260
+ async entityTable({ token }) {
2261
+ const answer = await callDoor(
2262
+ DOORS.entityTable,
2263
+ { p_token: token },
2264
+ "entityTable"
2265
+ );
2266
+ if (!answer.ok) return err(answer.error);
2267
+ const row = Array.isArray(answer.data) ? answer.data[0] : answer.data;
2268
+ if (!row) {
2269
+ return err({
2270
+ code: "not_found",
2271
+ message: `The registry answered nothing for the table "${token}".`,
2272
+ hint: "REC-33: a standard table is named by its registry token. Nothing was read."
2273
+ });
2274
+ }
2275
+ return ok(row);
2276
+ },
2277
+ async entityFields({ token }) {
2278
+ const rows = await callDoor(
2279
+ DOORS.entityFields,
2280
+ { p_organization_id: org, p_token: token },
2281
+ "entityFields"
2282
+ );
2283
+ if (!rows.ok) return err(rows.error);
2284
+ return ok((rows.data ?? []).map((row) => ({ id: row.id, ...row.data })));
2285
+ },
2286
+ async entityFieldDeclare({ token, spec }) {
2287
+ return callDoor(
2288
+ DOORS.entityFieldDeclare,
2289
+ { p_organization_id: org, p_token: token, p_spec: spec },
2290
+ "entityFieldDeclare"
2291
+ );
2292
+ },
2293
+ async entityFieldUpdate({ field_id, patch }) {
2294
+ return callDoor(
2295
+ DOORS.entityFieldUpdate,
2296
+ { p_organization_id: org, p_field_id: field_id, p_patch: patch },
2297
+ "entityFieldUpdate"
2298
+ );
2299
+ },
2300
+ async entityFieldRetire({ field_id }) {
2301
+ return callDoor(
2302
+ DOORS.entityFieldRetire,
2303
+ { p_organization_id: org, p_field_id: field_id },
2304
+ "entityFieldRetire"
2305
+ );
2306
+ },
2307
+ async entityFieldRights({ token }) {
2308
+ return callDoor(
2309
+ DOORS.entityFieldRights,
2310
+ { p_organization_id: org, p_token: token },
2311
+ "entityFieldRights"
2312
+ );
2313
+ },
2314
+ async entityRecordRead({ token, record_id }) {
2315
+ return callDoor(
2316
+ DOORS.entityRecordRead,
2317
+ { p_organization_id: org, p_token: token, p_record_id: record_id },
2318
+ "entityRecordRead"
2319
+ );
2320
+ },
2321
+ async entityValueWrite({ token, record_id, patch }) {
2322
+ return callDoor(
2323
+ DOORS.entityValueWrite,
2324
+ { p_organization_id: org, p_token: token, p_record_id: record_id, p_patch: patch },
2325
+ "entityValueWrite"
2326
+ );
2327
+ },
2328
+ async entityRecordsFind({ token, key, value, limit, offset }) {
2329
+ return callDoor(
2330
+ DOORS.entityRecordsFind,
2331
+ {
2332
+ p_organization_id: org,
2333
+ p_token: token,
2334
+ p_key: key,
2335
+ p_value: value === void 0 ? null : value,
2336
+ ...limit === void 0 ? {} : { p_limit: limit },
2337
+ ...offset === void 0 ? {} : { p_offset: offset }
2338
+ },
2339
+ "entityRecordsFind"
2340
+ );
2341
+ },
2132
2342
  async fieldUpdate({ field_id, patch }) {
2133
2343
  return callDoor(
2134
2344
  DOORS.fieldUpdate,
@@ -2198,6 +2408,65 @@ function createRecordsClient(config) {
2198
2408
  "formDeclare"
2199
2409
  );
2200
2410
  },
2411
+ async portals() {
2412
+ return callDoor(DOORS.portals, { p_organization_id: org }, "portals");
2413
+ },
2414
+ async portalCard({ portal_id }) {
2415
+ return callDoor(
2416
+ DOORS.portalCard,
2417
+ { p_organization_id: org, p_portal_id: portal_id },
2418
+ "portalCard"
2419
+ );
2420
+ },
2421
+ async portalDeclare(args) {
2422
+ return callDoor(
2423
+ DOORS.portalDeclare,
2424
+ {
2425
+ p_organization_id: org,
2426
+ p_title: args.title,
2427
+ p_client_table_id: args.client_table_id,
2428
+ p_tables: args.tables,
2429
+ p_portal_id: args.portal_id ?? null,
2430
+ p_slug: args.slug ?? null,
2431
+ p_sign_in_method: args.sign_in_method ?? "magic_link"
2432
+ },
2433
+ "portalDeclare"
2434
+ );
2435
+ },
2436
+ async portalInvite(args) {
2437
+ return callDoor(
2438
+ DOORS.portalInvite,
2439
+ {
2440
+ p_organization_id: org,
2441
+ p_portal_id: args.portal_id,
2442
+ p_client_record_id: args.client_record_id,
2443
+ p_email: args.email,
2444
+ // ALWAYS null from a client. See the interface comment: an invitation
2445
+ // confers nothing until the person follows their own sign-in link.
2446
+ p_user_id: null
2447
+ },
2448
+ "portalInvite"
2449
+ );
2450
+ },
2451
+ async portalRevoke({ portal_id, principal_id }) {
2452
+ return callDoor(
2453
+ DOORS.portalRevoke,
2454
+ { p_organization_id: org, p_portal_id: portal_id, p_principal_id: principal_id },
2455
+ "portalRevoke"
2456
+ );
2457
+ },
2458
+ async portalPreview({ portal_id, principal_id, table_id }) {
2459
+ return callDoor(
2460
+ DOORS.portalPreview,
2461
+ {
2462
+ p_organization_id: org,
2463
+ p_portal_id: portal_id,
2464
+ p_principal_id: principal_id,
2465
+ p_table_id: table_id
2466
+ },
2467
+ "portalPreview"
2468
+ );
2469
+ },
2201
2470
  async ruleRun({ rule_id, values, context }) {
2202
2471
  return callDoor(
2203
2472
  DOORS.ruleRun,
@@ -2222,6 +2491,55 @@ function createRecordsClient(config) {
2222
2491
  "ruleEval"
2223
2492
  );
2224
2493
  },
2494
+ async dashboards(args) {
2495
+ return callDoor(
2496
+ DOORS.dashboards,
2497
+ { p_organization_id: org, p_table_id: args?.table_id ?? null },
2498
+ "dashboards"
2499
+ );
2500
+ },
2501
+ async dashboardDeclare(args) {
2502
+ return callDoor(
2503
+ DOORS.dashboardDeclare,
2504
+ {
2505
+ p_organization_id: org,
2506
+ p_table_id: args.table_id,
2507
+ p_name: args.name,
2508
+ p_blocks: args.blocks ?? [],
2509
+ p_presentation: args.presentation ?? {},
2510
+ p_dashboard_id: args.dashboard_id ?? null
2511
+ },
2512
+ "dashboardDeclare"
2513
+ );
2514
+ },
2515
+ async dashboardRun({ dashboard_id, filter }) {
2516
+ return callDoor(
2517
+ DOORS.dashboardRun,
2518
+ { p_organization_id: org, p_dashboard_id: dashboard_id, p_filter: filter ?? {} },
2519
+ "dashboardRun"
2520
+ );
2521
+ },
2522
+ async dashboardStuck({ table_id, state_key, days, filter, limit }) {
2523
+ return callDoor(
2524
+ DOORS.dashboardStuck,
2525
+ {
2526
+ p_organization_id: org,
2527
+ p_table_id: table_id,
2528
+ p_state_key: state_key,
2529
+ p_days: days ?? 14,
2530
+ p_filter: filter ?? {},
2531
+ p_limit: limit ?? 50
2532
+ },
2533
+ "dashboardStuck"
2534
+ );
2535
+ },
2536
+ async dashboardDelete({ dashboard_id }) {
2537
+ return callDoor(
2538
+ DOORS.dashboardDelete,
2539
+ { p_organization_id: org, p_dashboard_id: dashboard_id },
2540
+ "dashboardDelete"
2541
+ );
2542
+ },
2225
2543
  async recordAggregate({ table_id, groupBy, measures, bucket, filter, limit }) {
2226
2544
  return callDoor(
2227
2545
  DOORS.recordAggregate,
@@ -2257,6 +2575,20 @@ function createRecordsClient(config) {
2257
2575
  async aggSubscriptionCadences() {
2258
2576
  return callDoor(DOORS.aggSubscriptionCadences, {}, "aggSubscriptionCadences");
2259
2577
  },
2578
+ async subscriptions(args) {
2579
+ return callDoor(
2580
+ DOORS.subscriptions,
2581
+ { p_organization_id: org, p_table_id: args?.table_id ?? null },
2582
+ "subscriptions"
2583
+ );
2584
+ },
2585
+ async subscriptionMute({ rule_id, muted }) {
2586
+ return callDoor(
2587
+ DOORS.subscriptionMute,
2588
+ { p_organization_id: org, p_rule_id: rule_id, p_muted: muted },
2589
+ "subscriptionMute"
2590
+ );
2591
+ },
2260
2592
  async docTemplateSave({ table_id, name, body, template_id }) {
2261
2593
  return callDoor(
2262
2594
  DOORS.docTemplateSave,
@@ -2546,6 +2878,128 @@ function createRecordsClient(config) {
2546
2878
  "workSlotExpire"
2547
2879
  );
2548
2880
  },
2881
+ // ── the work layer a person actually uses ────────────────────────────
2882
+ async workInbox(args) {
2883
+ return callDoor(
2884
+ DOORS.workInbox,
2885
+ {
2886
+ p_organization_id: org,
2887
+ p_limit: args?.limit ?? 50,
2888
+ p_offset: args?.offset ?? 0,
2889
+ p_include_decided: args?.includeDecided ?? false
2890
+ },
2891
+ "workInbox"
2892
+ );
2893
+ },
2894
+ async workList(args) {
2895
+ return callDoor(
2896
+ DOORS.workList,
2897
+ {
2898
+ p_organization_id: org,
2899
+ p_flavour: args?.flavour ?? "mine",
2900
+ p_include_finished: args?.includeFinished ?? false,
2901
+ p_limit: args?.limit ?? 100,
2902
+ p_offset: args?.offset ?? 0
2903
+ },
2904
+ "workList"
2905
+ );
2906
+ },
2907
+ async workAssign({ record_id, user_id = null, dueDate = null, clearDue = false }) {
2908
+ return callDoor(
2909
+ DOORS.workAssign,
2910
+ {
2911
+ p_organization_id: org,
2912
+ p_record_id: record_id,
2913
+ p_assignee_user_id: user_id,
2914
+ p_due_date: dueDate,
2915
+ p_clear_due: clearDue
2916
+ },
2917
+ "workAssign"
2918
+ );
2919
+ },
2920
+ async workRecordStates({ record_id }) {
2921
+ return callDoor(
2922
+ DOORS.workRecordStates,
2923
+ { p_organization_id: org, p_record_id: record_id },
2924
+ "workRecordStates"
2925
+ );
2926
+ },
2927
+ async workSetState({ record_id, state_id }) {
2928
+ return callDoor(
2929
+ DOORS.workSetState,
2930
+ { p_organization_id: org, p_record_id: record_id, p_state_id: state_id },
2931
+ "workSetState"
2932
+ );
2933
+ },
2934
+ async workPerson({ user_id, create = true }) {
2935
+ return callDoor(
2936
+ DOORS.workPerson,
2937
+ { p_organization_id: org, p_user_id: user_id, p_create: create },
2938
+ "workPerson"
2939
+ );
2940
+ },
2941
+ async workTemplates(args) {
2942
+ return callDoor(
2943
+ DOORS.workTemplates,
2944
+ { p_organization_id: org, p_limit: args?.limit ?? 100 },
2945
+ "workTemplates"
2946
+ );
2947
+ },
2948
+ async workApprovalApprovers({ subject_id, approver_id = null }) {
2949
+ return callDoor(
2950
+ DOORS.workApprovalApprovers,
2951
+ { p_organization_id: org, p_subject_id: subject_id, p_approver_id: approver_id },
2952
+ "workApprovalApprovers"
2953
+ );
2954
+ },
2955
+ async workApprovalRequest({
2956
+ subject_id,
2957
+ change,
2958
+ note = null,
2959
+ approver_id = null,
2960
+ origin = "person",
2961
+ conversation_id = null
2962
+ }) {
2963
+ return callDoor(
2964
+ DOORS.workApprovalRequest,
2965
+ {
2966
+ p_organization_id: org,
2967
+ p_subject_id: subject_id,
2968
+ p_change: change,
2969
+ p_note: note,
2970
+ p_approver_id: approver_id,
2971
+ p_origin: origin,
2972
+ p_conversation_id: conversation_id
2973
+ },
2974
+ "workApprovalRequest"
2975
+ );
2976
+ },
2977
+ async workApprovalMayDecide({ approval_id }) {
2978
+ return callDoor(
2979
+ DOORS.workApprovalMayDecide,
2980
+ { p_organization_id: org, p_approval_id: approval_id },
2981
+ "workApprovalMayDecide"
2982
+ );
2983
+ },
2984
+ async workApprovalDecide({ approval_id, approve, note = null }) {
2985
+ return callDoor(
2986
+ DOORS.workApprovalDecide,
2987
+ {
2988
+ p_organization_id: org,
2989
+ p_approval_id: approval_id,
2990
+ p_approve: approve,
2991
+ p_note: note
2992
+ },
2993
+ "workApprovalDecide"
2994
+ );
2995
+ },
2996
+ async workApprovalRead({ approval_id }) {
2997
+ return callDoor(
2998
+ DOORS.workApprovalRead,
2999
+ { p_organization_id: org, p_approval_id: approval_id },
3000
+ "workApprovalRead"
3001
+ );
3002
+ },
2549
3003
  // ── the trust doors ──────────────────────────────────────────────────
2550
3004
  async isExternalPrincipal(args) {
2551
3005
  return trustDoor(
@@ -2872,6 +3326,72 @@ function useRecordMutation() {
2872
3326
  [client, run, saving, error, conflict]
2873
3327
  );
2874
3328
  }
3329
+ function useEntityFields(token) {
3330
+ return useAsync(
3331
+ (client) => token ? client.entityFields({ token }) : Promise.resolve({ ok: true, data: [] }),
3332
+ [token]
3333
+ );
3334
+ }
3335
+ function useEntityRecord(token, recordId) {
3336
+ return useAsync(
3337
+ (client) => token && recordId ? client.entityRecordRead({ token, record_id: recordId }) : Promise.resolve({ ok: true, data: null }),
3338
+ [token, recordId]
3339
+ );
3340
+ }
3341
+ function useEntityTable(token) {
3342
+ return useAsync(
3343
+ (client) => token ? client.entityTable({ token }) : Promise.resolve({ ok: true, data: null }),
3344
+ [token]
3345
+ );
3346
+ }
3347
+ function useEntityFieldRights(token) {
3348
+ return useAsync(
3349
+ (client) => token ? client.entityFieldRights({ token }) : Promise.resolve({ ok: true, data: null }),
3350
+ [token]
3351
+ );
3352
+ }
3353
+ function useEntityFieldMutation() {
3354
+ const client = useRecordsClient();
3355
+ const [saving, setSaving] = useState(false);
3356
+ const [error, setError] = useState(null);
3357
+ const run = useCallback(
3358
+ async (call, whenRefused) => {
3359
+ setSaving(true);
3360
+ setError(null);
3361
+ try {
3362
+ const result = await call();
3363
+ if (result.ok) return result.data;
3364
+ setError(result.error);
3365
+ return whenRefused;
3366
+ } finally {
3367
+ setSaving(false);
3368
+ }
3369
+ },
3370
+ []
3371
+ );
3372
+ return useMemo2(
3373
+ () => ({
3374
+ declare: (args) => run(() => client.entityFieldDeclare({ token: args.token, spec: args.spec }), null),
3375
+ update: (args) => run(
3376
+ () => client.entityFieldUpdate({ field_id: args.field_id, patch: args.patch }),
3377
+ null
3378
+ ),
3379
+ retire: (args) => run(() => client.entityFieldRetire({ field_id: args.field_id }), null),
3380
+ write: (args) => run(
3381
+ () => client.entityValueWrite({
3382
+ token: args.token,
3383
+ record_id: args.record_id,
3384
+ patch: args.patch
3385
+ }),
3386
+ null
3387
+ ),
3388
+ saving,
3389
+ error,
3390
+ clearError: () => setError(null)
3391
+ }),
3392
+ [client, run, saving, error]
3393
+ );
3394
+ }
2875
3395
  function useFieldMutation() {
2876
3396
  const client = useRecordsClient();
2877
3397
  const [saving, setSaving] = useState(false);
@@ -3000,11 +3520,59 @@ var OVERRIDE_POLICIES = [
3000
3520
  var FRESHNESS = ["live", "cached", "snapshot"];
3001
3521
  var TABLE_DISPLAYS = ["list", "grid", "board", "calendar", "timeline"];
3002
3522
 
3523
+ // src/choice.ts
3524
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3525
+ function optionKey(option) {
3526
+ const stored = option.metadata?.["option_key"];
3527
+ if (typeof stored === "string" && stored.trim() !== "") return stored;
3528
+ return choiceSlug(optionLabel(option));
3529
+ }
3530
+ function optionLabel(option) {
3531
+ const doc = option.data;
3532
+ const title = doc?.["title"] ?? doc?.["name"];
3533
+ if (typeof title === "string" && title.trim() !== "") return title;
3534
+ return "Unnamed choice";
3535
+ }
3536
+ function choiceSlug(word) {
3537
+ const slug = word.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 55);
3538
+ return slug === "" ? "choice" : slug;
3539
+ }
3540
+ function isTheChosen(option, value) {
3541
+ if (typeof value !== "string") return false;
3542
+ const asked = value.trim().toLowerCase();
3543
+ if (asked === "") return false;
3544
+ return asked === optionKey(option).toLowerCase() || asked === optionLabel(option).toLowerCase() || asked === option.id.toLowerCase();
3545
+ }
3546
+ function choiceValuesOf(value) {
3547
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
3548
+ if (typeof value === "string" && value !== "") return [value];
3549
+ return [];
3550
+ }
3551
+ function choicesOf(document, fieldKeyOrId) {
3552
+ const block = document?.["_choices"];
3553
+ if (!block || typeof block !== "object") return [];
3554
+ const entry = block[fieldKeyOrId];
3555
+ if (!entry) return [];
3556
+ const list = Array.isArray(entry) ? entry : [entry];
3557
+ return list.filter((x) => !!x && typeof x === "object" && typeof x.key === "string");
3558
+ }
3559
+ function holdsARetiredChoice(document, fieldKeyOrId) {
3560
+ return choicesOf(document, fieldKeyOrId).some((c) => c.retired === true);
3561
+ }
3562
+ function looksLikeAnId(value) {
3563
+ return typeof value === "string" && UUID.test(value);
3564
+ }
3565
+
3003
3566
  // src/rule.ts
3004
3567
  function publicFormPath(formId) {
3005
3568
  return `/f/${formId}`;
3006
3569
  }
3007
3570
 
3571
+ // src/portal.ts
3572
+ function portalPath(slug) {
3573
+ return `/portal/c/${slug}`;
3574
+ }
3575
+
3008
3576
  // src/aggregate.ts
3009
3577
  function measureKey(measure) {
3010
3578
  return measure.op === "count" ? "count" : `${measure.op}_${measure.key ?? ""}`;
@@ -3046,12 +3614,26 @@ export {
3046
3614
  VALUE_ENVELOPE_KEYS,
3047
3615
  asPermissionLevel,
3048
3616
  atLeast,
3617
+ choiceSlug,
3618
+ choiceValuesOf,
3619
+ choicesOf,
3049
3620
  err,
3050
3621
  highestLevel,
3622
+ holdsARetiredChoice,
3051
3623
  isRecordsErr,
3624
+ isTheChosen,
3625
+ looksLikeAnId,
3052
3626
  measureKey,
3053
3627
  ok,
3628
+ optionKey,
3629
+ optionLabel,
3630
+ portalPath,
3054
3631
  publicFormPath,
3632
+ useEntityFieldMutation,
3633
+ useEntityFieldRights,
3634
+ useEntityFields,
3635
+ useEntityRecord,
3636
+ useEntityTable,
3055
3637
  useFieldMutation,
3056
3638
  useFields,
3057
3639
  useMergeField,