{"version":3,"sources":["../src/backend/table-contribution.ts"],"names":[],"mappings":";;;AA+CO,IAAM,0BAAA,GAA6B;AAGnC,IAAM,uBAAA,GAA0B;AAMhC,IAAM,gCAAA,GAAmC","file":"chunk-4YMHXGA6.cjs","sourcesContent":["/**\n * Unified table-contribution contract (#129).\n *\n * Every table TypeGraph owns — whether modeled as a Drizzle table or\n * emitted as strategy-owned raw DDL — is described by a single\n * {@link TableContribution} shape. This is the one place that answers\n * \"what tables does this backend/strategy own?\", replacing the\n * previously split surfaces (Drizzle named exports, tables-factory\n * recursion, strategy raw DDL, per-table `ensureXTable` methods).\n *\n * Lives in the neutral `backend/` layer (sibling of `backend/types.ts`,\n * which `query/dialect` already depends on) and is deliberately\n * Drizzle-free, so declaring contributions does not pull the concrete\n * Drizzle backend runtime into the query/dialect layer.\n *\n * ## Identity vs. signature (prerequisite for #135)\n *\n * #135 (durable fulltext/contribution materialization) needs to make\n * \"not materialized\" vs. \"materialized but stale\" a decidable, durable\n * fact instead of an in-memory per-backend latch. That requires two\n * conceptually separate things, and #129's job is only to make both\n * *derivable* from the contract:\n *\n * - **Materialization identity** — `owner` + `logicalName` +\n *   resolved physical `tableName`. Keying on `logicalName` alone is\n *   insufficient: custom per-deployment table names must be\n *   distinguishable, otherwise two deployments with different physical\n *   names would collide on one durable marker. (#135 additionally\n *   scopes this by `graphId` at persistence time.)\n * - **Drift signature** — a hash of the strategy identity/version,\n *   the resolved table name(s), and the normalized `createDdl`. #129\n *   guarantees `createDdl` is deterministic for a given resolved\n *   configuration so the hash #135 computes is meaningful.\n *\n * The signature is intentionally **not** eagerly carried on the\n * contribution: hashing is async (Web Crypto, see `utils/hash`) and\n * #135 already owns signature persistence the same way\n * `materializeIndexes` does for declared indexes.\n */\n\n/**\n * `logicalName` of the strategy-owned fulltext slot. Used as a logic\n * discriminant (latch routing, runtime-ensure) across the strategies\n * and both backends — a shared constant so a strategy declaring a\n * different name fails loudly at the call site instead of silently\n * skipping the latched fulltext path.\n */\nexport const FULLTEXT_CONTRIBUTION_NAME = \"fulltext\";\n\n/** `owner` of core/base schema tables (not strategy-owned). */\nexport const BASE_CONTRIBUTION_OWNER = \"base\";\n\n/** Ownership scope for a strategy-owned physical contribution. */\nexport type ContributionScope = \"deployment\" | \"graph\";\n\n/** Durable-marker key used for deployment-scoped physical contributions. */\nexport const DEPLOYMENT_CONTRIBUTION_GRAPH_ID = \"__typegraph_deployment__\";\n\n/**\n * A single table TypeGraph owns.\n */\nexport type TableContribution = Readonly<{\n  /**\n   * Whether physical storage is shared by the deployment or owned by one\n   * graph. Omitted by older custom strategies, which retain graph scope.\n   */\n  scope?: ContributionScope;\n  /**\n   * Stable, graph- and deployment-independent identity for the logical\n   * slot this contribution fills (e.g. `\"fulltext\"`). NOT the physical\n   * table name. Stable across table-name overrides and across strategy\n   * swaps of the *same* logical slot, so #135's durable marker can\n   * survive both.\n   */\n  logicalName: string;\n  /**\n   * Identifies the producer of this contribution (e.g. a strategy id\n   * like `\"tsvector\"` / `\"fts5\"`, or `\"base\"` for core schema tables).\n   * Part of the #135 materialization identity and an input to the\n   * drift signature — a strategy swap on the same `logicalName` is a\n   * legitimate, detectable drift, not a silent reuse.\n   */\n  owner: string;\n  /**\n   * Resolved physical table name after any per-deployment name\n   * override. Part of the #135 materialization identity (custom names\n   * must be distinguishable) and used by diagnostics / the focused\n   * bootstrap ensure.\n   */\n  tableName: string;\n  /**\n   * Idempotent (`CREATE ... IF NOT EXISTS`) statements that\n   * materialize this contribution's table **and its supporting\n   * indexes**. Running the full list is how the runtime ensure\n   * self-heals partial states (table present, index missing) — it is\n   * not a probe-and-skip. Deterministic for a given resolved\n   * configuration: the canonical normalized input to #135's drift\n   * signature.\n   */\n  createDdl: readonly string[];\n  /**\n   * Idempotent (`DROP ... IF EXISTS`) statements that tear this\n   * contribution's storage down, ordered so that running the list\n   * leaves nothing behind. Declaring it is what makes a contribution\n   * *rebuildable*: the destructive\n   * `store.rebuildContribution()` path drops through these statements\n   * before re-running {@link createDdl}, which is the only repair for a\n   * table provisioned at a shape the current `createDdl` no longer\n   * produces.\n   *\n   * Optional because it is a capability, not an invariant. A\n   * contribution whose content cannot be reconstructed from data\n   * TypeGraph already stores has no business advertising a rebuild —\n   * dropping it would destroy the only copy — and a third-party\n   * strategy that predates this field keeps compiling and is reported\n   * as not rebuildable rather than silently rebuilt through a\n   * synthesized `DROP`. Backends surface the resulting gap as\n   * `capabilities.contributions.rebuild`.\n   *\n   * The rebuild visits a strategy's `runtimeEnsure` contributions, the\n   * same set the boot ensure provisions — so a companion table a strategy\n   * declares outside that set is neither dropped nor recreated, and must\n   * not be something the recreated storage depends on.\n   */\n  dropDdl?: readonly string[];\n  /**\n   * When `true`, the post-schema-load focused ensure\n   * (`loadActiveSchemaWithBootstrap`) materializes this contribution\n   * on every successful schema load.\n   *\n   * **Invariant: only strategy-declared contributions may set this.**\n   * Core/base tables are always `false` — they are created by\n   * drizzle-kit / `bootstrapTables`. This is what lets the boot path\n   * derive runtime contributions straight from the strategy\n   * (`fulltextStrategy.ownedTables`) without walking — and generating\n   * DDL for — every base table.\n   */\n  runtimeEnsure: boolean;\n}>;\n\n/**\n * A table a {@link FulltextStrategy} declares it owns. An alias, not a\n * distinct shape: a strategy's declaration is already authoritative\n * (no resolution step). The name documents the producer role.\n */\nexport type StrategyTableContribution = TableContribution;\n"]}