@sqlbraid/core 1.0.0 → 1.0.3
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 +1 -1
- package/README.md +3 -12
- package/dist/driver.d.ts +39 -0
- package/dist/driver.d.ts.map +1 -1
- package/dist/driver.js +64 -1
- package/dist/driver.js.map +1 -1
- package/dist/index.d.ts +731 -564
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +664 -574
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,277 +1,302 @@
|
|
|
1
1
|
import { StandardSchemaV1, StandardSchemaV1 as StandardSchemaV1$1 } from "@standard-schema/spec";
|
|
2
|
-
//#region src/
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
readonly
|
|
6
|
-
readonly
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export
|
|
2
|
+
//#region src/errors.d.ts
|
|
3
|
+
/** Thrown when a driver value cannot be represented without losing database information. */
|
|
4
|
+
export declare class ResultExactnessError extends Error {
|
|
5
|
+
static readonly code: "BRAID_RESULT_EXACTNESS";
|
|
6
|
+
readonly code: "BRAID_RESULT_EXACTNESS";
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
export type PublicErrorCategory = "runtime" | "adapter" | "compiler";
|
|
10
|
+
/** One deliberately public SQLBraid error code; an arbitrary `BRAID_` message is not automatically public. */
|
|
11
|
+
export interface PublicErrorDefinition {
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly category: PublicErrorCategory;
|
|
14
|
+
readonly owner: string;
|
|
15
|
+
/**
|
|
16
|
+
* UnsupportedFeatureError only: features for which this code is a public
|
|
17
|
+
* contract. Other public errors intentionally omit this metadata.
|
|
18
|
+
*/
|
|
19
|
+
readonly features?: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The intentionally small compatibility boundary for SQLBraid-owned errors.
|
|
23
|
+
*
|
|
24
|
+
* Keep this registry explicit. In particular, a BRAID_ token in a driver
|
|
25
|
+
* message or an internal compiler fallback is not public merely because it
|
|
26
|
+
* happens to use the project prefix.
|
|
27
|
+
*/
|
|
28
|
+
export declare const PUBLIC_ERROR_DEFINITIONS: readonly PublicErrorDefinition[];
|
|
29
|
+
/** Public adapter capability failure. Unsupported features reject explicitly rather than being buffered or simulated. */
|
|
30
|
+
export declare class UnsupportedFeatureError extends Error {
|
|
31
|
+
readonly feature: string;
|
|
32
|
+
readonly code: `BRAID_${string}`;
|
|
33
|
+
constructor(feature: string, code: `BRAID_${string}`, message: string, options?: ErrorOptions);
|
|
34
|
+
}
|
|
35
|
+
/** Return true only for a registered, semantically valid feature/code pair. */
|
|
36
|
+
export declare function isPublicUnsupportedFeatureError(error: unknown): error is UnsupportedFeatureError;
|
|
37
|
+
/** An adapter-owned input/transport failure that retains TypeError semantics. */
|
|
38
|
+
export declare class AdapterError extends TypeError {
|
|
39
|
+
readonly code: `BRAID_${string}`;
|
|
40
|
+
constructor(code: `BRAID_${string}`, message: string, options?: ErrorOptions);
|
|
41
|
+
}
|
|
42
|
+
/** Rendering/authoring failure with a stable diagnostic code, raised before driver execution. */
|
|
43
|
+
export declare class SqlRenderError extends Error {
|
|
44
|
+
readonly code: string;
|
|
45
|
+
constructor(code: string, message: string);
|
|
46
|
+
}
|
|
10
47
|
//#endregion
|
|
11
|
-
//#region src/
|
|
48
|
+
//#region src/numeric.d.ts
|
|
49
|
+
export type NumericSemantics = "exact-integer" | "exact-decimal" | "approximate-binary";
|
|
50
|
+
export type NumericRepresentation = "string" | "number";
|
|
51
|
+
export type TransportFidelity = "lossless" | "guarded" | "lossy" | "unsupported";
|
|
52
|
+
/** Database type semantics, JavaScript representation, and transport-fidelity claim for one mapping. */
|
|
53
|
+
export interface NumericTypeContract {
|
|
54
|
+
readonly semantics: NumericSemantics;
|
|
55
|
+
readonly representation: NumericRepresentation;
|
|
56
|
+
readonly fidelity: TransportFidelity;
|
|
57
|
+
readonly binaryPrecision?: 32 | 64;
|
|
58
|
+
}
|
|
59
|
+
export interface ExactIntegerRange {
|
|
60
|
+
readonly min?: bigint;
|
|
61
|
+
readonly max?: bigint;
|
|
62
|
+
}
|
|
12
63
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
64
|
+
* Decode an exact integer from driver output, optionally enforcing bigint bounds.
|
|
65
|
+
*
|
|
66
|
+
* @throws {ResultExactnessError} When the value is not an exact integer or violates the requested range.
|
|
16
67
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
68
|
+
export declare function decodeExactInteger(value: unknown, range?: ExactIntegerRange): bigint;
|
|
69
|
+
/**
|
|
70
|
+
* Normalize an exact integer at the raw SQLBraid boundary without changing
|
|
71
|
+
* its textual spelling. This is intentionally not a bigint decoder: callers
|
|
72
|
+
* that need arithmetic may opt in to decodeExactInteger().
|
|
73
|
+
*/
|
|
74
|
+
export declare function normalizeExactInteger(value: unknown): string;
|
|
75
|
+
/**
|
|
76
|
+
* Convert a database-reported count to a safe operational Number. Counts are
|
|
77
|
+
* not application values, so unlike exact SQL numerics they remain numbers,
|
|
78
|
+
* but narrowing an unsafe value is never implicit.
|
|
79
|
+
*/
|
|
80
|
+
export declare function safeDatabaseCount(value: unknown): number;
|
|
81
|
+
/**
|
|
82
|
+
* Preserve an exact decimal as text; numeric JavaScript values are rejected because they may already be rounded.
|
|
83
|
+
*
|
|
84
|
+
* @throws {ResultExactnessError} When the value cannot prove exact decimal fidelity.
|
|
85
|
+
*/
|
|
86
|
+
export declare function decodeExactDecimal(value: unknown, options?: {
|
|
87
|
+
readonly allowBigInt?: boolean;
|
|
88
|
+
}): string;
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/parameter.d.ts
|
|
91
|
+
declare const boundParameterBrand: unique symbol;
|
|
92
|
+
export type RoutineParameterDirection = "in" | "out" | "inout";
|
|
93
|
+
/** Explicit database-type metadata for one bound value; this is not application validation or an input codec. */
|
|
94
|
+
export interface ParameterTypeHint<Input = unknown> {
|
|
95
|
+
readonly databaseType: string;
|
|
96
|
+
readonly length?: number | "max";
|
|
97
|
+
readonly precision?: number;
|
|
98
|
+
readonly scale?: number;
|
|
99
|
+
readonly __input?: Input;
|
|
21
100
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
readonly
|
|
25
|
-
|
|
26
|
-
readonly
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
readonly
|
|
31
|
-
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
readonly id: "numeric.approximate-float";
|
|
48
|
-
readonly family: "representation";
|
|
49
|
-
}, {
|
|
50
|
-
readonly id: "numeric.approximate-special";
|
|
51
|
-
readonly family: "representation";
|
|
52
|
-
}, {
|
|
53
|
-
readonly id: "numeric.bind-exact";
|
|
54
|
-
readonly family: "representation";
|
|
55
|
-
}, {
|
|
56
|
-
readonly id: "numeric.aggregate";
|
|
57
|
-
readonly family: "representation";
|
|
58
|
-
}, {
|
|
59
|
-
readonly id: "numeric.command-metadata";
|
|
60
|
-
readonly family: "representation";
|
|
61
|
-
}, {
|
|
62
|
-
readonly id: "numeric.special-values";
|
|
63
|
-
readonly family: "representation";
|
|
64
|
-
}, {
|
|
65
|
-
readonly id: "numeric.scale-greater-than-precision";
|
|
66
|
-
readonly family: "representation";
|
|
67
|
-
}, {
|
|
68
|
-
readonly id: "numeric.negative-scale";
|
|
69
|
-
readonly family: "representation";
|
|
70
|
-
}, {
|
|
71
|
-
readonly id: "data.json-parsed";
|
|
72
|
-
readonly family: "representation";
|
|
73
|
-
}, {
|
|
74
|
-
readonly id: "data.json-lossless-text";
|
|
75
|
-
readonly family: "representation";
|
|
76
|
-
}, {
|
|
77
|
-
readonly id: "data.sql-variant";
|
|
78
|
-
readonly family: "representation";
|
|
79
|
-
}, {
|
|
80
|
-
readonly id: "data.oracle-object";
|
|
81
|
-
readonly family: "representation";
|
|
82
|
-
}, {
|
|
83
|
-
readonly id: "data.oracle-collection";
|
|
84
|
-
readonly family: "representation";
|
|
85
|
-
}, {
|
|
86
|
-
readonly id: "data.vector";
|
|
87
|
-
readonly family: "representation";
|
|
88
|
-
}, {
|
|
89
|
-
readonly id: "data.binary";
|
|
90
|
-
readonly family: "representation";
|
|
91
|
-
}, {
|
|
92
|
-
readonly id: "data.uuid";
|
|
93
|
-
readonly family: "representation";
|
|
94
|
-
}, {
|
|
95
|
-
readonly id: "data.temporal-native";
|
|
96
|
-
readonly family: "representation";
|
|
97
|
-
}, {
|
|
98
|
-
readonly id: "data.temporal-lossless";
|
|
99
|
-
readonly family: "representation";
|
|
100
|
-
}, {
|
|
101
|
-
readonly id: "data.timezone";
|
|
102
|
-
readonly family: "representation";
|
|
103
|
-
}, {
|
|
104
|
-
readonly id: "metadata.command-safe";
|
|
105
|
-
readonly family: "metadata";
|
|
106
|
-
}, {
|
|
107
|
-
readonly id: "dml.insert-returning";
|
|
108
|
-
readonly family: "support";
|
|
109
|
-
}, {
|
|
110
|
-
readonly id: "dml.update-returning";
|
|
111
|
-
readonly family: "support";
|
|
112
|
-
}, {
|
|
113
|
-
readonly id: "dml.delete-returning";
|
|
114
|
-
readonly family: "support";
|
|
115
|
-
}, {
|
|
116
|
-
readonly id: "dml.merge-returning";
|
|
117
|
-
readonly family: "support";
|
|
118
|
-
}, {
|
|
119
|
-
readonly id: "dml.upsert-returning";
|
|
120
|
-
readonly family: "support";
|
|
121
|
-
}, {
|
|
122
|
-
readonly id: "session.pinned";
|
|
123
|
-
readonly family: "support";
|
|
124
|
-
}, {
|
|
125
|
-
readonly id: "statement.prepare";
|
|
126
|
-
readonly family: "support";
|
|
127
|
-
}, {
|
|
128
|
-
readonly id: "statement.cancel";
|
|
129
|
-
readonly family: "support";
|
|
130
|
-
}, {
|
|
131
|
-
readonly id: "statement.stream";
|
|
132
|
-
readonly family: "support";
|
|
133
|
-
}, {
|
|
134
|
-
readonly id: "statement.bulk";
|
|
135
|
-
readonly family: "support";
|
|
136
|
-
}, {
|
|
137
|
-
readonly id: "execution.bulk-fidelity";
|
|
138
|
-
readonly family: "support";
|
|
139
|
-
}, {
|
|
140
|
-
readonly id: "transaction";
|
|
141
|
-
readonly family: "support";
|
|
142
|
-
}, {
|
|
143
|
-
readonly id: "transaction.savepoint";
|
|
144
|
-
readonly family: "support";
|
|
145
|
-
}, {
|
|
146
|
-
readonly id: "transaction.read-only";
|
|
147
|
-
readonly family: "support";
|
|
148
|
-
}, {
|
|
149
|
-
readonly id: "transaction.isolation.read-uncommitted";
|
|
150
|
-
readonly family: "support";
|
|
151
|
-
}, {
|
|
152
|
-
readonly id: "transaction.isolation.read-committed";
|
|
153
|
-
readonly family: "support";
|
|
154
|
-
}, {
|
|
155
|
-
readonly id: "transaction.isolation.repeatable-read";
|
|
156
|
-
readonly family: "support";
|
|
157
|
-
}, {
|
|
158
|
-
readonly id: "transaction.isolation.serializable";
|
|
159
|
-
readonly family: "support";
|
|
160
|
-
}, {
|
|
161
|
-
readonly id: "routine.call";
|
|
162
|
-
readonly family: "support";
|
|
163
|
-
}, {
|
|
164
|
-
readonly id: "routine.out";
|
|
165
|
-
readonly family: "support";
|
|
166
|
-
}, {
|
|
167
|
-
readonly id: "routine.inout";
|
|
168
|
-
readonly family: "support";
|
|
169
|
-
}, {
|
|
170
|
-
readonly id: "routine.result-sets";
|
|
171
|
-
readonly family: "support";
|
|
172
|
-
}, {
|
|
173
|
-
readonly id: "routine.out-cursor";
|
|
174
|
-
readonly family: "support";
|
|
175
|
-
}, {
|
|
176
|
-
readonly id: "routine.return-value";
|
|
177
|
-
readonly family: "support";
|
|
178
|
-
}, {
|
|
179
|
-
readonly id: "metadata.identity";
|
|
180
|
-
readonly family: "metadata";
|
|
181
|
-
}, {
|
|
182
|
-
readonly id: "metadata.generated";
|
|
183
|
-
readonly family: "metadata";
|
|
184
|
-
}, {
|
|
185
|
-
readonly id: "metadata.routines";
|
|
186
|
-
readonly family: "metadata";
|
|
187
|
-
}, {
|
|
188
|
-
readonly id: "metadata.types";
|
|
189
|
-
readonly family: "metadata";
|
|
190
|
-
}];
|
|
191
|
-
export declare const WELL_KNOWN_CAPABILITIES: readonly WellKnownCapability[];
|
|
192
|
-
type WellKnownCapabilityId = (typeof definitions)[number]["id"];
|
|
193
|
-
export declare const WELL_KNOWN_CAPABILITY_IDS: readonly WellKnownCapabilityId[];
|
|
194
|
-
export declare function isWellKnownCapabilityId(value: string): value is WellKnownCapabilityId;
|
|
101
|
+
/** Value plus an explicit database type hint, created by `sql.bind()`. */
|
|
102
|
+
export interface BoundParameter<Input = unknown> {
|
|
103
|
+
readonly value: Input;
|
|
104
|
+
readonly hint: ParameterTypeHint<Input>;
|
|
105
|
+
readonly [boundParameterBrand]: true;
|
|
106
|
+
}
|
|
107
|
+
/** Value-only routine OUT/INOUT marker; the direction and output name are interpreted by the adapter. */
|
|
108
|
+
export interface RoutineParameter<Input = unknown> {
|
|
109
|
+
readonly value: Input;
|
|
110
|
+
readonly hint?: ParameterTypeHint;
|
|
111
|
+
readonly direction: Exclude<RoutineParameterDirection, "in">;
|
|
112
|
+
readonly outputName: string;
|
|
113
|
+
}
|
|
114
|
+
/** Validate and freeze an explicit database parameter-type hint. */
|
|
115
|
+
export declare function createParameterTypeHint<Input = unknown>(hint: ParameterTypeHint<Input>): ParameterTypeHint<Input>;
|
|
116
|
+
/** Create the value-only marker consumed by adapter binding for an explicitly typed input. */
|
|
117
|
+
export declare function createBoundParameter<Input>(value: NoInfer<Input>, hint: ParameterTypeHint<Input>): BoundParameter<Input>;
|
|
118
|
+
/** Recognize only bound-parameter objects created by SQLBraid's own constructor. */
|
|
119
|
+
export declare function isBoundParameter(value: unknown): value is BoundParameter;
|
|
120
|
+
/** Create a value-only OUT parameter descriptor; the adapter supplies the native carrier. */
|
|
121
|
+
export declare function createRoutineOutParameter(name: string, hint?: ParameterTypeHint): RoutineParameter<null>;
|
|
122
|
+
/** Create a value-only INOUT parameter descriptor; input value and output channel stay distinct. */
|
|
123
|
+
export declare function createRoutineInOutParameter<Input>(name: string, value: NoInfer<Input>, hint?: ParameterTypeHint<Input>): RoutineParameter<Input>;
|
|
124
|
+
/** Recognize only routine OUT/INOUT descriptors created by SQLBraid's own constructor. */
|
|
125
|
+
export declare function isRoutineParameter(value: unknown): value is RoutineParameter;
|
|
195
126
|
//#endregion
|
|
196
|
-
//#region src/
|
|
127
|
+
//#region src/routine.d.ts
|
|
128
|
+
/** Optional routine identity metadata used by procedure-aware adapters and prepared-shape checks. */
|
|
129
|
+
export interface RoutineProcedure {
|
|
130
|
+
readonly name: string;
|
|
131
|
+
readonly parameterNames: readonly string[];
|
|
132
|
+
}
|
|
133
|
+
export type RoutineSchema = StandardSchemaV1$1<any, any>;
|
|
134
|
+
/**
|
|
135
|
+
* Application mapping contracts for routine OUT values, result sets, and return values.
|
|
136
|
+
* Each channel is independent; an OUT cursor is represented as a result set, not as scalar output.
|
|
137
|
+
*/
|
|
138
|
+
export interface RoutineContract<Output extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>, Sets extends readonly RoutineSchema[] = readonly RoutineSchema[], ReturnValue = unknown> {
|
|
139
|
+
readonly output?: StandardSchemaV1$1<any, Output>;
|
|
140
|
+
readonly resultSets?: Sets;
|
|
141
|
+
readonly returnValue?: StandardSchemaV1$1<any, ReturnValue>;
|
|
142
|
+
readonly procedure?: RoutineProcedure;
|
|
143
|
+
}
|
|
144
|
+
/** One materialized routine result set, kept separate from scalar OUT and return-value channels. */
|
|
145
|
+
export interface RoutineResultSet<Row = unknown> {
|
|
146
|
+
readonly rows: readonly Row[];
|
|
147
|
+
}
|
|
148
|
+
export type RoutineResultSetTuple<Sets extends readonly unknown[]> = { readonly [K in keyof Sets]: RoutineResultSet<Sets[K]>; };
|
|
149
|
+
/** Application-facing routine result with independent output, result-set, and return-value channels. */
|
|
150
|
+
export interface RoutineCallResult<Output extends Readonly<Record<string, unknown>> = Readonly<Record<string, unknown>>, Sets extends readonly unknown[] = readonly unknown[], ReturnValue = unknown> {
|
|
151
|
+
readonly output: Output;
|
|
152
|
+
readonly resultSets: RoutineResultSetTuple<Sets>;
|
|
153
|
+
readonly returnValue?: ReturnValue;
|
|
154
|
+
}
|
|
155
|
+
export type RoutineSchemaOutput<Schema> = Schema extends StandardSchemaV1$1<any, infer Output> ? Output : never;
|
|
156
|
+
type RoutineRowsFromSchemas<Schemas extends readonly RoutineSchema[]> = { readonly [K in keyof Schemas]: RoutineSchemaOutput<Schemas[K]>; };
|
|
157
|
+
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 {
|
|
158
|
+
readonly returnValue: RoutineSchema;
|
|
159
|
+
} ? {
|
|
160
|
+
readonly returnValue: RoutineSchemaOutput<Contract["returnValue"]>;
|
|
161
|
+
} : {});
|
|
162
|
+
export type RoutineResultSource = {
|
|
163
|
+
readonly kind: "out-cursor";
|
|
164
|
+
readonly name?: string;
|
|
165
|
+
readonly parameterIndex?: number;
|
|
166
|
+
} | {
|
|
167
|
+
readonly kind: "implicit";
|
|
168
|
+
readonly index: number;
|
|
169
|
+
} | {
|
|
170
|
+
readonly kind: "emitted";
|
|
171
|
+
readonly index: number;
|
|
172
|
+
};
|
|
173
|
+
/** Driver result-set payload with provenance for OUT cursors and emitted/implicit sets. */
|
|
174
|
+
export interface DriverRoutineResultSet {
|
|
175
|
+
readonly rows: readonly unknown[];
|
|
176
|
+
readonly source: RoutineResultSource;
|
|
177
|
+
}
|
|
178
|
+
/** Fully materialized routine result; native cursors, requests, and LOB handles must not escape this boundary. */
|
|
179
|
+
export interface DriverRoutineResult {
|
|
180
|
+
readonly output: Readonly<Record<string, unknown>>;
|
|
181
|
+
readonly returnValue?: unknown;
|
|
182
|
+
readonly resultSets: readonly DriverRoutineResultSet[];
|
|
183
|
+
}
|
|
184
|
+
export type RoutineMappingLocation = {
|
|
185
|
+
readonly kind: "output";
|
|
186
|
+
} | {
|
|
187
|
+
readonly kind: "return-value";
|
|
188
|
+
} | {
|
|
189
|
+
readonly kind: "result-set";
|
|
190
|
+
readonly resultSetIndex: number;
|
|
191
|
+
readonly rowIndex: number;
|
|
192
|
+
};
|
|
193
|
+
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";
|
|
194
|
+
/** Identifies which routine channel or row failed during Standard Schema mapping. */
|
|
195
|
+
export declare class RoutineMappingError extends Error {
|
|
196
|
+
static readonly code: "BRAID_CALL_MAP";
|
|
197
|
+
readonly code: "BRAID_CALL_MAP";
|
|
198
|
+
readonly location: RoutineMappingLocation;
|
|
199
|
+
constructor(message: string, location: RoutineMappingLocation, options?: {
|
|
200
|
+
readonly cause?: unknown;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/template-ir.d.ts
|
|
197
205
|
export declare const SQL_FRAGMENT: unique symbol;
|
|
198
|
-
|
|
206
|
+
/** Half-open source range in the cooked template text, used for diagnostics and source mapping. */
|
|
199
207
|
export interface SourceRange {
|
|
200
208
|
readonly start: number;
|
|
201
209
|
readonly end: number;
|
|
202
210
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
readonly
|
|
206
|
-
readonly
|
|
207
|
-
readonly
|
|
211
|
+
/** Safety bounds applied while parsing and rendering dynamic SQL. */
|
|
212
|
+
export interface RenderLimits {
|
|
213
|
+
readonly maxSqlBytes?: number;
|
|
214
|
+
readonly maxBindCount?: number;
|
|
215
|
+
readonly maxStructuralItems?: number;
|
|
216
|
+
readonly maxNestingDepth?: number;
|
|
217
|
+
}
|
|
218
|
+
/** Declared logical result channel; runtime checks the driver's actual result kind against it. */
|
|
219
|
+
export type QueryResultKind = "rows" | "command" | "call" | "unknown";
|
|
220
|
+
export interface TextNode {
|
|
221
|
+
readonly kind: "text";
|
|
222
|
+
readonly text: string;
|
|
223
|
+
readonly range: SourceRange;
|
|
224
|
+
}
|
|
225
|
+
export interface BindNode {
|
|
226
|
+
readonly kind: "bind";
|
|
227
|
+
readonly interpolation: number;
|
|
228
|
+
readonly range: SourceRange;
|
|
229
|
+
}
|
|
230
|
+
export interface FragmentNode {
|
|
231
|
+
readonly kind: "fragment";
|
|
232
|
+
readonly fragment: SqlFragment;
|
|
233
|
+
readonly range: SourceRange;
|
|
234
|
+
}
|
|
235
|
+
export interface IdentifierNode {
|
|
236
|
+
readonly kind: "identifier";
|
|
237
|
+
readonly value: string | readonly string[];
|
|
238
|
+
readonly range: SourceRange;
|
|
239
|
+
}
|
|
240
|
+
export interface RawNode {
|
|
241
|
+
readonly kind: "raw";
|
|
242
|
+
readonly text: string;
|
|
243
|
+
readonly range: SourceRange;
|
|
208
244
|
}
|
|
209
|
-
export
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
export interface NumericTypeContract {
|
|
214
|
-
readonly semantics: NumericSemantics;
|
|
215
|
-
readonly representation: NumericRepresentation;
|
|
216
|
-
readonly fidelity: TransportFidelity;
|
|
217
|
-
readonly binaryPrecision?: 32 | 64;
|
|
245
|
+
export interface ListNode {
|
|
246
|
+
readonly kind: "list";
|
|
247
|
+
readonly values: readonly unknown[];
|
|
248
|
+
readonly range: SourceRange;
|
|
218
249
|
}
|
|
219
|
-
export interface
|
|
220
|
-
readonly
|
|
221
|
-
readonly
|
|
250
|
+
export interface IfNode {
|
|
251
|
+
readonly kind: "if";
|
|
252
|
+
readonly condition: number;
|
|
253
|
+
readonly children: readonly TemplateNode[];
|
|
254
|
+
readonly range: SourceRange;
|
|
222
255
|
}
|
|
223
|
-
export
|
|
224
|
-
|
|
225
|
-
readonly
|
|
226
|
-
|
|
256
|
+
export interface ChooseWhen {
|
|
257
|
+
readonly condition: number;
|
|
258
|
+
readonly children: readonly TemplateNode[];
|
|
259
|
+
readonly range: SourceRange;
|
|
227
260
|
}
|
|
228
|
-
export
|
|
229
|
-
|
|
230
|
-
readonly
|
|
231
|
-
readonly
|
|
232
|
-
readonly
|
|
261
|
+
export interface ChooseNode {
|
|
262
|
+
readonly kind: "choose";
|
|
263
|
+
readonly whens: readonly ChooseWhen[];
|
|
264
|
+
readonly otherwise?: readonly TemplateNode[];
|
|
265
|
+
readonly range: SourceRange;
|
|
266
|
+
}
|
|
267
|
+
export interface TrimAttributes {
|
|
268
|
+
readonly prefix: string;
|
|
269
|
+
readonly prefixOverrides: readonly string[];
|
|
270
|
+
readonly suffix: string;
|
|
271
|
+
readonly suffixOverrides: readonly string[];
|
|
272
|
+
}
|
|
273
|
+
export interface TrimNode {
|
|
274
|
+
readonly kind: "trim";
|
|
275
|
+
readonly attributes: TrimAttributes;
|
|
276
|
+
readonly children: readonly TemplateNode[];
|
|
277
|
+
readonly range: SourceRange;
|
|
278
|
+
}
|
|
279
|
+
export type TemplateNode = TextNode | BindNode | FragmentNode | IdentifierNode | RawNode | ListNode | IfNode | ChooseNode | TrimNode;
|
|
280
|
+
/** Frozen template intermediate representation with source ranges and optional raw-text parallel nodes. */
|
|
281
|
+
export interface TemplateIr {
|
|
282
|
+
readonly version: 1;
|
|
283
|
+
readonly nodes: readonly TemplateNode[];
|
|
284
|
+
readonly sourceLength: number;
|
|
233
285
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
286
|
+
* Optional parallel node tree preserving raw JavaScript template text for
|
|
287
|
+
* native tagged-template transports. The logical node tree remains cooked.
|
|
236
288
|
*/
|
|
237
|
-
readonly
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* The intentionally small compatibility boundary for SQLBraid-owned errors.
|
|
241
|
-
*
|
|
242
|
-
* Keep this registry explicit. In particular, a BRAID_ token in a driver
|
|
243
|
-
* message or an internal compiler fallback is not public merely because it
|
|
244
|
-
* happens to use the project prefix.
|
|
245
|
-
*/
|
|
246
|
-
export declare const PUBLIC_ERROR_DEFINITIONS: readonly PublicErrorDefinition[];
|
|
247
|
-
export declare function decodeExactInteger(value: unknown, range?: ExactIntegerRange): bigint;
|
|
248
|
-
/**
|
|
249
|
-
* Normalize an exact integer at the raw SQLBraid boundary without changing
|
|
250
|
-
* its textual spelling. This is intentionally not a bigint decoder: callers
|
|
251
|
-
* that need arithmetic may opt in to decodeExactInteger().
|
|
252
|
-
*/
|
|
253
|
-
export declare function normalizeExactInteger(value: unknown): string;
|
|
254
|
-
/**
|
|
255
|
-
* Convert a database-reported count to a safe operational Number. Counts are
|
|
256
|
-
* not application values, so unlike exact SQL numerics they remain numbers,
|
|
257
|
-
* but narrowing an unsafe value is never implicit.
|
|
258
|
-
*/
|
|
259
|
-
export declare function safeDatabaseCount(value: unknown): number;
|
|
260
|
-
export declare function decodeExactDecimal(value: unknown, options?: {
|
|
261
|
-
readonly allowBigInt?: boolean;
|
|
262
|
-
}): string;
|
|
263
|
-
export type RoutineParameterDirection = "in" | "out" | "inout";
|
|
264
|
-
export interface RoutineProcedure {
|
|
265
|
-
readonly name: string;
|
|
266
|
-
readonly parameterNames: readonly string[];
|
|
289
|
+
readonly rawNodes?: readonly TemplateNode[];
|
|
267
290
|
}
|
|
268
|
-
|
|
269
|
-
export interface
|
|
270
|
-
readonly
|
|
271
|
-
readonly
|
|
272
|
-
readonly
|
|
273
|
-
readonly
|
|
291
|
+
/** Explicit structural SQL fragment. Ordinary interpolations are values; fragments opt into SQL structure. */
|
|
292
|
+
export interface SqlFragment {
|
|
293
|
+
readonly [SQL_FRAGMENT]: true;
|
|
294
|
+
readonly ir: TemplateIr;
|
|
295
|
+
readonly values: readonly unknown[];
|
|
296
|
+
readonly dialectId: string;
|
|
274
297
|
}
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/statement.d.ts
|
|
275
300
|
/**
|
|
276
301
|
* A rendered parameter is always a value. Adapters MUST NOT interpret it as
|
|
277
302
|
* raw SQL, an identifier, a nested query, a driver-specific fragment, or a
|
|
@@ -284,6 +309,10 @@ export interface RenderedParameter {
|
|
|
284
309
|
readonly direction?: RoutineParameterDirection;
|
|
285
310
|
readonly outputName?: string;
|
|
286
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Immutable logical statement before driver materialization.
|
|
314
|
+
* `segments.length` is always `parameters.length + 1`; structural SQL lives in segments and parameters remain values.
|
|
315
|
+
*/
|
|
287
316
|
export interface RenderedStatement {
|
|
288
317
|
readonly segments: readonly string[];
|
|
289
318
|
readonly parameters: readonly RenderedParameter[];
|
|
@@ -299,34 +328,31 @@ export interface RenderedStatement {
|
|
|
299
328
|
readonly fingerprint?: string;
|
|
300
329
|
readonly variantFingerprint?: string;
|
|
301
330
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
readonly
|
|
305
|
-
readonly
|
|
306
|
-
readonly scale?: number;
|
|
307
|
-
readonly __input?: Input;
|
|
308
|
-
}
|
|
309
|
-
export interface BoundParameter<Input = unknown> {
|
|
310
|
-
readonly value: Input;
|
|
311
|
-
readonly hint: ParameterTypeHint<Input>;
|
|
312
|
-
readonly [boundParameterBrand]: true;
|
|
313
|
-
}
|
|
314
|
-
export interface RoutineParameter<Input = unknown> {
|
|
315
|
-
readonly value: Input;
|
|
316
|
-
readonly hint?: ParameterTypeHint;
|
|
317
|
-
readonly direction: Exclude<RoutineParameterDirection, "in">;
|
|
318
|
-
readonly outputName: string;
|
|
331
|
+
/** One logical command shape plus its value matrix; all rows must remain homogeneous. */
|
|
332
|
+
export interface RenderedBulk {
|
|
333
|
+
readonly statement: RenderedStatement;
|
|
334
|
+
readonly parameterSets: readonly (readonly unknown[])[];
|
|
319
335
|
}
|
|
320
|
-
export declare function
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
export declare function
|
|
324
|
-
|
|
325
|
-
|
|
336
|
+
export declare function createRenderedBulk(bulk: RenderedBulk): RenderedBulk;
|
|
337
|
+
/** Validate and freeze one logical statement without creating a second mutable SQL/value source of truth. */
|
|
338
|
+
/** @throws {TypeError|SqlRenderError} For broken segment/parameter invariants or unsupported bind values. */
|
|
339
|
+
export declare function createRenderedStatement(statement: {
|
|
340
|
+
readonly segments: readonly string[];
|
|
341
|
+
readonly parameters: readonly RenderedParameter[];
|
|
342
|
+
readonly nativeTemplate?: TemplateStringsArray;
|
|
343
|
+
readonly resultKind: QueryResultKind;
|
|
344
|
+
readonly routineProcedure?: RoutineProcedure;
|
|
345
|
+
readonly dialectId: string;
|
|
346
|
+
readonly fingerprint?: string;
|
|
347
|
+
readonly variantFingerprint?: string;
|
|
348
|
+
}): RenderedStatement;
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/binding.d.ts
|
|
326
351
|
export type ParameterTransportKind = "native-value-template" | "text-positional" | "text-named" | "typed-request";
|
|
327
352
|
export type RequestedReuse = "auto" | "simple" | "reuse";
|
|
328
353
|
export type EffectiveReuse = "simple" | "reuse";
|
|
329
354
|
export type ReuseOwner = "sqlbraid" | "driver" | "server";
|
|
355
|
+
/** Inputs to pure binding description. Placeholder syntax and prepared reuse remain adapter-owned. */
|
|
330
356
|
export interface StatementBindingContext {
|
|
331
357
|
readonly dialectId: string;
|
|
332
358
|
readonly requestedReuse: RequestedReuse;
|
|
@@ -341,12 +367,14 @@ export interface BindingDescription {
|
|
|
341
367
|
readonly direction?: RoutineParameterDirection;
|
|
342
368
|
readonly outputName?: string;
|
|
343
369
|
}
|
|
370
|
+
/** Diagnostic-only literalization controls; the result must never be sent to a database. */
|
|
344
371
|
export interface LiteralizeOptions {
|
|
345
372
|
readonly values?: "inline" | "redacted";
|
|
346
373
|
readonly maxValueLength?: number;
|
|
347
374
|
readonly binary?: "summary" | "full";
|
|
348
375
|
readonly redact?: (parameter: RenderedParameter, index: number) => boolean;
|
|
349
376
|
}
|
|
377
|
+
/** Diagnostic SQL reconstruction with explicit redaction/truncation evidence. */
|
|
350
378
|
export interface LiteralizedSqlResult {
|
|
351
379
|
readonly text: string;
|
|
352
380
|
/**
|
|
@@ -358,6 +386,10 @@ export interface LiteralizedSqlResult {
|
|
|
358
386
|
readonly redactedParameters: number;
|
|
359
387
|
readonly truncatedParameters: number;
|
|
360
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Immutable transport description derived from one logical statement.
|
|
391
|
+
* `literalizedSql()` reconstructs diagnostics from segments and values; it is never execution input.
|
|
392
|
+
*/
|
|
361
393
|
export interface StatementBindingDescription {
|
|
362
394
|
readonly adapterId: string;
|
|
363
395
|
readonly dialectId: string;
|
|
@@ -373,6 +405,10 @@ export interface StatementBindingDescription {
|
|
|
373
405
|
/** Diagnostic reconstruction only; never use this text as execution input. */
|
|
374
406
|
readonly literalizedSql: (options?: LiteralizeOptions) => LiteralizedSqlResult;
|
|
375
407
|
}
|
|
408
|
+
/**
|
|
409
|
+
* Driver-owned binding policy. Implementations choose transport, placeholders, type encoding, and reuse ownership.
|
|
410
|
+
* `describe` must be pure and safe to run before connection acquisition.
|
|
411
|
+
*/
|
|
376
412
|
export interface StatementBindingAdapter {
|
|
377
413
|
readonly id: string;
|
|
378
414
|
describe(statement: RenderedStatement, context: StatementBindingContext): StatementBindingDescription;
|
|
@@ -389,10 +425,7 @@ export interface StatementBindingDescriptionOptions {
|
|
|
389
425
|
};
|
|
390
426
|
readonly formatLiteral?: (parameter: RenderedParameter, index: number, options: LiteralizeOptions) => string | undefined;
|
|
391
427
|
}
|
|
392
|
-
|
|
393
|
-
readonly statement: RenderedStatement;
|
|
394
|
-
readonly parameterSets: readonly (readonly unknown[])[];
|
|
395
|
-
}
|
|
428
|
+
/** Binding metadata for a homogeneous bulk operation; values are fetched by item index. */
|
|
396
429
|
export interface BulkBindingDescription {
|
|
397
430
|
readonly adapterId: string;
|
|
398
431
|
readonly dialectId: string;
|
|
@@ -403,29 +436,18 @@ export interface BulkBindingDescription {
|
|
|
403
436
|
valuesAt(index: number): readonly unknown[];
|
|
404
437
|
literalizedSql(index: number, options?: LiteralizeOptions): LiteralizedSqlResult;
|
|
405
438
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Normalize and snapshot a homogeneous bulk's logical statement and value
|
|
408
|
-
* matrix. Values themselves are application-owned and are not cloned.
|
|
409
|
-
*/
|
|
410
|
-
export declare function createRenderedBulk(bulk: RenderedBulk): RenderedBulk;
|
|
411
|
-
export declare function createRenderedStatement(statement: {
|
|
412
|
-
readonly segments: readonly string[];
|
|
413
|
-
readonly parameters: readonly RenderedParameter[];
|
|
414
|
-
readonly nativeTemplate?: TemplateStringsArray;
|
|
415
|
-
readonly resultKind: QueryResultKind;
|
|
416
|
-
readonly routineProcedure?: RoutineProcedure;
|
|
417
|
-
readonly dialectId: string;
|
|
418
|
-
readonly fingerprint?: string;
|
|
419
|
-
readonly variantFingerprint?: string;
|
|
420
|
-
}): RenderedStatement;
|
|
439
|
+
/** Materialize placeholder text as a derived view; this helper does not own reuse or driver transport policy. */
|
|
421
440
|
export declare function parameterizedSql(statement: RenderedStatement, placeholder: (index: number) => string): string;
|
|
441
|
+
/** Build an immutable binding description before I/O, including adapter reuse policy and diagnostic literalization. */
|
|
422
442
|
export declare function createStatementBindingDescription(statement: RenderedStatement, context: StatementBindingContext, options: StatementBindingDescriptionOptions): StatementBindingDescription;
|
|
423
443
|
/**
|
|
424
|
-
* Build one binding description for a
|
|
425
|
-
* metadata is shared by every parameter set; values and diagnostics are
|
|
426
|
-
* addressed only when requested for a particular item.
|
|
444
|
+
* Build one binding description for a homogeneous bulk statement without cloning application-owned values.
|
|
445
|
+
* Statement metadata is shared by every parameter set; values and diagnostics are addressed by item index.
|
|
427
446
|
*/
|
|
428
447
|
export declare function createBulkBindingDescription(bulk: RenderedBulk, context: StatementBindingContext, options: StatementBindingDescriptionOptions): BulkBindingDescription;
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/dialect.d.ts
|
|
450
|
+
/** Lexical features the template parser must know to avoid treating SQL text inside comments/quotes as directives. */
|
|
429
451
|
export interface DialectLexicalProfile {
|
|
430
452
|
readonly lineCommentPrefixes: readonly string[];
|
|
431
453
|
/** Require whitespace/control after -- (MySQL/MariaDB). Defaults to false. */
|
|
@@ -437,103 +459,36 @@ export interface DialectLexicalProfile {
|
|
|
437
459
|
readonly supportsBacktickIdentifiers?: boolean;
|
|
438
460
|
readonly supportsBracketIdentifiers?: boolean;
|
|
439
461
|
readonly supportsOracleQQuotes?: boolean;
|
|
440
|
-
readonly backslashEscapes?: boolean;
|
|
441
|
-
}
|
|
442
|
-
export interface Dialect {
|
|
443
|
-
readonly id: string;
|
|
444
|
-
quoteIdentifier(identifier: string): string;
|
|
445
|
-
readonly lexicalProfile?: DialectLexicalProfile;
|
|
446
|
-
}
|
|
447
|
-
export interface TypeMapping {
|
|
448
|
-
readonly databaseType: string;
|
|
449
|
-
readonly inputType: string;
|
|
450
|
-
readonly outputType: string;
|
|
451
|
-
readonly nullable: boolean;
|
|
452
|
-
readonly numeric?: NumericTypeContract;
|
|
453
|
-
}
|
|
454
|
-
export interface TypePolicy {
|
|
455
|
-
readonly id: string;
|
|
456
|
-
readonly hash: string;
|
|
457
|
-
readonly mappings: readonly TypeMapping[];
|
|
458
|
-
decode(databaseType: string, value: unknown): unknown;
|
|
459
|
-
encode(databaseType: string, value: unknown): unknown;
|
|
460
|
-
}
|
|
461
|
-
export interface TextNode {
|
|
462
|
-
readonly kind: "text";
|
|
463
|
-
readonly text: string;
|
|
464
|
-
readonly range: SourceRange;
|
|
465
|
-
}
|
|
466
|
-
export interface BindNode {
|
|
467
|
-
readonly kind: "bind";
|
|
468
|
-
readonly interpolation: number;
|
|
469
|
-
readonly range: SourceRange;
|
|
470
|
-
}
|
|
471
|
-
export interface FragmentNode {
|
|
472
|
-
readonly kind: "fragment";
|
|
473
|
-
readonly fragment: SqlFragment;
|
|
474
|
-
readonly range: SourceRange;
|
|
475
|
-
}
|
|
476
|
-
export interface IdentifierNode {
|
|
477
|
-
readonly kind: "identifier";
|
|
478
|
-
readonly value: string | readonly string[];
|
|
479
|
-
readonly range: SourceRange;
|
|
480
|
-
}
|
|
481
|
-
export interface RawNode {
|
|
482
|
-
readonly kind: "raw";
|
|
483
|
-
readonly text: string;
|
|
484
|
-
readonly range: SourceRange;
|
|
485
|
-
}
|
|
486
|
-
export interface ListNode {
|
|
487
|
-
readonly kind: "list";
|
|
488
|
-
readonly values: readonly unknown[];
|
|
489
|
-
readonly range: SourceRange;
|
|
490
|
-
}
|
|
491
|
-
export interface IfNode {
|
|
492
|
-
readonly kind: "if";
|
|
493
|
-
readonly condition: number;
|
|
494
|
-
readonly children: readonly TemplateNode[];
|
|
495
|
-
readonly range: SourceRange;
|
|
496
|
-
}
|
|
497
|
-
export interface ChooseWhen {
|
|
498
|
-
readonly condition: number;
|
|
499
|
-
readonly children: readonly TemplateNode[];
|
|
500
|
-
readonly range: SourceRange;
|
|
501
|
-
}
|
|
502
|
-
export interface ChooseNode {
|
|
503
|
-
readonly kind: "choose";
|
|
504
|
-
readonly whens: readonly ChooseWhen[];
|
|
505
|
-
readonly otherwise?: readonly TemplateNode[];
|
|
506
|
-
readonly range: SourceRange;
|
|
507
|
-
}
|
|
508
|
-
export interface TrimAttributes {
|
|
509
|
-
readonly prefix: string;
|
|
510
|
-
readonly prefixOverrides: readonly string[];
|
|
511
|
-
readonly suffix: string;
|
|
512
|
-
readonly suffixOverrides: readonly string[];
|
|
513
|
-
}
|
|
514
|
-
export interface TrimNode {
|
|
515
|
-
readonly kind: "trim";
|
|
516
|
-
readonly attributes: TrimAttributes;
|
|
517
|
-
readonly children: readonly TemplateNode[];
|
|
518
|
-
readonly range: SourceRange;
|
|
462
|
+
readonly backslashEscapes?: boolean;
|
|
519
463
|
}
|
|
520
|
-
|
|
521
|
-
export interface
|
|
522
|
-
readonly
|
|
523
|
-
|
|
524
|
-
readonly
|
|
525
|
-
/**
|
|
526
|
-
* Optional parallel node tree preserving raw JavaScript template text for
|
|
527
|
-
* native tagged-template transports. The logical node tree remains cooked.
|
|
528
|
-
*/
|
|
529
|
-
readonly rawNodes?: readonly TemplateNode[];
|
|
464
|
+
/** SQL dialect boundary: identifier quoting plus lexical behavior used by template parsing and trimming. */
|
|
465
|
+
export interface Dialect {
|
|
466
|
+
readonly id: string;
|
|
467
|
+
quoteIdentifier(identifier: string): string;
|
|
468
|
+
readonly lexicalProfile?: DialectLexicalProfile;
|
|
530
469
|
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
readonly
|
|
534
|
-
readonly
|
|
535
|
-
readonly
|
|
470
|
+
/** One database type's input/output representation and numeric fidelity claim. */
|
|
471
|
+
export interface TypeMapping {
|
|
472
|
+
readonly databaseType: string;
|
|
473
|
+
readonly inputType: string;
|
|
474
|
+
readonly outputType: string;
|
|
475
|
+
readonly nullable: boolean;
|
|
476
|
+
readonly numeric?: NumericTypeContract;
|
|
477
|
+
}
|
|
478
|
+
/** Adapter type policy; it normalizes driver values and encodes inputs without becoming a schema validator. */
|
|
479
|
+
export interface TypePolicy {
|
|
480
|
+
readonly id: string;
|
|
481
|
+
readonly hash: string;
|
|
482
|
+
readonly mappings: readonly TypeMapping[];
|
|
483
|
+
decode(databaseType: string, value: unknown): unknown;
|
|
484
|
+
encode(databaseType: string, value: unknown): unknown;
|
|
536
485
|
}
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/query.d.ts
|
|
488
|
+
/**
|
|
489
|
+
* SQLBraid query value. It retains template IR and application mapping metadata until runtime rendering.
|
|
490
|
+
* `resultSchema` is applied after driver materialization and is never forwarded to the driver.
|
|
491
|
+
*/
|
|
537
492
|
export interface Query<Row = unknown, Kind extends QueryResultKind = "unknown"> {
|
|
538
493
|
readonly ir: TemplateIr;
|
|
539
494
|
readonly values: readonly unknown[];
|
|
@@ -549,17 +504,20 @@ export interface Query<Row = unknown, Kind extends QueryResultKind = "unknown">
|
|
|
549
504
|
export type RowQuery<Row = unknown> = Query<Row, "rows">;
|
|
550
505
|
export type CommandQuery = Query<CommandResult, "command">;
|
|
551
506
|
export type CallQuery<Result extends RoutineCallResult = RoutineCallResult> = Query<Result, "call">;
|
|
507
|
+
/** Driver-normalized command metadata; adapters may expose additional native fields without changing the kind. */
|
|
552
508
|
export interface CommandResult {
|
|
553
509
|
readonly affectedRows?: number;
|
|
554
510
|
readonly insertId?: string;
|
|
555
511
|
readonly [key: string]: unknown;
|
|
556
512
|
}
|
|
513
|
+
/** Materialized row result. Runtime validates that it matches a rows query declaration. */
|
|
557
514
|
export interface RowsExecutionResult<Row = unknown> {
|
|
558
515
|
readonly kind: "rows";
|
|
559
516
|
readonly rows: readonly Row[];
|
|
560
517
|
readonly rowCount?: number;
|
|
561
518
|
readonly command?: never;
|
|
562
519
|
}
|
|
520
|
+
/** Materialized command result. Command executions intentionally expose no row payload. */
|
|
563
521
|
export interface CommandExecutionResult {
|
|
564
522
|
readonly kind: "command";
|
|
565
523
|
readonly rows: readonly [];
|
|
@@ -567,125 +525,175 @@ export interface CommandExecutionResult {
|
|
|
567
525
|
readonly command: CommandResult;
|
|
568
526
|
}
|
|
569
527
|
export type QueryExecutionResult<Row = unknown> = RowsExecutionResult<Row> | CommandExecutionResult;
|
|
528
|
+
/** Execution controls shared by materialized, routine, batch, and stream operations. */
|
|
570
529
|
export interface ExecutionOptions {
|
|
571
530
|
readonly signal?: AbortSignal;
|
|
531
|
+
/** Override the database reuse preference for this operation; adapters select the effective strategy. */
|
|
532
|
+
readonly reuse?: RequestedReuse;
|
|
572
533
|
}
|
|
534
|
+
/** Physical SPI may complete synchronously; the public database surface remains asynchronous. */
|
|
573
535
|
export type Awaitable<T> = T | PromiseLike<T>;
|
|
536
|
+
/** Optional Standard Schema mapping applied after query-bound mapping and driver materialization. */
|
|
574
537
|
export interface RowValidationOptions<Row> extends ExecutionOptions {
|
|
575
538
|
readonly schema?: StandardSchemaV1$1<unknown, NoInfer<Row>>;
|
|
576
539
|
}
|
|
577
540
|
export interface StreamOptions<Row> extends RowValidationOptions<Row> {}
|
|
541
|
+
/** Portable transaction isolation vocabulary; adapters reject levels they cannot provide. */
|
|
578
542
|
export type TransactionIsolation = "read-uncommitted" | "read-committed" | "repeatable-read" | "serializable";
|
|
543
|
+
/** Options for the outer physical transaction. Nested `db.tx()` calls are savepoints and accept no second option set. */
|
|
579
544
|
export interface TransactionOptions {
|
|
580
545
|
readonly isolation?: TransactionIsolation;
|
|
581
546
|
readonly readOnly?: boolean;
|
|
582
547
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
/** An adapter-owned input/transport failure that retains TypeError semantics. */
|
|
591
|
-
export declare class AdapterError extends TypeError {
|
|
592
|
-
readonly code: `BRAID_${string}`;
|
|
593
|
-
constructor(code: `BRAID_${string}`, message: string, options?: ErrorOptions);
|
|
594
|
-
}
|
|
595
|
-
export interface RoutineResultSet<Row = unknown> {
|
|
596
|
-
readonly rows: readonly Row[];
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/environment.d.ts
|
|
550
|
+
export interface EnvironmentCapability {
|
|
551
|
+
readonly status: "guaranteed" | "guarded" | "unsupported";
|
|
552
|
+
readonly canonical?: "string" | "number" | "Uint8Array";
|
|
553
|
+
readonly rawRepresentations?: readonly string[];
|
|
554
|
+
readonly conditionCode?: string;
|
|
597
555
|
}
|
|
598
|
-
|
|
599
|
-
export interface
|
|
600
|
-
readonly
|
|
601
|
-
|
|
602
|
-
|
|
556
|
+
/** Observed database/driver/runtime evidence plus exact support-target matching. */
|
|
557
|
+
export interface DatabaseEnvironment {
|
|
558
|
+
readonly database: {
|
|
559
|
+
readonly product: string;
|
|
560
|
+
readonly version?: string;
|
|
561
|
+
readonly edition?: string;
|
|
562
|
+
};
|
|
563
|
+
readonly driver: {
|
|
564
|
+
readonly id: string;
|
|
565
|
+
readonly version?: string;
|
|
566
|
+
readonly profile?: string;
|
|
567
|
+
};
|
|
568
|
+
readonly runtime: {
|
|
569
|
+
readonly id: string;
|
|
570
|
+
readonly version?: string;
|
|
571
|
+
};
|
|
572
|
+
readonly typePolicy?: {
|
|
573
|
+
readonly id: string;
|
|
574
|
+
readonly hash: string;
|
|
575
|
+
};
|
|
576
|
+
readonly capabilities: Readonly<Record<string, EnvironmentCapability>>;
|
|
577
|
+
readonly supportMatch: {
|
|
578
|
+
readonly status: "official" | "conditional" | "compatible";
|
|
579
|
+
readonly targetId?: string;
|
|
580
|
+
readonly reason?: string;
|
|
581
|
+
};
|
|
603
582
|
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
readonly
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
readonly
|
|
613
|
-
readonly
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
};
|
|
622
|
-
export interface DriverRoutineResultSet {
|
|
623
|
-
readonly rows: readonly unknown[];
|
|
624
|
-
readonly source: RoutineResultSource;
|
|
583
|
+
/** Adapter evidence only. Probes run through the ordinary observed, leased query path. */
|
|
584
|
+
export interface DriverEnvironment {
|
|
585
|
+
readonly database: DatabaseEnvironment["database"];
|
|
586
|
+
readonly driver: DatabaseEnvironment["driver"];
|
|
587
|
+
readonly typePolicy?: {
|
|
588
|
+
readonly id: string;
|
|
589
|
+
readonly hash: string;
|
|
590
|
+
};
|
|
591
|
+
readonly capabilities: DatabaseEnvironment["capabilities"];
|
|
592
|
+
readonly probe?: {
|
|
593
|
+
readonly statement: RenderedStatement;
|
|
594
|
+
readonly read: (rows: readonly unknown[]) => {
|
|
595
|
+
readonly version?: string;
|
|
596
|
+
readonly edition?: string;
|
|
597
|
+
readonly capabilities?: Readonly<Record<string, EnvironmentCapability>>;
|
|
598
|
+
};
|
|
599
|
+
};
|
|
625
600
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
readonly
|
|
629
|
-
readonly
|
|
601
|
+
/** Structural subset of a support manifest; importing support tooling is unnecessary. */
|
|
602
|
+
export interface EnvironmentSupportTarget {
|
|
603
|
+
readonly id: string;
|
|
604
|
+
readonly status: string;
|
|
605
|
+
readonly database: {
|
|
606
|
+
readonly product: string;
|
|
607
|
+
readonly version: string;
|
|
608
|
+
readonly edition: string;
|
|
609
|
+
};
|
|
610
|
+
readonly driver: {
|
|
611
|
+
readonly id: string;
|
|
612
|
+
readonly version: string;
|
|
613
|
+
readonly profile: string;
|
|
614
|
+
};
|
|
615
|
+
readonly runtime: {
|
|
616
|
+
readonly id: string;
|
|
617
|
+
readonly version: string;
|
|
618
|
+
};
|
|
619
|
+
readonly typePolicy: {
|
|
620
|
+
readonly id: string;
|
|
621
|
+
readonly hash: string;
|
|
622
|
+
};
|
|
623
|
+
readonly evidence: {
|
|
624
|
+
readonly status: string;
|
|
625
|
+
};
|
|
630
626
|
}
|
|
631
|
-
export
|
|
632
|
-
readonly
|
|
633
|
-
|
|
634
|
-
readonly
|
|
635
|
-
} | {
|
|
636
|
-
readonly kind: "result-set";
|
|
637
|
-
readonly resultSetIndex: number;
|
|
638
|
-
readonly rowIndex: number;
|
|
639
|
-
};
|
|
640
|
-
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";
|
|
641
|
-
export declare class RoutineMappingError extends Error {
|
|
642
|
-
static readonly code: "BRAID_CALL_MAP";
|
|
643
|
-
readonly code: "BRAID_CALL_MAP";
|
|
644
|
-
readonly location: RoutineMappingLocation;
|
|
645
|
-
constructor(message: string, location: RoutineMappingLocation, options?: {
|
|
646
|
-
readonly cause?: unknown;
|
|
647
|
-
});
|
|
627
|
+
export interface EnvironmentOptions {
|
|
628
|
+
readonly targets?: readonly EnvironmentSupportTarget[];
|
|
629
|
+
/** Re-probe the current lease instead of returning the cached observation. */
|
|
630
|
+
readonly refresh?: boolean;
|
|
648
631
|
}
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region src/executor.d.ts
|
|
634
|
+
/** Native or adapter execution strategy reported for a bulk operation; the label does not imply atomicity. */
|
|
649
635
|
export type BulkExecutionMode = "native-bulk" | "pipeline" | "prepared-loop" | "remote-batch";
|
|
636
|
+
/** Driver bulk result normalized for runtime accounting and observer events. */
|
|
650
637
|
export interface BulkExecutionResult {
|
|
651
638
|
readonly inputCount: number;
|
|
652
639
|
readonly affectedRows?: number;
|
|
653
640
|
readonly executionMode: BulkExecutionMode;
|
|
654
641
|
}
|
|
642
|
+
/**
|
|
643
|
+
* Physical execution SPI for one serialized resource.
|
|
644
|
+
* Query/call/control methods may be synchronous at this boundary; streams remain async iterables and retain ownership until closed.
|
|
645
|
+
*/
|
|
655
646
|
export interface QueryExecutor {
|
|
656
647
|
/** Stable identity for the physical execution resource shared by wrappers; pools must use a leased resource. */
|
|
657
648
|
readonly ownershipKey?: object;
|
|
658
649
|
readonly statementBinding: StatementBindingAdapter;
|
|
659
650
|
readonly environment?: DriverEnvironment;
|
|
651
|
+
/** Execute one materialized statement on this physical resource. */
|
|
660
652
|
query<Row>(rendered: RenderedStatement, binding?: StatementBindingDescription, options?: ExecutionOptions): Awaitable<QueryExecutionResult<Row>>;
|
|
653
|
+
/** Open a true driver stream; the physical resource remains owned until iteration closes. */
|
|
661
654
|
stream<Row>(rendered: RenderedStatement, binding?: StatementBindingDescription, options?: ExecutionOptions): AsyncIterable<Row>;
|
|
655
|
+
/** Execute a routine call and return normalized scalar/result-set channels. */
|
|
662
656
|
call(rendered: RenderedStatement, binding?: StatementBindingDescription, options?: ExecutionOptions): Awaitable<DriverRoutineResult>;
|
|
657
|
+
/** Optional homogeneous bulk protocol. The reported execution mode does not imply atomicity. */
|
|
663
658
|
bulk?(bulk: RenderedBulk, binding: BulkBindingDescription, options?: ExecutionOptions): Awaitable<BulkExecutionResult>;
|
|
659
|
+
/** Pure pre-acquire validation for adapter-specific transaction option support. */
|
|
664
660
|
validateTransactionOptions?(options: TransactionOptions): void;
|
|
661
|
+
/** Begin the outer transaction on this physical resource. */
|
|
665
662
|
begin?(options?: TransactionOptions): Awaitable<void>;
|
|
663
|
+
/** Commit the outer transaction on this physical resource. */
|
|
666
664
|
commit?(): Awaitable<void>;
|
|
665
|
+
/** Roll back the outer transaction on this physical resource. */
|
|
667
666
|
rollback?(): Awaitable<void>;
|
|
667
|
+
/** Create a nested transaction boundary on the current resource. */
|
|
668
668
|
savepoint?(name: string): Awaitable<void>;
|
|
669
|
+
/** Roll back the current resource to a previously created savepoint. */
|
|
669
670
|
rollbackTo?(name: string): Awaitable<void>;
|
|
671
|
+
/** End the logical savepoint boundary; adapters may implement this as a no-op when the database releases implicitly. */
|
|
670
672
|
releaseSavepoint?(name: string): Awaitable<void>;
|
|
671
673
|
}
|
|
674
|
+
/** Acquired physical resource. The lease owns release/discard, while runtime owns operation serialization. */
|
|
672
675
|
export interface ConnectionLease extends QueryExecutor {
|
|
673
676
|
release(options?: {
|
|
674
677
|
readonly discard?: boolean;
|
|
675
678
|
}): void | Promise<void>;
|
|
676
679
|
}
|
|
680
|
+
/** Lease factory for pools; acquiring one lease is the boundary that establishes physical connection ownership. */
|
|
677
681
|
export interface ConnectionProvider {
|
|
678
682
|
readonly statementBinding: StatementBindingAdapter;
|
|
679
683
|
readonly environment?: DriverEnvironment;
|
|
680
684
|
validateTransactionOptions?(options: TransactionOptions): void;
|
|
681
685
|
acquire(): Promise<ConnectionLease>;
|
|
682
686
|
}
|
|
687
|
+
//#endregion
|
|
688
|
+
//#region src/observers.d.ts
|
|
689
|
+
/** Immutable observer projection of adapter transport and reuse decisions. */
|
|
683
690
|
export interface QueryExecutionPlan {
|
|
684
691
|
readonly adapterId: string;
|
|
685
692
|
readonly dialectId: string;
|
|
686
693
|
readonly transport: ParameterTransportKind;
|
|
687
694
|
readonly reuse: StatementBindingDescription["reuse"];
|
|
688
695
|
}
|
|
696
|
+
/** Observer event emitted after rendering and binding, before physical execution. */
|
|
689
697
|
export interface QueryReadyEvent {
|
|
690
698
|
readonly type: "query:ready";
|
|
691
699
|
readonly purpose?: "environment";
|
|
@@ -709,6 +717,7 @@ export interface QueryReadyEvent {
|
|
|
709
717
|
readonly transactionDepth: number;
|
|
710
718
|
readonly transactionScoped: boolean;
|
|
711
719
|
}
|
|
720
|
+
/** Observer event emitted after driver materialization and result-kind validation, before mapping. */
|
|
712
721
|
export interface QueryResultEvent {
|
|
713
722
|
readonly type: "query:result";
|
|
714
723
|
readonly purpose?: "environment";
|
|
@@ -725,6 +734,7 @@ export interface QueryResultEvent {
|
|
|
725
734
|
readonly transactionDepth: number;
|
|
726
735
|
readonly transactionScoped: boolean;
|
|
727
736
|
}
|
|
737
|
+
/** Observer event emitted after query-bound and execution-level mapping completes. */
|
|
728
738
|
export interface QueryMappedEvent {
|
|
729
739
|
readonly type: "query:mapped";
|
|
730
740
|
readonly purpose?: "environment";
|
|
@@ -738,6 +748,7 @@ export interface QueryMappedEvent {
|
|
|
738
748
|
readonly transactionDepth: number;
|
|
739
749
|
readonly transactionScoped: boolean;
|
|
740
750
|
}
|
|
751
|
+
/** Observer event emitted after the complete homogeneous bulk is prepared, before physical execution. */
|
|
741
752
|
export interface BulkReadyEvent {
|
|
742
753
|
readonly type: "bulk:ready";
|
|
743
754
|
readonly operationId: string;
|
|
@@ -748,6 +759,7 @@ export interface BulkReadyEvent {
|
|
|
748
759
|
readonly valuesAt: (index: number) => readonly unknown[];
|
|
749
760
|
readonly literalizedSql: (index: number, options?: LiteralizeOptions) => LiteralizedSqlResult;
|
|
750
761
|
}
|
|
762
|
+
/** Observer event emitted after bulk execution and result normalization. */
|
|
751
763
|
export interface BulkResultEvent {
|
|
752
764
|
readonly type: "bulk:result";
|
|
753
765
|
readonly operationId: string;
|
|
@@ -759,6 +771,7 @@ export interface BulkResultEvent {
|
|
|
759
771
|
readonly transactionScoped: boolean;
|
|
760
772
|
}
|
|
761
773
|
export type QueryErrorStage = "render" | "prepared" | "observer-before" | "materialize" | "acquire" | "driver" | "result-kind" | "cardinality" | "query-map" | "execution-map" | "observer-after" | "release" | "stream" | "transaction";
|
|
774
|
+
/** Observer event describing the stage and truthful execution flags for a failed operation. */
|
|
762
775
|
export interface QueryErrorEvent {
|
|
763
776
|
readonly type: "query:error";
|
|
764
777
|
readonly purpose?: "environment";
|
|
@@ -773,6 +786,7 @@ export interface QueryErrorEvent {
|
|
|
773
786
|
readonly transactionDepth: number;
|
|
774
787
|
readonly transactionScoped: boolean;
|
|
775
788
|
}
|
|
789
|
+
/** Observer event emitted when a stream is admitted and its lease is about to be retained. */
|
|
776
790
|
export interface StreamStartEvent {
|
|
777
791
|
readonly type: "stream:start";
|
|
778
792
|
readonly operationId: string;
|
|
@@ -790,115 +804,40 @@ export interface StreamStartEvent {
|
|
|
790
804
|
readonly declaredKind: "rows";
|
|
791
805
|
readonly variantFingerprint?: string;
|
|
792
806
|
readonly preparedName?: string;
|
|
793
|
-
readonly transactionDepth: number;
|
|
794
|
-
readonly transactionScoped: boolean;
|
|
795
|
-
}
|
|
796
|
-
export interface StreamEndEvent {
|
|
797
|
-
readonly type: "stream:end";
|
|
798
|
-
readonly operationId: string;
|
|
799
|
-
readonly status: "completed" | "error";
|
|
800
|
-
readonly durationMs: number;
|
|
801
|
-
readonly rowCount: number;
|
|
802
|
-
readonly error?: unknown;
|
|
803
|
-
readonly transactionDepth: number;
|
|
804
|
-
readonly transactionScoped: boolean;
|
|
805
|
-
}
|
|
806
|
-
export type TransactionEventPhase = "begin" | "commit" | "rollback" | "savepoint" | "rollback-to-savepoint" | "release-savepoint";
|
|
807
|
-
export interface TransactionEvent {
|
|
808
|
-
readonly type: "transaction";
|
|
809
|
-
readonly transactionId: string;
|
|
810
|
-
readonly phase: TransactionEventPhase;
|
|
811
|
-
readonly status: "requested" | "completed" | "failed";
|
|
812
|
-
readonly depth: number;
|
|
813
|
-
readonly savepointName?: string;
|
|
814
|
-
readonly durationMs?: number;
|
|
815
|
-
readonly error?: unknown;
|
|
816
|
-
}
|
|
817
|
-
export type ExecutionEvent = QueryReadyEvent | QueryResultEvent | QueryMappedEvent | BulkReadyEvent | BulkResultEvent | QueryErrorEvent | StreamStartEvent | StreamEndEvent | TransactionEvent;
|
|
818
|
-
export interface ExecutionObserver {
|
|
819
|
-
onEvent(event: ExecutionEvent): void | Promise<void>;
|
|
820
|
-
}
|
|
821
|
-
export interface EnvironmentCapability {
|
|
822
|
-
readonly status: "guaranteed" | "guarded" | "unsupported";
|
|
823
|
-
readonly canonical?: "string" | "number" | "Uint8Array";
|
|
824
|
-
readonly rawRepresentations?: readonly string[];
|
|
825
|
-
readonly conditionCode?: string;
|
|
826
|
-
}
|
|
827
|
-
export interface DatabaseEnvironment {
|
|
828
|
-
readonly database: {
|
|
829
|
-
readonly product: string;
|
|
830
|
-
readonly version?: string;
|
|
831
|
-
readonly edition?: string;
|
|
832
|
-
};
|
|
833
|
-
readonly driver: {
|
|
834
|
-
readonly id: string;
|
|
835
|
-
readonly version?: string;
|
|
836
|
-
readonly profile?: string;
|
|
837
|
-
};
|
|
838
|
-
readonly runtime: {
|
|
839
|
-
readonly id: string;
|
|
840
|
-
readonly version?: string;
|
|
841
|
-
};
|
|
842
|
-
readonly typePolicy?: {
|
|
843
|
-
readonly id: string;
|
|
844
|
-
readonly hash: string;
|
|
845
|
-
};
|
|
846
|
-
readonly capabilities: Readonly<Record<string, EnvironmentCapability>>;
|
|
847
|
-
readonly supportMatch: {
|
|
848
|
-
readonly status: "official" | "conditional" | "compatible";
|
|
849
|
-
readonly targetId?: string;
|
|
850
|
-
readonly reason?: string;
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
/** Adapter evidence only. Probes run through the ordinary observed, leased query path. */
|
|
854
|
-
export interface DriverEnvironment {
|
|
855
|
-
readonly database: DatabaseEnvironment["database"];
|
|
856
|
-
readonly driver: DatabaseEnvironment["driver"];
|
|
857
|
-
readonly typePolicy?: {
|
|
858
|
-
readonly id: string;
|
|
859
|
-
readonly hash: string;
|
|
860
|
-
};
|
|
861
|
-
readonly capabilities: DatabaseEnvironment["capabilities"];
|
|
862
|
-
readonly probe?: {
|
|
863
|
-
readonly statement: RenderedStatement;
|
|
864
|
-
readonly read: (rows: readonly unknown[]) => {
|
|
865
|
-
readonly version?: string;
|
|
866
|
-
readonly edition?: string;
|
|
867
|
-
readonly capabilities?: Readonly<Record<string, EnvironmentCapability>>;
|
|
868
|
-
};
|
|
869
|
-
};
|
|
807
|
+
readonly transactionDepth: number;
|
|
808
|
+
readonly transactionScoped: boolean;
|
|
870
809
|
}
|
|
871
|
-
/**
|
|
872
|
-
export interface
|
|
873
|
-
readonly
|
|
874
|
-
readonly
|
|
875
|
-
readonly
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
readonly
|
|
881
|
-
readonly id: string;
|
|
882
|
-
readonly version: string;
|
|
883
|
-
readonly profile: string;
|
|
884
|
-
};
|
|
885
|
-
readonly runtime: {
|
|
886
|
-
readonly id: string;
|
|
887
|
-
readonly version: string;
|
|
888
|
-
};
|
|
889
|
-
readonly typePolicy: {
|
|
890
|
-
readonly id: string;
|
|
891
|
-
readonly hash: string;
|
|
892
|
-
};
|
|
893
|
-
readonly evidence: {
|
|
894
|
-
readonly status: string;
|
|
895
|
-
};
|
|
810
|
+
/** Terminal stream event; delivery is attempted for every observer even if one observer fails. */
|
|
811
|
+
export interface StreamEndEvent {
|
|
812
|
+
readonly type: "stream:end";
|
|
813
|
+
readonly operationId: string;
|
|
814
|
+
readonly status: "completed" | "error";
|
|
815
|
+
readonly durationMs: number;
|
|
816
|
+
readonly rowCount: number;
|
|
817
|
+
readonly error?: unknown;
|
|
818
|
+
readonly transactionDepth: number;
|
|
819
|
+
readonly transactionScoped: boolean;
|
|
896
820
|
}
|
|
897
|
-
export
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
readonly
|
|
821
|
+
export type TransactionEventPhase = "begin" | "commit" | "rollback" | "savepoint" | "rollback-to-savepoint" | "release-savepoint";
|
|
822
|
+
/** Transaction-control lifecycle event for outer transactions and nested savepoints. */
|
|
823
|
+
export interface TransactionEvent {
|
|
824
|
+
readonly type: "transaction";
|
|
825
|
+
readonly transactionId: string;
|
|
826
|
+
readonly phase: TransactionEventPhase;
|
|
827
|
+
readonly status: "requested" | "completed" | "failed";
|
|
828
|
+
readonly depth: number;
|
|
829
|
+
readonly savepointName?: string;
|
|
830
|
+
readonly durationMs?: number;
|
|
831
|
+
readonly error?: unknown;
|
|
832
|
+
}
|
|
833
|
+
export type ExecutionEvent = QueryReadyEvent | QueryResultEvent | QueryMappedEvent | BulkReadyEvent | BulkResultEvent | QueryErrorEvent | StreamStartEvent | StreamEndEvent | TransactionEvent;
|
|
834
|
+
/** Readonly observer hook. Observers may fail execution, but cannot rewrite SQL, binds, routing, or results. */
|
|
835
|
+
export interface ExecutionObserver {
|
|
836
|
+
onEvent(event: ExecutionEvent): void | Promise<void>;
|
|
901
837
|
}
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/database.d.ts
|
|
840
|
+
/** Root database behavior: observers and default prepared-reuse preference. */
|
|
902
841
|
export interface DatabaseOptions {
|
|
903
842
|
readonly observers?: readonly ExecutionObserver[];
|
|
904
843
|
readonly reuse?: RequestedReuse;
|
|
@@ -910,6 +849,7 @@ export type PreparedFactoryOptions = {
|
|
|
910
849
|
readonly input: "required";
|
|
911
850
|
};
|
|
912
851
|
export type PreparedArguments<Input, Options> = [Input] extends [never] ? [options?: Options] : [input: Input, options?: Options];
|
|
852
|
+
/** Prepared handle whose input arity and result helpers are fixed by the factory's query kind. */
|
|
913
853
|
export type PreparedQuery<Input, Q extends PreparableQuery> = {
|
|
914
854
|
readonly name: string;
|
|
915
855
|
} & (Q extends CallQuery<infer Result> ? {
|
|
@@ -924,15 +864,29 @@ export type PreparedQuery<Input, Q extends PreparableQuery> = {
|
|
|
924
864
|
} : {}));
|
|
925
865
|
export type ExecutableQuery = RowQuery<unknown> | Query<unknown, "command"> | Query<unknown, "unknown">;
|
|
926
866
|
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;
|
|
867
|
+
/**
|
|
868
|
+
* Async application database surface.
|
|
869
|
+
* Root pooled operations acquire/release per operation; `session()` and `tx()` callbacks pin a scoped resource.
|
|
870
|
+
* Scoped handles expire when their callback returns, and streams must close before a scope can finish.
|
|
871
|
+
*/
|
|
927
872
|
export interface Database {
|
|
873
|
+
/** Observe database/driver/runtime evidence and optionally match it against exact support targets. */
|
|
928
874
|
environment(options?: EnvironmentOptions): Promise<DatabaseEnvironment>;
|
|
875
|
+
/** Materialize every row and apply query/execution mapping after the root lease is released. */
|
|
929
876
|
all<Row>(query: RowQuery<Row>, options?: RowValidationOptions<Row>): Promise<readonly Row[]>;
|
|
877
|
+
/** Require exactly one row; cardinality is checked before application mapping. */
|
|
930
878
|
one<Row>(query: RowQuery<Row>, options?: RowValidationOptions<Row>): Promise<Row>;
|
|
879
|
+
/** Return `undefined` for zero rows and reject when more than one row is returned. */
|
|
931
880
|
maybeOne<Row>(query: RowQuery<Row>, options?: RowValidationOptions<Row>): Promise<Row | undefined>;
|
|
881
|
+
/** Execute a row, command, or unknown query and preserve its normalized result kind. */
|
|
932
882
|
execute<Q extends ExecutableQuery>(query: Q, options?: ExecutionOptions): Promise<ExecutionResultOf<Q>>;
|
|
883
|
+
/** Execute a routine query and materialize all normalized routine channels before mapping. */
|
|
933
884
|
call<Result extends RoutineCallResult>(query: CallQuery<Result>, options?: ExecutionOptions): Promise<Result>;
|
|
885
|
+
/** Execute different queries sequentially on one physical use/lease. This is not an implicit transaction. */
|
|
934
886
|
batch<const Queries extends readonly ExecutableQuery[]>(queries: Queries, options?: ExecutionOptions): Promise<{ readonly [K in keyof Queries]: ExecutionResultOf<Queries[K]>; }>;
|
|
887
|
+
/** Execute one homogeneous command shape for many inputs using the adapter's bulk strategy. */
|
|
935
888
|
bulk<Input>(inputs: readonly Input[], factory: (input: Input, index: number) => CommandQuery, options?: ExecutionOptions): Promise<BulkResult>;
|
|
889
|
+
/** Create a prepared handle whose first successful execution locks the logical SQLBraid shape. */
|
|
936
890
|
prepare<Factory extends () => PreparableQuery>(name: string, factory: Factory & (Parameters<Factory> extends [] ? unknown : never), options: {
|
|
937
891
|
readonly input: "none";
|
|
938
892
|
}): PreparedQuery<never, ReturnType<Factory>>;
|
|
@@ -940,47 +894,260 @@ export interface Database {
|
|
|
940
894
|
prepare<Factory extends (input: never) => PreparableQuery>(name: string, factory: Factory & (number extends Parameters<Factory>["length"] ? unknown : Parameters<Factory>["length"] extends 0 | 1 ? unknown : never), options: {
|
|
941
895
|
readonly input: "required";
|
|
942
896
|
}): PreparedQuery<Parameters<Factory>[0], ReturnType<Factory>>;
|
|
897
|
+
/** Stream rows without full buffering; the physical resource remains pinned until iteration closes. */
|
|
943
898
|
stream<Row>(query: RowQuery<Row>, options?: StreamOptions<Row>): AsyncIterable<Row>;
|
|
899
|
+
/** Pin one physical resource for the callback without implicitly starting a transaction. */
|
|
944
900
|
session<T>(callback: (database: Database) => Promise<T>): Promise<T>;
|
|
901
|
+
/** Run the callback in one physical transaction; nested calls use savepoints on the same resource. */
|
|
945
902
|
tx<T>(callback: (database: Database) => Promise<T>): Promise<T>;
|
|
946
903
|
tx<T>(options: TransactionOptions, callback: (database: Database) => Promise<T>): Promise<T>;
|
|
947
904
|
}
|
|
905
|
+
/** Normalized bulk accounting; root bulk is not implicitly transactional. */
|
|
948
906
|
export interface BulkResult {
|
|
949
907
|
readonly inputCount: number;
|
|
950
908
|
readonly affectedRows?: number;
|
|
951
909
|
}
|
|
952
910
|
export type QueryRow<Q> = Q extends Query<infer Row, QueryResultKind> ? Row : never;
|
|
911
|
+
//#endregion
|
|
912
|
+
//#region src/authoring.d.ts
|
|
913
|
+
/** Generic SQL tag shape used by configured dialect/query-kind specializations. */
|
|
953
914
|
export interface SqlTagLike<Kind extends QueryResultKind = QueryResultKind, Row = unknown> {
|
|
954
915
|
(strings: TemplateStringsArray, ...values: readonly unknown[]): Query<Row, Kind>;
|
|
955
916
|
}
|
|
956
917
|
export interface RoutineContractTag<Contract extends RoutineContract> {
|
|
957
918
|
(strings: TemplateStringsArray, ...values: readonly unknown[]): CallQuery<RoutineResultFromContract<Contract>>;
|
|
958
919
|
}
|
|
920
|
+
/** Row-specialized tag supporting either a TypeScript row type or a Standard Schema mapper. */
|
|
959
921
|
export interface RowsTag {
|
|
960
922
|
<Input, Output>(schema: StandardSchemaV1$1<Input, Output>): SqlTagLike<"rows", Output>;
|
|
961
923
|
<Row = unknown>(strings: TemplateStringsArray, ...values: readonly unknown[]): RowQuery<Row>;
|
|
962
924
|
}
|
|
925
|
+
/**
|
|
926
|
+
* SQL authoring surface. Values are bound by default; `ident`, `fragment`, `list`, `join`, and `raw` are explicit structure.
|
|
927
|
+
*/
|
|
963
928
|
export interface SqlTag extends SqlTagLike<"unknown"> {
|
|
929
|
+
/** Declare a row-producing query, optionally with query-bound Standard Schema mapping. */
|
|
964
930
|
rows: RowsTag;
|
|
931
|
+
/** Declare a command query that must normalize to command metadata. */
|
|
965
932
|
command: (strings: TemplateStringsArray, ...values: readonly unknown[]) => CommandQuery;
|
|
933
|
+
/** Declare a routine query, optionally with explicit output/result-set/return mapping contracts. */
|
|
966
934
|
call: {
|
|
967
935
|
<Result extends RoutineCallResult = RoutineCallResult>(strings: TemplateStringsArray, ...values: readonly unknown[]): CallQuery<Result>;
|
|
968
936
|
<Contract extends RoutineContract>(contract: Contract): RoutineContractTag<Contract>;
|
|
969
937
|
};
|
|
938
|
+
/** Attach explicit database parameter metadata without turning the value into SQL structure. */
|
|
970
939
|
bind<Input>(value: NoInfer<Input>, hint: ParameterTypeHint<Input>): BoundParameter<Input>;
|
|
940
|
+
/** Declare a routine OUT parameter owned by the adapter. */
|
|
971
941
|
out(name: string, hint?: ParameterTypeHint): RoutineParameter<null>;
|
|
942
|
+
/** Declare a routine INOUT parameter owned by the adapter. */
|
|
972
943
|
inOut<Input>(name: string, value: NoInfer<Input>, hint?: ParameterTypeHint<Input>): RoutineParameter<Input>;
|
|
944
|
+
/** Create explicit SQL structure while preserving ordinary interpolations as values. */
|
|
973
945
|
fragment: (strings: TemplateStringsArray, ...values: readonly unknown[]) => SqlFragment;
|
|
946
|
+
/** Empty structural fragment for conditional composition. */
|
|
974
947
|
empty: SqlFragment;
|
|
948
|
+
/** Create a dialect-quoted identifier or qualified identifier path. */
|
|
975
949
|
ident: (identifier: string | readonly string[]) => SqlFragment;
|
|
950
|
+
/** Insert verbatim SQL structure. Never pass user-controlled or otherwise untrusted text. */
|
|
976
951
|
raw: (text: string) => SqlFragment;
|
|
952
|
+
/** Join already-structural fragments with a structural separator. */
|
|
977
953
|
join: (items: readonly SqlFragment[], separator?: SqlFragment) => SqlFragment;
|
|
954
|
+
/** Expand an array as a structural comma-separated list of value binds. */
|
|
978
955
|
list: (values: readonly unknown[]) => SqlFragment;
|
|
979
956
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
957
|
+
//#endregion
|
|
958
|
+
//#region src/authoring-modules.d.ts
|
|
959
|
+
/** Data-only authoring identity shared by compiler, tooling, and editor consumers. */
|
|
960
|
+
type AuthoringModuleCatalogEntry = {
|
|
961
|
+
readonly moduleSpecifier: string;
|
|
962
|
+
readonly dialectId?: "postgres" | "mysql" | "mariadb" | "sqlite" | "oracle" | "mssql";
|
|
963
|
+
readonly helperFamily: "template" | "facade";
|
|
964
|
+
};
|
|
965
|
+
export declare const AUTHORING_MODULE_CATALOG: readonly AuthoringModuleCatalogEntry[];
|
|
966
|
+
//#endregion
|
|
967
|
+
//#region src/capabilities.d.ts
|
|
968
|
+
/**
|
|
969
|
+
* The machine-readable capability vocabulary shared by adapters, support data,
|
|
970
|
+
* and documentation. A capability's family describes what its status proves;
|
|
971
|
+
* representation and metadata evidence are not execution support aliases.
|
|
972
|
+
*/
|
|
973
|
+
type CapabilityFamily = "support" | "representation" | "metadata";
|
|
974
|
+
interface WellKnownCapability {
|
|
975
|
+
readonly id: string;
|
|
976
|
+
readonly family: CapabilityFamily;
|
|
983
977
|
}
|
|
978
|
+
declare const definitions: readonly [{
|
|
979
|
+
readonly id: "sql.native-transparency";
|
|
980
|
+
readonly family: "support";
|
|
981
|
+
}, {
|
|
982
|
+
readonly id: "sql.generated-structure";
|
|
983
|
+
readonly family: "support";
|
|
984
|
+
}, {
|
|
985
|
+
readonly id: "result.rows";
|
|
986
|
+
readonly family: "support";
|
|
987
|
+
}, {
|
|
988
|
+
readonly id: "result.command";
|
|
989
|
+
readonly family: "support";
|
|
990
|
+
}, {
|
|
991
|
+
readonly id: "result.multiple-sets";
|
|
992
|
+
readonly family: "support";
|
|
993
|
+
}, {
|
|
994
|
+
readonly id: "result.standard-schema";
|
|
995
|
+
readonly family: "support";
|
|
996
|
+
}, {
|
|
997
|
+
readonly id: "numeric.exact-integer";
|
|
998
|
+
readonly family: "representation";
|
|
999
|
+
}, {
|
|
1000
|
+
readonly id: "numeric.exact-decimal";
|
|
1001
|
+
readonly family: "representation";
|
|
1002
|
+
}, {
|
|
1003
|
+
readonly id: "numeric.approximate-float";
|
|
1004
|
+
readonly family: "representation";
|
|
1005
|
+
}, {
|
|
1006
|
+
readonly id: "numeric.approximate-special";
|
|
1007
|
+
readonly family: "representation";
|
|
1008
|
+
}, {
|
|
1009
|
+
readonly id: "numeric.bind-exact";
|
|
1010
|
+
readonly family: "representation";
|
|
1011
|
+
}, {
|
|
1012
|
+
readonly id: "numeric.aggregate";
|
|
1013
|
+
readonly family: "representation";
|
|
1014
|
+
}, {
|
|
1015
|
+
readonly id: "numeric.command-metadata";
|
|
1016
|
+
readonly family: "representation";
|
|
1017
|
+
}, {
|
|
1018
|
+
readonly id: "numeric.special-values";
|
|
1019
|
+
readonly family: "representation";
|
|
1020
|
+
}, {
|
|
1021
|
+
readonly id: "numeric.scale-greater-than-precision";
|
|
1022
|
+
readonly family: "representation";
|
|
1023
|
+
}, {
|
|
1024
|
+
readonly id: "numeric.negative-scale";
|
|
1025
|
+
readonly family: "representation";
|
|
1026
|
+
}, {
|
|
1027
|
+
readonly id: "data.json-parsed";
|
|
1028
|
+
readonly family: "representation";
|
|
1029
|
+
}, {
|
|
1030
|
+
readonly id: "data.json-lossless-text";
|
|
1031
|
+
readonly family: "representation";
|
|
1032
|
+
}, {
|
|
1033
|
+
readonly id: "data.sql-variant";
|
|
1034
|
+
readonly family: "representation";
|
|
1035
|
+
}, {
|
|
1036
|
+
readonly id: "data.oracle-object";
|
|
1037
|
+
readonly family: "representation";
|
|
1038
|
+
}, {
|
|
1039
|
+
readonly id: "data.oracle-collection";
|
|
1040
|
+
readonly family: "representation";
|
|
1041
|
+
}, {
|
|
1042
|
+
readonly id: "data.vector";
|
|
1043
|
+
readonly family: "representation";
|
|
1044
|
+
}, {
|
|
1045
|
+
readonly id: "data.binary";
|
|
1046
|
+
readonly family: "representation";
|
|
1047
|
+
}, {
|
|
1048
|
+
readonly id: "data.uuid";
|
|
1049
|
+
readonly family: "representation";
|
|
1050
|
+
}, {
|
|
1051
|
+
readonly id: "data.temporal-native";
|
|
1052
|
+
readonly family: "representation";
|
|
1053
|
+
}, {
|
|
1054
|
+
readonly id: "data.temporal-lossless";
|
|
1055
|
+
readonly family: "representation";
|
|
1056
|
+
}, {
|
|
1057
|
+
readonly id: "data.timezone";
|
|
1058
|
+
readonly family: "representation";
|
|
1059
|
+
}, {
|
|
1060
|
+
readonly id: "metadata.command-safe";
|
|
1061
|
+
readonly family: "metadata";
|
|
1062
|
+
}, {
|
|
1063
|
+
readonly id: "dml.insert-returning";
|
|
1064
|
+
readonly family: "support";
|
|
1065
|
+
}, {
|
|
1066
|
+
readonly id: "dml.update-returning";
|
|
1067
|
+
readonly family: "support";
|
|
1068
|
+
}, {
|
|
1069
|
+
readonly id: "dml.delete-returning";
|
|
1070
|
+
readonly family: "support";
|
|
1071
|
+
}, {
|
|
1072
|
+
readonly id: "dml.merge-returning";
|
|
1073
|
+
readonly family: "support";
|
|
1074
|
+
}, {
|
|
1075
|
+
readonly id: "dml.upsert-returning";
|
|
1076
|
+
readonly family: "support";
|
|
1077
|
+
}, {
|
|
1078
|
+
readonly id: "session.pinned";
|
|
1079
|
+
readonly family: "support";
|
|
1080
|
+
}, {
|
|
1081
|
+
readonly id: "statement.prepare";
|
|
1082
|
+
readonly family: "support";
|
|
1083
|
+
}, {
|
|
1084
|
+
readonly id: "statement.cancel";
|
|
1085
|
+
readonly family: "support";
|
|
1086
|
+
}, {
|
|
1087
|
+
readonly id: "statement.stream";
|
|
1088
|
+
readonly family: "support";
|
|
1089
|
+
}, {
|
|
1090
|
+
readonly id: "statement.bulk";
|
|
1091
|
+
readonly family: "support";
|
|
1092
|
+
}, {
|
|
1093
|
+
readonly id: "execution.bulk-fidelity";
|
|
1094
|
+
readonly family: "support";
|
|
1095
|
+
}, {
|
|
1096
|
+
readonly id: "transaction";
|
|
1097
|
+
readonly family: "support";
|
|
1098
|
+
}, {
|
|
1099
|
+
readonly id: "transaction.savepoint";
|
|
1100
|
+
readonly family: "support";
|
|
1101
|
+
}, {
|
|
1102
|
+
readonly id: "transaction.read-only";
|
|
1103
|
+
readonly family: "support";
|
|
1104
|
+
}, {
|
|
1105
|
+
readonly id: "transaction.isolation.read-uncommitted";
|
|
1106
|
+
readonly family: "support";
|
|
1107
|
+
}, {
|
|
1108
|
+
readonly id: "transaction.isolation.read-committed";
|
|
1109
|
+
readonly family: "support";
|
|
1110
|
+
}, {
|
|
1111
|
+
readonly id: "transaction.isolation.repeatable-read";
|
|
1112
|
+
readonly family: "support";
|
|
1113
|
+
}, {
|
|
1114
|
+
readonly id: "transaction.isolation.serializable";
|
|
1115
|
+
readonly family: "support";
|
|
1116
|
+
}, {
|
|
1117
|
+
readonly id: "routine.call";
|
|
1118
|
+
readonly family: "support";
|
|
1119
|
+
}, {
|
|
1120
|
+
readonly id: "routine.out";
|
|
1121
|
+
readonly family: "support";
|
|
1122
|
+
}, {
|
|
1123
|
+
readonly id: "routine.inout";
|
|
1124
|
+
readonly family: "support";
|
|
1125
|
+
}, {
|
|
1126
|
+
readonly id: "routine.result-sets";
|
|
1127
|
+
readonly family: "support";
|
|
1128
|
+
}, {
|
|
1129
|
+
readonly id: "routine.out-cursor";
|
|
1130
|
+
readonly family: "support";
|
|
1131
|
+
}, {
|
|
1132
|
+
readonly id: "routine.return-value";
|
|
1133
|
+
readonly family: "support";
|
|
1134
|
+
}, {
|
|
1135
|
+
readonly id: "metadata.identity";
|
|
1136
|
+
readonly family: "metadata";
|
|
1137
|
+
}, {
|
|
1138
|
+
readonly id: "metadata.generated";
|
|
1139
|
+
readonly family: "metadata";
|
|
1140
|
+
}, {
|
|
1141
|
+
readonly id: "metadata.routines";
|
|
1142
|
+
readonly family: "metadata";
|
|
1143
|
+
}, {
|
|
1144
|
+
readonly id: "metadata.types";
|
|
1145
|
+
readonly family: "metadata";
|
|
1146
|
+
}];
|
|
1147
|
+
export declare const WELL_KNOWN_CAPABILITIES: readonly WellKnownCapability[];
|
|
1148
|
+
type WellKnownCapabilityId = (typeof definitions)[number]["id"];
|
|
1149
|
+
export declare const WELL_KNOWN_CAPABILITY_IDS: readonly WellKnownCapabilityId[];
|
|
1150
|
+
export declare function isWellKnownCapabilityId(value: string): value is WellKnownCapabilityId;
|
|
984
1151
|
//#endregion
|
|
985
1152
|
export type { AuthoringModuleCatalogEntry, CapabilityFamily, StandardSchemaV1, WellKnownCapability, WellKnownCapabilityId };
|
|
986
1153
|
//# sourceMappingURL=index.d.ts.map
|