@palbase/backend 2.0.2 → 3.0.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.
Files changed (50) hide show
  1. package/dist/{chunk-4J3F32SH.js → chunk-B7EUJP5W.js} +38 -9
  2. package/dist/chunk-B7EUJP5W.js.map +1 -0
  3. package/dist/{chunk-L36JLUPO.js → chunk-PHAFZGHN.js} +43 -46
  4. package/dist/chunk-PHAFZGHN.js.map +1 -0
  5. package/dist/db/env.cjs +19 -0
  6. package/dist/db/env.cjs.map +1 -0
  7. package/dist/db/env.d.cts +45 -0
  8. package/dist/db/env.d.ts +45 -0
  9. package/dist/db/env.js +1 -0
  10. package/dist/db/env.js.map +1 -0
  11. package/dist/db/index.cjs +28 -231
  12. package/dist/db/index.cjs.map +1 -1
  13. package/dist/db/index.d.cts +4 -20
  14. package/dist/db/index.d.ts +4 -20
  15. package/dist/db/index.js +3 -233
  16. package/dist/db/index.js.map +1 -1
  17. package/dist/{endpoint-Djk5L6G2.d.ts → endpoint-DJ98tQd6.d.cts} +30 -68
  18. package/dist/{endpoint-BlcY2xNA.d.cts → endpoint-DJ98tQd6.d.ts} +30 -68
  19. package/dist/index-CXUs9iTQ.d.ts +294 -0
  20. package/dist/index-CZAwpQE1.d.cts +294 -0
  21. package/dist/index.cjs +229 -61
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +398 -154
  24. package/dist/index.d.ts +398 -154
  25. package/dist/index.js +147 -12
  26. package/dist/index.js.map +1 -1
  27. package/dist/test/index.cjs +41 -1
  28. package/dist/test/index.cjs.map +1 -1
  29. package/dist/test/index.d.cts +1 -2
  30. package/dist/test/index.d.ts +1 -2
  31. package/dist/test/index.js +1 -1
  32. package/docs/README.md +31 -10
  33. package/docs/background.md +19 -13
  34. package/docs/database.md +30 -17
  35. package/docs/endpoints.md +42 -24
  36. package/docs/errors.md +3 -4
  37. package/docs/events.md +25 -17
  38. package/docs/getting-started.md +25 -9
  39. package/docs/llms-full.txt +489 -164
  40. package/docs/llms.txt +3 -1
  41. package/docs/migrations.md +98 -0
  42. package/docs/resources.md +94 -0
  43. package/docs/routing.md +59 -26
  44. package/docs/schema.md +48 -38
  45. package/docs/services.md +5 -6
  46. package/package.json +11 -1
  47. package/dist/chunk-4J3F32SH.js.map +0 -1
  48. package/dist/chunk-L36JLUPO.js.map +0 -1
  49. package/dist/schema-BqfEhIC0.d.cts +0 -133
  50. package/dist/schema-BqfEhIC0.d.ts +0 -133
