@palbase/backend 22.0.1 → 22.1.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 (42) hide show
  1. package/dist/bin/palbase-backend.cjs +340 -22
  2. package/dist/bin/palbase-backend.cjs.map +1 -1
  3. package/dist/bin/palbase-backend.js +2 -2
  4. package/dist/{chunk-QYOHMVUW.js → chunk-74XDEF5J.js} +338 -22
  5. package/dist/chunk-74XDEF5J.js.map +1 -0
  6. package/dist/{chunk-SSGAMC26.js → chunk-I3ON7MYF.js} +57 -5
  7. package/dist/chunk-I3ON7MYF.js.map +1 -0
  8. package/dist/{chunk-POYAFBLF.js → chunk-SQC5EIWY.js} +5 -3
  9. package/dist/chunk-SQC5EIWY.js.map +1 -0
  10. package/dist/db/index.cjs +60 -6
  11. package/dist/db/index.cjs.map +1 -1
  12. package/dist/db/index.d.cts +2 -2
  13. package/dist/db/index.d.ts +2 -2
  14. package/dist/db/index.js +7 -3
  15. package/dist/{endpoint-B0LpZixz.d.cts → endpoint-BVT6jcVW.d.cts} +39 -7
  16. package/dist/{endpoint-B0LpZixz.d.ts → endpoint-BVT6jcVW.d.ts} +39 -7
  17. package/dist/engine/index.cjs +340 -22
  18. package/dist/engine/index.cjs.map +1 -1
  19. package/dist/engine/index.d.cts +4 -4
  20. package/dist/engine/index.d.ts +4 -4
  21. package/dist/engine/index.js +2 -2
  22. package/dist/{index-B4W6d2VJ.d.cts → index-BS1gW4nV.d.cts} +24 -25
  23. package/dist/{index-BGSCWlUa.d.cts → index-BqCiHao8.d.cts} +97 -7
  24. package/dist/{index-BCNtlG1w.d.ts → index-CCZqzych.d.ts} +24 -25
  25. package/dist/{index-g-EzitI-.d.ts → index-vwHoS0l2.d.ts} +97 -7
  26. package/dist/index.cjs +244 -6
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +124 -9
  29. package/dist/index.d.ts +124 -9
  30. package/dist/index.js +186 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/openapi/index.d.cts +2 -2
  33. package/dist/openapi/index.d.ts +2 -2
  34. package/dist/{registry-Cw0YEYCg.d.cts → registry-BWttGlaT.d.cts} +1 -1
  35. package/dist/{registry-3BLYv4si.d.ts → registry-Bsuf-orT.d.ts} +1 -1
  36. package/docs/endpoints.md +1 -1
  37. package/docs/errors.md +9 -0
  38. package/docs/llms-full.txt +10 -1
  39. package/package.json +2 -2
  40. package/dist/chunk-POYAFBLF.js.map +0 -1
  41. package/dist/chunk-QYOHMVUW.js.map +0 -1
  42. package/dist/chunk-SSGAMC26.js.map +0 -1
@@ -1,7 +1,7 @@
1
- export { A as App, l as AuthVerifier, B as BootRefused, m as CreateAppOptions, E as EgressPolicy, n as EngineConfig, M as ModuleClients, o as RateLimiter, p as RequestDatabase, q as RouteEntry, r as RuntimeHooks, s as ScrubResult, t as SqlDriver, u as SqlTx, v as buildRouteTable, w as createApp, x as createLazyTransaction, y as createOps, z as createRequestDatabase, G as effectiveAuth, H as hostAllowed, I as installEgressFence, J as loadConfig, K as makeMemoryCache, O as matchRoute, Q as quoteIdent, T as scrubSecrets, U as withTables } from '../index-B4W6d2VJ.cjs';
2
- import '../endpoint-B0LpZixz.cjs';
1
+ export { A as App, l as AuthVerifier, B as BootRefused, m as CreateAppOptions, E as EgressPolicy, n as EngineConfig, M as ModuleClients, o as RateLimiter, p as RequestDatabase, q as RouteEntry, r as RuntimeHooks, s as ScrubResult, t as SqlDriver, u as SqlTx, v as buildRouteTable, w as createApp, x as createLazyTransaction, y as createOps, z as createRequestDatabase, G as effectiveAuth, H as hostAllowed, I as installEgressFence, J as loadConfig, K as makeMemoryCache, O as matchRoute, Q as quoteIdent, T as scrubSecrets, U as withTables } from '../index-BS1gW4nV.cjs';
2
+ import '../endpoint-BVT6jcVW.cjs';
3
3
  import '../db/env.cjs';
4
4
  import 'node:async_hooks';
5
- import '../index-BGSCWlUa.cjs';
6
- import '../registry-Cw0YEYCg.cjs';
5
+ import '../index-BqCiHao8.cjs';
6
+ import '../registry-BWttGlaT.cjs';
7
7
  import 'zod';
@@ -1,7 +1,7 @@
1
- export { A as App, l as AuthVerifier, B as BootRefused, m as CreateAppOptions, E as EgressPolicy, n as EngineConfig, M as ModuleClients, o as RateLimiter, p as RequestDatabase, q as RouteEntry, r as RuntimeHooks, s as ScrubResult, t as SqlDriver, u as SqlTx, v as buildRouteTable, w as createApp, x as createLazyTransaction, y as createOps, z as createRequestDatabase, G as effectiveAuth, H as hostAllowed, I as installEgressFence, J as loadConfig, K as makeMemoryCache, O as matchRoute, Q as quoteIdent, T as scrubSecrets, U as withTables } from '../index-BCNtlG1w.js';
2
- import '../endpoint-B0LpZixz.js';
1
+ export { A as App, l as AuthVerifier, B as BootRefused, m as CreateAppOptions, E as EgressPolicy, n as EngineConfig, M as ModuleClients, o as RateLimiter, p as RequestDatabase, q as RouteEntry, r as RuntimeHooks, s as ScrubResult, t as SqlDriver, u as SqlTx, v as buildRouteTable, w as createApp, x as createLazyTransaction, y as createOps, z as createRequestDatabase, G as effectiveAuth, H as hostAllowed, I as installEgressFence, J as loadConfig, K as makeMemoryCache, O as matchRoute, Q as quoteIdent, T as scrubSecrets, U as withTables } from '../index-CCZqzych.js';
2
+ import '../endpoint-BVT6jcVW.js';
3
3
  import '../db/env.js';
