@palbase/backend 30.0.0 → 32.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 (67) hide show
  1. package/dist/bin/palbase-backend.cjs +136 -3
  2. package/dist/bin/palbase-backend.cjs.map +1 -1
  3. package/dist/bin/palbase-backend.js +7 -7
  4. package/dist/{chunk-TWX6JTGJ.js → chunk-26GH54D2.js} +3 -5
  5. package/dist/{chunk-TWX6JTGJ.js.map → chunk-26GH54D2.js.map} +1 -1
  6. package/dist/{chunk-5J5W75A6.js → chunk-5C5UCILO.js} +27 -325
  7. package/dist/chunk-5C5UCILO.js.map +1 -0
  8. package/dist/{chunk-VN7NMDUH.js → chunk-AZJIKCOR.js} +113 -15
  9. package/dist/chunk-AZJIKCOR.js.map +1 -0
  10. package/dist/{chunk-VVMJEVQP.js → chunk-BRLJOXWS.js} +2 -2
  11. package/dist/{chunk-3TUJWHC2.js → chunk-IXAX5CON.js} +378 -19
  12. package/dist/chunk-IXAX5CON.js.map +1 -0
  13. package/dist/{chunk-CGNN2PUH.js → chunk-KATPXCJ5.js} +37 -4
  14. package/dist/{chunk-CGNN2PUH.js.map → chunk-KATPXCJ5.js.map} +1 -1
  15. package/dist/chunk-KGP6ALIU.js +361 -0
  16. package/dist/chunk-KGP6ALIU.js.map +1 -0
  17. package/dist/chunk-XEGZ3S2Q.js +346 -0
  18. package/dist/chunk-XEGZ3S2Q.js.map +1 -0
  19. package/dist/{chunk-ENZ2RFFJ.js → chunk-Z4CZRMNF.js} +3 -310
  20. package/dist/chunk-Z4CZRMNF.js.map +1 -0
  21. package/dist/db/index.cjs +29 -0
  22. package/dist/db/index.cjs.map +1 -1
  23. package/dist/db/index.d.cts +1 -1
  24. package/dist/db/index.d.ts +1 -1
  25. package/dist/db/index.js +12 -13
  26. package/dist/engine/index.cjs +136 -3
  27. package/dist/engine/index.cjs.map +1 -1
  28. package/dist/engine/index.d.cts +3 -3
  29. package/dist/engine/index.d.ts +3 -3
  30. package/dist/engine/index.js +7 -7
  31. package/dist/{index-b-Q3l7W5.d.ts → index-BILC9WwS.d.ts} +9 -2
  32. package/dist/{index-8qy3kIuA.d.ts → index-BgWnP07a.d.ts} +119 -17
  33. package/dist/{index-Zi7MptvP.d.cts → index-CWGiJ2Up.d.cts} +9 -2
  34. package/dist/{index-DtCgaZAg.d.cts → index-DgYkdNT9.d.cts} +119 -17
  35. package/dist/index.cjs +87 -5
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +6 -23
  38. package/dist/index.d.ts +6 -23
  39. package/dist/index.js +48 -48
  40. package/dist/index.js.map +1 -1
  41. package/dist/openapi/index.d.cts +2 -2
  42. package/dist/openapi/index.d.ts +2 -2
  43. package/dist/openapi/index.js +3 -4
  44. package/dist/openapi/index.js.map +1 -1
  45. package/dist/{registry-CEYLH-Iz.d.cts → registry-BcRYIQ-R.d.cts} +1 -1
  46. package/dist/{registry-BGJ-Al6F.d.ts → registry-ClzjxIWy.d.ts} +1 -1
  47. package/dist/test/index.cjs +703 -14
  48. package/dist/test/index.cjs.map +1 -1
  49. package/dist/test/index.d.cts +59 -4
  50. package/dist/test/index.d.ts +59 -4
  51. package/dist/test/index.js +51 -13
  52. package/dist/test/index.js.map +1 -1
  53. package/docs/README.md +1 -1
  54. package/docs/database.md +54 -0
  55. package/docs/llms-full.txt +87 -1
  56. package/docs/schema.md +32 -0
  57. package/package.json +1 -1
  58. package/template/package.json +1 -1
  59. package/dist/chunk-3TUJWHC2.js.map +0 -1
  60. package/dist/chunk-5J5W75A6.js.map +0 -1
  61. package/dist/chunk-ENZ2RFFJ.js.map +0 -1
  62. package/dist/chunk-SG4UTNOP.js +0 -374
  63. package/dist/chunk-SG4UTNOP.js.map +0 -1
  64. package/dist/chunk-VN7NMDUH.js.map +0 -1
  65. package/dist/chunk-VXPNPVAG.js +0 -40
  66. package/dist/chunk-VXPNPVAG.js.map +0 -1
  67. /package/dist/{chunk-VVMJEVQP.js.map → chunk-BRLJOXWS.js.map} +0 -0
@@ -1,8 +1,8 @@
1
- import '../index-DtCgaZAg.cjs';
2
- export { A as App, g as AuthVerifier, B as BootRefused, h as CreateAppOptions, D as DECLARATION_REFUSAL, a as DeclarationRefused, E as EgressPolicy, j as EngineConfig, M as ModuleClients, R as RateLimiter, k as RequestDatabase, l as RouteEntry, m as RuntimeHooks, S as ScrubResult, n as SqlDriver, o as SqlTx, p as buildRouteTable, q as createApp, r as createLazyTransaction, s as createOps, t as createRequestDatabase, u as effectiveAuth, v as hostAllowed, w as installEgressFence, i as isDeclarationRefused, x as loadConfig, y as makeMemoryCache, z as matchRoute, F as quoteIdent, G as scrubSecrets, H as withTables } from '../index-Zi7MptvP.cjs';
1
+ import '../index-DgYkdNT9.cjs';
2
+ export { A as App, g as AuthVerifier, B as BootRefused, h as CreateAppOptions, D as DECLARATION_REFUSAL, a as DeclarationRefused, E as EgressPolicy, j as EngineConfig, M as ModuleClients, R as RateLimiter, k as RequestDatabase, l as RouteEntry, m as RuntimeHooks, S as ScrubResult, n as SqlDriver, o as SqlTx, p as buildRouteTable, q as createApp, r as createLazyTransaction, s as createOps, t as createRequestDatabase, u as effectiveAuth, v as hostAllowed, w as installEgressFence, i as isDeclarationRefused, x as loadConfig, y as makeMemoryCache, z as matchRoute, F as quoteIdent, G as scrubSecrets, H as withTables } from '../index-CWGiJ2Up.cjs';
3
3
  import '../db/env.cjs';
4
4
  import '../stack.cjs';
5
5
  import 'zod';
6
6
  import 'node:async_hooks';
7
7
  import '../module-Dl1KFVtc.cjs';
8
- import '../registry-CEYLH-Iz.cjs';
8
+ import '../registry-BcRYIQ-R.cjs';
@@ -1,8 +1,8 @@
1
- import '../index-8qy3kIuA.js';
2
- export { A as App, g as AuthVerifier, B as BootRefused, h as CreateAppOptions, D as DECLARATION_REFUSAL, a as DeclarationRefused, E as EgressPolicy, j as EngineConfig, M as ModuleClients, R as RateLimiter, k as RequestDatabase, l as RouteEntry, m as RuntimeHooks, S as ScrubResult, n as SqlDriver, o as SqlTx, p as buildRouteTable, q as createApp, r as createLazyTransaction, s as createOps, t as createRequestDatabase, u as effectiveAuth, v as hostAllowed, w as installEgressFence, i as isDeclarationRefused, x as loadConfig, y as makeMemoryCache, z as matchRoute, F as quoteIdent, G as scrubSecrets, H as withTables } from '../index-b-Q3l7W5.js';
1
+ import '../index-BgWnP07a.js';
2
+ export { A as App, g as AuthVerifier, B as BootRefused, h as CreateAppOptions, D as DECLARATION_REFUSAL, a as DeclarationRefused, E as EgressPolicy, j as EngineConfig, M as ModuleClients, R as RateLimiter, k as RequestDatabase, l as RouteEntry, m as RuntimeHooks, S as ScrubResult, n as SqlDriver, o as SqlTx, p as buildRouteTable, q as createApp, r as createLazyTransaction, s as createOps, t as createRequestDatabase, u as effectiveAuth, v as hostAllowed, w as installEgressFence, i as isDeclarationRefused, x as loadConfig, y as makeMemoryCache, z as matchRoute, F as quoteIdent, G as scrubSecrets, H as withTables } from '../index-BILC9WwS.js';
3
3
  import '../db/env.js';
4
4
  import '../stack.js';
5
5
  import 'zod';
6
6
  import 'node:async_hooks';
7
7
  import '../module-Dl1KFVtc.js';
