Skip to content

Commit

Permalink
ES2022-style imports
Browse files Browse the repository at this point in the history
  • Loading branch information
surol committed Sep 17, 2023
1 parent d35fede commit 550fef8
Show file tree
Hide file tree
Showing 55 changed files with 233 additions and 221 deletions.
6 changes: 3 additions & 3 deletions src/core/dispatch-error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ErrorMeans } from './error.means';
import type { RequestHandler } from './request-handler';
import { requestExtension } from './request-modification';
import type { ErrorMeans } from './error.means.js';
import type { RequestHandler } from './request-handler.js';
import { requestExtension } from './request-modification.js';

/**
* Dispatches request processing error.
Expand Down
14 changes: 0 additions & 14 deletions src/core/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/core/logging/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/core/logging/logger.means.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RequestLogger } from './request-logger';
import type { RequestLogger } from './request-logger.js';

/**
* Request logger means.
Expand Down
10 changes: 5 additions & 5 deletions src/core/logging/logging.capability.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { consoleLogger } from '@proc7ts/logger';
import { RequestCapability } from '../request-capability';
import type { RequestHandler } from '../request-handler';
import { requestExtension } from '../request-modification';
import type { LoggerMeans } from './logger.means';
import type { RequestLogger } from './request-logger';
import { RequestCapability } from '../request-capability.js';
import type { RequestHandler } from '../request-handler.js';
import { requestExtension } from '../request-modification.js';
import type { LoggerMeans } from './logger.means.js';
import type { RequestLogger } from './request-logger.js';

/**
* Request logging capability.
Expand Down
14 changes: 7 additions & 7 deletions src/core/logging/logging.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { beforeEach, describe, expect, it, jest } from '@jest/globals';
import { consoleLogger, silentLogger } from '@proc7ts/logger';
import { noop } from '@proc7ts/primitives';
import type { Mock } from 'jest-mock';
import type { RequestContext } from '../request-context';
import type { RequestHandler } from '../request-handler';
import type { RequestProcessor } from '../request-processor';
import { requestProcessor } from '../request-processor';
import type { LoggerMeans } from './logger.means';
import { Logging } from './logging.capability';
import type { RequestLogger } from './request-logger';
import type { RequestContext } from '../request-context.js';
import type { RequestHandler } from '../request-handler.js';
import type { RequestProcessor } from '../request-processor.js';
import { requestProcessor } from '../request-processor.js';
import type { LoggerMeans } from './logger.means.js';
import { Logging } from './logging.capability.js';
import type { RequestLogger } from './request-logger.js';

describe('Logging', () => {
let handler: Mock<(context: RequestContext<LoggerMeans>) => void>;
Expand Down
3 changes: 3 additions & 0 deletions src/core/logging/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './logger.means.js';
export * from './logging.capability.js';
export * from './request-logger.js';
13 changes: 13 additions & 0 deletions src/core/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @module @hatsy/hatsy/core.js
*/
export * from './dispatch-error.js';
export * from './error.means.js';
export * from './logging/mod.js';
export * from './request-body.means.js';
export * from './request-capability.js';
export * from './request-context.js';
export * from './request-handler.js';
export * from './request-modification.js';
export * from './request-processor.js';
export * from './request-value-transformer.js';
2 changes: 1 addition & 1 deletion src/core/request-capability.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RequestHandler } from './request-handler';
import type { RequestHandler } from './request-handler.js';

