okmodel 0.5.0 → 0.6.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 +36 -18
- package/dist/adapters/pg/no-inflight-timeout.d.ts +17 -0
- package/dist/adapters/pg/postgres-extra.d.ts +22 -0
- package/dist/contracts/catalog/document.d.ts +19 -5
- package/dist/contracts/catalog/object.d.ts +2 -1
- package/dist/contracts/catalog/policy.d.ts +48 -0
- package/dist/contracts/catalog/types.d.ts +25 -1
- package/dist/contracts/catalog/view.d.ts +2 -0
- package/dist/contracts/internal.js +1 -1
- package/dist/contracts/location.d.ts +10 -0
- package/dist/dialects/pg/column.d.ts +13 -2
- package/dist/dialects/pg/ddl.d.ts +37 -1
- package/dist/dialects/pg/emit.d.ts +19 -1
- package/dist/dialects/pg/errors.d.ts +32 -1
- 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/filter-parse.d.ts +10 -3
- package/dist/dialects/pg/fn/index.js +10 -2
- package/dist/dialects/pg/index.d.ts +2 -1
- package/dist/dialects/pg/index.js +29 -17
- package/dist/dialects/pg/introspect.d.ts +7 -0
- package/dist/dialects/pg/model.d.ts +7 -2
- package/dist/dialects/pg/ops/or.d.ts +1 -1
- package/dist/dialects/pg/owner.d.ts +42 -0
- package/dist/dialects/pg/path-endpoint.d.ts +20 -0
- package/dist/dialects/pg/role/check.d.ts +3 -0
- package/dist/dialects/pg/role/index.d.ts +71 -6
- package/dist/dialects/pg/role/sql.d.ts +11 -0
- package/dist/dialects/pg/schema.d.ts +2 -0
- package/dist/dialects/pg/table.d.ts +25 -3
- package/dist/dialects/pg/temporal.d.ts +5 -76
- package/dist/dialects/pg/tenancy.d.ts +45 -3
- package/dist/dialects/pg/view/client.d.ts +19 -1
- package/dist/dialects/pg/view/index.d.ts +4 -0
- package/dist/dialects/pg/view/index.js +21 -178
- package/dist/dialects/pg/view/refresh.d.ts +24 -0
- package/dist/runtime/batch.d.ts +1 -1
- package/dist/runtime/client.d.ts +6 -1
- package/dist/runtime/conflict.d.ts +2 -1
- package/dist/runtime/drift.d.ts +9 -0
- package/dist/runtime/inflight.d.ts +14 -0
- package/dist/runtime/pg/bun.js +6 -5
- package/dist/runtime/pg/pg.js +5 -5
- package/dist/runtime/pg/pglite.js +6 -5
- package/dist/runtime/pg/postgresjs.js +5 -5
- package/dist/runtime/plan.d.ts +22 -1
- package/dist/runtime/predicate.d.ts +19 -0
- package/dist/runtime/safety/index.js +1 -1
- package/dist/runtime/tenancy/composite.d.ts +26 -0
- package/dist/runtime/tenancy/context.d.ts +16 -0
- package/dist/runtime/tenancy/index.d.ts +9 -5
- package/dist/runtime/tenancy/index.js +1508 -37
- package/dist/runtime/tenancy/path.d.ts +87 -0
- package/dist/runtime/tenancy/rls.d.ts +67 -0
- package/dist/runtime/tenancy/via.d.ts +22 -0
- package/dist/runtime/traits/index.js +17 -11
- package/dist/runtime/types.d.ts +13 -1
- package/dist/runtime/validate/index.js +4 -4
- package/dist/runtime/write.d.ts +1 -1
- package/dist/shared/09p049xa.js +702 -0
- package/dist/shared/{ykv7wh5b.js → 1f0xa3cb.js} +5 -5
- package/dist/shared/1nw1f3vs.js +23 -0
- package/dist/shared/{6p5k20sm.js → 1z04fa85.js} +21 -11
- package/dist/shared/{p7pfx624.js → 2cg3wnxc.js} +314 -65
- package/dist/shared/{dyj86cmj.js → 2jd1sn0e.js} +2 -2
- package/dist/shared/{qgvt8nx1.js → 2z7wv5tj.js} +21 -5
- package/dist/shared/{kyxb62mc.js → 31vm914h.js} +9 -1
- package/dist/shared/{sf8m6tfy.js → 32cnm7kn.js} +8 -3
- package/dist/shared/{t4tbsy9h.js → 358zsv4r.js} +1 -1
- package/dist/shared/{jdgqqx31.js → 3fqwmr09.js} +38 -14
- package/dist/shared/{922qbgnw.js → 3qnhc7w5.js} +16 -9
- package/dist/shared/{zvbjc949.js → 4az561fn.js} +1 -1
- package/dist/shared/{k3ted12y.js → 54tqkxja.js} +20 -2
- package/dist/shared/{k7cc9nzk.js → 5d8t84hg.js} +15 -3
- package/dist/shared/{fa9vt245.js → 5j36z8dn.js} +17 -6
- package/dist/shared/{1g0drakv.js → 5yv4k6a6.js} +1 -1
- package/dist/shared/8dqhth8c.js +12 -0
- package/dist/shared/8etn7d8w.js +62 -0
- package/dist/shared/{g516zdsb.js → 8x72s86k.js} +476 -30
- package/dist/shared/{nkc9sfqb.js → 929h19xp.js} +145 -7
- package/dist/shared/{gjthds9j.js → 9628a9xt.js} +1 -1
- package/dist/shared/{8xsbagad.js → 9s0ypp87.js} +88 -7
- package/dist/shared/{b066g80h.js → ag4c7516.js} +2 -2
- package/dist/shared/b3awxn7h.js +45 -0
- package/dist/shared/b4v57v3x.js +9 -0
- package/dist/shared/bdk4sty6.js +58 -0
- package/dist/shared/{s6gqfn5j.js → c58secgj.js} +125 -8
- package/dist/shared/{rrstp3kb.js → cgbamx3e.js} +2 -2
- package/dist/shared/d5azex6s.js +6 -0
- package/dist/shared/{5fqx9yh4.js → dk8v79p3.js} +3 -1
- package/dist/shared/{4m9fn52z.js → ed0b8k4s.js} +1 -1
- package/dist/shared/{z2rnngj4.js → ek2wt2dz.js} +8 -5
- package/dist/shared/{wxn4b7pp.js → f0f1n281.js} +59 -12
- package/dist/shared/{gdh9mrtp.js → g90m9b0g.js} +3 -2
- package/dist/shared/{tbszx8mz.js → gwn6v667.js} +2 -2
- package/dist/shared/{c8aghh05.js → h15jx9bc.js} +8 -2
- package/dist/shared/{3p4b1fg0.js → hazqqecq.js} +17 -93
- package/dist/shared/{4ef7mmqf.js → j3rkk835.js} +34 -11
- package/dist/shared/{bt9sfq0z.js → j60w0dvr.js} +56 -21
- package/dist/shared/{ycatkxmq.js → jgqj11w4.js} +1 -1
- package/dist/shared/k68eedmy.js +85 -0
- package/dist/shared/{szm0cksa.js → knmes2kh.js} +34 -6
- package/dist/shared/{ckjbyrt9.js → mb2ycs1p.js} +7 -9
- package/dist/shared/{tq9afp8d.js → n076ydsc.js} +1 -1
- package/dist/shared/{xhh1srw3.js → nx9hh281.js} +50 -32
- package/dist/shared/{kdkxh3kb.js → p248q79y.js} +58 -59
- package/dist/shared/{990a291j.js → p6bjzq9q.js} +14 -9
- package/dist/shared/{h4nqvjkp.js → pjr6xrm5.js} +2 -2
- package/dist/shared/pz6rj8ay.js +212 -0
- package/dist/shared/{5vdm4sgp.js → q3j1tq7a.js} +36 -23
- package/dist/shared/{8bwbwy8h.js → qq3899ht.js} +128 -18
- package/dist/shared/{dxjp14rk.js → r11n8grd.js} +2 -2
- package/dist/shared/r1fdd0f6.js +19 -0
- package/dist/shared/{8ktwd3rh.js → r3j8s5y0.js} +1 -1
- package/dist/shared/rhs3xe4k.js +7 -0
- package/dist/shared/{jsd07prz.js → rpycarcr.js} +6 -6
- package/dist/shared/{xsq7v6wp.js → sbdme3vy.js} +14 -2
- package/dist/shared/{xdpj5kkm.js → t3g0k88x.js} +775 -264
- package/dist/shared/{ayz64vzj.js → ttmg09vd.js} +708 -19
- package/dist/shared/{r6pj4fq2.js → venqrjna.js} +8 -4
- package/dist/shared/{fancm5pt.js → vjpnzwjz.js} +138 -15
- package/dist/shared/{9tgmr1gh.js → vmfkhszw.js} +44 -9
- package/dist/shared/{wqem4jed.js → wkme6tep.js} +11 -9
- package/dist/shared/{qy9rdq0g.js → wt5rzv1h.js} +15 -11
- package/dist/shared/wxr8cwns.js +6 -0
- package/dist/shared/{bzsjtd7c.js → wynzeggs.js} +19 -14
- package/dist/shared/x3jc53kg.js +220 -0
- package/dist/shared/{7p2wbz7f.js → x72jb7ad.js} +1 -1
- package/dist/shared/{fyqkk1m0.js → xq0mvhts.js} +10 -9
- package/dist/shared/xqve9598.js +53 -0
- package/dist/shared/{47xzb9fc.js → y2t3jktd.js} +2 -2
- package/dist/shared/{9x25fxhc.js → y34a8714.js} +1 -1
- package/dist/shared/{k7dwkhvq.js → y6jdds7g.js} +4 -1
- package/dist/shared/{h8ne16fq.js → ys0xzyaj.js} +1 -1
- package/dist/shared/{c9z5g0fm.js → ywr8hmey.js} +5 -2
- package/dist/shared/{g7ez901n.js → ywspezzx.js} +1 -1
- package/dist/shared/{9m80mkac.js → ze4hxsmy.js} +1 -1
- package/dist/shared/{fb00y8fp.js → zm0mafk4.js} +12 -6
- package/dist/shared/{y005b761.js → zy8r7qvz.js} +6 -2
- package/dist/tooling/cli.js +97 -24
- package/dist/tooling/migrate/apply.d.ts +14 -0
- package/dist/tooling/migrate/check.d.ts +3 -4
- package/dist/tooling/migrate/classify.d.ts +4 -0
- package/dist/tooling/migrate/commands.d.ts +1 -2
- package/dist/tooling/migrate/config.d.ts +3 -2
- package/dist/tooling/migrate/drift.d.ts +1 -1
- package/dist/tooling/migrate/estimate.d.ts +14 -1
- package/dist/tooling/migrate/files.d.ts +11 -1
- package/dist/tooling/migrate/index.js +17 -16
- package/dist/tooling/migrate/lint.d.ts +4 -4
- package/dist/tooling/migrate/lost.d.ts +28 -0
- package/dist/tooling/migrate/paths.d.ts +14 -0
- package/dist/tooling/migrate/plan.d.ts +10 -3
- package/dist/tooling/migrate/policy.d.ts +11 -0
- package/dist/tooling/migrate/runner.d.ts +25 -0
- package/dist/tooling/migrate/sandbox.d.ts +57 -0
- package/dist/tooling/migrate/sql-lex.d.ts +39 -0
- package/dist/tooling/migrate/text.d.ts +42 -0
- package/dist/tooling/node-version.d.ts +21 -0
- package/dist/tooling/testing/factories.d.ts +10 -0
- package/dist/tooling/testing/facts.d.ts +33 -5
- package/dist/tooling/testing/index.d.ts +1 -1
- package/dist/tooling/testing/index.js +3 -3
- package/dist/tooling/testing/isolation.d.ts +15 -8
- package/package.json +10 -6
- package/dist/shared/0v1g424p.js +0 -26
- package/dist/shared/r73pt594.js +0 -426
- package/dist/shared/rasvvzgz.js +0 -21
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
noTimeout2
|
|
3
|
+
} from "./8dqhth8c.js";
|
|
1
4
|
import {
|
|
2
5
|
noticeBuffer,
|
|
3
6
|
WireSession,
|
|
4
7
|
cursorStream
|
|
5
|
-
} from "./
|
|
8
|
+
} from "./4az561fn.js";
|
|
6
9
|
import {
|
|
7
10
|
BUNSQL_CAPABILITIES,
|
|
8
11
|
driverErrors,
|
|
9
12
|
rejectClosed,
|
|
10
13
|
mapFailure,
|
|
11
14
|
runCall
|
|
12
|
-
} from "./
|
|
15
|
+
} from "./cgbamx3e.js";
|
|
13
16
|
|
|
14
17
|
// src/adapters/pg/bunsql.ts
|
|
15
18
|
import { SQL } from "bun";
|
|
@@ -41,16 +44,18 @@ function open5(config) {
|
|
|
41
44
|
counters.busy = Math.max(0, counters.busy - 1);
|
|
42
45
|
});
|
|
43
46
|
const held = { sql, parked, acquireMs, counters, notices, isClosed };
|
|
44
|
-
const checkout = () => closed ? rejectClosed() : import("./
|
|
47
|
+
const checkout = () => closed ? rejectClosed() : import("./j3rkk835.js").then((mod) => mod.checkout(held));
|
|
45
48
|
return {
|
|
46
49
|
capabilities: BUNSQL_CAPABILITIES,
|
|
47
50
|
execute(text, params, options) {
|
|
51
|
+
noTimeout2(options);
|
|
48
52
|
return runCall(closed, options, async (watch) => {
|
|
49
53
|
await releaseParked(parked);
|
|
50
54
|
return root.query(text, params, watch);
|
|
51
55
|
});
|
|
52
56
|
},
|
|
53
57
|
async batch(statements, options) {
|
|
58
|
+
noTimeout2(options);
|
|
54
59
|
const connection = await checkout();
|
|
55
60
|
try {
|
|
56
61
|
return await connection.batch(statements, options);
|
|
@@ -503,7 +503,7 @@ function constraint2(input) {
|
|
|
503
503
|
const name = input.name === undefined ? deterministicName2({
|
|
504
504
|
parent: input.parent.name,
|
|
505
505
|
purpose: input.constraintKind,
|
|
506
|
-
nameKey
|
|
506
|
+
nameKey: input.constraintKind === "check" ? nameKey : defaultNameKey(input.constraintKind, columns)
|
|
507
507
|
}) : fitIdentifier2(input.name);
|
|
508
508
|
const identity = {
|
|
509
509
|
kind: "constraint",
|
|
@@ -1,44 +1,62 @@
|
|
|
1
1
|
import {
|
|
2
2
|
open2
|
|
3
|
-
} from "./
|
|
4
|
-
import"./
|
|
3
|
+
} from "./wkme6tep.js";
|
|
4
|
+
import"./qq3899ht.js";
|
|
5
5
|
import {
|
|
6
6
|
createdOf,
|
|
7
7
|
testing2
|
|
8
|
-
} from "./
|
|
8
|
+
} from "./8x72s86k.js";
|
|
9
9
|
import"./n442h54c.js";
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
assertDirectConnection,
|
|
13
|
-
selectTarget,
|
|
11
|
+
projectPath,
|
|
14
12
|
loadConfig,
|
|
15
13
|
loadSchema
|
|
16
|
-
} from "./
|
|
17
|
-
import
|
|
18
|
-
|
|
14
|
+
} from "./t3g0k88x.js";
|
|
15
|
+
import {
|
|
16
|
+
sessionFailure,
|
|
17
|
+
finishQuiet,
|
|
18
|
+
assertTargetPolicy,
|
|
19
|
+
assertDirectConnection,
|
|
20
|
+
assertStableBackend,
|
|
21
|
+
selectTarget
|
|
22
|
+
} from "./ttmg09vd.js";
|
|
23
|
+
import"./9s0ypp87.js";
|
|
19
24
|
import {
|
|
20
25
|
OkmError2
|
|
21
26
|
} from "./52szzakm.js";
|
|
22
27
|
|
|
23
28
|
// src/tooling/migrate/seed.ts
|
|
24
29
|
import { existsSync } from "node:fs";
|
|
25
|
-
import { join } from "node:path";
|
|
26
30
|
import { pathToFileURL } from "node:url";
|
|
27
31
|
async function seedProject(cwd, file, flags) {
|
|
28
32
|
const config = await loadConfig(cwd);
|
|
29
33
|
const target = selectTarget(config, flags.target);
|
|
30
34
|
assertTargetPolicy(target, "seed", flags.allowProtected);
|
|
31
|
-
const path =
|
|
35
|
+
const path = projectPath(cwd, file);
|
|
32
36
|
if (!existsSync(path)) {
|
|
33
37
|
throw new OkmError2("invalid", `Seed file ${file} was not found.`, {
|
|
34
38
|
fix: { summary: "Pass okm seed <file> a module in this project." }
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
|
-
|
|
41
|
+
const allowPooler = flags.allowPooler || config.allowPooler === true;
|
|
42
|
+
assertDirectConnection(target.url, allowPooler);
|
|
38
43
|
const schema = await loadSchema(cwd, config.schema);
|
|
39
44
|
const pool = open2({ url: target.url, max: 1 });
|
|
40
|
-
|
|
45
|
+
let harness;
|
|
41
46
|
try {
|
|
47
|
+
const held = await pool.reserve?.();
|
|
48
|
+
if (held !== undefined) {
|
|
49
|
+
try {
|
|
50
|
+
await assertStableBackend(async () => {
|
|
51
|
+
const result = await held.execute("select pg_backend_pid()::text");
|
|
52
|
+
const cell = result.rows[0]?.[0];
|
|
53
|
+
return cell === null || cell === undefined ? "" : String(cell);
|
|
54
|
+
}, allowPooler);
|
|
55
|
+
} finally {
|
|
56
|
+
await finishQuiet(() => held.release());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
harness = await testing2(schema, { driver: pool, migrate: false });
|
|
42
60
|
const imported = await import(`${pathToFileURL(path).href}?okm=${Date.now()}`);
|
|
43
61
|
const seed = isRecord(imported) ? imported.default : undefined;
|
|
44
62
|
if (typeof seed !== "function") {
|
|
@@ -48,8 +66,14 @@ async function seedProject(cwd, file, flags) {
|
|
|
48
66
|
}
|
|
49
67
|
await seed(harness);
|
|
50
68
|
return formatCreated(target.name, createdOf(harness));
|
|
69
|
+
} catch (error) {
|
|
70
|
+
throw sessionFailure(error) ?? error;
|
|
51
71
|
} finally {
|
|
52
|
-
|
|
72
|
+
const opened = harness;
|
|
73
|
+
if (opened !== undefined)
|
|
74
|
+
await finishQuiet(() => opened.close());
|
|
75
|
+
else
|
|
76
|
+
await finishQuiet(() => pool.close());
|
|
53
77
|
}
|
|
54
78
|
}
|
|
55
79
|
function formatCreated(target, counts) {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mapPostgresError2
|
|
3
|
+
} from "./c58secgj.js";
|
|
1
4
|
import {
|
|
2
5
|
withHttp
|
|
3
|
-
} from "./
|
|
6
|
+
} from "./j60w0dvr.js";
|
|
4
7
|
import {
|
|
5
8
|
decodeResult
|
|
6
|
-
} from "./
|
|
9
|
+
} from "./2z7wv5tj.js";
|
|
7
10
|
import {
|
|
8
11
|
OkmError2
|
|
9
12
|
} from "./52szzakm.js";
|
|
@@ -17,13 +20,17 @@ async function* streamRows(session, call, prepare, log) {
|
|
|
17
20
|
})));
|
|
18
21
|
}
|
|
19
22
|
const { plan, params } = await prepare();
|
|
20
|
-
const decode = plan.outputs.includes.length === 0 ? decodeResult : (await import("./
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const decode = plan.outputs.includes.length === 0 ? decodeResult : (await import("./ys0xzyaj.js")).decodeIncluded;
|
|
24
|
+
try {
|
|
25
|
+
for await (const chunk of session.pool.stream(plan.text, params)) {
|
|
26
|
+
const decoded = decode(plan, chunk, call.table);
|
|
27
|
+
if (!Array.isArray(decoded))
|
|
28
|
+
continue;
|
|
29
|
+
for (const row of decoded)
|
|
30
|
+
yield row;
|
|
31
|
+
}
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw log(session.http === undefined ? mapPostgresError2(error) : mapPostgresError2(error, { http: session.http }));
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
export {
|
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
// src/adapters/pg/watch.ts
|
|
2
|
+
var callers = new WeakMap;
|
|
3
|
+
function listenOn(signal, onAbort) {
|
|
4
|
+
let set = callers.get(signal);
|
|
5
|
+
if (set === undefined) {
|
|
6
|
+
const created = new Set;
|
|
7
|
+
callers.set(signal, created);
|
|
8
|
+
signal.addEventListener("abort", () => {
|
|
9
|
+
for (const each of created)
|
|
10
|
+
each();
|
|
11
|
+
}, { once: true });
|
|
12
|
+
set = created;
|
|
13
|
+
}
|
|
14
|
+
const registered = set;
|
|
15
|
+
registered.add(onAbort);
|
|
16
|
+
return () => {
|
|
17
|
+
registered.delete(onAbort);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
2
20
|
function openWatch(options) {
|
|
3
21
|
let kind;
|
|
4
22
|
const controller = new AbortController;
|
|
@@ -7,7 +25,7 @@ function openWatch(options) {
|
|
|
7
25
|
kind = "cancelled";
|
|
8
26
|
controller.abort();
|
|
9
27
|
};
|
|
10
|
-
options.signal
|
|
28
|
+
const release = options.signal === undefined ? undefined : listenOn(options.signal, onAbort);
|
|
11
29
|
let timer;
|
|
12
30
|
if (options.timeout !== undefined) {
|
|
13
31
|
timer = setTimeout(() => {
|
|
@@ -21,7 +39,7 @@ function openWatch(options) {
|
|
|
21
39
|
finish() {
|
|
22
40
|
if (timer !== undefined)
|
|
23
41
|
clearTimeout(timer);
|
|
24
|
-
|
|
42
|
+
release?.();
|
|
25
43
|
},
|
|
26
44
|
reason() {
|
|
27
45
|
return kind;
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
refuseUncancellableTimeout
|
|
3
|
+
} from "./b4v57v3x.js";
|
|
1
4
|
import {
|
|
2
5
|
isConnectionLost
|
|
3
|
-
} from "./
|
|
6
|
+
} from "./gwn6v667.js";
|
|
4
7
|
import {
|
|
5
8
|
openClient,
|
|
6
9
|
withHttp,
|
|
7
10
|
settleCall
|
|
8
|
-
} from "./
|
|
11
|
+
} from "./j60w0dvr.js";
|
|
9
12
|
import {
|
|
10
13
|
rejectKeys,
|
|
11
14
|
isRecord,
|
|
12
15
|
fail
|
|
13
|
-
} from "./
|
|
16
|
+
} from "./2z7wv5tj.js";
|
|
14
17
|
import {
|
|
15
18
|
OkmError2
|
|
16
19
|
} from "./52szzakm.js";
|
|
@@ -92,6 +95,9 @@ class Frame {
|
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
async function tx(session, args) {
|
|
98
|
+
if (typeof args[0] === "function" && args.length > 1) {
|
|
99
|
+
fail("OKM1120", "options go first: tx(options, fn).");
|
|
100
|
+
}
|
|
95
101
|
const fn = typeof args[0] === "function" ? args[0] : args[1];
|
|
96
102
|
const given = typeof args[0] === "function" ? {} : args[0] ?? {};
|
|
97
103
|
try {
|
|
@@ -102,6 +108,7 @@ async function tx(session, args) {
|
|
|
102
108
|
rejectKeys(given, ["isolation", "retry", "signal", "timeout"], "tx");
|
|
103
109
|
const options = given;
|
|
104
110
|
check(options);
|
|
111
|
+
await refuseUncancellableTimeout(session.pool, options.timeout);
|
|
105
112
|
const call = fn;
|
|
106
113
|
return session.tx === undefined ? await outer(session, call, options) : await nested(session, call, options);
|
|
107
114
|
} catch (error) {
|
|
@@ -272,6 +279,10 @@ async function nested(session, fn, options) {
|
|
|
272
279
|
const saved = frame.failed;
|
|
273
280
|
const after = [];
|
|
274
281
|
let released = false;
|
|
282
|
+
const hooks = session.pool;
|
|
283
|
+
const pending = hooks.okmScopePending?.();
|
|
284
|
+
if (pending !== undefined)
|
|
285
|
+
await pending;
|
|
275
286
|
try {
|
|
276
287
|
await step(session, frame, `SAVEPOINT ${name}`);
|
|
277
288
|
hear?.phase(session.hookm, "start", depth + 1);
|
|
@@ -290,6 +301,7 @@ async function nested(session, fn, options) {
|
|
|
290
301
|
await frame.conn.execute(`ROLLBACK TO SAVEPOINT ${name}`).catch(() => {
|
|
291
302
|
return;
|
|
292
303
|
});
|
|
304
|
+
hooks.okmForgetScope?.();
|
|
293
305
|
frame.failed = saved;
|
|
294
306
|
hear?.phase(session.hookm, "rollback", depth + 1);
|
|
295
307
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
noTimeout2
|
|
3
|
+
} from "./8dqhth8c.js";
|
|
1
4
|
import {
|
|
2
5
|
PGLITE_CAPABILITIES,
|
|
3
6
|
driverErrors,
|
|
@@ -9,7 +12,7 @@ import {
|
|
|
9
12
|
runCall,
|
|
10
13
|
EMPTY_NOTICES,
|
|
11
14
|
resultFrom
|
|
12
|
-
} from "./
|
|
15
|
+
} from "./cgbamx3e.js";
|
|
13
16
|
|
|
14
17
|
// src/adapters/pg/pglite.ts
|
|
15
18
|
import { PGlite } from "@electric-sql/pglite";
|
|
@@ -46,11 +49,17 @@ async function open3(config = {}) {
|
|
|
46
49
|
await slot.acquire(acquireMs);
|
|
47
50
|
let released = false;
|
|
48
51
|
return {
|
|
49
|
-
execute: (text, params, options) =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
execute: (text, params, options) => {
|
|
53
|
+
noTimeout2(options);
|
|
54
|
+
return runCall(closed, options, (watch) => session.query(text, params, watch));
|
|
55
|
+
},
|
|
56
|
+
batch: (statements, options) => {
|
|
57
|
+
noTimeout2(options);
|
|
58
|
+
return runCall(closed, options, async (watch) => {
|
|
59
|
+
const { runAtomicBatch } = await import("./ag4c7516.js");
|
|
60
|
+
return runAtomicBatch(session, statements, watch);
|
|
61
|
+
});
|
|
62
|
+
},
|
|
54
63
|
async release() {
|
|
55
64
|
if (released)
|
|
56
65
|
return;
|
|
@@ -66,6 +75,7 @@ async function open3(config = {}) {
|
|
|
66
75
|
return {
|
|
67
76
|
capabilities: PGLITE_CAPABILITIES,
|
|
68
77
|
execute(text, params, options) {
|
|
78
|
+
noTimeout2(options);
|
|
69
79
|
return runCall(closed, options, async (watch) => {
|
|
70
80
|
await slot.acquire(acquireMs);
|
|
71
81
|
try {
|
|
@@ -76,6 +86,7 @@ async function open3(config = {}) {
|
|
|
76
86
|
});
|
|
77
87
|
},
|
|
78
88
|
async batch(statements, options) {
|
|
89
|
+
noTimeout2(options);
|
|
79
90
|
const connection = await lease();
|
|
80
91
|
try {
|
|
81
92
|
return await connection.batch(statements, options);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OkmError2
|
|
3
|
+
} from "./52szzakm.js";
|
|
4
|
+
|
|
5
|
+
// src/dialects/pg/view/refresh.ts
|
|
6
|
+
async function refreshView(session, name, concurrently) {
|
|
7
|
+
const host = asHost(session);
|
|
8
|
+
await host.connected;
|
|
9
|
+
const timeout = host.timeouts?.statement;
|
|
10
|
+
const options = timeout === undefined ? undefined : { timeout };
|
|
11
|
+
const text = `refresh materialized view${concurrently ? " concurrently" : ""} ${quote(name)}`;
|
|
12
|
+
const connection = await host.pool.reserve?.();
|
|
13
|
+
if (connection === undefined) {
|
|
14
|
+
throw new OkmError2("OKM1111", "Refresh needs a driver that can reserve a connection.", {
|
|
15
|
+
fix: { summary: "Use a Postgres driver that supports interactive transactions." }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
if (concurrently) {
|
|
20
|
+
await connection.execute("select set_config('app.unscoped', 'on', false)");
|
|
21
|
+
try {
|
|
22
|
+
await connection.execute(text, undefined, options);
|
|
23
|
+
} finally {
|
|
24
|
+
await connection.execute("select set_config('app.unscoped', '', false)").catch(() => {
|
|
25
|
+
return;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
await connection.execute("begin");
|
|
31
|
+
try {
|
|
32
|
+
await connection.execute("select set_config('app.unscoped', 'on', true)");
|
|
33
|
+
await connection.execute(text, undefined, options);
|
|
34
|
+
await connection.execute("commit");
|
|
35
|
+
} catch (error) {
|
|
36
|
+
await connection.execute("rollback").catch(() => {
|
|
37
|
+
return;
|
|
38
|
+
});
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
const { mapPostgresError } = await import("./d5azex6s.js");
|
|
43
|
+
const mapped = mapPostgresError(error, {
|
|
44
|
+
...host.http !== undefined ? { http: host.http } : {},
|
|
45
|
+
...host.includeValues === true ? { includeValues: true } : {},
|
|
46
|
+
...host.schema !== undefined ? { schema: host.schema } : {}
|
|
47
|
+
});
|
|
48
|
+
host.logger?.error?.({ code: mapped.code, summary: mapped.summary });
|
|
49
|
+
throw mapped;
|
|
50
|
+
} finally {
|
|
51
|
+
await connection.release();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function asHost(session) {
|
|
55
|
+
return session;
|
|
56
|
+
}
|
|
57
|
+
function quote(name) {
|
|
58
|
+
return `"${name.replaceAll('"', '""')}"`;
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
refreshView
|
|
62
|
+
};
|