okmodel 0.5.1 → 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 (233) hide show
  1. package/README.md +100 -1116
  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 +20 -0
  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 +41 -3
  14. package/dist/adapters/pg/reserved.d.ts +42 -0
  15. package/dist/adapters/pg/session.d.ts +0 -18
  16. package/dist/contracts/catalog/document.d.ts +19 -5
  17. package/dist/contracts/catalog/object.d.ts +2 -1
  18. package/dist/contracts/catalog/policy.d.ts +48 -0
  19. package/dist/contracts/catalog/types.d.ts +25 -1
  20. package/dist/contracts/catalog/view.d.ts +2 -0
  21. package/dist/contracts/connection.d.ts +7 -6
  22. package/dist/contracts/internal.js +1 -1
  23. package/dist/contracts/location.d.ts +10 -0
  24. package/dist/dialects/pg/column.d.ts +13 -2
  25. package/dist/dialects/pg/ddl.d.ts +37 -1
  26. package/dist/dialects/pg/emit.d.ts +19 -1
  27. package/dist/dialects/pg/errors.d.ts +32 -1
  28. package/dist/dialects/pg/ext/citext.js +1 -1
  29. package/dist/dialects/pg/ext/index.js +1 -1
  30. package/dist/dialects/pg/ext/pg-trgm.js +1 -1
  31. package/dist/dialects/pg/filter-parse.d.ts +5 -4
  32. package/dist/dialects/pg/floor.d.ts +68 -0
  33. package/dist/dialects/pg/fn/index.js +2 -2
  34. package/dist/dialects/pg/index.d.ts +8 -2
  35. package/dist/dialects/pg/index.js +67 -171
  36. package/dist/dialects/pg/introspect.d.ts +7 -0
  37. package/dist/dialects/pg/keys.d.ts +11 -8
  38. package/dist/dialects/pg/model.d.ts +47 -2
  39. package/dist/dialects/pg/morph.d.ts +43 -0
  40. package/dist/dialects/pg/operator-fit.d.ts +2 -2
  41. package/dist/dialects/pg/operators.d.ts +14 -7
  42. package/dist/dialects/pg/ops/bucket.d.ts +65 -0
  43. package/dist/dialects/pg/ops/inc.d.ts +2 -2
  44. package/dist/dialects/pg/ops/matches.d.ts +9 -12
  45. package/dist/dialects/pg/ops/relevance.d.ts +13 -0
  46. package/dist/dialects/pg/ops/search-query.d.ts +22 -0
  47. package/dist/dialects/pg/ops/window.d.ts +103 -0
  48. package/dist/dialects/pg/owner.d.ts +42 -0
  49. package/dist/dialects/pg/path-endpoint.d.ts +20 -0
  50. package/dist/dialects/pg/preset.d.ts +1 -1
  51. package/dist/dialects/pg/relations.d.ts +100 -3
  52. package/dist/dialects/pg/role/check.d.ts +3 -0
  53. package/dist/dialects/pg/role/index.d.ts +71 -6
  54. package/dist/dialects/pg/role/sql.d.ts +11 -0
  55. package/dist/dialects/pg/schema.d.ts +33 -3
  56. package/dist/dialects/pg/table.d.ts +25 -3
  57. package/dist/dialects/pg/tenancy.d.ts +45 -3
  58. package/dist/dialects/pg/view/client.d.ts +19 -1
  59. package/dist/dialects/pg/view/index.d.ts +4 -0
  60. package/dist/dialects/pg/view/index.js +21 -178
  61. package/dist/dialects/pg/view/refresh.d.ts +24 -0
  62. package/dist/runtime/aggregate.d.ts +8 -2
  63. package/dist/runtime/batch.d.ts +1 -1
  64. package/dist/runtime/bucket-group.d.ts +70 -0
  65. package/dist/runtime/conflict.d.ts +24 -6
  66. package/dist/runtime/drift.d.ts +9 -0
  67. package/dist/runtime/include.d.ts +0 -8
  68. package/dist/runtime/inflight.d.ts +14 -0
  69. package/dist/runtime/page.d.ts +4 -1
  70. package/dist/runtime/pg/bun.js +12 -5
  71. package/dist/runtime/pg/pg.js +5 -5
  72. package/dist/runtime/pg/pglite.d.ts +1 -0
  73. package/dist/runtime/pg/pglite.js +9 -8
  74. package/dist/runtime/pg/postgresjs.js +5 -5
  75. package/dist/runtime/plan.d.ts +113 -15
  76. package/dist/runtime/predicate.d.ts +19 -0
  77. package/dist/runtime/read-stream.d.ts +13 -16
  78. package/dist/runtime/result-name.d.ts +17 -0
  79. package/dist/runtime/safety/index.js +1 -1
  80. package/dist/runtime/server-check.d.ts +3 -3
  81. package/dist/runtime/sort-bind.d.ts +21 -0
  82. package/dist/runtime/sort.d.ts +56 -0
  83. package/dist/runtime/sync.d.ts +70 -0
  84. package/dist/runtime/tenancy/composite.d.ts +26 -0
  85. package/dist/runtime/tenancy/context.d.ts +16 -0
  86. package/dist/runtime/tenancy/index.d.ts +9 -5
  87. package/dist/runtime/tenancy/index.js +1511 -38
  88. package/dist/runtime/tenancy/path.d.ts +87 -0
  89. package/dist/runtime/tenancy/rls.d.ts +67 -0
  90. package/dist/runtime/tenancy/via.d.ts +22 -0
  91. package/dist/runtime/text-search.d.ts +20 -0
  92. package/dist/runtime/traits/index.d.ts +80 -0
  93. package/dist/runtime/traits/index.js +187 -17
  94. package/dist/runtime/tree.d.ts +38 -0
  95. package/dist/runtime/types.d.ts +231 -23
  96. package/dist/runtime/validate/index.js +4 -4
  97. package/dist/runtime/version.d.ts +39 -0
  98. package/dist/runtime/window.d.ts +21 -0
  99. package/dist/runtime/write.d.ts +55 -3
  100. package/dist/shared/{krxx77g0.js → 14vx95q4.js} +12 -18
  101. package/dist/shared/1est4ezg.js +313 -0
  102. package/dist/shared/{4az561fn.js → 1qa0qajz.js} +8 -23
  103. package/dist/shared/1w508jbr.js +1611 -0
  104. package/dist/shared/2c13q96h.js +18 -0
  105. package/dist/shared/2d3xq4ps.js +9 -0
  106. package/dist/shared/2shdbn8q.js +23 -0
  107. package/dist/shared/{t4tbsy9h.js → 358zsv4r.js} +1 -1
  108. package/dist/shared/3v7t1yrv.js +208 -0
  109. package/dist/shared/5e3tf63j.js +220 -0
  110. package/dist/shared/5fe3kbsh.js +10 -0
  111. package/dist/shared/5v3xf80k.js +37 -0
  112. package/dist/shared/{51mvgj8w.js → 63qtkrca.js} +130 -3
  113. package/dist/shared/{gbtcc2d7.js → 67txcrcw.js} +62 -66
  114. package/dist/shared/79dt02vc.js +12 -0
  115. package/dist/shared/{v36c5g6p.js → 7k9grvf6.js} +407 -14
  116. package/dist/shared/7kms6fvj.js +20 -0
  117. package/dist/shared/7mnme5tn.js +8 -0
  118. package/dist/shared/7n7ddwt4.js +6 -0
  119. package/dist/shared/{87jvvhnt.js → 81ebdx9p.js} +48 -68
  120. package/dist/shared/{szm0cksa.js → 8skf0cam.js} +34 -6
  121. package/dist/shared/{gjthds9j.js → 9628a9xt.js} +1 -1
  122. package/dist/shared/9a4ae4p8.js +31 -0
  123. package/dist/shared/{8xsbagad.js → 9s0ypp87.js} +88 -7
  124. package/dist/shared/9y3mmmh1.js +436 -0
  125. package/dist/shared/ab9gmbwy.js +213 -0
  126. package/dist/shared/{sycnx8gt.js → ax7qv55k.js} +18 -8
  127. package/dist/shared/{f5cw5q5r.js → aytqh5y2.js} +6 -4
  128. package/dist/shared/{fancm5pt.js → b5pftnn2.js} +138 -15
  129. package/dist/shared/{efmy2gcg.js → b76b8d95.js} +2 -2
  130. package/dist/shared/bdk4sty6.js +58 -0
  131. package/dist/shared/{32zqc1dw.js → bg3rym3g.js} +63 -32
  132. package/dist/shared/{0t22wwh1.js → bm22fvzr.js} +16 -14
  133. package/dist/shared/bz84tkzm.js +342 -0
  134. package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
  135. package/dist/shared/cn957f8d.js +179 -0
  136. package/dist/shared/{pf0d8f77.js → cnkky55j.js} +25 -14
  137. package/dist/shared/{5fqx9yh4.js → dk8v79p3.js} +3 -1
  138. package/dist/shared/{nkaxvt9q.js → dkxgzaqd.js} +224 -19
  139. package/dist/shared/dzj09cye.js +10 -0
  140. package/dist/shared/{4m9fn52z.js → ed0b8k4s.js} +1 -1
  141. package/dist/shared/{z2rnngj4.js → ek2wt2dz.js} +8 -5
  142. package/dist/shared/exn3sd90.js +359 -0
  143. package/dist/shared/g6evj1j3.js +66 -0
  144. package/dist/shared/ga9j92qj.js +25 -0
  145. package/dist/shared/{qv2ydck9.js → gs74dbj5.js} +651 -76
  146. package/dist/shared/gzaveazc.js +285 -0
  147. package/dist/shared/{8rsy3hxz.js → h15jx9bc.js} +1 -1
  148. package/dist/shared/{dyj86cmj.js → hyh73qk6.js} +3 -3
  149. package/dist/shared/je4axnm8.js +22 -0
  150. package/dist/shared/{ycatkxmq.js → jgqj11w4.js} +1 -1
  151. package/dist/shared/{6qd27mx0.js → jvd0mqag.js} +5 -5
  152. package/dist/shared/jznfax0y.js +155 -0
  153. package/dist/shared/{cgbamx3e.js → kb2sdhfb.js} +7 -4
  154. package/dist/shared/{ps7a6h14.js → kr0jzbw2.js} +12 -8
  155. package/dist/shared/{janx09m5.js → ktz42yez.js} +20 -8
  156. package/dist/shared/{gde73es6.js → m6p12kbr.js} +56 -55
  157. package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
  158. package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
  159. package/dist/shared/{nxdp2ze3.js → mtaszv5a.js} +144 -12
  160. package/dist/shared/n816peh1.js +45 -0
  161. package/dist/shared/nbw1z4yd.js +18 -0
  162. package/dist/shared/{cctw17hj.js → p6qc5gcp.js} +38 -34
  163. package/dist/shared/{6rk2gen5.js → pbp1ss85.js} +20 -17
  164. package/dist/shared/pt94kz7f.js +6 -0
  165. package/dist/shared/{wq9n6pwr.js → pz6rj8ay.js} +82 -9
  166. package/dist/shared/q5c6ngn3.js +13 -0
  167. package/dist/shared/{8bwbwy8h.js → qq3899ht.js} +128 -18
  168. package/dist/shared/{8ktwd3rh.js → r3j8s5y0.js} +1 -1
  169. package/dist/shared/rhs3xe4k.js +7 -0
  170. package/dist/shared/{ntneex2a.js → rpycarcr.js} +6 -6
  171. package/dist/shared/{sdc7r2ww.js → rs73fca9.js} +8 -8
  172. package/dist/shared/{tm5ab8we.js → sfz1ksn6.js} +7 -4
  173. package/dist/shared/{6mnp99hx.js → svncdeh5.js} +16 -12
  174. package/dist/shared/{hf22e0wt.js → tbrvgw6z.js} +62 -42
  175. package/dist/shared/te5as7z7.js +622 -0
  176. package/dist/shared/{ga3sfy93.js → tsvww22q.js} +535 -200
  177. package/dist/shared/{47x8x9ze.js → ttsqgp4p.js} +20 -13
  178. package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
  179. package/dist/shared/vb6qfyve.js +152 -0
  180. package/dist/shared/{r2sp8hrc.js → vczs8gd4.js} +22 -13
  181. package/dist/shared/{1g0drakv.js → vqrjpcqn.js} +145 -3
  182. package/dist/shared/{2pqx26h8.js → w72kgg4q.js} +31 -22
  183. package/dist/shared/{96qcj21c.js → w79hsckn.js} +16 -51
  184. package/dist/shared/wa07eas9.js +730 -0
  185. package/dist/shared/{k8v5v5wj.js → x933k9a3.js} +75 -34
  186. package/dist/shared/{cr74e96e.js → xhfsfkgk.js} +62 -28
  187. package/dist/shared/xjk7hnn5.js +272 -0
  188. package/dist/shared/{5enne4ma.js → xnxsed62.js} +66 -113
  189. package/dist/shared/xqve9598.js +53 -0
  190. package/dist/shared/{9x25fxhc.js → y34a8714.js} +1 -1
  191. package/dist/shared/{k7dwkhvq.js → y6jdds7g.js} +4 -1
  192. package/dist/shared/y6njgyda.js +249 -0
  193. package/dist/shared/{c9z5g0fm.js → ywr8hmey.js} +5 -2
  194. package/dist/shared/{g7ez901n.js → ywspezzx.js} +1 -1
  195. package/dist/shared/z7s6fpxv.js +62 -0
  196. package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
  197. package/dist/shared/{9m80mkac.js → ze4hxsmy.js} +1 -1
  198. package/dist/shared/zm0ptry0.js +40 -0
  199. package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
  200. package/dist/shared/zp9fmend.js +145 -0
  201. package/dist/shared/{y005b761.js → zy8r7qvz.js} +6 -2
  202. package/dist/tooling/cli.js +41 -15
  203. package/dist/tooling/migrate/apply.d.ts +14 -0
  204. package/dist/tooling/migrate/check.d.ts +3 -4
  205. package/dist/tooling/migrate/classify.d.ts +4 -0
  206. package/dist/tooling/migrate/config.d.ts +3 -2
  207. package/dist/tooling/migrate/engine.d.ts +3 -2
  208. package/dist/tooling/migrate/files.d.ts +11 -1
  209. package/dist/tooling/migrate/index.js +14 -14
  210. package/dist/tooling/migrate/lint.d.ts +1 -1
  211. package/dist/tooling/migrate/lost.d.ts +28 -0
  212. package/dist/tooling/migrate/paths.d.ts +14 -0
  213. package/dist/tooling/migrate/plan.d.ts +6 -3
  214. package/dist/tooling/migrate/runner.d.ts +25 -0
  215. package/dist/tooling/migrate/sandbox.d.ts +57 -0
  216. package/dist/tooling/migrate/sql-lex.d.ts +20 -3
  217. package/dist/tooling/migrate/text.d.ts +42 -0
  218. package/dist/tooling/node-version.d.ts +21 -0
  219. package/dist/tooling/testing/facts.d.ts +33 -5
  220. package/dist/tooling/testing/index.d.ts +1 -1
  221. package/dist/tooling/testing/index.js +3 -3
  222. package/dist/tooling/testing/isolation.d.ts +11 -5
  223. package/package.json +8 -3
  224. package/dist/shared/7m88x3e9.js +0 -45
  225. package/dist/shared/7zwwyh0v.js +0 -448
  226. package/dist/shared/aj2qxyhj.js +0 -90
  227. package/dist/shared/caw8b9d8.js +0 -204
  228. package/dist/shared/jwtxdj06.js +0 -76
  229. package/dist/shared/kfjp0gck.js +0 -212
  230. package/dist/shared/q58y17hy.js +0 -21
  231. package/dist/shared/qm7cdtvr.js +0 -912
  232. package/dist/shared/r8x5qhd7.js +0 -86
  233. package/dist/shared/zqrnhwsq.js +0 -31
