validup 0.1.6 → 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
 
@@ -1,3 +1,17 @@
1
1
  export declare enum GroupKey {
2
2
  WILDCARD = "*"
3
3
  }
4
+ export declare enum OptionalValue {
5
+ /**
6
+ * value: undefined
7
+ */
8
+ UNDEFINED = "undefined",
9
+ /**
10
+ * value: null & undefined
11
+ */
12
+ NULL = "null",
13
+ /**
14
+ * value: empty string, false, 0
15
+ */
16
+ FALSY = "falsy"
17
+ }
@@ -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;
@@ -1 +1,2 @@
1
1
  export * from './error';
2
+ export * from './optional-value';
@@ -0,0 +1,8 @@
1
+ import { OptionalValue } from '../constants';
2
+ /**
3
+ * Check if input value (type of) satisfies optional value type constraint.
4
+ *
5
+ * @param value
6
+ * @param optionalValue
7
+ */
8
+ export declare function isOptionalValue(value: unknown, optionalValue?: `${OptionalValue}`): boolean;
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,17 +27,48 @@ 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 = {}));
32
+ return GroupKey;
33
+ }({});
34
+ var OptionalValue = /*#__PURE__*/ function(OptionalValue) {
35
+ /**
36
+ * value: undefined
37
+ */ OptionalValue["UNDEFINED"] = "undefined";
38
+ /**
39
+ * value: null & undefined
40
+ */ OptionalValue["NULL"] = "null";
41
+ /**
42
+ * value: empty string, false, 0
43
+ */ OptionalValue["FALSY"] = "falsy";
44
+ return OptionalValue;
45
+ }({});
46
+
47
+ /**
48
+ * Check if input value (type of) satisfies optional value type constraint.
49
+ *
50
+ * @param value
51
+ * @param optionalValue
52
+ */ function isOptionalValue(value, optionalValue) {
53
+ const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;
54
+ if (optionValueNormalized === OptionalValue.NULL) {
55
+ return value === null || typeof value === 'undefined';
56
+ }
57
+ if (optionValueNormalized === OptionalValue.UNDEFINED) {
58
+ return typeof value === 'undefined';
59
+ }
60
+ return !value;
61
+ }
31
62
 
