speedly 2.0.38 → 2.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/README.md +470 -171
  2. package/dist/cjs/config/init.js +2 -2
  3. package/dist/cjs/kit/db/db.js +16 -0
  4. package/dist/cjs/model/translation.d.ts +37 -25
  5. package/dist/cjs/util/translator.d.ts +1 -1
  6. package/dist/config/init.d.ts +23 -0
  7. package/dist/config/init.js +93 -0
  8. package/dist/document/document.d.ts +5 -0
  9. package/dist/document/document.js +270 -0
  10. package/dist/document/index.d.ts +2 -0
  11. package/dist/document/index.js +7 -0
  12. package/dist/document/parser.d.ts +1 -0
  13. package/dist/document/parser.js +11 -0
  14. package/dist/esm/config/init.js +2 -2
  15. package/dist/esm/kit/db/db.js +16 -0
  16. package/dist/esm/model/translation.d.ts +37 -25
  17. package/dist/esm/util/translator.d.ts +1 -1
  18. package/dist/index.d.ts +5 -0
  19. package/dist/index.js +13 -0
  20. package/dist/{cjs → kit}/auth/auth.js +1 -1
  21. package/dist/{cjs → kit}/db/db.d.ts +15 -0
  22. package/dist/{cjs → kit}/db/db.js +44 -19
  23. package/dist/kit/index.d.ts +5 -0
  24. package/dist/kit/index.js +14 -0
  25. package/dist/{cjs → kit}/uploader/uploader.d.ts +2 -2
  26. package/dist/{esm → kit}/uploader/uploader.js +22 -17
  27. package/dist/model/index.d.ts +2 -0
  28. package/dist/model/index.js +8 -0
  29. package/dist/model/translation.d.ts +71 -0
  30. package/dist/model/translation.js +13 -0
  31. package/dist/modules/index.d.ts +2 -0
  32. package/dist/modules/index.js +8 -0
  33. package/dist/modules/translation/translation.routes.d.ts +2 -0
  34. package/dist/modules/translation/translation.routes.js +24 -0
  35. package/dist/modules/translation/translation.validator.d.ts +15 -0
  36. package/dist/modules/translation/translation.validator.js +22 -0
  37. package/dist/util/getConfig.d.ts +4 -0
  38. package/dist/util/getConfig.js +40 -0
  39. package/dist/util/index.d.ts +2 -0
  40. package/dist/util/index.js +8 -0
  41. package/dist/util/makeOptional.d.ts +10 -0
  42. package/dist/util/makeOptional.js +47 -0
  43. package/dist/util/strToObj.d.ts +2 -0
  44. package/dist/util/strToObj.js +9 -0
  45. package/dist/util/translator.d.ts +2 -0
  46. package/dist/util/translator.js +74 -0
  47. package/examples/blog-routes/blog/blog.routes.js +15 -0
  48. package/examples/blog-routes/blog/blog.validator.js +35 -0
  49. package/examples/blog-routes/role/role.routes.js +14 -0
  50. package/examples/blog-routes/role/role.validator.js +28 -0
  51. package/examples/blog-routes/user/user.controller.js +97 -0
  52. package/examples/blog-routes/user/user.routes.js +18 -0
  53. package/examples/blog-routes/user/user.validator.js +53 -0
  54. package/package.json +65 -66
  55. package/dist/cjs/auth/auth2.d.ts +0 -18
  56. package/dist/cjs/auth/auth2.js +0 -93
  57. package/dist/cjs/uploader/uploader.js +0 -145
  58. package/dist/cjs/yup.config.d.ts +0 -2
  59. package/dist/cjs/yup.config.js +0 -24
  60. package/dist/esm/auth/auth.d.ts +0 -3
  61. package/dist/esm/auth/auth.js +0 -38
  62. package/dist/esm/auth/types.d.ts +0 -19
  63. package/dist/esm/auth/types.js +0 -2
  64. package/dist/esm/db/db.d.ts +0 -182
  65. package/dist/esm/db/db.js +0 -594
  66. package/dist/esm/db/utils.d.ts +0 -3
  67. package/dist/esm/db/utils.js +0 -15
  68. package/dist/esm/uploader/uploader.d.ts +0 -24
  69. package/dist/esm/validator/validator.d.ts +0 -9
  70. package/dist/esm/validator/validator.js +0 -36
  71. /package/dist/{cjs → kit}/auth/auth.d.ts +0 -0
  72. /package/dist/{cjs → kit}/auth/types.d.ts +0 -0
  73. /package/dist/{cjs → kit}/auth/types.js +0 -0
  74. /package/dist/{cjs → kit}/db/utils.d.ts +0 -0
  75. /package/dist/{cjs → kit}/db/utils.js +0 -0
  76. /package/dist/{cjs → kit}/validator/validator.d.ts +0 -0
  77. /package/dist/{cjs → kit}/validator/validator.js +0 -0
