okmodel 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -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 +369 -0
- package/dist/runtime/write.d.ts +48 -0
- package/dist/shared/4j72449d.js +37 -0
- package/dist/shared/79ggp945.js +148 -0
- package/dist/shared/7ck0dtry.js +259 -0
- package/dist/shared/8b04d28c.js +14 -0
- package/dist/shared/ax16zpvm.js +171 -0
- package/dist/shared/ckb1p0a4.js +566 -0
- package/dist/shared/cn0n68ft.js +16 -0
- package/dist/shared/dynq16vb.js +81 -0
- package/dist/shared/f5thc1s0.js +1050 -0
- package/dist/shared/fgqgsb5z.js +281 -0
- package/dist/shared/g2v6gnc8.js +347 -0
- package/dist/shared/g5fhqmwe.js +188 -0
- package/dist/shared/gk7cs7sp.js +566 -0
- package/dist/shared/hd293j9g.js +98 -0
- package/dist/shared/j5cn2963.js +701 -0
- package/dist/shared/kynx7vbm.js +1490 -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/px90pf9p.js +396 -0
- package/dist/shared/qk3hxfja.js +83 -0
- package/dist/shared/tb4ze1tr.js +119 -0
- package/dist/shared/vkm3q4x1.js +30 -0
- package/dist/shared/w8samvk1.js +18 -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/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 +94 -7
- package/dist/index.js +0 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `OkmError`: categories, HTTP mapping, and `safe` / `match` (spec §14).
|
|
3
|
+
*
|
|
4
|
+
* Doctor text for every OKM code lives in the tooling registry and is not
|
|
5
|
+
* imported here. A caller who never explains a code does not load it.
|
|
6
|
+
*/
|
|
7
|
+
import type { Row, TableName } from "./rows.js";
|
|
8
|
+
/**
|
|
9
|
+
* Catalog failures that have a code in spec section 21 or D128.
|
|
10
|
+
*
|
|
11
|
+
* OKM1020 stays the code for an unknown table and for catalog failures that
|
|
12
|
+
* still have no narrower code. A dependency cycle is OKM1026. A document this
|
|
13
|
+
* version cannot read is OKM1027.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CATALOG_CODES: readonly ["OKM1020", "OKM1021", "OKM1022", "OKM1023", "OKM1026", "OKM1027", "OKM1122"];
|
|
16
|
+
/** A catalog error code. */
|
|
17
|
+
export type CatalogCode = (typeof CATALOG_CODES)[number];
|
|
18
|
+
/**
|
|
19
|
+
* Column definition, reserved options, and codec failures (D130, D132).
|
|
20
|
+
*
|
|
21
|
+
* OKM1060 is an invalid column definition. OKM1061 is a table or schema option
|
|
22
|
+
* the types accept but this version does not implement. OKM1210 is a value a
|
|
23
|
+
* codec rejects.
|
|
24
|
+
*/
|
|
25
|
+
export declare const COLUMN_CODES: readonly ["OKM1060", "OKM1061", "OKM1210"];
|
|
26
|
+
/** A column or codec error code. */
|
|
27
|
+
export type ColumnCode = (typeof COLUMN_CODES)[number];
|
|
28
|
+
/**
|
|
29
|
+
* Query, capability, and connect codes the read path throws.
|
|
30
|
+
*
|
|
31
|
+
* These are spec §21 codes. They are a type only, so the runtime entry does
|
|
32
|
+
* not gain a second registry.
|
|
33
|
+
*/
|
|
34
|
+
export type QueryCode = "OKM1101" | "OKM1102" | "OKM1104" | "OKM1105" | "OKM1111" | "OKM1120" | "OKM1121" | "OKM1190" | "OKM1801" | "OKM1802" | "OKM1843";
|
|
35
|
+
/** Kinds from spec §14, in category order. */
|
|
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
|
+
/** One spec §14 kind. */
|
|
38
|
+
export type ErrorKind = (typeof ERROR_KINDS)[number];
|
|
39
|
+
/** Categories from spec §14. Statuses are overridable per category. */
|
|
40
|
+
export declare const ERROR_CATEGORIES: readonly ["input", "conflict", "not_found", "forbidden", "transient", "internal"];
|
|
41
|
+
/** One spec §14 category. */
|
|
42
|
+
export type ErrorCategory = (typeof ERROR_CATEGORIES)[number];
|
|
43
|
+
/**
|
|
44
|
+
* A structured suggestion for a person or a coding agent.
|
|
45
|
+
*
|
|
46
|
+
* `suggestion` is the nearest accepted name when the input was a typo.
|
|
47
|
+
*/
|
|
48
|
+
export type ErrorFix = {
|
|
49
|
+
/** What to do, in one sentence. */
|
|
50
|
+
readonly summary: string;
|
|
51
|
+
/** Accepted name to use instead, when one is close. */
|
|
52
|
+
readonly suggestion?: string;
|
|
53
|
+
};
|
|
54
|
+
/** Column name to constraint reason. Row values are not included. */
|
|
55
|
+
export type ErrorFields = Readonly<Record<string, string>>;
|
|
56
|
+
/** Body of {@link OkmError.toHttp}. */
|
|
57
|
+
export type HttpErrorBody = {
|
|
58
|
+
/** OKM code, or the kind when spec §21 does not number that kind. */
|
|
59
|
+
readonly code: string;
|
|
60
|
+
/** Same text as {@link OkmError.summary}. */
|
|
61
|
+
readonly reason: string;
|
|
62
|
+
/** Field reasons. Empty when the error has no columns. */
|
|
63
|
+
readonly fields: ErrorFields;
|
|
64
|
+
};
|
|
65
|
+
/** HTTP mapping of one error. */
|
|
66
|
+
export type HttpError = {
|
|
67
|
+
readonly status: number;
|
|
68
|
+
readonly body: HttpErrorBody;
|
|
69
|
+
};
|
|
70
|
+
/** Replacement statuses. Omitted categories keep the spec default. */
|
|
71
|
+
export type ErrorStatuses = Partial<Record<ErrorCategory, number>>;
|
|
72
|
+
/** Structured log record. Row values are never included. */
|
|
73
|
+
export type ErrorLog = {
|
|
74
|
+
readonly name: "OkmError";
|
|
75
|
+
readonly code: string;
|
|
76
|
+
readonly kind: ErrorKind;
|
|
77
|
+
readonly category: ErrorCategory;
|
|
78
|
+
readonly summary: string;
|
|
79
|
+
readonly retryable: boolean;
|
|
80
|
+
readonly batchIndex: number | null;
|
|
81
|
+
readonly fix: ErrorFix;
|
|
82
|
+
readonly fields: ErrorFields;
|
|
83
|
+
readonly table?: string;
|
|
84
|
+
readonly columns?: readonly string[];
|
|
85
|
+
readonly constraint?: string;
|
|
86
|
+
readonly sqlstate?: string;
|
|
87
|
+
};
|
|
88
|
+
/** Fields the constructor accepts beyond the code and the summary. */
|
|
89
|
+
export type OkmErrorOptions = {
|
|
90
|
+
readonly kind?: ErrorKind;
|
|
91
|
+
readonly fix?: ErrorFix;
|
|
92
|
+
readonly table?: string;
|
|
93
|
+
readonly columns?: readonly string[];
|
|
94
|
+
/** Constraint reason stored by {@link OkmError.fields}. Defaults to the kind. */
|
|
95
|
+
readonly fieldReason?: string;
|
|
96
|
+
readonly constraint?: string;
|
|
97
|
+
readonly sqlstate?: string;
|
|
98
|
+
/** Statement index, or `null` at commit. Omitted on a single statement. */
|
|
99
|
+
readonly batchIndex?: number | null;
|
|
100
|
+
readonly cause?: unknown;
|
|
101
|
+
readonly retryable?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Row values. Stored only when `includeValues` is set, and never logged.
|
|
104
|
+
* Development only (spec §14).
|
|
105
|
+
*/
|
|
106
|
+
readonly includeValues?: boolean;
|
|
107
|
+
readonly values?: Readonly<Record<string, string>>;
|
|
108
|
+
/**
|
|
109
|
+
* Category overrides from `connect({ errors })`.
|
|
110
|
+
*
|
|
111
|
+
* {@link OkmError.toHttp} uses them when the caller does not pass statuses.
|
|
112
|
+
*/
|
|
113
|
+
readonly http?: ErrorStatuses;
|
|
114
|
+
};
|
|
115
|
+
/** Success or a mapped {@link OkmError}. */
|
|
116
|
+
export type SafeResult<T> = {
|
|
117
|
+
readonly ok: true;
|
|
118
|
+
readonly value: T;
|
|
119
|
+
} | {
|
|
120
|
+
readonly ok: false;
|
|
121
|
+
readonly error: OkmError;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Column names on a registered table, or plain strings when it is not registered.
|
|
125
|
+
*
|
|
126
|
+
* An empty `Register` leaves every name as `string`. Augmenting `Register`
|
|
127
|
+
* narrows `users` to that table's columns.
|
|
128
|
+
*/
|
|
129
|
+
export type ErrorColumns<T extends string> = [TableName] extends [never] ? readonly string[] : T extends TableName ? readonly (keyof Row<T> & string)[] : readonly string[];
|
|
130
|
+
type Categorised<C extends ErrorCategory> = OkmError & {
|
|
131
|
+
readonly category: C;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* One OKModel error.
|
|
135
|
+
*
|
|
136
|
+
* Construction does not format a stack trace and does not compile a regular
|
|
137
|
+
* expression. Row values stay out unless `includeValues` was set.
|
|
138
|
+
*/
|
|
139
|
+
export declare class OkmError extends Error {
|
|
140
|
+
#private;
|
|
141
|
+
/** Spec code, or the kind when spec §21 does not number that kind. */
|
|
142
|
+
readonly code: string;
|
|
143
|
+
/** Spec §14 kind. */
|
|
144
|
+
readonly kind: ErrorKind;
|
|
145
|
+
/** Spec §14 category. */
|
|
146
|
+
readonly category: ErrorCategory;
|
|
147
|
+
/** Whether a declared retry may run this error again. `cancelled` never retries. */
|
|
148
|
+
readonly retryable: boolean;
|
|
149
|
+
/** What to change. */
|
|
150
|
+
readonly fix: ErrorFix;
|
|
151
|
+
/** Table the database named, when it named one. */
|
|
152
|
+
readonly table: string | undefined;
|
|
153
|
+
/** Columns the failure names. Empty when it names none. */
|
|
154
|
+
readonly columns: readonly string[];
|
|
155
|
+
/** Constraint name the database sent, when it sent one. */
|
|
156
|
+
readonly constraint: string | undefined;
|
|
157
|
+
/** SQLSTATE the database sent, when it sent one. */
|
|
158
|
+
readonly sqlstate: string | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Failing statement inside a batch, or `null` when the failure is the commit.
|
|
161
|
+
*
|
|
162
|
+
* `null` on a single statement as well: there is no statement index.
|
|
163
|
+
*/
|
|
164
|
+
readonly batchIndex: number | null;
|
|
165
|
+
/** Constraint reason used by {@link fields}. */
|
|
166
|
+
readonly fieldReason: string;
|
|
167
|
+
/**
|
|
168
|
+
* Same text as `message`.
|
|
169
|
+
*
|
|
170
|
+
* @returns The summary
|
|
171
|
+
*/
|
|
172
|
+
get summary(): string;
|
|
173
|
+
/**
|
|
174
|
+
* @param code - Spec code, or a kind name for an unnumbered mapped error
|
|
175
|
+
* @param message - What failed. This becomes {@link summary}
|
|
176
|
+
* @param options - Kind, columns, and fix. Omitted fields are derived
|
|
177
|
+
*/
|
|
178
|
+
constructor(code: string, message: string, options?: OkmErrorOptions);
|
|
179
|
+
/**
|
|
180
|
+
* Maps a caught value to an {@link OkmError}.
|
|
181
|
+
*
|
|
182
|
+
* An {@link OkmError} is returned as itself. A driver error whose kind is
|
|
183
|
+
* `timeout`, `cancelled`, or `outcome_unknown` keeps that kind. Postgres
|
|
184
|
+
* SQLSTATE mapping is `mapPostgresError` in the Postgres dialect: this
|
|
185
|
+
* method does not interpret constraint SQLSTATEs.
|
|
186
|
+
*
|
|
187
|
+
* @param error - Any thrown value
|
|
188
|
+
* @returns An OKModel error
|
|
189
|
+
*/
|
|
190
|
+
static from(error: unknown): OkmError;
|
|
191
|
+
/**
|
|
192
|
+
* Narrows `error` to one kind, and to one table's columns when `table` is set.
|
|
193
|
+
*
|
|
194
|
+
* @param error - Caught value
|
|
195
|
+
* @param kind - Expected kind
|
|
196
|
+
* @param table - Expected table. Columns are typed from `Register` when it names one
|
|
197
|
+
* @returns `true` when the kind matches and, if given, the table matches
|
|
198
|
+
*/
|
|
199
|
+
static is<K extends ErrorKind>(error: unknown, kind: K): error is Omit<OkmError, "kind"> & {
|
|
200
|
+
readonly kind: K;
|
|
201
|
+
};
|
|
202
|
+
static is<K extends ErrorKind, T extends string>(error: unknown, kind: K, table: T): error is Omit<OkmError, "kind" | "table" | "columns"> & {
|
|
203
|
+
readonly kind: K;
|
|
204
|
+
readonly table: T;
|
|
205
|
+
readonly columns: ErrorColumns<T>;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* Field name to constraint reason.
|
|
209
|
+
*
|
|
210
|
+
* The same object is returned on later calls. Row values are not included.
|
|
211
|
+
*
|
|
212
|
+
* @returns A map, empty when the error names no column
|
|
213
|
+
*/
|
|
214
|
+
fields(): ErrorFields;
|
|
215
|
+
/**
|
|
216
|
+
* Row values, only when the error was built with `includeValues`.
|
|
217
|
+
*
|
|
218
|
+
* @returns The values, or `undefined` when they were not kept
|
|
219
|
+
*/
|
|
220
|
+
values(): Readonly<Record<string, string>> | undefined;
|
|
221
|
+
/**
|
|
222
|
+
* HTTP status and a body without row values.
|
|
223
|
+
*
|
|
224
|
+
* @param statuses - Category overrides from `connect()`. Omitted categories use the spec default
|
|
225
|
+
* @returns Status and `{ code, reason, fields }`
|
|
226
|
+
*/
|
|
227
|
+
toHttp(statuses?: ErrorStatuses): HttpError;
|
|
228
|
+
/**
|
|
229
|
+
* Structured record for a log. Row values are omitted.
|
|
230
|
+
*
|
|
231
|
+
* @returns The fields a log line may print
|
|
232
|
+
*/
|
|
233
|
+
log(): ErrorLog;
|
|
234
|
+
/**
|
|
235
|
+
* Runs the handler for this category, or `_` when that category is omitted.
|
|
236
|
+
*
|
|
237
|
+
* @param handlers - One function per category that the caller handles, plus `_`
|
|
238
|
+
* @returns Whatever the chosen handler returns
|
|
239
|
+
*/
|
|
240
|
+
match<I = never, C = never, NF = never, F = never, T = never, X = never, D = never>(handlers: {
|
|
241
|
+
readonly input?: (error: Categorised<"input">) => I;
|
|
242
|
+
readonly conflict?: (error: Categorised<"conflict">) => C;
|
|
243
|
+
readonly not_found?: (error: Categorised<"not_found">) => NF;
|
|
244
|
+
readonly forbidden?: (error: Categorised<"forbidden">) => F;
|
|
245
|
+
readonly transient?: (error: Categorised<"transient">) => T;
|
|
246
|
+
readonly internal?: (error: Categorised<"internal">) => X;
|
|
247
|
+
readonly _: (error: OkmError) => D;
|
|
248
|
+
}): I | C | NF | F | T | X | D;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Settles `pending` as `{ ok, value }` or `{ ok, error }`.
|
|
252
|
+
*
|
|
253
|
+
* The error is {@link OkmError.from}. Postgres constraint mapping happens
|
|
254
|
+
* before this, in the dialect, once a query throws.
|
|
255
|
+
*
|
|
256
|
+
* @param pending - Work that may throw
|
|
257
|
+
* @returns A result that does not throw
|
|
258
|
+
*/
|
|
259
|
+
export declare function safe<T>(pending: Promise<T>): Promise<SafeResult<T>>;
|
|
260
|
+
/**
|
|
261
|
+
* Throws an {@link OkmError} for a catalog failure.
|
|
262
|
+
*
|
|
263
|
+
* @param code - Spec code
|
|
264
|
+
* @param message - What failed. Name the accepted values
|
|
265
|
+
* @param options - Fix and nearest-name suggestion
|
|
266
|
+
*/
|
|
267
|
+
export declare function catalogError(code: CatalogCode, message: string, options?: OkmErrorOptions): never;
|
|
268
|
+
/**
|
|
269
|
+
* Throws for an unknown table, field, preset, or option.
|
|
270
|
+
*
|
|
271
|
+
* The message must already name the accepted values. A close candidate adds
|
|
272
|
+
* "Did you mean `name`?" and a {@link ErrorFix.suggestion}.
|
|
273
|
+
*
|
|
274
|
+
* @param code - Spec code for this guard
|
|
275
|
+
* @param input - The name that was rejected
|
|
276
|
+
* @param candidates - Accepted and reserved names
|
|
277
|
+
* @param message - What failed, including the accepted values
|
|
278
|
+
*/
|
|
279
|
+
export declare function throwNamed(code: CatalogCode | ColumnCode | QueryCode, input: string, candidates: readonly string[], message: string): never;
|
|
280
|
+
/**
|
|
281
|
+
* Removes row values from a server message.
|
|
282
|
+
*
|
|
283
|
+
* `Key (email)=(ada@example.com)` becomes `Key (email)`. A `contains (...)`
|
|
284
|
+
* list becomes `contains (…)`.
|
|
285
|
+
*
|
|
286
|
+
* @param text - Driver or server text
|
|
287
|
+
* @returns Text safe to put on an error
|
|
288
|
+
*/
|
|
289
|
+
export declare function stripRowValues(text: string): string;
|
|
290
|
+
/**
|
|
291
|
+
* Index of the parenthesis that closes the one at `open`.
|
|
292
|
+
*
|
|
293
|
+
* @param text - Source text
|
|
294
|
+
* @param open - Index of the opening `(`
|
|
295
|
+
* @returns Index of the matching `)`, or `undefined` when it is missing
|
|
296
|
+
*/
|
|
297
|
+
export declare function matchingParen(text: string, open: number): number | undefined;
|
|
298
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public entry for the `okmodel` package.
|
|
3
|
+
*
|
|
4
|
+
* Application code imports `OkmError`, `safe`, the row types, and the driver
|
|
5
|
+
* types from here. Catalog builders and the helpers a dialect author calls
|
|
6
|
+
* live on `okmodel/internal`, so `table` and `index` on this entry are not a
|
|
7
|
+
* second schema API.
|
|
8
|
+
*/
|
|
9
|
+
export { CATALOG_CODES, COLUMN_CODES, ERROR_CATEGORIES, ERROR_KINDS, OkmError, safe, type CatalogCode, type ColumnCode, type QueryCode, type ErrorCategory, type ErrorColumns, type ErrorFields, type ErrorFix, type ErrorKind, type ErrorLog, type ErrorStatuses, type HttpError, type HttpErrorBody, type OkmErrorOptions, type SafeResult, } from "./error.js";
|
|
10
|
+
export type { AnySchema, AnyTableShape, Insert, Register, Row, SchemaOf, TableName, Update, } from "./rows.js";
|
|
11
|
+
export type { DescribeResult, DriverCapabilities, DriverConnection, DriverErrorFields, DriverFailureKind, DriverPool, DriverPoolConfig, DriverStats, ExecuteOptions, ExecuteResult, Notice, PreparedMode, Statement, TransactionMode, WireValue, } from "./driver.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CATALOG_CODES2,
|
|
3
|
+
COLUMN_CODES2,
|
|
4
|
+
ERROR_KINDS2,
|
|
5
|
+
ERROR_CATEGORIES2,
|
|
6
|
+
OkmError2,
|
|
7
|
+
safe2
|
|
8
|
+
} from "../shared/ycwz42az.js";
|
|
9
|
+
export {
|
|
10
|
+
CATALOG_CODES2 as CATALOG_CODES,
|
|
11
|
+
COLUMN_CODES2 as COLUMN_CODES,
|
|
12
|
+
ERROR_CATEGORIES2 as ERROR_CATEGORIES,
|
|
13
|
+
ERROR_KINDS2 as ERROR_KINDS,
|
|
14
|
+
OkmError2 as OkmError,
|
|
15
|
+
safe2 as safe
|
|
16
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Undocumented entry for `okmodel/internal`.
|
|
3
|
+
*
|
|
4
|
+
* No stability promise. Dialect authors and the sibling entries import these.
|
|
5
|
+
* Application code imports `table` and `index` from `okmodel/pg`, not the
|
|
6
|
+
* catalog builders here.
|
|
7
|
+
*/
|
|
8
|
+
/** @internal */
|
|
9
|
+
export { catalogError, throwNamed } from "./error.js";
|
|
10
|
+
/** @internal */
|
|
11
|
+
export { nearestName } from "./nearest.js";
|
|
12
|
+
/** @internal */
|
|
13
|
+
export { sha256 } from "./sha256.js";
|
|
14
|
+
/** @internal */
|
|
15
|
+
export { BUILT_KINDS, CATALOG_VERSION, KIND_OPERATIONS, OBJECT_KINDS, OBJECT_OPERATIONS, OWNERS, POSTGRES_IDENTIFIER_MAX_BYTES, assertIdentifier, assertNamespace, column, constraint, deterministicName, fitIdentifier, identityKey, identityLabel, identifierLimitApplies, index, isReservedIdentifier, resolveNamespace, sameNamespace, sameRef, sequence, staticNamespace, table, templateNamespace, utf8ByteLength, type AnchoredIdentity, type BuiltKind, type Catalog, type CatalogEnvelope, type CatalogObject, type ColumnDefinition, type ColumnInput, type ColumnObject, type ConstraintDefinition, type ConstraintInput, type ConstraintKind, type ConstraintObject, type DefaultPrivilegeIdentity, type DependencyEdge, type ExtensionIdentity, type FunctionIdentity, type GrantIdentity, type GrantObjectRef, type IndexDefinition, type IndexInput, type IndexObject, type NamePurpose, type Namespace, type NamespaceIdentity, type ObjectIdentity, type ObjectKind, type ObjectOperation, type ObjectRef, type Owner, type PartitionMethod, type Provenance, type ReferentialAction, type RoleIdentity, type SequenceDefinition, type SequenceInput, type SequenceObject, type TableDefinition, type TableInput, type TableObject, } from "./catalog/index.js";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OWNERS2,
|
|
3
|
+
OBJECT_KINDS2,
|
|
4
|
+
BUILT_KINDS2,
|
|
5
|
+
OBJECT_OPERATIONS2,
|
|
6
|
+
KIND_OPERATIONS2,
|
|
7
|
+
CATALOG_VERSION2,
|
|
8
|
+
staticNamespace2,
|
|
9
|
+
templateNamespace2,
|
|
10
|
+
assertNamespace2,
|
|
11
|
+
resolveNamespace2,
|
|
12
|
+
identityKey2,
|
|
13
|
+
identifierLimitApplies2,
|
|
14
|
+
identityLabel2,
|
|
15
|
+
sameRef2,
|
|
16
|
+
sameNamespace2,
|
|
17
|
+
table3,
|
|
18
|
+
column2,
|
|
19
|
+
index3,
|
|
20
|
+
constraint2,
|
|
21
|
+
sequence2
|
|
22
|
+
} from "../shared/j5cn2963.js";
|
|
23
|
+
import {
|
|
24
|
+
utf8ByteLength2,
|
|
25
|
+
sha2562,
|
|
26
|
+
POSTGRES_IDENTIFIER_MAX_BYTES2,
|
|
27
|
+
isReservedIdentifier2,
|
|
28
|
+
assertIdentifier2,
|
|
29
|
+
fitIdentifier2,
|
|
30
|
+
deterministicName2
|
|
31
|
+
} from "../shared/mkjmqjv4.js";
|
|
32
|
+
import {
|
|
33
|
+
nearestName2,
|
|
34
|
+
catalogError2,
|
|
35
|
+
throwNamed2
|
|
36
|
+
} from "../shared/ycwz42az.js";
|
|
37
|
+
export {
|
|
38
|
+
BUILT_KINDS2 as BUILT_KINDS,
|
|
39
|
+
CATALOG_VERSION2 as CATALOG_VERSION,
|
|
40
|
+
KIND_OPERATIONS2 as KIND_OPERATIONS,
|
|
41
|
+
OBJECT_KINDS2 as OBJECT_KINDS,
|
|
42
|
+
OBJECT_OPERATIONS2 as OBJECT_OPERATIONS,
|
|
43
|
+
OWNERS2 as OWNERS,
|
|
44
|
+
POSTGRES_IDENTIFIER_MAX_BYTES2 as POSTGRES_IDENTIFIER_MAX_BYTES,
|
|
45
|
+
assertIdentifier2 as assertIdentifier,
|
|
46
|
+
assertNamespace2 as assertNamespace,
|
|
47
|
+
catalogError2 as catalogError,
|
|
48
|
+
column2 as column,
|
|
49
|
+
constraint2 as constraint,
|
|
50
|
+
deterministicName2 as deterministicName,
|
|
51
|
+
fitIdentifier2 as fitIdentifier,
|
|
52
|
+
identifierLimitApplies2 as identifierLimitApplies,
|
|
53
|
+
identityKey2 as identityKey,
|
|
54
|
+
identityLabel2 as identityLabel,
|
|
55
|
+
index3 as index,
|
|
56
|
+
isReservedIdentifier2 as isReservedIdentifier,
|
|
57
|
+
nearestName2 as nearestName,
|
|
58
|
+
resolveNamespace2 as resolveNamespace,
|
|
59
|
+
sameNamespace2 as sameNamespace,
|
|
60
|
+
sameRef2 as sameRef,
|
|
61
|
+
sequence2 as sequence,
|
|
62
|
+
sha2562 as sha256,
|
|
63
|
+
staticNamespace2 as staticNamespace,
|
|
64
|
+
table3 as table,
|
|
65
|
+
templateNamespace2 as templateNamespace,
|
|
66
|
+
throwNamed2 as throwNamed,
|
|
67
|
+
utf8ByteLength2 as utf8ByteLength
|
|
68
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nearest-name hints for unknown tables, fields, presets, and options.
|
|
3
|
+
*
|
|
4
|
+
* One edit-distance helper. No dependency, and nothing runs at import.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Closest candidate to `input`, or `undefined` when none is close.
|
|
8
|
+
*
|
|
9
|
+
* Comparison ignores ASCII case. The returned spelling is the candidate's.
|
|
10
|
+
*
|
|
11
|
+
* @param input - The name that was not accepted
|
|
12
|
+
* @param candidates - Accepted and reserved names
|
|
13
|
+
* @returns A name to show after "did you mean"
|
|
14
|
+
*/
|
|
15
|
+
export declare function nearestName(input: string, candidates: readonly string[]): string | undefined;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row lookup by table name.
|
|
3
|
+
*
|
|
4
|
+
* `Register` is declaration merging on `okmodel`. `Row`, `Insert`, and
|
|
5
|
+
* `Update` read it when the caller does not pass a schema. The shapes
|
|
6
|
+
* themselves are computed by `table()` in the dialect.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Project schema slot.
|
|
10
|
+
*
|
|
11
|
+
* Augment `okmodel` with one `schema` property. `okm check` warns on a
|
|
12
|
+
* second augmentation later (OKM1025).
|
|
13
|
+
*/
|
|
14
|
+
export interface Register {
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Fields a table exposes for row lookup.
|
|
18
|
+
*
|
|
19
|
+
* The dialect's table value has these phantoms. This shape stays in
|
|
20
|
+
* contracts so the package entry can name `Row` without importing a dialect.
|
|
21
|
+
*/
|
|
22
|
+
export type AnyTableShape = {
|
|
23
|
+
readonly "~name": string;
|
|
24
|
+
readonly "~row": unknown;
|
|
25
|
+
readonly "~insert": unknown;
|
|
26
|
+
readonly "~update": unknown;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A schema that can look up tables by name.
|
|
30
|
+
*/
|
|
31
|
+
export type AnySchema = {
|
|
32
|
+
readonly "~byName": {
|
|
33
|
+
readonly [name: string]: AnyTableShape;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The schema a lookup uses.
|
|
38
|
+
*
|
|
39
|
+
* An explicit argument wins. Otherwise the type is `Register["schema"]`.
|
|
40
|
+
*
|
|
41
|
+
* @typeParam S - Explicit schema, or `undefined` to read {@link Register}
|
|
42
|
+
*/
|
|
43
|
+
export type SchemaOf<S extends AnySchema | undefined> = S extends AnySchema ? S : Register extends {
|
|
44
|
+
readonly schema: infer R extends AnySchema;
|
|
45
|
+
} ? R : never;
|
|
46
|
+
/**
|
|
47
|
+
* Table names of a schema, defaulting to {@link Register}.
|
|
48
|
+
*
|
|
49
|
+
* @typeParam S - Explicit schema, or `undefined`
|
|
50
|
+
*/
|
|
51
|
+
export type TableName<S extends AnySchema | undefined = undefined> = keyof SchemaOf<S>["~byName"] & string;
|
|
52
|
+
/**
|
|
53
|
+
* Row type. Hidden columns are already removed.
|
|
54
|
+
*
|
|
55
|
+
* @typeParam N - Table name
|
|
56
|
+
* @typeParam S - Explicit schema. Omit it to use {@link Register}
|
|
57
|
+
*/
|
|
58
|
+
export type Row<N extends TableName<S>, S extends AnySchema | undefined = undefined> = ShapeOf<S, N, "~row">;
|
|
59
|
+
/**
|
|
60
|
+
* Insert type. Guarded, generated, and primary-key columns are already removed.
|
|
61
|
+
*
|
|
62
|
+
* @typeParam N - Table name
|
|
63
|
+
* @typeParam S - Explicit schema. Omit it to use {@link Register}
|
|
64
|
+
*/
|
|
65
|
+
export type Insert<N extends TableName<S>, S extends AnySchema | undefined = undefined> = ShapeOf<S, N, "~insert">;
|
|
66
|
+
/**
|
|
67
|
+
* Update type. The same columns as insert, every one optional.
|
|
68
|
+
*
|
|
69
|
+
* @typeParam N - Table name
|
|
70
|
+
* @typeParam S - Explicit schema. Omit it to use {@link Register}
|
|
71
|
+
*/
|
|
72
|
+
export type Update<N extends TableName<S>, S extends AnySchema | undefined = undefined> = ShapeOf<S, N, "~update">;
|
|
73
|
+
/**
|
|
74
|
+
* One phantom on the table named `N`.
|
|
75
|
+
*
|
|
76
|
+
* The index can include `undefined` under `noUncheckedIndexedAccess`.
|
|
77
|
+
* The conditional drops that and keeps the table's own shape.
|
|
78
|
+
*
|
|
79
|
+
* @typeParam S - Explicit schema, or `undefined`
|
|
80
|
+
* @typeParam N - Table name
|
|
81
|
+
* @typeParam K - `~row`, `~insert`, or `~update`
|
|
82
|
+
*/
|
|
83
|
+
type ShapeOf<S extends AnySchema | undefined, N extends string, K extends keyof AnyTableShape> = N extends keyof SchemaOf<S>["~byName"] ? SchemaOf<S>["~byName"][N] extends infer T ? T extends AnyTableShape ? T[K] : never : never : never;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SHA-256 (FIPS 180-4) implemented in TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* Contracts must not call Bun, a host crypto API, or a Node built-in.
|
|
5
|
+
* Round constants are built on the first hash, not when this module loads.
|
|
6
|
+
* Callers in other layers use this for catalog and fixture hashes.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* SHA-256 of a string, encoded as UTF-8.
|
|
10
|
+
*
|
|
11
|
+
* @param text - Input text
|
|
12
|
+
* @returns Lowercase hex digest
|
|
13
|
+
*/
|
|
14
|
+
export declare function sha256(text: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UTF-8 measurement and encoding.
|
|
3
|
+
*
|
|
4
|
+
* Identifier fitting and SHA-256 share this walk so neither keeps its own copy.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* UTF-8 byte length of a string.
|
|
8
|
+
*
|
|
9
|
+
* @param value - Text to measure
|
|
10
|
+
* @returns Byte length
|
|
11
|
+
*/
|
|
12
|
+
export declare function utf8ByteLength(value: string): number;
|
|
13
|
+
/**
|
|
14
|
+
* UTF-8 bytes of a string.
|
|
15
|
+
*
|
|
16
|
+
* ASCII, the usual catalog text, is one pass into one buffer. Anything else
|
|
17
|
+
* uses the same width rules as {@link utf8ByteLength}.
|
|
18
|
+
*
|
|
19
|
+
* @param value - Text to encode
|
|
20
|
+
* @returns UTF-8 bytes
|
|
21
|
+
*/
|
|
22
|
+
export declare function encodeUtf8(value: string): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* UTF-8 prefix of `value` that fits in `budget` bytes.
|
|
25
|
+
*
|
|
26
|
+
* A code point that would cross the budget is left off, so a surrogate pair
|
|
27
|
+
* is never split.
|
|
28
|
+
*
|
|
29
|
+
* @param value - Text to cut
|
|
30
|
+
* @param budget - Maximum UTF-8 bytes
|
|
31
|
+
* @returns The prefix
|
|
32
|
+
*/
|
|
33
|
+
export declare function truncateUtf8(value: string, budget: number): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Postgres array literals.
|
|
3
|
+
*
|
|
4
|
+
* Encode and decode run only when a column uses `.array()`. The scanner is
|
|
5
|
+
* created per call.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Writes a nested array as a Postgres array literal.
|
|
9
|
+
*
|
|
10
|
+
* @param value - Nested arrays of scalar values
|
|
11
|
+
* @param dims - Rank, at least 1
|
|
12
|
+
* @param encode - Scalar encoder
|
|
13
|
+
* @param raw - Whether scalar tokens may stay bare
|
|
14
|
+
* @returns A `{...}` literal
|
|
15
|
+
*/
|
|
16
|
+
export declare function writeArray(value: unknown, dims: number, encode: (value: unknown) => string, raw: boolean): string;
|
|
17
|
+
/**
|
|
18
|
+
* Reads a Postgres array literal back into nested scalars.
|
|
19
|
+
*
|
|
20
|
+
* @param wire - Literal produced by {@link writeArray}
|
|
21
|
+
* @param dims - Rank, at least 1
|
|
22
|
+
* @param decode - Scalar decoder
|
|
23
|
+
* @returns Nested arrays
|
|
24
|
+
*/
|
|
25
|
+
export declare function readArray(wire: string, dims: number, decode: (wire: string) => unknown): unknown;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* boolean and bytea.
|
|
3
|
+
*/
|
|
4
|
+
import { type ColumnBuilder, type PlainFlags } from "./column.js";
|
|
5
|
+
/**
|
|
6
|
+
* Boolean.
|
|
7
|
+
*
|
|
8
|
+
* @returns A boolean column
|
|
9
|
+
*/
|
|
10
|
+
export declare function boolean(): ColumnBuilder<boolean, PlainFlags>;
|
|
11
|
+
/**
|
|
12
|
+
* Binary data. Wire text is `\x` plus lowercase hex.
|
|
13
|
+
*
|
|
14
|
+
* @returns A bytea column
|
|
15
|
+
*/
|
|
16
|
+
export declare function bytea(): ColumnBuilder<Uint8Array, PlainFlags>;
|
|
17
|
+
/**
|
|
18
|
+
* Encodes true or false.
|
|
19
|
+
*
|
|
20
|
+
* @param value - Boolean
|
|
21
|
+
* @returns `true` or `false`
|
|
22
|
+
*/
|
|
23
|
+
export declare function encodeBoolean(value: boolean): string;
|
|
24
|
+
/**
|
|
25
|
+
* Decodes a boolean token.
|
|
26
|
+
*
|
|
27
|
+
* Accepts `true`, `false`, `t`, `f`, `1`, and `0`.
|
|
28
|
+
*
|
|
29
|
+
* @param wire - Boolean text
|
|
30
|
+
* @returns A boolean
|
|
31
|
+
*/
|
|
32
|
+
export declare function decodeBoolean(wire: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Encodes bytes as `\x` hex.
|
|
35
|
+
*
|
|
36
|
+
* @param value - Bytes
|
|
37
|
+
* @returns Hex text
|
|
38
|
+
*/
|
|
39
|
+
export declare function encodeBytea(value: Uint8Array): string;
|
|
40
|
+
/**
|
|
41
|
+
* Decodes `\x` hex into a new byte array.
|
|
42
|
+
*
|
|
43
|
+
* @param wire - Hex text
|
|
44
|
+
* @returns Bytes
|
|
45
|
+
*/
|
|
46
|
+
export declare function decodeBytea(wire: string): Uint8Array;
|