okmodel 0.3.0 → 0.4.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 (104) hide show
  1. package/README.md +182 -22
  2. package/dist/contracts/catalog/document.d.ts +6 -2
  3. package/dist/dialects/pg/ext/citext.js +1 -1
  4. package/dist/dialects/pg/ext/index.js +1 -1
  5. package/dist/dialects/pg/ext/pg-trgm.js +1 -1
  6. package/dist/dialects/pg/index.js +3 -3
  7. package/dist/dialects/pg/role/sql.d.ts +11 -4
  8. package/dist/dialects/pg/table.d.ts +17 -1
  9. package/dist/dialects/pg/view/index.js +1 -1
  10. package/dist/dialects/pg/view/scratch.d.ts +3 -2
  11. package/dist/runtime/catalog-cache.d.ts +17 -0
  12. package/dist/runtime/compat-words.d.ts +23 -0
  13. package/dist/runtime/drift-detail.d.ts +20 -4
  14. package/dist/runtime/drift.d.ts +4 -2
  15. package/dist/runtime/pg/bun.js +2 -2
  16. package/dist/runtime/pg/pg.js +2 -2
  17. package/dist/runtime/pg/pglite.js +2 -2
  18. package/dist/runtime/pg/postgresjs.js +2 -2
  19. package/dist/runtime/traits/index.js +5 -4
  20. package/dist/runtime/types.d.ts +2 -0
  21. package/dist/runtime/validate/index.js +2 -2
  22. package/dist/shared/2321avmn.js +418 -0
  23. package/dist/shared/{x6wysh83.js → 3p4b1fg0.js} +3 -5
  24. package/dist/shared/{wekze34d.js → 41kv2xdm.js} +74 -2
  25. package/dist/shared/{fs0ex00p.js → 4ef7mmqf.js} +2 -2
  26. package/dist/shared/5mtf6cj3.js +94 -0
  27. package/dist/shared/{999ade2q.js → 5vdm4sgp.js} +1 -1
  28. package/dist/shared/{qybh48nd.js → 6693j9rs.js} +1 -1
  29. package/dist/shared/{bqha5cg6.js → 6p5k20sm.js} +2 -2
  30. package/dist/shared/7nk68fj8.js +751 -0
  31. package/dist/shared/{ne02ng5c.js → 84ptn35q.js} +7 -4
  32. package/dist/shared/{t616ynfn.js → 8jb4ymh2.js} +59 -12
  33. package/dist/shared/{th14ygv2.js → 8ktwd3rh.js} +29 -1
  34. package/dist/shared/9yn6a2vd.js +11 -0
  35. package/dist/shared/ady1ms74.js +72 -0
  36. package/dist/shared/{scwxrpx2.js → c5g81ngb.js} +82 -15
  37. package/dist/shared/{6bazvqwm.js → fb00y8fp.js} +2 -2
  38. package/dist/shared/{jkc6ws1p.js → g7ez901n.js} +83 -2
  39. package/dist/shared/{kgnc8grt.js → gdh9mrtp.js} +1 -1
  40. package/dist/shared/hqjsxnz7.js +13 -0
  41. package/dist/shared/htnaj77v.js +17 -0
  42. package/dist/shared/{mt5wswjz.js → jgxzjzcz.js} +1 -1
  43. package/dist/shared/{6w5j844a.js → jsd07prz.js} +2 -2
  44. package/dist/shared/{m78s7898.js → kafaa5zv.js} +1 -1
  45. package/dist/shared/kj680nxv.js +19 -0
  46. package/dist/shared/{k34e0xf2.js → kkzwp3d2.js} +8 -8
  47. package/dist/shared/{2ssqrv66.js → n5y9zyj1.js} +1029 -174
  48. package/dist/shared/{ty3v3hfk.js → nxb42q7h.js} +2 -2
  49. package/dist/shared/{5nmdenb6.js → q6zsyh31.js} +1003 -40
  50. package/dist/shared/{fptpmvxp.js → q795afwa.js} +26 -21
  51. package/dist/shared/{3ekj9x92.js → qn0srwwq.js} +1 -1
  52. package/dist/shared/s4mb6a4b.js +545 -0
  53. package/dist/shared/{01yr20s5.js → sf8m6tfy.js} +2 -2
  54. package/dist/shared/{bryqk9k9.js → sr5ms7b3.js} +1 -1
  55. package/dist/shared/{meck53jv.js → tny2t3sm.js} +6 -5
  56. package/dist/shared/{p24x2334.js → v7tpnhnz.js} +1 -1
  57. package/dist/shared/{xw1d69vd.js → wqem4jed.js} +6 -6
  58. package/dist/shared/{49ypnfwt.js → xghkt7a9.js} +50 -28
  59. package/dist/shared/{7fvtrkwr.js → ycatkxmq.js} +1 -1
  60. package/dist/shared/ygem90rn.js +900 -0
  61. package/dist/shared/{1tfdfvhh.js → yjw02enp.js} +6 -4
  62. package/dist/shared/{ydaz1sv3.js → zg24x0hm.js} +1 -1
  63. package/dist/tooling/cli.js +46 -17
  64. package/dist/tooling/migrate/apply.d.ts +59 -5
  65. package/dist/tooling/migrate/backfill.d.ts +136 -0
  66. package/dist/tooling/migrate/check.d.ts +65 -0
  67. package/dist/tooling/migrate/classify.d.ts +108 -0
  68. package/dist/tooling/migrate/commands.d.ts +2 -2
  69. package/dist/tooling/migrate/config.d.ts +22 -0
  70. package/dist/tooling/migrate/doctor.d.ts +3 -0
  71. package/dist/tooling/migrate/drift.d.ts +18 -2
  72. package/dist/tooling/migrate/estimate.d.ts +50 -0
  73. package/dist/tooling/migrate/extensions.d.ts +2 -0
  74. package/dist/tooling/migrate/files.d.ts +12 -0
  75. package/dist/tooling/migrate/index.d.ts +3 -2
  76. package/dist/tooling/migrate/index.js +67 -1
  77. package/dist/tooling/migrate/lint-rules.d.ts +51 -0
  78. package/dist/tooling/migrate/lint.d.ts +71 -0
  79. package/dist/tooling/migrate/managed.d.ts +1 -1
  80. package/dist/tooling/migrate/plan.d.ts +64 -9
  81. package/dist/tooling/migrate/project.d.ts +42 -7
  82. package/dist/tooling/migrate/provision.d.ts +18 -0
  83. package/dist/tooling/migrate/reference.d.ts +40 -0
  84. package/dist/tooling/migrate/runner.d.ts +108 -0
  85. package/dist/tooling/migrate/safe.d.ts +77 -0
  86. package/dist/tooling/migrate/seed.d.ts +20 -0
  87. package/dist/tooling/migrate/snapshot.d.ts +78 -0
  88. package/dist/tooling/migrate/status.d.ts +25 -6
  89. package/dist/tooling/testing/factories.d.ts +117 -0
  90. package/dist/tooling/testing/facts.d.ts +72 -0
  91. package/dist/tooling/testing/index.d.ts +89 -0
  92. package/dist/tooling/testing/index.js +8 -0
  93. package/dist/tooling/testing/isolation.d.ts +30 -0
  94. package/dist/tooling/testing/random.d.ts +40 -0
  95. package/dist/tooling/testing/record.d.ts +38 -0
  96. package/package.json +6 -2
  97. package/dist/shared/dbjej1tw.js +0 -456
  98. package/dist/shared/g4f5kcx9.js +0 -37
  99. package/dist/shared/qbxzvwwc.js +0 -88
  100. package/dist/shared/zwmqxb0g.js +0 -79
  101. package/dist/shared/{xva8v7qk.js → awrsqrn7.js} +3 -3
  102. package/dist/shared/{75xkjv0t.js → fa9vt245.js} +0 -0
  103. package/dist/shared/{m9tv7xn7.js → radd3z4g.js} +3 -3
  104. /package/dist/shared/{0jc3ffzf.js → zvbjc949.js} +0 -0
