okmodel 0.6.0 → 0.7.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 (157) hide show
  1. package/README.md +100 -1131
  2. package/dist/adapters/capabilities.d.ts +3 -0
  3. package/dist/adapters/failure.d.ts +13 -2
  4. package/dist/adapters/lazy-errors.d.ts +22 -0
  5. package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
  6. package/dist/adapters/pg/bunsql.d.ts +14 -1
  7. package/dist/adapters/pg/cursor.d.ts +17 -0
  8. package/dist/adapters/pg/no-inflight-timeout.d.ts +11 -8
  9. package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
  10. package/dist/adapters/pg/nodepostgres.d.ts +12 -0
  11. package/dist/adapters/pg/pglite-wire.d.ts +24 -0
  12. package/dist/adapters/pg/pglite.d.ts +10 -0
  13. package/dist/adapters/pg/postgres-extra.d.ts +27 -11
  14. package/dist/adapters/pg/reserved.d.ts +42 -0
  15. package/dist/adapters/pg/session.d.ts +0 -18
  16. package/dist/contracts/connection.d.ts +7 -6
  17. package/dist/dialects/pg/floor.d.ts +68 -0
  18. package/dist/dialects/pg/index.d.ts +6 -1
  19. package/dist/dialects/pg/index.js +49 -159
  20. package/dist/dialects/pg/keys.d.ts +11 -8
  21. package/dist/dialects/pg/model.d.ts +40 -0
  22. package/dist/dialects/pg/morph.d.ts +43 -0
  23. package/dist/dialects/pg/operator-fit.d.ts +2 -2
  24. package/dist/dialects/pg/operators.d.ts +14 -7
  25. package/dist/dialects/pg/ops/bucket.d.ts +65 -0
  26. package/dist/dialects/pg/ops/inc.d.ts +2 -2
  27. package/dist/dialects/pg/ops/matches.d.ts +9 -12
  28. package/dist/dialects/pg/ops/relevance.d.ts +13 -0
  29. package/dist/dialects/pg/ops/search-query.d.ts +22 -0
  30. package/dist/dialects/pg/ops/window.d.ts +103 -0
  31. package/dist/dialects/pg/preset.d.ts +1 -1
  32. package/dist/dialects/pg/relations.d.ts +100 -3
  33. package/dist/dialects/pg/schema.d.ts +31 -3
  34. package/dist/dialects/pg/view/index.js +1 -1
  35. package/dist/runtime/aggregate.d.ts +8 -2
  36. package/dist/runtime/bucket-group.d.ts +70 -0
  37. package/dist/runtime/conflict.d.ts +22 -4
  38. package/dist/runtime/include.d.ts +0 -8
  39. package/dist/runtime/inflight.d.ts +1 -1
  40. package/dist/runtime/page.d.ts +4 -1
  41. package/dist/runtime/pg/bun.js +12 -6
  42. package/dist/runtime/pg/pg.js +5 -5
  43. package/dist/runtime/pg/pglite.d.ts +1 -0
  44. package/dist/runtime/pg/pglite.js +9 -9
  45. package/dist/runtime/pg/postgresjs.js +5 -5
  46. package/dist/runtime/plan.d.ts +95 -5
  47. package/dist/runtime/read-stream.d.ts +13 -16
  48. package/dist/runtime/result-name.d.ts +17 -0
  49. package/dist/runtime/server-check.d.ts +3 -3
  50. package/dist/runtime/sort-bind.d.ts +21 -0
  51. package/dist/runtime/sort.d.ts +56 -0
  52. package/dist/runtime/sync.d.ts +70 -0
  53. package/dist/runtime/tenancy/index.js +7 -5
  54. package/dist/runtime/text-search.d.ts +20 -0
  55. package/dist/runtime/traits/index.d.ts +80 -0
  56. package/dist/runtime/traits/index.js +175 -11
  57. package/dist/runtime/tree.d.ts +38 -0
  58. package/dist/runtime/types.d.ts +218 -22
  59. package/dist/runtime/validate/index.js +2 -2
  60. package/dist/runtime/version.d.ts +39 -0
  61. package/dist/runtime/window.d.ts +21 -0
  62. package/dist/runtime/write.d.ts +54 -2
  63. package/dist/shared/{wkme6tep.js → 14vx95q4.js} +8 -16
  64. package/dist/shared/1est4ezg.js +313 -0
  65. package/dist/shared/{4az561fn.js → 1qa0qajz.js} +8 -23
  66. package/dist/shared/{2cg3wnxc.js → 1w508jbr.js} +593 -130
  67. package/dist/shared/2c13q96h.js +18 -0
  68. package/dist/shared/{b4v57v3x.js → 2d3xq4ps.js} +2 -2
  69. package/dist/shared/{1nw1f3vs.js → 2shdbn8q.js} +7 -7
  70. package/dist/shared/3v7t1yrv.js +208 -0
  71. package/dist/shared/{x3jc53kg.js → 5e3tf63j.js} +2 -2
  72. package/dist/shared/5fe3kbsh.js +10 -0
  73. package/dist/shared/5v3xf80k.js +37 -0
  74. package/dist/shared/{c58secgj.js → 63qtkrca.js} +38 -4
  75. package/dist/shared/{2z7wv5tj.js → 67txcrcw.js} +55 -34
  76. package/dist/shared/79dt02vc.js +12 -0
  77. package/dist/shared/{8x72s86k.js → 7k9grvf6.js} +10 -4
  78. package/dist/shared/7kms6fvj.js +20 -0
  79. package/dist/shared/7mnme5tn.js +8 -0
  80. package/dist/shared/7n7ddwt4.js +6 -0
  81. package/dist/shared/{5j36z8dn.js → 81ebdx9p.js} +39 -70
  82. package/dist/shared/{knmes2kh.js → 8skf0cam.js} +1 -1
  83. package/dist/shared/9a4ae4p8.js +31 -0
  84. package/dist/shared/9y3mmmh1.js +436 -0
  85. package/dist/shared/ab9gmbwy.js +213 -0
  86. package/dist/shared/{f0f1n281.js → ax7qv55k.js} +2 -2
  87. package/dist/shared/{g90m9b0g.js → aytqh5y2.js} +6 -5
  88. package/dist/shared/{vjpnzwjz.js → b5pftnn2.js} +1 -1
  89. package/dist/shared/{ag4c7516.js → b76b8d95.js} +2 -2
  90. package/dist/shared/{vmfkhszw.js → bg3rym3g.js} +33 -26
  91. package/dist/shared/{mb2ycs1p.js → bm22fvzr.js} +15 -15
  92. package/dist/shared/{q3j1tq7a.js → bz84tkzm.js} +148 -23
  93. package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
  94. package/dist/shared/cn957f8d.js +179 -0
  95. package/dist/shared/{gwn6v667.js → cnkky55j.js} +25 -14
  96. package/dist/shared/{ys0xzyaj.js → dkxgzaqd.js} +224 -19
  97. package/dist/shared/dzj09cye.js +10 -0
  98. package/dist/shared/exn3sd90.js +359 -0
  99. package/dist/shared/g6evj1j3.js +66 -0
  100. package/dist/shared/ga9j92qj.js +25 -0
  101. package/dist/shared/{t3g0k88x.js → gs74dbj5.js} +16 -12
  102. package/dist/shared/gzaveazc.js +285 -0
  103. package/dist/shared/{2jd1sn0e.js → hyh73qk6.js} +1 -1
  104. package/dist/shared/{r1fdd0f6.js → je4axnm8.js} +5 -2
  105. package/dist/shared/{1f0xa3cb.js → jvd0mqag.js} +3 -3
  106. package/dist/shared/jznfax0y.js +155 -0
  107. package/dist/shared/{cgbamx3e.js → kb2sdhfb.js} +7 -4
  108. package/dist/shared/{wt5rzv1h.js → kr0jzbw2.js} +5 -5
  109. package/dist/shared/{p6bjzq9q.js → ktz42yez.js} +12 -4
  110. package/dist/shared/{p248q79y.js → m6p12kbr.js} +2 -2
  111. package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
  112. package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
  113. package/dist/shared/{929h19xp.js → mtaszv5a.js} +40 -10
  114. package/dist/shared/{b3awxn7h.js → n816peh1.js} +1 -1
  115. package/dist/shared/nbw1z4yd.js +18 -0
  116. package/dist/shared/{nx9hh281.js → p6qc5gcp.js} +12 -11
  117. package/dist/shared/{pjr6xrm5.js → pbp1ss85.js} +20 -17
  118. package/dist/shared/pt94kz7f.js +6 -0
  119. package/dist/shared/q5c6ngn3.js +13 -0
  120. package/dist/shared/{xq0mvhts.js → rs73fca9.js} +4 -4
  121. package/dist/shared/{r11n8grd.js → sfz1ksn6.js} +7 -4
  122. package/dist/shared/{wynzeggs.js → svncdeh5.js} +6 -6
  123. package/dist/shared/{j60w0dvr.js → tbrvgw6z.js} +57 -38
  124. package/dist/shared/te5as7z7.js +622 -0
  125. package/dist/shared/{ttmg09vd.js → tsvww22q.js} +1 -1
  126. package/dist/shared/{y2t3jktd.js → ttsqgp4p.js} +19 -12
  127. package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
  128. package/dist/shared/{sbdme3vy.js → vb6qfyve.js} +60 -10
  129. package/dist/shared/{5d8t84hg.js → vczs8gd4.js} +14 -14
  130. package/dist/shared/{5yv4k6a6.js → vqrjpcqn.js} +144 -2
  131. package/dist/shared/{3fqwmr09.js → w72kgg4q.js} +4 -4
  132. package/dist/shared/{1z04fa85.js → w79hsckn.js} +12 -57
  133. package/dist/shared/{09p049xa.js → wa07eas9.js} +42 -14
  134. package/dist/shared/{32cnm7kn.js → x933k9a3.js} +74 -38
  135. package/dist/shared/{n076ydsc.js → xhfsfkgk.js} +62 -28
  136. package/dist/shared/xjk7hnn5.js +272 -0
  137. package/dist/shared/{hazqqecq.js → xnxsed62.js} +50 -21
  138. package/dist/shared/y6njgyda.js +249 -0
  139. package/dist/shared/{8etn7d8w.js → z7s6fpxv.js} +1 -1
  140. package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
  141. package/dist/shared/zm0ptry0.js +40 -0
  142. package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
  143. package/dist/shared/zp9fmend.js +145 -0
  144. package/dist/tooling/cli.js +11 -11
  145. package/dist/tooling/migrate/engine.d.ts +3 -2
  146. package/dist/tooling/migrate/index.js +7 -7
  147. package/dist/tooling/testing/index.js +1 -1
  148. package/package.json +4 -2
  149. package/dist/shared/3qnhc7w5.js +0 -38
  150. package/dist/shared/7m88x3e9.js +0 -45
  151. package/dist/shared/8dqhth8c.js +0 -12
  152. package/dist/shared/d5azex6s.js +0 -6
  153. package/dist/shared/j3rkk835.js +0 -99
  154. package/dist/shared/k68eedmy.js +0 -85
  155. package/dist/shared/venqrjna.js +0 -216
  156. package/dist/shared/wxr8cwns.js +0 -6
  157. package/dist/shared/zm0mafk4.js +0 -92
