@travetto/schema 3.1.6 → 3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/schema",
3
- "version": "3.1.6",
3
+ "version": "3.1.8",
4
4
  "description": "Data type registry for runtime validation, reflection and binding.",
5
5
  "keywords": [
6
6
  "schema",
@@ -27,10 +27,10 @@
27
27
  "directory": "module/schema"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/registry": "^3.1.3"
30
+ "@travetto/registry": "^3.1.4"
31
31
  },
32
32
  "peerDependencies": {
33
- "@travetto/transformer": "^3.1.4"
33
+ "@travetto/transformer": "^3.1.5"
34
34
  },
35
35
  "peerDependenciesMeta": {
36
36
  "@travetto/transformer": {
@@ -56,8 +56,16 @@ export class SchemaValidator {
56
56
  * @param relative The relative path of object traversal
57
57
  */
58
58
  static #validateFieldSchema(fieldSchema: FieldConfig, val: unknown, relative: string = ''): ValidationError[] {
59
- const path = `${relative}${relative && '.'}${fieldSchema.name}`;
59
+ return this.#validateFieldSchemaRaw(fieldSchema, val, `${relative}${relative ? '.' : ''}${fieldSchema.name}`);
60
+ }
60
61
 
62
+ /**
63
+ * Validate a single field config against a passed in value
64
+ * @param fieldSchema The field schema configuration
65
+ * @param val The raw value, could be an array or not
66
+ * @param path The current path of validation traversal
67
+ */
68
+ static #validateFieldSchemaRaw(fieldSchema: FieldConfig, val: unknown, path: string = ''): ValidationError[] {
61
69
  const hasValue = !(val === undefined || val === null || (typeof val === 'string' && val === '') || (Array.isArray(val) && val.length === 0));
62
70
 
63
71
  if (!hasValue) {
@@ -316,10 +324,10 @@ export class SchemaValidator {
316
324
  * @param method The method being invoked
317
325
  * @param params The params to validate
318
326
  */
319
- static async validateMethod<T>(cls: Class<T>, method: string, params: unknown[]): Promise<void> {
327
+ static async validateMethod<T>(cls: Class<T>, method: string, params: unknown[], prefixes: (string | undefined)[] = []): Promise<void> {
320
328
  const errors: ValidationError[] = [];
321
329
  for (const field of SchemaRegistry.getMethodSchema(cls, method)) {
322
- errors.push(...this.#validateFieldSchema(field, params[field.index!]));
330
+ errors.push(...this.#validateFieldSchemaRaw(field, params[field.index!], prefixes[field.index!]));
323
331
  }
324
332
  if (errors.length) {
325
333
  throw new ValidationResultError(errors);