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
@@ -1,6 +1,6 @@
1
1
  import"../shared/qq3899ht.js";
2
2
  import"../shared/n442h54c.js";
3
- import"../shared/wkme6tep.js";
3
+ import"../shared/14vx95q4.js";
4
4
  import {
5
5
  formatFindings,
6
6
  hasError,
@@ -9,10 +9,10 @@ import {
9
9
  generateProject,
10
10
  planProject,
11
11
  checkProject
12
- } from "../shared/t3g0k88x.js";
12
+ } from "../shared/gs74dbj5.js";
13
13
  import {
14
14
  sessionFailure
15
- } from "../shared/ttmg09vd.js";
15
+ } from "../shared/tsvww22q.js";
16
16
  import"../shared/9s0ypp87.js";
17
17
  import {
18
18
  OkmError2
@@ -73,12 +73,12 @@ async function run(argv, io) {
73
73
  return;
74
74
  }
75
75
  if (command === "dev") {
76
- const { devProject } = await import("../shared/xq0mvhts.js");
76
+ const { devProject } = await import("../shared/rs73fca9.js");
77
77
  stdout(await devProject(cwd));
78
78
  return;
79
79
  }
80
80
  if (command === "push") {
81
- const { pushProject } = await import("../shared/1nw1f3vs.js");
81
+ const { pushProject } = await import("../shared/2shdbn8q.js");
82
82
  stdout(await pushProject(cwd, invoke(splitFlags(rest))));
83
83
  return;
84
84
  }
@@ -97,17 +97,17 @@ async function run(argv, io) {
97
97
  return;
98
98
  }
99
99
  if (sub === "apply") {
100
- const { applyProject } = await import("../shared/1nw1f3vs.js");
100
+ const { applyProject } = await import("../shared/2shdbn8q.js");
101
101
  stdout(await applyProject(cwd, invoke(parsed), stdout));
102
102
  return;
103
103
  }
104
104
  if (sub === "status") {
105
- const { statusProject } = await import("../shared/wynzeggs.js");
105
+ const { statusProject } = await import("../shared/svncdeh5.js");
106
106
  stdout(await statusProject(cwd, invoke(parsed)));
107
107
  return;
108
108
  }
109
109
  if (sub === "check") {
110
- const { checkMigrations } = await import("../shared/09p049xa.js");
110
+ const { checkMigrations } = await import("../shared/wa07eas9.js");
111
111
  const provision = parsed.flags.includes("--provision") || rest.slice(1).includes("--provision");
112
112
  stdout(await checkMigrations(cwd, invoke(parsed), { provision }));
113
113
  return;
@@ -120,13 +120,13 @@ async function run(argv, io) {
120
120
  fix: { summary: "Pass okm seed <file>." }
121
121
  });
122
122
  }
123
- const { seedProject } = await import("../shared/3fqwmr09.js");
123
+ const { seedProject } = await import("../shared/w72kgg4q.js");
124
124
  stdout(await seedProject(cwd, parsed.name, invoke(parsed)));
125
125
  return;
126
126
  }
127
127
  if (command === "doctor") {
128
128
  const parsed = splitFlags(rest);
129
- const { doctorProject } = await import("../shared/wt5rzv1h.js");
129
+ const { doctorProject } = await import("../shared/kr0jzbw2.js");
130
130
  stdout(await doctorProject(cwd, parsed.name, invoke(parsed)));
131
131
  return;
132
132
  }
@@ -138,7 +138,7 @@ async function run(argv, io) {
138
138
  });
139
139
  }
140
140
  if (sub === "list" || sub === "check") {
141
- const { extProject } = await import("../shared/p6bjzq9q.js");
141
+ const { extProject } = await import("../shared/ktz42yez.js");
142
142
  stdout(await extProject(cwd, sub, invoke(splitFlags(rest.slice(1)))));
143
143
  return;
144
144
  }
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Engine-version checks `okm migrate apply` runs before the first statement.
3
3
  *
