okmodel 0.7.0 → 0.8.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/dist/adapters/capabilities.d.ts +32 -0
- package/dist/adapters/failure.d.ts +1 -1
- package/dist/adapters/pg/bun-sql.d.ts +53 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +1 -1
- package/dist/adapters/pg/bunsql.d.ts +1 -1
- package/dist/adapters/pg/neon-extra.d.ts +18 -0
- package/dist/adapters/pg/neon.d.ts +104 -0
- package/dist/adapters/pg/no-inflight-timeout.d.ts +1 -1
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/fn/index.d.ts +39 -1
- package/dist/dialects/pg/fn/index.js +118 -26
- package/dist/dialects/pg/index.d.ts +2 -0
- package/dist/dialects/pg/index.js +393 -18
- package/dist/dialects/pg/introspect.d.ts +11 -0
- package/dist/dialects/pg/operators.d.ts +1 -1
- package/dist/dialects/pg/ops/fragment.d.ts +119 -0
- package/dist/dialects/pg/ops/lane.d.ts +49 -0
- package/dist/dialects/pg/view/client.d.ts +14 -6
- package/dist/dialects/pg/view/index.d.ts +73 -1
- package/dist/dialects/pg/view/index.js +156 -5
- package/dist/dialects/pg/view/scratch.d.ts +8 -5
- package/dist/runtime/otel.d.ts +105 -0
- package/dist/runtime/otel.js +97 -0
- package/dist/runtime/pg/bun.js +4 -4
- package/dist/runtime/pg/neon.d.ts +38 -0
- package/dist/runtime/pg/neon.js +64 -0
- package/dist/runtime/pg/pg.js +4 -4
- package/dist/runtime/pg/pglite.js +4 -4
- package/dist/runtime/pg/postgresjs.js +4 -4
- package/dist/runtime/plan.d.ts +1 -1
- package/dist/runtime/sql-fragment.d.ts +43 -0
- package/dist/runtime/tenancy/index.js +10 -10
- package/dist/runtime/topology.d.ts +1 -1
- package/dist/runtime/traits/index.js +15 -16
- package/dist/runtime/types.d.ts +15 -1
- package/dist/runtime/validate/index.js +4 -4
- package/dist/shared/{mtaszv5a.js → 0wrea3jq.js} +102 -4
- package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
- package/dist/shared/{w79hsckn.js → 14x60fbf.js} +5 -5
- package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
- package/dist/shared/{svncdeh5.js → 195pzzzz.js} +8 -8
- package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
- package/dist/shared/{jvd0mqag.js → 3449rcae.js} +5 -5
- package/dist/shared/{14vx95q4.js → 35q0n9tz.js} +7 -7
- package/dist/shared/3bb7wsqt.js +99 -0
- package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
- package/dist/shared/{81ebdx9p.js → 4m6hskg8.js} +4 -4
- package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
- package/dist/shared/{bg3rym3g.js → 63f4ksbz.js} +2 -2
- package/dist/shared/{pt94kz7f.js → 6m78c8ss.js} +1 -1
- package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
- package/dist/shared/{zm0ptry0.js → 7ghwamrf.js} +1 -1
- package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
- package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
- package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
- package/dist/shared/{kb2sdhfb.js → ae4j5f42.js} +17 -1
- package/dist/shared/agsfb86s.js +233 -0
- package/dist/shared/{7k9grvf6.js → b6d6p0zc.js} +5 -5
- package/dist/shared/{tbrvgw6z.js → bah9nbg3.js} +17 -16
- package/dist/shared/{5fe3kbsh.js → bnby0esn.js} +1 -1
- package/dist/shared/bsek72fg.js +225 -0
- package/dist/shared/{1w508jbr.js → bxas03mq.js} +21 -17
- package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
- package/dist/shared/{tsvww22q.js → dpc2r7rb.js} +7 -7
- package/dist/shared/{vb6qfyve.js → e8zyaqvj.js} +2 -2
- package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
- package/dist/shared/{gs74dbj5.js → f4jy1j7x.js} +27 -14
- package/dist/shared/{ttsqgp4p.js → fjpnhqan.js} +2 -2
- package/dist/shared/{xjk7hnn5.js → g5yc06ka.js} +2 -2
- package/dist/shared/{w72kgg4q.js → hfqmpasr.js} +6 -6
- package/dist/shared/{kr0jzbw2.js → hm5f8jby.js} +7 -7
- package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
- package/dist/shared/{cn957f8d.js → jebgrkeq.js} +3 -3
- package/dist/shared/{wa07eas9.js → jp36k7dp.js} +11 -11
- package/dist/shared/jx2m62cs.js +96 -0
- package/dist/shared/{sfz1ksn6.js → k86n8vq3.js} +2 -2
- package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
- package/dist/shared/{8skf0cam.js → kj9d8maq.js} +1 -1
- package/dist/shared/{aytqh5y2.js → m4xff2a6.js} +2 -2
- package/dist/shared/{zp9fmend.js → mfedzr74.js} +4 -4
- package/dist/shared/{ax7qv55k.js → mkrn359n.js} +60 -11
- package/dist/shared/{m6p12kbr.js → mnvjvqyp.js} +10 -10
- package/dist/shared/{1qa0qajz.js → mtw6jz76.js} +1 -1
- package/dist/shared/{1est4ezg.js → n05z9nwz.js} +3 -3
- package/dist/shared/{pbp1ss85.js → n0jmpgj1.js} +2 -2
- package/dist/shared/{ktz42yez.js → n41w4fbz.js} +5 -5
- package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
- package/dist/shared/n7kg8mmx.js +61 -0
- package/dist/shared/{g6evj1j3.js → needfe47.js} +1 -1
- package/dist/shared/{2shdbn8q.js → njga14v4.js} +9 -9
- package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
- package/dist/shared/{b5pftnn2.js → p3xbdcvt.js} +14 -18
- package/dist/shared/{te5as7z7.js → p5nh3r8q.js} +3 -3
- package/dist/shared/{p6qc5gcp.js → pan0370z.js} +6 -6
- package/dist/shared/{79dt02vc.js → q0cqt2sp.js} +1 -1
- package/dist/shared/{5v3xf80k.js → qd9hhd8f.js} +1 -1
- package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
- package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
- package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
- package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
- package/dist/shared/{vczs8gd4.js → v1wad97q.js} +2 -2
- package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
- package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
- package/dist/shared/{bz84tkzm.js → wcrheftc.js} +2 -2
- package/dist/shared/{ab9gmbwy.js → wvdjznah.js} +5 -5
- package/dist/shared/{7mnme5tn.js → wz2a78mp.js} +1 -1
- package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
- package/dist/shared/{je4axnm8.js → z581d7ny.js} +2 -2
- package/dist/shared/{x933k9a3.js → zbqbmmrp.js} +10 -10
- package/dist/shared/{rs73fca9.js → zgex00fd.js} +6 -6
- package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
- package/dist/tooling/cli.js +26 -13
- package/dist/tooling/driver-run.js +4971 -0
- package/dist/tooling/driver-test.d.ts +36 -0
- package/dist/tooling/migrate/commands.d.ts +2 -2
- package/dist/tooling/migrate/index.js +9 -9
- package/dist/tooling/migrate/project.d.ts +3 -0
- package/dist/tooling/shared/03k6res6.js +210 -0
- package/dist/tooling/shared/08kemxjd.js +10 -0
- package/dist/tooling/shared/2revefqt.js +209 -0
- package/dist/tooling/shared/2wtvc7rw.js +1425 -0
- package/dist/tooling/shared/345tbc2k.js +16 -0
- package/dist/tooling/shared/3m1hkg7z.js +344 -0
- package/dist/tooling/shared/3rrw5w8f.js +81 -0
- package/dist/tooling/shared/3tq8pnb8.js +131 -0
- package/dist/tooling/shared/417zdsk7.js +194 -0
- package/dist/tooling/shared/4d2w25vw.js +40 -0
- package/dist/tooling/shared/54tqkxja.js +51 -0
- package/dist/tooling/shared/5bvw2nev.js +12 -0
- package/dist/tooling/shared/6nyfyw70.js +231 -0
- package/dist/tooling/shared/72fyg4zv.js +160 -0
- package/dist/tooling/shared/733a1tq3.js +38 -0
- package/dist/tooling/shared/7ae7rjmn.js +20 -0
- package/dist/tooling/shared/7kms6fvj.js +20 -0
- package/dist/tooling/shared/8sqrsw3s.js +49 -0
- package/dist/tooling/shared/96ps4g1z.js +32 -0
- package/dist/tooling/shared/9kazs5p6.js +195 -0
- package/dist/tooling/shared/9xzm7hjg.js +38 -0
- package/dist/tooling/shared/a6pp9d12.js +49 -0
- package/dist/tooling/shared/a7q7t4n3.js +22 -0
- package/dist/tooling/shared/aftb2mwr.js +18 -0
- package/dist/tooling/shared/bz2dqhab.js +311 -0
- package/dist/tooling/shared/cmptmb4f.js +12 -0
- package/dist/tooling/shared/ddjtfgnx.js +177 -0
- package/dist/tooling/shared/djydjpqt.js +261 -0
- package/dist/tooling/shared/dw08f3m8.js +9 -0
- package/dist/tooling/shared/dy672fz6.js +16 -0
- package/dist/tooling/shared/dzx85q70.js +66 -0
- package/dist/tooling/shared/ec71zqgt.js +270 -0
- package/dist/tooling/shared/ep8zh3bk.js +6 -0
- package/dist/tooling/shared/f9mphxej.js +3789 -0
- package/dist/tooling/shared/fb9k2qwd.js +89 -0
- package/dist/tooling/shared/g9ad4n80.js +211 -0
- package/dist/tooling/shared/gfvtj6d0.js +94 -0
- package/dist/tooling/shared/gmcf9cxf.js +294 -0
- package/dist/tooling/shared/htnaj77v.js +17 -0
- package/dist/tooling/shared/j9t5s12a.js +7 -0
- package/dist/tooling/shared/jne7b93p.js +42 -0
- package/dist/tooling/shared/ma2340rx.js +118 -0
- package/dist/tooling/shared/mtrqn2hn.js +505 -0
- package/dist/tooling/shared/n4jqhpqz.js +27 -0
- package/dist/tooling/shared/nf7jmhfa.js +20 -0
- package/dist/tooling/shared/p7f08ktn.js +332 -0
- package/dist/tooling/shared/ppnnnvj8.js +13 -0
- package/dist/tooling/shared/pqy21k24.js +312 -0
- package/dist/tooling/shared/pw8fgahx.js +69 -0
- package/dist/tooling/shared/pwsytxm5.js +17 -0
- package/dist/tooling/shared/rf83gr2d.js +94 -0
- package/dist/tooling/shared/rq5kk8j6.js +401 -0
- package/dist/tooling/shared/rs1jb051.js +12 -0
- package/dist/tooling/shared/smn6kz1p.js +157 -0
- package/dist/tooling/shared/spk1jg3r.js +1696 -0
- package/dist/tooling/shared/tn8gay14.js +143 -0
- package/dist/tooling/shared/vraj6d74.js +42 -0
- package/dist/tooling/shared/vs0t6qt8.js +64 -0
- package/dist/tooling/shared/vx86qjv8.js +150 -0
- package/dist/tooling/shared/w7qe8sj1.js +140 -0
- package/dist/tooling/shared/wt7j7nf6.js +15 -0
- package/dist/tooling/shared/wwnekq5n.js +6 -0
- package/dist/tooling/shared/xhrnjch9.js +185 -0
- package/dist/tooling/shared/xjs6zqtc.js +190 -0
- package/dist/tooling/shared/y031jct9.js +16 -0
- package/dist/tooling/shared/y5656f0e.js +233 -0
- package/dist/tooling/shared/yfr8hzhm.js +604 -0
- package/dist/tooling/shared/yk9mp7vb.js +250 -0
- package/dist/tooling/shared/yw30vnq2.js +139 -0
- package/dist/tooling/shared/z8d7ptht.js +618 -0
- package/dist/tooling/shared/zhwnfyb2.js +9 -0
- package/dist/tooling/shared/zvnhh1n0.js +198 -0
- package/dist/tooling/testing/index.js +3 -3
- package/package.json +14 -2
- package/dist/shared/y34a8714.js +0 -150
- package/dist/shared/zy8r7qvz.js +0 -116
- package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
- package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OkmError,
|
|
3
|
+
DriverError2
|
|
4
|
+
} from "./f9mphxej.js";
|
|
5
|
+
|
|
6
|
+
// src/adapters/lazy-errors.ts
|
|
7
|
+
function refused() {
|
|
8
|
+
return Promise.reject(new OkmError("OKM1120", "timeout"));
|
|
9
|
+
}
|
|
10
|
+
function closed() {
|
|
11
|
+
return Promise.reject(new DriverError2("The pool is closed.", { sqlstate: "08006" }));
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
closed,
|
|
15
|
+
refused
|
|
16
|
+
};
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DriverError2,
|
|
3
|
+
timedOut2,
|
|
4
|
+
isConnectionLost
|
|
5
|
+
} from "./f9mphxej.js";
|
|
6
|
+
import {
|
|
7
|
+
PgSession2
|
|
8
|
+
} from "./p7f08ktn.js";
|
|
9
|
+
import {
|
|
10
|
+
driverErrors,
|
|
11
|
+
rejectClosed,
|
|
12
|
+
mapFailure,
|
|
13
|
+
runCall,
|
|
14
|
+
rowsFrom,
|
|
15
|
+
resultFrom
|
|
16
|
+
} from "./xhrnjch9.js";
|
|
17
|
+
|
|
18
|
+
// src/adapters/pg/postgres-extra.ts
|
|
19
|
+
var RESET_ALL = "RESET ALL";
|
|
20
|
+
var UNLOCK = "SELECT pg_advisory_unlock_all()";
|
|
21
|
+
async function checkout(pool, timeoutMs) {
|
|
22
|
+
if (pool.isClosed())
|
|
23
|
+
return rejectClosed();
|
|
24
|
+
const reserved = await reserveConnection(pool.sql, pool.acquireMs, pool.counters, timeoutMs);
|
|
25
|
+
pool.counters.reserved += 1;
|
|
26
|
+
const local = new Set;
|
|
27
|
+
const session = new PgSession2(reserved, pool.counters, "reserved", local, pool.isClosed, pool.poolInflight, pool.notices, pool.named);
|
|
28
|
+
let released = false;
|
|
29
|
+
const lost = { on: false, stop: () => {
|
|
30
|
+
return;
|
|
31
|
+
} };
|
|
32
|
+
arm(reserved, lost);
|
|
33
|
+
let limit = timeoutMs !== undefined && timeoutMs > 0 ? timeoutMs : 0;
|
|
34
|
+
const remember = (timeout) => {
|
|
35
|
+
if (timeout !== undefined && timeout > 0)
|
|
36
|
+
limit = timeout;
|
|
37
|
+
};
|
|
38
|
+
const guard = (run) => lost.on ? rejectClosed() : run().catch((error) => {
|
|
39
|
+
if (isConnectionLost(error))
|
|
40
|
+
lost.on = true;
|
|
41
|
+
throw error;
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
execute: (text, params, options) => {
|
|
45
|
+
remember(options?.timeout);
|
|
46
|
+
return guard(() => runCall(pool.isClosed(), options, (watch) => session.query(text, params, watch)));
|
|
47
|
+
},
|
|
48
|
+
batch: (statements, options) => {
|
|
49
|
+
remember(options?.timeout);
|
|
50
|
+
return guard(() => runCall(pool.isClosed(), options, async (watch) => {
|
|
51
|
+
const { runAtomicBatch } = await import("./3rrw5w8f.js");
|
|
52
|
+
return runAtomicBatch(session, statements, watch);
|
|
53
|
+
}));
|
|
54
|
+
},
|
|
55
|
+
cancel() {
|
|
56
|
+
session.cancel();
|
|
57
|
+
},
|
|
58
|
+
async release() {
|
|
59
|
+
if (released)
|
|
60
|
+
return;
|
|
61
|
+
released = true;
|
|
62
|
+
const ms = limit;
|
|
63
|
+
try {
|
|
64
|
+
if (!lost.on)
|
|
65
|
+
await deadline(ms, () => resetConnection(reserved, session.depth()), lost);
|
|
66
|
+
} catch {
|
|
67
|
+
lost.on = true;
|
|
68
|
+
} finally {
|
|
69
|
+
pool.counters.reserved = Math.max(0, pool.counters.reserved - 1);
|
|
70
|
+
if (lost.on)
|
|
71
|
+
await deadline(ms, () => pool.sql.unsafe("select 1"), pool.sql).catch(() => {
|
|
72
|
+
return;
|
|
73
|
+
});
|
|
74
|
+
else
|
|
75
|
+
reserved.release();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async function describe(sql, text, params) {
|
|
81
|
+
const pending = sql.unsafe(text, asParams(params), { prepare: true });
|
|
82
|
+
const described = await pending.describe();
|
|
83
|
+
return {
|
|
84
|
+
columns: described.columns.map((column) => column.name),
|
|
85
|
+
parameterCount: described.types.length
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function* stream(sql, text, params) {
|
|
89
|
+
const pending = sql.unsafe(text, asParams(params));
|
|
90
|
+
for await (const chunk of pending.cursor(64)) {
|
|
91
|
+
yield rowsFrom(chunk);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function poolWaits(sql) {
|
|
95
|
+
const options = sql.options;
|
|
96
|
+
if (options === undefined || options.q !== undefined)
|
|
97
|
+
return options;
|
|
98
|
+
const q = new Set;
|
|
99
|
+
const n = new Set;
|
|
100
|
+
options.q = q;
|
|
101
|
+
options.n = n;
|
|
102
|
+
options.onclose = (id) => {
|
|
103
|
+
n.add(id);
|
|
104
|
+
if (n.size < options.max) {
|
|
105
|
+
queueMicrotask(() => {
|
|
106
|
+
for (const wait of q)
|
|
107
|
+
wait.a();
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
n.clear();
|
|
112
|
+
for (const wait of q)
|
|
113
|
+
wait.s();
|
|
114
|
+
q.clear();
|
|
115
|
+
};
|
|
116
|
+
return options;
|
|
117
|
+
}
|
|
118
|
+
function deadline(ms, run, link) {
|
|
119
|
+
let timer;
|
|
120
|
+
let off = () => {
|
|
121
|
+
return;
|
|
122
|
+
};
|
|
123
|
+
const slot = link !== undefined && "stop" in link ? link : undefined;
|
|
124
|
+
const pool = slot === undefined && link !== undefined ? poolWaits(link) : undefined;
|
|
125
|
+
let ended = false;
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
const fail = (error) => {
|
|
128
|
+
if (ended)
|
|
129
|
+
return;
|
|
130
|
+
ended = true;
|
|
131
|
+
reject(error);
|
|
132
|
+
};
|
|
133
|
+
const stop = () => {
|
|
134
|
+
fail(new DriverError2("Connection closed", { sqlstate: "08006" }));
|
|
135
|
+
};
|
|
136
|
+
if (slot !== undefined)
|
|
137
|
+
slot.stop = stop;
|
|
138
|
+
const go = () => {
|
|
139
|
+
const pending = run();
|
|
140
|
+
if (ms > 0 && timer === undefined) {
|
|
141
|
+
timer = setTimeout(() => {
|
|
142
|
+
pending.cancel?.();
|
|
143
|
+
fail(timedOut2());
|
|
144
|
+
}, ms);
|
|
145
|
+
}
|
|
146
|
+
pending.then((value) => {
|
|
147
|
+
if (ended) {
|
|
148
|
+
value.release?.();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
ended = true;
|
|
152
|
+
pool?.n?.clear();
|
|
153
|
+
resolve(value);
|
|
154
|
+
}, fail);
|
|
155
|
+
};
|
|
156
|
+
if (ms === 0 && pool?.q !== undefined) {
|
|
157
|
+
let used = false;
|
|
158
|
+
const wait = {
|
|
159
|
+
s: stop,
|
|
160
|
+
a() {
|
|
161
|
+
if (used || ended)
|
|
162
|
+
return;
|
|
163
|
+
used = true;
|
|
164
|
+
go();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
pool.q.add(wait);
|
|
168
|
+
off = () => pool.q?.delete(wait);
|
|
169
|
+
}
|
|
170
|
+
go();
|
|
171
|
+
}).finally(() => {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
if (slot !== undefined)
|
|
174
|
+
slot.stop = () => {
|
|
175
|
+
return;
|
|
176
|
+
};
|
|
177
|
+
off();
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async function runBatch(pool, statements, options) {
|
|
181
|
+
const connection = await checkout(pool, options?.timeout);
|
|
182
|
+
try {
|
|
183
|
+
return await connection.batch(statements, options);
|
|
184
|
+
} finally {
|
|
185
|
+
await connection.release();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function reserveConnection(sql, acquireMs, counters, callMs) {
|
|
189
|
+
counters.waiting += 1;
|
|
190
|
+
let settled = false;
|
|
191
|
+
const finish = () => {
|
|
192
|
+
counters.waiting = Math.max(0, counters.waiting - 1);
|
|
193
|
+
};
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
let timer;
|
|
196
|
+
if (acquireMs !== undefined) {
|
|
197
|
+
timer = setTimeout(() => {
|
|
198
|
+
if (settled)
|
|
199
|
+
return;
|
|
200
|
+
settled = true;
|
|
201
|
+
finish();
|
|
202
|
+
driverErrors().then((errors) => {
|
|
203
|
+
reject(errors.acquireTimeout());
|
|
204
|
+
});
|
|
205
|
+
}, acquireMs);
|
|
206
|
+
}
|
|
207
|
+
const ms = callMs !== undefined && callMs > 0 ? callMs : 0;
|
|
208
|
+
deadline(ms, () => sql.reserve(), sql).then((connection) => {
|
|
209
|
+
if (settled) {
|
|
210
|
+
resetConnection(connection, 0).catch(() => {
|
|
211
|
+
return;
|
|
212
|
+
}).finally(() => {
|
|
213
|
+
connection.release();
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
settled = true;
|
|
218
|
+
if (timer !== undefined)
|
|
219
|
+
clearTimeout(timer);
|
|
220
|
+
finish();
|
|
221
|
+
resolve(connection);
|
|
222
|
+
}, (error) => {
|
|
223
|
+
if (settled)
|
|
224
|
+
return;
|
|
225
|
+
settled = true;
|
|
226
|
+
if (timer !== undefined)
|
|
227
|
+
clearTimeout(timer);
|
|
228
|
+
finish();
|
|
229
|
+
mapFailure(error).then(reject);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async function resetConnection(sql, depth) {
|
|
234
|
+
if (depth > 0)
|
|
235
|
+
await sql.unsafe("ROLLBACK").catch(() => {
|
|
236
|
+
return;
|
|
237
|
+
});
|
|
238
|
+
try {
|
|
239
|
+
await sql.unsafe(RESET_ALL);
|
|
240
|
+
await sql.unsafe(UNLOCK);
|
|
241
|
+
} catch {
|
|
242
|
+
await sql.unsafe("ROLLBACK").catch(() => {
|
|
243
|
+
return;
|
|
244
|
+
});
|
|
245
|
+
await sql.unsafe(RESET_ALL);
|
|
246
|
+
await sql.unsafe(UNLOCK);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function asParams(params) {
|
|
250
|
+
if (params === undefined)
|
|
251
|
+
return [];
|
|
252
|
+
return params;
|
|
253
|
+
}
|
|
254
|
+
function arm(sql, lost) {
|
|
255
|
+
const unsafe = sql.unsafe.bind(sql);
|
|
256
|
+
sql.unsafe = (text, params, options) => unsafe(text, params, {
|
|
257
|
+
...options,
|
|
258
|
+
onexecute(connection) {
|
|
259
|
+
connection.onclose = () => {
|
|
260
|
+
lost.on = true;
|
|
261
|
+
lost.stop();
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
async function holdCheckout(gate, checkout) {
|
|
267
|
+
try {
|
|
268
|
+
const connection = await checkout();
|
|
269
|
+
let released = false;
|
|
270
|
+
const release = connection.release.bind(connection);
|
|
271
|
+
connection.release = () => {
|
|
272
|
+
if (released)
|
|
273
|
+
return Promise.resolve();
|
|
274
|
+
released = true;
|
|
275
|
+
return release().finally(() => {
|
|
276
|
+
gate.leave();
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
return connection;
|
|
280
|
+
} catch (error) {
|
|
281
|
+
gate.leave();
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
async function holdListener(gate, start) {
|
|
286
|
+
try {
|
|
287
|
+
const stop = await start();
|
|
288
|
+
let stopped = false;
|
|
289
|
+
return async () => {
|
|
290
|
+
if (stopped)
|
|
291
|
+
return;
|
|
292
|
+
stopped = true;
|
|
293
|
+
try {
|
|
294
|
+
await stop();
|
|
295
|
+
} finally {
|
|
296
|
+
gate.leave();
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
} catch (error) {
|
|
300
|
+
gate.leave();
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function watchQuery(pending, watch, onAbort, ctx) {
|
|
305
|
+
return pending.then((value) => {
|
|
306
|
+
finishWatch(pending, watch, onAbort, ctx);
|
|
307
|
+
const why = watch.reason();
|
|
308
|
+
if (why === "timeout" || why === "cancelled")
|
|
309
|
+
return classify(why, watch);
|
|
310
|
+
ctx.note(ctx.text);
|
|
311
|
+
return resultFrom(value, ctx.notices.since(ctx.start));
|
|
312
|
+
}, (error) => {
|
|
313
|
+
finishWatch(pending, watch, onAbort, ctx);
|
|
314
|
+
return classify(error, watch);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function finishWatch(pending, watch, onAbort, ctx) {
|
|
318
|
+
ctx.leave();
|
|
319
|
+
ctx.untrack(pending);
|
|
320
|
+
watch.signal.removeEventListener("abort", onAbort);
|
|
321
|
+
}
|
|
322
|
+
async function classify(error, watch) {
|
|
323
|
+
const errors = await driverErrors();
|
|
324
|
+
if (error instanceof errors.DriverError)
|
|
325
|
+
return Promise.reject(error);
|
|
326
|
+
const why = typeof error === "string" ? error : watch.reason();
|
|
327
|
+
if (why === "timeout") {
|
|
328
|
+
return Promise.reject(errors.timedOut(typeof error === "string" ? undefined : error));
|
|
329
|
+
}
|
|
330
|
+
const code = errors.errorField(error, "code");
|
|
331
|
+
if (why === "cancelled" || code === "57014") {
|
|
332
|
+
return Promise.reject(errors.cancelled(typeof error === "string" ? undefined : error));
|
|
333
|
+
}
|
|
334
|
+
return Promise.reject(errors.mapDriverError(error));
|
|
335
|
+
}
|
|
336
|
+
export {
|
|
337
|
+
checkout,
|
|
338
|
+
describe,
|
|
339
|
+
holdCheckout,
|
|
340
|
+
holdListener,
|
|
341
|
+
runBatch,
|
|
342
|
+
stream,
|
|
343
|
+
watchQuery
|
|
344
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DriverError2,
|
|
3
|
+
outcomeUnknown2,
|
|
4
|
+
mapDriverError2,
|
|
5
|
+
isConnectionLost
|
|
6
|
+
} from "./f9mphxej.js";
|
|
7
|
+
|
|
8
|
+
// src/adapters/pg/batch.ts
|
|
9
|
+
var savepointIds = 0;
|
|
10
|
+
async function runAtomicBatch(session, statements, watch) {
|
|
11
|
+
if (session.inTransaction())
|
|
12
|
+
return savepoint(session, statements, watch);
|
|
13
|
+
return transaction(session, statements, watch);
|
|
14
|
+
}
|
|
15
|
+
async function transaction(session, statements, watch) {
|
|
16
|
+
try {
|
|
17
|
+
await control(session, "BEGIN", watch);
|
|
18
|
+
const results = await statementsOf(session, statements, watch);
|
|
19
|
+
try {
|
|
20
|
+
await control(session, "COMMIT", watch);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (isConnectionLost(error))
|
|
23
|
+
throw outcomeUnknown2(error);
|
|
24
|
+
throw stamp(error, null);
|
|
25
|
+
}
|
|
26
|
+
return results;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (!isConnectionLost(error))
|
|
29
|
+
await rollback(session);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function savepoint(session, statements, watch) {
|
|
34
|
+
savepointIds += 1;
|
|
35
|
+
const name = `okm_b${String(savepointIds)}`;
|
|
36
|
+
try {
|
|
37
|
+
await control(session, `SAVEPOINT ${name}`, watch);
|
|
38
|
+
const results = await statementsOf(session, statements, watch);
|
|
39
|
+
await control(session, `RELEASE SAVEPOINT ${name}`, watch);
|
|
40
|
+
return results;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (!isConnectionLost(error))
|
|
43
|
+
await rollback(session, `ROLLBACK TO SAVEPOINT ${name}`);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function control(session, text, watch) {
|
|
48
|
+
return session.query(text, undefined, watch).then(() => {
|
|
49
|
+
return;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async function rollback(session, text = "ROLLBACK") {
|
|
53
|
+
try {
|
|
54
|
+
await session.query(text, undefined, undefined);
|
|
55
|
+
} catch {
|
|
56
|
+
session.abandon();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function statementsOf(session, statements, watch) {
|
|
60
|
+
const results = Array.from({ length: statements.length });
|
|
61
|
+
for (let index = 0;index < statements.length; index += 1) {
|
|
62
|
+
const statement = statements[index];
|
|
63
|
+
if (statement === undefined)
|
|
64
|
+
continue;
|
|
65
|
+
try {
|
|
66
|
+
results[index] = await session.query(statement.text, statement.params, watch);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
throw stamp(error, index);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return results;
|
|
72
|
+
}
|
|
73
|
+
function stamp(error, batchIndex) {
|
|
74
|
+
const mapped = mapDriverError2(error, batchIndex);
|
|
75
|
+
if (mapped instanceof DriverError2)
|
|
76
|
+
return mapped;
|
|
77
|
+
return error;
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
runAtomicBatch
|
|
81
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OkmError,
|
|
3
|
+
writeArray
|
|
4
|
+
} from "./f9mphxej.js";
|
|
5
|
+
|
|
6
|
+
// src/dialects/pg/operator-fit.ts
|
|
7
|
+
var FAMILIES = {
|
|
8
|
+
startsWith: ["text"],
|
|
9
|
+
endsWith: ["text"],
|
|
10
|
+
like: ["text"],
|
|
11
|
+
ilike: ["text"],
|
|
12
|
+
contains: ["text", "array", "jsonb", "range"],
|
|
13
|
+
containedBy: ["array", "jsonb", "range"],
|
|
14
|
+
overlaps: ["array", "range"],
|
|
15
|
+
hasKey: ["jsonb"],
|
|
16
|
+
hasAnyKey: ["jsonb"],
|
|
17
|
+
path: ["json", "jsonb"],
|
|
18
|
+
matches: ["tsvector"],
|
|
19
|
+
relevance: ["tsvector"],
|
|
20
|
+
"json.set": ["json", "jsonb"],
|
|
21
|
+
"arr.append": ["array"],
|
|
22
|
+
"arr.remove": ["array"]
|
|
23
|
+
};
|
|
24
|
+
var ACCEPTED = {
|
|
25
|
+
text: [
|
|
26
|
+
"eq",
|
|
27
|
+
"not",
|
|
28
|
+
"lt",
|
|
29
|
+
"lte",
|
|
30
|
+
"gt",
|
|
31
|
+
"gte",
|
|
32
|
+
"between",
|
|
33
|
+
"startsWith",
|
|
34
|
+
"contains",
|
|
35
|
+
"endsWith",
|
|
36
|
+
"like",
|
|
37
|
+
"ilike",
|
|
38
|
+
"inList",
|
|
39
|
+
"notIn"
|
|
40
|
+
],
|
|
41
|
+
array: [
|
|
42
|
+
"eq",
|
|
43
|
+
"not",
|
|
44
|
+
"contains",
|
|
45
|
+
"containedBy",
|
|
46
|
+
"overlaps",
|
|
47
|
+
"inList",
|
|
48
|
+
"notIn",
|
|
49
|
+
"arr.append",
|
|
50
|
+
"arr.remove"
|
|
51
|
+
],
|
|
52
|
+
jsonb: ["eq", "not", "contains", "containedBy", "hasKey", "hasAnyKey", "path", "json.set"],
|
|
53
|
+
json: ["eq", "not", "path", "json.set"],
|
|
54
|
+
range: ["eq", "not", "lt", "lte", "gt", "gte", "contains", "containedBy", "overlaps"],
|
|
55
|
+
tsvector: ["eq", "not", "matches", "relevance"],
|
|
56
|
+
scalar: ["eq", "not", "lt", "lte", "gt", "gte", "between", "inList", "notIn", "inc"]
|
|
57
|
+
};
|
|
58
|
+
var SAFE_TYPE = /^[A-Za-z_][A-Za-z0-9_]*(\(\d+\))?(\[\])*$/;
|
|
59
|
+
var REGCONFIG = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)?$/;
|
|
60
|
+
function columnFamily(dataType) {
|
|
61
|
+
if (dataType.endsWith("[]"))
|
|
62
|
+
return "array";
|
|
63
|
+
if (dataType === "jsonb")
|
|
64
|
+
return "jsonb";
|
|
65
|
+
if (dataType === "json")
|
|
66
|
+
return "json";
|
|
67
|
+
if (dataType === "tsvector")
|
|
68
|
+
return "tsvector";
|
|
69
|
+
if (dataType.endsWith("range"))
|
|
70
|
+
return "range";
|
|
71
|
+
if (dataType === "text" || dataType === "citext" || dataType.startsWith("varchar(") || dataType.startsWith("char(") || dataType.startsWith("character")) {
|
|
72
|
+
return "text";
|
|
73
|
+
}
|
|
74
|
+
return "scalar";
|
|
75
|
+
}
|
|
76
|
+
function assertOperatorFits(column, name) {
|
|
77
|
+
const families = FAMILIES[name];
|
|
78
|
+
if (families === undefined)
|
|
79
|
+
return;
|
|
80
|
+
if (families.includes(columnFamily(column.dataType)))
|
|
81
|
+
return;
|
|
82
|
+
const accepted = ACCEPTED[columnFamily(column.dataType)];
|
|
83
|
+
const search = (name === "matches" || name === "relevance") && columnFamily(column.dataType) === "text" ? " Search needs a column built for search, not a plain text column." : "";
|
|
84
|
+
throw new OkmError("OKM1124", `Operator ${name} does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${accepted.join(", ")}.${search}`, { fix: { summary: `Use one of: ${accepted.join(", ")}.` } });
|
|
85
|
+
}
|
|
86
|
+
function sqlType(dataType, column) {
|
|
87
|
+
if (SAFE_TYPE.test(dataType))
|
|
88
|
+
return dataType;
|
|
89
|
+
assertOperatorFits(column, "contains");
|
|
90
|
+
throw new OkmError("OKM1124", `Operator contains does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${ACCEPTED[columnFamily(column.dataType)].join(", ")}.`, { fix: { summary: "Use a column type this operator accepts." } });
|
|
91
|
+
}
|
|
92
|
+
function assertNoControl(value, role) {
|
|
93
|
+
for (let index = 0;index < value.length; index += 1) {
|
|
94
|
+
const code = value.charCodeAt(index);
|
|
95
|
+
if (code <= 31 || code === 127) {
|
|
96
|
+
throw new OkmError("OKM1122", `${role} contains a control character.`, {
|
|
97
|
+
fix: { summary: "Remove NUL and other control characters. The value is not sent." }
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function assertBoundText(value, role) {
|
|
103
|
+
if (value.length === 0) {
|
|
104
|
+
throw new OkmError("OKM1122", `${role} is empty.`, {
|
|
105
|
+
fix: { summary: "Pass a non-empty key or path segment." }
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
assertNoControl(value, role);
|
|
109
|
+
}
|
|
110
|
+
function assertRegconfig(config) {
|
|
111
|
+
if (!REGCONFIG.test(config)) {
|
|
112
|
+
throw new OkmError("OKM1122", `Language ${config} is not a text search language. Pass a name such as english.`, { fix: { summary: "Pass a language name such as english." } });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function textArray(values, role) {
|
|
116
|
+
for (const value of values)
|
|
117
|
+
assertBoundText(value, role);
|
|
118
|
+
return writeArray(values, 1, (value) => String(value), false);
|
|
119
|
+
}
|
|
120
|
+
function arrayElementType(dataType, column) {
|
|
121
|
+
if (!dataType.endsWith("[]")) {
|
|
122
|
+
assertOperatorFits(column, "arr.append");
|
|
123
|
+
}
|
|
124
|
+
const element = dataType.slice(0, -2);
|
|
125
|
+
if (!SAFE_TYPE.test(element)) {
|
|
126
|
+
throw new OkmError("OKM1124", `Operator arr.append does not apply to ${column.dataType} column ${column.field}. Accepted operators: ${ACCEPTED.array.join(", ")}.`, { fix: { summary: "Use arr.append on an array column." } });
|
|
127
|
+
}
|
|
128
|
+
return element;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { assertOperatorFits, sqlType, assertNoControl, assertBoundText, assertRegconfig, textArray, arrayElementType };
|