@@ -1,133 +0,0 @@
1
- /** On delete action for foreign key references. */
2
- type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
3
- /** Column type identifiers. */
4
- type ColumnType = 'uuid' | 'text' | 'integer' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
5
- /** Base column definition shared by all column types. */
6
- interface ColumnDef {
7
- type: ColumnType;
8
- nullable: boolean;
9
- primaryKey: boolean;
10
- defaultValue?: unknown;
11
- defaultRandom?: boolean;
12
- defaultNow?: boolean;
13
- references?: {
14
- table: string;
15
- column: string;
16
- };
17
- onDeleteAction?: OnDeleteAction;
18
- enumName?: string;
19
- enumValues?: string[];
20
- }
21
- declare const __colKind: unique symbol;
22
- declare const __colNullable: unique symbol;
23
- declare const __colHasDefault: unique symbol;
24
- declare const __colEnumValues: unique symbol;
25
- /**
26
- * Fluent column builder with phantom type params:
27
- * K — ColumnType literal (e.g. "text", "integer")
28
- * N — boolean: true when nullable() has been called last (false = NOT NULL)
29
- * D — boolean: true when a default has been set
30
- * E — enum value union (never for non-enum columns)
31
- *
32
- * All four params have defaults so bare `ColumnBuilder` (no args) still
33
- * satisfies `Record<string, ColumnBuilder>` in schema.ts without modification.
34
- *
35
- * The four `declare readonly` brand fields carry the phantom types into the
36
- * structural shape so that conditional types like ColValue<C> can discriminate
37
- * on K without requiring runtime values on those fields.
38
- */
39
- declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean = boolean, D extends boolean = boolean, E = unknown> {
40
- readonly [__colKind]: K;
41
- readonly [__colNullable]: N;
42
- readonly [__colHasDefault]: D;
43
- readonly [__colEnumValues]: E;
44
- readonly _def: ColumnDef;
45
- constructor(type: K, existingDef?: ColumnDef);
46
- /** Mark this column as the primary key. */
47
- primaryKey(): ColumnBuilder<K, N, D, E>;
48
- /** Mark this column as NOT NULL (default). */
49
- notNull(): ColumnBuilder<K, false, D, E>;
50
- /** Allow NULL values. */
51
- nullable(): ColumnBuilder<K, true, D, E>;
52
- /** Set a default value. */
53
- default(value: unknown): ColumnBuilder<K, N, true, E>;
54
- /** UUID: generate a random default (gen_random_uuid()). */
55
- defaultRandom(): ColumnBuilder<K, N, true, E>;
56
- /** Timestamp: default to now(). */
57
- defaultNow(): ColumnBuilder<K, N, true, E>;
58
- /** Add a foreign key reference. */
59
- references(table: string, column: string): ColumnBuilder<K, N, D, E>;
60
- /** Set the ON DELETE action for a foreign key reference. */
61
- onDelete(action: OnDeleteAction): ColumnBuilder<K, N, D, E>;
62
- }
63
- /**
64
- * Extracts the TypeScript value type for a column, respecting nullability.
65
- * - "uuid" | "text" | "timestamp" → string (or string | null when N = true)
66
- * - "integer" → number
67
- * - "boolean" → boolean
68
- * - "jsonb" → unknown (opaque JSON)
69
- * - "enum" → E (the union of literal values)
70
- */
71
- 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;
72
- /**
73
- * True when a column is optional on INSERT:
74
- * - nullable columns (N = true) — the DB allows NULL so the field may be omitted
75
- * - columns with a default (D = true) — the DB fills in the value when absent
76
- */
77
- type ColIsOptionalOnInsert<C> = C extends ColumnBuilder<infer _K, true, infer _D, infer _E> ? true : C extends ColumnBuilder<infer _K, infer _N, true, infer _E> ? true : false;
78
- /** Create a UUID column. */
79
- declare function uuid(): ColumnBuilder<'uuid', false, false, never>;
80
- /** Create a TEXT column. */
81
- declare function text(): ColumnBuilder<'text', false, false, never>;
82
- /** Create an INTEGER column. */
83
- declare function integer(): ColumnBuilder<'integer', false, false, never>;
84
- /** Create a BOOLEAN column. */
85
- declare function boolean(): ColumnBuilder<'boolean', false, false, never>;
86
- /** Create a TIMESTAMP column. */
87
- declare function timestamp(): ColumnBuilder<'timestamp', false, false, never>;
88
- /** Create a JSONB column. */
89
- declare function jsonb(): ColumnBuilder<'jsonb', false, false, never>;
90
- /**
91
- * Create an ENUM column.
92
- * @param name The PostgreSQL enum type name (used in DDL).
93
- * @param values A readonly tuple of valid string values — kept `const` so the
94
- * union `V[number]` is as narrow as possible.
95
- */
96
- declare function enumType<const V extends readonly string[]>(name: string, values: V): ColumnBuilder<'enum', false, false, V[number]>;
97
-
98
- /**
99
- * A table definition with its columns.
100
- *
101
- * The `C` type parameter preserves the precise per-column phantom types so
102
- * that downstream mapped types (InsertShape, RowShape) can discriminate on
103
- * them. The default `Record<string, ColumnBuilder>` keeps all existing call
104
- * sites that use `TableDef` without a type argument (generator.ts, etc.)
105
- * compiling unchanged.
106
- */
107
- interface TableDef<C extends Record<string, ColumnBuilder> = Record<string, ColumnBuilder>> {
108
- name: string;
109
- columns: C;
110
- }
111
- /**
112
- * A schema definition containing multiple tables.
113
- *
114
- * The `T` type parameter preserves the exact `TableDef<...>` type for each
115
- * table so that `SchemaDef["tables"]["rooms"]` resolves to the precise
116
- * `TableDef<{ id: ColumnBuilder<'uuid', false, true, never>; ... }>`.
117
- */
118
- interface SchemaDef<T extends Record<string, TableDef> = Record<string, TableDef>> {
119
- tables: T;
120
- }
121
- /**
122
- * Define a table with a name and columns.
123
- *
124
- * The generic parameter `C` preserves each column's phantom type params so
125
- * that `InsertShape<T>` and `RowShape<T>` can derive precise TypeScript types
126
- * from the column builders. The runtime return shape is identical to before —
127
- * only the static type is widened.
128
- */
129
- declare function table<C extends Record<string, ColumnBuilder>>(name: string, columns: C): TableDef<C>;
130
- /** Define a schema containing multiple tables. */
131
- declare function defineSchema<T extends Record<string, TableDef>>(tables: T): SchemaDef<T>;
132
-
133
- export { type ColIsOptionalOnInsert as C, type OnDeleteAction as O, type SchemaDef as S, type TableDef as T, type ColValue as a, ColumnBuilder as b, type ColumnDef as c, type ColumnType as d, boolean as e, defineSchema as f, enumType as g, text as h, integer as i, jsonb as j, timestamp as k, table as t, uuid as u };
@@ -1,133 +0,0 @@
1
- /** On delete action for foreign key references. */
2
- type OnDeleteAction = 'cascade' | 'set null' | 'restrict' | 'no action';
3
- /** Column type identifiers. */
4
- type ColumnType = 'uuid' | 'text' | 'integer' | 'boolean' | 'timestamp' | 'jsonb' | 'enum';
5
- /** Base column definition shared by all column types. */
6
- interface ColumnDef {
7
- type: ColumnType;
8
- nullable: boolean;
9
- primaryKey: boolean;
10
- defaultValue?: unknown;
11
- defaultRandom?: boolean;
12
- defaultNow?: boolean;
13
- references?: {
14
- table: string;
15
- column: string;
16
- };
17
- onDeleteAction?: OnDeleteAction;
18
- enumName?: string;
19
- enumValues?: string[];
20
- }
21
- declare const __colKind: unique symbol;
22
- declare const __colNullable: unique symbol;
23
- declare const __colHasDefault: unique symbol;
24
- declare const __colEnumValues: unique symbol;
25
- /**
26
- * Fluent column builder with phantom type params:
27
- * K — ColumnType literal (e.g. "text", "integer")
28
- * N — boolean: true when nullable() has been called last (false = NOT NULL)
29
- * D — boolean: true when a default has been set
30
- * E — enum value union (never for non-enum columns)
31
- *
32
- * All four params have defaults so bare `ColumnBuilder` (no args) still
33
- * satisfies `Record<string, ColumnBuilder>` in schema.ts without modification.
34
- *
35
- * The four `declare readonly` brand fields carry the phantom types into the
36
- * structural shape so that conditional types like ColValue<C> can discriminate
37
- * on K without requiring runtime values on those fields.
38
- */
39
- declare class ColumnBuilder<K extends ColumnType = ColumnType, N extends boolean = boolean, D extends boolean = boolean, E = unknown> {
40
- readonly [__colKind]: K;
41
- readonly [__colNullable]: N;
42
- readonly [__colHasDefault]: D;
43
- readonly [__colEnumValues]: E;
44
- readonly _def: ColumnDef;
45
- constructor(type: K, existingDef?: ColumnDef);
46
- /** Mark this column as the primary key. */
47
- primaryKey(): ColumnBuilder<K, N, D, E>;
48
- /** Mark this column as NOT NULL (default). */
49
- notNull(): ColumnBuilder<K, false, D, E>;
50
- /** Allow NULL values. */
51
- nullable(): ColumnBuilder<K, true, D, E>;
52
- /** Set a default value. */
53
- default(value: unknown): ColumnBuilder<K, N, true, E>;
54
- /** UUID: generate a random default (gen_random_uuid()). */
55
- defaultRandom(): ColumnBuilder<K, N, true, E>;
56
- /** Timestamp: default to now(). */
57
- defaultNow(): ColumnBuilder<K, N, true, E>;
58
- /** Add a foreign key reference. */
59
- references(table: string, column: string): ColumnBuilder<K, N, D, E>;
60
- /** Set the ON DELETE action for a foreign key reference. */
61
- onDelete(action: OnDeleteAction): ColumnBuilder<K, N, D, E>;
62
- }
63
- /**
64
- * Extracts the TypeScript value type for a column, respecting nullability.
65
- * - "uuid" | "text" | "timestamp" → string (or string | null when N = true)
66
- * - "integer" → number
67
- * - "boolean" → boolean
68
- * - "jsonb" → unknown (opaque JSON)
69
- * - "enum" → E (the union of literal values)
70
- */
71
- 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;
72
- /**
73
- * True when a column is optional on INSERT:
74
- * - nullable columns (N = true) — the DB allows NULL so the field may be omitted
75
- * - columns with a default (D = true) — the DB fills in the value when absent
76
- */
77
- type ColIsOptionalOnInsert<C> = C extends ColumnBuilder<infer _K, true, infer _D, infer _E> ? true : C extends ColumnBuilder<infer _K, infer _N, true, infer _E> ? true : false;
78
- /** Create a UUID column. */
79
- declare function uuid(): ColumnBuilder<'uuid', false, false, never>;
80
- /** Create a TEXT column. */
81
- declare function text(): ColumnBuilder<'text', false, false, never>;
82
- /** Create an INTEGER column. */
83
- declare function integer(): ColumnBuilder<'integer', false, false, never>;
84
- /** Create a BOOLEAN column. */
85
- declare function boolean(): ColumnBuilder<'boolean', false, false, never>;
86
- /** Create a TIMESTAMP column. */
87
- declare function timestamp(): ColumnBuilder<'timestamp', false, false, never>;
88
- /** Create a JSONB column. */
89
- declare function jsonb(): ColumnBuilder<'jsonb', false, false, never>;
90
- /**
91
- * Create an ENUM column.
92
- * @param name The PostgreSQL enum type name (used in DDL).
93
- * @param values A readonly tuple of valid string values — kept `const` so the
94
- * union `V[number]` is as narrow as possible.
95
- */
96
- declare function enumType<const V extends readonly string[]>(name: string, values: V): ColumnBuilder<'enum', false, false, V[number]>;
97
-
98
- /**
99
- * A table definition with its columns.
100
- *
101
- * The `C` type parameter preserves the precise per-column phantom types so
102
- * that downstream mapped types (InsertShape, RowShape) can discriminate on
103
- * them. The default `Record<string, ColumnBuilder>` keeps all existing call
104
- * sites that use `TableDef` without a type argument (generator.ts, etc.)
105
- * compiling unchanged.
106
- */
107
- interface TableDef<C extends Record<string, ColumnBuilder> = Record<string, ColumnBuilder>> {
108
- name: string;
109
- columns: C;
110
- }
111
- /**
112
- * A schema definition containing multiple tables.
113
- *
114
- * The `T` type parameter preserves the exact `TableDef<...>` type for each
115
- * table so that `SchemaDef["tables"]["rooms"]` resolves to the precise
116
- * `TableDef<{ id: ColumnBuilder<'uuid', false, true, never>; ... }>`.
117
- */
118
- interface SchemaDef<T extends Record<string, TableDef> = Record<string, TableDef>> {
119
- tables: T;
120
- }
121
- /**
122
- * Define a table with a name and columns.
123
- *
124
- * The generic parameter `C` preserves each column's phantom type params so
125
- * that `InsertShape<T>` and `RowShape<T>` can derive precise TypeScript types
126
- * from the column builders. The runtime return shape is identical to before —
127
- * only the static type is widened.
128
- */
129
- declare function table<C extends Record<string, ColumnBuilder>>(name: string, columns: C): TableDef<C>;
130
- /** Define a schema containing multiple tables. */
131
- declare function defineSchema<T extends Record<string, TableDef>>(tables: T): SchemaDef<T>;
132
-
133
- export { type ColIsOptionalOnInsert as C, type OnDeleteAction as O, type SchemaDef as S, type TableDef as T, type ColValue as a, ColumnBuilder as b, type ColumnDef as c, type ColumnType as d, boolean as e, defineSchema as f, enumType as g, text as h, integer as i, jsonb as j, timestamp as k, table as t, uuid as u };