@palbase/backend 8.2.0 → 8.4.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.
@@ -4,7 +4,7 @@ import { D as DBClient } from './endpoint-fW9yWla0.js';
4
4
  /** On delete action for foreign key references. */
5
5
  type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
6
6
  /** Column type identifiers. */
7
- type ColumnType = 'uuid' | 'text' | 'integer' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
7
+ type ColumnType = 'uuid' | 'text' | 'integer' | 'bigint' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
8
8
  /** Base column definition shared by all column types. */
9
9
  interface ColumnDef {
10
10
  type: ColumnType;
@@ -20,6 +20,7 @@ interface ColumnDef {
20
20
  onDeleteAction?: OnDeleteAction;
21
21
  enumName?: string;
22
22
  enumValues?: string[];
23
+ unique?: boolean;
23
24
  }
24
25
  declare const __colKind: unique symbol;
25
26
  declare const __colNullable: unique symbol;
@@ -62,16 +63,20 @@ declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean
62
63
  references(table: string, column: string): ColumnBuilder<K, N, D, E>;
63
64
  /** Set the ON DELETE action for a foreign key reference. */
64
65
  onDelete(action: OnDeleteAction): ColumnBuilder<K, N, D, E>;
66
+ /** Add a single-column UNIQUE constraint. */
67
+ unique(): ColumnBuilder<K, N, D, E>;
65
68
  }
66
69
  /**
67
70
  * Extracts the TypeScript value type for a column, respecting nullability.
68
- * - "uuid" | "text" | "timestamp" → string (or string | null when N = true)
71
+ * - "uuid" | "text" | "timestamp" | "bigint" → string (or string | null when N = true)
72
+ * Note: bigint surfaces as string because JS number loses precision past 2^53;
73
+ * pgx/PostgREST serialize int8 as string. App code uses BigInt(row.amount).
69
74
  * - "integer" → number
70
75
  * - "boolean" → boolean
71
76
  * - "jsonb" → unknown (opaque JSON)
72
77
  * - "enum" → E (the union of literal values)
73
78
  */
74
- type ColValue<C> = C extends ColumnBuilder<'uuid' | 'text' | 'timestamp', infer N, infer _D, infer _E> ? N extends true ? string | null : string : C extends ColumnBuilder<'integer', infer N, infer _D, infer _E> ? N extends true ? number | null : number : C extends ColumnBuilder<'boolean', infer N, infer _D, infer _E> ? N extends true ? boolean | null : boolean : C extends ColumnBuilder<'jsonb', infer _N, infer _D, infer _E> ? unknown : C extends ColumnBuilder<'enum', infer N, infer _D, infer E> ? N extends true ? E | null : E : never;
79
+ type ColValue<C> = C extends ColumnBuilder<'uuid' | 'text' | 'timestamp' | 'bigint', infer N, infer _D, infer _E> ? N extends true ? string | null : string : C extends ColumnBuilder<'integer', infer N, infer _D, infer _E> ? N extends true ? number | null : number : C extends ColumnBuilder<'boolean', infer N, infer _D, infer _E> ? N extends true ? boolean | null : boolean : C extends ColumnBuilder<'jsonb', infer _N, infer _D, infer _E> ? unknown : C extends ColumnBuilder<'enum', infer N, infer _D, infer E> ? N extends true ? E | null : E : never;
75
80
  /**
76
81
  * True when a column is optional on INSERT:
77
82
  * - nullable columns (N = true) — the DB allows NULL so the field may be omitted
@@ -82,8 +87,14 @@ type ColIsOptionalOnInsert<C> = C extends ColumnBuilder<infer _K, true, infer _D
82
87
  declare function uuid(): ColumnBuilder<'uuid', false, false, never>;
83
88
  /** Create a TEXT column. */
84
89
  declare function text(): ColumnBuilder<'text', false, false, never>;