@@ -0,0 +1,62 @@
1
+ import {
2
+ OkmError2
3
+ } from "./52szzakm.js";
4
+
5
+ // src/dialects/pg/view/refresh.ts
6
+ async function refreshView(session, name, concurrently) {
7
+ const host = asHost(session);
8
+ await host.connected;
9
+ const timeout = host.timeouts?.statement;
10
+ const options = timeout === undefined ? undefined : { timeout };
11
+ const text = `refresh materialized view${concurrently ? " concurrently" : ""} ${quote(name)}`;
12
+ const connection = await host.pool.reserve?.();
13
+ if (connection === undefined) {
14
+ throw new OkmError2("OKM1111", "Refresh needs a driver that can reserve a connection.", {
15
+ fix: { summary: "Use a Postgres driver that supports interactive transactions." }
16
+ });
17
+ }
18
+ try {
19
+ if (concurrently) {
20
+ await connection.execute("select set_config('app.unscoped', 'on', false)");
21
+ try {
22
+ await connection.execute(text, undefined, options);
23
+ } finally {
24
+ await connection.execute("select set_config('app.unscoped', '', false)").catch(() => {
25
+ return;
26
+ });
27
+ }
28
+ return;
29
+ }
30
+ await connection.execute("begin");
31
+ try {
32
+ await connection.execute("select set_config('app.unscoped', 'on', true)");
33
+ await connection.execute(text, undefined, options);
34
+ await connection.execute("commit");
35
+ } catch (error) {
36
+ await connection.execute("rollback").catch(() => {
37
+ return;
38
+ });
39
+ throw error;
40
+ }
41
+ } catch (error) {
42
+ const { mapPostgresError } = await import("./63qtkrca.js");
43
+ const mapped = mapPostgresError(error, {
44
+ ...host.http !== undefined ? { http: host.http } : {},
45
+ ...host.includeValues === true ? { includeValues: true } : {},
46
+ ...host.schema !== undefined ? { schema: host.schema } : {}
47
+ });
48
+ host.logger?.error?.({ code: mapped.code, summary: mapped.summary });
49
+ throw mapped;
50
+ } finally {
51
+ await connection.release();
52
+ }
53
+ }
54
+ function asHost(session) {
55
+ return session;
56
+ }
57
+ function quote(name) {
58
+ return `"${name.replaceAll('"', '""')}"`;
59
+ }
60
+ export {
61
+ refreshView
62
+ };
@@ -18,6 +18,7 @@ var FAMILIES = {
18
18
  hasAnyKey: ["jsonb"],
19
19
  path: ["json", "jsonb"],
20
20
  matches: ["tsvector"],
21
+ relevance: ["tsvector"],
21
22
  "json.set": ["json", "jsonb"],
22
23
  "arr.append": ["array"],
23
24
  "arr.remove": ["array"]
@@ -53,7 +54,7 @@ var ACCEPTED = {
53
54
  jsonb: ["eq", "not", "contains", "containedBy", "hasKey", "hasAnyKey", "path", "json.set"],
54
55
  json: ["eq", "not", "path", "json.set"],
55
56
  range: ["eq", "not", "lt", "lte", "gt", "gte", "contains", "containedBy", "overlaps"],
56
- tsvector: ["eq", "not", "matches"],
57
+ tsvector: ["eq", "not", "matches", "relevance"],
57
58
  scalar: ["eq", "not", "lt", "lte", "gt", "gte", "between", "inList", "notIn", "inc"]
58
59
  };
59
60
  var SAFE_TYPE = /^[A-Za-z_][A-Za-z0-9_]*(\(\d+\))?(\[\])*$/;
@@ -81,7 +82,7 @@ function assertOperatorFits(column, name) {
81
82
  if (families.includes(columnFamily(column.dataType)))
82
83
  return;
83
84
  const accepted = ACCEPTED[columnFamily(column.dataType)];
84
- const search = name === "matches" && columnFamily(column.dataType) === "text" ? " Text search needs a tsvector column." : "";
85
+ const search = (name === "matches" || name === "relevance") && columnFamily(column.dataType) === "text" ? " Search needs a column built for search, not a plain text column." : "";
85
86
  throw new OkmError2("OKM1124", `Operator ${name} does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${accepted.join(", ")}.${search}`, { fix: { summary: `Use one of: ${accepted.join(", ")}.` } });
86
87
  }
87
88
  function sqlType(dataType, column) {
@@ -110,7 +111,7 @@ function assertBoundText(value, role) {
110
111
  }
111
112
  function assertRegconfig(config) {
112
113
  if (!REGCONFIG.test(config)) {
113
- throw new OkmError2("OKM1122", `Text search config ${config} must be a regconfig name such as english or pg_catalog.simple.`, { fix: { summary: "Pass a regconfig name. Quotes and extra clauses are not accepted." } });
114
+ throw new OkmError2("OKM1122", `Language ${config} is not a text search language. Pass a name such as english.`, { fix: { summary: "Pass a language name such as english." } });
114
115
  }
115
116
  }
116
117
  function textArray(values, role) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ColumnBuilder2
3
- } from "./c9z5g0fm.js";
3
+ } from "./ywr8hmey.js";
4
4
  import {
5
5
  definition
6
6
  } from "./tmbdywx0.js";
