Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Commit

Permalink
fix: fix some types
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Nov 30, 2020
1 parent 2afd9be commit 42aebd5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Adapter {
*
* @param {Key} key
* @param {Uint8Array} val
* @param {Options} options
* @param {Options} [options]
* @returns {Promise<void>}
*/
put (key, val, options) { // eslint-disable-line require-await
Expand All @@ -45,7 +45,7 @@ class Adapter {
* Store the given key/value pairs
*
* @param {AnyIterable<Pair>} source
* @param {Object} options
* @param {Object} [options]
* @returns {AsyncGenerator<Pair>}
*/
async * putMany (source, options = {}) {
Expand All @@ -59,7 +59,7 @@ class Adapter {
* Retrieve the value for the passed key
*
* @param {Key} key
* @param {Object} options
* @param {Object} [options]
* @returns {Promise<Uint8Array>}
*/
get (key, options = {}) {
Expand All @@ -79,6 +79,7 @@ class Adapter {
* Check for the existence of a value for the passed key
*
* @param {Key} key
* @param {Options} [options]
* @returns {Promise<boolean>}
* @example
* ```js
Expand All @@ -91,15 +92,15 @@ class Adapter {
* }
* ```
*/
has (key) { // eslint-disable-line require-await
has (key, options) { // eslint-disable-line require-await
return Promise.resolve(false)
}

/**
* Remove the record for the passed key
*
* @param {Key} key
* @param {Object} options
* @param {Object} [options]
* @returns {Promise<void>}
*/
delete (key, options = {}) { // eslint-disable-line require-await
Expand All @@ -110,7 +111,7 @@ class Adapter {
* Remove values for the passed keys
*
* @param {AnyIterable<Key>} source
* @param {Options} options
* @param {Options} [options]
* @returns {AsyncGenerator<Key>}
*/
async * deleteMany (source, options = {}) {
Expand Down Expand Up @@ -149,7 +150,7 @@ class Adapter {
* Yield all datastore values
*
* @param {Query} q
* @param {Options} options
* @param {Options} [options]
* @returns {AsyncGenerator<Pair>}
*/
async * _all (q, options) { // eslint-disable-line require-await
Expand All @@ -158,7 +159,7 @@ class Adapter {

/**
* @param {Query} q
* @param {Options} options
* @param {Options} [options]
* @returns {AsyncGenerator<Pair|{key: Key}>}
*/
query (q, options) {
Expand Down
25 changes: 20 additions & 5 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
'use strict'

const errcode = require('err-code')

/**
*
* @param {Error} [err]
*/
const dbOpenFailedError = (err) => {
err = err || new Error('Cannot open database')
return errcode(err, 'ERR_DB_OPEN_FAILED')
}

/**
*
* @param {Error} [err]
*/
const dbDeleteFailedError = (err) => {
err = err || new Error('Delete failed')
return errcode(err, 'ERR_DB_DELETE_FAILED')
}

/**
*
* @param {Error} [err]
*/
const dbWriteFailedError = (err) => {
err = err || new Error('Write failed')
return errcode(err, 'ERR_DB_WRITE_FAILED')
}

/**
*
* @param {Error} [err]
*/
const notFoundError = (err) => {
err = err || new Error('Not Found')
return errcode(err, 'ERR_NOT_FOUND')
}

/**
*
* @param {Error} [err]
*/
const abortedError = (err) => {
err = err || new Error('Aborted')
return errcode(err, 'ERR_ABORTED')
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export interface IDatastore {
* @param q
* @param options
*/
_all(q: Query, options: Options): AsyncGenerator<Pair>
_all(q: Query, options?: Options): AsyncGenerator<Pair>
}

export interface Query {
Expand Down

0 comments on commit 42aebd5

Please sign in to comment.