speedly 1.0.0 → 1.1.0
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 +70 -0
- package/dist/cjs/validator/validator.d.ts +9 -0
- package/dist/cjs/validator/validator.js +32 -0
- package/dist/esm/auth/auth.js +81 -0
- package/dist/esm/db/db.d.ts +181 -0
- package/dist/esm/db/db.js +480 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/model/translation.d.ts +2 -0
- package/dist/esm/model/translation.js +8 -0
- package/dist/{modules/db.d.ts → esm/uploader/uploader.d.ts} +1 -1
- package/dist/esm/uploader/uploader.js +145 -0
- package/dist/esm/util/getConfig.d.ts +4 -0
- package/dist/esm/util/getConfig.js +16 -0
- package/dist/esm/util/strToObj.d.ts +2 -0
- package/dist/esm/util/strToObj.js +7 -0
- package/dist/esm/util/translator.d.ts +2 -0
- package/dist/esm/util/translator.js +65 -0
- package/dist/esm/validator/validator.d.ts +9 -0
- package/dist/esm/validator/validator.js +28 -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/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
|