@modern-js/bff-core 2.63.5 → 2.63.7
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.
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,36 +15,20 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var generateClient_exports = {};
|
|
30
20
|
__export(generateClient_exports, {
|
|
31
21
|
DEFAULT_CLIENT_REQUEST_CREATOR: () => DEFAULT_CLIENT_REQUEST_CREATOR,
|
|
22
|
+
INNER_CLIENT_REQUEST_CREATOR: () => INNER_CLIENT_REQUEST_CREATOR,
|
|
32
23
|
generateClient: () => generateClient
|
|
33
24
|
});
|
|
34
25
|
module.exports = __toCommonJS(generateClient_exports);
|
|
35
|
-
var path = __toESM(require("path"));
|
|
36
26
|
var import_router = require("../router");
|
|
37
27
|
var import_result = require("./result");
|
|
38
28
|
const DEFAULT_CLIENT_REQUEST_CREATOR = "@modern-js/create-request";
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
} else {
|
|
43
|
-
let resolvedPath = requestCreator;
|
|
44
|
-
try {
|
|
45
|
-
resolvedPath = path.dirname(requireResolve(requestCreator));
|
|
46
|
-
} catch (error) {
|
|
47
|
-
}
|
|
48
|
-
requestCreator = `${resolvedPath}${target ? `/${target}` : ""}`.replace(/\\/g, "/");
|
|
49
|
-
}
|
|
29
|
+
const INNER_CLIENT_REQUEST_CREATOR = "@modern-js/plugin-bff/runtime/create-request";
|
|
30
|
+
const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve = require.resolve, httpMethodDecider, domain }) => {
|
|
31
|
+
requestCreator = requestCreator || INNER_CLIENT_REQUEST_CREATOR;
|
|
50
32
|
const apiRouter = new import_router.ApiRouter({
|
|
51
33
|
appDir,
|
|
52
34
|
apiDir,
|
|
@@ -67,17 +49,30 @@ const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix,
|
|
|
67
49
|
}
|
|
68
50
|
const upperHttpMethod = httpMethod.toUpperCase();
|
|
69
51
|
const routeName = routePath;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
const requestId = target === "bundle" ? process.env.npm_package_name : void 0;
|
|
53
|
+
if (action === "upload") {
|
|
54
|
+
const requestOptions = {
|
|
55
|
+
path: routeName,
|
|
56
|
+
domain,
|
|
57
|
+
requestId
|
|
58
|
+
};
|
|
59
|
+
handlersCode += `export ${exportStatement} createUploader(${JSON.stringify(requestOptions)});`;
|
|
75
60
|
} else {
|
|
76
|
-
|
|
61
|
+
const portValue = target === "server" ? `process.env.PORT || ${String(port)}` : String(port);
|
|
62
|
+
const optionsStr = `{
|
|
63
|
+
path: '${routeName}',
|
|
64
|
+
method: '${upperHttpMethod}',
|
|
65
|
+
port: ${portValue},
|
|
66
|
+
httpMethodDecider: '${httpMethodDecider || "functionName"}'
|
|
67
|
+
${domain ? `, domain: '${domain}'` : ""}
|
|
68
|
+
${fetcher ? ", fetch: 'fetch'" : ""}
|
|
69
|
+
${requestId ? `, requestId: '${requestId}'` : ""}
|
|
70
|
+
}`.replace(/\n\s*/g, "");
|
|
71
|
+
handlersCode += `export ${exportStatement} createRequest(${optionsStr});
|
|
77
72
|
`;
|
|
78
73
|
}
|
|
79
74
|
}
|
|
80
|
-
const importCode = `import { createRequest${handlerInfos.find((i) => i.action) ? ", createUploader" : ""} } from '${requestCreator}';
|
|
75
|
+
const importCode = `import { createRequest${handlerInfos.find((i) => i.action === "upload") ? ", createUploader" : ""} } from '${requestCreator}';
|
|
81
76
|
${fetcher ? `import { fetch } from '${fetcher}';
|
|
82
77
|
` : ""}`;
|
|
83
78
|
return (0, import_result.Ok)(`${importCode}
|
|
@@ -86,5 +81,6 @@ ${handlersCode}`);
|
|
|
86
81
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
82
|
0 && (module.exports = {
|
|
88
83
|
DEFAULT_CLIENT_REQUEST_CREATOR,
|
|
84
|
+
INNER_CLIENT_REQUEST_CREATOR,
|
|
89
85
|
generateClient
|
|
90
86
|
});
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
1
|
import { ApiRouter } from "../router";
|
|
3
2
|
import { Err, Ok } from "./result";
|
|
4
3
|
const DEFAULT_CLIENT_REQUEST_CREATOR = "@modern-js/create-request";
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} else {
|
|
9
|
-
let resolvedPath = requestCreator;
|
|
10
|
-
try {
|
|
11
|
-
resolvedPath = path.dirname(requireResolve(requestCreator));
|
|
12
|
-
} catch (error) {
|
|
13
|
-
}
|
|
14
|
-
requestCreator = `${resolvedPath}${target ? `/${target}` : ""}`.replace(/\\/g, "/");
|
|
15
|
-
}
|
|
4
|
+
const INNER_CLIENT_REQUEST_CREATOR = "@modern-js/plugin-bff/runtime/create-request";
|
|
5
|
+
const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve = require.resolve, httpMethodDecider, domain }) => {
|
|
6
|
+
requestCreator = requestCreator || INNER_CLIENT_REQUEST_CREATOR;
|
|
16
7
|
const apiRouter = new ApiRouter({
|
|
17
8
|
appDir,
|
|
18
9
|
apiDir,
|
|
@@ -33,17 +24,30 @@ const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix,
|
|
|
33
24
|
}
|
|
34
25
|
const upperHttpMethod = httpMethod.toUpperCase();
|
|
35
26
|
const routeName = routePath;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
const requestId = target === "bundle" ? process.env.npm_package_name : void 0;
|
|
28
|
+
if (action === "upload") {
|
|
29
|
+
const requestOptions = {
|
|
30
|
+
path: routeName,
|
|
31
|
+
domain,
|
|
32
|
+
requestId
|
|
33
|
+
};
|
|
34
|
+
handlersCode += `export ${exportStatement} createUploader(${JSON.stringify(requestOptions)});`;
|
|
41
35
|
} else {
|
|
42
|
-
|
|
36
|
+
const portValue = target === "server" ? `process.env.PORT || ${String(port)}` : String(port);
|
|
37
|
+
const optionsStr = `{
|
|
38
|
+
path: '${routeName}',
|
|
39
|
+
method: '${upperHttpMethod}',
|
|
40
|
+
port: ${portValue},
|
|
41
|
+
httpMethodDecider: '${httpMethodDecider || "functionName"}'
|
|
42
|
+
${domain ? `, domain: '${domain}'` : ""}
|
|
43
|
+
${fetcher ? ", fetch: 'fetch'" : ""}
|
|
44
|
+
${requestId ? `, requestId: '${requestId}'` : ""}
|
|
45
|
+
}`.replace(/\n\s*/g, "");
|
|
46
|
+
handlersCode += `export ${exportStatement} createRequest(${optionsStr});
|
|
43
47
|
`;
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
const importCode = `import { createRequest${handlerInfos.find((i) => i.action) ? ", createUploader" : ""} } from '${requestCreator}';
|
|
50
|
+
const importCode = `import { createRequest${handlerInfos.find((i) => i.action === "upload") ? ", createUploader" : ""} } from '${requestCreator}';
|
|
47
51
|
${fetcher ? `import { fetch } from '${fetcher}';
|
|
48
52
|
` : ""}`;
|
|
49
53
|
return Ok(`${importCode}
|
|
@@ -51,5 +55,6 @@ ${handlersCode}`);
|
|
|
51
55
|
};
|
|
52
56
|
export {
|
|
53
57
|
DEFAULT_CLIENT_REQUEST_CREATOR,
|
|
58
|
+
INNER_CLIENT_REQUEST_CREATOR,
|
|
54
59
|
generateClient
|
|
55
60
|
};
|
|
@@ -14,6 +14,8 @@ export type GenClientOptions = {
|
|
|
14
14
|
target?: string;
|
|
15
15
|
requireResolve?: typeof require.resolve;
|
|
16
16
|
httpMethodDecider?: HttpMethodDecider;
|
|
17
|
+
domain?: string;
|
|
17
18
|
};
|
|
18
19
|
export declare const DEFAULT_CLIENT_REQUEST_CREATOR = "@modern-js/create-request";
|
|
19
|
-
export declare const
|
|
20
|
+
export declare const INNER_CLIENT_REQUEST_CREATOR = "@modern-js/plugin-bff/runtime/create-request";
|
|
21
|
+
export declare const generateClient: ({ appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve, httpMethodDecider, domain, }: GenClientOptions) => Promise<GenClientResult>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type Merge<T, U> = T & Omit<U, keyof T>;
|
|
2
2
|
export declare enum OperatorType {
|
|
3
3
|
Trigger = 0,
|
|
4
4
|
Middleware = 1
|
|
@@ -61,3 +61,4 @@ export type ExtractOuputType<T> = {
|
|
|
61
61
|
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;
|
|
62
62
|
export type AsyncFunction = (...args: any[]) => Promise<any>;
|
|
63
63
|
export declare const httpMethods: HttpMethod[];
|
|
64
|
+
export {};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.63.
|
|
18
|
+
"version": "2.63.7",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"koa-compose": "^4.1.0",
|
|
33
33
|
"reflect-metadata": "^0.1.13",
|
|
34
34
|
"type-fest": "2.15.0",
|
|
35
|
-
"@modern-js/utils": "2.63.
|
|
35
|
+
"@modern-js/utils": "2.63.7"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/jest": "^29",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"tsconfig-paths": "^4.1.2",
|
|
44
44
|
"typescript": "^5",
|
|
45
45
|
"zod": "^3.22.3",
|
|
46
|
-
"@modern-js/types": "2.63.
|
|
47
|
-
"@scripts/build": "2.63.
|
|
48
|
-
"@scripts/jest-config": "2.63.
|
|
46
|
+
"@modern-js/types": "2.63.7",
|
|
47
|
+
"@scripts/build": "2.63.7",
|
|
48
|
+
"@scripts/jest-config": "2.63.7"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"ts-node": "^10.9.1",
|