@modern-js/bff-core 2.58.0 → 2.58.2
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/cjs/client/generateClient.js +1 -1
- package/dist/cjs/operators/http.js +1 -1
- package/dist/cjs/router/index.js +8 -8
- package/dist/cjs/router/utils.js +3 -3
- package/dist/esm/client/generateClient.js +1 -1
- package/dist/esm/router/index.js +8 -8
- package/dist/esm/router/utils.js +4 -4
- package/dist/types/client/generateClient.d.ts +1 -1
- package/dist/types/operators/http.d.ts +1 -1
- package/dist/types/router/index.d.ts +3 -3
- package/dist/types/router/types.d.ts +1 -1
- package/dist/types/router/utils.d.ts +2 -2
- package/dist/types/types.d.ts +1 -1
- package/dist/types/utils/debug.d.ts +1 -1
- package/package.json +8 -8
|
@@ -54,7 +54,7 @@ const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix,
|
|
|
54
54
|
prefix,
|
|
55
55
|
httpMethodDecider
|
|
56
56
|
});
|
|
57
|
-
const handlerInfos = apiRouter.getSingleModuleHandlers(resourcePath);
|
|
57
|
+
const handlerInfos = await apiRouter.getSingleModuleHandlers(resourcePath);
|
|
58
58
|
if (!handlerInfos) {
|
|
59
59
|
return (0, import_result.Err)(`generate client error: Cannot require module ${resourcePath}`);
|
|
60
60
|
}
|
|
@@ -53,7 +53,7 @@ const validateInput = async (schema, input) => {
|
|
|
53
53
|
try {
|
|
54
54
|
return await schema.parseAsync(input);
|
|
55
55
|
} catch (error) {
|
|
56
|
-
const { z: zod } = await
|
|
56
|
+
const { z: zod } = await import("zod");
|
|
57
57
|
if (error instanceof zod.ZodError) {
|
|
58
58
|
throw new import_http.ValidationError(400, error.message);
|
|
59
59
|
}
|
package/dist/cjs/router/index.js
CHANGED
|
@@ -57,8 +57,8 @@ class ApiRouter {
|
|
|
57
57
|
}
|
|
58
58
|
return false;
|
|
59
59
|
}
|
|
60
|
-
getSingleModuleHandlers(filename) {
|
|
61
|
-
const moduleInfo = this.getModuleInfo(filename);
|
|
60
|
+
async getSingleModuleHandlers(filename) {
|
|
61
|
+
const moduleInfo = await this.getModuleInfo(filename);
|
|
62
62
|
if (moduleInfo) {
|
|
63
63
|
return this.getModuleHandlerInfos(moduleInfo);
|
|
64
64
|
}
|
|
@@ -167,9 +167,9 @@ class ApiRouter {
|
|
|
167
167
|
}
|
|
168
168
|
return this.loadApiFiles();
|
|
169
169
|
}
|
|
170
|
-
getApiHandlers() {
|
|
170
|
+
async getApiHandlers() {
|
|
171
171
|
const filenames = this.getApiFiles();
|
|
172
|
-
const moduleInfos = this.getModuleInfos(filenames);
|
|
172
|
+
const moduleInfos = await this.getModuleInfos(filenames);
|
|
173
173
|
const apiHandlers = this.getHandlerInfos(moduleInfos);
|
|
174
174
|
(0, import_utils2.debug)("apiHandlers", apiHandlers.length, apiHandlers);
|
|
175
175
|
return apiHandlers;
|
|
@@ -189,12 +189,12 @@ class ApiRouter {
|
|
|
189
189
|
throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
getModuleInfos(filenames) {
|
|
193
|
-
return filenames.map((filename) => this.getModuleInfo(filename)).filter((moduleInfo) => Boolean(moduleInfo));
|
|
192
|
+
async getModuleInfos(filenames) {
|
|
193
|
+
return Promise.all(filenames.map((filename) => this.getModuleInfo(filename)).filter((moduleInfo) => Boolean(moduleInfo)));
|
|
194
194
|
}
|
|
195
|
-
getModuleInfo(filename) {
|
|
195
|
+
async getModuleInfo(filename) {
|
|
196
196
|
try {
|
|
197
|
-
const module2 = (0, import_utils3.requireHandlerModule)(filename);
|
|
197
|
+
const module2 = await (0, import_utils3.requireHandlerModule)(filename);
|
|
198
198
|
return {
|
|
199
199
|
filename,
|
|
200
200
|
module: module2
|
package/dist/cjs/router/utils.js
CHANGED
|
@@ -69,9 +69,9 @@ const clearRouteName = (routeName) => {
|
|
|
69
69
|
};
|
|
70
70
|
const isHandler = (input) => input && typeof input === "function";
|
|
71
71
|
const isFunction = (input) => input && {}.toString.call(input) === "[object Function]";
|
|
72
|
-
const requireHandlerModule = (modulePath) => {
|
|
73
|
-
const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual :
|
|
74
|
-
const module2 = originRequire(modulePath);
|
|
72
|
+
const requireHandlerModule = async (modulePath) => {
|
|
73
|
+
const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual : import_utils.compatibleRequire;
|
|
74
|
+
const module2 = await originRequire(modulePath, false);
|
|
75
75
|
if (isFunction(module2)) {
|
|
76
76
|
return {
|
|
77
77
|
default: module2
|
|
@@ -20,7 +20,7 @@ const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix,
|
|
|
20
20
|
prefix,
|
|
21
21
|
httpMethodDecider
|
|
22
22
|
});
|
|
23
|
-
const handlerInfos = apiRouter.getSingleModuleHandlers(resourcePath);
|
|
23
|
+
const handlerInfos = await apiRouter.getSingleModuleHandlers(resourcePath);
|
|
24
24
|
if (!handlerInfos) {
|
|
25
25
|
return Err(`generate client error: Cannot require module ${resourcePath}`);
|
|
26
26
|
}
|
package/dist/esm/router/index.js
CHANGED
|
@@ -23,8 +23,8 @@ class ApiRouter {
|
|
|
23
23
|
}
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
|
-
getSingleModuleHandlers(filename) {
|
|
27
|
-
const moduleInfo = this.getModuleInfo(filename);
|
|
26
|
+
async getSingleModuleHandlers(filename) {
|
|
27
|
+
const moduleInfo = await this.getModuleInfo(filename);
|
|
28
28
|
if (moduleInfo) {
|
|
29
29
|
return this.getModuleHandlerInfos(moduleInfo);
|
|
30
30
|
}
|
|
@@ -133,9 +133,9 @@ class ApiRouter {
|
|
|
133
133
|
}
|
|
134
134
|
return this.loadApiFiles();
|
|
135
135
|
}
|
|
136
|
-
getApiHandlers() {
|
|
136
|
+
async getApiHandlers() {
|
|
137
137
|
const filenames = this.getApiFiles();
|
|
138
|
-
const moduleInfos = this.getModuleInfos(filenames);
|
|
138
|
+
const moduleInfos = await this.getModuleInfos(filenames);
|
|
139
139
|
const apiHandlers = this.getHandlerInfos(moduleInfos);
|
|
140
140
|
debug("apiHandlers", apiHandlers.length, apiHandlers);
|
|
141
141
|
return apiHandlers;
|
|
@@ -155,12 +155,12 @@ class ApiRouter {
|
|
|
155
155
|
throw new Error(`The ${paramsName} ${filename} is not a abolute path`);
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
getModuleInfos(filenames) {
|
|
159
|
-
return filenames.map((filename) => this.getModuleInfo(filename)).filter((moduleInfo) => Boolean(moduleInfo));
|
|
158
|
+
async getModuleInfos(filenames) {
|
|
159
|
+
return Promise.all(filenames.map((filename) => this.getModuleInfo(filename)).filter((moduleInfo) => Boolean(moduleInfo)));
|
|
160
160
|
}
|
|
161
|
-
getModuleInfo(filename) {
|
|
161
|
+
async getModuleInfo(filename) {
|
|
162
162
|
try {
|
|
163
|
-
const module = requireHandlerModule(filename);
|
|
163
|
+
const module = await requireHandlerModule(filename);
|
|
164
164
|
return {
|
|
165
165
|
filename,
|
|
166
166
|
module
|
package/dist/esm/router/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { globby } from "@modern-js/utils";
|
|
2
|
+
import { globby, compatibleRequire } from "@modern-js/utils";
|
|
3
3
|
import { INDEX_SUFFIX } from "./constants";
|
|
4
4
|
const getFiles = (lambdaDir, rules) => globby.sync(rules, {
|
|
5
5
|
cwd: lambdaDir,
|
|
@@ -32,9 +32,9 @@ const clearRouteName = (routeName) => {
|
|
|
32
32
|
};
|
|
33
33
|
const isHandler = (input) => input && typeof input === "function";
|
|
34
34
|
const isFunction = (input) => input && {}.toString.call(input) === "[object Function]";
|
|
35
|
-
const requireHandlerModule = (modulePath) => {
|
|
36
|
-
const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual :
|
|
37
|
-
const module = originRequire(modulePath);
|
|
35
|
+
const requireHandlerModule = async (modulePath) => {
|
|
36
|
+
const originRequire = process.env.NODE_ENV === "test" ? jest.requireActual : compatibleRequire;
|
|
37
|
+
const module = await originRequire(modulePath, false);
|
|
38
38
|
if (isFunction(module)) {
|
|
39
39
|
return {
|
|
40
40
|
default: module
|
|
@@ -2,7 +2,7 @@ import 'reflect-metadata';
|
|
|
2
2
|
import type { HttpMethodDecider } from '@modern-js/types';
|
|
3
3
|
import { HttpMethod } from '../types';
|
|
4
4
|
import { APIMode } from './constants';
|
|
5
|
-
import { ApiHandler, APIHandlerInfo } from './types';
|
|
5
|
+
import type { ApiHandler, APIHandlerInfo } from './types';
|
|
6
6
|
export * from './types';
|
|
7
7
|
export * from './constants';
|
|
8
8
|
export declare class ApiRouter {
|
|
@@ -27,14 +27,14 @@ export declare class ApiRouter {
|
|
|
27
27
|
getApiMode(): APIMode;
|
|
28
28
|
getLambdaDir(): string;
|
|
29
29
|
isApiFile(filename: string): boolean;
|
|
30
|
-
getSingleModuleHandlers(filename: string): APIHandlerInfo[] | null
|
|
30
|
+
getSingleModuleHandlers(filename: string): Promise<APIHandlerInfo[] | null>;
|
|
31
31
|
getHandlerInfo(filename: string, originFuncName: string, handler: ApiHandler): APIHandlerInfo | null;
|
|
32
32
|
getSafeRoutePath(filename: string, handler?: ApiHandler): string;
|
|
33
33
|
getRouteName(filename: string, handler?: ApiHandler): string;
|
|
34
34
|
getHttpMethod(originHandlerName: string, handler?: ApiHandler): HttpMethod | null;
|
|
35
35
|
loadApiFiles(): string[];
|
|
36
36
|
getApiFiles(): string[];
|
|
37
|
-
getApiHandlers(): APIHandlerInfo[]
|
|
37
|
+
getApiHandlers(): Promise<APIHandlerInfo[]>;
|
|
38
38
|
/**
|
|
39
39
|
* 如果用户未传入或传入空串,默认为 /api
|
|
40
40
|
* 如果传入 /,则 prefix 为 /
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { APIHandlerInfo } from './types';
|
|
1
|
+
import type { APIHandlerInfo } from './types';
|
|
2
2
|
type MaybeAsync<I> = I | Promise<I>;
|
|
3
3
|
export type NormalHandler = (...args: any[]) => any;
|
|
4
4
|
export type Handler<I, O> = (input: I) => MaybeAsync<O>;
|
|
5
5
|
export declare const getFiles: (lambdaDir: string, rules: string | string[]) => string[];
|
|
6
6
|
export declare const getPathFromFilename: (baseDir: string, filename: string) => string;
|
|
7
7
|
export declare const isHandler: (input: any) => input is Handler<any, any>;
|
|
8
|
-
export declare const requireHandlerModule: (modulePath: string) => any
|
|
8
|
+
export declare const requireHandlerModule: (modulePath: string) => Promise<any>;
|
|
9
9
|
export declare const sortRoutes: (apiHandlers: APIHandlerInfo[]) => APIHandlerInfo[];
|
|
10
10
|
export {};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const debug:
|
|
1
|
+
export declare const debug: (...args: unknown[]) => void;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.58.
|
|
18
|
+
"version": "2.58.2",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
+
"@swc/helpers": "0.5.3",
|
|
31
32
|
"koa-compose": "^4.1.0",
|
|
32
33
|
"reflect-metadata": "^0.1.13",
|
|
33
34
|
"type-fest": "2.15.0",
|
|
34
|
-
"@
|
|
35
|
-
"@modern-js/utils": "2.58.0"
|
|
35
|
+
"@modern-js/utils": "2.58.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/jest": "^29",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"tsconfig-paths": "^4.1.2",
|
|
44
44
|
"typescript": "^5",
|
|
45
45
|
"zod": "^3.22.3",
|
|
46
|
-
"@
|
|
47
|
-
"@scripts/
|
|
48
|
-
"@
|
|
46
|
+
"@modern-js/types": "2.58.2",
|
|
47
|
+
"@scripts/build": "2.58.2",
|
|
48
|
+
"@scripts/jest-config": "2.58.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"zod": "^3.22.3",
|
|
52
51
|
"ts-node": "^10.9.1",
|
|
53
|
-
"tsconfig-paths": "^4.1.2"
|
|
52
|
+
"tsconfig-paths": "^4.1.2",
|
|
53
|
+
"zod": "^3.22.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
56
|
"zod": {
|