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
@@ -1,51 +1,55 @@
1
1
  import {
2
2
  open2
3
- } from "./krxx77g0.js";
3
+ } from "./14vx95q4.js";
4
4
  import {
5
5
  startupHash2
6
- } from "./8bwbwy8h.js";
6
+ } from "./qq3899ht.js";
7
7
  import {
8
8
  runTarget,
9
9
  assumeRole,
10
+ grantAppMeta,
10
11
  statementOutsideTransaction,
11
- loadMigrations,
12
- loadHeadSnapshot,
13
12
  readReference,
14
13
  referenceInserts,
15
14
  provisionMark,
16
15
  expandProvisioned,
17
16
  installSnapshot
18
- } from "./gde73es6.js";
17
+ } from "./m6p12kbr.js";
19
18
  import {
20
19
  assertCreateRole,
21
20
  currentUser,
22
21
  roleExists
23
- } from "./szm0cksa.js";
22
+ } from "./8skf0cam.js";
24
23
  import {
24
+ projectPath,
25
+ loadMigrations,
26
+ loadHeadSnapshot,
25
27
  lintMigrationDirectory,
26
28
  hasError,
27
29
  lintRefusal,
28
30
  projectHead,
29
31
  loadBuiltSchema,
30
32
  loadConfig
31
- } from "./qv2ydck9.js";
33
+ } from "./gs74dbj5.js";
32
34
  import {
33
35
  changesRole,
34
36
  batchSizeField,
35
37
  assertExtensionsAvailable,
36
38
  planMigration,
39
+ finishQuiet,
37
40
  assertTargetPolicy,
38
41
  assertDirectConnection,
39
42
  assertStableBackend,
40
43
  selectTarget
41
- } from "./ga3sfy93.js";
44
+ } from "./tsvww22q.js";
45
+ import {
46
+ UUIDV7_POSTGRES,
47
+ uuidv7NeedsPostgres
48
+ } from "./ga9j92qj.js";
42
49
  import {
43
50
  OkmError2
44
51
  } from "./52szzakm.js";
45
52
 
46
- // src/tooling/migrate/apply.ts
47
- import { join } from "node:path";
48
-
49
53
  // src/tooling/migrate/engine.ts
50
54
  var IDENT = String.raw`"(?:[^"]|"")+"|[A-Za-z_][\w$]*`;
51
55
  var DEFAULT_UUIDV7 = /\bdefault\s+uuidv7\s*\(\s*\)/i;
@@ -70,14 +74,11 @@ async function assertUuidV7Available(connection, migrations) {
70
74
  const row = result.rows[0];
71
75
  const major = Math.floor(Number(row?.[0] ?? "0") / 1e4);
72
76
  const defined = row?.[1] !== null && row?.[1] !== undefined;
73
- if (major >= 18 || defined)
77
+ if (major >= UUIDV7_POSTGRES || defined)
74
78
  return;
75
79
  const where = found.column === undefined ? "A column" : `Column ${found.column}`;
76
- throw new OkmError2("OKM1812", `${where} has a uuidv7() default (migration ${found.migrationId}, step ${String(found.stepIndex)}), and the server is PostgreSQL ${String(major)}. uuidv7() arrives in PostgreSQL 18. Nothing was changed.`, {
77
- fix: {
78
- summary: 'Either run PostgreSQL 18 and declare schema({ requires: { postgres: ">=18" } }), or use t.id({ default: "uuidv4" }) (or schema({ defaults: { id: "uuidv4" } })), which uses gen_random_uuid() and works on PostgreSQL 13 and newer. Then delete the migration that was not applied and generate it again.'
79
- }
80
- });
80
+ const message = `${where} has a uuidv7() default (migration ${found.migrationId}, step ${String(found.stepIndex)}), and the server is PostgreSQL ${String(major)}. ${uuidv7NeedsPostgres()} Nothing was changed.`;
81
+ throw new OkmError2("OKM1812", message, { fix: { summary: uuidv7NeedsPostgres() } });
81
82
  }
