@ai-matrx/records 0.98.6 → 0.98.8

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.
@@ -578,6 +578,95 @@ declare function supabaseDataSource(client: object): RecordsDataSource;
578
578
  */
579
579
  declare function asRecordsDataSource(source: unknown): RecordsDataSource;
580
580
 
581
+ /** The schema every door of the record store lives in. The only place an app-facing string says it. */
582
+ declare const STORE_SCHEMA = "custom";
583
+ /** What a door refused with, as PostgREST gave it. */
584
+ interface StoreDoorError {
585
+ message: string;
586
+ code?: string | null;
587
+ hint?: string | null;
588
+ details?: string | null;
589
+ }
590
+ interface StoreDoorAnswer<T = unknown> {
591
+ data: T | null;
592
+ error: StoreDoorError | null;
593
+ }
594
+ /** The bare caller: the same `rpc(fn, args)` shape the hand-written layers declared. */
595
+ interface StoreCaller {
596
+ rpc(fn: string, args?: Record<string, unknown>): PromiseLike<{
597
+ data: unknown;
598
+ error: StoreDoorError | null;
599
+ }>;
600
+ }
601
+ /** The named doors an app calls most. Every member is a thin call over `rpc`; nothing is added to the answer. */
602
+ interface StoreDoors extends StoreCaller {
603
+ /** `custom.where_id_opens(p_id)` — which organization an object lives in. `data` is null when it is not given to the caller; the error is plain JSON (it streams to a browser as is). */
604
+ whereIdOpens(id: string): PromiseLike<{
605
+ data: unknown;
606
+ error: {
607
+ code: string | null;
608
+ message: string;
609
+ } | null;
610
+ }>;
611
+ /** `custom.table_kernel_id()` — the id of the store's Table kernel (a constant of the store). */
612
+ tableKernelId(): PromiseLike<StoreDoorAnswer<string>>;
613
+ /** `custom.read_records_by_ids` — the records of `ids` the caller may read in `tableId`, in `organizationId`. */
614
+ readRecordsByIds(organizationId: string, tableId: string, ids: readonly string[]): PromiseLike<StoreDoorAnswer>;
615
+ /** `custom.read_records_page` — one page; `args` are the door's own named arguments. */
616
+ readRecordsPage(args: Record<string, unknown>): PromiseLike<StoreDoorAnswer>;
617
+ /** `custom.record_table` — the table a record lives in. */
618
+ recordTable(organizationId: string, recordId: string): PromiseLike<StoreDoorAnswer<string>>;
619
+ /** `custom.applicable_fields` — the fields of a table. */
620
+ applicableFields(organizationId: string, tableId: string): PromiseLike<StoreDoorAnswer>;
621
+ /** `custom.field_declare` — declare one field on a table. */
622
+ fieldDeclare(organizationId: string, tableId: string, spec: Record<string, unknown>): PromiseLike<StoreDoorAnswer<string>>;
623
+ /** `custom.record_update` — patch a record's values. */
624
+ recordUpdate(organizationId: string, recordId: string, patch: Record<string, unknown>): PromiseLike<StoreDoorAnswer>;
625
+ /** `custom.entity_reference_words` — the labels of `{token,id}` refs, withheld when the caller may not open them. */
626
+ entityReferenceWords(organizationId: string, refs: ReadonlyArray<{
627
+ token: string;
628
+ id: string;
629
+ }>): PromiseLike<StoreDoorAnswer>;
630
+ /** `custom.templates` — the catalogue (one page of cards for `filter`). */
631
+ templates(filter: Record<string, unknown>): PromiseLike<StoreDoorAnswer>;
632
+ /** `custom.template_from_tables` — draft a template spec from existing tables. */
633
+ templateFromTables(args: {
634
+ organizationId: string;
635
+ tableIds: readonly string[];
636
+ includeRows: boolean;
637
+ rowsPerTable: number;
638
+ }): PromiseLike<StoreDoorAnswer>;
639
+ /** `custom.template_declare` — declare a template (`scope` is `"org"` for an organization's own). */
640
+ templateDeclare(scope: string, spec: Record<string, unknown>): PromiseLike<StoreDoorAnswer>;
641
+ /** `custom.template_keep` — keep a one-off template in the organization's own. */
642
+ templateKeep(templateId: string): PromiseLike<StoreDoorAnswer>;
643
+ /** `custom.template_archive` — archive (or, with `restore`, bring back) an organization's own template. */
644
+ templateArchive(templateId: string, restore?: boolean): PromiseLike<StoreDoorAnswer>;
645
+ /** `custom.template_install_claim` — the host step's lease on one install step. */
646
+ templateInstallClaim(args: {
647
+ organizationId: string;
648
+ installId: string;
649
+ kind: string;
650
+ label: string;
651
+ sourceId?: string | null;
652
+ leaseSeconds: number;
653
+ }): PromiseLike<StoreDoorAnswer>;
654
+ /** `custom.template_install_note` — record the thing a host step made. */
655
+ templateInstallNote(args: {
656
+ organizationId: string;
657
+ installId: string;
658
+ kind: string;
659
+ id: string;
660
+ label: string;
661
+ }): PromiseLike<StoreDoorAnswer>;
662
+ }
663
+ /**
664
+ * Bind a supabase-js client (browser, server session, anon, or service-role) to the store's
665
+ * doors. A client with no `schema()` is refused by name on every call (`data_source_unbound`), never
666
+ * a thrown `undefined is not a function` in a render.
667
+ */
668
+ declare function storeDoors(client: unknown): StoreDoors;
669
+
581
670
  /** The SQLSTATEs this package claims to understand. Exported for the guard. */
