@skmtc/core 0.0.791 → 0.0.793

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 (113) hide show
  1. package/esm/dsl/GeneratedValueList.d.ts +158 -0
  2. package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
  3. package/esm/dsl/GeneratedValueList.js +158 -0
  4. package/esm/dsl/Stringable.d.ts +76 -0
  5. package/esm/dsl/Stringable.d.ts.map +1 -1
  6. package/esm/dsl/Stringable.js +75 -0
  7. package/esm/helpers/collateExamples.d.ts +150 -0
  8. package/esm/helpers/collateExamples.d.ts.map +1 -1
  9. package/esm/helpers/collateExamples.js +145 -0
  10. package/esm/helpers/formatNumber.d.ts +95 -0
  11. package/esm/helpers/formatNumber.d.ts.map +1 -1
  12. package/esm/helpers/formatNumber.js +95 -0
  13. package/esm/helpers/generationStats.d.ts +287 -1
  14. package/esm/helpers/generationStats.d.ts.map +1 -1
  15. package/esm/helpers/generationStats.js +266 -0
  16. package/esm/helpers/isEmpty.d.ts +62 -0
  17. package/esm/helpers/isEmpty.d.ts.map +1 -1
  18. package/esm/helpers/isEmpty.js +62 -0
  19. package/esm/helpers/isImported.d.ts +80 -0
  20. package/esm/helpers/isImported.d.ts.map +1 -1
  21. package/esm/helpers/isImported.js +80 -0
  22. package/esm/helpers/naming.d.ts +65 -1
  23. package/esm/helpers/naming.d.ts.map +1 -1
  24. package/esm/helpers/naming.js +65 -1
  25. package/esm/helpers/parseModuleName.d.ts +175 -0
  26. package/esm/helpers/parseModuleName.d.ts.map +1 -1
  27. package/esm/helpers/parseModuleName.js +153 -0
  28. package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
  29. package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  30. package/esm/helpers/toResolvedArtifactPath.js +140 -0
  31. package/esm/oas/example/Example.d.ts +81 -1
  32. package/esm/oas/example/Example.d.ts.map +1 -1
  33. package/esm/oas/example/Example.js +74 -1
  34. package/esm/oas/header/Header.d.ts +217 -1
  35. package/esm/oas/header/Header.d.ts.map +1 -1
  36. package/esm/oas/header/Header.js +207 -1
  37. package/esm/oas/info/Info.d.ts +72 -0
  38. package/esm/oas/info/Info.d.ts.map +1 -1
  39. package/esm/oas/info/Info.js +62 -0
  40. package/esm/oas/mediaType/MediaType.d.ts +85 -0
  41. package/esm/oas/mediaType/MediaType.d.ts.map +1 -1
  42. package/esm/oas/mediaType/MediaType.js +77 -0
  43. package/esm/oas/pathItem/PathItem.d.ts +92 -0
  44. package/esm/oas/pathItem/PathItem.d.ts.map +1 -1
  45. package/esm/oas/pathItem/PathItem.js +85 -0
  46. package/esm/oas/requestBody/RequestBody.d.ts +264 -0
  47. package/esm/oas/requestBody/RequestBody.d.ts.map +1 -1
  48. package/esm/oas/requestBody/RequestBody.js +257 -0
  49. package/esm/oas/schema/Schema.d.ts +117 -0
  50. package/esm/oas/schema/Schema.d.ts.map +1 -1
  51. package/esm/typescript/identifiers.d.ts +159 -0
  52. package/esm/typescript/identifiers.d.ts.map +1 -1
  53. package/esm/typescript/identifiers.js +159 -0
  54. package/esm/typescript/withDescription.d.ts +119 -0
  55. package/esm/typescript/withDescription.d.ts.map +1 -1
  56. package/esm/typescript/withDescription.js +119 -0
  57. package/package.json +1 -1
  58. package/script/dsl/GeneratedValueList.d.ts +158 -0
  59. package/script/dsl/GeneratedValueList.d.ts.map +1 -1
  60. package/script/dsl/GeneratedValueList.js +158 -0
  61. package/script/dsl/Stringable.d.ts +76 -0
  62. package/script/dsl/Stringable.d.ts.map +1 -1
  63. package/script/dsl/Stringable.js +75 -0
  64. package/script/helpers/collateExamples.d.ts +150 -0
  65. package/script/helpers/collateExamples.d.ts.map +1 -1
  66. package/script/helpers/collateExamples.js +145 -0
  67. package/script/helpers/formatNumber.d.ts +95 -0
  68. package/script/helpers/formatNumber.d.ts.map +1 -1
  69. package/script/helpers/formatNumber.js +95 -0
  70. package/script/helpers/generationStats.d.ts +287 -1
  71. package/script/helpers/generationStats.d.ts.map +1 -1
  72. package/script/helpers/generationStats.js +266 -0
  73. package/script/helpers/isEmpty.d.ts +62 -0
  74. package/script/helpers/isEmpty.d.ts.map +1 -1
  75. package/script/helpers/isEmpty.js +62 -0
  76. package/script/helpers/isImported.d.ts +80 -0
  77. package/script/helpers/isImported.d.ts.map +1 -1
  78. package/script/helpers/isImported.js +80 -0
  79. package/script/helpers/naming.d.ts +65 -1
  80. package/script/helpers/naming.d.ts.map +1 -1
  81. package/script/helpers/naming.js +65 -1
  82. package/script/helpers/parseModuleName.d.ts +175 -0
  83. package/script/helpers/parseModuleName.d.ts.map +1 -1
  84. package/script/helpers/parseModuleName.js +153 -0
  85. package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
  86. package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  87. package/script/helpers/toResolvedArtifactPath.js +140 -0
  88. package/script/oas/example/Example.d.ts +81 -1
  89. package/script/oas/example/Example.d.ts.map +1 -1
  90. package/script/oas/example/Example.js +74 -1
  91. package/script/oas/header/Header.d.ts +217 -1
  92. package/script/oas/header/Header.d.ts.map +1 -1
  93. package/script/oas/header/Header.js +207 -1
  94. package/script/oas/info/Info.d.ts +72 -0
  95. package/script/oas/info/Info.d.ts.map +1 -1
  96. package/script/oas/info/Info.js +62 -0
  97. package/script/oas/mediaType/MediaType.d.ts +85 -0
  98. package/script/oas/mediaType/MediaType.d.ts.map +1 -1
  99. package/script/oas/mediaType/MediaType.js +77 -0
  100. package/script/oas/pathItem/PathItem.d.ts +92 -0
  101. package/script/oas/pathItem/PathItem.d.ts.map +1 -1
  102. package/script/oas/pathItem/PathItem.js +85 -0
  103. package/script/oas/requestBody/RequestBody.d.ts +264 -0
  104. package/script/oas/requestBody/RequestBody.d.ts.map +1 -1
  105. package/script/oas/requestBody/RequestBody.js +257 -0
  106. package/script/oas/schema/Schema.d.ts +117 -0
  107. package/script/oas/schema/Schema.d.ts.map +1 -1
  108. package/script/typescript/identifiers.d.ts +159 -0
  109. package/script/typescript/identifiers.d.ts.map +1 -1
  110. package/script/typescript/identifiers.js +159 -0
  111. package/script/typescript/withDescription.d.ts +119 -0
  112. package/script/typescript/withDescription.d.ts.map +1 -1
  113. package/script/typescript/withDescription.js +119 -0
