From dc3011c800116968c50ea72ecb8379705a044eed Mon Sep 17 00:00:00 2001 From: crandmck Date: Mon, 7 Apr 2014 16:17:19 -0700 Subject: [PATCH 01/10] Work on JSDoc comments --- lib/storage-handler.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/storage-handler.js b/lib/storage-handler.js index 1497ef0..f56c669 100644 --- a/lib/storage-handler.js +++ b/lib/storage-handler.js @@ -3,11 +3,12 @@ var StringDecoder = require('string_decoder').StringDecoder; /** * Handle multipart/form-data upload to the storage service - * @param provider The storage service provider + * @param {Object} provider The storage service provider * @param {Request} req The HTTP request * @param {Response} res The HTTP response * @param {String} container The container name - * @param {Function} cb The callback + * @callback {Function} cb Callback function + * @header storageService.upload(provider, req, res, container, cb) */ exports.upload = function (provider, req, res, container, cb) { var form = new IncomingForm(this.options); @@ -103,13 +104,14 @@ exports.upload = function (provider, req, res, container, cb) { } /** - * Handle download from a container/file - * @param provider The storage service provider + * Handle download from a container/file. + * @param {Object} provider The storage service provider * @param {Request} req The HTTP request * @param {Response} res The HTTP response * @param {String} container The container name * @param {String} file The file name - * @param {Function} cb The callback + * @callback {Function} cb Callback function. + * @header storageService.download(provider, req, res, container, file, cb) */ exports.download = function (provider, req, res, container, file, cb) { var reader = provider.download({ From bb6567c439ca3270acdeeb3ca0346877a147c856 Mon Sep 17 00:00:00 2001 From: crandmck Date: Mon, 7 Apr 2014 16:18:51 -0700 Subject: [PATCH 02/10] Work on JSDoc comments --- lib/storage-service.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lib/storage-service.js b/lib/storage-service.js index 621722a..24c30c4 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -9,7 +9,7 @@ module.exports = StorageService; * Storage service constructor. Properties of options object depend on the storage service provider. * * - * @options {Object} options The options to create a provider; see below; + * @options {Object} options The options to create a provider; see below. * @prop {Object} connector * @prop {String} provider Use 'filesystem' for local file system. Other supported values are: 'amazon', 'rackspace', 'azure', and 'openstack'. * @prop {String} root With 'filesystem' provider, the path to the root of storage directory. @@ -46,7 +46,9 @@ function map(obj) { /** * List all storage service containers. - * @param {Function} callback Callback function; parameters: err - error message, containers - object holding all containers. + * @callback {Function} callback Callback function. See below. + * @param err {String} Error message + * @param containers {Object} object holding all containers. */ StorageService.prototype.getContainers = function (cb) { @@ -64,12 +66,18 @@ StorageService.prototype.getContainers = function (cb) { /** * Create a new storage service container. Other option properties depend on the provider. * - * @options {Object} options The options to create a provider; see below; + * @options {Object} options The options to create a provider; see below. * @prop {Object} connector - * @prop {String} provider Storage service provider. Use 'filesystem' for local file system. Other supported values are: 'amazon', 'rackspace', 'azure', and 'openstack'. - * @prop {String} root With 'filesystem' provider, the path to the root of storage directory. - * @prop {String} - * @param {Function} callback Callback function. + * @prop {String} provider Storage service provider. Must be one of: + * + * + * Other supported values depend on the provider. See the [documentation](http://docs.strongloop.com/display/DOC/Storage+service) for more information. + * @callback {Function} callback Callback function. */ StorageService.prototype.createContainer = function (options, cb) { @@ -86,7 +94,7 @@ StorageService.prototype.createContainer = function (options, cb) { /** * Destroy an existing storage service container. * @param {Object} container Container object. - * @param {Function} callback Callback function. + * @callback {Function} callback Callback function. */ StorageService.prototype.destroyContainer = function (container, cb) { return this.client.destroyContainer(container, cb); @@ -95,7 +103,7 @@ StorageService.prototype.destroyContainer = function (container, cb) { /** * Look up a container by name. * @param {Object} container Container object. - * @param {Function} callback Callback function. + * @callback {Function} callback Callback function. */ StorageService.prototype.getContainer = function (container, cb) { return this.client.getContainer(container, function (err, container) { @@ -106,9 +114,10 @@ StorageService.prototype.getContainer = function (container, cb) { /** * Get the stream for uploading * @param {Object} container Container object. - * @param {String} file IS THIS A FILE? + * @param {String} file * @options options See below. - * @param callback Callback function + * @prop TBD + * @callback callback Callback function */ StorageService.prototype.uploadStream = function (container, file, options, cb) { if (!cb && typeof options === 'function') { @@ -130,7 +139,8 @@ StorageService.prototype.uploadStream = function (container, file, options, cb) * Get the stream for downloading. * @param {Object} container Container object. * @param {String} file Path to file. - * @options {Object} options See below. + * @options {Object} options See below. + * @prop TBD * @param {Function} callback Callback function */ StorageService.prototype.downloadStream = function (container, file, options, cb) { @@ -152,8 +162,8 @@ StorageService.prototype.downloadStream = function (container, file, options, cb /** * List all files within the given container. * @param {Object} container Container object. - * @param {Function} download - * @param {Function} callback Callback function + * @param {Function} download + * @callback {Function} callback Callback function */ StorageService.prototype.getFiles = function (container, download, cb) { return this.client.getFiles(container, download, function (err, files) { From a58ed7711fbe7f30e3147f31da081d289b507e54 Mon Sep 17 00:00:00 2001 From: crandmck Date: Mon, 7 Apr 2014 16:32:12 -0700 Subject: [PATCH 03/10] Add param info to constructor JSDoc --- lib/storage-service.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/storage-service.js b/lib/storage-service.js index 24c30c4..62221c8 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -11,8 +11,16 @@ module.exports = StorageService; * * @options {Object} options The options to create a provider; see below. * @prop {Object} connector - * @prop {String} provider Use 'filesystem' for local file system. Other supported values are: 'amazon', 'rackspace', 'azure', and 'openstack'. - * @prop {String} root With 'filesystem' provider, the path to the root of storage directory. + * @prop {String} provider Storage service provider. Must be one of: + *
  • 'filesystem' - local file system.
  • + *
  • 'amazon'
  • + *
  • 'rackspace'
  • + *
  • 'azure'
  • + *
  • 'openstack'
  • + *
+ * + * Other supported values depend on the provider. + * See the [documentation](http://docs.strongloop.com/display/DOC/Storage+service) for more information. * @class */ function StorageService(options) { @@ -76,7 +84,8 @@ StorageService.prototype.getContainers = function (cb) { *
  • 'openstack'
  • * * - * Other supported values depend on the provider. See the [documentation](http://docs.strongloop.com/display/DOC/Storage+service) for more information. + * Other supported values depend on the provider. + * See the [documentation](http://docs.strongloop.com/display/DOC/Storage+service) for more information. * @callback {Function} callback Callback function. */ From 228041977900e69d512fecc9923ea143c757b6ff Mon Sep 17 00:00:00 2001 From: crandmck Date: Mon, 7 Apr 2014 16:43:00 -0700 Subject: [PATCH 04/10] Clean up JS Doc --- lib/storage-service.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/storage-service.js b/lib/storage-service.js index 62221c8..ea21e36 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -8,9 +8,7 @@ module.exports = StorageService; /** * Storage service constructor. Properties of options object depend on the storage service provider. * - * * @options {Object} options The options to create a provider; see below. - * @prop {Object} connector * @prop {String} provider Storage service provider. Must be one of: *
    • 'filesystem' - local file system.
    • *
    • 'amazon'
    • @@ -75,7 +73,6 @@ StorageService.prototype.getContainers = function (cb) { * Create a new storage service container. Other option properties depend on the provider. * * @options {Object} options The options to create a provider; see below. - * @prop {Object} connector * @prop {String} provider Storage service provider. Must be one of: *
      • 'filesystem' - local file system.
      • *
      • 'amazon'
      • From d45cece2fa3b5876685b64d85fe10ca21092fdff Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Mon, 7 Apr 2014 18:19:35 -0700 Subject: [PATCH 05/10] Update jsdocs --- docs.json | 6 +- lib/providers/filesystem/index.js | 8 +-- lib/storage-connector.js | 8 ++- lib/storage-service.js | 114 ++++++++++++++++-------------- 4 files changed, 74 insertions(+), 62 deletions(-) diff --git a/docs.json b/docs.json index 32cef15..899aec4 100644 --- a/docs.json +++ b/docs.json @@ -1,8 +1,8 @@ { "content": [ { "title": "LoopBack Storage Service", "depth": 2 }, - "lib/storage-service.js", - { "title": "Storage Handler API", "depth": 3 }, - "lib/storage-handler.js" + "lib/storage-service.js", + { "title": "LoopBack Storage Connector", "depth": 2 }, + "lib/storage-connector.js" ] } diff --git a/lib/providers/filesystem/index.js b/lib/providers/filesystem/index.js index 85043eb..9285103 100644 --- a/lib/providers/filesystem/index.js +++ b/lib/providers/filesystem/index.js @@ -190,10 +190,10 @@ FileSystemProvider.prototype.download = function (options, cb) { } }; -FileSystemProvider.prototype.getFiles = function (container, download, cb) { - if (typeof download === 'function' && !(download instanceof RegExp)) { - cb = download; - download = false; +FileSystemProvider.prototype.getFiles = function (container, options, cb) { + if (typeof options === 'function' && !(options instanceof RegExp)) { + cb = options; + options = false; } var self = this; if (!validateName(container, cb)) return; diff --git a/lib/storage-connector.js b/lib/storage-connector.js index 8894d0d..b09360f 100644 --- a/lib/storage-connector.js +++ b/lib/storage-connector.js @@ -1,8 +1,10 @@ var StorageService = require('./storage-service'); /** - * Export the initialize method to Loopback data - * @param dataSource - * @param callback + * Initialize the storage service as a connector for LoopBack data sources + * @param {DataSource} dataSource DataSource instance + * @prop {Object} settings Connector settings + * @callback {Function} callback Callback function + * @param {String|Object} err Error string or object */ exports.initialize = function (dataSource, callback) { var settings = dataSource.settings || {}; diff --git a/lib/storage-service.js b/lib/storage-service.js index ea21e36..5382c3c 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -8,7 +8,7 @@ module.exports = StorageService; /** * Storage service constructor. Properties of options object depend on the storage service provider. * - * @options {Object} options The options to create a provider; see below. + * @options {Object} options Options to create a provider; see below. * @prop {String} provider Storage service provider. Must be one of: *
        • 'filesystem' - local file system.
        • *
        • 'amazon'
        • @@ -31,32 +31,14 @@ function StorageService(options) { function map(obj) { return obj; - /* - if (!obj || typeof obj !== 'object') { - return obj; - } - var data = {}; - for (var i in obj) { - if (obj.hasOwnProperty(i) && typeof obj[i] !== 'function' - && typeof obj[i] !== 'object') { - if (i === 'newListener' || i === 'delimiter' || i === 'wildcard') { - // Skip properties from the base class - continue; - } - data[i] = obj[i]; - } - } - return data; - */ } /** * List all storage service containers. - * @callback {Function} callback Callback function. See below. - * @param err {String} Error message - * @param containers {Object} object holding all containers. + * @callback {Function} callback Callback function + * @param {Object|String} err Error string or object + * @param {Object[]} containers An array of container metadata objects */ - StorageService.prototype.getContainers = function (cb) { this.client.getContainers(function (err, containers) { if (err) { @@ -70,20 +52,13 @@ StorageService.prototype.getContainers = function (cb) { }; /** - * Create a new storage service container. Other option properties depend on the provider. - * - * @options {Object} options The options to create a provider; see below. - * @prop {String} provider Storage service provider. Must be one of: - *
          • 'filesystem' - local file system.
          • - *
          • 'amazon'
          • - *
          • 'rackspace'
          • - *
          • 'azure'
          • - *
          • 'openstack'
          • - *
          + * Create a new storage service container. * - * Other supported values depend on the provider. - * See the [documentation](http://docs.strongloop.com/display/DOC/Storage+service) for more information. - * @callback {Function} callback Callback function. + * @options {Object} options Options to create a container. Option properties depend on the provider. + * @prop {String} name Container name + * @callback {Function} cb Callback function + * @param {Object|String} err Error string or object + * @param {Object} container Container metadata object */ StorageService.prototype.createContainer = function (options, cb) { @@ -99,17 +74,20 @@ StorageService.prototype.createContainer = function (options, cb) { /** * Destroy an existing storage service container. - * @param {Object} container Container object. + * @param {String} container Container name. * @callback {Function} callback Callback function. + * @param {Object|String} err Error string or object */ StorageService.prototype.destroyContainer = function (container, cb) { return this.client.destroyContainer(container, cb); }; /** - * Look up a container by name. - * @param {Object} container Container object. + * Look up a container metadata object by name. + * @param {String} container Container name. * @callback {Function} callback Callback function. + * @param {Object|String} err Error string or object + * @param {Object} container Container metadata object */ StorageService.prototype.getContainer = function (container, cb) { return this.client.getContainer(container, function (err, container) { @@ -119,11 +97,12 @@ StorageService.prototype.getContainer = function (container, cb) { /** * Get the stream for uploading - * @param {Object} container Container object. - * @param {String} file - * @options options See below. - * @prop TBD + * @param {String} container Container name + * @param {String} file File name + * @options {Object} [options] Options for uploading * @callback callback Callback function + * @param {String|Object} err Error string or object + * @returns {Stream} Stream for uploading */ StorageService.prototype.uploadStream = function (container, file, options, cb) { if (!cb && typeof options === 'function') { @@ -143,11 +122,12 @@ StorageService.prototype.uploadStream = function (container, file, options, cb) /** * Get the stream for downloading. - * @param {Object} container Container object. - * @param {String} file Path to file. - * @options {Object} options See below. - * @prop TBD - * @param {Function} callback Callback function + * @param {String} container Container name. + * @param {String} file File name. + * @options {Object} options Options for downloading + * @callback {Function} callback Callback function + * @param {String|Object} err Error string or object + * @returns {Stream} Stream for downloading */ StorageService.prototype.downloadStream = function (container, file, options, cb) { if (!cb && typeof options === 'function') { @@ -167,12 +147,14 @@ StorageService.prototype.downloadStream = function (container, file, options, cb /** * List all files within the given container. - * @param {Object} container Container object. - * @param {Function} download - * @callback {Function} callback Callback function + * @param {String} container Container name. + * @param {Object} [options] Options for download + * @callback {Function} cb Callback function + * @param {Object|String} err Error string or object + * @param {Object[]} files An array of file metadata objects */ -StorageService.prototype.getFiles = function (container, download, cb) { - return this.client.getFiles(container, download, function (err, files) { +StorageService.prototype.getFiles = function (container, options, cb) { + return this.client.getFiles(container, options, function (err, files) { if (err) { cb(err, files); } else { @@ -183,20 +165,48 @@ StorageService.prototype.getFiles = function (container, download, cb) { }); }; +/** + * Look up the metadata object for a file by name + * @param {String} container Container name + * @param {String} file File name + * @callback {Function} cb Callback function + * @param {Object|String} err Error string or object + * @param {Object} file File metadata object + */ StorageService.prototype.getFile = function (container, file, cb) { return this.client.getFile(container, file, function (err, f) { return cb(err, map(f)); }); }; +/** + * Remove an existing file + * @param {String} container Container name + * @param {String} file File name + * @callback {Function} cb Callback function + * @param {Object|String} err Error string or object + */ StorageService.prototype.removeFile = function (container, file, cb) { return this.client.removeFile(container, file, cb); }; +/*! + * Upload middleware for the HTTP request/response + * @param {Request} req Request object + * @param {Response} res Response object + * @param {Function} cb Callback function + */ StorageService.prototype.upload = function (req, res, cb) { return handler.upload(this.client, req, res, req.params.container, cb); }; +/*! + * Download middleware + * @param {String} container Container name + * @param {String} file File name + * @param {Response} res HTTP response + * @param {Function} cb Callback function + */ StorageService.prototype.download = function (container, file, res, cb) { return handler.download(this.client, null, res, container, file, cb); }; From 9354447d6df03c3dd8e9a719ed31149de932cb2e Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 8 Apr 2014 08:41:34 -0700 Subject: [PATCH 06/10] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b39886d..0b59386 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "loopback-storage-service", "description": "Loopback Storage Service", - "version": "1.0.0", + "version": "1.0.1", "main": "index.js", "scripts": { "test": "./node_modules/.bin/mocha --timeout 30000 test/*test.js" From e26599e2143a49e020fe6eaf24ee6920c6ce8b33 Mon Sep 17 00:00:00 2001 From: Rand McKinney Date: Wed, 9 Apr 2014 17:11:36 -0700 Subject: [PATCH 07/10] Doc upload and download functions --- lib/storage-service.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/storage-service.js b/lib/storage-service.js index 5382c3c..4a20b8d 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -190,8 +190,8 @@ StorageService.prototype.removeFile = function (container, file, cb) { return this.client.removeFile(container, file, cb); }; -/*! - * Upload middleware for the HTTP request/response +/** + * Upload middleware for the HTTP request/response * @param {Request} req Request object * @param {Response} res Response object * @param {Function} cb Callback function @@ -200,8 +200,8 @@ StorageService.prototype.upload = function (req, res, cb) { return handler.upload(this.client, req, res, req.params.container, cb); }; -/*! - * Download middleware +/** + * Download middleware * @param {String} container Container name * @param {String} file File name * @param {Response} res HTTP response @@ -285,4 +285,4 @@ StorageService.prototype.download.accepts = [ {arg: 'res', type: 'object', 'http': {source: 'res'}} ]; StorageService.prototype.download.http = -{verb: 'get', path: '/:container/download/:file'}; \ No newline at end of file +{verb: 'get', path: '/:container/download/:file'}; From 09a3255201bea91d1b0c8a7b5595db4f4f91c519 Mon Sep 17 00:00:00 2001 From: Rand McKinney Date: Thu, 10 Apr 2014 11:40:26 -0700 Subject: [PATCH 08/10] Update docs.json Add storage-handler.js instead of storage-connector.js --- docs.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs.json b/docs.json index 899aec4..b65c05e 100644 --- a/docs.json +++ b/docs.json @@ -2,7 +2,6 @@ "content": [ { "title": "LoopBack Storage Service", "depth": 2 }, "lib/storage-service.js", - { "title": "LoopBack Storage Connector", "depth": 2 }, - "lib/storage-connector.js" + "lib/storage-handler.js" ] } From a1cdfa098e21724c5abeee38da06a6e26f07b3e8 Mon Sep 17 00:00:00 2001 From: cgole Date: Fri, 30 May 2014 09:37:06 -0700 Subject: [PATCH 09/10] Add formidable as dependency --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 0b59386..d953863 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,12 @@ }, "dependencies": { "pkgcloud": "~0.9.4", - "async": "~0.2.10" + "async": "~0.2.10", + "formidable": "~1.0.14" }, "devDependencies": { "express": "~3.4.0", "loopback": "1.x.x", - "formidable": "~1.0.14", "mocha": "~1.18.2", "supertest": "~0.10.0", "mkdirp": "~0.3.5" From 660ddd8c78073fda3ff94ef9454da0b678c524c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Fri, 30 May 2014 18:38:58 +0200 Subject: [PATCH 10/10] v1.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d953863..388f48a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "loopback-storage-service", "description": "Loopback Storage Service", - "version": "1.0.1", + "version": "1.0.2", "main": "index.js", "scripts": { "test": "./node_modules/.bin/mocha --timeout 30000 test/*test.js"