@ai-matrx/records 0.51.0 → 0.53.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.
@@ -452,6 +452,7 @@ var STORE_DOORS = [
452
452
  { name: "io_export", args: "p_organization_id uuid, p_table_id uuid, p_columns text[] DEFAULT NULL::text[], p_limit integer DEFAULT 10000, p_required text DEFAULT 'viewer'::text", returns: "jsonb", security: "definer" },
453
453
  { name: "io_export_csv", args: "p_organization_id uuid, p_table_id uuid, p_columns text[] DEFAULT NULL::text[], p_limit integer DEFAULT 10000, p_delimiter text DEFAULT chr(44), p_required text DEFAULT 'viewer'::text", returns: "text", security: "definer" },
454
454
  { name: "io_import_begin", args: "p_organization_id uuid, p_table_id uuid, p_format text DEFAULT 'csv'::text, p_source_name text DEFAULT NULL::text, p_source_columns jsonb DEFAULT '[]'::jsonb, p_file_hash text DEFAULT NULL::text, p_policy jsonb DEFAULT '{}'::jsonb, p_dedupe_key text DEFAULT NULL::text, p_file_bytes bigint DEFAULT NULL::bigint, p_force boolean DEFAULT false", returns: "jsonb", security: "definer" },
455
+ { name: "io_import_declare_columns", args: "p_organization_id uuid, p_table_id uuid, p_rows jsonb, p_mapping jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
455
456
  { name: "io_import_finish", args: "p_organization_id uuid, p_import_id uuid, p_unmapped text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
456
457
  { name: "io_import_forget", args: "p_organization_id uuid, p_import_id uuid", returns: "boolean", security: "definer" },
457
458
  { name: "io_import_open", args: "p_organization_id uuid, p_table_id uuid, p_format text DEFAULT 'csv'::text, p_source_name text DEFAULT NULL::text, p_source_columns jsonb DEFAULT '[]'::jsonb", returns: "uuid", security: "definer" },
@@ -485,6 +486,7 @@ var STORE_DOORS = [
485
486
  { name: "levels_raised_by_a_less_specific_rung", args: "", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, member_email text, record_id uuid, addressed_level permission_level, answered_level permission_level)", security: "definer" },
486
487
  { 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" },
487
488
  { 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" },
489
+ { name: "list_portals", args: "p_organization_id uuid, p_archived text DEFAULT 'active'::text", 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" },
488
490
  { name: "lookup_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb", returns: "jsonb", security: "invoker" },
489
491
  { 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" },
490
492
  { 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" },
@@ -534,6 +536,7 @@ var STORE_DOORS = [
534
536
  { name: "pipeline_read", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
535
537
  { name: "pipeline_transition_refusal", args: "p_organization_id uuid, p_record_id uuid, p_to text", returns: "jsonb", security: "definer" },
536
538
  { name: "portal_admits", args: "p_organization_id uuid, p_user_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "definer" },
539
+ { name: "portal_archive", args: "p_organization_id uuid, p_portal_id uuid, p_confirm_title text, p_reason text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
537
540
  { name: "portal_card", args: "p_organization_id uuid, p_portal_id uuid", returns: "jsonb", security: "definer" },
538
541
  { 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" },
539
542
  { 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" },
@@ -545,6 +548,7 @@ var STORE_DOORS = [
545
548
  { name: "portal_principal_bind", args: "p_organization_id uuid, p_principal_id uuid, p_user_id uuid", returns: "jsonb", security: "definer" },
546
549
  { name: "portal_public", args: "p_slug text", returns: "jsonb", security: "definer" },
547
550
  { name: "portal_record_title", args: "p_organization_id uuid, p_record_id uuid", returns: "text", security: "definer" },
551
+ { name: "portal_restore", args: "p_organization_id uuid, p_portal_id uuid, p_confirm_title text", returns: "jsonb", security: "definer" },
548
552
  { name: "portal_revoke", args: "p_organization_id uuid, p_portal_id uuid, p_principal_id uuid", returns: "jsonb", security: "definer" },
549
553
  { name: "portal_slug", args: "p_organization_id uuid, p_title text, p_portal_id uuid DEFAULT NULL::uuid", returns: "text", security: "definer" },
550
554
  { name: "portal_tables", args: "p_organization_id uuid", returns: "TABLE(portal_id uuid, table_id uuid, name text)", security: "definer" },
@@ -687,6 +691,7 @@ var STORE_DOORS = [
687
691
  { 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" },
688
692
  { name: "storage_modes", args: "", returns: "text[]", security: "invoker" },
689
693
  { name: "store_is_open", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "invoker" },
694
+ { name: "store_off_sentence", args: "p_organization_id uuid", returns: "text", security: "invoker" },
690
695
  { name: "subscription_cadences", args: "p_organization_id uuid", returns: "text[]", security: "definer" },
691
696
  { name: "subscription_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
692
697
  { name: "subscription_mute", args: "p_organization_id uuid, p_rule_id uuid, p_muted boolean DEFAULT true", returns: "boolean", security: "definer" },
@@ -825,16 +830,16 @@ var STORE_KNOBS = [
825
830
  { key: "world_publish_enabled", value: "false", type: "boolean" }
826
831
  ];
827
832
  var STORE_REFUSAL_CODES = [
828
- { code: "02000", raised_by: "_checklist_instantiate,_portal_invite_payload,_share_write_person,_table_share_invite_payload,checklist_declare,checklist_run,checklist_step_complete,checklist_step_refusal,checklist_template_shape,conversation_scope_bind,dashboard_delete,dashboard_run,doc_letterhead,doc_render_body,doc_render_document,doc_render_read,doc_sign,doc_signature_intact,doc_signature_read,doc_template_delete,doc_template_read,doc_template_save,enrich_pin,entity_field_retire,entity_field_update,entity_record_read,entity_value_write,external_history_event,external_rows,external_stub_upsert,external_writes_set,io_restore,migrate_delete,migrate_extract_parent,migrate_merge,migrate_reclass,migrate_rename,migrate_reparent,migrate_retype,migrate_split,migrate_undo,organization_clear,portal_card,portal_declare,portal_invite,portal_invite_accept,portal_preview,portal_principal_bind,portal_revoke,read_record,record_delete,record_restore,record_restore_preview,record_table,record_update,relation_uncarry,share_access,share_grant,share_lane_set,share_people,share_revoke,sign_request_cancel,sign_request_create,sign_request_remind,sign_request_unchanged,table_archive,table_share_outside_accept,table_share_outside_invite,table_share_outside_resend,table_share_outside_revoke,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_assign,work_record_states,work_set_state" },
833
+ { code: "02000", raised_by: "_checklist_instantiate,_portal_invite_payload,_share_write_person,_table_share_invite_payload,checklist_declare,checklist_run,checklist_step_complete,checklist_step_refusal,checklist_template_shape,conversation_scope_bind,dashboard_delete,dashboard_run,doc_letterhead,doc_render_body,doc_render_document,doc_render_read,doc_sign,doc_signature_intact,doc_signature_read,doc_template_delete,doc_template_read,doc_template_save,enrich_pin,entity_field_retire,entity_field_update,entity_record_read,entity_value_write,external_history_event,external_rows,external_stub_upsert,external_writes_set,io_restore,migrate_delete,migrate_extract_parent,migrate_merge,migrate_reclass,migrate_rename,migrate_reparent,migrate_retype,migrate_split,migrate_undo,organization_clear,portal_archive,portal_card,portal_declare,portal_invite,portal_invite_accept,portal_preview,portal_principal_bind,portal_restore,portal_revoke,read_record,record_delete,record_restore,record_restore_preview,record_table,record_update,relation_uncarry,share_access,share_grant,share_lane_set,share_people,share_revoke,sign_request_cancel,sign_request_create,sign_request_remind,sign_request_unchanged,table_archive,table_share_outside_accept,table_share_outside_invite,table_share_outside_resend,table_share_outside_revoke,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_assign,work_record_states,work_set_state" },
829
834
  { code: "0A000", raised_by: "checklist_step_complete,external_rows,external_source_declare,external_write_through,promote_field,promoted_index_expr,promoted_query_sql,promoted_read,rule_eval,work_assign" },
830
835
  { code: "22003", raised_by: "context_resolve" },
831
836
  { code: "22004", raised_by: "_entity_custom_fields_guard,_share_write_person,_value_envelope,actor_word,agg_assert_key,agg_sql,anon_capture,anon_token_issue,anon_write,assert_client_may_reach,booking_declare,capture_submit,checklist_declare,context_resolve,dashboard_block_normalize,dashboard_declare,dashboard_window_sql,doc_render_write,doc_sign,doc_signature_write,doc_template_save,enrich_land,enrich_normalize,external_history_event,external_rows,external_source_declare,external_stub_upsert,external_write_through,external_writes_set,field_history,form_declare,form_submit,home_add,io_comment_write,io_import_begin,io_infer_column,io_outbox_drain,io_restore,migrate_choice_keys,migrate_purge,migrate_reclass,migrate_split,migrate_undo,organization_clear,organization_contents,pipeline_declare,pipeline_gate_preview,portal_declare,portal_invite,portal_principal_bind,provenance_retention_days,provenance_write,query_across_homes,query_by_coordinates,query_rollup,record_delete,record_reparent,record_resolve,record_restore,record_update,record_write,record_write_many,relation_carry,relation_own,rule_declare,share_grant,sign_request_create,sign_request_sign,subscription_declare,table_archive,table_declare,table_share_outside_invite,value_restore,view_declare,work_approval_decide,work_approval_request,work_template_declare" },
832
837
  { code: "22007", raised_by: "dashboard_window_sql" },
833
838
  { code: "22012", raised_by: "rule_eval" },
834
- { code: "22023", raised_by: "_booking_availability,_entity_custom_fields_guard,_take_op_id,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,booking_declare,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,enrich_declare,enrich_land,enrich_normalize,enrich_pin,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,field_update,io_export,io_import_begin,io_import_finish,io_import_plan,io_import_report,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,page_size,pin_agent_cells,pipeline_move,portal_declare,provenance_write,query_by_coordinates,query_rollup,read_records_archived,record_update,record_write_many,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,sign_request_create,sign_request_sign,subscription_declare,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
839
+ { code: "22023", raised_by: "_booking_availability,_entity_custom_fields_guard,_take_op_id,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,booking_declare,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,enrich_declare,enrich_land,enrich_normalize,enrich_pin,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,field_update,io_export,io_import_begin,io_import_finish,io_import_plan,io_import_report,io_proposal_accept,list_portals,migrate_merge,migrate_reclass,my_levels,organization_clear,page_size,pin_agent_cells,pipeline_move,portal_declare,provenance_write,query_by_coordinates,query_rollup,read_records_archived,record_update,record_write_many,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,sign_request_create,sign_request_sign,subscription_declare,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
835
840
  { code: "23503", raised_by: "_booking_availability,_checklist_instantiate,_containment_guard,_display_spec_for,_field_document_for,_field_type_parity_guard,_pipeline_stage_key,_record_rule_uses,agg_digest_assemble,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,booking_cancel,booking_confirm,booking_declare,booking_hold,booking_reschedule,capture_publish,checklist_declare,checklist_steps_table,comment_write,dashboard_declare,delete_rule,doc_sign,doc_template_save,enrich_declare,enrich_due,enrich_land,form_declare,form_submit,home_add,inbound_declare,inbound_mail_land,inbound_set,io_comment_write,io_import_begin,io_import_finish,io_import_report,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,pipeline_board,pipeline_declare,pipeline_move,pipeline_read,pipeline_transition_refusal,promote_field,promote_table,record_applicability,record_reparent,relation_carry,relation_own,resolve_first_match,rule_applies,rule_declare,rule_eval,rule_members,rule_run,sign_request_create,subscription_mute,subscription_preview,view_declare,work_set_state,work_take_assignment,work_template_instantiate" },
836
841
  { code: "23505", raised_by: "_share_write_person,_unique_rule_holds,doc_sign,doc_signature_write,entity_field_declare,field_declare,home_add,inbound_declare,io_proposal_accept,relation_carry,relation_own,sign_request_cancel,sign_request_create,table_share_outside_resend,work_approval_decide,work_slot_hold" },
837
- { code: "23514", raised_by: "_checklist_instantiate,_checklist_step_guard,_containment_guard,_dated_values_guard,_derived_fields,_display_spec_for,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_columns_word_guard,_table_shape_guard,_undeclared_key_guard,_value_envelope,_with_display,_work_shape_guard,_workdoors_approval_guard,assert_columns_are_defined,assert_entity_is_organization_scoped,booking_declare,capture_publish,capture_sheet_declare,checklist_declare,checklist_step_complete,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,io_comment_write,io_import_rows,migrate_merge,relation_carry,relation_own,sign_request_create,sign_request_sign,table_declare,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
842
+ { code: "23514", raised_by: "_checklist_instantiate,_checklist_step_guard,_containment_guard,_dated_values_guard,_derived_fields,_display_spec_for,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_columns_word_guard,_table_shape_guard,_undeclared_key_guard,_value_envelope,_with_display,_work_shape_guard,_workdoors_approval_guard,assert_columns_are_defined,assert_entity_is_organization_scoped,booking_declare,capture_publish,capture_sheet_declare,checklist_declare,checklist_step_complete,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,io_comment_write,io_import_rows,migrate_merge,portal_archive,portal_restore,relation_carry,relation_own,sign_request_create,sign_request_sign,table_declare,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
838
843
  { code: "40001", raised_by: "has_visibility_at" },
839
844
  { code: "42501", raised_by: "_doc_render_immutable,_doc_signature_immutable,_field_definition_write,_field_write_door,_rule_definition_write,_store_door,agent_table_claim,anon_capture,anon_inbound_land,anon_publish,anon_token_issue,anon_token_verify,anon_write,assert_client_may_change,assert_client_may_open,assert_client_may_reach,assert_may_know_table,assert_organization_admin,assert_store_door,booking_confirm,booking_declare,booking_hold,capture_submit,checklist_run,comment_write,conversation_scope_bind,conversation_scope_unbind,doc_sign,enrich_declare,enrich_due,enrich_land,enrich_normalize,entity_field_declare,entity_field_retire,entity_field_update,entity_value_write,external_write_through,form_declare,form_submit,inbound_mail_land,io_comment_resolve,io_comment_write,io_import_begin,io_import_finish,io_restore,migrate_purge,migrate_reclass,my_levels,organization_clear,portal_declare,portal_invitation,portal_invite,portal_invite_accept,portal_principal_bind,promote_table,query_visibility_parity,read_record,read_records,read_records_archived,read_records_by_ids,read_records_matching,record_table,share_grant,subscription_mute,subscription_preview,table_share_outside_accept,table_share_outside_invite,table_share_outside_resend,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_person" },
840
845
  { code: "42703", raised_by: "entity_table,portal_declare" },
@@ -1964,6 +1969,19 @@ var DOORS = {
1964
1969
  fieldOptions: "field_options",
1965
1970
  parityValues: "parity_values",
1966
1971
  tableDeclare: "table_declare",
1972
+ // GETTING RID OF A TABLE — which is a JOB, NOT A STATEMENT (VERIFIER-11 F3).
1973
+ // `record_delete` above is the store's one soft-delete door and it is right
1974
+ // for a record; aimed at a TABLE it recurses through everything the Table
1975
+ // contains inside one transaction, and that is unbounded by construction. A
1976
+ // person pressing "Delete this table" on 1,430 records the product itself
1977
+ // had just imported waited twelve seconds and was told `57014`, "canceling
1978
+ // statement due to statement timeout … Nothing was changed. Try a smaller
1979
+ // page" — advice that means nothing when what you are doing is getting rid
1980
+ // of a table. `custom.table_archive` does the same work in passes and
1981
+ // answers each one with numbers, so a screen shows a sentence and a count
1982
+ // instead of a spinner and an SQLSTATE. It is STATELESS, so a run cut in
1983
+ // half resumes exactly where it stopped: there is no job row to lose.
1984
+ tableArchive: "table_archive",
1967
1985
  // ADDING A COLUMN — the first thing anybody does with a table, and until
1968
1986
  // 2026-09-19 there was no door for it. A Field is a record (REC-25), so a
1969
1987
  // screen wrote one with `record_write`; that door writes ONE row with
@@ -2091,6 +2109,7 @@ var DOORS = {
2091
2109
  // ways to start an import from one client is how they drift.
2092
2110
  importPlan: "io_import_plan",
2093
2111
  importBegin: "io_import_begin",
2112
+ importDeclareColumns: "io_import_declare_columns",
2094
2113
  importRows: "io_import_rows",
2095
2114
  importFinish: "io_import_finish",
2096
2115
  importReport: "io_import_report",
@@ -2127,6 +2146,17 @@ var DOORS = {
2127
2146
  portalInvite: "portal_invite",
2128
2147
  portalRevoke: "portal_revoke",
2129
2148
  portalPreview: "portal_preview",
2149
+ // ORG-CLEANUP, 2026-09-22 — A PORTAL IS ARCHIVED, NEVER DELETED.
2150
+ // `portals` keeps its signature and HIDES archived portals (the law's default
2151
+ // is to hide); `list_portals(org, 'active'|'archived'|'all')` is the
2152
+ // archive-aware reader, taking the platform archive filter's own three values
2153
+ // so one door serves both lanes and no screen has to invent a second control.
2154
+ // `portal_archive` / `portal_restore` are the way out and the way back; both
2155
+ // take the portal's own title typed back, because ten portals can carry one
2156
+ // title and the title alone is not what picks this one.
2157
+ listPortals: "list_portals",
2158
+ portalArchive: "portal_archive",
2159
+ portalRestore: "portal_restore",
2130
2160
  // SCR-16 — the canvas. A dashboard is a record in the presentation kernel
2131
2161
  // whose blocks are saved SPECS for the eighth verb; `dashboardRun` walks them
2132
2162
  // under the CALLER'S principal, so nothing here is precomputed and nothing is
@@ -2607,6 +2637,18 @@ function createRecordsClient(config) {
2607
2637
  "recordRestore"
2608
2638
  );
2609
2639
  },
2640
+ async tableArchive({ table_id, chunk, includeTable }) {
2641
+ return callDoor(
2642
+ DOORS.tableArchive,
2643
+ {
2644
+ p_organization_id: org,
2645
+ p_table_id: table_id,
2646
+ p_chunk: chunk ?? 50,
2647
+ p_include_table: includeTable ?? true
2648
+ },
2649
+ "tableArchive"
2650
+ );
2651
+ },
2610
2652
  async recordRead({ record_id, withComputed = false }) {
2611
2653
  const door = await callDoor(
2612
2654
  DOORS.readRecord,
@@ -3160,6 +3202,18 @@ function createRecordsClient(config) {
3160
3202
  "importBegin"
3161
3203
  );
3162
3204
  },
3205
+ async importDeclareColumns(args) {
3206
+ return callDoor(
3207
+ DOORS.importDeclareColumns,
3208
+ {
3209
+ p_organization_id: org,
3210
+ p_table_id: args.table_id,
3211
+ p_rows: args.rows,
3212
+ p_mapping: args.mapping ?? {}
3213
+ },
3214
+ "importDeclareColumns"
3215
+ );
3216
+ },
3163
3217
  async importRows(args) {
3164
3218
  return callDoor(
3165
3219
  DOORS.importRows,
@@ -3230,6 +3284,36 @@ function createRecordsClient(config) {
3230
3284
  async portals() {
3231
3285
  return callDoor(DOORS.portals, { p_organization_id: org }, "portals");
3232
3286
  },
3287
+ async listPortals(args) {
3288
+ return callDoor(
3289
+ DOORS.listPortals,
3290
+ { p_organization_id: org, p_archived: args?.archived ?? "active" },
3291
+ "listPortals"
3292
+ );
3293
+ },
3294
+ async portalArchive(args) {
3295
+ return callDoor(
3296
+ DOORS.portalArchive,
3297
+ {
3298
+ p_organization_id: org,
3299
+ p_portal_id: args.portal_id,
3300
+ p_confirm_title: args.confirm_title,
3301
+ p_reason: args.reason ?? null
3302
+ },
3303
+ "portalArchive"
3304
+ );
3305
+ },
3306
+ async portalRestore(args) {
3307
+ return callDoor(
3308
+ DOORS.portalRestore,
3309
+ {
3310
+ p_organization_id: org,
3311
+ p_portal_id: args.portal_id,
3312
+ p_confirm_title: args.confirm_title
3313
+ },
3314
+ "portalRestore"
3315
+ );
3316
+ },
3233
3317
  async portalTables() {
3234
3318
  return callDoor(DOORS.portalTables, { p_organization_id: org }, "portalTables");
3235
3319
  },
@@ -4636,6 +4720,85 @@ function useRecordMutation() {
4636
4720
  [client, run, saving, error, conflict]
4637
4721
  );
4638
4722
  }
4723
+ var MIN_ARCHIVE_CHUNK = 10;
4724
+ function useTableArchive(tableId, options) {
4725
+ const client = useRecordsClient();
4726
+ const chunk = options?.chunk ?? 50;
4727
+ const includeTable = options?.includeTable ?? true;
4728
+ const [progress, setProgress] = useState(null);
4729
+ const [running, setRunning] = useState(false);
4730
+ const [passes, setPasses] = useState(0);
4731
+ const [error, setError] = useState(null);
4732
+ const [interrupted, setInterrupted] = useState(false);
4733
+ const [chunkInUse, setChunkInUse] = useState(chunk);
4734
+ const [slowedDown, setSlowedDown] = useState(false);
4735
+ const cut = useRef(false);
4736
+ const preview = useCallback(async () => {
4737
+ setError(null);
4738
+ const answered = await client.tableArchive({ table_id: tableId, chunk: 0, includeTable });
4739
+ if (!answered.ok) {
4740
+ setError(answered.error);
4741
+ return null;
4742
+ }
4743
+ setProgress(answered.data);
4744
+ return answered.data;
4745
+ }, [client, tableId, includeTable]);
4746
+ const loop = useCallback(async () => {
4747
+ cut.current = false;
4748
+ setRunning(true);
4749
+ setError(null);
4750
+ setInterrupted(false);
4751
+ setPasses(0);
4752
+ let last = null;
4753
+ let size = chunk;
4754
+ setChunkInUse(size);
4755
+ setSlowedDown(false);
4756
+ try {
4757
+ for (; ; ) {
4758
+ const answered = await client.tableArchive({ table_id: tableId, chunk: size, includeTable });
4759
+ if (!answered.ok) {
4760
+ if (answered.error.code === "timed_out" && size > MIN_ARCHIVE_CHUNK) {
4761
+ size = Math.max(MIN_ARCHIVE_CHUNK, Math.floor(size / 2));
4762
+ setChunkInUse(size);
4763
+ setSlowedDown(true);
4764
+ continue;
4765
+ }
4766
+ setError(answered.error);
4767
+ setInterrupted(true);
4768
+ return last;
4769
+ }
4770
+ last = answered.data;
4771
+ setProgress(answered.data);
4772
+ setPasses((n) => n + 1);
4773
+ if (answered.data.done) return answered.data;
4774
+ if (cut.current) {
4775
+ setInterrupted(true);
4776
+ return answered.data;
4777
+ }
4778
+ }
4779
+ } finally {
4780
+ setRunning(false);
4781
+ }
4782
+ }, [client, tableId, chunk, includeTable]);
4783
+ return useMemo2(
4784
+ () => ({
4785
+ progress,
4786
+ running,
4787
+ passes,
4788
+ chunkInUse,
4789
+ slowedDown,
4790
+ error,
4791
+ interrupted,
4792
+ preview,
4793
+ start: loop,
4794
+ carryOn: loop,
4795
+ stop: () => {
4796
+ cut.current = true;
4797
+ }
4798
+ }),
4799
+ [progress, running, passes, chunkInUse, slowedDown, error, interrupted, preview, loop]
4800
+ );
4801
+ }
4639
4802
  function useEntityFields(token) {
4640
4803
  return useAsync(
4641
4804
  (client) => token ? client.entityFields({ token }) : Promise.resolve({ ok: true, data: [] }),
@@ -5118,6 +5281,24 @@ function publicFormPath(formId) {
5118
5281
  function portalPath(slug) {
5119
5282
  return `/portal/c/${slug}`;
5120
5283
  }
5284
+ var PORTAL_ARCHIVE_FILTERS = ["active", "archived", "all"];
5285
+ var DEFAULT_PORTAL_ARCHIVE_FILTER = "active";
5286
+ function isPortalArchiveFilter(word) {
5287
+ return typeof word === "string" && PORTAL_ARCHIVE_FILTERS.includes(word);
5288
+ }
5289
+ function portalArchiveConsequence(title, signedIn, invited) {
5290
+ const people = invited === 0 ? "Nobody is invited to it" : signedIn === 0 ? `The ${invited} ${invited === 1 ? "person" : "people"} invited to it will not be able to sign in` : `The ${signedIn} ${signedIn === 1 ? "person" : "people"} signed in to it, and the ${invited - signedIn} still invited, will not be able to sign in`;
5291
+ return `\u201C${title}\u201D will leave your portal list. ${people}, and their invitation links will say this portal was archived and can be restored. Nothing is deleted \u2014 every Table it shows and everyone invited to it is kept exactly as it is, and you can restore it at any time.`;
5292
+ }
5293
+ function portalConfirmLine(title) {
5294
+ return `Type the portal\u2019s title \u2014 ${title} \u2014 to confirm you mean this one.`;
5295
+ }
5296
+ function portalTitleTypedBack(typed, title) {
5297
+ return typed.trim() === (title ?? "").trim();
5298
+ }
5299
+ function emptyPortalArchiveLine() {
5300
+ return "No portal of this organization has been archived. A portal you put away waits here until somebody restores it, and nothing is ever destroyed.";
5301
+ }
5121
5302
 
5122
5303
  // src/capture-queue.ts
5123
5304
  var DB_NAME = "matrx-capture";
@@ -5412,6 +5593,7 @@ export {
5412
5593
  CONTEXT_POLICIES,
5413
5594
  DECLARABLE_FIELD_KINDS,
5414
5595
  DEFAULT_ARCHIVE_LANE,
5596
+ DEFAULT_PORTAL_ARCHIVE_FILTER,
5415
5597
  DELIVERIES,
5416
5598
  ENTITY_TOKENS,
5417
5599
  FIELD_KINDS,
@@ -5428,6 +5610,7 @@ export {
5428
5610
  PERMISSION_LEVELS,
5429
5611
  PER_VALUE_ACCESS_WORDS,
5430
5612
  PIPELINE_RULE_KINDS,
5613
+ PORTAL_ARCHIVE_FILTERS,
5431
5614
  REFUSALS_WORTH_REPEATING,
5432
5615
  RELATION_BINDINGS,
5433
5616
  RELATION_CARDINALITIES,
@@ -5459,6 +5642,7 @@ export {
5459
5642
  coerceTypedAnswers,
5460
5643
  coercionLabel,
5461
5644
  emptyArchiveLine,
5645
+ emptyPortalArchiveLine,
5462
5646
  err,
5463
5647
  fieldKindFor,
5464
5648
  forgetAllOps,
@@ -5468,6 +5652,7 @@ export {
5468
5652
  isArchiveLane,
5469
5653
  isDecided,
5470
5654
  isOwnOp,
5655
+ isPortalArchiveFilter,
5471
5656
  isRecordsErr,
5472
5657
  isTheChosen,
5473
5658
  looksLikeAnId,
@@ -5480,7 +5665,10 @@ export {
5480
5665
  openCaptureQueue,
5481
5666
  optionKey,
5482
5667
  optionLabel,
5668
+ portalArchiveConsequence,
5669
+ portalConfirmLine,
5483
5670
  portalPath,
5671
+ portalTitleTypedBack,
5484
5672
  publicFormPath,
5485
5673
  rememberedOpCount,
5486
5674
  sameDocument,
@@ -5504,6 +5692,7 @@ export {
5504
5692
  useRecordsActor,
5505
5693
  useRecordsClient,
5506
5694
  useTable,
5695
+ useTableArchive,
5507
5696
  useTables
5508
5697
  };
5509
5698
  //# sourceMappingURL=index.js.map