@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,111 @@
|
|
|
1
|
+
export declare enum ErrorType {
|
|
2
|
+
CONFIG_NOT_FOUND = "CONFIG_NOT_FOUND",
|
|
3
|
+
CONFIG_PARSE_ERROR = "CONFIG_PARSE_ERROR",
|
|
4
|
+
CONFIG_VALIDATION_ERROR = "CONFIG_VALIDATION_ERROR",
|
|
5
|
+
INVALID_PRESET = "INVALID_PRESET",
|
|
6
|
+
INVALID_INPUT_TYPE = "INVALID_INPUT_TYPE",
|
|
7
|
+
MISSING_REQUIRED_FIELD = "MISSING_REQUIRED_FIELD",
|
|
8
|
+
INPUT_DOCUMENT_ERROR = "INPUT_DOCUMENT_ERROR",
|
|
9
|
+
GENERATOR_ERROR = "GENERATOR_ERROR",
|
|
10
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR",
|
|
11
|
+
UNSUPPORTED_LANGUAGE = "UNSUPPORTED_LANGUAGE",
|
|
12
|
+
MISSING_INPUT_DOCUMENT = "MISSING_INPUT_DOCUMENT",
|
|
13
|
+
MISSING_PAYLOAD = "MISSING_PAYLOAD",
|
|
14
|
+
MISSING_PARAMETER = "MISSING_PARAMETER",
|
|
15
|
+
CIRCULAR_DEPENDENCY = "CIRCULAR_DEPENDENCY",
|
|
16
|
+
DUPLICATE_GENERATOR_ID = "DUPLICATE_GENERATOR_ID",
|
|
17
|
+
UNSUPPORTED_PRESET_FOR_INPUT = "UNSUPPORTED_PRESET_FOR_INPUT"
|
|
18
|
+
}
|
|
19
|
+
export interface CodegenErrorDetails {
|
|
20
|
+
type: ErrorType;
|
|
21
|
+
message: string;
|
|
22
|
+
help?: string;
|
|
23
|
+
details?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare class CodegenError extends Error {
|
|
26
|
+
readonly type: ErrorType;
|
|
27
|
+
readonly help?: string;
|
|
28
|
+
readonly details?: string;
|
|
29
|
+
constructor({ type, message, help, details }: CodegenErrorDetails);
|
|
30
|
+
/**
|
|
31
|
+
* Format the error message for display to users
|
|
32
|
+
* @param useColors Whether to use colored output
|
|
33
|
+
*/
|
|
34
|
+
format(useColors?: boolean): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Helper functions to create specific error types
|
|
38
|
+
*/
|
|
39
|
+
export declare function createConfigNotFoundError(options?: {
|
|
40
|
+
filePath?: string;
|
|
41
|
+
searchLocations?: string[];
|
|
42
|
+
}): CodegenError;
|
|
43
|
+
export declare function createConfigParseError(options: {
|
|
44
|
+
filePath: string;
|
|
45
|
+
originalError: Error;
|
|
46
|
+
}): CodegenError;
|
|
47
|
+
export declare function createInvalidPresetError(options: {
|
|
48
|
+
preset: string;
|
|
49
|
+
language: string;
|
|
50
|
+
}): CodegenError;
|
|
51
|
+
export declare function createInvalidInputTypeError(options: {
|
|
52
|
+
inputType: string;
|
|
53
|
+
}): CodegenError;
|
|
54
|
+
export declare function createMissingRequiredFieldError(options: {
|
|
55
|
+
field: string;
|
|
56
|
+
location?: string;
|
|
57
|
+
}): CodegenError;
|
|
58
|
+
export declare function createConfigValidationError(options: {
|
|
59
|
+
validationErrors: string[];
|
|
60
|
+
}): CodegenError;
|
|
61
|
+
export declare function createInputDocumentError(options: {
|
|
62
|
+
inputPath: string;
|
|
63
|
+
inputType: string;
|
|
64
|
+
errorMessage: string;
|
|
65
|
+
}): CodegenError;
|
|
66
|
+
export declare function createRemoteFetchError(options: {
|
|
67
|
+
url: string;
|
|
68
|
+
status?: number;
|
|
69
|
+
statusText?: string;
|
|
70
|
+
cause?: unknown;
|
|
71
|
+
reason?: 'timeout' | 'network' | 'http';
|
|
72
|
+
}): CodegenError;
|
|
73
|
+
export declare function createGeneratorError(options: {
|
|
74
|
+
generatorId: string;
|
|
75
|
+
originalError: Error;
|
|
76
|
+
}): CodegenError;
|
|
77
|
+
export declare function createUnsupportedLanguageError(options: {
|
|
78
|
+
preset: string;
|
|
79
|
+
language: string;
|
|
80
|
+
}): CodegenError;
|
|
81
|
+
export declare function createMissingInputDocumentError(options: {
|
|
82
|
+
expectedType: 'asyncapi' | 'openapi' | 'jsonschema';
|
|
83
|
+
generatorPreset?: string;
|
|
84
|
+
}): CodegenError;
|
|
85
|
+
export declare function createMissingPayloadError(options: {
|
|
86
|
+
channelOrOperation: string;
|
|
87
|
+
protocol?: string;
|
|
88
|
+
}): CodegenError;
|
|
89
|
+
export declare function createMissingParameterError(options: {
|
|
90
|
+
channelOrOperation: string;
|
|
91
|
+
protocol?: string;
|
|
92
|
+
}): CodegenError;
|
|
93
|
+
export declare function createCircularDependencyError(options?: {
|
|
94
|
+
generatorIds?: string[];
|
|
95
|
+
}): CodegenError;
|
|
96
|
+
export declare function createDuplicateGeneratorIdError(options: {
|
|
97
|
+
duplicateIds: string[];
|
|
98
|
+
}): CodegenError;
|
|
99
|
+
export declare function createUnsupportedPresetForInputError(options: {
|
|
100
|
+
preset: string;
|
|
101
|
+
inputType: string;
|
|
102
|
+
supportedPresets: string[];
|
|
103
|
+
}): CodegenError;
|
|
104
|
+
export declare function createMissingDependencyOutputError(options: {
|
|
105
|
+
generatorPreset: string;
|
|
106
|
+
dependencyName: string;
|
|
107
|
+
}): CodegenError;
|
|
108
|
+
/**
|
|
109
|
+
* Parse Zod validation errors and convert them to user-friendly messages
|
|
110
|
+
*/
|
|
111
|
+
export declare function parseZodErrors(zodError: any): string[];
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseZodErrors = exports.createMissingDependencyOutputError = exports.createUnsupportedPresetForInputError = exports.createDuplicateGeneratorIdError = exports.createCircularDependencyError = exports.createMissingParameterError = exports.createMissingPayloadError = exports.createMissingInputDocumentError = exports.createUnsupportedLanguageError = exports.createGeneratorError = exports.createRemoteFetchError = exports.createInputDocumentError = exports.createConfigValidationError = exports.createMissingRequiredFieldError = exports.createInvalidInputTypeError = exports.createInvalidPresetError = exports.createConfigParseError = exports.createConfigNotFoundError = exports.CodegenError = exports.ErrorType = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Custom error types for better error handling and user-friendly messages
|
|
9
|
+
*/
|
|
10
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
11
|
+
var ErrorType;
|
|
12
|
+
(function (ErrorType) {
|
|
13
|
+
ErrorType["CONFIG_NOT_FOUND"] = "CONFIG_NOT_FOUND";
|
|
14
|
+
ErrorType["CONFIG_PARSE_ERROR"] = "CONFIG_PARSE_ERROR";
|
|
15
|
+
ErrorType["CONFIG_VALIDATION_ERROR"] = "CONFIG_VALIDATION_ERROR";
|
|
16
|
+
ErrorType["INVALID_PRESET"] = "INVALID_PRESET";
|
|
17
|
+
ErrorType["INVALID_INPUT_TYPE"] = "INVALID_INPUT_TYPE";
|
|
18
|
+
ErrorType["MISSING_REQUIRED_FIELD"] = "MISSING_REQUIRED_FIELD";
|
|
19
|
+
ErrorType["INPUT_DOCUMENT_ERROR"] = "INPUT_DOCUMENT_ERROR";
|
|
20
|
+
ErrorType["GENERATOR_ERROR"] = "GENERATOR_ERROR";
|
|
21
|
+
ErrorType["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
22
|
+
ErrorType["UNSUPPORTED_LANGUAGE"] = "UNSUPPORTED_LANGUAGE";
|
|
23
|
+
ErrorType["MISSING_INPUT_DOCUMENT"] = "MISSING_INPUT_DOCUMENT";
|
|
24
|
+
ErrorType["MISSING_PAYLOAD"] = "MISSING_PAYLOAD";
|
|
25
|
+
ErrorType["MISSING_PARAMETER"] = "MISSING_PARAMETER";
|
|
26
|
+
ErrorType["CIRCULAR_DEPENDENCY"] = "CIRCULAR_DEPENDENCY";
|
|
27
|
+
ErrorType["DUPLICATE_GENERATOR_ID"] = "DUPLICATE_GENERATOR_ID";
|
|
28
|
+
ErrorType["UNSUPPORTED_PRESET_FOR_INPUT"] = "UNSUPPORTED_PRESET_FOR_INPUT";
|
|
29
|
+
})(ErrorType || (exports.ErrorType = ErrorType = {}));
|
|
30
|
+
class CodegenError extends Error {
|
|
31
|
+
type;
|
|
32
|
+
help;
|
|
33
|
+
details;
|
|
34
|
+
constructor({ type, message, help, details }) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'CodegenError';
|
|
37
|
+
this.type = type;
|
|
38
|
+
this.help = help;
|
|
39
|
+
this.details = details;
|
|
40
|
+
// Maintains proper stack trace for where our error was thrown
|
|
41
|
+
if (Error.captureStackTrace) {
|
|
42
|
+
Error.captureStackTrace(this, CodegenError);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Format the error message for display to users
|
|
47
|
+
* @param useColors Whether to use colored output
|
|
48
|
+
*/
|
|
49
|
+
format(useColors = true) {
|
|
50
|
+
const c = useColors
|
|
51
|
+
? picocolors_1.default
|
|
52
|
+
: {
|
|
53
|
+
red: (s) => s,
|
|
54
|
+
yellow: (s) => s,
|
|
55
|
+
cyan: (s) => s,
|
|
56
|
+
dim: (s) => s,
|
|
57
|
+
bold: (s) => s
|
|
58
|
+
};
|
|
59
|
+
let output = `\n${c.red(c.bold('Error:'))} ${this.message}`;
|
|
60
|
+
if (this.details) {
|
|
61
|
+
output += `\n\n${c.yellow('Details:')}\n${c.dim(this.details)}`;
|
|
62
|
+
}
|
|
63
|
+
if (this.help) {
|
|
64
|
+
output += `\n\n${c.cyan('How to fix:')}\n${this.help}`;
|
|
65
|
+
}
|
|
66
|
+
return output;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.CodegenError = CodegenError;
|
|
70
|
+
/**
|
|
71
|
+
* Helper functions to create specific error types
|
|
72
|
+
*/
|
|
73
|
+
function createConfigNotFoundError(options) {
|
|
74
|
+
const { filePath, searchLocations } = options ?? {};
|
|
75
|
+
if (filePath) {
|
|
76
|
+
return new CodegenError({
|
|
77
|
+
type: ErrorType.CONFIG_NOT_FOUND,
|
|
78
|
+
message: `Configuration file not found at: ${filePath}`,
|
|
79
|
+
help: `Please check that the file exists and the path is correct.\nYou can create a configuration file using: codegen init`
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const locations = searchLocations?.map((loc) => ` - ${loc}`).join('\n') || '';
|
|
83
|
+
return new CodegenError({
|
|
84
|
+
type: ErrorType.CONFIG_NOT_FOUND,
|
|
85
|
+
message: 'No configuration file found in the current directory',
|
|
86
|
+
details: `Searched in the following locations:\n${locations}`,
|
|
87
|
+
help: `Create a configuration file using: codegen init\nOr specify a configuration file path: codegen generate <path-to-config>`
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
exports.createConfigNotFoundError = createConfigNotFoundError;
|
|
91
|
+
function createConfigParseError(options) {
|
|
92
|
+
const { filePath, originalError } = options;
|
|
93
|
+
return new CodegenError({
|
|
94
|
+
type: ErrorType.CONFIG_PARSE_ERROR,
|
|
95
|
+
message: `Failed to parse configuration file: ${filePath}`,
|
|
96
|
+
details: originalError.message,
|
|
97
|
+
help: `Check that your configuration file is valid JSON, YAML, or JavaScript.\nMake sure there are no syntax errors in the file.`
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
exports.createConfigParseError = createConfigParseError;
|
|
101
|
+
function createInvalidPresetError(options) {
|
|
102
|
+
const { preset, language } = options;
|
|
103
|
+
const validPresets = [
|
|
104
|
+
'payloads',
|
|
105
|
+
'parameters',
|
|
106
|
+
'headers',
|
|
107
|
+
'types',
|
|
108
|
+
'channels',
|
|
109
|
+
'client',
|
|
110
|
+
'models',
|
|
111
|
+
'custom'
|
|
112
|
+
];
|
|
113
|
+
const presetList = validPresets.map((p) => ` - ${p}`).join('\n');
|
|
114
|
+
return new CodegenError({
|
|
115
|
+
type: ErrorType.INVALID_PRESET,
|
|
116
|
+
message: `Invalid preset '${preset}' for language '${language}'`,
|
|
117
|
+
details: `Valid presets are:\n${presetList}`,
|
|
118
|
+
help: `Update your configuration to use a valid preset.\nFor more information, visit: https://the-codegen-project.org/docs/generators`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
exports.createInvalidPresetError = createInvalidPresetError;
|
|
122
|
+
function createInvalidInputTypeError(options) {
|
|
123
|
+
const { inputType } = options;
|
|
124
|
+
const validTypes = ['asyncapi', 'openapi', 'jsonschema'];
|
|
125
|
+
const typeList = validTypes.map((t) => ` - ${t}`).join('\n');
|
|
126
|
+
return new CodegenError({
|
|
127
|
+
type: ErrorType.INVALID_INPUT_TYPE,
|
|
128
|
+
message: `Invalid input type '${inputType}'`,
|
|
129
|
+
details: `Valid input types are:\n${typeList}`,
|
|
130
|
+
help: `Update your configuration to use a valid inputType.\nFor more information, visit: https://the-codegen-project.org/docs/category/inputs`
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
exports.createInvalidInputTypeError = createInvalidInputTypeError;
|
|
134
|
+
function createMissingRequiredFieldError(options) {
|
|
135
|
+
const { field, location } = options;
|
|
136
|
+
const locationSuffix = location ? ` at "${location}"` : '';
|
|
137
|
+
return new CodegenError({
|
|
138
|
+
type: ErrorType.MISSING_REQUIRED_FIELD,
|
|
139
|
+
message: `Missing required field: ${field}${locationSuffix}`,
|
|
140
|
+
help: `Add the required '${field}' field to your configuration file.\nFor more information, visit: https://the-codegen-project.org/docs/configurations/`
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
exports.createMissingRequiredFieldError = createMissingRequiredFieldError;
|
|
144
|
+
function createConfigValidationError(options) {
|
|
145
|
+
const { validationErrors } = options;
|
|
146
|
+
return new CodegenError({
|
|
147
|
+
type: ErrorType.CONFIG_VALIDATION_ERROR,
|
|
148
|
+
message: 'Configuration validation failed',
|
|
149
|
+
details: validationErrors.join('\n'),
|
|
150
|
+
help: `Review and fix the validation errors in your configuration file.\nFor more information, visit: https://the-codegen-project.org/docs/configurations/`
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.createConfigValidationError = createConfigValidationError;
|
|
154
|
+
function detectFormatHint(inputPath) {
|
|
155
|
+
if (inputPath.endsWith('.json')) {
|
|
156
|
+
return 'JSON';
|
|
157
|
+
}
|
|
158
|
+
if (inputPath.endsWith('.yaml') || inputPath.endsWith('.yml')) {
|
|
159
|
+
return 'YAML';
|
|
160
|
+
}
|
|
161
|
+
return 'JSON or YAML';
|
|
162
|
+
}
|
|
163
|
+
function createInputDocumentError(options) {
|
|
164
|
+
const { inputPath, inputType, errorMessage } = options;
|
|
165
|
+
const isUrl = inputPath.startsWith('http://') || inputPath.startsWith('https://');
|
|
166
|
+
const formatHint = detectFormatHint(inputPath);
|
|
167
|
+
const sourceHelp = isUrl
|
|
168
|
+
? `Check that the URL is reachable and returns a valid ${formatHint} document.`
|
|
169
|
+
: `Check that the input file exists and is a valid ${formatHint} file.`;
|
|
170
|
+
return new CodegenError({
|
|
171
|
+
type: ErrorType.INPUT_DOCUMENT_ERROR,
|
|
172
|
+
message: `Failed to load ${inputType} document: ${inputPath}`,
|
|
173
|
+
details: errorMessage,
|
|
174
|
+
help: `${sourceHelp}\nEnsure the document conforms to the ${inputType} specification.`
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
exports.createInputDocumentError = createInputDocumentError;
|
|
178
|
+
/**
|
|
179
|
+
* Build a typed error for a failed remote fetch. Help text is tailored
|
|
180
|
+
* to the HTTP status code (401/403 → auth, 404 → URL, 429 → rate-limit,
|
|
181
|
+
* timeout → timeout, network → connectivity, other → generic).
|
|
182
|
+
*/
|
|
183
|
+
function remoteFetchHelp(url, reason, status, cause) {
|
|
184
|
+
if (reason === 'timeout') {
|
|
185
|
+
return 'The request timed out. Increase the timeout, retry, or check that the host is reachable.';
|
|
186
|
+
}
|
|
187
|
+
if (status === 401 || status === 403) {
|
|
188
|
+
return `Authentication or authorization failed for ${url}. Check the 'auth' field in your configuration (token, header name, header value).`;
|
|
189
|
+
}
|
|
190
|
+
if (status === 404) {
|
|
191
|
+
return `The URL ${url} returned 404. Verify the URL is correct and the resource exists.`;
|
|
192
|
+
}
|
|
193
|
+
if (status === 429) {
|
|
194
|
+
return `The server is rate-limiting requests to ${url}. Retry later or reduce the request rate.`;
|
|
195
|
+
}
|
|
196
|
+
if (status && status >= 500) {
|
|
197
|
+
return `The server returned a ${status} error for ${url}. The remote service may be temporarily unavailable; retry later.`;
|
|
198
|
+
}
|
|
199
|
+
if (reason === 'network' || (!status && cause)) {
|
|
200
|
+
return `Could not reach ${url}. Check your network connection, DNS, and any firewall/proxy settings.`;
|
|
201
|
+
}
|
|
202
|
+
return `Could not fetch ${url}.`;
|
|
203
|
+
}
|
|
204
|
+
function formatStatusPart(status, statusText) {
|
|
205
|
+
if (!status) {
|
|
206
|
+
return '';
|
|
207
|
+
}
|
|
208
|
+
const trailing = statusText ? ` ${statusText}` : '';
|
|
209
|
+
return ` (HTTP ${status}${trailing})`;
|
|
210
|
+
}
|
|
211
|
+
function stringifyCause(cause) {
|
|
212
|
+
if (cause instanceof Error) {
|
|
213
|
+
return cause.message;
|
|
214
|
+
}
|
|
215
|
+
if (cause === undefined) {
|
|
216
|
+
return '';
|
|
217
|
+
}
|
|
218
|
+
return String(cause);
|
|
219
|
+
}
|
|
220
|
+
function createRemoteFetchError(options) {
|
|
221
|
+
const { url, status, statusText, cause, reason } = options;
|
|
222
|
+
const help = remoteFetchHelp(url, reason, status, cause);
|
|
223
|
+
const statusPart = formatStatusPart(status, statusText);
|
|
224
|
+
const causePart = stringifyCause(cause);
|
|
225
|
+
return new CodegenError({
|
|
226
|
+
type: ErrorType.INPUT_DOCUMENT_ERROR,
|
|
227
|
+
message: `Failed to fetch remote document from ${url}${statusPart}`,
|
|
228
|
+
details: causePart || undefined,
|
|
229
|
+
help
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
exports.createRemoteFetchError = createRemoteFetchError;
|
|
233
|
+
function createGeneratorError(options) {
|
|
234
|
+
const { generatorId, originalError } = options;
|
|
235
|
+
return new CodegenError({
|
|
236
|
+
type: ErrorType.GENERATOR_ERROR,
|
|
237
|
+
message: `Generator '${generatorId}' failed`,
|
|
238
|
+
details: originalError.message,
|
|
239
|
+
help: `Check the generator configuration and input document.\nIf the issue persists, please report it at: https://github.com/the-codegen-project/cli/issues`
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
exports.createGeneratorError = createGeneratorError;
|
|
243
|
+
function createUnsupportedLanguageError(options) {
|
|
244
|
+
const { preset, language } = options;
|
|
245
|
+
return new CodegenError({
|
|
246
|
+
type: ErrorType.UNSUPPORTED_LANGUAGE,
|
|
247
|
+
message: `Language '${language}' is not supported for the '${preset}' preset`,
|
|
248
|
+
details: `Currently only 'typescript' is supported.`,
|
|
249
|
+
help: `Change the 'language' field in your configuration to 'typescript'.\nFor more information: https://the-codegen-project.org/docs/configurations`
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
exports.createUnsupportedLanguageError = createUnsupportedLanguageError;
|
|
253
|
+
function createMissingInputDocumentError(options) {
|
|
254
|
+
const { expectedType, generatorPreset } = options;
|
|
255
|
+
const presetContext = generatorPreset
|
|
256
|
+
? ` for the '${generatorPreset}' generator`
|
|
257
|
+
: '';
|
|
258
|
+
return new CodegenError({
|
|
259
|
+
type: ErrorType.MISSING_INPUT_DOCUMENT,
|
|
260
|
+
message: `Expected ${expectedType} document${presetContext}, but none was provided`,
|
|
261
|
+
help: `1. Ensure your configuration has 'inputType: "${expectedType}"'\n2. Verify 'inputPath' points to a valid ${expectedType} document\n3. Check the document exists and is readable\n\nFor more information: https://the-codegen-project.org/docs/inputs/${expectedType}`
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
exports.createMissingInputDocumentError = createMissingInputDocumentError;
|
|
265
|
+
function createMissingPayloadError(options) {
|
|
266
|
+
const { channelOrOperation, protocol } = options;
|
|
267
|
+
const protocolContext = protocol ? ` for ${protocol}` : '';
|
|
268
|
+
return new CodegenError({
|
|
269
|
+
type: ErrorType.MISSING_PAYLOAD,
|
|
270
|
+
message: `Could not find payload for '${channelOrOperation}'${protocolContext}`,
|
|
271
|
+
help: `1. Ensure the 'payloads' generator is configured before 'channels'\n2. Check that your spec defines message payloads for this channel\n3. Verify the channel/operation name matches the spec\n\nFor more information: https://the-codegen-project.org/docs/generators/channels`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
exports.createMissingPayloadError = createMissingPayloadError;
|
|
275
|
+
function createMissingParameterError(options) {
|
|
276
|
+
const { channelOrOperation, protocol } = options;
|
|
277
|
+
const protocolContext = protocol ? ` for ${protocol}` : '';
|
|
278
|
+
return new CodegenError({
|
|
279
|
+
type: ErrorType.MISSING_PARAMETER,
|
|
280
|
+
message: `Could not find parameter for '${channelOrOperation}'${protocolContext}`,
|
|
281
|
+
help: `1. Ensure the 'parameters' generator is configured before 'channels'\n2. Check that your spec defines parameters for this channel\n3. Verify the channel/operation name matches the spec\n\nFor more information: https://the-codegen-project.org/docs/generators/channels`
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
exports.createMissingParameterError = createMissingParameterError;
|
|
285
|
+
function createCircularDependencyError(options) {
|
|
286
|
+
const generatorIds = options?.generatorIds;
|
|
287
|
+
const idsContext = generatorIds?.length
|
|
288
|
+
? `\nInvolved generators: ${generatorIds.join(', ')}`
|
|
289
|
+
: '';
|
|
290
|
+
return new CodegenError({
|
|
291
|
+
type: ErrorType.CIRCULAR_DEPENDENCY,
|
|
292
|
+
message: `Circular dependency detected in generator configuration${idsContext}`,
|
|
293
|
+
help: `Review the 'dependencies' field in your generators to remove circular references.\nGenerators are executed in dependency order - ensure there's no A->B->A cycle.\n\nFor more information: https://the-codegen-project.org/docs/configurations`
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
exports.createCircularDependencyError = createCircularDependencyError;
|
|
297
|
+
function createDuplicateGeneratorIdError(options) {
|
|
298
|
+
const { duplicateIds } = options;
|
|
299
|
+
return new CodegenError({
|
|
300
|
+
type: ErrorType.DUPLICATE_GENERATOR_ID,
|
|
301
|
+
message: `Duplicate generator IDs found: ${duplicateIds.join(', ')}`,
|
|
302
|
+
help: `Each generator must have a unique 'id'. Either:\n1. Remove duplicate generators\n2. Give each generator a unique 'id' field\n\nFor more information: https://the-codegen-project.org/docs/configurations`
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
exports.createDuplicateGeneratorIdError = createDuplicateGeneratorIdError;
|
|
306
|
+
function createUnsupportedPresetForInputError(options) {
|
|
307
|
+
const { preset, inputType, supportedPresets } = options;
|
|
308
|
+
return new CodegenError({
|
|
309
|
+
type: ErrorType.UNSUPPORTED_PRESET_FOR_INPUT,
|
|
310
|
+
message: `Preset '${preset}' is not supported with '${inputType}' input`,
|
|
311
|
+
details: `Supported presets for ${inputType}: ${supportedPresets.join(', ')}`,
|
|
312
|
+
help: `Change your generator to use a supported preset, or change your input type.\n\nFor more information: https://the-codegen-project.org/docs/generators`
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
exports.createUnsupportedPresetForInputError = createUnsupportedPresetForInputError;
|
|
316
|
+
function createMissingDependencyOutputError(options) {
|
|
317
|
+
const { generatorPreset, dependencyName } = options;
|
|
318
|
+
return new CodegenError({
|
|
319
|
+
type: ErrorType.GENERATOR_ERROR,
|
|
320
|
+
message: `Internal error: Missing dependency output '${dependencyName}' for '${generatorPreset}' generator`,
|
|
321
|
+
help: `This is likely a bug. Please report it at: https://github.com/the-codegen-project/cli/issues`
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
exports.createMissingDependencyOutputError = createMissingDependencyOutputError;
|
|
325
|
+
/**
|
|
326
|
+
* Parse Zod validation errors and convert them to user-friendly messages
|
|
327
|
+
*/
|
|
328
|
+
function parseZodErrors(zodError) {
|
|
329
|
+
const errors = [];
|
|
330
|
+
if (zodError.issues) {
|
|
331
|
+
for (const error of zodError.issues) {
|
|
332
|
+
const path = error.path.join('.');
|
|
333
|
+
const message = error.message;
|
|
334
|
+
// Handle specific error types
|
|
335
|
+
if (error.code === 'invalid_union_discriminator') {
|
|
336
|
+
const expected = error.options?.join("' | '") || '';
|
|
337
|
+
errors.push(`Invalid value at "${path}". Expected: '${expected}'`);
|
|
338
|
+
}
|
|
339
|
+
else if (error.code === 'invalid_type') {
|
|
340
|
+
errors.push(`Invalid type at "${path}". Expected ${error.expected}, got ${error.received}`);
|
|
341
|
+
}
|
|
342
|
+
else if (error.code === 'invalid_literal') {
|
|
343
|
+
errors.push(`Invalid value at "${path}". Expected: '${error.expected}'`);
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
errors.push(`${message} at "${path}"`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return errors;
|
|
351
|
+
}
|
|
352
|
+
exports.parseZodErrors = parseZodErrors;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';
|
|
2
|
+
import { GenericCodegenContext } from '../../types';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { OpenAPIV3, OpenAPIV2, OpenAPIV3_1 } from 'openapi-types';
|
|
5
|
+
import { JsonSchemaDocument } from '../../inputs/jsonschema';
|
|
6
|
+
export interface CustomContext extends GenericCodegenContext {
|
|
7
|
+
inputType: 'asyncapi' | 'openapi' | 'jsonschema';
|
|
8
|
+
asyncapiDocument?: AsyncAPIDocumentInterface;
|
|
9
|
+
openapiDocument?: OpenAPIV3.Document | OpenAPIV2.Document | OpenAPIV3_1.Document;
|
|
10
|
+
jsonSchemaDocument?: JsonSchemaDocument;
|
|
11
|
+
generator: CustomGenerator;
|
|
12
|
+
}
|
|
13
|
+
export declare const zodCustomGenerator: z.ZodObject<{
|
|
14
|
+
id: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
15
|
+
dependencies: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
16
|
+
preset: z.ZodDefault<z.ZodLiteral<"custom">>;
|
|
17
|
+
options: z.ZodDefault<z.ZodOptional<z.ZodAny>>;
|
|
18
|
+
outputPath: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
19
|
+
language: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"typescript">>>;
|
|
20
|
+
renderFunction: z.ZodDefault<z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodDefault<z.ZodObject<{
|
|
21
|
+
inputType: z.ZodDefault<z.ZodEnum<["asyncapi", "openapi", "jsonschema"]>>;
|
|
22
|
+
asyncapiDocument: z.ZodAny;
|
|
23
|
+
openapiDocument: z.ZodAny;
|
|
24
|
+
jsonSchemaDocument: z.ZodAny;
|
|
25
|
+
generator: z.ZodAny;
|
|
26
|
+
dependencyOutputs: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
inputType: "asyncapi" | "openapi" | "jsonschema";
|
|
29
|
+
dependencyOutputs: Record<string, any>;
|
|
30
|
+
generator?: any;
|
|
31
|
+
asyncapiDocument?: any;
|
|
32
|
+
openapiDocument?: any;
|
|
33
|
+
jsonSchemaDocument?: any;
|
|
34
|
+
}, {
|
|
35
|
+
inputType?: "asyncapi" | "openapi" | "jsonschema" | undefined;
|
|
36
|
+
generator?: any;
|
|
37
|
+
asyncapiDocument?: any;
|
|
38
|
+
openapiDocument?: any;
|
|
39
|
+
dependencyOutputs?: Record<string, any> | undefined;
|
|
40
|
+
jsonSchemaDocument?: any;
|
|
41
|
+
}>>, z.ZodDefault<z.ZodOptional<z.ZodAny>>], z.ZodUnknown>, z.ZodAny>>>;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
preset: "custom";
|
|
44
|
+
id: string;
|
|
45
|
+
dependencies: string[];
|
|
46
|
+
language: "typescript";
|
|
47
|
+
outputPath: string;
|
|
48
|
+
renderFunction: (args_0: {
|
|
49
|
+
inputType?: "asyncapi" | "openapi" | "jsonschema" | undefined;
|
|
50
|
+
generator?: any;
|
|
51
|
+
asyncapiDocument?: any;
|
|
52
|
+
openapiDocument?: any;
|
|
53
|
+
dependencyOutputs?: Record<string, any> | undefined;
|
|
54
|
+
jsonSchemaDocument?: any;
|
|
55
|
+
} | undefined, args_1: any, ...args_2: unknown[]) => any;
|
|
56
|
+
options?: any;
|
|
57
|
+
}, {
|
|
58
|
+
options?: any;
|
|
59
|
+
preset?: "custom" | undefined;
|
|
60
|
+
id?: string | undefined;
|
|
61
|
+
dependencies?: string[] | undefined;
|
|
62
|
+
language?: "typescript" | undefined;
|
|
63
|
+
outputPath?: string | undefined;
|
|
64
|
+
renderFunction?: ((args_0: {
|
|
65
|
+
inputType: "asyncapi" | "openapi" | "jsonschema";
|
|
66
|
+
dependencyOutputs: Record<string, any>;
|
|
67
|
+
generator?: any;
|
|
68
|
+
asyncapiDocument?: any;
|
|
69
|
+
openapiDocument?: any;
|
|
70
|
+
jsonSchemaDocument?: any;
|
|
71
|
+
}, args_1: any, ...args_2: unknown[]) => any) | undefined;
|
|
72
|
+
}>;
|
|
73
|
+
export type CustomGenerator = z.input<typeof zodCustomGenerator>;
|
|
74
|
+
export type CustomGeneratorInternal = z.infer<typeof zodCustomGenerator>;
|
|
75
|
+
export declare const defaultCustomGenerator: CustomGeneratorInternal;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultCustomGenerator = exports.zodCustomGenerator = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.zodCustomGenerator = zod_1.z.object({
|
|
6
|
+
id: zod_1.z
|
|
7
|
+
.string()
|
|
8
|
+
.optional()
|
|
9
|
+
.default('custom')
|
|
10
|
+
.describe('Unique identifier for this generator instance. Used by other generators to reference this one as a dependency. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)'),
|
|
11
|
+
dependencies: zod_1.z
|
|
12
|
+
.array(zod_1.z.string())
|
|
13
|
+
.optional()
|
|
14
|
+
.default([])
|
|
15
|
+
.describe('The list of other generator IDs that this generator depends on. Outputs from these generators are passed to renderFunction via dependencyOutputs. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)'),
|
|
16
|
+
preset: zod_1.z
|
|
17
|
+
.literal('custom')
|
|
18
|
+
.default('custom')
|
|
19
|
+
.describe('Lets you write a custom render function that produces arbitrary code from the parsed input document and the outputs of other generators. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)'),
|
|
20
|
+
options: zod_1.z
|
|
21
|
+
.any()
|
|
22
|
+
.optional()
|
|
23
|
+
.default({})
|
|
24
|
+
.describe('Arbitrary user-defined options that are forwarded to the renderFunction as its second argument. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)'),
|
|
25
|
+
outputPath: zod_1.z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.default('custom')
|
|
29
|
+
.describe('The directory path where files written by the custom generator will be placed. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)'),
|
|
30
|
+
language: zod_1.z.literal('typescript').optional().default('typescript'),
|
|
31
|
+
renderFunction: zod_1.z
|
|
32
|
+
.function()
|
|
33
|
+
.args(zod_1.z
|
|
34
|
+
.object({
|
|
35
|
+
inputType: zod_1.z
|
|
36
|
+
.enum(['asyncapi', 'openapi', 'jsonschema'])
|
|
37
|
+
.default('asyncapi')
|
|
38
|
+
.describe('The type of input document being processed. [Read more about supported inputs here](https://the-codegen-project.org/docs/configurations)'),
|
|
39
|
+
asyncapiDocument: zod_1.z
|
|
40
|
+
.any()
|
|
41
|
+
.describe('The parsed AsyncAPI document (AsyncAPIDocumentInterface from @asyncapi/parser) when inputType is "asyncapi". [Read more about AsyncAPI input here](https://the-codegen-project.org/docs/inputs/asyncapi)'),
|
|
42
|
+
openapiDocument: zod_1.z
|
|
43
|
+
.any()
|
|
44
|
+
.describe('The parsed OpenAPI document (one of OpenAPIV3.Document | OpenAPIV2.Document | OpenAPIV3_1.Document from openapi-types) when inputType is "openapi". [Read more about OpenAPI input here](https://the-codegen-project.org/docs/inputs/openapi)'),
|
|
45
|
+
jsonSchemaDocument: zod_1.z
|
|
46
|
+
.any()
|
|
47
|
+
.describe('The parsed JSON Schema document when inputType is "jsonschema". [Read more about JSON Schema input here](https://the-codegen-project.org/docs/inputs/jsonschema)'),
|
|
48
|
+
generator: zod_1.z
|
|
49
|
+
.any()
|
|
50
|
+
.describe('The fully resolved configuration object for this custom generator instance. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)'),
|
|
51
|
+
dependencyOutputs: zod_1.z
|
|
52
|
+
.record(zod_1.z.any())
|
|
53
|
+
.default({})
|
|
54
|
+
.describe('A map of generator ID to render result for each generator listed in dependencies. Use this to access models, channels, etc. produced by other generators. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)')
|
|
55
|
+
})
|
|
56
|
+
.default({}), zod_1.z
|
|
57
|
+
.any()
|
|
58
|
+
.optional()
|
|
59
|
+
.describe('The user-defined options passed in via the "options" field of this generator configuration. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)')
|
|
60
|
+
.default({}))
|
|
61
|
+
.returns(zod_1.z.any())
|
|
62
|
+
.optional()
|
|
63
|
+
.default(() => { })
|
|
64
|
+
.describe('The render function executed by the custom generator. Receives the parsed input document and the outputs of dependency generators, and is responsible for producing custom code. [Read more about the custom generator here](https://the-codegen-project.org/docs/generators/custom)')
|
|
65
|
+
});
|
|
66
|
+
exports.defaultCustomGenerator = exports.zodCustomGenerator.parse({});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { TypescriptParametersGenerator, generateTypescriptParameters, defaultTypeScriptParametersOptions, TypeScriptPayloadGenerator, generateTypescriptPayload, defaultTypeScriptPayloadGenerator, TypeScriptChannelsGenerator, generateTypeScriptChannels, defaultTypeScriptChannelsGenerator, TypeScriptClientGenerator, defaultTypeScriptClientGenerator, generateTypeScriptClient, TypeScriptChannelsContext, TypeScriptClientContext, TypeScriptPayloadContext, TypescriptParametersContext, TypeScriptPayloadGeneratorInternal, TypeScriptChannelsGeneratorInternal, TypeScriptClientGeneratorInternal, TypescriptParametersGeneratorInternal, TypeScriptParameterRenderType, TypescriptHeadersContext, TypescriptHeadersGenerator, defaultTypeScriptHeadersOptions, generateTypescriptHeaders, TypescriptHeadersGeneratorInternal, TypescriptTypesContext, TypescriptTypesGenerator, TypescriptTypesGeneratorInternal, defaultTypeScriptTypesOptions, generateTypescriptTypes, ChannelFunctionTypes } from './typescript';
|
|
2
|
+
export { defaultCustomGenerator, CustomGenerator, CustomGeneratorInternal, CustomContext } from './generic/custom';
|
|
3
|
+
import { GenerationResult, RunGeneratorContext } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Function that runs the given generator context ensuring the generators are rendered in the correct order.
|
|
6
|
+
*/
|
|
7
|
+
export declare function runGenerators(context: RunGeneratorContext): Promise<GenerationResult>;
|
|
8
|
+
/**
|
|
9
|
+
* Load the configuration and run the generator
|
|
10
|
+
*
|
|
11
|
+
* @param configFileOrContext Either a config file path or a pre-realized RunGeneratorContext
|
|
12
|
+
* @returns Generation result with file tracking information
|
|
13
|
+
*/
|
|
14
|
+
export declare function generateWithConfig(configFileOrContext: string | undefined | RunGeneratorContext): Promise<GenerationResult>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateWithConfig = exports.runGenerators = exports.defaultCustomGenerator = exports.ChannelFunctionTypes = exports.generateTypescriptTypes = exports.defaultTypeScriptTypesOptions = exports.generateTypescriptHeaders = exports.defaultTypeScriptHeadersOptions = exports.generateTypeScriptClient = exports.defaultTypeScriptClientGenerator = exports.defaultTypeScriptChannelsGenerator = exports.generateTypeScriptChannels = exports.defaultTypeScriptPayloadGenerator = exports.generateTypescriptPayload = exports.defaultTypeScriptParametersOptions = exports.generateTypescriptParameters = void 0;
|
|
4
|
+
var typescript_1 = require("./typescript");
|
|
5
|
+
Object.defineProperty(exports, "generateTypescriptParameters", { enumerable: true, get: function () { return typescript_1.generateTypescriptParameters; } });
|
|
6
|
+
Object.defineProperty(exports, "defaultTypeScriptParametersOptions", { enumerable: true, get: function () { return typescript_1.defaultTypeScriptParametersOptions; } });
|
|
7
|
+
Object.defineProperty(exports, "generateTypescriptPayload", { enumerable: true, get: function () { return typescript_1.generateTypescriptPayload; } });
|
|
8
|
+
Object.defineProperty(exports, "defaultTypeScriptPayloadGenerator", { enumerable: true, get: function () { return typescript_1.defaultTypeScriptPayloadGenerator; } });
|
|
9
|
+
Object.defineProperty(exports, "generateTypeScriptChannels", { enumerable: true, get: function () { return typescript_1.generateTypeScriptChannels; } });
|
|
10
|
+
Object.defineProperty(exports, "defaultTypeScriptChannelsGenerator", { enumerable: true, get: function () { return typescript_1.defaultTypeScriptChannelsGenerator; } });
|
|
11
|
+
Object.defineProperty(exports, "defaultTypeScriptClientGenerator", { enumerable: true, get: function () { return typescript_1.defaultTypeScriptClientGenerator; } });
|
|
12
|
+
Object.defineProperty(exports, "generateTypeScriptClient", { enumerable: true, get: function () { return typescript_1.generateTypeScriptClient; } });
|
|
13
|
+
Object.defineProperty(exports, "defaultTypeScriptHeadersOptions", { enumerable: true, get: function () { return typescript_1.defaultTypeScriptHeadersOptions; } });
|
|
14
|
+
Object.defineProperty(exports, "generateTypescriptHeaders", { enumerable: true, get: function () { return typescript_1.generateTypescriptHeaders; } });
|
|
15
|
+
Object.defineProperty(exports, "defaultTypeScriptTypesOptions", { enumerable: true, get: function () { return typescript_1.defaultTypeScriptTypesOptions; } });
|
|
16
|
+
Object.defineProperty(exports, "generateTypescriptTypes", { enumerable: true, get: function () { return typescript_1.generateTypescriptTypes; } });
|
|
17
|
+
Object.defineProperty(exports, "ChannelFunctionTypes", { enumerable: true, get: function () { return typescript_1.ChannelFunctionTypes; } });
|
|
18
|
+
var custom_1 = require("./generic/custom");
|
|
19
|
+
Object.defineProperty(exports, "defaultCustomGenerator", { enumerable: true, get: function () { return custom_1.defaultCustomGenerator; } });
|
|
20
|
+
const renderer_1 = require("../renderer");
|
|
21
|
+
const configurations_1 = require("../configurations");
|
|
22
|
+
/**
|
|
23
|
+
* Function that runs the given generator context ensuring the generators are rendered in the correct order.
|
|
24
|
+
*/
|
|
25
|
+
async function runGenerators(context) {
|
|
26
|
+
const graph = (0, renderer_1.determineRenderGraph)(context);
|
|
27
|
+
return (0, renderer_1.renderGraph)(context, graph);
|
|
28
|
+
}
|
|
29
|
+
exports.runGenerators = runGenerators;
|
|
30
|
+
/**
|
|
31
|
+
* Load the configuration and run the generator
|
|
32
|
+
*
|
|
33
|
+
* @param configFileOrContext Either a config file path or a pre-realized RunGeneratorContext
|
|
34
|
+
* @returns Generation result with file tracking information
|
|
35
|
+
*/
|
|
36
|
+
async function generateWithConfig(configFileOrContext) {
|
|
37
|
+
const context = typeof configFileOrContext === 'string' || configFileOrContext === undefined
|
|
38
|
+
? await (0, configurations_1.realizeGeneratorContext)(configFileOrContext)
|
|
39
|
+
: configFileOrContext;
|
|
40
|
+
return runGenerators(context);
|
|
41
|
+
}
|
|
42
|
+
exports.generateWithConfig = generateWithConfig;
|