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,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
open4
|
|
3
|
+
} from "./417zdsk7.js";
|
|
4
|
+
import {
|
|
5
|
+
createClient
|
|
6
|
+
} from "./mtrqn2hn.js";
|
|
7
|
+
|
|
8
|
+
// src/runtime/pg/pg.ts
|
|
9
|
+
function connect(target, options) {
|
|
10
|
+
if (typeof target === "object" && !isPool(target)) {
|
|
11
|
+
return import("./2wtvc7rw.js").then((mod) => mod.default(target, options, open4));
|
|
12
|
+
}
|
|
13
|
+
const owned = !isPool(target);
|
|
14
|
+
const pool = isPool(target) ? target : open4({
|
|
15
|
+
url: target,
|
|
16
|
+
...options.max !== undefined ? { max: options.max } : {},
|
|
17
|
+
...options.timeouts !== undefined ? { timeouts: options.timeouts } : {},
|
|
18
|
+
...options.prepared !== undefined ? { prepared: options.prepared } : {},
|
|
19
|
+
...options.searchPath !== undefined ? { searchPath: options.searchPath } : {},
|
|
20
|
+
...options.ssl !== undefined ? { ssl: options.ssl } : {}
|
|
21
|
+
});
|
|
22
|
+
return createClient(options.schema, pool, {
|
|
23
|
+
ownsPool: owned,
|
|
24
|
+
http: options.errors?.http,
|
|
25
|
+
includeValues: options.errors?.includeValues,
|
|
26
|
+
logger: options.logger,
|
|
27
|
+
signal: options.signal,
|
|
28
|
+
timeout: options.timeout,
|
|
29
|
+
timeouts: options.timeouts,
|
|
30
|
+
hookm: options.hookm,
|
|
31
|
+
catalog: options.catalog,
|
|
32
|
+
catalogDir: options.catalogDir,
|
|
33
|
+
requireMeta: options.requireMeta,
|
|
34
|
+
generators: options.generators
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function isPool(target) {
|
|
38
|
+
return typeof target === "object" && "execute" in target && "capabilities" in target;
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
connect
|
|
42
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
stack2
|
|
3
|
+
} from "./cmptmb4f.js";
|
|
4
|
+
import {
|
|
5
|
+
OkmError,
|
|
6
|
+
isOperator,
|
|
7
|
+
operatorValue
|
|
8
|
+
} from "./f9mphxej.js";
|
|
9
|
+
|
|
10
|
+
// src/dialects/pg/preset.ts
|
|
11
|
+
var RESERVED_PRESETS = new Set([
|
|
12
|
+
"find",
|
|
13
|
+
"one",
|
|
14
|
+
"page",
|
|
15
|
+
"aggregate",
|
|
16
|
+
"count",
|
|
17
|
+
"exists",
|
|
18
|
+
"insert",
|
|
19
|
+
"update",
|
|
20
|
+
"delete",
|
|
21
|
+
"descendants",
|
|
22
|
+
"ancestors",
|
|
23
|
+
"sync",
|
|
24
|
+
"archive",
|
|
25
|
+
"restore",
|
|
26
|
+
"withArchived",
|
|
27
|
+
"onlyArchived",
|
|
28
|
+
"then",
|
|
29
|
+
"lock",
|
|
30
|
+
"watch",
|
|
31
|
+
"subscribe",
|
|
32
|
+
"stream",
|
|
33
|
+
"inspect",
|
|
34
|
+
"explain",
|
|
35
|
+
"with",
|
|
36
|
+
"for",
|
|
37
|
+
"as"
|
|
38
|
+
]);
|
|
39
|
+
function checkPresetNames(names, where) {
|
|
40
|
+
for (const name of names) {
|
|
41
|
+
if (!RESERVED_PRESETS.has(name))
|
|
42
|
+
continue;
|
|
43
|
+
throw new OkmError("OKM1040", `Preset ${name} on ${where} is a client method or a reserved name. Reserved: ${[...RESERVED_PRESETS].join(", ")}.`, { fix: { summary: `Rename the preset ${name}.` } });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/runtime/presets.ts
|
|
48
|
+
function checkSchema(schema) {
|
|
49
|
+
for (const name in schema.model) {
|
|
50
|
+
const presets = schema.model[name]?.presets;
|
|
51
|
+
if (presets !== undefined)
|
|
52
|
+
checkPresetNames(Object.keys(presets), `table ${name}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function resolve(schema, table, uses) {
|
|
56
|
+
const model = schema.model[table];
|
|
57
|
+
const known = model?.presets ?? {};
|
|
58
|
+
const chain = [];
|
|
59
|
+
for (let use = uses;use !== undefined; use = use[0])
|
|
60
|
+
chain.unshift(use);
|
|
61
|
+
const wheres = [];
|
|
62
|
+
const rules = [];
|
|
63
|
+
for (const [, name, args] of chain) {
|
|
64
|
+
const preset = known[name];
|
|
65
|
+
if (typeof preset !== "function") {
|
|
66
|
+
throw new OkmError("OKM1120", `Table ${table} has no preset ${name}.`, {
|
|
67
|
+
fix: { summary: `Use one of: ${Object.keys(known).join(", ")}.` }
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const added = [];
|
|
71
|
+
const q = {
|
|
72
|
+
where(filter) {
|
|
73
|
+
added.push(filter);
|
|
74
|
+
return q;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (preset(q, ...args) !== q) {
|
|
78
|
+
throw new OkmError("OKM1121", `Preset ${name} on ${table} must return the builder it was given.`, { fix: { summary: "Return q, as in (q) => q.where({ ... })." } });
|
|
79
|
+
}
|
|
80
|
+
for (const filter of added)
|
|
81
|
+
wheres.push(filter);
|
|
82
|
+
rules.push({
|
|
83
|
+
rule: "preset",
|
|
84
|
+
contribution: `${name} filters ${[...new Set(added.flatMap(fieldsOf))].join(", ") || "nothing"}`,
|
|
85
|
+
provenance: ownerOf(model, name, table),
|
|
86
|
+
...model?.source !== undefined ? { source: model.source } : {}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return { wheres, rules };
|
|
90
|
+
}
|
|
91
|
+
function refine(schema, call, uses) {
|
|
92
|
+
const { wheres, rules } = resolve(schema, call.table, uses);
|
|
93
|
+
return {
|
|
94
|
+
...call,
|
|
95
|
+
where: stack2(call.where, wheres),
|
|
96
|
+
ruleLines: [...call.ruleLines ?? [], ...rules]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function ownerOf(model, name, table) {
|
|
100
|
+
for (const trait of model?.traits ?? []) {
|
|
101
|
+
const presets = trait.presets;
|
|
102
|
+
if (presets !== undefined && Object.hasOwn(presets, name))
|
|
103
|
+
return `trait ${trait.name}`;
|
|
104
|
+
}
|
|
105
|
+
return `table ${table}`;
|
|
106
|
+
}
|
|
107
|
+
function fieldsOf(filter) {
|
|
108
|
+
if (isOperator(filter)) {
|
|
109
|
+
const branches = operatorValue(filter);
|
|
110
|
+
return Array.isArray(branches) ? branches.flatMap(fieldsOf) : [];
|
|
111
|
+
}
|
|
112
|
+
return typeof filter === "object" && filter !== null ? Object.keys(filter) : [];
|
|
113
|
+
}
|
|
114
|
+
export {
|
|
115
|
+
checkSchema,
|
|
116
|
+
refine,
|
|
117
|
+
resolve
|
|
118
|
+
};
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OkmError,
|
|
3
|
+
safe,
|
|
4
|
+
throwNamed,
|
|
5
|
+
archiveRules,
|
|
6
|
+
readOptionNames,
|
|
7
|
+
readNeedsOperatorSql,
|
|
8
|
+
bindCall,
|
|
9
|
+
compileCall,
|
|
10
|
+
decodeResult,
|
|
11
|
+
logicalIntent,
|
|
12
|
+
appliedRules,
|
|
13
|
+
rejectKeys
|
|
14
|
+
} from "./f9mphxej.js";
|
|
15
|
+
|
|
16
|
+
// src/runtime/client.ts
|
|
17
|
+
var PLAN_LIMIT = 64;
|
|
18
|
+
var SINGLE_ENDPOINT = {
|
|
19
|
+
endpoint: "primary",
|
|
20
|
+
role: "primary",
|
|
21
|
+
reason: "single-endpoint"
|
|
22
|
+
};
|
|
23
|
+
function createClient(schema, pool, options) {
|
|
24
|
+
const closing = {
|
|
25
|
+
current: undefined,
|
|
26
|
+
early: false
|
|
27
|
+
};
|
|
28
|
+
const checked = checkServer(pool, schema, options.http, options.requireMeta === true, callOptions(options), {
|
|
29
|
+
...options.catalog !== undefined ? { catalog: options.catalog } : {},
|
|
30
|
+
...options.catalogDir !== undefined ? { catalogDir: options.catalogDir } : {}
|
|
31
|
+
});
|
|
32
|
+
const connected = checked.catch((error) => {
|
|
33
|
+
if (!closing.early)
|
|
34
|
+
throw error;
|
|
35
|
+
throw new OkmError("unavailable", "The client was closed before it connected. Await connected before close(), or do not close it before use.", { kind: "unavailable", fix: { summary: "Await client.connected before calling close()." } });
|
|
36
|
+
});
|
|
37
|
+
connected.catch(() => {
|
|
38
|
+
return;
|
|
39
|
+
});
|
|
40
|
+
const session = {
|
|
41
|
+
schema,
|
|
42
|
+
pool,
|
|
43
|
+
ownsPool: options.ownsPool,
|
|
44
|
+
http: options.http,
|
|
45
|
+
includeValues: options.includeValues === true,
|
|
46
|
+
logger: options.logger,
|
|
47
|
+
connected,
|
|
48
|
+
cache: new Map,
|
|
49
|
+
generators: options.generators,
|
|
50
|
+
timeouts: options.timeouts,
|
|
51
|
+
hookm: options.hookm,
|
|
52
|
+
closing
|
|
53
|
+
};
|
|
54
|
+
return openClient(session);
|
|
55
|
+
}
|
|
56
|
+
function openClient(session) {
|
|
57
|
+
const names = Object.keys(session.schema.model);
|
|
58
|
+
const tables = {};
|
|
59
|
+
for (const name of names)
|
|
60
|
+
tables[name] = tableApi(session, name);
|
|
61
|
+
const close = () => {
|
|
62
|
+
if (!session.ownsPool)
|
|
63
|
+
return Promise.resolve();
|
|
64
|
+
session.closing.early = true;
|
|
65
|
+
session.closing.current ??= session.pool.close();
|
|
66
|
+
return session.closing.current;
|
|
67
|
+
};
|
|
68
|
+
const client = {
|
|
69
|
+
...tables,
|
|
70
|
+
table(name) {
|
|
71
|
+
const found = tables[name];
|
|
72
|
+
if (found !== undefined)
|
|
73
|
+
return found;
|
|
74
|
+
try {
|
|
75
|
+
if (session.schema.model[name] !== undefined && session.schema.tenancy !== undefined && session.scope === undefined) {
|
|
76
|
+
session.schema.tenancy.missing(name);
|
|
77
|
+
}
|
|
78
|
+
throwNamed("OKM1120", name, names, `Table ${name} is not in the schema. Accepted names: ${names.join(", ")}.`);
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error instanceof OkmError)
|
|
81
|
+
throw attachHttp(session.http, error);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
close,
|
|
86
|
+
connected: session.connected,
|
|
87
|
+
tx: (...args) => import("./rq5kk8j6.js").then((mod) => mod.tx(session, args)),
|
|
88
|
+
batch: (ops, options) => batchHandle(session, ops, options),
|
|
89
|
+
...session.tx?.extras
|
|
90
|
+
};
|
|
91
|
+
const hooks = session.schema.hooks;
|
|
92
|
+
if (hooks !== undefined) {
|
|
93
|
+
for (const hook of hooks) {
|
|
94
|
+
hook(client, {
|
|
95
|
+
names,
|
|
96
|
+
tables,
|
|
97
|
+
scoped: session.scope !== undefined,
|
|
98
|
+
open: (scope) => openClient({ ...session, scope })
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
attachAsyncDispose(client, close);
|
|
103
|
+
return client;
|
|
104
|
+
}
|
|
105
|
+
function attachAsyncDispose(client, close) {
|
|
106
|
+
const symbol = Symbol.asyncDispose;
|
|
107
|
+
if (typeof symbol !== "symbol")
|
|
108
|
+
return;
|
|
109
|
+
Object.defineProperty(client, symbol, {
|
|
110
|
+
configurable: true,
|
|
111
|
+
enumerable: false,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: () => close()
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function tableApi(session, table, view, uses) {
|
|
117
|
+
const base = { uses };
|
|
118
|
+
const mods = { archive: view, uses };
|
|
119
|
+
const api = {
|
|
120
|
+
find(options = {}) {
|
|
121
|
+
if ("lock" in options) {
|
|
122
|
+
return lazyRead(session, () => import("./vs0t6qt8.js"), table, options, base, view);
|
|
123
|
+
}
|
|
124
|
+
return start(session, "find", table, options, base, view);
|
|
125
|
+
},
|
|
126
|
+
one(options = {}) {
|
|
127
|
+
return start(session, "one", table, options, base, view);
|
|
128
|
+
},
|
|
129
|
+
count(options = {}) {
|
|
130
|
+
return start(session, "count", table, options, base, view);
|
|
131
|
+
},
|
|
132
|
+
exists(options = {}) {
|
|
133
|
+
return start(session, "exists", table, options, base, view);
|
|
134
|
+
},
|
|
135
|
+
page(options) {
|
|
136
|
+
return lazyRead(session, () => import("./j9t5s12a.js"), table, options, base, view);
|
|
137
|
+
},
|
|
138
|
+
aggregate(options = {}) {
|
|
139
|
+
return lazyRead(session, () => import("./bz2dqhab.js"), table, options, base, view);
|
|
140
|
+
},
|
|
141
|
+
insert(data, options = {}) {
|
|
142
|
+
return writeHandle(session, "insert", table, data, options, mods);
|
|
143
|
+
},
|
|
144
|
+
update(target, options = {}) {
|
|
145
|
+
return writeHandle(session, "update", table, target, options, mods);
|
|
146
|
+
},
|
|
147
|
+
delete(target, options = {}) {
|
|
148
|
+
return writeHandle(session, "delete", table, target, options, mods);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
for (const walk of ["descendants", "ancestors"]) {
|
|
152
|
+
api[walk] = (id, options) => lazyRead(session, () => import("./dw08f3m8.js"), table, { id, walk, options }, base, view);
|
|
153
|
+
}
|
|
154
|
+
api.sync = (id, relation, ids, options) => lazyRead(session, () => import("./z8d7ptht.js"), table, { id, relation, ids, options }, base, view, true);
|
|
155
|
+
const hooks = session.schema.hooks;
|
|
156
|
+
if (hooks !== undefined) {
|
|
157
|
+
for (const hook of hooks) {
|
|
158
|
+
hook(api, {
|
|
159
|
+
table,
|
|
160
|
+
...view !== undefined ? { view } : {},
|
|
161
|
+
uses,
|
|
162
|
+
reopen: (next) => tableApi(session, table, next, uses),
|
|
163
|
+
session
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for (const name in session.schema.model[table]?.presets) {
|
|
168
|
+
api[name] = (...args) => tableApi(session, table, view, [uses, name, args]);
|
|
169
|
+
}
|
|
170
|
+
api[Symbol.for("okm.lane")] = [session, table, mapError];
|
|
171
|
+
return api;
|
|
172
|
+
}
|
|
173
|
+
function batchHandle(session, ops, options, replica) {
|
|
174
|
+
return queryHandle(() => import("./vx86qjv8.js").then((mod) => mod.batch(session, ops, options, replica)), {
|
|
175
|
+
replica: () => batchHandle(session, ops, options, true)
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
var writers;
|
|
179
|
+
function loadWrite() {
|
|
180
|
+
writers ??= import("./733a1tq3.js");
|
|
181
|
+
return writers;
|
|
182
|
+
}
|
|
183
|
+
function queryHandle(run, extra) {
|
|
184
|
+
let pending;
|
|
185
|
+
const once = () => {
|
|
186
|
+
pending ??= run();
|
|
187
|
+
return pending;
|
|
188
|
+
};
|
|
189
|
+
const self = {
|
|
190
|
+
then(onFulfilled, onRejected) {
|
|
191
|
+
return once().then(onFulfilled, onRejected);
|
|
192
|
+
},
|
|
193
|
+
catch(onRejected) {
|
|
194
|
+
return self.then(undefined, onRejected);
|
|
195
|
+
},
|
|
196
|
+
finally(fn) {
|
|
197
|
+
return self.then((value) => {
|
|
198
|
+
fn();
|
|
199
|
+
return value;
|
|
200
|
+
}, (error) => {
|
|
201
|
+
fn();
|
|
202
|
+
throw error;
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
safe() {
|
|
206
|
+
return safe(once());
|
|
207
|
+
},
|
|
208
|
+
...extra
|
|
209
|
+
};
|
|
210
|
+
return self;
|
|
211
|
+
}
|
|
212
|
+
function writeHandle(session, op, table, input, options, mods) {
|
|
213
|
+
return queryHandle(() => runWrite(session, op, table, input, options, mods), {
|
|
214
|
+
"~plan": () => runWrite(session, op, table, input, options, mods, true),
|
|
215
|
+
sql() {
|
|
216
|
+
return loadWrite().then((mod) => mod.explainWrite(session.schema, op, table, input, options, mods, session.generators, session.scope));
|
|
217
|
+
},
|
|
218
|
+
expect(count) {
|
|
219
|
+
return writeHandle(session, op, table, input, options, { ...mods, expect: count });
|
|
220
|
+
},
|
|
221
|
+
all(reason) {
|
|
222
|
+
return writeHandle(session, op, table, input, options, { ...mods, all: reason });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
async function runWrite(session, op, table, input, options, mods, plan) {
|
|
227
|
+
await session.connected;
|
|
228
|
+
const mod = await loadWrite();
|
|
229
|
+
try {
|
|
230
|
+
return await mod.executeWrite(session, op, table, input, options, mods, session.scope, plan);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
throw logged(session, await mapError(session, error));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
function rejectedRead(error) {
|
|
236
|
+
const fail = () => Promise.reject(error);
|
|
237
|
+
return queryHandle(fail, {
|
|
238
|
+
all: () => rejectedRead(error),
|
|
239
|
+
required: () => rejectedRead(error),
|
|
240
|
+
inspect: fail,
|
|
241
|
+
sql: fail,
|
|
242
|
+
stream() {
|
|
243
|
+
return {
|
|
244
|
+
[Symbol.asyncIterator]() {
|
|
245
|
+
return { next: fail };
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
function start(session, op, table, options, mods, view) {
|
|
252
|
+
const model = session.schema.model[table];
|
|
253
|
+
let call;
|
|
254
|
+
try {
|
|
255
|
+
call = readCall(op, table, options, mods.all, session.scope, model, session.schema, view);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
return rejectedRead(error instanceof OkmError ? attachHttp(session.http, error) : error);
|
|
258
|
+
}
|
|
259
|
+
return readHandle(session, table, call, mods, async (plan, rows) => {
|
|
260
|
+
const value = await decodeRows(plan, rows, table);
|
|
261
|
+
if (mods.required === true && value === null) {
|
|
262
|
+
throw new OkmError("not_found", `one() on ${table} matched no row.`, withHttp(session.http, { kind: "not_found", table }));
|
|
263
|
+
}
|
|
264
|
+
return value;
|
|
265
|
+
}, () => ({
|
|
266
|
+
all(reason) {
|
|
267
|
+
return start(session, op, table, options, { ...mods, all: reason }, view);
|
|
268
|
+
},
|
|
269
|
+
required() {
|
|
270
|
+
return start(session, op, table, options, { ...mods, required: true }, view);
|
|
271
|
+
},
|
|
272
|
+
stream(batch) {
|
|
273
|
+
return streamLazy(session, call, mods, view, batch);
|
|
274
|
+
}
|
|
275
|
+
}));
|
|
276
|
+
}
|
|
277
|
+
function lazyRead(session, load, table, options, mods, view, sync) {
|
|
278
|
+
const read = () => load().then((mod) => ({ it: mod.build(session, table, options, mods, view) }));
|
|
279
|
+
const sql = () => read().then((box) => box.it.sql());
|
|
280
|
+
const extra = { sql };
|
|
281
|
+
if (sync) {
|
|
282
|
+
extra.expect = (count) => lazyRead(session, load, table, options, { ...mods, expect: count }, view, true);
|
|
283
|
+
} else {
|
|
284
|
+
extra.inspect = () => read().then((box) => box.it.inspect());
|
|
285
|
+
extra.all = (reason) => lazyRead(session, load, table, options, { ...mods, all: reason }, view);
|
|
286
|
+
}
|
|
287
|
+
return queryHandle(() => read().then((box) => box.it), extra);
|
|
288
|
+
}
|
|
289
|
+
async function decodeRows(plan, rows, table) {
|
|
290
|
+
return plan.outputs.includes.length === 0 ? decodeResult(plan, rows, table) : (await import("./yfr8hzhm.js")).decodeIncluded(plan, rows, table);
|
|
291
|
+
}
|
|
292
|
+
function readHandle(session, table, call, mods, decode, extra) {
|
|
293
|
+
let prepared;
|
|
294
|
+
const origin = call;
|
|
295
|
+
const searched = "search" in call;
|
|
296
|
+
const prepare = async () => {
|
|
297
|
+
if (prepared !== undefined)
|
|
298
|
+
return prepared;
|
|
299
|
+
if (mods.uses !== undefined) {
|
|
300
|
+
call = (await import("./ma2340rx.js")).refine(session.schema, origin, mods.uses);
|
|
301
|
+
}
|
|
302
|
+
if (searched) {
|
|
303
|
+
call = (await import("./smn6kz1p.js")).applyTextSearch(session.schema, call);
|
|
304
|
+
}
|
|
305
|
+
const hooks = await hooksFor(call);
|
|
306
|
+
if (readNeedsOperatorSql(session.schema, call) || hooks?.needsOperator(session.schema, call)) {
|
|
307
|
+
await loadOperatorSql();
|
|
308
|
+
}
|
|
309
|
+
if (call.build === undefined && selectHasWindow(call.select)) {
|
|
310
|
+
call = (await import("./pqy21k24.js")).attach(session.schema, call);
|
|
311
|
+
}
|
|
312
|
+
const bound = bindCall(session.schema, call, hooks);
|
|
313
|
+
let plan = session.cache.get(bound.key);
|
|
314
|
+
if (plan === undefined) {
|
|
315
|
+
plan = compileCall(session.schema, call, bound.key, hooks);
|
|
316
|
+
if (session.cache.size >= PLAN_LIMIT) {
|
|
317
|
+
const oldest = session.cache.keys().next().value;
|
|
318
|
+
if (oldest !== undefined)
|
|
319
|
+
session.cache.delete(oldest);
|
|
320
|
+
}
|
|
321
|
+
session.cache.set(bound.key, plan);
|
|
322
|
+
}
|
|
323
|
+
prepared = { plan, params: bound.params };
|
|
324
|
+
return prepared;
|
|
325
|
+
};
|
|
326
|
+
const sync = () => !searched && call.include === undefined && mods.uses === undefined && !selectHasWindow(call.select) && !readNeedsOperatorSql(session.schema, call);
|
|
327
|
+
const run = async () => {
|
|
328
|
+
await session.connected;
|
|
329
|
+
const { plan, params } = await prepare();
|
|
330
|
+
try {
|
|
331
|
+
const result = await session.pool.execute(plan.text, params, callOptions(call, session.timeouts?.statement));
|
|
332
|
+
if (session.hookm && result.notices.length) {
|
|
333
|
+
import("./96ps4g1z.js").then((mod) => mod.notices(session.hookm, result.notices));
|
|
334
|
+
}
|
|
335
|
+
return await decode(plan, result.rows);
|
|
336
|
+
} catch (error) {
|
|
337
|
+
const mapped = await mapError(session, error);
|
|
338
|
+
if (session.schema.model[table]?.conceal !== true)
|
|
339
|
+
throw logged(session, mapped);
|
|
340
|
+
const { scrubCall } = await import("./72fyg4zv.js");
|
|
341
|
+
throw logged(session, scrubCall(mapped, session.schema, call));
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
return queryHandle(run, {
|
|
345
|
+
inspect() {
|
|
346
|
+
const source = session.schema.model[table]?.source;
|
|
347
|
+
if (call.include === undefined && prepared !== undefined) {
|
|
348
|
+
return finish(session, inspection(prepared.plan, prepared.params, call, source), call);
|
|
349
|
+
}
|
|
350
|
+
if (sync()) {
|
|
351
|
+
const bound = bindNow(session.schema, call);
|
|
352
|
+
prepared = bound;
|
|
353
|
+
return finish(session, inspection(bound.plan, bound.params, call, source), call);
|
|
354
|
+
}
|
|
355
|
+
return prepare().then(({ plan, params }) => finish(session, inspection(plan, params, call, source), call));
|
|
356
|
+
},
|
|
357
|
+
sql() {
|
|
358
|
+
if (call.include === undefined && prepared !== undefined) {
|
|
359
|
+
return { text: prepared.plan.text, params: prepared.params };
|
|
360
|
+
}
|
|
361
|
+
if (sync()) {
|
|
362
|
+
const { plan, params } = bindNow(session.schema, call);
|
|
363
|
+
prepared = { plan, params };
|
|
364
|
+
return { text: plan.text, params };
|
|
365
|
+
}
|
|
366
|
+
return prepare().then(({ plan, params }) => ({ text: plan.text, params }));
|
|
367
|
+
},
|
|
368
|
+
...extra?.(prepare)
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
function streamLazy(session, call, mods, view, batch) {
|
|
372
|
+
return async function* () {
|
|
373
|
+
const { streamRows } = await import("./ddjtfgnx.js");
|
|
374
|
+
yield* streamRows(session, call, mods, view, batch, (error) => logged(session, error));
|
|
375
|
+
}();
|
|
376
|
+
}
|
|
377
|
+
function archiveRecord(model, view) {
|
|
378
|
+
if (model?.archive === undefined)
|
|
379
|
+
return;
|
|
380
|
+
const rules = archiveRules(model, view);
|
|
381
|
+
if (rules === undefined)
|
|
382
|
+
return;
|
|
383
|
+
return { ruleLines: rules };
|
|
384
|
+
}
|
|
385
|
+
function readCall(op, table, options, all, scope, model, schema, view) {
|
|
386
|
+
const record = options;
|
|
387
|
+
rejectKeys(record, readOptionNames(op), op, true);
|
|
388
|
+
return {
|
|
389
|
+
op,
|
|
390
|
+
table,
|
|
391
|
+
...record.where !== undefined ? { where: record.where } : {},
|
|
392
|
+
...record.select !== undefined ? { select: record.select } : {},
|
|
393
|
+
...record.orderBy !== undefined ? { orderBy: record.orderBy } : {},
|
|
394
|
+
...record.limit !== undefined ? { limit: record.limit } : {},
|
|
395
|
+
...record.include !== undefined ? { include: record.include } : {},
|
|
396
|
+
..."search" in record ? { search: record.search } : {},
|
|
397
|
+
...callOptions(record),
|
|
398
|
+
...all !== undefined ? { all } : {},
|
|
399
|
+
...scope !== undefined ? { scope } : {},
|
|
400
|
+
...schema.tenancy !== undefined && model !== undefined ? { tenancyRules: schema.tenancy.rules(table, model.source, scope) } : {},
|
|
401
|
+
...view !== undefined ? { archive: view } : {},
|
|
402
|
+
...archiveRecord(model, view)
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
async function checkServer(pool, schema, http, requireMeta, options, source) {
|
|
406
|
+
const server = await import("./pw8fgahx.js");
|
|
407
|
+
let rows;
|
|
408
|
+
try {
|
|
409
|
+
const result = await pool.execute(server.versionQuery, undefined, options);
|
|
410
|
+
rows = result.rows;
|
|
411
|
+
} catch (error) {
|
|
412
|
+
const { mapPostgresError } = await import("./ep8zh3bk.js");
|
|
413
|
+
throw mapPostgresError(error, mapOptions(http, false, schema));
|
|
414
|
+
}
|
|
415
|
+
await server.acceptServer(pool, schema, rows, http, requireMeta, options, source);
|
|
416
|
+
}
|
|
417
|
+
async function mapError(session, error) {
|
|
418
|
+
if (error instanceof OkmError) {
|
|
419
|
+
return session.http === undefined ? error : new OkmError(error.code, error.message, { ...errorFields(error), http: session.http });
|
|
420
|
+
}
|
|
421
|
+
const { mapPostgresError } = await import("./ep8zh3bk.js");
|
|
422
|
+
return mapPostgresError(error, mapOptions(session.http, session.includeValues, session.schema));
|
|
423
|
+
}
|
|
424
|
+
function errorFields(error) {
|
|
425
|
+
return {
|
|
426
|
+
kind: error.kind,
|
|
427
|
+
...error.table !== undefined ? { table: error.table } : {},
|
|
428
|
+
...error.columns.length > 0 ? { columns: error.columns } : {},
|
|
429
|
+
fix: error.fix
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
var includeHooks;
|
|
433
|
+
var operatorSql;
|
|
434
|
+
function loadOperatorSql() {
|
|
435
|
+
operatorSql ??= import("./9kazs5p6.js").then(() => {
|
|
436
|
+
return;
|
|
437
|
+
});
|
|
438
|
+
return operatorSql;
|
|
439
|
+
}
|
|
440
|
+
function selectHasWindow(select) {
|
|
441
|
+
return Array.isArray(select) && select.some((item) => typeof item !== "string");
|
|
442
|
+
}
|
|
443
|
+
function hooksFor(call) {
|
|
444
|
+
if (call.include === undefined)
|
|
445
|
+
return Promise.resolve(undefined);
|
|
446
|
+
includeHooks ??= import("./yfr8hzhm.js").then((mod) => mod.includeHooks);
|
|
447
|
+
return includeHooks;
|
|
448
|
+
}
|
|
449
|
+
function bindNow(schema, call) {
|
|
450
|
+
const bound = bindCall(schema, call);
|
|
451
|
+
const plan = compileCall(schema, call, bound.key);
|
|
452
|
+
return { plan, params: bound.params };
|
|
453
|
+
}
|
|
454
|
+
function finish(session, view, call) {
|
|
455
|
+
if (session.schema.model[call.table]?.conceal !== true)
|
|
456
|
+
return view;
|
|
457
|
+
return import("./72fyg4zv.js").then((mod) => mod.redactView(session.schema, view, call));
|
|
458
|
+
}
|
|
459
|
+
function inspection(plan, params, call, source) {
|
|
460
|
+
return {
|
|
461
|
+
intent: logicalIntent(call),
|
|
462
|
+
rules: appliedRules(call, source),
|
|
463
|
+
plan: { strategy: "postgres:single-statement", statements: 1, fingerprint: plan.fingerprint },
|
|
464
|
+
sql: { text: plan.text, params },
|
|
465
|
+
routing: SINGLE_ENDPOINT
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
function withHttp(http, options) {
|
|
469
|
+
return http === undefined ? options : { ...options, http };
|
|
470
|
+
}
|
|
471
|
+
function attachHttp(http, error) {
|
|
472
|
+
if (http === undefined)
|
|
473
|
+
return error;
|
|
474
|
+
return new OkmError(error.code, error.message, { ...errorFields(error), http });
|
|
475
|
+
}
|
|
476
|
+
function callOptions(input, statement) {
|
|
477
|
+
const timeout = input.timeout ?? statement;
|
|
478
|
+
const route = input.route;
|
|
479
|
+
const pin = input.pin;
|
|
480
|
+
if (input.signal === undefined && timeout === undefined && route === undefined && pin === undefined) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
return {
|
|
484
|
+
...input.signal !== undefined ? { signal: input.signal } : {},
|
|
485
|
+
...timeout !== undefined ? { timeout } : {},
|
|
486
|
+
...route !== undefined ? { route } : {},
|
|
487
|
+
...pin !== undefined ? { pin } : {}
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function mapOptions(http, includeValues, schema) {
|
|
491
|
+
return {
|
|
492
|
+
...http !== undefined ? { http } : {},
|
|
493
|
+
...includeValues ? { includeValues: true } : {},
|
|
494
|
+
schema
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
async function settleCall(session, error) {
|
|
498
|
+
throw logged(session, await mapError(session, error));
|
|
499
|
+
}
|
|
500
|
+
function logged(session, error) {
|
|
501
|
+
session.logger?.error?.({ code: error.code, summary: error.summary });
|
|
502
|
+
return error;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
export { createClient, openClient, queryHandle, decodeRows, readHandle, readCall, withHttp, attachHttp, settleCall };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/runtime/tx.ts
|
|
2
|
+
async function runWrite(host, statements, options, atomic) {
|
|
3
|
+
if (statements.length === 0)
|
|
4
|
+
return [];
|
|
5
|
+
const first = statements[0];
|
|
6
|
+
const limit = options?.timeout ?? host.timeouts?.statement;
|
|
7
|
+
const call = limit === undefined || limit === options?.timeout ? options : { ...options, timeout: limit };
|
|
8
|
+
const single = statements.length === 1 && first !== undefined && atomic === undefined;
|
|
9
|
+
const watched = host.hookm !== undefined && !single && host.tx === undefined ? await import("./96ps4g1z.js") : undefined;
|
|
10
|
+
watched?.phase(host.hookm, "start", 0);
|
|
11
|
+
let results;
|
|
12
|
+
try {
|
|
13
|
+
results = single ? [await host.pool.execute(first.text, first.params, call)] : await host.pool.batch(statements, call);
|
|
14
|
+
} catch (error) {
|
|
15
|
+
watched?.phase(host.hookm, "rollback", 0);
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
watched?.phase(host.hookm, "commit", 0);
|
|
19
|
+
if (host.hookm !== undefined) {
|
|
20
|
+
const heard = results.flatMap((result) => result.notices);
|
|
21
|
+
if (heard.length > 0)
|
|
22
|
+
(await import("./96ps4g1z.js")).notices(host.hookm, heard);
|
|
23
|
+
}
|
|
24
|
+
return results;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { runWrite };
|