@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
@@ -10,25 +10,143 @@ exports.ResultsHandler = void 0;
10
10
  const levels_js_1 = require("../deps/jsr.io/@std/log/0.224.14/levels.js");
11
11
  const base_handler_js_1 = require("../deps/jsr.io/@std/log/0.224.14/base_handler.js");
12
12
  const ts_pattern_1 = require("ts-pattern");
13
+ /**
14
+ * Custom log handler that captures warning and error results for SKMTC processing.
15
+ *
16
+ * The `ResultsHandler` extends Deno's standard library BaseHandler to provide
17
+ * specialized logging behavior for the SKMTC pipeline. It integrates with the
18
+ * CoreContext to capture warnings and errors as structured results that can be
19
+ * analyzed and reported after processing completes.
20
+ *
21
+ * This handler ensures that important processing issues are captured and stored
22
+ * in the context's results system rather than just being logged to the console.
23
+ *
24
+ * ## Key Features
25
+ *
26
+ * - **Result Capture**: Automatically captures WARN and ERROR logs as results
27
+ * - **Immediate Flushing**: Critical errors trigger immediate flush
28
+ * - **Lifecycle Management**: Proper setup and cleanup with event handlers
29
+ * - **Context Integration**: Seamlessly integrates with CoreContext results system
30
+ *
31
+ * @example Setting up the handler
32
+ * ```typescript
33
+ * import { getLogger } from '@std/log';
34
+ * import { ResultsHandler, CoreContext } from '@skmtc/core';
35
+ *
36
+ * const context = new CoreContext({
37
+ * // ... context options
38
+ * });
39
+ *
40
+ * const handler = new ResultsHandler('WARN', {
41
+ * context: context,
42
+ * formatter: '[{levelName}] {msg}'
43
+ * });
44
+ *
45
+ * const logger = getLogger();
46
+ * logger.addHandler(handler);
47
+ *
48
+ * // Now warnings and errors will be captured as results
49
+ * logger.warning('Schema validation issue detected');
50
+ * logger.error('Failed to process operation');
51
+ * ```
52
+ *
53
+ * @example Integration in pipeline
54
+ * ```typescript
55
+ * class ProcessingPipeline {
56
+ * async process(document: OasDocument) {
57
+ * const context = new CoreContext(options);
58
+ *
59
+ * // Set up results handler
60
+ * const handler = new ResultsHandler('WARN', { context });
61
+ * const logger = getLogger();
62
+ * logger.addHandler(handler);
63
+ *
64
+ * try {
65
+ * const result = await this.processDocument(document, context);
66
+ *
67
+ * // Check captured results
68
+ * if (context.results.hasWarnings()) {
69
+ * console.log('Processing completed with warnings');
70
+ * }
71
+ *
72
+ * return result;
73
+ * } finally {
74
+ * handler.destroy();
75
+ * }
76
+ * }
77
+ * }
78
+ * ```
79
+ */
13
80
  class ResultsHandler extends base_handler_js_1.BaseHandler {
81
+ /**
82
+ * Creates a new ResultsHandler instance.
83
+ *
84
+ * @param levelName - The minimum log level to handle
85
+ * @param options - Handler configuration including CoreContext
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const context = new CoreContext(contextOptions);
90
+ * const handler = new ResultsHandler('WARN', {
91
+ * context,
92
+ * formatter: '[{levelName}] {msg}'
93
+ * });
94
+ * ```
95
+ */
14
96
  constructor(levelName, options) {
15
97
  super(levelName, options);
16
98
  _ResultsHandler_instances.add(this);
99
+ /** The CoreContext instance for capturing results */
17
100
  Object.defineProperty(this, "context", {
18
101
  enumerable: true,
19
102
  configurable: true,
20
103
  writable: true,
21
104
  value: void 0
22
105
  });
106
+ /** Bound callback for cleanup on process unload */
23
107
  _ResultsHandler_unloadCallback.set(this, (() => {
24
108
  this.destroy();
25
- }).bind(this));
109
+ }).bind(this)
110
+ /**
111
+ * Creates a new ResultsHandler instance.
112
+ *
113
+ * @param levelName - The minimum log level to handle
114
+ * @param options - Handler configuration including CoreContext
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const context = new CoreContext(contextOptions);
119
+ * const handler = new ResultsHandler('WARN', {
120
+ * context,
121
+ * formatter: '[{levelName}] {msg}'
122
+ * });
123
+ * ```
124
+ */
125
+ );
26
126
  this.context = options.context;
