@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
|
@@ -1,18 +1,182 @@
|
|
|
1
1
|
import type { Identifier } from './Identifier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Arguments for creating empty ContentSettings without enrichments.
|
|
4
|
+
*/
|
|
2
5
|
type EmptyArgs = {
|
|
6
|
+
/** The path where generated content will be exported */
|
|
3
7
|
exportPath: string;
|
|
8
|
+
/** The identifier for the content being generated */
|
|
4
9
|
identifier: Identifier;
|
|
5
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Arguments for creating ContentSettings with enrichments.
|
|
13
|
+
*
|
|
14
|
+
* @template EnrichmentType - The type of enrichment data
|
|
15
|
+
*/
|
|
6
16
|
type CreateArgs<EnrichmentType = undefined> = {
|
|
17
|
+
/** The identifier for the content being generated */
|
|
7
18
|
identifier: Identifier;
|
|
19
|
+
/** The path where generated content will be exported */
|
|
8
20
|
exportPath: string;
|
|
21
|
+
/** Custom enrichment data for extending generation */
|
|
9
22
|
enrichments: EnrichmentType;
|
|
10
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Configuration settings for content generators in the SKMTC DSL system.
|
|
26
|
+
*
|
|
27
|
+
* `ContentSettings` encapsulates the configuration needed by generators to
|
|
28
|
+
* produce content, including where to export the generated files, how to
|
|
29
|
+
* identify the content, and any custom enrichment data for extending
|
|
30
|
+
* the generation process.
|
|
31
|
+
*
|
|
32
|
+
* This class is used by both {@link ModelBase} and {@link OperationBase}
|
|
33
|
+
* to configure their generation behavior, providing a consistent interface
|
|
34
|
+
* for generator settings across the system.
|
|
35
|
+
*
|
|
36
|
+
* ## Key Features
|
|
37
|
+
*
|
|
38
|
+
* - **Export Path Management**: Specifies where generated content should be written
|
|
39
|
+
* - **Identifier Integration**: Links content to specific identifiers for naming
|
|
40
|
+
* - **Enrichment Support**: Allows custom data to extend generation capabilities
|
|
41
|
+
* - **Type Safety**: Generic enrichment typing for compile-time validation
|
|
42
|
+
*
|
|
43
|
+
* @template EnrichmentType - The type of enrichment data (default: undefined)
|
|
44
|
+
*
|
|
45
|
+
* @example Basic settings without enrichments
|
|
46
|
+
* ```typescript
|
|
47
|
+
* import { ContentSettings, Identifier } from '@skmtc/core';
|
|
48
|
+
*
|
|
49
|
+
* const settings = ContentSettings.empty({
|
|
50
|
+
* exportPath: './src/generated/models.ts',
|
|
51
|
+
* identifier: Identifier.createType('UserModels')
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* console.log(settings.exportPath); // './src/generated/models.ts'
|
|
55
|
+
* console.log(settings.enrichments); // undefined
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example Settings with custom enrichments
|
|
59
|
+
* ```typescript
|
|
60
|
+
* type ValidationEnrichment = {
|
|
61
|
+
* validateRequired: boolean;
|
|
62
|
+
* generateComments: boolean;
|
|
63
|
+
* customValidators: string[];
|
|
64
|
+
* };
|
|
65
|
+
*
|
|
66
|
+
* const enrichedSettings = new ContentSettings({
|
|
67
|
+
* identifier: Identifier.createType('ValidatedModels'),
|
|
68
|
+
* exportPath: './src/models/validated.ts',
|
|
69
|
+
* enrichments: {
|
|
70
|
+
* validateRequired: true,
|
|
71
|
+
* generateComments: true,
|
|
72
|
+
* customValidators: ['email', 'phone']
|
|
73
|
+
* }
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // Access enrichment data in generators
|
|
77
|
+
* if (enrichedSettings.enrichments?.validateRequired) {
|
|
78
|
+
* // Generate validation logic
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example Using with ModelBase
|
|
83
|
+
* ```typescript
|
|
84
|
+
* class ValidatedModelGenerator extends ModelBase<ValidationEnrichment> {
|
|
85
|
+
* constructor(args) {
|
|
86
|
+
* super({
|
|
87
|
+
* ...args,
|
|
88
|
+
* settings: new ContentSettings({
|
|
89
|
+
* identifier: Identifier.createType(args.refName),
|
|
90
|
+
* exportPath: './src/validated-models.ts',
|
|
91
|
+
* enrichments: {
|
|
92
|
+
* validateRequired: true,
|
|
93
|
+
* generateComments: false,
|
|
94
|
+
* customValidators: []
|
|
95
|
+
* }
|
|
96
|
+
* })
|
|
97
|
+
* });
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* toDefinition(): Definition {
|
|
101
|
+
* const validation = this.settings.enrichments?.validateRequired
|
|
102
|
+
* ? this.generateValidation()
|
|
103
|
+
* : '';
|
|
104
|
+
*
|
|
105
|
+
* return new Definition({
|
|
106
|
+
* context: this.context,
|
|
107
|
+
* identifier: this.settings.identifier,
|
|
108
|
+
* value: {
|
|
109
|
+
* generatorKey: this.generatorKey,
|
|
110
|
+
* content: `${this.generateInterface()}${validation}`
|
|
111
|
+
* }
|
|
112
|
+
* });
|
|
113
|
+
* }
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
11
117
|
export declare class ContentSettings<EnrichmentType = undefined> {
|
|
118
|
+
/** The identifier for the content being generated */
|
|
12
119
|
identifier: Identifier;
|
|
120
|
+
/** The path where generated content will be exported */
|
|
13
121
|
exportPath: string;
|
|
122
|
+
/** Custom enrichment data for extending generation */
|
|
14
123
|
enrichments: EnrichmentType;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a new ContentSettings instance with enrichments.
|
|
126
|
+
*
|
|
127
|
+
* @param args - Settings configuration
|
|
128
|
+
* @param args.identifier - The identifier for the content being generated
|
|
129
|
+
* @param args.exportPath - The path where generated content will be exported
|
|
130
|
+
* @param args.enrichments - Custom enrichment data for extending generation
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const settings = new ContentSettings({
|
|
135
|
+
* identifier: Identifier.createType('ApiModels'),
|
|
136
|
+
* exportPath: './src/api/models.ts',
|
|
137
|
+
* enrichments: {
|
|
138
|
+
* includeValidation: true,
|
|
139
|
+
* format: 'detailed'
|
|
140
|
+
* }
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
15
144
|
constructor({ identifier, exportPath, enrichments }: CreateArgs<EnrichmentType>);
|
|
145
|
+
/**
|
|
146
|
+
* Factory method to create ContentSettings without enrichments.
|
|
147
|
+
*
|
|
148
|
+
* This is a convenience method for creating ContentSettings when no
|
|
149
|
+
* custom enrichment data is needed. It explicitly sets enrichments
|
|
150
|
+
* to undefined and returns a properly typed instance.
|
|
151
|
+
*
|
|
152
|
+
* @param args - Basic settings arguments
|
|
153
|
+
* @param args.identifier - The identifier for the content being generated
|
|
154
|
+
* @param args.exportPath - The path where generated content will be exported
|
|
155
|
+
* @returns ContentSettings instance with undefined enrichments
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const basicSettings = ContentSettings.empty({
|
|
160
|
+
* identifier: Identifier.createType('SimpleModels'),
|
|
161
|
+
* exportPath: './src/models.ts'
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* console.log(basicSettings.enrichments); // undefined
|
|
165
|
+
*
|
|
166
|
+
* // Use in generator
|
|
167
|
+
* class SimpleGenerator extends ModelBase {
|
|
168
|
+
* constructor(args) {
|
|
169
|
+
* super({
|
|
170
|
+
* ...args,
|
|
171
|
+
* settings: ContentSettings.empty({
|
|
172
|
+
* identifier: Identifier.createType(args.refName),
|
|
173
|
+
* exportPath: './src/simple-models.ts'
|
|
174
|
+
* })
|
|
175
|
+
* });
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
16
180
|
static empty({ identifier, exportPath }: EmptyArgs): ContentSettings<undefined>;
|
|
17
181
|
}
|
|
18
182
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSettings.d.ts","sourceRoot":"","sources":["../../src/dsl/ContentSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,KAAK,SAAS,GAAG;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED,KAAK,UAAU,CAAC,cAAc,GAAG,SAAS,IAAI;IAC5C,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,cAAc,CAAA;CAC5B,CAAA;AAED,qBAAa,eAAe,CAAC,cAAc,GAAG,SAAS;IACrD,UAAU,EAAE,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"ContentSettings.d.ts","sourceRoot":"","sources":["../../src/dsl/ContentSettings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD;;GAEG;AACH,KAAK,SAAS,GAAG;IACf,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAA;IAClB,qDAAqD;IACrD,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED;;;;GAIG;AACH,KAAK,UAAU,CAAC,cAAc,GAAG,SAAS,IAAI;IAC5C,qDAAqD;IACrD,UAAU,EAAE,UAAU,CAAA;IACtB,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAA;IAClB,sDAAsD;IACtD,WAAW,EAAE,cAAc,CAAA;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4FG;AACH,qBAAa,eAAe,CAAC,cAAc,GAAG,SAAS;IACrD,qDAAqD;IACrD,UAAU,EAAE,UAAU,CAAA;IAEtB,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAA;IAElB,sDAAsD;IACtD,WAAW,EAAE,cAAc,CAAA;IAE3B;;;;;;;;;;;;;;;;;;;OAmBG;gBACS,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,UAAU,CAAC,cAAc,CAAC;IAM/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,MAAM,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC;CAOhF"}
|
|
@@ -1,17 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration settings for content generators in the SKMTC DSL system.
|
|
3
|
+
*
|
|
4
|
+
* `ContentSettings` encapsulates the configuration needed by generators to
|
|
5
|
+
* produce content, including where to export the generated files, how to
|
|
6
|
+
* identify the content, and any custom enrichment data for extending
|
|
7
|
+
* the generation process.
|
|
8
|
+
*
|
|
9
|
+
* This class is used by both {@link ModelBase} and {@link OperationBase}
|
|
10
|
+
* to configure their generation behavior, providing a consistent interface
|
|
11
|
+
* for generator settings across the system.
|
|
12
|
+
*
|
|
13
|
+
* ## Key Features
|
|
14
|
+
*
|
|
15
|
+
* - **Export Path Management**: Specifies where generated content should be written
|
|
16
|
+
* - **Identifier Integration**: Links content to specific identifiers for naming
|
|
17
|
+
* - **Enrichment Support**: Allows custom data to extend generation capabilities
|
|
18
|
+
* - **Type Safety**: Generic enrichment typing for compile-time validation
|
|
19
|
+
*
|
|
20
|
+
* @template EnrichmentType - The type of enrichment data (default: undefined)
|
|
21
|
+
*
|
|
22
|
+
* @example Basic settings without enrichments
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import { ContentSettings, Identifier } from '@skmtc/core';
|
|
25
|
+
*
|
|
26
|
+
* const settings = ContentSettings.empty({
|
|
27
|
+
* exportPath: './src/generated/models.ts',
|
|
28
|
+
* identifier: Identifier.createType('UserModels')
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* console.log(settings.exportPath); // './src/generated/models.ts'
|
|
32
|
+
* console.log(settings.enrichments); // undefined
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Settings with custom enrichments
|
|
36
|
+
* ```typescript
|
|
37
|
+
* type ValidationEnrichment = {
|
|
38
|
+
* validateRequired: boolean;
|
|
39
|
+
* generateComments: boolean;
|
|
40
|
+
* customValidators: string[];
|
|
41
|
+
* };
|
|
42
|
+
*
|
|
43
|
+
* const enrichedSettings = new ContentSettings({
|
|
44
|
+
* identifier: Identifier.createType('ValidatedModels'),
|
|
45
|
+
* exportPath: './src/models/validated.ts',
|
|
46
|
+
* enrichments: {
|
|
47
|
+
* validateRequired: true,
|
|
48
|
+
* generateComments: true,
|
|
49
|
+
* customValidators: ['email', 'phone']
|
|
50
|
+
* }
|
|
51
|
+
* });
|
|
52
|
+
*
|
|
53
|
+
* // Access enrichment data in generators
|
|
54
|
+
* if (enrichedSettings.enrichments?.validateRequired) {
|
|
55
|
+
* // Generate validation logic
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Using with ModelBase
|
|
60
|
+
* ```typescript
|
|
61
|
+
* class ValidatedModelGenerator extends ModelBase<ValidationEnrichment> {
|
|
62
|
+
* constructor(args) {
|
|
63
|
+
* super({
|
|
64
|
+
* ...args,
|
|
65
|
+
* settings: new ContentSettings({
|
|
66
|
+
* identifier: Identifier.createType(args.refName),
|
|
67
|
+
* exportPath: './src/validated-models.ts',
|
|
68
|
+
* enrichments: {
|
|
69
|
+
* validateRequired: true,
|
|
70
|
+
* generateComments: false,
|
|
71
|
+
* customValidators: []
|
|
72
|
+
* }
|
|
73
|
+
* })
|
|
74
|
+
* });
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* toDefinition(): Definition {
|
|
78
|
+
* const validation = this.settings.enrichments?.validateRequired
|
|
79
|
+
* ? this.generateValidation()
|
|
80
|
+
* : '';
|
|
81
|
+
*
|
|
82
|
+
* return new Definition({
|
|
83
|
+
* context: this.context,
|
|
84
|
+
* identifier: this.settings.identifier,
|
|
85
|
+
* value: {
|
|
86
|
+
* generatorKey: this.generatorKey,
|
|
87
|
+
* content: `${this.generateInterface()}${validation}`
|
|
88
|
+
* }
|
|
89
|
+
* });
|
|
90
|
+
* }
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
1
94
|
export class ContentSettings {
|
|
95
|
+
/**
|
|
96
|
+
* Creates a new ContentSettings instance with enrichments.
|
|
97
|
+
*
|
|
98
|
+
* @param args - Settings configuration
|
|
99
|
+
* @param args.identifier - The identifier for the content being generated
|
|
100
|
+
* @param args.exportPath - The path where generated content will be exported
|
|
101
|
+
* @param args.enrichments - Custom enrichment data for extending generation
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const settings = new ContentSettings({
|
|
106
|
+
* identifier: Identifier.createType('ApiModels'),
|
|
107
|
+
* exportPath: './src/api/models.ts',
|
|
108
|
+
* enrichments: {
|
|
109
|
+
* includeValidation: true,
|
|
110
|
+
* format: 'detailed'
|
|
111
|
+
* }
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
2
115
|
constructor({ identifier, exportPath, enrichments }) {
|
|
116
|
+
/** The identifier for the content being generated */
|
|
3
117
|
Object.defineProperty(this, "identifier", {
|
|
4
118
|
enumerable: true,
|
|
5
119
|
configurable: true,
|
|
6
120
|
writable: true,
|
|
7
121
|
value: void 0
|
|
8
122
|
});
|
|
123
|
+
/** The path where generated content will be exported */
|
|
9
124
|
Object.defineProperty(this, "exportPath", {
|
|
10
125
|
enumerable: true,
|
|
11
126
|
configurable: true,
|
|
12
127
|
writable: true,
|
|
13
128
|
value: void 0
|
|
14
129
|
});
|
|
130
|
+
/** Custom enrichment data for extending generation */
|
|
15
131
|
Object.defineProperty(this, "enrichments", {
|
|
16
132
|
enumerable: true,
|
|
17
133
|
configurable: true,
|
|
@@ -22,6 +138,41 @@ export class ContentSettings {
|
|
|
22
138
|
this.exportPath = exportPath;
|
|
23
139
|
this.enrichments = enrichments;
|
|
24
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Factory method to create ContentSettings without enrichments.
|
|
143
|
+
*
|
|
144
|
+
* This is a convenience method for creating ContentSettings when no
|
|
145
|
+
* custom enrichment data is needed. It explicitly sets enrichments
|
|
146
|
+
* to undefined and returns a properly typed instance.
|
|
147
|
+
*
|
|
148
|
+
* @param args - Basic settings arguments
|
|
149
|
+
* @param args.identifier - The identifier for the content being generated
|
|
150
|
+
* @param args.exportPath - The path where generated content will be exported
|
|
151
|
+
* @returns ContentSettings instance with undefined enrichments
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const basicSettings = ContentSettings.empty({
|
|
156
|
+
* identifier: Identifier.createType('SimpleModels'),
|
|
157
|
+
* exportPath: './src/models.ts'
|
|
158
|
+
* });
|
|
159
|
+
*
|
|
160
|
+
* console.log(basicSettings.enrichments); // undefined
|
|
161
|
+
*
|
|
162
|
+
* // Use in generator
|
|
163
|
+
* class SimpleGenerator extends ModelBase {
|
|
164
|
+
* constructor(args) {
|
|
165
|
+
* super({
|
|
166
|
+
* ...args,
|
|
167
|
+
* settings: ContentSettings.empty({
|
|
168
|
+
* identifier: Identifier.createType(args.refName),
|
|
169
|
+
* exportPath: './src/simple-models.ts'
|
|
170
|
+
* })
|
|
171
|
+
* });
|
|
172
|
+
* }
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
25
176
|
static empty({ identifier, exportPath }) {
|
|
26
177
|
return new ContentSettings({
|
|
27
178
|
identifier,
|
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"}
|