32
63
  /*
33
64
  * Copyright (c) 2024-2024.
34
65
  * Author Peter Placzek (tada5hi)
35
66
  * For the full copyright and license information,
36
67
  * view the LICENSE file that was distributed with this source code.
37
- */ class ValidupValidatorError extends Error {
68
+ */ class ValidupError extends Error {
69
+ }
70
+
71
+ class ValidupValidatorError extends ValidupError {
38
72
  constructor(options){
39
73
  super(options.message);
40
74
  this.path = options.path;
@@ -45,14 +79,6 @@ function buildErrorMessageForAttributes(input) {
45
79
  }
46
80
  }
47
81
 
48
- /*
49
- * Copyright (c) 2024-2024.
50
- * Author Peter Placzek (tada5hi)
51
- * For the full copyright and license information,
52
- * view the LICENSE file that was distributed with this source code.
53
- */ class ValidupError extends Error {
54
- }
55
-
56
82
  class ValidupNestedError extends ValidupError {
57
83
  addChild(child) {
58
84
  this.children.push(child);
@@ -132,6 +158,12 @@ class Container {
132
158
  } else if (this.options.pathsToInclude) {
133
159
  pathsToInclude = this.options.pathsToInclude;
134
160
  }
161
+ let pathsToExclude;
162
+ if (options.pathsToExclude) {
163
+ pathsToExclude = options.pathsToExclude;
164
+ } else if (this.options.pathsToInclude) {
165
+ pathsToExclude = this.options.pathsToExclude;
166
+ }
135
167
  let itemCount = 0;
136
168
  for(let i = 0; i < this.items.length; i++){
137
169
  const item = this.items[i];
@@ -161,8 +193,15 @@ class Container {
161
193
  if (typeof pathsToInclude !== 'undefined' && pathsToInclude.indexOf(path) === -1) {
162
194
  continue;
163
195
  }
196
+ if (typeof pathsToExclude !== 'undefined' && pathsToExclude.indexOf(path) !== -1) {
197
+ continue;
198
+ }
164
199
  try {
165
- if (item.data instanceof Container) {
200
+ if (item.optional && isOptionalValue(value, item.optionalValue)) {
201
+ if (item.optionalInclude) {
202
+ output[path] = value;
203
+ }
204
+ } else if (item.data instanceof Container) {
166
205
  const tmp = await item.data.run(isObject(value) ? value : {}, {
167
206
  group: options.group,
168
207
  flat: true,
@@ -179,7 +218,8 @@ class Container {
179
218
  pathRaw: item.path ?? '',
180
219
  pathAbsolute,
181
220
  value,
182
- data
221
+ data,
222
+ group: options.group
183
223
  });
184
224
  }
185
225
  } catch (e) {
@@ -239,19 +279,19 @@ class Container {
239
279
  return temp;
240
280
  }
241
281
  isItemGroupIncluded(item, group) {
242
- if (group === exports.GroupKey.WILDCARD) {
282
+ if (group === GroupKey.WILDCARD) {
243
283
  return true;
244
284
  }
245
285
  if (item.group) {
246
286
  if (Array.isArray(item.group)) {
247
- if (item.group.indexOf(exports.GroupKey.WILDCARD) !== -1) {
287
+ if (item.group.indexOf(GroupKey.WILDCARD) !== -1) {
248
288
  return true;
249
289
  }
250
290
  if (group && item.group.indexOf(group) !== -1) {
251
291
  return true;
252
292
  }
253
293
  } else {
254
- if (item.group === exports.GroupKey.WILDCARD) {
294
+ if (item.group === GroupKey.WILDCARD) {
255
295
  return true;
256
296
  }
257
297
  if (item.group === group) {
@@ -287,10 +327,14 @@ class Container {
287
327
  }
288
328
 
289
329
  exports.Container = Container;
330
+ exports.GroupKey = GroupKey;
331
+ exports.OptionalValue = OptionalValue;
290
332
  exports.ValidupError = ValidupError;
291
333
  exports.ValidupNestedError = ValidupNestedError;
292
334
  exports.ValidupValidatorError = ValidupValidatorError;
335
+ exports.buildErrorMessageForAttribute = buildErrorMessageForAttribute;
293
336
  exports.buildErrorMessageForAttributes = buildErrorMessageForAttributes;
294
337
  exports.hasOwnProperty = hasOwnProperty;
295
338
  exports.isObject = isObject;
339
+ exports.isOptionalValue = isOptionalValue;
296
340
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/helpers/error.ts","../src/constants.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","/*\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 } 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 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 });\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","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","value","getPathValue","indexOf","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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aAAA;AAEA,YAAA,IAAIiE,GAAIC,CAAAA,EAAE,CAAC,CAAA,CAAA,KAAO,GAAK,EAAA;gBACnB/B,MAAU8B,IAAAA,GAAAA,CAAAA;aACP,MAAA;gBACH9B,MAAUA,IAAAA,MAAAA,CAAOnC,MAAM,GAAG,CAAA,GAAI,CAAC,CAAC,EAAEiE,GAAI,CAAA,CAAC,GAAGA,GAAAA,CAAAA;AAC9C,aAAA;AACJ,SAAA;QAEA,OAAO9B,MAAAA,CAAAA;AACX,KAAA;AAEUgC,IAAAA,UAAAA,GAAoB,EAE9B;;IAxRA7D,WAAYC,CAAAA,OAAAA,GAA+B,EAAE,CAAE;QAC3C,IAAI,CAACA,OAAO,GAAGA,OAAAA,CAAAA;QACf,IAAI,CAAC0B,KAAK,GAAG,EAAE,CAAA;AAEf,QAAA,IAAI,CAACkC,UAAU,EAAA,CAAA;AACnB,KAAA;AAoRJ;;;;;;;;;;"}
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 } 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,MAAM,GAAG,CAAG,EAAA;QAClB,OAAO,CAAC,eAAe,EAAEN,KAAAA,CAAMO,IAAI,CAAC,IAAA,CAAA,CAAM,aAAa,CAAC;AAC5D;IAEA,OAAOZ,6BAAAA,CAA8BK,KAAK,CAAC,CAAE,CAAA,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;;ACfD;;;;;AAKC,IACM,SAASC,eACZC,CA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C9C;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,17 +25,48 @@ 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 = {}));
30
+ return GroupKey;
31
+ }({});
32
+ var OptionalValue = /*#__PURE__*/ function(OptionalValue) {
33
+ /**
34
+ * value: undefined
35
+ */ OptionalValue["UNDEFINED"] = "undefined";
36
+ /**
37
+ * value: null & undefined
38
+ */ OptionalValue["NULL"] = "null";
39
+ /**
40
+ * value: empty string, false, 0
41
+ */ OptionalValue["FALSY"] = "falsy";
42
+ return OptionalValue;
43
+ }({});
44
+
45
+ /**
46
+ * Check if input value (type of) satisfies optional value type constraint.
47
+ *
48
+ * @param value
49
+ * @param optionalValue
50
+ */ function isOptionalValue(value, optionalValue) {
51
+ const optionValueNormalized = optionalValue || OptionalValue.UNDEFINED;
52
+ if (optionValueNormalized === OptionalValue.NULL) {
53
+ return value === null || typeof value === 'undefined';
54
+ }
55
+ if (optionValueNormalized === OptionalValue.UNDEFINED) {
56
+ return typeof value === 'undefined';
57
+ }
58
+ return !value;
59
+ }
29
60
 
30
61
  /*
31
62
  * Copyright (c) 2024-2024.
32
63
  * Author Peter Placzek (tada5hi)
33
64
  * For the full copyright and license information,
34
65
  * view the LICENSE file that was distributed with this source code.
35
- */ class ValidupValidatorError extends Error {
66
+ */ class ValidupError extends Error {
67
+ }
68
+
69
+ class ValidupValidatorError extends ValidupError {
36
70
  constructor(options){
37
71
  super(options.message);
38
72
  this.path = options.path;
@@ -43,14 +77,6 @@ function buildErrorMessageForAttributes(input) {
43
77
  }
44
78
  }
45
79
 
46
- /*
47
- * Copyright (c) 2024-2024.
48
- * Author Peter Placzek (tada5hi)
49
- * For the full copyright and license information,
50
- * view the LICENSE file that was distributed with this source code.
51
- */ class ValidupError extends Error {
52
- }
53
-
54
80
  class ValidupNestedError extends ValidupError {
55
81
  addChild(child) {
56
82
  this.children.push(child);
@@ -130,6 +156,12 @@ class Container {
130
156
  } else if (this.options.pathsToInclude) {
131
157
  pathsToInclude = this.options.pathsToInclude;
132
158
  }
159
+ let pathsToExclude;
160
+ if (options.pathsToExclude) {
161
+ pathsToExclude = options.pathsToExclude;
162
+ } else if (this.options.pathsToInclude) {
163
+ pathsToExclude = this.options.pathsToExclude;
164
+ }
133
165
  let itemCount = 0;
134
166
  for(let i = 0; i < this.items.length; i++){
135
167
  const item = this.items[i];
@@ -159,8 +191,15 @@ class Container {
159
191
  if (typeof pathsToInclude !== 'undefined' && pathsToInclude.indexOf(path) === -1) {
160
192
  continue;
161
193
  }
194
+ if (typeof pathsToExclude !== 'undefined' && pathsToExclude.indexOf(path) !== -1) {
195
+ continue;
196
+ }
162
197
  try {
163
- if (item.data instanceof Container) {
198
+ if (item.optional && isOptionalValue(value, item.optionalValue)) {
199
+ if (item.optionalInclude) {
200
+ output[path] = value;
201
+ }
202
+ } else if (item.data instanceof Container) {
164
203
  const tmp = await item.data.run(isObject(value) ? value : {}, {
165
204
  group: options.group,
166
205
  flat: true,
@@ -177,7 +216,8 @@ class Container {
177
216
  pathRaw: item.path ?? '',
178
217
  pathAbsolute,
179
218
  value,
180
- data
219
+ data,
220
+ group: options.group
181
221
  });
182
222
  }
183
223
  } catch (e) {
@@ -284,5 +324,5 @@ class Container {
284
324
  }
285
325
  }
286
326
 
287
- export { Container, GroupKey, ValidupError, ValidupNestedError, ValidupValidatorError, buildErrorMessageForAttributes, hasOwnProperty, isObject };
327
+ export { Container, GroupKey, OptionalValue, ValidupError, ValidupNestedError, ValidupValidatorError, buildErrorMessageForAttribute, buildErrorMessageForAttributes, hasOwnProperty, isObject, isOptionalValue };
288
328
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/helpers/error.ts","../src/constants.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","/*\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 } 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 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 });\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","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","value","getPathValue","indexOf","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,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,IAAA,IAAA,SAAA;AAEWS,CAAAA,SAAAA,QAAAA,EAAAA;;GAAAA,QAAAA,KAAAA,QAAAA,GAAAA,EAAAA,CAAAA,CAAAA;;ACPZ;;;;;IAgBO,MAAMC,qBAA8BC,SAAAA,KAAAA,CAAAA;AA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,CAAC0B,KAAK,GAAG,EAAE,CAAA;AAEf,QAAA,IAAI,CAACkC,UAAU,EAAA,CAAA;AACnB,KAAA;AAoRJ;;;;"}
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,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,aAAcJ,CAAAA,KAAAA,CAAAA;KACnB,MAAA;QACHC,KAAQI,GAAAA,MAA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QAAAA,CAASsE,QAAQ,EAAE;oBAClC,OAAO,IAAA;AACX;gBAEA,IAAIzB,IAAAA,CAAKE,KAAK,KAAKA,KAAO,EAAA;oBACtB,OAAO,IAAA;AACX;AACJ;YAEA,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/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { OptionalValue } from './constants';
1
2
  import type { Container } from './module';
2
3
  export type ObjectLiteral = Record<string | number, any>;
3
4
  export type ContainerOptions<T> = {
@@ -11,6 +12,12 @@ export type ContainerOptions<T> = {
11
12
  * be considered for execution.
12
13
  */
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>[];
14
21
  };
15
22
  export type ContainerRunOptions<T extends Record<string, any> = Record<string, any>> = {
16
23
  /**
@@ -37,6 +44,12 @@ export type ContainerRunOptions<T extends Record<string, any> = Record<string, a
37
44
  * be considered for execution.
38
45
  */
39
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>[];
40
53
  };
41
54
  export type ValidatorContext = {
42
55
  /**
@@ -59,16 +72,37 @@ export type ValidatorContext = {
59
72
  * The input data of the current container.
60
73
  */
61
74
  data: Record<string, any>;
75
+ /**
76
+ * The group name for which the validator is executed.
77
+ */
78
+ group?: string;
62
79
  };
63
80
  export type Validator = (ctx: ValidatorContext) => Promise<unknown> | unknown;
64
81
  export type ContainerMountOptions = {
82
+ /**
83
+ * Group(s) to execute.
84
+ */
65
85
  group?: string | string[];
66
86
  /**
67
- * Limit mounted paths on execution.
68
- * By default, all mounted containers/validators will
69
- * be considered for execution.
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
70
104
  */
71
- pathsToInclude?: string[];
105
+ optionalInclude?: boolean;
72
106
  };
73
107
  export type ContainerItem = ContainerMountOptions & {
74
108
  path?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "validup",
3
- "version": "0.1.6",
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
  }