@skmtc/core 0.0.786 → 0.0.788
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/context/GenerateContext.d.ts +95 -0
- package/esm/context/GenerateContext.d.ts.map +1 -1
- package/esm/context/GenerateContext.js +95 -0
- 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/dsl/JsonFile.d.ts +162 -0
- package/esm/dsl/JsonFile.d.ts.map +1 -1
- package/esm/dsl/JsonFile.js +157 -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/operation/Operation.d.ts +107 -1
- package/esm/oas/operation/Operation.d.ts.map +1 -1
- package/esm/oas/operation/Operation.js +107 -1
- package/esm/oas/ref/Ref.d.ts +86 -0
- package/esm/oas/ref/Ref.d.ts.map +1 -1
- package/esm/oas/ref/Ref.js +86 -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/context/GenerateContext.d.ts +95 -0
- package/script/context/GenerateContext.d.ts.map +1 -1
- package/script/context/GenerateContext.js +95 -0
- 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/dsl/JsonFile.d.ts +162 -0
- package/script/dsl/JsonFile.d.ts.map +1 -1
- package/script/dsl/JsonFile.js +157 -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/operation/Operation.d.ts +107 -1
- package/script/oas/operation/Operation.d.ts.map +1 -1
- package/script/oas/operation/Operation.js +107 -1
- package/script/oas/ref/Ref.d.ts +86 -0
- package/script/oas/ref/Ref.d.ts.map +1 -1
- package/script/oas/ref/Ref.js +86 -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/script/dsl/Definition.js
CHANGED
|
@@ -3,27 +3,171 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Definition = void 0;
|
|
4
4
|
const ContentBase_js_1 = require("./ContentBase.js");
|
|
5
5
|
const withDescription_js_1 = require("../typescript/withDescription.js");
|
|
6
|
+
/**
|
|
7
|
+
* Represents a complete code definition in the SKMTC DSL system.
|
|
8
|
+
*
|
|
9
|
+
* The `Definition` class is the primary output unit of generators, representing
|
|
10
|
+
* a complete piece of generated code (like an interface, function, or constant).
|
|
11
|
+
* It combines an identifier, generated content, and optional metadata into a
|
|
12
|
+
* formatted code definition with proper TypeScript syntax.
|
|
13
|
+
*
|
|
14
|
+
* This class automatically handles export statements, type annotations, and
|
|
15
|
+
* JSDoc comment generation, making it the building block for all generated
|
|
16
|
+
* code artifacts.
|
|
17
|
+
*
|
|
18
|
+
* ## Key Features
|
|
19
|
+
*
|
|
20
|
+
* - **Automatic Exports**: Handles export keyword based on configuration
|
|
21
|
+
* - **Type Safety**: Preserves type information through generic parameters
|
|
22
|
+
* - **JSDoc Integration**: Automatic comment generation from descriptions
|
|
23
|
+
* - **Entity Type Support**: Handles different definition types (const, type, etc.)
|
|
24
|
+
* - **Identifier Management**: Integrates with the Identifier system for naming
|
|
25
|
+
*
|
|
26
|
+
* @template V - The type of generated value (preserves generator-specific types)
|
|
27
|
+
*
|
|
28
|
+
* @example Basic interface definition
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { Definition, Identifier } from '@skmtc/core';
|
|
31
|
+
*
|
|
32
|
+
* const userInterface = new Definition({
|
|
33
|
+
* context: generateContext,
|
|
34
|
+
* identifier: Identifier.createType('User'),
|
|
35
|
+
* description: 'Represents a user in the system',
|
|
36
|
+
* value: {
|
|
37
|
+
* generatorKey: 'typescript-interfaces',
|
|
38
|
+
* content: `{
|
|
39
|
+
* id: string;
|
|
40
|
+
* name: string;
|
|
41
|
+
* email: string;
|
|
42
|
+
* }`
|
|
43
|
+
* }
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* console.log(userInterface.toString());
|
|
47
|
+
* //
|
|
48
|
+
* // Represents a user in the system
|
|
49
|
+
* //
|
|
50
|
+
* // export type User = {
|
|
51
|
+
* // id: string;
|
|
52
|
+
* // name: string;
|
|
53
|
+
* // email: string;
|
|
54
|
+
* // };
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example Function definition with parameters
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const apiFunction = new Definition({
|
|
60
|
+
* context: generateContext,
|
|
61
|
+
* identifier: Identifier.createVariable('fetchUser', 'Promise<User>'),
|
|
62
|
+
* description: 'Fetches a user by ID from the API',
|
|
63
|
+
* value: {
|
|
64
|
+
* generatorKey: 'api-client',
|
|
65
|
+
* content: `async (id: string) => {
|
|
66
|
+
* const response = await fetch(\`/api/users/\${id}\`);
|
|
67
|
+
* return response.json();
|
|
68
|
+
* }`
|
|
69
|
+
* }
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* console.log(apiFunction.toString());
|
|
73
|
+
* //
|
|
74
|
+
* // Fetches a user by ID from the API
|
|
75
|
+
* //
|
|
76
|
+
* // export const fetchUser: Promise<User> = async (id: string) => {
|
|
77
|
+
* // const response = await fetch(`/api/users/${id}`);
|
|
78
|
+
* // return response.json();
|
|
79
|
+
* // };
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example Non-exported definition
|
|
83
|
+
* ```typescript
|
|
84
|
+
* const helperFunction = new Definition({
|
|
85
|
+
* context: generateContext,
|
|
86
|
+
* identifier: Identifier.createVariable('validateEmail'),
|
|
87
|
+
* value: {
|
|
88
|
+
* generatorKey: 'utilities',
|
|
89
|
+
* content: `(email: string): boolean => {
|
|
90
|
+
* return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email);
|
|
91
|
+
* }`
|
|
92
|
+
* },
|
|
93
|
+
* noExport: true // Internal helper, not exported
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* console.log(helperFunction.toString());
|
|
97
|
+
* // const validateEmail = (email: string): boolean => {
|
|
98
|
+
* // return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
99
|
+
* // };
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example Using in generator classes
|
|
103
|
+
* ```typescript
|
|
104
|
+
* import { ModelBase, Definition, Identifier } from '@skmtc/core';
|
|
105
|
+
*
|
|
106
|
+
* class TypeScriptInterface extends ModelBase {
|
|
107
|
+
* toDefinition(): Definition {
|
|
108
|
+
* const schema = this.context.getSchema(this.refName);
|
|
109
|
+
*
|
|
110
|
+
* return new Definition({
|
|
111
|
+
* context: this.context,
|
|
112
|
+
* identifier: Identifier.createType(this.refName),
|
|
113
|
+
* description: schema.description,
|
|
114
|
+
* value: {
|
|
115
|
+
* generatorKey: this.generatorKey,
|
|
116
|
+
* content: this.generateInterfaceBody(schema)
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
* }
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
6
123
|
class Definition extends ContentBase_js_1.ContentBase {
|
|
124
|
+
/**
|
|
125
|
+
* Creates a new Definition instance.
|
|
126
|
+
*
|
|
127
|
+
* @param args - Definition configuration
|
|
128
|
+
* @param args.context - Generation context for pipeline access
|
|
129
|
+
* @param args.identifier - The identifier (name and type info) for this definition
|
|
130
|
+
* @param args.value - The generated content value
|
|
131
|
+
* @param args.description - Optional description for JSDoc comments
|
|
132
|
+
* @param args.noExport - Whether to omit the export keyword (default: false)
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const constant = new Definition({
|
|
137
|
+
* context: generateContext,
|
|
138
|
+
* identifier: Identifier.createVariable('API_BASE_URL', 'string'),
|
|
139
|
+
* description: 'Base URL for all API requests',
|
|
140
|
+
* value: {
|
|
141
|
+
* generatorKey: 'constants',
|
|
142
|
+
* content: "'https://api.example.com'"
|
|
143
|
+
* }
|
|
144
|
+
* });
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
7
147
|
constructor({ context, identifier, value, description, noExport }) {
|
|
8
148
|
super({ context, generatorKey: value.generatorKey });
|
|
149
|
+
/** The identifier for this definition */
|
|
9
150
|
Object.defineProperty(this, "identifier", {
|
|
10
151
|
enumerable: true,
|
|
11
152
|
configurable: true,
|
|
12
153
|
writable: true,
|
|
13
154
|
value: void 0
|
|
14
155
|
});
|
|
156
|
+
/** Optional description for JSDoc comments */
|
|
15
157
|
Object.defineProperty(this, "description", {
|
|
16
158
|
enumerable: true,
|
|
17
159
|
configurable: true,
|
|
18
160
|
writable: true,
|
|
19
161
|
value: void 0
|
|
20
162
|
});
|
|
163
|
+
/** The generated value content */
|
|
21
164
|
Object.defineProperty(this, "value", {
|
|
22
165
|
enumerable: true,
|
|
23
166
|
configurable: true,
|
|
24
167
|
writable: true,
|
|
25
168
|
value: void 0
|
|
26
169
|
});
|
|
170
|
+
/** Whether to skip the export keyword */
|
|
27
171
|
Object.defineProperty(this, "noExport", {
|
|
28
172
|
enumerable: true,
|
|
29
173
|
configurable: true,
|
|
@@ -35,6 +179,51 @@ class Definition extends ContentBase_js_1.ContentBase {
|
|
|
35
179
|
this.description = description;
|
|
36
180
|
this.noExport = noExport;
|
|
37
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Generates the complete TypeScript definition code.
|
|
184
|
+
*
|
|
185
|
+
* This method produces a properly formatted TypeScript definition with:
|
|
186
|
+
* - Optional JSDoc comments from the description
|
|
187
|
+
* - Export keyword (unless noExport is true)
|
|
188
|
+
* - Entity type (const, type, function, etc.)
|
|
189
|
+
* - Identifier with optional type annotation
|
|
190
|
+
* - Generated value content
|
|
191
|
+
*
|
|
192
|
+
* The output follows TypeScript syntax conventions and can be written
|
|
193
|
+
* directly to a .ts file.
|
|
194
|
+
*
|
|
195
|
+
* @returns The complete TypeScript definition as a string
|
|
196
|
+
*
|
|
197
|
+
* @example Type definition
|
|
198
|
+
* ```typescript
|
|
199
|
+
* const typeDef = new Definition({
|
|
200
|
+
* context,
|
|
201
|
+
* identifier: Identifier.createType('Status'),
|
|
202
|
+
* description: 'Possible status values',
|
|
203
|
+
* value: { generatorKey: 'types', content: "'pending' | 'complete' | 'failed'" }
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* console.log(typeDef.toString());
|
|
207
|
+
* //
|
|
208
|
+
* // Possible status values
|
|
209
|
+
* //
|
|
210
|
+
* // export type Status = 'pending' | 'complete' | 'failed';
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @example Constant definition
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const constDef = new Definition({
|
|
216
|
+
* context,
|
|
217
|
+
* identifier: Identifier.createVariable('DEFAULT_TIMEOUT', 'number'),
|
|
218
|
+
* value: { generatorKey: 'config', content: '5000' }
|
|
219
|
+
* });
|
|
220
|
+
*
|
|
221
|
+
* console.log(constDef.toString());
|
|
222
|
+
* // export const DEFAULT_TIMEOUT: number = 5000;
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* @todo Move syntax to typescript package to enable language-agnostic use
|
|
226
|
+
*/
|
|
38
227
|
toString() {
|
|
39
228
|
const identifier = this.identifier.typeName
|
|
40
229
|
? `${this.identifier.name}: ${this.identifier.typeName}`
|
|
@@ -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/script/dsl/EntityType.js
CHANGED
|
@@ -2,8 +2,66 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityType = void 0;
|
|
4
4
|
const ts_pattern_1 = require("ts-pattern");
|
|
5
|
+
/**
|
|
6
|
+
* Represents the type of a TypeScript entity for code generation.
|
|
7
|
+
*
|
|
8
|
+
* `EntityType` encapsulates the distinction between different kinds of
|
|
9
|
+
* TypeScript entities, specifically variables (which become `const` declarations)
|
|
10
|
+
* and types (which become `type` or `interface` declarations).
|
|
11
|
+
*
|
|
12
|
+
* This class is used by the {@link Identifier} system to ensure that
|
|
13
|
+
* generated code uses the correct TypeScript keywords and syntax patterns.
|
|
14
|
+
*
|
|
15
|
+
* @example Variable entity type
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { EntityType } from '@skmtc/core';
|
|
18
|
+
*
|
|
19
|
+
* const variableEntity = new EntityType('variable');
|
|
20
|
+
* console.log(variableEntity.toString()); // 'const'
|
|
21
|
+
*
|
|
22
|
+
* // Used in code generation:
|
|
23
|
+
* // const API_URL = 'https://api.example.com';
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example Type entity type
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const typeEntity = new EntityType('type');
|
|
29
|
+
* console.log(typeEntity.toString()); // 'type'
|
|
30
|
+
*
|
|
31
|
+
* // Used in code generation:
|
|
32
|
+
* // type User = { id: string; name: string; };
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Integration with Identifier
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { Identifier, EntityType } from '@skmtc/core';
|
|
38
|
+
*
|
|
39
|
+
* // Create a variable identifier (uses 'const' keyword)
|
|
40
|
+
* const varId = Identifier.createVariable('API_KEY', 'string');
|
|
41
|
+
* console.log(varId.entityType.toString()); // 'const'
|
|
42
|
+
*
|
|
43
|
+
* // Create a type identifier (uses 'type' keyword)
|
|
44
|
+
* const typeId = Identifier.createType('UserStatus');
|
|
45
|
+
* console.log(typeId.entityType.toString()); // 'type'
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
5
48
|
class EntityType {
|
|
49
|
+
/**
|
|
50
|
+
* Creates a new EntityType instance.
|
|
51
|
+
*
|
|
52
|
+
* @param type - The type of entity ('variable' for const declarations, 'type' for type declarations)
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // For generating const declarations
|
|
57
|
+
* const constEntity = new EntityType('variable');
|
|
58
|
+
*
|
|
59
|
+
* // For generating type declarations
|
|
60
|
+
* const typeEntity = new EntityType('type');
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
6
63
|
constructor(type) {
|
|
64
|
+
/** The entity type discriminator */
|
|
7
65
|
Object.defineProperty(this, "type", {
|
|
8
66
|
enumerable: true,
|
|
9
67
|
configurable: true,
|
|
@@ -12,6 +70,31 @@ class EntityType {
|
|
|
12
70
|
});
|
|
13
71
|
this.type = type;
|
|
14
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns the appropriate TypeScript keyword for this entity type.
|
|
75
|
+
*
|
|
76
|
+
* This method maps the entity type to the correct TypeScript declaration
|
|
77
|
+
* keyword that should be used in generated code:
|
|
78
|
+
* - 'variable' entities become 'const' declarations
|
|
79
|
+
* - 'type' entities become 'type' declarations
|
|
80
|
+
*
|
|
81
|
+
* @returns The TypeScript keyword string ('const' or 'type')
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const varEntity = new EntityType('variable');
|
|
86
|
+
* console.log(varEntity.toString()); // 'const'
|
|
87
|
+
*
|
|
88
|
+
* const typeEntity = new EntityType('type');
|
|
89
|
+
* console.log(typeEntity.toString()); // 'type'
|
|
90
|
+
*
|
|
91
|
+
* // Used in code generation:
|
|
92
|
+
* const keyword = entityType.toString();
|
|
93
|
+
* const declaration = `${keyword} ${identifier} = ${value};`;
|
|
94
|
+
* // Results in: "const API_URL = 'https://example.com';" or
|
|
95
|
+
* // Results in: "type Status = 'active' | 'inactive';"
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
15
98
|
toString() {
|
|
16
99
|
return (0, ts_pattern_1.match)(this.type)
|
|
17
100
|
.with('variable', () => 'const')
|
package/script/dsl/JsonFile.d.ts
CHANGED
|
@@ -1,12 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructor arguments for {@link JsonFile}.
|
|
3
|
+
*/
|
|
1
4
|
type JsonFileArgs = {
|
|
5
|
+
/** The file path for the generated JSON file */
|
|
2
6
|
path: string;
|
|
7
|
+
/** The JSON content to write to the file */
|
|
3
8
|
content: Record<string, unknown>;
|
|
4
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Represents a JSON file in the SKMTC DSL system.
|
|
12
|
+
*
|
|
13
|
+
* The `JsonFile` class is used to generate JSON files as part of the code generation
|
|
14
|
+
* process. It provides a simple interface for creating configuration files, manifests,
|
|
15
|
+
* package.json files, and other JSON-based artifacts with proper formatting.
|
|
16
|
+
*
|
|
17
|
+
* ## Key Features
|
|
18
|
+
*
|
|
19
|
+
* - **JSON Formatting**: Automatically formats JSON with 2-space indentation
|
|
20
|
+
* - **Type Safety**: Accepts any valid JSON-serializable content structure
|
|
21
|
+
* - **Path Management**: Associates content with specific file paths
|
|
22
|
+
* - **String Conversion**: Easy integration with file writing systems
|
|
23
|
+
*
|
|
24
|
+
* @example Basic JSON file creation
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { JsonFile } from '@skmtc/core';
|
|
27
|
+
*
|
|
28
|
+
* const packageJson = new JsonFile({
|
|
29
|
+
* path: './package.json',
|
|
30
|
+
* content: {
|
|
31
|
+
* name: 'my-api-client',
|
|
32
|
+
* version: '1.0.0',
|
|
33
|
+
* type: 'module',
|
|
34
|
+
* main: './index.js',
|
|
35
|
+
* dependencies: {
|
|
36
|
+
* 'axios': '^1.0.0'
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const jsonContent = packageJson.toString();
|
|
42
|
+
* console.log(jsonContent);
|
|
43
|
+
* // {
|
|
44
|
+
* // "name": "my-api-client",
|
|
45
|
+
* // "version": "1.0.0",
|
|
46
|
+
* // "type": "module",
|
|
47
|
+
* // "main": "./index.js",
|
|
48
|
+
* // "dependencies": {
|
|
49
|
+
* // "axios": "^1.0.0"
|
|
50
|
+
* // }
|
|
51
|
+
* // }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Configuration file generation
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const configFile = new JsonFile({
|
|
57
|
+
* path: './src/config/api.json',
|
|
58
|
+
* content: {
|
|
59
|
+
* baseUrl: 'https://api.example.com',
|
|
60
|
+
* timeout: 5000,
|
|
61
|
+
* retryAttempts: 3,
|
|
62
|
+
* endpoints: {
|
|
63
|
+
* users: '/users',
|
|
64
|
+
* products: '/products',
|
|
65
|
+
* orders: '/orders'
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Write to file system
|
|
71
|
+
* await Deno.writeTextFile(configFile.path, configFile.toString());
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example OpenAPI specification output
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const openApiFile = new JsonFile({
|
|
77
|
+
* path: './dist/openapi.json',
|
|
78
|
+
* content: {
|
|
79
|
+
* openapi: '3.0.0',
|
|
80
|
+
* info: {
|
|
81
|
+
* title: 'My API',
|
|
82
|
+
* version: '1.0.0'
|
|
83
|
+
* },
|
|
84
|
+
* paths: {
|
|
85
|
+
* '/users': {
|
|
86
|
+
* get: {
|
|
87
|
+
* summary: 'List users',
|
|
88
|
+
* responses: {
|
|
89
|
+
* '200': {
|
|
90
|
+
* description: 'Success'
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example Using with generator registration
|
|
101
|
+
* ```typescript
|
|
102
|
+
* class MyGenerator extends ContentBase {
|
|
103
|
+
* generate() {
|
|
104
|
+
* const manifestFile = new JsonFile({
|
|
105
|
+
* path: './generated/manifest.json',
|
|
106
|
+
* content: {
|
|
107
|
+
* generatedAt: new Date().toISOString(),
|
|
108
|
+
* version: '1.0.0',
|
|
109
|
+
* files: [
|
|
110
|
+
* './models/User.ts',
|
|
111
|
+
* './models/Product.ts'
|
|
112
|
+
* ]
|
|
113
|
+
* }
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // Register with the generation context
|
|
117
|
+
* this.register({ jsonFile: manifestFile });
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
5
122
|
export declare class JsonFile {
|
|
123
|
+
/** The file type, always 'json' for JSON files */
|
|
6
124
|
fileType: 'json';
|
|
125
|
+
/** The file path for this generated JSON file */
|
|
7
126
|
path: string;
|
|
127
|
+
/** The JSON content to write to the file */
|
|
8
128
|
content: Record<string, unknown>;
|
|
129
|
+
/**
|
|
130
|
+
* Creates a new JsonFile instance.
|
|
131
|
+
*
|
|
132
|
+
* @param args - JSON file configuration
|
|
133
|
+
* @param args.path - The output path for this JSON file
|
|
134
|
+
* @param args.content - The JSON content to write
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const configFile = new JsonFile({
|
|
139
|
+
* path: './config/settings.json',
|
|
140
|
+
* content: {
|
|
141
|
+
* theme: 'dark',
|
|
142
|
+
* language: 'en',
|
|
143
|
+
* features: ['auth', 'notifications']
|
|
144
|
+
* }
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
9
148
|
constructor({ path, content }: JsonFileArgs);
|
|
149
|
+
/**
|
|
150
|
+
* Converts the JSON content to a formatted string.
|
|
151
|
+
*
|
|
152
|
+
* This method serializes the content object to JSON with 2-space indentation
|
|
153
|
+
* for readable output. The resulting string is suitable for writing directly
|
|
154
|
+
* to a file or including in the generation pipeline.
|
|
155
|
+
*
|
|
156
|
+
* @returns The formatted JSON content as a string
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const file = new JsonFile({
|
|
161
|
+
* path: './data.json',
|
|
162
|
+
* content: { name: 'test', value: 42 }
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* console.log(file.toString());
|
|
166
|
+
* // {
|
|
167
|
+
* // "name": "test",
|
|
168
|
+
* // "value": 42
|
|
169
|
+
* // }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
10
172
|
toString(): string;
|
|
11
173
|
}
|
|
12
174
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonFile.d.ts","sourceRoot":"","sources":["../../src/dsl/JsonFile.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED,qBAAa,QAAQ;IACnB,QAAQ,EAAE,MAAM,CAAS;
|
|
1
|
+
{"version":3,"file":"JsonFile.d.ts","sourceRoot":"","sources":["../../src/dsl/JsonFile.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,YAAY,GAAG;IAClB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,qBAAa,QAAQ;IACnB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAS;IAEzB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAA;IAEZ,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEhC;;;;;;;;;;;;;;;;;;OAkBG;gBACS,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,YAAY;IAK3C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|