speedly 1.2.47 → 1.3.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.
@@ -13,6 +13,8 @@ type ConfigsType = {
13
13
  dbType?: string;
14
14
  path?: string;
15
15
  dbEnv?: string;
16
+ response?: boolean;
17
+ first?: boolean;
16
18
  type: "internal" | "external";
17
19
  pagination?: {
18
20
  quantity?: number;
@@ -26,157 +28,157 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
26
28
  (req: Request, res: Response, next: NextFunction): Promise<void>;
27
29
  select(value: string | {
28
30
  [key: string]: -1 | 1;
29
- }): /*elided*/ any;
31
+ }): any;
30
32
  sort(value: string | {
31
33
  [key: string]: -1 | 1;
32
- }): /*elided*/ any;
33
- skip(value: number): /*elided*/ any;
34
- limit(value: number): /*elided*/ any;
35
- populate(value: string | object | (string | object)[]): /*elided*/ any;
34
+ }): any;
35
+ skip(value: number): any;
36
+ limit(value: number): any;
37
+ populate(value: string | object | (string | object)[]): any;
36
38
  };
37
39
  create: (body?: {}) => {
38
40
  (req: Request, res: Response, next: NextFunction): Promise<void>;
39
41
  select(value: string | {
40
42
  [key: string]: -1 | 1;
41
- }): /*elided*/ any;
43
+ }): any;
42
44
  sort(value: string | {
43
45
  [key: string]: -1 | 1;
44
- }): /*elided*/ any;
45
- skip(value: number): /*elided*/ any;
46
- limit(value: number): /*elided*/ any;
47
- populate(value: string | object | (string | object)[]): /*elided*/ any;
46
+ }): any;
47
+ skip(value: number): any;
48
+ limit(value: number): any;
49
+ populate(value: string | object | (string | object)[]): any;
48
50
  };
49
51
  updateOne: (match?: {}, body?: {}) => {
50
52
  (req: Request, res: Response, next: NextFunction): Promise<void>;
51
53
  select(value: string | {
52
54
  [key: string]: -1 | 1;
53
- }): /*elided*/ any;
55
+ }): any;
54
56
  sort(value: string | {
55
57
  [key: string]: -1 | 1;
56
- }): /*elided*/ any;
57
- skip(value: number): /*elided*/ any;
58
- limit(value: number): /*elided*/ any;
59
- populate(value: string | object | (string | object)[]): /*elided*/ any;
58
+ }): any;
59
+ skip(value: number): any;
60
+ limit(value: number): any;
61
+ populate(value: string | object | (string | object)[]): any;
60
62
  };
61
63
  updateMany: (match?: {}, body?: {}) => {
62
64
  (req: Request, res: Response, next: NextFunction): Promise<void>;
63
65
  select(value: string | {
64
66
  [key: string]: -1 | 1;
65
- }): /*elided*/ any;
67
+ }): any;
66
68
  sort(value: string | {
67
69
  [key: string]: -1 | 1;
68
- }): /*elided*/ any;
69
- skip(value: number): /*elided*/ any;
70
- limit(value: number): /*elided*/ any;
71
- populate(value: string | object | (string | object)[]): /*elided*/ any;
70
+ }): any;
71
+ skip(value: number): any;
72
+ limit(value: number): any;
73
+ populate(value: string | object | (string | object)[]): any;
72
74
  };
73
75
  deleteOne: (match?: {}) => {
74
76
  (req: Request, res: Response, next: NextFunction): Promise<void>;
75
77
  select(value: string | {
76
78
  [key: string]: -1 | 1;
77
- }): /*elided*/ any;
79
+ }): any;
78
80
  sort(value: string | {
79
81
  [key: string]: -1 | 1;
80
- }): /*elided*/ any;
81
- skip(value: number): /*elided*/ any;
82
- limit(value: number): /*elided*/ any;
83
- populate(value: string | object | (string | object)[]): /*elided*/ any;
82
+ }): any;
83
+ skip(value: number): any;
84
+ limit(value: number): any;
85
+ populate(value: string | object | (string | object)[]): any;
84
86
  };
85
87
  deleteMany: (match?: {}) => {
86
88
  (req: Request, res: Response, next: NextFunction): Promise<void>;
87
89
  select(value: string | {
88
90
  [key: string]: -1 | 1;
89
- }): /*elided*/ any;
91
+ }): any;
90
92
  sort(value: string | {
91
93
  [key: string]: -1 | 1;
92
- }): /*elided*/ any;
93
- skip(value: number): /*elided*/ any;
94
- limit(value: number): /*elided*/ any;
95
- populate(value: string | object | (string | object)[]): /*elided*/ any;
94
+ }): any;
95
+ skip(value: number): any;
96
+ limit(value: number): any;
97
+ populate(value: string | object | (string | object)[]): any;
96
98
  };
