@prisma-next/runtime-executor 0.3.0-dev.15 → 0.3.0-dev.151
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 +159 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +399 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +20 -13
- package/src/async-iterable-result.ts +61 -22
- package/src/exports/index.ts +3 -5
- package/src/marker.ts +1 -4
- package/src/runtime-core.ts +101 -34
- 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/plugins/lints.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { ExecutionPlan } from '@prisma-next/contract/types';
|
|
2
|
-
import { evaluateRawGuardrails } from '../guardrails/raw';
|
|
3
|
-
import type { Plugin, PluginContext } from './types';
|
|
4
|
-
|
|
5
|
-
export interface LintsOptions {
|
|
6
|
-
readonly severities?: {
|
|
7
|
-
readonly selectStar?: 'warn' | 'error';
|
|
8
|
-
readonly noLimit?: 'warn' | 'error';
|
|
9
|
-
readonly readOnlyMutation?: 'warn' | 'error';
|
|
10
|
-
readonly unindexedPredicate?: 'warn' | 'error';
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function lintError(code: string, message: string, details?: Record<string, unknown>) {
|
|
15
|
-
const error = new Error(message) as Error & {
|
|
16
|
-
code: string;
|
|
17
|
-
category: 'LINT';
|
|
18
|
-
severity: 'error';
|
|
19
|
-
details?: Record<string, unknown>;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(error, 'name', {
|
|
22
|
-
value: 'RuntimeError',
|
|
23
|
-
configurable: true,
|
|
24
|
-
});
|
|
25
|
-
return Object.assign(error, {
|
|
26
|
-
code,
|
|
27
|
-
category: 'LINT' as const,
|
|
28
|
-
severity: 'error' as const,
|
|
29
|
-
details,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function lints<TContract = unknown, TAdapter = unknown, TDriver = unknown>(
|
|
34
|
-
options?: LintsOptions,
|
|
35
|
-
): Plugin<TContract, TAdapter, TDriver> {
|
|
36
|
-
return Object.freeze({
|
|
37
|
-
name: 'lints',
|
|
38
|
-
|
|
39
|
-
async beforeExecute(plan: ExecutionPlan, ctx: PluginContext<TContract, TAdapter, TDriver>) {
|
|
40
|
-
if (plan.ast) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const evaluation = evaluateRawGuardrails(plan);
|
|
45
|
-
|
|
46
|
-
for (const lint of evaluation.lints) {
|
|
47
|
-
const configuredSeverity = getConfiguredSeverity(lint.code, options);
|
|
48
|
-
const effectiveSeverity = configuredSeverity ?? lint.severity;
|
|
49
|
-
|
|
50
|
-
if (effectiveSeverity === 'error') {
|
|
51
|
-
throw lintError(lint.code, lint.message, lint.details);
|
|
52
|
-
}
|
|
53
|
-
if (effectiveSeverity === 'warn') {
|
|
54
|
-
ctx.log.warn({
|
|
55
|
-
code: lint.code,
|
|
56
|
-
message: lint.message,
|
|
57
|
-
details: lint.details,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function getConfiguredSeverity(code: string, options?: LintsOptions): 'warn' | 'error' | undefined {
|
|
66
|
-
const severities = options?.severities;
|
|
67
|
-
if (!severities) {
|
|
68
|
-
return undefined;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (code === 'LINT.SELECT_STAR') {
|
|
72
|
-
return severities.selectStar;
|
|
73
|
-
}
|
|
74
|
-
if (code === 'LINT.NO_LIMIT') {
|
|
75
|
-
return severities.noLimit;
|
|
76
|
-
}
|
|
77
|
-
if (code === 'LINT.READ_ONLY_MUTATION') {
|
|
78
|
-
return severities.readOnlyMutation;
|
|
79
|
-
}
|
|
80
|
-
if (code === 'LINT.UNINDEXED_PREDICATE') {
|
|
81
|
-
return severities.unindexedPredicate;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|