27
127
  }
128
+ /**
129
+ * Sets up the handler with event listeners.
130
+ *
131
+ * Registers cleanup callbacks for process termination to ensure
132
+ * proper resource cleanup and result flushing.
133
+ *
134
+ * @override
135
+ */
28
136
  setup() {
29
137
  __classPrivateFieldGet(this, _ResultsHandler_instances, "m", _ResultsHandler_resetBuffer).call(this);
30
138
  addEventListener('unload', __classPrivateFieldGet(this, _ResultsHandler_unloadCallback, "f"));
31
139
  }
140
+ /**
141
+ * Handles incoming log records.
142
+ *
143
+ * Processes log records through the base handler and triggers
144
+ * immediate flushing for critical errors above ERROR level.
145
+ *
146
+ * @param logRecord - The log record to handle
147
+ *
148
+ * @override
149
+ */
32
150
  handle(logRecord) {
33
151
  super.handle(logRecord);
34
152
  // Immediately flush if log level is higher than ERROR
@@ -36,6 +154,23 @@ class ResultsHandler extends base_handler_js_1.BaseHandler {
36
154
  this.flush();
37
155
  }
38
156
  }
157
+ /**
158
+ * Captures log messages as results in the context.
159
+ *
160
+ * Converts log level names to result types and captures them
161
+ * in the associated CoreContext for later analysis.
162
+ *
163
+ * @param levelName - The log level name ('WARN' or 'ERROR')
164
+ *
165
+ * @throws {Error} When an unsupported log level is provided
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * // This is called automatically by the logging system
170
+ * handler.log('WARN'); // Captures as 'warning' result
171
+ * handler.log('ERROR'); // Captures as 'error' result
172
+ * ```
173
+ */
39
174
  log(levelName) {
40
175
  this.context.captureCurrentResult((0, ts_pattern_1.match)(levelName)
41
176
  .with('WARN', () => 'warning')
@@ -44,9 +179,39 @@ class ResultsHandler extends base_handler_js_1.BaseHandler {
44
179
  throw new Error(`Unexpected log level name: ${levelName}`);
45
180
  }));
46
181
  }
182
+ /**
183
+ * Flushes any buffered content.
184
+ *
185
+ * This implementation resets the internal buffer. Override
186
+ * this method in subclasses to implement custom flushing behavior.
187
+ *
188
+ * @override
189
+ */
47
190
  flush() {
48
191
  __classPrivateFieldGet(this, _ResultsHandler_instances, "m", _ResultsHandler_resetBuffer).call(this);
49
192
  }
