UNPKG

@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

52 lines (51 loc) 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CreateDtoFieldConfig = void 0; const annotations_1 = require("../../annotations"); const field_classifiers_1 = require("../../field-classifiers"); class CreateDtoFieldConfig { constructor(templateHelpers) { this.templateHelpers = templateHelpers; this.relationModifiers = annotations_1.DTO_RELATION_MODIFIERS_ON_CREATE; this.canCreateAnnotation = annotations_1.DTO_RELATION_CAN_CRAEATE_ON_CREATE; this.canConnectAnnotation = annotations_1.DTO_RELATION_CAN_CONNECT_ON_CREATE; this.optionalAnnotation = annotations_1.DTO_CREATE_OPTIONAL; this.dtoNameGenerator = (name) => { return this.templateHelpers.createDtoName(name); }; this.fieldFilters = { shouldSkipField: (field) => { return (0, field_classifiers_1.isReadOnly)(field); }, shouldProcessOptional: (field) => { const isDtoOptional = (0, field_classifiers_1.isAnnotatedWith)(field, annotations_1.DTO_CREATE_OPTIONAL); if (!isDtoOptional) { return ((0, field_classifiers_1.isIdWithDefaultValue)(field) || (0, field_classifiers_1.isUpdatedAt)(field) || (0, field_classifiers_1.isRequiredWithDefaultValue)(field)); } return false; }, }; this.getFieldOverrides = (field) => { const overrides = {}; if (field.kind === 'object') { const isDtoRelationRequired = (0, field_classifiers_1.isAnnotatedWith)(field, annotations_1.DTO_RELATION_REQUIRED); if (isDtoRelationRequired) { overrides.isRequired = true; } if (field.isList) { overrides.isRequired = false; } } else { const isDtoOptional = (0, field_classifiers_1.isAnnotatedWith)(field, annotations_1.DTO_CREATE_OPTIONAL); if (isDtoOptional) { overrides.isRequired = false; } } return overrides; }; } } exports.CreateDtoFieldConfig = CreateDtoFieldConfig;