@avleon/cli 0.0.45 → 0.0.46

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@avleon/cli",
3
- "version": "0.0.45",
3
+ "version": "0.0.46",
4
4
  "description": "CLI for scaffolding and running Avleon applications",
5
5
  "author": "Tareq Hossain",
6
6
  "license": "ISC",
@@ -11,6 +11,7 @@
11
11
  },
12
12
  "files": [
13
13
  "dist",
14
+ "stubs",
14
15
  "README.md"
15
16
  ],
16
17
  "scripts": {
@@ -0,0 +1,11 @@
1
+ import { Builder, AppConfig } from '@avleon/core';
2
+ import { HomeController } from './controllers/home.controller';
3
+
4
+ const builder = Builder.createAppBuilder();
5
+
6
+ const app = builder.build();
7
+ app.useOpenApi((config:AppConfig)=> config.openApi);
8
+ app.useControllers([HomeController]);
9
+
10
+
11
+ app.run();
@@ -0,0 +1,17 @@
1
+ import { Builder, AppConfig } from '@avleon/core';
2
+ const builder = Builder.createAppBuilder();
3
+
4
+ builder.services.addOpenApi();
5
+ builder.services.addServices();
6
+ builder.services.addAuthentication();
7
+ builder.servicse.addControllers();
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;
File without changes
@@ -0,0 +1,7 @@
1
+ import { Get, HttpResponse } from '@avleon/core';
2
+ export class {{name}}{
3
+ constructor(
4
+ private readonly {}
5
+ ){}
6
+ }
7
+
@@ -0,0 +1,11 @@
1
+ @Config
2
+ export class OpenApiConfig {
3
+ config() {
4
+ return {
5
+ title: 'My API',
6
+ version: '1.0.0',
7
+ description: 'API documentation',
8
+ path: '/api-docs',
9
+ };
10
+ }
11
+ }
@@ -0,0 +1,12 @@
1
+ import { ApiController, Get, HttpResponse } from '@avleon/core';
2
+
3
+
4
+ @ApiController('/{controller}s')
5
+ export class {Controller}Controller{
6
+
7
+ @Get()
8
+ index(){
9
+ return "{controller} ok";
10
+ }
11
+
12
+ }
@@ -0,0 +1,52 @@
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
+ constructor(
8
+ private readonly {model}Service: {Model}Service
9
+ ){}
10
+
11
+ @Get()
12
+ async index(@Query() query?:any){
13
+ if(query && query.page){
14
+ const result = await this.{model}Service.paginate(query.page);
15
+ return result;
16
+ }
17
+ const result = await this.{model}Service.findAll();
18
+ return result;
19
+ }
20
+
21
+ @Get('/:id')
22
+ async findOne(@Param('id') id:number){
23
+ const is{Model} = await this.{model}Service.findByPk(id);
24
+ if(!is{Model}) throw HttpExceptions.notFound("{Model} not found.");
25
+ return is{Model};
26
+ }
27
+
28
+ @Post()
29
+ async create(@Body() body:any){
30
+ const isSave = await this.{model}Service.create(body);
31
+ return isSave;
32
+ }
33
+
34
+ @Post('/:id')
35
+ async update(@Param('id') id:number, updateBody:any){
36
+ const is{Model} = await this.{model}Service.findByPk(id);
37
+ if(!is{Model}) throw HttpExceptions.notFound("{Model} not found.");
38
+ const isUpdated = await this.{model}Service.update(id,updateBody);
39
+ if(!isUpdated) throw HttpExceptions.internalError("Can't update {Model}");
40
+ return "Updated Successfully";
41
+ }
42
+
43
+ @Delete('/:id')
44
+ async delete(@Param('id') id:number){
45
+ const is{Model} = await this.{model}Service.findByPk(id);
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
+ }
@@ -0,0 +1,34 @@
1
+ import { ApiController, Get, Post, Delete, Param, Query, Body, HttpExceptions } from '@avleon/core';
2
+
3
+ @ApiController('/{controller}s')
4
+ export class {Controller}Controller{
5
+
6
+
7
+
8
+ @Get()
9
+ async index(@Query() query?:any){
10
+ throw new Error("Method not implemented.");
11
+ }
12
+
13
+ @Get('/:id')
14
+ async findOne(@Param('id') id:number){
15
+ throw new Error("Method not implemented.");
16
+ }
17
+
18
+ @Post()
19
+ async create(@Body() body:any){
20
+ throw new Error("Method not implemented.");
21
+ }
22
+
23
+ @Post('/:id')
24
+ async update(@Param('id') id:number, updateBody:any){
25
+
26
+ throw new Error("Method not implemented.");
27
+ }
28
+
29
+ @Delete('/:id')
30
+ async delete(@Param('id') id:number){
31
+ throw new Error("Method not implemented.");
32
+ }
33
+
34
+ }
File without changes
@@ -0,0 +1,6 @@
1
+
2
+
3
+ export class {Model}{
4
+ id: number;
5
+ name: string;
6
+ }
@@ -0,0 +1,23 @@
1
+
2
+ import {Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn} from 'typeorm';
3
+
4
+ @Entity({name:"{Model}"})
5
+ export class {Model}{
6
+
7
+ @PrimaryGeneratedColumn()
8
+ id:number;
9
+
10
+
11
+ // your fields
12
+
13
+ // @Column()
14
+ // name:string
15
+
16
+
17
+ @CreateDateColumn()
18
+ createdAt: Date;
19
+
20
+
21
+ @UpdateDateColumn()
22
+ updatedAt: Date;
23
+ }
@@ -0,0 +1,10 @@
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();
@@ -0,0 +1,9 @@
1
+ import { AppService } from '@avleon/core';
2
+
3
+ @AppService
4
+ export class {Service} {
5
+
6
+ sayHello(){
7
+ return "Hello World!";
8
+ }
9
+ }
@@ -0,0 +1,73 @@
1
+ import { AppService, InjectRepository } from '@avleon/core';
2
+ import { Repository } from 'typeorm';
3
+ import { {Model} } from '../models/{model}.model';
4
+
5
+
6
+ @AppService
7
+ export class {Service}Service{
8
+
9
+ constructor(
10
+ @InjectRepository({Model})
11
+ private readonly {model}Repository:Repository<{Model}>
12
+ ){}
13
+
14
+ async findAll(options:any={}){
15
+ return this.{model}Repository.find(options);
16
+ }
17
+
18
+ async paginate(current:number = 1, options:any={}){
19
+ const take = 10;
20
+ const skip = current > 1 ? ( current -1 ) * 10 : 0;
21
+ const total = await this.{model}Repository.count(options);
22
+ const totalPage = Math.ceil(total / take);
23
+ const next = current < totalPage ? current + 1 : null;
24
+ const prev = current > 1 ? current - 1 : null;
25
+ const data = await this.{model}Repository.find({
26
+ ...options,
27
+ take,
28
+ skip
29
+ })
30
+
31
+ return {
32
+ total,
33
+ totalPage,
34
+ current,
35
+ next,
36
+ prev,
37
+ data
38
+ };
39
+ }
40
+
41
+ async findByPk(id:number){
42
+ return this.{model}Repository.findOne({id});
43
+ }
44
+
45
+ async findBy(options:any){
46
+ return this.{model}Repository.findBy(options);
47
+ }
48
+
49
+ async findOneBy(options:any){
50
+ return this.{model}Repository.findOneBy(options);
51
+ }
52
+
53
+
54
+ async findOne(id:number){
55
+ return this.{model}Repository.findOne({where:{id}}) ;
56
+ }
57
+
58
+ async create(createBody:any){
59
+ const newItem = this.{model}Repository.create();
60
+ return await this.{model}Repository.save();
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
+ }
@@ -0,0 +1,71 @@
1
+ import { AppService, Collection } from '@avleon/core';
2
+ import { {Model} } from '../models/{model}.model';
3
+
4
+
5
+ @AppService
6
+ export class {Service}Service{
7
+
8
+ constructor(
9
+ private readonly {model}Collection:Collection.from<{Model}>([])
10
+ ){}
11
+
12
+ async findAll(options:any={}){
13
+ return this.{model}Collection.find(options);
14
+ }
15
+
16
+ async paginate(current:number = 1, options:any={}){
17
+ const take = 10;
18
+ const skip = current > 1 ? ( current -1 ) * 10 : 0;
19
+ const total = await this.{model}Collection.count(options);
20
+ const totalPage = Math.ceil(total / take);
21
+ const next = current < totalPage ? current + 1 : null;
22
+ const prev = current > 1 ? current - 1 : null;
23
+ const data = await this.{model}Collection.find({
24
+ ...options,
25
+ take,
26
+ skip
27
+ })
28
+
29
+ return {
30
+ total,
31
+ totalPage,
32
+ current,
33
+ next,
34
+ prev,
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
+ }