97
99
  findOne: (match?: {}) => {
98
100
  (req: Request, res: Response, next: NextFunction): Promise<void>;
99
101
  select(value: string | {
100
102
  [key: string]: -1 | 1;
101
- }): /*elided*/ any;
103
+ }): any;
102
104
  sort(value: string | {
103
105
  [key: string]: -1 | 1;
104
- }): /*elided*/ any;
105
- skip(value: number): /*elided*/ any;
106
- limit(value: number): /*elided*/ any;
107
- populate(value: string | object | (string | object)[]): /*elided*/ any;
106
+ }): any;
107
+ skip(value: number): any;
108
+ limit(value: number): any;
109
+ populate(value: string | object | (string | object)[]): any;
108
110
  };
109
111
  findOneAndUpdate: (match?: {}, body?: {}) => {
110
112
  (req: Request, res: Response, next: NextFunction): Promise<void>;
111
113
  select(value: string | {
112
114
  [key: string]: -1 | 1;
113
- }): /*elided*/ any;
115
+ }): any;
114
116
  sort(value: string | {
115
117
  [key: string]: -1 | 1;
116
- }): /*elided*/ any;
117
- skip(value: number): /*elided*/ any;
118
- limit(value: number): /*elided*/ any;
119
- populate(value: string | object | (string | object)[]): /*elided*/ any;
118
+ }): any;
119
+ skip(value: number): any;
120
+ limit(value: number): any;
121
+ populate(value: string | object | (string | object)[]): any;
120
122
  };
121
123
  aggregate: (pipeline?: never[]) => {
122
124
  (req: Request, res: Response, next: NextFunction): Promise<void>;
123
125
  select(value: string | {
124
126
  [key: string]: -1 | 1;
125
- }): /*elided*/ any;
127
+ }): any;
126
128
  sort(value: string | {
127
129
  [key: string]: -1 | 1;
128
- }): /*elided*/ any;
129
- skip(value: number): /*elided*/ any;
130
- limit(value: number): /*elided*/ any;
131
- populate(value: string | object | (string | object)[]): /*elided*/ any;
130
+ }): any;
131
+ skip(value: number): any;
132
+ limit(value: number): any;
133
+ populate(value: string | object | (string | object)[]): any;
132
134
  };
133
135
  findOneAndDelete: (match?: {}) => {
134
136
  (req: Request, res: Response, next: NextFunction): Promise<void>;
135
137
  select(value: string | {
136
138
  [key: string]: -1 | 1;
137
- }): /*elided*/ any;
139
+ }): any;
138
140
  sort(value: string | {
139
141
  [key: string]: -1 | 1;
140
- }): /*elided*/ any;
141
- skip(value: number): /*elided*/ any;
142
- limit(value: number): /*elided*/ any;
143
- populate(value: string | object | (string | object)[]): /*elided*/ any;
142
+ }): any;
143
+ skip(value: number): any;
144
+ limit(value: number): any;
145
+ populate(value: string | object | (string | object)[]): any;
144
146
  };
145
147
  findById: (id?: string) => {
146
148
  (req: Request, res: Response, next: NextFunction): Promise<void>;
147
149
  select(value: string | {
148
150
  [key: string]: -1 | 1;
149
- }): /*elided*/ any;
151
+ }): any;
150
152
  sort(value: string | {
151
153
  [key: string]: -1 | 1;
152
- }): /*elided*/ any;
153
- skip(value: number): /*elided*/ any;
154
- limit(value: number): /*elided*/ any;
155
- populate(value: string | object | (string | object)[]): /*elided*/ any;
154
+ }): any;
155
+ skip(value: number): any;
156
+ limit(value: number): any;
157
+ populate(value: string | object | (string | object)[]): any;
156
158
  };
157
159
  findByIdAndUpdate: (id?: string, body?: {}) => {
158
160
  (req: Request, res: Response, next: NextFunction): Promise<void>;
159
161
  select(value: string | {
160
162
  [key: string]: -1 | 1;
161
- }): /*elided*/ any;
163
+ }): any;
162
164
  sort(value: string | {
163
165
  [key: string]: -1 | 1;
164
- }): /*elided*/ any;
165
- skip(value: number): /*elided*/ any;
166
- limit(value: number): /*elided*/ any;
167
- populate(value: string | object | (string | object)[]): /*elided*/ any;
166
+ }): any;
167
+ skip(value: number): any;
168
+ limit(value: number): any;
169
+ populate(value: string | object | (string | object)[]): any;
168
170
  };
169
171
  findByIdAndDelete: (id?: string) => {
170
172
  (req: Request, res: Response, next: NextFunction): Promise<void>;
171
173
  select(value: string | {
172
174
  [key: string]: -1 | 1;
173
- }): /*elided*/ any;
175
+ }): any;
174
176
  sort(value: string | {
175
177
  [key: string]: -1 | 1;
176
- }): /*elided*/ any;
177
- skip(value: number): /*elided*/ any;
178
- limit(value: number): /*elided*/ any;
179
- populate(value: string | object | (string | object)[]): /*elided*/ any;
178
+ }): any;
179
+ skip(value: number): any;
180
+ limit(value: number): any;
181
+ populate(value: string | object | (string | object)[]): any;
180
182
  };
