@kravc/schema 2.8.0-alpha.6 → 2.8.0-alpha.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.
Files changed (118) hide show
  1. package/dist/CredentialFactory.d.ts +5 -318
  2. package/dist/CredentialFactory.d.ts.map +1 -1
  3. package/dist/CredentialFactory.js +5 -317
  4. package/dist/CredentialFactory.js.map +1 -1
  5. package/dist/Schema.d.ts +15 -420
  6. package/dist/Schema.d.ts.map +1 -1
  7. package/dist/Schema.js +13 -384
  8. package/dist/Schema.js.map +1 -1
  9. package/dist/ValidationError.d.ts +3 -49
  10. package/dist/ValidationError.d.ts.map +1 -1
  11. package/dist/ValidationError.js +3 -48
  12. package/dist/ValidationError.js.map +1 -1
  13. package/dist/Validator.d.ts +6 -470
  14. package/dist/Validator.d.ts.map +1 -1
  15. package/dist/Validator.js +50 -478
  16. package/dist/Validator.js.map +1 -1
  17. package/dist/helpers/cleanupAttributes.d.ts +3 -32
  18. package/dist/helpers/cleanupAttributes.d.ts.map +1 -1
  19. package/dist/helpers/cleanupAttributes.js +1 -30
  20. package/dist/helpers/cleanupAttributes.js.map +1 -1
  21. package/dist/helpers/cleanupNulls.d.ts +1 -25
  22. package/dist/helpers/cleanupNulls.d.ts.map +1 -1
  23. package/dist/helpers/cleanupNulls.js +2 -61
  24. package/dist/helpers/cleanupNulls.js.map +1 -1
  25. package/dist/helpers/createSchemasMap.d.ts +2 -93
  26. package/dist/helpers/createSchemasMap.d.ts.map +1 -1
  27. package/dist/helpers/createSchemasMap.js +4 -162
  28. package/dist/helpers/createSchemasMap.js.map +1 -1
  29. package/dist/helpers/getReferenceIds.d.ts +1 -165
  30. package/dist/helpers/getReferenceIds.d.ts.map +1 -1
  31. package/dist/helpers/getReferenceIds.js +2 -166
  32. package/dist/helpers/getReferenceIds.js.map +1 -1
  33. package/dist/helpers/got.d.ts +2 -58
  34. package/dist/helpers/got.d.ts.map +1 -1
  35. package/dist/helpers/got.js +1 -57
  36. package/dist/helpers/got.js.map +1 -1
  37. package/dist/helpers/mapObjectProperties.d.ts +2 -144
  38. package/dist/helpers/mapObjectProperties.d.ts.map +1 -1
  39. package/dist/helpers/mapObjectProperties.js +1 -142
  40. package/dist/helpers/mapObjectProperties.js.map +1 -1
  41. package/dist/helpers/normalizeAttributes.d.ts +3 -211
  42. package/dist/helpers/normalizeAttributes.d.ts.map +1 -1
  43. package/dist/helpers/normalizeAttributes.js +1 -209
  44. package/dist/helpers/normalizeAttributes.js.map +1 -1
  45. package/dist/helpers/normalizeProperties.d.ts +1 -165
  46. package/dist/helpers/normalizeProperties.d.ts.map +1 -1
  47. package/dist/helpers/normalizeProperties.js +1 -164
  48. package/dist/helpers/normalizeProperties.js.map +1 -1
  49. package/dist/helpers/normalizeRequired.d.ts +1 -153
  50. package/dist/helpers/normalizeRequired.d.ts.map +1 -1
  51. package/dist/helpers/normalizeRequired.js +0 -151
  52. package/dist/helpers/normalizeRequired.js.map +1 -1
  53. package/dist/helpers/normalizeType.d.ts +1 -77
  54. package/dist/helpers/normalizeType.d.ts.map +1 -1
  55. package/dist/helpers/normalizeType.js +11 -139
  56. package/dist/helpers/normalizeType.js.map +1 -1
  57. package/dist/helpers/nullifyEmptyValues.d.ts +1 -135
  58. package/dist/helpers/nullifyEmptyValues.d.ts.map +1 -1
  59. package/dist/helpers/nullifyEmptyValues.js +13 -143
  60. package/dist/helpers/nullifyEmptyValues.js.map +1 -1
  61. package/dist/helpers/removeRequiredAndDefault.d.ts +2 -102
  62. package/dist/helpers/removeRequiredAndDefault.d.ts.map +1 -1
  63. package/dist/helpers/removeRequiredAndDefault.js +1 -100
  64. package/dist/helpers/removeRequiredAndDefault.js.map +1 -1
  65. package/dist/helpers/validateId.d.ts +1 -36
  66. package/dist/helpers/validateId.d.ts.map +1 -1
  67. package/dist/helpers/validateId.js +1 -36
  68. package/dist/helpers/validateId.js.map +1 -1
  69. package/dist/ld/documentLoader.d.ts +1 -1
  70. package/dist/ld/documentLoader.d.ts.map +1 -1
  71. package/dist/ld/documentLoader.js +1 -1
  72. package/dist/ld/documentLoader.js.map +1 -1
  73. package/dist/ld/getLinkedDataAttributeType.d.ts +1 -1
  74. package/dist/ld/getLinkedDataAttributeType.d.ts.map +1 -1
  75. package/dist/ld/getLinkedDataAttributeType.js +1 -1
  76. package/dist/ld/getLinkedDataAttributeType.js.map +1 -1
  77. package/dist/ld/getLinkedDataContext.d.ts +1 -1
  78. package/dist/ld/getLinkedDataContext.d.ts.map +1 -1
  79. package/dist/ld/getLinkedDataContext.js +1 -1
  80. package/dist/ld/getLinkedDataContext.js.map +1 -1
  81. package/package.json +2 -2
  82. package/src/CredentialFactory.ts +5 -318
  83. package/src/Schema.ts +17 -427
  84. package/src/ValidationError.ts +5 -52
  85. package/src/Validator.ts +19 -483
  86. package/src/__tests__/CredentialFactory.test.ts +1 -1
  87. package/src/__tests__/Schema.test.ts +3 -8
  88. package/src/__tests__/ValidationError.test.ts +4 -2
  89. package/src/__tests__/Validator.test.ts +21 -4
  90. package/src/helpers/__tests__/cleanupAttributes.test.ts +3 -1
  91. package/src/helpers/__tests__/createSchemasMap.test.ts +1 -1
  92. package/src/helpers/__tests__/mapObjectProperties.test.ts +2 -1
  93. package/src/helpers/__tests__/normalizeAttributes.test.ts +4 -2
  94. package/src/helpers/__tests__/normalizeProperties.test.ts +3 -1
  95. package/src/helpers/__tests__/normalizeRequired.test.ts +4 -9
  96. package/src/helpers/__tests__/nullifyEmptyValues.test.ts +43 -12
  97. package/src/helpers/__tests__/removeRequiredAndDefault.test.ts +3 -10
  98. package/src/helpers/cleanupAttributes.ts +6 -44
  99. package/src/helpers/cleanupNulls.ts +2 -63
  100. package/src/helpers/createSchemasMap.ts +4 -163
  101. package/src/helpers/getReferenceIds.ts +2 -173
  102. package/src/helpers/got.ts +3 -59
  103. package/src/helpers/mapObjectProperties.ts +4 -156
  104. package/src/helpers/normalizeAttributes.ts +7 -211
  105. package/src/helpers/normalizeProperties.ts +1 -172
  106. package/src/helpers/normalizeRequired.ts +1 -161
  107. package/src/helpers/normalizeType.ts +11 -139
  108. package/src/helpers/nullifyEmptyValues.ts +10 -145
  109. package/src/helpers/removeRequiredAndDefault.ts +1 -106
  110. package/src/helpers/validateId.ts +1 -36
  111. package/src/ld/documentLoader.ts +1 -1
  112. package/src/ld/getLinkedDataAttributeType.ts +1 -1
  113. package/src/ld/getLinkedDataContext.ts +1 -1
  114. package/src/{helpers/JsonSchema.ts → types.d.ts} +12 -16
  115. package/dist/helpers/JsonSchema.d.ts +0 -99
  116. package/dist/helpers/JsonSchema.d.ts.map +0 -1
  117. package/dist/helpers/JsonSchema.js +0 -3
  118. package/dist/helpers/JsonSchema.js.map +0 -1
