okmodel 0.0.0 → 0.1.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 (147) hide show
  1. package/README.md +44 -1
  2. package/dist/adapters/capabilities.d.ts +62 -0
  3. package/dist/adapters/error.d.ts +91 -0
  4. package/dist/adapters/failure.d.ts +39 -0
  5. package/dist/adapters/pg/batch.d.ts +36 -0
  6. package/dist/adapters/pg/call.d.ts +59 -0
  7. package/dist/adapters/pg/pglite.d.ts +21 -0
  8. package/dist/adapters/pg/postgres-extra.d.ts +43 -0
  9. package/dist/adapters/pg/postgresjs.d.ts +95 -0
  10. package/dist/adapters/pg/result.d.ts +30 -0
  11. package/dist/contracts/catalog/build.d.ts +18 -0
  12. package/dist/contracts/catalog/document.d.ts +79 -0
  13. package/dist/contracts/catalog/enum.d.ts +35 -0
  14. package/dist/contracts/catalog/identifier.d.ts +71 -0
  15. package/dist/contracts/catalog/identity.d.ts +98 -0
  16. package/dist/contracts/catalog/index.d.ts +11 -0
  17. package/dist/contracts/catalog/json.d.ts +17 -0
  18. package/dist/contracts/catalog/object.d.ts +142 -0
  19. package/dist/contracts/catalog/order.d.ts +43 -0
  20. package/dist/contracts/catalog/rewrite.d.ts +18 -0
  21. package/dist/contracts/catalog/types.d.ts +292 -0
  22. package/dist/contracts/catalog/words.d.ts +13 -0
  23. package/dist/contracts/connection.d.ts +33 -0
  24. package/dist/contracts/driver.d.ts +163 -0
  25. package/dist/contracts/error.d.ts +298 -0
  26. package/dist/contracts/index.d.ts +11 -0
  27. package/dist/contracts/index.js +16 -0
  28. package/dist/contracts/internal.d.ts +15 -0
  29. package/dist/contracts/internal.js +68 -0
  30. package/dist/contracts/nearest.d.ts +15 -0
  31. package/dist/contracts/rows.d.ts +84 -0
  32. package/dist/contracts/sha256.d.ts +14 -0
  33. package/dist/contracts/utf8.d.ts +33 -0
  34. package/dist/dialects/pg/array-literal.d.ts +25 -0
  35. package/dist/dialects/pg/bool.d.ts +46 -0
  36. package/dist/dialects/pg/column.d.ts +386 -0
  37. package/dist/dialects/pg/compile.d.ts +81 -0
  38. package/dist/dialects/pg/custom.d.ts +21 -0
  39. package/dist/dialects/pg/ddl.d.ts +70 -0
  40. package/dist/dialects/pg/decimal.d.ts +62 -0
  41. package/dist/dialects/pg/declarations.d.ts +34 -0
  42. package/dist/dialects/pg/emit.d.ts +18 -0
  43. package/dist/dialects/pg/enum.d.ts +30 -0
  44. package/dist/dialects/pg/errors.d.ts +30 -0
  45. package/dist/dialects/pg/finite.d.ts +15 -0
  46. package/dist/dialects/pg/geometry.d.ts +55 -0
  47. package/dist/dialects/pg/index.d.ts +45 -0
  48. package/dist/dialects/pg/index.js +1821 -0
  49. package/dist/dialects/pg/integer.d.ts +96 -0
  50. package/dist/dialects/pg/introspect.d.ts +43 -0
  51. package/dist/dialects/pg/json.d.ts +43 -0
  52. package/dist/dialects/pg/keys.d.ts +32 -0
  53. package/dist/dialects/pg/misuse.d.ts +31 -0
  54. package/dist/dialects/pg/model.d.ts +71 -0
  55. package/dist/dialects/pg/namespace.d.ts +63 -0
  56. package/dist/dialects/pg/network.d.ts +28 -0
  57. package/dist/dialects/pg/operators.d.ts +71 -0
  58. package/dist/dialects/pg/ops/between.d.ts +10 -0
  59. package/dist/dialects/pg/ops/contains.d.ts +8 -0
  60. package/dist/dialects/pg/ops/endsWith.d.ts +8 -0
  61. package/dist/dialects/pg/ops/eq.d.ts +9 -0
  62. package/dist/dialects/pg/ops/every.d.ts +9 -0
  63. package/dist/dialects/pg/ops/gt.d.ts +9 -0
  64. package/dist/dialects/pg/ops/gte.d.ts +9 -0
  65. package/dist/dialects/pg/ops/has.d.ts +9 -0
  66. package/dist/dialects/pg/ops/ilike.d.ts +8 -0
  67. package/dist/dialects/pg/ops/inList.d.ts +9 -0
  68. package/dist/dialects/pg/ops/inc.d.ts +13 -0
  69. package/dist/dialects/pg/ops/like.d.ts +8 -0
  70. package/dist/dialects/pg/ops/lt.d.ts +9 -0
  71. package/dist/dialects/pg/ops/lte.d.ts +9 -0
  72. package/dist/dialects/pg/ops/none.d.ts +9 -0
  73. package/dist/dialects/pg/ops/not.d.ts +9 -0
  74. package/dist/dialects/pg/ops/notIn.d.ts +9 -0
  75. package/dist/dialects/pg/ops/or.d.ts +9 -0
  76. package/dist/dialects/pg/ops/startsWith.d.ts +8 -0
  77. package/dist/dialects/pg/quote.d.ts +24 -0
  78. package/dist/dialects/pg/range.d.ts +50 -0
  79. package/dist/dialects/pg/relations.d.ts +45 -0
  80. package/dist/dialects/pg/schema.d.ts +77 -0
  81. package/dist/dialects/pg/search.d.ts +23 -0
  82. package/dist/dialects/pg/table.d.ts +201 -0
  83. package/dist/dialects/pg/temporal.d.ts +211 -0
  84. package/dist/dialects/pg/text.d.ts +44 -0
  85. package/dist/dialects/pg/time.d.ts +46 -0
  86. package/dist/okm.js +2 -0
  87. package/dist/okmodel.js +2 -0
  88. package/dist/runtime/client.d.ts +47 -0
  89. package/dist/runtime/conflict.d.ts +38 -0
  90. package/dist/runtime/drift-detail.d.ts +32 -0
  91. package/dist/runtime/drift.d.ts +29 -0
  92. package/dist/runtime/include.d.ts +15 -0
  93. package/dist/runtime/pg/pglite.d.ts +25 -0
  94. package/dist/runtime/pg/pglite.js +48 -0
  95. package/dist/runtime/pg/postgresjs.d.ts +29 -0
  96. package/dist/runtime/pg/postgresjs.js +62 -0
  97. package/dist/runtime/plan.d.ts +167 -0
  98. package/dist/runtime/tx.d.ts +29 -0
  99. package/dist/runtime/types.d.ts +369 -0
  100. package/dist/runtime/write.d.ts +48 -0
  101. package/dist/shared/4j72449d.js +37 -0
  102. package/dist/shared/79ggp945.js +148 -0
  103. package/dist/shared/7ck0dtry.js +259 -0
  104. package/dist/shared/8b04d28c.js +14 -0
  105. package/dist/shared/ax16zpvm.js +171 -0
  106. package/dist/shared/ckb1p0a4.js +566 -0
  107. package/dist/shared/cn0n68ft.js +16 -0
  108. package/dist/shared/dynq16vb.js +81 -0
  109. package/dist/shared/f5thc1s0.js +1050 -0
  110. package/dist/shared/fgqgsb5z.js +281 -0
  111. package/dist/shared/g2v6gnc8.js +347 -0
  112. package/dist/shared/g5fhqmwe.js +188 -0
  113. package/dist/shared/gk7cs7sp.js +566 -0
  114. package/dist/shared/hd293j9g.js +98 -0
  115. package/dist/shared/j5cn2963.js +701 -0
  116. package/dist/shared/kynx7vbm.js +1490 -0
  117. package/dist/shared/mkjmqjv4.js +456 -0
  118. package/dist/shared/mtkwv8wx.js +18 -0
  119. package/dist/shared/ngk8gj61.js +40 -0
  120. package/dist/shared/p0cbr3g2.js +79 -0
  121. package/dist/shared/px90pf9p.js +396 -0
  122. package/dist/shared/qk3hxfja.js +83 -0
  123. package/dist/shared/tb4ze1tr.js +119 -0
  124. package/dist/shared/vkm3q4x1.js +30 -0
  125. package/dist/shared/w8samvk1.js +18 -0
  126. package/dist/shared/xy79j5hq.js +177 -0
  127. package/dist/shared/y9m15dfv.js +888 -0
  128. package/dist/shared/ycwz42az.js +412 -0
  129. package/dist/shared/zhc5vmgf.js +257 -0
  130. package/dist/tooling/cli.d.ts +1 -0
  131. package/dist/tooling/cli.js +193 -0
  132. package/dist/tooling/errors/registry.d.ts +33 -0
  133. package/dist/tooling/migrate/apply.d.ts +86 -0
  134. package/dist/tooling/migrate/commands.d.ts +21 -0
  135. package/dist/tooling/migrate/config.d.ts +48 -0
  136. package/dist/tooling/migrate/dev.d.ts +16 -0
  137. package/dist/tooling/migrate/equal.d.ts +15 -0
  138. package/dist/tooling/migrate/files.d.ts +19 -0
  139. package/dist/tooling/migrate/index.d.ts +7 -0
  140. package/dist/tooling/migrate/index.js +7 -0
  141. package/dist/tooling/migrate/plan.d.ts +76 -0
  142. package/dist/tooling/migrate/policy.d.ts +78 -0
  143. package/dist/tooling/migrate/project.d.ts +69 -0
  144. package/dist/tooling/migrate/status.d.ts +74 -0
  145. package/dist/tooling/migrate/values.d.ts +29 -0
  146. package/package.json +94 -7
  147. package/dist/index.js +0 -0