85
- /** Create an INTEGER column. */
90
+ /** Create an INTEGER column. Emits int4 (max ~2.1B). */
86
91
  declare function integer(): ColumnBuilder<'integer', false, false, never>;
92
+ /**
93
+ * Create a BIGINT column (Postgres int8, max ~9.2×10^18).
94
+ * Surfaces as `string` in row/insert types — JS number loses precision past 2^53
95
+ * and pgx/PostgREST serialize int8 as a JSON string. Use BigInt(row.column) in app code.
96
+ */
97
+ declare function bigint(): ColumnBuilder<'bigint', false, false, never>;
87
98
  /** Create a BOOLEAN column. */
88
99
  declare function boolean(): ColumnBuilder<'boolean', false, false, never>;
89
100
  /** Create a TIMESTAMP column. */
@@ -212,6 +223,22 @@ declare const EXTENSION_DEPENDENCIES: Partial<Record<PalbaseExtension, PalbaseEx
212
223
  /** Runtime guard: is `name` a supported Palbase extension? */
213
224
  declare function isPalbaseExtension(name: string): name is PalbaseExtension;
214
225
 
226
+ /**
227
+ * A named raw-SQL DDL object declared in db/schema.ts for anything the typed DSL
228
+ * cannot express (EXCLUDE, CHECK, partial/expression indexes, triggers, views).
229
+ * The deploy emits `up` verbatim on the privileged DDL connection — same trust
230
+ * posture as policy().using(). Tracked by NAME (not by diffing the body), so a
231
+ * changed body needs a new name or an explicit drop+add.
232
+ */
233
+ interface RawConstraintDef {
234
+ name: string;
235
+ up: string;
236
+ down?: string;
237
+ }
238
+ declare function raw(name: string, up: string, opts?: {
239
+ down?: string;
240
+ }): RawConstraintDef;
241
+
215
242
  /**
216
243
  * A map of column builders keyed by column name — the value you write under
217
244
  * the `columns` key of `defineSchema({ tables: { <name>: { columns } } })`.
@@ -239,6 +266,41 @@ interface TableInput<C extends ColumnMap = ColumnMap> {
239
266
  columns: C;
240
267
  rls?: boolean;
241
268
  policies?: (PolicyBuilder | PolicyDef)[];
269
+ /** Composite/named primary key (ordered column names). Omit for single-column inline .primaryKey(). */
270
+ primaryKey?: string[];
271
+ /** Named multi-column UNIQUE constraints. */
272
+ unique?: {
273
+ name: string;
274
+ columns: string[];
275
+ }[];
276
+ /** Named raw-SQL DDL objects (EXCLUDE, triggers, views) that the typed DSL cannot express. */
277
+ raw?: RawConstraintDef[];
278
+ /**
279
+ * Named first-class CHECK constraints. Diffed by NAME with a BODY compare:
280
+ * a changed `expr` (after pg normalization) recreates the constraint
281
+ * (DROP + ADD). `expr` is trusted SQL emitted verbatim (like policy USING),
282
+ * `name` is identifier-validated.
283
+ */
284
+ checks?: {
285
+ name: string;
286
+ expr: string;
287
+ }[];
288
+ /**
289
+ * Plain (non-unique) btree indexes over an ordered column list, emitted as
290
+ * standalone `CREATE INDEX [IF NOT EXISTS] name ON table (col1, col2)`
291
+ * statements (NOT a table clause — a separate migration statement category).
292
+ * Structural compare by NAME (no expression normalization). `name` and each
293
+ * column are identifier-validated by the Go differ.
294
+ *
295
+ * Scope: columns-only plain btree. Partial (`where`) and expression indexes
296
+ * are a deliberate follow-up — modelling them needs the same raw-SQL
297
+ * normalization round-trip CHECK uses (Task 10), so they are NOT in this
298
+ * type yet to avoid a half-working partial-index path.
299
+ */
300
+ indexes?: {
301
+ name: string;
302
+ columns: string[];
303
+ }[];
242
304
  }