@@ -0,0 +1,40 @@
1
+ import {
2
+ isConnectionLost
3
+ } from "./cnkky55j.js";
4
+ import {
5
+ rejectClosed
6
+ } from "./kb2sdhfb.js";
7
+
8
+ // src/adapters/pg/reserved.ts
9
+ var RESET_ALL = "RESET ALL";
10
+ var UNLOCK = "SELECT pg_advisory_unlock_all()";
11
+ async function resetSession2(depth, run) {
12
+ if (depth > 0)
13
+ await run("ROLLBACK").catch(() => {
14
+ return;
15
+ });
16
+ try {
17
+ await run(RESET_ALL);
18
+ await run(UNLOCK);
19
+ } catch {
20
+ await run("ROLLBACK").catch(() => {
21
+ return;
22
+ });
23
+ await run(RESET_ALL);
24
+ await run(UNLOCK);
25
+ }
26
+ }
27
+ async function resetQueried2(session) {
28
+ await resetSession2(session.inTransaction() ? 1 : 0, (text) => text === "ROLLBACK" ? session.rollback() : session.query(text, undefined, undefined));
29
+ }
30
+ function refuseWhenLost2(lost, run) {
31
+ if (lost.on)
32
+ return rejectClosed();
33
+ return run().catch((error) => {
34
+ if (isConnectionLost(error))
35
+ lost.on = true;
36
+ throw error;
37
+ });
38
+ }
39
+
40
+ export { resetSession2, resetQueried2, refuseWhenLost2 };
@@ -13,6 +13,9 @@ var RESERVED_PRESETS = new Set([
13
13
  "insert",
14
14
  "update",
15
15
  "delete",
16
+ "descendants",
17
+ "ancestors",
18
+ "sync",
16
19
  "archive",
17
20
  "restore",
18
21
  "withArchived",
@@ -0,0 +1,145 @@
1
+ import {
2
+ DriverError2
3
+ } from "./cm3w0ywp.js";
4
+ import {
5
+ armDriverError,
6
+ send,
7
+ connectClient
8
+ } from "./w79hsckn.js";
9
+ import {
10
+ resetSession2
11
+ } from "./zm0ptry0.js";
12
+ import {
13
+ cursorStream
14
+ } from "./7kms6fvj.js";
15
+ import {
16
+ isConnectionLost
17
+ } from "./cnkky55j.js";
18
+ import {
19
+ WireSession
20
+ } from "./1qa0qajz.js";
21
+ import {
22
+ rejectClosed,
23
+ runCall
24
+ } from "./kb2sdhfb.js";
25
+
26
+ // src/adapters/pg/nodepostgres-extra.ts
27
+ async function checkout(held) {
28
+ const { pool, counters, named, isClosed } = held;
29
+ if (isClosed())
30
+ return rejectClosed();
31
+ const client = await connectClient(pool, held.acquireMs, counters);
32
+ counters.reserved += 1;
33
+ let lost = false;
34
+ const onError = () => {
35
+ lost = true;
36
+ };
37
+ const events = client;
38
+ events.on("error", onError);
39
+ const local = new Set;
40
+ const session = new WireSession((text, params) => {
41
+ const pending = send(client, text, params, named, client);
42
+ const guarded = pending.catch((error) => {
43
+ if (isConnectionLost(error) || lost) {
44
+ lost = true;
45
+ if (isConnectionLost(error))
46
+ throw error;
47
+ throw Object.assign(new DriverError2("CONNECTION_CLOSED", { cause: error }), {
48
+ code: "CONNECTION_CLOSED"
49
+ });
50
+ }
51
+ throw error;
52
+ });
53
+ guarded.cancel = () => {
54
+ pending.cancel?.();
55
+ };
56
+ return guarded;
57
+ }, held.notices, isClosed, true, () => {
58
+ counters.reservedBusy += 1;
59
+ }, () => {
60
+ counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
61
+ }, local);
62
+ const guard = (run) => lost ? rejectClosed() : run();
63
+ let released = false;
64
+ return {
65
+ execute: (text, params, options) => guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch))),
66
+ batch: (statements, options) => guard(() => runCall(isClosed(), options, async (watch) => {
67
+ const { runAtomicBatch } = await import("./b76b8d95.js");
68
+ return runAtomicBatch(session, statements, watch);
69
+ })),
70
+ cancel() {
71
+ session.cancel();
72
+ },
73
+ async release() {
74
+ if (released)
75
+ return;
76
+ released = true;
77
+ try {
78
+ if (!lost)
79
+ await reset(session, client);
80
+ } finally {
81
+ counters.reserved = Math.max(0, counters.reserved - 1);
82
+ events.removeListener("error", onError);
83
+ client.release(lost);
84
+ }
85
+ }
86
+ };
87
+ }
88
+ async function reset(session, client) {
89
+ await resetSession2(session.depth(), (text) => client.query(text));
90
+ }
91
+ async function listen(held, channel, onNotify) {
92
+ const { pool, counters } = held;
93
+ const client = await connectClient(pool, held.acquireMs, counters);
94
+ counters.reserved += 1;
95
+ const quoted = quoteIdent(channel);
96
+ const onNotification = (message) => {
97
+ if (message.channel === channel)
98
+ onNotify(message.payload ?? "");
99
+ };
100
+ client.on("notification", onNotification);
101
+ let released = false;
102
+ const release = (dead) => {
103
+ if (released)
104
+ return;
105
+ released = true;
106
+ client.removeListener("notification", onNotification);
107
+ client.removeListener("error", release);
108
+ counters.reserved = Math.max(0, counters.reserved - 1);
109
+ client.release(Boolean(dead));
110
+ };
111
+ armDriverError(client, release);
112
+ try {
113
+ await client.query(`LISTEN ${quoted}`);
114
+ } catch (error) {
115
+ release(false);
116
+ throw error;
117
+ }
118
+ return async () => {
119
+ if (released)
120
+ return;
121
+ try {
122
+ await client.query(`UNLISTEN ${quoted}`);
123
+ } finally {
124
+ release(false);
125
+ }
126
+ };
127
+ }
128
+ function streamRows(checkout, text, params) {
129
+ return async function* () {
130
+ const connection = await checkout();
131
+ try {
132
+ yield* cursorStream((statement, values) => connection.execute(statement, values), text, params);
133
+ } finally {
134
+ await connection.release();
135
+ }
136
+ }();
137
+ }
138
+ function quoteIdent(name) {
139
+ return `"${name.replaceAll('"', '""')}"`;
140
+ }
141
+ export {
142
+ checkout,
143
+ listen,
144
+ streamRows
145
+ };
@@ -3,7 +3,7 @@ import {
3
3
  assertNamespace2,
4
4
  normaliseEdges,
5
5
  assertProvenance
6
- } from "./t4tbsy9h.js";
6
+ } from "./358zsv4r.js";
7
7
  import {
8
8
  assertIdentifier2,
9
9
  fitIdentifier2,
@@ -23,7 +23,11 @@ function viewObject(input) {
23
23
  const query = readQuery(input.name, input.query);
24
24
  assertNamespace2(namespace);
25
25
  assertProvenance(input.provenance);
26
- const definition = { columns, query };
26
+ const definition = {
27
+ columns,
28
+ query,
29
+ ...input.securityInvoker === true ? { securityInvoker: true } : {}
30
+ };
27
31
  return {
28
32
  kind: "view",
29
33
  identity: { kind: "view", namespace, name: input.name },
@@ -1,6 +1,6 @@
1
- import"../shared/8bwbwy8h.js";
1
+ import"../shared/qq3899ht.js";
2
2
  import"../shared/n442h54c.js";
3
- import"../shared/krxx77g0.js";
3
+ import"../shared/14vx95q4.js";
4
4
  import {
5
5
  formatFindings,
6
6
  hasError,
@@ -9,9 +9,11 @@ import {
9
9
  generateProject,
10
10
  planProject,
11
11
  checkProject
12
- } from "../shared/qv2ydck9.js";
13
- import"../shared/ga3sfy93.js";
14
- import"../shared/8xsbagad.js";
12
+ } from "../shared/gs74dbj5.js";
13
+ import {
14
+ sessionFailure
15
+ } from "../shared/tsvww22q.js";
16
+ import"../shared/9s0ypp87.js";
15
17
  import {
16
18
  OkmError2
17
19
  } from "../shared/52szzakm.js";
@@ -23,7 +25,7 @@ import { fileURLToPath } from "node:url";
23
25
 
24
26
  // src/tooling/migrate/commands.ts
25
27
  function formatFailure(error, verbose = false) {
26
- const mapped = OkmError2.from(error);
28
+ const mapped = sessionFailure(error) ?? OkmError2.from(error);
27
29
  let text = `error ${mapped.code}: ${mapped.message}
28
30
  ${mapped.fix.summary}
29
31
  `;
@@ -71,12 +73,12 @@ async function run(argv, io) {
71
73
  return;
72
74
  }
73
75
  if (command === "dev") {
74
- const { devProject } = await import("../shared/sdc7r2ww.js");
76
+ const { devProject } = await import("../shared/rs73fca9.js");
75
77
  stdout(await devProject(cwd));
76
78
  return;
77
79
  }
78
80
  if (command === "push") {
79
- const { pushProject } = await import("../shared/q58y17hy.js");
81
+ const { pushProject } = await import("../shared/2shdbn8q.js");
80
82
  stdout(await pushProject(cwd, invoke(splitFlags(rest))));
81
83
  return;
82
84
  }
@@ -95,17 +97,17 @@ async function run(argv, io) {
95
97
  return;
96
98
  }
97
99
  if (sub === "apply") {
98
- const { applyProject } = await import("../shared/q58y17hy.js");
100
+ const { applyProject } = await import("../shared/2shdbn8q.js");
99
101
  stdout(await applyProject(cwd, invoke(parsed), stdout));
100
102
  return;
101
103
  }
102
104
  if (sub === "status") {
103
- const { statusProject } = await import("../shared/6mnp99hx.js");
105
+ const { statusProject } = await import("../shared/svncdeh5.js");
104
106
  stdout(await statusProject(cwd, invoke(parsed)));
105
107
  return;
106
108
  }
107
109
  if (sub === "check") {
108
- const { checkMigrations } = await import("../shared/7zwwyh0v.js");
110
+ const { checkMigrations } = await import("../shared/wa07eas9.js");
109
111
  const provision = parsed.flags.includes("--provision") || rest.slice(1).includes("--provision");
110
112
  stdout(await checkMigrations(cwd, invoke(parsed), { provision }));
111
113
  return;
@@ -118,13 +120,13 @@ async function run(argv, io) {
118
120
  fix: { summary: "Pass okm seed <file>." }
119
121
  });
120
122
  }
121
- const { seedProject } = await import("../shared/2pqx26h8.js");
123
+ const { seedProject } = await import("../shared/w72kgg4q.js");
122
124
  stdout(await seedProject(cwd, parsed.name, invoke(parsed)));
123
125
  return;
124
126
  }
125
127
  if (command === "doctor") {
126
128
  const parsed = splitFlags(rest);
127
- const { doctorProject } = await import("../shared/ps7a6h14.js");
129
+ const { doctorProject } = await import("../shared/kr0jzbw2.js");
128
130
  stdout(await doctorProject(cwd, parsed.name, invoke(parsed)));
129
131
  return;
130
132
  }
@@ -136,7 +138,7 @@ async function run(argv, io) {
136
138
  });
137
139
  }
