@sqlbraid/core 0.1.0-rc.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/LICENSE +21 -0
- package/README.md +41 -0
- package/dist/index.d.ts +735 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +475 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
import { StandardSchemaV1, StandardSchemaV1 as StandardSchemaV1$1 } from "@standard-schema/spec";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
export declare const SQL_FRAGMENT: unique symbol;
|
|
4
|
+
declare const boundParameterBrand: unique symbol;
|
|
5
|
+
export interface SourceRange {
|
|
6
|
+
readonly start: number;
|
|
7
|
+
readonly end: number;
|
|
8
|
+
}
|
|
9
|
+
export interface RenderLimits {
|
|
10
|
+
readonly maxSqlBytes?: number;
|
|
11
|
+
readonly maxBindCount?: number;
|
|
12
|
+
readonly maxStructuralItems?: number;
|
|
13
|
+
readonly maxNestingDepth?: number;
|
|
14
|
+
}
|
|
15
|
+
export type QueryResultKind = "rows" | "command" | "call" | "unknown";
|
|
16
|
+
export type NumericSemantics = "exact-integer" | "exact-decimal" | "approximate-binary";
|
|
17
|
+
export type NumericRepresentation = "string" | "number";
|
|
18
|
+
export type TransportFidelity = "lossless" | "guarded" | "lossy" | "unsupported";
|
|
19
|
+
export interface NumericTypeContract {
|
|
20
|
+
readonly semantics: NumericSemantics;
|
|
21
|
+
readonly representation: NumericRepresentation;
|
|
22
|
+
readonly fidelity: TransportFidelity;
|
|
23
|
+
readonly binaryPrecision?: 32 | 64;
|
|
24
|
+
}
|
|
25
|
+
export interface ExactIntegerRange {
|
|
26
|
+
readonly min?: bigint;
|
|
27
|
+
readonly max?: bigint;
|
|
28
|
+
}
|
|
29
|
+
export declare class ResultExactnessError extends Error {
|
|
30
|
+
readonly code = "BRAID_RESULT_EXACTNESS";
|
|
31
|
+
constructor(message?: string);
|
|
32
|
+
}
|
|
33
|
+
export declare function decodeExactInteger(value: unknown, range?: ExactIntegerRange): bigint;
|
|
34
|
+
/**
|
|
35
|
+
* Normalize an exact integer at the raw SQLBraid boundary without changing
|
|
36
|
+
* its textual spelling. This is intentionally not a bigint decoder: callers
|
|
37
|
+
* that need arithmetic may opt in to decodeExactInteger().
|
|
38
|
+
*/
|
|
39
|
+
export declare function normalizeExactInteger(value: unknown): string;
|
|
40
|
+
/**
|
|
41
|
+
* Convert a database-reported count to a safe operational Number. Counts are
|
|
42
|
+
* not application values, so unlike exact SQL numerics they remain numbers,
|
|
43
|
+
* but narrowing an unsafe value is never implicit.
|
|
44
|
+
*/
|
|
45
|
+
export declare function safeDatabaseCount(value: unknown): number;
|
|
46
|
+
export declare function decodeExactDecimal(value: unknown, options?: {
|
|
47
|
+
readonly allowBigInt?: boolean;
|
|
48
|
+
}): string;
|
|
49
|
+
export type RoutineParameterDirection = "in" | "out" | "inout";
|
|
50
|
+
export interface RoutineProcedure {
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly parameterNames: readonly string[];
|
|
53
|
+
}
|
|
54
|
+
export type RoutineSchema = StandardSchemaV1$1<any, any>;
|
|
55
|
+
export interface RoutineContract<Output extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>, Sets extends readonly RoutineSchema[] = readonly RoutineSchema[], ReturnValue = unknown> {
|
|
56
|
+
readonly output?: StandardSchemaV1$1<any, Output>;
|
|
57
|
+
readonly resultSets?: Sets;
|
|
58
|
+
readonly returnValue?: StandardSchemaV1$1<any, ReturnValue>;
|
|
59
|
+
readonly procedure?: RoutineProcedure;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A rendered parameter is always a value. Adapters MUST NOT interpret it as
|
|
63
|
+
* raw SQL, an identifier, a nested query, a driver-specific fragment, or a
|
|
64
|
+
* structural tagged-template command.
|
|
65
|
+
*/
|
|
66
|
+
export interface RenderedParameter {
|
|
67
|
+
readonly value: unknown;
|
|
68
|
+
readonly interpolation?: number;
|
|
69
|
+
readonly hint?: ParameterTypeHint;
|
|
70
|
+
readonly direction?: RoutineParameterDirection;
|
|
71
|
+
readonly outputName?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface RenderedStatement {
|
|
74
|
+
readonly segments: readonly string[];
|
|
75
|
+
readonly parameters: readonly RenderedParameter[];
|
|
76
|
+
readonly dialectId: string;
|
|
77
|
+
readonly resultKind: QueryResultKind;
|
|
78
|
+
readonly routineProcedure?: RoutineProcedure;
|
|
79
|
+
readonly fingerprint?: string;
|
|
80
|
+
readonly variantFingerprint?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface ParameterTypeHint<Input = unknown> {
|
|
83
|
+
readonly databaseType: string;
|
|
84
|
+
readonly length?: number | "max";
|
|
85
|
+
readonly precision?: number;
|
|
86
|
+
readonly scale?: number;
|
|
87
|
+
readonly __input?: Input;
|
|
88
|
+
}
|
|
89
|
+
export interface BoundParameter<Input = unknown> {
|
|
90
|
+
readonly value: Input;
|
|
91
|
+
readonly hint: ParameterTypeHint<Input>;
|
|
92
|
+
readonly [boundParameterBrand]: true;
|
|
93
|
+
}
|
|
94
|
+
export interface RoutineParameter<Input = unknown> {
|
|
95
|
+
readonly value: Input;
|
|
96
|
+
readonly hint?: ParameterTypeHint;
|
|
97
|
+
readonly direction: Exclude<RoutineParameterDirection, "in">;
|
|
98
|
+
readonly outputName: string;
|
|
99
|
+
}
|
|
100
|
+
export declare function createParameterTypeHint<Input = unknown>(hint: ParameterTypeHint<Input>): ParameterTypeHint<Input>;
|
|
101
|
+
export declare function createBoundParameter<Input>(value: NoInfer<Input>, hint: ParameterTypeHint<Input>): BoundParameter<Input>;
|
|
102
|
+
export declare function isBoundParameter(value: unknown): value is BoundParameter;
|
|
103
|
+
export declare function createRoutineOutParameter(name: string, hint?: ParameterTypeHint): RoutineParameter<null>;
|
|
104
|
+
export declare function createRoutineInOutParameter<Input>(name: string, value: NoInfer<Input>, hint?: ParameterTypeHint<Input>): RoutineParameter<Input>;
|
|
105
|
+
export declare function isRoutineParameter(value: unknown): value is RoutineParameter;
|
|
106
|
+
export type ParameterTransportKind = "native-value-template" | "text-positional" | "text-named" | "typed-request";
|
|
107
|
+
export type RequestedReuse = "auto" | "simple" | "reuse";
|
|
108
|
+
export type EffectiveReuse = "simple" | "reuse";
|
|
109
|
+
export type ReuseOwner = "sqlbraid" | "driver" | "server";
|
|
110
|
+
export interface StatementBindingContext {
|
|
111
|
+
readonly dialectId: string;
|
|
112
|
+
readonly requestedReuse: RequestedReuse;
|
|
113
|
+
readonly preparedName?: string;
|
|
114
|
+
readonly transactionScoped?: boolean;
|
|
115
|
+
}
|
|
116
|
+
export interface BindingDescription {
|
|
117
|
+
readonly index: number;
|
|
118
|
+
readonly name?: string;
|
|
119
|
+
readonly interpolation?: number;
|
|
120
|
+
readonly hint?: ParameterTypeHint;
|
|
121
|
+
readonly direction?: RoutineParameterDirection;
|
|
122
|
+
readonly outputName?: string;
|
|
123
|
+
}
|
|
124
|
+
export interface LiteralizeOptions {
|
|
125
|
+
readonly values?: "inline" | "redacted";
|
|
126
|
+
readonly maxValueLength?: number;
|
|
127
|
+
readonly binary?: "summary" | "full";
|
|
128
|
+
readonly redact?: (parameter: RenderedParameter, index: number) => boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface LiteralizedSqlResult {
|
|
131
|
+
readonly text: string;
|
|
132
|
+
/**
|
|
133
|
+
* True when no diagnostic parameter representation was truncated. Redaction,
|
|
134
|
+
* unsupported literal markers, and divergence from wire SQL do not make it
|
|
135
|
+
* incomplete.
|
|
136
|
+
*/
|
|
137
|
+
readonly complete: boolean;
|
|
138
|
+
readonly redactedParameters: number;
|
|
139
|
+
readonly truncatedParameters: number;
|
|
140
|
+
}
|
|
141
|
+
export interface StatementBindingDescription {
|
|
142
|
+
readonly adapterId: string;
|
|
143
|
+
readonly dialectId: string;
|
|
144
|
+
readonly transport: ParameterTransportKind;
|
|
145
|
+
readonly parameterizedSql?: string;
|
|
146
|
+
readonly bindings: readonly BindingDescription[];
|
|
147
|
+
readonly reuse: {
|
|
148
|
+
readonly requested: RequestedReuse;
|
|
149
|
+
readonly effective: EffectiveReuse;
|
|
150
|
+
readonly owner: ReuseOwner;
|
|
151
|
+
readonly capacity?: number;
|
|
152
|
+
};
|
|
153
|
+
/** Diagnostic reconstruction only; never use this text as execution input. */
|
|
154
|
+
readonly literalizedSql: (options?: LiteralizeOptions) => LiteralizedSqlResult;
|
|
155
|
+
}
|
|
156
|
+
export interface StatementBindingAdapter {
|
|
157
|
+
readonly id: string;
|
|
158
|
+
describe(statement: RenderedStatement, context: StatementBindingContext): StatementBindingDescription;
|
|
159
|
+
describeBulk?(bulk: RenderedBulk, context: StatementBindingContext): BulkBindingDescription;
|
|
160
|
+
}
|
|
161
|
+
export interface StatementBindingDescriptionOptions {
|
|
162
|
+
readonly adapterId: string;
|
|
163
|
+
readonly transport: ParameterTransportKind;
|
|
164
|
+
readonly placeholder?: (index: number) => string;
|
|
165
|
+
readonly reuse: {
|
|
166
|
+
readonly effective: EffectiveReuse;
|
|
167
|
+
readonly owner: ReuseOwner;
|
|
168
|
+
readonly capacity?: number;
|
|
169
|
+
};
|
|
170
|
+
readonly formatLiteral?: (parameter: RenderedParameter, index: number, options: LiteralizeOptions) => string | undefined;
|
|
171
|
+
}
|
|
172
|
+
export interface RenderedBulk {
|
|
173
|
+
readonly statement: RenderedStatement;
|
|
174
|
+
readonly parameterSets: readonly (readonly unknown[])[];
|
|
175
|
+
}
|
|
176
|
+
export interface BulkBindingDescription {
|
|
177
|
+
readonly adapterId: string;
|
|
178
|
+
readonly dialectId: string;
|
|
179
|
+
readonly transport: ParameterTransportKind;
|
|
180
|
+
readonly parameterizedSql?: string;
|
|
181
|
+
readonly bindings: readonly BindingDescription[];
|
|
182
|
+
readonly itemCount: number;
|
|
183
|
+
valuesAt(index: number): readonly unknown[];
|
|
184
|
+
literalizedSql(index: number, options?: LiteralizeOptions): LiteralizedSqlResult;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Normalize and snapshot a homogeneous bulk's logical statement and value
|
|
188
|
+
* matrix. Values themselves are application-owned and are not cloned.
|
|
189
|
+
*/
|
|
190
|
+
export declare function createRenderedBulk(bulk: RenderedBulk): RenderedBulk;
|
|
191
|
+
export declare function createRenderedStatement(statement: {
|
|
192
|
+
readonly segments: readonly string[];
|
|
193
|
+
readonly parameters: readonly RenderedParameter[];
|
|
194
|
+
readonly resultKind: QueryResultKind;
|
|
195
|
+
readonly routineProcedure?: RoutineProcedure;
|
|
196
|
+
readonly dialectId: string;
|
|
197
|
+
readonly fingerprint?: string;
|
|
198
|
+
readonly variantFingerprint?: string;
|
|
199
|
+
}): RenderedStatement;
|
|
200
|
+
export declare function parameterizedSql(statement: RenderedStatement, placeholder: (index: number) => string): string;
|
|
201
|
+
export declare function createStatementBindingDescription(statement: RenderedStatement, context: StatementBindingContext, options: StatementBindingDescriptionOptions): StatementBindingDescription;
|
|
202
|
+
/**
|
|
203
|
+
* Build one binding description for a logical bulk statement. The statement
|
|
204
|
+
* metadata is shared by every parameter set; values and diagnostics are
|
|
205
|
+
* addressed only when requested for a particular item.
|
|
206
|
+
*/
|
|
207
|
+
export declare function createBulkBindingDescription(bulk: RenderedBulk, context: StatementBindingContext, options: StatementBindingDescriptionOptions): BulkBindingDescription;
|
|
208
|
+
export interface DialectLexicalProfile {
|
|
209
|
+
readonly lineCommentPrefixes: readonly string[];
|
|
210
|
+
readonly supportsNestedBlockComments?: boolean;
|
|
211
|
+
readonly supportsDollarQuotes?: boolean;
|
|
212
|
+
readonly supportsBacktickIdentifiers?: boolean;
|
|
213
|
+
readonly supportsBracketIdentifiers?: boolean;
|
|
214
|
+
readonly supportsOracleQQuotes?: boolean;
|
|
215
|
+
readonly backslashEscapes?: boolean;
|
|
216
|
+
}
|
|
217
|
+
export interface Dialect {
|
|
218
|
+
readonly id: string;
|
|
219
|
+
quoteIdentifier(identifier: string): string;
|
|
220
|
+
readonly lexicalProfile?: DialectLexicalProfile;
|
|
221
|
+
}
|
|
222
|
+
export interface TypeMapping {
|
|
223
|
+
readonly databaseType: string;
|
|
224
|
+
readonly inputType: string;
|
|
225
|
+
readonly outputType: string;
|
|
226
|
+
readonly nullable: boolean;
|
|
227
|
+
readonly numeric?: NumericTypeContract;
|
|
228
|
+
}
|
|
229
|
+
export interface TypePolicy {
|
|
230
|
+
readonly id: string;
|
|
231
|
+
readonly hash: string;
|
|
232
|
+
readonly mappings: readonly TypeMapping[];
|
|
233
|
+
decode(databaseType: string, value: unknown): unknown;
|
|
234
|
+
encode(databaseType: string, value: unknown): unknown;
|
|
235
|
+
}
|
|
236
|
+
export interface TextNode {
|
|
237
|
+
readonly kind: "text";
|
|
238
|
+
readonly text: string;
|
|
239
|
+
readonly range: SourceRange;
|
|
240
|
+
}
|
|
241
|
+
export interface BindNode {
|
|
242
|
+
readonly kind: "bind";
|
|
243
|
+
readonly interpolation: number;
|
|
244
|
+
readonly range: SourceRange;
|
|
245
|
+
}
|
|
246
|
+
export interface FragmentNode {
|
|
247
|
+
readonly kind: "fragment";
|
|
248
|
+
readonly fragment: SqlFragment;
|
|
249
|
+
readonly range: SourceRange;
|
|
250
|
+
}
|
|
251
|
+
export interface IdentifierNode {
|
|
252
|
+
readonly kind: "identifier";
|
|
253
|
+
readonly value: string | readonly string[];
|
|
254
|
+
readonly range: SourceRange;
|
|
255
|
+
}
|
|
256
|
+
export interface RawNode {
|
|
257
|
+
readonly kind: "raw";
|
|
258
|
+
readonly text: string;
|
|
259
|
+
readonly range: SourceRange;
|
|
260
|
+
}
|
|
261
|
+
export interface ListNode {
|
|
262
|
+
readonly kind: "list";
|
|
263
|
+
readonly values: readonly unknown[];
|
|
264
|
+
readonly range: SourceRange;
|
|
265
|
+
}
|
|
266
|
+
export interface IfNode {
|
|
267
|
+
readonly kind: "if";
|
|
268
|
+
readonly condition: number;
|
|
269
|
+
readonly children: readonly TemplateNode[];
|
|
270
|
+
readonly range: SourceRange;
|
|
271
|
+
}
|
|
272
|
+
export interface ChooseWhen {
|
|
273
|
+
readonly condition: number;
|
|
274
|
+
readonly children: readonly TemplateNode[];
|
|
275
|
+
readonly range: SourceRange;
|
|
276
|
+
}
|
|
277
|
+
export interface ChooseNode {
|
|
278
|
+
readonly kind: "choose";
|
|
279
|
+
readonly whens: readonly ChooseWhen[];
|
|
280
|
+
readonly otherwise?: readonly TemplateNode[];
|
|
281
|
+
readonly range: SourceRange;
|
|
282
|
+
}
|
|
283
|
+
export interface TrimAttributes {
|
|
284
|
+
readonly prefix: string;
|
|
285
|
+
readonly prefixOverrides: readonly string[];
|
|
286
|
+
readonly suffix: string;
|
|
287
|
+
readonly suffixOverrides: readonly string[];
|
|
288
|
+
}
|
|
289
|
+
export interface TrimNode {
|
|
290
|
+
readonly kind: "trim";
|
|
291
|
+
readonly attributes: TrimAttributes;
|
|
292
|
+
readonly children: readonly TemplateNode[];
|
|
293
|
+
readonly range: SourceRange;
|
|
294
|
+
}
|
|
295
|
+
export type TemplateNode = TextNode | BindNode | FragmentNode | IdentifierNode | RawNode | ListNode | IfNode | ChooseNode | TrimNode;
|
|
296
|
+
export interface TemplateIr {
|
|
297
|
+
readonly version: 1;
|
|
298
|
+
readonly nodes: readonly TemplateNode[];
|
|
299
|
+
readonly sourceLength: number;
|
|
300
|
+
}
|
|
301
|
+
export interface SqlFragment {
|
|
302
|
+
readonly [SQL_FRAGMENT]: true;
|
|
303
|
+
readonly ir: TemplateIr;
|
|
304
|
+
readonly values: readonly unknown[];
|
|
305
|
+
readonly dialectId: string;
|
|
306
|
+
}
|
|
307
|
+
export interface Query<Row = unknown, Kind extends QueryResultKind = "unknown"> {
|
|
308
|
+
readonly ir: TemplateIr;
|
|
309
|
+
readonly values: readonly unknown[];
|
|
310
|
+
readonly resultKind: Kind;
|
|
311
|
+
/**
|
|
312
|
+
* Application result mapper. Never forwarded to a DB driver.
|
|
313
|
+
*/
|
|
314
|
+
readonly resultSchema?: StandardSchemaV1$1<unknown, Row>;
|
|
315
|
+
readonly routineContract?: RoutineContract;
|
|
316
|
+
render(): RenderedStatement;
|
|
317
|
+
readonly __row?: Row;
|
|
318
|
+
}
|
|
319
|
+
export type RowQuery<Row = unknown> = Query<Row, "rows">;
|
|
320
|
+
export type CommandQuery = Query<CommandResult, "command">;
|
|
321
|
+
export type CallQuery<Result extends RoutineCallResult = RoutineCallResult> = Query<Result, "call">;
|
|
322
|
+
export interface CommandResult {
|
|
323
|
+
readonly affectedRows?: number;
|
|
324
|
+
readonly insertId?: string;
|
|
325
|
+
readonly [key: string]: unknown;
|
|
326
|
+
}
|
|
327
|
+
export interface RowsExecutionResult<Row = unknown> {
|
|
328
|
+
readonly kind: "rows";
|
|
329
|
+
readonly rows: readonly Row[];
|
|
330
|
+
readonly rowCount?: number;
|
|
331
|
+
readonly command?: never;
|
|
332
|
+
}
|
|
333
|
+
export interface CommandExecutionResult {
|
|
334
|
+
readonly kind: "command";
|
|
335
|
+
readonly rows: readonly [];
|
|
336
|
+
readonly rowCount?: number;
|
|
337
|
+
readonly command: CommandResult;
|
|
338
|
+
}
|
|
339
|
+
export type QueryExecutionResult<Row = unknown> = RowsExecutionResult<Row> | CommandExecutionResult;
|
|
340
|
+
export interface ExecutionOptions {
|
|
341
|
+
readonly signal?: AbortSignal;
|
|
342
|
+
}
|
|
343
|
+
export interface RowValidationOptions<Row> extends ExecutionOptions {
|
|
344
|
+
readonly schema?: StandardSchemaV1$1<unknown, NoInfer<Row>>;
|
|
345
|
+
}
|
|
346
|
+
export interface StreamOptions<Row> extends RowValidationOptions<Row> {}
|
|
347
|
+
export type TransactionIsolation = "read-uncommitted" | "read-committed" | "repeatable-read" | "serializable";
|
|
348
|
+
export interface TransactionOptions {
|
|
349
|
+
readonly isolation?: TransactionIsolation;
|
|
350
|
+
readonly readOnly?: boolean;
|
|
351
|
+
}
|
|
352
|
+
export declare class UnsupportedFeatureError extends Error {
|
|
353
|
+
readonly feature: string;
|
|
354
|
+
readonly code: `BRAID_${string}`;
|
|
355
|
+
constructor(feature: string, code: `BRAID_${string}`, message: string, options?: ErrorOptions);
|
|
356
|
+
}
|
|
357
|
+
export interface RoutineResultSet<Row = unknown> {
|
|
358
|
+
readonly rows: readonly Row[];
|
|
359
|
+
}
|
|
360
|
+
export type RoutineResultSetTuple<Sets extends readonly unknown[]> = { readonly [K in keyof Sets]: RoutineResultSet<Sets[K]>; };
|
|
361
|
+
export interface RoutineCallResult<Output extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>, Sets extends readonly unknown[] = readonly unknown[], ReturnValue = unknown> {
|
|
362
|
+
readonly output: Output;
|
|
363
|
+
readonly resultSets: RoutineResultSetTuple<Sets>;
|
|
364
|
+
readonly returnValue?: ReturnValue;
|
|
365
|
+
}
|
|
366
|
+
export type RoutineSchemaOutput<Schema> = Schema extends StandardSchemaV1$1<any, infer Output> ? Output : never;
|
|
367
|
+
type RoutineRowsFromSchemas<Schemas extends readonly RoutineSchema[]> = { readonly [K in keyof Schemas]: RoutineSchemaOutput<Schemas[K]>; };
|
|
368
|
+
export type RoutineResultFromContract<Contract extends RoutineContract> = RoutineCallResult<Contract["output"] extends RoutineSchema ? RoutineSchemaOutput<Contract["output"]> extends Readonly<Record<string, unknown>> ? RoutineSchemaOutput<Contract["output"]> : Readonly<Record<string, unknown>> : Readonly<Record<string, unknown>>, Contract["resultSets"] extends (infer Schemas extends readonly RoutineSchema[]) ? RoutineRowsFromSchemas<Schemas> : readonly unknown[], Contract["returnValue"] extends RoutineSchema ? RoutineSchemaOutput<Contract["returnValue"]> : unknown> & (Contract extends {
|
|
369
|
+
readonly returnValue: RoutineSchema;
|
|
370
|
+
} ? {
|
|
371
|
+
readonly returnValue: RoutineSchemaOutput<Contract["returnValue"]>;
|
|
372
|
+
} : {});
|
|
373
|
+
export type RoutineResultSource = {
|
|
374
|
+
readonly kind: "out-cursor";
|
|
375
|
+
readonly name?: string;
|
|
376
|
+
readonly parameterIndex?: number;
|
|
377
|
+
} | {
|
|
378
|
+
readonly kind: "implicit";
|
|
379
|
+
readonly index: number;
|
|
380
|
+
} | {
|
|
381
|
+
readonly kind: "emitted";
|
|
382
|
+
readonly index: number;
|
|
383
|
+
};
|
|
384
|
+
export interface DriverRoutineResultSet {
|
|
385
|
+
readonly rows: readonly unknown[];
|
|
386
|
+
readonly source: RoutineResultSource;
|
|
387
|
+
}
|
|
388
|
+
export interface DriverRoutineResult {
|
|
389
|
+
readonly output: Readonly<Record<string, unknown>>;
|
|
390
|
+
readonly returnValue?: unknown;
|
|
391
|
+
readonly resultSets: readonly DriverRoutineResultSet[];
|
|
392
|
+
}
|
|
393
|
+
export type RoutineMappingLocation = {
|
|
394
|
+
readonly kind: "output";
|
|
395
|
+
} | {
|
|
396
|
+
readonly kind: "return-value";
|
|
397
|
+
} | {
|
|
398
|
+
readonly kind: "result-set";
|
|
399
|
+
readonly resultSetIndex: number;
|
|
400
|
+
readonly rowIndex: number;
|
|
401
|
+
};
|
|
402
|
+
export type DriverCapabilityErrorCode = "BRAID_STREAM_UNSUPPORTED" | "BRAID_CALL_UNSUPPORTED" | "BRAID_CALL_RESULT_SETS" | "BRAID_CALL_CURSOR_TX_REQUIRED" | "BRAID_CALL_OUT_UNSUPPORTED" | "BRAID_CALL_RETURN_UNSUPPORTED" | "BRAID_CALL_CURSOR_UNSUPPORTED" | "BRAID_RESOURCE_CLEANUP";
|
|
403
|
+
export declare class RoutineMappingError extends Error {
|
|
404
|
+
readonly code = "BRAID_CALL_MAP";
|
|
405
|
+
readonly location: RoutineMappingLocation;
|
|
406
|
+
constructor(message: string, location: RoutineMappingLocation, options?: {
|
|
407
|
+
readonly cause?: unknown;
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
export type BulkExecutionMode = "native-bulk" | "pipeline" | "prepared-loop" | "remote-batch";
|
|
411
|
+
export interface BulkExecutionResult {
|
|
412
|
+
readonly inputCount: number;
|
|
413
|
+
readonly affectedRows?: number;
|
|
414
|
+
readonly executionMode: BulkExecutionMode;
|
|
415
|
+
}
|
|
416
|
+
export interface QueryExecutor {
|
|
417
|
+
/** Stable identity for the physical execution resource shared by wrappers; pools must use a leased resource. */
|
|
418
|
+
readonly ownershipKey?: object;
|
|
419
|
+
readonly statementBinding: StatementBindingAdapter;
|
|
420
|
+
readonly environment?: DriverEnvironment;
|
|
421
|
+
query<Row>(rendered: RenderedStatement, binding?: StatementBindingDescription, options?: ExecutionOptions): Promise<QueryExecutionResult<Row>>;
|
|
422
|
+
stream<Row>(rendered: RenderedStatement, binding?: StatementBindingDescription, options?: ExecutionOptions): AsyncIterable<Row>;
|
|
423
|
+
call(rendered: RenderedStatement, binding?: StatementBindingDescription, options?: ExecutionOptions): Promise<DriverRoutineResult>;
|
|
424
|
+
bulk?(bulk: RenderedBulk, binding: BulkBindingDescription, options?: ExecutionOptions): Promise<BulkExecutionResult>;
|
|
425
|
+
begin?(options?: TransactionOptions): Promise<void>;
|
|
426
|
+
commit?(): Promise<void>;
|
|
427
|
+
rollback?(): Promise<void>;
|
|
428
|
+
savepoint?(name: string): Promise<void>;
|
|
429
|
+
rollbackTo?(name: string): Promise<void>;
|
|
430
|
+
releaseSavepoint?(name: string): Promise<void>;
|
|
431
|
+
}
|
|
432
|
+
export interface ConnectionLease extends QueryExecutor {
|
|
433
|
+
release(options?: {
|
|
434
|
+
readonly discard?: boolean;
|
|
435
|
+
}): void | Promise<void>;
|
|
436
|
+
}
|
|
437
|
+
export interface ConnectionProvider {
|
|
438
|
+
readonly statementBinding: StatementBindingAdapter;
|
|
439
|
+
readonly environment?: DriverEnvironment;
|
|
440
|
+
acquire(): Promise<ConnectionLease>;
|
|
441
|
+
}
|
|
442
|
+
export interface QueryExecutionPlan {
|
|
443
|
+
readonly adapterId: string;
|
|
444
|
+
readonly dialectId: string;
|
|
445
|
+
readonly transport: ParameterTransportKind;
|
|
446
|
+
readonly reuse: StatementBindingDescription["reuse"];
|
|
447
|
+
}
|
|
448
|
+
export interface QueryReadyEvent {
|
|
449
|
+
readonly type: "query:ready";
|
|
450
|
+
readonly purpose?: "environment";
|
|
451
|
+
readonly operationId: string;
|
|
452
|
+
readonly batchId?: string;
|
|
453
|
+
readonly sql?: string;
|
|
454
|
+
readonly values: readonly unknown[];
|
|
455
|
+
readonly bindingMap?: readonly {
|
|
456
|
+
readonly placeholder: number;
|
|
457
|
+
readonly interpolation?: number;
|
|
458
|
+
readonly direction?: RoutineParameterDirection;
|
|
459
|
+
readonly outputName?: string;
|
|
460
|
+
}[];
|
|
461
|
+
readonly parameterHints?: readonly (ParameterTypeHint | undefined)[];
|
|
462
|
+
readonly execution: QueryExecutionPlan;
|
|
463
|
+
readonly literalizedSql: (options?: LiteralizeOptions) => LiteralizedSqlResult;
|
|
464
|
+
readonly declaredKind: QueryResultKind;
|
|
465
|
+
readonly fingerprint?: string;
|
|
466
|
+
readonly variantFingerprint?: string;
|
|
467
|
+
readonly preparedName?: string;
|
|
468
|
+
readonly transactionDepth: number;
|
|
469
|
+
readonly transactionScoped: boolean;
|
|
470
|
+
}
|
|
471
|
+
export interface QueryResultEvent {
|
|
472
|
+
readonly type: "query:result";
|
|
473
|
+
readonly purpose?: "environment";
|
|
474
|
+
readonly operationId: string;
|
|
475
|
+
readonly preparedName?: string;
|
|
476
|
+
readonly batchId?: string;
|
|
477
|
+
readonly durationMs: number;
|
|
478
|
+
readonly actualKind: "rows" | "command" | "call";
|
|
479
|
+
readonly rowCount?: number;
|
|
480
|
+
readonly resultSetCount?: number;
|
|
481
|
+
readonly outputKeys?: readonly string[];
|
|
482
|
+
readonly hasReturnValue?: boolean;
|
|
483
|
+
readonly command?: Readonly<Record<string, unknown>>;
|
|
484
|
+
readonly transactionDepth: number;
|
|
485
|
+
readonly transactionScoped: boolean;
|
|
486
|
+
}
|
|
487
|
+
export interface QueryMappedEvent {
|
|
488
|
+
readonly type: "query:mapped";
|
|
489
|
+
readonly purpose?: "environment";
|
|
490
|
+
readonly operationId: string;
|
|
491
|
+
readonly preparedName?: string;
|
|
492
|
+
readonly batchId?: string;
|
|
493
|
+
readonly durationMs: number;
|
|
494
|
+
readonly rowCount: number;
|
|
495
|
+
readonly queryMapped: boolean;
|
|
496
|
+
readonly executionMapped: boolean;
|
|
497
|
+
readonly transactionDepth: number;
|
|
498
|
+
readonly transactionScoped: boolean;
|
|
499
|
+
}
|
|
500
|
+
export interface BulkReadyEvent {
|
|
501
|
+
readonly type: "bulk:ready";
|
|
502
|
+
readonly operationId: string;
|
|
503
|
+
readonly itemCount: number;
|
|
504
|
+
readonly transactionDepth: number;
|
|
505
|
+
readonly transactionScoped: boolean;
|
|
506
|
+
readonly sql?: string;
|
|
507
|
+
readonly valuesAt: (index: number) => readonly unknown[];
|
|
508
|
+
readonly literalizedSql: (index: number, options?: LiteralizeOptions) => LiteralizedSqlResult;
|
|
509
|
+
}
|
|
510
|
+
export interface BulkResultEvent {
|
|
511
|
+
readonly type: "bulk:result";
|
|
512
|
+
readonly operationId: string;
|
|
513
|
+
readonly itemCount: number;
|
|
514
|
+
readonly affectedRows?: number;
|
|
515
|
+
readonly executionMode: BulkExecutionMode;
|
|
516
|
+
readonly durationMs: number;
|
|
517
|
+
readonly transactionDepth: number;
|
|
518
|
+
readonly transactionScoped: boolean;
|
|
519
|
+
}
|
|
520
|
+
export type QueryErrorStage = "render" | "prepared" | "observer-before" | "materialize" | "acquire" | "driver" | "result-kind" | "cardinality" | "query-map" | "execution-map" | "observer-after" | "release" | "stream" | "transaction";
|
|
521
|
+
export interface QueryErrorEvent {
|
|
522
|
+
readonly type: "query:error";
|
|
523
|
+
readonly purpose?: "environment";
|
|
524
|
+
readonly operationId: string;
|
|
525
|
+
readonly preparedName?: string;
|
|
526
|
+
readonly batchId?: string;
|
|
527
|
+
readonly error: unknown;
|
|
528
|
+
readonly stage: QueryErrorStage;
|
|
529
|
+
readonly executionStarted: boolean;
|
|
530
|
+
readonly executionCompleted: boolean;
|
|
531
|
+
readonly durationMs?: number;
|
|
532
|
+
readonly transactionDepth: number;
|
|
533
|
+
readonly transactionScoped: boolean;
|
|
534
|
+
}
|
|
535
|
+
export interface StreamStartEvent {
|
|
536
|
+
readonly type: "stream:start";
|
|
537
|
+
readonly operationId: string;
|
|
538
|
+
readonly sql?: string;
|
|
539
|
+
readonly values: readonly unknown[];
|
|
540
|
+
readonly bindingMap?: readonly {
|
|
541
|
+
readonly placeholder: number;
|
|
542
|
+
readonly interpolation?: number;
|
|
543
|
+
readonly direction?: RoutineParameterDirection;
|
|
544
|
+
readonly outputName?: string;
|
|
545
|
+
}[];
|
|
546
|
+
readonly parameterHints?: readonly (ParameterTypeHint | undefined)[];
|
|
547
|
+
readonly execution: QueryExecutionPlan;
|
|
548
|
+
readonly literalizedSql: (options?: LiteralizeOptions) => LiteralizedSqlResult;
|
|
549
|
+
readonly declaredKind: "rows";
|
|
550
|
+
readonly variantFingerprint?: string;
|
|
551
|
+
readonly preparedName?: string;
|
|
552
|
+
readonly transactionDepth: number;
|
|
553
|
+
readonly transactionScoped: boolean;
|
|
554
|
+
}
|
|
555
|
+
export interface StreamEndEvent {
|
|
556
|
+
readonly type: "stream:end";
|
|
557
|
+
readonly operationId: string;
|
|
558
|
+
readonly status: "completed" | "error";
|
|
559
|
+
readonly durationMs: number;
|
|
560
|
+
readonly rowCount: number;
|
|
561
|
+
readonly error?: unknown;
|
|
562
|
+
readonly transactionDepth: number;
|
|
563
|
+
readonly transactionScoped: boolean;
|
|
564
|
+
}
|
|
565
|
+
export type TransactionEventPhase = "begin" | "commit" | "rollback" | "savepoint" | "rollback-to-savepoint" | "release-savepoint";
|
|
566
|
+
export interface TransactionEvent {
|
|
567
|
+
readonly type: "transaction";
|
|
568
|
+
readonly transactionId: string;
|
|
569
|
+
readonly phase: TransactionEventPhase;
|
|
570
|
+
readonly status: "requested" | "completed" | "failed";
|
|
571
|
+
readonly depth: number;
|
|
572
|
+
readonly savepointName?: string;
|
|
573
|
+
readonly durationMs?: number;
|
|
574
|
+
readonly error?: unknown;
|
|
575
|
+
}
|
|
576
|
+
export type ExecutionEvent = QueryReadyEvent | QueryResultEvent | QueryMappedEvent | BulkReadyEvent | BulkResultEvent | QueryErrorEvent | StreamStartEvent | StreamEndEvent | TransactionEvent;
|
|
577
|
+
export interface ExecutionObserver {
|
|
578
|
+
onEvent(event: ExecutionEvent): void | Promise<void>;
|
|
579
|
+
}
|
|
580
|
+
export interface EnvironmentCapability {
|
|
581
|
+
readonly status: "guaranteed" | "guarded" | "unsupported";
|
|
582
|
+
readonly canonical?: "string" | "number" | "Uint8Array";
|
|
583
|
+
readonly rawRepresentations?: readonly string[];
|
|
584
|
+
readonly conditionCode?: string;
|
|
585
|
+
}
|
|
586
|
+
export interface DatabaseEnvironment {
|
|
587
|
+
readonly database: {
|
|
588
|
+
readonly product: string;
|
|
589
|
+
readonly version?: string;
|
|
590
|
+
readonly edition?: string;
|
|
591
|
+
};
|
|
592
|
+
readonly driver: {
|
|
593
|
+
readonly id: string;
|
|
594
|
+
readonly version?: string;
|
|
595
|
+
readonly profile?: string;
|
|
596
|
+
};
|
|
597
|
+
readonly runtime: {
|
|
598
|
+
readonly id: string;
|
|
599
|
+
readonly version?: string;
|
|
600
|
+
};
|
|
601
|
+
readonly typePolicy?: {
|
|
602
|
+
readonly id: string;
|
|
603
|
+
readonly hash: string;
|
|
604
|
+
};
|
|
605
|
+
readonly capabilities: Readonly<Record<string, EnvironmentCapability>>;
|
|
606
|
+
readonly supportMatch: {
|
|
607
|
+
readonly status: "official" | "conditional" | "compatible";
|
|
608
|
+
readonly targetId?: string;
|
|
609
|
+
readonly reason?: string;
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
/** Adapter evidence only. Probes run through the ordinary observed, leased query path. */
|
|
613
|
+
export interface DriverEnvironment {
|
|
614
|
+
readonly database: DatabaseEnvironment["database"];
|
|
615
|
+
readonly driver: DatabaseEnvironment["driver"];
|
|
616
|
+
readonly typePolicy?: {
|
|
617
|
+
readonly id: string;
|
|
618
|
+
readonly hash: string;
|
|
619
|
+
};
|
|
620
|
+
readonly capabilities: DatabaseEnvironment["capabilities"];
|
|
621
|
+
readonly probe?: {
|
|
622
|
+
readonly statement: RenderedStatement;
|
|
623
|
+
readonly read: (rows: readonly unknown[]) => {
|
|
624
|
+
readonly version?: string;
|
|
625
|
+
readonly edition?: string;
|
|
626
|
+
readonly capabilities?: Readonly<Record<string, EnvironmentCapability>>;
|
|
627
|
+
};
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
/** Structural subset of a support manifest; importing support tooling is unnecessary. */
|
|
631
|
+
export interface EnvironmentSupportTarget {
|
|
632
|
+
readonly id: string;
|
|
633
|
+
readonly status: string;
|
|
634
|
+
readonly database: {
|
|
635
|
+
readonly product: string;
|
|
636
|
+
readonly version: string;
|
|
637
|
+
readonly edition: string;
|
|
638
|
+
};
|
|
639
|
+
readonly driver: {
|
|
640
|
+
readonly id: string;
|
|
641
|
+
readonly version: string;
|
|
642
|
+
readonly profile: string;
|
|
643
|
+
};
|
|
644
|
+
readonly runtime: {
|
|
645
|
+
readonly id: string;
|
|
646
|
+
readonly version: string;
|
|
647
|
+
};
|
|
648
|
+
readonly typePolicy: {
|
|
649
|
+
readonly id: string;
|
|
650
|
+
readonly hash: string;
|
|
651
|
+
};
|
|
652
|
+
readonly evidence: {
|
|
653
|
+
readonly status: string;
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
export interface EnvironmentOptions {
|
|
657
|
+
readonly targets?: readonly EnvironmentSupportTarget[];
|
|
658
|
+
/** Re-probe the current lease instead of returning the cached observation. */
|
|
659
|
+
readonly refresh?: boolean;
|
|
660
|
+
}
|
|
661
|
+
export interface DatabaseOptions {
|
|
662
|
+
readonly observers?: readonly ExecutionObserver[];
|
|
663
|
+
readonly reuse?: RequestedReuse;
|
|
664
|
+
}
|
|
665
|
+
export type PreparableQuery = ExecutableQuery | CallQuery;
|
|
666
|
+
export type PreparedArguments<Input, Options> = [Input] extends [never] ? [options?: Options] : [input: Input, options?: Options];
|
|
667
|
+
export type PreparedQuery<Input, Q extends PreparableQuery> = {
|
|
668
|
+
readonly name: string;
|
|
669
|
+
} & (Q extends CallQuery<infer Result> ? {
|
|
670
|
+
call(...args: PreparedArguments<Input, ExecutionOptions>): Promise<Result>;
|
|
671
|
+
} : {
|
|
672
|
+
execute(...args: PreparedArguments<Input, ExecutionOptions>): Promise<ExecutionResultOf<Q>>;
|
|
673
|
+
} & (Q extends RowQuery<infer Row> ? {
|
|
674
|
+
all(...args: PreparedArguments<Input, RowValidationOptions<Row>>): Promise<readonly Row[]>;
|
|
675
|
+
one(...args: PreparedArguments<Input, RowValidationOptions<Row>>): Promise<Row>;
|
|
676
|
+
maybeOne(...args: PreparedArguments<Input, RowValidationOptions<Row>>): Promise<Row | undefined>;
|
|
677
|
+
stream(...args: PreparedArguments<Input, StreamOptions<Row>>): AsyncIterable<Row>;
|
|
678
|
+
} : {}));
|
|
679
|
+
export type ExecutableQuery = RowQuery<unknown> | Query<unknown, "command"> | Query<unknown, "unknown">;
|
|
680
|
+
export type ExecutionResultOf<Q> = Q extends RowQuery<infer Row> ? RowsExecutionResult<Row> : Q extends Query<unknown, "command"> ? CommandExecutionResult : Q extends Query<infer Row, "unknown"> ? QueryExecutionResult<Row> : never;
|
|
681
|
+
export interface Database {
|
|
682
|
+
environment(options?: EnvironmentOptions): Promise<DatabaseEnvironment>;
|
|
683
|
+
all<Row>(query: RowQuery<Row>, options?: RowValidationOptions<Row>): Promise<readonly Row[]>;
|
|
684
|
+
one<Row>(query: RowQuery<Row>, options?: RowValidationOptions<Row>): Promise<Row>;
|
|
685
|
+
maybeOne<Row>(query: RowQuery<Row>, options?: RowValidationOptions<Row>): Promise<Row | undefined>;
|
|
686
|
+
execute<Q extends ExecutableQuery>(query: Q, options?: ExecutionOptions): Promise<ExecutionResultOf<Q>>;
|
|
687
|
+
call<Result extends RoutineCallResult>(query: CallQuery<Result>, options?: ExecutionOptions): Promise<Result>;
|
|
688
|
+
batch<const Queries extends readonly ExecutableQuery[]>(queries: Queries, options?: ExecutionOptions): Promise<{ readonly [K in keyof Queries]: ExecutionResultOf<Queries[K]>; }>;
|
|
689
|
+
bulk<Input>(inputs: readonly Input[], factory: (input: Input, index: number) => CommandQuery, options?: ExecutionOptions): Promise<BulkResult>;
|
|
690
|
+
prepare<Factory extends () => PreparableQuery>(name: string, factory: Factory & (Parameters<Factory> extends [] ? unknown : never)): PreparedQuery<never, ReturnType<Factory>>;
|
|
691
|
+
prepare<Factory extends (input: never) => PreparableQuery>(name: string, factory: Factory & (Parameters<Factory> extends [unknown] ? unknown : never)): PreparedQuery<Parameters<Factory>[0], ReturnType<Factory>>;
|
|
692
|
+
stream<Row>(query: RowQuery<Row>, options?: StreamOptions<Row>): AsyncIterable<Row>;
|
|
693
|
+
session<T>(callback: (database: Database) => Promise<T>): Promise<T>;
|
|
694
|
+
tx<T>(callback: (database: Database) => Promise<T>): Promise<T>;
|
|
695
|
+
tx<T>(options: TransactionOptions, callback: (database: Database) => Promise<T>): Promise<T>;
|
|
696
|
+
}
|
|
697
|
+
export interface BulkResult {
|
|
698
|
+
readonly inputCount: number;
|
|
699
|
+
readonly affectedRows?: number;
|
|
700
|
+
}
|
|
701
|
+
export type QueryRow<Q> = Q extends Query<infer Row, QueryResultKind> ? Row : never;
|
|
702
|
+
export interface SqlTagLike<Kind extends QueryResultKind = QueryResultKind, Row = unknown> {
|
|
703
|
+
(strings: TemplateStringsArray, ...values: readonly unknown[]): Query<Row, Kind>;
|
|
704
|
+
}
|
|
705
|
+
export interface RoutineContractTag<Contract extends RoutineContract> {
|
|
706
|
+
(strings: TemplateStringsArray, ...values: readonly unknown[]): CallQuery<RoutineResultFromContract<Contract>>;
|
|
707
|
+
}
|
|
708
|
+
export interface RowsTag {
|
|
709
|
+
<Input, Output>(schema: StandardSchemaV1$1<Input, Output>): SqlTagLike<"rows", Output>;
|
|
710
|
+
<Row = unknown>(strings: TemplateStringsArray, ...values: readonly unknown[]): RowQuery<Row>;
|
|
711
|
+
}
|
|
712
|
+
export interface SqlTag extends SqlTagLike<"unknown"> {
|
|
713
|
+
rows: RowsTag;
|
|
714
|
+
command: (strings: TemplateStringsArray, ...values: readonly unknown[]) => CommandQuery;
|
|
715
|
+
call: {
|
|
716
|
+
<Result extends RoutineCallResult = RoutineCallResult>(strings: TemplateStringsArray, ...values: readonly unknown[]): CallQuery<Result>;
|
|
717
|
+
<Contract extends RoutineContract>(contract: Contract): RoutineContractTag<Contract>;
|
|
718
|
+
};
|
|
719
|
+
bind<Input>(value: NoInfer<Input>, hint: ParameterTypeHint<Input>): BoundParameter<Input>;
|
|
720
|
+
out(name: string, hint?: ParameterTypeHint): RoutineParameter<null>;
|
|
721
|
+
inOut<Input>(name: string, value: NoInfer<Input>, hint?: ParameterTypeHint<Input>): RoutineParameter<Input>;
|
|
722
|
+
fragment: (strings: TemplateStringsArray, ...values: readonly unknown[]) => SqlFragment;
|
|
723
|
+
empty: SqlFragment;
|
|
724
|
+
ident: (identifier: string | readonly string[]) => SqlFragment;
|
|
725
|
+
raw: (text: string) => SqlFragment;
|
|
726
|
+
join: (items: readonly SqlFragment[], separator?: SqlFragment) => SqlFragment;
|
|
727
|
+
list: (values: readonly unknown[]) => SqlFragment;
|
|
728
|
+
}
|
|
729
|
+
export declare class SqlRenderError extends Error {
|
|
730
|
+
readonly code: string;
|
|
731
|
+
constructor(code: string, message: string);
|
|
732
|
+
}
|
|
733
|
+
//#endregion
|
|
734
|
+
export type { StandardSchemaV1 };
|
|
735
|
+
//# sourceMappingURL=index.d.ts.map
|