okmodel 0.3.0 → 0.5.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.
- package/README.md +263 -23
- package/dist/contracts/catalog/document.d.ts +26 -2
- package/dist/contracts/driver.d.ts +7 -0
- package/dist/dialects/pg/ext/citext.js +1 -1
- package/dist/dialects/pg/ext/index.js +1 -1
- package/dist/dialects/pg/ext/pg-trgm.js +1 -1
- package/dist/dialects/pg/index.js +3 -3
- package/dist/dialects/pg/introspect.d.ts +6 -0
- package/dist/dialects/pg/role/sql.d.ts +21 -4
- package/dist/dialects/pg/schema.d.ts +15 -6
- package/dist/dialects/pg/table.d.ts +17 -1
- package/dist/dialects/pg/view/index.d.ts +20 -6
- package/dist/dialects/pg/view/index.js +1 -1
- package/dist/dialects/pg/view/scratch.d.ts +2 -1
- package/dist/runtime/catalog-cache.d.ts +17 -0
- package/dist/runtime/compat-words.d.ts +23 -0
- package/dist/runtime/drift-detail.d.ts +20 -4
- package/dist/runtime/drift.d.ts +4 -2
- package/dist/runtime/pg/bun.d.ts +12 -7
- package/dist/runtime/pg/bun.js +5 -2
- package/dist/runtime/pg/pg.d.ts +12 -6
- package/dist/runtime/pg/pg.js +5 -2
- package/dist/runtime/pg/pglite.d.ts +11 -3
- package/dist/runtime/pg/pglite.js +5 -2
- package/dist/runtime/pg/postgresjs.d.ts +12 -6
- package/dist/runtime/pg/postgresjs.js +5 -2
- package/dist/runtime/plan.d.ts +3 -1
- package/dist/runtime/tenancy/index.js +1 -1
- package/dist/runtime/topology.d.ts +191 -0
- package/dist/runtime/traits/index.js +7 -6
- package/dist/runtime/types.d.ts +59 -2
- package/dist/runtime/validate/index.js +2 -2
- package/dist/shared/{x6wysh83.js → 3p4b1fg0.js} +3 -5
- package/dist/shared/{ty3v3hfk.js → 47xzb9fc.js} +2 -2
- package/dist/shared/{fs0ex00p.js → 4ef7mmqf.js} +2 -2
- package/dist/shared/{qybh48nd.js → 5fqx9yh4.js} +6 -2
- package/dist/shared/5mtf6cj3.js +94 -0
- package/dist/shared/{999ade2q.js → 5vdm4sgp.js} +1 -1
- package/dist/shared/{bqha5cg6.js → 6p5k20sm.js} +2 -2
- package/dist/shared/{t616ynfn.js → 8bwbwy8h.js} +71 -13
- package/dist/shared/{th14ygv2.js → 8ktwd3rh.js} +29 -1
- package/dist/shared/{wekze34d.js → 8xsbagad.js} +74 -2
- package/dist/shared/{bryqk9k9.js → 922qbgnw.js} +3 -3
- package/dist/shared/{meck53jv.js → 990a291j.js} +6 -5
- package/dist/shared/{jns2wx4t.js → 9tgmr1gh.js} +1 -1
- package/dist/shared/9yn6a2vd.js +11 -0
- package/dist/shared/{2ssqrv66.js → ayz64vzj.js} +1037 -181
- package/dist/shared/{k34e0xf2.js → bt9sfq0z.js} +16 -14
- package/dist/shared/{scwxrpx2.js → bzsjtd7c.js} +84 -15
- package/dist/shared/{m9tv7xn7.js → ckjbyrt9.js} +4 -4
- package/dist/shared/{ydaz1sv3.js → dxjp14rk.js} +10 -2
- package/dist/shared/{49ypnfwt.js → fancm5pt.js} +24 -229
- package/dist/shared/{6bazvqwm.js → fb00y8fp.js} +2 -2
- package/dist/shared/{1tfdfvhh.js → fyqkk1m0.js} +6 -4
- package/dist/shared/g516zdsb.js +905 -0
- package/dist/shared/{jkc6ws1p.js → g7ez901n.js} +83 -2
- package/dist/shared/{kgnc8grt.js → gdh9mrtp.js} +1 -1
- package/dist/shared/{p24x2334.js → h4nqvjkp.js} +5 -3
- package/dist/shared/{edwqqryd.js → h8ne16fq.js} +1 -1
- package/dist/shared/htnaj77v.js +17 -0
- package/dist/shared/jdgqqx31.js +72 -0
- package/dist/shared/{6w5j844a.js → jsd07prz.js} +2 -2
- package/dist/shared/{m78s7898.js → k7cc9nzk.js} +24 -7
- package/dist/shared/kdkxh3kb.js +758 -0
- package/dist/shared/nkc9sfqb.js +1161 -0
- package/dist/shared/{xva8v7qk.js → p7pfx624.js} +5 -5
- package/dist/shared/{xrfnq5k8.js → qgvt8nx1.js} +11 -2
- package/dist/shared/{ne02ng5c.js → qy9rdq0g.js} +9 -5
- package/dist/shared/{3ekj9x92.js → r6pj4fq2.js} +5 -3
- package/dist/shared/r73pt594.js +426 -0
- package/dist/shared/rasvvzgz.js +21 -0
- package/dist/shared/{01yr20s5.js → sf8m6tfy.js} +2 -2
- package/dist/shared/{hcmdtwgh.js → szm0cksa.js} +4 -1
- package/dist/shared/{axhk06q1.js → tq9afp8d.js} +1 -1
- package/dist/shared/{xw1d69vd.js → wqem4jed.js} +6 -6
- package/dist/shared/wxn4b7pp.js +252 -0
- package/dist/shared/xdpj5kkm.js +2203 -0
- package/dist/shared/xhh1srw3.js +589 -0
- package/dist/shared/{mt5wswjz.js → xsq7v6wp.js} +2 -2
- package/dist/shared/{7fvtrkwr.js → ycatkxmq.js} +1 -1
- package/dist/shared/ykv7wh5b.js +14 -0
- package/dist/shared/{fptpmvxp.js → z2rnngj4.js} +26 -21
- package/dist/tooling/cli.js +46 -17
- package/dist/tooling/migrate/apply.d.ts +61 -5
- package/dist/tooling/migrate/backfill.d.ts +136 -0
- package/dist/tooling/migrate/check.d.ts +65 -0
- package/dist/tooling/migrate/classify.d.ts +108 -0
- package/dist/tooling/migrate/commands.d.ts +2 -2
- package/dist/tooling/migrate/config.d.ts +22 -0
- package/dist/tooling/migrate/doctor.d.ts +3 -0
- package/dist/tooling/migrate/drift.d.ts +18 -2
- package/dist/tooling/migrate/estimate.d.ts +50 -0
- package/dist/tooling/migrate/extensions.d.ts +2 -0
- package/dist/tooling/migrate/files.d.ts +19 -0
- package/dist/tooling/migrate/index.d.ts +3 -2
- package/dist/tooling/migrate/index.js +69 -1
- package/dist/tooling/migrate/lint-rules.d.ts +51 -0
- package/dist/tooling/migrate/lint.d.ts +71 -0
- package/dist/tooling/migrate/managed.d.ts +1 -1
- package/dist/tooling/migrate/plan.d.ts +64 -9
- package/dist/tooling/migrate/project.d.ts +42 -7
- package/dist/tooling/migrate/provision.d.ts +18 -0
- package/dist/tooling/migrate/reference.d.ts +40 -0
- package/dist/tooling/migrate/runner.d.ts +108 -0
- package/dist/tooling/migrate/safe.d.ts +77 -0
- package/dist/tooling/migrate/seed.d.ts +20 -0
- package/dist/tooling/migrate/snapshot.d.ts +78 -0
- package/dist/tooling/migrate/status.d.ts +25 -6
- package/dist/tooling/testing/factories.d.ts +117 -0
- package/dist/tooling/testing/facts.d.ts +75 -0
- package/dist/tooling/testing/index.d.ts +89 -0
- package/dist/tooling/testing/index.js +8 -0
- package/dist/tooling/testing/isolation.d.ts +30 -0
- package/dist/tooling/testing/random.d.ts +40 -0
- package/dist/tooling/testing/record.d.ts +38 -0
- package/package.json +6 -2
- package/dist/shared/5nmdenb6.js +0 -1229
- package/dist/shared/dbjej1tw.js +0 -456
- package/dist/shared/g4f5kcx9.js +0 -37
- package/dist/shared/qbxzvwwc.js +0 -88
- package/dist/shared/zwmqxb0g.js +0 -79
- /package/dist/shared/{75xkjv0t.js → fa9vt245.js} +0 -0
- /package/dist/shared/{0jc3ffzf.js → zvbjc949.js} +0 -0
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
+
assertNamespace2,
|
|
2
3
|
identityKey2,
|
|
3
4
|
identityLabel2,
|
|
4
|
-
|
|
5
|
+
normaliseEdges,
|
|
6
|
+
compareText,
|
|
7
|
+
assertProvenance
|
|
5
8
|
} from "./t4tbsy9h.js";
|
|
6
9
|
import {
|
|
7
10
|
CATALOG_VERSION2
|
|
8
11
|
} from "./4e4c6vq2.js";
|
|
12
|
+
import {
|
|
13
|
+
assertIdentifier2,
|
|
14
|
+
assertStoredText
|
|
15
|
+
} from "./nfzc5z0w.js";
|
|
9
16
|
import {
|
|
10
17
|
catalogError2
|
|
11
18
|
} from "./52szzakm.js";
|
|
@@ -135,4 +142,78 @@ function assertForeignKeys(objects, keys) {
|
|
|
135
142
|
}
|
|
136
143
|
}
|
|
137
144
|
|
|
138
|
-
|
|
145
|
+
// src/contracts/catalog/enum.ts
|
|
146
|
+
function enumType(input) {
|
|
147
|
+
assertNamespace2(input.namespace);
|
|
148
|
+
assertIdentifier2(input.name, "type");
|
|
149
|
+
assertProvenance(input.provenance);
|
|
150
|
+
if (input.labels.length === 0) {
|
|
151
|
+
catalogError2("OKM1020", `Enum ${input.name} must list at least one label.`);
|
|
152
|
+
}
|
|
153
|
+
const labels = [];
|
|
154
|
+
const seen = new Set;
|
|
155
|
+
for (const label of input.labels) {
|
|
156
|
+
assertStoredText(label, "enum label");
|
|
157
|
+
if (label.length === 0) {
|
|
158
|
+
catalogError2("OKM1020", `Enum ${input.name} has an empty label.`);
|
|
159
|
+
}
|
|
160
|
+
if (seen.has(label)) {
|
|
161
|
+
catalogError2("OKM1020", `Enum ${input.name} repeats label ${label}.`);
|
|
162
|
+
}
|
|
163
|
+
seen.add(label);
|
|
164
|
+
labels.push(label);
|
|
165
|
+
}
|
|
166
|
+
const identity = {
|
|
167
|
+
kind: "type",
|
|
168
|
+
namespace: input.namespace,
|
|
169
|
+
name: input.name
|
|
170
|
+
};
|
|
171
|
+
return {
|
|
172
|
+
kind: "type",
|
|
173
|
+
identity,
|
|
174
|
+
owner: input.owner ?? "managed",
|
|
175
|
+
definition: { labels },
|
|
176
|
+
dependencies: normaliseEdges(input.dependencies ?? []),
|
|
177
|
+
provenance: input.provenance
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function domainType(input) {
|
|
181
|
+
assertNamespace2(input.namespace);
|
|
182
|
+
assertIdentifier2(input.name, "type");
|
|
183
|
+
assertProvenance(input.provenance);
|
|
184
|
+
if (input.base.length === 0) {
|
|
185
|
+
catalogError2("OKM1020", `Domain ${input.name} needs a base type.`);
|
|
186
|
+
}
|
|
187
|
+
assertStoredText(input.check, "domain check");
|
|
188
|
+
if (input.check.length === 0) {
|
|
189
|
+
catalogError2("OKM1020", `Domain ${input.name} needs a check.`);
|
|
190
|
+
}
|
|
191
|
+
const identity = {
|
|
192
|
+
kind: "type",
|
|
193
|
+
namespace: input.namespace,
|
|
194
|
+
name: input.name
|
|
195
|
+
};
|
|
196
|
+
const definition = { base: input.base, check: input.check };
|
|
197
|
+
return {
|
|
198
|
+
kind: "type",
|
|
199
|
+
identity,
|
|
200
|
+
owner: input.owner ?? "managed",
|
|
201
|
+
definition,
|
|
202
|
+
dependencies: normaliseEdges(input.dependencies ?? []),
|
|
203
|
+
provenance: input.provenance
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function isDomain(definition) {
|
|
207
|
+
return "base" in definition;
|
|
208
|
+
}
|
|
209
|
+
function sameEnumLabels(left, right) {
|
|
210
|
+
if (left.length !== right.length)
|
|
211
|
+
return false;
|
|
212
|
+
for (let index = 0;index < left.length; index += 1) {
|
|
213
|
+
if (left[index] !== right[index])
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export { dependencyOrder, catalog, enumType, domainType, isDomain, sameEnumLabels };
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
readHandle,
|
|
4
4
|
readCall,
|
|
5
5
|
attachHttp
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./bt9sfq0z.js";
|
|
7
7
|
import {
|
|
8
8
|
selectedColumns,
|
|
9
9
|
parseOrder,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
isRecord,
|
|
16
16
|
registerFailFix,
|
|
17
17
|
fail
|
|
18
|
-
} from "./
|
|
18
|
+
} from "./qgvt8nx1.js";
|
|
19
19
|
import {
|
|
20
20
|
OkmError2,
|
|
21
21
|
throwNamed2
|
|
@@ -30,6 +30,7 @@ var OPTIONS = [
|
|
|
30
30
|
"limit",
|
|
31
31
|
"include",
|
|
32
32
|
"after",
|
|
33
|
+
"route",
|
|
33
34
|
"signal",
|
|
34
35
|
"timeout"
|
|
35
36
|
];
|
|
@@ -69,7 +70,8 @@ function plan(session, table, options, mods, view) {
|
|
|
69
70
|
limit: size + 1,
|
|
70
71
|
include: record.include,
|
|
71
72
|
signal: record.signal,
|
|
72
|
-
timeout: record.timeout
|
|
73
|
+
timeout: record.timeout,
|
|
74
|
+
route: record.route
|
|
73
75
|
}, undefined, session.scope, session.schema.model[table], session.schema, view),
|
|
74
76
|
...after !== undefined ? { after } : {}
|
|
75
77
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/runtime/catalog-cache.ts
|
|
2
|
+
var inflight = new Map;
|
|
3
|
+
function loadOnce(key, load) {
|
|
4
|
+
const found = inflight.get(key);
|
|
5
|
+
if (found !== undefined)
|
|
6
|
+
return found;
|
|
7
|
+
const pending = Promise.resolve().then(load);
|
|
8
|
+
inflight.set(key, pending);
|
|
9
|
+
pending.catch(() => {
|
|
10
|
+
if (inflight.get(key) === pending)
|
|
11
|
+
inflight.delete(key);
|
|
12
|
+
});
|
|
13
|
+
return pending;
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
loadOnce
|
|
17
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
open2
|
|
3
|
+
} from "./wqem4jed.js";
|
|
4
|
+
import"./8bwbwy8h.js";
|
|
5
|
+
import {
|
|
6
|
+
createdOf,
|
|
7
|
+
testing2
|
|
8
|
+
} from "./g516zdsb.js";
|
|
9
|
+
import"./n442h54c.js";
|
|
10
|
+
import {
|
|
11
|
+
assertTargetPolicy,
|
|
12
|
+
assertDirectConnection,
|
|
13
|
+
selectTarget,
|
|
14
|
+
loadConfig,
|
|
15
|
+
loadSchema
|
|
16
|
+
} from "./xdpj5kkm.js";
|
|
17
|
+
import"./ayz64vzj.js";
|
|
18
|
+
import"./8xsbagad.js";
|
|
19
|
+
import {
|
|
20
|
+
OkmError2
|
|
21
|
+
} from "./52szzakm.js";
|
|
22
|
+
|
|
23
|
+
// src/tooling/migrate/seed.ts
|
|
24
|
+
import { existsSync } from "node:fs";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { pathToFileURL } from "node:url";
|
|
27
|
+
async function seedProject(cwd, file, flags) {
|
|
28
|
+
const config = await loadConfig(cwd);
|
|
29
|
+
const target = selectTarget(config, flags.target);
|
|
30
|
+
assertTargetPolicy(target, "seed", flags.allowProtected);
|
|
31
|
+
const path = join(cwd, file);
|
|
32
|
+
if (!existsSync(path)) {
|
|
33
|
+
throw new OkmError2("invalid", `Seed file ${file} was not found.`, {
|
|
34
|
+
fix: { summary: "Pass okm seed <file> a module in this project." }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
assertDirectConnection(target.url, flags.allowPooler || config.allowPooler === true);
|
|
38
|
+
const schema = await loadSchema(cwd, config.schema);
|
|
39
|
+
const pool = open2({ url: target.url, max: 1 });
|
|
40
|
+
const harness = await testing2(schema, { driver: pool, migrate: false });
|
|
41
|
+
try {
|
|
42
|
+
const imported = await import(`${pathToFileURL(path).href}?okm=${Date.now()}`);
|
|
43
|
+
const seed = isRecord(imported) ? imported.default : undefined;
|
|
44
|
+
if (typeof seed !== "function") {
|
|
45
|
+
throw new OkmError2("invalid", `${file} must default-export a function.`, {
|
|
46
|
+
fix: { summary: "export default async function seed(t) { ... }." }
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
await seed(harness);
|
|
50
|
+
return formatCreated(target.name, createdOf(harness));
|
|
51
|
+
} finally {
|
|
52
|
+
await harness.close();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function formatCreated(target, counts) {
|
|
56
|
+
const lines = [`target ${target}`];
|
|
57
|
+
if (counts.length === 0)
|
|
58
|
+
lines.push("created nothing");
|
|
59
|
+
else {
|
|
60
|
+
for (const item of counts)
|
|
61
|
+
lines.push(`${item.table} ${String(item.count)}`);
|
|
62
|
+
}
|
|
63
|
+
return `${lines.join(`
|
|
64
|
+
`)}
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
function isRecord(value) {
|
|
68
|
+
return typeof value === "object" && value !== null;
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
seedProject
|
|
72
|
+
};
|
|
@@ -60,6 +60,7 @@ var TABLE_KNOWN = new Set([
|
|
|
60
60
|
"omitDefaults",
|
|
61
61
|
"presets",
|
|
62
62
|
"primaryKey",
|
|
63
|
+
"reference",
|
|
63
64
|
"relations",
|
|
64
65
|
"renamedFrom",
|
|
65
66
|
"sqlName",
|
|
@@ -71,8 +72,7 @@ var TABLE_KNOWN = new Set([
|
|
|
71
72
|
]);
|
|
72
73
|
var TABLE_LATER = {
|
|
73
74
|
computed: "later",
|
|
74
|
-
policies: "later"
|
|
75
|
-
reference: "0.4"
|
|
75
|
+
policies: "later"
|
|
76
76
|
};
|
|
77
77
|
function table2(name, columns, options) {
|
|
78
78
|
const source = callerLocation(1);
|
|
@@ -5,12 +5,12 @@ import {
|
|
|
5
5
|
openClient,
|
|
6
6
|
withHttp,
|
|
7
7
|
settleCall
|
|
8
|
-
} from "./
|
|
8
|
+
} from "./bt9sfq0z.js";
|
|
9
9
|
import {
|
|
10
10
|
rejectKeys,
|
|
11
11
|
isRecord,
|
|
12
12
|
fail
|
|
13
|
-
} from "./
|
|
13
|
+
} from "./qgvt8nx1.js";
|
|
14
14
|
import {
|
|
15
15
|
OkmError2
|
|
16
16
|
} from "./52szzakm.js";
|
|
@@ -312,8 +312,16 @@ function held(session, frame, after, depth) {
|
|
|
312
312
|
};
|
|
313
313
|
const pool = depth === 0 ? {
|
|
314
314
|
capabilities: base.capabilities,
|
|
315
|
-
execute: (text, params, options) =>
|
|
316
|
-
|
|
315
|
+
execute: (text, params, options) => {
|
|
316
|
+
if (options?.route === "replica")
|
|
317
|
+
replicaInside();
|
|
318
|
+
return guarded(() => frame.conn.execute(text, params, stoppable(frame, options)), false);
|
|
319
|
+
},
|
|
320
|
+
batch: (statements, options) => {
|
|
321
|
+
if (options?.route === "replica")
|
|
322
|
+
replicaInside();
|
|
323
|
+
return guarded(() => frame.conn.batch(statements, stoppable(frame, options)), true);
|
|
324
|
+
},
|
|
317
325
|
stats: () => base.stats(),
|
|
318
326
|
close: () => Promise.resolve()
|
|
319
327
|
} : base;
|
|
@@ -364,13 +372,22 @@ function lockKey(key) {
|
|
|
364
372
|
return ["select pg_advisory_xact_lock($1::bigint)", String(key)];
|
|
365
373
|
}
|
|
366
374
|
function callOf(options) {
|
|
367
|
-
if (options?.signal === undefined && options?.timeout === undefined)
|
|
375
|
+
if (options?.signal === undefined && options?.timeout === undefined && options?.route === undefined) {
|
|
368
376
|
return;
|
|
377
|
+
}
|
|
369
378
|
return {
|
|
370
|
-
...options
|
|
371
|
-
...options
|
|
379
|
+
...options?.signal !== undefined ? { signal: options.signal } : {},
|
|
380
|
+
...options?.timeout !== undefined ? { timeout: options.timeout } : {},
|
|
381
|
+
...options?.route !== undefined ? { route: options.route } : {}
|
|
372
382
|
};
|
|
373
383
|
}
|
|
384
|
+
function replicaInside() {
|
|
385
|
+
throw new OkmError2("OKM1840", "This operation needs the primary.", {
|
|
386
|
+
fix: {
|
|
387
|
+
summary: "Run the operation on the primary. Writes, batch, locks, and tx() never go to a replica."
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
374
391
|
export {
|
|
375
392
|
tx
|
|
376
393
|
};
|