okmodel 0.0.0 → 0.1.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 +246 -1
- package/dist/adapters/capabilities.d.ts +62 -0
- package/dist/adapters/error.d.ts +91 -0
- package/dist/adapters/failure.d.ts +39 -0
- package/dist/adapters/pg/batch.d.ts +36 -0
- package/dist/adapters/pg/call.d.ts +59 -0
- package/dist/adapters/pg/pglite.d.ts +21 -0
- package/dist/adapters/pg/postgres-extra.d.ts +43 -0
- package/dist/adapters/pg/postgresjs.d.ts +95 -0
- package/dist/adapters/pg/result.d.ts +30 -0
- package/dist/contracts/catalog/build.d.ts +18 -0
- package/dist/contracts/catalog/document.d.ts +79 -0
- package/dist/contracts/catalog/enum.d.ts +35 -0
- package/dist/contracts/catalog/identifier.d.ts +71 -0
- package/dist/contracts/catalog/identity.d.ts +98 -0
- package/dist/contracts/catalog/index.d.ts +11 -0
- package/dist/contracts/catalog/json.d.ts +17 -0
- package/dist/contracts/catalog/object.d.ts +142 -0
- package/dist/contracts/catalog/order.d.ts +43 -0
- package/dist/contracts/catalog/rewrite.d.ts +18 -0
- package/dist/contracts/catalog/types.d.ts +292 -0
- package/dist/contracts/catalog/words.d.ts +13 -0
- package/dist/contracts/connection.d.ts +33 -0
- package/dist/contracts/driver.d.ts +163 -0
- package/dist/contracts/error.d.ts +298 -0
- package/dist/contracts/index.d.ts +11 -0
- package/dist/contracts/index.js +16 -0
- package/dist/contracts/internal.d.ts +15 -0
- package/dist/contracts/internal.js +68 -0
- package/dist/contracts/nearest.d.ts +15 -0
- package/dist/contracts/rows.d.ts +84 -0
- package/dist/contracts/sha256.d.ts +14 -0
- package/dist/contracts/utf8.d.ts +33 -0
- package/dist/dialects/pg/array-literal.d.ts +25 -0
- package/dist/dialects/pg/bool.d.ts +46 -0
- package/dist/dialects/pg/column.d.ts +386 -0
- package/dist/dialects/pg/compile.d.ts +81 -0
- package/dist/dialects/pg/custom.d.ts +21 -0
- package/dist/dialects/pg/ddl.d.ts +70 -0
- package/dist/dialects/pg/decimal.d.ts +62 -0
- package/dist/dialects/pg/declarations.d.ts +34 -0
- package/dist/dialects/pg/emit.d.ts +18 -0
- package/dist/dialects/pg/enum.d.ts +30 -0
- package/dist/dialects/pg/errors.d.ts +30 -0
- package/dist/dialects/pg/finite.d.ts +15 -0
- package/dist/dialects/pg/geometry.d.ts +55 -0
- package/dist/dialects/pg/index.d.ts +45 -0
- package/dist/dialects/pg/index.js +1821 -0
- package/dist/dialects/pg/integer.d.ts +96 -0
- package/dist/dialects/pg/introspect.d.ts +43 -0
- package/dist/dialects/pg/json.d.ts +43 -0
- package/dist/dialects/pg/keys.d.ts +32 -0
- package/dist/dialects/pg/misuse.d.ts +31 -0
- package/dist/dialects/pg/model.d.ts +71 -0
- package/dist/dialects/pg/namespace.d.ts +63 -0
- package/dist/dialects/pg/network.d.ts +28 -0
- package/dist/dialects/pg/operators.d.ts +71 -0
- package/dist/dialects/pg/ops/between.d.ts +10 -0
- package/dist/dialects/pg/ops/contains.d.ts +8 -0
- package/dist/dialects/pg/ops/endsWith.d.ts +8 -0
- package/dist/dialects/pg/ops/eq.d.ts +9 -0
- package/dist/dialects/pg/ops/every.d.ts +9 -0
- package/dist/dialects/pg/ops/gt.d.ts +9 -0
- package/dist/dialects/pg/ops/gte.d.ts +9 -0
- package/dist/dialects/pg/ops/has.d.ts +9 -0
- package/dist/dialects/pg/ops/ilike.d.ts +8 -0
- package/dist/dialects/pg/ops/inList.d.ts +9 -0
- package/dist/dialects/pg/ops/inc.d.ts +13 -0
- package/dist/dialects/pg/ops/like.d.ts +8 -0
- package/dist/dialects/pg/ops/lt.d.ts +9 -0
- package/dist/dialects/pg/ops/lte.d.ts +9 -0
- package/dist/dialects/pg/ops/none.d.ts +9 -0
- package/dist/dialects/pg/ops/not.d.ts +9 -0
- package/dist/dialects/pg/ops/notIn.d.ts +9 -0
- package/dist/dialects/pg/ops/or.d.ts +9 -0
- package/dist/dialects/pg/ops/startsWith.d.ts +8 -0
- package/dist/dialects/pg/quote.d.ts +24 -0
- package/dist/dialects/pg/range.d.ts +50 -0
- package/dist/dialects/pg/relations.d.ts +45 -0
- package/dist/dialects/pg/schema.d.ts +77 -0
- package/dist/dialects/pg/search.d.ts +23 -0
- package/dist/dialects/pg/table.d.ts +201 -0
- package/dist/dialects/pg/temporal.d.ts +211 -0
- package/dist/dialects/pg/text.d.ts +44 -0
- package/dist/dialects/pg/time.d.ts +46 -0
- package/dist/okm.js +2 -0
- package/dist/okmodel.js +2 -0
- package/dist/runtime/client.d.ts +47 -0
- package/dist/runtime/conflict.d.ts +38 -0
- package/dist/runtime/drift-detail.d.ts +32 -0
- package/dist/runtime/drift.d.ts +29 -0
- package/dist/runtime/include.d.ts +15 -0
- package/dist/runtime/pg/pglite.d.ts +25 -0
- package/dist/runtime/pg/pglite.js +48 -0
- package/dist/runtime/pg/postgresjs.d.ts +29 -0
- package/dist/runtime/pg/postgresjs.js +62 -0
- package/dist/runtime/plan.d.ts +167 -0
- package/dist/runtime/tx.d.ts +29 -0
- package/dist/runtime/types.d.ts +385 -0
- package/dist/runtime/write.d.ts +48 -0
- package/dist/shared/05w44d8g.js +1524 -0
- package/dist/shared/523ft3e8.js +171 -0
- package/dist/shared/8b04d28c.js +14 -0
- package/dist/shared/cn0n68ft.js +16 -0
- package/dist/shared/dkn3y60a.js +374 -0
- package/dist/shared/dynq16vb.js +81 -0
- package/dist/shared/fgqgsb5z.js +281 -0
- package/dist/shared/g5fhqmwe.js +188 -0
- package/dist/shared/gk7cs7sp.js +566 -0
- package/dist/shared/hadrfb9h.js +398 -0
- package/dist/shared/hd293j9g.js +98 -0
- package/dist/shared/j5cn2963.js +701 -0
- package/dist/shared/jjb7yht9.js +37 -0
- package/dist/shared/kprcwaha.js +30 -0
- package/dist/shared/m3ypagh5.js +347 -0
- package/dist/shared/mkjmqjv4.js +456 -0
- package/dist/shared/mtkwv8wx.js +18 -0
- package/dist/shared/ngk8gj61.js +40 -0
- package/dist/shared/p0cbr3g2.js +79 -0
- package/dist/shared/qk3hxfja.js +83 -0
- package/dist/shared/rgs0st28.js +1066 -0
- package/dist/shared/w8samvk1.js +18 -0
- package/dist/shared/x5x59srr.js +566 -0
- package/dist/shared/xqbhg6cn.js +119 -0
- package/dist/shared/xy79j5hq.js +177 -0
- package/dist/shared/y9m15dfv.js +888 -0
- package/dist/shared/ycwz42az.js +412 -0
- package/dist/shared/yd1kzwn2.js +148 -0
- package/dist/shared/zhc5vmgf.js +257 -0
- package/dist/tooling/cli.d.ts +1 -0
- package/dist/tooling/cli.js +193 -0
- package/dist/tooling/errors/registry.d.ts +33 -0
- package/dist/tooling/migrate/apply.d.ts +86 -0
- package/dist/tooling/migrate/commands.d.ts +21 -0
- package/dist/tooling/migrate/config.d.ts +48 -0
- package/dist/tooling/migrate/dev.d.ts +16 -0
- package/dist/tooling/migrate/equal.d.ts +15 -0
- package/dist/tooling/migrate/files.d.ts +19 -0
- package/dist/tooling/migrate/index.d.ts +7 -0
- package/dist/tooling/migrate/index.js +7 -0
- package/dist/tooling/migrate/plan.d.ts +76 -0
- package/dist/tooling/migrate/policy.d.ts +78 -0
- package/dist/tooling/migrate/project.d.ts +69 -0
- package/dist/tooling/migrate/status.d.ts +74 -0
- package/dist/tooling/migrate/values.d.ts +29 -0
- package/package.json +109 -7
- package/dist/index.js +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* smallint, integer, and bigint.
|
|
3
|
+
*
|
|
4
|
+
* Bigint defaults to a decimal string. `as` selects number or bigint.
|
|
5
|
+
*/
|
|
6
|
+
import { type ColumnBuilder, type IdentityFlags, type PlainFlags } from "./column.js";
|
|
7
|
+
/** How a bigint value is represented in TypeScript. */
|
|
8
|
+
export type BigintAs = "string" | "number" | "bigint";
|
|
9
|
+
/**
|
|
10
|
+
* 16-bit integer.
|
|
11
|
+
*
|
|
12
|
+
* @returns A smallint column
|
|
13
|
+
*/
|
|
14
|
+
export declare function smallint(): ColumnBuilder<number, PlainFlags>;
|
|
15
|
+
/**
|
|
16
|
+
* 32-bit integer.
|
|
17
|
+
*
|
|
18
|
+
* @returns An integer column
|
|
19
|
+
*/
|
|
20
|
+
export declare function integer(): ColumnBuilder<number, PlainFlags>;
|
|
21
|
+
/** TypeScript value for a bigint codec mode. */
|
|
22
|
+
export type BigintValue<TAs extends BigintAs> = TAs extends "number" ? number : TAs extends "bigint" ? bigint : string;
|
|
23
|
+
/**
|
|
24
|
+
* 64-bit integer. The default codec is a decimal string.
|
|
25
|
+
*
|
|
26
|
+
* @typeParam TAs - `string`, `number`, or `bigint`
|
|
27
|
+
* @param options - `as` overrides the TypeScript representation
|
|
28
|
+
* @returns A bigint column
|
|
29
|
+
*/
|
|
30
|
+
export declare function bigint<const TAs extends BigintAs = "string">(options?: {
|
|
31
|
+
readonly as?: TAs;
|
|
32
|
+
}): ColumnBuilder<BigintValue<TAs>, PlainFlags>;
|
|
33
|
+
/**
|
|
34
|
+
* `bigint` identity column, `GENERATED ALWAYS AS IDENTITY`.
|
|
35
|
+
*
|
|
36
|
+
* Insert and update omit it. The codec follows the same `as` modes as {@link bigint}.
|
|
37
|
+
*
|
|
38
|
+
* @typeParam TAs - `string`, `number`, or `bigint`
|
|
39
|
+
* @param options - Codec selection
|
|
40
|
+
* @returns An identity column
|
|
41
|
+
*/
|
|
42
|
+
export declare function identity<const TAs extends BigintAs = "string">(options?: {
|
|
43
|
+
readonly as?: TAs;
|
|
44
|
+
}): ColumnBuilder<BigintValue<TAs>, IdentityFlags>;
|
|
45
|
+
/**
|
|
46
|
+
* Encodes a bigint decimal string.
|
|
47
|
+
*
|
|
48
|
+
* @param value - Decimal integer
|
|
49
|
+
* @returns The same spelling when it is a canonical integer
|
|
50
|
+
*/
|
|
51
|
+
export declare function encodeBigintString(value: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Decodes a bigint decimal string.
|
|
54
|
+
*
|
|
55
|
+
* @param wire - Decimal integer
|
|
56
|
+
* @returns The same spelling
|
|
57
|
+
*/
|
|
58
|
+
export declare function decodeBigintString(wire: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Encodes a safe integer as a bigint literal.
|
|
61
|
+
*
|
|
62
|
+
* @param value - Safe integer
|
|
63
|
+
* @returns Decimal text
|
|
64
|
+
*/
|
|
65
|
+
export declare function encodeBigintNumber(value: number): string;
|
|
66
|
+
/**
|
|
67
|
+
* Decodes a bigint literal that fits in a safe integer.
|
|
68
|
+
*
|
|
69
|
+
* @param wire - Decimal integer
|
|
70
|
+
* @returns A safe integer
|
|
71
|
+
*/
|
|
72
|
+
export declare function decodeBigintNumber(wire: string): number;
|
|
73
|
+
/**
|
|
74
|
+
* Encodes a native bigint.
|
|
75
|
+
*
|
|
76
|
+
* @param value - Bigint
|
|
77
|
+
* @returns Decimal text
|
|
78
|
+
*/
|
|
79
|
+
export declare function encodeBigintValue(value: bigint): string;
|
|
80
|
+
/**
|
|
81
|
+
* Decodes a bigint literal to a native bigint.
|
|
82
|
+
*
|
|
83
|
+
* @param wire - Decimal integer
|
|
84
|
+
* @returns A bigint
|
|
85
|
+
*/
|
|
86
|
+
export declare function decodeBigintValue(wire: string): bigint;
|
|
87
|
+
/**
|
|
88
|
+
* Encodes an integer that must lie in a closed range.
|
|
89
|
+
*
|
|
90
|
+
* @param value - Integer
|
|
91
|
+
* @param min - Inclusive lower bound
|
|
92
|
+
* @param max - Inclusive upper bound
|
|
93
|
+
* @param role - Type name used in the error
|
|
94
|
+
* @returns Decimal text
|
|
95
|
+
*/
|
|
96
|
+
export declare function integerToken(value: number, min: number, max: number, role: string): string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a Postgres schema into a catalog.
|
|
3
|
+
*
|
|
4
|
+
* Copied partition primary keys and inherited indexes are not objects: a
|
|
5
|
+
* relation that is a child in `pg_inherits` is skipped, and so is an index
|
|
6
|
+
* that is itself inherited (M0-06). Expressions come back from `pg_get_expr`
|
|
7
|
+
* and `pg_get_constraintdef`, which is the database's normalised text (D128).
|
|
8
|
+
*/
|
|
9
|
+
import type { Catalog } from "../../contracts/catalog/types.js";
|
|
10
|
+
/** A connection that can run one query. Parameters are `$1`, `$2`, … */
|
|
11
|
+
export type CatalogQuery = {
|
|
12
|
+
/**
|
|
13
|
+
* Runs one query.
|
|
14
|
+
*
|
|
15
|
+
* @param text - SQL
|
|
16
|
+
* @param params - Bound parameters
|
|
17
|
+
* @returns Rows as objects keyed by the select aliases
|
|
18
|
+
*/
|
|
19
|
+
query(text: string, params?: readonly string[]): Promise<readonly Record<string, unknown>[]>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Introspects one concrete schema.
|
|
23
|
+
*
|
|
24
|
+
* Identities use `logical`, not the concrete schema name, so two scratch
|
|
25
|
+
* schemas compare. The default logical namespace is `public`.
|
|
26
|
+
*
|
|
27
|
+
* @param runner - Database connection
|
|
28
|
+
* @param concrete - Schema to read
|
|
29
|
+
* @param logical - Namespace stored on the catalog identities
|
|
30
|
+
* @returns A checked catalog
|
|
31
|
+
*/
|
|
32
|
+
export declare function introspectSchema(runner: CatalogQuery, concrete: string, logical?: string): Promise<Catalog>;
|
|
33
|
+
/**
|
|
34
|
+
* Applies one expression as a check and reads Postgres's reprint.
|
|
35
|
+
*
|
|
36
|
+
* Two authoring spellings of the same predicate compare equal after this.
|
|
37
|
+
* A different predicate does not.
|
|
38
|
+
*
|
|
39
|
+
* @param runner - Database connection
|
|
40
|
+
* @param expression - Check expression without the `CHECK` keyword
|
|
41
|
+
* @returns The reprinted expression, without the `CHECK` keyword
|
|
42
|
+
*/
|
|
43
|
+
export declare function reprintCheck(runner: CatalogQuery, expression: string): Promise<string>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* json, jsonb, and the bigint JSON replacer.
|
|
3
|
+
*/
|
|
4
|
+
import { type ColumnBuilder, type PlainFlags } from "./column.js";
|
|
5
|
+
/**
|
|
6
|
+
* `JSON.stringify` replacer that writes bigint as a decimal string.
|
|
7
|
+
*
|
|
8
|
+
* `JSON.stringify` throws on a bigint. Projects that choose `bigint: "bigint"`
|
|
9
|
+
* pass this to `JSON.stringify`.
|
|
10
|
+
*
|
|
11
|
+
* @param _key - Property name. Unused
|
|
12
|
+
* @param value - Value about to be serialised
|
|
13
|
+
* @returns A string for bigint, otherwise the value
|
|
14
|
+
*/
|
|
15
|
+
export declare function jsonReplacer(_key: string, value: unknown): unknown;
|
|
16
|
+
/**
|
|
17
|
+
* JSON text. `T` is the TypeScript shape; the codec does not check it.
|
|
18
|
+
*
|
|
19
|
+
* @typeParam T - JSON value type
|
|
20
|
+
* @returns A json column
|
|
21
|
+
*/
|
|
22
|
+
export declare function json<T = unknown>(): ColumnBuilder<T, PlainFlags>;
|
|
23
|
+
/**
|
|
24
|
+
* Binary JSON. `T` is the TypeScript shape; the codec does not check it.
|
|
25
|
+
*
|
|
26
|
+
* @typeParam T - JSON value type
|
|
27
|
+
* @returns A jsonb column
|
|
28
|
+
*/
|
|
29
|
+
export declare function jsonb<T = unknown>(): ColumnBuilder<T, PlainFlags>;
|
|
30
|
+
/**
|
|
31
|
+
* Encodes JSON. Bigint values become decimal strings.
|
|
32
|
+
*
|
|
33
|
+
* @param value - JSON value
|
|
34
|
+
* @returns JSON text
|
|
35
|
+
*/
|
|
36
|
+
export declare function encodeJson(value: unknown): string;
|
|
37
|
+
/**
|
|
38
|
+
* Decodes JSON text.
|
|
39
|
+
*
|
|
40
|
+
* @param wire - JSON text
|
|
41
|
+
* @returns The parsed value
|
|
42
|
+
*/
|
|
43
|
+
export declare function decodeJson(wire: string): unknown;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UUID keys.
|
|
3
|
+
*/
|
|
4
|
+
import { type ColumnBuilder, type IdFlags, type PlainFlags } from "./column.js";
|
|
5
|
+
/**
|
|
6
|
+
* UUID primary key with default `uuidv7()`.
|
|
7
|
+
*
|
|
8
|
+
* Insert and update omit it, and it is guarded.
|
|
9
|
+
*
|
|
10
|
+
* @returns An id column
|
|
11
|
+
*/
|
|
12
|
+
export declare function id(): ColumnBuilder<string, IdFlags>;
|
|
13
|
+
/**
|
|
14
|
+
* UUID text, with no default.
|
|
15
|
+
*
|
|
16
|
+
* @returns A uuid column
|
|
17
|
+
*/
|
|
18
|
+
export declare function uuid(): ColumnBuilder<string, PlainFlags>;
|
|
19
|
+
/**
|
|
20
|
+
* Encodes a UUID as lowercase hex with hyphens.
|
|
21
|
+
*
|
|
22
|
+
* @param value - UUID text
|
|
23
|
+
* @returns Canonical UUID
|
|
24
|
+
*/
|
|
25
|
+
export declare function encodeUuid(value: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Decodes UUID text.
|
|
28
|
+
*
|
|
29
|
+
* @param wire - UUID text
|
|
30
|
+
* @returns Canonical UUID
|
|
31
|
+
*/
|
|
32
|
+
export declare function decodeUuid(wire: string): string;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column and codec failures from spec section 21 (D130).
|
|
3
|
+
*
|
|
4
|
+
* OKM1060 is an invalid column definition. OKM1061 is a reserved option this
|
|
5
|
+
* version does not implement. OKM1210 is a value a codec rejects.
|
|
6
|
+
* Messages name the accepted values.
|
|
7
|
+
*/
|
|
8
|
+
/** Invalid length, precision, scale, rank, qualifier, or value list. */
|
|
9
|
+
export declare const COLUMN_DEFINITION_CODE = "OKM1060";
|
|
10
|
+
/** A table or schema option reserved for a later prompt. */
|
|
11
|
+
export declare const RESERVED_OPTION_CODE = "OKM1061";
|
|
12
|
+
/** A codec rejected a value. */
|
|
13
|
+
export declare const CODEC_VALUE_CODE = "OKM1210";
|
|
14
|
+
/**
|
|
15
|
+
* Throws OKM1060.
|
|
16
|
+
*
|
|
17
|
+
* @param message - What is wrong with the column definition, including accepted values
|
|
18
|
+
*/
|
|
19
|
+
export declare function definition(message: string): never;
|
|
20
|
+
/**
|
|
21
|
+
* Throws OKM1061.
|
|
22
|
+
*
|
|
23
|
+
* @param message - Which option is reserved, and the prompt or milestone that adds it
|
|
24
|
+
*/
|
|
25
|
+
export declare function unavailable(message: string): never;
|
|
26
|
+
/**
|
|
27
|
+
* Throws OKM1210.
|
|
28
|
+
*
|
|
29
|
+
* @param message - What the codec refused, including accepted values
|
|
30
|
+
*/
|
|
31
|
+
export declare function rejected(message: string): never;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime table model the read path compiles against.
|
|
3
|
+
*
|
|
4
|
+
* `schema()` fills it once. Query planning does not walk column builders again.
|
|
5
|
+
*/
|
|
6
|
+
/** One column the planner can filter, select, decode, and write. */
|
|
7
|
+
export type ColumnModel = {
|
|
8
|
+
/** Field name. */
|
|
9
|
+
readonly field: string;
|
|
10
|
+
/** SQL name, already checked as an identifier. */
|
|
11
|
+
readonly sql: string;
|
|
12
|
+
/** Catalog type, used when a value is projected through JSON. */
|
|
13
|
+
readonly dataType: string;
|
|
14
|
+
/** Codec encode. Identity text still returns the same string. */
|
|
15
|
+
readonly encode: (value: unknown) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Codec decode.
|
|
18
|
+
*
|
|
19
|
+
* Omitted when the wire text is the TypeScript value, so a row does not
|
|
20
|
+
* call a codec it does not need.
|
|
21
|
+
*/
|
|
22
|
+
readonly decode: ((wire: string) => unknown) | undefined;
|
|
23
|
+
/** Excluded from a default select. Named selects still return it. */
|
|
24
|
+
readonly hidden: boolean;
|
|
25
|
+
/** Refused when present in insert or update input. */
|
|
26
|
+
readonly guarded: boolean;
|
|
27
|
+
/** Included in insert and update. Guarded, generated, and omitted columns are not. */
|
|
28
|
+
readonly writable: boolean;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A resolved relation.
|
|
32
|
+
*
|
|
33
|
+
* The join is always `related.{remote} = this.{local}`.
|
|
34
|
+
*/
|
|
35
|
+
export type RelationModel = {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly kind: "one" | "many";
|
|
38
|
+
/** Related table's TypeScript name. */
|
|
39
|
+
readonly table: string;
|
|
40
|
+
/** SQL names on this table. */
|
|
41
|
+
readonly local: readonly string[];
|
|
42
|
+
/** SQL names on the related table. */
|
|
43
|
+
readonly remote: readonly string[];
|
|
44
|
+
};
|
|
45
|
+
/** One table, keyed by its TypeScript name on the schema. */
|
|
46
|
+
export type TableModel = {
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly sql: string;
|
|
49
|
+
/** Primary-key field names, in catalog order. */
|
|
50
|
+
readonly primary: readonly string[];
|
|
51
|
+
/**
|
|
52
|
+
* Field lists that `onConflict.on` may name.
|
|
53
|
+
*
|
|
54
|
+
* Each list is a primary key or a unique constraint. Order is the catalog order.
|
|
55
|
+
*/
|
|
56
|
+
readonly uniques: readonly (readonly string[])[];
|
|
57
|
+
readonly columns: readonly ColumnModel[];
|
|
58
|
+
readonly relations: readonly RelationModel[];
|
|
59
|
+
};
|
|
60
|
+
/** Schema fields the read path and `connect()` read. */
|
|
61
|
+
export type QuerySchema = {
|
|
62
|
+
readonly "~byName": {
|
|
63
|
+
readonly [name: string]: {
|
|
64
|
+
readonly "~row": unknown;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
readonly model: Readonly<Record<string, TableModel>>;
|
|
68
|
+
readonly requires?: {
|
|
69
|
+
readonly postgres?: string;
|
|
70
|
+
} | undefined;
|
|
71
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `t` namespace from spec section 6.4.
|
|
3
|
+
*
|
|
4
|
+
* Importing `t` pulls every builder. Import one builder when an application
|
|
5
|
+
* uses only that type.
|
|
6
|
+
*/
|
|
7
|
+
import { boolean, bytea } from "./bool.js";
|
|
8
|
+
import { custom } from "./custom.js";
|
|
9
|
+
import { double, numeric, real } from "./decimal.js";
|
|
10
|
+
import { domain, enumColumn } from "./enum.js";
|
|
11
|
+
import { line, point } from "./geometry.js";
|
|
12
|
+
import { bigint, identity, integer, smallint } from "./integer.js";
|
|
13
|
+
import { json, jsonb } from "./json.js";
|
|
14
|
+
import { id, uuid } from "./keys.js";
|
|
15
|
+
import { cidr, inet, macaddr, macaddr8 } from "./network.js";
|
|
16
|
+
import { daterange, int4range, int8range, numrange, tstzrange } from "./range.js";
|
|
17
|
+
import { ltree, tsvector } from "./search.js";
|
|
18
|
+
import { char, citext, text, varchar } from "./text.js";
|
|
19
|
+
import { date, interval, time, timestamp, timestamptz, timetz } from "./time.js";
|
|
20
|
+
/**
|
|
21
|
+
* Postgres column builders.
|
|
22
|
+
*/
|
|
23
|
+
export declare const t: {
|
|
24
|
+
id: typeof id;
|
|
25
|
+
identity: typeof identity;
|
|
26
|
+
uuid: typeof uuid;
|
|
27
|
+
smallint: typeof smallint;
|
|
28
|
+
integer: typeof integer;
|
|
29
|
+
bigint: typeof bigint;
|
|
30
|
+
numeric: typeof numeric;
|
|
31
|
+
real: typeof real;
|
|
32
|
+
double: typeof double;
|
|
33
|
+
text: typeof text;
|
|
34
|
+
varchar: typeof varchar;
|
|
35
|
+
char: typeof char;
|
|
36
|
+
citext: typeof citext;
|
|
37
|
+
boolean: typeof boolean;
|
|
38
|
+
bytea: typeof bytea;
|
|
39
|
+
json: typeof json;
|
|
40
|
+
jsonb: typeof jsonb;
|
|
41
|
+
timestamptz: typeof timestamptz;
|
|
42
|
+
timestamp: typeof timestamp;
|
|
43
|
+
date: typeof date;
|
|
44
|
+
time: typeof time;
|
|
45
|
+
timetz: typeof timetz;
|
|
46
|
+
interval: typeof interval;
|
|
47
|
+
tstzrange: typeof tstzrange;
|
|
48
|
+
daterange: typeof daterange;
|
|
49
|
+
int4range: typeof int4range;
|
|
50
|
+
int8range: typeof int8range;
|
|
51
|
+
numrange: typeof numrange;
|
|
52
|
+
inet: typeof inet;
|
|
53
|
+
cidr: typeof cidr;
|
|
54
|
+
macaddr: typeof macaddr;
|
|
55
|
+
macaddr8: typeof macaddr8;
|
|
56
|
+
point: typeof point;
|
|
57
|
+
line: typeof line;
|
|
58
|
+
tsvector: typeof tsvector;
|
|
59
|
+
ltree: typeof ltree;
|
|
60
|
+
enum: typeof enumColumn;
|
|
61
|
+
domain: typeof domain;
|
|
62
|
+
custom: typeof custom;
|
|
63
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Network address columns. Values are canonical text.
|
|
3
|
+
*/
|
|
4
|
+
import { type ColumnBuilder, type PlainFlags } from "./column.js";
|
|
5
|
+
/**
|
|
6
|
+
* IPv4 or IPv6 host, with an optional prefix.
|
|
7
|
+
*
|
|
8
|
+
* @returns An inet column
|
|
9
|
+
*/
|
|
10
|
+
export declare function inet(): ColumnBuilder<string, PlainFlags>;
|
|
11
|
+
/**
|
|
12
|
+
* IPv4 or IPv6 network. A prefix is required.
|
|
13
|
+
*
|
|
14
|
+
* @returns A cidr column
|
|
15
|
+
*/
|
|
16
|
+
export declare function cidr(): ColumnBuilder<string, PlainFlags>;
|
|
17
|
+
/**
|
|
18
|
+
* 48-bit MAC address, lowercase.
|
|
19
|
+
*
|
|
20
|
+
* @returns A macaddr column
|
|
21
|
+
*/
|
|
22
|
+
export declare function macaddr(): ColumnBuilder<string, PlainFlags>;
|
|
23
|
+
/**
|
|
24
|
+
* 64-bit MAC address, lowercase.
|
|
25
|
+
*
|
|
26
|
+
* @returns A macaddr8 column
|
|
27
|
+
*/
|
|
28
|
+
export declare function macaddr8(): ColumnBuilder<string, PlainFlags>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tagged filter operators (spec §10.1, D125).
|
|
3
|
+
*
|
|
4
|
+
* The brand is a symbol. JSON cannot create one, so request data cannot add
|
|
5
|
+
* an operator or traverse a relation. A plain object stays OKM1121.
|
|
6
|
+
*/
|
|
7
|
+
declare const brand: unique symbol;
|
|
8
|
+
declare const RUNTIME: unique symbol;
|
|
9
|
+
/** Operator names the read path compiles. */
|
|
10
|
+
export type OperatorName = "eq" | "lt" | "lte" | "gt" | "gte" | "between" | "startsWith" | "contains" | "endsWith" | "like" | "ilike" | "inList" | "notIn" | "not" | "or" | "has" | "none" | "every" | "inc";
|
|
11
|
+
/** A tagged operator. `value` is the operand the helper stored. */
|
|
12
|
+
export type Tagged<Name extends OperatorName, V> = {
|
|
13
|
+
readonly [brand]: Name;
|
|
14
|
+
readonly value: V;
|
|
15
|
+
};
|
|
16
|
+
/** Equality, including json and jsonb (D125). */
|
|
17
|
+
export type Eq<V> = Tagged<"eq", V>;
|
|
18
|
+
/** One-sided comparison. */
|
|
19
|
+
export type Compare<Name extends "lt" | "lte" | "gt" | "gte", V> = Tagged<Name, V>;
|
|
20
|
+
/** Inclusive range. */
|
|
21
|
+
export type Between<V> = Tagged<"between", readonly [V, V]>;
|
|
22
|
+
/** A literal pattern. `%`, `_`, and `\` in the value are escaped. */
|
|
23
|
+
export type Pattern<Name extends "startsWith" | "contains" | "endsWith"> = Tagged<Name, string>;
|
|
24
|
+
/** A raw `LIKE` or `ILIKE` pattern. The caller owns the wildcards. */
|
|
25
|
+
export type RawPattern<Name extends "like" | "ilike"> = Tagged<Name, string>;
|
|
26
|
+
/** Membership. An empty list matches nothing. */
|
|
27
|
+
export type InList<V> = Tagged<"inList", readonly V[]>;
|
|
28
|
+
/** The complement of {@link InList}. An empty list matches everything. */
|
|
29
|
+
export type NotIn<V> = Tagged<"notIn", readonly V[]>;
|
|
30
|
+
/** Negation of null, a value, or another operator. */
|
|
31
|
+
export type Not<V> = Tagged<"not", V>;
|
|
32
|
+
/** Disjunction. Each branch is a where object. */
|
|
33
|
+
export type Or<V> = Tagged<"or", readonly V[]>;
|
|
34
|
+
/** A relation filter. The value is the related table's where. */
|
|
35
|
+
export type RelationFilter<Name extends "has" | "none" | "every", V> = Tagged<Name, V>;
|
|
36
|
+
type AnyTagged = {
|
|
37
|
+
readonly [RUNTIME]: OperatorName;
|
|
38
|
+
readonly value: unknown;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Reports whether `value` is a tagged operator.
|
|
42
|
+
*
|
|
43
|
+
* @param value - A where operand
|
|
44
|
+
* @returns `true` when a helper created it
|
|
45
|
+
*/
|
|
46
|
+
export declare function isOperator(value: unknown): value is AnyTagged;
|
|
47
|
+
/**
|
|
48
|
+
* Reads the operator name.
|
|
49
|
+
*
|
|
50
|
+
* @param value - A value {@link isOperator} accepted
|
|
51
|
+
* @returns The helper that created it
|
|
52
|
+
*/
|
|
53
|
+
export declare function operatorName(value: AnyTagged): OperatorName;
|
|
54
|
+
/**
|
|
55
|
+
* Reads the operand.
|
|
56
|
+
*
|
|
57
|
+
* @param value - A value {@link isOperator} accepted
|
|
58
|
+
* @returns The operand the helper stored
|
|
59
|
+
*/
|
|
60
|
+
export declare function operatorValue(value: AnyTagged): unknown;
|
|
61
|
+
/**
|
|
62
|
+
* Tags an operator. Each helper lives in its own module so unused ones drop out.
|
|
63
|
+
*
|
|
64
|
+
* @typeParam Name - Operator name
|
|
65
|
+
* @typeParam V - Operand
|
|
66
|
+
* @param name - Operator name
|
|
67
|
+
* @param value - Operand
|
|
68
|
+
* @returns A tagged operator
|
|
69
|
+
*/
|
|
70
|
+
export declare function tag<Name extends OperatorName, V>(name: Name, value: V): Tagged<Name, V>;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Between } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Inclusive range.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam V - Operand
|
|
6
|
+
* @param from - Lower bound
|
|
7
|
+
* @param to - Upper bound
|
|
8
|
+
* @returns A tagged operator
|
|
9
|
+
*/
|
|
10
|
+
export declare function between<const V>(from: V, to: V): Between<V>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Pattern } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Case-sensitive substring. `%`, `_`, and `\` in `value` are escaped.
|
|
4
|
+
*
|
|
5
|
+
* @param value - Literal substring
|
|
6
|
+
* @returns A tagged operator
|
|
7
|
+
*/
|
|
8
|
+
export declare function contains(value: string): Pattern<"contains">;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Pattern } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Case-sensitive suffix. `%`, `_`, and `\` in `value` are escaped.
|
|
4
|
+
*
|
|
5
|
+
* @param value - Literal suffix
|
|
6
|
+
* @returns A tagged operator
|
|
7
|
+
*/
|
|
8
|
+
export declare function endsWith(value: string): Pattern<"endsWith">;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Eq } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Equality. This is the form for json and jsonb (D125).
|
|
4
|
+
*
|
|
5
|
+
* @typeParam V - Operand
|
|
6
|
+
* @param value - Value to compare
|
|
7
|
+
* @returns A tagged operator
|
|
8
|
+
*/
|
|
9
|
+
export declare function eq<const V>(value: V): Eq<V>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RelationFilter } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Every related row matches. True when there are no related rows.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam V - Related where
|
|
6
|
+
* @param where - Filter on the related table
|
|
7
|
+
* @returns A relation filter
|
|
8
|
+
*/
|
|
9
|
+
export declare function every<const V>(where: V): RelationFilter<"every", V>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RelationFilter } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Related rows exist.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam V - Related where
|
|
6
|
+
* @param where - Filter on the related table
|
|
7
|
+
* @returns A relation filter
|
|
8
|
+
*/
|
|
9
|
+
export declare function has<const V>(where: V): RelationFilter<"has", V>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type InList } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Membership. An empty list matches nothing and does not become `IN ()`.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam V - Element
|
|
6
|
+
* @param values - Accepted values
|
|
7
|
+
* @returns A tagged operator
|
|
8
|
+
*/
|
|
9
|
+
export declare function inList<const V>(values: readonly V[]): InList<V>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Tagged } from "../operators.js";
|
|
2
|
+
/** Adds to the stored number. `undefined` in `set` still leaves the field unchanged. */
|
|
3
|
+
export type Inc<V> = Tagged<"inc", V>;
|
|
4
|
+
/**
|
|
5
|
+
* Atomic increment used in `update` `set` (spec §11).
|
|
6
|
+
*
|
|
7
|
+
* JSON and array operators are not this helper.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam V - Amount
|
|
10
|
+
* @param value - Amount to add
|
|
11
|
+
* @returns A tagged operator
|
|
12
|
+
*/
|
|
13
|
+
export declare function inc<const V>(value: V): Inc<V>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RelationFilter } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* No related row matches.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam V - Related where
|
|
6
|
+
* @param where - Filter on the related table
|
|
7
|
+
* @returns A relation filter
|
|
8
|
+
*/
|
|
9
|
+
export declare function none<const V>(where: V): RelationFilter<"none", V>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Not } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Negation. `not(null)` is `IS NOT NULL`.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam V - Operand
|
|
6
|
+
* @param value - Null, a value, or another operator
|
|
7
|
+
* @returns A tagged operator
|
|
8
|
+
*/
|
|
9
|
+
export declare function not<const V>(value: V): Not<V>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type NotIn } from "../operators.js";
|
|
2
|
+
/**
|
|
3
|
+
* Complement of {@link inList}. An empty list matches everything.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam V - Element
|
|
6
|
+
* @param values - Rejected values
|
|
7
|
+
* @returns A tagged operator
|
|
8
|
+
*/
|
|
9
|
+
export declare function notIn<const V>(values: readonly V[]): NotIn<V>;
|