243
305
  /**
244
306
  * A table definition — the runtime value the Go runtime's `schema_extract.js`
@@ -257,6 +319,23 @@ interface TableDef<C extends ColumnMap = ColumnMap> {
257
319
  columns: C;
258
320
  rls: boolean;
259
321
  policies: PolicyDef[];
322
+ primaryKey?: string[];
323
+ unique?: {
324
+ name: string;
325
+ columns: string[];
326
+ }[];
327
+ /** Named raw-SQL DDL objects emitted verbatim on deploy. Tracked by name. */
328
+ raw?: RawConstraintDef[];
329
+ /** Named first-class CHECK constraints. Diffed by name + (normalized) body. */
330
+ checks?: {
331
+ name: string;
332
+ expr: string;
333
+ }[];
334
+ /** Plain btree indexes (columns-only), emitted as standalone CREATE INDEX. Diffed by name. */
335
+ indexes?: {
336
+ name: string;
337
+ columns: string[];
338
+ }[];
260
339
  }
261
340
  /**
262
341
  * A schema definition containing multiple tables, keyed by table name.
@@ -466,4 +545,4 @@ interface EnvTypedDatabase extends Omit<DBClient, "transaction" | "asService"> {
466
545
  asService(): EnvServiceDatabase;
467
546
  }
468
547
 
469
- export { text as A, timestamp as B, ColumnBuilder as C, uuid as D, type EnvTypedDatabase as E, type InsertShape as I, type OnDeleteAction as O, PALBASE_EXTENSIONS as P, type RowShape 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 EnvTypedTx as h, type PalbaseExtension as i, PolicyBuilder as j, type PolicyCommand as k, type PolicyDef as l, type PolicyMode as m, type SchemaInput as n, type TableInput as o, type TypedDB as p, type TypedTable as q, type TypedTx as r, boolean as s, defineSchema as t, enumType as u, integer as v, isPalbaseExtension as w, jsonb as x, makeTypedDB as y, policy as z };
548
+ export { makeTypedDB as A, policy as B, ColumnBuilder as C, raw as D, type EnvTypedDatabase as E, text as F, timestamp as G, uuid as H, type InsertShape as I, 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 EnvTypedTx 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 TypedDB as q, type TypedTable as r, type TypedTx as s, bigint as t, boolean as u, defineSchema as v, enumType as w, integer as x, isPalbaseExtension as y, jsonb as z };
@@ -4,7 +4,7 @@ import { D as DBClient } from './endpoint-fW9yWla0.cjs';
4
4
  /** On delete action for foreign key references. */
5
5
  type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
6
6
  /** Column type identifiers. */
7
- type ColumnType = 'uuid' | 'text' | 'integer' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
7
+ type ColumnType = 'uuid' | 'text' | 'integer' | 'bigint' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
8
8
  /** Base column definition shared by all column types. */
9
9
  interface ColumnDef {
10
10
  type: ColumnType;
@@ -20,6 +20,7 @@ interface ColumnDef {
20
20
  onDeleteAction?: OnDeleteAction;
21
21
  enumName?: string;
22
22
  enumValues?: string[];
23
+ unique?: boolean;
23
24
  }
24
25
  declare const __colKind: unique symbol;
25
26
  declare const __colNullable: unique symbol;
@@ -62,16 +63,20 @@ declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean
62
63
  references(table: string, column: string): ColumnBuilder<K, N, D, E>;
63
64
  /** Set the ON DELETE action for a foreign key reference. */
64
65
  onDelete(action: OnDeleteAction): ColumnBuilder<K, N, D, E>;
66
+ /** Add a single-column UNIQUE constraint. */
67
+ unique(): ColumnBuilder<K, N, D, E>;
65
68
  }