193
+ /**
194
+ * Destroys the handler and cleans up resources.
195
+ *
196
+ * Flushes any remaining content and removes event listeners
197
+ * to prevent memory leaks.
198
+ *
199
+ * @override
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const handler = new ResultsHandler('WARN', { context });
204
+ *
205
+ * try {
206
+ * // Use handler
207
+ * logger.addHandler(handler);
208
+ * await processDocument();
209
+ * } finally {
210
+ * // Always clean up
211
+ * handler.destroy();
212
+ * }
213
+ * ```
214
+ */
50
215
  destroy() {
51
216
  this.flush();
52
217
  removeEventListener('unload', __classPrivateFieldGet(this, _ResultsHandler_unloadCallback, "f"));
@@ -1,2 +1,30 @@
1
+ /**
2
+ * Marker constant representing an empty or unset value in the SKMTC DSL system.
3
+ *
4
+ * This constant is used throughout the DSL to represent placeholders, empty
5
+ * templates, or uninitialized content. It provides a consistent way to identify
6
+ * empty states that need to be handled during code generation.
7
+ *
8
+ * @example Usage in templates
9
+ * ```typescript
10
+ * import { EMPTY } from '@skmtc/core';
11
+ *
12
+ * const template = someCondition ? 'actual content' : EMPTY;
13
+ *
14
+ * if (template === EMPTY) {
15
+ * // Handle empty state
16
+ * console.log('No content to generate');
17
+ * }
18
+ * ```
19
+ *
20
+ * @example DSL content generation
21
+ * ```typescript
22
+ * const content = new List([
23
+ * 'import { User } from "./types";',
24
+ * someFeature ? 'import { Admin } from "./admin";' : EMPTY,
25
+ * 'export { User };'
26
+ * ]).filter(line => line !== EMPTY);
27
+ * ```
28
+ */
1
29
  export declare const EMPTY = "__EMPTY__";
2
30
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/dsl/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,cAAc,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/dsl/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,KAAK,cAAc,CAAA"}
@@ -1,4 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EMPTY = void 0;
4
+ /**
5
+ * Marker constant representing an empty or unset value in the SKMTC DSL system.
6
+ *
7
+ * This constant is used throughout the DSL to represent placeholders, empty
8
+ * templates, or uninitialized content. It provides a consistent way to identify
9
+ * empty states that need to be handled during code generation.
10
+ *
11
+ * @example Usage in templates
12
+ * ```typescript
13
+ * import { EMPTY } from '@skmtc/core';
14
+ *
15
+ * const template = someCondition ? 'actual content' : EMPTY;
16
+ *
17
+ * if (template === EMPTY) {
18
+ * // Handle empty state
19
+ * console.log('No content to generate');
20
+ * }
21
+ * ```
22
+ *
23
+ * @example DSL content generation
24
+ * ```typescript
25
+ * const content = new List([
26
+ * 'import { User } from "./types";',
27
+ * someFeature ? 'import { Admin } from "./admin";' : EMPTY,
28
+ * 'export { User };'
29
+ * ]).filter(line => line !== EMPTY);
30
+ * ```
31
+ */
4
32
  exports.EMPTY = '__EMPTY__';
@@ -1,16 +1,164 @@
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 default values.
6
+ *
7
+ * @template T - The expected type of the default value
8
+ * @template Nullable - Whether the schema allows null values
9
+ * @template Value - The OpenAPI schema object type
10
+ */
4
11
  type ParseDefaultArgs<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
12
+ /** The OpenAPI schema object without nullable, example, and enum properties */
5
13
  value: Omit<Value, 'nullable' | 'example' | 'enum'>;
14
+ /** Whether the schema allows null values */
6
15
  nullable: Nullable;
16
+ /** Valibot schema for validating the default value */
7
17
  valibotSchema: v.GenericSchema<T>;
18
+ /** Parse context for error handling */
8
19
  context: ParseContext;
9
20
  };
21
+ /**
22
+ * Return type for parsed default value data.
23
+ *
24
+ * @template T - The expected type of the default value
25
+ * @template Nullable - Whether the schema allows null values
26
+ * @template Value - The OpenAPI schema object type
27
+ */
10
28
  type ParseDefaultReturn<T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject> = {
29
+ /** The parsed and validated default value */
11
30
  default: Nullable extends true ? T | null | undefined : T | undefined;
31
+ /** The schema object with all processed properties removed */
12
32
  value: Omit<Value, 'nullable' | 'example' | 'enum' | 'default'>;
13
33
  };
