okmodel 0.4.0 → 0.5.1
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 +95 -12
- package/dist/contracts/catalog/document.d.ts +20 -0
- package/dist/contracts/driver.d.ts +7 -0
- package/dist/dialects/pg/filter-parse.d.ts +8 -2
- package/dist/dialects/pg/fn/index.js +8 -0
- package/dist/dialects/pg/index.js +8 -2
- package/dist/dialects/pg/introspect.d.ts +6 -0
- package/dist/dialects/pg/ops/or.d.ts +1 -1
- package/dist/dialects/pg/role/sql.d.ts +10 -0
- package/dist/dialects/pg/schema.d.ts +15 -6
- package/dist/dialects/pg/temporal.d.ts +5 -76
- package/dist/dialects/pg/view/index.d.ts +20 -6
- package/dist/dialects/pg/view/index.js +1 -1
- package/dist/dialects/pg/view/scratch.d.ts +2 -2
- package/dist/runtime/client.d.ts +6 -1
- package/dist/runtime/conflict.d.ts +2 -1
- package/dist/runtime/pg/bun.d.ts +12 -7
- package/dist/runtime/pg/bun.js +7 -4
- package/dist/runtime/pg/pg.d.ts +12 -6
- package/dist/runtime/pg/pg.js +7 -4
- package/dist/runtime/pg/pglite.d.ts +11 -3
- package/dist/runtime/pg/pglite.js +7 -4
- package/dist/runtime/pg/postgresjs.d.ts +12 -6
- package/dist/runtime/pg/postgresjs.js +7 -4
- package/dist/runtime/plan.d.ts +16 -1
- package/dist/runtime/tenancy/index.js +1 -1
- package/dist/runtime/topology.d.ts +191 -0
- package/dist/runtime/traits/index.js +7 -7
- package/dist/runtime/types.d.ts +57 -2
- package/dist/runtime/validate/index.js +3 -3
- package/dist/shared/{radd3z4g.js → 0t22wwh1.js} +5 -9
- package/dist/shared/{ady1ms74.js → 2pqx26h8.js} +25 -10
- package/dist/shared/{kyxb62mc.js → 31vm914h.js} +9 -1
- package/dist/shared/{jns2wx4t.js → 32zqc1dw.js} +18 -7
- package/dist/shared/{nxb42q7h.js → 47x8x9ze.js} +2 -2
- package/dist/shared/{zvbjc949.js → 4az561fn.js} +1 -1
- package/dist/shared/{s6gqfn5j.js → 51mvgj8w.js} +27 -3
- package/dist/shared/{k3ted12y.js → 54tqkxja.js} +20 -2
- package/dist/shared/{3p4b1fg0.js → 5enne4ma.js} +1 -1
- package/dist/shared/{6693j9rs.js → 5fqx9yh4.js} +6 -2
- package/dist/shared/{c5g81ngb.js → 6mnp99hx.js} +11 -8
- package/dist/shared/{hqjsxnz7.js → 6qd27mx0.js} +5 -4
- package/dist/shared/{v7tpnhnz.js → 6rk2gen5.js} +5 -3
- package/dist/shared/{2321avmn.js → 7zwwyh0v.js} +46 -16
- package/dist/shared/{fa9vt245.js → 87jvvhnt.js} +2 -2
- package/dist/shared/{8jb4ymh2.js → 8bwbwy8h.js} +12 -1
- package/dist/shared/{c8aghh05.js → 8rsy3hxz.js} +7 -1
- package/dist/shared/{41kv2xdm.js → 8xsbagad.js} +1 -1
- package/dist/shared/{6p5k20sm.js → 96qcj21c.js} +3 -3
- package/dist/shared/{jgxzjzcz.js → aj2qxyhj.js} +2 -2
- package/dist/shared/{5vdm4sgp.js → caw8b9d8.js} +4 -4
- package/dist/shared/{s4mb6a4b.js → cctw17hj.js} +74 -15
- package/dist/shared/{rrstp3kb.js → cgbamx3e.js} +2 -2
- package/dist/shared/{axhk06q1.js → cr74e96e.js} +1 -1
- package/dist/shared/{b066g80h.js → efmy2gcg.js} +2 -2
- package/dist/shared/{gdh9mrtp.js → f5cw5q5r.js} +2 -2
- package/dist/shared/{xghkt7a9.js → fancm5pt.js} +6 -233
- package/dist/shared/{n5y9zyj1.js → ga3sfy93.js} +369 -14
- package/dist/shared/{xrfnq5k8.js → gbtcc2d7.js} +55 -5
- package/dist/shared/{7nk68fj8.js → gde73es6.js} +20 -15
- package/dist/shared/{kkzwp3d2.js → hf22e0wt.js} +55 -19
- package/dist/shared/{tny2t3sm.js → janx09m5.js} +8 -7
- package/dist/shared/{4ef7mmqf.js → jwtxdj06.js} +5 -5
- package/dist/shared/{sf8m6tfy.js → k8v5v5wj.js} +3 -3
- package/dist/shared/{qn0srwwq.js → kfjp0gck.js} +5 -3
- package/dist/shared/{wqem4jed.js → krxx77g0.js} +7 -7
- package/dist/shared/{edwqqryd.js → nkaxvt9q.js} +1 -1
- package/dist/shared/{jsd07prz.js → ntneex2a.js} +1 -1
- package/dist/shared/nxdp2ze3.js +1197 -0
- package/dist/shared/{tbszx8mz.js → pf0d8f77.js} +1 -1
- package/dist/shared/{84ptn35q.js → ps7a6h14.js} +10 -9
- package/dist/shared/{kj680nxv.js → q58y17hy.js} +9 -7
- package/dist/shared/{awrsqrn7.js → qm7cdtvr.js} +22 -9
- package/dist/shared/{q6zsyh31.js → qv2ydck9.js} +156 -205
- package/dist/shared/{kafaa5zv.js → r2sp8hrc.js} +28 -8
- package/dist/shared/{fb00y8fp.js → r8x5qhd7.js} +5 -5
- package/dist/shared/{yjw02enp.js → sdc7r2ww.js} +8 -7
- package/dist/shared/sycnx8gt.js +289 -0
- package/dist/shared/{hcmdtwgh.js → szm0cksa.js} +4 -1
- package/dist/shared/{zg24x0hm.js → tm5ab8we.js} +10 -2
- package/dist/shared/{ygem90rn.js → v36c5g6p.js} +85 -21
- package/dist/shared/wq9n6pwr.js +139 -0
- package/dist/shared/{7p2wbz7f.js → x72jb7ad.js} +1 -1
- package/dist/shared/{q795afwa.js → z2rnngj4.js} +3 -3
- package/dist/shared/{sr5ms7b3.js → zqrnhwsq.js} +3 -3
- package/dist/tooling/cli.js +70 -23
- package/dist/tooling/migrate/apply.d.ts +2 -0
- package/dist/tooling/migrate/commands.d.ts +1 -2
- package/dist/tooling/migrate/drift.d.ts +1 -1
- package/dist/tooling/migrate/estimate.d.ts +14 -1
- package/dist/tooling/migrate/files.d.ts +7 -0
- package/dist/tooling/migrate/index.js +12 -9
- package/dist/tooling/migrate/lint.d.ts +3 -3
- package/dist/tooling/migrate/plan.d.ts +7 -3
- package/dist/tooling/migrate/policy.d.ts +11 -0
- package/dist/tooling/migrate/sql-lex.d.ts +22 -0
- package/dist/tooling/testing/factories.d.ts +10 -0
- package/dist/tooling/testing/facts.d.ts +3 -0
- package/dist/tooling/testing/index.js +3 -3
- package/dist/tooling/testing/isolation.d.ts +4 -3
- package/package.json +6 -5
- package/dist/shared/0v1g424p.js +0 -26
package/dist/runtime/pg/bun.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `connect` for Bun.sql (`okmodel/pg/bun`).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* inside the adapter.
|
|
4
|
+
* A string or an existing pool is one endpoint. A `{ primary, replicas }` object
|
|
5
|
+
* loads the topology module. The client is typed by the schema passed in.
|
|
6
|
+
* This entry runs on Bun. Node cannot load the `bun` import inside the adapter.
|
|
7
7
|
*/
|
|
8
8
|
import type { DriverPool } from "../../contracts/driver.js";
|
|
9
9
|
import type { QuerySchema } from "../../dialects/pg/model.js";
|
|
10
10
|
import { type BunSqlConfig } from "../../adapters/pg/bunsql.js";
|
|
11
|
+
import type { RoutedClient, TopologyInput, TopologyOptions } from "../topology.js";
|
|
11
12
|
import type { ConnectOptions, Connected } from "../types.js";
|
|
12
13
|
export { open, type BunSqlConfig, type BunSqlTls } from "../../adapters/pg/bunsql.js";
|
|
13
14
|
export { capabilities, hasCapability, readCapability } from "../../adapters/pg/bunsql.js";
|
|
@@ -15,16 +16,20 @@ export { DriverError } from "../../adapters/error.js";
|
|
|
15
16
|
/** A connection string or a pool from {@link open}. */
|
|
16
17
|
export type BunSqlTarget = string | DriverPool;
|
|
17
18
|
/** Driver options `connect` forwards to {@link open}. */
|
|
18
|
-
export type BunSqlConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<BunSqlConfig, "url"
|
|
19
|
+
export type BunSqlConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<BunSqlConfig, "url"> & TopologyOptions;
|
|
19
20
|
/**
|
|
20
|
-
* Connects one Postgres endpoint through Bun.sql
|
|
21
|
+
* Connects one Postgres endpoint through Bun.sql, or a primary and its replicas.
|
|
22
|
+
*
|
|
23
|
+
* A string or a pool is one endpoint. A topology loads on demand and the promise
|
|
24
|
+
* resolves to the client. Reads use the first healthy replica.
|
|
21
25
|
*
|
|
22
26
|
* Named prepared statements are off unless `prepared` is `"named"`.
|
|
23
27
|
* `prepared: "named"` is not for transaction-mode poolers.
|
|
24
28
|
*
|
|
25
29
|
* @typeParam S - Schema
|
|
26
|
-
* @param target - URL
|
|
30
|
+
* @param target - URL, an existing pool, or `{ primary, replicas }`
|
|
27
31
|
* @param options - Schema, errors, logger, and driver options
|
|
28
|
-
* @returns The client. Await `connected` for the dialect check
|
|
32
|
+
* @returns The client. A topology returns a promise. Await `connected` for the dialect check
|
|
29
33
|
*/
|
|
34
|
+
export declare function connect<const S extends QuerySchema>(target: TopologyInput, options: BunSqlConnectOptions<S>): Promise<RoutedClient<S>>;
|
|
30
35
|
export declare function connect<const S extends QuerySchema>(target: BunSqlTarget, options: BunSqlConnectOptions<S>): Connected<S>;
|
package/dist/runtime/pg/bun.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DriverError2
|
|
3
|
-
} from "../../shared/
|
|
3
|
+
} from "../../shared/31vm914h.js";
|
|
4
4
|
import {
|
|
5
5
|
open5
|
|
6
|
-
} from "../../shared/
|
|
6
|
+
} from "../../shared/k8v5v5wj.js";
|
|
7
7
|
import {
|
|
8
8
|
BUNSQL_CAPABILITIES,
|
|
9
9
|
readCapability2,
|
|
10
10
|
hasCapability2
|
|
11
|
-
} from "../../shared/
|
|
11
|
+
} from "../../shared/cgbamx3e.js";
|
|
12
12
|
import {
|
|
13
13
|
createClient
|
|
14
|
-
} from "../../shared/
|
|
14
|
+
} from "../../shared/hf22e0wt.js";
|
|
15
15
|
|
|
16
16
|
// src/runtime/pg/bun.ts
|
|
17
17
|
function connect(target, options) {
|
|
18
|
+
if (typeof target === "object" && !isPool(target)) {
|
|
19
|
+
return import("../../shared/nxdp2ze3.js").then((mod) => mod.default(target, options, open5));
|
|
20
|
+
}
|
|
18
21
|
const owned = !isPool(target);
|
|
19
22
|
const pool = isPool(target) ? target : open5({
|
|
20
23
|
url: target,
|
package/dist/runtime/pg/pg.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `connect` for node-postgres (`okmodel/pg/pg`).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* schema passed in, not
|
|
4
|
+
* A string or an existing pool is one endpoint. A `{ primary, replicas }` object
|
|
5
|
+
* loads the topology module. The client is typed by the schema passed in, not
|
|
6
|
+
* by `Register`.
|
|
6
7
|
*/
|
|
7
8
|
import type { DriverPool } from "../../contracts/driver.js";
|
|
8
9
|
import type { QuerySchema } from "../../dialects/pg/model.js";
|
|
9
10
|
import { type NodePostgresConfig } from "../../adapters/pg/nodepostgres.js";
|
|
11
|
+
import type { RoutedClient, TopologyInput, TopologyOptions } from "../topology.js";
|
|
10
12
|
import type { ConnectOptions, Connected } from "../types.js";
|
|
11
13
|
export { open, type NodePostgresConfig } from "../../adapters/pg/nodepostgres.js";
|
|
12
14
|
export { capabilities, hasCapability, readCapability } from "../../adapters/pg/nodepostgres.js";
|
|
@@ -14,16 +16,20 @@ export { DriverError } from "../../adapters/error.js";
|
|
|
14
16
|
/** A connection string or a pool from {@link open}. */
|
|
15
17
|
export type NodePostgresTarget = string | DriverPool;
|
|
16
18
|
/** Driver options `connect` forwards to {@link open}. */
|
|
17
|
-
export type NodePostgresConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<NodePostgresConfig, "url"
|
|
19
|
+
export type NodePostgresConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<NodePostgresConfig, "url"> & TopologyOptions;
|
|
18
20
|
/**
|
|
19
|
-
* Connects one Postgres endpoint through node-postgres
|
|
21
|
+
* Connects one Postgres endpoint through node-postgres, or a primary and its replicas.
|
|
22
|
+
*
|
|
23
|
+
* A string or a pool is one endpoint. A topology loads on demand and the promise
|
|
24
|
+
* resolves to the client. Reads use the first healthy replica.
|
|
20
25
|
*
|
|
21
26
|
* Named prepared statements are off unless `prepared` is `"named"`.
|
|
22
27
|
* `prepared: "named"` is not for transaction-mode poolers.
|
|
23
28
|
*
|
|
24
29
|
* @typeParam S - Schema
|
|
25
|
-
* @param target - URL
|
|
30
|
+
* @param target - URL, an existing pool, or `{ primary, replicas }`
|
|
26
31
|
* @param options - Schema, errors, logger, and driver options
|
|
27
|
-
* @returns The client. Await `connected` for the dialect check
|
|
32
|
+
* @returns The client. A topology returns a promise. Await `connected` for the dialect check
|
|
28
33
|
*/
|
|
34
|
+
export declare function connect<const S extends QuerySchema>(target: TopologyInput, options: NodePostgresConnectOptions<S>): Promise<RoutedClient<S>>;
|
|
29
35
|
export declare function connect<const S extends QuerySchema>(target: NodePostgresTarget, options: NodePostgresConnectOptions<S>): Connected<S>;
|
package/dist/runtime/pg/pg.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DriverError2
|
|
3
|
-
} from "../../shared/
|
|
3
|
+
} from "../../shared/31vm914h.js";
|
|
4
4
|
import {
|
|
5
5
|
open4
|
|
6
|
-
} from "../../shared/
|
|
6
|
+
} from "../../shared/96qcj21c.js";
|
|
7
7
|
import {
|
|
8
8
|
NODE_POSTGRES_CAPABILITIES,
|
|
9
9
|
readCapability2,
|
|
10
10
|
hasCapability2
|
|
11
|
-
} from "../../shared/
|
|
11
|
+
} from "../../shared/cgbamx3e.js";
|
|
12
12
|
import {
|
|
13
13
|
createClient
|
|
14
|
-
} from "../../shared/
|
|
14
|
+
} from "../../shared/hf22e0wt.js";
|
|
15
15
|
|
|
16
16
|
// src/runtime/pg/pg.ts
|
|
17
17
|
function connect(target, options) {
|
|
18
|
+
if (typeof target === "object" && !isPool(target)) {
|
|
19
|
+
return import("../../shared/nxdp2ze3.js").then((mod) => mod.default(target, options, open4));
|
|
20
|
+
}
|
|
18
21
|
const owned = !isPool(target);
|
|
19
22
|
const pool = isPool(target) ? target : open4({
|
|
20
23
|
url: target,
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
* `connect` for PGlite (`okmodel/pg/pglite`).
|
|
3
3
|
*
|
|
4
4
|
* Opening a database is async. An existing pool is reused and not closed.
|
|
5
|
+
* A `{ primary, replicas }` object loads the topology module. A replica URL is
|
|
6
|
+
* that endpoint's data directory.
|
|
5
7
|
*/
|
|
6
8
|
import type { DriverPool } from "../../contracts/driver.js";
|
|
7
9
|
import type { QuerySchema } from "../../dialects/pg/model.js";
|
|
8
10
|
import { type PgliteConfig } from "../../adapters/pg/pglite.js";
|
|
11
|
+
import type { RoutedClient, TopologyInput, TopologyOptions } from "../topology.js";
|
|
9
12
|
import type { ConnectOptions, Connected } from "../types.js";
|
|
10
13
|
export { open, type PgliteConfig } from "../../adapters/pg/pglite.js";
|
|
11
14
|
export { capabilities, hasCapability, readCapability } from "../../adapters/pg/pglite.js";
|
|
@@ -13,13 +16,18 @@ export { DriverError } from "../../adapters/error.js";
|
|
|
13
16
|
/** A data directory, a pool from {@link open}, or omitted for memory. */
|
|
14
17
|
export type PgliteTarget = string | DriverPool | undefined;
|
|
15
18
|
/** Driver options `connect` forwards to {@link open}. */
|
|
16
|
-
export type PgliteConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<PgliteConfig, "dataDir"
|
|
19
|
+
export type PgliteConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<PgliteConfig, "dataDir"> & TopologyOptions;
|
|
17
20
|
/**
|
|
18
|
-
* Connects one PGlite endpoint and returns a client for `schema`.
|
|
21
|
+
* Connects one PGlite endpoint, or a primary and its replicas, and returns a client for `schema`.
|
|
22
|
+
*
|
|
23
|
+
* A string, a pool, or an omitted target is one endpoint. A topology loads on
|
|
24
|
+
* demand. Reads use the first healthy replica. A replica `url` is that
|
|
25
|
+
* endpoint's data directory.
|
|
19
26
|
*
|
|
20
27
|
* @typeParam S - Schema
|
|
21
|
-
* @param target - Data directory, existing pool,
|
|
28
|
+
* @param target - Data directory, existing pool, omitted for memory, or `{ primary, replicas }`
|
|
22
29
|
* @param options - Schema, errors, and logger
|
|
23
30
|
* @returns The client
|
|
24
31
|
*/
|
|
32
|
+
export declare function connect<const S extends QuerySchema>(target: TopologyInput, options: PgliteConnectOptions<S>): Promise<RoutedClient<S>>;
|
|
25
33
|
export declare function connect<const S extends QuerySchema>(target: PgliteTarget, options: PgliteConnectOptions<S>): Promise<Connected<S>>;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DriverError2
|
|
3
|
-
} from "../../shared/
|
|
3
|
+
} from "../../shared/31vm914h.js";
|
|
4
4
|
import {
|
|
5
5
|
open3
|
|
6
|
-
} from "../../shared/
|
|
6
|
+
} from "../../shared/87jvvhnt.js";
|
|
7
7
|
import {
|
|
8
8
|
PGLITE_CAPABILITIES,
|
|
9
9
|
readCapability2,
|
|
10
10
|
hasCapability2
|
|
11
|
-
} from "../../shared/
|
|
11
|
+
} from "../../shared/cgbamx3e.js";
|
|
12
12
|
import {
|
|
13
13
|
createClient
|
|
14
|
-
} from "../../shared/
|
|
14
|
+
} from "../../shared/hf22e0wt.js";
|
|
15
15
|
|
|
16
16
|
// src/runtime/pg/pglite.ts
|
|
17
17
|
async function connect(target, options) {
|
|
18
|
+
if (typeof target === "object" && !isPool(target)) {
|
|
19
|
+
return import("../../shared/nxdp2ze3.js").then((mod) => mod.default(target, options, open3));
|
|
20
|
+
}
|
|
18
21
|
const pool = isPool(target) ? target : await open3({
|
|
19
22
|
...target !== undefined ? { dataDir: target } : {},
|
|
20
23
|
...options.timeouts !== undefined ? { timeouts: options.timeouts } : {}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `connect` for postgres.js (`okmodel/pg/postgresjs`).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* schema passed in, not
|
|
4
|
+
* A string or an existing pool is one endpoint. A `{ primary, replicas }` object
|
|
5
|
+
* loads the topology module. The client is typed by the schema passed in, not
|
|
6
|
+
* by `Register`.
|
|
6
7
|
*/
|
|
7
8
|
import type { DriverPool } from "../../contracts/driver.js";
|
|
8
9
|
import type { QuerySchema } from "../../dialects/pg/model.js";
|
|
9
10
|
import { type PostgresJsConfig } from "../../adapters/pg/postgresjs.js";
|
|
11
|
+
import type { RoutedClient, TopologyInput, TopologyOptions } from "../topology.js";
|
|
10
12
|
import type { ConnectOptions, Connected } from "../types.js";
|
|
11
13
|
export { open, type PostgresJsConfig } from "../../adapters/pg/postgresjs.js";
|
|
12
14
|
export { capabilities, hasCapability, readCapability } from "../../adapters/pg/postgresjs.js";
|
|
@@ -14,16 +16,20 @@ export { DriverError } from "../../adapters/error.js";
|
|
|
14
16
|
/** A connection string or a pool from {@link open}. */
|
|
15
17
|
export type PostgresTarget = string | DriverPool;
|
|
16
18
|
/** Driver options `connect` forwards to {@link open}. */
|
|
17
|
-
export type PostgresConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<PostgresJsConfig, "url"
|
|
19
|
+
export type PostgresConnectOptions<S extends QuerySchema> = ConnectOptions<S> & Omit<PostgresJsConfig, "url"> & TopologyOptions;
|
|
18
20
|
/**
|
|
19
|
-
* Connects one Postgres endpoint and returns a client for `schema`.
|
|
21
|
+
* Connects one Postgres endpoint, or a primary and its replicas, and returns a client for `schema`.
|
|
22
|
+
*
|
|
23
|
+
* A string or a pool is one endpoint. A topology loads on demand and the promise
|
|
24
|
+
* resolves to the client. Reads use the first healthy replica.
|
|
20
25
|
*
|
|
21
26
|
* Named prepared statements are off unless `prepared` is `"named"`.
|
|
22
27
|
* `prepared: "named"` is not for transaction-mode poolers.
|
|
23
28
|
*
|
|
24
29
|
* @typeParam S - Schema
|
|
25
|
-
* @param target - URL
|
|
30
|
+
* @param target - URL, an existing pool, or `{ primary, replicas }`
|
|
26
31
|
* @param options - Schema, errors, logger, and driver options
|
|
27
|
-
* @returns The client. Await `connected` for the dialect check
|
|
32
|
+
* @returns The client. A topology returns a promise. Await `connected` for the dialect check
|
|
28
33
|
*/
|
|
34
|
+
export declare function connect<const S extends QuerySchema>(target: TopologyInput, options: PostgresConnectOptions<S>): Promise<RoutedClient<S>>;
|
|
29
35
|
export declare function connect<const S extends QuerySchema>(target: PostgresTarget, options: PostgresConnectOptions<S>): Connected<S>;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DriverError2
|
|
3
|
-
} from "../../shared/
|
|
3
|
+
} from "../../shared/31vm914h.js";
|
|
4
4
|
import {
|
|
5
5
|
open2
|
|
6
|
-
} from "../../shared/
|
|
6
|
+
} from "../../shared/krxx77g0.js";
|
|
7
7
|
import {
|
|
8
8
|
POSTGRESJS_CAPABILITIES,
|
|
9
9
|
readCapability2,
|
|
10
10
|
hasCapability2
|
|
11
|
-
} from "../../shared/
|
|
11
|
+
} from "../../shared/cgbamx3e.js";
|
|
12
12
|
import {
|
|
13
13
|
createClient
|
|
14
|
-
} from "../../shared/
|
|
14
|
+
} from "../../shared/hf22e0wt.js";
|
|
15
15
|
|
|
16
16
|
// src/runtime/pg/postgresjs.ts
|
|
17
17
|
function connect(target, options) {
|
|
18
|
+
if (typeof target === "object" && !isPool(target)) {
|
|
19
|
+
return import("../../shared/nxdp2ze3.js").then((mod) => mod.default(target, options, open2));
|
|
20
|
+
}
|
|
18
21
|
const owned = !isPool(target);
|
|
19
22
|
const pool = isPool(target) ? target : open2({
|
|
20
23
|
url: target,
|
package/dist/runtime/plan.d.ts
CHANGED
|
@@ -41,9 +41,11 @@ export type ReadCall = {
|
|
|
41
41
|
readonly build?: ReadBuild;
|
|
42
42
|
/** Writes the end of the statement, after `limit`. A row lock sets it. */
|
|
43
43
|
readonly tail?: (sink: Sink) => void;
|
|
44
|
-
/** The caller's `signal` and `
|
|
44
|
+
/** The caller's `signal`, `timeout`, and `route`. They never enter the plan or its key. */
|
|
45
45
|
readonly signal?: AbortSignal;
|
|
46
46
|
readonly timeout?: number;
|
|
47
|
+
/** `"primary"` or `"replica"`. Absent means the router classifies the statement. */
|
|
48
|
+
readonly route?: "primary" | "replica";
|
|
47
49
|
/** Set by `for()` or `unscoped()`. Absent on a schema with no tenancy. */
|
|
48
50
|
readonly scope?: CallScope;
|
|
49
51
|
/** Inspect lines from the tenancy object. Absent when the schema has no tenancy. */
|
|
@@ -286,6 +288,19 @@ export declare function indexes(schema: QuerySchema): ReadonlyMap<string, Indexe
|
|
|
286
288
|
export declare function quote(name: string): string;
|
|
287
289
|
export declare function list(names: readonly string[]): string;
|
|
288
290
|
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
291
|
+
/**
|
|
292
|
+
* Whether `where` constrains a row.
|
|
293
|
+
*
|
|
294
|
+
* A field value is a leaf. Anything other than `undefined` counts, including
|
|
295
|
+
* `null`, objects, arrays, and operators. The walk does not enter a field value.
|
|
296
|
+
* It enters the where object's own keys, `and`, `or`, and `not` when `not` is
|
|
297
|
+
* the where itself. An `or()` branch with no predicate is OKM1121. `or([])`
|
|
298
|
+
* matches nothing.
|
|
299
|
+
*
|
|
300
|
+
* @param where - Caller filter, or one `and` / `or` / `not` operand
|
|
301
|
+
* @returns `false` when the filter matches every row
|
|
302
|
+
*/
|
|
303
|
+
export declare function effectivePredicate(where: unknown): boolean;
|
|
289
304
|
/**
|
|
290
305
|
* Records the fix text for a code thrown from a chunk that loads on first use.
|
|
291
306
|
*
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Primary and replica endpoints (spec §15.1).
|
|
3
|
+
*
|
|
4
|
+
* Loaded only when `connect` is given a topology object. The string and pool
|
|
5
|
+
* paths do not import this module. An automatic read chooses among eligible
|
|
6
|
+
* replicas. One watermark on this handle covers the root, `for()`, `unscoped()`,
|
|
7
|
+
* `using()`, and `reserve()`.
|
|
8
|
+
*/
|
|
9
|
+
import type { DriverPool, DriverTimeouts } from "../contracts/driver.js";
|
|
10
|
+
import type { QuerySchema } from "../dialects/pg/model.js";
|
|
11
|
+
import type { ConnectOptions, Connected } from "./types.js";
|
|
12
|
+
/** `"primary"` or `"replica"`. `using` and `route` accept only these. */
|
|
13
|
+
export type RouteName = "primary" | "replica";
|
|
14
|
+
/**
|
|
15
|
+
* One routing choice.
|
|
16
|
+
*
|
|
17
|
+
* `onRoute` receives this. `inspect()` does not, until the dev inspector (M2).
|
|
18
|
+
*/
|
|
19
|
+
export type RouteEvent = {
|
|
20
|
+
/** What the statement was classified as. */
|
|
21
|
+
readonly op: "read" | "write" | "tx" | "lock";
|
|
22
|
+
/** Endpoint name. The primary is `"primary"`. */
|
|
23
|
+
readonly endpoint: string;
|
|
24
|
+
/**
|
|
25
|
+
* `primary-required`, `constraint:primary`, `constraint:replica`,
|
|
26
|
+
* `auto:<name>`, or `fallback:<no-replicas | unhealthy | position-unknown | saturated | behind>`.
|
|
27
|
+
*/
|
|
28
|
+
readonly reason: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* One replica passed to a custom `routing.select`.
|
|
32
|
+
*
|
|
33
|
+
* `lag` is the replica's byte lag, or `null` when the primary insert position
|
|
34
|
+
* or the replica replay position has not been seen. `latencyMs` stays `null`
|
|
35
|
+
* until a probe or a successful read has been timed.
|
|
36
|
+
*/
|
|
37
|
+
export type ReplicaCandidate = {
|
|
38
|
+
/** Endpoint name. */
|
|
39
|
+
readonly name: string;
|
|
40
|
+
/** Configured weight. Zero and below are OKM1120 at connect. */
|
|
41
|
+
readonly weight: number;
|
|
42
|
+
/** In-flight statements this router is running on the replica. */
|
|
43
|
+
readonly inflight: number;
|
|
44
|
+
/** EWMA of observed round-trip time, in milliseconds, or `null`. */
|
|
45
|
+
readonly latencyMs: number | null;
|
|
46
|
+
/** Byte lag behind the primary, or `null` when either position is unknown. */
|
|
47
|
+
readonly lag: number | null;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* A topology client.
|
|
51
|
+
*
|
|
52
|
+
* `using` returns a client that forces one route. That client has no `close`
|
|
53
|
+
* and no `using`. Only the root closes the pools.
|
|
54
|
+
*/
|
|
55
|
+
export type RoutedClient<S extends QuerySchema> = Connected<S> & {
|
|
56
|
+
/**
|
|
57
|
+
* Forces later operations onto the primary or a replica.
|
|
58
|
+
*
|
|
59
|
+
* @param route - `"primary"` or `"replica"`
|
|
60
|
+
* @returns A client with no `close` and no `using`
|
|
61
|
+
*/
|
|
62
|
+
using(route: RouteName): Omit<Connected<S>, "close">;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Replay position for one replica.
|
|
66
|
+
*
|
|
67
|
+
* Tests supply this over independent databases. The probe still runs `SELECT 1`
|
|
68
|
+
* on the replica's pool. The position does not come from a mocked driver.
|
|
69
|
+
*/
|
|
70
|
+
export type ReplicaState = {
|
|
71
|
+
/**
|
|
72
|
+
* @param endpoint - The replica being probed
|
|
73
|
+
* @returns The replay LSN, or `null` when the replica has not replayed
|
|
74
|
+
*/
|
|
75
|
+
replayLsn(endpoint: {
|
|
76
|
+
readonly name: string;
|
|
77
|
+
}): string | null | Promise<string | null>;
|
|
78
|
+
/**
|
|
79
|
+
* Replay timestamp for a time `maxLag`.
|
|
80
|
+
*
|
|
81
|
+
* Omitted, and with no seam, the probe reads `pg_last_xact_replay_timestamp()`
|
|
82
|
+
* only when `maxLag` is a duration.
|
|
83
|
+
*
|
|
84
|
+
* @param endpoint - The replica being probed
|
|
85
|
+
* @returns A timestamp, or `null` when the replica has not replayed a transaction
|
|
86
|
+
*/
|
|
87
|
+
replayTime?(endpoint: {
|
|
88
|
+
readonly name: string;
|
|
89
|
+
}): Date | string | null | Promise<Date | string | null>;
|
|
90
|
+
};
|
|
91
|
+
/** One replica in `{ primary, replicas }`. A string is a URL with weight 1. */
|
|
92
|
+
export type ReplicaInput = {
|
|
93
|
+
readonly url: string;
|
|
94
|
+
readonly weight?: number;
|
|
95
|
+
readonly name?: string;
|
|
96
|
+
readonly pool?: {
|
|
97
|
+
readonly max?: number;
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
/** The first argument of `connect` when it is a topology. */
|
|
101
|
+
export type TopologyInput = {
|
|
102
|
+
readonly primary: string;
|
|
103
|
+
readonly replicas?: readonly (string | ReplicaInput)[];
|
|
104
|
+
};
|
|
105
|
+
/** Options only the topology module reads. */
|
|
106
|
+
export type TopologyOptions = {
|
|
107
|
+
/**
|
|
108
|
+
* Background probe interval. `"1s"` when omitted.
|
|
109
|
+
*
|
|
110
|
+
* `select` chooses among eligible replicas. The default is `"weighted"`.
|
|
111
|
+
* `consistency` is `"session"` (the default) or `"eventual"`. `maxLag` is a
|
|
112
|
+
* duration (`"5s"`, `"500ms"`, `"2m"`) or a size (`"16MB"`, `"512KB"`,
|
|
113
|
+
* `"1GB"`, `"4096B"`). `fallback` is `"primary"` (the default) or `"error"`.
|
|
114
|
+
*/
|
|
115
|
+
readonly routing?: {
|
|
116
|
+
readonly probe?: string | number;
|
|
117
|
+
readonly select?: "weighted" | "roundRobin" | "leastConnections" | "latencyAware" | ((candidates: readonly ReplicaCandidate[], ctx: {
|
|
118
|
+
readonly op: "read";
|
|
119
|
+
}) => ReplicaCandidate | string);
|
|
120
|
+
readonly consistency?: "session" | "eventual";
|
|
121
|
+
readonly fallback?: "primary" | "error";
|
|
122
|
+
readonly maxLag?: string;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Called after an endpoint is chosen.
|
|
126
|
+
*
|
|
127
|
+
* A throw is swallowed. The operation still runs.
|
|
128
|
+
*/
|
|
129
|
+
readonly onRoute?: (event: RouteEvent) => void;
|
|
130
|
+
/** Test seam for replay positions. Omitted, the probe reads `pg_last_wal_replay_lsn()`. */
|
|
131
|
+
readonly replicaState?: ReplicaState;
|
|
132
|
+
};
|
|
133
|
+
/** One endpoint after connect. Tests read this. It is not the query path. */
|
|
134
|
+
export type EndpointView = {
|
|
135
|
+
readonly name: string;
|
|
136
|
+
readonly role: "primary" | "replica";
|
|
137
|
+
readonly weight: number;
|
|
138
|
+
/** `max` passed to the driver. Absent when connect did not set one. */
|
|
139
|
+
readonly max: number | undefined;
|
|
140
|
+
/** Whether `replication.position` was detected on this endpoint. */
|
|
141
|
+
readonly position: boolean;
|
|
142
|
+
readonly circuit: "closed" | "open";
|
|
143
|
+
readonly failures: number;
|
|
144
|
+
readonly replayLsn: string | null;
|
|
145
|
+
/** Delay until the next probe. The primary is 0. */
|
|
146
|
+
readonly nextDelayMs: number;
|
|
147
|
+
};
|
|
148
|
+
/** The topology a client was built with. */
|
|
149
|
+
export type TopologyView = {
|
|
150
|
+
readonly endpoints: readonly EndpointView[];
|
|
151
|
+
};
|
|
152
|
+
/** Fields each driver's `open` may read. Extra keys are ignored by that driver. */
|
|
153
|
+
type EndpointConfig = {
|
|
154
|
+
readonly url: string;
|
|
155
|
+
readonly dataDir: string;
|
|
156
|
+
readonly max?: number;
|
|
157
|
+
readonly timeouts?: DriverTimeouts;
|
|
158
|
+
readonly prepared?: "named" | "unnamed";
|
|
159
|
+
readonly searchPath?: string;
|
|
160
|
+
readonly ssl?: unknown;
|
|
161
|
+
};
|
|
162
|
+
/** Opens one endpoint. postgres.js reads `url`. PGlite reads `dataDir`. */
|
|
163
|
+
export type EndpointOpen = (config: EndpointConfig) => DriverPool | Promise<DriverPool>;
|
|
164
|
+
/**
|
|
165
|
+
* Opens one pool per endpoint, detects `replication.position`, and starts replica probes.
|
|
166
|
+
*
|
|
167
|
+
* An automatic read runs the selection pipeline and `routing.select`.
|
|
168
|
+
* `close()` stops the probes and closes every pool this call opened,
|
|
169
|
+
* including clients from `using`.
|
|
170
|
+
*
|
|
171
|
+
* @param target - `{ primary, replicas }`
|
|
172
|
+
* @param options - Schema, pool default, probe interval, and the optional seam
|
|
173
|
+
* @param open - The driver's `open`
|
|
174
|
+
* @returns The client
|
|
175
|
+
*/
|
|
176
|
+
export declare function connectTopology<S extends QuerySchema>(target: object, options: ConnectOptions<S> & TopologyOptions & {
|
|
177
|
+
readonly max?: number;
|
|
178
|
+
readonly prepared?: "named" | "unnamed";
|
|
179
|
+
readonly searchPath?: string;
|
|
180
|
+
readonly ssl?: unknown;
|
|
181
|
+
}, open: EndpointOpen): Promise<RoutedClient<S>>;
|
|
182
|
+
/**
|
|
183
|
+
* Reads the endpoints recorded for a client this module built.
|
|
184
|
+
*
|
|
185
|
+
* A string `connect` has no record. Routing does not call this.
|
|
186
|
+
*
|
|
187
|
+
* @param client - The value `connect` returned
|
|
188
|
+
* @returns The endpoints, or `undefined` when `client` is not a topology client
|
|
189
|
+
*/
|
|
190
|
+
export declare function readTopology(client: object): TopologyView | undefined;
|
|
191
|
+
export default connectTopology;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import"../../shared/
|
|
1
|
+
import"../../shared/8bwbwy8h.js";
|
|
2
2
|
import {
|
|
3
3
|
checkPresetNames,
|
|
4
4
|
duplicatePreset
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "../../shared/n0dgs0pb.js";
|
|
9
9
|
import {
|
|
10
10
|
quoteIdent
|
|
11
|
-
} from "../../shared/
|
|
11
|
+
} from "../../shared/8xsbagad.js";
|
|
12
12
|
import {
|
|
13
13
|
functionObject,
|
|
14
14
|
triggerObject
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from "../../shared/dyj86cmj.js";
|
|
22
22
|
import {
|
|
23
23
|
snakeCase
|
|
24
|
-
} from "../../shared/
|
|
24
|
+
} from "../../shared/ntneex2a.js";
|
|
25
25
|
import {
|
|
26
26
|
ColumnBuilder2,
|
|
27
27
|
retarget
|
|
@@ -38,10 +38,10 @@ import {
|
|
|
38
38
|
queryHandle,
|
|
39
39
|
attachHttp,
|
|
40
40
|
settleCall
|
|
41
|
-
} from "../../shared/
|
|
41
|
+
} from "../../shared/hf22e0wt.js";
|
|
42
42
|
import {
|
|
43
43
|
installArchiveInspect
|
|
44
|
-
} from "../../shared/
|
|
44
|
+
} from "../../shared/gbtcc2d7.js";
|
|
45
45
|
import {
|
|
46
46
|
fitIdentifier2
|
|
47
47
|
} from "../../shared/nfzc5z0w.js";
|
|
@@ -58,7 +58,7 @@ function rewriteArchivable(self, tables, casing, schemaTraits, cascade) {
|
|
|
58
58
|
const edges = foreignKeys(tables, casing, byName);
|
|
59
59
|
const archiveSql = casing === "snake" ? "archived_at" : "archivedAt";
|
|
60
60
|
const idSql = casing === "snake" ? "archive_id" : "archiveId";
|
|
61
|
-
const predicate =
|
|
61
|
+
const predicate = casing === "snake" ? "(archived_at IS NULL)" : '("archivedAt" IS NULL)';
|
|
62
62
|
return tables.map((item) => {
|
|
63
63
|
if (!applies(self, item, schemaTraits))
|
|
64
64
|
return item;
|
|
@@ -459,7 +459,7 @@ function refuse(host, table) {
|
|
|
459
459
|
}
|
|
460
460
|
var archiveMod;
|
|
461
461
|
function loadArchive() {
|
|
462
|
-
archiveMod ??= import("../../shared/
|
|
462
|
+
archiveMod ??= import("../../shared/0t22wwh1.js");
|
|
463
463
|
return archiveMod;
|
|
464
464
|
}
|
|
465
465
|
async function settle(host, table, mods) {
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -99,6 +99,12 @@ export type CallOptions = {
|
|
|
99
99
|
readonly signal?: AbortSignal;
|
|
100
100
|
/** Milliseconds. The call fails as `timeout` when it runs longer. */
|
|
101
101
|
readonly timeout?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Forces this read onto the primary or a replica.
|
|
104
|
+
*
|
|
105
|
+
* Absent, a topology client chooses. A single endpoint serves either value.
|
|
106
|
+
*/
|
|
107
|
+
readonly route?: "primary" | "replica";
|
|
102
108
|
};
|
|
103
109
|
/** Options shared by reads. */
|
|
104
110
|
export type ReadOptions<S extends QuerySchema, K extends keyof S["~byName"]> = CallOptions & {
|
|
@@ -602,6 +608,55 @@ export type TxClient<S extends QuerySchema, Root extends boolean = false> = {
|
|
|
602
608
|
*/
|
|
603
609
|
advisoryLock(key: string | number | bigint, options?: CallOptions): Promise<void>;
|
|
604
610
|
} & TxApi<S, Root>;
|
|
611
|
+
/** A view field: its column name in camel case, as the client publishes it. */
|
|
612
|
+
type CamelName<N extends string> = N extends `_${infer Rest}` ? CamelName<Rest> : N extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<CamelName<Tail>>}` : N;
|
|
613
|
+
/** One view row. Every column is decoded as text, so each field is a string or null. */
|
|
614
|
+
type ViewRow<D> = D extends {
|
|
615
|
+
readonly "~columns"?: infer C extends readonly {
|
|
616
|
+
readonly name: string;
|
|
617
|
+
}[];
|
|
618
|
+
} ? {
|
|
619
|
+
readonly [Col in C[number] as CamelName<Col["name"]>]: string | null;
|
|
620
|
+
} : never;
|
|
621
|
+
/** Options `find` and `one` take on a view. */
|
|
622
|
+
type ViewReadOptions<Row> = CallOptions & {
|
|
623
|
+
readonly where?: FieldWhere<Row>;
|
|
624
|
+
readonly select?: readonly (keyof Row & string)[];
|
|
625
|
+
readonly orderBy?: OrderBy<Row>;
|
|
626
|
+
readonly limit?: number;
|
|
627
|
+
};
|
|
628
|
+
/** The read-only handle `db.views` holds for one view. */
|
|
629
|
+
type ViewApi<Row> = {
|
|
630
|
+
find<const O extends ViewReadOptions<Row> & {
|
|
631
|
+
readonly limit: number;
|
|
632
|
+
}>(options: O): Read<readonly Show<Selected<Row, O extends {
|
|
633
|
+
readonly select: infer Sel;
|
|
634
|
+
} ? Sel : undefined>>[]>;
|
|
635
|
+
find<const O extends ViewReadOptions<Row>>(options: O): {
|
|
636
|
+
all(reason: string): Read<readonly Show<Selected<Row, O extends {
|
|
637
|
+
readonly select: infer Sel;
|
|
638
|
+
} ? Sel : undefined>>[]>;
|
|
639
|
+
};
|
|
640
|
+
one<const O extends ViewReadOptions<Row>>(options?: O): Read<Show<Selected<Row, O extends {
|
|
641
|
+
readonly select: infer Sel;
|
|
642
|
+
} ? Sel : undefined>> | null>;
|
|
643
|
+
count(options?: CallOptions & {
|
|
644
|
+
readonly where?: FieldWhere<Row>;
|
|
645
|
+
}): Read<number>;
|
|
646
|
+
exists(options?: CallOptions & {
|
|
647
|
+
readonly where?: FieldWhere<Row>;
|
|
648
|
+
}): Read<boolean>;
|
|
649
|
+
};
|
|
650
|
+
/** `db.views`, typed from `schema({ views })`. Absent when the schema declares none. */
|
|
651
|
+
type ViewsClient<S> = S extends {
|
|
652
|
+
readonly "~views": infer V extends readonly unknown[];
|
|
653
|
+
} ? {
|
|
654
|
+
readonly views: {
|
|
655
|
+
readonly [D in V[number] as D extends {
|
|
656
|
+
readonly name: infer N extends string;
|
|
657
|
+
} ? CamelName<N> : never]: ViewApi<Show<ViewRow<D>>>;
|
|
658
|
+
};
|
|
659
|
+
} : unknown;
|
|
605
660
|
/** A client whose tables are already inside one tenant or an unscoped reason. */
|
|
606
661
|
type ScopedClient<S extends QuerySchema> = {
|
|
607
662
|
readonly [K in keyof S["~byName"] & string]: TableApi<S, K>;
|
|
@@ -612,7 +667,7 @@ type ScopedClient<S extends QuerySchema> = {
|
|
|
612
667
|
close(): Promise<void>;
|
|
613
668
|
/** Resolves when the dialect and `requires` checks have finished. */
|
|
614
669
|
readonly connected: Promise<void>;
|
|
615
|
-
} & TxApi<S, false> & IfAsyncDisposable<typeof Symbol>;
|
|
670
|
+
} & TxApi<S, false> & ViewsClient<S> & IfAsyncDisposable<typeof Symbol>;
|
|
616
671
|
/** `for` and `unscoped` on a schema that set tenancy. */
|
|
617
672
|
type ScopeMethods<S extends QuerySchema> = TenantKeyOf<S> extends never ? object : {
|
|
618
673
|
/**
|
|
@@ -650,7 +705,7 @@ export type Connected<S extends QuerySchema> = {
|
|
|
650
705
|
close(): Promise<void>;
|
|
651
706
|
/** Resolves when the dialect and `requires` checks have finished. */
|
|
652
707
|
readonly connected: Promise<void>;
|
|
653
|
-
} & TxApi<S, true> & ScopeMethods<S> & IfAsyncDisposable<typeof Symbol>;
|
|
708
|
+
} & TxApi<S, true> & ScopeMethods<S> & ViewsClient<S> & IfAsyncDisposable<typeof Symbol>;
|
|
654
709
|
/**
|
|
655
710
|
* A catalog `okm build` wrote.
|
|
656
711
|
*
|