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.
Files changed (147) hide show
  1. package/README.md +44 -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 +369 -0
  100. package/dist/runtime/write.d.ts +48 -0
  101. package/dist/shared/4j72449d.js +37 -0
  102. package/dist/shared/79ggp945.js +148 -0
  103. package/dist/shared/7ck0dtry.js +259 -0
  104. package/dist/shared/8b04d28c.js +14 -0
  105. package/dist/shared/ax16zpvm.js +171 -0
  106. package/dist/shared/ckb1p0a4.js +566 -0
  107. package/dist/shared/cn0n68ft.js +16 -0
  108. package/dist/shared/dynq16vb.js +81 -0
  109. package/dist/shared/f5thc1s0.js +1050 -0
  110. package/dist/shared/fgqgsb5z.js +281 -0
  111. package/dist/shared/g2v6gnc8.js +347 -0
  112. package/dist/shared/g5fhqmwe.js +188 -0
  113. package/dist/shared/gk7cs7sp.js +566 -0
  114. package/dist/shared/hd293j9g.js +98 -0
  115. package/dist/shared/j5cn2963.js +701 -0
  116. package/dist/shared/kynx7vbm.js +1490 -0
  117. package/dist/shared/mkjmqjv4.js +456 -0
  118. package/dist/shared/mtkwv8wx.js +18 -0
  119. package/dist/shared/ngk8gj61.js +40 -0
  120. package/dist/shared/p0cbr3g2.js +79 -0
  121. package/dist/shared/px90pf9p.js +396 -0
  122. package/dist/shared/qk3hxfja.js +83 -0
  123. package/dist/shared/tb4ze1tr.js +119 -0
  124. package/dist/shared/vkm3q4x1.js +30 -0
  125. package/dist/shared/w8samvk1.js +18 -0
  126. package/dist/shared/xy79j5hq.js +177 -0
  127. package/dist/shared/y9m15dfv.js +888 -0
  128. package/dist/shared/ycwz42az.js +412 -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 +94 -7
  147. package/dist/index.js +0 -0
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Catalog kinds, identity, and the shared envelope.
3
+ *
4
+ * Every object uses one envelope (kind, identity, owner, definition,
5
+ * dependencies, provenance). Kinds other than table, column, index,
6
+ * constraint, sequence, and type (enum) are named here so a later prompt
7
+ * can fill them in without changing the envelope.
8
+ */
9
+ /** Who may change an object. `ignored` is invisible to diffs. */
10
+ export declare const OWNERS: readonly ["managed", "external", "ignored"];
11
+ /** Ownership stored on every catalog object. */
12
+ export type Owner = (typeof OWNERS)[number];
13
+ /**
14
+ * Object kinds from spec section 5.7.
15
+ *
16
+ * Built in this layer: table, column, index, constraint, sequence, and type.
17
+ * A type object is an enum: ordered labels, and no other form.
18
+ */
19
+ export declare const OBJECT_KINDS: readonly ["table", "column", "index", "constraint", "sequence", "view", "materializedView", "type", "function", "trigger", "policy", "extension", "role", "grant", "defaultPrivilege"];
20
+ /** A catalog object kind. */
21
+ export type ObjectKind = (typeof OBJECT_KINDS)[number];
22
+ /** Kinds that have factories in this layer. */
23
+ export declare const BUILT_KINDS: readonly ["table", "column", "index", "constraint", "sequence", "type"];
24
+ /** A kind this layer can construct. */
25
+ export type BuiltKind = (typeof BUILT_KINDS)[number];
26
+ /**
27
+ * Lifecycle operations a kind declares.
28
+ *
29
+ * Spec section 5.7: create, replace when compatible, alter, drop, and
30
+ * recreate-with-dependents.
31
+ */
32
+ export declare const OBJECT_OPERATIONS: readonly ["create", "replace", "alter", "drop", "recreateWithDependents"];
33
+ /** One lifecycle operation. */
34
+ export type ObjectOperation = (typeof OBJECT_OPERATIONS)[number];
35
+ /**
36
+ * Operations each kind declares.
37
+ *
38
+ * Roles are created and altered in place and are never dropped (D119).
39
+ * Materialized views have no replace. Grants and default privileges are
40
+ * declared so the map covers section 5.7; those objects are not built here.
41
+ */
42
+ export declare const KIND_OPERATIONS: {
43
+ readonly [K in ObjectKind]: readonly ObjectOperation[];
44
+ };
45
+ /**
46
+ * A schema name.
47
+ *
48
+ * `static` is a concrete schema. `template` keeps a pattern such as
49
+ * `tenant_{id}`. Snapshots and diffs store the template.
50
+ */
51
+ export type Namespace = {
52
+ readonly form: "static";
53
+ readonly name: string;
54
+ } | {
55
+ readonly form: "template";
56
+ readonly pattern: string;
57
+ };
58
+ /**
59
+ * A table (or other namespace-qualified parent) inside a namespace.
60
+ *
61
+ * The namespace may be a template. It is not resolved here.
62
+ */
63
+ export type ObjectRef = {
64
+ readonly namespace: Namespace;
65
+ readonly name: string;
66
+ };
67
+ /** Identity of a table, view, materialized view, sequence, or type. */
68
+ export type NamespaceIdentity = {
69
+ readonly kind: "table" | "view" | "materializedView" | "sequence" | "type";
70
+ readonly namespace: Namespace;
71
+ readonly name: string;
72
+ };
73
+ /**
74
+ * Identity of an object that lives on a parent table.
75
+ *
76
+ * Columns, indexes, and constraints use `(parent, name)`. Triggers and
77
+ * policies use `(table, name)`, the same shape.
78
+ */
79
+ export type AnchoredIdentity = {
80
+ readonly kind: "column" | "index" | "constraint" | "trigger" | "policy";
81
+ readonly parent: ObjectRef;
82
+ readonly name: string;
83
+ };
84
+ /** Function identity. Argument types keep overloads distinct. */
85
+ export type FunctionIdentity = {
86
+ readonly kind: "function";
87
+ readonly namespace: Namespace;
88
+ readonly name: string;
89
+ readonly argTypes: readonly string[];
90
+ };
91
+ /**
92
+ * Grant identity.
93
+ *
94
+ * The key is `(role, object, privilege)`. It is not a stored identifier and
95
+ * is exempt from the dialect length limit (D119).
96
+ */
97
+ export type GrantIdentity = {
98
+ readonly kind: "grant";
99
+ readonly role: string;
100
+ readonly object: GrantObjectRef;
101
+ readonly privilege: string;
102
+ };
103
+ /** What a grant attaches to. `namespace` is the schema itself. */
104
+ export type GrantObjectRef = {
105
+ readonly kind: "table" | "sequence" | "namespace";
106
+ readonly namespace: Namespace;
107
+ readonly name: string;
108
+ };
109
+ /**
110
+ * Default-privilege identity.
111
+ *
112
+ * The key is `(forRole, namespace, objectKind, grantee, privilege)`. It is
113
+ * exempt from the dialect length limit (D119).
114
+ */
115
+ export type DefaultPrivilegeIdentity = {
116
+ readonly kind: "defaultPrivilege";
117
+ readonly forRole: string;
118
+ readonly namespace: Namespace;
119
+ readonly objectKind: string;
120
+ readonly grantee: string;
121
+ readonly privilege: string;
122
+ };
123
+ /** Role identity. Roles are cluster objects and have no namespace. */
124
+ export type RoleIdentity = {
125
+ readonly kind: "role";
126
+ readonly name: string;
127
+ };
128
+ /** Extension identity. Extensions are database-scoped and have no namespace. */
129
+ export type ExtensionIdentity = {
130
+ readonly kind: "extension";
131
+ readonly name: string;
132
+ };
133
+ /** Stable identity. The variant depends on the kind. */
134
+ export type ObjectIdentity = NamespaceIdentity | AnchoredIdentity | FunctionIdentity | GrantIdentity | DefaultPrivilegeIdentity | RoleIdentity | ExtensionIdentity;
135
+ /** Where an object came from. */
136
+ export type Provenance = {
137
+ readonly origin: "file";
138
+ readonly name: string;
139
+ } | {
140
+ readonly origin: "trait";
141
+ readonly name: string;
142
+ } | {
143
+ readonly origin: "extension";
144
+ readonly name: string;
145
+ };
146
+ /**
147
+ * An edge to another object.
148
+ *
149
+ * A target whose kind is `column` is column granularity. Any other kind is
150
+ * object granularity.
151
+ */
152
+ export type DependencyEdge = {
153
+ readonly target: ObjectIdentity;
154
+ };
155
+ /** How a partitioned table assigns rows. */
156
+ export type PartitionMethod = "range" | "list" | "hash";
157
+ /** Table definition. Columns, indexes, and constraints are their own objects. */
158
+ export type TableDefinition = {
159
+ readonly partition?: {
160
+ readonly method: PartitionMethod;
161
+ readonly columns: readonly string[];
162
+ };
163
+ };
164
+ /**
165
+ * Column definition.
166
+ *
167
+ * `dataType` is the type name (`uuid`, `text`, `varchar(200)`), not a SQL
168
+ * expression. At most one of `defaultExpression`, `identity`, and `generated`
169
+ * is set.
170
+ */
171
+ export type ColumnDefinition = {
172
+ readonly dataType: string;
173
+ readonly nullable: boolean;
174
+ readonly defaultExpression?: string;
175
+ readonly identity?: {
176
+ readonly always: boolean;
177
+ };
178
+ readonly generated?: {
179
+ readonly stored: boolean;
180
+ readonly expression: string;
181
+ };
182
+ };
183
+ /**
184
+ * Index definition.
185
+ *
186
+ * `nameKey` is the stable token the name was generated from. It does not
187
+ * follow a later field rename. Column order is significant.
188
+ */
189
+ export type IndexDefinition = {
190
+ readonly columns: readonly string[];
191
+ readonly unique: boolean;
192
+ readonly nameKey: string;
193
+ readonly predicate?: string;
194
+ readonly expression?: string;
195
+ };
196
+ /** Constraint family. */
197
+ export type ConstraintKind = "primaryKey" | "unique" | "foreignKey" | "check";
198
+ /**
199
+ * What Postgres does when a referenced row changes.
200
+ *
201
+ * Stored on the foreign key so `onDelete` and `onUpdate` survive compile.
202
+ */
203
+ export declare const REFERENTIAL_ACTIONS: readonly ["cascade", "no action", "restrict", "set default", "set null"];
204
+ /** One referential action. */
205
+ export type ReferentialAction = (typeof REFERENTIAL_ACTIONS)[number];
206
+ /**
207
+ * Returns the action when `value` is one this catalog stores.
208
+ *
209
+ * @param value - Author or document text
210
+ * @returns The action, or `undefined` when it is not in the list
211
+ */
212
+ export declare function referentialAction(value: string): ReferentialAction | undefined;
213
+ /** Constraint definition. `nameKey` stays put when a field is renamed. */
214
+ export type ConstraintDefinition = {
215
+ readonly constraintKind: ConstraintKind;
216
+ readonly columns: readonly string[];
217
+ readonly nameKey: string;
218
+ readonly deferrable: boolean;
219
+ readonly initially: "immediate" | "deferred";
220
+ readonly nullsNotDistinct: boolean;
221
+ readonly expression?: string;
222
+ readonly references?: {
223
+ readonly parent: ObjectRef;
224
+ readonly columns: readonly string[];
225
+ readonly onDelete?: ReferentialAction;
226
+ readonly onUpdate?: ReferentialAction;
227
+ };
228
+ };
229
+ /**
230
+ * Enum definition.
231
+ *
232
+ * `labels` is the stored order. That order is part of the catalog hash.
233
+ * Domains are not represented here.
234
+ */
235
+ export type TypeDefinition = {
236
+ readonly labels: readonly string[];
237
+ };
238
+ /** Sequence definition. Start and increment are decimal integers. */
239
+ export type SequenceDefinition = {
240
+ readonly dataType: "smallint" | "integer" | "bigint";
241
+ readonly start: string;
242
+ readonly increment: string;
243
+ readonly cycle: boolean;
244
+ };
245
+ /** Shared fields on every catalog object. */
246
+ export type CatalogEnvelope<K extends ObjectKind, I extends ObjectIdentity, D> = {
247
+ readonly kind: K;
248
+ readonly identity: I;
249
+ readonly owner: Owner;
250
+ readonly definition: D;
251
+ readonly dependencies: readonly DependencyEdge[];
252
+ readonly provenance: Provenance;
253
+ };
254
+ /** A table, possibly partitioned. Copied partition keys are not objects. */
255
+ export type TableObject = CatalogEnvelope<"table", NamespaceIdentity & {
256
+ readonly kind: "table";
257
+ }, TableDefinition>;
258
+ /** A column of a table. */
259
+ export type ColumnObject = CatalogEnvelope<"column", AnchoredIdentity & {
260
+ readonly kind: "column";
261
+ }, ColumnDefinition>;
262
+ /** A secondary index. */
263
+ export type IndexObject = CatalogEnvelope<"index", AnchoredIdentity & {
264
+ readonly kind: "index";
265
+ }, IndexDefinition>;
266
+ /** A table constraint. */
267
+ export type ConstraintObject = CatalogEnvelope<"constraint", AnchoredIdentity & {
268
+ readonly kind: "constraint";
269
+ }, ConstraintDefinition>;
270
+ /** A sequence. */
271
+ export type SequenceObject = CatalogEnvelope<"sequence", NamespaceIdentity & {
272
+ readonly kind: "sequence";
273
+ }, SequenceDefinition>;
274
+ /** An enum. Identity is `(namespace, name)`. */
275
+ export type TypeObject = CatalogEnvelope<"type", NamespaceIdentity & {
276
+ readonly kind: "type";
277
+ }, TypeDefinition>;
278
+ /**
279
+ * One built catalog object.
280
+ *
281
+ * Views, functions, triggers, extensions, roles, grants, and default
282
+ * privileges use {@link CatalogEnvelope} when they are built. They are not
283
+ * part of this union yet.
284
+ */
285
+ export type CatalogObject = TableObject | ColumnObject | IndexObject | ConstraintObject | SequenceObject | TypeObject;
286
+ /** Format version stored in the serialized catalog. */
287
+ export declare const CATALOG_VERSION = 1;
288
+ /** A catalog document. Object order is identity-key order. */
289
+ export type Catalog = {
290
+ readonly version: typeof CATALOG_VERSION;
291
+ readonly objects: readonly CatalogObject[];
292
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * PostgreSQL reserved keywords.
3
+ *
4
+ * An unquoted reserved word is rejected (OKM1122). Non-reserved keywords are
5
+ * allowed as names. The list is the PostgreSQL 17 "reserved" column. The set
6
+ * is built on first use.
7
+ */
8
+ /**
9
+ * Reserved keywords, lowercase.
10
+ *
11
+ * @returns The PostgreSQL reserved-word set
12
+ */
13
+ export declare function reservedWords(): ReadonlySet<string>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Connection failures shared by adapters and the Postgres error mapping.
3
+ *
4
+ * A lost connection during `COMMIT` is `outcome_unknown` (the adapter decides
5
+ * that). Any other connection failure is kind `unavailable`.
6
+ */
7
+ /**
8
+ * Reports whether `sqlstate` is a connection or availability class.
9
+ *
10
+ * Class `08` is connection exception. `53300` is too many connections.
11
+ * `57P01`–`57P03` are shutdown and "cannot connect now".
12
+ *
13
+ * @param sqlstate - Postgres SQLSTATE
14
+ * @returns `true` when the server could not keep the session
15
+ */
16
+ export declare function isConnectionSqlstate(sqlstate: string): boolean;
17
+ /**
18
+ * Reports whether a driver or OS code means the socket is gone.
19
+ *
20
+ * @param code - `error.code` from Node or the driver
21
+ * @returns `true` for a refused, reset, or closed connection
22
+ */
23
+ export declare function isConnectionErrno(code: string): boolean;
24
+ /**
25
+ * Reports whether `error` is a dropped or refused connection.
26
+ *
27
+ * Constraint failures are not connection failures. `23505` stays a unique
28
+ * violation even when it is raised at commit.
29
+ *
30
+ * @param error - Caught value
31
+ * @returns `true` when no session remains
32
+ */
33
+ export declare function isConnectionFailure(error: unknown): boolean;
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Driver contract (spec §4.2). Types only: this module has no runtime.
3
+ *
4
+ * Adapters implement these shapes. Values cross the boundary as wire text.
5
+ * Codecs stay in the dialect.
6
+ */
7
+ /** How a driver runs transactions. Atomic `batch` is not a mode. */
8
+ export type TransactionMode = "interactive" | "batch" | "none";
9
+ /** How a driver prepares statements. */
10
+ export type PreparedMode = "named" | "unnamed" | "none";
11
+ /**
12
+ * Execution capabilities for one driver (spec §4).
13
+ *
14
+ * Atomic `batch` is required on every driver and is not a flag.
15
+ */
16
+ export type DriverCapabilities = {
17
+ /** `reserve` exists only when this is `"interactive"`. */
18
+ readonly transactions: TransactionMode;
19
+ /** Rows can be pulled in chunks. */
20
+ readonly stream: boolean;
21
+ /** `LISTEN` / `NOTIFY`. */
22
+ readonly listen: boolean;
23
+ /** An in-flight statement can be aborted. */
24
+ readonly cancel: boolean;
25
+ /** Prepared-statement mode this driver uses. */
26
+ readonly prepared: PreparedMode;
27
+ /** The server can describe a statement without running it. */
28
+ readonly describe: boolean;
29
+ };
30
+ /** A Postgres wire value. Null is SQL NULL. */
31
+ export type WireValue = string | null;
32
+ /** One statement. `$1` is `params[0]`. */
33
+ export type Statement = {
34
+ readonly text: string;
35
+ /** Wire parameters. Omitted when the statement has none. */
36
+ readonly params?: readonly WireValue[];
37
+ };
38
+ /** A server notice, normalised from the driver's own notice object. */
39
+ export type Notice = {
40
+ readonly severity: string;
41
+ readonly code?: string;
42
+ readonly message: string;
43
+ };
44
+ /**
45
+ * Result of one statement.
46
+ *
47
+ * `count` is the affected-row count. `rows` are wire text.
48
+ */
49
+ export type ExecuteResult = {
50
+ readonly rows: readonly (readonly WireValue[])[];
51
+ readonly count: number;
52
+ readonly notices: readonly Notice[];
53
+ };
54
+ /** Per-call cancellation and deadline (spec §4.2, §15). */
55
+ export type ExecuteOptions = {
56
+ /** Abort the call. An abort is kind `cancelled`. */
57
+ readonly signal?: AbortSignal;
58
+ /**
59
+ * Milliseconds for the whole call.
60
+ *
61
+ * A deadline is kind `timeout`.
62
+ */
63
+ readonly timeout?: number;
64
+ };
65
+ /** Column names and parameter count from a describe. */
66
+ export type DescribeResult = {
67
+ readonly columns: readonly string[];
68
+ readonly parameterCount: number;
69
+ };
70
+ /** Pool counters for selection strategies (spec §4.2). */
71
+ export type DriverStats = {
72
+ readonly size: number;
73
+ readonly idle: number;
74
+ readonly inflight: number;
75
+ readonly waiting: number;
76
+ };
77
+ /**
78
+ * Why a call ended before a statement result (D124).
79
+ *
80
+ * `outcome_unknown` means a commit was sent and the result never arrived.
81
+ * The dialect maps it to OKM1401. Adapters do not construct `OkmError`.
82
+ */
83
+ export type DriverFailureKind = "timeout" | "cancelled" | "outcome_unknown";
84
+ /**
85
+ * Fields on {@link DriverError}.
86
+ *
87
+ * `batchIndex` is the failing statement, or `null` when the failure is the
88
+ * commit itself (a deferred constraint). `kind` is set for a timeout, an
89
+ * abort, or a commit whose result never arrived, and is absent on a database
90
+ * error.
91
+ */
92
+ export type DriverErrorFields = {
93
+ readonly sqlstate?: string;
94
+ readonly constraint?: string;
95
+ readonly table?: string;
96
+ readonly column?: string;
97
+ readonly detail?: string;
98
+ readonly cause?: unknown;
99
+ readonly batchIndex?: number | null;
100
+ readonly kind?: DriverFailureKind;
101
+ };
102
+ /**
103
+ * A connection checked out of a pool.
104
+ *
105
+ * Present when `transactions` is `"interactive"`. `batch` on a connection
106
+ * that already has a transaction uses a savepoint and does not commit the
107
+ * outer transaction (D124).
108
+ */
109
+ export type DriverConnection = {
110
+ /** Runs one statement on this connection. */
111
+ execute(text: string, params?: readonly WireValue[], options?: ExecuteOptions): Promise<ExecuteResult>;
112
+ /** Atomic batch. Inside a transaction this is a savepoint and does not commit the outer one. */
113
+ batch(statements: readonly Statement[], options?: ExecuteOptions): Promise<readonly ExecuteResult[]>;
114
+ /** Returns the connection after `RESET ALL` and `pg_advisory_unlock_all()`. */
115
+ release(): Promise<void>;
116
+ /** Aborts the in-flight statement. Present when `cancel` is set. */
117
+ cancel?(): void;
118
+ };
119
+ /**
120
+ * One endpoint's pool.
121
+ *
122
+ * `reserve`, `stream`, `describe`, `listen`, and `cancel` are present only
123
+ * when the matching capability is set.
124
+ */
125
+ export type DriverPool = {
126
+ /** Declared execution capabilities. */
127
+ readonly capabilities: DriverCapabilities;
128
+ /** Runs one statement on some connection. */
129
+ execute(text: string, params?: readonly WireValue[], options?: ExecuteOptions): Promise<ExecuteResult>;
130
+ /** Atomic batch. All statements commit, or none do. */
131
+ batch(statements: readonly Statement[], options?: ExecuteOptions): Promise<readonly ExecuteResult[]>;
132
+ /** Checks out one connection. Present when `transactions` is `"interactive"`. */
133
+ reserve?(): Promise<DriverConnection>;
134
+ /** Describes a statement without running it. Present when `describe` is set. */
135
+ describe?(text: string, params?: readonly WireValue[]): Promise<DescribeResult>;
136
+ /** Yields row chunks. Present when `stream` is set. */
137
+ stream?(text: string, params?: readonly WireValue[]): AsyncIterable<readonly (readonly WireValue[])[]>;
138
+ /** Listens on a channel. Present when `listen` is set. The returned function stops listening. */
139
+ listen?(channel: string, onNotify: (payload: string) => void): Promise<() => Promise<void>>;
140
+ /** Aborts in-flight statements on this pool. Present when `cancel` is set. */
141
+ cancel?(): void;
142
+ /** Pool counters. */
143
+ stats(): DriverStats;
144
+ /** Closes every connection. */
145
+ close(): Promise<void>;
146
+ };
147
+ /**
148
+ * Pool options shared by adapters.
149
+ *
150
+ * One `open` is one endpoint. The runtime does not share a pool across
151
+ * endpoints.
152
+ */
153
+ export type DriverPoolConfig = {
154
+ /** Connections in the pool. PGlite is always one. */
155
+ readonly max?: number;
156
+ /**
157
+ * Wait for a connection up to `acquire` milliseconds, then fail with
158
+ * OKM1846. Omitted means wait without that deadline.
159
+ */
160
+ readonly timeouts?: {
161
+ readonly acquire?: number;
162
+ };
163
+ };