@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.
package/dist/index.cjs CHANGED
@@ -55,11 +55,20 @@ __export(src_exports, {
55
55
  VALUE_ENVELOPE_KEYS: () => VALUE_ENVELOPE_KEYS,
56
56
  asPermissionLevel: () => asPermissionLevel,
57
57
  atLeast: () => atLeast,
58
+ choiceSlug: () => choiceSlug,
59
+ choiceValuesOf: () => choiceValuesOf,
60
+ choicesOf: () => choicesOf,
58
61
  err: () => err,
59
62
  highestLevel: () => highestLevel,
63
+ holdsARetiredChoice: () => holdsARetiredChoice,
60
64
  isRecordsErr: () => isRecordsErr,
65
+ isTheChosen: () => isTheChosen,
66
+ looksLikeAnId: () => looksLikeAnId,
61
67
  measureKey: () => measureKey,
62
68
  ok: () => ok,
69
+ optionKey: () => optionKey,
70
+ optionLabel: () => optionLabel,
71
+ portalPath: () => portalPath,
63
72
  publicFormPath: () => publicFormPath
64
73
  });
65
74
  module.exports = __toCommonJS(src_exports);
@@ -147,11 +156,59 @@ function highestLevel(left, right) {
147
156
  return ORDINAL[left] >= ORDINAL[right] ? left : right;
148
157
  }
149
158
 
159
+ // src/choice.ts
160
+ var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
161
+ function optionKey(option) {
162
+ const stored = option.metadata?.["option_key"];
163
+ if (typeof stored === "string" && stored.trim() !== "") return stored;
164
+ return choiceSlug(optionLabel(option));
165
+ }
166
+ function optionLabel(option) {
167
+ const doc = option.data;
168
+ const title = doc?.["title"] ?? doc?.["name"];
169
+ if (typeof title === "string" && title.trim() !== "") return title;
170
+ return "Unnamed choice";
171
+ }
172
+ function choiceSlug(word) {
173
+ const slug = word.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 55);
174
+ return slug === "" ? "choice" : slug;
175
+ }
176
+ function isTheChosen(option, value) {
177
+ if (typeof value !== "string") return false;
178
+ const asked = value.trim().toLowerCase();
179
+ if (asked === "") return false;
180
+ return asked === optionKey(option).toLowerCase() || asked === optionLabel(option).toLowerCase() || asked === option.id.toLowerCase();
181
+ }
182
+ function choiceValuesOf(value) {
183
+ if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
184
+ if (typeof value === "string" && value !== "") return [value];
185
+ return [];
186
+ }
187
+ function choicesOf(document, fieldKeyOrId) {
188
+ const block = document?.["_choices"];
189
+ if (!block || typeof block !== "object") return [];
190
+ const entry = block[fieldKeyOrId];
191
+ if (!entry) return [];
192
+ const list = Array.isArray(entry) ? entry : [entry];
193
+ return list.filter((x) => !!x && typeof x === "object" && typeof x.key === "string");
194
+ }
195
+ function holdsARetiredChoice(document, fieldKeyOrId) {
196
+ return choicesOf(document, fieldKeyOrId).some((c) => c.retired === true);
197
+ }
198
+ function looksLikeAnId(value) {
199
+ return typeof value === "string" && UUID.test(value);
200
+ }
201
+
150
202
  // src/rule.ts
151
203
  function publicFormPath(formId) {
152
204
  return `/f/${formId}`;
153
205
  }
154
206
 
207
+ // src/portal.ts
208
+ function portalPath(slug) {
209
+ return `/portal/c/${slug}`;
210
+ }
211
+
155
212
  // src/aggregate.ts
