gg-express 1.0.7 → 1.0.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/dist/GGExpress.d.ts +2 -1
- package/dist/GGExpress.js +77 -4
- package/package.json +1 -1
- package/src/GGExpress.ts +77 -2
package/dist/GGExpress.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
2
|
import Express from "express-serve-static-core";
|
|
3
|
-
export { GGApi } from "./GGApi";
|
|
4
3
|
type Unarray<T> = T extends (infer U)[] ? U : T;
|
|
5
4
|
type AsConstArray<T extends readonly any[]> = [...T];
|
|
6
5
|
type paramType = "number" | "string" | AsConstArray<Array<string>> | AsConstArray<Array<number>>;
|
|
@@ -58,4 +57,6 @@ export default class GGExpress {
|
|
|
58
57
|
responseStructure: R;
|
|
59
58
|
}, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K>, res: MyResponse<R["dataType"], RS, KR>, next: NextFunction) => any>): Express.Express;
|
|
60
59
|
generateStaticRouteFile(): void;
|
|
60
|
+
generateGGApi(filePathWithFileName: string): void;
|
|
61
61
|
}
|
|
62
|
+
export {};
|
package/dist/GGExpress.js
CHANGED
|
@@ -3,10 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GGApi = void 0;
|
|
7
6
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
|
|
9
|
-
Object.defineProperty(exports, "GGApi", { enumerable: true, get: function () { return GGApi_1.GGApi; } });
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
10
8
|
const myExpressRouteList = [];
|
|
11
9
|
class GGExpress {
|
|
12
10
|
constructor(app, outputPath) {
|
|
@@ -97,7 +95,8 @@ class GGExpress {
|
|
|
97
95
|
delete : { ${genInterfaceString(deleteDelete)} },
|
|
98
96
|
}`;
|
|
99
97
|
for (let row of this.outputPath) {
|
|
100
|
-
fs_1.default.writeFileSync(row, content);
|
|
98
|
+
fs_1.default.writeFileSync(path_1.default.join(row, 'staticRouteInterface.ts'), content);
|
|
99
|
+
this.generateGGApi(path_1.default.join(row, 'apiConnector.ts'));
|
|
101
100
|
}
|
|
102
101
|
// const serverFilePath = path.join(
|
|
103
102
|
// appRootPath.toString(),
|
|
@@ -116,5 +115,79 @@ class GGExpress {
|
|
|
116
115
|
// fs.writeFileSync(serverFilePath, content)
|
|
117
116
|
// fs.writeFileSync(myAppFilePath, content)
|
|
118
117
|
}
|
|
118
|
+
generateGGApi(filePathWithFileName) {
|
|
119
|
+
let code = `
|
|
120
|
+
import { staticRouteInterface } from "./staticRouteInterface"
|
|
121
|
+
import axios from "axios"
|
|
122
|
+
|
|
123
|
+
export class GGApi {
|
|
124
|
+
constructor() {}
|
|
125
|
+
|
|
126
|
+
get<T extends keyof staticRouteInterface["get"]>(
|
|
127
|
+
url: T,
|
|
128
|
+
requireParams: staticRouteInterface["get"][T]["requireParams"]
|
|
129
|
+
): Promise<staticRouteInterface["get"][T]["responseStructure"]> {
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
axios
|
|
132
|
+
.get(url, { params: requireParams })
|
|
133
|
+
.then((response) => {
|
|
134
|
+
resolve(response.data)
|
|
135
|
+
})
|
|
136
|
+
.catch((error) => {
|
|
137
|
+
reject(error)
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
post<T extends keyof staticRouteInterface["post"]>(
|
|
143
|
+
url: T,
|
|
144
|
+
requireParams: staticRouteInterface["post"][T]["requireParams"]
|
|
145
|
+
): Promise<staticRouteInterface["post"][T]["responseStructure"]> {
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
axios
|
|
148
|
+
.post(url, requireParams)
|
|
149
|
+
.then((response) => {
|
|
150
|
+
resolve(response.data)
|
|
151
|
+
})
|
|
152
|
+
.catch((error) => {
|
|
153
|
+
reject(error)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
}
|
|
157
|
+
put<T extends keyof staticRouteInterface["put"]>(
|
|
158
|
+
url: T,
|
|
159
|
+
requireParams: staticRouteInterface["put"][T]["requireParams"]
|
|
160
|
+
): Promise<staticRouteInterface["put"][T]["responseStructure"]> {
|
|
161
|
+
return new Promise((resolve, reject) => {
|
|
162
|
+
axios
|
|
163
|
+
.put(url, requireParams)
|
|
164
|
+
.then((response) => {
|
|
165
|
+
resolve(response.data)
|
|
166
|
+
})
|
|
167
|
+
.catch((error) => {
|
|
168
|
+
reject(error)
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
delete<T extends keyof staticRouteInterface["delete"]>(
|
|
173
|
+
url: T,
|
|
174
|
+
requireParams: staticRouteInterface["delete"][T]["requireParams"]
|
|
175
|
+
): Promise<staticRouteInterface["delete"][T]["responseStructure"]> {
|
|
176
|
+
return new Promise((resolve, reject) => {
|
|
177
|
+
axios
|
|
178
|
+
.delete(url, requireParams)
|
|
179
|
+
.then((response) => {
|
|
180
|
+
resolve(response.data)
|
|
181
|
+
})
|
|
182
|
+
.catch((error) => {
|
|
183
|
+
reject(error)
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
`;
|
|
190
|
+
fs_1.default.writeFileSync(filePathWithFileName, code);
|
|
191
|
+
}
|
|
119
192
|
}
|
|
120
193
|
exports.default = GGExpress;
|
package/package.json
CHANGED
package/src/GGExpress.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { NextFunction, Request, Response } from "express"
|
|
|
3
3
|
import Express from "express-serve-static-core"
|
|
4
4
|
import fs from "fs"
|
|
5
5
|
import path from "path"
|
|
6
|
-
export { GGApi } from "./GGApi"
|
|
6
|
+
// export { GGApi } from "./GGApi"
|
|
7
7
|
type Unarray<T> = T extends (infer U)[] ? U : T;
|
|
8
8
|
type AsConstArray<T extends readonly any[]> = [...T]
|
|
9
9
|
type paramType =
|
|
@@ -279,7 +279,8 @@ export default class GGExpress {
|
|
|
279
279
|
}`
|
|
280
280
|
|
|
281
281
|
for (let row of this.outputPath) {
|
|
282
|
-
fs.writeFileSync(row, content)
|
|
282
|
+
fs.writeFileSync(path.join(row,'staticRouteInterface.ts'), content)
|
|
283
|
+
this.generateGGApi(path.join(row,'apiConnector.ts'))
|
|
283
284
|
}
|
|
284
285
|
|
|
285
286
|
// const serverFilePath = path.join(
|
|
@@ -300,4 +301,78 @@ export default class GGExpress {
|
|
|
300
301
|
// fs.writeFileSync(serverFilePath, content)
|
|
301
302
|
// fs.writeFileSync(myAppFilePath, content)
|
|
302
303
|
}
|
|
304
|
+
generateGGApi(filePathWithFileName : string) {
|
|
305
|
+
let code = `
|
|
306
|
+
import { staticRouteInterface } from "./staticRouteInterface"
|
|
307
|
+
import axios from "axios"
|
|
308
|
+
|
|
309
|
+
export class GGApi {
|
|
310
|
+
constructor() {}
|
|
311
|
+
|
|
312
|
+
get<T extends keyof staticRouteInterface["get"]>(
|
|
313
|
+
url: T,
|
|
314
|
+
requireParams: staticRouteInterface["get"][T]["requireParams"]
|
|
315
|
+
): Promise<staticRouteInterface["get"][T]["responseStructure"]> {
|
|
316
|
+
return new Promise((resolve, reject) => {
|
|
317
|
+
axios
|
|
318
|
+
.get(url, { params: requireParams })
|
|
319
|
+
.then((response) => {
|
|
320
|
+
resolve(response.data)
|
|
321
|
+
})
|
|
322
|
+
.catch((error) => {
|
|
323
|
+
reject(error)
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
post<T extends keyof staticRouteInterface["post"]>(
|
|
329
|
+
url: T,
|
|
330
|
+
requireParams: staticRouteInterface["post"][T]["requireParams"]
|
|
331
|
+
): Promise<staticRouteInterface["post"][T]["responseStructure"]> {
|
|
332
|
+
return new Promise((resolve, reject) => {
|
|
333
|
+
axios
|
|
334
|
+
.post(url, requireParams)
|
|
335
|
+
.then((response) => {
|
|
336
|
+
resolve(response.data)
|
|
337
|
+
})
|
|
338
|
+
.catch((error) => {
|
|
339
|
+
reject(error)
|
|
340
|
+
})
|
|
341
|
+
})
|
|
342
|
+
}
|
|
343
|
+
put<T extends keyof staticRouteInterface["put"]>(
|
|
344
|
+
url: T,
|
|
345
|
+
requireParams: staticRouteInterface["put"][T]["requireParams"]
|
|
346
|
+
): Promise<staticRouteInterface["put"][T]["responseStructure"]> {
|
|
347
|
+
return new Promise((resolve, reject) => {
|
|
348
|
+
axios
|
|
349
|
+
.put(url, requireParams)
|
|
350
|
+
.then((response) => {
|
|
351
|
+
resolve(response.data)
|
|
352
|
+
})
|
|
353
|
+
.catch((error) => {
|
|
354
|
+
reject(error)
|
|
355
|
+
})
|
|
356
|
+
})
|
|
357
|
+
}
|
|
358
|
+
delete<T extends keyof staticRouteInterface["delete"]>(
|
|
359
|
+
url: T,
|
|
360
|
+
requireParams: staticRouteInterface["delete"][T]["requireParams"]
|
|
361
|
+
): Promise<staticRouteInterface["delete"][T]["responseStructure"]> {
|
|
362
|
+
return new Promise((resolve, reject) => {
|
|
363
|
+
axios
|
|
364
|
+
.delete(url, requireParams)
|
|
365
|
+
.then((response) => {
|
|
366
|
+
resolve(response.data)
|
|
367
|
+
})
|
|
368
|
+
.catch((error) => {
|
|
369
|
+
reject(error)
|
|
370
|
+
})
|
|
371
|
+
})
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
`
|
|
376
|
+
fs.writeFileSync(filePathWithFileName,code)
|
|
377
|
+
}
|
|
303
378
|
}
|