Skip to content

Commit

Permalink
Remove redundent callback code (hyperledger-archives#3842)
Browse files Browse the repository at this point in the history
closes #3841

Signed-off-by: Dave Kelsey <[email protected]>
  • Loading branch information
Dave Kelsey authored Apr 13, 2018
1 parent b4ba4e9 commit 5398dbf
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 830 deletions.
162 changes: 6 additions & 156 deletions packages/composer-runtime/lib/datacollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,7 @@ class DataCollection {
* @return {Promise} A promise that will be resolved with an array of objects,
* or rejected with an error.
*/
getAll() {
return new Promise((resolve, reject) => {
this._getAll((error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}

/**
* @callback getAllCallback
* @protected
* @param {Error} error The error if any.
* @param {Object[]} objects The objects in the collection.
*/

/**
* Get all of the objects in this collection.
* @abstract
* @private
* @param {getAllCallback} callback The callback function to call when complete.
*/
_getAll(callback) {
async getAll() {
throw new Error('abstract function called');
}

Expand All @@ -71,32 +47,7 @@ class DataCollection {
* @return {Promise} A promise that will be resolved with an object, or rejected
* with an error.
*/
get(id) {
return new Promise((resolve, reject) => {
this._get(id, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}

/**
* @callback getCallback
* @protected
* @param {Error} error The error if any.
* @param {Object} object The object in the collection.
*/

/**
* Get the specified object in this collection.
* @abstract
* @private
* @param {string} id The ID of the object.
* @param {getCallback} callback The callback function to call when complete.
*/
_get(id, callback) {
async get(id) {
throw new Error('abstract function called');
}

Expand All @@ -108,32 +59,7 @@ class DataCollection {
* be true if the specified object exists in this collection, or rejected with
* an error.
*/
exists(id) {
return new Promise((resolve, reject) => {
this._exists(id, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}

/**
* @callback existsCallback
* @protected
* @param {Error} error The error if any.
* @param {boolean} exists Whether or not the object exists in the collection.
*/

/**
* Check to see if the specified object exists in this collection.
* @abstract
* @private
* @param {string} id The ID of the object.
* @param {existsCallback} callback The callback function to call when complete.
*/
_exists(id, callback) {
async exists(id) {
throw new Error('abstract function called');
}

Expand All @@ -146,34 +72,7 @@ class DataCollection {
* @return {Promise} A promise that will be resolved when complete, or rejected
* with an error.
*/
add(id, object, force) {
force = !!force;
return new Promise((resolve, reject) => {
this._add(id, object, force, (error, result) => {
if (error) {
return reject(error);
}
return resolve();
});
});
}

/**
* @callback addCallback
* @protected
* @param {Error} error The error if any.
*/

/**
* Add an object to the collection.
* @abstract
* @private
* @param {string} id The ID of the object.
* @param {Object} object The object.
* @param {boolean} force don't check for existence, force it
* @param {addCallback} callback The callback function to call when complete.
*/
_add(id, object, force, callback) {
async add(id, object, force) {
throw new Error('abstract function called');
}

Expand All @@ -185,32 +84,7 @@ class DataCollection {
* @return {Promise} A promise that will be resolved when complete, or rejected
* with an error.
*/
update(id, object) {
return new Promise((resolve, reject) => {
this._update(id, object, (error, result) => {
if (error) {
return reject(error);
}
return resolve();
});
});
}

/**
* @callback updateCallback
* @protected
* @param {Error} error The error if any.
*/

/**
* Update an object in the collection.
* @abstract
* @private
* @param {string} id The ID of the object.
* @param {Object} object The object.
* @param {updateCallback} callback The callback function to call when complete.
*/
_update(id, object, callback) {
async update(id, object) {
throw new Error('abstract function called');
}

Expand All @@ -221,31 +95,7 @@ class DataCollection {
* @return {Promise} A promise that will be resolved when complete, or rejected
* with an error.
*/
remove(id) {
return new Promise((resolve, reject) => {
this._remove(id, (error) => {
if (error) {
return reject(error);
}
return resolve();
});
});
}

/**
* @callback removeCallback
* @protected
* @param {Error} error The error if any.
*/

/**
* Remove an object from the collection.
* @abstract
* @private
* @param {string} id The ID of the object.
* @param {removeCallback} callback The callback function to call when complete.
*/
_remove(id, callback) {
async remove(id) {
throw new Error('abstract function called');
}

Expand Down
136 changes: 5 additions & 131 deletions packages/composer-runtime/lib/dataservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,7 @@ class DataService extends Service {
* @return {Promise} A promise that will be resolved with a {@link DataCollection}
* when complete, or rejected with an error.
*/
createCollection(id, force) {
force = !!force;
return new Promise((resolve, reject) => {
this._createCollection(id, force, (error, dataCollection) => {
if (error) {
return reject(error);
}
return resolve(dataCollection);
});
});
}

/**
* @callback createCollectionCallback
* @protected
* @param {Error} error The error if any.
* @param {DataCollection} dataCollection The data collection.
*/

/**
* Create a collection with the specified ID.
* @abstract
* @private
* @param {string} id The ID of the collection.
* @param {force} force force creation, don't check for existence 1st
* @param {createCollectionCallback} callback The callback function to call when complete.
*/
_createCollection(id, force, callback) {
async createCollection(id, force) {
throw new Error('abstract function called');
}

Expand All @@ -73,31 +46,7 @@ class DataService extends Service {
* @return {Promise} A promise that will be resolved when complete, or rejected
* with an error.
*/
deleteCollection(id) {
return new Promise((resolve, reject) => {
this._deleteCollection(id, (error) => {
if (error) {
return reject(error);
}
return resolve();
});
});
}

/**
* @callback deleteCollectionCallback
* @protected
* @param {Error} error The error if any.
*/

/**
* Delete a collection with the specified ID.
* @abstract
* @private
* @param {string} id The ID of the collection.
* @param {deleteCollectionCallback} callback The callback function to call when complete.
*/
_deleteCollection(id, callback) {
async deleteCollection(id) {
throw new Error('abstract function called');
}

Expand All @@ -108,32 +57,7 @@ class DataService extends Service {
* @return {Promise} A promise that will be resolved with a {@link DataCollection}
* when complete, or rejected with an error.
*/
getCollection(id) {
return new Promise((resolve, reject) => {
this._getCollection(id, (error, dataCollection) => {
if (error) {
return reject(error);
}
return resolve(dataCollection);
});
});
}

/**
* @callback getCollectionCallback
* @protected
* @param {Error} error The error if any.
* @param {DataCollection} dataCollection The data collection.
*/

/**
* Get the collection with the specified ID.
* @abstract
* @private
* @param {string} id The ID of the collection.
* @param {getCollectionCallback} callback The callback function to call when complete.
*/
_getCollection(id, callback) {
async getCollection(id) {
throw new Error('abstract function called');
}

Expand All @@ -144,32 +68,7 @@ class DataService extends Service {
* @return {Promise} A promise that will be resolved with a boolean
* indicating whether the collection exists.
*/
existsCollection(id) {
return new Promise((resolve, reject) => {
this._existsCollection(id, (error, exists) => {
if (error) {
return reject(error);
}
return resolve(exists);
});
});
}

/**
* @callback existsCollectionCallback
* @protected
* @param {Error} error The error if any.
* @param {DataCollection} dataCollection The data collection.
*/

/**
* Determine whether the collection with the specified ID exists.
* @abstract
* @private
* @param {string} id The ID of the collection.
* @param {existsCollectionCallback} callback The callback function to call when complete.
*/
_existsCollection(id, callback) {
async existsCollection(id) {
throw new Error('abstract function called');
}

Expand All @@ -181,32 +80,7 @@ class DataService extends Service {
* @return {Promise} A promise that will be resolved with an array of objects
* when complete, or rejected with an error.
*/
executeQuery(queryString) {
return new Promise((resolve, reject) => {
this._executeQuery(queryString, (error, result) => {
if (error) {
return reject(error);
}
return resolve(result);
});
});
}

/**
* @callback executeQueryCallback
* @protected
* @param {Error} error The error if any.
* @param {Object[]} objects The objects.
*/

/**
* Execute a query across all objects stored in all collections, using a query
* string that is dependent on the current Blockchain platform.
* @abstract
* @param {string} queryString The query string for the current Blockchain platform.
* @param {executeQueryCallback} callback The callback function to call when complete.
*/
_executeQuery(queryString, callback) {
async executeQuery(queryString) {
throw new Error('abstract function called');
}

Expand Down
Loading

0 comments on commit 5398dbf

Please sign in to comment.