@palbase/backend 8.4.0 → 8.6.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/{chunk-XVPAX7AK.js → chunk-WORMYTK3.js} +21 -1
- package/dist/chunk-WORMYTK3.js.map +1 -0
- package/dist/db/index.cjs +16 -0
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.d.cts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -1
- package/dist/{index-wfWWQ8YN.d.cts → index-B0KV1w1a.d.cts} +58 -21
- package/dist/{index-LGFGRWCB.d.ts → index-CFD7RDMY.d.ts} +58 -21
- package/dist/index.cjs +21 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-XVPAX7AK.js.map +0 -1
|
@@ -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' | 'bigint' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
|
|
7
|
+
type ColumnType = 'uuid' | 'text' | 'integer' | 'bigint' | 'numeric' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
|
|
8
8
|
/** Base column definition shared by all column types. */
|
|
9
9
|
interface ColumnDef {
|
|
10
10
|
type: ColumnType;
|
|
@@ -26,57 +26,75 @@ declare const __colKind: unique symbol;
|
|
|
26
26
|
declare const __colNullable: unique symbol;
|
|
27
27
|
declare const __colHasDefault: unique symbol;
|
|
28
28
|
declare const __colEnumValues: unique symbol;
|
|
29
|
+
declare const __colPayload: unique symbol;
|
|
29
30
|
/**
|
|
30
31
|
* Fluent column builder with phantom type params:
|
|
31
32
|
* K — ColumnType literal (e.g. "text", "integer")
|
|
32
33
|
* N — boolean: true when nullable() has been called last (false = NOT NULL)
|
|
33
34
|
* D — boolean: true when a default has been set
|
|
34
35
|
* E — enum value union (never for non-enum columns)
|
|
36
|
+
* P — jsonb payload shape (unknown unless jsonb<T>() supplied one)
|
|
35
37
|
*
|
|
36
|
-
* All
|
|
38
|
+
* All five params have defaults so bare `ColumnBuilder` (no args) still
|
|
37
39
|
* satisfies `Record<string, ColumnBuilder>` in schema.ts without modification.
|
|
38
40
|
*
|
|
39
|
-
* The
|
|
41
|
+
* The five `declare readonly` brand fields carry the phantom types into the
|
|
40
42
|
* structural shape so that conditional types like ColValue<C> can discriminate
|
|
41
43
|
* on K without requiring runtime values on those fields.
|
|
42
44
|
*/
|
|
43
|
-
declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean = boolean, D extends boolean = boolean, E = unknown> {
|
|
45
|
+
declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean = boolean, D extends boolean = boolean, E = unknown, P = unknown> {
|
|
44
46
|
readonly [__colKind]: K;
|
|
45
47
|
readonly [__colNullable]: N;
|
|
46
48
|
readonly [__colHasDefault]: D;
|
|
47
49
|
readonly [__colEnumValues]: E;
|
|
50
|
+
readonly [__colPayload]: P;
|
|
48
51
|
readonly _def: ColumnDef;
|
|
49
52
|
constructor(type: K, existingDef?: ColumnDef);
|
|
50
53
|
/** Mark this column as the primary key. */
|
|
51
|
-
primaryKey(): ColumnBuilder<K, N, D, E>;
|
|
54
|
+
primaryKey(): ColumnBuilder<K, N, D, E, P>;
|
|
52
55
|
/** Mark this column as NOT NULL (default). */
|
|
53
|
-
notNull(): ColumnBuilder<K, false, D, E>;
|
|
56
|
+
notNull(): ColumnBuilder<K, false, D, E, P>;
|
|
54
57
|
/** Allow NULL values. */
|
|
55
|
-
nullable(): ColumnBuilder<K, true, D, E>;
|
|
58
|
+
nullable(): ColumnBuilder<K, true, D, E, P>;
|
|
56
59
|
/** Set a default value. */
|
|
57
|
-
default(value: unknown): ColumnBuilder<K, N, true, E>;
|
|
60
|
+
default(value: unknown): ColumnBuilder<K, N, true, E, P>;
|
|
58
61
|
/** UUID: generate a random default (gen_random_uuid()). */
|
|
59
|
-
defaultRandom(): ColumnBuilder<K, N, true, E>;
|
|
62
|
+
defaultRandom(): ColumnBuilder<K, N, true, E, P>;
|
|
60
63
|
/** Timestamp: default to now(). */
|
|
61
|
-
defaultNow(): ColumnBuilder<K, N, true, E>;
|
|
64
|
+
defaultNow(): ColumnBuilder<K, N, true, E, P>;
|
|
62
65
|
/** Add a foreign key reference. */
|
|
63
|
-
references(table: string, column: string): ColumnBuilder<K, N, D, E>;
|
|
66
|
+
references(table: string, column: string): ColumnBuilder<K, N, D, E, P>;
|
|
67
|
+
/**
|
|
68
|
+
* Add a real DB-level foreign key to the built-in auth users
|
|
69
|
+
* (`REFERENCES auth.users(id)`), so a column like `user_id` gets true
|
|
70
|
+
* database cascade/integrity instead of app-layer-only. Sugar for
|
|
71
|
+
* `.references("auth.users", "id")`.
|
|
72
|
+
*
|
|
73
|
+
* `auth.users` lives in the SAME tenant database (palauth-owned), so this is
|
|
74
|
+
* a genuine cross-schema integrity constraint scoped to THIS tenant's users.
|
|
75
|
+
* The referenced `auth.users.id` is `text` (palauth ids are `usr_<uuid>`), so
|
|
76
|
+
* the referencing column must be `text()` too. Combine with `.onDelete(...)`
|
|
77
|
+
* for cascade behaviour, e.g. a `user_id` column defined as
|
|
78
|
+
* `text().notNull().referencesAuthUser().onDelete("cascade")`.
|
|
79
|
+
*/
|
|
80
|
+
referencesAuthUser(): ColumnBuilder<K, N, D, E, P>;
|
|
64
81
|
/** Set the ON DELETE action for a foreign key reference. */
|
|
65
|
-
onDelete(action: OnDeleteAction): ColumnBuilder<K, N, D, E>;
|
|
82
|
+
onDelete(action: OnDeleteAction): ColumnBuilder<K, N, D, E, P>;
|
|
66
83
|
/** Add a single-column UNIQUE constraint. */
|
|
67
|
-
unique(): ColumnBuilder<K, N, D, E>;
|
|
84
|
+
unique(): ColumnBuilder<K, N, D, E, P>;
|
|
68
85
|
}
|
|
69
86
|
/**
|
|
70
87
|
* Extracts the TypeScript value type for a column, respecting nullability.
|
|
71
|
-
* - "uuid" | "text" | "timestamp" | "bigint" → string (or string | null when N = true)
|
|
72
|
-
* Note: bigint
|
|
73
|
-
* pgx/PostgREST serialize int8 as
|
|
88
|
+
* - "uuid" | "text" | "timestamp" | "bigint" | "numeric" → string (or string | null when N = true)
|
|
89
|
+
* Note: bigint/numeric surface as string — JS number loses precision past 2^53,
|
|
90
|
+
* and pgx/PostgREST serialize int8/numeric as strings. App code uses
|
|
91
|
+
* BigInt(row.amount) for bigint, or a decimal lib for numeric.
|
|
74
92
|
* - "integer" → number
|
|
75
93
|
* - "boolean" → boolean
|
|
76
|
-
* - "jsonb" →
|
|
94
|
+
* - "jsonb" → P (the dev-supplied payload shape from jsonb<T>(), else unknown)
|
|
77
95
|
* - "enum" → E (the union of literal values)
|
|
78
96
|
*/
|
|
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
|
|
97
|
+
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;
|
|
80
98
|
/**
|
|
81
99
|
* True when a column is optional on INSERT:
|
|
82
100
|
* - nullable columns (N = true) — the DB allows NULL so the field may be omitted
|
|
@@ -95,12 +113,31 @@ declare function integer(): ColumnBuilder<'integer', false, false, never>;
|
|
|
95
113
|
* and pgx/PostgREST serialize int8 as a JSON string. Use BigInt(row.column) in app code.
|
|
96
114
|
*/
|
|
97
115
|
declare function bigint(): ColumnBuilder<'bigint', false, false, never>;
|
|
116
|
+
/**
|
|
117
|
+
* Create a NUMERIC column (Postgres `numeric`/`decimal`, arbitrary precision).
|
|
118
|
+
* For exact fractional values (money with cents as a decimal, rates, weights)
|
|
119
|
+
* where int4/int8 don't fit. Surfaces as `string` in row/insert types — JS
|
|
120
|
+
* number can't hold arbitrary-precision decimals without rounding, and
|
|
121
|
+
* pgx/PostgREST serialize numeric as a JSON string. Parse with a decimal lib
|
|
122
|
+
* (or BigInt for scaled integers) in app code.
|
|
123
|
+
*/
|
|
124
|
+
declare function numeric(): ColumnBuilder<'numeric', false, false, never>;
|
|
98
125
|
/** Create a BOOLEAN column. */
|
|
99
126
|
declare function boolean(): ColumnBuilder<'boolean', false, false, never>;
|
|
100
127
|
/** Create a TIMESTAMP column. */
|
|
101
128
|
declare function timestamp(): ColumnBuilder<'timestamp', false, false, never>;
|
|
102
|
-
/**
|
|
103
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Create a JSONB column. Pass a payload type to make the generated row/insert
|
|
131
|
+
* type concrete instead of `unknown`:
|
|
132
|
+
*
|
|
133
|
+
* tags: jsonb<string[]>() // row.tags: string[]
|
|
134
|
+
* meta: jsonb<{ tier: string }>() // row.meta: { tier: string }
|
|
135
|
+
* raw: jsonb() // row.raw: unknown (back-compat)
|
|
136
|
+
*
|
|
137
|
+
* The runtime accepts a plain JS object/array directly (no JSON.stringify); the
|
|
138
|
+
* generic only refines the TYPE the env codegen emits.
|
|
139
|
+
*/
|
|
140
|
+
declare function jsonb<T = unknown>(): ColumnBuilder<'jsonb', false, false, never, T>;
|
|
104
141
|
/**
|
|
105
142
|
* Create an ENUM column.
|
|
106
143
|
* @param name The PostgreSQL enum type name (used in DDL).
|
|
@@ -545,4 +582,4 @@ interface EnvTypedDatabase extends Omit<DBClient, "transaction" | "asService"> {
|
|
|
545
582
|
asService(): EnvServiceDatabase;
|
|
546
583
|
}
|
|
547
584
|
|
|
548
|
-
export { makeTypedDB as A,
|
|
585
|
+
export { makeTypedDB as A, numeric as B, ColumnBuilder as C, policy as D, type EnvTypedDatabase as E, raw as F, text as G, timestamp as H, type InsertShape as I, uuid as J, 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
|
@@ -94,6 +94,7 @@ __export(src_exports, {
|
|
|
94
94
|
jsonb: () => jsonb,
|
|
95
95
|
makeEnvDts: () => makeEnvDts,
|
|
96
96
|
makeTypedDB: () => makeTypedDB,
|
|
97
|
+
numeric: () => numeric,
|
|
97
98
|
parseFileSizeLimit: () => parseFileSizeLimit,
|
|
98
99
|
policy: () => policy,
|
|
99
100
|
raw: () => raw,
|
|
@@ -387,6 +388,22 @@ var ColumnBuilder = class _ColumnBuilder {
|
|
|
387
388
|
this._def.references = { table, column };
|
|
388
389
|
return new _ColumnBuilder(this._def.type, this._def);
|
|
389
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Add a real DB-level foreign key to the built-in auth users
|
|
393
|
+
* (`REFERENCES auth.users(id)`), so a column like `user_id` gets true
|
|
394
|
+
* database cascade/integrity instead of app-layer-only. Sugar for
|
|
395
|
+
* `.references("auth.users", "id")`.
|
|
396
|
+
*
|
|
397
|
+
* `auth.users` lives in the SAME tenant database (palauth-owned), so this is
|
|
398
|
+
* a genuine cross-schema integrity constraint scoped to THIS tenant's users.
|
|
399
|
+
* The referenced `auth.users.id` is `text` (palauth ids are `usr_<uuid>`), so
|
|
400
|
+
* the referencing column must be `text()` too. Combine with `.onDelete(...)`
|
|
401
|
+
* for cascade behaviour, e.g. a `user_id` column defined as
|
|
402
|
+
* `text().notNull().referencesAuthUser().onDelete("cascade")`.
|
|
403
|
+
*/
|
|
404
|
+
referencesAuthUser() {
|
|
405
|
+
return this.references("auth.users", "id");
|
|
406
|
+
}
|
|
390
407
|
/** Set the ON DELETE action for a foreign key reference. */
|
|
391
408
|
onDelete(action) {
|
|
392
409
|
this._def.onDeleteAction = action;
|
|
@@ -410,6 +427,9 @@ function integer() {
|
|
|
410
427
|
function bigint() {
|
|
411
428
|
return new ColumnBuilder("bigint");
|
|
412
429
|
}
|
|
430
|
+
function numeric() {
|
|
431
|
+
return new ColumnBuilder("numeric");
|
|
432
|
+
}
|
|
413
433
|
function boolean() {
|
|
414
434
|
return new ColumnBuilder("boolean");
|
|
415
435
|
}
|
|
@@ -1558,6 +1578,7 @@ var import_zod2 = require("zod");
|
|
|
1558
1578
|
jsonb,
|
|
1559
1579
|
makeEnvDts,
|
|
1560
1580
|
makeTypedDB,
|
|
1581
|
+
numeric,
|
|
1561
1582
|
parseFileSizeLimit,
|
|
1562
1583
|
policy,
|
|
1563
1584
|
raw,
|