@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/esm/dsl/Definition.d.ts
CHANGED
|
@@ -2,19 +2,218 @@ import type { GenerateContext } from '../context/GenerateContext.js';
|
|
|
2
2
|
import type { Identifier } from './Identifier.js';
|
|
3
3
|
import { ContentBase } from './ContentBase.js';
|
|
4
4
|
import type { GeneratedValue } from '../types/GeneratedValue.js';
|
|
5
|
+
/**
|
|
6
|
+
* Constructor arguments for {@link Definition}.
|
|
7
|
+
*
|
|
8
|
+
* @template V - The type of generated value this definition contains
|
|
9
|
+
*/
|
|
5
10
|
type ConstructorArgs<V extends GeneratedValue> = {
|
|
11
|
+
/** The generation context providing pipeline access */
|
|
6
12
|
context: GenerateContext;
|
|
13
|
+
/** Optional description for JSDoc comments */
|
|
7
14
|
description?: string;
|
|
15
|
+
/** The identifier for this definition */
|
|
8
16
|
identifier: Identifier;
|
|
17
|
+
/** The generated value content */
|
|
9
18
|
value: V;
|
|
19
|
+
/** Whether to skip the export keyword */
|
|
10
20
|
noExport?: boolean;
|
|
11
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Represents a complete code definition in the SKMTC DSL system.
|
|
24
|
+
*
|
|
25
|
+
* The `Definition` class is the primary output unit of generators, representing
|
|
26
|
+
* a complete piece of generated code (like an interface, function, or constant).
|
|
27
|
+
* It combines an identifier, generated content, and optional metadata into a
|
|
28
|
+
* formatted code definition with proper TypeScript syntax.
|
|
29
|
+
*
|
|
30
|
+
* This class automatically handles export statements, type annotations, and
|
|
31
|
+
* JSDoc comment generation, making it the building block for all generated
|
|
32
|
+
* code artifacts.
|
|
33
|
+
*
|
|
34
|
+
* ## Key Features
|
|
35
|
+
*
|
|
36
|
+
* - **Automatic Exports**: Handles export keyword based on configuration
|
|
37
|
+
* - **Type Safety**: Preserves type information through generic parameters
|
|
38
|
+
* - **JSDoc Integration**: Automatic comment generation from descriptions
|
|
39
|
+
* - **Entity Type Support**: Handles different definition types (const, type, etc.)
|
|
40
|
+
* - **Identifier Management**: Integrates with the Identifier system for naming
|
|
41
|
+
*
|
|
42
|
+
* @template V - The type of generated value (preserves generator-specific types)
|
|
43
|
+
*
|
|
44
|
+
* @example Basic interface definition
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { Definition, Identifier } from '@skmtc/core';
|
|
47
|
+
*
|
|
48
|
+
* const userInterface = new Definition({
|
|
49
|
+
* context: generateContext,
|
|
50
|
+
* identifier: Identifier.createType('User'),
|
|
51
|
+
* description: 'Represents a user in the system',
|
|
52
|
+
* value: {
|
|
53
|
+
* generatorKey: 'typescript-interfaces',
|
|
54
|
+
* content: `{
|
|
55
|
+
* id: string;
|
|
56
|
+
* name: string;
|
|
57
|
+
* email: string;
|
|
58
|
+
* }`
|
|
59
|
+
* }
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* console.log(userInterface.toString());
|
|
63
|
+
* //
|
|
64
|
+
* // Represents a user in the system
|
|
65
|
+
* //
|
|
66
|
+
* // export type User = {
|
|
67
|
+
* // id: string;
|
|
68
|
+
* // name: string;
|
|
69
|
+
* // email: string;
|
|
70
|
+
* // };
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example Function definition with parameters
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const apiFunction = new Definition({
|
|
76
|
+
* context: generateContext,
|
|
77
|
+
* identifier: Identifier.createVariable('fetchUser', 'Promise<User>'),
|
|
78
|
+
* description: 'Fetches a user by ID from the API',
|
|
79
|
+
* value: {
|
|
80
|
+
* generatorKey: 'api-client',
|
|
81
|
+
* content: `async (id: string) => {
|
|
82
|
+
* const response = await fetch(\`/api/users/\${id}\`);
|
|
83
|
+
* return response.json();
|
|
84
|
+
* }`
|
|
85
|
+
* }
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* console.log(apiFunction.toString());
|
|
89
|
+
* //
|
|
90
|
+
* // Fetches a user by ID from the API
|
|
91
|
+
* //
|
|
92
|
+
* // export const fetchUser: Promise<User> = async (id: string) => {
|
|
93
|
+
* // const response = await fetch(`/api/users/${id}`);
|
|
94
|
+
* // return response.json();
|
|
95
|
+
* // };
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Non-exported definition
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const helperFunction = new Definition({
|
|
101
|
+
* context: generateContext,
|
|
102
|
+
* identifier: Identifier.createVariable('validateEmail'),
|
|
103
|
+
* value: {
|
|
104
|
+
* generatorKey: 'utilities',
|
|
105
|
+
* content: `(email: string): boolean => {
|
|
106
|
+
* return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email);
|
|
107
|
+
* }`
|
|
108
|
+
* },
|
|
109
|
+
* noExport: true // Internal helper, not exported
|
|
110
|
+
* });
|
|
111
|
+
*
|
|
112
|
+
* console.log(helperFunction.toString());
|
|
113
|
+
* // const validateEmail = (email: string): boolean => {
|
|
114
|
+
* // return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
|
|
115
|
+
* // };
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @example Using in generator classes
|
|
119
|
+
* ```typescript
|
|
120
|
+
* import { ModelBase, Definition, Identifier } from '@skmtc/core';
|
|
121
|
+
*
|
|
122
|
+
* class TypeScriptInterface extends ModelBase {
|
|
123
|
+
* toDefinition(): Definition {
|
|
124
|
+
* const schema = this.context.getSchema(this.refName);
|
|
125
|
+
*
|
|
126
|
+
* return new Definition({
|
|
127
|
+
* context: this.context,
|
|
128
|
+
* identifier: Identifier.createType(this.refName),
|
|
129
|
+
* description: schema.description,
|
|
130
|
+
* value: {
|
|
131
|
+
* generatorKey: this.generatorKey,
|
|
132
|
+
* content: this.generateInterfaceBody(schema)
|
|
133
|
+
* }
|
|
134
|
+
* });
|
|
135
|
+
* }
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
12
139
|
export declare class Definition<V extends GeneratedValue = GeneratedValue> extends ContentBase {
|
|
140
|
+
/** The identifier for this definition */
|
|
13
141
|
identifier: Identifier;
|
|
142
|
+
/** Optional description for JSDoc comments */
|
|
14
143
|
description: string | undefined;
|
|
144
|
+
/** The generated value content */
|
|
15
145
|
value: V;
|
|
146
|
+
/** Whether to skip the export keyword */
|
|
16
147
|
noExport?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Creates a new Definition instance.
|
|
150
|
+
*
|
|
151
|
+
* @param args - Definition configuration
|
|
152
|
+
* @param args.context - Generation context for pipeline access
|
|
153
|
+
* @param args.identifier - The identifier (name and type info) for this definition
|
|
154
|
+
* @param args.value - The generated content value
|
|
155
|
+
* @param args.description - Optional description for JSDoc comments
|
|
156
|
+
* @param args.noExport - Whether to omit the export keyword (default: false)
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const constant = new Definition({
|
|
161
|
+
* context: generateContext,
|
|
162
|
+
* identifier: Identifier.createVariable('API_BASE_URL', 'string'),
|
|
163
|
+
* description: 'Base URL for all API requests',
|
|
164
|
+
* value: {
|
|
165
|
+
* generatorKey: 'constants',
|
|
166
|
+
* content: "'https://api.example.com'"
|
|
167
|
+
* }
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
17
171
|
constructor({ context, identifier, value, description, noExport }: ConstructorArgs<V>);
|
|
172
|
+
/**
|
|
173
|
+
* Generates the complete TypeScript definition code.
|
|
174
|
+
*
|
|
175
|
+
* This method produces a properly formatted TypeScript definition with:
|
|
176
|
+
* - Optional JSDoc comments from the description
|
|
177
|
+
* - Export keyword (unless noExport is true)
|
|
178
|
+
* - Entity type (const, type, function, etc.)
|
|
179
|
+
* - Identifier with optional type annotation
|
|
180
|
+
* - Generated value content
|
|
181
|
+
*
|
|
182
|
+
* The output follows TypeScript syntax conventions and can be written
|
|
183
|
+
* directly to a .ts file.
|
|
184
|
+
*
|
|
185
|
+
* @returns The complete TypeScript definition as a string
|
|
186
|
+
*
|
|
187
|
+
* @example Type definition
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const typeDef = new Definition({
|
|
190
|
+
* context,
|
|
191
|
+
* identifier: Identifier.createType('Status'),
|
|
192
|
+
* description: 'Possible status values',
|
|
193
|
+
* value: { generatorKey: 'types', content: "'pending' | 'complete' | 'failed'" }
|
|
194
|
+
* });
|
|
195
|
+
*
|
|
196
|
+
* console.log(typeDef.toString());
|
|
197
|
+
* //
|
|
198
|
+
* // Possible status values
|
|
199
|
+
* //
|
|
200
|
+
* // export type Status = 'pending' | 'complete' | 'failed';
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* @example Constant definition
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const constDef = new Definition({
|
|
206
|
+
* context,
|
|
207
|
+
* identifier: Identifier.createVariable('DEFAULT_TIMEOUT', 'number'),
|
|
208
|
+
* value: { generatorKey: 'config', content: '5000' }
|
|
209
|
+
* });
|
|
210
|
+
*
|
|
211
|
+
* console.log(constDef.toString());
|
|
212
|
+
* // export const DEFAULT_TIMEOUT: number = 5000;
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* @todo Move syntax to typescript package to enable language-agnostic use
|
|
216
|
+
*/
|
|
18
217
|
toString(): string;
|
|
19
218
|
}
|
|
20
219
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Definition.d.ts","sourceRoot":"","sources":["../../src/dsl/Definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAEhE,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,OAAO,EAAE,eAAe,CAAA;IACxB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,UAAU,CAAA;IACtB,KAAK,EAAE,CAAC,CAAA;IACR,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,qBAAa,UAAU,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,CAAE,SAAQ,WAAW;IACpF,UAAU,EAAE,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"Definition.d.ts","sourceRoot":"","sources":["../../src/dsl/Definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAEhE;;;;GAIG;AACH,KAAK,eAAe,CAAC,CAAC,SAAS,cAAc,IAAI;IAC/C,uDAAuD;IACvD,OAAO,EAAE,eAAe,CAAA;IACxB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,yCAAyC;IACzC,UAAU,EAAE,UAAU,CAAA;IACtB,kCAAkC;IAClC,KAAK,EAAE,CAAC,CAAA;IACR,yCAAyC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoHG;AACH,qBAAa,UAAU,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,CAAE,SAAQ,WAAW;IACpF,yCAAyC;IACzC,UAAU,EAAE,UAAU,CAAA;IAEtB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAE/B,kCAAkC;IAClC,KAAK,EAAE,CAAC,CAAA;IAER,yCAAyC;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;;;;;;;;;;;;;;;;;;;;OAsBG;gBACS,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC;IASrF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACM,QAAQ,IAAI,MAAM;CAa5B"}
|
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')
|