@avleon/cli 0.0.46 → 0.0.47
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/dist/cli.js +61 -87
- package/dist/commands.js +27 -19
- package/dist/controller.js +25 -21
- package/dist/create.js +116 -102
- package/dist/helpers/path-helper.js +19 -4
- package/dist/service.js +9 -13
- package/package.json +62 -62
- package/readme.md +116 -66
- package/stubs/app/app-controller.stub +13 -11
- package/stubs/app/app-minimal.stub +7 -17
- package/stubs/config.stub +15 -11
- package/stubs/controllers/basic-controller.stub +9 -12
- package/stubs/controllers/orm-rest-controller.stub +45 -52
- package/stubs/controllers/rest-controller.stub +29 -34
- package/stubs/models/basic-model.stub +4 -6
- package/stubs/models/entity-model.stub +18 -23
- package/stubs/serve.stub +10 -10
- package/stubs/services/basic-service.stub +8 -9
- package/stubs/services/orm-rest-service.stub +60 -73
- package/stubs/services/rest-service.stub +34 -71
- package/stubs/app/app-withdb.stub +0 -0
- package/stubs/basic-controller.stub +0 -7
- package/stubs/model.stub +0 -0
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
app.
|
|
8
|
-
app.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
app.
|
|
1
|
+
import { Avleon } from '@avleon/core';
|
|
2
|
+
import { OpenApiConfig } from './config/openapi.config';
|
|
3
|
+
import { HomeController } from './controllers/home.controller';
|
|
4
|
+
|
|
5
|
+
const app = Avleon.createApplication();
|
|
6
|
+
|
|
7
|
+
if (app.isDevelopment()) {
|
|
8
|
+
app.useOpenApi(OpenApiConfig);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
app.useControllers([HomeController]);
|
|
12
|
+
|
|
13
|
+
export default app;
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const app = builder.build();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if(app.isDevelopment()){
|
|
13
|
-
app.useOpenApi((config:AppConfig)=> config.openApi);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
app.mapGet('/', () => "Hello World!");
|
|
17
|
-
export default app;
|
|
1
|
+
import { Avleon } from '@avleon/core';
|
|
2
|
+
|
|
3
|
+
const app = Avleon.createApplication();
|
|
4
|
+
|
|
5
|
+
app.mapGet('/', () => 'Hello World!');
|
|
6
|
+
|
|
7
|
+
export default app;
|
package/stubs/config.stub
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
@
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
1
|
+
import { AppConfig, AvleonConfig, Environment, OpenApiUiOptions } from '@avleon/core';
|
|
2
|
+
|
|
3
|
+
@AppConfig
|
|
4
|
+
export class OpenApiConfig extends AvleonConfig<OpenApiUiOptions> {
|
|
5
|
+
config(env: Environment): OpenApiUiOptions {
|
|
6
|
+
return {
|
|
7
|
+
info: {
|
|
8
|
+
title: 'My API',
|
|
9
|
+
version: '1.0.0',
|
|
10
|
+
description: 'API documentation',
|
|
11
|
+
},
|
|
12
|
+
routePrefix: '/docs',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { ApiController, Get
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
}
|
|
1
|
+
import { ApiController, Get } from '@avleon/core';
|
|
2
|
+
|
|
3
|
+
@ApiController('/{controller}s')
|
|
4
|
+
export class {Controller}Controller {
|
|
5
|
+
@Get()
|
|
6
|
+
index() {
|
|
7
|
+
return '{controller} ok';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -1,52 +1,45 @@
|
|
|
1
|
-
import { ApiController, Get, Post, Delete, Param, Query, Body, HttpExceptions } from '@avleon/core';
|
|
2
|
-
import { {Model}Service } from '../services/{model}.service';
|
|
3
|
-
|
|
4
|
-
@ApiController('/{controller}s')
|
|
5
|
-
export class {Controller}Controller{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
){
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@
|
|
29
|
-
async
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if(!is{Model}) throw HttpExceptions.notFound("{Model} not found.");
|
|
47
|
-
const isDeleted = await this.{model}Service.delete(id);
|
|
48
|
-
if(!isDeleted) throw HttpExceptions.internalError("Can't delete");
|
|
49
|
-
return "Deleted Successfully";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|
|
1
|
+
import { ApiController, Get, Post, Put, Delete, Param, Query, Body, HttpExceptions } from '@avleon/core';
|
|
2
|
+
import { {Model}Service } from '../services/{model}.service';
|
|
3
|
+
|
|
4
|
+
@ApiController('/{controller}s')
|
|
5
|
+
export class {Controller}Controller {
|
|
6
|
+
constructor(private readonly {model}Service: {Model}Service) {}
|
|
7
|
+
|
|
8
|
+
@Get()
|
|
9
|
+
async index(@Query() query?: any) {
|
|
10
|
+
if (query && query.page) {
|
|
11
|
+
return this.{model}Service.paginate(Number(query.page));
|
|
12
|
+
}
|
|
13
|
+
return this.{model}Service.findAll();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Get('/:id')
|
|
17
|
+
async findOne(@Param('id') id: number) {
|
|
18
|
+
const is{Model} = await this.{model}Service.findByPk(id);
|
|
19
|
+
if (!is{Model}) throw HttpExceptions.notFound('{Model} not found.');
|
|
20
|
+
return is{Model};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Post()
|
|
24
|
+
async create(@Body() body: any) {
|
|
25
|
+
return this.{model}Service.create(body);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Put('/:id')
|
|
29
|
+
async update(@Param('id') id: number, @Body() updateBody: any) {
|
|
30
|
+
const is{Model} = await this.{model}Service.findByPk(id);
|
|
31
|
+
if (!is{Model}) throw HttpExceptions.notFound('{Model} not found.');
|
|
32
|
+
const isUpdated = await this.{model}Service.update(id, updateBody);
|
|
33
|
+
if (!isUpdated) throw HttpExceptions.internalError("Can't update {Model}");
|
|
34
|
+
return 'Updated Successfully';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Delete('/:id')
|
|
38
|
+
async delete(@Param('id') id: number) {
|
|
39
|
+
const is{Model} = await this.{model}Service.findByPk(id);
|
|
40
|
+
if (!is{Model}) throw HttpExceptions.notFound('{Model} not found.');
|
|
41
|
+
const isDeleted = await this.{model}Service.delete(id);
|
|
42
|
+
if (!isDeleted) throw HttpExceptions.internalError("Can't delete {Model}");
|
|
43
|
+
return 'Deleted Successfully';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
import { ApiController, Get, Post, Delete, Param, Query, Body
|
|
2
|
-
|
|
3
|
-
@ApiController('/{controller}s')
|
|
4
|
-
export class {Controller}Controller{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
async delete(@Param('id') id:number){
|
|
31
|
-
throw new Error("Method not implemented.");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}
|
|
1
|
+
import { ApiController, Get, Post, Put, Delete, Param, Query, Body } from '@avleon/core';
|
|
2
|
+
|
|
3
|
+
@ApiController('/{controller}s')
|
|
4
|
+
export class {Controller}Controller {
|
|
5
|
+
@Get()
|
|
6
|
+
async index(@Query() query?: any) {
|
|
7
|
+
throw new Error('Method not implemented.');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@Get('/:id')
|
|
11
|
+
async findOne(@Param('id') id: number) {
|
|
12
|
+
throw new Error('Method not implemented.');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Post()
|
|
16
|
+
async create(@Body() body: any) {
|
|
17
|
+
throw new Error('Method not implemented.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Put('/:id')
|
|
21
|
+
async update(@Param('id') id: number, @Body() updateBody: any) {
|
|
22
|
+
throw new Error('Method not implemented.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Delete('/:id')
|
|
26
|
+
async delete(@Param('id') id: number) {
|
|
27
|
+
throw new Error('Method not implemented.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@UpdateDateColumn()
|
|
22
|
-
updatedAt: Date;
|
|
23
|
-
}
|
|
1
|
+
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn } from 'typeorm';
|
|
2
|
+
|
|
3
|
+
@Entity({ name: '{model}' })
|
|
4
|
+
export class {Model} {
|
|
5
|
+
@PrimaryGeneratedColumn()
|
|
6
|
+
id: number;
|
|
7
|
+
|
|
8
|
+
// your fields
|
|
9
|
+
|
|
10
|
+
// @Column()
|
|
11
|
+
// name: string;
|
|
12
|
+
|
|
13
|
+
@CreateDateColumn()
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
|
|
16
|
+
@UpdateDateColumn()
|
|
17
|
+
updatedAt: Date;
|
|
18
|
+
}
|
package/stubs/serve.stub
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Environment, inject } from
|
|
2
|
-
import app from
|
|
3
|
-
|
|
4
|
-
async function serve() {
|
|
5
|
-
const env = inject(Environment);
|
|
6
|
-
const port = env.get<number>(
|
|
7
|
-
await app.run(port);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
serve();
|
|
1
|
+
import { Environment, inject } from '@avleon/core';
|
|
2
|
+
import app from './app';
|
|
3
|
+
|
|
4
|
+
async function serve() {
|
|
5
|
+
const env = inject(Environment);
|
|
6
|
+
const port = env.get<number>('PORT') || 4000;
|
|
7
|
+
await app.run(port);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
serve();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AppService } from '@avleon/core';
|
|
2
|
-
|
|
3
|
-
@AppService
|
|
4
|
-
export class {Service} {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
import { AppService } from '@avleon/core';
|
|
2
|
+
|
|
3
|
+
@AppService
|
|
4
|
+
export class {Service}Service {
|
|
5
|
+
sayHello() {
|
|
6
|
+
return 'Hello World!';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -1,73 +1,60 @@
|
|
|
1
|
-
import { AppService, InjectRepository } from '@avleon/core';
|
|
2
|
-
import { Repository } from 'typeorm';
|
|
3
|
-
import { {Model} } from '../models/{model}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
){
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async update(id:number, updateBody:any){
|
|
64
|
-
const isUpdate = await this.{model}Repository.update({id}, updateBody);
|
|
65
|
-
return isUpdate.affected > 0;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async delete(id:number){
|
|
69
|
-
const isDeleted = await this.{model}Repository.delete({id});
|
|
70
|
-
return isDeleted.affected > 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
}
|
|
1
|
+
import { AppService, InjectRepository } from '@avleon/core';
|
|
2
|
+
import { Repository } from 'typeorm';
|
|
3
|
+
import { {Model} } from '../models/{model}';
|
|
4
|
+
|
|
5
|
+
@AppService
|
|
6
|
+
export class {Service}Service {
|
|
7
|
+
constructor(
|
|
8
|
+
@InjectRepository({Model})
|
|
9
|
+
private readonly {model}Repository: Repository<{Model}>,
|
|
10
|
+
) {}
|
|
11
|
+
|
|
12
|
+
async findAll(options: any = {}) {
|
|
13
|
+
return this.{model}Repository.find(options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async paginate(current = 1, options: any = {}) {
|
|
17
|
+
const take = 10;
|
|
18
|
+
const skip = current > 1 ? (current - 1) * take : 0;
|
|
19
|
+
const total = await this.{model}Repository.count(options);
|
|
20
|
+
const totalPage = Math.ceil(total / take);
|
|
21
|
+
|
|
22
|
+
const data = await this.{model}Repository.find({ ...options, take, skip });
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
total,
|
|
26
|
+
totalPage,
|
|
27
|
+
current,
|
|
28
|
+
next: current < totalPage ? current + 1 : null,
|
|
29
|
+
prev: current > 1 ? current - 1 : null,
|
|
30
|
+
data,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async findByPk(id: number) {
|
|
35
|
+
return this.{model}Repository.findOneBy({ id } as any);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async findBy(options: any) {
|
|
39
|
+
return this.{model}Repository.findBy(options);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async findOneBy(options: any) {
|
|
43
|
+
return this.{model}Repository.findOneBy(options);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async create(createBody: Partial<{Model}>) {
|
|
47
|
+
const newItem = this.{model}Repository.create(createBody as any);
|
|
48
|
+
return this.{model}Repository.save(newItem);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async update(id: number, updateBody: Partial<{Model}>) {
|
|
52
|
+
const result = await this.{model}Repository.update({ id } as any, updateBody as any);
|
|
53
|
+
return (result.affected ?? 0) > 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async delete(id: number) {
|
|
57
|
+
const result = await this.{model}Repository.delete({ id } as any);
|
|
58
|
+
return (result.affected ?? 0) > 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,71 +1,34 @@
|
|
|
1
|
-
import { AppService, Collection } from '@avleon/core';
|
|
2
|
-
import { {Model} } from '../models/{model}
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
async
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
data
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async findByPk(id:number){
|
|
40
|
-
return this.{model}Collection.findOne({id});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async findBy(options:any){
|
|
44
|
-
return this.{model}Collection.findBy(options);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async findOneBy(options:any){
|
|
48
|
-
return this.{model}Collection.findOneBy(options);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
async findOne(id:number){
|
|
53
|
-
return this.{model}Collection.findOne({where:{id}}) ;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async create(createBody:any){
|
|
57
|
-
const savedItem = await this.{model}Collection.save(createBody);
|
|
58
|
-
return savedItem;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async update(id:number, updateBody:any){
|
|
62
|
-
const isUpdate = await this.{model}Collection.update(id, updateBody);
|
|
63
|
-
return isUpdate;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async delete(id:number){
|
|
67
|
-
const isDeleted = await this.{model}Collection.delete(id);
|
|
68
|
-
return isDeleted > 0;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}
|
|
1
|
+
import { AppService, Collection } from '@avleon/core';
|
|
2
|
+
import { {Model} } from '../models/{model}';
|
|
3
|
+
|
|
4
|
+
@AppService
|
|
5
|
+
export class {Service}Service {
|
|
6
|
+
private readonly {model}Collection = Collection.from<{Model}>([]);
|
|
7
|
+
|
|
8
|
+
async findAll() {
|
|
9
|
+
return this.{model}Collection.find();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async paginate(page = 1, take = 10) {
|
|
13
|
+
const skip = page > 1 ? (page - 1) * take : 0;
|
|
14
|
+
return this.{model}Collection.paginate({ take, skip });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async findByPk(id: number) {
|
|
18
|
+
return this.{model}Collection.findOne((item) => item.id === id);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async create(createBody: Partial<{Model}>) {
|
|
22
|
+
return this.{model}Collection.add(createBody);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async update(id: number, updateBody: Partial<{Model}>) {
|
|
26
|
+
this.{model}Collection.update((item) => item.id === id, updateBody);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async delete(id: number) {
|
|
31
|
+
this.{model}Collection.delete((item) => item.id === id);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
File without changes
|
package/stubs/model.stub
DELETED
|
File without changes
|