181
183
  } | undefined;
182
184
  export default db;
package/dist/cjs/db/db.js CHANGED
@@ -14,6 +14,8 @@ let configs = {
14
14
  path: "../models",
15
15
  type: "external",
16
16
  dbEnv: "DB_URL",
17
+ first: false,
18
+ response: true,
17
19
  ...(0, getConfig_1.default)("db"),
18
20
  };
19
21
  const usingMongoDb = (collectionName, config = { type: "external" }) => {
@@ -485,21 +487,32 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
485
487
  : []);
486
488
  }
487
489
  }
488
- const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
489
- const resBody = queryState.action == "aggregate"
490
- ? {
491
- message: config?.message ||
492
- `the ${collectionName} was found successfully`,
493
- content: [],
494
- ...data[0],
495
- }
496
- : {
497
- content: data,
498
- ...{ detail: Object.keys(detail).length ? detail : undefined },
499
- message: config?.message ||
500
- `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
501
- };
502
- res.success ? res.success(200, resBody) : res.status(200).json(resBody);
490
+ if (config?.response) {
491
+ const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
492
+ if (queryState.action == "aggregate" && config.first && data[0]?.content.length)
493
+ data[0].content.length = data[0].content[0];
494
+ const resBody = queryState.action == "aggregate"
495
+ ? {
496
+ message: config?.message ||
497
+ `the ${collectionName} was found successfully`,
498
+ content: [],
499
+ ...data[0],
500
+ }
501
+ : {
502
+ content: data,
503
+ ...{
504
+ detail: Object.keys(detail).length ? detail : undefined,
505
+ },
506
+ message: config?.message ||
507
+ `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
508
+ };
509
+ res.success
510
+ ? res.success(200, resBody)
511
+ : res.status(200).json(resBody);
512
+ }
513
+ else {
514
+ next();
515
+ }
503
516
  }
504
517
  }
505
518
  catch (err) {
@@ -579,6 +592,8 @@ const db = (collectionName, config = configs) => {
579
592
  path: "../models",
580
593
  dbEnv: "DB_URL",
581
594
  type: "external",
595
+ first: false,
596
+ response: true,
582
597
  ...(0, getConfig_1.default)("db"),
583
598
  };
584
599
  Object.entries(config).forEach(([key, value]) => {
@@ -8,58 +8,40 @@ declare const utils: {
8
8
  };
9
9
  declare const models: {
10
10
  translation: import("mongoose").Model<{
11
- createdAt: NativeDate;
12
- updatedAt: NativeDate;
13
- } & {
14
11
  text: string;
15
12
  lang: string;
16
13
  translatedText: string;
17
- }, {}, {}, {}, import("mongoose").Document<unknown, {}, {
18
- createdAt: NativeDate;
19
- updatedAt: NativeDate;
20
- } & {
14
+ } & import("mongoose").DefaultTimestampProps, {}, {}, {}, import("mongoose").Document<unknown, {}, {
21
15
  text: string;
22
16
  lang: string;
23
17
  translatedText: string;
24
- }, {}, {
18
+ } & import("mongoose").DefaultTimestampProps, {}, {
25
19
  timestamps: true;
26
20
  }> & {
27
- createdAt: NativeDate;
28
- updatedAt: NativeDate;
29
- } & {
30
21
  text: string;
31
22
  lang: string;
32
23
  translatedText: string;
33
- } & {
24
+ } & import("mongoose").DefaultTimestampProps & {
34
25
  _id: import("mongoose").Types.ObjectId;
35
26
  } & {
36
27
  __v: number;
37
28
  }, import("mongoose").Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
38
29
  timestamps: true;
39
30
  }, {
40
- createdAt: NativeDate;
41
- updatedAt: NativeDate;
42
- } & {
43
31
  text: string;
44
32
  lang: string;
45
33
  translatedText: string;
46
- }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
47
- createdAt: NativeDate;
48
- updatedAt: NativeDate;
49
- } & {
34
+ } & import("mongoose").DefaultTimestampProps, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
50
35
  text: string;
51
36
  lang: string;
52
37
  translatedText: string;
53
- }>, {}, import("mongoose").ResolveSchemaOptions<{
38
+ } & import("mongoose").DefaultTimestampProps>, {}, import("mongoose").ResolveSchemaOptions<{
54
39
  timestamps: true;
55
40
  }>> & import("mongoose").FlatRecord<{
56
- createdAt: NativeDate;
57
- updatedAt: NativeDate;
58
- } & {
59
41
  text: string;
60
42
  lang: string;
61
43
  translatedText: string;
62
- }> & {
44
+ } & import("mongoose").DefaultTimestampProps> & {
63
45
  _id: import("mongoose").Types.ObjectId;
64
46
  } & {
65
47
  __v: number;
@@ -1,57 +1,39 @@
1
1
  import mongoose from 'mongoose';
2
2
  declare const model: mongoose.Model<{
3
- createdAt: NativeDate;
4
- updatedAt: NativeDate;
5
- } & {
6
3
  text: string;
7
4
  lang: string;
8
5
  translatedText: string;
9
- }, {}, {}, {}, mongoose.Document<unknown, {}, {
10
- createdAt: NativeDate;
11
- updatedAt: NativeDate;
12
- } & {
6
+ } & mongoose.DefaultTimestampProps, {}, {}, {}, mongoose.Document<unknown, {}, {
13
7
  text: string;
14
8
  lang: string;
15
9
  translatedText: string;
16
- }, {}, {
10
+ } & mongoose.DefaultTimestampProps, {}, {
17
11
  timestamps: true;
18
12
  }> & {
19
- createdAt: NativeDate;
20
- updatedAt: NativeDate;
21
- } & {
22
13
  text: string;
23
14
  lang: string;
24
15
  translatedText: string;
25
- } & {
16
+ } & mongoose.DefaultTimestampProps & {
26
17
  _id: mongoose.Types.ObjectId;
27
18
  } & {
28
19
  __v: number;
29
20
  }, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
30
21
  timestamps: true;
31
22
  }, {
32
- createdAt: NativeDate;
33
- updatedAt: NativeDate;
34
- } & {
35
23
  text: string;
36
24
  lang: string;
37
25
  translatedText: string;
38
- }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
39
- createdAt: NativeDate;
40
- updatedAt: NativeDate;
41
- } & {
26
+ } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
42
27
  text: string;