@@ -1,79 +0,0 @@
1
- import {
2
- OkmError2
3
- } from "./52szzakm.js";
4
-
5
- // src/runtime/drift-detail.ts
6
- function driftVerdict(codeHash, recordedHash, migrations) {
7
- const codeAt = indexOfHash(migrations, codeHash);
8
- const recordedAt = indexOfHash(migrations, recordedHash);
9
- if (codeAt < 0 || recordedAt < 0 || recordedAt < codeAt)
10
- return "behind";
11
- if (recordedAt === codeAt)
12
- return "ok";
13
- for (let index = codeAt + 1;index <= recordedAt; index += 1) {
14
- if (migrations[index]?.expand !== true)
15
- return "contract";
16
- }
17
- return "ok";
18
- }
19
- async function assertDrift(pool, codeHash, recordedHash, options) {
20
- let rows;
21
- try {
22
- const result = await pool.execute("select migration_id, class, catalog_hash from okm_history order by migration_id, step_index", undefined, options);
23
- rows = result.rows;
24
- } catch (error) {
25
- throw behind(error);
26
- }
27
- const verdict = driftVerdict(codeHash, recordedHash, groupMigrations(rows));
28
- if (verdict === "ok")
29
- return;
30
- if (verdict === "contract") {
31
- throw new OkmError2("OKM1520", "The database is ahead of the code by a contract migration.", {
32
- fix: {
33
- summary: "Roll the application forward, or repair the database. A contract step is not compatible with this code."
34
- }
35
- });
36
- }
37
- throw behind(undefined);
38
- }
39
- function indexOfHash(migrations, hash) {
40
- let found = -1;
41
- for (let index = 0;index < migrations.length; index += 1) {
42
- if (migrations[index]?.catalogHash === hash)
43
- found = index;
44
- }
45
- return found;
46
- }
47
- function groupMigrations(rows) {
48
- const grouped = [];
49
- for (const row of rows) {
50
- const id = row[0];
51
- const stepClass = row[1];
52
- const hash = row[2];
53
- if (id == null || stepClass == null || hash == null)
54
- continue;
55
- const expand = stepClass === "expand";
56
- const last = grouped.at(-1);
57
- if (last !== undefined && last.id === id) {
58
- grouped[grouped.length - 1] = {
59
- id,
60
- catalogHash: hash,
61
- expand: last.expand && expand
62
- };
63
- continue;
64
- }
65
- grouped.push({ id, catalogHash: hash, expand });
66
- }
67
- return grouped;
68
- }
69
- function behind(cause) {
70
- return new OkmError2("OKM1520", "The database is behind the code.", {
71
- ...cause === undefined ? {} : { cause },
72
- fix: {
73
- summary: "Inspect the diff and repair the database, or generate a migration that matches the drift."
74
- }
75
- });
76
- }
77
- export {
78
- assertDrift
79
- };
@@ -3,6 +3,9 @@ import {
3
3
  textArray,
4
4
  arrayElementType
5
5
  } from "./n7mcc1gk.js";
6
+ import {
7
+ stack
8
+ } from "./672t5vym.js";
6
9
  import {
7
10
  touchFields,
8
11
  fieldSealed,
@@ -11,9 +14,6 @@ import {
11
14
  import {
12
15
  runWrite
13
16
  } from "./n4jqhpqz.js";
14
- import {
15
- stack
16
- } from "./672t5vym.js";
17
17
  import {
18
18
  writeWouldValidate
19
19
  } from "./9m80mkac.js";
File without changes
@@ -1,9 +1,9 @@
1
- import {
2
- runWrite
3
- } from "./n4jqhpqz.js";
4
1
  import {
5
2
  stack
6
3
  } from "./672t5vym.js";
4
+ import {
5
+ runWrite
6
+ } from "./n4jqhpqz.js";
7
7
  import {
8
8
  withRowFilters,
9
9
  archiveRules,
File without changes