Skip to content

Commit 3b6489e

Browse files
vladimyrjb55
authored andcommitted
Generate docs from JSDoc
- adding JSDoc annotations for generating documentation using documentation.js - adding `store#remove` example to readme
1 parent 1f6606a commit 3b6489e

File tree

3 files changed

+174
-17
lines changed

3 files changed

+174
-17
lines changed

index.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ var debug = require('debug')('s3-blob-store');
55
var mime = require('mime-types');
66
var uploadStream = require('s3-stream-upload');
77

8+
/**
9+
* Create S3 blob store
10+
* @constructor
11+
* @param {Object} opts
12+
* @param {S3} opts.client S3 client
13+
* @param {String} opts.bucket bucket name
14+
*/
815
function S3BlobStore (opts) {
916
if (!(this instanceof S3BlobStore)) return new S3BlobStore(opts);
1017
opts = opts || {};
@@ -16,6 +23,12 @@ function S3BlobStore (opts) {
1623
this.s3 = opts.client;
1724
}
1825

26+
/**
27+
* Create read stream
28+
* @param {ReadStreamOptions|String} opts options or object key
29+
* @returns {ReadableStream}
30+
* readable stream of data for the file in your bucket whose key matches
31+
*/
1932
S3BlobStore.prototype.createReadStream = function (opts) {
2033
if (typeof opts === 'string') opts = { key: opts };
2134
var config = { client: this.s3, params: this.downloadParams(opts) };
@@ -55,6 +68,12 @@ S3BlobStore.prototype.downloadParams = function (opts) {
5568
return params;
5669
};
5770

71+
/**
72+
* Create write stream
73+
* @param {Options<WriteParams>|String} opts options or object key
74+
* @param {function(Error, { key: String })} done callback
75+
* @returns {WritableStream} writable stream that you can pipe data to
76+
*/
5877
S3BlobStore.prototype.createWriteStream = function (opts, s3opts, done) {
5978
if (typeof s3opts === 'function') {
6079
done = s3opts;
@@ -74,12 +93,22 @@ S3BlobStore.prototype.createWriteStream = function (opts, s3opts, done) {
7493
return out;
7594
};
7695

96+
/**
97+
* Remove object from store
98+
* @param {{ key: String }|String} opts options containing object key or just key
99+
* @param {function(Error)} done callback
100+
*/
77101
S3BlobStore.prototype.remove = function (opts, done) {
78102
var key = typeof opts === 'string' ? opts : opts.key;
79103
this.s3.deleteObject({ Bucket: this.bucket, Key: key }, done);
80104
return this;
81105
};
82106

107+
/**
108+
* Check if object exits
109+
* @param {{ key: String }|String} opts options containing object key or just key
110+
* @param {function(Error, Boolean)} done callback
111+
*/
83112
S3BlobStore.prototype.exists = function (opts, done) {
84113
if (typeof opts === 'string') opts = { key: opts };
85114
this.s3.headObject({ Bucket: this.bucket, Key: opts.key }, function (err, res) {
@@ -89,3 +118,43 @@ S3BlobStore.prototype.exists = function (opts, done) {
89118
};
90119

91120
module.exports = S3BlobStore;
121+
122+
/** @typedef {import('stream').Readable} ReadableStream */
123+
/** @typedef {import('stream').Writeable} WriteableStream */
124+
125+
/**
126+
* @typedef {Object} Options
127+
* @property {String} key object key
128+
* @property {String} [name] `key` alias
129+
* @property {String} [filename] `key` alias
130+
* @property {S3Params} [params] additional S3 options
131+
* @template S3Params
132+
*/
133+
134+
/**
135+
* [`Options`](#options) including `s3-stream-download` configuration
136+
* @typedef {Options<ReadParams> & S3StreamDownloaderOptions} ReadStreamOptions
137+
* @name ReadStreamOptions
138+
* @see https://github.com/jb55/s3-download-stream#api
139+
*/
140+
141+
/**
142+
* S3 client
143+
* @typedef {import('aws-sdk').S3} S3
144+
* @name S3
145+
* @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html
146+
*/
147+
148+
/**
149+
* S3 `getObject` params
150+
* @typedef {import('aws-sdk').S3.GetObjectRequest} ReadParams
151+
* @name ReadParams
152+
* @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getObject-property
153+
*/
154+
155+
/**
156+
* S3 `putObject` params
157+
* @typedef {import('aws-sdk').S3.PutObjectRequest} WriteParams
158+
* @name WriteParams
159+
* @see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property
160+
*/

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"index.js"
1919
],
2020
"scripts": {
21+
"docs": "documentation readme index.js --section=API",
2122
"lint": "eslint . --ext .js",
2223
"test": "node test.js | tap-spec"
2324
},
@@ -30,6 +31,7 @@
3031
"devDependencies": {
3132
"abstract-blob-store": "^3.3.2",
3233
"aws-sdk": "^2.0.15",
34+
"documentation": "^12.1.4",
3335
"eslint": "^6.8.0",
3436
"eslint-config-semistandard": "^15.0.0",
3537
"eslint-config-standard": "^14.1.0",

readme.md

Lines changed: 103 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
Amazon S3 [abstract-blob-store](http://npmrepo.com/abstract-blob-store)
44

5-
65
[![blob-store-compatible](https://raw.githubusercontent.com/maxogden/abstract-blob-store/master/badge.png)](https://github.com/maxogden/abstract-blob-store)
76

87
## Installation
@@ -35,6 +34,11 @@ fs.createReadStream('/tmp/somefile.txt')
3534
store.createReadStream({ key: 'somefile.txt' })
3635
.pipe(fs.createWriteStream('/tmp/somefile.txt'));
3736

37+
// remove
38+
store.remove({ key: 'somefile.txt' }, function (err) {
39+
// ...
40+
});
41+
3842
// exists
3943
store.exists({ key: 'somefile.txt' }, function (err, exists) {
4044
// ...
@@ -43,33 +47,115 @@ store.exists({ key: 'somefile.txt' }, function (err, exists) {
4347

4448
## API
4549

46-
### `var s3 = require('s3-blob-store')(options)`
50+
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
51+
52+
#### Table of Contents
53+
54+
- [S3BlobStore](#s3blobstore)
55+
- [Parameters](#parameters)
56+
- [createReadStream](#createreadstream)
57+
- [Parameters](#parameters-1)
58+
- [createWriteStream](#createwritestream)
59+
- [Parameters](#parameters-2)
60+
- [remove](#remove)
61+
- [Parameters](#parameters-3)
62+
- [exists](#exists)
63+
- [Parameters](#parameters-4)
64+
- [WriteParams](#writeparams)
65+
- [Options](#options)
66+
- [Properties](#properties)
67+
- [ReadStreamOptions](#readstreamoptions)
68+
- [S3](#s3)
69+
- [ReadParams](#readparams)
70+
71+
### S3BlobStore
72+
73+
Create S3 blob store
74+
75+
#### Parameters
76+
77+
- `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
78+
- `opts.client` **[S3](#s3)** S3 client
79+
- `opts.bucket` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** bucket name
80+
81+
#### createReadStream
82+
83+
Create read stream
84+
85+
##### Parameters
86+
87+
- `opts` **([ReadStreamOptions](#readstreamoptions) \| [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** options or object key
88+
89+
Returns **ReadableStream** readable stream of data for the file in your bucket whose key matches
90+
91+
#### createWriteStream
92+
93+
Create write stream
94+
95+
##### Parameters
96+
97+
- `opts` **([Options](#options)&lt;[WriteParams](#writeparams)> | [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** options or object key
98+
- `s3opts`
99+
- `done` **function ([Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error), {key: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)})** callback
100+
101+
Returns **WritableStream** writable stream that you can pipe data to
102+
103+
#### remove
104+
105+
Remove object from store
106+
107+
##### Parameters
108+
109+
- `opts` **({key: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)} | [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** options containing object key or just key
110+
- `done` **function ([Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error))** callback
111+
112+
#### exists
113+
114+
Check if object exits
115+
116+
##### Parameters
117+
118+
- `opts` **({key: [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)} | [String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))** options containing object key or just key
119+
- `done` **function ([Error](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error), [Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean))** callback
120+
121+
###
122+
123+
### WriteParams
124+
125+
- **See: <https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property>**
126+
127+
S3 `putObject` params
128+
129+
### Options
130+
131+
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
132+
133+
#### Properties
47134

48-
`options` must be an object that has the following properties:
135+
- `key` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** object key
136+
- `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** `key` alias
137+
- `filename` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** `key` alias
138+
- `params` **S3Params?** additional S3 options
49139

50-
- `client`: an `require('aws-sdk').S3` instance
51-
- `bucket`: your bucket
140+
### ReadStreamOptions
52141

53-
### `s3.createWriteStream(opts, cb)`
142+
- **See: <https://github.com/jb55/s3-download-stream#api>**
54143

55-
returns a writable stream that you can pipe data to.
144+
[`Options`](#options) including `s3-stream-download` configuration
56145

57-
`opts` should be an object that has options `key` (will be the filename in
58-
your bucket)
146+
### S3
59147

60-
`opts.params` additional [parameters](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property) to pass to S3
148+
- **See: <https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html>**
61149

62-
`cb` will be called with `(err)` if there is was an error
150+
S3 client
63151

64-
### `s3.createReadStream(opts)`
152+
### ReadParams
65153

66-
`opts` should be `{ key: string (usually a hash or path + filename) }`
154+
- **See: <https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getObject-property>**
67155

68-
`opts.params` additional [parameters](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getObject-property) to pass to S3
69-
`opts.concurrency` optional parameter for [s3-download-stream](https://github.com/jb55/s3-download-stream)
70-
`opts.chunkSize` optional parameter for [s3-download-stream](https://github.com/jb55/s3-download-stream)
156+
S3 `getObject` params
71157

72-
returns a readable stream of data for the file in your bucket whose key matches
158+
###
73159

74160
## License
75161

0 commit comments

Comments
 (0)