43
28
  lang: string;
44
29
  translatedText: string;
45
- }>, {}, mongoose.ResolveSchemaOptions<{
30
+ } & mongoose.DefaultTimestampProps>, {}, mongoose.ResolveSchemaOptions<{
46
31
  timestamps: true;
47
32
  }>> & mongoose.FlatRecord<{
48
- createdAt: NativeDate;
49
- updatedAt: NativeDate;
50
- } & {
51
33
  text: string;
52
34
  lang: string;
53
35
  translatedText: string;
54
- }> & {
36
+ } & mongoose.DefaultTimestampProps> & {
55
37
  _id: mongoose.Types.ObjectId;
56
38
  } & {
57
39
  __v: number;
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
26
  exports.default = default_1;
37
27
  const yup = __importStar(require("yup"));
@@ -13,6 +13,8 @@ type ConfigsType = {
13
13
  dbType?: string;
14
14
  path?: string;
15
15
  dbEnv?: string;
16
+ response?: boolean;
17
+ first?: boolean;
16
18
  type: "internal" | "external";
17
19
  pagination?: {
18
20
  quantity?: number;
@@ -26,157 +28,157 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
26
28
  (req: Request, res: Response, next: NextFunction): Promise<void>;
27
29
  select(value: string | {
28
30
  [key: string]: -1 | 1;
29
- }): /*elided*/ any;
31
+ }): any;
30
32
  sort(value: string | {
31
33
  [key: string]: -1 | 1;
32
- }): /*elided*/ any;
33
- skip(value: number): /*elided*/ any;
34
- limit(value: number): /*elided*/ any;
35
- populate(value: string | object | (string | object)[]): /*elided*/ any;
34
+ }): any;
35
+ skip(value: number): any;
36
+ limit(value: number): any;
37
+ populate(value: string | object | (string | object)[]): any;
36
38
  };
37
39
  create: (body?: {}) => {
38
40
  (req: Request, res: Response, next: NextFunction): Promise<void>;
39
41
  select(value: string | {
40
42
  [key: string]: -1 | 1;
41
- }): /*elided*/ any;
43
+ }): any;
42
44
  sort(value: string | {
43
45
  [key: string]: -1 | 1;
44
- }): /*elided*/ any;
45
- skip(value: number): /*elided*/ any;
46
- limit(value: number): /*elided*/ any;
47
- populate(value: string | object | (string | object)[]): /*elided*/ any;
46
+ }): any;
47
+ skip(value: number): any;
48
+ limit(value: number): any;
49
+ populate(value: string | object | (string | object)[]): any;
48
50
  };
49
51
  updateOne: (match?: {}, body?: {}) => {
50
52
  (req: Request, res: Response, next: NextFunction): Promise<void>;
51
53
  select(value: string | {
52
54
  [key: string]: -1 | 1;
53
- }): /*elided*/ any;
55
+ }): any;
54
56
  sort(value: string | {
55
57
  [key: string]: -1 | 1;
56
- }): /*elided*/ any;
57
- skip(value: number): /*elided*/ any;
58
- limit(value: number): /*elided*/ any;
59
- populate(value: string | object | (string | object)[]): /*elided*/ any;
58
+ }): any;
59
+ skip(value: number): any;
60
+ limit(value: number): any;
61
+ populate(value: string | object | (string | object)[]): any;
60
62
  };
