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.
Files changed (147) hide show
  1. package/README.md +246 -1
  2. package/dist/adapters/capabilities.d.ts +62 -0
  3. package/dist/adapters/error.d.ts +91 -0
  4. package/dist/adapters/failure.d.ts +39 -0
  5. package/dist/adapters/pg/batch.d.ts +36 -0
  6. package/dist/adapters/pg/call.d.ts +59 -0
  7. package/dist/adapters/pg/pglite.d.ts +21 -0
  8. package/dist/adapters/pg/postgres-extra.d.ts +43 -0
  9. package/dist/adapters/pg/postgresjs.d.ts +95 -0
  10. package/dist/adapters/pg/result.d.ts +30 -0
  11. package/dist/contracts/catalog/build.d.ts +18 -0
  12. package/dist/contracts/catalog/document.d.ts +79 -0
  13. package/dist/contracts/catalog/enum.d.ts +35 -0
  14. package/dist/contracts/catalog/identifier.d.ts +71 -0
  15. package/dist/contracts/catalog/identity.d.ts +98 -0
  16. package/dist/contracts/catalog/index.d.ts +11 -0
  17. package/dist/contracts/catalog/json.d.ts +17 -0
  18. package/dist/contracts/catalog/object.d.ts +142 -0
  19. package/dist/contracts/catalog/order.d.ts +43 -0
  20. package/dist/contracts/catalog/rewrite.d.ts +18 -0
  21. package/dist/contracts/catalog/types.d.ts +292 -0
  22. package/dist/contracts/catalog/words.d.ts +13 -0
  23. package/dist/contracts/connection.d.ts +33 -0
  24. package/dist/contracts/driver.d.ts +163 -0
  25. package/dist/contracts/error.d.ts +298 -0
  26. package/dist/contracts/index.d.ts +11 -0
  27. package/dist/contracts/index.js +16 -0
  28. package/dist/contracts/internal.d.ts +15 -0
  29. package/dist/contracts/internal.js +68 -0
  30. package/dist/contracts/nearest.d.ts +15 -0
  31. package/dist/contracts/rows.d.ts +84 -0
  32. package/dist/contracts/sha256.d.ts +14 -0
  33. package/dist/contracts/utf8.d.ts +33 -0
  34. package/dist/dialects/pg/array-literal.d.ts +25 -0
  35. package/dist/dialects/pg/bool.d.ts +46 -0
  36. package/dist/dialects/pg/column.d.ts +386 -0
  37. package/dist/dialects/pg/compile.d.ts +81 -0
  38. package/dist/dialects/pg/custom.d.ts +21 -0
  39. package/dist/dialects/pg/ddl.d.ts +70 -0
  40. package/dist/dialects/pg/decimal.d.ts +62 -0
  41. package/dist/dialects/pg/declarations.d.ts +34 -0
  42. package/dist/dialects/pg/emit.d.ts +18 -0
  43. package/dist/dialects/pg/enum.d.ts +30 -0
  44. package/dist/dialects/pg/errors.d.ts +30 -0
  45. package/dist/dialects/pg/finite.d.ts +15 -0
  46. package/dist/dialects/pg/geometry.d.ts +55 -0
  47. package/dist/dialects/pg/index.d.ts +45 -0
  48. package/dist/dialects/pg/index.js +1821 -0
  49. package/dist/dialects/pg/integer.d.ts +96 -0
  50. package/dist/dialects/pg/introspect.d.ts +43 -0
  51. package/dist/dialects/pg/json.d.ts +43 -0
  52. package/dist/dialects/pg/keys.d.ts +32 -0
  53. package/dist/dialects/pg/misuse.d.ts +31 -0
  54. package/dist/dialects/pg/model.d.ts +71 -0
  55. package/dist/dialects/pg/namespace.d.ts +63 -0
  56. package/dist/dialects/pg/network.d.ts +28 -0
  57. package/dist/dialects/pg/operators.d.ts +71 -0
  58. package/dist/dialects/pg/ops/between.d.ts +10 -0
  59. package/dist/dialects/pg/ops/contains.d.ts +8 -0
  60. package/dist/dialects/pg/ops/endsWith.d.ts +8 -0
  61. package/dist/dialects/pg/ops/eq.d.ts +9 -0
  62. package/dist/dialects/pg/ops/every.d.ts +9 -0
  63. package/dist/dialects/pg/ops/gt.d.ts +9 -0
  64. package/dist/dialects/pg/ops/gte.d.ts +9 -0
  65. package/dist/dialects/pg/ops/has.d.ts +9 -0
  66. package/dist/dialects/pg/ops/ilike.d.ts +8 -0
  67. package/dist/dialects/pg/ops/inList.d.ts +9 -0
  68. package/dist/dialects/pg/ops/inc.d.ts +13 -0
  69. package/dist/dialects/pg/ops/like.d.ts +8 -0
  70. package/dist/dialects/pg/ops/lt.d.ts +9 -0
  71. package/dist/dialects/pg/ops/lte.d.ts +9 -0
  72. package/dist/dialects/pg/ops/none.d.ts +9 -0
  73. package/dist/dialects/pg/ops/not.d.ts +9 -0
  74. package/dist/dialects/pg/ops/notIn.d.ts +9 -0
  75. package/dist/dialects/pg/ops/or.d.ts +9 -0
  76. package/dist/dialects/pg/ops/startsWith.d.ts +8 -0
  77. package/dist/dialects/pg/quote.d.ts +24 -0
  78. package/dist/dialects/pg/range.d.ts +50 -0
  79. package/dist/dialects/pg/relations.d.ts +45 -0
  80. package/dist/dialects/pg/schema.d.ts +77 -0
  81. package/dist/dialects/pg/search.d.ts +23 -0
  82. package/dist/dialects/pg/table.d.ts +201 -0
  83. package/dist/dialects/pg/temporal.d.ts +211 -0
  84. package/dist/dialects/pg/text.d.ts +44 -0
  85. package/dist/dialects/pg/time.d.ts +46 -0
  86. package/dist/okm.js +2 -0
  87. package/dist/okmodel.js +2 -0
  88. package/dist/runtime/client.d.ts +47 -0
  89. package/dist/runtime/conflict.d.ts +38 -0
  90. package/dist/runtime/drift-detail.d.ts +32 -0
  91. package/dist/runtime/drift.d.ts +29 -0
  92. package/dist/runtime/include.d.ts +15 -0
  93. package/dist/runtime/pg/pglite.d.ts +25 -0
  94. package/dist/runtime/pg/pglite.js +48 -0
  95. package/dist/runtime/pg/postgresjs.d.ts +29 -0
  96. package/dist/runtime/pg/postgresjs.js +62 -0
  97. package/dist/runtime/plan.d.ts +167 -0
  98. package/dist/runtime/tx.d.ts +29 -0
  99. package/dist/runtime/types.d.ts +385 -0
  100. package/dist/runtime/write.d.ts +48 -0
  101. package/dist/shared/05w44d8g.js +1524 -0
  102. package/dist/shared/523ft3e8.js +171 -0
  103. package/dist/shared/8b04d28c.js +14 -0
  104. package/dist/shared/cn0n68ft.js +16 -0
  105. package/dist/shared/dkn3y60a.js +374 -0
  106. package/dist/shared/dynq16vb.js +81 -0
  107. package/dist/shared/fgqgsb5z.js +281 -0
  108. package/dist/shared/g5fhqmwe.js +188 -0
  109. package/dist/shared/gk7cs7sp.js +566 -0
  110. package/dist/shared/hadrfb9h.js +398 -0
  111. package/dist/shared/hd293j9g.js +98 -0
  112. package/dist/shared/j5cn2963.js +701 -0
  113. package/dist/shared/jjb7yht9.js +37 -0
  114. package/dist/shared/kprcwaha.js +30 -0
  115. package/dist/shared/m3ypagh5.js +347 -0
  116. package/dist/shared/mkjmqjv4.js +456 -0
  117. package/dist/shared/mtkwv8wx.js +18 -0
  118. package/dist/shared/ngk8gj61.js +40 -0
  119. package/dist/shared/p0cbr3g2.js +79 -0
  120. package/dist/shared/qk3hxfja.js +83 -0
  121. package/dist/shared/rgs0st28.js +1066 -0
  122. package/dist/shared/w8samvk1.js +18 -0
  123. package/dist/shared/x5x59srr.js +566 -0
  124. package/dist/shared/xqbhg6cn.js +119 -0
  125. package/dist/shared/xy79j5hq.js +177 -0
  126. package/dist/shared/y9m15dfv.js +888 -0
  127. package/dist/shared/ycwz42az.js +412 -0
  128. package/dist/shared/yd1kzwn2.js +148 -0
  129. package/dist/shared/zhc5vmgf.js +257 -0
  130. package/dist/tooling/cli.d.ts +1 -0
  131. package/dist/tooling/cli.js +193 -0
  132. package/dist/tooling/errors/registry.d.ts +33 -0
  133. package/dist/tooling/migrate/apply.d.ts +86 -0
  134. package/dist/tooling/migrate/commands.d.ts +21 -0
  135. package/dist/tooling/migrate/config.d.ts +48 -0
  136. package/dist/tooling/migrate/dev.d.ts +16 -0
  137. package/dist/tooling/migrate/equal.d.ts +15 -0
  138. package/dist/tooling/migrate/files.d.ts +19 -0
  139. package/dist/tooling/migrate/index.d.ts +7 -0
  140. package/dist/tooling/migrate/index.js +7 -0
  141. package/dist/tooling/migrate/plan.d.ts +76 -0
  142. package/dist/tooling/migrate/policy.d.ts +78 -0
  143. package/dist/tooling/migrate/project.d.ts +69 -0
  144. package/dist/tooling/migrate/status.d.ts +74 -0
  145. package/dist/tooling/migrate/values.d.ts +29 -0
  146. package/package.json +109 -7
  147. package/dist/index.js +0 -0