156
213
  function measureKey(measure) {
157
214
  return measure.op === "count" ? "count" : `${measure.op}_${measure.key ?? ""}`;
@@ -266,7 +323,24 @@ var STORE_DOORS = [
266
323
  { name: "caller_role", args: "", returns: "name", security: "invoker" },
267
324
  { 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" },
268
325
  { 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" },
326
+ { name: "choice_census", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
327
+ { name: "choice_field_map", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "invoker" },
328
+ { name: "choice_filter_normalize", args: "p_map jsonb, p_filter jsonb", returns: "jsonb", security: "invoker" },
329
+ { 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" },
330
+ { name: "choice_key_of", args: "p_field jsonb, p_token text", returns: "text", security: "invoker" },
331
+ { name: "choice_options", args: "p_organization_id uuid, p_options_table_id uuid", returns: "jsonb", security: "invoker" },
332
+ { name: "choice_render", args: "p_organization_id uuid, p_table_id uuid, p_doc jsonb", returns: "jsonb", security: "invoker" },
333
+ { name: "choice_render_groups", args: "p_map jsonb, p_groups jsonb", returns: "jsonb", security: "invoker" },
334
+ { name: "choice_render_note", args: "p_field jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
335
+ { name: "choice_render_value", args: "p_field jsonb, p_value jsonb", returns: "jsonb", security: "invoker" },
336
+ { name: "choice_slug", args: "p_word text", returns: "text", security: "invoker" },
337
+ { name: "choice_synonyms", args: "p_organization_id uuid, p_table_id uuid, p_token text", returns: "text[]", security: "invoker" },
338
+ { name: "choice_synonyms_in", args: "p_map jsonb, p_token text", returns: "text[]", security: "invoker" },
339
+ { name: "choice_words", args: "p_field jsonb", returns: "text", security: "invoker" },
269
340
  { name: "client_write_grants", args: "", returns: "TABLE(role_name text, object_name text, privilege text)", security: "invoker" },
341
+ { 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" },
342
+ { name: "comment_thread", args: "p_organization_id uuid, p_record_id uuid, p_include_resolved boolean DEFAULT false", returns: "jsonb", security: "definer" },
343
+ { 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" },
270
344
  { 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" },
271
345
  { name: "containment_chain", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(ancestor_id uuid, depth integer)", security: "invoker" },
272
346
  { name: "containment_depth_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
@@ -274,6 +348,17 @@ var STORE_DOORS = [
274
348
  { name: "containment_parent", args: "p_data jsonb", returns: "uuid", security: "invoker" },
275
349
  { name: "cross_organization_links_open", args: "p_source_organization_id uuid, p_target_organization_id uuid", returns: "boolean", security: "invoker" },
276
350
  { name: "custom_fields_tables", args: "", returns: "TABLE(token text, schema_name text, table_name text)", security: "invoker" },
351
+ { name: "dashboard_block_normalize", args: "p_organization_id uuid, p_subject_table_id uuid, p_block jsonb", returns: "jsonb", security: "definer" },
352
+ { name: "dashboard_class", args: "", returns: "text", security: "invoker" },
353
+ { 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" },
354
+ { name: "dashboard_delete", args: "p_organization_id uuid, p_dashboard_id uuid", returns: "boolean", security: "definer" },
355
+ { name: "dashboard_field_keys", args: "p_organization_id uuid, p_table_id uuid", returns: "text[]", security: "definer" },
356
+ { name: "dashboard_kinds", args: "", returns: "text[]", security: "invoker" },
357
+ { name: "dashboard_moment_sql", args: "p_key text", returns: "text", security: "invoker" },
358
+ { name: "dashboard_run", args: "p_organization_id uuid, p_dashboard_id uuid, p_filter jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
359
+ { 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" },
360
+ { name: "dashboard_window_sql", args: "p_key text, p_window jsonb", returns: "text", security: "invoker" },
361
+ { 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" },
277
362
  { name: "delete_cascade_closure", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid[]", security: "invoker" },
278
363
  { name: "delete_preview", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
279
364
  { name: "delete_rule", args: "p_organization_id uuid, p_record_id uuid, p_apply boolean DEFAULT true", returns: "jsonb", security: "definer" },
@@ -288,13 +373,17 @@ var STORE_DOORS = [
288
373
  { name: "doc_render_document", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
289
374
  { name: "doc_render_read", args: "p_organization_id uuid, p_render_id uuid", returns: "jsonb", security: "definer" },
290
375
  { 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" },
376
+ { 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" },
291
377
  { 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" },
292
378
  { name: "doc_signature_field_ok", args: "p_field_data jsonb", returns: "boolean", security: "invoker" },
293
379
  { name: "doc_signature_intact", args: "p_organization_id uuid, p_signature_id uuid", returns: "jsonb", security: "invoker" },
294
380
  { name: "doc_signature_read", args: "p_organization_id uuid, p_signature_id uuid", returns: "jsonb", security: "definer" },
295
381
  { 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" },
382
+ { 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" },
383
+ { name: "doc_template_delete", args: "p_organization_id uuid, p_template_id uuid", returns: "boolean", security: "definer" },
296
384
  { name: "doc_template_read", args: "p_organization_id uuid, p_template_id uuid", returns: "jsonb", security: "definer" },
297
385
  { 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" },
386
+ { 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" },
298
387
  { name: "doc_token_pattern", args: "", returns: "text", security: "invoker" },
299
388
  { name: "doc_tokens", args: "p_body text", returns: "TABLE(ordinal integer, raw text, field_id uuid)", security: "invoker" },
300
389
  { 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" },
@@ -323,6 +412,7 @@ var STORE_DOORS = [
323
412
  { name: "field_behaviour", args: "p_field_data jsonb", returns: "text", security: "invoker" },
324
413
  { name: "field_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
325
414
  { 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" },
415
+ { 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" },
326
416
  { name: "field_kernel_id", args: "", returns: "uuid", security: "invoker" },
327
417
  { name: "field_options", args: "p_organization_id uuid, p_field_id uuid", returns: "SETOF custom.record", security: "definer" },
328
418
  { name: "field_retire", args: "p_organization_id uuid, p_field_id uuid", returns: "boolean", security: "definer" },
@@ -341,7 +431,11 @@ var STORE_DOORS = [
341
431
  { 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" },
342
432
  { 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" },
343
433
  { name: "hidden_field_notice", args: "p_field custom.record, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "invoker" },
434
+ { name: "history_actor", args: "p_tier text, p_document jsonb, p_actor_id uuid, p_people jsonb", returns: "jsonb", security: "invoker" },
435
+ { name: "history_changes", args: "p_organization_id uuid, p_table_id uuid, p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
436
+ { name: "history_people", args: "p_organization_id uuid, p_ids uuid[]", returns: "jsonb", security: "definer" },
344
437
  { 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" },
438
+ { name: "history_restore_body", args: "p_current jsonb, p_target jsonb, p_field_key text DEFAULT NULL::text", returns: "jsonb", security: "invoker" },
345
439
  { name: "history_retention", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
346
440
  { name: "history_retention_floor_raise", args: "p_organization_id uuid, p_days integer", returns: "integer", security: "definer" },
347
441
  { name: "history_retention_set", args: "p_organization_id uuid, p_table_id uuid, p_days integer", returns: "integer", security: "definer" },
@@ -370,16 +464,20 @@ var STORE_DOORS = [
370
464
  { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "integer", security: "definer" },
371
465
  { 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" },
372
466
  { 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" },
467
+ { 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" },
468
+ { 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" },
373
469
  { name: "lookup_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb", returns: "jsonb", security: "invoker" },
374
470
  { 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" },
375
471
  { 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" },
376
472
  { name: "merge_field_kernel_id", args: "", returns: "uuid", security: "invoker" },
473
+ { name: "migrate_choice_keys", args: "p_organization_id uuid, p_table_id uuid, p_dry_run boolean DEFAULT false", returns: "jsonb", security: "definer" },
377
474
  { name: "migrate_delete", args: "p_organization_id uuid, p_record_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
378
475
  { name: "migrate_demote", args: "p_organization_id uuid, p_table_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
379
476
  { 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" },
380
477
  { 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" },
381
478
  { name: "migrate_promote", args: "p_organization_id uuid, p_table_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
382
479
  { 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" },
480
+ { 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" },
383
481
  { name: "migrate_rename", args: "p_organization_id uuid, p_id uuid, p_to text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
384
482
  { 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" },
385
483
  { name: "migrate_retype", args: "p_organization_id uuid, p_id uuid, p_to text, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
@@ -399,6 +497,20 @@ var STORE_DOORS = [
399
497
  { 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" },
400
498
  { name: "per_value_access_words", args: "", returns: "text[]", security: "invoker" },
401
499
  { name: "person_kernel_id", args: "", returns: "uuid", security: "invoker" },
500
+ { name: "portal_admits", args: "p_organization_id uuid, p_user_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "definer" },
501
+ { name: "portal_card", args: "p_organization_id uuid, p_portal_id uuid", returns: "jsonb", security: "definer" },
502
+ { 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" },
503
+ { 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" },
504
+ { name: "portal_invitation", args: "p_slug text, p_email text", returns: "jsonb", security: "definer" },
505
+ { 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" },
506
+ { name: "portal_me", args: "", returns: "jsonb", security: "definer" },
507
+ { 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" },
508
+ { name: "portal_principal_bind", args: "p_organization_id uuid, p_principal_id uuid, p_user_id uuid", returns: "jsonb", security: "definer" },
509
+ { name: "portal_public", args: "p_slug text", returns: "jsonb", security: "definer" },
510
+ { name: "portal_record_title", args: "p_organization_id uuid, p_record_id uuid", returns: "text", security: "definer" },
511
+ { name: "portal_revoke", args: "p_organization_id uuid, p_portal_id uuid, p_principal_id uuid", returns: "jsonb", security: "definer" },
512
+ { name: "portal_slug", args: "p_organization_id uuid, p_title text, p_portal_id uuid DEFAULT NULL::uuid", returns: "text", security: "definer" },
513
+ { 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" },
402
514
  { name: "presentation_kernel_id", args: "", returns: "uuid", security: "invoker" },
403
515
  { name: "promote_field", args: "p_organization_id uuid, p_table_id uuid, p_field_id uuid", returns: "jsonb", security: "invoker" },
404
516
  { name: "promote_table", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
@@ -444,15 +556,20 @@ var STORE_DOORS = [
444
556
  { name: "record_card", args: "p_viewer uuid, p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
445
557
  { 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" },
446
558
  { name: "record_delete", args: "p_organization_id uuid, p_record_id uuid", returns: "timestamp with time zone", security: "definer" },
559
+ { 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" },
447
560
  { 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" },
448
561
  { name: "record_reparent", args: "p_organization_id uuid, p_record_id uuid, p_parent_id uuid", returns: "void", security: "definer" },
449
562
  { name: "record_resolve", args: "p_organization_id uuid, p_id uuid", returns: "jsonb", security: "definer" },
450
563
  { name: "record_restore", args: "p_organization_id uuid, p_record_id uuid", returns: "void", security: "definer" },
564
+ { 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" },
565
+ { name: "record_restore_version", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "jsonb", security: "definer" },
451
566
  { name: "record_state_as_of", args: "p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(state jsonb, replayed boolean)", security: "definer" },
567
+ { name: "record_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
452
568
  { 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" },
453
569
  { name: "record_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
454
570
  { 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" },
455
571
  { name: "record_write", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb", returns: "uuid", security: "definer" },
572
+ { name: "refusals_claiming_a_level_never_asked", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
456
573
  { name: "relation_carry", args: "p_organization_id uuid, p_container_id uuid, p_item_id uuid", returns: "uuid", security: "definer" },
457
574
  { name: "relation_edges_withdraw", args: "p_organization_id uuid, p_field_ids uuid[], p_why text", returns: "integer", security: "definer" },
458
575
  { name: "relation_own", args: "p_organization_id uuid, p_owner_id uuid, p_target_id uuid", returns: "uuid", security: "definer" },
@@ -498,7 +615,11 @@ var STORE_DOORS = [
498
615
  { 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" },
499
616
  { name: "storage_modes", args: "", returns: "text[]", security: "invoker" },
500
617
  { name: "store_is_open", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "invoker" },
618
+ { name: "subscription_cadences", args: "p_organization_id uuid", returns: "text[]", security: "definer" },
619
+ { name: "subscription_mute", args: "p_organization_id uuid, p_rule_id uuid, p_muted boolean DEFAULT true", returns: "boolean", security: "definer" },
620
+ { 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" },
501
621
  { name: "table_capacity", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
622
+ { 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" },
502
623
  { name: "table_contents", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(record_id uuid, kind text, goes_at integer)", security: "invoker" },
503
624
  { name: "table_declare", args: "p_organization_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
504
625
  { name: "table_has_a_visible_record", args: "p_user uuid, p_organization_id uuid, p_table_id uuid", returns: "boolean", security: "definer" },
@@ -520,6 +641,7 @@ var STORE_DOORS = [
520
641
  { name: "value_envelope_ok", args: "p_data jsonb", returns: "boolean", security: "invoker" },
521
642
  { name: "value_envelope_refusal", args: "p_data jsonb", returns: "text", security: "invoker" },
522
643
  { 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" },
644
+ { name: "value_restore", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_version integer", returns: "jsonb", security: "definer" },
523
645
  { name: "value_versions", args: "p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
524
646
  { 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" },
525
647
  { 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" },
@@ -532,6 +654,7 @@ var STORE_DOORS = [
532
654
  { name: "widget_kernel_id", args: "", returns: "uuid", security: "invoker" },
533
655
  { 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" },
534
656
  { 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" },
657
+ { name: "work_approval_kinds", args: "", returns: "text[]", security: "invoker" },
535
658
  { name: "work_approval_may_decide", args: "p_organization_id uuid, p_approval_id uuid", returns: "boolean", security: "definer" },
536
659
  { name: "work_approval_read", args: "p_organization_id uuid, p_approval_id uuid", returns: "jsonb", security: "definer" },
537
660
  { 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" },
@@ -551,6 +674,7 @@ var STORE_DOORS = [
551
674
  { name: "work_slot_index_name", args: "p_table_id uuid", returns: "text", security: "invoker" },
552
675
  { name: "work_slot_release", args: "p_organization_id uuid, p_hold_id uuid", returns: "boolean", security: "definer" },
553
676
  { 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" },
677
+ { name: "work_state_id", args: "p_organization_id uuid, p_table_id uuid, p_value text", returns: "uuid", security: "invoker" },
554
678
  { name: "work_states", args: "", returns: "TABLE(sort integer, name text, terminal boolean, next text[])", security: "invoker" },
555
679
  { name: "work_take_assignment", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
556
680
  { name: "work_template_declare", args: "p_organization_id uuid, p_name text, p_graph jsonb", returns: "uuid", security: "definer" },
@@ -568,6 +692,7 @@ var STORE_KNOBS = [
568
692
  { key: "code_paths_enabled", value: "false", type: "boolean" },
569
693
  { key: "consumer_chat_seeding_enabled", value: "false", type: "boolean" },
570
694
  { key: "consumer_checkout_enabled", value: "false", type: "boolean" },
695
+ { key: "consumer_context_enabled", value: "false", type: "boolean" },
571
696
  { key: "consumer_education_enabled", value: "false", type: "boolean" },
572
697
  { key: "consumer_extension_enabled", value: "false", type: "boolean" },
573
698
  { key: "consumer_grid_enabled", value: "false", type: "boolean" },
@@ -599,17 +724,18 @@ var STORE_KNOBS = [
599
724
  { key: "world_publish_enabled", value: "false", type: "boolean" }
600
725
  ];
601
726
  var STORE_REFUSAL_CODES = [
602
- { 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" },
603
- { 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" },
604
- { 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" },
727
+ { 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" },
728
+ { 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" },
729
+ { 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" },
730
+ { code: "22007", raised_by: "dashboard_window_sql" },
605
731
  { code: "22012", raised_by: "rule_eval" },
606
- { 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" },
607
- { 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" },
732
+ { 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" },
733
+ { 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" },
608
734
  { 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" },
609
- { 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" },
735
+ { 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" },
610
736
  { code: "40001", raised_by: "has_visibility_at" },
611
- { 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" },
612
- { code: "42703", raised_by: "entity_table" },
737
+ { 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" },
738
+ { code: "42703", raised_by: "entity_table,portal_declare" },
613
739
  { code: "53400", raised_by: "anon_rate_take,delete_cascade_closure,promote_field" },
614
740
  { code: "54001", raised_by: "record_delete" },
615
741
  { code: "PT409", raised_by: "record_update" }