66
69
  /**
67
70
  * Extracts the TypeScript value type for a column, respecting nullability.
68
- * - "uuid" | "text" | "timestamp" → string (or string | null when N = true)
71
+ * - "uuid" | "text" | "timestamp" | "bigint" → string (or string | null when N = true)
72
+ * Note: bigint surfaces as string because JS number loses precision past 2^53;
73
+ * pgx/PostgREST serialize int8 as string. App code uses BigInt(row.amount).
69
74
  * - "integer" → number
70
75
  * - "boolean" → boolean
71
76
  * - "jsonb" → unknown (opaque JSON)
72
77
  * - "enum" → E (the union of literal values)
73
78
  */
74
- type ColValue<C> = C extends ColumnBuilder<'uuid' | 'text' | 'timestamp', infer N, infer _D, infer _E> ? N extends true ? string | null : string : C extends ColumnBuilder<'integer', infer N, infer _D, infer _E> ? N extends true ? number | null : number : C extends ColumnBuilder<'boolean', infer N, infer _D, infer _E> ? N extends true ? boolean | null : boolean : C extends ColumnBuilder<'jsonb', infer _N, infer _D, infer _E> ? unknown : C extends ColumnBuilder<'enum', infer N, infer _D, infer E> ? N extends true ? E | null : E : never;
79
+ type ColValue<C> = C extends ColumnBuilder<'uuid' | 'text' | 'timestamp' | 'bigint', infer N, infer _D, infer _E> ? N extends true ? string | null : string : C extends ColumnBuilder<'integer', infer N, infer _D, infer _E> ? N extends true ? number | null : number : C extends ColumnBuilder<'boolean', infer N, infer _D, infer _E> ? N extends true ? boolean | null : boolean : C extends ColumnBuilder<'jsonb', infer _N, infer _D, infer _E> ? unknown : C extends ColumnBuilder<'enum', infer N, infer _D, infer E> ? N extends true ? E | null : E : never;
75
80
  /**
76
81
  * True when a column is optional on INSERT:
77
82
  * - nullable columns (N = true) — the DB allows NULL so the field may be omitted
@@ -82,8 +87,14 @@ type ColIsOptionalOnInsert<C> = C extends ColumnBuilder<infer _K, true, infer _D
82
87
  declare function uuid(): ColumnBuilder<'uuid', false, false, never>;
83
88
  /** Create a TEXT column. */
84
89
  declare function text(): ColumnBuilder<'text', false, false, never>;
85
- /** Create an INTEGER column. */
90
+ /** Create an INTEGER column. Emits int4 (max ~2.1B). */
86
91
  declare function integer(): ColumnBuilder<'integer', false, false, never>;
92
+ /**
93
+ * Create a BIGINT column (Postgres int8, max ~9.2×10^18).
94
+ * Surfaces as `string` in row/insert types — JS number loses precision past 2^53
95
+ * and pgx/PostgREST serialize int8 as a JSON string. Use BigInt(row.column) in app code.
96
+ */
97
+ declare function bigint(): ColumnBuilder<'bigint', false, false, never>;
87
98
  /** Create a BOOLEAN column. */
88
99
  declare function boolean(): ColumnBuilder<'boolean', false, false, never>;
89
100
  /** Create a TIMESTAMP column. */
@@ -212,6 +223,22 @@ declare const EXTENSION_DEPENDENCIES: Partial<Record<PalbaseExtension, PalbaseEx
212
223
  /** Runtime guard: is `name` a supported Palbase extension? */
213
224
  declare function isPalbaseExtension(name: string): name is PalbaseExtension;
214
225
 
