@skmtc/core 0.0.796 → 0.0.798

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 (109) 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 +147 -2
  5. package/esm/context/CoreContext.d.ts.map +1 -1
  6. package/esm/context/CoreContext.js +87 -0
  7. package/esm/context/GenerateContext.d.ts +180 -0
  8. package/esm/context/GenerateContext.d.ts.map +1 -1
  9. package/esm/context/GenerateContext.js +25 -0
  10. package/esm/context/ParseContext.d.ts +6 -0
  11. package/esm/context/ParseContext.d.ts.map +1 -1
  12. package/esm/context/ParseContext.js +6 -0
  13. package/esm/dsl/constants.d.ts +28 -0
  14. package/esm/dsl/constants.d.ts.map +1 -1
  15. package/esm/dsl/constants.js +28 -0
  16. package/esm/oas/_helpers/parseDefault.d.ts +148 -0
  17. package/esm/oas/_helpers/parseDefault.d.ts.map +1 -1
  18. package/esm/oas/_helpers/parseDefault.js +128 -0
  19. package/esm/oas/_helpers/parseEnum.d.ts +124 -0
  20. package/esm/oas/_helpers/parseEnum.d.ts.map +1 -1
  21. package/esm/oas/_helpers/parseEnum.js +104 -0
  22. package/esm/oas/_helpers/parseExample.d.ts +107 -0
  23. package/esm/oas/_helpers/parseExample.d.ts.map +1 -1
  24. package/esm/oas/_helpers/parseExample.js +87 -0
  25. package/esm/oas/_helpers/parseFormat.d.ts +154 -0
  26. package/esm/oas/_helpers/parseFormat.d.ts.map +1 -1
  27. package/esm/oas/_helpers/parseFormat.js +138 -0
  28. package/esm/oas/_helpers/parseNullable.d.ts +127 -0
  29. package/esm/oas/_helpers/parseNullable.d.ts.map +1 -1
  30. package/esm/oas/_helpers/parseNullable.js +113 -0
  31. package/esm/oas/example/toExamplesV3.d.ts +39 -0
  32. package/esm/oas/example/toExamplesV3.d.ts.map +1 -1
  33. package/esm/oas/example/toExamplesV3.js +29 -0
  34. package/esm/oas/object/Object.d.ts +6 -0
  35. package/esm/oas/object/Object.d.ts.map +1 -1
  36. package/esm/oas/object/Object.js +6 -0
  37. package/esm/oas/operation/Operation.d.ts +34 -0
  38. package/esm/oas/operation/Operation.d.ts.map +1 -1
  39. package/esm/oas/operation/Operation.js +14 -0
  40. package/esm/oas/parameter/Parameter.d.ts +3 -0
  41. package/esm/oas/parameter/Parameter.d.ts.map +1 -1
  42. package/esm/oas/parameter/Parameter.js +3 -0
  43. package/esm/oas/ref/ref-types.d.ts +42 -0
  44. package/esm/oas/ref/ref-types.d.ts.map +1 -1
  45. package/esm/oas/ref/ref-types.js +9 -0
  46. package/esm/oas/securitySchemes/security-scheme-types.d.ts +63 -0
  47. package/esm/oas/securitySchemes/security-scheme-types.d.ts.map +1 -1
  48. package/esm/oas/securitySchemes/security-scheme-types.js +15 -0
  49. package/esm/run/toV3JsonDocument.d.ts +90 -0
  50. package/esm/run/toV3JsonDocument.d.ts.map +1 -1
  51. package/esm/run/toV3JsonDocument.js +84 -0
  52. package/esm/types/Results.d.ts +32 -0
  53. package/esm/types/Results.d.ts.map +1 -1
  54. package/esm/types/Results.js +12 -0
  55. package/package.json +1 -1
  56. package/script/app/validate.d.ts +32 -0
  57. package/script/app/validate.d.ts.map +1 -1
  58. package/script/app/validate.js +32 -0
  59. package/script/context/CoreContext.d.ts +147 -2
  60. package/script/context/CoreContext.d.ts.map +1 -1
  61. package/script/context/CoreContext.js +87 -0
  62. package/script/context/GenerateContext.d.ts +180 -0
  63. package/script/context/GenerateContext.d.ts.map +1 -1
  64. package/script/context/GenerateContext.js +25 -0
  65. package/script/context/ParseContext.d.ts +6 -0
  66. package/script/context/ParseContext.d.ts.map +1 -1
  67. package/script/context/ParseContext.js +6 -0
  68. package/script/dsl/constants.d.ts +28 -0
  69. package/script/dsl/constants.d.ts.map +1 -1
  70. package/script/dsl/constants.js +28 -0
  71. package/script/oas/_helpers/parseDefault.d.ts +148 -0
  72. package/script/oas/_helpers/parseDefault.d.ts.map +1 -1
  73. package/script/oas/_helpers/parseDefault.js +128 -0
  74. package/script/oas/_helpers/parseEnum.d.ts +124 -0
  75. package/script/oas/_helpers/parseEnum.d.ts.map +1 -1
  76. package/script/oas/_helpers/parseEnum.js +104 -0
  77. package/script/oas/_helpers/parseExample.d.ts +107 -0
  78. package/script/oas/_helpers/parseExample.d.ts.map +1 -1
  79. package/script/oas/_helpers/parseExample.js +87 -0
  80. package/script/oas/_helpers/parseFormat.d.ts +154 -0
  81. package/script/oas/_helpers/parseFormat.d.ts.map +1 -1
  82. package/script/oas/_helpers/parseFormat.js +138 -0
  83. package/script/oas/_helpers/parseNullable.d.ts +127 -0
  84. package/script/oas/_helpers/parseNullable.d.ts.map +1 -1
  85. package/script/oas/_helpers/parseNullable.js +113 -0
  86. package/script/oas/example/toExamplesV3.d.ts +39 -0
  87. package/script/oas/example/toExamplesV3.d.ts.map +1 -1
  88. package/script/oas/example/toExamplesV3.js +29 -0
  89. package/script/oas/object/Object.d.ts +6 -0
  90. package/script/oas/object/Object.d.ts.map +1 -1
  91. package/script/oas/object/Object.js +6 -0
  92. package/script/oas/operation/Operation.d.ts +34 -0
  93. package/script/oas/operation/Operation.d.ts.map +1 -1
  94. package/script/oas/operation/Operation.js +14 -0
  95. package/script/oas/parameter/Parameter.d.ts +3 -0
  96. package/script/oas/parameter/Parameter.d.ts.map +1 -1
  97. package/script/oas/parameter/Parameter.js +3 -0
  98. package/script/oas/ref/ref-types.d.ts +42 -0
  99. package/script/oas/ref/ref-types.d.ts.map +1 -1
  100. package/script/oas/ref/ref-types.js +9 -0
  101. package/script/oas/securitySchemes/security-scheme-types.d.ts +63 -0
  102. package/script/oas/securitySchemes/security-scheme-types.d.ts.map +1 -1
  103. package/script/oas/securitySchemes/security-scheme-types.js +15 -0
  104. package/script/run/toV3JsonDocument.d.ts +90 -0
  105. package/script/run/toV3JsonDocument.d.ts.map +1 -1
  106. package/script/run/toV3JsonDocument.js +84 -0
  107. package/script/types/Results.d.ts +32 -0
  108. package/script/types/Results.d.ts.map +1 -1
  109. package/script/types/Results.js +12 -0