@@ -3,16 +3,16 @@ import {
3
3
  } from "./n4jqhpqz.js";
4
4
  import {
5
5
  refuseUncancellableTimeout
6
- } from "./b4v57v3x.js";
6
+ } from "./2d3xq4ps.js";
7
7
  import {
8
8
  withHttp,
9
9
  settleCall
10
- } from "./j60w0dvr.js";
10
+ } from "./tbrvgw6z.js";
11
11
  import {
12
12
  rejectKeys,
13
13
  isRecord,
14
- fail
15
- } from "./2z7wv5tj.js";
14
+ fail2
15
+ } from "./67txcrcw.js";
16
16
  import {
17
17
  OkmError2
18
18
  } from "./52szzakm.js";
@@ -26,29 +26,29 @@ async function batch(session, ops, options, replica) {
26
26
  }));
27
27
  }
28
28
  if (!Array.isArray(ops))
29
- fail("OKM1121", "batch expects a list of write operations.");
29
+ fail2("OKM1121", "batch expects a list of write operations.");
30
30
  const record = options ?? {};
31
31
  if (!isRecord(record))
32
- fail("OKM1121", "batch options must be an object.");
32
+ fail2("OKM1121", "batch options must be an object.");
33
33
  rejectKeys(record, ["signal", "timeout"], "batch");