226
+ /**
227
+ * A named raw-SQL DDL object declared in db/schema.ts for anything the typed DSL
228
+ * cannot express (EXCLUDE, CHECK, partial/expression indexes, triggers, views).
229
+ * The deploy emits `up` verbatim on the privileged DDL connection — same trust
230
+ * posture as policy().using(). Tracked by NAME (not by diffing the body), so a
231
+ * changed body needs a new name or an explicit drop+add.
232
+ */
233
+ interface RawConstraintDef {
234
+ name: string;
235
+ up: string;
236
+ down?: string;
237
+ }
238
+ declare function raw(name: string, up: string, opts?: {
239
+ down?: string;
240
+ }): RawConstraintDef;
241
+
215
242
  /**
216
243
  * A map of column builders keyed by column name — the value you write under
217
244
  * the `columns` key of `defineSchema({ tables: { <name>: { columns } } })`.
@@ -239,6 +266,41 @@ interface TableInput<C extends ColumnMap = ColumnMap> {
239
266
  columns: C;
240
267
  rls?: boolean;
241
268
  policies?: (PolicyBuilder | PolicyDef)[];
269
+ /** Composite/named primary key (ordered column names). Omit for single-column inline .primaryKey(). */
270
+ primaryKey?: string[];
271
+ /** Named multi-column UNIQUE constraints. */
272
+ unique?: {
273
+ name: string;
274
+ columns: string[];
275
+ }[];
276
+ /** Named raw-SQL DDL objects (EXCLUDE, triggers, views) that the typed DSL cannot express. */
277
+ raw?: RawConstraintDef[];
278
+ /**
279
+ * Named first-class CHECK constraints. Diffed by NAME with a BODY compare:
280
+ * a changed `expr` (after pg normalization) recreates the constraint
281
+ * (DROP + ADD). `expr` is trusted SQL emitted verbatim (like policy USING),
282
+ * `name` is identifier-validated.
283
+ */
284
+ checks?: {
285
+ name: string;
286
+ expr: string;
287
+ }[];
288
+ /**
289
+ * Plain (non-unique) btree indexes over an ordered column list, emitted as
290
+ * standalone `CREATE INDEX [IF NOT EXISTS] name ON table (col1, col2)`
291
+ * statements (NOT a table clause — a separate migration statement category).
292
+ * Structural compare by NAME (no expression normalization). `name` and each
293
+ * column are identifier-validated by the Go differ.
294
+ *
295
+ * Scope: columns-only plain btree. Partial (`where`) and expression indexes
296
+ * are a deliberate follow-up — modelling them needs the same raw-SQL
297
+ * normalization round-trip CHECK uses (Task 10), so they are NOT in this
298
+ * type yet to avoid a half-working partial-index path.
299
+ */
300
+ indexes?: {
301
+ name: string;
302
+ columns: string[];
303
+ }[];
242
304
  }
243
305
  /**
244
306
  * A table definition — the runtime value the Go runtime's `schema_extract.js`
@@ -257,6 +319,23 @@ interface TableDef<C extends ColumnMap = ColumnMap> {
257
319
  columns: C;
258
320
  rls: boolean;
259
321
  policies: PolicyDef[];
322
+ primaryKey?: string[];
323
+ unique?: {
324
+ name: string;
325
+ columns: string[];
326
+ }[];
327
+ /** Named raw-SQL DDL objects emitted verbatim on deploy. Tracked by name. */
328
+ raw?: RawConstraintDef[];
329
+ /** Named first-class CHECK constraints. Diffed by name + (normalized) body. */
330
+ checks?: {
331
+ name: string;
332
+ expr: string;
333
+ }[];
334
+ /** Plain btree indexes (columns-only), emitted as standalone CREATE INDEX. Diffed by name. */
335
+ indexes?: {
336
+ name: string;
337
+ columns: string[];
338
+ }[];
260
339
  }