@@ -2,155 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const BOOLEAN_STRING_TRUE_VALUES = ['yes', 'true', '1'];
4
4
  const BOOLEAN_STRING_FALSE_VALUES = ['no', 'false', '0'];
5
- /**
6
- * Checks if a value is null or undefined.
7
- *
8
- * @param value - The value to check
9
- * @returns True if the value is null or undefined, false otherwise
10
- */
5
+ /** Checks if a value is null or undefined. */
11
6
  const isNullOrUndefined = (value) => value === null || value === undefined;
12
- /**
13
- * Checks if a JSON Schema type is numeric (number or integer).
14
- *
15
- * @param type - The JSON Schema type to check
16
- * @returns True if the type is 'number' or 'integer', false otherwise
17
- */
7
+ /** Checks if a JSON Schema type is numeric (number or integer). */
18
8
  const isNumericType = (type) => type === 'number' || type === 'integer';
19
- /**
20
- * Checks if a JSON Schema type is boolean.
21
- *
22
- * @param type - The JSON Schema type to check
23
- * @returns True if the type is 'boolean', false otherwise
24
- */
9
+ /** Checks if a JSON Schema type is boolean. */
25
10
  const isBooleanType = (type) => type === 'boolean';
26
- /**
27
- * Type guard that checks if a value is a number.
28
- *
29
- * @param value - The value to check
30
- * @returns True if the value is a number, false otherwise
31
- */
11
+ /** Type guard that checks if a value is a number. */
32
12
  const isNumberValue = (value) => typeof value === 'number';
