z-schema 12.2.0 → 12.3.1

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.
Files changed (110) hide show
  1. package/README.md +2 -2
  2. package/bin/z-schema +1 -1
  3. package/cjs/{index.js → index.cjs} +696 -687
  4. package/cjs/{index.d.ts → index.d.cts} +47 -26
  5. package/dist/{errors.d.mts → errors.d.ts} +2 -2
  6. package/dist/{errors.mjs → errors.js} +1 -2
  7. package/dist/{format-validators.mjs → format-validators.js} +43 -36
  8. package/dist/{index.d.mts → index.d.ts} +9 -9
  9. package/dist/{index.mjs → index.js} +3 -3
  10. package/dist/{json-schema-versions.d.mts → json-schema-versions.d.ts} +34 -3
  11. package/dist/{json-schema.d.mts → json-schema.d.ts} +7 -7
  12. package/dist/{json-schema.mjs → json-schema.js} +7 -12
  13. package/dist/{json-validation.mjs → json-validation.js} +143 -127
  14. package/dist/{report.d.mts → report.d.ts} +7 -8
  15. package/dist/{report.mjs → report.js} +28 -31
  16. package/dist/{schema-cache.d.mts → schema-cache.d.ts} +4 -4
  17. package/dist/{schema-cache.mjs → schema-cache.js} +10 -11
  18. package/dist/{schema-compiler.d.mts → schema-compiler.d.ts} +4 -4
  19. package/dist/{schema-compiler.mjs → schema-compiler.js} +95 -77
  20. package/dist/{schema-validator.d.mts → schema-validator.d.ts} +5 -5
  21. package/dist/{schema-validator.mjs → schema-validator.js} +138 -166
  22. package/dist/utils/{array.mjs → array.js} +4 -3
  23. package/dist/utils/{base64.mjs → base64.js} +3 -2
  24. package/dist/utils/{clone.mjs → clone.js} +18 -20
  25. package/dist/utils/{hostname.mjs → hostname.js} +19 -22
  26. package/dist/utils/{json.mjs → json.js} +11 -7
  27. package/dist/utils/{schema-regex.mjs → schema-regex.js} +5 -5
  28. package/dist/utils/{time.mjs → time.js} +5 -5
  29. package/dist/utils/unicode.js +22 -0
  30. package/dist/utils/{what-is.mjs → what-is.js} +1 -2
  31. package/dist/validation/{array.mjs → array.js} +18 -20
  32. package/dist/validation/{combinators.mjs → combinators.js} +16 -16
  33. package/dist/validation/{numeric.mjs → numeric.js} +11 -11
  34. package/dist/validation/{object.mjs → object.js} +35 -34
  35. package/dist/validation/{ref.mjs → ref.js} +4 -4
  36. package/dist/validation/{shared.mjs → shared.js} +12 -11
  37. package/dist/validation/{string.mjs → string.js} +32 -32
  38. package/dist/validation/type.js +34 -0
  39. package/dist/{z-schema-base.d.mts → z-schema-base.d.ts} +11 -12
  40. package/dist/{z-schema-base.mjs → z-schema-base.js} +45 -40
  41. package/dist/{z-schema-options.d.mts → z-schema-options.d.ts} +3 -3
  42. package/dist/{z-schema-options.mjs → z-schema-options.js} +4 -4
  43. package/dist/{z-schema-reader.d.mts → z-schema-reader.d.ts} +1 -1
  44. package/dist/{z-schema-versions.mjs → z-schema-versions.js} +21 -21
  45. package/dist/{z-schema.d.mts → z-schema.d.ts} +5 -13
  46. package/dist/{z-schema.mjs → z-schema.js} +37 -47
  47. package/package.json +22 -23
  48. package/src/errors.ts +1 -2
  49. package/src/format-validators.ts +139 -59
  50. package/src/json-schema-versions.ts +56 -2
  51. package/src/json-schema.ts +10 -9
  52. package/src/json-validation.ts +189 -146
  53. package/src/report.ts +37 -49
  54. package/src/schema-cache.ts +13 -13
  55. package/src/schema-compiler.ts +170 -117
  56. package/src/schema-validator.ts +239 -238
  57. package/src/utils/array.ts +9 -6
  58. package/src/utils/base64.ts +13 -2
  59. package/src/utils/clone.ts +28 -30
  60. package/src/utils/date.ts +6 -3
  61. package/src/utils/hostname.ts +27 -27
  62. package/src/utils/json.ts +16 -9
  63. package/src/utils/properties.ts +2 -2
  64. package/src/utils/schema-regex.ts +4 -4
  65. package/src/utils/time.ts +5 -5
  66. package/src/utils/unicode.ts +12 -5
  67. package/src/utils/what-is.ts +1 -5
  68. package/src/validation/array.ts +24 -22
  69. package/src/validation/combinators.ts +14 -14
  70. package/src/validation/numeric.ts +14 -28
  71. package/src/validation/object.ts +32 -36
  72. package/src/validation/ref.ts +5 -6
  73. package/src/validation/shared.ts +22 -21
  74. package/src/validation/string.ts +29 -39
  75. package/src/validation/type.ts +17 -17
  76. package/src/z-schema-base.ts +49 -38
  77. package/src/z-schema-options.ts +4 -3
  78. package/src/z-schema.ts +35 -45
  79. package/umd/ZSchema.js +711 -695
  80. package/umd/ZSchema.min.js +2 -2
  81. package/umd/package.json +3 -0
  82. package/dist/utils/unicode.mjs +0 -12
  83. package/dist/validation/type.mjs +0 -32
  84. /package/dist/{format-validators.d.mts → format-validators.d.ts} +0 -0
  85. /package/dist/{json-schema-versions.mjs → json-schema-versions.js} +0 -0
  86. /package/dist/schemas/{draft-04-schema.mjs → draft-04-schema.js} +0 -0
  87. /package/dist/schemas/{draft-06-schema.mjs → draft-06-schema.js} +0 -0
  88. /package/dist/schemas/{draft-07-schema.mjs → draft-07-schema.js} +0 -0
  89. /package/dist/schemas/{draft-2019-09-meta-applicator.mjs → draft-2019-09-meta-applicator.js} +0 -0
  90. /package/dist/schemas/{draft-2019-09-meta-content.mjs → draft-2019-09-meta-content.js} +0 -0
  91. /package/dist/schemas/{draft-2019-09-meta-core.mjs → draft-2019-09-meta-core.js} +0 -0
  92. /package/dist/schemas/{draft-2019-09-meta-format.mjs → draft-2019-09-meta-format.js} +0 -0
  93. /package/dist/schemas/{draft-2019-09-meta-meta-data.mjs → draft-2019-09-meta-meta-data.js} +0 -0
  94. /package/dist/schemas/{draft-2019-09-meta-validation.mjs → draft-2019-09-meta-validation.js} +0 -0
  95. /package/dist/schemas/{draft-2019-09-schema.mjs → draft-2019-09-schema.js} +0 -0
  96. /package/dist/schemas/{draft-2020-12-meta-applicator.mjs → draft-2020-12-meta-applicator.js} +0 -0
  97. /package/dist/schemas/{draft-2020-12-meta-content.mjs → draft-2020-12-meta-content.js} +0 -0
  98. /package/dist/schemas/{draft-2020-12-meta-core.mjs → draft-2020-12-meta-core.js} +0 -0
  99. /package/dist/schemas/{draft-2020-12-meta-format-annotation.mjs → draft-2020-12-meta-format-annotation.js} +0 -0
  100. /package/dist/schemas/{draft-2020-12-meta-format-assertion.mjs → draft-2020-12-meta-format-assertion.js} +0 -0
  101. /package/dist/schemas/{draft-2020-12-meta-meta-data.mjs → draft-2020-12-meta-meta-data.js} +0 -0
  102. /package/dist/schemas/{draft-2020-12-meta-unevaluated.mjs → draft-2020-12-meta-unevaluated.js} +0 -0
  103. /package/dist/schemas/{draft-2020-12-meta-validation.mjs → draft-2020-12-meta-validation.js} +0 -0
  104. /package/dist/schemas/{draft-2020-12-schema.mjs → draft-2020-12-schema.js} +0 -0
  105. /package/dist/utils/{constants.mjs → constants.js} +0 -0
  106. /package/dist/utils/{date.mjs → date.js} +0 -0
  107. /package/dist/utils/{properties.mjs → properties.js} +0 -0
  108. /package/dist/utils/{symbols.mjs → symbols.js} +0 -0
  109. /package/dist/utils/{uri.mjs → uri.js} +0 -0
  110. /package/dist/{z-schema-reader.mjs → z-schema-reader.js} +0 -0
