@skmtc/core 0.0.796 → 0.0.797

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 (55) hide show
  1. package/esm/app/validate.d.ts +32 -0
  2. package/esm/app/validate.d.ts.map +1 -1
  3. package/esm/app/validate.js +32 -0
  4. package/esm/context/CoreContext.d.ts +137 -1
  5. package/esm/context/CoreContext.d.ts.map +1 -1
  6. package/esm/context/CoreContext.js +87 -0
  7. package/esm/dsl/constants.d.ts +28 -0
  8. package/esm/dsl/constants.d.ts.map +1 -1
  9. package/esm/dsl/constants.js +28 -0
  10. package/esm/oas/_helpers/parseDefault.d.ts +148 -0
  11. package/esm/oas/_helpers/parseDefault.d.ts.map +1 -1
  12. package/esm/oas/_helpers/parseDefault.js +128 -0
  13. package/esm/oas/_helpers/parseEnum.d.ts +124 -0
  14. package/esm/oas/_helpers/parseEnum.d.ts.map +1 -1
  15. package/esm/oas/_helpers/parseEnum.js +104 -0
  16. package/esm/oas/_helpers/parseExample.d.ts +107 -0
  17. package/esm/oas/_helpers/parseExample.d.ts.map +1 -1
  18. package/esm/oas/_helpers/parseExample.js +87 -0
  19. package/esm/oas/_helpers/parseFormat.d.ts +154 -0
  20. package/esm/oas/_helpers/parseFormat.d.ts.map +1 -1
  21. package/esm/oas/_helpers/parseFormat.js +138 -0
  22. package/esm/oas/_helpers/parseNullable.d.ts +127 -0
  23. package/esm/oas/_helpers/parseNullable.d.ts.map +1 -1
  24. package/esm/oas/_helpers/parseNullable.js +113 -0
  25. package/esm/run/toV3JsonDocument.d.ts +90 -0
  26. package/esm/run/toV3JsonDocument.d.ts.map +1 -1
  27. package/esm/run/toV3JsonDocument.js +84 -0
  28. package/package.json +1 -1
  29. package/script/app/validate.d.ts +32 -0
  30. package/script/app/validate.d.ts.map +1 -1
  31. package/script/app/validate.js +32 -0
  32. package/script/context/CoreContext.d.ts +137 -1
  33. package/script/context/CoreContext.d.ts.map +1 -1
  34. package/script/context/CoreContext.js +87 -0
  35. package/script/dsl/constants.d.ts +28 -0
  36. package/script/dsl/constants.d.ts.map +1 -1
  37. package/script/dsl/constants.js +28 -0
  38. package/script/oas/_helpers/parseDefault.d.ts +148 -0
  39. package/script/oas/_helpers/parseDefault.d.ts.map +1 -1
  40. package/script/oas/_helpers/parseDefault.js +128 -0
  41. package/script/oas/_helpers/parseEnum.d.ts +124 -0
  42. package/script/oas/_helpers/parseEnum.d.ts.map +1 -1
  43. package/script/oas/_helpers/parseEnum.js +104 -0
  44. package/script/oas/_helpers/parseExample.d.ts +107 -0
  45. package/script/oas/_helpers/parseExample.d.ts.map +1 -1
  46. package/script/oas/_helpers/parseExample.js +87 -0
  47. package/script/oas/_helpers/parseFormat.d.ts +154 -0
  48. package/script/oas/_helpers/parseFormat.d.ts.map +1 -1
  49. package/script/oas/_helpers/parseFormat.js +138 -0
  50. package/script/oas/_helpers/parseNullable.d.ts +127 -0
  51. package/script/oas/_helpers/parseNullable.d.ts.map +1 -1
  52. package/script/oas/_helpers/parseNullable.js +113 -0
  53. package/script/run/toV3JsonDocument.d.ts +90 -0
  54. package/script/run/toV3JsonDocument.d.ts.map +1 -1
  55. package/script/run/toV3JsonDocument.js +84 -0