261
340
  /**
262
341
  * A schema definition containing multiple tables, keyed by table name.
@@ -466,4 +545,4 @@ interface EnvTypedDatabase extends Omit<DBClient, "transaction" | "asService"> {
466
545
  asService(): EnvServiceDatabase;
467
546
  }
468
547
 
469
- export { text as A, timestamp as B, ColumnBuilder as C, uuid as D, type EnvTypedDatabase as E, type InsertShape as I, type OnDeleteAction as O, PALBASE_EXTENSIONS as P, type RowShape 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 EnvTypedTx as h, type PalbaseExtension as i, PolicyBuilder as j, type PolicyCommand as k, type PolicyDef as l, type PolicyMode as m, type SchemaInput as n, type TableInput as o, type TypedDB as p, type TypedTable as q, type TypedTx as r, boolean as s, defineSchema as t, enumType as u, integer as v, isPalbaseExtension as w, jsonb as x, makeTypedDB as y, policy as z };
548
+ export { makeTypedDB as A, policy as B, ColumnBuilder as C, raw as D, type EnvTypedDatabase as E, text as F, timestamp as G, uuid as H, type InsertShape as I, 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 EnvTypedTx 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 TypedDB as q, type TypedTable as r, type TypedTx as s, bigint as t, boolean as u, defineSchema as v, enumType as w, integer as x, isPalbaseExtension as y, jsonb as z };
package/dist/index.cjs CHANGED
@@ -72,6 +72,7 @@ __export(src_exports, {
72
72
  __setRuntime: () => __setRuntime,
73
73
  __shutdownResources: () => __shutdownResources,
74
74
  auth: () => auth,
75
+ bigint: () => bigint,
75
76
  boolean: () => boolean,
76
77
  bucket: () => bucket,
77
78
  buildProvider: () => buildProvider,
@@ -95,6 +96,7 @@ __export(src_exports, {
95
96
  makeTypedDB: () => makeTypedDB,
96
97
  parseFileSizeLimit: () => parseFileSizeLimit,
97
98
  policy: () => policy,
99
+ raw: () => raw,
98
100
  recordThrows: () => recordThrows,
99
101
  reservedSecretKey: () => reservedSecretKey,
100
102
  storage: () => storage,
@@ -156,19 +158,19 @@ function makeTablesAccessor(ops) {
156
158
  return tablesProxy;
157
159
  }
158
160
  var rawDatabase = makeServiceProxy("Database");
159
- function makeTypedSurface(raw) {
161
+ function makeTypedSurface(raw2) {
160
162
  const ops = {
161
- query: (sql, params) => raw.query(sql, params),
162
- insert: (table, data) => raw.insert(table, data),
163
- update: (table, id, data) => raw.update(table, id, data),
164
- delete: (table, id) => raw.delete(table, id),
165
- findById: (table, id) => raw.findById(table, id),
166
- findMany: (table, query) => raw.findMany(table, query)
163
+ query: (sql, params) => raw2.query(sql, params),
164
+ insert: (table, data) => raw2.insert(table, data),
165
+ update: (table, id, data) => raw2.update(table, id, data),
166
+ delete: (table, id) => raw2.delete(table, id),
167
+ findById: (table, id) => raw2.findById(table, id),
168
+ findMany: (table, query) => raw2.findMany(table, query)
167
169
  };
168
170
  return Object.assign(ops, {
169
- tables: makeTablesAccessor(() => raw),
171
+ tables: makeTablesAccessor(() => raw2),
170
172
  transaction(fn) {
171
- return raw.transaction((rawTx) => fn({ tables: makeTablesAccessor(() => rawTx) }));
173
+ return raw2.transaction((rawTx) => fn({ tables: makeTablesAccessor(() => rawTx) }));
172
174
  }
173
175
  });
174
176
  }
@@ -283,12 +285,18 @@ function defineSchema(input) {
283
285
  if (table === void 0) continue;
284
286
  const policies = (table.policies ?? []).map(toPolicyDef);
285
287
  const rls = table.rls === true || policies.length > 0;
286
- tables[name] = {
288
+ const tableDef = {
287
289
  name,
288
290
  columns: table.columns,
289
291
  rls,
290
292
  policies
291
293
  };
294
+ if (table.primaryKey !== void 0) tableDef.primaryKey = table.primaryKey;
295
+ if (table.unique !== void 0) tableDef.unique = table.unique;
296
+ if (table.raw !== void 0 && table.raw.length > 0) tableDef.raw = table.raw.slice();
297
+ if (table.checks !== void 0 && table.checks.length > 0) tableDef.checks = table.checks.slice();
298
+ if (table.indexes !== void 0 && table.indexes.length > 0) tableDef.indexes = table.indexes.slice();
299
+ tables[name] = tableDef;
292
300
  }
293
301
  const extensions = [...new Set(input.extensions ?? [])];
294
302
  return { tables, extensions };
@@ -384,6 +392,11 @@ var ColumnBuilder = class _ColumnBuilder {
384
392
  this._def.onDeleteAction = action;
385
393
  return new _ColumnBuilder(this._def.type, this._def);
386
394
  }
395
+ /** Add a single-column UNIQUE constraint. */
396
+ unique() {
397
+ this._def.unique = true;
398
+ return new _ColumnBuilder(this._def.type, this._def);
399
+ }
387
400
  };
