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
|
@@ -78,6 +78,38 @@ export declare const BUNSQL_CAPABILITIES: {
|
|
|
78
78
|
readonly prepared: "unnamed";
|
|
79
79
|
readonly describe: false;
|
|
80
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Neon WebSocket pool execution flags.
|
|
83
|
+
*
|
|
84
|
+
* Interactive transactions pass on a direct connection. `stream`, `listen`,
|
|
85
|
+
* `cancel`, and `describe` stay false: a server cursor, `LISTEN`, and a
|
|
86
|
+
* side-channel cancel are session features the pooler does not keep, and the
|
|
87
|
+
* client has no describe API. Statements use the unnamed protocol.
|
|
88
|
+
* `prepared: "named"` is not for a transaction-mode pooler.
|
|
89
|
+
*/
|
|
90
|
+
export declare const NEON_WEBSOCKET_CAPABILITIES: {
|
|
91
|
+
readonly transactions: "interactive";
|
|
92
|
+
readonly stream: false;
|
|
93
|
+
readonly listen: false;
|
|
94
|
+
readonly cancel: false;
|
|
95
|
+
readonly prepared: "unnamed";
|
|
96
|
+
readonly describe: false;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Neon HTTP execution flags.
|
|
100
|
+
*
|
|
101
|
+
* One request is one statement. `sql.transaction` is the atomic batch.
|
|
102
|
+
* There is no interactive `tx()`, no `LISTEN`, no server cursor, and no
|
|
103
|
+
* cancel of a statement the server has already started.
|
|
104
|
+
*/
|
|
105
|
+
export declare const NEON_HTTP_CAPABILITIES: {
|
|
106
|
+
readonly transactions: "batch";
|
|
107
|
+
readonly stream: false;
|
|
108
|
+
readonly listen: false;
|
|
109
|
+
readonly cancel: false;
|
|
110
|
+
readonly prepared: "none";
|
|
111
|
+
readonly describe: false;
|
|
112
|
+
};
|
|
81
113
|
/**
|
|
82
114
|
* Reads one capability flag.
|
|
83
115
|
*
|
|
@@ -22,7 +22,7 @@ export declare function rejectClosed(): Promise<never>;
|
|
|
22
22
|
/**
|
|
23
23
|
* Rejects with OKM1120 when a driver cannot cancel a positive timeout.
|
|
24
24
|
*
|
|
25
|
-
* The message stays `timeout`. Kind stays `invalid`. Bun.sql and
|
|
25
|
+
* The message stays `timeout`. Kind stays `invalid`. Bun.sql, PGlite, and Neon call
|
|
26
26
|
* this. Other drivers do not, so their connect graphs omit it.
|
|
27
27
|
*
|
|
28
28
|
* @returns A rejected promise
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice of Bun.sql this adapter uses.
|
|
3
|
+
*
|
|
4
|
+
* `bun` is the runtime, not an npm package, and it ships no types. The
|
|
5
|
+
* published declarations name these types instead of importing `bun`, so a
|
|
6
|
+
* consumer can typecheck `okmodel/pg/bun` without `bun-types`.
|
|
7
|
+
*/
|
|
8
|
+
/** A pending query. `raw()` asks for rows as arrays. */
|
|
9
|
+
export interface SQLQuery extends Promise<unknown> {
|
|
10
|
+
/** Rows as arrays instead of objects. */
|
|
11
|
+
raw(): SQLQuery;
|
|
12
|
+
}
|
|
13
|
+
/** One pooled Bun.sql client. */
|
|
14
|
+
export interface SQL {
|
|
15
|
+
/**
|
|
16
|
+
* Runs a statement.
|
|
17
|
+
*
|
|
18
|
+
* @param text - SQL text
|
|
19
|
+
* @param values - Positional parameters
|
|
20
|
+
*/
|
|
21
|
+
unsafe(text: string, values?: readonly unknown[]): SQLQuery;
|
|
22
|
+
/**
|
|
23
|
+
* Checks out one connection.
|
|
24
|
+
*
|
|
25
|
+
* @param options - `signal` aborts the wait
|
|
26
|
+
*/
|
|
27
|
+
reserve(options?: {
|
|
28
|
+
readonly signal?: AbortSignal;
|
|
29
|
+
}): Promise<ReservedSQL>;
|
|
30
|
+
/** Closes the pool. */
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Subscribes to one `LISTEN` channel.
|
|
34
|
+
*
|
|
35
|
+
* @param channel - Channel name
|
|
36
|
+
* @param onnotify - Payload callback
|
|
37
|
+
*/
|
|
38
|
+
listen(channel: string, onnotify: (payload: string) => void): Promise<SQLListen>;
|
|
39
|
+
}
|
|
40
|
+
/** A `LISTEN` registration. */
|
|
41
|
+
export interface SQLListen {
|
|
42
|
+
/** Drops this registration. */
|
|
43
|
+
unlisten(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One connection reserved from {@link SQL.reserve}.
|
|
47
|
+
*
|
|
48
|
+
* `release` returns it to the pool.
|
|
49
|
+
*/
|
|
50
|
+
export interface ReservedSQL extends SQL {
|
|
51
|
+
/** Returns the connection to the pool. */
|
|
52
|
+
release(): void;
|
|
53
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Loaded on the first reserve, batch, stream, or dead connection. A read that
|
|
5
5
|
* succeeds does not use it.
|
|
6
6
|
*/
|
|
7
|
-
import type { ReservedSQL, SQL } from "bun";
|
|
7
|
+
import type { ReservedSQL, SQL } from "./bun-sql.js";
|
|
8
8
|
import type { DriverConnection, WireValue } from "../../contracts/driver.js";
|
|
9
9
|
import { type HeldPool } from "./bunsql.js";
|
|
10
10
|
/**
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* finished script exits without `close()`. `Query.cancel()` does not abort
|
|
10
10
|
* the backend, so `cancel` is false. Server notices are not surfaced.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import type { ReservedSQL, SQL } from "./bun-sql.js";
|
|
13
13
|
import type { DriverPool, DriverPoolConfig, WireValue } from "../../contracts/driver.js";
|
|
14
14
|
import { DriverError } from "../error.js";
|
|
15
15
|
import { noticeBuffer, type WireQuery } from "./session.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reserved connections for the Neon WebSocket pool.
|
|
3
|
+
*
|
|
4
|
+
* Loaded on the first reserve or batch. A read does not use it.
|
|
5
|
+
*/
|
|
6
|
+
import type { DriverConnection } from "../../contracts/driver.js";
|
|
7
|
+
import { type HeldPool } from "./neon.js";
|
|
8
|
+
/**
|
|
9
|
+
* Checks out one client and clears it on release.
|
|
10
|
+
*
|
|
11
|
+
* A client whose connection is gone is destroyed on release, and nothing more
|
|
12
|
+
* is sent to it. A checked-out client has no pool error listener, so one is
|
|
13
|
+
* set here: without it a dropped socket is an uncaught `error` event.
|
|
14
|
+
*
|
|
15
|
+
* @param held - The pool and its counters
|
|
16
|
+
* @returns A connection the caller must release
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkout(held: HeldPool): Promise<DriverConnection>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Neon adapter (`okmodel/pg/neon`).
|
|
3
|
+
*
|
|
4
|
+
* `@neondatabase/serverless` is an optional peer. This module is the only
|
|
5
|
+
* place that imports it. `mode: "websocket"` (the default) is a pooled
|
|
6
|
+
* WebSocket client with interactive transactions. `mode: "http"` is one HTTP
|
|
7
|
+
* request per statement, and `batch` is the driver's non-interactive
|
|
8
|
+
* transaction. A positive `timeout` is refused: neither mode aborts a
|
|
9
|
+
* statement the server has already started.
|
|
10
|
+
*
|
|
11
|
+
* The first WebSocket `open` sets `webSocketConstructor` only when it is
|
|
12
|
+
* still unset, so a caller can install one first. A transaction-mode pooler
|
|
13
|
+
* does not promise session state. One small compute can reuse a backend, so
|
|
14
|
+
* a custom `SET`, `LISTEN`, or a prepared statement may still be visible.
|
|
15
|
+
*/
|
|
16
|
+
import { Pool, type PoolClient } from "@neondatabase/serverless";
|
|
17
|
+
import type { DriverPool, DriverPoolConfig, WireValue } from "../../contracts/driver.js";
|
|
18
|
+
import { noticeBuffer, type WireQuery } from "./session.js";
|
|
19
|
+
export { NEON_WEBSOCKET_CAPABILITIES as capabilities, NEON_HTTP_CAPABILITIES as httpCapabilities, hasCapability, readCapability, } from "../capabilities.js";
|
|
20
|
+
export { DriverError } from "../error.js";
|
|
21
|
+
/** How {@link open} talks to Neon. */
|
|
22
|
+
export type NeonMode = "websocket" | "http";
|
|
23
|
+
/** Options for {@link open}. */
|
|
24
|
+
export type NeonConfig = DriverPoolConfig & {
|
|
25
|
+
/** Connection URL for this endpoint. */
|
|
26
|
+
readonly url: string;
|
|
27
|
+
/**
|
|
28
|
+
* `websocket` is a pooled WebSocket client. `http` is one-shot HTTP.
|
|
29
|
+
*
|
|
30
|
+
* Omitted means `websocket`.
|
|
31
|
+
*/
|
|
32
|
+
readonly mode?: NeonMode;
|
|
33
|
+
/**
|
|
34
|
+
* Named prepared statements, or the unnamed protocol.
|
|
35
|
+
*
|
|
36
|
+
* Unnamed is the default. It stays valid behind a pooler in transaction mode.
|
|
37
|
+
* `prepared: "named"` is not for transaction-mode poolers. HTTP ignores it.
|
|
38
|
+
*/
|
|
39
|
+
readonly prepared?: "named" | "unnamed";
|
|
40
|
+
/** Session search path for every WebSocket connection in the pool. */
|
|
41
|
+
readonly searchPath?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Pool occupancy. */
|
|
44
|
+
export type Counters = {
|
|
45
|
+
reserved: number;
|
|
46
|
+
busy: number;
|
|
47
|
+
reservedBusy: number;
|
|
48
|
+
waiting: number;
|
|
49
|
+
};
|
|
50
|
+
/** What a WebSocket checkout needs from the pool that opened it. */
|
|
51
|
+
export type HeldPool = {
|
|
52
|
+
readonly pool: Pool;
|
|
53
|
+
readonly acquireMs: number | undefined;
|
|
54
|
+
readonly counters: Counters;
|
|
55
|
+
readonly notices: ReturnType<typeof noticeBuffer>;
|
|
56
|
+
readonly named: boolean;
|
|
57
|
+
readonly isClosed: () => boolean;
|
|
58
|
+
};
|
|
59
|
+
/** A client that can run one array-mode statement. */
|
|
60
|
+
type Queryable = {
|
|
61
|
+
query(config: {
|
|
62
|
+
text: string;
|
|
63
|
+
values?: readonly WireValue[];
|
|
64
|
+
rowMode: "array";
|
|
65
|
+
types: typeof WIRE;
|
|
66
|
+
name?: string;
|
|
67
|
+
}): Promise<unknown>;
|
|
68
|
+
};
|
|
69
|
+
declare const WIRE: {
|
|
70
|
+
getTypeParser(): (value: string) => string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Opens a Neon pool for one endpoint.
|
|
74
|
+
*
|
|
75
|
+
* WebSocket mode connects once before returning, so a later short acquire
|
|
76
|
+
* timeout measures the queue and not a cold start. HTTP mode does not open a
|
|
77
|
+
* socket.
|
|
78
|
+
*
|
|
79
|
+
* @param config - URL, mode, pool size, and acquire timeout
|
|
80
|
+
* @returns The pool
|
|
81
|
+
*/
|
|
82
|
+
export declare function open(config: NeonConfig): Promise<DriverPool>;
|
|
83
|
+
/**
|
|
84
|
+
* Checks out one WebSocket client.
|
|
85
|
+
*
|
|
86
|
+
* The wait uses `timeouts.acquire`. A timeout is OKM1846 and does not keep the
|
|
87
|
+
* client.
|
|
88
|
+
*
|
|
89
|
+
* @param pool - Neon pool
|
|
90
|
+
* @param acquireMs - Wait ceiling, when one was set
|
|
91
|
+
* @param counters - Pool occupancy
|
|
92
|
+
* @returns The client
|
|
93
|
+
*/
|
|
94
|
+
export declare function connectClient(pool: Pool, acquireMs: number | undefined, counters: Counters): Promise<PoolClient>;
|
|
95
|
+
/**
|
|
96
|
+
* Sends one statement and returns the driver's promise.
|
|
97
|
+
*
|
|
98
|
+
* @param runner - Pool or checked-out client
|
|
99
|
+
* @param text - SQL
|
|
100
|
+
* @param params - Wire parameters
|
|
101
|
+
* @param named - Use a named prepared statement
|
|
102
|
+
* @returns The pending result
|
|
103
|
+
*/
|
|
104
|
+
export declare function send(runner: Queryable, text: string, params: readonly WireValue[] | undefined, named: boolean): WireQuery;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Refusal for a driver that cannot cancel an in-flight statement (D224).
|
|
3
3
|
*
|
|
4
|
-
* Bun.sql and
|
|
4
|
+
* Bun.sql, PGlite, and Neon refuse a positive `timeout`. The OKM1120 text loads with
|
|
5
5
|
* the lazy error module, so a connect entry does not carry it. Kind is
|
|
6
6
|
* `invalid`, which separates it from kind `timeout`. `timeout: 0` still fails
|
|
7
7
|
* immediately as kind `timeout`. `signal` is unchanged. postgres.js and
|
|
@@ -31,7 +31,7 @@ export type ColumnCode = (typeof COLUMN_CODES)[number];
|
|
|
31
31
|
* These are spec §21 codes. They are a type only, so the runtime entry does
|
|
32
32
|
* not gain a second registry.
|
|
33
33
|
*/
|
|
34
|
-
export type QueryCode = "OKM1101" | "OKM1102" | "OKM1104" | "OKM1105" | "OKM1111" | "OKM1120" | "OKM1121" | "OKM1124" | "OKM1130" | "OKM1190" | "OKM1701" | "OKM1704" | "OKM1801" | "OKM1802" | "OKM1803" | "OKM1843";
|
|
34
|
+
export type QueryCode = "OKM1101" | "OKM1102" | "OKM1104" | "OKM1105" | "OKM1111" | "OKM1120" | "OKM1121" | "OKM1124" | "OKM1125" | "OKM1130" | "OKM1190" | "OKM1701" | "OKM1704" | "OKM1801" | "OKM1802" | "OKM1803" | "OKM1843";
|
|
35
35
|
/** Kinds from spec §14, in category order. */
|
|
36
36
|
export declare const ERROR_KINDS: readonly ["invalid", "not_null", "check", "foreign_key", "unique", "exclusion", "conflict", "not_found", "not_unique", "forbidden", "serialization", "deadlock", "lock_timeout", "timeout", "cancelled", "unavailable", "schema_drift", "driver", "read_only", "outcome_unknown"];
|
|
37
37
|
/** One spec §14 kind. */
|
|
@@ -5,12 +5,46 @@
|
|
|
5
5
|
* records. `schema()` only asks each declared object for those records.
|
|
6
6
|
*/
|
|
7
7
|
import type { CatalogObject, FunctionLanguage, FunctionSecurity, FunctionVolatility, TriggerEvent, TriggerLevel, TriggerTiming } from "../../../contracts/catalog/types.js";
|
|
8
|
+
import { type FragmentIdent } from "../ops/fragment.js";
|
|
9
|
+
import { type Eq } from "../operators.js";
|
|
10
|
+
import type { Window } from "../ops/window.js";
|
|
8
11
|
import type { AnyTable, SqlText } from "../table.js";
|
|
9
12
|
/** One argument of {@link fn}. */
|
|
10
13
|
export type FunctionArgumentInput = {
|
|
11
14
|
readonly name: string;
|
|
12
15
|
readonly type: string;
|
|
13
16
|
};
|
|
17
|
+
/** Postgres types that bind as a number. Anything else binds as text. */
|
|
18
|
+
type NumericReturn = "smallint" | "integer" | "bigint" | "int2" | "int4" | "int8" | "real" | "double precision" | "float4" | "float8" | "numeric";
|
|
19
|
+
/** A select name for {@link FnCall.as}. Numeric returns are numbers. Text stays text. */
|
|
20
|
+
type CallAs<R extends string, A extends string> = R extends NumericReturn | `numeric${string}` ? Window<A, number> : Window<A, string>;
|
|
21
|
+
/**
|
|
22
|
+
* A typed call.
|
|
23
|
+
*
|
|
24
|
+
* It is a `sql` fragment, so `where` accepts it as {@link Eq}. `.as(name)` is
|
|
25
|
+
* the `select` form. `orderBy` does not: adding the call to that union is one
|
|
26
|
+
* composite type over the ceiling.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam R - Declared return type
|
|
29
|
+
*/
|
|
30
|
+
export type FnCall<R extends string = string> = Eq<never> & {
|
|
31
|
+
/**
|
|
32
|
+
* Names the select result.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam A - Result key
|
|
35
|
+
* @param name - Result key. Not a column name
|
|
36
|
+
* @returns A select entry
|
|
37
|
+
*/
|
|
38
|
+
as<const A extends string>(name: A): CallAs<R, A>;
|
|
39
|
+
};
|
|
40
|
+
/** One argument value. `ident` names a field. Null is SQL null. */
|
|
41
|
+
type CallValue<T extends string> = T extends "boolean" | "bool" ? boolean | FragmentIdent | null : T extends NumericReturn | `numeric${string}` ? number | FragmentIdent | null : string | FragmentIdent | null;
|
|
42
|
+
/** Argument list of a call, in declaration order. */
|
|
43
|
+
type CallArgs<A extends readonly FunctionArgumentInput[]> = {
|
|
44
|
+
[I in keyof A]: A[I] extends FunctionArgumentInput ? CallValue<A[I]["type"]> : never;
|
|
45
|
+
};
|
|
46
|
+
/** `fn.slugify(col)`. The value is {@link FnCall}. */
|
|
47
|
+
type FnCaller<A extends readonly FunctionArgumentInput[], R extends string> = (...args: CallArgs<A>) => FnCall<R>;
|
|
14
48
|
/**
|
|
15
49
|
* A table, or one column of a table.
|
|
16
50
|
*
|
|
@@ -96,7 +130,10 @@ export type TriggerDeclaration = {
|
|
|
96
130
|
* @param options - Signature, language, body, and dependencies
|
|
97
131
|
* @returns The definition object `schema({ functions })` stores
|
|
98
132
|
*/
|
|
99
|
-
export declare function fn(name: string, options: FunctionOptions
|
|
133
|
+
export declare function fn<const A extends readonly FunctionArgumentInput[] = readonly [], const R extends string = string>(name: string, options: FunctionOptions & {
|
|
134
|
+
readonly arguments?: A;
|
|
135
|
+
readonly returns: R;
|
|
136
|
+
}): Routine & FnCaller<A, R>;
|
|
100
137
|
/**
|
|
101
138
|
* Declares a trigger.
|
|
102
139
|
*
|
|
@@ -105,3 +142,4 @@ export declare function fn(name: string, options: FunctionOptions): Routine;
|
|
|
105
142
|
* @returns The definition object `schema({ triggers })` stores
|
|
106
143
|
*/
|
|
107
144
|
export declare function trigger(name: string, options: TriggerOptions): TriggerDeclaration;
|
|
145
|
+
export {};
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
functionObject,
|
|
3
3
|
triggerObject
|
|
4
|
-
} from "../../../shared/
|
|
4
|
+
} from "../../../shared/12z7aznj.js";
|
|
5
|
+
import {
|
|
6
|
+
isFragmentParts,
|
|
7
|
+
sqlExpression,
|
|
8
|
+
identName
|
|
9
|
+
} from "../../../shared/bsek72fg.js";
|
|
10
|
+
import {
|
|
11
|
+
quoteIdent
|
|
12
|
+
} from "../../../shared/sjk86yrx.js";
|
|
5
13
|
import {
|
|
6
14
|
staticNamespace2
|
|
7
15
|
} from "../../../shared/358zsv4r.js";
|
|
16
|
+
import {
|
|
17
|
+
isOperator,
|
|
18
|
+
operatorName,
|
|
19
|
+
operatorValue
|
|
20
|
+
} from "../../../shared/cn0n68ft.js";
|
|
8
21
|
import {
|
|
9
22
|
assertIdentifier2
|
|
10
23
|
} from "../../../shared/nfzc5z0w.js";
|
|
@@ -36,32 +49,111 @@ function fn(name, options) {
|
|
|
36
49
|
}
|
|
37
50
|
const argTypes = (options.arguments ?? []).map((argument) => argument.type);
|
|
38
51
|
const schema = options.schema ?? "public";
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
dependencies: dependencyEdges(options.dependsOn, built)
|
|
61
|
-
})
|
|
62
|
-
];
|
|
63
|
-
}
|
|
52
|
+
const declared = options.arguments ?? [];
|
|
53
|
+
const contribute = (peers, built) => {
|
|
54
|
+
assertPeers(peers, "functions");
|
|
55
|
+
const namespace = staticNamespace2(schema);
|
|
56
|
+
const provenance = { origin: "file", name };
|
|
57
|
+
return [
|
|
58
|
+
functionObject({
|
|
59
|
+
namespace,
|
|
60
|
+
name,
|
|
61
|
+
...options.arguments !== undefined ? { arguments: options.arguments } : {},
|
|
62
|
+
returns: options.returns,
|
|
63
|
+
language,
|
|
64
|
+
...options.volatility !== undefined ? { volatility: options.volatility } : {},
|
|
65
|
+
...options.security !== undefined ? { security: options.security } : {},
|
|
66
|
+
...options.searchPath !== undefined ? { searchPath: options.searchPath } : {},
|
|
67
|
+
body,
|
|
68
|
+
...atomic ? { atomic: true } : {},
|
|
69
|
+
provenance,
|
|
70
|
+
dependencies: dependencyEdges(options.dependsOn, built)
|
|
71
|
+
})
|
|
72
|
+
];
|
|
64
73
|
};
|
|
74
|
+
const call = (...args) => invoke(schema, name, declared, options.returns, args);
|
|
75
|
+
define(call, "name", name);
|
|
76
|
+
define(call, "schema", schema);
|
|
77
|
+
define(call, "argTypes", argTypes);
|
|
78
|
+
define(call, "contribute", contribute);
|
|
79
|
+
return call;
|
|
80
|
+
}
|
|
81
|
+
function define(target, key, value) {
|
|
82
|
+
Object.defineProperty(target, key, {
|
|
83
|
+
value,
|
|
84
|
+
enumerable: true,
|
|
85
|
+
writable: true,
|
|
86
|
+
configurable: true
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
var NUMERIC_RETURNS = new Set([
|
|
90
|
+
"smallint",
|
|
91
|
+
"integer",
|
|
92
|
+
"bigint",
|
|
93
|
+
"int2",
|
|
94
|
+
"int4",
|
|
95
|
+
"int8",
|
|
96
|
+
"real",
|
|
97
|
+
"double precision",
|
|
98
|
+
"float4",
|
|
99
|
+
"float8",
|
|
100
|
+
"numeric"
|
|
101
|
+
]);
|
|
102
|
+
function invoke(schemaName, name, declared, returns, args) {
|
|
103
|
+
if (args.length !== declared.length) {
|
|
104
|
+
throw new OkmError2("OKM1120", `Function ${name} expects ${String(declared.length)} arguments.`, { fix: { summary: "Pass one value for each declared argument, in order." } });
|
|
105
|
+
}
|
|
106
|
+
const parts = [{ k: "t", s: `${quoteIdent(schemaName)}.${quoteIdent(name)}(` }];
|
|
107
|
+
for (let index = 0;index < args.length; index += 1) {
|
|
108
|
+
if (index > 0)
|
|
109
|
+
parts.push({ k: "t", s: ", " });
|
|
110
|
+
appendArg(parts, args[index], name);
|
|
111
|
+
}
|
|
112
|
+
parts.push({ k: "t", s: ")" });
|
|
113
|
+
const textual = !(NUMERIC_RETURNS.has(returns) || returns.startsWith("numeric("));
|
|
114
|
+
return sqlExpression(parts, textual);
|
|
115
|
+
}
|
|
116
|
+
function appendArg(parts, value, name) {
|
|
117
|
+
if (value === null) {
|
|
118
|
+
parts.push({ k: "n" });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (typeof value === "string" || typeof value === "boolean") {
|
|
122
|
+
parts.push({ k: "p", v: String(value) });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (typeof value === "number") {
|
|
126
|
+
if (!Number.isFinite(value)) {
|
|
127
|
+
throw new OkmError2("OKM1120", `Function ${name} needs a finite number.`, {
|
|
128
|
+
fix: { summary: "Pass a finite number, or leave it out." }
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
parts.push({ k: "p", v: String(value) });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const field = identName(value);
|
|
135
|
+
if (field !== undefined) {
|
|
136
|
+
parts.push({ k: "i", n: field });
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (isOperator(value) && operatorName(value) === "sql") {
|
|
140
|
+
const stored = operatorValue(value);
|
|
141
|
+
if (isFragmentParts(stored)) {
|
|
142
|
+
parts.push({ k: "f", parts: stored });
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (isHandle(value)) {
|
|
147
|
+
assertIdentifier2(value.name, `function ${name}`);
|
|
148
|
+
parts.push({ k: "i", n: value.name });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
throw new OkmError2("OKM1121", `Function ${name} received a value it cannot bind.`, {
|
|
152
|
+
fix: { summary: "Pass a string, number, boolean, null, or ident(field)." }
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function isHandle(value) {
|
|
156
|
+
return typeof value === "object" && value !== null && "name" in value && typeof value.name === "string" && value.name.length > 0 && !isOperator(value);
|
|
65
157
|
}
|
|
66
158
|
function trigger(name, options) {
|
|
67
159
|
return {
|
|
@@ -57,4 +57,6 @@ export { or } from "./ops/or.js";
|
|
|
57
57
|
export { overlaps } from "./ops/overlaps.js";
|
|
58
58
|
export { path } from "./ops/path.js";
|
|
59
59
|
export { startsWith } from "./ops/startsWith.js";
|
|
60
|
+
export { fragment, ident, type Fragment } from "./ops/fragment.js";
|
|
61
|
+
export { explain, raw, type ExplainResult } from "./ops/lane.js";
|
|
60
62
|
export { many, manyThrough, morph, morphMany, morphTo, one, type ManyRelation, type ManyThroughRelation, type MorphManyRelation, type MorphRelation, type OneRelation, type RelationCall, } from "./relations.js";
|