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