-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: update types #302
Merged
Merged
chore: update types #302
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,52 +34,50 @@ module.exports = (store) => { | |
* @param {AbortSignal} [options.signal] - abort this config read | ||
* @returns {Promise<Config>} | ||
*/ | ||
getAll (options = {}) { // eslint-disable-line require-await | ||
return configStore.get(undefined, options) | ||
async getAll (options = {}) { // eslint-disable-line require-await | ||
// [email protected] cannot read keys from [email protected] dbs so fall back to | ||
// using IndexedDB API with string keys - only necessary until we do | ||
// the migratiion to v10 or above | ||
const encodedValue = await getWithFallback(configKey, store.get.bind(store), store.has.bind(store), store, { | ||
signal: options.signal | ||
}) | ||
|
||
return JSON.parse(uint8ArrayToString(encodedValue)) | ||
}, | ||
|
||
/** | ||
* Get the value for the passed configuration key from the repo. | ||
* | ||
* @param {string} [key] - the config key to get | ||
* @param {string} key - the config key to get | ||
* @param {Object} [options] - options | ||
* @param {AbortSignal} [options.signal] - abort this config read | ||
* @returns {Promise<Config | any>} | ||
*/ | ||
async get (key, options = {}) { | ||
if (!key) { | ||
key = undefined | ||
if (key == null) { | ||
throw new errors.NotFoundError(`Key ${key} does not exist in config`) | ||
} | ||
|
||
// [email protected] cannot read keys from [email protected] dbs so fall back to | ||
// using IndexedDB API with string keys - only necessary until we do | ||
// the migratiion to v10 or above | ||
const encodedValue = await getWithFallback(configKey, store.get.bind(store), store.has.bind(store), store, { | ||
signal: options.signal | ||
}) | ||
const config = await this.getAll(options) | ||
const value = _get(config, key) | ||
|
||
const config = JSON.parse(uint8ArrayToString(encodedValue)) | ||
if (key !== undefined && _get(config, key) === undefined) { | ||
if (value === undefined) { | ||
throw new errors.NotFoundError(`Key ${key} does not exist in config`) | ||
} | ||
|
||
const value = key !== undefined ? _get(config, key) : config | ||
return value | ||
}, | ||
|
||
/** | ||
* Set the current configuration for this repo. | ||
* | ||
* @param {string} [key] - the config key to be written | ||
* @param {string} key - the config key to be written | ||
* @param {any} [value] - the config value to be written | ||
* @param {Object} [options] - options | ||
* @param {AbortSignal} [options.signal] - abort this config write | ||
*/ | ||
set (key, value, options = {}) { | ||
if (arguments.length === 1) { | ||
value = key | ||
key = undefined | ||
} else if (!key || typeof key !== 'string') { | ||
// @ts-ignore ts thinks key will only be a string, but it may not be | ||
if (typeof key !== 'string' && !(key instanceof String)) { | ||
throw errcode(new Error('Invalid key type: ' + typeof key), 'ERR_INVALID_KEY') | ||
} | ||
|
||
|
@@ -137,7 +135,7 @@ module.exports = (store) => { | |
const key = m.key | ||
const value = m.value | ||
if (key) { | ||
const config = await configStore.get() | ||
const config = await configStore.getAll() | ||
if (typeof config === 'object' && config !== null) { | ||
_set(config, key, value) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an issue to track this? If not, can you create one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do, but it's not something that's ever going to be fixed so the issue will hang around forever.
The level-js 4 -> 5 version bump was because of this breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok makes sense, so maybe not worth