okmodel 0.1.0 → 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 +237 -19
  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 +390 -25
  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/{tb4ze1tr.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/{ckb1p0a4.js → 4jzzghr6.js} +416 -83
  117. package/dist/shared/{ycwz42az.js → 52szzakm.js} +6 -26
  118. package/dist/shared/{kynx7vbm.js → 5z4q2zda.js} +604 -21
  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/{ax16zpvm.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/{vkm3q4x1.js → eaxwrgby.js} +4 -3
  137. package/dist/shared/{7ck0dtry.js → ecdzej21.js} +160 -81
  138. package/dist/shared/{px90pf9p.js → edwqqryd.js} +21 -16
  139. package/dist/shared/{g2v6gnc8.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/{79ggp945.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/{4j72449d.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/{f5thc1s0.js → xrfnq5k8.js} +237 -418
  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 +56 -4
  181. package/dist/shared/gk7cs7sp.js +0 -566
@@ -6,7 +6,7 @@ import {
6
6
  acquireTimeout2,
7
7
  errorField2,
8
8
  mapDriverError2
9
- } from "./hd293j9g.js";
9
+ } from "./kyxb62mc.js";
10
10
  export {
11
11
  DriverError2 as DriverError,
12
12
  acquireTimeout2 as acquireTimeout,
@@ -0,0 +1,10 @@
1
+ import {
2
+ VALIDATION_NOT_IMPORTED2,
3
+ VALIDATION_NOT_IMPORTED_FIX2,
4
+ refuseMissingValidation2
5
+ } from "./n442h54c.js";
6
+ export {
7
+ VALIDATION_NOT_IMPORTED2 as VALIDATION_NOT_IMPORTED,
8
+ VALIDATION_NOT_IMPORTED_FIX2 as VALIDATION_NOT_IMPORTED_FIX,
9
+ refuseMissingValidation2 as refuseMissingValidation
10
+ };
@@ -0,0 +1,32 @@
1
+ // src/runtime/hookm.ts
2
+ function notices(hookm, notices) {
3
+ if (hookm === undefined)
4
+ return;
5
+ for (const notice of notices) {
6
+ for (const hook of hookm)
7
+ call(() => hook.onNotice?.(notice));
8
+ }
9
+ }
10
+ function phase(hookm, phase, depth) {
11
+ if (hookm === undefined)
12
+ return;
13
+ const event = { phase, depth };
14
+ for (const hook of hookm)
15
+ call(() => hook.onTransaction?.(event));
16
+ }
17
+ function report(session, error) {
18
+ for (const hook of session.hookm ?? [])
19
+ call(() => hook.onError?.(error));
20
+ const entry = error instanceof Error ? { code: "code" in error ? String(error.code) : error.name, summary: error.message } : { code: "error", summary: String(error) };
21
+ call(() => session.logger?.error?.(entry));
22
+ }
23
+ function call(fn) {
24
+ try {
25
+ fn();
26
+ } catch {}
27
+ }
28
+ export {
29
+ notices,
30
+ phase,
31
+ report
32
+ };
@@ -0,0 +1,76 @@
1
+ import {
2
+ send2,
3
+ reserve,
4
+ park
5
+ } from "./ytg3xf9p.js";
6
+ import {
7
+ isConnectionLost
8
+ } from "./tbszx8mz.js";
9
+ import {
10
+ WireSession
11
+ } from "./cstgkzdx.js";
12
+ import {
13
+ rejectClosed,
14
+ runCall
15
+ } from "./9k6vetvf.js";
16
+
17
+ // src/adapters/pg/bunsql-extra.ts
18
+ async function checkout(held) {
19
+ const { counters, isClosed } = held;
20
+ if (isClosed())
21
+ return rejectClosed();
22
+ const reserved = held.parked.pop() ?? await reserve(held.sql, held.acquireMs, counters);
23
+ counters.reserved += 1;
24
+ const session = new WireSession((text, params) => send2(reserved, text, params), held.notices, isClosed, false, () => {
25
+ counters.reservedBusy += 1;
26
+ }, () => {
27
+ counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
28
+ });
29
+ let lost = false;
30
+ const guard = (run) => lost ? rejectClosed("The connection was lost.") : run().catch((error) => {
31
+ if (isConnectionLost(error))
32
+ lost = true;
33
+ throw error;
34
+ });
35
+ let released = false;
36
+ return {
37
+ execute: (text, params, options) => guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch))),
38
+ batch: (statements, options) => guard(() => runCall(isClosed(), options, async (watch) => {
39
+ const { runAtomicBatch } = await import("./b066g80h.js");
40
+ return runAtomicBatch(session, statements, watch);
41
+ })),
42
+ async release() {
43
+ if (released)
44
+ return;
45
+ released = true;
46
+ try {
47
+ if (!lost)
48
+ await reset(session, reserved);
49
+ } finally {
50
+ counters.reserved = Math.max(0, counters.reserved - 1);
51
+ if (!lost)
52
+ await park(held.parked, reserved);
53
+ }
54
+ }
55
+ };
56
+ }
57
+ async function reset(session, sql) {
58
+ const run = (text) => sql.unsafe(text);
59
+ if (session.depth() > 0)
60
+ await run("ROLLBACK").catch(() => {
61
+ return;
62
+ });
63
+ try {
64
+ await run("RESET ALL");
65
+ await run("SELECT pg_advisory_unlock_all()");
66
+ } catch {
67
+ await run("ROLLBACK").catch(() => {
68
+ return;
69
+ });
70
+ await run("RESET ALL");
71
+ await run("SELECT pg_advisory_unlock_all()");
72
+ }
73
+ }
74
+ export {
75
+ checkout
76
+ };
@@ -15,6 +15,22 @@ var PGLITE_CAPABILITIES = {
15
15
  prepared: "unnamed",
16
16
  describe: true
17
17
  };
18
+ var NODE_POSTGRES_CAPABILITIES = {
19
+ transactions: "interactive",
20
+ stream: true,
21
+ listen: true,
22
+ cancel: true,
23
+ prepared: "unnamed",
24
+ describe: false
25
+ };
26
+ var BUNSQL_CAPABILITIES = {
27
+ transactions: "interactive",
28
+ stream: true,
29
+ listen: true,
30
+ cancel: false,
31
+ prepared: "unnamed",
32
+ describe: false
33
+ };
18
34
  function readCapability2(flags, name) {
19
35
  return flags[name];
20
36
  }
@@ -25,7 +41,7 @@ function hasCapability2(flags, name) {
25
41
  // src/adapters/failure.ts
26
42
  var loading;
27
43
  function driverErrors() {
28
- loading ??= import("./mtkwv8wx.js");
44
+ loading ??= import("./7p2wbz7f.js");
29
45
  return loading;
30
46
  }
31
47
  function rejectClosed(message = "The pool is closed.") {
@@ -48,9 +64,8 @@ function needsWatch(options) {
48
64
  }
49
65
  function nextTransactionDepth(depth, text) {
50
66
  const command = text.trim().replace(/;\s*$/, "").trim().toLowerCase();
51
- if (command === "begin" || command === "begin work" || command === "begin transaction") {
67
+ if (/^(?:begin|start transaction)(?:\s|$)/.test(command))
52
68
  return depth + 1;
53
- }
54
69
  if (command === "commit" || command === "commit work" || command === "end") {
55
70
  return Math.max(0, depth - 1);
56
71
  }
@@ -58,35 +73,6 @@ function nextTransactionDepth(depth, text) {
58
73
  return 0;
59
74
  return depth;
60
75
  }
61
- function openWatch(options) {
62
- let kind;
63
- const controller = new AbortController;
64
- const onAbort = () => {
65
- if (kind === undefined)
66
- kind = "cancelled";
67
- controller.abort();
68
- };
69
- options.signal?.addEventListener("abort", onAbort, { once: true });
70
- let timer;
71
- if (options.timeout !== undefined) {
72
- timer = setTimeout(() => {
73
- if (kind === undefined)
74
- kind = "timeout";
75
- controller.abort();
76
- }, options.timeout);
77
- }
78
- return {
79
- signal: controller.signal,
80
- finish() {
81
- if (timer !== undefined)
82
- clearTimeout(timer);
83
- options.signal?.removeEventListener("abort", onAbort);
84
- },
85
- reason() {
86
- return kind;
87
- }
88
- };
89
- }
90
76
  function runCall(closed, options, fn) {
91
77
  if (closed)
92
78
  return rejectClosed();
@@ -96,9 +82,12 @@ function runCall(closed, options, fn) {
96
82
  return rejectTimedOut();
97
83
  if (options === undefined || !needsWatch(options))
98
84
  return fn(undefined);
99
- const watch = openWatch(options);
100
- return fn(watch).finally(() => {
101
- watch.finish();
85
+ const watched = options;
86
+ return import("./k3ted12y.js").then(({ openWatch }) => {
87
+ const watch = openWatch(watched);
88
+ return fn(watch).finally(() => {
89
+ watch.finish();
90
+ });
102
91
  });
103
92
  }
104
93
 
@@ -174,4 +163,4 @@ function countFrom(value, rows) {
174
163
  return rows;
175
164
  }
176
165
 
177
- export { POSTGRESJS_CAPABILITIES, PGLITE_CAPABILITIES, readCapability2, hasCapability2, driverErrors, rejectClosed, rejectCancelled, rejectTimedOut, mapFailure, nextTransactionDepth, runCall, EMPTY_NOTICES, rowsFrom, resultFrom };
166
+ export { POSTGRESJS_CAPABILITIES, PGLITE_CAPABILITIES, NODE_POSTGRES_CAPABILITIES, BUNSQL_CAPABILITIES, readCapability2, hasCapability2, driverErrors, rejectClosed, rejectCancelled, rejectTimedOut, mapFailure, nextTransactionDepth, runCall, EMPTY_NOTICES, rowsFrom, resultFrom };
@@ -6,7 +6,7 @@ import {
6
6
  catalogHash2,
7
7
  loadTrustedCatalog2,
8
8
  parseCatalog2
9
- } from "./y9m15dfv.js";
9
+ } from "./d2whjz4k.js";
10
10
  export {
11
11
  catalogHash2 as catalogHash,
12
12
  creationOrder2 as creationOrder,
@@ -0,0 +1,13 @@
1
+ // src/runtime/safety-hook.ts
2
+ var hook;
3
+ function safetyInstalled() {
4
+ return hook !== undefined;
5
+ }
6
+ function installSafetyHook(next) {
7
+ hook = next;
8
+ }
9
+ function runSafety(contributions, hatches) {
10
+ hook?.(contributions, hatches);
11
+ }
12
+
13
+ export { safetyInstalled, installSafetyHook, runSafety };
@@ -2,10 +2,10 @@ import {
2
2
  DriverError2,
3
3
  outcomeUnknown2,
4
4
  mapDriverError2
5
- } from "./hd293j9g.js";
5
+ } from "./kyxb62mc.js";
6
6
  import {
7
- isConnectionFailure
8
- } from "./ngk8gj61.js";
7
+ isConnectionLost
8
+ } from "./tbszx8mz.js";
9
9
 
10
10
  // src/adapters/pg/batch.ts
11
11
  var savepointIds = 0;
@@ -21,13 +21,14 @@ async function transaction(session, statements, watch) {
21
21
  try {
22
22
  await control(session, "COMMIT", watch);
23
23
  } catch (error) {
24
- if (isConnectionFailure(error))
24
+ if (isConnectionLost(error))
25
25
  throw outcomeUnknown2(error);
26
26
  throw stamp(error, null);
27
27
  }
28
28
  return results;
29
29
  } catch (error) {
30
- await rollback(session);
30
+ if (!isConnectionLost(error))
31
+ await rollback(session);
31
32
  throw error;
32
33
  }
33
34
  }
@@ -40,7 +41,8 @@ async function savepoint(session, statements, watch) {
40
41
  await control(session, `RELEASE SAVEPOINT ${name}`, watch);
41
42
  return results;
42
43
  } catch (error) {
43
- await rollback(session, `ROLLBACK TO SAVEPOINT ${name}`);
44
+ if (!isConnectionLost(error))
45
+ await rollback(session, `ROLLBACK TO SAVEPOINT ${name}`);
44
46
  throw error;
45
47
  }
46
48
  }
@@ -0,0 +1,154 @@
1
+ import {
2
+ driverErrors,
3
+ rejectClosed,
4
+ nextTransactionDepth,
5
+ EMPTY_NOTICES,
6
+ resultFrom
7
+ } from "./9k6vetvf.js";
8
+
9
+ // src/adapters/pg/session.ts
10
+ function quoteIdent2(name) {
11
+ return `"${name.replaceAll('"', '""')}"`;
12
+ }
13
+ function noticeBuffer() {
14
+ let notices;
15
+ return {
16
+ push(notice) {
17
+ const severity = notice.severity ?? "";
18
+ const message = notice.message ?? "";
19
+ const code = notice.code !== undefined && notice.code.length > 0 ? notice.code : undefined;
20
+ const entry = code === undefined ? { severity, message } : { severity, message, code };
21
+ (notices ??= []).push(entry);
22
+ },
23
+ start() {
24
+ return notices?.length ?? 0;
25
+ },
26
+ since(start) {
27
+ if (notices === undefined || notices.length === start)
28
+ return EMPTY_NOTICES;
29
+ return notices.slice(start);
30
+ }
31
+ };
32
+ }
33
+
34
+ class WireSession {
35
+ canCancel;
36
+ transactionDepth = 0;
37
+ local = new Set;
38
+ send;
39
+ notices;
40
+ isClosed;
41
+ onEnter;
42
+ onLeave;
43
+ shared;
44
+ constructor(send, notices, isClosed, canCancel, onEnter, onLeave, shared) {
45
+ this.send = send;
46
+ this.notices = notices;
47
+ this.isClosed = isClosed;
48
+ this.canCancel = canCancel;
49
+ this.onEnter = onEnter;
50
+ this.onLeave = onLeave;
51
+ this.shared = shared;
52
+ }
53
+ query(text, params, watch) {
54
+ if (this.isClosed())
55
+ return rejectClosed();
56
+ const start = this.notices.start();
57
+ this.onEnter();
58
+ const pending = this.send(text, params);
59
+ if (watch === undefined) {
60
+ return pending.then((result) => {
61
+ this.onLeave();
62
+ this.note(text);
63
+ return resultFrom(result, this.notices.since(start));
64
+ }, (error) => {
65
+ this.onLeave();
66
+ return driverErrors().then((errors) => Promise.reject(errors.mapDriverError(error)));
67
+ });
68
+ }
69
+ return this.watched(pending, watch, start, text);
70
+ }
71
+ inTransaction() {
72
+ return this.transactionDepth > 0;
73
+ }
74
+ abandon() {
75
+ this.transactionDepth = 0;
76
+ }
77
+ depth() {
78
+ return this.transactionDepth;
79
+ }
80
+ cancel() {
81
+ for (const pending of this.local)
82
+ pending.cancel?.();
83
+ }
84
+ note(text) {
85
+ this.transactionDepth = nextTransactionDepth(this.transactionDepth, text);
86
+ }
87
+ track(pending) {
88
+ this.local.add(pending);
89
+ this.shared?.add(pending);
90
+ }
91
+ untrack(pending) {
92
+ this.local.delete(pending);
93
+ this.shared?.delete(pending);
94
+ }
95
+ watched(pending, watch, start, text) {
96
+ this.track(pending);
97
+ const onAbort = () => {
98
+ pending.cancel?.();
99
+ };
100
+ if (watch.signal.aborted)
101
+ onAbort();
102
+ else
103
+ watch.signal.addEventListener("abort", onAbort, { once: true });
104
+ return pending.then((result) => {
105
+ this.finishWatched(pending, watch, onAbort);
106
+ const why = watch.reason();
107
+ if (why === "timeout" || why === "cancelled")
108
+ return classify(why, watch);
109
+ this.note(text);
110
+ return resultFrom(result, this.notices.since(start));
111
+ }, (error) => {
112
+ this.finishWatched(pending, watch, onAbort);
113
+ return classify(error, watch);
114
+ });
115
+ }
116
+ finishWatched(pending, watch, onAbort) {
117
+ this.onLeave();
118
+ this.untrack(pending);
119
+ watch.signal.removeEventListener("abort", onAbort);
120
+ }
121
+ }
122
+ async function* cursorStream(run, text, params) {
123
+ const name = "okm_stream";
124
+ await run("BEGIN");
125
+ try {
126
+ await run(`DECLARE ${name} NO SCROLL CURSOR FOR ${text}`, params);
127
+ for (;; ) {
128
+ const chunk = await run(`FETCH 64 FROM ${name}`);
129
+ if (chunk.rows.length === 0)
130
+ break;
131
+ yield chunk.rows;
132
+ }
133
+ } finally {
134
+ await run("ROLLBACK").catch(() => {
135
+ return;
136
+ });
137
+ }
138
+ }
139
+ async function classify(error, watch) {
140
+ const errors = await driverErrors();
141
+ if (error instanceof errors.DriverError)
142
+ return Promise.reject(error);
143
+ const why = typeof error === "string" ? error : watch.reason();
144
+ if (why === "timeout") {
145
+ return Promise.reject(errors.timedOut(typeof error === "string" ? undefined : error));
146
+ }
147
+ const code = errors.errorField(error, "code") ?? errors.errorField(error, "errno");
148
+ if (why === "cancelled" || code === "57014") {
149
+ return Promise.reject(errors.cancelled(typeof error === "string" ? undefined : error));
150
+ }
151
+ return Promise.reject(errors.mapDriverError(error));
152
+ }
153
+
154
+ export { quoteIdent2, noticeBuffer, WireSession, cursorStream };
@@ -1,18 +1,19 @@
1
1
  import {
2
2
  open2
3
- } from "./7ck0dtry.js";
4
- import"./y9m15dfv.js";
3
+ } from "./ecdzej21.js";
4
+ import"./d2whjz4k.js";
5
+ import"./n442h54c.js";
5
6
  import {
6
7
  loadMigrations
7
- } from "./4j72449d.js";
8
+ } from "./rtnaqre0.js";
8
9
  import {
9
10
  assertTargetPolicy,
10
11
  listTargets,
11
12
  loadConfig
12
- } from "./kynx7vbm.js";
13
+ } from "./5z4q2zda.js";
13
14
  import {
14
15
  OkmError2
15
- } from "./ycwz42az.js";
16
+ } from "./52szzakm.js";
16
17
 