34
+ /**
35
+ * Parses and validates OpenAPI schema default values with type safety.
36
+ *
37
+ * This function extracts and validates default values from OpenAPI schema objects,
38
+ * ensuring they conform to the expected type and handling nullable schemas correctly.
39
+ * Invalid default values 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. This ensures that
43
+ * generated code maintains proper type constraints for default values.
44
+ *
45
+ * @template T - The expected type of the default value
46
+ * @template Nullable - Whether the schema allows null as a default
47
+ * @template Value - The OpenAPI schema object type
48
+ *
49
+ * @param args - Parsing configuration
50
+ * @returns Parsed default data with the validated default value and cleaned schema
51
+ *
52
+ * @example Basic string default parsing
53
+ * ```typescript
54
+ * import { parseDefault } from '@skmtc/core/oas/_helpers';
55
+ * import * as v from 'valibot';
56
+ *
57
+ * const result = parseDefault({
58
+ * value: {
59
+ * type: 'string',
60
+ * default: 'hello world',
61
+ * minLength: 5
62
+ * },
63
+ * nullable: false,
64
+ * valibotSchema: v.string(),
65
+ * context: parseContext
66
+ * });
67
+ *
68
+ * console.log(result.default); // 'hello world'
69
+ * console.log(result.value); // { type: 'string', minLength: 5 }
70
+ * ```
71
+ *
72
+ * @example Nullable default value
73
+ * ```typescript
74
+ * const result = parseDefault({
75
+ * value: {
76
+ * type: 'string',
77
+ * default: null,
78
+ * format: 'email'
79
+ * },
80
+ * nullable: true,
81
+ * valibotSchema: v.string(),
82
+ * context: parseContext
83
+ * });
84
+ *
85
+ * console.log(result.default); // null (valid for nullable schema)
86
+ * // Type: string | null | undefined
87
+ * ```
88
+ *
89
+ * @example Number default with constraints
90
+ * ```typescript
91
+ * const result = parseDefault({
92
+ * value: {
93
+ * type: 'number',
94
+ * default: 42,
95
+ * minimum: 0,
96
+ * maximum: 100
97
+ * },
98
+ * nullable: false,
99
+ * valibotSchema: v.number(),
100
+ * context: parseContext
101
+ * });
102
+ *
103
+ * console.log(result.default); // 42
104
+ * console.log(result.value); // { type: 'number', minimum: 0, maximum: 100 }
105
+ * ```
106
+ *
107
+ * @example Invalid default handling
108
+ * ```typescript
109
+ * const result = parseDefault({
110
+ * value: {
111
+ * type: 'boolean',
112
+ * default: 'not a boolean', // Invalid default
113
+ * description: 'A boolean flag'
114
+ * },
115
+ * nullable: false,
116
+ * valibotSchema: v.boolean(),
117
+ * context: parseContext
118
+ * });
119
+ *
120
+ * console.log(result.default); // undefined (invalid default removed)
121
+ * // Context will log a warning about the invalid default
122
+ * ```
123
+ *
124
+ * @example Array default value
125
+ * ```typescript
126
+ * const result = parseDefault({
127
+ * value: {
128
+ * type: 'array',
129
+ * items: { type: 'string' },
130
+ * default: ['item1', 'item2']
131
+ * },
132
+ * nullable: false,
133
+ * valibotSchema: v.array(v.string()),
134
+ * context: parseContext
135
+ * });
136
+ *
137
+ * console.log(result.default); // ['item1', 'item2']
138
+ * ```
139
+ *
140
+ * @example Object default value
141
+ * ```typescript
142
+ * const result = parseDefault({
143
+ * value: {
144
+ * type: 'object',
145
+ * properties: {
146
+ * name: { type: 'string' },
147
+ * age: { type: 'number' }
148
+ * },
149
+ * default: { name: 'John', age: 30 }
150
+ * },
151
+ * nullable: false,
152
+ * valibotSchema: v.object({
153
+ * name: v.string(),
154
+ * age: v.number()
155
+ * }),
156
+ * context: parseContext
157
+ * });
158
+ *
159
+ * console.log(result.default); // { name: 'John', age: 30 }
160
+ * ```
161
+ */
14
162
  export declare const parseDefault: <T, Nullable extends boolean | undefined, Value extends OpenAPIV3.SchemaObject>({ value, nullable, valibotSchema, context }: ParseDefaultArgs<T, Nullable, Value>) => ParseDefaultReturn<T, Nullable, Value>;
15
163
  export {};
16
164
  //# sourceMappingURL=parseDefault.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseDefault.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseDefault.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,GAAG,SAAS,GAAG,MAAM,CAAC,CAAA;IACnD,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,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;CAChE,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":"parseDefault.d.ts","sourceRoot":"","sources":["../../../src/oas/_helpers/parseDefault.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,+EAA+E;IAC/E,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC,CAAA;IACnD,4CAA4C;IAC5C,QAAQ,EAAE,QAAQ,CAAA;IAClB,sDAAsD;IACtD,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,8DAA8D;IAC9D,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;CAChE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+HG;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,134 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.parseDefault = void 0;
37
37
  const v = __importStar(require("valibot"));