4
4
  import 'node:async_hooks';
5
- import '../index-g-EzitI-.js';
6
- import '../registry-3BLYv4si.js';
5
+ import '../index-vwHoS0l2.js';
6
+ import '../registry-Bsuf-orT.js';
7
7
  import 'zod';
@@ -16,8 +16,8 @@ import {
16
16
  quoteIdent,
17
17
  scrubSecrets,
18
18
  withTables
19
- } from "../chunk-QYOHMVUW.js";
20
- import "../chunk-POYAFBLF.js";
19
+ } from "../chunk-74XDEF5J.js";
20
+ import "../chunk-SQC5EIWY.js";
21
21
  import "../chunk-W5ODXPY3.js";
22
22
  import "../chunk-QMVK4X3V.js";
23
23
  import "../chunk-7D4SUZUM.js";
@@ -1,8 +1,8 @@
1
1
  import { Buckets, BucketTypes } from './db/env.cjs';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
- import { C as CacheClient, P as PalbaseDocsClient, a as PalbaseFlagsClient, L as Logger, b as PalbaseNotificationsClient, c as PalbaseRealtimeClient, D as DBClient, S as SecretsService, d as PalbaseStorageClient, e as PalbaseBucketClient, T as TxPlanBody, f as TxPlanResponse } from './endpoint-B0LpZixz.cjs';
4
- import { E as EnvTypedDatabase } from './index-BGSCWlUa.cjs';
5
- import { R as RouteMeta } from './registry-Cw0YEYCg.cjs';
3
+ import { C as CacheClient, P as PalbaseDocsClient, a as PalbaseFlagsClient, L as Logger, b as PalbaseNotificationsClient, c as PalbaseRealtimeClient, D as DBClient, S as SecretsService, d as PalbaseStorageClient, e as PalbaseBucketClient, T as TxPlanBody, f as TxPlanResponse } from './endpoint-BVT6jcVW.cjs';
4
+ import { E as EnvTypedDatabase } from './index-BqCiHao8.cjs';
5
+ import { R as RouteMeta } from './registry-BWttGlaT.cjs';
6
6
 
7
7
  /**
8
8
  * The purchases surface the decorators need, declared as a NARROW STRUCTURAL
@@ -434,6 +434,21 @@ declare function createOps(tx: TxLike): {
434
434
  delete(table: string, id: string): Promise<void>;
435
435
  findById(table: string, id: string): Promise<Row | null>;
436
436
  findMany(table: string, query?: Row): Promise<Row[]>;
437
+ /**
438
+ * Tek-SQL hibrit arama (FR-014): iki kol CTE + FULL OUTER JOIN + RRF
439
+ * (1/(50+rank), CLAIM-N4). Operatör şema-nitelikli (C-10, M-1); GUC
440
+ * hnsw.iterative_scan=relaxed_order aynı tx'te set_config ile (CLAIM-N3 —
441
+ * RLS/filtre altında LIMIT-altı dönüş açığını kapatır). Sorgu-anı embed
442
+ * T024'te gelir; o zamana dek vector kolu yalnız params.vector ile koşar.
443
+ */
444
+ search(table: string, params?: {
445
+ query?: string;
446
+ vector?: number[];
447
+ where?: Record<string, unknown>;
448
+ limit?: number;
449
+ using?: string;
450
+ mode?: "hybrid" | "text" | "vector";
451
+ }): Promise<Row[]>;
437
452
  /** A real SAVEPOINT inside the request's transaction. */
438
453
  transaction<T>(cb: (t: unknown) => Promise<T>): Promise<T>;
439
454
  /**
@@ -779,28 +794,6 @@ declare function hostAllowed(host: string, allow: readonly string[]): boolean;
779
794
  */
780
795
  declare function installEgressFence(policy: EgressPolicy): typeof fetch;
781
796
 
782
- /**
783
- * engine/index.ts — the engine: a backend that boots itself.
784
- *
785
- * `createApp` turns a set of `@Controller` classes into a `fetch(Request)`
786
- * handler. No V8 isolate, no capability hop: this process owns its database
787
- * pool, verifies its own tokens, applies its own rate limits, and calls the
788
- * modules directly.
789
- *
790
- * import { createApp, loadConfig } from "@palbase/backend/engine";
791
- *
792
- * const app = await createApp({
793
- * config: loadConfig(process.env),
794
- * controllers: [TodosController],
795
- * schema,
796
- * });
797
- * Bun.serve({ port: app.config.port, fetch: app.handle });
798
- *
799
- * The Web-standard `fetch` signature is the point: the same handler runs under
800
- * Bun, Deno and any host that speaks Request/Response, so "works locally" and
801
- * "works in the cloud" are the same code path rather than two.
802
- */
803
-
804
797
  /** The `__`-prefixed request-scope seam, as re-exported by a deployed bundle. */
