validup 0.1.7 → 0.1.8

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/README.md CHANGED
@@ -165,7 +165,11 @@ type ValidatorContext = {
165
165
  /**
166
166
  * The input data of the current container.
167
167
  */
168
- data: Record<string, any>
168
+ data: Record<string, any>,
169
+ /**
170
+ * The group name for which the validator is executed.
171
+ */
172
+ group?: string
169
173
  };
170
174
  ```
171
175
 
@@ -5,7 +5,7 @@ export type ValidupNestedErrorOptions = {
5
5
  message?: string;
6
6
  };
7
7
  export declare class ValidupNestedError extends ValidupError {
8
- children: ValidupValidatorError[];
8
+ readonly children: ValidupValidatorError[];
9
9
  constructor(options?: ValidupNestedErrorOptions);
10
10
  addChild(child: ValidupValidatorError): void;
11
11
  }
@@ -1,3 +1,4 @@
1
+ import { ValidupError } from './base';
1
2
  export type ValidupValidatorErrorOptions = {
2
3
  path: string;
3
4
  pathAbsolute?: string;
@@ -6,7 +7,7 @@ export type ValidupValidatorErrorOptions = {
6
7
  received?: unknown;
7
8
  expected?: unknown;
8
9
  };
9
- export declare class ValidupValidatorError extends Error {
10
+ export declare class ValidupValidatorError extends ValidupError {
10
11
  readonly path: string;
11
12
  readonly pathAbsolute: string;
12
13
  readonly code?: string | null;
@@ -1 +1,2 @@
1
+ export declare function buildErrorMessageForAttribute(key: string | number): string;
1
2
  export declare function buildErrorMessageForAttributes(input: (number | string)[] | Record<string, any>): string;
package/dist/index.cjs CHANGED
@@ -3,6 +3,9 @@
3
3
  var smob = require('smob');
4
4
  var pathtrace = require('pathtrace');
5
5
 
6
+ function buildErrorMessageForAttribute(key) {
7
+ return `The attribute ${String(key)} is invalid.`;
8
+ }
6
9
  function buildErrorMessageForAttributes(input) {
7
10
  let names;
8
11
  if (Array.isArray(input)) {
@@ -16,7 +19,7 @@ function buildErrorMessageForAttributes(input) {
16
19
  if (names.length > 1) {
17
20
  return `The attributes ${names.join(', ')} are invalid.`;
18
21
  }
19
- return `The attribute ${String(names[0])} is invalid.`;
22
+ return buildErrorMessageForAttribute(names[0]);
20
23
  }
21
24
 
22
25
  /*
@@ -24,12 +27,11 @@ function buildErrorMessageForAttributes(input) {
24
27
  * Author Peter Placzek (tada5hi)
25
28
  * For the full copyright and license information,
26
29
  * view the LICENSE file that was distributed with this source code.
27
- */ exports.GroupKey = void 0;
28
- (function(GroupKey) {
30
+ */ var GroupKey = /*#__PURE__*/ function(GroupKey) {
29
31
  GroupKey["WILDCARD"] = "*";
30
- })(exports.GroupKey || (exports.GroupKey = {}));
31
- exports.OptionalValue = void 0;
32
- (function(OptionalValue) {
32
+ return GroupKey;
33
+ }({});
34
+ var OptionalValue = /*#__PURE__*/ function(OptionalValue) {
33
35
  /**
34
36
  * value: undefined
35
37
  */ OptionalValue["UNDEFINED"] = "undefined";
@@ -39,7 +41,8 @@ exports.OptionalValue = void 0;
39
41
  /**
40
42
  * value: empty string, false, 0
41
43
  */ OptionalValue["FALSY"] = "falsy";
42
- })(exports.OptionalValue || (exports.OptionalValue = {}));
44
+ return OptionalValue;
45
+ }({});
43
46
 
44
47
  /**
45
48
  * Check if input value (type of) satisfies optional value type constraint.
@@ -47,11 +50,11 @@ exports.OptionalValue = void 0;
47
50
  * @param value
48
51
  * @param optionalValue
49
52
  */ function isOptionalValue(value, optionalValue) {
50
- const optionValueNormalized = optionalValue || exports.OptionalValue.UNDEFINED;
51
- if (optionValueNormalized === exports.OptionalValue.NULL) {
52
- return value === null;
53
+ const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;
54
+ if (optionValueNormalized === OptionalValue.NULL) {
55
+ return value === null || typeof value === 'undefined';
53
56
  }
54
- if (optionValueNormalized === exports.OptionalValue.UNDEFINED) {
57
+ if (optionValueNormalized === OptionalValue.UNDEFINED) {
55
58
  return typeof value === 'undefined';
56
59
  }
57
60
  return !value;
@@ -62,7 +65,10 @@ exports.OptionalValue = void 0;
62
65
  * Author Peter Placzek (tada5hi)
63
66
  * For the full copyright and license information,
64
67
  * view the LICENSE file that was distributed with this source code.
65
- */ class ValidupValidatorError extends Error {
68
+ */ class ValidupError extends Error {
69
+ }
70
+
71
+ class ValidupValidatorError extends ValidupError {
66
72
  constructor(options){
67
73
  super(options.message);
68
74
  this.path = options.path;
@@ -73,14 +79,6 @@ exports.OptionalValue = void 0;
73
79
  }
74
80
  }
75
81
 
76
- /*
77
- * Copyright (c) 2024-2024.
78
- * Author Peter Placzek (tada5hi)
79
- * For the full copyright and license information,
80
- * view the LICENSE file that was distributed with this source code.
81
- */ class ValidupError extends Error {
82
- }
83
-
84
82
  class ValidupNestedError extends ValidupError {
85
83
  addChild(child) {
86
84
  this.children.push(child);
@@ -160,6 +158,12 @@ class Container {
160
158
  } else if (this.options.pathsToInclude) {
161
159
  pathsToInclude = this.options.pathsToInclude;
162
160
  }
161
+ let pathsToExclude;
162
+ if (options.pathsToExclude) {
163
+ pathsToExclude = options.pathsToExclude;
164
+ } else if (this.options.pathsToInclude) {
165
+ pathsToExclude = this.options.pathsToExclude;
166
+ }
163
167
  let itemCount = 0;
164
168
  for(let i = 0; i < this.items.length; i++){
165
169
  const item = this.items[i];
@@ -189,23 +193,24 @@ class Container {
189
193
  if (typeof pathsToInclude !== 'undefined' && pathsToInclude.indexOf(path) === -1) {
190
194
  continue;
191
195
  }
196
+ if (typeof pathsToExclude !== 'undefined' && pathsToExclude.indexOf(path) !== -1) {
197
+ continue;
198
+ }
192
199
  try {
193
- if (item.data instanceof Container) {
194
- if (item.optional && isOptionalValue(value, item.optionalValue)) {
195
- if (item.optionalInclude) {
196
- output[path] = value;
197
- }
198
- } else {
199
- const tmp = await item.data.run(isObject(value) ? value : {}, {
200
- group: options.group,
201
- flat: true,
202
- path: pathAbsolute,
203
- pathsToInclude: options.pathsToInclude
204
- });
205
- const tmpKeys = Object.keys(tmp);
206
- for(let k = 0; k < tmpKeys.length; k++){
207
- output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];
208
- }
200
+ if (item.optional && isOptionalValue(value, item.optionalValue)) {
201
+ if (item.optionalInclude) {
202
+ output[path] = value;
203
+ }
204
+ } else if (item.data instanceof Container) {
205
+ const tmp = await item.data.run(isObject(value) ? value : {}, {
206
+ group: options.group,
207
+ flat: true,
208
+ path: pathAbsolute,
209
+ pathsToInclude: options.pathsToInclude
210
+ });
211
+ const tmpKeys = Object.keys(tmp);
212
+ for(let k = 0; k < tmpKeys.length; k++){
213
+ output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];
209
214
  }
210
215
  } else {
211
216
  output[path] = await item.data({
@@ -213,7 +218,8 @@ class Container {
213
218
  pathRaw: item.path ?? '',
214
219
  pathAbsolute,
215
220
  value,
216
- data
221
+ data,
222
+ group: options.group
217
223
  });
218
224
  }
219
225
  } catch (e) {
@@ -273,19 +279,19 @@ class Container {
273
279
  return temp;
274
280
  }
275
281
  isItemGroupIncluded(item, group) {
276
- if (group === exports.GroupKey.WILDCARD) {
282
+ if (group === GroupKey.WILDCARD) {
277
283
  return true;
278
284
  }
279
285
  if (item.group) {
280
286
  if (Array.isArray(item.group)) {
281
- if (item.group.indexOf(exports.GroupKey.WILDCARD) !== -1) {
287
+ if (item.group.indexOf(GroupKey.WILDCARD) !== -1) {
282
288
  return true;
283
289
  }
284
290
  if (group && item.group.indexOf(group) !== -1) {
285
291
  return true;
286
292
  }
287
293
  } else {
288
- if (item.group === exports.GroupKey.WILDCARD) {
294
+ if (item.group === GroupKey.WILDCARD) {
289
295
  return true;
290
296
  }
291
297
  if (item.group === group) {
@@ -321,9 +327,12 @@ class Container {
321
327
  }
322
328
 
323
329
  exports.Container = Container;
330
+ exports.GroupKey = GroupKey;
331
+ exports.OptionalValue = OptionalValue;
324
332
  exports.ValidupError = ValidupError;
325
333
  exports.ValidupNestedError = ValidupNestedError;
326
334
  exports.ValidupValidatorError = ValidupValidatorError;
335
+ exports.buildErrorMessageForAttribute = buildErrorMessageForAttribute;
327
336
  exports.buildErrorMessageForAttributes = buildErrorMessageForAttributes;
328
337
  exports.hasOwnProperty = hasOwnProperty;
329
338
  exports.isObject = isObject;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/helpers/error.ts","../src/constants.ts","../src/helpers/optional-value.ts","../src/errors/validator.ts","../src/errors/base.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 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 `The attribute ${String(names[0])} is invalid.`;\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;\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 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 Error {\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\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 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 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 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 try {\n if (item.data instanceof Container) {\n if (\n item.optional &&\n isOptionalValue(value, item.optionalValue)\n ) {\n if (item.optionalInclude) {\n output[path] = value;\n }\n } else {\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 }\n } else {\n output[path] = await item.data({\n path,\n pathRaw: item.path ?? '',\n\n pathAbsolute,\n value,\n data,\n });\n }\n } catch (e) {\n if (e instanceof ValidupValidatorError) {\n errors.push(e);\n } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\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 }\n\n errorKeys.push(pathAbsolute);\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":["buildErrorMessageForAttributes","input","names","Array","isArray","distinctArray","Object","keys","length","join","String","GroupKey","OptionalValue","isOptionalValue","value","optionalValue","optionValueNormalized","UNDEFINED","NULL","ValidupValidatorError","Error","constructor","options","message","path","pathAbsolute","code","received","expected","ValidupError","ValidupNestedError","addChild","child","children","push","hasOwnProperty","obj","prop","prototype","call","isObject","Container","mount","args","SyntaxError","data","dataIsContainer","i","items","run","output","errors","errorKeys","pathsToInclude","itemCount","item","isItemGroupIncluded","group","pathsCount","paths","expandPath","j","mergePaths","getPathValue","indexOf","optional","optionalInclude","tmp","flat","tmpKeys","k","pathRaw","e","error","cause","oneOf","defaults","defaultKeys","temp","setPathValue","WILDCARD","arg","at","initialize"],"mappings":";;;;;AASO,SAASA,+BAA+BC,KAAgD,EAAA;IAC3F,IAAIC,KAAAA,CAAAA;IACJ,IAAIC,KAAAA,CAAMC,OAAO,CAACH,KAAQ,CAAA,EAAA;AACtBC,QAAAA,KAAAA,GAAQG,kBAAcJ,CAAAA,KAAAA,CAAAA,CAAAA;KACnB,MAAA;QACHC,KAAQI,GAAAA,MAAAA,CAAOC,IAAI,CAACN,KAAAA,CAAAA,CAAAA;AACxB,KAAA;IAEA,IAAIC,KAAAA,CAAMM,MAAM,KAAK,CAAG,EAAA;QACpB,OAAO,+BAAA,CAAA;AACX,KAAA;IAEA,IAAIN,KAAAA,CAAMM,MAAM,GAAG,CAAG,EAAA;QAClB,OAAO,CAAC,eAAe,EAAEN,KAAAA,CAAMO,IAAI,CAAC,IAAA,CAAA,CAAM,aAAa,CAAC,CAAA;AAC5D,KAAA;IAEA,OAAO,CAAC,cAAc,EAAEC,MAAAA,CAAOR,KAAK,CAAC,CAAA,CAAE,CAAE,CAAA,YAAY,CAAC,CAAA;AAC1D;;AC1BA;;;;;AAKC,IAAAS,0BAAA;AAEWA,CAAAA,SAAAA,QAAAA,EAAAA;;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/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 } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\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 }\n\n errorKeys.push(pathAbsolute);\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","constructor","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","error","cause","oneOf","defaults","defaultKeys","temp","setPathValue","WILDCARD","arg","at","initialize"],"mappings":";;;;;AASO,SAASA,8BAA8BC,GAAoB,EAAA;AAC9D,IAAA,OAAO,CAAC,cAAc,EAAEC,MAAOD,CAAAA,GAAAA,CAAAA,CAAK,YAAY,CAAC;AACrD;AAEO,SAASE,+BAA+BC,KAAgD,EAAA;IAC3F,IAAIC,KAAAA;IACJ,IAAIC,KAAAA,CAAMC,OAAO,CAACH,KAAQ,CAAA,EAAA;AACtBC,QAAAA,KAAAA,GAAQG,kBAAcJ,CAAAA,KAAAA,CAAAA;KACnB,MAAA;QACHC,KAAQI,GAAAA,MAAAA,CAAOC,IAAI,CAACN,KAAAA,CAAAA;AACxB;IAEA,IAAIC,KAAAA,CAAMM,MAAM,KAAK,CAAG,EAAA;QACpB,OAAO,+BAAA;AACX;IAEA,IAAIN,KAAAA,CAAMM,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OAAO,KAAA;AACX;QAEA,OAAO,IAAA;AACX;IAEQK,UAAW,CAAA,GAAGpB,IAA4B,EAAE;AAChD,QAAA,IAAIO,MAAkB,GAAA,EAAA;AAEtB,QAAA,IAAK,IAAIH,CAAI,GAAA,CAAA,EAAGA,IAAIJ,IAAKlC,CAAAA,MAAM,EAAEsC,CAAK,EAAA,CAAA;YAClC,MAAMmC,GAAAA,GAAMvC,IAAI,CAACI,CAAE,CAAA;AACnB,YAAA,IAAI,CAACmC,GAAAA,IAAOA,GAAIzE,CAAAA,MAAM,KAAK,CAAG,EAAA;AAC1B,gBAAA;AACJ;AAEA,YAAA,IAAIyE,GAAIC,CAAAA,EAAE,CAAC,CAAA,CAAA,KAAO,GAAK,EAAA;gBACnBjC,MAAUgC,IAAAA,GAAAA;aACP,MAAA;gBACHhC,MAAUA,IAAAA,MAAAA,CAAOzC,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAEyE,KAAK,GAAGA,GAAAA;AAC9C;AACJ;QAEA,OAAOhC,MAAAA;AACX;AAEUkC,IAAAA,UAAAA,GAAoB;;IA5S9B9D,WAAYC,CAAAA,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACyB,KAAK,GAAG,EAAE;AAEf,QAAA,IAAI,CAACoC,UAAU,EAAA;AACnB;AA0SJ;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  import { distinctArray } from 'smob';
2
2
  import { expandPath, getPathValue, setPathValue } from 'pathtrace';
3
3
 
4
+ function buildErrorMessageForAttribute(key) {
5
+ return `The attribute ${String(key)} is invalid.`;
6
+ }
4
7
  function buildErrorMessageForAttributes(input) {
5
8
  let names;
6
9
  if (Array.isArray(input)) {
@@ -14,7 +17,7 @@ function buildErrorMessageForAttributes(input) {
14
17
  if (names.length > 1) {
15
18
  return `The attributes ${names.join(', ')} are invalid.`;
16
19
  }
17
- return `The attribute ${String(names[0])} is invalid.`;
20
+ return buildErrorMessageForAttribute(names[0]);
18
21
  }
19
22
 
20
23
  /*
@@ -22,12 +25,11 @@ function buildErrorMessageForAttributes(input) {
22
25
  * Author Peter Placzek (tada5hi)
23
26
  * For the full copyright and license information,
24
27
  * view the LICENSE file that was distributed with this source code.
25
- */ var GroupKey;
26
- (function(GroupKey) {
28
+ */ var GroupKey = /*#__PURE__*/ function(GroupKey) {
27
29
  GroupKey["WILDCARD"] = "*";
28
- })(GroupKey || (GroupKey = {}));
29
- var OptionalValue;
30
- (function(OptionalValue) {
30
+ return GroupKey;
31
+ }({});
32
+ var OptionalValue = /*#__PURE__*/ function(OptionalValue) {
31
33
  /**
32
34
  * value: undefined
33
35
  */ OptionalValue["UNDEFINED"] = "undefined";
@@ -37,7 +39,8 @@ var OptionalValue;
37
39
  /**
38
40
  * value: empty string, false, 0
39
41
  */ OptionalValue["FALSY"] = "falsy";
40
- })(OptionalValue || (OptionalValue = {}));
42
+ return OptionalValue;
43
+ }({});
41
44
 
42
45
  /**
43
46
  * Check if input value (type of) satisfies optional value type constraint.
@@ -47,7 +50,7 @@ var OptionalValue;
47
50
  */ function isOptionalValue(value, optionalValue) {
48
51
  const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;
49
52
  if (optionValueNormalized === OptionalValue.NULL) {
50
- return value === null;
53
+ return value === null || typeof value === 'undefined';
51
54
  }
52
55
  if (optionValueNormalized === OptionalValue.UNDEFINED) {
53
56
  return typeof value === 'undefined';
@@ -60,7 +63,10 @@ var OptionalValue;
60
63
  * Author Peter Placzek (tada5hi)
61
64
  * For the full copyright and license information,
62
65
  * view the LICENSE file that was distributed with this source code.
63
- */ class ValidupValidatorError extends Error {
66
+ */ class ValidupError extends Error {
67
+ }
68
+
69
+ class ValidupValidatorError extends ValidupError {
64
70
  constructor(options){
65
71
  super(options.message);
66
72
  this.path = options.path;
@@ -71,14 +77,6 @@ var OptionalValue;
71
77
  }
72
78
  }
73
79
 
74
- /*
75
- * Copyright (c) 2024-2024.
76
- * Author Peter Placzek (tada5hi)
77
- * For the full copyright and license information,
78
- * view the LICENSE file that was distributed with this source code.
79
- */ class ValidupError extends Error {
80
- }
81
-
82
80
  class ValidupNestedError extends ValidupError {
83
81
  addChild(child) {
84
82
  this.children.push(child);
@@ -158,6 +156,12 @@ class Container {
158
156
  } else if (this.options.pathsToInclude) {
159
157
  pathsToInclude = this.options.pathsToInclude;
160
158
  }
159
+ let pathsToExclude;
160
+ if (options.pathsToExclude) {
161
+ pathsToExclude = options.pathsToExclude;
162
+ } else if (this.options.pathsToInclude) {
163
+ pathsToExclude = this.options.pathsToExclude;
164
+ }
161
165
  let itemCount = 0;
162
166
  for(let i = 0; i < this.items.length; i++){
163
167
  const item = this.items[i];
@@ -187,23 +191,24 @@ class Container {
187
191
  if (typeof pathsToInclude !== 'undefined' && pathsToInclude.indexOf(path) === -1) {
188
192
  continue;
189
193
  }
194
+ if (typeof pathsToExclude !== 'undefined' && pathsToExclude.indexOf(path) !== -1) {
195
+ continue;
196
+ }
190
197
  try {
191
- if (item.data instanceof Container) {
192
- if (item.optional && isOptionalValue(value, item.optionalValue)) {
193
- if (item.optionalInclude) {
194
- output[path] = value;
195
- }
196
- } else {
197
- const tmp = await item.data.run(isObject(value) ? value : {}, {
198
- group: options.group,
199
- flat: true,
200
- path: pathAbsolute,
201
- pathsToInclude: options.pathsToInclude
202
- });
203
- const tmpKeys = Object.keys(tmp);
204
- for(let k = 0; k < tmpKeys.length; k++){
205
- output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];
206
- }
198
+ if (item.optional && isOptionalValue(value, item.optionalValue)) {
199
+ if (item.optionalInclude) {
200
+ output[path] = value;
201
+ }
202
+ } else if (item.data instanceof Container) {
203
+ const tmp = await item.data.run(isObject(value) ? value : {}, {
204
+ group: options.group,
205
+ flat: true,
206
+ path: pathAbsolute,
207
+ pathsToInclude: options.pathsToInclude
208
+ });
209
+ const tmpKeys = Object.keys(tmp);
210
+ for(let k = 0; k < tmpKeys.length; k++){
211
+ output[this.mergePaths(path, tmpKeys[k])] = tmp[tmpKeys[k]];
207
212
  }
208
213
  } else {
209
214
  output[path] = await item.data({
@@ -211,7 +216,8 @@ class Container {
211
216
  pathRaw: item.path ?? '',
212
217
  pathAbsolute,
213
218
  value,
214
- data
219
+ data,
220
+ group: options.group
215
221
  });
216
222
  }
217
223
  } catch (e) {
@@ -318,5 +324,5 @@ class Container {
318
324
  }
319
325
  }
320
326
 
321
- export { Container, GroupKey, OptionalValue, ValidupError, ValidupNestedError, ValidupValidatorError, buildErrorMessageForAttributes, hasOwnProperty, isObject, isOptionalValue };
327
+ export { Container, GroupKey, OptionalValue, ValidupError, ValidupNestedError, ValidupValidatorError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, hasOwnProperty, isObject, isOptionalValue };
322
328
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/helpers/error.ts","../src/constants.ts","../src/helpers/optional-value.ts","../src/errors/validator.ts","../src/errors/base.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 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 `The attribute ${String(names[0])} is invalid.`;\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;\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 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 Error {\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\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 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 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 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 try {\n if (item.data instanceof Container) {\n if (\n item.optional &&\n isOptionalValue(value, item.optionalValue)\n ) {\n if (item.optionalInclude) {\n output[path] = value;\n }\n } else {\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 }\n } else {\n output[path] = await item.data({\n path,\n pathRaw: item.path ?? '',\n\n pathAbsolute,\n value,\n data,\n });\n }\n } catch (e) {\n if (e instanceof ValidupValidatorError) {\n errors.push(e);\n } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\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 }\n\n errorKeys.push(pathAbsolute);\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":["buildErrorMessageForAttributes","input","names","Array","isArray","distinctArray","Object","keys","length","join","String","GroupKey","OptionalValue","isOptionalValue","value","optionalValue","optionValueNormalized","UNDEFINED","NULL","ValidupValidatorError","Error","constructor","options","message","path","pathAbsolute","code","received","expected","ValidupError","ValidupNestedError","addChild","child","children","push","hasOwnProperty","obj","prop","prototype","call","isObject","Container","mount","args","SyntaxError","data","dataIsContainer","i","items","run","output","errors","errorKeys","pathsToInclude","itemCount","item","isItemGroupIncluded","group","pathsCount","paths","expandPath","j","mergePaths","getPathValue","indexOf","optional","optionalInclude","tmp","flat","tmpKeys","k","pathRaw","e","error","cause","oneOf","defaults","defaultKeys","temp","setPathValue","WILDCARD","arg","at","initialize"],"mappings":";;;AASO,SAASA,+BAA+BC,KAAgD,EAAA;IAC3F,IAAIC,KAAAA,CAAAA;IACJ,IAAIC,KAAAA,CAAMC,OAAO,CAACH,KAAQ,CAAA,EAAA;AACtBC,QAAAA,KAAAA,GAAQG,aAAcJ,CAAAA,KAAAA,CAAAA,CAAAA;KACnB,MAAA;QACHC,KAAQI,GAAAA,MA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,MAAAA,CAAO1C,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAEyE,GAAI,CAAA,CAAC,GAAGA,GAAAA,CAAAA;AAC9C,aAAA;AACJ,SAAA;QAEA,OAAO/B,MAAAA,CAAAA;AACX,KAAA;AAEUiC,IAAAA,UAAAA,GAAoB,EAE9B;;IAjSA9D,WAAYC,CAAAA,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA,CAAAA;QACf,IAAI,CAAC0B,KAAK,GAAG,EAAE,CAAA;AAEf,QAAA,IAAI,CAACmC,UAAU,EAAA,CAAA;AACnB,KAAA;AA6RJ;;;;"}
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 } else if (e instanceof ValidupNestedError) {\n errors.push(...e.children);\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 }\n\n errorKeys.push(pathAbsolute);\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","constructor","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","error","cause","oneOf","defaults","defaultKeys","temp","setPathValue","WILDCARD","arg","at","initialize"],"mappings":";;;AASO,SAASA,8BAA8BC,GAA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,CAACyB,KAAK,GAAG,EAAE;AAEf,QAAA,IAAI,CAACoC,UAAU,EAAA;AACnB;AA0SJ;;;;"}
package/dist/types.d.ts CHANGED
@@ -12,6 +12,12 @@ export type ContainerOptions<T> = {
12
12
  * be considered for execution.
13
13
  */
14
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>[];
15
21
  };
16
22
  export type ContainerRunOptions<T extends Record<string, any> = Record<string, any>> = {
17
23
  /**
@@ -38,6 +44,12 @@ export type ContainerRunOptions<T extends Record<string, any> = Record<string, a
38
44
  * be considered for execution.
39
45
  */
40
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>[];
41
53
  };
42
54
  export type ValidatorContext = {
43
55
  /**
@@ -60,6 +72,10 @@ export type ValidatorContext = {
60
72
  * The input data of the current container.
61
73
  */
62
74
  data: Record<string, any>;
75
+ /**
76
+ * The group name for which the validator is executed.
77
+ */
78
+ group?: string;
63
79
  };
64
80
  export type Validator = (ctx: ValidatorContext) => Promise<unknown> | unknown;
65
81
  export type ContainerMountOptions = {
@@ -68,13 +84,8 @@ export type ContainerMountOptions = {
68
84
  */
69
85
  group?: string | string[];
70
86
  /**
71
- * Limit mounted paths on execution.
72
- * By default, all mounted containers/validators will
73
- * be considered for execution.
74
- */
75
- pathsToInclude?: string[];
76
- /**
77
- * Specify if the mounted container has to be evaluated successfully.
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.
78
89
  *
79
90
  * default: false
80
91
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "validup",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "A validation library.",
5
5
  "author": {
6
6
  "name": "Peter Placzek",
@@ -40,7 +40,7 @@
40
40
  "keywords": [],
41
41
  "license": "MIT",
42
42
  "dependencies": {
43
- "pathtrace": "^1.0.0",
43
+ "pathtrace": "^1.1.0",
44
44
  "smob": "^1.5.0"
45
45
  }
46
46
  }