33
- /**
34
- * Type guard that checks if a value is a boolean.
35
- *
36
- * @param value - The value to check
37
- * @returns True if the value is a boolean, false otherwise
38
- */
13
+ /** Type guard that checks if a value is a boolean. */
39
14
  const isBooleanValue = (value) => typeof value === 'boolean';
40
- /**
41
- * Type guard that checks if a value is a string.
42
- *
43
- * @param value - The value to check
44
- * @returns True if the value is a string, false otherwise
45
- */
15
+ /** Type guard that checks if a value is a string. */
46
16
  const isStringValue = (value) => typeof value === 'string';
47
- /**
48
- * Checks if a string is empty or contains only whitespace characters.
49
- *
50
- * @param value - The string to check
51
- * @returns True if the string is empty or whitespace-only, false otherwise
52
- */
17
+ /** Checks if a string is empty or contains only whitespace characters. */
53
18
  const isEmptyOrWhitespaceString = (value) => value === '' || value.trim() === '';
54
- /**
55
- * Checks if a number is valid (not NaN).
56
- *
57
- * @param value - The number to check
58
- * @returns True if the number is valid (not NaN), false otherwise
59
- */
19
+ /** Checks if a number is valid (not NaN). */
60
20
  const isValidNumber = (value) => !isNaN(value);
61
- /**
62
- * Checks if a string represents a boolean true value.
63
- * Recognized values (case-insensitive): 'yes', 'true', '1'.
64
- *
65
- * @param value - The string to check
66
- * @returns True if the string represents a boolean true value, false otherwise
67
- */
21
+ /** Checks if a string represents a boolean true value. */
68
22
  const isBooleanTrueString = (value) => BOOLEAN_STRING_TRUE_VALUES.includes(value.toLowerCase());
69
- /**
70
- * Checks if a string represents a boolean false value.
71
- * Recognized values (case-insensitive): 'no', 'false', '0'.
72
- *
73
- * @param value - The string to check
74
- * @returns True if the string represents a boolean false value, false otherwise
75
- */
23
+ /** Checks if a string represents a boolean false value. */
76
24
  const isBooleanFalseString = (value) => BOOLEAN_STRING_FALSE_VALUES.includes(value.toLowerCase());
