Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup Node.js LTS
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: lts/*
cache: yarn
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: ${{ matrix.node }}
cache: yarn
Expand All @@ -40,6 +40,6 @@ jobs:
run: yarn run-s build lint test

- name: Codecov
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5
uses: codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/pkg-pr-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup Node.js LTS
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: lts/*
cache: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
fetch-depth: 0

- name: Setup Node.js LTS
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: lts/*
cache: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Setup Node.js LTS
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: lts/*
cache: yarn
Expand Down
935 changes: 0 additions & 935 deletions .yarn/releases/yarn-4.8.1.cjs

This file was deleted.

948 changes: 948 additions & 0 deletions .yarn/releases/yarn-4.9.1.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ plugins:
path: .yarn/plugins/plugin-prepare-lifecycle.cjs
spec: 'https://github.com/un-es/yarn-plugin-prepare-lifecycle/releases/download/v0.0.1/index.js'

yarnPath: .yarn/releases/yarn-4.8.1.cjs
yarnPath: .yarn/releases/yarn-4.9.1.cjs
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
],
"funding": "https://opencollective.com/un-ts",
"license": "MIT",
"packageManager": "yarn@4.8.1",
"packageManager": "yarn@4.9.1",
"engines": {
"node": ">=0.10.0"
},
"main": "lib/index.cjs",
"types": "lib/index.d.ts",
"module": "lib/index.js",
"exports": {
".": {
Expand All @@ -33,7 +34,6 @@
},
"./package.json": "./package.json"
},
"types": "lib/index.d.ts",
"files": [
"index.d.cts",
"lib",
Expand Down Expand Up @@ -71,7 +71,7 @@
"ajv": "^8.17.1"
},
"devDependencies": {
"@1stg/common-config": "^11.1.2",
"@1stg/common-config": "^13.0.0",
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.28.1",
"@commitlint/cli": "^19.8.0",
Expand Down
14 changes: 8 additions & 6 deletions src/ajv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ import type { SchemaVersion } from './types.js'
const ajvCache: Partial<Record<'default' | 'draft2020', AjvCore.default>> = {}

/**
* Retrieves an Ajv validator instance for a specified JSON Schema draft version.
* Retrieves an Ajv validator instance for a specified JSON Schema draft
* version.
*
* This function returns a cached Ajv instance if available, or creates a new one configured for either
* 'draft2019' (default) or 'draft2020'. The created instance is enhanced with a custom "migrateSchema" keyword
* that transforms JSON Schemas to be compatible with different specification drafts by adjusting properties
* such as "id", "$schema", "constant", "enum", and various numeric constraints.
* This function returns a cached Ajv instance if available, or creates a new
* one configured for either 'draft2019' (default) or 'draft2020'. The created
* instance is enhanced with a custom "migrateSchema" keyword that transforms
* JSON Schemas to be compatible with different specification drafts by
* adjusting properties such as "id", "$schema", "constant", "enum", and various
* numeric constraints.
*
* @param version - The target JSON Schema version (defaults to 'draft2019').
* @returns An Ajv instance configured for JSON Schema validation and migration.
*
* @remark The custom "migrateSchema" keyword may throw a TypeError if a schema's "id" is not a string, or an Error
* if the "id" format is invalid for the given version during the migration process.
*/
Expand Down
27 changes: 16 additions & 11 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import {
import type { SchemaVersion } from './types.js'

/**
* Recursively evaluates a JSON schema to determine if it reduces to a constant boolean value.
* Recursively evaluates a JSON schema to determine if it reduces to a constant
* boolean value.
*
* An empty schema (i.e., an object with no keys) is considered to be a constant true schema.
* If the schema has only the "not" property, the function evaluates the value of "not" recursively
* and returns its logical negation when it resolves to a boolean.
* An empty schema (i.e., an object with no keys) is considered to be a constant
* true schema. If the schema has only the "not" property, the function
* evaluates the value of "not" recursively and returns its logical negation
* when it resolves to a boolean.
*
* @param schema - The JSON schema object to evaluate.
* @returns A boolean indicating the constant result if determinable, or undefined if the schema's
* boolean value cannot be established.
* @returns A boolean indicating the constant result if determinable, or
* undefined if the schema's boolean value cannot be established.
*/
export function constantResultSchema(
schema: AnySchemaObject,
Expand All @@ -36,12 +38,15 @@ export function constantResultSchema(
/**
* Returns the JSON meta-schema corresponding to the specified schema version.
*
* This function selects the appropriate meta-schema constant based on the provided version,
* mapping 'draft7', 'draft2019', and 'draft2020' to their respective meta-schema definitions.
* If an unrecognized version is provided, the function returns undefined.
* This function selects the appropriate meta-schema constant based on the
* provided version, mapping 'draft7', 'draft2019', and 'draft2020' to their
* respective meta-schema definitions. If an unrecognized version is provided,
* the function returns undefined.
*
* @param version - The JSON Schema version (e.g., 'draft7', 'draft2019', 'draft2020').
* @returns The meta-schema constant for the specified version, or undefined if the version is not supported.
* @param version - The JSON Schema version (e.g., 'draft7', 'draft2019',
* 'draft2020').
* @returns The meta-schema constant for the specified version, or undefined if
* the version is not supported.
*/
export function metaSchema(version: SchemaVersion) {
switch (version) {
Expand Down
25 changes: 15 additions & 10 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import type { SchemaVersion } from './types.js'
/**
* Generates a migration schema object based on the specified version.
*
* This function constructs a schema object used for validating schema migrations. It selects between
* two draft schemas depending on whether the provided version is 'draft2020' or not, and returns an object
* with a unique `$id`, the chosen schema, and an `allOf` array that combines migration metadata with a reference
* to the base schema. For the 'draft2020' version, a `$dynamicAnchor` is added, whereas for other versions a
* `$recursiveAnchor` property is set.
* This function constructs a schema object used for validating schema
* migrations. It selects between two draft schemas depending on whether the
* provided version is 'draft2020' or not, and returns an object with a unique
* `$id`, the chosen schema, and an `allOf` array that combines migration
* metadata with a reference to the base schema. For the 'draft2020' version, a
* `$dynamicAnchor` is added, whereas for other versions a `$recursiveAnchor`
* property is set.
*
* @param version - The migration schema version (e.g., 'draft2020').
* @returns The migration schema object configured for the supplied version.
Expand All @@ -31,12 +33,15 @@ export function getMigrateSchema(version: SchemaVersion): SchemaObject {
/**
* Returns a schema migration function for the specified version.
*
* The returned function validates a provided schema against a migration schema and ensures its "$schema"
* property is set to the correct meta-schema for the given version. The migration validator is compiled
* on the first invocation and reused for subsequent validations.
* The returned function validates a provided schema against a migration schema
* and ensures its "$schema" property is set to the correct meta-schema for the
* given version. The migration validator is compiled on the first invocation
* and reused for subsequent validations.
*
* @param version - The schema version specifying which migration rules and meta-schema to use.
* @returns A function that, when given a schema object, validates it for migration and updates its "$schema" property.
* @param version - The schema version specifying which migration rules and
* meta-schema to use.
* @returns A function that, when given a schema object, validates it for
* migration and updates its "$schema" property.
*/
export function getMigrate(version: SchemaVersion) {
let migrate: ValidateFunction | undefined
Expand Down
Loading
Loading