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