582
671
  declare const MAPPED_SQLSTATES: string[];
583
672
  /** Map a PostgREST/supabase-js failure into the package's refusal shape. */
@@ -763,4 +852,4 @@ declare function seededDataSource(index: Map<string, unknown>): {
763
852
  missed: () => boolean;
764
853
  };
765
854
 
766
- export { type BlockOutcome, DEFAULT_DOCUMENT_MAX_BYTES, DEFAULT_VALUE_MAX_BYTES, DOORS, type DoorKey, type ExportRow, Field, LANDING_SOURCE_TYPE, LANDING_TARGET_TYPES, type Landing, type LandingBlock, type LandingOutcomes, type LandingState, type LandingStore, MAPPED_SQLSTATES, type MirrorLimits, OUTPUT_KEPT_KEY, PRIMED_DOOR_TTL_MS, PRODUCED_BY_LABEL, type ParsedImport, PgError, PredictedRefusal, type PrimedBundleAnswer, type ReadFileText, ReadValue, RecordDocument, RecordsDataSource, RecordsError, RecordsResult, type RecordsSeed, type RecordsSeedAnswer, StaleWriteDetail, type SupabaseLike, TableKindFacts, Uuid, WHOLE_VALUE_SOURCE_KIND, type WholeValuePointer, announceRecordChanged, announceTableStructureChanged, archivedOrganizationId, asRecordsDataSource, blockLandedInStore, cellText, doorAbsent, doorCensus, doorExists, doorReady, dropPrimedDoorAnswers, exportCellText, exportCsv, exportMarkdown, exportXlsx, forgetPrimedTablePageBundles, importCsv, importXlsx, isRecordRemoved, landingOutcomesFor, mapPgError, mapThrownError, markRecordRemoved, markRecordRestored, onRecordChanged, onTableStructureChanged, outcomeForBlock, outputIsKept, parseCsv, predictEnvelopeRefusal, predictSizeRefusal, predictValueRefusals, predictWriteRefusals, primeDoorAnswer, primeRecordPageBundle, primeTablePageBundle, recordingDataSource, seedIndex, seedKey, seededDataSource, staleWriteDetail, supabaseDataSource, tableKindFacts, takePrimedTablePageBundle, toAoa, valuesAreUnconfirmed, wholeValueNotRead, wholeValueOf, wholeValueOfRead, wholeValueSize, withWholeValues };
855
+ export { type BlockOutcome, DEFAULT_DOCUMENT_MAX_BYTES, DEFAULT_VALUE_MAX_BYTES, DOORS, type DoorKey, type ExportRow, Field, LANDING_SOURCE_TYPE, LANDING_TARGET_TYPES, type Landing, type LandingBlock, type LandingOutcomes, type LandingState, type LandingStore, MAPPED_SQLSTATES, type MirrorLimits, OUTPUT_KEPT_KEY, PRIMED_DOOR_TTL_MS, PRODUCED_BY_LABEL, type ParsedImport, PgError, PredictedRefusal, type PrimedBundleAnswer, type ReadFileText, ReadValue, RecordDocument, RecordsDataSource, RecordsError, RecordsResult, type RecordsSeed, type RecordsSeedAnswer, STORE_SCHEMA, StaleWriteDetail, type StoreCaller, type StoreDoorAnswer, type StoreDoorError, type StoreDoors, type SupabaseLike, TableKindFacts, Uuid, WHOLE_VALUE_SOURCE_KIND, type WholeValuePointer, announceRecordChanged, announceTableStructureChanged, archivedOrganizationId, asRecordsDataSource, blockLandedInStore, cellText, doorAbsent, doorCensus, doorExists, doorReady, dropPrimedDoorAnswers, exportCellText, exportCsv, exportMarkdown, exportXlsx, forgetPrimedTablePageBundles, importCsv, importXlsx, isRecordRemoved, landingOutcomesFor, mapPgError, mapThrownError, markRecordRemoved, markRecordRestored, onRecordChanged, onTableStructureChanged, outcomeForBlock, outputIsKept, parseCsv, predictEnvelopeRefusal, predictSizeRefusal, predictValueRefusals, predictWriteRefusals, primeDoorAnswer, primeRecordPageBundle, primeTablePageBundle, recordingDataSource, seedIndex, seedKey, seededDataSource, staleWriteDetail, storeDoors, supabaseDataSource, tableKindFacts, takePrimedTablePageBundle, toAoa, valuesAreUnconfirmed, wholeValueNotRead, wholeValueOf, wholeValueOfRead, wholeValueSize, withWholeValues };
@@ -578,6 +578,95 @@ declare function supabaseDataSource(client: object): RecordsDataSource;
578
578
  */
