New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: type regression on fastify #1246
Merged
kibertoad
merged 3 commits into
pinojs:master
from
climba03003:fix--type-regression-on-fastify
Dec 1, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
|
||
import type { EventEmitter } from "events"; | ||
// @ts-ignore -- gracefully falls back to `any` if not installed | ||
import type { PrettyOptions } from "pino-pretty"; | ||
import type { PrettyOptions as PinoPrettyOptions } from "pino-pretty"; | ||
import type { SonicBoom, SonicBoomOpts } from "sonic-boom"; | ||
import type { WorkerOptions } from "worker_threads"; | ||
|
||
|
@@ -27,9 +27,6 @@ import * as pinoStdSerializers from "pino-std-serializers"; | |
|
||
//// Non-exported types and interfaces | ||
|
||
type SerializerFn = (value: any) => any; | ||
type WriteFn = (o: object) => void; | ||
|
||
// ToDo https://github.com/pinojs/thread-stream/issues/24 | ||
type ThreadStream = any | ||
|
||
|
@@ -42,90 +39,6 @@ interface redactOptions { | |
remove?: boolean; | ||
} | ||
|
||
interface BaseLogger { | ||
/** | ||
* Set this property to the desired logging level. In order of priority, available levels are: | ||
* | ||
* - 'fatal' | ||
* - 'error' | ||
* - 'warn' | ||
* - 'info' | ||
* - 'debug' | ||
* - 'trace' | ||
* | ||
* The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`, | ||
* and `'info'` logs will be enabled. | ||
* | ||
* You can pass `'silent'` to disable logging. | ||
*/ | ||
level: pino.LevelWithSilent | string; | ||
|
||
/** | ||
* Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
fatal: pino.LogFn; | ||
/** | ||
* Log at `'error'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
error: pino.LogFn; | ||
/** | ||
* Log at `'warn'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
warn: pino.LogFn; | ||
/** | ||
* Log at `'info'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
info: pino.LogFn; | ||
/** | ||
* Log at `'debug'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
debug: pino.LogFn; | ||
/** | ||
* Log at `'trace'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
trace: pino.LogFn; | ||
/** | ||
* Noop function. | ||
*/ | ||
silent: pino.LogFn; | ||
} | ||
|
||
interface LoggerExtras extends EventEmitter { | ||
/** | ||
* Exposes the Pino package version. Also available on the exported pino function. | ||
|
@@ -192,10 +105,98 @@ interface LoggerExtras extends EventEmitter { | |
|
||
declare namespace pino { | ||
//// Exported types and interfaces | ||
|
||
interface BaseLogger { | ||
/** | ||
* Set this property to the desired logging level. In order of priority, available levels are: | ||
* | ||
* - 'fatal' | ||
* - 'error' | ||
* - 'warn' | ||
* - 'info' | ||
* - 'debug' | ||
* - 'trace' | ||
* | ||
* The logging level is a __minimum__ level. For instance if `logger.level` is `'info'` then all `'fatal'`, `'error'`, `'warn'`, | ||
* and `'info'` logs will be enabled. | ||
* | ||
* You can pass `'silent'` to disable logging. | ||
*/ | ||
level: pino.LevelWithSilent | string; | ||
|
||
/** | ||
* Log at `'fatal'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
fatal: pino.LogFn; | ||
/** | ||
* Log at `'error'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
error: pino.LogFn; | ||
/** | ||
* Log at `'warn'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
warn: pino.LogFn; | ||
/** | ||
* Log at `'info'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
info: pino.LogFn; | ||
/** | ||
* Log at `'debug'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
debug: pino.LogFn; | ||
/** | ||
* Log at `'trace'` level the given msg. If the first argument is an object, all its properties will be included in the JSON line. | ||
* If more args follows `msg`, these will be used to format `msg` using `util.format`. | ||
* | ||
* @typeParam T: the interface of the object being serialized. Default is object. | ||
* @param obj: object to be serialized | ||
* @param msg: the log message to write | ||
* @param ...args: format string values when `msg` is a format string | ||
*/ | ||
trace: pino.LogFn; | ||
/** | ||
* Noop function. | ||
*/ | ||
silent: pino.LogFn; | ||
} | ||
|
||
type Bindings = Record<string, any>; | ||
|
||
type Level = "fatal" | "error" | "warn" | "info" | "debug" | "trace"; | ||
type LevelWithSilent = pino.Level | "silent"; | ||
|
||
type SerializerFn = (value: any) => any; | ||
type WriteFn = (o: object) => void; | ||
|
||
type LevelChangeEventListener = ( | ||
lvl: LevelWithSilent | string, | ||
|
@@ -278,6 +279,8 @@ declare namespace pino { | |
(msg: string, ...args: any[]): void; | ||
} | ||
|
||
interface PrettyOptions extends PinoPrettyOptions {} | ||
|
||
interface LoggerOptions { | ||
transport?: TransportSingleOptions | TransportMultiOptions | TransportPipelineOptions | ||
/** | ||
|
@@ -756,10 +759,13 @@ export type LevelChangeEventListener = pino.LevelChangeEventListener; | |
export type LogDescriptor = pino.LogDescriptor; | ||
export type Logger = pino.Logger; | ||
export type SerializedError = pino.SerializedError; | ||
export type SerializerFn = pino.SerializerFn; | ||
export type SerializedRequest = pino.SerializedRequest; | ||
export type SerializedResponse = pino.SerializedResponse; | ||
export type WriteFn = pino.WriteFn; | ||
|
||
// Interfaces | ||
export interface BaseLogger extends pino.BaseLogger {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kibertoad I think here is what you mention? |
||
export interface ChildLoggerOptions extends pino.ChildLoggerOptions {} | ||
export interface DestinationStream extends pino.DestinationStream {} | ||
export interface LevelMapping extends pino.LevelMapping {} | ||
|
@@ -768,6 +774,7 @@ export interface LogFn extends pino.LogFn {} | |
export interface LoggerOptions extends pino.LoggerOptions {} | ||
export interface MultiStreamOptions extends pino.MultiStreamOptions {} | ||
export interface MultiStreamRes extends pino.MultiStreamRes {} | ||
export interface PrettyOptions extends pino.PrettyOptions {} | ||
export interface StreamEntry extends pino.StreamEntry {} | ||
export interface TransportBaseOptions extends pino.TransportBaseOptions {} | ||
export interface TransportMultiOptions extends pino.TransportMultiOptions {} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why move it from top level into a namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it never export outside and nobody can use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we export it instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the old way of import is missing this exportation.
e.g.
Top-level export is mapped on line 768
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally want to move away from relying on namespace. See #1193 (comment)
I agree that types should be fixed if we lost the way to do something we could do before, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it should move away from namespace, but the current version is too late to do it.
Current version should support the import syntax that can be used in
7.0.0
.The complete removal should be happen in next major
8.0.0
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that we can't remove it yet, but can we at least already provide alternative for people who want to do direct named imports? That was the gist of #1193 and it seems like the right direction.
Other than that, PR LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mention on line 768, it has the top-level export mapped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR already provide the type import for below format.
If anything is missing, please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for clarification!