validup 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/helpers/error.ts","../src/constants.ts","../src/helpers/optional-value.ts","../src/errors/base.ts","../src/errors/validator.ts","../src/errors/nested.ts","../src/utils/has-own-property.ts","../src/utils/object.ts","../src/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { distinctArray } from 'smob';\n\nexport function buildErrorMessageForAttribute(key: string | number) {\n return `The attribute ${String(key)} is invalid.`;\n}\n\nexport function buildErrorMessageForAttributes(input: (number | string)[] | Record<string, any>) {\n let names: string[];\n if (Array.isArray(input)) {\n names = distinctArray(input);\n } else {\n names = Object.keys(input);\n }\n\n if (names.length === 0) {\n return 'An unexpected error occurred.';\n }\n\n if (names.length > 1) {\n return `The attributes ${names.join(', ')} are invalid.`;\n }\n\n return buildErrorMessageForAttribute(names[0]);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum GroupKey {\n WILDCARD = '*',\n}\n\nexport enum OptionalValue {\n /**\n * value: undefined\n */\n UNDEFINED = 'undefined',\n /**\n * value: null & undefined\n */\n NULL = 'null',\n /**\n * value: empty string, false, 0\n */\n FALSY = 'falsy',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { OptionalValue } from '../constants';\n\n/**\n * Check if input value (type of) satisfies optional value type constraint.\n *\n * @param value\n * @param optionalValue\n */\nexport function isOptionalValue(\n value: unknown,\n optionalValue?: `${OptionalValue}`,\n) {\n const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;\n\n if (optionValueNormalized === OptionalValue.NULL) {\n return value === null || typeof value === 'undefined';\n }\n\n if (optionValueNormalized === OptionalValue.UNDEFINED) {\n return typeof value === 'undefined';\n }\n\n return !value;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport class ValidupError extends Error {\n\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { ValidupError } from './base';\n\nexport type ValidupValidatorErrorOptions = {\n path: string,\n pathAbsolute?: string,\n message?: string,\n code?: string | null,\n received?: unknown,\n expected?: unknown\n};\n\nexport class ValidupValidatorError extends ValidupError {\n readonly path: string;\n\n readonly pathAbsolute : string;\n\n readonly code?: string | null;\n\n readonly received?: unknown;\n\n readonly expected?: unknown;\n\n constructor(options: ValidupValidatorErrorOptions) {\n super(options.message);\n\n this.path = options.path;\n this.pathAbsolute = options.pathAbsolute ?? options.path;\n this.code = options.code;\n this.received = options.received;\n this.expected = options.expected;\n }\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { ValidupValidatorError } from './validator';\nimport { ValidupError } from './base';\n\nexport type ValidupNestedErrorOptions = {\n children?: ValidupValidatorError[],\n message?: string\n};\n\nexport class ValidupNestedError extends ValidupError {\n readonly children: ValidupValidatorError[];\n\n constructor(options: ValidupNestedErrorOptions = {}) {\n super(options.message || 'One or many attributes may be invalid.');\n\n this.children = options.children || [];\n }\n\n addChild(child: ValidupValidatorError) {\n this.children.push(child);\n }\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { expandPath, getPathValue, setPathValue } from 'pathtrace';\nimport { GroupKey } from './constants';\nimport { ValidupNestedError, ValidupValidatorError } from './errors';\nimport { buildErrorMessageForAttributes, isOptionalValue } from './helpers';\nimport type {\n ContainerItem,\n ContainerMountOptions,\n ContainerOptions,\n ContainerRunOptions,\n ObjectPropertyPath,\n ObjectPropertyPathExtended,\n Validator,\n} from './types';\nimport { hasOwnProperty, isObject } from './utils';\n\nexport class Container<\n T extends Record<string, any> = Record<string, any>,\n> {\n protected options : ContainerOptions<T>;\n\n protected items : ContainerItem[];\n\n // ----------------------------------------------\n\n constructor(options: ContainerOptions<T> = {}) {\n this.options = options;\n this.items = [];\n\n this.initialize();\n }\n\n // ----------------------------------------------\n\n mount(container: Container) : void;\n\n mount(\n options: ContainerMountOptions,\n container: Container\n ): void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n data: Container | Validator\n ) : void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n options: ContainerMountOptions,\n data: Container | Validator\n ) : void;\n\n mount(...args: any[]) : void {\n if (args.length < 1) {\n throw new SyntaxError('The mount method requires at least one argument');\n }\n\n let path : string | undefined;\n\n let data: Container | Validator | undefined;\n let dataIsContainer : boolean = false;\n\n let options: ContainerMountOptions = {};\n\n for (let i = 0; i < args.length; i++) {\n if (typeof args[i] === 'string') {\n path = args[i];\n continue;\n }\n\n if (typeof args[i] === 'function') {\n data = args[i];\n continue;\n }\n\n if (args[i] instanceof Container) {\n data = args[i];\n dataIsContainer = true;\n continue;\n }\n\n if (isObject(args[i])) {\n options = args[i];\n }\n }\n\n if (\n !dataIsContainer &&\n (typeof path === 'undefined' || path.length === 0)\n ) {\n throw new SyntaxError('Only a container can be mounted without a key.');\n }\n\n if (typeof data === 'undefined') {\n throw new SyntaxError('No container/validator could be extracted from the fn arguments.');\n }\n\n this.items.push({\n ...options,\n data,\n path,\n });\n }\n\n // ----------------------------------------------\n\n async run(\n data: Record<string, any> = {},\n options: ContainerRunOptions<T> = {},\n ): Promise<T> {\n const output: Record<string, any> = {};\n\n const errors: ValidupValidatorError[] = [];\n const errorKeys : string[] = [];\n\n let pathsToInclude : string[] | undefined;\n if (options.pathsToInclude) {\n pathsToInclude = options.pathsToInclude as string[];\n } else if (this.options.pathsToInclude) {\n pathsToInclude = this.options.pathsToInclude as string[];\n }\n\n let pathsToExclude : string[] | undefined;\n if (options.pathsToExclude) {\n pathsToExclude = options.pathsToExclude as string[];\n } else if (this.options.pathsToInclude) {\n pathsToExclude = this.options.pathsToExclude as string[];\n }\n\n let itemCount = 0;\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n\n if (!this.isItemGroupIncluded(item, options.group)) {\n continue;\n }\n\n let pathsCount = 0;\n\n let paths : string[];\n if (item.path) {\n paths = expandPath(data, item.path);\n } else {\n paths = [''];\n }\n\n for (let j = 0; j < paths.length; j++) {\n const path = paths[j];\n const pathAbsolute = this.mergePaths(options.path, paths[j]);\n\n let value : unknown;\n if (hasOwnProperty(output, path)) {\n value = output[path];\n } else if (path.length > 0) {\n value = getPathValue(data, path);\n } else {\n value = data;\n }\n\n if (\n typeof pathsToInclude !== 'undefined' &&\n pathsToInclude.indexOf(path) === -1\n ) {\n continue;\n }\n\n if (\n typeof pathsToExclude !== 'undefined' &&\n pathsToExclude.indexOf(path) !== -1\n ) {\n continue;\n }\n\n try {\n if (\n item.optional &&\n isOptionalValue(value, item.optionalValue)\n ) {\n if (item.optionalInclude) {\n output[path] = value;\n }\n } else if (item.data instanceof Container) {\n const tmp = await item.data.run(\n isObject(value) ? value : {},\n {\n group: options.group,\n flat: true,\n path: pathAbsolute,\n pathsToInclude: options.pathsToInclude,\n // todo: extract defaults for container\n },\n );\n\n const tmpKeys = Object.keys(tmp);\n for (let k = 0; k < tmpKeys.length; k++) {\n output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];\n }\n } else {\n output[path] = await item.data({\n path,\n pathRaw: item.path ?? '',\n\n pathAbsolute,\n value,\n data,\n group: options.group,\n });\n }\n } catch (e) {\n if (e instanceof ValidupValidatorError) {\n errors.push(e);\n errorKeys.push(pathAbsolute);\n } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\n\n if (pathAbsolute.length > 0) {\n errorKeys.push(pathAbsolute);\n } else {\n errorKeys.push(...e.children.map((child) => child.pathAbsolute));\n }\n } else {\n const error = new ValidupValidatorError({\n path,\n pathAbsolute,\n received: value,\n });\n\n if (e instanceof Error) {\n error.cause = e;\n error.message = e.message;\n }\n\n errors.push(error);\n errorKeys.push(pathAbsolute);\n }\n }\n\n pathsCount++;\n }\n\n if (pathsCount > 0) {\n itemCount++;\n }\n }\n\n if (this.options.oneOf) {\n if (errors.length === itemCount) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n } else if (errors.length > 0) {\n throw new ValidupNestedError({ message: buildErrorMessageForAttributes(errorKeys), children: errors });\n }\n\n if (options.defaults) {\n const defaultKeys = Object.keys(options.defaults);\n for (let i = 0; i < defaultKeys.length; i++) {\n if (\n !hasOwnProperty(output, defaultKeys[i]) ||\n typeof output[defaultKeys[i]] === 'undefined'\n ) {\n output[defaultKeys[i]] = options.defaults[defaultKeys[i] as unknown as ObjectPropertyPath<T>];\n }\n }\n }\n\n if (options.flat) {\n return output as T;\n }\n\n const temp : Record<string, any> = {};\n\n const keys = Object.keys(output);\n for (let i = 0; i < keys.length; i++) {\n setPathValue(temp, keys[i], output[keys[i]]);\n }\n\n return temp as T;\n }\n\n private isItemGroupIncluded(\n item: ContainerItem,\n group?: string,\n ) : boolean {\n if (group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group) {\n if (Array.isArray(item.group)) {\n if (item.group.indexOf(GroupKey.WILDCARD) !== -1) {\n return true;\n }\n\n if (group && item.group.indexOf(group) !== -1) {\n return true;\n }\n } else {\n if (item.group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.group === group) {\n return true;\n }\n }\n\n return false;\n }\n\n return true;\n }\n\n private mergePaths(...args: (string | undefined)[]) {\n let output : string = '';\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg || arg.length === 0) {\n continue;\n }\n\n if (arg.at(0) === '.') {\n output += arg;\n } else {\n output += output.length > 0 ? `.${arg}` : arg;\n }\n }\n\n return output;\n }\n\n protected initialize() : void {\n\n }\n}\n"],"names":["buildErrorMessageForAttribute","key","String","buildErrorMessageForAttributes","input","names","Array","isArray","distinctArray","Object","keys","length","join","GroupKey","OptionalValue","isOptionalValue","value","optionalValue","optionValueNormalized","UNDEFINED","NULL","ValidupError","Error","ValidupValidatorError","options","message","path","pathAbsolute","code","received","expected","ValidupNestedError","addChild","child","children","push","hasOwnProperty","obj","prop","prototype","call","isObject","Container","mount","args","SyntaxError","data","dataIsContainer","i","items","run","output","errors","errorKeys","pathsToInclude","pathsToExclude","itemCount","item","isItemGroupIncluded","group","pathsCount","paths","expandPath","j","mergePaths","getPathValue","indexOf","optional","optionalInclude","tmp","flat","tmpKeys","k","pathRaw","e","map","error","cause","oneOf","defaults","defaultKeys","temp","setPathValue","WILDCARD","arg","at","initialize"],"mappings":";;;;;AASO,SAASA,8BAA8BC,GAAoB,EAAA;AAC9D,IAAA,OAAO,CAAC,cAAc,EAAEC,MAAAA,CAAOD,GAAAA,CAAAA,CAAK,YAAY,CAAC;AACrD;AAEO,SAASE,+BAA+BC,KAAgD,EAAA;IAC3F,IAAIC,KAAAA;IACJ,IAAIC,KAAAA,CAAMC,OAA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A,CAAKjC,MAAM,EAAEqC,CAAAA,EAAAA,CAAK;YAClC,MAAMoC,GAAAA,GAAMxC,IAAI,CAACI,CAAAA,CAAE;AACnB,YAAA,IAAI,CAACoC,GAAAA,IAAOA,GAAAA,CAAIzE,MAAM,KAAK,CAAA,EAAG;AAC1B,gBAAA;AACJ,YAAA;AAEA,YAAA,IAAIyE,GAAAA,CAAIC,EAAE,CAAC,CAAA,CAAA,KAAO,GAAA,EAAK;gBACnBlC,MAAAA,IAAUiC,GAAAA;YACd,CAAA,MAAO;gBACHjC,MAAAA,IAAUA,MAAAA,CAAOxC,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAEyE,KAAK,GAAGA,GAAAA;AAC9C,YAAA;AACJ,QAAA;QAEA,OAAOjC,MAAAA;AACX,IAAA;AAEUmC,IAAAA,UAAAA,GAAoB,CAE9B;;IApTA,WAAA,CAAY9D,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACyB,KAAK,GAAG,EAAE;AAEf,QAAA,IAAI,CAACqC,UAAU,EAAA;AACnB,IAAA;AAgTJ;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/helpers/error.ts","../src/constants.ts","../src/helpers/optional-value.ts","../src/errors/base.ts","../src/issue/constants.ts","../src/issue/define.ts","../src/utils/has-own-property.ts","../src/utils/object.ts","../src/container/check.ts","../src/container/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { distinctArray } from 'smob';\n\nexport function buildErrorMessageForAttribute(key: PropertyKey) {\n return `Property ${String(key)} is invalid`;\n}\n\nexport function buildErrorMessageForAttributes(input: PropertyKey[] | Record<string, any>) {\n let names: PropertyKey[];\n if (Array.isArray(input)) {\n names = distinctArray(input);\n } else {\n names = Object.keys(input);\n }\n\n if (names.length === 0) {\n return 'Properties are invalid';\n }\n\n if (names.length > 1) {\n return `Properties ${names.join(', ')} are invalid.`;\n }\n\n return buildErrorMessageForAttribute(names[0]);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum GroupKey {\n WILDCARD = '*',\n}\n\nexport enum OptionalValue {\n /**\n * value: undefined\n */\n UNDEFINED = 'undefined',\n /**\n * value: null & undefined\n */\n NULL = 'null',\n /**\n * value: empty string, false, 0\n */\n FALSY = 'falsy',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { OptionalValue } from '../constants';\n\n/**\n * Check if input value (type of) satisfies optional value type constraint.\n *\n * @param value\n * @param optionalValue\n */\nexport function isOptionalValue(\n value: unknown,\n optionalValue?: `${OptionalValue}`,\n) {\n const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;\n\n if (optionValueNormalized === OptionalValue.NULL) {\n return value === null || typeof value === 'undefined';\n }\n\n if (optionValueNormalized === OptionalValue.UNDEFINED) {\n return typeof value === 'undefined';\n }\n\n return !value;\n}\n","/*\n * Copyright (c) 2024-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Issue } from '../issue';\n\nexport class ValidupError extends Error {\n readonly issues: Issue[];\n\n constructor(issues: Issue[] = []) {\n super(JSON.stringify(\n issues,\n (_: string, value: any) => {\n if (typeof value === 'bigint') {\n return value.toString();\n }\n\n return value;\n },\n 2,\n ));\n\n this.issues = issues;\n }\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum IssueCode {\n VALUE_INVALID = 'value_invalid',\n\n ONE_OF_FAILED = 'one_of_failed',\n}\n","/*\n * Copyright (c) 2026.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { IssueCode } from './constants';\nimport type { IssueGroup, IssueItem } from './types';\n\ntype PartialProps<T extends Record<PropertyKey, any>, K extends keyof T> = Pick<T, Exclude<keyof T, K>> & Partial<Pick<T, K>>;\n\nexport function defineIssueItem(data: Omit<PartialProps<IssueItem, 'code'>, 'type'>): IssueItem {\n return {\n type: 'item',\n ...data,\n code: IssueCode.VALUE_INVALID || data.code,\n };\n}\n\nexport function defineIssueGroup(data: Omit<IssueGroup, 'type'>): IssueGroup {\n return {\n type: 'group',\n ...data,\n };\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown> {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isObject(input: unknown) : input is Record<string, any> {\n return !!input &&\n typeof input === 'object' &&\n !Array.isArray(input);\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from '../utils';\nimport type { IContainer } from './types';\n\nexport function isContainer(input: unknown) : input is IContainer {\n return isObject(input) &&\n typeof input.run === 'function';\n}\n","/*\n * Copyright (c) 2024-2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { Path } from 'pathtrace';\nimport {\n expandPath, getPathValue, pathToArray, setPathValue,\n} from 'pathtrace';\nimport { GroupKey } from '../constants';\nimport { ValidupError } from '../errors';\nimport { buildErrorMessageForAttribute, isOptionalValue } from '../helpers';\nimport type { Validator } from '../types';\nimport { hasOwnProperty, isObject } from '../utils';\nimport { isContainer } from './check';\nimport type {\n ContainerOptions, ContainerRunOptions, IContainer, Mount, MountOptions,\n} from './types';\nimport type { Issue } from '../issue';\nimport { IssueCode, defineIssueGroup, defineIssueItem } from '../issue';\n\nexport class Container<\n T extends Record<string, any> = Record<string, any>,\n> implements IContainer {\n protected options : ContainerOptions<T>;\n\n protected items : Mount[];\n\n // ----------------------------------------------\n\n constructor(options: ContainerOptions<T> = {}) {\n this.options = options;\n this.items = [];\n\n this.initialize();\n }\n\n // ----------------------------------------------\n\n mount(container: IContainer) : void;\n\n mount(\n options: MountOptions,\n container: IContainer\n ): void;\n\n mount(\n // eslint-disable-next-line @typescript-eslint/ban-types\n key: Path<T> | (string & {}),\n data: IContainer | Validator\n ) : void;\n\n mount(\n // eslint-disable-next-line @typescript-eslint/ban-types\n key: Path<T> | (string & {}),\n options: MountOptions,\n data: IContainer | Validator\n ) : void;\n\n mount(...args: any[]) : void {\n if (args.length < 1) {\n throw new SyntaxError('The mount method requires at least one argument');\n }\n\n let path : string | undefined;\n\n let data: IContainer | Validator | undefined;\n let dataIsContainer : boolean = false;\n\n let options: MountOptions = {};\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n\n if (typeof arg === 'string') {\n path = arg;\n continue;\n }\n\n if (typeof arg === 'function') {\n data = arg;\n continue;\n }\n\n if (isContainer(arg)) {\n data = arg;\n dataIsContainer = true;\n continue;\n }\n\n if (isObject(arg)) {\n options = args[i];\n }\n }\n\n if (\n !dataIsContainer &&\n (typeof path === 'undefined' || path.length === 0)\n ) {\n throw new SyntaxError('Only a container can be mounted without a key.');\n }\n\n if (typeof data === 'undefined') {\n throw new SyntaxError('No container/validator could be extracted from the fn arguments.');\n }\n\n if (isContainer(data)) {\n this.items.push({\n options,\n data,\n path,\n type: 'container',\n });\n\n return;\n }\n\n this.items.push({\n options,\n data,\n path,\n type: 'validator',\n });\n }\n\n // ----------------------------------------------\n\n /**\n * @throws ValidupError\n * @param data\n * @param options\n */\n async run(\n data: Record<string, any> = {},\n options: ContainerRunOptions<T> = {},\n ): Promise<T> {\n let pathsToInclude : string[] | undefined;\n if (options.pathsToInclude) {\n pathsToInclude = options.pathsToInclude as string[];\n } else if (this.options.pathsToInclude) {\n pathsToInclude = this.options.pathsToInclude as string[];\n }\n\n let pathsToExclude : string[] | undefined;\n if (options.pathsToExclude) {\n pathsToExclude = options.pathsToExclude as string[];\n } else if (this.options.pathsToInclude) {\n pathsToExclude = this.options.pathsToExclude as string[];\n }\n\n const output: Record<string, any> = {};\n\n const issues : Issue[] = [];\n\n let itemCount : number = 0;\n let errorCount : number = 0;\n\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n\n if (!this.isItemGroupIncluded(item, options.group)) {\n // todo: maybe add issue info\n continue;\n }\n\n let pathCount = 0;\n let pathFailed = false;\n\n let keys : string[];\n if (item.path) {\n keys = expandPath(data, item.path);\n } else {\n keys = [''];\n }\n\n for (let j = 0; j < keys.length; j++) {\n const key = keys[j];\n const keyParts = key ? pathToArray(key) : [];\n\n const pathRelative = keyParts.at(-1);\n const pathAbsolute = [\n ...(options.path ? options.path : []),\n ...keyParts,\n ];\n\n let value : unknown;\n if (key.length > 0) {\n value = hasOwnProperty(output, key) ?\n output[key] :\n getPathValue(data, key);\n } else {\n value = data;\n }\n\n if (\n typeof pathsToInclude !== 'undefined' &&\n pathsToInclude.indexOf(key) === -1\n ) {\n // todo: maybe add issue info\n continue;\n }\n\n if (\n typeof pathsToExclude !== 'undefined' &&\n pathsToExclude.indexOf(key) !== -1\n ) {\n // todo: maybe add issue info\n continue;\n }\n\n try {\n if (\n item.options.optional &&\n isOptionalValue(value, item.options.optionalValue)\n ) {\n if (item.options.optionalInclude) {\n output[key] = value;\n }\n } else if (item.type === 'container') {\n const tmp = await item.data.run(\n isObject(value) ? value : {},\n {\n group: options.group,\n flat: true,\n path: pathAbsolute,\n pathsToInclude: options.pathsToInclude,\n // todo: extract defaults for container\n },\n );\n\n const tmpKeys = Object.keys(tmp);\n for (let k = 0; k < tmpKeys.length; k++) {\n output[this.mergePaths(key, tmpKeys[k])] = tmp[tmpKeys[k]];\n }\n } else if (item.type === 'validator') {\n output[key] = await item.data({\n key,\n path: pathAbsolute,\n\n value,\n data,\n group: options.group,\n });\n }\n } catch (e) {\n const childIssues : Issue[] = [];\n\n if (e instanceof ValidupError) {\n for (let i = 0; i < e.issues.length; i++) {\n const issue = e.issues[i];\n\n childIssues.push({\n ...issue,\n path: [\n ...keyParts,\n ...(issue.path || []),\n ],\n });\n }\n } else if (e instanceof Error) {\n childIssues.push(defineIssueItem({\n path: keyParts,\n message: e.message,\n }));\n }\n\n if (pathRelative) {\n if (item.type === 'container' || childIssues.length > 1) {\n const group = defineIssueGroup({\n message: buildErrorMessageForAttribute(pathRelative),\n path: keyParts,\n issues: childIssues,\n });\n\n issues.push(group);\n } else {\n issues.push(...childIssues);\n }\n } else {\n issues.push(...childIssues);\n }\n\n pathFailed = true;\n }\n\n pathCount++;\n }\n\n if (pathCount > 0) {\n itemCount++;\n\n if (pathFailed) {\n errorCount++;\n }\n }\n }\n\n if (this.options.oneOf) {\n if (errorCount === itemCount) {\n const group = defineIssueGroup({\n code: IssueCode.ONE_OF_FAILED,\n message: 'None of the branches succeeded',\n issues,\n path: options.path ? options.path : [],\n });\n\n throw new ValidupError([group]);\n }\n } else if (errorCount > 0) {\n throw new ValidupError(issues);\n }\n\n if (options.defaults) {\n const defaultKeys = Object.keys(options.defaults);\n for (let i = 0; i < defaultKeys.length; i++) {\n if (\n !hasOwnProperty(output, defaultKeys[i]) ||\n typeof output[defaultKeys[i]] === 'undefined'\n ) {\n output[defaultKeys[i]] = options.defaults[defaultKeys[i] as unknown as Path<T>];\n }\n }\n }\n\n if (options.flat) {\n return output as T;\n }\n\n const temp : Record<string, any> = {};\n\n const keys = Object.keys(output);\n for (let i = 0; i < keys.length; i++) {\n setPathValue(temp, keys[i], output[keys[i]]);\n }\n\n return temp as T;\n }\n\n private isItemGroupIncluded(\n item: Mount,\n group?: string,\n ) : boolean {\n if (group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.options.group) {\n if (Array.isArray(item.options.group)) {\n if (item.options.group.indexOf(GroupKey.WILDCARD) !== -1) {\n return true;\n }\n\n if (group && item.options.group.indexOf(group) !== -1) {\n return true;\n }\n } else {\n if (item.options.group === GroupKey.WILDCARD) {\n return true;\n }\n\n if (item.options.group === group) {\n return true;\n }\n }\n\n return false;\n }\n\n return true;\n }\n\n private mergePaths(...args: (string | undefined)[]) {\n let output : string = '';\n\n for (let i = 0; i < args.length; i++) {\n const arg = args[i];\n if (!arg || arg.length === 0) {\n continue;\n }\n\n if (arg.at(0) === '.') {\n output += arg;\n } else {\n output += output.length > 0 ? `.${arg}` : arg;\n }\n }\n\n return output;\n }\n\n protected initialize() : void {\n\n }\n}\n"],"names":["buildErrorMessageForAttribute","key","String","buildErrorMessageForAttributes","input","names","Array","isArray","distinctArray","Object","keys","length","join","GroupKey","OptionalValue","isOptionalValue","value","optionalValue","optionValueNormalized","UNDEFINED","NULL","ValidupError","Error","issues","JSON","stringify","_","toString","IssueCode","defineIssueItem","data","type","code","VALUE_INVALID","defineIssueGroup","hasOwnProperty","obj","prop","prototype","call","isObject","isContainer","run","Container","mount","args","SyntaxError","path","dataIsContainer","options","i","arg","items","push","pathsToInclude","pathsToExclude","output","itemCount","errorCount","item","isItemGroupIncluded","group","pathCount","pathFailed","expandPath","j","keyParts","pathToArray","pathRelative","at","pathAbsolute","getPathValue","indexOf","optional","optionalInclude","tmp","flat","tmpKeys","k","mergePaths","e","childIssues","issue","message","oneOf","ONE_OF_FAILED","defaults","defaultKeys","temp","setPathValue","WILDCARD","initialize"],"mappings":";;;;;AASO,SAASA,8BAA8BC,GAAgB,EAAA;AAC1D,IAAA,OAAO,CAAC,SAAS,EAAEC,MAAAA,CAAOD,GAAAA,CAAAA,CAAK,WAAW,CAAC;AAC/C;AAEO,SAASE,+BAA+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,EAAK;gBACnBb,MAAAA,IAAUL,GAAAA;YACd,CAAA,MAAO;gBACHK,MAAAA,IAAUA,MAAAA,CAAO7C,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAEwC,KAAK,GAAGA,GAAAA;AAC9C,YAAA;AACJ,QAAA;QAEA,OAAOK,MAAAA;AACX,IAAA;AAEUmC,IAAAA,UAAAA,GAAoB,CAE9B;;IA1WA,WAAA,CAAY1C,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACG,KAAK,GAAG,EAAE;AAEf,QAAA,IAAI,CAACuC,UAAU,EAAA;AACnB,IAAA;AAsWJ;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './helpers';
2
2
  export * from './constants';
3
3
  export * from './errors';
4
- export * from './module';
4
+ export * from './issue';
5
+ export * from './container';
5
6
  export * from './types';
6
7
  export * from './utils';
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { distinctArray } from 'smob';
2
- import { expandPath, getPathValue, setPathValue } from 'pathtrace';
2
+ import { expandPath, pathToArray, getPathValue, setPathValue } from 'pathtrace';
3
3
 
4
4
  function buildErrorMessageForAttribute(key) {
5
- return `The attribute ${String(key)} is invalid.`;
5
+ return `Property ${String(key)} is invalid`;
6
6
  }
7
7
  function buildErrorMessageForAttributes(input) {
8
8
  let names;
@@ -12,10 +12,10 @@ function buildErrorMessageForAttributes(input) {
12
12
  names = Object.keys(input);
13
13
  }
14
14
  if (names.length === 0) {
15
- return 'An unexpected error occurred.';
15
+ return 'Properties are invalid';
16
16
  }
17
17
  if (names.length > 1) {
18
- return `The attributes ${names.join(', ')} are invalid.`;
18
+ return `Properties ${names.join(', ')} are invalid.`;
19
19
  }
20
20
  return buildErrorMessageForAttribute(names[0]);
21
21
  }
@@ -64,27 +64,40 @@ var OptionalValue = /*#__PURE__*/ function(OptionalValue) {
64
64
  * For the full copyright and license information,
65
65
  * view the LICENSE file that was distributed with this source code.
66
66
  */ class ValidupError extends Error {
67
- }
68
-
69
- class ValidupValidatorError extends ValidupError {
70
- constructor(options){
71
- super(options.message);
72
- this.path = options.path;
73
- this.pathAbsolute = options.pathAbsolute ?? options.path;
74
- this.code = options.code;
75
- this.received = options.received;
76
- this.expected = options.expected;
67
+ constructor(issues = []){
68
+ super(JSON.stringify(issues, (_, value)=>{
69
+ if (typeof value === 'bigint') {
70
+ return value.toString();
71
+ }
72
+ return value;
73
+ }, 2));
74
+ this.issues = issues;
77
75
  }
78
76
  }
79
77
 
80
- class ValidupNestedError extends ValidupError {
81
- addChild(child) {
82
- this.children.push(child);
83
- }
84
- constructor(options = {}){
85
- super(options.message || 'One or many attributes may be invalid.');
86
- this.children = options.children || [];
87
- }
78
+ /*
79
+ * Copyright (c) 2026.
80
+ * Author Peter Placzek (tada5hi)
81
+ * For the full copyright and license information,
82
+ * view the LICENSE file that was distributed with this source code.
83
+ */ var IssueCode = /*#__PURE__*/ function(IssueCode) {
84
+ IssueCode["VALUE_INVALID"] = "value_invalid";
85
+ IssueCode["ONE_OF_FAILED"] = "one_of_failed";
86
+ return IssueCode;
87
+ }({});
88
+
89
+ function defineIssueItem(data) {
90
+ return {
91
+ type: 'item',
92
+ ...data,
93
+ code: IssueCode.VALUE_INVALID || data.code
94
+ };
95
+ }
96
+ function defineIssueGroup(data) {
97
+ return {
98
+ type: 'group',
99
+ ...data
100
+ };
88
101
  }
89
102
 
90
103
  /*
@@ -106,6 +119,10 @@ function hasOwnProperty(obj, prop) {
106
119
  return !!input && typeof input === 'object' && !Array.isArray(input);
107
120
  }
108
121
 
122
+ function isContainer(input) {
123
+ return isObject(input) && typeof input.run === 'function';
124
+ }
125
+
109
126
  class Container {
110
127
  mount(...args) {
111
128
  if (args.length < 1) {
@@ -116,20 +133,21 @@ class Container {
116
133
  let dataIsContainer = false;
117
134
  let options = {};
118
135
  for(let i = 0; i < args.length; i++){
119
- if (typeof args[i] === 'string') {
120
- path = args[i];
136
+ const arg = args[i];
137
+ if (typeof arg === 'string') {
138
+ path = arg;
121
139
  continue;
122
140
  }
123
- if (typeof args[i] === 'function') {
124
- data = args[i];
141
+ if (typeof arg === 'function') {
142
+ data = arg;
125
143
  continue;
126
144
  }
127
- if (args[i] instanceof Container) {
128
- data = args[i];
145
+ if (isContainer(arg)) {
146
+ data = arg;
129
147
  dataIsContainer = true;
130
148
  continue;
131
149
  }
132
- if (isObject(args[i])) {
150
+ if (isObject(arg)) {
133
151
  options = args[i];
134
152
  }
135
153
  }
@@ -139,17 +157,28 @@ class Container {
139
157
  if (typeof data === 'undefined') {
140
158
  throw new SyntaxError('No container/validator could be extracted from the fn arguments.');
141
159
  }
160
+ if (isContainer(data)) {
161
+ this.items.push({
162
+ options,
163
+ data,
164
+ path,
165
+ type: 'container'
166
+ });
167
+ return;
168
+ }
142
169
  this.items.push({
143
- ...options,
170
+ options,
144
171
  data,
145
- path
172
+ path,
173
+ type: 'validator'
146
174
  });
147
175
  }
148
176
  // ----------------------------------------------
149
- async run(data = {}, options = {}) {
150
- const output = {};
151
- const errors = [];
152
- const errorKeys = [];
177
+ /**
178
+ * @throws ValidupError
179
+ * @param data
180
+ * @param options
181
+ */ async run(data = {}, options = {}) {
153
182
  let pathsToInclude;
154
183
  if (options.pathsToInclude) {
155
184
  pathsToInclude = options.pathsToInclude;
@@ -162,44 +191,51 @@ class Container {
162
191
  } else if (this.options.pathsToInclude) {
163
192
  pathsToExclude = this.options.pathsToExclude;
164
193
  }
194
+ const output = {};
195
+ const issues = [];
165
196
  let itemCount = 0;
197
+ let errorCount = 0;
166
198
  for(let i = 0; i < this.items.length; i++){
167
199
  const item = this.items[i];
168
200
  if (!this.isItemGroupIncluded(item, options.group)) {
169
201
  continue;
170
202
  }
171
- let pathsCount = 0;
172
- let paths;
203
+ let pathCount = 0;
204
+ let pathFailed = false;
205
+ let keys;
173
206
  if (item.path) {
174
- paths = expandPath(data, item.path);
207
+ keys = expandPath(data, item.path);
175
208
  } else {
176
- paths = [
209
+ keys = [
177
210
  ''
178
211
  ];
179
212
  }
180
- for(let j = 0; j < paths.length; j++){
181
- const path = paths[j];
182
- const pathAbsolute = this.mergePaths(options.path, paths[j]);
213
+ for(let j = 0; j < keys.length; j++){
214
+ const key = keys[j];
215
+ const keyParts = key ? pathToArray(key) : [];
216
+ const pathRelative = keyParts.at(-1);
217
+ const pathAbsolute = [
218
+ ...options.path ? options.path : [],
219
+ ...keyParts
220
+ ];
183
221
  let value;
184
- if (hasOwnProperty(output, path)) {
185
- value = output[path];
186
- } else if (path.length > 0) {
187
- value = getPathValue(data, path);
222
+ if (key.length > 0) {
223
+ value = hasOwnProperty(output, key) ? output[key] : getPathValue(data, key);
188
224
  } else {
189
225
  value = data;
190
226
  }
191
- if (typeof pathsToInclude !== 'undefined' && pathsToInclude.indexOf(path) === -1) {
227
+ if (typeof pathsToInclude !== 'undefined' && pathsToInclude.indexOf(key) === -1) {
192
228
  continue;
193
229
  }
194
- if (typeof pathsToExclude !== 'undefined' && pathsToExclude.indexOf(path) !== -1) {
230
+ if (typeof pathsToExclude !== 'undefined' && pathsToExclude.indexOf(key) !== -1) {
195
231
  continue;
196
232
  }
197
233
  try {
198
- if (item.optional && isOptionalValue(value, item.optionalValue)) {
199
- if (item.optionalInclude) {
200
- output[path] = value;
234
+ if (item.options.optional && isOptionalValue(value, item.options.optionalValue)) {
235
+ if (item.options.optionalInclude) {
236
+ output[key] = value;
201
237
  }
202
- } else if (item.data instanceof Container) {
238
+ } else if (item.type === 'container') {
203
239
  const tmp = await item.data.run(isObject(value) ? value : {}, {
204
240
  group: options.group,
205
241
  flat: true,
@@ -208,61 +244,75 @@ class Container {
208
244
  });
209
245
  const tmpKeys = Object.keys(tmp);
210
246
  for(let k = 0; k < tmpKeys.length; k++){
211
- output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];
247
+ output[this.mergePaths(key, tmpKeys[k])] = tmp[tmpKeys[k]];
212
248
  }
213
- } else {
214
- output[path] = await item.data({
215
- path,
216
- pathRaw: item.path ?? '',
217
- pathAbsolute,
249
+ } else if (item.type === 'validator') {
250
+ output[key] = await item.data({
251
+ key,
252
+ path: pathAbsolute,
218
253
  value,
219
254
  data,
220
255
  group: options.group
221
256
  });
222
257
  }
223
258
  } catch (e) {
224
- if (e instanceof ValidupValidatorError) {
225
- errors.push(e);
226
- errorKeys.push(pathAbsolute);
227
- } else if (e instanceof ValidupNestedError) {
228
- errors.push(...e.children);
229
- if (pathAbsolute.length > 0) {
230
- errorKeys.push(pathAbsolute);
259
+ const childIssues = [];
260
+ if (e instanceof ValidupError) {
261
+ for(let i = 0; i < e.issues.length; i++){
262
+ const issue = e.issues[i];
263
+ childIssues.push({
264
+ ...issue,
265
+ path: [
266
+ ...keyParts,
267
+ ...issue.path || []
268
+ ]
269
+ });
270
+ }
271
+ } else if (e instanceof Error) {
272
+ childIssues.push(defineIssueItem({
273
+ path: keyParts,
274
+ message: e.message
275
+ }));
276
+ }
277
+ if (pathRelative) {
278
+ if (item.type === 'container' || childIssues.length > 1) {
279
+ const group = defineIssueGroup({
280
+ message: buildErrorMessageForAttribute(pathRelative),
281
+ path: keyParts,
282
+ issues: childIssues
283
+ });
284
+ issues.push(group);
231
285
  } else {
232
- errorKeys.push(...e.children.map((child)=>child.pathAbsolute));
286
+ issues.push(...childIssues);
233
287
  }
234
288
  } else {
235
- const error = new ValidupValidatorError({
236
- path,
237
- pathAbsolute,
238
- received: value
239
- });
240
- if (e instanceof Error) {
241
- error.cause = e;
242
- error.message = e.message;
243
- }
244
- errors.push(error);
245
- errorKeys.push(pathAbsolute);
289
+ issues.push(...childIssues);
246
290
  }
291
+ pathFailed = true;
247
292
  }
248
- pathsCount++;
293
+ pathCount++;
249
294
  }
250
- if (pathsCount > 0) {
295
+ if (pathCount > 0) {
251
296
  itemCount++;
297
+ if (pathFailed) {
298
+ errorCount++;
299
+ }
252
300
  }
253
301
  }
254
302
  if (this.options.oneOf) {
255
- if (errors.length === itemCount) {
256
- throw new ValidupNestedError({
257
- message: buildErrorMessageForAttributes(errorKeys),
258
- children: errors
303
+ if (errorCount === itemCount) {
304
+ const group = defineIssueGroup({
305
+ code: IssueCode.ONE_OF_FAILED,
306
+ message: 'None of the branches succeeded',
307
+ issues,
308
+ path: options.path ? options.path : []
259
309
  });
310
+ throw new ValidupError([
311
+ group
312
+ ]);
260
313
  }
261
- } else if (errors.length > 0) {
262
- throw new ValidupNestedError({
263
- message: buildErrorMessageForAttributes(errorKeys),
264
- children: errors
265
- });
314
+ } else if (errorCount > 0) {
315
+ throw new ValidupError(issues);
266
316
  }
267
317
  if (options.defaults) {
268
318
  const defaultKeys = Object.keys(options.defaults);
@@ -286,19 +336,19 @@ class Container {
286
336
  if (group === GroupKey.WILDCARD) {
287
337
  return true;
288
338
  }
289
- if (item.group) {
290
- if (Array.isArray(item.group)) {
291
- if (item.group.indexOf(GroupKey.WILDCARD) !== -1) {
339
+ if (item.options.group) {
340
+ if (Array.isArray(item.options.group)) {
341
+ if (item.options.group.indexOf(GroupKey.WILDCARD) !== -1) {
292
342
  return true;
293
343
  }
294
- if (group && item.group.indexOf(group) !== -1) {
344
+ if (group && item.options.group.indexOf(group) !== -1) {
295
345
  return true;
296
346
  }
297
347
  } else {
298
- if (item.group === GroupKey.WILDCARD) {
348
+ if (item.options.group === GroupKey.WILDCARD) {
299
349
  return true;
300
350
  }
301
- if (item.group === group) {
351
+ if (item.options.group === group) {
302
352
  return true;
303
353
  }
304
354
  }
@@ -330,5 +380,5 @@ class Container {
330
380
  }
331
381
  }
332
382
 
333
- export { Container, GroupKey, OptionalValue, ValidupError, ValidupNestedError, ValidupValidatorError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, hasOwnProperty, isObject, isOptionalValue };
383
+ export { Container, GroupKey, IssueCode, OptionalValue, ValidupError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, defineIssueGroup, defineIssueItem, hasOwnProperty, isContainer, isObject, isOptionalValue };
334
384
  //# sourceMappingURL=index.mjs.map