@modern-js/bff-runtime 2.15.0 → 2.16.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 +8 -0
- package/dist/cjs/compatible.js +4 -15
- package/dist/cjs/index.js +29 -31
- package/dist/cjs/match.js +25 -40
- package/dist/cjs/request.js +4 -15
- package/dist/cjs/response.js +11 -25
- package/dist/cjs/types.js +4 -15
- package/dist/esm/compatible.js +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/match.js +206 -200
- package/dist/esm/request.js +1 -1
- package/dist/esm/response.js +15 -16
- package/dist/esm/types.js +1 -1
- package/dist/esm-node/compatible.js +1 -0
- package/dist/esm-node/index.js +1 -6
- package/dist/esm-node/match.js +10 -26
- package/dist/esm-node/request.js +1 -0
- package/dist/esm-node/response.js +3 -8
- package/dist/esm-node/types.js +1 -0
- package/package.json +8 -4
package/CHANGELOG.md
CHANGED
package/dist/cjs/compatible.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var compatible_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(compatible_exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
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 src_exports = {};
|
|
20
|
-
__export(src_exports, {
|
|
21
|
-
isHandler: () => import_match.isHandler,
|
|
22
|
-
isSchemaHandler: () => import_match.isSchemaHandler,
|
|
23
|
-
match: () => import_match.match
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
match: () => _match.match,
|
|
14
|
+
isHandler: () => _match.isHandler,
|
|
15
|
+
isSchemaHandler: () => _match.isSchemaHandler
|
|
33
16
|
});
|
|
17
|
+
_export_star(require("farrow-schema"), exports);
|
|
18
|
+
const _match = require("./match");
|
|
19
|
+
function _export_star(from, to) {
|
|
20
|
+
Object.keys(from).forEach(function(k) {
|
|
21
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
22
|
+
Object.defineProperty(to, k, {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function() {
|
|
25
|
+
return from[k];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return from;
|
|
31
|
+
}
|
package/dist/cjs/match.js
CHANGED
|
@@ -1,31 +1,23 @@
|
|
|
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 match_exports = {};
|
|
19
|
-
__export(match_exports, {
|
|
20
|
-
baseMatch: () => baseMatch,
|
|
21
|
-
isHandler: () => isHandler,
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
22
13
|
isSchemaHandler: () => isSchemaHandler,
|
|
14
|
+
isHandler: () => isHandler,
|
|
15
|
+
baseMatch: () => baseMatch,
|
|
23
16
|
match: () => match
|
|
24
17
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var import_response = require("./response");
|
|
18
|
+
const _farrowschema = require("farrow-schema");
|
|
19
|
+
const _validator = require("farrow-schema/validator");
|
|
20
|
+
const _response = require("./response");
|
|
29
21
|
const getErrorMessage = (error) => {
|
|
30
22
|
let { message } = error;
|
|
31
23
|
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
@@ -35,24 +27,24 @@ ${message}`;
|
|
|
35
27
|
return message;
|
|
36
28
|
};
|
|
37
29
|
const HANDLER_WITH_SCHEMA = "HANDLER_WITH_SCHEMA";
|
|
38
|
-
const isSchemaHandler = (input) =>
|
|
30
|
+
const isSchemaHandler = (input) => {
|
|
31
|
+
return input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
32
|
+
};
|
|
39
33
|
const isHandler = (input) => input && typeof input === "function";
|
|
40
34
|
const baseMatch = (schema, handler) => {
|
|
41
35
|
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
42
|
-
const validateApiOutput = (0,
|
|
43
|
-
(0, import_farrow_schema.toSchemaCtor)(schema.response)
|
|
44
|
-
);
|
|
36
|
+
const validateApiOutput = (0, _validator.createSchemaValidator)((0, _farrowschema.toSchemaCtor)(schema.response));
|
|
45
37
|
const handle = async (input) => {
|
|
46
38
|
const inputResult = validateApiInput(input);
|
|
47
39
|
if (inputResult.isErr) {
|
|
48
|
-
return (0,
|
|
40
|
+
return (0, _response.InputValidationError)(getErrorMessage(inputResult.value));
|
|
49
41
|
}
|
|
50
42
|
const output = await handler(input);
|
|
51
43
|
const outputResult = validateApiOutput(output);
|
|
52
44
|
if (outputResult.isErr) {
|
|
53
|
-
return (0,
|
|
45
|
+
return (0, _response.OutputValidationError)(getErrorMessage(outputResult.value));
|
|
54
46
|
}
|
|
55
|
-
return (0,
|
|
47
|
+
return (0, _response.HandleSuccess)(output);
|
|
56
48
|
};
|
|
57
49
|
return Object.assign(handle, {
|
|
58
50
|
schema,
|
|
@@ -77,13 +69,6 @@ const createRequestSchemaValidator = (schema) => {
|
|
|
77
69
|
if (schema.cookies) {
|
|
78
70
|
descriptors.cookies = schema.cookies;
|
|
79
71
|
}
|
|
80
|
-
const RequestStruct = (0,
|
|
81
|
-
return (0,
|
|
72
|
+
const RequestStruct = (0, _farrowschema.Struct)(descriptors);
|
|
73
|
+
return (0, _validator.createSchemaValidator)((0, _farrowschema.NonStrict)(RequestStruct));
|
|
82
74
|
};
|
|
83
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
-
0 && (module.exports = {
|
|
85
|
-
baseMatch,
|
|
86
|
-
isHandler,
|
|
87
|
-
isSchemaHandler,
|
|
88
|
-
match
|
|
89
|
-
});
|
package/dist/cjs/request.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var request_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(request_exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
package/dist/cjs/response.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
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 response_exports = {};
|
|
19
|
-
__export(response_exports, {
|
|
7
|
+
Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
20
13
|
HandleSuccess: () => HandleSuccess,
|
|
21
14
|
InputValidationError: () => InputValidationError,
|
|
22
15
|
OutputValidationError: () => OutputValidationError
|
|
23
16
|
});
|
|
24
|
-
module.exports = __toCommonJS(response_exports);
|
|
25
17
|
const HandleSuccess = (output) => ({
|
|
26
18
|
type: "HandleSuccess",
|
|
27
19
|
value: output
|
|
@@ -34,9 +26,3 @@ const OutputValidationError = (message) => ({
|
|
|
34
26
|
type: "OutputValidationError",
|
|
35
27
|
message
|
|
36
28
|
});
|
|
37
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
-
0 && (module.exports = {
|
|
39
|
-
HandleSuccess,
|
|
40
|
-
InputValidationError,
|
|
41
|
-
OutputValidationError
|
|
42
|
-
});
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
-
for (let key of __getOwnPropNames(from))
|
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
-
}
|
|
11
|
-
return to;
|
|
12
|
-
};
|
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var types_exports = {};
|
|
15
|
-
module.exports = __toCommonJS(types_exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
package/dist/esm/compatible.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/dist/esm/index.js
CHANGED
package/dist/esm/match.js
CHANGED
|
@@ -1,220 +1,226 @@
|
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(void 0);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
42
|
}
|
|
43
|
-
var __generator =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
var __generator = function(thisArg, body) {
|
|
44
|
+
var f, y, t, g, _ = {
|
|
45
|
+
label: 0,
|
|
46
|
+
sent: function() {
|
|
47
|
+
if (t[0] & 1)
|
|
48
|
+
throw t[1];
|
|
49
|
+
return t[1];
|
|
50
|
+
},
|
|
51
|
+
trys: [],
|
|
52
|
+
ops: []
|
|
53
|
+
};
|
|
54
|
+
return g = {
|
|
55
|
+
next: verb(0),
|
|
56
|
+
"throw": verb(1),
|
|
57
|
+
"return": verb(2)
|
|
58
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
59
|
+
return this;
|
|
60
|
+
}), g;
|
|
61
|
+
function verb(n) {
|
|
62
|
+
return function(v) {
|
|
63
|
+
return step([
|
|
64
|
+
n,
|
|
65
|
+
v
|
|
66
|
+
]);
|
|
52
67
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
break;
|
|
81
|
-
case 4:
|
|
82
|
-
_.label++;
|
|
83
|
-
return {
|
|
84
|
-
value: op[1],
|
|
85
|
-
done: false
|
|
86
|
-
};
|
|
87
|
-
case 5:
|
|
88
|
-
_.label++;
|
|
89
|
-
y = op[1];
|
|
90
|
-
op = [
|
|
91
|
-
0
|
|
92
|
-
];
|
|
93
|
-
continue;
|
|
94
|
-
case 7:
|
|
95
|
-
op = _.ops.pop();
|
|
96
|
-
_.trys.pop();
|
|
97
|
-
continue;
|
|
98
|
-
default:
|
|
99
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
100
|
-
_ = 0;
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
104
|
-
_.label = op[1];
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
108
|
-
_.label = t[1];
|
|
109
|
-
t = op;
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
if (t && _.label < t[2]) {
|
|
113
|
-
_.label = t[2];
|
|
114
|
-
_.ops.push(op);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
if (t[2]) _.ops.pop();
|
|
118
|
-
_.trys.pop();
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
op = body.call(thisArg, _);
|
|
122
|
-
} catch (e) {
|
|
68
|
+
}
|
|
69
|
+
function step(op) {
|
|
70
|
+
if (f)
|
|
71
|
+
throw new TypeError("Generator is already executing.");
|
|
72
|
+
while (_)
|
|
73
|
+
try {
|
|
74
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
75
|
+
return t;
|
|
76
|
+
if (y = 0, t)
|
|
77
|
+
op = [
|
|
78
|
+
op[0] & 2,
|
|
79
|
+
t.value
|
|
80
|
+
];
|
|
81
|
+
switch (op[0]) {
|
|
82
|
+
case 0:
|
|
83
|
+
case 1:
|
|
84
|
+
t = op;
|
|
85
|
+
break;
|
|
86
|
+
case 4:
|
|
87
|
+
_.label++;
|
|
88
|
+
return {
|
|
89
|
+
value: op[1],
|
|
90
|
+
done: false
|
|
91
|
+
};
|
|
92
|
+
case 5:
|
|
93
|
+
_.label++;
|
|
94
|
+
y = op[1];
|
|
123
95
|
op = [
|
|
124
|
-
|
|
125
|
-
e
|
|
96
|
+
0
|
|
126
97
|
];
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
98
|
+
continue;
|
|
99
|
+
case 7:
|
|
100
|
+
op = _.ops.pop();
|
|
101
|
+
_.trys.pop();
|
|
102
|
+
continue;
|
|
103
|
+
default:
|
|
104
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
105
|
+
_ = 0;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
109
|
+
_.label = op[1];
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
113
|
+
_.label = t[1];
|
|
114
|
+
t = op;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (t && _.label < t[2]) {
|
|
118
|
+
_.label = t[2];
|
|
119
|
+
_.ops.push(op);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (t[2])
|
|
123
|
+
_.ops.pop();
|
|
124
|
+
_.trys.pop();
|
|
125
|
+
continue;
|
|
130
126
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
127
|
+
op = body.call(thisArg, _);
|
|
128
|
+
} catch (e) {
|
|
129
|
+
op = [
|
|
130
|
+
6,
|
|
131
|
+
e
|
|
132
|
+
];
|
|
133
|
+
y = 0;
|
|
134
|
+
} finally {
|
|
135
|
+
f = t = 0;
|
|
136
|
+
}
|
|
137
|
+
if (op[0] & 5)
|
|
138
|
+
throw op[1];
|
|
139
|
+
return {
|
|
140
|
+
value: op[0] ? op[1] : void 0,
|
|
141
|
+
done: true
|
|
142
|
+
};
|
|
143
|
+
}
|
|
137
144
|
};
|
|
138
145
|
import { toSchemaCtor, Struct, NonStrict } from "farrow-schema";
|
|
139
146
|
import { createSchemaValidator } from "farrow-schema/validator";
|
|
140
147
|
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
|
|
141
148
|
var getErrorMessage = function(error) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
149
|
+
var message = error.message;
|
|
150
|
+
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
151
|
+
message = "path: ".concat(JSON.stringify(error.path), "\n").concat(message);
|
|
152
|
+
}
|
|
153
|
+
return message;
|
|
147
154
|
};
|
|
148
155
|
var HANDLER_WITH_SCHEMA = "HANDLER_WITH_SCHEMA";
|
|
149
|
-
var isSchemaHandler = function(input) {
|
|
150
|
-
|
|
156
|
+
export var isSchemaHandler = function(input) {
|
|
157
|
+
return input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
151
158
|
};
|
|
152
|
-
var isHandler = function(input) {
|
|
153
|
-
|
|
159
|
+
export var isHandler = function(input) {
|
|
160
|
+
return input && typeof input === "function";
|
|
154
161
|
};
|
|
155
|
-
var baseMatch = function(schema, handler) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
162
|
+
export var baseMatch = function(schema, handler) {
|
|
163
|
+
var validateApiInput = createRequestSchemaValidator(schema.request);
|
|
164
|
+
var validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
165
|
+
var handle = function() {
|
|
166
|
+
var _ref = _async_to_generator(function(input) {
|
|
167
|
+
var inputResult, output, outputResult;
|
|
168
|
+
return __generator(this, function(_state) {
|
|
169
|
+
switch (_state.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
inputResult = validateApiInput(input);
|
|
172
|
+
if (inputResult.isErr) {
|
|
173
|
+
return [
|
|
174
|
+
2,
|
|
175
|
+
InputValidationError(getErrorMessage(inputResult.value))
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
return [
|
|
179
|
+
4,
|
|
180
|
+
handler(input)
|
|
181
|
+
];
|
|
182
|
+
case 1:
|
|
183
|
+
output = _state.sent();
|
|
184
|
+
outputResult = validateApiOutput(output);
|
|
185
|
+
if (outputResult.isErr) {
|
|
186
|
+
return [
|
|
187
|
+
2,
|
|
188
|
+
OutputValidationError(getErrorMessage(outputResult.value))
|
|
189
|
+
];
|
|
190
|
+
}
|
|
191
|
+
return [
|
|
192
|
+
2,
|
|
193
|
+
HandleSuccess(output)
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
return function handle2(input) {
|
|
199
|
+
return _ref.apply(this, arguments);
|
|
200
|
+
};
|
|
201
|
+
}();
|
|
202
|
+
return Object.assign(handle, _define_property({
|
|
203
|
+
schema
|
|
204
|
+
}, HANDLER_WITH_SCHEMA, true));
|
|
198
205
|
};
|
|
199
|
-
var match = baseMatch;
|
|
206
|
+
export var match = baseMatch;
|
|
200
207
|
var createRequestSchemaValidator = function(schema) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
208
|
+
var descriptors = {};
|
|
209
|
+
if (schema.params) {
|
|
210
|
+
descriptors.params = schema.params;
|
|
211
|
+
}
|
|
212
|
+
if (schema.query) {
|
|
213
|
+
descriptors.query = schema.query;
|
|
214
|
+
}
|
|
215
|
+
if (schema.data) {
|
|
216
|
+
descriptors.data = schema.data;
|
|
217
|
+
}
|
|
218
|
+
if (schema.headers) {
|
|
219
|
+
descriptors.headers = schema.headers;
|
|
220
|
+
}
|
|
221
|
+
if (schema.cookies) {
|
|
222
|
+
descriptors.cookies = schema.cookies;
|
|
223
|
+
}
|
|
224
|
+
var RequestStruct = Struct(descriptors);
|
|
225
|
+
return createSchemaValidator(NonStrict(RequestStruct));
|
|
219
226
|
};
|
|
220
|
-
export { baseMatch, isHandler, isSchemaHandler, match };
|
package/dist/esm/request.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
package/dist/esm/response.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
var HandleSuccess = function(output) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export var HandleSuccess = function(output) {
|
|
2
|
+
return {
|
|
3
|
+
type: "HandleSuccess",
|
|
4
|
+
value: output
|
|
5
|
+
};
|
|
6
6
|
};
|
|
7
|
-
var InputValidationError = function(message) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export var InputValidationError = function(message) {
|
|
8
|
+
return {
|
|
9
|
+
type: "InputValidationError",
|
|
10
|
+
message
|
|
11
|
+
};
|
|
12
12
|
};
|
|
13
|
-
var OutputValidationError = function(message) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
export var OutputValidationError = function(message) {
|
|
14
|
+
return {
|
|
15
|
+
type: "OutputValidationError",
|
|
16
|
+
message
|
|
17
|
+
};
|
|
18
18
|
};
|
|
19
|
-
export { HandleSuccess, InputValidationError, OutputValidationError };
|
package/dist/esm/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm-node/index.js
CHANGED
package/dist/esm-node/match.js
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
NonStrict
|
|
5
|
-
} from "farrow-schema";
|
|
6
|
-
import {
|
|
7
|
-
createSchemaValidator
|
|
8
|
-
} from "farrow-schema/validator";
|
|
9
|
-
import {
|
|
10
|
-
HandleSuccess,
|
|
11
|
-
InputValidationError,
|
|
12
|
-
OutputValidationError
|
|
13
|
-
} from "./response";
|
|
1
|
+
import { toSchemaCtor, Struct, NonStrict } from "farrow-schema";
|
|
2
|
+
import { createSchemaValidator } from "farrow-schema/validator";
|
|
3
|
+
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
|
|
14
4
|
const getErrorMessage = (error) => {
|
|
15
5
|
let { message } = error;
|
|
16
6
|
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
@@ -20,13 +10,13 @@ ${message}`;
|
|
|
20
10
|
return message;
|
|
21
11
|
};
|
|
22
12
|
const HANDLER_WITH_SCHEMA = "HANDLER_WITH_SCHEMA";
|
|
23
|
-
const isSchemaHandler = (input) =>
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
export const isSchemaHandler = (input) => {
|
|
14
|
+
return input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
15
|
+
};
|
|
16
|
+
export const isHandler = (input) => input && typeof input === "function";
|
|
17
|
+
export const baseMatch = (schema, handler) => {
|
|
26
18
|
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
27
|
-
const validateApiOutput = createSchemaValidator(
|
|
28
|
-
toSchemaCtor(schema.response)
|
|
29
|
-
);
|
|
19
|
+
const validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
30
20
|
const handle = async (input) => {
|
|
31
21
|
const inputResult = validateApiInput(input);
|
|
32
22
|
if (inputResult.isErr) {
|
|
@@ -44,7 +34,7 @@ const baseMatch = (schema, handler) => {
|
|
|
44
34
|
[HANDLER_WITH_SCHEMA]: true
|
|
45
35
|
});
|
|
46
36
|
};
|
|
47
|
-
const match = baseMatch;
|
|
37
|
+
export const match = baseMatch;
|
|
48
38
|
const createRequestSchemaValidator = (schema) => {
|
|
49
39
|
const descriptors = {};
|
|
50
40
|
if (schema.params) {
|
|
@@ -65,9 +55,3 @@ const createRequestSchemaValidator = (schema) => {
|
|
|
65
55
|
const RequestStruct = Struct(descriptors);
|
|
66
56
|
return createSchemaValidator(NonStrict(RequestStruct));
|
|
67
57
|
};
|
|
68
|
-
export {
|
|
69
|
-
baseMatch,
|
|
70
|
-
isHandler,
|
|
71
|
-
isSchemaHandler,
|
|
72
|
-
match
|
|
73
|
-
};
|
package/dist/esm-node/request.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
const HandleSuccess = (output) => ({
|
|
1
|
+
export const HandleSuccess = (output) => ({
|
|
2
2
|
type: "HandleSuccess",
|
|
3
3
|
value: output
|
|
4
4
|
});
|
|
5
|
-
const InputValidationError = (message) => ({
|
|
5
|
+
export const InputValidationError = (message) => ({
|
|
6
6
|
type: "InputValidationError",
|
|
7
7
|
message
|
|
8
8
|
});
|
|
9
|
-
const OutputValidationError = (message) => ({
|
|
9
|
+
export const OutputValidationError = (message) => ({
|
|
10
10
|
type: "OutputValidationError",
|
|
11
11
|
message
|
|
12
12
|
});
|
|
13
|
-
export {
|
|
14
|
-
HandleSuccess,
|
|
15
|
-
InputValidationError,
|
|
16
|
-
OutputValidationError
|
|
17
|
-
};
|
package/dist/esm-node/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/modern.js/issues",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/web-infra-dev/modern.js",
|
|
9
|
+
"directory": "packages/server/bff-runtime"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"keywords": [
|
|
9
13
|
"react",
|
|
@@ -11,7 +15,7 @@
|
|
|
11
15
|
"modern",
|
|
12
16
|
"modern.js"
|
|
13
17
|
],
|
|
14
|
-
"version": "2.
|
|
18
|
+
"version": "2.16.0",
|
|
15
19
|
"jsnext:source": "./src/index.ts",
|
|
16
20
|
"types": "./dist/types/index.d.ts",
|
|
17
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -38,8 +42,8 @@
|
|
|
38
42
|
"jest": "^29",
|
|
39
43
|
"ts-jest": "^29.0.5",
|
|
40
44
|
"typescript": "^4",
|
|
41
|
-
"@scripts/
|
|
42
|
-
"@scripts/
|
|
45
|
+
"@scripts/jest-config": "2.16.0",
|
|
46
|
+
"@scripts/build": "2.16.0"
|
|
43
47
|
},
|
|
44
48
|
"publishConfig": {
|
|
45
49
|
"registry": "https://registry.npmjs.org/",
|