17
18
  // src/tooling/migrate/status.ts
18
19
  import { join } from "node:path";
@@ -2,12 +2,8 @@ import {
2
2
  dependencyOrder,
3
3
  catalog,
4
4
  enumType
5
- } from "./g5fhqmwe.js";
5
+ } from "./qxa0yb9j.js";
6
6
  import {
7
- OWNERS2,
8
- BUILT_KINDS2,
9
- referentialAction,
10
- CATALOG_VERSION2,
11
7
  canonicalJson,
12
8
  staticNamespace2,
13
9
  templateNamespace2,
@@ -23,13 +19,19 @@ import {
23
19
  constraint2,
24
20
  sequence2,
25
21
  compareText
26
- } from "./j5cn2963.js";
22
+ } from "./t4tbsy9h.js";
23
+ import {
24
+ OWNERS2,
25
+ BUILT_KINDS2,
26
+ referentialAction,
27
+ CATALOG_VERSION2
28
+ } from "./4e4c6vq2.js";
27
29
  import {
28
30
  sha2562
29
- } from "./mkjmqjv4.js";
31
+ } from "./nfzc5z0w.js";
30
32
  import {
31
33
  catalogError2
32
- } from "./ycwz42az.js";
34
+ } from "./52szzakm.js";
33
35
 