@@ -8,11 +8,11 @@ import { cacheValidationResult, deferOrRunSync } from './shared.js';
8
8
  // allOf
9
9
  // ---------------------------------------------------------------------------
10
10
 
11
- export function allOfValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
11
+ export function allOfValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
12
12
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.3.2
13
13
  for (let i = 0; i < schema.allOf!.length; i++) {
14
- const validateResult = this._jsonValidate(report, schema.allOf![i], json);
15
- if (this.options.breakOnFirstError && validateResult === false) {
14
+ const validateResult = ctx._jsonValidate(report, schema.allOf![i], json);
15
+ if (ctx.options.breakOnFirstError && !validateResult) {
16
16
  break;
17
17
  }
18
18
  }
@@ -22,14 +22,14 @@ export function allOfValidator(this: ZSchemaBase, report: Report, schema: JsonSc
22
22
  // anyOf
23
23
  // ---------------------------------------------------------------------------
24
24
 
25
- export function anyOfValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
25
+ export function anyOfValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
26
26
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.4.2
27
27
  const subReports: Report[] = [];
28
28
 
29
29
  for (let i = 0; i < schema.anyOf!.length; i++) {
30
30
  const subReport = new Report(report);
31
31
  subReports.push(subReport);
32
- this._jsonValidate(subReport, schema.anyOf![i], json);
32
+ ctx._jsonValidate(subReport, schema.anyOf![i], json);
33
33
  cacheValidationResult(report, schema.anyOf![i], json, subReport.errors.length === 0);
34
34
  }
35
35
 
@@ -43,7 +43,7 @@ export function anyOfValidator(this: ZSchemaBase, report: Report, schema: JsonSc
43
43
  }
44
44
  }
45
45
 
46
- if (passed === false) {
46
+ if (!passed) {
47
47
  report.addError('ANY_OF_MISSING', undefined, subReports, schema, 'anyOf');
48
48
  }
49
49
  });