@@ -1 +1 @@
1
- {"version":3,"file":"parseExample.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseExample.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,KAAK,gBAAgB,CACnB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC9B,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa,EAAE,CAAC,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CAAA;AAED;;;;;;GAMG;AACH,KAAK,kBAAkB,CACrB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,6CAA6C;IAC7C,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAAA;IACrE,gEAAgE;IAChE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;CAC3C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsFG;AACH,eAAO,MAAM,YAAY,GACvB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,EACpC,6CAKC,gBAAgB,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAG,kBAAkB,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAgB9E,CAAA"}
@@ -35,6 +35,93 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.parseExample = void 0;
37
37
  const v = __importStar(require("valibot"));
38
+ /**
39
+ * Parses and validates OpenAPI schema examples with type safety.
40
+ *
41
+ * This function extracts and validates example values from OpenAPI schema objects,
42
+ * ensuring they conform to the expected type and handling nullable schemas correctly.
43
+ * Invalid examples are removed and logged as warnings through the parse context.
44
+ *
45
+ * The function provides full type safety, with the return type reflecting whether
46
+ * null values are allowed based on the nullable parameter.
47
+ *
48
+ * @template T - The expected type of the example value
49
+ * @template Nullable - Whether the schema allows null values
50
+ * @template Value - The OpenAPI schema object type
51
+ *
52
+ * @param args - Parsing configuration
53
+ * @returns Parsed example data with the validated example and cleaned schema
54
+ *
55
+ * @example Basic string example parsing
56
+ * ```typescript
57
+ * import { parseExample } from '@skmtc/core/oas/_helpers';
58
+ * import * as v from 'valibot';
59
+ *
60
+ * const result = parseExample({
61
+ * value: {
62
+ * type: 'string',
63
+ * example: 'hello world',
64
+ * format: 'text'
65
+ * },
66
+ * nullable: false,
67
+ * valibotSchema: v.string(),
68
+ * context: parseContext
69
+ * });
70
+ *
71
+ * console.log(result.example); // 'hello world'
72
+ * console.log(result.value); // { type: 'string', format: 'text' }
73
+ * ```
74
+ *
75
+ * @example Nullable schema example
76
+ * ```typescript
77
+ * const result = parseExample({
78
+ * value: {
79
+ * type: 'string',
80
+ * example: null,
81
+ * minLength: 1
82
+ * },
83
+ * nullable: true,
84
+ * valibotSchema: v.string(),
85
+ * context: parseContext
86
+ * });
87
+ *
88
+ * console.log(result.example); // null (valid for nullable schema)
89
+ * // Type: string | null | undefined
90
+ * ```
91
+ *
92
+ * @example Invalid example handling
93
+ * ```typescript
94
+ * const result = parseExample({
95
+ * value: {
96
+ * type: 'number',
97
+ * example: 'not a number', // Invalid example
98
+ * minimum: 0
99
+ * },
100
+ * nullable: false,
101
+ * valibotSchema: v.number(),
102
+ * context: parseContext
103
+ * });
104
+ *
105
+ * console.log(result.example); // undefined (invalid example removed)
106
+ * // Context will log a warning about the invalid example
107
+ * ```
108
+ *
109
+ * @example Array example parsing
110
+ * ```typescript
111
+ * const result = parseExample({
112
+ * value: {
113
+ * type: 'array',
114
+ * items: { type: 'string' },
115
+ * example: ['item1', 'item2', 'item3']
116
+ * },
117
+ * nullable: false,
118
+ * valibotSchema: v.array(v.string()),
119
+ * context: parseContext
120
+ * });
121
+ *
122
+ * console.log(result.example); // ['item1', 'item2', 'item3']
123
+ * ```
124
+ */
38
125
  const parseExample = ({ value, nullable, valibotSchema, context }) => {
39
126
  const { example, ...rest } = value;
40
127
  const parsedExample = context.provisionalParse({
@@ -1,15 +1,169 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import type { ParseContext } from '../../context/ParseContext.js';
3
3
  import * as v from 'valibot';
4
+ /**
5
+ * Arguments for parsing OpenAPI schema format values.
6
+ *
7
+ * @template T - The expected type of the format value
8
+ */
4
9
  type ParseFormatArgs<T> = {
10
+ /** The OpenAPI schema object with processed properties removed */
5
11
  value: Omit<OpenAPIV3.SchemaObject, 'nullable' | 'example' | 'enums'>;
12
+ /** Valibot schema for validating the format value */
6
13
  valibotSchema: v.GenericSchema<T>;
14
+ /** Parse context for error handling */
7
15
  context: ParseContext;
8
16
  };
17
+ /**
18
+ * Return type for parsed format data.
19
+ *
20
+ * @template T - The expected type of the format value
21
+ * @template Value - The OpenAPI schema object type
22
+ */
9
23
  type ParseFormatReturn<T, Value extends OpenAPIV3.SchemaObject> = {
24
+ /** The parsed and validated format string */
10
25
  format: T | undefined;
26
+ /** The schema object without the format property */
11
27
  value: Omit<Value, 'format'>;
12
28
  };
29
+ /**
30
+ * Parses and validates OpenAPI schema format values with type safety.
31
+ *
32
+ * This function extracts and validates format specifiers from OpenAPI schema objects,
33
+ * ensuring they conform to expected format types for the given schema. Invalid format
34
+ * values are removed and logged as warnings through the parse context.
35
+ *
36
+ * The format property provides additional semantic information about the expected
37
+ * structure of string values (like 'email', 'date-time', 'uuid', etc.) and numeric
38
+ * precision (like 'float', 'double' for numbers, 'int32', 'int64' for integers).
39
+ *
40
+ * @template T - The expected type of the format value (usually string)
41
+ * @template Value - The OpenAPI schema object type
42
+ *
43
+ * @param args - Parsing configuration
44
+ * @returns Parsed format data with the validated format and cleaned schema
45
+ *
46
+ * @example String format parsing
47
+ * ```typescript
48
+ * import { parseFormat } from '@skmtc/core/oas/_helpers';
49
+ * import * as v from 'valibot';
50
+ *
51
+ * const result = parseFormat({
52
+ * value: {
53
+ * type: 'string',
54
+ * format: 'email',
55
+ * maxLength: 100
56
+ * },
57
+ * valibotSchema: v.string(),
58
+ * context: parseContext
59
+ * });
60
+ *
61
+ * console.log(result.format); // 'email'
62
+ * console.log(result.value); // { type: 'string', maxLength: 100 }
63
+ * ```
64
+ *
65
+ * @example Date-time format
66
+ * ```typescript
67
+ * const result = parseFormat({
68
+ * value: {
69
+ * type: 'string',
70
+ * format: 'date-time',
71
+ * description: 'ISO 8601 timestamp'
72
+ * },
73
+ * valibotSchema: v.string(),
74
+ * context: parseContext
75
+ * });
76
+ *
77
+ * console.log(result.format); // 'date-time'
78
+ * // Can be used to generate Date objects in TypeScript
79
+ * ```
80
+ *
81
+ * @example Number precision formats
82
+ * ```typescript
83
+ * const result = parseFormat({
84
+ * value: {
85
+ * type: 'number',
86
+ * format: 'float',
87
+ * minimum: 0
88
+ * },
89
+ * valibotSchema: v.string(), // Format is always a string
90
+ * context: parseContext
91
+ * });
92
+ *
93
+ * console.log(result.format); // 'float'
94
+ * // Indicates single-precision floating-point
95
+ * ```
96
+ *
97
+ * @example Integer format specifiers
98
+ * ```typescript
99
+ * const result = parseFormat({
100
+ * value: {
101
+ * type: 'integer',
102
+ * format: 'int64',
103
+ * description: 'Large integer ID'
104
+ * },
105
+ * valibotSchema: v.string(),
106
+ * context: parseContext
107
+ * });
108
+ *
109
+ * console.log(result.format); // 'int64'
110
+ * // Indicates 64-bit signed integer
111
+ * ```
112
+ *
113
+ * @example Invalid format handling
114
+ * ```typescript
115
+ * const result = parseFormat({
116
+ * value: {
117
+ * type: 'string',
118
+ * format: 123, // Invalid - should be string
119
+ * pattern: '^[a-z]+$'
120
+ * } as any,
121
+ * valibotSchema: v.string(),
122
+ * context: parseContext
123
+ * });
124
+ *
125
+ * console.log(result.format); // undefined (invalid format removed)
126
+ * console.log(result.value); // { type: 'string', pattern: '^[a-z]+$' }
127
+ * // Context will log a warning about the invalid format
128
+ * ```
129
+ *
130
+ * @example Missing format (undefined)
131
+ * ```typescript
132
+ * const result = parseFormat({
133
+ * value: {
134
+ * type: 'string',
135
+ * minLength: 1,
136
+ * maxLength: 50
137
+ * },
138
+ * valibotSchema: v.string(),
139
+ * context: parseContext
140
+ * });
141
+ *
142
+ * console.log(result.format); // undefined (no format specified)
143
+ * console.log(result.value); // { type: 'string', minLength: 1, maxLength: 50 }
144
+ * ```
145
+ *
146
+ * @example Common string formats
147
+ * ```typescript
148
+ * // Standard OpenAPI string formats:
149
+ * // - 'date': full-date as defined by RFC3339
150
+ * // - 'date-time': date-time as defined by RFC3339
151
+ * // - 'time': time as defined by RFC3339
152
+ * // - 'email': email address as defined by RFC5322
153
+ * // - 'uri': URI as defined by RFC3986
154
+ * // - 'uuid': UUID as defined by RFC4122
155
+ * // - 'binary': binary data (base64 encoded)
156
+ * // - 'byte': base64 encoded characters
157
+ * // - 'password': hint for UI to obscure input
158
+ *
159
+ * const emailFormat = parseFormat({
160
+ * value: { type: 'string', format: 'email' },
161
+ * valibotSchema: v.string(),
162
+ * context
163
+ * });
164
+ * // Can generate validation: v.pipe(v.string(), v.email())
165
+ * ```
166
+ */
13
167
  export declare const parseFormat: <T, Value extends OpenAPIV3.SchemaObject>({ value, valibotSchema, context }: ParseFormatArgs<T>) => ParseFormatReturn<T, Value>;
14
168
  export {};
15
169
  //# sourceMappingURL=parseFormat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseFormat.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,KAAK,eAAe,CAAC,CAAC,IAAI;IACxB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAAC,CAAA;IACrE,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,KAAK,iBAAiB,CAAC,CAAC,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IAChE,MAAM,EAAE,CAAC,G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AAC,EAAE,KAAK,SAAS,SAAS,CAAC,YAAY,EAAE,mCAIlE,eAAe,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,EAAE,KAAK,CAgBjD,CAAA"}
@@ -35,6 +35,144 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.parseFormat = void 0;
37
37
  const v = __importStar(require("valibot"));
38
+ /**
39
+ * Parses and validates OpenAPI schema format values with type safety.
40
+ *
41
+ * This function extracts and validates format specifiers from OpenAPI schema objects,
42
+ * ensuring they conform to expected format types for the given schema. Invalid format
43
+ * values are removed and logged as warnings through the parse context.
44
+ *
45
+ * The format property provides additional semantic information about the expected
46
+ * structure of string values (like 'email', 'date-time', 'uuid', etc.) and numeric
47
+ * precision (like 'float', 'double' for numbers, 'int32', 'int64' for integers).
48
+ *
49
+ * @template T - The expected type of the format value (usually string)
50
+ * @template Value - The OpenAPI schema object type
51
+ *
52
+ * @param args - Parsing configuration
53
+ * @returns Parsed format data with the validated format and cleaned schema
54
+ *
55
+ * @example String format parsing
56
+ * ```typescript
57
+ * import { parseFormat } from '@skmtc/core/oas/_helpers';
58
+ * import * as v from 'valibot';
59
+ *
60
+ * const result = parseFormat({
61
+ * value: {
62
+ * type: 'string',
63
+ * format: 'email',
64
+ * maxLength: 100
65
+ * },
66
+ * valibotSchema: v.string(),
67
+ * context: parseContext
68
+ * });
69
+ *
70
+ * console.log(result.format); // 'email'
71
+ * console.log(result.value); // { type: 'string', maxLength: 100 }
72
+ * ```
73
+ *
74
+ * @example Date-time format
75
+ * ```typescript
76
+ * const result = parseFormat({
77
+ * value: {
78
+ * type: 'string',
79
+ * format: 'date-time',
80
+ * description: 'ISO 8601 timestamp'
81
+ * },
82
+ * valibotSchema: v.string(),
83
+ * context: parseContext
84
+ * });
85
+ *
86
+ * console.log(result.format); // 'date-time'
87
+ * // Can be used to generate Date objects in TypeScript
88
+ * ```
89
+ *
90
+ * @example Number precision formats
91
+ * ```typescript
92
+ * const result = parseFormat({
93
+ * value: {
94
+ * type: 'number',
95
+ * format: 'float',
96
+ * minimum: 0
97
+ * },
98
+ * valibotSchema: v.string(), // Format is always a string
99
+ * context: parseContext
100
+ * });
101
+ *
102
+ * console.log(result.format); // 'float'
103
+ * // Indicates single-precision floating-point
104
+ * ```
105
+ *
106
+ * @example Integer format specifiers
107
+ * ```typescript
108
+ * const result = parseFormat({
109
+ * value: {
110
+ * type: 'integer',
111
+ * format: 'int64',
112
+ * description: 'Large integer ID'
113
+ * },
114
+ * valibotSchema: v.string(),
115
+ * context: parseContext
116
+ * });
117
+ *
118
+ * console.log(result.format); // 'int64'
119
+ * // Indicates 64-bit signed integer
120
+ * ```
121
+ *
122
+ * @example Invalid format handling
123
+ * ```typescript
124
+ * const result = parseFormat({
125
+ * value: {
126
+ * type: 'string',
127
+ * format: 123, // Invalid - should be string
128
+ * pattern: '^[a-z]+$'
129
+ * } as any,
130
+ * valibotSchema: v.string(),
131
+ * context: parseContext
132
+ * });
133
+ *
134
+ * console.log(result.format); // undefined (invalid format removed)
135
+ * console.log(result.value); // { type: 'string', pattern: '^[a-z]+$' }
136
+ * // Context will log a warning about the invalid format
137
+ * ```
138
+ *
139
+ * @example Missing format (undefined)
140
+ * ```typescript
141
+ * const result = parseFormat({
142
+ * value: {
143
+ * type: 'string',
144
+ * minLength: 1,
145
+ * maxLength: 50
146
+ * },
147
+ * valibotSchema: v.string(),
148
+ * context: parseContext
149
+ * });
150
+ *
151
+ * console.log(result.format); // undefined (no format specified)
152
+ * console.log(result.value); // { type: 'string', minLength: 1, maxLength: 50 }
153
+ * ```
154
+ *
155
+ * @example Common string formats
156
+ * ```typescript
157
+ * // Standard OpenAPI string formats:
158
+ * // - 'date': full-date as defined by RFC3339
159
+ * // - 'date-time': date-time as defined by RFC3339
160
+ * // - 'time': time as defined by RFC3339
161
+ * // - 'email': email address as defined by RFC5322
162
+ * // - 'uri': URI as defined by RFC3986
163
+ * // - 'uuid': UUID as defined by RFC4122
164
+ * // - 'binary': binary data (base64 encoded)
165
+ * // - 'byte': base64 encoded characters
166
+ * // - 'password': hint for UI to obscure input
167
+ *
168
+ * const emailFormat = parseFormat({
169
+ * value: { type: 'string', format: 'email' },
170
+ * valibotSchema: v.string(),
171
+ * context
172
+ * });
173
+ * // Can generate validation: v.pipe(v.string(), v.email())
174
+ * ```
175
+ */
38
176
  const parseFormat = ({ value, valibotSchema, context }) => {
39
177
  const { format, ...rest } = value;
40
178
  const parsedFormat = context.provisionalParse({
@@ -1,12 +1,139 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import type { ParseContext } from '../../context/ParseContext.js';
3
+ /**
4
+ * Arguments for parsing the nullable property from OpenAPI schemas.
5
+ *
6
+ * @template Value - The OpenAPI schema object type
7
+ */
3
8
  export type ParseNullableArgs<Value extends OpenAPIV3.SchemaObject> = {
9
+ /** The OpenAPI schema object containing the nullable property */
4
10
  value: Value;
11
+ /** Parse context for error handling */
5
12
  context: ParseContext;
6
13
  };
14
+ /**
15
+ * Return type for parsed nullable data.
16
+ *
17
+ * @template Value - The OpenAPI schema object type
18
+ */
7
19
  export type ParseNullableReturn<Value extends OpenAPIV3.SchemaObject> = {
20
+ /** The validated nullable flag (true, false, or undefined) */
8
21
  nullable: boolean | undefined;
22
+ /** The schema object without the nullable property */
9
23
  value: Omit<Value, 'nullable'>;
10
24
  };
25
+ /**
26
+ * Parses and validates the nullable property from OpenAPI schema objects.
27
+ *
28
+ * This function extracts and validates the `nullable` property from OpenAPI
29
+ * schema objects, ensuring it's a valid boolean value. Invalid nullable values
30
+ * are removed and logged as warnings through the parse context.
31
+ *
32
+ * The nullable property determines whether a schema value can be null in addition
33
+ * to its primary type, which affects type generation and validation logic.
34
+ *
35
+ * @template Value - The OpenAPI schema object type
36
+ *
37
+ * @param args - Parsing configuration
38
+ * @returns Parsed nullable data with the validated flag and cleaned schema
39
+ *
40
+ * @example Valid nullable property
41
+ * ```typescript
42
+ * import { parseNullable } from '@skmtc/core/oas/_helpers';
43
+ *
44
+ * const result = parseNullable({
45
+ * value: {
46
+ * type: 'string',
47
+ * nullable: true,
48
+ * description: 'An optional string that can be null'
49
+ * },
50
+ * context: parseContext
51
+ * });
52
+ *
53
+ * console.log(result.nullable); // true
54
+ * console.log(result.value); // { type: 'string', description: 'An optional string that can be null' }
55
+ * ```
56
+ *
57
+ * @example Explicitly non-nullable
58
+ * ```typescript
59
+ * const result = parseNullable({
60
+ * value: {
61
+ * type: 'number',
62
+ * nullable: false,
63
+ * minimum: 0
64
+ * },
65
+ * context: parseContext
66
+ * });
67
+ *
68
+ * console.log(result.nullable); // false
69
+ * console.log(result.value); // { type: 'number', minimum: 0 }
70
+ * ```
71
+ *
72
+ * @example Missing nullable property (undefined)
73
+ * ```typescript
74
+ * const result = parseNullable({
75
+ * value: {
76
+ * type: 'string',
77
+ * format: 'email'
78
+ * },
79
+ * context: parseContext
80
+ * });
81
+ *
82
+ * console.log(result.nullable); // undefined (property not present)
83
+ * console.log(result.value); // { type: 'string', format: 'email' }
84
+ * ```
85
+ *
86
+ * @example Invalid nullable value
87
+ * ```typescript
88
+ * const result = parseNullable({
89
+ * value: {
90
+ * type: 'boolean',
91
+ * nullable: 'yes', // Invalid - should be boolean
92
+ * description: 'A flag'
93
+ * } as any,
94
+ * context: parseContext
95
+ * });
96
+ *
97
+ * console.log(result.nullable); // undefined (invalid value removed)
98
+ * console.log(result.value); // { type: 'boolean', description: 'A flag' }
99
+ * // Context will log a warning about the invalid nullable value
100
+ * ```
101
+ *
102
+ * @example Usage in type generation
103
+ * ```typescript
104
+ * function generateTypeScript(schema: OpenAPIV3.SchemaObject) {
105
+ * const { nullable, value } = parseNullable({ value: schema, context });
106
+ *
107
+ * const baseType = generateBaseType(value);
108
+ * const nullableType = nullable ? ` | null` : '';
109
+ *
110
+ * return `${baseType}${nullableType}`;
111
+ * }
112
+ *
113
+ * // Examples:
114
+ * // nullable: true -> 'string | null'
115
+ * // nullable: false -> 'string'
116
+ * // nullable: undefined -> 'string' (default behavior)
117
+ * ```
118
+ *
119
+ * @example Complex schema with nullable
120
+ * ```typescript
121
+ * const result = parseNullable({
122
+ * value: {
123
+ * type: 'object',
124
+ * properties: {
125
+ * name: { type: 'string' },
126
+ * age: { type: 'number' }
127
+ * },
128
+ * required: ['name'],
129
+ * nullable: true // The entire object can be null
130
+ * },
131
+ * context: parseContext
132
+ * });
133
+ *
134
+ * console.log(result.nullable); // true
135
+ * // Generated type might be: { name: string; age?: number } | null
136
+ * ```
137
+ */
11
138
  export declare const parseNullable: <Value extends OpenAPIV3.SchemaObject>({ value, context }: ParseNullableArgs<Value>) => ParseNullableReturn<Value>;
12
139
  //# sourceMappingURL=parseNullable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseNullable.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseNullable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IACpE,KAAK,EAAE,KAAK,CAAA;IACZ,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,MAAM,MAAM,mBAAmB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IACtE,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;CAC/B,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS,SAAS,CAAC,YAAY,EAAE,oBAGjE,iBAAiB,CAAC,KAAK,CAAC,KAAG,mBAAmB,CAAC,KAAK,CAgBtD,CAAA"}
1
+ {"version":3,"file":"parseNullable.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseNullable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AAGjE;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IACpE,iEAAiE;IACjE,KAAK,EAAE,KAAK,CAAA;IACZ,uCAAuC;IACvC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,SAAS,SAAS,CAAC,YAAY,IAAI;IACtE,8DAA8D;IAC9D,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,sDAAsD;IACtD,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;CAC/B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgHG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,SAAS,SAAS,CAAC,YAAY,EAAE,oBAGjE,iBAAiB,CAAC,KAAK,CAAC,KAAG,mBAAmB,CAAC,KAAK,CAgBtD,CAAA"}
@@ -35,6 +35,119 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.parseNullable = void 0;
37
37
  const v = __importStar(require("valibot"));
38
+ /**
39
+ * Parses and validates the nullable property from OpenAPI schema objects.
40
+ *
41
+ * This function extracts and validates the `nullable` property from OpenAPI
42
+ * schema objects, ensuring it's a valid boolean value. Invalid nullable values
43
+ * are removed and logged as warnings through the parse context.
44
+ *
45
+ * The nullable property determines whether a schema value can be null in addition
46
+ * to its primary type, which affects type generation and validation logic.
47
+ *
48
+ * @template Value - The OpenAPI schema object type
49
+ *
50
+ * @param args - Parsing configuration
51
+ * @returns Parsed nullable data with the validated flag and cleaned schema
52
+ *
53
+ * @example Valid nullable property
54
+ * ```typescript
55
+ * import { parseNullable } from '@skmtc/core/oas/_helpers';
56
+ *
57
+ * const result = parseNullable({
58
+ * value: {
59
+ * type: 'string',
60
+ * nullable: true,
61
+ * description: 'An optional string that can be null'
62
+ * },
63
+ * context: parseContext
64
+ * });
65
+ *
66
+ * console.log(result.nullable); // true
67
+ * console.log(result.value); // { type: 'string', description: 'An optional string that can be null' }
68
+ * ```
69
+ *
70
+ * @example Explicitly non-nullable
71
+ * ```typescript
72
+ * const result = parseNullable({
73
+ * value: {
74
+ * type: 'number',
75
+ * nullable: false,
76
+ * minimum: 0
77
+ * },
78
+ * context: parseContext
79
+ * });
80
+ *
81
+ * console.log(result.nullable); // false
82
+ * console.log(result.value); // { type: 'number', minimum: 0 }
83
+ * ```
84
+ *
85
+ * @example Missing nullable property (undefined)
86
+ * ```typescript
87
+ * const result = parseNullable({
88
+ * value: {
89
+ * type: 'string',
90
+ * format: 'email'
91
+ * },
92
+ * context: parseContext
93
+ * });
94
+ *
95
+ * console.log(result.nullable); // undefined (property not present)
96
+ * console.log(result.value); // { type: 'string', format: 'email' }
97
+ * ```
98
+ *
99
+ * @example Invalid nullable value
100
+ * ```typescript
101
+ * const result = parseNullable({
102
+ * value: {
103
+ * type: 'boolean',
104
+ * nullable: 'yes', // Invalid - should be boolean
105
+ * description: 'A flag'
106
+ * } as any,
107
+ * context: parseContext
108
+ * });
109
+ *
110
+ * console.log(result.nullable); // undefined (invalid value removed)
111
+ * console.log(result.value); // { type: 'boolean', description: 'A flag' }
112
+ * // Context will log a warning about the invalid nullable value
113
+ * ```
114
+ *
115
+ * @example Usage in type generation
116
+ * ```typescript
117
+ * function generateTypeScript(schema: OpenAPIV3.SchemaObject) {
118
+ * const { nullable, value } = parseNullable({ value: schema, context });
119
+ *
120
+ * const baseType = generateBaseType(value);
121
+ * const nullableType = nullable ? ` | null` : '';
122
+ *
123
+ * return `${baseType}${nullableType}`;
124
+ * }
125
+ *
126
+ * // Examples:
127
+ * // nullable: true -> 'string | null'
128
+ * // nullable: false -> 'string'
129
+ * // nullable: undefined -> 'string' (default behavior)
130
+ * ```
131
+ *
132
+ * @example Complex schema with nullable
133
+ * ```typescript
134
+ * const result = parseNullable({
135
+ * value: {
136
+ * type: 'object',
137
+ * properties: {
138
+ * name: { type: 'string' },
139
+ * age: { type: 'number' }
140
+ * },
141
+ * required: ['name'],
142
+ * nullable: true // The entire object can be null
143
+ * },
144
+ * context: parseContext
145
+ * });
146
+ *
147
+ * console.log(result.nullable); // true
148
+ * // Generated type might be: { name: string; age?: number } | null
149
+ * ```
150
+ */
38
151
  const parseNullable = ({ value, context }) => {
39
152
  const { nullable, ...rest } = value;
40
153
  const parsedNullable = context.provisionalParse({