okmodel 0.8.0 → 0.9.1
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 +23 -1
- package/dist/adapters/pg/bunsql-extra.d.ts +5 -5
- package/dist/adapters/pg/bunsql.d.ts +6 -2
- package/dist/adapters/pg/nodepostgres.d.ts +16 -1
- package/dist/adapters/pg/postgres-extra.d.ts +3 -17
- package/dist/adapters/pg/postgresjs.d.ts +2 -1
- package/dist/contracts/driver.d.ts +3 -2
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/errors.d.ts +2 -0
- package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gin.js +20 -0
- package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gist.js +20 -0
- package/dist/dialects/pg/ext/call.d.ts +53 -0
- package/dist/dialects/pg/ext/citext.js +1 -1
- package/dist/dialects/pg/ext/feature.d.ts +26 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
- package/dist/dialects/pg/ext/hstore.d.ts +41 -0
- package/dist/dialects/pg/ext/hstore.js +29 -0
- package/dist/dialects/pg/ext/index.d.ts +56 -0
- package/dist/dialects/pg/ext/index.js +1 -1
- package/dist/dialects/pg/ext/ltree.d.ts +41 -0
- package/dist/dialects/pg/ext/ltree.js +29 -0
- package/dist/dialects/pg/ext/pg-trgm.js +4 -13
- package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
- package/dist/dialects/pg/ext/pgcrypto.js +33 -0
- package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
- package/dist/dialects/pg/ext/unaccent.js +21 -0
- package/dist/dialects/pg/ext/using.d.ts +23 -0
- package/dist/dialects/pg/ext/versions.d.ts +36 -0
- package/dist/dialects/pg/external.d.ts +19 -0
- package/dist/dialects/pg/filters.d.ts +2 -2
- package/dist/dialects/pg/fn/index.js +5 -5
- package/dist/dialects/pg/index.d.ts +1 -0
- package/dist/dialects/pg/index.js +19 -14
- package/dist/dialects/pg/introspect.d.ts +12 -0
- package/dist/dialects/pg/view/index.js +7 -7
- package/dist/dialects/pg/view/scratch.d.ts +4 -1
- package/dist/runtime/artifact-file.d.ts +22 -0
- package/dist/runtime/client.d.ts +10 -0
- package/dist/runtime/drift-detail.d.ts +2 -1
- package/dist/runtime/drift.d.ts +3 -10
- package/dist/runtime/param-limit.d.ts +20 -0
- package/dist/runtime/pg/bun.js +4 -4
- package/dist/runtime/pg/neon.js +4 -4
- package/dist/runtime/pg/pg.js +4 -4
- package/dist/runtime/pg/pglite.js +4 -4
- package/dist/runtime/pg/postgresjs.js +11 -11
- package/dist/runtime/server-check.d.ts +36 -6
- package/dist/runtime/tenancy/index.js +1 -1
- package/dist/runtime/traits/index.js +6 -6
- package/dist/runtime/validate/index.js +2 -2
- package/dist/runtime/write.d.ts +1 -1
- package/dist/shared/{4m6hskg8.js → 0j6qe91y.js} +4 -4
- package/dist/shared/{6m78c8ss.js → 1h5h1rf5.js} +1 -1
- package/dist/shared/{4vbf83xx.js → 2vcnpf0n.js} +1 -1
- package/dist/shared/{qd9hhd8f.js → 3ap5hxvj.js} +2 -1
- package/dist/shared/{v1wad97q.js → 3d7a80fq.js} +1 -1
- package/dist/shared/{wcrheftc.js → 3dr444ny.js} +58 -79
- package/dist/shared/{hm5f8jby.js → 3vvpcphd.js} +8 -7
- package/dist/shared/{760ppr76.js → 4a3mmhhe.js} +2 -2
- package/dist/shared/{mkrn359n.js → 4pkz5nvw.js} +222 -39
- package/dist/shared/{agsfb86s.js → 4te76xc5.js} +4 -4
- package/dist/shared/{63f4ksbz.js → 60y4ahmw.js} +1 -1
- package/dist/shared/61bmrmhr.js +35 -0
- package/dist/shared/{bxas03mq.js → 63qjmhnp.js} +100 -17
- package/dist/shared/{g5yc06ka.js → 67w3kn71.js} +1 -1
- package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
- package/dist/shared/{njga14v4.js → 6vfvsdkt.js} +10 -8
- package/dist/shared/{kj9d8maq.js → 6xqvesa5.js} +1 -1
- package/dist/shared/8gdbty5v.js +665 -0
- package/dist/shared/{pan0370z.js → 8ma6drzr.js} +211 -30
- package/dist/shared/{mnvjvqyp.js → 8p2bgye0.js} +124 -32
- package/dist/shared/{mfedzr74.js → 8qwqrxed.js} +14 -6
- package/dist/shared/{hfqmpasr.js → 8v7vzpgt.js} +11 -8
- package/dist/shared/{7ghwamrf.js → 99qp9vtg.js} +1 -1
- package/dist/shared/{zgex00fd.js → ak61ye1f.js} +5 -5
- package/dist/shared/{dpc2r7rb.js → bdekbvmt.js} +218 -95
- package/dist/shared/{jebgrkeq.js → bxjq6xqv.js} +2 -2
- package/dist/shared/c7dqd3gk.js +1806 -0
- package/dist/shared/ddh72ym5.js +20 -0
- package/dist/shared/e1c55v04.js +10 -0
- package/dist/shared/{mtw6jz76.js → e275q7sd.js} +1 -1
- package/dist/shared/{k86n8vq3.js → ekhq3ytz.js} +1 -1
- package/dist/shared/esy4dyxe.js +17 -0
- package/dist/shared/{gcefca6p.js → f9t9g54z.js} +22 -9
- package/dist/shared/{sjk86yrx.js → fk9vef30.js} +84 -73
- package/dist/shared/fkjne6gx.js +8 -0
- package/dist/shared/{e8zyaqvj.js → fne90dvz.js} +4 -1
- package/dist/shared/{needfe47.js → g89fmz5s.js} +1 -1
- package/dist/shared/{m4xff2a6.js → ghqzdp94.js} +2 -2
- package/dist/shared/{n0jmpgj1.js → gr9sn4za.js} +1 -1
- package/dist/shared/{5mtf6cj3.js → gzgfsspx.js} +5 -2
- package/dist/shared/h9811jjm.js +17 -0
- package/dist/shared/{z581d7ny.js → hgt69zjf.js} +2 -2
- package/dist/shared/{35q0n9tz.js → jvxcp1qk.js} +71 -87
- package/dist/shared/k73e8n9d.js +136 -0
- package/dist/shared/{195pzzzz.js → kzgrcy8s.js} +12 -8
- package/dist/shared/kzgrnckd.js +29 -0
- package/dist/shared/{p3xbdcvt.js → mz48rs74.js} +68 -8
- package/dist/shared/{zbqbmmrp.js → n6je5b28.js} +13 -26
- package/dist/shared/{b6d6p0zc.js → ns35jqz0.js} +75 -49
- package/dist/shared/{n05z9nwz.js → nstwgzn8.js} +1 -1
- package/dist/{tooling/shared/08kemxjd.js → shared/pgsak1yw.js} +1 -1
- package/dist/shared/py2zrrm6.js +451 -0
- package/dist/shared/{9dr2qnx7.js → qqm3ze6q.js} +1 -1
- package/dist/shared/{wvdjznah.js → rcjm0yn7.js} +31 -38
- package/dist/shared/rged92v6.js +17 -0
- package/dist/shared/{jp36k7dp.js → rw4tpcd0.js} +81 -51
- package/dist/shared/{bsek72fg.js → s5qe47a6.js} +3 -0
- package/dist/shared/{1d9q9cv2.js → smxzjz60.js} +2 -2
- package/dist/shared/{wz2a78mp.js → th5rnaxw.js} +1 -1
- package/dist/{tooling/shared/rs1jb051.js → shared/tr64w5p0.js} +1 -1
- package/dist/shared/{14x60fbf.js → tyqapcgk.js} +73 -10
- package/dist/shared/vsna85qf.js +8 -0
- package/dist/shared/{63qtkrca.js → vy47ryqa.js} +55 -5
- package/dist/shared/{jx2m62cs.js → wbdh9qbg.js} +7 -5
- package/dist/shared/{f4jy1j7x.js → wp7y8q3y.js} +946 -105
- package/dist/shared/{16kvjebh.js → xbd9xs6p.js} +7 -26
- package/dist/shared/{bah9nbg3.js → xbvz446k.js} +18 -23
- package/dist/shared/{p5nh3r8q.js → y6tfjk9q.js} +2 -2
- package/dist/shared/{3bb7wsqt.js → ycnft340.js} +1 -1
- package/dist/shared/{z7s6fpxv.js → ymenf259.js} +1 -1
- package/dist/shared/{0wrea3jq.js → ysdw2fg3.js} +10 -2
- package/dist/shared/zecrwdk9.js +61 -0
- package/dist/shared/{3t6kw83m.js → zm2rzqba.js} +2 -1
- package/dist/tooling/cli.js +200 -50
- package/dist/tooling/driver-run.js +109 -343
- package/dist/tooling/github/comment.d.ts +56 -0
- package/dist/tooling/github/post-comment.d.ts +17 -0
- package/dist/tooling/migrate/apply.d.ts +17 -2
- package/dist/tooling/migrate/commands.d.ts +2 -1
- package/dist/tooling/migrate/config.d.ts +13 -0
- package/dist/tooling/migrate/drift.d.ts +12 -0
- package/dist/tooling/migrate/driver-url.d.ts +17 -0
- package/dist/tooling/migrate/export.d.ts +165 -0
- package/dist/tooling/migrate/ext-surface.d.ts +80 -0
- package/dist/tooling/migrate/ext.d.ts +31 -4
- package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
- package/dist/tooling/migrate/index.d.ts +3 -0
- package/dist/tooling/migrate/index.js +57 -10
- package/dist/tooling/migrate/lint-rules.d.ts +18 -1
- package/dist/tooling/migrate/lint.d.ts +14 -1
- package/dist/tooling/migrate/place.d.ts +18 -0
- package/dist/tooling/migrate/plan-json.d.ts +65 -0
- package/dist/tooling/migrate/policy.d.ts +17 -5
- package/dist/tooling/migrate/pooler-probe.d.ts +23 -0
- package/dist/tooling/migrate/project.d.ts +10 -1
- package/dist/tooling/migrate/pull-emit.d.ts +98 -0
- package/dist/tooling/migrate/pull-routines.d.ts +126 -0
- package/dist/tooling/migrate/pull-verify.d.ts +26 -0
- package/dist/tooling/migrate/pull.d.ts +65 -0
- package/dist/tooling/migrate/reprint.d.ts +32 -0
- package/dist/tooling/migrate/runner.d.ts +24 -1
- package/dist/tooling/migrate/sandbox.d.ts +8 -2
- package/dist/tooling/migrate/schema-api.d.ts +43 -0
- package/dist/tooling/migrate/sql-lex.d.ts +18 -0
- package/dist/tooling/shared/{ppnnnvj8.js → 09a6vsys.js} +1 -1
- package/dist/tooling/shared/{7ae7rjmn.js → 0v9ptnxp.js} +8 -8
- package/dist/tooling/shared/{fb9k2qwd.js → 0wtzps9p.js} +11 -30
- package/dist/tooling/shared/{a6pp9d12.js → 0yhf1db4.js} +6 -6
- package/dist/tooling/shared/{dy672fz6.js → 19msgrsc.js} +2 -2
- package/dist/{shared/q0cqt2sp.js → tooling/shared/1fwfm5m3.js} +1 -1
- package/dist/tooling/shared/{f9mphxej.js → 2jdn09e2.js} +401 -24
- package/dist/tooling/shared/{jne7b93p.js → 2qrte2ct.js} +5 -5
- package/dist/tooling/shared/{5bvw2nev.js → 2v4nwnkb.js} +1 -1
- package/dist/tooling/shared/{spk1jg3r.js → 33z39trp.js} +106 -23
- package/dist/tooling/shared/{z8d7ptht.js → 353vnw9z.js} +5 -5
- package/dist/tooling/shared/{dw08f3m8.js → 390kry9g.js} +2 -2
- package/dist/tooling/shared/{xjs6zqtc.js → 3f6etb9z.js} +18 -31
- package/dist/{shared/bnby0esn.js → tooling/shared/3t2cqmsx.js} +1 -1
- package/dist/tooling/shared/{wwnekq5n.js → 4dzvjtpy.js} +1 -1
- package/dist/tooling/shared/{y5656f0e.js → 4ec0nxvw.js} +10 -10
- package/dist/tooling/shared/{3m1hkg7z.js → 4tg2bn41.js} +59 -78
- package/dist/tooling/shared/{zvnhh1n0.js → 5rah55z0.js} +2 -2
- package/dist/tooling/shared/{pqy21k24.js → 804w1t69.js} +4 -4
- package/dist/tooling/shared/8g0m0rvd.js +134 -0
- package/dist/tooling/shared/8msbtw5s.js +8 -0
- package/dist/tooling/shared/{4d2w25vw.js → 8t22h3h7.js} +2 -2
- package/dist/tooling/shared/{smn6kz1p.js → 91c59b7b.js} +2 -2
- package/dist/tooling/shared/{aftb2mwr.js → adk9k6va.js} +1 -1
- package/dist/tooling/shared/{j9t5s12a.js → ajjd5cwz.js} +2 -2
- package/dist/tooling/shared/{cmptmb4f.js → angjck01.js} +1 -1
- package/dist/tooling/shared/{yw30vnq2.js → asnnc3v5.js} +1 -1
- package/dist/tooling/shared/{ma2340rx.js → bj1kyqc8.js} +2 -2
- package/dist/tooling/shared/{2wtvc7rw.js → bt3tjemb.js} +11 -3
- package/dist/tooling/shared/{ec71zqgt.js → chk2bh4f.js} +2 -2
- package/dist/tooling/shared/{gmcf9cxf.js → ckq4z5ax.js} +5 -2
- package/dist/tooling/shared/{w7qe8sj1.js → d3rhb24q.js} +1 -1
- package/dist/tooling/shared/{y031jct9.js → d8q00vxg.js} +4 -4
- package/dist/tooling/shared/{vs0t6qt8.js → dx188rxs.js} +2 -2
- package/dist/tooling/shared/{g9ad4n80.js → efq6p9df.js} +35 -42
- package/dist/tooling/shared/{ddjtfgnx.js → en6rwzq0.js} +3 -3
- package/dist/tooling/shared/{6nyfyw70.js → f2r5g0fs.js} +2 -2
- package/dist/tooling/shared/{03k6res6.js → f4gep0nk.js} +1 -1
- package/dist/tooling/shared/{gfvtj6d0.js → f8a010fm.js} +13 -11
- package/dist/tooling/shared/{3tq8pnb8.js → fdsek6pa.js} +1 -1
- package/dist/tooling/shared/fvmrxsd1.js +8 -0
- package/dist/tooling/shared/{733a1tq3.js → g3xybeqf.js} +4 -3
- package/dist/tooling/shared/{pwsytxm5.js → gefmpwsa.js} +1 -1
- package/dist/tooling/shared/{mtrqn2hn.js → gjj71hfh.js} +25 -30
- package/dist/tooling/shared/{8sqrsw3s.js → jgzt69pa.js} +5 -5
- package/dist/tooling/shared/{nf7jmhfa.js → jm30k2ca.js} +10 -8
- package/dist/tooling/shared/{vx86qjv8.js → kayqzpbk.js} +6 -3
- package/dist/tooling/shared/{zhwnfyb2.js → kvw1672d.js} +1 -1
- package/dist/tooling/shared/{rq5kk8j6.js → mr1kcgpw.js} +3 -3
- package/dist/tooling/shared/{72fyg4zv.js → mwbdf409.js} +1 -1
- package/dist/tooling/shared/{wt7j7nf6.js → ns9207v3.js} +1 -1
- package/dist/tooling/shared/{9xzm7hjg.js → p6tjv97k.js} +3 -3
- package/dist/tooling/shared/{yfr8hzhm.js → p73evwf0.js} +1 -1
- package/dist/tooling/shared/{dzx85q70.js → phc1nc4g.js} +1 -1
- package/dist/tooling/shared/{417zdsk7.js → ppybjw50.js} +79 -16
- package/dist/tooling/shared/{yk9mp7vb.js → qdrn8ghn.js} +5 -4
- package/dist/tooling/shared/rd8h01ta.js +20 -0
- package/dist/tooling/shared/{bz2dqhab.js → rwg8y90m.js} +3 -3
- package/dist/tooling/shared/{xhrnjch9.js → ry2f3w8p.js} +3 -3
- package/dist/tooling/shared/{a7q7t4n3.js → ryc5sa58.js} +8 -8
- package/dist/tooling/shared/{2revefqt.js → ss87qxwv.js} +2 -2
- package/dist/tooling/shared/{rf83gr2d.js → vg68k11z.js} +7 -3
- package/dist/tooling/shared/{p7f08ktn.js → vms9dta5.js} +73 -89
- package/dist/tooling/shared/{3rrw5w8f.js → xchpnbdv.js} +1 -1
- package/dist/tooling/shared/{djydjpqt.js → xn6p01fh.js} +5 -5
- package/dist/tooling/shared/{9kazs5p6.js → xwr6q618.js} +3 -3
- package/dist/tooling/shared/{ep8zh3bk.js → xx3gmq94.js} +1 -1
- package/dist/tooling/shared/{tn8gay14.js → y2bd7yfx.js} +21 -13
- package/dist/tooling/shared/{vraj6d74.js → y4gq9rbe.js} +11 -11
- package/dist/tooling/shared/y4vwft92.js +9 -0
- package/dist/tooling/shared/{345tbc2k.js → yz68xcmc.js} +1 -1
- package/dist/tooling/testing/factories.d.ts +1 -3
- package/dist/tooling/testing/index.js +2 -2
- package/package.json +39 -9
- package/dist/shared/3449rcae.js +0 -14
- package/dist/shared/fjpnhqan.js +0 -71
- package/dist/shared/n41w4fbz.js +0 -113
- package/dist/tooling/shared/pw8fgahx.js +0 -69
- /package/dist/shared/{ae4j5f42.js → mfvx6kjx.js} +0 -0
|
@@ -3,18 +3,18 @@ import {
|
|
|
3
3
|
} from "./cm3w0ywp.js";
|
|
4
4
|
import {
|
|
5
5
|
noTimeout
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./tr64w5p0.js";
|
|
7
7
|
import {
|
|
8
8
|
noticeBuffer,
|
|
9
9
|
WireSession
|
|
10
|
-
} from "./
|
|
10
|
+
} from "./e275q7sd.js";
|
|
11
11
|
import {
|
|
12
12
|
BUNSQL_CAPABILITIES,
|
|
13
13
|
driverErrors,
|
|
14
14
|
rejectClosed,
|
|
15
15
|
mapFailure,
|
|
16
16
|
runCall
|
|
17
|
-
} from "./
|
|
17
|
+
} from "./mfvx6kjx.js";
|
|
18
18
|
|
|
19
19
|
// src/adapters/pg/bunsql.ts
|
|
20
20
|
import { SQL as BunSQL } from "bun";
|
|
@@ -30,7 +30,6 @@ function open5(config) {
|
|
|
30
30
|
let closed = false;
|
|
31
31
|
const isClosed = () => closed;
|
|
32
32
|
const named = config.prepared === "named";
|
|
33
|
-
const parked = [];
|
|
34
33
|
let dropped = 0;
|
|
35
34
|
let closures = 0;
|
|
36
35
|
const sql = new BunSQL(config.url, {
|
|
@@ -57,7 +56,6 @@ function open5(config) {
|
|
|
57
56
|
});
|
|
58
57
|
const held = {
|
|
59
58
|
sql,
|
|
60
|
-
parked,
|
|
61
59
|
acquireMs,
|
|
62
60
|
counters,
|
|
63
61
|
notices,
|
|
@@ -66,26 +64,26 @@ function open5(config) {
|
|
|
66
64
|
};
|
|
67
65
|
const run = (text, params, watch) => {
|
|
68
66
|
const sent = dropped;
|
|
69
|
-
return root.query(text, params, watch).catch((error) => import("./
|
|
67
|
+
return root.query(text, params, watch).catch((error) => import("./rcjm0yn7.js").then((mod) => mod.recover(sql, error, text, root.depth(), clientPools.has(pool), dropped > sent, () => root.query(text, params, watch))));
|
|
70
68
|
};
|
|
71
69
|
const afterDrop = (text, params, watch) => {
|
|
72
70
|
if (dropped === 0)
|
|
73
71
|
return run(text, params, watch);
|
|
74
72
|
const seen = dropped;
|
|
75
|
-
return import("./
|
|
73
|
+
return import("./rcjm0yn7.js").then((mod) => mod.drainClosed(sql).then(() => {
|
|
76
74
|
if (dropped === seen)
|
|
77
75
|
dropped = 0;
|
|
78
76
|
return run(text, params, watch);
|
|
79
77
|
}));
|
|
80
78
|
};
|
|
81
|
-
const checkout = () => closed ? rejectClosed() : import("./
|
|
79
|
+
const checkout = () => closed ? rejectClosed() : import("./rcjm0yn7.js").then((mod) => mod.checkout(held));
|
|
82
80
|
const pool = {
|
|
83
81
|
capabilities: BUNSQL_CAPABILITIES,
|
|
84
82
|
execute(text, params, options) {
|
|
85
83
|
const refused = noTimeout(options);
|
|
86
84
|
if (refused !== undefined)
|
|
87
85
|
return refused;
|
|
88
|
-
return runCall(closed, options, (watch) =>
|
|
86
|
+
return runCall(closed, options, (watch) => afterDrop(text, params, watch));
|
|
89
87
|
},
|
|
90
88
|
async batch(statements, options) {
|
|
91
89
|
const refused = noTimeout(options);
|
|
@@ -101,17 +99,16 @@ function open5(config) {
|
|
|
101
99
|
reserve: () => checkout(),
|
|
102
100
|
stream(text, params) {
|
|
103
101
|
return async function* () {
|
|
104
|
-
const { streamRows } = await import("./
|
|
102
|
+
const { streamRows } = await import("./rcjm0yn7.js");
|
|
105
103
|
yield* streamRows(checkout, text, params);
|
|
106
104
|
}();
|
|
107
105
|
},
|
|
108
106
|
listen(channel, onNotify) {
|
|
109
|
-
return import("./
|
|
107
|
+
return import("./rcjm0yn7.js").then((mod) => mod.listen(sql, closed, channel, onNotify));
|
|
110
108
|
},
|
|
111
109
|
stats: () => statsOf(counters, max),
|
|
112
110
|
async close() {
|
|
113
111
|
closed = true;
|
|
114
|
-
await releaseParked(parked);
|
|
115
112
|
await sql.close();
|
|
116
113
|
}
|
|
117
114
|
};
|
|
@@ -149,24 +146,14 @@ async function reserve(sql, acquireMs, counters) {
|
|
|
149
146
|
const errors = await driverErrors();
|
|
150
147
|
throw errors.acquireTimeout();
|
|
151
148
|
}
|
|
149
|
+
if (error instanceof Error && (error.message === "Connection closed" || error.message === "connection must be a PostgresSQLConnection")) {
|
|
150
|
+
throw new DriverError2(error.message, { cause: error, sqlstate: "08006" });
|
|
151
|
+
}
|
|
152
152
|
throw await mapFailure(error);
|
|
153
153
|
} finally {
|
|
154
154
|
counters.waiting = Math.max(0, counters.waiting - 1);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
async function park(parked, reserved) {
|
|
158
|
-
parked.push(reserved);
|
|
159
|
-
while (parked.length > 1) {
|
|
160
|
-
const extra = parked.shift();
|
|
161
|
-
if (extra !== undefined)
|
|
162
|
-
await releaseReserved(extra);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async function releaseParked(parked) {
|
|
166
|
-
const pending = parked.splice(0);
|
|
167
|
-
for (const reserved of pending)
|
|
168
|
-
await releaseReserved(reserved);
|
|
169
|
-
}
|
|
170
157
|
function releaseReserved(reserved) {
|
|
171
158
|
const done = reserved.release();
|
|
172
159
|
return done instanceof Promise ? done.then(() => {
|
|
@@ -187,4 +174,4 @@ function statsOf(counters, size) {
|
|
|
187
174
|
};
|
|
188
175
|
}
|
|
189
176
|
|
|
190
|
-
export { markClientPool, open5, send2, reserve,
|
|
177
|
+
export { markClientPool, open5, send2, reserve, releaseReserved };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
renderCatalog2
|
|
3
|
+
} from "./fk9vef30.js";
|
|
1
4
|
import {
|
|
2
5
|
viewGlobalReason,
|
|
3
6
|
viewMentions
|
|
4
|
-
} from "./
|
|
5
|
-
import {
|
|
6
|
-
renderCatalog
|
|
7
|
-
} from "./sjk86yrx.js";
|
|
7
|
+
} from "./4a3mmhhe.js";
|
|
8
8
|
import {
|
|
9
9
|
createClient
|
|
10
|
-
} from "./
|
|
10
|
+
} from "./xbvz446k.js";
|
|
11
11
|
import {
|
|
12
12
|
OkmError2
|
|
13
13
|
} from "./52szzakm.js";
|
|
@@ -189,29 +189,30 @@ function bindFactories(host, definitions) {
|
|
|
189
189
|
}
|
|
190
190
|
return bound;
|
|
191
191
|
}
|
|
192
|
-
async function insertRow(host, table, overrides, children, inherited) {
|
|
193
|
-
|
|
192
|
+
async function insertRow(host, table, overrides, children, inherited, creating) {
|
|
193
|
+
const inflight = creating ?? new Set;
|
|
194
|
+
if (inflight.has(table)) {
|
|
194
195
|
throw new OkmError2("invalid", `Factory cycle at ${table}.`, {
|
|
195
196
|
fix: { summary: "A ref() points back at a row that is still being created." }
|
|
196
197
|
});
|
|
197
198
|
}
|
|
198
|
-
|
|
199
|
+
inflight.add(table);
|
|
199
200
|
try {
|
|
200
|
-
return await insertPrepared(host, table, overrides, children, inherited);
|
|
201
|
+
return await insertPrepared(host, table, overrides, children, inherited, inflight);
|
|
201
202
|
} finally {
|
|
202
|
-
|
|
203
|
+
inflight.delete(table);
|
|
203
204
|
}
|
|
204
205
|
}
|
|
205
|
-
async function insertPrepared(host, table, overrides, children, inherited) {
|
|
206
|
+
async function insertPrepared(host, table, overrides, children, inherited, creating) {
|
|
206
207
|
const facts = requireTable(host, table);
|
|
207
208
|
const defined = host.definitions.get(table)?.(context(host)) ?? {};
|
|
208
209
|
const merged = { ...defined, ...overrides };
|
|
209
|
-
const
|
|
210
|
-
const taken = takeTenant(merged, facts.tenant ?
|
|
210
|
+
const keys = tenantKeyNames(host);
|
|
211
|
+
const taken = takeTenant(merged, facts.tenant ? keys : []);
|
|
211
212
|
const requested = taken.tenant ?? inherited;
|
|
212
213
|
const tenant = facts.tenant ? requested ?? host.rng.uuid() : undefined;
|
|
213
|
-
const resolved = await resolveRefs(host, taken.rest, tenant);
|
|
214
|
-
await fillRequired(host, facts, resolved, tenant);
|
|
214
|
+
const resolved = await resolveRefs(host, taken.rest, tenant, creating);
|
|
215
|
+
await fillRequired(host, facts, resolved, tenant, creating);
|
|
215
216
|
const row = await writeRow(host, facts, resolved, tenant);
|
|
216
217
|
host.cache.set(cacheKey(table, facts.tenant ? tenant : undefined), row);
|
|
217
218
|
host.created.set(table, (host.created.get(table) ?? 0) + 1);
|
|
@@ -227,7 +228,7 @@ async function insertPrepared(host, table, overrides, children, inherited) {
|
|
|
227
228
|
}
|
|
228
229
|
const link = linkFields(host, facts, requireTable(host, child), row);
|
|
229
230
|
for (let index = 0;index < count; index += 1) {
|
|
230
|
-
await insertRow(host, child, link, undefined, tenant);
|
|
231
|
+
await insertRow(host, child, link, undefined, tenant, creating);
|
|
231
232
|
}
|
|
232
233
|
}
|
|
233
234
|
}
|
|
@@ -276,20 +277,26 @@ function context(host) {
|
|
|
276
277
|
}
|
|
277
278
|
};
|
|
278
279
|
}
|
|
279
|
-
function takeTenant(row,
|
|
280
|
-
if (
|
|
280
|
+
function takeTenant(row, keys) {
|
|
281
|
+
if (keys.length === 0)
|
|
281
282
|
return { tenant: undefined, rest: row };
|
|
282
|
-
const value = row[key];
|
|
283
283
|
const rest = { ...row };
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
284
|
+
let tenant;
|
|
285
|
+
for (const key of keys) {
|
|
286
|
+
if (!Object.hasOwn(rest, key))
|
|
287
|
+
continue;
|
|
288
|
+
const value = rest[key];
|
|
289
|
+
delete rest[key];
|
|
290
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
291
|
+
throw new OkmError2("invalid", `${key} must be a uuid string.`, {
|
|
292
|
+
fix: { summary: `Pass create({ ${key} }) the tenant uuid.` }
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
tenant ??= value;
|
|
289
296
|
}
|
|
290
|
-
return { tenant
|
|
297
|
+
return { tenant, rest };
|
|
291
298
|
}
|
|
292
|
-
async function resolveRefs(host, row, tenant) {
|
|
299
|
+
async function resolveRefs(host, row, tenant, creating) {
|
|
293
300
|
const resolved = {};
|
|
294
301
|
for (const field of Object.keys(row)) {
|
|
295
302
|
const value = row[field];
|
|
@@ -298,18 +305,18 @@ async function resolveRefs(host, row, tenant) {
|
|
|
298
305
|
resolved[field] = value;
|
|
299
306
|
continue;
|
|
300
307
|
}
|
|
301
|
-
resolved[field] = primaryValue(await referenced(host, target, tenant), requireTable(host, target), host
|
|
308
|
+
resolved[field] = primaryValue(await referenced(host, target, tenant, creating), requireTable(host, target), tenantKeyNames(host));
|
|
302
309
|
}
|
|
303
310
|
return resolved;
|
|
304
311
|
}
|
|
305
|
-
async function fillRequired(host, facts, row, tenant) {
|
|
312
|
+
async function fillRequired(host, facts, row, tenant, creating) {
|
|
306
313
|
for (const column of facts.columns) {
|
|
307
314
|
if (!isRequired(column) || Object.hasOwn(row, column.field))
|
|
308
315
|
continue;
|
|
309
316
|
const foreign = facts.foreignKeys.find((key) => key.columns.includes(column.sql));
|
|
310
317
|
if (foreign !== undefined) {
|
|
311
318
|
const target = factsBySql(host, foreign.target);
|
|
312
|
-
const parent = await referenced(host, target.name, tenant);
|
|
319
|
+
const parent = await referenced(host, target.name, tenant, creating);
|
|
313
320
|
assignForeign(host, facts, foreign, parent, row);
|
|
314
321
|
if (Object.hasOwn(row, column.field))
|
|
315
322
|
continue;
|
|
@@ -319,7 +326,7 @@ async function fillRequired(host, facts, row, tenant) {
|
|
|
319
326
|
}
|
|
320
327
|
function assignForeign(host, child, foreign, parent, row) {
|
|
321
328
|
const target = factsBySql(host, foreign.target);
|
|
322
|
-
const
|
|
329
|
+
const keys = new Set(tenantKeyNames(host));
|
|
323
330
|
for (let index = 0;index < foreign.columns.length; index += 1) {
|
|
324
331
|
const childSql = foreign.columns[index];
|
|
325
332
|
const parentSql = foreign.targetColumns[index];
|
|
@@ -327,25 +334,36 @@ function assignForeign(host, child, foreign, parent, row) {
|
|
|
327
334
|
continue;
|
|
328
335
|
const field = fieldOf(child, childSql);
|
|
329
336
|
const source = fieldOf(target, parentSql);
|
|
330
|
-
if (field === undefined || source === undefined || field
|
|
337
|
+
if (field === undefined || source === undefined || keys.has(field))
|
|
331
338
|
continue;
|
|
332
339
|
if (!Object.hasOwn(row, field))
|
|
333
340
|
row[field] = parent[source];
|
|
334
341
|
}
|
|
335
342
|
}
|
|
336
|
-
async function referenced(host, table, tenant) {
|
|
343
|
+
async function referenced(host, table, tenant, creating) {
|
|
337
344
|
const facts = requireTable(host, table);
|
|
338
345
|
const scope = facts.tenant ? tenant : undefined;
|
|
339
346
|
const cached = host.cache.get(cacheKey(table, scope));
|
|
340
347
|
if (cached !== undefined)
|
|
341
348
|
return cached;
|
|
342
|
-
return insertRow(host, table, scope === undefined ? undefined : tenantOverride(host, scope), undefined, scope);
|
|
349
|
+
return insertRow(host, table, scope === undefined ? undefined : tenantOverride(host, scope), undefined, scope, creating);
|
|
343
350
|
}
|
|
344
351
|
function tenantOverride(host, tenant) {
|
|
345
|
-
const
|
|
346
|
-
if (
|
|
352
|
+
const keys = tenantKeyNames(host);
|
|
353
|
+
if (keys.length === 0)
|
|
347
354
|
return;
|
|
348
|
-
|
|
355
|
+
const overrides = {};
|
|
356
|
+
for (const key of keys)
|
|
357
|
+
overrides[key] = tenant;
|
|
358
|
+
return overrides;
|
|
359
|
+
}
|
|
360
|
+
function tenantKeyNames(host) {
|
|
361
|
+
const tenancy = host.schema.tenancy;
|
|
362
|
+
if (tenancy === undefined)
|
|
363
|
+
return [];
|
|
364
|
+
if (tenancy.keys !== undefined && tenancy.keys.length > 0)
|
|
365
|
+
return tenancy.keys;
|
|
366
|
+
return [tenancy.key];
|
|
349
367
|
}
|
|
350
368
|
function linkFields(host, parent, child, row) {
|
|
351
369
|
const many = parent.relations.find((relation) => relation.kind === "many" && relation.table === child.name);
|
|
@@ -366,7 +384,7 @@ function linkFields(host, parent, child, row) {
|
|
|
366
384
|
});
|
|
367
385
|
}
|
|
368
386
|
function paired(host, child, parent, childSql, parentSql, row) {
|
|
369
|
-
const
|
|
387
|
+
const keys = new Set(tenantKeyNames(host));
|
|
370
388
|
const linked = {};
|
|
371
389
|
for (let index = 0;index < childSql.length; index += 1) {
|
|
372
390
|
const childName = childSql[index];
|
|
@@ -375,7 +393,7 @@ function paired(host, child, parent, childSql, parentSql, row) {
|
|
|
375
393
|
continue;
|
|
376
394
|
const field = fieldOf(child, childName);
|
|
377
395
|
const source = fieldOf(parent, parentName);
|
|
378
|
-
if (field === undefined || source === undefined || field
|
|
396
|
+
if (field === undefined || source === undefined || keys.has(field))
|
|
379
397
|
continue;
|
|
380
398
|
linked[field] = row[source];
|
|
381
399
|
}
|
|
@@ -463,8 +481,9 @@ function enumLabels(catalog, dataType) {
|
|
|
463
481
|
}
|
|
464
482
|
return;
|
|
465
483
|
}
|
|
466
|
-
function primaryValue(row, facts,
|
|
467
|
-
const
|
|
484
|
+
function primaryValue(row, facts, tenantKeys) {
|
|
485
|
+
const skip = new Set(tenantKeys);
|
|
486
|
+
const fields = facts.primary.filter((field) => !skip.has(field));
|
|
468
487
|
if (fields.length !== 1) {
|
|
469
488
|
throw new OkmError2("invalid", `ref(${facts.name}) needs a single primary key.`, {
|
|
470
489
|
fix: { summary: "Set the foreign-key columns in the factory." }
|
|
@@ -590,16 +609,18 @@ async function isolation(host) {
|
|
|
590
609
|
}
|
|
591
610
|
}
|
|
592
611
|
async function checkTable(host, facts, tenantA, tenantB) {
|
|
593
|
-
const key = host.schema.tenancy?.key;
|
|
594
|
-
if (key === undefined)
|
|
595
|
-
return;
|
|
596
612
|
const keys = tenantKeys(host);
|
|
613
|
+
if (keys.length === 0)
|
|
614
|
+
return;
|
|
597
615
|
if (host.definitions.size > 0 && !host.definitions.has(facts.name)) {
|
|
598
616
|
throw new OkmError2("invalid", `Factory ${facts.name} is missing.`, {
|
|
599
617
|
fix: { summary: `Add ${facts.name} to factories().` }
|
|
600
618
|
});
|
|
601
619
|
}
|
|
602
|
-
const
|
|
620
|
+
const overrides = {};
|
|
621
|
+
for (const key of keys)
|
|
622
|
+
overrides[key] = tenantB;
|
|
623
|
+
const row = await insertRow(host, facts.name, overrides, undefined, tenantB);
|
|
603
624
|
const where = primaryWhere(facts, row, keys);
|
|
604
625
|
const client = openTenant(host, tenantA);
|
|
605
626
|
const handle = tableHandle2(client, facts.name);
|
|
@@ -762,7 +783,14 @@ async function checkFlips(host, facts, keys, tenantA, tenantB) {
|
|
|
762
783
|
continue;
|
|
763
784
|
values[flipped] = tenantB;
|
|
764
785
|
const client = openTenant(host, values);
|
|
765
|
-
|
|
786
|
+
let stored;
|
|
787
|
+
try {
|
|
788
|
+
stored = await tableHandle2(client, facts.name).insert(data);
|
|
789
|
+
} catch (error) {
|
|
790
|
+
if (error instanceof OkmError2 && error.kind === "foreign_key")
|
|
791
|
+
continue;
|
|
792
|
+
throw error;
|
|
793
|
+
}
|
|
766
794
|
if (!isRow2(stored))
|
|
767
795
|
continue;
|
|
768
796
|
const where = primaryWhere(facts, stored, keys);
|
|
@@ -863,9 +891,8 @@ async function checkView(host, view, keys, tenantA, tenantB) {
|
|
|
863
891
|
for (const tenant of [tenantA, tenantB]) {
|
|
864
892
|
for (const name of sources) {
|
|
865
893
|
const facts = requireFacts(host, name);
|
|
866
|
-
const key = keys[0];
|
|
867
894
|
const overrides = markerFor(view, facts, keys, tenant);
|
|
868
|
-
|
|
895
|
+
for (const key of keys)
|
|
869
896
|
overrides[key] = tenant;
|
|
870
897
|
const row = await insertRow(host, name, overrides, undefined, tenant);
|
|
871
898
|
if (tenant === tenantB)
|
|
@@ -1301,7 +1328,7 @@ async function testing2(schema, options) {
|
|
|
1301
1328
|
const seed = options.seed ?? 1;
|
|
1302
1329
|
const pool = await options.driver;
|
|
1303
1330
|
if (options.migrate !== false) {
|
|
1304
|
-
for (const statement of
|
|
1331
|
+
for (const statement of renderCatalog2(schema.catalog, "public")) {
|
|
1305
1332
|
if (statement.trim().length === 0)
|
|
1306
1333
|
continue;
|
|
1307
1334
|
await pool.execute(statement);
|
|
@@ -1317,7 +1344,6 @@ async function testing2(schema, options) {
|
|
|
1317
1344
|
facts,
|
|
1318
1345
|
rng: rng(seed),
|
|
1319
1346
|
cache: new Map,
|
|
1320
|
-
creating: new Set,
|
|
1321
1347
|
created: new Map,
|
|
1322
1348
|
definitions: new Map
|
|
1323
1349
|
};
|