@@ -1,16 +1,140 @@
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 enum values.
6
+ *
7
+ * @template T - The expected type of enum values
8
+ * @template Nullable - Whether the schema allows null values
9
+ * @template Value - The OpenAPI schema object type
10
+ */
4
11
  type ParseEnumArgs<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
12
+ /** The OpenAPI schema object without nullable property */
5
13
  value: Omit<Value, 'nullable'>;
14
+ /** Whether the schema allows null values */
6
15
  nullable: Nullable;
16
+ /** Valibot schema for validating enum values */
7
17
  valibotSchema: v.GenericSchema<T>;
18
+ /** Parse context for error handling */
8
19
  context: ParseContext;
9
20
  };
21
+ /**
22
+ * Return type for parsed enum data.
23
+ *
24
+ * @template T - The expected type of enum values
25
+ * @template Nullable - Whether the schema allows null values
26
+ * @template Value - The OpenAPI schema object type
27
+ */
10
28
  type ParseEnumReturn<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
29
+ /** The parsed and validated enum array */
11
30
  enum: Nullable extends true ? (T | null)[] | undefined : T[] | undefined;
31
+ /** The schema object without enum and nullable properties */
12
32
  value: Omit<Value, 'nullable' | 'enum'>;
13
33
  };
34
+ /**
35
+ * Parses and validates OpenAPI schema enum values with type safety.
36
+ *
37
+ * This function extracts and validates enum arrays from OpenAPI schema objects,
38
+ * ensuring all enum values conform to the expected type and handling nullable
39
+ * schemas correctly. Invalid enum values are removed and logged as warnings
40
+ * through the parse context.
41
+ *
42
+ * The function provides full type safety, with the return type reflecting whether
43
+ * null values are allowed in the enum array based on the nullable parameter.
44
+ *
45
+ * @template T - The expected type of enum values
46
+ * @template Nullable - Whether the schema allows null values in enums
47
+ * @template Value - The OpenAPI schema object type
48
+ *
49
+ * @param args - Parsing configuration
50
+ * @returns Parsed enum data with the validated enum array and cleaned schema
51
+ *
52
+ * @example Basic string enum parsing
53
+ * ```typescript
54
+ * import { parseEnum } from '@skmtc/core/oas/_helpers';
55
+ * import * as v from 'valibot';
56
+ *
57
+ * const result = parseEnum({
58
+ * value: {
59
+ * type: 'string',
60
+ * enum: ['active', 'inactive', 'pending'],
61
+ * description: 'User status'
62
+ * },
63
+ * nullable: false,
64
+ * valibotSchema: v.string(),
65
+ * context: parseContext
66
+ * });
67
+ *
68
+ * console.log(result.enum); // ['active', 'inactive', 'pending']
69
+ * console.log(result.value); // { type: 'string', description: 'User status' }
70
+ * ```
71
+ *
72
+ * @example Nullable enum parsing
73
+ * ```typescript
74
+ * const result = parseEnum({
75
+ * value: {
76
+ * type: 'string',
77
+ * enum: ['red', 'green', 'blue', null],
78
+ * description: 'Optional color selection'
79
+ * },
80
+ * nullable: true,
81
+ * valibotSchema: v.string(),
82
+ * context: parseContext
83
+ * });
84
+ *
85
+ * console.log(result.enum); // ['red', 'green', 'blue', null]
86
+ * // Type: (string | null)[] | undefined
87
+ * ```
88
+ *
89
+ * @example Number enum parsing
90
+ * ```typescript
91
+ * const result = parseEnum({
92
+ * value: {
93
+ * type: 'number',
94
+ * enum: [1, 2, 3, 5, 8, 13],
95
+ * description: 'Fibonacci subset'
96
+ * },
97
+ * nullable: false,
98
+ * valibotSchema: v.number(),
99
+ * context: parseContext
100
+ * });
101
+ *
102
+ * console.log(result.enum); // [1, 2, 3, 5, 8, 13]
103
+ * ```
104
+ *
105
+ * @example Invalid enum handling
106
+ * ```typescript
107
+ * const result = parseEnum({
108
+ * value: {
109
+ * type: 'number',
110
+ * enum: [1, 'invalid', 3], // Contains invalid value
111
+ * description: 'Mixed enum (invalid)'
112
+ * },
113
+ * nullable: false,
114
+ * valibotSchema: v.number(),
115
+ * context: parseContext
116
+ * });
117
+ *
118
+ * console.log(result.enum); // undefined (entire enum removed due to invalid value)
119
+ * // Context will log a warning about the invalid enum
120
+ * ```
121
+ *
122
+ * @example Boolean enum (essentially optional boolean)
123
+ * ```typescript
124
+ * const result = parseEnum({
125
+ * value: {
126
+ * type: 'boolean',
127
+ * enum: [true, false],
128
+ * description: 'Explicit boolean enum'
129
+ * },
130
+ * nullable: false,
131
+ * valibotSchema: v.boolean(),
132
+ * context: parseContext
133
+ * });
134
+ *
135
+ * console.log(result.enum); // [true, false]
136
+ * ```
137
+ */
14
138
  export declare const parseEnum: <T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject>({ value, nullable, valibotSchema, context }: ParseEnumArgs<T, Nullable, Value>) => ParseEnumReturn<T, Nullable, Value>;