8
- import '../registry-BGJ-Al6F.js';
8
+ import '../registry-ClzjxIWy.js';
@@ -16,17 +16,17 @@ import {
16
16
  quoteIdent,
17
17
  scrubSecrets,
18
18
  withTables
19
- } from "../chunk-VN7NMDUH.js";
19
+ } from "../chunk-AZJIKCOR.js";
20
20
  import {
21
21
  DECLARATION_REFUSAL,
22
22
  DeclarationRefused,
23
23
  isDeclarationRefused
24
- } from "../chunk-5J5W75A6.js";
25
- import "../chunk-SG4UTNOP.js";
26
- import "../chunk-3TUJWHC2.js";
27
- import "../chunk-VVMJEVQP.js";
28
- import "../chunk-CGNN2PUH.js";
29
- import "../chunk-VXPNPVAG.js";
24
+ } from "../chunk-5C5UCILO.js";
25
+ import "../chunk-XEGZ3S2Q.js";
26
+ import "../chunk-KGP6ALIU.js";
27
+ import "../chunk-IXAX5CON.js";
28
+ import "../chunk-BRLJOXWS.js";
29
+ import "../chunk-KATPXCJ5.js";
30
30
  export {
31
31
  AuthVerifier,
32
32
  BootRefused,
@@ -1,6 +1,6 @@
1
- import { D as DBClient, a as DBOps, T as TxPlanBody, b as TxPlanResponse, A as AuthSpec, C as CacheClient, c as RuntimeServices, _ as __runWithRuntime, d as __requestALS } from './index-8qy3kIuA.js';
1
+ import { D as DBClient, b as DBOps, T as TxPlanBody, c as TxPlanResponse, A as AuthSpec, C as CacheClient, a as RuntimeServices, _ as __runWithRuntime, d as __requestALS } from './index-BgWnP07a.js';
2
2
  import { T as Token } from './module-Dl1KFVtc.js';
3
- import { R as RouteMeta } from './registry-BGJ-Al6F.js';
3
+ import { R as RouteMeta } from './registry-ClzjxIWy.js';
4
4
 
5
5
  /**
6
6
  * engine/config.ts — settings from the environment, and the gate that refuses
@@ -174,6 +174,13 @@ interface FindManyOptions {
174
174
  /** Projeksiyon (FR-009): verilmezse `SELECT *`. Kolon adları ŞEMAYA karşı
175
175
  * doğrulanır — bilinmeyen ad SQL'e ulaşmadan, adıyla reddedilir. */
176
176
  select?: string[];
177
+ /**
178
+ * İLİŞKİLİ SATIRLARI da getir — TEK sorguda, LATERAL ile.
179
+ *
180
+ * `has` ilişki üzerinden SÜZER, `with` GETİRİR. İkisi aynı ilişki grafiğini
181
+ * okuyor (yabancı anahtarlardan türetilmiş), yani ilişki adları aynı.
182
+ */
183
+ with?: Record<string, unknown>;
177
184
  limit?: number;
178
185
  /** Rows to skip before the page starts. Only meaningful with `limit`, and
179
186
  * refused without it — see `offsetClause`. */
@@ -1,4 +1,4 @@
1
- import { Tables, TableTypes, Schemas } from './db/env.js';
1
+ import { Schemas, Tables, TableTypes } from './db/env.js';
2
2
  import { ZodSchema, z } from 'zod';
3
3
  import { PalbaseFlagKey, Buckets, BucketTypes, PalbaseSecretName } from './stack.js';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -226,6 +226,13 @@ interface ColumnDef {
226
226
  * is never serialized into a migration. It exists so the row surface can hand
227
227
  * back the type the application actually works with.
228
228
  */
229
+ /**
230
+ * The named codec this column declares (FR-001). Unlike `transform`, the NAME
231
+ * survives into the runtime object, so `makeEnvDts` can emit the matching
232
+ * TypeScript type instead of falling back to the storage type. Not part of
233
+ * the DDL: the column's Postgres type is unchanged.
234
+ */
235
+ codec?: CodecName;
229
236
  transform?: ColumnTransform;
230
237
  }
231
238
  /**
@@ -240,6 +247,21 @@ interface ColumnTransform<T = unknown> {
240
247
  fromDb: (value: unknown) => T;
241
248
  toDb: (value: T) => unknown;
242
249
  }
250
+ /**
251
+ * The closed set of named column codecs (FR-001).
252
+ *
253
+ * WHY A CLOSED SET rather than `.transform<T>()`. A transform's target type is
254
+ * a TYPE parameter — erased at runtime — so the generator that reads the
255
+ * bundled schema object cannot learn it. `palbase-env.d.ts` therefore said
256
+ * `string` while the engine handed the application a number, and a consumer
257
+ * project wrote a hand-rolled codec module plus 141 call sites to compensate.
258
+ *
259
+ * A codec is NAMED instead of typed: the name lands in `_def.codec`, travels in
260
+ * the runtime object to every reader, and BOTH the conversion and the emitted
261
+ * TypeScript type are derived from it. One declaration, one truth, and no way
262
+ * for the two to disagree.
263
+ */
264
+ type CodecName = 'number' | 'decimal';
243
265
  declare const __colKind: unique symbol;
244
266
  declare const __colNullable: unique symbol;
245
267
  declare const __colHasDefault: unique symbol;
@@ -418,6 +440,22 @@ declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean
418
440
  * A transform is a PROJECTION, never a constraint: it lives only in this
419
441
  * process, so it can neither validate nor migrate what is stored.
420
442
  */
443
+ /**
444
+ * Surface this exact-precision column as a JS `number` (FR-001).
445
+ *
446
+ * `numeric`/`bigint` arrive as strings because a JS number cannot hold their
447
+ * full range — correct, and exactly why this exists: application code that
448
+ * does arithmetic on the column otherwise rewrites the same `Number(row.x)` /
449
+ * `String(v)` pair in every caller, and each rewrite is a place the two
450
+ * directions can drift apart.
451
+ */
452
+ asNumber(): ColumnBuilder<K, N, D, E, P, number>;
453
+ /**
454
+ * Surface this exact-precision column as a `string` — the value Postgres
455
+ * sent, DECLARED rather than defaulted (FR-001).
456
+ */
457
+ asDecimal(): ColumnBuilder<K, N, D, E, P, string>;
458
+ private withCodec;
421
459
  transform<Target>(fns: ColumnTransform<Target>): ColumnBuilder<K, N, D, E, P, Target>;
422
460
  }
