@palbase/backend 33.0.2 → 34.0.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.
Files changed (81) hide show
  1. package/dist/bin/palbase-backend.cjs +2020 -350
  2. package/dist/bin/palbase-backend.cjs.map +1 -1
  3. package/dist/bin/palbase-backend.js +9 -7
  4. package/dist/bin/palbase-backend.js.map +1 -1
  5. package/dist/{chunk-SI4KGEM3.js → chunk-FOWA7PF4.js} +97 -96
  6. package/dist/chunk-FOWA7PF4.js.map +1 -0
  7. package/dist/chunk-GHNC2UHS.js +20 -0
  8. package/dist/chunk-GHNC2UHS.js.map +1 -0
  9. package/dist/{chunk-AAT5G7KY.js → chunk-JJW3L62T.js} +2 -2
  10. package/dist/chunk-JJW3L62T.js.map +1 -0
  11. package/dist/{chunk-TVCCR6SO.js → chunk-LOGL2ZHD.js} +58 -9
  12. package/dist/chunk-LOGL2ZHD.js.map +1 -0
  13. package/dist/{chunk-C6COAB3E.js → chunk-MNGZE2MM.js} +1651 -186
  14. package/dist/chunk-MNGZE2MM.js.map +1 -0
  15. package/dist/{chunk-XOX6RFPZ.js → chunk-PRH45NZU.js} +46 -3
  16. package/dist/chunk-PRH45NZU.js.map +1 -0
  17. package/dist/{chunk-26GH54D2.js → chunk-RZLY4BOY.js} +5 -3
  18. package/dist/{chunk-26GH54D2.js.map → chunk-RZLY4BOY.js.map} +1 -1
  19. package/dist/{chunk-YIQ4RS4F.js → chunk-SEM36BWY.js} +283 -5
  20. package/dist/chunk-SEM36BWY.js.map +1 -0
  21. package/dist/{chunk-KATPXCJ5.js → chunk-UMESJJRS.js} +19 -40
  22. package/dist/chunk-UMESJJRS.js.map +1 -0
  23. package/dist/chunk-VXPNPVAG.js +40 -0
  24. package/dist/chunk-VXPNPVAG.js.map +1 -0
  25. package/dist/{chunk-WWUG2QXF.js → chunk-YX7UA7VC.js} +53 -4
  26. package/dist/chunk-YX7UA7VC.js.map +1 -0
  27. package/dist/db/env.cjs.map +1 -1
  28. package/dist/db/env.d.cts +2 -0
  29. package/dist/db/env.d.ts +2 -0
  30. package/dist/db/index.cjs +261 -2
  31. package/dist/db/index.cjs.map +1 -1
  32. package/dist/db/index.d.cts +46 -3
  33. package/dist/db/index.d.ts +46 -3
  34. package/dist/db/index.js +14 -5
  35. package/dist/{index-DMZG3kpo.d.ts → endpoint-DpNUx-ON.d.ts} +315 -57
  36. package/dist/{index-DB_nW-AV.d.cts → endpoint-kYgEHrrV.d.cts} +315 -57
  37. package/dist/engine/index.cjs +2026 -348
  38. package/dist/engine/index.cjs.map +1 -1
  39. package/dist/engine/index.d.cts +5 -5
  40. package/dist/engine/index.d.ts +5 -5
  41. package/dist/engine/index.js +17 -7
  42. package/dist/{index-D-3duy8Y.d.ts → index-JrHqNsjQ.d.ts} +108 -50
  43. package/dist/{index-DLveQoOf.d.cts → index-pnDsEfxJ.d.cts} +108 -50
  44. package/dist/index.cjs +616 -254
  45. package/dist/index.cjs.map +1 -1
  46. package/dist/index.d.cts +7 -6
  47. package/dist/index.d.ts +7 -6
  48. package/dist/index.js +25 -15
  49. package/dist/index.js.map +1 -1
  50. package/dist/openapi/index.cjs +7 -0
  51. package/dist/openapi/index.cjs.map +1 -1
  52. package/dist/openapi/index.d.cts +3 -3
  53. package/dist/openapi/index.d.ts +3 -3
  54. package/dist/openapi/index.js +4 -3
  55. package/dist/openapi/index.js.map +1 -1
  56. package/dist/{registry-DSTThhKf.d.cts → registry-BcOd8Zhf.d.cts} +3 -1
  57. package/dist/{registry-JjF5lcj4.d.ts → registry-BoX5iNyY.d.ts} +3 -1
  58. package/dist/test/index.cjs +103 -66
  59. package/dist/test/index.cjs.map +1 -1
  60. package/dist/test/index.d.cts +3 -3
  61. package/dist/test/index.d.ts +3 -3
  62. package/dist/test/index.js +33 -7
  63. package/dist/test/index.js.map +1 -1
  64. package/docs/README.md +1 -1
  65. package/docs/database.md +308 -0
  66. package/docs/examples/check-query-contracts.ts +5 -0
  67. package/docs/examples/database-dx.contract.json +65 -0
  68. package/docs/examples/database-dx.ts +63 -0
  69. package/docs/examples/money-transfer.ts +73 -0
  70. package/docs/llms-full.txt +309 -1
  71. package/package.json +1 -2
  72. package/template/package.json +1 -1
  73. package/dist/chunk-AAT5G7KY.js.map +0 -1
  74. package/dist/chunk-C6COAB3E.js.map +0 -1
  75. package/dist/chunk-KATPXCJ5.js.map +0 -1
  76. package/dist/chunk-SI4KGEM3.js.map +0 -1
  77. package/dist/chunk-TVCCR6SO.js.map +0 -1
  78. package/dist/chunk-WWUG2QXF.js.map +0 -1
  79. package/dist/chunk-XOX6RFPZ.js.map +0 -1
  80. package/dist/chunk-YIQ4RS4F.js.map +0 -1
  81. package/stack-images.json +0 -24
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/db/schema.ts","../src/db/policy.ts","../src/db/extensions.ts","../src/db/raw.ts","../src/db/embedding.ts"],"sourcesContent":["import type { ColumnBuilder } from \"./columns.js\";\nimport { qualifiedTableKey } from \"./schema-json.js\";\nimport { PolicyBuilder, exprCtx } from \"./policy.js\";\nimport type { PolicyDef, PolicyExprCtx, PolicyExpr, PolicyExprRef } from \"./policy.js\";\nimport type { PalbaseExtension } from \"./extensions.js\";\nimport type { RawConstraintDef } from \"./raw.js\";\nimport type { ChatModelRef, EmbeddingModelRef } from \"./embedding.js\";\n\n/**\n * A map of column builders keyed by column name — the value you write under\n * the `columns` key of `defineTable(\"<name>\", { columns })`.\n *\n * The default `Record<string, ColumnBuilder>` keeps bare references compiling\n * without a type argument.\n */\nexport type ColumnMap = Record<string, ColumnBuilder>;\n\n/**\n * The author-facing value written under each table key:\n * `{ columns, rls?, policies? }`.\n *\n * - `columns`: the column map (required).\n * - `rls`: enable + FORCE row-level security on this table. **Defaults to\n * `true`**, and is forced on when `policies` is non-empty. A table with RLS\n * and no policies is deny-all, which is the starting state: nothing reads it\n * until a policy says who may. Set `rls: false` only for a genuinely public\n * table — it is an explicit opt-out that a reviewer can grep for, not\n * something you get by forgetting.\n * - `policies`: the RLS policies for this table, authored with `policy(name)`.\n * Each entry may be a {@link PolicyBuilder} (the normal `policy(...)` chain)\n * or a raw {@link PolicyDef} object.\n *\n * The `C` type parameter preserves the precise per-column phantom types so the\n * typed `Database.public.*` surface keeps inferring insert/row shapes.\n */\n/** Arama metriği — tek kelime; opclass ve operatör bundan türetilir, asla yüzeye çıkmaz (D-5/D-6). */\nexport type SearchMetric = \"cosine\" | \"euclidean\" | \"inner_product\";\n\n/** Bir vektör arama kolu. `model` varsa auto-embed: platform yazma+sorgu embedding'ini üstlenir (D-9). */\nexport interface VectorSearchDecl {\n /** Hedef vector kolonu; tabloda TEK vector kolonu varsa atlanabilir (Go apply çözer, FR-010). */\n column?: string;\n /** Varsa auto-embed. Deskriptor düz veridir — şemayla serileşir (C-3). */\n model?: EmbeddingModelRef;\n /** model varsa ZORUNLU: embed kaynak kolonları = trigger'ın UPDATE OF listesi (C-2). */\n from?: string[];\n metric?: SearchMetric;\n /** Kaynak metin değişince ara-dönem davranışı (yalnız auto-embed'de):\n * \"null\" (vars.) — embedding anında NULL'lanır; satır yeni vektör yazılana\n * dek anlamsal aramada aday değildir. Bayat eşleşme asla servis edilmez.\n * \"keep\" — eski vektör aramada kalır, platform yenisini yazınca sessizce\n * değişir. Görünürlük penceresi sıfır; bedeli saniyeler süren bayat\n * eşleşme riski (Confluence-tipi sync yükleri için). */\n staleness?: \"null\" | \"keep\";\n}\n\n/** Tablonun arama beyanı — İKİ biçim (D-007, tek yüzey):\n *\n * YENİ (önerilen): `{ from, model, ... }` — `from` kolonları hem FTS'e hem\n * embed'e girer. Tabloda vector kolonu declare edilmişse SATIR-modu; yoksa\n * CHUNK-modu otomatiktir (D-010): vektörler türev `__palbase_chunks`\n * tablosunda yaşar, içerik otomatik bölünür. `text: false` FTS'i kapatır,\n * `text: [..]` FTS kolonlarını from'dan ayırır. `chunks` yalnız ince ayar.\n *\n * ESKİ: `text: string[]` + `vector: {...}` — aynen çalışır, wire çıktısı\n * bayt-aynı kalır (NFR-B1). İki biçim KARIŞTIRILAMAZ. */\nexport interface SearchDecl {\n text?: string[] | boolean;\n vector?: VectorSearchDecl | VectorSearchDecl[];\n /** Yeni biçim: arama kaynağı kolonlar (FTS + embed). Varlığı yeni biçimi seçer. */\n from?: string[];\n /** Yeni biçim: auto-embed modeli (zorunlu — BYO için eski biçimi kullanın). */\n model?: EmbeddingModelRef;\n metric?: SearchMetric;\n staleness?: \"null\" | \"keep\";\n /** Chunk-modu ince ayarı (yalnız vector kolonsuz tabloda anlamlı). */\n chunks?: { size?: number; overlap?: number };\n /** Sorgu-yeniden-yazımı: tek yönlü eş anlamlı haritası (FR-026). */\n synonyms?: Record<string, string[]>;\n /** Geçerlilik kolonları türetilir; arama varsayılan yalnız günceli tarar (FR-029). */\n validity?: boolean;\n}\n\n/** Hafıza beyanı (FR-032, D-019): kaynak tablonun yazımlarından platform\n * fact damıtır ve `into` tablosuna yazar. Hedef NORMAL declared tablodur —\n * kendi search/unique/validity beyanlarıyla. Okuma = Database.$search(into).\n * subject default \"owner\": fact'in kime ait olduğu kolonu (iki tabloda da). */\nexport interface MemoryDecl {\n from: string[];\n into: string;\n extract: ChatModelRef;\n subject?: string;\n}\n\n/**\n * Bir index bildiriminin girdi şekli (FR-041…043).\n *\n * `columns` ile `expression` birbirinin alternatifidir: biri kolon listesi,\n * diğeri `lower(email)` gibi bir ifade. `where` partial index koşuludur ve\n * filtre şekli sorgu tarafındaki `WhereFilter` ile aynıdır — iki ayrı filtre\n * dili olmaz.\n */\n/**\n * Bir index'in TEL şekli — `IndexJSON` ile aynı alanlar (T002).\n *\n * Bildirilmeyen alan HİÇ yazılmaz: sıfır değer yazmak, bildirmeyen her index'i\n * diff'te değişmiş gösterir ve her deploy'a boş bir migration ekler.\n */\nexport interface IndexDef {\n name: string;\n columns?: string[];\n expression?: string;\n where?: PolicyExpr;\n sort?: \"asc\" | \"desc\";\n nulls?: \"first\" | \"last\";\n include?: string[];\n}\n\n/**\n * `index(\"<ad>\")` — C-5 (FR-041…043).\n *\n * ```ts\n * indexes: (c) => [\n * index(\"orders_open\")\n * .on(c.col(\"status\")) // kolon TİPLİ\n * .where(c.col(\"deleted_at\").isNull()) // partial\n * .include([\"total\"]), // covering\n * ]\n * ```\n *\n * `policy()` ile AYNI dili konuşur: `where` politika ifade yapısının ta kendisi.\n * Üçüncü bir filtre lehçesi açmak, aynı sorunun iki yazımı demekti.\n *\n * Kolon bağlamı callback'ten geliyor çünkü index tablo tanımının İÇİNDE\n * bildiriliyor — `orders.status` yazmak, `orders` bağlaması o noktada henüz\n * kurulmadığı için mümkün değil (T015'te `policies` için ölçülen aynı kısıt).\n */\nexport class IndexBuilder {\n readonly _def: IndexDef;\n\n constructor(name: string) {\n if (name.trim() === \"\") {\n throw new Error(\"index(ad): index'in adı boş olamaz — Palbase index'leri ADA göre uzlaştırır.\");\n }\n this._def = { name };\n }\n\n /** Index'in kolonları. SIRA KORUNUR — çok kolonlu bir index'in anlamı sırasıdır. */\n on(...cols: PolicyExprRef[]): this {\n this._def.columns = cols.map((c) => {\n const e = c.expr;\n if (e.kind !== \"col\") {\n throw new Error(`index(${this._def.name}).on(): yalnız kolon referansı alır — ifade için onExpression(\"…\") kullanın.`);\n }\n return e.name;\n });\n return this;\n }\n\n /**\n * İfade index'i (`lower(email)`), kolon yerine.\n *\n * Metin VERBATIM emit ediliyor — `policy().using(\"…\")` ile aynı güven duruşu.\n * Tipli yapı bunu ifade edemiyor ve kaçış kapağını kapatmak, yazarı elle\n * migration yazmaya iterdi.\n */\n onExpression(expr: string): this {\n this._def.expression = expr;\n return this;\n }\n\n /** Partial index koşulu — politika ifade dilinin ta kendisi. */\n where(expr: PolicyExprRef): this {\n this._def.where = expr.expr;\n return this;\n }\n\n /** Sıra. Tek yönlü index'te sıra genelde önemsizdir; ORDER BY ile eşleşen\n * bir index arandığında değildir. */\n desc(): this {\n this._def.sort = \"desc\";\n return this;\n }\n\n asc(): this {\n this._def.sort = \"asc\";\n return this;\n }\n\n /** NULL'ların yeri — `ORDER BY … NULLS LAST` ile eşleşmesi için. */\n nulls(where: \"first\" | \"last\"): this {\n this._def.nulls = where;\n return this;\n }\n\n /** Covering index (`INCLUDE`): index-only scan için taşınan ama\n * ARANMAYAN kolonlar. */\n include(cols: string[]): this {\n this._def.include = cols;\n return this;\n }\n}\n\nexport function index(name: string): IndexBuilder {\n return new IndexBuilder(name);\n}\n\nexport interface TableInput<C extends ColumnMap = ColumnMap> {\n columns: C;\n rls?: boolean;\n /**\n * Bu tablonun RLS politikaları — TABLONUN KENDİ KOLONLARININ bir fonksiyonu\n * olarak (FR-022).\n *\n * Callback olmasının sebebi tip: `columns`'tan çıkarılan `C`, TypeScript\n * tarafından buraya bağlamlandırılıyor, yani `p.col(\"ownerr\")` yazım hatası\n * DERLEME hatası oluyor. Düz bir dizide `policy(\"x\")` tek başına çağrıldığı\n * için hangi tabloda olduğunu bilemez, ve yanlış kolon adı ancak deploy\n * anında `CREATE POLICY` çalışırken Postgres'ten dönerdi. Bir RLS\n * politikasında yanlış kolon adı yetki hatasıdır; derlemede yakalanır.\n *\n * ```ts\n * policies: (p) => [\n * policy(\"owner_read\").for(\"select\").using(p.col(\"owner\").eq(p.auth.uid())),\n * ]\n * ```\n */\n policies?: (p: PolicyExprCtx<Extract<keyof C, string>>) => (PolicyBuilder | PolicyDef)[];\n /** Composite/named primary key (ordered column names). Omit for single-column inline .primaryKey(). */\n primaryKey?: string[];\n /** Named multi-column UNIQUE constraints. */\n unique?: { name: string; columns: string[] }[];\n /** Named raw-SQL DDL objects (EXCLUDE, triggers, views) that the typed DSL cannot express. */\n raw?: RawConstraintDef[];\n /**\n * Named first-class CHECK constraints. Diffed by NAME with a BODY compare:\n * a changed `expr` (after pg normalization) recreates the constraint\n * (DROP + ADD). `expr` is trusted SQL emitted verbatim (like policy USING),\n * `name` is identifier-validated.\n */\n checks?: { name: string; expr: string }[];\n /**\n * Plain (non-unique) btree indexes over an ordered column list, emitted as\n * standalone `CREATE INDEX [IF NOT EXISTS] name ON table (col1, col2)`\n * statements (NOT a table clause — a separate migration statement category).\n * Structural compare by NAME (no expression normalization). `name` and each\n * column are identifier-validated by the Go differ.\n *\n * Scope: columns-only plain btree. Partial (`where`) and expression indexes\n * are a deliberate follow-up — modelling them needs the same raw-SQL\n * normalization round-trip CHECK uses (Task 10), so they are NOT in this\n * type yet to avoid a half-working partial-index path.\n */\n indexes?: (p: PolicyExprCtx<Extract<keyof C, string>>) => (IndexBuilder | IndexDef)[];\n /**\n * appendOnly (FR-030): tablo yalnız INSERT kabul eder — UPDATE/DELETE hem\n * veritabanı yetkisiyle hem üretilen tipte reddedilir (T017/T018).\n * Ledger deseninin veri katmanından istediği TEK şey budur: bakiye türetilmiş\n * bir değerdir ve entry log'u değiştirilebilirse doğruluğunu kaybeder.\n */\n appendOnly?: boolean;\n /** Arama beyanı — bkz. SearchDecl. */\n search?: SearchDecl;\n /** Hafıza beyanı — bkz. MemoryDecl (FR-032). */\n memory?: MemoryDecl;\n}\n\n/**\n * A table definition — the runtime value the Go runtime's `schema_extract.js`\n * reads. It keys tables by `tableDef.name`, reads `tableDef.columns` for the\n * column DDL, and `tableDef.rls` + `tableDef.policies` for RLS.\n *\n * `defineSchema` derives `name` from the object key, so authors never repeat\n * the table name. `rls`/`policies` are always present after normalization\n * (defaulted to `true`/`[]`).\n *\n * The `C` type parameter preserves the precise per-column phantom types so that\n * downstream mapped types (InsertShape, RowShape) can discriminate on them.\n */\nexport interface TableDef<C extends ColumnMap = ColumnMap> {\n name: string;\n columns: C;\n rls: boolean;\n policies: PolicyDef[];\n primaryKey?: string[];\n unique?: { name: string; columns: string[] }[];\n /** Named raw-SQL DDL objects emitted verbatim on deploy. Tracked by name. */\n raw?: RawConstraintDef[];\n /** Named first-class CHECK constraints. Diffed by name + (normalized) body. */\n checks?: { name: string; expr: string }[];\n /** Index bildirimleri; partial/expression/sıra/covering alanlarıyla (FR-041…043). */\n indexes?: IndexDef[];\n /** appendOnly (FR-030) — bkz. TableInput. */\n appendOnly?: boolean;\n /** Arama beyanı, doğrulanmış ve taşınmış hali. */\n search?: SearchDecl;\n /** Hafıza beyanı, doğrulanmış ve taşınmış hali (FR-032). */\n memory?: MemoryDecl;\n}\n\n/**\n * A schema definition containing multiple tables, keyed by table name.\n *\n * The `T` type parameter preserves the exact `TableDef<...>` type for each\n * table so that `SchemaDef[\"tables\"][\"rooms\"]` resolves to the precise\n * `TableDef<{ id: ColumnBuilder<'uuid', false, true, never>; ... }>`.\n */\nexport interface SchemaDef<\n T extends Record<string, TableDef> = Record<string, TableDef>,\n> {\n /** The schema's own name — `public`, `billing`, … Declared, never derived. */\n name: string;\n /** Reachable over HTTP? False unless the author opts in. */\n exposed: boolean;\n tables: T;\n /** Postgres extensions to install on deploy. Normalized to `[]` when absent. */\n extensions: PalbaseExtension[];\n}\n\n/** The author-facing input to `defineSchema` — a `tables` map whose keys are\n * the table names and whose values are `{ columns, rls?, policies? }`, plus an\n * optional `extensions` allowlist. */\nexport interface SchemaInput<\n T extends Record<string, TableInput> = Record<string, TableInput>,\n> {\n tables: T;\n /**\n * Postgres extensions to enable for this project, e.g. `[\"vector\"]`.\n * Config-as-code: installed by the deploy (CREATE EXTENSION … SCHEMA\n * extensions) with the privileged deploy connection. The type is an\n * allowlist union, so unsupported names fail typecheck.\n */\n extensions?: PalbaseExtension[];\n}\n\n/** Map the author's `{ tables: { <name>: { columns } } }` input to the\n * `{ tables: { <name>: TableDef<columns> } }` runtime/type shape, threading the\n * per-table column map `T[K][\"columns\"]` so column-level inference survives. */\ntype TablesByName<T extends readonly TableHandle[]> = {\n [K in T[number] as K[typeof TABLE_META][\"name\"]]: K[typeof TABLE_META];\n};\n\n/** Normalize a single `policies` entry into a plain `PolicyDef` (read off a\n * `PolicyBuilder._def`, or passed through when already a `PolicyDef`). */\nfunction toPolicyDef(p: PolicyBuilder | PolicyDef): PolicyDef {\n return p instanceof PolicyBuilder ? p._def : p;\n}\n\n/**\n * How a schema file reads. One file per schema — `db/public.ts`, `db/billing.ts`\n * — and the schema says its own name:\n *\n * const todos = defineTable(\"todos\", {\n * columns: {\n * id: uuid().primaryKey().defaultRandom(),\n * owner: text().notNull(),\n * title: text().notNull(),\n * },\n * rls: true,\n * policies: [\n * policy(\"owner_all\").for(\"all\").to(\"authenticated\")\n * .using(\"owner = (select auth.uid())\")\n * .withCheck(\"owner = (select auth.uid())\"),\n * ],\n * });\n *\n * export default defineSchema(\"public\", { tables: [todos] });\n *\n * The dictionary form `defineSchema({ tables: { todos: {…} } })` is RETIRED and\n * refused by name: a table whose name comes from a key does not know what it is\n * called while it is being built, so it cannot resolve `references(() =>\n * other.id)`, and a schema that does not say its own name cannot tell one\n * `invoices` from another schema's `invoices`.\n *\n * The returned value is `{ name, tables: { todos: { name, columns, rls,\n * policies } }, extensions, exposed }` — the exact shape the runtime schema\n * extractor parses. Per-column phantom types are preserved so\n * `Database.public.todos.insert({...})` stays typed.\n *\n * RLS normalization: `rls` defaults to **`true`**, `policies` to `[]`. A table\n * that declares neither is therefore deny-all — nothing reads it until a policy\n * says who may, which is the safe starting point rather than a bug. Declare\n * `rls: false` for a genuinely public table; that is an explicit, greppable\n * statement of intent instead of an omission. When `policies` is non-empty,\n * `rls` is forced on (ENABLE + FORCE) regardless of the declared flag — a table\n * with policies must have RLS enabled or the policies would be inert.\n */\n/**\n * Where a table's metadata lives.\n *\n * The table VALUE is its columns, so `lists.id` is the column — which means a\n * column called `name` would overwrite the table's own name if metadata sat in\n * a plain field. Measured, not imagined: the existing `users` / `rooms` tests\n * (both declare a `name` column) produced an `[object Object]` table key.\n * `columns`, `rls`, `search`, `memory`, `unique` and `indexes` are all plausible\n * column names too. A column cannot collide with a symbol.\n */\nexport const TABLE_META: unique symbol = Symbol.for(\"palbase.table.meta\");\n\n/** A value produced by `defineTable`: the columns, plus metadata behind the symbol. */\nexport type TableHandle<C extends ColumnMap = ColumnMap, N extends string = string> =\n C & { readonly [TABLE_META]: TableDef<C> & { name: N } };\n\n/**\n * Declare one table as a standalone value that KNOWS ITS OWN NAME.\n *\n * The name lives here, not in a dictionary key. A table whose name comes from a\n * key cannot resolve `references(() => other.id)` when it is built — it does not\n * know what to call itself — which forces a two-phase resolution with an\n * empty-name intermediate state. One name source, no empty identity.\n *\n * The returned object spreads its own columns, so a sibling can point at it:\n * `references(() => lists.id)`.\n */\nexport function defineTable<const N extends string, C extends ColumnMap>(\n name: N,\n input: TableInput<C>,\n): TableHandle<C, N> {\n if (name.trim() === \"\") {\n throw new Error(\"defineTable(name, …): name must not be empty\");\n }\n // İfade bağlamı TABLONUN KENDİ kolon adlarıyla kuruluyor (FR-022). Çalışma\n // zamanında `col()` adı doğrulamıyor — doğrulayan tip; burada yapılacak\n // ikinci bir kontrol, tipin zaten imkânsız kıldığı bir şeyi tekrar ederdi.\n const policies = (input.policies?.(exprCtx(Object.keys(input.columns), 0, name)) ?? []).map(toPolicyDef);\n // Fail closed. RLS is on unless the author explicitly says `rls: false`, and\n // policies force it on regardless — a policy on a table without RLS enabled is\n // inert, so declaring both resolves towards the safe reading.\n //\n // This defaulted to `false` until 2026-08-07, which meant a table nobody\n // thought about had no row-level security while `typed-db.ts` documented the\n // default `Database.*` path as RLS-enforced. The live proof settled it: user B\n // read user A's row in full through the typed client, while the same request\n // against a table declaring `rls: true` returned 0 of 165 rows. With no\n // policies this is deny-all.\n const rls = policies.length > 0 || input.rls !== false;\n // EACH TABLE GETS ITS OWN COLUMN OBJECTS.\n //\n // A ColumnBuilder shares one `_def` with every builder derived from it, so a\n // shared column — `const audit = { created_at: timestamp() }` spread into two\n // tables, the most ordinary pattern this DSL has — would put BOTH tables'\n // stamps on one object and the second declaration would win. A reference\n // thunk written as `() => a.created_at` then resolved to table `b`: a\n // well-formed foreign key onto the WRONG table, with no error anywhere.\n //\n // Copying is what `.ignored()` already does about the same aliasing, and it\n // keeps the spread pattern working rather than banning it. The copies are\n // what the def AND the handle carry, so the identity match that resolves a\n // reference thunk still finds its column.\n const owned = {} as C;\n for (const [colName, b] of Object.entries(input.columns)) {\n const builder = b as { _def: ColumnDefLike };\n // Same class, same phantom type parameters, its own `_def`. Cloning through\n // the prototype rather than the constructor keeps this file free of a value\n // import from columns.ts — the two modules only ever exchanged types.\n const clone = Object.create(Object.getPrototypeOf(builder)) as { _def: ColumnDefLike };\n Object.defineProperty(clone, \"_def\", { value: { ...builder._def }, enumerable: true, writable: true });\n (owned as Record<string, unknown>)[colName] = clone;\n }\n\n const def = {\n name,\n columns: owned,\n rls,\n policies,\n } as TableDef<C> & { name: N };\n if (input.primaryKey !== undefined) def.primaryKey = input.primaryKey;\n if (input.unique !== undefined) def.unique = input.unique;\n if (input.raw !== undefined && input.raw.length > 0) def.raw = input.raw.slice();\n if (input.checks !== undefined && input.checks.length > 0) def.checks = input.checks.slice();\n // İfade bağlamı `policies` ile AYNI — index kolonları da tablonun kendi\n // kolonlarından çözülüyor ve yanlış ad derleme hatası (FR-041).\n const declaredIndexes = (input.indexes?.(exprCtx(Object.keys(input.columns), 0, name)) ?? []).map(\n (i) => (i instanceof IndexBuilder ? i._def : i),\n );\n if (declaredIndexes.length > 0) def.indexes = declaredIndexes;\n if (input.appendOnly === true) def.appendOnly = true;\n if (input.search !== undefined) {\n const s = input.search;\n // Erken, beyan-anı doğrulama (apply doğrulamasını İKAME ETMEZ — yazım\n // hatası deploy'a gitmeden yazarın yüzüne söylenir).\n if (s.from !== undefined) {\n // YENİ biçim (D-007). Eski alanlarla karışım tek biçime zorlanır:\n // iki yarım beyanın hangisinin kazandığını okuyucu bilemez.\n if (s.vector !== undefined) {\n throw new Error(\n `table ${name}: search beyanında tek biçim kullanın — 'from' (yeni) ile 'vector' (eski) birlikte olamaz`,\n );\n }\n if (s.from.length === 0) {\n throw new Error(`table ${name}: search.from boş olamaz`);\n }\n if (s.model === undefined) {\n throw new Error(\n `table ${name}: search.from model'siz anlamsız — auto-embed için model verin (BYO için eski 'vector' biçimini kullanın)`,\n );\n }\n if (Array.isArray(s.text) && s.text.length === 0) {\n throw new Error(`table ${name}: search.text boş dizi olamaz — FTS istemiyorsan text: false yazın`);\n }\n } else {\n // ESKİ biçim — davranış ve hata metinleri aynen (NFR-B1'in DX yarısı).\n if (typeof s.text === \"boolean\") {\n throw new Error(`table ${name}: text:${String(s.text)} yalnız yeni biçimde ('from' ile) geçerli`);\n }\n if (s.text === undefined && s.vector === undefined) {\n throw new Error(\n `table ${name}: search beyanı boş — en az bir kol (text ya da vector) verin, yoksa alanı hiç yazmayın`,\n );\n }\n if (s.text !== undefined && s.text.length === 0) {\n throw new Error(`table ${name}: search.text boş olamaz — FTS kolu istemiyorsan alanı hiç yazma`);\n }\n const legs = s.vector === undefined ? [] : Array.isArray(s.vector) ? s.vector : [s.vector];\n for (const leg of legs) {\n if (leg.model !== undefined && (leg.from === undefined || leg.from.length === 0)) {\n throw new Error(`table ${name}: search.vector.model beyan edildi ama 'from' yok — embed kaynağı kolonlar zorunlu (C-2)`);\n }\n if (leg.model === undefined && leg.from !== undefined) {\n throw new Error(`table ${name}: search.vector.from model'siz anlamsız — auto-embed için model verin`);\n }\n }\n }\n def.search = s;\n }\n if (input.memory !== undefined) {\n if (input.memory.from.length === 0) {\n throw new Error(`table ${name}: memory.from boş olamaz`);\n }\n def.memory = input.memory;\n }\n // The stamp goes on the COPIES, after the def exists — that is how a\n // reference thunk names its target when `defineSchema` resolves it.\n for (const b of Object.values(owned as Record<string, unknown>)) {\n (b as { _def: { ownerTable?: unknown } })._def.ownerTable = def;\n }\n // Columns are the enumerable surface; metadata hangs off a non-enumerable\n // symbol so it survives spreads and cannot be shadowed by a column name.\n const handle = { ...(owned as Record<string, unknown>) } as TableHandle<C, N>;\n Object.defineProperty(handle, TABLE_META, { value: def, enumerable: false });\n return handle;\n}\n\n/**\n * Which schema declared a table.\n *\n * A `TableDef` cannot carry it: `defineTable` runs before any schema exists, and\n * `defineSchema` is where the answer arrives. It lives OUTSIDE the def rather\n * than on it because the def is serialized — a field here would either leak into\n * the wire shape or need a second rule saying not to. A WeakMap keyed by the def\n * object is the same fact with no surface.\n *\n * It exists because a foreign key names its target and that name is only half a\n * name without the schema. `resolveReferences` reads it to write the referent\n * the way `qualifiedTableKey` writes every other table name.\n */\nconst declaringSchemaOf = new WeakMap<object, string>();\n\n/**\n * Resolve every pending reference thunk.\n *\n * Runs inside `defineSchema`, where all table bindings exist and every table\n * already carries its name — which is why the name lives on the table and not in\n * a dictionary key: resolving against a table that does not yet know what it is\n * called would need a second pass over an empty-name intermediate state.\n *\n * The written referent follows the ONE naming convention (`qualifiedTableKey`):\n * a `public` table is bare, anything else is schema-qualified. The deciding fact\n * is the REFERENT's schema, not whether the key crosses a schema boundary —\n * exactly the CASE Go's introspection uses when it reads a live FK back\n * (`introspect.go`: `CASE WHEN rn.nspname = 'public' THEN rt.relname ELSE\n * rn.nspname || '.' || rt.relname END`). Writing `invoices` for a table that\n * lives in `billing` made Go read it as `public.invoices`: a FK onto a table\n * that does not exist, or — worse and silently — onto a DIFFERENT table that\n * happened to share the name.\n */\nfunction resolveReferences(tables: Record<string, TableDef>, schemaName: string): void {\n for (const table of Object.values(tables)) {\n for (const [colName, builder] of Object.entries(table.columns)) {\n const def = (builder as { _def: ColumnDefLike })._def;\n if (def.selfRefColumn !== undefined) {\n if (!(def.selfRefColumn in table.columns)) {\n throw new Error(\n `table \"${table.name}\" column \"${colName}\": selfReferences(\"${def.selfRefColumn}\") — no such column on this table`,\n );\n }\n // A self-reference is a reference: its referent is this table, in THIS\n // schema, so it is written by the same rule as any other.\n def.references = {\n table: qualifiedTableKey(schemaName, table.name),\n column: def.selfRefColumn,\n };\n continue;\n }\n if (def.referencesThunk === undefined) continue;\n const target = def.referencesThunk();\n const owner = (target as { _def?: ColumnDefLike } | undefined)?._def?.ownerTable;\n if (owner === undefined) {\n throw new Error(\n `table \"${table.name}\" column \"${colName}\": references(() => …) must point at a column of a table declared with defineTable(...)`,\n );\n }\n const targetColumn = Object.entries(owner.columns).find(\n ([, b]) => (b as { _def: unknown })._def === (target as { _def: unknown })._def,\n )?.[0];\n if (targetColumn === undefined) {\n throw new Error(\n `table \"${table.name}\" column \"${colName}\": the referenced column was not found on table \"${owner.name}\"`,\n );\n }\n const targetSchema = declaringSchemaOf.get(owner);\n if (targetSchema === undefined) {\n // Assuming `public` here is the exact silence this resolution closes:\n // it would produce a FK onto a table that does not exist, or onto a\n // same-named one that does. Name the gap instead.\n throw new Error(\n `table \"${table.name}\" column \"${colName}\": references(() => …) points at table ` +\n `\"${owner.name}\", which no defineSchema(...) has claimed yet — a foreign key cannot ` +\n `be written without its target's schema. Declare that table's schema first ` +\n `(one file per schema: db/public.ts, db/billing.ts …, imported by this one).`,\n );\n }\n def.references = {\n table: qualifiedTableKey(targetSchema, owner.name),\n column: targetColumn,\n };\n }\n }\n}\n\ntype ColumnDefLike = {\n references?: { table: string; column: string };\n referencesThunk?: () => unknown;\n selfRefColumn?: string;\n ownerTable?: { name: string; columns: Record<string, unknown> };\n};\n\n/**\n * Collect declared tables into one schema.\n *\n * Takes an ARRAY, not a dictionary: the tables already carry their names, and a\n * second name source is a second thing that can disagree.\n */\nexport function defineSchema<const T extends readonly TableHandle[]>(\n name: string,\n input: { tables: T; exposed?: boolean; extensions?: PalbaseExtension[] },\n): SchemaDef<TablesByName<T>> {\n // The TYPE first, then the value. The retired one-argument form passes an\n // object here, and a guard that only asks whether the name is blank calls\n // `.trim()` on it — which threw `name.trim is not a function` out of the child\n // process that runs `db/*.ts` during push: no file, no form, nothing to act\n // on. `references(\"t\", \"c\")` already answers its own retirement by name.\n if (typeof name !== \"string\") {\n throw new Error(\n `defineSchema(...) takes the schema NAME first: ` +\n `defineSchema(\"public\", { tables: [todos, lists] }). ` +\n `The one-argument form defineSchema({ tables: { … } }) is gone — a schema that does not ` +\n `say its own name cannot be told apart from another schema's table of the same name, ` +\n `which is what a cross-schema foreign key has to do. ` +\n `Migrate db/public.ts (one file per schema: db/public.ts, db/billing.ts …): name the ` +\n `schema, and lift each table key onto the table itself with ` +\n `defineTable(\"todos\", { columns: { … } }), then list the tables in the array.`,\n );\n }\n if (name.trim() === \"\") {\n throw new Error(\"defineSchema(name, …): name must not be empty\");\n }\n const tables = {} as Record<string, TableDef>;\n for (const handle of input.tables) {\n const table = handle[TABLE_META];\n if (tables[table.name] !== undefined) {\n throw new Error(\n `defineSchema(\"${name}\"): two tables declare the name \"${table.name}\" — table names must be unique within a schema`,\n );\n }\n tables[table.name] = table;\n // Stamped BEFORE resolution: a reference from this schema to a sibling in it\n // must find the sibling's schema, and the sibling may be declared later in\n // the array than the table pointing at it.\n declaringSchemaOf.set(table, name);\n }\n // Thunks are invoked HERE: every binding exists and every name is already set.\n resolveReferences(tables, name);\n // memory beyanları TABLOLAR-ARASI doğrulanır (into/subject/fact) — tüm\n // tablolar kurulduktan sonra: beyan sırasına bağımlılık olmasın (FR-032).\n for (const [name, def] of Object.entries(tables)) {\n const m = (def as TableDef).memory;\n if (m === undefined) continue;\n const target = Object.values(tables).find((t) => (t as TableDef).name === m.into) as TableDef | undefined;\n if (target === undefined) {\n throw new Error(`table ${name}: memory.into \"${m.into}\" şemada declared değil`);\n }\n const subject = m.subject ?? \"owner\";\n if (!(subject in (def as TableDef).columns)) {\n throw new Error(`table ${name}: memory.subject \"${subject}\" kolonu kaynak tabloda yok`);\n }\n if (!(subject in target.columns)) {\n throw new Error(`table ${name}: memory.subject \"${subject}\" kolonu hedef \"${m.into}\" tablosunda yok`);\n }\n const factCol = target.columns[\"fact\"];\n const factDef = factCol !== undefined && \"_def\" in (factCol as object)\n ? (factCol as { _def: { type?: string } })._def\n : (factCol as { type?: string } | undefined);\n if (factDef === undefined || factDef.type !== \"text\") {\n throw new Error(`table ${name}: memory.into \"${m.into}\" tablosunda \"fact\" (text) kolonu zorunlu`);\n }\n for (const c of m.from) {\n if (!(c in (def as TableDef).columns)) {\n throw new Error(`table ${name}: memory.from kolonu \"${c}\" kaynak tabloda yok`);\n }\n }\n }\n // Dedupe + normalize extensions (order-independent; deploy resolves deps).\n const extensions = [...new Set(input.extensions ?? [])];\n // Declaring a schema is not the same as putting it on the internet, so\n // `exposed` is false unless the author says otherwise — EXCEPT for `public`,\n // which is reachable today and stays reachable. Making the default uniform\n // would silently 404 every existing project's /v1/db traffic on upgrade.\n return {\n name,\n tables: tables as TablesByName<T>,\n extensions,\n exposed: input.exposed ?? name === \"public\",\n };\n}\n","import { TABLE_META } from \"./schema.js\";\nimport type { ColumnMap, TableHandle } from \"./schema.js\";\n\n/**\n * policy.ts — the RLS policy authoring DSL.\n *\n * `policy(name)` returns a fluent builder that mirrors the `ColumnBuilder`\n * style in columns.ts: each chainable method mutates the underlying\n * definition and returns the builder so calls compose. The terminal value is\n * a plain {@link PolicyDef} — the exact JSON shape the runtime's\n * `schema_extract.js` reads off the bundled module and the Go side parses into\n * `PolicyJSON` (CONTRACT-POLICY).\n *\n * @example\n * import { policy } from \"@palbase/backend\";\n *\n * policy(\"owner_select\")\n * .for(\"select\")\n * .to(\"authenticated\")\n * .using(\"owner = (select auth.uid())\");\n */\n\n\n// ---------------------------------------------------------------------------\n// C-4 — politika ifadesinin YAPISI (FR-022). SÖZLEŞME BURADA DONAR.\n//\n// T016 (`existsIn`), T027 (Go emitter) ve T028 (korelasyonlu EXISTS) bu tipi\n// tüketir; şekli değiştirmek üç tarafı birden kırar.\n//\n// NEDEN string değil de yapı: bir string ifadeyi ne TypeScript ne Go okuyabilir.\n// Kolon adı yanlışsa hata `CREATE POLICY` anında Postgres'ten gelir — deploy\n// sırasında, yazma anında değil. Dahası InitPlan sarmalaması (`auth.uid()` →\n// `(select auth.uid())`, satır başına bir kez yerine statement başına bir kez)\n// ve `TO <rol>` daraltması ancak yapı üstünde GÜVENLE verilebilir; string\n// üzerinde regex'le yapmak, yorum içindeki bir `auth.uid()`'yi de sarmalar.\n// ---------------------------------------------------------------------------\n\n/** Politika ifadesinin düğümleri. DÜZ VERİ: tele bu şekilde gider. */\nexport type PolicyExpr =\n | {\n kind: \"col\";\n name: string;\n /**\n * Hangi tablonun kolonu (FR-023). Yoksa POLİTİKANIN KENDİ tablosu —\n * Postgres politika ifadesinde onu niteliksiz çözer. Doluysa bir\n * `existsIn` alt-sorgusunun takma adı.\n *\n * Bu ayrım korelasyonun tamamı: ayırt edilmezse `team_id = team_id`\n * üretilir, her satır için doğrudur, ve politika HİÇBİR ŞEYİ süzmez —\n * yani tüm belgeler herkese görünür.\n */\n alias?: string;\n }\n | { kind: \"authUid\" }\n | { kind: \"lit\"; value: string | number | boolean | null }\n | { kind: \"binop\"; op: PolicyBinOp; left: PolicyExpr; right: PolicyExpr }\n | { kind: \"and\"; parts: PolicyExpr[] }\n | { kind: \"or\"; parts: PolicyExpr[] }\n | { kind: \"not\"; expr: PolicyExpr }\n | { kind: \"isNull\"; expr: PolicyExpr; negated: boolean }\n | {\n /**\n * Korelasyonlu `EXISTS (SELECT 1 FROM <table> <alias> WHERE <predicate>)`.\n *\n * FR-024 BAĞLAYICI: alt-sorgu DOĞRUDAN üretilir, bir `SECURITY DEFINER`\n * fonksiyona SARILMAZ. Ölçüldü (spec Research Appendix, pg16): doğrudan\n * alt-sorguda hedef tablonun KENDİ RLS'i uygulanıyor — yani sızıntı\n * kanalı yok. Sarmalama ise onu bypass ederdi.\n */\n kind: \"exists\";\n table: string;\n alias: string;\n /**\n * POLİTİKANIN KENDİ tablosunun adı — korelasyonun çalışması için ŞART.\n *\n * ÖLÇÜLDÜ (canlı pg16): alt-sorgu içinde niteliksiz bir kolon adı\n * Postgres tarafından İÇ tabloya çözülüyor. Yani dış kolon niteliksiz\n * bırakılınca `pb_e1.team_id = pb_e1.team_id` üretiliyor — her satır\n * için doğru, ve politika HİÇBİR ŞEYİ süzmüyor: iki farklı kullanıcı\n * da tüm belgeleri gördü. Dış tablo adı burada taşınıyor ki emitter\n * `\"documents\".\"team_id\"` yazabilsin.\n */\n outer: string;\n predicate: PolicyExpr;\n };\n\n/** Karşılaştırma operatörleri. `in` sağ tarafta liste bekler. */\nexport type PolicyBinOp = \"eq\" | \"neq\" | \"gt\" | \"gte\" | \"lt\" | \"lte\" | \"in\";\n\n/**\n * Bir ifadenin ETRAFINDAKİ akıcı sarmalayıcı.\n *\n * Düğüm (`expr`) düz veri kalıyor, metotlar sarmalayıcıda yaşıyor: `_def.using`\n * serileştiğinde metotlu bir nesne değil, tam olarak tele gidecek şekil olsun\n * diye. `.using()` sarmalayıcıyı açar.\n */\nexport class PolicyExprRef {\n constructor(readonly expr: PolicyExpr) {}\n\n private bin(op: PolicyBinOp, other: PolicyOperand): PolicyExprRef {\n return new PolicyExprRef({ kind: \"binop\", op, left: this.expr, right: toExpr(other) });\n }\n\n eq(other: PolicyOperand): PolicyExprRef { return this.bin(\"eq\", other); }\n neq(other: PolicyOperand): PolicyExprRef { return this.bin(\"neq\", other); }\n gt(other: PolicyOperand): PolicyExprRef { return this.bin(\"gt\", other); }\n gte(other: PolicyOperand): PolicyExprRef { return this.bin(\"gte\", other); }\n lt(other: PolicyOperand): PolicyExprRef { return this.bin(\"lt\", other); }\n lte(other: PolicyOperand): PolicyExprRef { return this.bin(\"lte\", other); }\n\n /**\n * `IS NULL` / `IS NOT NULL` — `= NULL` SQL'de her zaman UNKNOWN'dır, o yüzden\n * niyet ayrı bir düğümle yazılır. Partial index'in en sık koşulu\n * (`WHERE deleted_at IS NULL`) tam olarak bu.\n */\n isNull(negated = false): PolicyExprRef {\n return new PolicyExprRef({ kind: \"isNull\", expr: this.expr, negated });\n }\n\n and(...others: PolicyExprRef[]): PolicyExprRef {\n return new PolicyExprRef({ kind: \"and\", parts: [this.expr, ...others.map((o) => o.expr)] });\n }\n or(...others: PolicyExprRef[]): PolicyExprRef {\n return new PolicyExprRef({ kind: \"or\", parts: [this.expr, ...others.map((o) => o.expr)] });\n }\n not(): PolicyExprRef {\n return new PolicyExprRef({ kind: \"not\", expr: this.expr });\n }\n}\n\n/** `.eq()` gibi metotların sağ tarafı: başka bir ifade ya da düz bir değer. */\nexport type PolicyOperand = PolicyExprRef | string | number | boolean | null;\n\n/**\n * Düz değer LİTERAL olur, kolon referansı OLMAZ.\n *\n * `.eq(\"owner\")` bir string karşılaştırmasıdır — `owner` kolonuna referans\n * değil. İkisi karışırsa politika sessizce yanlış satırları gösterir ve RLS'te\n * bunun adı yetki atlamasıdır. Kolon istiyorsan `p.col(\"owner\")` yazacaksın.\n */\nfunction toExpr(v: PolicyOperand): PolicyExpr {\n return v instanceof PolicyExprRef ? v.expr : { kind: \"lit\", value: v };\n}\n\n/**\n * Politika ifadesi bağlamı — `defineTable`'ın `policies` callback'ine verilir.\n *\n * Kolon adları TABLONUN KENDİ kolonlarıyla sınırlıdır (FR-022). Bu, `policies`\n * bir dizi değil de callback olduğu için mümkün: TypeScript `columns`'tan\n * `C`'yi çıkarıp callback'i onunla bağlamlandırıyor. `policy(\"x\")` tek başına\n * çağrıldığında hangi tabloda olduğunu bilemezdi.\n */\nexport interface PolicyExprCtx<Cols extends string = string> {\n /** Bu tablonun bir kolonu. Bilinmeyen ad DERLENMEZ. */\n col(name: Cols): PolicyExprRef;\n /**\n * \"Bu satırın sahibi olduğum bir takıma ait mi?\" — üyelik tabanlı kiracılık\n * (FR-023), korelasyonlu bir `EXISTS` alt-sorgusu olarak.\n *\n * ```ts\n * policies: (p) => [\n * policy(\"team_read\").for(\"select\").using(\n * p.existsIn(teamMembers, (m) =>\n * m.col(\"team_id\").eq(p.col(\"team_id\"))\n * .and(m.col(\"user_id\").eq(p.auth.uid()))),\n * ),\n * ]\n * ```\n *\n * `m` ÜYELİK tablosunun kolonlarını, `p` bu tablonunkileri verir; ikisi de\n * tipli ve SQL'de farklı nitelenirler. Karışsalardı `team_id = team_id`\n * üretilir ve politika hiçbir şeyi süzmezdi.\n *\n * ÖZYİNELEME TUZAĞI: üyelik tablosunun KENDİ politikası `existsIn`\n * KULLANMAZ — `user_id = auth.uid()` yazar. İki tablo birbirini\n * sorgularsa Postgres sorgu anında\n * `infinite recursion detected in policy for relation …` der. Asimetri\n * kasıtlıdır: üyelik tablosu basit olanı alır, diğer her tablo ona\n * alt-sorgu ATAR.\n */\n existsIn<C extends ColumnMap, N extends string>(\n table: TableHandle<C, N>,\n predicate: (row: PolicyExprCtx<Extract<keyof C, string>>) => PolicyExprRef,\n ): PolicyExprRef;\n /** Çağıranın kimliği. SQL'e `(select auth.uid())` olarak iner (InitPlan). */\n auth: { uid(): PolicyExprRef };\n /** Düz bir değer — karşılaştırmanın sağ tarafında açıkça literal demek için. */\n lit(v: string | number | boolean | null): PolicyExprRef;\n and(...parts: PolicyExprRef[]): PolicyExprRef;\n or(...parts: PolicyExprRef[]): PolicyExprRef;\n not(part: PolicyExprRef): PolicyExprRef;\n}\n\n/**\n * İfade bağlamını kurar. `defineTable` bunu kendi kolon adlarıyla çağırır;\n * testler ve elle kullanım için de dışa açık.\n */\nexport function exprCtx<Cols extends string = string>(\n _columns?: readonly Cols[],\n depth = 0,\n /**\n * POLİTİKANIN KENDİ tablosu — her derinlikte AYNI kalır.\n *\n * Alt-sorgunun içinde takma adsız duran bir kolon, dış sorgudaki tabloya\n * bağlanmak zorundadır; Go tarafı onu bu adla nitelendiriyor. Değer iç içe\n * geçmede ORTA tablonun adına kayıyordu (`meta.name` aşağı veriliyordu) ve\n * sonuç canlıda `ERROR: missing FROM-clause entry for table \"…\"` oluyordu —\n * yani iç içe `existsIn` içinden politikanın kendi kolonuna erişmek imkânsızdı\n * (nihai inceleme I-1, ölçüldü). Kök tablo aşağı DEĞİŞMEDEN taşınır.\n */\n ownTable = \"\",\n): PolicyExprCtx<Cols> {\n // Takma ad DERİNLİKTEN türetiliyor, bir sayaçtan değil: aynı şema iki kez\n // yüklendiğinde (test, sonra deploy) sayaç farklı değer üretir ve golden\n // çıktı sebepsiz değişirdi. Derinlik ifadenin kendi şeklinden gelir.\n const alias = `pb_e${depth}`;\n return {\n col: (name) =>\n new PolicyExprRef(depth === 0 ? { kind: \"col\", name } : { kind: \"col\", name, alias }),\n auth: { uid: () => new PolicyExprRef({ kind: \"authUid\" }) },\n lit: (v) => new PolicyExprRef({ kind: \"lit\", value: v }),\n and: (...parts) => new PolicyExprRef({ kind: \"and\", parts: parts.map((p) => p.expr) }),\n or: (...parts) => new PolicyExprRef({ kind: \"or\", parts: parts.map((p) => p.expr) }),\n not: (part) => new PolicyExprRef({ kind: \"not\", expr: part.expr }),\n existsIn: (table, predicate) => {\n const meta = (table as { [TABLE_META]: { name: string; columns: ColumnMap } })[TABLE_META];\n const inner = exprCtx(Object.keys(meta.columns), depth + 1, ownTable);\n return new PolicyExprRef({\n kind: \"exists\",\n table: meta.name,\n alias: `pb_e${depth + 1}`,\n outer: ownTable,\n predicate: predicate(inner as never).expr,\n });\n },\n };\n}\n\n/** The SQL command a policy applies to. `\"all\"` covers SELECT/INSERT/UPDATE/DELETE. */\nexport type PolicyCommand = \"all\" | \"select\" | \"insert\" | \"update\" | \"delete\";\n\n/** Whether a policy is permissive (OR-combined, the default) or restrictive\n * (AND-combined). Mirrors Postgres `CREATE POLICY ... AS PERMISSIVE|RESTRICTIVE`. */\nexport type PolicyMode = \"permissive\" | \"restrictive\";\n\n/**\n * The compiled, serializable policy definition — the EXACT shape consumed by\n * `schema_extract.js` → Go `PolicyJSON` (CONTRACT-POLICY).\n *\n * - `roles`: the DB roles this policy applies to (`TO` clause). An empty array\n * means the policy applies to PUBLIC (all roles) — the Postgres default.\n * - `using`: the `USING (...)` row-visibility expression, or `null` when none.\n * - `withCheck`: the `WITH CHECK (...)` write-validation expression, or `null`.\n * - `permissive`: `true` for `AS PERMISSIVE` (default), `false` for restrictive.\n */\nexport interface PolicyDef {\n name: string;\n command: PolicyCommand;\n roles: string[];\n /** Yapı (FR-022) ya da ham string (FR-028 kaçış kapağı). */\n using: string | PolicyExpr | null;\n withCheck: string | PolicyExpr | null;\n permissive: boolean;\n}\n\n/**\n * Fluent RLS policy builder.\n *\n * Defaults (documented, applied at construction):\n * - `command`: `\"all\"` — applies to every SQL command unless `.for(...)` narrows it.\n * - `roles`: `[\"authenticated\"]` — the common case is \"rule applies to signed-in\n * users\". Call `.to(...)` to override; pass `.to()` with no roles (or never\n * call it after a reset) to target PUBLIC.\n * - `using` / `withCheck`: `null` — no row filter / write check until set.\n * - `permissive`: `true` — `AS PERMISSIVE` (policies OR together).\n *\n * Each method mutates `_def` in place and returns `this`, so the chain is a\n * single builder instance (no per-call allocation, like a tagged-template\n * compile target). The terminal `PolicyDef` is read directly off `_def` by\n * `schema_extract.js`.\n */\n/** Quote an identifier for the policy expression. Table and column names reach\n * here from the schema author; neither is allowed to become syntax. */\nfunction quote(name: string): string {\n return `\"${name.replace(/\"/g, '\"\"')}\"`;\n}\n\n/**\n * Bir politikanın adreslenebileceği Postgres rolleri.\n *\n * Serbest string DEĞİL, çünkü küme SABİT: bunları palbase provision ediyor,\n * kiracı yeni bir PG rolü yaratmıyor. Serbest bırakıldığında `authenitcated`\n * gibi bir harf hatası derlenip migration'a kadar gidiyordu — Drizzle'da da\n * aynı boşluk ölçüldü (`to` tipi `(string & {})`, yazım hatası DDL'e geçiyor).\n *\n * Çalışma anı zaten fail-closed (bilinmeyen rol kapıyı kapatıyor,\n * `session_rls_fail_closed_integration_test.go`); bu, aynı cevabı derleme\n * anına taşıyor.\n *\n * `backend_*` ikizleri elle YAZILMAZ — `NormalizeDeclaredPolicies` onları\n * kendisi ekliyor; yine de kabul ediliyor ki elle yazan kod kırılmasın.\n */\nexport type PolicyRole =\n | \"anon\"\n | \"authenticated\"\n | \"service_role\"\n | \"backend_anon\"\n | \"backend_authenticated\"\n | \"backend_service_role\";\n\nexport class PolicyBuilder {\n readonly _def: PolicyDef;\n\n constructor(name: string) {\n this._def = {\n name,\n command: \"all\",\n roles: [\"authenticated\"],\n using: null,\n withCheck: null,\n permissive: true,\n };\n }\n\n /** Restrict the policy to a single SQL command (default `\"all\"`). */\n for(command: PolicyCommand): this {\n this._def.command = command;\n return this;\n }\n\n /**\n * Set the DB roles the policy applies to (the `TO` clause), replacing any\n * previously-set roles. Call with no arguments to target PUBLIC (all roles).\n *\n * @example\n * policy(\"p\").to(\"authenticated\")\n * policy(\"p\").to(\"authenticated\", \"service_role\")\n * policy(\"p\").to() // PUBLIC\n */\n to(...roles: PolicyRole[]): this {\n this._def.roles = roles;\n return this;\n }\n\n /**\n * `USING (...)` satır görünürlüğü ifadesi.\n *\n * Tercih edilen biçim YAPI'dır (FR-022) — `policies` callback'inin verdiği\n * bağlamla kurulur ve kolon adları derlemede doğrulanır:\n *\n * ```ts\n * policies: (p) => [\n * policy(\"owner_read\").for(\"select\").using(p.col(\"owner\").eq(p.auth.uid())),\n * ]\n * ```\n *\n * Ham string KAÇIŞ KAPAĞI olarak kalır (FR-028): yapının ifade edemediği bir\n * şey gerektiğinde yol kapanmaz. Ama o yolda kolon adı doğrulaması yoktur ve\n * hata deploy anında Postgres'ten gelir.\n */\n using(expr: string | PolicyExprRef): this {\n this._def.using = expr instanceof PolicyExprRef ? expr.expr : expr;\n return this;\n }\n\n /**\n * \"Rows of THIS table whose owner the caller is a member of\" — the membership\n * pattern, written so it cannot recurse.\n *\n * THE TRAP IT EXISTS FOR. Written by hand, membership policies point at each\n * other: `channels` is visible to members, so its policy reads\n * `channel_members`; `channel_members` is visible to members, so its policy\n * reads `channels`. Postgres refuses the pair at query time with `infinite\n * recursion detected in policy for relation ...`, and the error names the\n * relation but not the cycle. The way out is asymmetry — the MEMBERSHIP table\n * is protected by `user_id = auth.uid()` and nothing else, and every other\n * table subqueries INTO it. That shape was in the platform's own schema and\n * written down nowhere; a customer recovered it by reading that schema.\n *\n * `(select auth.uid())` rather than a bare call: the scalar subquery is\n * evaluated ONCE per statement instead of per row.\n *\n * @example\n * // channels: visible to members. The membership table gets the simple one.\n * policy(\"member_read\").for(\"select\").to(\"authenticated\")\n * .memberOf(\"channel_members\", \"channel_id\")\n * // → id IN (SELECT \"channel_id\" FROM \"channel_members\"\n * // WHERE \"user_id\" = (select auth.uid()))\n */\n memberOf(\n membershipTable: string,\n foreignKey: string,\n options: { column?: string; userColumn?: string } = {},\n ): this {\n if (this._def.using !== null) {\n // Silently AND-ing the two would hide whichever the author meant; silently\n // replacing would hide the one they wrote. Neither is a thing to guess.\n throw new Error(\n `policy(${this._def.name}).memberOf(): this policy already has a using() expression. ` +\n \"Write one or the other — memberOf IS the using expression.\",\n );\n }\n const column = options.column ?? \"id\";\n const userColumn = options.userColumn ?? \"user_id\";\n this._def.using =\n `${quote(column)} IN (SELECT ${quote(foreignKey)} FROM ${quote(membershipTable)} ` +\n `WHERE ${quote(userColumn)} = (select auth.uid()))`;\n return this;\n }\n\n /** `WITH CHECK (...)` yazma doğrulaması — `using` ile aynı iki biçim. */\n withCheck(expr: string | PolicyExprRef): this {\n this._def.withCheck = expr instanceof PolicyExprRef ? expr.expr : expr;\n return this;\n }\n\n /** Set the policy mode: `\"permissive\"` (default, OR-combined) or\n * `\"restrictive\"` (AND-combined). */\n as(mode: PolicyMode): this {\n this._def.permissive = mode === \"permissive\";\n return this;\n }\n}\n\n/**\n * Start authoring an RLS policy. Returns a {@link PolicyBuilder}; the resulting\n * `PolicyBuilder` is accepted directly in a table's `policies: [...]` array\n * (its `_def` is read at schema-extract time).\n *\n * @param name The policy name. Palbase reconciliation keys policies by\n * `(table, name)`, so names must be unique per table.\n */\nexport function policy(name: string): PolicyBuilder {\n return new PolicyBuilder(name);\n}\n","/**\n * Postgres extensions a Palbase project can enable from its schema.\n *\n * Extensions are config-as-code: declare them in `defineSchema({ extensions })`\n * and the deploy installs them (CREATE EXTENSION … SCHEMA extensions) using the\n * deploy path's privileged connection. They are NOT toggled live from Studio —\n * CREATE EXTENSION requires a superuser role that only the deploy path holds.\n *\n * The list is an allowlist (a string-literal union) so editors autocomplete the\n * supported names and a typo fails typecheck. It is intentionally extensible:\n * add a name here (+ confirm the base image ships it) to support more.\n */\nexport const PALBASE_EXTENSIONS = [\n // Search & text\n \"vector\", // pgvector: AI embeddings + vector similarity search (semantic search / RAG).\n // NB: the Postgres extension is named \"vector\", not \"pgvector\" — declare \"vector\".\n \"pg_trgm\", // trigram fuzzy / typo-tolerant text search\n \"unaccent\", // accent-insensitive text search\n \"citext\", // case-insensitive text type\n // Geospatial / location\n \"cube\", // multi-dimensional cubes (dependency of earthdistance)\n \"earthdistance\", // great-circle distance (needs cube)\n // Data types & structures\n \"hstore\", // key/value pairs in a single column\n \"ltree\", // hierarchical tree-structured labels\n // Indexing & constraints\n \"btree_gist\", // GiST operator classes for scalar types — needed for EXCLUDE\n // constraints that mix \"=\" with a range/&& overlap (e.g. no-double-booking).\n // Scheduling\n // Crypto / ids (also installed by default; listable for explicitness)\n \"pgcrypto\", // cryptographic functions (hashing, encryption)\n \"uuid-ossp\", // UUID generation functions\n] as const;\n\n/** A Postgres extension supported by Palbase (allowlist union). */\nexport type PalbaseExtension = (typeof PALBASE_EXTENSIONS)[number];\n\n/**\n * Extensions that depend on another extension. The deploy installs\n * dependencies first; declaring `earthdistance` without `cube` still works\n * because the deploy resolves the order, but listing both is clearer.\n */\nexport const EXTENSION_DEPENDENCIES: Partial<Record<PalbaseExtension, PalbaseExtension[]>> = {\n earthdistance: [\"cube\"],\n};\n\n/** Runtime guard: is `name` a supported Palbase extension? */\nexport function isPalbaseExtension(name: string): name is PalbaseExtension {\n return (PALBASE_EXTENSIONS as readonly string[]).includes(name);\n}\n","/**\n * A named raw-SQL DDL object declared in a schema file (`db/public.ts`,\n * `db/billing.ts`, …) for anything the typed DSL\n * cannot express (EXCLUDE, CHECK, partial/expression indexes, triggers, views).\n * The deploy emits `up` verbatim on the privileged DDL connection — same trust\n * posture as policy().using(). Tracked by NAME (not by diffing the body), so a\n * changed body needs a new name or an explicit drop+add.\n */\nexport interface RawConstraintDef {\n name: string;\n up: string;\n down?: string;\n}\n\nexport function raw(name: string, up: string, opts?: { down?: string }): RawConstraintDef {\n return { name, up, ...(opts?.down != null ? { down: opts.down } : {}) };\n}\n","/** Embedding sağlayıcı DESKRIPTORU — canlı istemci değil, düz veri: şemayla\n * birlikte serileşir, çağrıyı Go worker (yazma) ve engine (sorgu) yapar.\n * Adlandırma Vercel AI SDK'nın aynasıdır (openai.embedding(\"...\")) ama paket\n * bağımlılığı bilinçli olarak YOKTUR (spec C-3, UD-016). v1 sağlayıcı: openai (D-10). */\nexport interface EmbeddingModelRef {\n provider: \"openai\";\n model: string;\n dimensions?: number;\n apiKeyName?: string;\n baseURL?: string;\n}\n/** Chat/damıtma modeli DESKRIPTORU (C-11, D-019) — memory beyanının extract'i.\n * Embedding gibi düz veridir; çağrıyı worker yapar, anahtar vault'taki\n * OPENAI_API_KEY'dir (D-017: aynı sağlayıcı, yeni dış sistem yok). */\nexport interface ChatModelRef {\n provider: \"openai\";\n model: string;\n}\nexport const openai = {\n embedding(\n model: string,\n opts?: { dimensions?: number; apiKeyName?: string; baseURL?: string },\n ): EmbeddingModelRef {\n return { provider: \"openai\", model, apiKeyName: opts?.apiKeyName ?? \"OPENAI_API_KEY\",\n ...(opts?.dimensions !== undefined ? { dimensions: opts.dimensions } : {}),\n ...(opts?.baseURL !== undefined ? { baseURL: opts.baseURL } : {}) };\n },\n chat(model: string): ChatModelRef {\n return { provider: \"openai\", model };\n },\n};\n"],"mappings":";;;;;;;;AAyIO,IAAMA,eAAN,MAAMA;EAxIb,OAwIaA;;;EACFC;EAET,YAAYC,MAAc;AACxB,QAAIA,KAAKC,KAAI,MAAO,IAAI;AACtB,YAAM,IAAIC,MAAM,+GAAA;IAClB;AACA,SAAKH,OAAO;MAAEC;IAAK;EACrB;;EAGAG,MAAMC,MAA6B;AACjC,SAAKL,KAAKM,UAAUD,KAAKE,IAAI,CAACC,MAAAA;AAC5B,YAAMC,IAAID,EAAEE;AACZ,UAAID,EAAEE,SAAS,OAAO;AACpB,cAAM,IAAIR,MAAM,SAAS,KAAKH,KAAKC,IAAI,+GAA8E;MACvH;AACA,aAAOQ,EAAER;IACX,CAAA;AACA,WAAO;EACT;;;;;;;;EASAW,aAAaF,MAAoB;AAC/B,SAAKV,KAAKa,aAAaH;AACvB,WAAO;EACT;;EAGAI,MAAMJ,MAA2B;AAC/B,SAAKV,KAAKc,QAAQJ,KAA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,KAAKG,QACR,GAAGN,MAAMgB,MAAAA,CAAAA,eAAsBhB,MAAMa,UAAAA,CAAAA,SAAoBb,MAAMY,eAAAA,CAAAA,UACtDZ,MAAMiB,UAAAA,CAAAA;AACjB,WAAO;EACT;;EAGAV,UAAUtD,MAAoC;AAC5C,SAAKkD,KAAKI,YAAYtD,gBAAgBD,gBAAgBC,KAAKA,OAAOA;AAClE,WAAO;EACT;;;EAIAiE,GAAGC,MAAwB;AACzB,SAAKhB,KAAKK,aAAaW,SAAS;AAChC,WAAO;EACT;AACF;AAUO,SAASC,OAAOpC,MAAY;AACjC,SAAO,IAAIkB,cAAclB,IAAAA;AAC3B;AAFgBoC;;;ACpaT,IAAMC,qBAAqB;;EAEhC;;EAEA;EACA;EACA;;EAEA;EACA;;EAEA;EACA;;EAEA;;;;EAIA;EACA;;AAWK,IAAMC,yBAAgF;EAC3FC,eAAe;IAAC;;AAClB;AAGO,SAASC,mBAAmBC,MAAY;AAC7C,SAAQJ,mBAAyCK,SAASD,IAAAA;AAC5D;AAFgBD;;;ACjCT,SAASG,IAAIC,MAAcC,IAAYC,MAAwB;AACpE,SAAO;IAAEF;IAAMC;IAAI,GAAIC,MAAMC,QAAQ,OAAO;MAAEA,MAAMD,KAAKC;IAAK,IAAI,CAAC;EAAG;AACxE;AAFgBJ;;;ACIT,IAAMK,SAAS;EACpBC,UACEC,OACAC,MAAqE;AAErE,WAAO;MAAEC,UAAU;MAAUF;MAAOG,YAAYF,MAAME,cAAc;MAClE,GAAIF,MAAMG,eAAeC,SAAY;QAAED,YAAYH,KAAKG;MAAW,IAAI,CAAC;MACxE,GAAIH,MAAMK,YAAYD,SAAY;QAAEC,SAASL,KAAKK;MAAQ,IAAI,CAAC;IAAG;EACtE;EACAC,KAAKP,OAAa;AAChB,WAAO;MAAEE,UAAU;MAAUF;IAAM;EACrC;AACF;","names":["IndexBuilder","_def","name","trim","Error","on","cols","columns","map","c","e","expr","kind","onExpression","expression","where","desc","sort","asc","nulls","include","index","toPolicyDef","p","PolicyBuilder","TABLE_META","Symbol","for","defineTable","input","policies","exprCtx","Object","keys","rls","length","owned","colName","b","entries","builder","clone","create","getPrototypeOf","defineProperty","value","enumerable","writable","def","primaryKey","undefined","unique","raw","slice","checks","declaredIndexes","indexes","i","appendOnly","search","s","from","vector","model","Array","isArray","text","String","legs","leg","memory","values","ownerTable","handle","declaringSchemaOf","WeakMap","resolveReferences","tables","schemaName","table","selfRefColumn","references","qualifiedTableKey","column","referencesThunk","target","owner","targetColumn","find","targetSchema","get","defineSchema","set","m","t","into","subject","factCol","factDef","type","extensions","Set","exposed","PolicyExprRef","expr","bin","op","other","kind","left","right","toExpr","eq","neq","gt","gte","lt","lte","isNull","negated","and","others","parts","map","o","or","not","v","value","exprCtx","_columns","depth","ownTable","alias","col","name","auth","uid","lit","p","part","existsIn","table","predicate","meta","TABLE_META","inner","Object","keys","columns","outer","quote","replace","PolicyBuilder","_def","command","roles","using","withCheck","permissive","for","to","memberOf","membershipTable","foreignKey","options","Error","column","userColumn","as","mode","policy","PALBASE_EXTENSIONS","EXTENSION_DEPENDENCIES","earthdistance","isPalbaseExtension","name","includes","raw","name","up","opts","down","openai","embedding","model","opts","provider","apiKeyName","dimensions","undefined","baseURL","chat"]}
package/stack-images.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "33": [
3
- {
4
- "env": "PALBASE_PALSVC_IMAGE",
5
- "ref": "ghcr.io/palgroup/palbase/palsvc:0.42.0",
6
- "build": "cd v2 && DOCKER_BUILDKIT=1 docker build -t palbase-palsvc -f Dockerfile ."
7
- },
8
- {
9
- "env": "PALBASE_RUNTIME_IMAGE",
10
- "ref": "ghcr.io/palgroup/palbase/runtime-dev:0.42.0",
11
- "build": "cd v2/runtime && DOCKER_BUILDKIT=1 docker build --target dev -t palbase-runtime-dev -f Dockerfile ."
12
- },
13
- {
14
- "env": "PALBASE_EDGE_IMAGE",
15
- "ref": "ghcr.io/palgroup/palbase/edge:0.42.0",
16
- "build": "cd v2/deploy/envoy && DOCKER_BUILDKIT=1 docker build -t palbase-edge ."
17
- },
18
- {
19
- "env": "PALBASE_POSTGRES_IMAGE",
20
- "ref": "pgvector/pgvector:pg16",
21
- "build": ""
22
- }
23
- ]
24
- }