gg-express 1.0.6 → 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.
@@ -57,5 +57,6 @@ export default class GGExpress {
57
57
  responseStructure: R;
58
58
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K>, res: MyResponse<R["dataType"], RS, KR>, next: NextFunction) => any>): Express.Express;
59
59
  generateStaticRouteFile(): void;
60
+ generateGGApi(filePathWithFileName: string): void;
60
61
  }
61
62
  export {};
package/dist/GGExpress.js CHANGED
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
7
8
  const myExpressRouteList = [];
8
9
  class GGExpress {
9
10
  constructor(app, outputPath) {
@@ -94,7 +95,8 @@ class GGExpress {
94
95
  delete : { ${genInterfaceString(deleteDelete)} },
95
96
  }`;
96
97
  for (let row of this.outputPath) {
97
- 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'));
98
100
  }
99
101
  // const serverFilePath = path.join(
100
102
  // appRootPath.toString(),
@@ -113,5 +115,79 @@ class GGExpress {
113
115
  // fs.writeFileSync(serverFilePath, content)
114
116
  // fs.writeFileSync(myAppFilePath, content)
115
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
+ }
116
192
  }
117
193
  exports.default = GGExpress;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-express",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "main": "dist/GGExpress.js",
6
6
  "scripts": {
package/src/GGApi.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { staticRouteInterface } from "./staticRouteInterface"
2
2
  import axios from "axios"
3
+
3
4
  export class GGApi {
4
5
  constructor() {}
5
6
 
package/src/GGExpress.ts CHANGED
@@ -3,6 +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
7
  type Unarray<T> = T extends (infer U)[] ? U : T;
7
8
  type AsConstArray<T extends readonly any[]> = [...T]
8
9
  type paramType =
@@ -278,7 +279,8 @@ export default class GGExpress {
278
279
  }`
279
280
 
280
281
  for (let row of this.outputPath) {
281
- fs.writeFileSync(row, content)
282
+ fs.writeFileSync(path.join(row,'staticRouteInterface.ts'), content)
283
+ this.generateGGApi(path.join(row,'apiConnector.ts'))
282
284
  }
283
285
 
284
286
  // const serverFilePath = path.join(
@@ -299,4 +301,78 @@ export default class GGExpress {
299
301
  // fs.writeFileSync(serverFilePath, content)
300
302
  // fs.writeFileSync(myAppFilePath, content)
301
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
+ }
302
378
  }