speedly 2.0.43 → 2.0.44
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/configs.default.d.ts +36 -0
- package/dist/cjs/configs.default.js +32 -0
- package/dist/cjs/kit/auth/auth.js +1 -8
- package/dist/cjs/kit/db/db.d.ts +2 -15
- package/dist/cjs/kit/db/db.js +8 -37
- package/dist/cjs/kit/uploader/uploader.d.ts +0 -1
- package/dist/cjs/kit/uploader/uploader.js +3 -9
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.js +155 -0
- package/dist/cjs/util/getConfig.d.ts +2 -3
- package/dist/cjs/util/getConfig.js +15 -3
- package/dist/cjs/util/importFromPwd.d.ts +1 -0
- package/dist/cjs/util/importFromPwd.js +22 -0
- package/dist/cjs/util/index.d.ts +3 -1
- package/dist/cjs/util/index.js +5 -1
- package/dist/cjs/util/translator.js +2 -2
- package/dist/esm/configs.default.d.ts +36 -0
- package/dist/esm/configs.default.js +32 -0
- package/dist/esm/kit/auth/auth.js +1 -8
- package/dist/esm/kit/db/db.d.ts +2 -15
- package/dist/esm/kit/db/db.js +8 -37
- package/dist/esm/kit/uploader/uploader.d.ts +0 -1
- package/dist/esm/kit/uploader/uploader.js +3 -9
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +155 -0
- package/dist/esm/util/getConfig.d.ts +2 -3
- package/dist/esm/util/getConfig.js +15 -3
- package/dist/esm/util/importFromPwd.d.ts +1 -0
- package/dist/esm/util/importFromPwd.js +22 -0
- package/dist/esm/util/index.d.ts +3 -1
- package/dist/esm/util/index.js +5 -1
- package/dist/esm/util/translator.js +2 -2
- package/package.json +52 -19
- package/dist/config/init.d.ts +0 -23
- package/dist/config/init.js +0 -93
- package/dist/document/document.d.ts +0 -5
- package/dist/document/document.js +0 -270
- package/dist/document/index.d.ts +0 -2
- package/dist/document/index.js +0 -7
- package/dist/document/parser.d.ts +0 -1
- package/dist/document/parser.js +0 -11
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -13
- package/dist/kit/auth/auth.d.ts +0 -3
- package/dist/kit/auth/auth.js +0 -38
- package/dist/kit/auth/types.d.ts +0 -19
- package/dist/kit/auth/types.js +0 -2
- package/dist/kit/db/db.d.ts +0 -197
- package/dist/kit/db/db.js +0 -619
- package/dist/kit/db/utils.d.ts +0 -3
- package/dist/kit/db/utils.js +0 -15
- package/dist/kit/index.d.ts +0 -5
- package/dist/kit/index.js +0 -14
- package/dist/kit/uploader/uploader.d.ts +0 -24
- package/dist/kit/uploader/uploader.js +0 -150
- package/dist/kit/validator/validator.d.ts +0 -9
- package/dist/kit/validator/validator.js +0 -36
- package/dist/model/index.d.ts +0 -2
- package/dist/model/index.js +0 -8
- package/dist/model/translation.d.ts +0 -71
- package/dist/model/translation.js +0 -13
- package/dist/modules/index.d.ts +0 -2
- package/dist/modules/index.js +0 -8
- package/dist/modules/translation/translation.routes.d.ts +0 -2
- package/dist/modules/translation/translation.routes.js +0 -24
- package/dist/modules/translation/translation.validator.d.ts +0 -15
- package/dist/modules/translation/translation.validator.js +0 -22
- package/dist/util/getConfig.d.ts +0 -4
- package/dist/util/getConfig.js +0 -40
- package/dist/util/index.d.ts +0 -2
- package/dist/util/index.js +0 -8
- package/dist/util/makeOptional.d.ts +0 -10
- package/dist/util/makeOptional.js +0 -47
- package/dist/util/strToObj.d.ts +0 -2
- package/dist/util/strToObj.js +0 -9
- package/dist/util/translator.d.ts +0 -2
- package/dist/util/translator.js +0 -74
- package/examples/blog-routes/blog/blog.routes.js +0 -15
- package/examples/blog-routes/blog/blog.validator.js +0 -35
- package/examples/blog-routes/role/role.routes.js +0 -14
- package/examples/blog-routes/role/role.validator.js +0 -28
- package/examples/blog-routes/user/user.controller.js +0 -97
- package/examples/blog-routes/user/user.routes.js +0 -18
- package/examples/blog-routes/user/user.validator.js +0 -53
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Request } from "express";
|
|
2
|
+
export interface DefaultConfig {
|
|
3
|
+
uploader: {
|
|
4
|
+
saveInDb: boolean;
|
|
5
|
+
prefix: string;
|
|
6
|
+
limit: number;
|
|
7
|
+
format: RegExp;
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
db: {
|
|
11
|
+
dbType: string;
|
|
12
|
+
path: string;
|
|
13
|
+
type: 'internal' | 'external';
|
|
14
|
+
dbEnv: string;
|
|
15
|
+
first: boolean;
|
|
16
|
+
response: boolean;
|
|
17
|
+
pagination: {
|
|
18
|
+
quantity?: number;
|
|
19
|
+
detailed?: boolean;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
} | false;
|
|
22
|
+
};
|
|
23
|
+
auth: {
|
|
24
|
+
admin: {
|
|
25
|
+
role: string;
|
|
26
|
+
model: string;
|
|
27
|
+
};
|
|
28
|
+
jwtSecretEnv: string;
|
|
29
|
+
customValidator: (req: Request, key: string) => (boolean | null) | Promise<boolean | null> | null;
|
|
30
|
+
};
|
|
31
|
+
translate: {
|
|
32
|
+
one_api_token: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
declare const defaultConfigs: DefaultConfig;
|
|
36
|
+
export default defaultConfigs;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const defaultConfigs = {
|
|
4
|
+
uploader: {
|
|
5
|
+
saveInDb: false,
|
|
6
|
+
prefix: "",
|
|
7
|
+
limit: 5,
|
|
8
|
+
format: /png|jpg|webp|jpeg/i,
|
|
9
|
+
path: "../../../public",
|
|
10
|
+
},
|
|
11
|
+
db: {
|
|
12
|
+
dbType: "mongodb",
|
|
13
|
+
path: "../model",
|
|
14
|
+
type: "external",
|
|
15
|
+
dbEnv: "DB_URL",
|
|
16
|
+
first: false,
|
|
17
|
+
response: true,
|
|
18
|
+
pagination: {
|
|
19
|
+
detailed: true,
|
|
20
|
+
quantity: 20
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
auth: {
|
|
24
|
+
admin: { role: "ADMIN", model: "../models/admin" },
|
|
25
|
+
jwtSecretEnv: "JWT_KEY",
|
|
26
|
+
customValidator: (req, key) => {
|
|
27
|
+
return true;
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
translate: { one_api_token: "" }
|
|
31
|
+
};
|
|
32
|
+
exports.default = defaultConfigs;
|
|
@@ -4,14 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
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
|
-
};
|
|
7
|
+
const gConfig = (0, getConfig_1.default)("auth");
|
|
15
8
|
const executer = (authType) => {
|
|
16
9
|
const mw = async (req, res, next) => {
|
|
17
10
|
const accessResult = await gConfig?.customValidator?.(req, authType);
|
package/dist/cjs/kit/db/db.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { DefaultConfig } from "../../configs.default";
|
|
2
3
|
declare module "express-serve-static-core" {
|
|
3
4
|
interface Request {
|
|
4
5
|
document?: any;
|
|
@@ -9,21 +10,7 @@ declare module "express-serve-static-core" {
|
|
|
9
10
|
success?: (statusCode: number, body: any) => void;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
dbType?: string;
|
|
14
|
-
path?: string;
|
|
15
|
-
dbEnv?: string;
|
|
16
|
-
response?: boolean;
|
|
17
|
-
first?: boolean;
|
|
18
|
-
type: "internal" | "external";
|
|
19
|
-
pagination?: {
|
|
20
|
-
quantity?: number;
|
|
21
|
-
detailed?: boolean;
|
|
22
|
-
[key: string]: unknown;
|
|
23
|
-
};
|
|
24
|
-
[key: string]: unknown;
|
|
25
|
-
};
|
|
26
|
-
declare const db: (collectionName: string, config?: ConfigsType) => {
|
|
13
|
+
declare const db: (collectionName: string, config?: Partial<DefaultConfig["db"]>) => {
|
|
27
14
|
find: (match?: {}) => {
|
|
28
15
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
29
16
|
select(value: string | {
|
package/dist/cjs/kit/db/db.js
CHANGED
|
@@ -9,15 +9,7 @@ const strToObj_1 = __importDefault(require("../../util/strToObj"));
|
|
|
9
9
|
const getConfig_1 = __importDefault(require("../../util/getConfig"));
|
|
10
10
|
const translator_1 = __importDefault(require("../../util/translator"));
|
|
11
11
|
const utils_1 = require("./utils");
|
|
12
|
-
let configs =
|
|
13
|
-
dbType: "mongodb",
|
|
14
|
-
path: "../models",
|
|
15
|
-
type: "external",
|
|
16
|
-
dbEnv: "DB_URL",
|
|
17
|
-
first: false,
|
|
18
|
-
response: true,
|
|
19
|
-
...(0, getConfig_1.default)("db"),
|
|
20
|
-
};
|
|
12
|
+
let configs = (0, getConfig_1.default)("db");
|
|
21
13
|
const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
22
14
|
let model;
|
|
23
15
|
let queryState = {
|
|
@@ -207,7 +199,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
|
207
199
|
},
|
|
208
200
|
});
|
|
209
201
|
}
|
|
210
|
-
if (req.query.page && queryState.action !== "aggregate") {
|
|
202
|
+
if (configs.pagination && req.query.page && queryState.action !== "aggregate") {
|
|
211
203
|
const pageStr = Array.isArray(req.query.page)
|
|
212
204
|
? req.query.page[0]
|
|
213
205
|
: typeof req.query.page === "string"
|
|
@@ -235,7 +227,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
|
235
227
|
value: limitNum,
|
|
236
228
|
});
|
|
237
229
|
}
|
|
238
|
-
else if (req.query.limit && queryState.action !== "aggregate") {
|
|
230
|
+
else if (configs.pagination && req.query.limit && queryState.action !== "aggregate") {
|
|
239
231
|
const limitStr = Array.isArray(req.query.limit)
|
|
240
232
|
? req.query.limit[0]
|
|
241
233
|
: typeof req.query.limit === "string"
|
|
@@ -278,23 +270,9 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
|
278
270
|
}
|
|
279
271
|
}
|
|
280
272
|
try {
|
|
281
|
-
const page = parseInt(Array.isArray(req.query.page)
|
|
282
|
-
? String(req.query.page[0])
|
|
283
|
-
: typeof req.query.page === "string"
|
|
284
|
-
? req.query.page
|
|
285
|
-
: "") || 1;
|
|
286
|
-
const limit = parseInt(Array.isArray(req.query.limit)
|
|
287
|
-
? String(req.query.limit[0])
|
|
288
|
-
: typeof req.query.limit === "string"
|
|
289
|
-
? req.query.limit
|
|
290
|
-
: req.query.limit !== undefined
|
|
291
|
-
? String(req.query.limit)
|
|
292
|
-
: "") ||
|
|
293
|
-
configs.pagination?.quantity ||
|
|
294
|
-
20;
|
|
295
273
|
switch (queryState.action) {
|
|
296
274
|
case "find":
|
|
297
|
-
if (configs.pagination?.detailed && req.query.page) {
|
|
275
|
+
if (configs.pagination && configs.pagination?.detailed && req.query.page) {
|
|
298
276
|
const page = parseInt(Array.isArray(req.query.page)
|
|
299
277
|
? String(req.query.page[0])
|
|
300
278
|
: typeof req.query.page === "string"
|
|
@@ -372,7 +350,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
|
372
350
|
data = model?.[queryState.action]?.call(model, queryState.id || req.params.id);
|
|
373
351
|
break;
|
|
374
352
|
case "aggregate":
|
|
375
|
-
if (configs.pagination?.detailed && req.query.page) {
|
|
353
|
+
if (configs.pagination && configs.pagination?.detailed && req.query.page) {
|
|
376
354
|
const page = parseInt(req.query.page) || 1;
|
|
377
355
|
const limit = parseInt(req.query.limit) ||
|
|
378
356
|
configs.pagination?.quantity ||
|
|
@@ -607,17 +585,10 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
|
|
|
607
585
|
// return chainActions;
|
|
608
586
|
// };
|
|
609
587
|
const db = (collectionName, config = configs) => {
|
|
610
|
-
let generatedConfig =
|
|
611
|
-
dbType: "mongodb",
|
|
612
|
-
path: "../models",
|
|
613
|
-
dbEnv: "DB_URL",
|
|
614
|
-
type: "external",
|
|
615
|
-
first: false,
|
|
616
|
-
response: true,
|
|
617
|
-
...(0, getConfig_1.default)("db"),
|
|
618
|
-
};
|
|
588
|
+
let generatedConfig = (0, getConfig_1.default)("db");
|
|
619
589
|
Object.entries(config).forEach(([key, value]) => {
|
|
620
|
-
|
|
590
|
+
if (key in generatedConfig)
|
|
591
|
+
generatedConfig[key] = value;
|
|
621
592
|
});
|
|
622
593
|
switch (generatedConfig.dbType) {
|
|
623
594
|
case "mongodb":
|
|
@@ -8,7 +8,6 @@ declare global {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
declare const _default: (destination: string | ((req: Request, file: Express.Multer.File) => string) | undefined, filename: string | ((req: Request, file: Express.Multer.File) => string), config?: {
|
|
11
|
-
[key: string]: any;
|
|
12
11
|
saveInDb: boolean;
|
|
13
12
|
prefix: string;
|
|
14
13
|
limit: number;
|
|
@@ -8,19 +8,13 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const multer_1 = __importDefault(require("multer"));
|
|
9
9
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
10
|
const getConfig_1 = __importDefault(require("../../util/getConfig"));
|
|
11
|
-
let configs =
|
|
12
|
-
saveInDb: false,
|
|
13
|
-
prefix: "",
|
|
14
|
-
limit: 5,
|
|
15
|
-
format: /png|jpg|webp|jpeg/i,
|
|
16
|
-
path: "../../../public",
|
|
17
|
-
...(0, getConfig_1.default)("uploader"),
|
|
18
|
-
};
|
|
11
|
+
let configs = (0, getConfig_1.default)("uploader");
|
|
19
12
|
exports.default = (destination = "/image", filename, config = configs) => {
|
|
20
13
|
let dest;
|
|
21
14
|
try {
|
|
22
15
|
Object.entries(config).forEach(([key, val]) => {
|
|
23
|
-
|
|
16
|
+
if (key in configs)
|
|
17
|
+
configs[key] = val;
|
|
24
18
|
});
|
|
25
19
|
const storage = multer_1.default.diskStorage({
|
|
26
20
|
destination: function (req, file, cb) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
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 configs = {
|
|
8
|
+
model: (0, getConfig_1.default)('db'),
|
|
9
|
+
uploader: (0, getConfig_1.default)('uploader')
|
|
10
|
+
};
|
|
11
|
+
const mongoose_1 = require("mongoose");
|
|
12
|
+
const importFromPwd_1 = __importDefault(require("../util/importFromPwd"));
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const media = (0, importFromPwd_1.default)(path_1.default.join("..", "model", "media"));
|
|
15
|
+
const yup_1 = __importDefault(require("yup"));
|
|
16
|
+
const fs_1 = __importDefault(require("fs"));
|
|
17
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
18
|
+
const types = {
|
|
19
|
+
file: {
|
|
20
|
+
min: 0,
|
|
21
|
+
max: Infinity,
|
|
22
|
+
validFormat: /.+/,
|
|
23
|
+
},
|
|
24
|
+
image: {
|
|
25
|
+
min: 0,
|
|
26
|
+
max: Infinity,
|
|
27
|
+
validFormat: /.+/,
|
|
28
|
+
},
|
|
29
|
+
video: {
|
|
30
|
+
min: 0,
|
|
31
|
+
max: Infinity,
|
|
32
|
+
validFormat: /.+/,
|
|
33
|
+
},
|
|
34
|
+
audio: {
|
|
35
|
+
min: 0,
|
|
36
|
+
max: Infinity,
|
|
37
|
+
validFormat: /.+/,
|
|
38
|
+
},
|
|
39
|
+
element: {
|
|
40
|
+
min: 0,
|
|
41
|
+
max: Infinity,
|
|
42
|
+
validFormat: /.+/,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
// Add a global method for strings to ensure they are valid ObjectIds
|
|
46
|
+
yup_1.default.addMethod(yup_1.default.string, "oid", function (errorMessage = "آیدی درست نیست") {
|
|
47
|
+
return this.test({
|
|
48
|
+
name: "oid",
|
|
49
|
+
message: errorMessage,
|
|
50
|
+
test(value) {
|
|
51
|
+
if (!value)
|
|
52
|
+
return true;
|
|
53
|
+
if (value == "$$REMOVE")
|
|
54
|
+
return true;
|
|
55
|
+
if (!value || !(0, mongoose_1.isValidObjectId)(value)) {
|
|
56
|
+
return false; // Invalid ObjectId
|
|
57
|
+
}
|
|
58
|
+
return true; // Valid ObjectId
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
yup_1.default.addMethod(yup_1.default.string, "media", function (type = "image") {
|
|
63
|
+
return this.test("media", "invalid media file", async function (value) {
|
|
64
|
+
const { path, createError } = this;
|
|
65
|
+
if (!value)
|
|
66
|
+
return true;
|
|
67
|
+
if (value == "$$REMOVE")
|
|
68
|
+
return true;
|
|
69
|
+
if (!(0, mongoose_1.isValidObjectId)(value))
|
|
70
|
+
return createError({ path, message: "file id is invalid" });
|
|
71
|
+
const mediaDoc = await media.findById(value);
|
|
72
|
+
if (mediaDoc.type !== type)
|
|
73
|
+
return createError({ path, message: `file type must be ${type}` });
|
|
74
|
+
return true;
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
yup_1.default.addMethod(yup_1.default.array, "media", function (typeSchema = { ...types }) {
|
|
78
|
+
let mediaSchema;
|
|
79
|
+
return this.transform((value) => {
|
|
80
|
+
return value?.map((item) => {
|
|
81
|
+
if (item._id)
|
|
82
|
+
return item._id.toObjectId();
|
|
83
|
+
return item;
|
|
84
|
+
});
|
|
85
|
+
}).test("media", "Invalid media files", async function (value) {
|
|
86
|
+
mediaSchema = lodash_1.default.cloneDeep(typeSchema);
|
|
87
|
+
const { path, createError } = this;
|
|
88
|
+
let mediaDocs = [];
|
|
89
|
+
let i = 1;
|
|
90
|
+
if (!value)
|
|
91
|
+
return true;
|
|
92
|
+
for (let mediaId of value) {
|
|
93
|
+
if (mediaId?._id)
|
|
94
|
+
mediaId = mediaId._id;
|
|
95
|
+
if (!(0, mongoose_1.isValidObjectId)(mediaId))
|
|
96
|
+
return createError({ path, message: `file ${i} id is invalid` });
|
|
97
|
+
const mediaDoc = await media.findById(mediaId);
|
|
98
|
+
if (!mediaDoc)
|
|
99
|
+
return createError({
|
|
100
|
+
path,
|
|
101
|
+
message: `file ${i} does'nt exist in database`,
|
|
102
|
+
});
|
|
103
|
+
if (!fs_1.default.existsSync(path_1.default.join(__dirname, configs.uploader.path, mediaDoc.dirPath, mediaDoc.name)) && mediaDoc.type != 'script')
|
|
104
|
+
return createError({
|
|
105
|
+
path,
|
|
106
|
+
message: `file ${i} does'nt exist in files`,
|
|
107
|
+
});
|
|
108
|
+
mediaDocs.push(mediaDoc);
|
|
109
|
+
i++;
|
|
110
|
+
}
|
|
111
|
+
i = 1;
|
|
112
|
+
let mediaType;
|
|
113
|
+
const mediaTypes = ["audio", "video", "script", "image"];
|
|
114
|
+
if (mediaSchema?.max < mediaDocs.length)
|
|
115
|
+
return createError({
|
|
116
|
+
path,
|
|
117
|
+
message: `media : ${mediaType} is more than maximum ${mediaSchema?.max}`,
|
|
118
|
+
});
|
|
119
|
+
if (mediaSchema?.min > mediaDocs.length)
|
|
120
|
+
return createError({
|
|
121
|
+
path,
|
|
122
|
+
message: `media : ${mediaType} is less than minimum ${mediaSchema?.min}`,
|
|
123
|
+
});
|
|
124
|
+
for (const mediaDoc of mediaDocs) {
|
|
125
|
+
mediaType = mediaTypes.find((mt) => mt == mediaDoc.type) || "file";
|
|
126
|
+
console.log("yup.config", 99, !mediaSchema[mediaType]);
|
|
127
|
+
if (!mediaSchema[mediaType])
|
|
128
|
+
return createError({ path, message: `file ${i} type forbidden` });
|
|
129
|
+
if (mediaSchema[mediaType].validFormat &&
|
|
130
|
+
!mediaSchema[mediaType].validFormat.test(mediaDoc.name.split(".").slice(-1)[0]))
|
|
131
|
+
return createError({ path, message: `file ${i} have invalid format` });
|
|
132
|
+
if (mediaSchema.typeOrder && mediaSchema.typeOrder[i] && !mediaDoc.type.match(mediaSchema.typeOrder[i]))
|
|
133
|
+
mediaSchema[mediaType].values = mediaSchema[mediaType].values
|
|
134
|
+
? [...mediaSchema[mediaType].values, mediaDoc]
|
|
135
|
+
: [mediaDoc];
|
|
136
|
+
i++;
|
|
137
|
+
}
|
|
138
|
+
let typeObj;
|
|
139
|
+
for (const typeField in mediaSchema) {
|
|
140
|
+
typeObj = mediaSchema[typeField];
|
|
141
|
+
if (typeObj.min && typeObj.min > (mediaDocs.filter(item => item.type == typeField).length || 0))
|
|
142
|
+
return createError({
|
|
143
|
+
path,
|
|
144
|
+
message: `media : ${typeField} is less than minimum ${typeObj.min}`,
|
|
145
|
+
});
|
|
146
|
+
if (typeObj.max && typeObj.max < (mediaDocs.filter(item => item.type == typeField).length || 0))
|
|
147
|
+
return createError({
|
|
148
|
+
path,
|
|
149
|
+
message: `media : ${typeField} is more than maximum ${typeObj.max}`,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
module.exports = yup_1.default;
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const fs_1 = __importDefault(require("fs"));
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const configs_default_1 = __importDefault(require("../configs.default"));
|
|
8
9
|
const find = (field, ...args) => {
|
|
9
10
|
const rel = path_1.default.join.apply(null, [].slice.call(args));
|
|
10
11
|
if (!require?.main?.filename)
|
|
@@ -33,8 +34,19 @@ const findStartingWith = (start, rel, field) => {
|
|
|
33
34
|
};
|
|
34
35
|
const configGetter = (configField) => {
|
|
35
36
|
const foundData = find(configField, "speedly.config");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
let configValue = {};
|
|
38
|
+
if (configs_default_1.default[configField] &&
|
|
39
|
+
Object.entries(configs_default_1.default[configField]).length) {
|
|
40
|
+
configValue = {
|
|
41
|
+
...configs_default_1.default[configField]
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
if (foundData) {
|
|
45
|
+
configValue = {
|
|
46
|
+
...configValue,
|
|
47
|
+
...foundData
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return configValue;
|
|
39
51
|
};
|
|
40
52
|
exports.default = configGetter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function importFromPwd(path: string): any;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
exports.default = importFromPwd;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
function importFromPwd(path) {
|
|
9
|
+
if (!require?.main?.filename)
|
|
10
|
+
return null;
|
|
11
|
+
const mainDir = path_1.default.dirname(require.main.filename);
|
|
12
|
+
const fullPath = path_1.default.join(mainDir, path);
|
|
13
|
+
try {
|
|
14
|
+
return require(fullPath);
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
18
|
+
throw new Error(`File ${fullPath} doesn't exist`);
|
|
19
|
+
}
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/dist/cjs/util/index.d.ts
CHANGED
package/dist/cjs/util/index.js
CHANGED
|
@@ -3,6 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.translator = void 0;
|
|
6
|
+
exports.makeOptional = exports.strToObj = exports.translator = void 0;
|
|
7
7
|
const translator_1 = __importDefault(require("./translator"));
|
|
8
8
|
exports.translator = translator_1.default;
|
|
9
|
+
const makeOptional_1 = __importDefault(require("./makeOptional"));
|
|
10
|
+
exports.makeOptional = makeOptional_1.default;
|
|
11
|
+
const strToObj_1 = __importDefault(require("./strToObj"));
|
|
12
|
+
exports.strToObj = strToObj_1.default;
|
|
@@ -7,7 +7,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
7
7
|
const translation_1 = __importDefault(require("./../model/translation"));
|
|
8
8
|
const TIMEOUT = 5000;
|
|
9
9
|
const getConfig_1 = __importDefault(require("./getConfig"));
|
|
10
|
-
const configs =
|
|
10
|
+
const configs = (0, getConfig_1.default)("translate");
|
|
11
11
|
async function firstSuccessful(promises) {
|
|
12
12
|
return new Promise((resolve, reject) => {
|
|
13
13
|
let rejections = 0;
|
|
@@ -48,7 +48,7 @@ exports.default = async (text = "unspecified text", lang = "fa") => {
|
|
|
48
48
|
}, {
|
|
49
49
|
timeout: TIMEOUT,
|
|
50
50
|
headers: {
|
|
51
|
-
"one-api-token":
|
|
51
|
+
"one-api-token": configs.one_api_token,
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
54
|
if (res.data.status === 200) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Request } from "express";
|
|
2
|
+
export interface DefaultConfig {
|
|
3
|
+
uploader: {
|
|
4
|
+
saveInDb: boolean;
|
|
5
|
+
prefix: string;
|
|
6
|
+
limit: number;
|
|
7
|
+
format: RegExp;
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
db: {
|
|
11
|
+
dbType: string;
|
|
12
|
+
path: string;
|
|
13
|
+
type: 'internal' | 'external';
|
|
14
|
+
dbEnv: string;
|
|
15
|
+
first: boolean;
|
|
16
|
+
response: boolean;
|
|
17
|
+
pagination: {
|
|
18
|
+
quantity?: number;
|
|
19
|
+
detailed?: boolean;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
} | false;
|
|
22
|
+
};
|
|
23
|
+
auth: {
|
|
24
|
+
admin: {
|
|
25
|
+
role: string;
|
|
26
|
+
model: string;
|
|
27
|
+
};
|
|
28
|
+
jwtSecretEnv: string;
|
|
29
|
+
customValidator: (req: Request, key: string) => (boolean | null) | Promise<boolean | null> | null;
|
|
30
|
+
};
|
|
31
|
+
translate: {
|
|
32
|
+
one_api_token: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
declare const defaultConfigs: DefaultConfig;
|
|
36
|
+
export default defaultConfigs;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const defaultConfigs = {
|
|
4
|
+
uploader: {
|
|
5
|
+
saveInDb: false,
|
|
6
|
+
prefix: "",
|
|
7
|
+
limit: 5,
|
|
8
|
+
format: /png|jpg|webp|jpeg/i,
|
|
9
|
+
path: "../../../public",
|
|
10
|
+
},
|
|
11
|
+
db: {
|
|
12
|
+
dbType: "mongodb",
|
|
13
|
+
path: "../model",
|
|
14
|
+
type: "external",
|
|
15
|
+
dbEnv: "DB_URL",
|
|
16
|
+
first: false,
|
|
17
|
+
response: true,
|
|
18
|
+
pagination: {
|
|
19
|
+
detailed: true,
|
|
20
|
+
quantity: 20
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
auth: {
|
|
24
|
+
admin: { role: "ADMIN", model: "../models/admin" },
|
|
25
|
+
jwtSecretEnv: "JWT_KEY",
|
|
26
|
+
customValidator: (req, key) => {
|
|
27
|
+
return true;
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
translate: { one_api_token: "" }
|
|
31
|
+
};
|
|
32
|
+
exports.default = defaultConfigs;
|
|
@@ -4,14 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
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
|
-
};
|
|
7
|
+
const gConfig = (0, getConfig_1.default)("auth");
|
|
15
8
|
const executer = (authType) => {
|
|
16
9
|
const mw = async (req, res, next) => {
|
|
17
10
|
const accessResult = await gConfig?.customValidator?.(req, authType);
|
package/dist/esm/kit/db/db.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
import { DefaultConfig } from "../../configs.default";
|
|
2
3
|
declare module "express-serve-static-core" {
|
|
3
4
|
interface Request {
|
|
4
5
|
document?: any;
|
|
@@ -9,21 +10,7 @@ declare module "express-serve-static-core" {
|
|
|
9
10
|
success?: (statusCode: number, body: any) => void;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
dbType?: string;
|
|
14
|
-
path?: string;
|
|
15
|
-
dbEnv?: string;
|
|
16
|
-
response?: boolean;
|
|
17
|
-
first?: boolean;
|
|
18
|
-
type: "internal" | "external";
|
|
19
|
-
pagination?: {
|
|
20
|
-
quantity?: number;
|
|
21
|
-
detailed?: boolean;
|
|
22
|
-
[key: string]: unknown;
|
|
23
|
-
};
|
|
24
|
-
[key: string]: unknown;
|
|
25
|
-
};
|
|
26
|
-
declare const db: (collectionName: string, config?: ConfigsType) => {
|
|
13
|
+
declare const db: (collectionName: string, config?: Partial<DefaultConfig["db"]>) => {
|
|
27
14
|
find: (match?: {}) => {
|
|
28
15
|
(req: Request, res: Response, next: NextFunction): Promise<void>;
|
|
29
16
|
select(value: string | {
|