okmodel 0.1.1 → 0.2.1

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 (181) hide show
  1. package/README.md +32 -16
  2. package/dist/adapters/capabilities.d.ts +34 -0
  3. package/dist/adapters/pg/bunsql-extra.d.ts +17 -0
  4. package/dist/adapters/pg/bunsql.d.ts +60 -0
  5. package/dist/adapters/pg/call.d.ts +2 -12
  6. package/dist/adapters/pg/nodepostgres-extra.d.ts +18 -0
  7. package/dist/adapters/pg/nodepostgres.d.ts +57 -0
  8. package/dist/adapters/pg/postgres-extra.d.ts +50 -1
  9. package/dist/adapters/pg/postgresjs.d.ts +0 -4
  10. package/dist/adapters/pg/session.d.ts +94 -0
  11. package/dist/adapters/pg/watch.d.ts +18 -0
  12. package/dist/contracts/catalog/object.d.ts +1 -0
  13. package/dist/contracts/catalog/types.d.ts +15 -8
  14. package/dist/contracts/connection.d.ts +13 -0
  15. package/dist/contracts/driver.d.ts +18 -5
  16. package/dist/contracts/error.d.ts +17 -1
  17. package/dist/contracts/generator.d.ts +63 -0
  18. package/dist/contracts/index.d.ts +2 -2
  19. package/dist/contracts/index.js +1 -1
  20. package/dist/contracts/internal.js +11 -9
  21. package/dist/contracts/location.d.ts +24 -0
  22. package/dist/contracts/rows.d.ts +15 -0
  23. package/dist/dialects/pg/archive-bind.d.ts +22 -0
  24. package/dist/dialects/pg/column.d.ts +126 -9
  25. package/dist/dialects/pg/compile.d.ts +1 -0
  26. package/dist/dialects/pg/custom.d.ts +6 -0
  27. package/dist/dialects/pg/filter-parse.d.ts +19 -0
  28. package/dist/dialects/pg/filters.d.ts +19 -0
  29. package/dist/dialects/pg/index.d.ts +11 -2
  30. package/dist/dialects/pg/index.js +159 -1063
  31. package/dist/dialects/pg/keys.d.ts +19 -3
  32. package/dist/dialects/pg/model.d.ts +223 -2
  33. package/dist/dialects/pg/operator-fit.d.ts +86 -0
  34. package/dist/dialects/pg/operators.d.ts +39 -1
  35. package/dist/dialects/pg/ops/arr-append.d.ts +9 -0
  36. package/dist/dialects/pg/ops/arr-ns.d.ts +7 -0
  37. package/dist/dialects/pg/ops/arr-remove.d.ts +9 -0
  38. package/dist/dialects/pg/ops/containedBy.d.ts +9 -0
  39. package/dist/dialects/pg/ops/contains.d.ts +8 -4
  40. package/dist/dialects/pg/ops/hasAnyKey.d.ts +8 -0
  41. package/dist/dialects/pg/ops/hasKey.d.ts +8 -0
  42. package/dist/dialects/pg/ops/json-ns.d.ts +6 -0
  43. package/dist/dialects/pg/ops/json-set.d.ts +12 -0
  44. package/dist/dialects/pg/ops/matches.d.ts +16 -0
  45. package/dist/dialects/pg/ops/overlaps.d.ts +9 -0
  46. package/dist/dialects/pg/ops/path.d.ts +13 -0
  47. package/dist/dialects/pg/preset.d.ts +76 -0
  48. package/dist/dialects/pg/relations.d.ts +59 -2
  49. package/dist/dialects/pg/schema.d.ts +109 -5
  50. package/dist/dialects/pg/table.d.ts +130 -11
  51. package/dist/dialects/pg/temporal.d.ts +9 -7
  52. package/dist/dialects/pg/tenancy.d.ts +94 -0
  53. package/dist/dialects/pg/through.d.ts +21 -0
  54. package/dist/dialects/pg/trait.d.ts +141 -0
  55. package/dist/dialects/pg/where.d.ts +37 -0
  56. package/dist/runtime/aggregate.d.ts +25 -0
  57. package/dist/runtime/archive-handle.d.ts +18 -0
  58. package/dist/runtime/archive-rules.d.ts +12 -0
  59. package/dist/runtime/archive.d.ts +73 -0
  60. package/dist/runtime/batch.d.ts +20 -0
  61. package/dist/runtime/client.d.ts +114 -5
  62. package/dist/runtime/conflict.d.ts +2 -1
  63. package/dist/runtime/exposure.d.ts +27 -0
  64. package/dist/runtime/hookm.d.ts +39 -0
  65. package/dist/runtime/ids/index.d.ts +11 -0
  66. package/dist/runtime/ids/index.js +193 -0
  67. package/dist/runtime/ids/okid-extended.d.ts +19 -0
  68. package/dist/runtime/ids/okid-generator.d.ts +21 -0
  69. package/dist/runtime/ids/okid-shared.d.ts +89 -0
  70. package/dist/runtime/ids/okid.d.ts +24 -0
  71. package/dist/runtime/ids/uuid.d.ts +21 -0
  72. package/dist/runtime/lock.d.ts +22 -0
  73. package/dist/runtime/operator-sql.d.ts +8 -0
  74. package/dist/runtime/page.d.ts +25 -0
  75. package/dist/runtime/pg/bun.d.ts +30 -0
  76. package/dist/runtime/pg/bun.js +52 -0
  77. package/dist/runtime/pg/pg.d.ts +29 -0
  78. package/dist/runtime/pg/pg.js +52 -0
  79. package/dist/runtime/pg/pglite.js +16 -17
  80. package/dist/runtime/pg/postgresjs.js +14 -24
  81. package/dist/runtime/plan.d.ts +146 -7
  82. package/dist/runtime/preset-stack.d.ts +17 -0
  83. package/dist/runtime/presets.d.ts +48 -0
  84. package/dist/runtime/read-stream.d.ts +26 -0
  85. package/dist/runtime/safety/index.d.ts +159 -0
  86. package/dist/runtime/safety/index.js +294 -0
  87. package/dist/runtime/safety-hook.d.ts +42 -0
  88. package/dist/runtime/server-check.d.ts +34 -0
  89. package/dist/runtime/tenancy/index.d.ts +37 -0
  90. package/dist/runtime/tenancy/index.js +365 -0
  91. package/dist/runtime/trait-read.d.ts +30 -0
  92. package/dist/runtime/traits/index.d.ts +128 -0
  93. package/dist/runtime/traits/index.js +509 -0
  94. package/dist/runtime/transaction.d.ts +19 -0
  95. package/dist/runtime/tx.d.ts +22 -7
  96. package/dist/runtime/types.d.ts +376 -27
  97. package/dist/runtime/validate/bind.d.ts +11 -0
  98. package/dist/runtime/validate/closed.d.ts +16 -0
  99. package/dist/runtime/validate/engine.d.ts +41 -0
  100. package/dist/runtime/validate/hook.d.ts +17 -0
  101. package/dist/runtime/validate/index.d.ts +21 -0
  102. package/dist/runtime/validate/index.js +175 -0
  103. package/dist/runtime/validate/load.d.ts +13 -0
  104. package/dist/runtime/validate/places.d.ts +41 -0
  105. package/dist/runtime/validate/rules.d.ts +108 -0
  106. package/dist/runtime/validate/surface.d.ts +102 -0
  107. package/dist/runtime/write.d.ts +30 -5
  108. package/dist/shared/{fgqgsb5z.js → 0qkxbm1f.js} +2 -2
  109. package/dist/shared/0v1g424p.js +26 -0
  110. package/dist/shared/10tjenmd.js +210 -0
  111. package/dist/shared/{xqbhg6cn.js → 1dp5knt7.js} +95 -10
  112. package/dist/shared/38crxbgn.js +229 -0
  113. package/dist/shared/3a5ne750.js +158 -0
  114. package/dist/shared/4b9da9d7.js +138 -0
  115. package/dist/shared/4e4c6vq2.js +62 -0
  116. package/dist/shared/{x5x59srr.js → 4jzzghr6.js} +416 -83
  117. package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
  118. package/dist/shared/{05w44d8g.js → 5z4q2zda.js} +567 -18
  119. package/dist/shared/672t5vym.js +12 -0
  120. package/dist/shared/7m88x3e9.js +45 -0
  121. package/dist/shared/7mht49yd.js +1091 -0
  122. package/dist/shared/{mtkwv8wx.js → 7p2wbz7f.js} +1 -1
  123. package/dist/shared/83eaefwr.js +10 -0
  124. package/dist/shared/96ps4g1z.js +32 -0
  125. package/dist/shared/97g2jnrw.js +76 -0
  126. package/dist/shared/{xy79j5hq.js → 9k6vetvf.js} +25 -36
  127. package/dist/shared/{w8samvk1.js → a1gdp7j9.js} +1 -1
  128. package/dist/shared/a5sxz52y.js +13 -0
  129. package/dist/shared/{dynq16vb.js → b066g80h.js} +8 -6
  130. package/dist/shared/cstgkzdx.js +154 -0
  131. package/dist/shared/{523ft3e8.js → d04j53v8.js} +6 -5
  132. package/dist/shared/{y9m15dfv.js → d2whjz4k.js} +15 -9
  133. package/dist/shared/dd4f8mnx.js +307 -0
  134. package/dist/shared/e6wg00wd.js +164 -0
  135. package/dist/shared/e7a268fy.js +195 -0
  136. package/dist/shared/{kprcwaha.js → eaxwrgby.js} +4 -3
  137. package/dist/shared/{dkn3y60a.js → ecdzej21.js} +76 -112
  138. package/dist/shared/{hadrfb9h.js → edwqqryd.js} +17 -14
  139. package/dist/shared/{m3ypagh5.js → eqmtn1bj.js} +57 -5
  140. package/dist/shared/g1b5zzj9.js +75 -0
  141. package/dist/shared/g9f0zqce.js +376 -0
  142. package/dist/shared/ge03bfca.js +64 -0
  143. package/dist/shared/{yd1kzwn2.js → jns2wx4t.js} +55 -12
  144. package/dist/shared/k3ted12y.js +33 -0
  145. package/dist/shared/k7dwkhvq.js +31 -0
  146. package/dist/shared/{hd293j9g.js → kyxb62mc.js} +14 -2
  147. package/dist/shared/m9tv7xn7.js +404 -0
  148. package/dist/shared/mrq77sgw.js +55 -0
  149. package/dist/shared/mxmcdsh5.js +450 -0
  150. package/dist/shared/n442h54c.js +14 -0
  151. package/dist/shared/n47rd821.js +442 -0
  152. package/dist/shared/n4jqhpqz.js +27 -0
  153. package/dist/shared/{mkjmqjv4.js → nfzc5z0w.js} +2 -104
  154. package/dist/shared/nsva2a6b.js +42 -0
  155. package/dist/shared/ps43134h.js +69 -0
  156. package/dist/shared/{8b04d28c.js → py3nh7jy.js} +2 -2
  157. package/dist/shared/qa5dsc7z.js +86 -0
  158. package/dist/shared/{g5fhqmwe.js → qxa0yb9j.js} +6 -4
  159. package/dist/shared/r6nwkxnt.js +86 -0
  160. package/dist/shared/{jjb7yht9.js → rtnaqre0.js} +3 -3
  161. package/dist/shared/rwmrejjz.js +26 -0
  162. package/dist/shared/{zhc5vmgf.js → s6gqfn5j.js} +2 -2
  163. package/dist/shared/sacqha1y.js +70 -0
  164. package/dist/shared/{qk3hxfja.js → sfh4pk75.js} +5 -5
  165. package/dist/shared/{j5cn2963.js → t4tbsy9h.js} +13 -64
  166. package/dist/shared/{ngk8gj61.js → tbszx8mz.js} +15 -1
  167. package/dist/shared/v18jva5b.js +90 -0
  168. package/dist/shared/x9v1qgeb.js +201 -0
  169. package/dist/shared/xatfg0gn.js +193 -0
  170. package/dist/shared/xkz8g6by.js +225 -0
  171. package/dist/shared/{rgs0st28.js → xrfnq5k8.js} +237 -434
  172. package/dist/shared/ytg3xf9p.js +149 -0
  173. package/dist/shared/yw5c610b.js +48 -0
  174. package/dist/shared/zd93g3rq.js +31 -0
  175. package/dist/shared/zt8y0wzb.js +132 -0
  176. package/dist/shared/{p0cbr3g2.js → zwmqxb0g.js} +1 -1
  177. package/dist/tooling/cli.js +14 -10
  178. package/dist/tooling/migrate/commands.d.ts +10 -0
  179. package/dist/tooling/migrate/engine.d.ts +36 -0
  180. package/package.json +41 -4
  181. package/dist/shared/gk7cs7sp.js +0 -566
