bootpress 9.0.0 → 9.0.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/README.md +12 -4
- package/index.js +21 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -219,7 +219,15 @@ There must be only one element in an array schema which defines ````ArrayOf<Sche
|
|
|
219
219
|
### **asStrict(any, string | object | array)**
|
|
220
220
|
Same as 'as' method but doesn't try to parse different types instead throws error.
|
|
221
221
|
|
|
222
|
-
|
|
222
|
+
# Release Notes
|
|
223
|
+
|
|
224
|
+
## v9.0.2:
|
|
225
|
+
- Added support for null/undefined returning async functions
|
|
226
|
+
|
|
227
|
+
## v9.0.1:
|
|
228
|
+
- Fixed errors in argument passers
|
|
229
|
+
|
|
230
|
+
## v9.0.0:
|
|
223
231
|
- New Feature:
|
|
224
232
|
- Type checking for each argument while passing arguments to service methods
|
|
225
233
|
- Deprecated:
|
|
@@ -228,14 +236,14 @@ Same as 'as' method but doesn't try to parse different types instead throws erro
|
|
|
228
236
|
- Added:
|
|
229
237
|
- PassQuery, PassCookie, PassParam
|
|
230
238
|
|
|
231
|
-
## v8.0.0
|
|
239
|
+
## v8.0.0:
|
|
232
240
|
- Added support for async service functions. (You don't need to await if you wrapped your service with Bootpress functions)
|
|
233
241
|
- Bugfix for falsy response values
|
|
234
242
|
- Simplified implementation
|
|
235
243
|
|
|
236
|
-
## v7.1.0
|
|
244
|
+
## v7.1.0:
|
|
237
245
|
- getOrThrow: Throws specified error when value is an empty array too.
|
|
238
|
-
## v7.0.0
|
|
246
|
+
## v7.0.0:
|
|
239
247
|
|
|
240
248
|
### Deprecated helper methods:
|
|
241
249
|
- asSchema
|
package/index.js
CHANGED
|
@@ -42,7 +42,11 @@ function RestService(service) {
|
|
|
42
42
|
}
|
|
43
43
|
else if (result instanceof Promise) {
|
|
44
44
|
result.then(r => {
|
|
45
|
-
|
|
45
|
+
if (r == undefined) {
|
|
46
|
+
reply(res, 204, null);
|
|
47
|
+
} else {
|
|
48
|
+
reply(res, r.status ?? 200, r.data ?? r);
|
|
49
|
+
}
|
|
46
50
|
}).catch(e => {
|
|
47
51
|
reply(res, e.status ?? 500, e.message ?? e);
|
|
48
52
|
})
|
|
@@ -70,7 +74,11 @@ function RestMethod(callback) {
|
|
|
70
74
|
}
|
|
71
75
|
else if (result instanceof Promise) {
|
|
72
76
|
result.then(r => {
|
|
73
|
-
|
|
77
|
+
if (r == undefined) {
|
|
78
|
+
reply(res, 204, undefined);
|
|
79
|
+
} else {
|
|
80
|
+
reply(res, r.status ?? 200, r.data ?? r);
|
|
81
|
+
}
|
|
74
82
|
}).catch(e => {
|
|
75
83
|
reply(res, e.status ?? 500, e.message ?? e);
|
|
76
84
|
})
|
|
@@ -96,7 +104,11 @@ function Restify(target, key, desc) {
|
|
|
96
104
|
}
|
|
97
105
|
else if (result instanceof Promise) {
|
|
98
106
|
result.then(r => {
|
|
99
|
-
|
|
107
|
+
if (r == undefined) {
|
|
108
|
+
reply(res, 204, null);
|
|
109
|
+
} else {
|
|
110
|
+
reply(res, r.status ?? 200, r.data ?? r);
|
|
111
|
+
}
|
|
100
112
|
}).catch(e => {
|
|
101
113
|
reply(res, e.status ?? 500, e.message ?? e);
|
|
102
114
|
})
|
|
@@ -127,12 +139,12 @@ function isRequstHandlerArgs(args) {
|
|
|
127
139
|
function PassParam(paramName) {
|
|
128
140
|
return (actualHandler) => {
|
|
129
141
|
return (...args) => {
|
|
130
|
-
const paramToPass = req.params[paramName];
|
|
131
142
|
if (isRequstHandlerArgs(args)) {
|
|
132
143
|
const req = args.at(-3); const res = args.at(-2);
|
|
144
|
+
const paramToPass = req.params[paramName];
|
|
133
145
|
return actualHandler(paramToPass)(req, res);
|
|
134
146
|
} else {
|
|
135
|
-
return (req, res) => actualHandler(...args, paramToPass)(req, res);
|
|
147
|
+
return (req, res) => { const paramToPass = req.params[paramName]; actualHandler(...args, paramToPass)(req, res); };
|
|
136
148
|
}
|
|
137
149
|
}
|
|
138
150
|
}
|
|
@@ -141,12 +153,12 @@ function PassParam(paramName) {
|
|
|
141
153
|
function PassQuery(searchQuery) {
|
|
142
154
|
return (actualHandler) => {
|
|
143
155
|
return (...args) => {
|
|
144
|
-
const paramToPass = req.query[searchQuery];
|
|
145
156
|
if (isRequstHandlerArgs(args)) {
|
|
146
157
|
const req = args.at(-3); const res = args.at(-2);
|
|
158
|
+
const paramToPass = req.query[searchQuery];
|
|
147
159
|
return actualHandler(paramToPass)(req, res);
|
|
148
160
|
} else {
|
|
149
|
-
return (req, res) => actualHandler(...args, paramToPass)(req, res);
|
|
161
|
+
return (req, res) => { const paramToPass = req.query[searchQuery]; actualHandler(...args, paramToPass)(req, res); };
|
|
150
162
|
}
|
|
151
163
|
}
|
|
152
164
|
}
|
|
@@ -280,12 +292,12 @@ function PassAllCookies(actualHandler) {
|
|
|
280
292
|
function PassCookie(cookieName) {
|
|
281
293
|
return (actualHandler) => {
|
|
282
294
|
return (...args) => {
|
|
283
|
-
const cookie = req.cookies[cookieName];
|
|
284
295
|
if (isRequstHandlerArgs(args)) {
|
|
285
296
|
const req = args.at(-3); const res = args.at(-2);
|
|
297
|
+
const cookie = req.cookies[cookieName];
|
|
286
298
|
return actualHandler(cookie)(req, res);
|
|
287
299
|
} else {
|
|
288
|
-
return (req, res) => actualHandler(...args, cookie)(req, res);
|
|
300
|
+
return (req, res) => { const cookie = req.cookies[cookieName]; actualHandler(...args, cookie)(req, res); };
|
|
289
301
|
}
|
|
290
302
|
}
|
|
291
303
|
}
|