validup 0.1.9 → 0.1.10
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.
- package/dist/container/check.d.ts +2 -0
- package/dist/container/index.d.ts +3 -0
- package/dist/{module.d.ts → container/module.d.ts} +7 -6
- package/dist/container/types.d.ts +91 -0
- package/dist/index.cjs +14 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +14 -9
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +0 -82
- package/package.json +1 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { ObjectPropertyPathExtended, Validator } from '../types';
|
|
2
|
+
import type { ContainerItem, ContainerMountOptions, ContainerOptions, ContainerRunOptions, IContainer } from './types';
|
|
3
|
+
export declare class Container<T extends Record<string, any> = Record<string, any>> implements IContainer {
|
|
3
4
|
protected options: ContainerOptions<T>;
|
|
4
5
|
protected items: ContainerItem[];
|
|
5
6
|
constructor(options?: ContainerOptions<T>);
|
|
6
|
-
mount(container:
|
|
7
|
-
mount(options: ContainerMountOptions, container:
|
|
8
|
-
mount(key: ObjectPropertyPathExtended<T>, data:
|
|
9
|
-
mount(key: ObjectPropertyPathExtended<T>, options: ContainerMountOptions, data:
|
|
7
|
+
mount(container: IContainer): void;
|
|
8
|
+
mount(options: ContainerMountOptions, container: IContainer): void;
|
|
9
|
+
mount(key: ObjectPropertyPathExtended<T>, data: IContainer | Validator): void;
|
|
10
|
+
mount(key: ObjectPropertyPathExtended<T>, options: ContainerMountOptions, data: IContainer | Validator): void;
|
|
10
11
|
run(data?: Record<string, any>, options?: ContainerRunOptions<T>): Promise<T>;
|
|
11
12
|
private isItemGroupIncluded;
|
|
12
13
|
private mergePaths;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { OptionalValue } from '../constants';
|
|
2
|
+
import type { ObjectLiteral, ObjectPropertyPath, Validator } from '../types';
|
|
3
|
+
export type ContainerOptions<T> = {
|
|
4
|
+
/**
|
|
5
|
+
* Only one of the mounted container/validators must succeed.
|
|
6
|
+
*/
|
|
7
|
+
oneOf?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Limit mounted paths on execution.
|
|
10
|
+
* By default, all mounted containers/validators will
|
|
11
|
+
* be considered for execution.
|
|
12
|
+
*/
|
|
13
|
+
pathsToInclude?: ObjectPropertyPath<T>[];
|
|
14
|
+
/**
|
|
15
|
+
* Exclude mounted paths on execution.
|
|
16
|
+
* By default, all mounted containers/validators will
|
|
17
|
+
* be considered for execution.
|
|
18
|
+
*/
|
|
19
|
+
pathsToExclude?: ObjectPropertyPath<T>[];
|
|
20
|
+
};
|
|
21
|
+
export type ContainerRunOptions<T extends Record<string, any> = Record<string, any>> = {
|
|
22
|
+
/**
|
|
23
|
+
* Default values for the container output.
|
|
24
|
+
*/
|
|
25
|
+
defaults?: {
|
|
26
|
+
[Key in ObjectPropertyPath<T>]: any;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Group to execute.
|
|
30
|
+
*/
|
|
31
|
+
group?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Output flat object?
|
|
34
|
+
*/
|
|
35
|
+
flat?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Passed path from the parent container.
|
|
38
|
+
*/
|
|
39
|
+
path?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Limit mounted paths on execution.
|
|
42
|
+
* By default, all mounted containers/validators will
|
|
43
|
+
* be considered for execution.
|
|
44
|
+
*/
|
|
45
|
+
pathsToInclude?: ObjectPropertyPath<T>[];
|
|
46
|
+
/**
|
|
47
|
+
* Exclude mounted paths on execution.
|
|
48
|
+
* By default, all mounted containers/validators will
|
|
49
|
+
* be considered for execution.
|
|
50
|
+
*/
|
|
51
|
+
pathsToExclude?: ObjectPropertyPath<T>[];
|
|
52
|
+
};
|
|
53
|
+
export type ContainerMountOptions = {
|
|
54
|
+
/**
|
|
55
|
+
* Group(s) to execute.
|
|
56
|
+
*/
|
|
57
|
+
group?: string | string[];
|
|
58
|
+
/**
|
|
59
|
+
* Specify if an optional value is also acceptable for the mount key.
|
|
60
|
+
* An optional value won't be passed to the underlying container/validator.
|
|
61
|
+
*
|
|
62
|
+
* default: false
|
|
63
|
+
*/
|
|
64
|
+
optional?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Which values are considered optional.
|
|
67
|
+
* An optional value won't be passed to the underlying container/validator.
|
|
68
|
+
*
|
|
69
|
+
* default: 'undefined'
|
|
70
|
+
*/
|
|
71
|
+
optionalValue?: `${OptionalValue}`;
|
|
72
|
+
/**
|
|
73
|
+
* Include optional value as property in output.
|
|
74
|
+
*
|
|
75
|
+
* default: false
|
|
76
|
+
*/
|
|
77
|
+
optionalInclude?: boolean;
|
|
78
|
+
};
|
|
79
|
+
export interface IContainer<T extends ObjectLiteral = ObjectLiteral> {
|
|
80
|
+
/**
|
|
81
|
+
* Execute container with given input.
|
|
82
|
+
*
|
|
83
|
+
* @param data
|
|
84
|
+
* @param options
|
|
85
|
+
*/
|
|
86
|
+
run(data?: Record<string, any>, options?: ContainerRunOptions<T>): Promise<T>;
|
|
87
|
+
}
|
|
88
|
+
export type ContainerItem = ContainerMountOptions & {
|
|
89
|
+
path?: string;
|
|
90
|
+
data: Validator | IContainer;
|
|
91
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -108,6 +108,10 @@ function hasOwnProperty(obj, prop) {
|
|
|
108
108
|
return !!input && typeof input === 'object' && !Array.isArray(input);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
function isContainer(input) {
|
|
112
|
+
return isObject(input) && typeof input.run === 'function';
|
|
113
|
+
}
|
|
114
|
+
|
|
111
115
|
class Container {
|
|
112
116
|
mount(...args) {
|
|
113
117
|
if (args.length < 1) {
|
|
@@ -118,20 +122,21 @@ class Container {
|
|
|
118
122
|
let dataIsContainer = false;
|
|
119
123
|
let options = {};
|
|
120
124
|
for(let i = 0; i < args.length; i++){
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
const arg = args[i];
|
|
126
|
+
if (typeof arg === 'string') {
|
|
127
|
+
path = arg;
|
|
123
128
|
continue;
|
|
124
129
|
}
|
|
125
|
-
if (typeof
|
|
126
|
-
data =
|
|
130
|
+
if (typeof arg === 'function') {
|
|
131
|
+
data = arg;
|
|
127
132
|
continue;
|
|
128
133
|
}
|
|
129
|
-
if (
|
|
130
|
-
data =
|
|
134
|
+
if (isContainer(arg)) {
|
|
135
|
+
data = arg;
|
|
131
136
|
dataIsContainer = true;
|
|
132
137
|
continue;
|
|
133
138
|
}
|
|
134
|
-
if (isObject(
|
|
139
|
+
if (isObject(arg)) {
|
|
135
140
|
options = args[i];
|
|
136
141
|
}
|
|
137
142
|
}
|
|
@@ -201,7 +206,7 @@ class Container {
|
|
|
201
206
|
if (item.optionalInclude) {
|
|
202
207
|
output[path] = value;
|
|
203
208
|
}
|
|
204
|
-
} else if (item.data
|
|
209
|
+
} else if (isContainer(item.data)) {
|
|
205
210
|
const tmp = await item.data.run(isObject(value) ? value : {}, {
|
|
206
211
|
group: options.group,
|
|
207
212
|
flat: true,
|
|
@@ -341,6 +346,7 @@ exports.ValidupValidatorError = ValidupValidatorError;
|
|
|
341
346
|
exports.buildErrorMessageForAttribute = buildErrorMessageForAttribute;
|
|
342
347
|
exports.buildErrorMessageForAttributes = buildErrorMessageForAttributes;
|
|
343
348
|
exports.hasOwnProperty = hasOwnProperty;
|
|
349
|
+
exports.isContainer = isContainer;
|
|
344
350
|
exports.isObject = isObject;
|
|
345
351
|
exports.isOptionalValue = isOptionalValue;
|
|
346
352
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -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,OAAO,CAACH,KAAAA,CAAAA,EAAQ;AACtBC,QAAAA,KAAAA,GAAQG,kBAAAA,CAAcJ,KAAAA,CAAAA;IAC1B,CAAA,MAAO;QACHC,KAAAA,GAAQI,MAAAA,CAAOC,IAAI,CAACN,KAAAA,CAAAA;AACxB,IAAA;IAEA,IAAIC,KAAAA,CAAMM,MAAM,KAAK,CAAA,EAAG;QACpB,OAAO,+BAAA;AACX,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,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/errors/validator.ts","../src/errors/nested.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: 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) 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 { expandPath, getPathValue, setPathValue } from 'pathtrace';\nimport { GroupKey } from '../constants';\nimport { ValidupNestedError, ValidupValidatorError } from '../errors';\nimport { buildErrorMessageForAttributes, isOptionalValue } from '../helpers';\nimport type {\n ObjectPropertyPath,\n ObjectPropertyPathExtended,\n Validator,\n} from '../types';\nimport { hasOwnProperty, isObject } from '../utils';\nimport { isContainer } from './check';\nimport type {\n ContainerItem, ContainerMountOptions, ContainerOptions, ContainerRunOptions, IContainer,\n} from './types';\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 : 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: IContainer) : void;\n\n mount(\n options: ContainerMountOptions,\n container: IContainer\n ): void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n data: IContainer | Validator\n ) : void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n options: ContainerMountOptions,\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: ContainerMountOptions = {};\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 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 (isContainer(item.data)) {\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","isContainer","run","Container","mount","args","SyntaxError","data","dataIsContainer","i","arg","items","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","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,OAAO,CAACH,KAAAA,CAAAA,EAAQ;AACtBC,QAAAA,KAAAA,GAAQG,kBAAAA,CAAcJ,KAAAA,CAAAA;IAC1B,CAAA,MAAO;QACHC,KAAAA,GAAQI,MAAAA,CAAOC,IAAI,CAACN,KAAAA,CAAAA;AACxB,IAAA;IAEA,IAAIC,KAAAA,CAAMM,MAAM,KAAK,CAAA,EAAG;QACpB,OAAO,+BAAA;AACX,IAAA;IAEA,IAAIN,KAAAA,CAAMM,MAAM,GAAG,CAAA,EAAG;QAClB,OAAO,CAAC,eAAe,EAAEN,KAAAA,CAAMO,IAAI,CAAC,IAAA,CAAA,CAAM,aAAa,CAAC;AAC5D,IAAA;IAEA,OAAOZ,6BAAAA,CAA8BK,KAAK,CAAC,CAAA,CAAE,CAAA;AACjD;;AC9BA;;;;;IAOO,IAAKQ,QAAAA,iBAAAA,SAAAA,QAAAA,EAAAA;;AAAAA,IAAAA,OAAAA,QAAAA;AAEX,CAAA,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AA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA;QACf,IAAI,CAAC4B,KAAK,GAAG,EAAE;AAEf,QAAA,IAAI,CAACmC,UAAU,EAAA;AACnB,IAAA;AAkTJ;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -106,6 +106,10 @@ function hasOwnProperty(obj, prop) {
|
|
|
106
106
|
return !!input && typeof input === 'object' && !Array.isArray(input);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
function isContainer(input) {
|
|
110
|
+
return isObject(input) && typeof input.run === 'function';
|
|
111
|
+
}
|
|
112
|
+
|
|
109
113
|
class Container {
|
|
110
114
|
mount(...args) {
|
|
111
115
|
if (args.length < 1) {
|
|
@@ -116,20 +120,21 @@ class Container {
|
|
|
116
120
|
let dataIsContainer = false;
|
|
117
121
|
let options = {};
|
|
118
122
|
for(let i = 0; i < args.length; i++){
|
|
119
|
-
|
|
120
|
-
|
|
123
|
+
const arg = args[i];
|
|
124
|
+
if (typeof arg === 'string') {
|
|
125
|
+
path = arg;
|
|
121
126
|
continue;
|
|
122
127
|
}
|
|
123
|
-
if (typeof
|
|
124
|
-
data =
|
|
128
|
+
if (typeof arg === 'function') {
|
|
129
|
+
data = arg;
|
|
125
130
|
continue;
|
|
126
131
|
}
|
|
127
|
-
if (
|
|
128
|
-
data =
|
|
132
|
+
if (isContainer(arg)) {
|
|
133
|
+
data = arg;
|
|
129
134
|
dataIsContainer = true;
|
|
130
135
|
continue;
|
|
131
136
|
}
|
|
132
|
-
if (isObject(
|
|
137
|
+
if (isObject(arg)) {
|
|
133
138
|
options = args[i];
|
|
134
139
|
}
|
|
135
140
|
}
|
|
@@ -199,7 +204,7 @@ class Container {
|
|
|
199
204
|
if (item.optionalInclude) {
|
|
200
205
|
output[path] = value;
|
|
201
206
|
}
|
|
202
|
-
} else if (item.data
|
|
207
|
+
} else if (isContainer(item.data)) {
|
|
203
208
|
const tmp = await item.data.run(isObject(value) ? value : {}, {
|
|
204
209
|
group: options.group,
|
|
205
210
|
flat: true,
|
|
@@ -330,5 +335,5 @@ class Container {
|
|
|
330
335
|
}
|
|
331
336
|
}
|
|
332
337
|
|
|
333
|
-
export { Container, GroupKey, OptionalValue, ValidupError, ValidupNestedError, ValidupValidatorError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, hasOwnProperty, isObject, isOptionalValue };
|
|
338
|
+
export { Container, GroupKey, OptionalValue, ValidupError, ValidupNestedError, ValidupValidatorError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, hasOwnProperty, isContainer, isObject, isOptionalValue };
|
|
334
339
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","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,OAAO,CAACH,KAAAA,CAAAA,EAAQ;AACtBC,QAAAA,KAAAA,GAAQG,aAAAA,CAAcJ,KAAAA,CAAAA;IAC1B,CAAA,MAAO;QACHC,KAAAA,GAAQI,MAAAA,CAAOC,IAAI,CAACN,KAAAA,CAAAA;AACxB,IAAA;IAEA,IAAIC,KAAAA,CAAMM,MAAM,KAAK,CAAA,EAAG;QACpB,OAAO,+BAAA;AACX,IAAA;IAEA,IAAIN,KAAAA,CAAMM,MAAM,GAAG,CAAA,EAAG;QAClB,OAAO,CAAC,eAAe,EAAEN,KAAAA,CAAMO,IAAI,CAAC,IAAA,CAAA,CAAM,aAAa,CAAC;AAC5D,IAAA;IAEA,OAAOZ,6BAAAA,CAA8BK,KAAK,CAAC,CAAA,CAAE,CAAA;AACjD;;AC9BA;;;;;IAOO,IAAKQ,QAAAA,iBAAAA,SAAAA,QAAAA,EAAAA;;AAAAA,IAAAA,OAAAA,QAAAA;AAEX,CAAA,CAAA,EAAA;AAEM,IAAA,aAAKC,iBAAAA,SAAAA,aAAAA,EAAAA;AACR;;AAEC,QAAA,aAAA,CAAA,WAAA,CAAA,GAAA,WAAA;AAED;;AAEC,QAAA,aAAA,CAAA,MAAA,CAAA,GAAA,MAAA;AAED;;AAEC,QAAA,aAAA,CAAA,OAAA,CAAA,GAAA,OAAA;AAXOA,IAAAA,OAAAA,aAAAA;AAaX,CAAA,CAAA,EAAA;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A,CAASsE,QAAQ,EAAE;oBAClC,OAAO,IAAA;AACX,gBAAA;gBAEA,IAAI1B,IAAAA,CAAKE,KAAK,KAAKA,KAAAA,EAAO;oBACtB,OAAO,IAAA;AACX,gBAAA;AACJ,YAAA;YAEA,OAAO,KAAA;AACX,QAAA;QAEA,OAAO,IAAA;AACX,IAAA;IAEQK,UAAAA,CAAW,GAAGpB,IAA4B,EAAE;AAChD,QAAA,IAAIO,MAAAA,GAAkB,EAAA;AAEtB,QAAA,IAAK,IAAIH,CAAAA,GAAI,CAAA,EAAGA,IAAIJ,IAAAA,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.mjs","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/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: 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) 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 { expandPath, getPathValue, setPathValue } from 'pathtrace';\nimport { GroupKey } from '../constants';\nimport { ValidupNestedError, ValidupValidatorError } from '../errors';\nimport { buildErrorMessageForAttributes, isOptionalValue } from '../helpers';\nimport type {\n ObjectPropertyPath,\n ObjectPropertyPathExtended,\n Validator,\n} from '../types';\nimport { hasOwnProperty, isObject } from '../utils';\nimport { isContainer } from './check';\nimport type {\n ContainerItem, ContainerMountOptions, ContainerOptions, ContainerRunOptions, IContainer,\n} from './types';\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 : 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: IContainer) : void;\n\n mount(\n options: ContainerMountOptions,\n container: IContainer\n ): void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n data: IContainer | Validator\n ) : void;\n\n mount(\n key: ObjectPropertyPathExtended<T>,\n options: ContainerMountOptions,\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: ContainerMountOptions = {};\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 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 (isContainer(item.data)) {\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","isContainer","run","Container","mount","args","SyntaxError","data","dataIsContainer","i","arg","items","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","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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AIH,CAAAA,GAAI,CAAA,EAAGA,IAAIJ,IAAAA,CAAKnC,MAAM,EAAEuC,CAAAA,EAAAA,CAAK;YAClC,MAAMC,GAAAA,GAAML,IAAI,CAACI,CAAAA,CAAE;AACnB,YAAA,IAAI,CAACC,GAAAA,IAAOA,GAAAA,CAAIxC,MAAM,KAAK,CAAA,EAAG;AAC1B,gBAAA;AACJ,YAAA;AAEA,YAAA,IAAIwC,GAAAA,CAAImC,EAAE,CAAC,CAAA,CAAA,KAAO,GAAA,EAAK;gBACnBjC,MAAAA,IAAUF,GAAAA;YACd,CAAA,MAAO;gBACHE,MAAAA,IAAUA,MAAAA,CAAO1C,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAEwC,KAAK,GAAGA,GAAAA;AAC9C,YAAA;AACJ,QAAA;QAEA,OAAOE,MAAAA;AACX,IAAA;AAEUkC,IAAAA,UAAAA,GAAoB,CAE9B;;IAtTA,WAAA,CAAY/D,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA;QACf,IAAI,CAAC4B,KAAK,GAAG,EAAE;AAEf,QAAA,IAAI,CAACmC,UAAU,EAAA;AACnB,IAAA;AAkTJ;;;;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,56 +1,4 @@
|
|
|
1
|
-
import type { OptionalValue } from './constants';
|
|
2
|
-
import type { Container } from './module';
|
|
3
1
|
export type ObjectLiteral = Record<string | number, any>;
|
|
4
|
-
export type ContainerOptions<T> = {
|
|
5
|
-
/**
|
|
6
|
-
* Only one of the mounted container/validators must succeed.
|
|
7
|
-
*/
|
|
8
|
-
oneOf?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Limit mounted paths on execution.
|
|
11
|
-
* By default, all mounted containers/validators will
|
|
12
|
-
* be considered for execution.
|
|
13
|
-
*/
|
|
14
|
-
pathsToInclude?: ObjectPropertyPath<T>[];
|
|
15
|
-
/**
|
|
16
|
-
* Exclude mounted paths on execution.
|
|
17
|
-
* By default, all mounted containers/validators will
|
|
18
|
-
* be considered for execution.
|
|
19
|
-
*/
|
|
20
|
-
pathsToExclude?: ObjectPropertyPath<T>[];
|
|
21
|
-
};
|
|
22
|
-
export type ContainerRunOptions<T extends Record<string, any> = Record<string, any>> = {
|
|
23
|
-
/**
|
|
24
|
-
* Default values for the container output.
|
|
25
|
-
*/
|
|
26
|
-
defaults?: {
|
|
27
|
-
[Key in ObjectPropertyPath<T>]: any;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Group to execute.
|
|
31
|
-
*/
|
|
32
|
-
group?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Output flat object?
|
|
35
|
-
*/
|
|
36
|
-
flat?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Passed path from the parent container.
|
|
39
|
-
*/
|
|
40
|
-
path?: string;
|
|
41
|
-
/**
|
|
42
|
-
* Limit mounted paths on execution.
|
|
43
|
-
* By default, all mounted containers/validators will
|
|
44
|
-
* be considered for execution.
|
|
45
|
-
*/
|
|
46
|
-
pathsToInclude?: ObjectPropertyPath<T>[];
|
|
47
|
-
/**
|
|
48
|
-
* Exclude mounted paths on execution.
|
|
49
|
-
* By default, all mounted containers/validators will
|
|
50
|
-
* be considered for execution.
|
|
51
|
-
*/
|
|
52
|
-
pathsToExclude?: ObjectPropertyPath<T>[];
|
|
53
|
-
};
|
|
54
2
|
export type ValidatorContext = {
|
|
55
3
|
/**
|
|
56
4
|
* The expanded mount path in the current container.
|
|
@@ -78,36 +26,6 @@ export type ValidatorContext = {
|
|
|
78
26
|
group?: string;
|
|
79
27
|
};
|
|
80
28
|
export type Validator = (ctx: ValidatorContext) => Promise<unknown> | unknown;
|
|
81
|
-
export type ContainerMountOptions = {
|
|
82
|
-
/**
|
|
83
|
-
* Group(s) to execute.
|
|
84
|
-
*/
|
|
85
|
-
group?: string | string[];
|
|
86
|
-
/**
|
|
87
|
-
* Specify if an optional value is also acceptable for the mount key.
|
|
88
|
-
* An optional value won't be passed to the underlying container/validator.
|
|
89
|
-
*
|
|
90
|
-
* default: false
|
|
91
|
-
*/
|
|
92
|
-
optional?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* Which values are considered optional.
|
|
95
|
-
* An optional value won't be passed to the underlying container/validator.
|
|
96
|
-
*
|
|
97
|
-
* default: 'undefined'
|
|
98
|
-
*/
|
|
99
|
-
optionalValue?: `${OptionalValue}`;
|
|
100
|
-
/**
|
|
101
|
-
* Include optional value as property in output.
|
|
102
|
-
*
|
|
103
|
-
* default: false
|
|
104
|
-
*/
|
|
105
|
-
optionalInclude?: boolean;
|
|
106
|
-
};
|
|
107
|
-
export type ContainerItem = ContainerMountOptions & {
|
|
108
|
-
path?: string;
|
|
109
|
-
data: Validator | Container;
|
|
110
|
-
};
|
|
111
29
|
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
|
112
30
|
type PrevIndex = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];
|
|
113
31
|
export type ObjectPropertyPathExtended<T, Depth extends number = 4> = [Depth] extends [0] ? never : T extends ObjectLiteral ? {
|