805
798
  interface RuntimeHooks {
806
799
  __runWithRuntime: typeof __runWithRuntime;
@@ -809,6 +802,12 @@ interface RuntimeHooks {
809
802
  /** The module singletons the engine injects, minus the two it owns itself. */
810
803
  type ModuleClients = Partial<Pick<RuntimeServices, "Documents" | "Storage" | "Notifications" | "Flags" | "Realtime" | "Purchases" | "Secrets">>;
811
804
  interface CreateAppOptions {
805
+ /**
806
+ * Vault'tan TEK secret okuma (FR-025): sorgu-anı embedding'in anahtarı
807
+ * buradan akar. Verilmezse auto-embed'li search({query}) adlandırılmış
808
+ * hatayla düşer — sessiz boş sonuç asla (FR-015).
809
+ */
810
+ secretReader?: (name: string) => Promise<string | null>;
812
811
  config: EngineConfig;
813
812
  /** `@Controller` classes. A class that collected zero routes is fatal. */
814
813
  controllers: readonly unknown[];
@@ -1,5 +1,5 @@
1
1
  import { Tables, TableTypes } from './db/env.cjs';
2
- import { D as DBClient, b8 as TxPlanHandle, bh as TxTable, M as Materialized } from './endpoint-B0LpZixz.cjs';
2
+ import { D as DBClient, b8 as TxPlanHandle, bh as TxTable, M as Materialized } from './endpoint-BVT6jcVW.cjs';
3
3
 
4
4
  /** On delete action for foreign key references. */
5
5
  type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
@@ -13,7 +13,7 @@ type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
13
13
  */
14
14
  type AuthUserOnDelete = Extract<OnDeleteAction, 'cascade' | 'set null'>;
15
15
  /** Column type identifiers. */
16
- type ColumnType = 'uuid' | 'text' | 'integer' | 'bigint' | 'numeric' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
16
+ type ColumnType = 'uuid' | 'text' | 'integer' | 'bigint' | 'numeric' | 'boolean' | 'timestamp' | 'jsonb' | 'enum' | 'vector';
17
17
  /** Base column definition shared by all column types. */
18
18
  interface ColumnDef {
19
19
  type: ColumnType;
@@ -36,6 +36,9 @@ interface ColumnDef {
36
36
  enumName?: string;
37
37
  enumValues?: string[];
38
38
  unique?: boolean;
39
+ /** vector(n): the declared dimension count — part of the TYPE (typmod), read
40
+ * by the wire serializer and the deploy's auto-index (FR-001). */
41
+ dimensions?: number;
39
42
  }
40
43
  declare const __colKind: unique symbol;
41
44
  declare const __colNullable: unique symbol;
@@ -147,7 +150,7 @@ declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean
147
150
  * - "jsonb" → P (the dev-supplied payload shape from jsonb<T>(), else unknown)
148
151
  * - "enum" → E (the union of literal values)
149
152
  */
150
- type ColValue<C> = C extends ColumnBuilder<'uuid' | 'text' | 'timestamp' | 'bigint' | 'numeric', infer N, infer _D, infer _E, infer _P> ? N extends true ? string | null : string : C extends ColumnBuilder<'integer', infer N, infer _D, infer _E, infer _P> ? N extends true ? number | null : number : C extends ColumnBuilder<'boolean', infer N, infer _D, infer _E, infer _P> ? N extends true ? boolean | null : boolean : C extends ColumnBuilder<'jsonb', infer N, infer _D, infer _E, infer P> ? N extends true ? P | null : P : C extends ColumnBuilder<'enum', infer N, infer _D, infer E, infer _P> ? N extends true ? E | null : E : never;
153
+ type ColValue<C> = C extends ColumnBuilder<'uuid' | 'text' | 'timestamp' | 'bigint' | 'numeric', infer N, infer _D, infer _E, infer _P> ? N extends true ? string | null : string : C extends ColumnBuilder<'integer', infer N, infer _D, infer _E, infer _P> ? N extends true ? number | null : number : C extends ColumnBuilder<'boolean', infer N, infer _D, infer _E, infer _P> ? N extends true ? boolean | null : boolean : C extends ColumnBuilder<'jsonb', infer N, infer _D, infer _E, infer P> ? N extends true ? P | null : P : C extends ColumnBuilder<'vector', infer N, infer _D, infer _E, infer _P> ? N extends true ? number[] | null : number[] : C extends ColumnBuilder<'enum', infer N, infer _D, infer E, infer _P> ? N extends true ? E | null : E : never;
151
154
  /**
152
155
  * True when a column is optional on INSERT:
153
156
  * - nullable columns (N = true) — the DB allows NULL so the field may be omitted
@@ -198,6 +201,10 @@ declare function jsonb<T = unknown>(): ColumnBuilder<'jsonb', false, false, neve
198
201
  * union `V[number]` is as narrow as possible.
199
202
  */
200
203
  declare function enumType<const V extends readonly string[]>(name: string, values: V): ColumnBuilder<'enum', false, false, V[number]>;
204
+ /** vector(n) — pgvector kolonu. n TİPİN parçasıdır (typmod) ve [1, 2000] —
205
+ * 2000 = pgvector'ün HNSW-indekslenebilir tavanı; auto-index bu beyanla bağlı
206
+ * (spec FR-001, D-3). */
207
+ declare function vector(dimensions: number): ColumnBuilder<'vector', false, false, unknown, number[]>;
201
208
 
202
209
  /**
203
210
  * policy.ts — the RLS policy authoring DSL.
@@ -301,7 +308,7 @@ declare function policy(name: string): PolicyBuilder;
301
308
  * supported names and a typo fails typecheck. It is intentionally extensible:
302
309
  * add a name here (+ confirm the base image ships it) to support more.
303
310
  */
304
- declare const PALBASE_EXTENSIONS: readonly ["vector", "pg_trgm", "unaccent", "citext", "postgis", "cube", "earthdistance", "hstore", "ltree", "btree_gist", "pg_cron", "pgcrypto", "uuid-ossp"];
311
+ declare const PALBASE_EXTENSIONS: readonly ["vector", "pg_trgm", "unaccent", "citext", "cube", "earthdistance", "hstore", "ltree", "btree_gist", "pgcrypto", "uuid-ossp"];
305
312
  /** A Postgres extension supported by Palbase (allowlist union). */
306
313
  type PalbaseExtension = (typeof PALBASE_EXTENSIONS)[number];
307
314
  /**
@@ -329,6 +336,25 @@ declare function raw(name: string, up: string, opts?: {
329
336
  down?: string;
330
337
  }): RawConstraintDef;
331
338
 
339
+ /** Embedding sağlayıcı DESKRIPTORU — canlı istemci değil, düz veri: şemayla
340
+ * birlikte serileşir, çağrıyı Go worker (yazma) ve engine (sorgu) yapar.
341
+ * Adlandırma Vercel AI SDK'nın aynasıdır (openai.embedding("...")) ama paket
342
+ * bağımlılığı bilinçli olarak YOKTUR (spec C-3, UD-016). v1 sağlayıcı: openai (D-10). */
343
+ interface EmbeddingModelRef {
344
+ provider: "openai";
345
+ model: string;
346
+ dimensions?: number;
347
+ apiKeyName?: string;
348
+ baseURL?: string;
349
+ }
350
+ declare const openai: {
351
+ embedding(model: string, opts?: {
352
+ dimensions?: number;
353
+ apiKeyName?: string;
354
+ baseURL?: string;
355
+ }): EmbeddingModelRef;
356
+ };
357
+
332
358
  /**
333
359
  * A map of column builders keyed by column name — the value you write under
334
360
  * the `columns` key of `defineSchema({ tables: { <name>: { columns } } })`.
@@ -355,6 +381,32 @@ type ColumnMap = Record<string, ColumnBuilder>;
355
381
  * The `C` type parameter preserves the precise per-column phantom types so the
356
382
  * typed `Database.tables.*` surface keeps inferring insert/row shapes.
357
383
  */
384
+ /** Arama metriği — tek kelime; opclass ve operatör bundan türetilir, asla yüzeye çıkmaz (D-5/D-6). */
385
+ type SearchMetric = "cosine" | "euclidean" | "inner_product";
386
+ /** Bir vektör arama kolu. `model` varsa auto-embed: platform yazma+sorgu embedding'ini üstlenir (D-9). */
387
+ interface VectorSearchDecl {
388
+ /** Hedef vector kolonu; tabloda TEK vector kolonu varsa atlanabilir (Go apply çözer, FR-010). */
389
+ column?: string;
390
+ /** Varsa auto-embed. Deskriptor düz veridir — şemayla serileşir (C-3). */
391
+ model?: EmbeddingModelRef;
392
+ /** model varsa ZORUNLU: embed kaynak kolonları = trigger'ın UPDATE OF listesi (C-2). */
393
+ from?: string[];
394
+ metric?: SearchMetric;
395
+ /** Kaynak metin değişince ara-dönem davranışı (yalnız auto-embed'de):
396
+ * "null" (vars.) — embedding anında NULL'lanır; satır yeni vektör yazılana
397
+ * dek anlamsal aramada aday değildir. Bayat eşleşme asla servis edilmez.
398
+ * "keep" — eski vektör aramada kalır, platform yenisini yazınca sessizce
399
+ * değişir. Görünürlük penceresi sıfır; bedeli saniyeler süren bayat
400
+ * eşleşme riski (Confluence-tipi sync yükleri için). */
401
+ staleness?: "null" | "keep";
402
+ }
403
+ /** Tablonun arama beyanı. `text`: FTS kolonları (sabit 'simple' sözlük, D-4 — palbase_fts + GIN türetilir).
404
+ * `vector`: bir ya da birden çok ANN kolu. İkisi de opsiyonel; blok yoksa tablo yine
405
+ * vector kolonu varlığıyla aranabilir (D-3/FR-013). */
406
+ interface SearchDecl {
407
+ text?: string[];
408
+ vector?: VectorSearchDecl | VectorSearchDecl[];
409
+ }
358
410
  interface TableInput<C extends ColumnMap = ColumnMap> {
359
411
  columns: C;
360
412
  rls?: boolean;
@@ -394,6 +446,8 @@ interface TableInput<C extends ColumnMap = ColumnMap> {
394
446
  name: string;
395
447
  columns: string[];
396
448
  }[];
449
+ /** Arama beyanı — bkz. SearchDecl. */
450
+ search?: SearchDecl;
397
451
  }
398
452
  /**
399
453
  * A table definition — the runtime value the Go runtime's `schema_extract.js`
@@ -429,6 +483,8 @@ interface TableDef<C extends ColumnMap = ColumnMap> {
429
483
  name: string;
430
484
  columns: string[];
431
485
  }[];
486
+ /** Arama beyanı, doğrulanmış ve taşınmış hali. */
487
+ search?: SearchDecl;
432
488
  }
433
489
  /**
434
490
  * A schema definition containing multiple tables, keyed by table name.
@@ -583,8 +639,32 @@ type TypedTx<S extends SchemaDef> = TxPlanHandle<{
583
639
  * through `Object.keys` iteration) — see the module-level doc comment.
584
640
  */
585
641
  declare function makeTypedDB<S extends SchemaDef>(schema: S, raw: DBClient): TypedDB<S>;
586
- /** A typed table accessor derived from one env `Tables` entry's flat shapes. */
587
- interface EnvTypedTable<T extends TableTypes> {
642
+ /** Bir where değeri: düz eşitlik YA DA operatör nesnesi (FR-016). */
643
+ type WhereOp<V> = V | {
644
+ gt?: V;
645
+ gte?: V;
646
+ lt?: V;
647
+ lte?: V;
648
+ neq?: V;
649
+ in?: V[];
650
+ };
651
+ /** search() parametreleri, satır tipiyle koşullanmış (FR-013). `offset` BİLEREK yok (UD-013). */
652
+ interface SearchParamsTyped<T extends TableTypes> {
653
+ /** Metin sorgusu: FTS kolunu besler; embed beyanlıysa sorgu vektörü de bundan üretilir. */
654
+ query?: string;
655
+ /** Hazır sorgu vektörü — verilirse embed çağrısı olmaz (FR-025). */
656
+ vector?: number[];
657
+ where?: {
658
+ [K in keyof T["row"]]?: WhereOp<T["row"][K]>;
659
+ };
660
+ /** default 20, tavan 100 (engine uygular). */
661
+ limit?: number;
662
+ /** Birden çok vektör kolonunda hedef seçimi (model geçişi, FR-013/using). */
663
+ using?: string;
664
+ mode?: "hybrid" | "text" | "vector";
665
+ }
666
+ /** Temel tablo erişimcisi — search'süz beş op. */
667
+ interface EnvTypedTableBase<T extends TableTypes> {
588
668
  insert(data: T["insert"]): Promise<T["row"]>;
589
669
  /** Update the row by id; resolves to the updated row, or `null` if no row
590
670
  * matched (absent or RLS-hidden) — an idempotent outcome, mirroring
@@ -594,6 +674,16 @@ interface EnvTypedTable<T extends TableTypes> {
594
674
  findById(id: string): Promise<T["row"] | null>;
595
675
  findMany(query?: Partial<T["row"]>): Promise<T["row"][]>;
596
676
  }
677
+ /** Tablo erişimcisi: env girdisi `searchable: true` taşıyorsa (vector kolonu ya da
678
+ * search beyanı — env-gen üretir) `search()` üyesi VARDIR; yoksa üye hiç yoktur ve
679
+ * çağrı derleme hatasıdır (FR-013). Yapısal koşul TableTypes'ı genişletmeden çalışır. */
680
+ type EnvTypedTable<T extends TableTypes> = EnvTypedTableBase<T> & (T extends {
681
+ searchable: true;
682
+ } ? {
683
+ search(params: SearchParamsTyped<T>): Promise<Array<T["row"] & {
684
+ _score: number;
685
+ }>>;
686
+ } : Record<never, never>);
597
687
  /** The `tables` map exposed on `Database`/`tx`, keyed by the env `Tables`
598
688
  * interface. When no schema is declared `Tables` is empty, so `tables` is an
599
689
  * empty object — accessing `.tables.foo` is then a compile error (no member). */
@@ -671,4 +761,4 @@ interface EnvTypedDatabase extends Omit<DBClient, "txPlan" | "asService"> {
671
761
  asService(): EnvServiceDatabase;
672
762
  }
673
763
 
674
- export { jsonb as A, makeTypedDB as B, ColumnBuilder as C, numeric as D, type EnvTypedDatabase as E, policy as F, raw as G, text as H, type InsertShape as I, timestamp as J, uuid as K, type OnDeleteAction as O, PALBASE_EXTENSIONS as P, type RawConstraintDef as R, type SchemaDef as S, type TableDef as T, type ColumnDef as a, type ColumnMap as b, type ColumnType as c, EXTENSION_DEPENDENCIES as d, type EnvServiceDatabase as e, type EnvTables as f, type EnvTypedTable as g, type PalbaseExtension as h, PolicyBuilder as i, type PolicyCommand as j, type PolicyDef as k, type PolicyMode as l, type RowShape as m, type SchemaInput as n, type TableInput as o, type TxPlan as p, type TxTables as q, type TypedDB as r, type TypedTable as s, type TypedTx as t, bigint as u, boolean as v, defineSchema as w, enumType as x, integer as y, isPalbaseExtension as z };
764
+ export { isPalbaseExtension as A, jsonb as B, ColumnBuilder as C, makeTypedDB as D, type EnvTypedDatabase as E, numeric as F, openai as G, policy as H, type InsertShape as I, raw as J, text as K, timestamp as L, uuid as M, vector as N, type OnDeleteAction as O, PALBASE_EXTENSIONS as P, type RawConstraintDef as R, type SchemaDef as S, type TableDef as T, type ColumnDef as a, type ColumnMap as b, type ColumnType as c, EXTENSION_DEPENDENCIES as d, type EmbeddingModelRef as e, type EnvServiceDatabase as f, type EnvTables as g, type EnvTypedTable as h, type PalbaseExtension as i, PolicyBuilder as j, type PolicyCommand as k, type PolicyDef as l, type PolicyMode as m, type RowShape as n, type SchemaInput as o, type TableInput as p, type TxPlan as q, type TxTables as r, type TypedDB as s, type TypedTable as t, type TypedTx as u, bigint as v, boolean as w, defineSchema as x, enumType as y, integer as z };
@@ -1,8 +1,8 @@
1
1
  import { Buckets, BucketTypes } from './db/env.js';
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
- import { C as CacheClient, P as PalbaseDocsClient, a as PalbaseFlagsClient, L as Logger, b as PalbaseNotificationsClient, c as PalbaseRealtimeClient, D as DBClient, S as SecretsService, d as PalbaseStorageClient, e as PalbaseBucketClient, T as TxPlanBody, f as TxPlanResponse } from './endpoint-B0LpZixz.js';
4
- import { E as EnvTypedDatabase } from './index-g-EzitI-.js';
5
- import { R as RouteMeta } from './registry-3BLYv4si.js';
3
+ import { C as CacheClient, P as PalbaseDocsClient, a as PalbaseFlagsClient, L as Logger, b as PalbaseNotificationsClient, c as PalbaseRealtimeClient, D as DBClient, S as SecretsService, d as PalbaseStorageClient, e as PalbaseBucketClient, T as TxPlanBody, f as TxPlanResponse } from './endpoint-BVT6jcVW.js';
4
+ import { E as EnvTypedDatabase } from './index-vwHoS0l2.js';
5
+ import { R as RouteMeta } from './registry-Bsuf-orT.js';
6
6
 
7
7
  /**
8
8
  * The purchases surface the decorators need, declared as a NARROW STRUCTURAL
@@ -434,6 +434,21 @@ declare function createOps(tx: TxLike): {
434
434
  delete(table: string, id: string): Promise<void>;
435
435
  findById(table: string, id: string): Promise<Row | null>;
436
436
  findMany(table: string, query?: Row): Promise<Row[]>;
437
+ /**
438
+ * Tek-SQL hibrit arama (FR-014): iki kol CTE + FULL OUTER JOIN + RRF
439
+ * (1/(50+rank), CLAIM-N4). Operatör şema-nitelikli (C-10, M-1); GUC
440
+ * hnsw.iterative_scan=relaxed_order aynı tx'te set_config ile (CLAIM-N3 —
441
+ * RLS/filtre altında LIMIT-altı dönüş açığını kapatır). Sorgu-anı embed
442
+ * T024'te gelir; o zamana dek vector kolu yalnız params.vector ile koşar.
443
+ */
444
+ search(table: string, params?: {
445
+ query?: string;
446
+ vector?: number[];
447
+ where?: Record<string, unknown>;
448
+ limit?: number;
449
+ using?: string;
450
+ mode?: "hybrid" | "text" | "vector";
451
+ }): Promise<Row[]>;
437
452
  /** A real SAVEPOINT inside the request's transaction. */
438
453
  transaction<T>(cb: (t: unknown) => Promise<T>): Promise<T>;
439
454
  /**
@@ -779,28 +794,6 @@ declare function hostAllowed(host: string, allow: readonly string[]): boolean;
779
794
  */
780
795
  declare function installEgressFence(policy: EgressPolicy): typeof fetch;
781
796
 
782
- /**
783
- * engine/index.ts — the engine: a backend that boots itself.
784
- *
785
- * `createApp` turns a set of `@Controller` classes into a `fetch(Request)`
786
- * handler. No V8 isolate, no capability hop: this process owns its database
787
- * pool, verifies its own tokens, applies its own rate limits, and calls the
788
- * modules directly.
789
- *
790
- * import { createApp, loadConfig } from "@palbase/backend/engine";
791
- *
792
- * const app = await createApp({
793
- * config: loadConfig(process.env),
794
- * controllers: [TodosController],
795
- * schema,
796
- * });
797
- * Bun.serve({ port: app.config.port, fetch: app.handle });
798
- *
799
- * The Web-standard `fetch` signature is the point: the same handler runs under
800
- * Bun, Deno and any host that speaks Request/Response, so "works locally" and
801
- * "works in the cloud" are the same code path rather than two.
802
- */
803
-
804
797
  /** The `__`-prefixed request-scope seam, as re-exported by a deployed bundle. */
805
798
  interface RuntimeHooks {
806
799
  __runWithRuntime: typeof __runWithRuntime;
@@ -809,6 +802,12 @@ interface RuntimeHooks {
809
802
  /** The module singletons the engine injects, minus the two it owns itself. */
810
803
  type ModuleClients = Partial<Pick<RuntimeServices, "Documents" | "Storage" | "Notifications" | "Flags" | "Realtime" | "Purchases" | "Secrets">>;
811
804
  interface CreateAppOptions {
805
+ /**
806
+ * Vault'tan TEK secret okuma (FR-025): sorgu-anı embedding'in anahtarı
807
+ * buradan akar. Verilmezse auto-embed'li search({query}) adlandırılmış
808
+ * hatayla düşer — sessiz boş sonuç asla (FR-015).
809
+ */
810
+ secretReader?: (name: string) => Promise<string | null>;
812
811
  config: EngineConfig;
813
812
  /** `@Controller` classes. A class that collected zero routes is fatal. */
814
813
  controllers: readonly unknown[];
@@ -1,5 +1,5 @@
1
1
  import { Tables, TableTypes } from './db/env.js';
2
- import { D as DBClient, b8 as TxPlanHandle, bh as TxTable, M as Materialized } from './endpoint-B0LpZixz.js';
2
+ import { D as DBClient, b8 as TxPlanHandle, bh as TxTable, M as Materialized } from './endpoint-BVT6jcVW.js';
3
3
 
4
4
  /** On delete action for foreign key references. */
5
5
  type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
@@ -13,7 +13,7 @@ type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
13
13
  */
14
14
  type AuthUserOnDelete = Extract<OnDeleteAction, 'cascade' | 'set null'>;
15
15
  /** Column type identifiers. */
16
- type ColumnType = 'uuid' | 'text' | 'integer' | 'bigint' | 'numeric' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
16
+ type ColumnType = 'uuid' | 'text' | 'integer' | 'bigint' | 'numeric' | 'boolean' | 'timestamp' | 'jsonb' | 'enum' | 'vector';
17
17
  /** Base column definition shared by all column types. */
18
18
  interface ColumnDef {
19
19
  type: ColumnType;
@@ -36,6 +36,9 @@ interface ColumnDef {
36
36
  enumName?: string;
37
37
  enumValues?: string[];
38
38
  unique?: boolean;
39
+ /** vector(n): the declared dimension count — part of the TYPE (typmod), read
40
+ * by the wire serializer and the deploy's auto-index (FR-001). */
41
+ dimensions?: number;
39
42
  }
40
43
  declare const __colKind: unique symbol;
41
44
  declare const __colNullable: unique symbol;
@@ -147,7 +150,7 @@ declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean
147
150
  * - "jsonb" → P (the dev-supplied payload shape from jsonb<T>(), else unknown)
148
151
  * - "enum" → E (the union of literal values)
149
152
  */
150
- type ColValue<C> = C extends ColumnBuilder<'uuid' | 'text' | 'timestamp' | 'bigint' | 'numeric', infer N, infer _D, infer _E, infer _P> ? N extends true ? string | null : string : C extends ColumnBuilder<'integer', infer N, infer _D, infer _E, infer _P> ? N extends true ? number | null : number : C extends ColumnBuilder<'boolean', infer N, infer _D, infer _E, infer _P> ? N extends true ? boolean | null : boolean : C extends ColumnBuilder<'jsonb', infer N, infer _D, infer _E, infer P> ? N extends true ? P | null : P : C extends ColumnBuilder<'enum', infer N, infer _D, infer E, infer _P> ? N extends true ? E | null : E : never;
153
+ type ColValue<C> = C extends ColumnBuilder<'uuid' | 'text' | 'timestamp' | 'bigint' | 'numeric', infer N, infer _D, infer _E, infer _P> ? N extends true ? string | null : string : C extends ColumnBuilder<'integer', infer N, infer _D, infer _E, infer _P> ? N extends true ? number | null : number : C extends ColumnBuilder<'boolean', infer N, infer _D, infer _E, infer _P> ? N extends true ? boolean | null : boolean : C extends ColumnBuilder<'jsonb', infer N, infer _D, infer _E, infer P> ? N extends true ? P | null : P : C extends ColumnBuilder<'vector', infer N, infer _D, infer _E, infer _P> ? N extends true ? number[] | null : number[] : C extends ColumnBuilder<'enum', infer N, infer _D, infer E, infer _P> ? N extends true ? E | null : E : never;
151
154
  /**
152
155
  * True when a column is optional on INSERT:
153
156
  * - nullable columns (N = true) — the DB allows NULL so the field may be omitted
@@ -198,6 +201,10 @@ declare function jsonb<T = unknown>(): ColumnBuilder<'jsonb', false, false, neve
198
201
  * union `V[number]` is as narrow as possible.
199
202
  */
200
203
  declare function enumType<const V extends readonly string[]>(name: string, values: V): ColumnBuilder<'enum', false, false, V[number]>;
204
+ /** vector(n) — pgvector kolonu. n TİPİN parçasıdır (typmod) ve [1, 2000] —
205
+ * 2000 = pgvector'ün HNSW-indekslenebilir tavanı; auto-index bu beyanla bağlı
206
+ * (spec FR-001, D-3). */
207
+ declare function vector(dimensions: number): ColumnBuilder<'vector', false, false, unknown, number[]>;
201
208
 
202
209
  /**
203
210
  * policy.ts — the RLS policy authoring DSL.
@@ -301,7 +308,7 @@ declare function policy(name: string): PolicyBuilder;
301
308
  * supported names and a typo fails typecheck. It is intentionally extensible:
302
309
  * add a name here (+ confirm the base image ships it) to support more.
303
310
  */
304
- declare const PALBASE_EXTENSIONS: readonly ["vector", "pg_trgm", "unaccent", "citext", "postgis", "cube", "earthdistance", "hstore", "ltree", "btree_gist", "pg_cron", "pgcrypto", "uuid-ossp"];
311
+ declare const PALBASE_EXTENSIONS: readonly ["vector", "pg_trgm", "unaccent", "citext", "cube", "earthdistance", "hstore", "ltree", "btree_gist", "pgcrypto", "uuid-ossp"];
305
312
  /** A Postgres extension supported by Palbase (allowlist union). */
306
313
  type PalbaseExtension = (typeof PALBASE_EXTENSIONS)[number];
307
314
  /**
@@ -329,6 +336,25 @@ declare function raw(name: string, up: string, opts?: {
329
336
  down?: string;
330
337
  }): RawConstraintDef;
331
338
 
339
+ /** Embedding sağlayıcı DESKRIPTORU — canlı istemci değil, düz veri: şemayla
340
+ * birlikte serileşir, çağrıyı Go worker (yazma) ve engine (sorgu) yapar.
341
+ * Adlandırma Vercel AI SDK'nın aynasıdır (openai.embedding("...")) ama paket
342
+ * bağımlılığı bilinçli olarak YOKTUR (spec C-3, UD-016). v1 sağlayıcı: openai (D-10). */
343
+ interface EmbeddingModelRef {
344
+ provider: "openai";
345
+ model: string;
346
+ dimensions?: number;
347
+ apiKeyName?: string;
348
+ baseURL?: string;
349
+ }
350
+ declare const openai: {
351
+ embedding(model: string, opts?: {
352
+ dimensions?: number;
353
+ apiKeyName?: string;
354
+ baseURL?: string;
355
+ }): EmbeddingModelRef;
356
+ };
357
+
332
358
  /**
333
359
  * A map of column builders keyed by column name — the value you write under
334
360
  * the `columns` key of `defineSchema({ tables: { <name>: { columns } } })`.
@@ -355,6 +381,32 @@ type ColumnMap = Record<string, ColumnBuilder>;
355
381
  * The `C` type parameter preserves the precise per-column phantom types so the
356
382
  * typed `Database.tables.*` surface keeps inferring insert/row shapes.
357
383
  */
384
+ /** Arama metriği — tek kelime; opclass ve operatör bundan türetilir, asla yüzeye çıkmaz (D-5/D-6). */
385
+ type SearchMetric = "cosine" | "euclidean" | "inner_product";
386
+ /** Bir vektör arama kolu. `model` varsa auto-embed: platform yazma+sorgu embedding'ini üstlenir (D-9). */
387
+ interface VectorSearchDecl {
388
+ /** Hedef vector kolonu; tabloda TEK vector kolonu varsa atlanabilir (Go apply çözer, FR-010). */
389
+ column?: string;
390
+ /** Varsa auto-embed. Deskriptor düz veridir — şemayla serileşir (C-3). */
391
+ model?: EmbeddingModelRef;
392
+ /** model varsa ZORUNLU: embed kaynak kolonları = trigger'ın UPDATE OF listesi (C-2). */
393
+ from?: string[];
394
+ metric?: SearchMetric;
395
+ /** Kaynak metin değişince ara-dönem davranışı (yalnız auto-embed'de):
396
+ * "null" (vars.) — embedding anında NULL'lanır; satır yeni vektör yazılana
397
+ * dek anlamsal aramada aday değildir. Bayat eşleşme asla servis edilmez.
398
+ * "keep" — eski vektör aramada kalır, platform yenisini yazınca sessizce
399
+ * değişir. Görünürlük penceresi sıfır; bedeli saniyeler süren bayat
400
+ * eşleşme riski (Confluence-tipi sync yükleri için). */
401
+ staleness?: "null" | "keep";
402
+ }
403
+ /** Tablonun arama beyanı. `text`: FTS kolonları (sabit 'simple' sözlük, D-4 — palbase_fts + GIN türetilir).
404
+ * `vector`: bir ya da birden çok ANN kolu. İkisi de opsiyonel; blok yoksa tablo yine
405
+ * vector kolonu varlığıyla aranabilir (D-3/FR-013). */
406
+ interface SearchDecl {
407
+ text?: string[];
408
+ vector?: VectorSearchDecl | VectorSearchDecl[];
409
+ }
358
410
  interface TableInput<C extends ColumnMap = ColumnMap> {
359
411
  columns: C;
360
412
  rls?: boolean;
@@ -394,6 +446,8 @@ interface TableInput<C extends ColumnMap = ColumnMap> {
394
446
  name: string;
395
447
  columns: string[];
396
448
  }[];
449
+ /** Arama beyanı — bkz. SearchDecl. */
450
+ search?: SearchDecl;
397
451
  }
398
452
  /**
399
453
  * A table definition — the runtime value the Go runtime's `schema_extract.js`
@@ -429,6 +483,8 @@ interface TableDef<C extends ColumnMap = ColumnMap> {
429
483
  name: string;
430
484
  columns: string[];
431
485
  }[];
486
+ /** Arama beyanı, doğrulanmış ve taşınmış hali. */
487
+ search?: SearchDecl;
432
488
  }
433
489
  /**
434
490
  * A schema definition containing multiple tables, keyed by table name.
@@ -583,8 +639,32 @@ type TypedTx<S extends SchemaDef> = TxPlanHandle<{
583
639
  * through `Object.keys` iteration) — see the module-level doc comment.
584
640
  */
585
641
  declare function makeTypedDB<S extends SchemaDef>(schema: S, raw: DBClient): TypedDB<S>;
586
- /** A typed table accessor derived from one env `Tables` entry's flat shapes. */
587
- interface EnvTypedTable<T extends TableTypes> {
642
+ /** Bir where değeri: düz eşitlik YA DA operatör nesnesi (FR-016). */
643
+ type WhereOp<V> = V | {
644
+ gt?: V;
645
+ gte?: V;
646
+ lt?: V;
647
+ lte?: V;
648
+ neq?: V;
649
+ in?: V[];
650
+ };
651
+ /** search() parametreleri, satır tipiyle koşullanmış (FR-013). `offset` BİLEREK yok (UD-013). */
652
+ interface SearchParamsTyped<T extends TableTypes> {
653
+ /** Metin sorgusu: FTS kolunu besler; embed beyanlıysa sorgu vektörü de bundan üretilir. */
654
+ query?: string;
655
+ /** Hazır sorgu vektörü — verilirse embed çağrısı olmaz (FR-025). */
656
+ vector?: number[];
657
+ where?: {
658
+ [K in keyof T["row"]]?: WhereOp<T["row"][K]>;
659
+ };
660
+ /** default 20, tavan 100 (engine uygular). */
661
+ limit?: number;
662
+ /** Birden çok vektör kolonunda hedef seçimi (model geçişi, FR-013/using). */
663
+ using?: string;
664
+ mode?: "hybrid" | "text" | "vector";
665
+ }
666
+ /** Temel tablo erişimcisi — search'süz beş op. */
667
+ interface EnvTypedTableBase<T extends TableTypes> {
588
668
  insert(data: T["insert"]): Promise<T["row"]>;
589
669
  /** Update the row by id; resolves to the updated row, or `null` if no row
590
670
  * matched (absent or RLS-hidden) — an idempotent outcome, mirroring
@@ -594,6 +674,16 @@ interface EnvTypedTable<T extends TableTypes> {
594
674
  findById(id: string): Promise<T["row"] | null>;
595
675
  findMany(query?: Partial<T["row"]>): Promise<T["row"][]>;
596
676
  }
677
+ /** Tablo erişimcisi: env girdisi `searchable: true` taşıyorsa (vector kolonu ya da
678
+ * search beyanı — env-gen üretir) `search()` üyesi VARDIR; yoksa üye hiç yoktur ve
679
+ * çağrı derleme hatasıdır (FR-013). Yapısal koşul TableTypes'ı genişletmeden çalışır. */
680
+ type EnvTypedTable<T extends TableTypes> = EnvTypedTableBase<T> & (T extends {
681
+ searchable: true;
682
+ } ? {
683
+ search(params: SearchParamsTyped<T>): Promise<Array<T["row"] & {
684
+ _score: number;
685
+ }>>;
686
+ } : Record<never, never>);
597
687
  /** The `tables` map exposed on `Database`/`tx`, keyed by the env `Tables`
598
688
  * interface. When no schema is declared `Tables` is empty, so `tables` is an
599
689
  * empty object — accessing `.tables.foo` is then a compile error (no member). */
@@ -671,4 +761,4 @@ interface EnvTypedDatabase extends Omit<DBClient, "txPlan" | "asService"> {
671
761
  asService(): EnvServiceDatabase;
672
762
  }
673
763
 
674
- export { jsonb as A, makeTypedDB as B, ColumnBuilder as C, numeric as D, type EnvTypedDatabase as E, policy as F, raw as G, text as H, type InsertShape as I, timestamp as J, uuid as K, type OnDeleteAction as O, PALBASE_EXTENSIONS as P, type RawConstraintDef as R, type SchemaDef as S, type TableDef as T, type ColumnDef as a, type ColumnMap as b, type ColumnType as c, EXTENSION_DEPENDENCIES as d, type EnvServiceDatabase as e, type EnvTables as f, type EnvTypedTable as g, type PalbaseExtension as h, PolicyBuilder as i, type PolicyCommand as j, type PolicyDef as k, type PolicyMode as l, type RowShape as m, type SchemaInput as n, type TableInput as o, type TxPlan as p, type TxTables as q, type TypedDB as r, type TypedTable as s, type TypedTx as t, bigint as u, boolean as v, defineSchema as w, enumType as x, integer as y, isPalbaseExtension as z };
764
+ export { isPalbaseExtension as A, jsonb as B, ColumnBuilder as C, makeTypedDB as D, type EnvTypedDatabase as E, numeric as F, openai as G, policy as H, type InsertShape as I, raw as J, text as K, timestamp as L, uuid as M, vector as N, type OnDeleteAction as O, PALBASE_EXTENSIONS as P, type RawConstraintDef as R, type SchemaDef as S, type TableDef as T, type ColumnDef as a, type ColumnMap as b, type ColumnType as c, EXTENSION_DEPENDENCIES as d, type EmbeddingModelRef as e, type EnvServiceDatabase as f, type EnvTables as g, type EnvTypedTable as h, type PalbaseExtension as i, PolicyBuilder as j, type PolicyCommand as k, type PolicyDef as l, type PolicyMode as m, type RowShape as n, type SchemaInput as o, type TableInput as p, type TxPlan as q, type TxTables as r, type TypedDB as s, type TypedTable as t, type TypedTx as u, bigint as v, boolean as w, defineSchema as x, enumType as y, integer as z };