4
- * The only engine-dependent feature in 0.2 is a `uuidv7()` database default,
5
- * which Postgres has from 18. Nothing here is reachable from `connect()`.
4
+ * An explicit `uuidv7()` database default needs {@link UUIDV7_POSTGRES}.
5
+ * A bare `t.id()` stores `gen_random_uuid()` and does not match here.
6
+ * Nothing here is reachable from `connect()`.
6
7
  */
7
8
  import type { DriverConnection } from "../../contracts/driver.js";
8
9
  import type { StoredMigration } from "./files.js";
@@ -1,26 +1,26 @@
1
- import"../../shared/wkme6tep.js";
1
+ import"../../shared/14vx95q4.js";
2
2
  import"../../shared/qq3899ht.js";
3
3
  import"../../shared/n442h54c.js";
4
4
  import {
5
5
  applyTarget2,
6
6
  backfillTiming2
7
- } from "../../shared/nx9hh281.js";
7
+ } from "../../shared/p6qc5gcp.js";
8
8
  import {
9
9
  readReference
10
- } from "../../shared/p248q79y.js";
11
- import"../../shared/knmes2kh.js";
12
- import"../../shared/vjpnzwjz.js";
10
+ } from "../../shared/m6p12kbr.js";
11
+ import"../../shared/8skf0cam.js";
12
+ import"../../shared/b5pftnn2.js";
13
13
  import {
14
14
  projectPath,
15
15
  loadMigrations,
16
16
  loadHeadSnapshot,
17
17
  loadBuiltSchema,
18
18
  loadConfig
19
- } from "../../shared/t3g0k88x.js";
19
+ } from "../../shared/gs74dbj5.js";
20
20
  import {
21
21
  assertTargetPolicy,
22
22
  selectTarget
23
- } from "../../shared/ttmg09vd.js";
23
+ } from "../../shared/tsvww22q.js";
24
24
  import"../../shared/9s0ypp87.js";
25
25
  import {
26
26
  OkmError2
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  testing2
3
- } from "../../shared/8x72s86k.js";
3
+ } from "../../shared/7k9grvf6.js";
4
4
  import"../../shared/9s0ypp87.js";
5
5
  import"../../shared/qq3899ht.js";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "okmodel",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "okmodel is a catalog-first TypeScript ORM, PostgreSQL first.",
