@devstroupe/devkit-cli 1.0.0
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/README.md +40 -0
- package/dist/boilerplates/angular-template/.dockerignore +4 -0
- package/dist/boilerplates/angular-template/.postcssrc.json +5 -0
- package/dist/boilerplates/angular-template/Dockerfile +14 -0
- package/dist/boilerplates/angular-template/angular.json +85 -0
- package/dist/boilerplates/angular-template/components.json +5 -0
- package/dist/boilerplates/angular-template/framework.code-workspace +7 -0
- package/dist/boilerplates/angular-template/nginx.conf +23 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/browserslist +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/jiti +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/lessc +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/ng +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/ng-xi18n +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/ngc +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/sass +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/terser +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/tsc +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/tsserver +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/vite +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/vitest +21 -0
- package/dist/boilerplates/angular-template/node_modules/.bin/yaml +21 -0
- package/dist/boilerplates/angular-template/package.json +47 -0
- package/dist/boilerplates/angular-template/postcss.config.js +5 -0
- package/dist/boilerplates/angular-template/proxy.conf.json +7 -0
- package/dist/boilerplates/angular-template/src/app/app.component.html +3 -0
- package/dist/boilerplates/angular-template/src/app/app.component.ts +12 -0
- package/dist/boilerplates/angular-template/src/app/app.config.ts +59 -0
- package/dist/boilerplates/angular-template/src/app/app.entity-routes.ts +4 -0
- package/dist/boilerplates/angular-template/src/app/app.routes.ts +25 -0
- package/dist/boilerplates/angular-template/src/app/core/guards/auth.guard.ts +16 -0
- package/dist/boilerplates/angular-template/src/app/core/services/auth.service.ts +98 -0
- package/dist/boilerplates/angular-template/src/app/modules/auth/login/login.component.html +51 -0
- package/dist/boilerplates/angular-template/src/app/modules/auth/login/login.component.ts +47 -0
- package/dist/boilerplates/angular-template/src/app/modules/auth/register/register.component.html +59 -0
- package/dist/boilerplates/angular-template/src/app/modules/auth/register/register.component.ts +47 -0
- package/dist/boilerplates/angular-template/src/app/modules/dashboard/dashboard.component.html +14 -0
- package/dist/boilerplates/angular-template/src/app/modules/dashboard/dashboard.component.ts +23 -0
- package/dist/boilerplates/angular-template/src/app/shared/interceptors/tenant.interceptor.ts +25 -0
- package/dist/boilerplates/angular-template/src/index.html +64 -0
- package/dist/boilerplates/angular-template/src/main.ts +6 -0
- package/dist/boilerplates/angular-template/src/styles.css +9 -0
- package/dist/boilerplates/angular-template/tsconfig.json +36 -0
- package/dist/boilerplates/nest-template/Dockerfile +16 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/acorn +21 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/nest +21 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/prettier +21 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/tsc +21 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/tsserver +21 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/typeorm +21 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/typeorm-ts-node-commonjs +21 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/typeorm-ts-node-esm +21 -0
- package/dist/boilerplates/nest-template/node_modules/.bin/webpack +21 -0
- package/dist/boilerplates/nest-template/package.json +43 -0
- package/dist/boilerplates/nest-template/src/app.module.ts +24 -0
- package/dist/boilerplates/nest-template/src/database/data-source.ts +16 -0
- package/dist/boilerplates/nest-template/src/database/migrations/1700000000000-create-users.ts +26 -0
- package/dist/boilerplates/nest-template/src/main.ts +46 -0
- package/dist/boilerplates/nest-template/src/modules/auth/auth.controller.ts +34 -0
- package/dist/boilerplates/nest-template/src/modules/auth/auth.module.ts +22 -0
- package/dist/boilerplates/nest-template/src/modules/auth/auth.service.ts +57 -0
- package/dist/boilerplates/nest-template/src/modules/auth/current-user.decorator.ts +8 -0
- package/dist/boilerplates/nest-template/src/modules/auth/jwt-auth.guard.ts +31 -0
- package/dist/boilerplates/nest-template/src/modules/auth/roles.decorator.ts +4 -0
- package/dist/boilerplates/nest-template/src/modules/auth/roles.guard.ts +24 -0
- package/dist/boilerplates/nest-template/src/modules/user/database-seed.service.ts +47 -0
- package/dist/boilerplates/nest-template/src/modules/user/domain/user.repository.ts +9 -0
- package/dist/boilerplates/nest-template/src/modules/user/domain/user.ts +9 -0
- package/dist/boilerplates/nest-template/src/modules/user/infra/database/user.orm-entity.ts +31 -0
- package/dist/boilerplates/nest-template/src/modules/user/infra/database/user.repository.adapter.ts +53 -0
- package/dist/boilerplates/nest-template/src/modules/user/service/user.service.ts +44 -0
- package/dist/boilerplates/nest-template/src/modules/user/user.module.ts +20 -0
- package/dist/boilerplates/nest-template/tsconfig.build.json +4 -0
- package/dist/boilerplates/nest-template/tsconfig.json +21 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1967 -0
- package/dist/migrations/sort-entities.d.ts +2 -0
- package/dist/migrations/sort-entities.js +30 -0
- package/dist/rules/linter-rules.d.ts +12 -0
- package/dist/rules/linter-rules.js +338 -0
- package/dist/rules/linter-rules.test.d.ts +1 -0
- package/dist/rules/linter-rules.test.js +214 -0
- package/dist/templates/angular/dialog-handler.template.d.ts +2 -0
- package/dist/templates/angular/dialog-handler.template.js +49 -0
- package/dist/templates/angular/form.template.d.ts +3 -0
- package/dist/templates/angular/form.template.js +453 -0
- package/dist/templates/angular/index.d.ts +4 -0
- package/dist/templates/angular/index.js +20 -0
- package/dist/templates/angular/list.template.d.ts +3 -0
- package/dist/templates/angular/list.template.js +213 -0
- package/dist/templates/angular/service.template.d.ts +1 -0
- package/dist/templates/angular/service.template.js +20 -0
- package/dist/templates/cli-templates.d.ts +2 -0
- package/dist/templates/cli-templates.js +18 -0
- package/dist/templates/nest/crud.templates.d.ts +9 -0
- package/dist/templates/nest/crud.templates.js +362 -0
- package/dist/templates/nest/index.d.ts +3 -0
- package/dist/templates/nest/index.js +19 -0
- package/dist/templates/nest/microservice.templates.d.ts +4 -0
- package/dist/templates/nest/microservice.templates.js +157 -0
- package/dist/templates/nest/migration.template.d.ts +3 -0
- package/dist/templates/nest/migration.template.js +127 -0
- package/dist/templates/relationship-templates.test.d.ts +1 -0
- package/dist/templates/relationship-templates.test.js +181 -0
- package/dist/templates/shared/names.d.ts +3 -0
- package/dist/templates/shared/names.js +14 -0
- package/dist/templates/shared/relationships.d.ts +27 -0
- package/dist/templates/shared/relationships.js +96 -0
- package/dist/templates/ui/components/avatar.template.d.ts +3 -0
- package/dist/templates/ui/components/avatar.template.js +66 -0
- package/dist/templates/ui/components/badge.template.d.ts +3 -0
- package/dist/templates/ui/components/badge.template.js +27 -0
- package/dist/templates/ui/components/button.template.d.ts +5 -0
- package/dist/templates/ui/components/button.template.js +64 -0
- package/dist/templates/ui/components/card-list.template.d.ts +5 -0
- package/dist/templates/ui/components/card-list.template.js +79 -0
- package/dist/templates/ui/components/dialog.template.d.ts +5 -0
- package/dist/templates/ui/components/dialog.template.js +51 -0
- package/dist/templates/ui/components/filter.template.d.ts +4 -0
- package/dist/templates/ui/components/filter.template.js +218 -0
- package/dist/templates/ui/components/index.d.ts +10 -0
- package/dist/templates/ui/components/index.js +26 -0
- package/dist/templates/ui/components/input.template.d.ts +4 -0
- package/dist/templates/ui/components/input.template.js +76 -0
- package/dist/templates/ui/components/select.template.d.ts +4 -0
- package/dist/templates/ui/components/select.template.js +176 -0
- package/dist/templates/ui/components/simple-list.template.d.ts +5 -0
- package/dist/templates/ui/components/simple-list.template.js +89 -0
- package/dist/templates/ui/components/table.template.d.ts +5 -0
- package/dist/templates/ui/components/table.template.js +112 -0
- package/dist/templates/ui/index.d.ts +9 -0
- package/dist/templates/ui/index.js +25 -0
- package/dist/templates/ui/layout/header.template.d.ts +5 -0
- package/dist/templates/ui/layout/header.template.js +236 -0
- package/dist/templates/ui/layout/index.d.ts +4 -0
- package/dist/templates/ui/layout/index.js +20 -0
- package/dist/templates/ui/layout/main-layout.template.d.ts +5 -0
- package/dist/templates/ui/layout/main-layout.template.js +126 -0
- package/dist/templates/ui/layout/shell.template.d.ts +5 -0
- package/dist/templates/ui/layout/shell.template.js +76 -0
- package/dist/templates/ui/layout/sidebar.template.d.ts +5 -0
- package/dist/templates/ui/layout/sidebar.template.js +412 -0
- package/dist/templates/ui/playground.template.d.ts +5 -0
- package/dist/templates/ui/playground.template.js +570 -0
- package/dist/templates/ui/readme.template.d.ts +1 -0
- package/dist/templates/ui/readme.template.js +23 -0
- package/dist/templates/ui/shared/colors.d.ts +1 -0
- package/dist/templates/ui/shared/colors.js +31 -0
- package/dist/templates/ui/shared/profile-component.template.d.ts +5 -0
- package/dist/templates/ui/shared/profile-component.template.js +403 -0
- package/dist/templates/ui/shared/profile-service.template.d.ts +1 -0
- package/dist/templates/ui/shared/profile-service.template.js +44 -0
- package/dist/templates/ui/shared/theme-service.template.d.ts +1 -0
- package/dist/templates/ui/shared/theme-service.template.js +47 -0
- package/dist/templates/ui/spartan/badge-directive.template.d.ts +3 -0
- package/dist/templates/ui/spartan/badge-directive.template.js +50 -0
- package/dist/templates/ui/spartan/button-directive.template.d.ts +3 -0
- package/dist/templates/ui/spartan/button-directive.template.js +82 -0
- package/dist/templates/ui/spartan/button-token.template.d.ts +3 -0
- package/dist/templates/ui/spartan/button-token.template.js +31 -0
- package/dist/templates/ui/spartan/hlm-core.template.d.ts +3 -0
- package/dist/templates/ui/spartan/hlm-core.template.js +322 -0
- package/dist/templates/ui/spartan/index.d.ts +5 -0
- package/dist/templates/ui/spartan/index.js +21 -0
- package/dist/templates/ui/spartan/input-directive.template.d.ts +3 -0
- package/dist/templates/ui/spartan/input-directive.template.js +31 -0
- package/dist/templates/ui/theme-css.template.d.ts +7 -0
- package/dist/templates/ui/theme-css.template.js +210 -0
- package/dist/templates/ui-templates.d.ts +1 -0
- package/dist/templates/ui-templates.js +17 -0
- package/package.json +50 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.angularListHtmlTemplate = angularListHtmlTemplate;
|
|
4
|
+
exports.angularListTsTemplate = angularListTsTemplate;
|
|
5
|
+
const names_1 = require("../shared/names");
|
|
6
|
+
const relationships_1 = require("../shared/relationships");
|
|
7
|
+
function angularListHtmlTemplate(name, properties, listType = 'table', formType = 'page', filterType = 'popover') {
|
|
8
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
9
|
+
let listComponentHtml = '';
|
|
10
|
+
if (listType === 'card') {
|
|
11
|
+
listComponentHtml = ` <!-- Lista em Cards Dinâmica -->
|
|
12
|
+
<devkit-card-list
|
|
13
|
+
[columns]="columns"
|
|
14
|
+
[items]="items"
|
|
15
|
+
(rowClick)="editItem($event.id)"
|
|
16
|
+
></devkit-card-list>`;
|
|
17
|
+
}
|
|
18
|
+
else if (listType === 'list') {
|
|
19
|
+
listComponentHtml = ` <!-- Lista Simples Dinâmica -->
|
|
20
|
+
<devkit-simple-list
|
|
21
|
+
[columns]="columns"
|
|
22
|
+
[items]="items"
|
|
23
|
+
(rowClick)="editItem($event.id)"
|
|
24
|
+
></devkit-simple-list>`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
listComponentHtml = ` <!-- Tabela Dinâmica -->
|
|
28
|
+
<devkit-table
|
|
29
|
+
[columns]="columns"
|
|
30
|
+
[items]="items"
|
|
31
|
+
[currentSort]="$any(filter).sort || ''"
|
|
32
|
+
[currentDirection]="$any(filter).direction || 'ASC'"
|
|
33
|
+
[striped]="true"
|
|
34
|
+
(sortChange)="onSort($event)"
|
|
35
|
+
(rowClick)="editItem($event.id)"
|
|
36
|
+
></devkit-table>`;
|
|
37
|
+
}
|
|
38
|
+
const routerOutletHtml = formType === 'dialog' ? '\n <!-- Outlet para carregar o Dialog Handler -->\n <router-outlet></router-outlet>' : '';
|
|
39
|
+
return `<div class="flex flex-col space-y-4 text-foreground">
|
|
40
|
+
<div class="flex justify-between items-center">
|
|
41
|
+
<h1 class="text-2xl font-bold tracking-tight text-foreground">${pascalName}s</h1>
|
|
42
|
+
<devkit-button (btnClick)="createItem()">Criar Novo</devkit-button>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<!-- Filtros Dinâmicos -->
|
|
46
|
+
<devkit-filter [config]="filterConfig" [initialValues]="$any(filter).filter || emptyFilter" [displayMode]="'${filterType}'" (filterApplied)="onFilter($event)"></devkit-filter>
|
|
47
|
+
|
|
48
|
+
${listComponentHtml}
|
|
49
|
+
${routerOutletHtml}
|
|
50
|
+
</div>
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
function angularListTsTemplate(name, properties, listType = 'table', formType = 'page') {
|
|
54
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
55
|
+
const relationships = (0, relationships_1.getRelationships)(properties);
|
|
56
|
+
const singularRelationships = relationships.filter((relationship) => (0, relationships_1.isSingularRelationship)(relationship.kind));
|
|
57
|
+
const filterConfig = properties
|
|
58
|
+
.filter((p) => p.type !== 'relationship')
|
|
59
|
+
.map((p) => {
|
|
60
|
+
let typeStr = 'text';
|
|
61
|
+
if (p.type === 'boolean')
|
|
62
|
+
typeStr = 'boolean';
|
|
63
|
+
if (p.type === 'datepicker')
|
|
64
|
+
typeStr = 'datepicker';
|
|
65
|
+
return ` { key: '${p.name}', label: '${p.label}', type: '${typeStr}' }`;
|
|
66
|
+
})
|
|
67
|
+
.concat(singularRelationships.map((relationship) => {
|
|
68
|
+
const stateName = relationship.property.name.replace(/[-_](.)/g, (_, character) => character.toUpperCase());
|
|
69
|
+
return ` {
|
|
70
|
+
key: '${relationship.foreignKey}',
|
|
71
|
+
label: '${relationship.property.label}',
|
|
72
|
+
type: 'select',
|
|
73
|
+
options: this.${stateName}Lookup.options,
|
|
74
|
+
searchable: ${relationship.lookupMode === 'remote'},
|
|
75
|
+
loading: this.${stateName}Lookup.loading,
|
|
76
|
+
hasMore: this.${stateName}Lookup.hasMore,
|
|
77
|
+
onSearch: (search: string) => this.${stateName}Lookup.setSearch(search),
|
|
78
|
+
onLoadMore: () => this.${stateName}Lookup.loadMore()
|
|
79
|
+
}`;
|
|
80
|
+
}))
|
|
81
|
+
.join(',\n');
|
|
82
|
+
const colsCode = properties
|
|
83
|
+
.filter((p) => p.type !== 'relationship' || (0, relationships_1.getRelationships)([p])[0].kind !== 'one-to-many')
|
|
84
|
+
.map((p) => {
|
|
85
|
+
if (p.type === 'relationship') {
|
|
86
|
+
const relationship = (0, relationships_1.getRelationships)([p])[0];
|
|
87
|
+
return ` { key: '${relationship.relationName}.${relationship.displayField}', label: '${p.label}', sortable: false }`;
|
|
88
|
+
}
|
|
89
|
+
return ` { key: '${p.name}', label: '${p.label}', sortable: true }`;
|
|
90
|
+
})
|
|
91
|
+
.join(',\n');
|
|
92
|
+
let importComponent = '';
|
|
93
|
+
let componentName = '';
|
|
94
|
+
if (listType === 'card') {
|
|
95
|
+
importComponent = "import { DevkitCardListComponent } from '@devstroupe/ui/card-list/card-list.component';";
|
|
96
|
+
componentName = 'DevkitCardListComponent';
|
|
97
|
+
}
|
|
98
|
+
else if (listType === 'list') {
|
|
99
|
+
importComponent = "import { DevkitSimpleListComponent } from '@devstroupe/ui/simple-list/simple-list.component';";
|
|
100
|
+
componentName = 'DevkitSimpleListComponent';
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
importComponent = "import { DevkitTableComponent } from '@devstroupe/ui/table/table.component';";
|
|
104
|
+
componentName = 'DevkitTableComponent';
|
|
105
|
+
}
|
|
106
|
+
const isDialog = formType === 'dialog';
|
|
107
|
+
const routeImports = isDialog
|
|
108
|
+
? "import { ActivatedRoute, Router } from '@angular/router';\nimport { RouterModule } from '@angular/router';"
|
|
109
|
+
: "import { ActivatedRoute, Router } from '@angular/router';";
|
|
110
|
+
const createNavigation = isDialog
|
|
111
|
+
? `this._router.navigate(['new'], { relativeTo: this._route });`
|
|
112
|
+
: `this._router.navigate(['/${name}/new']);`;
|
|
113
|
+
const editNavigation = isDialog
|
|
114
|
+
? `this._router.navigate([id, 'edit'], { relativeTo: this._route });`
|
|
115
|
+
: `this._router.navigate(['/${name}/', id, 'edit']);`;
|
|
116
|
+
const relatedTargets = [...new Set(singularRelationships.map((relationship) => relationship.target))];
|
|
117
|
+
const relationshipServiceImports = relatedTargets
|
|
118
|
+
.map((target) => `import { ${(0, names_1.kebabToPascal)(target)}Service } from '../../../services/${target}.service';`)
|
|
119
|
+
.join('\n');
|
|
120
|
+
const relationshipInjections = singularRelationships.map((relationship) => {
|
|
121
|
+
const stateName = relationship.property.name.replace(/[-_](.)/g, (_, character) => character.toUpperCase());
|
|
122
|
+
return ` private ${stateName}Service = inject(${(0, names_1.kebabToPascal)(relationship.target)}Service);`;
|
|
123
|
+
}).join('\n');
|
|
124
|
+
const relationshipState = singularRelationships.map((relationship) => {
|
|
125
|
+
const stateName = relationship.property.name.replace(/[-_](.)/g, (_, character) => character.toUpperCase());
|
|
126
|
+
const limitOverride = relationship.lookupMode === 'all' ? `, limit: 'all'` : '';
|
|
127
|
+
return ` readonly ${stateName}Lookup = new RelationshipLookup<any>({
|
|
128
|
+
loader: (filter) => this.${stateName}Service.list({
|
|
129
|
+
...filter${limitOverride},
|
|
130
|
+
filter: { ...(filter.filter ?? {}), ...${JSON.stringify(relationship.filters)} }
|
|
131
|
+
}),
|
|
132
|
+
valueField: '${relationship.valueField}',
|
|
133
|
+
displayField: '${relationship.displayField}',
|
|
134
|
+
pageSize: ${relationship.pageSize},
|
|
135
|
+
minSearchLength: ${relationship.minSearchLength}
|
|
136
|
+
});`;
|
|
137
|
+
}).join('\n\n');
|
|
138
|
+
const relationshipLoadCalls = singularRelationships.map((relationship) => {
|
|
139
|
+
const stateName = relationship.property.name.replace(/[-_](.)/g, (_, character) => character.toUpperCase());
|
|
140
|
+
return ` this.${stateName}Lookup.load();
|
|
141
|
+
const selected${(0, names_1.kebabToPascal)(stateName)} = this.filter.filter?.['${relationship.foreignKey}'];
|
|
142
|
+
if (selected${(0, names_1.kebabToPascal)(stateName)}) {
|
|
143
|
+
this.${stateName}Service.findOne(selected${(0, names_1.kebabToPascal)(stateName)}).subscribe(item => this.${stateName}Lookup.include(item));
|
|
144
|
+
}`;
|
|
145
|
+
}).join('\n');
|
|
146
|
+
const relationshipDestroyCalls = singularRelationships.map((relationship) => {
|
|
147
|
+
const stateName = relationship.property.name.replace(/[-_](.)/g, (_, character) => character.toUpperCase());
|
|
148
|
+
return ` this.${stateName}Lookup.destroy();`;
|
|
149
|
+
}).join('\n');
|
|
150
|
+
return `import { ChangeDetectorRef, Component, OnInit, OnDestroy, inject } from '@angular/core';
|
|
151
|
+
import { CommonModule } from '@angular/common';
|
|
152
|
+
import { BaseListPage, RelationshipLookup } from '@devstroupe/devkit-angular';
|
|
153
|
+
import { ITableColumn } from '@devstroupe/ui/table/table.component';
|
|
154
|
+
${importComponent}
|
|
155
|
+
import { DevkitFilterComponent, FilterItemConfig } from '@devstroupe/ui/filter/filter.component';
|
|
156
|
+
import { DevkitButtonComponent } from '@devstroupe/ui/button/button.component';
|
|
157
|
+
${routeImports}
|
|
158
|
+
${relationshipServiceImports}
|
|
159
|
+
import { ${pascalName}Service } from '../../../services/${name}.service';
|
|
160
|
+
|
|
161
|
+
@Component({
|
|
162
|
+
selector: 'app-${name}-list',
|
|
163
|
+
standalone: true,
|
|
164
|
+
imports: [CommonModule, ${componentName}, DevkitFilterComponent, DevkitButtonComponent${isDialog ? ', RouterModule' : ''}],
|
|
165
|
+
templateUrl: './${name}-list.component.html'
|
|
166
|
+
})
|
|
167
|
+
export class ${pascalName}ListComponent extends BaseListPage<any> implements OnInit, OnDestroy {
|
|
168
|
+
readonly emptyFilter: Record<string, never> = {};
|
|
169
|
+
protected override service = inject(${pascalName}Service);
|
|
170
|
+
private _router = inject(Router);
|
|
171
|
+
private _route = inject(ActivatedRoute);
|
|
172
|
+
private _changeDetector = inject(ChangeDetectorRef);
|
|
173
|
+
${relationshipInjections}
|
|
174
|
+
|
|
175
|
+
${relationshipState}
|
|
176
|
+
|
|
177
|
+
ngOnInit(): void {
|
|
178
|
+
this.initBaseListPage(this._router, this._route, this._changeDetector);
|
|
179
|
+
${relationshipLoadCalls}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
ngOnDestroy(): void {
|
|
183
|
+
this.destroyBaseListPage();
|
|
184
|
+
${relationshipDestroyCalls}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
columns: ITableColumn[] = [
|
|
188
|
+
{ key: 'id', label: 'ID', sortable: true },
|
|
189
|
+
${colsCode}
|
|
190
|
+
];
|
|
191
|
+
|
|
192
|
+
readonly filterConfig: FilterItemConfig[] = [
|
|
193
|
+
${filterConfig}
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
createItem(): void {
|
|
197
|
+
${createNavigation}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
editItem(id: any): void {
|
|
201
|
+
${editNavigation}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
onFilter(values: any): void {
|
|
205
|
+
this.updateQueryParams({ filter: values, page: 1 });
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
onSort(event: { sort: string; direction: 'ASC' | 'DESC' }): void {
|
|
209
|
+
this.updateQueryParams({ sort: event.sort, direction: event.direction });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
`;
|
|
213
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function angularServiceTemplate(name: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.angularServiceTemplate = angularServiceTemplate;
|
|
4
|
+
const names_1 = require("../shared/names");
|
|
5
|
+
function angularServiceTemplate(name) {
|
|
6
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
7
|
+
return `import { Injectable } from '@angular/core';
|
|
8
|
+
import { HttpClient } from '@angular/common/http';
|
|
9
|
+
import { BaseService } from '@devstroupe/devkit-angular';
|
|
10
|
+
|
|
11
|
+
@Injectable({
|
|
12
|
+
providedIn: 'root',
|
|
13
|
+
})
|
|
14
|
+
export class ${pascalName}Service extends BaseService<any> {
|
|
15
|
+
constructor(http: HttpClient) {
|
|
16
|
+
super(http, '/api/${name}');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./nest"), exports);
|
|
18
|
+
__exportStar(require("./angular"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IDevkitEntityProperty } from '@devstroupe/devkit-core';
|
|
2
|
+
export declare function nestDomainEntityTemplate(name: string, properties: IDevkitEntityProperty[], isTenantScoped: boolean): string;
|
|
3
|
+
export declare function nestRepositoryPortTemplate(name: string): string;
|
|
4
|
+
export declare function nestOrmEntityTemplate(name: string, properties: IDevkitEntityProperty[], tableName: string, isTenantScoped: boolean): string;
|
|
5
|
+
export declare function nestRepositoryAdapterTemplate(name: string, properties: IDevkitEntityProperty[], isTenantScoped: boolean): string;
|
|
6
|
+
export declare function nestDtoTemplate(name: string, properties: IDevkitEntityProperty[]): string;
|
|
7
|
+
export declare function nestServiceTemplate(name: string): string;
|
|
8
|
+
export declare function nestControllerTemplate(name: string): string;
|
|
9
|
+
export declare function nestModuleTemplate(name: string): string;
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nestDomainEntityTemplate = nestDomainEntityTemplate;
|
|
4
|
+
exports.nestRepositoryPortTemplate = nestRepositoryPortTemplate;
|
|
5
|
+
exports.nestOrmEntityTemplate = nestOrmEntityTemplate;
|
|
6
|
+
exports.nestRepositoryAdapterTemplate = nestRepositoryAdapterTemplate;
|
|
7
|
+
exports.nestDtoTemplate = nestDtoTemplate;
|
|
8
|
+
exports.nestServiceTemplate = nestServiceTemplate;
|
|
9
|
+
exports.nestControllerTemplate = nestControllerTemplate;
|
|
10
|
+
exports.nestModuleTemplate = nestModuleTemplate;
|
|
11
|
+
const names_1 = require("../shared/names");
|
|
12
|
+
const relationships_1 = require("../shared/relationships");
|
|
13
|
+
function nestDomainEntityTemplate(name, properties, isTenantScoped) {
|
|
14
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
15
|
+
const propsCode = properties
|
|
16
|
+
.map((p) => {
|
|
17
|
+
if (p.type === 'relationship') {
|
|
18
|
+
const relation = (0, relationships_1.getRelationships)([p])[0];
|
|
19
|
+
if (relation.kind === 'one-to-many') {
|
|
20
|
+
return ` ${relation.relationName}?: any[];`;
|
|
21
|
+
}
|
|
22
|
+
if (relation.kind === 'many-to-many') {
|
|
23
|
+
return ` ${relation.relationName}?: any[];`;
|
|
24
|
+
}
|
|
25
|
+
return ` ${relation.foreignKey}!: number;\n ${relation.relationName}?: any;`;
|
|
26
|
+
}
|
|
27
|
+
const typeStr = p.type === 'number' ? 'number' : p.type === 'boolean' ? 'boolean' : 'string';
|
|
28
|
+
return ` ${p.name}!: ${typeStr};`;
|
|
29
|
+
})
|
|
30
|
+
.join('\n');
|
|
31
|
+
const tenantField = isTenantScoped ? '\n tenantId!: string;' : '';
|
|
32
|
+
return `export class ${pascalName} {
|
|
33
|
+
id!: number;
|
|
34
|
+
${propsCode}${tenantField}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
function nestRepositoryPortTemplate(name) {
|
|
39
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
40
|
+
return `import { IPaginator, IFilterPagination } from '@devstroupe/devkit-core';
|
|
41
|
+
import { ${pascalName} } from './${name}';
|
|
42
|
+
|
|
43
|
+
export interface I${pascalName}Repository {
|
|
44
|
+
create(data: Partial<${pascalName}>): Promise<${pascalName}>;
|
|
45
|
+
update(id: number, data: Partial<${pascalName}>): Promise<${pascalName}>;
|
|
46
|
+
findOne(id: number): Promise<${pascalName} | null>;
|
|
47
|
+
findMany(filter: IFilterPagination): Promise<IPaginator<${pascalName}>>;
|
|
48
|
+
delete(id: number): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
}
|
|
52
|
+
function nestOrmEntityTemplate(name, properties, tableName, isTenantScoped) {
|
|
53
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
54
|
+
const relationships = (0, relationships_1.getRelationships)(properties);
|
|
55
|
+
const typeormImports = ['Entity', 'PrimaryGeneratedColumn', 'Column'];
|
|
56
|
+
if (relationships.some((relation) => relation.kind === 'many-to-one'))
|
|
57
|
+
typeormImports.push('ManyToOne');
|
|
58
|
+
if (relationships.some((relation) => relation.kind === 'one-to-one'))
|
|
59
|
+
typeormImports.push('OneToOne');
|
|
60
|
+
if (relationships.some((relation) => relation.kind === 'one-to-many'))
|
|
61
|
+
typeormImports.push('OneToMany');
|
|
62
|
+
if (relationships.some((relation) => relation.kind === 'many-to-many'))
|
|
63
|
+
typeormImports.push('ManyToMany');
|
|
64
|
+
if (relationships.some((relation) => (0, relationships_1.isSingularRelationship)(relation.kind) && relation.owner))
|
|
65
|
+
typeormImports.push('JoinColumn');
|
|
66
|
+
if (relationships.some((relation) => relation.kind === 'many-to-many' && relation.owner))
|
|
67
|
+
typeormImports.push('JoinTable');
|
|
68
|
+
const relImports = [...new Set(relationships.map((relation) => relation.target))]
|
|
69
|
+
.map((targetKebab) => {
|
|
70
|
+
const targetPascal = (0, names_1.kebabToPascal)(targetKebab);
|
|
71
|
+
return `import { ${targetPascal}OrmEntity } from '../../../${targetKebab}/infra/database/${targetKebab}.orm-entity';`;
|
|
72
|
+
})
|
|
73
|
+
.join('\n');
|
|
74
|
+
const propsCode = properties
|
|
75
|
+
.map((p) => {
|
|
76
|
+
if (p.type === 'relationship') {
|
|
77
|
+
const relation = (0, relationships_1.getRelationships)([p])[0];
|
|
78
|
+
const targetPascal = (0, names_1.kebabToPascal)(relation.target);
|
|
79
|
+
const inverseSide = relation.inverseSide
|
|
80
|
+
?? relation.foreignKey?.replace(/_id$/, '')
|
|
81
|
+
?? name;
|
|
82
|
+
const inverse = inverseSide ? `, target => target.${inverseSide}` : '';
|
|
83
|
+
const options = `{ onDelete: '${relation.onDelete}', nullable: ${!p.required} }`;
|
|
84
|
+
if (relation.kind === 'one-to-many') {
|
|
85
|
+
return ` @OneToMany(() => ${targetPascal}OrmEntity, target => target.${inverseSide})\n ${relation.relationName}?: ${targetPascal}OrmEntity[];`;
|
|
86
|
+
}
|
|
87
|
+
if (relation.kind === 'many-to-many') {
|
|
88
|
+
const junctionTable = relation.joinTableName ?? `${name}_${relation.target}`;
|
|
89
|
+
const joinTable = relation.owner ? `\n @JoinTable({
|
|
90
|
+
name: '${junctionTable}',
|
|
91
|
+
joinColumn: { name: '${name}_id', referencedColumnName: 'id' },
|
|
92
|
+
inverseJoinColumn: { name: '${relation.target}_id', referencedColumnName: '${relation.valueField}' }
|
|
93
|
+
})` : '';
|
|
94
|
+
return ` @ManyToMany(() => ${targetPascal}OrmEntity${relation.inverseSide ? inverse : ''})${joinTable}\n ${relation.relationName}?: ${targetPascal}OrmEntity[];`;
|
|
95
|
+
}
|
|
96
|
+
const decorator = relation.kind === 'one-to-one' ? 'OneToOne' : 'ManyToOne';
|
|
97
|
+
const fkDecorator = p.required ? '@Column()' : '@Column({ nullable: true })';
|
|
98
|
+
const joinColumn = relation.owner ? `\n @JoinColumn({ name: '${relation.foreignKey}', referencedColumnName: '${relation.valueField}' })` : '';
|
|
99
|
+
return ` ${fkDecorator}\n ${relation.foreignKey}!: number;\n\n @${decorator}(() => ${targetPascal}OrmEntity${relation.inverseSide ? inverse : ''}, ${options})${joinColumn}\n ${relation.relationName}?: ${targetPascal}OrmEntity;`;
|
|
100
|
+
}
|
|
101
|
+
const decorator = p.required ? '@Column()' : '@Column({ nullable: true })';
|
|
102
|
+
const typeStr = p.type === 'number' ? 'number' : p.type === 'boolean' ? 'boolean' : 'string';
|
|
103
|
+
return ` ${decorator}\n ${p.name}!: ${typeStr};`;
|
|
104
|
+
})
|
|
105
|
+
.join('\n\n');
|
|
106
|
+
const tenantField = isTenantScoped ? '\n\n @Column()\n tenantId!: string;' : '';
|
|
107
|
+
const relImportsStr = relImports ? `\n${relImports}` : '';
|
|
108
|
+
return `import { ${typeormImports.join(', ')} } from 'typeorm';${relImportsStr}
|
|
109
|
+
|
|
110
|
+
@Entity('${tableName}')
|
|
111
|
+
export class ${pascalName}OrmEntity {
|
|
112
|
+
@PrimaryGeneratedColumn()
|
|
113
|
+
id!: number;
|
|
114
|
+
|
|
115
|
+
${propsCode}${tenantField}
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
}
|
|
119
|
+
function nestRepositoryAdapterTemplate(name, properties, isTenantScoped) {
|
|
120
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
121
|
+
const tenantInject = isTenantScoped ? `import { Inject, Scope } from '@nestjs/common';\nimport { REQUEST } from '@nestjs/core';\n` : '';
|
|
122
|
+
const tenantConstructor = isTenantScoped ? `,\n @Inject(REQUEST) private readonly request: any` : '';
|
|
123
|
+
const tenantIdGetter = isTenantScoped ? `\n private get tenantId(): string {\n return this.request?.data?.tenantId || this.request?.tenantId || this.request?.headers?.['x-tenant-id'] || 'default';\n }\n` : '';
|
|
124
|
+
const relationships = (0, relationships_1.getRelationships)(properties);
|
|
125
|
+
const relKeys = relationships
|
|
126
|
+
.filter((relation) => relation.kind !== 'one-to-many')
|
|
127
|
+
.map((relation) => relation.relationName);
|
|
128
|
+
const persistedProperties = properties.filter((property) => {
|
|
129
|
+
if (property.type !== 'relationship')
|
|
130
|
+
return true;
|
|
131
|
+
return (0, relationships_1.getRelationships)([property])[0].kind !== 'one-to-many';
|
|
132
|
+
});
|
|
133
|
+
const allowedProperties = persistedProperties.flatMap((property) => {
|
|
134
|
+
if (property.type !== 'relationship')
|
|
135
|
+
return [property.name];
|
|
136
|
+
const relation = (0, relationships_1.getRelationships)([property])[0];
|
|
137
|
+
return (0, relationships_1.isSingularRelationship)(relation.kind) ? [relation.foreignKey] : [];
|
|
138
|
+
});
|
|
139
|
+
const relationsOption = relKeys.length > 0 ? `, relations: [${relKeys.map(r => `'${r}'`).join(', ')}]` : '';
|
|
140
|
+
const joinsCode = relKeys.map((r) => `\n qb.leftJoinAndSelect(\`\${alias}.${r}\`, '${r}');`).join('');
|
|
141
|
+
const mapRels = relKeys.map((r) => ` if (orm.${r}) domain.${r} = orm.${r};`).join('\n');
|
|
142
|
+
const mapToDomainProperties = properties
|
|
143
|
+
.filter((property) => property.type !== 'relationship')
|
|
144
|
+
.map((property) => ` domain.${property.name} = orm.${property.name};`)
|
|
145
|
+
.concat(relationships
|
|
146
|
+
.filter((relation) => (0, relationships_1.isSingularRelationship)(relation.kind))
|
|
147
|
+
.map((relation) => ` domain.${relation.foreignKey} = orm.${relation.foreignKey};`))
|
|
148
|
+
.join('\n');
|
|
149
|
+
const mapToOrmProperties = persistedProperties.map((property) => {
|
|
150
|
+
if (property.type !== 'relationship') {
|
|
151
|
+
return ` if (domain.${property.name} !== undefined) orm.${property.name} = domain.${property.name};`;
|
|
152
|
+
}
|
|
153
|
+
const relation = (0, relationships_1.getRelationships)([property])[0];
|
|
154
|
+
if (relation.kind === 'many-to-many') {
|
|
155
|
+
return ` if (domain.${relation.relationName} !== undefined) orm.${relation.relationName} = domain.${relation.relationName}!.map((item: any) => typeof item === 'object' ? item : ({ ${relation.valueField}: item } as any));`;
|
|
156
|
+
}
|
|
157
|
+
return ` if (domain.${relation.foreignKey} !== undefined) orm.${relation.foreignKey} = domain.${relation.foreignKey};`;
|
|
158
|
+
}).join('\n');
|
|
159
|
+
return `import { Injectable } from '@nestjs/common';
|
|
160
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
161
|
+
import { Repository } from 'typeorm';
|
|
162
|
+
import { BaseRepository } from '@devstroupe/devkit-nest';
|
|
163
|
+
import { IPaginator, IFilterPagination } from '@devstroupe/devkit-core';
|
|
164
|
+
import { ${pascalName}OrmEntity } from './${name}.orm-entity';
|
|
165
|
+
import { ${pascalName} } from '../../domain/${name}';
|
|
166
|
+
import { I${pascalName}Repository } from '../../domain/${name}.repository.port';
|
|
167
|
+
${tenantInject}
|
|
168
|
+
@Injectable(${isTenantScoped ? '{ scope: Scope.REQUEST }' : ''})
|
|
169
|
+
export class ${pascalName}RepositoryAdapter extends BaseRepository<${pascalName}OrmEntity> implements I${pascalName}Repository {
|
|
170
|
+
constructor(
|
|
171
|
+
@InjectRepository(${pascalName}OrmEntity)
|
|
172
|
+
private readonly ormRepository: Repository<${pascalName}OrmEntity>${tenantConstructor}
|
|
173
|
+
) {
|
|
174
|
+
super(ormRepository);
|
|
175
|
+
}
|
|
176
|
+
${tenantIdGetter}
|
|
177
|
+
async create(data: Partial<${pascalName}>): Promise<${pascalName}> {
|
|
178
|
+
const entity = this.ormRepository.create(this.mapToOrm(data));${isTenantScoped ? '\n entity.tenantId = this.tenantId;' : ''}
|
|
179
|
+
const saved = await this.ormRepository.save(entity);
|
|
180
|
+
return (await this.findOne(saved.id))!;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async update(id: number, data: Partial<${pascalName}>): Promise<${pascalName}> {
|
|
184
|
+
const existing = await this.findOne(id);
|
|
185
|
+
if (!existing) {
|
|
186
|
+
throw new Error(\`${pascalName} with ID \${id} not found\`);
|
|
187
|
+
}
|
|
188
|
+
const entity = await this.ormRepository.preload({ id, ...this.mapToOrm(data) } as any);
|
|
189
|
+
if (!entity) {
|
|
190
|
+
throw new Error(\`${pascalName} with ID \${id} not found\`);
|
|
191
|
+
}
|
|
192
|
+
await this.ormRepository.save(entity);
|
|
193
|
+
const updated = await this.findOne(id);
|
|
194
|
+
return updated!;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async findOne(id: number): Promise<${pascalName} | null> {
|
|
198
|
+
const entity = await this.ormRepository.findOne({
|
|
199
|
+
where: { id${isTenantScoped ? ', tenantId: this.tenantId' : ''} } as any${relationsOption}
|
|
200
|
+
});
|
|
201
|
+
return entity ? this.mapToDomain(entity) : null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async findMany(filter: IFilterPagination): Promise<IPaginator<${pascalName}>> {
|
|
205
|
+
const alias = '${name}';
|
|
206
|
+
const qb = this.ormRepository.createQueryBuilder(alias);${isTenantScoped ? `\n qb.andWhere(\`\${alias}.tenantId = :tenantId\`, { tenantId: this.tenantId });` : ''}${joinsCode}
|
|
207
|
+
|
|
208
|
+
const paginated = await this.paginate(qb, filter, {
|
|
209
|
+
allowedFilters: [${allowedProperties.map(property => `'${property}'`).join(', ')}],
|
|
210
|
+
allowedSorts: [${allowedProperties.map(property => `'${property}'`).join(', ')}],
|
|
211
|
+
searchableFields: [${properties.filter(p => p.type === 'string').map(p => `'${p.name}'`).join(', ') || "'id'"}],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
items: paginated.items.map(item => this.mapToDomain(item)),
|
|
216
|
+
meta: paginated.meta
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async delete(id: number): Promise<void> {${isTenantScoped ? `\n const entity = await this.findOne(id);\n if (entity) {\n await this.ormRepository.delete(id);\n }` : `\n await this.ormRepository.delete(id);`}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private mapToDomain(orm: ${pascalName}OrmEntity): ${pascalName} {
|
|
224
|
+
const domain = new ${pascalName}();
|
|
225
|
+
domain.id = orm.id;
|
|
226
|
+
${mapToDomainProperties}${isTenantScoped ? '\n domain.tenantId = orm.tenantId;' : ''}
|
|
227
|
+
${mapRels}
|
|
228
|
+
return domain;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private mapToOrm(domain: Partial<${pascalName}>): Partial<${pascalName}OrmEntity> {
|
|
232
|
+
const orm: Partial<${pascalName}OrmEntity> = {};
|
|
233
|
+
if (domain.id !== undefined) orm.id = domain.id;
|
|
234
|
+
${mapToOrmProperties}${isTenantScoped ? '\n if (domain.tenantId !== undefined) orm.tenantId = domain.tenantId;' : ''}
|
|
235
|
+
return orm;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
`;
|
|
239
|
+
}
|
|
240
|
+
function nestDtoTemplate(name, properties) {
|
|
241
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
242
|
+
const createProps = properties
|
|
243
|
+
.filter((p) => p.type !== 'relationship' || (0, relationships_1.getRelationships)([p])[0].kind !== 'one-to-many')
|
|
244
|
+
.map((p) => {
|
|
245
|
+
const relationship = p.type === 'relationship' ? (0, relationships_1.getRelationships)([p])[0] : undefined;
|
|
246
|
+
const isArray = relationship?.kind === 'many-to-many';
|
|
247
|
+
const apiProperty = `@ApiProperty({ example: ${isArray ? '[1, 2]' : p.type === 'number' || p.type === 'relationship' ? '1' : p.type === 'boolean' ? 'true' : "'value'"}, description: '${p.label}'${isArray ? ', isArray: true' : ''} })`;
|
|
248
|
+
const suffix = p.required ? '!' : '?';
|
|
249
|
+
const typeStr = isArray ? 'number[]' : p.type === 'number' || p.type === 'relationship' ? 'number' : p.type === 'boolean' ? 'boolean' : 'string';
|
|
250
|
+
const propertyName = relationship?.kind === 'many-to-many' ? relationship.relationName : p.name;
|
|
251
|
+
return ` ${apiProperty}\n ${propertyName}${suffix}: ${typeStr};`;
|
|
252
|
+
})
|
|
253
|
+
.join('\n\n');
|
|
254
|
+
return `import { ApiProperty } from '@nestjs/swagger';
|
|
255
|
+
|
|
256
|
+
export class Create${pascalName}Dto {
|
|
257
|
+
${createProps}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export class Update${pascalName}Dto extends Create${pascalName}Dto {}
|
|
261
|
+
|
|
262
|
+
export class Filter${pascalName}Dto {
|
|
263
|
+
@ApiProperty({ required: false })
|
|
264
|
+
page?: number;
|
|
265
|
+
|
|
266
|
+
@ApiProperty({ required: false })
|
|
267
|
+
limit?: number | 'all' | 'todos';
|
|
268
|
+
|
|
269
|
+
@ApiProperty({ required: false })
|
|
270
|
+
search?: string;
|
|
271
|
+
|
|
272
|
+
@ApiProperty({ required: false })
|
|
273
|
+
sort?: string;
|
|
274
|
+
|
|
275
|
+
@ApiProperty({ required: false })
|
|
276
|
+
direction?: 'ASC' | 'DESC';
|
|
277
|
+
|
|
278
|
+
@ApiProperty({ required: false, type: Object })
|
|
279
|
+
filter?: Record<string, any>;
|
|
280
|
+
}
|
|
281
|
+
`;
|
|
282
|
+
}
|
|
283
|
+
function nestServiceTemplate(name) {
|
|
284
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
285
|
+
return `import { Injectable, Inject } from '@nestjs/common';
|
|
286
|
+
import { I${pascalName}Repository } from '../domain/${name}.repository.port';
|
|
287
|
+
import { ${pascalName} } from '../domain/${name}';
|
|
288
|
+
import { Create${pascalName}Dto, Update${pascalName}Dto, Filter${pascalName}Dto } from '../infra/http/${name}.dto';
|
|
289
|
+
|
|
290
|
+
@Injectable()
|
|
291
|
+
export class ${pascalName}Service {
|
|
292
|
+
constructor(
|
|
293
|
+
@Inject('I${pascalName}Repository')
|
|
294
|
+
private readonly repository: I${pascalName}Repository
|
|
295
|
+
) {}
|
|
296
|
+
|
|
297
|
+
async create(dto: Create${pascalName}Dto): Promise<${pascalName}> {
|
|
298
|
+
return await this.repository.create(dto);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async update(id: number, dto: Update${pascalName}Dto): Promise<${pascalName}> {
|
|
302
|
+
return await this.repository.update(id, dto);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
async findOne(id: number): Promise<${pascalName} | null> {
|
|
306
|
+
return await this.repository.findOne(id);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async findMany(filter: Filter${pascalName}Dto) {
|
|
310
|
+
return await this.repository.findMany(filter);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async delete(id: number): Promise<void> {
|
|
314
|
+
await this.repository.delete(id);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
`;
|
|
318
|
+
}
|
|
319
|
+
function nestControllerTemplate(name) {
|
|
320
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
321
|
+
const camelName = (0, names_1.kebabToCamel)(name);
|
|
322
|
+
return `import { Controller } from '@nestjs/common';
|
|
323
|
+
import { ApiTags } from '@nestjs/swagger';
|
|
324
|
+
import { BaseCrudController } from '@devstroupe/devkit-nest';
|
|
325
|
+
import { ${pascalName}Service } from '../../service/${name}.service';
|
|
326
|
+
import { ${pascalName} } from '../../domain/${name}';
|
|
327
|
+
import { Filter${pascalName}Dto } from './${name}.dto';
|
|
328
|
+
|
|
329
|
+
@Controller('${name}')
|
|
330
|
+
@ApiTags('${name}')
|
|
331
|
+
export class ${pascalName}Controller extends BaseCrudController<${pascalName}, Filter${pascalName}Dto> {
|
|
332
|
+
constructor(private readonly ${camelName}Service: ${pascalName}Service) {
|
|
333
|
+
super(${camelName}Service);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
`;
|
|
337
|
+
}
|
|
338
|
+
function nestModuleTemplate(name) {
|
|
339
|
+
const pascalName = (0, names_1.kebabToPascal)(name);
|
|
340
|
+
return `import { Module } from '@nestjs/common';
|
|
341
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
342
|
+
import { ${pascalName}OrmEntity } from './infra/database/${name}.orm-entity';
|
|
343
|
+
import { ${pascalName}RepositoryAdapter } from './infra/database/${name}.repository';
|
|
344
|
+
import { ${pascalName}Service } from './service/${name}.service';
|
|
345
|
+
import { ${pascalName}Controller } from './infra/http/${name}.controller';
|
|
346
|
+
|
|
347
|
+
@Module({
|
|
348
|
+
imports: [TypeOrmModule.forFeature([${pascalName}OrmEntity])],
|
|
349
|
+
controllers: [${pascalName}Controller],
|
|
350
|
+
providers: [
|
|
351
|
+
${pascalName}Service,
|
|
352
|
+
{
|
|
353
|
+
provide: 'I${pascalName}Repository',
|
|
354
|
+
useClass: ${pascalName}RepositoryAdapter,
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
exports: [${pascalName}Service],
|
|
358
|
+
})
|
|
359
|
+
export class ${pascalName}Module {}
|
|
360
|
+
`;
|
|
361
|
+
}
|
|
362
|
+
// ---------------- Angular Templates ----------------
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./crud.templates"), exports);
|
|
18
|
+
__exportStar(require("./microservice.templates"), exports);
|
|
19
|
+
__exportStar(require("./migration.template"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function nestGatewayControllerTemplate(name: string): string;
|
|
2
|
+
export declare function nestGatewayModuleTemplate(name: string, defaultPort: number): string;
|
|
3
|
+
export declare function nestMsControllerTemplate(name: string): string;
|
|
4
|
+
export declare function nestMsModuleTemplate(name: string): string;
|