tspace-spear 1.2.7 → 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 +347 -155
- 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 +108 -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 +57 -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 +55 -96
- 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 +190 -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.d.ts +78 -8
- package/dist/lib/core/decorators/context.js +84 -9
- 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/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/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 +15 -6
|
@@ -0,0 +1,173 @@
|
|
|
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.createModule = createModule;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const shared_1 = require("../shared");
|
|
10
|
+
function createModule(root, name) {
|
|
11
|
+
if (!name) {
|
|
12
|
+
console.log("Missing module path, try spear g module dogs");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const modulePath = path_1.default.resolve(process.cwd(), root, 'modules', (0, shared_1.toPlural)(name));
|
|
16
|
+
fs_1.default.mkdirSync(modulePath, { recursive: true });
|
|
17
|
+
const controllerPath = path_1.default.resolve(process.cwd(), root, "modules", (0, shared_1.toPlural)(name), `${(0, shared_1.toSingular)(name)}.controller.ts`);
|
|
18
|
+
const servicePath = path_1.default.resolve(process.cwd(), root, "modules", (0, shared_1.toPlural)(name), `${(0, shared_1.toSingular)(name)}.service.ts`);
|
|
19
|
+
const dtoPath = path_1.default.resolve(process.cwd(), root, "modules", (0, shared_1.toPlural)(name), `${(0, shared_1.toSingular)(name)}.dto.ts`);
|
|
20
|
+
const controllerName = (0, shared_1.capitalize)((0, shared_1.toSingular)(name)) + "Controller";
|
|
21
|
+
const serviceName = (0, shared_1.capitalize)((0, shared_1.toSingular)(name)) + "Service";
|
|
22
|
+
const dtoName = (0, shared_1.capitalize)((0, shared_1.toSingular)(name)) + "Dto";
|
|
23
|
+
fs_1.default.writeFileSync(controllerPath, `import {
|
|
24
|
+
type T,
|
|
25
|
+
Controller,
|
|
26
|
+
Get,
|
|
27
|
+
Post,
|
|
28
|
+
Put,
|
|
29
|
+
Patch,
|
|
30
|
+
Delete,
|
|
31
|
+
ValidateDto
|
|
32
|
+
} from "tspace-spear";
|
|
33
|
+
|
|
34
|
+
import { ${serviceName} } from "./${(0, shared_1.toSingular)(name)}.service";
|
|
35
|
+
|
|
36
|
+
import {
|
|
37
|
+
Create${dtoName},
|
|
38
|
+
Update${dtoName}
|
|
39
|
+
} from "./${(0, shared_1.toSingular)(name)}.dto";
|
|
40
|
+
|
|
41
|
+
@Controller("/${name}")
|
|
42
|
+
class ${controllerName} {
|
|
43
|
+
|
|
44
|
+
constructor(
|
|
45
|
+
private ${(0, shared_1.toSingular)(name)}Service: ${serviceName} = new ${serviceName}()
|
|
46
|
+
) {}
|
|
47
|
+
|
|
48
|
+
@Get("/")
|
|
49
|
+
async index() {
|
|
50
|
+
return this.${(0, shared_1.toSingular)(name)}Service.index();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Get("/:id")
|
|
54
|
+
async show({
|
|
55
|
+
params
|
|
56
|
+
}: T.Context<{ params: { id: number } }>) {
|
|
57
|
+
return this.${(0, shared_1.toSingular)(name)}Service.show(+params.id);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Post("/")
|
|
61
|
+
@ValidateDto(Create${dtoName})
|
|
62
|
+
async create({
|
|
63
|
+
body
|
|
64
|
+
}: T.Context<{ body: Create${dtoName} }>) {
|
|
65
|
+
return this.${(0, shared_1.toSingular)(name)}Service
|
|
66
|
+
.create({
|
|
67
|
+
name: body.name,
|
|
68
|
+
age: body.age
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@Put("/:id")
|
|
73
|
+
@Patch("/:id")
|
|
74
|
+
@ValidateDto(Update${dtoName})
|
|
75
|
+
async update({
|
|
76
|
+
params,
|
|
77
|
+
body
|
|
78
|
+
}: T.Context<{
|
|
79
|
+
params: { id: number };
|
|
80
|
+
body: Update${dtoName};
|
|
81
|
+
}>) {
|
|
82
|
+
|
|
83
|
+
return this.${(0, shared_1.toSingular)(name)}Service
|
|
84
|
+
.update(+params.id, {
|
|
85
|
+
name: body.name,
|
|
86
|
+
age: body.age
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Delete("/:id")
|
|
91
|
+
async remove({
|
|
92
|
+
params
|
|
93
|
+
}: T.Context<{ params: { id: number } }>) {
|
|
94
|
+
return this.${(0, shared_1.toSingular)(name)}Service
|
|
95
|
+
.remove(+params.id);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { ${controllerName} };
|
|
100
|
+
export default ${controllerName};
|
|
101
|
+
`);
|
|
102
|
+
fs_1.default.writeFileSync(servicePath, `import {
|
|
103
|
+
Create${dtoName},
|
|
104
|
+
Update${dtoName}
|
|
105
|
+
} from "./${(0, shared_1.toSingular)(name)}.dto";
|
|
106
|
+
|
|
107
|
+
class ${serviceName} {
|
|
108
|
+
public async index() {
|
|
109
|
+
return [];
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
public async show(id: number) {
|
|
113
|
+
return {};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
public async create(body : Create${dtoName}) {
|
|
117
|
+
return {};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public async update(id: number, body: Update${dtoName}) {
|
|
121
|
+
return {};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public async remove(id: number) {
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { ${serviceName} };
|
|
130
|
+
export default ${serviceName};
|
|
131
|
+
`);
|
|
132
|
+
fs_1.default.writeFileSync(dtoPath, `import {
|
|
133
|
+
IsString,
|
|
134
|
+
Min,
|
|
135
|
+
IsNotEmpty,
|
|
136
|
+
IsNumber,
|
|
137
|
+
} from "class-validator";
|
|
138
|
+
|
|
139
|
+
export class Create${dtoName} {
|
|
140
|
+
@IsString()
|
|
141
|
+
@IsNotEmpty()
|
|
142
|
+
name!: string;
|
|
143
|
+
|
|
144
|
+
@IsNumber()
|
|
145
|
+
@Min(0.1)
|
|
146
|
+
age!: number;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export class Update${dtoName} {
|
|
150
|
+
@IsString()
|
|
151
|
+
@IsNotEmpty()
|
|
152
|
+
name!: string;
|
|
153
|
+
|
|
154
|
+
@IsNumber()
|
|
155
|
+
@Min(0.1)
|
|
156
|
+
age!: number;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
`);
|
|
160
|
+
console.log(`
|
|
161
|
+
CREATE ${modulePath}
|
|
162
|
+
CREATE ${controllerPath}
|
|
163
|
+
CREATE ${servicePath}
|
|
164
|
+
CREATE ${dtoPath}
|
|
165
|
+
|
|
166
|
+
✔ Successfully generated module "${name}"
|
|
167
|
+
|
|
168
|
+
Controller ${controllerName}
|
|
169
|
+
Service ${serviceName}
|
|
170
|
+
DTO ${dtoName}
|
|
171
|
+
`);
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @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zB,cAAc;cACd,WAAW;cACX,OAAO;CACpB,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createService(root: string, name?: string): void;
|
|
@@ -0,0 +1,53 @@
|
|
|
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.createService = createService;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const shared_1 = require("../shared");
|
|
10
|
+
function createService(root, name) {
|
|
11
|
+
if (!name) {
|
|
12
|
+
console.log("Missing service path, try spear g service dog");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const resolvedPath = path_1.default.resolve(process.cwd(), root, 'modules', (0, shared_1.toPlural)(name));
|
|
16
|
+
const fileName = `${(0, shared_1.toSingular)(name)}.service.ts`;
|
|
17
|
+
const target = path_1.default.join(resolvedPath, fileName);
|
|
18
|
+
fs_1.default.mkdirSync(resolvedPath, { recursive: true });
|
|
19
|
+
const className = (0, shared_1.capitalize)((0, shared_1.toSingular)(name)) + "Service";
|
|
20
|
+
fs_1.default.writeFileSync(target, `
|
|
21
|
+
class ${className} {
|
|
22
|
+
public async index() {
|
|
23
|
+
return [];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
public async show(id: number) {
|
|
27
|
+
return {};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
public async create() {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public async update(id: number) {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public async remove(id: number) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { ${className} };
|
|
44
|
+
export default ${className};
|
|
45
|
+
`);
|
|
46
|
+
console.log(`
|
|
47
|
+
CREATE ${target}
|
|
48
|
+
|
|
49
|
+
✔ Successfully generated service "${name}"
|
|
50
|
+
|
|
51
|
+
`);
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/generators/service/index.ts"],"names":[],"mappings":";;;;;AAQA,sCAoDC;AA5DD,4CAAoB;AACpB,gDAAwB;AACxB,sCAImB;AAEnB,SAAgB,aAAa,CAAC,IAAa,EAAC,IAAa;IACvD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;QAC7D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,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,aAAa,CAAC;IAElD,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,SAAS,CAAC;IAE3D,YAAE,CAAC,aAAa,CACd,MAAM,EACN;QACI,SAAS;;;;;;;;;;;;;;;;;;;;;;WAsBN,SAAS;iBACH,SAAS;CACzB,CACE,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC;WACF,MAAM;;oCAEmB,IAAI;;CAEvC,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
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";
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceTemplate = void 0;
|
|
4
|
+
exports.ServiceTemplate = `
|
|
5
|
+
import {
|
|
6
|
+
CreateCatDto,
|
|
7
|
+
UpdateCatDto
|
|
8
|
+
} from "./cat.dto";
|
|
9
|
+
|
|
10
|
+
type Cat = {
|
|
11
|
+
id: number;
|
|
12
|
+
name: string;
|
|
13
|
+
age: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class CatService {
|
|
17
|
+
private cats: Cat[] = [
|
|
18
|
+
{ id: 1, name: 'cat1', age: 1.6 },
|
|
19
|
+
{ id: 2, name: 'cat2', age: 1.8 },
|
|
20
|
+
];
|
|
21
|
+
public async index() {
|
|
22
|
+
return this.cats;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
public async show(id: number) {
|
|
26
|
+
const cat = this.cats.find(cat => cat.id === id);
|
|
27
|
+
if(cat == null) return null;
|
|
28
|
+
return cat;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
public async create({ name, age }: CreateCatDto) {
|
|
32
|
+
|
|
33
|
+
const cat = {
|
|
34
|
+
id: this.cats.length + 1,
|
|
35
|
+
name: name,
|
|
36
|
+
age: age
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
this.cats.push(cat);
|
|
40
|
+
|
|
41
|
+
return cat;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public async update(id: number, { name, age }: UpdateCatDto) {
|
|
45
|
+
const index = this.cats.findIndex(d => d.id === id);
|
|
46
|
+
|
|
47
|
+
if (index === -1) {
|
|
48
|
+
throw new Error("Cat not found");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.cats[index] = {
|
|
52
|
+
...this.cats[index],
|
|
53
|
+
...{ name, age }
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const cat = this.cats[index];
|
|
57
|
+
|
|
58
|
+
return cat;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public async remove(id: number) {
|
|
62
|
+
const index = this.cats.findIndex(d => d.id === id);
|
|
63
|
+
|
|
64
|
+
if (index === -1) {
|
|
65
|
+
throw new Error("Cat not found");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.cats.splice(index, 1);
|
|
69
|
+
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../../src/cli/generators/service/template.ts"],"names":[],"mappings":";;;AACa,QAAA,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqE9B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toSingular = toSingular;
|
|
4
|
+
exports.toPlural = toPlural;
|
|
5
|
+
exports.capitalize = capitalize;
|
|
6
|
+
function toSingular(name) {
|
|
7
|
+
if (!name)
|
|
8
|
+
return name;
|
|
9
|
+
return name.endsWith("s") ? name.slice(0, -1) : name;
|
|
10
|
+
}
|
|
11
|
+
function toPlural(name) {
|
|
12
|
+
if (!name)
|
|
13
|
+
return name;
|
|
14
|
+
if (name.endsWith("s"))
|
|
15
|
+
return name;
|
|
16
|
+
return name + "s";
|
|
17
|
+
}
|
|
18
|
+
function capitalize(value) {
|
|
19
|
+
return (value.charAt(0).toUpperCase() +
|
|
20
|
+
value.slice(1));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/cli/generators/shared/index.ts"],"names":[],"mappings":";;AAAA,gCAGC;AAED,4BAMC;AAED,gCAOC;AApBD,SAAgB,UAAU,CAAC,IAAY;IACrC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC;AAED,SAAgB,QAAQ,CAAC,IAAY;IACnC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAEvB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAEpC,OAAO,IAAI,GAAG,GAAG,CAAC;AACpB,CAAC;AAED,SAAgB,UAAU,CACxB,KAAa;IAEb,OAAO,CACL,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE;QAC7B,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CACf,CAAC;AACJ,CAAC"}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,109 +1,68 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`);
|
|
4
|
+
const app_1 = require("./generators/app");
|
|
5
|
+
const module_1 = require("./generators/module");
|
|
6
|
+
const controller_1 = require("./generators/controller");
|
|
7
|
+
const service_1 = require("./generators/service");
|
|
8
|
+
const middleware_1 = require("./generators/middleware");
|
|
9
|
+
const dto_1 = require("./generators/dto");
|
|
10
|
+
const [, , command, type, name] = process.argv;
|
|
11
|
+
/**
|
|
12
|
+
* spear create new <name>
|
|
13
|
+
* spear g module <name>
|
|
14
|
+
* spear g controller <name>
|
|
15
|
+
* spear g service <name>
|
|
16
|
+
* spear g middleware <name>
|
|
17
|
+
*/
|
|
18
|
+
if (command === "create" && type === "new") {
|
|
19
|
+
(0, app_1.createApp)(name)
|
|
20
|
+
.then(_ => process.exit(1))
|
|
21
|
+
.catch(_ => process.exit(1));
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
if (!
|
|
29
|
-
|
|
23
|
+
else if (command === "g") {
|
|
24
|
+
if (!name) {
|
|
25
|
+
printUsage();
|
|
30
26
|
process.exit(1);
|
|
31
27
|
}
|
|
32
|
-
const root =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
const root = 'src';
|
|
29
|
+
switch (type) {
|
|
30
|
+
case "module":
|
|
31
|
+
(0, module_1.createModule)(root, name);
|
|
32
|
+
break;
|
|
33
|
+
case "controller":
|
|
34
|
+
(0, controller_1.createController)(root, name);
|
|
35
|
+
break;
|
|
36
|
+
case "service":
|
|
37
|
+
(0, service_1.createService)(root, name);
|
|
38
|
+
break;
|
|
39
|
+
case "dto":
|
|
40
|
+
(0, dto_1.createDto)(root, name);
|
|
41
|
+
break;
|
|
42
|
+
case "middleware":
|
|
43
|
+
(0, middleware_1.createMiddleware)(root, name);
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
printUsage();
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
type T,
|
|
57
|
-
Controller,
|
|
58
|
-
Get,
|
|
59
|
-
Post,
|
|
60
|
-
Put,
|
|
61
|
-
Delete
|
|
62
|
-
} from "tspace-spear";
|
|
63
|
-
|
|
64
|
-
@Controller("/${name}")
|
|
65
|
-
export default class ${className} {
|
|
66
|
-
|
|
67
|
-
@Get("/")
|
|
68
|
-
async index() {
|
|
69
|
-
return {};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
@Get("/:id")
|
|
73
|
-
async show({
|
|
74
|
-
params
|
|
75
|
-
}: T.Context<{ params: { id: number } }>) {
|
|
76
|
-
return { id: params.id };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@Post("/")
|
|
80
|
-
async create({
|
|
81
|
-
body
|
|
82
|
-
}: T.Context<{ body: {} }>) {
|
|
83
|
-
return { body };
|
|
84
|
-
}
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
printUsage();
|
|
52
|
+
}
|
|
53
|
+
function printUsage() {
|
|
54
|
+
console.log(`
|
|
55
|
+
Usage:
|
|
85
56
|
|
|
86
|
-
|
|
87
|
-
async update({
|
|
88
|
-
params,
|
|
89
|
-
body
|
|
90
|
-
}: T.Context<{ params: { id: number }; body: {} }>) {
|
|
91
|
-
return { id: params.id, body };
|
|
92
|
-
}
|
|
57
|
+
spear create new app
|
|
93
58
|
|
|
94
|
-
|
|
95
|
-
async remove({
|
|
96
|
-
params
|
|
97
|
-
}: T.Context<{ params: { id: number } }>) {
|
|
98
|
-
return { id: params.id };
|
|
99
|
-
}
|
|
59
|
+
Generators:
|
|
100
60
|
|
|
101
|
-
|
|
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
|
|
102
66
|
`);
|
|
103
|
-
console.log(`Controller created: ${target}`);
|
|
104
|
-
}
|
|
105
|
-
function capitalize(value) {
|
|
106
|
-
return (value.charAt(0).toUpperCase() +
|
|
107
|
-
value.slice(1));
|
|
108
67
|
}
|
|
109
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":"
|
|
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,CA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 @@
|
|
|
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;
|