34
34
  await refuseUncancellableTimeout(session.pool, typeof record["timeout"] === "number" ? record["timeout"] : undefined);
35
35
  for (const op of ops) {
36
36
  if (typeof op === "object" && op !== null && op["~refresh"] === true) {
37
- fail("OKM1121", "batch does not take refresh(). Await refresh() on its own. It is one statement and cannot share the batch.");
37
+ fail2("OKM1121", "batch does not take refresh(). Await refresh() on its own. It is one statement and cannot share the batch.");
38
38
  }
39
39
  }
40
40
  const prepared = [];
41
41
  for (const op of ops) {
42
42
  const plan = typeof op === "object" && op !== null ? op["~plan"] : undefined;
43
43
  if (plan === undefined) {
44
- fail("OKM1121", "batch takes write operations: insert, update, delete, and archive. Pass them without awaiting.");
44
+ fail2("OKM1121", "batch takes write operations: insert, update, delete, and archive. Pass them without awaiting.");
45
45
  }
46
46
  const item = await plan();
47
47
  if (item.checked === "parent") {
48
48
  throw new OkmError2("OKM1705", "batch does not take an update that sets a path column. The parent is checked in the statement, and a batch cannot report that after it commits. Use update({ where, set }) inside tx().", { fix: { summary: "Use update({ where, set }) inside tx()." } });
49
49
  }
50
50
  if (item.checked !== undefined) {
51
- fail("OKM1121", item.checked === "restore" ? "batch does not take restore: it is refused while its parent is archived, and a batch cannot report that after it commits. Use tx()." : "batch does not take a write with expect: the count is checked after the statement ran, and a batch cannot report that after it commits. Use tx().");
51
+ fail2("OKM1121", item.checked === "restore" ? "batch does not take restore: it is refused while its parent is archived, and a batch cannot report that after it commits. Use tx()." : "batch does not take a write with expect: the count is checked after the statement ran, and a batch cannot report that after it commits. Use tx().");
52
52
  }
53
53
  prepared.push(item);
54
54
  }
