Make the .s3instance , .log, and .S3 properties private.
Give it a proper name.
Create objects from your stamp.
Shorter API
Here is the same FileStore stamp but written in a more concise way.
The reusable HasLog stamp can be implemented in the following way.
Using the stamp
Use your stamp ad-hoc.
Or preconfigure it.
If you want to silence the shameful fact that you are collecting cat gifs then here is how you disable log. Just overwrite the log property with a silent one.
Alternatively, you can have a generic silent logger stamp. Compose with it to override the HasLog.
The new keyword also works with any stamp.
Another way to create an object is to use .create() static method.
Mocking I/O in unit tests
Replacing actual S3 with a fake one.
Basic API
Head to the Basics page to view more API documentation. However, by now you already know all you need.
module.exports = require('@stamp/it')({
init(_, { stamp }) {
// this will reuse the stamp name "FileStore" we set above
this.log = require('bunyan').createLogger({ name: stamp.name })
}
})
async function uploadTo(req, res) {
const fileStore = FileStore({ bucket: req.params.bucket }) // create instance
await fileStore.upload({ fileName: req.query.file, stream: req }) // use the method of the stamp
res.sendStatus(201)
}
const CatGifStore = FileStore.setDefaultBucket('cat-gifs') // pre-configuring the bucket name
const catGifStore = CatGifStore() // create an instance of the store
await catGifStore.upload({ fileName: 'cat.gif', stream: readableStream })