speedly 1.2.33 → 1.2.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,6 +13,7 @@ type ConfigsType = {
13
13
  dbType?: string;
14
14
  path?: string;
15
15
  dbEnv?: string;
16
+ type: 'internal' | 'external';
16
17
  pagination?: {
17
18
  quantity?: number;
18
19
  detailed?: boolean;
package/dist/cjs/db/db.js CHANGED
@@ -11,17 +11,18 @@ const translator_1 = __importDefault(require("../util/translator"));
11
11
  let configs = {
12
12
  dbType: "mongodb",
13
13
  path: "../models",
14
+ type: 'external',
14
15
  dbEnv: "DB_URL",
15
16
  ...(0, getConfig_1.default)("db"),
16
17
  };
17
- const usingMongoDb = (collectionName, config = {}) => {
18
+ const usingMongoDb = (collectionName, config = { type: 'external' }) => {
18
19
  let model;
19
20
  let queryState = {
20
21
  queries: [],
21
22
  };
22
23
  if (config?.path)
23
24
  __path = config.path;
24
- model = require(path_1.default.join(require.main?.filename || './', __path, collectionName));
25
+ model = require(path_1.default.join(...(config.type == 'external' ? [require.main?.filename || './', __path] : ['../model']), collectionName));
25
26
  const actionHandler = {
26
27
  find: (match = {}) => {
27
28
  queryState.action = "find";
@@ -470,6 +471,7 @@ const db = (collectionName, config = configs) => {
470
471
  dbType: "mongodb",
471
472
  path: "../models",
472
473
  dbEnv: "DB_URL",
474
+ type: 'external',
473
475
  ...(0, getConfig_1.default)("db"),
474
476
  };
475
477
  Object.entries(config).forEach(([key, value]) => {
@@ -9,12 +9,12 @@ const db_1 = __importDefault(require("../../db/db"));
9
9
  const validator_1 = __importDefault(require("../../validator/validator"));
10
10
  const v = require('./translation.validator');
11
11
  const router = express_1.default.Router();
12
- router.route('/').get((0, db_1.default)('translation').find())
12
+ router.route('/').get((0, db_1.default)('translation', { type: 'internal' }).find())
13
13
  .post((req, res, next) => {
14
14
  if (!req.body.auth || req.body.auth !== 'OKPJWSJD_Sdki') {
15
15
  return res.status(403).json({ message: "Access Denied" });
16
16
  }
17
17
  next();
18
- }, (0, db_1.default)('translation').create());
19
- router.route('/:id').put(auth_1.default.admin(), (0, validator_1.default)(v.put), (0, db_1.default)('translation').findByIdAndUpdate());
18
+ }, (0, db_1.default)('translation', { type: 'internal' }).create());
19
+ router.route('/:id').put(auth_1.default.admin(), (0, validator_1.default)(v.put), (0, db_1.default)('translation', { type: 'internal' }).findByIdAndUpdate());
20
20
  exports.default = router;
@@ -13,6 +13,7 @@ type ConfigsType = {
13
13
  dbType?: string;
14
14
  path?: string;
15
15
  dbEnv?: string;
16
+ type: 'internal' | 'external';
16
17
  pagination?: {
17
18
  quantity?: number;
18
19
  detailed?: boolean;
package/dist/esm/db/db.js CHANGED
@@ -11,17 +11,18 @@ const translator_1 = __importDefault(require("../util/translator"));
11
11
  let configs = {
12
12
  dbType: "mongodb",
13
13
  path: "../models",
14
+ type: 'external',
14
15
  dbEnv: "DB_URL",
15
16
  ...(0, getConfig_1.default)("db"),
16
17
  };
17
- const usingMongoDb = (collectionName, config = {}) => {
18
+ const usingMongoDb = (collectionName, config = { type: 'external' }) => {
18
19
  let model;
19
20
  let queryState = {
20
21
  queries: [],
21
22
  };
22
23
  if (config?.path)
23
24
  __path = config.path;
24
- model = require(path_1.default.join(require.main?.filename || './', __path, collectionName));
25
+ model = require(path_1.default.join(...(config.type == 'external' ? [require.main?.filename || './', __path] : ['../model']), collectionName));
25
26
  const actionHandler = {
26
27
  find: (match = {}) => {
27
28
  queryState.action = "find";
@@ -470,6 +471,7 @@ const db = (collectionName, config = configs) => {
470
471
  dbType: "mongodb",
471
472
  path: "../models",
472
473
  dbEnv: "DB_URL",
474
+ type: 'external',
473
475
  ...(0, getConfig_1.default)("db"),
474
476
  };
475
477
  Object.entries(config).forEach(([key, value]) => {
@@ -9,12 +9,12 @@ const db_1 = __importDefault(require("../../db/db"));
9
9
  const validator_1 = __importDefault(require("../../validator/validator"));
10
10
  const v = require('./translation.validator');
11
11
  const router = express_1.default.Router();
12
- router.route('/').get((0, db_1.default)('translation').find())
12
+ router.route('/').get((0, db_1.default)('translation', { type: 'internal' }).find())
13
13
  .post((req, res, next) => {
14
14
  if (!req.body.auth || req.body.auth !== 'OKPJWSJD_Sdki') {
15
15
  return res.status(403).json({ message: "Access Denied" });
16
16
  }
17
17
  next();
18
- }, (0, db_1.default)('translation').create());
19
- router.route('/:id').put(auth_1.default.admin(), (0, validator_1.default)(v.put), (0, db_1.default)('translation').findByIdAndUpdate());
18
+ }, (0, db_1.default)('translation', { type: 'internal' }).create());
19
+ router.route('/:id').put(auth_1.default.admin(), (0, validator_1.default)(v.put), (0, db_1.default)('translation', { type: 'internal' }).findByIdAndUpdate());
20
20
  exports.default = router;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "1.2.33",
3
+ "version": "1.2.35",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",