@povio/openapi-codegen-cli 3.1.1 → 3.2.0-rc.10

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.
Files changed (69) hide show
  1. package/README.md +63 -15
  2. package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
  3. package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
  4. package/dist/acl.d.mts +6 -20
  5. package/dist/acl.mjs +8 -13
  6. package/dist/{auth.context-Bu5KW2sI.mjs → auth.context-COWO6ssl.mjs} +1 -21
  7. package/dist/auth.d.mts +2 -0
  8. package/dist/auth.mjs +3 -0
  9. package/dist/axios.d.mts +2 -0
  10. package/dist/axios.mjs +2 -0
  11. package/dist/{config-BU7wVf7U.d.mts → config-DgrOddSC.d.mts} +1 -2
  12. package/dist/config.d.mts +4 -0
  13. package/dist/config.mjs +5 -0
  14. package/dist/{error-handling-DSI86D3u.mjs → error-handling-BeydPL7s.mjs} +21 -51
  15. package/dist/{error-handling-D-mHJ60d.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
  16. package/dist/errors.d.mts +3 -0
  17. package/dist/errors.mjs +2 -0
  18. package/dist/generate.runner-CD7mlcJ4.mjs +184 -0
  19. package/dist/generate.utils-CT-LA-gX.cjs +2267 -0
  20. package/dist/generateCodeFromOpenAPIDoc-D9W5BtAt.mjs +2097 -0
  21. package/dist/{generateCodeFromOpenAPIDoc-DseBECa-.mjs → generateCodeFromOpenAPIDoc-DhI7CHeh.cjs} +1349 -2344
  22. package/dist/generator.d.mts +3 -10
  23. package/dist/generator.mjs +9 -9
  24. package/dist/getDataFromOpenAPIDoc-D8w0QElH.mjs +2011 -0
  25. package/dist/i18n-B_brQh4X.d.mts +38 -0
  26. package/dist/i18n-D-FesqFb.mjs +36 -0
  27. package/dist/index.d.mts +12 -200
  28. package/dist/index.mjs +12 -264
  29. package/dist/metro.cjs +114 -4959
  30. package/dist/metro.d.mts +3 -4
  31. package/dist/metro.mjs +4 -9
  32. package/dist/native-bindings-BTQGSGhU.mjs +1480 -0
  33. package/dist/native-rest-interceptor-CAWR8H5Y.mjs +208 -0
  34. package/dist/native-rest-interceptor-Cz6saoq5.d.mts +46 -0
  35. package/dist/native.d.mts +3 -0
  36. package/dist/native.mjs +3 -0
  37. package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
  38. package/dist/openapi-codegen-native-linux-x64.node +0 -0
  39. package/dist/openapi-codegen-native-win32-x64.node +0 -0
  40. package/dist/{openapi-codegen.runner-Co_bG00_.mjs → openapi-codegen.runner-C4TIXQNx.mjs} +4 -5
  41. package/dist/{openapi-source.runner-wLs5vqw6.mjs → openapi-source.runner-BZ6ZLgRO.mjs} +19 -10
  42. package/dist/{openapi-source.runner-BSIrB6ny.d.mts → openapi-source.runner-ykstqlPC.d.mts} +2 -8
  43. package/dist/{options-CE4Koxof.d.mts → options-KPf-Fti5.d.mts} +6 -1
  44. package/dist/query.d.mts +3 -0
  45. package/dist/query.mjs +3 -0
  46. package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
  47. package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
  48. package/dist/rest-client-CQyFvqYC.d.mts +55 -0
  49. package/dist/rest-interceptor-D5NCNTm1.mjs +115 -0
  50. package/dist/rest-transport.types-DM5-qyOJ.d.mts +66 -0
  51. package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
  52. package/dist/rest.d.mts +2 -0
  53. package/dist/rest.mjs +2 -0
  54. package/dist/rest.utils-rezWAIYL.d.mts +10 -0
  55. package/dist/router.context-EPlMBk3G.mjs +21 -0
  56. package/dist/sh.d.mts +1 -1
  57. package/dist/sh.mjs +41 -71
  58. package/dist/tiny.d.mts +1 -3
  59. package/dist/tiny.mjs +2 -3
  60. package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
  61. package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
  62. package/dist/vite.d.mts +3 -4
  63. package/dist/vite.mjs +6 -10
  64. package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
  65. package/dist/workspace.context-isVY9ves.d.mts +23 -0
  66. package/dist/zod.d.mts +2 -7
  67. package/dist/zod.mjs +2 -4
  68. package/package.json +73 -26
  69. package/dist/generate.runner-C1HrS_9G.mjs +0 -90
@@ -0,0 +1,184 @@
1
+ import { D as getTagFileName, Wn as Profiler, a as writeGenerateFileData, dt as DEFAULT_GENERATE_OPTIONS, i as removeStaleGeneratedFiles, n as shouldUseNativeCodegen, o as deepMerge, r as getOutputFileName, t as compileNativeData } from "./native-bindings-BTQGSGhU.mjs";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ //#region src/generators/core/resolveConfig.ts
5
+ function resolveConfig({ fileConfig = {}, params: { includeTags, excludeTags, inlineEndpointsExcludeModules, workspaceContext, ...options } }) {
6
+ const resolvedConfig = deepMerge(DEFAULT_GENERATE_OPTIONS, fileConfig ?? {}, {
7
+ ...options,
8
+ includeTags: includeTags?.split(","),
9
+ excludeTags: excludeTags?.split(","),
10
+ inlineEndpointsExcludeModules: inlineEndpointsExcludeModules?.split(","),
11
+ workspaceContext: workspaceContext?.split(",")
12
+ });
13
+ resolvedConfig.checkAcl = resolvedConfig.acl && resolvedConfig.checkAcl;
14
+ resolvedConfig.workspaceContext = Array.from(new Set((resolvedConfig.workspaceContext ?? []).map((value) => value.trim()).filter(Boolean)));
15
+ return resolvedConfig;
16
+ }
17
+ //#endregion
18
+ //#region src/native/generateFilesFromNativeOpenAPI.ts
19
+ function generateFilesFromNativeOpenAPI(source, yaml, options) {
20
+ if (!supportsCompleteNativeRender(options)) {
21
+ if (process.env.OPENAPI_CODEGEN_REQUIRE_FULL_NATIVE === "1") throw new Error("The selected options are not supported by the full native renderer");
22
+ return;
23
+ }
24
+ const nativeData = compileNativeData(source, yaml, JSON.stringify({
25
+ ...options,
26
+ nativeCompact: true
27
+ })).data;
28
+ if (!nativeData.renderedComplete) {
29
+ if (process.env.OPENAPI_CODEGEN_REQUIRE_FULL_NATIVE === "1") throw new Error("The selected options are not supported by the full native renderer");
30
+ return;
31
+ }
32
+ const files = [];
33
+ const taggedRenderers = options.modelsOnly ? [["models", nativeData.renderedModels]] : [
34
+ ["models", nativeData.renderedModels],
35
+ ["endpoints", nativeData.renderedEndpoints],
36
+ ["queries", nativeData.renderedQueries],
37
+ ...options.acl ? [["acl", nativeData.renderedAcl]] : []
38
+ ];
39
+ for (const tag of nativeData.renderedTags) for (const [type, rendered] of taggedRenderers) {
40
+ const content = rendered[tag];
41
+ if (content) files.push(taggedFile(options, tag, type, content));
42
+ }
43
+ if (!options.modelsOnly) {
44
+ if (options.acl && nativeData.renderedShared.appAcl) files.push(outputFile(options, "acl/app.ability.ts", nativeData.renderedShared.appAcl));
45
+ if (options.mutationEffects && nativeData.renderedShared.queryModules) files.push(outputFile(options, "queryModules.ts", nativeData.renderedShared.queryModules));
46
+ if (!options.restClientImportPath) files.push(outputFile(options, "app-rest-client.ts", `import { ${options.restClient === "native" ? "NativeRestClient" : "RestClient"} } from "@povio/openapi-codegen-cli${options.restClient === "native" ? "/native" : ""}";\n\nexport const AppRestClient = new ${options.restClient === "native" ? "NativeRestClient" : "RestClient"}({\n config: {\n baseURL: "${nativeData.baseUrl}"\n },\n});\n`));
47
+ if (nativeData.renderedShared.domainErrors) files.push(outputFile(options, "domain-errors.ts", nativeData.renderedShared.domainErrors));
48
+ }
49
+ return files;
50
+ }
51
+ function supportsCompleteNativeRender(options) {
52
+ return options.splitByTags && (options.modelsInCommon && options.tsNamespaces || !options.modelsInCommon && !options.tsNamespaces) && !options.inlineEndpoints && !options.builderConfigs && (options.workspaceContext?.length ?? 0) === 0;
53
+ }
54
+ function taggedFile(options, tag, type, content) {
55
+ return outputFile(options, getTagFileName({
56
+ tag,
57
+ type,
58
+ options
59
+ }), content);
60
+ }
61
+ function outputFile(options, fileName, content) {
62
+ return {
63
+ fileName: getOutputFileName({
64
+ output: options.output,
65
+ fileName
66
+ }),
67
+ content
68
+ };
69
+ }
70
+ //#endregion
71
+ //#region src/generators/run/generate.runner.ts
72
+ async function runGenerate({ fileConfig, params, formatGeneratedFile, profiler = new Profiler(process.env.OPENAPI_CODEGEN_PROFILE === "1") }) {
73
+ const config = profiler.runSync("config.resolve", () => resolveConfig({
74
+ fileConfig,
75
+ params: params ?? {}
76
+ }));
77
+ const useNative = shouldUseNativeCodegen();
78
+ const isJson = path.extname(new URL(config.input, "file://").pathname).toLowerCase() === ".json";
79
+ const useRawNativeInput = useNative && (isJson || typeof Bun === "undefined");
80
+ let nativeInput = useRawNativeInput ? await getRawOpenApiSource(config.input, profiler) : await getOpenApiSource(config.input, profiler);
81
+ if (useNative && !useRawNativeInput) {
82
+ const document = "document" in nativeInput ? nativeInput.document : void 0;
83
+ nativeInput = {
84
+ ...nativeInput,
85
+ source: profiler.runSync("openapi.serialize", () => JSON.stringify(document)),
86
+ yaml: false
87
+ };
88
+ }
89
+ const openApiDoc = "document" in nativeInput ? nativeInput.document : {};
90
+ const outputExists = fs.existsSync(config.output);
91
+ const filesData = await profiler.runAsync("generate.total", async () => {
92
+ if (useNative) {
93
+ const nativeFiles = generateFilesFromNativeOpenAPI(nativeInput.source, nativeInput.yaml, config);
94
+ if (nativeFiles) return nativeFiles;
95
+ }
96
+ const { generateCodeFromOpenAPIDoc } = await import("./generateCodeFromOpenAPIDoc-D9W5BtAt.mjs").then((n) => n.n);
97
+ return generateCodeFromOpenAPIDoc(openApiDoc, config, profiler, {
98
+ source: nativeInput.source,
99
+ yaml: nativeInput.yaml
100
+ });
101
+ });
102
+ if (config.clearOutput) profiler.runSync("files.removeStaleGenerated", () => {
103
+ removeStaleGeneratedFiles({
104
+ output: config.output,
105
+ filesData,
106
+ options: config
107
+ });
108
+ });
109
+ await profiler.runAsync("files.write", async () => {
110
+ await writeGenerateFileData(filesData, {
111
+ formatGeneratedFile,
112
+ skipExistingCheck: !outputExists
113
+ });
114
+ });
115
+ return {
116
+ skipped: false,
117
+ config,
118
+ stats: getGenerateStats(filesData, config)
119
+ };
120
+ }
121
+ async function getOpenApiDoc(input, profiler = new Profiler(false)) {
122
+ return (await getOpenApiSource(input, profiler)).document;
123
+ }
124
+ async function getOpenApiSource(input, profiler = new Profiler(false)) {
125
+ const raw = await getRawOpenApiSource(input, profiler);
126
+ const { source } = raw;
127
+ const document = await profiler.runAsync("openapi.parse", () => parseOpenApiSource(input, source));
128
+ return {
129
+ ...raw,
130
+ document
131
+ };
132
+ }
133
+ async function getRawOpenApiSource(input, profiler = new Profiler(false)) {
134
+ return {
135
+ source: await profiler.runAsync("openapi.read", () => readOpenApiSource(input)),
136
+ yaml: path.extname(new URL(input, "file://").pathname).toLowerCase() !== ".json"
137
+ };
138
+ }
139
+ async function readOpenApiSource(input) {
140
+ if (/^https?:\/\//i.test(input)) {
141
+ const response = await fetch(input);
142
+ if (!response.ok) throw new Error(`Unable to load OpenAPI document: ${response.status} ${response.statusText}`);
143
+ return response.text();
144
+ }
145
+ return fs.promises.readFile(input, "utf-8");
146
+ }
147
+ async function parseOpenApiSource(input, source) {
148
+ try {
149
+ return JSON.parse(source.charCodeAt(0) === 65279 ? source.slice(1) : source);
150
+ } catch (error) {
151
+ if (path.extname(new URL(input, "file://").pathname).toLowerCase() === ".json") throw error;
152
+ if (typeof Bun !== "undefined") return Bun.YAML.parse(source);
153
+ const { parse } = await import("yaml");
154
+ return parse(source);
155
+ }
156
+ }
157
+ function getGenerateStats(filesData, config) {
158
+ const generatedFilesCount = filesData.length;
159
+ if (generatedFilesCount === 0) return {
160
+ generatedFilesCount,
161
+ generatedModulesCount: 0
162
+ };
163
+ if (!config.splitByTags) return {
164
+ generatedFilesCount,
165
+ generatedModulesCount: 1
166
+ };
167
+ const moduleSuffixes = new Set(Object.values(config.configs).map((generateConfig) => generateConfig.outputFileNameSuffix).filter(Boolean));
168
+ const modules = /* @__PURE__ */ new Set();
169
+ for (const file of filesData) {
170
+ const segments = path.relative(config.output, file.fileName).split(path.sep).filter(Boolean);
171
+ if (segments.length < 2) continue;
172
+ const moduleName = segments[0];
173
+ const fileName = segments[segments.length - 1];
174
+ if (!fileName.startsWith(`${moduleName}.`)) continue;
175
+ const suffix = fileName.slice(moduleName.length + 1).replace(/\.tsx?$/, "");
176
+ if (moduleSuffixes.has(suffix)) modules.add(moduleName);
177
+ }
178
+ return {
179
+ generatedFilesCount,
180
+ generatedModulesCount: modules.size
181
+ };
182
+ }
183
+ //#endregion
184
+ export { runGenerate as n, resolveConfig as r, getOpenApiDoc as t };