import { U as Uuid, j as RecordsError } from './record-C3thPhpR.js'; import { a as FieldTypeWord, u as NewFieldDeclaration } from './field-IlJ97y8H.js'; import './ports-uIDHLgZN.js'; import { F as FieldDrift, R as RecordsClient } from './client-C3U4B-hT.js'; /** One Field a person asked for, in the words a person uses (FLD-1 / FLD-11). */ interface NewFieldSpec { key: string; label: string; /** * The word for what this column holds — any word `custom._field_document_for` * resolves for `type` (a parity type, a behavior, a plain synonym, or a kind * such as `signature`, `relation`, `entity_reference`, `autonumber`). It is * sent to the door as `type`, unmapped; a word that means nothing is refused * by name, with the list. */ type: FieldTypeWord; sort?: number; required?: boolean; multi?: boolean; config?: Record; /** A choice list's choices, as words. The store keeps them as a Table (FLD-5). */ options?: string[]; /** A column that points at another Table of this organization (FLD-11 / REL-8). */ relationTarget?: Uuid; /** A currency column's symbol; a date column's day-or-day-and-time. */ unit?: string; kind?: "date" | "datetime"; /** * An `entity_reference` column's kinds: the platform entity tokens it may point * at (`ai_model`, `note`, `web_site` …; `custom.entity_reference_kinds()` lists * them). The store refuses an entity reference that names none. */ allowedTypes?: string[]; /** * No two live records may hold the same value here (a `unique` Rule, FLD-3 / B1). A column * `recordUpsert` finds a record by must carry it. */ unique?: boolean; /** * An EXISTING choice list's Table — the column uses those very option records instead of making a * new list (a drafts table copying its source table's column keeps the same choices). Sent as * `config.options_table_id`. */ optionsTableId?: Uuid; /** * Anything else `custom.field_declare` accepts, passed through verbatim and applied LAST (a stored * Field document copied key for key, `format`, `sensitivity`, `via` / `pick` / `agg` / `of`, …). * The store judges every key; a word it does not take is refused by name. */ declaration?: Partial & Record; } interface NewTableSpec { name: string; /** The token the Table is addressed by. Derived from the name when absent. */ slug?: string; labelSingular?: string; labelPlural?: string; /** The Field whose value is the record's title (REC-2). Defaults to the first Field. */ titleField?: string; fields?: NewFieldSpec[]; /** * `ensureTable` only: put a NEW table in this existing Home (one the caller may change, in this * organization) instead of making a Home for it. A table that already exists stays where it is. */ homeId?: Uuid; /** SC-1 placement: the app (one of its features) keeps this table, not the organization. */ platformOwned?: boolean; /** * WHICH feature keeps it, one lower-case word (`agent_output`, `context`, …). `ensureTable` finds a * table by slug AND this word: a person's table of the same slug is a different table. */ keptFor?: string; /** The content kind whose outputs this table holds. */ kind?: string; /** A drafts table: the Table its records are drafts of. */ draftsFor?: Uuid; /** A drafts table: that Table's stamp when the drafts table last matched it. */ draftsStamp?: string; /** * An TYPED TABLE's declaration facts (`defineTypedTable`, `@ai-matrx/records/typed-table`): scope, owner, * gate reason, review date and spec hash, stored on the Table document as `app_table`. Written * when the table is born; an existing table keeps the block it was born with. */ typedTable?: Record; /** * THE APP'S CODE DEPENDS ON THIS TABLE (`code_depends: true` on its document; lane 12 P5). The * store then refuses archiving, renaming (slug or kept_for), moving or unmarking it through every * door; the one way through is `archiveTypedTableDeliberately`. `ensureTable` writes it on birth and * merges it onto an existing table that lacks it. Only an typed-table spec (`typedTable`) carries it. */ codeDepends?: boolean; /** * `ensureTable` only, on BIRTH: what a new row starts with, set through * `custom.table_row_defaults_set` (e.g. `{ shown_to: "only_me" }` — hidden from other people's * lists, never locked). A table that already exists keeps its own. */ rowDefaults?: { shown_to?: "only_me" | "my_team" | "everyone" | null; }; /** * `ensureTable` only, on BIRTH: every member of the organization reaches the new table at this * level (`custom.share_lane_set(…, 'organization', level)`), so members can add rows to a table * one of them made first. A table that already exists keeps its own sharing. */ membersReach?: "viewer" | "commenter" | "editor"; } /** * What `ensureTable` answers: `declareTable`'s answer, plus whether this call MADE the table and * how the columns it already had differ from the spec (`drift`, reported and never applied — see * `FieldDrift`). `drift` is `[]` on a birth and when nothing differs. */ type EnsureResult = { ok: true; data: Uuid; homeId: Uuid; created: boolean; drift: FieldDrift[] | null; } | { ok: false; error: RecordsError; }; type DeclareResult = /** * The Table's id — and its HOME's, because REC-14 gives the Table exactly one * and the caller that made it is the only one that can tidy it up again. A * caller reading `data` alone is unaffected. */ { ok: true; data: Uuid; homeId: Uuid; } | { ok: false; error: RecordsError; }; /** `My Sales Pipeline` → `my_sales_pipeline`. A token, never a sentence. */ declare function tokenFor(name: string): string; /** The one Field a Table cannot be declared without: something to call a record. */ /** * WHY THE FIRST FIELD IS NOT REQUIRED. * * It was, and the cost showed up the moment the grid could add a row: "New * record" writes an empty record and puts you in the first cell, and the store * correctly refused every one of them — `REC-51: Title is required` — so the * one gesture that makes a grid feel like a grid never worked on a table a * person had just made. A title is what makes a record a CHIP (REC-2), which is * a fact about how it is shown, not a promise it can never be written without; * an organization that wants it demanded says so in the field editor, and the * store then enforces it for everyone. */ declare const DEFAULT_FIELDS: NewFieldSpec[]; /** * One column, in the shape `custom.field_declare` takes — and EVERYTHING a * person said about it. The keys after the type are not decoration: without * `options` the door refuses a choice list outright ("A list of choices needs * its choices"), without `unit` a money column is dollars whatever the person * picked, and without `relation_target` a column that points at another of this * organization's own tables cannot be declared at all. */ declare function fieldDeclarationFor(field: NewFieldSpec): NewFieldDeclaration; /** * FIND THIS TABLE BY ITS SLUG, OR MAKE IT — the birth a PAGE uses (lane PLATFORM-APP-DATA). * * `declareTable` is a person's "Create table": it always makes a new one. A page that keeps its * own data ("the front desk's callback log") needs the opposite — THE table of that address, * made the first time and found every time after — and the hand-written version of that * (list every table, search, then declare) made two tables when two tabs saved first at once. * `custom.table_ensure` does the find and the make in ONE transaction under a lock on * (organization, slug), so both callers get the same table; a second call adds any column the * spec names that the table does not have yet and never retypes or drops one. * * Same answer shape as `declareTable` (the Table's id and its Home's) plus `created` and `drift`: * every column the table already had whose stored type, format, label, multi, required or unique * differs from the spec — reported, never applied. On a store without the * door it is `door_absent`, never a fallback to the racing walk. */ declare function ensureTable(client: RecordsClient, spec: NewTableSpec): Promise; declare function declareTable(client: RecordsClient, spec: NewTableSpec): Promise; /** * Columns for an existing Table, through the door that declares one. Used by * the create path and by import. * * A column the store refused STOPS the sequence and hands back the store's own * sentence: a Table that quietly lost a column is the silent failure this * package exists to prevent. */ declare function addFields(client: RecordsClient, tableId: Uuid, fields: NewFieldSpec[]): Promise<{ ok: true; data: Uuid; } | { ok: false; error: RecordsError; }>; export { DEFAULT_FIELDS as D, addFields as c, declareTable as d, ensureTable as e, fieldDeclarationFor as f, tokenFor as t }; export type { EnsureResult as E, NewFieldSpec as N, DeclareResult as a, NewTableSpec as b };