@@ -73,11 +73,61 @@ async function run(session, prepared, options) {
73
73
  } catch (error) {
74
74
  throw at(error, starts);
75
75
  }
76
+ const extra = await recover(session, prepared, results, starts, options);
76
77
  return prepared.map((item, index) => {
77
78
  const from = starts[index] ?? 0;
78
- return item.finish(results.slice(from, from + item.statements.length));
79
+ const slice = results.slice(from, from + item.statements.length);
80
+ const more = extra.get(index);
81
+ return item.finish(more === undefined ? slice : slice.concat(more));
79
82
  });
80
83
  }
84
+ async function recover(session, prepared, results, starts, options) {
85
+ const pending = [];
86
+ for (let index = 0;index < prepared.length; index += 1) {
87
+ const item = prepared[index];
88
+ if (item?.follow === undefined)
89
+ continue;
90
+ const from = starts[index] ?? 0;
91
+ const more = item.follow(results.slice(from, from + item.statements.length));
92
+ if (more.length === 0)
93
+ continue;
94
+ pending.push({ index, statements: more });
95
+ }
96
+ const found = new Map;
97
+ if (pending.length === 0)
98
+ return found;
99
+ const flat = [];
100
+ const extraStarts = [];
101
+ for (const item of pending) {
102
+ extraStarts.push(flat.length);
103
+ flat.push(...item.statements);
104
+ }
105
+ let ran;
106
+ try {
107
+ ran = await runWrite(session, flat, call(options), true);
108
+ } catch (error) {
109
+ throw mapExtra(error, pending, extraStarts);
110
+ }
111
+ for (let index = 0;index < pending.length; index += 1) {
112
+ const item = pending[index];
113
+ if (item === undefined)
114
+ continue;
115
+ const from = extraStarts[index] ?? 0;
116
+ found.set(item.index, ran.slice(from, extraStarts[index + 1] ?? ran.length));
117
+ }
118
+ return found;
119
+ }
120
+ function mapExtra(error, pending, extraStarts) {
121
+ const failed = error?.batchIndex;
122
+ const move = error?.at;
123
+ if (typeof failed !== "number" || typeof move !== "function")
124
+ return error;
125
+ let slot = 0;
126
+ while (slot + 1 < extraStarts.length && (extraStarts[slot + 1] ?? Infinity) <= failed)
127
+ slot += 1;
128
+ const op = pending[slot]?.index ?? slot;
129
+ return op === failed ? error : move.call(error, op);
130
+ }
81
131
  function call(options) {
82
132
  const { signal, timeout } = options;
83
133
  if (signal === undefined && timeout === undefined)
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  refuseUncancellableTimeout
3
- } from "./b4v57v3x.js";
3
+ } from "./2d3xq4ps.js";
4
4
  import {
5
5
  isConnectionLost
6
- } from "./gwn6v667.js";
6
+ } from "./cnkky55j.js";
7
7
  import {
8
8
  openClient,
9
9
  withHttp,
10
10
  settleCall
11
- } from "./j60w0dvr.js";
11
+ } from "./tbrvgw6z.js";
12
12
  import {
13
13
  rejectKeys,
14
14
  isRecord,
15
- fail
16
- } from "./2z7wv5tj.js";
15
+ fail2
16
+ } from "./67txcrcw.js";
17
17
  import {
18
18
  OkmError2
19
19
  } from "./52szzakm.js";
@@ -96,15 +96,15 @@ class Frame {
96
96
  }
