tspace-spear 1.2.7 → 1.2.8
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 +46 -75
- package/dist/cli/app.d.ts +1 -1
- package/dist/cli/app.js +7 -3
- package/dist/cli/app.js.map +1 -1
- package/dist/cli/client.d.ts +1 -0
- package/dist/cli/client.js +30 -0
- package/dist/cli/client.js.map +1 -0
- package/dist/cli/controller.d.ts +1 -1
- package/dist/cli/controller.js +12 -1
- package/dist/cli/controller.js.map +1 -1
- package/dist/cli/generators/app/index.d.ts +1 -0
- package/dist/cli/generators/app/index.js +124 -0
- package/dist/cli/generators/app/index.js.map +1 -0
- package/dist/cli/generators/app/template.d.ts +1 -0
- package/dist/cli/generators/app/template.js +42 -0
- package/dist/cli/generators/app/template.js.map +1 -0
- package/dist/cli/generators/client/template.d.ts +1 -0
- package/dist/cli/generators/client/template.js +30 -0
- package/dist/cli/generators/client/template.js.map +1 -0
- package/dist/cli/generators/controller/index.d.ts +1 -0
- package/dist/cli/generators/controller/index.js +78 -0
- package/dist/cli/generators/controller/index.js.map +1 -0
- package/dist/cli/generators/controller/template.d.ts +1 -0
- package/dist/cli/generators/controller/template.js +99 -0
- package/dist/cli/generators/controller/template.js.map +1 -0
- package/dist/cli/generators/dto/index.d.ts +1 -0
- package/dist/cli/generators/dto/index.js +55 -0
- package/dist/cli/generators/dto/index.js.map +1 -0
- package/dist/cli/generators/dto/template.d.ts +1 -0
- package/dist/cli/generators/dto/template.js +32 -0
- package/dist/cli/generators/dto/template.js.map +1 -0
- package/dist/cli/generators/middleware/index.d.ts +1 -0
- package/dist/cli/generators/middleware/index.js +38 -0
- package/dist/cli/generators/middleware/index.js.map +1 -0
- package/dist/cli/generators/middleware/template.d.ts +1 -0
- package/dist/cli/generators/middleware/template.js +16 -0
- package/dist/cli/generators/middleware/template.js.map +1 -0
- package/dist/cli/generators/module/index.d.ts +1 -0
- package/dist/cli/generators/module/index.js +173 -0
- package/dist/cli/generators/module/index.js.map +1 -0
- package/dist/cli/generators/service/index.d.ts +1 -0
- package/dist/cli/generators/service/index.js +53 -0
- package/dist/cli/generators/service/index.js.map +1 -0
- package/dist/cli/generators/service/template.d.ts +1 -0
- package/dist/cli/generators/service/template.js +74 -0
- package/dist/cli/generators/service/template.js.map +1 -0
- package/dist/cli/generators/shared/index.d.ts +3 -0
- package/dist/cli/generators/shared/index.js +22 -0
- package/dist/cli/generators/shared/index.js.map +1 -0
- package/dist/cli/index.js +52 -96
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/middleware.d.ts +1 -0
- package/dist/cli/middleware.js +16 -0
- package/dist/cli/middleware.js.map +1 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +17 -0
- package/dist/client.js.map +1 -0
- package/dist/common/middlewares/log.middleware.d.ts +2 -0
- package/dist/common/middlewares/log.middleware.js +12 -0
- package/dist/common/middlewares/log.middleware.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/core/compiler/generator.js +20 -2
- package/dist/lib/core/compiler/generator.js.map +1 -1
- package/dist/lib/core/decorators/context.d.ts +78 -8
- package/dist/lib/core/decorators/context.js +74 -7
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/package/index.d.ts +11 -0
- package/dist/lib/core/package/index.js +42 -0
- package/dist/lib/core/package/index.js.map +1 -0
- package/dist/modules/cats/cat.controller.d.ts +58 -0
- package/dist/modules/cats/cat.controller.js +90 -0
- package/dist/modules/cats/cat.controller.js.map +1 -0
- package/dist/modules/cats/cat.dto.d.ts +8 -0
- package/dist/modules/cats/cat.dto.js +44 -0
- package/dist/modules/cats/cat.dto.js.map +1 -0
- package/dist/modules/cats/cat.service.d.ts +23 -0
- package/dist/modules/cats/cat.service.js +56 -0
- package/dist/modules/cats/cat.service.js.map +1 -0
- package/dist/tests/e2e..test.d.ts +1 -0
- package/dist/tests/e2e..test.js +16 -0
- package/dist/tests/e2e..test.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -73,28 +73,48 @@ new Spear()
|
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
## Cli
|
|
76
|
+
Generate applications, modules, controllers, services, and middleware with the Spear CLI.
|
|
76
77
|
```sh
|
|
77
78
|
# Install CLI globally
|
|
78
79
|
npm install -g tspace-spear
|
|
79
80
|
|
|
80
81
|
# Create a new application structure
|
|
81
|
-
|
|
82
|
+
spear create new my-app
|
|
82
83
|
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
✔ Successfully created project "my-app"
|
|
85
|
+
|
|
86
|
+
📦 Project Structure
|
|
85
87
|
|
|
86
|
-
# Generated structure
|
|
87
88
|
src/
|
|
88
|
-
├──
|
|
89
|
-
│ └──
|
|
90
|
-
│
|
|
89
|
+
├── common/
|
|
90
|
+
│ └── middlewares/
|
|
91
|
+
│ └── log.middleware.ts
|
|
92
|
+
│
|
|
93
|
+
├── modules/
|
|
94
|
+
│ └── cats/
|
|
95
|
+
│ ├── cat.controller.ts
|
|
96
|
+
│ ├── cat.service.ts
|
|
97
|
+
│ └── cat.dto.ts
|
|
98
|
+
│
|
|
99
|
+
├── client.ts
|
|
91
100
|
└── index.ts
|
|
92
101
|
|
|
93
|
-
|
|
102
|
+
🚀 Next Steps
|
|
103
|
+
|
|
104
|
+
cd my-app
|
|
105
|
+
|
|
106
|
+
npm run dev
|
|
107
|
+
|
|
108
|
+
✔ Server is running at:
|
|
109
|
+
http://localhost:8000
|
|
110
|
+
|
|
111
|
+
✔ Swagger Docs:
|
|
112
|
+
http://localhost:8000/api/docs
|
|
113
|
+
|
|
114
|
+
✔ Run E2E client:
|
|
115
|
+
ts-node src/client.ts
|
|
94
116
|
|
|
95
|
-
ts-node src/
|
|
96
|
-
## Server is now listening http://localhost:8000
|
|
97
|
-
## Docs is now listening http://localhost:8000/api/docs
|
|
117
|
+
ts-node src/client.ts // for E2E
|
|
98
118
|
```
|
|
99
119
|
|
|
100
120
|
## Adapter
|
|
@@ -580,8 +600,9 @@ DTO (Data Transfer Object) is used to validate and transform incoming request da
|
|
|
580
600
|
import {
|
|
581
601
|
Controller ,
|
|
582
602
|
Post,
|
|
583
|
-
createDtoDecorator,
|
|
584
603
|
Validate,
|
|
604
|
+
ValidateDto,
|
|
605
|
+
createDtoDecorator,
|
|
585
606
|
type T
|
|
586
607
|
} from 'tspace-spear';
|
|
587
608
|
|
|
@@ -593,8 +614,6 @@ import {
|
|
|
593
614
|
validate
|
|
594
615
|
} from "class-validator";
|
|
595
616
|
|
|
596
|
-
import { ClassConstructor, plainToInstance } from 'class-transformer';
|
|
597
|
-
|
|
598
617
|
const ValidateDtoCustomBody = (keys: string[]) => {
|
|
599
618
|
return createDtoDecorator((ctx) => {
|
|
600
619
|
const body = ctx.body ?? {};
|
|
@@ -620,13 +639,6 @@ const ValidateDtoCustomBody = (keys: string[]) => {
|
|
|
620
639
|
});
|
|
621
640
|
}
|
|
622
641
|
|
|
623
|
-
const ValidateDtoZodBody = (schema: z.ZodTypeAny) => {
|
|
624
|
-
return createDtoDecorator((ctx) => {
|
|
625
|
-
const result = schema.parse(ctx.body);
|
|
626
|
-
ctx.body = result as T.Body;
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
|
|
630
642
|
const ValidateDtoPromiseBody = (keys: string[]) => {
|
|
631
643
|
return createDtoDecorator(async (ctx) => {
|
|
632
644
|
await new Promise(resolve => setTimeout(resolve,500));
|
|
@@ -646,39 +658,6 @@ const ValidateDtoPromiseBody = (keys: string[]) => {
|
|
|
646
658
|
});
|
|
647
659
|
}
|
|
648
660
|
|
|
649
|
-
const ValidateDtoClsBody = <T extends object>(
|
|
650
|
-
cls: ClassConstructor<T>
|
|
651
|
-
) => {
|
|
652
|
-
return createDtoDecorator(async (ctx) => {
|
|
653
|
-
|
|
654
|
-
const dto = plainToInstance(
|
|
655
|
-
cls,
|
|
656
|
-
ctx.body
|
|
657
|
-
);
|
|
658
|
-
|
|
659
|
-
const errors = await validate(dto);
|
|
660
|
-
|
|
661
|
-
if (errors.length > 0) {
|
|
662
|
-
throw {
|
|
663
|
-
message: "Validation failed",
|
|
664
|
-
issues: errors.flatMap((error) => {
|
|
665
|
-
const constraints = error.constraints ?? {};
|
|
666
|
-
|
|
667
|
-
const firstError = Object.values(constraints)[0] ?? "Validation error";
|
|
668
|
-
|
|
669
|
-
return {
|
|
670
|
-
path: error.property,
|
|
671
|
-
message: firstError,
|
|
672
|
-
};
|
|
673
|
-
})
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
ctx.body = dto;
|
|
678
|
-
}
|
|
679
|
-
);
|
|
680
|
-
};
|
|
681
|
-
|
|
682
661
|
const catSchema = z.object({
|
|
683
662
|
name: z.string(),
|
|
684
663
|
age: z.number(),
|
|
@@ -692,7 +671,6 @@ class CreateCatDto {
|
|
|
692
671
|
age!: number;
|
|
693
672
|
}
|
|
694
673
|
|
|
695
|
-
|
|
696
674
|
// file cat-controller.ts
|
|
697
675
|
@Controller('/cats')
|
|
698
676
|
export class CatController {
|
|
@@ -701,47 +679,40 @@ export class CatController {
|
|
|
701
679
|
// only required validation without type checking
|
|
702
680
|
@Validate(["name", "age"], { required: { allowEmptyString: false, allowNull: false } })
|
|
703
681
|
public async basic(ctx : T.Context<{ body : { name : any , age : any }}>) {
|
|
704
|
-
const body = ctx.body;
|
|
705
682
|
return {
|
|
706
|
-
body
|
|
683
|
+
body : ctx.body
|
|
707
684
|
}
|
|
708
685
|
}
|
|
709
686
|
|
|
710
|
-
@Post('/')
|
|
687
|
+
@Post('/custom')
|
|
711
688
|
@ValidateDtoCustomBody(["name", "age"])
|
|
712
689
|
public async custom(ctx : T.Context<{ body : { name : string , age : number }}>) {
|
|
713
|
-
const body = ctx.body;
|
|
714
690
|
return {
|
|
715
|
-
body
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
@Post('/zod')
|
|
720
|
-
@ValidateDtoZodBody(catSchema)
|
|
721
|
-
public async zod(ctx : T.Context<z.infer<typeof catSchema>>) {
|
|
722
|
-
const body = ctx.body;
|
|
723
|
-
return {
|
|
724
|
-
body
|
|
691
|
+
body : ctx.body
|
|
725
692
|
}
|
|
726
693
|
}
|
|
727
694
|
|
|
728
695
|
@Post('/promise')
|
|
729
696
|
@ValidateDtoPromiseBody(['name'])
|
|
730
697
|
public async promise(ctx : T.Context<{ body : { name : string }}>) {
|
|
731
|
-
|
|
698
|
+
return {
|
|
699
|
+
body : ctx.body
|
|
700
|
+
}
|
|
701
|
+
}
|
|
732
702
|
|
|
703
|
+
@Post('/zod')
|
|
704
|
+
@ValidateDto(catSchema, { adaptor : "zod" })
|
|
705
|
+
public async zod(ctx : T.Context<{ body : z.infer<typeof catSchema>}>) {
|
|
733
706
|
return {
|
|
734
|
-
body
|
|
707
|
+
body : ctx.body
|
|
735
708
|
}
|
|
736
709
|
}
|
|
737
710
|
|
|
738
711
|
@Post('/cls')
|
|
739
|
-
@
|
|
712
|
+
@ValidateDto(CreateCatDto)
|
|
740
713
|
public async cls(ctx : T.Context<{ body : CreateCatDto }>) {
|
|
741
|
-
const body = ctx.body;
|
|
742
|
-
|
|
743
714
|
return {
|
|
744
|
-
body
|
|
715
|
+
body : ctx.body
|
|
745
716
|
}
|
|
746
717
|
}
|
|
747
718
|
}
|
package/dist/cli/app.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const app = "\nimport Spear from \"tspace-spear\";\n\
|
|
1
|
+
export declare const app = "\nimport Spear from \"tspace-spear\";\n\nconst app = new Spear({\n logger: true,\n controllers: {\n folder: `${__dirname}/controllers`,\n name: /controller\\.(ts|js)$/i,\n\n // don't forget to set this option for auto-generate route metadata for type-safe E2E usage, \n // and swagger documentation. By default if use .useSwagger() in app no need to set any description\n preRouteTypes: true\n }\n})\n\napp.useGlobalPrefix(\"api\");\napp.useSwagger();\napp.useBodyParser();\n\napp.listen(8000 , ({ port , server }) => {\n console.log(`Server listening on : http://localhost:${port}`)\n console.log(`Docs listening on : http://localhost:${port}/api/docs`)\n})\n\ntype AppRouter = typeof app.contract;\nexport { AppRouter };\nexport { app };\n";
|
package/dist/cli/app.js
CHANGED
|
@@ -4,11 +4,11 @@ exports.app = void 0;
|
|
|
4
4
|
exports.app = `
|
|
5
5
|
import Spear from "tspace-spear";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const app = new Spear({
|
|
8
8
|
logger: true,
|
|
9
9
|
controllers: {
|
|
10
10
|
folder: \`\${__dirname}/controllers\`,
|
|
11
|
-
name: /controller
|
|
11
|
+
name: /controller\\\.(ts|js)$/i,
|
|
12
12
|
|
|
13
13
|
// don't forget to set this option for auto-generate route metadata for type-safe E2E usage,
|
|
14
14
|
// and swagger documentation. By default if use .useSwagger() in app no need to set any description
|
|
@@ -22,7 +22,11 @@ app.useBodyParser();
|
|
|
22
22
|
|
|
23
23
|
app.listen(8000 , ({ port , server }) => {
|
|
24
24
|
console.log(\`Server listening on : http://localhost:\${port}\`)
|
|
25
|
-
console.log(
|
|
25
|
+
console.log(\`Docs listening on : http://localhost:\${port}/api/docs\`)
|
|
26
26
|
})
|
|
27
|
+
|
|
28
|
+
type AppRouter = typeof app.contract;
|
|
29
|
+
export { AppRouter };
|
|
30
|
+
export { app };
|
|
27
31
|
`;
|
|
28
32
|
//# sourceMappingURL=app.js.map
|
package/dist/cli/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/cli/app.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/cli/app.ts"],"names":[],"mappings":";;;AAAa,QAAA,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BlB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const client = "\n// for example E2E\nimport { AppRouter } from \".\";\nimport { ApiClient } from \"tspace-spear/client\";\n\nconst client: ApiClient<AppRouter> = new ApiClient(\n \"http://localhost:8000/api\"\n);\n\nasync function main() { \n \n const res = await client.get(\"/cats\");\n res.data.cats = 1 // Type error: Type 'number' is not assignable to type '{ id: number; name: string; age: number; }[]'\n res.data.cats[0].name = 1 // Type error: Type 'number' is not assignable to type 'string'\n res.data.cats[0].age = \"1.6\" // Type error: Type 'string' is not assignable to type 'number'\n\n console.log(res) \n // res.ok -> boolean\n // res.status -> number\n // res.data -> { cats: [{ id: 1, name: 'cat1', age: 1.6 },{ id: 2, name: 'cat2', age: 1.8 }] }\n\n await client.get(\"/catsq\"); // Type error: Argument of type '\"/catsq\"' is not assignable to parameter of type '\"/cats\" | \"/cats/:id\" | ... 3 more\n \n}\nmain()\n";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.client = void 0;
|
|
4
|
+
exports.client = `
|
|
5
|
+
// for example E2E
|
|
6
|
+
import { AppRouter } from ".";
|
|
7
|
+
import { ApiClient } from "tspace-spear/client";
|
|
8
|
+
|
|
9
|
+
const client: ApiClient<AppRouter> = new ApiClient(
|
|
10
|
+
"http://localhost:8000/api"
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
|
|
15
|
+
const res = await client.get("/cats");
|
|
16
|
+
res.data.cats = 1 // Type error: Type 'number' is not assignable to type '{ id: number; name: string; age: number; }[]'
|
|
17
|
+
res.data.cats[0].name = 1 // Type error: Type 'number' is not assignable to type 'string'
|
|
18
|
+
res.data.cats[0].age = "1.6" // Type error: Type 'string' is not assignable to type 'number'
|
|
19
|
+
|
|
20
|
+
console.log(res)
|
|
21
|
+
// res.ok -> boolean
|
|
22
|
+
// res.status -> number
|
|
23
|
+
// res.data -> { cats: [{ id: 1, name: 'cat1', age: 1.6 },{ id: 2, name: 'cat2', age: 1.8 }] }
|
|
24
|
+
|
|
25
|
+
await client.get("/catsq"); // Type error: Argument of type '"/catsq"' is not assignable to parameter of type '"/cats" | "/cats/:id" | ... 3 more
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
main()
|
|
29
|
+
`;
|
|
30
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/cli/client.ts"],"names":[],"mappings":";;;AACa,QAAA,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyBrB,CAAA"}
|
package/dist/cli/controller.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CatController = "\nimport {\n type T,\n Controller,\n Get,\n Post,\n Put,\n Delete\n} from \"tspace-spear\";\n\ntype Cat = {\n id: number;\n name: string;\n age: number;\n};\n\nlet cats: Cat[] = [\n {\n id: 1,\n name: \"cat 1\",\n age: 2\n },\n {\n id: 2,\n name: \"cat 2\",\n age: 4\n }\n];\n\n@Controller(\"/cats\")\
|
|
1
|
+
export declare const CatController = "\nimport {\n type T,\n Controller,\n Middleware,\n Get,\n Post,\n Put,\n Delete\n} from \"tspace-spear\";\n\nimport { CatMiddleware } from \"../middlewares/cat.middleware\";\n\ntype Cat = {\n id: number;\n name: string;\n age: number;\n};\n\nlet cats: Cat[] = [\n {\n id: 1,\n name: \"cat 1\",\n age: 2\n },\n {\n id: 2,\n name: \"cat 2\",\n age: 4\n }\n];\n\n@Controller(\"/cats\")\nclass CatController {\n\n @Get(\"/\")\n @Middleware(CatMiddleware)\n async index() {\n return {\n cats\n };\n }\n\n @Get(\"/:id\")\n @Middleware(CatMiddleware)\n async show({\n res,\n params\n }: T.Context<{\n params: {\n id: number;\n };\n }>) {\n\n const cat = cats.find(\n d => d.id === Number(params.id)\n );\n\n if (!cat) {\n throw res.notFound(\n \"Cat not found\"\n );\n }\n\n return {\n cat\n };\n }\n\n @Post(\"/\")\n @Middleware(CatMiddleware)\n async create({\n body\n }: T.Context<{\n body: {\n name: string;\n age: number;\n };\n }>) {\n\n const cat: Cat = {\n id: cats.length + 1,\n name: body.name,\n age: body.age\n };\n\n cats.push(cat);\n\n return {\n message: \"Created\",\n cat\n };\n }\n\n @Put(\"/:id\")\n @Middleware(CatMiddleware)\n async update({\n res,\n params,\n body\n }: T.Context<{\n params: {\n id: number;\n };\n body: Partial<{\n name: string;\n age: number;\n }>;\n }>) {\n\n const index = cats.findIndex(\n d => d.id === Number(params.id)\n );\n\n if (index === -1) {\n throw res.notFound(\n \"Cat not found\"\n );\n }\n\n cats[index] = {\n ...cats[index],\n ...body\n };\n\n return {\n message: \"Updated\",\n cat: cats[index]\n };\n }\n\n @Delete(\"/:id\")\n @Middleware(CatMiddleware)\n async remove({\n res,\n params\n }: T.Context<{\n params: {\n id: number;\n };\n }>) {\n\n const index = cats.findIndex(\n d => d.id === Number(params.id)\n );\n\n if (index === -1) {\n throw res.notFound(\n \"Cat not found\"\n );\n }\n\n cats = cats.filter(\n d => d.id !== Number(params.id)\n );\n\n return {\n message: \"Deleted\"\n };\n }\n}\n\nexport { CatController };\nexport default CatController;\n";
|
package/dist/cli/controller.js
CHANGED
|
@@ -5,12 +5,15 @@ exports.CatController = `
|
|
|
5
5
|
import {
|
|
6
6
|
type T,
|
|
7
7
|
Controller,
|
|
8
|
+
Middleware,
|
|
8
9
|
Get,
|
|
9
10
|
Post,
|
|
10
11
|
Put,
|
|
11
12
|
Delete
|
|
12
13
|
} from "tspace-spear";
|
|
13
14
|
|
|
15
|
+
import { CatMiddleware } from "../middlewares/cat.middleware";
|
|
16
|
+
|
|
14
17
|
type Cat = {
|
|
15
18
|
id: number;
|
|
16
19
|
name: string;
|
|
@@ -31,9 +34,10 @@ let cats: Cat[] = [
|
|
|
31
34
|
];
|
|
32
35
|
|
|
33
36
|
@Controller("/cats")
|
|
34
|
-
|
|
37
|
+
class CatController {
|
|
35
38
|
|
|
36
39
|
@Get("/")
|
|
40
|
+
@Middleware(CatMiddleware)
|
|
37
41
|
async index() {
|
|
38
42
|
return {
|
|
39
43
|
cats
|
|
@@ -41,6 +45,7 @@ export default class CatController {
|
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
@Get("/:id")
|
|
48
|
+
@Middleware(CatMiddleware)
|
|
44
49
|
async show({
|
|
45
50
|
res,
|
|
46
51
|
params
|
|
@@ -66,6 +71,7 @@ export default class CatController {
|
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
@Post("/")
|
|
74
|
+
@Middleware(CatMiddleware)
|
|
69
75
|
async create({
|
|
70
76
|
body
|
|
71
77
|
}: T.Context<{
|
|
@@ -90,6 +96,7 @@ export default class CatController {
|
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
@Put("/:id")
|
|
99
|
+
@Middleware(CatMiddleware)
|
|
93
100
|
async update({
|
|
94
101
|
res,
|
|
95
102
|
params,
|
|
@@ -126,6 +133,7 @@ export default class CatController {
|
|
|
126
133
|
}
|
|
127
134
|
|
|
128
135
|
@Delete("/:id")
|
|
136
|
+
@Middleware(CatMiddleware)
|
|
129
137
|
async remove({
|
|
130
138
|
res,
|
|
131
139
|
params
|
|
@@ -154,5 +162,8 @@ export default class CatController {
|
|
|
154
162
|
};
|
|
155
163
|
}
|
|
156
164
|
}
|
|
165
|
+
|
|
166
|
+
export { CatController };
|
|
167
|
+
export default CatController;
|
|
157
168
|
`;
|
|
158
169
|
//# sourceMappingURL=controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/cli/controller.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/cli/controller.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoK5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createApp(inputPath?: string): Promise<void>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createApp = createApp;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
10
|
+
const template_1 = require("./template");
|
|
11
|
+
const template_2 = require("../client/template");
|
|
12
|
+
const template_3 = require("../middleware/template");
|
|
13
|
+
const template_4 = require("../controller/template");
|
|
14
|
+
const template_5 = require("../service/template");
|
|
15
|
+
const template_6 = require("../dto/template");
|
|
16
|
+
const c = {
|
|
17
|
+
bold: (text) => `\x1b[1m${text}\x1b[0m`,
|
|
18
|
+
dim: (text) => `\x1b[2m${text}\x1b[0m`,
|
|
19
|
+
green: (text) => `\x1b[32m${text}\x1b[0m`,
|
|
20
|
+
cyan: (text) => `\x1b[36m${text}\x1b[0m`,
|
|
21
|
+
underline: (text) => `\x1b[4m${text}\x1b[0m`,
|
|
22
|
+
gray: (text) => `\x1b[90m${text}\x1b[0m`,
|
|
23
|
+
reset: "\x1b[0m"
|
|
24
|
+
};
|
|
25
|
+
async function createApp(inputPath) {
|
|
26
|
+
if (!inputPath) {
|
|
27
|
+
console.log("Missing target path, try: spear g app src");
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
const root = path_1.default.resolve(process.cwd(), inputPath);
|
|
31
|
+
fs_1.default.mkdirSync(root, { recursive: true });
|
|
32
|
+
await fs_1.default.promises.writeFile(path_1.default.join(root, "package.json"), JSON.stringify({
|
|
33
|
+
name: path_1.default.basename(root),
|
|
34
|
+
version: "1.0.0",
|
|
35
|
+
main: "dist/index.js",
|
|
36
|
+
scripts: {
|
|
37
|
+
build: "tsc",
|
|
38
|
+
start: "node dist/index.js",
|
|
39
|
+
dev: "ts-node src/index.ts",
|
|
40
|
+
},
|
|
41
|
+
dependencies: {
|
|
42
|
+
"tspace-spear": "latest",
|
|
43
|
+
"class-transformer": "0.5.1",
|
|
44
|
+
"class-validator": "0.15.1"
|
|
45
|
+
},
|
|
46
|
+
devDependencies: {
|
|
47
|
+
"typescript": "5.6.2",
|
|
48
|
+
"ts-node": "10.9.2",
|
|
49
|
+
"@types/node": "16.18.126"
|
|
50
|
+
},
|
|
51
|
+
}, null, 2));
|
|
52
|
+
await fs_1.default.promises.writeFile(path_1.default.join(root, "tsconfig.json"), JSON.stringify({
|
|
53
|
+
compilerOptions: {
|
|
54
|
+
"target": "esnext",
|
|
55
|
+
"module": "commonjs",
|
|
56
|
+
"lib": ["esnext", "DOM"],
|
|
57
|
+
"types": ["node"],
|
|
58
|
+
"allowJs": true,
|
|
59
|
+
"checkJs": false,
|
|
60
|
+
"outDir": "dist",
|
|
61
|
+
"rootDir": "src",
|
|
62
|
+
"strict": true,
|
|
63
|
+
"esModuleInterop": true,
|
|
64
|
+
"skipLibCheck": true,
|
|
65
|
+
"forceConsistentCasingInFileNames": true,
|
|
66
|
+
"emitDecoratorMetadata": true,
|
|
67
|
+
"experimentalDecorators": true,
|
|
68
|
+
},
|
|
69
|
+
}, null, 2));
|
|
70
|
+
const src = path_1.default.join(root, "src");
|
|
71
|
+
await fs_1.default.promises.mkdir(src, { recursive: true });
|
|
72
|
+
await fs_1.default.promises.mkdir(path_1.default.join(src, "common", "middlewares"), { recursive: true });
|
|
73
|
+
await fs_1.default.promises.mkdir(path_1.default.join(src, "modules", "cats"), { recursive: true });
|
|
74
|
+
await fs_1.default.promises.writeFile(path_1.default.join(src, "index.ts"), template_1.AppTemplate);
|
|
75
|
+
await fs_1.default.promises.writeFile(path_1.default.join(src, "client.ts"), template_2.ClientTemplate);
|
|
76
|
+
await fs_1.default.promises.writeFile(path_1.default.join(src, "common", "middlewares", "log.middleware.ts"), template_3.MiddlewareTemplate);
|
|
77
|
+
await fs_1.default.promises.writeFile(path_1.default.join(src, "modules", "cats", "cat.controller.ts"), template_4.ControllerTemplate);
|
|
78
|
+
await fs_1.default.promises.writeFile(path_1.default.join(src, "modules", "cats", "cat.service.ts"), template_5.ServiceTemplate);
|
|
79
|
+
await fs_1.default.promises.writeFile(path_1.default.join(src, "modules", "cats", "cat.dto.ts"), template_6.DtoTemplate);
|
|
80
|
+
console.log(`\n${c.bold("$ npm install")}\n`);
|
|
81
|
+
const startTime = Date.now();
|
|
82
|
+
const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
83
|
+
let i = 0;
|
|
84
|
+
const spinner = setInterval(() => {
|
|
85
|
+
process.stdout.write(`\r ${c.cyan(frames[i])} Installing dependencies...`);
|
|
86
|
+
i = (i + 1) % frames.length;
|
|
87
|
+
}, 50);
|
|
88
|
+
await new Promise((resolve, reject) => {
|
|
89
|
+
(0, child_process_1.exec)("npm install", { cwd: root }, (error) => {
|
|
90
|
+
if (error)
|
|
91
|
+
return reject(error);
|
|
92
|
+
return resolve();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
96
|
+
const nodeModulesPath = path_1.default.join(root, "node_modules");
|
|
97
|
+
let totalPhysicalPackages = 0;
|
|
98
|
+
if (fs_1.default.existsSync(nodeModulesPath)) {
|
|
99
|
+
const files = await fs_1.default.promises.readdir(nodeModulesPath);
|
|
100
|
+
const packages = files.filter(file => !file.startsWith(".") && !file.startsWith("@"));
|
|
101
|
+
totalPhysicalPackages = packages.length;
|
|
102
|
+
}
|
|
103
|
+
clearInterval(spinner);
|
|
104
|
+
process.stdout.write("\r\x1b[K");
|
|
105
|
+
const endTime = Date.now();
|
|
106
|
+
const elapsedSeconds = ((endTime - startTime) / 1000).toFixed(2);
|
|
107
|
+
console.log(`${c.bold(c.cyan("dependencies"))}`);
|
|
108
|
+
console.log(`${c.gray("├──")} ${c.green("+")} tspace-spear${c.dim("@latest")}`);
|
|
109
|
+
console.log(`${c.gray("├──")} ${c.green("+")} class-transformer${c.dim("@0.5.1")}`);
|
|
110
|
+
console.log(`${c.gray("└──")} ${c.green("+")} class-validator${c.dim("@0.15.1")}`);
|
|
111
|
+
console.log(`${c.gray("│")}`);
|
|
112
|
+
console.log(`${c.bold(c.gray("devDependencies"))}`);
|
|
113
|
+
console.log(`${c.gray("├──")} ${c.green("+")} typescript${c.dim("@5.6.2")}`);
|
|
114
|
+
console.log(`${c.gray("├──")} ${c.green("+")} ts-node${c.dim("@10.9.2")}`);
|
|
115
|
+
console.log(`${c.gray("└──")} ${c.green("+")} @types/node${c.dim("@16.18.126")}\n`);
|
|
116
|
+
console.log(`\n${c.green(`${totalPhysicalPackages} packages installed`)} ${c.dim(`[${elapsedSeconds}s]`)}`);
|
|
117
|
+
console.log(`${c.dim(`[${elapsedSeconds}s] npm install`)}`);
|
|
118
|
+
console.log(`\n--------`);
|
|
119
|
+
console.log("A local project was created for you and dependencies were installed automatically.\n");
|
|
120
|
+
console.log(`${c.green("Created spear project successfully")}\n`);
|
|
121
|
+
console.log(c.bold(c.gray("# To get started, run:")));
|
|
122
|
+
console.log(`\n cd ${inputPath}\n ${c.cyan("npm run dev")}\n`);
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/generators/app/index.ts"],"names":[],"mappings":";;;;;AAsBA,8BAsJC;AA5KD,4CAAoB;AACpB,gDAAwB;AACxB,iDAAsD;AACtD,yCAAyC;AACzC,iDAAoD;AACpD,qDAA4D;AAC5D,qDAA4D;AAC5D,kDAAsD;AACtD,8CAA8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AC,EAAE,CAAC,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IAC3E,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEpF,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,qBAAqB,qBAAqB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,cAAc,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5G,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,cAAc,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAE5D,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;IACzB,OAAO,CAAC,GAAG,CAAC,sFAAsF,CAAC,CAAC;IACpG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,oCAAoC,CAAC,IAAI,CAAC,CAAC;IAElE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,UAAU,SAAS,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AppTemplate = "\nimport Spear from \"tspace-spear\";\n\nconst app = new Spear({\n logger: true,\n controllers: {\n folder: `${__dirname}/modules/*`,\n name: /controller\\.(ts|js)$/i,\n\n // don't forget to set this option for auto-generate route metadata for type-safe E2E usage, \n // and swagger documentation. By default if use .useSwagger() in app no need to set any description\n preRouteTypes: true\n }\n})\n\napp.cors({\n origins: [ \n /^http:\\/\\/localhost:\\d+$/ \n ],\n credentials: true\n});\n\napp.useGlobalPrefix(\"api\");\napp.useSwagger();\napp.useBodyParser();\n\napp.listen(8000 , ({ port , server }) => {\n console.log(`Server listening on : http://localhost:${port}`)\n console.log(`Docs listening on : http://localhost:${port}/api/docs`)\n});\n\ntype AppRouter = typeof app.contract;\n\nexport { AppRouter };\nexport { app };\nexport default app;\n";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AppTemplate = void 0;
|
|
4
|
+
exports.AppTemplate = `
|
|
5
|
+
import Spear from "tspace-spear";
|
|
6
|
+
|
|
7
|
+
const app = new Spear({
|
|
8
|
+
logger: true,
|
|
9
|
+
controllers: {
|
|
10
|
+
folder: \`\${__dirname}/modules/*\`,
|
|
11
|
+
name: /controller\\\.(ts|js)$/i,
|
|
12
|
+
|
|
13
|
+
// don't forget to set this option for auto-generate route metadata for type-safe E2E usage,
|
|
14
|
+
// and swagger documentation. By default if use .useSwagger() in app no need to set any description
|
|
15
|
+
preRouteTypes: true
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
app.cors({
|
|
20
|
+
origins: [
|
|
21
|
+
/^http:\\/\\/localhost:\\d+$/\
|
|
22
|
+
|
|
23
|
+
],
|
|
24
|
+
credentials: true
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.useGlobalPrefix("api");
|
|
28
|
+
app.useSwagger();
|
|
29
|
+
app.useBodyParser();
|
|
30
|
+
|
|
31
|
+
app.listen(8000 , ({ port , server }) => {
|
|
32
|
+
console.log(\`Server listening on : http://localhost:\${port}\`)
|
|
33
|
+
console.log(\`Docs listening on : http://localhost:\${port}/api/docs\`)
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
type AppRouter = typeof app.contract;
|
|
37
|
+
|
|
38
|
+
export { AppRouter };
|
|
39
|
+
export { app };
|
|
40
|
+
export default app;
|
|
41
|
+
`;
|
|
42
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../src/cli/generators/app/template.ts"],"names":[],"mappings":";;;AAAa,QAAA,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ClientTemplate = "\n// for example E2E\nimport { AppRouter } from \".\";\nimport { ApiClient } from \"tspace-spear/client\";\n\nconst client: ApiClient<AppRouter> = new ApiClient(\n \"http://localhost:8000/api\"\n);\n\nasync function main() { \n \n const res = await client.get(\"/cats\");\n res.data.cats = 1 // Type error: Type 'number' is not assignable to type '{ id: number; name: string; age: number; }[]'\n res.data.cats[0].name = 1 // Type error: Type 'number' is not assignable to type 'string'\n res.data.cats[0].age = \"1.6\" // Type error: Type 'string' is not assignable to type 'number'\n\n console.log(res) \n // res.ok -> boolean\n // res.status -> number\n // res.data -> { cats: [{ id: 1, name: 'cat1', age: 1.6 },{ id: 2, name: 'cat2', age: 1.8 }] }\n\n await client.get(\"/catsq\"); // Type error: Argument of type '\"/catsq\"' is not assignable to parameter of type '\"/cats\" | \"/cats/:id\" | ... 3 more\n \n}\nmain()\n";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientTemplate = void 0;
|
|
4
|
+
exports.ClientTemplate = `
|
|
5
|
+
// for example E2E
|
|
6
|
+
import { AppRouter } from ".";
|
|
7
|
+
import { ApiClient } from "tspace-spear/client";
|
|
8
|
+
|
|
9
|
+
const client: ApiClient<AppRouter> = new ApiClient(
|
|
10
|
+
"http://localhost:8000/api"
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
|
|
15
|
+
const res = await client.get("/cats");
|
|
16
|
+
res.data.cats = 1 // Type error: Type 'number' is not assignable to type '{ id: number; name: string; age: number; }[]'
|
|
17
|
+
res.data.cats[0].name = 1 // Type error: Type 'number' is not assignable to type 'string'
|
|
18
|
+
res.data.cats[0].age = "1.6" // Type error: Type 'string' is not assignable to type 'number'
|
|
19
|
+
|
|
20
|
+
console.log(res)
|
|
21
|
+
// res.ok -> boolean
|
|
22
|
+
// res.status -> number
|
|
23
|
+
// res.data -> { cats: [{ id: 1, name: 'cat1', age: 1.6 },{ id: 2, name: 'cat2', age: 1.8 }] }
|
|
24
|
+
|
|
25
|
+
await client.get("/catsq"); // Type error: Argument of type '"/catsq"' is not assignable to parameter of type '"/cats" | "/cats/:id" | ... 3 more
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
main()
|
|
29
|
+
`;
|
|
30
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../src/cli/generators/client/template.ts"],"names":[],"mappings":";;;AACa,QAAA,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyB7B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createController(root: string, name?: string): void;
|