/**
* Request processing capability.
Expand Down
4 changes: 2 additions & 2 deletions src/core/request-context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RequestHandler } from './request-handler';
import type { RequestModification } from './request-modification';
import type { RequestHandler } from './request-handler.js';
import type { RequestModification } from './request-modification.js';

/**
* Request processing context.
Expand Down
4 changes: 2 additions & 2 deletions src/core/request-handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, it } from '@jest/globals';
import { valueProvider } from '@proc7ts/primitives';
import type { ServerResponse } from 'node:http';
import type { RequestContext } from './request-context';
import { requestHandler, RequestHandler } from './request-handler';
import type { RequestContext } from './request-context.js';
import { requestHandler, RequestHandler } from './request-handler.js';

describe('requestHandler', () => {
let context: RequestContext<object>;
Expand Down
4 changes: 2 additions & 2 deletions src/core/request-handler.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { RequestContext } from './request-context';
import type { RequestContext } from './request-context.js';

/**
* Request processing handler signature.
*
* Handler implementations expect a request processing context containing specific processing means.
* E.g. the ones for {@link HttpMeans HTTP request processing}. The handler may either respond using the provided means,
* or delegate to {@link RequestContext.Agent.next next handler}.
* or delegate to {@link RequestContext.Agent#next next handler}.
*
* The handler may be asynchronous.
*
Expand Down
6 changes: 3 additions & 3 deletions src/core/request-processor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RequestContext } from './request-context';
import type { RequestHandler, RequestHandlerMethod } from './request-handler';
import type { RequestModification } from './request-modification';
import type { RequestContext } from './request-context.js';
import type { RequestHandler, RequestHandlerMethod } from './request-handler.js';
import type { RequestModification } from './request-modification.js';

/**
* Generic request processor.
Expand Down
2 changes: 1 addition & 1 deletion src/core/request-value-transformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RequestContext } from './request-context';
import type { RequestContext } from './request-context.js';

/**
* Signature of request value transformer function.
Expand Down
15 changes: 8 additions & 7 deletions src/http/dispatch/dispatch-by-accepted.handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
import { silentLogger } from '@proc7ts/logger';
import type { RequestContext } from '../../core';
import { Logging } from '../../core';
import { TestHttpServer } from '../../testing';
import type { HttpMeans } from '../http.means';
import { Rendering, RenderMeans } from '../render';
import { addResponseHeader } from '../util';
import { dispatchByAccepted } from './dispatch-by-accepted.handler';
import { Logging } from '../../core/logging/logging.capability.js';
import { RequestContext } from '../../core/request-context.js';
import { TestHttpServer } from '../../testing/test-http-server.js';
import { HttpMeans } from '../http.means.js';
import { RenderMeans } from '../render/render.means.js';
import { Rendering } from '../render/rendering.capability.js';
import { addResponseHeader } from '../util/add-response-header.js';
import { dispatchByAccepted } from './dispatch-by-accepted.handler.js';

describe('dispatchByAccepted', () => {
let server: TestHttpServer;
Expand Down
8 changes: 4 additions & 4 deletions src/http/dispatch/dispatch-by-accepted.handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { httpMimeNegotiator } from 'http-header-value/headers.js';
import type { RequestHandler, RequestHandlerMethod } from '../../core';
import { HttpError } from '../http-error';
import type { HttpMeans } from '../http.means';
import { addResponseHeader } from '../util';
import { HttpError } from '../http-error.js';
import type { HttpMeans } from '../http.means.js';
import { RequestHandler, RequestHandlerMethod } from '../../core/request-handler.js';
import { addResponseHeader } from '../util/add-response-header.js';

/**
* Request processing handlers for accepted MIME types.
Expand Down
8 changes: 4 additions & 4 deletions src/http/dispatch/dispatch-by-language.handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { afterAll, beforeAll, beforeEach, describe, expect, it } from '@jest/globals';
import { silentLogger } from '@proc7ts/logger';
import { Logging } from '../../core';
import { TestHttpServer } from '../../testing';
import { Rendering } from '../render';
import { dispatchByLanguage } from './dispatch-by-language.handler';
import { Logging } from '../../core/logging/logging.capability.js';
import { TestHttpServer } from '../../testing/test-http-server.js';
import { Rendering } from '../render/rendering.capability.js';
import { dispatchByLanguage } from './dispatch-by-language.handler.js';

describe('dispatchByLanguage', () => {
let server: TestHttpServer;
Expand Down
8 changes: 4 additions & 4 deletions src/http/dispatch/dispatch-by-language.handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { httpLanguageNegotiator } from 'http-header-value/headers.js';
import type { RequestHandler, RequestHandlerMethod } from '../../core';
import { HttpError } from '../http-error';
import type { HttpMeans } from '../http.means';
import { addResponseHeader } from '../util';
import { RequestHandler, RequestHandlerMethod } from '../../core/request-handler.js';
import { HttpError } from '../http-error.js';
import type { HttpMeans } from '../http.means.js';
import { addResponseHeader } from '../util/add-response-header.js';

/**
* Request processing handlers for accepted languages.
Expand Down
15 changes: 9 additions & 6 deletions src/http/dispatch/dispatch-by-method.handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { afterAll, afterEach, beforeAll, describe, expect, it } from '@jest/globals';
import { silentLogger } from '@proc7ts/logger';
import { noop } from '@proc7ts/primitives';
import { Logging, RequestContext, requestHandler } from '../../core';
import { TestHttpServer } from '../../testing';
import { HttpError } from '../http-error';
import type { HttpMeans } from '../http.means';
import { Rendering, RenderMeans } from '../render';
import { dispatchByMethod } from './dispatch-by-method.handler';
import { TestHttpServer } from '../../testing/test-http-server.js';
import { Rendering } from '../render/rendering.capability.js';
import { dispatchByMethod } from './dispatch-by-method.handler.js';
import { RequestContext } from '../../core/request-context.js';
import { HttpMeans } from '../http.means.js';
import { RenderMeans } from '../render/render.means.js';
import { requestHandler } from '../../core/request-handler.js';
import { Logging } from '../../core/logging/logging.capability.js';
import { HttpError } from '../http-error.js';

describe('dispatchByName', () => {
let server: TestHttpServer;
Expand Down
4 changes: 2 additions & 2 deletions src/http/dispatch/dispatch-by-method.handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RequestHandler, RequestHandlerMethod } from '../../core';
import type { HttpMeans } from '../http.means';
import { RequestHandler, RequestHandlerMethod } from '../../core/request-handler.js';
import type { HttpMeans } from '../http.means.js';

/**
* Request processing handlers for HTTP request methods.
Expand Down
3 changes: 0 additions & 3 deletions src/http/dispatch/index.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/http/dispatch/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './dispatch-by-accepted.handler.js';
export * from './dispatch-by-language.handler.js';
export * from './dispatch-by-method.handler.js';
5 changes: 3 additions & 2 deletions src/http/http-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ErrorMeans, RequestHandler } from '../core';
import type { HttpMeans } from './http.means';
import { ErrorMeans } from '../core/error.means.js';
import { RequestHandler } from '../core/request-handler.js';
import type { HttpMeans } from './http.means.js';

/**
* HTTP processing configuration.
Expand Down
8 changes: 4 additions & 4 deletions src/http/http-error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { dueLog } from '@proc7ts/logger';
import { HttpError } from './http-error';
import { HttpError } from './http-error.js';

describe('HttpError', () => {
describe('message', () => {
Expand Down Expand Up @@ -33,11 +33,11 @@ describe('HttpError', () => {
]);
});
it('expands reason at output stage', () => {
const reason = new Error('test');
const cause = new Error('test');

expect(dueLog({ on: 'out', line: [new HttpError(500, { reason })] }).line).toEqual([
expect(dueLog({ on: 'out', line: [new HttpError(500, { cause })] }).line).toEqual([
'500',
reason,
cause,
]);
});
});
Expand Down
60 changes: 31 additions & 29 deletions src/http/http-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,45 @@ import type { DueLog, Loggable } from '@proc7ts/logger';
*/
export class HttpError extends Error implements Loggable {

readonly #statusCode: number;
readonly #statusMessage?: string | undefined;
readonly #details?: string | undefined;

/**
* HTTP status message.
* Constructs HTTP status error.
*
* @param statusCode - HTTP status code.
* @param options - HTTP error options.
*/
readonly statusMessage?: string | undefined;
constructor(statusCode: number, options: HttpError.Options = {}) {
super(httpErrorMessage(statusCode, options), options);
this.name = 'HttpError';
this.#statusCode = statusCode;
this.#statusMessage = options.statusMessage;
this.#details = options.details;
}

/**
* Error details.
*
* This will be displayed on error page in addition to error code.
* HTTP status code.
*/
readonly details?: string | undefined;
get statusCode(): number {
return this.#statusCode;
}

/**
* Arbitrary error reason.
*
* This is another error typically.
* HTTP status message.
*/
readonly reason?: unknown | undefined;
get statusMessage(): string | undefined {
return this.#statusMessage;
}

/**
* Constructs HTTP status error.
* Error details.
*
* @param statusCode - HTTP status code.
* @param options - HTTP error options.
* This will be displayed on error page in addition to error code.
*/
constructor(readonly statusCode: number, options: HttpError.Options = {}) {
super(httpErrorMessage(statusCode, options));
this.statusMessage = options.statusMessage;
this.details = options.details;
this.reason = options.reason;
get details(): string | undefined {
return this.#details;
}

/**
Expand All @@ -56,13 +65,13 @@ export class HttpError extends Error implements Loggable {
}

const report: unknown[] = [this.message];
const { details, reason } = this;
const { details, cause } = this;

if (details) {
report.push(details);
}
if (reason) {
report.push(reason);
if (cause) {
report.push(cause);
}

return report;
Expand All @@ -84,7 +93,7 @@ export namespace HttpError {
/**
* Options for {@link HttpError HTTP error} construction.
*/
export interface Options {
export interface Options extends ErrorOptions {
/**
* HTTP status message.
*/
Expand All @@ -103,12 +112,5 @@ export namespace HttpError {
* This will be displayed on error page in addition to error code.
*/
readonly details?: string | undefined;

/**
* Arbitrary error reason.
*
* This is another error typically.
*/
readonly reason?: unknown | undefined;
}
}
4 changes: 2 additions & 2 deletions src/http/http-listener.impl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IncomingMessage, ServerResponse } from 'node:http';
import type { HttpConfig } from './http-config';
import type { HttpMeans } from './http.means';
import type { HttpConfig } from './http-config.js';
import type { HttpMeans } from './http.means.js';

/**
* @internal
Expand Down
Loading

0 comments on commit 550fef8

Please sign in to comment.