Skip to content
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

Merged
merged 12 commits into from
May 28, 2021
Merged

Add TS types #913

merged 12 commits into from
May 28, 2021

Conversation

kibertoad
Copy link
Contributor

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.

@kibertoad
Copy link
Contributor Author

@jsumners I would assume that me and @fox1t would need maintainer permissions if we move forward with the "at least 2 dedicated maintainers for TS" plan with 30 days response SLA. Considering that both of us are already members of fastify org, hopefully this shouldn't be a controversial request.

@kibertoad
Copy link
Contributor Author

kibertoad commented Sep 19, 2020

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.
And if sonic-book one is merged, I'll remove duplicate types from this PR.

@@ -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": [
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 🤦‍♂️

#136

@@ -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": [
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use it.

Copy link

@jstewmon jstewmon left a 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: {

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.

Copy link
Contributor Author

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 {

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.

@72636c
Copy link

72636c commented Sep 23, 2020

Thanks for this work! Unfortunately the default-exported types in [email protected] are now incompatible with @types/pino. Would it be worth patching @types/pino and @types/sonic-boom to switch to the default export while this is in flux?

node_modules/@types/pino/index.d.ts(194,122): error TS2709: Cannot use namespace 'SonicBoom' as a type.
node_modules/@types/pino/index.d.ts(202,57): error TS2709: Cannot use namespace 'SonicBoom' as a type.

@mcollina
Copy link
Member

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.

@mcollina mcollina added the v7 label Sep 23, 2020
@mcollina
Copy link
Member

I'll revert in sonic-boom as well. Let's treat them all as semver-major.

@kibertoad
Copy link
Contributor Author

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.

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
Copy link

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?

Copy link
Contributor Author

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
Copy link

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 ( :( )

@fox1t
Copy link

fox1t commented Sep 23, 2020

@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.

@kibertoad
Copy link
Contributor Author

@fox1t You are right. Since we are going for semver major either way, might as well use the opportunity to refine the API.

@mcollina
Copy link
Member

After the current incident, it seems that a significant amount of pino users are served by the types in @types/pino. Moving them to these will break them badly. I'll need to let this bounce a bit in my head before making a call. By adding types to pino, we will be adding significant more issue traffic that this project currently gets. Logging should be "boring" and work well.

@jsumners
Copy link
Member

By adding types to pino, we will be adding significant more issue traffic that this project currently gets. Logging should be "boring" and work well.

Agreed. And increasing the issue load around here is not helpful.

@fox1t
Copy link

fox1t commented Sep 23, 2020

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.

@kibertoad
Copy link
Contributor Author

@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.
And obviously there are two sides to "lots of people use @types/pino" as well - it means that any improvements that we make will have greater impact as well, and I am very confident that whatever challenges people may encounter with types, we would be able to address them faster and better than what is currently the case with DefinitelyTyped ad-hoc maintainership.

@davidmarkclements
Copy link
Member

is anyone still wanting to maintain types in Pino? If not I'll close this in a week or so.

@kibertoad
Copy link
Contributor Author

@davidmarkclements Yes. Is next semver major coming up? Can we get back to getting this merged?

@mcollina mcollina added this to the v7.0.0 milestone May 18, 2021
@kibertoad kibertoad changed the base branch from master to next May 22, 2021 11:00
@kibertoad
Copy link
Contributor Author

@mcollina Some changes leaked from master that are not yet in next into this PR. Can I create a PR syncing next with master to simplify things?

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",
Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was released

@mcollina
Copy link
Member

@mcollina Some changes leaked from master that are not yet in next into this PR. Can I create a PR syncing next with master to simplify things?

This should be fixed now.

Note that there is also #1003 that would need typings.

@kibertoad
Copy link
Contributor Author

@mcollina Sure. Would you like these types added in this PR, or should I wait until #1003 lands and create separate PR then?

Copy link
Member

@mcollina mcollina left a 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is deprecated

Copy link
Contributor Author

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",
Copy link
Member

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

Copy link
Contributor Author

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",
Copy link
Member

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,
},
});
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already uses spaces.

@kibertoad
Copy link
Contributor Author

kibertoad commented May 26, 2021

Will update the PR tomorrow.

Remove references to deprecated "extreme mode" functionality
@kibertoad
Copy link
Contributor Author

@mcollina Ready for re-review!

Copy link
Member

@mcollina mcollina left a 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",
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kibertoad
Copy link
Contributor Author

@mcollina Typed multistream to the best of my ability based on API docs, could you please check if typing makes sense?

Copy link
Member

@mcollina mcollina left a 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
Copy link
Member

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.

@mcollina mcollina merged commit dfca887 into pinojs:next May 28, 2021
@mcollina
Copy link
Member

@kibertoad I've invited you to this org to make sure you can help maintain these going forward.

davidmarkclements added a commit that referenced this pull request May 31, 2021
This was referenced May 31, 2021
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: bundle type definitions in Pino itself
7 participants