@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,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.zodTheCodegenConfiguration = exports.zodJsonSchemaCodegenConfiguration = exports.zodJsonSchemaTypescriptConfig = exports.zodOpenAPICodegenConfiguration = exports.zodOpenAPITypescriptConfig = exports.zodAsyncAPICodegenConfiguration = exports.zodAsyncAPITypescriptConfig = exports.zodProjectTelemetryConfig = exports.zodImportExtension = exports.zodInputAuth = exports.zodJsonSchemaGenerators = exports.zodJsonSchemaTypeScriptGenerators = exports.zodOpenAPIGenerators = exports.zodOpenAPITypeScriptGenerators = exports.zodAsyncAPIGenerators = exports.zodAsyncAPITypeScriptGenerators = void 0;
|
|
4
|
+
const channels_1 = require("./generators/typescript/channels");
|
|
5
|
+
const parameters_1 = require("./generators/typescript/parameters");
|
|
6
|
+
const payloads_1 = require("./generators/typescript/payloads");
|
|
7
|
+
const custom_1 = require("./generators/generic/custom");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const client_1 = require("./generators/typescript/client");
|
|
10
|
+
const headers_1 = require("./generators/typescript/headers");
|
|
11
|
+
const types_1 = require("./generators/typescript/types");
|
|
12
|
+
const models_1 = require("./generators/typescript/models");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
exports.zodAsyncAPITypeScriptGenerators = zod_1.z.discriminatedUnion('preset', [
|
|
15
|
+
payloads_1.zodTypeScriptPayloadGenerator,
|
|
16
|
+
parameters_1.zodTypescriptParametersGenerator,
|
|
17
|
+
channels_1.zodTypescriptChannelsGenerator,
|
|
18
|
+
client_1.zodTypescriptClientGenerator,
|
|
19
|
+
headers_1.zodTypescriptHeadersGenerator,
|
|
20
|
+
types_1.zodTypescriptTypesGenerator,
|
|
21
|
+
models_1.zodTypescriptModelsGenerator,
|
|
22
|
+
custom_1.zodCustomGenerator
|
|
23
|
+
]);
|
|
24
|
+
exports.zodAsyncAPIGenerators = zod_1.z.union([
|
|
25
|
+
...exports.zodAsyncAPITypeScriptGenerators.options
|
|
26
|
+
]);
|
|
27
|
+
exports.zodOpenAPITypeScriptGenerators = zod_1.z.discriminatedUnion('preset', [
|
|
28
|
+
payloads_1.zodTypeScriptPayloadGenerator,
|
|
29
|
+
parameters_1.zodTypescriptParametersGenerator,
|
|
30
|
+
headers_1.zodTypescriptHeadersGenerator,
|
|
31
|
+
types_1.zodTypescriptTypesGenerator,
|
|
32
|
+
channels_1.zodTypescriptChannelsGenerator,
|
|
33
|
+
models_1.zodTypescriptModelsGenerator,
|
|
34
|
+
custom_1.zodCustomGenerator
|
|
35
|
+
]);
|
|
36
|
+
exports.zodOpenAPIGenerators = zod_1.z.union([
|
|
37
|
+
...exports.zodOpenAPITypeScriptGenerators.options
|
|
38
|
+
]);
|
|
39
|
+
exports.zodJsonSchemaTypeScriptGenerators = zod_1.z.discriminatedUnion('preset', [models_1.zodTypescriptModelsGenerator, custom_1.zodCustomGenerator]);
|
|
40
|
+
exports.zodJsonSchemaGenerators = zod_1.z.union([
|
|
41
|
+
...exports.zodJsonSchemaTypeScriptGenerators.options
|
|
42
|
+
]);
|
|
43
|
+
const SCHEMA_DESCRIPTION = 'JSON Schema reference used by IDEs to enable auto-completion and validation in JSON and YAML configuration files. [Read more about configurations here](https://the-codegen-project.org/docs/configurations)';
|
|
44
|
+
const LANGUAGE_DESCRIPTION = 'Sets the global language for all generators. Either this global value or each generator must define its own language. [Read more about configurations here](https://the-codegen-project.org/docs/configurations)';
|
|
45
|
+
const DOCUMENT_TYPE_DESCRIPTION = 'The type of input document being processed (asyncapi, openapi, or jsonschema). [Read more about inputs here](https://the-codegen-project.org/docs/configurations)';
|
|
46
|
+
const INPUT_PATH_DESCRIPTION = 'Path or URL to the input document used as the source for code generation. [Read more about configurations here](https://the-codegen-project.org/docs/configurations)';
|
|
47
|
+
const GENERATORS_DESCRIPTION = 'The list of generators to run as part of this configuration. [Read more about generators here](https://the-codegen-project.org/docs/generators)';
|
|
48
|
+
const INPUT_AUTH_DESCRIPTION = 'Authentication for fetching remote input specifications via http(s). Ignored for local file paths. ' +
|
|
49
|
+
'WARNING: these credentials are sent to every URL the loader fetches, including external $ref targets on other hosts. ' +
|
|
50
|
+
'See https://the-codegen-project.org/docs/configurations#auth-scope-and-security-considerations for details.';
|
|
51
|
+
/**
|
|
52
|
+
* Authentication configuration for fetching remote input documents.
|
|
53
|
+
* One of three shapes:
|
|
54
|
+
* - bearer: adds `Authorization: Bearer <token>`.
|
|
55
|
+
* - apiKey: adds `<header>: <value>`.
|
|
56
|
+
* - custom: adds the given headers verbatim.
|
|
57
|
+
*
|
|
58
|
+
* The same headers are attached to every URL the loader fetches,
|
|
59
|
+
* including external `$ref` targets on other hosts.
|
|
60
|
+
*/
|
|
61
|
+
exports.zodInputAuth = zod_1.z
|
|
62
|
+
.discriminatedUnion('type', [
|
|
63
|
+
zod_1.z.object({
|
|
64
|
+
type: zod_1.z.literal('bearer'),
|
|
65
|
+
token: zod_1.z.string().min(1)
|
|
66
|
+
}),
|
|
67
|
+
zod_1.z.object({
|
|
68
|
+
type: zod_1.z.literal('apiKey'),
|
|
69
|
+
header: zod_1.z.string().min(1),
|
|
70
|
+
value: zod_1.z.string().min(1)
|
|
71
|
+
}),
|
|
72
|
+
zod_1.z.object({
|
|
73
|
+
type: zod_1.z.literal('custom'),
|
|
74
|
+
headers: zod_1.z.record(zod_1.z.string(), zod_1.z.string())
|
|
75
|
+
})
|
|
76
|
+
])
|
|
77
|
+
.optional()
|
|
78
|
+
.describe(INPUT_AUTH_DESCRIPTION);
|
|
79
|
+
// Re-export from utils - the canonical source of truth for import extension
|
|
80
|
+
var utils_2 = require("./utils");
|
|
81
|
+
Object.defineProperty(exports, "zodImportExtension", { enumerable: true, get: function () { return utils_2.zodImportExtension; } });
|
|
82
|
+
/**
|
|
83
|
+
* Project-level telemetry configuration
|
|
84
|
+
* Allows overriding global telemetry settings for specific projects
|
|
85
|
+
*/
|
|
86
|
+
exports.zodProjectTelemetryConfig = zod_1.z
|
|
87
|
+
.object({
|
|
88
|
+
enabled: zod_1.z
|
|
89
|
+
.boolean()
|
|
90
|
+
.optional()
|
|
91
|
+
.describe('Enable or disable anonymous telemetry collection for this project. Overrides the global telemetry setting in ~/.the-codegen-project/config.json. [Read more about telemetry here](https://the-codegen-project.org/docs/telemetry)'),
|
|
92
|
+
endpoint: zod_1.z
|
|
93
|
+
.string()
|
|
94
|
+
.optional()
|
|
95
|
+
.describe('Custom telemetry endpoint URL for self-hosted analytics. Overrides the global telemetry endpoint. [Read more about telemetry here](https://the-codegen-project.org/docs/telemetry)'),
|
|
96
|
+
trackingId: zod_1.z
|
|
97
|
+
.string()
|
|
98
|
+
.optional()
|
|
99
|
+
.describe('Custom tracking ID used to attribute telemetry events to a specific project or organization. Overrides the global tracking ID. [Read more about telemetry here](https://the-codegen-project.org/docs/telemetry)')
|
|
100
|
+
})
|
|
101
|
+
.optional()
|
|
102
|
+
.describe('Project-level telemetry configuration that overrides the global settings in ~/.the-codegen-project/config.json. [Read more about telemetry here](https://the-codegen-project.org/docs/telemetry)');
|
|
103
|
+
/**
|
|
104
|
+
* TypeScript-specific configuration options.
|
|
105
|
+
* These are only valid when language is 'typescript' (or omitted, defaulting to typescript).
|
|
106
|
+
*/
|
|
107
|
+
const zodTypeScriptConfigOptions = {
|
|
108
|
+
language: zod_1.z.literal('typescript').optional().describe(LANGUAGE_DESCRIPTION),
|
|
109
|
+
importExtension: utils_1.zodImportExtension
|
|
110
|
+
};
|
|
111
|
+
// =============================================================================
|
|
112
|
+
// AsyncAPI Configuration
|
|
113
|
+
// =============================================================================
|
|
114
|
+
/**
|
|
115
|
+
* TypeScript configuration for AsyncAPI input.
|
|
116
|
+
* When other languages are added, this becomes part of a z.union([typescript, python, ...])
|
|
117
|
+
*/
|
|
118
|
+
exports.zodAsyncAPITypescriptConfig = zod_1.z.object({
|
|
119
|
+
$schema: zod_1.z.string().optional().describe(SCHEMA_DESCRIPTION),
|
|
120
|
+
inputType: zod_1.z.literal('asyncapi').describe(DOCUMENT_TYPE_DESCRIPTION),
|
|
121
|
+
inputPath: zod_1.z.string().describe(INPUT_PATH_DESCRIPTION),
|
|
122
|
+
auth: exports.zodInputAuth,
|
|
123
|
+
...zodTypeScriptConfigOptions,
|
|
124
|
+
generators: zod_1.z
|
|
125
|
+
.array(exports.zodAsyncAPITypeScriptGenerators)
|
|
126
|
+
.describe(GENERATORS_DESCRIPTION),
|
|
127
|
+
telemetry: exports.zodProjectTelemetryConfig
|
|
128
|
+
});
|
|
129
|
+
// For now, only TypeScript is supported. When adding new languages:
|
|
130
|
+
// export const zodAsyncAPICodegenConfiguration = z.union([
|
|
131
|
+
// zodAsyncAPITypescriptConfig,
|
|
132
|
+
// zodAsyncAPIPythonConfig,
|
|
133
|
+
// ]);
|
|
134
|
+
exports.zodAsyncAPICodegenConfiguration = exports.zodAsyncAPITypescriptConfig;
|
|
135
|
+
// =============================================================================
|
|
136
|
+
// OpenAPI Configuration
|
|
137
|
+
// =============================================================================
|
|
138
|
+
/**
|
|
139
|
+
* TypeScript configuration for OpenAPI input.
|
|
140
|
+
*/
|
|
141
|
+
exports.zodOpenAPITypescriptConfig = zod_1.z.object({
|
|
142
|
+
$schema: zod_1.z.string().optional().describe(SCHEMA_DESCRIPTION),
|
|
143
|
+
inputType: zod_1.z.literal('openapi').describe(DOCUMENT_TYPE_DESCRIPTION),
|
|
144
|
+
inputPath: zod_1.z.string().describe(INPUT_PATH_DESCRIPTION),
|
|
145
|
+
auth: exports.zodInputAuth,
|
|
146
|
+
...zodTypeScriptConfigOptions,
|
|
147
|
+
generators: zod_1.z
|
|
148
|
+
.array(exports.zodOpenAPITypeScriptGenerators)
|
|
149
|
+
.describe(GENERATORS_DESCRIPTION),
|
|
150
|
+
telemetry: exports.zodProjectTelemetryConfig
|
|
151
|
+
});
|
|
152
|
+
// For now, only TypeScript is supported
|
|
153
|
+
exports.zodOpenAPICodegenConfiguration = exports.zodOpenAPITypescriptConfig;
|
|
154
|
+
// =============================================================================
|
|
155
|
+
// JSON Schema Configuration
|
|
156
|
+
// =============================================================================
|
|
157
|
+
/**
|
|
158
|
+
* TypeScript configuration for JSON Schema input.
|
|
159
|
+
*/
|
|
160
|
+
exports.zodJsonSchemaTypescriptConfig = zod_1.z.object({
|
|
161
|
+
$schema: zod_1.z.string().optional().describe(SCHEMA_DESCRIPTION),
|
|
162
|
+
inputType: zod_1.z.literal('jsonschema').describe(DOCUMENT_TYPE_DESCRIPTION),
|
|
163
|
+
inputPath: zod_1.z.string().describe(INPUT_PATH_DESCRIPTION),
|
|
164
|
+
auth: exports.zodInputAuth,
|
|
165
|
+
...zodTypeScriptConfigOptions,
|
|
166
|
+
generators: zod_1.z
|
|
167
|
+
.array(exports.zodJsonSchemaTypeScriptGenerators)
|
|
168
|
+
.describe(GENERATORS_DESCRIPTION),
|
|
169
|
+
telemetry: exports.zodProjectTelemetryConfig
|
|
170
|
+
});
|
|
171
|
+
// For now, only TypeScript is supported
|
|
172
|
+
exports.zodJsonSchemaCodegenConfiguration = exports.zodJsonSchemaTypescriptConfig;
|
|
173
|
+
exports.zodTheCodegenConfiguration = zod_1.z.discriminatedUnion('inputType', [
|
|
174
|
+
exports.zodAsyncAPICodegenConfiguration,
|
|
175
|
+
exports.zodOpenAPICodegenConfiguration,
|
|
176
|
+
exports.zodJsonSchemaCodegenConfiguration
|
|
177
|
+
]);
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ChannelInterface, OperationInterface, OperationReplyInterface } from '@asyncapi/parser';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/**
|
|
4
|
+
* Deep partial type that does NOT partial function arguments.
|
|
5
|
+
*/
|
|
6
|
+
export type DeepPartial<T> = T extends Function ? T : T extends object ? {
|
|
7
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
8
|
+
} : T;
|
|
9
|
+
/**
|
|
10
|
+
* Merge a non optional value with custom optional values to form a full value that has all properties sat.
|
|
11
|
+
*/
|
|
12
|
+
export declare function mergePartialAndDefault<T extends Record<string, any>>(defaultNonOptional: T, customOptional?: DeepPartial<T>): T;
|
|
13
|
+
/**
|
|
14
|
+
* Find duplicates in array of objects based on property
|
|
15
|
+
*/
|
|
16
|
+
export declare function findDuplicatesInArray(array: any[], property: string): any[];
|
|
17
|
+
/**
|
|
18
|
+
* Get OS type, abstracted away from special cases
|
|
19
|
+
*/
|
|
20
|
+
export declare function getOSType(): 'windows' | 'unix' | 'macos';
|
|
21
|
+
/**
|
|
22
|
+
* Windows renders relative paths weird i.e. '\' instead of '/'
|
|
23
|
+
*/
|
|
24
|
+
export declare function ensureRelativePath(pathToCheck: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Ensure array has unique values only.
|
|
27
|
+
*/
|
|
28
|
+
export declare function ensureUniqueValuesInArray(array: any[]): any[];
|
|
29
|
+
export declare function findExtensionObject(parsedObj: any): any;
|
|
30
|
+
export declare function findNameFromChannel(channel: ChannelInterface): string;
|
|
31
|
+
export declare function findOperationId(operation: OperationInterface, channel: ChannelInterface): any;
|
|
32
|
+
export declare function findNameFromOperation(operation: OperationInterface, channel: ChannelInterface): string;
|
|
33
|
+
export declare function firstLowercase(name: string): string;
|
|
34
|
+
export declare function findReplyId(operation: OperationInterface, reply: OperationReplyInterface, channel: ChannelInterface): string;
|
|
35
|
+
/**
|
|
36
|
+
* Extract JSDoc metadata from an AsyncAPI operation.
|
|
37
|
+
* Returns description and deprecated flag for use in generated JSDoc comments.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getOperationMetadata(operation: OperationInterface): {
|
|
40
|
+
description?: string;
|
|
41
|
+
deprecated?: boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare function onlyUnique(array: any[]): any[];
|
|
44
|
+
/**
|
|
45
|
+
* Shared Zod schema for import extension configuration.
|
|
46
|
+
* Used both globally (typescript.importExtension) and per-generator.
|
|
47
|
+
*
|
|
48
|
+
* - 'none': No extension (default, for bundlers and classic moduleResolution)
|
|
49
|
+
* - '.ts': Add .ts extension (for moduleResolution: "node16"/"nodenext" with allowImportingTsExtensions)
|
|
50
|
+
* - '.js': Add .js extension (for compiled ESM output)
|
|
51
|
+
*/
|
|
52
|
+
export declare const zodImportExtension: z.ZodOptional<z.ZodEnum<[".ts", ".js", "none"]>>;
|
|
53
|
+
/**
|
|
54
|
+
* Import extension type for TypeScript imports.
|
|
55
|
+
* - 'none': No extension added (default, for bundlers and classic moduleResolution)
|
|
56
|
+
* - '.ts': Add .ts extension (for moduleResolution: "node16" / "nodenext" with allowImportingTsExtensions)
|
|
57
|
+
* - '.js': Add .js extension (for compiled ESM output)
|
|
58
|
+
*/
|
|
59
|
+
export type ImportExtension = 'none' | '.ts' | '.js';
|
|
60
|
+
/**
|
|
61
|
+
* Appends file extension to import path based on configuration.
|
|
62
|
+
* Used to support modern TypeScript moduleResolution settings like "node16" or "nodenext"
|
|
63
|
+
* which require explicit file extensions in import statements.
|
|
64
|
+
*
|
|
65
|
+
* @param importPath - The relative import path (e.g., './payloads/User')
|
|
66
|
+
* @param extension - The extension to append ('none', '.ts', or '.js')
|
|
67
|
+
* @returns The import path with extension appended (or unchanged if 'none')
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* appendImportExtension('./payloads/User', '.ts') // => './payloads/User.ts'
|
|
71
|
+
* appendImportExtension('./payloads/User', 'none') // => './payloads/User'
|
|
72
|
+
*/
|
|
73
|
+
export declare function appendImportExtension(importPath: string, extension: ImportExtension): string;
|
|
74
|
+
/**
|
|
75
|
+
* Resolves the effective import extension from generator config or global config.
|
|
76
|
+
* Priority: generator.importExtension > config.importExtension > 'none'
|
|
77
|
+
*
|
|
78
|
+
* @param generator - Generator configuration that may have importExtension override
|
|
79
|
+
* @param config - Global configuration that may have importExtension (optional)
|
|
80
|
+
* @returns The resolved import extension ('none', '.ts', or '.js')
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Generator override takes precedence
|
|
84
|
+
* resolveImportExtension({importExtension: '.js'}, {importExtension: '.ts'})
|
|
85
|
+
* // => '.js'
|
|
86
|
+
*
|
|
87
|
+
* // Falls back to global config
|
|
88
|
+
* resolveImportExtension({}, {importExtension: '.ts'})
|
|
89
|
+
* // => '.ts'
|
|
90
|
+
*
|
|
91
|
+
* // Defaults to 'none' for backward compatibility
|
|
92
|
+
* resolveImportExtension({}, {})
|
|
93
|
+
* // => 'none'
|
|
94
|
+
*/
|
|
95
|
+
export declare function resolveImportExtension(generator: {
|
|
96
|
+
importExtension?: ImportExtension;
|
|
97
|
+
}, config?: {
|
|
98
|
+
importExtension?: ImportExtension;
|
|
99
|
+
}): ImportExtension;
|
|
100
|
+
/**
|
|
101
|
+
* Portable path join function that works in both Node.js and browser environments.
|
|
102
|
+
* Joins path segments with forward slashes and normalizes the result.
|
|
103
|
+
*
|
|
104
|
+
* @param segments - Path segments to join
|
|
105
|
+
* @returns Joined path with normalized slashes
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* joinPath('src/models', 'User.ts') // => 'src/models/User.ts'
|
|
109
|
+
* joinPath('src/models/', '/User.ts') // => 'src/models/User.ts'
|
|
110
|
+
* joinPath('./src', './models', 'User.ts') // => './src/models/User.ts'
|
|
111
|
+
*/
|
|
112
|
+
export declare function joinPath(...segments: string[]): string;
|
|
113
|
+
/**
|
|
114
|
+
* Portable relative path function that works in both Node.js and browser environments.
|
|
115
|
+
* Computes the relative path from one location to another.
|
|
116
|
+
*
|
|
117
|
+
* @param from - The starting directory path
|
|
118
|
+
* @param to - The target path
|
|
119
|
+
* @returns Relative path from 'from' to 'to'
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* relativePath('src/channels', 'src/models/User') // => '../models/User'
|
|
123
|
+
* relativePath('src/a/b', 'src/a/c') // => '../c'
|
|
124
|
+
* relativePath('src/models', 'src/models/User') // => 'User'
|
|
125
|
+
*/
|
|
126
|
+
export declare function relativePath(from: string, to: string): string;
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
|
|
3
|
+
/* eslint-disable security/detect-object-injection */
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.relativePath = exports.joinPath = exports.resolveImportExtension = exports.appendImportExtension = exports.zodImportExtension = exports.onlyUnique = exports.getOperationMetadata = exports.findReplyId = exports.firstLowercase = exports.findNameFromOperation = exports.findOperationId = exports.findNameFromChannel = exports.findExtensionObject = exports.ensureUniqueValuesInArray = exports.ensureRelativePath = exports.getOSType = exports.findDuplicatesInArray = exports.mergePartialAndDefault = void 0;
|
|
6
|
+
const process_1 = require("process");
|
|
7
|
+
const utils_1 = require("./generators/typescript/utils");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
/**
|
|
10
|
+
* Return true or false based on whether the input object is a regular object or a class
|
|
11
|
+
*
|
|
12
|
+
* Taken from: https://stackoverflow.com/a/43197340/6803886
|
|
13
|
+
* @param obj
|
|
14
|
+
*/
|
|
15
|
+
function isClass(obj) {
|
|
16
|
+
const isCtorClass = obj.constructor && obj.constructor.toString().substring(0, 5) === 'class';
|
|
17
|
+
if (obj.prototype === undefined) {
|
|
18
|
+
return isCtorClass;
|
|
19
|
+
}
|
|
20
|
+
const isPrototypeCtorClass = obj.prototype.constructor &&
|
|
21
|
+
obj.prototype.constructor.toString &&
|
|
22
|
+
obj.prototype.constructor.toString().substring(0, 5) === 'class';
|
|
23
|
+
return isCtorClass || isPrototypeCtorClass;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Merge a non optional value with custom optional values to form a full value that has all properties sat.
|
|
27
|
+
*/
|
|
28
|
+
function mergePartialAndDefault(defaultNonOptional, customOptional) {
|
|
29
|
+
if (customOptional === undefined) {
|
|
30
|
+
return Object.assign({}, defaultNonOptional);
|
|
31
|
+
}
|
|
32
|
+
// create a new object
|
|
33
|
+
const target = Object.assign({}, defaultNonOptional);
|
|
34
|
+
// deep merge the object into the target object
|
|
35
|
+
for (const [propName, prop] of Object.entries(customOptional)) {
|
|
36
|
+
const isObjectOrClass = typeof prop === 'object' && target[propName] !== undefined;
|
|
37
|
+
const isRegularObject = !isClass(prop);
|
|
38
|
+
const isArray = Array.isArray(prop);
|
|
39
|
+
if (isArray) {
|
|
40
|
+
// merge array into target with a new array instance so we dont touch the default value
|
|
41
|
+
target[propName] = ensureUniqueValuesInArray([
|
|
42
|
+
...(target[propName] ?? []),
|
|
43
|
+
...(prop ?? [])
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
else if (isObjectOrClass && isRegularObject) {
|
|
47
|
+
target[propName] = mergePartialAndDefault(target[propName], prop);
|
|
48
|
+
}
|
|
49
|
+
else if (prop) {
|
|
50
|
+
target[propName] = prop;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
exports.mergePartialAndDefault = mergePartialAndDefault;
|
|
56
|
+
/**
|
|
57
|
+
* Find duplicates in array of objects based on property
|
|
58
|
+
*/
|
|
59
|
+
function findDuplicatesInArray(array, property) {
|
|
60
|
+
const foundValues = array.map((generator) => {
|
|
61
|
+
return generator[property];
|
|
62
|
+
});
|
|
63
|
+
const duplicates = foundValues.filter((item, index) => foundValues.indexOf(item) !== index);
|
|
64
|
+
return Array.from(new Set(duplicates));
|
|
65
|
+
}
|
|
66
|
+
exports.findDuplicatesInArray = findDuplicatesInArray;
|
|
67
|
+
/**
|
|
68
|
+
* Get OS type, abstracted away from special cases
|
|
69
|
+
*/
|
|
70
|
+
function getOSType() {
|
|
71
|
+
if (process_1.platform === 'win32') {
|
|
72
|
+
return 'windows';
|
|
73
|
+
}
|
|
74
|
+
if (process_1.platform === 'darwin') {
|
|
75
|
+
return 'macos';
|
|
76
|
+
}
|
|
77
|
+
return 'unix';
|
|
78
|
+
}
|
|
79
|
+
exports.getOSType = getOSType;
|
|
80
|
+
/**
|
|
81
|
+
* Windows renders relative paths weird i.e. '\' instead of '/'
|
|
82
|
+
*/
|
|
83
|
+
function ensureRelativePath(pathToCheck) {
|
|
84
|
+
if (getOSType() === 'windows') {
|
|
85
|
+
return pathToCheck.replace(/\\/g, '/');
|
|
86
|
+
}
|
|
87
|
+
return pathToCheck;
|
|
88
|
+
}
|
|
89
|
+
exports.ensureRelativePath = ensureRelativePath;
|
|
90
|
+
/**
|
|
91
|
+
* Ensure array has unique values only.
|
|
92
|
+
*/
|
|
93
|
+
function ensureUniqueValuesInArray(array) {
|
|
94
|
+
return array.filter((value, index, filteredArray) => {
|
|
95
|
+
return filteredArray.indexOf(value) === index;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.ensureUniqueValuesInArray = ensureUniqueValuesInArray;
|
|
99
|
+
function findExtensionObject(parsedObj) {
|
|
100
|
+
return parsedObj?.extensions()?.get('x-the-codegen-project')?.value();
|
|
101
|
+
}
|
|
102
|
+
exports.findExtensionObject = findExtensionObject;
|
|
103
|
+
function findNameFromChannel(channel) {
|
|
104
|
+
const channelId = channel.id();
|
|
105
|
+
const userSpecificName = findExtensionObject(channel)
|
|
106
|
+
? findExtensionObject(channel)['channelName']
|
|
107
|
+
: undefined;
|
|
108
|
+
if (userSpecificName) {
|
|
109
|
+
return userSpecificName;
|
|
110
|
+
}
|
|
111
|
+
return (0, utils_1.pascalCase)(channelId.replace(/\W/g, ' '));
|
|
112
|
+
}
|
|
113
|
+
exports.findNameFromChannel = findNameFromChannel;
|
|
114
|
+
function findOperationId(operation, channel) {
|
|
115
|
+
const userSpecificName = findExtensionObject(operation)
|
|
116
|
+
? findExtensionObject(operation)['channelName']
|
|
117
|
+
: undefined;
|
|
118
|
+
if (userSpecificName) {
|
|
119
|
+
return userSpecificName;
|
|
120
|
+
}
|
|
121
|
+
let operationId = operation.id();
|
|
122
|
+
operationId = operation.hasOperationId()
|
|
123
|
+
? operation.operationId()
|
|
124
|
+
: operationId;
|
|
125
|
+
return operationId ?? channel.id();
|
|
126
|
+
}
|
|
127
|
+
exports.findOperationId = findOperationId;
|
|
128
|
+
function findNameFromOperation(operation, channel) {
|
|
129
|
+
const operationId = findOperationId(operation, channel);
|
|
130
|
+
return (0, utils_1.pascalCase)(operationId.replace(/\W/g, ' '));
|
|
131
|
+
}
|
|
132
|
+
exports.findNameFromOperation = findNameFromOperation;
|
|
133
|
+
function firstLowercase(name) {
|
|
134
|
+
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
135
|
+
}
|
|
136
|
+
exports.firstLowercase = firstLowercase;
|
|
137
|
+
function findReplyId(operation, reply, channel) {
|
|
138
|
+
return `${findOperationId(operation, reply.channel() ?? channel)}_reply`;
|
|
139
|
+
}
|
|
140
|
+
exports.findReplyId = findReplyId;
|
|
141
|
+
/**
|
|
142
|
+
* Extract JSDoc metadata from an AsyncAPI operation.
|
|
143
|
+
* Returns description and deprecated flag for use in generated JSDoc comments.
|
|
144
|
+
*/
|
|
145
|
+
function getOperationMetadata(operation) {
|
|
146
|
+
// Get description - prefer description() over summary()
|
|
147
|
+
let description;
|
|
148
|
+
if (operation.hasDescription()) {
|
|
149
|
+
description = operation.description();
|
|
150
|
+
}
|
|
151
|
+
else if (operation.hasSummary()) {
|
|
152
|
+
description = operation.summary();
|
|
153
|
+
}
|
|
154
|
+
// Check if operation is deprecated - access from raw JSON since no typed method exists
|
|
155
|
+
// The parser doesn't expose a deprecated() method, but the raw JSON contains it
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
|
+
const rawJson = operation.json?.() ?? operation._json;
|
|
158
|
+
const deprecated = rawJson?.deprecated === true;
|
|
159
|
+
return { description, deprecated };
|
|
160
|
+
}
|
|
161
|
+
exports.getOperationMetadata = getOperationMetadata;
|
|
162
|
+
function onlyUnique(array) {
|
|
163
|
+
const onlyUnique = (value, index, array) => {
|
|
164
|
+
return array.indexOf(value) === index;
|
|
165
|
+
};
|
|
166
|
+
return array.filter(onlyUnique);
|
|
167
|
+
}
|
|
168
|
+
exports.onlyUnique = onlyUnique;
|
|
169
|
+
/**
|
|
170
|
+
* Shared Zod schema for import extension configuration.
|
|
171
|
+
* Used both globally (typescript.importExtension) and per-generator.
|
|
172
|
+
*
|
|
173
|
+
* - 'none': No extension (default, for bundlers and classic moduleResolution)
|
|
174
|
+
* - '.ts': Add .ts extension (for moduleResolution: "node16"/"nodenext" with allowImportingTsExtensions)
|
|
175
|
+
* - '.js': Add .js extension (for compiled ESM output)
|
|
176
|
+
*/
|
|
177
|
+
exports.zodImportExtension = zod_1.z
|
|
178
|
+
.enum(['.ts', '.js', 'none'])
|
|
179
|
+
.optional()
|
|
180
|
+
.describe('File extension appended to relative import paths. Use ".ts" for moduleResolution: "node16"/"nodenext" with allowImportingTsExtensions, ".js" for compiled ESM output, or "none" (default) for bundlers and classic Node.js resolution. [Read more about import extensions here](https://the-codegen-project.org/docs/configurations)');
|
|
181
|
+
/**
|
|
182
|
+
* Appends file extension to import path based on configuration.
|
|
183
|
+
* Used to support modern TypeScript moduleResolution settings like "node16" or "nodenext"
|
|
184
|
+
* which require explicit file extensions in import statements.
|
|
185
|
+
*
|
|
186
|
+
* @param importPath - The relative import path (e.g., './payloads/User')
|
|
187
|
+
* @param extension - The extension to append ('none', '.ts', or '.js')
|
|
188
|
+
* @returns The import path with extension appended (or unchanged if 'none')
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* appendImportExtension('./payloads/User', '.ts') // => './payloads/User.ts'
|
|
192
|
+
* appendImportExtension('./payloads/User', 'none') // => './payloads/User'
|
|
193
|
+
*/
|
|
194
|
+
function appendImportExtension(importPath, extension) {
|
|
195
|
+
if (extension === 'none') {
|
|
196
|
+
return importPath;
|
|
197
|
+
}
|
|
198
|
+
return `${importPath}${extension}`;
|
|
199
|
+
}
|
|
200
|
+
exports.appendImportExtension = appendImportExtension;
|
|
201
|
+
/**
|
|
202
|
+
* Resolves the effective import extension from generator config or global config.
|
|
203
|
+
* Priority: generator.importExtension > config.importExtension > 'none'
|
|
204
|
+
*
|
|
205
|
+
* @param generator - Generator configuration that may have importExtension override
|
|
206
|
+
* @param config - Global configuration that may have importExtension (optional)
|
|
207
|
+
* @returns The resolved import extension ('none', '.ts', or '.js')
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* // Generator override takes precedence
|
|
211
|
+
* resolveImportExtension({importExtension: '.js'}, {importExtension: '.ts'})
|
|
212
|
+
* // => '.js'
|
|
213
|
+
*
|
|
214
|
+
* // Falls back to global config
|
|
215
|
+
* resolveImportExtension({}, {importExtension: '.ts'})
|
|
216
|
+
* // => '.ts'
|
|
217
|
+
*
|
|
218
|
+
* // Defaults to 'none' for backward compatibility
|
|
219
|
+
* resolveImportExtension({}, {})
|
|
220
|
+
* // => 'none'
|
|
221
|
+
*/
|
|
222
|
+
function resolveImportExtension(generator, config) {
|
|
223
|
+
return generator.importExtension ?? config?.importExtension ?? 'none';
|
|
224
|
+
}
|
|
225
|
+
exports.resolveImportExtension = resolveImportExtension;
|
|
226
|
+
/**
|
|
227
|
+
* Portable path join function that works in both Node.js and browser environments.
|
|
228
|
+
* Joins path segments with forward slashes and normalizes the result.
|
|
229
|
+
*
|
|
230
|
+
* @param segments - Path segments to join
|
|
231
|
+
* @returns Joined path with normalized slashes
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* joinPath('src/models', 'User.ts') // => 'src/models/User.ts'
|
|
235
|
+
* joinPath('src/models/', '/User.ts') // => 'src/models/User.ts'
|
|
236
|
+
* joinPath('./src', './models', 'User.ts') // => './src/models/User.ts'
|
|
237
|
+
*/
|
|
238
|
+
function joinPath(...segments) {
|
|
239
|
+
// Filter out empty segments
|
|
240
|
+
const filtered = segments.filter((s) => s !== '');
|
|
241
|
+
if (filtered.length === 0) {
|
|
242
|
+
return '';
|
|
243
|
+
}
|
|
244
|
+
// Join all segments, preserving leading ./ if present
|
|
245
|
+
const preserveLeadingDot = filtered[0].startsWith('./');
|
|
246
|
+
const preserveLeadingSlash = filtered[0].startsWith('/');
|
|
247
|
+
// Join and normalize
|
|
248
|
+
const joined = filtered
|
|
249
|
+
.map((segment, index) => {
|
|
250
|
+
// Remove leading slash from non-first segments
|
|
251
|
+
if (index > 0 && segment.startsWith('/')) {
|
|
252
|
+
segment = segment.slice(1);
|
|
253
|
+
}
|
|
254
|
+
// Remove leading ./ from non-first segments
|
|
255
|
+
if (index > 0 && segment.startsWith('./')) {
|
|
256
|
+
segment = segment.slice(2);
|
|
257
|
+
}
|
|
258
|
+
// Remove trailing slash from all but last segment
|
|
259
|
+
if (index < filtered.length - 1 && segment.endsWith('/')) {
|
|
260
|
+
segment = segment.slice(0, -1);
|
|
261
|
+
}
|
|
262
|
+
return segment;
|
|
263
|
+
})
|
|
264
|
+
.join('/');
|
|
265
|
+
// Normalize multiple slashes
|
|
266
|
+
let result = joined.replace(/\/+/g, '/');
|
|
267
|
+
// Restore leading pattern if needed
|
|
268
|
+
if (preserveLeadingDot && !result.startsWith('./')) {
|
|
269
|
+
result = `./${result}`;
|
|
270
|
+
}
|
|
271
|
+
else if (preserveLeadingSlash && !result.startsWith('/')) {
|
|
272
|
+
result = `/${result}`;
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
exports.joinPath = joinPath;
|
|
277
|
+
/**
|
|
278
|
+
* Checks if a path is absolute (starts with drive letter or /)
|
|
279
|
+
*/
|
|
280
|
+
function isAbsolutePath(p) {
|
|
281
|
+
// Windows drive letter (C:/) or Unix absolute (/)
|
|
282
|
+
return /^[a-zA-Z]:[\\/]/.test(p) || p.startsWith('/');
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Returns the current working directory in Node environments, or undefined
|
|
286
|
+
* in browser environments where no such concept exists.
|
|
287
|
+
*/
|
|
288
|
+
function getNodeCwd() {
|
|
289
|
+
// eslint-disable-next-line no-undef
|
|
290
|
+
const g = globalThis;
|
|
291
|
+
const proc = g.process;
|
|
292
|
+
if (proc && typeof proc.cwd === 'function') {
|
|
293
|
+
return proc.cwd().replace(/\\/g, '/');
|
|
294
|
+
}
|
|
295
|
+
return undefined;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Portable relative path function that works in both Node.js and browser environments.
|
|
299
|
+
* Computes the relative path from one location to another.
|
|
300
|
+
*
|
|
301
|
+
* @param from - The starting directory path
|
|
302
|
+
* @param to - The target path
|
|
303
|
+
* @returns Relative path from 'from' to 'to'
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* relativePath('src/channels', 'src/models/User') // => '../models/User'
|
|
307
|
+
* relativePath('src/a/b', 'src/a/c') // => '../c'
|
|
308
|
+
* relativePath('src/models', 'src/models/User') // => 'User'
|
|
309
|
+
*/
|
|
310
|
+
function relativePath(from, to) {
|
|
311
|
+
// Normalize Windows backslashes to forward slashes first
|
|
312
|
+
const normalizedFrom = from.replace(/\\/g, '/');
|
|
313
|
+
const normalizedTo = to.replace(/\\/g, '/');
|
|
314
|
+
const fromIsAbsolute = isAbsolutePath(normalizedFrom);
|
|
315
|
+
const toIsAbsolute = isAbsolutePath(normalizedTo);
|
|
316
|
+
// Handle mixed absolute/relative paths by resolving the relative one
|
|
317
|
+
// against the current working directory (Node). This mirrors
|
|
318
|
+
// `path.relative`, giving a deterministic result that doesn't depend on
|
|
319
|
+
// the depth of the absolute path from the filesystem root.
|
|
320
|
+
const cwd = getNodeCwd();
|
|
321
|
+
if (fromIsAbsolute !== toIsAbsolute && cwd !== undefined) {
|
|
322
|
+
const resolvedFrom = fromIsAbsolute
|
|
323
|
+
? normalizedFrom
|
|
324
|
+
: joinPath(cwd, normalizedFrom);
|
|
325
|
+
const resolvedTo = toIsAbsolute
|
|
326
|
+
? normalizedTo
|
|
327
|
+
: joinPath(cwd, normalizedTo);
|
|
328
|
+
return relativePath(resolvedFrom, resolvedTo);
|
|
329
|
+
}
|
|
330
|
+
// Fallback for browser: strip any absolute prefix so the two paths can be
|
|
331
|
+
// compared as relative paths (CWD-dependent, but browsers shouldn't see
|
|
332
|
+
// real absolute filesystem paths).
|
|
333
|
+
if (fromIsAbsolute && !toIsAbsolute) {
|
|
334
|
+
const fromWithoutRoot = normalizedFrom
|
|
335
|
+
.replace(/^[a-zA-Z]:\//, '')
|
|
336
|
+
.replace(/^\//, '');
|
|
337
|
+
return relativePath(fromWithoutRoot, normalizedTo);
|
|
338
|
+
}
|
|
339
|
+
if (!fromIsAbsolute && toIsAbsolute) {
|
|
340
|
+
const toWithoutRoot = normalizedTo
|
|
341
|
+
.replace(/^[a-zA-Z]:\//, '')
|
|
342
|
+
.replace(/^\//, '');
|
|
343
|
+
return relativePath(normalizedFrom, toWithoutRoot);
|
|
344
|
+
}
|
|
345
|
+
// Normalize paths: remove leading ./ and trailing /
|
|
346
|
+
const normFrom = normalizedFrom.replace(/^\.\//, '').replace(/\/$/, '');
|
|
347
|
+
const normTo = normalizedTo.replace(/^\.\//, '').replace(/\/$/, '');
|
|
348
|
+
const fromParts = normFrom.split('/').filter((p) => p !== '');
|
|
349
|
+
const toParts = normTo.split('/').filter((p) => p !== '');
|
|
350
|
+
// Find common prefix length
|
|
351
|
+
let commonLength = 0;
|
|
352
|
+
const minLength = Math.min(fromParts.length, toParts.length);
|
|
353
|
+
for (let i = 0; i < minLength; i++) {
|
|
354
|
+
if (fromParts[i] === toParts[i]) {
|
|
355
|
+
commonLength++;
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// Number of directories to go up from 'from'
|
|
362
|
+
const upCount = fromParts.length - commonLength;
|
|
363
|
+
// Remaining path in 'to' after common prefix
|
|
364
|
+
const remainingTo = toParts.slice(commonLength);
|
|
365
|
+
// Build relative path
|
|
366
|
+
const upParts = Array(upCount).fill('..');
|
|
367
|
+
const relativeParts = [...upParts, ...remainingTo];
|
|
368
|
+
if (relativeParts.length === 0) {
|
|
369
|
+
return '.';
|
|
370
|
+
}
|
|
371
|
+
return relativeParts.join('/');
|
|
372
|
+
}
|
|
373
|
+
exports.relativePath = relativePath;
|