UNPKG

@rxap/schematics-ts-morph

Version:

This package provides utilities for manipulating TypeScript code using ts-morph, particularly for Angular and NestJS projects. It offers functions to add, coerce, and modify code elements like classes, methods, decorators, and imports. The package also in

76 lines 3.83 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BuildOptionsDtoDataMapperImplementation = BuildOptionsDtoDataMapperImplementation; exports.CoerceOptionsOperationRule = CoerceOptionsOperationRule; const ts_morph_1 = require("@rxap/ts-morph"); const utilities_1 = require("@rxap/utilities"); const coerce_operation_1 = require("./coerce-operation"); function BuildOptionsDtoDataMapperImplementation(classDeclaration, moduleSourceFile, dto, options) { const { isArray, upstream, } = options; return () => { var _a, _b, _c; if (upstream) { if ((0, ts_morph_1.IsNormalizedOpenApiUpstreamOptions)(upstream)) { const { mapper } = upstream; let toFunction = 'ToOptions'; let toValue = null; let toDisplay = null; if (mapper && (0, ts_morph_1.IsNormalizedOptionsRequestMapper)(mapper)) { toFunction = (_a = mapper.toFunction) !== null && _a !== void 0 ? _a : toFunction; toValue = (_b = mapper.toValue) !== null && _b !== void 0 ? _b : toValue; toDisplay = (_c = mapper.toDisplay) !== null && _c !== void 0 ? _c : toDisplay; } const sourceFile = classDeclaration.getSourceFile(); switch (toFunction) { case ts_morph_1.ToOptionsFunction.TO_OPTIONS: (0, ts_morph_1.CoerceImports)(sourceFile, { namedImports: [ts_morph_1.ToOptionsFunction.TO_OPTIONS], moduleSpecifier: '@rxap/utilities', }); break; case ts_morph_1.ToOptionsFunction.TO_OPTIONS_FROM_OBJECT: (0, ts_morph_1.CoerceImports)(sourceFile, { namedImports: [ts_morph_1.ToOptionsFunction.TO_OPTIONS_FROM_OBJECT], moduleSpecifier: '@rxap/utilities', }); break; } return w => { w.write(toFunction); w.write('(data'); if (toValue) { w.write(`, ${toValue}`); } if (toDisplay) { if (!toValue) { w.write(', undefined'); } w.write(`, ${toDisplay}`); } w.write(')'); }; } } // TODO : implement the data mapper return isArray ? '[]' : '{}'; }; } function CoerceOptionsOperationRule(options) { const { control, builtDtoDataMapperImplementation = BuildOptionsDtoDataMapperImplementation, isArray = true, responseDtoName, propertyList = [ { name: 'display', type: 'string', }, { name: 'value', type: control.type, }, ], } = options; return (0, coerce_operation_1.CoerceOperation)(Object.assign(Object.assign({}, options), { propertyList, isArray, builtDtoDataMapperImplementation, buildOperationDtoClassName: (controllerName, { dtoClassName, dtoClassNameSuffix }) => { const className = responseDtoName !== null && responseDtoName !== void 0 ? responseDtoName : (0, utilities_1.joinWithDash)([dtoClassName !== null && dtoClassName !== void 0 ? dtoClassName : controllerName, control.name, 'control', 'options']); return dtoClassName !== null && dtoClassName !== void 0 ? dtoClassName : (dtoClassNameSuffix ? (0, utilities_1.CoerceSuffix)(className, dtoClassNameSuffix) : className); } })); } //# sourceMappingURL=coerce-options-operation.js.map