61
63
  updateMany: (match?: {}, body?: {}) => {
62
64
  (req: Request, res: Response, next: NextFunction): Promise<void>;
63
65
  select(value: string | {
64
66
  [key: string]: -1 | 1;
65
- }): /*elided*/ any;
67
+ }): any;
66
68
  sort(value: string | {
67
69
  [key: string]: -1 | 1;
68
- }): /*elided*/ any;
69
- skip(value: number): /*elided*/ any;
70
- limit(value: number): /*elided*/ any;
71
- populate(value: string | object | (string | object)[]): /*elided*/ any;
70
+ }): any;
71
+ skip(value: number): any;
72
+ limit(value: number): any;
73
+ populate(value: string | object | (string | object)[]): any;
72
74
  };
73
75
  deleteOne: (match?: {}) => {
74
76
  (req: Request, res: Response, next: NextFunction): Promise<void>;
75
77
  select(value: string | {
76
78
  [key: string]: -1 | 1;
77
- }): /*elided*/ any;
79
+ }): any;
78
80
  sort(value: string | {
79
81
  [key: string]: -1 | 1;
80
- }): /*elided*/ any;
81
- skip(value: number): /*elided*/ any;
82
- limit(value: number): /*elided*/ any;
83
- populate(value: string | object | (string | object)[]): /*elided*/ any;
82
+ }): any;
83
+ skip(value: number): any;
84
+ limit(value: number): any;
85
+ populate(value: string | object | (string | object)[]): any;
84
86
  };
85
87
  deleteMany: (match?: {}) => {
86
88
  (req: Request, res: Response, next: NextFunction): Promise<void>;
87
89
  select(value: string | {
88
90
  [key: string]: -1 | 1;
89
- }): /*elided*/ any;
91
+ }): any;
90
92
  sort(value: string | {
91
93
  [key: string]: -1 | 1;
92
- }): /*elided*/ any;
93
- skip(value: number): /*elided*/ any;
94
- limit(value: number): /*elided*/ any;
95
- populate(value: string | object | (string | object)[]): /*elided*/ any;
94
+ }): any;
95
+ skip(value: number): any;
96
+ limit(value: number): any;
97
+ populate(value: string | object | (string | object)[]): any;
96
98
  };
97
99
  findOne: (match?: {}) => {
98
100
  (req: Request, res: Response, next: NextFunction): Promise<void>;
99
101
  select(value: string | {
100
102
  [key: string]: -1 | 1;
101
- }): /*elided*/ any;
103
+ }): any;
102
104
  sort(value: string | {
103
105
  [key: string]: -1 | 1;
104
- }): /*elided*/ any;
105
- skip(value: number): /*elided*/ any;
106
- limit(value: number): /*elided*/ any;
107
- populate(value: string | object | (string | object)[]): /*elided*/ any;
106
+ }): any;
107
+ skip(value: number): any;
108
+ limit(value: number): any;
109
+ populate(value: string | object | (string | object)[]): any;
108
110
  };
109
111
  findOneAndUpdate: (match?: {}, body?: {}) => {
110
112
  (req: Request, res: Response, next: NextFunction): Promise<void>;
111
113
  select(value: string | {
112
114
  [key: string]: -1 | 1;
113
- }): /*elided*/ any;
115
+ }): any;
114
116
  sort(value: string | {
115
117
  [key: string]: -1 | 1;
116
- }): /*elided*/ any;
117
- skip(value: number): /*elided*/ any;
118
- limit(value: number): /*elided*/ any;
119
- populate(value: string | object | (string | object)[]): /*elided*/ any;
118
+ }): any;
119
+ skip(value: number): any;
120
+ limit(value: number): any;
121
+ populate(value: string | object | (string | object)[]): any;
120
122
  };
121
123
  aggregate: (pipeline?: never[]) => {
122
124
  (req: Request, res: Response, next: NextFunction): Promise<void>;
123
125
  select(value: string | {
124
126
  [key: string]: -1 | 1;
125
- }): /*elided*/ any;
127
+ }): any;
126
128
  sort(value: string | {
127
129
  [key: string]: -1 | 1;
128
- }): /*elided*/ any;
129
- skip(value: number): /*elided*/ any;
130
- limit(value: number): /*elided*/ any;
131
- populate(value: string | object | (string | object)[]): /*elided*/ any;
130
+ }): any;
131
+ skip(value: number): any;
132
+ limit(value: number): any;
133
+ populate(value: string | object | (string | object)[]): any;
132
134
  };
