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.
Files changed (58) hide show
  1. package/README.md +280 -0
  2. package/dist/cjs/auth/auth.js +86 -0
  3. package/dist/cjs/db/db.d.ts +181 -0
  4. package/dist/cjs/db/db.js +485 -0
  5. package/dist/cjs/index.d.ts +5 -0
  6. package/dist/cjs/index.js +44 -0
  7. package/dist/cjs/model/translation.d.ts +59 -0
  8. package/dist/cjs/model/translation.js +13 -0
  9. package/dist/{modules/auth.d.ts → cjs/uploader/uploader.d.ts} +1 -1
  10. package/dist/cjs/uploader/uploader.js +150 -0
  11. package/dist/cjs/util/getConfig.d.ts +4 -0
  12. package/dist/cjs/util/getConfig.js +21 -0
  13. package/dist/cjs/util/strToObj.d.ts +2 -0
  14. package/dist/cjs/util/strToObj.js +9 -0
  15. package/dist/cjs/util/translator.d.ts +2 -0
  16. package/dist/cjs/util/translator.js +67 -0
  17. package/dist/cjs/validator/validator.d.ts +9 -0
  18. package/dist/cjs/validator/validator.js +32 -0
  19. package/dist/esm/auth/auth.js +86 -0
  20. package/dist/esm/db/db.d.ts +181 -0
  21. package/dist/esm/db/db.js +485 -0
  22. package/dist/esm/index.d.ts +5 -0
  23. package/dist/esm/index.js +44 -0
  24. package/dist/esm/model/translation.d.ts +59 -0
  25. package/dist/esm/model/translation.js +13 -0
  26. package/dist/{modules/db.d.ts → esm/uploader/uploader.d.ts} +1 -1
  27. package/dist/esm/uploader/uploader.js +150 -0
  28. package/dist/esm/util/getConfig.d.ts +4 -0
  29. package/dist/esm/util/getConfig.js +21 -0
  30. package/dist/esm/util/strToObj.d.ts +2 -0
  31. package/dist/esm/util/strToObj.js +9 -0
  32. package/dist/esm/util/translator.d.ts +2 -0
  33. package/dist/esm/util/translator.js +67 -0
  34. package/dist/esm/validator/validator.d.ts +9 -0
  35. package/dist/esm/validator/validator.js +32 -0
  36. package/package.json +28 -15
  37. package/dist/index.d.ts +0 -0
  38. package/dist/index.js +0 -1
  39. package/dist/modules/auth.js +0 -68
  40. package/dist/modules/db/aggregation.d.ts +0 -0
  41. package/dist/modules/db/aggregation.js +0 -1
  42. package/dist/modules/db/aggregation.types.d.ts +0 -56
  43. package/dist/modules/db/aggregation.types.js +0 -2
  44. package/dist/modules/db/db.d.ts +0 -0
  45. package/dist/modules/db/db.js +0 -1
  46. package/dist/modules/db/db.type.js +0 -2
  47. package/dist/modules/db.js +0 -228
  48. package/dist/modules/types/db.d.ts +0 -38
  49. package/dist/modules/types/db.js +0 -1
  50. package/dist/modules/uploader.js +0 -57
  51. package/dist/modules/utils.d.ts +0 -0
  52. package/dist/modules/utils.js +0 -1
  53. package/dist/modules/validator.d.ts +0 -1
  54. package/dist/modules/validator.js +0 -47
  55. package/dist/utils/strToObj.d.ts +0 -0
  56. package/dist/utils/strToObj.js +0 -8
  57. /package/dist/{modules/db/db.type.d.ts → cjs/auth/auth.d.ts} +0 -0
  58. /package/dist/{modules/uploader.d.ts → esm/auth/auth.d.ts} +0 -0
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const multer_1 = __importDefault(require("multer"));
9
+ const mongoose_1 = __importDefault(require("mongoose"));
10
+ const getConfig = require("../util/getConfig");
11
+ const relativePath = '../../../public';
12
+ let configs = {
13
+ saveInDb: false,
14
+ prefix: "",
15
+ limit: 5,
16
+ format: /png|jpg|webp|jpeg/i,
17
+ ...getConfig("uploader")
18
+ };
19
+ console.log('uploader', 15, configs);
20
+ module.exports = (destination = "/image", config = configs) => {
21
+ let dest;
22
+ try {
23
+ Object.entries(config).forEach(([key, val]) => {
24
+ configs[key] = val;
25
+ });
26
+ const storage = multer_1.default.diskStorage({
27
+ destination: function (req, file, cb) {
28
+ try {
29
+ dest = typeof destination === "function"
30
+ ? destination(req, file)
31
+ : destination;
32
+ const splitPath = dest.split("/");
33
+ let currentPath = path_1.default.join(__dirname, relativePath);
34
+ splitPath.forEach(folder => {
35
+ currentPath = path_1.default.join(currentPath, folder);
36
+ console.log('uploader', 39, currentPath, !fs_1.default.existsSync(currentPath));
37
+ if (!fs_1.default.existsSync(currentPath)) {
38
+ fs_1.default.mkdirSync(currentPath);
39
+ }
40
+ });
41
+ cb(null, path_1.default.join(__dirname, relativePath, dest));
42
+ }
43
+ catch (err) {
44
+ cb(err, "");
45
+ }
46
+ },
47
+ filename: function (req, file, cb) {
48
+ try {
49
+ const ext = path_1.default.extname(file.originalname);
50
+ if (!ext.slice(1).match(configs.format)) {
51
+ return cb(new Error("File format not acceptable"), '');
52
+ }
53
+ const originalName = Buffer.from(file.originalname, "latin1").toString("utf8");
54
+ const fileName = (configs.prefix ? configs.prefix + "-" : "") +
55
+ originalName.replace(/\.\w+$/, "") + ext;
56
+ const filePath = path_1.default.join(__dirname, relativePath, dest, fileName);
57
+ console.log('uploader', 65, filePath);
58
+ try {
59
+ fs_1.default.existsSync(filePath);
60
+ }
61
+ catch (error) {
62
+ console.log('uploader', 70, error);
63
+ }
64
+ if (fs_1.default.existsSync(filePath)) {
65
+ return cb(new Error("File already exists in the destination folder"), '');
66
+ }
67
+ cb(null, fileName);
68
+ }
69
+ catch (err) {
70
+ cb(err, '');
71
+ }
72
+ },
73
+ });
74
+ const uploader = (0, multer_1.default)({
75
+ storage,
76
+ limits: { fileSize: (configs.limit || 5) * 1024 * 1024 }, // MB
77
+ });
78
+ return {
79
+ single: (fieldName) => (req, res, next) => {
80
+ uploader.single(fieldName)(req, res, async (err) => {
81
+ if (err) {
82
+ console.log('uploader', 85, err);
83
+ return next({ status: 405, json: { message: err.message } });
84
+ }
85
+ if (req.file) {
86
+ if (configs.saveInDb) {
87
+ const db = mongoose_1.default.connection;
88
+ const collection = db.collection("media");
89
+ const duplicate = await collection.findOne({ alt: req.body.alt });
90
+ if (duplicate) {
91
+ fs_1.default.rmSync(req.file.path);
92
+ return res.status(405).json({ message: "alt is repetitive" });
93
+ }
94
+ const mediaDoc = await collection.insertOne({
95
+ type: req.file.mimetype.split("/")[0],
96
+ name: req.file.filename,
97
+ dirPath: dest + "/",
98
+ alt: req.body.alt,
99
+ desc: req.body.desc,
100
+ url: "/static/" + dest + "/" + req.file.filename,
101
+ });
102
+ console.log('uploader', 101, mediaDoc);
103
+ req.mediaId = mediaDoc.insertedId;
104
+ }
105
+ req.body[fieldName] = path_1.default
106
+ .join("/static", path_1.default.relative(path_1.default.join(__dirname, relativePath), req.file.path))
107
+ .replaceAll(/\\/g, "/");
108
+ }
109
+ next();
110
+ });
111
+ },
112
+ array: (fieldName, maxCount = Infinity) => (req, res, next) => {
113
+ uploader.array(fieldName, maxCount)(req, res, (err) => {
114
+ if (err)
115
+ return res.status(405).json({ message: err.message });
116
+ if (req.files && Array.isArray(req.files) && req.files.length) {
117
+ req.body[fieldName] = req.files.map(file => path_1.default
118
+ .join("/static", path_1.default.relative(path_1.default.join(__dirname, relativePath), file.path))
119
+ .replaceAll(/\\/g, "/"));
120
+ }
121
+ next();
122
+ });
123
+ },
124
+ fields: (fields) => (req, res, next) => {
125
+ uploader.fields(fields)(req, res, (err) => {
126
+ if (err)
127
+ return res.status(405).json({ message: err.message });
128
+ next();
129
+ });
130
+ },
131
+ any: () => (req, res, next) => {
132
+ uploader.any()(req, res, (err) => {
133
+ if (err)
134
+ return res.status(405).json({ message: err.message });
135
+ next();
136
+ });
137
+ },
138
+ none: () => (req, res, next) => {
139
+ uploader.none()(req, res, (err) => {
140
+ if (err)
141
+ return res.status(405).json({ message: err.message });
142
+ next();
143
+ });
144
+ },
145
+ };
146
+ }
147
+ catch (error) {
148
+ console.log("uploader init error", error);
149
+ }
150
+ };
@@ -0,0 +1,4 @@
1
+ declare const _default: (configField: string) => {
2
+ [key: string]: unknown;
3
+ };
4
+ export default _default;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ // const { path } = require('../../app');
8
+ exports.default = (configField) => {
9
+ const stackPath = new Error().stack?.split('\n')[2].trim().match(/\(.+\)/)?.[0].replace(/([\(\)]|\:\d+\:\d+)/g, '');
10
+ for (let i = 1; i < 4; i++) {
11
+ const filePath = stackPath?.replace(/\\/g, '/').split('/').slice(0, -i).join('/') + '/speedly.config.js';
12
+ if (fs_1.default.existsSync(filePath)) {
13
+ const config = require(filePath);
14
+ if (config && config[configField]) {
15
+ return config[configField];
16
+ }
17
+ return {};
18
+ }
19
+ }
20
+ return {};
21
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: (value: string, falseValue?: number, splitValue?: string) => {};
2
+ export default _default;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = (value, falseValue = -1, splitValue = ' ') => {
4
+ return value.split(splitValue).reduce((prev, curr) => {
5
+ if (curr[0] == '-')
6
+ return { ...prev, [curr.slice(1)]: falseValue };
7
+ return { ...prev, [curr]: 1 };
8
+ }, {});
9
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: (text?: string, lang?: string) => Promise<unknown>;
2
+ export default _default;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const axios_1 = __importDefault(require("axios"));
7
+ const translation_1 = __importDefault(require("./../model/translation"));
8
+ const getConfig_1 = __importDefault(require("./getConfig"));
9
+ const configs = { ...(0, getConfig_1.default)('translate') };
10
+ async function firstSuccessful(promises) {
11
+ return new Promise((resolve, reject) => {
12
+ let rejections = 0;
13
+ const total = promises.length;
14
+ promises.forEach((p) => {
15
+ Promise.resolve(p)
16
+ .then(resolve)
17
+ .catch(() => {
18
+ rejections++;
19
+ if (rejections === total) {
20
+ reject(new Error("همه ترجمه‌ها شکست خوردند"));
21
+ }
22
+ });
23
+ });
24
+ });
25
+ }
26
+ exports.default = async (text = "unspecified text", lang = "fa") => {
27
+ const formattedText = text
28
+ .replaceAll(/[\-\_]/g, " ")
29
+ .replaceAll(/[A-Z]/g, " $&");
30
+ const translationDoc = await translation_1.default.findOne({ text: formattedText, lang });
31
+ if (translationDoc)
32
+ return translationDoc.translatedText;
33
+ const translationPromises = [];
34
+ translationPromises.push((async () => {
35
+ const res = await axios_1.default.get(`https://655.mtis.workers.dev/translate?text=${encodeURIComponent(formattedText)}&source_lang=en&target_lang=${lang}`, { timeout: 2000 });
36
+ if (!res.data?.response?.translated_text)
37
+ throw new Error("Translation failed");
38
+ return res.data.response.translated_text;
39
+ })());
40
+ if (configs.one_api_token)
41
+ translationPromises.push((async () => {
42
+ const res = await axios_1.default.post("https://api.one-api.ir/translate/v1/microsoft", {
43
+ text: formattedText,
44
+ target: lang,
45
+ }, {
46
+ timeout: 2000,
47
+ headers: {
48
+ "one-api-token": configs.one_api_token
49
+ },
50
+ });
51
+ if (res.data.status === 200) {
52
+ return res.data.result;
53
+ }
54
+ else {
55
+ throw new Error(res.data.message);
56
+ }
57
+ })());
58
+ try {
59
+ const result = await firstSuccessful(translationPromises);
60
+ await translation_1.default.create({ text: formattedText, lang, translatedText: result });
61
+ return result;
62
+ }
63
+ catch (err) {
64
+ console.error("translator error:", err);
65
+ return formattedText;
66
+ }
67
+ };
@@ -0,0 +1,9 @@
1
+ import { RequestHandler } from "express";
2
+ import * as yup from "yup";
3
+ type ValidationSchema = {
4
+ body?: yup.AnyObjectSchema;
5
+ params?: yup.AnyObjectSchema;
6
+ query?: yup.AnyObjectSchema;
7
+ };
8
+ export declare const validator: <T extends ValidationSchema>(schemas: T) => RequestHandler;
9
+ export {};
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validator = void 0;
4
+ // این تابع validator generic هست
5
+ const validator = (schemas) => async (req, res, next) => {
6
+ try {
7
+ if (schemas.body) {
8
+ req.body = (await schemas.body.validate(req.body, {
9
+ stripUnknown: true,
10
+ }));
11
+ }
12
+ if (schemas.params) {
13
+ req.params = (await schemas.params.validate(req.params, {
14
+ stripUnknown: true,
15
+ }));
16
+ }
17
+ if (schemas.query) {
18
+ req.query = (await schemas.query.validate(req.query, {
19
+ stripUnknown: true,
20
+ }));
21
+ }
22
+ next();
23
+ }
24
+ catch (err) {
25
+ return next({
26
+ status: 405,
27
+ json: { message: err.message },
28
+ section: "validation",
29
+ });
30
+ }
31
+ };
32
+ exports.validator = validator;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const getConfig_1 = __importDefault(require("../util/getConfig"));
7
+ const gConfig = { admin: { role: 'ADMIN', model: '../models/admin' }, jwtSecretEnv: 'JWT_KEY', customValidator: (req, key) => { return true; }, ...(0, getConfig_1.default)('auth') };
8
+ const auth = (config = gConfig) => {
9
+ // const adminModel = require('../models/admin')
10
+ let handlerState = {};
11
+ const useAuth = async (req, res, next) => {
12
+ try {
13
+ const nextFunc = (handlers, index = 0) => (errorMessage = '') => {
14
+ if (errorMessage)
15
+ return next(errorMessage);
16
+ if (!handlers.length || !handlers[index + 1])
17
+ return next();
18
+ handlers[index + 1](req, res, nextFunc(handlers, index + 1));
19
+ };
20
+ const keys = Object.keys(handlerState);
21
+ for (let i = 0; i < keys.length; i++) {
22
+ const key = keys[i];
23
+ if (!handlerState[key]?.handlers?.length)
24
+ continue;
25
+ if (await gConfig?.customValidator?.(req, key)) {
26
+ return await handlerState[key].handlers[0](req, res, nextFunc(handlerState[key].handlers));
27
+ }
28
+ else if (await gConfig?.customValidator?.(req, key) == null) {
29
+ return next({ status: 401, json: { message: 'unauthorized' } });
30
+ }
31
+ else if (i === keys.length - 1) {
32
+ next({ status: 405, json: { message: 'you don\'t have access to this section' } });
33
+ }
34
+ else
35
+ continue;
36
+ }
37
+ // اینجا اگر i === keys.length - 1 باشد یعنی آخرین آیتم هستی
38
+ // }else if (!req.cookies.AT_SECRET) {
39
+ // if (!handlerState.user || !handlerState.user?.handlers?.length) return res.status(403).json({ message: 'you dont have access for this section' })
40
+ // handlerState.user.handlers[0](req ,res , nextFunc(handlerState.user.handlers))
41
+ // }else {
42
+ // if(!handlerState.admin || !handlerState.admin?.handlers?.length) {
43
+ // if (!handlerState.user || !handlerState.user?.handlers?.length) return res.status(404).json({ message: 'route not found :(' })
44
+ // handlerState.user.handlers[0](req ,res , nextFunc(handlerState.user.handlers))
45
+ // } else {
46
+ // const tokenPayload = jwt.verify(req.cookies.AT_SECRET , process.env[gConfig.jwtSecretEnv])
47
+ // const adminDoc = await adminModel.findById(tokenPayload.id)
48
+ // if(!adminDoc)return res.status(403).json({ message: 'you don\'t have access for this section' })
49
+ // if(adminDoc.role !='OWNER' && adminDoc.role != config?.admin?.role ) return res.status(403).json({ message: 'you dont have access for this section' })
50
+ // req.admin = adminDoc
51
+ // handlerState.admin.handlers[0](req , res , nextFunc(handlerState.admin.handlers))
52
+ // }
53
+ // }
54
+ }
55
+ catch (error) {
56
+ console.log('auth', 42, error);
57
+ next({ status: 403, json: { message: (error instanceof Error ? error.message : 'error on authentication please login again') } });
58
+ }
59
+ };
60
+ useAuth.admin = (...handlers) => {
61
+ if (!Array.isArray(handlers))
62
+ throw new Error('handlers must be an array');
63
+ const hasConfig = typeof handlers[0] === 'object' && 'permission' in handlers[0];
64
+ const configObj = hasConfig ? handlers[0] : undefined;
65
+ const handlerFns = hasConfig ? handlers.slice(1) : handlers;
66
+ handlerState[`admin${configObj?.permission ? `:${configObj.permission}` : ''}`] = {
67
+ ...(configObj ? { config: configObj } : {}),
68
+ handlers: handlerFns
69
+ };
70
+ return useAuth;
71
+ };
72
+ useAuth.user = (...handlers) => {
73
+ if (!Array.isArray(handlers))
74
+ throw new Error('handlers must be an array');
75
+ handlerState.user = { handlers };
76
+ return useAuth;
77
+ };
78
+ useAuth.any = (...handlers) => {
79
+ if (!Array.isArray(handlers))
80
+ throw new Error('handlers must be an array');
81
+ handlerState.any = { handlers };
82
+ return useAuth;
83
+ };
84
+ return useAuth;
85
+ };
86
+ module.exports = auth;
@@ -0,0 +1,181 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ declare module 'express-serve-static-core' {
3
+ interface Request {
4
+ document?: any;
5
+ user?: any;
6
+ }
7
+ interface Response {
8
+ logger?: (message: string, details?: any) => void;
9
+ success?: (statusCode: number, body: any) => void;
10
+ }
11
+ }
12
+ type ConfigsType = {
13
+ dbType?: string;
14
+ path?: string;
15
+ dbEnv?: string;
16
+ pagination?: {
17
+ quantity?: number;
18
+ detailed?: boolean;
19
+ [key: string]: unknown;
20
+ };
21
+ [key: string]: unknown;
22
+ };
23
+ declare const db: (collectionName: string, config?: ConfigsType) => {
24
+ find: (match?: {}) => {
25
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
26
+ select(value: string | {
27
+ [key: string]: -1 | 1;
28
+ }): /*elided*/ any;
29
+ sort(value: string | {
30
+ [key: string]: -1 | 1;
31
+ }): /*elided*/ any;
32
+ skip(value: number): /*elided*/ any;
33
+ limit(value: number): /*elided*/ any;
34
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
35
+ };
36
+ create: (body?: {}) => {
37
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
38
+ select(value: string | {
39
+ [key: string]: -1 | 1;
40
+ }): /*elided*/ any;
41
+ sort(value: string | {
42
+ [key: string]: -1 | 1;
43
+ }): /*elided*/ any;
44
+ skip(value: number): /*elided*/ any;
45
+ limit(value: number): /*elided*/ any;
46
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
47
+ };
48
+ updateOne: (match?: {}, body?: {}) => {
49
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
50
+ select(value: string | {
51
+ [key: string]: -1 | 1;
52
+ }): /*elided*/ any;
53
+ sort(value: string | {
54
+ [key: string]: -1 | 1;
55
+ }): /*elided*/ any;
56
+ skip(value: number): /*elided*/ any;
57
+ limit(value: number): /*elided*/ any;
58
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
59
+ };
60
+ updateMany: (match?: {}, body?: {}) => {
61
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
62
+ select(value: string | {
63
+ [key: string]: -1 | 1;
64
+ }): /*elided*/ any;
65
+ sort(value: string | {
66
+ [key: string]: -1 | 1;
67
+ }): /*elided*/ any;
68
+ skip(value: number): /*elided*/ any;
69
+ limit(value: number): /*elided*/ any;
70
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
71
+ };
72
+ deleteOne: (match?: {}) => {
73
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
74
+ select(value: string | {
75
+ [key: string]: -1 | 1;
76
+ }): /*elided*/ any;
77
+ sort(value: string | {
78
+ [key: string]: -1 | 1;
79
+ }): /*elided*/ any;
80
+ skip(value: number): /*elided*/ any;
81
+ limit(value: number): /*elided*/ any;
82
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
83
+ };
84
+ deleteMany: (match?: {}) => {
85
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
86
+ select(value: string | {
87
+ [key: string]: -1 | 1;
88
+ }): /*elided*/ any;
89
+ sort(value: string | {
90
+ [key: string]: -1 | 1;
91
+ }): /*elided*/ any;
92
+ skip(value: number): /*elided*/ any;
93
+ limit(value: number): /*elided*/ any;
94
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
95
+ };
96
+ findOne: (match?: {}) => {
97
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
98
+ select(value: string | {
99
+ [key: string]: -1 | 1;
100
+ }): /*elided*/ any;
101
+ sort(value: string | {
102
+ [key: string]: -1 | 1;
103
+ }): /*elided*/ any;
104
+ skip(value: number): /*elided*/ any;
105
+ limit(value: number): /*elided*/ any;
106
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
107
+ };
108
+ findOneAndUpdate: (match?: {}, body?: {}) => {
109
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
110
+ select(value: string | {
111
+ [key: string]: -1 | 1;
112
+ }): /*elided*/ any;
113
+ sort(value: string | {
114
+ [key: string]: -1 | 1;
115
+ }): /*elided*/ any;
116
+ skip(value: number): /*elided*/ any;
117
+ limit(value: number): /*elided*/ any;
118
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
119
+ };
120
+ aggregate: (pipeline?: never[]) => {
121
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
122
+ select(value: string | {
123
+ [key: string]: -1 | 1;
124
+ }): /*elided*/ any;
125
+ sort(value: string | {
126
+ [key: string]: -1 | 1;
127
+ }): /*elided*/ any;
128
+ skip(value: number): /*elided*/ any;
129
+ limit(value: number): /*elided*/ any;
130
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
131
+ };
132
+ findOneAndDelete: (match?: {}) => {
133
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
134
+ select(value: string | {
135
+ [key: string]: -1 | 1;
136
+ }): /*elided*/ any;
137
+ sort(value: string | {
138
+ [key: string]: -1 | 1;
139
+ }): /*elided*/ any;
140
+ skip(value: number): /*elided*/ any;
141
+ limit(value: number): /*elided*/ any;
142
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
143
+ };
144
+ findById: (id?: string) => {
145
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
146
+ select(value: string | {
147
+ [key: string]: -1 | 1;
148
+ }): /*elided*/ any;
149
+ sort(value: string | {
150
+ [key: string]: -1 | 1;
151
+ }): /*elided*/ any;
152
+ skip(value: number): /*elided*/ any;
153
+ limit(value: number): /*elided*/ any;
154
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
155
+ };
156
+ findByIdAndUpdate: (id?: string, body?: {}) => {
157
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
158
+ select(value: string | {
159
+ [key: string]: -1 | 1;
160
+ }): /*elided*/ any;
161
+ sort(value: string | {
162
+ [key: string]: -1 | 1;
163
+ }): /*elided*/ any;
164
+ skip(value: number): /*elided*/ any;
165
+ limit(value: number): /*elided*/ any;
166
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
167
+ };
168
+ findByIdAndDelete: (id?: string) => {
169
+ (req: Request, res: Response, next: NextFunction): Promise<void>;
170
+ select(value: string | {
171
+ [key: string]: -1 | 1;
172
+ }): /*elided*/ any;
173
+ sort(value: string | {
174
+ [key: string]: -1 | 1;
175
+ }): /*elided*/ any;
176
+ skip(value: number): /*elided*/ any;
177
+ limit(value: number): /*elided*/ any;
178
+ populate(value: string | object | (string | object)[]): /*elided*/ any;
179
+ };
180
+ } | undefined;
181
+ export default db;