@@ -1,9 +1,167 @@
1
1
  import type { GeneratedValue } from '../types/GeneratedValue.js';
2
+ /**
3
+ * A utility class for managing lists of generated values with customizable separators.
4
+ *
5
+ * `GeneratedValueList` provides a way to collect multiple generated values and combine
6
+ * them into a single string with a specified separator. It automatically filters out
7
+ * empty values to prevent generating unnecessary whitespace or malformed output.
8
+ *
9
+ * This class is useful for building lists of code elements like function parameters,
10
+ * import statements, or any other comma-separated (or otherwise separated) constructs
11
+ * where individual items might sometimes be empty.
12
+ *
13
+ * ## Key Features
14
+ *
15
+ * - **Custom Separators**: Support for any string separator (commas, newlines, spaces, etc.)
16
+ * - **Empty Filtering**: Automatically removes empty values from output
17
+ * - **Type Safety**: Works with any GeneratedValue type
18
+ * - **Incremental Building**: Values can be added one at a time
19
+ *
20
+ * @example Basic usage with comma separation
21
+ * ```typescript
22
+ * import { GeneratedValueList } from '@skmtc/core';
23
+ *
24
+ * const parameterList = new GeneratedValueList(', ');
25
+ * parameterList.add({ toString: () => 'id: string' });
26
+ * parameterList.add({ toString: () => 'name: string' });
27
+ * parameterList.add({ toString: () => 'email?: string' });
28
+ *
29
+ * console.log(parameterList.toString());
30
+ * // 'id: string, name: string, email?: string'
31
+ * ```
32
+ *
33
+ * @example With newline separation for code blocks
34
+ * ```typescript
35
+ * const codeLines = new GeneratedValueList('\n');
36
+ * codeLines.add({ toString: () => 'import { User } from "./types";' });
37
+ * codeLines.add({ toString: () => 'import { validate } from "./utils";' });
38
+ * codeLines.add({ toString: () => '' }); // Empty line will be filtered
39
+ * codeLines.add({ toString: () => 'export class UserService {' });
40
+ * codeLines.add({ toString: () => ' // Implementation' });
41
+ * codeLines.add({ toString: () => '}' });
42
+ *
43
+ * console.log(codeLines.toString());
44
+ * // import { User } from "./types";
45
+ * // import { validate } from "./utils";
46
+ * // export class UserService {
47
+ * // // Implementation
48
+ * // }
49
+ * ```
50
+ *
51
+ * @example Empty value filtering
52
+ * ```typescript
53
+ * const mixedList = new GeneratedValueList(' | ');
54
+ * mixedList.add({ toString: () => "'active'" });
55
+ * mixedList.add({ toString: () => '' }); // This will be filtered out
56
+ * mixedList.add({ toString: () => "'inactive'" });
57
+ * mixedList.add({ toString: () => "'pending'" });
58
+ *
59
+ * console.log(mixedList.toString());
60
+ * // "'active' | 'inactive' | 'pending'"
61
+ * ```
62
+ *
63
+ * @example Using in code generation
64
+ * ```typescript
65
+ * class InterfaceGenerator {
66
+ * generateInterface(name: string, properties: Array<{name: string, type: string}>) {
67
+ * const propertyList = new GeneratedValueList(';\n ');
68
+ *
69
+ * properties.forEach(prop => {
70
+ * if (prop.type) { // Only add properties that have types
71
+ * propertyList.add({
72
+ * toString: () => `${prop.name}: ${prop.type}`
73
+ * });
74
+ * }
75
+ * });
76
+ *
77
+ * return `interface ${name} {\n ${propertyList.toString()};\n}`;
78
+ * }
79
+ * }
80
+ *
81
+ * const generator = new InterfaceGenerator();
82
+ * const userInterface = generator.generateInterface('User', [
83
+ * { name: 'id', type: 'string' },
84
+ * { name: 'name', type: 'string' },
85
+ * { name: 'invalid', type: '' }, // Will be filtered out
86
+ * { name: 'email', type: 'string | null' }
87
+ * ]);
88
+ *
89
+ * console.log(userInterface);
90
+ * // interface User {
91
+ * // id: string;
92
+ * // name: string;
93
+ * // email: string | null;
94
+ * // }
95
+ * ```
96
+ */
2
97
  export declare class GeneratedValueList {
98
+ /** The separator string used to join values */
3
99
  separator: string;
100
+ /** Internal array of generated values */
4
101
  private items;
102
+ /**
103
+ * Creates a new GeneratedValueList with the specified separator.
104
+ *
105
+ * @param separator - The string to use when joining values (e.g., ', ', '\n', ' | ')
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // For comma-separated lists
110
+ * const commaList = new GeneratedValueList(', ');
111
+ *
112
+ * // For line-separated content
113
+ * const lineList = new GeneratedValueList('\n');
114
+ *
115
+ * // For union types
116
+ * const unionList = new GeneratedValueList(' | ');
117
+ * ```
118
+ */
5
119
  constructor(separator: string);
120
+ /**
121
+ * Adds a generated value to the list.
122
+ *
123
+ * The value will be included in the output string when `toString()` is called,
124
+ * unless the value's `toString()` method returns an empty string, in which case
125
+ * it will be automatically filtered out.
126
+ *
127
+ * @param str - The generated value to add to the list
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const list = new GeneratedValueList(', ');
132
+ *
133
+ * // Add simple values
134
+ * list.add({ toString: () => 'value1' });
135
+ * list.add({ toString: () => 'value2' });
136
+ *
137
+ * // Add conditional values
138
+ * const conditionalValue = shouldInclude ? 'conditional' : '';
139
+ * list.add({ toString: () => conditionalValue });
140
+ *
141
+ * console.log(list.toString()); // 'value1, value2' (conditional filtered if empty)
142
+ * ```
143
+ */
6
144
  add(str: GeneratedValue): void;
145
+ /**
146
+ * Converts the list to a string representation with values joined by the separator.
147
+ *
148
+ * This method processes all added values by calling their `toString()` methods,
149
+ * filters out any empty strings (matching the {@link EMPTY} constant), and joins
150
+ * the remaining values with the configured separator.
151
+ *
152
+ * @returns The joined string representation of all non-empty values
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const list = new GeneratedValueList(' -> ');
157
+ * list.add({ toString: () => 'start' });
158
+ * list.add({ toString: () => '' }); // Will be filtered out
159
+ * list.add({ toString: () => 'middle' });
160
+ * list.add({ toString: () => 'end' });
161
+ *
162
+ * console.log(list.toString()); // 'start -> middle -> end'
163
+ * ```
164
+ */
7
165
  toString(): string;
8
166
  }
