speedly 1.0.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.
File without changes
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ namespace Express {
3
+ interface Request {
4
+ admin?: any;
5
+ }
6
+ }
7
+ }
8
+ export {};
@@ -0,0 +1,68 @@
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
+ const jwt = require('jsonwebtoken');
13
+ const adminModel = require('./../models/admin');
14
+ const auth = (config = { admin: { role: 'ADMIN' } }) => {
15
+ let handlerState = {};
16
+ const useAuth = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
17
+ var _a, _b, _c, _d, _e, _f, _g;
18
+ console.log('auth 6 ', req.cookies);
19
+ try {
20
+ const nextFunc = (handlers, index = 0) => (errorMessage = '') => {
21
+ if (!handlers.length || !handlers[index + 1])
22
+ return next();
23
+ if (errorMessage)
24
+ return next(errorMessage);
25
+ handlers[index + 1](req, res, nextFunc(handlers, index + 1));
26
+ };
27
+ if (!req.cookies.AT_SECRET) {
28
+ if (!handlerState.user || !((_b = (_a = handlerState.user) === null || _a === void 0 ? void 0 : _a.handlers) === null || _b === void 0 ? void 0 : _b.length))
29
+ return res.status(403).json({ message: 'you dont have access for this section' });
30
+ handlerState.user.handlers[0](req, res, nextFunc(handlerState.user.handlers));
31
+ }
32
+ else {
33
+ if (!handlerState.admin || !((_d = (_c = handlerState.admin) === null || _c === void 0 ? void 0 : _c.handlers) === null || _d === void 0 ? void 0 : _d.length)) {
34
+ if (!handlerState.user || !((_f = (_e = handlerState.user) === null || _e === void 0 ? void 0 : _e.handlers) === null || _f === void 0 ? void 0 : _f.length))
35
+ return res.status(404).json({ message: 'route not found :(' });
36
+ handlerState.user.handlers[0](req, res, nextFunc(handlerState.user.handlers));
37
+ }
38
+ else {
39
+ const tokenPayload = jwt.verify(req.cookies.AT_SECRET, process.env.ACCESS_TOKEN_SECRET);
40
+ const adminDoc = yield adminModel.findById(tokenPayload.id);
41
+ if (!adminDoc)
42
+ return res.status(403).json({ message: 'you dont have access for this section' });
43
+ if (adminDoc.role != 'OWNER' && adminDoc.role != ((_g = config === null || config === void 0 ? void 0 : config.admin) === null || _g === void 0 ? void 0 : _g.role))
44
+ return res.status(403).json({ message: 'you dont have access for this section' });
45
+ req.admin = adminDoc;
46
+ handlerState.admin.handlers[0](req, res, nextFunc(handlerState.admin.handlers));
47
+ }
48
+ }
49
+ }
50
+ catch (error) {
51
+ }
52
+ });
53
+ useAuth.admin = (...handlers) => {
54
+ var _a;
55
+ if (!Array.isArray(handlers))
56
+ throw new Error('handlers must be an array');
57
+ handlerState.admin = { role: ((_a = config === null || config === void 0 ? void 0 : config.admin) === null || _a === void 0 ? void 0 : _a.role) || 'admin', handlers };
58
+ return useAuth;
59
+ };
60
+ useAuth.user = (...handlers) => {
61
+ if (!Array.isArray(handlers))
62
+ throw new Error('handlers must be an array');
63
+ handlerState.user = { handlers };
64
+ return useAuth;
65
+ };
66
+ return useAuth;
67
+ };
68
+ module.exports = auth;
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,56 @@
1
+ export interface IAggregationBuilder {
2
+ match(filter: object): this;
3
+ group(id: any, fn: (op: IAggregationOperators) => object): this;
4
+ project(fields: object): this;
5
+ addFields(fields: object): this;
6
+ sort(sort: object): this;
7
+ limit(n: number): this;
8
+ skip(n: number): this;
9
+ unwind(field: string | object): this;
10
+ lookup(config: ILookupConfig): this;
11
+ count(field: string): this;
12
+ sortByCount(field: string): this;
13
+ facet(facets: {
14
+ [key: string]: any[];
15
+ }): this;
16
+ bucket(params: IBucketConfig): this;
17
+ bucketAuto(params: IBucketAutoConfig): this;
18
+ replaceRoot(newRoot: object): this;
19
+ redact(expression: any): this;
20
+ sample(size: number): this;
21
+ merge(output: string | object): this;
22
+ out(collection: string): this;
23
+ raw(stage: object): this;
24
+ toArray(): Promise<any[]>;
25
+ first(): Promise<any | null>;
26
+ }
27
+ export interface IAggregationOperators {
28
+ sum(field: string | number): object;
29
+ avg(field: string | number): object;
30
+ min(field: string | number): object;
31
+ max(field: string | number): object;
32
+ first(field: string): object;
33
+ last(field: string): object;
34
+ push(field: string): object;
35
+ addToSet(field: string): object;
36
+ count(): object;
37
+ }
38
+ export interface ILookupConfig {
39
+ from: string;
40
+ localField?: string;
41
+ foreignField?: string;
42
+ as: string;
43
+ let?: object;
44
+ pipeline?: any[];
45
+ }
46
+ export interface IBucketConfig {
47
+ groupBy: any;
48
+ boundaries: any[];
49
+ default?: any;
50
+ output?: object;
51
+ }
52
+ export interface IBucketAutoConfig {
53
+ groupBy: any;
54
+ buckets: number;
55
+ output?: object;
56
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ namespace Express {
3
+ interface Request {
4
+ document?: any;
5
+ }
6
+ }
7
+ }
8
+ export {};
@@ -0,0 +1,228 @@
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;
@@ -0,0 +1,38 @@
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
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
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
+ };
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
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;
File without changes
@@ -0,0 +1,8 @@
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
+ };
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "speedly",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "tsc"
9
+ },
10
+ "keywords": ["mongodb", "aggregation", "builder", "fluent", "typescript"],
11
+ "author": "Mahserin",
12
+ "license": "MIT",
13
+ "description": "A powerful backend module that lets you build and run advanced MongoDB aggregation queries with blazing speed and ultimate simplicity.",
14
+ "dependencies": {
15
+ "@types/express": "^5.0.1",
16
+ "@types/node": "^22.15.17",
17
+ "express": "^5.1.0",
18
+ "jsonwebtoken": "^9.0.2",
19
+ "typescript": "^5.8.3",
20
+ "yup": "^1.6.1"
21
+ },
22
+ "devDependencies": {
23
+ "@types/multer": "^1.4.12"
24
+ }
25
+ }