@skmtc/core 0.0.795 → 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 (61) 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/context/ResultsHandler.d.ts +152 -0
  8. package/esm/context/ResultsHandler.d.ts.map +1 -1
  9. package/esm/context/ResultsHandler.js +166 -1
  10. package/esm/dsl/constants.d.ts +28 -0
  11. package/esm/dsl/constants.d.ts.map +1 -1
  12. package/esm/dsl/constants.js +28 -0
  13. package/esm/oas/_helpers/parseDefault.d.ts +148 -0
  14. package/esm/oas/_helpers/parseDefault.d.ts.map +1 -1
  15. package/esm/oas/_helpers/parseDefault.js +128 -0
  16. package/esm/oas/_helpers/parseEnum.d.ts +124 -0
  17. package/esm/oas/_helpers/parseEnum.d.ts.map +1 -1
  18. package/esm/oas/_helpers/parseEnum.js +104 -0
  19. package/esm/oas/_helpers/parseExample.d.ts +107 -0
  20. package/esm/oas/_helpers/parseExample.d.ts.map +1 -1
  21. package/esm/oas/_helpers/parseExample.js +87 -0
  22. package/esm/oas/_helpers/parseFormat.d.ts +154 -0
  23. package/esm/oas/_helpers/parseFormat.d.ts.map +1 -1
  24. package/esm/oas/_helpers/parseFormat.js +138 -0
  25. package/esm/oas/_helpers/parseNullable.d.ts +127 -0
  26. package/esm/oas/_helpers/parseNullable.d.ts.map +1 -1
  27. package/esm/oas/_helpers/parseNullable.js +113 -0
  28. package/esm/run/toV3JsonDocument.d.ts +90 -0
  29. package/esm/run/toV3JsonDocument.d.ts.map +1 -1
  30. package/esm/run/toV3JsonDocument.js +84 -0
  31. package/package.json +1 -1
  32. package/script/app/validate.d.ts +32 -0
  33. package/script/app/validate.d.ts.map +1 -1
  34. package/script/app/validate.js +32 -0
  35. package/script/context/CoreContext.d.ts +137 -1
  36. package/script/context/CoreContext.d.ts.map +1 -1
  37. package/script/context/CoreContext.js +87 -0
  38. package/script/context/ResultsHandler.d.ts +152 -0
  39. package/script/context/ResultsHandler.d.ts.map +1 -1
  40. package/script/context/ResultsHandler.js +166 -1
  41. package/script/dsl/constants.d.ts +28 -0
  42. package/script/dsl/constants.d.ts.map +1 -1
  43. package/script/dsl/constants.js +28 -0
  44. package/script/oas/_helpers/parseDefault.d.ts +148 -0
  45. package/script/oas/_helpers/parseDefault.d.ts.map +1 -1
  46. package/script/oas/_helpers/parseDefault.js +128 -0
  47. package/script/oas/_helpers/parseEnum.d.ts +124 -0
  48. package/script/oas/_helpers/parseEnum.d.ts.map +1 -1
  49. package/script/oas/_helpers/parseEnum.js +104 -0
  50. package/script/oas/_helpers/parseExample.d.ts +107 -0
  51. package/script/oas/_helpers/parseExample.d.ts.map +1 -1
  52. package/script/oas/_helpers/parseExample.js +87 -0
  53. package/script/oas/_helpers/parseFormat.d.ts +154 -0
  54. package/script/oas/_helpers/parseFormat.d.ts.map +1 -1
  55. package/script/oas/_helpers/parseFormat.js +138 -0
  56. package/script/oas/_helpers/parseNullable.d.ts +127 -0
  57. package/script/oas/_helpers/parseNullable.d.ts.map +1 -1
  58. package/script/oas/_helpers/parseNullable.js +113 -0
  59. package/script/run/toV3JsonDocument.d.ts +90 -0
  60. package/script/run/toV3JsonDocument.d.ts.map +1 -1
  61. package/script/run/toV3JsonDocument.js +84 -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,GAAG,SAAS,CAAA;IACxE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC,CAAA;CACxC,CAAA;AAED,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
