@creator.co/wapi 1.5.9-alpha.4 → 1.5.9-alpha.6
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/package.json +1 -1
- package/dist/src/Server/RouteResolver.d.ts +2 -2
- package/dist/src/Server/RouteResolver.js.map +1 -1
- package/dist/src/Server/Router.d.ts +2 -1
- package/dist/src/Server/Router.js.map +1 -1
- package/dist/src/Server/lib/Server.js +0 -1
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/package.json +1 -1
- package/src/Server/RouteResolver.ts +5 -5
- package/src/Server/Router.ts +3 -1
- package/src/Server/lib/Server.ts +8 -5
- package/tests/Server/lib/ContainerServer.test.ts +10 -10
package/dist/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyRoute, RouterConfig } from './Router';
|
|
2
2
|
import { HttpMethod } from '../API/Request';
|
|
3
3
|
/**
|
|
4
4
|
* A class that resolves routes based on the provided configuration.
|
|
@@ -24,7 +24,7 @@ export default class RouteResolver {
|
|
|
24
24
|
* @param {string} path - The path of the request.
|
|
25
25
|
* @returns {Route | undefined} - The resolved route or undefined if no route is found.
|
|
26
26
|
*/
|
|
27
|
-
resolveRoute(method: HttpMethod, path: string):
|
|
27
|
+
resolveRoute(method: HttpMethod, path: string): AnyRoute | undefined;
|
|
28
28
|
/**
|
|
29
29
|
* Builds the routes for the router based on the given configuration.
|
|
30
30
|
* @param {RouterConfig} config - The router configuration object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouteResolver.js","sourceRoot":"","sources":["../../../src/Server/RouteResolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAGA;;GAEG;AACH;IAkBE;;;OAGG;IACH;QACE,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;IAChB,CAAC;IAED;;;;;;OAMG;IACI,yBAAQ,GAAf,UAAgB,
|
|
1
|
+
{"version":3,"file":"RouteResolver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CAAC,AAzCD,IAyCC"}
|
|
@@ -56,6 +56,7 @@ export interface Route<InputType = never, OutputType = never, PathParamsType = S
|
|
|
56
56
|
*/
|
|
57
57
|
querySchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>;
|
|
58
58
|
}
|
|
59
|
+
export type AnyRoute = Route<any, any>;
|
|
59
60
|
/**
|
|
60
61
|
* Represents the configuration options for a router.
|
|
61
62
|
* @typedef {TransactionConfig & {
|
|
@@ -78,7 +79,7 @@ export type RouterConfig = TransactionConfig & {
|
|
|
78
79
|
* An array of route objects representing the available routes in the application.
|
|
79
80
|
* @type {Route[]}
|
|
80
81
|
*/
|
|
81
|
-
routes:
|
|
82
|
+
routes: AnyRoute[];
|
|
82
83
|
/**
|
|
83
84
|
* The port number for the server to listen on.
|
|
84
85
|
* @type {number | undefined}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAKA,yDAAmD;AACnD,uCAAiC;AAQjC,uCAAiC;
|
|
1
|
+
{"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAKA,yDAAmD;AACnD,uCAAiC;AAQjC,uCAAiC;AA4HjC;;GAEG;AACH;IAUE;;;;OAIG;IACH,gBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,yBAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,gBAAM,CAAC,MAAM,CAAC,CAAA;IACrF,CAAC;IAED;;;OAGG;IACI,0BAAS,GAAhB;QACE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IAChC,CAAC;IAED;;;OAGG;IACK,4BAAW,GAAnB;QACE,OAAO,eAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;IACH,aAAC;AAAD,CAAC,AAnCD,IAmCC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../../../src/Server/lib/Server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA6C;AAG7C,+
|
|
1
|
+
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../../../src/Server/lib/Server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA6C;AAG7C,+CAAgE;AAChE,2DAAoE;AACpE,wDAAkD;AAElD,kDAA4C;AAE5C;;GAEG;AACH;IAcE;;;;OAIG;IACH,gBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,aAAa,GAAG,IAAI,uBAAa,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC;IAED;;;OAGG;IACI,0BAAS,GAAhB;QACE,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC9C,CAAC;IAED;;;;;OAKG;IACU,sCAAqB,GAAlC,UAAmC,KAA2B,EAAE,OAAgB;;;;;;oBAC9E,mBAAmB;oBACnB,qBAAM,IAAI,qBAAW,CACnB,KAAK,EACL,OAAO,EACP,IAAI,CAAC,MAAM,CACZ,CAAC,OAAO,CAAC,UAAM,WAAW;;;;;wCACnB,OAAO,GAAG,WAAW,CAAC,OAAO,CAAA;wCAC7B,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;6CACjF,KAAK,EAAL,wBAAK;wCACP,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,wBAAwB,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;wCAC5D,iBAAiB;wCACjB,IAAI,KAAK,CA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AAC,SAAS,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACvD,IAAI,MAAM;YAAE,GAAG,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAClD,CAAC;IACH,aAAC;AAAD,CAAC,AA5FD,IA4FC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnyRoute, RouterConfig } from './Router'
|
|
2
2
|
import { HttpMethod } from '../API/Request'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -9,7 +9,7 @@ class Routes {
|
|
|
9
9
|
* Represents the current route.
|
|
10
10
|
* @type {Route | undefined}
|
|
11
11
|
*/
|
|
12
|
-
private current?:
|
|
12
|
+
private current?: AnyRoute
|
|
13
13
|
/**
|
|
14
14
|
* Optional private variable that represents a collection of routes.
|
|
15
15
|
* @type {Routes | undefined}
|
|
@@ -37,7 +37,7 @@ class Routes {
|
|
|
37
37
|
* @returns None
|
|
38
38
|
* @throws {Error} If a duplicate route is detected.
|
|
39
39
|
*/
|
|
40
|
-
public addRoute(route:
|
|
40
|
+
public addRoute(route: AnyRoute, parts: string[]): void {
|
|
41
41
|
const first = parts.shift()
|
|
42
42
|
if (first) {
|
|
43
43
|
if (first.startsWith(':')) {
|
|
@@ -59,7 +59,7 @@ class Routes {
|
|
|
59
59
|
* @param {string[]} parts - An array of route parts.
|
|
60
60
|
* @returns {Route} The resolved route.
|
|
61
61
|
*/
|
|
62
|
-
public resolveRoute(parts: string[]):
|
|
62
|
+
public resolveRoute(parts: string[]): AnyRoute | undefined {
|
|
63
63
|
const first = parts.shift()
|
|
64
64
|
if (first) {
|
|
65
65
|
if (first in this.next) {
|
|
@@ -99,7 +99,7 @@ export default class RouteResolver {
|
|
|
99
99
|
* @param {string} path - The path of the request.
|
|
100
100
|
* @returns {Route | undefined} - The resolved route or undefined if no route is found.
|
|
101
101
|
*/
|
|
102
|
-
public resolveRoute(method: HttpMethod, path: string):
|
|
102
|
+
public resolveRoute(method: HttpMethod, path: string): AnyRoute | undefined {
|
|
103
103
|
const parts = path.split('/').filter(p => p.length)
|
|
104
104
|
return this.routes[method]?.resolveRoute(parts)
|
|
105
105
|
}
|
package/src/Server/Router.ts
CHANGED
|
@@ -82,6 +82,8 @@ export interface Route<
|
|
|
82
82
|
querySchema?: z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
export type AnyRoute = Route<any, any>
|
|
86
|
+
|
|
85
87
|
/**
|
|
86
88
|
* Represents the configuration options for a router.
|
|
87
89
|
* @typedef {TransactionConfig & {
|
|
@@ -104,7 +106,7 @@ export type RouterConfig = TransactionConfig & {
|
|
|
104
106
|
* An array of route objects representing the available routes in the application.
|
|
105
107
|
* @type {Route[]}
|
|
106
108
|
*/
|
|
107
|
-
routes:
|
|
109
|
+
routes: AnyRoute[]
|
|
108
110
|
/**
|
|
109
111
|
* The port number for the server to listen on.
|
|
110
112
|
* @type {number | undefined}
|
package/src/Server/lib/Server.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { APIGatewayProxyEvent, Context } from 'aws-lambda'
|
|
|
2
2
|
import { pathToRegexp } from 'path-to-regexp'
|
|
3
3
|
|
|
4
4
|
import Request from '../../API/Request'
|
|
5
|
-
import Response from '../../API/Response'
|
|
6
|
-
import Transaction from '../../BaseEvent/Transaction'
|
|
5
|
+
import Response, { ResponseErrorType } from '../../API/Response'
|
|
6
|
+
import Transaction, { StringMap } from '../../BaseEvent/Transaction'
|
|
7
7
|
import Validator from '../../Validation/Validator'
|
|
8
8
|
import { RouterConfig } from '../Router'
|
|
9
9
|
import RouteResolver from '../RouteResolver'
|
|
@@ -51,7 +51,11 @@ export default class Server {
|
|
|
51
51
|
*/
|
|
52
52
|
public async handleServerlessEvent(event: APIGatewayProxyEvent, context: Context) {
|
|
53
53
|
// init transaction
|
|
54
|
-
await new Transaction
|
|
54
|
+
await new Transaction<never, ResponseErrorType, never, StringMap, StringMap>(
|
|
55
|
+
event,
|
|
56
|
+
context,
|
|
57
|
+
this.config
|
|
58
|
+
).execute(async transaction => {
|
|
55
59
|
const request = transaction.request
|
|
56
60
|
const route = this.routeResolver.resolveRoute(request.getMethod(), request.getPath())
|
|
57
61
|
if (route) {
|
|
@@ -80,8 +84,7 @@ export default class Server {
|
|
|
80
84
|
}
|
|
81
85
|
|
|
82
86
|
// Continue to route handler
|
|
83
|
-
|
|
84
|
-
return await route.handler(transaction as any)
|
|
87
|
+
return await route.handler(transaction)
|
|
85
88
|
}
|
|
86
89
|
//No route found :/
|
|
87
90
|
return new Response(404, { err: 'Route not found!' })
|
|
@@ -70,7 +70,7 @@ describe('Container server routing', () => {
|
|
|
70
70
|
handler: async () => {
|
|
71
71
|
return Response.SimpleResponse({ name: 'abc' })
|
|
72
72
|
},
|
|
73
|
-
},
|
|
73
|
+
} as any,
|
|
74
74
|
],
|
|
75
75
|
})
|
|
76
76
|
await server.start()
|
|
@@ -198,7 +198,7 @@ describe('Container server validation (body)', () => {
|
|
|
198
198
|
handler: async () => {
|
|
199
199
|
return Response.SimpleResponse({ name: 'abc' })
|
|
200
200
|
},
|
|
201
|
-
},
|
|
201
|
+
} as any,
|
|
202
202
|
],
|
|
203
203
|
})
|
|
204
204
|
await server.start()
|
|
@@ -221,7 +221,7 @@ describe('Container server validation (body)', () => {
|
|
|
221
221
|
handler: async () => {
|
|
222
222
|
return Response.SimpleResponse({ name: 'abc' })
|
|
223
223
|
},
|
|
224
|
-
},
|
|
224
|
+
} as any,
|
|
225
225
|
],
|
|
226
226
|
})
|
|
227
227
|
await server.start()
|
|
@@ -245,7 +245,7 @@ describe('Container server validation (body)', () => {
|
|
|
245
245
|
handler: async () => {
|
|
246
246
|
return Response.SimpleResponse({ name: 'abc' })
|
|
247
247
|
},
|
|
248
|
-
},
|
|
248
|
+
} as any,
|
|
249
249
|
],
|
|
250
250
|
})
|
|
251
251
|
await server.start()
|
|
@@ -269,7 +269,7 @@ describe('Container server validation (body)', () => {
|
|
|
269
269
|
handler: async () => {
|
|
270
270
|
return Response.SimpleResponse({ name: 'abc' })
|
|
271
271
|
},
|
|
272
|
-
},
|
|
272
|
+
} as any,
|
|
273
273
|
],
|
|
274
274
|
})
|
|
275
275
|
await server.start()
|
|
@@ -293,7 +293,7 @@ describe('Container server validation (body)', () => {
|
|
|
293
293
|
handler: async () => {
|
|
294
294
|
return Response.SimpleResponse({ name: 'abc' })
|
|
295
295
|
},
|
|
296
|
-
},
|
|
296
|
+
} as any,
|
|
297
297
|
],
|
|
298
298
|
})
|
|
299
299
|
await server.start()
|
|
@@ -317,7 +317,7 @@ describe('Container server validation (body)', () => {
|
|
|
317
317
|
handler: async () => {
|
|
318
318
|
return Response.SimpleResponse({ name: 'abc' })
|
|
319
319
|
},
|
|
320
|
-
},
|
|
320
|
+
} as any,
|
|
321
321
|
],
|
|
322
322
|
})
|
|
323
323
|
await server.start()
|
|
@@ -358,7 +358,7 @@ describe('Container server validation (query)', () => {
|
|
|
358
358
|
handler: async () => {
|
|
359
359
|
return Response.SimpleResponse({ name: 'abc' })
|
|
360
360
|
},
|
|
361
|
-
},
|
|
361
|
+
} as any,
|
|
362
362
|
],
|
|
363
363
|
})
|
|
364
364
|
await server.start()
|
|
@@ -444,7 +444,7 @@ describe('Container server validation (path)', () => {
|
|
|
444
444
|
handler: async () => {
|
|
445
445
|
return Response.SimpleResponse({ name: 'abc' })
|
|
446
446
|
},
|
|
447
|
-
},
|
|
447
|
+
} as any,
|
|
448
448
|
],
|
|
449
449
|
})
|
|
450
450
|
await server.start()
|
|
@@ -507,7 +507,7 @@ describe('Container server raw body', () => {
|
|
|
507
507
|
raw = t.request.getBody(true)
|
|
508
508
|
return Response.SimpleResponse(null)
|
|
509
509
|
},
|
|
510
|
-
},
|
|
510
|
+
} as any,
|
|
511
511
|
],
|
|
512
512
|
})
|
|
513
513
|
await server.start()
|