@steroidsjs/nest 1.4.43 → 1.4.44

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/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@steroidsjs/nest",
3
- "version": "1.4.43",
3
+ "version": "1.4.44",
4
4
  "scripts": {
5
- "build": "tsc && copyfiles ./{package.json,LICENSE,README.md} dist/",
5
+ "copy-assets": "copyfiles ./{package.json,LICENSE,README.md} dist/ && copyfiles src/infrastructure/commands/entity-generator/templates/*.txt dist/",
6
+ "build": "tsc && npm run copy-assets",
6
7
  "watch": "tsc -p tsconfig-debug.json",
7
8
  "test": "jest --config jest.e2e.config.ts"
8
9
  },
@@ -24,32 +25,32 @@
24
25
  "@nestjs/common": "^8.4.1",
25
26
  "@nestjs/config": "^1.2.0",
26
27
  "@nestjs/core": "^8.4.1",
28
+ "@nestjs/platform-express": "^8.4.1",
27
29
  "@nestjs/swagger": "^5.2.0",
28
30
  "@nestjs/typeorm": "^8.0.3",
29
- "@nestjs/platform-express": "^8.4.1",
30
31
  "@sqltools/formatter": "^1.2.3",
31
32
  "class-transformer": "^0.5.1",
32
33
  "class-validator": "^0.13.2",
34
+ "date-fns": "^2.28.0",
33
35
  "express": "^4.17.3",
34
36
  "lodash": "^4.17.21",
35
37
  "nestjs-command": "^3.1.1",
36
38
  "pluralize": "^8.0.0",
39
+ "rxjs": "^7.2.0",
37
40
  "typedi": "^0.10.0",
38
41
  "typeorm": "^0.2.45",
39
- "uuid": "^8.3.2",
40
- "date-fns": "^2.28.0",
41
- "rxjs": "^7.2.0"
42
+ "uuid": "^8.3.2"
42
43
  },
43
44
  "devDependencies": {
44
- "@types/node": "^16.11.7",
45
+ "@jest/globals": "^27.4.6",
46
+ "@types/jest": "^27.4.0",
47
+ "@types/node": "^18.7.23",
45
48
  "copyfiles": "^2.4.1",
46
- "tsconfig-paths": "^3.10.1",
47
- "typescript": "^4.3.5",
49
+ "jest": "^27.4.7",
50
+ "pg": "^8.7.1",
48
51
  "ts-jest": "^27.1.3",
49
52
  "ts-node": "^10.0.0",
50
- "jest": "^27.4.7",
51
- "@types/jest": "^27.4.0",
52
- "@jest/globals": "^27.4.6",
53
- "pg": "^8.7.1"
53
+ "tsconfig-paths": "^3.10.1",
54
+ "typescript": "^4.3.5"
54
55
  }
55
56
  }