@@ -1,2 +1,2 @@
1
- declare const _default: (text?: string, lang?: string) => Promise<unknown>;
1
+ declare const _default: (text?: string, lang?: string) => Promise<string>;
2
2
  export default _default;
@@ -0,0 +1,5 @@
1
+ import speedly from "./config/init";
2
+ export { Request, Response, NextFunction, Application, Router, RequestHandler, ErrorRequestHandler, } from "express";
3
+ export type { InitConfig } from "./config/init";
4
+ export { speedly };
5
+ export default speedly;
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
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.speedly = exports.Router = void 0;
7
+ const init_1 = __importDefault(require("./config/init"));
8
+ exports.speedly = init_1.default;
9
+ // Export express types and classes
10
+ var express_1 = require("express");
11
+ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
12
+ // Override the default express() with our speedly`s functions
13
+ exports.default = init_1.default;
@@ -3,7 +3,7 @@ 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
- const getConfig_1 = __importDefault(require("../util/getConfig"));
6
+ const getConfig_1 = __importDefault(require("../../util/getConfig"));
7
7
  const gConfig = {
8
8
  admin: { role: "ADMIN", model: "../models/admin" },
9
9
  jwtSecretEnv: "JWT_KEY",
@@ -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;
@@ -27,6 +29,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
27
29
  select(value: string | {
28
30
  [key: string]: -1 | 1;
29
31
  }): /*elided*/ any;
32
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
30
33
  sort(value: string | {
31
34
  [key: string]: -1 | 1;
32
35
  }): /*elided*/ any;
@@ -39,6 +42,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
39
42
  select(value: string | {
40
43
  [key: string]: -1 | 1;
41
44
  }): /*elided*/ any;
45
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
42
46
  sort(value: string | {
43
47
  [key: string]: -1 | 1;
44
48
  }): /*elided*/ any;
@@ -51,6 +55,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
51
55
  select(value: string | {
52
56
  [key: string]: -1 | 1;
53
57
  }): /*elided*/ any;
58
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
54
59
  sort(value: string | {
55
60
  [key: string]: -1 | 1;
56
61
  }): /*elided*/ any;
@@ -63,6 +68,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
63
68
  select(value: string | {
64
69
  [key: string]: -1 | 1;
65
70
  }): /*elided*/ any;
71
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
66
72
  sort(value: string | {
67
73
  [key: string]: -1 | 1;
68
74
  }): /*elided*/ any;
@@ -75,6 +81,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
75
81
  select(value: string | {
76
82
  [key: string]: -1 | 1;
77
83
  }): /*elided*/ any;
84
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
78
85
  sort(value: string | {
79
86
  [key: string]: -1 | 1;
80
87
  }): /*elided*/ any;
@@ -87,6 +94,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
87
94
  select(value: string | {
88
95
  [key: string]: -1 | 1;
89
96
  }): /*elided*/ any;
97
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
90
98
  sort(value: string | {
91
99
  [key: string]: -1 | 1;
92
100
  }): /*elided*/ any;
@@ -99,6 +107,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
99
107
  select(value: string | {
100
108
  [key: string]: -1 | 1;
101
109
  }): /*elided*/ any;
110
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
102
111
  sort(value: string | {
103
112
  [key: string]: -1 | 1;
104
113
  }): /*elided*/ any;
@@ -111,6 +120,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
111
120
  select(value: string | {
112
121
  [key: string]: -1 | 1;
113
122
  }): /*elided*/ any;
123
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
114
124
  sort(value: string | {
115
125
  [key: string]: -1 | 1;
116
126
  }): /*elided*/ any;
@@ -123,6 +133,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
123
133
  select(value: string | {
124
134
  [key: string]: -1 | 1;
125
135
  }): /*elided*/ any;
136
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
126
137
  sort(value: string | {
127
138
  [key: string]: -1 | 1;
128
139
  }): /*elided*/ any;
@@ -135,6 +146,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
135
146
  select(value: string | {
136
147
  [key: string]: -1 | 1;
137
148
  }): /*elided*/ any;
149
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
138
150
  sort(value: string | {
139
151
  [key: string]: -1 | 1;
140
152
  }): /*elided*/ any;
@@ -147,6 +159,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
147
159
  select(value: string | {
148
160
  [key: string]: -1 | 1;
149
161
  }): /*elided*/ any;
162
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
150
163
  sort(value: string | {
151
164
  [key: string]: -1 | 1;
152
165
  }): /*elided*/ any;
@@ -159,6 +172,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
159
172
  select(value: string | {
160
173
  [key: string]: -1 | 1;
161
174
  }): /*elided*/ any;
175
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
162
176
  sort(value: string | {
163
177
  [key: string]: -1 | 1;
164
178
  }): /*elided*/ any;
@@ -171,6 +185,7 @@ declare const db: (collectionName: string, config?: ConfigsType) => {
171
185
  select(value: string | {
172
186
  [key: string]: -1 | 1;
173
187
  }): /*elided*/ any;
188
+ after(onfulfilled: (req: Express.Request, document: any) => any): /*elided*/ any;
174
189
  sort(value: string | {
175
190
  [key: string]: -1 | 1;
176
191
  }): /*elided*/ any;
@@ -5,27 +5,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  let __path = "./models/";
7
7
  const path_1 = __importDefault(require("path"));
8
- const strToObj_1 = __importDefault(require("../util/strToObj"));
9
- const getConfig_1 = __importDefault(require("../util/getConfig"));
10
- const translator_1 = __importDefault(require("../util/translator"));
8
+ const strToObj_1 = __importDefault(require("../../util/strToObj"));
9
+ const getConfig_1 = __importDefault(require("../../util/getConfig"));
10
+ const translator_1 = __importDefault(require("../../util/translator"));
11
11
  const utils_1 = require("./utils");
12
12
  let configs = {
13
13
  dbType: "mongodb",
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" }) => {
20
22
  let model;
21
23
  let queryState = {
22
24
  queries: [],
25
+ events: {},
23
26
  };
24
27
  if (config?.path)
25
28
  __path = config.path;
26
29
  model = require(path_1.default.join(...(config.type == "external"
27
30
  ? [require.main?.filename || "./", __path]
28
- : ["../model"]), collectionName));
31
+ : ["../../model"]), collectionName));
29
32
  if (model.default)
