okmodel 0.0.0 → 0.1.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 (147) hide show
  1. package/README.md +44 -1
  2. package/dist/adapters/capabilities.d.ts +62 -0
  3. package/dist/adapters/error.d.ts +91 -0
  4. package/dist/adapters/failure.d.ts +39 -0
  5. package/dist/adapters/pg/batch.d.ts +36 -0
  6. package/dist/adapters/pg/call.d.ts +59 -0
  7. package/dist/adapters/pg/pglite.d.ts +21 -0
  8. package/dist/adapters/pg/postgres-extra.d.ts +43 -0
  9. package/dist/adapters/pg/postgresjs.d.ts +95 -0
  10. package/dist/adapters/pg/result.d.ts +30 -0
  11. package/dist/contracts/catalog/build.d.ts +18 -0
  12. package/dist/contracts/catalog/document.d.ts +79 -0
  13. package/dist/contracts/catalog/enum.d.ts +35 -0
  14. package/dist/contracts/catalog/identifier.d.ts +71 -0
  15. package/dist/contracts/catalog/identity.d.ts +98 -0
  16. package/dist/contracts/catalog/index.d.ts +11 -0
  17. package/dist/contracts/catalog/json.d.ts +17 -0
  18. package/dist/contracts/catalog/object.d.ts +142 -0
  19. package/dist/contracts/catalog/order.d.ts +43 -0
  20. package/dist/contracts/catalog/rewrite.d.ts +18 -0
  21. package/dist/contracts/catalog/types.d.ts +292 -0
  22. package/dist/contracts/catalog/words.d.ts +13 -0
  23. package/dist/contracts/connection.d.ts +33 -0
  24. package/dist/contracts/driver.d.ts +163 -0
  25. package/dist/contracts/error.d.ts +298 -0
  26. package/dist/contracts/index.d.ts +11 -0
  27. package/dist/contracts/index.js +16 -0
  28. package/dist/contracts/internal.d.ts +15 -0
  29. package/dist/contracts/internal.js +68 -0
  30. package/dist/contracts/nearest.d.ts +15 -0
  31. package/dist/contracts/rows.d.ts +84 -0
  32. package/dist/contracts/sha256.d.ts +14 -0
  33. package/dist/contracts/utf8.d.ts +33 -0
  34. package/dist/dialects/pg/array-literal.d.ts +25 -0
  35. package/dist/dialects/pg/bool.d.ts +46 -0
  36. package/dist/dialects/pg/column.d.ts +386 -0
  37. package/dist/dialects/pg/compile.d.ts +81 -0
  38. package/dist/dialects/pg/custom.d.ts +21 -0
  39. package/dist/dialects/pg/ddl.d.ts +70 -0
  40. package/dist/dialects/pg/decimal.d.ts +62 -0
  41. package/dist/dialects/pg/declarations.d.ts +34 -0
  42. package/dist/dialects/pg/emit.d.ts +18 -0
  43. package/dist/dialects/pg/enum.d.ts +30 -0
  44. package/dist/dialects/pg/errors.d.ts +30 -0
  45. package/dist/dialects/pg/finite.d.ts +15 -0
  46. package/dist/dialects/pg/geometry.d.ts +55 -0
  47. package/dist/dialects/pg/index.d.ts +45 -0
  48. package/dist/dialects/pg/index.js +1821 -0
  49. package/dist/dialects/pg/integer.d.ts +96 -0
  50. package/dist/dialects/pg/introspect.d.ts +43 -0
  51. package/dist/dialects/pg/json.d.ts +43 -0
  52. package/dist/dialects/pg/keys.d.ts +32 -0
  53. package/dist/dialects/pg/misuse.d.ts +31 -0
  54. package/dist/dialects/pg/model.d.ts +71 -0
  55. package/dist/dialects/pg/namespace.d.ts +63 -0
  56. package/dist/dialects/pg/network.d.ts +28 -0
  57. package/dist/dialects/pg/operators.d.ts +71 -0
  58. package/dist/dialects/pg/ops/between.d.ts +10 -0
  59. package/dist/dialects/pg/ops/contains.d.ts +8 -0
  60. package/dist/dialects/pg/ops/endsWith.d.ts +8 -0
  61. package/dist/dialects/pg/ops/eq.d.ts +9 -0
  62. package/dist/dialects/pg/ops/every.d.ts +9 -0
  63. package/dist/dialects/pg/ops/gt.d.ts +9 -0
  64. package/dist/dialects/pg/ops/gte.d.ts +9 -0
  65. package/dist/dialects/pg/ops/has.d.ts +9 -0
  66. package/dist/dialects/pg/ops/ilike.d.ts +8 -0
  67. package/dist/dialects/pg/ops/inList.d.ts +9 -0
  68. package/dist/dialects/pg/ops/inc.d.ts +13 -0
  69. package/dist/dialects/pg/ops/like.d.ts +8 -0
  70. package/dist/dialects/pg/ops/lt.d.ts +9 -0
  71. package/dist/dialects/pg/ops/lte.d.ts +9 -0
  72. package/dist/dialects/pg/ops/none.d.ts +9 -0
  73. package/dist/dialects/pg/ops/not.d.ts +9 -0
  74. package/dist/dialects/pg/ops/notIn.d.ts +9 -0
  75. package/dist/dialects/pg/ops/or.d.ts +9 -0
  76. package/dist/dialects/pg/ops/startsWith.d.ts +8 -0
  77. package/dist/dialects/pg/quote.d.ts +24 -0
  78. package/dist/dialects/pg/range.d.ts +50 -0
  79. package/dist/dialects/pg/relations.d.ts +45 -0
  80. package/dist/dialects/pg/schema.d.ts +77 -0
  81. package/dist/dialects/pg/search.d.ts +23 -0
  82. package/dist/dialects/pg/table.d.ts +201 -0
  83. package/dist/dialects/pg/temporal.d.ts +211 -0
  84. package/dist/dialects/pg/text.d.ts +44 -0
  85. package/dist/dialects/pg/time.d.ts +46 -0
  86. package/dist/okm.js +2 -0
  87. package/dist/okmodel.js +2 -0
  88. package/dist/runtime/client.d.ts +47 -0
  89. package/dist/runtime/conflict.d.ts +38 -0
  90. package/dist/runtime/drift-detail.d.ts +32 -0
  91. package/dist/runtime/drift.d.ts +29 -0
  92. package/dist/runtime/include.d.ts +15 -0
  93. package/dist/runtime/pg/pglite.d.ts +25 -0
  94. package/dist/runtime/pg/pglite.js +48 -0
  95. package/dist/runtime/pg/postgresjs.d.ts +29 -0
  96. package/dist/runtime/pg/postgresjs.js +62 -0
  97. package/dist/runtime/plan.d.ts +167 -0
  98. package/dist/runtime/tx.d.ts +29 -0
  99. package/dist/runtime/types.d.ts +369 -0
  100. package/dist/runtime/write.d.ts +48 -0
  101. package/dist/shared/4j72449d.js +37 -0
  102. package/dist/shared/79ggp945.js +148 -0
  103. package/dist/shared/7ck0dtry.js +259 -0
  104. package/dist/shared/8b04d28c.js +14 -0
  105. package/dist/shared/ax16zpvm.js +171 -0
  106. package/dist/shared/ckb1p0a4.js +566 -0
  107. package/dist/shared/cn0n68ft.js +16 -0
  108. package/dist/shared/dynq16vb.js +81 -0
  109. package/dist/shared/f5thc1s0.js +1050 -0
  110. package/dist/shared/fgqgsb5z.js +281 -0
  111. package/dist/shared/g2v6gnc8.js +347 -0
  112. package/dist/shared/g5fhqmwe.js +188 -0
  113. package/dist/shared/gk7cs7sp.js +566 -0
  114. package/dist/shared/hd293j9g.js +98 -0
  115. package/dist/shared/j5cn2963.js +701 -0
  116. package/dist/shared/kynx7vbm.js +1490 -0
  117. package/dist/shared/mkjmqjv4.js +456 -0
  118. package/dist/shared/mtkwv8wx.js +18 -0
  119. package/dist/shared/ngk8gj61.js +40 -0
  120. package/dist/shared/p0cbr3g2.js +79 -0
  121. package/dist/shared/px90pf9p.js +396 -0
  122. package/dist/shared/qk3hxfja.js +83 -0
  123. package/dist/shared/tb4ze1tr.js +119 -0
  124. package/dist/shared/vkm3q4x1.js +30 -0
  125. package/dist/shared/w8samvk1.js +18 -0
  126. package/dist/shared/xy79j5hq.js +177 -0
  127. package/dist/shared/y9m15dfv.js +888 -0
  128. package/dist/shared/ycwz42az.js +412 -0
  129. package/dist/shared/zhc5vmgf.js +257 -0
  130. package/dist/tooling/cli.d.ts +1 -0
  131. package/dist/tooling/cli.js +193 -0
  132. package/dist/tooling/errors/registry.d.ts +33 -0
  133. package/dist/tooling/migrate/apply.d.ts +86 -0
  134. package/dist/tooling/migrate/commands.d.ts +21 -0
  135. package/dist/tooling/migrate/config.d.ts +48 -0
  136. package/dist/tooling/migrate/dev.d.ts +16 -0
  137. package/dist/tooling/migrate/equal.d.ts +15 -0
  138. package/dist/tooling/migrate/files.d.ts +19 -0
  139. package/dist/tooling/migrate/index.d.ts +7 -0
  140. package/dist/tooling/migrate/index.js +7 -0
  141. package/dist/tooling/migrate/plan.d.ts +76 -0
  142. package/dist/tooling/migrate/policy.d.ts +78 -0
  143. package/dist/tooling/migrate/project.d.ts +69 -0
  144. package/dist/tooling/migrate/status.d.ts +74 -0
  145. package/dist/tooling/migrate/values.d.ts +29 -0
  146. package/package.json +94 -7
  147. package/dist/index.js +0 -0
