@palbase/backend 8.3.0 → 8.5.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-FIB3SBVQ.js → chunk-2I5YHNFW.js} +9 -1
- package/dist/chunk-2I5YHNFW.js.map +1 -0
- package/dist/db/index.cjs +5 -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 +3 -1
- package/dist/{index-tudF0wAM.d.ts → index-Bth3XEUs.d.ts} +51 -20
- package/dist/{index-CC0LdYkQ.d.cts → index-Ls753IER.d.cts} +51 -20
- package/dist/index.cjs +12 -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 +7 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-FIB3SBVQ.js.map +0 -1
|
@@ -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' | 'numeric' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
|
|
8
8
|
/** Base column definition shared by all column types. */
|
|
9
9
|
interface ColumnDef {
|
|
10
10
|
type: ColumnType;
|
|
@@ -26,55 +26,61 @@ 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>;
|
|
64
67
|
/** Set the ON DELETE action for a foreign key reference. */
|
|
65
|
-
onDelete(action: OnDeleteAction): ColumnBuilder<K, N, D, E>;
|
|
68
|
+
onDelete(action: OnDeleteAction): ColumnBuilder<K, N, D, E, P>;
|
|
66
69
|
/** Add a single-column UNIQUE constraint. */
|
|
67
|
-
unique(): ColumnBuilder<K, N, D, E>;
|
|
70
|
+
unique(): ColumnBuilder<K, N, D, E, P>;
|
|
68
71
|
}
|
|
69
72
|
/**
|
|
70
73
|
* Extracts the TypeScript value type for a column, respecting nullability.
|
|
71
|
-
* - "uuid" | "text" | "timestamp" → string (or string | null when N = true)
|
|
74
|
+
* - "uuid" | "text" | "timestamp" | "bigint" | "numeric" → string (or string | null when N = true)
|
|
75
|
+
* Note: bigint/numeric surface as string — JS number loses precision past 2^53,
|
|
76
|
+
* and pgx/PostgREST serialize int8/numeric as strings. App code uses
|
|
77
|
+
* BigInt(row.amount) for bigint, or a decimal lib for numeric.
|
|
72
78
|
* - "integer" → number
|
|
73
79
|
* - "boolean" → boolean
|
|
74
|
-
* - "jsonb" →
|
|
80
|
+
* - "jsonb" → P (the dev-supplied payload shape from jsonb<T>(), else unknown)
|
|
75
81
|
* - "enum" → E (the union of literal values)
|
|
76
82
|
*/
|
|
77
|
-
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
|
|
83
|
+
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;
|
|
78
84
|
/**
|
|
79
85
|
* True when a column is optional on INSERT:
|
|
80
86
|
* - nullable columns (N = true) — the DB allows NULL so the field may be omitted
|
|
@@ -85,14 +91,39 @@ type ColIsOptionalOnInsert<C> = C extends ColumnBuilder<infer _K, true, infer _D
|
|
|
85
91
|
declare function uuid(): ColumnBuilder<'uuid', false, false, never>;
|
|
86
92
|
/** Create a TEXT column. */
|
|
87
93
|
declare function text(): ColumnBuilder<'text', false, false, never>;
|
|
88
|
-
/** Create an INTEGER column. */
|
|
94
|
+
/** Create an INTEGER column. Emits int4 (max ~2.1B). */
|
|
89
95
|
declare function integer(): ColumnBuilder<'integer', false, false, never>;
|
|
96
|
+
/**
|
|
97
|
+
* Create a BIGINT column (Postgres int8, max ~9.2×10^18).
|
|
98
|
+
* Surfaces as `string` in row/insert types — JS number loses precision past 2^53
|
|
99
|
+
* and pgx/PostgREST serialize int8 as a JSON string. Use BigInt(row.column) in app code.
|
|
100
|
+
*/
|
|
101
|
+
declare function bigint(): ColumnBuilder<'bigint', false, false, never>;
|
|
102
|
+
/**
|
|
103
|
+
* Create a NUMERIC column (Postgres `numeric`/`decimal`, arbitrary precision).
|
|
104
|
+
* For exact fractional values (money with cents as a decimal, rates, weights)
|
|
105
|
+
* where int4/int8 don't fit. Surfaces as `string` in row/insert types — JS
|
|
106
|
+
* number can't hold arbitrary-precision decimals without rounding, and
|
|
107
|
+
* pgx/PostgREST serialize numeric as a JSON string. Parse with a decimal lib
|
|
108
|
+
* (or BigInt for scaled integers) in app code.
|
|
109
|
+
*/
|
|
110
|
+
declare function numeric(): ColumnBuilder<'numeric', false, false, never>;
|
|
90
111
|
/** Create a BOOLEAN column. */
|
|
91
112
|
declare function boolean(): ColumnBuilder<'boolean', false, false, never>;
|
|
92
113
|
/** Create a TIMESTAMP column. */
|
|
93
114
|
declare function timestamp(): ColumnBuilder<'timestamp', false, false, never>;
|
|
94
|
-
/**
|
|
95
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Create a JSONB column. Pass a payload type to make the generated row/insert
|
|
117
|
+
* type concrete instead of `unknown`:
|
|
118
|
+
*
|
|
119
|
+
* tags: jsonb<string[]>() // row.tags: string[]
|
|
120
|
+
* meta: jsonb<{ tier: string }>() // row.meta: { tier: string }
|
|
121
|
+
* raw: jsonb() // row.raw: unknown (back-compat)
|
|
122
|
+
*
|
|
123
|
+
* The runtime accepts a plain JS object/array directly (no JSON.stringify); the
|
|
124
|
+
* generic only refines the TYPE the env codegen emits.
|
|
125
|
+
*/
|
|
126
|
+
declare function jsonb<T = unknown>(): ColumnBuilder<'jsonb', false, false, never, T>;
|
|
96
127
|
/**
|
|
97
128
|
* Create an ENUM column.
|
|
98
129
|
* @param name The PostgreSQL enum type name (used in DDL).
|
|
@@ -537,4 +568,4 @@ interface EnvTypedDatabase extends Omit<DBClient, "transaction" | "asService"> {
|
|
|
537
568
|
asService(): EnvServiceDatabase;
|
|
538
569
|
}
|
|
539
570
|
|
|
540
|
-
export {
|
|
571
|
+
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
|
@@ -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,
|
|
@@ -93,6 +94,7 @@ __export(src_exports, {
|
|
|
93
94
|
jsonb: () => jsonb,
|
|
94
95
|
makeEnvDts: () => makeEnvDts,
|
|
95
96
|
makeTypedDB: () => makeTypedDB,
|
|
97
|
+
numeric: () => numeric,
|
|
96
98
|
parseFileSizeLimit: () => parseFileSizeLimit,
|
|
97
99
|
policy: () => policy,
|
|
98
100
|
raw: () => raw,
|
|
@@ -406,6 +408,12 @@ function text() {
|
|
|
406
408
|
function integer() {
|
|
407
409
|
return new ColumnBuilder("integer");
|
|
408
410
|
}
|
|
411
|
+
function bigint() {
|
|
412
|
+
return new ColumnBuilder("bigint");
|
|
413
|
+
}
|
|
414
|
+
function numeric() {
|
|
415
|
+
return new ColumnBuilder("numeric");
|
|
416
|
+
}
|
|
409
417
|
function boolean() {
|
|
410
418
|
return new ColumnBuilder("boolean");
|
|
411
419
|
}
|
|
@@ -464,6 +472,8 @@ function baseTsType(def) {
|
|
|
464
472
|
return "string";
|
|
465
473
|
case "integer":
|
|
466
474
|
return "number";
|
|
475
|
+
case "bigint":
|
|
476
|
+
return "string";
|
|
467
477
|
case "boolean":
|
|
468
478
|
return "boolean";
|
|
469
479
|
case "jsonb":
|
|
@@ -1530,6 +1540,7 @@ var import_zod2 = require("zod");
|
|
|
1530
1540
|
__setRuntime,
|
|
1531
1541
|
__shutdownResources,
|
|
1532
1542
|
auth,
|
|
1543
|
+
bigint,
|
|
1533
1544
|
boolean,
|
|
1534
1545
|
bucket,
|
|
1535
1546
|
buildProvider,
|
|
@@ -1551,6 +1562,7 @@ var import_zod2 = require("zod");
|
|
|
1551
1562
|
jsonb,
|
|
1552
1563
|
makeEnvDts,
|
|
1553
1564
|
makeTypedDB,
|
|
1565
|
+
numeric,
|
|
1554
1566
|
parseFileSizeLimit,
|
|
1555
1567
|
policy,
|
|
1556
1568
|
raw,
|