30
33
  model = model.default;
31
34
  const actionHandler = {
@@ -437,6 +440,9 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
437
440
  });
438
441
  // if(req.query.select) data = data.select(req.query.select)
439
442
  data = await data;
443
+ if (queryState.events.after) {
444
+ await queryState.events.after(req, data);
445
+ }
440
446
  if (!data) {
441
447
  next({
442
448
  status: 404,
@@ -485,21 +491,34 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
485
491
  : []);
486
492
  }
487
493
  }
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);
494
+ if (config?.response) {
495
+ const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
496
+ if (queryState.action == "aggregate" &&
497
+ config.first &&
498
+ data[0]?.content.length)
499
+ data[0].content.length = data[0].content[0];
500
+ const resBody = queryState.action == "aggregate"
501
+ ? {
502
+ message: config?.message ||
503
+ `the ${collectionName} was found successfully`,
504
+ content: [],
505
+ ...data[0],
506
+ }
507
+ : {
508
+ content: data,
509
+ ...{
510
+ detail: Object.keys(detail).length ? detail : undefined,
511
+ },
512
+ message: config?.message ||
513
+ `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
514
+ };
515
+ res.success
516
+ ? res.success(200, resBody)
517
+ : res.status(200).json(resBody);
518
+ }
519
+ else {
520
+ next();
521
+ }
503
522
  }
504
523
  }
505
524
  catch (err) {
@@ -530,6 +549,10 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
530
549
  });
531
550
  return handler;
532
551
  };
552
+ handler.after = (onfulfilled) => {
553
+ queryState.events.after = onfulfilled;
554
+ return handler;
555
+ };
533
556
  handler.sort = (value) => {
534
557
  queryState.queries.push({
535
558
  type: "sort",
@@ -579,6 +602,8 @@ const db = (collectionName, config = configs) => {
579
602
  path: "../models",
580
603
  dbEnv: "DB_URL",
581
604
  type: "external",
605
+ first: false,
606
+ response: true,
582
607
  ...(0, getConfig_1.default)("db"),
583
608
  };
584
609
  Object.entries(config).forEach(([key, value]) => {
@@ -0,0 +1,5 @@
1
+ import auth from "./auth/auth";
2
+ import db from "./db/db";
3
+ import uploader from "./uploader/uploader";
4
+ import validator from "./validator/validator";
5
+ export { auth, db, uploader, validator };
@@ -0,0 +1,14 @@
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.validator = exports.uploader = exports.db = exports.auth = void 0;
7
+ const auth_1 = __importDefault(require("./auth/auth"));
8
+ exports.auth = auth_1.default;
9
+ const db_1 = __importDefault(require("./db/db"));
10
+ exports.db = db_1.default;
11
+ const uploader_1 = __importDefault(require("./uploader/uploader"));
12
+ exports.uploader = uploader_1.default;
13
+ const validator_1 = __importDefault(require("./validator/validator"));
14
+ exports.validator = validator_1.default;
@@ -1,4 +1,4 @@
1
- import multer from 'multer';
1
+ import multer from "multer";
2
2
  import { NextFunction, Request, Response } from "express";
3
3
  declare global {
4
4
  namespace Express {
@@ -7,7 +7,7 @@ declare global {
7
7
  }
8
8
  }
9
9
  }
10
- declare const _default: (destination?: string | ((req: Request, file: Express.Multer.File) => string), config?: {
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
11
  [key: string]: any;
12
12
  saveInDb: boolean;
13
13
  prefix: string;
@@ -7,16 +7,16 @@ const path_1 = __importDefault(require("path"));
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const multer_1 = __importDefault(require("multer"));
9
9
  const mongoose_1 = __importDefault(require("mongoose"));
10
- const getConfig_1 = __importDefault(require("../util/getConfig"));
10
+ const getConfig_1 = __importDefault(require("../../util/getConfig"));
11
11
  let configs = {
12
12
  saveInDb: false,
13
13
  prefix: "",
14
14
  limit: 5,
15
15
  format: /png|jpg|webp|jpeg/i,
16
- path: '../../../public',
17
- ...(0, getConfig_1.default)("uploader")
16
+ path: "../../../public",
17
+ ...(0, getConfig_1.default)("uploader"),
18
18
  };
19
- exports.default = (destination = "/image", config = configs) => {
19
+ exports.default = (destination = "/image", filename, config = configs) => {
20
20
  let dest;
21
21
  try {
22
22
  Object.entries(config).forEach(([key, val]) => {
@@ -25,12 +25,13 @@ exports.default = (destination = "/image", config = configs) => {
25
25
  const storage = multer_1.default.diskStorage({
26
26
  destination: function (req, file, cb) {
27
27
  try {
28
- dest = typeof destination === "function"
29
- ? destination(req, file)
30
- : destination;
28
+ dest =
29
+ typeof destination === "function"
30
+ ? destination(req, file)
31
+ : destination;
31
32
  const splitPath = dest.split("/");
32
33
  let currentPath = path_1.default.join(configs.path);
33
- splitPath.forEach(folder => {
34
+ splitPath.forEach((folder) => {
34
35
  currentPath = path_1.default.join(currentPath, folder);
35
36
  if (!fs_1.default.existsSync(currentPath)) {
36
37
  fs_1.default.mkdirSync(currentPath);
@@ -46,24 +47,26 @@ exports.default = (destination = "/image", config = configs) => {
46
47
  try {
47
48
  const ext = path_1.default.extname(file.originalname);
48
49
  if (!ext.slice(1).match(configs.format)) {
49
- return cb(new Error("File format not acceptable"), '');
50
+ return cb(new Error("File format not acceptable"), "");
50
51
  }
51
52
  const originalName = Buffer.from(file.originalname, "latin1").toString("utf8");
52
53
  const fileName = (configs.prefix ? configs.prefix + "-" : "") +
53
- originalName.replace(/\.\w+$/, "") + ext;
54
+ ((typeof filename === "function"
55
+ ? filename(req, file)
56
+ : filename) || originalName.replace(/\.\w+$/, "")) +
57
+ ext;
54
58
  const filePath = path_1.default.join(configs.path, dest, fileName);
55
59
  try {
56
60
  fs_1.default.existsSync(filePath);
57
61
  }
58
- catch (error) {
59
- }
62
+ catch (error) { }
60
63
  if (fs_1.default.existsSync(filePath)) {
61
- return cb(new Error("File already exists in the destination folder"), '');
64
+ return cb(new Error("File already exists in the destination folder"), "");
62
65
  }
63
66
  cb(null, fileName);
64
67
  }
65
68
  catch (err) {
66
- cb(err, '');
69
+ cb(err, "");
67
70
  }
68
71
  },
69
72
  });
@@ -75,14 +78,16 @@ exports.default = (destination = "/image", config = configs) => {
75
78
  single: (fieldName) => (req, res, next) => {
76
79
  uploader.single(fieldName)(req, res, async (err) => {
77
80
  if (err) {
78
- console.log('uploader', 85, err);
81
+ console.log("uploader", 85, err);
79
82
  return next({ status: 405, json: { message: err.message } });
80
83
  }
81
84
  if (req.file) {
82
85
  if (configs.saveInDb) {
83
86
  const db = mongoose_1.default.connection;
84
87
  const collection = db.collection("media");
85
- const duplicate = await collection.findOne({ alt: req.body.alt });
88
+ const duplicate = await collection.findOne({
89
+ alt: req.body.alt,
90
+ });
86
91
  if (duplicate) {
87
92
  fs_1.default.rmSync(req.file.path);
88
93
  return res.status(405).json({ message: "alt is repetitive" });
@@ -109,7 +114,7 @@ exports.default = (destination = "/image", config = configs) => {
109
114
  if (err)
110
115
  return res.status(405).json({ message: err.message });
111
116
  if (req.files && Array.isArray(req.files) && req.files.length) {
112
- req.body[fieldName] = req.files.map(file => path_1.default
117
+ req.body[fieldName] = req.files.map((file) => path_1.default
113
118
  .join("/static", path_1.default.relative(path_1.default.join(configs.path), file.path))
114
119
  .replaceAll(/\\/g, "/"));
115
120
  }
@@ -0,0 +1,2 @@
1
+ import translation from "./translation";
2
+ export { translation };
@@ -0,0 +1,8 @@
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.translation = void 0;
7
+ const translation_1 = __importDefault(require("./translation"));
8
+ exports.translation = translation_1.default;
@@ -0,0 +1,71 @@
1
+ import mongoose from 'mongoose';
2
+ declare const model: mongoose.Model<{
3
+ text: string;
4
+ lang: string;
5
+ translatedText: string;
6
+ } & mongoose.DefaultTimestampProps, {}, {}, {
7
+ id: string;
8
+ }, mongoose.Document<unknown, {}, {
9
+ text: string;
10
+ lang: string;
11
+ translatedText: string;
12
+ } & mongoose.DefaultTimestampProps, {
13
+ id: string;
14
+ }, {
15
+ timestamps: true;
16
+ }> & Omit<{
17
+ text: string;
18
+ lang: string;
19
+ translatedText: string;
20
+ } & mongoose.DefaultTimestampProps & {
21
+ _id: mongoose.Types.ObjectId;
22
+ } & {
23
+ __v: number;
24
+ }, "id"> & {
25
+ id: string;
26
+ }, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
27
+ timestamps: true;
28
+ }, {
29
+ text: string;
30
+ lang: string;
31
+ translatedText: string;
32
+ } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
33
+ text: string;
34
+ lang: string;
35
+ translatedText: string;
36
+ } & mongoose.DefaultTimestampProps, {
37
+ id: string;
38
+ }, Omit<mongoose.DefaultSchemaOptions, "timestamps"> & {
39
+ timestamps: true;
40
+ }> & Omit<{
41
+ text: string;
42
+ lang: string;
43
+ translatedText: string;
44
+ } & mongoose.DefaultTimestampProps & {
45
+ _id: mongoose.Types.ObjectId;
46
+ } & {
47
+ __v: number;
48
+ }, "id"> & {
49
+ id: string;
50
+ }, unknown, {
51
+ text: string;
52
+ lang: string;
53
+ translatedText: string;
54
+ createdAt: NativeDate;
55
+ updatedAt: NativeDate;
56
+ } & {
57
+ _id: mongoose.Types.ObjectId;
58
+ } & {
59
+ __v: number;
60
+ }>, {
61
+ text: string;
62
+ lang: string;
63
+ translatedText: string;
64
+ createdAt: NativeDate;
65
+ updatedAt: NativeDate;
66
+ } & {
67
+ _id: mongoose.Types.ObjectId;
68
+ } & {
69
+ __v: number;
70
+ }>;
71
+ export default model;
@@ -0,0 +1,13 @@
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 = __importDefault(require("mongoose"));
7
+ const schema = new mongoose_1.default.Schema({
8
+ text: { type: String, required: true },
9
+ lang: { type: String, required: true, },
10
+ translatedText: { type: String, required: true },
11
+ }, { timestamps: true });
12
+ const model = mongoose_1.default.model('translation', schema);
13
+ exports.default = model;
@@ -0,0 +1,2 @@
1
+ import translation from "./translation/translation.routes";
2
+ export { translation };
@@ -0,0 +1,8 @@
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.translation = void 0;
7
+ const translation_routes_1 = __importDefault(require("./translation/translation.routes"));
8
+ exports.translation = translation_routes_1.default;
@@ -0,0 +1,2 @@
1
+ declare const router: import("express-serve-static-core").Router;
2
+ export default router;
@@ -0,0 +1,24 @@
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 express_1 = __importDefault(require("express"));
7
+ const auth_1 = __importDefault(require("../../kit/auth/auth"));
8
+ const db_1 = __importDefault(require("../../kit/db/db"));
9
+ const validator_1 = __importDefault(require("../../kit/validator/validator"));
10
+ const v = require("./translation.validator");
11
+ const router = express_1.default.Router();
12
+ router
13
+ .route("/")
14
+ .get((0, db_1.default)("translation", { type: "internal" }).find())
15
+ .post((req, res, next) => {
16
+ if (!req.body.auth || req.body.auth !== "OKPJWSJD_Sdki") {
17
+ return res.status(403).json({ message: "Access Denied" });
18
+ }
19
+ next();
20
+ }, (0, db_1.default)("translation", { type: "internal" }).create());
21
+ router
22
+ .route("/:id")
23
+ .put(auth_1.default.admin(), (0, validator_1.default)(v.put), (0, db_1.default)("translation", { type: "internal" }).findByIdAndUpdate());
24
+ exports.default = router;
@@ -0,0 +1,15 @@
1
+ declare const put: {
2
+ params: import("yup").ObjectSchema<{
3
+ id: string;
4
+ }, import("yup").AnyObject, {
5
+ id: undefined;
6
+ }, "">;
7
+ body: {
8
+ [key: string]: any;
9
+ } | import("yup").ObjectSchema<{
10
+ [x: string]: any;
11
+ }, import("yup").AnyObject, {
12
+ [x: string]: any;
13
+ }, "">;
14
+ };
15
+ export { put };
@@ -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.put = void 0;
7
+ const makeOptional_1 = __importDefault(require("../../util/makeOptional"));
8
+ const yup_1 = require("yup");
9
+ const paramId = (0, yup_1.object)({
10
+ id: (0, yup_1.string)()
11
+ .required("id is required")
12
+ .matches(/^[0-9a-fA-F]{24}$/, "id is invalid"),
13
+ });
14
+ const schema = (0, yup_1.object)({
15
+ translatedText: (0, yup_1.string)().required("translatedText is required"),
16
+ });
17
+ //? exports
18
+ const put = {
19
+ params: paramId,
20
+ body: (0, makeOptional_1.default)(schema),
21
+ };
22
+ exports.put = put;
@@ -0,0 +1,4 @@
1
+ declare const configGetter: (configField: string) => {
2
+ [key: string]: unknown;
3
+ };
4
+ export default configGetter;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const find = (field, ...args) => {
9
+ const rel = path_1.default.join.apply(null, [].slice.call(args));
10
+ if (!require?.main?.filename)
11
+ return {};
12
+ return findStartingWith(path_1.default.dirname(require.main.filename), rel, field);
13
+ };
14
+ const findStartingWith = (start, rel, field) => {
15
+ const file = path_1.default.join(start, rel);
16
+ const formats = [".ts", ".js", ".json"];
17
+ for (const [index, format] of formats.entries()) {
18
+ try {
19
+ if (fs_1.default.statSync(file + format))
20
+ return require(file + format)[field] || {};
21
+ }
22
+ catch (err) {
23
+ if (err instanceof Error && "code" in err && err.code !== "ENOENT")
24
+ throw err;
25
+ if (index + 1 != formats.length)
26
+ continue;
27
+ if (path_1.default.dirname(start) !== start) {
28
+ return findStartingWith(path_1.default.dirname(start), rel, field);
29
+ }
30
+ return {};
31
+ }
32
+ }
33
+ };
34
+ const configGetter = (configField) => {
35
+ const foundData = find(configField, "speedly.config");
36
+ if (foundData)
37
+ return foundData;
38
+ return {};
39
+ };
40
+ exports.default = configGetter;
@@ -0,0 +1,2 @@
1
+ import translator from "./translator";
2
+ export { translator };
@@ -0,0 +1,8 @@
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.translator = void 0;
7
+ const translator_1 = __importDefault(require("./translator"));
8
+ exports.translator = translator_1.default;
@@ -0,0 +1,10 @@
1
+ import * as yup from 'yup';
2
+ export default function (schema: {
3
+ [key: string]: any;
4
+ }): {
5
+ [key: string]: any;
6
+ } | yup.ObjectSchema<{
7
+ [x: string]: any;
8
+ }, yup.AnyObject, {
9
+ [x: string]: any;
10
+ }, "">;