77
- /**
78
- * Normalizes a value to match a specified JSON Schema type.
79
- *
80
- * ## Intent
81
- *
82
- * This function is designed to coerce values into their expected types based on JSON Schema
83
- * type definitions. It's particularly useful when processing data from external sources (like
84
- * form inputs, query parameters, or API responses) where values may arrive as strings but
85
- * need to be converted to their proper types according to a schema definition.
86
- *
87
- * The function performs type coercion where appropriate, but preserves the original value
88
- * when conversion is not possible or when the value is already of the correct type. This
89
- * makes it safe to use in data normalization pipelines without losing information.
90
- *
91
- * ## Use Cases
92
- *
93
- * 1. **Schema-based data normalization**: When processing objects against JSON Schema
94
- * definitions, ensuring property values match their declared types.
95
- *
96
- * 2. **Form data processing**: Converting string values from HTML forms (which are always
97
- * strings) to their expected types (numbers, booleans) based on schema definitions.
98
- *
99
- * 3. **API response normalization**: Normalizing API responses where types may be ambiguous
100
- * or incorrectly serialized (e.g., numbers as strings, booleans as strings).
101
- *
102
- * 4. **Configuration parsing**: Parsing configuration values from environment variables or
103
- * config files where everything is initially a string but needs type coercion.
104
- *
105
- * ## Behavior by Type
106
- *
107
- * - **number/integer**: Attempts to convert strings and booleans to numbers. Preserves
108
- * original value if conversion fails or value is already a number.
109
- *
110
- * - **boolean**: Converts numbers (0 → false, non-zero → true) and recognized string
111
- * values ('yes', 'true', '1' → true; 'no', 'false', '0' → false). Preserves original
112
- * value for unrecognized strings or non-convertible types.
113
- *
114
- * - **string/object/array**: Returns the value as-is (no conversion performed).
115
- *
116
- * - **null/undefined**: Always preserved regardless of target type.
117
- *
118
- * ## Examples
119
- *
120
- * ### Number Conversion
121
- * ```typescript
122
- * normalizeType('number', '123') // → 123
123
- * normalizeType('number', '45.67') // → 45.67
124
- * normalizeType('number', '0') // → 0
125
- * normalizeType('number', true) // → 1
126
- * normalizeType('number', 'abc') // → 'abc' (conversion failed, original preserved)
127
- * ```
128
- *
129
- * ### Boolean Conversion
130
- * ```typescript
131
- * normalizeType('boolean', 0) // → false
132
- * normalizeType('boolean', 1) // → true
133
- * normalizeType('boolean', 'yes') // → true
134
- * normalizeType('boolean', 'true') // → true
135
- * normalizeType('boolean', '1') // → true
136
- * normalizeType('boolean', 'no') // → false
137
- * normalizeType('boolean', 'false') // → false
138
- * normalizeType('boolean', 'maybe') // → 'maybe' (unrecognized, original preserved)
139
- * ```
140
- *
141
- * ### Type Preservation
142
- * ```typescript
143
- * normalizeType('string', 'hello') // → 'hello'
144
- * normalizeType('string', 123) // → 123 (no conversion for string type)
145
- * normalizeType('object', { a: 1 }) // → { a: 1 }
146
- * normalizeType('array', [1, 2, 3]) // → [1, 2, 3]
147
- * normalizeType('number', null) // → null (null always preserved)
148
- * ```
149
- *
150
- * @param type - The target JSON Schema type ('number', 'integer', 'boolean', 'string', 'object', 'array')
151
- * @param value - The value to normalize (can be any type)
152
- * @returns The normalized value, or the original value if normalization is not applicable
153
- */
25
+ /** Normalizes a value to match a specified JSON Schema type. */
154
26
  const normalizeType = (type, value) => {
155
27
  // Preserve null and undefined values regardless of target type
156
28
  if (isNullOrUndefined(value)) {
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeType.js","sourceRoot":"","sources":["../../src/helpers/normalizeType.ts"],"names":[],"mappings":";;AAEA,MAAM,0BAA0B,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;AACxD,MAAM,2BAA2B,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAA6B,EAAE,CACtE,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAExC;;;;;GAKG;AACH,MAAM,aAAa,GAAG,CAAC,IAAe,EAAW,EAAE,CAAC,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,CAAC;AAE5F;;;;;GAKG;AACH,MAAM,aAAa,GAAG,CAAC,IAAe,EAAW,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,aAAa,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAErF;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,KAAc,EAAoB,EAAE,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC;AAExF;;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K,CAAC,EAAE,CAAC;gBAChC,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,0EAA0E;QAC1E,OAAO,KAAK,CAAC;IACf,CAAC;IAED,0EAA0E;IAC1E,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,kBAAe,aAAa,CAAC"}
@@ -1,139 +1,5 @@
1
1
  import { type SchemaErrorDetail } from 'z-schema';
2
- import type { TargetObject } from './JsonSchema';
3
- /**
4
- * Converts empty string values to null for specific format validation errors.
5
- *
6
- * **Intent:**
7
- * This function provides a post-validation normalization strategy that attempts to
8
- * resolve format validation errors by converting empty strings to null. This is
9
- * particularly useful when dealing with optional fields where an empty string
10
- * represents "no value provided" rather than an invalid format. By converting
11
- * empty strings to null, the validation may pass if the schema allows null values
12
- * for optional fields.
13
- *
14
- * **Use Cases:**
15
- * - **Optional field normalization**: When optional string fields receive empty
16
- * strings from user input or API responses, converting them to null allows
17
- * validation to succeed if the schema permits null values for optional fields.
18
- * This is especially common with form inputs that submit empty strings instead
19
- * of omitting fields entirely.
20
- * - **Format error recovery**: After schema validation fails with format errors
21
- * (pattern mismatch, enum mismatch, invalid format), this function attempts to
22
- * resolve errors by nullifying empty strings. This enables graceful handling
23
- * of optional fields that failed format validation due to empty values.
24
- * - **API integration**: When integrating with external APIs or services that
25
- * send empty strings for optional fields, this function normalizes the data
26
- * to use null instead, which is often more semantically correct for optional
27
- * fields in JSON schemas.
28
- * - **Data transformation pipeline**: As part of a validation and normalization
29
- * pipeline, this function can be used to clean and normalize data before
30
- * further processing or storage, ensuring consistent representation of
31
- * "missing" values.
32
- * - **User input handling**: When processing user-submitted forms or data where
33
- * empty string inputs should be treated as "not provided" rather than invalid,
34
- * this function converts them to null for proper schema validation.
35
- *
36
- * **Behavior:**
37
- * - Returns a deep clone of the input object (does not mutate the original)
38
- * - Only processes format-related errors (PATTERN, ENUM_MISMATCH, INVALID_FORMAT)
39
- * - Skips required attributes (marked with `x-required: true`)
40
- * - Only converts empty strings (`''`) to null, preserving other values
41
- * - Supports nested paths and array indices
42
- * - Returns both the modified object and remaining validation errors that
43
- * couldn't be resolved
44
- *
45
- * **Examples:**
46
- *
47
- * ```typescript
48
- * // Example 1: Basic usage with pattern error
49
- * const object = { email: '' };
50
- * const error = {
51
- * code: 'PATTERN',
52
- * path: '#/email',
53
- * // ... other error properties
54
- * };
55
- * const [result, remainingErrors] = nullifyEmptyValues(object, [error]);
56
- * // result: { email: null }
57
- * // remainingErrors: []
58
- * ```
59
- *
60
- * ```typescript
61
- * // Example 2: Required fields are not nullified
62
- * const object = { requiredField: '', optionalField: '' };
63
- * const requiredError = {
64
- * code: 'PATTERN',
65
- * path: '#/requiredField',
66
- * // schema has x-required: true
67
- * };
68
- * const optionalError = {
69
- * code: 'PATTERN',
70
- * path: '#/optionalField',
71
- * // schema has no x-required or x-required: false
72
- * };
73
- * const [result, remainingErrors] = nullifyEmptyValues(
74
- * object,
75
- * [requiredError, optionalError]
76
- * );
77
- * // result: { requiredField: '', optionalField: null }
78
- * // remainingErrors: [requiredError] // required field error remains
79
- * ```
80
- *
81
- * ```typescript
82
- * // Example 3: Nested paths and arrays
83
- * const object = {
84
- * user: {
85
- * profile: {
86
- * bio: '',
87
- * tags: ['', 'tag1', '']
88
- * }
89
- * }
90
- * };
91
- * const errors = [
92
- * { code: 'PATTERN', path: '#/user/profile/bio' },
93
- * { code: 'INVALID_FORMAT', path: '#/user/profile/tags/0' },
94
- * { code: 'ENUM_MISMATCH', path: '#/user/profile/tags/2' }
95
- * ];
96
- * const [result, remainingErrors] = nullifyEmptyValues(object, errors);
97
- * // result: {
98
- * // user: {
99
- * // profile: {
100
- * // bio: null,
101
- * // tags: [null, 'tag1', null]
102
- * // }
103
- * // }
104
- * // }
105
- * // remainingErrors: []
106
- * ```
107
- *
108
- * ```typescript
109
- * // Example 4: Non-format errors are not processed
110
- * const object = { field: '' };
111
- * const formatError = { code: 'PATTERN', path: '#/field' };
112
- * const typeError = { code: 'INVALID_TYPE', path: '#/field' };
113
- * const [result, remainingErrors] = nullifyEmptyValues(
114
- * object,
115
- * [formatError, typeError]
116
- * );
117
- * // result: { field: null }
118
- * // remainingErrors: [typeError] // type error remains
119
- * ```
120
- *
121
- * ```typescript
122
- * // Example 5: Non-empty values are preserved
123
- * const object = { field: 'invalid-value' };
124
- * const error = { code: 'PATTERN', path: '#/field' };
125
- * const [result, remainingErrors] = nullifyEmptyValues(object, [error]);
126
- * // result: { field: 'invalid-value' } // unchanged
127
- * // remainingErrors: [error] // error remains
128
- * ```
129
- *
130
- * @param object - The target object to process (will be deep cloned, not mutated)
131
- * @param validationErrors - Array of schema validation errors from z-schema
132
- * @returns A tuple containing:
133
- * - `[0]`: Deep clone of the object with empty strings converted to null where applicable
134
- * - `[1]`: Array of validation errors that couldn't be resolved (required fields,
135
- * non-format errors, or errors for non-empty values)
136
- */
2
+ /** Converts empty string values to null for specific format validation errors. */
137
3
  declare const nullifyEmptyValues: (object: TargetObject, validationErrors: SchemaErrorDetail[]) => [TargetObject, SchemaErrorDetail[]];
138
4
  export default nullifyEmptyValues;
139
5
  //# sourceMappingURL=nullifyEmptyValues.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nullifyEmptyValues.d.ts","sourceRoot":"","sources":["../../src/helpers/nullifyEmptyValues.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAiBjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqIG;AACH,QAAA,MAAM,kBAAkB,GACtB,QAAQ,YAAY,EACpB,kBAAkB,iBAAiB,EAAE,KACpC,CAAC,YAAY,EAAE,iBAAiB,EAAE,CA+CpC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
1
+ {"version":3,"file":"nullifyEmptyValues.d.ts","sourceRoot":"","sources":["../../src/helpers/nullifyEmptyValues.ts"],"names":[],"mappings":"AACA,OAAgB,EAAE,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAe3D,kFAAkF;AAClF,QAAA,MAAM,kBAAkB,GACtB,QAAQ,YAAY,EACpB,kBAAkB,iBAAiB,EAAE,KACpC,CAAC,YAAY,EAAE,iBAAiB,EAAE,CAiDpC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const lodash_1 = require("lodash");
4
- const z_schema_1 = require("z-schema");
7
+ const z_schema_1 = __importDefault(require("z-schema"));
5
8
  /**
6
9
  * Format error codes that indicate validation failures due to format mismatches.
7
10
  * These errors can potentially be resolved by converting empty strings to null.
@@ -11,151 +14,16 @@ const FORMAT_ERROR_CODES = [
11
14
  'ENUM_MISMATCH',
12
15
  'INVALID_FORMAT'
13
16
  ];
14
- /**
15
- * Values that are considered "empty" and can be safely converted to null.
16
- */
17
+ /** Values that are considered "empty" and can be safely converted to null. */
17
18
  const EMPTY_VALUES = [''];
18
- /**
19
- * Converts empty string values to null for specific format validation errors.
20
- *
21
- * **Intent:**
22
- * This function provides a post-validation normalization strategy that attempts to
23
- * resolve format validation errors by converting empty strings to null. This is
24
- * particularly useful when dealing with optional fields where an empty string
25
- * represents "no value provided" rather than an invalid format. By converting
26
- * empty strings to null, the validation may pass if the schema allows null values
27
- * for optional fields.
28
- *
29
- * **Use Cases:**
30
- * - **Optional field normalization**: When optional string fields receive empty
31
- * strings from user input or API responses, converting them to null allows
32
- * validation to succeed if the schema permits null values for optional fields.
33
- * This is especially common with form inputs that submit empty strings instead
34
- * of omitting fields entirely.
35
- * - **Format error recovery**: After schema validation fails with format errors
36
- * (pattern mismatch, enum mismatch, invalid format), this function attempts to
37
- * resolve errors by nullifying empty strings. This enables graceful handling
38
- * of optional fields that failed format validation due to empty values.
39
- * - **API integration**: When integrating with external APIs or services that
40
- * send empty strings for optional fields, this function normalizes the data
41
- * to use null instead, which is often more semantically correct for optional
42
- * fields in JSON schemas.
43
- * - **Data transformation pipeline**: As part of a validation and normalization
44
- * pipeline, this function can be used to clean and normalize data before
45
- * further processing or storage, ensuring consistent representation of
46
- * "missing" values.
47
- * - **User input handling**: When processing user-submitted forms or data where
48
- * empty string inputs should be treated as "not provided" rather than invalid,
49
- * this function converts them to null for proper schema validation.
50
- *
51
- * **Behavior:**
52
- * - Returns a deep clone of the input object (does not mutate the original)
53
- * - Only processes format-related errors (PATTERN, ENUM_MISMATCH, INVALID_FORMAT)
54
- * - Skips required attributes (marked with `x-required: true`)
55
- * - Only converts empty strings (`''`) to null, preserving other values
56
- * - Supports nested paths and array indices
57
- * - Returns both the modified object and remaining validation errors that
58
- * couldn't be resolved
59
- *
60
- * **Examples:**
61
- *
62
- * ```typescript
63
- * // Example 1: Basic usage with pattern error
64
- * const object = { email: '' };
65
- * const error = {
66
- * code: 'PATTERN',
67
- * path: '#/email',
68
- * // ... other error properties
69
- * };
70
- * const [result, remainingErrors] = nullifyEmptyValues(object, [error]);
71
- * // result: { email: null }
72
- * // remainingErrors: []
73
- * ```
74
- *
75
- * ```typescript
76
- * // Example 2: Required fields are not nullified
77
- * const object = { requiredField: '', optionalField: '' };
78
- * const requiredError = {
79
- * code: 'PATTERN',
80
- * path: '#/requiredField',
81
- * // schema has x-required: true
82
- * };
83
- * const optionalError = {
84
- * code: 'PATTERN',
85
- * path: '#/optionalField',
86
- * // schema has no x-required or x-required: false
87
- * };
88
- * const [result, remainingErrors] = nullifyEmptyValues(
89
- * object,
90
- * [requiredError, optionalError]
91
- * );
92
- * // result: { requiredField: '', optionalField: null }
93
- * // remainingErrors: [requiredError] // required field error remains
94
- * ```
95
- *
96
- * ```typescript
97
- * // Example 3: Nested paths and arrays
98
- * const object = {
99
- * user: {
100
- * profile: {
101
- * bio: '',
102
- * tags: ['', 'tag1', '']
103
- * }
104
- * }
105
- * };
106
- * const errors = [
107
- * { code: 'PATTERN', path: '#/user/profile/bio' },
108
- * { code: 'INVALID_FORMAT', path: '#/user/profile/tags/0' },
109
- * { code: 'ENUM_MISMATCH', path: '#/user/profile/tags/2' }
110
- * ];
111
- * const [result, remainingErrors] = nullifyEmptyValues(object, errors);
112
- * // result: {
113
- * // user: {
114
- * // profile: {
115
- * // bio: null,
116
- * // tags: [null, 'tag1', null]
117
- * // }
118
- * // }
119
- * // }
120
- * // remainingErrors: []
121
- * ```
122
- *
123
- * ```typescript
124
- * // Example 4: Non-format errors are not processed
125
- * const object = { field: '' };
126
- * const formatError = { code: 'PATTERN', path: '#/field' };
127
- * const typeError = { code: 'INVALID_TYPE', path: '#/field' };
128
- * const [result, remainingErrors] = nullifyEmptyValues(
129
- * object,
130
- * [formatError, typeError]
131
- * );
132
- * // result: { field: null }
133
- * // remainingErrors: [typeError] // type error remains
134
- * ```
135
- *
136
- * ```typescript
137
- * // Example 5: Non-empty values are preserved
138
- * const object = { field: 'invalid-value' };
139
- * const error = { code: 'PATTERN', path: '#/field' };
140
- * const [result, remainingErrors] = nullifyEmptyValues(object, [error]);
141
- * // result: { field: 'invalid-value' } // unchanged
142
- * // remainingErrors: [error] // error remains
143
- * ```
144
- *
145
- * @param object - The target object to process (will be deep cloned, not mutated)
146
- * @param validationErrors - Array of schema validation errors from z-schema
147
- * @returns A tuple containing:
148
- * - `[0]`: Deep clone of the object with empty strings converted to null where applicable
149
- * - `[1]`: Array of validation errors that couldn't be resolved (required fields,
150
- * non-format errors, or errors for non-empty values)
151
- */
19
+ /** Converts empty string values to null for specific format validation errors. */
152
20
  const nullifyEmptyValues = (object, validationErrors) => {
153
21
  // Create a deep clone to avoid mutating the original object
154
22
  const result = JSON.parse(JSON.stringify(object));
155
23
  const remainingErrors = [];
156
24
  for (const error of validationErrors) {
157
25
  const { code, path: pathString } = error;
158
- const schema = (0, lodash_1.get)(error, z_schema_1.schemaSymbol);
26
+ const schema = (0, lodash_1.get)(error, z_schema_1.default.schemaSymbol);
159
27
  const isAttributeRequired = schema?.['x-required'] === true;
160
28
  const isFormatError = FORMAT_ERROR_CODES.includes(code);
161
29
  const shouldSkipRequiredAttribute = isAttributeRequired;
@@ -171,10 +39,12 @@ const nullifyEmptyValues = (object, validationErrors) => {
171
39
  continue;
172
40
  }
173
41
  // Parse the JSON path (e.g., '#/user/profile/field' -> ['user', 'profile', 'field'])
174
- const path = pathString.replace(/^#\//, '').split('/').filter(Boolean);
175
- // Get the actual value from the error's JSON context
176
- const json = (0, lodash_1.get)(error, z_schema_1.jsonSymbol);
177
- const value = (0, lodash_1.get)(json, path);
42
+ const path = typeof pathString === 'string'
43
+ ? pathString.replace(/^#\//, '').split('/').filter(Boolean)
44
+ : pathString;
45
+ // Get the actual value from the error's JSON context, or fall back to the object
46
+ const json = (0, lodash_1.get)(error, z_schema_1.default.jsonSymbol);
47
+ const value = (0, lodash_1.get)(json ?? result, path);
178
48
  const isEmptyValue = EMPTY_VALUES.includes(value);
179
49
  const shouldSkipNonEmptyValue = !isEmptyValue;
180
50
  // Only nullify if the value is actually empty
@@ -1 +1 @@
1
- {"version":3,"file":"nullifyEmptyValues.js","sourceRoot":"","sources":["../../src/helpers/nullifyEmptyValues.ts"],"names":[],"mappings":";;AAAA,mCAAkC;AAClC,uCAA4E;AAI5E;;;GAGG;AACH,MAAM,kBAAkB,GAAG;IACzB,SAAS;IACT,eAAe;IACf,gBAAgB;CACR,CAAC;AAEX;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,EAAE,CAAU,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
- import type { EnumSchema, PropertySchema } from './JsonSchema';
2
- /**
3
- * Recursively removes `required` and `default` attributes from a JSON schema.
4
- *
5
- * **Intent:**
6
- * This function is designed to transform JSON schemas by stripping out validation
7
- * constraints (`required`) and default values (`default`) from all properties,
8
- * including nested objects and array items. This is useful for creating "pure"
9
- * or "update-friendly" versions of schemas where all fields become optional and
10
- * no defaults are applied.
11
- *
12
- * **Use Cases:**
13
- * 1. **Update Schemas**: Create schemas for partial updates where all fields are optional
14
- * 2. **Schema Transformation**: Prepare schemas for contexts where required/default
15
- * constraints are not needed (e.g., credential generation, API transformations)
16
- * 3. **Schema Normalization**: Remove validation metadata before further processing
17
- *
18
- * **Behavior:**
19
- * - Mutates the input schema in-place by deleting `required` and `default` properties
20
- * - Recursively processes nested object properties
21
- * - Recursively processes array items (including nested objects within arrays)
22
- * - Preserves all other schema properties (type, description, pattern, etc.)
23
- * - Returns an object containing only the `properties` field
24
- *
25
- * **Examples:**
26
- *
27
- * ```typescript
28
- * // Example 1: Simple object schema
29
- * const schema = {
30
- * type: 'object',
31
- * properties: {
32
- * name: { type: 'string', required: true, default: 'John' },
33
- * age: { type: 'number', required: false, default: 0 }
34
- * }
35
- * };
36
- *
37
- * const result = removeRequiredAndDefault(schema);
38
- * // result.properties.name: { type: 'string' } (required and default removed)
39
- * // result.properties.age: { type: 'number' } (required and default removed)
40
- * ```
41
- *
42
- * ```typescript
43
- * // Example 2: Nested objects
44
- * const schema = {
45
- * type: 'object',
46
- * properties: {
47
- * user: {
48
- * type: 'object',
49
- * required: true,
50
- * default: {},
51
- * properties: {
52
- * name: { type: 'string', required: true, default: 'John' },
53
- * address: {
54
- * type: 'object',
55
- * properties: {
56
- * street: { type: 'string', required: true, default: '' }
57
- * }
58
- * }
59
- * }
60
- * }
61
- * }
62
- * };
63
- *
64
- * const result = removeRequiredAndDefault(schema);
65
- * // All required and default attributes are removed at all nesting levels
66
- * ```
67
- *
68
- * ```typescript
69
- * // Example 3: Arrays with object items
70
- * const schema = {
71
- * type: 'object',
72
- * properties: {
73
- * users: {
74
- * type: 'array',
75
- * required: true,
76
- * default: [],
77
- * items: {
78
- * type: 'object',
79
- * properties: {
80
- * name: { type: 'string', required: true, default: 'John' }
81
- * }
82
- * }
83
- * }
84
- * }
85
- * };
86
- *
87
- * const result = removeRequiredAndDefault(schema);
88
- * // Removes required/default from array property and nested object properties
89
- * ```
90
- *
91
- * **Limitations:**
92
- * - Only processes schemas with a `properties` field (ObjectPropertySchema)
93
- * - EnumSchema is accepted as a parameter but not processed (will return empty properties)
94
- * - The function mutates the input schema object
95
- * - Array items that are primitives (string, number, etc.) are processed but
96
- * their return values are discarded (this is intentional)
97
- *
98
- * @param jsonSchema - The JSON schema to process (must have a `properties` field)
99
- * @returns An object containing only the `properties` field with all `required`
100
- * and `default` attributes removed recursively
101
- */
1
+ /** Recursively removes `required` and `default` attributes from a JSON schema. */
102
2
  declare const removeRequiredAndDefault: (jsonSchema: PropertySchema | EnumSchema) => {
103
- properties: import("./JsonSchema").PropertiesSchema;
3
+ properties: PropertiesSchema;
104
4
  };
105
5
  export default removeRequiredAndDefault;
106
6
  //# sourceMappingURL=removeRequiredAndDefault.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"removeRequiredAndDefault.d.ts","sourceRoot":"","sources":["../../src/helpers/removeRequiredAndDefault.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EAGf,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmGG;AACH,QAAA,MAAM,wBAAwB,GAAI,YAAY,cAAc,GAAG,UAAU;;CAyCxE,CAAC;AAEF,eAAe,wBAAwB,CAAC"}
1
+ {"version":3,"file":"removeRequiredAndDefault.d.ts","sourceRoot":"","sources":["../../src/helpers/removeRequiredAndDefault.ts"],"names":[],"mappings":"AACA,kFAAkF;AAClF,QAAA,MAAM,wBAAwB,GAAI,YAAY,cAAc,GAAG,UAAU;;CAyCxE,CAAC;AAEF,eAAe,wBAAwB,CAAC"}