speedly 1.0.0 → 1.1.1
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 +280 -0
- package/dist/cjs/auth/auth.js +86 -0
- package/dist/cjs/db/db.d.ts +181 -0
- package/dist/cjs/db/db.js +485 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/model/translation.d.ts +59 -0
- package/dist/cjs/model/translation.js +13 -0
- package/dist/{modules/auth.d.ts → cjs/uploader/uploader.d.ts} +1 -1
- package/dist/cjs/uploader/uploader.js +150 -0
- package/dist/cjs/util/getConfig.d.ts +4 -0
- package/dist/cjs/util/getConfig.js +21 -0
- package/dist/cjs/util/strToObj.d.ts +2 -0
- package/dist/cjs/util/strToObj.js +9 -0
- package/dist/cjs/util/translator.d.ts +2 -0
- package/dist/cjs/util/translator.js +67 -0
- package/dist/cjs/validator/validator.d.ts +9 -0
- package/dist/cjs/validator/validator.js +32 -0
- package/dist/esm/auth/auth.js +86 -0
- package/dist/esm/db/db.d.ts +181 -0
- package/dist/esm/db/db.js +485 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +44 -0
- package/dist/esm/model/translation.d.ts +59 -0
- package/dist/esm/model/translation.js +13 -0
- package/dist/{modules/db.d.ts → esm/uploader/uploader.d.ts} +1 -1
- package/dist/esm/uploader/uploader.js +150 -0
- package/dist/esm/util/getConfig.d.ts +4 -0
- package/dist/esm/util/getConfig.js +21 -0
- package/dist/esm/util/strToObj.d.ts +2 -0
- package/dist/esm/util/strToObj.js +9 -0
- package/dist/esm/util/translator.d.ts +2 -0
- package/dist/esm/util/translator.js +67 -0
- package/dist/esm/validator/validator.d.ts +9 -0
- package/dist/esm/validator/validator.js +32 -0
- package/package.json +28 -15
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -1
- package/dist/modules/auth.js +0 -68
- package/dist/modules/db/aggregation.d.ts +0 -0
- package/dist/modules/db/aggregation.js +0 -1
- package/dist/modules/db/aggregation.types.d.ts +0 -56
- package/dist/modules/db/aggregation.types.js +0 -2
- package/dist/modules/db/db.d.ts +0 -0
- package/dist/modules/db/db.js +0 -1
- package/dist/modules/db/db.type.js +0 -2
- package/dist/modules/db.js +0 -228
- package/dist/modules/types/db.d.ts +0 -38
- package/dist/modules/types/db.js +0 -1
- package/dist/modules/uploader.js +0 -57
- package/dist/modules/utils.d.ts +0 -0
- package/dist/modules/utils.js +0 -1
- package/dist/modules/validator.d.ts +0 -1
- package/dist/modules/validator.js +0 -47
- package/dist/utils/strToObj.d.ts +0 -0
- package/dist/utils/strToObj.js +0 -8
- /package/dist/{modules/db/db.type.d.ts → cjs/auth/auth.d.ts} +0 -0
- /package/dist/{modules/uploader.d.ts → esm/auth/auth.d.ts} +0 -0
package/dist/modules/db.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
let __path = "./models/";
|
|
13
|
-
const path = require("path");
|
|
14
|
-
const strToObj = require("../utils/strToObj");
|
|
15
|
-
const db = (collectionName, config = { path: "../models" }) => {
|
|
16
|
-
let model;
|
|
17
|
-
let queryState = {
|
|
18
|
-
queries: [],
|
|
19
|
-
};
|
|
20
|
-
if (config === null || config === void 0 ? void 0 : config.path)
|
|
21
|
-
__path = config.path;
|
|
22
|
-
model = require(path.join(__path, collectionName));
|
|
23
|
-
const actionHandler = {
|
|
24
|
-
find: (match = {}) => {
|
|
25
|
-
queryState.action = "find";
|
|
26
|
-
queryState.match = match;
|
|
27
|
-
return handler;
|
|
28
|
-
},
|
|
29
|
-
aggregate: (pipelineGenerator) => {
|
|
30
|
-
},
|
|
31
|
-
create: (body = {}) => {
|
|
32
|
-
queryState.action = "create";
|
|
33
|
-
queryState.body = body;
|
|
34
|
-
return handler;
|
|
35
|
-
},
|
|
36
|
-
updateOne: (match = {}, body = {}) => {
|
|
37
|
-
queryState.action = "updateOne";
|
|
38
|
-
queryState.match = match;
|
|
39
|
-
queryState.body = body;
|
|
40
|
-
return handler;
|
|
41
|
-
},
|
|
42
|
-
updateMany: (match = {}, body = {}) => {
|
|
43
|
-
queryState.action = "updateById";
|
|
44
|
-
queryState.match = match;
|
|
45
|
-
queryState.body = body;
|
|
46
|
-
return handler;
|
|
47
|
-
},
|
|
48
|
-
deleteOne: (match = {}) => {
|
|
49
|
-
queryState.action = "deleteOne";
|
|
50
|
-
queryState.match = match;
|
|
51
|
-
return handler;
|
|
52
|
-
},
|
|
53
|
-
deleteMany: (match = {}) => {
|
|
54
|
-
queryState.action = "deleteMany";
|
|
55
|
-
queryState.match = match;
|
|
56
|
-
return handler;
|
|
57
|
-
},
|
|
58
|
-
findOne: (match = {}) => {
|
|
59
|
-
queryState.action = "findOne";
|
|
60
|
-
queryState.match = match;
|
|
61
|
-
return handler;
|
|
62
|
-
},
|
|
63
|
-
findOneAndUpdate: (match = {}, body = {}) => {
|
|
64
|
-
queryState.action = "findOneAndUpdate";
|
|
65
|
-
queryState.match = match;
|
|
66
|
-
queryState.body = body;
|
|
67
|
-
return handler;
|
|
68
|
-
},
|
|
69
|
-
findOneAndDelete: (match = {}) => {
|
|
70
|
-
queryState.action = "findOneAndDelete";
|
|
71
|
-
queryState.match = match;
|
|
72
|
-
return handler;
|
|
73
|
-
},
|
|
74
|
-
findById: (id = "") => {
|
|
75
|
-
queryState.action = "findById";
|
|
76
|
-
queryState.id = id;
|
|
77
|
-
return handler;
|
|
78
|
-
},
|
|
79
|
-
findByIdAndUpdate: (id = "", body = {}) => {
|
|
80
|
-
queryState.action = "findByIdAndUpdate";
|
|
81
|
-
queryState.id = id;
|
|
82
|
-
queryState.body = body;
|
|
83
|
-
return handler;
|
|
84
|
-
},
|
|
85
|
-
findByIdAndDelete: (id = "") => {
|
|
86
|
-
queryState.action = "findByIdAndDelete";
|
|
87
|
-
queryState.id = id;
|
|
88
|
-
return handler;
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
const handler = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
93
|
-
let data;
|
|
94
|
-
let match = {};
|
|
95
|
-
let realTimeQueries = [...queryState.queries];
|
|
96
|
-
const { sort, limit, page, select } = req.query;
|
|
97
|
-
if (req.query.search) {
|
|
98
|
-
const splittedSearch = typeof req.query.search === 'string'
|
|
99
|
-
? req.query.search.trim().split(/\s|/g)
|
|
100
|
-
: [];
|
|
101
|
-
const searchValue = splittedSearch.map(word => `(?=.*${word.split('').join('\\s?')})`).join('');
|
|
102
|
-
match.$or = [
|
|
103
|
-
{ name: { $regex: searchValue } },
|
|
104
|
-
{ title: { $regex: searchValue } },
|
|
105
|
-
{ subTitle: { $regex: searchValue } }
|
|
106
|
-
];
|
|
107
|
-
}
|
|
108
|
-
if (req.query.filters)
|
|
109
|
-
match = Object.assign(Object.assign({}, match), JSON.parse(req.query.filters));
|
|
110
|
-
if (typeof queryState.match == 'function')
|
|
111
|
-
match = Object.assign(Object.assign({}, match), queryState.match(req));
|
|
112
|
-
if (typeof queryState.match == 'object')
|
|
113
|
-
match = Object.assign(Object.assign({}, match), queryState.match);
|
|
114
|
-
{
|
|
115
|
-
if (req.query.sort) {
|
|
116
|
-
const sortQueryIndex = realTimeQueries.findIndex(q => q.type == 'sort');
|
|
117
|
-
const sortObject = strToObj(req.query.sort);
|
|
118
|
-
if (sortQueryIndex == -1)
|
|
119
|
-
realTimeQueries.push({ type: 'sort', value: sortObject });
|
|
120
|
-
else
|
|
121
|
-
realTimeQueries.splice(sortQueryIndex, 1, { type: 'sort', value: Object.assign(Object.assign({}, (typeof realTimeQueries[sortQueryIndex].value === 'object' ? realTimeQueries[sortQueryIndex].value : {})), (typeof sortObject === 'object' ? sortObject : {})) });
|
|
122
|
-
}
|
|
123
|
-
if (req.query.limit) {
|
|
124
|
-
if (realTimeQueries.findIndex(q => q.type == 'limit') == -1)
|
|
125
|
-
realTimeQueries.push({ type: 'limit', value: req.query.limit });
|
|
126
|
-
}
|
|
127
|
-
if (req.query.select) {
|
|
128
|
-
const selectQueryIndex = realTimeQueries.findIndex(q => q.type == 'select');
|
|
129
|
-
const selectObject = strToObj(req.query.select);
|
|
130
|
-
if (selectQueryIndex == -1)
|
|
131
|
-
realTimeQueries.push({ type: 'select', value: selectObject });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
try {
|
|
135
|
-
if (queryState.action) {
|
|
136
|
-
if (!data)
|
|
137
|
-
switch (queryState.action) {
|
|
138
|
-
case "find":
|
|
139
|
-
data = (_a = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _a === void 0 ? void 0 : _a.call(model, match);
|
|
140
|
-
break;
|
|
141
|
-
case "create":
|
|
142
|
-
data = (_b = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _b === void 0 ? void 0 : _b.call(model, Object.assign(Object.assign({}, req.body), (typeof queryState.body == 'function' ? queryState.body(req) : queryState.body)));
|
|
143
|
-
break;
|
|
144
|
-
case "updateOne":
|
|
145
|
-
data = (_c = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _c === void 0 ? void 0 : _c.call(model, match, Object.assign(Object.assign({}, req.body), (typeof queryState.body == 'function' ? queryState.body(req) : queryState.body)));
|
|
146
|
-
break;
|
|
147
|
-
case "updateMany":
|
|
148
|
-
data = (_d = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _d === void 0 ? void 0 : _d.call(model, match, Object.assign(Object.assign({}, req.body), (typeof queryState.body == 'function' ? queryState.body(req) : queryState.body)));
|
|
149
|
-
break;
|
|
150
|
-
case "deleteOne":
|
|
151
|
-
data = (_e = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _e === void 0 ? void 0 : _e.call(model, match);
|
|
152
|
-
break;
|
|
153
|
-
case "deleteMany":
|
|
154
|
-
data = (_f = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _f === void 0 ? void 0 : _f.call(model, match);
|
|
155
|
-
break;
|
|
156
|
-
case "findOne":
|
|
157
|
-
data = (_g = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _g === void 0 ? void 0 : _g.call(model, match);
|
|
158
|
-
break;
|
|
159
|
-
case "findOneAndUpdate":
|
|
160
|
-
yield ((_h = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _h === void 0 ? void 0 : _h.call(model, match, { $set: Object.assign(Object.assign({}, req.body), (typeof queryState.body == 'function' ? queryState.body(req) : queryState.body))
|
|
161
|
-
}));
|
|
162
|
-
data = model.findOne(match);
|
|
163
|
-
break;
|
|
164
|
-
case "findOneAndDelete":
|
|
165
|
-
data = (_j = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _j === void 0 ? void 0 : _j.call(model, match);
|
|
166
|
-
break;
|
|
167
|
-
case "findById":
|
|
168
|
-
console.log('model', 99, req.body);
|
|
169
|
-
data = (_k = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _k === void 0 ? void 0 : _k.call(model, queryState.id || req.params.id);
|
|
170
|
-
break;
|
|
171
|
-
case "findByIdAndUpdate":
|
|
172
|
-
req.document = yield model.findById(queryState.id || req.params.id);
|
|
173
|
-
yield ((_l = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _l === void 0 ? void 0 : _l.call(model, queryState.id || req.params.id, { $set: Object.assign(Object.assign({}, req.body), (typeof queryState.body == 'function' ? queryState.body(req) : queryState.body)) }));
|
|
174
|
-
data = model.findById(queryState.id || req.params.id);
|
|
175
|
-
break;
|
|
176
|
-
case "findByIdAndDelete":
|
|
177
|
-
data = (_m = model === null || model === void 0 ? void 0 : model[queryState.action]) === null || _m === void 0 ? void 0 : _m.call(model, queryState.id || req.params.id);
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
realTimeQueries.forEach((q) => {
|
|
181
|
-
var _a;
|
|
182
|
-
data = (_a = data === null || data === void 0 ? void 0 : data[q.type]) === null || _a === void 0 ? void 0 : _a.call(data, q.value);
|
|
183
|
-
});
|
|
184
|
-
// if(req.query.select) data = data.select(req.query.select)
|
|
185
|
-
data = yield data;
|
|
186
|
-
if (!data) {
|
|
187
|
-
res.status(404).json({
|
|
188
|
-
message: `${collectionName} not found.`,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
res.status(200).json({
|
|
193
|
-
content: data,
|
|
194
|
-
message: `${queryState.action.match(/create|update|delete/i) || queryState.action.match(/find/i) || queryState.action} ${collectionName} was successfully`,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
catch (err) {
|
|
200
|
-
if (((_o = err === null || err === void 0 ? void 0 : err.errorResponse) === null || _o === void 0 ? void 0 : _o.code) == 11000)
|
|
201
|
-
return res.status(403).json({ message: Object.entries(err.errorResponse.keyValue || {})[0].join(' ') + ' is duplicated' });
|
|
202
|
-
console.error("Error : model", err);
|
|
203
|
-
res.status(400).json({ message: err.message });
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
handler.select = (value) => {
|
|
207
|
-
queryState.queries.push({ type: "select", value: typeof value == 'string' ? strToObj(value, 0) : value });
|
|
208
|
-
return handler;
|
|
209
|
-
};
|
|
210
|
-
handler.skip = (value) => {
|
|
211
|
-
queryState.queries.push({ type: "skip", value });
|
|
212
|
-
return handler;
|
|
213
|
-
};
|
|
214
|
-
handler.limit = (value) => {
|
|
215
|
-
queryState.queries.push({ type: "limit", value });
|
|
216
|
-
return handler;
|
|
217
|
-
};
|
|
218
|
-
handler.sort = (value) => {
|
|
219
|
-
queryState.queries.push({ type: "sort", value: typeof value == 'string' ? strToObj(value) : value });
|
|
220
|
-
return handler;
|
|
221
|
-
};
|
|
222
|
-
handler.populate = (value) => {
|
|
223
|
-
queryState.queries.push({ type: "populate", value });
|
|
224
|
-
return handler;
|
|
225
|
-
};
|
|
226
|
-
return actionHandler;
|
|
227
|
-
};
|
|
228
|
-
module.exports = db;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
type FlagCombination = '' | 'i' | 'g' | 'm' | 's' | 'u' | 'y' | 'ig' | 'im' | 'is' | 'iu' | 'iy' | 'gm' | 'gs' | 'gu' | 'gy' | 'ms' | 'mu' | 'my' | 'su' | 'sy' | 'uy' | 'igm' | 'igs' | 'igu' | 'igy' | 'ims' | 'imu' | 'imy' | 'isu' | 'isy' | 'iuy' | 'gms' | 'gmu' | 'gmy' | 'gsu' | 'gsy' | 'guy' | 'msu' | 'msy' | 'muy' | 'suy' | 'igms' | 'igmu' | 'igmy' | 'igsu' | 'igsy' | 'iguy' | 'imsu' | 'imsy' | 'imuy' | 'isuy' | 'gmsu' | 'gmsy' | 'gmuy' | 'gsuy' | 'msuy' | 'igmsu' | 'igmsy' | 'igmuy' | 'igsuy' | 'imsuy' | 'gmsuy' | 'igmsuy';
|
|
2
|
-
type Types = "double" | "string" | "object" | "array" | "binData" | "undefined" | "objectId" | "bool" | "date" | "null" | "regex" | "dbPointer" | "javascript" | "symbol" | "int" | "timestamp" | "long" | "decimal" | "minKey" | "maxKey";
|
|
3
|
-
interface MatchOperators {
|
|
4
|
-
eq: (value: string | number) => MatchOperators;
|
|
5
|
-
ne: (value: string | number) => MatchOperators;
|
|
6
|
-
gte: (value: number) => MatchOperators;
|
|
7
|
-
gt: (value: number) => MatchOperators;
|
|
8
|
-
lte: (value: number) => MatchOperators;
|
|
9
|
-
lt: (value: number) => MatchOperators;
|
|
10
|
-
nin: (value: (number | string)[]) => MatchOperators;
|
|
11
|
-
in: (value: (number | string)[]) => MatchOperators;
|
|
12
|
-
and: (value: {
|
|
13
|
-
[key: string]: number | string | boolean | MatchOperators;
|
|
14
|
-
}[]) => MatchOperators;
|
|
15
|
-
or: (value: {
|
|
16
|
-
[key: string]: number | string | boolean | MatchOperators;
|
|
17
|
-
}[]) => MatchOperators;
|
|
18
|
-
not: (value: {
|
|
19
|
-
[key: string]: number | string | boolean | MatchOperators;
|
|
20
|
-
}) => MatchOperators;
|
|
21
|
-
nor: (value: {
|
|
22
|
-
[key: string]: number | string | boolean | MatchOperators;
|
|
23
|
-
}[]) => MatchOperators;
|
|
24
|
-
elemMatch: (value: {
|
|
25
|
-
[key: string]: number | string | boolean | MatchOperators;
|
|
26
|
-
}) => MatchOperators;
|
|
27
|
-
all: (value: (number | string | boolean)[]) => MatchOperators;
|
|
28
|
-
size: (value: number) => MatchOperators;
|
|
29
|
-
exist: (value: boolean) => MatchOperators;
|
|
30
|
-
type: (value: Types) => MatchOperators;
|
|
31
|
-
regex: (value: RegExp, option?: FlagCombination) => MatchOperators;
|
|
32
|
-
mod: (number: number, devisor: number) => MatchOperators;
|
|
33
|
-
expr: (value: MatchOperators) => MatchOperators;
|
|
34
|
-
}
|
|
35
|
-
interface ProjectOperators {
|
|
36
|
-
add: (...args: (number | `$${string}`)[]) => ProjectOperators;
|
|
37
|
-
cond: ($if: (operators: MatchOperators) => unknown, $then: (operators: MatchOperators) => unknown, $else: (operators: MatchOperators) => unknown) => ProjectOperators;
|
|
38
|
-
}
|
package/dist/modules/types/db.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/dist/modules/uploader.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const multer = require('multer');
|
|
6
|
-
module.exports = (destination = '/image', config = { prefix: '', limit: 5, format: /png|jpg|webp|jpeg/i }) => {
|
|
7
|
-
const splittedDest = destination.split('/');
|
|
8
|
-
splittedDest.forEach((folder, i) => {
|
|
9
|
-
const folderPath = path.join(__dirname, '../../public', ...splittedDest.slice(0, i + 1));
|
|
10
|
-
if (!fs.existsSync(folderPath)) {
|
|
11
|
-
fs.mkdirSync(folderPath);
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
const storage = multer.diskStorage({
|
|
15
|
-
destination: function (req, file, cb) {
|
|
16
|
-
cb(null, path.join(__dirname, '../../public', destination));
|
|
17
|
-
},
|
|
18
|
-
filename: function (req, file, cb) {
|
|
19
|
-
const ext = path.extname(file.originalname);
|
|
20
|
-
if (!ext.slice(1).match(config.format || /png|jpg|webp|jpeg/ig)) {
|
|
21
|
-
cb(new Error('file format not acceptable'));
|
|
22
|
-
}
|
|
23
|
-
const uniqueSuffix = Date.now() + Math.round(Math.random() * 1E9);
|
|
24
|
-
cb(null, (config.prefix ? config.prefix + '-' : '') + Buffer.from(file.originalname, 'latin1').toString('utf8').replace(/\.\w+/, '').replace(/[\s]+/, '-') + '-' + uniqueSuffix + ext);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
const uploader = multer({ storage: storage, limits: { fileSize: (config.limit || 5) * 1024 * 1024 } });
|
|
28
|
-
return {
|
|
29
|
-
single: (fieldName) => (req, res, next) => {
|
|
30
|
-
const nextFunction = (err) => {
|
|
31
|
-
if (err)
|
|
32
|
-
return next([405, err.message]);
|
|
33
|
-
console.log('uploader', 32, req.body);
|
|
34
|
-
if (req.file) {
|
|
35
|
-
req.body[fieldName] = path.join('/static', path.relative(path.join(__dirname, '../../public'), req.file.path)).replaceAll(/\\/g, '/');
|
|
36
|
-
}
|
|
37
|
-
if (Array.isArray(req.files))
|
|
38
|
-
req.body[fieldName] = req.files.map(file => path.join('/static', path.relative(path.join(__dirname, '../../public'), file.path)).replace(/\\/g, '/'));
|
|
39
|
-
next();
|
|
40
|
-
};
|
|
41
|
-
uploader.single(fieldName)(req, res, nextFunction);
|
|
42
|
-
},
|
|
43
|
-
array: (fieldName, maxCount = Infinity) => (req, res, next) => {
|
|
44
|
-
const nextFunction = (err) => {
|
|
45
|
-
if (err)
|
|
46
|
-
return next([405, err.message]);
|
|
47
|
-
if (req.file) {
|
|
48
|
-
req.body[fieldName] = path.join('/static', path.relative(path.join(__dirname, '../../public'), req.file.path)).replaceAll(/\\/g, '/');
|
|
49
|
-
}
|
|
50
|
-
if (Array.isArray(req.files))
|
|
51
|
-
req.body[fieldName] = req.files.map(file => path.join('/static', path.relative(path.join(__dirname, '../../public'), file.path)).replaceAll(/\\/g, '/'));
|
|
52
|
-
next();
|
|
53
|
-
};
|
|
54
|
-
uploader.array(fieldName, maxCount)(req, res, nextFunction);
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
};
|
package/dist/modules/utils.d.ts
DELETED
|
File without changes
|
package/dist/modules/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const { isValidObjectId } = require('mongoose');
|
|
16
|
-
const yup_1 = __importDefault(require("yup"));
|
|
17
|
-
exports.validate = (validation = {}, config = {}) => (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
try {
|
|
19
|
-
const body = req.body;
|
|
20
|
-
if (validation.body)
|
|
21
|
-
yield validation.body.validate(body);
|
|
22
|
-
if (validation.params)
|
|
23
|
-
yield validation.params.validate(req.params);
|
|
24
|
-
if (validation.query)
|
|
25
|
-
yield validation.query.validate(req.query);
|
|
26
|
-
next();
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
console.log('VALIDATOR_ERROR : ', err);
|
|
30
|
-
return next([405, err.message]);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
yup_1.default.addMethod(yup_1.default.string, 'oid', function (errorMessage = 'id not validate') {
|
|
34
|
-
return this.test({
|
|
35
|
-
name: 'oid',
|
|
36
|
-
message: errorMessage,
|
|
37
|
-
test(value) {
|
|
38
|
-
if (!value)
|
|
39
|
-
return true;
|
|
40
|
-
if (!value || !isValidObjectId(value)) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
return true;
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
exports.types = yup_1.default;
|
package/dist/utils/strToObj.d.ts
DELETED
|
File without changes
|
package/dist/utils/strToObj.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = (value, falseValue = -1, splitValue = ' ') => {
|
|
3
|
-
return value.split(splitValue).reduce((prev, curr) => {
|
|
4
|
-
if (curr[0] == '-')
|
|
5
|
-
return Object.assign(Object.assign({}, prev), { [curr.slice(1)]: falseValue });
|
|
6
|
-
return Object.assign(Object.assign({}, prev), { [curr]: 1 });
|
|
7
|
-
}, {});
|
|
8
|
-
};
|
|
File without changes
|
|
File without changes
|