spice-js 2.5.17 → 2.5.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/build/bootstrap/seed.js +21 -0
- package/build/docs/generator.js +6 -6
- package/build/index.js +7 -5
- package/build/utility/RestHelper.js +19 -11
- package/package.json +2 -2
- package/src/bootstrap/seed.js +16 -0
- package/src/docs/generator.js +28 -26
- package/src/index.js +3 -2
- package/src/models/SpiceModel.js +1 -1
- package/src/utility/RestHelper.js +151 -136
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _path = _interopRequireDefault(require("path"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
spice.seeds = {};
|
|
8
|
+
|
|
9
|
+
var paths = _path.default.join(spice.root_path, "seeds");
|
|
10
|
+
|
|
11
|
+
require("fs").readdirSync(paths).forEach(function (file) {
|
|
12
|
+
if (file != "index.js") {
|
|
13
|
+
var seed = require(_path.default.join(paths, file));
|
|
14
|
+
|
|
15
|
+
spice.seeds[file.split(".")[0]] = seed;
|
|
16
|
+
|
|
17
|
+
if (seed.run) {
|
|
18
|
+
seed.run();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
package/build/docs/generator.js
CHANGED
|
@@ -103,16 +103,16 @@ function getRoutes(models) {
|
|
|
103
103
|
produces: ["application/json"]
|
|
104
104
|
};
|
|
105
105
|
_path.responses = {
|
|
106
|
-
|
|
106
|
+
200: {
|
|
107
107
|
description: "Successful Operation"
|
|
108
108
|
},
|
|
109
|
-
|
|
109
|
+
401: {
|
|
110
110
|
description: "Authentication Error"
|
|
111
111
|
},
|
|
112
|
-
|
|
112
|
+
400: {
|
|
113
113
|
description: "Bad Request"
|
|
114
114
|
},
|
|
115
|
-
|
|
115
|
+
404: {
|
|
116
116
|
description: "Not found"
|
|
117
117
|
}
|
|
118
118
|
};
|
|
@@ -427,8 +427,8 @@ function _generateSpec() {
|
|
|
427
427
|
security: [{
|
|
428
428
|
Bearer: []
|
|
429
429
|
}],
|
|
430
|
-
host: spice.config.spice.host + ":" + spice.config.spice.port,
|
|
431
|
-
port:
|
|
430
|
+
host: spice.config.spice.host + ":" + (spice.config.spice.external_port || spice.config.spice.port),
|
|
431
|
+
port: spice.config.spice.external_port || spice.config.spice.port,
|
|
432
432
|
basePath: "/",
|
|
433
433
|
tags: generateTags(),
|
|
434
434
|
paths: generatePaths(routes),
|
package/build/index.js
CHANGED
|
@@ -77,6 +77,8 @@ var _tasks = _interopRequireDefault(require("./bootstrap/tasks"));
|
|
|
77
77
|
|
|
78
78
|
exports.addTask = _tasks.default;
|
|
79
79
|
|
|
80
|
+
var _koa2SwaggerUi = require("koa2-swagger-ui");
|
|
81
|
+
|
|
80
82
|
var _generator = _interopRequireDefault(require("./docs/generator"));
|
|
81
83
|
|
|
82
84
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -104,8 +106,6 @@ spice.module_root_path = path.resolve(__dirname);
|
|
|
104
106
|
|
|
105
107
|
var convert = require("koa-convert");
|
|
106
108
|
|
|
107
|
-
var koaSwagger = require("koa2-swagger-ui");
|
|
108
|
-
|
|
109
109
|
spice.classes = {};
|
|
110
110
|
/* spice.classes.Event = Event;
|
|
111
111
|
spice.classes.Serializer = Serializer;
|
|
@@ -151,7 +151,7 @@ class Spice {
|
|
|
151
151
|
console.log("Connection Up", sock);
|
|
152
152
|
}); */
|
|
153
153
|
|
|
154
|
-
app.use(koaSwagger({
|
|
154
|
+
app.use((0, _koa2SwaggerUi.koaSwagger)({
|
|
155
155
|
hideTopbar: true,
|
|
156
156
|
title: "Spice JS",
|
|
157
157
|
routePrefix: "/docs",
|
|
@@ -159,8 +159,10 @@ class Spice {
|
|
|
159
159
|
swaggerOptions: {
|
|
160
160
|
spec: yield (0, _generator.default)(),
|
|
161
161
|
deepLinking: true,
|
|
162
|
-
displayRequestDuration: true
|
|
163
|
-
|
|
162
|
+
displayRequestDuration: true,
|
|
163
|
+
jsonEditor: true
|
|
164
|
+
},
|
|
165
|
+
exposeSpec: true
|
|
164
166
|
}));
|
|
165
167
|
yield require("./loaders").load();
|
|
166
168
|
return spice;
|
|
@@ -13,13 +13,13 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
13
13
|
|
|
14
14
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
15
15
|
|
|
16
|
-
var fs = require(
|
|
16
|
+
var fs = require("fs");
|
|
17
17
|
|
|
18
|
-
var path = require(
|
|
18
|
+
var path = require("path");
|
|
19
19
|
|
|
20
20
|
var {
|
|
21
21
|
parse
|
|
22
|
-
} = require(
|
|
22
|
+
} = require("json2csv");
|
|
23
23
|
|
|
24
24
|
class RestHelper {
|
|
25
25
|
constructor() {}
|
|
@@ -54,6 +54,14 @@ class RestHelper {
|
|
|
54
54
|
})();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
static clear_pagination(ctx, next) {
|
|
58
|
+
return _asyncToGenerator(function* () {
|
|
59
|
+
delete ctx.query.limit;
|
|
60
|
+
delete ctx.query.offset;
|
|
61
|
+
yield next();
|
|
62
|
+
})();
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
static send_download(ctx, next) {
|
|
58
66
|
return _asyncToGenerator(function* () {
|
|
59
67
|
function makeDirectory(dir) {
|
|
@@ -63,10 +71,10 @@ class RestHelper {
|
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
try {
|
|
66
|
-
var download_type = ctx.request.query.format ||
|
|
74
|
+
var download_type = ctx.request.query.format || "csv";
|
|
67
75
|
var content;
|
|
68
76
|
|
|
69
|
-
if (download_type ==
|
|
77
|
+
if (download_type == "csv") {
|
|
70
78
|
var items = _lodash.default.map(ctx.data, item => {
|
|
71
79
|
return (0, _flat.default)(item);
|
|
72
80
|
});
|
|
@@ -77,10 +85,10 @@ class RestHelper {
|
|
|
77
85
|
fields
|
|
78
86
|
};
|
|
79
87
|
content = parse(items, opts);
|
|
80
|
-
ctx.set(
|
|
88
|
+
ctx.set("content-type", "text/csv");
|
|
81
89
|
} else {
|
|
82
90
|
content = JSON.stringify(ctx.data);
|
|
83
|
-
ctx.set(
|
|
91
|
+
ctx.set("content-type", "application/json");
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
makeDirectory("./storage/exports");
|
|
@@ -89,7 +97,7 @@ class RestHelper {
|
|
|
89
97
|
yield fs.writeFile(file, content, function (err) {
|
|
90
98
|
if (err) throw err;
|
|
91
99
|
});
|
|
92
|
-
ctx.set(
|
|
100
|
+
ctx.set("content-disposition", "attachment");
|
|
93
101
|
ctx.response.attachment(file);
|
|
94
102
|
ctx.status = 200;
|
|
95
103
|
ctx.body = fs.createReadStream(file);
|
|
@@ -102,8 +110,8 @@ class RestHelper {
|
|
|
102
110
|
}
|
|
103
111
|
|
|
104
112
|
static makeid(length) {
|
|
105
|
-
var result =
|
|
106
|
-
var characters =
|
|
113
|
+
var result = "";
|
|
114
|
+
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
107
115
|
var charactersLength = characters.length;
|
|
108
116
|
|
|
109
117
|
for (var i = 0; i < length; i++) {
|
|
@@ -175,7 +183,7 @@ class RestHelper {
|
|
|
175
183
|
} catch (error) {
|
|
176
184
|
try {
|
|
177
185
|
if (value.toLowerCase() == "true" || value.toLowerCase() == "false") {
|
|
178
|
-
returnValue = value ===
|
|
186
|
+
returnValue = value === "true";
|
|
179
187
|
return returnValue;
|
|
180
188
|
} else {
|
|
181
189
|
throw Error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spice-js",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.18",
|
|
4
4
|
"description": "spice",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"koa-static": "^5.0.0",
|
|
31
31
|
"koa-validation": "^0.1.9",
|
|
32
32
|
"koa-views": "^6.2.3",
|
|
33
|
-
"koa2-swagger-ui": "^
|
|
33
|
+
"koa2-swagger-ui": "^5.5.1",
|
|
34
34
|
"lodash": "^4.17.15",
|
|
35
35
|
"nunjucks": "^3.2.0",
|
|
36
36
|
"open": "7.0.0",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
|
|
3
|
+
spice.seeds = {};
|
|
4
|
+
|
|
5
|
+
let paths = path.join(spice.root_path, "seeds");
|
|
6
|
+
require("fs")
|
|
7
|
+
.readdirSync(paths)
|
|
8
|
+
.forEach(function (file) {
|
|
9
|
+
if (file != "index.js") {
|
|
10
|
+
let seed = require(path.join(paths, file));
|
|
11
|
+
spice.seeds[file.split(".")[0]] = seed;
|
|
12
|
+
if (seed.run) {
|
|
13
|
+
seed.run();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
package/src/docs/generator.js
CHANGED
|
@@ -82,16 +82,16 @@ function getRoutes(models) {
|
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
path.responses = {
|
|
85
|
-
|
|
85
|
+
200: {
|
|
86
86
|
description: "Successful Operation",
|
|
87
87
|
},
|
|
88
|
-
|
|
88
|
+
401: {
|
|
89
89
|
description: "Authentication Error",
|
|
90
90
|
},
|
|
91
|
-
|
|
91
|
+
400: {
|
|
92
92
|
description: "Bad Request",
|
|
93
93
|
},
|
|
94
|
-
|
|
94
|
+
404: {
|
|
95
95
|
description: "Not found",
|
|
96
96
|
},
|
|
97
97
|
};
|
|
@@ -271,27 +271,27 @@ function getProperties(obj) {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
if (map != undefined && map.type == "model") {
|
|
274
|
-
if(map.reference != undefined){
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
274
|
+
if (map.reference != undefined) {
|
|
275
|
+
let references = _.isArray(map.reference)
|
|
276
|
+
? map.reference
|
|
277
|
+
: [map.reference];
|
|
278
|
+
let reference = `#/definitions/${
|
|
279
|
+
_.isString(map.reference) ? map.reference : references[0].name
|
|
280
|
+
}`;
|
|
281
|
+
if (to_return.type == "array") {
|
|
282
|
+
to_return.items.$ref = reference;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (to_return.type == "object") {
|
|
286
|
+
to_return.$ref = reference;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (to_return.type == "string") {
|
|
290
|
+
to_return.type = "object";
|
|
291
|
+
to_return.readOnly = true;
|
|
292
|
+
to_return.$ref = reference;
|
|
293
|
+
}
|
|
283
294
|
}
|
|
284
|
-
|
|
285
|
-
if (to_return.type == "object") {
|
|
286
|
-
to_return.$ref = reference;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (to_return.type == "string") {
|
|
290
|
-
to_return.type = "object";
|
|
291
|
-
to_return.readOnly = true;
|
|
292
|
-
to_return.$ref = reference;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
295
|
}
|
|
296
296
|
return to_return;
|
|
297
297
|
});
|
|
@@ -372,8 +372,10 @@ export default async function generateSpec() {
|
|
|
372
372
|
},
|
|
373
373
|
],
|
|
374
374
|
|
|
375
|
-
host: `${spice.config.spice.host}:${
|
|
376
|
-
|
|
375
|
+
host: `${spice.config.spice.host}:${
|
|
376
|
+
spice.config.spice.external_port || spice.config.spice.port
|
|
377
|
+
}`,
|
|
378
|
+
port: spice.config.spice.external_port || spice.config.spice.port,
|
|
377
379
|
basePath: "/",
|
|
378
380
|
tags: generateTags(),
|
|
379
381
|
paths: generatePaths(routes),
|
package/src/index.js
CHANGED
|
@@ -38,8 +38,7 @@ export { default as MailFile } from "./mail/providers/File";
|
|
|
38
38
|
export { default as MapType } from "./utility/MapType";
|
|
39
39
|
export { default as addTask } from "./bootstrap/tasks";
|
|
40
40
|
const convert = require("koa-convert");
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
import { koaSwagger } from "koa2-swagger-ui";
|
|
43
42
|
spice.classes = {};
|
|
44
43
|
/* spice.classes.Event = Event;
|
|
45
44
|
spice.classes.Serializer = Serializer;
|
|
@@ -90,7 +89,9 @@ export default class Spice {
|
|
|
90
89
|
spec: await docGen(),
|
|
91
90
|
deepLinking: true,
|
|
92
91
|
displayRequestDuration: true,
|
|
92
|
+
jsonEditor: true,
|
|
93
93
|
},
|
|
94
|
+
exposeSpec: true,
|
|
94
95
|
})
|
|
95
96
|
);
|
|
96
97
|
await require("./loaders").load();
|
package/src/models/SpiceModel.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import flatten from
|
|
2
|
-
import _ from "lodash"
|
|
3
|
-
const fs = require(
|
|
4
|
-
const path = require(
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
parse
|
|
8
|
-
} = require('json2csv');
|
|
1
|
+
import flatten from "flat";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
|
|
6
|
+
const { parse } = require("json2csv");
|
|
9
7
|
export default class RestHelper {
|
|
10
8
|
constructor() { }
|
|
11
9
|
static async clear_pagination(ctx, next) {
|
|
@@ -31,150 +29,167 @@ export default class RestHelper {
|
|
|
31
29
|
console.log("Error at response: ", e, e.stack);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
32
|
+
|
|
34
33
|
|
|
35
|
-
static async
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
try {
|
|
42
|
-
let download_type = ctx.request.query.format || 'csv';
|
|
43
|
-
let content;
|
|
44
|
-
if (download_type == 'csv') {
|
|
45
|
-
let items = _.map(ctx.data, item => {
|
|
46
|
-
return flatten(item);
|
|
47
|
-
});
|
|
48
|
-
let fields = _.union(_.keys(_.first(items)), _.keys(_.last(items)), _.keys(_.nth(items.length / 2)));
|
|
49
|
-
const opts = {
|
|
50
|
-
fields
|
|
51
|
-
};
|
|
52
|
-
content = parse(items, opts);
|
|
53
|
-
ctx.set('content-type', 'text/csv');
|
|
54
|
-
} else {
|
|
55
|
-
content = JSON.stringify(ctx.data);
|
|
56
|
-
ctx.set('content-type', 'application/json');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
makeDirectory(`./storage/exports`);
|
|
60
|
-
makeDirectory(`./storage/exports/${download_type}/`);
|
|
61
|
-
let file = path.resolve(`./storage/exports/${download_type}/${RestHelper.makeid(9)}.${download_type}`);
|
|
62
|
-
await fs.writeFile(file, content, function (err) {
|
|
63
|
-
if (err) throw err;
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
ctx.set('content-disposition', 'attachment');
|
|
67
|
-
ctx.response.attachment(file);
|
|
68
|
-
ctx.status = 200;
|
|
69
|
-
ctx.body = fs.createReadStream(file);
|
|
70
|
-
} catch (e) {
|
|
71
|
-
console.log(e.stack)
|
|
72
|
-
ctx.status = 400;
|
|
73
|
-
ctx.body = RestHelper.prepare_response(RestHelper.FAILURE, e);
|
|
74
|
-
}
|
|
34
|
+
static async clear_pagination(ctx, next) {
|
|
35
|
+
delete ctx.query.limit;
|
|
36
|
+
delete ctx.query.offset;
|
|
37
|
+
await next();
|
|
75
38
|
}
|
|
76
39
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
83
|
-
}
|
|
84
|
-
return result;
|
|
40
|
+
static async send_download(ctx, next) {
|
|
41
|
+
function makeDirectory(dir) {
|
|
42
|
+
if (!fs.existsSync(dir)) {
|
|
43
|
+
fs.mkdirSync(dir);
|
|
44
|
+
}
|
|
85
45
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
data
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
46
|
+
try {
|
|
47
|
+
let download_type = ctx.request.query.format || "csv";
|
|
48
|
+
let content;
|
|
49
|
+
if (download_type == "csv") {
|
|
50
|
+
let items = _.map(ctx.data, (item) => {
|
|
51
|
+
return flatten(item);
|
|
52
|
+
});
|
|
53
|
+
let fields = _.union(
|
|
54
|
+
_.keys(_.first(items)),
|
|
55
|
+
_.keys(_.last(items)),
|
|
56
|
+
_.keys(_.nth(items.length / 2))
|
|
57
|
+
);
|
|
58
|
+
const opts = {
|
|
59
|
+
fields,
|
|
60
|
+
};
|
|
61
|
+
content = parse(items, opts);
|
|
62
|
+
ctx.set("content-type", "text/csv");
|
|
63
|
+
} else {
|
|
64
|
+
content = JSON.stringify(ctx.data);
|
|
65
|
+
ctx.set("content-type", "application/json");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
makeDirectory(`./storage/exports`);
|
|
69
|
+
makeDirectory(`./storage/exports/${download_type}/`);
|
|
70
|
+
let file = path.resolve(
|
|
71
|
+
`./storage/exports/${download_type}/${RestHelper.makeid(
|
|
72
|
+
9
|
|
73
|
+
)}.${download_type}`
|
|
74
|
+
);
|
|
75
|
+
await fs.writeFile(file, content, function (err) {
|
|
76
|
+
if (err) throw err;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
ctx.set("content-disposition", "attachment");
|
|
80
|
+
ctx.response.attachment(file);
|
|
81
|
+
ctx.status = 200;
|
|
82
|
+
ctx.body = fs.createReadStream(file);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.log(e.stack);
|
|
85
|
+
ctx.status = 400;
|
|
86
|
+
ctx.body = RestHelper.prepare_response(RestHelper.FAILURE, e);
|
|
104
87
|
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static makeid(length) {
|
|
91
|
+
var result = "";
|
|
92
|
+
var characters =
|
|
93
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
94
|
+
var charactersLength = characters.length;
|
|
95
|
+
for (var i = 0; i < length; i++) {
|
|
96
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
static SUCCESS = "SUCCESS";
|
|
102
|
+
static FAILURE = "FAILURE";
|
|
103
|
+
static prepare_collection(
|
|
104
|
+
status,
|
|
105
|
+
obj = {
|
|
106
|
+
data: [],
|
|
107
|
+
total: null,
|
|
108
|
+
}
|
|
109
|
+
) {
|
|
110
|
+
var data = {
|
|
111
|
+
status: status,
|
|
112
|
+
type: "collection",
|
|
113
|
+
count: obj.data.length,
|
|
114
|
+
data: obj.data,
|
|
115
|
+
total: obj.total,
|
|
116
|
+
};
|
|
117
|
+
if (obj.total == null || obj.total == undefined) {
|
|
118
|
+
delete data.total;
|
|
119
|
+
}
|
|
120
|
+
return data;
|
|
121
|
+
}
|
|
105
122
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (token) {
|
|
113
|
-
response.token = token;
|
|
114
|
-
}
|
|
123
|
+
static prepare_response(status, data, errors, token) {
|
|
124
|
+
var response = {
|
|
125
|
+
status: status,
|
|
126
|
+
type: "single",
|
|
127
|
+
};
|
|
115
128
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
response.errors = errors;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
if (data) {
|
|
123
|
-
response.data = data;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
129
|
+
if (token) {
|
|
130
|
+
response.token = token;
|
|
131
|
+
}
|
|
126
132
|
|
|
127
|
-
|
|
133
|
+
if (status == this.FAILURE) {
|
|
134
|
+
response.message = data;
|
|
135
|
+
if (errors) {
|
|
136
|
+
response.errors = errors;
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
if (data) {
|
|
140
|
+
response.data = data;
|
|
141
|
+
}
|
|
128
142
|
}
|
|
129
143
|
|
|
130
|
-
|
|
131
|
-
|
|
144
|
+
return response;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static get_typed_value(value) {
|
|
148
|
+
var returnValue;
|
|
149
|
+
try {
|
|
150
|
+
returnValue = Number(value);
|
|
151
|
+
if (isNaN(returnValue)) {
|
|
152
|
+
throw returnValue;
|
|
153
|
+
} else {
|
|
154
|
+
return returnValue;
|
|
155
|
+
}
|
|
156
|
+
} catch (error) {
|
|
157
|
+
try {
|
|
158
|
+
if (value.toLowerCase() == "true" || value.toLowerCase() == "false") {
|
|
159
|
+
returnValue = value === "true";
|
|
160
|
+
return returnValue;
|
|
161
|
+
} else {
|
|
162
|
+
throw Error;
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
132
165
|
try {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
throw returnValue;
|
|
136
|
-
} else {
|
|
137
|
-
return returnValue;
|
|
138
|
-
}
|
|
139
|
-
|
|
166
|
+
returnValue = JSON.parse(value);
|
|
167
|
+
return returnValue;
|
|
140
168
|
} catch (error) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
} catch (error) {
|
|
149
|
-
try {
|
|
150
|
-
returnValue = JSON.parse(value);
|
|
151
|
-
return returnValue;
|
|
152
|
-
} catch (error) {
|
|
153
|
-
try {
|
|
154
|
-
returnValue = String(value);
|
|
155
|
-
return returnValue;
|
|
156
|
-
} catch (error) {
|
|
157
|
-
console.log("Cant parse" + value);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
169
|
+
try {
|
|
170
|
+
returnValue = String(value);
|
|
171
|
+
return returnValue;
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.log("Cant parse" + value);
|
|
174
|
+
}
|
|
161
175
|
}
|
|
176
|
+
}
|
|
162
177
|
}
|
|
178
|
+
}
|
|
163
179
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (isNaN(port)) {
|
|
168
|
-
// named pipe
|
|
169
|
-
return val;
|
|
170
|
-
}
|
|
180
|
+
static normalizePort(val) {
|
|
181
|
+
var port = parseInt(val, 10);
|
|
171
182
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
183
|
+
if (isNaN(port)) {
|
|
184
|
+
// named pipe
|
|
185
|
+
return val;
|
|
186
|
+
}
|
|
176
187
|
|
|
177
|
-
|
|
188
|
+
if (port >= 0) {
|
|
189
|
+
// port number
|
|
190
|
+
return port;
|
|
178
191
|
}
|
|
179
192
|
|
|
180
|
-
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
}
|