swagger-typescript-api 13.1.0 → 13.1.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # swagger-typescript-api
2
2
 
3
+ ## 13.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1198](https://github.com/acacode/swagger-typescript-api/pull/1198) [`1cb1c9c`](https://github.com/acacode/swagger-typescript-api/commit/1cb1c9c0d39dacefb89a6b44eaf2a6266334f3c6) Thanks [@smorimoto](https://github.com/smorimoto)! - Integrate `generateCommand` arguments and run method into main command.
8
+
9
+ ## 13.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1163](https://github.com/acacode/swagger-typescript-api/pull/1163) [`e477b58`](https://github.com/acacode/swagger-typescript-api/commit/e477b5850504b3f4829b2749d1dbc5d310e9bca1) Thanks [@RoXuS](https://github.com/RoXuS)! - Ensure enums are at the top of the components to avoid issue on recursive schema parsing.
14
+
3
15
  ## 13.1.0
4
16
 
5
17
  ### Minor Changes
@@ -10,6 +22,8 @@
10
22
 
11
23
  - [#1171](https://github.com/acacode/swagger-typescript-api/pull/1171) [`c1cc45a`](https://github.com/acacode/swagger-typescript-api/commit/c1cc45a6f27698f2b21cc35696cf529b0e9a210d) Thanks [@smorimoto](https://github.com/smorimoto)! - Fix TypeScript declaration file path.
12
24
 
25
+ - [#1149](https://github.com/acacode/swagger-typescript-api/pull/1149) [`9d2d66a`](https://github.com/acacode/swagger-typescript-api/commit/9d2d66ab52a7eaba70b51cf2d52e6528f7f69ff5) Thanks [@smorimoto](https://github.com/smorimoto)! - Re-add TypeScript definitions for better type support.
26
+
13
27
  - [#1145](https://github.com/acacode/swagger-typescript-api/pull/1145) [`73f6bfd`](https://github.com/acacode/swagger-typescript-api/commit/73f6bfddb501211a30f9dca0e1098f905761badb) Thanks [@smorimoto](https://github.com/smorimoto)! - Replace Prettier with Biome as the code formatter to improve performance during the code generation phase.
14
28
 
15
29
  - [#1141](https://github.com/acacode/swagger-typescript-api/pull/1141) [`821bfad`](https://github.com/acacode/swagger-typescript-api/commit/821bfad0dc8dffc7a8571a052b38f96c3d1c8087) Thanks [@dding-g](https://github.com/dding-g)! - Remove redundant `union-enums` option in favor of `generate-union-enums`.
@@ -0,0 +1,11 @@
1
+ //#region rolldown:runtime
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all) __defProp(target, name, {
5
+ get: all[name],
6
+ enumerable: true
7
+ });
8
+ };
9
+
10
+ //#endregion
11
+ export { __export };
package/dist/cli.cjs CHANGED
@@ -1,3 +1,328 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';var chunkNO753Z7P_cjs=require('./chunk-NO753Z7P.cjs'),s=require('path'),c12=require('c12'),citty=require('citty');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var s__namespace=/*#__PURE__*/_interopNamespace(s);var o=new chunkNO753Z7P_cjs.e({}),f=citty.defineCommand({meta:{name:"generate-templates",description:'Generate ".ejs" templates needed for generate api'},args:{"clean-output":{type:"boolean",description:"clean output folder before generate template. WARNING: May cause data loss",default:o.cleanOutput},debug:{type:"boolean",description:"additional information about processes inside this tool",default:o.debug},"http-client":{type:"string",description:`http client type (possible values: ${Object.values(chunkNO753Z7P_cjs.b)})`,default:o.httpClientType},modular:{type:"boolean",description:"generate templates needed to separate files for http client, data contracts, and routes",default:o.modular},output:{type:"string",alias:"o",description:"output path of generated templates",default:o.output,required:true},rewrite:{type:"boolean",alias:"r",description:"rewrite content in existing templates",default:o.rewrite},silent:{type:"boolean",description:"Output only errors to console",default:o.silent}},run:async({args:e})=>{await chunkNO753Z7P_cjs.f({cleanOutput:e["clean-output"],httpClientType:e["http-client"],modular:e.modular,output:e.output,rewrite:e.rewrite,silent:e.silent,debug:e.debug});}}),t=new chunkNO753Z7P_cjs.d({}),y=citty.defineCommand({meta:{name:"generate",description:chunkNO753Z7P_cjs.a.description},args:{"add-readonly":{type:"boolean",description:"generate readonly properties",default:t.addReadonly},"another-array-type":{type:"boolean",description:"generate array types as Array<Type> (by default Type[])",default:t.anotherArrayType},"api-class-name":{type:"string",description:"name of the api class",default:t.apiClassName},axios:{type:"boolean",description:"generate axios http client",default:false},"clean-output":{type:"boolean",description:"clean output folder before generate api. WARNING: May cause data loss",default:t.cleanOutput},client:{type:"boolean",description:"do not generate an API class",default:t.generateClient},"custom-config":{type:"string",description:"custom config: primitiveTypeConstructs, hooks, ... "},debug:{type:"boolean",description:"additional information about processes inside this tool",default:t.debug},"default-as-success":{type:"boolean",alias:"d",description:'use "default" response status code as success response too. some swagger schemas use "default" response status code as success response type by default.',default:t.defaultResponseAsSuccess},"default-response":{type:"string",description:"default type for empty response schema",default:t.defaultResponseType},"disable-throw-on-error":{type:"boolean",description:"Do not throw an error when response.ok is not true",default:t.disableThrowOnError},"enum-names-as-values":{type:"boolean",description:"use values in 'x-enumNames' as enum values (not only as keys)",default:t.enumNamesAsValues},"extract-enums":{type:"boolean",description:"extract all enums from inline interface/type content to typescript enum construction",default:t.extractEnums},"extract-request-body":{type:"boolean",description:"extract request body type to data contract",default:t.extractRequestBody},"extract-request-params":{type:"boolean",description:"extract request params to data contract (Also combine path params and query params into one object)",default:t.extractRequestParams},"extract-response-body":{type:"boolean",description:"extract response body type to data contract",default:t.extractResponseBody},"extract-response-error":{type:"boolean",description:"extract response error type to data contract",default:t.extractResponseError},"extract-responses":{type:"boolean",description:"extract all responses described in /components/responses",default:t.extractResponses},"generate-union-enums":{type:"boolean",description:'generate all "enum" types as union types (T1 | T2 | TN)',default:t.generateUnionEnums},"http-client":{type:"string",description:`http client type (possible values: ${Object.values(chunkNO753Z7P_cjs.b)})`},js:{type:"boolean",description:"generate js api module with declaration file",default:t.toJS},modular:{type:"boolean",description:"generate separated files for http client, data contracts, and routes",default:t.modular},"module-name-first-tag":{type:"boolean",description:"splits routes based on the first tag",default:t.moduleNameFirstTag},"module-name-index":{type:"string",description:"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",default:t.moduleNameIndex.toString()},name:{type:"string",alias:"n",description:"name of output typescript api file",default:t.fileName},output:{type:"string",alias:"o",description:"output path of typescript api file",default:"./"},patch:{type:"boolean",description:"fix up small errors in the swagger source definition",default:t.patch},path:{type:"string",alias:"p",description:"path/url to swagger scheme",required:true},responses:{type:"boolean",alias:"r",description:"generate additional information about request responses also add typings for bad responses",default:t.generateResponses},"route-types":{type:"boolean",description:"generate type definitions for API routes",default:t.generateRouteTypes},silent:{type:"boolean",description:"Output only errors to console",default:t.silent},"single-http-client":{type:"boolean",description:"Ability to send HttpClient instance to Api constructor",default:t.singleHttpClient},"sort-routes":{type:"boolean",description:"sort routes in alphabetical order",default:t.sortRoutes},"sort-types":{type:"boolean",description:"sort fields and types",default:t.sortTypes},templates:{type:"string",alias:"t",description:"path to folder containing templates"},"type-prefix":{type:"string",description:"data contract name prefix",default:t.typePrefix},"type-suffix":{type:"string",description:"data contract name suffix",default:t.typeSuffix},"unwrap-response-data":{type:"boolean",description:"unwrap the data item from the response",default:t.unwrapResponseData}},run:async({args:e})=>{let d=await c12.loadConfig({configFile:e["custom-config"]});await chunkNO753Z7P_cjs.g({addReadonly:e["add-readonly"],anotherArrayType:e["another-array-type"],apiClassName:e["api-class-name"],cleanOutput:e["clean-output"],debug:e.debug,defaultResponseAsSuccess:e["default-as-success"],defaultResponseType:e["default-response"],disableThrowOnError:e["disable-throw-on-error"],enumNamesAsValues:e["enum-names-as-values"],extractEnums:e["extract-enums"],extractRequestBody:e["extract-request-body"],extractRequestParams:e["extract-request-params"],extractResponseBody:e["extract-response-body"],extractResponseError:e["extract-response-error"],extractResponses:e["extract-responses"],fileName:e.name,generateClient:e.client,generateResponses:e.responses,generateRouteTypes:e["route-types"],generateUnionEnums:e["generate-union-enums"],httpClientType:e["http-client"]||e.axios?chunkNO753Z7P_cjs.b.AXIOS:chunkNO753Z7P_cjs.b.FETCH,input:s__namespace.resolve(process.cwd(),e.path),modular:e.modular,moduleNameFirstTag:e["module-name-first-tag"],moduleNameIndex:+e["module-name-index"]||0,output:s__namespace.resolve(process.cwd(),e.output||"."),patch:e.patch,silent:e.silent,singleHttpClient:e["single-http-client"],sortRoutes:e["sort-routes"],sortTypes:e["sort-types"],templates:e.templates,toJS:e.js,typePrefix:e["type-prefix"],typeSuffix:e["type-suffix"],unwrapResponseData:e["unwrap-response-data"],url:e.path,...d.config});}}),b=citty.defineCommand({meta:{name:chunkNO753Z7P_cjs.a.name,description:chunkNO753Z7P_cjs.a.description,version:chunkNO753Z7P_cjs.a.version},subCommands:{generate:y,"generate-templates":f}});citty.runMain(b);//# sourceMappingURL=cli.cjs.map
2
+ "use strict";
3
+ const require_src = require('./src-D3nQpZ1i.cjs');
4
+ const node_path = require_src.__toESM(require("node:path"));
5
+ const c12 = require_src.__toESM(require("c12"));
6
+ const citty = require_src.__toESM(require("citty"));
7
+
8
+ //#region index.ts
9
+ const templateGenBaseConfig = new require_src.TemplatesGenConfig({});
10
+ const generateTemplatesCommand = (0, citty.defineCommand)({
11
+ meta: {
12
+ name: "generate-templates",
13
+ description: "Generate \".ejs\" templates needed for generate api"
14
+ },
15
+ args: {
16
+ "clean-output": {
17
+ type: "boolean",
18
+ description: "clean output folder before generate template. WARNING: May cause data loss",
19
+ default: templateGenBaseConfig.cleanOutput
20
+ },
21
+ debug: {
22
+ type: "boolean",
23
+ description: "additional information about processes inside this tool",
24
+ default: templateGenBaseConfig.debug
25
+ },
26
+ "http-client": {
27
+ type: "string",
28
+ description: `http client type (possible values: ${Object.values(require_src.HTTP_CLIENT)})`,
29
+ default: templateGenBaseConfig.httpClientType
30
+ },
31
+ modular: {
32
+ type: "boolean",
33
+ description: "generate templates needed to separate files for http client, data contracts, and routes",
34
+ default: templateGenBaseConfig.modular
35
+ },
36
+ output: {
37
+ type: "string",
38
+ alias: "o",
39
+ description: "output path of generated templates",
40
+ default: templateGenBaseConfig.output,
41
+ required: true
42
+ },
43
+ rewrite: {
44
+ type: "boolean",
45
+ alias: "r",
46
+ description: "rewrite content in existing templates",
47
+ default: templateGenBaseConfig.rewrite
48
+ },
49
+ silent: {
50
+ type: "boolean",
51
+ description: "Output only errors to console",
52
+ default: templateGenBaseConfig.silent
53
+ }
54
+ },
55
+ run: async ({ args }) => {
56
+ await require_src.generateTemplates({
57
+ cleanOutput: args["clean-output"],
58
+ httpClientType: args["http-client"],
59
+ modular: args.modular,
60
+ output: args.output,
61
+ rewrite: args.rewrite,
62
+ silent: args.silent,
63
+ debug: args.debug
64
+ });
65
+ }
66
+ });
67
+ const codeGenBaseConfig = new require_src.CodeGenConfig({});
68
+ const generateCommand = (0, citty.defineCommand)({
69
+ meta: {
70
+ name: "generate",
71
+ description: require_src.package_default.description
72
+ },
73
+ args: {
74
+ "add-readonly": {
75
+ type: "boolean",
76
+ description: "generate readonly properties",
77
+ default: codeGenBaseConfig.addReadonly
78
+ },
79
+ "another-array-type": {
80
+ type: "boolean",
81
+ description: "generate array types as Array<Type> (by default Type[])",
82
+ default: codeGenBaseConfig.anotherArrayType
83
+ },
84
+ "api-class-name": {
85
+ type: "string",
86
+ description: "name of the api class",
87
+ default: codeGenBaseConfig.apiClassName
88
+ },
89
+ axios: {
90
+ type: "boolean",
91
+ description: "generate axios http client",
92
+ default: false
93
+ },
94
+ "clean-output": {
95
+ type: "boolean",
96
+ description: "clean output folder before generate api. WARNING: May cause data loss",
97
+ default: codeGenBaseConfig.cleanOutput
98
+ },
99
+ client: {
100
+ type: "boolean",
101
+ description: "do not generate an API class",
102
+ default: codeGenBaseConfig.generateClient
103
+ },
104
+ "custom-config": {
105
+ type: "string",
106
+ description: "custom config: primitiveTypeConstructs, hooks, ... "
107
+ },
108
+ debug: {
109
+ type: "boolean",
110
+ description: "additional information about processes inside this tool",
111
+ default: codeGenBaseConfig.debug
112
+ },
113
+ "default-as-success": {
114
+ type: "boolean",
115
+ alias: "d",
116
+ description: "use \"default\" response status code as success response too. some swagger schemas use \"default\" response status code as success response type by default.",
117
+ default: codeGenBaseConfig.defaultResponseAsSuccess
118
+ },
119
+ "default-response": {
120
+ type: "string",
121
+ description: "default type for empty response schema",
122
+ default: codeGenBaseConfig.defaultResponseType
123
+ },
124
+ "disable-throw-on-error": {
125
+ type: "boolean",
126
+ description: "Do not throw an error when response.ok is not true",
127
+ default: codeGenBaseConfig.disableThrowOnError
128
+ },
129
+ "enum-names-as-values": {
130
+ type: "boolean",
131
+ description: "use values in 'x-enumNames' as enum values (not only as keys)",
132
+ default: codeGenBaseConfig.enumNamesAsValues
133
+ },
134
+ "extract-enums": {
135
+ type: "boolean",
136
+ description: "extract all enums from inline interface/type content to typescript enum construction",
137
+ default: codeGenBaseConfig.extractEnums
138
+ },
139
+ "extract-request-body": {
140
+ type: "boolean",
141
+ description: "extract request body type to data contract",
142
+ default: codeGenBaseConfig.extractRequestBody
143
+ },
144
+ "extract-request-params": {
145
+ type: "boolean",
146
+ description: "extract request params to data contract (Also combine path params and query params into one object)",
147
+ default: codeGenBaseConfig.extractRequestParams
148
+ },
149
+ "extract-response-body": {
150
+ type: "boolean",
151
+ description: "extract response body type to data contract",
152
+ default: codeGenBaseConfig.extractResponseBody
153
+ },
154
+ "extract-response-error": {
155
+ type: "boolean",
156
+ description: "extract response error type to data contract",
157
+ default: codeGenBaseConfig.extractResponseError
158
+ },
159
+ "extract-responses": {
160
+ type: "boolean",
161
+ description: "extract all responses described in /components/responses",
162
+ default: codeGenBaseConfig.extractResponses
163
+ },
164
+ "generate-union-enums": {
165
+ type: "boolean",
166
+ description: "generate all \"enum\" types as union types (T1 | T2 | TN)",
167
+ default: codeGenBaseConfig.generateUnionEnums
168
+ },
169
+ "http-client": {
170
+ type: "string",
171
+ description: `http client type (possible values: ${Object.values(require_src.HTTP_CLIENT)})`
172
+ },
173
+ js: {
174
+ type: "boolean",
175
+ description: "generate js api module with declaration file",
176
+ default: codeGenBaseConfig.toJS
177
+ },
178
+ modular: {
179
+ type: "boolean",
180
+ description: "generate separated files for http client, data contracts, and routes",
181
+ default: codeGenBaseConfig.modular
182
+ },
183
+ "module-name-first-tag": {
184
+ type: "boolean",
185
+ description: "splits routes based on the first tag",
186
+ default: codeGenBaseConfig.moduleNameFirstTag
187
+ },
188
+ "module-name-index": {
189
+ type: "string",
190
+ description: "determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",
191
+ default: codeGenBaseConfig.moduleNameIndex.toString()
192
+ },
193
+ name: {
194
+ type: "string",
195
+ alias: "n",
196
+ description: "name of output typescript api file",
197
+ default: codeGenBaseConfig.fileName
198
+ },
199
+ output: {
200
+ type: "string",
201
+ alias: "o",
202
+ description: "output path of typescript api file",
203
+ default: "./"
204
+ },
205
+ patch: {
206
+ type: "boolean",
207
+ description: "fix up small errors in the swagger source definition",
208
+ default: codeGenBaseConfig.patch
209
+ },
210
+ path: {
211
+ type: "string",
212
+ alias: "p",
213
+ description: "path/url to swagger scheme",
214
+ required: true
215
+ },
216
+ responses: {
217
+ type: "boolean",
218
+ alias: "r",
219
+ description: "generate additional information about request responses also add typings for bad responses",
220
+ default: codeGenBaseConfig.generateResponses
221
+ },
222
+ "route-types": {
223
+ type: "boolean",
224
+ description: "generate type definitions for API routes",
225
+ default: codeGenBaseConfig.generateRouteTypes
226
+ },
227
+ silent: {
228
+ type: "boolean",
229
+ description: "Output only errors to console",
230
+ default: codeGenBaseConfig.silent
231
+ },
232
+ "single-http-client": {
233
+ type: "boolean",
234
+ description: "Ability to send HttpClient instance to Api constructor",
235
+ default: codeGenBaseConfig.singleHttpClient
236
+ },
237
+ "sort-routes": {
238
+ type: "boolean",
239
+ description: "sort routes in alphabetical order",
240
+ default: codeGenBaseConfig.sortRoutes
241
+ },
242
+ "sort-types": {
243
+ type: "boolean",
244
+ description: "sort fields and types",
245
+ default: codeGenBaseConfig.sortTypes
246
+ },
247
+ templates: {
248
+ type: "string",
249
+ alias: "t",
250
+ description: "path to folder containing templates"
251
+ },
252
+ "type-prefix": {
253
+ type: "string",
254
+ description: "data contract name prefix",
255
+ default: codeGenBaseConfig.typePrefix
256
+ },
257
+ "type-suffix": {
258
+ type: "string",
259
+ description: "data contract name suffix",
260
+ default: codeGenBaseConfig.typeSuffix
261
+ },
262
+ "unwrap-response-data": {
263
+ type: "boolean",
264
+ description: "unwrap the data item from the response",
265
+ default: codeGenBaseConfig.unwrapResponseData
266
+ }
267
+ },
268
+ run: async ({ args }) => {
269
+ const customConfig = await (0, c12.loadConfig)({ configFile: args["custom-config"] });
270
+ await require_src.generateApi({
271
+ addReadonly: args["add-readonly"],
272
+ anotherArrayType: args["another-array-type"],
273
+ apiClassName: args["api-class-name"],
274
+ cleanOutput: args["clean-output"],
275
+ debug: args.debug,
276
+ defaultResponseAsSuccess: args["default-as-success"],
277
+ defaultResponseType: args["default-response"],
278
+ disableThrowOnError: args["disable-throw-on-error"],
279
+ enumNamesAsValues: args["enum-names-as-values"],
280
+ extractEnums: args["extract-enums"],
281
+ extractRequestBody: args["extract-request-body"],
282
+ extractRequestParams: args["extract-request-params"],
283
+ extractResponseBody: args["extract-response-body"],
284
+ extractResponseError: args["extract-response-error"],
285
+ extractResponses: args["extract-responses"],
286
+ fileName: args.name,
287
+ generateClient: args.client,
288
+ generateResponses: args.responses,
289
+ generateRouteTypes: args["route-types"],
290
+ generateUnionEnums: args["generate-union-enums"],
291
+ httpClientType: args["http-client"] || args.axios ? require_src.HTTP_CLIENT.AXIOS : require_src.HTTP_CLIENT.FETCH,
292
+ input: node_path.resolve(process.cwd(), args.path),
293
+ modular: args.modular,
294
+ moduleNameFirstTag: args["module-name-first-tag"],
295
+ moduleNameIndex: +args["module-name-index"] || 0,
296
+ output: node_path.resolve(process.cwd(), args.output || "."),
297
+ patch: args.patch,
298
+ silent: args.silent,
299
+ singleHttpClient: args["single-http-client"],
300
+ sortRoutes: args["sort-routes"],
301
+ sortTypes: args["sort-types"],
302
+ templates: args.templates,
303
+ toJS: args.js,
304
+ typePrefix: args["type-prefix"],
305
+ typeSuffix: args["type-suffix"],
306
+ unwrapResponseData: args["unwrap-response-data"],
307
+ url: args.path,
308
+ ...customConfig.config
309
+ });
310
+ }
311
+ });
312
+ const main = (0, citty.defineCommand)({
313
+ meta: {
314
+ name: require_src.package_default.name,
315
+ description: require_src.package_default.description,
316
+ version: require_src.package_default.version
317
+ },
318
+ args: generateCommand.args,
319
+ run: generateCommand.run,
320
+ subCommands: {
321
+ generate: generateCommand,
322
+ "generate-templates": generateTemplatesCommand
323
+ }
324
+ });
325
+ (0, citty.runMain)(main);
326
+
327
+ //#endregion
3
328
  //# sourceMappingURL=cli.cjs.map
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"names":["templateGenBaseConfig","TemplatesGenConfig","generateTemplatesCommand","defineCommand","HTTP_CLIENT","args","generateTemplates","codeGenBaseConfig","CodeGenConfig","generateCommand","package_default","customConfig","loadConfig","generateApi","s","main","runMain"],"mappings":";qeAYA,IAAMA,EAAwB,IAAIC,mBAAAA,CAAmB,EAAE,CAAA,CAEjDC,EAA2BC,mBAAc,CAAA,CAC7C,KAAM,CACJ,IAAA,CAAM,qBACN,WAAa,CAAA,mDACf,EACA,IAAM,CAAA,CACJ,eAAgB,CACd,IAAA,CAAM,UACN,WACE,CAAA,4EAAA,CACF,QAASH,CAAsB,CAAA,WACjC,EACA,KAAO,CAAA,CACL,KAAM,SACN,CAAA,WAAA,CAAa,0DACb,OAASA,CAAAA,CAAAA,CAAsB,KACjC,CACA,CAAA,aAAA,CAAe,CACb,IAAM,CAAA,QAAA,CACN,YAAa,CAAsC,mCAAA,EAAA,MAAA,CAAO,OACxDI,mBACF,CAAC,IACD,OAASJ,CAAAA,CAAAA,CAAsB,cACjC,CACA,CAAA,OAAA,CAAS,CACP,IAA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AA,SAAA,CAAWA,EAAK,SAChB,CAAA,IAAA,CAAMA,EAAK,EACX,CAAA,UAAA,CAAYA,EAAK,aAAa,CAAA,CAC9B,WAAYA,CAAK,CAAA,aAAa,EAC9B,kBAAoBA,CAAAA,CAAAA,CAAK,sBAAsB,CAC/C,CAAA,GAAA,CAAKA,EAAK,IACV,CAAA,GAAGM,EAAa,MAClB,CAAC,EACH,CACF,CAAC,EAEKI,CAAOZ,CAAAA,mBAAAA,CAAc,CACzB,IAAM,CAAA,CACJ,KAAMO,mBAAY,CAAA,IAAA,CAClB,YAAaA,mBAAY,CAAA,WAAA,CACzB,QAASA,mBAAY,CAAA,OACvB,EACA,WAAa,CAAA,CACX,SAAUD,CACV,CAAA,oBAAA,CAAsBP,CACxB,CACF,CAAC,CAEDc,CAAAA,aAAAA,CAAQD,CAAI,CAAA","file":"cli.cjs","sourcesContent":["#!/usr/bin/env node\n\nimport * as path from \"node:path\";\nimport { loadConfig } from \"c12\";\nimport { defineCommand, runMain } from \"citty\";\nimport packageJson from \"./package.json\" with { type: \"json\" };\nimport { TemplatesGenConfig } from \"./src/commands/generate-templates/configuration.js\";\nimport { CodeGenConfig } from \"./src/configuration.js\";\nimport { HTTP_CLIENT } from \"./src/constants.js\";\nimport { generateApi, generateTemplates } from \"./src/index.js\";\nimport type { GenerateApiParams, HttpClientType } from \"./types/index.js\";\n\nconst templateGenBaseConfig = new TemplatesGenConfig({});\n\nconst generateTemplatesCommand = defineCommand({\n meta: {\n name: \"generate-templates\",\n description: 'Generate \".ejs\" templates needed for generate api',\n },\n args: {\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate template. WARNING: May cause data loss\",\n default: templateGenBaseConfig.cleanOutput,\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: templateGenBaseConfig.debug,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n default: templateGenBaseConfig.httpClientType,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate templates needed to separate files for http client, data contracts, and routes\",\n default: templateGenBaseConfig.modular,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of generated templates\",\n default: templateGenBaseConfig.output,\n required: true,\n },\n rewrite: {\n type: \"boolean\",\n alias: \"r\",\n description: \"rewrite content in existing templates\",\n default: templateGenBaseConfig.rewrite,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: templateGenBaseConfig.silent,\n },\n },\n run: async ({ args }) => {\n await generateTemplates({\n cleanOutput: args[\"clean-output\"],\n httpClientType: args[\"http-client\"] as HttpClientType,\n modular: args.modular,\n output: args.output,\n rewrite: args.rewrite,\n silent: args.silent,\n debug: args.debug,\n });\n },\n});\n\nconst codeGenBaseConfig = new CodeGenConfig({});\n\nconst generateCommand = defineCommand({\n meta: {\n name: \"generate\",\n description: packageJson.description,\n },\n args: {\n \"add-readonly\": {\n type: \"boolean\",\n description: \"generate readonly properties\",\n default: codeGenBaseConfig.addReadonly,\n },\n \"another-array-type\": {\n type: \"boolean\",\n description: \"generate array types as Array<Type> (by default Type[])\",\n default: codeGenBaseConfig.anotherArrayType,\n },\n \"api-class-name\": {\n type: \"string\",\n description: \"name of the api class\",\n default: codeGenBaseConfig.apiClassName,\n },\n axios: {\n type: \"boolean\",\n description: \"generate axios http client\",\n default: false,\n },\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate api. WARNING: May cause data loss\",\n default: codeGenBaseConfig.cleanOutput,\n },\n client: {\n type: \"boolean\",\n description: \"do not generate an API class\",\n default: codeGenBaseConfig.generateClient,\n },\n \"custom-config\": {\n type: \"string\",\n description: \"custom config: primitiveTypeConstructs, hooks, ... \",\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: codeGenBaseConfig.debug,\n },\n \"default-as-success\": {\n type: \"boolean\",\n alias: \"d\",\n description:\n 'use \"default\" response status code as success response too. some swagger schemas use \"default\" response status code as success response type by default.',\n default: codeGenBaseConfig.defaultResponseAsSuccess,\n },\n \"default-response\": {\n type: \"string\",\n description: \"default type for empty response schema\",\n default: codeGenBaseConfig.defaultResponseType,\n },\n \"disable-throw-on-error\": {\n type: \"boolean\",\n description: \"Do not throw an error when response.ok is not true\",\n default: codeGenBaseConfig.disableThrowOnError,\n },\n \"enum-names-as-values\": {\n type: \"boolean\",\n description:\n \"use values in 'x-enumNames' as enum values (not only as keys)\",\n default: codeGenBaseConfig.enumNamesAsValues,\n },\n \"extract-enums\": {\n type: \"boolean\",\n description:\n \"extract all enums from inline interface/type content to typescript enum construction\",\n default: codeGenBaseConfig.extractEnums,\n },\n \"extract-request-body\": {\n type: \"boolean\",\n description: \"extract request body type to data contract\",\n default: codeGenBaseConfig.extractRequestBody,\n },\n \"extract-request-params\": {\n type: \"boolean\",\n description:\n \"extract request params to data contract (Also combine path params and query params into one object)\",\n default: codeGenBaseConfig.extractRequestParams,\n },\n \"extract-response-body\": {\n type: \"boolean\",\n description: \"extract response body type to data contract\",\n default: codeGenBaseConfig.extractResponseBody,\n },\n \"extract-response-error\": {\n type: \"boolean\",\n description: \"extract response error type to data contract\",\n default: codeGenBaseConfig.extractResponseError,\n },\n \"extract-responses\": {\n type: \"boolean\",\n description: \"extract all responses described in /components/responses\",\n default: codeGenBaseConfig.extractResponses,\n },\n \"generate-union-enums\": {\n type: \"boolean\",\n description: 'generate all \"enum\" types as union types (T1 | T2 | TN)',\n default: codeGenBaseConfig.generateUnionEnums,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n },\n js: {\n type: \"boolean\",\n description: \"generate js api module with declaration file\",\n default: codeGenBaseConfig.toJS,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate separated files for http client, data contracts, and routes\",\n default: codeGenBaseConfig.modular,\n },\n \"module-name-first-tag\": {\n type: \"boolean\",\n description: \"splits routes based on the first tag\",\n default: codeGenBaseConfig.moduleNameFirstTag,\n },\n \"module-name-index\": {\n type: \"string\",\n description:\n \"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)\",\n default: codeGenBaseConfig.moduleNameIndex.toString(),\n },\n name: {\n type: \"string\",\n alias: \"n\",\n description: \"name of output typescript api file\",\n default: codeGenBaseConfig.fileName,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of typescript api file\",\n default: \"./\",\n },\n patch: {\n type: \"boolean\",\n description: \"fix up small errors in the swagger source definition\",\n default: codeGenBaseConfig.patch,\n },\n path: {\n type: \"string\",\n alias: \"p\",\n description: \"path/url to swagger scheme\",\n required: true,\n },\n responses: {\n type: \"boolean\",\n alias: \"r\",\n description:\n \"generate additional information about request responses also add typings for bad responses\",\n default: codeGenBaseConfig.generateResponses,\n },\n \"route-types\": {\n type: \"boolean\",\n description: \"generate type definitions for API routes\",\n default: codeGenBaseConfig.generateRouteTypes,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: codeGenBaseConfig.silent,\n },\n \"single-http-client\": {\n type: \"boolean\",\n description: \"Ability to send HttpClient instance to Api constructor\",\n default: codeGenBaseConfig.singleHttpClient,\n },\n \"sort-routes\": {\n type: \"boolean\",\n description: \"sort routes in alphabetical order\",\n default: codeGenBaseConfig.sortRoutes,\n },\n \"sort-types\": {\n type: \"boolean\",\n description: \"sort fields and types\",\n default: codeGenBaseConfig.sortTypes,\n },\n templates: {\n type: \"string\",\n alias: \"t\",\n description: \"path to folder containing templates\",\n },\n \"type-prefix\": {\n type: \"string\",\n description: \"data contract name prefix\",\n default: codeGenBaseConfig.typePrefix,\n },\n \"type-suffix\": {\n type: \"string\",\n description: \"data contract name suffix\",\n default: codeGenBaseConfig.typeSuffix,\n },\n \"unwrap-response-data\": {\n type: \"boolean\",\n description: \"unwrap the data item from the response\",\n default: codeGenBaseConfig.unwrapResponseData,\n },\n },\n run: async ({ args }) => {\n const customConfig = await loadConfig<GenerateApiParams>({\n configFile: args[\"custom-config\"],\n });\n\n await generateApi({\n addReadonly: args[\"add-readonly\"],\n anotherArrayType: args[\"another-array-type\"],\n apiClassName: args[\"api-class-name\"],\n cleanOutput: args[\"clean-output\"],\n debug: args.debug,\n defaultResponseAsSuccess: args[\"default-as-success\"],\n defaultResponseType: args[\"default-response\"],\n disableThrowOnError: args[\"disable-throw-on-error\"],\n enumNamesAsValues: args[\"enum-names-as-values\"],\n extractEnums: args[\"extract-enums\"],\n extractRequestBody: args[\"extract-request-body\"],\n extractRequestParams: args[\"extract-request-params\"],\n extractResponseBody: args[\"extract-response-body\"],\n extractResponseError: args[\"extract-response-error\"],\n extractResponses: args[\"extract-responses\"],\n fileName: args.name,\n generateClient: args.client,\n generateResponses: args.responses,\n generateRouteTypes: args[\"route-types\"],\n generateUnionEnums: args[\"generate-union-enums\"],\n httpClientType:\n args[\"http-client\"] || args.axios\n ? HTTP_CLIENT.AXIOS\n : HTTP_CLIENT.FETCH,\n input: path.resolve(process.cwd(), args.path as string),\n modular: args.modular,\n moduleNameFirstTag: args[\"module-name-first-tag\"],\n moduleNameIndex: +args[\"module-name-index\"] || 0,\n output: path.resolve(process.cwd(), (args.output as string) || \".\"),\n patch: args.patch,\n silent: args.silent,\n singleHttpClient: args[\"single-http-client\"],\n sortRoutes: args[\"sort-routes\"],\n sortTypes: args[\"sort-types\"],\n templates: args.templates,\n toJS: args.js,\n typePrefix: args[\"type-prefix\"],\n typeSuffix: args[\"type-suffix\"],\n unwrapResponseData: args[\"unwrap-response-data\"],\n url: args.path,\n ...customConfig.config,\n });\n },\n});\n\nconst main = defineCommand({\n meta: {\n name: packageJson.name,\n description: packageJson.description,\n version: packageJson.version,\n },\n subCommands: {\n generate: generateCommand,\n \"generate-templates\": generateTemplatesCommand,\n },\n});\n\nrunMain(main);\n"]}
1
+ {"version":3,"file":"cli.cjs","names":[],"sources":["../index.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport * as path from \"node:path\";\nimport { loadConfig } from \"c12\";\nimport { defineCommand, runMain } from \"citty\";\nimport packageJson from \"./package.json\" with { type: \"json\" };\nimport { TemplatesGenConfig } from \"./src/commands/generate-templates/configuration.js\";\nimport { CodeGenConfig } from \"./src/configuration.js\";\nimport { HTTP_CLIENT } from \"./src/constants.js\";\nimport { generateApi, generateTemplates } from \"./src/index.js\";\nimport type { GenerateApiParams, HttpClientType } from \"./types/index.js\";\n\nconst templateGenBaseConfig = new TemplatesGenConfig({});\n\nconst generateTemplatesCommand = defineCommand({\n meta: {\n name: \"generate-templates\",\n description: 'Generate \".ejs\" templates needed for generate api',\n },\n args: {\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate template. WARNING: May cause data loss\",\n default: templateGenBaseConfig.cleanOutput,\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: templateGenBaseConfig.debug,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n default: templateGenBaseConfig.httpClientType,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate templates needed to separate files for http client, data contracts, and routes\",\n default: templateGenBaseConfig.modular,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of generated templates\",\n default: templateGenBaseConfig.output,\n required: true,\n },\n rewrite: {\n type: \"boolean\",\n alias: \"r\",\n description: \"rewrite content in existing templates\",\n default: templateGenBaseConfig.rewrite,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: templateGenBaseConfig.silent,\n },\n },\n run: async ({ args }) => {\n await generateTemplates({\n cleanOutput: args[\"clean-output\"],\n httpClientType: args[\"http-client\"] as HttpClientType,\n modular: args.modular,\n output: args.output,\n rewrite: args.rewrite,\n silent: args.silent,\n debug: args.debug,\n });\n },\n});\n\nconst codeGenBaseConfig = new CodeGenConfig({});\n\nconst generateCommand = defineCommand({\n meta: {\n name: \"generate\",\n description: packageJson.description,\n },\n args: {\n \"add-readonly\": {\n type: \"boolean\",\n description: \"generate readonly properties\",\n default: codeGenBaseConfig.addReadonly,\n },\n \"another-array-type\": {\n type: \"boolean\",\n description: \"generate array types as Array<Type> (by default Type[])\",\n default: codeGenBaseConfig.anotherArrayType,\n },\n \"api-class-name\": {\n type: \"string\",\n description: \"name of the api class\",\n default: codeGenBaseConfig.apiClassName,\n },\n axios: {\n type: \"boolean\",\n description: \"generate axios http client\",\n default: false,\n },\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate api. WARNING: May cause data loss\",\n default: codeGenBaseConfig.cleanOutput,\n },\n client: {\n type: \"boolean\",\n description: \"do not generate an API class\",\n default: codeGenBaseConfig.generateClient,\n },\n \"custom-config\": {\n type: \"string\",\n description: \"custom config: primitiveTypeConstructs, hooks, ... \",\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: codeGenBaseConfig.debug,\n },\n \"default-as-success\": {\n type: \"boolean\",\n alias: \"d\",\n description:\n 'use \"default\" response status code as success response too. some swagger schemas use \"default\" response status code as success response type by default.',\n default: codeGenBaseConfig.defaultResponseAsSuccess,\n },\n \"default-response\": {\n type: \"string\",\n description: \"default type for empty response schema\",\n default: codeGenBaseConfig.defaultResponseType,\n },\n \"disable-throw-on-error\": {\n type: \"boolean\",\n description: \"Do not throw an error when response.ok is not true\",\n default: codeGenBaseConfig.disableThrowOnError,\n },\n \"enum-names-as-values\": {\n type: \"boolean\",\n description:\n \"use values in 'x-enumNames' as enum values (not only as keys)\",\n default: codeGenBaseConfig.enumNamesAsValues,\n },\n \"extract-enums\": {\n type: \"boolean\",\n description:\n \"extract all enums from inline interface/type content to typescript enum construction\",\n default: codeGenBaseConfig.extractEnums,\n },\n \"extract-request-body\": {\n type: \"boolean\",\n description: \"extract request body type to data contract\",\n default: codeGenBaseConfig.extractRequestBody,\n },\n \"extract-request-params\": {\n type: \"boolean\",\n description:\n \"extract request params to data contract (Also combine path params and query params into one object)\",\n default: codeGenBaseConfig.extractRequestParams,\n },\n \"extract-response-body\": {\n type: \"boolean\",\n description: \"extract response body type to data contract\",\n default: codeGenBaseConfig.extractResponseBody,\n },\n \"extract-response-error\": {\n type: \"boolean\",\n description: \"extract response error type to data contract\",\n default: codeGenBaseConfig.extractResponseError,\n },\n \"extract-responses\": {\n type: \"boolean\",\n description: \"extract all responses described in /components/responses\",\n default: codeGenBaseConfig.extractResponses,\n },\n \"generate-union-enums\": {\n type: \"boolean\",\n description: 'generate all \"enum\" types as union types (T1 | T2 | TN)',\n default: codeGenBaseConfig.generateUnionEnums,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n },\n js: {\n type: \"boolean\",\n description: \"generate js api module with declaration file\",\n default: codeGenBaseConfig.toJS,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate separated files for http client, data contracts, and routes\",\n default: codeGenBaseConfig.modular,\n },\n \"module-name-first-tag\": {\n type: \"boolean\",\n description: \"splits routes based on the first tag\",\n default: codeGenBaseConfig.moduleNameFirstTag,\n },\n \"module-name-index\": {\n type: \"string\",\n description:\n \"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)\",\n default: codeGenBaseConfig.moduleNameIndex.toString(),\n },\n name: {\n type: \"string\",\n alias: \"n\",\n description: \"name of output typescript api file\",\n default: codeGenBaseConfig.fileName,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of typescript api file\",\n default: \"./\",\n },\n patch: {\n type: \"boolean\",\n description: \"fix up small errors in the swagger source definition\",\n default: codeGenBaseConfig.patch,\n },\n path: {\n type: \"string\",\n alias: \"p\",\n description: \"path/url to swagger scheme\",\n required: true,\n },\n responses: {\n type: \"boolean\",\n alias: \"r\",\n description:\n \"generate additional information about request responses also add typings for bad responses\",\n default: codeGenBaseConfig.generateResponses,\n },\n \"route-types\": {\n type: \"boolean\",\n description: \"generate type definitions for API routes\",\n default: codeGenBaseConfig.generateRouteTypes,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: codeGenBaseConfig.silent,\n },\n \"single-http-client\": {\n type: \"boolean\",\n description: \"Ability to send HttpClient instance to Api constructor\",\n default: codeGenBaseConfig.singleHttpClient,\n },\n \"sort-routes\": {\n type: \"boolean\",\n description: \"sort routes in alphabetical order\",\n default: codeGenBaseConfig.sortRoutes,\n },\n \"sort-types\": {\n type: \"boolean\",\n description: \"sort fields and types\",\n default: codeGenBaseConfig.sortTypes,\n },\n templates: {\n type: \"string\",\n alias: \"t\",\n description: \"path to folder containing templates\",\n },\n \"type-prefix\": {\n type: \"string\",\n description: \"data contract name prefix\",\n default: codeGenBaseConfig.typePrefix,\n },\n \"type-suffix\": {\n type: \"string\",\n description: \"data contract name suffix\",\n default: codeGenBaseConfig.typeSuffix,\n },\n \"unwrap-response-data\": {\n type: \"boolean\",\n description: \"unwrap the data item from the response\",\n default: codeGenBaseConfig.unwrapResponseData,\n },\n },\n run: async ({ args }) => {\n const customConfig = await loadConfig<GenerateApiParams>({\n configFile: args[\"custom-config\"],\n });\n\n await generateApi({\n addReadonly: args[\"add-readonly\"],\n anotherArrayType: args[\"another-array-type\"],\n apiClassName: args[\"api-class-name\"],\n cleanOutput: args[\"clean-output\"],\n debug: args.debug,\n defaultResponseAsSuccess: args[\"default-as-success\"],\n defaultResponseType: args[\"default-response\"],\n disableThrowOnError: args[\"disable-throw-on-error\"],\n enumNamesAsValues: args[\"enum-names-as-values\"],\n extractEnums: args[\"extract-enums\"],\n extractRequestBody: args[\"extract-request-body\"],\n extractRequestParams: args[\"extract-request-params\"],\n extractResponseBody: args[\"extract-response-body\"],\n extractResponseError: args[\"extract-response-error\"],\n extractResponses: args[\"extract-responses\"],\n fileName: args.name,\n generateClient: args.client,\n generateResponses: args.responses,\n generateRouteTypes: args[\"route-types\"],\n generateUnionEnums: args[\"generate-union-enums\"],\n httpClientType:\n args[\"http-client\"] || args.axios\n ? HTTP_CLIENT.AXIOS\n : HTTP_CLIENT.FETCH,\n input: path.resolve(process.cwd(), args.path as string),\n modular: args.modular,\n moduleNameFirstTag: args[\"module-name-first-tag\"],\n moduleNameIndex: +args[\"module-name-index\"] || 0,\n output: path.resolve(process.cwd(), (args.output as string) || \".\"),\n patch: args.patch,\n silent: args.silent,\n singleHttpClient: args[\"single-http-client\"],\n sortRoutes: args[\"sort-routes\"],\n sortTypes: args[\"sort-types\"],\n templates: args.templates,\n toJS: args.js,\n typePrefix: args[\"type-prefix\"],\n typeSuffix: args[\"type-suffix\"],\n unwrapResponseData: args[\"unwrap-response-data\"],\n url: args.path,\n ...customConfig.config,\n });\n },\n});\n\nconst main = defineCommand({\n meta: {\n name: packageJson.name,\n description: packageJson.description,\n version: packageJson.version,\n },\n args: generateCommand.args,\n run: generateCommand.run,\n subCommands: {\n generate: generateCommand,\n \"generate-templates\": generateTemplatesCommand,\n },\n});\n\nrunMain(main);\n"],"mappings":";;;;;;;;AAYA,MAAM,wBAAwB,IAAI,+BAAmB,CAAE;AAEvD,MAAM,2BAA2B,yBAAc;CAC7C,MAAM;EACJ,MAAM;EACN,aAAa;CACd;CACD,MAAM;EACJ,gBAAgB;GACd,MAAM;GACN,aACE;GACF,SAAS,sBAAsB;EAChC;EACD,OAAO;GACL,MAAM;GACN,aAAa;GACb,SAAS,sBAAsB;EAChC;EACD,eAAe;GACb,MAAM;GACN,cAAc,qCAAqC,OAAO,OACxD,wBACD,CAAC;GACF,SAAS,sBAAsB;EAChC;EACD,SAAS;GACP,MAAM;GACN,aACE;GACF,SAAS,sBAAsB;EAChC;EACD,QAAQ;GACN,MAAM;GACN,OAAO;GACP,aAAa;GACb,SAAS,sBAAsB;GAC/B,UAAU;EACX;EACD,SAAS;GACP,MAAM;GACN,OAAO;GACP,aAAa;GACb,SAAS,sBAAsB;EAChC;EACD,QAAQ;GACN,MAAM;GACN,aAAa;GACb,SAAS,sBAAsB;EAChC;CACF;CACD,KAAK,OAAO,EAAE,MAAM,KAAK;AACvB,QAAM,8BAAkB;GACtB,aAAa,KAAK;GAClB,gBAAgB,KAAK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