@prisma-next/runtime-executor 0.3.0-dev.4 → 0.3.0-dev.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +180 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +599 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +25 -17
- package/src/async-iterable-result.ts +78 -0
- package/src/errors.ts +39 -0
- package/src/exports/index.ts +31 -0
- package/src/fingerprint.ts +14 -0
- package/src/guardrails/raw.ts +204 -0
- package/src/index.ts +1 -0
- package/src/marker.ts +85 -0
- package/src/plugins/budgets.ts +328 -0
- package/src/plugins/lints.ts +85 -0
- package/src/plugins/types.ts +42 -0
- package/src/runtime-core.ts +362 -0
- package/src/runtime-spi.ts +16 -0
- package/dist/index.d.ts +0 -157
- package/dist/index.js +0 -746
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
+
import type { OperationRegistry } from '@prisma-next/operations';
|
|
3
|
+
import { AsyncIterableResult } from './async-iterable-result';
|
|
4
|
+
import { runtimeError } from './errors';
|
|
5
|
+
import { computeSqlFingerprint } from './fingerprint';
|
|
6
|
+
import { parseContractMarkerRow } from './marker';
|
|
7
|
+
import type { Log, Plugin, PluginContext } from './plugins/types';
|
|
8
|
+
import type { RuntimeFamilyAdapter } from './runtime-spi';
|
|
9
|
+
|
|
10
|
+
export interface RuntimeVerifyOptions {
|
|
11
|
+
readonly mode: 'onFirstUse' | 'startup' | 'always';
|
|
12
|
+
readonly requireMarker: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type TelemetryOutcome = 'success' | 'runtime-error';
|
|
16
|
+
|
|
17
|
+
export interface RuntimeTelemetryEvent {
|
|
18
|
+
readonly lane: string;
|
|
19
|
+
readonly target: string;
|
|
20
|
+
readonly fingerprint: string;
|
|
21
|
+
readonly outcome: TelemetryOutcome;
|
|
22
|
+
readonly durationMs?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RuntimeCoreOptions<TContract = unknown, TAdapter = unknown, TDriver = unknown> {
|
|
26
|
+
readonly familyAdapter: RuntimeFamilyAdapter<TContract>;
|
|
27
|
+
readonly driver: TDriver;
|
|
28
|
+
readonly verify: RuntimeVerifyOptions;
|
|
29
|
+
readonly plugins?: readonly Plugin<TContract, TAdapter, TDriver>[];
|
|
30
|
+
readonly mode?: 'strict' | 'permissive';
|
|
31
|
+
readonly log?: Log;
|
|
32
|
+
readonly operationRegistry: OperationRegistry;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RuntimeCore<TContract = unknown, TAdapter = unknown, TDriver = unknown>
|
|
36
|
+
extends RuntimeQueryable {
|
|
37
|
+
// Type parameters are used in the implementation for type safety
|
|
38
|
+
readonly _typeContract?: TContract;
|
|
39
|
+
readonly _typeAdapter?: TAdapter;
|
|
40
|
+
readonly _typeDriver?: TDriver;
|
|
41
|
+
connection(): Promise<RuntimeConnection>;
|
|
42
|
+
telemetry(): RuntimeTelemetryEvent | null;
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
operations(): OperationRegistry;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface RuntimeConnection extends RuntimeQueryable {
|
|
48
|
+
transaction(): Promise<RuntimeTransaction>;
|
|
49
|
+
release(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface RuntimeTransaction extends RuntimeQueryable {
|
|
53
|
+
commit(): Promise<void>;
|
|
54
|
+
rollback(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface RuntimeQueryable {
|
|
58
|
+
execute<Row = Record<string, unknown>>(plan: ExecutionPlan<Row>): AsyncIterableResult<Row>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface DriverWithQuery<_TDriver> {
|
|
62
|
+
query(sql: string, params: readonly unknown[]): Promise<{ rows: ReadonlyArray<unknown> }>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface DriverWithConnection<_TDriver> {
|
|
66
|
+
acquireConnection(): Promise<DriverConnection>;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface DriverConnection extends Queryable {
|
|
70
|
+
beginTransaction(): Promise<DriverTransaction>;
|
|
71
|
+
release(): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface DriverTransaction extends Queryable {
|
|
75
|
+
commit(): Promise<void>;
|
|
76
|
+
rollback(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface Queryable {
|
|
80
|
+
execute<Row = Record<string, unknown>>(options: {
|
|
81
|
+
sql: string;
|
|
82
|
+
params: readonly unknown[];
|
|
83
|
+
}): AsyncIterable<Row>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface DriverWithClose<_TDriver> {
|
|
87
|
+
close(): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
class RuntimeCoreImpl<TContract = unknown, TAdapter = unknown, TDriver = unknown>
|
|
91
|
+
implements RuntimeCore<TContract, TAdapter, TDriver>
|
|
92
|
+
{
|
|
93
|
+
readonly _typeContract?: TContract;
|
|
94
|
+
readonly _typeAdapter?: TAdapter;
|
|
95
|
+
readonly _typeDriver?: TDriver;
|
|
96
|
+
private readonly contract: TContract;
|
|
97
|
+
private readonly familyAdapter: RuntimeFamilyAdapter<TContract>;
|
|
98
|
+
private readonly driver: TDriver;
|
|
99
|
+
private readonly plugins: readonly Plugin<TContract, TAdapter, TDriver>[];
|
|
100
|
+
private readonly mode: 'strict' | 'permissive';
|
|
101
|
+
private readonly verify: RuntimeVerifyOptions;
|
|
102
|
+
private readonly operationRegistry: OperationRegistry;
|
|
103
|
+
private readonly pluginContext: PluginContext<TContract, TAdapter, TDriver>;
|
|
104
|
+
|
|
105
|
+
private verified: boolean;
|
|
106
|
+
private startupVerified: boolean;
|
|
107
|
+
private _telemetry: RuntimeTelemetryEvent | null;
|
|
108
|
+
|
|
109
|
+
constructor(options: RuntimeCoreOptions<TContract, TAdapter, TDriver>) {
|
|
110
|
+
const { familyAdapter, driver } = options;
|
|
111
|
+
this.contract = familyAdapter.contract;
|
|
112
|
+
this.familyAdapter = familyAdapter;
|
|
113
|
+
this.driver = driver;
|
|
114
|
+
this.plugins = options.plugins ?? [];
|
|
115
|
+
this.mode = options.mode ?? 'strict';
|
|
116
|
+
this.verify = options.verify;
|
|
117
|
+
this.operationRegistry = options.operationRegistry;
|
|
118
|
+
|
|
119
|
+
this.verified = options.verify.mode === 'startup' ? false : options.verify.mode === 'always';
|
|
120
|
+
this.startupVerified = false;
|
|
121
|
+
this._telemetry = null;
|
|
122
|
+
|
|
123
|
+
this.pluginContext = {
|
|
124
|
+
contract: this.contract,
|
|
125
|
+
adapter: options.familyAdapter as unknown as TAdapter,
|
|
126
|
+
driver: this.driver,
|
|
127
|
+
mode: this.mode,
|
|
128
|
+
now: () => Date.now(),
|
|
129
|
+
log: options.log ?? {
|
|
130
|
+
info: () => {
|
|
131
|
+
// No-op in MVP - diagnostics stay out of runtime core
|
|
132
|
+
},
|
|
133
|
+
warn: () => {
|
|
134
|
+
// No-op in MVP - diagnostics stay out of runtime core
|
|
135
|
+
},
|
|
136
|
+
error: () => {
|
|
137
|
+
// No-op in MVP - diagnostics stay out of runtime core
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private async verifyPlanIfNeeded(_plan: ExecutionPlan): Promise<void> {
|
|
144
|
+
void _plan;
|
|
145
|
+
if (this.verify.mode === 'always') {
|
|
146
|
+
this.verified = false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (this.verified) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const readStatement = this.familyAdapter.markerReader.readMarkerStatement();
|
|
154
|
+
const driver = this.driver as unknown as DriverWithQuery<TDriver>;
|
|
155
|
+
const result = await driver.query(readStatement.sql, readStatement.params);
|
|
156
|
+
|
|
157
|
+
if (result.rows.length === 0) {
|
|
158
|
+
if (this.verify.requireMarker) {
|
|
159
|
+
throw runtimeError('CONTRACT.MARKER_MISSING', 'Contract marker not found in database');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.verified = true;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const marker = parseContractMarkerRow(result.rows[0]);
|
|
167
|
+
|
|
168
|
+
const contract = this.contract as {
|
|
169
|
+
storageHash: string;
|
|
170
|
+
executionHash?: string | null;
|
|
171
|
+
profileHash?: string | null;
|
|
172
|
+
};
|
|
173
|
+
if (marker.storageHash !== contract.storageHash) {
|
|
174
|
+
throw runtimeError(
|
|
175
|
+
'CONTRACT.MARKER_MISMATCH',
|
|
176
|
+
'Database storage hash does not match contract',
|
|
177
|
+
{
|
|
178
|
+
expected: contract.storageHash,
|
|
179
|
+
actual: marker.storageHash,
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const expectedProfile = contract.profileHash ?? null;
|
|
185
|
+
if (expectedProfile !== null && marker.profileHash !== expectedProfile) {
|
|
186
|
+
throw runtimeError(
|
|
187
|
+
'CONTRACT.MARKER_MISMATCH',
|
|
188
|
+
'Database profile hash does not match contract',
|
|
189
|
+
{
|
|
190
|
+
expectedProfile,
|
|
191
|
+
actualProfile: marker.profileHash,
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
this.verified = true;
|
|
197
|
+
this.startupVerified = true;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private validatePlan(plan: ExecutionPlan): void {
|
|
201
|
+
this.familyAdapter.validatePlan(plan, this.contract);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private recordTelemetry(
|
|
205
|
+
plan: ExecutionPlan,
|
|
206
|
+
outcome: TelemetryOutcome,
|
|
207
|
+
durationMs?: number,
|
|
208
|
+
): void {
|
|
209
|
+
const contract = this.contract as { target: string };
|
|
210
|
+
this._telemetry = Object.freeze({
|
|
211
|
+
lane: plan.meta.lane,
|
|
212
|
+
target: contract.target,
|
|
213
|
+
fingerprint: computeSqlFingerprint(plan.sql),
|
|
214
|
+
outcome,
|
|
215
|
+
...(durationMs !== undefined ? { durationMs } : {}),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
execute<Row = Record<string, unknown>>(plan: ExecutionPlan<Row>): AsyncIterableResult<Row> {
|
|
220
|
+
return this.#executeWith(plan, this.driver as Queryable);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async connection(): Promise<RuntimeConnection> {
|
|
224
|
+
const driver = this.driver as unknown as DriverWithConnection<TDriver>;
|
|
225
|
+
const driverConn = await driver.acquireConnection();
|
|
226
|
+
const self = this;
|
|
227
|
+
|
|
228
|
+
const runtimeConnection: RuntimeConnection = {
|
|
229
|
+
async transaction(): Promise<RuntimeTransaction> {
|
|
230
|
+
const driverTx = await driverConn.beginTransaction();
|
|
231
|
+
const runtimeTx: RuntimeTransaction = {
|
|
232
|
+
async commit(): Promise<void> {
|
|
233
|
+
await driverTx.commit();
|
|
234
|
+
},
|
|
235
|
+
async rollback(): Promise<void> {
|
|
236
|
+
await driverTx.rollback();
|
|
237
|
+
},
|
|
238
|
+
execute<Row = Record<string, unknown>>(
|
|
239
|
+
plan: ExecutionPlan<Row>,
|
|
240
|
+
): AsyncIterableResult<Row> {
|
|
241
|
+
return self.#executeWith(plan, driverTx);
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
return runtimeTx;
|
|
245
|
+
},
|
|
246
|
+
execute<Row = Record<string, unknown>>(plan: ExecutionPlan<Row>): AsyncIterableResult<Row> {
|
|
247
|
+
return self.#executeWith(plan, driverConn);
|
|
248
|
+
},
|
|
249
|
+
async release(): Promise<void> {
|
|
250
|
+
await driverConn.release();
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
return runtimeConnection;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
telemetry(): RuntimeTelemetryEvent | null {
|
|
258
|
+
return this._telemetry;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
operations(): OperationRegistry {
|
|
262
|
+
return this.operationRegistry;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
close(): Promise<void> {
|
|
266
|
+
const driver = this.driver as unknown as DriverWithClose<TDriver>;
|
|
267
|
+
if (typeof driver.close === 'function') {
|
|
268
|
+
return driver.close();
|
|
269
|
+
}
|
|
270
|
+
return Promise.resolve();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
#executeWith<Row = Record<string, unknown>>(
|
|
274
|
+
plan: ExecutionPlan<Row>,
|
|
275
|
+
queryable: Queryable,
|
|
276
|
+
): AsyncIterableResult<Row> {
|
|
277
|
+
this.validatePlan(plan);
|
|
278
|
+
this._telemetry = null;
|
|
279
|
+
|
|
280
|
+
const iterator = async function* (
|
|
281
|
+
self: RuntimeCoreImpl<TContract, TAdapter, TDriver>,
|
|
282
|
+
): AsyncGenerator<Row, void, unknown> {
|
|
283
|
+
const startedAt = Date.now();
|
|
284
|
+
let rowCount = 0;
|
|
285
|
+
let completed = false;
|
|
286
|
+
|
|
287
|
+
if (!self.startupVerified && self.verify.mode === 'startup') {
|
|
288
|
+
await self.verifyPlanIfNeeded(plan);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (self.verify.mode === 'onFirstUse') {
|
|
292
|
+
await self.verifyPlanIfNeeded(plan);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
if (self.verify.mode === 'always') {
|
|
297
|
+
await self.verifyPlanIfNeeded(plan);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
for (const plugin of self.plugins) {
|
|
301
|
+
if (plugin.beforeExecute) {
|
|
302
|
+
await plugin.beforeExecute(plan, self.pluginContext);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const encodedParams = plan.params;
|
|
307
|
+
|
|
308
|
+
for await (const row of queryable.execute<Record<string, unknown>>({
|
|
309
|
+
sql: plan.sql,
|
|
310
|
+
params: encodedParams,
|
|
311
|
+
})) {
|
|
312
|
+
for (const plugin of self.plugins) {
|
|
313
|
+
if (plugin.onRow) {
|
|
314
|
+
await plugin.onRow(row, plan, self.pluginContext);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
rowCount++;
|
|
318
|
+
yield row as Row;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
completed = true;
|
|
322
|
+
self.recordTelemetry(plan, 'success', Date.now() - startedAt);
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (self._telemetry === null) {
|
|
325
|
+
self.recordTelemetry(plan, 'runtime-error', Date.now() - startedAt);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const latencyMs = Date.now() - startedAt;
|
|
329
|
+
for (const plugin of self.plugins) {
|
|
330
|
+
if (plugin.afterExecute) {
|
|
331
|
+
try {
|
|
332
|
+
await plugin.afterExecute(
|
|
333
|
+
plan,
|
|
334
|
+
{ rowCount, latencyMs, completed },
|
|
335
|
+
self.pluginContext,
|
|
336
|
+
);
|
|
337
|
+
} catch {
|
|
338
|
+
// Ignore errors from afterExecute hooks
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
throw error;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const latencyMs = Date.now() - startedAt;
|
|
347
|
+
for (const plugin of self.plugins) {
|
|
348
|
+
if (plugin.afterExecute) {
|
|
349
|
+
await plugin.afterExecute(plan, { rowCount, latencyMs, completed }, self.pluginContext);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
return new AsyncIterableResult(iterator(this));
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function createRuntimeCore<TContract = unknown, TAdapter = unknown, TDriver = unknown>(
|
|
359
|
+
options: RuntimeCoreOptions<TContract, TAdapter, TDriver>,
|
|
360
|
+
): RuntimeCore<TContract, TAdapter, TDriver> {
|
|
361
|
+
return new RuntimeCoreImpl(options);
|
|
362
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
+
|
|
3
|
+
export interface MarkerStatement {
|
|
4
|
+
readonly sql: string;
|
|
5
|
+
readonly params: readonly unknown[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface MarkerReader {
|
|
9
|
+
readMarkerStatement(): MarkerStatement;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface RuntimeFamilyAdapter<TContract = unknown> {
|
|
13
|
+
readonly contract: TContract;
|
|
14
|
+
readonly markerReader: MarkerReader;
|
|
15
|
+
validatePlan(plan: ExecutionPlan, contract: TContract): void;
|
|
16
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { ExecutionPlan, ContractMarkerRecord } from '@prisma-next/contract/types';
|
|
2
|
-
export { ContractMarkerRecord } from '@prisma-next/contract/types';
|
|
3
|
-
import { OperationRegistry } from '@prisma-next/operations';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Custom async iterable result that extends AsyncIterable with a toArray() method.
|
|
7
|
-
* This provides a convenient way to collect all results from an async iterator.
|
|
8
|
-
*/
|
|
9
|
-
declare class AsyncIterableResult<Row> implements AsyncIterable<Row> {
|
|
10
|
-
private readonly generator;
|
|
11
|
-
private consumed;
|
|
12
|
-
private consumedBy;
|
|
13
|
-
constructor(generator: AsyncGenerator<Row, void, unknown>);
|
|
14
|
-
[Symbol.asyncIterator](): AsyncIterator<Row>;
|
|
15
|
-
/**
|
|
16
|
-
* Collects all values from the async iterator into an array.
|
|
17
|
-
* Once called, the iterator is consumed and cannot be reused.
|
|
18
|
-
*/
|
|
19
|
-
toArray(): Promise<Row[]>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface RuntimeErrorEnvelope extends Error {
|
|
23
|
-
readonly code: string;
|
|
24
|
-
readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';
|
|
25
|
-
readonly severity: 'error';
|
|
26
|
-
readonly details?: Record<string, unknown>;
|
|
27
|
-
}
|
|
28
|
-
declare function runtimeError(code: string, message: string, details?: Record<string, unknown>): RuntimeErrorEnvelope;
|
|
29
|
-
|
|
30
|
-
declare function computeSqlFingerprint(sql: string): string;
|
|
31
|
-
|
|
32
|
-
type LintSeverity = 'error' | 'warn';
|
|
33
|
-
type BudgetSeverity = 'error' | 'warn';
|
|
34
|
-
interface LintFinding {
|
|
35
|
-
readonly code: `LINT.${string}`;
|
|
36
|
-
readonly severity: LintSeverity;
|
|
37
|
-
readonly message: string;
|
|
38
|
-
readonly details?: Record<string, unknown>;
|
|
39
|
-
}
|
|
40
|
-
interface BudgetFinding {
|
|
41
|
-
readonly code: `BUDGET.${string}`;
|
|
42
|
-
readonly severity: BudgetSeverity;
|
|
43
|
-
readonly message: string;
|
|
44
|
-
readonly details?: Record<string, unknown>;
|
|
45
|
-
}
|
|
46
|
-
interface RawGuardrailConfig {
|
|
47
|
-
readonly budgets?: {
|
|
48
|
-
readonly unboundedSelectSeverity?: BudgetSeverity;
|
|
49
|
-
readonly estimatedRows?: number;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
interface RawGuardrailResult {
|
|
53
|
-
readonly lints: LintFinding[];
|
|
54
|
-
readonly budgets: BudgetFinding[];
|
|
55
|
-
readonly statement: 'select' | 'mutation' | 'other';
|
|
56
|
-
}
|
|
57
|
-
declare function evaluateRawGuardrails(plan: ExecutionPlan, config?: RawGuardrailConfig): RawGuardrailResult;
|
|
58
|
-
|
|
59
|
-
declare function parseContractMarkerRow(row: unknown): ContractMarkerRecord;
|
|
60
|
-
|
|
61
|
-
type Severity = 'error' | 'warn' | 'info';
|
|
62
|
-
interface Log {
|
|
63
|
-
info(event: unknown): void;
|
|
64
|
-
warn(event: unknown): void;
|
|
65
|
-
error(event: unknown): void;
|
|
66
|
-
}
|
|
67
|
-
interface PluginContext<TContract = unknown, TAdapter = unknown, TDriver = unknown> {
|
|
68
|
-
readonly contract: TContract;
|
|
69
|
-
readonly adapter: TAdapter;
|
|
70
|
-
readonly driver: TDriver;
|
|
71
|
-
readonly mode: 'strict' | 'permissive';
|
|
72
|
-
readonly now: () => number;
|
|
73
|
-
readonly log: Log;
|
|
74
|
-
}
|
|
75
|
-
interface AfterExecuteResult {
|
|
76
|
-
readonly rowCount: number;
|
|
77
|
-
readonly latencyMs: number;
|
|
78
|
-
readonly completed: boolean;
|
|
79
|
-
}
|
|
80
|
-
interface Plugin<TContract = unknown, TAdapter = unknown, TDriver = unknown> {
|
|
81
|
-
readonly name: string;
|
|
82
|
-
beforeExecute?(plan: ExecutionPlan, ctx: PluginContext<TContract, TAdapter, TDriver>): Promise<void>;
|
|
83
|
-
onRow?(row: Record<string, unknown>, plan: ExecutionPlan, ctx: PluginContext<TContract, TAdapter, TDriver>): Promise<void>;
|
|
84
|
-
afterExecute?(plan: ExecutionPlan, result: AfterExecuteResult, ctx: PluginContext<TContract, TAdapter, TDriver>): Promise<void>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
interface BudgetsOptions {
|
|
88
|
-
readonly maxRows?: number;
|
|
89
|
-
readonly defaultTableRows?: number;
|
|
90
|
-
readonly tableRows?: Record<string, number>;
|
|
91
|
-
readonly maxLatencyMs?: number;
|
|
92
|
-
readonly severities?: {
|
|
93
|
-
readonly rowCount?: 'warn' | 'error';
|
|
94
|
-
readonly latency?: 'warn' | 'error';
|
|
95
|
-
};
|
|
96
|
-
readonly explain?: {
|
|
97
|
-
readonly enabled?: boolean;
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
declare function budgets<TContract = unknown, TAdapter = unknown, TDriver = unknown>(options?: BudgetsOptions): Plugin<TContract, TAdapter, TDriver>;
|
|
101
|
-
|
|
102
|
-
interface LintsOptions {
|
|
103
|
-
readonly severities?: {
|
|
104
|
-
readonly selectStar?: 'warn' | 'error';
|
|
105
|
-
readonly noLimit?: 'warn' | 'error';
|
|
106
|
-
readonly readOnlyMutation?: 'warn' | 'error';
|
|
107
|
-
readonly unindexedPredicate?: 'warn' | 'error';
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
declare function lints<TContract = unknown, TAdapter = unknown, TDriver = unknown>(options?: LintsOptions): Plugin<TContract, TAdapter, TDriver>;
|
|
111
|
-
|
|
112
|
-
interface MarkerStatement {
|
|
113
|
-
readonly sql: string;
|
|
114
|
-
readonly params: readonly unknown[];
|
|
115
|
-
}
|
|
116
|
-
interface MarkerReader {
|
|
117
|
-
readMarkerStatement(): MarkerStatement;
|
|
118
|
-
}
|
|
119
|
-
interface RuntimeFamilyAdapter<TContract = unknown> {
|
|
120
|
-
readonly contract: TContract;
|
|
121
|
-
readonly markerReader: MarkerReader;
|
|
122
|
-
validatePlan(plan: ExecutionPlan, contract: TContract): void;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
interface RuntimeVerifyOptions {
|
|
126
|
-
readonly mode: 'onFirstUse' | 'startup' | 'always';
|
|
127
|
-
readonly requireMarker: boolean;
|
|
128
|
-
}
|
|
129
|
-
type TelemetryOutcome = 'success' | 'runtime-error';
|
|
130
|
-
interface RuntimeTelemetryEvent {
|
|
131
|
-
readonly lane: string;
|
|
132
|
-
readonly target: string;
|
|
133
|
-
readonly fingerprint: string;
|
|
134
|
-
readonly outcome: TelemetryOutcome;
|
|
135
|
-
readonly durationMs?: number;
|
|
136
|
-
}
|
|
137
|
-
interface RuntimeCoreOptions<TContract = unknown, TAdapter = unknown, TDriver = unknown> {
|
|
138
|
-
readonly familyAdapter: RuntimeFamilyAdapter<TContract>;
|
|
139
|
-
readonly driver: TDriver;
|
|
140
|
-
readonly verify: RuntimeVerifyOptions;
|
|
141
|
-
readonly plugins?: readonly Plugin<TContract, TAdapter, TDriver>[];
|
|
142
|
-
readonly mode?: 'strict' | 'permissive';
|
|
143
|
-
readonly log?: Log;
|
|
144
|
-
readonly operationRegistry: OperationRegistry;
|
|
145
|
-
}
|
|
146
|
-
interface RuntimeCore<TContract = unknown, TAdapter = unknown, TDriver = unknown> {
|
|
147
|
-
readonly _typeContract?: TContract;
|
|
148
|
-
readonly _typeAdapter?: TAdapter;
|
|
149
|
-
readonly _typeDriver?: TDriver;
|
|
150
|
-
execute<Row = Record<string, unknown>>(plan: ExecutionPlan<Row>): AsyncIterableResult<Row>;
|
|
151
|
-
telemetry(): RuntimeTelemetryEvent | null;
|
|
152
|
-
close(): Promise<void>;
|
|
153
|
-
operations(): OperationRegistry;
|
|
154
|
-
}
|
|
155
|
-
declare function createRuntimeCore<TContract = unknown, TAdapter = unknown, TDriver = unknown>(options: RuntimeCoreOptions<TContract, TAdapter, TDriver>): RuntimeCore<TContract, TAdapter, TDriver>;
|
|
156
|
-
|
|
157
|
-
export { type AfterExecuteResult, AsyncIterableResult, type BudgetFinding, type BudgetsOptions, type LintFinding, type LintsOptions, type Log, type MarkerReader, type MarkerStatement, type Plugin, type PluginContext, type RawGuardrailResult, type RuntimeCore, type RuntimeCoreOptions, type RuntimeErrorEnvelope, type RuntimeFamilyAdapter, type RuntimeTelemetryEvent, type RuntimeVerifyOptions, type Severity, type TelemetryOutcome, budgets, computeSqlFingerprint, createRuntimeCore, evaluateRawGuardrails, lints, parseContractMarkerRow, runtimeError };
|