34
36
  // src/contracts/catalog/rewrite.ts
35
37
  function replaceIdentifier(text, from, to) {
@@ -251,6 +253,7 @@ function rewriteColumn(object, change, dependencies) {
251
253
  provenance: object.provenance,
252
254
  dependencies,
253
255
  ...definition.defaultExpression !== undefined ? { defaultExpression: rewriteExpr(definition.defaultExpression, change, local) } : {},
256
+ ...definition.collation !== undefined ? { collation: definition.collation } : {},
254
257
  ...definition.identity !== undefined ? { identity: definition.identity } : {},
255
258
  ...definition.generated !== undefined ? {
256
259
  generated: {
@@ -335,6 +338,7 @@ function rewriteTableName(object, change, fromKey, toIdentity) {
335
338
  ...object.definition.defaultExpression !== undefined ? {
336
339
  defaultExpression: rewriteExpr(object.definition.defaultExpression, { from: change.from, to: change.to }, local)
337
340
  } : {},
341
+ ...object.definition.collation !== undefined ? { collation: object.definition.collation } : {},
338
342
  ...object.definition.identity !== undefined ? { identity: object.definition.identity } : {},
339
343
  ...object.definition.generated !== undefined ? { generated: object.definition.generated } : {}
340
344
  });
@@ -457,6 +461,7 @@ function definitionToJson(object) {
457
461
  dataType: definition.dataType,
458
462
  nullable: definition.nullable,
459
463
  ...definition.defaultExpression !== undefined ? { defaultExpression: definition.defaultExpression } : {},
464
+ ...definition.collation !== undefined ? { collation: definition.collation } : {},
460
465
  ...definition.identity !== undefined ? { identity: { always: definition.identity.always } } : {},
461
466
  ...definition.generated !== undefined ? {
462
467
  generated: {
@@ -564,7 +569,7 @@ function parseColumn(identity, definition, owner, provenance, dependencies) {
564
569
  if (identity.kind !== "column") {
565
570
  catalogError2("OKM1020", `Column object identity is ${identity.kind}, not a column.`);
566
571
  }
567
- rejectUnknown(definition, ["dataType", "defaultExpression", "generated", "identity", "nullable"], "column definition");
572
+ rejectUnknown(definition, ["collation", "dataType", "defaultExpression", "generated", "identity", "nullable"], "column definition");
568
573
  const generated = definition.generated;
569
574
  const columnIdentity = definition.identity;
570
575
  return column2({
@@ -576,6 +581,7 @@ function parseColumn(identity, definition, owner, provenance, dependencies) {
576
581
  provenance,
577
582
  dependencies,
578
583
  ...definition.defaultExpression === undefined ? {} : { defaultExpression: requireString(definition.defaultExpression, "default") },
584
+ ...definition.collation === undefined ? {} : { collation: requireString(definition.collation, "collation") },
579
585
  ...columnIdentity === undefined ? {} : { identity: parseAlways(columnIdentity) },
580
586
  ...generated === undefined ? {} : { generated: parseGenerated(generated) }
581
587
  });