@jayfong/x-server 2.74.3 → 2.75.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.
@@ -59,6 +59,9 @@ class ApiGenerator {
59
59
  // 分类源文件路径
60
60
  const categorySourceFilePath = categorySourceFile.fileName;
61
61
 
62
+ // 忽略仅开发时生效的路由
63
+ if (/@dev[\/\.]/.test(categorySourceFilePath)) continue;
64
+
62
65
  // 分类 URL
63
66
  const categoryUrlMatch = categorySourceFilePath.match(this.categoryUrlRe);
64
67
  let categoryUrl = categoryUrlMatch[1] ?? categoryUrlMatch[2] ?? '';
@@ -127,6 +127,16 @@ class BuildUtil {
127
127
  loader: 'js'
128
128
  };
129
129
  });
130
+
131
+ // 支持仅开发时生效的路由
132
+ build.onLoad({
133
+ filter: /@dev[\/\.]/
134
+ }, async () => {
135
+ return {
136
+ contents: 'export {}',
137
+ loader: 'js'
138
+ };
139
+ });
130
140
  }
131
141
  },
132
142
  // @ts-ignore
@@ -1,68 +1,68 @@
1
- import * as handlers from './handlers'
2
- import { Handler, XServer } from '@jayfong/x-server'
1
+ import { Handler, XServer } from '@jayfong/x-server';
2
+ import * as handlers from './handlers';
3
3
 
4
4
  const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
5
- // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `['${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
5
+ // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `['${(f.path+'/').replace(/@dev/g, '').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
6
6
  // @endindex
7
- ]
7
+ ];
8
8
 
9
9
  // https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
10
10
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
11
11
  k: infer I,
12
12
  ) => void
13
13
  ? I
14
- : never
14
+ : never;
15
15
  type RouteMap = {
16
16
  // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `'${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}': typeof handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__,`)
17
17
  // @endindex
18
- }
18
+ };
19
19
  export type HandlerMap = UnionToIntersection<
20
20
  {
21
21
  [K in keyof RouteMap]: {
22
22
  [X in keyof RouteMap[K]]: {
23
- [Y in `${K}${X & string}`]: RouteMap[K][X]
24
- }
25
- }[keyof RouteMap[K]]
23
+ [Y in `${K}${X & string}`]: RouteMap[K][X];
24
+ };
25
+ }[keyof RouteMap[K]];
26
26
  }[keyof RouteMap]
27
- >
28
- export type HandlerPath = keyof HandlerMap
27
+ >;
28
+ export type HandlerPath = keyof HandlerMap;
29
29
  export type HandlerMetaMap = {
30
30
  [K in HandlerPath]: HandlerMap[K] extends Handler<infer X, infer Y, infer Z>
31
31
  ? {
32
- payload: X
33
- result: Y
34
- method: Z
32
+ payload: X;
33
+ result: Y;
34
+ method: Z;
35
35
  }
36
- : {}
37
- }
36
+ : {};
37
+ };
38
38
  export type HandlerPayloadMap = {
39
39
  // @ts-ignore
40
- [K in HandlerPath]: HandlerMetaMap[K]['payload']
41
- }
40
+ [K in HandlerPath]: HandlerMetaMap[K]['payload'];
41
+ };
42
42
  export type HandlerResultMap = {
43
43
  // @ts-ignore
44
- [K in HandlerPath]: HandlerMetaMap[K]['result']
45
- }
44
+ [K in HandlerPath]: HandlerMetaMap[K]['result'];
45
+ };
46
46
  export type HandlerMethodMap = {
47
47
  // @ts-ignore
48
- [K in HandlerPath]: HandlerMetaMap[K]['method']
49
- }
48
+ [K in HandlerPath]: HandlerMetaMap[K]['method'];
49
+ };
50
50
 
51
51
  export const routes: XServer.Route[] = basePathWithHandlers.reduce<
52
52
  XServer.Route[]
53
53
  >((res, item) => {
54
54
  const validHandlerNames = Object.keys(item[1]).filter(
55
55
  name => !name.startsWith('_') && name !== 'default',
56
- )
56
+ );
57
57
  for (const handlerName of validHandlerNames) {
58
- const path = item[1][handlerName].options.requestPath || handlerName
59
- const paths = Array.isArray(path) ? path : [path]
58
+ const path = item[1][handlerName].options.requestPath || handlerName;
59
+ const paths = Array.isArray(path) ? path : [path];
60
60
  for (const path of paths) {
61
61
  res.push({
62
62
  path: `${item[0]}${path}`,
63
63
  handler: item[1][handlerName],
64
- })
64
+ });
65
65
  }
66
66
  }
