Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit eb28fa1

Browse files
committed
Switch to ES2022
1 parent f2d7c87 commit eb28fa1

10 files changed

Lines changed: 33 additions & 38 deletions

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hatsy/hatsy",
3-
"version": "2.5.3",
3+
"version": "3.0.0-pre.0",
44
"description": "Asynchronous TypeScript-friendly HTTP server for Node.js",
55
"keywords": [
66
"http-framework",
@@ -22,10 +22,10 @@
2222
"types": "./dist/hatsy.d.ts",
2323
"typesVersions": {
2424
"*": {
25-
"core": [
25+
"core.js": [
2626
"./dist/hatsy.core.d.ts"
2727
],
28-
"testing": [
28+
"testing.js": [
2929
"./dist/hatsy.testing.d.ts"
3030
]
3131
}
@@ -35,30 +35,28 @@
3535
"types": "./dist/hatsy.d.ts",
3636
"default": "./dist/hatsy.js"
3737
},
38-
"./core": {
38+
"./core.js": {
3939
"types": "./dist/hatsy.core.d.ts",
4040
"default": "./dist/hatsy.core.js"
4141
},
4242
"./package.json": "./package.json",
43-
"./testing": {
43+
"./testing.js": {
4444
"types": "./dist/hatsy.testing.d.ts",
4545
"default": "./dist/hatsy.testing.js"
4646
}
4747
},
4848
"sideEffects": false,
4949
"dependencies": {
50-
"@frontmeans/httongue": "^2.4.0",
51-
"@hatsy/http-header-value": "^3.7.1",
52-
"@proc7ts/logger": "^1.3.2",
53-
"@proc7ts/primitives": "^3.0.2"
50+
"@proc7ts/logger": "^2.0.0",
51+
"@proc7ts/primitives": "^4.0.1",
52+
"httongue": "^3.1.0",
53+
"http-header-value": "^4.0.0"
5454
},
5555
"engines": {
56-
"node": ">=12"
56+
"node": ">=18"
5757
},
5858
"devDependencies": {
5959
"@jest/globals": "^29.7.0",
60-
"@proc7ts/context-values": "^7.1.1",
61-
"@proc7ts/logger": "^1.3.2",
6260
"@run-z/eslint-config": "^3.5.0",
6361
"@run-z/prettier-config": "^2.0.0",
6462
"@run-z/project-config": "^0.20.0",

src/http/dispatch/dispatch-by-accepted.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { httpMimeNegotiator } from '@hatsy/http-header-value/headers';
1+
import { httpMimeNegotiator } from 'http-header-value/headers.js';
22
import type { RequestHandler, RequestHandlerMethod } from '../../core';
33
import { HttpError } from '../http-error';
44
import type { HttpMeans } from '../http.means';

src/http/dispatch/dispatch-by-language.handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { httpLanguageNegotiator } from '@hatsy/http-header-value/headers';
1+
import { httpLanguageNegotiator } from 'http-header-value/headers.js';
22
import type { RequestHandler, RequestHandlerMethod } from '../../core';
33
import { HttpError } from '../http-error';
44
import type { HttpMeans } from '../http.means';

src/http/http-listener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { HttpAddressRep } from '@hatsy/http-header-value/node';
21
import { consoleLogger } from '@proc7ts/logger';
32
import { lazyValue, noop } from '@proc7ts/primitives';
3+
import { HttpAddressRep } from 'http-header-value/node.js';
44
import type { IncomingMessage, ServerResponse } from 'node:http';
55
import {
6-
dispatchError,
76
ErrorMeans,
87
LoggerMeans,
98
Logging,
109
RequestContext,
1110
RequestHandler,
11+
dispatchError,
1212
requestProcessor,
1313
} from '../core';
1414
import type { HttpConfig } from './http-config';

src/http/render/render-http-error.handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { escapeXML, MIMEType } from '@frontmeans/httongue';
1+
import { escapeXML } from 'httongue';
22
import { STATUS_CODES } from 'node:http';
33
import type { ErrorMeans, RequestContext, RequestHandler } from '../../core';
44
import { dispatchByAccepted } from '../dispatch';
@@ -79,9 +79,9 @@ function renderJsonError(context: RequestContext<HttpMeans & RenderMeans & Error
7979
export const renderHttpError: RequestHandler<HttpMeans & ErrorMeans> = /*#__PURE__*/ Rendering.for(
8080
/*#__PURE__*/ dispatchByAccepted<HttpMeans & ErrorMeans & RenderMeans>(
8181
{
82-
[MIMEType.JSON]: renderJsonError,
83-
[MIMEType.TextJSON]: renderJsonError,
84-
[MIMEType.HTML]: renderHtmlError,
82+
'application/json': renderJsonError,
83+
'text/json': renderJsonError,
84+
'text/html': renderHtmlError,
8585
'*/*': renderHtmlError,
8686
},
8787
renderHtmlError,

src/http/render/rendering.capability.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { MIMEType } from '@frontmeans/httongue';
21
import { RequestCapability, requestExtension, RequestHandler } from '../../core';
32
import type { HttpMeans } from '../http.means';
43
import type { RenderMeans } from './render.means';
@@ -29,12 +28,12 @@ class RenderingCapability extends RequestCapability<HttpMeans, RenderMeans> {
2928
renderBody,
3029

3130
renderHtml(html: string | Buffer) {
32-
response.setHeader('Content-Type', `${MIMEType.HTML}; charset=utf-8`);
31+
response.setHeader('Content-Type', `text/html; charset=utf-8`);
3332
renderBody(html);
3433
},
3534

3635
renderJson(body: unknown) {
37-
response.setHeader('Content-Type', `${MIMEType.JSON}; charset=utf-8`);
36+
response.setHeader('Content-Type', `application/json; charset=utf-8`);
3837
renderBody(JSON.stringify(body));
3938
},
4039
}),

src/http/request/form-decoding.capability.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { MIMEType } from '@frontmeans/httongue';
21
import { asis } from '@proc7ts/primitives';
32
import { URLSearchParams } from 'node:url';
43
import {
@@ -17,8 +16,8 @@ import type { HttpMeans } from '../http.means';
1716
* @internal
1817
*/
1918
const URL_ENCODED_MIMES: Record<string, number> = {
20-
[MIMEType.Text]: 1,
21-
[MIMEType.FormURLEncoded]: 1,
19+
'text/plain': 1,
20+
'application/x-www-form-urlencoded': 1,
2221
};
2322

2423
/**
@@ -67,11 +66,11 @@ class FormDecodingCapability<TInput extends HttpMeans, TBody>
6766
): RequestHandler<TMeans> {
6867
return async context => {
6968
const { request } = context;
70-
const { 'content-type': contentType = MIMEType.Text } = request.headers;
69+
const { 'content-type': contentType = 'text/plain' } = request.headers;
7170

7271
if (!URL_ENCODED_MIMES[contentType]) {
7372
return Promise.reject(
74-
new HttpError(415, { details: `${MIMEType.FormURLEncoded} request expected` }),
73+
new HttpError(415, { details: `application/x-www-form-urlencoded request expected` }),
7574
);
7675
}
7776

src/http/request/http-forwarding.capability.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { HttpForwardTrust } from '@hatsy/http-header-value/headers';
2-
import { HttpAddressRep } from '@hatsy/http-header-value/node';
31
import { lazyValue } from '@proc7ts/primitives';
2+
import type { HttpForwardTrust } from 'http-header-value/headers.js';
3+
import { HttpAddressRep } from 'http-header-value/node.js';
44
import { RequestCapability, RequestHandler, requestUpdate } from '../../core';
55
import type { HttpMeans } from '../http.means';
66

src/http/request/json-parsing.capability.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { MIMEType } from '@frontmeans/httongue';
21
import { asis } from '@proc7ts/primitives';
32
import {
43
RequestBodyMeans,
@@ -17,9 +16,9 @@ import type { FormDecoding } from './form-decoding.capability';
1716
* @internal
1817
*/
1918
const JSON_MIMES: Readonly<Record<string, number>> = {
20-
[MIMEType.Text]: 1,
21-
[MIMEType.JSON]: 1,
22-
[MIMEType.TextJSON]: 1,
19+
'text/plain': 1,
20+
'application/json': 1,
21+
'text/json': 1,
2322
};
2423

2524
/**
@@ -67,10 +66,10 @@ class JsonParsingCapability<TInput extends HttpMeans, TBody>
6766
): RequestHandler<TMeans> {
6867
return async context => {
6968
const { request, next } = context;
70-
const { 'content-type': contentType = MIMEType.Text } = request.headers;
69+
const { 'content-type': contentType = 'text/plain' } = request.headers;
7170

7271
if (!JSON_MIMES[contentType]) {
73-
return Promise.reject(new HttpError(415, { details: `${MIMEType.JSON} request expected` }));
72+
return Promise.reject(new HttpError(415, { details: `application/json request expected` }));
7473
}
7574

7675
let json: unknown;

src/http/util/add-response-header.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { arrayOfElements, elementOrArray } from '@proc7ts/primitives';
1+
import { asArray, elementOrArray } from '@proc7ts/primitives';
22
import type { ServerResponse } from 'node:http';
33

44
/**
@@ -11,7 +11,7 @@ import type { ServerResponse } from 'node:http';
1111
* @param value - HTTP header value to add.
1212
*/
1313
export function addResponseHeader(response: ServerResponse, name: string, value: string): void {
14-
const oldValues = arrayOfElements(response.getHeader(name)).map(String);
14+
const oldValues = asArray(response.getHeader(name)).map(String);
1515
const newValues = elementOrArray(new Set<string>(oldValues).add(value))!;
1616

1717
response.setHeader(name, newValues);

0 commit comments

Comments
 (0)