@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
30 lines • 1.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoerceOperationTableActionRule = CoerceOperationTableActionRule;
const ts_morph_1 = require("@rxap/ts-morph");
const ts_morph_2 = require("ts-morph");
const coerce_imports_1 = require("../ts-morph/coerce-imports");
const coerce_table_action_1 = require("./coerce-table-action");
function CoerceOperationTableActionRule(options) {
let { tsMorphTransform, operationId, tableName, type, scope, } = options;
tsMorphTransform !== null && tsMorphTransform !== void 0 ? tsMorphTransform : (tsMorphTransform = () => ({}));
return (0, coerce_table_action_1.CoerceTableActionRule)(Object.assign(Object.assign({}, options), { tsMorphTransform: (project, sourceFile, classDeclaration) => {
(0, ts_morph_1.CoerceDependencyInjection)(sourceFile, {
injectionToken: (0, ts_morph_1.OperationIdToRemoteMethodClassName)(operationId),
parameterName: 'method',
scope: ts_morph_2.Scope.Private,
module: ts_morph_1.Module.ANGULAR,
});
(0, coerce_imports_1.CoerceImports)(sourceFile, {
namedImports: [(0, ts_morph_1.OperationIdToRemoteMethodClassName)(operationId)],
moduleSpecifier: (0, ts_morph_1.OperationIdToClassRemoteMethodImportPath)(operationId, scope),
});
return Object.assign({ statements: [
`console.log(\`action row type: ${type}\`, parameters);`,
`const { __rowId: rowId } = parameters;`,
`if (!rowId) { throw new Error('The table action ${type} is called with a row object that does not have the property rowId.'); }`,
`return this.method.call({ parameters: { rowId } });`,
], returnType: `Promise<void>` }, tsMorphTransform(project, sourceFile, classDeclaration));
} }));
}
//# sourceMappingURL=coerce-operation-table-action.js.map