@modern-js/bff-core 2.15.0 → 2.17.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/CHANGELOG.md +21 -0
- package/dist/cjs/api.js +22 -42
- package/dist/cjs/client/generateClient.js +63 -66
- package/dist/cjs/client/index.js +18 -17
- package/dist/cjs/client/result.js +11 -24
- package/dist/cjs/errors/http.js +26 -24
- package/dist/cjs/index.js +41 -50
- package/dist/cjs/operators/http.js +95 -101
- package/dist/cjs/router/constants.js +32 -40
- package/dist/cjs/router/index.js +114 -116
- package/dist/cjs/router/types.js +4 -15
- package/dist/cjs/router/utils.js +33 -50
- package/dist/cjs/types.js +29 -46
- package/dist/cjs/utils/alias.js +78 -58
- package/dist/cjs/utils/debug.js +8 -26
- package/dist/cjs/utils/index.js +24 -30
- package/dist/cjs/utils/meta.js +13 -28
- package/dist/cjs/utils/storage.js +51 -41
- package/dist/cjs/utils/validate.js +27 -44
- package/dist/esm/api.js +5 -5
- package/dist/esm/client/generateClient.js +6 -30
- package/dist/esm/client/result.js +2 -6
- package/dist/esm/errors/http.js +17 -6
- package/dist/esm/index.js +3 -23
- package/dist/esm/operators/http.js +22 -55
- package/dist/esm/router/constants.js +21 -20
- package/dist/esm/router/index.js +58 -61
- package/dist/esm/router/types.js +1 -0
- package/dist/esm/router/utils.js +11 -14
- package/dist/esm/types.js +16 -24
- package/dist/esm/utils/alias.js +12 -18
- package/dist/esm/utils/debug.js +1 -4
- package/dist/esm/utils/index.js +1 -4
- package/dist/esm/utils/meta.js +4 -10
- package/dist/esm/utils/storage.js +2 -6
- package/dist/esm/utils/validate.js +12 -15
- package/package.json +11 -7
package/dist/cjs/utils/alias.js
CHANGED
|
@@ -1,56 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var alias_exports = {};
|
|
29
|
-
__export(alias_exports, {
|
|
30
|
-
createMatchPath: () => createMatchPath,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
31
13
|
getRelativeRuntimePath: () => getRelativeRuntimePath,
|
|
14
|
+
createMatchPath: () => createMatchPath,
|
|
32
15
|
registerPaths: () => registerPaths
|
|
33
16
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
17
|
+
const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
|
|
18
|
+
const _os = /* @__PURE__ */ _interop_require_wildcard(require("os"));
|
|
19
|
+
const _fs = /* @__PURE__ */ _interop_require_default(require("fs"));
|
|
20
|
+
const _module = /* @__PURE__ */ _interop_require_default(require("module"));
|
|
21
|
+
function _interop_require_default(obj) {
|
|
22
|
+
return obj && obj.__esModule ? obj : {
|
|
23
|
+
default: obj
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
27
|
+
if (typeof WeakMap !== "function")
|
|
28
|
+
return null;
|
|
29
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
31
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
32
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
33
|
+
})(nodeInterop);
|
|
34
|
+
}
|
|
35
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
36
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
37
|
+
return obj;
|
|
38
|
+
}
|
|
39
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
40
|
+
return {
|
|
41
|
+
default: obj
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
45
|
+
if (cache && cache.has(obj)) {
|
|
46
|
+
return cache.get(obj);
|
|
47
|
+
}
|
|
48
|
+
var newObj = {};
|
|
49
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
50
|
+
for (var key in obj) {
|
|
51
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
52
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
53
|
+
if (desc && (desc.get || desc.set)) {
|
|
54
|
+
Object.defineProperty(newObj, key, desc);
|
|
55
|
+
} else {
|
|
56
|
+
newObj[key] = obj[key];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
newObj.default = obj;
|
|
61
|
+
if (cache) {
|
|
62
|
+
cache.set(obj, newObj);
|
|
63
|
+
}
|
|
64
|
+
return newObj;
|
|
65
|
+
}
|
|
39
66
|
const getRelativeRuntimePath = (appDirectory, serverRuntimePath) => {
|
|
40
67
|
let relativeRuntimePath = "";
|
|
41
|
-
if (
|
|
42
|
-
relativeRuntimePath = `../${
|
|
43
|
-
appDirectory,
|
|
44
|
-
serverRuntimePath
|
|
45
|
-
)}`;
|
|
68
|
+
if (_os.platform() === "win32") {
|
|
69
|
+
relativeRuntimePath = `../${_path.relative(appDirectory, serverRuntimePath)}`;
|
|
46
70
|
} else {
|
|
47
|
-
relativeRuntimePath =
|
|
48
|
-
"../",
|
|
49
|
-
path.relative(appDirectory, serverRuntimePath)
|
|
50
|
-
);
|
|
71
|
+
relativeRuntimePath = _path.join("../", _path.relative(appDirectory, serverRuntimePath));
|
|
51
72
|
}
|
|
52
73
|
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
53
|
-
relativeRuntimePath = `./${
|
|
74
|
+
relativeRuntimePath = `./${_path.relative(appDirectory, serverRuntimePath)}`;
|
|
54
75
|
}
|
|
55
76
|
return relativeRuntimePath;
|
|
56
77
|
};
|
|
@@ -70,12 +91,14 @@ const createMatchPath = (paths) => {
|
|
|
70
91
|
if (found) {
|
|
71
92
|
let foundPaths = sortedPaths[found];
|
|
72
93
|
if (!Array.isArray(foundPaths)) {
|
|
73
|
-
foundPaths = [
|
|
94
|
+
foundPaths = [
|
|
95
|
+
foundPaths
|
|
96
|
+
];
|
|
74
97
|
}
|
|
75
|
-
foundPaths = foundPaths.filter((foundPath) =>
|
|
98
|
+
foundPaths = foundPaths.filter((foundPath) => _path.isAbsolute(foundPath));
|
|
76
99
|
for (const p of foundPaths) {
|
|
77
100
|
const foundPath = request.replace(found, p);
|
|
78
|
-
if (
|
|
101
|
+
if (_fs.default.existsSync(foundPath)) {
|
|
79
102
|
return foundPath;
|
|
80
103
|
}
|
|
81
104
|
}
|
|
@@ -85,27 +108,24 @@ const createMatchPath = (paths) => {
|
|
|
85
108
|
};
|
|
86
109
|
};
|
|
87
110
|
const registerPaths = (paths) => {
|
|
88
|
-
const originalResolveFilename =
|
|
89
|
-
const { builtinModules } =
|
|
111
|
+
const originalResolveFilename = _module.default._resolveFilename;
|
|
112
|
+
const { builtinModules } = _module.default;
|
|
90
113
|
const matchPath = createMatchPath(paths);
|
|
91
|
-
|
|
114
|
+
_module.default._resolveFilename = function(request, _parent) {
|
|
92
115
|
const isCoreModule = builtinModules.includes(request);
|
|
93
116
|
if (!isCoreModule) {
|
|
94
117
|
const matched = matchPath(request);
|
|
95
118
|
if (matched) {
|
|
96
|
-
const modifiedArguments = [
|
|
119
|
+
const modifiedArguments = [
|
|
120
|
+
matched,
|
|
121
|
+
...[].slice.call(arguments, 1)
|
|
122
|
+
];
|
|
97
123
|
return originalResolveFilename.apply(this, modifiedArguments);
|
|
98
124
|
}
|
|
99
125
|
}
|
|
100
126
|
return originalResolveFilename.apply(this, arguments);
|
|
101
127
|
};
|
|
102
128
|
return () => {
|
|
103
|
-
|
|
129
|
+
_module.default._resolveFilename = originalResolveFilename;
|
|
104
130
|
};
|
|
105
131
|
};
|
|
106
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
-
0 && (module.exports = {
|
|
108
|
-
createMatchPath,
|
|
109
|
-
getRelativeRuntimePath,
|
|
110
|
-
registerPaths
|
|
111
|
-
});
|
package/dist/cjs/utils/debug.js
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var debug_exports = {};
|
|
19
|
-
__export(debug_exports, {
|
|
20
|
-
debug: () => debug
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
21
4
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
-
0 && (module.exports = {
|
|
27
|
-
debug
|
|
5
|
+
Object.defineProperty(exports, "debug", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => debug
|
|
28
8
|
});
|
|
9
|
+
const _utils = require("@modern-js/utils");
|
|
10
|
+
const debug = (0, _utils.createDebugger)("bff");
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var utils_exports = {};
|
|
20
|
-
__export(utils_exports, {
|
|
21
|
-
debug: () => import_debug.debug
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
22
4
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var import_debug = require("./debug");
|
|
27
|
-
__reExport(utils_exports, require("./meta"), module.exports);
|
|
28
|
-
__reExport(utils_exports, require("./validate"), module.exports);
|
|
29
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
-
0 && (module.exports = {
|
|
31
|
-
debug
|
|
5
|
+
Object.defineProperty(exports, "debug", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _debug.debug
|
|
32
8
|
});
|
|
9
|
+
_export_star(require("./storage"), exports);
|
|
10
|
+
_export_star(require("./alias"), exports);
|
|
11
|
+
const _debug = require("./debug");
|
|
12
|
+
_export_star(require("./meta"), exports);
|
|
13
|
+
_export_star(require("./validate"), exports);
|
|
14
|
+
function _export_star(from, to) {
|
|
15
|
+
Object.keys(from).forEach(function(k) {
|
|
16
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
17
|
+
Object.defineProperty(to, k, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return from[k];
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return from;
|
|
26
|
+
}
|
package/dist/cjs/utils/meta.js
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
6
|
for (var name in all)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var meta_exports = {};
|
|
19
|
-
__export(meta_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
20
13
|
HANDLER_WITH_META: () => HANDLER_WITH_META,
|
|
21
14
|
INPUT_PARAMS_DECIDER: () => INPUT_PARAMS_DECIDER,
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
isWithMetaHandler: () => isWithMetaHandler,
|
|
16
|
+
isInputParamsDeciderHandler: () => isInputParamsDeciderHandler
|
|
24
17
|
});
|
|
25
|
-
module.exports = __toCommonJS(meta_exports);
|
|
26
18
|
const HANDLER_WITH_META = "HANDLER_WITH_META";
|
|
27
19
|
const INPUT_PARAMS_DECIDER = "INPUT_PARAMS_DECIDER";
|
|
28
20
|
const isWithMetaHandler = (handler) => {
|
|
@@ -31,10 +23,3 @@ const isWithMetaHandler = (handler) => {
|
|
|
31
23
|
const isInputParamsDeciderHandler = (handler) => {
|
|
32
24
|
return typeof handler === "function" && handler[INPUT_PARAMS_DECIDER];
|
|
33
25
|
};
|
|
34
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
-
0 && (module.exports = {
|
|
36
|
-
HANDLER_WITH_META,
|
|
37
|
-
INPUT_PARAMS_DECIDER,
|
|
38
|
-
isInputParamsDeciderHandler,
|
|
39
|
-
isWithMetaHandler
|
|
40
|
-
});
|
|
@@ -1,40 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var storage_exports = {};
|
|
29
|
-
__export(storage_exports, {
|
|
30
|
-
createStorage: () => createStorage
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
31
4
|
});
|
|
32
|
-
|
|
33
|
-
|
|
5
|
+
Object.defineProperty(exports, "createStorage", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => createStorage
|
|
8
|
+
});
|
|
9
|
+
const _async_hooks = /* @__PURE__ */ _interop_require_wildcard(require("async_hooks"));
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
11
|
+
if (typeof WeakMap !== "function")
|
|
12
|
+
return null;
|
|
13
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
14
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
15
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
16
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
17
|
+
})(nodeInterop);
|
|
18
|
+
}
|
|
19
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
20
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
23
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
24
|
+
return {
|
|
25
|
+
default: obj
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
29
|
+
if (cache && cache.has(obj)) {
|
|
30
|
+
return cache.get(obj);
|
|
31
|
+
}
|
|
32
|
+
var newObj = {};
|
|
33
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
34
|
+
for (var key in obj) {
|
|
35
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
36
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
37
|
+
if (desc && (desc.get || desc.set)) {
|
|
38
|
+
Object.defineProperty(newObj, key, desc);
|
|
39
|
+
} else {
|
|
40
|
+
newObj[key] = obj[key];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
newObj.default = obj;
|
|
45
|
+
if (cache) {
|
|
46
|
+
cache.set(obj, newObj);
|
|
47
|
+
}
|
|
48
|
+
return newObj;
|
|
49
|
+
}
|
|
34
50
|
const createStorage = () => {
|
|
35
51
|
let storage;
|
|
36
|
-
if (typeof
|
|
37
|
-
storage = new
|
|
52
|
+
if (typeof _async_hooks.AsyncLocalStorage !== "undefined") {
|
|
53
|
+
storage = new _async_hooks.AsyncLocalStorage();
|
|
38
54
|
}
|
|
39
55
|
const run = (context, cb) => {
|
|
40
56
|
if (!storage) {
|
|
@@ -58,9 +74,7 @@ const createStorage = () => {
|
|
|
58
74
|
}
|
|
59
75
|
const context = storage.getStore();
|
|
60
76
|
if (!context) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
`Can't call useContext out of scope, it should be placed in the bff function`
|
|
63
|
-
);
|
|
77
|
+
throw new Error(`Can't call useContext out of scope, it should be placed in the bff function`);
|
|
64
78
|
}
|
|
65
79
|
return context;
|
|
66
80
|
};
|
|
@@ -69,7 +83,3 @@ const createStorage = () => {
|
|
|
69
83
|
useContext
|
|
70
84
|
};
|
|
71
85
|
};
|
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
73
|
-
0 && (module.exports = {
|
|
74
|
-
createStorage
|
|
75
|
-
});
|
|
@@ -1,54 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
8
6
|
for (var name in all)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var validate_exports = {};
|
|
29
|
-
__export(validate_exports, {
|
|
30
|
-
ERR_INVALID_ARG_TYPE: () => ERR_INVALID_ARG_TYPE,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
31
13
|
getTypeErrorMessage: () => getTypeErrorMessage,
|
|
14
|
+
ERR_INVALID_ARG_TYPE: () => ERR_INVALID_ARG_TYPE,
|
|
32
15
|
validateFunction: () => validateFunction
|
|
33
16
|
});
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
const _util = /* @__PURE__ */ _interop_require_default(require("util"));
|
|
18
|
+
function _interop_require_default(obj) {
|
|
19
|
+
return obj && obj.__esModule ? obj : {
|
|
20
|
+
default: obj
|
|
21
|
+
};
|
|
22
|
+
}
|
|
36
23
|
const getTypeErrorMessage = (actual) => {
|
|
37
|
-
var _a;
|
|
38
24
|
let msg = "";
|
|
39
25
|
if (actual == null) {
|
|
40
26
|
msg += `. Received ${actual}`;
|
|
41
27
|
} else if (typeof actual === "function" && actual.name) {
|
|
42
28
|
msg += `. Received function ${actual.name}`;
|
|
43
29
|
} else if (typeof actual === "object") {
|
|
44
|
-
|
|
30
|
+
var _actual_constructor;
|
|
31
|
+
if ((_actual_constructor = actual.constructor) === null || _actual_constructor === void 0 ? void 0 : _actual_constructor.name) {
|
|
45
32
|
msg += `. Received an instance of ${actual.constructor.name}`;
|
|
46
33
|
} else {
|
|
47
|
-
const inspected =
|
|
34
|
+
const inspected = _util.default.inspect(actual, {
|
|
35
|
+
depth: -1
|
|
36
|
+
});
|
|
48
37
|
msg += `. Received ${inspected}`;
|
|
49
38
|
}
|
|
50
39
|
} else {
|
|
51
|
-
let inspected =
|
|
40
|
+
let inspected = _util.default.inspect(actual, {
|
|
41
|
+
colors: false
|
|
42
|
+
});
|
|
52
43
|
if (inspected.length > 25) {
|
|
53
44
|
inspected = `${inspected.slice(0, 25)}...`;
|
|
54
45
|
}
|
|
@@ -58,9 +49,7 @@ const getTypeErrorMessage = (actual) => {
|
|
|
58
49
|
};
|
|
59
50
|
class ERR_INVALID_ARG_TYPE extends Error {
|
|
60
51
|
constructor(funcName, expectedType, actual) {
|
|
61
|
-
const message = `[ERR_INVALID_ARG_TYPE]: The '${funcName}' argument must be of type ${expectedType}${getTypeErrorMessage(
|
|
62
|
-
actual
|
|
63
|
-
)}`;
|
|
52
|
+
const message = `[ERR_INVALID_ARG_TYPE]: The '${funcName}' argument must be of type ${expectedType}${getTypeErrorMessage(actual)}`;
|
|
64
53
|
super(message);
|
|
65
54
|
}
|
|
66
55
|
}
|
|
@@ -70,9 +59,3 @@ const validateFunction = (maybeFunc, name) => {
|
|
|
70
59
|
}
|
|
71
60
|
return true;
|
|
72
61
|
};
|
|
73
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
-
0 && (module.exports = {
|
|
75
|
-
ERR_INVALID_ARG_TYPE,
|
|
76
|
-
getTypeErrorMessage,
|
|
77
|
-
validateFunction
|
|
78
|
-
});
|
package/dist/esm/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import compose from "koa-compose";
|
|
3
3
|
import { validateFunction, HANDLER_WITH_META } from "./utils";
|
|
4
|
-
function Api(...args) {
|
|
4
|
+
export function Api(...args) {
|
|
5
5
|
const handler = args.pop();
|
|
6
6
|
validateFunction(handler, "Apihandler");
|
|
7
7
|
const operators = args;
|
|
@@ -30,7 +30,10 @@ function Api(...args) {
|
|
|
30
30
|
inputs = val;
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
-
const stack = [
|
|
33
|
+
const stack = [
|
|
34
|
+
...validateHandlers,
|
|
35
|
+
...pipeHandlers
|
|
36
|
+
];
|
|
34
37
|
stack.push(async (helper, next) => {
|
|
35
38
|
const res = await handler(helper.inputs);
|
|
36
39
|
helper.result = res;
|
|
@@ -42,6 +45,3 @@ function Api(...args) {
|
|
|
42
45
|
runner[HANDLER_WITH_META] = true;
|
|
43
46
|
return runner;
|
|
44
47
|
}
|
|
45
|
-
export {
|
|
46
|
-
Api
|
|
47
|
-
};
|
|
@@ -1,33 +1,17 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { ApiRouter } from "../router";
|
|
3
3
|
import { Ok, Err } from "./result";
|
|
4
|
-
const DEFAULT_CLIENT_REQUEST_CREATOR = "@modern-js/create-request";
|
|
5
|
-
const generateClient = async ({
|
|
6
|
-
resourcePath,
|
|
7
|
-
apiDir,
|
|
8
|
-
lambdaDir,
|
|
9
|
-
prefix,
|
|
10
|
-
port,
|
|
11
|
-
target,
|
|
12
|
-
requestCreator,
|
|
13
|
-
fetcher,
|
|
14
|
-
requireResolve = require.resolve,
|
|
15
|
-
httpMethodDecider
|
|
16
|
-
}) => {
|
|
4
|
+
export const DEFAULT_CLIENT_REQUEST_CREATOR = "@modern-js/create-request";
|
|
5
|
+
export const generateClient = async ({ resourcePath, apiDir, lambdaDir, prefix, port, target, requestCreator, fetcher, requireResolve = require.resolve, httpMethodDecider }) => {
|
|
17
6
|
if (!requestCreator) {
|
|
18
|
-
requestCreator = requireResolve(
|
|
19
|
-
`${DEFAULT_CLIENT_REQUEST_CREATOR}${target ? `/${target}` : ""}`
|
|
20
|
-
).replace(/\\/g, "/");
|
|
7
|
+
requestCreator = requireResolve(`${DEFAULT_CLIENT_REQUEST_CREATOR}${target ? `/${target}` : ""}`).replace(/\\/g, "/");
|
|
21
8
|
} else {
|
|
22
9
|
let resolvedPath = requestCreator;
|
|
23
10
|
try {
|
|
24
11
|
resolvedPath = path.dirname(requireResolve(requestCreator));
|
|
25
12
|
} catch (error) {
|
|
26
13
|
}
|
|
27
|
-
requestCreator = `${resolvedPath}${target ? `/${target}` : ""}`.replace(
|
|
28
|
-
/\\/g,
|
|
29
|
-
"/"
|
|
30
|
-
);
|
|
14
|
+
requestCreator = `${resolvedPath}${target ? `/${target}` : ""}`.replace(/\\/g, "/");
|
|
31
15
|
}
|
|
32
16
|
const apiRouter = new ApiRouter({
|
|
33
17
|
apiDir,
|
|
@@ -49,14 +33,10 @@ const generateClient = async ({
|
|
|
49
33
|
const upperHttpMethod = httpMethod.toUpperCase();
|
|
50
34
|
const routeName = routePath;
|
|
51
35
|
if (target === "server") {
|
|
52
|
-
handlersCode += `export ${exportStatement} createRequest('${routeName}', '${upperHttpMethod}', process.env.PORT || ${String(
|
|
53
|
-
port
|
|
54
|
-
)}, '${httpMethodDecider ? httpMethodDecider : "functionName"}' ${fetcher ? `, fetch` : ""});
|
|
36
|
+
handlersCode += `export ${exportStatement} createRequest('${routeName}', '${upperHttpMethod}', process.env.PORT || ${String(port)}, '${httpMethodDecider ? httpMethodDecider : "functionName"}' ${fetcher ? `, fetch` : ""});
|
|
55
37
|
`;
|
|
56
38
|
} else {
|
|
57
|
-
handlersCode += `export ${exportStatement} createRequest('${routeName}', '${upperHttpMethod}', ${String(
|
|
58
|
-
port
|
|
59
|
-
)}, '${httpMethodDecider ? httpMethodDecider : "functionName"}' ${fetcher ? `, fetch` : ""});
|
|
39
|
+
handlersCode += `export ${exportStatement} createRequest('${routeName}', '${upperHttpMethod}', ${String(port)}, '${httpMethodDecider ? httpMethodDecider : "functionName"}' ${fetcher ? `, fetch` : ""});
|
|
60
40
|
`;
|
|
61
41
|
}
|
|
62
42
|
}
|
|
@@ -66,7 +46,3 @@ ${fetcher ? `import { fetch } from '${fetcher}';
|
|
|
66
46
|
return Ok(`${importCode}
|
|
67
47
|
${handlersCode}`);
|
|
68
48
|
};
|
|
69
|
-
export {
|
|
70
|
-
DEFAULT_CLIENT_REQUEST_CREATOR,
|
|
71
|
-
generateClient
|
|
72
|
-
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const Err = (value) => {
|
|
1
|
+
export const Err = (value) => {
|
|
2
2
|
const err = {
|
|
3
3
|
kind: "Err",
|
|
4
4
|
value,
|
|
@@ -7,7 +7,7 @@ const Err = (value) => {
|
|
|
7
7
|
};
|
|
8
8
|
return err;
|
|
9
9
|
};
|
|
10
|
-
const Ok = (value) => {
|
|
10
|
+
export const Ok = (value) => {
|
|
11
11
|
const ok = {
|
|
12
12
|
kind: "Ok",
|
|
13
13
|
value,
|
|
@@ -16,7 +16,3 @@ const Ok = (value) => {
|
|
|
16
16
|
};
|
|
17
17
|
return ok;
|
|
18
18
|
};
|
|
19
|
-
export {
|
|
20
|
-
Err,
|
|
21
|
-
Ok
|
|
22
|
-
};
|