@@ -0,0 +1,9 @@
1
+ import { type Or } from "../operators.js";
2
+ /**
3
+ * Disjunction of where objects.
4
+ *
5
+ * @typeParam V - One branch
6
+ * @param branches - Where objects, or-ed
7
+ * @returns A tagged operator
8
+ */
9
+ export declare function or<const V>(branches: readonly V[]): Or<V>;
@@ -0,0 +1,8 @@
1
+ import { type Pattern } from "../operators.js";
2
+ /**
3
+ * Case-sensitive prefix. `%`, `_`, and `\` in `value` are escaped.
4
+ *
5
+ * @param value - Literal prefix
6
+ * @returns A tagged operator
7
+ */
8
+ export declare function startsWith(value: string): Pattern<"startsWith">;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * SQL literal quoting for catalog default expressions.
3
+ *
4
+ * Only single quotes are escaped. Postgres `standard_conforming_strings` is
5
+ * on, so a backslash stays a backslash.
6
+ */
7
+ /**
8
+ * Wraps text in a SQL string literal.
9
+ *
10
+ * @param value - Raw text
11
+ * @returns A single-quoted literal
12
+ */
13
+ export declare function quoteLiteral(value: string): string;
14
+ /**
15
+ * Quotes one element of a Postgres array literal.
16
+ *
17
+ * Bare tokens are integers, decimals, and booleans. Everything else is a
18
+ * double-quoted element.
19
+ *
20
+ * @param encoded - Element text from the scalar codec
21
+ * @param raw - When true, a numeric or boolean token may stay bare
22
+ * @returns One array-literal element
23
+ */
24
+ export declare function arrayElement(encoded: string, raw: boolean): string;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Postgres range columns.
3
+ *
4
+ * A range is either empty or a pair of bounds. Unbounded sides use null.
5
+ */
6
+ import { type ColumnBuilder, type PlainFlags } from "./column.js";
7
+ /**
8
+ * A range value.
9
+ *
10
+ * @typeParam T - Bound type
11
+ */
12
+ export type Range<T> = {
13
+ readonly empty: true;
14
+ } | {
15
+ readonly empty: false;
16
+ readonly lower: T | null;
17
+ readonly upper: T | null;
18
+ readonly lowerInclusive: boolean;
19
+ readonly upperInclusive: boolean;
20
+ };
21
+ /**
22
+ * Timestamp with time zone range.
23
+ *
24
+ * @returns A tstzrange column
25
+ */
26
+ export declare function tstzrange(): ColumnBuilder<Range<Temporal.Instant>, PlainFlags>;
27
+ /**
28
+ * Date range.
29
+ *
30
+ * @returns A daterange column
31
+ */
32
+ export declare function daterange(): ColumnBuilder<Range<Temporal.PlainDate>, PlainFlags>;
33
+ /**
34
+ * 32-bit integer range.
35
+ *
36
+ * @returns An int4range column
37
+ */
38
+ export declare function int4range(): ColumnBuilder<Range<number>, PlainFlags>;
39
+ /**
40
+ * 64-bit integer range. Bounds are decimal strings.
41
+ *
42
+ * @returns An int8range column
43
+ */
44
+ export declare function int8range(): ColumnBuilder<Range<string>, PlainFlags>;
45
+ /**
46
+ * Numeric range. Bounds are decimal strings.
47
+ *
48
+ * @returns A numrange column
49
+ */
50
+ export declare function numrange(): ColumnBuilder<Range<string>, PlainFlags>;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `one` and `many` relations.
3
+ *
4
+ * They name a table. `schema()` resolves the foreign key. An ambiguous key
5
+ * is OKM1021. `manyThrough` arrives in 0.2. `morph` stays reserved.
6
+ */
7
+ /** A to-one relation. `field` is the local foreign key when the table has several. */
8
+ export type OneRelation<TTable extends string = string> = {
9
+ readonly kind: "one";
10
+ readonly table: TTable;
11
+ readonly field: string | undefined;
12
+ };
13
+ /** A to-many relation. `field` is the foreign key on the other table. */
14
+ export type ManyRelation<TTable extends string = string> = {
15
+ readonly kind: "many";
16
+ readonly table: TTable;
17
+ readonly field: string | undefined;
18
+ };
19
+ /** A relation `table()` stores. */
20
+ export type RelationCall = OneRelation | ManyRelation;
21
+ /**
22
+ * Declares a to-one relation by table name.
23
+ *
24
+ * @typeParam TTable - Related table
25
+ * @param table - Related table name
26
+ * @param field - Local foreign-key field, when more than one key points there
27
+ * @returns The relation `schema()` resolves
28
+ */
29
+ export declare function one<const TTable extends string>(table: TTable, field?: string): OneRelation<TTable>;
30
+ /**
31
+ * Declares a to-many relation by table name.
32
+ *
33
+ * @typeParam TTable - Related table
34
+ * @param table - Related table name
35
+ * @param field - Foreign-key field on that table, when more than one key points here
36
+ * @returns The relation `schema()` resolves
37
+ */
38
+ export declare function many<const TTable extends string>(table: TTable, field?: string): ManyRelation<TTable>;
39
+ /**
40
+ * Reports whether `value` is a relation helper result.
41
+ *
42
+ * @param value - One entry of `relations`
43
+ * @returns `true` for `one` and `many`
44
+ */
45
+ export declare function isRelationCall(value: unknown): value is RelationCall;
@@ -0,0 +1,77 @@
1
+ /**
2
+ * `schema()` compiles tables into one catalog.
3
+ *
4
+ * Work happens here, not in `table()` and not at import.
5
+ */
6
+ import type { Catalog } from "../../contracts/catalog/types.js";
7
+ import { type TableModel } from "./model.js";
8
+ import { type AnyTable } from "./table.js";
9
+ /** Codec defaults from spec section 6.6. */
10
+ export type SchemaCodecs = {
11
+ readonly bigint: "string" | "number" | "bigint";
12
+ readonly numeric: "string" | "number";
13
+ readonly timestamps: "temporal";
14
+ };
15
+ /** Engine requirement recorded for connect. */
16
+ export type SchemaRequires = {
17
+ readonly postgres?: string;
18
+ };
19
+ /**
20
+ * Input for {@link schema}.
21
+ *
22
+ * Later keys are part of the type and rejected when present.
23
+ *
24
+ * @typeParam TTables - Tables in declaration order
25
+ */
26
+ export type SchemaInput<TTables extends readonly AnyTable[]> = {
27
+ readonly tables: TTables;
28
+ readonly requires?: SchemaRequires;
29
+ readonly casing?: "snake";
30
+ readonly codecs?: {
31
+ readonly bigint?: SchemaCodecs["bigint"];
32
+ readonly numeric?: SchemaCodecs["numeric"];
33
+ readonly timestamps?: SchemaCodecs["timestamps"];
34
+ };
35
+ readonly types?: "emitted" | "inferred";
36
+ readonly traits?: unknown;
37
+ readonly tenancy?: unknown;
38
+ readonly validation?: unknown;
39
+ readonly extensions?: unknown;
40
+ readonly functions?: unknown;
41
+ readonly triggers?: unknown;
42
+ readonly views?: unknown;
43
+ };
44
+ /**
45
+ * A compiled schema.
46
+ *
47
+ * `~byName` is what `Row`, `Insert`, and `Update` index. `catalog` is the
48
+ * document `catalogHash` and `serializeCatalog` accept.
49
+ *
50
+ * @typeParam TTables - Tables in declaration order
51
+ */
52
+ export type BuiltSchema<TTables extends readonly AnyTable[]> = {
53
+ readonly "~byName": {
54
+ readonly [T in TTables[number] as T["~name"]]: T;
55
+ };
56
+ readonly catalog: Catalog;
57
+ readonly types: "emitted" | "inferred";
58
+ readonly casing: "snake" | undefined;
59
+ readonly codecs: SchemaCodecs;
60
+ readonly requires: SchemaRequires | undefined;
61
+ readonly tables: TTables;
62
+ /** Query model. Built once, beside the catalog document. */
63
+ readonly model: {
64
+ readonly [T in TTables[number] as T["~name"]]: TableModel;
65
+ };
66
+ };
67
+ /**
68
+ * Compiles tables into a catalog.
69
+ *
70
+ * Names, dependencies, and provenance are fixed here. Calling it twice on
71
+ * the same tables returns equal catalog bytes.
72
+ *
73
+ * @typeParam TTables - Tables in declaration order
74
+ * @param config - Tables, casing, codecs, and the row-type mode
75
+ * @returns The schema and its catalog
76
+ */
77
+ export declare function schema<const TTables extends readonly AnyTable[]>(config: SchemaInput<TTables>): BuiltSchema<TTables>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Full-text search and ltree.
3
+ */
4
+ import { type ColumnBuilder, type PlainFlags } from "./column.js";
5
+ /**
6
+ * Full-text vector. The value is the vector text.
7
+ *
8
+ * @returns A tsvector column
9
+ */
10
+ export declare function tsvector(): ColumnBuilder<string, PlainFlags>;
11
+ /**
12
+ * Label tree. The column depends on the `ltree` extension.
13
+ *
14
+ * @returns An ltree column
15
+ */
16
+ export declare function ltree(): ColumnBuilder<string, PlainFlags>;
17
+ /**
18
+ * Encodes an ltree path.
19
+ *
20
+ * @param value - Labels separated by dots
21
+ * @returns The same path when every label is valid
22
+ */
23
+ export declare function encodeLtree(value: string): string;
@@ -0,0 +1,201 @@
1
+ /**
2
+ * `table()`, index calls, and check text.
3
+ *
4
+ * `table()` stores the columns. It does not build catalog objects.
5
+ * `schema()` does that.
6
+ */
7
+ import { type ColumnInsertOf, type ColumnRowOf, type ColumnUpdateOf } from "./column.js";
8
+ import { type RelationCall } from "./relations.js";
9
+ /**
10
+ * A column as seen by `indexes` and `checks`.
11
+ *
12
+ * `name` is the SQL name `schema()` will store.
13
+ */
14
+ export type ColumnHandle = {
15
+ readonly name: string;
16
+ };
17
+ /**
18
+ * An index declared on a table.
19
+ */
20
+ export type IndexCall = {
21
+ readonly columns: readonly string[];
22
+ readonly isUnique: boolean;
23
+ /**
24
+ * Marks the index unique.
25
+ *
26
+ * @returns The same columns, unique
27
+ */
28
+ unique(): IndexCall;
29
+ };
30
+ /**
31
+ * Text stored for a check constraint.
32
+ *
33
+ * The database normalises it later. Here it is the author's text.
34
+ */
35
+ export type SqlText = {
36
+ readonly text: string;
37
+ };
38
+ /** Values an {@link sql} template may interpolate. */
39
+ export type SqlValue = string | number | boolean | null | ColumnHandle | SqlText;
40
+ /**
41
+ * Options `table()` stores.
42
+ *
43
+ * Keys that belong to a later prompt are accepted and rejected at runtime.
44
+ *
45
+ * @typeParam TColumns - Columns of this table
46
+ */
47
+ export type TableOptions<TColumns> = {
48
+ readonly indexes?: (columns: Handles<TColumns>) => readonly IndexCall[];
49
+ readonly checks?: {
50
+ readonly [name: string]: (columns: Handles<TColumns>) => SqlText;
51
+ };
52
+ readonly unique?: {
53
+ readonly [name: string]: readonly (keyof TColumns & string)[];
54
+ };
55
+ readonly sqlName?: string;
56
+ readonly renamedFrom?: string;
57
+ readonly comment?: string;
58
+ readonly validate?: unknown;
59
+ readonly validation?: unknown;
60
+ readonly traits?: unknown;
61
+ readonly omitDefaults?: unknown;
62
+ readonly tenancy?: unknown;
63
+ readonly computed?: unknown;
64
+ readonly presets?: unknown;
65
+ readonly policies?: unknown;
66
+ readonly reference?: unknown;
67
+ /** `one` and `many`. Other relation kinds stay reserved. */
68
+ readonly relations?: unknown;
69
+ };
70
+ /**
71
+ * Column handles keyed by field name.
72
+ *
73
+ * @typeParam TColumns - Columns of this table
74
+ */
75
+ export type Handles<TColumns> = {
76
+ readonly [K in keyof TColumns]: ColumnHandle;
77
+ };
78
+ /**
79
+ * A table value.
80
+ *
81
+ * `~row`, `~insert`, and `~update` are the shapes `Row`, `Insert`, and
82
+ * `Update` read. They are computed here, once, from the column flags.
83
+ *
84
+ * @typeParam TName - Table name
85
+ * @typeParam TColumns - Column builders
86
+ * @typeParam TRelations - Relations declared on this table
87
+ */
88
+ export type Table<TName extends string, TColumns, TRelations extends Readonly<Record<string, RelationCall>> = Readonly<Record<string, never>>> = {
89
+ readonly "~name": TName;
90
+ readonly "~columns": TColumns;
91
+ readonly "~row": RowFrom<TColumns>;
92
+ readonly "~insert": InsertFrom<TColumns>;
93
+ readonly "~update": UpdateFrom<TColumns>;
94
+ readonly "~relations": TRelations;
95
+ readonly name: TName;
96
+ readonly columns: TColumns;
97
+ readonly options?: TableOptions<TColumns>;
98
+ };
99
+ /**
100
+ * Any table `schema()` can compile.
101
+ */
102
+ export type AnyTable = {
103
+ readonly "~name": string;
104
+ readonly "~row": unknown;
105
+ readonly "~insert": unknown;
106
+ readonly "~update": unknown;
107
+ readonly "~relations"?: Readonly<Record<string, RelationCall>>;
108
+ readonly name: string;
109
+ readonly columns: Readonly<Record<string, object>>;
110
+ readonly options?: object;
111
+ };
112
+ /**
113
+ * Row shape. Hidden columns are omitted.
114
+ *
115
+ * @typeParam TColumns - Column builders
116
+ */
117
+ export type RowFrom<TColumns> = {
118
+ readonly [K in keyof TColumns as ColumnRowOf<TColumns[K]> extends never ? never : K]: ColumnRowOf<TColumns[K]>;
119
+ };
120
+ /**
121
+ * Insert shape. Omitted columns are dropped. Optional ones include `undefined`.
122
+ *
123
+ * @typeParam TColumns - Column builders
124
+ */
125
+ export type InsertFrom<TColumns> = {
126
+ readonly [K in keyof TColumns as ColumnInsertOf<TColumns[K]> extends never ? never : K]: ColumnInsertOf<TColumns[K]>;
127
+ };
128
+ /**
129
+ * Update shape. Omitted columns are dropped. The rest include `undefined`.
130
+ *
131
+ * @typeParam TColumns - Column builders
132
+ */
133
+ export type UpdateFrom<TColumns> = {
134
+ readonly [K in keyof TColumns as ColumnUpdateOf<TColumns[K]> extends never ? never : K]: ColumnUpdateOf<TColumns[K]>;
135
+ };
136
+ /**
137
+ * Declares a table.
138
+ *
139
+ * The catalog objects are built in `schema()`, not here.
140
+ *
141
+ * @typeParam TName - Table name
142
+ * @typeParam TColumns - Column builders
143
+ * @param name - Table name used by references and row types
144
+ * @param columns - Columns keyed by field name
145
+ * @param options - Indexes, checks, unique constraints, and names
146
+ * @returns The table
147
+ */
148
+ export declare function table<const TName extends string, const TColumns extends Readonly<Record<string, object>>>(name: TName, columns: TColumns): Table<TName, TColumns, Readonly<Record<string, never>>>;
149
+ export declare function table<const TName extends string, const TColumns extends Readonly<Record<string, object>>, const TOptions extends TableOptions<TColumns>>(name: TName, columns: TColumns, options: TOptions): Table<TName, TColumns, RelationsOf<TOptions>>;
150
+ /**
151
+ * Relation map stored on a table.
152
+ *
153
+ * Absent relations are an empty map, so a table without `relations` does not
154
+ * grow a conditional at every call.
155
+ *
156
+ * @typeParam TOptions - Options argument, or `undefined`
157
+ */
158
+ type RelationsOf<TOptions> = TOptions extends {
159
+ readonly relations: infer R;
160
+ } ? R extends Readonly<Record<string, RelationCall>> ? R : Readonly<Record<string, never>> : Readonly<Record<string, never>>;
161
+ /**
162
+ * Declares an index from column handles.
163
+ *
164
+ * @param columns - Columns in index order
165
+ * @returns An index call `schema()` compiles
166
+ */
167
+ export declare function index(...columns: readonly ColumnHandle[]): IndexCall;
168
+ /**
169
+ * Captures a check expression as text.
170
+ *
171
+ * Column handles become their SQL names. This is not a query builder.
172
+ *
173
+ * @param strings - Literal parts
174
+ * @param values - Interpolated columns, text, or numbers
175
+ * @returns The expression `schema()` stores
176
+ */
177
+ export declare function sql(strings: TemplateStringsArray, ...values: readonly SqlValue[]): SqlText;
178
+ /**
179
+ * Converts a camelCase field name to snake_case.
180
+ *
181
+ * @param name - Field or table name
182
+ * @returns The SQL spelling used when `casing` is `"snake"`
183
+ */
184
+ export declare function snakeCase(name: string): string;
185
+ /**
186
+ * Type name emitted for a table: `tasks` becomes `Tasks`.
187
+ *
188
+ * @param name - Table name
189
+ * @returns A TypeScript identifier
190
+ */
191
+ export declare function emittedTypeName(name: string): string;
192
+ /**
193
+ * Rejects options a later prompt owns, and unknown keys.
194
+ *
195
+ * @param options - Author object
196
+ * @param known - Keys this prompt implements
197
+ * @param later - Keys reserved for a named prompt
198
+ * @param where - Table or schema name used in the message
199
+ */
200
+ export declare function rejectLater(options: object, known: ReadonlySet<string>, later: Readonly<Record<string, string>>, where: string): void;
201
+ export {};
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Temporal codecs. `Temporal` is read when a value is encoded or decoded.
3
+ */
4
+ /** A time of day with a numeric UTC offset. Temporal has no timetz value. */
5
+ export type TimeWithOffset = {
6
+ readonly time: Temporal.PlainTime;
7
+ readonly offset: string;
8
+ };
9
+ /** Fractional seconds accepted by the date/time builders. */
10
+ export type TimePrecision = 0 | 1 | 2 | 3 | 4 | 5 | 6;
11
+ /**
12
+ * Checks a fractional-second precision.
13
+ *
14
+ * @param precision - Digits, or omitted
15
+ * @param role - Column type name
16
+ * @returns The precision, or undefined when omitted
17
+ */
18
+ export declare function timePrecision(precision: number | undefined, role: string): TimePrecision | undefined;
19
+ /**
20
+ * Encodes an instant.
21
+ *
22
+ * @param value - Instant
23
+ * @param precision - Fractional digits, or full precision when omitted
24
+ * @returns ISO-8601 text
25
+ */
26
+ export declare function encodeInstant(value: Temporal.Instant, precision?: TimePrecision): string;
27
+ /**
28
+ * Decodes an instant.
29
+ *
30
+ * @param wire - ISO-8601 text
31
+ * @returns An instant
32
+ */
33
+ export declare function decodeInstant(wire: string): Temporal.Instant;
34
+ /**
35
+ * Encodes a timestamp without time zone.
36
+ *
37
+ * @param value - Local date and time
38
+ * @param precision - Fractional digits
39
+ * @returns ISO-8601 text without a zone
40
+ */
41
+ export declare function encodeDateTime(value: Temporal.PlainDateTime, precision?: TimePrecision): string;
42
+ /**
43
+ * Decodes a timestamp without time zone.
44
+ *
45
+ * @param wire - ISO-8601 text
46
+ * @returns A plain date-time
47
+ */
48
+ export declare function decodeDateTime(wire: string): Temporal.PlainDateTime;
49
+ /**
50
+ * Encodes a date.
51
+ *
52
+ * @param value - Date
53
+ * @returns `YYYY-MM-DD`
54
+ */
55
+ export declare function encodeDate(value: Temporal.PlainDate): string;
56
+ /**
57
+ * Decodes a date.
58
+ *
59
+ * @param wire - `YYYY-MM-DD`
60
+ * @returns A date
61
+ */
62
+ export declare function decodeDate(wire: string): Temporal.PlainDate;
63
+ /**
64
+ * Encodes a time of day.
65
+ *
66
+ * @param value - Time
67
+ * @param precision - Fractional digits
68
+ * @returns `HH:MM:SS` text
69
+ */
70
+ export declare function encodeTime(value: Temporal.PlainTime, precision?: TimePrecision): string;
71
+ /**
72
+ * Decodes a time of day.
73
+ *
74
+ * @param wire - Time text
75
+ * @returns A time
76
+ */
77
+ export declare function decodeTime(wire: string): Temporal.PlainTime;
78
+ /**
79
+ * Encodes a time with offset.
80
+ *
81
+ * @param value - Time and offset
82
+ * @param precision - Fractional digits
83
+ * @returns Time text plus `±HH:MM`
84
+ */
85
+ export declare function encodeTimeZone(value: TimeWithOffset, precision?: TimePrecision): string;
86
+ /**
87
+ * Decodes a time with offset.
88
+ *
89
+ * @param wire - Time text plus an offset
90
+ * @returns Time and offset
91
+ */
92
+ export declare function decodeTimeZone(wire: string): TimeWithOffset;
93
+ /**
94
+ * Encodes a duration as an ISO-8601 duration.
95
+ *
96
+ * @param value - Duration
97
+ * @returns ISO-8601 text Postgres accepts for interval
98
+ */
99
+ export declare function encodeDuration(value: Temporal.Duration): string;
100
+ /**
101
+ * Decodes an ISO-8601 duration.
102
+ *
103
+ * @param wire - Duration text
104
+ * @returns A duration
105
+ */
106
+ export declare function decodeDuration(wire: string): Temporal.Duration;
107
+ /**
108
+ * Postgres interval field qualifier.
109
+ *
110
+ * @param fields - Qualifier such as `day to second`
111
+ * @returns The same qualifier when it is known
112
+ */
113
+ export declare function intervalFields(fields: string): string;
114
+ /**
115
+ * Temporal is in the runtime (Node and Bun) and not in this repository's
116
+ * TypeScript libs. These declarations name the methods the codecs call.
117
+ */
118
+ declare global {
119
+ /** Instant, plain date-time, date, time, and duration. */
120
+ namespace Temporal {
121
+ /** UTC instant. */
122
+ interface Instant {
123
+ /**
124
+ * @param options - Fractional digits to keep
125
+ * @returns ISO-8601 text
126
+ */
127
+ toString(options?: {
128
+ readonly fractionalSecondDigits?: number;
129
+ }): string;
130
+ }
131
+ /** Date and time without a zone. */
132
+ interface PlainDateTime {
133
+ /**
134
+ * @param options - Fractional digits to keep
135
+ * @returns ISO-8601 text
136
+ */
137
+ toString(options?: {
138
+ readonly fractionalSecondDigits?: number;
139
+ }): string;
140
+ }
141
+ /** Calendar date. */
142
+ interface PlainDate {
143
+ /**
144
+ * @returns `YYYY-MM-DD`
145
+ */
146
+ toString(): string;
147
+ /**
148
+ * @param duration - Days to add
149
+ * @returns A later or earlier date
150
+ */
151
+ add(duration: {
152
+ readonly days: number;
153
+ }): Temporal.PlainDate;
154
+ }
155
+ /** Time of day. */
156
+ interface PlainTime {
157
+ /**
158
+ * @param options - Fractional digits to keep
159
+ * @returns Time text
160
+ */
161
+ toString(options?: {
162
+ readonly fractionalSecondDigits?: number;
163
+ }): string;
164
+ }
165
+ /** ISO-8601 duration. */
166
+ interface Duration {
167
+ /**
168
+ * @returns ISO-8601 duration text
169
+ */
170
+ toString(): string;
171
+ }
172
+ }
173
+ /** Temporal constructors used by the codecs. */
174
+ var Temporal: {
175
+ readonly Instant: {
176
+ /**
177
+ * @param item - ISO-8601 instant
178
+ * @returns An instant
179
+ */
180
+ from(item: string): Temporal.Instant;
181
+ };
182
+ readonly PlainDateTime: {
183
+ /**
184
+ * @param item - ISO-8601 date-time
185
+ * @returns A plain date-time
186
+ */
187
+ from(item: string): Temporal.PlainDateTime;
188
+ };
189
+ readonly PlainDate: {
190
+ /**
191
+ * @param item - `YYYY-MM-DD`
192
+ * @returns A date
193
+ */
194
+ from(item: string): Temporal.PlainDate;
195
+ };
196
+ readonly PlainTime: {
197
+ /**
198
+ * @param item - Time text
199
+ * @returns A time
200
+ */
201
+ from(item: string): Temporal.PlainTime;
202
+ };
203
+ readonly Duration: {
204
+ /**
205
+ * @param item - ISO-8601 duration
206
+ * @returns A duration
207
+ */
208
+ from(item: string): Temporal.Duration;
209
+ };
210
+ };
211
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Text, varchar, char, and citext.
3
+ */
4
+ import { type ColumnBuilder, type PlainFlags } from "./column.js";
5
+ /**
6
+ * Unbounded text.
7
+ *
8
+ * @returns A text column
9
+ */
10
+ export declare function text(): ColumnBuilder<string, PlainFlags>;
11
+ /**
12
+ * Bounded text. The TypeScript type stays `string`. Encode rejects a longer value.
13
+ *
14
+ * @param length - Maximum characters, at least 1
15
+ * @returns A varchar column
16
+ */
17
+ export declare function varchar(length: number): ColumnBuilder<string, PlainFlags>;
18
+ /**
19
+ * Fixed-length character. Encode rejects a longer value and does not pad.
20
+ *
21
+ * @param length - Characters, at least 1
22
+ * @returns A char column
23
+ */
24
+ export declare function char(length: number): ColumnBuilder<string, PlainFlags>;
25
+ /**
26
+ * Case-insensitive text. The column depends on the `citext` extension.
27
+ *
28
+ * @returns A citext column
29
+ */
30
+ export declare function citext(): ColumnBuilder<string, PlainFlags>;
31
+ /**
32
+ * Returns text unchanged.
33
+ *
34
+ * @param value - Text
35
+ * @returns The same text
36
+ */
37
+ export declare function encodeText(value: string): string;
38
+ /**
39
+ * Returns wire text unchanged.
40
+ *
41
+ * @param wire - Text
42
+ * @returns The same text
43
+ */
44
+ export declare function decodeText(wire: string): string;