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
package/dist/runtime/types.d.ts
CHANGED
|
@@ -7,8 +7,10 @@
|
|
|
7
7
|
import type { DriverTimeouts, Notice } from "../contracts/driver.js";
|
|
8
8
|
import type { SafeResult } from "../contracts/error.js";
|
|
9
9
|
import type { QuerySchema } from "../dialects/pg/model.js";
|
|
10
|
+
import type { Bucket } from "../dialects/pg/ops/bucket.js";
|
|
11
|
+
import type { Window } from "../dialects/pg/ops/window.js";
|
|
10
12
|
import type { Inc } from "../dialects/pg/ops/inc.js";
|
|
11
|
-
import type { ArrAppend, ArrRemove, JsonSet, Or, RelationFilter } from "../dialects/pg/operators.js";
|
|
13
|
+
import type { ArrAppend, ArrRemove, JsonSet, Or, RelationFilter, Relevance, SearchMatch } from "../dialects/pg/operators.js";
|
|
12
14
|
import type { FieldWhere, IsJsonObject } from "../dialects/pg/where.js";
|
|
13
15
|
import type { AppliedRule, ReadOp } from "./plan.js";
|
|
14
16
|
export type { FieldWhere, WhereValue } from "../dialects/pg/where.js";
|
|
@@ -22,8 +24,20 @@ export type RelationsOf<S extends QuerySchema, K extends keyof S["~byName"]> = S
|
|
|
22
24
|
} ? R : Record<string, never>;
|
|
23
25
|
/** Array and JSON writes the column value type can accept. */
|
|
24
26
|
type WriteOp<V> = [unknown] extends [V] ? JsonSet<unknown> | ArrAppend<unknown> | ArrRemove<unknown> : (V extends readonly (infer E)[] ? ArrAppend<E> | ArrRemove<E> : never) | (IsJsonObject<V> extends true ? JsonSet<unknown> : never);
|
|
25
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* `inc` on a number or bigint column.
|
|
29
|
+
*
|
|
30
|
+
* A `string` column is not included. `text` is a string, and so is `numeric`
|
|
31
|
+
* or `bigint` when the codec keeps the decimal text. The statement still
|
|
32
|
+
* accepts `inc` on a numeric database type.
|
|
33
|
+
*/
|
|
34
|
+
type IncOf<V> = [unknown] extends [V] ? Inc<number> | Inc<bigint> : [NonNullable<V>] extends [number] ? Inc<number> : [NonNullable<V>] extends [bigint] ? Inc<bigint> : never;
|
|
35
|
+
/** `has`, `none`, and `every` against the related row. A morph include is not a filter. */
|
|
26
36
|
export type RelFilter<S extends QuerySchema, Rel> = Rel extends {
|
|
37
|
+
readonly morph: {
|
|
38
|
+
readonly targets: readonly string[];
|
|
39
|
+
};
|
|
40
|
+
} ? never : Rel extends {
|
|
27
41
|
readonly table: infer T extends string;
|
|
28
42
|
} ? T extends keyof S["~byName"] ? RelationFilter<"has" | "none" | "every", FieldWhere<RowOf<S, T>>> : never : never;
|
|
29
43
|
/** Known relation names. A string index (no declared relations) adds none. */
|
|
@@ -39,14 +53,34 @@ export type OrderBy<Row> = {
|
|
|
39
53
|
readonly [K in keyof Row]?: "asc" | "desc" | {
|
|
40
54
|
readonly dir: "asc" | "desc";
|
|
41
55
|
readonly nulls?: "first" | "last";
|
|
42
|
-
} | undefined;
|
|
56
|
+
} | Relevance | undefined;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Text to look for.
|
|
60
|
+
*
|
|
61
|
+
* A string is enough when the table has one column built for search. `in`
|
|
62
|
+
* names the column when it has more than one.
|
|
63
|
+
*/
|
|
64
|
+
export type TextSearch<Row> = string | {
|
|
65
|
+
/** Text to look for. */
|
|
66
|
+
readonly for: string;
|
|
67
|
+
/** Column to search. Required when the table has more than one. */
|
|
68
|
+
readonly in?: keyof Row & string;
|
|
69
|
+
/** How to match. Omitted means `natural`. */
|
|
70
|
+
readonly match?: SearchMatch;
|
|
71
|
+
/** Text search language, such as `english`. Omitted uses the database default. */
|
|
72
|
+
readonly language?: string;
|
|
43
73
|
};
|
|
44
74
|
type Related<S extends QuerySchema, T extends keyof S["~byName"], Opt> = Opt extends {
|
|
45
75
|
readonly select: infer Sel;
|
|
46
76
|
} ? Selected<RowOf<S, T>, Sel> : RowOf<S, T>;
|
|
47
|
-
/** One include. To-many needs `limit`. */
|
|
77
|
+
/** One include. To-many needs `limit`. A morph include is `true`. */
|
|
48
78
|
export type IncludeOf<S extends QuerySchema, K extends keyof S["~byName"]> = {
|
|
49
79
|
readonly [R in RelationKeys<RelationsOf<S, K>>]?: RelationsOf<S, K>[R] extends {
|
|
80
|
+
readonly morph: {
|
|
81
|
+
readonly targets: readonly string[];
|
|
82
|
+
};
|
|
83
|
+
} ? true : RelationsOf<S, K>[R] extends {
|
|
50
84
|
readonly kind: "many";
|
|
51
85
|
readonly table: infer T extends string;
|
|
52
86
|
} ? T extends keyof S["~byName"] ? {
|
|
@@ -63,14 +97,40 @@ export type IncludeOf<S extends QuerySchema, K extends keyof S["~byName"]> = {
|
|
|
63
97
|
readonly orderBy?: OrderBy<RowOf<S, T>>;
|
|
64
98
|
} : never : never;
|
|
65
99
|
};
|
|
100
|
+
/**
|
|
101
|
+
* Rows a morph include can return.
|
|
102
|
+
*
|
|
103
|
+
* Each target's row, plus the type field set to that table name, or null when
|
|
104
|
+
* the target row is missing.
|
|
105
|
+
*/
|
|
106
|
+
/** Flattens an intersection so a morph arm is one object type. */
|
|
107
|
+
type Flat<T> = {
|
|
108
|
+
readonly [K in keyof T]: T[K];
|
|
109
|
+
};
|
|
110
|
+
/** One arm of a morph union. Distributes over the closed target list. */
|
|
111
|
+
type MorphArm<S extends QuerySchema, T extends string, Field extends string> = T extends keyof S["~byName"] ? Flat<RowOf<S, T> & {
|
|
112
|
+
readonly [P in Field]: T;
|
|
113
|
+
}> : never;
|
|
114
|
+
type MorphUnion<S extends QuerySchema, Targets extends readonly string[], Field extends string> = MorphArm<S, Targets[number], Field> | null;
|
|
66
115
|
/** Columns kept by `select`. The full row when `select` is omitted. */
|
|
67
116
|
export type Selected<Row, Sel> = [Sel] extends [readonly (infer P)[]] ? [P] extends [keyof Row] ? {
|
|
68
117
|
readonly [K in P & keyof Row]: Row[K];
|
|
69
|
-
} : Row : Row;
|
|
118
|
+
} : boolean extends HasWindow<P> ? Pick<Row, Extract<P, keyof Row>> & WindowFields<Row, P> : [P] extends [Window<string, string | number>] ? WindowFields<Row, P> : Row : Row;
|
|
119
|
+
/** `true` when a select entry is a window. A mix of fields and windows is `boolean`. */
|
|
120
|
+
type HasWindow<P> = P extends Window<string, string | number> ? true : false;
|
|
121
|
+
/** Result keys a window helper adds. A field name contributes nothing. */
|
|
122
|
+
type WindowFields<Row, P> = Intersect<P extends Window<infer A, infer V> ? {
|
|
123
|
+
readonly [K in A]: V extends keyof Row ? NonNullable<Row[V]> | null : V extends number ? number : string;
|
|
124
|
+
} : {}>;
|
|
70
125
|
type IncludeRows<S extends QuerySchema, K extends keyof S["~byName"], Inc> = [Inc] extends [
|
|
71
126
|
Record<string, unknown>
|
|
72
127
|
] ? {
|
|
73
128
|
readonly [R in keyof Inc & keyof RelationsOf<S, K>]: RelationsOf<S, K>[R] extends {
|
|
129
|
+
readonly morph: {
|
|
130
|
+
readonly targets: infer Targets extends readonly string[];
|
|
131
|
+
readonly typeField: infer Field extends string;
|
|
132
|
+
};
|
|
133
|
+
} ? MorphUnion<S, Targets, Field> : RelationsOf<S, K>[R] extends {
|
|
74
134
|
readonly kind: "many";
|
|
75
135
|
readonly table: infer T extends keyof S["~byName"];
|
|
76
136
|
} ? readonly Related<S, T, Inc[R]>[] : RelationsOf<S, K>[R] extends {
|
|
@@ -109,7 +169,8 @@ export type CallOptions = {
|
|
|
109
169
|
/** Options shared by reads. */
|
|
110
170
|
export type ReadOptions<S extends QuerySchema, K extends keyof S["~byName"]> = CallOptions & {
|
|
111
171
|
readonly where?: WhereOf<S, K>;
|
|
112
|
-
|
|
172
|
+
/** Field names, or a window helper (`rowNumber`, `rank`, `denseRank`, `runningTotal`). */
|
|
173
|
+
readonly select?: readonly ((keyof RowOf<S, K> & string) | Window<string, string | number>)[];
|
|
113
174
|
readonly orderBy?: OrderBy<RowOf<S, K>>;
|
|
114
175
|
readonly include?: IncludeOf<S, K>;
|
|
115
176
|
};
|
|
@@ -118,6 +179,7 @@ export type ReadOptions<S extends QuerySchema, K extends keyof S["~byName"]> = C
|
|
|
118
179
|
*
|
|
119
180
|
* `wait` says what happens when a row is locked by another transaction: `nowait`
|
|
120
181
|
* fails at once (kind `lock_timeout`) and `skip` leaves that row out.
|
|
182
|
+
* `lock: "skip"` is not a read lock. It claims rows on `update`.
|
|
121
183
|
*/
|
|
122
184
|
export type LockOptions = {
|
|
123
185
|
readonly lock?: "update" | "share";
|
|
@@ -126,6 +188,48 @@ export type LockOptions = {
|
|
|
126
188
|
/** `find` options. `limit` is required unless the caller uses `.all(reason)`. */
|
|
127
189
|
export type FindOptions<S extends QuerySchema, K extends keyof S["~byName"]> = ReadOptions<S, K> & {
|
|
128
190
|
readonly limit?: number;
|
|
191
|
+
/** Text to look for. The closest matches come first unless `orderBy` is set. */
|
|
192
|
+
readonly search?: TextSearch<RowOf<S, K>>;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Options for `descendants` and `ancestors`.
|
|
196
|
+
*
|
|
197
|
+
* `depth` is how many steps from the starting row. Omit it to walk the whole
|
|
198
|
+
* tree. `self` includes that row. `relation` names which self-relation when
|
|
199
|
+
* the table has more than one.
|
|
200
|
+
*/
|
|
201
|
+
export type TreeOptions<S extends QuerySchema, K extends keyof S["~byName"]> = CallOptions & {
|
|
202
|
+
readonly where?: WhereOf<S, K>;
|
|
203
|
+
readonly select?: readonly (keyof RowOf<S, K> & string)[];
|
|
204
|
+
readonly orderBy?: OrderBy<RowOf<S, K>>;
|
|
205
|
+
readonly depth?: number;
|
|
206
|
+
/** Include the starting row. Omitted leaves it out. */
|
|
207
|
+
readonly self?: boolean;
|
|
208
|
+
/** Which self-relation. Required when the table has more than one. */
|
|
209
|
+
readonly relation?: string;
|
|
210
|
+
};
|
|
211
|
+
/** Links `sync` added and removed. Values are the related row's primary key. */
|
|
212
|
+
export type SyncResult = {
|
|
213
|
+
readonly added: readonly unknown[];
|
|
214
|
+
readonly removed: readonly unknown[];
|
|
215
|
+
};
|
|
216
|
+
/** Options for `sync`. `expect` matches an update: the count is links added plus links removed. */
|
|
217
|
+
export type SyncOptions = CallOptions & {
|
|
218
|
+
readonly expect?: number;
|
|
219
|
+
};
|
|
220
|
+
/** The handle `sync` returns. */
|
|
221
|
+
export type SyncHandle = Promise<SyncResult> & {
|
|
222
|
+
/** The statement, before it runs. */
|
|
223
|
+
sql(): Promise<{
|
|
224
|
+
readonly statements: readonly {
|
|
225
|
+
readonly text: string;
|
|
226
|
+
readonly params?: readonly (string | null)[];
|
|
227
|
+
}[];
|
|
228
|
+
}>;
|
|
229
|
+
/** `{ ok, value }` or `{ ok, error }`. */
|
|
230
|
+
safe(): Promise<SafeResult<SyncResult>>;
|
|
231
|
+
/** Throws `not_found` when the number of added and removed links is not `count`. */
|
|
232
|
+
expect(count: number): SyncHandle;
|
|
129
233
|
};
|
|
130
234
|
/** A query handle. Await it, or inspect it before it runs. */
|
|
131
235
|
export type Query<T> = Promise<T> & {
|
|
@@ -148,15 +252,27 @@ export type Read<T> = Query<T> & {
|
|
|
148
252
|
all(reason: string): Read<T>;
|
|
149
253
|
/** Turns a null `one()` into `not_found`. */
|
|
150
254
|
required(): Read<NonNullable<T>>;
|
|
151
|
-
/**
|
|
152
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Yields rows in keyset batches on every driver.
|
|
257
|
+
*
|
|
258
|
+
* `batch` is how many rows one query fetches. The default is 1000.
|
|
259
|
+
* `limit` on the find is the total. A table with no primary key is OKM1120.
|
|
260
|
+
*/
|
|
261
|
+
stream(options?: {
|
|
262
|
+
readonly batch?: number;
|
|
263
|
+
}): AsyncIterable<T extends readonly (infer R)[] ? R : T>;
|
|
153
264
|
};
|
|
154
265
|
/** One page: the rows, and the cursor for the next page. `next` is `null` on the last page. */
|
|
155
266
|
export type Page<Row> = {
|
|
156
267
|
readonly items: readonly Row[];
|
|
157
268
|
readonly next: string | null;
|
|
158
269
|
};
|
|
159
|
-
/**
|
|
270
|
+
/**
|
|
271
|
+
* `page` options. `after` is the `next` of the page before.
|
|
272
|
+
*
|
|
273
|
+
* `page` refuses a window helper when the call runs (OKM1120). The keyset
|
|
274
|
+
* cursor has no window value to encode.
|
|
275
|
+
*/
|
|
160
276
|
export type PageOptions<S extends QuerySchema, K extends keyof S["~byName"]> = ReadOptions<S, K> & {
|
|
161
277
|
/** Rows in the page. At least 1. */
|
|
162
278
|
readonly limit: number;
|
|
@@ -172,25 +288,51 @@ export type PageOptions<S extends QuerySchema, K extends keyof S["~byName"]> = R
|
|
|
172
288
|
type NumericKeys<Row> = {
|
|
173
289
|
readonly [F in keyof Row]-?: [NonNullable<Row[F]>] extends [number | string] ? F : never;
|
|
174
290
|
}[keyof Row] & string;
|
|
291
|
+
/** One `orderBy` value. `asc` is nulls last and `desc` is nulls first unless `nulls` is set. */
|
|
292
|
+
type SortDir = "asc" | "desc" | {
|
|
293
|
+
readonly dir: "asc" | "desc";
|
|
294
|
+
readonly nulls?: "first" | "last";
|
|
295
|
+
};
|
|
175
296
|
/** `aggregate` options. A hidden field is refused at runtime. */
|
|
176
297
|
export type AggregateOptions<S extends QuerySchema, K extends keyof S["~byName"]> = CallOptions & {
|
|
177
298
|
readonly where?: WhereOf<S, K>;
|
|
178
299
|
/** One result row per distinct combination. Needs `limit`, or `.all(reason)`. */
|
|
179
|
-
readonly groupBy?: readonly (keyof RowOf<S, K> & string)[];
|
|
300
|
+
readonly groupBy?: readonly ((keyof RowOf<S, K> & string) | Bucket<string, string, string>)[];
|
|
180
301
|
/** Adds `count`, the number of rows in the group. */
|
|
181
302
|
readonly count?: true;
|
|
182
303
|
readonly sum?: readonly NumericKeys<RowOf<S, K>>[];
|
|
183
304
|
readonly avg?: readonly NumericKeys<RowOf<S, K>>[];
|
|
184
305
|
readonly min?: readonly (keyof RowOf<S, K> & string)[];
|
|
185
306
|
readonly max?: readonly (keyof RowOf<S, K> & string)[];
|
|
186
|
-
/**
|
|
187
|
-
|
|
307
|
+
/**
|
|
308
|
+
* Orders the groups. A `groupBy` field or a bucket `as`.
|
|
309
|
+
* Without it, groups come in `groupBy` order.
|
|
310
|
+
*/
|
|
311
|
+
readonly orderBy?: OrderBy<RowOf<S, K>> | {
|
|
312
|
+
readonly [key: string]: SortDir | undefined;
|
|
313
|
+
};
|
|
188
314
|
readonly limit?: number;
|
|
189
315
|
};
|
|
316
|
+
/** `true` when a group entry is a bucket. A mix of fields and buckets is `boolean`. */
|
|
317
|
+
type HasBucket<G> = G extends Bucket<string, string, string> ? true : false;
|
|
318
|
+
/** One bucket key. A string group contributes nothing. */
|
|
319
|
+
type BucketPiece<Row, G> = G extends Bucket<infer C, infer U, infer A> ? {
|
|
320
|
+
readonly [K in A]: (U extends "second" | "minute" | "hour" ? Temporal.Instant : Temporal.PlainDate) | (C extends keyof Row ? (null extends Row[C] ? null : never) : null);
|
|
321
|
+
} : {};
|
|
322
|
+
/** Intersection of a union of group pieces. */
|
|
323
|
+
type Intersect<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : unknown;
|
|
324
|
+
/**
|
|
325
|
+
* Group keys on an aggregate row.
|
|
326
|
+
*
|
|
327
|
+
* A plain field list stays `Pick`. A bucket list adds each `as` key. The value
|
|
328
|
+
* is `Temporal.PlainDate` for a calendar unit and `Temporal.Instant` for a
|
|
329
|
+
* clock unit, and includes `null` when the column does.
|
|
330
|
+
*/
|
|
331
|
+
type GroupOf<Row, G> = boolean extends HasBucket<G> ? Pick<Row, Extract<G, keyof Row>> & Intersect<BucketPiece<Row, G>> : [G] extends [Bucket<string, string, string>] ? Intersect<BucketPiece<Row, G>> : Pick<Row, G & keyof Row>;
|
|
190
332
|
/** A group: its fields, and the aggregates the call named. */
|
|
191
333
|
export type AggregateRow<Row, O> = Show<(O extends {
|
|
192
334
|
readonly groupBy: readonly (infer G)[];
|
|
193
|
-
} ?
|
|
335
|
+
} ? GroupOf<Row, G> : unknown) & (O extends {
|
|
194
336
|
readonly count: true;
|
|
195
337
|
} ? {
|
|
196
338
|
readonly count: number;
|
|
@@ -311,9 +453,15 @@ export type InsertOf<S extends QuerySchema, K extends keyof S["~byName"]> = S["~
|
|
|
311
453
|
export type UpdateOf<S extends QuerySchema, K extends keyof S["~byName"]> = S["~byName"][K] extends {
|
|
312
454
|
readonly "~update": infer U;
|
|
313
455
|
} ? U : never;
|
|
314
|
-
/**
|
|
456
|
+
/**
|
|
457
|
+
* `set` values.
|
|
458
|
+
*
|
|
459
|
+
* `undefined` leaves the field unchanged. `null` sets null, and only on a
|
|
460
|
+
* nullable column. `inc` adds to a number or bigint column. A null number
|
|
461
|
+
* stays null. `json.set` and `arr` write json and arrays.
|
|
462
|
+
*/
|
|
315
463
|
export type UpdateSet<S extends QuerySchema, K extends keyof S["~byName"]> = {
|
|
316
|
-
readonly [F in keyof UpdateOf<S, K>]?: UpdateOf<S, K>[F] |
|
|
464
|
+
readonly [F in keyof UpdateOf<S, K>]?: UpdateOf<S, K>[F] | IncOf<UpdateOf<S, K>[F]> | WriteOp<NonNullable<UpdateOf<S, K>[F]>>;
|
|
317
465
|
};
|
|
318
466
|
/** Conflict handling on `insert` (spec §11). */
|
|
319
467
|
export type OnConflict<S extends QuerySchema, K extends keyof S["~byName"]> = "error" | "ignore" | {
|
|
@@ -337,7 +485,7 @@ export type InsertOptions<S extends QuerySchema, K extends keyof S["~byName"]> =
|
|
|
337
485
|
};
|
|
338
486
|
/** Options for `update` and `delete`. */
|
|
339
487
|
export type WriteOptions<S extends QuerySchema, K extends keyof S["~byName"]> = {
|
|
340
|
-
readonly returning?: readonly (keyof RowOf<S, K> & string)[];
|
|
488
|
+
readonly returning?: true | readonly (keyof RowOf<S, K> & string)[];
|
|
341
489
|
/** Guarded fields this call may set. `delete` ignores it. */
|
|
342
490
|
readonly allow?: readonly (keyof RowOf<S, K> & string)[];
|
|
343
491
|
readonly expect?: number;
|
|
@@ -372,19 +520,32 @@ type AllowedSet<S extends QuerySchema, K extends keyof S["~byName"], Allow exten
|
|
|
372
520
|
type AllowedUpdate<S extends QuerySchema, K extends keyof S["~byName"], Allow extends readonly (keyof RowOf<S, K> & string)[]> = {
|
|
373
521
|
readonly where?: WhereOf<S, K>;
|
|
374
522
|
readonly set: AllowedSet<S, K, Allow>;
|
|
523
|
+
readonly version?: number;
|
|
375
524
|
} | readonly {
|
|
376
525
|
readonly id?: unknown;
|
|
377
526
|
readonly where?: WhereOf<S, K>;
|
|
378
527
|
readonly set: AllowedSet<S, K, Allow>;
|
|
528
|
+
readonly version?: number;
|
|
379
529
|
}[];
|
|
380
|
-
/**
|
|
530
|
+
/**
|
|
531
|
+
* One update, or a per-row list in one statement.
|
|
532
|
+
*
|
|
533
|
+
* `lock: "skip"` with `limit` claims that many matching rows and leaves rows
|
|
534
|
+
* another transaction already holds. It is not valid on a list.
|
|
535
|
+
*/
|
|
381
536
|
export type UpdateTarget<S extends QuerySchema, K extends keyof S["~byName"]> = {
|
|
382
537
|
readonly where?: WhereOf<S, K>;
|
|
383
538
|
readonly set: UpdateSet<S, K>;
|
|
539
|
+
readonly limit?: number;
|
|
540
|
+
readonly lock?: "skip";
|
|
541
|
+
/** Version read from the row. Required at runtime when the table is `versioned()`. */
|
|
542
|
+
readonly version?: number;
|
|
384
543
|
} | readonly {
|
|
385
544
|
readonly id?: unknown;
|
|
386
545
|
readonly where?: WhereOf<S, K>;
|
|
387
546
|
readonly set: UpdateSet<S, K>;
|
|
547
|
+
/** Version read from the row. Required at runtime when the table is `versioned()`. */
|
|
548
|
+
readonly version?: number;
|
|
388
549
|
}[];
|
|
389
550
|
/** `{ count, archiveId }` from one `archive()` call. */
|
|
390
551
|
export type ArchiveCount = {
|
|
@@ -462,6 +623,7 @@ export type TableApi<S extends QuerySchema, K extends keyof S["~byName"] & strin
|
|
|
462
623
|
};
|
|
463
624
|
count(options?: CallOptions & {
|
|
464
625
|
readonly where?: WhereOf<S, K>;
|
|
626
|
+
readonly search?: TextSearch<RowOf<S, K>>;
|
|
465
627
|
}): Read<number>;
|
|
466
628
|
exists(options?: CallOptions & {
|
|
467
629
|
readonly where?: WhereOf<S, K>;
|
|
@@ -475,6 +637,20 @@ export type TableApi<S extends QuerySchema, K extends keyof S["~byName"] & strin
|
|
|
475
637
|
readonly allow: Allow;
|
|
476
638
|
}): Write<Show<RowOf<S, K>>>;
|
|
477
639
|
insert(data: RequiredInsert<InsertOf<S, K>> & OptionalInsert<InsertOf<S, K>>, options?: InsertOptions<S, K>): Write<Show<RowOf<S, K>>>;
|
|
640
|
+
/**
|
|
641
|
+
* Inserts a list in one transaction. Unknown keys are dropped.
|
|
642
|
+
*
|
|
643
|
+
* `{ allow: ["id"] }` may set `id` on a client-generator primary key.
|
|
644
|
+
* A row that omits `id` still takes the generator. A longer `allow` list
|
|
645
|
+
* does not open `id` in this type.
|
|
646
|
+
*
|
|
647
|
+
* @param data - Rows. `id` is optional when `allow` is exactly `["id"]`
|
|
648
|
+
* @param options - Must set `allow` to `["id"]`
|
|
649
|
+
* @returns The inserted rows
|
|
650
|
+
*/
|
|
651
|
+
insert(data: readonly (RequiredInsert<InsertOf<S, K>> & OptionalInsert<InsertOf<S, K>> & Partial<Pick<RowOf<S, K>, "id" & keyof RowOf<S, K>>>)[], options: InsertOptions<S, K> & {
|
|
652
|
+
readonly allow: readonly ["id"];
|
|
653
|
+
}): Write<readonly Show<RowOf<S, K>>[]>;
|
|
478
654
|
/**
|
|
479
655
|
* Inserts a list in one transaction. Unknown keys are dropped.
|
|
480
656
|
*
|
|
@@ -482,15 +658,49 @@ export type TableApi<S extends QuerySchema, K extends keyof S["~byName"] & strin
|
|
|
482
658
|
* database default for that row; `null` stays NULL.
|
|
483
659
|
*/
|
|
484
660
|
insert(data: readonly (RequiredInsert<InsertOf<S, K>> & OptionalInsert<InsertOf<S, K>>)[], options?: InsertOptions<S, K>): Write<readonly Show<RowOf<S, K>>[]>;
|
|
485
|
-
/**
|
|
486
|
-
|
|
661
|
+
/**
|
|
662
|
+
* Updates matching rows, or a per-row list in one statement. `where` is required.
|
|
663
|
+
*
|
|
664
|
+
* `{ allow, returning: true }` returns the written rows. `{ allow }` without
|
|
665
|
+
* `returning: true` returns `{ count }`.
|
|
666
|
+
*/
|
|
667
|
+
update<const Allow extends readonly (keyof RowOf<S, K> & string)[], const Opt extends WriteOptions<S, K> & {
|
|
487
668
|
readonly allow: Allow;
|
|
488
|
-
}): Write<WriteCount>;
|
|
669
|
+
}>(target: AllowedUpdate<S, K, Allow>, options: Opt): [Opt["returning"]] extends [true] ? Write<readonly Show<RowOf<S, K>>[]> : Write<WriteCount>;
|
|
670
|
+
update(target: UpdateTarget<S, K>, options: WriteOptions<S, K> & {
|
|
671
|
+
readonly returning: true;
|
|
672
|
+
}): Write<readonly Show<RowOf<S, K>>[]>;
|
|
489
673
|
update(target: UpdateTarget<S, K>, options?: WriteOptions<S, K>): Write<WriteCount>;
|
|
490
|
-
/**
|
|
674
|
+
/**
|
|
675
|
+
* Deletes matching rows. `where` is required.
|
|
676
|
+
*
|
|
677
|
+
* `{ returning: true }` is not accepted. Pass the field names, or omit
|
|
678
|
+
* `returning` for `{ count }`.
|
|
679
|
+
*/
|
|
491
680
|
delete(target: {
|
|
492
681
|
readonly where?: WhereOf<S, K>;
|
|
493
|
-
}, options?: WriteOptions<S, K>
|
|
682
|
+
}, options?: Omit<WriteOptions<S, K>, "returning"> & {
|
|
683
|
+
readonly returning?: Exclude<WriteOptions<S, K>["returning"], true>;
|
|
684
|
+
}): Write<WriteCount>;
|
|
685
|
+
/**
|
|
686
|
+
* Rows below `id`, walking the table's self-relation.
|
|
687
|
+
*
|
|
688
|
+
* One statement. A row already seen is not entered again, so a cycle in the
|
|
689
|
+
* data returns. A missing id returns no rows. `where` and a preset filter
|
|
690
|
+
* the rows that come back. Tenancy and the active set apply at every step.
|
|
691
|
+
*/
|
|
692
|
+
descendants<const O extends TreeOptions<S, K>>(id: unknown, options?: O): Query<readonly ResultRow<S, K, O>[]>;
|
|
693
|
+
/** Rows above `id`. The options match {@link TableApi.descendants}. */
|
|
694
|
+
ancestors<const O extends TreeOptions<S, K>>(id: unknown, options?: O): Query<readonly ResultRow<S, K, O>[]>;
|
|
695
|
+
/**
|
|
696
|
+
* Sets a to-many relation to exactly `ids`.
|
|
697
|
+
*
|
|
698
|
+
* One statement. A join table gains and loses link rows. A nullable foreign
|
|
699
|
+
* key is set or cleared, and the related row stays. A link that would have
|
|
700
|
+
* to delete a row is refused. Duplicate ids count once. An id that is not
|
|
701
|
+
* in the related table is `not_found`, and nothing is written.
|
|
702
|
+
*/
|
|
703
|
+
sync(id: unknown, relation: string, ids: readonly unknown[], options?: SyncOptions): SyncHandle;
|
|
494
704
|
} & (S["~byName"][K] extends {
|
|
495
705
|
readonly "~archive": true;
|
|
496
706
|
} ? ArchiveOps<S, K, L> : unknown) & PresetApi<S, K, L> & TableExtras<S, K>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validationGate
|
|
3
|
-
} from "../../shared/
|
|
3
|
+
} from "../../shared/w9ejzaqf.js";
|
|
4
4
|
import {
|
|
5
5
|
addSchemaHook
|
|
6
|
-
} from "../../shared/
|
|
6
|
+
} from "../../shared/9dr2qnx7.js";
|
|
7
7
|
import {
|
|
8
8
|
queryHandle
|
|
9
|
-
} from "../../shared/
|
|
9
|
+
} from "../../shared/bah9nbg3.js";
|
|
10
10
|
import {
|
|
11
11
|
OkmError2
|
|
12
12
|
} from "../../shared/52szzakm.js";
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
// src/runtime/validate/load.ts
|
|
15
15
|
var engine;
|
|
16
16
|
function loadEngine() {
|
|
17
|
-
engine ??= import("../../shared/
|
|
17
|
+
engine ??= import("../../shared/9dvh1dr6.js");
|
|
18
18
|
return engine;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optimistic version checks.
|
|
3
|
+
*
|
|
4
|
+
* Loaded on the first update of a `versioned()` table. A plain update does
|
|
5
|
+
* not import it. The check and the bump are one statement: a stale row is
|
|
6
|
+
* not written, and the caller hears category `conflict`.
|
|
7
|
+
*/
|
|
8
|
+
import type { Statement } from "../contracts/driver.js";
|
|
9
|
+
import type { QuerySchema } from "../dialects/pg/model.js";
|
|
10
|
+
import { type Outputs } from "./plan.js";
|
|
11
|
+
import { type Indexed } from "./plan.js";
|
|
12
|
+
import { type WriteMods } from "./write.js";
|
|
13
|
+
/** What {@link planVersioned} hands back to the write path. */
|
|
14
|
+
export type VersionPlan = {
|
|
15
|
+
readonly statements: readonly Statement[];
|
|
16
|
+
readonly outputs: Outputs;
|
|
17
|
+
readonly shape: "count" | "rows";
|
|
18
|
+
readonly expect: number | undefined;
|
|
19
|
+
/** Fields the caller tried to write, and the versions they sent. */
|
|
20
|
+
readonly versioned: {
|
|
21
|
+
readonly fields: readonly string[];
|
|
22
|
+
readonly sent: readonly number[];
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Plans an update that checks `version` and bumps it.
|
|
27
|
+
*
|
|
28
|
+
* A list carries one version per row. `lock: "skip"` claims rows at that
|
|
29
|
+
* version and leaves locked rows. `.all()` is refused. An upsert is refused
|
|
30
|
+
* by the insert planner, not here.
|
|
31
|
+
*
|
|
32
|
+
* @param schema - Connected schema
|
|
33
|
+
* @param table - Target table
|
|
34
|
+
* @param input - `{ where, set, version }` or a per-row list
|
|
35
|
+
* @param options - Returning, expect, signal, timeout
|
|
36
|
+
* @param mods - `.expect`. `.all` is refused
|
|
37
|
+
* @returns One statement, and the versions the caller sent
|
|
38
|
+
*/
|
|
39
|
+
export declare function planVersioned(schema: QuerySchema, table: Indexed, input: unknown, options: Record<string, unknown>, mods: WriteMods): VersionPlan;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Window helpers in `select` (spec §10, §13 tool 12).
|
|
3
|
+
*
|
|
4
|
+
* Loaded on the first `find` or `one` whose `select` contains a helper.
|
|
5
|
+
* A plain list of field names never loads this module. `page` does not take
|
|
6
|
+
* a window: its select is field names, and the keyset cursor has no window
|
|
7
|
+
* value to encode.
|
|
8
|
+
*/
|
|
9
|
+
import type { QuerySchema } from "../dialects/pg/model.js";
|
|
10
|
+
import { type ReadCall } from "./plan.js";
|
|
11
|
+
/**
|
|
12
|
+
* Plans a read whose `select` contains a window helper.
|
|
13
|
+
*
|
|
14
|
+
* The returned call writes the statement. Includes, tenancy, and presets stay
|
|
15
|
+
* on the planner the plain read uses.
|
|
16
|
+
*
|
|
17
|
+
* @param schema - Connected schema
|
|
18
|
+
* @param call - The read, with a window in `select`
|
|
19
|
+
* @returns The same read, with its statement builder set
|
|
20
|
+
*/
|
|
21
|
+
export declare function attach(schema: QuerySchema, call: ReadCall): ReadCall;
|
package/dist/runtime/write.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { ExecuteOptions, ExecuteResult, Statement } from "../contracts/driver.js";
|
|
8
8
|
import type { IdGenerators } from "../contracts/generator.js";
|
|
9
|
-
import type { PresetUse } from "../dialects/pg/model.js";
|
|
9
|
+
import type { ColumnModel, PresetUse } from "../dialects/pg/model.js";
|
|
10
10
|
import type { QuerySchema } from "../dialects/pg/model.js";
|
|
11
|
-
import { type ArchiveView, type CallScope } from "./plan.js";
|
|
11
|
+
import { type ArchiveView, type CallScope, type Indexed, type Sink } from "./plan.js";
|
|
12
12
|
import { type RunHost } from "./tx.js";
|
|
13
13
|
/** Statements in one insert stay under this many parameters. The protocol limit is 65535. */
|
|
14
14
|
export declare const WRITE_PARAM_BUDGET = 2048;
|
|
@@ -41,6 +41,13 @@ export type PreparedWrite = {
|
|
|
41
41
|
/** Set when `finish` can refuse a statement that already ran. `batch` refuses such a write (D183). */
|
|
42
42
|
readonly checked?: "restore" | "expect" | "parent";
|
|
43
43
|
finish(results: readonly ExecuteResult[]): unknown;
|
|
44
|
+
/**
|
|
45
|
+
* More statements once the planned ones have run.
|
|
46
|
+
*
|
|
47
|
+
* First-or-create uses this when the insert returned fewer rows than it was
|
|
48
|
+
* given. Empty means the insert already returned every row.
|
|
49
|
+
*/
|
|
50
|
+
follow?(results: readonly ExecuteResult[]): readonly Statement[];
|
|
44
51
|
};
|
|
45
52
|
/**
|
|
46
53
|
* Runs a write and decodes it.
|
|
@@ -71,3 +78,48 @@ export declare function executeWrite(host: WriteHost, op: WriteOp, table: string
|
|
|
71
78
|
export declare function explainWrite(schema: QuerySchema, op: WriteOp, table: string, input: unknown, options: object, mods: WriteMods, generators?: IdGenerators, scope?: CallScope): Promise<{
|
|
72
79
|
readonly statements: readonly Statement[];
|
|
73
80
|
}>;
|
|
81
|
+
export declare function updateSliceBody(schema: QuerySchema, table: Indexed, rows: readonly {
|
|
82
|
+
readonly where: unknown;
|
|
83
|
+
readonly set: Record<string, unknown>;
|
|
84
|
+
}[], sql: Sql, wrapWhere?: boolean, hooks?: {
|
|
85
|
+
afterWhere?(sql: Sql, index: number): void;
|
|
86
|
+
afterSet?(sql: Sql): void;
|
|
87
|
+
}): void;
|
|
88
|
+
export declare function rejectDuplicateTargets(table: Indexed, rows: readonly {
|
|
89
|
+
readonly where: unknown;
|
|
90
|
+
}[]): void;
|
|
91
|
+
export declare function emitSet(sql: Sql, table: Indexed, set: Record<string, unknown>, alias: string): void;
|
|
92
|
+
export declare class Sql {
|
|
93
|
+
private readonly parts;
|
|
94
|
+
private readonly params;
|
|
95
|
+
text(value: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Binds one parameter.
|
|
98
|
+
*
|
|
99
|
+
* An empty data type leaves the parameter uncast so `where` can infer it.
|
|
100
|
+
*/
|
|
101
|
+
param(wire: string | null, dataType: string): void;
|
|
102
|
+
sink(): Sink;
|
|
103
|
+
statement(): Statement;
|
|
104
|
+
}
|
|
105
|
+
export declare function writeSet(table: Indexed, value: unknown, allow: ReadonlySet<string>, tenancy: QuerySchema["tenancy"]): Record<string, unknown>;
|
|
106
|
+
/**
|
|
107
|
+
* A list that sets one field with an operator in one row and a plain value,
|
|
108
|
+
* or a different operator, in another.
|
|
109
|
+
*/
|
|
110
|
+
export declare function rejectMixedSets(rows: readonly {
|
|
111
|
+
readonly set: Record<string, unknown>;
|
|
112
|
+
}[]): void;
|
|
113
|
+
/**
|
|
114
|
+
* `lock: "skip"` with `limit` on one update. Absent when the caller named neither.
|
|
115
|
+
*
|
|
116
|
+
* @param input - The update target
|
|
117
|
+
* @returns The row cap, or `undefined` when this update does not claim
|
|
118
|
+
*/
|
|
119
|
+
export declare function readClaim(input: Record<string, unknown>): number | undefined;
|
|
120
|
+
export declare function rejectUpdateKeys(input: Record<string, unknown>, row: boolean): void;
|
|
121
|
+
export declare function requireFilter(table: Indexed, where: unknown, mods: WriteMods, op: WriteOp): void;
|
|
122
|
+
export declare function returningOption(table: Indexed, value: unknown): readonly ColumnModel[] | undefined;
|
|
123
|
+
export declare function expectOf(options: Record<string, unknown>, mods: WriteMods): number | undefined;
|
|
124
|
+
export declare function allowSet(table: Indexed, value: unknown): ReadonlySet<string>;
|
|
125
|
+
export declare function noteGuarded(table: Indexed, allow: ReadonlySet<string>, op: "insert" | "update"): void;
|