@prisma-next/runtime-executor 0.3.0-dev.10 → 0.3.0-dev.100
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 +201 -0
- package/README.md +2 -3
- package/dist/index.d.mts +153 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +390 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +23 -16
- package/src/async-iterable-result.ts +39 -22
- package/src/exports/index.ts +3 -4
- package/src/marker.ts +1 -1
- package/src/runtime-core.ts +105 -28
- package/dist/async-iterable-result.d.ts +0 -17
- package/dist/async-iterable-result.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -8
- package/dist/errors.d.ts.map +0 -1
- package/dist/exports/index.d.ts +0 -17
- package/dist/exports/index.d.ts.map +0 -1
- package/dist/fingerprint.d.ts +0 -2
- package/dist/fingerprint.d.ts.map +0 -1
- package/dist/guardrails/raw.d.ts +0 -28
- package/dist/guardrails/raw.d.ts.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -746
- package/dist/index.js.map +0 -1
- package/dist/marker.d.ts +0 -13
- package/dist/marker.d.ts.map +0 -1
- package/dist/plugins/budgets.d.ts +0 -16
- package/dist/plugins/budgets.d.ts.map +0 -1
- package/dist/plugins/lints.d.ts +0 -11
- package/dist/plugins/lints.d.ts.map +0 -1
- package/dist/plugins/types.d.ts +0 -27
- package/dist/plugins/types.d.ts.map +0 -1
- package/dist/runtime-core.d.ts +0 -37
- package/dist/runtime-core.d.ts.map +0 -1
- package/dist/runtime-spi.d.ts +0 -14
- package/dist/runtime-spi.d.ts.map +0 -1
- package/src/plugins/budgets.ts +0 -328
- package/src/plugins/lints.ts +0 -85
package/src/runtime-core.ts
CHANGED
|
@@ -32,22 +32,51 @@ export interface RuntimeCoreOptions<TContract = unknown, TAdapter = unknown, TDr
|
|
|
32
32
|
readonly operationRegistry: OperationRegistry;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export interface RuntimeCore<TContract = unknown, TAdapter = unknown, TDriver = unknown>
|
|
35
|
+
export interface RuntimeCore<TContract = unknown, TAdapter = unknown, TDriver = unknown>
|
|
36
|
+
extends RuntimeQueryable {
|
|
36
37
|
// Type parameters are used in the implementation for type safety
|
|
37
38
|
readonly _typeContract?: TContract;
|
|
38
39
|
readonly _typeAdapter?: TAdapter;
|
|
39
40
|
readonly _typeDriver?: TDriver;
|
|
40
|
-
|
|
41
|
+
connection(): Promise<RuntimeConnection>;
|
|
41
42
|
telemetry(): RuntimeTelemetryEvent | null;
|
|
42
43
|
close(): Promise<void>;
|
|
43
44
|
operations(): OperationRegistry;
|
|
44
45
|
}
|
|
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
|
+
|
|
46
61
|
interface DriverWithQuery<_TDriver> {
|
|
47
62
|
query(sql: string, params: readonly unknown[]): Promise<{ rows: ReadonlyArray<unknown> }>;
|
|
48
63
|
}
|
|
49
64
|
|
|
50
|
-
interface
|
|
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 {
|
|
51
80
|
execute<Row = Record<string, unknown>>(options: {
|
|
52
81
|
sql: string;
|
|
53
82
|
params: readonly unknown[];
|
|
@@ -136,12 +165,20 @@ class RuntimeCoreImpl<TContract = unknown, TAdapter = unknown, TDriver = unknown
|
|
|
136
165
|
|
|
137
166
|
const marker = parseContractMarkerRow(result.rows[0]);
|
|
138
167
|
|
|
139
|
-
const contract = this.contract as {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
+
);
|
|
145
182
|
}
|
|
146
183
|
|
|
147
184
|
const expectedProfile = contract.profileHash ?? null;
|
|
@@ -180,6 +217,63 @@ class RuntimeCoreImpl<TContract = unknown, TAdapter = unknown, TDriver = unknown
|
|
|
180
217
|
}
|
|
181
218
|
|
|
182
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> {
|
|
183
277
|
this.validatePlan(plan);
|
|
184
278
|
this._telemetry = null;
|
|
185
279
|
|
|
@@ -209,10 +303,9 @@ class RuntimeCoreImpl<TContract = unknown, TAdapter = unknown, TDriver = unknown
|
|
|
209
303
|
}
|
|
210
304
|
}
|
|
211
305
|
|
|
212
|
-
const
|
|
213
|
-
const encodedParams = plan.params as readonly unknown[];
|
|
306
|
+
const encodedParams = plan.params;
|
|
214
307
|
|
|
215
|
-
for await (const row of
|
|
308
|
+
for await (const row of queryable.execute<Record<string, unknown>>({
|
|
216
309
|
sql: plan.sql,
|
|
217
310
|
params: encodedParams,
|
|
218
311
|
})) {
|
|
@@ -260,22 +353,6 @@ class RuntimeCoreImpl<TContract = unknown, TAdapter = unknown, TDriver = unknown
|
|
|
260
353
|
|
|
261
354
|
return new AsyncIterableResult(iterator(this));
|
|
262
355
|
}
|
|
263
|
-
|
|
264
|
-
telemetry(): RuntimeTelemetryEvent | null {
|
|
265
|
-
return this._telemetry;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
operations(): OperationRegistry {
|
|
269
|
-
return this.operationRegistry;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
close(): Promise<void> {
|
|
273
|
-
const driver = this.driver as unknown as DriverWithClose<TDriver>;
|
|
274
|
-
if (typeof driver.close === 'function') {
|
|
275
|
-
return driver.close();
|
|
276
|
-
}
|
|
277
|
-
return Promise.resolve();
|
|
278
|
-
}
|
|
279
356
|
}
|
|
280
357
|
|
|
281
358
|
export function createRuntimeCore<TContract = unknown, TAdapter = unknown, TDriver = unknown>(
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom async iterable result that extends AsyncIterable with a toArray() method.
|
|
3
|
-
* This provides a convenient way to collect all results from an async iterator.
|
|
4
|
-
*/
|
|
5
|
-
export declare class AsyncIterableResult<Row> implements AsyncIterable<Row> {
|
|
6
|
-
private readonly generator;
|
|
7
|
-
private consumed;
|
|
8
|
-
private consumedBy;
|
|
9
|
-
constructor(generator: AsyncGenerator<Row, void, unknown>);
|
|
10
|
-
[Symbol.asyncIterator](): AsyncIterator<Row>;
|
|
11
|
-
/**
|
|
12
|
-
* Collects all values from the async iterator into an array.
|
|
13
|
-
* Once called, the iterator is consumed and cannot be reused.
|
|
14
|
-
*/
|
|
15
|
-
toArray(): Promise<Row[]>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=async-iterable-result.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async-iterable-result.d.ts","sourceRoot":"","sources":["../src/async-iterable-result.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,mBAAmB,CAAC,GAAG,CAAE,YAAW,aAAa,CAAC,GAAG,CAAC;IACjE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqC;IAC/D,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAqC;gBAE3C,SAAS,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC;IAIzD,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC;IAmB5C;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;CAsBhC"}
|
package/dist/errors.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export interface RuntimeErrorEnvelope extends Error {
|
|
2
|
-
readonly code: string;
|
|
3
|
-
readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';
|
|
4
|
-
readonly severity: 'error';
|
|
5
|
-
readonly details?: Record<string, unknown>;
|
|
6
|
-
}
|
|
7
|
-
export declare function runtimeError(code: string, message: string, details?: Record<string, unknown>): RuntimeErrorEnvelope;
|
|
8
|
-
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAqB,SAAQ,KAAK;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IACvE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,oBAAoB,CActB"}
|
package/dist/exports/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export { AsyncIterableResult } from '../async-iterable-result';
|
|
2
|
-
export type { RuntimeErrorEnvelope } from '../errors';
|
|
3
|
-
export { runtimeError } from '../errors';
|
|
4
|
-
export { computeSqlFingerprint } from '../fingerprint';
|
|
5
|
-
export type { BudgetFinding, LintFinding, RawGuardrailResult } from '../guardrails/raw';
|
|
6
|
-
export { evaluateRawGuardrails } from '../guardrails/raw';
|
|
7
|
-
export type { ContractMarkerRecord } from '../marker';
|
|
8
|
-
export { parseContractMarkerRow } from '../marker';
|
|
9
|
-
export type { BudgetsOptions } from '../plugins/budgets';
|
|
10
|
-
export { budgets } from '../plugins/budgets';
|
|
11
|
-
export type { LintsOptions } from '../plugins/lints';
|
|
12
|
-
export { lints } from '../plugins/lints';
|
|
13
|
-
export type { AfterExecuteResult, Log, Plugin, PluginContext, Severity, } from '../plugins/types';
|
|
14
|
-
export type { RuntimeCore, RuntimeCoreOptions, RuntimeTelemetryEvent, RuntimeVerifyOptions, TelemetryOutcome, } from '../runtime-core';
|
|
15
|
-
export { createRuntimeCore } from '../runtime-core';
|
|
16
|
-
export type { MarkerReader, MarkerStatement, RuntimeFamilyAdapter } from '../runtime-spi';
|
|
17
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,YAAY,EACV,kBAAkB,EAClB,GAAG,EACH,MAAM,EACN,aAAa,EACb,QAAQ,GACT,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/fingerprint.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fingerprint.d.ts","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":"AAMA,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOzD"}
|
package/dist/guardrails/raw.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
-
export type LintSeverity = 'error' | 'warn';
|
|
3
|
-
export type BudgetSeverity = 'error' | 'warn';
|
|
4
|
-
export interface LintFinding {
|
|
5
|
-
readonly code: `LINT.${string}`;
|
|
6
|
-
readonly severity: LintSeverity;
|
|
7
|
-
readonly message: string;
|
|
8
|
-
readonly details?: Record<string, unknown>;
|
|
9
|
-
}
|
|
10
|
-
export interface BudgetFinding {
|
|
11
|
-
readonly code: `BUDGET.${string}`;
|
|
12
|
-
readonly severity: BudgetSeverity;
|
|
13
|
-
readonly message: string;
|
|
14
|
-
readonly details?: Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
export interface RawGuardrailConfig {
|
|
17
|
-
readonly budgets?: {
|
|
18
|
-
readonly unboundedSelectSeverity?: BudgetSeverity;
|
|
19
|
-
readonly estimatedRows?: number;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
export interface RawGuardrailResult {
|
|
23
|
-
readonly lints: LintFinding[];
|
|
24
|
-
readonly budgets: BudgetFinding[];
|
|
25
|
-
readonly statement: 'select' | 'mutation' | 'other';
|
|
26
|
-
}
|
|
27
|
-
export declare function evaluateRawGuardrails(plan: ExecutionPlan, config?: RawGuardrailConfig): RawGuardrailResult;
|
|
28
|
-
//# sourceMappingURL=raw.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../src/guardrails/raw.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAsB,MAAM,6BAA6B,CAAC;AAErF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,CAAC;AAC5C,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,MAAM,CAAC;AAE9C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,QAAQ,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,UAAU,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACjB,QAAQ,CAAC,uBAAuB,CAAC,EAAE,cAAc,CAAC;QAClD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;KACjC,CAAC;CACH;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;CACrD;AAQD,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,aAAa,EACnB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,kBAAkB,CA4DpB"}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|