Comparing version 13.0.1 to 13.1.0
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { type OnDidChangeCallback, type Options, type Unsubscribe, type OnDidAnyChangeCallback } from './types.js'; | ||
@@ -46,2 +45,3 @@ export default class Conf<T extends Record<string, any> = Record<string, unknown>> implements Iterable<[keyof T, T[keyof T]]> { | ||
delete<Key extends keyof T>(key: Key): void; | ||
delete(key: string): void; | ||
/** | ||
@@ -48,0 +48,0 @@ Delete all items. |
@@ -58,4 +58,4 @@ /* eslint-disable @typescript-eslint/naming-convention, @typescript-eslint/no-unsafe-return */ | ||
this.#options = options; | ||
if (options.schema) { | ||
if (typeof options.schema !== 'object') { | ||
if (options.schema ?? options.ajvOptions ?? options.rootSchema) { | ||
if (options.schema && typeof options.schema !== 'object') { | ||
throw new TypeError('The `schema` option must be an object.'); | ||
@@ -66,5 +66,7 @@ } | ||
useDefaults: true, | ||
...options.ajvOptions, | ||
}); | ||
ajvFormats(ajv); | ||
const schema = { | ||
...options.rootSchema, | ||
type: 'object', | ||
@@ -74,3 +76,3 @@ properties: options.schema, | ||
this.#validator = ajv.compile(schema); | ||
for (const [key, value] of Object.entries(options.schema)) { // TODO: Remove the `as any`. | ||
for (const [key, value] of Object.entries(options.schema ?? {})) { // TODO: Remove the `as any`. | ||
if (value?.default) { | ||
@@ -77,0 +79,0 @@ this.#defaultValues[key] = value.default; // eslint-disable-line @typescript-eslint/no-unsafe-assignment |
@@ -1,3 +0,3 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { type JSONSchema as TypedJSONSchema } from 'json-schema-typed'; | ||
import type { CurrentOptions as AjvOptions } from 'ajv/dist/core.js'; | ||
import type Conf from './index.js'; | ||
@@ -14,6 +14,4 @@ export type Options<T extends Record<string, any>> = { | ||
Under the hood, the JSON Schema validator [ajv](https://github.com/epoberezkin/ajv) is used to validate your config. We use [JSON Schema draft-07](https://json-schema.org/latest/json-schema-validation.html) and support all [validation keywords](https://github.com/epoberezkin/ajv/blob/master/KEYWORDS.md) and [formats](https://github.com/epoberezkin/ajv#formats). | ||
This will be the [`properties`](https://json-schema.org/understanding-json-schema/reference/object.html#properties) object of the JSON schema. That is, define `schema` as an object where each key is the name of your data's property and each value is a JSON schema used to validate that property. | ||
You should define your schema as an object where each key is the name of your data's property and each value is a JSON schema used to validate that property. See more [here](https://json-schema.org/understanding-json-schema/reference/object.html#properties). | ||
@example | ||
@@ -52,2 +50,43 @@ ``` | ||
/** | ||
Top-level properties for the schema, excluding `properties` field. | ||
@example | ||
``` | ||
import Conf from 'conf'; | ||
const store = new Conf({ | ||
projectName: 'foo', | ||
schema: {}, | ||
rootSchema: { | ||
additionalProperties: false | ||
} | ||
}); | ||
``` | ||
*/ | ||
rootSchema?: Omit<TypedJSONSchema, 'properties'>; | ||
/** | ||
[Options passed to AJV](https://ajv.js.org/options.html). | ||
Under the hood, the JSON Schema validator [ajv](https://ajv.js.org/json-schema.html) is used to validate your config. We use [JSON Schema draft-2020-12](https://json-schema.org/draft/2020-12/release-notes) and support all validation keywords and formats. | ||
**Note:** By default, `allErrors` and `useDefaults` are both set to `true`, but can be overridden. | ||
@example | ||
``` | ||
import Conf from 'conf'; | ||
const store = new Conf({ | ||
projectName: 'foo', | ||
schema: {}, | ||
rootSchema: { | ||
additionalProperties: false | ||
}, | ||
ajvOptions: { | ||
removeAdditional: true | ||
} | ||
}); | ||
``` | ||
*/ | ||
ajvOptions?: AjvOptions; | ||
/** | ||
Name of the config file (without extension). | ||
@@ -243,1 +282,2 @@ | ||
export type Unsubscribe = () => void; | ||
export type { CurrentOptions as AjvOptions } from 'ajv/dist/core.js'; |
{ | ||
"name": "conf", | ||
"version": "13.0.1", | ||
"version": "13.1.0", | ||
"description": "Simple config handling for your app or module", | ||
@@ -50,3 +50,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"ajv": "^8.16.0", | ||
"ajv": "^8.17.1", | ||
"ajv-formats": "^3.0.1", | ||
@@ -58,12 +58,12 @@ "atomically": "^2.0.3", | ||
"json-schema-typed": "^8.0.1", | ||
"semver": "^7.6.2", | ||
"uint8array-extras": "^1.1.0" | ||
"semver": "^7.6.3", | ||
"uint8array-extras": "^1.4.0" | ||
}, | ||
"devDependencies": { | ||
"@sindresorhus/tsconfig": "^5.0.0", | ||
"@types/node": "^20.14.2", | ||
"@sindresorhus/tsconfig": "^7.0.0", | ||
"@types/node": "^22.10.1", | ||
"@types/semver": "^7.5.8", | ||
"ava": "^6.1.3", | ||
"del": "^7.1.0", | ||
"del-cli": "^5.1.0", | ||
"ava": "^6.2.0", | ||
"del": "^8.0.0", | ||
"del-cli": "^6.0.0", | ||
"delay": "^6.0.0", | ||
@@ -73,5 +73,5 @@ "p-event": "^6.0.1", | ||
"ts-node": "^10.9.2", | ||
"tsd": "^0.31.0", | ||
"typescript": "^5.4.5", | ||
"xo": "^0.58.0" | ||
"tsd": "^0.31.2", | ||
"typescript": "^5.7.2", | ||
"xo": "^0.60.0" | ||
}, | ||
@@ -78,0 +78,0 @@ "ava": { |
@@ -67,6 +67,4 @@ # conf | ||
Under the hood, the JSON Schema validator [ajv](https://ajv.js.org/json-schema.html) is used to validate your config. We use [JSON Schema draft-2020-12](https://json-schema.org/draft/2020-12/release-notes) and support all validation keywords and formats. | ||
This will be the [`properties`](https://json-schema.org/understanding-json-schema/reference/object.html#properties) object of the JSON schema. That is, define `schema` as an object where each key is the name of your data's property and each value is a JSON schema used to validate that property. | ||
You should define your schema as an object where each key is the name of your data's property and each value is a JSON schema used to validate that property. See more [here](https://json-schema.org/understanding-json-schema/reference/object.html#properties). | ||
Example: | ||
@@ -104,2 +102,49 @@ | ||
#### rootSchema | ||
Type: `object` | ||
Top-level properties for the schema, excluding `properties` field. | ||
Example: | ||
```js | ||
import Conf from 'conf'; | ||
const store = new Conf({ | ||
projectName: 'foo', | ||
schema: { /* β¦ */ }, | ||
rootSchema: { | ||
additionalProperties: false | ||
} | ||
}); | ||
``` | ||
#### ajvOptions | ||
Type: `object` | ||
[Options passed to AJV](https://ajv.js.org/options.html). | ||
Under the hood, the JSON Schema validator [ajv](https://ajv.js.org/json-schema.html) is used to validate your config. We use [JSON Schema draft-2020-12](https://json-schema.org/draft/2020-12/release-notes) and support all validation keywords and formats. | ||
**Note:** By default, `allErrors` and `useDefaults` are both set to `true`, but can be overridden. | ||
Example: | ||
```js | ||
import Conf from 'conf'; | ||
const store = new Conf({ | ||
projectName: 'foo', | ||
schema: { /* β¦ */ }, | ||
rootSchema: { | ||
additionalProperties: false | ||
}, | ||
ajvOptions: { | ||
removeAdditional: true | ||
} | ||
}); | ||
``` | ||
#### migrations | ||
@@ -210,3 +255,3 @@ | ||
Type: `string`\ | ||
Type: `string` | ||
@@ -213,0 +258,0 @@ **Required if you specify the `migration` option.** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47457
735
506
+ Addedtype-fest@4.30.0(transitive)
- Removedtype-fest@4.30.1(transitive)
Updatedajv@^8.17.1
Updatedsemver@^7.6.3
Updateduint8array-extras@^1.4.0