15
139
  export {};
16
140
  //# sourceMappingURL=parseEnum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseEnum.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseEnum.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,aAAa,CAChB,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,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,KAAK,eAAe,CAClB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,IAAI,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,CAAC,EAAE,GAA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A6D;IAC7D,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC,CAAA;CACxC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuGG;AACH,eAAO,MAAM,SAAS,GACpB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,EACpC,6CAKC,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAG,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAgBxE,CAAA"}
@@ -1,4 +1,108 @@
1
1
  import * as v from 'valibot';
2
+ /**
3
+ * Parses and validates OpenAPI schema enum values with type safety.
4
+ *
5
+ * This function extracts and validates enum arrays from OpenAPI schema objects,
6
+ * ensuring all enum values conform to the expected type and handling nullable
7
+ * schemas correctly. Invalid enum values are removed and logged as warnings
8
+ * through the parse context.
9
+ *
10
+ * The function provides full type safety, with the return type reflecting whether
11
+ * null values are allowed in the enum array based on the nullable parameter.
12
+ *
13
+ * @template T - The expected type of enum values
14
+ * @template Nullable - Whether the schema allows null values in enums
15
+ * @template Value - The OpenAPI schema object type
16
+ *
17
+ * @param args - Parsing configuration
18
+ * @returns Parsed enum data with the validated enum array and cleaned schema
19
+ *
20
+ * @example Basic string enum parsing
21
+ * ```typescript
22
+ * import { parseEnum } from '@skmtc/core/oas/_helpers';
23
+ * import * as v from 'valibot';
24
+ *
25
+ * const result = parseEnum({
26
+ * value: {
27
+ * type: 'string',
28
+ * enum: ['active', 'inactive', 'pending'],
29
+ * description: 'User status'
30
+ * },
31
+ * nullable: false,
32
+ * valibotSchema: v.string(),
33
+ * context: parseContext
34
+ * });
35
+ *
36
+ * console.log(result.enum); // ['active', 'inactive', 'pending']
37
+ * console.log(result.value); // { type: 'string', description: 'User status' }
38
+ * ```
39
+ *
40
+ * @example Nullable enum parsing
41
+ * ```typescript
42
+ * const result = parseEnum({
43
+ * value: {
44
+ * type: 'string',
45
+ * enum: ['red', 'green', 'blue', null],
46
+ * description: 'Optional color selection'
47
+ * },
48
+ * nullable: true,
49
+ * valibotSchema: v.string(),
50
+ * context: parseContext
51
+ * });
52
+ *
53
+ * console.log(result.enum); // ['red', 'green', 'blue', null]
54
+ * // Type: (string | null)[] | undefined
55
+ * ```
56
+ *
57
+ * @example Number enum parsing
58
+ * ```typescript
59
+ * const result = parseEnum({
60
+ * value: {
61
+ * type: 'number',
62
+ * enum: [1, 2, 3, 5, 8, 13],
63
+ * description: 'Fibonacci subset'
64
+ * },
65
+ * nullable: false,
66
+ * valibotSchema: v.number(),
67
+ * context: parseContext
68
+ * });
69
+ *
70
+ * console.log(result.enum); // [1, 2, 3, 5, 8, 13]
71
+ * ```
72
+ *
73
+ * @example Invalid enum handling
74
+ * ```typescript
75
+ * const result = parseEnum({
76
+ * value: {
77
+ * type: 'number',
78
+ * enum: [1, 'invalid', 3], // Contains invalid value
79
+ * description: 'Mixed enum (invalid)'
80
+ * },
81
+ * nullable: false,
82
+ * valibotSchema: v.number(),
83
+ * context: parseContext
84
+ * });
85
+ *
86
+ * console.log(result.enum); // undefined (entire enum removed due to invalid value)
87
+ * // Context will log a warning about the invalid enum
88
+ * ```
89
+ *
90
+ * @example Boolean enum (essentially optional boolean)
91
+ * ```typescript
92
+ * const result = parseEnum({
93
+ * value: {
94
+ * type: 'boolean',
95
+ * enum: [true, false],
96
+ * description: 'Explicit boolean enum'
97
+ * },
98
+ * nullable: false,
99
+ * valibotSchema: v.boolean(),
100
+ * context: parseContext
101
+ * });
102
+ *
103
+ * console.log(result.enum); // [true, false]
104
+ * ```
105
+ */
2
106
  export const parseEnum = ({ value, nullable, valibotSchema, context }) => {
3
107
  const { enum: enums, ...rest } = value;
4
108
  const parsedEnum = context.provisionalParse({
@@ -1,16 +1,123 @@
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 examples.
6
+ *
7
+ * @template T - The expected type of the example value
8
+ * @template Nullable - Whether the schema allows null values
9
+ * @template Value - The OpenAPI schema object type
10
+ */
4
11
  type ParseExampleArgs<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
12
+ /** The OpenAPI schema object without nullable property */
5
13
  value: Omit<Value, 'nullable'>;
14
+ /** Whether the schema allows null values */
6
15
  nullable: Nullable;
16
+ /** Valibot schema for validating the example */
7
17
  valibotSchema: v.GenericSchema<T>;
18
+ /** Parse context for error handling */
8
19
  context: ParseContext;
9
20
  };
21
+ /**
22
+ * Return type for parsed example data.
23
+ *
24
+ * @template T - The expected type of the example value
25
+ * @template Nullable - Whether the schema allows null values
26
+ * @template Value - The OpenAPI schema object type
27
+ */
10
28
  type ParseExampleReturn<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
29
+ /** The parsed and validated example value */
11
30
  example: Nullable extends true ? T | null | undefined : T | undefined;
31
+ /** The schema object without example and nullable properties */
12
32
  value: Omit<Value, 'nullable' | 'example'>;
13
33
  };
34
+ /**
35
+ * Parses and validates OpenAPI schema examples with type safety.
36
+ *
37
+ * This function extracts and validates example values from OpenAPI schema objects,
38
+ * ensuring they conform to the expected type and handling nullable schemas correctly.
39
+ * Invalid examples are removed and logged as warnings through the parse context.
40
+ *
41
+ * The function provides full type safety, with the return type reflecting whether
42
+ * null values are allowed based on the nullable parameter.
43
+ *
44
+ * @template T - The expected type of the example value
45
+ * @template Nullable - Whether the schema allows null values
46
+ * @template Value - The OpenAPI schema object type
47
+ *
48
+ * @param args - Parsing configuration
49
+ * @returns Parsed example data with the validated example and cleaned schema
50
+ *
51
+ * @example Basic string example parsing
52
+ * ```typescript
53
+ * import { parseExample } from '@skmtc/core/oas/_helpers';
54
+ * import * as v from 'valibot';
55
+ *
56
+ * const result = parseExample({
57
+ * value: {
58
+ * type: 'string',
59
+ * example: 'hello world',
60
+ * format: 'text'
61
+ * },
62
+ * nullable: false,
63
+ * valibotSchema: v.string(),
64
+ * context: parseContext
65
+ * });
66
+ *
67
+ * console.log(result.example); // 'hello world'
68
+ * console.log(result.value); // { type: 'string', format: 'text' }
69
+ * ```
70
+ *
71
+ * @example Nullable schema example
72
+ * ```typescript
73
+ * const result = parseExample({
74
+ * value: {
75
+ * type: 'string',
76
+ * example: null,
77
+ * minLength: 1
78
+ * },
79
+ * nullable: true,
80
+ * valibotSchema: v.string(),
81
+ * context: parseContext
82
+ * });
83
+ *
84
+ * console.log(result.example); // null (valid for nullable schema)
85
+ * // Type: string | null | undefined
86
+ * ```
87
+ *
88
+ * @example Invalid example handling
89
+ * ```typescript
90
+ * const result = parseExample({
91
+ * value: {
92
+ * type: 'number',
93
+ * example: 'not a number', // Invalid example
94
+ * minimum: 0
95
+ * },
96
+ * nullable: false,
97
+ * valibotSchema: v.number(),
98
+ * context: parseContext
99
+ * });
100
+ *
101
+ * console.log(result.example); // undefined (invalid example removed)
102
+ * // Context will log a warning about the invalid example
103
+ * ```
104
+ *
105
+ * @example Array example parsing
106
+ * ```typescript
107
+ * const result = parseExample({
108
+ * value: {
109
+ * type: 'array',
110
+ * items: { type: 'string' },
111
+ * example: ['item1', 'item2', 'item3']
112
+ * },
113
+ * nullable: false,
114
+ * valibotSchema: v.array(v.string()),
115
+ * context: parseContext
116
+ * });
117
+ *
118
+ * console.log(result.example); // ['item1', 'item2', 'item3']
119
+ * ```
120
+ */
14
121
  export declare const parseExample: <T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject>({ value, nullable, valibotSchema, context }: ParseExampleArgs<T, Nullable, Value>) => ParseExampleReturn<T, Nullable, Value>;
15
122
  export {};
16
123
  //# sourceMappingURL=parseExample.d.ts.map
@@ -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,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,OAAO,EAAE,YAAY,CAAA;CACtB,CAAA;AAED,KAAK,kBAAkB,CACrB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,OAAO,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAAA;IACrE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,CAAA;CAC3C,CAAA;AAED,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"}
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;;;;;;GAMG;AACH,KAAK,gBAAgB,CACnB,CAAC,EACD,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,KAAK,SAAS,SAAS,CAAC,YAAY,IAClC;IACF,0DAA0D;IAC1D,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;IAC9B,4CAA4C;IAC5C,QAAQ,EAAE,QAAQ,CAAA;IAClB,gDAAgD;IAChD,aAAa,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAA;IACjC,uCAAuC;IACvC,OAAO,EAAE,YAAY,CAAA;CACtB,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"}
@@ -1,4 +1,91 @@
1
1
  import * as v from 'valibot';
2
+ /**
3
+ * Parses and validates OpenAPI schema examples with type safety.
4
+ *
5
+ * This function extracts and validates example values from OpenAPI schema objects,
6
+ * ensuring they conform to the expected type and handling nullable schemas correctly.
7
+ * Invalid examples are removed and logged as warnings through the parse context.
8
+ *
9
+ * The function provides full type safety, with the return type reflecting whether
10
+ * null values are allowed based on the nullable parameter.
11
+ *
12
+ * @template T - The expected type of the example value
13
+ * @template Nullable - Whether the schema allows null values
14
+ * @template Value - The OpenAPI schema object type
15
+ *
16
+ * @param args - Parsing configuration
17
+ * @returns Parsed example data with the validated example and cleaned schema
18
+ *
19
+ * @example Basic string example parsing
20
+ * ```typescript
21
+ * import { parseExample } from '@skmtc/core/oas/_helpers';
22
+ * import * as v from 'valibot';
23
+ *
24
+ * const result = parseExample({
25
+ * value: {
26
+ * type: 'string',
27
+ * example: 'hello world',
28
+ * format: 'text'
29
+ * },
30
+ * nullable: false,
31
+ * valibotSchema: v.string(),
32
+ * context: parseContext
33
+ * });
34
+ *
35
+ * console.log(result.example); // 'hello world'
36
+ * console.log(result.value); // { type: 'string', format: 'text' }
37
+ * ```
38
+ *
39
+ * @example Nullable schema example
40
+ * ```typescript
41
+ * const result = parseExample({
42
+ * value: {
43
+ * type: 'string',
44
+ * example: null,
45
+ * minLength: 1
46
+ * },
47
+ * nullable: true,
48
+ * valibotSchema: v.string(),
49
+ * context: parseContext
50
+ * });
51
+ *
52
+ * console.log(result.example); // null (valid for nullable schema)
53
+ * // Type: string | null | undefined
54
+ * ```
55
+ *
56
+ * @example Invalid example handling
57
+ * ```typescript
58
+ * const result = parseExample({
59
+ * value: {
60
+ * type: 'number',
61
+ * example: 'not a number', // Invalid example
62
+ * minimum: 0
63
+ * },
64
+ * nullable: false,
65
+ * valibotSchema: v.number(),
66
+ * context: parseContext
67
+ * });
68
+ *
69
+ * console.log(result.example); // undefined (invalid example removed)
70
+ * // Context will log a warning about the invalid example
71
+ * ```
72
+ *
73
+ * @example Array example parsing
74
+ * ```typescript
75
+ * const result = parseExample({
76
+ * value: {
77
+ * type: 'array',
78
+ * items: { type: 'string' },
79
+ * example: ['item1', 'item2', 'item3']
80
+ * },
81
+ * nullable: false,
82
+ * valibotSchema: v.array(v.string()),
83
+ * context: parseContext
84
+ * });
85
+ *
86
+ * console.log(result.example); // ['item1', 'item2', 'item3']
87
+ * ```
88
+ */
2
89
  export const parseExample = ({ value, nullable, valibotSchema, context }) => {
3
90
  const { example, ...rest } = value;
4
91
  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,KAA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