diff --git a/.gitignore b/.gitignore index c2658d7..940d56a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +dist diff --git a/Schema.ts b/Schema.ts deleted file mode 100644 index 96a308c..0000000 --- a/Schema.ts +++ /dev/null @@ -1,165 +0,0 @@ -import SchemaArray from "./items/array" -import SchemaBoolean from "./items/boolean" -import SchemaEnum, { EnumLike } from "./items/enum" -import SchemaLiteral from "./items/literal" -import SchemaNullable from "./items/nullable" -import SchemaNumber from "./items/number" -import SchemaObject from "./items/object" -import SchemaString from "./items/string" -import { SchemaUnion } from "./items/union" -import SchemaItem from "./SchemaItem" -import { SchemaJSON } from "./types" - -export function parceable() { - - return (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => { - if (!(target instanceof SchemaItem)) { - throw new Error('the decorator is only usable on Schema') - } - - - const original = target[propertyKey] - - const t = function () { } - - descriptor.value = function (this: SchemaItem, ...args: Array) { - this.savedCalls.push({ name: propertyKey as string, args: args }) - const res = original.call(this, ...args) - return res - } - - return descriptor - } -} - -interface SchemaItemStatic { - new(...args: Array): SchemaItem -} - -type ExtractGeneric = T extends SchemaItem ? U : never - -export default class Schema { - private static registeredModules: Array = [ - SchemaArray, - SchemaBoolean, - SchemaEnum, - SchemaLiteral, - SchemaNullable, - SchemaObject, - SchemaString, - SchemaUnion - ] - - public static register(module: SchemaItemStatic) { - this.registeredModules.push(module) - } - - public static getModule(name: string) { - return this.registeredModules.find((it) => it.name === name) - } - - public static array( - ...inputs: ConstructorParameters> - ): SchemaArray { - return new SchemaArray(...inputs) - } - - public static boolean( - ...inputs: ConstructorParameters - ): SchemaBoolean { - return new SchemaBoolean(...inputs) - } - - public static enum( - ...inputs: ConstructorParameters> - ): SchemaEnum { - return new SchemaEnum(...inputs) - } - - /** - * - * @param input the literal value (note: append `as const` else the typing won't work correctly) - * @returns - */ - public static literal( - input: Type - ): SchemaLiteral { - return new SchemaLiteral(input) - } - - public static nullable( - ...inputs: ConstructorParameters> - ): SchemaNullable { - return new SchemaNullable(...inputs) - } - - public static number( - ...inputs: ConstructorParameters - ): SchemaNumber { - return new SchemaNumber(...inputs) - } - - public static object>>( - ...inputs: ConstructorParameters> - ): SchemaObject { - return new SchemaObject(...inputs) - } - - /** - * See {@link SchemaString} - */ - public static string( - ...inputs: ConstructorParameters - ): SchemaString { - return new SchemaString(...inputs) - } - - public static union>>( - ...inputs: ConstructorParameters> - ): SchemaUnion { - return new SchemaUnion(...inputs) - } - - public static fromJSON(json: SchemaJSON): SchemaItem { - - // get the module - const fn = this.getModule(json.i) - - // handle module not detected - if (!fn) { - throw new Error(`Schema cannot parse ${json.i}`) - } - - // init the module - const item = new fn(...(json.c?.map((it) => this.isSchemaJSON(it) ? Schema.fromJSON(it) : it) ?? [])) - - // handle validations - for (const validation of (json.f ?? [])) { - // validation not found in item :( - if (!(validation.n in item)) { - throw new Error('validation not available in Schema Item') - } - - // init the validation - (item[validation.n] as (...params: Array) => void)(...validation.a.map((it) => Schema.isSchemaJSON(it) ? Schema.fromJSON(it) : it)) - } - - // add the attributes - item.attrs(...json.a ?? []) - - - return item - } - - public static isSchemaJSON(data: unknown): data is SchemaJSON { - if (typeof data !== 'object' || data === null) { - return false - } - - if (!('i' in data)) { - return false - } - - return true - } -} diff --git a/bun.lockb b/bun.lockb deleted file mode 100755 index 93ab718..0000000 Binary files a/bun.lockb and /dev/null differ diff --git a/eslint.config.mjs b/eslint.config.mjs index df4b75e..3133653 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -8,11 +8,24 @@ export default [ js.configs.recommended, ...tseslint.configs.strictTypeChecked, ...tseslint.configs.stylisticTypeChecked, + { + ignores: [ + 'tests', + 'eslint.config.mjs', + 'dist', + 'index.ts' + ] + }, { languageOptions: { parserOptions: { - project: ['tsconfig.json'] + projectService: true, + tsconfigRootDir: import.meta.dirname, }, + }, + }, + { + languageOptions: { globals: { ...globals.node, ...globals.browser, @@ -23,16 +36,6 @@ export default [ '@typescript-eslint': typescriptEslint, '@stylistic': stylistic }, - ignores: [ - 'node_modules/', - 'out/', - '*.js', - '__tests__/', - 'src/route.ts', - 'dist/', - '.astro/', - '.diaz/' - ], rules: { '@stylistic/arrow-parens': [ diff --git a/index.ts b/index.ts index 29f2f42..85beba7 100644 --- a/index.ts +++ b/index.ts @@ -1,10 +1,12 @@ -import s from "./Schema" +import { Infer, s } from '.' -s.string() +const res = new s({ + a: s.object({ + p: s.string() + }) +}) +type Infered = Infer -/* -buffer -date -file -record -*/ +type Test = Infered['a']['p'] + +console.log(res.parse("{ hello: 'world' }")) diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..196e46e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,2805 @@ +{ + "name": "@dzeio/schema", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@dzeio/schema", + "version": "1.0.0", + "dependencies": { + "@dzeio/object-util": "^1.8.3", + "@standard-schema/spec": "^1.0.0", + "zod": "^3.24.2" + }, + "devDependencies": { + "@eslint/js": "^9.18.0", + "@stylistic/eslint-plugin": "^2.13.0", + "@types/bun": "^1.1.18", + "@typescript-eslint/eslint-plugin": "^8.21.0", + "globals": "^15.14.0", + "tsup": "^8.3.6", + "typescript": "^5.7.3", + "typescript-eslint": "^8.21.0", + "vitest": "^3.0.4" + } + }, + "node_modules/@dzeio/object-util": { + "version": "1.8.3", + "license": "MIT" + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.24.2", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.4.1", + "dev": true, + "license": "MIT", + "dependencies": { + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.12.1", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/config-array": { + "version": "0.19.1", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@eslint/object-schema": "^2.1.5", + "debug": "^4.3.1", + "minimatch": "^3.1.2" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/core": { + "version": "0.10.0", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "3.2.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^10.0.1", + "globals": "^14.0.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@eslint/js": { + "version": "9.18.0", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/object-schema": { + "version": "2.1.5", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/plugin-kit": { + "version": "0.2.5", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@eslint/core": "^0.10.0", + "levn": "^0.4.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@humanfs/core": { + "version": "0.19.1", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node": { + "version": "0.16.6", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "dependencies": { + "@humanfs/core": "^0.19.1", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node/node_modules/@humanwhocodes/retry": { + "version": "0.3.1", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/retry": { + "version": "0.4.1", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.8", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/set-array": "^1.2.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.24" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/set-array": { + "version": "1.2.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.0", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.25", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "dev": true, + "license": "MIT", + "optional": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.31.0", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.31.0", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@standard-schema/spec": { + "version": "1.0.0", + "license": "MIT" + }, + "node_modules/@stylistic/eslint-plugin": { + "version": "2.13.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/utils": "^8.13.0", + "eslint-visitor-keys": "^4.2.0", + "espree": "^10.3.0", + "estraverse": "^5.3.0", + "picomatch": "^4.0.2" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "peerDependencies": { + "eslint": ">=8.40.0" + } + }, + "node_modules/@types/bun": { + "version": "1.1.18", + "dev": true, + "license": "MIT", + "dependencies": { + "bun-types": "1.1.44" + } + }, + "node_modules/@types/estree": { + "version": "1.0.6", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/@types/node": { + "version": "20.12.14", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/ws": { + "version": "8.5.13", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/regexpp": "^4.10.0", + "@typescript-eslint/scope-manager": "8.21.0", + "@typescript-eslint/type-utils": "8.21.0", + "@typescript-eslint/utils": "8.21.0", + "@typescript-eslint/visitor-keys": "8.21.0", + "graphemer": "^1.4.0", + "ignore": "^5.3.1", + "natural-compare": "^1.4.0", + "ts-api-utils": "^2.0.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.8.0" + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/scope-manager": "8.21.0", + "@typescript-eslint/types": "8.21.0", + "@typescript-eslint/typescript-estree": "8.21.0", + "@typescript-eslint/visitor-keys": "8.21.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.8.0" + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.21.0", + "@typescript-eslint/visitor-keys": "8.21.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/type-utils": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/typescript-estree": "8.21.0", + "@typescript-eslint/utils": "8.21.0", + "debug": "^4.3.4", + "ts-api-utils": "^2.0.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.8.0" + } + }, + "node_modules/@typescript-eslint/types": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.21.0", + "@typescript-eslint/visitor-keys": "8.21.0", + "debug": "^4.3.4", + "fast-glob": "^3.3.2", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^2.0.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <5.8.0" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch": { + "version": "9.0.5", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/minimatch/node_modules/brace-expansion": { + "version": "2.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/@typescript-eslint/utils": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", + "@typescript-eslint/scope-manager": "8.21.0", + "@typescript-eslint/types": "8.21.0", + "@typescript-eslint/typescript-estree": "8.21.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.8.0" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.21.0", + "eslint-visitor-keys": "^4.2.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@vitest/expect": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "3.0.4", + "@vitest/utils": "3.0.4", + "chai": "^5.1.2", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "3.0.4", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.17" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^5.0.0 || ^6.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/pretty-format": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "3.0.4", + "pathe": "^2.0.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.0.4", + "magic-string": "^0.30.17", + "pathe": "^2.0.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyspy": "^3.0.2" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.0.4", + "loupe": "^3.1.2", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/acorn": { + "version": "8.14.0", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "dev": true, + "license": "MIT", + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/ajv": { + "version": "6.12.6", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ansi-regex": { + "version": "6.1.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "dev": true, + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/any-promise": { + "version": "1.3.0", + "dev": true, + "license": "MIT" + }, + "node_modules/argparse": { + "version": "2.0.1", + "dev": true, + "license": "Python-2.0", + "peer": true + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "dev": true, + "license": "MIT" + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.3", + "dev": true, + "license": "MIT", + "dependencies": { + "fill-range": "^7.1.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/bun-types": { + "version": "1.1.44", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "~20.12.8", + "@types/ws": "~8.5.10" + } + }, + "node_modules/bundle-require": { + "version": "5.1.0", + "dev": true, + "license": "MIT", + "dependencies": { + "load-tsconfig": "^0.2.3" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "peerDependencies": { + "esbuild": ">=0.18" + } + }, + "node_modules/cac": { + "version": "6.7.14", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/callsites": { + "version": "3.1.0", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/chai": { + "version": "5.1.2", + "dev": true, + "license": "MIT", + "dependencies": { + "assertion-error": "^2.0.1", + "check-error": "^2.1.1", + "deep-eql": "^5.0.1", + "loupe": "^3.1.0", + "pathval": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/check-error": { + "version": "2.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 16" + } + }, + "node_modules/chokidar": { + "version": "4.0.3", + "dev": true, + "license": "MIT", + "dependencies": { + "readdirp": "^4.0.1" + }, + "engines": { + "node": ">= 14.16.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "dev": true, + "license": "MIT" + }, + "node_modules/commander": { + "version": "4.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/consola": { + "version": "3.4.0", + "dev": true, + "license": "MIT", + "engines": { + "node": "^14.18.0 || >=16.10.0" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "dev": true, + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/debug": { + "version": "4.4.0", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/deep-eql": { + "version": "5.0.2", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/deep-is": { + "version": "0.1.4", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "dev": true, + "license": "MIT" + }, + "node_modules/emoji-regex": { + "version": "9.2.2", + "dev": true, + "license": "MIT" + }, + "node_modules/es-module-lexer": { + "version": "1.6.0", + "dev": true, + "license": "MIT" + }, + "node_modules/esbuild": { + "version": "0.24.2", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.24.2", + "@esbuild/android-arm": "0.24.2", + "@esbuild/android-arm64": "0.24.2", + "@esbuild/android-x64": "0.24.2", + "@esbuild/darwin-arm64": "0.24.2", + "@esbuild/darwin-x64": "0.24.2", + "@esbuild/freebsd-arm64": "0.24.2", + "@esbuild/freebsd-x64": "0.24.2", + "@esbuild/linux-arm": "0.24.2", + "@esbuild/linux-arm64": "0.24.2", + "@esbuild/linux-ia32": "0.24.2", + "@esbuild/linux-loong64": "0.24.2", + "@esbuild/linux-mips64el": "0.24.2", + "@esbuild/linux-ppc64": "0.24.2", + "@esbuild/linux-riscv64": "0.24.2", + "@esbuild/linux-s390x": "0.24.2", + "@esbuild/linux-x64": "0.24.2", + "@esbuild/netbsd-arm64": "0.24.2", + "@esbuild/netbsd-x64": "0.24.2", + "@esbuild/openbsd-arm64": "0.24.2", + "@esbuild/openbsd-x64": "0.24.2", + "@esbuild/sunos-x64": "0.24.2", + "@esbuild/win32-arm64": "0.24.2", + "@esbuild/win32-ia32": "0.24.2", + "@esbuild/win32-x64": "0.24.2" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/eslint": { + "version": "9.18.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@eslint-community/regexpp": "^4.12.1", + "@eslint/config-array": "^0.19.0", + "@eslint/core": "^0.10.0", + "@eslint/eslintrc": "^3.2.0", + "@eslint/js": "9.18.0", + "@eslint/plugin-kit": "^0.2.5", + "@humanfs/node": "^0.16.6", + "@humanwhocodes/module-importer": "^1.0.1", + "@humanwhocodes/retry": "^0.4.1", + "@types/estree": "^1.0.6", + "@types/json-schema": "^7.0.15", + "ajv": "^6.12.4", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.6", + "debug": "^4.3.2", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^8.2.0", + "eslint-visitor-keys": "^4.2.0", + "espree": "^10.3.0", + "esquery": "^1.5.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^8.0.0", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3" + }, + "bin": { + "eslint": "bin/eslint.js" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "jiti": "*" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + } + } + }, + "node_modules/eslint-scope": { + "version": "8.2.0", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "4.2.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree": { + "version": "10.3.0", + "dev": true, + "license": "BSD-2-Clause", + "dependencies": { + "acorn": "^8.14.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^4.2.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/esquery": { + "version": "1.6.0", + "dev": true, + "license": "BSD-3-Clause", + "peer": true, + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estree-walker": { + "version": "3.0.3", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/expect-type": { + "version": "1.1.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/fast-glob": { + "version": "3.3.3", + "dev": true, + "license": "MIT", + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.8" + }, + "engines": { + "node": ">=8.6.0" + } + }, + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "dev": true, + "license": "ISC", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/fastq": { + "version": "1.18.0", + "dev": true, + "license": "ISC", + "dependencies": { + "reusify": "^1.0.4" + } + }, + "node_modules/fdir": { + "version": "6.4.3", + "dev": true, + "license": "MIT", + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/file-entry-cache": { + "version": "8.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "flat-cache": "^4.0.0" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/fill-range": { + "version": "7.1.1", + "dev": true, + "license": "MIT", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/find-up": { + "version": "5.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/flat-cache": { + "version": "4.0.1", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "flatted": "^3.2.9", + "keyv": "^4.5.4" + }, + "engines": { + "node": ">=16" + } + }, + "node_modules/flatted": { + "version": "3.3.2", + "dev": true, + "license": "ISC", + "peer": true + }, + "node_modules/foreground-child": { + "version": "3.3.0", + "dev": true, + "license": "ISC", + "dependencies": { + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob": { + "version": "10.4.5", + "dev": true, + "license": "ISC", + "dependencies": { + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob-parent": { + "version": "6.0.2", + "dev": true, + "license": "ISC", + "peer": true, + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/glob/node_modules/minimatch": { + "version": "9.0.5", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob/node_modules/minimatch/node_modules/brace-expansion": { + "version": "2.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/globals": { + "version": "15.14.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/graphemer": { + "version": "1.4.0", + "dev": true, + "license": "MIT" + }, + "node_modules/has-flag": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/ignore": { + "version": "5.3.2", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/import-fresh": { + "version": "3.3.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/import-fresh/node_modules/resolve-from": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=0.8.19" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "dev": true, + "license": "MIT", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "dev": true, + "license": "ISC" + }, + "node_modules/jackspeak": { + "version": "3.4.3", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/cliui": "^8.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" + } + }, + "node_modules/joycon": { + "version": "3.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + } + }, + "node_modules/js-yaml": { + "version": "4.1.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/json-buffer": { + "version": "3.0.1", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/keyv": { + "version": "4.5.4", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "json-buffer": "3.0.1" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/lilconfig": { + "version": "3.1.3", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/antonk52" + } + }, + "node_modules/lines-and-columns": { + "version": "1.2.4", + "dev": true, + "license": "MIT" + }, + "node_modules/load-tsconfig": { + "version": "0.2.5", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + } + }, + "node_modules/locate-path": { + "version": "6.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "p-locate": "^5.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/lodash.sortby": { + "version": "4.7.0", + "dev": true, + "license": "MIT" + }, + "node_modules/loupe": { + "version": "3.1.2", + "dev": true, + "license": "MIT" + }, + "node_modules/lru-cache": { + "version": "10.4.3", + "dev": true, + "license": "ISC" + }, + "node_modules/magic-string": { + "version": "0.30.17", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, + "node_modules/merge2": { + "version": "1.4.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, + "node_modules/micromatch": { + "version": "4.0.8", + "dev": true, + "license": "MIT", + "dependencies": { + "braces": "^3.0.3", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "2.3.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/minimatch": { + "version": "3.1.2", + "dev": true, + "license": "ISC", + "peer": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minipass": { + "version": "7.1.2", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "dev": true, + "license": "MIT" + }, + "node_modules/mz": { + "version": "2.7.0", + "dev": true, + "license": "MIT", + "dependencies": { + "any-promise": "^1.0.0", + "object-assign": "^4.0.1", + "thenify-all": "^1.0.0" + } + }, + "node_modules/nanoid": { + "version": "3.3.8", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/natural-compare": { + "version": "1.4.0", + "dev": true, + "license": "MIT" + }, + "node_modules/object-assign": { + "version": "4.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/optionator": { + "version": "0.9.4", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/p-limit": { + "version": "3.1.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate": { + "version": "5.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "p-limit": "^3.0.2" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/package-json-from-dist": { + "version": "1.0.1", + "dev": true, + "license": "BlueOak-1.0.0" + }, + "node_modules/parent-module": { + "version": "1.0.1", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-scurry": { + "version": "1.11.1", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "lru-cache": "^10.2.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" + }, + "engines": { + "node": ">=16 || 14 >=14.18" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/pathe": { + "version": "2.0.2", + "dev": true, + "license": "MIT" + }, + "node_modules/pathval": { + "version": "2.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14.16" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.2", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/pirates": { + "version": "4.0.6", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, + "node_modules/postcss": { + "version": "8.5.1", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.8", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/postcss-load-config": { + "version": "6.0.1", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "lilconfig": "^3.1.1" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "jiti": ">=1.21.0", + "postcss": ">=8.0.9", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + }, + "postcss": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/punycode": { + "version": "2.3.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/queue-microtask": { + "version": "1.2.3", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/readdirp": { + "version": "4.1.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14.18.0" + }, + "funding": { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/resolve-from": { + "version": "5.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/reusify": { + "version": "1.0.4", + "dev": true, + "license": "MIT", + "engines": { + "iojs": ">=1.0.0", + "node": ">=0.10.0" + } + }, + "node_modules/rollup": { + "version": "4.31.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "1.0.6" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.31.0", + "@rollup/rollup-android-arm64": "4.31.0", + "@rollup/rollup-darwin-arm64": "4.31.0", + "@rollup/rollup-darwin-x64": "4.31.0", + "@rollup/rollup-freebsd-arm64": "4.31.0", + "@rollup/rollup-freebsd-x64": "4.31.0", + "@rollup/rollup-linux-arm-gnueabihf": "4.31.0", + "@rollup/rollup-linux-arm-musleabihf": "4.31.0", + "@rollup/rollup-linux-arm64-gnu": "4.31.0", + "@rollup/rollup-linux-arm64-musl": "4.31.0", + "@rollup/rollup-linux-loongarch64-gnu": "4.31.0", + "@rollup/rollup-linux-powerpc64le-gnu": "4.31.0", + "@rollup/rollup-linux-riscv64-gnu": "4.31.0", + "@rollup/rollup-linux-s390x-gnu": "4.31.0", + "@rollup/rollup-linux-x64-gnu": "4.31.0", + "@rollup/rollup-linux-x64-musl": "4.31.0", + "@rollup/rollup-win32-arm64-msvc": "4.31.0", + "@rollup/rollup-win32-ia32-msvc": "4.31.0", + "@rollup/rollup-win32-x64-msvc": "4.31.0", + "fsevents": "~2.3.2" + } + }, + "node_modules/run-parallel": { + "version": "1.2.0", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "queue-microtask": "^1.2.2" + } + }, + "node_modules/semver": { + "version": "7.6.3", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "dev": true, + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/siginfo": { + "version": "2.0.0", + "dev": true, + "license": "ISC" + }, + "node_modules/signal-exit": { + "version": "4.1.0", + "dev": true, + "license": "ISC", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/source-map": { + "version": "0.8.0-beta.0", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "whatwg-url": "^7.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/source-map-js": { + "version": "1.2.1", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/stackback": { + "version": "0.0.2", + "dev": true, + "license": "MIT" + }, + "node_modules/std-env": { + "version": "3.8.0", + "dev": true, + "license": "MIT" + }, + "node_modules/string-width": { + "version": "5.1.2", + "dev": true, + "license": "MIT", + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/emoji-regex": { + "version": "8.0.0", + "dev": true, + "license": "MIT" + }, + "node_modules/string-width-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/string-width-cjs/node_modules/strip-ansi/node_modules/ansi-regex": { + "version": "5.0.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "7.1.0", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", + "version": "6.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/sucrase": { + "version": "3.35.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.2", + "commander": "^4.0.0", + "glob": "^10.3.10", + "lines-and-columns": "^1.1.6", + "mz": "^2.7.0", + "pirates": "^4.0.1", + "ts-interface-checker": "^0.1.9" + }, + "bin": { + "sucrase": "bin/sucrase", + "sucrase-node": "bin/sucrase-node" + }, + "engines": { + "node": ">=16 || 14 >=14.17" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/thenify": { + "version": "3.3.1", + "dev": true, + "license": "MIT", + "dependencies": { + "any-promise": "^1.0.0" + } + }, + "node_modules/thenify-all": { + "version": "1.6.0", + "dev": true, + "license": "MIT", + "dependencies": { + "thenify": ">= 3.1.0 < 4" + }, + "engines": { + "node": ">=0.8" + } + }, + "node_modules/tinybench": { + "version": "2.9.0", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "0.3.2", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyglobby": { + "version": "0.2.10", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.4.2", + "picomatch": "^4.0.2" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/tinypool": { + "version": "1.0.2", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.0.0 || >=20.0.0" + } + }, + "node_modules/tinyrainbow": { + "version": "2.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/tinyspy": { + "version": "3.0.2", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/tr46": { + "version": "1.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.1.0" + } + }, + "node_modules/tree-kill": { + "version": "1.2.2", + "dev": true, + "license": "MIT", + "bin": { + "tree-kill": "cli.js" + } + }, + "node_modules/ts-api-utils": { + "version": "2.0.0", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18.12" + }, + "peerDependencies": { + "typescript": ">=4.8.4" + } + }, + "node_modules/ts-interface-checker": { + "version": "0.1.13", + "dev": true, + "license": "Apache-2.0" + }, + "node_modules/tsup": { + "version": "8.3.6", + "dev": true, + "license": "MIT", + "dependencies": { + "bundle-require": "^5.0.0", + "cac": "^6.7.14", + "chokidar": "^4.0.1", + "consola": "^3.2.3", + "debug": "^4.3.7", + "esbuild": "^0.24.0", + "joycon": "^3.1.1", + "picocolors": "^1.1.1", + "postcss-load-config": "^6.0.1", + "resolve-from": "^5.0.0", + "rollup": "^4.24.0", + "source-map": "0.8.0-beta.0", + "sucrase": "^3.35.0", + "tinyexec": "^0.3.1", + "tinyglobby": "^0.2.9", + "tree-kill": "^1.2.2" + }, + "bin": { + "tsup": "dist/cli-default.js", + "tsup-node": "dist/cli-node.js" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@microsoft/api-extractor": "^7.36.0", + "@swc/core": "^1", + "postcss": "^8.4.12", + "typescript": ">=4.5.0" + }, + "peerDependenciesMeta": { + "@microsoft/api-extractor": { + "optional": true + }, + "@swc/core": { + "optional": true + }, + "postcss": { + "optional": true + }, + "typescript": { + "optional": true + } + } + }, + "node_modules/type-check": { + "version": "0.4.0", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/typescript": { + "version": "5.7.3", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/typescript-eslint": { + "version": "8.21.0", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/eslint-plugin": "8.21.0", + "@typescript-eslint/parser": "8.21.0", + "@typescript-eslint/utils": "8.21.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.8.0" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "dev": true, + "license": "MIT" + }, + "node_modules/uri-js": { + "version": "4.4.1", + "dev": true, + "license": "BSD-2-Clause", + "peer": true, + "dependencies": { + "punycode": "^2.1.0" + } + }, + "node_modules/vite": { + "version": "6.0.11", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "^0.24.2", + "postcss": "^8.4.49", + "rollup": "^4.23.0" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", + "jiti": ">=1.21.0", + "less": "*", + "lightningcss": "^1.21.0", + "sass": "*", + "sass-embedded": "*", + "stylus": "*", + "sugarss": "*", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vite-node": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "cac": "^6.7.14", + "debug": "^4.4.0", + "es-module-lexer": "^1.6.0", + "pathe": "^2.0.2", + "vite": "^5.0.0 || ^6.0.0" + }, + "bin": { + "vite-node": "vite-node.mjs" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/vitest": { + "version": "3.0.4", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/expect": "3.0.4", + "@vitest/mocker": "3.0.4", + "@vitest/pretty-format": "^3.0.4", + "@vitest/runner": "3.0.4", + "@vitest/snapshot": "3.0.4", + "@vitest/spy": "3.0.4", + "@vitest/utils": "3.0.4", + "chai": "^5.1.2", + "debug": "^4.4.0", + "expect-type": "^1.1.0", + "magic-string": "^0.30.17", + "pathe": "^2.0.2", + "std-env": "^3.8.0", + "tinybench": "^2.9.0", + "tinyexec": "^0.3.2", + "tinypool": "^1.0.2", + "tinyrainbow": "^2.0.0", + "vite": "^5.0.0 || ^6.0.0", + "vite-node": "3.0.4", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@types/debug": "^4.1.12", + "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", + "@vitest/browser": "3.0.4", + "@vitest/ui": "3.0.4", + "happy-dom": "*", + "jsdom": "*" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@types/debug": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + } + } + }, + "node_modules/webidl-conversions": { + "version": "4.0.2", + "dev": true, + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "7.1.0", + "dev": true, + "license": "MIT", + "dependencies": { + "lodash.sortby": "^4.7.0", + "tr46": "^1.0.1", + "webidl-conversions": "^4.0.2" + } + }, + "node_modules/which": { + "version": "2.0.2", + "dev": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/word-wrap": { + "version": "1.2.5", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/wrap-ansi": { + "version": "8.1.0", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/string-width": { + "version": "4.2.3", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/string-width/node_modules/emoji-regex": { + "version": "8.0.0", + "dev": true, + "license": "MIT" + }, + "node_modules/wrap-ansi-cjs/node_modules/strip-ansi": { + "version": "6.0.1", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi-cjs/node_modules/strip-ansi/node_modules/ansi-regex": { + "version": "5.0.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/wrap-ansi/node_modules/ansi-styles": { + "version": "6.2.1", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/yocto-queue": { + "version": "0.1.0", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/zod": { + "version": "3.24.2", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz", + "integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + } + } +} diff --git a/package.json b/package.json index a9b9b89..c0cf828 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,43 @@ { - "dependencies": { - "@dzeio/object-util": "^1.8.3", - "@eslint/js": "^9.18.0", - "@stylistic/eslint-plugin": "^2.13.0", - "@types/bun": "^1.1.18", - "@typescript-eslint/eslint-plugin": "^8.21.0", - "globals": "^15.14.0", - "typescript": "^5.7.3", - "typescript-eslint": "^8.21.0", - "vitest": "^3.0.4" - } -} \ No newline at end of file + "name": "@dzeio/schema", + "version": "0.0.2", + "dependencies": { + "@dzeio/object-util": "^1.8.3" + }, + "main": "./dist/Schema.js", + "module": "./dist/Schema.mjs", + "types": "./dist/Schema.d.ts", + "files": [ + "dist" + ], + "exports": { + ".": { + "require": { + "types": "./dist/Schema.d.ts", + "default": "./dist/Schema.js" + }, + "import": { + "types": "./dist/Schema.d.mts", + "default": "./dist/Schema.mjs" + } + } + }, + "devDependencies": { + "@eslint/js": "^9.18.0", + "@standard-schema/spec": "^1.0.0", + "@stylistic/eslint-plugin": "^2.13.0", + "@types/bun": "^1.1.18", + "@typescript-eslint/eslint-plugin": "^8.21.0", + "globals": "^15.14.0", + "tsup": "^8.3.6", + "typescript": "^5.7.3", + "typescript-eslint": "^8.21.0", + "vitest": "^3.0.4" + }, + "scripts": { + "test": "bun test", + "lint": "eslint", + "build": "rm -rf dist && tsup ./src/Schema.ts --format cjs,esm --dts --clean", + "prepublishOnly": "rm -rf dist && tsup ./src/Schema.ts --format cjs,esm --dts --clean" + } +} diff --git a/src/Schema.ts b/src/Schema.ts new file mode 100644 index 0000000..086b52c --- /dev/null +++ b/src/Schema.ts @@ -0,0 +1,241 @@ +/* eslint-disable id-blacklist */ +import { parseForm, parseFormData, parseQuery } from 'helpers' +import SchemaDate from 'items/date' +import SchemaRecord from 'items/record' +import SchemaArray from './items/array' +import SchemaBoolean from './items/boolean' +import SchemaEnum, { EnumLike } from './items/enum' +import SchemaLiteral from './items/literal' +import SchemaNullable from './items/nullable' +import SchemaNumber from './items/number' +import SchemaObject from './items/object' +import SchemaString from './items/string' +import SchemaUnion from './items/union' +import SchemaItem from './SchemaItem' +import { SchemaJSON } from './types' + +export function parceable() { + + return (target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => { + // make sure the target is of SchemaItem + if (!(target instanceof SchemaItem)) { + throw new Error('the decorator is only usable on Schema') + } + + // make sur the property exists in the target + if (!(propertyKey in target)) { + throw new Error('property not set in object') + } + + // @ts-expect-error call a function defined from calls of collable + const original = target[propertyKey] as (...args: Array) => unknown + + // replace original function with modified one + descriptor.value = function(this: SchemaItem, ...args: Array) { + this.savedCalls.push({ name: propertyKey as string, args: args as Array }) + const res: unknown = original.call(this, ...args) + return res + } + + // return the modified descriptor + return descriptor + } +} + +type SchemaItemStatic = new (...args: Array) => SchemaItem + +export const Types = { + Array: SchemaArray, + Boolean: SchemaBoolean, + Date: SchemaDate, + Enum: SchemaEnum, + Literal: SchemaLiteral, + Nullable: SchemaNullable, + Object: SchemaObject, + Record: SchemaRecord, + String: SchemaString, + Union: SchemaUnion +} as const + +export default class Schema = Record> extends SchemaObject { + private static registeredModules: Array = [ + SchemaArray, + SchemaBoolean, + SchemaDate, + SchemaEnum, + SchemaLiteral, + SchemaNullable, + SchemaObject, + SchemaRecord, + SchemaString, + SchemaUnion + ] + + public static register(module: SchemaItemStatic) { + this.registeredModules.push(module) + } + + public static getModule(name: string) { + return this.registeredModules.find((it) => it.name === name) + } + + public static array( + ...inputs: ConstructorParameters> + ): SchemaArray { + return new SchemaArray(...inputs) + } + + public static boolean( + ...inputs: ConstructorParameters + ): SchemaBoolean { + return new SchemaBoolean(...inputs) + } + + public static date( + ...inputs: ConstructorParameters + ): SchemaDate { + return new SchemaDate(...inputs) + } + + public static enum( + ...inputs: ConstructorParameters> + ): SchemaEnum { + return new SchemaEnum(...inputs) + } + + /** + * + * @param input the literal value (note: append `as const` else the typing won't work correctly) + * @returns + */ + public static literal( + input: Type + ): SchemaLiteral { + return new SchemaLiteral(input) + } + + public static nullable( + ...inputs: ConstructorParameters> + ): SchemaNullable { + return new SchemaNullable(...inputs) + } + + public static number( + ...inputs: ConstructorParameters + ): SchemaNumber { + return new SchemaNumber(...inputs) + } + + public static object>( + ...inputs: ConstructorParameters> + ): SchemaObject { + return new SchemaObject(...inputs) + } + + public static record( + ...inputs: ConstructorParameters> + ): SchemaRecord { + return new SchemaRecord(...inputs) + } + + /** + * See {@link SchemaString} + */ + public static string( + ...inputs: ConstructorParameters + ): SchemaString { + return new SchemaString(...inputs) + } + + public static union>( + ...inputs: ConstructorParameters> + ): SchemaUnion { + return new SchemaUnion(...inputs) + } + + public static fromJSON(json: SchemaJSON): SchemaItem { + + // get the module + const fn = this.getModule(json.i) + + // handle module not detected + if (!fn) { + throw new Error(`Schema cannot parse ${json.i}`) + } + + // init the module + const item = new fn(...(json.c?.map((it) => this.isSchemaJSON(it) ? Schema.fromJSON(it) : it) ?? [])) + + // handle validations + for (const validation of (json.f ?? [])) { + // validation not found in item :( + if (!(validation.n in item)) { + throw new Error('validation not available in Schema Item') + } + + // init the validation + // @ts-expect-error call a function defined from calls of collable + (item[validation.n] as (...params: Array) => void)(...validation.a?.map((it) => Schema.isSchemaJSON(it) ? Schema.fromJSON(it) : it) ?? []) + } + + // add the attributes + item.attrs(...json.a ?? []) + + + return item + } + + public static isSchemaJSON(data: unknown): data is SchemaJSON { + if (typeof data !== 'object' || data === null) { + return false + } + + if (!('i' in data)) { + return false + } + + return true + } + + /** + * @deprecated use helper `parseQuery` + */ + public validateQuery(query: URLSearchParams, fast = false) { + return parseQuery(this, query, { fast }) + } + + /** + * @deprecated use `parse` + */ + public validate(input: unknown, fast = false) { + return this.parse(input, { fast }) + } + + /** + * @deprecated use helper `parseForm` + */ + public validateForm(form: HTMLFormElement, fast = false) { + return parseForm(this, form, { fast }) + } + + /** + * @deprecated use helper `parseFormData` + */ + public validateFormData(data: FormData, fast = false) { + return parseFormData(this, data, { fast }) + } +} + +export const s = Schema + +export * from './helpers' +export type * from './types.d.ts' + +export { + SchemaArray, + SchemaBoolean, SchemaDate, SchemaEnum, SchemaItem, SchemaLiteral, + SchemaNullable, + SchemaNumber, + SchemaObject, SchemaRecord, SchemaString, + SchemaUnion +} diff --git a/SchemaItem.ts b/src/SchemaItem.ts similarity index 75% rename from SchemaItem.ts rename to src/SchemaItem.ts index 5512d51..bdfb303 100644 --- a/SchemaItem.ts +++ b/src/SchemaItem.ts @@ -1,37 +1,41 @@ -import Schema from "./Schema" -import { SchemaJSON, ValidationError, ValidationResult } from "./types" +/* eslint-disable id-length */ +import { objectClean } from '@dzeio/object-util' +import { StandardSchemaV1 } from '@standard-schema/spec' +import Schema, { SchemaNullable } from './Schema' +import { SchemaJSON, ValidationError, ValidationResult } from './types' +export default abstract class SchemaItem implements StandardSchemaV1 { -export default abstract class SchemaItem { - - private invalidError = 'the field is invalid' - - /** - * list of attributes for custom works - */ - public readonly attributes: Array = [] - - public attrs(...attributes: Array) { - this.attributes.concat(attributes) - return this - } - - public setInvalidError(err: string): this { - this.invalidError = err - return this - } - - public clone(): this { - return Schema.fromJSON(this.toJSON()) as this + // standard Schema V1 spec + public '~standard': StandardSchemaV1.Props = { + vendor: 'aptatio', + version: 1, + validate: (value: unknown) => { + const res = this.parse(value) + if (!res.valid) { + return { + issues: res.errors + } + } + return { + value: res.object, + issues: res.errors, + } + } } /** - * schemas implementing unwrap can return their child component (mostly the value) - * - * ex: s.record(s.number(), s.string()) returns s.string() - * - * es2: s.nullable(s.string()) returns s.string() + * keep public ? */ - public unwrap?(): SchemaItem + public validations: Array<{ + fn: (input: Type) => boolean + error?: string | undefined + }> = [] + + /** + * Function calls saved for serialization + */ + public savedCalls: Array<{ name: string, args: Array | IArguments | undefined }> = [] + /** * Pre process the variable for various reasons @@ -53,23 +57,51 @@ export default abstract class SchemaItem { public postProcess: Array<(input: Type) => Type> = [] /** - * keep public ? + * list of attributes for custom works */ - public validations: Array<{ - fn: (input: Type) => boolean - error?: string | undefined - }> = [] - - public savedCalls: Array<{ name: string, args: Array | IArguments | undefined }> = [] + public readonly attributes: Array = [] private readonly items?: Array + private invalidError = 'the field is invalid' + public constructor(items?: Array | IArguments) { if (items && items.length > 0) { this.items = Array.isArray(items) ? items : Array.from(items) } } + public attrs(...attributes: Array) { + this.attributes.concat(attributes) + return this + } + + public attr(...attributes: Array) { + return this.attrs(...attributes) + } + + public setInvalidError(err: string): this { + this.invalidError = err + return this + } + + public clone(): this { + return Schema.fromJSON(this.toJSON()) as this + } + + public nullable(): SchemaNullable { + return new SchemaNullable(this) + } + + /** + * schemas implementing unwrap can return their child component (mostly the value) + * + * ex: s.record(s.number(), s.string()) returns s.string() + * + * es2: s.nullable(s.string()) returns s.string() + */ + public unwrap?(): SchemaItem + public parse(input: unknown, options?: { fast?: boolean }): ValidationResult { // pre process the variable for (const preProcess of this.preProcess) { @@ -95,6 +127,7 @@ export default abstract class SchemaItem { }) // if the system should be fast, stop checking for other errors + // eslint-disable-next-line max-depth if (options?.fast) { return { valid: false, @@ -119,26 +152,27 @@ export default abstract class SchemaItem { input = postProcess(input as Type) } - // validate that the pre process handled correctly the variable - if (!this.isOfType(input)) { - throw new Error('Post process error occured :(') - } - return { valid: true, - object: input + object: input as Type } } public toJSON(): SchemaJSON { - return { + // build the JSON + const res = { i: this.constructor.name, a: this.attributes.length > 0 ? this.attributes : undefined, c: this.items?.map((it) => it instanceof SchemaItem ? it.toJSON() : it), f: this.savedCalls .map((it) => (it.args ? { n: it.name, a: Array.from(it.args) } : { n: it.name })) } + + // cleanup the object from undefined to make it smaller + objectClean(res, { deep: false }) + + return res } protected addValidation(fn: ((input: Type) => boolean) | { fn: (input: Type) => boolean, error?: string }, error?: string) { @@ -148,6 +182,7 @@ export default abstract class SchemaItem { return this } + // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents protected addPreProcess(fn: (input: unknown) => Type | unknown) { this.preProcess.push(fn) diff --git a/src/helpers.ts b/src/helpers.ts new file mode 100644 index 0000000..657bac1 --- /dev/null +++ b/src/helpers.ts @@ -0,0 +1,60 @@ +import { objectGet, objectLoop, objectSet } from '@dzeio/object-util' +import SchemaArray from 'items/array' +import SchemaBoolean from 'items/boolean' +import SchemaNullable from 'items/nullable' +import SchemaObject from 'items/object' +import type SchemaItem from 'SchemaItem' + +export function parseQuery(model: T, query: URLSearchParams, opts?: Parameters[1]): ReturnType { + const record: Record = {} + for (const [key, value] of query) { + record[key] = value + } + + return model.parse(record, opts) as ReturnType +} + +export function parseFormData(model: T, data: FormData, opts?: Parameters[1]): ReturnType { + const record: Record = {} + // console.log('VALIDATE FORM DATA data', data) + for (const [key, value] of data) { + // console.log('parse', key, value) + const isArray = model.model[key].isOfType([]) ?? false + // record[key] = isArray ? data.getAll(key) : value + objectSet(record, key.split('.').map((it) => /^\d+$/g.test(it) ? parseInt(it, 10) : it), isArray ? data.getAll(key) : value) + } + + // quick hack to handle FormData not returning Checkboxes + const handleBoolean = (value: SchemaItem, keys: Array) => { + if (value instanceof SchemaNullable) { + handleBoolean(value.unwrap(), keys) + } + + if (value instanceof SchemaArray) { + const elements: Array | undefined = objectGet(record, keys) + for (let it = 0; it < (elements?.length ?? 0); it++) { + handleBoolean(value.unwrap(), [...keys, it]) + } + } + + if (value instanceof SchemaObject) { + handleSchemaForBoolean(value.model as Record, keys) + } + + if (value instanceof SchemaBoolean) { + objectSet(record, keys, !!data.get(keys.join('.'))) + } + } + const handleSchemaForBoolean = (modl: Record, keys: Array = []) => { + objectLoop(modl, (value, key) => { + handleBoolean(value as unknown as SchemaItem, [...keys, key]) + }) + } + handleSchemaForBoolean(model.model) + // console.log(JSON.stringify(record, undefined, 2)) + return model.parse(record, opts) as ReturnType +} + +export function parseForm(model: T, form: HTMLFormElement, opts?: Parameters[1]): ReturnType { + return parseFormData(model, new FormData(form), opts) +} diff --git a/items/array.ts b/src/items/array.ts similarity index 60% rename from items/array.ts rename to src/items/array.ts index 7d00d19..e15afd6 100644 --- a/items/array.ts +++ b/src/items/array.ts @@ -1,13 +1,9 @@ -import { parceable } from "../Schema" -import SchemaItem from "../SchemaItem" -import { SchemaInfer, ValidationError, ValidationResult } from "../types" +import { parceable } from '../Schema' +import SchemaItem from '../SchemaItem' +import { SchemaInfer, ValidationError, ValidationResult } from '../types' export default class SchemaArray extends SchemaItem>> { - public constructor(public readonly values: Type) { super(arguments) } - - public unwrap() { - return this.values - } + public constructor(public readonly values: Type) { super([values]) } /** * transform the array so it only contains one of each elements @@ -22,7 +18,7 @@ export default class SchemaArray extends SchemaItem>> { // check errors from itself - let { valid, object, errors = [] } = super.parse(input, options) + const { valid, object, errors = [] } = super.parse(input, options) // skip checking childs if self is not valid (maybe still try to check childs whan fast is false ?) if (!valid) { @@ -37,39 +33,49 @@ export default class SchemaArray extends SchemaItem = [] for (let idx = 0; idx < (object as Array).length; idx++) { const item = (object as Array)[idx] - const res = this.values.parse(item) - if (res.errors && res.errors.length > 0) { - const errors = res.errors.map((it) => ({ - ...it, - field: it.field ? `${idx}.${it.field}` : idx.toString() - })) - if (options?.fast) { - return { - valid: false, - object: clone as any, - errors: errors - } - } - errs.push(...errors) - } else { + const res: ValidationResult> = this.values.parse(item) + + // handle valid child schema + if (res.valid) { clone.push(res.object) + continue } + + // handle child errors + const errss = res.errors.map((it) => ({ + ...it, + field: it.field ? `${idx}.${it.field}` : idx.toString() + })) + + if (options?.fast) { + return { + valid: false, + object: clone, + errors: errss + } + } + errs.push(...errss) } if (errs.length > 0) { return { valid: false, - object: clone as any, + object: clone, errors: errs } } return { valid: true, - object: clone as any + object: clone } } + + public override unwrap(): Type { + return this.values + } + public override isOfType(input: unknown): input is Array> { return Array.isArray(input) } diff --git a/items/boolean.ts b/src/items/boolean.ts similarity index 88% rename from items/boolean.ts rename to src/items/boolean.ts index 0f992ea..6cfc40b 100644 --- a/items/boolean.ts +++ b/src/items/boolean.ts @@ -1,5 +1,5 @@ -import { parceable } from "../Schema" -import SchemaItem from "../SchemaItem" +import { parceable } from '../Schema' +import SchemaItem from '../SchemaItem' export default class SchemaBoolean extends SchemaItem { diff --git a/src/items/date.ts b/src/items/date.ts new file mode 100644 index 0000000..81812bd --- /dev/null +++ b/src/items/date.ts @@ -0,0 +1,8 @@ +import SchemaItem from '../SchemaItem' + +export default class SchemaDate extends SchemaItem { + + public override isOfType(input: unknown): input is Date { + return input instanceof Date + } +} diff --git a/items/enum.ts b/src/items/enum.ts similarity index 89% rename from items/enum.ts rename to src/items/enum.ts index ebea38f..ad1adc0 100644 --- a/items/enum.ts +++ b/src/items/enum.ts @@ -1,6 +1,6 @@ import SchemaItem from '../SchemaItem' -export type EnumLike = { +export interface EnumLike { [k: string]: string | number [n: number]: string } @@ -21,7 +21,7 @@ export default class SchemaEnum extends SchemaItem Object.values(this.templateEnum).includes(input), - message: `Input is not part of ${templateEnum.constructor.name}` + error: `Input is not part of ${templateEnum.constructor.name}` }) } diff --git a/items/literal.ts b/src/items/literal.ts similarity index 65% rename from items/literal.ts rename to src/items/literal.ts index c7cff1c..97cd6ff 100644 --- a/items/literal.ts +++ b/src/items/literal.ts @@ -1,10 +1,10 @@ -import SchemaItem from "../SchemaItem" +import SchemaItem from '../SchemaItem' export default class SchemaLiteral extends SchemaItem { public constructor(private readonly value: Type) { - super(arguments) + super([value]) - this.validations.push({ fn: (value) => value === this.value }) + this.validations.push({ fn: (it) => it === this.value }) } public override isOfType(input: unknown): input is Type { diff --git a/items/nullable.ts b/src/items/nullable.ts similarity index 57% rename from items/nullable.ts rename to src/items/nullable.ts index 39bb05f..4a7b732 100644 --- a/items/nullable.ts +++ b/src/items/nullable.ts @@ -1,14 +1,14 @@ -import SchemaItem from "../SchemaItem" -import { SchemaInfer, ValidationResult } from "../types" +import SchemaItem from '../SchemaItem' +import { SchemaInfer, ValidationResult } from '../types' export default class SchemaNullable extends SchemaItem | undefined> { - public constructor(public readonly child: Type) { super(arguments) } + public constructor(public readonly child: Type) { super([child]) } - public unwrap() { + public unwrap(): Type { return this.child } - public parse(input: unknown, options?: { fast?: boolean }): ValidationResult> { + public override parse(input: unknown, options?: { fast?: boolean }): ValidationResult | undefined> { if (this.isNull(input)) { return { valid: true, @@ -16,7 +16,7 @@ export default class SchemaNullable extends SchemaItem< } } - return this.child.parse(input) + return this.child.parse(input, options) } public override isOfType(input: unknown): input is SchemaInfer | undefined { diff --git a/items/number.ts b/src/items/number.ts similarity index 100% rename from items/number.ts rename to src/items/number.ts index 2748092..2741c1a 100644 --- a/items/number.ts +++ b/src/items/number.ts @@ -3,14 +3,6 @@ import SchemaItem from '../SchemaItem' export default class SchemaNumber extends SchemaItem { - public min(...params: Parameters): this { - return this.gte(...params) - } - - public max(...params: Parameters): this { - return this.lte(...params) - } - /** * validate that the number is less or equal than {@link value} * @param value the maxumum value (inclusive) @@ -92,4 +84,12 @@ export default class SchemaNumber extends SchemaItem { public override isOfType(input: unknown): input is number { return typeof input === 'number' && !Number.isNaN(input) } + + public min(...params: Parameters): this { + return this.gte(...params) + } + + public max(...params: Parameters): this { + return this.lte(...params) + } } diff --git a/items/object.ts b/src/items/object.ts similarity index 59% rename from items/object.ts rename to src/items/object.ts index edeb67b..d769948 100644 --- a/items/object.ts +++ b/src/items/object.ts @@ -1,21 +1,21 @@ -import { isObject, objectLoop, objectClone } from '@dzeio/object-util' -import SchemaItem from "../SchemaItem" -import { SchemaInfer, ValidationResult } from "../types" +import { isObject, objectClone, objectLoop } from '@dzeio/object-util' +import SchemaItem from '../SchemaItem' +import { SchemaInfer, ValidationResult } from '../types' -type ModelInfer>> = { +type ModelInfer> = { [key in keyof M]: SchemaInfer } -export default class SchemaObject>> extends SchemaItem> { - public id: string = 'object' +export default class SchemaObject = Record> extends SchemaItem> { + public id = 'object' public constructor(public readonly model: T) { - super(arguments) + super([model]) } public override parse(input: unknown, options?: { fast?: boolean }): ValidationResult> { // check errors from itself - let { valid, object, errors = [] } = super.parse(objectClone(input), options) + const { valid, object, errors = [] } = super.parse(input, options) // skip checking childs if self is not valid (maybe still try to check childs whan fast is false ?) if (!valid) { @@ -26,20 +26,26 @@ export default class SchemaObject>> ext } as ValidationResult> } + const clone = objectClone(object) + // loop through the childs objectLoop(this.model, (childSchema, key) => { - const childValue = object![key] + const childValue = clone[key] // parse the child const child = childSchema.parse(childValue) // add errors - if ((child.errors?.length ?? 0) > 0) { - errors.push(...child.errors!) + if (!child.valid) { + errors.push(...child.errors.map((it) => ({ + ...it, + field: it.field ? `${key}.${it.field}` : key + }))) } // @ts-expect-error while it's a generic we know by proof above that it's valid ! - object![key] = child.object + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + clone[key] = child.object // skip rest of items if current one is invalid return child.valid || !options?.fast @@ -49,7 +55,7 @@ export default class SchemaObject>> ext return { valid: errors.length === 0, errors: errors, - object: object + object: clone } as ValidationResult> } diff --git a/src/items/record.ts b/src/items/record.ts new file mode 100644 index 0000000..3303810 --- /dev/null +++ b/src/items/record.ts @@ -0,0 +1,55 @@ +import { isObject, objectLoop } from '@dzeio/object-util' +import SchemaItem from '../SchemaItem' +import { SchemaInfer, ValidationResult } from '../types' + +export default class SchemaRecord extends SchemaItem, SchemaInfer>> { + + public constructor(private readonly keys: Keys, private readonly values: Values) { + super([keys, values]) + } + + public parse(input: unknown, options?: { fast?: boolean }): ValidationResult, SchemaInfer>> { + + // check errors from itself + const { valid, object, errors = [] } = super.parse(input, options) + + // skip checking childs if self is not valid (maybe still try to check childs whan fast is false ?) + if (!valid) { + return { + valid, + object, + errors + } as ValidationResult> + } + + const clone: Partial> = {} + objectLoop(object, (value, key: string | number) => { + const res1 = this.keys.parse(key) + const res2 = this.values.parse(value) + if (!res1.valid || !res2.valid) { + errors.push(...((res1.errors ?? []).concat(...(res2.errors ?? []))).map((it) => ({ + message: it.message, + field: it.field ? `${key as string}.${it.field}` : key.toString() + }))) + } else { + // @ts-expect-error normal behavior + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + clone[res1.object] = res2.object + } + + // skip completion if fast is enabled + return errors.length === 0 || !options?.fast + }) + + // answer ! + return { + valid: errors.length === 0, + errors: errors, + object: clone + } as ValidationResult> + } + + public override isOfType(input: unknown): input is Record, SchemaInfer> { + return isObject(input) && Object.prototype.toString.call(input) === '[object Object]' + } +} diff --git a/items/string.ts b/src/items/string.ts similarity index 95% rename from items/string.ts rename to src/items/string.ts index e4518e1..974195b 100644 --- a/items/string.ts +++ b/src/items/string.ts @@ -1,16 +1,7 @@ -import { parceable } from "../Schema" -import SchemaItem from "../SchemaItem" +import { parceable } from '../Schema' +import SchemaItem from '../SchemaItem' export default class SchemaString extends SchemaItem { - public id = 'string' - - public minLength(value: number, message?: string) { - return this.min(value, message) - } - - public maxLength(value: number, message?: string) { - return this.max(value, message) - } /** * force the input text to be a minimum of `value` size @@ -89,6 +80,13 @@ export default class SchemaString extends SchemaItem { return this } + public minLength(value: number, message?: string) { + return this.min(value, message) + } + + public maxLength(value: number, message?: string) { + return this.max(value, message) + } public override isOfType(input: unknown): input is string { return typeof input === 'string' diff --git a/items/union.ts b/src/items/union.ts similarity index 81% rename from items/union.ts rename to src/items/union.ts index 544c196..860f26e 100644 --- a/items/union.ts +++ b/src/items/union.ts @@ -1,8 +1,8 @@ import SchemaItem from '../SchemaItem' import { SchemaInfer, ValidationResult } from '../types' -type ItemType>> = SchemaInfer -export class SchemaUnion>> extends SchemaItem> { +type ItemType> = SchemaInfer +export default class SchemaUnion> extends SchemaItem> { private schemas: T @@ -14,7 +14,7 @@ export class SchemaUnion>> extends SchemaItem> { // check errors from itself - let { valid, object, errors = [] } = super.parse(input, options) + const { valid, object, errors = [] } = super.parse(input, options) // skip checking childs if self is not valid (maybe still try to check childs whan fast is false ?) if (!valid) { diff --git a/src/types.d.ts b/src/types.d.ts new file mode 100644 index 0000000..e328deb --- /dev/null +++ b/src/types.d.ts @@ -0,0 +1,57 @@ +import SchemaItem from './SchemaItem' + +export type SchemaInfer = Type extends SchemaItem ? X : never +export type Infer = SchemaInfer + +export interface ValidationError { + message: string + field?: string + value?: unknown +} + +export type ValidationResult = { + object: T + valid: true + errors?: undefined +} | { + valid: false + object?: (T extends object ? Partial : T) | undefined + errors: Array +} + +export type ValidationResultOld = { + object: T + valid: true + error?: undefined +} | { + valid: false + object?: (T extends object ? Partial : T) | undefined + error: Array +} + +export interface SchemaJSON { + i: string + a?: Array | undefined + c?: Array | undefined + f?: Array<{ + n: string + a?: Array | undefined + }> | undefined +} + +/** +* @deprecated use `SchemaJSON` +*/ +export type SchemaItemJSON = SchemaJSON + +/** +* @deprecated use `Record` +*/ +export type Model = Record + +/** +* @deprecated +*/ +export type ModelInfer = { + [key in keyof M]: SchemaInfer +} diff --git a/tests/Schema.test.ts b/tests/Schema.test.ts index e8984de..7da8717 100644 --- a/tests/Schema.test.ts +++ b/tests/Schema.test.ts @@ -1,5 +1,5 @@ import { expect, test } from 'bun:test' -import s from '../Schema' +import s from '../src/Schema' test('number enum', () => { enum Test { @@ -74,6 +74,13 @@ test('object', () => { expect(schema.parse({ a: 'a', b: '1' }).valid).toBe(false) }) + +test('record', () => { + const schema = s.record(s.string(), s.number()) + expect(schema.parse({ a: 1, b: 2 }).valid).toBe(true) + expect(schema.parse({ a: 1, b: '1' }).valid).toBe(false) +}) + test('string', () => { const schema = s.string() expect(schema.parse('1').valid).toBe(true) diff --git a/tsconfig.json b/tsconfig.json index 4a78121..391af21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,34 @@ { - "exclude": [ - "cypress" + "include": [ + "src", ], "compilerOptions": { + // Compilation "baseUrl": "src", + "target": "ES2019", // Follow NodeJS oldest supported LTS and use version from https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping + "module": "commonjs", + "resolveJsonModule": true, + "moduleResolution": "node", + "esModuleInterop": true, "experimentalDecorators": true, - "emitDecoratorMetadata": true + "emitDecoratorMetadata": true, + "skipLibCheck": true, + "allowJs": true, + "pretty": true, + "allowSyntheticDefaultImports": true, + // Type Checking + "forceConsistentCasingInFileNames": true, + "alwaysStrict": true, + "strict": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true } } diff --git a/types.d.ts b/types.d.ts deleted file mode 100644 index a862733..0000000 --- a/types.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -import SchemaItem from "./SchemaItem" - -export type SchemaInfer = Type extends SchemaItem ? X : never - -export interface ValidationError { - message: string - field?: string - value?: unknown -} - -export type ValidationResult = { - object: T - valid: true - errors?: undefined -} | { - valid: false - object?: (T extends object ? Partial : T) | undefined - errors: Array -} - -export interface SchemaJSON { - i: string - a?: Array | undefined - c?: Array | undefined - f?: Array<{ - n: string - a?: Array | undefined - }> | undefined -}