38
+ /**
39
+ * Parses and validates OpenAPI schema default values with type safety.
40
+ *
41
+ * This function extracts and validates default values from OpenAPI schema objects,
42
+ * ensuring they conform to the expected type and handling nullable schemas correctly.
43
+ * Invalid default values 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. This ensures that
47
+ * generated code maintains proper type constraints for default values.
48
+ *
49
+ * @template T - The expected type of the default value
50
+ * @template Nullable - Whether the schema allows null as a default
51
+ * @template Value - The OpenAPI schema object type
52
+ *
53
+ * @param args - Parsing configuration
54
+ * @returns Parsed default data with the validated default value and cleaned schema
55
+ *
56
+ * @example Basic string default parsing
57
+ * ```typescript
58
+ * import { parseDefault } from '@skmtc/core/oas/_helpers';
59
+ * import * as v from 'valibot';
60
+ *
61
+ * const result = parseDefault({
62
+ * value: {
63
+ * type: 'string',
64
+ * default: 'hello world',
65
+ * minLength: 5
66
+ * },
67
+ * nullable: false,
68
+ * valibotSchema: v.string(),
69
+ * context: parseContext
70
+ * });
71
+ *
72
+ * console.log(result.default); // 'hello world'
73
+ * console.log(result.value); // { type: 'string', minLength: 5 }
74
+ * ```
75
+ *
76
+ * @example Nullable default value
77
+ * ```typescript
78
+ * const result = parseDefault({
79
+ * value: {
80
+ * type: 'string',
81
+ * default: null,
82
+ * format: 'email'
83
+ * },
84
+ * nullable: true,
85
+ * valibotSchema: v.string(),
86
+ * context: parseContext
87
+ * });
88
+ *
89
+ * console.log(result.default); // null (valid for nullable schema)
90
+ * // Type: string | null | undefined
91
+ * ```
92
+ *
93
+ * @example Number default with constraints
94
+ * ```typescript
95
+ * const result = parseDefault({
96
+ * value: {
97
+ * type: 'number',
98
+ * default: 42,
99
+ * minimum: 0,
100
+ * maximum: 100
101
+ * },
102
+ * nullable: false,
103
+ * valibotSchema: v.number(),
104
+ * context: parseContext
105
+ * });
106
+ *
107
+ * console.log(result.default); // 42
108
+ * console.log(result.value); // { type: 'number', minimum: 0, maximum: 100 }
109
+ * ```
110
+ *
111
+ * @example Invalid default handling
112
+ * ```typescript
113
+ * const result = parseDefault({
114
+ * value: {
115
+ * type: 'boolean',
116
+ * default: 'not a boolean', // Invalid default
117
+ * description: 'A boolean flag'
118
+ * },
119
+ * nullable: false,
120
+ * valibotSchema: v.boolean(),
121
+ * context: parseContext
122
+ * });
123
+ *
124
+ * console.log(result.default); // undefined (invalid default removed)
125
+ * // Context will log a warning about the invalid default
126
+ * ```
127
+ *
128
+ * @example Array default value
129
+ * ```typescript
130
+ * const result = parseDefault({
131
+ * value: {
132
+ * type: 'array',
133
+ * items: { type: 'string' },
134
+ * default: ['item1', 'item2']
135
+ * },
136
+ * nullable: false,
137
+ * valibotSchema: v.array(v.string()),
138
+ * context: parseContext
139
+ * });
140
+ *
141
+ * console.log(result.default); // ['item1', 'item2']
142
+ * ```
143
+ *
144
+ * @example Object default value
145
+ * ```typescript
146
+ * const result = parseDefault({
147
+ * value: {
148
+ * type: 'object',
149
+ * properties: {
150
+ * name: { type: 'string' },
151
+ * age: { type: 'number' }
152
+ * },
153
+ * default: { name: 'John', age: 30 }
154
+ * },
155
+ * nullable: false,
156
+ * valibotSchema: v.object({
157
+ * name: v.string(),
158
+ * age: v.number()
159
+ * }),
160
+ * context: parseContext
161
+ * });
162
+ *
163
+ * console.log(result.default); // { name: 'John', age: 30 }
164
+ * ```
165
+ */
38
166
  const parseDefault = ({ value, nullable, valibotSchema, context }) => {
39
167
  const { default: defaultValue, ...rest } = value;
40
168
  const parsedDefault = context.provisionalParse({