tspace-spear 1.2.8 → 1.2.9-beta.1
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 +303 -82
- package/dist/cli/app.d.ts +1 -1
- package/dist/cli/app.js +3 -7
- package/dist/cli/app.js.map +1 -1
- package/dist/cli/controller.d.ts +1 -1
- package/dist/cli/controller.js +1 -12
- package/dist/cli/controller.js.map +1 -1
- package/dist/cli/generators/app/index.js +1 -1
- package/dist/cli/generators/app/index.js.map +1 -1
- package/dist/cli/generators/controller/template.d.ts +1 -1
- package/dist/cli/generators/controller/template.js +16 -7
- package/dist/cli/generators/controller/template.js.map +1 -1
- package/dist/cli/generators/dto/index.js +5 -3
- package/dist/cli/generators/dto/index.js.map +1 -1
- package/dist/cli/generators/module/index.js +3 -3
- package/dist/cli/generators/service/template.d.ts +1 -1
- package/dist/cli/generators/service/template.js +17 -17
- package/dist/cli/index.js +10 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/lib/core/client/index.d.ts +13 -43
- package/dist/lib/core/client/index.js +70 -33
- package/dist/lib/core/client/index.js.map +1 -1
- package/dist/lib/core/client/types.d.ts +43 -0
- package/dist/lib/core/client/types.js +3 -0
- package/dist/lib/core/client/types.js.map +1 -0
- package/dist/lib/core/compiler/generator.d.ts +4 -6
- package/dist/lib/core/compiler/generator.js +172 -39
- package/dist/lib/core/compiler/generator.js.map +1 -1
- package/dist/lib/core/compiler/index.d.ts +2 -2
- package/dist/lib/core/compiler/index.js +2 -2
- package/dist/lib/core/compiler/index.js.map +1 -1
- package/dist/lib/core/compiler/pre-routes.d.ts +12 -130
- package/dist/lib/core/compiler/pre-routes.js +13 -35
- package/dist/lib/core/compiler/pre-routes.js.map +1 -1
- package/dist/lib/core/compiler/types.d.ts +25 -0
- package/dist/lib/core/decorators/context.js +23 -15
- package/dist/lib/core/decorators/context.js.map +1 -1
- package/dist/lib/core/decorators/controller.js +2 -1
- package/dist/lib/core/decorators/controller.js.map +1 -1
- package/dist/lib/core/decorators/index.d.ts +1 -0
- package/dist/lib/core/decorators/index.js +1 -0
- package/dist/lib/core/decorators/index.js.map +1 -1
- package/dist/lib/core/decorators/methods.js +4 -3
- package/dist/lib/core/decorators/methods.js.map +1 -1
- package/dist/lib/core/decorators/middleware.d.ts +40 -2
- package/dist/lib/core/decorators/middleware.js +54 -9
- package/dist/lib/core/decorators/middleware.js.map +1 -1
- package/dist/lib/core/decorators/service.d.ts +28 -0
- package/dist/lib/core/decorators/service.js +36 -0
- package/dist/lib/core/decorators/service.js.map +1 -0
- package/dist/lib/core/decorators/statusCode.js +3 -1
- package/dist/lib/core/decorators/statusCode.js.map +1 -1
- package/dist/lib/core/decorators/swagger.js +4 -3
- package/dist/lib/core/decorators/swagger.js.map +1 -1
- package/dist/lib/core/exception/index.d.ts +68 -0
- package/dist/lib/core/exception/index.js +123 -0
- package/dist/lib/core/exception/index.js.map +1 -0
- package/dist/lib/core/metadata/index.d.ts +6 -0
- package/dist/lib/core/metadata/index.js +13 -0
- package/dist/lib/core/metadata/index.js.map +1 -0
- package/dist/lib/core/server/fast-router.d.ts +2 -2
- package/dist/lib/core/server/fast-router.js +17 -3
- package/dist/lib/core/server/fast-router.js.map +1 -1
- package/dist/lib/core/server/index.d.ts +32 -5
- package/dist/lib/core/server/index.js +188 -45
- package/dist/lib/core/server/index.js.map +1 -1
- package/dist/lib/core/server/parser-factory.js +59 -10
- package/dist/lib/core/server/parser-factory.js.map +1 -1
- package/dist/lib/core/server/response.js +21 -1
- package/dist/lib/core/server/response.js.map +1 -1
- package/dist/lib/core/types/index.d.ts +42 -29
- package/package.json +14 -5
- package/dist/cli/client.d.ts +0 -1
- package/dist/cli/client.js +0 -30
- package/dist/cli/client.js.map +0 -1
- package/dist/cli/middleware.d.ts +0 -1
- package/dist/cli/middleware.js +0 -16
- package/dist/cli/middleware.js.map +0 -1
- package/dist/client.d.ts +0 -1
- package/dist/client.js +0 -17
- package/dist/client.js.map +0 -1
- package/dist/common/middlewares/log.middleware.d.ts +0 -2
- package/dist/common/middlewares/log.middleware.js +0 -12
- package/dist/common/middlewares/log.middleware.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -32
- package/dist/index.js.map +0 -1
- package/dist/modules/cats/cat.controller.d.ts +0 -58
- package/dist/modules/cats/cat.controller.js +0 -90
- package/dist/modules/cats/cat.controller.js.map +0 -1
- package/dist/modules/cats/cat.dto.d.ts +0 -8
- package/dist/modules/cats/cat.dto.js +0 -44
- package/dist/modules/cats/cat.dto.js.map +0 -1
- package/dist/modules/cats/cat.service.d.ts +0 -23
- package/dist/modules/cats/cat.service.js +0 -56
- package/dist/modules/cats/cat.service.js.map +0 -1
- package/dist/tests/e2e..test.d.ts +0 -1
- package/dist/tests/e2e..test.js +0 -16
- package/dist/tests/e2e..test.js.map +0 -1
|
@@ -5,6 +5,7 @@ exports.ControllerTemplate = `
|
|
|
5
5
|
import {
|
|
6
6
|
type T,
|
|
7
7
|
Controller,
|
|
8
|
+
Service,
|
|
8
9
|
Middleware,
|
|
9
10
|
Get,
|
|
10
11
|
Post,
|
|
@@ -16,17 +17,19 @@ import { CatService } from "./cat.service";
|
|
|
16
17
|
import { CreateCatDto , UpdateCatDto } from "./cat.dto";
|
|
17
18
|
import { LogMiddleware } from "../../common/middlewares/log.middleware";
|
|
18
19
|
|
|
20
|
+
@Service([CatService])
|
|
19
21
|
@Controller("/cats")
|
|
20
22
|
class CatController {
|
|
21
23
|
|
|
22
24
|
constructor(
|
|
23
|
-
private catService: CatService
|
|
25
|
+
private catService: CatService
|
|
24
26
|
) {}
|
|
25
27
|
|
|
26
28
|
@Get("/")
|
|
27
29
|
@Middleware(LogMiddleware)
|
|
28
30
|
async index() {
|
|
29
|
-
|
|
31
|
+
const cats = await this.catService.index();
|
|
32
|
+
return { cats };
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
@Get("/:id")
|
|
@@ -38,8 +41,8 @@ class CatController {
|
|
|
38
41
|
id: number;
|
|
39
42
|
};
|
|
40
43
|
}>) {
|
|
41
|
-
|
|
42
|
-
return
|
|
44
|
+
const cat = await this.catService.show(params.id);
|
|
45
|
+
return { cat }
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
@Post("/")
|
|
@@ -51,11 +54,13 @@ class CatController {
|
|
|
51
54
|
body: CreateCatDto;
|
|
52
55
|
}>) {
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
const cat = await this.catService
|
|
55
58
|
.create({
|
|
56
59
|
name: body.name,
|
|
57
60
|
age: body.age
|
|
58
61
|
});
|
|
62
|
+
|
|
63
|
+
return { cat };
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
@Put("/:id")
|
|
@@ -71,11 +76,13 @@ class CatController {
|
|
|
71
76
|
body: UpdateCatDto;
|
|
72
77
|
}>) {
|
|
73
78
|
|
|
74
|
-
|
|
79
|
+
const cat = await this.catService
|
|
75
80
|
.update(params.id, {
|
|
76
81
|
name: body.name,
|
|
77
82
|
age: body.age
|
|
78
83
|
});
|
|
84
|
+
|
|
85
|
+
return { cat }
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
@Delete("/:id")
|
|
@@ -88,8 +95,10 @@ class CatController {
|
|
|
88
95
|
};
|
|
89
96
|
}>) {
|
|
90
97
|
|
|
91
|
-
|
|
98
|
+
const deleted = await this.catService
|
|
92
99
|
.remove(params.id);
|
|
100
|
+
|
|
101
|
+
return deleted;
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../src/cli/generators/controller/template.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../src/cli/generators/controller/template.ts"],"names":[],"mappings":";;;AAAa,QAAA,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuGjC,CAAC"}
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
Min,
|
|
24
24
|
IsNotEmpty,
|
|
25
25
|
IsNumber,
|
|
26
|
+
IsOptional
|
|
26
27
|
} from "class-validator";
|
|
27
28
|
|
|
28
29
|
export class Create${className} {
|
|
@@ -36,13 +37,14 @@ export class Create${className} {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export class Update${className} {
|
|
40
|
+
@IsOptional()
|
|
39
41
|
@IsString()
|
|
40
|
-
|
|
41
|
-
name!: string;
|
|
42
|
+
name?: string;
|
|
42
43
|
|
|
44
|
+
@IsOptional()
|
|
43
45
|
@IsNumber()
|
|
44
46
|
@Min(0.1)
|
|
45
|
-
age
|
|
47
|
+
age?: number;
|
|
46
48
|
}
|
|
47
49
|
`);
|
|
48
50
|
console.log(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/generators/dto/index.ts"],"names":[],"mappings":";;;;;AAQA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/generators/dto/index.ts"],"names":[],"mappings":";;;;;AAQA,8BAwDC;AAhED,4CAAoB;AACpB,gDAAwB;AACxB,sCAImB;AAEnB,SAAgB,SAAS,CAAC,IAAa,EAAC,IAAa;IACjD,IAAI,CAAC,IAAI,EAAE,CAAC;QACR,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;QACrD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAEH,MAAM,YAAY,GAAG,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAG,SAAS,EAAE,IAAA,iBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC;IAEnF,MAAM,QAAQ,GAAG,GAAG,IAAA,mBAAU,EAAC,IAAI,CAAC,SAAS,CAAC;IAE9C,MAAM,MAAM,GAAG,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IAEjD,YAAE,CAAC,SAAS,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAEhD,MAAM,SAAS,GAAG,IAAA,mBAAU,EAAC,IAAA,mBAAU,EAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC;IAEvD,YAAE,CAAC,aAAa,CACd,MAAM,EACN;;;;;;;;;qBASiB,SAAS;;;;;;;;;;qBAUT,SAAS;;;;;;;;;;CAU7B,CACE,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC;WACF,MAAM;;gCAEe,IAAI;;CAEnC,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -54,7 +54,7 @@ class ${controllerName} {
|
|
|
54
54
|
async show({
|
|
55
55
|
params
|
|
56
56
|
}: T.Context<{ params: { id: number } }>) {
|
|
57
|
-
return this.${(0, shared_1.toSingular)(name)}Service.show(params.id);
|
|
57
|
+
return this.${(0, shared_1.toSingular)(name)}Service.show(+params.id);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
@Post("/")
|
|
@@ -81,7 +81,7 @@ class ${controllerName} {
|
|
|
81
81
|
}>) {
|
|
82
82
|
|
|
83
83
|
return this.${(0, shared_1.toSingular)(name)}Service
|
|
84
|
-
.update(params.id, {
|
|
84
|
+
.update(+params.id, {
|
|
85
85
|
name: body.name,
|
|
86
86
|
age: body.age
|
|
87
87
|
});
|
|
@@ -92,7 +92,7 @@ class ${controllerName} {
|
|
|
92
92
|
params
|
|
93
93
|
}: T.Context<{ params: { id: number } }>) {
|
|
94
94
|
return this.${(0, shared_1.toSingular)(name)}Service
|
|
95
|
-
.remove(params.id);
|
|
95
|
+
.remove(+params.id);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const ServiceTemplate = "\ntype Cat = {\n id: number;\n name: string;\n age: number;\n}\n\nexport class CatService {\n private cats: Cat[] = [\n { id: 1, name: 'cat1', age: 1.6 },\n { id: 2, name: 'cat2', age: 1.8 },\n ];\n public async index() {\n return this.cats;\n };\n\n public async show(id: number) {\n
|
|
1
|
+
export declare const ServiceTemplate = "\nimport { \n CreateCatDto, \n UpdateCatDto \n} from \"./cat.dto\";\n\ntype Cat = {\n id: number;\n name: string;\n age: number;\n}\n\nexport class CatService {\n private cats: Cat[] = [\n { id: 1, name: 'cat1', age: 1.6 },\n { id: 2, name: 'cat2', age: 1.8 },\n ];\n public async index() {\n return this.cats;\n };\n\n public async show(id: number) {\n const cat = this.cats.find(cat => cat.id === id);\n if(cat == null) return null;\n return cat;\n };\n\n public async create({ name, age }: CreateCatDto) {\n\n const cat = {\n id: this.cats.length + 1,\n name: name,\n age: age\n };\n\n this.cats.push(cat);\n\n return cat;\n }\n \n public async update(id: number, { name, age }: UpdateCatDto) {\n const index = this.cats.findIndex(d => d.id === id);\n\n if (index === -1) {\n throw new Error(\"Cat not found\");\n }\n\n this.cats[index] = {\n ...this.cats[index],\n ...{ name, age } \n };\n\n const cat = this.cats[index];\n\n return cat;\n }\n\n public async remove(id: number) {\n const index = this.cats.findIndex(d => d.id === id);\n\n if (index === -1) {\n throw new Error(\"Cat not found\");\n }\n\n this.cats.splice(index, 1);\n\n return true;\n }\n}\n";
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServiceTemplate = void 0;
|
|
4
4
|
exports.ServiceTemplate = `
|
|
5
|
+
import {
|
|
6
|
+
CreateCatDto,
|
|
7
|
+
UpdateCatDto
|
|
8
|
+
} from "./cat.dto";
|
|
9
|
+
|
|
5
10
|
type Cat = {
|
|
6
11
|
id: number;
|
|
7
12
|
name: string;
|
|
@@ -18,12 +23,14 @@ export class CatService {
|
|
|
18
23
|
};
|
|
19
24
|
|
|
20
25
|
public async show(id: number) {
|
|
21
|
-
|
|
26
|
+
const cat = this.cats.find(cat => cat.id === id);
|
|
27
|
+
if(cat == null) return null;
|
|
28
|
+
return cat;
|
|
22
29
|
};
|
|
23
30
|
|
|
24
|
-
public async create({ name, age }:
|
|
31
|
+
public async create({ name, age }: CreateCatDto) {
|
|
25
32
|
|
|
26
|
-
const cat
|
|
33
|
+
const cat = {
|
|
27
34
|
id: this.cats.length + 1,
|
|
28
35
|
name: name,
|
|
29
36
|
age: age
|
|
@@ -31,13 +38,10 @@ export class CatService {
|
|
|
31
38
|
|
|
32
39
|
this.cats.push(cat);
|
|
33
40
|
|
|
34
|
-
return
|
|
35
|
-
message: "Created",
|
|
36
|
-
cat
|
|
37
|
-
};
|
|
41
|
+
return cat;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
public async update(id: number, { name, age }:
|
|
44
|
+
public async update(id: number, { name, age }: UpdateCatDto) {
|
|
41
45
|
const index = this.cats.findIndex(d => d.id === id);
|
|
42
46
|
|
|
43
47
|
if (index === -1) {
|
|
@@ -49,10 +53,9 @@ export class CatService {
|
|
|
49
53
|
...{ name, age }
|
|
50
54
|
};
|
|
51
55
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
+
const cat = this.cats[index];
|
|
57
|
+
|
|
58
|
+
return cat;
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
public async remove(id: number) {
|
|
@@ -62,12 +65,9 @@ export class CatService {
|
|
|
62
65
|
throw new Error("Cat not found");
|
|
63
66
|
}
|
|
64
67
|
|
|
65
|
-
|
|
68
|
+
this.cats.splice(index, 1);
|
|
66
69
|
|
|
67
|
-
return
|
|
68
|
-
message: "Deleted",
|
|
69
|
-
cat: removedCat
|
|
70
|
-
};
|
|
70
|
+
return true;
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
`;
|
package/dist/cli/index.js
CHANGED
|
@@ -20,7 +20,7 @@ if (command === "create" && type === "new") {
|
|
|
20
20
|
.then(_ => process.exit(1))
|
|
21
21
|
.catch(_ => process.exit(1));
|
|
22
22
|
}
|
|
23
|
-
if (command === "g") {
|
|
23
|
+
else if (command === "g") {
|
|
24
24
|
if (!name) {
|
|
25
25
|
printUsage();
|
|
26
26
|
process.exit(1);
|
|
@@ -47,19 +47,22 @@ if (command === "g") {
|
|
|
47
47
|
}
|
|
48
48
|
process.exit(0);
|
|
49
49
|
}
|
|
50
|
+
else {
|
|
51
|
+
printUsage();
|
|
52
|
+
}
|
|
50
53
|
function printUsage() {
|
|
51
54
|
console.log(`
|
|
52
55
|
Usage:
|
|
53
56
|
|
|
54
|
-
spear create new
|
|
57
|
+
spear create new app
|
|
55
58
|
|
|
56
59
|
Generators:
|
|
57
60
|
|
|
58
|
-
spear g module
|
|
59
|
-
spear g controller
|
|
60
|
-
spear g service
|
|
61
|
-
spear g dto
|
|
62
|
-
spear g middleware
|
|
61
|
+
spear g module names
|
|
62
|
+
spear g controller name
|
|
63
|
+
spear g service name
|
|
64
|
+
spear g dto name
|
|
65
|
+
spear g middleware name
|
|
63
66
|
`);
|
|
64
67
|
}
|
|
65
68
|
//# sourceMappingURL=index.js.map
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAEA,0CAA6C;AAC7C,gDAAmD;AACnD,wDAA2D;AAC3D,kDAAqD;AACrD,wDAA2D;AAC3D,0CAA6C;AAE7C,MAAM,CAAC,EAAE,AAAD,EAAG,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;AAE/C;;;;;;GAMG;AAEH,IAAI,OAAO,KAAK,QAAQ,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;IAC3C,IAAA,eAAS,EAAC,IAAI,CAAC;SACd,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,C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IAAI,CAAC,CAAC;YACrB,MAAM;QAER,KAAK,YAAY;YACf,IAAA,6BAAgB,EAAC,IAAI,EAAC,IAAI,CAAC,CAAC;YAC5B,MAAM;QAER;YACE,UAAU,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;KAAM,CAAC;IACN,UAAU,EAAE,CAAC;AACf,CAAC;AAED,SAAS,UAAU;IACjB,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;CAYb,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import type { AnyRoutes, RoutesWithMethod,
|
|
2
|
-
type RequestInput<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = RequestParams<TRoutes, TPath, TMethod> extends never ? {
|
|
3
|
-
params?: never;
|
|
4
|
-
query?: RequestQuery<TRoutes, TPath, TMethod>;
|
|
5
|
-
body?: RequestBody<TRoutes, TPath, TMethod>;
|
|
6
|
-
files?: RequestFiles<TRoutes, TPath, TMethod>;
|
|
7
|
-
} : {
|
|
8
|
-
params: RequestParams<TRoutes, TPath, TMethod>;
|
|
9
|
-
query?: RequestQuery<TRoutes, TPath, TMethod>;
|
|
10
|
-
body?: RequestBody<TRoutes, TPath, TMethod>;
|
|
11
|
-
files?: RequestFiles<TRoutes, TPath, TMethod>;
|
|
12
|
-
};
|
|
1
|
+
import type { AnyRoutes, RoutesWithMethod, ResponseType, RequestInput, OptionalIfEmpty, ApiResponse } from "./types";
|
|
13
2
|
/**
|
|
14
3
|
* Type-safe HTTP client built on top of the native Fetch API.
|
|
15
4
|
*
|
|
@@ -41,42 +30,23 @@ type RequestInput<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMetho
|
|
|
41
30
|
* })
|
|
42
31
|
*
|
|
43
32
|
* // fully typed response
|
|
44
|
-
*
|
|
33
|
+
* if(res.ok)
|
|
34
|
+
* console.log(res.cats)
|
|
45
35
|
* ```
|
|
46
36
|
*/
|
|
47
37
|
declare class ApiClient<TRoutes extends AnyRoutes> {
|
|
48
38
|
private baseURL;
|
|
49
39
|
constructor(baseURL: string);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
post<TPath extends RoutesWithMethod<TRoutes, "POST">>(path: TPath, input: RequestInput<TRoutes, TPath, "POST">): Promise<{
|
|
61
|
-
ok: boolean;
|
|
62
|
-
status: number;
|
|
63
|
-
data: ResponseType<TRoutes, TPath, "POST">;
|
|
64
|
-
}>;
|
|
65
|
-
put<TPath extends RoutesWithMethod<TRoutes, "PUT">>(path: TPath, input: RequestInput<TRoutes, TPath, "PUT">): Promise<{
|
|
66
|
-
ok: boolean;
|
|
67
|
-
status: number;
|
|
68
|
-
data: ResponseType<TRoutes, TPath, "PUT">;
|
|
69
|
-
}>;
|
|
70
|
-
patch<TPath extends RoutesWithMethod<TRoutes, "PATCH">>(path: TPath, input: RequestInput<TRoutes, TPath, "PATCH">): Promise<{
|
|
71
|
-
ok: boolean;
|
|
72
|
-
status: number;
|
|
73
|
-
data: ResponseType<TRoutes, TPath, "PATCH">;
|
|
74
|
-
}>;
|
|
75
|
-
delete<TPath extends RoutesWithMethod<TRoutes, "DELETE">>(path: TPath, input?: RequestInput<TRoutes, TPath, "DELETE">): Promise<{
|
|
76
|
-
ok: boolean;
|
|
77
|
-
status: number;
|
|
78
|
-
data: ResponseType<TRoutes, TPath, "DELETE">;
|
|
79
|
-
}>;
|
|
40
|
+
private request;
|
|
41
|
+
get<TPath extends RoutesWithMethod<TRoutes, "GET">>(path: TPath, ...args: OptionalIfEmpty<RequestInput<TRoutes, TPath, "GET">>): Promise<ApiResponse<ResponseType<TRoutes, TPath, "GET">>>;
|
|
42
|
+
post<TPath extends RoutesWithMethod<TRoutes, "POST">>(path: TPath, ...args: OptionalIfEmpty<RequestInput<TRoutes, TPath, "POST">>): Promise<ApiResponse<ResponseType<TRoutes, TPath, "POST">>>;
|
|
43
|
+
put<TPath extends RoutesWithMethod<TRoutes, "PUT">>(path: TPath, ...args: OptionalIfEmpty<RequestInput<TRoutes, TPath, "PUT">>): Promise<ApiResponse<ResponseType<TRoutes, TPath, "PUT">>>;
|
|
44
|
+
patch<TPath extends RoutesWithMethod<TRoutes, "PATCH">>(path: TPath, ...args: OptionalIfEmpty<RequestInput<TRoutes, TPath, "PATCH">>): Promise<ApiResponse<ResponseType<TRoutes, TPath, "PATCH">>>;
|
|
45
|
+
delete<TPath extends RoutesWithMethod<TRoutes, "DELETE">>(path: TPath, ...args: OptionalIfEmpty<RequestInput<TRoutes, TPath, "DELETE">>): Promise<ApiResponse<ResponseType<TRoutes, TPath, "DELETE">>>;
|
|
46
|
+
upload<TMethod extends "POST" | "PUT" | "PATCH" = "POST", TPath extends RoutesWithMethod<TRoutes, TMethod> = RoutesWithMethod<TRoutes, TMethod>>(path: TPath, options: {
|
|
47
|
+
method?: TMethod;
|
|
48
|
+
formdata: FormData;
|
|
49
|
+
}): Promise<ApiResponse<ResponseType<TRoutes, TPath, TMethod>>>;
|
|
80
50
|
}
|
|
81
51
|
export { ApiClient };
|
|
82
52
|
export default ApiClient;
|
|
@@ -15,27 +15,51 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.ApiClient = void 0;
|
|
27
37
|
let fetchFn = null;
|
|
28
|
-
async
|
|
38
|
+
const getFetch = async () => {
|
|
29
39
|
if (fetchFn)
|
|
30
40
|
return fetchFn;
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
// Browser OR modern Node v18+ (preferred)
|
|
42
|
+
if (typeof globalThis.fetch === "function") {
|
|
43
|
+
fetchFn = globalThis.fetch.bind(globalThis);
|
|
33
44
|
return fetchFn;
|
|
34
45
|
}
|
|
46
|
+
// Legacy Node fallback
|
|
35
47
|
const mod = await Promise.resolve().then(() => __importStar(require("node-fetch")));
|
|
36
48
|
fetchFn = mod.default;
|
|
37
49
|
return fetchFn;
|
|
38
|
-
}
|
|
50
|
+
};
|
|
51
|
+
const isFormData = (value) => {
|
|
52
|
+
// In Node.js 18+ it is compatible with the browser implementation.
|
|
53
|
+
if (typeof globalThis.FormData !== "undefined") {
|
|
54
|
+
return value instanceof globalThis.FormData;
|
|
55
|
+
}
|
|
56
|
+
// In Node.js below 18-, FormData is not the same as in the browser
|
|
57
|
+
// using from pkg form-data
|
|
58
|
+
return (value != null &&
|
|
59
|
+
typeof value === "object" &&
|
|
60
|
+
typeof value.append === "function" &&
|
|
61
|
+
typeof value.getHeaders === "function");
|
|
62
|
+
};
|
|
39
63
|
/**
|
|
40
64
|
* Type-safe HTTP client built on top of the native Fetch API.
|
|
41
65
|
*
|
|
@@ -67,7 +91,8 @@ async function getFetch() {
|
|
|
67
91
|
* })
|
|
68
92
|
*
|
|
69
93
|
* // fully typed response
|
|
70
|
-
*
|
|
94
|
+
* if(res.ok)
|
|
95
|
+
* console.log(res.cats)
|
|
71
96
|
* ```
|
|
72
97
|
*/
|
|
73
98
|
class ApiClient {
|
|
@@ -92,50 +117,62 @@ class ApiClient {
|
|
|
92
117
|
if (!fetchFn) {
|
|
93
118
|
throw new Error("Fetch is not available. Use Node 18+ or polyfill.");
|
|
94
119
|
}
|
|
120
|
+
let body = input?.body
|
|
121
|
+
? JSON.stringify(input.body)
|
|
122
|
+
: undefined;
|
|
123
|
+
let headers = {
|
|
124
|
+
"Content-Type": "application/json",
|
|
125
|
+
};
|
|
126
|
+
const isFileUpload = isFormData(input?.body);
|
|
127
|
+
if (isFileUpload) {
|
|
128
|
+
body = input?.body;
|
|
129
|
+
headers = undefined;
|
|
130
|
+
}
|
|
95
131
|
const res = await fetchFn(url, {
|
|
96
132
|
method: method,
|
|
97
|
-
headers
|
|
98
|
-
|
|
99
|
-
},
|
|
100
|
-
body: input?.body
|
|
101
|
-
? JSON.stringify(input.body)
|
|
102
|
-
: undefined,
|
|
133
|
+
headers,
|
|
134
|
+
body
|
|
103
135
|
});
|
|
104
136
|
const contentType = res.headers.get("content-type");
|
|
105
137
|
const isJson = contentType?.includes("application/json");
|
|
106
138
|
const data = isJson
|
|
107
139
|
? await res.json()
|
|
108
140
|
: await res.text();
|
|
109
|
-
// if (!res.ok) {
|
|
110
|
-
// throw new Error(
|
|
111
|
-
// data?.message ||
|
|
112
|
-
// data?.error ||
|
|
113
|
-
// (typeof data === "string"
|
|
114
|
-
// ? data
|
|
115
|
-
// : `HTTP ${res.status}`),
|
|
116
|
-
// );
|
|
117
|
-
// }
|
|
118
141
|
return {
|
|
119
142
|
ok: res.ok,
|
|
143
|
+
headers: res.headers,
|
|
120
144
|
status: res.status,
|
|
121
|
-
data,
|
|
145
|
+
data: data,
|
|
122
146
|
};
|
|
123
147
|
}
|
|
124
|
-
async get(path,
|
|
148
|
+
async get(path, ...args) {
|
|
149
|
+
const input = args[0];
|
|
125
150
|
return this.request("GET", path, input);
|
|
126
151
|
}
|
|
127
|
-
async post(path,
|
|
152
|
+
async post(path, ...args) {
|
|
153
|
+
const input = args[0];
|
|
128
154
|
return this.request("POST", path, input);
|
|
129
155
|
}
|
|
130
|
-
async put(path,
|
|
156
|
+
async put(path, ...args) {
|
|
157
|
+
const input = args[0];
|
|
131
158
|
return this.request("PUT", path, input);
|
|
132
159
|
}
|
|
133
|
-
async patch(path,
|
|
160
|
+
async patch(path, ...args) {
|
|
161
|
+
const input = args[0];
|
|
134
162
|
return this.request("PATCH", path, input);
|
|
135
163
|
}
|
|
136
|
-
async delete(path,
|
|
164
|
+
async delete(path, ...args) {
|
|
165
|
+
const input = args[0];
|
|
137
166
|
return this.request("DELETE", path, input);
|
|
138
167
|
}
|
|
168
|
+
async upload(path, options) {
|
|
169
|
+
const { method = "POST", formdata } = options;
|
|
170
|
+
return this.request(method, path,
|
|
171
|
+
//@ts-ignore
|
|
172
|
+
{
|
|
173
|
+
body: formdata
|
|
174
|
+
});
|
|
175
|
+
}
|
|
139
176
|
}
|
|
140
177
|
exports.ApiClient = ApiClient;
|
|
141
178
|
exports.default = ApiClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/client/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/core/client/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,IAAI,OAAO,GAAwB,IAAI,CAAC;AAExC,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;IAC1B,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAE5B,0CAA0C;IAC1C,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QA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YAAY;QACZ;YACE,IAAI,EAAG,QAAQ;SAChB,CACF,CAAC;IACJ,CAAC;CAEF;AAEQ,8BAAS;AAClB,kBAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type AnyRoutes = {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
};
|
|
4
|
+
export type RoutesWithMethod<TRoutes extends AnyRoutes, TMethod extends string> = {
|
|
5
|
+
[K in keyof TRoutes]: TMethod extends keyof TRoutes[K] ? K : never;
|
|
6
|
+
}[keyof TRoutes];
|
|
7
|
+
export type ExtractFrom<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath], Key extends string> = TRoutes[TPath][TMethod] extends Record<Key, infer R> ? R : never;
|
|
8
|
+
export type RequestBody<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = ExtractFrom<TRoutes, TPath, TMethod, "body">;
|
|
9
|
+
export type RequestQuery<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = ExtractFrom<TRoutes, TPath, TMethod, "query">;
|
|
10
|
+
export type RequestParams<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = ExtractFrom<TRoutes, TPath, TMethod, "params">;
|
|
11
|
+
export type RequestFiles<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = ExtractFrom<TRoutes, TPath, TMethod, "files">;
|
|
12
|
+
export type ResponseType<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = TRoutes[TPath][TMethod] extends {
|
|
13
|
+
response: infer R;
|
|
14
|
+
} ? Awaited<R> : never;
|
|
15
|
+
export type Prettify<T> = {
|
|
16
|
+
[K in keyof T]: T[K];
|
|
17
|
+
} & {};
|
|
18
|
+
export type ExactProperty<Key extends string, T> = [
|
|
19
|
+
T
|
|
20
|
+
] extends [never] ? {
|
|
21
|
+
[K in Key]?: never;
|
|
22
|
+
} : undefined extends T ? {
|
|
23
|
+
[K in Key]?: T;
|
|
24
|
+
} : {} extends T ? {
|
|
25
|
+
[K in Key]?: T;
|
|
26
|
+
} : {
|
|
27
|
+
[K in Key]: T;
|
|
28
|
+
};
|
|
29
|
+
export type OptionalIfEmpty<T> = {} extends T ? [input?: T] : [input: T];
|
|
30
|
+
export type RequestInput<TRoutes extends AnyRoutes, TPath extends keyof TRoutes, TMethod extends keyof TRoutes[TPath]> = Prettify<ExactProperty<"params", RequestParams<TRoutes, TPath, TMethod>> & ExactProperty<"query", RequestQuery<TRoutes, TPath, TMethod>> & ExactProperty<"body", RequestBody<TRoutes, TPath, TMethod>> & ExactProperty<"files", RequestFiles<TRoutes, TPath, TMethod>>>;
|
|
31
|
+
export type SuccessStatus = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226;
|
|
32
|
+
export type ErrorStatus = 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
|
|
33
|
+
export type ApiResponse<T, E = any> = {
|
|
34
|
+
ok: true;
|
|
35
|
+
status: SuccessStatus;
|
|
36
|
+
headers: Headers;
|
|
37
|
+
data: T;
|
|
38
|
+
} | {
|
|
39
|
+
ok: false;
|
|
40
|
+
status: ErrorStatus;
|
|
41
|
+
headers: Headers;
|
|
42
|
+
data: E;
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/lib/core/client/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
type Route = {
|
|
2
2
|
method: string;
|
|
3
3
|
path: string;
|
|
4
|
-
response: string;
|
|
5
4
|
body: string;
|
|
6
5
|
params: string;
|
|
7
6
|
query: string;
|
|
8
7
|
files: string;
|
|
8
|
+
response: string;
|
|
9
9
|
};
|
|
10
10
|
type Options = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
name: RegExp;
|
|
14
|
-
};
|
|
11
|
+
folder: string;
|
|
12
|
+
name: RegExp;
|
|
15
13
|
output?: string;
|
|
16
14
|
};
|
|
17
|
-
export declare
|
|
15
|
+
export declare const generateRoutes: (globalPrefix: string, options: Options) => Promise<Route[] | undefined>;
|
|
18
16
|
export {};
|