97
97
  async function tx(session, args) {
98
98
  if (typeof args[0] === "function" && args.length > 1) {
99
- fail("OKM1120", "options go first: tx(options, fn).");
99
+ fail2("OKM1120", "options go first: tx(options, fn).");
100
100
  }
101
101
  const fn = typeof args[0] === "function" ? args[0] : args[1];
102
102
  const given = typeof args[0] === "function" ? {} : args[0] ?? {};
103
103
  try {
104
104
  if (typeof fn !== "function")
105
- fail("OKM1121", "tx expects a callback: tx(fn) or tx(options, fn).");
105
+ fail2("OKM1121", "tx expects a callback: tx(fn) or tx(options, fn).");
106
106
  if (!isRecord(given))
107
- fail("OKM1121", "tx options must be an object.");
107
+ fail2("OKM1121", "tx options must be an object.");
108
108
  rejectKeys(given, ["isolation", "retry", "signal", "timeout"], "tx");
109
109
  const options = given;
110
110
  check(options);
@@ -123,14 +123,14 @@ function failWith(session, error) {
123
123
  }
124
124
  function check(options) {
125
125
  if (options.isolation !== undefined && !Object.hasOwn(BEGIN, options.isolation)) {
126
- fail("OKM1120", `isolation must be one of: ${Object.keys(BEGIN).join(", ")}.`);
126
+ fail2("OKM1120", `isolation must be one of: ${Object.keys(BEGIN).join(", ")}.`);
127
127
  }
128
128
  const { retry, timeout } = options;
129
129
  if (retry !== undefined && (!Number.isInteger(retry) || retry < 0)) {
130
- fail("OKM1121", "retry must be an integer from 0 up.");
130
+ fail2("OKM1121", "retry must be an integer from 0 up.");
131
131
  }
132
132
  if (timeout !== undefined && (typeof timeout !== "number" || !(timeout > 0))) {
133
- fail("OKM1121", "timeout must be a number of milliseconds above 0.");
133
+ fail2("OKM1121", "timeout must be a number of milliseconds above 0.");
134
134
  }
135
135
  }
136
136
  async function outer(session, fn, options) {
@@ -269,7 +269,7 @@ async function run(session, after, hear) {
269
269
  }
270
270
  async function nested(session, fn, options) {
271
271
  if (Object.keys(options).length > 0) {
272
- fail("OKM1121", "isolation, retry, timeout, and signal belong to the outermost tx(). A nested tx() is a savepoint on the same transaction.");
272
+ fail2("OKM1121", "isolation, retry, timeout, and signal belong to the outermost tx(). A nested tx() is a savepoint on the same transaction.");
273
273
  }
274
274
  const { state: frame, depth } = session.tx;
275
275
  frame.check();
@@ -347,7 +347,7 @@ function held(session, frame, after, depth) {
347
347
  extras: {
348
348
  afterCommit(callback) {
349
349
  if (typeof callback !== "function") {
350
- fail("OKM1121", "afterCommit expects a function.");
350
+ fail2("OKM1121", "afterCommit expects a function.");
351
351
  }
352
352
  frame.check();
353
353
  after.push(callback);
@@ -380,7 +380,7 @@ function lockKey(key) {
380
380
  }
381
381
  const fits = typeof key === "number" ? Number.isSafeInteger(key) : typeof key === "bigint" && key >= -(2n ** 63n) && key < 2n ** 63n;
382
382
  if (!fits)
383
- fail("OKM1121", "advisoryLock takes a string, a safe integer, or a bigint that fits in 64 bits.");
383
+ fail2("OKM1121", "advisoryLock takes a string, a safe integer, or a bigint that fits in 64 bits.");
384
384
  return ["select pg_advisory_xact_lock($1::bigint)", String(key)];
385
385
  }
386
386
  function callOf(options) {
@@ -1,11 +1,153 @@
1
1
  import {
2
- required
2
+ required,
3
+ openColumn
3
4
  } from "./ywr8hmey.js";
4
5
  import {
5
6
  definition,
6
7
  rejected
7
8
  } from "./tmbdywx0.js";
8
9
 
10
+ // src/dialects/pg/integer.ts
11
+ function smallint2() {
12
+ return required({
13
+ baseType: "smallint",
14
+ encode: (value) => integerToken(value, -32768, 32767, "smallint"),
15
+ decode: (wire) => decodeBounded(wire, -32768, 32767, "smallint"),
16
+ sqlForm: "raw"
17
+ });
18
+ }
19
+ function integer2() {
20
+ return required({
21
+ baseType: "integer",
22
+ encode: (value) => integerToken(value, -2147483648, 2147483647, "integer"),
23
+ decode: (wire) => decodeBounded(wire, -2147483648, 2147483647, "integer"),
24
+ sqlForm: "raw"
25
+ });
26
+ }
27
+ function bigint2(options) {
28
+ const mode = options?.as ?? "string";
29
+ if (mode === "number") {
30
+ return required({
31
+ baseType: "bigint",
32
+ encode: encodeBigintNumber,
33
+ decode: decodeBigintNumber,
34
+ sqlForm: "raw",
35
+ typeLabel: "number"
36
+ });
37
+ }
38
+ if (mode === "bigint") {
39
+ return required({
40
+ baseType: "bigint",
41
+ encode: encodeBigintValue,
42
+ decode: decodeBigintValue,
43
+ sqlForm: "raw",
44
+ typeLabel: "bigint"
45
+ });
46
+ }
47
+ if (mode !== "string") {
48
+ definition(`bigint as ${String(mode)} must be string, number, or bigint.`);
49
+ }
50
+ return required({
51
+ baseType: "bigint",
52
+ encode: encodeBigintString,
53
+ decode: decodeBigintString,
54
+ sqlForm: "raw"
55
+ });
56
+ }
57
+ function identity2(options) {
58
+ const mode = options?.as ?? "string";
59
+ if (mode === "number") {
60
+ return openColumn({
61
+ ...identityFlags(),
62
+ encode: encodeBigintNumber,
63
+ decode: decodeBigintNumber,
64
+ typeLabel: "number"
65
+ });
66
+ }
67
+ if (mode === "bigint") {
68
+ return openColumn({
69
+ ...identityFlags(),
70
+ encode: encodeBigintValue,
71
+ decode: decodeBigintValue,
72
+ typeLabel: "bigint"
73
+ });
74
+ }
75
+ if (mode !== "string") {
76
+ definition(`identity as ${String(mode)} must be string, number, or bigint.`);
77
+ }
78
+ return openColumn({
79
+ ...identityFlags(),
80
+ encode: encodeBigintString,
81
+ decode: decodeBigintString
82
+ });
83
+ }
84
+ function encodeBigintString(value) {
85
+ parseBigint(value);
86
+ return value;
87
+ }
88
+ function decodeBigintString(wire) {
89
+ return encodeBigintString(wire);
90
+ }
91
+ function encodeBigintNumber(value) {
92
+ if (!Number.isSafeInteger(value)) {
93
+ rejected(`bigint number ${String(value)} must be an integer from ${String(Number.MIN_SAFE_INTEGER)} to ${String(Number.MAX_SAFE_INTEGER)}.`);
94
+ }
95
+ return String(value);
96
+ }
97
+ function decodeBigintNumber(wire) {
98
+ const parsed = parseBigint(wire);
99
+ const value = Number(parsed);
100
+ if (!Number.isSafeInteger(value)) {
101
+ rejected(`bigint ${wire} must be an integer from ${String(Number.MIN_SAFE_INTEGER)} to ${String(Number.MAX_SAFE_INTEGER)} when as is number.`);
102
+ }
103
+ return value;
104
+ }
105
+ function encodeBigintValue(value) {
106
+ return value.toString();
107
+ }
108
+ function decodeBigintValue(wire) {
109
+ return parseBigint(wire);
110
+ }
111
+ function integerToken(value, min, max, role) {
112
+ if (!Number.isInteger(value) || value < min || value > max) {
113
+ rejected(`${role} ${String(value)} must be an integer from ${String(min)} to ${String(max)}.`);
114
+ }
115
+ return String(value);
116
+ }
117
+ function decodeBounded(wire, min, max, role) {
118
+ if (!integerText().test(wire)) {
119
+ rejected(`${role} ${wire} must be an integer, for example 0 or -12.`);
120
+ }
121
+ const value = Number(wire);
122
+ integerToken(value, min, max, role);
123
+ return value;
124
+ }
125
+ function identityFlags() {
126
+ return {
127
+ baseType: "bigint",
128
+ nullable: false,
129
+ hasDefault: true,
130
+ generated: false,
131
+ guarded: false,
132
+ hidden: false,
133
+ omitWrite: true,
134
+ sqlForm: "raw",
135
+ identity: { always: true },
136
+ primaryKey: true
137
+ };
138
+ }
139
+ function parseBigint(wire) {
140
+ if (!integerText().test(wire)) {
141
+ rejected(`bigint ${wire} must be an integer with no leading zeros, for example 0 or -12.`);
142
+ }
143
+ return BigInt(wire);
144
+ }
145
+ function integerText() {
146
+ integerPattern ??= /^-?(?:0|[1-9]\d*)$/;
147
+ return integerPattern;
148
+ }
149
+ var integerPattern;
150
+
9
151
  // src/dialects/pg/temporal.ts
10
152
  var TEMPORAL_MISSING = "Date and time codecs need the Temporal global. okmodel does not ship a polyfill. Use a runtime that provides Temporal, or assign a polyfill to globalThis.Temporal before using these columns.";
11
153
  function requireTemporal() {
@@ -222,4 +364,4 @@ function timed(name, precision) {
222
364
  return `${name}(${String(precision)})`;
223
365
  }
224
366
 
225
- export { encodeInstant, decodeInstant, encodeDate, decodeDate, timestamptz2, timestamp2, date2, time2, timetz2, interval2 };
367
+ export { smallint2, integer2, bigint2, identity2, encodeBigintString, decodeBigintString, integerToken, encodeInstant, decodeInstant, encodeDate, decodeDate, timestamptz2, timestamp2, date2, time2, timetz2, interval2 };
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  open2
3
- } from "./wkme6tep.js";
3
+ } from "./14vx95q4.js";
4
4
  import"./qq3899ht.js";
5
5
  import {
6
6
  createdOf,
7
7
  testing2
8
- } from "./8x72s86k.js";
8
+ } from "./7k9grvf6.js";
9
9
  import"./n442h54c.js";
10
10
  import {
11
11
  projectPath,
12
12
  loadConfig,
13
13
  loadSchema
14
- } from "./t3g0k88x.js";
14
+ } from "./gs74dbj5.js";
15
15
  import {
16
16
  sessionFailure,
17
17
  finishQuiet,
@@ -19,7 +19,7 @@ import {
19
19
  assertDirectConnection,
20
20
  assertStableBackend,
21
21
  selectTarget
22
- } from "./ttmg09vd.js";
22
+ } from "./tsvww22q.js";
23
23
  import"./9s0ypp87.js";
24
24
  import {
25
25
  OkmError2
@@ -1,16 +1,14 @@
1
1
  import {
2
- quoteIdent2,
3
2
  noticeBuffer,
4
- WireSession,
5
- cursorStream
6
- } from "./4az561fn.js";
3
+ WireSession
4
+ } from "./1qa0qajz.js";
7
5
  import {
8
6
  NODE_POSTGRES_CAPABILITIES,
9
7
  driverErrors,
10
8
  rejectClosed,
11
9
  mapFailure,
12
10
  runCall
13
- } from "./cgbamx3e.js";
11
+ } from "./kb2sdhfb.js";
14
12
 
15
13
  // src/adapters/pg/nodepostgres.ts
16
14
  import net from "node:net";
@@ -57,7 +55,7 @@ function open4(config) {
57
55
  counters.busy = Math.max(0, counters.busy - 1);
58
56
  }, inflight);
59
57
  const held = { pool, acquireMs, counters, notices, named, isClosed };
60
- const checkout = () => closed ? rejectClosed() : import("./zm0mafk4.js").then((mod) => mod.checkout(held));
58
+ const checkout = () => closed ? rejectClosed() : import("./zp9fmend.js").then((mod) => mod.checkout(held));
61
59
  return {
62
60
  capabilities: NODE_POSTGRES_CAPABILITIES,
63
61
  execute(text, params, options) {
@@ -89,10 +87,15 @@ function open4(config) {
89
87
  },
90
88
  reserve: () => checkout(),
91
89
  stream(text, params) {
92
- return stream(text, params);
90
+ return async function* () {
91
+ const { streamRows } = await import("./zp9fmend.js");
92
+ yield* streamRows(checkout, text, params);
93
+ }();
93
94
  },
94
95
  listen(channel, onNotify) {
95
- return listen(channel, onNotify);
96
+ if (closed)
97
+ return rejectClosed();
98
+ return import("./zp9fmend.js").then((mod) => mod.listen(held, channel, onNotify));
96
99
  },
97
100
  cancel() {
98
101
  for (const pending of inflight)
@@ -104,54 +107,6 @@ function open4(config) {
104
107
  await pool.end();
105
108
  }
106
109
  };
107
- function stream(text, params) {
108
- return async function* () {
109
- const connection = await checkout();
110
- try {
111
- yield* cursorStream((statement, values) => connection.execute(statement, values), text, params);
112
- } finally {
113
- await connection.release();
114
- }
115
- }();
116
- }
117
- async function listen(channel, onNotify) {
118
- if (closed)
119
- return rejectClosed();
120
- const client = await connectClient(pool, acquireMs, counters);
121
- counters.reserved += 1;
122
- const quoted = quoteIdent2(channel);
123
- const onNotification = (message) => {
124
- if (message.channel === channel)
125
- onNotify(message.payload ?? "");
126
- };
127
- client.on("notification", onNotification);
128
- let released = false;
129
- const release = (dead) => {
130
- if (released)
131
- return;
132
- released = true;
133
- client.removeListener("notification", onNotification);
134
- client.removeListener("error", release);
135
- counters.reserved = Math.max(0, counters.reserved - 1);
136
- client.release(Boolean(dead));
137
- };
138
- armDriverError(client, release);
139
- try {
140
- await client.query(`LISTEN ${quoted}`);
141
- } catch (error) {
142
- release(false);
143
- throw error;
144
- }
145
- return async () => {
146
- if (released)
147
- return;
148
- try {
149
- await client.query(`UNLISTEN ${quoted}`);
150
- } finally {
151
- release(false);
152
- }
153
- };
154
- }
155
110
  }
156
111
  function send(runner, text, params, named, client) {
157
112
  const query = {
@@ -236,4 +191,4 @@ function statsOf(counters, size) {
236
191
  };
237
192
  }
238
193
 
239
- export { open4, send, connectClient };
194
+ export { armDriverError, open4, send, connectClient };
@@ -2,31 +2,32 @@ import {
2
2
  parseCatalog2
3
3
  } from "./qq3899ht.js";
4
4
  import"./n442h54c.js";
5
- import"./wkme6tep.js";
5
+ import"./cm3w0ywp.js";
6
+ import"./14vx95q4.js";
6
7
  import {
7
8
  watchReserved2
8
- } from "./q3j1tq7a.js";
9
+ } from "./bz84tkzm.js";
9
10
  import {
10
11
  ensureMigrationTables2
11
- } from "./nx9hh281.js";
12
+ } from "./p6qc5gcp.js";
12
13
  import {
13
14
  sealViews,
14
15
  catalogQuery2,
15
16
  managedRoleOptions2
16
- } from "./f0f1n281.js";
17
+ } from "./ax7qv55k.js";
17
18
  import {
18
19
  assumeRole,
19
20
  grantSchema,
20
21
  assertSchemaUsageLanded,
21
22
  catalogsEqual,
22
23
  snapshotDifference
23
- } from "./p248q79y.js";
24
+ } from "./m6p12kbr.js";
24
25
  import {
25
26
  roleExists
26
- } from "./knmes2kh.js";
27
+ } from "./8skf0cam.js";
27
28
  import {
28
29
  introspectSchema
29
- } from "./vjpnzwjz.js";
30
+ } from "./b5pftnn2.js";
30
31
  import {
31
32
  projectPath,
32
33
  loadMigrations,
@@ -35,7 +36,7 @@ import {
35
36
  hasError,
36
37
  lintRefusal,
37
38
  openProject
38
- } from "./t3g0k88x.js";
39
+ } from "./gs74dbj5.js";
39
40
  import {
40
41
  sqlStatements,
41
42
  transactionControl,
@@ -50,10 +51,10 @@ import {
50
51
  assertDirectConnection,
51
52
  assertStableBackend,
52
53
  selectTarget
53
- } from "./ttmg09vd.js";
54
+ } from "./tsvww22q.js";
54
55
  import {
55
56
  isConnectionLost
56
- } from "./gwn6v667.js";
57
+ } from "./cnkky55j.js";
57
58
  import {
58
59
  quoteIdent
59
60
  } from "./9s0ypp87.js";
