routup 0.1.3 → 0.2.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.
@@ -1,4 +1,7 @@
1
1
  import { Request } from '../../type';
2
2
  export declare function setRequestEnv(req: Request, key: string, value: unknown): void;
3
+ export declare function setRequestEnv(req: Request, record: Record<string, any>, append?: boolean): void;
4
+ export declare function useRequestEnv(req: Request): Record<string, any>;
3
5
  export declare function useRequestEnv(req: Request, key: string): unknown | undefined;
6
+ export declare function unsetRequestEnv(req: Request, key: string): void;
4
7
  //# sourceMappingURL=env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/helpers/request/env.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIrC,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAI,IAAI,CAQ9E;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAI,OAAO,GAAG,SAAS,CAM7E"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/helpers/request/env.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIrC,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAI,IAAI,CAAC;AAChF,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,OAAO,GAAI,IAAI,CAAC;AA0BlG,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAClE,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAI,OAAO,GAAG,SAAS,CAAC;AAiB/E,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,QAMxD"}
@@ -6,11 +6,27 @@
6
6
  * view the LICENSE file that was distributed with this source code.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.useRequestEnv = exports.setRequestEnv = void 0;
9
+ exports.unsetRequestEnv = exports.useRequestEnv = exports.setRequestEnv = void 0;
10
+ const smob_1 = require("smob");
10
11
  const envSymbol = Symbol.for('ReqEnv');
