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,185 @@
|
|
|
1
|
+
// src/adapters/capabilities.ts
|
|
2
|
+
var POSTGRESJS_CAPABILITIES = {
|
|
3
|
+
transactions: "interactive",
|
|
4
|
+
stream: true,
|
|
5
|
+
listen: true,
|
|
6
|
+
cancel: true,
|
|
7
|
+
prepared: "unnamed",
|
|
8
|
+
describe: true
|
|
9
|
+
};
|
|
10
|
+
var PGLITE_CAPABILITIES = {
|
|
11
|
+
transactions: "interactive",
|
|
12
|
+
stream: false,
|
|
13
|
+
listen: true,
|
|
14
|
+
cancel: false,
|
|
15
|
+
prepared: "unnamed",
|
|
16
|
+
describe: true
|
|
17
|
+
};
|
|
18
|
+
var NODE_POSTGRES_CAPABILITIES = {
|
|
19
|
+
transactions: "interactive",
|
|
20
|
+
stream: true,
|
|
21
|
+
listen: true,
|
|
22
|
+
cancel: true,
|
|
23
|
+
prepared: "unnamed",
|
|
24
|
+
describe: false
|
|
25
|
+
};
|
|
26
|
+
var BUNSQL_CAPABILITIES = {
|
|
27
|
+
transactions: "interactive",
|
|
28
|
+
stream: true,
|
|
29
|
+
listen: true,
|
|
30
|
+
cancel: false,
|
|
31
|
+
prepared: "unnamed",
|
|
32
|
+
describe: false
|
|
33
|
+
};
|
|
34
|
+
var NEON_WEBSOCKET_CAPABILITIES = {
|
|
35
|
+
transactions: "interactive",
|
|
36
|
+
stream: false,
|
|
37
|
+
listen: false,
|
|
38
|
+
cancel: false,
|
|
39
|
+
prepared: "unnamed",
|
|
40
|
+
describe: false
|
|
41
|
+
};
|
|
42
|
+
var NEON_HTTP_CAPABILITIES = {
|
|
43
|
+
transactions: "batch",
|
|
44
|
+
stream: false,
|
|
45
|
+
listen: false,
|
|
46
|
+
cancel: false,
|
|
47
|
+
prepared: "none",
|
|
48
|
+
describe: false
|
|
49
|
+
};
|
|
50
|
+
function readCapability2(flags, name) {
|
|
51
|
+
return flags[name];
|
|
52
|
+
}
|
|
53
|
+
function hasCapability2(flags, name) {
|
|
54
|
+
return flags[name];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/adapters/failure.ts
|
|
58
|
+
var loading;
|
|
59
|
+
function driverErrors() {
|
|
60
|
+
loading ??= import("./aftb2mwr.js");
|
|
61
|
+
return loading;
|
|
62
|
+
}
|
|
63
|
+
function rejectClosed() {
|
|
64
|
+
return import("./345tbc2k.js").then((mod) => mod.closed());
|
|
65
|
+
}
|
|
66
|
+
function rejectUncancellable() {
|
|
67
|
+
return import("./345tbc2k.js").then((mod) => mod.refused());
|
|
68
|
+
}
|
|
69
|
+
function rejectCancelled() {
|
|
70
|
+
return driverErrors().then((mod) => Promise.reject(mod.cancelled()));
|
|
71
|
+
}
|
|
72
|
+
function rejectTimedOut() {
|
|
73
|
+
return driverErrors().then((mod) => Promise.reject(mod.timedOut()));
|
|
74
|
+
}
|
|
75
|
+
async function mapFailure(error) {
|
|
76
|
+
const mod = await driverErrors();
|
|
77
|
+
return mod.mapDriverError(error);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/adapters/pg/call.ts
|
|
81
|
+
function needsWatch(options) {
|
|
82
|
+
return options?.signal !== undefined || options?.timeout !== undefined;
|
|
83
|
+
}
|
|
84
|
+
function nextTransactionDepth(depth, text) {
|
|
85
|
+
const command = text.trim().replace(/;\s*$/, "").trim().toLowerCase();
|
|
86
|
+
if (/^(?:begin|start transaction)(?:\s|$)/.test(command))
|
|
87
|
+
return depth + 1;
|
|
88
|
+
if (command === "commit" || command === "commit work" || command === "end") {
|
|
89
|
+
return Math.max(0, depth - 1);
|
|
90
|
+
}
|
|
91
|
+
if (command === "rollback" || command === "rollback work")
|
|
92
|
+
return 0;
|
|
93
|
+
return depth;
|
|
94
|
+
}
|
|
95
|
+
function runCall(closed, options, fn) {
|
|
96
|
+
if (closed)
|
|
97
|
+
return rejectClosed();
|
|
98
|
+
if (options?.signal?.aborted === true)
|
|
99
|
+
return rejectCancelled();
|
|
100
|
+
if (options?.timeout !== undefined && options.timeout <= 0)
|
|
101
|
+
return rejectTimedOut();
|
|
102
|
+
if (options === undefined || !needsWatch(options))
|
|
103
|
+
return fn(undefined);
|
|
104
|
+
const watched = options;
|
|
105
|
+
return import("./54tqkxja.js").then(({ openWatch }) => {
|
|
106
|
+
const watch = openWatch(watched);
|
|
107
|
+
return fn(watch).finally(() => {
|
|
108
|
+
watch.finish();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/adapters/pg/result.ts
|
|
114
|
+
var EMPTY_NOTICES = [];
|
|
115
|
+
function cell(value) {
|
|
116
|
+
if (value === null || value === undefined)
|
|
117
|
+
return null;
|
|
118
|
+
if (typeof value === "string")
|
|
119
|
+
return value;
|
|
120
|
+
if (typeof value === "bigint")
|
|
121
|
+
return value.toString();
|
|
122
|
+
if (value instanceof Uint8Array)
|
|
123
|
+
return new TextDecoder().decode(value);
|
|
124
|
+
if (typeof value === "number" || typeof value === "boolean")
|
|
125
|
+
return String(value);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
function rowsFrom(value) {
|
|
129
|
+
const list = rowList(value);
|
|
130
|
+
const rows = Array.from({ length: list.length });
|
|
131
|
+
for (let index = 0;index < list.length; index += 1) {
|
|
132
|
+
rows[index] = rowCells(list[index]);
|
|
133
|
+
}
|
|
134
|
+
return rows;
|
|
135
|
+
}
|
|
136
|
+
function resultFrom(value, notices) {
|
|
137
|
+
const rows = rowsFrom(value);
|
|
138
|
+
return {
|
|
139
|
+
rows,
|
|
140
|
+
count: countFrom(value, rows.length),
|
|
141
|
+
notices
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function rowList(value) {
|
|
145
|
+
if (Array.isArray(value))
|
|
146
|
+
return value;
|
|
147
|
+
if (typeof value === "object" && value !== null && "rows" in value) {
|
|
148
|
+
const rows = Reflect.get(value, "rows");
|
|
149
|
+
if (Array.isArray(rows))
|
|
150
|
+
return rows;
|
|
151
|
+
}
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
function rowCells(row) {
|
|
155
|
+
if (Array.isArray(row)) {
|
|
156
|
+
const cells = Array.from({ length: row.length });
|
|
157
|
+
for (let index = 0;index < row.length; index += 1)
|
|
158
|
+
cells[index] = cell(row[index]);
|
|
159
|
+
return cells;
|
|
160
|
+
}
|
|
161
|
+
if (typeof row === "object" && row !== null) {
|
|
162
|
+
const values = Object.values(row);
|
|
163
|
+
const cells = Array.from({ length: values.length });
|
|
164
|
+
for (let index = 0;index < values.length; index += 1)
|
|
165
|
+
cells[index] = cell(values[index]);
|
|
166
|
+
return cells;
|
|
167
|
+
}
|
|
168
|
+
return [cell(row)];
|
|
169
|
+
}
|
|
170
|
+
function countFrom(value, rows) {
|
|
171
|
+
if (typeof value !== "object" || value === null)
|
|
172
|
+
return rows;
|
|
173
|
+
const count = Reflect.get(value, "count");
|
|
174
|
+
if (typeof count === "number" && !Number.isNaN(count))
|
|
175
|
+
return count;
|
|
176
|
+
const rowCount = Reflect.get(value, "rowCount");
|
|
177
|
+
if (typeof rowCount === "number" && !Number.isNaN(rowCount))
|
|
178
|
+
return rowCount;
|
|
179
|
+
const affected = Reflect.get(value, "affectedRows");
|
|
180
|
+
if (typeof affected === "number" && !Number.isNaN(affected))
|
|
181
|
+
return affected;
|
|
182
|
+
return rows;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export { POSTGRESJS_CAPABILITIES, PGLITE_CAPABILITIES, NODE_POSTGRES_CAPABILITIES, BUNSQL_CAPABILITIES, NEON_WEBSOCKET_CAPABILITIES, NEON_HTTP_CAPABILITIES, readCapability2, hasCapability2, driverErrors, rejectClosed, rejectUncancellable, rejectCancelled, rejectTimedOut, mapFailure, nextTransactionDepth, runCall, EMPTY_NOTICES, rowsFrom, resultFrom };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DriverError2
|
|
3
|
+
} from "./f9mphxej.js";
|
|
4
|
+
import {
|
|
5
|
+
noticeBuffer,
|
|
6
|
+
WireSession
|
|
7
|
+
} from "./yw30vnq2.js";
|
|
8
|
+
import {
|
|
9
|
+
noTimeout
|
|
10
|
+
} from "./rs1jb051.js";
|
|
11
|
+
import {
|
|
12
|
+
BUNSQL_CAPABILITIES,
|
|
13
|
+
driverErrors,
|
|
14
|
+
rejectClosed,
|
|
15
|
+
mapFailure,
|
|
16
|
+
runCall
|
|
17
|
+
} from "./xhrnjch9.js";
|
|
18
|
+
|
|
19
|
+
// src/adapters/pg/bunsql.ts
|
|
20
|
+
import { SQL as BunSQL } from "bun";
|
|
21
|
+
var clientPools = new WeakSet;
|
|
22
|
+
function markClientPool2(pool) {
|
|
23
|
+
clientPools.add(pool);
|
|
24
|
+
}
|
|
25
|
+
function open2(config) {
|
|
26
|
+
const max = config.max ?? 10;
|
|
27
|
+
const acquireMs = config.timeouts?.acquire;
|
|
28
|
+
const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
|
|
29
|
+
const notices = noticeBuffer();
|
|
30
|
+
let closed = false;
|
|
31
|
+
const isClosed = () => closed;
|
|
32
|
+
const named = config.prepared === "named";
|
|
33
|
+
const parked = [];
|
|
34
|
+
let dropped = 0;
|
|
35
|
+
let closures = 0;
|
|
36
|
+
const sql = new BunSQL(config.url, {
|
|
37
|
+
max,
|
|
38
|
+
idleTimeout: 0,
|
|
39
|
+
maxLifetime: 0,
|
|
40
|
+
prepare: named,
|
|
41
|
+
bigint: false,
|
|
42
|
+
connectionTimeout: 5,
|
|
43
|
+
connection: {
|
|
44
|
+
application_name: "okmodel",
|
|
45
|
+
...config.searchPath !== undefined ? { search_path: config.searchPath } : {}
|
|
46
|
+
},
|
|
47
|
+
...config.ssl !== undefined ? { tls: config.ssl } : {},
|
|
48
|
+
onclose() {
|
|
49
|
+
dropped += 1;
|
|
50
|
+
closures += 1;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const root = new WireSession((text, params) => send2(sql, text, params), notices, isClosed, false, () => {
|
|
54
|
+
counters.busy += 1;
|
|
55
|
+
}, () => {
|
|
56
|
+
counters.busy = Math.max(0, counters.busy - 1);
|
|
57
|
+
});
|
|
58
|
+
const held = {
|
|
59
|
+
sql,
|
|
60
|
+
parked,
|
|
61
|
+
acquireMs,
|
|
62
|
+
counters,
|
|
63
|
+
notices,
|
|
64
|
+
isClosed,
|
|
65
|
+
closures: () => closures
|
|
66
|
+
};
|
|
67
|
+
const run = (text, params, watch) => {
|
|
68
|
+
const sent = dropped;
|
|
69
|
+
return root.query(text, params, watch).catch((error) => import("./g9ad4n80.js").then((mod) => mod.recover(sql, error, text, root.depth(), clientPools.has(pool), dropped > sent, () => root.query(text, params, watch))));
|
|
70
|
+
};
|
|
71
|
+
const afterDrop = (text, params, watch) => {
|
|
72
|
+
if (dropped === 0)
|
|
73
|
+
return run(text, params, watch);
|
|
74
|
+
const seen = dropped;
|
|
75
|
+
return import("./g9ad4n80.js").then((mod) => mod.drainClosed(sql).then(() => {
|
|
76
|
+
if (dropped === seen)
|
|
77
|
+
dropped = 0;
|
|
78
|
+
return run(text, params, watch);
|
|
79
|
+
}));
|
|
80
|
+
};
|
|
81
|
+
const checkout = () => closed ? rejectClosed() : import("./g9ad4n80.js").then((mod) => mod.checkout(held));
|
|
82
|
+
const pool = {
|
|
83
|
+
capabilities: BUNSQL_CAPABILITIES,
|
|
84
|
+
execute(text, params, options) {
|
|
85
|
+
const refused = noTimeout(options);
|
|
86
|
+
if (refused !== undefined)
|
|
87
|
+
return refused;
|
|
88
|
+
return runCall(closed, options, (watch) => releaseParked(parked).then(() => afterDrop(text, params, watch)));
|
|
89
|
+
},
|
|
90
|
+
async batch(statements, options) {
|
|
91
|
+
const refused = noTimeout(options);
|
|
92
|
+
if (refused !== undefined)
|
|
93
|
+
return refused;
|
|
94
|
+
const connection = await checkout();
|
|
95
|
+
try {
|
|
96
|
+
return await connection.batch(statements, options);
|
|
97
|
+
} finally {
|
|
98
|
+
await connection.release();
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
reserve: () => checkout(),
|
|
102
|
+
stream(text, params) {
|
|
103
|
+
return async function* () {
|
|
104
|
+
const { streamRows } = await import("./g9ad4n80.js");
|
|
105
|
+
yield* streamRows(checkout, text, params);
|
|
106
|
+
}();
|
|
107
|
+
},
|
|
108
|
+
listen(channel, onNotify) {
|
|
109
|
+
return import("./g9ad4n80.js").then((mod) => mod.listen(sql, parked, closed, channel, onNotify));
|
|
110
|
+
},
|
|
111
|
+
stats: () => statsOf(counters, max),
|
|
112
|
+
async close() {
|
|
113
|
+
closed = true;
|
|
114
|
+
await releaseParked(parked);
|
|
115
|
+
await sql.close();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return pool;
|
|
119
|
+
}
|
|
120
|
+
function send2(sql, text, params) {
|
|
121
|
+
const refused = refuseInt8(params);
|
|
122
|
+
if (refused !== undefined)
|
|
123
|
+
return refused;
|
|
124
|
+
if (params === undefined || params.length === 0)
|
|
125
|
+
return sql.unsafe(text).raw();
|
|
126
|
+
return sql.unsafe(text, [...params]).raw();
|
|
127
|
+
}
|
|
128
|
+
function refuseInt8(params) {
|
|
129
|
+
if (params === undefined)
|
|
130
|
+
return;
|
|
131
|
+
for (const value of params) {
|
|
132
|
+
if (value === null || value.length < 19 || !/^-?(?:0|[1-9]\d*)$/.test(value))
|
|
133
|
+
continue;
|
|
134
|
+
const parsed = BigInt(value);
|
|
135
|
+
if (parsed > 9223372036854775807n || parsed < -9223372036854775808n) {
|
|
136
|
+
return Promise.reject(new DriverError2("bigint out of range", { sqlstate: "22003" }));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
async function reserve2(sql, acquireMs, counters) {
|
|
142
|
+
counters.waiting += 1;
|
|
143
|
+
try {
|
|
144
|
+
if (acquireMs === undefined)
|
|
145
|
+
return await sql.reserve();
|
|
146
|
+
return await sql.reserve({ signal: AbortSignal.timeout(acquireMs) });
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (isAbort(error)) {
|
|
149
|
+
const errors = await driverErrors();
|
|
150
|
+
throw errors.acquireTimeout();
|
|
151
|
+
}
|
|
152
|
+
throw await mapFailure(error);
|
|
153
|
+
} finally {
|
|
154
|
+
counters.waiting = Math.max(0, counters.waiting - 1);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
async function park2(parked, reserved) {
|
|
158
|
+
parked.push(reserved);
|
|
159
|
+
while (parked.length > 1) {
|
|
160
|
+
const extra = parked.shift();
|
|
161
|
+
if (extra !== undefined)
|
|
162
|
+
await releaseReserved(extra);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function releaseParked(parked) {
|
|
166
|
+
const pending = parked.splice(0);
|
|
167
|
+
for (const reserved of pending)
|
|
168
|
+
await releaseReserved(reserved);
|
|
169
|
+
}
|
|
170
|
+
function releaseReserved(reserved) {
|
|
171
|
+
const done = reserved.release();
|
|
172
|
+
return done instanceof Promise ? done.then(() => {
|
|
173
|
+
return;
|
|
174
|
+
}) : Promise.resolve();
|
|
175
|
+
}
|
|
176
|
+
function isAbort(error) {
|
|
177
|
+
if (!(error instanceof Error))
|
|
178
|
+
return false;
|
|
179
|
+
return error.name === "AbortError" || error.name === "TimeoutError";
|
|
180
|
+
}
|
|
181
|
+
function statsOf(counters, size) {
|
|
182
|
+
return {
|
|
183
|
+
size,
|
|
184
|
+
idle: Math.max(0, size - counters.reserved - counters.busy),
|
|
185
|
+
inflight: counters.busy + counters.reservedBusy,
|
|
186
|
+
waiting: counters.waiting
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { markClientPool2, open2, send2, reserve2, park2 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
open3,
|
|
3
|
+
PgSession2
|
|
4
|
+
} from "./p7f08ktn.js";
|
|
5
|
+
import {
|
|
6
|
+
POSTGRESJS_CAPABILITIES,
|
|
7
|
+
readCapability2,
|
|
8
|
+
hasCapability2
|
|
9
|
+
} from "./xhrnjch9.js";
|
|
10
|
+
export {
|
|
11
|
+
PgSession2 as PgSession,
|
|
12
|
+
POSTGRESJS_CAPABILITIES as capabilities,
|
|
13
|
+
hasCapability2 as hasCapability,
|
|
14
|
+
open3 as open,
|
|
15
|
+
readCapability2 as readCapability
|
|
16
|
+
};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import {
|
|
2
|
+
outcomeUnknown2
|
|
3
|
+
} from "./f9mphxej.js";
|
|
4
|
+
import {
|
|
5
|
+
noticeBuffer,
|
|
6
|
+
WireSession
|
|
7
|
+
} from "./yw30vnq2.js";
|
|
8
|
+
import {
|
|
9
|
+
noTimeout
|
|
10
|
+
} from "./rs1jb051.js";
|
|
11
|
+
import {
|
|
12
|
+
NEON_WEBSOCKET_CAPABILITIES,
|
|
13
|
+
NEON_HTTP_CAPABILITIES,
|
|
14
|
+
driverErrors,
|
|
15
|
+
rejectClosed,
|
|
16
|
+
mapFailure,
|
|
17
|
+
runCall,
|
|
18
|
+
EMPTY_NOTICES,
|
|
19
|
+
resultFrom
|
|
20
|
+
} from "./xhrnjch9.js";
|
|
21
|
+
|
|
22
|
+
// src/adapters/pg/neon.ts
|
|
23
|
+
import {
|
|
24
|
+
Pool,
|
|
25
|
+
neon,
|
|
26
|
+
neonConfig
|
|
27
|
+
} from "@neondatabase/serverless";
|
|
28
|
+
var CONNECT_MS = 30000;
|
|
29
|
+
var WIRE = {
|
|
30
|
+
getTypeParser() {
|
|
31
|
+
return (value) => value;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var names = new Map;
|
|
35
|
+
async function open5(config) {
|
|
36
|
+
if (config.mode === "http")
|
|
37
|
+
return openHttp(config);
|
|
38
|
+
return openWebSocket(config);
|
|
39
|
+
}
|
|
40
|
+
function connectClient3(pool, acquireMs, counters) {
|
|
41
|
+
counters.waiting += 1;
|
|
42
|
+
let settled = false;
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
let timer;
|
|
45
|
+
if (acquireMs !== undefined) {
|
|
46
|
+
timer = setTimeout(() => {
|
|
47
|
+
settled = true;
|
|
48
|
+
counters.waiting = Math.max(0, counters.waiting - 1);
|
|
49
|
+
driverErrors().then((errors) => {
|
|
50
|
+
reject(errors.acquireTimeout());
|
|
51
|
+
});
|
|
52
|
+
}, acquireMs);
|
|
53
|
+
}
|
|
54
|
+
take(pool).then((client) => {
|
|
55
|
+
if (settled) {
|
|
56
|
+
client.release();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (timer !== undefined)
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
counters.waiting = Math.max(0, counters.waiting - 1);
|
|
62
|
+
resolve(client);
|
|
63
|
+
}, (error) => {
|
|
64
|
+
if (settled)
|
|
65
|
+
return;
|
|
66
|
+
if (timer !== undefined)
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
counters.waiting = Math.max(0, counters.waiting - 1);
|
|
69
|
+
mapFailure(error).then(reject);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function send4(runner, text, params, named) {
|
|
74
|
+
const query = {
|
|
75
|
+
text,
|
|
76
|
+
rowMode: "array",
|
|
77
|
+
types: WIRE,
|
|
78
|
+
...params !== undefined && params.length > 0 ? { values: params } : {},
|
|
79
|
+
...named ? { name: statementName(text) } : {}
|
|
80
|
+
};
|
|
81
|
+
return runner.query(query);
|
|
82
|
+
}
|
|
83
|
+
async function openWebSocket(config) {
|
|
84
|
+
ensureWebSocket();
|
|
85
|
+
const max = config.max ?? 10;
|
|
86
|
+
const acquireMs = config.timeouts?.acquire;
|
|
87
|
+
const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
|
|
88
|
+
const notices = noticeBuffer();
|
|
89
|
+
let closed = false;
|
|
90
|
+
const isClosed = () => closed;
|
|
91
|
+
const named = config.prepared === "named";
|
|
92
|
+
const pool = new Pool({
|
|
93
|
+
connectionString: config.url,
|
|
94
|
+
max,
|
|
95
|
+
idleTimeoutMillis: 0,
|
|
96
|
+
allowExitOnIdle: true,
|
|
97
|
+
connectionTimeoutMillis: CONNECT_MS,
|
|
98
|
+
application_name: "okmodel",
|
|
99
|
+
types: WIRE,
|
|
100
|
+
...config.searchPath !== undefined ? { options: `-c search_path=${config.searchPath}` } : {}
|
|
101
|
+
});
|
|
102
|
+
pool.on("error", () => {
|
|
103
|
+
return;
|
|
104
|
+
});
|
|
105
|
+
try {
|
|
106
|
+
const warmed = await take(pool);
|
|
107
|
+
warmed.release();
|
|
108
|
+
} catch (error) {
|
|
109
|
+
await pool.end().catch(() => {
|
|
110
|
+
return;
|
|
111
|
+
});
|
|
112
|
+
throw await mapFailure(error);
|
|
113
|
+
}
|
|
114
|
+
const root = new WireSession((text, params) => send4(pool, text, params, named), notices, isClosed, false, () => {
|
|
115
|
+
counters.busy += 1;
|
|
116
|
+
}, () => {
|
|
117
|
+
counters.busy = Math.max(0, counters.busy - 1);
|
|
118
|
+
});
|
|
119
|
+
const held = { pool, acquireMs, counters, notices, named, isClosed };
|
|
120
|
+
const checkout = () => closed ? rejectClosed() : import("./gfvtj6d0.js").then((mod) => mod.checkout(held));
|
|
121
|
+
return {
|
|
122
|
+
capabilities: NEON_WEBSOCKET_CAPABILITIES,
|
|
123
|
+
execute(text, params, options) {
|
|
124
|
+
const refused = noTimeout(options);
|
|
125
|
+
if (refused !== undefined)
|
|
126
|
+
return refused;
|
|
127
|
+
return runCall(closed, options, (watch) => root.query(text, params, watch));
|
|
128
|
+
},
|
|
129
|
+
async batch(statements, options) {
|
|
130
|
+
const refused = noTimeout(options);
|
|
131
|
+
if (refused !== undefined)
|
|
132
|
+
return refused;
|
|
133
|
+
const connection = await checkout();
|
|
134
|
+
try {
|
|
135
|
+
return await connection.batch(statements, options);
|
|
136
|
+
} finally {
|
|
137
|
+
await connection.release();
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
reserve: () => checkout(),
|
|
141
|
+
stats: () => statsOf(counters, max),
|
|
142
|
+
async close() {
|
|
143
|
+
closed = true;
|
|
144
|
+
await pool.end();
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function openHttp(config) {
|
|
149
|
+
const max = config.max ?? 10;
|
|
150
|
+
const counters = { reserved: 0, busy: 0, reservedBusy: 0, waiting: 0 };
|
|
151
|
+
let closed = false;
|
|
152
|
+
const sql = neon(config.url, { arrayMode: true, fullResults: true });
|
|
153
|
+
const run = async (text, params) => {
|
|
154
|
+
counters.busy += 1;
|
|
155
|
+
try {
|
|
156
|
+
const result = await sql.query(text, params === undefined ? [] : [...params]);
|
|
157
|
+
return resultFrom(result, EMPTY_NOTICES);
|
|
158
|
+
} finally {
|
|
159
|
+
counters.busy = Math.max(0, counters.busy - 1);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
capabilities: NEON_HTTP_CAPABILITIES,
|
|
164
|
+
execute(text, params, options) {
|
|
165
|
+
const refused = noTimeout(options);
|
|
166
|
+
if (refused !== undefined)
|
|
167
|
+
return refused;
|
|
168
|
+
if (closed)
|
|
169
|
+
return rejectClosed();
|
|
170
|
+
return runCall(closed, options, () => run(text, params).catch((error) => mapFailure(error).then((mapped) => Promise.reject(mapped))));
|
|
171
|
+
},
|
|
172
|
+
async batch(statements, options) {
|
|
173
|
+
const refused = noTimeout(options);
|
|
174
|
+
if (refused !== undefined)
|
|
175
|
+
return refused;
|
|
176
|
+
if (closed)
|
|
177
|
+
return rejectClosed();
|
|
178
|
+
counters.busy += 1;
|
|
179
|
+
try {
|
|
180
|
+
const queries = statements.map((statement) => sql.query(statement.text, statement.params === undefined ? [] : [...statement.params]));
|
|
181
|
+
const results = await sql.transaction(queries, httpOptions());
|
|
182
|
+
return results.map((result) => resultFrom(result, EMPTY_NOTICES));
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (!isDatabaseError(error))
|
|
185
|
+
throw outcomeUnknown2(error);
|
|
186
|
+
throw await mapFailure(error);
|
|
187
|
+
} finally {
|
|
188
|
+
counters.busy = Math.max(0, counters.busy - 1);
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
stats: () => statsOf(counters, max),
|
|
192
|
+
close() {
|
|
193
|
+
closed = true;
|
|
194
|
+
return Promise.resolve();
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function httpOptions() {
|
|
199
|
+
return { arrayMode: true, fullResults: true };
|
|
200
|
+
}
|
|
201
|
+
function isDatabaseError(error) {
|
|
202
|
+
if (typeof error !== "object" || error === null)
|
|
203
|
+
return false;
|
|
204
|
+
const code = Reflect.get(error, "code");
|
|
205
|
+
return typeof code === "string" && /^[0-9A-Z]{5}$/.test(code);
|
|
206
|
+
}
|
|
207
|
+
function take(pool) {
|
|
208
|
+
const connect = pool.connect.bind(pool);
|
|
209
|
+
return connect();
|
|
210
|
+
}
|
|
211
|
+
function ensureWebSocket() {
|
|
212
|
+
if (neonConfig.webSocketConstructor === undefined && typeof WebSocket === "function") {
|
|
213
|
+
neonConfig.webSocketConstructor = WebSocket;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function statementName(text) {
|
|
217
|
+
const existing = names.get(text);
|
|
218
|
+
if (existing !== undefined)
|
|
219
|
+
return existing;
|
|
220
|
+
const name = `okm_${String(names.size)}`;
|
|
221
|
+
names.set(text, name);
|
|
222
|
+
return name;
|
|
223
|
+
}
|
|
224
|
+
function statsOf(counters, size) {
|
|
225
|
+
return {
|
|
226
|
+
size,
|
|
227
|
+
idle: Math.max(0, size - counters.reserved - counters.busy),
|
|
228
|
+
inflight: counters.busy + counters.reservedBusy,
|
|
229
|
+
waiting: counters.waiting
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export { open5, connectClient3, send4 };
|