@modern-js/bff-runtime 2.69.5 → 3.0.0-alpha.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/dist/cjs/index.js +76 -32
- package/dist/cjs/match.js +75 -81
- package/dist/cjs/request.js +17 -15
- package/dist/cjs/response.js +50 -40
- package/dist/cjs/types.js +17 -15
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/match.mjs +39 -0
- package/dist/esm/response.mjs +13 -0
- package/dist/esm-node/index.mjs +3 -0
- package/dist/esm-node/match.mjs +39 -0
- package/dist/esm-node/response.mjs +13 -0
- package/package.json +8 -11
- package/rslib.config.mts +4 -0
- package/rstest.config.ts +5 -0
- package/dist/esm/index.js +0 -7
- package/dist/esm/match.js +0 -91
- package/dist/esm/response.js +0 -23
- package/dist/esm-node/index.js +0 -7
- package/dist/esm-node/match.js +0 -61
- package/dist/esm-node/response.js +0 -17
- /package/dist/esm/{request.js → request.mjs} +0 -0
- /package/dist/esm/{types.js → types.mjs} +0 -0
- /package/dist/esm-node/{request.js → request.mjs} +0 -0
- /package/dist/esm-node/{types.js → types.mjs} +0 -0
package/dist/cjs/index.js
CHANGED
|
@@ -1,35 +1,79 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./match" (module) {
|
|
4
|
+
module.exports = require("./match.js");
|
|
5
|
+
},
|
|
6
|
+
"farrow-schema" (module) {
|
|
7
|
+
module.exports = require("farrow-schema");
|
|
8
|
+
}
|
|
9
9
|
};
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
10
|
+
var __webpack_module_cache__ = {};
|
|
11
|
+
function __webpack_require__(moduleId) {
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
+
exports: {}
|
|
16
|
+
};
|
|
17
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
+
return module.exports;
|
|
19
|
+
}
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.n = (module)=>{
|
|
22
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
23
|
+
__webpack_require__.d(getter, {
|
|
24
|
+
a: getter
|
|
25
|
+
});
|
|
26
|
+
return getter;
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
31
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: definition[key]
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
39
|
+
})();
|
|
40
|
+
(()=>{
|
|
41
|
+
__webpack_require__.r = (exports1)=>{
|
|
42
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
43
|
+
value: 'Module'
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
46
|
+
value: true
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
var __webpack_exports__ = {};
|
|
51
|
+
(()=>{
|
|
52
|
+
__webpack_require__.r(__webpack_exports__);
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
isHandler: ()=>_match__rspack_import_1.isHandler,
|
|
55
|
+
isSchemaHandler: ()=>_match__rspack_import_1.isSchemaHandler,
|
|
56
|
+
match: ()=>_match__rspack_import_1.match
|
|
57
|
+
});
|
|
58
|
+
var farrow_schema__rspack_import_0 = __webpack_require__("farrow-schema");
|
|
59
|
+
var __rspack_reexport = {};
|
|
60
|
+
for(const __rspack_import_key in farrow_schema__rspack_import_0)if ([
|
|
61
|
+
"isHandler",
|
|
62
|
+
"default",
|
|
63
|
+
"isSchemaHandler",
|
|
64
|
+
"match"
|
|
65
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>farrow_schema__rspack_import_0[__rspack_import_key];
|
|
66
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
67
|
+
var _match__rspack_import_1 = __webpack_require__("./match");
|
|
68
|
+
})();
|
|
69
|
+
exports.isHandler = __webpack_exports__.isHandler;
|
|
70
|
+
exports.isSchemaHandler = __webpack_exports__.isSchemaHandler;
|
|
71
|
+
exports.match = __webpack_exports__.match;
|
|
72
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
73
|
+
"isHandler",
|
|
74
|
+
"isSchemaHandler",
|
|
75
|
+
"match"
|
|
76
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
77
|
+
Object.defineProperty(exports, '__esModule', {
|
|
78
|
+
value: true
|
|
35
79
|
});
|
package/dist/cjs/match.js
CHANGED
|
@@ -1,88 +1,82 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
isHandler: ()=>isHandler,
|
|
28
|
+
baseMatch: ()=>baseMatch,
|
|
29
|
+
isSchemaHandler: ()=>isSchemaHandler,
|
|
30
|
+
match: ()=>match
|
|
25
31
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
message = `path: ${JSON.stringify(error.path)}
|
|
34
|
-
${message}`;
|
|
35
|
-
}
|
|
36
|
-
return message;
|
|
32
|
+
const external_farrow_schema_namespaceObject = require("farrow-schema");
|
|
33
|
+
const validator_namespaceObject = require("farrow-schema/validator");
|
|
34
|
+
const external_response_js_namespaceObject = require("./response.js");
|
|
35
|
+
const getErrorMessage = (error)=>{
|
|
36
|
+
let { message } = error;
|
|
37
|
+
if (Array.isArray(error.path) && error.path.length > 0) message = `path: ${JSON.stringify(error.path)}\n${message}`;
|
|
38
|
+
return message;
|
|
37
39
|
};
|
|
38
|
-
const HANDLER_WITH_SCHEMA =
|
|
39
|
-
const isSchemaHandler = (input)
|
|
40
|
-
const isHandler = (input)
|
|
41
|
-
const baseMatch = (schema, handler)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return Object.assign(handle, {
|
|
57
|
-
schema,
|
|
58
|
-
[HANDLER_WITH_SCHEMA]: true
|
|
59
|
-
});
|
|
40
|
+
const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
|
|
41
|
+
const isSchemaHandler = (input)=>input && input?.[HANDLER_WITH_SCHEMA] === true;
|
|
42
|
+
const isHandler = (input)=>input && 'function' == typeof input;
|
|
43
|
+
const baseMatch = (schema, handler)=>{
|
|
44
|
+
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
45
|
+
const validateApiOutput = (0, validator_namespaceObject.createSchemaValidator)((0, external_farrow_schema_namespaceObject.toSchemaCtor)(schema.response));
|
|
46
|
+
const handle = async (input)=>{
|
|
47
|
+
const inputResult = validateApiInput(input);
|
|
48
|
+
if (inputResult.isErr) return (0, external_response_js_namespaceObject.InputValidationError)(getErrorMessage(inputResult.value));
|
|
49
|
+
const output = await handler(input);
|
|
50
|
+
const outputResult = validateApiOutput(output);
|
|
51
|
+
if (outputResult.isErr) return (0, external_response_js_namespaceObject.OutputValidationError)(getErrorMessage(outputResult.value));
|
|
52
|
+
return (0, external_response_js_namespaceObject.HandleSuccess)(output);
|
|
53
|
+
};
|
|
54
|
+
return Object.assign(handle, {
|
|
55
|
+
schema,
|
|
56
|
+
[HANDLER_WITH_SCHEMA]: true
|
|
57
|
+
});
|
|
60
58
|
};
|
|
61
59
|
const match = baseMatch;
|
|
62
|
-
const createRequestSchemaValidator = (schema)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
descriptors.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
descriptors.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
descriptors.data = schema.data;
|
|
72
|
-
}
|
|
73
|
-
if (schema.headers) {
|
|
74
|
-
descriptors.headers = schema.headers;
|
|
75
|
-
}
|
|
76
|
-
if (schema.cookies) {
|
|
77
|
-
descriptors.cookies = schema.cookies;
|
|
78
|
-
}
|
|
79
|
-
const RequestStruct = (0, import_farrow_schema.Struct)(descriptors);
|
|
80
|
-
return (0, import_validator.createSchemaValidator)((0, import_farrow_schema.NonStrict)(RequestStruct));
|
|
60
|
+
const createRequestSchemaValidator = (schema)=>{
|
|
61
|
+
const descriptors = {};
|
|
62
|
+
if (schema.params) descriptors.params = schema.params;
|
|
63
|
+
if (schema.query) descriptors.query = schema.query;
|
|
64
|
+
if (schema.data) descriptors.data = schema.data;
|
|
65
|
+
if (schema.headers) descriptors.headers = schema.headers;
|
|
66
|
+
if (schema.cookies) descriptors.cookies = schema.cookies;
|
|
67
|
+
const RequestStruct = (0, external_farrow_schema_namespaceObject.Struct)(descriptors);
|
|
68
|
+
return (0, validator_namespaceObject.createSchemaValidator)((0, external_farrow_schema_namespaceObject.NonStrict)(RequestStruct));
|
|
81
69
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
70
|
+
exports.baseMatch = __webpack_exports__.baseMatch;
|
|
71
|
+
exports.isHandler = __webpack_exports__.isHandler;
|
|
72
|
+
exports.isSchemaHandler = __webpack_exports__.isSchemaHandler;
|
|
73
|
+
exports.match = __webpack_exports__.match;
|
|
74
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
75
|
+
"baseMatch",
|
|
76
|
+
"isHandler",
|
|
77
|
+
"isSchemaHandler",
|
|
78
|
+
"match"
|
|
79
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
80
|
+
Object.defineProperty(exports, '__esModule', {
|
|
81
|
+
value: true
|
|
88
82
|
});
|
package/dist/cjs/request.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
package/dist/cjs/response.js
CHANGED
|
@@ -1,43 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
HandleSuccess: ()=>HandleSuccess,
|
|
28
|
+
InputValidationError: ()=>InputValidationError,
|
|
29
|
+
OutputValidationError: ()=>OutputValidationError
|
|
24
30
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
31
|
+
const HandleSuccess = (output)=>({
|
|
32
|
+
type: 'HandleSuccess',
|
|
33
|
+
value: output
|
|
34
|
+
});
|
|
35
|
+
const InputValidationError = (message)=>({
|
|
36
|
+
type: 'InputValidationError',
|
|
37
|
+
message
|
|
38
|
+
});
|
|
39
|
+
const OutputValidationError = (message)=>({
|
|
40
|
+
type: 'OutputValidationError',
|
|
41
|
+
message
|
|
42
|
+
});
|
|
43
|
+
exports.HandleSuccess = __webpack_exports__.HandleSuccess;
|
|
44
|
+
exports.InputValidationError = __webpack_exports__.InputValidationError;
|
|
45
|
+
exports.OutputValidationError = __webpack_exports__.OutputValidationError;
|
|
46
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
47
|
+
"HandleSuccess",
|
|
48
|
+
"InputValidationError",
|
|
49
|
+
"OutputValidationError"
|
|
50
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
51
|
+
Object.defineProperty(exports, '__esModule', {
|
|
52
|
+
value: true
|
|
43
53
|
});
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NonStrict, Struct, toSchemaCtor } from "farrow-schema";
|
|
2
|
+
import { createSchemaValidator } from "farrow-schema/validator";
|
|
3
|
+
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
|
|
4
|
+
const getErrorMessage = (error)=>{
|
|
5
|
+
let { message } = error;
|
|
6
|
+
if (Array.isArray(error.path) && error.path.length > 0) message = `path: ${JSON.stringify(error.path)}\n${message}`;
|
|
7
|
+
return message;
|
|
8
|
+
};
|
|
9
|
+
const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
|
|
10
|
+
const isSchemaHandler = (input)=>input && input?.[HANDLER_WITH_SCHEMA] === true;
|
|
11
|
+
const isHandler = (input)=>input && 'function' == typeof input;
|
|
12
|
+
const baseMatch = (schema, handler)=>{
|
|
13
|
+
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
14
|
+
const validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
15
|
+
const handle = async (input)=>{
|
|
16
|
+
const inputResult = validateApiInput(input);
|
|
17
|
+
if (inputResult.isErr) return InputValidationError(getErrorMessage(inputResult.value));
|
|
18
|
+
const output = await handler(input);
|
|
19
|
+
const outputResult = validateApiOutput(output);
|
|
20
|
+
if (outputResult.isErr) return OutputValidationError(getErrorMessage(outputResult.value));
|
|
21
|
+
return HandleSuccess(output);
|
|
22
|
+
};
|
|
23
|
+
return Object.assign(handle, {
|
|
24
|
+
schema,
|
|
25
|
+
[HANDLER_WITH_SCHEMA]: true
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const match = baseMatch;
|
|
29
|
+
const createRequestSchemaValidator = (schema)=>{
|
|
30
|
+
const descriptors = {};
|
|
31
|
+
if (schema.params) descriptors.params = schema.params;
|
|
32
|
+
if (schema.query) descriptors.query = schema.query;
|
|
33
|
+
if (schema.data) descriptors.data = schema.data;
|
|
34
|
+
if (schema.headers) descriptors.headers = schema.headers;
|
|
35
|
+
if (schema.cookies) descriptors.cookies = schema.cookies;
|
|
36
|
+
const RequestStruct = Struct(descriptors);
|
|
37
|
+
return createSchemaValidator(NonStrict(RequestStruct));
|
|
38
|
+
};
|
|
39
|
+
export { baseMatch, isHandler, isSchemaHandler, match };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const HandleSuccess = (output)=>({
|
|
2
|
+
type: 'HandleSuccess',
|
|
3
|
+
value: output
|
|
4
|
+
});
|
|
5
|
+
const InputValidationError = (message)=>({
|
|
6
|
+
type: 'InputValidationError',
|
|
7
|
+
message
|
|
8
|
+
});
|
|
9
|
+
const OutputValidationError = (message)=>({
|
|
10
|
+
type: 'OutputValidationError',
|
|
11
|
+
message
|
|
12
|
+
});
|
|
13
|
+
export { HandleSuccess, InputValidationError, OutputValidationError };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NonStrict, Struct, toSchemaCtor } from "farrow-schema";
|
|
2
|
+
import { createSchemaValidator } from "farrow-schema/validator";
|
|
3
|
+
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response.mjs";
|
|
4
|
+
const getErrorMessage = (error)=>{
|
|
5
|
+
let { message } = error;
|
|
6
|
+
if (Array.isArray(error.path) && error.path.length > 0) message = `path: ${JSON.stringify(error.path)}\n${message}`;
|
|
7
|
+
return message;
|
|
8
|
+
};
|
|
9
|
+
const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
|
|
10
|
+
const isSchemaHandler = (input)=>input && input?.[HANDLER_WITH_SCHEMA] === true;
|
|
11
|
+
const isHandler = (input)=>input && 'function' == typeof input;
|
|
12
|
+
const baseMatch = (schema, handler)=>{
|
|
13
|
+
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
14
|
+
const validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
15
|
+
const handle = async (input)=>{
|
|
16
|
+
const inputResult = validateApiInput(input);
|
|
17
|
+
if (inputResult.isErr) return InputValidationError(getErrorMessage(inputResult.value));
|
|
18
|
+
const output = await handler(input);
|
|
19
|
+
const outputResult = validateApiOutput(output);
|
|
20
|
+
if (outputResult.isErr) return OutputValidationError(getErrorMessage(outputResult.value));
|
|
21
|
+
return HandleSuccess(output);
|
|
22
|
+
};
|
|
23
|
+
return Object.assign(handle, {
|
|
24
|
+
schema,
|
|
25
|
+
[HANDLER_WITH_SCHEMA]: true
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const match = baseMatch;
|
|
29
|
+
const createRequestSchemaValidator = (schema)=>{
|
|
30
|
+
const descriptors = {};
|
|
31
|
+
if (schema.params) descriptors.params = schema.params;
|
|
32
|
+
if (schema.query) descriptors.query = schema.query;
|
|
33
|
+
if (schema.data) descriptors.data = schema.data;
|
|
34
|
+
if (schema.headers) descriptors.headers = schema.headers;
|
|
35
|
+
if (schema.cookies) descriptors.cookies = schema.cookies;
|
|
36
|
+
const RequestStruct = Struct(descriptors);
|
|
37
|
+
return createSchemaValidator(NonStrict(RequestStruct));
|
|
38
|
+
};
|
|
39
|
+
export { baseMatch, isHandler, isSchemaHandler, match };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const HandleSuccess = (output)=>({
|
|
2
|
+
type: 'HandleSuccess',
|
|
3
|
+
value: output
|
|
4
|
+
});
|
|
5
|
+
const InputValidationError = (message)=>({
|
|
6
|
+
type: 'InputValidationError',
|
|
7
|
+
message
|
|
8
|
+
});
|
|
9
|
+
const OutputValidationError = (message)=>({
|
|
10
|
+
type: 'OutputValidationError',
|
|
11
|
+
message
|
|
12
|
+
});
|
|
13
|
+
export { HandleSuccess, InputValidationError, OutputValidationError };
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "
|
|
18
|
+
"version": "3.0.0-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
".": {
|
|
25
25
|
"node": {
|
|
26
26
|
"jsnext:source": "./src/index.ts",
|
|
27
|
-
"import": "./dist/esm-node/index.
|
|
27
|
+
"import": "./dist/esm-node/index.mjs",
|
|
28
28
|
"require": "./dist/cjs/index.js"
|
|
29
29
|
},
|
|
30
30
|
"default": "./dist/esm/index.js"
|
|
@@ -37,21 +37,18 @@
|
|
|
37
37
|
"farrow-schema": "^1.12.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/
|
|
41
|
-
"@
|
|
42
|
-
"jest": "^29",
|
|
43
|
-
"ts-jest": "^29.1.0",
|
|
40
|
+
"@types/node": "^20",
|
|
41
|
+
"@rslib/core": "0.18.5",
|
|
44
42
|
"typescript": "^5",
|
|
45
|
-
"@
|
|
46
|
-
"@scripts/jest-config": "2.66.0"
|
|
43
|
+
"@modern-js/rslib": "2.68.10"
|
|
47
44
|
},
|
|
48
45
|
"publishConfig": {
|
|
49
46
|
"registry": "https://registry.npmjs.org/",
|
|
50
47
|
"access": "public"
|
|
51
48
|
},
|
|
52
49
|
"scripts": {
|
|
53
|
-
"
|
|
54
|
-
"build": "
|
|
55
|
-
"test": "
|
|
50
|
+
"dev": "rslib build --watch",
|
|
51
|
+
"build": "rslib build",
|
|
52
|
+
"test": "rstest --passWithNoTests"
|
|
56
53
|
}
|
|
57
54
|
}
|
package/rslib.config.mts
ADDED
package/rstest.config.ts
ADDED
package/dist/esm/index.js
DELETED
package/dist/esm/match.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import { NonStrict, Struct, toSchemaCtor } from "farrow-schema";
|
|
5
|
-
import { createSchemaValidator } from "farrow-schema/validator";
|
|
6
|
-
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
|
|
7
|
-
var getErrorMessage = function(error) {
|
|
8
|
-
var message = error.message;
|
|
9
|
-
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
10
|
-
message = "path: ".concat(JSON.stringify(error.path), "\n").concat(message);
|
|
11
|
-
}
|
|
12
|
-
return message;
|
|
13
|
-
};
|
|
14
|
-
var HANDLER_WITH_SCHEMA = "HANDLER_WITH_SCHEMA";
|
|
15
|
-
var isSchemaHandler = function(input) {
|
|
16
|
-
return input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
17
|
-
};
|
|
18
|
-
var isHandler = function(input) {
|
|
19
|
-
return input && typeof input === "function";
|
|
20
|
-
};
|
|
21
|
-
var baseMatch = function(schema, handler) {
|
|
22
|
-
var validateApiInput = createRequestSchemaValidator(schema.request);
|
|
23
|
-
var validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
24
|
-
var handle = function() {
|
|
25
|
-
var _ref = _async_to_generator(function(input) {
|
|
26
|
-
var inputResult, output, outputResult;
|
|
27
|
-
return _ts_generator(this, function(_state) {
|
|
28
|
-
switch (_state.label) {
|
|
29
|
-
case 0:
|
|
30
|
-
inputResult = validateApiInput(input);
|
|
31
|
-
if (inputResult.isErr) {
|
|
32
|
-
return [
|
|
33
|
-
2,
|
|
34
|
-
InputValidationError(getErrorMessage(inputResult.value))
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
return [
|
|
38
|
-
4,
|
|
39
|
-
handler(input)
|
|
40
|
-
];
|
|
41
|
-
case 1:
|
|
42
|
-
output = _state.sent();
|
|
43
|
-
outputResult = validateApiOutput(output);
|
|
44
|
-
if (outputResult.isErr) {
|
|
45
|
-
return [
|
|
46
|
-
2,
|
|
47
|
-
OutputValidationError(getErrorMessage(outputResult.value))
|
|
48
|
-
];
|
|
49
|
-
}
|
|
50
|
-
return [
|
|
51
|
-
2,
|
|
52
|
-
HandleSuccess(output)
|
|
53
|
-
];
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
return function handle2(input) {
|
|
58
|
-
return _ref.apply(this, arguments);
|
|
59
|
-
};
|
|
60
|
-
}();
|
|
61
|
-
return Object.assign(handle, _define_property({
|
|
62
|
-
schema
|
|
63
|
-
}, HANDLER_WITH_SCHEMA, true));
|
|
64
|
-
};
|
|
65
|
-
var match = baseMatch;
|
|
66
|
-
var createRequestSchemaValidator = function(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
|
-
};
|
|
86
|
-
export {
|
|
87
|
-
baseMatch,
|
|
88
|
-
isHandler,
|
|
89
|
-
isSchemaHandler,
|
|
90
|
-
match
|
|
91
|
-
};
|
package/dist/esm/response.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
var HandleSuccess = function(output) {
|
|
2
|
-
return {
|
|
3
|
-
type: "HandleSuccess",
|
|
4
|
-
value: output
|
|
5
|
-
};
|
|
6
|
-
};
|
|
7
|
-
var InputValidationError = function(message) {
|
|
8
|
-
return {
|
|
9
|
-
type: "InputValidationError",
|
|
10
|
-
message
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
var OutputValidationError = function(message) {
|
|
14
|
-
return {
|
|
15
|
-
type: "OutputValidationError",
|
|
16
|
-
message
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export {
|
|
20
|
-
HandleSuccess,
|
|
21
|
-
InputValidationError,
|
|
22
|
-
OutputValidationError
|
|
23
|
-
};
|
package/dist/esm-node/index.js
DELETED
package/dist/esm-node/match.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { NonStrict, Struct, toSchemaCtor } from "farrow-schema";
|
|
2
|
-
import { createSchemaValidator } from "farrow-schema/validator";
|
|
3
|
-
import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
|
|
4
|
-
const getErrorMessage = (error) => {
|
|
5
|
-
let { message } = error;
|
|
6
|
-
if (Array.isArray(error.path) && error.path.length > 0) {
|
|
7
|
-
message = `path: ${JSON.stringify(error.path)}
|
|
8
|
-
${message}`;
|
|
9
|
-
}
|
|
10
|
-
return message;
|
|
11
|
-
};
|
|
12
|
-
const HANDLER_WITH_SCHEMA = "HANDLER_WITH_SCHEMA";
|
|
13
|
-
const isSchemaHandler = (input) => input && (input === null || input === void 0 ? void 0 : input[HANDLER_WITH_SCHEMA]) === true;
|
|
14
|
-
const isHandler = (input) => input && typeof input === "function";
|
|
15
|
-
const baseMatch = (schema, handler) => {
|
|
16
|
-
const validateApiInput = createRequestSchemaValidator(schema.request);
|
|
17
|
-
const validateApiOutput = createSchemaValidator(toSchemaCtor(schema.response));
|
|
18
|
-
const handle = async (input) => {
|
|
19
|
-
const inputResult = validateApiInput(input);
|
|
20
|
-
if (inputResult.isErr) {
|
|
21
|
-
return InputValidationError(getErrorMessage(inputResult.value));
|
|
22
|
-
}
|
|
23
|
-
const output = await handler(input);
|
|
24
|
-
const outputResult = validateApiOutput(output);
|
|
25
|
-
if (outputResult.isErr) {
|
|
26
|
-
return OutputValidationError(getErrorMessage(outputResult.value));
|
|
27
|
-
}
|
|
28
|
-
return HandleSuccess(output);
|
|
29
|
-
};
|
|
30
|
-
return Object.assign(handle, {
|
|
31
|
-
schema,
|
|
32
|
-
[HANDLER_WITH_SCHEMA]: true
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
const match = baseMatch;
|
|
36
|
-
const createRequestSchemaValidator = (schema) => {
|
|
37
|
-
const descriptors = {};
|
|
38
|
-
if (schema.params) {
|
|
39
|
-
descriptors.params = schema.params;
|
|
40
|
-
}
|
|
41
|
-
if (schema.query) {
|
|
42
|
-
descriptors.query = schema.query;
|
|
43
|
-
}
|
|
44
|
-
if (schema.data) {
|
|
45
|
-
descriptors.data = schema.data;
|
|
46
|
-
}
|
|
47
|
-
if (schema.headers) {
|
|
48
|
-
descriptors.headers = schema.headers;
|
|
49
|
-
}
|
|
50
|
-
if (schema.cookies) {
|
|
51
|
-
descriptors.cookies = schema.cookies;
|
|
52
|
-
}
|
|
53
|
-
const RequestStruct = Struct(descriptors);
|
|
54
|
-
return createSchemaValidator(NonStrict(RequestStruct));
|
|
55
|
-
};
|
|
56
|
-
export {
|
|
57
|
-
baseMatch,
|
|
58
|
-
isHandler,
|
|
59
|
-
isSchemaHandler,
|
|
60
|
-
match
|
|
61
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const HandleSuccess = (output) => ({
|
|
2
|
-
type: "HandleSuccess",
|
|
3
|
-
value: output
|
|
4
|
-
});
|
|
5
|
-
const InputValidationError = (message) => ({
|
|
6
|
-
type: "InputValidationError",
|
|
7
|
-
message
|
|
8
|
-
});
|
|
9
|
-
const OutputValidationError = (message) => ({
|
|
10
|
-
type: "OutputValidationError",
|
|
11
|
-
message
|
|
12
|
-
});
|
|
13
|
-
export {
|
|
14
|
-
HandleSuccess,
|
|
15
|
-
InputValidationError,
|
|
16
|
-
OutputValidationError
|
|
17
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|