@skmtc/core 0.0.786 → 0.0.787
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.
- package/esm/dsl/ContentSettings.d.ts +164 -0
- package/esm/dsl/ContentSettings.d.ts.map +1 -1
- package/esm/dsl/ContentSettings.js +151 -0
- package/esm/dsl/Definition.d.ts +199 -0
- package/esm/dsl/Definition.d.ts.map +1 -1
- package/esm/dsl/Definition.js +189 -0
- package/esm/dsl/EntityType.d.ts +83 -0
- package/esm/dsl/EntityType.d.ts.map +1 -1
- package/esm/dsl/EntityType.js +83 -0
- package/esm/oas/array/Array.d.ts +109 -1
- package/esm/oas/array/Array.d.ts.map +1 -1
- package/esm/oas/array/Array.js +93 -1
- package/esm/oas/integer/Integer.d.ts +98 -0
- package/esm/oas/integer/Integer.d.ts.map +1 -1
- package/esm/oas/integer/Integer.js +80 -0
- package/esm/oas/string/String.d.ts +103 -1
- package/esm/oas/string/String.d.ts.map +1 -1
- package/esm/oas/string/String.js +87 -1
- package/esm/types/Brand.d.ts +74 -0
- package/esm/types/Brand.d.ts.map +1 -1
- package/esm/types/Brand.js +9 -0
- package/esm/types/RefName.d.ts +61 -0
- package/esm/types/RefName.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/dsl/ContentSettings.d.ts +164 -0
- package/script/dsl/ContentSettings.d.ts.map +1 -1
- package/script/dsl/ContentSettings.js +151 -0
- package/script/dsl/Definition.d.ts +199 -0
- package/script/dsl/Definition.d.ts.map +1 -1
- package/script/dsl/Definition.js +189 -0
- package/script/dsl/EntityType.d.ts +83 -0
- package/script/dsl/EntityType.d.ts.map +1 -1
- package/script/dsl/EntityType.js +83 -0
- package/script/oas/array/Array.d.ts +109 -1
- package/script/oas/array/Array.d.ts.map +1 -1
- package/script/oas/array/Array.js +93 -1
- package/script/oas/integer/Integer.d.ts +98 -0
- package/script/oas/integer/Integer.d.ts.map +1 -1
- package/script/oas/integer/Integer.js +80 -0
- package/script/oas/string/String.d.ts +103 -1
- package/script/oas/string/String.d.ts.map +1 -1
- package/script/oas/string/String.js +87 -1
- package/script/types/Brand.d.ts +74 -0
- package/script/types/Brand.d.ts.map +1 -1
- package/script/types/Brand.js +9 -0
- package/script/types/RefName.d.ts +61 -0
- package/script/types/RefName.d.ts.map +1 -1
package/esm/dsl/Definition.js
CHANGED
|
@@ -1,26 +1,170 @@
|
|
|
1
1
|
import { ContentBase } from './ContentBase.js';
|
|
2
2
|
import { withDescription } from '../typescript/withDescription.js';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a complete code definition in the SKMTC DSL system.
|
|
5
|
+
*
|
|
6
|
+
* The `Definition` class is the primary output unit of generators, representing
|
|
7
|
+
* a complete piece of generated code (like an interface, function, or constant).
|
|
8
|
+
* It combines an identifier, generated content, and optional metadata into a
|
|
9
|
+
* formatted code definition with proper TypeScript syntax.
|
|
10
|
+
*
|
|
11
|
+
* This class automatically handles export statements, type annotations, and
|
|
12
|
+
* JSDoc comment generation, making it the building block for all generated
|
|
13
|
+
* code artifacts.
|
|
14
|
+
*
|
|
15
|
+
* ## Key Features
|
|
16
|
+
*
|
|
17
|
+
* - **Automatic Exports**: Handles export keyword based on configuration
|
|
18
|
+
* - **Type Safety**: Preserves type information through generic parameters
|
|
19
|
+
* - **JSDoc Integration**: Automatic comment generation from descriptions
|
|
20
|
+
* - **Entity Type Support**: Handles different definition types (const, type, etc.)
|
|
21
|
+
* - **Identifier Management**: Integrates with the Identifier system for naming
|
|
22
|
+
*
|
|
23
|
+
* @template V - The type of generated value (preserves generator-specific types)
|
|
24
|
+
*
|
|
25
|
+
* @example Basic interface definition
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { Definition, Identifier } from '@skmtc/core';
|
|
28
|
+
*
|
|
29
|
+
* const userInterface = new Definition({
|
|
30
|
+
* context: generateContext,
|
|
31
|
+
* identifier: Identifier.createType('User'),
|
|
32
|
+
* description: 'Represents a user in the system',
|
|
33
|
+
* value: {
|
|
34
|
+
* generatorKey: 'typescript-interfaces',
|
|
35
|
+
* content: `{
|
|
36
|
+
* id: string;
|
|
37
|
+
* name: string;
|
|
38
|
+
* email: string;
|
|
39
|
+
* }`
|
|
40
|
+
* }
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* console.log(userInterface.toString());
|
|
44
|
+
* //
|
|
45
|
+
* // Represents a user in the system
|
|
46
|
+
* //
|
|
47
|
+
* // export type User = {
|
|
48
|
+
* // id: string;
|
|
49
|
+
* // name: string;
|
|
50
|
+
* // email: string;
|
|
51
|
+
* // };
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Function definition with parameters
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const apiFunction = new Definition({
|
|
57
|
+
* context: generateContext,
|
|
58
|
+
* identifier: Identifier.createVariable('fetchUser', 'Promise<User>'),
|
|
59
|
+
* description: 'Fetches a user by ID from the API',
|
|
60
|
+
* value: {
|
|
61
|
+
* generatorKey: 'api-client',
|
|
62
|
+
* content: `async (id: string) => {
|
|
63
|
+
* const response = await fetch(\`/api/users/\${id}\`);
|
|
64
|
+
* return response.json();
|
|
65
|
+
* }`
|
|
66
|
+
* }
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* console.log(apiFunction.toString());
|
|
70
|
+
* //
|
|
71
|
+
* // Fetches a user by ID from the API
|
|
72
|
+
* //
|
|
73
|
+
* // export const fetchUser: Promise<User> = async (id: string) => {
|
|
74
|
+
* // const response = await fetch(`/api/users/${id}`);
|
|
75
|
+
* // return response.json();
|
|
76
|
+
* // };
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example Non-exported definition
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const helperFunction = new Definition({
|
|
82
|
+
* context: generateContext,
|
|
83
|
+
* identifier: Identifier.createVariable('validateEmail'),
|
|
84
|
+
* value: {
|
|
85
|
+
* generatorKey: 'utilities',
|
|
86
|
+
* content: `(email: string): boolean => {
|
|
87
|
+
* return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email);
|
|
88
|
+
* }`
|
|
89
|
+
* },
|
|
90
|
+
* noExport: true // Internal helper, not exported
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* console.log(helperFunction.toString());
|
|
94
|
+
* // const validateEmail = (email: string): boolean => {
|
|
95
|
+
* // return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
96
|
+
* // };
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example Using in generator classes
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { ModelBase, Definition, Identifier } from '@skmtc/core';
|
|
102
|
+
*
|
|
103
|
+
* class TypeScriptInterface extends ModelBase {
|
|
104
|
+
* toDefinition(): Definition {
|
|
105
|
+
* const schema = this.context.getSchema(this.refName);
|
|
106
|
+
*
|
|
107
|
+
* return new Definition({
|
|
108
|
+
* context: this.context,
|
|
109
|
+
* identifier: Identifier.createType(this.refName),
|
|
110
|
+
* description: schema.description,
|
|
111
|
+
* value: {
|
|
112
|
+
* generatorKey: this.generatorKey,
|
|
113
|
+
* content: this.generateInterfaceBody(schema)
|
|
114
|
+
* }
|
|
115
|
+
* });
|
|
116
|
+
* }
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
3
120
|
export class Definition extends ContentBase {
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new Definition instance.
|
|
123
|
+
*
|
|
124
|
+
* @param args - Definition configuration
|
|
125
|
+
* @param args.context - Generation context for pipeline access
|
|
126
|
+
* @param args.identifier - The identifier (name and type info) for this definition
|
|
127
|
+
* @param args.value - The generated content value
|
|
128
|
+
* @param args.description - Optional description for JSDoc comments
|
|
129
|
+
* @param args.noExport - Whether to omit the export keyword (default: false)
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const constant = new Definition({
|
|
134
|
+
* context: generateContext,
|
|
135
|
+
* identifier: Identifier.createVariable('API_BASE_URL', 'string'),
|
|
136
|
+
* description: 'Base URL for all API requests',
|
|
137
|
+
* value: {
|
|
138
|
+
* generatorKey: 'constants',
|
|
139
|
+
* content: "'https://api.example.com'"
|
|
140
|
+
* }
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
4
144
|
constructor({ context, identifier, value, description, noExport }) {
|
|
5
145
|
super({ context, generatorKey: value.generatorKey });
|
|
146
|
+
/** The identifier for this definition */
|
|
6
147
|
Object.defineProperty(this, "identifier", {
|
|
7
148
|
enumerable: true,
|
|
8
149
|
configurable: true,
|
|
9
150
|
writable: true,
|
|
10
151
|
value: void 0
|
|
11
152
|
});
|
|
153
|
+
/** Optional description for JSDoc comments */
|
|
12
154
|
Object.defineProperty(this, "description", {
|
|
13
155
|
enumerable: true,
|
|
14
156
|
configurable: true,
|
|
15
157
|
writable: true,
|
|
16
158
|
value: void 0
|
|
17
159
|
});
|
|
160
|
+
/** The generated value content */
|
|
18
161
|
Object.defineProperty(this, "value", {
|
|
19
162
|
enumerable: true,
|
|
20
163
|
configurable: true,
|
|
21
164
|
writable: true,
|
|
22
165
|
value: void 0
|
|
23
166
|
});
|
|
167
|
+
/** Whether to skip the export keyword */
|
|
24
168
|
Object.defineProperty(this, "noExport", {
|
|
25
169
|
enumerable: true,
|
|
26
170
|
configurable: true,
|
|
@@ -32,6 +176,51 @@ export class Definition extends ContentBase {
|
|
|
32
176
|
this.description = description;
|
|
33
177
|
this.noExport = noExport;
|
|
34
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Generates the complete TypeScript definition code.
|
|
181
|
+
*
|
|
182
|
+
* This method produces a properly formatted TypeScript definition with:
|
|
183
|
+
* - Optional JSDoc comments from the description
|
|
184
|
+
* - Export keyword (unless noExport is true)
|
|
185
|
+
* - Entity type (const, type, function, etc.)
|
|
186
|
+
* - Identifier with optional type annotation
|
|
187
|
+
* - Generated value content
|
|
188
|
+
*
|
|
189
|
+
* The output follows TypeScript syntax conventions and can be written
|
|
190
|
+
* directly to a .ts file.
|
|
191
|
+
*
|
|
192
|
+
* @returns The complete TypeScript definition as a string
|
|
193
|
+
*
|
|
194
|
+
* @example Type definition
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const typeDef = new Definition({
|
|
197
|
+
* context,
|
|
198
|
+
* identifier: Identifier.createType('Status'),
|
|
199
|
+
* description: 'Possible status values',
|
|
200
|
+
* value: { generatorKey: 'types', content: "'pending' | 'complete' | 'failed'" }
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* console.log(typeDef.toString());
|
|
204
|
+
* //
|
|
205
|
+
* // Possible status values
|
|
206
|
+
* //
|
|
207
|
+
* // export type Status = 'pending' | 'complete' | 'failed';
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* @example Constant definition
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const constDef = new Definition({
|
|
213
|
+
* context,
|
|
214
|
+
* identifier: Identifier.createVariable('DEFAULT_TIMEOUT', 'number'),
|
|
215
|
+
* value: { generatorKey: 'config', content: '5000' }
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* console.log(constDef.toString());
|
|
219
|
+
* // export const DEFAULT_TIMEOUT: number = 5000;
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @todo Move syntax to typescript package to enable language-agnostic use
|
|
223
|
+
*/
|
|
35
224
|
toString() {
|
|
36
225
|
const identifier = this.identifier.typeName
|
|
37
226
|
? `${this.identifier.name}: ${this.identifier.typeName}`
|
package/esm/dsl/EntityType.d.ts
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the type of a TypeScript entity for code generation.
|
|
3
|
+
*
|
|
4
|
+
* `EntityType` encapsulates the distinction between different kinds of
|
|
5
|
+
* TypeScript entities, specifically variables (which become `const` declarations)
|
|
6
|
+
* and types (which become `type` or `interface` declarations).
|
|
7
|
+
*
|
|
8
|
+
* This class is used by the {@link Identifier} system to ensure that
|
|
9
|
+
* generated code uses the correct TypeScript keywords and syntax patterns.
|
|
10
|
+
*
|
|
11
|
+
* @example Variable entity type
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { EntityType } from '@skmtc/core';
|
|
14
|
+
*
|
|
15
|
+
* const variableEntity = new EntityType('variable');
|
|
16
|
+
* console.log(variableEntity.toString()); // 'const'
|
|
17
|
+
*
|
|
18
|
+
* // Used in code generation:
|
|
19
|
+
* // const API_URL = 'https://api.example.com';
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @example Type entity type
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const typeEntity = new EntityType('type');
|
|
25
|
+
* console.log(typeEntity.toString()); // 'type'
|
|
26
|
+
*
|
|
27
|
+
* // Used in code generation:
|
|
28
|
+
* // type User = { id: string; name: string; };
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Integration with Identifier
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { Identifier, EntityType } from '@skmtc/core';
|
|
34
|
+
*
|
|
35
|
+
* // Create a variable identifier (uses 'const' keyword)
|
|
36
|
+
* const varId = Identifier.createVariable('API_KEY', 'string');
|
|
37
|
+
* console.log(varId.entityType.toString()); // 'const'
|
|
38
|
+
*
|
|
39
|
+
* // Create a type identifier (uses 'type' keyword)
|
|
40
|
+
* const typeId = Identifier.createType('UserStatus');
|
|
41
|
+
* console.log(typeId.entityType.toString()); // 'type'
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
1
44
|
export declare class EntityType {
|
|
45
|
+
/** The entity type discriminator */
|
|
2
46
|
type: 'variable' | 'type';
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new EntityType instance.
|
|
49
|
+
*
|
|
50
|
+
* @param type - The type of entity ('variable' for const declarations, 'type' for type declarations)
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // For generating const declarations
|
|
55
|
+
* const constEntity = new EntityType('variable');
|
|
56
|
+
*
|
|
57
|
+
* // For generating type declarations
|
|
58
|
+
* const typeEntity = new EntityType('type');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
3
61
|
constructor(type: 'variable' | 'type');
|
|
62
|
+
/**
|
|
63
|
+
* Returns the appropriate TypeScript keyword for this entity type.
|
|
64
|
+
*
|
|
65
|
+
* This method maps the entity type to the correct TypeScript declaration
|
|
66
|
+
* keyword that should be used in generated code:
|
|
67
|
+
* - 'variable' entities become 'const' declarations
|
|
68
|
+
* - 'type' entities become 'type' declarations
|
|
69
|
+
*
|
|
70
|
+
* @returns The TypeScript keyword string ('const' or 'type')
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const varEntity = new EntityType('variable');
|
|
75
|
+
* console.log(varEntity.toString()); // 'const'
|
|
76
|
+
*
|
|
77
|
+
* const typeEntity = new EntityType('type');
|
|
78
|
+
* console.log(typeEntity.toString()); // 'type'
|
|
79
|
+
*
|
|
80
|
+
* // Used in code generation:
|
|
81
|
+
* const keyword = entityType.toString();
|
|
82
|
+
* const declaration = `${keyword} ${identifier} = ${value};`;
|
|
83
|
+
* // Results in: "const API_URL = 'https://example.com';" or
|
|
84
|
+
* // Results in: "type Status = 'active' | 'inactive';"
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
4
87
|
toString(): string;
|
|
5
88
|
}
|
|
6
89
|
//# sourceMappingURL=EntityType.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityType.d.ts","sourceRoot":"","sources":["../../src/dsl/EntityType.ts"],"names":[],"mappings":"AAEA,qBAAa,UAAU;IACrB,IAAI,EAAE,UAAU,GAAG,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"EntityType.d.ts","sourceRoot":"","sources":["../../src/dsl/EntityType.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,qBAAa,UAAU;IACrB,oCAAoC;IACpC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAA;IAEzB;;;;;;;;;;;;;OAaG;gBACS,IAAI,EAAE,UAAU,GAAG,MAAM;IAIrC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,QAAQ,IAAI,MAAM;CAMnB"}
|
package/esm/dsl/EntityType.js
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
import { match } from 'ts-pattern';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the type of a TypeScript entity for code generation.
|
|
4
|
+
*
|
|
5
|
+
* `EntityType` encapsulates the distinction between different kinds of
|
|
6
|
+
* TypeScript entities, specifically variables (which become `const` declarations)
|
|
7
|
+
* and types (which become `type` or `interface` declarations).
|
|
8
|
+
*
|
|
9
|
+
* This class is used by the {@link Identifier} system to ensure that
|
|
10
|
+
* generated code uses the correct TypeScript keywords and syntax patterns.
|
|
11
|
+
*
|
|
12
|
+
* @example Variable entity type
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { EntityType } from '@skmtc/core';
|
|
15
|
+
*
|
|
16
|
+
* const variableEntity = new EntityType('variable');
|
|
17
|
+
* console.log(variableEntity.toString()); // 'const'
|
|
18
|
+
*
|
|
19
|
+
* // Used in code generation:
|
|
20
|
+
* // const API_URL = 'https://api.example.com';
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Type entity type
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const typeEntity = new EntityType('type');
|
|
26
|
+
* console.log(typeEntity.toString()); // 'type'
|
|
27
|
+
*
|
|
28
|
+
* // Used in code generation:
|
|
29
|
+
* // type User = { id: string; name: string; };
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Integration with Identifier
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { Identifier, EntityType } from '@skmtc/core';
|
|
35
|
+
*
|
|
36
|
+
* // Create a variable identifier (uses 'const' keyword)
|
|
37
|
+
* const varId = Identifier.createVariable('API_KEY', 'string');
|
|
38
|
+
* console.log(varId.entityType.toString()); // 'const'
|
|
39
|
+
*
|
|
40
|
+
* // Create a type identifier (uses 'type' keyword)
|
|
41
|
+
* const typeId = Identifier.createType('UserStatus');
|
|
42
|
+
* console.log(typeId.entityType.toString()); // 'type'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
2
45
|
export class EntityType {
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new EntityType instance.
|
|
48
|
+
*
|
|
49
|
+
* @param type - The type of entity ('variable' for const declarations, 'type' for type declarations)
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // For generating const declarations
|
|
54
|
+
* const constEntity = new EntityType('variable');
|
|
55
|
+
*
|
|
56
|
+
* // For generating type declarations
|
|
57
|
+
* const typeEntity = new EntityType('type');
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
3
60
|
constructor(type) {
|
|
61
|
+
/** The entity type discriminator */
|
|
4
62
|
Object.defineProperty(this, "type", {
|
|
5
63
|
enumerable: true,
|
|
6
64
|
configurable: true,
|
|
@@ -9,6 +67,31 @@ export class EntityType {
|
|
|
9
67
|
});
|
|
10
68
|
this.type = type;
|
|
11
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns the appropriate TypeScript keyword for this entity type.
|
|
72
|
+
*
|
|
73
|
+
* This method maps the entity type to the correct TypeScript declaration
|
|
74
|
+
* keyword that should be used in generated code:
|
|
75
|
+
* - 'variable' entities become 'const' declarations
|
|
76
|
+
* - 'type' entities become 'type' declarations
|
|
77
|
+
*
|
|
78
|
+
* @returns The TypeScript keyword string ('const' or 'type')
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const varEntity = new EntityType('variable');
|
|
83
|
+
* console.log(varEntity.toString()); // 'const'
|
|
84
|
+
*
|
|
85
|
+
* const typeEntity = new EntityType('type');
|
|
86
|
+
* console.log(typeEntity.toString()); // 'type'
|
|
87
|
+
*
|
|
88
|
+
* // Used in code generation:
|
|
89
|
+
* const keyword = entityType.toString();
|
|
90
|
+
* const declaration = `${keyword} ${identifier} = ${value};`;
|
|
91
|
+
* // Results in: "const API_URL = 'https://example.com';" or
|
|
92
|
+
* // Results in: "type Status = 'active' | 'inactive';"
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
12
95
|
toString() {
|
|
13
96
|
return match(this.type)
|
|
14
97
|
.with('variable', () => 'const')
|
package/esm/oas/array/Array.d.ts
CHANGED
|
@@ -2,21 +2,129 @@ import "../../_dnt.polyfills.js";
|
|
|
2
2
|
import type { OasSchema, ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
3
3
|
import type { OasRef } from '../ref/Ref.js';
|
|
4
4
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
5
|
+
/**
|
|
6
|
+
* Constructor fields for {@link OasArray}.
|
|
7
|
+
*
|
|
8
|
+
* @template Nullable - Whether the array value can be null
|
|
9
|
+
*/
|
|
5
10
|
export type ArrayFields<Nullable extends boolean | undefined> = {
|
|
11
|
+
/** Schema definition for array items */
|
|
6
12
|
items: OasSchema | OasRef<'schema'>;
|
|
13
|
+
/** A short summary of the array schema */
|
|
7
14
|
title?: string;
|
|
15
|
+
/** A description of the array schema */
|
|
8
16
|
description?: string;
|
|
17
|
+
/** Whether the array value can be null */
|
|
9
18
|
nullable?: Nullable;
|
|
19
|
+
/** Whether array items must be unique */
|
|
10
20
|
uniqueItems?: boolean;
|
|
21
|
+
/** Custom extension fields (x-* properties) */
|
|
11
22
|
extensionFields?: Record<string, unknown>;
|
|
23
|
+
/** Example array value */
|
|
12
24
|
example?: Nullable extends true ? unknown[] | null | undefined : unknown[] | undefined;
|
|
25
|
+
/** Maximum number of items allowed */
|
|
13
26
|
maxItems?: number;
|
|
27
|
+
/** Minimum number of items required */
|
|
14
28
|
minItems?: number;
|
|
29
|
+
/** Array of allowed enum values for the entire array */
|
|
15
30
|
enums?: Nullable extends true ? (unknown | null)[] | undefined : unknown[] | undefined;
|
|
31
|
+
/** Default value for the array */
|
|
16
32
|
defaultValue?: Nullable extends true ? unknown[] | null | undefined : unknown[] | undefined;
|
|
17
33
|
};
|
|
18
34
|
/**
|
|
19
|
-
*
|
|
35
|
+
* Represents an array schema in the OpenAPI Specification.
|
|
36
|
+
*
|
|
37
|
+
* `OasArray` handles array type definitions with comprehensive validation
|
|
38
|
+
* constraints including item count limits, uniqueness requirements, and
|
|
39
|
+
* item type specifications. It supports nested schemas and references
|
|
40
|
+
* for complex array structures.
|
|
41
|
+
*
|
|
42
|
+
* This class is used throughout the OAS processing pipeline to represent
|
|
43
|
+
* array fields in API schemas, including lists of objects, primitive arrays,
|
|
44
|
+
* and complex nested array structures.
|
|
45
|
+
*
|
|
46
|
+
* ## Key Features
|
|
47
|
+
*
|
|
48
|
+
* - **Item Type Definition**: Support for any schema type as array items
|
|
49
|
+
* - **Size Constraints**: Minimum and maximum item count validation
|
|
50
|
+
* - **Uniqueness Validation**: Ensure array items are unique (like Set behavior)
|
|
51
|
+
* - **Nested Schemas**: Support for complex nested array structures
|
|
52
|
+
* - **Reference Handling**: Seamless integration with schema references
|
|
53
|
+
* - **Nullable Support**: Type-safe nullable array handling
|
|
54
|
+
* - **JSON Schema**: Conversion to standard JSON Schema format
|
|
55
|
+
*
|
|
56
|
+
* @template Nullable - Whether the array value can be null
|
|
57
|
+
*
|
|
58
|
+
* @example String array
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { OasArray, OasString } from '@skmtc/core';
|
|
61
|
+
*
|
|
62
|
+
* const tagsArray = new OasArray({
|
|
63
|
+
* title: 'Tags',
|
|
64
|
+
* description: 'List of tags associated with the item',
|
|
65
|
+
* items: new OasString({ minLength: 1 }),
|
|
66
|
+
* minItems: 1,
|
|
67
|
+
* uniqueItems: true,
|
|
68
|
+
* example: ['javascript', 'typescript', 'react']
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Object array with references
|
|
73
|
+
* ```typescript
|
|
74
|
+
* import { OasArray, OasRef } from '@skmtc/core';
|
|
75
|
+
*
|
|
76
|
+
* const usersArray = new OasArray({
|
|
77
|
+
* title: 'Users',
|
|
78
|
+
* description: 'List of user objects',
|
|
79
|
+
* items: new OasRef({ refName: 'User' }),
|
|
80
|
+
* maxItems: 100,
|
|
81
|
+
* example: [
|
|
82
|
+
* { id: 1, name: 'John' },
|
|
83
|
+
* { id: 2, name: 'Jane' }
|
|
84
|
+
* ]
|
|
85
|
+
* });
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example Nested array (array of arrays)
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const matrixArray = new OasArray({
|
|
91
|
+
* title: 'Matrix',
|
|
92
|
+
* description: '2D array of numbers',
|
|
93
|
+
* items: new OasArray({
|
|
94
|
+
* items: new OasInteger({ minimum: 0 })
|
|
95
|
+
* }),
|
|
96
|
+
* example: [
|
|
97
|
+
* [1, 2, 3],
|
|
98
|
+
* [4, 5, 6],
|
|
99
|
+
* [7, 8, 9]
|
|
100
|
+
* ]
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example Nullable array with constraints
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const optionalIdsArray = new OasArray<true>({
|
|
107
|
+
* title: 'Optional IDs',
|
|
108
|
+
* description: 'Optional list of IDs',
|
|
109
|
+
* items: new OasInteger({ format: 'int64', minimum: 1 }),
|
|
110
|
+
* nullable: true,
|
|
111
|
+
* minItems: 0,
|
|
112
|
+
* maxItems: 10,
|
|
113
|
+
* defaultValue: null
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example Unique items validation
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const uniqueEmailsArray = new OasArray({
|
|
120
|
+
* title: 'Email Recipients',
|
|
121
|
+
* description: 'List of unique email addresses',
|
|
122
|
+
* items: new OasString({ format: 'email' }),
|
|
123
|
+
* uniqueItems: true, // Ensures no duplicate emails
|
|
124
|
+
* minItems: 1,
|
|
125
|
+
* example: ['user1@example.com', 'user2@example.com']
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
20
128
|
*/
|
|
21
129
|
export declare class OasArray<Nullable extends boolean | undefined = boolean | undefined> {
|
|
22
130
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Array.d.ts","sourceRoot":"","sources":["../../../src/oas/array/Array.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,IAAI;IAC9D,KAAK,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAA;IACnC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACzC,OAAO,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;IACtF,YAAY,CAAC,EAAE,QAAQ,SAAS,IAAI,GAAG,OAAO,E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,GAAG,OAAO,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,EAAE,GAAG,SAAS,CAAA;gBAE9E,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;IAczC,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC;IAI7B,WAAW,IAAI,QAAQ,CAAC,QAAQ,CAAC;IAIjC,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,iBAAiB;CAexE"}
|
package/esm/oas/array/Array.js
CHANGED
|
@@ -1,6 +1,98 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Represents an array schema in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* `OasArray` handles array type definitions with comprehensive validation
|
|
6
|
+
* constraints including item count limits, uniqueness requirements, and
|
|
7
|
+
* item type specifications. It supports nested schemas and references
|
|
8
|
+
* for complex array structures.
|
|
9
|
+
*
|
|
10
|
+
* This class is used throughout the OAS processing pipeline to represent
|
|
11
|
+
* array fields in API schemas, including lists of objects, primitive arrays,
|
|
12
|
+
* and complex nested array structures.
|
|
13
|
+
*
|
|
14
|
+
* ## Key Features
|
|
15
|
+
*
|
|
16
|
+
* - **Item Type Definition**: Support for any schema type as array items
|
|
17
|
+
* - **Size Constraints**: Minimum and maximum item count validation
|
|
18
|
+
* - **Uniqueness Validation**: Ensure array items are unique (like Set behavior)
|
|
19
|
+
* - **Nested Schemas**: Support for complex nested array structures
|
|
20
|
+
* - **Reference Handling**: Seamless integration with schema references
|
|
21
|
+
* - **Nullable Support**: Type-safe nullable array handling
|
|
22
|
+
* - **JSON Schema**: Conversion to standard JSON Schema format
|
|
23
|
+
*
|
|
24
|
+
* @template Nullable - Whether the array value can be null
|
|
25
|
+
*
|
|
26
|
+
* @example String array
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { OasArray, OasString } from '@skmtc/core';
|
|
29
|
+
*
|
|
30
|
+
* const tagsArray = new OasArray({
|
|
31
|
+
* title: 'Tags',
|
|
32
|
+
* description: 'List of tags associated with the item',
|
|
33
|
+
* items: new OasString({ minLength: 1 }),
|
|
34
|
+
* minItems: 1,
|
|
35
|
+
* uniqueItems: true,
|
|
36
|
+
* example: ['javascript', 'typescript', 'react']
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Object array with references
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { OasArray, OasRef } from '@skmtc/core';
|
|
43
|
+
*
|
|
44
|
+
* const usersArray = new OasArray({
|
|
45
|
+
* title: 'Users',
|
|
46
|
+
* description: 'List of user objects',
|
|
47
|
+
* items: new OasRef({ refName: 'User' }),
|
|
48
|
+
* maxItems: 100,
|
|
49
|
+
* example: [
|
|
50
|
+
* { id: 1, name: 'John' },
|
|
51
|
+
* { id: 2, name: 'Jane' }
|
|
52
|
+
* ]
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Nested array (array of arrays)
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const matrixArray = new OasArray({
|
|
59
|
+
* title: 'Matrix',
|
|
60
|
+
* description: '2D array of numbers',
|
|
61
|
+
* items: new OasArray({
|
|
62
|
+
* items: new OasInteger({ minimum: 0 })
|
|
63
|
+
* }),
|
|
64
|
+
* example: [
|
|
65
|
+
* [1, 2, 3],
|
|
66
|
+
* [4, 5, 6],
|
|
67
|
+
* [7, 8, 9]
|
|
68
|
+
* ]
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example Nullable array with constraints
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const optionalIdsArray = new OasArray<true>({
|
|
75
|
+
* title: 'Optional IDs',
|
|
76
|
+
* description: 'Optional list of IDs',
|
|
77
|
+
* items: new OasInteger({ format: 'int64', minimum: 1 }),
|
|
78
|
+
* nullable: true,
|
|
79
|
+
* minItems: 0,
|
|
80
|
+
* maxItems: 10,
|
|
81
|
+
* defaultValue: null
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example Unique items validation
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const uniqueEmailsArray = new OasArray({
|
|
88
|
+
* title: 'Email Recipients',
|
|
89
|
+
* description: 'List of unique email addresses',
|
|
90
|
+
* items: new OasString({ format: 'email' }),
|
|
91
|
+
* uniqueItems: true, // Ensures no duplicate emails
|
|
92
|
+
* minItems: 1,
|
|
93
|
+
* example: ['user1@example.com', 'user2@example.com']
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
4
96
|
*/
|
|
5
97
|
export class OasArray {
|
|
6
98
|
constructor(fields) {
|