speedly 1.2.47 → 1.2.48
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/dist/cjs/db/db.d.ts +66 -65
- package/dist/cjs/db/db.js +22 -15
- package/dist/cjs/index.d.ts +6 -24
- package/dist/cjs/model/translation.d.ts +6 -24
- package/dist/cjs/util/makeOptional.js +7 -17
- package/dist/esm/db/db.d.ts +66 -65
- package/dist/esm/db/db.js +22 -15
- package/dist/esm/index.d.ts +6 -24
- package/dist/esm/model/translation.d.ts +6 -24
- package/dist/esm/util/makeOptional.js +7 -17
- package/package.json +1 -1
- package/dist/cjs/auth/auth2.d.ts +0 -18
- package/dist/cjs/auth/auth2.js +0 -93
- package/dist/cjs/yup.config.d.ts +0 -2
- package/dist/cjs/yup.config.js +0 -24
package/dist/cjs/db/db.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ type ConfigsType = {
|
|
|
13
13
|
dbType?: string;
|
|
14
14
|
path?: string;
|
|
15
15
|
dbEnv?: string;
|
|
16
|
+
response?: boolean;
|
|
16
17
|
type: "internal" | "external";
|
|
17
18
|
pagination?: {
|
|
18
19
|
quantity?: number;
|
|
@@ -26,157 +27,157 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
|
|
|
26
27
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
27
28
|
select(value: string | {
|
|
28
29
|
[key: string]: -1 | 1;
|
|
29
|
-
}):
|
|
30
|
+
}): any;
|
|
30
31
|
sort(value: string | {
|
|
31
32
|
[key: string]: -1 | 1;
|
|
32
|
-
}):
|
|
33
|
-
skip(value: number):
|
|
34
|
-
limit(value: number):
|
|
35
|
-
populate(value: string | object | (string | object)[]):
|
|
33
|
+
}): any;
|
|
34
|
+
skip(value: number): any;
|
|
35
|
+
limit(value: number): any;
|
|
36
|
+
populate(value: string | object | (string | object)[]): any;
|
|
36
37
|
};
|
|
37
38
|
create: (body?: {}) => {
|
|
38
39
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
39
40
|
select(value: string | {
|
|
40
41
|
[key: string]: -1 | 1;
|
|
41
|
-
}):
|
|
42
|
+
}): any;
|
|
42
43
|
sort(value: string | {
|
|
43
44
|
[key: string]: -1 | 1;
|
|
44
|
-
}):
|
|
45
|
-
skip(value: number):
|
|
46
|
-
limit(value: number):
|
|
47
|
-
populate(value: string | object | (string | object)[]):
|
|
45
|
+
}): any;
|
|
46
|
+
skip(value: number): any;
|
|
47
|
+
limit(value: number): any;
|
|
48
|
+
populate(value: string | object | (string | object)[]): any;
|
|
48
49
|
};
|
|
49
50
|
updateOne: (match?: {}, body?: {}) => {
|
|
50
51
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
51
52
|
select(value: string | {
|
|
52
53
|
[key: string]: -1 | 1;
|
|
53
|
-
}):
|
|
54
|
+
}): any;
|
|
54
55
|
sort(value: string | {
|
|
55
56
|
[key: string]: -1 | 1;
|
|
56
|
-
}):
|
|
57
|
-
skip(value: number):
|
|
58
|
-
limit(value: number):
|
|
59
|
-
populate(value: string | object | (string | object)[]):
|
|
57
|
+
}): any;
|
|
58
|
+
skip(value: number): any;
|
|
59
|
+
limit(value: number): any;
|
|
60
|
+
populate(value: string | object | (string | object)[]): any;
|
|
60
61
|
};
|
|
61
62
|
updateMany: (match?: {}, body?: {}) => {
|
|
62
63
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
63
64
|
select(value: string | {
|
|
64
65
|
[key: string]: -1 | 1;
|
|
65
|
-
}):
|
|
66
|
+
}): any;
|
|
66
67
|
sort(value: string | {
|
|
67
68
|
[key: string]: -1 | 1;
|
|
68
|
-
}):
|
|
69
|
-
skip(value: number):
|
|
70
|
-
limit(value: number):
|
|
71
|
-
populate(value: string | object | (string | object)[]):
|
|
69
|
+
}): any;
|
|
70
|
+
skip(value: number): any;
|
|
71
|
+
limit(value: number): any;
|
|
72
|
+
populate(value: string | object | (string | object)[]): any;
|
|
72
73
|
};
|
|
73
74
|
deleteOne: (match?: {}) => {
|
|
74
75
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
75
76
|
select(value: string | {
|
|
76
77
|
[key: string]: -1 | 1;
|
|
77
|
-
}):
|
|
78
|
+
}): any;
|
|
78
79
|
sort(value: string | {
|
|
79
80
|
[key: string]: -1 | 1;
|
|
80
|
-
}):
|
|
81
|
-
skip(value: number):
|
|
82
|
-
limit(value: number):
|
|
83
|
-
populate(value: string | object | (string | object)[]):
|
|
81
|
+
}): any;
|
|
82
|
+
skip(value: number): any;
|
|
83
|
+
limit(value: number): any;
|
|
84
|
+
populate(value: string | object | (string | object)[]): any;
|
|
84
85
|
};
|
|
85
86
|
deleteMany: (match?: {}) => {
|
|
86
87
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
87
88
|
select(value: string | {
|
|
88
89
|
[key: string]: -1 | 1;
|
|
89
|
-
}):
|
|
90
|
+
}): any;
|
|
90
91
|
sort(value: string | {
|
|
91
92
|
[key: string]: -1 | 1;
|
|
92
|
-
}):
|
|
93
|
-
skip(value: number):
|
|
94
|
-
limit(value: number):
|
|
95
|
-
populate(value: string | object | (string | object)[]):
|
|
93
|
+
}): any;
|
|
94
|
+
skip(value: number): any;
|
|
95
|
+
limit(value: number): any;
|
|
96
|
+
populate(value: string | object | (string | object)[]): any;
|
|
96
97
|
};
|
|
97
98
|
findOne: (match?: {}) => {
|
|
98
99
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
99
100
|
select(value: string | {
|
|
100
101
|
[key: string]: -1 | 1;
|
|
101
|
-
}):
|
|
102
|
+
}): any;
|
|
102
103
|
sort(value: string | {
|
|
103
104
|
[key: string]: -1 | 1;
|
|
104
|
-
}):
|
|
105
|
-
skip(value: number):
|
|
106
|
-
limit(value: number):
|
|
107
|
-
populate(value: string | object | (string | object)[]):
|
|
105
|
+
}): any;
|
|
106
|
+
skip(value: number): any;
|
|
107
|
+
limit(value: number): any;
|
|
108
|
+
populate(value: string | object | (string | object)[]): any;
|
|
108
109
|
};
|
|
109
110
|
findOneAndUpdate: (match?: {}, body?: {}) => {
|
|
110
111
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
111
112
|
select(value: string | {
|
|
112
113
|
[key: string]: -1 | 1;
|
|
113
|
-
}):
|
|
114
|
+
}): any;
|
|
114
115
|
sort(value: string | {
|
|
115
116
|
[key: string]: -1 | 1;
|
|
116
|
-
}):
|
|
117
|
-
skip(value: number):
|
|
118
|
-
limit(value: number):
|
|
119
|
-
populate(value: string | object | (string | object)[]):
|
|
117
|
+
}): any;
|
|
118
|
+
skip(value: number): any;
|
|
119
|
+
limit(value: number): any;
|
|
120
|
+
populate(value: string | object | (string | object)[]): any;
|
|
120
121
|
};
|
|
121
122
|
aggregate: (pipeline?: never[]) => {
|
|
122
123
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
123
124
|
select(value: string | {
|
|
124
125
|
[key: string]: -1 | 1;
|
|
125
|
-
}):
|
|
126
|
+
}): any;
|
|
126
127
|
sort(value: string | {
|
|
127
128
|
[key: string]: -1 | 1;
|
|
128
|
-
}):
|
|
129
|
-
skip(value: number):
|
|
130
|
-
limit(value: number):
|
|
131
|
-
populate(value: string | object | (string | object)[]):
|
|
129
|
+
}): any;
|
|
130
|
+
skip(value: number): any;
|
|
131
|
+
limit(value: number): any;
|
|
132
|
+
populate(value: string | object | (string | object)[]): any;
|
|
132
133
|
};
|
|
133
134
|
findOneAndDelete: (match?: {}) => {
|
|
134
135
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
135
136
|
select(value: string | {
|
|
136
137
|
[key: string]: -1 | 1;
|
|
137
|
-
}):
|
|
138
|
+
}): any;
|
|
138
139
|
sort(value: string | {
|
|
139
140
|
[key: string]: -1 | 1;
|
|
140
|
-
}):
|
|
141
|
-
skip(value: number):
|
|
142
|
-
limit(value: number):
|
|
143
|
-
populate(value: string | object | (string | object)[]):
|
|
141
|
+
}): any;
|
|
142
|
+
skip(value: number): any;
|
|
143
|
+
limit(value: number): any;
|
|
144
|
+
populate(value: string | object | (string | object)[]): any;
|
|
144
145
|
};
|
|
145
146
|
findById: (id?: string) => {
|
|
146
147
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
147
148
|
select(value: string | {
|
|
148
149
|
[key: string]: -1 | 1;
|
|
149
|
-
}):
|
|
150
|
+
}): any;
|
|
150
151
|
sort(value: string | {
|
|
151
152
|
[key: string]: -1 | 1;
|
|
152
|
-
}):
|
|
153
|
-
skip(value: number):
|
|
154
|
-
limit(value: number):
|
|
155
|
-
populate(value: string | object | (string | object)[]):
|
|
153
|
+
}): any;
|
|
154
|
+
skip(value: number): any;
|
|
155
|
+
limit(value: number): any;
|
|
156
|
+
populate(value: string | object | (string | object)[]): any;
|
|
156
157
|
};
|
|
157
158
|
findByIdAndUpdate: (id?: string, body?: {}) => {
|
|
158
159
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
159
160
|
select(value: string | {
|
|
160
161
|
[key: string]: -1 | 1;
|
|
161
|
-
}):
|
|
162
|
+
}): any;
|
|
162
163
|
sort(value: string | {
|
|
163
164
|
[key: string]: -1 | 1;
|
|
164
|
-
}):
|
|
165
|
-
skip(value: number):
|
|
166
|
-
limit(value: number):
|
|
167
|
-
populate(value: string | object | (string | object)[]):
|
|
165
|
+
}): any;
|
|
166
|
+
skip(value: number): any;
|
|
167
|
+
limit(value: number): any;
|
|
168
|
+
populate(value: string | object | (string | object)[]): any;
|
|
168
169
|
};
|
|
169
170
|
findByIdAndDelete: (id?: string) => {
|
|
170
171
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
171
172
|
select(value: string | {
|
|
172
173
|
[key: string]: -1 | 1;
|
|
173
|
-
}):
|
|
174
|
+
}): any;
|
|
174
175
|
sort(value: string | {
|
|
175
176
|
[key: string]: -1 | 1;
|
|
176
|
-
}):
|
|
177
|
-
skip(value: number):
|
|
178
|
-
limit(value: number):
|
|
179
|
-
populate(value: string | object | (string | object)[]):
|
|
177
|
+
}): any;
|
|
178
|
+
skip(value: number): any;
|
|
179
|
+
limit(value: number): any;
|
|
180
|
+
populate(value: string | object | (string | object)[]): any;
|
|
180
181
|
};
|
|
181
182
|
} | undefined;
|
|
182
183
|
export default db;
|
package/dist/cjs/db/db.js
CHANGED
|
@@ -14,6 +14,7 @@ let configs = {
|
|
|
14
14
|
path: "../models",
|
|
15
15
|
type: "external",
|
|
16
16
|
dbEnv: "DB_URL",
|
|
17
|
+
response: true,
|
|
17
18
|
...(0, getConfig_1.default)("db"),
|
|
18
19
|
};
|
|
19
20
|
const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
@@ -485,21 +486,26 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
|
485
486
|
: []);
|
|
486
487
|
}
|
|
487
488
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
489
|
+
if (config?.response) {
|
|
490
|
+
const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
|
|
491
|
+
const resBody = queryState.action == "aggregate"
|
|
492
|
+
? {
|
|
493
|
+
message: config?.message ||
|
|
494
|
+
`the ${collectionName} was found successfully`,
|
|
495
|
+
content: [],
|
|
496
|
+
...data[0],
|
|
497
|
+
}
|
|
498
|
+
: {
|
|
499
|
+
content: data,
|
|
500
|
+
...{ detail: Object.keys(detail).length ? detail : undefined },
|
|
501
|
+
message: config?.message ||
|
|
502
|
+
`the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
|
|
503
|
+
};
|
|
504
|
+
res.success ? res.success(200, resBody) : res.status(200).json(resBody);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
next();
|
|
508
|
+
}
|
|
503
509
|
}
|
|
504
510
|
}
|
|
505
511
|
catch (err) {
|
|
@@ -579,6 +585,7 @@ const db = (collectionName, config = configs) => {
|
|
|
579
585
|
path: "../models",
|
|
580
586
|
dbEnv: "DB_URL",
|
|
581
587
|
type: "external",
|
|
588
|
+
response: true,
|
|
582
589
|
...(0, getConfig_1.default)("db"),
|
|
583
590
|
};
|
|
584
591
|
Object.entries(config).forEach(([key, value]) => {
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -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) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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/dist/esm/db/db.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ type ConfigsType = {
|
|
|
13
13
|
dbType?: string;
|
|
14
14
|
path?: string;
|
|
15
15
|
dbEnv?: string;
|
|
16
|
+
response?: boolean;
|
|
16
17
|
type: "internal" | "external";
|
|
17
18
|
pagination?: {
|
|
18
19
|
quantity?: number;
|
|
@@ -26,157 +27,157 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
|
|
|
26
27
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
27
28
|
select(value: string | {
|
|
28
29
|
[key: string]: -1 | 1;
|
|
29
|
-
}):
|
|
30
|
+
}): any;
|
|
30
31
|
sort(value: string | {
|
|
31
32
|
[key: string]: -1 | 1;
|
|
32
|
-
}):
|
|
33
|
-
skip(value: number):
|
|
34
|
-
limit(value: number):
|
|
35
|
-
populate(value: string | object | (string | object)[]):
|
|
33
|
+
}): any;
|
|
34
|
+
skip(value: number): any;
|
|
35
|
+
limit(value: number): any;
|
|
36
|
+
populate(value: string | object | (string | object)[]): any;
|
|
36
37
|
};
|
|
37
38
|
create: (body?: {}) => {
|
|
38
39
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
39
40
|
select(value: string | {
|
|
40
41
|
[key: string]: -1 | 1;
|
|
41
|
-
}):
|
|
42
|
+
}): any;
|
|
42
43
|
sort(value: string | {
|
|
43
44
|
[key: string]: -1 | 1;
|
|
44
|
-
}):
|
|
45
|
-
skip(value: number):
|
|
46
|
-
limit(value: number):
|
|
47
|
-
populate(value: string | object | (string | object)[]):
|
|
45
|
+
}): any;
|
|
46
|
+
skip(value: number): any;
|
|
47
|
+
limit(value: number): any;
|
|
48
|
+
populate(value: string | object | (string | object)[]): any;
|
|
48
49
|
};
|
|
49
50
|
updateOne: (match?: {}, body?: {}) => {
|
|
50
51
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
51
52
|
select(value: string | {
|
|
52
53
|
[key: string]: -1 | 1;
|
|
53
|
-
}):
|
|
54
|
+
}): any;
|
|
54
55
|
sort(value: string | {
|
|
55
56
|
[key: string]: -1 | 1;
|
|
56
|
-
}):
|
|
57
|
-
skip(value: number):
|
|
58
|
-
limit(value: number):
|
|
59
|
-
populate(value: string | object | (string | object)[]):
|
|
57
|
+
}): any;
|
|
58
|
+
skip(value: number): any;
|
|
59
|
+
limit(value: number): any;
|
|
60
|
+
populate(value: string | object | (string | object)[]): any;
|
|
60
61
|
};
|
|
61
62
|
updateMany: (match?: {}, body?: {}) => {
|
|
62
63
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
63
64
|
select(value: string | {
|
|
64
65
|
[key: string]: -1 | 1;
|
|
65
|
-
}):
|
|
66
|
+
}): any;
|
|
66
67
|
sort(value: string | {
|
|
67
68
|
[key: string]: -1 | 1;
|
|
68
|
-
}):
|
|
69
|
-
skip(value: number):
|
|
70
|
-
limit(value: number):
|
|
71
|
-
populate(value: string | object | (string | object)[]):
|
|
69
|
+
}): any;
|
|
70
|
+
skip(value: number): any;
|
|
71
|
+
limit(value: number): any;
|
|
72
|
+
populate(value: string | object | (string | object)[]): any;
|
|
72
73
|
};
|
|
73
74
|
deleteOne: (match?: {}) => {
|
|
74
75
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
75
76
|
select(value: string | {
|
|
76
77
|
[key: string]: -1 | 1;
|
|
77
|
-
}):
|
|
78
|
+
}): any;
|
|
78
79
|
sort(value: string | {
|
|
79
80
|
[key: string]: -1 | 1;
|
|
80
|
-
}):
|
|
81
|
-
skip(value: number):
|
|
82
|
-
limit(value: number):
|
|
83
|
-
populate(value: string | object | (string | object)[]):
|
|
81
|
+
}): any;
|
|
82
|
+
skip(value: number): any;
|
|
83
|
+
limit(value: number): any;
|
|
84
|
+
populate(value: string | object | (string | object)[]): any;
|
|
84
85
|
};
|
|
85
86
|
deleteMany: (match?: {}) => {
|
|
86
87
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
87
88
|
select(value: string | {
|
|
88
89
|
[key: string]: -1 | 1;
|
|
89
|
-
}):
|
|
90
|
+
}): any;
|
|
90
91
|
sort(value: string | {
|
|
91
92
|
[key: string]: -1 | 1;
|
|
92
|
-
}):
|
|
93
|
-
skip(value: number):
|
|
94
|
-
limit(value: number):
|
|
95
|
-
populate(value: string | object | (string | object)[]):
|
|
93
|
+
}): any;
|
|
94
|
+
skip(value: number): any;
|
|
95
|
+
limit(value: number): any;
|
|
96
|
+
populate(value: string | object | (string | object)[]): any;
|
|
96
97
|
};
|
|
97
98
|
findOne: (match?: {}) => {
|
|
98
99
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
99
100
|
select(value: string | {
|
|
100
101
|
[key: string]: -1 | 1;
|
|
101
|
-
}):
|
|
102
|
+
}): any;
|
|
102
103
|
sort(value: string | {
|
|
103
104
|
[key: string]: -1 | 1;
|
|
104
|
-
}):
|
|
105
|
-
skip(value: number):
|
|
106
|
-
limit(value: number):
|
|
107
|
-
populate(value: string | object | (string | object)[]):
|
|
105
|
+
}): any;
|
|
106
|
+
skip(value: number): any;
|
|
107
|
+
limit(value: number): any;
|
|
108
|
+
populate(value: string | object | (string | object)[]): any;
|
|
108
109
|
};
|
|
109
110
|
findOneAndUpdate: (match?: {}, body?: {}) => {
|
|
110
111
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
111
112
|
select(value: string | {
|
|
112
113
|
[key: string]: -1 | 1;
|
|
113
|
-
}):
|
|
114
|
+
}): any;
|
|
114
115
|
sort(value: string | {
|
|
115
116
|
[key: string]: -1 | 1;
|
|
116
|
-
}):
|
|
117
|
-
skip(value: number):
|
|
118
|
-
limit(value: number):
|
|
119
|
-
populate(value: string | object | (string | object)[]):
|
|
117
|
+
}): any;
|
|
118
|
+
skip(value: number): any;
|
|
119
|
+
limit(value: number): any;
|
|
120
|
+
populate(value: string | object | (string | object)[]): any;
|
|
120
121
|
};
|
|
121
122
|
aggregate: (pipeline?: never[]) => {
|
|
122
123
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
123
124
|
select(value: string | {
|
|
124
125
|
[key: string]: -1 | 1;
|
|
125
|
-
}):
|
|
126
|
+
}): any;
|
|
126
127
|
sort(value: string | {
|
|
127
128
|
[key: string]: -1 | 1;
|
|
128
|
-
}):
|
|
129
|
-
skip(value: number):
|
|
130
|
-
limit(value: number):
|
|
131
|
-
populate(value: string | object | (string | object)[]):
|
|
129
|
+
}): any;
|
|
130
|
+
skip(value: number): any;
|
|
131
|
+
limit(value: number): any;
|
|
132
|
+
populate(value: string | object | (string | object)[]): any;
|
|
132
133
|
};
|
|
133
134
|
findOneAndDelete: (match?: {}) => {
|
|
134
135
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
135
136
|
select(value: string | {
|
|
136
137
|
[key: string]: -1 | 1;
|
|
137
|
-
}):
|
|
138
|
+
}): any;
|
|
138
139
|
sort(value: string | {
|
|
139
140
|
[key: string]: -1 | 1;
|
|
140
|
-
}):
|
|
141
|
-
skip(value: number):
|
|
142
|
-
limit(value: number):
|
|
143
|
-
populate(value: string | object | (string | object)[]):
|
|
141
|
+
}): any;
|
|
142
|
+
skip(value: number): any;
|
|
143
|
+
limit(value: number): any;
|
|
144
|
+
populate(value: string | object | (string | object)[]): any;
|
|
144
145
|
};
|
|
145
146
|
findById: (id?: string) => {
|
|
146
147
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
147
148
|
select(value: string | {
|
|
148
149
|
[key: string]: -1 | 1;
|
|
149
|
-
}):
|
|
150
|
+
}): any;
|
|
150
151
|
sort(value: string | {
|
|
151
152
|
[key: string]: -1 | 1;
|
|
152
|
-
}):
|
|
153
|
-
skip(value: number):
|
|
154
|
-
limit(value: number):
|
|
155
|
-
populate(value: string | object | (string | object)[]):
|
|
153
|
+
}): any;
|
|
154
|
+
skip(value: number): any;
|
|
155
|
+
limit(value: number): any;
|
|
156
|
+
populate(value: string | object | (string | object)[]): any;
|
|
156
157
|
};
|
|
157
158
|
findByIdAndUpdate: (id?: string, body?: {}) => {
|
|
158
159
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
159
160
|
select(value: string | {
|
|
160
161
|
[key: string]: -1 | 1;
|
|
161
|
-
}):
|
|
162
|
+
}): any;
|
|
162
163
|
sort(value: string | {
|
|
163
164
|
[key: string]: -1 | 1;
|
|
164
|
-
}):
|
|
165
|
-
skip(value: number):
|
|
166
|
-
limit(value: number):
|
|
167
|
-
populate(value: string | object | (string | object)[]):
|
|
165
|
+
}): any;
|
|
166
|
+
skip(value: number): any;
|
|
167
|
+
limit(value: number): any;
|
|
168
|
+
populate(value: string | object | (string | object)[]): any;
|
|
168
169
|
};
|
|
169
170
|
findByIdAndDelete: (id?: string) => {
|
|
170
171
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
171
172
|
select(value: string | {
|
|
172
173
|
[key: string]: -1 | 1;
|
|
173
|
-
}):
|
|
174
|
+
}): any;
|
|
174
175
|
sort(value: string | {
|
|
175
176
|
[key: string]: -1 | 1;
|
|
176
|
-
}):
|
|
177
|
-
skip(value: number):
|
|
178
|
-
limit(value: number):
|
|
179
|
-
populate(value: string | object | (string | object)[]):
|
|
177
|
+
}): any;
|
|
178
|
+
skip(value: number): any;
|
|
179
|
+
limit(value: number): any;
|
|
180
|
+
populate(value: string | object | (string | object)[]): any;
|
|
180
181
|
};
|
|
181
182
|
} | undefined;
|
|
182
183
|
export default db;
|
package/dist/esm/db/db.js
CHANGED
|
@@ -14,6 +14,7 @@ let configs = {
|
|
|
14
14
|
path: "../models",
|
|
15
15
|
type: "external",
|
|
16
16
|
dbEnv: "DB_URL",
|
|
17
|
+
response: true,
|
|
17
18
|
...(0, getConfig_1.default)("db"),
|
|
18
19
|
};
|
|
19
20
|
const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
@@ -485,21 +486,26 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
|
485
486
|
: []);
|
|
486
487
|
}
|
|
487
488
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
489
|
+
if (config?.response) {
|
|
490
|
+
const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
|
|
491
|
+
const resBody = queryState.action == "aggregate"
|
|
492
|
+
? {
|
|
493
|
+
message: config?.message ||
|
|
494
|
+
`the ${collectionName} was found successfully`,
|
|
495
|
+
content: [],
|
|
496
|
+
...data[0],
|
|
497
|
+
}
|
|
498
|
+
: {
|
|
499
|
+
content: data,
|
|
500
|
+
...{ detail: Object.keys(detail).length ? detail : undefined },
|
|
501
|
+
message: config?.message ||
|
|
502
|
+
`the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
|
|
503
|
+
};
|
|
504
|
+
res.success ? res.success(200, resBody) : res.status(200).json(resBody);
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
next();
|
|
508
|
+
}
|
|
503
509
|
}
|
|
504
510
|
}
|
|
505
511
|
catch (err) {
|
|
@@ -579,6 +585,7 @@ const db = (collectionName, config = configs) => {
|
|
|
579
585
|
path: "../models",
|
|
580
586
|
dbEnv: "DB_URL",
|
|
581
587
|
type: "external",
|
|
588
|
+
response: true,
|
|
582
589
|
...(0, getConfig_1.default)("db"),
|
|
583
590
|
};
|
|
584
591
|
Object.entries(config).forEach(([key, value]) => {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -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) ||
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
package/dist/cjs/auth/auth2.d.ts
DELETED
|
@@ -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;
|
package/dist/cjs/auth/auth2.js
DELETED
|
@@ -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;
|
package/dist/cjs/yup.config.d.ts
DELETED
package/dist/cjs/yup.config.js
DELETED
|
@@ -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;
|