@palbase/backend 33.0.2 → 34.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.
- package/dist/bin/palbase-backend.cjs +2273 -358
- package/dist/bin/palbase-backend.cjs.map +1 -1
- package/dist/bin/palbase-backend.js +9 -7
- package/dist/bin/palbase-backend.js.map +1 -1
- package/dist/{chunk-YIQ4RS4F.js → chunk-5UGPXKMJ.js} +331 -5
- package/dist/chunk-5UGPXKMJ.js.map +1 -0
- package/dist/chunk-GHNC2UHS.js +20 -0
- package/dist/chunk-GHNC2UHS.js.map +1 -0
- package/dist/{chunk-AAT5G7KY.js → chunk-JJW3L62T.js} +2 -2
- package/dist/chunk-JJW3L62T.js.map +1 -0
- package/dist/{chunk-SI4KGEM3.js → chunk-P7MGSAFT.js} +102 -96
- package/dist/chunk-P7MGSAFT.js.map +1 -0
- package/dist/{chunk-XOX6RFPZ.js → chunk-PRH45NZU.js} +46 -3
- package/dist/chunk-PRH45NZU.js.map +1 -0
- package/dist/{chunk-26GH54D2.js → chunk-RZLY4BOY.js} +5 -3
- package/dist/{chunk-26GH54D2.js.map → chunk-RZLY4BOY.js.map} +1 -1
- package/dist/{chunk-KATPXCJ5.js → chunk-UMESJJRS.js} +19 -40
- package/dist/chunk-UMESJJRS.js.map +1 -0
- package/dist/chunk-VXPNPVAG.js +40 -0
- package/dist/chunk-VXPNPVAG.js.map +1 -0
- package/dist/{chunk-WWUG2QXF.js → chunk-X2UYIXDS.js} +59 -4
- package/dist/chunk-X2UYIXDS.js.map +1 -0
- package/dist/{chunk-C6COAB3E.js → chunk-XZPDPYVY.js} +1905 -195
- package/dist/chunk-XZPDPYVY.js.map +1 -0
- package/dist/{chunk-TVCCR6SO.js → chunk-YO5GYM73.js} +58 -9
- package/dist/chunk-YO5GYM73.js.map +1 -0
- package/dist/db/env.cjs.map +1 -1
- package/dist/db/env.d.cts +2 -0
- package/dist/db/env.d.ts +2 -0
- package/dist/db/index.cjs +285 -2
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +46 -3
- package/dist/db/index.d.ts +46 -3
- package/dist/db/index.js +14 -5
- package/dist/{index-DMZG3kpo.d.ts → endpoint-BXPdsTA5.d.ts} +370 -58
- package/dist/{index-DB_nW-AV.d.cts → endpoint-DqhUP7RT.d.cts} +370 -58
- package/dist/engine/index.cjs +2279 -356
- package/dist/engine/index.cjs.map +1 -1
- package/dist/engine/index.d.cts +5 -5
- package/dist/engine/index.d.ts +5 -5
- package/dist/engine/index.js +17 -7
- package/dist/{index-DLveQoOf.d.cts → index-Co0Hj_aO.d.cts} +108 -50
- package/dist/{index-D-3duy8Y.d.ts → index-MhCL7ll4.d.ts} +108 -50
- package/dist/index.cjs +806 -386
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +27 -15
- package/dist/index.js.map +1 -1
- package/dist/openapi/index.cjs +7 -0
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.d.cts +3 -3
- package/dist/openapi/index.d.ts +3 -3
- package/dist/openapi/index.js +4 -3
- package/dist/openapi/index.js.map +1 -1
- package/dist/{registry-DSTThhKf.d.cts → registry-BkIVHPzB.d.cts} +3 -1
- package/dist/{registry-JjF5lcj4.d.ts → registry-CvGLR5j1.d.ts} +3 -1
- package/dist/test/index.cjs +103 -66
- package/dist/test/index.cjs.map +1 -1
- package/dist/test/index.d.cts +3 -3
- package/dist/test/index.d.ts +3 -3
- package/dist/test/index.js +33 -7
- package/dist/test/index.js.map +1 -1
- package/docs/README.md +1 -1
- package/docs/auth.md +58 -0
- package/docs/database.md +308 -0
- package/docs/examples/check-query-contracts.ts +5 -0
- package/docs/examples/database-dx.contract.json +65 -0
- package/docs/examples/database-dx.ts +63 -0
- package/docs/examples/money-transfer.ts +73 -0
- package/docs/llms-full.txt +382 -1
- package/docs/schema.md +15 -0
- package/package.json +1 -2
- package/template/db/public.ts +12 -0
- package/template/package.json +1 -1
- package/dist/chunk-AAT5G7KY.js.map +0 -1
- package/dist/chunk-C6COAB3E.js.map +0 -1
- package/dist/chunk-KATPXCJ5.js.map +0 -1
- package/dist/chunk-SI4KGEM3.js.map +0 -1
- package/dist/chunk-TVCCR6SO.js.map +0 -1
- package/dist/chunk-WWUG2QXF.js.map +0 -1
- package/dist/chunk-XOX6RFPZ.js.map +0 -1
- package/dist/chunk-YIQ4RS4F.js.map +0 -1
- package/stack-images.json +0 -24
|
@@ -1,8 +1,112 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ZodSchema, z } from 'zod';
|
|
1
|
+
import { z, ZodSchema } from 'zod';
|
|
3
2
|
import { PalbaseFlagKey, Buckets, BucketTypes, PalbaseSecretName } from './stack.js';
|
|
3
|
+
import { Schemas, Tables, TableTypes } from './db/env.js';
|
|
4
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
5
|
|
|
6
|
+
interface CommandOptions {
|
|
7
|
+
/** auto uses the sequential plan when a command cannot be compiled or the
|
|
8
|
+
* executor is not installed. compiled refuses fallback; sequential opts out. */
|
|
9
|
+
mode?: "auto" | "compiled" | "sequential";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface InsertManyOptions<Key extends string = string> {
|
|
13
|
+
onConflict?: readonly Key[];
|
|
14
|
+
/** Defaults to ignore when onConflict is supplied. */
|
|
15
|
+
action?: "ignore" | "update";
|
|
16
|
+
/** false returns the affected row count and skips row serialization. */
|
|
17
|
+
returning?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Forward and backward requests are exclusive. Omit the size for 50 rows. */
|
|
21
|
+
type PageNavigation = {
|
|
22
|
+
first?: number;
|
|
23
|
+
after?: string;
|
|
24
|
+
last?: never;
|
|
25
|
+
before?: never;
|
|
26
|
+
} | {
|
|
27
|
+
last?: number;
|
|
28
|
+
before?: string;
|
|
29
|
+
first?: never;
|
|
30
|
+
after?: never;
|
|
31
|
+
};
|
|
32
|
+
interface PageInfo {
|
|
33
|
+
startCursor: string | null;
|
|
34
|
+
endCursor: string | null;
|
|
35
|
+
hasNextPage: boolean;
|
|
36
|
+
hasPreviousPage: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface Page<Row> {
|
|
39
|
+
rows: Row[];
|
|
40
|
+
pageInfo: PageInfo;
|
|
41
|
+
}
|
|
42
|
+
/** The raw transport surface. Typed tables restrict column and relation names. */
|
|
43
|
+
type RawPageOptions = PageNavigation & {
|
|
44
|
+
orderBy?: {
|
|
45
|
+
column: string;
|
|
46
|
+
direction?: "asc" | "desc";
|
|
47
|
+
nulls?: "first" | "last";
|
|
48
|
+
} | readonly {
|
|
49
|
+
column: string;
|
|
50
|
+
direction?: "asc" | "desc";
|
|
51
|
+
nulls?: "first" | "last";
|
|
52
|
+
}[];
|
|
53
|
+
select?: readonly string[];
|
|
54
|
+
with?: Record<string, unknown>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
interface DatabaseBudget {
|
|
58
|
+
/** Application statements, including failed statements and retry attempts. */
|
|
59
|
+
maxQueries?: number;
|
|
60
|
+
/** Root rows returned across application statements. Nested relation rows are included in bytes. */
|
|
61
|
+
maxRows?: number;
|
|
62
|
+
/** Estimated JSON result bytes; this is not PostgreSQL protocol traffic. */
|
|
63
|
+
maxBytes?: number;
|
|
64
|
+
}
|
|
65
|
+
interface DatabaseQueryEvent {
|
|
66
|
+
ordinal: number;
|
|
67
|
+
fingerprint: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
sql?: string;
|
|
70
|
+
source?: string;
|
|
71
|
+
durationMs: number;
|
|
72
|
+
rows: number;
|
|
73
|
+
bytes: number;
|
|
74
|
+
errorCode?: string;
|
|
75
|
+
}
|
|
76
|
+
interface DatabaseDiagnostics {
|
|
77
|
+
endpoint?: string;
|
|
78
|
+
requestId?: string;
|
|
79
|
+
outcome: "active" | "committed" | "failed";
|
|
80
|
+
elapsedMs: number;
|
|
81
|
+
queries: number;
|
|
82
|
+
rows: number;
|
|
83
|
+
bytes: number;
|
|
84
|
+
queueMs: number;
|
|
85
|
+
/** Time until the driver's transaction callback starts; includes wire BEGIN. */
|
|
86
|
+
poolMs: number;
|
|
87
|
+
setupMs: number;
|
|
88
|
+
/** Driver wait including PostgreSQL execution/locks and network time. */
|
|
89
|
+
sqlMs: number;
|
|
90
|
+
commitMs: number;
|
|
91
|
+
rollbackMs: number;
|
|
92
|
+
commits: number;
|
|
93
|
+
commitFailures: number;
|
|
94
|
+
rollbackRequests: number;
|
|
95
|
+
retries: number;
|
|
96
|
+
/** Bounded to the first 200 completed statements. Totals include every statement. */
|
|
97
|
+
statements: readonly DatabaseQueryEvent[];
|
|
98
|
+
}
|
|
99
|
+
interface DatabaseDiagnosticsOptions extends DatabaseBudget {
|
|
100
|
+
endpoint?: string;
|
|
101
|
+
requestId?: string;
|
|
102
|
+
/** Opt-in because a stack capture costs work on every statement. */
|
|
103
|
+
captureSource?: boolean;
|
|
104
|
+
/** SQL parameters are never recorded. Raw SQL text can contain inline literals. */
|
|
105
|
+
includeSql?: boolean;
|
|
106
|
+
onQuery?: (event: DatabaseQueryEvent) => void | Promise<void>;
|
|
107
|
+
onComplete?: (diagnostics: DatabaseDiagnostics) => void | Promise<void>;
|
|
108
|
+
}
|
|
109
|
+
|
|
6
110
|
/** Supported HTTP methods for endpoints. */
|
|
7
111
|
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
8
112
|
/**
|
|
@@ -58,6 +162,11 @@ interface User {
|
|
|
58
162
|
/**
|
|
59
163
|
* The caller's APPLICATION roles, as assigned in `auth.user_roles`.
|
|
60
164
|
*
|
|
165
|
+
* A snapshot for display, NOT the authority: read `can` on rows and
|
|
166
|
+
* `pb.auth.permissions` in clients. `can` is for the interface; it cannot be
|
|
167
|
+
* used for an authorization decision; it may be incomplete; the server
|
|
168
|
+
* decides again on every request.
|
|
169
|
+
*
|
|
61
170
|
* Not to be confused with {@link User.role}, which is the DATABASE role RLS
|
|
62
171
|
* reads and is the literal string "authenticated" for every signed-in user.
|
|
63
172
|
* These are the names a stack declares (`palbase roles`) and an operator
|
|
@@ -144,6 +253,13 @@ type MiddlewareHandler = (ctx: MiddlewareContext, next: () => Promise<void>) =>
|
|
|
144
253
|
*/
|
|
145
254
|
declare function defineMiddleware(_fn: MiddlewareHandler): never;
|
|
146
255
|
|
|
256
|
+
/** A union of exact keys, not a partial row that could match many records. */
|
|
257
|
+
type UniqueWhere<Row, Keys> = Keys extends readonly (infer Key extends readonly string[])[] ? Key extends unknown ? {
|
|
258
|
+
[K in Extract<Key[number], keyof Row>]-?: NonNullable<Row[K]>;
|
|
259
|
+
} & {
|
|
260
|
+
[K in Exclude<keyof Row, Key[number]>]?: never;
|
|
261
|
+
} : never : never;
|
|
262
|
+
|
|
147
263
|
/** On delete action for foreign key references. */
|
|
148
264
|
type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
|
|
149
265
|
/**
|
|
@@ -886,6 +1002,34 @@ declare class PolicyBuilder {
|
|
|
886
1002
|
* `(table, name)`, so names must be unique per table.
|
|
887
1003
|
*/
|
|
888
1004
|
declare function policy(name: string): PolicyBuilder;
|
|
1005
|
+
/**
|
|
1006
|
+
* `can` alanının YANIT şeması (FR-004, D-14).
|
|
1007
|
+
*
|
|
1008
|
+
* Bir satırın `can`'i, tablonun adlandırılmış UPDATE policy'lerinden o satır ve
|
|
1009
|
+
* çağıran için `true` dönenlerin adıdır (engine `canColumns`). Yanıt şemaları
|
|
1010
|
+
* elle yazılan zod olduğu için (`dto/*.ts`) bu alan OpenAPI'ye ancak buradan
|
|
1011
|
+
* girer: `z.object({ …, can: can(transfers) })`. Enum değerleri policy
|
|
1012
|
+
* TANIMINDAN gelir — elle yazılan policy adı yoktur; iki codegen (`emitter.ts`
|
|
1013
|
+
* enum→union, swiftgen enum→`case`) tipli sabitleri buradan üretir.
|
|
1014
|
+
*
|
|
1015
|
+
* SÖZLEŞME (FR-005): `can` ARAYÜZ içindir; yetki kararı için kullanılamaz;
|
|
1016
|
+
* eksik olabilir (render edilemeyen policy düşer); sunucu her istekte yeniden
|
|
1017
|
+
* karar verir. Ham string policy'de kolon adlarını NİTELİKSİZ yazın — motor
|
|
1018
|
+
* ifadeyi `t` alias'ı altında seçer, `transfers.status` orada çözülmez; yorum
|
|
1019
|
+
* (`--`, `/*`) ve `auth.has_permission(...)`'ın `(select …)` sarmalı olmadan
|
|
1020
|
+
* çağrılması da o policy'yi `can`'den düşürür (warn ile). Yalnız `.for("update")`
|
|
1021
|
+
* policy'leri `can`'e girer; `.for("all")` UPDATE'i yönetir ama yankılanmaz.
|
|
1022
|
+
* `(select …)` sarmalayıcısını motor bir METİN kapısıyla arar (tırnaklı/boşluklu
|
|
1023
|
+
* yazımların sonlu olmayan kümesini DOĞRULAMAZ): bir çağrının satır başına
|
|
1024
|
+
* koşup koşmadığının ölçümü EXPLAIN ANALYZE'dır ve demo koşusunda (T016)
|
|
1025
|
+
* alınır — yavaş bir `can` yanlış değildir, kapı yalnız yaygın yanlışı yakalar.
|
|
1026
|
+
* `can` adı rezervedir: `can` kolonu olan tabloda yankı yok (bu fonksiyon fırlatır),
|
|
1027
|
+
* `can` adlı ilişki (`can` tablosu, `can_id` FK, `as`/`reverseAs: "can"`) ise
|
|
1028
|
+
* `defineTable`'da reddedilir.
|
|
1029
|
+
* AS RESTRICTIVE policy'ler Postgres'te olduğu gibi her izinli policy'ye AND'lenir;
|
|
1030
|
+
* `TO <rol>` listesi oturum rolüyle kapılanır.
|
|
1031
|
+
*/
|
|
1032
|
+
declare function can<C extends ColumnMap>(table: TableDef<C>): z.ZodArray<z.ZodEnum<[string, ...string[]]>>;
|
|
889
1033
|
|
|
890
1034
|
/**
|
|
891
1035
|
* Postgres extensions a Palbase project can enable from its schema.
|
|
@@ -1128,6 +1272,25 @@ interface TableInput<C extends ColumnMap = ColumnMap> {
|
|
|
1128
1272
|
* ```
|
|
1129
1273
|
*/
|
|
1130
1274
|
policies?: (p: PolicyExprCtx<Extract<keyof C, string>>) => (PolicyBuilder | PolicyDef)[];
|
|
1275
|
+
/**
|
|
1276
|
+
* KOŞAN SÜRÜMÜN "BU TABLOYU ARTIK OKUMUYORUM" SÖZÜ — düşürmenin ilk yarısı.
|
|
1277
|
+
*
|
|
1278
|
+
* `ColumnDef.ignored`'ın tablo karşılığı ve aynı sebeple var: şema rayı, koşan
|
|
1279
|
+
* sürümün hâlâ BEYAN ettiği bir şeyi düşürmeyi reddeder — sıfır satırlı bir
|
|
1280
|
+
* tablo için bile, çünkü koşan sürümün bir SELECT'i ona dokunuyor olabilir.
|
|
1281
|
+
*
|
|
1282
|
+
* ONSUZ TABLO HİÇ DÜŞMÜYORDU (ölçüldü, canlı push 06.09.2026): rayın tavsiyesi
|
|
1283
|
+
* *"beyandan çıkar ve bir kez deploy et"*ti, ama beyandan çıkarmak düşürmeyi
|
|
1284
|
+
* ÜRETEN şeyin ta kendisi — o deploy'da da koşan sürüm tabloyu beyan ediyor
|
|
1285
|
+
* olur ve aynı red gelir. Kolonun çıkış yolu vardı, tablonun yoktu.
|
|
1286
|
+
*
|
|
1287
|
+
* İşaretlemek hiçbir DDL üretmez; ilk deploy'u BEDAVA yapan şey bu.
|
|
1288
|
+
*
|
|
1289
|
+
* ```ts
|
|
1290
|
+
* const cloud_images = defineTable("cloud_images", { ignored: true, columns: { … } });
|
|
1291
|
+
* ```
|
|
1292
|
+
*/
|
|
1293
|
+
ignored?: boolean;
|
|
1131
1294
|
/** Composite/named primary key (ordered column names). Omit for single-column inline .primaryKey(). */
|
|
1132
1295
|
primaryKey?: string[];
|
|
1133
1296
|
/** Named multi-column UNIQUE constraints. */
|
|
@@ -1188,6 +1351,8 @@ interface TableDef<C extends ColumnMap = ColumnMap> {
|
|
|
1188
1351
|
name: string;
|
|
1189
1352
|
columns: C;
|
|
1190
1353
|
rls: boolean;
|
|
1354
|
+
/** Koşan sürümün "bu tabloyu okumuyorum" sözü — bkz. TableInput.ignored. */
|
|
1355
|
+
ignored?: boolean;
|
|
1191
1356
|
policies: PolicyDef[];
|
|
1192
1357
|
primaryKey?: string[];
|
|
1193
1358
|
unique?: {
|
|
@@ -2938,23 +3103,95 @@ declare const Flags: PalbaseFlagsAmbient;
|
|
|
2938
3103
|
*/
|
|
2939
3104
|
declare const Realtime: PalbaseRealtimeClient;
|
|
2940
3105
|
|
|
2941
|
-
/**
|
|
2942
|
-
*
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
3106
|
+
/** Limits apply per engine process. PostgreSQL locks remain the authority when
|
|
3107
|
+
* several replicas write the same rows. Size the total budget across replicas. */
|
|
3108
|
+
interface WorkloadOptions {
|
|
3109
|
+
concurrency: number;
|
|
3110
|
+
queueLimit: number;
|
|
3111
|
+
tenantConcurrency?: number;
|
|
3112
|
+
tenantQueueLimit?: number;
|
|
3113
|
+
queueTimeoutMs?: number;
|
|
3114
|
+
/** Read from authenticated claims; defaults to tenant_id, then sub, then one
|
|
3115
|
+
* shared anonymous bucket. A request body never chooses the tenant budget. */
|
|
3116
|
+
tenantClaim?: string;
|
|
3117
|
+
}
|
|
3118
|
+
interface DatabaseWorkload {
|
|
3119
|
+
readonly name: string;
|
|
3120
|
+
readonly concurrency: number;
|
|
3121
|
+
readonly queueLimit: number;
|
|
3122
|
+
readonly tenantConcurrency: number;
|
|
3123
|
+
readonly tenantQueueLimit: number;
|
|
3124
|
+
readonly queueTimeoutMs: number;
|
|
3125
|
+
readonly tenantClaim: string;
|
|
3126
|
+
}
|
|
3127
|
+
/** Declare once at module scope and reuse on $atomic calls. Keys, queue limits
|
|
3128
|
+
* and tenant budgets affect admission, not SQL permissions or isolation. */
|
|
3129
|
+
declare function defineWorkload(name: string, options: WorkloadOptions): DatabaseWorkload;
|
|
3130
|
+
|
|
3131
|
+
/** A PostgreSQL isolation level supported by the explicit root transaction. */
|
|
3132
|
+
type TransactionIsolation = "read committed" | "repeatable read" | "serializable";
|
|
3133
|
+
interface AtomicOptions {
|
|
3134
|
+
/** Each retry opens a fresh transaction and reruns the complete callback.
|
|
3135
|
+
* Defaults to zero. Keep external effects outside it; persist an outbox instead. */
|
|
3136
|
+
retry?: number;
|
|
3137
|
+
isolation?: TransactionIsolation;
|
|
3138
|
+
readOnly?: boolean;
|
|
3139
|
+
/** Maximum wait for a PostgreSQL lock. Defaults to 5000 ms. */
|
|
3140
|
+
lockTimeoutMs?: number;
|
|
3141
|
+
/** PostgreSQL statement timeout; applies to every statement in this scope. */
|
|
3142
|
+
statementTimeoutMs?: number;
|
|
3143
|
+
/** Total work deadline including queueing and retries. Active Bun queries are
|
|
3144
|
+
* cancelled; rollback settles before release. An in-flight COMMIT is awaited. */
|
|
3145
|
+
timeoutMs?: number;
|
|
3146
|
+
signal?: AbortSignal;
|
|
3147
|
+
workload?: DatabaseWorkload;
|
|
3148
|
+
/** Resource names shared within a workload. Include a tenant prefix if the
|
|
3149
|
+
* resource ID itself is only unique inside a tenant. Requires workload. */
|
|
3150
|
+
conflictKeys?: readonly string[];
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
/** Storage metadata that affects the declared response; defaults and unrelated
|
|
3154
|
+
* columns do not change an explicitly projected query's contract. */
|
|
3155
|
+
interface QueryColumnContract {
|
|
3156
|
+
type: string;
|
|
3157
|
+
nullable: boolean;
|
|
3158
|
+
codec?: string;
|
|
3159
|
+
enumValues?: readonly string[];
|
|
3160
|
+
dimensions?: number;
|
|
3161
|
+
}
|
|
3162
|
+
interface PreparedRead {
|
|
3163
|
+
name: string;
|
|
3164
|
+
table: string;
|
|
3165
|
+
columns: Record<string, QueryColumnContract>;
|
|
3166
|
+
where: Record<string, unknown>;
|
|
3167
|
+
options: {
|
|
3168
|
+
select: string[];
|
|
3169
|
+
orderBy?: {
|
|
3170
|
+
column: string;
|
|
3171
|
+
direction?: "asc" | "desc";
|
|
3172
|
+
nulls?: "first" | "last";
|
|
3173
|
+
} | {
|
|
3174
|
+
column: string;
|
|
3175
|
+
direction?: "asc" | "desc";
|
|
3176
|
+
nulls?: "first" | "last";
|
|
3177
|
+
}[];
|
|
3178
|
+
limit?: number;
|
|
3179
|
+
};
|
|
3180
|
+
}
|
|
3181
|
+
interface CompiledRead {
|
|
3182
|
+
sql: string;
|
|
3183
|
+
params: unknown[];
|
|
3184
|
+
}
|
|
3185
|
+
interface QueryDatabase {
|
|
3186
|
+
readQuery(query: PreparedRead): Promise<Record<string, unknown>[]>;
|
|
3187
|
+
compileQuery(query: PreparedRead): CompiledRead;
|
|
3188
|
+
explainQuery(query: PreparedRead): Promise<unknown[]>;
|
|
3189
|
+
}
|
|
3190
|
+
interface EnvQueryDatabase {
|
|
3191
|
+
$readQuery: QueryDatabase["readQuery"];
|
|
3192
|
+
$compileQuery: QueryDatabase["compileQuery"];
|
|
3193
|
+
$explainQuery: QueryDatabase["explainQuery"];
|
|
3194
|
+
}
|
|
2958
3195
|
|
|
2959
3196
|
/** Keys of C whose columns are required on INSERT (not nullable, no default). */
|
|
2960
3197
|
type RequiredKeys<C> = {
|
|
@@ -2986,12 +3223,22 @@ type RowShape<T extends TableDef> = {
|
|
|
2986
3223
|
};
|
|
2987
3224
|
/** A typed table accessor that mirrors the runtime DBClient surface. */
|
|
2988
3225
|
interface TypedTable<T extends TableDef> {
|
|
3226
|
+
/** Runtime validates the key against the installed schema. Generated env tables
|
|
3227
|
+
* also check the complete unique/composite key at compile time. */
|
|
3228
|
+
findUnique<K extends keyof RowShape<T> = keyof RowShape<T>>(q: {
|
|
3229
|
+
where: Partial<RowShape<T>>;
|
|
3230
|
+
select?: readonly K[];
|
|
3231
|
+
}): Promise<Pick<RowShape<T>, K> | null>;
|
|
3232
|
+
page<K extends keyof RowShape<T> = keyof RowShape<T>>(q?: PageInput<RowShape<T>, K>): Promise<Page<Pick<RowShape<T>, K>>>;
|
|
2989
3233
|
insert(data: InsertValues<InsertShape<T>>): Promise<RowShape<T>>;
|
|
2990
3234
|
/** Çok satır, TEK statement. Satırların anahtar kümesi aynı olmalı. */
|
|
2991
|
-
insertMany(rows: readonly InsertValues<InsertShape<T>>[], opts
|
|
2992
|
-
|
|
2993
|
-
|
|
3235
|
+
insertMany(rows: readonly InsertValues<InsertShape<T>>[], opts: InsertManyOptions & {
|
|
3236
|
+
returning: false;
|
|
3237
|
+
}): Promise<number>;
|
|
3238
|
+
insertMany(rows: readonly InsertValues<InsertShape<T>>[], opts?: InsertManyOptions & {
|
|
3239
|
+
returning?: true;
|
|
2994
3240
|
}): Promise<RowShape<T>[]>;
|
|
3241
|
+
insertMany(rows: readonly InsertValues<InsertShape<T>>[], opts?: InsertManyOptions): Promise<RowShape<T>[] | number>;
|
|
2995
3242
|
put(q: {
|
|
2996
3243
|
data: InsertShape<T>;
|
|
2997
3244
|
onConflict: readonly string[];
|
|
@@ -3058,7 +3305,9 @@ interface TypedTable<T extends TableDef> {
|
|
|
3058
3305
|
}): Promise<number>;
|
|
3059
3306
|
}
|
|
3060
3307
|
/** A typed DB facade covering all tables declared in schema `S`. */
|
|
3061
|
-
interface TypedDB<S extends SchemaDef> {
|
|
3308
|
+
interface TypedDB<S extends SchemaDef> extends QueryDatabase {
|
|
3309
|
+
diagnostics: DBOps["diagnostics"];
|
|
3310
|
+
command<T>(fn: (tx: TypedTx<S>) => T extends Promise<unknown> ? never : T, options?: CommandOptions): Promise<Materialized<T>>;
|
|
3062
3311
|
tables: {
|
|
3063
3312
|
[K in keyof S["tables"]]: TypedTable<S["tables"][K]>;
|
|
3064
3313
|
};
|
|
@@ -3095,7 +3344,7 @@ type TypedTx<S extends SchemaDef> = TxPlanHandle<{
|
|
|
3095
3344
|
* object to the precise mapped type (TS cannot infer the mapped-type result
|
|
3096
3345
|
* through `Object.keys` iteration) — see the module-level doc comment.
|
|
3097
3346
|
*/
|
|
3098
|
-
declare function makeTypedDB<S extends SchemaDef>(schema: S, raw:
|
|
3347
|
+
declare function makeTypedDB<S extends SchemaDef>(schema: S, raw: AtomicClient): TypedDB<S>;
|
|
3099
3348
|
/** Bir where değeri: düz eşitlik YA DA operatör nesnesi (FR-016). */
|
|
3100
3349
|
/**
|
|
3101
3350
|
* Metin operatörleri YALNIZ metin kolonlarında görünür (FR-005).
|
|
@@ -3240,10 +3489,9 @@ type SqlFragment = {
|
|
|
3240
3489
|
/**
|
|
3241
3490
|
* Retryable bir hatada işlemi yeniden dener (FR-037).
|
|
3242
3491
|
*
|
|
3243
|
-
*
|
|
3244
|
-
*
|
|
3245
|
-
*
|
|
3246
|
-
* çalışan yarısı.
|
|
3492
|
+
* `fn` must open and settle a NEW transaction on each invocation. Repeating
|
|
3493
|
+
* a savepoint retains the old snapshot and cannot retry a failed COMMIT.
|
|
3494
|
+
* Database.$atomic owns that boundary for ordinary application code.
|
|
3247
3495
|
*
|
|
3248
3496
|
* VARSAYILAN SIFIR. Sessiz bir varsayılan retry, idempotent OLMAYAN bir işlemi
|
|
3249
3497
|
* çağıranın haberi olmadan iki kez çalıştırırdı — bir para transferini iki kez.
|
|
@@ -3283,7 +3531,12 @@ type TextOps<V> = V extends string ? {
|
|
|
3283
3531
|
icontains?: string;
|
|
3284
3532
|
startsWith?: string;
|
|
3285
3533
|
endsWith?: string;
|
|
3286
|
-
} :
|
|
3534
|
+
} : {
|
|
3535
|
+
contains?: never;
|
|
3536
|
+
icontains?: never;
|
|
3537
|
+
startsWith?: never;
|
|
3538
|
+
endsWith?: never;
|
|
3539
|
+
};
|
|
3287
3540
|
/** Operatör gövdesi, kolon-referans tipi DIŞARIDAN verilmiş hâliyle.
|
|
3288
3541
|
*
|
|
3289
3542
|
* `C` bir parametre, çünkü `ColRefOf<Row, V>` aksi hâlde altı operatör
|
|
@@ -3469,16 +3722,17 @@ type HasBranch<Row, Rels> = [unknown] extends [Rels] ? never : [keyof Rels] exte
|
|
|
3469
3722
|
* `true` bütün kolonları, bir nesne ise `select`/`where`/`orderBy`/`limit` ile
|
|
3470
3723
|
* daraltılmış hâlini getiriyor. Tek sorgu: LATERAL + `json_agg`.
|
|
3471
3724
|
*/
|
|
3472
|
-
type WithOpts<To> = {
|
|
3725
|
+
type WithOpts<To, D extends HasDepth> = {
|
|
3473
3726
|
select?: readonly Extract<keyof RelatedRow<To>, string>[];
|
|
3474
3727
|
where?: WhereFilter<RelatedRow<To>>;
|
|
3475
3728
|
orderBy?: OrderBySpec<RelatedRow<To>> | readonly OrderBySpec<RelatedRow<To>>[];
|
|
3476
3729
|
limit?: number;
|
|
3730
|
+
with?: D extends 1 ? never : [keyof RelatedRels<To>] extends [never] ? never : WithInput<RelatedRels<To>, HasDec[D]>;
|
|
3477
3731
|
};
|
|
3478
|
-
type WithInput<Rels> = {
|
|
3732
|
+
type WithInput<Rels, D extends HasDepth = 3> = {
|
|
3479
3733
|
[R in keyof Rels]?: Rels[R] extends {
|
|
3480
3734
|
to: infer To;
|
|
3481
|
-
} ? true | WithOpts<To> : never;
|
|
3735
|
+
} ? true | WithOpts<To, D> : never;
|
|
3482
3736
|
};
|
|
3483
3737
|
/** Bir `with` dalının DÖNÜŞ tipi — `many` dizi, `one` tekil ya da null. */
|
|
3484
3738
|
type WithRowOf<Rels, R extends keyof Rels, Q> = Rels[R] extends {
|
|
@@ -3486,7 +3740,9 @@ type WithRowOf<Rels, R extends keyof Rels, Q> = Rels[R] extends {
|
|
|
3486
3740
|
kind: infer K;
|
|
3487
3741
|
} ? (Q extends {
|
|
3488
3742
|
select: readonly (infer C extends keyof RelatedRow<To>)[];
|
|
3489
|
-
} ? Pick<RelatedRow<To>, C> : RelatedRow<To>)
|
|
3743
|
+
} ? Pick<RelatedRow<To>, C> : RelatedRow<To>) & (Q extends {
|
|
3744
|
+
with: infer W;
|
|
3745
|
+
} ? WithResult<RelatedRels<To>, W> : unknown) extends infer Row ? [K] extends ["many"] ? Row[] : Row | null : never : never;
|
|
3490
3746
|
/**
|
|
3491
3747
|
* `with` istenmediğinde `unknown` — kesişimde YOK OLSUN diye.
|
|
3492
3748
|
*
|
|
@@ -3544,6 +3800,9 @@ type QueryInput<Row, K extends keyof Row = keyof Row, Rels = unknown> = {
|
|
|
3544
3800
|
*/
|
|
3545
3801
|
select?: readonly K[];
|
|
3546
3802
|
} & FindManyOpts<Row>;
|
|
3803
|
+
type PageInput<Row, K extends keyof Row = keyof Row, Rels = unknown> = Omit<QueryInput<Row, keyof Row, Rels>, "limit" | "offset" | "select"> & {
|
|
3804
|
+
select?: readonly K[];
|
|
3805
|
+
} & PageNavigation;
|
|
3547
3806
|
/** Bir yazmanın TEK parametresi: neyi (`where`) neye çevirdiğin (`set`). */
|
|
3548
3807
|
type MutateInput<Row, Insert, Rels = unknown> = {
|
|
3549
3808
|
where: WhereFilter<Row> | SqlFragment | HasBranch<Row, Rels>;
|
|
@@ -3727,6 +3986,16 @@ type AggregateResult<Q, Row> = Q extends {
|
|
|
3727
3986
|
} & AggBody<Q, Row>)[] : AggBody<Q, Row>;
|
|
3728
3987
|
/** Temel tablo erişimcisi — search'süz beş op. */
|
|
3729
3988
|
interface EnvTypedTableBase<T extends TableTypes> {
|
|
3989
|
+
findUnique<K extends keyof T["row"] = keyof T["row"], W extends WithInput<RelsOf<T>> = Record<never, never>>(q: {
|
|
3990
|
+
where: UniqueWhere<T["row"], T["uniqueKeys"]>;
|
|
3991
|
+
select?: readonly K[];
|
|
3992
|
+
with?: QueryInput<T["row"], keyof T["row"], RelsOf<T>>["with"] & W;
|
|
3993
|
+
}): Promise<(Pick<T["row"], K> & WithResult<RelsOf<T>, W>) | null>;
|
|
3994
|
+
/** Index-backed pagination. The engine appends the declared primary key to
|
|
3995
|
+
* orderBy, encrypts cursor values and validates the query and caller scope. */
|
|
3996
|
+
page<K extends keyof T["row"] = keyof T["row"], W extends WithInput<RelsOf<T>> = Record<never, never>>(q?: PageInput<T["row"], K, RelsOf<T>> & {
|
|
3997
|
+
with?: W;
|
|
3998
|
+
}): Promise<Page<Pick<T["row"], K> & WithResult<RelsOf<T>, W>>>;
|
|
3730
3999
|
insert(data: InsertValues<T["insert"]>): Promise<T["row"]>;
|
|
3731
4000
|
/**
|
|
3732
4001
|
* Çok satırı TEK statement'la ekle (tek gidiş-dönüş).
|
|
@@ -3743,14 +4012,13 @@ interface EnvTypedTableBase<T extends TableTypes> {
|
|
|
3743
4012
|
*
|
|
3744
4013
|
* Boş dizi boş sonuç döner — hata değil: "eklenecek bir şey yoktu".
|
|
3745
4014
|
*/
|
|
3746
|
-
insertMany(rows: readonly InsertValues<T["insert"]>[], opts
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
* üzerine yazar. */
|
|
3752
|
-
action?: "ignore" | "update";
|
|
4015
|
+
insertMany(rows: readonly InsertValues<T["insert"]>[], opts: InsertManyOptions<Extract<keyof T["row"], string>> & {
|
|
4016
|
+
returning: false;
|
|
4017
|
+
}): Promise<number>;
|
|
4018
|
+
insertMany(rows: readonly InsertValues<T["insert"]>[], opts?: InsertManyOptions<Extract<keyof T["row"], string>> & {
|
|
4019
|
+
returning?: true;
|
|
3753
4020
|
}): Promise<T["row"][]>;
|
|
4021
|
+
insertMany(rows: readonly InsertValues<T["insert"]>[], opts?: InsertManyOptions<Extract<keyof T["row"], string>>): Promise<T["row"][] | number>;
|
|
3754
4022
|
/**
|
|
3755
4023
|
* Bir idempotency anahtarını sahiplen (FR-033).
|
|
3756
4024
|
*
|
|
@@ -4007,13 +4275,22 @@ type TxPlan = TxPlanHandle<TxTables> & TxSchemaSurface;
|
|
|
4007
4275
|
* Every op it performs runs as the `service_role` (BYPASSRLS).
|
|
4008
4276
|
*/
|
|
4009
4277
|
type EnvServiceDatabase = EnvSchemaSurface & {
|
|
4278
|
+
/** Commits independently of the request. All decision reads and writes belong
|
|
4279
|
+
* inside this callback; each retry includes a new BEGIN and COMMIT. */
|
|
4280
|
+
$atomic<T>(fn: (tx: AtomicDatabase) => Promise<T>, options?: AtomicOptions): Promise<T>;
|
|
4010
4281
|
/** Ham SQL. Generic verilmezse `unknown[]` döner (FR-021). */
|
|
4011
4282
|
$query: DBClient["query"];
|
|
4012
4283
|
$insert: DBClient["insert"];
|
|
4013
4284
|
$update: DBClient["update"];
|
|
4014
4285
|
$delete: DBClient["delete"];
|
|
4015
4286
|
$findById: DBClient["findById"];
|
|
4287
|
+
$findUnique: DBClient["findUnique"];
|
|
4288
|
+
$readQuery: DBClient["readQuery"];
|
|
4289
|
+
$diagnostics: DBClient["diagnostics"];
|
|
4290
|
+
$compileQuery: DBClient["compileQuery"];
|
|
4291
|
+
$explainQuery: DBClient["explainQuery"];
|
|
4016
4292
|
$findMany: DBClient["findMany"];
|
|
4293
|
+
$page: DBClient["page"];
|
|
4017
4294
|
$put: DBClient["put"];
|
|
4018
4295
|
$updateMany: DBClient["updateMany"];
|
|
4019
4296
|
$deleteMany: DBClient["deleteMany"];
|
|
@@ -4027,12 +4304,12 @@ type EnvServiceDatabase = EnvSchemaSurface & {
|
|
|
4027
4304
|
$lockRows: DBClient["lockRows"];
|
|
4028
4305
|
$advisoryXactLock: DBClient["advisoryXactLock"];
|
|
4029
4306
|
$attempt: DBClient["attempt"];
|
|
4307
|
+
$command<T>(fn: (tx: TxPlan) => T extends Promise<unknown> ? never : T, options?: CommandOptions): Promise<Materialized<T>>;
|
|
4030
4308
|
/** Bkz. {@link EnvTypedDatabase.$transaction}. */
|
|
4031
4309
|
/**
|
|
4032
|
-
*
|
|
4033
|
-
*
|
|
4034
|
-
*
|
|
4035
|
-
* haberi olmadan iki kez çalıştırırdı.
|
|
4310
|
+
* A plan is a savepoint in the current transaction. Nonzero `retry` is
|
|
4311
|
+
* refused; use $atomic for whole-transaction retry, including decision reads
|
|
4312
|
+
* and COMMIT. The default plan keeps request-scoped commit/rollback behavior.
|
|
4036
4313
|
*/
|
|
4037
4314
|
$transaction<T>(fn: (tx: TxPlan) => T extends Promise<unknown> ? never : T, opts?: {
|
|
4038
4315
|
retry?: number;
|
|
@@ -4072,13 +4349,22 @@ type EnvSchemaSurface = {
|
|
|
4072
4349
|
* await Database.$transaction((tx) => { … });
|
|
4073
4350
|
*/
|
|
4074
4351
|
type EnvTypedDatabase = EnvSchemaSurface & {
|
|
4352
|
+
/** Commits independently of the request. A later handler failure does not
|
|
4353
|
+
* undo this scope. The callback cannot switch RLS identity or nest a root. */
|
|
4354
|
+
$atomic<T>(fn: (tx: AtomicDatabase) => Promise<T>, options?: AtomicOptions): Promise<T>;
|
|
4075
4355
|
/** Ham SQL. Generic verilmezse `unknown[]` döner (FR-021). */
|
|
4076
4356
|
$query: DBClient["query"];
|
|
4077
4357
|
$insert: DBClient["insert"];
|
|
4078
4358
|
$update: DBClient["update"];
|
|
4079
4359
|
$delete: DBClient["delete"];
|
|
4080
4360
|
$findById: DBClient["findById"];
|
|
4361
|
+
$findUnique: DBClient["findUnique"];
|
|
4362
|
+
$readQuery: DBClient["readQuery"];
|
|
4363
|
+
$diagnostics: DBClient["diagnostics"];
|
|
4364
|
+
$compileQuery: DBClient["compileQuery"];
|
|
4365
|
+
$explainQuery: DBClient["explainQuery"];
|
|
4081
4366
|
$findMany: DBClient["findMany"];
|
|
4367
|
+
$page: DBClient["page"];
|
|
4082
4368
|
$put: DBClient["put"];
|
|
4083
4369
|
$updateMany: DBClient["updateMany"];
|
|
4084
4370
|
$deleteMany: DBClient["deleteMany"];
|
|
@@ -4092,6 +4378,7 @@ type EnvTypedDatabase = EnvSchemaSurface & {
|
|
|
4092
4378
|
$lockRows: DBClient["lockRows"];
|
|
4093
4379
|
$advisoryXactLock: DBClient["advisoryXactLock"];
|
|
4094
4380
|
$attempt: DBClient["attempt"];
|
|
4381
|
+
$command<T>(fn: (tx: TxPlan) => T extends Promise<unknown> ? never : T, options?: CommandOptions): Promise<Materialized<T>>;
|
|
4095
4382
|
/** RLS'i bypass eden kardeş yüzey. Kendisi `$asService` TAŞIMAZ — çift bypass yok. */
|
|
4096
4383
|
$asService(): EnvServiceDatabase;
|
|
4097
4384
|
/**
|
|
@@ -4100,15 +4387,16 @@ type EnvTypedDatabase = EnvSchemaSurface & {
|
|
|
4100
4387
|
* Callback SENKRONDUR: döndüğünde hiçbir şey çalışmamıştır.
|
|
4101
4388
|
*/
|
|
4102
4389
|
/**
|
|
4103
|
-
*
|
|
4104
|
-
*
|
|
4105
|
-
*
|
|
4106
|
-
* haberi olmadan iki kez çalıştırırdı.
|
|
4390
|
+
* A plan is a savepoint in the current transaction. Nonzero `retry` is
|
|
4391
|
+
* refused; use $atomic for whole-transaction retry, including decision reads
|
|
4392
|
+
* and COMMIT. The default plan keeps request-scoped commit/rollback behavior.
|
|
4107
4393
|
*/
|
|
4108
4394
|
$transaction<T>(fn: (tx: TxPlan) => T extends Promise<unknown> ? never : T, opts?: {
|
|
4109
4395
|
retry?: number;
|
|
4110
4396
|
}): Promise<Materialized<T>>;
|
|
4111
4397
|
};
|
|
4398
|
+
/** The same typed table/query surface on one active physical transaction. */
|
|
4399
|
+
type AtomicDatabase = Omit<EnvServiceDatabase, "$atomic">;
|
|
4112
4400
|
|
|
4113
4401
|
/**
|
|
4114
4402
|
* tx-plan.ts — `Database.$transaction()` as a PLAN, not a pinned session.
|
|
@@ -4768,7 +5056,16 @@ interface RateLimitConfig {
|
|
|
4768
5056
|
}
|
|
4769
5057
|
/** The six raw string-keyed DB operations shared by `DBClient` and the
|
|
4770
5058
|
* transaction-scoped client. */
|
|
4771
|
-
interface DBOps {
|
|
5059
|
+
interface DBOps extends QueryDatabase {
|
|
5060
|
+
/** Null when diagnostics/budgets are disabled. Binding values are never included. */
|
|
5061
|
+
diagnostics(): DatabaseDiagnostics | null;
|
|
5062
|
+
/** Match exactly one declared primary/unique key; null never denotes a unique value. */
|
|
5063
|
+
findUnique(table: string, where: Record<string, unknown>, opts?: {
|
|
5064
|
+
select?: readonly string[];
|
|
5065
|
+
with?: Record<string, unknown>;
|
|
5066
|
+
}): Promise<Record<string, unknown> | null>;
|
|
5067
|
+
/** Keyset pagination with opaque, lossless cursors and a unique ordering. */
|
|
5068
|
+
page(table: string, query?: Record<string, unknown>, opts?: RawPageOptions): Promise<Page<Record<string, unknown>>>;
|
|
4772
5069
|
/**
|
|
4773
5070
|
* Run SQL on the REQUEST'S OWN transaction.
|
|
4774
5071
|
*
|
|
@@ -4814,10 +5111,13 @@ interface DBOps {
|
|
|
4814
5111
|
count?: boolean;
|
|
4815
5112
|
groupBy?: readonly string[];
|
|
4816
5113
|
}): Promise<Record<string, unknown> | Record<string, unknown>[]>;
|
|
4817
|
-
insertMany(table: string, rows: readonly Record<string, unknown>[], opts
|
|
4818
|
-
|
|
4819
|
-
|
|
5114
|
+
insertMany(table: string, rows: readonly Record<string, unknown>[], opts: InsertManyOptions & {
|
|
5115
|
+
returning: false;
|
|
5116
|
+
}): Promise<number>;
|
|
5117
|
+
insertMany(table: string, rows: readonly Record<string, unknown>[], opts?: InsertManyOptions & {
|
|
5118
|
+
returning?: true;
|
|
4820
5119
|
}): Promise<Record<string, unknown>[]>;
|
|
5120
|
+
insertMany(table: string, rows: readonly Record<string, unknown>[], opts?: InsertManyOptions): Promise<Record<string, unknown>[] | number>;
|
|
4821
5121
|
/**
|
|
4822
5122
|
* Insert the row, or update it when it collides on `onConflict` — one
|
|
4823
5123
|
* statement, so two concurrent callers cannot both lose.
|
|
@@ -4945,7 +5245,14 @@ interface DBOps {
|
|
|
4945
5245
|
orderBy?: {
|
|
4946
5246
|
column: string;
|
|
4947
5247
|
direction?: "asc" | "desc";
|
|
4948
|
-
|
|
5248
|
+
nulls?: "first" | "last";
|
|
5249
|
+
} | {
|
|
5250
|
+
column: string;
|
|
5251
|
+
direction?: "asc" | "desc";
|
|
5252
|
+
nulls?: "first" | "last";
|
|
5253
|
+
}[];
|
|
5254
|
+
select?: string[];
|
|
5255
|
+
with?: Record<string, unknown>;
|
|
4949
5256
|
limit?: number;
|
|
4950
5257
|
offset?: number;
|
|
4951
5258
|
}): Promise<Record<string, unknown>[]>;
|
|
@@ -4995,15 +5302,18 @@ interface DBOps {
|
|
|
4995
5302
|
}
|
|
4996
5303
|
/** Database client interface injected into endpoint context. */
|
|
4997
5304
|
interface DBClient extends DBOps {
|
|
5305
|
+
/** Execute a compilable plan on PostgreSQL, with an explicit fallback policy. */
|
|
5306
|
+
command(plan: TxPlanBody, options?: CommandOptions): Promise<TxPlanResponse>;
|
|
5307
|
+
/** An independent physical transaction. Resolves after COMMIT, and retries the
|
|
5308
|
+
* complete callback on a fresh transaction. One identity for its entire scope. */
|
|
5309
|
+
atomic<T>(fn: (tx: AtomicClient) => Promise<T>, options?: AtomicOptions): Promise<T>;
|
|
4998
5310
|
/**
|
|
4999
5311
|
* Run a whole transaction as ONE plan, executed on the request's own
|
|
5000
5312
|
* transaction inside a savepoint.
|
|
5001
5313
|
*
|
|
5002
5314
|
* The low-level seam behind `Database.$transaction(plan)`: the SDK builds the
|
|
5003
|
-
* plan
|
|
5004
|
-
*
|
|
5005
|
-
* Nothing pins a Postgres backend across round trips, because there is only
|
|
5006
|
-
* one round trip.
|
|
5315
|
+
* plan and the local engine executes it on this transaction. A single API
|
|
5316
|
+
* call can issue several SQL statements; it does not promise one DB round trip.
|
|
5007
5317
|
*
|
|
5008
5318
|
* On failure the runtime must reject with an error carrying the broker's
|
|
5009
5319
|
* envelope fields — see {@link TxPlanRejection}. `slot` in particular is what
|
|
@@ -5028,6 +5338,8 @@ interface DBClient extends DBOps {
|
|
|
5028
5338
|
*/
|
|
5029
5339
|
asService(): Omit<DBClient, "asService">;
|
|
5030
5340
|
}
|
|
5341
|
+
/** An active root-transaction handle cannot switch identities or nest another root. */
|
|
5342
|
+
type AtomicClient = Omit<DBClient, "asService" | "atomic">;
|
|
5031
5343
|
/** Logger interface injected into endpoint context. */
|
|
5032
5344
|
interface Logger {
|
|
5033
5345
|
info(message: string, ...args: unknown[]): void;
|
|
@@ -5319,4 +5631,4 @@ type Middleware = (ctx: MiddlewareContext, next: () => Promise<void>) => Promise
|
|
|
5319
5631
|
*/
|
|
5320
5632
|
type AuthSpec = boolean | Partial<AuthConfig>;
|
|
5321
5633
|
|
|
5322
|
-
export { type
|
|
5634
|
+
export { type ErrorMap as $, type AuthSpec as A, BadRequest as B, type CompiledRead as C, type DatabaseBudget as D, type EnvServiceDatabase as E, type ColumnMap as F, type ColumnType as G, HttpError as H, Conflict as I, Database as J, type DatabaseQueryEvent as K, type DatabaseWorkload as L, DeadlockDetected as M, Documents as N, EXTENSION_DEPENDENCIES as O, type PreparedRead as P, type EmbeddingModelRef as Q, type RateLimitConfig as R, type SchemaDef as S, type TransactionIsolation as T, type EnvQueryDatabase as U, type EnvSchemas as V, type EnvTables as W, type EnvTypedDatabase as X, type EnvTypedTable as Y, type ErrorDef as Z, __runWithRuntime as _, type DBClient as a, type PalbaseFileObject as a$, type ErrorThrowers as a0, type FileContext as a1, type FindManyOpts as a2, Flags as a3, Forbidden as a4, type HttpMethod as a5, IndexBuilder as a6, type IndexDef as a7, type InsertManyOptions as a8, type InsertShape as a9, type PalbaseAttestiOSResult as aA, type PalbaseAuthAdminClient as aB, type PalbaseAuthClient as aC, type PalbaseBatchOverrideOperation as aD, type PalbaseBatchSetOverridesResult as aE, type PalbaseBindDeviceParams as aF, type PalbaseBucketClient as aG, type PalbaseClearAllOverridesResult as aH, type PalbaseClearOverrideResult as aI, type PalbaseCohortQueryInput as aJ, type PalbaseCohortResult as aK, type PalbaseCollectionRef as aL, type PalbaseCountQueryInput as aM, type PalbaseCountResult as aN, type PalbaseCreateLinkParams as aO, type PalbaseDeviceInfo as aP, type PalbaseDeviceTokenView as aQ, type PalbaseDocsClient as aR, type PalbaseDocumentRef as aS, type PalbaseDocumentSnapshot as aT, type PalbaseEmailClient as aU, type PalbaseEmailSendParams as aV, type PalbaseEmailSendResponse as aW, type PalbaseEventNamesResult as aX, type PalbaseEventsQueryInput as aY, type PalbaseEventsResult as aZ, type PalbaseExtension as a_, type InsertValues as aa, type LifecycleHook as ab, Log as ac, type Logger as ad, type Materialized as ae, type Middleware as af, type MiddlewareContext as ag, type MiddlewareHandler as ah, type MutateInput as ai, NotFound as aj, Notifications as ak, type OnDeleteAction as al, type OrderBySpec as am, PALBASE_EXTENSIONS as an, type PBRequest as ao, type PageInfo as ap, type PageInput as aq, type PageNavigation as ar, PalError as as, type PalbaseAnalyticsClient as at, type PalbaseAnalyticsManagementNamespace as au, type PalbaseAnalyticsProperties as av, type PalbaseAnalyticsQueryNamespace as aw, type PalbaseAttestAndroidParams as ax, type PalbaseAttestAndroidResult as ay, type PalbaseAttestiOSParams as az, type RuntimeServices as b, PolicyExprRef as b$, type PalbaseFlag as b0, type PalbaseFlagContext as b1, type PalbaseFlagSource as b2, type PalbaseFlagValue as b3, type PalbaseFlagVariant as b4, type PalbaseFlagsClient as b5, type PalbaseFlagsServiceClient as b6, type PalbaseFunctionsClient as b7, type PalbaseFunnelQueryInput as b8, type PalbaseFunnelResult as b9, type PalbaseQuerySnapshot as bA, type PalbaseRealtimeClient as bB, type PalbaseRegisterDeviceParams as bC, type PalbaseRetentionQueryInput as bD, type PalbaseRetentionResult as bE, type PalbaseSession as bF, type PalbaseSetOverrideResult as bG, type PalbaseSetOverridesResult as bH, type PalbaseSignedUrlResponse as bI, type PalbaseSmsClient as bJ, type PalbaseSmsSendParams as bK, type PalbaseSmsSendResponse as bL, type PalbaseStorageClient as bM, type PalbaseTransformOptions as bN, type PalbaseUpdateLinkParams as bO, type PalbaseUploadOptions as bP, type PalbaseUser as bQ, type PalbaseUserDetailResult as bR, type PalbaseUsersQueryInput as bS, type PalbaseUsersResult as bT, type PalbaseVerifyRequestSignatureParams as bU, type PalbaseWhereOperator as bV, type PolicyBinOp as bW, PolicyBuilder as bX, type PolicyCommand as bY, type PolicyDef as bZ, type PolicyExprCtx as b_, type PalbaseIdentifyTraits as ba, type PalbaseInboxClient as bb, type PalbaseInboxListOptions as bc, type PalbaseInboxListResult as bd, type PalbaseInboxMessage as be, type PalbaseInboxSendParams as bf, type PalbaseInboxSendResponse as bg, type PalbaseInitialLink as bh, type PalbaseInvokeOptions as bi, type PalbaseLink as bj, type PalbaseLinkAnalytics as bk, type PalbaseLinkDetails as bl, type PalbaseLinksClient as bm, type PalbaseListLinksOptions as bn, type PalbaseListLinksResult as bo, type PalbaseListOptions as bp, type PalbaseMatchParams as bq, type PalbaseMultiChannelResponse as br, type PalbaseNotificationsClient as bs, type PalbaseOverviewResult as bt, type PalbasePreferences as bu, type PalbasePreferencesClient as bv, type PalbasePushClient as bw, type PalbasePushSendParams as bx, type PalbasePushSendResponse as by, type PalbaseQrCodeOptions as bz, type DatabaseDiagnosticsOptions as c, can as c$, type PolicyMode as c0, type PolicyOperand as c1, type QueryColumnContract as c2, type QueryDatabase as c3, type QueryInput as c4, type RawConstraintDef as c5, Realtime as c6, type Ref as c7, type RequestStore as c8, type RowShape as c9, type TxSetShape as cA, type TxSetValue as cB, type TxTable as cC, type TxTables as cD, type TxWhere as cE, type TxWireExpr as cF, type TxWireGuard as cG, type TxWireOp as cH, type TxWireRef as cI, type TxWireValue as cJ, type TypedDB as cK, type TypedTable as cL, type TypedTx as cM, Unauthorized as cN, UniqueViolation as cO, type UniqueWhere as cP, type User as cQ, type VerifiedDevice as cR, type WhereFilter as cS, type WhereOp as cT, type WorkloadOptions as cU, __getRuntime as cV, __resetLifecycleHooks as cW, __runStartHooks as cX, __setRuntime as cY, bigint as cZ, boolean as c_, Secrets as ca, type SecretsService as cb, SerializationFailure as cc, type SetShape as cd, type SetValue as ce, type ShutdownRunner as cf, type SqlFragment as cg, Storage as ch, TABLE_META as ci, type TableDef as cj, type TableHandle as ck, type TableInput as cl, TooManyRequests as cm, type TxColumnExpr as cn, type TxInsertShape as co, type TxInsertValue as cp, type TxNow as cq, type TxPlan as cr, TxPlanError as cs, type TxPlanHandle as ct, type TxPlanOpResult as cu, type TxPlanRejection as cv, TxRefError as cw, type TxRow as cx, type TxRows as cy, type TxSelectOptions as cz, type DatabaseDiagnostics as d, col as d0, dec as d1, decrement as d2, defineMiddleware as d3, defineSchema as d4, defineTable as d5, defineWorkload as d6, enumType as d7, exprCtx as d8, inc as d9, increment as da, index as db, installationRef as dc, integer as dd, isPalbaseExtension as de, isRetryable as df, jsonb as dg, makeTypedDB as dh, now as di, numeric as dj, onShutdown as dk, onStart as dl, openai as dm, ownedByUser as dn, policy as dp, raw as dq, sqlFragment as dr, text as ds, timestamp as dt, userRef as du, uuid as dv, vector as dw, withRetry as dx, type ColValue as dy, type DBOps as e, type RawPageOptions as f, type Page as g, type TxPlanBody as h, type CommandOptions as i, type TxPlanResponse as j, type CacheClient as k, __requestALS as l, type PalbaseResult as m, type PolicyExpr as n, type AggregateInput as o, type AggregateResult as p, type AnyColumn as q, type AtomicDatabase as r, type AtomicOptions as s, Auth as t, type AuthConfig as u, Cache as v, type ClientInfo as w, type ColRef as x, ColumnBuilder as y, type ColumnDef as z };
|