+ {"version":3,"file":"parseEnum.d.ts","s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AE,QAAQ,EAAE,KAAK,CAAC,KAAG,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAgBxE,CAAA"}
@@ -35,6 +35,110 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.parseEnum = void 0;
37
37
  const v = __importStar(require("valibot"));
38
+ /**
39
+ * Parses and validates OpenAPI schema enum values with type safety.
40
+ *
41
+ * This function extracts and validates enum arrays from OpenAPI schema objects,
42
+ * ensuring all enum values conform to the expected type and handling nullable
43
+ * schemas correctly. Invalid enum values are removed and logged as warnings
44
+ * through the parse context.
45
+ *
46
+ * The function provides full type safety, with the return type reflecting whether
47
+ * null values are allowed in the enum array based on the nullable parameter.
48
+ *
49
+ * @template T - The expected type of enum values
50
+ * @template Nullable - Whether the schema allows null values in enums
51
+ * @template Value - The OpenAPI schema object type
52
+ *
53
+ * @param args - Parsing configuration
54
+ * @returns Parsed enum data with the validated enum array and cleaned schema
55
+ *
56
+ * @example Basic string enum parsing
57
+ * ```typescript
58
+ * import { parseEnum } from '@skmtc/core/oas/_helpers';
59
+ * import * as v from 'valibot';
60
+ *
61
+ * const result = parseEnum({
62
+ * value: {
63
+ * type: 'string',
64
+ * enum: ['active', 'inactive', 'pending'],
65
+ * description: 'User status'
66
+ * },
67
+ * nullable: false,
68
+ * valibotSchema: v.string(),
69
+ * context: parseContext
70
+ * });
71
+ *
72
+ * console.log(result.enum); // ['active', 'inactive', 'pending']
73
+ * console.log(result.value); // { type: 'string', description: 'User status' }
74
+ * ```
75
+ *
76
+ * @example Nullable enum parsing
77
+ * ```typescript
78
+ * const result = parseEnum({
79
+ * value: {
80
+ * type: 'string',
81
+ * enum: ['red', 'green', 'blue', null],
82
+ * description: 'Optional color selection'
83
+ * },
84
+ * nullable: true,
85
+ * valibotSchema: v.string(),
86
+ * context: parseContext
87
+ * });
88
+ *
89
+ * console.log(result.enum); // ['red', 'green', 'blue', null]
90
+ * // Type: (string | null)[] | undefined
91
+ * ```
92
+ *
93
+ * @example Number enum parsing
94
+ * ```typescript
95
+ * const result = parseEnum({
96
+ * value: {
97
+ * type: 'number',
98
+ * enum: [1, 2, 3, 5, 8, 13],
99
+ * description: 'Fibonacci subset'
100
+ * },
101
+ * nullable: false,
102
+ * valibotSchema: v.number(),
103
+ * context: parseContext
104
+ * });
105
+ *
106
+ * console.log(result.enum); // [1, 2, 3, 5, 8, 13]
107
+ * ```
108
+ *
109
+ * @example Invalid enum handling
110
+ * ```typescript
111
+ * const result = parseEnum({
112
+ * value: {
113
+ * type: 'number',
114
+ * enum: [1, 'invalid', 3], // Contains invalid value
115
+ * description: 'Mixed enum (invalid)'
116
+ * },
117
+ * nullable: false,
118
+ * valibotSchema: v.number(),
119
+ * context: parseContext
120
+ * });
121
+ *
122
+ * console.log(result.enum); // undefined (entire enum removed due to invalid value)
123
+ * // Context will log a warning about the invalid enum
124
+ * ```
125
+ *
126
+ * @example Boolean enum (essentially optional boolean)
127
+ * ```typescript
128
+ * const result = parseEnum({
129
+ * value: {
130
+ * type: 'boolean',
131
+ * enum: [true, false],
132
+ * description: 'Explicit boolean enum'
133
+ * },
134
+ * nullable: false,
135
+ * valibotSchema: v.boolean(),
136
+ * context: parseContext
137
+ * });
138
+ *
139
+ * console.log(result.enum); // [true, false]
140
+ * ```
141
+ */
38
142
  const parseEnum = ({ value, nullable, valibotSchema, context }) => {
39
143
  const { enum: enums, ...rest } = value;
40
144
  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,CA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,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"}
@@ -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,OA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