@aeriajs/node-http 0.0.192 → 0.0.194

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/driver.js CHANGED
@@ -1,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerServer = exports.abstractResponse = exports.abstractRequest = void 0;
4
- const http_1 = require("@aeriajs/http");
5
- const types_1 = require("@aeriajs/types");
6
- const common_1 = require("@aeriajs/common");
7
- const http = require("node:http");
8
- const node_url_1 = require("node:url");
1
+ import { logResponse } from '@aeriajs/http';
2
+ import { ERROR_SYMBOL_DESCRIPTION } from '@aeriajs/types';
3
+ import { isEndpointError } from '@aeriajs/common';
4
+ import * as http from 'node:http';
5
+ import { parse as parseUrl } from 'node:url';
9
6
  const getBody = async (request) => {
10
7
  const bodyParts = [];
11
8
  for await (const chunk of request) {
@@ -13,7 +10,7 @@ const getBody = async (request) => {
13
10
  }
14
11
  return Buffer.concat(bodyParts).toString();
15
12
  };
16
- const abstractRequest = async (request) => {
13
+ export const abstractRequest = async (request) => {
17
14
  if (!request.url || !request.method) {
18
15
  throw new Error;
19
16
  }
@@ -26,15 +23,14 @@ const abstractRequest = async (request) => {
26
23
  ? undefined
27
24
  : await getBody(request),
28
25
  query: url.includes('?')
29
- ? (0, node_url_1.parse)(url, true).query
26
+ ? parseUrl(url, true).query
30
27
  : {},
31
28
  payload: {},
32
29
  fragments: [],
33
30
  });
34
31
  return req;
35
32
  };
36
- exports.abstractRequest = abstractRequest;
37
- const abstractResponse = (response, options) => {
33
+ export const abstractResponse = (response, options) => {
38
34
  const { end } = response;
39
35
  return Object.assign(response, {
40
36
  writeHead: response.writeHead.bind(response),
@@ -42,19 +38,19 @@ const abstractResponse = (response, options) => {
42
38
  end: (value) => {
43
39
  if (value === undefined) {
44
40
  if (options.enableLogging) {
45
- (0, http_1.logResponse)(response);
41
+ logResponse(response);
46
42
  }
47
43
  return end.bind(response)();
48
44
  }
49
45
  if (typeof value === 'object' && !(value instanceof Buffer)) {
50
46
  if (!response.headersSent) {
51
- if ((0, common_1.isEndpointError)(value)) {
47
+ if (isEndpointError(value)) {
52
48
  const { error } = value;
53
49
  response.writeHead(error.httpStatus, {
54
50
  'content-type': 'application/json',
55
51
  });
56
52
  Object.assign(value, {
57
- [types_1.ERROR_SYMBOL_DESCRIPTION]: true,
53
+ [ERROR_SYMBOL_DESCRIPTION]: true,
58
54
  });
59
55
  }
60
56
  else {
@@ -64,7 +60,7 @@ const abstractResponse = (response, options) => {
64
60
  }
65
61
  }
66
62
  if (options.enableLogging) {
67
- (0, http_1.logResponse)(response);
63
+ logResponse(response);
68
64
  }
69
65
  return end.bind(response)(JSON.stringify(value));
70
66
  }
@@ -72,22 +68,21 @@ const abstractResponse = (response, options) => {
72
68
  ? value
73
69
  : String(value);
74
70
  if (options.enableLogging) {
75
- (0, http_1.logResponse)(response);
71
+ logResponse(response);
76
72
  }
77
73
  return end.bind(response)(endVal);
78
74
  },
79
75
  });
80
76
  };
81
- exports.abstractResponse = abstractResponse;
82
77
  const abstractTransaction = async (request, response, options) => {
83
- const req = await (0, exports.abstractRequest)(request);
84
- const res = (0, exports.abstractResponse)(response, options);
78
+ const req = await abstractRequest(request);
79
+ const res = abstractResponse(response, options);
85
80
  return {
86
81
  req,
87
82
  res,
88
83
  };
89
84
  };
90
- const registerServer = (options, cb) => {
85
+ export const registerServer = (options, cb) => {
91
86
  const server = http.createServer(async (request, response) => {
92
87
  const { req, res, } = await abstractTransaction(request, response, options);
93
88
  cb(req, res);
@@ -97,4 +92,3 @@ const registerServer = (options, cb) => {
97
92
  listen: () => server.listen(options.port, options.host),
98
93
  };
99
94
  };
100
- exports.registerServer = registerServer;
package/dist/index.js CHANGED
@@ -1,17 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./driver.js"), exports);
1
+ export * from './driver.js';
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@aeriajs/node-http",
3
- "version": "0.0.192",
3
+ "type": "module",
4
+ "version": "0.0.194",
4
5
  "description": "## Installation",
5
6
  "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -14,8 +14,7 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.mjs",
18
- "require": "./dist/index.js"
17
+ "default": "./dist/index.js"
19
18
  }
20
19
  },
21
20
  "files": [
@@ -26,16 +25,13 @@
26
25
  "@aeriajs/http": "link:../http"
27
26
  },
28
27
  "peerDependencies": {
29
- "@aeriajs/common": "^0.0.157",
30
- "@aeriajs/http": "^0.0.192"
28
+ "@aeriajs/common": "^0.0.158",
29
+ "@aeriajs/http": "^0.0.194"
31
30
  },
32
31
  "scripts": {
33
32
  "test": "echo skipping",
34
33
  "lint": "eslint .",
35
34
  "lint:fix": "eslint . --fix",
36
- "build": "pnpm build:cjs && pnpm build:esm",
37
- "build:cjs": "tsc",
38
- "build:esm": "esbuild './src/**/*.ts' --outdir=dist --out-extension:.js=.mjs && pnpm build:esm-transform",
39
- "build:esm-transform": "pnpm -w esm-transform $PWD/dist"
35
+ "build": "tsc"
40
36
  }
41
37
  }
package/dist/driver.mjs DELETED
@@ -1,91 +0,0 @@
1
- "use strict";
2
- import { logResponse } from "@aeriajs/http";
3
- import { ERROR_SYMBOL_DESCRIPTION } from "@aeriajs/types";
4
- import { isEndpointError } from "@aeriajs/common";
5
- import * as http from "node:http";
6
- import { parse as parseUrl } from "node:url";
7
- const getBody = async (request) => {
8
- const bodyParts = [];
9
- for await (const chunk of request) {
10
- bodyParts.push(chunk);
11
- }
12
- return Buffer.concat(bodyParts).toString();
13
- };
14
- export const abstractRequest = async (request) => {
15
- if (!request.url || !request.method) {
16
- throw new Error();
17
- }
18
- const url = request.url;
19
- const req = Object.assign(request, {
20
- url,
21
- method: request.method,
22
- headers: request.headers,
23
- body: request.headers["x-stream-request"] ? void 0 : await getBody(request),
24
- query: url.includes("?") ? parseUrl(url, true).query : {},
25
- payload: {},
26
- fragments: []
27
- });
28
- return req;
29
- };
30
- export const abstractResponse = (response, options) => {
31
- const { end } = response;
32
- return Object.assign(response, {
33
- writeHead: response.writeHead.bind(response),
34
- setHeader: response.setHeader.bind(response),
35
- end: (value) => {
36
- if (value === void 0) {
37
- if (options.enableLogging) {
38
- logResponse(response);
39
- }
40
- return end.bind(response)();
41
- }
42
- if (typeof value === "object" && !(value instanceof Buffer)) {
43
- if (!response.headersSent) {
44
- if (isEndpointError(value)) {
45
- const { error } = value;
46
- response.writeHead(error.httpStatus, {
47
- "content-type": "application/json"
48
- });
49
- Object.assign(value, {
50
- [ERROR_SYMBOL_DESCRIPTION]: true
51
- });
52
- } else {
53
- response.writeHead(200, {
54
- "content-type": "application/json"
55
- });
56
- }
57
- }
58
- if (options.enableLogging) {
59
- logResponse(response);
60
- }
61
- return end.bind(response)(JSON.stringify(value));
62
- }
63
- const endVal = value instanceof Buffer ? value : String(value);
64
- if (options.enableLogging) {
65
- logResponse(response);
66
- }
67
- return end.bind(response)(endVal);
68
- }
69
- });
70
- };
71
- const abstractTransaction = async (request, response, options) => {
72
- const req = await abstractRequest(request);
73
- const res = abstractResponse(response, options);
74
- return {
75
- req,
76
- res
77
- };
78
- };
79
- export const registerServer = (options, cb) => {
80
- const server = http.createServer(async (request, response) => {
81
- const {
82
- req,
83
- res
84
- } = await abstractTransaction(request, response, options);
85
- cb(req, res);
86
- });
87
- return {
88
- server,
89
- listen: () => server.listen(options.port, options.host)
90
- };
91
- };
package/dist/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- export * from "./driver.mjs";