@@ -53,14 +53,14 @@ export function anyOfValidator(this: ZSchemaBase, report: Report, schema: JsonSc
53
53
  // oneOf
54
54
  // ---------------------------------------------------------------------------
55
55
 
56
- export function oneOfValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
56
+ export function oneOfValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
57
57
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.5.2
58
58
  const subReports: Report[] = [];
59
59
 
60
60
  for (let i = 0; i < schema.oneOf!.length; i++) {
61
61
  const subReport = new Report(report);
62
62
  subReports.push(subReport);
63
- this._jsonValidate(subReport, schema.oneOf![i], json);
63
+ ctx._jsonValidate(subReport, schema.oneOf![i], json);
64
64
  cacheValidationResult(report, schema.oneOf![i], json, subReport.errors.length === 0);
65
65
  }
66
66
 
@@ -85,10 +85,10 @@ export function oneOfValidator(this: ZSchemaBase, report: Report, schema: JsonSc
85
85
  // not
86
86
  // ---------------------------------------------------------------------------
87
87
 
88
- export function notValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
88
+ export function notValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
89
89
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.5.6.2
90
90
  const subReport = new Report(report);
91
- if (this._jsonValidate(subReport, schema.not!, json) === true) {
91
+ if (ctx._jsonValidate(subReport, schema.not!, json)) {
92
92
  report.addError('NOT_PASSED', undefined, undefined, schema, 'not');
93
93
  }
94
94
  }
@@ -97,8 +97,8 @@ export function notValidator(this: ZSchemaBase, report: Report, schema: JsonSche
97
97
  // if / then / else
98
98
  // ---------------------------------------------------------------------------
99
99
 
100
- export function ifValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
101
- if (this.options.version === 'draft-04' || this.options.version === 'draft-06') {
100
+ export function ifValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
101
+ if (ctx.options.version === 'draft-04' || ctx.options.version === 'draft-06') {
102
102
  return;
103
103
  }
104
104
 
@@ -111,7 +111,7 @@ export function ifValidator(this: ZSchemaBase, report: Report, schema: JsonSchem
111
111
  }
112
112
 
113
113
  const conditionReport = new Report(report);
114
- this._jsonValidate(conditionReport, conditionSchema as any, json);
114
+ ctx._jsonValidate(conditionReport, conditionSchema, json);
115
115
  cacheValidationResult(report, conditionSchema, json, conditionReport.errors.length === 0);
116
116
 
117
117
  const branchSchema = conditionReport.errors.length === 0 ? thenSchema : elseSchema;
@@ -119,7 +119,7 @@ export function ifValidator(this: ZSchemaBase, report: Report, schema: JsonSchem
119
119
  return;
120
120
  }
121
121
 
122
- this._jsonValidate(report, branchSchema as any, json);
122
+ ctx._jsonValidate(report, branchSchema, json);
123
123
  }
124
124
 
125
125
  export function thenValidator() {
@@ -8,9 +8,9 @@ import { shouldSkipValidate } from './shared.js';
8
8
  // multipleOf
9
9
  // ---------------------------------------------------------------------------
10
10
 
11
- export function multipleOfValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
11
+ export function multipleOfValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
12
12
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.1.2
13
- if (shouldSkipValidate(this.validateOptions, ['MULTIPLE_OF'])) {
13
+ if (shouldSkipValidate(ctx.validateOptions, ['MULTIPLE_OF'])) {
14
14
  return;
15
15
  }
16
16
  if (typeof json !== 'number') {
@@ -27,9 +27,9 @@ export function multipleOfValidator(this: ZSchemaBase, report: Report, schema: J
27
27
  // maximum
28
28
  // ---------------------------------------------------------------------------
29
29
 
30
- export function maximumValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
30
+ export function maximumValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
31
31
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.2.2
32
- if (shouldSkipValidate(this.validateOptions, ['MAXIMUM', 'MAXIMUM_EXCLUSIVE'])) {
32
+ if (shouldSkipValidate(ctx.validateOptions, ['MAXIMUM', 'MAXIMUM_EXCLUSIVE'])) {
33
33
  return;
34
34
  }
35
35
  if (typeof json !== 'number') {
@@ -39,10 +39,8 @@ export function maximumValidator(this: ZSchemaBase, report: Report, schema: Json
39
39
  if (json > schema.maximum!) {
40
40
  report.addError('MAXIMUM', [json, schema.maximum!], undefined, schema, 'maximum');
41
41
  }
42
- } else {
43
- if (json >= schema.maximum!) {
44
- report.addError('MAXIMUM_EXCLUSIVE', [json, schema.maximum!], undefined, schema, 'maximum');
45
- }
42
+ } else if (json >= schema.maximum!) {
43
+ report.addError('MAXIMUM_EXCLUSIVE', [json, schema.maximum!], undefined, schema, 'maximum');
46
44
  }
47
45
  }
48
46
 
@@ -50,15 +48,10 @@ export function maximumValidator(this: ZSchemaBase, report: Report, schema: Json
50
48
  // exclusiveMaximum
51
49
  // ---------------------------------------------------------------------------
52
50
 
53
- export function exclusiveMaximumValidator(
54
- this: ZSchemaBase,
55
- report: Report,
56
- schema: JsonSchemaInternal,
57
- json: unknown
58
- ) {
51
+ export function exclusiveMaximumValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
59
52
  // In draft-06+, exclusiveMaximum is a standalone number
60
53
  if (typeof schema.exclusiveMaximum === 'number') {
61
- if (shouldSkipValidate(this.validateOptions, ['MAXIMUM_EXCLUSIVE'])) {
54
+ if (shouldSkipValidate(ctx.validateOptions, ['MAXIMUM_EXCLUSIVE'])) {
62
55
  return;
63
56
  }
64
57
  if (typeof json !== 'number') {
@@ -75,9 +68,9 @@ export function exclusiveMaximumValidator(
75
68
  // minimum
76
69
  // ---------------------------------------------------------------------------
77
70
 
78
- export function minimumValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
71
+ export function minimumValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
79
72
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.1.3.2
80
- if (shouldSkipValidate(this.validateOptions, ['MINIMUM', 'MINIMUM_EXCLUSIVE'])) {
73
+ if (shouldSkipValidate(ctx.validateOptions, ['MINIMUM', 'MINIMUM_EXCLUSIVE'])) {
81
74
  return;
82
75
  }
83
76
  if (typeof json !== 'number') {
@@ -87,10 +80,8 @@ export function minimumValidator(this: ZSchemaBase, report: Report, schema: Json
87
80
  if (json < schema.minimum!) {
88
81
  report.addError('MINIMUM', [json, schema.minimum!], undefined, schema, 'minimum');
89
82
  }
90
- } else {
91
- if (json <= schema.minimum!) {
92
- report.addError('MINIMUM_EXCLUSIVE', [json, schema.minimum!], undefined, schema, 'minimum');
93
- }
83
+ } else if (json <= schema.minimum!) {
84
+ report.addError('MINIMUM_EXCLUSIVE', [json, schema.minimum!], undefined, schema, 'minimum');
94
85
  }
95
86
  }
96
87
 
@@ -98,15 +89,10 @@ export function minimumValidator(this: ZSchemaBase, report: Report, schema: Json
98
89
  // exclusiveMinimum
99
90
  // ---------------------------------------------------------------------------
100
91
 
101
- export function exclusiveMinimumValidator(
102
- this: ZSchemaBase,
103
- report: Report,
104
- schema: JsonSchemaInternal,
105
- json: unknown
106
- ) {
92
+ export function exclusiveMinimumValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
107
93
  // In draft-06+, exclusiveMinimum is a standalone number
108
94
  if (typeof schema.exclusiveMinimum === 'number') {
109
- if (shouldSkipValidate(this.validateOptions, ['MINIMUM_EXCLUSIVE'])) {
95
+ if (shouldSkipValidate(ctx.validateOptions, ['MINIMUM_EXCLUSIVE'])) {
110
96
  return;
111
97
  }
112
98
  if (typeof json !== 'number') {
@@ -11,9 +11,9 @@ import { deferOrRunSync, shouldSkipValidate, supportsDependentKeywords } from '.
11
11
  // maxProperties
12
12
  // ---------------------------------------------------------------------------
13
13
 
14
- export function maxPropertiesValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
14
+ export function maxPropertiesValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
15
15
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.1.2
16
- if (shouldSkipValidate(this.validateOptions, ['OBJECT_PROPERTIES_MAXIMUM'])) {
16
+ if (shouldSkipValidate(ctx.validateOptions, ['OBJECT_PROPERTIES_MAXIMUM'])) {
17
17
  return;
18
18
  }
19
19
  if (!isObject(json)) {
@@ -35,9 +35,9 @@ export function maxPropertiesValidator(this: ZSchemaBase, report: Report, schema
35
35
  // minProperties
36
36
  // ---------------------------------------------------------------------------
37
37
 
38
- export function minPropertiesValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
38
+ export function minPropertiesValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
39
39
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.2.2
40
- if (shouldSkipValidate(this.validateOptions, ['OBJECT_PROPERTIES_MINIMUM'])) {
40
+ if (shouldSkipValidate(ctx.validateOptions, ['OBJECT_PROPERTIES_MINIMUM'])) {
41
41
  return;
42
42
  }
43
43
  if (!isObject(json)) {
@@ -59,9 +59,9 @@ export function minPropertiesValidator(this: ZSchemaBase, report: Report, schema
59
59
  // required
60
60
  // ---------------------------------------------------------------------------
61
61
 
62
- export function requiredValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
62
+ export function requiredValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
63
63
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.3.2
64
- if (shouldSkipValidate(this.validateOptions, ['OBJECT_MISSING_REQUIRED_PROPERTY'])) {
64
+ if (shouldSkipValidate(ctx.validateOptions, ['OBJECT_MISSING_REQUIRED_PROPERTY'])) {
65
65
  return;
66
66
  }
67
67
  if (!isObject(json)) {
@@ -81,14 +81,14 @@ export function requiredValidator(this: ZSchemaBase, report: Report, schema: Jso
81
81
  // ---------------------------------------------------------------------------
82
82
 
83
83
  export function additionalPropertiesValidator(
84
- this: ZSchemaBase,
84
+ ctx: ZSchemaBase,
85
85
  report: Report,
86
86
  schema: JsonSchemaInternal,
87
87
  json: unknown
88
88
  ) {
89
89
  // covered in properties and patternProperties
90
90
  if (schema.properties === undefined && schema.patternProperties === undefined) {
91
- return propertiesValidator.call(this, report, schema, json);
91
+ propertiesValidator(ctx, report, schema, json);
92
92
  }
93
93
  }
94
94
 
@@ -97,14 +97,14 @@ export function additionalPropertiesValidator(
97
97
  // ---------------------------------------------------------------------------
98
98
 
99
99
  export function patternPropertiesValidator(
100
- this: ZSchemaBase,
100
+ ctx: ZSchemaBase,
101
101
  report: Report,
102
102
  schema: JsonSchemaInternal,
103
103
  json: unknown
104
104
  ) {
105
105
  // covered in properties
106
106
  if (schema.properties === undefined) {
107
- return propertiesValidator.call(this, report, schema, json);
107
+ propertiesValidator(ctx, report, schema, json);
108
108
  }
109
109
  }
110
110
 
@@ -112,16 +112,16 @@ export function patternPropertiesValidator(
112
112
  // properties
113
113
  // ---------------------------------------------------------------------------
114
114
 
115
- export function propertiesValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
115
+ export function propertiesValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
116
116
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.4.2
117
- if (shouldSkipValidate(this.validateOptions, ['OBJECT_ADDITIONAL_PROPERTIES'])) {
117
+ if (shouldSkipValidate(ctx.validateOptions, ['OBJECT_ADDITIONAL_PROPERTIES'])) {
118
118
  return;
119
119
  }
120
120
  if (!isObject(json)) {
121
121
  return;
122
122
  }
123
- const properties = schema.properties !== undefined ? schema.properties : {};
124
- const patternProperties = schema.patternProperties !== undefined ? schema.patternProperties : {};
123
+ const properties = schema.properties === undefined ? {} : schema.properties;
124
+ const patternProperties = schema.patternProperties === undefined ? {} : schema.patternProperties;
125
125
  if (schema.additionalProperties === false) {
126
126
  // The property set of the json to validate.
127
127
  let s = Object.keys(json);
@@ -132,14 +132,15 @@ export function propertiesValidator(this: ZSchemaBase, report: Report, schema: J
132
132
  // remove from "s" all elements of "p", if any;
133
133
  s = difference(s, p);
134
134
  // for each regex in "pp", remove all elements of "s" which this regex matches.
135
- for (const ppKey of pp) {
135
+ for (let i = 0; i < pp.length; i++) {
136
+ const ppKey = pp[i];
136
137
  const result = compileSchemaRegex(ppKey);
137
138
  if (!result.ok) {
138
139
  continue;
139
140
  }
140
141
  const regExp = result.value;
141
142
  for (let idx2 = s.length - 1; idx2 >= 0; idx2--) {
142
- if (regExp.test(s[idx2]) === true) {
143
+ if (regExp.test(s[idx2])) {
143
144
  s.splice(idx2, 1);
144
145
  }
145
146
  }
@@ -147,8 +148,8 @@ export function propertiesValidator(this: ZSchemaBase, report: Report, schema: J
147
148
  // Validation of the json succeeds if, after these two steps, set "s" is empty.
148
149
  if (s.length > 0) {
149
150
  // assumeAdditional can be an array of allowed properties
150
- if (Array.isArray(this.options.assumeAdditional)) {
151
- for (const allowed of this.options.assumeAdditional) {
151
+ if (Array.isArray(ctx.options.assumeAdditional)) {
152
+ for (const allowed of ctx.options.assumeAdditional) {
152
153
  const io = s.indexOf(allowed);
153
154
  if (io !== -1) {
154
155
  s.splice(io, 1);
@@ -168,9 +169,9 @@ export function propertiesValidator(this: ZSchemaBase, report: Report, schema: J
168
169
  // dependencies
169
170
  // ---------------------------------------------------------------------------
170
171
 
171
- export function dependenciesValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
172
+ export function dependenciesValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
172
173
  // http://json-schema.org/latest/json-schema-validation.html#rfc.section.5.4.5.2
173
- if (shouldSkipValidate(this.validateOptions, ['OBJECT_DEPENDENCY_KEY'])) {
174
+ if (shouldSkipValidate(ctx.validateOptions, ['OBJECT_DEPENDENCY_KEY'])) {
174
175
  return;
175
176
  }
176
177
  if (!isObject(json)) {
@@ -199,7 +200,7 @@ export function dependenciesValidator(this: ZSchemaBase, report: Report, schema:
199
200
  }
200
201
  } else {
201
202
  // if dependency is a schema, validate against this schema
202
- this._jsonValidate(report, dependencyDefinition, json);
203
+ ctx._jsonValidate(report, dependencyDefinition, json);
203
204
  }
204
205
  }
205
206
  }
@@ -209,13 +210,8 @@ export function dependenciesValidator(this: ZSchemaBase, report: Report, schema:
209
210
  // dependentSchemas
210
211
  // ---------------------------------------------------------------------------
211
212
 
212
- export function dependentSchemasValidator(
213
- this: ZSchemaBase,
214
- report: Report,
215
- schema: JsonSchemaInternal,
216
- json: unknown
217
- ) {
218
- if (!supportsDependentKeywords(schema, this.options.version)) {
213
+ export function dependentSchemasValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
214
+ if (!supportsDependentKeywords(schema, ctx.options.version)) {
219
215
  return;
220
216
  }
221
217
  if (!isObject(json) || !isObject(schema.dependentSchemas)) {
@@ -227,7 +223,7 @@ export function dependentSchemasValidator(
227
223
  for (const dependencyName of keys) {
228
224
  if (Object.hasOwn(json, dependencyName)) {
229
225
  const dependencySchema = schema.dependentSchemas[dependencyName];
230
- this._jsonValidate(report, dependencySchema, json);
226
+ ctx._jsonValidate(report, dependencySchema, json);
231
227
  }
232
228
  }
233
229
  }
@@ -237,15 +233,15 @@ export function dependentSchemasValidator(
237
233
  // ---------------------------------------------------------------------------
238
234
 
239
235
  export function dependentRequiredValidator(
240
- this: ZSchemaBase,
236
+ ctx: ZSchemaBase,
241
237
  report: Report,
242
238
  schema: JsonSchemaInternal,
243
239
  json: unknown
244
240
  ) {
245
- if (!supportsDependentKeywords(schema, this.options.version)) {
241
+ if (!supportsDependentKeywords(schema, ctx.options.version)) {
246
242
  return;
247
243
  }
248
- if (shouldSkipValidate(this.validateOptions, ['OBJECT_DEPENDENCY_KEY'])) {
244
+ if (shouldSkipValidate(ctx.validateOptions, ['OBJECT_DEPENDENCY_KEY'])) {
249
245
  return;
250
246
  }
251
247
  if (!isObject(json) || !isObject(schema.dependentRequired)) {
@@ -282,8 +278,8 @@ export function dependentRequiredValidator(
282
278
  // propertyNames
283
279
  // ---------------------------------------------------------------------------
284
280
 
285
- export function propertyNamesValidator(this: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
286
- if (shouldSkipValidate(this.validateOptions, ['PROPERTY_NAMES'])) {
281
+ export function propertyNamesValidator(ctx: ZSchemaBase, report: Report, schema: JsonSchemaInternal, json: unknown) {
282
+ if (shouldSkipValidate(ctx.validateOptions, ['PROPERTY_NAMES'])) {
287
283
  return;
288
284
  }
289
285
 
@@ -302,13 +298,13 @@ export function propertyNamesValidator(this: ZSchemaBase, report: Report, schema
302
298
  for (const key of keys) {
303
299
  const subReport = new Report_(report);
304
300
  subReports.push(subReport);
305
- this._jsonValidate(subReport, propertyNamesSchema as any, key);
301
+ ctx._jsonValidate(subReport, propertyNamesSchema, key);
306
302
  }
307
303
 
308
304
  const addPropertyNameErrors = () => {
309
305
  for (let idx = 0; idx < keys.length; idx++) {
310
306
  if (subReports[idx].errors.length > 0) {
311
- report.addError('PROPERTY_NAMES', [keys[idx]], subReports[idx], schema, undefined);
307
+ report.addError('PROPERTY_NAMES', [keys[idx]], subReports[idx], schema);
312
308
  }
313
309
  }
314
310
  };
@@ -10,11 +10,11 @@ import { getRemotePath } from '../utils/uri.js';
10
10
  export const getDynamicRefAnchorName = (dynamicRef: string) => {
11
11
  const hashIdx = dynamicRef.indexOf('#');
12
12
  if (hashIdx === -1) {
13
- return undefined;
13
+ return;
14
14
  }
15
15
  const fragment = dynamicRef.slice(hashIdx + 1);
16
- if (!fragment || fragment[0] === '/') {
17
- return undefined;
16
+ if (!fragment || fragment.startsWith('/')) {
17
+ return;
18
18
  }
19
19
  return fragment;
20
20
  };
@@ -26,7 +26,6 @@ export const findDynamicAnchorInScope = (scopeSchema: JsonSchemaInternal, anchor
26
26
  if (found && found.$dynamicAnchor === anchorName) {
27
27
  return found;
28
28
  }
29
- return undefined;
30
29
  };
31
30
 
32
31
  // ---------------------------------------------------------------------------
@@ -40,7 +39,7 @@ export const resolveRecursiveRef = (
40
39
  schema: JsonSchemaInternal,
41
40
  recursiveAnchorStack: JsonSchemaInternal[]
42
41
  ): JsonSchemaInternal | undefined => {
43
- const resolved = schema.__$recursiveRefResolved as JsonSchemaInternal | undefined;
42
+ const resolved = schema.__$recursiveRefResolved;
44
43
  if (!resolved) {
45
44
  return undefined;
46
45
  }
@@ -66,7 +65,7 @@ export const resolveDynamicRef = (
66
65
  dynamicScopeStack: JsonSchemaInternal[]
67
66
  ): JsonSchemaInternal | boolean | undefined => {
68
67
  const resolved = schema.__$dynamicRefResolved as JsonSchemaInternal | boolean | undefined;
69
- if (typeof resolved === 'undefined' || !schema.$dynamicRef) {
68
+ if (resolved === undefined || !schema.$dynamicRef) {
70
69
  return resolved;
71
70
  }
72
71
  let target = resolved;
@@ -1,3 +1,4 @@
1
+ import type { ErrorCode } from '../errors.js';
1
2
  import type { JsonSchema, JsonSchemaAll, JsonSchemaInternal, JsonSchemaVersion } from '../json-schema-versions.js';
2
3
  // JsonSchemaAll is retained for the VALIDATION_VOCAB_KEYWORDS Set key type.
3
4
  import type { Report } from '../report.js';
@@ -9,22 +10,17 @@ import { isObject } from '../utils/what-is.js';
9
10
  // Shared types
10
11
  // ---------------------------------------------------------------------------
11
12
 
12
- export type JsonValidatorFn = (this: ZSchemaBase, report: Report, schema: JsonSchema, json: unknown) => void;
13
+ export type JsonValidatorFn = (ctx: ZSchemaBase, report: Report, schema: JsonSchema, json: unknown) => void;
13
14
 
14
15
  // ---------------------------------------------------------------------------
15
16
  // Draft / vocabulary helpers
16
17
  // ---------------------------------------------------------------------------
17
18
 
18
- export const shouldSkipValidate = function (options: ValidateOptions, errors: any) {
19
- return (
20
- options &&
21
- Array.isArray(options.includeErrors) &&
22
- options.includeErrors.length > 0 &&
23
- !errors.some(function (err: any) {
24
- return options.includeErrors!.includes(err);
25
- })
26
- );
27
- };
19
+ export const shouldSkipValidate = (options: ValidateOptions, errors: readonly ErrorCode[]) =>
20
+ options &&
21
+ Array.isArray(options.includeErrors) &&
22
+ options.includeErrors.length > 0 &&
23
+ !errors.some((err) => options.includeErrors!.includes(err));
28
24
 
29
25
  export const supportsDependentKeywords = (
30
26
  schema: JsonSchemaInternal,
@@ -89,12 +85,12 @@ export const isValidationVocabularyEnabled = (
89
85
  return true;
90
86
  }
91
87
 
92
- const vocabulary = metaSchema.$vocabulary as Record<string, boolean>;
88
+ const vocabulary = metaSchema.$vocabulary;
93
89
  const has2019 = Object.hasOwn(vocabulary, VOCAB_VALIDATION_2019_09);
94
90
  const has2020 = Object.hasOwn(vocabulary, VOCAB_VALIDATION_2020_12);
95
91
 
96
92
  if (has2019 || has2020) {
97
- return vocabulary[VOCAB_VALIDATION_2019_09] === true || vocabulary[VOCAB_VALIDATION_2020_12] === true;
93
+ return vocabulary[VOCAB_VALIDATION_2019_09] || vocabulary[VOCAB_VALIDATION_2020_12];
98
94
  }
99
95
 
100
96
  return false;
@@ -124,16 +120,16 @@ export const isFormatAssertionVocabEnabled = (
124
120
  return false; // no vocabulary info, default to annotation-only for modern drafts
125
121
  }
126
122
 
127
- const vocabulary = metaSchema.$vocabulary as Record<string, boolean>;
123
+ const vocabulary = metaSchema.$vocabulary;
128
124
 
129
125
  // For draft 2020-12, only the format-assertion vocabulary enables format as assertion
130
126
  if (Object.hasOwn(vocabulary, VOCAB_FORMAT_ASSERTION_2020_12)) {
131
- return vocabulary[VOCAB_FORMAT_ASSERTION_2020_12] === true;
127
+ return vocabulary[VOCAB_FORMAT_ASSERTION_2020_12];
132
128
  }
133
129
 
134
130
  // For draft 2019-09, check if the format vocabulary is enabled (true)
135
131
  if (Object.hasOwn(vocabulary, VOCAB_FORMAT_2019_09)) {
136
- return vocabulary[VOCAB_FORMAT_2019_09] === true;
132
+ return vocabulary[VOCAB_FORMAT_2019_09];
137
133
  }
138
134
 
139
135
  return false; // default to annotation-only for modern drafts
@@ -170,17 +166,22 @@ export function getCachedValidationResult(report: Report, schema: unknown, json:
170
166
  */
171
167
  export function deferOrRunSync(report: Report, subReports: Report[], decisionFn: () => void): void {
172
168
  const asyncTasksBefore = report.asyncTasks.length;
173
- for (const subReport of subReports) {
174
- report.asyncTasks.push(...subReport.asyncTasks);
169
+ for (let i = 0; i < subReports.length; i++) {
170
+ const tasks = subReports[i].asyncTasks;
171
+ for (let j = 0; j < tasks.length; j++) {
172
+ report.asyncTasks.push(tasks[j]);
173
+ }
175
174
  }
176
175
  const hasAsyncTasks = report.asyncTasks.length > asyncTasksBefore;
177
176
 
178
177
  if (hasAsyncTasks) {
179
178
  report.addAsyncTaskWithPath(
180
- (callback) => {
181
- setTimeout(() => callback(null), 0);
179
+ (callback: (result: unknown) => void) => {
180
+ setTimeout(() => {
181
+ callback(null);
182
+ }, 0);
182
183
  },
183
- [] as any,
184
+ [],
184
185
  () => {
185
186
  decisionFn();
186
187
  }