@webpieces/dev-config 0.2.79 → 0.2.81
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/architecture/executors/validate-code/executor.d.ts +7 -0
- package/architecture/executors/validate-code/executor.js +13 -2
- package/architecture/executors/validate-code/executor.js.map +1 -1
- package/architecture/executors/validate-code/executor.ts +23 -2
- package/architecture/executors/validate-code/schema.json +21 -0
- package/architecture/executors/validate-dtos/executor.d.ts +40 -0
- package/architecture/executors/validate-dtos/executor.js +486 -0
- package/architecture/executors/validate-dtos/executor.js.map +1 -0
- package/architecture/executors/validate-dtos/executor.ts +606 -0
- package/architecture/executors/validate-dtos/schema.json +24 -0
- package/executors.json +5 -0
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { ExecutorContext } from '@nx/devkit';
|
|
|
2
2
|
import { ReturnTypeMode } from '../validate-return-types/executor';
|
|
3
3
|
import { NoInlineTypesMode } from '../validate-no-inline-types/executor';
|
|
4
4
|
import { NoAnyUnknownMode } from '../validate-no-any-unknown/executor';
|
|
5
|
+
import { ValidateDtosMode } from '../validate-dtos/executor';
|
|
5
6
|
export type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';
|
|
6
7
|
export type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';
|
|
7
8
|
export interface MethodMaxLimitConfig {
|
|
@@ -16,12 +17,18 @@ export interface FileMaxLimitConfig {
|
|
|
16
17
|
disableAllowed?: boolean;
|
|
17
18
|
ignoreModifiedUntilEpoch?: number;
|
|
18
19
|
}
|
|
20
|
+
export interface ValidateDtosConfig {
|
|
21
|
+
mode?: ValidateDtosMode;
|
|
22
|
+
prismaSchemaPath?: string;
|
|
23
|
+
dtoSourcePaths?: string[];
|
|
24
|
+
}
|
|
19
25
|
export interface ValidateCodeOptions {
|
|
20
26
|
methodMaxLimit?: MethodMaxLimitConfig;
|
|
21
27
|
fileMaxLimit?: FileMaxLimitConfig;
|
|
22
28
|
requireReturnTypeMode?: ReturnTypeMode;
|
|
23
29
|
noInlineTypeLiteralsMode?: NoInlineTypesMode;
|
|
24
30
|
noAnyUnknownMode?: NoAnyUnknownMode;
|
|
31
|
+
validateDtos?: ValidateDtosConfig;
|
|
25
32
|
}
|
|
26
33
|
export interface ExecutorResult {
|
|
27
34
|
success: boolean;
|
|
@@ -8,6 +8,7 @@ const executor_3 = tslib_1.__importDefault(require("../validate-modified-files/e
|
|
|
8
8
|
const executor_4 = tslib_1.__importDefault(require("../validate-return-types/executor"));
|
|
9
9
|
const executor_5 = tslib_1.__importDefault(require("../validate-no-inline-types/executor"));
|
|
10
10
|
const executor_6 = tslib_1.__importDefault(require("../validate-no-any-unknown/executor"));
|
|
11
|
+
const executor_7 = tslib_1.__importDefault(require("../validate-dtos/executor"));
|
|
11
12
|
function formatEpochDate(epoch) {
|
|
12
13
|
return new Date(epoch * 1000).toISOString().split('T')[0];
|
|
13
14
|
}
|
|
@@ -63,6 +64,9 @@ function parseConfig(options) {
|
|
|
63
64
|
returnTypeMode: options.requireReturnTypeMode ?? 'OFF',
|
|
64
65
|
noInlineTypesMode: options.noInlineTypeLiteralsMode ?? 'OFF',
|
|
65
66
|
noAnyUnknownMode: options.noAnyUnknownMode ?? 'OFF',
|
|
67
|
+
validateDtosMode: options.validateDtos?.mode ?? 'OFF',
|
|
68
|
+
validateDtosPrismaPath: options.validateDtos?.prismaSchemaPath,
|
|
69
|
+
validateDtosSrcPaths: options.validateDtos?.dtoSourcePaths ?? [],
|
|
66
70
|
};
|
|
67
71
|
}
|
|
68
72
|
function formatOverride(override) {
|
|
@@ -78,12 +82,13 @@ function logConfig(config) {
|
|
|
78
82
|
console.log(` Require return types: ${config.returnTypeMode}`);
|
|
79
83
|
console.log(` No inline type literals: ${config.noInlineTypesMode}`);
|
|
80
84
|
console.log(` No any/unknown: ${config.noAnyUnknownMode}`);
|
|
85
|
+
console.log(` Validate DTOs: ${config.validateDtosMode}`);
|
|
81
86
|
console.log('');
|
|
82
87
|
}
|
|
83
88
|
function isAllOff(config) {
|
|
84
89
|
return config.methodMode === 'OFF' && config.fileMode === 'OFF' &&
|
|
85
90
|
config.returnTypeMode === 'OFF' && config.noInlineTypesMode === 'OFF' &&
|
|
86
|
-
config.noAnyUnknownMode === 'OFF';
|
|
91
|
+
config.noAnyUnknownMode === 'OFF' && config.validateDtosMode === 'OFF';
|
|
87
92
|
}
|
|
88
93
|
async function runMethodValidators(config, context) {
|
|
89
94
|
const results = [];
|
|
@@ -116,9 +121,15 @@ async function runExecutor(options, context) {
|
|
|
116
121
|
const returnTypesResult = await (0, executor_4.default)({ mode: config.returnTypeMode }, context);
|
|
117
122
|
const noInlineTypesResult = await (0, executor_5.default)({ mode: config.noInlineTypesMode }, context);
|
|
118
123
|
const noAnyUnknownResult = await (0, executor_6.default)({ mode: config.noAnyUnknownMode }, context);
|
|
124
|
+
const validateDtosResult = await (0, executor_7.default)({
|
|
125
|
+
mode: config.validateDtosMode,
|
|
126
|
+
prismaSchemaPath: config.validateDtosPrismaPath,
|
|
127
|
+
dtoSourcePaths: config.validateDtosSrcPaths,
|
|
128
|
+
}, context);
|
|
119
129
|
const allSuccess = methodResults.every((r) => r.success) &&
|
|
120
130
|
fileResult.success && returnTypesResult.success &&
|
|
121
|
-
noInlineTypesResult.success && noAnyUnknownResult.success
|
|
131
|
+
noInlineTypesResult.success && noAnyUnknownResult.success &&
|
|
132
|
+
validateDtosResult.success;
|
|
122
133
|
console.log(allSuccess ? '\n\u2705 All code validations passed\n' : '\n\u274c Some code validations failed\n');
|
|
123
134
|
return { success: allSuccess };
|
|
124
135
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-code/executor.ts"],"names":[],"mappings":";;AAkLA,8BA2BC;;AA5MD,wFAAqE;AACrE,6FAA+E;AAC/E,2FAA2E;AAC3E,yFA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AM,EAAE,OAAO,CAAC,CAAC;IACjE,MAAM,UAAU,GAAG,MAAM,IAAA,kBAAwB,EAAC;QAC9C,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,QAAQ,EAAE,cAAc,EAAE,MAAM,CAAC,kBAAkB;KAC5F,EAAE,OAAO,CAAC,CAAC;IACZ,MAAM,iBAAiB,GAAG,MAAM,IAAA,kBAAsB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,cAAc,EAAE,EAAE,OAAO,CAAC,CAAC;IACjG,MAAM,mBAAmB,GAAG,MAAM,IAAA,kBAAwB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,iBAAiB,EAAE,EAAE,OAAO,CAAC,CAAC;IACxG,MAAM,kBAAkB,GAAG,MAAM,IAAA,kBAAuB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAC;IAErG,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACpD,UAAU,CAAC,OAAO,IAAI,iBAAiB,CAAC,OAAO;QAC/C,mBAAmB,CAAC,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC;IAE9D,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,wCAAwC,CAAC,CAAC,CAAC,yCAAyC,CAAC,CAAC;IAC/G,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { ExecutorContext } from '@nx/devkit';\nimport runNewMethodsExecutor from '../validate-new-methods/executor';\nimport runModifiedMethodsExecutor from '../validate-modified-methods/executor';\nimport runModifiedFilesExecutor from '../validate-modified-files/executor';\nimport runReturnTypesExecutor, { ReturnTypeMode } from '../validate-return-types/executor';\nimport runNoInlineTypesExecutor, { NoInlineTypesMode } from '../validate-no-inline-types/executor';\nimport runNoAnyUnknownExecutor, { NoAnyUnknownMode } from '../validate-no-any-unknown/executor';\n\nexport type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';\nexport type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';\n\nexport interface MethodMaxLimitConfig {\n limit?: number;\n mode?: MethodMaxLimitMode;\n disableAllowed?: boolean;\n ignoreModifiedUntilEpoch?: number;\n}\n\nexport interface FileMaxLimitConfig {\n limit?: number;\n mode?: FileMaxLimitMode;\n disableAllowed?: boolean;\n ignoreModifiedUntilEpoch?: number;\n}\n\nexport interface ValidateCodeOptions {\n methodMaxLimit?: MethodMaxLimitConfig;\n fileMaxLimit?: FileMaxLimitConfig;\n requireReturnTypeMode?: ReturnTypeMode;\n noInlineTypeLiteralsMode?: NoInlineTypesMode;\n noAnyUnknownMode?: NoAnyUnknownMode;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface OverrideInfo {\n active: boolean;\n normalMode: string;\n expiresDate: string;\n}\n\ninterface ParsedConfig {\n methodLimit: number;\n methodMode: MethodMaxLimitMode;\n methodDisableAllowed: boolean;\n methodOverride: OverrideInfo | undefined;\n fileLimit: number;\n fileMode: FileMaxLimitMode;\n fileDisableAllowed: boolean;\n fileOverride: OverrideInfo | undefined;\n returnTypeMode: ReturnTypeMode;\n noInlineTypesMode: NoInlineTypesMode;\n noAnyUnknownMode: NoAnyUnknownMode;\n}\n\ninterface ResolvedMethodMode {\n mode: MethodMaxLimitMode;\n override: OverrideInfo | undefined;\n}\n\ninterface ResolvedFileMode {\n mode: FileMaxLimitMode;\n override: OverrideInfo | undefined;\n}\n\nfunction formatEpochDate(epoch: number): string {\n return new Date(epoch * 1000).toISOString().split('T')[0];\n}\n\nfunction resolveMethodMode(\n normalMode: MethodMaxLimitMode, epoch: number | undefined\n): ResolvedMethodMode {\n if (epoch === undefined) {\n return { mode: normalMode, override: undefined };\n }\n const nowSeconds = Date.now() / 1000;\n if (nowSeconds < epoch) {\n // Active: downgrade to skip modified checking\n const downgraded: MethodMaxLimitMode =\n normalMode === 'OFF' ? 'OFF' : 'NEW_METHODS';\n return {\n mode: downgraded,\n override: { active: true, normalMode, expiresDate: formatEpochDate(epoch) },\n };\n }\n // Expired\n console.log(`\\n\\u26a0\\ufe0f methodMaxLimit.ignoreModifiedUntilEpoch (${epoch}) has expired (${formatEpochDate(epoch)}). Remove it from nx.json. Using normal mode: ${normalMode}\\n`);\n return { mode: normalMode, override: undefined };\n}\n\nfunction resolveFileMode(\n normalMode: FileMaxLimitMode, epoch: number | undefined\n): ResolvedFileMode {\n if (epoch === undefined) {\n return { mode: normalMode, override: undefined };\n }\n const nowSeconds = Date.now() / 1000;\n if (nowSeconds < epoch) {\n // Active: file checking is inherently about modified files, so skip entirely\n return {\n mode: 'OFF',\n override: { active: true, normalMode, expiresDate: formatEpochDate(epoch) },\n };\n }\n // Expired\n console.log(`\\n\\u26a0\\ufe0f fileMaxLimit.ignoreModifiedUntilEpoch (${epoch}) has expired (${formatEpochDate(epoch)}). Remove it from nx.json. Using normal mode: ${normalMode}\\n`);\n return { mode: normalMode, override: undefined };\n}\n\nfunction parseConfig(options: ValidateCodeOptions): ParsedConfig {\n const methodConfig: MethodMaxLimitConfig = options.methodMaxLimit ?? {};\n const fileConfig: FileMaxLimitConfig = options.fileMaxLimit ?? {};\n\n const normalMethodMode = methodConfig.mode ?? 'NEW_AND_MODIFIED_METHODS';\n const normalFileMode = fileConfig.mode ?? 'MODIFIED_FILES';\n\n const methodResolved = resolveMethodMode(normalMethodMode, methodConfig.ignoreModifiedUntilEpoch);\n const fileResolved = resolveFileMode(normalFileMode, fileConfig.ignoreModifiedUntilEpoch);\n\n return {\n methodLimit: methodConfig.limit ?? 80,\n methodMode: methodResolved.mode,\n methodDisableAllowed: methodConfig.disableAllowed ?? true,\n methodOverride: methodResolved.override,\n fileLimit: fileConfig.limit ?? 900,\n fileMode: fileResolved.mode,\n fileDisableAllowed: fileConfig.disableAllowed ?? true,\n fileOverride: fileResolved.override,\n returnTypeMode: options.requireReturnTypeMode ?? 'OFF',\n noInlineTypesMode: options.noInlineTypeLiteralsMode ?? 'OFF',\n noAnyUnknownMode: options.noAnyUnknownMode ?? 'OFF',\n };\n}\n\nfunction formatOverride(override: OverrideInfo | undefined): string {\n if (!override) {\n return '';\n }\n return ` (override active, normal: ${override.normalMode}, expires: ${override.expiresDate})`;\n}\n\nfunction logConfig(config: ParsedConfig): void {\n console.log('\\n\\ud83d\\udccf Running Code Validations\\n');\n console.log(` Method limits: mode=${config.methodMode}${formatOverride(config.methodOverride)}, limit=${config.methodLimit}, disableAllowed=${config.methodDisableAllowed}`);\n console.log(` File limits: mode=${config.fileMode}${formatOverride(config.fileOverride)}, limit=${config.fileLimit}, disableAllowed=${config.fileDisableAllowed}`);\n console.log(` Require return types: ${config.returnTypeMode}`);\n console.log(` No inline type literals: ${config.noInlineTypesMode}`);\n console.log(` No any/unknown: ${config.noAnyUnknownMode}`);\n console.log('');\n}\n\nfunction isAllOff(config: ParsedConfig): boolean {\n return config.methodMode === 'OFF' && config.fileMode === 'OFF' &&\n config.returnTypeMode === 'OFF' && config.noInlineTypesMode === 'OFF' &&\n config.noAnyUnknownMode === 'OFF';\n}\n\nasync function runMethodValidators(config: ParsedConfig, context: ExecutorContext): Promise<ExecutorResult[]> {\n const results: ExecutorResult[] = [];\n const runNew = config.methodMode === 'NEW_METHODS' || config.methodMode === 'NEW_AND_MODIFIED_METHODS';\n const runModified = config.methodMode === 'NEW_AND_MODIFIED_METHODS' || config.methodMode === 'MODIFIED_FILES';\n\n if (runNew) {\n results.push(await runNewMethodsExecutor({\n limit: config.methodLimit,\n mode: config.methodMode, disableAllowed: config.methodDisableAllowed,\n }, context));\n }\n if (runModified) {\n results.push(await runModifiedMethodsExecutor({\n limit: config.methodLimit, mode: config.methodMode, disableAllowed: config.methodDisableAllowed,\n }, context));\n }\n return results;\n}\n\nexport default async function runExecutor(\n options: ValidateCodeOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const config = parseConfig(options);\n\n if (isAllOff(config)) {\n console.log('\\n\\u23ed\\ufe0f Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n logConfig(config);\n\n const methodResults = await runMethodValidators(config, context);\n const fileResult = await runModifiedFilesExecutor({\n limit: config.fileLimit, mode: config.fileMode, disableAllowed: config.fileDisableAllowed,\n }, context);\n const returnTypesResult = await runReturnTypesExecutor({ mode: config.returnTypeMode }, context);\n const noInlineTypesResult = await runNoInlineTypesExecutor({ mode: config.noInlineTypesMode }, context);\n const noAnyUnknownResult = await runNoAnyUnknownExecutor({ mode: config.noAnyUnknownMode }, context);\n\n const allSuccess = methodResults.every((r) => r.success) &&\n fileResult.success && returnTypesResult.success &&\n noInlineTypesResult.success && noAnyUnknownResult.success;\n\n console.log(allSuccess ? '\\n\\u2705 All code validations passed\\n' : '\\n\\u274c Some code validations failed\\n');\n return { success: allSuccess };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/dev-config/architecture/executors/validate-code/executor.ts"],"names":[],"mappings":";;AAiMA,8BAiCC;;AAjOD,wFAAqE;AACrE,6FAA+E;AAC/E,2FAA2E;AAC3E,yFAA2F;AAC3F,4FAAmG;AACnG,2FAAgG;AAChG,iFAAsF;AAuEtF,SAAS,eAAe,CAAC,KAAa;IAClC,OAAO,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,iBAAiB,CACtB,UAA8B,EAAE,KAAyB;IAEzD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACtB,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IACrD,CAAC;IACD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAA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AQ,EAAE,cAAc,EAAE,MAAM,CAAC,kBAAkB;KAC5F,EAAE,OAAO,CAAC,CAAC;IACZ,MAAM,iBAAiB,GAAG,MAAM,IAAA,kBAAsB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,cAAc,EAAE,EAAE,OAAO,CAAC,CAAC;IACjG,MAAM,mBAAmB,GAAG,MAAM,IAAA,kBAAwB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,iBAAiB,EAAE,EAAE,OAAO,CAAC,CAAC;IACxG,MAAM,kBAAkB,GAAG,MAAM,IAAA,kBAAuB,EAAC,EAAE,IAAI,EAAE,MAAM,CAAC,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAC;IACrG,MAAM,kBAAkB,GAAG,MAAM,IAAA,kBAAuB,EAAC;QACrD,IAAI,EAAE,MAAM,CAAC,gBAAgB;QAC7B,gBAAgB,EAAE,MAAM,CAAC,sBAAsB;QAC/C,cAAc,EAAE,MAAM,CAAC,oBAAoB;KAC9C,EAAE,OAAO,CAAC,CAAC;IAEZ,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACpD,UAAU,CAAC,OAAO,IAAI,iBAAiB,CAAC,OAAO;QAC/C,mBAAmB,CAAC,OAAO,IAAI,kBAAkB,CAAC,OAAO;QACzD,kBAAkB,CAAC,OAAO,CAAC;IAE/B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,wCAAwC,CAAC,CAAC,CAAC,yCAAyC,CAAC,CAAC;IAC/G,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AACnC,CAAC","sourcesContent":["import { ExecutorContext } from '@nx/devkit';\nimport runNewMethodsExecutor from '../validate-new-methods/executor';\nimport runModifiedMethodsExecutor from '../validate-modified-methods/executor';\nimport runModifiedFilesExecutor from '../validate-modified-files/executor';\nimport runReturnTypesExecutor, { ReturnTypeMode } from '../validate-return-types/executor';\nimport runNoInlineTypesExecutor, { NoInlineTypesMode } from '../validate-no-inline-types/executor';\nimport runNoAnyUnknownExecutor, { NoAnyUnknownMode } from '../validate-no-any-unknown/executor';\nimport runValidateDtosExecutor, { ValidateDtosMode } from '../validate-dtos/executor';\n\nexport type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';\nexport type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';\n\nexport interface MethodMaxLimitConfig {\n limit?: number;\n mode?: MethodMaxLimitMode;\n disableAllowed?: boolean;\n ignoreModifiedUntilEpoch?: number;\n}\n\nexport interface FileMaxLimitConfig {\n limit?: number;\n mode?: FileMaxLimitMode;\n disableAllowed?: boolean;\n ignoreModifiedUntilEpoch?: number;\n}\n\nexport interface ValidateDtosConfig {\n mode?: ValidateDtosMode;\n prismaSchemaPath?: string;\n dtoSourcePaths?: string[];\n}\n\nexport interface ValidateCodeOptions {\n methodMaxLimit?: MethodMaxLimitConfig;\n fileMaxLimit?: FileMaxLimitConfig;\n requireReturnTypeMode?: ReturnTypeMode;\n noInlineTypeLiteralsMode?: NoInlineTypesMode;\n noAnyUnknownMode?: NoAnyUnknownMode;\n validateDtos?: ValidateDtosConfig;\n}\n\nexport interface ExecutorResult {\n success: boolean;\n}\n\ninterface OverrideInfo {\n active: boolean;\n normalMode: string;\n expiresDate: string;\n}\n\ninterface ParsedConfig {\n methodLimit: number;\n methodMode: MethodMaxLimitMode;\n methodDisableAllowed: boolean;\n methodOverride: OverrideInfo | undefined;\n fileLimit: number;\n fileMode: FileMaxLimitMode;\n fileDisableAllowed: boolean;\n fileOverride: OverrideInfo | undefined;\n returnTypeMode: ReturnTypeMode;\n noInlineTypesMode: NoInlineTypesMode;\n noAnyUnknownMode: NoAnyUnknownMode;\n validateDtosMode: ValidateDtosMode;\n validateDtosPrismaPath: string | undefined;\n validateDtosSrcPaths: string[];\n}\n\ninterface ResolvedMethodMode {\n mode: MethodMaxLimitMode;\n override: OverrideInfo | undefined;\n}\n\ninterface ResolvedFileMode {\n mode: FileMaxLimitMode;\n override: OverrideInfo | undefined;\n}\n\nfunction formatEpochDate(epoch: number): string {\n return new Date(epoch * 1000).toISOString().split('T')[0];\n}\n\nfunction resolveMethodMode(\n normalMode: MethodMaxLimitMode, epoch: number | undefined\n): ResolvedMethodMode {\n if (epoch === undefined) {\n return { mode: normalMode, override: undefined };\n }\n const nowSeconds = Date.now() / 1000;\n if (nowSeconds < epoch) {\n // Active: downgrade to skip modified checking\n const downgraded: MethodMaxLimitMode =\n normalMode === 'OFF' ? 'OFF' : 'NEW_METHODS';\n return {\n mode: downgraded,\n override: { active: true, normalMode, expiresDate: formatEpochDate(epoch) },\n };\n }\n // Expired\n console.log(`\\n\\u26a0\\ufe0f methodMaxLimit.ignoreModifiedUntilEpoch (${epoch}) has expired (${formatEpochDate(epoch)}). Remove it from nx.json. Using normal mode: ${normalMode}\\n`);\n return { mode: normalMode, override: undefined };\n}\n\nfunction resolveFileMode(\n normalMode: FileMaxLimitMode, epoch: number | undefined\n): ResolvedFileMode {\n if (epoch === undefined) {\n return { mode: normalMode, override: undefined };\n }\n const nowSeconds = Date.now() / 1000;\n if (nowSeconds < epoch) {\n // Active: file checking is inherently about modified files, so skip entirely\n return {\n mode: 'OFF',\n override: { active: true, normalMode, expiresDate: formatEpochDate(epoch) },\n };\n }\n // Expired\n console.log(`\\n\\u26a0\\ufe0f fileMaxLimit.ignoreModifiedUntilEpoch (${epoch}) has expired (${formatEpochDate(epoch)}). Remove it from nx.json. Using normal mode: ${normalMode}\\n`);\n return { mode: normalMode, override: undefined };\n}\n\nfunction parseConfig(options: ValidateCodeOptions): ParsedConfig {\n const methodConfig: MethodMaxLimitConfig = options.methodMaxLimit ?? {};\n const fileConfig: FileMaxLimitConfig = options.fileMaxLimit ?? {};\n\n const normalMethodMode = methodConfig.mode ?? 'NEW_AND_MODIFIED_METHODS';\n const normalFileMode = fileConfig.mode ?? 'MODIFIED_FILES';\n\n const methodResolved = resolveMethodMode(normalMethodMode, methodConfig.ignoreModifiedUntilEpoch);\n const fileResolved = resolveFileMode(normalFileMode, fileConfig.ignoreModifiedUntilEpoch);\n\n return {\n methodLimit: methodConfig.limit ?? 80,\n methodMode: methodResolved.mode,\n methodDisableAllowed: methodConfig.disableAllowed ?? true,\n methodOverride: methodResolved.override,\n fileLimit: fileConfig.limit ?? 900,\n fileMode: fileResolved.mode,\n fileDisableAllowed: fileConfig.disableAllowed ?? true,\n fileOverride: fileResolved.override,\n returnTypeMode: options.requireReturnTypeMode ?? 'OFF',\n noInlineTypesMode: options.noInlineTypeLiteralsMode ?? 'OFF',\n noAnyUnknownMode: options.noAnyUnknownMode ?? 'OFF',\n validateDtosMode: options.validateDtos?.mode ?? 'OFF',\n validateDtosPrismaPath: options.validateDtos?.prismaSchemaPath,\n validateDtosSrcPaths: options.validateDtos?.dtoSourcePaths ?? [],\n };\n}\n\nfunction formatOverride(override: OverrideInfo | undefined): string {\n if (!override) {\n return '';\n }\n return ` (override active, normal: ${override.normalMode}, expires: ${override.expiresDate})`;\n}\n\nfunction logConfig(config: ParsedConfig): void {\n console.log('\\n\\ud83d\\udccf Running Code Validations\\n');\n console.log(` Method limits: mode=${config.methodMode}${formatOverride(config.methodOverride)}, limit=${config.methodLimit}, disableAllowed=${config.methodDisableAllowed}`);\n console.log(` File limits: mode=${config.fileMode}${formatOverride(config.fileOverride)}, limit=${config.fileLimit}, disableAllowed=${config.fileDisableAllowed}`);\n console.log(` Require return types: ${config.returnTypeMode}`);\n console.log(` No inline type literals: ${config.noInlineTypesMode}`);\n console.log(` No any/unknown: ${config.noAnyUnknownMode}`);\n console.log(` Validate DTOs: ${config.validateDtosMode}`);\n console.log('');\n}\n\nfunction isAllOff(config: ParsedConfig): boolean {\n return config.methodMode === 'OFF' && config.fileMode === 'OFF' &&\n config.returnTypeMode === 'OFF' && config.noInlineTypesMode === 'OFF' &&\n config.noAnyUnknownMode === 'OFF' && config.validateDtosMode === 'OFF';\n}\n\nasync function runMethodValidators(config: ParsedConfig, context: ExecutorContext): Promise<ExecutorResult[]> {\n const results: ExecutorResult[] = [];\n const runNew = config.methodMode === 'NEW_METHODS' || config.methodMode === 'NEW_AND_MODIFIED_METHODS';\n const runModified = config.methodMode === 'NEW_AND_MODIFIED_METHODS' || config.methodMode === 'MODIFIED_FILES';\n\n if (runNew) {\n results.push(await runNewMethodsExecutor({\n limit: config.methodLimit,\n mode: config.methodMode, disableAllowed: config.methodDisableAllowed,\n }, context));\n }\n if (runModified) {\n results.push(await runModifiedMethodsExecutor({\n limit: config.methodLimit, mode: config.methodMode, disableAllowed: config.methodDisableAllowed,\n }, context));\n }\n return results;\n}\n\nexport default async function runExecutor(\n options: ValidateCodeOptions,\n context: ExecutorContext\n): Promise<ExecutorResult> {\n const config = parseConfig(options);\n\n if (isAllOff(config)) {\n console.log('\\n\\u23ed\\ufe0f Skipping all code validations (all modes: OFF)\\n');\n return { success: true };\n }\n\n logConfig(config);\n\n const methodResults = await runMethodValidators(config, context);\n const fileResult = await runModifiedFilesExecutor({\n limit: config.fileLimit, mode: config.fileMode, disableAllowed: config.fileDisableAllowed,\n }, context);\n const returnTypesResult = await runReturnTypesExecutor({ mode: config.returnTypeMode }, context);\n const noInlineTypesResult = await runNoInlineTypesExecutor({ mode: config.noInlineTypesMode }, context);\n const noAnyUnknownResult = await runNoAnyUnknownExecutor({ mode: config.noAnyUnknownMode }, context);\n const validateDtosResult = await runValidateDtosExecutor({\n mode: config.validateDtosMode,\n prismaSchemaPath: config.validateDtosPrismaPath,\n dtoSourcePaths: config.validateDtosSrcPaths,\n }, context);\n\n const allSuccess = methodResults.every((r) => r.success) &&\n fileResult.success && returnTypesResult.success &&\n noInlineTypesResult.success && noAnyUnknownResult.success &&\n validateDtosResult.success;\n\n console.log(allSuccess ? '\\n\\u2705 All code validations passed\\n' : '\\n\\u274c Some code validations failed\\n');\n return { success: allSuccess };\n}\n"]}
|
|
@@ -5,6 +5,7 @@ import runModifiedFilesExecutor from '../validate-modified-files/executor';
|
|
|
5
5
|
import runReturnTypesExecutor, { ReturnTypeMode } from '../validate-return-types/executor';
|
|
6
6
|
import runNoInlineTypesExecutor, { NoInlineTypesMode } from '../validate-no-inline-types/executor';
|
|
7
7
|
import runNoAnyUnknownExecutor, { NoAnyUnknownMode } from '../validate-no-any-unknown/executor';
|
|
8
|
+
import runValidateDtosExecutor, { ValidateDtosMode } from '../validate-dtos/executor';
|
|
8
9
|
|
|
9
10
|
export type MethodMaxLimitMode = 'OFF' | 'NEW_METHODS' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';
|
|
10
11
|
export type FileMaxLimitMode = 'OFF' | 'MODIFIED_FILES';
|
|
@@ -23,12 +24,19 @@ export interface FileMaxLimitConfig {
|
|
|
23
24
|
ignoreModifiedUntilEpoch?: number;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
export interface ValidateDtosConfig {
|
|
28
|
+
mode?: ValidateDtosMode;
|
|
29
|
+
prismaSchemaPath?: string;
|
|
30
|
+
dtoSourcePaths?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
26
33
|
export interface ValidateCodeOptions {
|
|
27
34
|
methodMaxLimit?: MethodMaxLimitConfig;
|
|
28
35
|
fileMaxLimit?: FileMaxLimitConfig;
|
|
29
36
|
requireReturnTypeMode?: ReturnTypeMode;
|
|
30
37
|
noInlineTypeLiteralsMode?: NoInlineTypesMode;
|
|
31
38
|
noAnyUnknownMode?: NoAnyUnknownMode;
|
|
39
|
+
validateDtos?: ValidateDtosConfig;
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
export interface ExecutorResult {
|
|
@@ -53,6 +61,9 @@ interface ParsedConfig {
|
|
|
53
61
|
returnTypeMode: ReturnTypeMode;
|
|
54
62
|
noInlineTypesMode: NoInlineTypesMode;
|
|
55
63
|
noAnyUnknownMode: NoAnyUnknownMode;
|
|
64
|
+
validateDtosMode: ValidateDtosMode;
|
|
65
|
+
validateDtosPrismaPath: string | undefined;
|
|
66
|
+
validateDtosSrcPaths: string[];
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
interface ResolvedMethodMode {
|
|
@@ -131,6 +142,9 @@ function parseConfig(options: ValidateCodeOptions): ParsedConfig {
|
|
|
131
142
|
returnTypeMode: options.requireReturnTypeMode ?? 'OFF',
|
|
132
143
|
noInlineTypesMode: options.noInlineTypeLiteralsMode ?? 'OFF',
|
|
133
144
|
noAnyUnknownMode: options.noAnyUnknownMode ?? 'OFF',
|
|
145
|
+
validateDtosMode: options.validateDtos?.mode ?? 'OFF',
|
|
146
|
+
validateDtosPrismaPath: options.validateDtos?.prismaSchemaPath,
|
|
147
|
+
validateDtosSrcPaths: options.validateDtos?.dtoSourcePaths ?? [],
|
|
134
148
|
};
|
|
135
149
|
}
|
|
136
150
|
|
|
@@ -148,13 +162,14 @@ function logConfig(config: ParsedConfig): void {
|
|
|
148
162
|
console.log(` Require return types: ${config.returnTypeMode}`);
|
|
149
163
|
console.log(` No inline type literals: ${config.noInlineTypesMode}`);
|
|
150
164
|
console.log(` No any/unknown: ${config.noAnyUnknownMode}`);
|
|
165
|
+
console.log(` Validate DTOs: ${config.validateDtosMode}`);
|
|
151
166
|
console.log('');
|
|
152
167
|
}
|
|
153
168
|
|
|
154
169
|
function isAllOff(config: ParsedConfig): boolean {
|
|
155
170
|
return config.methodMode === 'OFF' && config.fileMode === 'OFF' &&
|
|
156
171
|
config.returnTypeMode === 'OFF' && config.noInlineTypesMode === 'OFF' &&
|
|
157
|
-
config.noAnyUnknownMode === 'OFF';
|
|
172
|
+
config.noAnyUnknownMode === 'OFF' && config.validateDtosMode === 'OFF';
|
|
158
173
|
}
|
|
159
174
|
|
|
160
175
|
async function runMethodValidators(config: ParsedConfig, context: ExecutorContext): Promise<ExecutorResult[]> {
|
|
@@ -196,10 +211,16 @@ export default async function runExecutor(
|
|
|
196
211
|
const returnTypesResult = await runReturnTypesExecutor({ mode: config.returnTypeMode }, context);
|
|
197
212
|
const noInlineTypesResult = await runNoInlineTypesExecutor({ mode: config.noInlineTypesMode }, context);
|
|
198
213
|
const noAnyUnknownResult = await runNoAnyUnknownExecutor({ mode: config.noAnyUnknownMode }, context);
|
|
214
|
+
const validateDtosResult = await runValidateDtosExecutor({
|
|
215
|
+
mode: config.validateDtosMode,
|
|
216
|
+
prismaSchemaPath: config.validateDtosPrismaPath,
|
|
217
|
+
dtoSourcePaths: config.validateDtosSrcPaths,
|
|
218
|
+
}, context);
|
|
199
219
|
|
|
200
220
|
const allSuccess = methodResults.every((r) => r.success) &&
|
|
201
221
|
fileResult.success && returnTypesResult.success &&
|
|
202
|
-
noInlineTypesResult.success && noAnyUnknownResult.success
|
|
222
|
+
noInlineTypesResult.success && noAnyUnknownResult.success &&
|
|
223
|
+
validateDtosResult.success;
|
|
203
224
|
|
|
204
225
|
console.log(allSuccess ? '\n\u2705 All code validations passed\n' : '\n\u274c Some code validations failed\n');
|
|
205
226
|
return { success: allSuccess };
|
|
@@ -73,6 +73,27 @@
|
|
|
73
73
|
"enum": ["OFF", "MODIFIED_CODE", "MODIFIED_FILES"],
|
|
74
74
|
"description": "OFF: skip validation. MODIFIED_CODE: only changed lines in diff. MODIFIED_FILES: all in modified files. Disallows `any` and `unknown` TypeScript keywords.",
|
|
75
75
|
"default": "OFF"
|
|
76
|
+
},
|
|
77
|
+
"validateDtos": {
|
|
78
|
+
"type": "object",
|
|
79
|
+
"description": "Validate DTO fields match Prisma Dbo model fields. Prevents AI from inventing field names.",
|
|
80
|
+
"properties": {
|
|
81
|
+
"mode": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"enum": ["OFF", "MODIFIED_CLASS", "MODIFIED_FILES"],
|
|
84
|
+
"description": "OFF: skip validation. MODIFIED_CLASS: only validate Dto classes with changed lines. MODIFIED_FILES: validate all Dtos in modified files.",
|
|
85
|
+
"default": "OFF"
|
|
86
|
+
},
|
|
87
|
+
"prismaSchemaPath": {
|
|
88
|
+
"type": "string",
|
|
89
|
+
"description": "Relative path from workspace root to schema.prisma"
|
|
90
|
+
},
|
|
91
|
+
"dtoSourcePaths": {
|
|
92
|
+
"type": "array",
|
|
93
|
+
"items": { "type": "string" },
|
|
94
|
+
"description": "Array of directories (relative to workspace root) containing Dto files"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
76
97
|
}
|
|
77
98
|
},
|
|
78
99
|
"required": []
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validate DTOs Executor
|
|
3
|
+
*
|
|
4
|
+
* Validates that every non-deprecated field in a XxxDto class/interface exists
|
|
5
|
+
* in the corresponding XxxDbo Prisma model. This catches AI agents inventing
|
|
6
|
+
* field names that don't match the database schema.
|
|
7
|
+
*
|
|
8
|
+
* ============================================================================
|
|
9
|
+
* MODES
|
|
10
|
+
* ============================================================================
|
|
11
|
+
* - OFF: Skip validation entirely
|
|
12
|
+
* - MODIFIED_CLASS: Only validate Dto classes that have changed lines in the diff
|
|
13
|
+
* - MODIFIED_FILES: Validate ALL Dto classes in files that were modified
|
|
14
|
+
*
|
|
15
|
+
* ============================================================================
|
|
16
|
+
* SKIP CONDITIONS
|
|
17
|
+
* ============================================================================
|
|
18
|
+
* - If schema.prisma itself is modified, validation is skipped (schema in flux)
|
|
19
|
+
* - Dto classes ending with "JoinDto" are skipped (they compose other Dtos)
|
|
20
|
+
* - Fields marked @deprecated in a comment are exempt
|
|
21
|
+
*
|
|
22
|
+
* ============================================================================
|
|
23
|
+
* MATCHING
|
|
24
|
+
* ============================================================================
|
|
25
|
+
* - UserDto matches UserDbo by case-insensitive prefix ("user")
|
|
26
|
+
* - Dbo field names are converted from snake_case to camelCase for comparison
|
|
27
|
+
* - Dto fields must be a subset of Dbo fields
|
|
28
|
+
* - Extra Dbo fields are allowed (e.g., password)
|
|
29
|
+
*/
|
|
30
|
+
import type { ExecutorContext } from '@nx/devkit';
|
|
31
|
+
export type ValidateDtosMode = 'OFF' | 'MODIFIED_CLASS' | 'MODIFIED_FILES';
|
|
32
|
+
export interface ValidateDtosOptions {
|
|
33
|
+
mode?: ValidateDtosMode;
|
|
34
|
+
prismaSchemaPath?: string;
|
|
35
|
+
dtoSourcePaths?: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface ExecutorResult {
|
|
38
|
+
success: boolean;
|
|
39
|
+
}
|
|
40
|
+
export default function runExecutor(options: ValidateDtosOptions, context: ExecutorContext): Promise<ExecutorResult>;
|