@skmtc/core 0.0.792 → 0.0.793
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/GeneratedValueList.d.ts +158 -0
- package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
- package/esm/dsl/GeneratedValueList.js +158 -0
- package/esm/dsl/Stringable.d.ts +76 -0
- package/esm/dsl/Stringable.d.ts.map +1 -1
- package/esm/dsl/Stringable.js +75 -0
- package/esm/helpers/collateExamples.d.ts +150 -0
- package/esm/helpers/collateExamples.d.ts.map +1 -1
- package/esm/helpers/collateExamples.js +145 -0
- package/esm/helpers/formatNumber.d.ts +95 -0
- package/esm/helpers/formatNumber.d.ts.map +1 -1
- package/esm/helpers/formatNumber.js +95 -0
- package/esm/helpers/generationStats.d.ts +287 -1
- package/esm/helpers/generationStats.d.ts.map +1 -1
- package/esm/helpers/generationStats.js +266 -0
- package/esm/helpers/isEmpty.d.ts +62 -0
- package/esm/helpers/isEmpty.d.ts.map +1 -1
- package/esm/helpers/isEmpty.js +62 -0
- package/esm/helpers/isImported.d.ts +80 -0
- package/esm/helpers/isImported.d.ts.map +1 -1
- package/esm/helpers/isImported.js +80 -0
- package/esm/helpers/parseModuleName.d.ts +175 -0
- package/esm/helpers/parseModuleName.d.ts.map +1 -1
- package/esm/helpers/parseModuleName.js +153 -0
- package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
- package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
- package/esm/helpers/toResolvedArtifactPath.js +140 -0
- package/esm/oas/schema/Schema.d.ts +117 -0
- package/esm/oas/schema/Schema.d.ts.map +1 -1
- package/esm/typescript/identifiers.d.ts +159 -0
- package/esm/typescript/identifiers.d.ts.map +1 -1
- package/esm/typescript/identifiers.js +159 -0
- package/esm/typescript/withDescription.d.ts +119 -0
- package/esm/typescript/withDescription.d.ts.map +1 -1
- package/esm/typescript/withDescription.js +119 -0
- package/package.json +1 -1
- package/script/dsl/GeneratedValueList.d.ts +158 -0
- package/script/dsl/GeneratedValueList.d.ts.map +1 -1
- package/script/dsl/GeneratedValueList.js +158 -0
- package/script/dsl/Stringable.d.ts +76 -0
- package/script/dsl/Stringable.d.ts.map +1 -1
- package/script/dsl/Stringable.js +75 -0
- package/script/helpers/collateExamples.d.ts +150 -0
- package/script/helpers/collateExamples.d.ts.map +1 -1
- package/script/helpers/collateExamples.js +145 -0
- package/script/helpers/formatNumber.d.ts +95 -0
- package/script/helpers/formatNumber.d.ts.map +1 -1
- package/script/helpers/formatNumber.js +95 -0
- package/script/helpers/generationStats.d.ts +287 -1
- package/script/helpers/generationStats.d.ts.map +1 -1
- package/script/helpers/generationStats.js +266 -0
- package/script/helpers/isEmpty.d.ts +62 -0
- package/script/helpers/isEmpty.d.ts.map +1 -1
- package/script/helpers/isEmpty.js +62 -0
- package/script/helpers/isImported.d.ts +80 -0
- package/script/helpers/isImported.d.ts.map +1 -1
- package/script/helpers/isImported.js +80 -0
- package/script/helpers/parseModuleName.d.ts +175 -0
- package/script/helpers/parseModuleName.d.ts.map +1 -1
- package/script/helpers/parseModuleName.js +153 -0
- package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
- package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
- package/script/helpers/toResolvedArtifactPath.js +140 -0
- package/script/oas/schema/Schema.d.ts +117 -0
- package/script/oas/schema/Schema.d.ts.map +1 -1
- package/script/typescript/identifiers.d.ts +159 -0
- package/script/typescript/identifiers.d.ts.map +1 -1
- package/script/typescript/identifiers.js +159 -0
- package/script/typescript/withDescription.d.ts +119 -0
- package/script/typescript/withDescription.d.ts.map +1 -1
- package/script/typescript/withDescription.js +119 -0
|
@@ -2,10 +2,169 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlePropertyName = exports.handleKey = void 0;
|
|
4
4
|
const helper_validator_identifier_1 = require("@babel/helper-validator-identifier");
|
|
5
|
+
/**
|
|
6
|
+
* Safely formats a key for use in object literals, adding quotes if needed.
|
|
7
|
+
*
|
|
8
|
+
* This function determines whether a property key needs to be quoted in JavaScript/TypeScript
|
|
9
|
+
* object literals based on identifier naming rules. Valid identifiers are left unquoted,
|
|
10
|
+
* while invalid identifiers (containing spaces, special characters, starting with numbers, etc.)
|
|
11
|
+
* are wrapped in single quotes.
|
|
12
|
+
*
|
|
13
|
+
* @param key - The property key to format
|
|
14
|
+
* @returns The key as-is if it's a valid identifier, otherwise wrapped in quotes
|
|
15
|
+
*
|
|
16
|
+
* @example Valid identifiers (no quotes needed)
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { handleKey } from '@skmtc/core';
|
|
19
|
+
*
|
|
20
|
+
* console.log(handleKey('name')); // 'name'
|
|
21
|
+
* console.log(handleKey('userName')); // 'userName'
|
|
22
|
+
* console.log(handleKey('_private')); // '_private'
|
|
23
|
+
* console.log(handleKey('$special')); // '$special'
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example Invalid identifiers (quotes added)
|
|
27
|
+
* ```typescript
|
|
28
|
+
* console.log(handleKey('first-name')); // "'first-name'"
|
|
29
|
+
* console.log(handleKey('2nd-place')); // "'2nd-place'"
|
|
30
|
+
* console.log(handleKey('user name')); // "'user name'"
|
|
31
|
+
* console.log(handleKey('api-key')); // "'api-key'"
|
|
32
|
+
* console.log(handleKey('data.nested')); // "'data.nested'"
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Usage in object generation
|
|
36
|
+
* ```typescript
|
|
37
|
+
* class ObjectGenerator {
|
|
38
|
+
* generateObjectLiteral(properties: Record<string, string>) {
|
|
39
|
+
* const props = Object.entries(properties)
|
|
40
|
+
* .map(([key, value]) => `${handleKey(key)}: ${value}`)
|
|
41
|
+
* .join(', ');
|
|
42
|
+
*
|
|
43
|
+
* return `{ ${props} }`;
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* const generator = new ObjectGenerator();
|
|
48
|
+
* const result = generator.generateObjectLiteral({
|
|
49
|
+
* 'name': 'string',
|
|
50
|
+
* 'first-name': 'string',
|
|
51
|
+
* 'age': 'number'
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* console.log(result);
|
|
55
|
+
* // { name: string, 'first-name': string, age: number }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example TypeScript interface generation
|
|
59
|
+
* ```typescript
|
|
60
|
+
* function generateInterface(name: string, properties: Record<string, string>) {
|
|
61
|
+
* const props = Object.entries(properties)
|
|
62
|
+
* .map(([key, type]) => ` ${handleKey(key)}: ${type};`)
|
|
63
|
+
* .join('\n');
|
|
64
|
+
*
|
|
65
|
+
* return `interface ${name} {\n${props}\n}`;
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* const userInterface = generateInterface('User', {
|
|
69
|
+
* 'id': 'string',
|
|
70
|
+
* 'first-name': 'string',
|
|
71
|
+
* 'last_name': 'string',
|
|
72
|
+
* '2fa-enabled': 'boolean'
|
|
73
|
+
* });
|
|
74
|
+
*
|
|
75
|
+
* console.log(userInterface);
|
|
76
|
+
* // interface User {
|
|
77
|
+
* // id: string;
|
|
78
|
+
* // 'first-name': string;
|
|
79
|
+
* // last_name: string;
|
|
80
|
+
* // '2fa-enabled': boolean;
|
|
81
|
+
* // }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
5
84
|
const handleKey = (key) => {
|
|
6
85
|
return (0, helper_validator_identifier_1.isIdentifierName)(key) ? key : `'${key}'`;
|
|
7
86
|
};
|
|
8
87
|
exports.handleKey = handleKey;
|
|
88
|
+
/**
|
|
89
|
+
* Safely formats property access, using dot notation or bracket notation as appropriate.
|
|
90
|
+
*
|
|
91
|
+
* This function generates the appropriate property access syntax for JavaScript/TypeScript
|
|
92
|
+
* code. Valid identifiers use dot notation (`parent.property`), while invalid identifiers
|
|
93
|
+
* use bracket notation (`parent['property']`).
|
|
94
|
+
*
|
|
95
|
+
* @param name - The property name to access
|
|
96
|
+
* @param parent - The parent object expression
|
|
97
|
+
* @returns Properly formatted property access expression
|
|
98
|
+
*
|
|
99
|
+
* @example Valid identifiers (dot notation)
|
|
100
|
+
* ```typescript
|
|
101
|
+
* import { handlePropertyName } from '@skmtc/core';
|
|
102
|
+
*
|
|
103
|
+
* console.log(handlePropertyName('name', 'user')); // 'user.name'
|
|
104
|
+
* console.log(handlePropertyName('firstName', 'user')); // 'user.firstName'
|
|
105
|
+
* console.log(handlePropertyName('_id', 'document')); // 'document._id'
|
|
106
|
+
* console.log(handlePropertyName('$meta', 'data')); // 'data.$meta'
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example Invalid identifiers (bracket notation)
|
|
110
|
+
* ```typescript
|
|
111
|
+
* console.log(handlePropertyName('first-name', 'user')); // "user['first-name']"
|
|
112
|
+
* console.log(handlePropertyName('2nd-place', 'result')); // "result['2nd-place']"
|
|
113
|
+
* console.log(handlePropertyName('user name', 'form')); // "form['user name']"
|
|
114
|
+
* console.log(handlePropertyName('api-key', 'config')); // "config['api-key']"
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example Usage in accessor generation
|
|
118
|
+
* ```typescript
|
|
119
|
+
* class PropertyAccessor {
|
|
120
|
+
* generateGetter(objectName: string, propertyPath: string[]) {
|
|
121
|
+
* return propertyPath.reduce((acc, prop) =>
|
|
122
|
+
* handlePropertyName(prop, acc), objectName
|
|
123
|
+
* );
|
|
124
|
+
* }
|
|
125
|
+
* }
|
|
126
|
+
*
|
|
127
|
+
* const accessor = new PropertyAccessor();
|
|
128
|
+
* const path1 = accessor.generateGetter('data', ['user', 'profile', 'firstName']);
|
|
129
|
+
* const path2 = accessor.generateGetter('config', ['api-settings', 'retry-count']);
|
|
130
|
+
*
|
|
131
|
+
* console.log(path1); // 'data.user.profile.firstName'
|
|
132
|
+
* console.log(path2); // "config['api-settings']['retry-count']"
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @example Complex object navigation
|
|
136
|
+
* ```typescript
|
|
137
|
+
* function generateObjectAccess(base: string, properties: string[]) {
|
|
138
|
+
* let result = base;
|
|
139
|
+
*
|
|
140
|
+
* for (const prop of properties) {
|
|
141
|
+
* result = handlePropertyName(prop, result);
|
|
142
|
+
* }
|
|
143
|
+
*
|
|
144
|
+
* return result;
|
|
145
|
+
* }
|
|
146
|
+
*
|
|
147
|
+
* const access1 = generateObjectAccess('response', ['data', 'user-info', 'name']);
|
|
148
|
+
* const access2 = generateObjectAccess('settings', ['ui', 'theme', 'darkMode']);
|
|
149
|
+
*
|
|
150
|
+
* console.log(access1); // "response.data['user-info'].name"
|
|
151
|
+
* console.log(access2); // "settings.ui.theme.darkMode"
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @example Function generation
|
|
155
|
+
* ```typescript
|
|
156
|
+
* function generatePropertyGetter(objName: string, propName: string) {
|
|
157
|
+
* const access = handlePropertyName(propName, objName);
|
|
158
|
+
* return `function get${propName.replace(/[^a-zA-Z0-9]/g, '')}() { return ${access}; }`;
|
|
159
|
+
* }
|
|
160
|
+
*
|
|
161
|
+
* const getter1 = generatePropertyGetter('user', 'firstName');
|
|
162
|
+
* const getter2 = generatePropertyGetter('config', 'api-key');
|
|
163
|
+
*
|
|
164
|
+
* console.log(getter1); // "function getfirstName() { return user.firstName; }"
|
|
165
|
+
* console.log(getter2); // "function getapikey() { return config['api-key']; }"
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
9
168
|
const handlePropertyName = (name, parent) => {
|
|
10
169
|
return (0, helper_validator_identifier_1.isIdentifierName)(name) ? `${parent}.${name}` : `${parent}['${name}']`;
|
|
11
170
|
};
|
|
@@ -1,4 +1,123 @@
|
|
|
1
1
|
import type { Stringable } from '../dsl/Stringable.js';
|
|
2
2
|
import type { Modifiers } from '../types/Modifiers.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a value with a JSDoc comment if a description is provided.
|
|
5
|
+
*
|
|
6
|
+
* This utility function is used throughout the SKMTC code generation system to
|
|
7
|
+
* add JSDoc documentation comments to generated TypeScript code. If a description
|
|
8
|
+
* is provided, it formats it as a single-line JSDoc comment above the value.
|
|
9
|
+
* If no description is provided, the value is returned unchanged.
|
|
10
|
+
*
|
|
11
|
+
* @param value - The code value to potentially wrap with documentation
|
|
12
|
+
* @param modifiers - Modifiers object containing optional description
|
|
13
|
+
* @param modifiers.description - Optional description text for the JSDoc comment
|
|
14
|
+
* @returns The value with JSDoc comment prepended if description exists, otherwise just the value
|
|
15
|
+
*
|
|
16
|
+
* @example With description
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { withDescription } from '@skmtc/core';
|
|
19
|
+
*
|
|
20
|
+
* const result = withDescription(
|
|
21
|
+
* 'export const API_URL = "https://api.example.com";',
|
|
22
|
+
* { description: 'Base URL for all API requests' }
|
|
23
|
+
* );
|
|
24
|
+
*
|
|
25
|
+
* console.log(result);
|
|
26
|
+
* // /** Base URL for all API requests *\/
|
|
27
|
+
* // export const API_URL = "https://api.example.com";
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Without description
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const result = withDescription(
|
|
33
|
+
* 'export const API_URL = "https://api.example.com";',
|
|
34
|
+
* { description: undefined }
|
|
35
|
+
* );
|
|
36
|
+
*
|
|
37
|
+
* console.log(result);
|
|
38
|
+
* // export const API_URL = "https://api.example.com";
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example Using with Definition class
|
|
42
|
+
* ```typescript
|
|
43
|
+
* class ModelGenerator {
|
|
44
|
+
* generateInterface(name: string, description?: string) {
|
|
45
|
+
* const interfaceCode = `interface ${name} {
|
|
46
|
+
* id: string;
|
|
47
|
+
* name: string;
|
|
48
|
+
* }`;
|
|
49
|
+
*
|
|
50
|
+
* return withDescription(interfaceCode, { description });
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* const generator = new ModelGenerator();
|
|
55
|
+
* const documented = generator.generateInterface('User', 'Represents a user in the system');
|
|
56
|
+
*
|
|
57
|
+
* console.log(documented);
|
|
58
|
+
* // /** Represents a user in the system *\/
|
|
59
|
+
* // interface User {
|
|
60
|
+
* // id: string;
|
|
61
|
+
* // name: string;
|
|
62
|
+
* // }
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example Integration with generated definitions
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { Definition, Identifier, withDescription } from '@skmtc/core';
|
|
68
|
+
*
|
|
69
|
+
* class DocumentedGenerator {
|
|
70
|
+
* createDefinition(name: string, value: string, docs?: string) {
|
|
71
|
+
* return new Definition({
|
|
72
|
+
* context: this.context,
|
|
73
|
+
* identifier: Identifier.createVariable(name),
|
|
74
|
+
* description: docs, // This gets processed by withDescription internally
|
|
75
|
+
* value: {
|
|
76
|
+
* generatorKey: 'documented',
|
|
77
|
+
* content: value
|
|
78
|
+
* }
|
|
79
|
+
* });
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @example Complex documentation
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const complexDoc = withDescription(
|
|
87
|
+
* `export type Status = 'active' | 'inactive' | 'pending';`,
|
|
88
|
+
* {
|
|
89
|
+
* description: 'User account status - active users can access all features'
|
|
90
|
+
* }
|
|
91
|
+
* );
|
|
92
|
+
*
|
|
93
|
+
* console.log(complexDoc);
|
|
94
|
+
* // /** User account status - active users can access all features *\/
|
|
95
|
+
* // export type Status = 'active' | 'inactive' | 'pending';
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example Conditional documentation
|
|
99
|
+
* ```typescript
|
|
100
|
+
* function generateWithOptionalDocs(
|
|
101
|
+
* code: string,
|
|
102
|
+
* includeDescription: boolean
|
|
103
|
+
* ) {
|
|
104
|
+
* return withDescription(code, {
|
|
105
|
+
* description: includeDescription
|
|
106
|
+
* ? 'This is an auto-generated definition'
|
|
107
|
+
* : undefined
|
|
108
|
+
* });
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* const withDocs = generateWithOptionalDocs('export const VALUE = 42;', true);
|
|
112
|
+
* const withoutDocs = generateWithOptionalDocs('export const VALUE = 42;', false);
|
|
113
|
+
*
|
|
114
|
+
* console.log(withDocs);
|
|
115
|
+
* // /** This is an auto-generated definition *\/
|
|
116
|
+
* // export const VALUE = 42;
|
|
117
|
+
*
|
|
118
|
+
* console.log(withoutDocs);
|
|
119
|
+
* // export const VALUE = 42;
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
3
122
|
export declare const withDescription: (value: Stringable, { description }: Modifiers) => string;
|
|
4
123
|
//# sourceMappingURL=withDescription.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withDescription.d.ts","sourceRoot":"","sources":["../../src/typescript/withDescription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD,eAAO,MAAM,eAAe,GAC1B,OAAO,UAAU,EACjB,iBAAiB,SAAS,KACzB,MAEF,CAAA"}
|
|
1
|
+
{"version":3,"file":"withDescription.d.ts","sourceRoot":"","sources":["../../src/typescript/withDescription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsHG;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,UAAU,EACjB,iBAAiB,SAAS,KACzB,MAEF,CAAA"}
|
|
@@ -1,6 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withDescription = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a value with a JSDoc comment if a description is provided.
|
|
6
|
+
*
|
|
7
|
+
* This utility function is used throughout the SKMTC code generation system to
|
|
8
|
+
* add JSDoc documentation comments to generated TypeScript code. If a description
|
|
9
|
+
* is provided, it formats it as a single-line JSDoc comment above the value.
|
|
10
|
+
* If no description is provided, the value is returned unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @param value - The code value to potentially wrap with documentation
|
|
13
|
+
* @param modifiers - Modifiers object containing optional description
|
|
14
|
+
* @param modifiers.description - Optional description text for the JSDoc comment
|
|
15
|
+
* @returns The value with JSDoc comment prepended if description exists, otherwise just the value
|
|
16
|
+
*
|
|
17
|
+
* @example With description
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { withDescription } from '@skmtc/core';
|
|
20
|
+
*
|
|
21
|
+
* const result = withDescription(
|
|
22
|
+
* 'export const API_URL = "https://api.example.com";',
|
|
23
|
+
* { description: 'Base URL for all API requests' }
|
|
24
|
+
* );
|
|
25
|
+
*
|
|
26
|
+
* console.log(result);
|
|
27
|
+
* // /** Base URL for all API requests *\/
|
|
28
|
+
* // export const API_URL = "https://api.example.com";
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Without description
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const result = withDescription(
|
|
34
|
+
* 'export const API_URL = "https://api.example.com";',
|
|
35
|
+
* { description: undefined }
|
|
36
|
+
* );
|
|
37
|
+
*
|
|
38
|
+
* console.log(result);
|
|
39
|
+
* // export const API_URL = "https://api.example.com";
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example Using with Definition class
|
|
43
|
+
* ```typescript
|
|
44
|
+
* class ModelGenerator {
|
|
45
|
+
* generateInterface(name: string, description?: string) {
|
|
46
|
+
* const interfaceCode = `interface ${name} {
|
|
47
|
+
* id: string;
|
|
48
|
+
* name: string;
|
|
49
|
+
* }`;
|
|
50
|
+
*
|
|
51
|
+
* return withDescription(interfaceCode, { description });
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* const generator = new ModelGenerator();
|
|
56
|
+
* const documented = generator.generateInterface('User', 'Represents a user in the system');
|
|
57
|
+
*
|
|
58
|
+
* console.log(documented);
|
|
59
|
+
* // /** Represents a user in the system *\/
|
|
60
|
+
* // interface User {
|
|
61
|
+
* // id: string;
|
|
62
|
+
* // name: string;
|
|
63
|
+
* // }
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example Integration with generated definitions
|
|
67
|
+
* ```typescript
|
|
68
|
+
* import { Definition, Identifier, withDescription } from '@skmtc/core';
|
|
69
|
+
*
|
|
70
|
+
* class DocumentedGenerator {
|
|
71
|
+
* createDefinition(name: string, value: string, docs?: string) {
|
|
72
|
+
* return new Definition({
|
|
73
|
+
* context: this.context,
|
|
74
|
+
* identifier: Identifier.createVariable(name),
|
|
75
|
+
* description: docs, // This gets processed by withDescription internally
|
|
76
|
+
* value: {
|
|
77
|
+
* generatorKey: 'documented',
|
|
78
|
+
* content: value
|
|
79
|
+
* }
|
|
80
|
+
* });
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @example Complex documentation
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const complexDoc = withDescription(
|
|
88
|
+
* `export type Status = 'active' | 'inactive' | 'pending';`,
|
|
89
|
+
* {
|
|
90
|
+
* description: 'User account status - active users can access all features'
|
|
91
|
+
* }
|
|
92
|
+
* );
|
|
93
|
+
*
|
|
94
|
+
* console.log(complexDoc);
|
|
95
|
+
* // /** User account status - active users can access all features *\/
|
|
96
|
+
* // export type Status = 'active' | 'inactive' | 'pending';
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example Conditional documentation
|
|
100
|
+
* ```typescript
|
|
101
|
+
* function generateWithOptionalDocs(
|
|
102
|
+
* code: string,
|
|
103
|
+
* includeDescription: boolean
|
|
104
|
+
* ) {
|
|
105
|
+
* return withDescription(code, {
|
|
106
|
+
* description: includeDescription
|
|
107
|
+
* ? 'This is an auto-generated definition'
|
|
108
|
+
* : undefined
|
|
109
|
+
* });
|
|
110
|
+
* }
|
|
111
|
+
*
|
|
112
|
+
* const withDocs = generateWithOptionalDocs('export const VALUE = 42;', true);
|
|
113
|
+
* const withoutDocs = generateWithOptionalDocs('export const VALUE = 42;', false);
|
|
114
|
+
*
|
|
115
|
+
* console.log(withDocs);
|
|
116
|
+
* // /** This is an auto-generated definition *\/
|
|
117
|
+
* // export const VALUE = 42;
|
|
118
|
+
*
|
|
119
|
+
* console.log(withoutDocs);
|
|
120
|
+
* // export const VALUE = 42;
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
4
123
|
const withDescription = (value, { description }) => {
|
|
5
124
|
return description ? `/** ${description} */\n${value}` : `${value}`;
|
|
6
125
|
};
|