justus 0.5.3 → 0.5.4

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 (70) hide show
  1. package/dist/dts-generator.cjs +21 -3
  2. package/dist/dts-generator.cjs.map +1 -1
  3. package/dist/dts-generator.mjs +21 -3
  4. package/dist/dts-generator.mjs.map +1 -1
  5. package/dist/extra/arn.cjs +1 -1
  6. package/dist/extra/arn.cjs.map +1 -1
  7. package/dist/extra/arn.mjs +1 -1
  8. package/dist/extra/arn.mjs.map +1 -1
  9. package/dist/index.cjs +13 -2
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +12 -0
  12. package/dist/index.mjs +9 -2
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/types.cjs +0 -7
  15. package/dist/types.cjs.map +1 -1
  16. package/dist/types.d.ts +7 -9
  17. package/dist/types.mjs +0 -6
  18. package/dist/types.mjs.map +1 -1
  19. package/dist/utilities.cjs +1 -0
  20. package/dist/utilities.cjs.map +1 -1
  21. package/dist/utilities.mjs +1 -0
  22. package/dist/utilities.mjs.map +1 -1
  23. package/dist/validators/bigint.cjs +146 -0
  24. package/dist/validators/bigint.cjs.map +6 -0
  25. package/dist/validators/bigint.d.ts +46 -0
  26. package/dist/validators/bigint.mjs +118 -0
  27. package/dist/validators/bigint.mjs.map +6 -0
  28. package/dist/validators/boolean.cjs +1 -1
  29. package/dist/validators/boolean.cjs.map +1 -1
  30. package/dist/validators/boolean.mjs +1 -1
  31. package/dist/validators/boolean.mjs.map +1 -1
  32. package/dist/validators/constant.cjs +2 -1
  33. package/dist/validators/constant.cjs.map +1 -1
  34. package/dist/validators/constant.d.ts +2 -2
  35. package/dist/validators/constant.mjs +2 -1
  36. package/dist/validators/constant.mjs.map +1 -1
  37. package/dist/validators/never.cjs +1 -1
  38. package/dist/validators/never.cjs.map +1 -1
  39. package/dist/validators/never.mjs +2 -2
  40. package/dist/validators/never.mjs.map +1 -1
  41. package/dist/validators/number.cjs +5 -5
  42. package/dist/validators/number.cjs.map +1 -1
  43. package/dist/validators/number.mjs +5 -5
  44. package/dist/validators/number.mjs.map +1 -1
  45. package/dist/validators/object.cjs +7 -5
  46. package/dist/validators/object.cjs.map +1 -1
  47. package/dist/validators/object.mjs +8 -6
  48. package/dist/validators/object.mjs.map +1 -1
  49. package/dist/validators/optional.cjs +1 -1
  50. package/dist/validators/optional.cjs.map +1 -1
  51. package/dist/validators/optional.mjs +2 -2
  52. package/dist/validators/optional.mjs.map +1 -1
  53. package/dist/validators/string.cjs +2 -2
  54. package/dist/validators/string.cjs.map +1 -1
  55. package/dist/validators/string.mjs +2 -2
  56. package/dist/validators/string.mjs.map +1 -1
  57. package/package.json +3 -5
  58. package/src/dts-generator.ts +22 -3
  59. package/src/extra/arn.ts +1 -1
  60. package/src/index.ts +20 -2
  61. package/src/types.ts +7 -12
  62. package/src/utilities.ts +1 -0
  63. package/src/validators/bigint.ts +147 -0
  64. package/src/validators/boolean.ts +1 -1
  65. package/src/validators/constant.ts +4 -3
  66. package/src/validators/never.ts +2 -2
  67. package/src/validators/number.ts +5 -5
  68. package/src/validators/object.ts +8 -7
  69. package/src/validators/optional.ts +2 -2
  70. package/src/validators/string.ts +2 -2
@@ -1,5 +1,5 @@
1
1
  import { ValidationError } from '../errors'
2
- import { AbstractValidator, defaultValidationOptions } from '../types'
2
+ import { AbstractValidator } from '../types'
3
3
 
