@skmtc/core 0.0.787 → 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/JsonFile.d.ts +162 -0
- package/esm/dsl/JsonFile.d.ts.map +1 -1
- package/esm/dsl/JsonFile.js +157 -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/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/JsonFile.d.ts +162 -0
- package/script/dsl/JsonFile.d.ts.map +1 -1
- package/script/dsl/JsonFile.js +157 -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
|
@@ -114,6 +114,101 @@ type GenerateResult = {
|
|
|
114
114
|
previews: Record<string, Record<string, Preview>>;
|
|
115
115
|
mappings: Record<string, Record<string, Mapping>>;
|
|
116
116
|
};
|
|
117
|
+
/**
|
|
118
|
+
* The generation context for the second phase of the SKMTC transformation pipeline.
|
|
119
|
+
*
|
|
120
|
+
* `GenerateContext` manages the transformation of parsed OAS (OpenAPI Schema) objects
|
|
121
|
+
* into code artifacts using pluggable generators. It provides APIs for model and operation
|
|
122
|
+
* generation, file management, dependency tracking, and artifact registration.
|
|
123
|
+
*
|
|
124
|
+
* ## Key Responsibilities
|
|
125
|
+
*
|
|
126
|
+
* - **Generator Orchestration**: Executes pluggable model and operation generators
|
|
127
|
+
* - **Schema Processing**: Provides utilities for working with OAS schemas and references
|
|
128
|
+
* - **File Management**: Handles file creation, imports, exports, and dependencies
|
|
129
|
+
* - **Artifact Registration**: Collects generated definitions and files for rendering
|
|
130
|
+
* - **Type System Integration**: Bridges OAS types with generator-specific type systems
|
|
131
|
+
* - **Settings Management**: Handles skipping logic and client customizations
|
|
132
|
+
*
|
|
133
|
+
* ## Generator Integration
|
|
134
|
+
*
|
|
135
|
+
* The context works with two main types of generators:
|
|
136
|
+
* - **Model Generators**: Transform schema definitions into type definitions
|
|
137
|
+
* - **Operation Generators**: Transform API operations into client functions
|
|
138
|
+
*
|
|
139
|
+
* @example Basic usage in a model generator
|
|
140
|
+
* ```typescript
|
|
141
|
+
* import { ModelBase } from '@skmtc/core';
|
|
142
|
+
*
|
|
143
|
+
* class TypeScriptInterface extends ModelBase {
|
|
144
|
+
* generate(): Definition {
|
|
145
|
+
* const schema = this.context.getSchema(this.refName);
|
|
146
|
+
*
|
|
147
|
+
* return new Definition({
|
|
148
|
+
* context: this.context,
|
|
149
|
+
* identifier: Identifier.createType(this.refName),
|
|
150
|
+
* description: schema.description,
|
|
151
|
+
* value: {
|
|
152
|
+
* generatorKey: this.generatorKey,
|
|
153
|
+
* content: this.generateInterfaceBody(schema)
|
|
154
|
+
* }
|
|
155
|
+
* });
|
|
156
|
+
* }
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @example Operation generator usage
|
|
161
|
+
* ```typescript
|
|
162
|
+
* class ApiClientGenerator extends OperationBase {
|
|
163
|
+
* generate(): Definition {
|
|
164
|
+
* const operation = this.context.getOperation(this.path, this.method);
|
|
165
|
+
*
|
|
166
|
+
* const functionName = this.context.createOperationName(this.path, this.method);
|
|
167
|
+
*
|
|
168
|
+
* return new Definition({
|
|
169
|
+
* context: this.context,
|
|
170
|
+
* identifier: Identifier.createVariable(functionName),
|
|
171
|
+
* value: {
|
|
172
|
+
* generatorKey: this.generatorKey,
|
|
173
|
+
* content: this.generateClientFunction(operation)
|
|
174
|
+
* }
|
|
175
|
+
* });
|
|
176
|
+
* }
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @example Schema and type system integration
|
|
181
|
+
* ```typescript
|
|
182
|
+
* class MyGenerator extends ModelBase {
|
|
183
|
+
* generate(): Definition {
|
|
184
|
+
* const schema = this.context.getSchema(this.refName);
|
|
185
|
+
*
|
|
186
|
+
* // Transform schema using type system
|
|
187
|
+
* const typeOutput = this.context.transformSchema(schema, {
|
|
188
|
+
* stringType: 'string',
|
|
189
|
+
* numberType: 'number',
|
|
190
|
+
* arrayType: (items) => `Array<${items}>`
|
|
191
|
+
* });
|
|
192
|
+
*
|
|
193
|
+
* // Register dependencies
|
|
194
|
+
* if (schema.hasReferences()) {
|
|
195
|
+
* this.context.addImportsToFile('./models/types.ts', {
|
|
196
|
+
* './common': ['BaseModel']
|
|
197
|
+
* });
|
|
198
|
+
* }
|
|
199
|
+
*
|
|
200
|
+
* return new Definition({
|
|
201
|
+
* context: this.context,
|
|
202
|
+
* identifier: Identifier.createType(this.refName),
|
|
203
|
+
* value: {
|
|
204
|
+
* generatorKey: this.generatorKey,
|
|
205
|
+
* content: typeOutput.content
|
|
206
|
+
* }
|
|
207
|
+
* });
|
|
208
|
+
* }
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
117
212
|
export declare class GenerateContext {
|
|
118
213
|
#private;
|
|
119
214
|
oasDocument: OasDocument;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateContext.d.ts","sourceRoot":"","sources":["../../src/context/GenerateContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,KAAK,EAAE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W,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,0BAA0B,iBAAiB,KAAG,WAI1E,CAAA"}
|
|
@@ -23,6 +23,101 @@ import { File } from '../dsl/File.js';
|
|
|
23
23
|
import { JsonFile } from '../dsl/JsonFile.js';
|
|
24
24
|
import invariant from 'tiny-invariant';
|
|
25
25
|
import { match } from 'ts-pattern';
|
|
26
|
+
/**
|
|
27
|
+
* The generation context for the second phase of the SKMTC transformation pipeline.
|
|
28
|
+
*
|
|
29
|
+
* `GenerateContext` manages the transformation of parsed OAS (OpenAPI Schema) objects
|
|
30
|
+
* into code artifacts using pluggable generators. It provides APIs for model and operation
|
|
31
|
+
* generation, file management, dependency tracking, and artifact registration.
|
|
32
|
+
*
|
|
33
|
+
* ## Key Responsibilities
|
|
34
|
+
*
|
|
35
|
+
* - **Generator Orchestration**: Executes pluggable model and operation generators
|
|
36
|
+
* - **Schema Processing**: Provides utilities for working with OAS schemas and references
|
|
37
|
+
* - **File Management**: Handles file creation, imports, exports, and dependencies
|
|
38
|
+
* - **Artifact Registration**: Collects generated definitions and files for rendering
|
|
39
|
+
* - **Type System Integration**: Bridges OAS types with generator-specific type systems
|
|
40
|
+
* - **Settings Management**: Handles skipping logic and client customizations
|
|
41
|
+
*
|
|
42
|
+
* ## Generator Integration
|
|
43
|
+
*
|
|
44
|
+
* The context works with two main types of generators:
|
|
45
|
+
* - **Model Generators**: Transform schema definitions into type definitions
|
|
46
|
+
* - **Operation Generators**: Transform API operations into client functions
|
|
47
|
+
*
|
|
48
|
+
* @example Basic usage in a model generator
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { ModelBase } from '@skmtc/core';
|
|
51
|
+
*
|
|
52
|
+
* class TypeScriptInterface extends ModelBase {
|
|
53
|
+
* generate(): Definition {
|
|
54
|
+
* const schema = this.context.getSchema(this.refName);
|
|
55
|
+
*
|
|
56
|
+
* return new Definition({
|
|
57
|
+
* context: this.context,
|
|
58
|
+
* identifier: Identifier.createType(this.refName),
|
|
59
|
+
* description: schema.description,
|
|
60
|
+
* value: {
|
|
61
|
+
* generatorKey: this.generatorKey,
|
|
62
|
+
* content: this.generateInterfaceBody(schema)
|
|
63
|
+
* }
|
|
64
|
+
* });
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Operation generator usage
|
|
70
|
+
* ```typescript
|
|
71
|
+
* class ApiClientGenerator extends OperationBase {
|
|
72
|
+
* generate(): Definition {
|
|
73
|
+
* const operation = this.context.getOperation(this.path, this.method);
|
|
74
|
+
*
|
|
75
|
+
* const functionName = this.context.createOperationName(this.path, this.method);
|
|
76
|
+
*
|
|
77
|
+
* return new Definition({
|
|
78
|
+
* context: this.context,
|
|
79
|
+
* identifier: Identifier.createVariable(functionName),
|
|
80
|
+
* value: {
|
|
81
|
+
* generatorKey: this.generatorKey,
|
|
82
|
+
* content: this.generateClientFunction(operation)
|
|
83
|
+
* }
|
|
84
|
+
* });
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example Schema and type system integration
|
|
90
|
+
* ```typescript
|
|
91
|
+
* class MyGenerator extends ModelBase {
|
|
92
|
+
* generate(): Definition {
|
|
93
|
+
* const schema = this.context.getSchema(this.refName);
|
|
94
|
+
*
|
|
95
|
+
* // Transform schema using type system
|
|
96
|
+
* const typeOutput = this.context.transformSchema(schema, {
|
|
97
|
+
* stringType: 'string',
|
|
98
|
+
* numberType: 'number',
|
|
99
|
+
* arrayType: (items) => `Array<${items}>`
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* // Register dependencies
|
|
103
|
+
* if (schema.hasReferences()) {
|
|
104
|
+
* this.context.addImportsToFile('./models/types.ts', {
|
|
105
|
+
* './common': ['BaseModel']
|
|
106
|
+
* });
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* return new Definition({
|
|
110
|
+
* context: this.context,
|
|
111
|
+
* identifier: Identifier.createType(this.refName),
|
|
112
|
+
* value: {
|
|
113
|
+
* generatorKey: this.generatorKey,
|
|
114
|
+
* content: typeOutput.content
|
|
115
|
+
* }
|
|
116
|
+
* });
|
|
117
|
+
* }
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
26
121
|
export class GenerateContext {
|
|
27
122
|
constructor({ oasDocument, settings, logger, captureCurrentResult, stackTrail, toGeneratorConfigMap }) {
|
|
28
123
|
_GenerateContext_instances.add(this);
|
package/esm/dsl/JsonFile.d.ts
CHANGED
|
@@ -1,12 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructor arguments for {@link JsonFile}.
|
|
3
|
+
*/
|
|
1
4
|
type JsonFileArgs = {
|
|
5
|
+
/** The file path for the generated JSON file */
|
|
2
6
|
path: string;
|
|
7
|
+
/** The JSON content to write to the file */
|
|
3
8
|
content: Record<string, unknown>;
|
|
4
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Represents a JSON file in the SKMTC DSL system.
|
|
12
|
+
*
|
|
13
|
+
* The `JsonFile` class is used to generate JSON files as part of the code generation
|
|
14
|
+
* process. It provides a simple interface for creating configuration files, manifests,
|
|
15
|
+
* package.json files, and other JSON-based artifacts with proper formatting.
|
|
16
|
+
*
|
|
17
|
+
* ## Key Features
|
|
18
|
+
*
|
|
19
|
+
* - **JSON Formatting**: Automatically formats JSON with 2-space indentation
|
|
20
|
+
* - **Type Safety**: Accepts any valid JSON-serializable content structure
|
|
21
|
+
* - **Path Management**: Associates content with specific file paths
|
|
22
|
+
* - **String Conversion**: Easy integration with file writing systems
|
|
23
|
+
*
|
|
24
|
+
* @example Basic JSON file creation
|
|
25
|
+
* ```typescript
|
|
26
|
+
* import { JsonFile } from '@skmtc/core';
|
|
27
|
+
*
|
|
28
|
+
* const packageJson = new JsonFile({
|
|
29
|
+
* path: './package.json',
|
|
30
|
+
* content: {
|
|
31
|
+
* name: 'my-api-client',
|
|
32
|
+
* version: '1.0.0',
|
|
33
|
+
* type: 'module',
|
|
34
|
+
* main: './index.js',
|
|
35
|
+
* dependencies: {
|
|
36
|
+
* 'axios': '^1.0.0'
|
|
37
|
+
* }
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* const jsonContent = packageJson.toString();
|
|
42
|
+
* console.log(jsonContent);
|
|
43
|
+
* // {
|
|
44
|
+
* // "name": "my-api-client",
|
|
45
|
+
* // "version": "1.0.0",
|
|
46
|
+
* // "type": "module",
|
|
47
|
+
* // "main": "./index.js",
|
|
48
|
+
* // "dependencies": {
|
|
49
|
+
* // "axios": "^1.0.0"
|
|
50
|
+
* // }
|
|
51
|
+
* // }
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example Configuration file generation
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const configFile = new JsonFile({
|
|
57
|
+
* path: './src/config/api.json',
|
|
58
|
+
* content: {
|
|
59
|
+
* baseUrl: 'https://api.example.com',
|
|
60
|
+
* timeout: 5000,
|
|
61
|
+
* retryAttempts: 3,
|
|
62
|
+
* endpoints: {
|
|
63
|
+
* users: '/users',
|
|
64
|
+
* products: '/products',
|
|
65
|
+
* orders: '/orders'
|
|
66
|
+
* }
|
|
67
|
+
* }
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Write to file system
|
|
71
|
+
* await Deno.writeTextFile(configFile.path, configFile.toString());
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example OpenAPI specification output
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const openApiFile = new JsonFile({
|
|
77
|
+
* path: './dist/openapi.json',
|
|
78
|
+
* content: {
|
|
79
|
+
* openapi: '3.0.0',
|
|
80
|
+
* info: {
|
|
81
|
+
* title: 'My API',
|
|
82
|
+
* version: '1.0.0'
|
|
83
|
+
* },
|
|
84
|
+
* paths: {
|
|
85
|
+
* '/users': {
|
|
86
|
+
* get: {
|
|
87
|
+
* summary: 'List users',
|
|
88
|
+
* responses: {
|
|
89
|
+
* '200': {
|
|
90
|
+
* description: 'Success'
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example Using with generator registration
|
|
101
|
+
* ```typescript
|
|
102
|
+
* class MyGenerator extends ContentBase {
|
|
103
|
+
* generate() {
|
|
104
|
+
* const manifestFile = new JsonFile({
|
|
105
|
+
* path: './generated/manifest.json',
|
|
106
|
+
* content: {
|
|
107
|
+
* generatedAt: new Date().toISOString(),
|
|
108
|
+
* version: '1.0.0',
|
|
109
|
+
* files: [
|
|
110
|
+
* './models/User.ts',
|
|
111
|
+
* './models/Product.ts'
|
|
112
|
+
* ]
|
|
113
|
+
* }
|
|
114
|
+
* });
|
|
115
|
+
*
|
|
116
|
+
* // Register with the generation context
|
|
117
|
+
* this.register({ jsonFile: manifestFile });
|
|
118
|
+
* }
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
5
122
|
export declare class JsonFile {
|
|
123
|
+
/** The file type, always 'json' for JSON files */
|
|
6
124
|
fileType: 'json';
|
|
125
|
+
/** The file path for this generated JSON file */
|
|
7
126
|
path: string;
|
|
127
|
+
/** The JSON content to write to the file */
|
|
8
128
|
content: Record<string, unknown>;
|
|
129
|
+
/**
|
|
130
|
+
* Creates a new JsonFile instance.
|
|
131
|
+
*
|
|
132
|
+
* @param args - JSON file configuration
|
|
133
|
+
* @param args.path - The output path for this JSON file
|
|
134
|
+
* @param args.content - The JSON content to write
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const configFile = new JsonFile({
|
|
139
|
+
* path: './config/settings.json',
|
|
140
|
+
* content: {
|
|
141
|
+
* theme: 'dark',
|
|
142
|
+
* language: 'en',
|
|
143
|
+
* features: ['auth', 'notifications']
|
|
144
|
+
* }
|
|
145
|
+
* });
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
9
148
|
constructor({ path, content }: JsonFileArgs);
|
|
149
|
+
/**
|
|
150
|
+
* Converts the JSON content to a formatted string.
|
|
151
|
+
*
|
|
152
|
+
* This method serializes the content object to JSON with 2-space indentation
|
|
153
|
+
* for readable output. The resulting string is suitable for writing directly
|
|
154
|
+
* to a file or including in the generation pipeline.
|
|
155
|
+
*
|
|
156
|
+
* @returns The formatted JSON content as a string
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const file = new JsonFile({
|
|
161
|
+
* path: './data.json',
|
|
162
|
+
* content: { name: 'test', value: 42 }
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* console.log(file.toString());
|
|
166
|
+
* // {
|
|
167
|
+
* // "name": "test",
|
|
168
|
+
* // "value": 42
|
|
169
|
+
* // }
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
10
172
|
toString(): string;
|
|
11
173
|
}
|
|
12
174
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JsonFile.d.ts","sourceRoot":"","sources":["../../src/dsl/JsonFile.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED,qBAAa,QAAQ;IACnB,QAAQ,EAAE,MAAM,CAAS;
|
|
1
|
+
{"version":3,"file":"JsonFile.d.ts","sourceRoot":"","sources":["../../src/dsl/JsonFile.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,YAAY,GAAG;IAClB,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAA;IACZ,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+GG;AACH,qBAAa,QAAQ;IACnB,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAS;IAEzB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAA;IAEZ,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAEhC;;;;;;;;;;;;;;;;;;OAkBG;gBACS,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,YAAY;IAK3C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,IAAI,MAAM;CAGnB"}
|
package/esm/dsl/JsonFile.js
CHANGED
|
@@ -1,17 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a JSON file in the SKMTC DSL system.
|
|
3
|
+
*
|
|
4
|
+
* The `JsonFile` class is used to generate JSON files as part of the code generation
|
|
5
|
+
* process. It provides a simple interface for creating configuration files, manifests,
|
|
6
|
+
* package.json files, and other JSON-based artifacts with proper formatting.
|
|
7
|
+
*
|
|
8
|
+
* ## Key Features
|
|
9
|
+
*
|
|
10
|
+
* - **JSON Formatting**: Automatically formats JSON with 2-space indentation
|
|
11
|
+
* - **Type Safety**: Accepts any valid JSON-serializable content structure
|
|
12
|
+
* - **Path Management**: Associates content with specific file paths
|
|
13
|
+
* - **String Conversion**: Easy integration with file writing systems
|
|
14
|
+
*
|
|
15
|
+
* @example Basic JSON file creation
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import { JsonFile } from '@skmtc/core';
|
|
18
|
+
*
|
|
19
|
+
* const packageJson = new JsonFile({
|
|
20
|
+
* path: './package.json',
|
|
21
|
+
* content: {
|
|
22
|
+
* name: 'my-api-client',
|
|
23
|
+
* version: '1.0.0',
|
|
24
|
+
* type: 'module',
|
|
25
|
+
* main: './index.js',
|
|
26
|
+
* dependencies: {
|
|
27
|
+
* 'axios': '^1.0.0'
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* const jsonContent = packageJson.toString();
|
|
33
|
+
* console.log(jsonContent);
|
|
34
|
+
* // {
|
|
35
|
+
* // "name": "my-api-client",
|
|
36
|
+
* // "version": "1.0.0",
|
|
37
|
+
* // "type": "module",
|
|
38
|
+
* // "main": "./index.js",
|
|
39
|
+
* // "dependencies": {
|
|
40
|
+
* // "axios": "^1.0.0"
|
|
41
|
+
* // }
|
|
42
|
+
* // }
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @example Configuration file generation
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const configFile = new JsonFile({
|
|
48
|
+
* path: './src/config/api.json',
|
|
49
|
+
* content: {
|
|
50
|
+
* baseUrl: 'https://api.example.com',
|
|
51
|
+
* timeout: 5000,
|
|
52
|
+
* retryAttempts: 3,
|
|
53
|
+
* endpoints: {
|
|
54
|
+
* users: '/users',
|
|
55
|
+
* products: '/products',
|
|
56
|
+
* orders: '/orders'
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* // Write to file system
|
|
62
|
+
* await Deno.writeTextFile(configFile.path, configFile.toString());
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example OpenAPI specification output
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const openApiFile = new JsonFile({
|
|
68
|
+
* path: './dist/openapi.json',
|
|
69
|
+
* content: {
|
|
70
|
+
* openapi: '3.0.0',
|
|
71
|
+
* info: {
|
|
72
|
+
* title: 'My API',
|
|
73
|
+
* version: '1.0.0'
|
|
74
|
+
* },
|
|
75
|
+
* paths: {
|
|
76
|
+
* '/users': {
|
|
77
|
+
* get: {
|
|
78
|
+
* summary: 'List users',
|
|
79
|
+
* responses: {
|
|
80
|
+
* '200': {
|
|
81
|
+
* description: 'Success'
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
* }
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* }
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Using with generator registration
|
|
92
|
+
* ```typescript
|
|
93
|
+
* class MyGenerator extends ContentBase {
|
|
94
|
+
* generate() {
|
|
95
|
+
* const manifestFile = new JsonFile({
|
|
96
|
+
* path: './generated/manifest.json',
|
|
97
|
+
* content: {
|
|
98
|
+
* generatedAt: new Date().toISOString(),
|
|
99
|
+
* version: '1.0.0',
|
|
100
|
+
* files: [
|
|
101
|
+
* './models/User.ts',
|
|
102
|
+
* './models/Product.ts'
|
|
103
|
+
* ]
|
|
104
|
+
* }
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* // Register with the generation context
|
|
108
|
+
* this.register({ jsonFile: manifestFile });
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
1
113
|
export class JsonFile {
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new JsonFile instance.
|
|
116
|
+
*
|
|
117
|
+
* @param args - JSON file configuration
|
|
118
|
+
* @param args.path - The output path for this JSON file
|
|
119
|
+
* @param args.content - The JSON content to write
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const configFile = new JsonFile({
|
|
124
|
+
* path: './config/settings.json',
|
|
125
|
+
* content: {
|
|
126
|
+
* theme: 'dark',
|
|
127
|
+
* language: 'en',
|
|
128
|
+
* features: ['auth', 'notifications']
|
|
129
|
+
* }
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
2
133
|
constructor({ path, content }) {
|
|
134
|
+
/** The file type, always 'json' for JSON files */
|
|
3
135
|
Object.defineProperty(this, "fileType", {
|
|
4
136
|
enumerable: true,
|
|
5
137
|
configurable: true,
|
|
6
138
|
writable: true,
|
|
7
139
|
value: 'json'
|
|
8
140
|
});
|
|
141
|
+
/** The file path for this generated JSON file */
|
|
9
142
|
Object.defineProperty(this, "path", {
|
|
10
143
|
enumerable: true,
|
|
11
144
|
configurable: true,
|
|
12
145
|
writable: true,
|
|
13
146
|
value: void 0
|
|
14
147
|
});
|
|
148
|
+
/** The JSON content to write to the file */
|
|
15
149
|
Object.defineProperty(this, "content", {
|
|
16
150
|
enumerable: true,
|
|
17
151
|
configurable: true,
|
|
@@ -21,6 +155,29 @@ export class JsonFile {
|
|
|
21
155
|
this.path = path;
|
|
22
156
|
this.content = content;
|
|
23
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Converts the JSON content to a formatted string.
|
|
160
|
+
*
|
|
161
|
+
* This method serializes the content object to JSON with 2-space indentation
|
|
162
|
+
* for readable output. The resulting string is suitable for writing directly
|
|
163
|
+
* to a file or including in the generation pipeline.
|
|
164
|
+
*
|
|
165
|
+
* @returns The formatted JSON content as a string
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* const file = new JsonFile({
|
|
170
|
+
* path: './data.json',
|
|
171
|
+
* content: { name: 'test', value: 42 }
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* console.log(file.toString());
|
|
175
|
+
* // {
|
|
176
|
+
* // "name": "test",
|
|
177
|
+
* // "value": 42
|
|
178
|
+
* // }
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
24
181
|
toString() {
|
|
25
182
|
return JSON.stringify(this.content, null, 2);
|
|
26
183
|
}
|