82
83
  function columnOf(sql) {
83
84
  const table = TABLE.exec(sql)?.[1];
@@ -121,6 +122,11 @@ var BACKFILL = `create table if not exists okm_backfill (
121
122
  updated_at timestamptz not null default now(),
122
123
  primary key (migration_id, step_index)
123
124
  )`;
125
+ async function ensureMigrationTables2(execute) {
126
+ await execute(META);
127
+ await execute(HISTORY);
128
+ await execute(BACKFILL);
129
+ }
124
130
  function applyUnits(migration, done) {
125
131
  const pending = [];
126
132
  for (let index = 0;index < migration.steps.length; index += 1) {
@@ -175,7 +181,8 @@ async function applyTarget2(request) {
175
181
  fix: { summary: "Apply needs a driver with interactive transactions." }
176
182
  });
177
183
  }
178
- const connection = await pool.reserve();
184
+ const reserved = await pool.reserve();
185
+ const connection = reserved;
179
186
  let locked = false;
180
187
  try {
181
188
  await assertStableBackend(() => backendPid(connection), request.allowPooler === true);
@@ -202,9 +209,7 @@ async function applyTarget2(request) {
202
209
  throw notEmpty(request.target, state.kind === "occupied" ? state.object : "okm_meta");
203
210
  }
204
211
  }
205
- await connection.execute(META);
206
- await connection.execute(HISTORY);
207
- await connection.execute(BACKFILL);
212
+ await ensureMigrationTables2((sql) => connection.execute(sql));
208
213
  const restamped = await restampLegacy(connection, request);
209
214
  const history = await readHistory(connection);
210
215
  const done = expandProvisioned(request.migrations, history.done, history.ids);
@@ -225,14 +230,14 @@ async function applyTarget2(request) {
225
230
  if (request.snapshot !== undefined) {
226
231
  await insertReference(connection, request);
227
232
  }
233
+ await grantAppMeta(connection, request.appRole, session);
228
234
  return restamped.length === 0 ? report : { ...report, restamped };
229
235
  } finally {
230
- if (locked)
231
- await connection.execute("select pg_advisory_unlock(hashtext($1))", [
232
- lockKey(request.target)
233
- ]);
234
- await connection.release();
235
- await pool.close();
236
+ if (locked) {
237
+ await finishQuiet(() => connection.execute("select pg_advisory_unlock(hashtext($1))", [lockKey(request.target)]));
238
+ }
239
+ await finishQuiet(() => connection.release());
240
+ await finishQuiet(() => pool.close());
236
241
  }
237
242
  }
238
243
  async function applyProject2(cwd, flags, write) {
@@ -267,7 +272,7 @@ nothing to apply
267
272
  catalogHash: head.catalogHash,
268
273
  reference: built === undefined ? [] : readReference(built.tables, built.casing, head.catalog)
269
274
  },
270
- ...config.roles !== undefined ? { migrationRole: config.roles.migration } : {},
275
+ ...config.roles !== undefined ? { migrationRole: config.roles.migration, appRole: config.roles.app } : {},
271
276
  lintDirectory: directory,
272
277
  onProgress: (line) => {
273
278
  if (write !== undefined)
@@ -314,7 +319,7 @@ no changes
314
319
  steps: plan.steps
315
320
  }
316
321
  ],
317
- ...config.roles !== undefined ? { migrationRole: config.roles.migration } : {}
322
+ ...config.roles !== undefined ? { migrationRole: config.roles.migration, appRole: config.roles.app } : {}
318
323
  });
319
324
  return formatReport(report);
320
325
  }
@@ -380,7 +385,7 @@ var RESTAMP = `with pairs as (
380
385
  )
381
386
  select distinct id from history order by id`;
382
387
  function joinMigrations(cwd, migrations) {
383
- return join(cwd, migrations ?? "migrations");
388
+ return projectPath(cwd, migrations ?? "migrations");
384
389
  }
