@modern-js/bff-runtime 0.0.0-next-0bf5ec13d2 → 0.0.0-next-b71d66058

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @modern-js/bff-runtime
2
2
 
3
- ## 0.0.0-next-0bf5ec13d2
3
+ ## 0.0.0-next-b71d66058
4
4
 
5
5
  ## 2.7.0
6
6
 
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "0.0.0-next-0bf5ec13d2",
14
+ "version": "0.0.0-next-b71d66058",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -33,13 +33,13 @@
33
33
  "farrow-schema": "^1.10.8"
34
34
  },
35
35
  "devDependencies": {
36
- "@scripts/build": "0.0.0-next-0bf5ec13d2",
37
- "@scripts/jest-config": "0.0.0-next-0bf5ec13d2",
38
36
  "@types/jest": "^27",
39
37
  "@types/node": "^14",
40
38
  "jest": "^27",
41
39
  "ts-jest": "^27.0.5",
42
- "typescript": "^4"
40
+ "typescript": "^4",
41
+ "@scripts/jest-config": "0.0.0-next-b71d66058",
42
+ "@scripts/build": "0.0.0-next-b71d66058"
43
43
  },
44
44
  "publishConfig": {
45
45
  "registry": "https://registry.npmjs.org/",
File without changes
@@ -1,7 +0,0 @@
1
- export * from "farrow-schema";
2
- import { match, isHandler, isSchemaHandler } from "./match";
3
- export {
4
- isHandler,
5
- isSchemaHandler,
6
- match
7
- };
@@ -1,93 +0,0 @@
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;
36
- if (Array.isArray(error.path) && error.path.length > 0) {
37
- message = `path: ${JSON.stringify(error.path)}
38
- ${message}`;
39
- }
40
- return message;
41
- };
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) => {
46
- const validateApiInput = createRequestSchemaValidator(schema.request);
47
- const validateApiOutput = createSchemaValidator(
48
- toSchemaCtor(schema.response)
49
- );
50
- const handle = (input) => __async(void 0, null, function* () {
51
- const inputResult = validateApiInput(input);
52
- if (inputResult.isErr) {
53
- return InputValidationError(getErrorMessage(inputResult.value));
54
- }
55
- const output = yield handler(input);
56
- const outputResult = validateApiOutput(output);
57
- if (outputResult.isErr) {
58
- return OutputValidationError(getErrorMessage(outputResult.value));
59
- }
60
- return HandleSuccess(output);
61
- });
62
- return Object.assign(handle, {
63
- schema,
64
- [HANDLER_WITH_SCHEMA]: true
65
- });
66
- };
67
- const match = baseMatch;
68
- const createRequestSchemaValidator = (schema) => {
69
- const descriptors = {};
70
- if (schema.params) {
71
- descriptors.params = schema.params;
72
- }
73
- if (schema.query) {
74
- descriptors.query = schema.query;
75
- }
76
- if (schema.data) {
77
- descriptors.data = schema.data;
78
- }
79
- if (schema.headers) {
80
- descriptors.headers = schema.headers;
81
- }
82
- if (schema.cookies) {
83
- descriptors.cookies = schema.cookies;
84
- }
85
- const RequestStruct = Struct(descriptors);
86
- return createSchemaValidator(NonStrict(RequestStruct));
87
- };
88
- export {
89
- baseMatch,
90
- isHandler,
91
- isSchemaHandler,
92
- match
93
- };
File without changes
@@ -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
@@ -1,15 +0,0 @@
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);
@@ -1,33 +0,0 @@
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 __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
24
- });
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
33
- });
@@ -1,109 +0,0 @@
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
44
- });
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;
51
- if (Array.isArray(error.path) && error.path.length > 0) {
52
- message = `path: ${JSON.stringify(error.path)}
53
- ${message}`;
54
- }
55
- return message;
56
- };
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";
60
- const baseMatch = (schema, handler) => {
61
- const validateApiInput = createRequestSchemaValidator(schema.request);
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* () {
66
- const inputResult = validateApiInput(input);
67
- if (inputResult.isErr) {
68
- return (0, import_response.InputValidationError)(getErrorMessage(inputResult.value));
69
- }
70
- const output = yield handler(input);
71
- const outputResult = validateApiOutput(output);
72
- if (outputResult.isErr) {
73
- return (0, import_response.OutputValidationError)(getErrorMessage(outputResult.value));
74
- }
75
- return (0, import_response.HandleSuccess)(output);
76
- });
77
- return Object.assign(handle, {
78
- schema,
79
- [HANDLER_WITH_SCHEMA]: true
80
- });
81
- };
82
- const match = baseMatch;
83
- const createRequestSchemaValidator = (schema) => {
84
- const descriptors = {};
85
- if (schema.params) {
86
- descriptors.params = schema.params;
87
- }
88
- if (schema.query) {
89
- descriptors.query = schema.query;
90
- }
91
- if (schema.data) {
92
- descriptors.data = schema.data;
93
- }
94
- if (schema.headers) {
95
- descriptors.headers = schema.headers;
96
- }
97
- if (schema.cookies) {
98
- descriptors.cookies = schema.cookies;
99
- }
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
- });
@@ -1,15 +0,0 @@
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);
@@ -1,42 +0,0 @@
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
23
- });
24
- module.exports = __toCommonJS(response_exports);
25
- const HandleSuccess = (output) => ({
26
- type: "HandleSuccess",
27
- value: output
28
- });
29
- const InputValidationError = (message) => ({
30
- type: "InputValidationError",
31
- message
32
- });
33
- const OutputValidationError = (message) => ({
34
- type: "OutputValidationError",
35
- message
36
- });
37
- // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {
39
- HandleSuccess,
40
- InputValidationError,
41
- OutputValidationError
42
- });
@@ -1,15 +0,0 @@
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);
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,3 +0,0 @@
1
- export * from "farrow-schema";
2
- import { match, isHandler, isSchemaHandler } from "./match";
3
- export { isHandler, isSchemaHandler, match };
@@ -1,220 +0,0 @@
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";
140
- import { HandleSuccess, InputValidationError, OutputValidationError } from "./response";
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;
147
- };
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;
151
- };
152
- var isHandler = function(input) {
153
- return input && typeof input === "function";
154
- };
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));
219
- };
220
- export { baseMatch, isHandler, isSchemaHandler, match };
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,19 +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: message
11
- };
12
- };
13
- var OutputValidationError = function(message) {
14
- return {
15
- type: "OutputValidationError",
16
- message: message
17
- };
18
- };
19
- export { HandleSuccess, InputValidationError, OutputValidationError };
@@ -1 +0,0 @@
1
- "use strict";