138
140
  if (sub === "list" || sub === "check") {
139
- const { extProject } = await import("../shared/janx09m5.js");
141
+ const { extProject } = await import("../shared/ktz42yez.js");
140
142
  stdout(await extProject(cwd, sub, invoke(splitFlags(rest.slice(1)))));
141
143
  return;
142
144
  }
@@ -270,10 +272,34 @@ function numberFlag(flag, value) {
270
272
  return parsed;
271
273
  }
272
274
 
275
+ // src/tooling/node-version.ts
276
+ function nodeSupportsConfigTypes(version) {
277
+ const match = /^v(\d+)\.(\d+)/.exec(version);
278
+ if (match === null)
279
+ return false;
280
+ const major = Number(match[1]);
281
+ const minor = Number(match[2]);
282
+ if (major > 22)
283
+ return true;
284
+ if (major < 22)
285
+ return false;
286
+ return minor >= 18;
287
+ }
288
+ function nodeStartupMessage(version, bunRuntime) {
289
+ if (bunRuntime || nodeSupportsConfigTypes(version))
290
+ return;
291
+ return `okm needs Node.js >=22.18 to load a .ts config (type stripping). This process is ${version}. Run bun --bun okm to use the Bun runtime.
292
+ `;
293
+ }
294
+
273
295
  // src/tooling/cli.ts