@@ -0,0 +1,3 @@
1
+ export declare class EntityCodeGenerateCommand {
2
+ index(entityName: string, moduleName: string): Promise<void>;
3
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.EntityCodeGenerateCommand = void 0;
16
+ const nestjs_command_1 = require("nestjs-command");
17
+ const common_1 = require("@nestjs/common");
18
+ const EntityCodeGenerator_1 = require("./EntityCodeGenerator");
19
+ let EntityCodeGenerateCommand = class EntityCodeGenerateCommand {
20
+ async index(entityName, moduleName) {
21
+ if (!entityName || !moduleName) {
22
+ throw new Error('Required parameters are not provided');
23
+ }
24
+ (new EntityCodeGenerator_1.EntityCodeGenerator(entityName, moduleName)).generate();
25
+ }
26
+ };
27
+ __decorate([
28
+ (0, nestjs_command_1.Command)({
29
+ command: 'entity:generate <entityName> <moduleName>',
30
+ describe: 'Generate code for entity (model, repository, dtos and so on...)',
31
+ }),
32
+ __param(0, (0, nestjs_command_1.Positional)({
33
+ name: 'entityName',
34
+ describe: 'A name of entity to generate',
35
+ type: 'string',
36
+ })),
37
+ __param(1, (0, nestjs_command_1.Positional)({
38
+ name: 'moduleName',
39
+ describe: 'A module to put the code in',
40
+ type: 'string',
41
+ })),
42
+ __metadata("design:type", Function),
43
+ __metadata("design:paramtypes", [String, String]),
44
+ __metadata("design:returntype", Promise)
45
+ ], EntityCodeGenerateCommand.prototype, "index", null);
46
+ EntityCodeGenerateCommand = __decorate([
47
+ (0, common_1.Injectable)()
48
+ ], EntityCodeGenerateCommand);
49
+ exports.EntityCodeGenerateCommand = EntityCodeGenerateCommand;
50
+ //# sourceMappingURL=EntityCodeGenerateCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityCodeGenerateCommand.js","sourceRoot":"","sources":["../../../../../src/infrastructure/commands/entity-generator/EntityCodeGenerateCommand.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,mDAAmD;AACnD,2CAA0C;AAC1C,+DAA0D;AAI1D,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;IASlC,KAAK,CAAC,KAAK,CAMH,UAAkB,EAMlB,UAAkB;QAEtB,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;SAC3D;QAED,CAAC,IAAI,yCAAmB,CACpB,UAAU,EACV,UAAU,CACb,CAAC,CAAC,QAAQ,EAAE,CAAC;IAClB,CAAC;CACJ,CAAA;AAvBG;IAJC,IAAA,wBAAO,EAAC;QACL,OAAO,EAAE,2CAA2C;QACpD,QAAQ,EAAE,iEAAiE;KAC9E,CAAC;IAEG,WAAA,IAAA,2BAAU,EAAC;QACR,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,8BAA8B;QACxC,IAAI,EAAE,QAAQ;KACjB,CAAC,CAAA;IAED,WAAA,IAAA,2BAAU,EAAC;QACR,IAAI,EAAE,YAAY;QAClB,QAAQ,EAAE,6BAA6B;QACvC,IAAI,EAAE,QAAQ;KACjB,CAAC,CAAA;;;;sDAWL;AA/BQ,yBAAyB;IADrC,IAAA,mBAAU,GAAE;GACA,yBAAyB,CAgCrC;AAhCY,8DAAyB"}
@@ -0,0 +1,10 @@
1
+ export declare class EntityCodeGenerator {
2
+ readonly entityName: string;
3
+ readonly moduleName: string;
4
+ readonly projectRootPath: string;
5
+ readonly modulePath: string;
6
+ constructor(entityName: string, moduleName: string, rootPath?: string);
7
+ generate(): void;
8
+ private generateFileByType;
9
+ private findModulePath;
10
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityCodeGenerator = void 0;
4
+ const fs = require("node:fs");
5
+ const path = require("path");
6
+ const lodash_1 = require("lodash");
7
+ const ENTITY_NAME_PLACEHOLDER = '%entityName%';
8
+ const resultPaths = {
9
+ model: 'domain/models/%entityName%Model.ts',
10
+ repository: 'infrastructure/repositories/%entityName%Repository.ts',
11
+ repositoryInterface: 'domain/interfaces/I%entityName%Repository.ts',
12
+ table: 'infrastructure/tables/%entityName%Table.ts',
13
+ service: 'domain/services/%entityName%Service.ts',
14
+ saveDto: 'domain/dtos/%entityName%SaveDto.ts',
15
+ searchDto: 'domain/dtos/%entityName%SearchDto.ts',
16
+ };
17
+ const templates = {
18
+ model: 'ModelTemplate.txt',
19
+ repository: 'RepositoryTemplate.txt',
20
+ repositoryInterface: 'RepositoryInterfaceTemplate.txt',
21
+ table: 'TableTemplate.txt',
22
+ service: 'ServiceTemplate.txt',
23
+ saveDto: 'SaveDtoTemplate.txt',
24
+ searchDto: 'SearchDtoTemplate.txt',
25
+ };
26
+ class EntityCodeGenerator {
27
+ constructor(entityName, moduleName, rootPath = null) {
28
+ if (entityName[0].toUpperCase() !== entityName[0]) {
29
+ this.entityName = entityName.charAt(0).toUpperCase() + entityName.slice(1);
30
+ }
31
+ else {
32
+ this.entityName = entityName;
33
+ }
34
+ this.moduleName = moduleName;
35
+ this.projectRootPath = rootPath || process.cwd();
36
+ this.modulePath = this.findModulePath(moduleName);
37
+ }
38
+ generate() {
39
+ const allFileTypes = Object.keys(templates);
40
+ for (const fileType of allFileTypes) {
41
+ this.generateFileByType(fileType);
42
+ }
43
+ }
44
+ generateFileByType(fileType) {
45
+ const templatePath = path.resolve(__dirname, 'templates');
46
+ let templateContent = fs.readFileSync(path.resolve(templatePath, templates[fileType]), 'utf8');
47
+ const resultFileContent = templateContent.replace(new RegExp(`${(0, lodash_1.escapeRegExp)(ENTITY_NAME_PLACEHOLDER)}`, 'g'), this.entityName);
48
+ let resultFilePath = path.resolve(this.modulePath, resultPaths[fileType].replace(ENTITY_NAME_PLACEHOLDER, this.entityName));
49
+ const resultFileDirPath = path.dirname(resultFilePath);
50
+ if (!fs.existsSync(resultFileDirPath)) {
51
+ fs.mkdirSync(resultFileDirPath, { recursive: true });
52
+ }
53
+ fs.writeFileSync(resultFilePath, resultFileContent);
54
+ }
55
+ findModulePath(moduleName) {
56
+ let possibleModulePaths = [
57
+ path.resolve(this.projectRootPath, 'src', moduleName),
58
+ path.resolve(this.projectRootPath, moduleName),
59
+ ];
60
+ for (const path of possibleModulePaths) {
61
+ if (fs.existsSync(path)) {
62
+ return path;
63
+ }
64
+ }
65
+ throw new Error('No module with a provided name is found');
66
+ }
67
+ }
68
+ exports.EntityCodeGenerator = EntityCodeGenerator;
69
+ //# sourceMappingURL=EntityCodeGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EntityCodeGenerator.js","sourceRoot":"","sources":["../../../../../src/infrastructure/commands/entity-generator/EntityCodeGenerator.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,6BAA6B;AAC7B,mCAAoC;AAEpC,MAAM,uBAAuB,GAAG,cAAc,CAAC;AAE/C,MAAM,WA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AAC;CACJ;AA7ED,kDA6EC"}
@@ -0,0 +1,3 @@
1
+ export class %entityName%Model {
2
+
3
+ }
@@ -0,0 +1,6 @@
1
+ import {ICrudRepository} from '@steroidsjs/nest/src/usecases/interfaces/ICrudRepository';
2
+ import {%entityName%Model} from '../models/%entityName%Model';
3
+
4
+ export const I%entityName%Repository = 'I%entityName%Repository';
5
+
6
+ export type I%entityName%Repository = ICrudRepository<%entityName%Model>
@@ -0,0 +1,18 @@
1
+ import {Repository} from 'typeorm';
2
+ import {Injectable} from '@nestjs/common';
3
+ import {InjectRepository} from '@nestjs/typeorm';
4
+ import {CrudRepository} from '@steroidsjs/nest/src/infrastructure/repositories/CrudRepository';
5
+ import {%entityName%Model} from '../../domain/models/%entityName%Model';
6
+ import {%entityName%Table} from '../tables/%entityName%Table';
7
+
8
+ @Injectable()
9
+ export class %entityName%Repository extends CrudRepository<%entityName%Model> {
10
+ constructor(
11
+ @InjectRepository(%entityName%Table)
12
+ public dbRepository: Repository<%entityName%Table>,
13
+ ) {
14
+ super();
15
+ }
16
+
17
+ protected modelClass = %entityName%Model;
18
+ }
@@ -0,0 +1,3 @@
1
+ export class %entityName%SaveDto {
2
+
3
+ }
@@ -0,0 +1,5 @@
1
+ import {SearchInputDto} from '@steroidsjs/nest/src/usecases/dtos/SearchInputDto';
2
+
3
+ export class %entityName%SearchDto extends SearchInputDto {
4
+
5
+ }
@@ -0,0 +1,16 @@
1
+ import {CrudService} from '@steroidsjs/nest/src/usecases/services/CrudService';
2
+ import {%entityName%SearchDto} from '../dtos/%entityName%SearchDto';
3
+ import {%entityName%SaveDto} from '../dtos/%entityName%SaveDto';
4
+ import {%entityName%Model} from '../models/%entityName%Model';
5
+ import {I%entityName%Repository} from '../interfaces/I%entityName%Repository';
6
+
7
+ export class %entityName%Service extends CrudService<%entityName%Model, %entityName%SearchDto, %entityName%SaveDto> {
8
+ protected modelClass = %entityName%Model;
9
+
10
+ constructor(
11
+ /** %entityName%Repository */
12
+ public repository: I%entityName%Repository,
13
+ ) {
14
+ super();
15
+ }
16
+ }
@@ -0,0 +1,6 @@
1
+ import {DeepPartial} from 'typeorm';
2
+ import {TableFromModel} from '@steroidsjs/nest/src/infrastructure/decorators/TableFromModel';
3
+ import {%entityName%Model} from '../../domain/models/%entityName%Model';
4
+
5
+ @TableFromModel(%entityName%Model, '%entityName%')
6
+ export class %entityName%Table implements DeepPartial<%entityName%Model> {}