388
401
  function uuid() {
389
402
  return new ColumnBuilder("uuid");
@@ -394,6 +407,9 @@ function text() {
394
407
  function integer() {
395
408
  return new ColumnBuilder("integer");
396
409
  }
410
+ function bigint() {
411
+ return new ColumnBuilder("bigint");
412
+ }
397
413
  function boolean() {
398
414
  return new ColumnBuilder("boolean");
399
415
  }
@@ -410,17 +426,22 @@ function enumType(name, values) {
410
426
  return builder;
411
427
  }
412
428
 
429
+ // src/db/raw.ts
430
+ function raw(name, up, opts) {
431
+ return { name, up, ...opts?.down != null ? { down: opts.down } : {} };
432
+ }
433
+
413
434
  // src/db/typed-db.ts
414
- function makeTypedTable(name, raw) {
435
+ function makeTypedTable(name, raw2) {
415
436
  return {
416
- insert: (data) => raw.insert(name, data),
417
- update: (id, data) => raw.update(name, id, data),
418
- delete: (id) => raw.delete(name, id),
419
- findById: (id) => raw.findById(name, id),
420
- findMany: (query) => raw.findMany(name, query)
437
+ insert: (data) => raw2.insert(name, data),
438
+ update: (id, data) => raw2.update(name, id, data),
439
+ delete: (id) => raw2.delete(name, id),
440
+ findById: (id) => raw2.findById(name, id),
441
+ findMany: (query) => raw2.findMany(name, query)
421
442
  };
422
443
  }
423
- function makeTypedDB(schema, raw) {
444
+ function makeTypedDB(schema, raw2) {
424
445
  function buildTables(client) {
425
446
  const tables = {};
426
447
  for (const key of Object.keys(schema.tables)) {
@@ -432,8 +453,8 @@ function makeTypedDB(schema, raw) {
432
453
  return tables;
433
454
  }
434
455
  const result = {
435
- tables: buildTables(raw),
436
- transaction: (fn) => raw.transaction((rawTx) => fn({ tables: buildTables(rawTx) }))
456
+ tables: buildTables(raw2),
457
+ transaction: (fn) => raw2.transaction((rawTx) => fn({ tables: buildTables(rawTx) }))
437
458
  };
438
459
  return result;
439
460
  }
@@ -447,6 +468,8 @@ function baseTsType(def) {
447
468
  return "string";
448
469
  case "integer":
449
470
  return "number";
471
+ case "bigint":
472
+ return "string";
450
473
  case "boolean":
451
474
  return "boolean";
452
475
  case "jsonb":
@@ -1513,6 +1536,7 @@ var import_zod2 = require("zod");
1513
1536
  __setRuntime,
1514
1537
  __shutdownResources,
1515
1538
  auth,
1539
+ bigint,
1516
1540
  boolean,
1517
1541
  bucket,
1518
1542
  buildProvider,
@@ -1536,6 +1560,7 @@ var import_zod2 = require("zod");
1536
1560
  makeTypedDB,
1537
1561
  parseFileSizeLimit,
1538
1562
  policy,
1563
+ raw,
1539
1564
  recordThrows,
1540
1565
  reservedSecretKey,
1541
1566
  storage,