@modern-js/bff-runtime 2.0.0-beta.3 → 2.0.0-beta.6
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 +12 -0
- package/dist/js/modern/index.js +7 -5
- package/dist/js/modern/match.js +56 -19
- package/dist/js/modern/request.js +0 -1
- package/dist/js/modern/response.js +12 -10
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/compatible.js +15 -0
- package/dist/js/node/index.js +29 -37
- package/dist/js/node/match.js +74 -31
- package/dist/js/node/request.js +15 -5
- package/dist/js/node/response.js +35 -17
- package/dist/js/node/types.js +15 -5
- package/dist/js/treeshaking/compatible.js +1 -0
- package/dist/js/treeshaking/index.js +3 -5
- package/dist/js/treeshaking/match.js +215 -80
- package/dist/js/treeshaking/request.js +1 -1
- package/dist/js/treeshaking/response.js +17 -19
- package/dist/js/treeshaking/types.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/js/modern/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export * from "farrow-schema";
|
|
2
|
+
import { match, isHandler, isSchemaHandler } from "./match";
|
|
3
|
+
export {
|
|
4
|
+
isHandler,
|
|
5
|
+
isSchemaHandler,
|
|
6
|
+
match
|
|
7
|
+
};
|
package/dist/js/modern/match.js
CHANGED
|
@@ -1,40 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import {
|
|
22
|
+
toSchemaCtor,
|
|
23
|
+
Struct,
|
|
24
|
+
NonStrict
|
|
25
|
+
} from "farrow-schema";
|
|
26
|
+
import {
|
|
27
|
+
createSchemaValidator
|
|
28
|
+
} from "farrow-schema/validator";
|
|
29
|
+
import {
|
|
30
|
+
HandleSuccess,
|
|
31
|
+
InputValidationError,
|
|
32
|
+
OutputValidationError
|
|
33
|
+
} from "./response";
|
|
34
|
+
const getErrorMessage = (error) => {
|
|
35
|
+
let { message } = error;
|
|
8
36
|
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
9
|
-
message = `path: ${JSON.stringify(error.path)}
|
|
37
|
+
message = `path: ${JSON.stringify(error.path)}
|
|
38
|
+
${message}`;
|
|
10
39
|
}
|
|
11
40
|
return message;
|
|
12
41
|
};
|
|
13
|
-
const HANDLER_WITH_SCHEMA =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
42
|
+
const HANDLER_WITH_SCHEMA = "HANDLER_WITH_SCHEMA";
|
|
43
|
+
const isSchemaHandler = (input) => input && (input == null ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
44
|
+
const isHandler = (input) => input && typeof input === "function";
|
|
45
|
+
const baseMatch = (schema, handler) => {
|
|
17
46
|
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
18
|
-
const validateApiOutput = createSchemaValidator(
|
|
19
|
-
|
|
47
|
+
const validateApiOutput = createSchemaValidator(
|
|
48
|
+
toSchemaCtor(schema.response)
|
|
49
|
+
);
|
|
50
|
+
const handle = (input) => __async(void 0, null, function* () {
|
|
20
51
|
const inputResult = validateApiInput(input);
|
|
21
52
|
if (inputResult.isErr) {
|
|
22
53
|
return InputValidationError(getErrorMessage(inputResult.value));
|
|
23
54
|
}
|
|
24
|
-
const output =
|
|
55
|
+
const output = yield handler(input);
|
|
25
56
|
const outputResult = validateApiOutput(output);
|
|
26
57
|
if (outputResult.isErr) {
|
|
27
58
|
return OutputValidationError(getErrorMessage(outputResult.value));
|
|
28
59
|
}
|
|
29
60
|
return HandleSuccess(output);
|
|
30
|
-
};
|
|
61
|
+
});
|
|
31
62
|
return Object.assign(handle, {
|
|
32
63
|
schema,
|
|
33
64
|
[HANDLER_WITH_SCHEMA]: true
|
|
34
65
|
});
|
|
35
66
|
};
|
|
36
|
-
|
|
37
|
-
const createRequestSchemaValidator = schema => {
|
|
67
|
+
const match = baseMatch;
|
|
68
|
+
const createRequestSchemaValidator = (schema) => {
|
|
38
69
|
const descriptors = {};
|
|
39
70
|
if (schema.params) {
|
|
40
71
|
descriptors.params = schema.params;
|
|
@@ -53,4 +84,10 @@ const createRequestSchemaValidator = schema => {
|
|
|
53
84
|
}
|
|
54
85
|
const RequestStruct = Struct(descriptors);
|
|
55
86
|
return createSchemaValidator(NonStrict(RequestStruct));
|
|
56
|
-
};
|
|
87
|
+
};
|
|
88
|
+
export {
|
|
89
|
+
baseMatch,
|
|
90
|
+
isHandler,
|
|
91
|
+
isSchemaHandler,
|
|
92
|
+
match
|
|
93
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type: 'HandleSuccess',
|
|
1
|
+
const HandleSuccess = (output) => ({
|
|
2
|
+
type: "HandleSuccess",
|
|
4
3
|
value: output
|
|
5
4
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type: 'InputValidationError',
|
|
5
|
+
const InputValidationError = (message) => ({
|
|
6
|
+
type: "InputValidationError",
|
|
9
7
|
message
|
|
10
8
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type: 'OutputValidationError',
|
|
9
|
+
const OutputValidationError = (message) => ({
|
|
10
|
+
type: "OutputValidationError",
|
|
14
11
|
message
|
|
15
|
-
});
|
|
12
|
+
});
|
|
13
|
+
export {
|
|
14
|
+
HandleSuccess,
|
|
15
|
+
InputValidationError,
|
|
16
|
+
OutputValidationError
|
|
17
|
+
};
|
package/dist/js/modern/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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);
|
package/dist/js/node/index.js
CHANGED
|
@@ -1,41 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
isHandler: true,
|
|
9
|
-
isSchemaHandler: true
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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 });
|
|
10
8
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "isSchemaHandler", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return _match.isSchemaHandler;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports, "match", {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () {
|
|
26
|
-
return _match.match;
|
|
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 });
|
|
27
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
|
|
28
24
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return _farrowSchema[key];
|
|
38
|
-
}
|
|
39
|
-
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
__reExport(src_exports, require("farrow-schema"), module.exports);
|
|
27
|
+
var import_match = require("./match");
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
isHandler,
|
|
31
|
+
isSchemaHandler,
|
|
32
|
+
match
|
|
40
33
|
});
|
|
41
|
-
var _match = require("./match");
|
package/dist/js/node/match.js
CHANGED
|
@@ -1,50 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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 __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var match_exports = {};
|
|
39
|
+
__export(match_exports, {
|
|
40
|
+
baseMatch: () => baseMatch,
|
|
41
|
+
isHandler: () => isHandler,
|
|
42
|
+
isSchemaHandler: () => isSchemaHandler,
|
|
43
|
+
match: () => match
|
|
5
44
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
const getErrorMessage = error => {
|
|
11
|
-
let {
|
|
12
|
-
message
|
|
13
|
-
} = error;
|
|
45
|
+
module.exports = __toCommonJS(match_exports);
|
|
46
|
+
var import_farrow_schema = require("farrow-schema");
|
|
47
|
+
var import_validator = require("farrow-schema/validator");
|
|
48
|
+
var import_response = require("./response");
|
|
49
|
+
const getErrorMessage = (error) => {
|
|
50
|
+
let { message } = error;
|
|
14
51
|
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
15
|
-
message = `path: ${JSON.stringify(error.path)}
|
|
52
|
+
message = `path: ${JSON.stringify(error.path)}
|
|
53
|
+
${message}`;
|
|
16
54
|
}
|
|
17
55
|
return message;
|
|
18
56
|
};
|
|
19
|
-
const HANDLER_WITH_SCHEMA =
|
|
20
|
-
const isSchemaHandler = input => input && (input
|
|
21
|
-
|
|
22
|
-
const isHandler = input => input && typeof input === 'function';
|
|
23
|
-
exports.isHandler = isHandler;
|
|
57
|
+
const HANDLER_WITH_SCHEMA = "HANDLER_WITH_SCHEMA";
|
|
58
|
+
const isSchemaHandler = (input) => input && (input == null ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
59
|
+
const isHandler = (input) => input && typeof input === "function";
|
|
24
60
|
const baseMatch = (schema, handler) => {
|
|
25
61
|
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
26
|
-
const validateApiOutput = (0,
|
|
27
|
-
|
|
62
|
+
const validateApiOutput = (0, import_validator.createSchemaValidator)(
|
|
63
|
+
(0, import_farrow_schema.toSchemaCtor)(schema.response)
|
|
64
|
+
);
|
|
65
|
+
const handle = (input) => __async(void 0, null, function* () {
|
|
28
66
|
const inputResult = validateApiInput(input);
|
|
29
67
|
if (inputResult.isErr) {
|
|
30
|
-
return (0,
|
|
68
|
+
return (0, import_response.InputValidationError)(getErrorMessage(inputResult.value));
|
|
31
69
|
}
|
|
32
|
-
const output =
|
|
70
|
+
const output = yield handler(input);
|
|
33
71
|
const outputResult = validateApiOutput(output);
|
|
34
72
|
if (outputResult.isErr) {
|
|
35
|
-
return (0,
|
|
73
|
+
return (0, import_response.OutputValidationError)(getErrorMessage(outputResult.value));
|
|
36
74
|
}
|
|
37
|
-
return (0,
|
|
38
|
-
};
|
|
75
|
+
return (0, import_response.HandleSuccess)(output);
|
|
76
|
+
});
|
|
39
77
|
return Object.assign(handle, {
|
|
40
78
|
schema,
|
|
41
79
|
[HANDLER_WITH_SCHEMA]: true
|
|
42
80
|
});
|
|
43
81
|
};
|
|
44
|
-
exports.baseMatch = baseMatch;
|
|
45
82
|
const match = baseMatch;
|
|
46
|
-
|
|
47
|
-
const createRequestSchemaValidator = schema => {
|
|
83
|
+
const createRequestSchemaValidator = (schema) => {
|
|
48
84
|
const descriptors = {};
|
|
49
85
|
if (schema.params) {
|
|
50
86
|
descriptors.params = schema.params;
|
|
@@ -61,6 +97,13 @@ const createRequestSchemaValidator = schema => {
|
|
|
61
97
|
if (schema.cookies) {
|
|
62
98
|
descriptors.cookies = schema.cookies;
|
|
63
99
|
}
|
|
64
|
-
const RequestStruct = (0,
|
|
65
|
-
return (0,
|
|
66
|
-
};
|
|
100
|
+
const RequestStruct = (0, import_farrow_schema.Struct)(descriptors);
|
|
101
|
+
return (0, import_validator.createSchemaValidator)((0, import_farrow_schema.NonStrict)(RequestStruct));
|
|
102
|
+
};
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
baseMatch,
|
|
106
|
+
isHandler,
|
|
107
|
+
isSchemaHandler,
|
|
108
|
+
match
|
|
109
|
+
});
|
package/dist/js/node/request.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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);
|
package/dist/js/node/response.js
CHANGED
|
@@ -1,24 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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 response_exports = {};
|
|
19
|
+
__export(response_exports, {
|
|
20
|
+
HandleSuccess: () => HandleSuccess,
|
|
21
|
+
InputValidationError: () => InputValidationError,
|
|
22
|
+
OutputValidationError: () => OutputValidationError
|
|
5
23
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type: 'HandleSuccess',
|
|
24
|
+
module.exports = __toCommonJS(response_exports);
|
|
25
|
+
const HandleSuccess = (output) => ({
|
|
26
|
+
type: "HandleSuccess",
|
|
10
27
|
value: output
|
|
11
28
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const InputValidationError = message => ({
|
|
15
|
-
type: 'InputValidationError',
|
|
29
|
+
const InputValidationError = (message) => ({
|
|
30
|
+
type: "InputValidationError",
|
|
16
31
|
message
|
|
17
32
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const OutputValidationError = message => ({
|
|
21
|
-
type: 'OutputValidationError',
|
|
33
|
+
const OutputValidationError = (message) => ({
|
|
34
|
+
type: "OutputValidationError",
|
|
22
35
|
message
|
|
23
36
|
});
|
|
24
|
-
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
HandleSuccess,
|
|
40
|
+
InputValidationError,
|
|
41
|
+
OutputValidationError
|
|
42
|
+
});
|
package/dist/js/node/types.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export { match, isHandler, isSchemaHandler } from "./match";
|
|
1
|
+
export * from "farrow-schema";
|
|
2
|
+
import { match, isHandler, isSchemaHandler } from "./match";
|
|
3
|
+
export { isHandler, isSchemaHandler, match };
|
|
@@ -1,85 +1,220 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
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
|
+
}
|
|
15
|
+
function _asyncToGenerator(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(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _defineProperty(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
44
|
+
var f, y, t, g, _ = {
|
|
45
|
+
label: 0,
|
|
46
|
+
sent: function() {
|
|
47
|
+
if (t[0] & 1) throw t[1];
|
|
48
|
+
return t[1];
|
|
49
|
+
},
|
|
50
|
+
trys: [],
|
|
51
|
+
ops: []
|
|
52
|
+
};
|
|
53
|
+
return(g = {
|
|
54
|
+
next: verb(0),
|
|
55
|
+
"throw": verb(1),
|
|
56
|
+
"return": verb(2)
|
|
57
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
58
|
+
return this;
|
|
59
|
+
}), g);
|
|
60
|
+
function verb(n) {
|
|
61
|
+
return function(v) {
|
|
62
|
+
return step([
|
|
63
|
+
n,
|
|
64
|
+
v
|
|
65
|
+
]);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function step(op) {
|
|
69
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
70
|
+
while(_)try {
|
|
71
|
+
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) return t;
|
|
72
|
+
if (y = 0, t) op = [
|
|
73
|
+
op[0] & 2,
|
|
74
|
+
t.value
|
|
75
|
+
];
|
|
76
|
+
switch(op[0]){
|
|
77
|
+
case 0:
|
|
78
|
+
case 1:
|
|
79
|
+
t = op;
|
|
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) {
|
|
123
|
+
op = [
|
|
124
|
+
6,
|
|
125
|
+
e
|
|
126
|
+
];
|
|
127
|
+
y = 0;
|
|
128
|
+
} finally{
|
|
129
|
+
f = t = 0;
|
|
130
|
+
}
|
|
131
|
+
if (op[0] & 5) throw op[1];
|
|
132
|
+
return {
|
|
133
|
+
value: op[0] ? op[1] : void 0,
|
|
134
|
+
done: true
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
import { toSchemaCtor, Struct, NonStrict } from "farrow-schema";
|
|
139
|
+
import { createSchemaValidator } from "farrow-schema/validator";
|
|
6
140
|
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
|
|
7
|
-
var getErrorMessage = function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
141
|
+
var getErrorMessage = function(error) {
|
|
142
|
+
var message = error.message;
|
|
143
|
+
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
144
|
+
message = "path: ".concat(JSON.stringify(error.path), "\n").concat(message);
|
|
145
|
+
}
|
|
146
|
+
return message;
|
|
13
147
|
};
|
|
14
|
-
var HANDLER_WITH_SCHEMA =
|
|
15
|
-
|
|
16
|
-
|
|
148
|
+
var HANDLER_WITH_SCHEMA = "HANDLER_WITH_SCHEMA";
|
|
149
|
+
var isSchemaHandler = function(input) {
|
|
150
|
+
return input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
17
151
|
};
|
|
18
|
-
|
|
19
|
-
|
|
152
|
+
var isHandler = function(input) {
|
|
153
|
+
return input && typeof input === "function";
|
|
20
154
|
};
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
155
|
+
var baseMatch = function(schema, handler) {
|
|
156
|
+
var validateApiInput = createRequestSchemaValidator(schema.request);
|
|
157
|
+
var validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
158
|
+
var handle = function() {
|
|
159
|
+
var _ref = _asyncToGenerator(function(input) {
|
|
160
|
+
var inputResult, output, outputResult;
|
|
161
|
+
return __generator(this, function(_state) {
|
|
162
|
+
switch(_state.label){
|
|
163
|
+
case 0:
|
|
164
|
+
inputResult = validateApiInput(input);
|
|
165
|
+
if (inputResult.isErr) {
|
|
166
|
+
return [
|
|
167
|
+
2,
|
|
168
|
+
InputValidationError(getErrorMessage(inputResult.value))
|
|
169
|
+
];
|
|
170
|
+
}
|
|
171
|
+
return [
|
|
172
|
+
4,
|
|
173
|
+
handler(input)
|
|
174
|
+
];
|
|
175
|
+
case 1:
|
|
176
|
+
output = _state.sent();
|
|
177
|
+
outputResult = validateApiOutput(output);
|
|
178
|
+
if (outputResult.isErr) {
|
|
179
|
+
return [
|
|
180
|
+
2,
|
|
181
|
+
OutputValidationError(getErrorMessage(outputResult.value))
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
return [
|
|
185
|
+
2,
|
|
186
|
+
HandleSuccess(output)
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
return function handle(input) {
|
|
192
|
+
return _ref.apply(this, arguments);
|
|
193
|
+
};
|
|
194
|
+
}();
|
|
195
|
+
return Object.assign(handle, _defineProperty({
|
|
196
|
+
schema: schema
|
|
197
|
+
}, HANDLER_WITH_SCHEMA, true));
|
|
198
|
+
};
|
|
199
|
+
var match = baseMatch;
|
|
200
|
+
var createRequestSchemaValidator = function(schema) {
|
|
201
|
+
var descriptors = {};
|
|
202
|
+
if (schema.params) {
|
|
203
|
+
descriptors.params = schema.params;
|
|
204
|
+
}
|
|
205
|
+
if (schema.query) {
|
|
206
|
+
descriptors.query = schema.query;
|
|
207
|
+
}
|
|
208
|
+
if (schema.data) {
|
|
209
|
+
descriptors.data = schema.data;
|
|
210
|
+
}
|
|
211
|
+
if (schema.headers) {
|
|
212
|
+
descriptors.headers = schema.headers;
|
|
213
|
+
}
|
|
214
|
+
if (schema.cookies) {
|
|
215
|
+
descriptors.cookies = schema.cookies;
|
|
216
|
+
}
|
|
217
|
+
var RequestStruct = Struct(descriptors);
|
|
218
|
+
return createSchemaValidator(NonStrict(RequestStruct));
|
|
64
219
|
};
|
|
65
|
-
export
|
|
66
|
-
var createRequestSchemaValidator = function createRequestSchemaValidator(schema) {
|
|
67
|
-
var descriptors = {};
|
|
68
|
-
if (schema.params) {
|
|
69
|
-
descriptors.params = schema.params;
|
|
70
|
-
}
|
|
71
|
-
if (schema.query) {
|
|
72
|
-
descriptors.query = schema.query;
|
|
73
|
-
}
|
|
74
|
-
if (schema.data) {
|
|
75
|
-
descriptors.data = schema.data;
|
|
76
|
-
}
|
|
77
|
-
if (schema.headers) {
|
|
78
|
-
descriptors.headers = schema.headers;
|
|
79
|
-
}
|
|
80
|
-
if (schema.cookies) {
|
|
81
|
-
descriptors.cookies = schema.cookies;
|
|
82
|
-
}
|
|
83
|
-
var RequestStruct = Struct(descriptors);
|
|
84
|
-
return createSchemaValidator(NonStrict(RequestStruct));
|
|
85
|
-
};
|
|
220
|
+
export { baseMatch, isHandler, isSchemaHandler, match };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
1
|
+
var HandleSuccess = function(output) {
|
|
2
|
+
return {
|
|
3
|
+
type: "HandleSuccess",
|
|
4
|
+
value: output
|
|
5
|
+
};
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
7
|
+
var InputValidationError = function(message) {
|
|
8
|
+
return {
|
|
9
|
+
type: "InputValidationError",
|
|
10
|
+
message: message
|
|
11
|
+
};
|
|
14
12
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
13
|
+
var OutputValidationError = function(message) {
|
|
14
|
+
return {
|
|
15
|
+
type: "OutputValidationError",
|
|
16
|
+
message: message
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export { HandleSuccess, InputValidationError, OutputValidationError };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.0.0-beta.
|
|
14
|
+
"version": "2.0.0-beta.6",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"jest": "^27",
|
|
40
40
|
"ts-jest": "^27.0.5",
|
|
41
41
|
"typescript": "^4",
|
|
42
|
-
"@scripts/build": "2.0.0-beta.
|
|
43
|
-
"@scripts/jest-config": "2.0.0-beta.
|
|
42
|
+
"@scripts/build": "2.0.0-beta.6",
|
|
43
|
+
"@scripts/jest-config": "2.0.0-beta.6"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"registry": "https://registry.npmjs.org/",
|