133
135
  findOneAndDelete: (match?: {}) => {
134
136
  (req: Request, res: Response, next: NextFunction): Promise<void>;
135
137
  select(value: string | {
136
138
  [key: string]: -1 | 1;
137
- }): /*elided*/ any;
139
+ }): any;
138
140
  sort(value: string | {
139
141
  [key: string]: -1 | 1;
140
- }): /*elided*/ any;
141
- skip(value: number): /*elided*/ any;
142
- limit(value: number): /*elided*/ any;
143
- populate(value: string | object | (string | object)[]): /*elided*/ any;
142
+ }): any;
143
+ skip(value: number): any;
144
+ limit(value: number): any;
145
+ populate(value: string | object | (string | object)[]): any;
144
146
  };
145
147
  findById: (id?: string) => {
146
148
  (req: Request, res: Response, next: NextFunction): Promise<void>;
147
149
  select(value: string | {
148
150
  [key: string]: -1 | 1;
149
- }): /*elided*/ any;
151
+ }): any;
150
152
  sort(value: string | {
151
153
  [key: string]: -1 | 1;
152
- }): /*elided*/ any;
153
- skip(value: number): /*elided*/ any;
154
- limit(value: number): /*elided*/ any;
155
- populate(value: string | object | (string | object)[]): /*elided*/ any;
154
+ }): any;
155
+ skip(value: number): any;
156
+ limit(value: number): any;
157
+ populate(value: string | object | (string | object)[]): any;
156
158
  };
157
159
  findByIdAndUpdate: (id?: string, body?: {}) => {
158
160
  (req: Request, res: Response, next: NextFunction): Promise<void>;
159
161
  select(value: string | {
160
162
  [key: string]: -1 | 1;
161
- }): /*elided*/ any;
163
+ }): any;
162
164
  sort(value: string | {
163
165
  [key: string]: -1 | 1;
164
- }): /*elided*/ any;
165
- skip(value: number): /*elided*/ any;
166
- limit(value: number): /*elided*/ any;
167
- populate(value: string | object | (string | object)[]): /*elided*/ any;
166
+ }): any;
167
+ skip(value: number): any;
168
+ limit(value: number): any;
169
+ populate(value: string | object | (string | object)[]): any;
168
170
  };
169
171
  findByIdAndDelete: (id?: string) => {
170
172
  (req: Request, res: Response, next: NextFunction): Promise<void>;
171
173
  select(value: string | {
172
174
  [key: string]: -1 | 1;
173
- }): /*elided*/ any;
175
+ }): any;
174
176
  sort(value: string | {
175
177
  [key: string]: -1 | 1;
176
- }): /*elided*/ any;
177
- skip(value: number): /*elided*/ any;
178
- limit(value: number): /*elided*/ any;
179
- populate(value: string | object | (string | object)[]): /*elided*/ any;
178
+ }): any;
179
+ skip(value: number): any;
180
+ limit(value: number): any;
181
+ populate(value: string | object | (string | object)[]): any;
180
182
  };
181
183
  } | undefined;
182
184
  export default db;
package/dist/esm/db/db.js CHANGED
@@ -14,6 +14,8 @@ let configs = {
14
14
  path: "../models",
15
15
  type: "external",
16
16
  dbEnv: "DB_URL",
17
+ first: false,
18
+ response: true,
17
19
  ...(0, getConfig_1.default)("db"),
18
20
  };
19
21
  const usingMongoDb = (collectionName, config = { type: "external" }) => {
@@ -485,21 +487,32 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
485
487
  : []);
486
488
  }
487
489
  }
488
- const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
489
- const resBody = queryState.action == "aggregate"
490
- ? {
491
- message: config?.message ||
492
- `the ${collectionName} was found successfully`,
493
- content: [],
494
- ...data[0],
495
- }
496
- : {
497
- content: data,
498
- ...{ detail: Object.keys(detail).length ? detail : undefined },
499
- message: config?.message ||
500
- `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
501
- };
502
- res.success ? res.success(200, resBody) : res.status(200).json(resBody);
490
+ if (config?.response) {
491
+ const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
492
+ if (queryState.action == "aggregate" && config.first && data[0]?.content.length)
493
+ data[0].content.length = data[0].content[0];
494
+ const resBody = queryState.action == "aggregate"
495
+ ? {
496
+ message: config?.message ||
497
+ `the ${collectionName} was found successfully`,
498
+ content: [],
499
+ ...data[0],
500
+ }
501
+ : {
502
+ content: data,
503
+ ...{
504
+ detail: Object.keys(detail).length ? detail : undefined,
505
+ },
506
+ message: config?.message ||
507
+ `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
508
+ };
509
+ res.success
510
+ ? res.success(200, resBody)
511
+ : res.status(200).json(resBody);
512
+ }
513
+ else {
514
+ next();
515
+ }
503
516
  }
504
517
  }