@@ -0,0 +1,259 @@
1
+ import {
2
+ POSTGRESJS_CAPABILITIES,
3
+ driverErrors,
4
+ rejectClosed,
5
+ mapFailure,
6
+ nextTransactionDepth,
7
+ runCall,
8
+ EMPTY_NOTICES,
9
+ resultFrom
10
+ } from "./xy79j5hq.js";
11
+
12
+ // src/adapters/pg/postgresjs.ts
13
+ import postgres from "postgres";
14
+ function open2(config) {
15
+ const max = config.max ?? 10;
16
+ const acquireMs = config.timeouts?.acquire;
17
+ const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
18
+ const poolInflight = new Set;
19
+ const notices = noticeBuffer();
20
+ let closed = false;
21
+ const isClosed = () => closed;
22
+ const named = config.prepared === "named";
23
+ const sql = postgres(config.url, {
24
+ max,
25
+ prepare: named,
26
+ idle_timeout: 30,
27
+ connect_timeout: 5,
28
+ types: WIRE_TYPES,
29
+ ...config.ssl !== undefined ? { ssl: config.ssl } : {},
30
+ connection: {
31
+ application_name: "okmodel",
32
+ ...config.searchPath !== undefined ? { search_path: config.searchPath } : {}
33
+ },
34
+ onnotice(notice) {
35
+ notices.push(notice);
36
+ }
37
+ });
38
+ const root = new PgSession(sql, counters, "pool", poolInflight, isClosed, undefined, notices, named);
39
+ const held = { sql, acquireMs, counters, isClosed, notices, named, poolInflight };
40
+ return {
41
+ capabilities: POSTGRESJS_CAPABILITIES,
42
+ execute(text, params, options) {
43
+ return runCall(closed, options, (watch) => root.query(text, params, watch));
44
+ },
45
+ async batch(statements, options) {
46
+ const { checkout } = await import("./tb4ze1tr.js");
47
+ const connection = await checkout(held);
48
+ try {
49
+ return await connection.batch(statements, options);
50
+ } finally {
51
+ await connection.release();
52
+ }
53
+ },
54
+ reserve: () => import("./tb4ze1tr.js").then((mod) => mod.checkout(held)),
55
+ describe: (text, params) => import("./tb4ze1tr.js").then((mod) => mod.describe(sql, text, params)),
56
+ stream(text, params) {
57
+ return loadStream(sql, text, params);
58
+ },
59
+ async listen(channel, onNotify) {
60
+ const listening = await sql.listen(channel, onNotify);
61
+ return async () => {
62
+ await listening.unlisten();
63
+ };
64
+ },
65
+ cancel() {
66
+ for (const pending of poolInflight)
67
+ pending.cancel();
68
+ },
69
+ stats: () => statsOf(counters, max),
70
+ async close() {
71
+ closed = true;
72
+ await sql.end({ timeout: 5 });
73
+ }
74
+ };
75
+ }
76
+
77
+ class PgSession {
78
+ canCancel = true;
79
+ transactionDepth = 0;
80
+ sql;
81
+ counters;
82
+ scope;
83
+ local;
84
+ isClosed;
85
+ shared;
86
+ notices;
87
+ named;
88
+ constructor(sql, counters, scope, local, isClosed, shared, notices, named) {
89
+ this.sql = sql;
90
+ this.counters = counters;
91
+ this.scope = scope;
92
+ this.local = local;
93
+ this.isClosed = isClosed;
94
+ this.shared = shared;
95
+ this.notices = notices;
96
+ this.named = named;
97
+ }
98
+ query(text, params, watch) {
99
+ if (this.isClosed())
100
+ return rejectClosed();
101
+ const start = this.notices.start();
102
+ this.enter();
103
+ const pending = send(this.sql, text, params, this.named);
104
+ if (watch === undefined) {
105
+ return pending.then((result) => {
106
+ this.leave();
107
+ this.note(text);
108
+ return resultFrom(result, this.notices.since(start));
109
+ }, (error) => {
110
+ this.leave();
111
+ return mapFailure(error).then((mapped) => {
112
+ throw mapped;
113
+ });
114
+ });
115
+ }
116
+ return this.watched(pending, watch, start, text);
117
+ }
118
+ inTransaction() {
119
+ return this.transactionDepth > 0;
120
+ }
121
+ abandon() {
122
+ this.transactionDepth = 0;
123
+ }
124
+ depth() {
125
+ return this.transactionDepth;
126
+ }
127
+ cancel() {
128
+ for (const pending of this.local)
129
+ pending.cancel();
130
+ }
131
+ note(text) {
132
+ this.transactionDepth = nextTransactionDepth(this.transactionDepth, text);
133
+ }
134
+ enter() {
135
+ if (this.scope === "pool")
136
+ this.counters.busy += 1;
137
+ else
138
+ this.counters.reservedBusy += 1;
139
+ }
140
+ leave() {
141
+ if (this.scope === "pool")
142
+ this.counters.busy = Math.max(0, this.counters.busy - 1);
143
+ else
144
+ this.counters.reservedBusy = Math.max(0, this.counters.reservedBusy - 1);
145
+ }
146
+ track(pending) {
147
+ this.local.add(pending);
148
+ this.shared?.add(pending);
149
+ }
150
+ untrack(pending) {
151
+ this.local.delete(pending);
152
+ this.shared?.delete(pending);
153
+ }
154
+ watched(pending, watch, start, text) {
155
+ this.track(pending);
156
+ const onAbort = () => {
157
+ pending.cancel();
158
+ };
159
+ if (watch.signal.aborted)
160
+ onAbort();
161
+ else
162
+ watch.signal.addEventListener("abort", onAbort, { once: true });
163
+ return pending.then((result) => {
164
+ this.finishWatched(pending, watch, onAbort);
165
+ const why = watch.reason();
166
+ if (why === "timeout" || why === "cancelled")
167
+ return classify(why, watch);
168
+ this.note(text);
169
+ return resultFrom(result, this.notices.since(start));
170
+ }, (error) => {
171
+ this.finishWatched(pending, watch, onAbort);
172
+ return classify(error, watch);
173
+ });
174
+ }
175
+ finishWatched(pending, watch, onAbort) {
176
+ this.leave();
177
+ this.untrack(pending);
178
+ watch.signal.removeEventListener("abort", onAbort);
179
+ }
180
+ }
181
+ async function* loadStream(sql, text, params) {
182
+ const { stream } = await import("./tb4ze1tr.js");
183
+ yield* stream(sql, text, params);
184
+ }
185
+ function send(sql, text, params, named) {
186
+ if (!named && (params === undefined || params.length === 0))
187
+ return sql.unsafe(text).raw();
188
+ return sql.unsafe(text, asParams(params), { prepare: named }).raw();
189
+ }
190
+ function asParams(params) {
191
+ if (params === undefined)
192
+ return [];
193
+ return params;
194
+ }
195
+ async function classify(error, watch) {
196
+ const errors = await driverErrors();
197
+ if (error instanceof errors.DriverError)
198
+ return Promise.reject(error);
199
+ const why = typeof error === "string" ? error : watch.reason();
200
+ if (why === "timeout")
201
+ return Promise.reject(errors.timedOut(typeof error === "string" ? undefined : error));
202
+ const code = errors.errorField(error, "code");
203
+ if (why === "cancelled" || code === "57014") {
204
+ return Promise.reject(errors.cancelled(typeof error === "string" ? undefined : error));
205
+ }
206
+ return Promise.reject(errors.mapDriverError(error));
207
+ }
208
+ function statsOf(counters, size) {
209
+ return {
210
+ size,
211
+ idle: Math.max(0, size - counters.reserved - counters.busy),
212
+ inflight: counters.busy + counters.reservedBusy,
213
+ waiting: counters.waiting
214
+ };
215
+ }
216
+ function noticeBuffer() {
217
+ let notices;
218
+ return {
219
+ push(notice) {
220
+ const severity = typeof notice.severity === "string" ? notice.severity : "";
221
+ const message = typeof notice.message === "string" ? notice.message : "";
222
+ const code = typeof notice.code === "string" && notice.code.length > 0 ? notice.code : undefined;
223
+ const entry = code === undefined ? { severity, message } : { severity, message, code };
224
+ (notices ??= []).push(entry);
225
+ },
226
+ start() {
227
+ return notices?.length ?? 0;
228
+ },
229
+ since(start) {
230
+ if (notices === undefined || notices.length === start)
231
+ return EMPTY_NOTICES;
232
+ return notices.slice(start);
233
+ }
234
+ };
235
+ }
236
+ function wire(to, from) {
237
+ return {
238
+ to,
239
+ from: [...from],
240
+ serialize: (value) => value,
241
+ parse: (value) => value
242
+ };
243
+ }
244
+ var WIRE_TYPES = {
245
+ number: wire(0, [21, 23, 26, 700, 701]),
246
+ boolean: wire(16, [16]),
247
+ bytea: wire(17, [17]),
248
+ json: wire(114, [114, 3802]),
249
+ date: wire(1184, [1082, 1114, 1184]),
250
+ boolArray: wire(1000, [1000]),
251
+ int2Array: wire(1005, [1005]),
252
+ int4Array: wire(1007, [1007]),
253
+ textArray: wire(1009, [1009]),
254
+ int8Array: wire(1016, [1016]),
255
+ numericArray: wire(1231, [1231]),
256
+ jsonbArray: wire(3807, [3807])
257
+ };
258
+
259
+ export { open2, PgSession };
@@ -0,0 +1,14 @@
1
+ import {
2
+ open3
3
+ } from "./fgqgsb5z.js";
4
+ import {
5
+ PGLITE_CAPABILITIES,
6
+ readCapability2,
7
+ hasCapability2
8
+ } from "./xy79j5hq.js";
9
+ export {
10
+ PGLITE_CAPABILITIES as capabilities,
11
+ hasCapability2 as hasCapability,
12
+ open3 as open,
13
+ readCapability2 as readCapability
14
+ };
@@ -0,0 +1,171 @@
1
+ import {
2
+ open2
3
+ } from "./7ck0dtry.js";
4
+ import"./y9m15dfv.js";
5
+ import {
6
+ loadMigrations
7
+ } from "./4j72449d.js";
8
+ import {
9
+ assertTargetPolicy,
10
+ listTargets,
11
+ loadConfig
12
+ } from "./kynx7vbm.js";
13
+ import {
14
+ OkmError2
15
+ } from "./ycwz42az.js";
16
+
17
+ // src/tooling/migrate/status.ts
18
+ import { join } from "node:path";
19
+ function describeStatus(migrations, history, recorded) {
20
+ const done = new Set(history.map((row) => `${row.migrationId}:${String(row.stepIndex)}`));
21
+ const known = new Set(migrations.map((migration) => migration.id));
22
+ for (const migration of migrations) {
23
+ let have = 0;
24
+ let missing = -1;
25
+ for (let index = 0;index < migration.steps.length; index += 1) {
26
+ if (done.has(`${migration.id}:${String(index)}`))
27
+ have += 1;
28
+ else if (missing < 0)
29
+ missing = index;
30
+ }
31
+ if (have > 0 && missing >= 0) {
32
+ return {
33
+ version: migration.id,
34
+ catalogHash: recorded?.hash ?? "-",
35
+ state: `failed at step ${String(missing)}`
36
+ };
37
+ }
38
+ }
39
+ const extra = history.some((row) => !known.has(row.migrationId));
40
+ const pending = migrations.filter((migration) => migration.steps.some((_, index) => !done.has(`${migration.id}:${String(index)}`)));
41
+ const finished = lastComplete(migrations, done);
42
+ const version = recorded?.version ?? finished ?? "-";
43
+ const catalogHash = recorded?.hash ?? "-";
44
+ if (extra)
45
+ return { version, catalogHash, state: "ahead" };
46
+ if (pending.length > 0) {
47
+ const contract = pending.some((migration) => migration.steps.some((step) => step.class !== "expand"));
48
+ return {
49
+ version,
50
+ catalogHash,
51
+ state: contract ? "behind by contract" : "behind by expand"
52
+ };
53
+ }
54
+ const last = migrations.at(-1);
55
+ if (last !== undefined && recorded !== undefined && recorded.hash !== last.catalogHash) {
56
+ return { version, catalogHash, state: "ahead" };
57
+ }
58
+ return {
59
+ version: recorded?.version ?? last?.id ?? "-",
60
+ catalogHash: recorded?.hash ?? last?.catalogHash ?? "-",
61
+ state: "current"
62
+ };
63
+ }
64
+ async function readTargetStatus(input) {
65
+ assertTargetPolicy({ name: input.target, protected: input.protected }, "status");
66
+ const pool = open2({
67
+ url: input.url,
68
+ max: 1,
69
+ ...input.searchPath !== undefined ? { searchPath: input.searchPath } : {}
70
+ });
71
+ try {
72
+ const present = await pool.execute("select (to_regclass('okm_meta') is not null), (to_regclass('okm_history') is not null)");
73
+ const meta = wireTrue(present.rows[0]?.[0] ?? null);
74
+ const history = wireTrue(present.rows[0]?.[1] ?? null);
75
+ const recorded = meta ? await readMeta(pool) : undefined;
76
+ const rows = history ? await readHistory(pool) : [];
77
+ const described = describeStatus(input.migrations, rows, recorded);
78
+ return {
79
+ target: input.target,
80
+ version: described.version,
81
+ catalogHash: described.catalogHash,
82
+ state: described.state,
83
+ protected: input.protected
84
+ };
85
+ } finally {
86
+ await pool.close();
87
+ }
88
+ }
89
+ async function statusProject(cwd, flags) {
90
+ const config = await loadConfig(cwd);
91
+ const targets = chosen(listTargets(config), flags.target);
92
+ const migrations = loadMigrations(join(cwd, config.migrations ?? "migrations"));
93
+ const rows = [];
94
+ for (const target of targets) {
95
+ rows.push(await readTargetStatus({
96
+ url: target.url,
97
+ target: target.name,
98
+ protected: target.protected,
99
+ migrations
100
+ }));
101
+ }
102
+ return formatStatus(rows);
103
+ }
104
+ function formatStatus(rows) {
105
+ const lines = ["target\tversion\tcatalog\tstate\tprotected"];
106
+ for (const row of rows) {
107
+ lines.push([row.target, row.version, row.catalogHash, row.state, row.protected ? "true" : "false"].join("\t"));
108
+ }
109
+ return `${lines.join(`
110
+ `)}
111
+ `;
112
+ }
113
+ function chosen(targets, name) {
114
+ if (targets.length === 0) {
115
+ throw new OkmError2("OKM1845", "No target is configured.", {
116
+ fix: { summary: "Set database or targets in okmodel.config.ts." }
117
+ });
118
+ }
119
+ if (name === undefined)
120
+ return targets;
121
+ const found = targets.find((target) => target.name === name);
122
+ if (found === undefined) {
123
+ throw new OkmError2("OKM1845", `Target ${name} is not configured.`, {
124
+ fix: { summary: "Pass a name from targets." }
125
+ });
126
+ }
127
+ return [found];
128
+ }
129
+ function lastComplete(migrations, done) {
130
+ let version;
131
+ for (const migration of migrations) {
132
+ if (migration.steps.length === 0)
133
+ continue;
134
+ const complete = migration.steps.every((_, index) => done.has(`${migration.id}:${String(index)}`));
135
+ if (!complete)
136
+ break;
137
+ version = migration.id;
138
+ }
139
+ return version;
140
+ }
141
+ async function readMeta(pool) {
142
+ const result = await pool.execute("select catalog_hash, migration_id from okm_meta where id = 'head'");
143
+ const hash = result.rows[0]?.[0];
144
+ const version = result.rows[0]?.[1];
145
+ if (hash === null || hash === undefined || version === null || version === undefined)
146
+ return;
147
+ return { hash, version };
148
+ }
149
+ async function readHistory(pool) {
150
+ const result = await pool.execute("select migration_id, step_index::text, class from okm_history order by migration_id, step_index");
151
+ const rows = [];
152
+ for (const row of result.rows) {
153
+ const migrationId = row[0];
154
+ const step = row[1];
155
+ const stepClass = row[2];
156
+ if (migrationId == null || step == null || stepClass == null)
157
+ continue;
158
+ rows.push({
159
+ migrationId,
160
+ stepIndex: Number(step),
161
+ class: stepClass === "contract" || stepClass === "unclassified" ? stepClass : "expand"
162
+ });
163
+ }
164
+ return rows;
165
+ }
166
+ function wireTrue(value) {
167
+ return value === "t" || value === "true";
168
+ }
169
+ export {
170
+ statusProject
171
+ };