579
579
  declare function asRecordsDataSource(source: unknown): RecordsDataSource;
580
580
 
581
+ /** The schema every door of the record store lives in. The only place an app-facing string says it. */
582
+ declare const STORE_SCHEMA = "custom";
583
+ /** What a door refused with, as PostgREST gave it. */
584
+ interface StoreDoorError {
585
+ message: string;
586
+ code?: string | null;
587
+ hint?: string | null;
588
+ details?: string | null;
589
+ }
590
+ interface StoreDoorAnswer<T = unknown> {
591
+ data: T | null;
592
+ error: StoreDoorError | null;
593
+ }
594
+ /** The bare caller: the same `rpc(fn, args)` shape the hand-written layers declared. */
595
+ interface StoreCaller {
596
+ rpc(fn: string, args?: Record<string, unknown>): PromiseLike<{
597
+ data: unknown;
598
+ error: StoreDoorError | null;
599
+ }>;
600
+ }
601
+ /** The named doors an app calls most. Every member is a thin call over `rpc`; nothing is added to the answer. */
602
+ interface StoreDoors extends StoreCaller {
603
+ /** `custom.where_id_opens(p_id)` — which organization an object lives in. `data` is null when it is not given to the caller; the error is plain JSON (it streams to a browser as is). */
604
+ whereIdOpens(id: string): PromiseLike<{
605
+ data: unknown;
606
+ error: {
607
+ code: string | null;
608
+ message: string;
609
+ } | null;
610
+ }>;
611
+ /** `custom.table_kernel_id()` — the id of the store's Table kernel (a constant of the store). */
612
+ tableKernelId(): PromiseLike<StoreDoorAnswer<string>>;
613
+ /** `custom.read_records_by_ids` — the records of `ids` the caller may read in `tableId`, in `organizationId`. */
614
+ readRecordsByIds(organizationId: string, tableId: string, ids: readonly string[]): PromiseLike<StoreDoorAnswer>;
615
+ /** `custom.read_records_page` — one page; `args` are the door's own named arguments. */
616
+ readRecordsPage(args: Record<string, unknown>): PromiseLike<StoreDoorAnswer>;
617
+ /** `custom.record_table` — the table a record lives in. */
618
+ recordTable(organizationId: string, recordId: string): PromiseLike<StoreDoorAnswer<string>>;
619
+ /** `custom.applicable_fields` — the fields of a table. */
620
+ applicableFields(organizationId: string, tableId: string): PromiseLike<StoreDoorAnswer>;
621
+ /** `custom.field_declare` — declare one field on a table. */
622
+ fieldDeclare(organizationId: string, tableId: string, spec: Record<string, unknown>): PromiseLike<StoreDoorAnswer<string>>;
623
+ /** `custom.record_update` — patch a record's values. */
624
+ recordUpdate(organizationId: string, recordId: string, patch: Record<string, unknown>): PromiseLike<StoreDoorAnswer>;
625
+ /** `custom.entity_reference_words` — the labels of `{token,id}` refs, withheld when the caller may not open them. */
626
+ entityReferenceWords(organizationId: string, refs: ReadonlyArray<{
627
+ token: string;
628
+ id: string;
629
+ }>): PromiseLike<StoreDoorAnswer>;
630
+ /** `custom.templates` — the catalogue (one page of cards for `filter`). */
631
+ templates(filter: Record<string, unknown>): PromiseLike<StoreDoorAnswer>;
632
+ /** `custom.template_from_tables` — draft a template spec from existing tables. */
633
+ templateFromTables(args: {
634
+ organizationId: string;
635
+ tableIds: readonly string[];
636
+ includeRows: boolean;
637
+ rowsPerTable: number;
638
+ }): PromiseLike<StoreDoorAnswer>;
639
+ /** `custom.template_declare` — declare a template (`scope` is `"org"` for an organization's own). */
640
+ templateDeclare(scope: string, spec: Record<string, unknown>): PromiseLike<StoreDoorAnswer>;
641
+ /** `custom.template_keep` — keep a one-off template in the organization's own. */
642
+ templateKeep(templateId: string): PromiseLike<StoreDoorAnswer>;
643
+ /** `custom.template_archive` — archive (or, with `restore`, bring back) an organization's own template. */
644
+ templateArchive(templateId: string, restore?: boolean): PromiseLike<StoreDoorAnswer>;
645
+ /** `custom.template_install_claim` — the host step's lease on one install step. */
646
+ templateInstallClaim(args: {
647
+ organizationId: string;
648
+ installId: string;
649
+ kind: string;
650
+ label: string;
651
+ sourceId?: string | null;
652
+ leaseSeconds: number;
653
+ }): PromiseLike<StoreDoorAnswer>;
654
+ /** `custom.template_install_note` — record the thing a host step made. */
655
+ templateInstallNote(args: {
656
+ organizationId: string;
657
+ installId: string;
658
+ kind: string;
659
+ id: string;
660
+ label: string;
661
+ }): PromiseLike<StoreDoorAnswer>;
662
+ }
663
+ /**
664
+ * Bind a supabase-js client (browser, server session, anon, or service-role) to the store's
665
+ * doors. A client with no `schema()` is refused by name on every call (`data_source_unbound`), never
666
+ * a thrown `undefined is not a function` in a render.
667
+ */
668
+ declare function storeDoors(client: unknown): StoreDoors;
669
+
581
670
  /** The SQLSTATEs this package claims to understand. Exported for the guard. */
