@weverson_na/prisma-generator-nestjs-dto
Version:
Advanced Prisma Generator with Smart Merge v2: Creates DTO and Entity classes with AST-based preservation, intelligent import management, and modular architecture for NestJS
158 lines (157 loc) • 5.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DecoratorStrategy = void 0;
class DecoratorStrategy {
constructor() {
this.decoratorCategories = [
{
importPath: '@nestjs/swagger',
names: ['ApiProperty', 'ApiExtraModels'],
},
{
importPath: 'class-transformer',
names: ['Exclude', 'Expose', 'Transform', 'Type'],
},
{
importPath: 'class-validator',
names: [
'Allow',
'IsDefined',
'IsOptional',
'Validate',
'ValidateBy',
'ValidateIf',
'ValidateNested',
'ValidatePromise',
'IsLatLong',
'IsLatitude',
'IsLongitude',
'Equals',
'NotEquals',
'IsEmpty',
'IsNotEmpty',
'IsIn',
'IsNotIn',
'IsDivisibleBy',
'IsPositive',
'IsNegative',
'Max',
'Min',
'MinDate',
'MaxDate',
'Contains',
'NotContains',
'IsAlpha',
'IsAlphanumeric',
'IsDecimal',
'IsAscii',
'IsBase64',
'IsByteLength',
'IsCreditCard',
'IsCurrency',
'IsEmail',
'IsFQDN',
'IsFullWidth',
'IsHalfWidth',
'IsVariableWidth',
'IsHexColor',
'IsHexadecimal',
'IsMacAddress',
'IsIP',
'IsPort',
'IsISBN',
'IsISIN',
'IsISO8601',
'IsJSON',
'IsJWT',
'IsLowercase',
'IsMobilePhone',
'IsISO31661Alpha2',
'IsISO31661Alpha3',
'IsMongoId',
'IsMultibyte',
'IsSurrogatePair',
'IsUrl',
'IsUUID',
'IsFirebasePushId',
'IsUppercase',
'Length',
'MaxLength',
'MinLength',
'Matches',
'IsPhoneNumber',
'IsMilitaryTime',
'IsHash',
'IsISSN',
'IsDateString',
'IsBooleanString',
'IsNumberString',
'IsBase32',
'IsBIC',
'IsBtcAddress',
'IsDataURI',
'IsEAN',
'IsEthereumAddress',
'IsHSL',
'IsIBAN',
'IsIdentityCard',
'IsISRC',
'IsLocale',
'IsMagnetURI',
'IsMimeType',
'IsOctal',
'IsPassportNumber',
'IsPostalCode',
'IsRFC3339',
'IsRgbColor',
'IsSemVer',
'IsStrongPassword',
'IsTimeZone',
'IsBase58',
'id',
'code',
'IsBoolean',
'IsDate',
'IsNumber',
'IsEnum',
'IsInt',
'IsString',
'IsArray',
'IsObject',
'ArrayContains',
'ArrayNotContains',
'ArrayNotEmpty',
'ArrayMinSize',
'ArrayMaxSize',
'ArrayUnique',
'IsNotEmptyObject',
'IsInstance',
],
},
];
this.decoratorImportMap = new Map(this.decoratorCategories.flatMap(({ importPath, names }) => names.map((name) => [name, importPath])));
}
verifyIfDecoratorIsValid(decoratorName) {
const match = decoratorName.match(/^@?(\w+)/);
const name = match ? match[1] : decoratorName;
return this.decoratorImportMap.has(name);
}
verifyDocumentation(doc) {
const lines = doc.trim().split('\n');
let result = '';
for (const line of lines) {
const match = line.match(/^@(\w+)/);
if (match && this.decoratorImportMap.has(match[1])) {
result += `\n${line}`;
}
}
return result;
}
getValidatorAndImports(decoratorName) {
const importPath = this.decoratorImportMap.get(decoratorName);
if (!importPath)
return undefined;
return { importPath, decoratorName };
}
}
exports.DecoratorStrategy = DecoratorStrategy;