9
167
  //# sourceMappingURL=GeneratedValueList.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GeneratedValueList.d.ts","sourceRoot":"","sources":["../../src/dsl/GeneratedValueList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAGhE,qBAAa,kBAAkB;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,KAAK,CAAuB;gBAExB,SAAS,EAAE,MAAM;IAI7B,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI;IAI9B,QAAQ,IAAI,MAAM;CAMnB"}
1
+ {"version":3,"file":"GeneratedValueList.d.ts","sourceRoot":"","sources":["../../src/dsl/GeneratedValueList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,qBAAa,kBAAkB;IAC7B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAA;IAEjB,yCAAyC;IACzC,OAAO,CAAC,KAAK,CAAuB;IAEpC;;;;;;;;;;;;;;;;OAgBG;gBACS,SAAS,EAAE,MAAM;IAI7B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI;IAI9B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,IAAI,MAAM;CAMnB"}
@@ -1,12 +1,126 @@
1
1
  import { EMPTY } from './constants.js';
2
+ /**
3
+ * A utility class for managing lists of generated values with customizable separators.
4
+ *
5
+ * `GeneratedValueList` provides a way to collect multiple generated values and combine
6
+ * them into a single string with a specified separator. It automatically filters out
7
+ * empty values to prevent generating unnecessary whitespace or malformed output.
8
+ *
9
+ * This class is useful for building lists of code elements like function parameters,
10
+ * import statements, or any other comma-separated (or otherwise separated) constructs
11
+ * where individual items might sometimes be empty.
12
+ *
13
+ * ## Key Features
14
+ *
15
+ * - **Custom Separators**: Support for any string separator (commas, newlines, spaces, etc.)
16
+ * - **Empty Filtering**: Automatically removes empty values from output
17
+ * - **Type Safety**: Works with any GeneratedValue type
18
+ * - **Incremental Building**: Values can be added one at a time
19
+ *
20
+ * @example Basic usage with comma separation
21
+ * ```typescript
22
+ * import { GeneratedValueList } from '@skmtc/core';
23
+ *
24
+ * const parameterList = new GeneratedValueList(', ');
25
+ * parameterList.add({ toString: () => 'id: string' });
26
+ * parameterList.add({ toString: () => 'name: string' });
27
+ * parameterList.add({ toString: () => 'email?: string' });
28
+ *
29
+ * console.log(parameterList.toString());
30
+ * // 'id: string, name: string, email?: string'
31
+ * ```
32
+ *
33
+ * @example With newline separation for code blocks
34
+ * ```typescript
35
+ * const codeLines = new GeneratedValueList('\n');
36
+ * codeLines.add({ toString: () => 'import { User } from "./types";' });
37
+ * codeLines.add({ toString: () => 'import { validate } from "./utils";' });
38
+ * codeLines.add({ toString: () => '' }); // Empty line will be filtered
39
+ * codeLines.add({ toString: () => 'export class UserService {' });
40
+ * codeLines.add({ toString: () => ' // Implementation' });
41
+ * codeLines.add({ toString: () => '}' });
42
+ *
43
+ * console.log(codeLines.toString());
44
+ * // import { User } from "./types";
45
+ * // import { validate } from "./utils";
46
+ * // export class UserService {
47
+ * // // Implementation
48
+ * // }
49
+ * ```
50
+ *
51
+ * @example Empty value filtering
52
+ * ```typescript
53
+ * const mixedList = new GeneratedValueList(' | ');
54
+ * mixedList.add({ toString: () => "'active'" });
55
+ * mixedList.add({ toString: () => '' }); // This will be filtered out
56
+ * mixedList.add({ toString: () => "'inactive'" });
57
+ * mixedList.add({ toString: () => "'pending'" });
58
+ *
59
+ * console.log(mixedList.toString());
60
+ * // "'active' | 'inactive' | 'pending'"
61
+ * ```
62
+ *
63
+ * @example Using in code generation
64
+ * ```typescript
65
+ * class InterfaceGenerator {
66
+ * generateInterface(name: string, properties: Array<{name: string, type: string}>) {
67
+ * const propertyList = new GeneratedValueList(';\n ');
68
+ *
69
+ * properties.forEach(prop => {
70
+ * if (prop.type) { // Only add properties that have types
71
+ * propertyList.add({
72
+ * toString: () => `${prop.name}: ${prop.type}`
73
+ * });
74
+ * }
75
+ * });
76
+ *
77
+ * return `interface ${name} {\n ${propertyList.toString()};\n}`;
78
+ * }
79
+ * }
80
+ *
81
+ * const generator = new InterfaceGenerator();
82
+ * const userInterface = generator.generateInterface('User', [
83
+ * { name: 'id', type: 'string' },
84
+ * { name: 'name', type: 'string' },
85
+ * { name: 'invalid', type: '' }, // Will be filtered out
86
+ * { name: 'email', type: 'string | null' }
87
+ * ]);
88
+ *
89
+ * console.log(userInterface);
90
+ * // interface User {
91
+ * // id: string;
92
+ * // name: string;
93
+ * // email: string | null;
94
+ * // }
95
+ * ```
96
+ */
2
97
  export class GeneratedValueList {
98
+ /**
99
+ * Creates a new GeneratedValueList with the specified separator.
100
+ *
101
+ * @param separator - The string to use when joining values (e.g., ', ', '\n', ' | ')
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // For comma-separated lists
106
+ * const commaList = new GeneratedValueList(', ');
107
+ *
108
+ * // For line-separated content
109
+ * const lineList = new GeneratedValueList('\n');
110
+ *
111
+ * // For union types
112
+ * const unionList = new GeneratedValueList(' | ');
113
+ * ```
114
+ */
3
115
  constructor(separator) {
116
+ /** The separator string used to join values */
4
117
  Object.defineProperty(this, "separator", {
5
118
  enumerable: true,
6
119
  configurable: true,
7
120
  writable: true,
8
121
  value: void 0
9
122
  });
123
+ /** Internal array of generated values */
10
124
  Object.defineProperty(this, "items", {
11
125
  enumerable: true,
12
126
  configurable: true,
@@ -15,9 +129,53 @@ export class GeneratedValueList {
15
129
  });
16
130
  this.separator = separator;
17
131
  }
132
+ /**
133
+ * Adds a generated value to the list.
134
+ *
135
+ * The value will be included in the output string when `toString()` is called,
136
+ * unless the value's `toString()` method returns an empty string, in which case
137
+ * it will be automatically filtered out.
138
+ *
139
+ * @param str - The generated value to add to the list
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const list = new GeneratedValueList(', ');
144
+ *
145
+ * // Add simple values
146
+ * list.add({ toString: () => 'value1' });
147
+ * list.add({ toString: () => 'value2' });
148
+ *
149
+ * // Add conditional values
150
+ * const conditionalValue = shouldInclude ? 'conditional' : '';
151
+ * list.add({ toString: () => conditionalValue });
152
+ *
153
+ * console.log(list.toString()); // 'value1, value2' (conditional filtered if empty)
154
+ * ```
155
+ */
18
156
  add(str) {
19
157
  this.items.push(str);
20
158
  }
159
+ /**
160
+ * Converts the list to a string representation with values joined by the separator.
161
+ *
162
+ * This method processes all added values by calling their `toString()` methods,
163
+ * filters out any empty strings (matching the {@link EMPTY} constant), and joins
164
+ * the remaining values with the configured separator.
165
+ *
166
+ * @returns The joined string representation of all non-empty values
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * const list = new GeneratedValueList(' -> ');
171
+ * list.add({ toString: () => 'start' });
172
+ * list.add({ toString: () => '' }); // Will be filtered out
173
+ * list.add({ toString: () => 'middle' });
174
+ * list.add({ toString: () => 'end' });
175
+ *
176
+ * console.log(list.toString()); // 'start -> middle -> end'
177
+ * ```
178
+ */
21
179
  toString() {
22
180
  return this.items
23
181
  .map(item => item.toString())
@@ -1,5 +1,81 @@
1
+ /**
2
+ * Represents any object that can be converted to a string representation.
3
+ *
4
+ * The `Stringable` interface is a fundamental type used throughout the SKMTC DSL
5
+ * system to ensure that objects can be converted to strings for code generation.
6
+ * This interface matches JavaScript's built-in `toString()` contract and is used
7
+ * extensively by the {@link List} class and other string-building utilities.
8
+ *
9
+ * ## Usage in SKMTC
10
+ *
11
+ * This type is used as a constraint in generic classes and functions that need
12
+ * to output string representations. It allows for type-safe string building
13
+ * while accommodating both primitive types and custom objects.
14
+ *
15
+ * @example Built-in types are stringable
16
+ * ```typescript
17
+ * import type { Stringable } from '@skmtc/core';
18
+ *
19
+ * // All these types implement Stringable
20
+ * const str: Stringable = 'hello'; // string
21
+ * const num: Stringable = 42; // number
22
+ * const bool: Stringable = true; // boolean
23
+ * const obj: Stringable = { toString: () => 'custom' }; // custom object
24
+ * ```
25
+ *
26
+ * @example Custom classes implementing Stringable
27
+ * ```typescript
28
+ * class CodeBlock implements Stringable {
29
+ * constructor(private code: string) {}
30
+ *
31
+ * toString(): string {
32
+ * return `{\n ${this.code}\n}`;
33
+ * }
34
+ * }
35
+ *
36
+ * const block = new CodeBlock('console.log("hello");');
37
+ * console.log(block.toString());
38
+ * // {
39
+ * // console.log("hello");
40
+ * // }
41
+ * ```
42
+ *
43
+ * @example Using with List class
44
+ * ```typescript
45
+ * import { List } from '@skmtc/core';
46
+ *
47
+ * // List accepts any Stringable items
48
+ * const stringables: Stringable[] = [
49
+ * 'string literal',
50
+ * 42,
51
+ * true,
52
+ * { toString: () => 'custom object' },
53
+ * new CodeBlock('return value;')
54
+ * ];
55
+ *
56
+ * const list = new List(stringables);
57
+ * console.log(list.toString());
58
+ * // string literal, 42, true, custom object, {
59
+ * // return value;
60
+ * // }
61
+ * ```
62
+ *
63
+ * @example Type constraints in generics
64
+ * ```typescript
65
+ * function joinWithCommas<T extends Stringable>(items: T[]): string {
66
+ * return items.map(item => item.toString()).join(', ');
67
+ * }
68
+ *
69
+ * const result = joinWithCommas([1, 2, 3]); // "1, 2, 3"
70
+ * const identifiers = joinWithCommas([
71
+ * Identifier.createVariable('user'),
72
+ * Identifier.createType('User')
73
+ * ]); // "user, User"
74
+ * ```
75
+ */
1
76
  import "../_dnt.polyfills.js";
2
77
  export type Stringable = {
78
+ /** Converts the object to its string representation */
3
79
  toString: () => string;
4
80
  };
5
81
  //# sourceMappingURL=Stringable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Stringable.d.ts","sourceRoot":"","sources":["../../src/dsl/Stringable.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,MAAM,CAAA;CACvB,CAAA"}
1
+ {"version":3,"file":"Stringable.d.ts","sourceRoot":"","sources":["../../src/dsl/Stringable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,OAAO,sBAAsB,CAAC;AAE9B,MAAM,MAAM,UAAU,GAAG;IACvB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,MAAM,CAAA;CACvB,CAAA"}
@@ -1 +1,76 @@
1
+ /**
2
+ * Represents any object that can be converted to a string representation.
3
+ *
4
+ * The `Stringable` interface is a fundamental type used throughout the SKMTC DSL
5
+ * system to ensure that objects can be converted to strings for code generation.
6
+ * This interface matches JavaScript's built-in `toString()` contract and is used
7
+ * extensively by the {@link List} class and other string-building utilities.
8
+ *
9
+ * ## Usage in SKMTC
10
+ *
11
+ * This type is used as a constraint in generic classes and functions that need
12
+ * to output string representations. It allows for type-safe string building
13
+ * while accommodating both primitive types and custom objects.
14
+ *
15
+ * @example Built-in types are stringable
16
+ * ```typescript
17
+ * import type { Stringable } from '@skmtc/core';
18
+ *
19
+ * // All these types implement Stringable
20
+ * const str: Stringable = 'hello'; // string
21
+ * const num: Stringable = 42; // number
22
+ * const bool: Stringable = true; // boolean
23
+ * const obj: Stringable = { toString: () => 'custom' }; // custom object
24
+ * ```
25
+ *
26
+ * @example Custom classes implementing Stringable
27
+ * ```typescript
28
+ * class CodeBlock implements Stringable {
29
+ * constructor(private code: string) {}
30
+ *
31
+ * toString(): string {
32
+ * return `{\n ${this.code}\n}`;
33
+ * }
34
+ * }
35
+ *
36
+ * const block = new CodeBlock('console.log("hello");');
37
+ * console.log(block.toString());
38
+ * // {
39
+ * // console.log("hello");
40
+ * // }
41
+ * ```
42
+ *
43
+ * @example Using with List class
44
+ * ```typescript
45
+ * import { List } from '@skmtc/core';
46
+ *
47
+ * // List accepts any Stringable items
48
+ * const stringables: Stringable[] = [
49
+ * 'string literal',
50
+ * 42,
51
+ * true,
52
+ * { toString: () => 'custom object' },
53
+ * new CodeBlock('return value;')
54
+ * ];
55
+ *
56
+ * const list = new List(stringables);
57
+ * console.log(list.toString());
58
+ * // string literal, 42, true, custom object, {
59
+ * // return value;
60
+ * // }
61
+ * ```
62
+ *
63
+ * @example Type constraints in generics
64
+ * ```typescript
65
+ * function joinWithCommas<T extends Stringable>(items: T[]): string {
66
+ * return items.map(item => item.toString()).join(', ');
67
+ * }
68
+ *
69
+ * const result = joinWithCommas([1, 2, 3]); // "1, 2, 3"
70
+ * const identifiers = joinWithCommas([
71
+ * Identifier.createVariable('user'),
72
+ * Identifier.createType('User')
73
+ * ]); // "user, User"
74
+ * ```
75
+ */
1
76
  import "../_dnt.polyfills.js";
@@ -1,10 +1,160 @@
1
1
  import "../_dnt.polyfills.js";
2
2
  import type { OasRef } from '../oas/ref/Ref.js';
3
3
  import type { OasSchema } from '../oas/schema/Schema.js';
4
+ /**
5
+ * Arguments for collating examples from OpenAPI schemas.
6
+ */
4
7
  type CollatedExampleArgs = {
8
+ /** The OpenAPI schema or reference to extract examples from */
5
9
  objectSchema: OasSchema | OasRef<'schema'> | undefined;
10
+ /** Current recursion depth (used to prevent infinite loops) */
6
11
  depth: number;
7
12
  };
13
+ /**
14
+ * Recursively collates and builds example values from OpenAPI schemas.
15
+ *
16
+ * This function traverses OpenAPI schema structures and generates comprehensive
17
+ * example values based on the schema definitions and any explicit examples provided.
18
+ * It handles complex nested structures including objects, arrays, unions, and
19
+ * references while preventing infinite recursion through depth limiting.
20
+ *
21
+ * The function prioritizes explicit examples when available and falls back to
22
+ * generating examples from nested schemas. It's particularly useful for creating
23
+ * realistic test data, API documentation examples, and mock responses.
24
+ *
25
+ * @param args - Configuration for example collation
26
+ * @param args.objectSchema - The schema to extract examples from
27
+ * @param args.depth - Current recursion depth (prevents infinite loops)
28
+ * @returns Collated example value matching the schema structure, or undefined if no examples
29
+ *
30
+ * @throws {Error} When recursion depth exceeds 15 levels (prevents stack overflow)
31
+ *
32
+ * @example Basic schema examples
33
+ * ```typescript
34
+ * import { collateExamples } from '@skmtc/core';
35
+ *
36
+ * // String schema with example
37
+ * const stringSchema = new OasString({ example: 'john.doe@example.com' });
38
+ * const example = collateExamples({ objectSchema: stringSchema, depth: 0 });
39
+ * console.log(example); // 'john.doe@example.com'
40
+ *
41
+ * // Number schema with example
42
+ * const numberSchema = new OasNumber({ example: 42 });
43
+ * const numExample = collateExamples({ objectSchema: numberSchema, depth: 0 });
44
+ * console.log(numExample); // 42
45
+ * ```
46
+ *
47
+ * @example Object schema examples
48
+ * ```typescript
49
+ * // Object schema with nested properties
50
+ * const userSchema = new OasObject({
51
+ * properties: {
52
+ * id: new OasInteger({ example: 123 }),
53
+ * name: new OasString({ example: 'John Doe' }),
54
+ * email: new OasString({ example: 'john@example.com' }),
55
+ * age: new OasInteger({ example: 30 })
56
+ * }
57
+ * });
58
+ *
59
+ * const userExample = collateExamples({ objectSchema: userSchema, depth: 0 });
60
+ * console.log(userExample);
61
+ * // {
62
+ * // id: 123,
63
+ * // name: 'John Doe',
64
+ * // email: 'john@example.com',
65
+ * // age: 30
66
+ * // }
67
+ * ```
68
+ *
69
+ * @example Array schema examples
70
+ * ```typescript
71
+ * // Array of objects
72
+ * const usersArraySchema = new OasArray({
73
+ * items: new OasObject({
74
+ * properties: {
75
+ * id: new OasInteger({ example: 1 }),
76
+ * name: new OasString({ example: 'Jane Smith' })
77
+ * }
78
+ * })
79
+ * });
80
+ *
81
+ * const arrayExample = collateExamples({ objectSchema: usersArraySchema, depth: 0 });
82
+ * console.log(arrayExample);
83
+ * // [
84
+ * // {
85
+ * // id: 1,
86
+ * // name: 'Jane Smith'
87
+ * // }
88
+ * // ]
89
+ * ```
90
+ *
91
+ * @example Union schema examples
92
+ * ```typescript
93
+ * // Union of string and number
94
+ * const unionSchema = new OasUnion({
95
+ * members: [
96
+ * new OasString({ example: 'text-value' }),
97
+ * new OasNumber({ example: 99 })
98
+ * ]
99
+ * });
100
+ *
101
+ * const unionExample = collateExamples({ objectSchema: unionSchema, depth: 0 });
102
+ * console.log(unionExample); // 'text-value' (first member with example)
103
+ * ```
104
+ *
105
+ * @example Reference resolution
106
+ * ```typescript
107
+ * // Schema with reference to another schema
108
+ * const addressRef = new OasRef({
109
+ * $ref: '#/components/schemas/Address',
110
+ * resolve: () => new OasObject({
111
+ * properties: {
112
+ * street: new OasString({ example: '123 Main St' }),
113
+ * city: new OasString({ example: 'Springfield' })
114
+ * }
115
+ * })
116
+ * });
117
+ *
118
+ * const refExample = collateExamples({ objectSchema: addressRef, depth: 0 });
119
+ * console.log(refExample);
120
+ * // {
121
+ * // street: '123 Main St',
122
+ * // city: 'Springfield'
123
+ * // }
124
+ * ```
125
+ *
126
+ * @example Depth limiting and error handling
127
+ * ```typescript
128
+ * // Deep nesting detection
129
+ * try {
130
+ * const deepExample = collateExamples({ objectSchema: someSchema, depth: 16 });
131
+ * } catch (error) {
132
+ * console.error('Depth limit exceeded:', error.message); // 'Depth limit reached'
133
+ * }
134
+ *
135
+ * // Handling missing schemas
136
+ * const emptyExample = collateExamples({ objectSchema: undefined, depth: 0 });
137
+ * console.log(emptyExample); // undefined
138
+ * ```
139
+ *
140
+ * @example Using in API documentation generation
141
+ * ```typescript
142
+ * class ApiDocGenerator {
143
+ * generateExampleResponse(responseSchema: OasSchema) {
144
+ * const example = collateExamples({ objectSchema: responseSchema, depth: 0 });
145
+ *
146
+ * if (example) {
147
+ * return {
148
+ * description: 'Example response',
149
+ * value: example
150
+ * };
151
+ * }
152
+ *
153
+ * return { description: 'No example available' };
154
+ * }
155
+ * }
156
+ * ```
157
+ */
8
158
  export declare const collateExamples: ({ objectSchema, depth }: CollatedExampleArgs) => unknown;
9
159
  export {};
10
160
  //# sourceMappingURL=collateExamples.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collateExamples.d.ts","sourceRoot":"","sources":["../../src/helpers/collateExamples.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,KAAK,mBAAmB,GAAG;IACzB,YAAY,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IACtD,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,eAAe,GAAI,yBAAyB,mBAAmB,KAAG,OAwE9E,CAAA"}
1
+ {"version":3,"file":"collateExamples.d.ts","sourceRoot":"","sources":["../../src/helpers/collateExamples.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD;;GAEG;AACH,KAAK,mBAAmB,GAAG;IACzB,+DAA+D;IAC/D,YAAY,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IACtD,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgJG;AACH,eAAO,MAAM,eAAe,GAAI,yBAAyB,mBAAmB,KAAG,OAwE9E,CAAA"}