@ai-matrx/records 0.37.0 → 0.39.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.
@@ -85,6 +85,7 @@ __export(react_exports, {
85
85
  portalPath: () => portalPath,
86
86
  publicFormPath: () => publicFormPath,
87
87
  scopeChip: () => scopeChip,
88
+ tableShapeChanged: () => tableShapeChanged,
88
89
  useEntityFieldMutation: () => useEntityFieldMutation,
89
90
  useEntityFieldRights: () => useEntityFieldRights,
90
91
  useEntityFields: () => useEntityFields,
@@ -252,6 +253,7 @@ var STORE_DOORS = [
252
253
  { name: "assert_client_may_change", args: "p_organization_id uuid, p_subject_id uuid, p_door text, p_required permission_level DEFAULT 'editor'::permission_level, p_subject_word text DEFAULT 'record'::text", returns: "void", security: "invoker" },
253
254
  { name: "assert_client_may_open", args: "p_organization_id uuid, p_subject_id uuid, p_door text, p_required permission_level DEFAULT 'viewer'::permission_level, p_subject_word text DEFAULT 'record'::text", returns: "void", security: "invoker" },
254
255
  { name: "assert_client_may_reach", args: "p_organization_id uuid, p_door text", returns: "void", security: "invoker" },
256
+ { name: "assert_columns_are_defined", args: "p_organization_id uuid, p_record_id uuid, p_patch jsonb", returns: "void", security: "definer" },
255
257
  { name: "assert_entity_door", args: "p_organization_id uuid, p_door text", returns: "void", security: "definer" },
256
258
  { name: "assert_entity_is_organization_scoped", args: "p_token text, p_label text, p_scoped boolean", returns: "void", security: "invoker" },
257
259
  { name: "assert_may_know_table", args: "p_organization_id uuid, p_table_id uuid, p_door text", returns: "void", security: "invoker" },
@@ -306,6 +308,7 @@ var STORE_DOORS = [
306
308
  { 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" },
307
309
  { name: "comment_thread", args: "p_organization_id uuid, p_record_id uuid, p_include_resolved boolean DEFAULT false", returns: "jsonb", security: "definer" },
308
310
  { 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" },
311
+ { name: "computed_block", args: "p_block jsonb", returns: "jsonb", security: "invoker" },
309
312
  { 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" },
310
313
  { name: "containment_chain", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(ancestor_id uuid, depth integer)", security: "invoker" },
311
314
  { name: "containment_depth_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
@@ -337,6 +340,7 @@ var STORE_DOORS = [
337
340
  { name: "derive_visibility", args: "p_container_type text, p_container_id uuid", returns: "TABLE(item_type text, item_id uuid, depth integer, max_level permission_level)", security: "definer" },
338
341
  { name: "derived_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb, p_values jsonb DEFAULT NULL::jsonb", returns: "jsonb", security: "invoker" },
339
342
  { name: "derived_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
343
+ { name: "derived_values_of", args: "v_rec custom.record", returns: "jsonb", security: "invoker" },
340
344
  { name: "doc_content_hash", args: "p_body text", returns: "text", security: "invoker" },
341
345
  { name: "doc_format_value", args: "p_field_data jsonb, p_value jsonb", returns: "text", security: "invoker" },
342
346
  { name: "doc_letterhead", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
@@ -602,6 +606,7 @@ var STORE_DOORS = [
602
606
  { name: "record_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
603
607
  { 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" },
604
608
  { name: "record_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
609
+ { name: "record_values_of", args: "p_row custom.record", returns: "jsonb", security: "invoker" },
605
610
  { 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" },
606
611
  { name: "record_write", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb", returns: "uuid", security: "definer" },
607
612
  { name: "record_write_many", args: "p_organization_id uuid, p_table_id uuid, p_rows jsonb[], p_ids uuid[] DEFAULT NULL::uuid[]", returns: "uuid[]", security: "definer" },
@@ -805,7 +810,7 @@ var STORE_REFUSAL_CODES = [
805
810
  { code: "22023", raised_by: "_booking_availability,_entity_custom_fields_guard,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,booking_declare,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,enrich_declare,enrich_land,enrich_normalize,enrich_pin,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,io_export,io_import_begin,io_import_finish,io_import_plan,io_import_report,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,page_size,pin_agent_cells,pipeline_move,portal_declare,provenance_write,query_by_coordinates,query_rollup,record_update,record_write_many,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,sign_request_create,sign_request_sign,subscription_declare,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
806
811
  { code: "23503", raised_by: "_booking_availability,_checklist_instantiate,_containment_guard,_field_document_for,_pipeline_stage_key,_record_rule_uses,agg_digest_assemble,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,booking_cancel,booking_confirm,booking_declare,booking_hold,booking_reschedule,capture_publish,checklist_declare,checklist_steps_table,comment_write,dashboard_declare,delete_rule,doc_sign,doc_template_save,enrich_declare,enrich_due,enrich_land,form_declare,form_submit,home_add,inbound_declare,inbound_mail_land,inbound_set,io_comment_write,io_import_begin,io_import_finish,io_import_report,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,pipeline_board,pipeline_declare,pipeline_move,pipeline_read,pipeline_transition_refusal,promote_field,promote_table,record_applicability,record_reparent,relation_carry,relation_own,resolve_first_match,rule_applies,rule_declare,rule_eval,rule_members,rule_run,sign_request_create,subscription_mute,subscription_preview,view_declare,work_set_state,work_take_assignment,work_template_instantiate" },
807
812
  { code: "23505", raised_by: "_unique_rule_holds,doc_sign,doc_signature_write,entity_field_declare,field_declare,home_add,inbound_declare,io_proposal_accept,relation_carry,relation_own,share_grant,sign_request_cancel,sign_request_create,work_approval_decide,work_slot_hold" },
808
- { code: "23514", raised_by: "_checklist_instantiate,_checklist_step_guard,_claimed_column_guard,_containment_guard,_dated_values_guard,_derived_fields,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_columns_word_guard,_table_shape_guard,_undeclared_key_guard,_value_envelope,_work_shape_guard,_workdoors_approval_guard,assert_entity_is_organization_scoped,capture_publish,capture_sheet_declare,checklist_declare,checklist_step_complete,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,io_import_rows,migrate_merge,relation_carry,relation_own,sign_request_create,sign_request_sign,table_declare,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
813
+ { code: "23514", raised_by: "_checklist_instantiate,_checklist_step_guard,_containment_guard,_dated_values_guard,_derived_fields,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_columns_word_guard,_table_shape_guard,_undeclared_key_guard,_value_envelope,_work_shape_guard,_workdoors_approval_guard,assert_columns_are_defined,assert_entity_is_organization_scoped,capture_publish,capture_sheet_declare,checklist_declare,checklist_step_complete,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,io_import_rows,migrate_merge,relation_carry,relation_own,sign_request_create,sign_request_sign,table_declare,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
809
814
  { code: "40001", raised_by: "has_visibility_at" },
810
815
  { code: "42501", raised_by: "_doc_render_immutable,_doc_signature_immutable,_field_definition_write,_field_write_door,_rule_definition_write,_store_door,anon_capture,anon_inbound_land,anon_publish,anon_token_issue,anon_token_verify,anon_write,assert_client_may_change,assert_client_may_open,assert_client_may_reach,assert_may_know_table,assert_organization_admin,assert_store_door,booking_confirm,booking_declare,booking_hold,capture_submit,checklist_run,comment_write,conversation_scope_bind,conversation_scope_unbind,enrich_declare,enrich_due,enrich_land,enrich_normalize,entity_field_declare,entity_field_retire,entity_field_update,entity_value_write,external_write_through,form_declare,form_submit,inbound_mail_land,io_comment_resolve,io_comment_write,io_import_begin,io_import_finish,io_restore,migrate_purge,migrate_reclass,my_levels,organization_clear,portal_declare,portal_invitation,portal_invite,portal_principal_bind,promote_table,query_visibility_parity,read_record,read_records,record_table,share_grant,subscription_mute,subscription_preview,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_person" },
811
816
  { code: "42703", raised_by: "entity_table,portal_declare" },
@@ -1377,6 +1382,7 @@ var ENTITY_TOKENS = [
1377
1382
  "mandate_advance_batch_row",
1378
1383
  "mandate_binding",
1379
1384
  "mandate_binding_legacy",
1385
+ "mandate_goal_clauses",
1380
1386
  "mandate_legacy",
1381
1387
  "mandate_observation",
1382
1388
  "mandate_reference",
@@ -2532,7 +2538,8 @@ function createRecordsClient(config) {
2532
2538
  const { document, hidden } = unfold(row.document);
2533
2539
  return { id: row.id, document, level: row.level, hidden };
2534
2540
  });
2535
- return ok({ rows, total: null });
2541
+ const total = rows.length < limit ? offset + rows.length : null;
2542
+ return ok({ rows, total });
2536
2543
  },
2537
2544
  async query(input) {
2538
2545
  const plan = planQuery(input);
@@ -4274,13 +4281,36 @@ function useMyLevel(id) {
4274
4281
  [id]
4275
4282
  );
4276
4283
  }
4284
+ var shapeRevisions = /* @__PURE__ */ new Map();
4285
+ var shapeListeners = /* @__PURE__ */ new Set();
4286
+ function tableShapeChanged(tableId) {
4287
+ shapeRevisions.set(tableId, (shapeRevisions.get(tableId) ?? 0) + 1);
4288
+ for (const listener of shapeListeners) listener();
4289
+ }
4290
+ function registerShapeInterest(tableId) {
4291
+ if (!shapeRevisions.has(tableId)) shapeRevisions.set(tableId, 0);
4292
+ }
4293
+ function subscribeToShape(listener) {
4294
+ shapeListeners.add(listener);
4295
+ return () => {
4296
+ shapeListeners.delete(listener);
4297
+ };
4298
+ }
4299
+ function useShapeRevision(tableId) {
4300
+ const read = (0, import_react2.useCallback)(() => tableId ? shapeRevisions.get(tableId) ?? 0 : 0, [tableId]);
4301
+ return (0, import_react2.useSyncExternalStore)(subscribeToShape, read, () => 0);
4302
+ }
4277
4303
  function useFields(tableId, recordType) {
4304
+ const revision = useShapeRevision(tableId);
4305
+ (0, import_react2.useEffect)(() => {
4306
+ if (tableId) registerShapeInterest(tableId);
4307
+ }, [tableId]);
4278
4308
  return useAsync(
4279
4309
  async (client) => {
4280
4310
  if (!tableId) return { ok: true, data: [] };
4281
4311
  return client.fields({ table_id: tableId, ...recordType === void 0 ? {} : { recordType } });
4282
4312
  },
4283
- [tableId, recordType]
4313
+ [tableId, recordType, revision]
4284
4314
  );
4285
4315
  }
4286
4316
  function useRecords(tableId, options = {}) {
@@ -4453,19 +4483,41 @@ function useFieldMutation() {
4453
4483
  },
4454
4484
  []
4455
4485
  );
4486
+ const announce = (0, import_react2.useCallback)((tableId) => {
4487
+ if (tableId) {
4488
+ tableShapeChanged(tableId);
4489
+ return;
4490
+ }
4491
+ for (const id of [...shapeRevisions.keys()]) tableShapeChanged(id);
4492
+ }, []);
4456
4493
  return (0, import_react2.useMemo)(
4457
4494
  () => ({
4458
- declare: (args) => run(
4459
- () => client.fieldDeclare({ table_id: args.table_id, spec: args.spec }),
4460
- null
4461
- ),
4462
- update: (args) => run(() => client.fieldUpdate({ field_id: args.field_id, patch: args.patch }), null),
4463
- retire: (args) => run(() => client.fieldRetire({ field_id: args.field_id }), false),
4495
+ declare: async (args) => {
4496
+ const made = await run(
4497
+ () => client.fieldDeclare({ table_id: args.table_id, spec: args.spec }),
4498
+ null
4499
+ );
4500
+ if (made !== null) announce(args.table_id);
4501
+ return made;
4502
+ },
4503
+ update: async (args) => {
4504
+ const changed = await run(
4505
+ () => client.fieldUpdate({ field_id: args.field_id, patch: args.patch }),
4506
+ null
4507
+ );
4508
+ if (changed !== null) announce(null);
4509
+ return changed;
4510
+ },
4511
+ retire: async (args) => {
4512
+ const gone = await run(() => client.fieldRetire({ field_id: args.field_id }), false);
4513
+ if (gone) announce(null);
4514
+ return gone;
4515
+ },
4464
4516
  saving,
4465
4517
  error,
4466
4518
  clearError: () => setError(null)
4467
4519
  }),
4468
- [client, run, saving, error]
4520
+ [client, run, announce, saving, error]
4469
4521
  );
4470
4522
  }
4471
4523
  function useMergeField(key, state) {