505
518
  catch (err) {
@@ -579,6 +592,8 @@ const db = (collectionName, config = configs) => {
579
592
  path: "../models",
580
593
  dbEnv: "DB_URL",
581
594
  type: "external",
595
+ first: false,
596
+ response: true,
582
597
  ...(0, getConfig_1.default)("db"),
583
598
  };
584
599
  Object.entries(config).forEach(([key, value]) => {
@@ -8,58 +8,40 @@ declare const utils: {
8
8
  };
9
9
  declare const models: {
10
10
  translation: import("mongoose").Model<{
11
- createdAt: NativeDate;
12
- updatedAt: NativeDate;
13
- } & {
14
11
  text: string;
15
12
  lang: string;
16
13
  translatedText: string;
17
- }, {}, {}, {}, import("mongoose").Document<unknown, {}, {
18
- createdAt: NativeDate;
19
- updatedAt: NativeDate;
20
- } & {
14
+ } & import("mongoose").DefaultTimestampProps, {}, {}, {}, import("mongoose").Document<unknown, {}, {
21
15
  text: string;
22
16
  lang: string;
23
17
  translatedText: string;
24
- }, {}, {
18
+ } & import("mongoose").DefaultTimestampProps, {}, {
25
19
  timestamps: true;
26
20
  }> & {
27
- createdAt: NativeDate;
28
- updatedAt: NativeDate;
29
- } & {
30
21
  text: string;
31
22
  lang: string;
32
23
  translatedText: string;
33
- } & {
24
+ } & import("mongoose").DefaultTimestampProps & {
34
25
  _id: import("mongoose").Types.ObjectId;
35
26
  } & {
36
27
  __v: number;
37
28
  }, import("mongoose").Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
38
29
  timestamps: true;
39
30
  }, {
40
- createdAt: NativeDate;
41
- updatedAt: NativeDate;
42
- } & {
43
31
  text: string;
44
32
  lang: string;
45
33
  translatedText: string;
46
- }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
47
- createdAt: NativeDate;
48
- updatedAt: NativeDate;
49
- } & {
34
+ } & import("mongoose").DefaultTimestampProps, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
50
35
  text: string;
51
36
  lang: string;
52
37
  translatedText: string;
53
- }>, {}, import("mongoose").ResolveSchemaOptions<{
38
+ } & import("mongoose").DefaultTimestampProps>, {}, import("mongoose").ResolveSchemaOptions<{
54
39
  timestamps: true;
55
40
  }>> & import("mongoose").FlatRecord<{
56
- createdAt: NativeDate;
57
- updatedAt: NativeDate;
58
- } & {
59
41
  text: string;
60
42
  lang: string;
61
43
  translatedText: string;
62
- }> & {
44
+ } & import("mongoose").DefaultTimestampProps> & {
63
45
  _id: import("mongoose").Types.ObjectId;
64
46
  } & {
65
47
  __v: number;
@@ -1,57 +1,39 @@
1
1
  import mongoose from 'mongoose';
2
2
  declare const model: mongoose.Model<{
3
- createdAt: NativeDate;
4
- updatedAt: NativeDate;
5
- } & {
6
3
  text: string;
7
4
  lang: string;
8
5
  translatedText: string;
9
- }, {}, {}, {}, mongoose.Document<unknown, {}, {
10
- createdAt: NativeDate;
11
- updatedAt: NativeDate;
12
- } & {
6
+ } & mongoose.DefaultTimestampProps, {}, {}, {}, mongoose.Document<unknown, {}, {
13
7
  text: string;
14
8
  lang: string;
15
9
  translatedText: string;
16
- }, {}, {
10
+ } & mongoose.DefaultTimestampProps, {}, {
17
11
  timestamps: true;
18
12
  }> & {
19
- createdAt: NativeDate;
20
- updatedAt: NativeDate;
21
- } & {
22
13
  text: string;
23
14
  lang: string;
24
15
  translatedText: string;
25
- } & {
16
+ } & mongoose.DefaultTimestampProps & {
26
17
  _id: mongoose.Types.ObjectId;
27
18
  } & {
28
19
  __v: number;
29
20
  }, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
30
21
  timestamps: true;
31
22
  }, {
32
- createdAt: NativeDate;
33
- updatedAt: NativeDate;
34
- } & {
35
23
  text: string;
36
24
  lang: string;
37
25
  translatedText: string;
38
- }, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
39
- createdAt: NativeDate;
40
- updatedAt: NativeDate;
41
- } & {
26
+ } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
42
27
  text: string;
43
28
  lang: string;
44
29
  translatedText: string;
