hogashi.*

日記から何から

pt-query-digestのJSON出力の型書いた

 型を公開する練習として、 pt-query-digest *1--output json したときに出力される JSON の型を書いてみた。 JSON.parse() したものにつける型を想定している。

github.com

 index.d.ts とかを書いて、 package.jsontypes として指定しておくと完成らしい。 npm に公開しなくても、とりあえず yarn add -D https://github.com/hogashi/types-pt-query-digest-output-json とかやるとインストールできるのでさっと作ってみるには気楽。

www.typescriptlang.org

 値としては数値なはずだけどプロパティによって number だったり string だったりすることがあってちょっと難しい。ちゃんとコード読んでるわけでもないので、意外と null になるじゃんみたいなものもあったりしそう。あと pt-query-digest の v3.0 時点でもまだ開発中ということなので急に変わったりもしそうではある。

json output was introduced in 2.2.1 and is still in development, so the data structure may change in future versions.

https://www.percona.com/doc/percona-toolkit/3.0/pt-query-digest.html#options&:~:text=json%20output%20was%20introduced%20in%202.2.1%20and%20is%20still%20in%20development