4
4
  import type { ValidationOptions } from '../types'
5
5
 
@@ -7,7 +7,7 @@ import type { ValidationOptions } from '../types'
7
7
  export class NeverValidator extends AbstractValidator<never> {
8
8
  optional: true = true
9
9
 
10
- validate(value: unknown, options: ValidationOptions = defaultValidationOptions): never {
10
+ validate(value: unknown, options: ValidationOptions = {}): never {
11
11
  const { stripForbiddenProperties } = options
12
12
 
13
13
  // @ts-expect-error
@@ -46,7 +46,7 @@ export interface BrandedNumberConstraints<B extends string> extends NumberConstr
46
46
  /** A `Validator` validating any `number`. */
47
47
  export class AnyNumberValidator extends AbstractValidator<number> {
48
48
  validate(value: unknown): number {
49
- assertValidation(typeof value == 'number', 'Value is not a "number"')
49
+ assertValidation(typeof value === 'number', 'Value is not a "number"')
50
50
  assertValidation(! isNaN(value), 'Number is "NaN"')
51
51
  return value
52
52
  }
@@ -131,13 +131,13 @@ export class NumberValidator<N extends number = number> extends AbstractValidato
131
131
 
132
132
  validate(value: unknown): N {
133
133
  // Allow parsing from strings
134
- if ((typeof value == 'string') && (this.fromString)) {
134
+ if ((typeof value === 'string') && (this.fromString)) {
135
135
  const parsed = +`${value}`
136
136
  assertValidation(! isNaN(parsed), 'Number can not be parsed from string')
137
137
  value = parsed
138
138
  }
139
139
 
140
- assertValidation(typeof value == 'number', 'Value is not a "number"')
140
+ assertValidation(typeof value === 'number', 'Value is not a "number"')
141
141
 
142
142
  if (isNaN(value)) {
143
143
  assertValidation(this.allowNaN, 'Number is "NaN"')
@@ -147,10 +147,10 @@ export class NumberValidator<N extends number = number> extends AbstractValidato
147
147
  assertValidation(value >= this.minimum, `Number is less than ${this.minimum}`)
148
148
  assertValidation(value <= this.maximum, `Number is greater than ${this.maximum}`)
149
149
 
150
- assertValidation((this.exclusiveMinimum == undefined) || (value > this.exclusiveMinimum),
150
+ assertValidation((this.exclusiveMinimum === undefined) || (value > this.exclusiveMinimum),
151
151
  `Number is less than or equal to ${this.exclusiveMinimum}`)
152
152
 
153
- assertValidation((this.exclusiveMaximum == undefined) || (value < this.exclusiveMaximum),
153
+ assertValidation((this.exclusiveMaximum === undefined) || (value < this.exclusiveMaximum),
154
154
  `Number is greater than or equal to ${this.exclusiveMaximum}`)
155
155
 
156
156
  assertValidation(this.#isMultipleOf ? this.#isMultipleOf(value) : true,
@@ -1,6 +1,6 @@
1
1
  import { assertValidation, ValidationErrorBuilder } from '../errors'
2
2
  import { registry } from '../registry'
3
- import { AbstractValidator, defaultValidationOptions, makeValidatorFactory } from '../types'
3
+ import { AbstractValidator, makeValidatorFactory } from '../types'
4
4
  import { getValidator } from '../utilities'
5
5
 
6
6
  import type {
@@ -17,7 +17,7 @@ import type {
17
17
  /** A `Validator` validating any `object`. */
18
18
  export class AnyObjectValidator extends AbstractValidator<Record<string, any>> {
19
19
  validate(value: unknown): Record<string, any> {
20
- assertValidation(typeof value == 'object', 'Value is not an "object"')
20
+ assertValidation(typeof value === 'object', 'Value is not an "object"')
21
21
  assertValidation(value !== null, 'Value is "null"')
22
22
  return value
23
23
  }
@@ -43,11 +43,11 @@ export class ObjectValidator<S extends Schema> extends AbstractValidator<InferSc
43
43
  this.schema = schema
44
44
  }
45
45
 
46
- validate(value: unknown, options: ValidationOptions = defaultValidationOptions): InferSchema<S> {
46
+ validate(value: unknown, options: ValidationOptions = {}): InferSchema<S> {
47
47
  assertValidation(typeof value === 'object', 'Value is not an "object"')
48
48
  assertValidation(value !== null, 'Value is "null"')
49
49
 
50
- const { stripAdditionalProperties, stripOptionalNulls } = options
50
+ const { stripAdditionalProperties, stripOptionalNulls, partialValidation } = options
51
51
 
52
52
  const record: { [ k in string | number | symbol ]?: unknown } = value
53
53
  const builder = new ValidationErrorBuilder()
@@ -63,19 +63,20 @@ export class ObjectValidator<S extends Schema> extends AbstractValidator<InferSc
63
63
  }
64
64
 
65
65
  // if we have no value, then we have few possibilities:
66
+ // - we are performing a partial validation, so we ignore
66
67
  // - the (optional) validator provides a valid value
67
68
  // - the validator is optional, so we can simply ignore
68
69
  // - the validator is not optional, so the property is missing
69
70
  if (original === undefined) {
71
+ if (partialValidation) continue
70
72
  try {
71
73
  // try to validate, the validator _might_ be giving us a value
72
74
  const validated = validator.validate(original, options)
73
75
  // put the validated value in the clone, unless optional and undefined
74
- if (! (optional && (validated == undefined))) clone[key] = validated
76
+ if (! (optional && (validated === undefined))) clone[key] = validated
75
77
  } catch (error) {
76
78
  if (optional) continue // original was undefined, so we can skip!
77
79
  builder.record('Required property missing', key)
78
- // builder.record(error, key) // double error!
79
80
  }
80
81
 
81
82
  continue
@@ -85,7 +86,7 @@ export class ObjectValidator<S extends Schema> extends AbstractValidator<InferSc
85
86
  try {
86
87
  const validated = validator.validate(original, options)
87
88
  // put the validated value in the clone, unless optional and undefined
88
- if (! (optional && (validated == undefined))) clone[key] = validated
89
+ if (! (optional && (validated === undefined))) clone[key] = validated
89
90
  } catch (error) {
90
91
  builder.record(error, key)
91
92
  }
@@ -1,4 +1,4 @@
1
- import { AbstractValidator, defaultValidationOptions } from '../types'
1
+ import { AbstractValidator } from '../types'
2
2
  import { getValidator } from '../utilities'
3
3
 
4
4
  import type { InferInput, InferValidation, Validation, ValidationOptions, Validator } from '../types'
@@ -27,7 +27,7 @@ export class OptionalValidator<
27
27
  }
28
28
 
29
29
  try {
30
- this.defaultValue = validator.validate(defaultValue, defaultValidationOptions)
30
+ this.defaultValue = validator.validate(defaultValue, {})
31
31
  } catch (cause) {
32
32
  throw new TypeError('Default value does not match validator', { cause })
33
33
  }
@@ -22,7 +22,7 @@ export interface BrandedStringConstraints<B extends string> extends StringConstr
22
22
  /** A `Validator` validating any `string`. */
23
23
  export class AnyStringValidator extends AbstractValidator<string> {
24
24
  validate(value: unknown): string {
25
- assertValidation(typeof value == 'string', 'Value is not a "string"')
25
+ assertValidation(typeof value === 'string', 'Value is not a "string"')
26
26
  return value
27
27
  }
28
28
  }
@@ -55,7 +55,7 @@ export class StringValidator<S extends string = string, I = string> extends Abst
55
55
  }
56
56
 
57
57
  validate(value: unknown): S {
58
- assertValidation(typeof value == 'string', 'Value is not a "string"')
58
+ assertValidation(typeof value === 'string', 'Value is not a "string"')
59
59
 
60
60
  assertValidation(value.length >= this.minLength,
61
61
  `String must have a minimum length of ${this.minLength}`)