582
671
  declare const MAPPED_SQLSTATES: string[];
583
672
  /** Map a PostgREST/supabase-js failure into the package's refusal shape. */
@@ -763,4 +852,4 @@ declare function seededDataSource(index: Map<string, unknown>): {
763
852
  missed: () => boolean;
764
853
  };
765
854
 
766
- export { type BlockOutcome, DEFAULT_DOCUMENT_MAX_BYTES, DEFAULT_VALUE_MAX_BYTES, DOORS, type DoorKey, type ExportRow, Field, LANDING_SOURCE_TYPE, LANDING_TARGET_TYPES, type Landing, type LandingBlock, type LandingOutcomes, type LandingState, type LandingStore, MAPPED_SQLSTATES, type MirrorLimits, OUTPUT_KEPT_KEY, PRIMED_DOOR_TTL_MS, PRODUCED_BY_LABEL, type ParsedImport, PgError, PredictedRefusal, type PrimedBundleAnswer, type ReadFileText, ReadValue, RecordDocument, RecordsDataSource, RecordsError, RecordsResult, type RecordsSeed, type RecordsSeedAnswer, StaleWriteDetail, type SupabaseLike, TableKindFacts, Uuid, WHOLE_VALUE_SOURCE_KIND, type WholeValuePointer, announceRecordChanged, announceTableStructureChanged, archivedOrganizationId, asRecordsDataSource, blockLandedInStore, cellText, doorAbsent, doorCensus, doorExists, doorReady, dropPrimedDoorAnswers, exportCellText, exportCsv, exportMarkdown, exportXlsx, forgetPrimedTablePageBundles, importCsv, importXlsx, isRecordRemoved, landingOutcomesFor, mapPgError, mapThrownError, markRecordRemoved, markRecordRestored, onRecordChanged, onTableStructureChanged, outcomeForBlock, outputIsKept, parseCsv, predictEnvelopeRefusal, predictSizeRefusal, predictValueRefusals, predictWriteRefusals, primeDoorAnswer, primeRecordPageBundle, primeTablePageBundle, recordingDataSource, seedIndex, seedKey, seededDataSource, staleWriteDetail, supabaseDataSource, tableKindFacts, takePrimedTablePageBundle, toAoa, valuesAreUnconfirmed, wholeValueNotRead, wholeValueOf, wholeValueOfRead, wholeValueSize, withWholeValues };
855
+ export { type BlockOutcome, DEFAULT_DOCUMENT_MAX_BYTES, DEFAULT_VALUE_MAX_BYTES, DOORS, type DoorKey, type ExportRow, Field, LANDING_SOURCE_TYPE, LANDING_TARGET_TYPES, type Landing, type LandingBlock, type LandingOutcomes, type LandingState, type LandingStore, MAPPED_SQLSTATES, type MirrorLimits, OUTPUT_KEPT_KEY, PRIMED_DOOR_TTL_MS, PRODUCED_BY_LABEL, type ParsedImport, PgError, PredictedRefusal, type PrimedBundleAnswer, type ReadFileText, ReadValue, RecordDocument, RecordsDataSource, RecordsError, RecordsResult, type RecordsSeed, type RecordsSeedAnswer, STORE_SCHEMA, StaleWriteDetail, type StoreCaller, type StoreDoorAnswer, type StoreDoorError, type StoreDoors, type SupabaseLike, TableKindFacts, Uuid, WHOLE_VALUE_SOURCE_KIND, type WholeValuePointer, announceRecordChanged, announceTableStructureChanged, archivedOrganizationId, asRecordsDataSource, blockLandedInStore, cellText, doorAbsent, doorCensus, doorExists, doorReady, dropPrimedDoorAnswers, exportCellText, exportCsv, exportMarkdown, exportXlsx, forgetPrimedTablePageBundles, importCsv, importXlsx, isRecordRemoved, landingOutcomesFor, mapPgError, mapThrownError, markRecordRemoved, markRecordRestored, onRecordChanged, onTableStructureChanged, outcomeForBlock, outputIsKept, parseCsv, predictEnvelopeRefusal, predictSizeRefusal, predictValueRefusals, predictWriteRefusals, primeDoorAnswer, primeRecordPageBundle, primeTablePageBundle, recordingDataSource, seedIndex, seedKey, seededDataSource, staleWriteDetail, storeDoors, supabaseDataSource, tableKindFacts, takePrimedTablePageBundle, toAoa, valuesAreUnconfirmed, wholeValueNotRead, wholeValueOf, wholeValueOfRead, wholeValueSize, withWholeValues };
@@ -10731,6 +10731,58 @@ function blockLandedInStore(outcomes, block) {
10731
10731
  return false;
10732
10732
  }