@@ -0,0 +1,385 @@
1
+ /**
2
+ * Types for a connected client.
3
+ *
4
+ * Row shapes are the schema's `~row`. Operators are the tagged helpers.
5
+ * A plain object is not a where value when the column type is an object.
6
+ */
7
+ import type { SafeResult } from "../contracts/error.js";
8
+ import type { QuerySchema } from "../dialects/pg/model.js";
9
+ import type { Inc } from "../dialects/pg/ops/inc.js";
10
+ import type { Between, Compare, Eq, InList, Not, NotIn, Or, Pattern, RawPattern, RelationFilter } from "../dialects/pg/operators.js";
11
+ import type { AppliedRule, ReadOp } from "./plan.js";
12
+ /** One row of a table in `S`. */
13
+ export type RowOf<S extends QuerySchema, K extends keyof S["~byName"]> = S["~byName"][K] extends {
14
+ readonly "~row": infer R;
15
+ } ? R : never;
16
+ /** Relations declared on a table. */
17
+ export type RelationsOf<S extends QuerySchema, K extends keyof S["~byName"]> = S["~byName"][K] extends {
18
+ readonly "~relations": infer R;
19
+ } ? R : Record<string, never>;
20
+ type IsObject<V> = V extends object ? V extends readonly unknown[] ? false : null extends V ? false : true : false;
21
+ /** A where operand. Object columns take `eq`, not a bare object. */
22
+ export type WhereValue<V> = (IsObject<V> extends true ? never : V) | null | Eq<V> | Compare<"lt", V> | Compare<"lte", V> | Compare<"gt", V> | Compare<"gte", V> | Between<V> | Pattern<"startsWith"> | Pattern<"contains"> | Pattern<"endsWith"> | RawPattern<"like"> | RawPattern<"ilike"> | InList<V> | NotIn<V> | Not<V | null | Pattern<"startsWith"> | Pattern<"contains"> | Pattern<"endsWith"> | InList<V>>;
23
+ /** Field filters. Relation filters are one level, so the type does not cycle. */
24
+ export type FieldWhere<Row> = {
25
+ readonly [K in keyof Row]?: WhereValue<Row[K]> | undefined;
26
+ };
27
+ /** `has`, `none`, and `every` against the related row. */
28
+ export type RelFilter<S extends QuerySchema, Rel> = Rel extends {
29
+ readonly table: infer T extends string;
30
+ } ? T extends keyof S["~byName"] ? RelationFilter<"has" | "none" | "every", FieldWhere<RowOf<S, T>>> : never : never;
31
+ /** Known relation names. A string index (no declared relations) adds none. */
32
+ type RelationKeys<R> = string extends keyof R ? never : keyof R;
33
+ /** Column and relation filters for one table. */
34
+ type FiltersOf<S extends QuerySchema, K extends keyof S["~byName"]> = FieldWhere<RowOf<S, K>> & {
35
+ readonly [R in RelationKeys<RelationsOf<S, K>>]?: RelFilter<S, RelationsOf<S, K>[R]> | undefined;
36
+ };
37
+ /** `where` for one table. `or()` may be the whole filter. */
38
+ export type WhereOf<S extends QuerySchema, K extends keyof S["~byName"]> = FiltersOf<S, K> | Or<FiltersOf<S, K>>;
39
+ /** `orderBy`. `asc` is nulls last and `desc` is nulls first unless `nulls` is set. */
40
+ export type OrderBy<Row> = {
41
+ readonly [K in keyof Row]?: "asc" | "desc" | {
42
+ readonly dir: "asc" | "desc";
43
+ readonly nulls?: "first" | "last";
44
+ } | undefined;
45
+ };
46
+ type Related<S extends QuerySchema, T extends keyof S["~byName"], Opt> = Opt extends {
47
+ readonly select: infer Sel;
48
+ } ? Selected<RowOf<S, T>, Sel> : RowOf<S, T>;
49
+ /** One include. To-many needs `limit`. */
50
+ export type IncludeOf<S extends QuerySchema, K extends keyof S["~byName"]> = {
51
+ readonly [R in RelationKeys<RelationsOf<S, K>>]?: RelationsOf<S, K>[R] extends {
52
+ readonly kind: "many";
53
+ readonly table: infer T extends string;
54
+ } ? T extends keyof S["~byName"] ? {
55
+ readonly limit: number;
56
+ readonly select?: readonly (keyof RowOf<S, T> & string)[];
57
+ readonly where?: FieldWhere<RowOf<S, T>>;
58
+ readonly orderBy?: OrderBy<RowOf<S, T>>;
59
+ } : never : RelationsOf<S, K>[R] extends {
60
+ readonly kind: "one";
61
+ readonly table: infer T extends string;
62
+ } ? T extends keyof S["~byName"] ? true | {
63
+ readonly select?: readonly (keyof RowOf<S, T> & string)[];
64
+ readonly where?: FieldWhere<RowOf<S, T>>;
65
+ readonly orderBy?: OrderBy<RowOf<S, T>>;
66
+ } : never : never;
67
+ };
68
+ /** Columns kept by `select`. The full row when `select` is omitted. */
69
+ export type Selected<Row, Sel> = [Sel] extends [readonly (infer P)[]] ? [P] extends [keyof Row] ? {
70
+ readonly [K in P & keyof Row]: Row[K];
71
+ } : Row : Row;
72
+ type IncludeRows<S extends QuerySchema, K extends keyof S["~byName"], Inc> = [Inc] extends [
73
+ Record<string, unknown>
74
+ ] ? {
75
+ readonly [R in keyof Inc & keyof RelationsOf<S, K>]: RelationsOf<S, K>[R] extends {
76
+ readonly kind: "many";
77
+ readonly table: infer T extends keyof S["~byName"];
78
+ } ? readonly Related<S, T, Inc[R]>[] : RelationsOf<S, K>[R] extends {
79
+ readonly kind: "one";
80
+ readonly table: infer T extends keyof S["~byName"];
81
+ } ? Related<S, T, Inc[R]> | null : never;
82
+ } : unknown;
83
+ /**
84
+ * Rewrites a row so an editor shows the fields.
85
+ *
86
+ * A key-remapped alias such as `RowFrom` stays collapsed in hover and prints
87
+ * the column builders. This mapped type is what quickinfo expands.
88
+ */
89
+ type Show<T> = {
90
+ [K in keyof T]: T[K];
91
+ } & {};
92
+ /** Find or one row, plus includes. */
93
+ export type ResultRow<S extends QuerySchema, K extends keyof S["~byName"], O> = Show<Selected<RowOf<S, K>, O extends {
94
+ readonly select: infer Sel;
95
+ } ? Sel : undefined> & IncludeRows<S, K, O extends {
96
+ readonly include: infer Inc;
97
+ } ? Inc : undefined>>;
98
+ /** Options shared by reads. */
99
+ export type ReadOptions<S extends QuerySchema, K extends keyof S["~byName"]> = {
100
+ readonly where?: WhereOf<S, K>;
101
+ readonly select?: readonly (keyof RowOf<S, K> & string)[];
102
+ readonly orderBy?: OrderBy<RowOf<S, K>>;
103
+ readonly include?: IncludeOf<S, K>;
104
+ };
105
+ /** `find` options. `limit` is required unless the caller uses `.all(reason)`. */
106
+ export type FindOptions<S extends QuerySchema, K extends keyof S["~byName"]> = ReadOptions<S, K> & {
107
+ readonly limit?: number;
108
+ };
109
+ /** A query handle. Await it, or inspect it before it runs. */
110
+ export type Read<T> = Promise<T> & {
111
+ /** Logical intent, rules, plan, SQL, parameters, and the routing decision. */
112
+ inspect(): Inspection | Promise<Inspection>;
113
+ /** Statement text and parameters. */
114
+ sql(): {
115
+ readonly text: string;
116
+ readonly params: readonly (string | null)[];
117
+ } | Promise<{
118
+ readonly text: string;
119
+ readonly params: readonly (string | null)[];
120
+ }>;
121
+ /** `{ ok, value }` or `{ ok, error }`. */
122
+ safe(): Promise<SafeResult<T>>;
123
+ /** Allows `find` or a to-many include without `limit`. */
124
+ all(reason: string): Read<T>;
125
+ /** Turns a null `one()` into `not_found`. */
126
+ required(): Read<NonNullable<T>>;
127
+ /** Streams rows when the driver has `stream`. Otherwise OKM1111. */
128
+ stream(): AsyncIterable<T extends readonly (infer R)[] ? R : T>;
129
+ };
130
+ /** What {@link Read.inspect} returns. */
131
+ export type Inspection = {
132
+ readonly intent: {
133
+ readonly op: ReadOp;
134
+ readonly table: string;
135
+ readonly where: unknown;
136
+ readonly select: unknown;
137
+ readonly orderBy: unknown;
138
+ readonly limit: unknown;
139
+ readonly include: unknown;
140
+ readonly all: string | undefined;
141
+ };
142
+ readonly rules: readonly AppliedRule[];
143
+ readonly plan: {
144
+ readonly strategy: "postgres:single-statement";
145
+ readonly statements: 1;
146
+ readonly fingerprint: string;
147
+ };
148
+ readonly sql: {
149
+ readonly text: string;
150
+ readonly params: readonly (string | null)[];
151
+ };
152
+ readonly routing: RoutingDecision;
153
+ };
154
+ /** Why the router chose an endpoint. */
155
+ export type RoutingDecision = {
156
+ readonly endpoint: string;
157
+ readonly role: "primary" | "replica";
158
+ readonly reason: string;
159
+ };
160
+ /** One pool the router can return. */
161
+ export type Endpoint = {
162
+ readonly name: string;
163
+ readonly role: "primary" | "replica";
164
+ readonly pool: {
165
+ readonly capabilities: {
166
+ readonly stream: boolean;
167
+ };
168
+ execute(text: string, params?: readonly (string | null)[], options?: {
169
+ readonly signal?: AbortSignal;
170
+ readonly timeout?: number;
171
+ }): Promise<{
172
+ readonly rows: readonly (readonly (string | null)[])[];
173
+ }>;
174
+ stream?(text: string, params?: readonly (string | null)[]): AsyncIterable<readonly (readonly (string | null)[])[]>;
175
+ close(): Promise<void>;
176
+ };
177
+ };
178
+ /** A target's endpoints. The primary is not a replica. */
179
+ export type Topology = {
180
+ readonly primary: Endpoint;
181
+ readonly replicas: readonly Endpoint[];
182
+ };
183
+ /** A named target. P15 has one. */
184
+ export type Target = {
185
+ readonly name: string;
186
+ readonly topology: Topology;
187
+ };
188
+ /** Picks an endpoint. One operation uses one endpoint. */
189
+ export type Router = {
190
+ route(input: {
191
+ readonly operation: "read" | "write";
192
+ readonly constraint: "auto" | "primary" | "replica";
193
+ }): RoutingDecision;
194
+ };
195
+ /**
196
+ * Required keys of an insert row.
197
+ *
198
+ * A key whose value includes `undefined` is optional. Marking it required makes
199
+ * the editor offer only the property under the cursor (D139).
200
+ *
201
+ * @typeParam T - Insert shape
202
+ */
203
+ type RequiredInsert<T> = {
204
+ readonly [K in keyof T as undefined extends T[K] ? never : K]: T[K];
205
+ };
206
+ /**
207
+ * Optional keys of an insert row.
208
+ *
209
+ * @typeParam T - Insert shape
210
+ */
211
+ type OptionalInsert<T> = {
212
+ readonly [K in keyof T as undefined extends T[K] ? K : never]?: T[K];
213
+ };
214
+ /** Insert shape of one table. */
215
+ export type InsertOf<S extends QuerySchema, K extends keyof S["~byName"]> = S["~byName"][K] extends {
216
+ readonly "~insert": infer I;
217
+ } ? I : never;
218
+ /** Update shape of one table. */
219
+ export type UpdateOf<S extends QuerySchema, K extends keyof S["~byName"]> = S["~byName"][K] extends {
220
+ readonly "~update": infer U;
221
+ } ? U : never;
222
+ /** `set` values. `undefined` leaves the field unchanged. `inc` adds to it. */
223
+ export type UpdateSet<S extends QuerySchema, K extends keyof S["~byName"]> = {
224
+ readonly [F in keyof UpdateOf<S, K>]?: UpdateOf<S, K>[F] | Inc<NonNullable<UpdateOf<S, K>[F]>>;
225
+ };
226
+ /** Conflict handling on `insert` (spec §11). */
227
+ export type OnConflict<S extends QuerySchema, K extends keyof S["~byName"]> = "error" | "ignore" | {
228
+ readonly on: string | readonly string[];
229
+ readonly update: readonly (keyof UpdateOf<S, K> & string)[];
230
+ } | {
231
+ readonly on: string | readonly string[];
232
+ readonly return: true;
233
+ };
234
+ /** Options for `insert`. */
235
+ export type InsertOptions<S extends QuerySchema, K extends keyof S["~byName"]> = {
236
+ readonly onConflict?: OnConflict<S, K>;
237
+ readonly returning?: readonly (keyof RowOf<S, K> & string)[];
238
+ readonly expect?: number;
239
+ readonly signal?: AbortSignal;
240
+ readonly timeout?: number;
241
+ };
242
+ /** Options for `update` and `delete`. */
243
+ export type WriteOptions<S extends QuerySchema, K extends keyof S["~byName"]> = {
244
+ readonly returning?: readonly (keyof RowOf<S, K> & string)[];
245
+ readonly expect?: number;
246
+ readonly signal?: AbortSignal;
247
+ readonly timeout?: number;
248
+ };
249
+ /** `{ count }` from an update or delete without `returning`. */
250
+ export type WriteCount = {
251
+ readonly count: number;
252
+ };
253
+ /** A write handle. Await it, or read its SQL before it runs. */
254
+ export type Write<T> = Promise<T> & {
255
+ /** Statement text and parameters, one entry per chunk. */
256
+ sql(): Promise<{
257
+ readonly statements: readonly {
258
+ readonly text: string;
259
+ readonly params?: readonly (string | null)[];
260
+ }[];
261
+ }>;
262
+ /** `{ ok, value }` or `{ ok, error }`. */
263
+ safe(): Promise<SafeResult<T>>;
264
+ /** Throws `not_found` when the changed-row count is not `count`. */
265
+ expect(count: number): Write<T>;
266
+ /** Allows `update` or `delete` without `where`. */
267
+ all(reason: string): Write<T>;
268
+ };
269
+ /** One update, or a per-row list in one statement. */
270
+ export type UpdateTarget<S extends QuerySchema, K extends keyof S["~byName"]> = {
271
+ readonly where?: WhereOf<S, K>;
272
+ readonly set: UpdateSet<S, K>;
273
+ } | readonly {
274
+ readonly id?: unknown;
275
+ readonly where?: WhereOf<S, K>;
276
+ readonly set: UpdateSet<S, K>;
277
+ }[];
278
+ /** Methods on one table. */
279
+ export type TableApi<S extends QuerySchema, K extends keyof S["~byName"] & string> = {
280
+ find<const O extends FindOptions<S, K> & {
281
+ readonly limit: number;
282
+ }>(options: O): Read<readonly ResultRow<S, K, O>[]>;
283
+ find<const O extends FindOptions<S, K>>(options: O): {
284
+ all(reason: string): Read<readonly ResultRow<S, K, O>[]>;
285
+ };
286
+ one<const O extends ReadOptions<S, K>>(options?: O): Read<ResultRow<S, K, O> | null>;
287
+ count(options?: {
288
+ readonly where?: WhereOf<S, K>;
289
+ }): Read<number>;
290
+ exists(options?: {
291
+ readonly where?: WhereOf<S, K>;
292
+ }): Read<boolean>;
293
+ /**
294
+ * Inserts one row. Unknown keys are dropped.
295
+ *
296
+ * Optional columns are optional keys, so completion lists the ones not yet written.
297
+ */
298
+ insert(data: RequiredInsert<InsertOf<S, K>> & OptionalInsert<InsertOf<S, K>>, options?: InsertOptions<S, K>): Write<Show<RowOf<S, K>>>;
299
+ /** Inserts a list in one transaction. Unknown keys are dropped. */
300
+ insert(data: readonly InsertOf<S, K>[], options?: InsertOptions<S, K>): Write<readonly Show<RowOf<S, K>>[]>;
301
+ /** Updates matching rows, or a per-row list in one statement. `where` is required. */
302
+ update(target: UpdateTarget<S, K>, options?: WriteOptions<S, K>): Write<WriteCount>;
303
+ /** Deletes matching rows. `where` is required. */
304
+ delete(target: {
305
+ readonly where?: WhereOf<S, K>;
306
+ }, options?: WriteOptions<S, K>): Write<WriteCount>;
307
+ };
308
+ /**
309
+ * `[Symbol.asyncDispose]` when `Symbol` defines it.
310
+ *
311
+ * The check stays in the built declaration. A consumer `lib` without
312
+ * `asyncDispose` does not see the method, including with `skipLibCheck` off.
313
+ */
314
+ type IfAsyncDisposable<S> = S extends {
315
+ readonly asyncDispose: infer D;
316
+ } ? D extends symbol ? {
317
+ [K in D]: () => Promise<void>;
318
+ } : object : object;
319
+ /** A client typed by its own schema. */
320
+ export type Connected<S extends QuerySchema> = {
321
+ readonly [K in keyof S["~byName"] & string]: TableApi<S, K>;
322
+ } & {
323
+ /** Looks up a table by name. An unknown name is OKM1120. */
324
+ table<K extends keyof S["~byName"] & string>(name: K): TableApi<S, K>;
325
+ /**
326
+ * Closes the pool when this client opened it.
327
+ *
328
+ * A second call waits on the same close. A client that adopted a pool
329
+ * resolves without closing it.
330
+ */
331
+ close(): Promise<void>;
332
+ /** Resolves when the dialect and `requires` checks have finished. */
333
+ readonly connected: Promise<void>;
334
+ } & IfAsyncDisposable<typeof Symbol>;
335
+ /**
336
+ * A catalog `okm build` wrote.
337
+ *
338
+ * `connect` trusts it through `loadTrustedCatalog` when the database hash differs.
339
+ */
340
+ export type CatalogArtifact = {
341
+ readonly text: string;
342
+ readonly hash: string;
343
+ };
344
+ /** `connect` options shared by the Postgres drivers. */
345
+ export type ConnectOptions<S extends QuerySchema> = {
346
+ readonly schema: S;
347
+ /**
348
+ * Build artifact. When set, its hash is the code's catalog hash.
349
+ * The JSON is checked only when the database hash differs.
350
+ */
351
+ readonly catalog?: CatalogArtifact;
352
+ /**
353
+ * Directory of `catalog.hash` and `catalog.json`.
354
+ *
355
+ * When omitted, `connect` reads `.okm` under the process cwd if that hash file exists.
356
+ */
357
+ readonly catalogDir?: string;
358
+ readonly logger?: {
359
+ error?(entry: {
360
+ readonly code: string;
361
+ readonly summary: string;
362
+ }): void;
363
+ };
364
+ readonly errors?: {
365
+ /**
366
+ * Statuses for {@link OkmError.toHttp}.
367
+ *
368
+ * `toHttp()` uses these when the caller does not pass statuses.
369
+ * `toHttp(statuses)` replaces them for that call.
370
+ */
371
+ readonly http?: import("../contracts/error.js").ErrorStatuses;
372
+ readonly includeValues?: boolean;
373
+ };
374
+ /**
375
+ * Fail `connect` when `okm_meta` has no catalog hash (OKM1520).
376
+ *
377
+ * Omitted, a database with no recorded hash skips the drift check so an
378
+ * existing database can adopt OKModel. Set this on a production connection.
379
+ * The target name and `NODE_ENV` do not turn it on.
380
+ */
381
+ readonly requireMeta?: boolean;
382
+ readonly signal?: AbortSignal;
383
+ readonly timeout?: number;
384
+ };
385
+ export {};
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Insert, update, and delete.
3
+ *
4
+ * Loaded on the first write. Conflict SQL loads only when `onConflict` is not
5
+ * `"error"`. Chunked writes go through the internal transaction runner.
6
+ */
7
+ import type { DriverPool, Statement } from "../contracts/driver.js";
8
+ import type { QuerySchema } from "../dialects/pg/model.js";
9
+ /** Statements in one insert stay under this many parameters. The protocol limit is 65535. */
10
+ export declare const WRITE_PARAM_BUDGET = 2048;
11
+ /** A write the caller asked for. */
12
+ export type WriteOp = "insert" | "update" | "delete";
13
+ /** Modifiers chained on the write handle. */
14
+ export type WriteMods = {
15
+ readonly all?: string;
16
+ readonly expect?: number;
17
+ };
18
+ /** Pool and schema for one client. The client maps driver errors. */
19
+ export type WriteHost = {
20
+ readonly schema: QuerySchema;
21
+ readonly pool: DriverPool;
22
+ };
23
+ /**
24
+ * Runs a write and decodes it.
25
+ *
26
+ * @param host - Client schema and pool
27
+ * @param op - Insert, update, or delete
28
+ * @param table - Table name
29
+ * @param input - Rows, or the update or delete target
30
+ * @param options - Returning, conflict, expect, signal, timeout
31
+ * @param mods - `.all` and `.expect`
32
+ * @returns Rows, one row, or `{ count }`
33
+ */
34
+ export declare function executeWrite(host: WriteHost, op: WriteOp, table: string, input: unknown, options: object, mods: WriteMods): Promise<unknown>;
35
+ /**
36
+ * Plans a write and does not run it.
37
+ *
38
+ * @param schema - Connected schema
39
+ * @param op - Insert, update, or delete
40
+ * @param table - Table name
41
+ * @param input - Rows, or the update or delete target
42
+ * @param options - Returning, conflict, expect, signal, timeout
43
+ * @param mods - `.all` and `.expect`
44
+ * @returns The statements in order
45
+ */
46
+ export declare function explainWrite(schema: QuerySchema, op: WriteOp, table: string, input: unknown, options: object, mods: WriteMods): Promise<{
47
+ readonly statements: readonly Statement[];
48
+ }>;