5
5
  "keywords": [
6
6
  "migrations",
@@ -126,6 +126,7 @@
126
126
  "compiler-api": "bun ./scripts/compiler-api.ts",
127
127
  "publint": "publint run . --strict --pack bun",
128
128
  "attw": "bun ./scripts/attw.ts",
129
+ "pack-tracked": "bun ./scripts/pack-tracked.ts",
129
130
  "prepack": "bun ./scripts/strip-workspaces.ts strip",
130
131
  "postpack": "bun ./scripts/strip-workspaces.ts restore",
131
132
  "size": "bun ./scripts/size.ts",
@@ -134,7 +135,7 @@
134
135
  "test:postgres": "bun ./scripts/postgres-suite.ts",
135
136
  "test:tarball": "bun ./scripts/tarball-smoke.ts",
136
137
  "verify": "bun ./scripts/verify.ts",
137
- "check": "bun run format:check && bun run lint && bun run typecheck && bun run editor-check && bun run type-cost && bun run layers-check && bun run core-purity && bun run okid-drift && bun run docs:check && bun run readme:check && bun run compiler-api && bun run bundle-purity && bun run build && bun test && bun run test:runtimes && bun run publint && bun run attw && bun run size",
138
+ "check": "bun run format:check && bun run lint && bun run typecheck && bun run editor-check && bun run type-cost && bun run layers-check && bun run core-purity && bun run okid-drift && bun run docs:check && bun run readme:check && bun run compiler-api && bun run bundle-purity && bun run build && bun test && bun run test:runtimes && bun run publint && bun run attw && bun run pack-tracked && bun run size",
138
139
  "bump": "bun ./scripts/bump-version.ts",
139
140
  "release-check": "bun ./scripts/release-check.ts",
140
141
  "db:up": "bun ./packages/harness/src/docker-cli.ts up",
@@ -142,6 +143,7 @@
142
143
  "bench": "bun ./packages/bench/src/run.ts",
143
144
  "catalog-bench": "bun ./scripts/catalog-bench.ts",
144
145
  "attest": "ATTEST_shouldFormat=0 ATTEST_updateSnapshots=0 bun ./packages/attest/src/measure.bench.ts",
146
+ "dev": "bun run site:dev",
145
147
  "site:dev": "bun --cwd site dev",
146
148
  "site:build": "bun --cwd site build",
147
149
  "site:check": "bun --cwd site check",
@@ -1,38 +0,0 @@
1
- import {
2
- mapPostgresError2
3
- } from "./c58secgj.js";
4
- import {
5
- withHttp
6
- } from "./j60w0dvr.js";
7
- import {
8
- decodeResult
9
- } from "./2z7wv5tj.js";
10
- import {
11
- OkmError2
12
- } from "./52szzakm.js";
13
-
14
- // src/runtime/read-stream.ts
15
- async function* streamRows(session, call, prepare, log) {
16
- await session.connected;
17
- if (session.pool.capabilities.stream !== true || session.pool.stream === undefined) {
18
- throw log(new OkmError2("OKM1111", "stream needs a driver with stream: true. This driver does not have it.", withHttp(session.http, {
19
- fix: { summary: "Use a driver that sets stream, or read with find." }
20
- })));
21
- }
22
- const { plan, params } = await prepare();
23
- const decode = plan.outputs.includes.length === 0 ? decodeResult : (await import("./ys0xzyaj.js")).decodeIncluded;
24
- try {
25
- for await (const chunk of session.pool.stream(plan.text, params)) {
26
- const decoded = decode(plan, chunk, call.table);
27
- if (!Array.isArray(decoded))
28
- continue;
29
- for (const row of decoded)
30
- yield row;
31
- }
32
- } catch (error) {
33
- throw log(session.http === undefined ? mapPostgresError2(error) : mapPostgresError2(error, { http: session.http }));
34
- }
35
- }
36
- export {
37
- streamRows
38
- };
@@ -1,45 +0,0 @@
1
- // src/runtime/trait-read.ts
2
- function touchFields(model) {
3
- const traits = model.traits;
4
- if (traits === undefined)
5
- return;
6
- const names = [];
7
- for (const trait of traits) {
8
- const touch = trait.touch;
9
- if (touch === undefined)
10
- continue;
11
- for (const field of touch)
12
- names.push(field);
13
- }
14
- return names.length === 0 ? undefined : names;
15
- }
16
- function fieldSealed(model, field) {
17
- const traits = model.traits;
18
- if (traits === undefined)
19
- return false;
20
- for (const trait of traits) {
21
- const sealed = trait.sealed;
22
- if (sealed === undefined)
23
- continue;
24
- for (const name of sealed)
25
- if (name === field)
26
- return true;
27
- }
28
- return false;
29
- }
30
- function sealingTrait(model, field) {
31
- const traits = model.traits;
32
- if (traits === undefined)
33
- return;
34
- for (const trait of traits) {
35
- const sealed = trait.sealed;
36
- if (sealed === undefined)
37
- continue;
38
- for (const name of sealed)
39
- if (name === field)
40
- return trait.name;
41
- }
42
- return;
43
- }
44
-
45
- export { touchFields, fieldSealed, sealingTrait };
@@ -1,12 +0,0 @@
1
- import {
2
- OkmError2
3
- } from "./52szzakm.js";
4
-
5
- // src/adapters/pg/no-inflight-timeout.ts
6
- function noTimeout2(options) {
7
- if ((options?.timeout ?? 0) <= 0)
8
- return;
9
- throw new OkmError2("OKM1120", "timeout");
10
- }
11
-
12
- export { noTimeout2 };
@@ -1,6 +0,0 @@
1
- import {
2
- mapPostgresError2
3
- } from "./c58secgj.js";
4
- export {
5
- mapPostgresError2 as mapPostgresError
6
- };
@@ -1,99 +0,0 @@
1
- import {
2
- DriverError2
3
- } from "./31vm914h.js";
4
- import {
5
- noTimeout2
6
- } from "./8dqhth8c.js";
7
- import {
8
- send2,
9
- reserve,
10
- park
11
- } from "./32cnm7kn.js";
12
- import {
13
- isConnectionLost
14
- } from "./gwn6v667.js";
15
- import {
16
- WireSession
17
- } from "./4az561fn.js";
18
- import {
19
- rejectClosed,
20
- runCall
21
- } from "./cgbamx3e.js";
22
-
23
- // src/adapters/pg/bunsql-extra.ts
24
- async function checkout(held) {
25
- const { counters, isClosed } = held;
26
- if (isClosed())
27
- return rejectClosed();
28
- const reserved = held.parked.pop() ?? await reserve(held.sql, held.acquireMs, counters);
29
- counters.reserved += 1;
30
- const session = new WireSession((text, params) => send2(reserved, text, params), held.notices, isClosed, false, () => {
31
- counters.reservedBusy += 1;
32
- }, () => {
33
- counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
34
- });
35
- let lost = false;
36
- const guard = (run) => lost ? rejectClosed("CONNECTION_CLOSED") : run().catch((error) => {
37
- if (isConnectionLost(error))
38
- lost = true;
39
- if (error instanceof Error && bunClosed(error.message)) {
40
- lost = true;
41
- throw new DriverError2("CONNECTION_CLOSED", { cause: error });
42
- }
43
- throw error;
44
- });
45
- let released = false;
46
- return {
47
- execute: (text, params, options) => {
48
- noTimeout2(options);
49
- return guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch)));
50
- },
51
- batch: (statements, options) => {
52
- noTimeout2(options);
53
- return guard(() => runCall(isClosed(), options, async (watch) => {
54
- const { runAtomicBatch } = await import("./ag4c7516.js");
55
- return runAtomicBatch(session, statements, watch);
56
- }));
57
- },
58
- async release() {
59
- if (released)
60
- return;
61
- released = true;
62
- try {
63
- if (!lost)
64
- await reset(session, reserved);
65
- } finally {
66
- counters.reserved = Math.max(0, counters.reserved - 1);
67
- if (lost)
68
- await held.sql.unsafe("select 1").catch(() => {
69
- return;
70
- });
71
- else
72
- await park(held.parked, reserved);
73
- }
74
- }
75
- };
76
- }
77
- function bunClosed(message) {
78
- return message === "Connection closed" || message === "connection must be a PostgresSQLConnection";
79
- }
80
- async function reset(session, sql) {
81
- const run = (text) => sql.unsafe(text);
82
- if (session.depth() > 0)
83
- await run("ROLLBACK").catch(() => {
84
- return;
85
- });
86
- try {
87
- await run("RESET ALL");
88
- await run("SELECT pg_advisory_unlock_all()");
89
- } catch {
90
- await run("ROLLBACK").catch(() => {
91
- return;
92
- });
93
- await run("RESET ALL");
94
- await run("SELECT pg_advisory_unlock_all()");
95
- }
96
- }
97
- export {
98
- checkout
99
- };
@@ -1,85 +0,0 @@
1
- import {
2
- catalogError2,
3
- throwNamed2
4
- } from "./52szzakm.js";
5
-
6
- // src/dialects/pg/through.ts
7
- var emit = (planner, schema, relation, child, sink, parent, alias, depth) => {
8
- const through = relation.through;
9
- const join = through === undefined ? undefined : planner.indexes(schema).get(through.table);
10
- if (through === undefined || join === undefined) {
11
- return catalogError2("OKM1020", `Relation ${relation.name} names a join table that is not in the schema.`);
12
- }
13
- const { quote } = planner;
14
- const joinAlias = `j${alias}`;
15
- sink.mark(`via:${through.table}`);
16
- sink.text(`${quote(join.model.sql)} ${joinAlias} join ${quote(child.model.sql)} ${alias} on `);
17
- for (let index = 0;index < through.local.length; index += 1) {
18
- const local = through.local[index];
19
- const remote = through.remote[index];
20
- if (local === undefined || remote === undefined)
21
- continue;
22
- if (index > 0)
23
- sink.text(" and ");
24
- sink.text(`${alias}.${quote(remote)} = ${joinAlias}.${quote(local)}`);
25
- }
26
- sink.text(" where ");
27
- planner.join(sink, parent, joinAlias, relation);
28
- planner.where(schema, join, undefined, sink, joinAlias, depth + 1, true);
29
- };
30
- function resolveThrough(scope, table, through, from, to) {
31
- for (const name of [table, through]) {
32
- if (!scope.tables.includes(name)) {
33
- throwNamed2("OKM1020", name, scope.tables, `Relation ${scope.owner}.${scope.name} names ${name}, which is not in the schema. Accepted names: ${scope.tables.join(", ")}.`);
34
- }
35
- }
36
- const toOwner = pick(scope, through, scope.owner, from, `${scope.owner}.${scope.name}`, "from");
37
- const toTable = pick(scope, through, table, to, `${scope.owner}.${scope.name}`, "to");
38
- if (toOwner === toTable) {
39
- catalogError2("OKM1021", `Relation ${scope.owner}.${scope.name} uses ${toOwner.fromField} on ${through} for both ends. Pass from and to.`);
40
- }
41
- return {
42
- name: scope.name,
43
- kind: "many",
44
- table,
45
- local: toOwner.remote,
46
- remote: toOwner.local,
47
- through: { table: through, local: toTable.local, remote: toTable.remote, emit }
48
- };
49
- }
50
- function pick(scope, through, target, field, label, end) {
51
- const matches = scope.edges.filter((edge) => edge.fromTable === through && edge.toTable === target && (field === undefined || edge.fromField === field));
52
- const [only] = matches;
53
- if (matches.length === 1 && only !== undefined)
54
- return only;
55
- const fields = matches.map((edge) => edge.fromField).sort();
56
- catalogError2("OKM1021", `Relation ${label} through ${through} is ambiguous at ${end}. Accepted columns: ${fields.length === 0 ? "(none)" : fields.join(", ")}.`);
57
- }
58
-
59
- // src/dialects/pg/relations.ts
60
- function one2(table, field) {
61
- return { kind: "one", table, field };
62
- }
63
- function many2(table, field) {
64
- return { kind: "many", table, field };
65
- }
66
- function isRelationCall(value) {
67
- if (typeof value !== "object" || value === null)
68
- return false;
69
- if (!("kind" in value) || !("table" in value))
70
- return false;
71
- const kind = value.kind;
72
- return (kind === "one" || kind === "many") && typeof value.table === "string";
73
- }
74
- function manyThrough2(table, options) {
75
- const { through, from, to } = options;
76
- return {
77
- kind: "many",
78
- table,
79
- field: undefined,
80
- through,
81
- resolve: (scope) => resolveThrough(scope, table, through, from, to)
82
- };
83
- }
84
-
85
- export { one2, many2, isRelationCall, manyThrough2 };
@@ -1,216 +0,0 @@
1
- import {
2
- readHandle,
3
- readCall,
4
- attachHttp
5
- } from "./j60w0dvr.js";
6
- import {
7
- emitWhere,
8
- emitOrder,
9
- refuseHidden,
10
- rejectKeys,
11
- readLimit,
12
- projectExpr,
13
- cell,
14
- indexes,
15
- quote,
16
- list,
17
- isRecord,
18
- fail
19
- } from "./2z7wv5tj.js";
20
- import {
21
- OkmError2,
22
- throwNamed2
23
- } from "./52szzakm.js";
24
-
25
- // src/runtime/aggregate.ts
26
- var OPTIONS = [
27
- "where",
28
- "groupBy",
29
- "count",
30
- "sum",
31
- "avg",
32
- "min",
33
- "max",
34
- "orderBy",
35
- "limit",
36
- "route",
37
- "signal",
38
- "timeout"
39
- ];
40
- var NUMERIC = /^(smallint|integer|bigint|real|double precision|numeric|decimal)\b/;
41
- var AS_NUMBER = (wire) => Number(wire);
42
- var AS_TEXT = (wire) => wire;
43
- var UNORDERED = /^(json|jsonb|bytea|point|line|tsvector)\b|\[\]$/;
44
- var FUNCTIONS = [
45
- { option: "sum", tag: "s", numeric: true },
46
- { option: "avg", tag: "a", numeric: true },
47
- { option: "min", tag: "n", numeric: false },
48
- { option: "max", tag: "x", numeric: false }
49
- ];
50
- function build(session, table, options, mods, view) {
51
- try {
52
- return plan(session, table, options, mods, view);
53
- } catch (error) {
54
- throw error instanceof OkmError2 ? attachHttp(session.http, error) : error;
55
- }
56
- }
57
- function plan(session, table, options, mods, view) {
58
- const record = isRecord(options) ? options : {};
59
- rejectKeys(record, OPTIONS, "aggregate");
60
- const indexed = indexes(session.schema).get(table);
61
- if (indexed === undefined)
62
- fail("OKM1120", `Table ${table} is not in the schema.`);
63
- const spec = parse(indexed, record);
64
- if (spec.groups.length > 0 && record.limit === undefined && mods.all === undefined) {
65
- fail("OKM1101", "aggregate() with groupBy needs a limit, or .all(reason) for every group.");
66
- }
67
- const orderBy = record.orderBy;
68
- if (orderBy !== undefined) {
69
- if (!isRecord(orderBy))
70
- fail("OKM1120", "orderBy must be an object of fields.");
71
- for (const field of Object.keys(orderBy)) {
72
- const column = indexed.columns.get(field);
73
- if (column !== undefined)
74
- refuseHidden(column);
75
- if (!spec.groups.some((group) => group.field === field)) {
76
- throwNamed2("OKM1120", field, spec.groups.map((group) => group.field), `aggregate() orders by a groupBy field. Accepted names: ${list(spec.groups.map((group) => group.field))}.`);
77
- }
78
- }
79
- }
80
- if (record.limit !== undefined)
81
- readLimit(record.limit);
82
- const base = readCall("find", table, {
83
- where: record.where,
84
- orderBy,
85
- limit: record.limit,
86
- signal: record.signal,
87
- timeout: record.timeout,
88
- route: record.route
89
- }, mods.all, session.scope, session.schema.model[table], session.schema, view);
90
- const call = { ...base, op: "aggregate", build: statement(spec) };
91
- return readHandle(session, table, call, mods, (compiled, rows) => decode(compiled, rows));
92
- }
93
- function parse(table, record) {
94
- const groups = columns(table, record.groupBy, "groupBy");
95
- const count = record.count === true;
96
- if (record.count !== undefined && typeof record.count !== "boolean") {
97
- fail("OKM1120", "count is true when you want a row count.");
98
- }
99
- const calls = [];
100
- for (const { option, tag, numeric } of FUNCTIONS) {
101
- for (const column of columns(table, record[option], option)) {
102
- const fits = numeric ? NUMERIC.test(column.dataType) : !UNORDERED.test(column.dataType);
103
- if (!fits) {
104
- fail("OKM1124", `${option} does not apply to ${column.dataType} column ${column.field}. ${numeric ? "sum and avg take integer, real, and numeric columns." : "min and max need an ordered type."}`);
105
- }
106
- calls.push({ option, tag, column, decode: numeric ? sumDecode(column) : column.decode });
107
- }
108
- }
109
- if (!count && calls.length === 0 && groups.length === 0) {
110
- fail("OKM1120", "aggregate() needs count, sum, avg, min, max, or groupBy.");
111
- }
112
- return { groups, count, calls };
113
- }
114
- function sumDecode(column) {
115
- const kind = typeof (column.decode?.("0") ?? "");
116
- if (kind === "string")
117
- return AS_TEXT;
118
- if (kind === "number")
119
- return AS_NUMBER;
120
- return fail("OKM1124", `sum and avg need a column whose value is a number or a string. ${column.field} reads as ${kind}.`);
121
- }
122
- function columns(table, value, option) {
123
- if (value === undefined)
124
- return [];
125
- if (!Array.isArray(value))
126
- fail("OKM1120", `${option} must be a list of field names.`);
127
- const out = [];
128
- for (const name of value) {
129
- const column = typeof name === "string" ? table.columns.get(name) : undefined;
130
- if (typeof name !== "string" || column === undefined) {
131
- throwNamed2("OKM1120", String(name), table.names, `Field ${String(name)} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
132
- }
133
- if (column.hidden) {
134
- fail("OKM1120", `Field ${column.field} is hidden, so ${option} cannot read it.`);
135
- }
136
- out.push(column);
137
- }
138
- return out;
139
- }
140
- function statement(spec) {
141
- return (schema, table, sink, outputs, call) => {
142
- sink.mark(`aggregate|${table.model.name}|g:${spec.groups.map((column) => column.field).join(",")}|c:${String(spec.count)}|${spec.calls.map((item) => `${item.tag}:${item.column.field}`).join(",")}|`);
143
- sink.text("select ");
144
- const wrote = { at: 0 };
145
- for (const column of spec.groups) {
146
- put(sink, outputs, wrote, projectExpr(`t.${quote(column.sql)}`, column.dataType), {
147
- key: `g:${column.field}`,
148
- decode: column.decode
149
- });
150
- }
151
- if (spec.count)
152
- put(sink, outputs, wrote, "count(*)::text", { key: "c:", decode: undefined });
153
- for (const item of spec.calls) {
154
- const ref = `t.${quote(item.column.sql)}`;
155
- const expr = item.option === "sum" || item.option === "avg" ? `${item.option}(${ref})::text` : projectExpr(`${item.option}(${ref})`, item.column.dataType);
156
- put(sink, outputs, wrote, expr, {
157
- key: `${item.tag}:${item.column.field}`,
158
- decode: item.decode
159
- });
160
- }
161
- sink.text(" from ");
162
- sink.text(quote(table.model.sql));
163
- sink.text(" t");
164
- emitWhere(schema, table, call.where, sink, "t", 0);
165
- if (spec.groups.length > 0) {
166
- sink.text(" group by ");
167
- sink.text(spec.groups.map((column) => `t.${quote(column.sql)}`).join(", "));
168
- if (isRecord(call.orderBy) && Object.keys(call.orderBy).length > 0) {
169
- emitOrder(table, call.orderBy, sink, "t");
170
- } else {
171
- sink.text(" order by ");
172
- sink.text(spec.groups.map((column) => `t.${quote(column.sql)} asc nulls last`).join(", "));
173
- }
174
- }
175
- if (call.limit !== undefined) {
176
- const limit = String(call.limit);
177
- sink.text(" limit ");
178
- sink.param(limit);
179
- sink.mark(`l:${limit}`);
180
- }
181
- if (typeof call.all === "string")
182
- sink.mark(`all:${call.all}`);
183
- };
184
- }
185
- function put(sink, outputs, wrote, expr, out) {
186
- if (wrote.at > 0)
187
- sink.text(", ");
188
- sink.text(expr);
189
- outputs?.fields.push({ key: out.key, at: wrote.at, decode: out.decode });
190
- wrote.at += 1;
191
- }
192
- function decode(compiled, rows) {
193
- const items = [];
194
- for (const row of rows) {
195
- const item = {};
196
- for (const field of compiled.outputs.fields) {
197
- const value = row[field.at];
198
- const tag = field.key.slice(0, 2);
199
- const name = field.key.slice(2);
200
- if (tag === "g:") {
201
- item[name] = cell(value, field.decode);
202
- } else if (tag === "c:") {
203
- item.count = Number(value ?? 0);
204
- } else {
205
- const group = tag === "s:" ? "sum" : tag === "a:" ? "avg" : tag === "n:" ? "min" : "max";
206
- const into = item[group] ??= {};
207
- into[name] = cell(value, field.decode);
208
- }
209
- }
210
- items.push(item);
211
- }
212
- return items;
213
- }
214
- export {
215
- build
216
- };
@@ -1,6 +0,0 @@
1
- import {
2
- noTimeout2
3
- } from "./8dqhth8c.js";
4
- export {
5
- noTimeout2 as noTimeout
6
- };