@jayfong/x-server 1.35.5 → 1.35.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/lib/_cjs/cli/templates/routes.ts +32 -0
- package/lib/_cjs/core/get_handler_url.js +12 -0
- package/lib/_cjs/index.js +8 -0
- package/lib/cli/templates/routes.ts +32 -0
- package/lib/core/get_handler_url.d.ts +2 -0
- package/lib/core/get_handler_url.js +6 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
|
@@ -6,6 +6,38 @@ const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
|
|
|
6
6
|
// @endindex
|
|
7
7
|
]
|
|
8
8
|
|
|
9
|
+
// https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
|
|
10
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
11
|
+
k: infer I,
|
|
12
|
+
) => void
|
|
13
|
+
? I
|
|
14
|
+
: never
|
|
15
|
+
type RouteMap = {
|
|
16
|
+
// @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `'${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}': typeof handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__,`)
|
|
17
|
+
// @endindex
|
|
18
|
+
}
|
|
19
|
+
export type HandlerMap = UnionToIntersection<
|
|
20
|
+
{
|
|
21
|
+
[K in keyof RouteMap]: {
|
|
22
|
+
[X in keyof RouteMap[K]]: {
|
|
23
|
+
[Y in `${K}${X & string}`]: RouteMap[K][X]
|
|
24
|
+
}
|
|
25
|
+
}[keyof RouteMap[K]]
|
|
26
|
+
}[keyof RouteMap]
|
|
27
|
+
>
|
|
28
|
+
export type HandlerPath = keyof HandlerMap
|
|
29
|
+
export type HandlerPayloadMap = {
|
|
30
|
+
[K in HandlerPath]: HandlerMap[K] extends Handler<infer X> ? X : {}
|
|
31
|
+
}
|
|
32
|
+
export type HandlerResultMap = {
|
|
33
|
+
[K in HandlerPath]: HandlerMap[K] extends Handler<any, infer X> ? X : {}
|
|
34
|
+
}
|
|
35
|
+
export type HandlerMethodMap = {
|
|
36
|
+
[K in HandlerPath]: HandlerMap[K] extends Handler<any, any, infer X>
|
|
37
|
+
? X
|
|
38
|
+
: never
|
|
39
|
+
}
|
|
40
|
+
|
|
9
41
|
export const routes: XServer.Route[] = basePathWithHandlers.reduce<
|
|
10
42
|
XServer.Route[]
|
|
11
43
|
>((res, item) => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.getHandlerUrl = getHandlerUrl;
|
|
5
|
+
|
|
6
|
+
var _vtils = require("vtils");
|
|
7
|
+
|
|
8
|
+
var _x = require("../x");
|
|
9
|
+
|
|
10
|
+
function getHandlerUrl(path, query) {
|
|
11
|
+
return `${_x.x.env.APP_URL.replace(/\/+$/, '')}${path}${query ? `?${(0, _vtils.createUrlQueryString)(query)}` : ''}`;
|
|
12
|
+
}
|
package/lib/_cjs/index.js
CHANGED
|
@@ -50,6 +50,14 @@ Object.keys(_define_task).forEach(function (key) {
|
|
|
50
50
|
exports[key] = _define_task[key];
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
var _get_handler_url = require("./core/get_handler_url");
|
|
54
|
+
|
|
55
|
+
Object.keys(_get_handler_url).forEach(function (key) {
|
|
56
|
+
if (key === "default" || key === "__esModule") return;
|
|
57
|
+
if (key in exports && exports[key] === _get_handler_url[key]) return;
|
|
58
|
+
exports[key] = _get_handler_url[key];
|
|
59
|
+
});
|
|
60
|
+
|
|
53
61
|
var _handler = require("./core/handler");
|
|
54
62
|
|
|
55
63
|
Object.keys(_handler).forEach(function (key) {
|
|
@@ -6,6 +6,38 @@ const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
|
|
|
6
6
|
// @endindex
|
|
7
7
|
]
|
|
8
8
|
|
|
9
|
+
// https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
|
|
10
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
11
|
+
k: infer I,
|
|
12
|
+
) => void
|
|
13
|
+
? I
|
|
14
|
+
: never
|
|
15
|
+
type RouteMap = {
|
|
16
|
+
// @index(['../../src/handlers/**/*.ts', '!**/_*'], (f, _) => `'${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}': typeof handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__,`)
|
|
17
|
+
// @endindex
|
|
18
|
+
}
|
|
19
|
+
export type HandlerMap = UnionToIntersection<
|
|
20
|
+
{
|
|
21
|
+
[K in keyof RouteMap]: {
|
|
22
|
+
[X in keyof RouteMap[K]]: {
|
|
23
|
+
[Y in `${K}${X & string}`]: RouteMap[K][X]
|
|
24
|
+
}
|
|
25
|
+
}[keyof RouteMap[K]]
|
|
26
|
+
}[keyof RouteMap]
|
|
27
|
+
>
|
|
28
|
+
export type HandlerPath = keyof HandlerMap
|
|
29
|
+
export type HandlerPayloadMap = {
|
|
30
|
+
[K in HandlerPath]: HandlerMap[K] extends Handler<infer X> ? X : {}
|
|
31
|
+
}
|
|
32
|
+
export type HandlerResultMap = {
|
|
33
|
+
[K in HandlerPath]: HandlerMap[K] extends Handler<any, infer X> ? X : {}
|
|
34
|
+
}
|
|
35
|
+
export type HandlerMethodMap = {
|
|
36
|
+
[K in HandlerPath]: HandlerMap[K] extends Handler<any, any, infer X>
|
|
37
|
+
? X
|
|
38
|
+
: never
|
|
39
|
+
}
|
|
40
|
+
|
|
9
41
|
export const routes: XServer.Route[] = basePathWithHandlers.reduce<
|
|
10
42
|
XServer.Route[]
|
|
11
43
|
>((res, item) => {
|
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './core/define_handler';
|
|
|
4
4
|
export * from './core/define_hook';
|
|
5
5
|
export * from './core/define_server';
|
|
6
6
|
export * from './core/define_task';
|
|
7
|
+
export * from './core/get_handler_url';
|
|
7
8
|
export * from './core/handler';
|
|
8
9
|
export * from './core/http_error';
|
|
9
10
|
export * from './core/http_header';
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./core/define_handler";
|
|
|
5
5
|
export * from "./core/define_hook";
|
|
6
6
|
export * from "./core/define_server";
|
|
7
7
|
export * from "./core/define_task";
|
|
8
|
+
export * from "./core/get_handler_url";
|
|
8
9
|
export * from "./core/handler";
|
|
9
10
|
export * from "./core/http_error";
|
|
10
11
|
export * from "./core/http_header";
|