45
- }>, {}, mongoose.ResolveSchemaOptions<{
30
+ } & mongoose.DefaultTimestampProps>, {}, mongoose.ResolveSchemaOptions<{
46
31
  timestamps: true;
47
32
  }>> & mongoose.FlatRecord<{
48
- createdAt: NativeDate;
49
- updatedAt: NativeDate;
50
- } & {
51
33
  text: string;
52
34
  lang: string;
53
35
  translatedText: string;
54
- }> & {
36
+ } & mongoose.DefaultTimestampProps> & {
55
37
  _id: mongoose.Types.ObjectId;
56
38
  } & {
57
39
  __v: number;
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
35
25
  Object.defineProperty(exports, "__esModule", { value: true });
36
26
  exports.default = default_1;
37
27
  const yup = __importStar(require("yup"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "1.2.47",
3
+ "version": "1.3.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -1,18 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- type Handler = (req: Request, res: Response, next: (errorMessage?: string) => unknown) => unknown;
3
- type UseAuth = (req: Request, res: Response, next: NextFunction) => UseAuth | {
4
- user?: (...handlers: Handler[]) => unknown;
5
- admin?: (...handlers: [{
6
- permission: string;
7
- }, ...Handler[]] | Handler[]) => unknown;
8
- any?: (...handlers: Handler[]) => unknown;
9
- };
10
- declare const auth: (config?: {
11
- admin: {
12
- role: string;
13
- model: string;
14
- };
15
- jwtSecretEnv: string;
16
- customValidator: (req: Request, key: string) => boolean;
17
- }) => UseAuth;
18
- export default auth;
@@ -1,93 +0,0 @@
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 = {
8
- admin: { role: "ADMIN", model: "../models/admin" },
9
- jwtSecretEnv: "JWT_KEY",
10
- customValidator: (req, key) => {
11
- return true;
12
- },
13
- ...(0, getConfig_1.default)("auth"),
14
- };
15
- const holders = {};
16
- const auth = (config = gConfig) => {
17
- // const adminModel = require('../models/admin')
18
- let handlerState = {};
19
- let useAuth = async (req, res, next) => {
20
- try {
21
- const nextFunc = (handlers, index = 0) => (errorMessage = "") => {
22
- if (errorMessage)
23
- return next(errorMessage);
24
- if (!handlers.length || !handlers[index + 1])
25
- return next();
26
- handlers[index + 1](req, res, nextFunc(handlers, index + 1));
27
- };
28
- const keys = Object.keys(handlerState);
29
- for (let i = 0; i < keys.length; i++) {
30
- const key = keys[i];
31
- if (!handlerState[key]?.handlers?.length)
32
- continue;
33
- if (await gConfig?.customValidator?.(req, key)) {
34
- return await handlerState[key].handlers[0](req, res, nextFunc(handlerState[key].handlers));
35
- }
36
- else if ((await gConfig?.customValidator?.(req, key)) == null) {
37
- return next({ status: 401, json: { message: "unauthorized" } });
38
- }
39
- else if (i === keys.length - 1) {
40
- next({
41
- status: 405,
42
- json: { message: "you don't have access to this section" },
43
- });
44
- }
45
- else
46
- continue;
47
- }
48
- }
49
- catch (error) {
50
- console.log("auth", 42, error);
51
- next({
52
- status: 403,
53
- json: {
54
- message: error instanceof Error
55
- ? error.message
56
- : "error on authentication please login again",
57
- },
58
- });
59
- }
60
- };
61
- holders.admin = (...handlers) => {
62
- if (!Array.isArray(handlers))
63
- throw new Error("handlers must be an array");
64
- const hasConfig = typeof handlers[0] === "object" && "permission" in handlers[0];
65
- const configObj = hasConfig
66
- ? handlers[0]
67
- : undefined;
68
- const handlerFns = hasConfig
69
- ? handlers.slice(1)
70
- : handlers;
71
- handlerState[`admin${configObj?.permission ? `:${configObj.permission}` : ""}`] = {
72
- ...(configObj ? { config: configObj } : {}),
73
- handlers: handlerFns,
74
- };
75
- return useAuth;
76
- };
77
- holders.user = (...handlers) => {
78
- if (!Array.isArray(handlers))
79
- throw new Error("handlers must be an array");
80
- handlerState.user = { handlers };
81
- return useAuth;
82
- };
83
- holders.any = (...handlers) => {
84
- if (!Array.isArray(handlers))
85
- throw new Error("handlers must be an array");
86
- handlerState.any = { handlers };
87
- return useAuth;
88
- };
89
- useAuth = Object.assign(useAuth, holders);
90
- return useAuth;
91
- };
92
- console.log("auth", 81, typeof auth);
93
- exports.default = auth;
@@ -1,2 +0,0 @@
1
- import yup from "yup";
2
- export default yup;
@@ -1,24 +0,0 @@
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 mongoose_1 = require("mongoose");
7
- const yup_1 = __importDefault(require("yup"));
8
- yup_1.default.addMethod(yup_1.default.string, "oid", function (errorMessage = "آیدی درست نیست") {
9
- return this.test({
10
- name: "oid",
11
- message: errorMessage,
12
- test(value) {
13
- if (!value)
14
- return true;
15
- if (value == "$$REMOVE")
16
- return true;
17
- if (!value || !(0, mongoose_1.isValidObjectId)(value)) {
18
- return false; // Invalid ObjectId
19
- }
20
- return true; // Valid ObjectId
21
- },
22
- });
23
- });
24
- exports.default = yup_1.default;