From 7f2b9fabc594c29c354e5caeb607765c1445d8b1 Mon Sep 17 00:00:00 2001 From: Ruslan Lopatin Date: Sun, 17 Sep 2023 14:34:22 +0700 Subject: [PATCH 1/2] ES2022 --- package.json | 15 ++++++------ src/error-logging.handler.impl.ts | 6 ++--- src/index.ts | 5 ---- src/logging.spec.ts | 39 ++++++++++++++++--------------- src/logging.ts | 10 ++++---- src/mod.ts | 4 ++++ src/request.log.impl.ts | 2 +- tsconfig.json | 6 +---- typedoc.json | 5 ++-- 9 files changed, 45 insertions(+), 47 deletions(-) delete mode 100644 src/index.ts create mode 100644 src/mod.ts diff --git a/package.json b/package.json index 99806fa..1095f9d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hatsy/log-z-request", - "version": "3.0.1", + "version": "4.0.0-pre.0", "description": "Hatsy request logger", "keywords": [ "http-middleware", @@ -24,18 +24,19 @@ }, "sideEffects": false, "dependencies": { - "@proc7ts/logger": "^1.3.2", - "@proc7ts/primitives": "^3.0.2" + "@proc7ts/logger": "^2.0.0", + "@proc7ts/primitives": "^4.0.1" }, "peerDependencies": { - "@hatsy/hatsy": "^2.5.3", - "@run-z/log-z": "^2.2.1" + "@hatsy/hatsy": "^3.0.0-pre.0", + "@run-z/log-z": "^3.0.0" }, "devDependencies": { - "@hatsy/hatsy": "^2.5.3", + "@hatsy/hatsy": "^3.0.0-pre.0", "@jest/globals": "^29.7.0", + "@proc7ts/async": "^2.1.0", "@run-z/eslint-config": "^3.5.0", - "@run-z/log-z": "^2.2.1", + "@run-z/log-z": "^3.0.0", "@run-z/prettier-config": "^2.0.0", "@run-z/project-config": "^0.20.0", "@swc/core": "^1.3.85", diff --git a/src/error-logging.handler.impl.ts b/src/error-logging.handler.impl.ts index 56f8f35..0d4f8fe 100644 --- a/src/error-logging.handler.impl.ts +++ b/src/error-logging.handler.impl.ts @@ -1,8 +1,8 @@ -import type { ErrorMeans, LoggerMeans, RequestContext, RequestHandler } from '@hatsy/hatsy/core'; -import { requestExtension } from '@hatsy/hatsy/core'; +import type { ErrorMeans, LoggerMeans, RequestContext, RequestHandler } from '@hatsy/hatsy/core.js'; +import { requestExtension } from '@hatsy/hatsy/core.js'; import type { ZLogger } from '@run-z/log-z'; import { zlogDetails } from '@run-z/log-z'; -import type { RequestZLogConfig } from './logging'; +import type { RequestZLogConfig } from './logging.js'; /** * @internal diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 6284138..0000000 --- a/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @packageDocumentation - * @module @hatsy/log-z-request - */ -export * from './logging'; diff --git a/src/logging.spec.ts b/src/logging.spec.ts index c5ff70b..2887e22 100644 --- a/src/logging.spec.ts +++ b/src/logging.spec.ts @@ -1,13 +1,14 @@ -import type { RequestContext, RequestProcessor } from '@hatsy/hatsy/core'; -import { LoggerMeans, RequestHandler, requestProcessor } from '@hatsy/hatsy/core'; +import type { RequestContext, RequestProcessor } from '@hatsy/hatsy/core.js'; +import { LoggerMeans, RequestHandler, requestProcessor } from '@hatsy/hatsy/core.js'; import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'; +import { PromiseResolver } from '@proc7ts/async'; import { consoleLogger, processingLogger } from '@proc7ts/logger'; -import { asis, newPromiseResolver, noop, valueProvider } from '@proc7ts/primitives'; -import type { ZLogger, ZLogRecorder } from '@run-z/log-z'; -import { logZToLogger, zlogDetails, zlogINFO, ZLogLevel } from '@run-z/log-z'; +import { asis, noop, valueProvider } from '@proc7ts/primitives'; +import type { ZLogRecorder, ZLogger } from '@run-z/log-z'; +import { ZLogLevel, logZToLogger, zlogDetails, zlogINFO } from '@run-z/log-z'; import type { Mock } from 'jest-mock'; -import type { RequestZLogConfig } from './logging'; -import { ZLogging } from './logging'; +import type { RequestZLogConfig } from './logging.js'; +import { ZLogging } from './logging.js'; describe('ZLogging', () => { let infoSpy: Mock<(...args: unknown[]) => void>; @@ -23,19 +24,19 @@ describe('ZLogging', () => { }); it('logs nothing until error logged', async () => { - const whenLogged1 = newPromiseResolver(); - const whenLogged2 = newPromiseResolver(); + const whenLogged1 = new PromiseResolver(); + const whenLogged2 = new PromiseResolver(); const handler: RequestHandler> = async ({ log }) => { log.info('Info'); whenLogged1.resolve(log.whenLogged()); - await whenLogged2.promise(); + await whenLogged2.whenDone(); log.error('Error'); await log.whenLogged(); }; const promise = processor(handler)({}); - await whenLogged1.promise(); + await whenLogged1.whenDone(); expect(infoSpy).not.toHaveBeenCalled(); @@ -46,19 +47,19 @@ describe('ZLogging', () => { expect(errorSpy).toHaveBeenCalledWith('Error'); }); it('allows to trigger immediate logging', async () => { - const whenLogged1 = newPromiseResolver(); - const whenLogged2 = newPromiseResolver(); + const whenLogged1 = new PromiseResolver(); + const whenLogged2 = new PromiseResolver(); const handler: RequestHandler> = async ({ log }) => { log.info('Deferred'); whenLogged1.resolve(log.whenLogged()); - await whenLogged2.promise(); + await whenLogged2.whenDone(); log.info('Immediate', zlogDetails({ immediate: true })); await log.whenLogged(); }; const promise = processor(handler)({}); - await whenLogged1.promise(); + await whenLogged1.whenDone(); expect(infoSpy).not.toHaveBeenCalled(); @@ -69,17 +70,17 @@ describe('ZLogging', () => { expect(infoSpy).toHaveBeenCalledWith('Immediate'); }); it('triggers immediate logging on error', async () => { - const whenLogged = newPromiseResolver(); - const whenError = newPromiseResolver(); + const whenLogged = new PromiseResolver(); + const whenError = new PromiseResolver(); const handler: RequestHandler> = async ({ log }) => { log.info('Deferred'); whenLogged.resolve(log.whenLogged()); - await whenError.promise(); + await whenError.whenDone(); }; const promise = processor(handler, { by: logZToLogger(processingLogger(consoleLogger)) })({}); - await whenLogged.promise(); + await whenLogged.whenDone(); expect(infoSpy).not.toHaveBeenCalled(); diff --git a/src/logging.ts b/src/logging.ts index 5ef6c18..f7c3326 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -1,9 +1,9 @@ -import type { ErrorMeans, LoggerMeans, RequestContext, RequestHandler } from '@hatsy/hatsy/core'; -import { RequestCapability, requestExtension } from '@hatsy/hatsy/core'; -import type { ZLogger, ZLogLevel, ZLogRecorder } from '@run-z/log-z'; +import type { ErrorMeans, LoggerMeans, RequestContext, RequestHandler } from '@hatsy/hatsy/core.js'; +import { RequestCapability, requestExtension } from '@hatsy/hatsy/core.js'; +import type { ZLogLevel, ZLogRecorder, ZLogger } from '@run-z/log-z'; import { logZ, logZAtopOf, logZBy } from '@run-z/log-z'; -import { errorLoggingHandler } from './error-logging.handler.impl'; -import { logZRequest } from './request.log.impl'; +import { errorLoggingHandler } from './error-logging.handler.impl.js'; +import { logZRequest } from './request.log.impl.js'; /** * Logger configuration. diff --git a/src/mod.ts b/src/mod.ts new file mode 100644 index 0000000..ab30eae --- /dev/null +++ b/src/mod.ts @@ -0,0 +1,4 @@ +/** + * @module @hatsy/log-z-request + */ +export * from './logging.js'; diff --git a/src/request.log.impl.ts b/src/request.log.impl.ts index 42fdac2..2098d15 100644 --- a/src/request.log.impl.ts +++ b/src/request.log.impl.ts @@ -1,6 +1,6 @@ import type { ZLogMessage, ZLogRecorder } from '@run-z/log-z'; import { ZLogLevel } from '@run-z/log-z'; -import type { RequestZLogConfig } from './logging'; +import type { RequestZLogConfig } from './logging.js'; /** * @internal diff --git a/tsconfig.json b/tsconfig.json index d4db896..78ac30f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,7 @@ { "extends": "@run-z/project-config/tsconfig.lib.json", "compilerOptions": { - "lib": ["ES2019"], - "module": "ES2015", - "moduleResolution": "Node", - "outDir": "target/js", - "target": "ES2019" + "outDir": "target/js" }, "include": ["src/**/*"] } diff --git a/typedoc.json b/typedoc.json index 97cb45e..7c85242 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,5 +1,6 @@ { - "entryPoints": ["src/index.ts"], + "entryPoints": ["src/mod.ts"], "name": "Hatsy request logger", - "out": "./target/typedoc" + "out": "./target/typedoc", + "sort": ["static-first", "visibility", "enum-value-ascending", "alphabetical", "kind"] } From e92957be44a5e939eb53720fbbd2e86b56a4adf8 Mon Sep 17 00:00:00 2001 From: Ruslan Lopatin Date: Sun, 17 Sep 2023 15:10:35 +0700 Subject: [PATCH 2/2] Hatsy v3 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1095f9d..9605eec 100644 --- a/package.json +++ b/package.json @@ -28,11 +28,11 @@ "@proc7ts/primitives": "^4.0.1" }, "peerDependencies": { - "@hatsy/hatsy": "^3.0.0-pre.0", + "@hatsy/hatsy": "^3.0.0", "@run-z/log-z": "^3.0.0" }, "devDependencies": { - "@hatsy/hatsy": "^3.0.0-pre.0", + "@hatsy/hatsy": "^3.0.0", "@jest/globals": "^29.7.0", "@proc7ts/async": "^2.1.0", "@run-z/eslint-config": "^3.5.0",