-
Notifications
You must be signed in to change notification settings - Fork 885
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
Add TS types #913
Add TS types #913
Conversation
If nobody minds, I can also add types to https://github.com/pinojs/pino-std-serializers so that there are no third-party types used altogether (other than official Node ones). update: done. |
@@ -3,9 +3,12 @@ | |||
"version": "6.6.1", | |||
"description": "super fast, all natural json logger", | |||
"main": "pino.js", | |||
"type": "commonjs", | |||
"types": "pino.d.ts", | |||
"browser": "./browser.js", | |||
"files": [ |
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.
@mcollina and @davidmarkclements I thought we removed this difficult to maintain property from the package.json
?
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.
fastify
uses .npmignore
instead. If that is the way, I can use same approach here as well.
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 didn't remember we used this here even. Let's not change it in this PR.
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.
Agreed. Just asking because it got added in pino-std-serializers
with this types stuff.
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.
@jsumners pino-std-serializer currently bundles all the garbage such as travis config, which felt not ideal. I can remove it from there if you feel strongly about it.
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.
Looks like we actually settled on files
🤦♂️
@@ -3,9 +3,12 @@ | |||
"version": "6.6.1", | |||
"description": "super fast, all natural json logger", | |||
"main": "pino.js", | |||
"type": "commonjs", | |||
"types": "pino.d.ts", | |||
"browser": "./browser.js", | |||
"files": [ |
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 didn't remember we used this here even. Let's not change it in this PR.
pino.d.ts
Outdated
} | ||
} | ||
|
||
declare class SonicBoom extends EventEmitter { |
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 shipped in sonic-boom.
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.
Changed to use it.
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.
Several type and interface definitions are not exported, which can be inconvenient for users. Interfaces need to be exported to support module augmentation, and, in general, exporting all type and interface definitions offers convenience to users because they can more easily use them to declare types in their own code that interoperates with the package.
For example, LevelChangeEventListener
is useful for package users to declare the type of a function which will be passed as a listener.
/** | ||
* Provides functions for serializing objects common to many projects. | ||
*/ | ||
const stdSerializers: { |
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.
Is there a reason to maintain this mapping? The object is assigned directly from the stdSerializers
package, so I think it would be easier to maintain simply as const stdSerializers: typeof pinoStdSerizlizers
.
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.
Done
pino.d.ts
Outdated
type SerializerFn = (value: any) => any; | ||
type WriteFn = (o: object) => void; | ||
|
||
interface LogDescriptor { |
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.
Is this used? I don't see any references to it, and it is not exported.
Thanks for this work! Unfortunately the default-exported types in
|
From the amount of feedbacks we are getting from just changing sonic-boom types, I think we must do this as a semver-major change. |
I'll revert in sonic-boom as well. Let's treat them all as semver-major. |
Please take a look at the latest version, I exported the namespace, now these definition can be reached from within the namespace. Alternatively I think we can try to get rid of namespace altogether and do it more similarly to how fastify does it - but that would be a way more intrusive and breaking change. |
pino.js
Outdated
* - `import { P } from 'pino'` | ||
* - `import pino from 'pino'` | ||
*/ | ||
pino.P = pino |
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 P
and not pino
?
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.
to preserve naming of original @types/pino
, but you are right, we don't really need to do that.
pino.d.ts
Outdated
import { EventEmitter } from 'events'; | ||
import * as pinoStdSerializers from 'pino-std-serializers'; | ||
|
||
export default P |
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.
It would be much better to use Fastify approach and have the "infamous tripet" exported in JS and here a default + named export without using namespace at all. It is the only known way we have to support all of the tsconfigurations, faux modules, bundlers and so on ( :( )
@kibertoad I think we should go with the fastify apporach even if it takes a longer to be merged. It is surely more stable and better done. |
@fox1t You are right. Since we are going for semver major either way, might as well use the opportunity to refine the API. |
After the current incident, it seems that a significant amount of pino users are served by the types in |
Agreed. And increasing the issue load around here is not helpful. |
Yea, there are plenty of devs using pino types. I agree we should not break them. If we don't see any benefit from porting them in this package and allign them to fastify ones (triplet and so on) there is no point in breaking anything. |
@mcollina There are multiple directions where we can go, though. If we want to avoid breaking changes, we can, there is nothing stopping us from adopting existing DefinitelyTyped typings verbatim so that there is zero chance to break anything for anyone. And we'll still get a better workflow and more agility for how we address future challenges - when there will be pino 7 on the horizon, we could seize the opportunity and implement breaking changes then, cleaning up the types and making them more robust. |
is anyone still wanting to maintain types in Pino? If not I'll close this in a week or so. |
@davidmarkclements Yes. Is next semver major coming up? Can we get back to getting this merged? |
@mcollina Some changes leaked from |
package.json
Outdated
"winston": "^3.3.3" | ||
}, | ||
"dependencies": { | ||
"fast-redact": "^3.0.0", | ||
"fast-safe-stringify": "^2.0.7", | ||
"pino-std-serializers": "^3.1.0", | ||
"pino-std-serializers": "kibertoad/pino-std-serializers#feat/types", |
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 will be replaced with released version after it is available
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 was released
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.
Separate PR, note that multistream landed.
pino.d.ts
Outdated
* @param [fileDescriptor]: File path or numerical file descriptor, by default 1 | ||
* @returns A Sonic-Boom stream to be used as destination for the pino function | ||
*/ | ||
function extreme(fileDescriptor?: string | number): SonicBoom; |
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 is deprecated
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.
Removed everything referring to extreme mode
package.json
Outdated
@@ -76,7 +81,7 @@ | |||
"import-fresh": "^3.2.1", | |||
"log": "^6.0.0", | |||
"loglevel": "^1.6.7", | |||
"pino-pretty": "^4.1.0", | |||
"pino-pretty": "^4.8.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.
this should be 5.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.
Fixed
package.json
Outdated
"winston": "^3.3.3" | ||
}, | ||
"dependencies": { | ||
"fast-redact": "^3.0.0", | ||
"fast-safe-stringify": "^2.0.7", | ||
"pino-std-serializers": "^3.1.0", | ||
"pino-std-serializers": "kibertoad/pino-std-serializers#feat/types", |
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 was released
res: pino.stdSerializers.res, | ||
err: pino.stdSerializers.err, | ||
}, | ||
}); |
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.
Does this use tabs for indentation? Maybe can we have this conform to the rest?
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.
It already uses spaces.
Will update the PR tomorrow. |
Remove references to deprecated "extreme mode" functionality
@mcollina Ready for re-review! |
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.
Multistream is missing
package.json
Outdated
@@ -19,8 +22,9 @@ | |||
"docs": "docsify serve", | |||
"browser-test": "airtap --local 8080 test/browser*test.js", | |||
"lint": "eslint .", | |||
"test": "npm run lint && tap --100 test/*test.js test/*/*test.js", | |||
"test": "npm run test:types && npm run lint && tap --100 test/*test.js test/*/*test.js", |
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 you move the type tests to the end?
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.
done
Move type tests to the end
@mcollina Typed multistream to the best of my ability based on API docs, could you please check if typing makes sense? |
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.
lgtm
@@ -0,0 +1,876 @@ | |||
// Type definitions for pino 6.3 | |||
// Project: https://github.com/pinojs/pino.git, http://getpino.io |
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 think this header should be changed/updated.
@kibertoad I've invited you to this org to make sure you can help maintain these going forward. |
This reverts commit dfca887.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
fixes #910
Note that there is definitely room for improvements test-wise and some explicit
tsd
assertions definitely would be helpful, but I think everything else can be done incrementally - this provides a usable foundation.