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,261 @@
|
|
|
1
|
+
import {
|
|
2
|
+
noTimeout
|
|
3
|
+
} from "./rs1jb051.js";
|
|
4
|
+
import {
|
|
5
|
+
PGLITE_CAPABILITIES,
|
|
6
|
+
driverErrors,
|
|
7
|
+
rejectClosed,
|
|
8
|
+
rejectCancelled,
|
|
9
|
+
rejectTimedOut,
|
|
10
|
+
nextTransactionDepth,
|
|
11
|
+
runCall,
|
|
12
|
+
EMPTY_NOTICES,
|
|
13
|
+
resultFrom
|
|
14
|
+
} from "./xhrnjch9.js";
|
|
15
|
+
|
|
16
|
+
// src/adapters/pg/pglite.ts
|
|
17
|
+
import { PGlite } from "@electric-sql/pglite";
|
|
18
|
+
async function open6(config = {}) {
|
|
19
|
+
const wire = await import("./dzx85q70.js");
|
|
20
|
+
const db = new PGlite({
|
|
21
|
+
dataDir: config.dataDir ?? "memory://",
|
|
22
|
+
parsers: wire.parsers,
|
|
23
|
+
serializers: wire.serializers
|
|
24
|
+
});
|
|
25
|
+
await db.waitReady;
|
|
26
|
+
const acquireMs = config.timeouts?.acquire;
|
|
27
|
+
const slot = new Slot;
|
|
28
|
+
const notices = noticeBuffer();
|
|
29
|
+
const queryOptions = {
|
|
30
|
+
rowMode: "array",
|
|
31
|
+
parsers: wire.parsers,
|
|
32
|
+
serializers: wire.serializers,
|
|
33
|
+
onNotice(notice) {
|
|
34
|
+
notices.push(notice);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
let closed = false;
|
|
38
|
+
let inflight = 0;
|
|
39
|
+
const session = new PgliteSession(db, queryOptions, notices, () => {
|
|
40
|
+
inflight += 1;
|
|
41
|
+
}, () => {
|
|
42
|
+
inflight = Math.max(0, inflight - 1);
|
|
43
|
+
}, (error) => wire.fail(error));
|
|
44
|
+
async function lease() {
|
|
45
|
+
if (closed)
|
|
46
|
+
return rejectClosed();
|
|
47
|
+
await slot.acquire(acquireMs);
|
|
48
|
+
let released = false;
|
|
49
|
+
return {
|
|
50
|
+
execute: (text, params, options) => {
|
|
51
|
+
const refused = noTimeout(options);
|
|
52
|
+
if (refused !== undefined)
|
|
53
|
+
return refused;
|
|
54
|
+
return runCall(closed, options, (watch) => session.query(text, params, watch));
|
|
55
|
+
},
|
|
56
|
+
batch: (statements, options) => {
|
|
57
|
+
const refused = noTimeout(options);
|
|
58
|
+
if (refused !== undefined)
|
|
59
|
+
return refused;
|
|
60
|
+
return runCall(closed, options, async (watch) => {
|
|
61
|
+
const { runAtomicBatch } = await import("./3rrw5w8f.js");
|
|
62
|
+
return runAtomicBatch(session, statements, watch);
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
async release() {
|
|
66
|
+
if (released)
|
|
67
|
+
return;
|
|
68
|
+
released = true;
|
|
69
|
+
try {
|
|
70
|
+
const { resetQueried } = await import("./08kemxjd.js");
|
|
71
|
+
await resetQueried(session);
|
|
72
|
+
} finally {
|
|
73
|
+
slot.release();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
capabilities: PGLITE_CAPABILITIES,
|
|
80
|
+
execute(text, params, options) {
|
|
81
|
+
const refused = noTimeout(options);
|
|
82
|
+
if (refused !== undefined)
|
|
83
|
+
return refused;
|
|
84
|
+
return runCall(closed, options, async (watch) => {
|
|
85
|
+
await slot.acquire(acquireMs);
|
|
86
|
+
try {
|
|
87
|
+
return await session.query(text, params, watch);
|
|
88
|
+
} finally {
|
|
89
|
+
slot.release();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
async batch(statements, options) {
|
|
94
|
+
const refused = noTimeout(options);
|
|
95
|
+
if (refused !== undefined)
|
|
96
|
+
return refused;
|
|
97
|
+
const connection = await lease();
|
|
98
|
+
try {
|
|
99
|
+
return await connection.batch(statements, options);
|
|
100
|
+
} finally {
|
|
101
|
+
await connection.release();
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
reserve: () => lease(),
|
|
105
|
+
async describe(text) {
|
|
106
|
+
await slot.acquire(acquireMs);
|
|
107
|
+
try {
|
|
108
|
+
const described = await db.describeQuery(text);
|
|
109
|
+
return {
|
|
110
|
+
columns: described.resultFields.map((field) => field.name),
|
|
111
|
+
parameterCount: described.queryParams.length
|
|
112
|
+
};
|
|
113
|
+
} finally {
|
|
114
|
+
slot.release();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
async listen(channel, onNotify) {
|
|
118
|
+
const unlisten = await db.listen(channel, onNotify);
|
|
119
|
+
return async () => {
|
|
120
|
+
await unlisten();
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
stats() {
|
|
124
|
+
return { size: 1, idle: slot.idle, inflight, waiting: slot.waiting };
|
|
125
|
+
},
|
|
126
|
+
async close() {
|
|
127
|
+
closed = true;
|
|
128
|
+
await db.close();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function seal2(pool) {
|
|
133
|
+
let closed = 0;
|
|
134
|
+
return new Proxy(pool, {
|
|
135
|
+
get: (inner, key) => key === "close" ? () => Promise.resolve(closed = 1) : (inner = inner[key], closed && inner?.call ? () => rejectClosed() : inner)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
class PgliteSession {
|
|
140
|
+
canCancel = false;
|
|
141
|
+
transactionDepth = 0;
|
|
142
|
+
db;
|
|
143
|
+
options;
|
|
144
|
+
notices;
|
|
145
|
+
enter;
|
|
146
|
+
leave;
|
|
147
|
+
fail;
|
|
148
|
+
constructor(db, options, notices, enter, leave, fail) {
|
|
149
|
+
this.db = db;
|
|
150
|
+
this.options = options;
|
|
151
|
+
this.notices = notices;
|
|
152
|
+
this.enter = enter;
|
|
153
|
+
this.leave = leave;
|
|
154
|
+
this.fail = fail;
|
|
155
|
+
}
|
|
156
|
+
query(text, params, watch) {
|
|
157
|
+
const why = watch?.reason();
|
|
158
|
+
if (why === "timeout")
|
|
159
|
+
return rejectTimedOut();
|
|
160
|
+
if (why === "cancelled" || watch?.signal.aborted === true)
|
|
161
|
+
return rejectCancelled();
|
|
162
|
+
this.enter();
|
|
163
|
+
const pending = params === undefined || params.length === 0 ? this.db.query(text, undefined, this.options) : this.db.query(text, params, this.options);
|
|
164
|
+
return pending.then((result) => {
|
|
165
|
+
this.leave();
|
|
166
|
+
this.note(text);
|
|
167
|
+
return resultFrom(result, this.notices.take());
|
|
168
|
+
}, (error) => {
|
|
169
|
+
this.leave();
|
|
170
|
+
this.notices.take();
|
|
171
|
+
return this.fail(stampQuery(error, text)).then((mapped) => {
|
|
172
|
+
throw mapped;
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
inTransaction() {
|
|
177
|
+
return this.transactionDepth > 0;
|
|
178
|
+
}
|
|
179
|
+
abandon() {
|
|
180
|
+
this.transactionDepth = 0;
|
|
181
|
+
}
|
|
182
|
+
rollback() {
|
|
183
|
+
return this.query("ROLLBACK", undefined, undefined).then(() => {
|
|
184
|
+
this.transactionDepth = 0;
|
|
185
|
+
}, (error) => {
|
|
186
|
+
this.transactionDepth = 0;
|
|
187
|
+
throw error;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
note(text) {
|
|
191
|
+
this.transactionDepth = nextTransactionDepth(this.transactionDepth, text);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function noticeBuffer() {
|
|
195
|
+
let notices;
|
|
196
|
+
return {
|
|
197
|
+
push(notice) {
|
|
198
|
+
const severity = notice.severity ?? "";
|
|
199
|
+
const message = notice.message ?? "";
|
|
200
|
+
const code = notice.code !== undefined && notice.code.length > 0 ? notice.code : undefined;
|
|
201
|
+
const entry = code === undefined ? { severity, message } : { severity, message, code };
|
|
202
|
+
(notices ??= []).push(entry);
|
|
203
|
+
},
|
|
204
|
+
take() {
|
|
205
|
+
const taken = notices ?? EMPTY_NOTICES;
|
|
206
|
+
notices = undefined;
|
|
207
|
+
return taken;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
class Slot {
|
|
213
|
+
held = false;
|
|
214
|
+
waiters = [];
|
|
215
|
+
acquire(acquireMs) {
|
|
216
|
+
if (!this.held) {
|
|
217
|
+
this.held = true;
|
|
218
|
+
return Promise.resolve();
|
|
219
|
+
}
|
|
220
|
+
return new Promise((resolve, reject) => {
|
|
221
|
+
const waiter = {
|
|
222
|
+
resolve,
|
|
223
|
+
timer: undefined
|
|
224
|
+
};
|
|
225
|
+
if (acquireMs !== undefined) {
|
|
226
|
+
waiter.timer = setTimeout(() => {
|
|
227
|
+
const index = this.waiters.indexOf(waiter);
|
|
228
|
+
if (index !== -1)
|
|
229
|
+
this.waiters.splice(index, 1);
|
|
230
|
+
driverErrors().then((errors) => {
|
|
231
|
+
reject(errors.acquireTimeout());
|
|
232
|
+
});
|
|
233
|
+
}, acquireMs);
|
|
234
|
+
}
|
|
235
|
+
this.waiters.push(waiter);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
release() {
|
|
239
|
+
const next = this.waiters.shift();
|
|
240
|
+
if (next === undefined) {
|
|
241
|
+
this.held = false;
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (next.timer !== undefined)
|
|
245
|
+
clearTimeout(next.timer);
|
|
246
|
+
next.resolve();
|
|
247
|
+
}
|
|
248
|
+
get idle() {
|
|
249
|
+
return this.held ? 0 : 1;
|
|
250
|
+
}
|
|
251
|
+
get waiting() {
|
|
252
|
+
return this.waiters.length;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function stampQuery(error, text) {
|
|
256
|
+
if (typeof error === "object" && error !== null && !("query" in error))
|
|
257
|
+
Reflect.set(error, "query", text);
|
|
258
|
+
return error;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export { open6, seal2 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
open6,
|
|
3
|
+
seal2
|
|
4
|
+
} from "./djydjpqt.js";
|
|
5
|
+
import {
|
|
6
|
+
PGLITE_CAPABILITIES,
|
|
7
|
+
readCapability2,
|
|
8
|
+
hasCapability2
|
|
9
|
+
} from "./xhrnjch9.js";
|
|
10
|
+
export {
|
|
11
|
+
PGLITE_CAPABILITIES as capabilities,
|
|
12
|
+
hasCapability2 as hasCapability,
|
|
13
|
+
open6 as open,
|
|
14
|
+
readCapability2 as readCapability,
|
|
15
|
+
seal2 as seal
|
|
16
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mapFailure
|
|
3
|
+
} from "./xhrnjch9.js";
|
|
4
|
+
|
|
5
|
+
// src/adapters/pg/pglite-wire.ts
|
|
6
|
+
var OIDS = [
|
|
7
|
+
16,
|
|
8
|
+
17,
|
|
9
|
+
20,
|
|
10
|
+
21,
|
|
11
|
+
23,
|
|
12
|
+
25,
|
|
13
|
+
114,
|
|
14
|
+
700,
|
|
15
|
+
701,
|
|
16
|
+
1043,
|
|
17
|
+
1082,
|
|
18
|
+
1114,
|
|
19
|
+
1184,
|
|
20
|
+
1700,
|
|
21
|
+
2950,
|
|
22
|
+
3802,
|
|
23
|
+
1000,
|
|
24
|
+
1005,
|
|
25
|
+
1007,
|
|
26
|
+
1009,
|
|
27
|
+
1016,
|
|
28
|
+
1115,
|
|
29
|
+
1182,
|
|
30
|
+
1185,
|
|
31
|
+
1231,
|
|
32
|
+
199,
|
|
33
|
+
3807
|
|
34
|
+
];
|
|
35
|
+
function identity(value) {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function serialize(value) {
|
|
39
|
+
if (typeof value === "number" || typeof value === "bigint")
|
|
40
|
+
return String(value);
|
|
41
|
+
if (typeof value === "boolean")
|
|
42
|
+
return value ? "t" : "f";
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
var parsers = {};
|
|
46
|
+
var serializers = {};
|
|
47
|
+
for (const oid of OIDS) {
|
|
48
|
+
parsers[oid] = identity;
|
|
49
|
+
serializers[oid] = serialize;
|
|
50
|
+
}
|
|
51
|
+
function fail(error) {
|
|
52
|
+
return mapFailure(protocol(error));
|
|
53
|
+
}
|
|
54
|
+
function protocol(error) {
|
|
55
|
+
if (typeof error !== "object" || error === null || !("code" in error))
|
|
56
|
+
return error;
|
|
57
|
+
if (error.code !== "08P01")
|
|
58
|
+
return error;
|
|
59
|
+
const message = error instanceof Error ? error.message : "";
|
|
60
|
+
return new Error(message.length > 0 ? message : "protocol error");
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
fail,
|
|
64
|
+
parsers,
|
|
65
|
+
serializers
|
|
66
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readHandle,
|
|
3
|
+
readCall,
|
|
4
|
+
attachHttp
|
|
5
|
+
} from "./mtrqn2hn.js";
|
|
6
|
+
import {
|
|
7
|
+
OkmError,
|
|
8
|
+
throwNamed,
|
|
9
|
+
decodeResult,
|
|
10
|
+
emitWhere,
|
|
11
|
+
emitOrder,
|
|
12
|
+
selectedColumns,
|
|
13
|
+
rejectKeys,
|
|
14
|
+
projectExpr,
|
|
15
|
+
indexes,
|
|
16
|
+
quote,
|
|
17
|
+
list,
|
|
18
|
+
isRecord,
|
|
19
|
+
fail2
|
|
20
|
+
} from "./f9mphxej.js";
|
|
21
|
+
|
|
22
|
+
// src/runtime/tree.ts
|
|
23
|
+
var OPTIONS = [
|
|
24
|
+
"where",
|
|
25
|
+
"select",
|
|
26
|
+
"orderBy",
|
|
27
|
+
"depth",
|
|
28
|
+
"self",
|
|
29
|
+
"relation",
|
|
30
|
+
"route",
|
|
31
|
+
"signal",
|
|
32
|
+
"timeout"
|
|
33
|
+
];
|
|
34
|
+
function build2(session, table, options, mods, view) {
|
|
35
|
+
try {
|
|
36
|
+
return open(session, table, options, mods, view);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw error instanceof OkmError ? attachHttp(session.http, error) : error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function open(session, table, options, mods, view) {
|
|
42
|
+
const packed = readPacked(options);
|
|
43
|
+
const user = packed.user;
|
|
44
|
+
rejectKeys(user, OPTIONS, packed.walk);
|
|
45
|
+
const indexed = indexes(session.schema).get(table);
|
|
46
|
+
if (indexed === undefined)
|
|
47
|
+
fail2("OKM1120", `Table ${table} is not in the schema.`);
|
|
48
|
+
const edge = pickEdge(indexed, user.relation);
|
|
49
|
+
const identity = identityColumn2(session, indexed);
|
|
50
|
+
const depth = readDepth(user.depth);
|
|
51
|
+
const self = readSelf(user.self);
|
|
52
|
+
const id = userId(identity, packed.id);
|
|
53
|
+
const shared = {
|
|
54
|
+
...user.where !== undefined ? { where: user.where } : {},
|
|
55
|
+
...user.select !== undefined ? { select: user.select } : {},
|
|
56
|
+
...user.orderBy !== undefined ? { orderBy: user.orderBy } : {},
|
|
57
|
+
...user.signal !== undefined ? { signal: user.signal } : {},
|
|
58
|
+
...user.timeout !== undefined ? { timeout: user.timeout } : {},
|
|
59
|
+
...user.route !== undefined ? { route: user.route } : {}
|
|
60
|
+
};
|
|
61
|
+
const base = readCall("find", table, shared, mods.all, session.scope, session.schema.model[table], session.schema, view);
|
|
62
|
+
const spec = { direction: packed.walk, edge, identity, depth, self, id };
|
|
63
|
+
const call = {
|
|
64
|
+
...base,
|
|
65
|
+
op: packed.walk,
|
|
66
|
+
build: (schema, planned, sink, outputs, source) => {
|
|
67
|
+
emitTree(schema, planned, sink, outputs, source, spec);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return readHandle(session, table, call, mods, (compiled, rows) => decodeResult(compiled, rows, table));
|
|
71
|
+
}
|
|
72
|
+
function emitTree(schema, table, sink, outputs, call, spec) {
|
|
73
|
+
const { direction, edge, identity, depth, self, id } = spec;
|
|
74
|
+
sink.mark(`walk:${direction}|rel:${edge.name}|self:${self ? "1" : "0"}|depth:${depth === undefined ? "all" : String(depth)}|`);
|
|
75
|
+
const selected = selectedColumns(table, call.select);
|
|
76
|
+
sink.text("with recursive walk as (select ");
|
|
77
|
+
emitKeyList(sink, "s", edge.parent, "k");
|
|
78
|
+
emitKeyList(sink, "s", edge.child, "f");
|
|
79
|
+
sink.text(", 0 as depth, array[s.");
|
|
80
|
+
sink.text(quote(identity.sql));
|
|
81
|
+
sink.text("] as seen from ");
|
|
82
|
+
sink.text(quote(table.model.sql));
|
|
83
|
+
sink.text(" s where s.");
|
|
84
|
+
sink.text(quote(identity.sql));
|
|
85
|
+
sink.text(" = ");
|
|
86
|
+
sink.param(identity.encode(id));
|
|
87
|
+
emitWhere(schema, table, undefined, sink, "s", 0, true);
|
|
88
|
+
sink.text(" union all select ");
|
|
89
|
+
let started = emitBare(sink, "c", edge.parent, false);
|
|
90
|
+
emitBare(sink, "c", edge.child, started);
|
|
91
|
+
sink.text(", w.depth + 1, w.seen || c.");
|
|
92
|
+
sink.text(quote(identity.sql));
|
|
93
|
+
sink.text(" from ");
|
|
94
|
+
sink.text(quote(table.model.sql));
|
|
95
|
+
sink.text(" c join walk w on ");
|
|
96
|
+
if (direction === "descendants")
|
|
97
|
+
emitStep(sink, "c", edge.child, edge.parent, "k");
|
|
98
|
+
else
|
|
99
|
+
emitStep(sink, "c", edge.parent, edge.child, "f");
|
|
100
|
+
sink.text(" where c.");
|
|
101
|
+
sink.text(quote(identity.sql));
|
|
102
|
+
sink.text(" <> all(w.seen)");
|
|
103
|
+
if (depth !== undefined) {
|
|
104
|
+
sink.text(" and w.depth < ");
|
|
105
|
+
sink.text(String(depth));
|
|
106
|
+
}
|
|
107
|
+
emitWhere(schema, table, undefined, sink, "c", 0, true);
|
|
108
|
+
sink.text(") select ");
|
|
109
|
+
let column = 0;
|
|
110
|
+
for (let index = 0;index < selected.length; index += 1) {
|
|
111
|
+
const item = selected[index];
|
|
112
|
+
if (item === undefined)
|
|
113
|
+
continue;
|
|
114
|
+
if (column > 0)
|
|
115
|
+
sink.text(", ");
|
|
116
|
+
sink.text(projectExpr(`t.${quote(item.sql)}`, item.dataType));
|
|
117
|
+
sink.mark(`s:${item.field}`);
|
|
118
|
+
outputs?.fields.push({ key: item.field, at: column, decode: item.decode });
|
|
119
|
+
column += 1;
|
|
120
|
+
}
|
|
121
|
+
if (column === 0)
|
|
122
|
+
sink.text("1");
|
|
123
|
+
sink.text(" from ");
|
|
124
|
+
sink.text(quote(table.model.sql));
|
|
125
|
+
sink.text(" t join walk w on ");
|
|
126
|
+
emitStep(sink, "t", edge.parent, edge.parent, "k");
|
|
127
|
+
if (self)
|
|
128
|
+
emitWhere(schema, table, call.where, sink, "t", 0, false);
|
|
129
|
+
else {
|
|
130
|
+
sink.text(" where w.depth > 0");
|
|
131
|
+
emitWhere(schema, table, call.where, sink, "t", 0, true);
|
|
132
|
+
}
|
|
133
|
+
if (call.orderBy !== undefined) {
|
|
134
|
+
emitOrder(table, call.orderBy, sink, "t");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
sink.text(" order by w.depth asc");
|
|
138
|
+
sink.mark("order:depth");
|
|
139
|
+
for (const field of table.model.primary) {
|
|
140
|
+
const item = table.columns.get(field);
|
|
141
|
+
if (item === undefined)
|
|
142
|
+
continue;
|
|
143
|
+
sink.text(", t.");
|
|
144
|
+
sink.text(quote(item.sql));
|
|
145
|
+
sink.text(" asc");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function emitKeyList(sink, alias, columns, prefix) {
|
|
149
|
+
for (let index = 0;index < columns.length; index += 1) {
|
|
150
|
+
const name = columns[index];
|
|
151
|
+
if (name === undefined)
|
|
152
|
+
continue;
|
|
153
|
+
if (index > 0 || prefix === "f")
|
|
154
|
+
sink.text(", ");
|
|
155
|
+
sink.text(alias);
|
|
156
|
+
sink.text(".");
|
|
157
|
+
sink.text(quote(name));
|
|
158
|
+
sink.text(" as ");
|
|
159
|
+
sink.text(prefix);
|
|
160
|
+
sink.text(String(index));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function emitBare(sink, alias, columns, lead) {
|
|
164
|
+
let started = lead;
|
|
165
|
+
for (const name of columns) {
|
|
166
|
+
if (started)
|
|
167
|
+
sink.text(", ");
|
|
168
|
+
started = true;
|
|
169
|
+
sink.text(alias);
|
|
170
|
+
sink.text(".");
|
|
171
|
+
sink.text(quote(name));
|
|
172
|
+
}
|
|
173
|
+
return started;
|
|
174
|
+
}
|
|
175
|
+
function emitStep(sink, alias, columns, against, prefix) {
|
|
176
|
+
for (let index = 0;index < columns.length; index += 1) {
|
|
177
|
+
const name = columns[index];
|
|
178
|
+
if (name === undefined || against[index] === undefined)
|
|
179
|
+
continue;
|
|
180
|
+
if (index > 0)
|
|
181
|
+
sink.text(" and ");
|
|
182
|
+
sink.text(alias);
|
|
183
|
+
sink.text(".");
|
|
184
|
+
sink.text(quote(name));
|
|
185
|
+
sink.text(" = w.");
|
|
186
|
+
sink.text(prefix);
|
|
187
|
+
sink.text(String(index));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function readPacked(options) {
|
|
191
|
+
if (!isRecord(options) || options.walk !== "descendants" && options.walk !== "ancestors") {
|
|
192
|
+
fail2("OKM1120", "descendants and ancestors are table methods.");
|
|
193
|
+
}
|
|
194
|
+
const user = options.options;
|
|
195
|
+
if (user === undefined)
|
|
196
|
+
return { id: options.id, walk: options.walk, user: {} };
|
|
197
|
+
if (!isRecord(user))
|
|
198
|
+
fail2("OKM1120", `${options.walk} options must be an object.`);
|
|
199
|
+
return { id: options.id, walk: options.walk, user };
|
|
200
|
+
}
|
|
201
|
+
function pickEdge(table, relation) {
|
|
202
|
+
const edges = selfEdges(table);
|
|
203
|
+
if (edges.length === 0) {
|
|
204
|
+
fail2("OKM1120", `${table.model.name} has no relation to itself.`, `Declare children: many("${table.model.name}") or parent: one("${table.model.name}").`);
|
|
205
|
+
}
|
|
206
|
+
const groups = new Set(edges.map((edge) => edge.child.join("\x00")));
|
|
207
|
+
if (relation === undefined) {
|
|
208
|
+
if (groups.size !== 1) {
|
|
209
|
+
fail2("OKM1120", `${table.model.name} has more than one relation to itself. Pass relation.`, `Accepted names: ${edges.map((edge) => edge.name).join(", ")}.`);
|
|
210
|
+
}
|
|
211
|
+
const only = edges[0];
|
|
212
|
+
if (only === undefined)
|
|
213
|
+
fail2("OKM1120", `${table.model.name} has no relation to itself.`);
|
|
214
|
+
return only;
|
|
215
|
+
}
|
|
216
|
+
if (typeof relation !== "string" || relation.length === 0) {
|
|
217
|
+
fail2("OKM1120", "relation must be a name.");
|
|
218
|
+
}
|
|
219
|
+
const found = edges.find((edge) => edge.name === relation);
|
|
220
|
+
if (found === undefined) {
|
|
221
|
+
throwNamed("OKM1120", relation, edges.map((edge) => edge.name), `Relation ${relation} is not a self-relation of ${table.model.name}. Accepted names: ${list(edges.map((edge) => edge.name))}.`);
|
|
222
|
+
}
|
|
223
|
+
return found;
|
|
224
|
+
}
|
|
225
|
+
function selfEdges(table) {
|
|
226
|
+
const edges = [];
|
|
227
|
+
for (const relation of table.model.relations) {
|
|
228
|
+
if (relation.table !== table.model.name || relation.through !== undefined)
|
|
229
|
+
continue;
|
|
230
|
+
edges.push(relation.kind === "many" ? { name: relation.name, parent: relation.local, child: relation.remote } : { name: relation.name, parent: relation.remote, child: relation.local });
|
|
231
|
+
}
|
|
232
|
+
return edges;
|
|
233
|
+
}
|
|
234
|
+
function identityColumn2(session, table) {
|
|
235
|
+
const tenancy = session.schema.tenancy;
|
|
236
|
+
const keys = tenancy === undefined ? [] : tenancy.keys ?? [tenancy.key];
|
|
237
|
+
const fields = table.model.primary.filter((field) => !keys.includes(field));
|
|
238
|
+
if (fields.length !== 1) {
|
|
239
|
+
fail2("OKM1120", `${table.model.name} needs one primary key column besides the tenant key.`, "Use a single-column primary key.");
|
|
240
|
+
}
|
|
241
|
+
const field = fields[0];
|
|
242
|
+
const column = field === undefined ? undefined : table.columns.get(field);
|
|
243
|
+
if (column === undefined) {
|
|
244
|
+
fail2("OKM1120", `${table.model.name} needs one primary key column besides the tenant key.`);
|
|
245
|
+
}
|
|
246
|
+
return column;
|
|
247
|
+
}
|
|
248
|
+
function readDepth(value) {
|
|
249
|
+
if (value === undefined)
|
|
250
|
+
return;
|
|
251
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
252
|
+
fail2("OKM1120", "depth must be an integer from 0 up.");
|
|
253
|
+
}
|
|
254
|
+
return value;
|
|
255
|
+
}
|
|
256
|
+
function readSelf(value) {
|
|
257
|
+
if (value === undefined)
|
|
258
|
+
return false;
|
|
259
|
+
if (typeof value !== "boolean")
|
|
260
|
+
fail2("OKM1120", "self must be true or false.");
|
|
261
|
+
return value;
|
|
262
|
+
}
|
|
263
|
+
function userId(column, id) {
|
|
264
|
+
if (id === undefined || id === null) {
|
|
265
|
+
fail2("OKM1121", `${column.field} needs a value.`);
|
|
266
|
+
}
|
|
267
|
+
return id;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export { build2, identityColumn2 };
|