speedly 1.2.43 → 1.2.45

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.js CHANGED
@@ -8,6 +8,7 @@ const path_1 = __importDefault(require("path"));
8
8
  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
+ const utils_1 = require("./utils");
11
12
  let configs = {
12
13
  dbType: "mongodb",
13
14
  path: "../models",
@@ -349,14 +350,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
349
350
  break;
350
351
  case "findOneAndUpdate":
351
352
  req.document = await model.findOne(match);
352
- data = model?.[queryState.action]?.call(model, match, {
353
- $set: {
354
- ...req.body,
355
- ...(typeof queryState.body == "function"
356
- ? queryState.body(req)
357
- : queryState.body),
358
- },
359
- }, { new: true });
353
+ data = model?.[queryState.action]?.call(model, match, (0, utils_1.createUpdateObject)(req, queryState.body || {}), { new: true });
360
354
  break;
361
355
  case "findOneAndDelete":
362
356
  data = model?.[queryState.action]?.call(model, match);
@@ -0,0 +1,3 @@
1
+ import { Request } from "express";
2
+ declare const createUpdateObject: (req: Request, additionalFields: Record<string, any> | ((req: Request) => Record<string, any>)) => Record<string, any>;
3
+ export { createUpdateObject };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUpdateObject = void 0;
4
+ const createUpdateObject = (req, additionalFields) => {
5
+ let updateObject = { $set: { ...req.body } };
6
+ const additionalObject = typeof additionalFields === "function"
7
+ ? additionalFields(req)
8
+ : additionalFields;
9
+ if (Object.keys(additionalObject).find((key) => key.startsWith("$")))
10
+ updateObject = { ...updateObject, ...additionalObject };
11
+ else
12
+ updateObject.$set = { ...updateObject.$set, ...additionalObject };
13
+ return updateObject;
14
+ };
15
+ exports.createUpdateObject = createUpdateObject;
@@ -7,14 +7,16 @@ exports.put = void 0;
7
7
  const makeOptional_1 = __importDefault(require("../../util/makeOptional"));
8
8
  const yup_1 = require("yup");
9
9
  const paramId = (0, yup_1.object)({
10
- id: (0, yup_1.string)().required('id is required').matches(/^[0-9a-fA-F]{24}$/, 'id is invalid')
10
+ id: (0, yup_1.string)()
11
+ .required("id is required")
12
+ .matches(/^[0-9a-fA-F]{24}$/, "id is invalid"),
11
13
  });
12
14
  const schema = (0, yup_1.object)({
13
- translatedText: (0, yup_1.string)().required('translatedText is required'),
15
+ translatedText: (0, yup_1.string)().required("translatedText is required"),
14
16
  });
15
17
  //? exports
16
18
  const put = {
17
19
  params: paramId,
18
- body: (0, makeOptional_1.default)(schema)
20
+ body: (0, makeOptional_1.default)(schema),
19
21
  };
20
22
  exports.put = put;
package/dist/esm/db/db.js CHANGED
@@ -8,6 +8,7 @@ const path_1 = __importDefault(require("path"));
8
8
  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
+ const utils_1 = require("./utils");
11
12
  let configs = {
12
13
  dbType: "mongodb",
13
14
  path: "../models",
@@ -349,14 +350,7 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
349
350
  break;
350
351
  case "findOneAndUpdate":
351
352
  req.document = await model.findOne(match);
352
- data = model?.[queryState.action]?.call(model, match, {
353
- $set: {
354
- ...req.body,
355
- ...(typeof queryState.body == "function"
356
- ? queryState.body(req)
357
- : queryState.body),
358
- },
359
- }, { new: true });
353
+ data = model?.[queryState.action]?.call(model, match, (0, utils_1.createUpdateObject)(req, queryState.body || {}), { new: true });
360
354
  break;
361
355
  case "findOneAndDelete":
362
356
  data = model?.[queryState.action]?.call(model, match);
@@ -0,0 +1,3 @@
1
+ import { Request } from "express";
2
+ declare const createUpdateObject: (req: Request, additionalFields: Record<string, any> | ((req: Request) => Record<string, any>)) => Record<string, any>;
3
+ export { createUpdateObject };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createUpdateObject = void 0;
4
+ const createUpdateObject = (req, additionalFields) => {
5
+ let updateObject = { $set: { ...req.body } };
6
+ const additionalObject = typeof additionalFields === "function"
7
+ ? additionalFields(req)
8
+ : additionalFields;
9
+ if (Object.keys(additionalObject).find((key) => key.startsWith("$")))
10
+ updateObject = { ...updateObject, ...additionalObject };
11
+ else
12
+ updateObject.$set = { ...updateObject.$set, ...additionalObject };
13
+ return updateObject;
14
+ };
15
+ exports.createUpdateObject = createUpdateObject;
@@ -7,14 +7,16 @@ exports.put = void 0;
7
7
  const makeOptional_1 = __importDefault(require("../../util/makeOptional"));
8
8
  const yup_1 = require("yup");
9
9
  const paramId = (0, yup_1.object)({
10
- id: (0, yup_1.string)().required('id is required').matches(/^[0-9a-fA-F]{24}$/, 'id is invalid')
10
+ id: (0, yup_1.string)()
11
+ .required("id is required")
12
+ .matches(/^[0-9a-fA-F]{24}$/, "id is invalid"),
11
13
  });
12
14
  const schema = (0, yup_1.object)({
13
- translatedText: (0, yup_1.string)().required('translatedText is required'),
15
+ translatedText: (0, yup_1.string)().required("translatedText is required"),
14
16
  });
15
17
  //? exports
16
18
  const put = {
17
19
  params: paramId,
18
- body: (0, makeOptional_1.default)(schema)
20
+ body: (0, makeOptional_1.default)(schema),
19
21
  };
20
22
  exports.put = put;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "1.2.43",
3
+ "version": "1.2.45",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",