@alagoni97/cli 0.72.1
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/LICENSE +201 -0
- package/README.md +336 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.mjs +3 -0
- package/bin/run.cmd +3 -0
- package/bin/run.mjs +4 -0
- package/dist/LoggingInterface.d.ts +123 -0
- package/dist/LoggingInterface.js +300 -0
- package/dist/PersistedConfig.d.ts +46 -0
- package/dist/PersistedConfig.js +94 -0
- package/dist/browser/adapters/output.d.ts +69 -0
- package/dist/browser/adapters/output.js +91 -0
- package/dist/browser/config.d.ts +18 -0
- package/dist/browser/config.js +59 -0
- package/dist/browser/generate.d.ts +20 -0
- package/dist/browser/generate.js +129 -0
- package/dist/browser/index.d.ts +17 -0
- package/dist/browser/index.js +26 -0
- package/dist/browser/parser.d.ts +9 -0
- package/dist/browser/parser.js +61 -0
- package/dist/browser/shims/asyncapi-parser.d.ts +30 -0
- package/dist/browser/shims/asyncapi-parser.js +52 -0
- package/dist/browser/shims/fs.d.ts +190 -0
- package/dist/browser/shims/fs.js +188 -0
- package/dist/browser/shims/json-schema-ref-parser.d.ts +73 -0
- package/dist/browser/shims/json-schema-ref-parser.js +246 -0
- package/dist/browser/shims/swagger-parser.d.ts +20 -0
- package/dist/browser/shims/swagger-parser.js +40 -0
- package/dist/codegen/configurationSchemaBuilder.d.ts +15 -0
- package/dist/codegen/configurationSchemaBuilder.js +48 -0
- package/dist/codegen/configurations.d.ts +29 -0
- package/dist/codegen/configurations.js +260 -0
- package/dist/codegen/detection.d.ts +19 -0
- package/dist/codegen/detection.js +174 -0
- package/dist/codegen/errors.d.ts +111 -0
- package/dist/codegen/errors.js +352 -0
- package/dist/codegen/generators/generic/custom.d.ts +75 -0
- package/dist/codegen/generators/generic/custom.js +66 -0
- package/dist/codegen/generators/index.d.ts +14 -0
- package/dist/codegen/generators/index.js +42 -0
- package/dist/codegen/generators/typescript/channels/asyncapi.d.ts +10 -0
- package/dist/codegen/generators/typescript/channels/asyncapi.js +131 -0
- package/dist/codegen/generators/typescript/channels/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/channels/index.js +142 -0
- package/dist/codegen/generators/typescript/channels/openapi.d.ts +9 -0
- package/dist/codegen/generators/typescript/channels/openapi.js +168 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/index.js +149 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishExchange.d.ts +5 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishExchange.js +106 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishQueue.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/publishQueue.js +102 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/subscribeQueue.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/amqp/subscribeQueue.js +133 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/express.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/express.js +100 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/fetch.d.ts +5 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/fetch.js +144 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/eventsource/index.js +132 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/client.d.ts +10 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/client.js +224 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/common-types.d.ts +14 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/common-types.js +800 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/index.js +96 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/security.d.ts +48 -0
- package/dist/codegen/generators/typescript/channels/protocols/http/security.js +491 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/index.js +127 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/publish.js +108 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/subscribe.js +154 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/utils.d.ts +11 -0
- package/dist/codegen/generators/typescript/channels/protocols/kafka/utils.js +58 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/index.d.ts +6 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/index.js +113 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/publish.js +99 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/mqtt/subscribe.js +186 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/corePublish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/corePublish.js +90 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreReply.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreReply.js +142 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreRequest.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreRequest.js +100 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreSubscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/coreSubscribe.js +143 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/index.d.ts +11 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/index.js +224 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPublish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPublish.js +89 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPullSubscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPullSubscribe.js +146 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPushSubscription.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/jetstreamPushSubscription.js +149 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/utils.d.ts +35 -0
- package/dist/codegen/generators/typescript/channels/protocols/nats/utils.js +120 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/index.js +152 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/publish.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/publish.js +64 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/register.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/register.js +115 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/subscribe.d.ts +3 -0
- package/dist/codegen/generators/typescript/channels/protocols/websocket/subscribe.js +151 -0
- package/dist/codegen/generators/typescript/channels/types.d.ts +181 -0
- package/dist/codegen/generators/typescript/channels/types.js +131 -0
- package/dist/codegen/generators/typescript/channels/utils.d.ts +64 -0
- package/dist/codegen/generators/typescript/channels/utils.js +163 -0
- package/dist/codegen/generators/typescript/client/index.d.ts +8 -0
- package/dist/codegen/generators/typescript/client/index.js +61 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/corePublish.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/corePublish.js +53 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/coreSubscribe.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/coreSubscribe.js +90 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetStreamPullSubscription.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetStreamPullSubscription.js +83 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPublish.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPublish.js +54 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPushSubscription.d.ts +6 -0
- package/dist/codegen/generators/typescript/client/protocols/nats/jetstreamPushSubscription.js +82 -0
- package/dist/codegen/generators/typescript/client/protocols/nats.d.ts +2 -0
- package/dist/codegen/generators/typescript/client/protocols/nats.js +182 -0
- package/dist/codegen/generators/typescript/client/types.d.ts +49 -0
- package/dist/codegen/generators/typescript/client/types.js +37 -0
- package/dist/codegen/generators/typescript/headers.d.ts +54 -0
- package/dist/codegen/generators/typescript/headers.js +138 -0
- package/dist/codegen/generators/typescript/index.d.ts +7 -0
- package/dist/codegen/generators/typescript/index.js +38 -0
- package/dist/codegen/generators/typescript/models.d.ts +21761 -0
- package/dist/codegen/generators/typescript/models.js +64 -0
- package/dist/codegen/generators/typescript/parameters.d.ts +37 -0
- package/dist/codegen/generators/typescript/parameters.js +101 -0
- package/dist/codegen/generators/typescript/payloads.d.ts +73 -0
- package/dist/codegen/generators/typescript/payloads.js +250 -0
- package/dist/codegen/generators/typescript/types.d.ts +34 -0
- package/dist/codegen/generators/typescript/types.js +70 -0
- package/dist/codegen/generators/typescript/utils.d.ts +38 -0
- package/dist/codegen/generators/typescript/utils.js +195 -0
- package/dist/codegen/index.d.ts +7 -0
- package/dist/codegen/index.js +38 -0
- package/dist/codegen/inputs/asyncapi/generators/headers.d.ts +3 -0
- package/dist/codegen/inputs/asyncapi/generators/headers.js +41 -0
- package/dist/codegen/inputs/asyncapi/generators/parameters.d.ts +14 -0
- package/dist/codegen/inputs/asyncapi/generators/parameters.js +120 -0
- package/dist/codegen/inputs/asyncapi/generators/payloads.d.ts +16 -0
- package/dist/codegen/inputs/asyncapi/generators/payloads.js +124 -0
- package/dist/codegen/inputs/asyncapi/generators/types.d.ts +9 -0
- package/dist/codegen/inputs/asyncapi/generators/types.js +61 -0
- package/dist/codegen/inputs/asyncapi/index.d.ts +1 -0
- package/dist/codegen/inputs/asyncapi/index.js +7 -0
- package/dist/codegen/inputs/asyncapi/parser.d.ts +4 -0
- package/dist/codegen/inputs/asyncapi/parser.js +90 -0
- package/dist/codegen/inputs/index.d.ts +3 -0
- package/dist/codegen/inputs/index.js +19 -0
- package/dist/codegen/inputs/jsonschema/generators/index.d.ts +1 -0
- package/dist/codegen/inputs/jsonschema/generators/index.js +5 -0
- package/dist/codegen/inputs/jsonschema/generators/models.d.ts +7 -0
- package/dist/codegen/inputs/jsonschema/generators/models.js +26 -0
- package/dist/codegen/inputs/jsonschema/index.d.ts +1 -0
- package/dist/codegen/inputs/jsonschema/index.js +7 -0
- package/dist/codegen/inputs/jsonschema/parser.d.ts +31 -0
- package/dist/codegen/inputs/jsonschema/parser.js +128 -0
- package/dist/codegen/inputs/openapi/generators/headers.d.ts +3 -0
- package/dist/codegen/inputs/openapi/generators/headers.js +101 -0
- package/dist/codegen/inputs/openapi/generators/parameters.d.ts +10 -0
- package/dist/codegen/inputs/openapi/generators/parameters.js +852 -0
- package/dist/codegen/inputs/openapi/generators/payloads.d.ts +3 -0
- package/dist/codegen/inputs/openapi/generators/payloads.js +231 -0
- package/dist/codegen/inputs/openapi/generators/types.d.ts +9 -0
- package/dist/codegen/inputs/openapi/generators/types.js +86 -0
- package/dist/codegen/inputs/openapi/index.d.ts +2 -0
- package/dist/codegen/inputs/openapi/index.js +8 -0
- package/dist/codegen/inputs/openapi/parser.d.ts +4 -0
- package/dist/codegen/inputs/openapi/parser.js +115 -0
- package/dist/codegen/inputs/openapi/security.d.ts +56 -0
- package/dist/codegen/inputs/openapi/security.js +193 -0
- package/dist/codegen/modelina/index.d.ts +2 -0
- package/dist/codegen/modelina/index.js +20 -0
- package/dist/codegen/modelina/presets/index.d.ts +3 -0
- package/dist/codegen/modelina/presets/index.js +14 -0
- package/dist/codegen/modelina/presets/primitives.d.ts +34 -0
- package/dist/codegen/modelina/presets/primitives.js +211 -0
- package/dist/codegen/modelina/presets/union.d.ts +33 -0
- package/dist/codegen/modelina/presets/union.js +197 -0
- package/dist/codegen/modelina/presets/validation.d.ts +66 -0
- package/dist/codegen/modelina/presets/validation.js +183 -0
- package/dist/codegen/modelina/types.d.ts +61845 -0
- package/dist/codegen/modelina/types.js +412 -0
- package/dist/codegen/output/filesystem.d.ts +30 -0
- package/dist/codegen/output/filesystem.js +61 -0
- package/dist/codegen/output/index.d.ts +16 -0
- package/dist/codegen/output/index.js +57 -0
- package/dist/codegen/output/memory.d.ts +54 -0
- package/dist/codegen/output/memory.js +81 -0
- package/dist/codegen/output/modelina.d.ts +30 -0
- package/dist/codegen/output/modelina.js +30 -0
- package/dist/codegen/output/types.d.ts +47 -0
- package/dist/codegen/output/types.js +6 -0
- package/dist/codegen/renderer.d.ts +13 -0
- package/dist/codegen/renderer.js +309 -0
- package/dist/codegen/schemaPostProcess.d.ts +25 -0
- package/dist/codegen/schemaPostProcess.js +38 -0
- package/dist/codegen/types.d.ts +285187 -0
- package/dist/codegen/types.js +177 -0
- package/dist/codegen/utils.d.ts +126 -0
- package/dist/codegen/utils.js +373 -0
- package/dist/commands/base.d.ts +18 -0
- package/dist/commands/base.js +59 -0
- package/dist/commands/generate.d.ts +46 -0
- package/dist/commands/generate.js +305 -0
- package/dist/commands/init.d.ts +55 -0
- package/dist/commands/init.js +544 -0
- package/dist/commands/telemetry.d.ts +25 -0
- package/dist/commands/telemetry.js +115 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +35 -0
- package/dist/telemetry/anonymize.d.ts +19 -0
- package/dist/telemetry/anonymize.js +73 -0
- package/dist/telemetry/collector.d.ts +26 -0
- package/dist/telemetry/collector.js +57 -0
- package/dist/telemetry/config.d.ts +32 -0
- package/dist/telemetry/config.js +97 -0
- package/dist/telemetry/events.d.ts +72 -0
- package/dist/telemetry/events.js +5 -0
- package/dist/telemetry/index.d.ts +46 -0
- package/dist/telemetry/index.js +91 -0
- package/dist/telemetry/notice.d.ts +8 -0
- package/dist/telemetry/notice.js +50 -0
- package/dist/telemetry/sender.d.ts +14 -0
- package/dist/telemetry/sender.js +125 -0
- package/dist/utils/gitignore.d.ts +66 -0
- package/dist/utils/gitignore.js +111 -0
- package/dist/utils/inputSource.d.ts +3 -0
- package/dist/utils/inputSource.js +26 -0
- package/dist/utils/refResolvers.d.ts +29 -0
- package/dist/utils/refResolvers.js +83 -0
- package/dist/utils/remoteFetch.d.ts +18 -0
- package/dist/utils/remoteFetch.js +64 -0
- package/oclif.manifest.json +510 -0
- package/package.json +155 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserOutput = void 0;
|
|
4
|
+
class BrowserOutput {
|
|
5
|
+
files = new Map();
|
|
6
|
+
/**
|
|
7
|
+
* Write a file to memory.
|
|
8
|
+
* @param path - The file path (e.g., 'src/models/User.ts')
|
|
9
|
+
* @param content - The file content
|
|
10
|
+
*/
|
|
11
|
+
async write(path, content) {
|
|
12
|
+
this.files.set(path, content);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* No-op for browser - directories are virtual.
|
|
16
|
+
*/
|
|
17
|
+
async mkdir(_dirPath, _options) {
|
|
18
|
+
// No-op - directories are virtual in memory
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get all file paths that were written.
|
|
22
|
+
* Implements OutputAdapter interface.
|
|
23
|
+
*/
|
|
24
|
+
getWrittenFiles() {
|
|
25
|
+
return Array.from(this.files.keys());
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get all files with their content.
|
|
29
|
+
* Implements OutputAdapter interface.
|
|
30
|
+
*/
|
|
31
|
+
getAllFiles() {
|
|
32
|
+
const result = {};
|
|
33
|
+
for (const [path, content] of this.files) {
|
|
34
|
+
result[path] = content;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Read a file from memory.
|
|
40
|
+
* @param path - The file path
|
|
41
|
+
* @returns The file content, or undefined if not found
|
|
42
|
+
*/
|
|
43
|
+
read(path) {
|
|
44
|
+
return this.files.get(path);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get all files as a Record.
|
|
48
|
+
* @deprecated Use getAllFiles() instead for OutputAdapter compatibility
|
|
49
|
+
* @returns A copy of all files as Record<path, content>
|
|
50
|
+
*/
|
|
51
|
+
getAll() {
|
|
52
|
+
return this.getAllFiles();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Clear all files from memory.
|
|
56
|
+
*/
|
|
57
|
+
clear() {
|
|
58
|
+
this.files.clear();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if a file exists.
|
|
62
|
+
* @param path - The file path
|
|
63
|
+
* @returns True if the file exists
|
|
64
|
+
*/
|
|
65
|
+
has(path) {
|
|
66
|
+
return this.files.has(path);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Delete a specific file.
|
|
70
|
+
* @param path - The file path
|
|
71
|
+
* @returns True if the file was deleted, false if it didn't exist
|
|
72
|
+
*/
|
|
73
|
+
delete(path) {
|
|
74
|
+
return this.files.delete(path);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get all file paths.
|
|
78
|
+
* @deprecated Use getWrittenFiles() instead for OutputAdapter compatibility
|
|
79
|
+
* @returns Array of file paths
|
|
80
|
+
*/
|
|
81
|
+
getPaths() {
|
|
82
|
+
return this.getWrittenFiles();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Get the number of files.
|
|
86
|
+
*/
|
|
87
|
+
get size() {
|
|
88
|
+
return this.files.size;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.BrowserOutput = BrowserOutput;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TheCodegenConfiguration } from '../codegen/types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse a configuration string into a validated configuration object.
|
|
4
|
+
*
|
|
5
|
+
* @param configString - The configuration as a string (JSON or YAML)
|
|
6
|
+
* @param format - The format of the string ('json' or 'yaml')
|
|
7
|
+
* @returns The validated configuration object
|
|
8
|
+
* @throws Error if parsing or validation fails
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseConfig(configString: string, format: 'json' | 'yaml'): TheCodegenConfiguration;
|
|
11
|
+
/**
|
|
12
|
+
* Serialize a configuration object to a string.
|
|
13
|
+
*
|
|
14
|
+
* @param config - The configuration object
|
|
15
|
+
* @param format - The output format ('json' or 'yaml')
|
|
16
|
+
* @returns The configuration as a string
|
|
17
|
+
*/
|
|
18
|
+
export declare function serializeConfig(config: TheCodegenConfiguration, format: 'json' | 'yaml'): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeConfig = exports.parseConfig = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Parse configuration from string for browser environments.
|
|
6
|
+
* Replaces cosmiconfig filesystem search with direct string parsing.
|
|
7
|
+
*/
|
|
8
|
+
const yaml_1 = require("yaml");
|
|
9
|
+
const types_1 = require("../codegen/types");
|
|
10
|
+
/**
|
|
11
|
+
* Parse a configuration string into a validated configuration object.
|
|
12
|
+
*
|
|
13
|
+
* @param configString - The configuration as a string (JSON or YAML)
|
|
14
|
+
* @param format - The format of the string ('json' or 'yaml')
|
|
15
|
+
* @returns The validated configuration object
|
|
16
|
+
* @throws Error if parsing or validation fails
|
|
17
|
+
*/
|
|
18
|
+
function parseConfig(configString, format) {
|
|
19
|
+
let rawConfig;
|
|
20
|
+
// Parse the string based on format
|
|
21
|
+
try {
|
|
22
|
+
if (format === 'json') {
|
|
23
|
+
rawConfig = JSON.parse(configString);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
rawConfig = (0, yaml_1.parse)(configString);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const message = error instanceof Error ? error.message : 'Unknown parse error';
|
|
31
|
+
throw new Error(`Failed to parse ${format} configuration: ${message}`);
|
|
32
|
+
}
|
|
33
|
+
// Validate with Zod schema
|
|
34
|
+
const result = types_1.zodTheCodegenConfiguration.safeParse(rawConfig);
|
|
35
|
+
if (!result.success) {
|
|
36
|
+
const errors = result.error.issues
|
|
37
|
+
.map((issue) => ` - ${issue.path.join('.')}: ${issue.message}`)
|
|
38
|
+
.join('\n');
|
|
39
|
+
throw new Error(`Invalid configuration:\n${errors}`);
|
|
40
|
+
}
|
|
41
|
+
return result.data;
|
|
42
|
+
}
|
|
43
|
+
exports.parseConfig = parseConfig;
|
|
44
|
+
/**
|
|
45
|
+
* Serialize a configuration object to a string.
|
|
46
|
+
*
|
|
47
|
+
* @param config - The configuration object
|
|
48
|
+
* @param format - The output format ('json' or 'yaml')
|
|
49
|
+
* @returns The configuration as a string
|
|
50
|
+
*/
|
|
51
|
+
function serializeConfig(config, format) {
|
|
52
|
+
if (format === 'json') {
|
|
53
|
+
return JSON.stringify(config, null, 2);
|
|
54
|
+
}
|
|
55
|
+
// For YAML, we'd need to import stringify from yaml
|
|
56
|
+
// For now, default to JSON
|
|
57
|
+
return JSON.stringify(config, null, 2);
|
|
58
|
+
}
|
|
59
|
+
exports.serializeConfig = serializeConfig;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TheCodegenConfiguration } from '../codegen/types';
|
|
2
|
+
export interface BrowserGenerateInput {
|
|
3
|
+
/** The API specification as a string (YAML or JSON) */
|
|
4
|
+
spec: string;
|
|
5
|
+
/** The format of the specification */
|
|
6
|
+
specFormat: 'asyncapi' | 'openapi' | 'jsonschema';
|
|
7
|
+
/** The codegen configuration */
|
|
8
|
+
config: TheCodegenConfiguration;
|
|
9
|
+
}
|
|
10
|
+
export interface BrowserGenerateOutput {
|
|
11
|
+
/** Generated files as Record<path, content> */
|
|
12
|
+
files: Record<string, string>;
|
|
13
|
+
/** Any errors that occurred during generation */
|
|
14
|
+
errors: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate code from an API specification in the browser.
|
|
18
|
+
* This is the main entry point for browser-based code generation.
|
|
19
|
+
*/
|
|
20
|
+
export declare function generate(input: BrowserGenerateInput): Promise<BrowserGenerateOutput>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Main browser generation function.
|
|
6
|
+
* Uses the shared rendering pipeline for in-memory code generation.
|
|
7
|
+
* No filesystem I/O - returns generated files as data.
|
|
8
|
+
*/
|
|
9
|
+
const yaml_1 = require("yaml");
|
|
10
|
+
const openapi_parser_1 = require("@readme/openapi-parser");
|
|
11
|
+
const errors_1 = require("../codegen/errors");
|
|
12
|
+
const parser_1 = require("./parser");
|
|
13
|
+
const jsonschema_1 = require("../codegen/inputs/jsonschema");
|
|
14
|
+
const types_1 = require("../codegen/types");
|
|
15
|
+
const configurations_1 = require("../codegen/configurations");
|
|
16
|
+
const renderer_1 = require("../codegen/renderer");
|
|
17
|
+
/**
|
|
18
|
+
* Generate code from an API specification in the browser.
|
|
19
|
+
* This is the main entry point for browser-based code generation.
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
22
|
+
async function generate(input) {
|
|
23
|
+
const errors = [];
|
|
24
|
+
const files = {};
|
|
25
|
+
try {
|
|
26
|
+
// Validate and realize configuration (adds default generators for dependencies)
|
|
27
|
+
const configResult = types_1.zodTheCodegenConfiguration.safeParse(input.config);
|
|
28
|
+
if (!configResult.success) {
|
|
29
|
+
errors.push(`Invalid configuration: ${configResult.error.issues.map((i) => i.message).join(', ')}`);
|
|
30
|
+
return { files, errors };
|
|
31
|
+
}
|
|
32
|
+
// Realize configuration to add dependency generators and merge with defaults
|
|
33
|
+
const config = (0, configurations_1.realizeConfiguration)(configResult.data);
|
|
34
|
+
// Parse the specification
|
|
35
|
+
let asyncapiDocument;
|
|
36
|
+
let openapiDocument;
|
|
37
|
+
let jsonSchemaDocument;
|
|
38
|
+
// Validate spec is not empty
|
|
39
|
+
if (!input.spec || input.spec.trim() === '') {
|
|
40
|
+
errors.push('Empty specification provided');
|
|
41
|
+
return { files, errors };
|
|
42
|
+
}
|
|
43
|
+
switch (input.specFormat) {
|
|
44
|
+
case 'asyncapi':
|
|
45
|
+
try {
|
|
46
|
+
asyncapiDocument = await (0, parser_1.loadAsyncapiFromMemoryBrowser)(input.spec);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// Include details from CodegenError if available
|
|
50
|
+
let errorMsg = error instanceof Error ? error.message : String(error);
|
|
51
|
+
if (error instanceof errors_1.CodegenError && error.details) {
|
|
52
|
+
errorMsg += `\n${error.details}`;
|
|
53
|
+
}
|
|
54
|
+
errors.push(`Failed to parse AsyncAPI spec: ${errorMsg}`);
|
|
55
|
+
return { files, errors };
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'openapi':
|
|
59
|
+
try {
|
|
60
|
+
openapiDocument = await parseOpenAPIFromMemory(input.spec);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
errors.push(`Failed to parse OpenAPI spec: ${error instanceof Error ? error.message : String(error)}`);
|
|
64
|
+
return { files, errors };
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case 'jsonschema':
|
|
68
|
+
try {
|
|
69
|
+
const parsed = parseSpecString(input.spec);
|
|
70
|
+
jsonSchemaDocument = (0, jsonschema_1.loadJsonSchemaFromMemory)(parsed);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
errors.push(`Failed to parse JSON Schema: ${error instanceof Error ? error.message : String(error)}`);
|
|
74
|
+
return { files, errors };
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
errors.push(`Unknown spec format: ${input.specFormat}`);
|
|
79
|
+
return { files, errors };
|
|
80
|
+
}
|
|
81
|
+
// Cast the browser shim's AsyncAPIDocumentInterface to the Node.js version
|
|
82
|
+
// At runtime, the objects are compatible - this is just for TypeScript
|
|
83
|
+
const nodeAsyncapiDocument = asyncapiDocument;
|
|
84
|
+
// Build the context for the shared rendering pipeline
|
|
85
|
+
// Use root-level virtual path so output paths don't get 'browser/' prefix
|
|
86
|
+
const context = {
|
|
87
|
+
configuration: config,
|
|
88
|
+
configFilePath: '/virtual-config.mjs', // Virtual path for browser (root level)
|
|
89
|
+
documentPath: '/virtual-spec',
|
|
90
|
+
asyncapiDocument: nodeAsyncapiDocument,
|
|
91
|
+
openapiDocument,
|
|
92
|
+
jsonSchemaDocument
|
|
93
|
+
};
|
|
94
|
+
// Use the shared rendering pipeline
|
|
95
|
+
const graph = (0, renderer_1.determineRenderGraph)(context);
|
|
96
|
+
const result = await (0, renderer_1.renderGraph)(context, graph);
|
|
97
|
+
// Convert GeneratedFile[] to Record<string, string>
|
|
98
|
+
for (const file of result.files) {
|
|
99
|
+
files[file.path] = file.content;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
errors.push(`Generation failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
104
|
+
}
|
|
105
|
+
return { files, errors };
|
|
106
|
+
}
|
|
107
|
+
exports.generate = generate;
|
|
108
|
+
/**
|
|
109
|
+
* Parse an OpenAPI spec from a string.
|
|
110
|
+
*/
|
|
111
|
+
async function parseOpenAPIFromMemory(specString) {
|
|
112
|
+
const document = parseSpecString(specString);
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
114
|
+
const parsedDocument = await (0, openapi_parser_1.parse)(document);
|
|
115
|
+
return await (0, openapi_parser_1.dereference)(parsedDocument);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Parse a spec string (YAML or JSON) into an object.
|
|
119
|
+
*/
|
|
120
|
+
function parseSpecString(specString) {
|
|
121
|
+
// Try JSON first
|
|
122
|
+
try {
|
|
123
|
+
return JSON.parse(specString);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Fall back to YAML
|
|
127
|
+
return (0, yaml_1.parse)(specString);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser bundle entry point.
|
|
3
|
+
* Exports browser-compatible generation functions for use in web applications.
|
|
4
|
+
*
|
|
5
|
+
* This module provides:
|
|
6
|
+
* - generate() - Main function to generate code from API specs
|
|
7
|
+
* - parseConfig() - Parse configuration from JSON/YAML strings
|
|
8
|
+
* - BrowserOutput - In-memory file storage
|
|
9
|
+
* - MemoryAdapter - Shared in-memory output adapter
|
|
10
|
+
*/
|
|
11
|
+
export { generate } from './generate';
|
|
12
|
+
export type { BrowserGenerateInput, BrowserGenerateOutput } from './generate';
|
|
13
|
+
export { parseConfig, serializeConfig } from './config';
|
|
14
|
+
export { BrowserOutput } from './adapters/output';
|
|
15
|
+
export { MemoryAdapter } from '../codegen/output';
|
|
16
|
+
export type { OutputAdapter } from '../codegen/output';
|
|
17
|
+
export type { TheCodegenConfiguration } from '../codegen/types';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Browser bundle entry point.
|
|
4
|
+
* Exports browser-compatible generation functions for use in web applications.
|
|
5
|
+
*
|
|
6
|
+
* This module provides:
|
|
7
|
+
* - generate() - Main function to generate code from API specs
|
|
8
|
+
* - parseConfig() - Parse configuration from JSON/YAML strings
|
|
9
|
+
* - BrowserOutput - In-memory file storage
|
|
10
|
+
* - MemoryAdapter - Shared in-memory output adapter
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.MemoryAdapter = exports.BrowserOutput = exports.serializeConfig = exports.parseConfig = exports.generate = void 0;
|
|
14
|
+
// Main generation function
|
|
15
|
+
var generate_1 = require("./generate");
|
|
16
|
+
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
|
|
17
|
+
// Configuration parsing
|
|
18
|
+
var config_1 = require("./config");
|
|
19
|
+
Object.defineProperty(exports, "parseConfig", { enumerable: true, get: function () { return config_1.parseConfig; } });
|
|
20
|
+
Object.defineProperty(exports, "serializeConfig", { enumerable: true, get: function () { return config_1.serializeConfig; } });
|
|
21
|
+
// Adapters for direct usage
|
|
22
|
+
var output_1 = require("./adapters/output");
|
|
23
|
+
Object.defineProperty(exports, "BrowserOutput", { enumerable: true, get: function () { return output_1.BrowserOutput; } });
|
|
24
|
+
// Re-export shared MemoryAdapter for direct usage
|
|
25
|
+
var output_2 = require("../codegen/output");
|
|
26
|
+
Object.defineProperty(exports, "MemoryAdapter", { enumerable: true, get: function () { return output_2.MemoryAdapter; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncAPIDocumentInterface } from './shims/asyncapi-parser';
|
|
2
|
+
/**
|
|
3
|
+
* Load an AsyncAPI document from a string in the browser environment.
|
|
4
|
+
* Uses the browser-specific parser that properly handles $ref resolution.
|
|
5
|
+
*
|
|
6
|
+
* @param input - The AsyncAPI document as a YAML or JSON string
|
|
7
|
+
* @returns The parsed AsyncAPI document
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadAsyncapiFromMemoryBrowser(input: string): Promise<AsyncAPIDocumentInterface>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadAsyncapiFromMemoryBrowser = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Browser-specific AsyncAPI parser.
|
|
6
|
+
*
|
|
7
|
+
* This module provides the same interface as the Node.js parser but is designed
|
|
8
|
+
* to work correctly when bundled for browser environments.
|
|
9
|
+
*
|
|
10
|
+
* When bundled with esbuild for browser:
|
|
11
|
+
* - Uses the shim which loads @asyncapi/parser/browser with proper $ref resolution
|
|
12
|
+
*
|
|
13
|
+
* When running in Node.js (tests):
|
|
14
|
+
* - Uses the regular @asyncapi/parser which works correctly
|
|
15
|
+
*
|
|
16
|
+
* Reference: https://github.com/asyncapi/parser-js#using-in-the-browserspa-applications
|
|
17
|
+
*/
|
|
18
|
+
const errors_1 = require("../codegen/errors");
|
|
19
|
+
const asyncapi_parser_1 = require("./shims/asyncapi-parser");
|
|
20
|
+
/**
|
|
21
|
+
* Browser parser instance.
|
|
22
|
+
* Configured without linting rules for faster parsing.
|
|
23
|
+
* The Parser is loaded from our shim which handles browser vs Node.js environments.
|
|
24
|
+
*/
|
|
25
|
+
const parser = new asyncapi_parser_1.Parser({
|
|
26
|
+
ruleset: {
|
|
27
|
+
core: false,
|
|
28
|
+
recommended: false
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Load an AsyncAPI document from a string in the browser environment.
|
|
33
|
+
* Uses the browser-specific parser that properly handles $ref resolution.
|
|
34
|
+
*
|
|
35
|
+
* @param input - The AsyncAPI document as a YAML or JSON string
|
|
36
|
+
* @returns The parsed AsyncAPI document
|
|
37
|
+
*/
|
|
38
|
+
async function loadAsyncapiFromMemoryBrowser(input) {
|
|
39
|
+
const result = await parser.parse(input);
|
|
40
|
+
// Check for errors (severity 0 = error)
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
const errors = result.diagnostics?.filter((d) => d.severity === 0);
|
|
43
|
+
if (errors && errors.length > 0) {
|
|
44
|
+
throw (0, errors_1.createInputDocumentError)({
|
|
45
|
+
inputPath: 'memory',
|
|
46
|
+
inputType: 'asyncapi',
|
|
47
|
+
errorMessage: JSON.stringify(errors, null, 2)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
if (!result.document) {
|
|
52
|
+
throw (0, errors_1.createInputDocumentError)({
|
|
53
|
+
inputPath: 'memory',
|
|
54
|
+
inputType: 'asyncapi',
|
|
55
|
+
errorMessage: 'Failed to parse AsyncAPI document'
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
return result.document;
|
|
60
|
+
}
|
|
61
|
+
exports.loadAsyncapiFromMemoryBrowser = loadAsyncapiFromMemoryBrowser;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shim for @asyncapi/parser that works in both Node.js and browser environments.
|
|
3
|
+
*
|
|
4
|
+
* - In Node.js (tests): Uses the regular @asyncapi/parser package
|
|
5
|
+
* - In browser (bundled): Uses @asyncapi/parser/browser which has proper $ref resolution
|
|
6
|
+
*
|
|
7
|
+
* The esbuild plugin (asyncapiParserBrowserPlugin) transforms the browser bundle
|
|
8
|
+
* to properly export the Parser class.
|
|
9
|
+
*/
|
|
10
|
+
export interface AsyncAPIDocumentInterface {
|
|
11
|
+
version(): string;
|
|
12
|
+
info(): unknown;
|
|
13
|
+
servers(): unknown;
|
|
14
|
+
channels(): unknown;
|
|
15
|
+
operations(): unknown;
|
|
16
|
+
messages(): unknown;
|
|
17
|
+
schemas(): unknown;
|
|
18
|
+
securitySchemes(): unknown;
|
|
19
|
+
components(): unknown;
|
|
20
|
+
allServers(): unknown;
|
|
21
|
+
allChannels(): unknown;
|
|
22
|
+
allOperations(): unknown;
|
|
23
|
+
allMessages(): unknown;
|
|
24
|
+
allSchemas(): unknown;
|
|
25
|
+
extensions(): unknown;
|
|
26
|
+
json<T = any>(): T;
|
|
27
|
+
}
|
|
28
|
+
declare let ParserClass: any;
|
|
29
|
+
export declare const Parser: any;
|
|
30
|
+
export default ParserClass;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-undef, no-console */
|
|
3
|
+
/**
|
|
4
|
+
* Shim for @asyncapi/parser that works in both Node.js and browser environments.
|
|
5
|
+
*
|
|
6
|
+
* - In Node.js (tests): Uses the regular @asyncapi/parser package
|
|
7
|
+
* - In browser (bundled): Uses @asyncapi/parser/browser which has proper $ref resolution
|
|
8
|
+
*
|
|
9
|
+
* The esbuild plugin (asyncapiParserBrowserPlugin) transforms the browser bundle
|
|
10
|
+
* to properly export the Parser class.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.Parser = void 0;
|
|
14
|
+
// Detect environment - if we have window/document, we're in browser
|
|
15
|
+
const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
let ParserClass;
|
|
18
|
+
if (isBrowser) {
|
|
19
|
+
// In browser: use the browser bundle
|
|
20
|
+
// The esbuild plugin transforms this to properly export Parser
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
22
|
+
const browserBundle = require('@asyncapi/parser/browser');
|
|
23
|
+
// Debug: log the bundle structure to help diagnose issues
|
|
24
|
+
if (typeof console !== 'undefined' && console.debug) {
|
|
25
|
+
console.debug('[AsyncAPI Parser Shim] Bundle keys:', Object.keys(browserBundle));
|
|
26
|
+
console.debug('[AsyncAPI Parser Shim] Parser type:', typeof browserBundle.Parser);
|
|
27
|
+
console.debug('[AsyncAPI Parser Shim] default type:', typeof browserBundle.default);
|
|
28
|
+
if (browserBundle.default) {
|
|
29
|
+
console.debug('[AsyncAPI Parser Shim] default.Parser type:', typeof browserBundle.default?.Parser);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
ParserClass =
|
|
33
|
+
browserBundle.Parser ||
|
|
34
|
+
browserBundle.default?.Parser ||
|
|
35
|
+
browserBundle.default;
|
|
36
|
+
if (!ParserClass || typeof ParserClass !== 'function') {
|
|
37
|
+
console.error('AsyncAPI Parser browser bundle structure:', Object.keys(browserBundle));
|
|
38
|
+
console.error('Parser value:', browserBundle.Parser);
|
|
39
|
+
console.error('default value:', browserBundle.default);
|
|
40
|
+
throw new Error(`Could not find Parser constructor in @asyncapi/parser/browser bundle. ` +
|
|
41
|
+
`Parser type: ${typeof ParserClass}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// In Node.js: use the regular parser
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
47
|
+
const parserModule = require('@asyncapi/parser');
|
|
48
|
+
ParserClass = parserModule.Parser;
|
|
49
|
+
}
|
|
50
|
+
// Export Parser as both named and default export
|
|
51
|
+
exports.Parser = ParserClass;
|
|
52
|
+
exports.default = ParserClass;
|