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,456 @@
1
+ import {
2
+ catalogError2
3
+ } from "./ycwz42az.js";
4
+
5
+ // src/contracts/utf8.ts
6
+ function utf8ByteLength2(value) {
7
+ const length = value.length;
8
+ for (let index = 0;index < length; index += 1) {
9
+ if (value.charCodeAt(index) > 127) {
10
+ return utf8ByteLengthFull(value);
11
+ }
12
+ }
13
+ return length;
14
+ }
15
+ function utf8ByteLengthFull(value) {
16
+ let bytes = 0;
17
+ for (let index = 0;index < value.length; ) {
18
+ const unit = readCode(value, index);
19
+ bytes += utf8Width(unit.code);
20
+ index += unit.units;
21
+ }
22
+ return bytes;
23
+ }
24
+ function encodeUtf8(value) {
25
+ const bytes = new Uint8Array(value.length);
26
+ for (let index = 0;index < value.length; index++) {
27
+ const code = value.charCodeAt(index);
28
+ if (code > 127) {
29
+ return encodeUtf8Slow(value);
30
+ }
31
+ bytes[index] = code;
32
+ }
33
+ return bytes;
34
+ }
35
+ function truncateUtf8(value, budget) {
36
+ if (budget <= 0) {
37
+ return "";
38
+ }
39
+ let bytes = 0;
40
+ let end = 0;
41
+ for (let index = 0;index < value.length; ) {
42
+ const unit = readCode(value, index);
43
+ const width = utf8Width(unit.code);
44
+ if (bytes + width > budget) {
45
+ break;
46
+ }
47
+ bytes += width;
48
+ index += unit.units;
49
+ end = index;
50
+ }
51
+ return value.slice(0, end);
52
+ }
53
+ function encodeUtf8Slow(value) {
54
+ const bytes = new Uint8Array(utf8ByteLength2(value));
55
+ let offset = 0;
56
+ for (let index = 0;index < value.length; ) {
57
+ const unit = readCode(value, index);
58
+ offset = writeUtf8(bytes, offset, unit.code);
59
+ index += unit.units;
60
+ }
61
+ return bytes;
62
+ }
63
+ function readCode(value, index) {
64
+ const lead = value.charCodeAt(index);
65
+ const next = value.charCodeAt(index + 1);
66
+ if (lead >= 55296 && lead <= 56319 && next >= 56320 && next <= 57343) {
67
+ return {
68
+ code: 65536 + (lead - 55296 << 10) + (next - 56320),
69
+ units: 2
70
+ };
71
+ }
72
+ return { code: lead, units: 1 };
73
+ }
74
+ function utf8Width(code) {
75
+ if (code <= 127) {
76
+ return 1;
77
+ }
78
+ if (code <= 2047) {
79
+ return 2;
80
+ }
81
+ if (code <= 65535) {
82
+ return 3;
83
+ }
84
+ return 4;
85
+ }
86
+ function writeUtf8(bytes, offset, code) {
87
+ if (code <= 127) {
88
+ bytes[offset] = code;
89
+ return offset + 1;
90
+ }
91
+ if (code <= 2047) {
92
+ bytes[offset] = 192 | code >> 6;
93
+ bytes[offset + 1] = 128 | code & 63;
94
+ return offset + 2;
95
+ }
96
+ if (code <= 65535) {
97
+ bytes[offset] = 224 | code >> 12;
98
+ bytes[offset + 1] = 128 | code >> 6 & 63;
99
+ bytes[offset + 2] = 128 | code & 63;
100
+ return offset + 3;
101
+ }
102
+ bytes[offset] = 240 | code >> 18;
103
+ bytes[offset + 1] = 128 | code >> 12 & 63;
104
+ bytes[offset + 2] = 128 | code >> 6 & 63;
105
+ bytes[offset + 3] = 128 | code & 63;
106
+ return offset + 4;
107
+ }
108
+
109
+ // src/contracts/sha256.ts
110
+ var HEX = "0123456789abcdef";
111
+ var constants;
112
+ function sha2562(text) {
113
+ return toHex(sha256Bytes(encodeUtf8(text)));
114
+ }
115
+ function roundConstants() {
116
+ constants ??= new Uint32Array([
117
+ 1116352408,
118
+ 1899447441,
119
+ 3049323471,
120
+ 3921009573,
121
+ 961987163,
122
+ 1508970993,
123
+ 2453635748,
124
+ 2870763221,
125
+ 3624381080,
126
+ 310598401,
127
+ 607225278,
128
+ 1426881987,
129
+ 1925078388,
130
+ 2162078206,
131
+ 2614888103,
132
+ 3248222580,
133
+ 3835390401,
134
+ 4022224774,
135
+ 264347078,
136
+ 604807628,
137
+ 770255983,
138
+ 1249150122,
139
+ 1555081692,
140
+ 1996064986,
141
+ 2554220882,
142
+ 2821834349,
143
+ 2952996808,
144
+ 3210313671,
145
+ 3336571891,
146
+ 3584528711,
147
+ 113926993,
148
+ 338241895,
149
+ 666307205,
150
+ 773529912,
151
+ 1294757372,
152
+ 1396182291,
153
+ 1695183700,
154
+ 1986661051,
155
+ 2177026350,
156
+ 2456956037,
157
+ 2730485921,
158
+ 2820302411,
159
+ 3259730800,
160
+ 3345764771,
161
+ 3516065817,
162
+ 3600352804,
163
+ 4094571909,
164
+ 275423344,
165
+ 430227734,
166
+ 506948616,
167
+ 659060556,
168
+ 883997877,
169
+ 958139571,
170
+ 1322822218,
171
+ 1537002063,
172
+ 1747873779,
173
+ 1955562222,
174
+ 2024104815,
175
+ 2227730452,
176
+ 2361852424,
177
+ 2428436474,
178
+ 2756734187,
179
+ 3204031479,
180
+ 3329325298
181
+ ]);
182
+ return constants;
183
+ }
184
+ function sha256Bytes(message) {
185
+ const k = roundConstants();
186
+ const bitLength = message.length * 8;
187
+ const pad = (64 - (message.length + 9) % 64) % 64;
188
+ const total = message.length + 1 + pad + 8;
189
+ const data = new Uint8Array(total);
190
+ data.set(message);
191
+ data[message.length] = 128;
192
+ const view = new DataView(data.buffer);
193
+ view.setUint32(total - 8, Math.floor(bitLength / 4294967296));
194
+ view.setUint32(total - 4, bitLength >>> 0);
195
+ let h0 = 1779033703;
196
+ let h1 = 3144134277;
197
+ let h2 = 1013904242;
198
+ let h3 = 2773480762;
199
+ let h4 = 1359893119;
200
+ let h5 = 2600822924;
201
+ let h6 = 528734635;
202
+ let h7 = 1541459225;
203
+ const w = new Uint32Array(64);
204
+ for (let offset = 0;offset < data.length; offset += 64) {
205
+ for (let index = 0;index < 16; index++) {
206
+ w[index] = view.getUint32(offset + index * 4);
207
+ }
208
+ for (let index = 16;index < 64; index++) {
209
+ const w15 = w[index - 15] ?? 0;
210
+ const w2 = w[index - 2] ?? 0;
211
+ const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ w15 >>> 3;
212
+ const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ w2 >>> 10;
213
+ w[index] = (w[index - 16] ?? 0) + s0 + (w[index - 7] ?? 0) + s1 >>> 0;
214
+ }
215
+ let a = h0;
216
+ let b = h1;
217
+ let c = h2;
218
+ let d = h3;
219
+ let e = h4;
220
+ let f = h5;
221
+ let g = h6;
222
+ let h = h7;
223
+ for (let index = 0;index < 64; index++) {
224
+ const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
225
+ const ch = e & f ^ ~e & g;
226
+ const temp1 = h + s1 + ch + (k[index] ?? 0) + (w[index] ?? 0) >>> 0;
227
+ const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
228
+ const maj = a & b ^ a & c ^ b & c;
229
+ const temp2 = s0 + maj >>> 0;
230
+ h = g;
231
+ g = f;
232
+ f = e;
233
+ e = d + temp1 >>> 0;
234
+ d = c;
235
+ c = b;
236
+ b = a;
237
+ a = temp1 + temp2 >>> 0;
238
+ }
239
+ h0 = h0 + a >>> 0;
240
+ h1 = h1 + b >>> 0;
241
+ h2 = h2 + c >>> 0;
242
+ h3 = h3 + d >>> 0;
243
+ h4 = h4 + e >>> 0;
244
+ h5 = h5 + f >>> 0;
245
+ h6 = h6 + g >>> 0;
246
+ h7 = h7 + h >>> 0;
247
+ }
248
+ const out = new Uint8Array(32);
249
+ const outView = new DataView(out.buffer);
250
+ outView.setUint32(0, h0);
251
+ outView.setUint32(4, h1);
252
+ outView.setUint32(8, h2);
253
+ outView.setUint32(12, h3);
254
+ outView.setUint32(16, h4);
255
+ outView.setUint32(20, h5);
256
+ outView.setUint32(24, h6);
257
+ outView.setUint32(28, h7);
258
+ return out;
259
+ }
260
+ function rotr(value, bits) {
261
+ return value >>> bits | value << 32 - bits;
262
+ }
263
+ function toHex(bytes) {
264
+ let hex = "";
265
+ for (let index = 0;index < bytes.length; index++) {
266
+ const byte = bytes[index] ?? 0;
267
+ hex += HEX[byte >>> 4];
268
+ hex += HEX[byte & 15];
269
+ }
270
+ return hex;
271
+ }
272
+
273
+ // src/contracts/catalog/words.ts
274
+ var words;
275
+ function reservedWords() {
276
+ words ??= new Set([
277
+ "all",
278
+ "analyse",
279
+ "analyze",
280
+ "and",
281
+ "any",
282
+ "array",
283
+ "as",
284
+ "asc",
285
+ "asymmetric",
286
+ "authorization",
287
+ "binary",
288
+ "both",
289
+ "case",
290
+ "cast",
291
+ "check",
292
+ "collate",
293
+ "collation",
294
+ "column",
295
+ "concurrently",
296
+ "constraint",
297
+ "create",
298
+ "cross",
299
+ "current_catalog",
300
+ "current_date",
301
+ "current_role",
302
+ "current_schema",
303
+ "current_time",
304
+ "current_timestamp",
305
+ "current_user",
306
+ "default",
307
+ "deferrable",
308
+ "desc",
309
+ "distinct",
310
+ "do",
311
+ "else",
312
+ "end",
313
+ "except",
314
+ "false",
315
+ "fetch",
316
+ "for",
317
+ "foreign",
318
+ "freeze",
319
+ "from",
320
+ "full",
321
+ "grant",
322
+ "group",
323
+ "having",
324
+ "ilike",
325
+ "in",
326
+ "initially",
327
+ "inner",
328
+ "intersect",
329
+ "into",
330
+ "is",
331
+ "isnull",
332
+ "join",
333
+ "lateral",
334
+ "leading",
335
+ "left",
336
+ "like",
337
+ "limit",
338
+ "localtime",
339
+ "localtimestamp",
340
+ "natural",
341
+ "not",
342
+ "notnull",
343
+ "null",
344
+ "offset",
345
+ "on",
346
+ "only",
347
+ "or",
348
+ "order",
349
+ "outer",
350
+ "overlaps",
351
+ "placing",
352
+ "primary",
353
+ "references",
354
+ "returning",
355
+ "right",
356
+ "select",
357
+ "session_user",
358
+ "similar",
359
+ "some",
360
+ "symmetric",
361
+ "system_user",
362
+ "table",
363
+ "tablesample",
364
+ "then",
365
+ "to",
366
+ "trailing",
367
+ "true",
368
+ "union",
369
+ "unique",
370
+ "user",
371
+ "using",
372
+ "variadic",
373
+ "verbose",
374
+ "when",
375
+ "where",
376
+ "window",
377
+ "with"
378
+ ]);
379
+ return words;
380
+ }
381
+
382
+ // src/contracts/catalog/identifier.ts
383
+ var POSTGRES_IDENTIFIER_MAX_BYTES2 = 63;
384
+ var SUFFIX_HEX = 8;
385
+ var SUFFIX_BYTES = SUFFIX_HEX + 1;
386
+ var NAME_TAG = {
387
+ unique: "key",
388
+ foreignKey: "fkey",
389
+ check: "check",
390
+ index: "idx"
391
+ };
392
+ function isReservedIdentifier2(name) {
393
+ return reservedWords().has(name.toLowerCase());
394
+ }
395
+ function assertIdentifier2(name, role, limit = POSTGRES_IDENTIFIER_MAX_BYTES2) {
396
+ assertLimit(limit);
397
+ assertIdentifierText(name, role);
398
+ if (utf8ByteLength2(name) > limit) {
399
+ catalogError2("OKM1122", `${role} ${name} is ${String(utf8ByteLength2(name))} bytes. The limit is ${String(limit)}.`);
400
+ }
401
+ if (isReservedIdentifier2(name)) {
402
+ catalogError2("OKM1122", `${role} ${name} is a reserved word.`);
403
+ }
404
+ }
405
+ function fitIdentifier2(name, limit = POSTGRES_IDENTIFIER_MAX_BYTES2) {
406
+ assertLimit(limit);
407
+ assertIdentifierText(name, "identifier");
408
+ if (utf8ByteLength2(name) <= limit) {
409
+ return name;
410
+ }
411
+ const suffix = `_${sha2562(name).slice(0, SUFFIX_HEX)}`;
412
+ const budget = limit - SUFFIX_BYTES;
413
+ return `${truncateUtf8(name, budget)}${suffix}`;
414
+ }
415
+ function deterministicName2(input) {
416
+ const limit = input.limit ?? POSTGRES_IDENTIFIER_MAX_BYTES2;
417
+ assertIdentifier2(input.parent, "parent", limit);
418
+ if (input.purpose === "primaryKey") {
419
+ return fitIdentifier2(`${input.parent}_pkey`, limit);
420
+ }
421
+ const nameKey = input.nameKey ?? "";
422
+ assertIdentifierText(nameKey, "name key");
423
+ return fitIdentifier2(`${input.parent}_${nameKey}_${NAME_TAG[input.purpose]}`, limit);
424
+ }
425
+ function assertStoredText(value, role) {
426
+ if (value.includes("\x00") || hasControl(value)) {
427
+ catalogError2("OKM1122", `${role} contains a control character.`);
428
+ }
429
+ }
430
+ function assertIdentifierText(name, role) {
431
+ if (name.length === 0) {
432
+ catalogError2("OKM1122", `${role} is empty.`);
433
+ }
434
+ if (name.includes("\x00")) {
435
+ catalogError2("OKM1122", `${role} ${name} contains NUL.`);
436
+ }
437
+ if (hasControl(name)) {
438
+ catalogError2("OKM1122", `${role} ${name} contains a control character.`);
439
+ }
440
+ }
441
+ function assertLimit(limit) {
442
+ if (!Number.isSafeInteger(limit) || limit < SUFFIX_BYTES) {
443
+ catalogError2("OKM1122", `Identifier limit is ${String(limit)} bytes. It must be at least ${String(SUFFIX_BYTES)} so a fitted name can keep its hash suffix.`);
444
+ }
445
+ }
446
+ function hasControl(value) {
447
+ for (let index = 0;index < value.length; index++) {
448
+ const code = value.charCodeAt(index);
449
+ if (code < 32 || code === 127 || code >= 128 && code <= 159) {
450
+ return true;
451
+ }
452
+ }
453
+ return false;
454
+ }
455
+
456
+ export { utf8ByteLength2, sha2562, POSTGRES_IDENTIFIER_MAX_BYTES2, isReservedIdentifier2, assertIdentifier2, fitIdentifier2, deterministicName2, assertStoredText };
@@ -0,0 +1,18 @@
1
+ import {
2
+ DriverError2,
3
+ cancelled2,
4
+ timedOut2,
5
+ outcomeUnknown2,
6
+ acquireTimeout2,
7
+ errorField2,
8
+ mapDriverError2
9
+ } from "./hd293j9g.js";
10
+ export {
11
+ DriverError2 as DriverError,
12
+ acquireTimeout2 as acquireTimeout,
13
+ cancelled2 as cancelled,
14
+ errorField2 as errorField,
15
+ mapDriverError2 as mapDriverError,
16
+ outcomeUnknown2 as outcomeUnknown,
17
+ timedOut2 as timedOut
18
+ };
@@ -0,0 +1,40 @@
1
+ // src/contracts/connection.ts
2
+ function isConnectionSqlstate(sqlstate) {
3
+ return sqlstate.startsWith("08") || sqlstate === "53300" || sqlstate === "57P01" || sqlstate === "57P02" || sqlstate === "57P03";
4
+ }
5
+ function isConnectionErrno(code) {
6
+ switch (code) {
7
+ case "ECONNRESET":
8
+ case "ECONNREFUSED":
9
+ case "EPIPE":
10
+ case "ENOTFOUND":
11
+ case "ETIMEDOUT":
12
+ case "EHOSTUNREACH":
13
+ case "ENETUNREACH":
14
+ case "EAI_AGAIN":
15
+ case "CONNECTION_CLOSED":
16
+ case "CONNECTION_ENDED":
17
+ case "CONNECTION_DESTROYED":
18
+ return true;
19
+ default:
20
+ return false;
21
+ }
22
+ }
23
+ function isConnectionFailure(error) {
24
+ const sqlstate = readCode(error, "sqlstate") ?? readCode(error, "code");
25
+ if (sqlstate !== undefined && (isConnectionSqlstate(sqlstate) || isConnectionErrno(sqlstate))) {
26
+ return true;
27
+ }
28
+ if (!(error instanceof Error))
29
+ return false;
30
+ const message = error.message;
31
+ return message.includes("ECONNREFUSED") || message.includes("ECONNRESET") || message.includes("CONNECTION_CLOSED") || message.includes("terminating connection") || message.includes("The pool is closed");
32
+ }
33
+ function readCode(error, key) {
34
+ if (typeof error !== "object" || error === null || !(key in error))
35
+ return;
36
+ const value = Reflect.get(error, key);
37
+ return typeof value === "string" && value.length > 0 ? value : undefined;
38
+ }
39
+
40
+ export { isConnectionSqlstate, isConnectionFailure };
@@ -0,0 +1,79 @@
1
+ import {
2
+ OkmError2
3
+ } from "./ycwz42az.js";
4
+
5
+ // src/runtime/drift-detail.ts
6
+ function driftVerdict(codeHash, recordedHash, migrations) {
7
+ const codeAt = indexOfHash(migrations, codeHash);
8
+ const recordedAt = indexOfHash(migrations, recordedHash);
9
+ if (codeAt < 0 || recordedAt < 0 || recordedAt < codeAt)
10
+ return "behind";
11
+ if (recordedAt === codeAt)
12
+ return "ok";
13
+ for (let index = codeAt + 1;index <= recordedAt; index += 1) {
14
+ if (migrations[index]?.expand !== true)
15
+ return "contract";
16
+ }
17
+ return "ok";
18
+ }
19
+ async function assertDrift(pool, codeHash, recordedHash, options) {
20
+ let rows;
21
+ try {
22
+ const result = await pool.execute("select migration_id, class, catalog_hash from okm_history order by migration_id, step_index", undefined, options);
23
+ rows = result.rows;
24
+ } catch (error) {
25
+ throw behind(error);
26
+ }
27
+ const verdict = driftVerdict(codeHash, recordedHash, groupMigrations(rows));
28
+ if (verdict === "ok")
29
+ return;
30
+ if (verdict === "contract") {
31
+ throw new OkmError2("OKM1520", "The database is ahead of the code by a contract migration.", {
32
+ fix: {
33
+ summary: "Roll the application forward, or repair the database. A contract step is not compatible with this code."
34
+ }
35
+ });
36
+ }
37
+ throw behind(undefined);
38
+ }
39
+ function indexOfHash(migrations, hash) {
40
+ let found = -1;
41
+ for (let index = 0;index < migrations.length; index += 1) {
42
+ if (migrations[index]?.catalogHash === hash)
43
+ found = index;
44
+ }
45
+ return found;
46
+ }
47
+ function groupMigrations(rows) {
48
+ const grouped = [];
49
+ for (const row of rows) {
50
+ const id = row[0];
51
+ const stepClass = row[1];
52
+ const hash = row[2];
53
+ if (id == null || stepClass == null || hash == null)
54
+ continue;
55
+ const expand = stepClass === "expand";
56
+ const last = grouped.at(-1);
57
+ if (last !== undefined && last.id === id) {
58
+ grouped[grouped.length - 1] = {
59
+ id,
60
+ catalogHash: hash,
61
+ expand: last.expand && expand
62
+ };
63
+ continue;
64
+ }
65
+ grouped.push({ id, catalogHash: hash, expand });
66
+ }
67
+ return grouped;
68
+ }
69
+ function behind(cause) {
70
+ return new OkmError2("OKM1520", "The database is behind the code.", {
71
+ ...cause === undefined ? {} : { cause },
72
+ fix: {
73
+ summary: "Inspect the diff and repair the database, or generate a migration that matches the drift."
74
+ }
75
+ });
76
+ }
77
+ export {
78
+ assertDrift
79
+ };