@modern-js/bff-runtime 2.0.0-beta.0 → 2.0.0-beta.2
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 +2 -1
- package/dist/js/modern/match.js +0 -17
- package/dist/js/node/index.js +0 -3
- package/dist/js/node/match.js +0 -26
- package/dist/js/node/response.js +0 -6
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/match.js +0 -22
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
package/dist/js/modern/index.js
CHANGED
package/dist/js/modern/match.js
CHANGED
|
@@ -1,73 +1,56 @@
|
|
|
1
1
|
import { toSchemaCtor, Struct, NonStrict } from 'farrow-schema';
|
|
2
2
|
import { createSchemaValidator } from 'farrow-schema/validator';
|
|
3
3
|
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
|
|
4
|
-
|
|
5
4
|
const getErrorMessage = error => {
|
|
6
5
|
let {
|
|
7
6
|
message
|
|
8
7
|
} = error;
|
|
9
|
-
|
|
10
8
|
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
11
9
|
message = `path: ${JSON.stringify(error.path)}\n${message}`;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
return message;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
|
|
18
14
|
export const isSchemaHandler = input => input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
19
15
|
export const isHandler = input => input && typeof input === 'function';
|
|
20
16
|
export const baseMatch = (schema, handler) => {
|
|
21
17
|
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
22
18
|
const validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
23
|
-
|
|
24
19
|
const handle = async input => {
|
|
25
20
|
const inputResult = validateApiInput(input);
|
|
26
|
-
|
|
27
21
|
if (inputResult.isErr) {
|
|
28
22
|
return InputValidationError(getErrorMessage(inputResult.value));
|
|
29
23
|
}
|
|
30
|
-
|
|
31
24
|
const output = await handler(input);
|
|
32
25
|
const outputResult = validateApiOutput(output);
|
|
33
|
-
|
|
34
26
|
if (outputResult.isErr) {
|
|
35
27
|
return OutputValidationError(getErrorMessage(outputResult.value));
|
|
36
28
|
}
|
|
37
|
-
|
|
38
29
|
return HandleSuccess(output);
|
|
39
30
|
};
|
|
40
|
-
|
|
41
31
|
return Object.assign(handle, {
|
|
42
32
|
schema,
|
|
43
33
|
[HANDLER_WITH_SCHEMA]: true
|
|
44
34
|
});
|
|
45
35
|
};
|
|
46
36
|
export const match = baseMatch;
|
|
47
|
-
|
|
48
37
|
const createRequestSchemaValidator = schema => {
|
|
49
38
|
const descriptors = {};
|
|
50
|
-
|
|
51
39
|
if (schema.params) {
|
|
52
40
|
descriptors.params = schema.params;
|
|
53
41
|
}
|
|
54
|
-
|
|
55
42
|
if (schema.query) {
|
|
56
43
|
descriptors.query = schema.query;
|
|
57
44
|
}
|
|
58
|
-
|
|
59
45
|
if (schema.data) {
|
|
60
46
|
descriptors.data = schema.data;
|
|
61
47
|
}
|
|
62
|
-
|
|
63
48
|
if (schema.headers) {
|
|
64
49
|
descriptors.headers = schema.headers;
|
|
65
50
|
}
|
|
66
|
-
|
|
67
51
|
if (schema.cookies) {
|
|
68
52
|
descriptors.cookies = schema.cookies;
|
|
69
53
|
}
|
|
70
|
-
|
|
71
54
|
const RequestStruct = Struct(descriptors);
|
|
72
55
|
return createSchemaValidator(NonStrict(RequestStruct));
|
|
73
56
|
};
|
package/dist/js/node/index.js
CHANGED
|
@@ -26,9 +26,7 @@ Object.defineProperty(exports, "match", {
|
|
|
26
26
|
return _match.match;
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
|
-
|
|
30
29
|
var _farrowSchema = require("farrow-schema");
|
|
31
|
-
|
|
32
30
|
Object.keys(_farrowSchema).forEach(function (key) {
|
|
33
31
|
if (key === "default" || key === "__esModule") return;
|
|
34
32
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -40,5 +38,4 @@ Object.keys(_farrowSchema).forEach(function (key) {
|
|
|
40
38
|
}
|
|
41
39
|
});
|
|
42
40
|
});
|
|
43
|
-
|
|
44
41
|
var _match = require("./match");
|
package/dist/js/node/match.js
CHANGED
|
@@ -4,89 +4,63 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.match = exports.isSchemaHandler = exports.isHandler = exports.baseMatch = void 0;
|
|
7
|
-
|
|
8
7
|
var _farrowSchema = require("farrow-schema");
|
|
9
|
-
|
|
10
8
|
var _validator = require("farrow-schema/validator");
|
|
11
|
-
|
|
12
9
|
var _response = require("./response");
|
|
13
|
-
|
|
14
10
|
const getErrorMessage = error => {
|
|
15
11
|
let {
|
|
16
12
|
message
|
|
17
13
|
} = error;
|
|
18
|
-
|
|
19
14
|
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
20
15
|
message = `path: ${JSON.stringify(error.path)}\n${message}`;
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
return message;
|
|
24
18
|
};
|
|
25
|
-
|
|
26
19
|
const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
|
|
27
|
-
|
|
28
20
|
const isSchemaHandler = input => input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
29
|
-
|
|
30
21
|
exports.isSchemaHandler = isSchemaHandler;
|
|
31
|
-
|
|
32
22
|
const isHandler = input => input && typeof input === 'function';
|
|
33
|
-
|
|
34
23
|
exports.isHandler = isHandler;
|
|
35
|
-
|
|
36
24
|
const baseMatch = (schema, handler) => {
|
|
37
25
|
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
38
26
|
const validateApiOutput = (0, _validator.createSchemaValidator)((0, _farrowSchema.toSchemaCtor)(schema.response));
|
|
39
|
-
|
|
40
27
|
const handle = async input => {
|
|
41
28
|
const inputResult = validateApiInput(input);
|
|
42
|
-
|
|
43
29
|
if (inputResult.isErr) {
|
|
44
30
|
return (0, _response.InputValidationError)(getErrorMessage(inputResult.value));
|
|
45
31
|
}
|
|
46
|
-
|
|
47
32
|
const output = await handler(input);
|
|
48
33
|
const outputResult = validateApiOutput(output);
|
|
49
|
-
|
|
50
34
|
if (outputResult.isErr) {
|
|
51
35
|
return (0, _response.OutputValidationError)(getErrorMessage(outputResult.value));
|
|
52
36
|
}
|
|
53
|
-
|
|
54
37
|
return (0, _response.HandleSuccess)(output);
|
|
55
38
|
};
|
|
56
|
-
|
|
57
39
|
return Object.assign(handle, {
|
|
58
40
|
schema,
|
|
59
41
|
[HANDLER_WITH_SCHEMA]: true
|
|
60
42
|
});
|
|
61
43
|
};
|
|
62
|
-
|
|
63
44
|
exports.baseMatch = baseMatch;
|
|
64
45
|
const match = baseMatch;
|
|
65
46
|
exports.match = match;
|
|
66
|
-
|
|
67
47
|
const createRequestSchemaValidator = schema => {
|
|
68
48
|
const descriptors = {};
|
|
69
|
-
|
|
70
49
|
if (schema.params) {
|
|
71
50
|
descriptors.params = schema.params;
|
|
72
51
|
}
|
|
73
|
-
|
|
74
52
|
if (schema.query) {
|
|
75
53
|
descriptors.query = schema.query;
|
|
76
54
|
}
|
|
77
|
-
|
|
78
55
|
if (schema.data) {
|
|
79
56
|
descriptors.data = schema.data;
|
|
80
57
|
}
|
|
81
|
-
|
|
82
58
|
if (schema.headers) {
|
|
83
59
|
descriptors.headers = schema.headers;
|
|
84
60
|
}
|
|
85
|
-
|
|
86
61
|
if (schema.cookies) {
|
|
87
62
|
descriptors.cookies = schema.cookies;
|
|
88
63
|
}
|
|
89
|
-
|
|
90
64
|
const RequestStruct = (0, _farrowSchema.Struct)(descriptors);
|
|
91
65
|
return (0, _validator.createSchemaValidator)((0, _farrowSchema.NonStrict)(RequestStruct));
|
|
92
66
|
};
|
package/dist/js/node/response.js
CHANGED
|
@@ -4,27 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.OutputValidationError = exports.InputValidationError = exports.HandleSuccess = void 0;
|
|
7
|
-
|
|
8
7
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
9
8
|
const HandleSuccess = output => ({
|
|
10
9
|
type: 'HandleSuccess',
|
|
11
10
|
value: output
|
|
12
11
|
});
|
|
13
|
-
|
|
14
12
|
exports.HandleSuccess = HandleSuccess;
|
|
15
|
-
|
|
16
13
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
17
14
|
const InputValidationError = message => ({
|
|
18
15
|
type: 'InputValidationError',
|
|
19
16
|
message
|
|
20
17
|
});
|
|
21
|
-
|
|
22
18
|
exports.InputValidationError = InputValidationError;
|
|
23
|
-
|
|
24
19
|
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
25
20
|
const OutputValidationError = message => ({
|
|
26
21
|
type: 'OutputValidationError',
|
|
27
22
|
message
|
|
28
23
|
});
|
|
29
|
-
|
|
30
24
|
exports.OutputValidationError = OutputValidationError;
|
|
@@ -4,17 +4,13 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
4
4
|
import { toSchemaCtor, Struct, NonStrict } from 'farrow-schema';
|
|
5
5
|
import { createSchemaValidator } from 'farrow-schema/validator';
|
|
6
6
|
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
|
|
7
|
-
|
|
8
7
|
var getErrorMessage = function getErrorMessage(error) {
|
|
9
8
|
var message = error.message;
|
|
10
|
-
|
|
11
9
|
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
12
10
|
message = "path: ".concat(JSON.stringify(error.path), "\n").concat(message);
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
return message;
|
|
16
13
|
};
|
|
17
|
-
|
|
18
14
|
var HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
|
|
19
15
|
export var isSchemaHandler = function isSchemaHandler(input) {
|
|
20
16
|
return input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
@@ -25,7 +21,6 @@ export var isHandler = function isHandler(input) {
|
|
|
25
21
|
export var baseMatch = function baseMatch(schema, handler) {
|
|
26
22
|
var validateApiInput = createRequestSchemaValidator(schema.request);
|
|
27
23
|
var validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
28
|
-
|
|
29
24
|
var handle = /*#__PURE__*/function () {
|
|
30
25
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input) {
|
|
31
26
|
var inputResult, output, outputResult;
|
|
@@ -34,32 +29,24 @@ export var baseMatch = function baseMatch(schema, handler) {
|
|
|
34
29
|
switch (_context.prev = _context.next) {
|
|
35
30
|
case 0:
|
|
36
31
|
inputResult = validateApiInput(input);
|
|
37
|
-
|
|
38
32
|
if (!inputResult.isErr) {
|
|
39
33
|
_context.next = 3;
|
|
40
34
|
break;
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
return _context.abrupt("return", InputValidationError(getErrorMessage(inputResult.value)));
|
|
44
|
-
|
|
45
37
|
case 3:
|
|
46
38
|
_context.next = 5;
|
|
47
39
|
return handler(input);
|
|
48
|
-
|
|
49
40
|
case 5:
|
|
50
41
|
output = _context.sent;
|
|
51
42
|
outputResult = validateApiOutput(output);
|
|
52
|
-
|
|
53
43
|
if (!outputResult.isErr) {
|
|
54
44
|
_context.next = 9;
|
|
55
45
|
break;
|
|
56
46
|
}
|
|
57
|
-
|
|
58
47
|
return _context.abrupt("return", OutputValidationError(getErrorMessage(outputResult.value)));
|
|
59
|
-
|
|
60
48
|
case 9:
|
|
61
49
|
return _context.abrupt("return", HandleSuccess(output));
|
|
62
|
-
|
|
63
50
|
case 10:
|
|
64
51
|
case "end":
|
|
65
52
|
return _context.stop();
|
|
@@ -67,41 +54,32 @@ export var baseMatch = function baseMatch(schema, handler) {
|
|
|
67
54
|
}
|
|
68
55
|
}, _callee);
|
|
69
56
|
}));
|
|
70
|
-
|
|
71
57
|
return function handle(_x) {
|
|
72
58
|
return _ref.apply(this, arguments);
|
|
73
59
|
};
|
|
74
60
|
}();
|
|
75
|
-
|
|
76
61
|
return Object.assign(handle, _defineProperty({
|
|
77
62
|
schema: schema
|
|
78
63
|
}, HANDLER_WITH_SCHEMA, true));
|
|
79
64
|
};
|
|
80
65
|
export var match = baseMatch;
|
|
81
|
-
|
|
82
66
|
var createRequestSchemaValidator = function createRequestSchemaValidator(schema) {
|
|
83
67
|
var descriptors = {};
|
|
84
|
-
|
|
85
68
|
if (schema.params) {
|
|
86
69
|
descriptors.params = schema.params;
|
|
87
70
|
}
|
|
88
|
-
|
|
89
71
|
if (schema.query) {
|
|
90
72
|
descriptors.query = schema.query;
|
|
91
73
|
}
|
|
92
|
-
|
|
93
74
|
if (schema.data) {
|
|
94
75
|
descriptors.data = schema.data;
|
|
95
76
|
}
|
|
96
|
-
|
|
97
77
|
if (schema.headers) {
|
|
98
78
|
descriptors.headers = schema.headers;
|
|
99
79
|
}
|
|
100
|
-
|
|
101
80
|
if (schema.cookies) {
|
|
102
81
|
descriptors.cookies = schema.cookies;
|
|
103
82
|
}
|
|
104
|
-
|
|
105
83
|
var RequestStruct = Struct(descriptors);
|
|
106
84
|
return createSchemaValidator(NonStrict(RequestStruct));
|
|
107
85
|
};
|
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.2",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -34,21 +34,21 @@
|
|
|
34
34
|
"farrow-schema": "^1.10.8"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@scripts/build": "2.0.0-beta.0",
|
|
38
|
-
"@scripts/jest-config": "2.0.0-beta.0",
|
|
39
37
|
"@types/jest": "^27",
|
|
40
38
|
"@types/node": "^14",
|
|
41
39
|
"jest": "^27",
|
|
42
40
|
"ts-jest": "^27.0.5",
|
|
43
|
-
"typescript": "^4"
|
|
41
|
+
"typescript": "^4",
|
|
42
|
+
"@scripts/build": "2.0.0-beta.2",
|
|
43
|
+
"@scripts/jest-config": "2.0.0-beta.2"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"registry": "https://registry.npmjs.org/",
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
|
-
"new": "modern new",
|
|
51
|
-
"build": "modern build",
|
|
50
|
+
"new": "modern-lib new",
|
|
51
|
+
"build": "modern-lib build",
|
|
52
52
|
"test": "jest --passWithNoTests"
|
|
53
53
|
}
|
|
54
54
|
}
|