speedly 2.0.6 → 2.0.8

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.
@@ -8,8 +8,9 @@ type InitConfig = {
8
8
  staticFiles?: boolean;
9
9
  [key: string]: any;
10
10
  };
11
+ export type InitFunction = (config?: InitConfig) => express.Express;
12
+ export type { InitConfig };
11
13
  export default function speedly(config?: InitConfig): express.Express & {
12
14
  speedlyConfig: InitConfig;
13
15
  registerFallbacks: () => void;
14
16
  };
15
- export {};
@@ -1,3 +1,5 @@
1
1
  import speedly from "./config/init";
2
2
  export { Request, Response, NextFunction, Application, Router, RequestHandler, ErrorRequestHandler, } from "express";
3
+ export type { InitConfig } from "./config/init";
4
+ export { speedly };
3
5
  export default speedly;
package/dist/cjs/index.js CHANGED
@@ -3,12 +3,11 @@ 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.Router = void 0;
6
+ exports.speedly = exports.Router = void 0;
7
7
  const init_1 = __importDefault(require("./config/init"));
8
+ exports.speedly = init_1.default;
8
9
  // Export express types and classes
9
10
  var express_1 = require("express");
10
11
  Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
11
12
  // Override the default express() with our speedly`s functions
12
13
  exports.default = init_1.default;
13
- module.exports = init_1.default;
14
- module.exports.default = init_1.default;
@@ -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;
@@ -14,6 +14,8 @@ let configs = {
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" }) => {
@@ -485,21 +487,32 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
485
487
  : []);
486
488
  }
487
489
  }
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);
490
+ if (config?.response) {
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];
494
+ const resBody = queryState.action == "aggregate"
495
+ ? {
496
+ message: config?.message ||
497
+ `the ${collectionName} was found successfully`,
498
+ content: [],
499
+ ...data[0],
500
+ }
501
+ : {
502
+ content: data,
503
+ ...{
504
+ detail: Object.keys(detail).length ? detail : undefined,
505
+ },
506
+ message: config?.message ||
507
+ `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
508
+ };
509
+ res.success
510
+ ? res.success(200, resBody)
511
+ : res.status(200).json(resBody);
512
+ }
513
+ else {
514
+ next();
515
+ }
503
516
  }
504
517
  }
505
518
  catch (err) {
@@ -579,6 +592,8 @@ const db = (collectionName, config = configs) => {
579
592
  path: "../models",
580
593
  dbEnv: "DB_URL",
581
594
  type: "external",
595
+ first: false,
596
+ response: true,
582
597
  ...(0, getConfig_1.default)("db"),
583
598
  };
584
599
  Object.entries(config).forEach(([key, value]) => {
@@ -8,8 +8,9 @@ type InitConfig = {
8
8
  staticFiles?: boolean;
9
9
  [key: string]: any;
10
10
  };
11
+ export type InitFunction = (config?: InitConfig) => express.Express;
12
+ export type { InitConfig };
11
13
  export default function speedly(config?: InitConfig): express.Express & {
12
14
  speedlyConfig: InitConfig;
13
15
  registerFallbacks: () => void;
14
16
  };
15
- export {};
@@ -1,3 +1,5 @@
1
1
  import speedly from "./config/init";
2
2
  export { Request, Response, NextFunction, Application, Router, RequestHandler, ErrorRequestHandler, } from "express";
3
+ export type { InitConfig } from "./config/init";
4
+ export { speedly };
3
5
  export default speedly;
package/dist/esm/index.js CHANGED
@@ -3,12 +3,11 @@ 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.Router = void 0;
6
+ exports.speedly = exports.Router = void 0;
7
7
  const init_1 = __importDefault(require("./config/init"));
8
+ exports.speedly = init_1.default;
8
9
  // Export express types and classes
9
10
  var express_1 = require("express");
10
11
  Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
11
12
  // Override the default express() with our speedly`s functions
12
13
  exports.default = init_1.default;
13
- module.exports = init_1.default;
14
- module.exports.default = init_1.default;
@@ -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;
@@ -14,6 +14,8 @@ let configs = {
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" }) => {
@@ -485,21 +487,32 @@ const usingMongoDb = (collectionName, config = { type: "external" }) => {
485
487
  : []);
486
488
  }
487
489
  }
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);
490
+ if (config?.response) {
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];
494
+ const resBody = queryState.action == "aggregate"
495
+ ? {
496
+ message: config?.message ||
497
+ `the ${collectionName} was found successfully`,
498
+ content: [],
499
+ ...data[0],
500
+ }
501
+ : {
502
+ content: data,
503
+ ...{
504
+ detail: Object.keys(detail).length ? detail : undefined,
505
+ },
506
+ message: config?.message ||
507
+ `the ${collectionName} was ${action == "find" ? "found" : action + "ed"}`,
508
+ };
509
+ res.success
510
+ ? res.success(200, resBody)
511
+ : res.status(200).json(resBody);
512
+ }
513
+ else {
514
+ next();
515
+ }
503
516
  }
504
517
  }
505
518
  catch (err) {
@@ -579,6 +592,8 @@ const db = (collectionName, config = configs) => {
579
592
  path: "../models",
580
593
  dbEnv: "DB_URL",
581
594
  type: "external",
595
+ first: false,
596
+ response: true,
582
597
  ...(0, getConfig_1.default)("db"),
583
598
  };
584
599
  Object.entries(config).forEach(([key, value]) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speedly",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",