speedly 1.2.48 → 1.3.0

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.
@@ -14,6 +14,7 @@ type ConfigsType = {
14
14
  path?: string;
15
15
  dbEnv?: string;
16
16
  response?: boolean;
17
+ first?: boolean;
17
18
  type: "internal" | "external";
18
19
  pagination?: {
19
20
  quantity?: number;
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
+ first: false,
17
18
  response: true,
18
19
  ...(0, getConfig_1.default)("db"),
19
20
  };
@@ -488,6 +489,8 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
488
489
  }
489
490
  if (config?.response) {
490
491
  const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
492
+ if (queryState.action == "aggregate" && config.first && data[0]?.content.length)
493
+ data[0].content.length = data[0].content[0];
491
494
  const resBody = queryState.action == "aggregate"
492
495
  ? {
493
496
  message: config?.message ||
@@ -497,11 +500,15 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
497
500
  }
498
501
  : {
499
502
  content: data,
500
- ...{ detail: Object.keys(detail).length ? detail : undefined },
503
+ ...{
504
+ detail: Object.keys(detail).length ? detail : undefined,
505
+ },
501
506
  message: config?.message ||
502
507
  `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
503
508
  };
504
- res.success ? res.success(200, resBody) : res.status(200).json(resBody);
509
+ res.success
510
+ ? res.success(200, resBody)
511
+ : res.status(200).json(resBody);
505
512
  }
506
513
  else {
507
514
  next();
@@ -585,6 +592,7 @@ const db = (collectionName, config = configs) => {
585
592
  path: "../models",
586
593
  dbEnv: "DB_URL",
587
594
  type: "external",
595
+ first: false,
588
596
  response: true,
589
597
  ...(0, getConfig_1.default)("db"),
590
598
  };
@@ -14,6 +14,7 @@ type ConfigsType = {
14
14
  path?: string;
15
15
  dbEnv?: string;
16
16
  response?: boolean;
17
+ first?: boolean;
17
18
  type: "internal" | "external";
18
19
  pagination?: {
19
20
  quantity?: number;
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
+ first: false,
17
18
  response: true,
18
19
  ...(0, getConfig_1.default)("db"),
19
20
  };
@@ -488,6 +489,8 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
488
489
  }
489
490
  if (config?.response) {
490
491
  const action = queryState.action?.match(/create|update|delet/i)?.[0] || "find";
492
+ if (queryState.action == "aggregate" && config.first && data[0]?.content.length)
493
+ data[0].content.length = data[0].content[0];
491
494
  const resBody = queryState.action == "aggregate"
492
495
  ? {
493
496
  message: config?.message ||
@@ -497,11 +500,15 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
497
500
  }
498
501
  : {
499
502
  content: data,
500
- ...{ detail: Object.keys(detail).length ? detail : undefined },
503
+ ...{
504
+ detail: Object.keys(detail).length ? detail : undefined,
505
+ },
501
506
  message: config?.message ||
502
507
  `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
503
508
  };
504
- res.success ? res.success(200, resBody) : res.status(200).json(resBody);
509
+ res.success
510
+ ? res.success(200, resBody)
511
+ : res.status(200).json(resBody);
505
512
  }
506
513
  else {
507
514
  next();
@@ -585,6 +592,7 @@ const db = (collectionName, config = configs) => {
585
592
  path: "../models",
586
593
  dbEnv: "DB_URL",
587
594
  type: "external",
595
+ first: false,
588
596
  response: true,
589
597
  ...(0, getConfig_1.default)("db"),
590
598
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "1.2.48",
3
+ "version": "1.3.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",