speedly 2.0.7 → 2.0.9

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.
@@ -1,4 +1,5 @@
1
- import { InitFunction } from "./config/init";
2
- import { Express } from "express";
3
- declare let exportObject: Express & InitFunction;
4
- export default exportObject;
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/cjs/index.js CHANGED
@@ -1,45 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.speedly = exports.Router = void 0;
39
7
  const init_1 = __importDefault(require("./config/init"));
8
+ exports.speedly = init_1.default;
40
9
  // Export express types and classes
41
- const express = __importStar(require("express"));
42
- let exportObject = express;
43
- Object.assign(exportObject, init_1.default);
10
+ var express_1 = require("express");
11
+ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
44
12
  // Override the default express() with our speedly`s functions
45
- exports.default = exportObject;
13
+ 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]) => {
@@ -1,4 +1,5 @@
1
- import { InitFunction } from "./config/init";
2
- import { Express } from "express";
3
- declare let exportObject: Express & InitFunction;
4
- export default exportObject;
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/esm/index.js CHANGED
@@ -1,45 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
38
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.speedly = exports.Router = void 0;
39
7
  const init_1 = __importDefault(require("./config/init"));
8
+ exports.speedly = init_1.default;
40
9
  // Export express types and classes
41
- const express = __importStar(require("express"));
42
- let exportObject = express;
43
- Object.assign(exportObject, init_1.default);
10
+ var express_1 = require("express");
11
+ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return express_1.Router; } });
44
12
  // Override the default express() with our speedly`s functions
45
- exports.default = exportObject;
13
+ 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.7",
3
+ "version": "2.0.9",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -8,6 +8,26 @@
8
8
  ".": {
9
9
  "import": "./dist/esm/index.js",
10
10
  "require": "./dist/cjs/index.js"
11
+ },
12
+ "./kit": {
13
+ "import": "./dist/esm/kit/index.js",
14
+ "require": "./dist/cjs/kit/index.js"
15
+ },
16
+ "./util": {
17
+ "import": "./dist/esm/util/index.js",
18
+ "require": "./dist/cjs/util/index.js"
19
+ },
20
+ "./modules/": {
21
+ "import": "./dist/esm/modules/index.js",
22
+ "require": "./dist/cjs/modules/index.js"
23
+ },
24
+ "./document/": {
25
+ "import": "./dist/esm/document/index.js",
26
+ "require": "./dist/cjs/document/index.js"
27
+ },
28
+ "./model/": {
29
+ "import": "./dist/esm/model/index.js",
30
+ "require": "./dist/cjs/model/index.js"
11
31
  }
12
32
  },
13
33
  "scripts": {