Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 7, 2021
1 parent 259ba9b commit 2177831
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -86,7 +86,7 @@
},
"xo": {
"rules": {
"unicorn/prefer-optional-catch-binding": "off"
"@typescript-eslint/no-implicit-any-catch": "off"
}
},
"nyc": {
Expand Down
21 changes: 9 additions & 12 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -46,7 +46,7 @@ const MIGRATION_KEY = `${INTERNAL_KEY}.migrations.version`;
class Conf<T extends Record<string, any> = Record<string, unknown>> 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<Partial<Options<T>>>;
readonly #defaultValues: Partial<T> = {};
Expand Down Expand Up @@ -91,9 +91,7 @@ class Conf<T extends Record<string, any> = Record<string, unknown>> implements I

const ajv = new Ajv({
allErrors: true,
format: 'full',
useDefaults: true,
errorDataPath: 'property'
useDefaults: true
});

const schema: JSONSchema = {
Expand Down Expand Up @@ -137,7 +135,7 @@ class Conf<T extends Record<string, any> = Record<string, unknown>> implements I

try {
assert.deepEqual(fileStore, store);
} catch (_) {
} catch {
this.store = store;
}

Expand Down Expand Up @@ -232,7 +230,7 @@ class Conf<T extends Record<string, any> = Record<string, unknown>> implements I
return dotProp.has(this.store, key as string);
}

return key in this.store;
return (key as string) in this.store;
}

/**
Expand Down Expand Up @@ -376,10 +374,9 @@ class Conf<T extends Record<string, any> = Record<string, unknown>> 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();
}
Expand Down Expand Up @@ -407,7 +404,7 @@ class Conf<T extends Record<string, any> = Record<string, unknown>> 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);
}
Expand Down
4 changes: 1 addition & 3 deletions source/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ export interface Options<T> {
readonly watch?: boolean;
}

export type Migrations<T> = {
[semverSpecifier: string]: (store: Conf<T>) => void;
};
export type Migrations<T> = Record<string, (store: Conf<T>) => void>;

export type Schema<T> = { [Property in keyof T]: ValueSchema };
export type ValueSchema = TypedJSONSchema;
Expand Down
6 changes: 3 additions & 3 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand Down

0 comments on commit 2177831

Please sign in to comment.