67
- return res
68
- }, [])
67
+ return res;
68
+ }, []);
@@ -54,6 +54,9 @@ export class ApiGenerator {
54
54
  // 分类源文件路径
55
55
  const categorySourceFilePath = categorySourceFile.fileName;
56
56
 
57
+ // 忽略仅开发时生效的路由
58
+ if (/@dev[\/\.]/.test(categorySourceFilePath)) continue;
59
+
57
60
  // 分类 URL
58
61
  const categoryUrlMatch = categorySourceFilePath.match(this.categoryUrlRe);
59
62
  let categoryUrl = categoryUrlMatch[1] ?? categoryUrlMatch[2] ?? '';
@@ -121,6 +121,16 @@ export class BuildUtil {
121
121
  loader: 'js'
122
122
  };
123
123
  });
124
+
125
+ // 支持仅开发时生效的路由
126
+ build.onLoad({
127
+ filter: /@dev[\/\.]/
128
+ }, async () => {
129
+ return {
130
+ contents: 'export {}',
131
+ loader: 'js'
132
+ };
133
+ });
124
134
  }
125
135
  },
126
136
  // @ts-ignore
@@ -1,68 +1,68 @@
1
- import * as handlers from './handlers'
2
- import { Handler, XServer } from '@jayfong/x-server'
1
+ import { Handler, XServer } from '@jayfong/x-server';
2
+ import * as handlers from './handlers';
3
3
 
4
4
  const basePathWithHandlers: Array<[string, Record<string, Handler>]> = [
5
- // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `['${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
5
+ // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `['${(f.path+'/').replace(/@dev/g, '').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}', handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__ as any],`)
6
6
  // @endindex
7
- ]
7
+ ];
8
8
 
9
9
  // https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
10
10
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
11
11
  k: infer I,
12
12
  ) => void
13
13
  ? I
14
- : never
14
+ : never;
15
15
  type RouteMap = {
16
16
  // @index(['../../src/handlers/**/*.ts', '!**/_*', '!**/_*/**', '!**/*.test.*'], (f, _) => `'${(f.path+'/').replace('../../src/handlers/', '/').replace(/\/index\/$/, '/').split('/').map(v => _.snake(v)).join('/')}': typeof handlers.__${_.pascal(f.path.replace('/src/handlers/', ''))}__,`)
17
17
  // @endindex
18
- }
18
+ };
19
19
  export type HandlerMap = UnionToIntersection<
20
20
  {
21
21
  [K in keyof RouteMap]: {
22
22
  [X in keyof RouteMap[K]]: {
23
- [Y in `${K}${X & string}`]: RouteMap[K][X]
24
- }
25
- }[keyof RouteMap[K]]
23
+ [Y in `${K}${X & string}`]: RouteMap[K][X];
24
+ };
25
+ }[keyof RouteMap[K]];
26
26
  }[keyof RouteMap]
27
- >
28
- export type HandlerPath = keyof HandlerMap
27
+ >;
28
+ export type HandlerPath = keyof HandlerMap;
29
29
  export type HandlerMetaMap = {
30
30
  [K in HandlerPath]: HandlerMap[K] extends Handler<infer X, infer Y, infer Z>
31
31
  ? {
32
- payload: X
33
- result: Y
34
- method: Z
32
+ payload: X;
33
+ result: Y;
34
+ method: Z;
35
35
  }
36
- : {}
37
- }
36
+ : {};
37
+ };
38
38
  export type HandlerPayloadMap = {
39
39
  // @ts-ignore
40
- [K in HandlerPath]: HandlerMetaMap[K]['payload']
41
- }
40
+ [K in HandlerPath]: HandlerMetaMap[K]['payload'];
41
+ };
42
42
  export type HandlerResultMap = {
43
43
  // @ts-ignore
44
- [K in HandlerPath]: HandlerMetaMap[K]['result']
45
- }
44
+ [K in HandlerPath]: HandlerMetaMap[K]['result'];
45
+ };
46
46
  export type HandlerMethodMap = {
47
47
  // @ts-ignore
48
- [K in HandlerPath]: HandlerMetaMap[K]['method']
49
- }
48
+ [K in HandlerPath]: HandlerMetaMap[K]['method'];
49
+ };
50
50
 
51
51
  export const routes: XServer.Route[] = basePathWithHandlers.reduce<
52
52
  XServer.Route[]
53
53
  >((res, item) => {
54
54
  const validHandlerNames = Object.keys(item[1]).filter(
55
55
  name => !name.startsWith('_') && name !== 'default',
56
- )
56
+ );
57
57
  for (const handlerName of validHandlerNames) {
58
- const path = item[1][handlerName].options.requestPath || handlerName
59
- const paths = Array.isArray(path) ? path : [path]
58
+ const path = item[1][handlerName].options.requestPath || handlerName;
59
+ const paths = Array.isArray(path) ? path : [path];
60
60
  for (const path of paths) {
61
61
  res.push({
62
62
  path: `${item[0]}${path}`,
63
63
  handler: item[1][handlerName],
64
- })
64
+ });
65
65
  }
66
66
  }
67
- return res
68
- }, [])
67
+ return res;
68
+ }, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.74.3",
3
+ "version": "2.75.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",