@palbase/backend 8.4.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.
@@ -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' | '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,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 four params have defaults so bare `ColumnBuilder` (no args) still
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 four `declare readonly` brand fields carry the phantom types into 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" | "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).
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.
74
78
  * - "integer" → number
75
79
  * - "boolean" → boolean
76
- * - "jsonb" → unknown (opaque JSON)
80
+ * - "jsonb" → P (the dev-supplied payload shape from jsonb<T>(), else unknown)
77
81
  * - "enum" → E (the union of literal values)
78
82
  */
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;
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;
80
84
  /**
81
85
  * True when a column is optional on INSERT:
82
86
  * - nullable columns (N = true) — the DB allows NULL so the field may be omitted
@@ -95,12 +99,31 @@ declare function integer(): ColumnBuilder<'integer', false, false, never>;
95
99
  * and pgx/PostgREST serialize int8 as a JSON string. Use BigInt(row.column) in app code.
96
100
  */
97
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>;
98
111
  /** Create a BOOLEAN column. */
99
112
  declare function boolean(): ColumnBuilder<'boolean', false, false, never>;
100
113
  /** Create a TIMESTAMP column. */
101
114
  declare function timestamp(): ColumnBuilder<'timestamp', false, false, never>;
102
- /** Create a JSONB column. */
103
- declare function jsonb(): ColumnBuilder<'jsonb', false, false, never>;
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>;
104
127
  /**
105
128
  * Create an ENUM column.
106
129
  * @param name The PostgreSQL enum type name (used in DDL).
@@ -545,4 +568,4 @@ interface EnvTypedDatabase extends Omit<DBClient, "transaction" | "asService"> {
545
568
  asService(): EnvServiceDatabase;
546
569
  }
547
570
 
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 };
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
@@ -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,
@@ -410,6 +411,9 @@ function integer() {
410
411
  function bigint() {
411
412
  return new ColumnBuilder("bigint");
412
413
  }
414
+ function numeric() {
415
+ return new ColumnBuilder("numeric");
416
+ }
413
417
  function boolean() {
414
418
  return new ColumnBuilder("boolean");
415
419
  }
@@ -1558,6 +1562,7 @@ var import_zod2 = require("zod");
1558
1562
  jsonb,
1559
1563
  makeEnvDts,
1560
1564
  makeTypedDB,
1565
+ numeric,
1561
1566
  parseFileSizeLimit,
1562
1567
  policy,
1563
1568
  raw,