274
296
  var here = dirname(fileURLToPath(import.meta.url));
275
297
  var packageJsonPath = join(here, "..", "..", "package.json");
276
- if (process.argv.includes("--version")) {
298
+ var nodeProblem = nodeStartupMessage(process.version, process.versions.bun !== undefined);
299
+ if (nodeProblem !== undefined) {
300
+ process.stderr.write(nodeProblem);
301
+ process.exitCode = 1;
302
+ } else if (process.argv.includes("--version")) {
277
303
  process.stdout.write(`${readPackageVersion(packageJsonPath)}
278
304
  `);
279
305
  } else {
@@ -49,6 +49,14 @@ export type ApplyRequest = {
49
49
  * `SET ROLE` before any statement. That statement is not a plan step.
50
50
  */
51
51
  readonly migrationRole?: string;
52
+ /**
53
+ * Application role.
54
+ *
55
+ * After the plan, this role receives `SELECT` on `okm_meta` and nothing
56
+ * else. `connect()` can then read the stored hash. Check scratch paths
57
+ * leave this unset.
58
+ */
59
+ readonly appRole?: string;
52
60
  /**
53
61
  * Schema the migration role may create in.
54
62
  *
@@ -95,6 +103,12 @@ export type ApplyReport = {
95
103
  /** Set when the runner issued `SET ROLE` at session start. */
96
104
  readonly setRole?: string;
97
105
  };
106
+ /**
107
+ * Creates `okm_meta`, `okm_history`, and `okm_backfill` when they are absent.
108
+ *
109
+ * @param execute - Runs one statement on the apply or check connection
110
+ */
111
+ export declare function ensureMigrationTables(execute: (sql: string) => Promise<unknown>): Promise<void>;
98
112
  /**
99
113
  * Groups pending steps into the transactions apply will run.
100
114
  *
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * `okm migrate check` proves a migration history is sound (D196).
3
3
  *
4
- * The command replays every file into a scratch schema through
5
- * {@link applyTarget}, then plans the introspected schema back to that
6
- * file's catalog. It also checks the previous catalog, the head, and the
7
- * linter. Nothing here changes apply.
4
+ * The command replays every file into a scratch schema inside one transaction
5
+ * and rolls that transaction back. It also checks the previous catalog, the
6
+ * head, and the linter. Nothing here changes apply.
8
7
  */
9
8
  import type { Catalog } from "../../contracts/catalog/types.js";
10
9
  import { type MigrationClass } from "./classify.js";
@@ -76,6 +76,10 @@ export declare const STEP_CLASS: {
76
76
  readonly "rename-sequence": "contract";
77
77
  readonly "backfill-expand": "expand";
78
78
  readonly "backfill-contract": "contract";
79
+ readonly "enable-rls": "expand";
80
+ readonly "create-policy": "expand";
81
+ readonly "drop-policy": "contract";
82
+ readonly "disable-rls": "contract";
79
83
  readonly "raw-sql": "unclassified";
80
84
  };
81
85
  /** A planner operation. */
@@ -59,10 +59,11 @@ export type MigrateConfig = {
59
59
  readonly statementTimeoutMs?: number;
60
60
  };
61
61
  /**
62
- * Migration role and application role.
62
+ * Migration role, application role, and the optional reporting role.
63
63
  *
64
64
  * A name is external unless it is also listed in `managed`. The plan creates
65
- * a managed role and never drops one.
65
+ * a managed role and never drops one. `reporting` receives select only.
66
+ * `columns` grants select or update on named columns.
66
67
  */
67
68
  readonly roles?: RolesInput;
68
69
  };
@@ -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";
@@ -2,7 +2,7 @@
2
2
  * Migration files on disk: SQL from {@link formatPlan} plus the catalog hash.
3
3
  */
4
4
  import { parseCatalog } from "../../contracts/catalog/document.js";
5
- import { type PlanStep } from "./plan.js";
5
+ import { type MigrationPlan, type PlanStep } from "./plan.js";
6
6
  /** One migration the applier can run and resume. */
7
7
  export type StoredMigration = {
8
8
  readonly id: string;
@@ -25,6 +25,16 @@ export type StoredMigration = {
25
25
  * @returns Migrations in apply order
26
26
  */
27
27
  export declare function loadMigrations(directory: string): readonly StoredMigration[];
28
+ /**
29
+ * Reads one migration SQL file.
30
+ *
31
+ * Line endings and a UTF-8 BOM are normalized. A non-empty file with no steps
32
+ * and no `-- no steps` line is refused.
33
+ *
34
+ * @param path - `*.sql` path
35
+ * @returns The plan
36
+ */
37
+ export declare function readMigrationPlan(path: string): MigrationPlan;
28
38
  /**
29
39
  * Loads the last migration's catalog, which is the head snapshot.
30
40
  *
@@ -1,26 +1,27 @@
1
- import"../../shared/krxx77g0.js";
2
- import"../../shared/8bwbwy8h.js";
1
+ import"../../shared/14vx95q4.js";
2
+ import"../../shared/qq3899ht.js";
3
3
  import"../../shared/n442h54c.js";
4
4
  import {
5
5
  applyTarget2,
6
6
  backfillTiming2
7
- } from "../../shared/cctw17hj.js";
7
+ } from "../../shared/p6qc5gcp.js";
8
8
  import {
9
- loadMigrations,
10
- loadHeadSnapshot,
11
9
  readReference
12
- } from "../../shared/gde73es6.js";
13
- import"../../shared/szm0cksa.js";
14
- import"../../shared/fancm5pt.js";
10
+ } from "../../shared/m6p12kbr.js";
11
+ import"../../shared/8skf0cam.js";
12
+ import"../../shared/b5pftnn2.js";
15
13
  import {
14
+ projectPath,
15
+ loadMigrations,
16
+ loadHeadSnapshot,
16
17
  loadBuiltSchema,
17
18
  loadConfig
18
- } from "../../shared/qv2ydck9.js";
19
+ } from "../../shared/gs74dbj5.js";
19
20
  import {
20
21
  assertTargetPolicy,
21
22
  selectTarget
22
- } from "../../shared/ga3sfy93.js";
23
- import"../../shared/8xsbagad.js";
23
+ } from "../../shared/tsvww22q.js";
24
+ import"../../shared/9s0ypp87.js";
24
25
  import {
25
26
  OkmError2
26
27
  } from "../../shared/52szzakm.js";
@@ -30,12 +31,11 @@ function defineConfig(config) {
30
31
  return config;
31
32
  }
32
33
  // src/tooling/migrate/provision.ts
33
- import { join } from "node:path";
34
34
  async function provision(target, cwd = process.cwd()) {
35
35
  const config = await loadConfig(cwd);
36
36
  const selected = selectTarget(config, target);
37
37
  assertTargetPolicy(selected, "provision");
38
- const directory = join(cwd, config.migrations ?? "migrations");
38
+ const directory = projectPath(cwd, config.migrations ?? "migrations");
39
39
  const migrations = loadMigrations(directory);
40
40
  const head = loadHeadSnapshot(directory);
41
41
  if (head === undefined) {
@@ -58,7 +58,7 @@ async function provision(target, cwd = process.cwd()) {
58
58
  reference: readReference(built.tables, built.casing, head.catalog),
59
59
  only: true
60
60
  },
61
- ...config.roles !== undefined ? { migrationRole: config.roles.migration } : {},
61
+ ...config.roles !== undefined ? { migrationRole: config.roles.migration, appRole: config.roles.app } : {},
62
62
  lintDirectory: directory
63
63
  });
64
64
  if (report.applied.length === 0)
@@ -8,7 +8,7 @@
8
8
  import type { Catalog } from "../../contracts/catalog/types.js";
9
9
  import { OkmError } from "../../contracts/error.js";
10
10
  import { type LintSeverity } from "./lint-rules.js";
11
- import { type MigrationPlan } from "./plan.js";
11
+ import type { MigrationPlan } from "./plan.js";
12
12
  /** One finding. `place` is `step N`, `step N statement M`, or `table.column`. */
13
13
  export type Finding = {
14
14
  readonly severity: LintSeverity;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A session that dies in the middle of a command.
3
+ *
4
+ * A commit that was sent and never answered stays OKM1401. Every other
5
+ * dropped connection is unavailable. Cleanup that throws is ignored so the
6
+ * original failure is the one the command reports.
7
+ */
8
+ import { OkmError } from "../../contracts/error.js";
9
+ /**
10
+ * Maps a lost session to unavailable or OKM1401.
11
+ *
12
+ * An {@link OkmError} that already has one of those kinds is returned. An
13
+ * `invalid` error whose cause is a lost session keeps its message and takes
14
+ * that kind. Anything else returns `undefined`.
15
+ *
16
+ * @param error - Caught value
17
+ * @returns The session failure, or `undefined` when this is some other error
18
+ */
19
+ export declare function sessionFailure(error: unknown): OkmError | undefined;
20
+ /**
21
+ * Runs cleanup and ignores its failure.
22
+ *
23
+ * A dead session must not replace the error the command is already reporting,
24
+ * and it must not leave the process waiting on that session.
25
+ *
26
+ * @param run - Close, release, or unlock
27
+ */
28
+ export declare function finishQuiet(run: () => Promise<unknown>): Promise<void>;