@@ -151,12 +152,18 @@ async function inCheckTransaction(url, scratch, config, allowPooler, run) {
151
152
  onnotice: () => {}
152
153
  });
153
154
  const reserved = await sql.reserve();
154
- const lost = { on: false };
155
+ const lost = { on: false, stop: () => {
156
+ return;
157
+ } };
155
158
  watchReserved2(reserved, lost);
156
159
  refuseWhenLost(reserved, lost);
157
160
  let open = false;
158
161
  let failure;
159
162
  let value;
163
+ let created = false;
164
+ let sawCommit = false;
165
+ let rolledBack = false;
166
+ let xid = "";
160
167
  try {
161
168
  await assertStableBackend(async () => {
162
169
  const rows = await reserved.unsafe("select pg_backend_pid()::text as pid");
@@ -165,8 +172,9 @@ async function inCheckTransaction(url, scratch, config, allowPooler, run) {
165
172
  }, allowPooler);
166
173
  await reserved.unsafe("begin");
167
174
  open = true;
168
- const xid = await readXid(reserved);
175
+ xid = await readXid(reserved);
169
176
  await reserved.unsafe(`create schema ${quoteIdent(scratch)}`);
177
+ created = true;
170
178
  await reserved.unsafe(`set local search_path to ${quoteIdent(scratch)}`);
171
179
  await setLocalTimeout(reserved, "lock_timeout", config.timeouts?.lock);
172
180
  await setLocalTimeout(reserved, "statement_timeout", config.timeouts?.statement);
@@ -178,21 +186,36 @@ async function inCheckTransaction(url, scratch, config, allowPooler, run) {
178
186
  lost.on = true;
179
187
  return;
180
188
  });
181
- if (!lost.on && after !== xid)
189
+ if (!lost.on && after !== xid) {
190
+ sawCommit = true;
182
191
  throw xidChanged();
183
- if (!lost.on)
192
+ }
193
+ if (!lost.on) {
184
194
  await reserved.unsafe("rollback");
195
+ rolledBack = true;
196
+ }
185
197
  open = false;
186
198
  } catch (error) {
187
199
  if (isConnectionLost(error))
188
200
  lost.on = true;
189
201
  failure = error;
190
202
  } finally {
203
+ if (open && !lost.on && !sawCommit) {
204
+ const after = await readXid(reserved).catch((error) => {
205
+ if (isConnectionLost(error))
206
+ lost.on = true;
207
+ return;
208
+ });
209
+ if (!lost.on && after !== xid)
210
+ sawCommit = true;
211
+ }
191
212
  if (open && !lost.on) {
192
213
  await reserved.unsafe("rollback").catch((error) => {
193
214
  if (isConnectionLost(error))
194
215
  lost.on = true;
195
216
  });
217
+ if (!lost.on && !sawCommit)
218
+ rolledBack = true;
196
219
  }
197
220
  if (!lost.on)
198
221
  await reserved.unsafe("reset role").catch(() => {
@@ -207,6 +230,11 @@ async function inCheckTransaction(url, scratch, config, allowPooler, run) {
207
230
  }
208
231
  await finishQuiet(() => sql.end({ timeout: 5 }));
209
232
  }
233
+ if (!created || rolledBack) {
234
+ if (failure !== undefined)
235
+ throw sessionFailure(failure) ?? failure;
236
+ return value;
237
+ }
210
238
  const left = await dropScratch(url, scratch);
211
239
  if (left !== undefined) {
212
240
  const note = `Scratch schema ${left} is still present.`;