@modern-js/bff-core 1.22.2-beta.0 → 1.22.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 +21 -132
- package/dist/js/modern/api.js +34 -49
- package/dist/js/modern/client/generate-client.js +34 -52
- package/dist/js/modern/client/index.js +1 -1
- package/dist/js/modern/client/result.js +8 -10
- package/dist/js/modern/errors/http.js +14 -8
- package/dist/js/modern/index.js +3 -19
- package/dist/js/modern/operators/http.js +116 -139
- package/dist/js/modern/router/constants.js +13 -31
- package/dist/js/modern/router/index.js +131 -68
- package/dist/js/modern/router/types.js +1 -0
- package/dist/js/modern/router/utils.js +54 -36
- package/dist/js/modern/types.js +47 -45
- package/dist/js/modern/utils/alias.js +50 -35
- package/dist/js/modern/utils/debug.js +2 -5
- package/dist/js/modern/utils/index.js +2 -5
- package/dist/js/modern/utils/meta.js +4 -8
- package/dist/js/modern/utils/storage.js +14 -8
- package/dist/js/modern/utils/validate.js +29 -23
- package/dist/js/node/api.js +46 -78
- package/dist/js/node/client/generate-client.js +55 -85
- package/dist/js/node/client/index.js +18 -17
- package/dist/js/node/client/result.js +18 -32
- package/dist/js/node/errors/http.js +22 -28
- package/dist/js/node/index.js +122 -45
- package/dist/js/node/operators/http.js +169 -184
- package/dist/js/node/router/constants.js +28 -60
- package/dist/js/node/router/index.js +201 -112
- package/dist/js/node/router/types.js +5 -15
- package/dist/js/node/router/utils.js +78 -71
- package/dist/js/node/types.js +57 -71
- package/dist/js/node/utils/alias.js +73 -65
- package/dist/js/node/utils/debug.js +10 -27
- package/dist/js/node/utils/index.js +68 -28
- package/dist/js/node/utils/meta.js +12 -30
- package/dist/js/node/utils/storage.js +24 -36
- package/dist/js/node/utils/validate.js +44 -50
- package/package.json +40 -12
|
@@ -1,210 +1,187 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __async = (__this, __arguments, generator) => {
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
var fulfilled = (value) => {
|
|
23
|
-
try {
|
|
24
|
-
step(generator.next(value));
|
|
25
|
-
} catch (e) {
|
|
26
|
-
reject(e);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var rejected = (value) => {
|
|
30
|
-
try {
|
|
31
|
-
step(generator.throw(value));
|
|
32
|
-
} catch (e) {
|
|
33
|
-
reject(e);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
import {
|
|
41
|
-
HttpMetadata,
|
|
42
|
-
OperatorType,
|
|
43
|
-
HttpMethod,
|
|
44
|
-
TriggerType,
|
|
45
|
-
ResponseMetaType
|
|
46
|
-
} from "../types";
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
import { HttpMetadata, OperatorType, HttpMethod, TriggerType, ResponseMetaType } from "../types";
|
|
47
8
|
import { ValidationError } from "../errors/http";
|
|
48
|
-
|
|
9
|
+
|
|
10
|
+
const validateInput = async (schema, input) => {
|
|
49
11
|
try {
|
|
50
|
-
return
|
|
12
|
+
return await schema.parseAsync(input);
|
|
51
13
|
} catch (error) {
|
|
52
|
-
const {
|
|
14
|
+
const {
|
|
15
|
+
z: zod
|
|
16
|
+
} = require('zod');
|
|
17
|
+
|
|
53
18
|
if (error instanceof zod.ZodError) {
|
|
54
19
|
throw new ValidationError(400, error.message);
|
|
55
20
|
}
|
|
21
|
+
|
|
56
22
|
throw error;
|
|
57
23
|
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const createHttpOperator = method => {
|
|
27
|
+
return urlPath => {
|
|
61
28
|
return {
|
|
62
29
|
name: method,
|
|
63
|
-
|
|
30
|
+
|
|
31
|
+
metadata({
|
|
32
|
+
setMetadata
|
|
33
|
+
}) {
|
|
64
34
|
setMetadata(OperatorType.Trigger, {
|
|
65
35
|
type: TriggerType.Http,
|
|
66
36
|
path: urlPath,
|
|
67
37
|
method
|
|
68
38
|
});
|
|
69
39
|
}
|
|
40
|
+
|
|
70
41
|
};
|
|
71
42
|
};
|
|
72
43
|
};
|
|
73
|
-
const Get = createHttpOperator(HttpMethod.Get);
|
|
74
|
-
const Post = createHttpOperator(HttpMethod.Post);
|
|
75
|
-
const Put = createHttpOperator(HttpMethod.Put);
|
|
76
|
-
const Delete = createHttpOperator(HttpMethod.Delete);
|
|
77
|
-
const Connect = createHttpOperator(HttpMethod.Connect);
|
|
78
|
-
const Trace = createHttpOperator(HttpMethod.Trace);
|
|
79
|
-
const Patch = createHttpOperator(HttpMethod.Patch);
|
|
80
|
-
const Option = createHttpOperator(HttpMethod.Option);
|
|
81
|
-
const Head = createHttpOperator(HttpMethod.Head);
|
|
82
|
-
const Data =
|
|
44
|
+
export const Get = createHttpOperator(HttpMethod.Get);
|
|
45
|
+
export const Post = createHttpOperator(HttpMethod.Post);
|
|
46
|
+
export const Put = createHttpOperator(HttpMethod.Put);
|
|
47
|
+
export const Delete = createHttpOperator(HttpMethod.Delete);
|
|
48
|
+
export const Connect = createHttpOperator(HttpMethod.Connect);
|
|
49
|
+
export const Trace = createHttpOperator(HttpMethod.Trace);
|
|
50
|
+
export const Patch = createHttpOperator(HttpMethod.Patch);
|
|
51
|
+
export const Option = createHttpOperator(HttpMethod.Option);
|
|
52
|
+
export const Head = createHttpOperator(HttpMethod.Head);
|
|
53
|
+
export const Data = schema => {
|
|
83
54
|
return {
|
|
84
55
|
name: HttpMetadata.Data,
|
|
85
|
-
|
|
56
|
+
|
|
57
|
+
metadata({
|
|
58
|
+
setMetadata
|
|
59
|
+
}) {
|
|
86
60
|
setMetadata(HttpMetadata.Data, schema);
|
|
87
61
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
62
|
+
|
|
63
|
+
async validate(helper, next) {
|
|
64
|
+
const {
|
|
65
|
+
inputs: {
|
|
66
|
+
data
|
|
67
|
+
}
|
|
68
|
+
} = helper;
|
|
69
|
+
helper.inputs = _objectSpread(_objectSpread({}, helper.inputs), {}, {
|
|
70
|
+
data: await validateInput(schema, data)
|
|
97
71
|
});
|
|
72
|
+
return next();
|
|
98
73
|
}
|
|
74
|
+
|
|
99
75
|
};
|
|
100
76
|
};
|
|
101
|
-
const Query =
|
|
77
|
+
export const Query = schema => {
|
|
102
78
|
return {
|
|
103
79
|
name: HttpMetadata.Query,
|
|
104
|
-
|
|
80
|
+
|
|
81
|
+
metadata({
|
|
82
|
+
setMetadata
|
|
83
|
+
}) {
|
|
105
84
|
setMetadata(HttpMetadata.Query, schema);
|
|
106
85
|
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
86
|
+
|
|
87
|
+
async validate(helper, next) {
|
|
88
|
+
const {
|
|
89
|
+
inputs: {
|
|
90
|
+
query
|
|
91
|
+
}
|
|
92
|
+
} = helper;
|
|
93
|
+
helper.inputs = _objectSpread(_objectSpread({}, helper.inputs), {}, {
|
|
94
|
+
query: await validateInput(schema, query)
|
|
116
95
|
});
|
|
96
|
+
return next();
|
|
117
97
|
}
|
|
98
|
+
|
|
118
99
|
};
|
|
119
100
|
};
|
|
120
|
-
const Params =
|
|
101
|
+
export const Params = schema => {
|
|
121
102
|
return {
|
|
122
103
|
name: HttpMetadata.Params,
|
|
123
|
-
|
|
104
|
+
|
|
105
|
+
metadata({
|
|
106
|
+
setMetadata
|
|
107
|
+
}) {
|
|
124
108
|
setMetadata(HttpMetadata.Params, schema);
|
|
125
109
|
},
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
110
|
+
|
|
111
|
+
async validate(helper, next) {
|
|
112
|
+
const {
|
|
113
|
+
inputs: {
|
|
114
|
+
params
|
|
115
|
+
}
|
|
116
|
+
} = helper;
|
|
117
|
+
helper.inputs = _objectSpread(_objectSpread({}, helper.inputs), {}, {
|
|
118
|
+
params: await validateInput(schema, params)
|
|
135
119
|
});
|
|
120
|
+
return next();
|
|
136
121
|
}
|
|
122
|
+
|
|
137
123
|
};
|
|
138
124
|
};
|
|
139
|
-
const Headers =
|
|
125
|
+
export const Headers = schema => {
|
|
140
126
|
return {
|
|
141
127
|
name: HttpMetadata.Headers,
|
|
142
|
-
|
|
128
|
+
|
|
129
|
+
metadata({
|
|
130
|
+
setMetadata
|
|
131
|
+
}) {
|
|
143
132
|
setMetadata(HttpMetadata.Headers, schema);
|
|
144
133
|
},
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
134
|
+
|
|
135
|
+
async validate(helper, next) {
|
|
136
|
+
const {
|
|
137
|
+
inputs: {
|
|
138
|
+
headers
|
|
139
|
+
}
|
|
140
|
+
} = helper;
|
|
141
|
+
helper.inputs = _objectSpread(_objectSpread({}, helper.inputs), {}, {
|
|
142
|
+
headers: await validateInput(schema, headers)
|
|
154
143
|
});
|
|
144
|
+
return next();
|
|
155
145
|
}
|
|
146
|
+
|
|
156
147
|
};
|
|
157
148
|
};
|
|
149
|
+
|
|
158
150
|
const setResponseMeta = (helper, type, value) => {
|
|
159
151
|
const responseMetaData = helper.getMetadata(HttpMetadata.Response) || [];
|
|
160
|
-
helper.setMetadata(HttpMetadata.Response, [
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
value
|
|
165
|
-
}
|
|
166
|
-
]);
|
|
152
|
+
helper.setMetadata(HttpMetadata.Response, [...responseMetaData, {
|
|
153
|
+
type,
|
|
154
|
+
value
|
|
155
|
+
}]);
|
|
167
156
|
};
|
|
168
|
-
|
|
157
|
+
|
|
158
|
+
export const HttpCode = statusCode => {
|
|
169
159
|
return {
|
|
170
|
-
name:
|
|
160
|
+
name: 'HttpCode',
|
|
161
|
+
|
|
171
162
|
metadata(helper) {
|
|
172
163
|
setResponseMeta(helper, ResponseMetaType.StatusCode, statusCode);
|
|
173
164
|
}
|
|
165
|
+
|
|
174
166
|
};
|
|
175
167
|
};
|
|
176
|
-
const SetHeaders =
|
|
168
|
+
export const SetHeaders = headers => {
|
|
177
169
|
return {
|
|
178
|
-
name:
|
|
170
|
+
name: 'SetHeaders',
|
|
171
|
+
|
|
179
172
|
metadata(helper) {
|
|
180
173
|
setResponseMeta(helper, ResponseMetaType.Headers, headers);
|
|
181
174
|
}
|
|
175
|
+
|
|
182
176
|
};
|
|
183
177
|
};
|
|
184
|
-
const Redirect =
|
|
178
|
+
export const Redirect = url => {
|
|
185
179
|
return {
|
|
186
|
-
name:
|
|
180
|
+
name: 'Redirect',
|
|
181
|
+
|
|
187
182
|
metadata(helper) {
|
|
188
183
|
setResponseMeta(helper, ResponseMetaType.Redirect, url);
|
|
189
184
|
}
|
|
185
|
+
|
|
190
186
|
};
|
|
191
|
-
};
|
|
192
|
-
export {
|
|
193
|
-
Connect,
|
|
194
|
-
Data,
|
|
195
|
-
Delete,
|
|
196
|
-
Get,
|
|
197
|
-
Head,
|
|
198
|
-
Headers,
|
|
199
|
-
HttpCode,
|
|
200
|
-
Option,
|
|
201
|
-
Params,
|
|
202
|
-
Patch,
|
|
203
|
-
Post,
|
|
204
|
-
Put,
|
|
205
|
-
Query,
|
|
206
|
-
Redirect,
|
|
207
|
-
SetHeaders,
|
|
208
|
-
Trace,
|
|
209
|
-
createHttpOperator
|
|
210
|
-
};
|
|
187
|
+
};
|
|
@@ -1,32 +1,14 @@
|
|
|
1
1
|
import { HttpMethod } from "../types";
|
|
2
|
-
const AllHttpMethods = Object.values(HttpMethod);
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"!**/_*/**/*.[tj]s",
|
|
16
|
-
"!**/*.test.js",
|
|
17
|
-
"!**/*.test.ts",
|
|
18
|
-
"!**/*.d.ts",
|
|
19
|
-
"!__test__/*.ts",
|
|
20
|
-
"!__tests__/*.ts",
|
|
21
|
-
"!node_modules/**",
|
|
22
|
-
"!bootstrap.js"
|
|
23
|
-
];
|
|
24
|
-
export {
|
|
25
|
-
APIMode,
|
|
26
|
-
API_DIR,
|
|
27
|
-
API_FILE_RULES,
|
|
28
|
-
AllHttpMethods,
|
|
29
|
-
FRAMEWORK_MODE_APP_DIR,
|
|
30
|
-
FRAMEWORK_MODE_LAMBDA_DIR,
|
|
31
|
-
INDEX_SUFFIX
|
|
32
|
-
};
|
|
2
|
+
export const AllHttpMethods = Object.values(HttpMethod);
|
|
3
|
+
export let APIMode;
|
|
4
|
+
|
|
5
|
+
(function (APIMode) {
|
|
6
|
+
APIMode["FARMEWORK"] = "framework";
|
|
7
|
+
APIMode["FUNCTION"] = "function";
|
|
8
|
+
})(APIMode || (APIMode = {}));
|
|
9
|
+
|
|
10
|
+
export const FRAMEWORK_MODE_LAMBDA_DIR = 'lambda';
|
|
11
|
+
export const FRAMEWORK_MODE_APP_DIR = 'app';
|
|
12
|
+
export const INDEX_SUFFIX = 'index';
|
|
13
|
+
export const API_DIR = 'api';
|
|
14
|
+
export const API_FILE_RULES = ['**/*.[tj]s', '!**/_*', '!**/_*/**/*.[tj]s', '!**/*.test.js', '!**/*.test.ts', '!**/*.d.ts', '!__test__/*.ts', '!__tests__/*.ts', '!node_modules/**', '!bootstrap.js'];
|