express-ext 0.1.17 → 0.1.18
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/lib/http.js +3 -0
- package/lib/resources.js +1 -1
- package/package.json +1 -1
- package/src/http.ts +3 -0
- package/src/resources.ts +14 -1
package/lib/http.js
CHANGED
|
@@ -10,6 +10,7 @@ function handleError(err, res, log) {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
exports.handleError = handleError;
|
|
13
|
+
exports.error = handleError;
|
|
13
14
|
function toString(v) {
|
|
14
15
|
if (typeof v === 'string') {
|
|
15
16
|
return v;
|
|
@@ -174,6 +175,7 @@ function param(req, res, name) {
|
|
|
174
175
|
return v;
|
|
175
176
|
}
|
|
176
177
|
exports.param = param;
|
|
178
|
+
exports.getParam = param;
|
|
177
179
|
function params(req, name, d, split) {
|
|
178
180
|
var v = req.params[name];
|
|
179
181
|
if (!v || v.length === 0) {
|
|
@@ -185,6 +187,7 @@ function params(req, name, d, split) {
|
|
|
185
187
|
return v.split(split);
|
|
186
188
|
}
|
|
187
189
|
exports.params = params;
|
|
190
|
+
exports.getParams = params;
|
|
188
191
|
function getRequiredParameters(req, res, name, split) {
|
|
189
192
|
var v = req.params[name];
|
|
190
193
|
if (!v || v.length === 0) {
|
package/lib/resources.js
CHANGED
|
@@ -17,7 +17,7 @@ var TypeChecker = (function () {
|
|
|
17
17
|
TypeChecker.prototype.check = function (req, res, next) {
|
|
18
18
|
var obj = req.body;
|
|
19
19
|
if (!obj || obj === '') {
|
|
20
|
-
|
|
20
|
+
res.status(400).end('The request body cannot be empty');
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
var errors = resources.check(obj, this.attributes, this.allowUndefined);
|
package/package.json
CHANGED
package/src/http.ts
CHANGED
|
@@ -11,6 +11,7 @@ export function handleError(err: any, res: Response, log?: (msg: string) => void
|
|
|
11
11
|
res.status(500).end(toString(err));
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
+
export const error = handleError;
|
|
14
15
|
export function toString(v: any): string {
|
|
15
16
|
if (typeof v === 'string') {
|
|
16
17
|
return v;
|
|
@@ -158,6 +159,7 @@ export function param(req: Request, res: Response, name: string): string|undefin
|
|
|
158
159
|
}
|
|
159
160
|
return v;
|
|
160
161
|
}
|
|
162
|
+
export const getParam = param;
|
|
161
163
|
export function params(req: Request, name: string, d?: string[], split?: string): string[]|undefined {
|
|
162
164
|
const v = req.params[name];
|
|
163
165
|
if (!v || v.length === 0) {
|
|
@@ -168,6 +170,7 @@ export function params(req: Request, name: string, d?: string[], split?: string)
|
|
|
168
170
|
}
|
|
169
171
|
return v.split(split);
|
|
170
172
|
}
|
|
173
|
+
export const getParams = params;
|
|
171
174
|
export function getRequiredParameters(req: Request, res: Response, name: string, split?: string): string[]|undefined {
|
|
172
175
|
const v = req.params[name];
|
|
173
176
|
if (!v || v.length === 0) {
|
package/src/resources.ts
CHANGED
|
@@ -21,7 +21,7 @@ export class TypeChecker {
|
|
|
21
21
|
check(req: Request, res: Response, next: NextFunction): void {
|
|
22
22
|
const obj = req.body;
|
|
23
23
|
if (!obj || (obj as any) === '') {
|
|
24
|
-
|
|
24
|
+
res.status(400).end('The request body cannot be empty');
|
|
25
25
|
} else {
|
|
26
26
|
const errors = resources.check(obj, this.attributes, this.allowUndefined);
|
|
27
27
|
if (errors.length > 0) {
|
|
@@ -37,6 +37,14 @@ export function check(attributes: Attributes, allowUndefined?: boolean): Handler
|
|
|
37
37
|
const x = new TypeChecker(attributes, allowUndefined);
|
|
38
38
|
return x.check;
|
|
39
39
|
}
|
|
40
|
+
export interface Parameter {
|
|
41
|
+
name: string;
|
|
42
|
+
type: string;
|
|
43
|
+
}
|
|
44
|
+
export interface StringFormat {
|
|
45
|
+
texts: string[];
|
|
46
|
+
parameters: Parameter[];
|
|
47
|
+
}
|
|
40
48
|
export interface Template {
|
|
41
49
|
name?: string | null;
|
|
42
50
|
text: string;
|
|
@@ -48,6 +56,11 @@ export interface TemplateNode {
|
|
|
48
56
|
property: string | null;
|
|
49
57
|
encode?: string | null;
|
|
50
58
|
value: string | null;
|
|
59
|
+
format: StringFormat;
|
|
60
|
+
array?: string | null;
|
|
61
|
+
separator?: string | null;
|
|
62
|
+
suffix?: string | null;
|
|
63
|
+
prefix?: string | null;
|
|
51
64
|
}
|
|
52
65
|
export function loadTemplates(ok: boolean|undefined, buildTemplates: (streams: string[], correct?: (stream: string) => string) => Map<string, Template>, correct?: (stream: string) => string, files?: string[]): Map<string, Template>|undefined {
|
|
53
66
|
if (!ok) {
|