@@ -1,566 +0,0 @@
1
- import {
2
- REFERENTIAL_ACTIONS,
3
- referentialAction
4
- } from "./j5cn2963.js";
5
- import {
6
- OkmError2,
7
- throwNamed2
8
- } from "./ycwz42az.js";
9
-
10
- // src/dialects/pg/misuse.ts
11
- var COLUMN_DEFINITION_CODE = "OKM1060";
12
- var RESERVED_OPTION_CODE = "OKM1061";
13
- var CODEC_VALUE_CODE = "OKM1210";
14
- function definition(message) {
15
- throw new OkmError2(COLUMN_DEFINITION_CODE, message);
16
- }
17
- function unavailable(message) {
18
- throw new OkmError2(RESERVED_OPTION_CODE, message);
19
- }
20
- function rejected(message) {
21
- throw new OkmError2(CODEC_VALUE_CODE, message);
22
- }
23
-
24
- // src/dialects/pg/quote.ts
25
- function quoteLiteral(value) {
26
- return `'${value.replaceAll("'", "''")}'`;
27
- }
28
- function arrayElement(encoded, raw) {
29
- if (raw && (encoded === "true" || encoded === "false" || isBareNumber(encoded))) {
30
- return encoded;
31
- }
32
- return `"${encoded.replaceAll("\\", "\\\\").replaceAll('"', "\\\"")}"`;
33
- }
34
- function isBareNumber(encoded) {
35
- let pattern = bareNumber;
36
- pattern ??= /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/;
37
- bareNumber = pattern;
38
- return pattern.test(encoded);
39
- }
40
- var bareNumber;
41
-
42
- // src/dialects/pg/array-literal.ts
43
- function writeArray(value, dims, encode, raw) {
44
- return writeLevel(value, dims, encode, raw);
45
- }
46
- function readArray(wire, dims, decode) {
47
- const cursor = { text: wire, index: 0 };
48
- const parsed = parseValue(cursor);
49
- skipSpace(cursor);
50
- if (cursor.index !== cursor.text.length) {
51
- rejected("Array literal has trailing text.");
52
- }
53
- if (!Array.isArray(parsed)) {
54
- rejected("Array literal must start with `{`.");
55
- }
56
- return interpret(parsed, dims, decode);
57
- }
58
- function writeLevel(value, dims, encode, raw) {
59
- if (!Array.isArray(value)) {
60
- rejected("Array column expected an array.");
61
- }
62
- const parts = [];
63
- if (dims === 1) {
64
- for (const item of value) {
65
- if (item === null || item === undefined) {
66
- rejected("Array elements cannot be null.");
67
- }
68
- parts.push(arrayElement(encode(item), raw));
69
- }
70
- } else {
71
- for (const item of value) {
72
- parts.push(writeLevel(item, dims - 1, encode, raw));
73
- }
74
- }
75
- return `{${parts.join(",")}}`;
76
- }
77
- function interpret(nodes, dims, decode) {
78
- if (dims === 1) {
79
- return nodes.map((cell) => {
80
- if (typeof cell !== "string") {
81
- rejected("Array rank does not match dims.");
82
- }
83
- return decode(cell);
84
- });
85
- }
86
- return nodes.map((cell) => {
87
- if (!Array.isArray(cell)) {
88
- rejected("Array rank does not match dims.");
89
- }
90
- return interpret(cell, dims - 1, decode);
91
- });
92
- }
93
- function parseValue(cursor) {
94
- skipSpace(cursor);
95
- if (peek(cursor) === "{") {
96
- return parseArray(cursor);
97
- }
98
- return parseElement(cursor);
99
- }
100
- function parseArray(cursor) {
101
- expectChar(cursor, "{");
102
- skipSpace(cursor);
103
- if (peek(cursor) === "}") {
104
- cursor.index += 1;
105
- return [];
106
- }
107
- const items = [];
108
- for (;; ) {
109
- items.push(parseValue(cursor));
110
- skipSpace(cursor);
111
- if (peek(cursor) === ",") {
112
- cursor.index += 1;
113
- skipSpace(cursor);
114
- continue;
115
- }
116
- expectChar(cursor, "}");
117
- return items;
118
- }
119
- }
120
- function parseElement(cursor) {
121
- if (peek(cursor) === '"') {
122
- return parseQuoted(cursor);
123
- }
124
- const start = cursor.index;
125
- while (cursor.index < cursor.text.length) {
126
- const char = cursor.text[cursor.index];
127
- if (char === "," || char === "}" || char === undefined || isSpace(char)) {
128
- break;
129
- }
130
- cursor.index += 1;
131
- }
132
- const token = cursor.text.slice(start, cursor.index);
133
- if (token.length === 0) {
134
- rejected("Array literal is missing an element.");
135
- }
136
- if (token === "NULL") {
137
- return null;
138
- }
139
- return token;
140
- }
141
- function parseQuoted(cursor) {
142
- expectChar(cursor, '"');
143
- let out = "";
144
- for (;; ) {
145
- const char = next(cursor);
146
- if (char === undefined) {
147
- rejected("Array literal ended inside a quote.");
148
- }
149
- if (char === '"') {
150
- if (peek(cursor) === '"') {
151
- cursor.index += 1;
152
- out += '"';
153
- continue;
154
- }
155
- return out;
156
- }
157
- if (char === "\\") {
158
- const escaped = next(cursor);
159
- if (escaped === undefined) {
160
- rejected("Array literal ended inside an escape.");
161
- }
162
- out += escaped;
163
- continue;
164
- }
165
- out += char;
166
- }
167
- }
168
- function expectChar(cursor, expected) {
169
- if (peek(cursor) !== expected) {
170
- rejected(`Array literal expected ${expected}.`);
171
- }
172
- cursor.index += 1;
173
- }
174
- function peek(cursor) {
175
- return cursor.text[cursor.index];
176
- }
177
- function next(cursor) {
178
- const char = cursor.text[cursor.index];
179
- if (char !== undefined) {
180
- cursor.index += 1;
181
- }
182
- return char;
183
- }
184
- function skipSpace(cursor) {
185
- while (cursor.index < cursor.text.length) {
186
- const char = cursor.text[cursor.index];
187
- if (char === undefined || !isSpace(char)) {
188
- return;
189
- }
190
- cursor.index += 1;
191
- }
192
- }
193
- function isSpace(char) {
194
- return char === " " || char === `
195
- ` || char === "\t";
196
- }
197
-
198
- // src/dialects/pg/column.ts
199
- class ColumnBuilder2 {
200
- state;
201
- constructor(state) {
202
- this.state = state;
203
- }
204
- encode(value) {
205
- return this.state.encode(value);
206
- }
207
- decode(wire) {
208
- return this.state.decode(wire);
209
- }
210
- nullable() {
211
- return rebuild(this.state, { nullable: true });
212
- }
213
- default(value) {
214
- if (value === null && this.state.nullable === false) {
215
- definition("A null default is only accepted on a nullable column. Call .nullable() first.");
216
- }
217
- if (this.state.picklist !== undefined && value !== null) {
218
- const text = String(value);
219
- if (!this.state.picklist.values.includes(text)) {
220
- definition(`Default ${text} is not in the picklist ${this.state.picklist.values.join(", ")}.`);
221
- }
222
- }
223
- return rebuild(this.state, {
224
- hasDefault: true,
225
- defaultSql: value === null ? "NULL" : sqlOf(this.state, value),
226
- defaultValue: value,
227
- generated: undefined
228
- });
229
- }
230
- defaultSql(expression) {
231
- if (expression.length === 0) {
232
- definition("defaultSql must be a non-empty SQL expression.");
233
- }
234
- return rebuild(this.state, {
235
- hasDefault: true,
236
- defaultSql: expression,
237
- defaultValue: undefined,
238
- generated: undefined
239
- });
240
- }
241
- unique(options) {
242
- return rebuild(this.state, {
243
- unique: { reason: options?.reason, global: options?.global }
244
- });
245
- }
246
- picklist(values, options) {
247
- if (values.length === 0) {
248
- definition("A picklist must contain at least one value.");
249
- }
250
- const allowed = new Set;
251
- for (const value of values) {
252
- if (value.length === 0) {
253
- definition("Picklist values must be non-empty strings.");
254
- }
255
- if (allowed.has(value)) {
256
- definition(`Picklist value ${value} is repeated. Each value is accepted once.`);
257
- }
258
- allowed.add(value);
259
- }
260
- if (typeof this.state.defaultValue === "string" && !allowed.has(this.state.defaultValue)) {
261
- definition(`Default ${this.state.defaultValue} is not in the picklist ${values.join(", ")}.`);
262
- }
263
- const previous = this.state.elementEncode;
264
- const elementEncode = (value) => {
265
- if (typeof value !== "string" || !allowed.has(value)) {
266
- rejected(`Picklist rejected ${String(value)}. Accepted values: ${[...allowed].join(", ")}.`);
267
- }
268
- return previous(value);
269
- };
270
- return rebuild(this.state, {
271
- picklist: { values: values.slice(), check: options?.check !== false },
272
- elementEncode,
273
- encode: elementEncode
274
- });
275
- }
276
- generated(expression, options) {
277
- if (expression.length === 0) {
278
- definition("generated() must be a non-empty SQL expression.");
279
- }
280
- return rebuild(this.state, {
281
- generated: { stored: options?.stored !== false, expression },
282
- hasDefault: true,
283
- defaultSql: undefined,
284
- defaultValue: undefined
285
- });
286
- }
287
- guarded() {
288
- return rebuild(this.state, { guarded: true });
289
- }
290
- hidden() {
291
- return rebuild(this.state, { hidden: true });
292
- }
293
- references(table, options) {
294
- if (table.length === 0) {
295
- definition("references() needs a table name.");
296
- }
297
- const onDelete = readAction(options?.onDelete, "onDelete");
298
- const onUpdate = readAction(options?.onUpdate, "onUpdate");
299
- const columns = readReferenceColumns(options?.columns);
300
- return rebuild(this.state, {
301
- references: {
302
- table,
303
- ...onDelete !== undefined ? { onDelete } : {},
304
- ...onUpdate !== undefined ? { onUpdate } : {},
305
- ...columns !== undefined ? { columns } : {}
306
- }
307
- });
308
- }
309
- renamedFrom(name) {
310
- if (name.length === 0) {
311
- definition("renamedFrom must be a non-empty previous column name.");
312
- }
313
- return rebuild(this.state, { renamedFrom: name });
314
- }
315
- sqlName(name) {
316
- if (name.length === 0) {
317
- definition("sqlName must be a non-empty SQL identifier.");
318
- }
319
- return rebuild(this.state, { sqlName: name });
320
- }
321
- comment(text) {
322
- return rebuild(this.state, { comment: text });
323
- }
324
- array(options) {
325
- if (this.state.dims !== 0) {
326
- definition("array() accepts a scalar column. This column is already an array.");
327
- }
328
- const dims = options?.dims ?? 1;
329
- if (!Number.isInteger(dims) || dims < 1 || dims > 6) {
330
- definition(`Array dims ${String(dims)} must be an integer from 1 to 6.`);
331
- }
332
- const elementEncode = this.state.elementEncode;
333
- const elementDecode = this.state.elementDecode;
334
- const raw = this.state.sqlForm === "raw";
335
- return rebuild(this.state, {
336
- dims,
337
- encode: (value) => writeArray(value, dims, elementEncode, raw),
338
- decode: (wire) => readArray(wire, dims, elementDecode)
339
- });
340
- }
341
- }
342
- function required(body) {
343
- return openColumn({
344
- nullable: false,
345
- hasDefault: false,
346
- generated: false,
347
- guarded: false,
348
- hidden: false,
349
- omitWrite: false,
350
- ...body
351
- });
352
- }
353
- function openColumn(input) {
354
- const elementEncode = input.encode;
355
- const elementDecode = input.decode;
356
- return new ColumnBuilder2({
357
- baseType: input.baseType,
358
- dims: 0,
359
- nullable: input.nullable,
360
- hasDefault: input.hasDefault,
361
- defaultSql: input.defaultSql,
362
- defaultValue: undefined,
363
- identity: input.identity,
364
- generated: undefined,
365
- unique: undefined,
366
- picklist: undefined,
367
- guarded: input.guarded,
368
- hidden: input.hidden,
369
- omitWrite: input.omitWrite,
370
- renamedFrom: undefined,
371
- sqlName: undefined,
372
- comment: undefined,
373
- extension: input.extension,
374
- typeDependency: input.typeDependency,
375
- enumLabels: input.enumLabels,
376
- domain: input.domain,
377
- primaryKey: input.primaryKey === true,
378
- typeLabel: input.typeLabel,
379
- references: undefined,
380
- validate: undefined,
381
- sqlForm: input.sqlForm,
382
- encode: input.encode,
383
- decode: input.decode,
384
- elementEncode,
385
- elementDecode
386
- });
387
- }
388
- function formatType(baseType, dims) {
389
- if (dims === 0) {
390
- return baseType;
391
- }
392
- return baseType + "[]".repeat(dims);
393
- }
394
- function sqlOf(state, value) {
395
- const encoded = state.encode(value);
396
- const typed = formatType(state.baseType, state.dims);
397
- if (state.sqlForm === "cast") {
398
- return `${quoteLiteral(encoded)}::${typed}`;
399
- }
400
- if (state.sqlForm === "json") {
401
- return `${quoteLiteral(encoded)}::json`;
402
- }
403
- if (state.sqlForm === "jsonb") {
404
- return `${quoteLiteral(encoded)}::jsonb`;
405
- }
406
- if (state.dims > 0 || state.sqlForm === "quote") {
407
- return quoteLiteral(encoded);
408
- }
409
- return encoded;
410
- }
411
- function readAction(action, role) {
412
- if (action === undefined) {
413
- return;
414
- }
415
- if (referentialAction(action) === undefined) {
416
- definition(`references() ${role} ${action} is not a referential action. Accepted actions: ${REFERENTIAL_ACTIONS.join(", ")}.`);
417
- }
418
- return action;
419
- }
420
- function readReferenceColumns(columns) {
421
- if (columns === undefined) {
422
- return;
423
- }
424
- if (columns.length === 0) {
425
- definition("references() columns must name at least one target column.");
426
- }
427
- const copy = [];
428
- for (const name of columns) {
429
- if (name.length === 0) {
430
- definition("references() columns must be non-empty names.");
431
- }
432
- copy.push(name);
433
- }
434
- return copy;
435
- }
436
- function rebuild(state, patch) {
437
- return new ColumnBuilder2({ ...state, ...patch });
438
- }
439
-
440
- // src/dialects/pg/table.ts
441
- var TABLE_KNOWN = new Set([
442
- "checks",
443
- "comment",
444
- "indexes",
445
- "relations",
446
- "renamedFrom",
447
- "sqlName",
448
- "unique"
449
- ]);
450
- var TABLE_LATER = {
451
- computed: "later",
452
- omitDefaults: "0.2",
453
- policies: "later",
454
- presets: "0.2",
455
- reference: "0.4",
456
- tenancy: "0.2",
457
- traits: "0.2",
458
- validate: "0.2",
459
- validation: "0.2"
460
- };
461
- function table2(name, columns, options) {
462
- if (name.length === 0) {
463
- definition("table() needs a name.");
464
- }
465
- if (options !== undefined) {
466
- rejectLater(options, TABLE_KNOWN, TABLE_LATER, `Table ${name}`);
467
- }
468
- return { name, columns, ...options !== undefined ? { options } : {} };
469
- }
470
- function index2(...columns) {
471
- return indexCall(columns.map((column) => column.name), false);
472
- }
473
- function sql2(strings, ...values) {
474
- let text = strings[0] ?? "";
475
- for (let index = 0;index < values.length; index += 1) {
476
- text += sqlValue(values[index]);
477
- text += strings[index + 1] ?? "";
478
- }
479
- return { text };
480
- }
481
- function snakeCase(name) {
482
- let out = "";
483
- for (let index = 0;index < name.length; index += 1) {
484
- const char = name[index] ?? "";
485
- const lower = char.toLowerCase();
486
- if (lower !== char && char.toUpperCase() === char && out.length > 0 && !out.endsWith("_")) {
487
- out += "_";
488
- }
489
- out += lower;
490
- }
491
- return out;
492
- }
493
- function emittedTypeName(name) {
494
- let out = "";
495
- let capitalize = true;
496
- for (const char of name) {
497
- const letter = char >= "a" && char <= "z" || char >= "A" && char <= "Z";
498
- const digit = char >= "0" && char <= "9";
499
- if (!letter && !digit) {
500
- capitalize = true;
501
- continue;
502
- }
503
- if (capitalize && letter) {
504
- out += char.toUpperCase();
505
- capitalize = false;
506
- continue;
507
- }
508
- out += char;
509
- capitalize = false;
510
- }
511
- if (out.length === 0) {
512
- return "Table";
513
- }
514
- const first = out[0] ?? "";
515
- if (first >= "0" && first <= "9") {
516
- return `T${out}`;
517
- }
518
- return out;
519
- }
520
- function rejectLater(options, known, later, where) {
521
- const record = options;
522
- for (const key of Object.keys(record)) {
523
- const prompt = later[key];
524
- if (prompt !== undefined) {
525
- if (record[key] !== undefined) {
526
- const when = prompt === "later" ? "later" : `in ${prompt}`;
527
- unavailable(`${where} option ${key} is not available yet. It arrives ${when}.`);
528
- }
529
- continue;
530
- }
531
- if (!known.has(key)) {
532
- const accepted = [...known].sort().join(", ");
533
- const candidates = [...known, ...Object.keys(later)];
534
- throwNamed2("OKM1060", key, candidates, `${where} option ${key} is not supported. Accepted options: ${accepted}.`);
535
- }
536
- }
537
- }
538
- function indexCall(columns, isUnique) {
539
- return {
540
- columns,
541
- isUnique,
542
- unique() {
543
- return indexCall(columns, true);
544
- }
545
- };
546
- }
547
- function sqlValue(value) {
548
- if (typeof value === "string") {
549
- return value;
550
- }
551
- if (typeof value === "number" || typeof value === "boolean") {
552
- return String(value);
553
- }
554
- if (value === null || value === undefined) {
555
- return "null";
556
- }
557
- if ("text" in value && typeof value.text === "string") {
558
- return value.text;
559
- }
560
- if ("name" in value && typeof value.name === "string") {
561
- return value.name;
562
- }
563
- definition("sql accepts a column, a string, a number, a boolean, or null.");
564
- }
565
-
566
- export { definition, unavailable, rejected, quoteLiteral, ColumnBuilder2, required, openColumn, formatType, table2, index2, sql2, snakeCase, emittedTypeName, rejectLater };