10733
10733
 
10734
+ // src/core/storeDoors.ts
10735
+ var STORE_SCHEMA = "custom";
10736
+ function storeDoors(client) {
10737
+ const source = supabaseDataSource(client ?? {});
10738
+ const call = (fn, args = {}) => source.rpc(fn, args, { schema: STORE_SCHEMA });
10739
+ const typed = (fn, args) => call(fn, args);
10740
+ return {
10741
+ rpc: call,
10742
+ async whereIdOpens(id) {
10743
+ const raw = await call("where_id_opens", { p_id: id });
10744
+ const e = raw.error;
10745
+ return {
10746
+ data: raw.data ?? null,
10747
+ error: e ? { code: typeof e.code === "string" ? e.code : null, message: typeof e.message === "string" ? e.message : "The record store refused." } : null
10748
+ };
10749
+ },
10750
+ tableKernelId: () => typed("table_kernel_id", {}),
10751
+ readRecordsByIds: (organizationId, tableId, ids) => typed("read_records_by_ids", { p_organization_id: organizationId, p_table_id: tableId, p_record_ids: ids }),
10752
+ readRecordsPage: (args) => typed("read_records_page", args),
10753
+ recordTable: (organizationId, recordId) => typed("record_table", { p_organization_id: organizationId, p_record_id: recordId }),
10754
+ applicableFields: (organizationId, tableId) => typed("applicable_fields", { p_organization_id: organizationId, p_table_id: tableId }),
10755
+ fieldDeclare: (organizationId, tableId, spec) => typed("field_declare", { p_organization_id: organizationId, p_table_id: tableId, p_spec: spec }),
10756
+ recordUpdate: (organizationId, recordId, patch) => typed("record_update", { p_organization_id: organizationId, p_record_id: recordId, p_patch: patch }),
10757
+ entityReferenceWords: (organizationId, refs) => typed("entity_reference_words", { p_organization_id: organizationId, p_refs: refs.map((r) => ({ token: r.token, id: r.id })) }),
10758
+ templates: (filter) => typed("templates", { p_filter: filter }),
10759
+ templateFromTables: ({ organizationId, tableIds, includeRows, rowsPerTable }) => typed("template_from_tables", {
10760
+ p_organization_id: organizationId,
10761
+ p_table_ids: tableIds,
10762
+ p_include_rows: includeRows,
10763
+ p_rows_per_table: rowsPerTable
10764
+ }),
10765
+ templateDeclare: (scope, spec) => typed("template_declare", { p_scope: scope, p_spec: spec }),
10766
+ templateKeep: (templateId) => typed("template_keep", { p_template_id: templateId }),
10767
+ templateArchive: (templateId, restore) => typed("template_archive", restore === void 0 ? { p_template_id: templateId } : { p_template_id: templateId, p_restore: restore }),
10768
+ templateInstallClaim: ({ organizationId, installId, kind, label, sourceId, leaseSeconds }) => typed("template_install_claim", {
10769
+ p_organization_id: organizationId,
10770
+ p_install_id: installId,
10771
+ p_kind: kind,
10772
+ p_label: label,
10773
+ ...sourceId ? { p_source_id: sourceId } : {},
10774
+ p_lease_seconds: leaseSeconds
10775
+ }),
10776
+ templateInstallNote: ({ organizationId, installId, kind, id, label }) => typed("template_install_note", {
10777
+ p_organization_id: organizationId,
10778
+ p_install_id: installId,
10779
+ p_kind: kind,
10780
+ p_id: id,
10781
+ p_label: label
10782
+ })
10783
+ };
10784
+ }
10785
+
10734
10786
  // src/core/validation.ts
10735
10787
  import { isUuidShape as isUuidShape6 } from "@ai-matrx/kit/uuid";
10736
10788
  var DEFAULT_VALUE_MAX_BYTES = 1e5;
@@ -11350,6 +11402,7 @@ export {
11350
11402
  STORE_DOORS,
11351
11403
  STORE_KNOBS,
11352
11404
  STORE_REFUSAL_CODES,
11405
+ STORE_SCHEMA,
11353
11406
  SYSTEM_WRITER_WORDS,
11354
11407
  TABLE_DISPLAYS,
11355
11408
  TABLE_KIND_PREFIX,
@@ -11543,6 +11596,7 @@ export {
11543
11596
  stableFilterKey,
11544
11597
  staleWriteDetail,
11545
11598
  statusGroupOf,
11599
+ storeDoors,
11546
11600
  supabaseDataSource,
11547
11601
  tableIdOf,
11548
11602
  tableJsonSchema,