refactor(lib): organizational changes to the package structure - #312
refactor(lib): organizational changes to the package structure#312nhankyjangchan wants to merge 1 commit into
Conversation
- extracting symbols into lib/symbols.js - refactoring to improve the readability of lib/getPluginName.js - extracting metadata normalization and validation logic into lib/prepareMetadata.js - adding JSDoc annotations above package functions - added FastifyPluginFunction type - added new section of test to verify correct metadata normalization Signed-off-by: nhankyjangchan <dev.schuchkin.timur@gmail.com>
Fdawgs
left a comment
There was a problem hiding this comment.
Whilst i'm sure some of this is reasonable, squashing it all into an AI-generated commit and PR isn't.
I only used AI to draft the PR text because I didn't want to embarrass myself with my English skills. I’m typing this message using a translator right now, so I hope it’s reasonably readable. Does the code I submitted also look like "AI slop"? If you’re willing and able, could you point out my mistakes? I didn't use AI to write the code, but the fact that you thought I did suggests the quality is quite poor. I’d really appreciate any criticism—thank you! (As I mentioned earlier, this text was written using a translator. I really hope this doesn't lead to any awkward misunderstandings.) |
Work performed
Symbol.for('skip-override'),Symbol.for('fastify.display-name')andSymbol.for('plugin-meta')intolib/symbols.js, and re-export them from the entry point asfastifyPlugin.symbols.lib/prepareMetadata.js.lib/getPluginName.jsandlib/toCamelCase.js.FastifyPluginFunctiontype alias that covers both async and callback plugin signatures.null,array,string) instead of a genericobjectmessage.plugin(fn, ...)fromoptionstometadata, which better describes what it actually is: plugin metadata (name, fastify version, encapsulate), not generic options.For what?
kSkipOverride,kDisplayNameandkPluginMetaare currently private toindex.js, so consumers have to writeSymbol.for('plugin-meta')and hope the string is correct —Symbol.fornever throws on a typo. Exporting them asfastifyPlugin.symbolsturns that string into an API.index.jsnext to naming, symbols and camelCase conversion. Extracting them intolib/prepareMetadata.jsmakes the rules testable in isolation and shrinksplugin()to what it actually does.'The options object should be an object'does not say what the caller passed. The new message reports the actual type (null,array,string, …), which is what you need when a plugin fails to register.plugin(fn, ...)is not generic options — it is plugin metadata (name,fastify,encapsulate).metadatamatches both the content and the existingplugin-metasymbol.FastifyPluginFunctionalias covering async and callback signatures make the public API self-describing.Verified before pull request
npm run lint:fix && npm run lint && npm run testpasses