okmodel 0.6.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/README.md +100 -1131
- package/dist/adapters/capabilities.d.ts +35 -0
- package/dist/adapters/failure.d.ts +13 -2
- package/dist/adapters/lazy-errors.d.ts +22 -0
- package/dist/adapters/pg/bun-sql.d.ts +53 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
- package/dist/adapters/pg/bunsql.d.ts +15 -2
- package/dist/adapters/pg/cursor.d.ts +17 -0
- 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 +11 -8
- package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
- package/dist/adapters/pg/nodepostgres.d.ts +12 -0
- package/dist/adapters/pg/pglite-wire.d.ts +24 -0
- package/dist/adapters/pg/pglite.d.ts +10 -0
- package/dist/adapters/pg/postgres-extra.d.ts +27 -11
- package/dist/adapters/pg/reserved.d.ts +42 -0
- package/dist/adapters/pg/session.d.ts +0 -18
- package/dist/contracts/connection.d.ts +7 -6
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/floor.d.ts +68 -0
- 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 +8 -1
- package/dist/dialects/pg/index.js +435 -170
- package/dist/dialects/pg/introspect.d.ts +11 -0
- package/dist/dialects/pg/keys.d.ts +11 -8
- package/dist/dialects/pg/model.d.ts +40 -0
- package/dist/dialects/pg/morph.d.ts +43 -0
- package/dist/dialects/pg/operator-fit.d.ts +2 -2
- package/dist/dialects/pg/operators.d.ts +14 -7
- package/dist/dialects/pg/ops/bucket.d.ts +65 -0
- package/dist/dialects/pg/ops/fragment.d.ts +119 -0
- package/dist/dialects/pg/ops/inc.d.ts +2 -2
- package/dist/dialects/pg/ops/lane.d.ts +49 -0
- package/dist/dialects/pg/ops/matches.d.ts +9 -12
- package/dist/dialects/pg/ops/relevance.d.ts +13 -0
- package/dist/dialects/pg/ops/search-query.d.ts +22 -0
- package/dist/dialects/pg/ops/window.d.ts +103 -0
- package/dist/dialects/pg/preset.d.ts +1 -1
- package/dist/dialects/pg/relations.d.ts +100 -3
- package/dist/dialects/pg/schema.d.ts +31 -3
- 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/aggregate.d.ts +8 -2
- package/dist/runtime/bucket-group.d.ts +70 -0
- package/dist/runtime/conflict.d.ts +22 -4
- package/dist/runtime/include.d.ts +0 -8
- package/dist/runtime/inflight.d.ts +1 -1
- package/dist/runtime/otel.d.ts +105 -0
- package/dist/runtime/otel.js +97 -0
- package/dist/runtime/page.d.ts +4 -1
- package/dist/runtime/pg/bun.js +12 -6
- package/dist/runtime/pg/neon.d.ts +38 -0
- package/dist/runtime/pg/neon.js +64 -0
- package/dist/runtime/pg/pg.js +5 -5
- package/dist/runtime/pg/pglite.d.ts +1 -0
- package/dist/runtime/pg/pglite.js +9 -9
- package/dist/runtime/pg/postgresjs.js +5 -5
- package/dist/runtime/plan.d.ts +95 -5
- package/dist/runtime/read-stream.d.ts +13 -16
- package/dist/runtime/result-name.d.ts +17 -0
- package/dist/runtime/server-check.d.ts +3 -3
- package/dist/runtime/sort-bind.d.ts +21 -0
- package/dist/runtime/sort.d.ts +56 -0
- package/dist/runtime/sql-fragment.d.ts +43 -0
- package/dist/runtime/sync.d.ts +70 -0
- package/dist/runtime/tenancy/index.js +15 -13
- package/dist/runtime/text-search.d.ts +20 -0
- package/dist/runtime/topology.d.ts +1 -1
- package/dist/runtime/traits/index.d.ts +80 -0
- package/dist/runtime/traits/index.js +184 -21
- package/dist/runtime/tree.d.ts +38 -0
- package/dist/runtime/types.d.ts +232 -22
- package/dist/runtime/validate/index.js +4 -4
- package/dist/runtime/version.d.ts +39 -0
- package/dist/runtime/window.d.ts +21 -0
- package/dist/runtime/write.d.ts +54 -2
- package/dist/shared/{929h19xp.js → 0wrea3jq.js} +141 -13
- package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
- package/dist/shared/{1z04fa85.js → 14x60fbf.js} +12 -57
- package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
- package/dist/shared/{wynzeggs.js → 195pzzzz.js} +8 -8
- package/dist/shared/1d9q9cv2.js +312 -0
- package/dist/shared/2c13q96h.js +18 -0
- package/dist/shared/{b4v57v3x.js → 2d3xq4ps.js} +2 -2
- package/dist/shared/{1f0xa3cb.js → 3449rcae.js} +5 -5
- package/dist/shared/{wkme6tep.js → 35q0n9tz.js} +8 -16
- package/dist/shared/3bb7wsqt.js +99 -0
- package/dist/shared/3t6kw83m.js +249 -0
- package/dist/shared/{5j36z8dn.js → 4m6hskg8.js} +39 -70
- package/dist/shared/{n076ydsc.js → 4vbf83xx.js} +69 -28
- package/dist/shared/{vmfkhszw.js → 63f4ksbz.js} +33 -26
- package/dist/shared/{c58secgj.js → 63qtkrca.js} +38 -4
- package/dist/shared/6m78c8ss.js +6 -0
- package/dist/shared/{x3jc53kg.js → 760ppr76.js} +15 -7
- package/dist/shared/7ghwamrf.js +40 -0
- package/dist/shared/7kms6fvj.js +20 -0
- package/dist/shared/7n7ddwt4.js +6 -0
- package/dist/shared/9a4ae4p8.js +31 -0
- package/dist/shared/{hazqqecq.js → 9dr2qnx7.js} +63 -34
- package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
- package/dist/shared/a62rb2da.js +13 -0
- package/dist/shared/{cgbamx3e.js → ae4j5f42.js} +23 -4
- package/dist/shared/agsfb86s.js +233 -0
- package/dist/shared/{8x72s86k.js → b6d6p0zc.js} +13 -7
- package/dist/shared/{ag4c7516.js → b76b8d95.js} +2 -2
- package/dist/shared/{j60w0dvr.js → bah9nbg3.js} +58 -38
- package/dist/shared/bnby0esn.js +10 -0
- package/dist/shared/bsek72fg.js +225 -0
- package/dist/shared/{2cg3wnxc.js → bxas03mq.js} +608 -141
- package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
- package/dist/shared/{gwn6v667.js → cnkky55j.js} +25 -14
- package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
- package/dist/shared/{ttmg09vd.js → dpc2r7rb.js} +8 -8
- package/dist/shared/dzj09cye.js +10 -0
- package/dist/shared/{sbdme3vy.js → e8zyaqvj.js} +60 -10
- package/dist/shared/{2jd1sn0e.js → ecn8mfdq.js} +6 -6
- package/dist/shared/exn3sd90.js +359 -0
- package/dist/shared/{t3g0k88x.js → f4jy1j7x.js} +39 -22
- package/dist/shared/{y2t3jktd.js → fjpnhqan.js} +20 -13
- package/dist/shared/g5yc06ka.js +272 -0
- package/dist/shared/ga9j92qj.js +25 -0
- package/dist/shared/{3fqwmr09.js → hfqmpasr.js} +6 -6
- package/dist/shared/{wt5rzv1h.js → hm5f8jby.js} +7 -7
- package/dist/shared/{ys0xzyaj.js → hqpxf4a4.js} +224 -19
- package/dist/shared/jebgrkeq.js +179 -0
- package/dist/shared/{09p049xa.js → jp36k7dp.js} +44 -16
- package/dist/shared/jx2m62cs.js +96 -0
- package/dist/shared/{r11n8grd.js → k86n8vq3.js} +7 -4
- package/dist/shared/{2z7wv5tj.js → kgwp4jdd.js} +56 -35
- package/dist/shared/{knmes2kh.js → kj9d8maq.js} +1 -1
- package/dist/shared/{g90m9b0g.js → m4xff2a6.js} +6 -5
- package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
- package/dist/shared/mfedzr74.js +145 -0
- package/dist/shared/{f0f1n281.js → mkrn359n.js} +60 -11
- package/dist/shared/{p248q79y.js → mnvjvqyp.js} +10 -10
- package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
- package/dist/shared/{4az561fn.js → mtw6jz76.js} +8 -23
- package/dist/shared/n05z9nwz.js +313 -0
- package/dist/shared/{pjr6xrm5.js → n0jmpgj1.js} +20 -17
- package/dist/shared/{p6bjzq9q.js → n41w4fbz.js} +14 -6
- package/dist/shared/{b3awxn7h.js → n454kcnw.js} +1 -1
- package/dist/shared/n7kg8mmx.js +61 -0
- package/dist/shared/nbw1z4yd.js +18 -0
- package/dist/shared/needfe47.js +66 -0
- package/dist/shared/{1nw1f3vs.js → njga14v4.js} +9 -9
- package/dist/shared/{5yv4k6a6.js → nmnsgj7x.js} +145 -3
- package/dist/shared/{vjpnzwjz.js → p3xbdcvt.js} +14 -18
- package/dist/shared/p5nh3r8q.js +622 -0
- package/dist/shared/{nx9hh281.js → pan0370z.js} +13 -12
- package/dist/shared/q0cqt2sp.js +12 -0
- package/dist/shared/qd9hhd8f.js +37 -0
- package/dist/shared/{mb2ycs1p.js → qfw14tna.js} +15 -15
- package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
- package/dist/shared/th3be82n.js +208 -0
- package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
- package/dist/shared/{5d8t84hg.js → v1wad97q.js} +14 -14
- package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
- package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
- package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
- package/dist/shared/{q3j1tq7a.js → wcrheftc.js} +148 -23
- package/dist/shared/wvdjznah.js +213 -0
- package/dist/shared/wz2a78mp.js +8 -0
- package/dist/shared/xfhe73sb.js +436 -0
- package/dist/shared/{r1fdd0f6.js → z581d7ny.js} +5 -2
- package/dist/shared/{8etn7d8w.js → z7s6fpxv.js} +1 -1
- package/dist/shared/{32cnm7kn.js → zbqbmmrp.js} +76 -40
- package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
- package/dist/shared/{xq0mvhts.js → zgex00fd.js} +6 -6
- package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
- package/dist/shared/zq1he88x.js +155 -0
- 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/engine.d.ts +3 -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/{shared/d5azex6s.js → tooling/shared/ep8zh3bk.js} +1 -1
- 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 +17 -3
- package/dist/shared/3qnhc7w5.js +0 -38
- package/dist/shared/7m88x3e9.js +0 -45
- package/dist/shared/8dqhth8c.js +0 -12
- package/dist/shared/j3rkk835.js +0 -99
- package/dist/shared/k68eedmy.js +0 -85
- package/dist/shared/venqrjna.js +0 -216
- package/dist/shared/wxr8cwns.js +0 -6
- package/dist/shared/y34a8714.js +0 -150
- package/dist/shared/zm0mafk4.js +0 -92
- 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,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DriverError2
|
|
3
|
+
} from "./cm3w0ywp.js";
|
|
4
|
+
import {
|
|
5
|
+
connectClient2,
|
|
6
|
+
send3
|
|
7
|
+
} from "./agsfb86s.js";
|
|
8
|
+
import {
|
|
9
|
+
resetSession2
|
|
10
|
+
} from "./7ghwamrf.js";
|
|
11
|
+
import {
|
|
12
|
+
isConnectionLost
|
|
13
|
+
} from "./cnkky55j.js";
|
|
14
|
+
import {
|
|
15
|
+
noTimeout
|
|
16
|
+
} from "./q0cqt2sp.js";
|
|
17
|
+
import {
|
|
18
|
+
WireSession
|
|
19
|
+
} from "./mtw6jz76.js";
|
|
20
|
+
import {
|
|
21
|
+
rejectClosed,
|
|
22
|
+
runCall
|
|
23
|
+
} from "./ae4j5f42.js";
|
|
24
|
+
|
|
25
|
+
// src/adapters/pg/neon-extra.ts
|
|
26
|
+
async function checkout(held) {
|
|
27
|
+
const { pool, counters, named, isClosed } = held;
|
|
28
|
+
if (isClosed())
|
|
29
|
+
return rejectClosed();
|
|
30
|
+
const client = await connectClient2(pool, held.acquireMs, counters);
|
|
31
|
+
counters.reserved += 1;
|
|
32
|
+
let lost = false;
|
|
33
|
+
const onError = () => {
|
|
34
|
+
lost = true;
|
|
35
|
+
};
|
|
36
|
+
const events = client;
|
|
37
|
+
events.on("error", onError);
|
|
38
|
+
const local = new Set;
|
|
39
|
+
const session = new WireSession((text, params) => {
|
|
40
|
+
const pending = send3(client, text, params, named);
|
|
41
|
+
const guarded = pending.catch((error) => {
|
|
42
|
+
if (isConnectionLost(error) || lost) {
|
|
43
|
+
lost = true;
|
|
44
|
+
if (isConnectionLost(error))
|
|
45
|
+
throw error;
|
|
46
|
+
throw Object.assign(new DriverError2("CONNECTION_CLOSED", { cause: error }), {
|
|
47
|
+
code: "CONNECTION_CLOSED"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
throw error;
|
|
51
|
+
});
|
|
52
|
+
return guarded;
|
|
53
|
+
}, held.notices, isClosed, false, () => {
|
|
54
|
+
counters.reservedBusy += 1;
|
|
55
|
+
}, () => {
|
|
56
|
+
counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
|
|
57
|
+
}, local);
|
|
58
|
+
const guard = (run) => lost ? rejectClosed() : run();
|
|
59
|
+
let released = false;
|
|
60
|
+
return {
|
|
61
|
+
execute: (text, params, options) => {
|
|
62
|
+
const refused = noTimeout(options);
|
|
63
|
+
if (refused !== undefined)
|
|
64
|
+
return refused;
|
|
65
|
+
return guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch)));
|
|
66
|
+
},
|
|
67
|
+
batch: (statements, options) => {
|
|
68
|
+
const refused = noTimeout(options);
|
|
69
|
+
if (refused !== undefined)
|
|
70
|
+
return refused;
|
|
71
|
+
return guard(() => runCall(isClosed(), options, async (watch) => {
|
|
72
|
+
const { runAtomicBatch } = await import("./b76b8d95.js");
|
|
73
|
+
return runAtomicBatch(session, statements, watch);
|
|
74
|
+
}));
|
|
75
|
+
},
|
|
76
|
+
async release() {
|
|
77
|
+
if (released)
|
|
78
|
+
return;
|
|
79
|
+
released = true;
|
|
80
|
+
try {
|
|
81
|
+
if (!lost)
|
|
82
|
+
await reset(session, client);
|
|
83
|
+
} finally {
|
|
84
|
+
counters.reserved = Math.max(0, counters.reserved - 1);
|
|
85
|
+
events.removeListener("error", onError);
|
|
86
|
+
client.release(lost);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async function reset(session, client) {
|
|
92
|
+
await resetSession2(session.depth(), (text) => client.query(text));
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
checkout
|
|
96
|
+
};
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
readHandle,
|
|
4
4
|
readCall,
|
|
5
5
|
attachHttp
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./bah9nbg3.js";
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
} from "./
|
|
8
|
+
fail2
|
|
9
|
+
} from "./kgwp4jdd.js";
|
|
10
10
|
import {
|
|
11
11
|
OkmError2,
|
|
12
12
|
throwNamed2
|
|
@@ -35,13 +35,16 @@ function plan(session, table, options, mods, view) {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
+
if (lock === "skip") {
|
|
39
|
+
fail2("OKM1120", 'lock: "skip" claims rows on update. A read uses lock: "update" and wait: "skip".', 'Pass lock: "update" and wait: "skip" inside tx(). An update can claim rows on its own.');
|
|
40
|
+
}
|
|
38
41
|
if (session.tx === undefined) {
|
|
39
42
|
throw new OkmError2("OKM1830", "A row lock needs a transaction. find was called outside tx().", {
|
|
40
43
|
fix: { summary: "Move the find into tx(): the lock lasts until the transaction ends." }
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
if (lock === undefined)
|
|
44
|
-
|
|
47
|
+
fail2("OKM1121", "wait needs lock: pass lock: update or lock: share.");
|
|
45
48
|
if (typeof lock !== "string" || !LOCKS.includes(lock)) {
|
|
46
49
|
throwNamed2("OKM1120", shown(lock), LOCKS, `lock must be one of: ${LOCKS.join(", ")}.`);
|
|
47
50
|
}
|
|
@@ -41,6 +41,7 @@ var FIND_OPTIONS = [
|
|
|
41
41
|
"include",
|
|
42
42
|
"limit",
|
|
43
43
|
"orderBy",
|
|
44
|
+
"search",
|
|
44
45
|
"select",
|
|
45
46
|
"route",
|
|
46
47
|
"signal",
|
|
@@ -56,12 +57,15 @@ var ONE_OPTIONS = [
|
|
|
56
57
|
"timeout",
|
|
57
58
|
"where"
|
|
58
59
|
];
|
|
60
|
+
var COUNT_OPTIONS = ["route", "search", "signal", "timeout", "where"];
|
|
59
61
|
var FILTER_OPTIONS = ["route", "signal", "timeout", "where"];
|
|
60
62
|
function readOptionNames(op) {
|
|
61
63
|
if (op === "find")
|
|
62
64
|
return FIND_OPTIONS;
|
|
63
65
|
if (op === "one")
|
|
64
66
|
return ONE_OPTIONS;
|
|
67
|
+
if (op === "count")
|
|
68
|
+
return COUNT_OPTIONS;
|
|
65
69
|
return FILTER_OPTIONS;
|
|
66
70
|
}
|
|
67
71
|
var BASE_RULES = [
|
|
@@ -78,7 +82,19 @@ function readNeedsOperatorSql(schema, call) {
|
|
|
78
82
|
if (operatorEmit !== undefined)
|
|
79
83
|
return false;
|
|
80
84
|
const table = indexes(schema).get(call.table);
|
|
81
|
-
|
|
85
|
+
if (table === undefined)
|
|
86
|
+
return false;
|
|
87
|
+
return needsOperatorSql(table, call.where) || orderHasRelevance(call.orderBy);
|
|
88
|
+
}
|
|
89
|
+
function orderHasRelevance(orderBy) {
|
|
90
|
+
if (!isRecord(orderBy))
|
|
91
|
+
return false;
|
|
92
|
+
for (const key of Object.keys(orderBy)) {
|
|
93
|
+
const value = orderBy[key];
|
|
94
|
+
if (isOperator(value) && operatorName(value) === "relevance")
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
82
98
|
}
|
|
83
99
|
function emitRelationFrom(schema, relation, child, sink, parent, alias, depth) {
|
|
84
100
|
if (relation.through !== undefined) {
|
|
@@ -122,12 +138,12 @@ function needsOperatorSql(table, value, key) {
|
|
|
122
138
|
function isTextColumn(dataType) {
|
|
123
139
|
return dataType === "text" || dataType === "citext" || dataType.startsWith("varchar(") || dataType.startsWith("char(") || dataType.startsWith("character");
|
|
124
140
|
}
|
|
125
|
-
function emitLazy(column, ref, name, value, sink) {
|
|
141
|
+
function emitLazy(table, column, ref, name, value, sink, order) {
|
|
126
142
|
const emit = operatorEmit;
|
|
127
143
|
if (emit === undefined) {
|
|
128
|
-
|
|
144
|
+
fail2("OKM1121", `Operator ${name} on ${column.field} is not loaded.`);
|
|
129
145
|
}
|
|
130
|
-
emit(column, ref, name, value, sink);
|
|
146
|
+
emit(table, column, ref, name, value, sink, order);
|
|
131
147
|
}
|
|
132
148
|
function verifyRead(schema, call) {
|
|
133
149
|
if (!safetyInstalled())
|
|
@@ -208,7 +224,7 @@ function logicalIntent(call) {
|
|
|
208
224
|
table: call.table,
|
|
209
225
|
where: plain(call.where),
|
|
210
226
|
select: call.select,
|
|
211
|
-
orderBy: call.orderBy,
|
|
227
|
+
orderBy: plain(call.orderBy),
|
|
212
228
|
limit: call.limit,
|
|
213
229
|
include: plain(call.include),
|
|
214
230
|
all: call.all
|
|
@@ -261,7 +277,7 @@ function emitRead(schema, call, sink, outputs, hooks) {
|
|
|
261
277
|
throwNamed2("OKM1120", call.table, [...indexes(schema).keys()], `Table ${call.table} is not in the schema. Accepted names: ${list([...indexes(schema).keys()])}.`);
|
|
262
278
|
}
|
|
263
279
|
if (call.build !== undefined) {
|
|
264
|
-
call.build(schema, table, sink, outputs, call);
|
|
280
|
+
call.build(schema, table, sink, outputs, call, hooks);
|
|
265
281
|
return;
|
|
266
282
|
}
|
|
267
283
|
rejectOptions(call);
|
|
@@ -296,7 +312,7 @@ function emitRead(schema, call, sink, outputs, hooks) {
|
|
|
296
312
|
column += 1;
|
|
297
313
|
}
|
|
298
314
|
if (call.include !== undefined && hooks === undefined) {
|
|
299
|
-
|
|
315
|
+
fail2("OKM1120", "An include needs the include planner.");
|
|
300
316
|
}
|
|
301
317
|
const includes = hooks === undefined || call.include === undefined ? [] : hooks.read(schema, table, call.include, call.all);
|
|
302
318
|
if (selected.length === 0 && includes.length === 0)
|
|
@@ -375,7 +391,7 @@ function emitWhere(schema, table, where, sink, alias, depth, appended = false, e
|
|
|
375
391
|
continue;
|
|
376
392
|
const joined = isOperator(part);
|
|
377
393
|
if (!joined && !isRecord(part))
|
|
378
|
-
|
|
394
|
+
fail2("OKM1121", WHERE_FIELDS);
|
|
379
395
|
if (!joined && Object.keys(part).length === 0)
|
|
380
396
|
continue;
|
|
381
397
|
sink.text(started ? " and " : " where ");
|
|
@@ -389,7 +405,7 @@ function emitWhere(schema, table, where, sink, alias, depth, appended = false, e
|
|
|
389
405
|
var WHERE_FIELDS = "where must be an object of fields. Wrap an object value with eq.";
|
|
390
406
|
function emitAnd(schema, table, where, sink, alias, depth) {
|
|
391
407
|
if (!isRecord(where)) {
|
|
392
|
-
|
|
408
|
+
fail2("OKM1121", WHERE_FIELDS);
|
|
393
409
|
}
|
|
394
410
|
const keys = Object.keys(where);
|
|
395
411
|
let wrote = false;
|
|
@@ -446,7 +462,7 @@ function emitOperator(schema, table, column, ref, name, value, sink, alias, dept
|
|
|
446
462
|
return;
|
|
447
463
|
}
|
|
448
464
|
if (column === undefined) {
|
|
449
|
-
|
|
465
|
+
fail2("OKM1121", "That operator needs a field.");
|
|
450
466
|
}
|
|
451
467
|
if (name === "not") {
|
|
452
468
|
emitNot(schema, table, column, ref, value, sink, alias, depth);
|
|
@@ -464,7 +480,7 @@ function emitOperator(schema, table, column, ref, name, value, sink, alias, dept
|
|
|
464
480
|
}
|
|
465
481
|
if (name === "between") {
|
|
466
482
|
if (!Array.isArray(value) || value.length !== 2) {
|
|
467
|
-
|
|
483
|
+
fail2("OKM1121", `between on ${column.field} needs two values.`);
|
|
468
484
|
}
|
|
469
485
|
sink.text(ref);
|
|
470
486
|
sink.text(" between ");
|
|
@@ -479,7 +495,7 @@ function emitOperator(schema, table, column, ref, name, value, sink, alias, dept
|
|
|
479
495
|
}
|
|
480
496
|
if (TEXT_OPERATORS.includes(`,${name},`) && isTextColumn(column.dataType)) {
|
|
481
497
|
if (typeof value !== "string") {
|
|
482
|
-
|
|
498
|
+
fail2("OKM1121", `${name} on ${column.field} needs a string.`);
|
|
483
499
|
}
|
|
484
500
|
sink.text(ref);
|
|
485
501
|
if (name === "like" || name === "ilike") {
|
|
@@ -489,13 +505,13 @@ function emitOperator(schema, table, column, ref, name, value, sink, alias, dept
|
|
|
489
505
|
}
|
|
490
506
|
sink.text(" like ");
|
|
491
507
|
if (name !== "startsWith" && name !== "endsWith" && name !== "contains") {
|
|
492
|
-
|
|
508
|
+
fail2("OKM1121", `${name} on ${column.field} needs a string.`);
|
|
493
509
|
}
|
|
494
510
|
sink.param(literalPattern(value, name));
|
|
495
511
|
sink.text(" escape E'\\\\'");
|
|
496
512
|
return;
|
|
497
513
|
}
|
|
498
|
-
emitLazy(column, ref, name, value, sink);
|
|
514
|
+
emitLazy(table, column, ref, name, value, sink);
|
|
499
515
|
}
|
|
500
516
|
function emitNot(schema, table, column, ref, value, sink, alias, depth) {
|
|
501
517
|
if (value === null) {
|
|
@@ -517,7 +533,7 @@ function emitNot(schema, table, column, ref, value, sink, alias, depth) {
|
|
|
517
533
|
}
|
|
518
534
|
function emitIn(column, ref, name, value, sink) {
|
|
519
535
|
if (!Array.isArray(value)) {
|
|
520
|
-
|
|
536
|
+
fail2("OKM1121", `${name} on ${column.field} needs a list.`);
|
|
521
537
|
}
|
|
522
538
|
sink.mark(`:${String(value.length)}`);
|
|
523
539
|
if (value.length === 0) {
|
|
@@ -549,7 +565,7 @@ function emitOr(schema, table, value, sink, alias, depth) {
|
|
|
549
565
|
sink.text(" or ");
|
|
550
566
|
sink.text("(");
|
|
551
567
|
if (!isRecord(branch)) {
|
|
552
|
-
|
|
568
|
+
fail2("OKM1121", "or() branches must be where objects.");
|
|
553
569
|
}
|
|
554
570
|
let wrote = false;
|
|
555
571
|
for (const key of Object.keys(branch)) {
|
|
@@ -569,15 +585,15 @@ function emitOr(schema, table, value, sink, alias, depth) {
|
|
|
569
585
|
}
|
|
570
586
|
function emitRelationFilter(schema, relation, value, sink, alias, depth) {
|
|
571
587
|
if (!isOperator(value)) {
|
|
572
|
-
|
|
588
|
+
fail2("OKM1121", `Relation ${relation.name} needs has, none, or every.`);
|
|
573
589
|
}
|
|
574
590
|
const name = operatorName(value);
|
|
575
591
|
if (name !== "has" && name !== "none" && name !== "every") {
|
|
576
|
-
|
|
592
|
+
fail2("OKM1121", `Relation ${relation.name} needs has, none, or every.`);
|
|
577
593
|
}
|
|
578
594
|
const child = indexes(schema).get(relation.table);
|
|
579
595
|
if (child === undefined) {
|
|
580
|
-
|
|
596
|
+
fail2("OKM1120", `Relation ${relation.name} names ${relation.table}, which is not in the schema.`);
|
|
581
597
|
}
|
|
582
598
|
const childAlias = `r${String(depth)}_${relation.name}`;
|
|
583
599
|
sink.mark(`rel:${relation.name}:${name}`);
|
|
@@ -601,7 +617,7 @@ function emitOrder(table, orderBy, sink, alias) {
|
|
|
601
617
|
if (orderBy === undefined)
|
|
602
618
|
return;
|
|
603
619
|
if (!isRecord(orderBy)) {
|
|
604
|
-
|
|
620
|
+
fail2("OKM1120", "orderBy must be an object of fields.");
|
|
605
621
|
}
|
|
606
622
|
const keys = Object.keys(orderBy);
|
|
607
623
|
if (keys.length === 0)
|
|
@@ -616,9 +632,14 @@ function emitOrder(table, orderBy, sink, alias) {
|
|
|
616
632
|
throwNamed2("OKM1120", key, table.names, `Field ${key} is not on ${table.model.name}. Accepted names: ${list(table.names)}.`);
|
|
617
633
|
}
|
|
618
634
|
refuseHidden(column);
|
|
619
|
-
const
|
|
635
|
+
const value = orderBy[key];
|
|
620
636
|
if (index > 0)
|
|
621
637
|
sink.text(", ");
|
|
638
|
+
if (isOperator(value) && operatorName(value) === "relevance") {
|
|
639
|
+
emitLazy(table, column, `${alias}.${quote(column.sql)}`, "relevance", operatorValue(value), sink, true);
|
|
640
|
+
continue;
|
|
641
|
+
}
|
|
642
|
+
const parsed = parseOrder(key, value);
|
|
622
643
|
sink.text(alias);
|
|
623
644
|
sink.text(".");
|
|
624
645
|
sink.text(quote(column.sql));
|
|
@@ -647,7 +668,7 @@ function emitPrimaryOrder(table, sink, alias) {
|
|
|
647
668
|
function refuseHidden(column) {
|
|
648
669
|
if (column.hidden !== true)
|
|
649
670
|
return;
|
|
650
|
-
|
|
671
|
+
fail2("OKM1120", `Field ${column.field} is hidden.`, "Call hidden({ filterable: true }).");
|
|
651
672
|
}
|
|
652
673
|
function emitLimit(call, sink) {
|
|
653
674
|
if (call.op === "one") {
|
|
@@ -660,7 +681,7 @@ function emitLimit(call, sink) {
|
|
|
660
681
|
return;
|
|
661
682
|
if (call.all !== undefined) {
|
|
662
683
|
if (call.all.length === 0) {
|
|
663
|
-
|
|
684
|
+
fail2("OKM1101", "find() .all needs a reason.");
|
|
664
685
|
}
|
|
665
686
|
sink.mark(`all:${call.all}`);
|
|
666
687
|
if (call.limit !== undefined) {
|
|
@@ -672,7 +693,7 @@ function emitLimit(call, sink) {
|
|
|
672
693
|
return;
|
|
673
694
|
}
|
|
674
695
|
if (call.limit === undefined) {
|
|
675
|
-
|
|
696
|
+
fail2("OKM1101", "find() needs a limit, or .all(reason) when the full set is intentional.");
|
|
676
697
|
}
|
|
677
698
|
const limit = readLimit(call.limit);
|
|
678
699
|
sink.text(" limit ");
|
|
@@ -689,12 +710,12 @@ function selectedColumns(table, select) {
|
|
|
689
710
|
return columns;
|
|
690
711
|
}
|
|
691
712
|
if (!Array.isArray(select)) {
|
|
692
|
-
|
|
713
|
+
fail2("OKM1120", "select must be a list of field names.");
|
|
693
714
|
}
|
|
694
715
|
const columns = [];
|
|
695
716
|
for (const name of select) {
|
|
696
717
|
if (typeof name !== "string") {
|
|
697
|
-
|
|
718
|
+
fail2("OKM1120", "select must be a list of field names.");
|
|
698
719
|
}
|
|
699
720
|
const column = table.columns.get(name);
|
|
700
721
|
if (column === undefined) {
|
|
@@ -712,17 +733,17 @@ function parseOrder(field, value) {
|
|
|
712
733
|
if (isRecord(value)) {
|
|
713
734
|
const dir = value.dir ?? value.direction;
|
|
714
735
|
if (dir !== "asc" && dir !== "desc") {
|
|
715
|
-
|
|
736
|
+
fail2("OKM1120", `orderBy ${field} must be asc or desc.`);
|
|
716
737
|
}
|
|
717
738
|
const nulls = value.nulls;
|
|
718
739
|
if (nulls === undefined)
|
|
719
740
|
return { dir, nulls: dir === "asc" ? "last" : "first" };
|
|
720
741
|
if (nulls !== "first" && nulls !== "last") {
|
|
721
|
-
|
|
742
|
+
fail2("OKM1120", `orderBy ${field} nulls must be first or last.`);
|
|
722
743
|
}
|
|
723
744
|
return { dir, nulls };
|
|
724
745
|
}
|
|
725
|
-
|
|
746
|
+
fail2("OKM1120", `orderBy ${field} must be asc or desc.`);
|
|
726
747
|
}
|
|
727
748
|
function rejectOptions(call) {
|
|
728
749
|
const accepted = readOptionNames(call.op);
|
|
@@ -739,11 +760,11 @@ function rejectOptions(call) {
|
|
|
739
760
|
present.include = call.include;
|
|
740
761
|
rejectKeys(present, accepted, call.op);
|
|
741
762
|
}
|
|
742
|
-
function rejectKeys(value, accepted, where) {
|
|
763
|
+
function rejectKeys(value, accepted, where, search) {
|
|
743
764
|
for (const key of Object.keys(value)) {
|
|
744
765
|
if (accepted.includes(key))
|
|
745
766
|
continue;
|
|
746
|
-
throwNamed2("OKM1120", key, accepted, `Option ${key} is not accepted by ${where}. Accepted options: ${list(accepted)}.`);
|
|
767
|
+
throwNamed2("OKM1120", key, accepted, key === "search" && search === true ? `${where}() does not take search. Pass search to find or count.` : `Option ${key} is not accepted by ${where}. Accepted options: ${list(accepted)}.`);
|
|
747
768
|
}
|
|
748
769
|
}
|
|
749
770
|
function readLimit(value) {
|
|
@@ -754,7 +775,7 @@ function readLimit(value) {
|
|
|
754
775
|
}
|
|
755
776
|
function requireValue(column, value) {
|
|
756
777
|
if (value === undefined || value === null) {
|
|
757
|
-
|
|
778
|
+
fail2("OKM1121", `Field ${column.field} needs a value.`);
|
|
758
779
|
}
|
|
759
780
|
if (typeof value === "object")
|
|
760
781
|
takeObject(column, value);
|
|
@@ -762,7 +783,7 @@ function requireValue(column, value) {
|
|
|
762
783
|
}
|
|
763
784
|
function takeObject(column, value, bare = false) {
|
|
764
785
|
if (bare || !column.accepts?.includes({}.toString.call(value).slice(8, -1))) {
|
|
765
|
-
|
|
786
|
+
fail2("OKM1121", `Field ${column.field} rejects that object.`);
|
|
766
787
|
}
|
|
767
788
|
}
|
|
768
789
|
function projectExpr(sql, dataType) {
|
|
@@ -867,7 +888,7 @@ var FAIL_FIX = {
|
|
|
867
888
|
function registerFailFix(code, summary) {
|
|
868
889
|
FAIL_FIX[code] = summary;
|
|
869
890
|
}
|
|
870
|
-
function
|
|
891
|
+
function fail2(code, message, fix) {
|
|
871
892
|
const summary = fix ?? FAIL_FIX[code];
|
|
872
893
|
throw new OkmError2(code, message, summary === undefined ? undefined : { fix: { summary } });
|
|
873
894
|
}
|
|
@@ -891,4 +912,4 @@ function hasMany(include) {
|
|
|
891
912
|
return Object.keys(include).length > 0;
|
|
892
913
|
}
|
|
893
914
|
|
|
894
|
-
export { withRowFilters, installArchiveInspect, archiveRules, readOptionNames, installOperatorSql, readNeedsOperatorSql, emitRelationFrom, bindCall, compileCall, decodeResult, logicalIntent, appliedRules, emitJoin, emitWhere, emitOrder, emitPrimaryOrder, refuseHidden, selectedColumns, parseOrder, rejectKeys, readLimit, takeObject, projectExpr, jsonExpr, decodeRow, cell, indexes, quote, list, isRecord, orFail, registerFailFix,
|
|
915
|
+
export { withRowFilters, installArchiveInspect, archiveRules, readOptionNames, installOperatorSql, readNeedsOperatorSql, orderHasRelevance, emitRelationFrom, needsOperatorSql, bindCall, compileCall, decodeResult, logicalIntent, appliedRules, emitJoin, emitWhere, emitOrder, emitPrimaryOrder, refuseHidden, emitLimit, selectedColumns, parseOrder, rejectKeys, readLimit, takeObject, projectExpr, jsonExpr, decodeRow, cell, indexes, quote, list, isRecord, orFail, registerFailFix, fail2 };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
open3
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
open3,
|
|
3
|
+
seal2
|
|
4
|
+
} from "./4m6hskg8.js";
|
|
5
5
|
import {
|
|
6
6
|
PGLITE_CAPABILITIES,
|
|
7
7
|
readCapability2,
|
|
8
8
|
hasCapability2
|
|
9
|
-
} from "./
|
|
9
|
+
} from "./ae4j5f42.js";
|
|
10
10
|
export {
|
|
11
11
|
PGLITE_CAPABILITIES as capabilities,
|
|
12
12
|
hasCapability2 as hasCapability,
|
|
13
13
|
open3 as open,
|
|
14
|
-
readCapability2 as readCapability
|
|
14
|
+
readCapability2 as readCapability,
|
|
15
|
+
seal2 as seal
|
|
15
16
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./
|
|
2
|
+
stack2
|
|
3
|
+
} from "./mss6ctgv.js";
|
|
4
4
|
import {
|
|
5
5
|
checkPresetNames
|
|
6
|
-
} from "./
|
|
6
|
+
} from "./znm0bpp5.js";
|
|
7
7
|
import {
|
|
8
8
|
isOperator,
|
|
9
9
|
operatorValue
|
|
@@ -60,7 +60,7 @@ function refine(schema, call, uses) {
|
|
|
60
60
|
const { wheres, rules } = resolve(schema, call.table, uses);
|
|
61
61
|
return {
|
|
62
62
|
...call,
|
|
63
|
-
where:
|
|
63
|
+
where: stack2(call.where, wheres),
|
|
64
64
|
ruleLines: [...call.ruleLines ?? [], ...rules]
|
|
65
65
|
};
|
|
66
66
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DriverError2
|
|
3
|
+
} from "./cm3w0ywp.js";
|
|
4
|
+
import {
|
|
5
|
+
armDriverError,
|
|
6
|
+
send,
|
|
7
|
+
connectClient
|
|
8
|
+
} from "./14x60fbf.js";
|
|
9
|
+
import {
|
|
10
|
+
resetSession2
|
|
11
|
+
} from "./7ghwamrf.js";
|
|
12
|
+
import {
|
|
13
|
+
cursorStream
|
|
14
|
+
} from "./7kms6fvj.js";
|
|
15
|
+
import {
|
|
16
|
+
isConnectionLost
|
|
17
|
+
} from "./cnkky55j.js";
|
|
18
|
+
import {
|
|
19
|
+
WireSession
|
|
20
|
+
} from "./mtw6jz76.js";
|
|
21
|
+
import {
|
|
22
|
+
rejectClosed,
|
|
23
|
+
runCall
|
|
24
|
+
} from "./ae4j5f42.js";
|
|
25
|
+
|
|
26
|
+
// src/adapters/pg/nodepostgres-extra.ts
|
|
27
|
+
async function checkout(held) {
|
|
28
|
+
const { pool, counters, named, isClosed } = held;
|
|
29
|
+
if (isClosed())
|
|
30
|
+
return rejectClosed();
|
|
31
|
+
const client = await connectClient(pool, held.acquireMs, counters);
|
|
32
|
+
counters.reserved += 1;
|
|
33
|
+
let lost = false;
|
|
34
|
+
const onError = () => {
|
|
35
|
+
lost = true;
|
|
36
|
+
};
|
|
37
|
+
const events = client;
|
|
38
|
+
events.on("error", onError);
|
|
39
|
+
const local = new Set;
|
|
40
|
+
const session = new WireSession((text, params) => {
|
|
41
|
+
const pending = send(client, text, params, named, client);
|
|
42
|
+
const guarded = pending.catch((error) => {
|
|
43
|
+
if (isConnectionLost(error) || lost) {
|
|
44
|
+
lost = true;
|
|
45
|
+
if (isConnectionLost(error))
|
|
46
|
+
throw error;
|
|
47
|
+
throw Object.assign(new DriverError2("CONNECTION_CLOSED", { cause: error }), {
|
|
48
|
+
code: "CONNECTION_CLOSED"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
throw error;
|
|
52
|
+
});
|
|
53
|
+
guarded.cancel = () => {
|
|
54
|
+
pending.cancel?.();
|
|
55
|
+
};
|
|
56
|
+
return guarded;
|
|
57
|
+
}, held.notices, isClosed, true, () => {
|
|
58
|
+
counters.reservedBusy += 1;
|
|
59
|
+
}, () => {
|
|
60
|
+
counters.reservedBusy = Math.max(0, counters.reservedBusy - 1);
|
|
61
|
+
}, local);
|
|
62
|
+
const guard = (run) => lost ? rejectClosed() : run();
|
|
63
|
+
let released = false;
|
|
64
|
+
return {
|
|
65
|
+
execute: (text, params, options) => guard(() => runCall(isClosed(), options, (watch) => session.query(text, params, watch))),
|
|
66
|
+
batch: (statements, options) => guard(() => runCall(isClosed(), options, async (watch) => {
|
|
67
|
+
const { runAtomicBatch } = await import("./b76b8d95.js");
|
|
68
|
+
return runAtomicBatch(session, statements, watch);
|
|
69
|
+
})),
|
|
70
|
+
cancel() {
|
|
71
|
+
session.cancel();
|
|
72
|
+
},
|
|
73
|
+
async release() {
|
|
74
|
+
if (released)
|
|
75
|
+
return;
|
|
76
|
+
released = true;
|
|
77
|
+
try {
|
|
78
|
+
if (!lost)
|
|
79
|
+
await reset(session, client);
|
|
80
|
+
} finally {
|
|
81
|
+
counters.reserved = Math.max(0, counters.reserved - 1);
|
|
82
|
+
events.removeListener("error", onError);
|
|
83
|
+
client.release(lost);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function reset(session, client) {
|
|
89
|
+
await resetSession2(session.depth(), (text) => client.query(text));
|
|
90
|
+
}
|
|
91
|
+
async function listen(held, channel, onNotify) {
|
|
92
|
+
const { pool, counters } = held;
|
|
93
|
+
const client = await connectClient(pool, held.acquireMs, counters);
|
|
94
|
+
counters.reserved += 1;
|
|
95
|
+
const quoted = quoteIdent(channel);
|
|
96
|
+
const onNotification = (message) => {
|
|
97
|
+
if (message.channel === channel)
|
|
98
|
+
onNotify(message.payload ?? "");
|
|
99
|
+
};
|
|
100
|
+
client.on("notification", onNotification);
|
|
101
|
+
let released = false;
|
|
102
|
+
const release = (dead) => {
|
|
103
|
+
if (released)
|
|
104
|
+
return;
|
|
105
|
+
released = true;
|
|
106
|
+
client.removeListener("notification", onNotification);
|
|
107
|
+
client.removeListener("error", release);
|
|
108
|
+
counters.reserved = Math.max(0, counters.reserved - 1);
|
|
109
|
+
client.release(Boolean(dead));
|
|
110
|
+
};
|
|
111
|
+
armDriverError(client, release);
|
|
112
|
+
try {
|
|
113
|
+
await client.query(`LISTEN ${quoted}`);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
release(false);
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
return async () => {
|
|
119
|
+
if (released)
|
|
120
|
+
return;
|
|
121
|
+
try {
|
|
122
|
+
await client.query(`UNLISTEN ${quoted}`);
|
|
123
|
+
} finally {
|
|
124
|
+
release(false);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function streamRows(checkout, text, params) {
|
|
129
|
+
return async function* () {
|
|
130
|
+
const connection = await checkout();
|
|
131
|
+
try {
|
|
132
|
+
yield* cursorStream((statement, values) => connection.execute(statement, values), text, params);
|
|
133
|
+
} finally {
|
|
134
|
+
await connection.release();
|
|
135
|
+
}
|
|
136
|
+
}();
|
|
137
|
+
}
|
|
138
|
+
function quoteIdent(name) {
|
|
139
|
+
return `"${name.replaceAll('"', '""')}"`;
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
checkout,
|
|
143
|
+
listen,
|
|
144
|
+
streamRows
|
|
145
|
+
};
|