@modern-js/bff-core 2.40.1-alpha.0 → 2.42.0
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/router/constants.js +2 -12
- package/dist/cjs/router/index.js +3 -8
- package/dist/esm/router/constants.js +2 -12
- package/dist/esm/router/index.js +3 -8
- package/dist/types/api.d.ts +4 -1
- package/dist/types/client/generateClient.d.ts +13 -25
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/result.d.ts +9 -9
- package/dist/types/errors/http.d.ts +5 -5
- package/dist/types/index.d.ts +1 -1
- package/dist/types/operators/http.d.ts +11 -11
- package/dist/types/router/constants.d.ts +9 -9
- package/dist/types/router/index.d.ts +46 -53
- package/dist/types/router/types.d.ts +9 -9
- package/dist/types/router/utils.d.ts +1 -1
- package/dist/types/types.d.ts +38 -34
- package/dist/types/utils/alias.d.ts +2 -2
- package/dist/types/utils/debug.d.ts +1 -1
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/meta.d.ts +1 -1
- package/dist/types/utils/storage.d.ts +3 -3
- package/dist/types/utils/validate.d.ts +2 -2
- package/package.json +6 -6
|
@@ -31,18 +31,8 @@ var import_types = require("../types");
|
|
|
31
31
|
const AllHttpMethods = Object.values(import_types.HttpMethod);
|
|
32
32
|
var APIMode;
|
|
33
33
|
(function(APIMode2) {
|
|
34
|
-
APIMode2[
|
|
35
|
-
|
|
36
|
-
* 框架模式
|
|
37
|
-
*/
|
|
38
|
-
"FARMEWORK"
|
|
39
|
-
] = "framework";
|
|
40
|
-
APIMode2[
|
|
41
|
-
/**
|
|
42
|
-
* 函数模式
|
|
43
|
-
*/
|
|
44
|
-
"FUNCTION"
|
|
45
|
-
] = "function";
|
|
34
|
+
APIMode2["FARMEWORK"] = "framework";
|
|
35
|
+
APIMode2["FUNCTION"] = "function";
|
|
46
36
|
})(APIMode || (APIMode = {}));
|
|
47
37
|
const FRAMEWORK_MODE_LAMBDA_DIR = "lambda";
|
|
48
38
|
const FRAMEWORK_MODE_APP_DIR = "app";
|
package/dist/cjs/router/index.js
CHANGED
|
@@ -45,17 +45,12 @@ __reExport(router_exports, require("./constants"), module.exports);
|
|
|
45
45
|
class ApiRouter {
|
|
46
46
|
enableRegister() {
|
|
47
47
|
const existTsLoader = Boolean(require.extensions[".ts"]);
|
|
48
|
-
if (!existTsLoader
|
|
48
|
+
if (!existTsLoader) {
|
|
49
49
|
try {
|
|
50
50
|
const projectSearchDir = this.appDir || this.apiDir;
|
|
51
|
-
let tsconfigPath = import_path.default.join(this.appDir || process.cwd(), "tsconfig.json");
|
|
52
|
-
const serverTsconfigPath = import_path.default.resolve(this.appDir || process.cwd(), "tsconfig.server.json");
|
|
53
|
-
if (import_utils.fs.existsSync(serverTsconfigPath)) {
|
|
54
|
-
tsconfigPath = serverTsconfigPath;
|
|
55
|
-
}
|
|
56
51
|
const tsNode = require("ts-node");
|
|
57
52
|
tsNode.register({
|
|
58
|
-
|
|
53
|
+
projectSearchDir,
|
|
59
54
|
compilerOptions: {
|
|
60
55
|
allowJs: false
|
|
61
56
|
},
|
|
@@ -228,6 +223,7 @@ class ApiRouter {
|
|
|
228
223
|
return filenames.map((filename) => this.getModuleInfo(filename)).filter((moduleInfo) => Boolean(moduleInfo));
|
|
229
224
|
}
|
|
230
225
|
getModuleInfo(filename) {
|
|
226
|
+
this.enableRegister();
|
|
231
227
|
try {
|
|
232
228
|
const module2 = (0, import_utils3.requireHandlerModule)(filename);
|
|
233
229
|
return {
|
|
@@ -318,7 +314,6 @@ class ApiRouter {
|
|
|
318
314
|
this.lambdaDir = this.getExactLambdaDir(this.apiDir, lambdaDir);
|
|
319
315
|
this.existLambdaDir = import_utils.fs.existsSync(this.lambdaDir);
|
|
320
316
|
(0, import_utils2.debug)(`apiDir:`, this.apiDir, `lambdaDir:`, this.lambdaDir);
|
|
321
|
-
this.enableRegister();
|
|
322
317
|
}
|
|
323
318
|
}
|
|
324
319
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -2,18 +2,8 @@ import { HttpMethod } from "../types";
|
|
|
2
2
|
const AllHttpMethods = Object.values(HttpMethod);
|
|
3
3
|
var APIMode;
|
|
4
4
|
(function(APIMode2) {
|
|
5
|
-
APIMode2[
|
|
6
|
-
|
|
7
|
-
* 框架模式
|
|
8
|
-
*/
|
|
9
|
-
"FARMEWORK"
|
|
10
|
-
] = "framework";
|
|
11
|
-
APIMode2[
|
|
12
|
-
/**
|
|
13
|
-
* 函数模式
|
|
14
|
-
*/
|
|
15
|
-
"FUNCTION"
|
|
16
|
-
] = "function";
|
|
5
|
+
APIMode2["FARMEWORK"] = "framework";
|
|
6
|
+
APIMode2["FUNCTION"] = "function";
|
|
17
7
|
})(APIMode || (APIMode = {}));
|
|
18
8
|
const FRAMEWORK_MODE_LAMBDA_DIR = "lambda";
|
|
19
9
|
const FRAMEWORK_MODE_APP_DIR = "app";
|
package/dist/esm/router/index.js
CHANGED
|
@@ -11,17 +11,12 @@ export * from "./constants";
|
|
|
11
11
|
class ApiRouter {
|
|
12
12
|
enableRegister() {
|
|
13
13
|
const existTsLoader = Boolean(require.extensions[".ts"]);
|
|
14
|
-
if (!existTsLoader
|
|
14
|
+
if (!existTsLoader) {
|
|
15
15
|
try {
|
|
16
16
|
const projectSearchDir = this.appDir || this.apiDir;
|
|
17
|
-
let tsconfigPath = path.join(this.appDir || process.cwd(), "tsconfig.json");
|
|
18
|
-
const serverTsconfigPath = path.resolve(this.appDir || process.cwd(), "tsconfig.server.json");
|
|
19
|
-
if (fs.existsSync(serverTsconfigPath)) {
|
|
20
|
-
tsconfigPath = serverTsconfigPath;
|
|
21
|
-
}
|
|
22
17
|
const tsNode = require("ts-node");
|
|
23
18
|
tsNode.register({
|
|
24
|
-
|
|
19
|
+
projectSearchDir,
|
|
25
20
|
compilerOptions: {
|
|
26
21
|
allowJs: false
|
|
27
22
|
},
|
|
@@ -194,6 +189,7 @@ class ApiRouter {
|
|
|
194
189
|
return filenames.map((filename) => this.getModuleInfo(filename)).filter((moduleInfo) => Boolean(moduleInfo));
|
|
195
190
|
}
|
|
196
191
|
getModuleInfo(filename) {
|
|
192
|
+
this.enableRegister();
|
|
197
193
|
try {
|
|
198
194
|
const module = requireHandlerModule(filename);
|
|
199
195
|
return {
|
|
@@ -284,7 +280,6 @@ class ApiRouter {
|
|
|
284
280
|
this.lambdaDir = this.getExactLambdaDir(this.apiDir, lambdaDir);
|
|
285
281
|
this.existLambdaDir = fs.existsSync(this.lambdaDir);
|
|
286
282
|
debug(`apiDir:`, this.apiDir, `lambdaDir:`, this.lambdaDir);
|
|
287
|
-
this.enableRegister();
|
|
288
283
|
}
|
|
289
284
|
}
|
|
290
285
|
export {
|
package/dist/types/api.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import type { ApiRunner, ArrayToObject, ExtractInputType, ExtractOuputType, Operator, MaybeAsync } from './types';
|
|
3
|
-
export declare function Api<Operators extends Operator<any, any>[], Res extends MaybeAsync<any>>(...args: [
|
|
3
|
+
export declare function Api<Operators extends Operator<any, any>[], Res extends MaybeAsync<any>>(...args: [
|
|
4
|
+
...operators: Operators,
|
|
5
|
+
handler: (arg: ArrayToObject<ExtractOuputType<Operators>>) => Res
|
|
6
|
+
]): ApiRunner<ExtractInputType<Operators> extends void[] ? void : ArrayToObject<ExtractInputType<Operators>>, Res>;
|
|
@@ -2,30 +2,18 @@ import type { HttpMethodDecider } from '@modern-js/types';
|
|
|
2
2
|
import { Result } from './result';
|
|
3
3
|
export type GenClientResult = Result<string>;
|
|
4
4
|
export type GenClientOptions = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
resourcePath: string;
|
|
6
|
+
source: string;
|
|
7
|
+
appDir: string;
|
|
8
|
+
apiDir: string;
|
|
9
|
+
lambdaDir: string;
|
|
10
|
+
prefix: string;
|
|
11
|
+
port: number;
|
|
12
|
+
requestCreator?: string;
|
|
13
|
+
fetcher?: string;
|
|
14
|
+
target?: string;
|
|
15
|
+
requireResolve?: typeof require.resolve;
|
|
16
|
+
httpMethodDecider?: HttpMethodDecider;
|
|
17
17
|
};
|
|
18
18
|
export declare const DEFAULT_CLIENT_REQUEST_CREATOR = "@modern-js/create-request";
|
|
19
|
-
export declare const generateClient: ({
|
|
20
|
-
appDir,
|
|
21
|
-
resourcePath,
|
|
22
|
-
apiDir,
|
|
23
|
-
lambdaDir,
|
|
24
|
-
prefix,
|
|
25
|
-
port,
|
|
26
|
-
target,
|
|
27
|
-
requestCreator,
|
|
28
|
-
fetcher,
|
|
29
|
-
requireResolve,
|
|
30
|
-
httpMethodDecider
|
|
31
|
-
}: GenClientOptions) => Promise<GenClientResult>;
|
|
19
|
+
export declare const generateClient: ({ appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve, httpMethodDecider, }: GenClientOptions) => Promise<GenClientResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './generateClient';
|
|
1
|
+
export * from './generateClient';
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export type Err<T = unknown> = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
kind: 'Err';
|
|
3
|
+
value: T;
|
|
4
|
+
isErr: true;
|
|
5
|
+
isOk: false;
|
|
6
6
|
};
|
|
7
7
|
export type Ok<T = unknown> = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
kind: 'Ok';
|
|
9
|
+
value: T;
|
|
10
|
+
isErr: false;
|
|
11
|
+
isOk: true;
|
|
12
12
|
};
|
|
13
13
|
export type Result<T = unknown, E = string> = Err<E> | Ok<T>;
|
|
14
14
|
export declare const Err: <E = string>(value: E) => Err<E>;
|
|
15
|
-
export declare const Ok: <T, E = string>(value: T) => Result<T, E>;
|
|
15
|
+
export declare const Ok: <T, E = string>(value: T) => Result<T, E>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare class HttpError extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
status: number;
|
|
3
|
+
constructor(status: number, message: string);
|
|
4
4
|
}
|
|
5
5
|
export declare class ValidationError extends HttpError {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
6
|
+
private code;
|
|
7
|
+
constructor(status: number, message: string);
|
|
8
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export * from './router';
|
|
|
4
4
|
export * from './types';
|
|
5
5
|
export * from './client';
|
|
6
6
|
export * from './operators/http';
|
|
7
|
-
export { getRelativeRuntimePath, HANDLER_WITH_META, isWithMetaHandler, INPUT_PARAMS_DECIDER, isInputParamsDeciderHandler, createStorage, registerPaths } from './utils';
|
|
7
|
+
export { getRelativeRuntimePath, HANDLER_WITH_META, isWithMetaHandler, INPUT_PARAMS_DECIDER, isInputParamsDeciderHandler, createStorage, registerPaths, } from './utils';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import { Operator, HttpMethod, ResponseMetaType } from '../types';
|
|
3
3
|
export interface ResponseMeta {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type: ResponseMetaType;
|
|
5
|
+
value: unknown;
|
|
6
6
|
}
|
|
7
7
|
export declare const createHttpOperator: (method: HttpMethod) => (urlPath: string) => Operator<void>;
|
|
8
8
|
export declare const Get: (urlPath: string) => Operator<void>;
|
|
@@ -15,25 +15,25 @@ export declare const Patch: (urlPath: string) => Operator<void>;
|
|
|
15
15
|
export declare const Options: (urlPath: string) => Operator<void>;
|
|
16
16
|
export declare const Head: (urlPath: string) => Operator<void>;
|
|
17
17
|
export declare const Data: <Schema extends z.ZodType<any, z.ZodTypeDef, any>>(schema: Schema) => Operator<{
|
|
18
|
-
|
|
18
|
+
data: z.input<Schema>;
|
|
19
19
|
}, {
|
|
20
|
-
|
|
20
|
+
data: z.output<Schema>;
|
|
21
21
|
}>;
|
|
22
22
|
export declare const Query: <Schema extends z.ZodType<any, z.ZodTypeDef, any>>(schema: Schema) => Operator<{
|
|
23
|
-
|
|
23
|
+
query: z.input<Schema>;
|
|
24
24
|
}, {
|
|
25
|
-
|
|
25
|
+
query: z.output<Schema>;
|
|
26
26
|
}>;
|
|
27
27
|
export declare const Params: <Schema extends z.ZodType<any, z.ZodTypeDef, any>>(schema: Schema) => Operator<{
|
|
28
|
-
|
|
28
|
+
params: z.input<Schema>;
|
|
29
29
|
}, {
|
|
30
|
-
|
|
30
|
+
params: z.output<Schema>;
|
|
31
31
|
}>;
|
|
32
32
|
export declare const Headers: <Schema extends z.ZodType<any, z.ZodTypeDef, any>>(schema: Schema) => Operator<{
|
|
33
|
-
|
|
33
|
+
headers: z.input<Schema>;
|
|
34
34
|
}, {
|
|
35
|
-
|
|
35
|
+
headers: z.output<Schema>;
|
|
36
36
|
}>;
|
|
37
37
|
export declare const HttpCode: (statusCode: number) => Operator<void>;
|
|
38
38
|
export declare const SetHeaders: (headers: Record<string, string>) => Operator<void>;
|
|
39
|
-
export declare const Redirect: (url: string) => Operator<void>;
|
|
39
|
+
export declare const Redirect: (url: string) => Operator<void>;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export declare const AllHttpMethods: string[];
|
|
2
2
|
export declare enum APIMode {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 框架模式
|
|
5
|
+
*/
|
|
6
|
+
FARMEWORK = "framework",
|
|
7
|
+
/**
|
|
8
|
+
* 函数模式
|
|
9
|
+
*/
|
|
10
|
+
FUNCTION = "function"
|
|
11
11
|
}
|
|
12
12
|
export declare const FRAMEWORK_MODE_LAMBDA_DIR = "lambda";
|
|
13
13
|
export declare const FRAMEWORK_MODE_APP_DIR = "app";
|
|
14
14
|
export declare const INDEX_SUFFIX = "index";
|
|
15
15
|
export declare const API_DIR = "api";
|
|
16
|
-
export declare const API_FILE_RULES: string[];
|
|
16
|
+
export declare const API_FILE_RULES: string[];
|
|
@@ -6,56 +6,49 @@ import { ApiHandler, APIHandlerInfo } from './types';
|
|
|
6
6
|
export * from './types';
|
|
7
7
|
export * from './constants';
|
|
8
8
|
export declare class ApiRouter {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
private getModuleInfos;
|
|
56
|
-
private getModuleInfo;
|
|
57
|
-
private getHandlerInfos;
|
|
58
|
-
private getModuleHandlerInfos;
|
|
59
|
-
private validateValidApifile;
|
|
60
|
-
private getRoutePath;
|
|
61
|
-
}
|
|
9
|
+
private apiMode;
|
|
10
|
+
private appDir?;
|
|
11
|
+
private apiDir;
|
|
12
|
+
private existLambdaDir;
|
|
13
|
+
private httpMethodDecider;
|
|
14
|
+
private lambdaDir;
|
|
15
|
+
private prefix;
|
|
16
|
+
private apiFiles;
|
|
17
|
+
private isBuild?;
|
|
18
|
+
constructor({ appDir, apiDir, lambdaDir, prefix, isBuild, httpMethodDecider, }: {
|
|
19
|
+
appDir?: string;
|
|
20
|
+
apiDir: string;
|
|
21
|
+
lambdaDir?: string;
|
|
22
|
+
prefix?: string;
|
|
23
|
+
isBuild?: boolean;
|
|
24
|
+
httpMethodDecider?: HttpMethodDecider;
|
|
25
|
+
});
|
|
26
|
+
private enableRegister;
|
|
27
|
+
isExistLambda(): boolean;
|
|
28
|
+
getApiMode(): APIMode;
|
|
29
|
+
getLambdaDir(): string;
|
|
30
|
+
isApiFile(filename: string): boolean;
|
|
31
|
+
getSingleModuleHandlers(filename: string): APIHandlerInfo[] | null;
|
|
32
|
+
getHandlerInfo(filename: string, originFuncName: string, handler: ApiHandler): APIHandlerInfo | null;
|
|
33
|
+
getSafeRoutePath(filename: string, handler?: ApiHandler): string;
|
|
34
|
+
getRouteName(filename: string, handler?: ApiHandler): string;
|
|
35
|
+
getHttpMethod(originHandlerName: string, handler?: ApiHandler): HttpMethod | null;
|
|
36
|
+
loadApiFiles(): string[];
|
|
37
|
+
getApiFiles(): string[];
|
|
38
|
+
getApiHandlers(): APIHandlerInfo[];
|
|
39
|
+
/**
|
|
40
|
+
* 如果用户未传入或传入空串,默认为 /api
|
|
41
|
+
* 如果传入 /,则 prefix 为 /
|
|
42
|
+
*/
|
|
43
|
+
private initPrefix;
|
|
44
|
+
private validateAbsolute;
|
|
45
|
+
private getExactApiMode;
|
|
46
|
+
private createExistChecker;
|
|
47
|
+
private getExactLambdaDir;
|
|
48
|
+
private getModuleInfos;
|
|
49
|
+
private getModuleInfo;
|
|
50
|
+
private getHandlerInfos;
|
|
51
|
+
private getModuleHandlerInfos;
|
|
52
|
+
private validateValidApifile;
|
|
53
|
+
private getRoutePath;
|
|
54
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { HttpMethod } from '../types';
|
|
2
2
|
export type ModuleInfo = {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
filename: string;
|
|
4
|
+
module: HandlerModule;
|
|
5
5
|
};
|
|
6
6
|
type Handler = (...args: any) => any | Promise<any>;
|
|
7
7
|
export type ApiHandler = Handler;
|
|
8
8
|
export type HandlerModule = Record<string, ApiHandler>;
|
|
9
9
|
export type APIHandlerInfo = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
handler: ApiHandler;
|
|
11
|
+
name: string;
|
|
12
|
+
httpMethod: HttpMethod;
|
|
13
|
+
filename: string;
|
|
14
|
+
routeName: string;
|
|
15
|
+
routePath: string;
|
|
16
16
|
};
|
|
17
|
-
export {};
|
|
17
|
+
export {};
|
|
@@ -7,4 +7,4 @@ export declare const getPathFromFilename: (baseDir: string, filename: string) =>
|
|
|
7
7
|
export declare const isHandler: (input: any) => input is Handler<any, any>;
|
|
8
8
|
export declare const requireHandlerModule: (modulePath: string) => any;
|
|
9
9
|
export declare const sortRoutes: (apiHandlers: APIHandlerInfo[]) => APIHandlerInfo[];
|
|
10
|
-
export {};
|
|
10
|
+
export {};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,58 +1,62 @@
|
|
|
1
1
|
import { Merge } from 'type-fest';
|
|
2
2
|
export declare enum OperatorType {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Trigger = 0,
|
|
4
|
+
Middleware = 1
|
|
5
5
|
}
|
|
6
6
|
export declare enum TriggerType {
|
|
7
|
-
|
|
7
|
+
Http = 0
|
|
8
8
|
}
|
|
9
9
|
export declare enum HttpMetadata {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
Method = "METHOD",
|
|
11
|
+
Data = "DATA",
|
|
12
|
+
Query = "QUERY",
|
|
13
|
+
Params = "PARAMS",
|
|
14
|
+
Headers = "HEADERS",
|
|
15
|
+
Response = "RESPONSE"
|
|
16
16
|
}
|
|
17
17
|
export declare enum ResponseMetaType {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
StatusCode = 0,
|
|
19
|
+
Redirect = 1,
|
|
20
|
+
Headers = 2
|
|
21
21
|
}
|
|
22
22
|
export declare enum HttpMethod {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
Get = "GET",
|
|
24
|
+
Post = "POST",
|
|
25
|
+
Put = "PUT",
|
|
26
|
+
Delete = "DELETE",
|
|
27
|
+
Connect = "CONNECT",
|
|
28
|
+
Trace = "TRACE",
|
|
29
|
+
Patch = "PATCH",
|
|
30
|
+
Options = "OPTIONS",
|
|
31
|
+
Head = "HEAD"
|
|
32
32
|
}
|
|
33
33
|
export type InputSchemaMeata = Extract<HttpMetadata, HttpMetadata.Data | HttpMetadata.Query | HttpMetadata.Headers | HttpMetadata.Params>;
|
|
34
34
|
export type ExecuteFunc<Outputs> = (helper: ExecuteHelper<Outputs>, next: () => Promise<any>) => Promise<any>;
|
|
35
35
|
export type ExecuteHelper<Outputs> = {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
result?: any;
|
|
37
|
+
inputs: Outputs;
|
|
38
38
|
};
|
|
39
39
|
export type MetadataHelper = {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
setMetadata: <T = any>(key: any, value: T) => void;
|
|
41
|
+
getMetadata: <T = any>(key: any) => T;
|
|
42
42
|
};
|
|
43
43
|
export type Operator<Input = any, Output = Input> = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
name: string;
|
|
45
|
+
inputType?: Input;
|
|
46
|
+
outputType?: Output;
|
|
47
|
+
metadata?: (helper: MetadataHelper) => void;
|
|
48
|
+
validate?: ExecuteFunc<Output>;
|
|
49
|
+
execute?: ExecuteFunc<Output>;
|
|
50
50
|
};
|
|
51
51
|
export type MaybeAsync<T> = Promise<T> | T;
|
|
52
52
|
export type ApiRunner<Input extends object | void | unknown, Output extends MaybeAsync<any>> = (...args: Input extends void ? [] : [input: Input]) => Output;
|
|
53
53
|
export type NonNullable<T> = Exclude<T, null | undefined>;
|
|
54
|
-
export type ExtractInputType<T> = {
|
|
55
|
-
|
|
54
|
+
export type ExtractInputType<T> = {
|
|
55
|
+
[key in keyof T]: T[key] extends Operator<any, any> ? NonNullable<T[key]['inputType']> : void;
|
|
56
|
+
};
|
|
57
|
+
export type ExtractOuputType<T> = {
|
|
58
|
+
[key in keyof T]: T[key] extends Operator<any, any> ? NonNullable<T[key]['outputType']> : void;
|
|
59
|
+
};
|
|
56
60
|
export type ArrayToObject<T, R = {}> = T extends [infer First, ...infer Rest] ? First extends PromiseLike<infer PromiseValue> ? PromiseValue : First extends object ? Merge<First, ArrayToObject<Rest, R>> : ArrayToObject<Rest, R> : R;
|
|
57
61
|
export type AsyncFunction = (...args: any[]) => Promise<any>;
|
|
58
|
-
export declare const httpMethods: HttpMethod[];
|
|
62
|
+
export declare const httpMethods: HttpMethod[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
interface Paths {
|
|
2
|
-
|
|
2
|
+
[key: string]: string[] | string;
|
|
3
3
|
}
|
|
4
4
|
export declare const getRelativeRuntimePath: (appDirectory: string, serverRuntimePath: string) => string;
|
|
5
5
|
export declare const createMatchPath: (paths: Paths) => (request: string) => string | null;
|
|
6
6
|
export declare const registerPaths: (paths: Paths) => () => void;
|
|
7
|
-
export {};
|
|
7
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
|
|
1
|
+
export declare const debug: import("@modern-js/utils/compiled/debug").Debugger;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const HANDLER_WITH_META = "HANDLER_WITH_META";
|
|
2
2
|
export declare const INPUT_PARAMS_DECIDER = "INPUT_PARAMS_DECIDER";
|
|
3
3
|
export declare const isWithMetaHandler: (handler: any) => any;
|
|
4
|
-
export declare const isInputParamsDeciderHandler: (handler: any) => any;
|
|
4
|
+
export declare const isInputParamsDeciderHandler: (handler: any) => any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const createStorage: <T>() => {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
run: <O>(context: T, cb: () => O | Promise<O>) => Promise<O>;
|
|
3
|
+
useContext: () => T;
|
|
4
4
|
};
|
|
5
|
-
export { createStorage };
|
|
5
|
+
export { createStorage };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const getTypeErrorMessage: (actual: unknown) => string;
|
|
2
2
|
export declare class ERR_INVALID_ARG_TYPE extends Error {
|
|
3
|
-
|
|
3
|
+
constructor(funcName: string, expectedType: string, actual: unknown);
|
|
4
4
|
}
|
|
5
|
-
export declare const validateFunction: (maybeFunc: unknown, name: string) => boolean;
|
|
5
|
+
export declare const validateFunction: (maybeFunc: unknown, name: string) => boolean;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.42.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"koa-compose": "^4.1.0",
|
|
32
32
|
"reflect-metadata": "^0.1.13",
|
|
33
|
-
"@swc/helpers": "0.5.
|
|
34
|
-
"@modern-js/utils": "2.
|
|
33
|
+
"@swc/helpers": "0.5.3",
|
|
34
|
+
"@modern-js/utils": "2.42.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/jest": "^29",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"type-fest": "2.15.0",
|
|
44
44
|
"typescript": "^5",
|
|
45
45
|
"zod": "^3.22.3",
|
|
46
|
-
"@
|
|
47
|
-
"@scripts/
|
|
48
|
-
"@
|
|
46
|
+
"@modern-js/types": "2.42.0",
|
|
47
|
+
"@scripts/build": "2.42.0",
|
|
48
|
+
"@scripts/jest-config": "2.42.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"zod": "^3.22.3",
|