11
12
  function setRequestEnv(req, key, value) {
12
13
  if (envSymbol in req) {
13
- req[envSymbol][key] = value;
14
+ if (typeof key === 'object') {
15
+ if (value) {
16
+ req[envSymbol] = (0, smob_1.merge)(req[envSymbol], key);
17
+ }
18
+ else {
19
+ req[envSymbol] = key;
20
+ }
21
+ }
22
+ else {
23
+ req[envSymbol][key] = value;
24
+ }
25
+ return;
26
+ }
27
+ if (typeof key === 'object') {
28
+ req[envSymbol] = key;
29
+ return;
14
30
  }
15
31
  req[envSymbol] = {
16
32
  [key]: value,
@@ -19,9 +35,23 @@ function setRequestEnv(req, key, value) {
19
35
  exports.setRequestEnv = setRequestEnv;
20
36
  function useRequestEnv(req, key) {
21
37
  if (envSymbol in req) {
22
- return req[envSymbol][key];
38
+ if (typeof key === 'string') {
39
+ return req[envSymbol][key];
40
+ }
41
+ return req[envSymbol];
42
+ }
43
+ if (typeof key === 'string') {
44
+ return undefined;
23
45
  }
24
- return undefined;
46
+ return {};
25
47
  }
26
48
  exports.useRequestEnv = useRequestEnv;
49
+ function unsetRequestEnv(req, key) {
50
+ if (envSymbol in req) {
51
+ if ((0, smob_1.hasOwnProperty)(req[envSymbol], key)) {
52
+ delete req[envSymbol][key];
53
+ }
54
+ }
55
+ }
56
+ exports.unsetRequestEnv = unsetRequestEnv;
27
57
  //# sourceMappingURL=env.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/helpers/request/env.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAEvC,SAAgB,aAAa,CAAC,GAAY,EAAE,GAAW,EAAE,KAAc;IACnE,IAAI,SAAS,IAAI,GAAG,EAAE;QACjB,GAAW,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;KACxC;IAEA,GAAW,CAAC,SAAS,CAAC,GAAG;QACtB,CAAC,GAAG,CAAC,EAAE,KAAK;KACf,CAAC;AACN,CAAC;AARD,sCAQC;AAED,SAAgB,aAAa,CAAC,GAAY,EAAE,GAAW;IACnD,IAAI,SAAS,IAAI,GAAG,EAAE;QAClB,OAAQ,GAAW,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;KACvC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAND,sCAMC"}
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../../../src/helpers/request/env.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+BAA6C;AAG7C,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAIvC,SAAgB,aAAa,CAAC,GAAY,EAAE,GAAiC,EAAE,KAAyB;IACpG,IAAI,SAAS,IAAI,GAAG,EAAE;QAClB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YACzB,IAAI,KAAK,EAAE;gBACN,GAAW,CAAC,SAAS,CAAC,GAAG,IAAA,YAAK,EAAE,GAAW,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC;aACjE;iBAAM;gBACF,GAAW,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC;aACjC;SACJ;aAAM;YACF,GAAW,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SACxC;QAED,OAAO;KACV;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACxB,GAAW,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC;QAC9B,OAAO;KACV;IAEA,GAAW,CAAC,SAAS,CAAC,GAAG;QACtB,CAAC,GAAG,CAAC,EAAE,KAAK;KACf,CAAC;AACN,CAAC;AAvBD,sCAuBC;AAID,SAAgB,aAAa,CAAC,GAAY,EAAE,GAAY;IACpD,IAAI,SAAS,IAAI,GAAG,EAAE;QAClB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YACzB,OAAQ,GAAW,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;SACvC;QAED,OAAQ,GAAW,CAAC,SAAS,CAAC,CAAC;KAClC;IAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACzB,OAAO,SAAS,CAAC;KACpB;IAED,OAAO,EAAE,CAAC;AACd,CAAC;AAdD,sCAcC;AAED,SAAgB,eAAe,CAAC,GAAY,EAAE,GAAW;IACrD,IAAI,SAAS,IAAI,GAAG,EAAE;QAClB,IAAI,IAAA,qBAAc,EAAE,GAAW,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,EAAE;YAC9C,OAAQ,GAAW,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC;SACvC;KACJ;AACL,CAAC;AAND,0CAMC"}
@@ -1,5 +1,4 @@
1
1
  export * from './mount-path';
2
- export * from './body';
3
2
  export * from './env';
4
3
  export * from './header';
5
4
  export * from './header-accept';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/request/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/request/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAC7B,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
@@ -21,7 +21,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  __exportStar(require("./mount-path"), exports);
24
- __exportStar(require("./body"), exports);
25
24
  __exportStar(require("./env"), exports);
26
25
  __exportStar(require("./header"), exports);
27
26
  __exportStar(require("./header-accept"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/request/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,+CAA6B;AAC7B,yCAAuB;AACvB,wCAAsB;AACtB,2CAAyB;AACzB,kDAAgC;AAChC,0DAAwC;AACxC,2DAAyC;AACzC,2DAAyC;AACzC,wDAAsC;AACtC,+CAA6B;AAC7B,2CAAyB;AACzB,yCAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/request/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,+CAA6B;AAC7B,wCAAsB;AACtB,2CAAyB;AACzB,kDAAgC;AAChC,0DAAwC;AACxC,2DAAyC;AACzC,2DAAyC;AACzC,wDAAsC;AACtC,+CAA6B;AAC7B,2CAAyB;AACzB,yCAAuB"}
@@ -1,4 +1,3 @@
1
- export * from './body';
2
1
  export * from './cache';
3
2
  export * from './header';
4
3
  export * from './header-attachment';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/response/index.ts"],"names":[],"mappings":"AAOA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/response/index.ts"],"names":[],"mappings":"AAOA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
@@ -20,7 +20,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
20
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./body"), exports);
24
23
  __exportStar(require("./cache"), exports);
25
24
  __exportStar(require("./header"), exports);
26
25
  __exportStar(require("./header-attachment"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/response/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,yCAAuB;AACvB,0CAAwB;AACxB,2CAAyB;AACzB,sDAAoC;AACpC,wDAAsC;AACtC,yCAAuB;AACvB,8CAA4B;AAC5B,gDAA8B;AAC9B,gDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/response/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,2CAAyB;AACzB,sDAAoC;AACpC,wDAAsC;AACtC,yCAAuB;AACvB,8CAA4B;AAC5B,gDAA8B;AAC9B,gDAA8B"}
@@ -0,0 +1,3 @@
1
+ import { Response } from '../../type';
2
+ export declare function sendAccepted(res: Response, chunk?: any): void;
3
+ //# sourceMappingURL=send-accepted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-accepted.d.ts","sourceRoot":"","sources":["../../../src/helpers/response/send-accepted.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,wBAAgB,YAAY,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,GAAG,QAKtD"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.sendAccepted = void 0;
10
+ const send_1 = require("./send");
11
+ function sendAccepted(res, chunk) {
12
+ res.statusCode = 202;
13
+ res.statusMessage = 'Accepted';
14
+ return (0, send_1.send)(res, chunk);
15
+ }
16
+ exports.sendAccepted = sendAccepted;
17
+ //# sourceMappingURL=send-accepted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-accepted.js","sourceRoot":"","sources":["../../../src/helpers/response/send-accepted.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,iCAA8B;AAE9B,SAAgB,YAAY,CAAC,GAAa,EAAE,KAAW;IACnD,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;IACrB,GAAG,CAAC,aAAa,GAAG,UAAU,CAAC;IAE/B,OAAO,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC5B,CAAC;AALD,oCAKC"}
@@ -0,0 +1,3 @@
1
+ import { Response } from '../../type';
2
+ export declare function sendCreated(res: Response, chunk?: any): void;
3
+ //# sourceMappingURL=send-created.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-created.d.ts","sourceRoot":"","sources":["../../../src/helpers/response/send-created.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,wBAAgB,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,GAAG,QAKrD"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.sendCreated = void 0;
10
+ const send_1 = require("./send");
11
+ function sendCreated(res, chunk) {
12
+ res.statusCode = 201;
13
+ res.statusMessage = 'Created';
14
+ return (0, send_1.send)(res, chunk);
15
+ }
16
+ exports.sendCreated = sendCreated;
17
+ //# sourceMappingURL=send-created.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-created.js","sourceRoot":"","sources":["../../../src/helpers/response/send-created.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,iCAA8B;AAE9B,SAAgB,WAAW,CAAC,GAAa,EAAE,KAAW;IAClD,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;IACrB,GAAG,CAAC,aAAa,GAAG,SAAS,CAAC;IAE9B,OAAO,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC5B,CAAC;AALD,kCAKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "routup",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Routup is a minimalistic http based routing framework.",
5
5
  "main": "./dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -52,5 +52,5 @@
52
52
  "path-to-regexp": "^6.2.1",
53
53
  "smob": "^0.0.6"
54
54
  },
55
- "gitHead": "073b2771996cde8b9e24af7c4cd69f15a560d830"
55
+ "gitHead": "437eab266f760bd855b06baee914e738c185433c"
56
56
  }
@@ -1,5 +0,0 @@
1
- /// <reference types="node" />
2
- import { IncomingMessage } from 'http';
3
- export declare function useRequestBody(req: IncomingMessage): unknown | undefined;
4
- export declare function setRequestBody(req: IncomingMessage, body: unknown): void;
5
- //# sourceMappingURL=body.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../../src/helpers/request/body.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAIvC,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,GAAI,OAAO,GAAG,SAAS,CAUzE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,QAEjE"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setRequestBody = exports.useRequestBody = void 0;
4
- const BodySymbol = Symbol.for('ReqBody');
5
- function useRequestBody(req) {
6
- if ('body' in req) {
7
- return req.body;
8
- }
9
- if (BodySymbol in req) {
10
- return req[BodySymbol];
11
- }
12
- return undefined;
13
- }
14
- exports.useRequestBody = useRequestBody;
15
- function setRequestBody(req, body) {
16
- req[BodySymbol] = body;
17
- }
18
- exports.setRequestBody = setRequestBody;
19
- //# sourceMappingURL=body.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"body.js","sourceRoot":"","sources":["../../../src/helpers/request/body.ts"],"names":[],"mappings":";;;AAQA,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAEzC,SAAgB,cAAc,CAAC,GAAoB;IAC/C,IAAI,MAAM,IAAI,GAAG,EAAE;QACf,OAAQ,GAAW,CAAC,IAAI,CAAC;KAC5B;IAED,IAAI,UAAU,IAAI,GAAG,EAAE;QACnB,OAAQ,GAAW,CAAC,UAAU,CAAC,CAAC;KACnC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAVD,wCAUC;AAED,SAAgB,cAAc,CAAC,GAAoB,EAAE,IAAa;IAC7D,GAAW,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;AACpC,CAAC;AAFD,wCAEC"}
@@ -1,7 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { ServerResponse } from 'http';
4
- export declare function useResponseBody(res: ServerResponse): Buffer | undefined;
5
- export declare function setResponseBody(res: ServerResponse, body: Buffer): void;
6
- export declare function useResponseBodyFormatted(res: ServerResponse): unknown;
7
- //# sourceMappingURL=body.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../../src/helpers/response/body.ts"],"names":[],"mappings":";;AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAKtC,wBAAgB,eAAe,CAAC,GAAG,EAAE,cAAc,GAAI,MAAM,GAAG,SAAS,CAMxE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,QAEhE;AAGD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,cAAc,GAAI,OAAO,CAyBtE"}
@@ -1,48 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.useResponseBodyFormatted = exports.setResponseBody = exports.useResponseBody = void 0;
10
- const constants_1 = require("../../constants");
11
- const BodySymbol = Symbol.for('ResBody');
12
- function useResponseBody(res) {
13
- if (BodySymbol in res) {
14
- return res[BodySymbol];
15
- }
16
- return undefined;
17
- }
18
- exports.useResponseBody = useResponseBody;
19
- function setResponseBody(res, body) {
20
- res[BodySymbol] = body;
21
- }
22
- exports.setResponseBody = setResponseBody;
23
- /* istanbul ignore next */
24
- function useResponseBodyFormatted(res) {
25
- const body = useResponseBody(res);
26
- if (typeof body === 'undefined') {
27
- return undefined;
28
- }
29
- let contentType = res.getHeader(constants_1.HeaderName.CONTENT_TYPE);
30
- if (!contentType) {
31
- return contentType;
32
- }
33
- if (Array.isArray(contentType)) {
34
- contentType = contentType.shift();
35
- }
36
- else {
37
- contentType = `${contentType}`.split('; ').shift();
38
- }
39
- switch (contentType) {
40
- case 'application/json':
41
- return JSON.parse(body.toString('utf-8'));
42
- case 'text/html':
43
- return body.toString('utf-8');
44
- }
45
- return body;
46
- }
47
- exports.useResponseBodyFormatted = useResponseBodyFormatted;
48
- //# sourceMappingURL=body.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"body.js","sourceRoot":"","sources":["../../../src/helpers/response/body.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,+CAA6C;AAE7C,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAEzC,SAAgB,eAAe,CAAC,GAAmB;IAC/C,IAAI,UAAU,IAAI,GAAG,EAAE;QACnB,OAAQ,GAAW,CAAC,UAAU,CAAC,CAAC;KACnC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAND,0CAMC;AAED,SAAgB,eAAe,CAAC,GAAmB,EAAE,IAAY;IAC5D,GAAW,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;AACpC,CAAC;AAFD,0CAEC;AAED,0BAA0B;AAC1B,SAAgB,wBAAwB,CAAC,GAAmB;IACxD,MAAM,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC7B,OAAO,SAAS,CAAC;KACpB;IAED,IAAI,WAAW,GAAG,GAAG,CAAC,SAAS,CAAC,sBAAU,CAAC,YAAY,CAAC,CAAC;IACzD,IAAI,CAAC,WAAW,EAAE;QACd,OAAO,WAAW,CAAC;KACtB;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;QAC5B,WAAW,GAAG,WAAW,CAAC,KAAK,EAAE,CAAC;KACrC;SAAM;QACH,WAAW,GAAG,GAAG,WAAW,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;KACtD;IAED,QAAQ,WAAW,EAAE;QACjB,KAAK,kBAAkB;YACnB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QAC9C,KAAK,WAAW;YACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;KACrC;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAzBD,4DAyBC"}