diff --git a/package.json b/package.json index e18c46b..321ca15 100644 --- a/package.json +++ b/package.json @@ -42,34 +42,34 @@ "cache" ], "dependencies": { - "ajv": "^6.12.2", - "atomically": "^1.3.1", + "ajv": "^7.0.3", + "atomically": "^1.7.0", "debounce-fn": "^4.0.0", - "dot-prop": "^5.2.0", + "dot-prop": "^6.0.1", "env-paths": "^2.2.0", "json-schema-typed": "^7.0.3", "make-dir": "^3.1.0", - "onetime": "^5.1.0", + "onetime": "^5.1.2", "pkg-up": "^3.1.0", - "semver": "^7.3.2" + "semver": "^7.3.4" }, "devDependencies": { "@ava/typescript": "^1.1.1", "@sindresorhus/tsconfig": "^0.7.0", - "@types/node": "^14.0.14", - "@types/semver": "^7.3.1", + "@types/node": "^14.14.20", + "@types/semver": "^7.3.4", "@types/write-file-atomic": "^3.0.1", - "ava": "^3.9.0", + "ava": "^3.15.0", "clear-module": "^4.1.1", - "del": "^5.1.0", + "del": "^6.0.0", "del-cli": "^3.0.1", - "delay": "^4.3.0", + "delay": "^4.4.0", "nyc": "^15.1.0", "p-event": "^4.2.0", - "tempy": "^0.5.0", - "tsd": "^0.12.1", - "typescript": "3.9.6", - "xo": "^0.32.0" + "tempy": "^1.0.0", + "tsd": "^0.14.0", + "typescript": "4.1.3", + "xo": "^0.37.1" }, "types": "dist/source", "ava": { @@ -86,7 +86,7 @@ }, "xo": { "rules": { - "unicorn/prefer-optional-catch-binding": "off" + "@typescript-eslint/no-implicit-any-catch": "off" } }, "nyc": { diff --git a/source/index.ts b/source/index.ts index 1910206..634ac40 100644 --- a/source/index.ts +++ b/source/index.ts @@ -8,12 +8,12 @@ import makeDir = require('make-dir'); import pkgUp = require('pkg-up'); import envPaths = require('env-paths'); import atomically = require('atomically'); -import Ajv = require('ajv'); +import Ajv, {ValidateFunction as AjvValidateFunction} from 'ajv'; import debounceFn = require('debounce-fn'); import semver = require('semver'); import onetime = require('onetime'); -import {Deserialize, Migrations, OnDidChangeCallback, Options, Serialize, Unsubscribe, Schema, OnDidAnyChangeCallback} from './types'; import {JSONSchema} from 'json-schema-typed'; +import {Deserialize, Migrations, OnDidChangeCallback, Options, Serialize, Unsubscribe, Schema, OnDidAnyChangeCallback} from './types'; const encryptionAlgorithm = 'aes-256-cbc'; @@ -46,7 +46,7 @@ const MIGRATION_KEY = `${INTERNAL_KEY}.migrations.version`; class Conf = Record> implements Iterable<[keyof T, T[keyof T]]> { readonly path: string; readonly events: EventEmitter; - readonly #validator?: Ajv.ValidateFunction; + readonly #validator?: AjvValidateFunction; readonly #encryptionKey?: string | Buffer | NodeJS.TypedArray | DataView; readonly #options: Readonly>>; readonly #defaultValues: Partial = {}; @@ -91,9 +91,7 @@ class Conf = Record> implements I const ajv = new Ajv({ allErrors: true, - format: 'full', - useDefaults: true, - errorDataPath: 'property' + useDefaults: true }); const schema: JSONSchema = { @@ -137,7 +135,7 @@ class Conf = Record> implements I try { assert.deepEqual(fileStore, store); - } catch (_) { + } catch { this.store = store; } @@ -232,7 +230,7 @@ class Conf = Record> implements I return dotProp.has(this.store, key as string); } - return key in this.store; + return (key as string) in this.store; } /** @@ -376,10 +374,9 @@ class Conf = Record> implements I const decipher = crypto.createDecipher(encryptionAlgorithm, this.#encryptionKey); data = Buffer.concat([decipher.update(Buffer.from(data)), decipher.final()]).toString('utf8'); } - } catch (_) { } + } catch {} } - } catch (_) { - } + } catch {} return data.toString(); } @@ -407,7 +404,7 @@ class Conf = Record> implements I try { // TODO: Use `util.isDeepStrictEqual` when targeting Node.js 10 assert.deepEqual(newValue, oldValue); - } catch (_) { + } catch { currentValue = newValue; callback.call(this, newValue, oldValue); } diff --git a/source/types.ts b/source/types.ts index a72fbe8..fa2fc31 100644 --- a/source/types.ts +++ b/source/types.ts @@ -214,9 +214,7 @@ export interface Options { readonly watch?: boolean; } -export type Migrations = { - [semverSpecifier: string]: (store: Conf) => void; -}; +export type Migrations = Record) => void>; export type Schema = { [Property in keyof T]: ValueSchema }; export type ValueSchema = TypedJSONSchema; diff --git a/test/index.ts b/test/index.ts index 424b567..e8c8566 100644 --- a/test/index.ts +++ b/test/index.ts @@ -651,7 +651,7 @@ test('schema - multiple violations', t => { const config = new Conf({cwd: tempy.directory(), schema}); t.throws(() => { config.set('foo', {bar: '1', foobar: 101}); - }, {message: 'Config schema violation: `foo.bar` should be number; `foo.foobar` should be <= 100'}); + }, {message: 'Config schema violation: `foo/bar` should be number; `foo/foobar` should be <= 100'}); }); test('schema - complex schema', t => { @@ -673,10 +673,10 @@ test('schema - complex schema', t => { const config = new Conf({cwd: tempy.directory(), schema}); t.throws(() => { config.set('foo', 'abca'); - }, {message: 'Config schema violation: `foo` should NOT be longer than 3 characters; `foo` should match pattern "[def]+"'}); + }, {message: 'Config schema violation: `foo` should NOT have more than 3 characters; `foo` should match pattern "[def]+"'}); t.throws(() => { config.set('bar', [1, 1, 2, 'a']); - }, {message: 'Config schema violation: `bar` should NOT have more than 3 items; `bar[3]` should be integer; `bar` should NOT have duplicate items (items ## 1 and 0 are identical)'}); + }, {message: 'Config schema violation: `bar` should NOT have more than 3 items; `bar/3` should be integer; `bar` should NOT have duplicate items (items ## 1 and 0 are identical)'}); }); test('schema - invalid write to config file', t => {