423
461
  /**
@@ -741,6 +779,22 @@ interface PolicyDef {
741
779
  withCheck: string | PolicyExpr | null;
742
780
  permissive: boolean;
743
781
  }
782
+ /**
783
+ * Bir politikanın adreslenebileceği Postgres rolleri.
784
+ *
785
+ * Serbest string DEĞİL, çünkü küme SABİT: bunları palbase provision ediyor,
786
+ * kiracı yeni bir PG rolü yaratmıyor. Serbest bırakıldığında `authenitcated`
787
+ * gibi bir harf hatası derlenip migration'a kadar gidiyordu — Drizzle'da da
788
+ * aynı boşluk ölçüldü (`to` tipi `(string & {})`, yazım hatası DDL'e geçiyor).
789
+ *
790
+ * Çalışma anı zaten fail-closed (bilinmeyen rol kapıyı kapatıyor,
791
+ * `session_rls_fail_closed_integration_test.go`); bu, aynı cevabı derleme
792
+ * anına taşıyor.
793
+ *
794
+ * `backend_*` ikizleri elle YAZILMAZ — `NormalizeDeclaredPolicies` onları
795
+ * kendisi ekliyor; yine de kabul ediliyor ki elle yazan kod kırılmasın.
796
+ */
797
+ type PolicyRole = "anon" | "authenticated" | "service_role" | "backend_anon" | "backend_authenticated" | "backend_service_role";
744
798
  declare class PolicyBuilder {
745
799
  readonly _def: PolicyDef;
746
800
  constructor(name: string);
@@ -755,7 +809,7 @@ declare class PolicyBuilder {
755
809
  * policy("p").to("authenticated", "service_role")
756
810
  * policy("p").to() // PUBLIC
757
811
  */
758
- to(...roles: string[]): this;
812
+ to(...roles: PolicyRole[]): this;
759
813
  /**
760
814
  * `USING (...)` satır görünürlüğü ifadesi.
761
815
  *
@@ -2622,15 +2676,6 @@ interface RequestStore {
2622
2676
  * client's retry replay its first result instead of charging twice. */
2623
2677
  idempotencyKey?: string | null;
2624
2678
  }
2625
- /**
2626
- * Per-request store. The persistent runtime runs each request inside
2627
- * {@link __runWithRuntime}, so every async continuation of that request reads
2628
- * its OWN `runtime` (and any other request-scoped fields the runtime adds).
2629
- *
2630
- * Exported with a `__` prefix so the runtime (worker.js) shares the SAME ALS
2631
- * instance across the one module instance — two ALS instances would silently
2632
- * not see each other's stores. NOT part of the public author-facing API.
2633
- */
2634
2679
  declare const __requestALS: AsyncLocalStorage<RequestStore>;
2635
2680
  /** Install the live clients in the process-global fallback slot.
2636
2681
  *
@@ -2737,13 +2782,15 @@ interface RecoOps {
2737
2782
  /**
2738
2783
  * The project's own Postgres (pgx, schema `env_<envId>`).
2739
2784
  *
2740
- * Typed by default: `Database.tables.<name>.insert({...})` is typed against
2785
+ * Typed by default: `Database.public.<name>.insert({...})` is typed against
2741
2786
  * the project's generated `palbase-env.d.ts` with NO import and NO generic.
2742
- * The raw string ops (`query`/`insert`/`update`/`delete`/`findById`/`findMany`)
2743
- * are also available for dynamic table names and read-only SQL.
2787
+ * The raw string ops (`Database.$query`/`$insert`/`$update`/`$delete`/
2788
+ * `$findById`/`$findMany`) are also available for read-only SQL and for a table
2789
+ * name only known at runtime — which the typed surface cannot express past
2790
+ * seven tables (see `db/tx-union-key.test-d.ts`).
2744
2791
  *
2745
2792
  * RLS is enforced by default (the runtime runs each op as `authenticated` with
2746
- * the verified user's claims). To bypass RLS, call `Database.asService()` —
2793
+ * the verified user's claims). To bypass RLS, call `Database.$asService()` —
2747
2794
  * explicit and greppable — which runs as the `service_role` (BYPASSRLS).
2748
2795
  *
2749
2796
  * @example
@@ -3376,6 +3423,40 @@ type HasOnly<Rels> = [unknown] extends [Rels] ? unknown : [keyof Rels] extends [
3376
3423
  * (ölçüldü: kapı yeşil, çalışma anında "böyle bir ilişki yok" hatası).
3377
3424
  */
3378
3425
  type HasBranch<Row, Rels> = [unknown] extends [Rels] ? never : [keyof Rels] extends [never] ? never : WhereWithRelations<Row, Rels>;
3426
+ /**
3427
+ * `with` — İLİŞKİLİ SATIRLARI GETİR (`has` süzer, `with` getirir).
3428
+ *
3429
+ * `true` bütün kolonları, bir nesne ise `select`/`where`/`orderBy`/`limit` ile
3430
+ * daraltılmış hâlini getiriyor. Tek sorgu: LATERAL + `json_agg`.
3431
+ */
3432
+ type WithOpts<To> = {
3433
+ select?: readonly Extract<keyof RelatedRow<To>, string>[];
3434
+ where?: WhereFilter<RelatedRow<To>>;
3435
+ orderBy?: OrderBySpec<RelatedRow<To>> | readonly OrderBySpec<RelatedRow<To>>[];
3436
+ limit?: number;
3437
+ };
3438
+ type WithInput<Rels> = {
3439
+ [R in keyof Rels]?: Rels[R] extends {
3440
+ to: infer To;
3441
+ } ? true | WithOpts<To> : never;
3442
+ };
3443
+ /** Bir `with` dalının DÖNÜŞ tipi — `many` dizi, `one` tekil ya da null. */
3444
+ type WithRowOf<Rels, R extends keyof Rels, Q> = Rels[R] extends {
3445
+ to: infer To;
3446
+ kind: infer K;
3447
+ } ? (Q extends {
3448
+ select: readonly (infer C extends keyof RelatedRow<To>)[];
3449
+ } ? Pick<RelatedRow<To>, C> : RelatedRow<To>) extends infer Row ? [K] extends ["many"] ? Row[] : Row | null : never : never;
3450
+ /**
3451
+ * `with` istenmediğinde `unknown` — kesişimde YOK OLSUN diye.
3452
+ *
3453
+ * Boş bir nesne (`{}`) dönseydi `Pick<Row, K> & {}` satır tipini "aynı ama
3454
+ * özdeş değil" hâle getirirdi ve tam eşitlik iddiaları kırılırdı. Ölçüldü:
3455
+ * `toEqualTypeOf` dört yerde düştü.
3456
+ */
3457
+ type WithResult<Rels, W> = [keyof W] extends [never] ? unknown : {
3458
+ [R in keyof W & keyof Rels]: WithRowOf<Rels, R, W[R]>;
3459
+ };
3379
3460
  type QueryInput<Row, K extends keyof Row = keyof Row, Rels = unknown> = {
3380
3461
  /**
3381
3462
  * Filtre — ya tipli filtre dili ya da bir `sqlFragment` (FR-018). İkisi de
@@ -3383,6 +3464,25 @@ type QueryInput<Row, K extends keyof Row = keyof Row, Rels = unknown> = {
3383
3464
  * yolu değil (P1).
3384
3465
  */
3385
3466
  where?: WhereFilter<Row> | SqlFragment | HasBranch<Row, Rels>;
3467
+ /**
3468
+ * İlişkili satırları da getir — TEK sorguda.
3469
+ *
3470
+ * ```ts
3471
+ * const rows = await Database.public.users.findMany({
3472
+ * where: { active: true },
3473
+ * with: { orders: { select: ["id", "amount"], limit: 5 } },
3474
+ * });
3475
+ * rows[0].orders[0].amount; // string — KAYIPSIZ
3476
+ * ```
3477
+ *
3478
+ * `many` ilişki DİZİ döner (boşsa `[]`, `null` değil — `.map()` guard
3479
+ * istemesin); `one` ilişki tekil satır ya da `null`.
3480
+ *
3481
+ * PARA: `numeric`/`bigint` kolonları JSON'a `::text` ile giriyor. Cast
3482
+ * olmadan `numeric` bir JSON SAYISI olur ve kesinliğini kaybeder — ölçüldü,
3483
+ * `100000000000000000000000000` → `1e+26`.
3484
+ */
3485
+ with?: [unknown] extends [Rels] ? never : [keyof Rels] extends [never] ? never : WithInput<Rels>;
3386
3486
  /**
3387
3487
  * Projeksiyon (FR-009): yalnız bu kolonlar çekilir ve DÖNÜŞ TİPİ buna daralır.
3388
3488
  *
@@ -3655,7 +3755,9 @@ interface EnvTypedTableBase<T extends TableTypes> {
3655
3755
  findById(id: string): Promise<T["row"] | null>;
3656
3756
  /** Rows matching the filter. See {@link WhereFilter} / {@link FindManyOpts} —
3657
3757
  * this declaration is what makes the engine's operators callable. */
3658
- findMany<K extends keyof T["row"] = keyof T["row"]>(q?: QueryInput<T["row"], K, RelsOf<T>>): Promise<Pick<T["row"], K>[]>;
3758
+ findMany<K extends keyof T["row"] = keyof T["row"], W extends WithInput<RelsOf<T>> = Record<never, never>>(q?: QueryInput<T["row"], K, RelsOf<T>> & {
3759
+ with?: W;
3760
+ }): Promise<Array<Pick<T["row"], K> & WithResult<RelsOf<T>, W>>>;
3659
3761
  /**
3660
3762
  * Update every matching row in one statement; an empty filter is refused.
3661
3763
  *
@@ -5160,4 +5262,4 @@ type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise
5160
5262
  */
5161
5263
  type AuthSpec = boolean | Partial<AuthConfig>;
5162
5264
 
5163
- export { NotFound as $, type AuthSpec as A, BadRequest as B, type CacheClient as C, type DBClient as D, EXTENSION_DEPENDENCIES as E, type ErrorMap as F, type ErrorThrowers as G, HttpError as H, type FileContext as I, Flags as J, Forbidden as K, type HttpMethod as L, IndexBuilder as M, type IndexDef as N, type InsertShape as O, type PalbaseResult as P, type LifecycleHook as Q, type RateLimitConfig as R, type SchemaDef as S, type TxPlanBody as T, Log as U, type Logger as V, type Materialized as W, type Middleware as X, type MiddlewareContext as Y, type MiddlewareHandler as Z, __runWithRuntime as _, type DBOps as a, type PalbaseListLinksOptions as a$, Notifications as a0, type OnDeleteAction as a1, PALBASE_EXTENSIONS as a2, type PBRequest as a3, PalError as a4, type PalbaseAnalyticsClient as a5, type PalbaseAnalyticsManagementNamespace as a6, type PalbaseAnalyticsProperties as a7, type PalbaseAnalyticsQueryNamespace as a8, type PalbaseAttestAndroidParams as a9, type PalbaseEventsQueryInput as aA, type PalbaseEventsResult as aB, type PalbaseExtension as aC, type PalbaseFileObject as aD, type PalbaseFlag as aE, type PalbaseFlagContext as aF, type PalbaseFlagSource as aG, type PalbaseFlagValue as aH, type PalbaseFlagVariant as aI, type PalbaseFlagsClient as aJ, type PalbaseFlagsServiceClient as aK, type PalbaseFunctionsClient as aL, type PalbaseFunnelQueryInput as aM, type PalbaseFunnelResult as aN, type PalbaseIdentifyTraits as aO, type PalbaseInboxClient as aP, type PalbaseInboxListOptions as aQ, type PalbaseInboxListResult as aR, type PalbaseInboxMessage as aS, type PalbaseInboxSendParams as aT, type PalbaseInboxSendResponse as aU, type PalbaseInitialLink as aV, type PalbaseInvokeOptions as aW, type PalbaseLink as aX, type PalbaseLinkAnalytics as aY, type PalbaseLinkDetails as aZ, type PalbaseLinksClient as a_, type PalbaseAttestAndroidResult as aa, type PalbaseAttestiOSParams as ab, type PalbaseAttestiOSResult as ac, type PalbaseAuthAdminClient as ad, type PalbaseAuthClient as ae, type PalbaseBatchOverrideOperation as af, type PalbaseBatchSetOverridesResult as ag, type PalbaseBindDeviceParams as ah, type PalbaseBucketClient as ai, type PalbaseClearAllOverridesResult as aj, type PalbaseClearOverrideResult as ak, type PalbaseCohortQueryInput as al, type PalbaseCohortResult as am, type PalbaseCollectionRef as an, type PalbaseCountQueryInput as ao, type PalbaseCountResult as ap, type PalbaseCreateLinkParams as aq, type PalbaseDeviceInfo as ar, type PalbaseDeviceTokenView as as, type PalbaseDocsClient as at, type PalbaseDocumentRef as au, type PalbaseDocumentSnapshot as av, type PalbaseEmailClient as aw, type PalbaseEmailSendParams as ax, type PalbaseEmailSendResponse as ay, type PalbaseEventNamesResult as az, type TxPlanResponse as b, type TxNow as b$, type PalbaseListLinksResult as b0, type PalbaseListOptions as b1, type PalbaseMatchParams as b2, type PalbaseMultiChannelResponse as b3, type PalbaseNotificationsClient as b4, type PalbaseOverviewResult as b5, type PalbasePreferences as b6, type PalbasePreferencesClient as b7, type PalbasePushClient as b8, type PalbasePushSendParams as b9, type PolicyCommand as bA, type PolicyDef as bB, type PolicyExprCtx as bC, PolicyExprRef as bD, type PolicyMode as bE, type PolicyOperand as bF, type RawConstraintDef as bG, Realtime as bH, type Ref as bI, type RequestStore as bJ, type RowShape as bK, Secrets as bL, type SecretsService as bM, SerializationFailure as bN, type SetShape as bO, type SetValue as bP, type ShutdownRunner as bQ, type SqlFragment as bR, Storage as bS, TABLE_META as bT, type TableDef as bU, type TableHandle as bV, type TableInput as bW, TooManyRequests as bX, type TxColumnExpr as bY, type TxInsertShape as bZ, type TxInsertValue as b_, type PalbasePushSendResponse as ba, type PalbaseQrCodeOptions as bb, type PalbaseQuerySnapshot as bc, type PalbaseRealtimeClient as bd, type PalbaseRegisterDeviceParams as be, type PalbaseRetentionQueryInput as bf, type PalbaseRetentionResult as bg, type PalbaseSession as bh, type PalbaseSetOverrideResult as bi, type PalbaseSetOverridesResult as bj, type PalbaseSignedUrlResponse as bk, type PalbaseSmsClient as bl, type PalbaseSmsSendParams as bm, type PalbaseSmsSendResponse as bn, type PalbaseStorageClient as bo, type PalbaseTransformOptions as bp, type PalbaseUpdateLinkParams as bq, type PalbaseUploadOptions as br, type PalbaseUser as bs, type PalbaseUserDetailResult as bt, type PalbaseUsersQueryInput as bu, type PalbaseUsersResult as bv, type PalbaseVerifyRequestSignatureParams as bw, type PalbaseWhereOperator as bx, type PolicyBinOp as by, PolicyBuilder as bz, type RuntimeServices as c, withRetry as c$, type TxPlan as c0, TxPlanError as c1, type TxPlanHandle as c2, type TxPlanOpResult as c3, type TxPlanRejection as c4, TxRefError as c5, type TxRow as c6, type TxRows as c7, type TxSelectOptions as c8, type TxSetShape as c9, defineSchema as cA, defineTable as cB, enumType as cC, exprCtx as cD, inc as cE, increment as cF, index as cG, installationRef as cH, integer as cI, isPalbaseExtension as cJ, isRetryable as cK, jsonb as cL, makeTypedDB as cM, now as cN, numeric as cO, onShutdown as cP, onStart as cQ, openai as cR, ownedByUser as cS, policy as cT, raw as cU, sqlFragment as cV, text as cW, timestamp as cX, userRef as cY, uuid as cZ, vector as c_, type TxSetValue as ca, type TxTable as cb, type TxTables as cc, type TxWhere as cd, type TxWireExpr as ce, type TxWireGuard as cf, type TxWireOp as cg, type TxWireRef as ch, type TxWireValue as ci, type TypedDB as cj, type TypedTable as ck, type TypedTx as cl, Unauthorized as cm, UniqueViolation as cn, type User as co, type VerifiedDevice as cp, __getRuntime as cq, __resetLifecycleHooks as cr, __runStartHooks as cs, __setRuntime as ct, bigint as cu, boolean as cv, col as cw, dec as cx, decrement as cy, defineMiddleware as cz, __requestALS as d, type PolicyExpr as e, type AnyColumn as f, Auth as g, type AuthConfig as h, Cache as i, type ClientInfo as j, type ColRef as k, ColumnBuilder as l, type ColumnDef as m, type ColumnMap as n, type ColumnType as o, Conflict as p, Database as q, DeadlockDetected as r, Documents as s, type EmbeddingModelRef as t, type EnvSchemas as u, type EnvServiceDatabase as v, type EnvTables as w, type EnvTypedDatabase as x, type EnvTypedTable as y, type ErrorDef as z };
5265
+ export { type Materialized as $, type AuthSpec as A, BadRequest as B, type CacheClient as C, type DBClient as D, type EnvServiceDatabase as E, type EnvTypedTable as F, type ErrorDef as G, HttpError as H, type ErrorMap as I, type ErrorThrowers as J, type FileContext as K, type FindManyOpts as L, Flags as M, Forbidden as N, type HttpMethod as O, type PalbaseResult as P, IndexBuilder as Q, type RateLimitConfig as R, type SchemaDef as S, type TxPlanBody as T, type IndexDef as U, type InsertShape as V, type InsertValues as W, type LifecycleHook as X, Log as Y, type Logger as Z, __runWithRuntime as _, type RuntimeServices as a, type PalbaseInitialLink as a$, type Middleware as a0, type MiddlewareContext as a1, type MiddlewareHandler as a2, type MutateInput as a3, NotFound as a4, Notifications as a5, type OnDeleteAction as a6, type OrderBySpec as a7, PALBASE_EXTENSIONS as a8, type PBRequest as a9, type PalbaseDocumentRef as aA, type PalbaseDocumentSnapshot as aB, type PalbaseEmailClient as aC, type PalbaseEmailSendParams as aD, type PalbaseEmailSendResponse as aE, type PalbaseEventNamesResult as aF, type PalbaseEventsQueryInput as aG, type PalbaseEventsResult as aH, type PalbaseExtension as aI, type PalbaseFileObject as aJ, type PalbaseFlag as aK, type PalbaseFlagContext as aL, type PalbaseFlagSource as aM, type PalbaseFlagValue as aN, type PalbaseFlagVariant as aO, type PalbaseFlagsClient as aP, type PalbaseFlagsServiceClient as aQ, type PalbaseFunctionsClient as aR, type PalbaseFunnelQueryInput as aS, type PalbaseFunnelResult as aT, type PalbaseIdentifyTraits as aU, type PalbaseInboxClient as aV, type PalbaseInboxListOptions as aW, type PalbaseInboxListResult as aX, type PalbaseInboxMessage as aY, type PalbaseInboxSendParams as aZ, type PalbaseInboxSendResponse as a_, PalError as aa, type PalbaseAnalyticsClient as ab, type PalbaseAnalyticsManagementNamespace as ac, type PalbaseAnalyticsProperties as ad, type PalbaseAnalyticsQueryNamespace as ae, type PalbaseAttestAndroidParams as af, type PalbaseAttestAndroidResult as ag, type PalbaseAttestiOSParams as ah, type PalbaseAttestiOSResult as ai, type PalbaseAuthAdminClient as aj, type PalbaseAuthClient as ak, type PalbaseBatchOverrideOperation as al, type PalbaseBatchSetOverridesResult as am, type PalbaseBindDeviceParams as an, type PalbaseBucketClient as ao, type PalbaseClearAllOverridesResult as ap, type PalbaseClearOverrideResult as aq, type PalbaseCohortQueryInput as ar, type PalbaseCohortResult as as, type PalbaseCollectionRef as at, type PalbaseCountQueryInput as au, type PalbaseCountResult as av, type PalbaseCreateLinkParams as aw, type PalbaseDeviceInfo as ax, type PalbaseDeviceTokenView as ay, type PalbaseDocsClient as az, type DBOps as b, type TableDef as b$, type PalbaseInvokeOptions as b0, type PalbaseLink as b1, type PalbaseLinkAnalytics as b2, type PalbaseLinkDetails as b3, type PalbaseLinksClient as b4, type PalbaseListLinksOptions as b5, type PalbaseListLinksResult as b6, type PalbaseListOptions as b7, type PalbaseMatchParams as b8, type PalbaseMultiChannelResponse as b9, type PalbaseUsersQueryInput as bA, type PalbaseUsersResult as bB, type PalbaseVerifyRequestSignatureParams as bC, type PalbaseWhereOperator as bD, type PolicyBinOp as bE, PolicyBuilder as bF, type PolicyCommand as bG, type PolicyDef as bH, type PolicyExprCtx as bI, PolicyExprRef as bJ, type PolicyMode as bK, type PolicyOperand as bL, type QueryInput as bM, type RawConstraintDef as bN, Realtime as bO, type Ref as bP, type RequestStore as bQ, type RowShape as bR, Secrets as bS, type SecretsService as bT, SerializationFailure as bU, type SetShape as bV, type SetValue as bW, type ShutdownRunner as bX, type SqlFragment as bY, Storage as bZ, TABLE_META as b_, type PalbaseNotificationsClient as ba, type PalbaseOverviewResult as bb, type PalbasePreferences as bc, type PalbasePreferencesClient as bd, type PalbasePushClient as be, type PalbasePushSendParams as bf, type PalbasePushSendResponse as bg, type PalbaseQrCodeOptions as bh, type PalbaseQuerySnapshot as bi, type PalbaseRealtimeClient as bj, type PalbaseRegisterDeviceParams as bk, type PalbaseRetentionQueryInput as bl, type PalbaseRetentionResult as bm, type PalbaseSession as bn, type PalbaseSetOverrideResult as bo, type PalbaseSetOverridesResult as bp, type PalbaseSignedUrlResponse as bq, type PalbaseSmsClient as br, type PalbaseSmsSendParams as bs, type PalbaseSmsSendResponse as bt, type PalbaseStorageClient as bu, type PalbaseTransformOptions as bv, type PalbaseUpdateLinkParams as bw, type PalbaseUploadOptions as bx, type PalbaseUser as by, type PalbaseUserDetailResult as bz, type TxPlanResponse as c, ownedByUser as c$, type TableHandle as c0, type TableInput as c1, TooManyRequests as c2, type TxColumnExpr as c3, type TxInsertShape as c4, type TxInsertValue as c5, type TxNow as c6, type TxPlan as c7, TxPlanError as c8, type TxPlanHandle as c9, __resetLifecycleHooks as cA, __runStartHooks as cB, __setRuntime as cC, bigint as cD, boolean as cE, col as cF, dec as cG, decrement as cH, defineMiddleware as cI, defineSchema as cJ, defineTable as cK, enumType as cL, exprCtx as cM, inc as cN, increment as cO, index as cP, installationRef as cQ, integer as cR, isPalbaseExtension as cS, isRetryable as cT, jsonb as cU, makeTypedDB as cV, now as cW, numeric as cX, onShutdown as cY, onStart as cZ, openai as c_, type TxPlanOpResult as ca, type TxPlanRejection as cb, TxRefError as cc, type TxRow as cd, type TxRows as ce, type TxSelectOptions as cf, type TxSetShape as cg, type TxSetValue as ch, type TxTable as ci, type TxTables as cj, type TxWhere as ck, type TxWireExpr as cl, type TxWireGuard as cm, type TxWireOp as cn, type TxWireRef as co, type TxWireValue as cp, type TypedDB as cq, type TypedTable as cr, type TypedTx as cs, Unauthorized as ct, UniqueViolation as cu, type User as cv, type VerifiedDevice as cw, type WhereFilter as cx, type WhereOp as cy, __getRuntime as cz, __requestALS as d, policy as d0, raw as d1, sqlFragment as d2, text as d3, timestamp as d4, userRef as d5, uuid as d6, vector as d7, withRetry as d8, type PolicyExpr as e, type AggregateInput as f, type AggregateResult as g, type AnyColumn as h, Auth as i, type AuthConfig as j, Cache as k, type ClientInfo as l, type ColRef as m, ColumnBuilder as n, type ColumnDef as o, type ColumnMap as p, type ColumnType as q, Conflict as r, Database as s, DeadlockDetected as t, Documents as u, EXTENSION_DEPENDENCIES as v, type EmbeddingModelRef as w, type EnvSchemas as x, type EnvTables as y, type EnvTypedDatabase as z };
@@ -1,6 +1,6 @@
1
- import { D as DBClient, a as DBOps, T as TxPlanBody, b as TxPlanResponse, A as AuthSpec, C as CacheClient, c as RuntimeServices, _ as __runWithRuntime, d as __requestALS } from './index-DtCgaZAg.cjs';
1
+ import { D as DBClient, b as DBOps, T as TxPlanBody, c as TxPlanResponse, A as AuthSpec, C as CacheClient, a as RuntimeServices, _ as __runWithRuntime, d as __requestALS } from './index-DgYkdNT9.cjs';
2
2
  import { T as Token } from './module-Dl1KFVtc.cjs';
3
- import { R as RouteMeta } from './registry-CEYLH-Iz.cjs';
3
+ import { R as RouteMeta } from './registry-BcRYIQ-R.cjs';
4
4
 
5
5
  /**
6
6
  * engine/config.ts — settings from the environment, and the gate that refuses
@@ -174,6 +174,13 @@ interface FindManyOptions {
174
174
  /** Projeksiyon (FR-009): verilmezse `SELECT *`. Kolon adları ŞEMAYA karşı
175
175
  * doğrulanır — bilinmeyen ad SQL'e ulaşmadan, adıyla reddedilir. */
176
176
  select?: string[];
177
+ /**
178
+ * İLİŞKİLİ SATIRLARI da getir — TEK sorguda, LATERAL ile.
179
+ *
180
+ * `has` ilişki üzerinden SÜZER, `with` GETİRİR. İkisi aynı ilişki grafiğini
181
+ * okuyor (yabancı anahtarlardan türetilmiş), yani ilişki adları aynı.
182
+ */
183
+ with?: Record<string, unknown>;
177
184
  limit?: number;
178
185
  /** Rows to skip before the page starts. Only meaningful with `limit`, and
179
186
  * refused without it — see `offsetClause`. */
@@ -1,4 +1,4 @@
1
- import { Tables, TableTypes, Schemas } from './db/env.cjs';
1
+ import { Schemas, Tables, TableTypes } from './db/env.cjs';
2
2
  import { ZodSchema, z } from 'zod';
3
3
  import { PalbaseFlagKey, Buckets, BucketTypes, PalbaseSecretName } from './stack.cjs';
4
4
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -226,6 +226,13 @@ interface ColumnDef {
226
226
  * is never serialized into a migration. It exists so the row surface can hand
227
227
  * back the type the application actually works with.
228
228
  */
229
+ /**
230
+ * The named codec this column declares (FR-001). Unlike `transform`, the NAME
231
+ * survives into the runtime object, so `makeEnvDts` can emit the matching
232
+ * TypeScript type instead of falling back to the storage type. Not part of
233
+ * the DDL: the column's Postgres type is unchanged.
234
+ */
235
+ codec?: CodecName;
229
236
  transform?: ColumnTransform;
230
237
  }
231
238
  /**
@@ -240,6 +247,21 @@ interface ColumnTransform<T = unknown> {
240
247
  fromDb: (value: unknown) => T;
241
248
  toDb: (value: T) => unknown;
242
249
  }
250
+ /**
251
+ * The closed set of named column codecs (FR-001).
252
+ *
253
+ * WHY A CLOSED SET rather than `.transform<T>()`. A transform's target type is
254
+ * a TYPE parameter — erased at runtime — so the generator that reads the
255
+ * bundled schema object cannot learn it. `palbase-env.d.ts` therefore said
256
+ * `string` while the engine handed the application a number, and a consumer
257
+ * project wrote a hand-rolled codec module plus 141 call sites to compensate.
258
+ *
259
+ * A codec is NAMED instead of typed: the name lands in `_def.codec`, travels in
260
+ * the runtime object to every reader, and BOTH the conversion and the emitted
261
+ * TypeScript type are derived from it. One declaration, one truth, and no way
262
+ * for the two to disagree.
263
+ */
264
+ type CodecName = 'number' | 'decimal';
243
265
  declare const __colKind: unique symbol;
244
266
  declare const __colNullable: unique symbol;
245
267
  declare const __colHasDefault: unique symbol;
@@ -418,6 +440,22 @@ declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean
418
440
  * A transform is a PROJECTION, never a constraint: it lives only in this
419
441
  * process, so it can neither validate nor migrate what is stored.
420
442
  */
443
+ /**
444
+ * Surface this exact-precision column as a JS `number` (FR-001).
445
+ *
446
+ * `numeric`/`bigint` arrive as strings because a JS number cannot hold their
447
+ * full range — correct, and exactly why this exists: application code that
448
+ * does arithmetic on the column otherwise rewrites the same `Number(row.x)` /
449
+ * `String(v)` pair in every caller, and each rewrite is a place the two
450
+ * directions can drift apart.
451
+ */
452
+ asNumber(): ColumnBuilder<K, N, D, E, P, number>;
453
+ /**
454
+ * Surface this exact-precision column as a `string` — the value Postgres
455
+ * sent, DECLARED rather than defaulted (FR-001).
456
+ */
457
+ asDecimal(): ColumnBuilder<K, N, D, E, P, string>;
458
+ private withCodec;
421
459
  transform<Target>(fns: ColumnTransform<Target>): ColumnBuilder<K, N, D, E, P, Target>;
422
460
  }
423
461
  /**
@@ -741,6 +779,22 @@ interface PolicyDef {
741
779
  withCheck: string | PolicyExpr | null;
742
780
  permissive: boolean;
743
781
  }
782
+ /**
783
+ * Bir politikanın adreslenebileceği Postgres rolleri.
784
+ *
785
+ * Serbest string DEĞİL, çünkü küme SABİT: bunları palbase provision ediyor,
786
+ * kiracı yeni bir PG rolü yaratmıyor. Serbest bırakıldığında `authenitcated`
787
+ * gibi bir harf hatası derlenip migration'a kadar gidiyordu — Drizzle'da da
788
+ * aynı boşluk ölçüldü (`to` tipi `(string & {})`, yazım hatası DDL'e geçiyor).
789
+ *
790
+ * Çalışma anı zaten fail-closed (bilinmeyen rol kapıyı kapatıyor,
791
+ * `session_rls_fail_closed_integration_test.go`); bu, aynı cevabı derleme
792
+ * anına taşıyor.
793
+ *
794
+ * `backend_*` ikizleri elle YAZILMAZ — `NormalizeDeclaredPolicies` onları
795
+ * kendisi ekliyor; yine de kabul ediliyor ki elle yazan kod kırılmasın.
796
+ */
797
+ type PolicyRole = "anon" | "authenticated" | "service_role" | "backend_anon" | "backend_authenticated" | "backend_service_role";
744
798
  declare class PolicyBuilder {
745
799
  readonly _def: PolicyDef;
746
800
  constructor(name: string);
@@ -755,7 +809,7 @@ declare class PolicyBuilder {
755
809
  * policy("p").to("authenticated", "service_role")
756
810
  * policy("p").to() // PUBLIC
757
811
  */
758
- to(...roles: string[]): this;
812
+ to(...roles: PolicyRole[]): this;
759
813
  /**
760
814
  * `USING (...)` satır görünürlüğü ifadesi.
761
815
  *
@@ -2622,15 +2676,6 @@ interface RequestStore {
2622
2676
  * client's retry replay its first result instead of charging twice. */
2623
2677
  idempotencyKey?: string | null;
2624
2678
  }
2625
- /**
2626
- * Per-request store. The persistent runtime runs each request inside
2627
- * {@link __runWithRuntime}, so every async continuation of that request reads
2628
- * its OWN `runtime` (and any other request-scoped fields the runtime adds).
2629
- *
2630
- * Exported with a `__` prefix so the runtime (worker.js) shares the SAME ALS
2631
- * instance across the one module instance — two ALS instances would silently
2632
- * not see each other's stores. NOT part of the public author-facing API.
2633
- */
2634
2679
  declare const __requestALS: AsyncLocalStorage<RequestStore>;
2635
2680
  /** Install the live clients in the process-global fallback slot.
2636
2681
  *
@@ -2737,13 +2782,15 @@ interface RecoOps {
2737
2782
  /**
2738
2783
  * The project's own Postgres (pgx, schema `env_<envId>`).
2739
2784
  *
2740
- * Typed by default: `Database.tables.<name>.insert({...})` is typed against
2785
+ * Typed by default: `Database.public.<name>.insert({...})` is typed against
2741
2786
  * the project's generated `palbase-env.d.ts` with NO import and NO generic.
2742
- * The raw string ops (`query`/`insert`/`update`/`delete`/`findById`/`findMany`)
2743
- * are also available for dynamic table names and read-only SQL.
2787
+ * The raw string ops (`Database.$query`/`$insert`/`$update`/`$delete`/
2788
+ * `$findById`/`$findMany`) are also available for read-only SQL and for a table
2789
+ * name only known at runtime — which the typed surface cannot express past
2790
+ * seven tables (see `db/tx-union-key.test-d.ts`).
2744
2791
  *
2745
2792
  * RLS is enforced by default (the runtime runs each op as `authenticated` with
2746
- * the verified user's claims). To bypass RLS, call `Database.asService()` —
2793
+ * the verified user's claims). To bypass RLS, call `Database.$asService()` —
2747
2794
  * explicit and greppable — which runs as the `service_role` (BYPASSRLS).
2748
2795
  *
2749
2796
  * @example
@@ -3376,6 +3423,40 @@ type HasOnly<Rels> = [unknown] extends [Rels] ? unknown : [keyof Rels] extends [
3376
3423
  * (ölçüldü: kapı yeşil, çalışma anında "böyle bir ilişki yok" hatası).
3377
3424
  */
3378
3425
  type HasBranch<Row, Rels> = [unknown] extends [Rels] ? never : [keyof Rels] extends [never] ? never : WhereWithRelations<Row, Rels>;
3426
+ /**
3427
+ * `with` — İLİŞKİLİ SATIRLARI GETİR (`has` süzer, `with` getirir).
3428
+ *
3429
+ * `true` bütün kolonları, bir nesne ise `select`/`where`/`orderBy`/`limit` ile
3430
+ * daraltılmış hâlini getiriyor. Tek sorgu: LATERAL + `json_agg`.
3431
+ */
3432
+ type WithOpts<To> = {
3433
+ select?: readonly Extract<keyof RelatedRow<To>, string>[];
3434
+ where?: WhereFilter<RelatedRow<To>>;
3435
+ orderBy?: OrderBySpec<RelatedRow<To>> | readonly OrderBySpec<RelatedRow<To>>[];
3436
+ limit?: number;
3437
+ };
3438
+ type WithInput<Rels> = {
3439
+ [R in keyof Rels]?: Rels[R] extends {
3440
+ to: infer To;
3441
+ } ? true | WithOpts<To> : never;
3442
+ };
3443
+ /** Bir `with` dalının DÖNÜŞ tipi — `many` dizi, `one` tekil ya da null. */
3444
+ type WithRowOf<Rels, R extends keyof Rels, Q> = Rels[R] extends {
3445
+ to: infer To;
3446
+ kind: infer K;
3447
+ } ? (Q extends {
3448
+ select: readonly (infer C extends keyof RelatedRow<To>)[];
3449
+ } ? Pick<RelatedRow<To>, C> : RelatedRow<To>) extends infer Row ? [K] extends ["many"] ? Row[] : Row | null : never : never;
3450
+ /**
3451
+ * `with` istenmediğinde `unknown` — kesişimde YOK OLSUN diye.
3452
+ *
3453
+ * Boş bir nesne (`{}`) dönseydi `Pick<Row, K> & {}` satır tipini "aynı ama
3454
+ * özdeş değil" hâle getirirdi ve tam eşitlik iddiaları kırılırdı. Ölçüldü:
3455
+ * `toEqualTypeOf` dört yerde düştü.
3456
+ */
3457
+ type WithResult<Rels, W> = [keyof W] extends [never] ? unknown : {
3458
+ [R in keyof W & keyof Rels]: WithRowOf<Rels, R, W[R]>;
3459
+ };
3379
3460
  type QueryInput<Row, K extends keyof Row = keyof Row, Rels = unknown> = {
3380
3461
  /**
3381
3462
  * Filtre — ya tipli filtre dili ya da bir `sqlFragment` (FR-018). İkisi de
@@ -3383,6 +3464,25 @@ type QueryInput<Row, K extends keyof Row = keyof Row, Rels = unknown> = {
3383
3464
  * yolu değil (P1).
3384
3465
  */
3385
3466
  where?: WhereFilter<Row> | SqlFragment | HasBranch<Row, Rels>;
3467
+ /**
3468
+ * İlişkili satırları da getir — TEK sorguda.
3469
+ *
3470
+ * ```ts
3471
+ * const rows = await Database.public.users.findMany({
3472
+ * where: { active: true },
3473
+ * with: { orders: { select: ["id", "amount"], limit: 5 } },
3474
+ * });
3475
+ * rows[0].orders[0].amount; // string — KAYIPSIZ
3476
+ * ```
3477
+ *
3478
+ * `many` ilişki DİZİ döner (boşsa `[]`, `null` değil — `.map()` guard
3479
+ * istemesin); `one` ilişki tekil satır ya da `null`.
3480
+ *
3481
+ * PARA: `numeric`/`bigint` kolonları JSON'a `::text` ile giriyor. Cast
3482
+ * olmadan `numeric` bir JSON SAYISI olur ve kesinliğini kaybeder — ölçüldü,
3483
+ * `100000000000000000000000000` → `1e+26`.
3484
+ */
3485
+ with?: [unknown] extends [Rels] ? never : [keyof Rels] extends [never] ? never : WithInput<Rels>;
3386
3486
  /**
3387
3487
  * Projeksiyon (FR-009): yalnız bu kolonlar çekilir ve DÖNÜŞ TİPİ buna daralır.
3388
3488
  *
@@ -3655,7 +3755,9 @@ interface EnvTypedTableBase<T extends TableTypes> {
3655
3755
  findById(id: string): Promise<T["row"] | null>;
3656
3756
  /** Rows matching the filter. See {@link WhereFilter} / {@link FindManyOpts} —
3657
3757
  * this declaration is what makes the engine's operators callable. */
3658
- findMany<K extends keyof T["row"] = keyof T["row"]>(q?: QueryInput<T["row"], K, RelsOf<T>>): Promise<Pick<T["row"], K>[]>;
3758
+ findMany<K extends keyof T["row"] = keyof T["row"], W extends WithInput<RelsOf<T>> = Record<never, never>>(q?: QueryInput<T["row"], K, RelsOf<T>> & {
3759
+ with?: W;
3760
+ }): Promise<Array<Pick<T["row"], K> & WithResult<RelsOf<T>, W>>>;
3659
3761
  /**
3660
3762
  * Update every matching row in one statement; an empty filter is refused.
3661
3763
  *
@@ -5160,4 +5262,4 @@ type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise
5160
5262
  */
5161
5263
  type AuthSpec = boolean | Partial<AuthConfig>;
5162
5264
 
5163
- export { NotFound as $, type AuthSpec as A, BadRequest as B, type CacheClient as C, type DBClient as D, EXTENSION_DEPENDENCIES as E, type ErrorMap as F, type ErrorThrowers as G, HttpError as H, type FileContext as I, Flags as J, Forbidden as K, type HttpMethod as L, IndexBuilder as M, type IndexDef as N, type InsertShape as O, type PalbaseResult as P, type LifecycleHook as Q, type RateLimitConfig as R, type SchemaDef as S, type TxPlanBody as T, Log as U, type Logger as V, type Materialized as W, type Middleware as X, type MiddlewareContext as Y, type MiddlewareHandler as Z, __runWithRuntime as _, type DBOps as a, type PalbaseListLinksOptions as a$, Notifications as a0, type OnDeleteAction as a1, PALBASE_EXTENSIONS as a2, type PBRequest as a3, PalError as a4, type PalbaseAnalyticsClient as a5, type PalbaseAnalyticsManagementNamespace as a6, type PalbaseAnalyticsProperties as a7, type PalbaseAnalyticsQueryNamespace as a8, type PalbaseAttestAndroidParams as a9, type PalbaseEventsQueryInput as aA, type PalbaseEventsResult as aB, type PalbaseExtension as aC, type PalbaseFileObject as aD, type PalbaseFlag as aE, type PalbaseFlagContext as aF, type PalbaseFlagSource as aG, type PalbaseFlagValue as aH, type PalbaseFlagVariant as aI, type PalbaseFlagsClient as aJ, type PalbaseFlagsServiceClient as aK, type PalbaseFunctionsClient as aL, type PalbaseFunnelQueryInput as aM, type PalbaseFunnelResult as aN, type PalbaseIdentifyTraits as aO, type PalbaseInboxClient as aP, type PalbaseInboxListOptions as aQ, type PalbaseInboxListResult as aR, type PalbaseInboxMessage as aS, type PalbaseInboxSendParams as aT, type PalbaseInboxSendResponse as aU, type PalbaseInitialLink as aV, type PalbaseInvokeOptions as aW, type PalbaseLink as aX, type PalbaseLinkAnalytics as aY, type PalbaseLinkDetails as aZ, type PalbaseLinksClient as a_, type PalbaseAttestAndroidResult as aa, type PalbaseAttestiOSParams as ab, type PalbaseAttestiOSResult as ac, type PalbaseAuthAdminClient as ad, type PalbaseAuthClient as ae, type PalbaseBatchOverrideOperation as af, type PalbaseBatchSetOverridesResult as ag, type PalbaseBindDeviceParams as ah, type PalbaseBucketClient as ai, type PalbaseClearAllOverridesResult as aj, type PalbaseClearOverrideResult as ak, type PalbaseCohortQueryInput as al, type PalbaseCohortResult as am, type PalbaseCollectionRef as an, type PalbaseCountQueryInput as ao, type PalbaseCountResult as ap, type PalbaseCreateLinkParams as aq, type PalbaseDeviceInfo as ar, type PalbaseDeviceTokenView as as, type PalbaseDocsClient as at, type PalbaseDocumentRef as au, type PalbaseDocumentSnapshot as av, type PalbaseEmailClient as aw, type PalbaseEmailSendParams as ax, type PalbaseEmailSendResponse as ay, type PalbaseEventNamesResult as az, type TxPlanResponse as b, type TxNow as b$, type PalbaseListLinksResult as b0, type PalbaseListOptions as b1, type PalbaseMatchParams as b2, type PalbaseMultiChannelResponse as b3, type PalbaseNotificationsClient as b4, type PalbaseOverviewResult as b5, type PalbasePreferences as b6, type PalbasePreferencesClient as b7, type PalbasePushClient as b8, type PalbasePushSendParams as b9, type PolicyCommand as bA, type PolicyDef as bB, type PolicyExprCtx as bC, PolicyExprRef as bD, type PolicyMode as bE, type PolicyOperand as bF, type RawConstraintDef as bG, Realtime as bH, type Ref as bI, type RequestStore as bJ, type RowShape as bK, Secrets as bL, type SecretsService as bM, SerializationFailure as bN, type SetShape as bO, type SetValue as bP, type ShutdownRunner as bQ, type SqlFragment as bR, Storage as bS, TABLE_META as bT, type TableDef as bU, type TableHandle as bV, type TableInput as bW, TooManyRequests as bX, type TxColumnExpr as bY, type TxInsertShape as bZ, type TxInsertValue as b_, type PalbasePushSendResponse as ba, type PalbaseQrCodeOptions as bb, type PalbaseQuerySnapshot as bc, type PalbaseRealtimeClient as bd, type PalbaseRegisterDeviceParams as be, type PalbaseRetentionQueryInput as bf, type PalbaseRetentionResult as bg, type PalbaseSession as bh, type PalbaseSetOverrideResult as bi, type PalbaseSetOverridesResult as bj, type PalbaseSignedUrlResponse as bk, type PalbaseSmsClient as bl, type PalbaseSmsSendParams as bm, type PalbaseSmsSendResponse as bn, type PalbaseStorageClient as bo, type PalbaseTransformOptions as bp, type PalbaseUpdateLinkParams as bq, type PalbaseUploadOptions as br, type PalbaseUser as bs, type PalbaseUserDetailResult as bt, type PalbaseUsersQueryInput as bu, type PalbaseUsersResult as bv, type PalbaseVerifyRequestSignatureParams as bw, type PalbaseWhereOperator as bx, type PolicyBinOp as by, PolicyBuilder as bz, type RuntimeServices as c, withRetry as c$, type TxPlan as c0, TxPlanError as c1, type TxPlanHandle as c2, type TxPlanOpResult as c3, type TxPlanRejection as c4, TxRefError as c5, type TxRow as c6, type TxRows as c7, type TxSelectOptions as c8, type TxSetShape as c9, defineSchema as cA, defineTable as cB, enumType as cC, exprCtx as cD, inc as cE, increment as cF, index as cG, installationRef as cH, integer as cI, isPalbaseExtension as cJ, isRetryable as cK, jsonb as cL, makeTypedDB as cM, now as cN, numeric as cO, onShutdown as cP, onStart as cQ, openai as cR, ownedByUser as cS, policy as cT, raw as cU, sqlFragment as cV, text as cW, timestamp as cX, userRef as cY, uuid as cZ, vector as c_, type TxSetValue as ca, type TxTable as cb, type TxTables as cc, type TxWhere as cd, type TxWireExpr as ce, type TxWireGuard as cf, type TxWireOp as cg, type TxWireRef as ch, type TxWireValue as ci, type TypedDB as cj, type TypedTable as ck, type TypedTx as cl, Unauthorized as cm, UniqueViolation as cn, type User as co, type VerifiedDevice as cp, __getRuntime as cq, __resetLifecycleHooks as cr, __runStartHooks as cs, __setRuntime as ct, bigint as cu, boolean as cv, col as cw, dec as cx, decrement as cy, defineMiddleware as cz, __requestALS as d, type PolicyExpr as e, type AnyColumn as f, Auth as g, type AuthConfig as h, Cache as i, type ClientInfo as j, type ColRef as k, ColumnBuilder as l, type ColumnDef as m, type ColumnMap as n, type ColumnType as o, Conflict as p, Database as q, DeadlockDetected as r, Documents as s, type EmbeddingModelRef as t, type EnvSchemas as u, type EnvServiceDatabase as v, type EnvTables as w, type EnvTypedDatabase as x, type EnvTypedTable as y, type ErrorDef as z };
5265
+ export { type Materialized as $, type AuthSpec as A, BadRequest as B, type CacheClient as C, type DBClient as D, type EnvServiceDatabase as E, type EnvTypedTable as F, type ErrorDef as G, HttpError as H, type ErrorMap as I, type ErrorThrowers as J, type FileContext as K, type FindManyOpts as L, Flags as M, Forbidden as N, type HttpMethod as O, type PalbaseResult as P, IndexBuilder as Q, type RateLimitConfig as R, type SchemaDef as S, type TxPlanBody as T, type IndexDef as U, type InsertShape as V, type InsertValues as W, type LifecycleHook as X, Log as Y, type Logger as Z, __runWithRuntime as _, type RuntimeServices as a, type PalbaseInitialLink as a$, type Middleware as a0, type MiddlewareContext as a1, type MiddlewareHandler as a2, type MutateInput as a3, NotFound as a4, Notifications as a5, type OnDeleteAction as a6, type OrderBySpec as a7, PALBASE_EXTENSIONS as a8, type PBRequest as a9, type PalbaseDocumentRef as aA, type PalbaseDocumentSnapshot as aB, type PalbaseEmailClient as aC, type PalbaseEmailSendParams as aD, type PalbaseEmailSendResponse as aE, type PalbaseEventNamesResult as aF, type PalbaseEventsQueryInput as aG, type PalbaseEventsResult as aH, type PalbaseExtension as aI, type PalbaseFileObject as aJ, type PalbaseFlag as aK, type PalbaseFlagContext as aL, type PalbaseFlagSource as aM, type PalbaseFlagValue as aN, type PalbaseFlagVariant as aO, type PalbaseFlagsClient as aP, type PalbaseFlagsServiceClient as aQ, type PalbaseFunctionsClient as aR, type PalbaseFunnelQueryInput as aS, type PalbaseFunnelResult as aT, type PalbaseIdentifyTraits as aU, type PalbaseInboxClient as aV, type PalbaseInboxListOptions as aW, type PalbaseInboxListResult as aX, type PalbaseInboxMessage as aY, type PalbaseInboxSendParams as aZ, type PalbaseInboxSendResponse as a_, PalError as aa, type PalbaseAnalyticsClient as ab, type PalbaseAnalyticsManagementNamespace as ac, type PalbaseAnalyticsProperties as ad, type PalbaseAnalyticsQueryNamespace as ae, type PalbaseAttestAndroidParams as af, type PalbaseAttestAndroidResult as ag, type PalbaseAttestiOSParams as ah, type PalbaseAttestiOSResult as ai, type PalbaseAuthAdminClient as aj, type PalbaseAuthClient as ak, type PalbaseBatchOverrideOperation as al, type PalbaseBatchSetOverridesResult as am, type PalbaseBindDeviceParams as an, type PalbaseBucketClient as ao, type PalbaseClearAllOverridesResult as ap, type PalbaseClearOverrideResult as aq, type PalbaseCohortQueryInput as ar, type PalbaseCohortResult as as, type PalbaseCollectionRef as at, type PalbaseCountQueryInput as au, type PalbaseCountResult as av, type PalbaseCreateLinkParams as aw, type PalbaseDeviceInfo as ax, type PalbaseDeviceTokenView as ay, type PalbaseDocsClient as az, type DBOps as b, type TableDef as b$, type PalbaseInvokeOptions as b0, type PalbaseLink as b1, type PalbaseLinkAnalytics as b2, type PalbaseLinkDetails as b3, type PalbaseLinksClient as b4, type PalbaseListLinksOptions as b5, type PalbaseListLinksResult as b6, type PalbaseListOptions as b7, type PalbaseMatchParams as b8, type PalbaseMultiChannelResponse as b9, type PalbaseUsersQueryInput as bA, type PalbaseUsersResult as bB, type PalbaseVerifyRequestSignatureParams as bC, type PalbaseWhereOperator as bD, type PolicyBinOp as bE, PolicyBuilder as bF, type PolicyCommand as bG, type PolicyDef as bH, type PolicyExprCtx as bI, PolicyExprRef as bJ, type PolicyMode as bK, type PolicyOperand as bL, type QueryInput as bM, type RawConstraintDef as bN, Realtime as bO, type Ref as bP, type RequestStore as bQ, type RowShape as bR, Secrets as bS, type SecretsService as bT, SerializationFailure as bU, type SetShape as bV, type SetValue as bW, type ShutdownRunner as bX, type SqlFragment as bY, Storage as bZ, TABLE_META as b_, type PalbaseNotificationsClient as ba, type PalbaseOverviewResult as bb, type PalbasePreferences as bc, type PalbasePreferencesClient as bd, type PalbasePushClient as be, type PalbasePushSendParams as bf, type PalbasePushSendResponse as bg, type PalbaseQrCodeOptions as bh, type PalbaseQuerySnapshot as bi, type PalbaseRealtimeClient as bj, type PalbaseRegisterDeviceParams as bk, type PalbaseRetentionQueryInput as bl, type PalbaseRetentionResult as bm, type PalbaseSession as bn, type PalbaseSetOverrideResult as bo, type PalbaseSetOverridesResult as bp, type PalbaseSignedUrlResponse as bq, type PalbaseSmsClient as br, type PalbaseSmsSendParams as bs, type PalbaseSmsSendResponse as bt, type PalbaseStorageClient as bu, type PalbaseTransformOptions as bv, type PalbaseUpdateLinkParams as bw, type PalbaseUploadOptions as bx, type PalbaseUser as by, type PalbaseUserDetailResult as bz, type TxPlanResponse as c, ownedByUser as c$, type TableHandle as c0, type TableInput as c1, TooManyRequests as c2, type TxColumnExpr as c3, type TxInsertShape as c4, type TxInsertValue as c5, type TxNow as c6, type TxPlan as c7, TxPlanError as c8, type TxPlanHandle as c9, __resetLifecycleHooks as cA, __runStartHooks as cB, __setRuntime as cC, bigint as cD, boolean as cE, col as cF, dec as cG, decrement as cH, defineMiddleware as cI, defineSchema as cJ, defineTable as cK, enumType as cL, exprCtx as cM, inc as cN, increment as cO, index as cP, installationRef as cQ, integer as cR, isPalbaseExtension as cS, isRetryable as cT, jsonb as cU, makeTypedDB as cV, now as cW, numeric as cX, onShutdown as cY, onStart as cZ, openai as c_, type TxPlanOpResult as ca, type TxPlanRejection as cb, TxRefError as cc, type TxRow as cd, type TxRows as ce, type TxSelectOptions as cf, type TxSetShape as cg, type TxSetValue as ch, type TxTable as ci, type TxTables as cj, type TxWhere as ck, type TxWireExpr as cl, type TxWireGuard as cm, type TxWireOp as cn, type TxWireRef as co, type TxWireValue as cp, type TypedDB as cq, type TypedTable as cr, type TypedTx as cs, Unauthorized as ct, UniqueViolation as cu, type User as cv, type VerifiedDevice as cw, type WhereFilter as cx, type WhereOp as cy, __getRuntime as cz, __requestALS as d, policy as d0, raw as d1, sqlFragment as d2, text as d3, timestamp as d4, userRef as d5, uuid as d6, vector as d7, withRetry as d8, type PolicyExpr as e, type AggregateInput as f, type AggregateResult as g, type AnyColumn as h, Auth as i, type AuthConfig as j, Cache as k, type ClientInfo as l, type ColRef as m, ColumnBuilder as n, type ColumnDef as o, type ColumnMap as p, type ColumnType as q, Conflict as r, Database as s, DeadlockDetected as t, Documents as u, EXTENSION_DEPENDENCIES as v, type EmbeddingModelRef as w, type EnvSchemas as x, type EnvTables as y, type EnvTypedDatabase as z };