385
390
  async function backendPid(connection) {
386
391
  const result = await connection.execute("select pg_backend_pid()::text");
@@ -464,10 +469,9 @@ async function provisionEmpty(connection, request, session) {
464
469
  assertTargetPolicy({ name: request.target, protected: request.protected }, "reference", request.allowProtected === true);
465
470
  }
466
471
  const schema = concreteSchema(request);
467
- await connection.execute(META);
468
- await connection.execute(HISTORY);
469
- await connection.execute(BACKFILL);
472
+ await ensureMigrationTables2((sql) => connection.execute(sql));
470
473
  await installSnapshot(connection, snapshot.catalog, schema, snapshot.reference, session, request.migrationRole);
474
+ await grantAppMeta(connection, request.appRole, session);
471
475
  const mark = provisionMark(snapshot.migrationId);
472
476
  await connection.execute("begin");
473
477
  try {
@@ -601,4 +605,4 @@ function wireTrue(value) {
601
605
  return value === "t" || value === "true";
602
606
  }
603
607
 
604
- export { applyTarget2, applyProject2, pushProject2, backfillTiming2 };
608
+ export { ensureMigrationTables2, applyTarget2, applyProject2, pushProject2, backfillTiming2 };
@@ -3,7 +3,7 @@ import {
3
3
  readHandle,
4
4
  readCall,
5
5
  attachHttp
6
- } from "./hf22e0wt.js";
6
+ } from "./tbrvgw6z.js";
7
7
  import {
8
8
  selectedColumns,
9
9
  parseOrder,
@@ -14,8 +14,8 @@ import {
14
14
  list,
15
15
  isRecord,
16
16
  registerFailFix,
17
- fail
18
- } from "./gbtcc2d7.js";
17
+ fail2
18
+ } from "./67txcrcw.js";
19
19
  import {
20
20
  OkmError2,
21
21
  throwNamed2
@@ -34,21 +34,24 @@ var OPTIONS = [
34
34
  "signal",
35
35
  "timeout"
36
36
  ];
37
- function build(session, table, options, mods, view) {
37
+ function build3(session, table, options, mods, view, pin) {
38
38
  try {
39
- return plan(session, table, options, mods, view);
39
+ return plan(session, table, options, mods, view, pin);
40
40
  } catch (error) {
41
41
  throw error instanceof OkmError2 ? attachHttp(session.http, error) : error;
42
42
  }
43
43
  }
44
- function plan(session, table, options, mods, view) {
44
+ function plan(session, table, options, mods, view, pin) {
45
45
  const record = isRecord(options) ? options : {};
46
+ if (Object.hasOwn(record, "search")) {
47
+ fail2("OKM1120", "page() does not take search in this version. Use find({ search, limit }) for a ranked list.", "Ranked pages are later. find({ search, limit }) returns one ranked list.");
48
+ }
46
49
  rejectKeys(record, OPTIONS, "page");
47
50
  const indexed = indexes(session.schema).get(table);
48
51
  if (indexed === undefined)
49
- fail("OKM1120", `Table ${table} is not in the schema.`);
52
+ fail2("OKM1120", `Table ${table} is not in the schema.`);
50
53
  if (record.limit === undefined)
51
- fail("OKM1101", "page() needs a limit.");
54
+ fail2("OKM1101", "page() needs a limit.");
52
55
  const size = readLimit(record.limit);
53
56
  if (size < 1) {
54
57
  throw new OkmError2("invalid", "page() limit must be at least 1.", { kind: "invalid" });
@@ -73,7 +76,8 @@ function plan(session, table, options, mods, view) {
73
76
  timeout: record.timeout,
74
77
  route: record.route
75
78
  }, undefined, session.scope, session.schema.model[table], session.schema, view),
76
- ...after !== undefined ? { after } : {}
79
+ ...after !== undefined ? { after } : {},
80
+ ...pin !== undefined ? { pin } : {}
77
81
  };
78
82
  return readHandle(session, table, call, mods, async (compiled, rows) => {
79
83
  const items = await decodeRows(compiled, rows, table);
@@ -92,7 +96,7 @@ function plan(session, table, options, mods, view) {
92
96
  }
93
97
  function orderKeys(table, orderBy) {
94
98
  if (orderBy !== undefined && !isRecord(orderBy)) {
95
- fail("OKM1120", "orderBy must be an object of fields.");
99
+ fail2("OKM1120", "orderBy must be an object of fields.");
96
100
  }
97
101
  const keys = [];
98
102
  for (const field of Object.keys(orderBy ?? {})) {
@@ -103,7 +107,7 @@ function orderKeys(table, orderBy) {
103
107
  keys.push({ column, ...parseOrder(field, orderBy?.[field]) });
104
108
  }
105
109
  if (table.model.primary.length === 0) {
106
- fail("OKM1120", `page() needs a primary key on ${table.model.name} to break ties.`);
110
+ fail2("OKM1120", `page() needs a primary key on ${table.model.name} to break ties.`);
107
111
  }
108
112
  for (const field of table.model.primary) {
109
113
  const column = table.columns.get(field);
@@ -181,17 +185,16 @@ function readCursor(token, signature, count) {
181
185
  }
182
186
  }
183
187
  if (!Array.isArray(parsed) || typeof parsed[0] !== "string") {
184
- fail("OKM1130", "after is not a cursor that page() returned.");
188
+ fail2("OKM1130", "after is not a cursor that page() returned.");
185
189
  }
186
190
  if (parsed[0] !== signature) {
187
- fail("OKM1130", `The cursor was made for another order: ${parsed[0]}. This page orders by ${signature}.`);
191
+ fail2("OKM1130", `The cursor was made for another order: ${parsed[0]}. This page orders by ${signature}.`);
188
192
  }
189
193
  const values = parsed.slice(1);
190
194
  if (values.length !== count || !values.every((value) => value === null || typeof value === "string")) {
191
- fail("OKM1130", "after is not a cursor that page() returned.");
195
+ fail2("OKM1130", "after is not a cursor that page() returned.");
192
196
  }
193
197
  return values;
194
198
  }
195
- export {
196
- build
197
- };
199
+
200
+ export { build3 };
@@ -0,0 +1,6 @@
1
+ import {
2
+ build3
3
+ } from "./pbp1ss85.js";
4
+ export {
5
+ build3 as build
6
+ };
@@ -6,9 +6,30 @@ import {
6
6
  } from "./52szzakm.js";
7
7
 
8
8
  // src/dialects/pg/filter-parse.ts
9
- var PARSED_OPS = ",eq,in,inList,notIn,lt,lte,gt,gte,between,startsWith,endsWith,contains,like,ilike,";
10
- var PARSED_FIX = "Use eq, in, notIn, lt, lte, gt, gte, between, startsWith, endsWith, contains, like, or ilike.";
11
- function parseQuery(allow, sort, query) {
9
+ var PARSED = [
10
+ "eq",
11
+ "in",
12
+ "inList",
13
+ "notIn",
14
+ "lt",
15
+ "lte",
16
+ "gt",
17
+ "gte",
18
+ "between",
19
+ "startsWith",
20
+ "endsWith",
21
+ "contains",
22
+ "like",
23
+ "ilike",
24
+ "not",
25
+ "containedBy",
26
+ "overlaps",
27
+ "hasKey",
28
+ "hasAnyKey"
29
+ ];
30
+ var PARSED_OPS = `,${PARSED.join(",")},`;
31
+ var PARSED_FIX = "Use eq, in, notIn, lt, lte, gt, gte, between, startsWith, endsWith, contains, like, ilike, not, containedBy, overlaps, hasKey, or hasAnyKey.";
32
+ function parseQuery(allow, sort, query, relations) {
12
33
  if (typeof query !== "object" || query === null || Array.isArray(query)) {
13
34
  throw new OkmError2("OKM1121", "filters parse expects an object of fields.");
14
35
  }
@@ -21,6 +42,7 @@ function parseQuery(allow, sort, query) {
21
42
  });
22
43
  }
23
44
  }
45
+ const nested = relations ?? {};
24
46
  const whereParts = [];
25
47
  let orderBy;
26
48
  for (const key of Object.keys(query)) {
@@ -29,13 +51,17 @@ function parseQuery(allow, sort, query) {
29
51
  orderBy = { [value]: "asc" };
30
52
  continue;
31
53
  }
32
- if (!Object.hasOwn(allow, key)) {
33
- throw new OkmError2("OKM1123", `Field ${key} is not in the allow list.`, {
34
- fix: { summary: "Remove the field, or add it to filters({ allow })." }
35
- });
54
+ if (Object.hasOwn(allow, key)) {
55
+ whereParts.push(...clauses(key, allow[key] ?? [], value));
56
+ continue;
36
57
  }
37
- const ops = allow[key] ?? [];
38
- whereParts.push(...clauses(key, ops, value));
58
+ if (Object.hasOwn(nested, key)) {
59
+ whereParts.push(relationClause(key, nested[key] ?? [], value));
60
+ continue;
61
+ }
62
+ throw new OkmError2("OKM1123", `Field ${key} is not in the allow list.`, {
63
+ fix: { summary: "Remove the field, or add it to filters({ allow }) or relations." }
64
+ });
39
65
  }
40
66
  const where = combine(whereParts);
41
67
  return orderBy === undefined ? { where } : { where, orderBy };
@@ -100,6 +126,21 @@ function one(field, op, value) {
100
126
  return { [field]: tag("endsWith", text(value, op)) };
101
127
  case "contains":
102
128
  return { [field]: tag("contains", value) };
129
+ case "not":
130
+ if (value !== null && typeof value === "object") {
131
+ throw new OkmError2("OKM1120", `not on ${field} takes a scalar.`, {
132
+ fix: { summary: "Send not a scalar or null. Nested operators are not accepted." }
133
+ });
134
+ }
135
+ return { [field]: tag("not", value) };
136
+ case "containedBy":
137
+ return { [field]: tag("containedBy", value) };
138
+ case "overlaps":
139
+ return { [field]: tag("overlaps", value) };
140
+ case "hasKey":
141
+ return { [field]: tag("hasKey", text(value, "hasKey")) };
142
+ case "hasAnyKey":
143
+ return { [field]: tag("hasAnyKey", strings(value, field)) };
103
144
  case "like":
104
145
  return { [field]: tag("like", text(value, op)) };
105
146
  case "ilike":
@@ -110,6 +151,30 @@ function one(field, op, value) {
110
151
  });
111
152
  }
112
153
  }
154
+ function relationClause(name, fields, value) {
155
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
156
+ throw new OkmError2("OKM1120", `filters() cannot apply a value on ${name}.`, {
157
+ fix: { summary: "Send the relation an object of allowlisted fields." }
158
+ });
159
+ }
160
+ const parts = [];
161
+ for (const field of Object.keys(value)) {
162
+ if (!Object.hasOwn(value, field))
163
+ continue;
164
+ if (!fields.includes(field)) {
165
+ throw new OkmError2("OKM1123", `Field ${field} is not in the allow list.`, {
166
+ fix: { summary: "Remove the field, or add it to filters({ relations })." }
167
+ });
168
+ }
169
+ parts.push(...clauses(field, PARSED, value[field]));
170
+ }
171
+ if (parts.length === 0) {
172
+ throw new OkmError2("OKM1120", `filters() cannot apply a value on ${name}.`, {
173
+ fix: { summary: "Send the relation an object of allowlisted fields." }
174
+ });
175
+ }
176
+ return { [name]: tag("has", combine(parts)) };
177
+ }
113
178
  function combine(parts) {
114
179
  const first = parts[0];
115
180
  if (first === undefined)
@@ -126,6 +191,14 @@ function list(value, op) {
126
191
  }
127
192
  return value;
128
193
  }
194
+ function strings(value, field) {
195
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
196
+ throw new OkmError2("OKM1120", `hasAnyKey on ${field} needs an array of strings.`, {
197
+ fix: { summary: "Send hasAnyKey an array of strings." }
198
+ });
199
+ }
200
+ return value;
201
+ }
129
202
  function text(value, op) {
130
203
  if (typeof value !== "string") {
131
204
  throw new OkmError2("OKM1120", `${op} needs a string.`, {
@@ -0,0 +1,13 @@
1
+ import {
2
+ fail2
3
+ } from "./67txcrcw.js";
4
+
5
+ // src/runtime/result-name.ts
6
+ var PROTOTYPE_KEYS = ",__proto__,constructor,toString,hasOwnProperty,valueOf,isPrototypeOf,propertyIsEnumerable,toLocaleString,__defineGetter__,__defineSetter__,__lookupGetter__,__lookupSetter__,then,";
7
+ function refusePrototypeKey(name, where) {
8
+ if (!PROTOTYPE_KEYS.includes(`,${name},`))
9
+ return;
10
+ fail2("OKM1120", `${where} ${name} is a prototype key. Use another name for the result.`);
11
+ }
12
+
13
+ export { refusePrototypeKey };