@dune2/cli 1.1.5 → 1.2.0
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/dist/cli.mjs +5 -5
- package/dist/cli.mjs.map +1 -1
- package/dist/{config-CxSOgXuG.mjs → config-9MrZts4R.mjs} +2 -2
- package/dist/config-9MrZts4R.mjs.map +1 -0
- package/dist/{generateApi-CxXqgeuk.mjs → generateApi-Dd7TJHu0.mjs} +93 -20
- package/dist/generateApi-Dd7TJHu0.mjs.map +1 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{initConfig-Cu0d5qZ8.mjs → initConfig-D8kYF-u1.mjs} +2 -2
- package/dist/initConfig-D8kYF-u1.mjs.map +1 -0
- package/dist/{interactive-CG86IvnG.mjs → interactive-FF1hLdGL.mjs} +9 -9
- package/dist/interactive-FF1hLdGL.mjs.map +1 -0
- package/dist/normalizeConfig.d.mts +1 -1
- package/dist/normalizeConfig.mjs +25 -2
- package/dist/normalizeConfig.mjs.map +1 -0
- package/dist/types-BRp2czbi.d.mts +389 -0
- package/package.json +19 -23
- package/readme.md +1 -1
- package/dist/config-CxSOgXuG.mjs.map +0 -1
- package/dist/generateApi-CxXqgeuk.mjs.map +0 -1
- package/dist/initConfig-Cu0d5qZ8.mjs.map +0 -1
- package/dist/interactive-CG86IvnG.mjs.map +0 -1
- package/dist/normalizeConfig-Dx193DW8.mjs +0 -26
- package/dist/normalizeConfig-Dx193DW8.mjs.map +0 -1
- package/dist/prettier.cjs +0 -9954
- package/dist/prettier.cjs.map +0 -1
- package/dist/prettier.d.cts +0 -14
- package/dist/prettier.d.mts +0 -14
- package/dist/prettier.mjs +0 -9952
- package/dist/prettier.mjs.map +0 -1
- package/dist/types-lEW0KXAS.d.mts +0 -70
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
2
|
+
|
|
3
|
+
//#region ../../node_modules/.pnpm/openapi-types@12.1.3/node_modules/openapi-types/dist/index.d.ts
|
|
4
|
+
declare namespace OpenAPIV3 {
|
|
5
|
+
interface Document<T extends {} = {}> {
|
|
6
|
+
openapi: string;
|
|
7
|
+
info: InfoObject;
|
|
8
|
+
servers?: ServerObject[];
|
|
9
|
+
paths: PathsObject<T>;
|
|
10
|
+
components?: ComponentsObject;
|
|
11
|
+
security?: SecurityRequirementObject[];
|
|
12
|
+
tags?: TagObject[];
|
|
13
|
+
externalDocs?: ExternalDocumentationObject;
|
|
14
|
+
'x-express-openapi-additional-middleware'?: (((request: any, response: any, next: any) => Promise<void>) | ((request: any, response: any, next: any) => void))[];
|
|
15
|
+
'x-express-openapi-validation-strict'?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface InfoObject {
|
|
18
|
+
title: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
termsOfService?: string;
|
|
21
|
+
contact?: ContactObject;
|
|
22
|
+
license?: LicenseObject;
|
|
23
|
+
version: string;
|
|
24
|
+
}
|
|
25
|
+
interface ContactObject {
|
|
26
|
+
name?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
email?: string;
|
|
29
|
+
}
|
|
30
|
+
interface LicenseObject {
|
|
31
|
+
name: string;
|
|
32
|
+
url?: string;
|
|
33
|
+
}
|
|
34
|
+
interface ServerObject {
|
|
35
|
+
url: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
variables?: {
|
|
38
|
+
[variable: string]: ServerVariableObject;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
interface ServerVariableObject {
|
|
42
|
+
enum?: string[];
|
|
43
|
+
default: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
}
|
|
46
|
+
interface PathsObject<T extends {} = {}, P extends {} = {}> {
|
|
47
|
+
[pattern: string]: (PathItemObject<T> & P) | undefined;
|
|
48
|
+
}
|
|
49
|
+
enum HttpMethods {
|
|
50
|
+
GET = "get",
|
|
51
|
+
PUT = "put",
|
|
52
|
+
POST = "post",
|
|
53
|
+
DELETE = "delete",
|
|
54
|
+
OPTIONS = "options",
|
|
55
|
+
HEAD = "head",
|
|
56
|
+
PATCH = "patch",
|
|
57
|
+
TRACE = "trace"
|
|
58
|
+
}
|
|
59
|
+
type PathItemObject<T extends {} = {}> = {
|
|
60
|
+
$ref?: string;
|
|
61
|
+
summary?: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
servers?: ServerObject[];
|
|
64
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
65
|
+
} & { [method in HttpMethods]?: OperationObject<T> };
|
|
66
|
+
type OperationObject<T extends {} = {}> = {
|
|
67
|
+
tags?: string[];
|
|
68
|
+
summary?: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
externalDocs?: ExternalDocumentationObject;
|
|
71
|
+
operationId?: string;
|
|
72
|
+
parameters?: (ReferenceObject | ParameterObject)[];
|
|
73
|
+
requestBody?: ReferenceObject | RequestBodyObject;
|
|
74
|
+
responses: ResponsesObject;
|
|
75
|
+
callbacks?: {
|
|
76
|
+
[callback: string]: ReferenceObject | CallbackObject;
|
|
77
|
+
};
|
|
78
|
+
deprecated?: boolean;
|
|
79
|
+
security?: SecurityRequirementObject[];
|
|
80
|
+
servers?: ServerObject[];
|
|
81
|
+
} & T;
|
|
82
|
+
interface ExternalDocumentationObject {
|
|
83
|
+
description?: string;
|
|
84
|
+
url: string;
|
|
85
|
+
}
|
|
86
|
+
interface ParameterObject extends ParameterBaseObject {
|
|
87
|
+
name: string;
|
|
88
|
+
in: string;
|
|
89
|
+
}
|
|
90
|
+
interface HeaderObject extends ParameterBaseObject {}
|
|
91
|
+
interface ParameterBaseObject {
|
|
92
|
+
description?: string;
|
|
93
|
+
required?: boolean;
|
|
94
|
+
deprecated?: boolean;
|
|
95
|
+
allowEmptyValue?: boolean;
|
|
96
|
+
style?: string;
|
|
97
|
+
explode?: boolean;
|
|
98
|
+
allowReserved?: boolean;
|
|
99
|
+
schema?: ReferenceObject | SchemaObject;
|
|
100
|
+
example?: any;
|
|
101
|
+
examples?: {
|
|
102
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
103
|
+
};
|
|
104
|
+
content?: {
|
|
105
|
+
[media: string]: MediaTypeObject;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
type NonArraySchemaObjectType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
|
|
109
|
+
type ArraySchemaObjectType = 'array';
|
|
110
|
+
type SchemaObject = ArraySchemaObject | NonArraySchemaObject;
|
|
111
|
+
interface ArraySchemaObject extends BaseSchemaObject {
|
|
112
|
+
type: ArraySchemaObjectType;
|
|
113
|
+
items: ReferenceObject | SchemaObject;
|
|
114
|
+
}
|
|
115
|
+
interface NonArraySchemaObject extends BaseSchemaObject {
|
|
116
|
+
type?: NonArraySchemaObjectType;
|
|
117
|
+
}
|
|
118
|
+
interface BaseSchemaObject {
|
|
119
|
+
title?: string;
|
|
120
|
+
description?: string;
|
|
121
|
+
format?: string;
|
|
122
|
+
default?: any;
|
|
123
|
+
multipleOf?: number;
|
|
124
|
+
maximum?: number;
|
|
125
|
+
exclusiveMaximum?: boolean;
|
|
126
|
+
minimum?: number;
|
|
127
|
+
exclusiveMinimum?: boolean;
|
|
128
|
+
maxLength?: number;
|
|
129
|
+
minLength?: number;
|
|
130
|
+
pattern?: string;
|
|
131
|
+
additionalProperties?: boolean | ReferenceObject | SchemaObject;
|
|
132
|
+
maxItems?: number;
|
|
133
|
+
minItems?: number;
|
|
134
|
+
uniqueItems?: boolean;
|
|
135
|
+
maxProperties?: number;
|
|
136
|
+
minProperties?: number;
|
|
137
|
+
required?: string[];
|
|
138
|
+
enum?: any[];
|
|
139
|
+
properties?: {
|
|
140
|
+
[name: string]: ReferenceObject | SchemaObject;
|
|
141
|
+
};
|
|
142
|
+
allOf?: (ReferenceObject | SchemaObject)[];
|
|
143
|
+
oneOf?: (ReferenceObject | SchemaObject)[];
|
|
144
|
+
anyOf?: (ReferenceObject | SchemaObject)[];
|
|
145
|
+
not?: ReferenceObject | SchemaObject;
|
|
146
|
+
nullable?: boolean;
|
|
147
|
+
discriminator?: DiscriminatorObject;
|
|
148
|
+
readOnly?: boolean;
|
|
149
|
+
writeOnly?: boolean;
|
|
150
|
+
xml?: XMLObject;
|
|
151
|
+
externalDocs?: ExternalDocumentationObject;
|
|
152
|
+
example?: any;
|
|
153
|
+
deprecated?: boolean;
|
|
154
|
+
}
|
|
155
|
+
interface DiscriminatorObject {
|
|
156
|
+
propertyName: string;
|
|
157
|
+
mapping?: {
|
|
158
|
+
[value: string]: string;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
interface XMLObject {
|
|
162
|
+
name?: string;
|
|
163
|
+
namespace?: string;
|
|
164
|
+
prefix?: string;
|
|
165
|
+
attribute?: boolean;
|
|
166
|
+
wrapped?: boolean;
|
|
167
|
+
}
|
|
168
|
+
interface ReferenceObject {
|
|
169
|
+
$ref: string;
|
|
170
|
+
}
|
|
171
|
+
interface ExampleObject {
|
|
172
|
+
summary?: string;
|
|
173
|
+
description?: string;
|
|
174
|
+
value?: any;
|
|
175
|
+
externalValue?: string;
|
|
176
|
+
}
|
|
177
|
+
interface MediaTypeObject {
|
|
178
|
+
schema?: ReferenceObject | SchemaObject;
|
|
179
|
+
example?: any;
|
|
180
|
+
examples?: {
|
|
181
|
+
[media: string]: ReferenceObject | ExampleObject;
|
|
182
|
+
};
|
|
183
|
+
encoding?: {
|
|
184
|
+
[media: string]: EncodingObject;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
interface EncodingObject {
|
|
188
|
+
contentType?: string;
|
|
189
|
+
headers?: {
|
|
190
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
191
|
+
};
|
|
192
|
+
style?: string;
|
|
193
|
+
explode?: boolean;
|
|
194
|
+
allowReserved?: boolean;
|
|
195
|
+
}
|
|
196
|
+
interface RequestBodyObject {
|
|
197
|
+
description?: string;
|
|
198
|
+
content: {
|
|
199
|
+
[media: string]: MediaTypeObject;
|
|
200
|
+
};
|
|
201
|
+
required?: boolean;
|
|
202
|
+
}
|
|
203
|
+
interface ResponsesObject {
|
|
204
|
+
[code: string]: ReferenceObject | ResponseObject;
|
|
205
|
+
}
|
|
206
|
+
interface ResponseObject {
|
|
207
|
+
description: string;
|
|
208
|
+
headers?: {
|
|
209
|
+
[header: string]: ReferenceObject | HeaderObject;
|
|
210
|
+
};
|
|
211
|
+
content?: {
|
|
212
|
+
[media: string]: MediaTypeObject;
|
|
213
|
+
};
|
|
214
|
+
links?: {
|
|
215
|
+
[link: string]: ReferenceObject | LinkObject;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
interface LinkObject {
|
|
219
|
+
operationRef?: string;
|
|
220
|
+
operationId?: string;
|
|
221
|
+
parameters?: {
|
|
222
|
+
[parameter: string]: any;
|
|
223
|
+
};
|
|
224
|
+
requestBody?: any;
|
|
225
|
+
description?: string;
|
|
226
|
+
server?: ServerObject;
|
|
227
|
+
}
|
|
228
|
+
interface CallbackObject {
|
|
229
|
+
[url: string]: PathItemObject;
|
|
230
|
+
}
|
|
231
|
+
interface SecurityRequirementObject {
|
|
232
|
+
[name: string]: string[];
|
|
233
|
+
}
|
|
234
|
+
interface ComponentsObject {
|
|
235
|
+
schemas?: {
|
|
236
|
+
[key: string]: ReferenceObject | SchemaObject;
|
|
237
|
+
};
|
|
238
|
+
responses?: {
|
|
239
|
+
[key: string]: ReferenceObject | ResponseObject;
|
|
240
|
+
};
|
|
241
|
+
parameters?: {
|
|
242
|
+
[key: string]: ReferenceObject | ParameterObject;
|
|
243
|
+
};
|
|
244
|
+
examples?: {
|
|
245
|
+
[key: string]: ReferenceObject | ExampleObject;
|
|
246
|
+
};
|
|
247
|
+
requestBodies?: {
|
|
248
|
+
[key: string]: ReferenceObject | RequestBodyObject;
|
|
249
|
+
};
|
|
250
|
+
headers?: {
|
|
251
|
+
[key: string]: ReferenceObject | HeaderObject;
|
|
252
|
+
};
|
|
253
|
+
securitySchemes?: {
|
|
254
|
+
[key: string]: ReferenceObject | SecuritySchemeObject;
|
|
255
|
+
};
|
|
256
|
+
links?: {
|
|
257
|
+
[key: string]: ReferenceObject | LinkObject;
|
|
258
|
+
};
|
|
259
|
+
callbacks?: {
|
|
260
|
+
[key: string]: ReferenceObject | CallbackObject;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
type SecuritySchemeObject = HttpSecurityScheme | ApiKeySecurityScheme | OAuth2SecurityScheme | OpenIdSecurityScheme;
|
|
264
|
+
interface HttpSecurityScheme {
|
|
265
|
+
type: 'http';
|
|
266
|
+
description?: string;
|
|
267
|
+
scheme: string;
|
|
268
|
+
bearerFormat?: string;
|
|
269
|
+
}
|
|
270
|
+
interface ApiKeySecurityScheme {
|
|
271
|
+
type: 'apiKey';
|
|
272
|
+
description?: string;
|
|
273
|
+
name: string;
|
|
274
|
+
in: string;
|
|
275
|
+
}
|
|
276
|
+
interface OAuth2SecurityScheme {
|
|
277
|
+
type: 'oauth2';
|
|
278
|
+
description?: string;
|
|
279
|
+
flows: {
|
|
280
|
+
implicit?: {
|
|
281
|
+
authorizationUrl: string;
|
|
282
|
+
refreshUrl?: string;
|
|
283
|
+
scopes: {
|
|
284
|
+
[scope: string]: string;
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
password?: {
|
|
288
|
+
tokenUrl: string;
|
|
289
|
+
refreshUrl?: string;
|
|
290
|
+
scopes: {
|
|
291
|
+
[scope: string]: string;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
clientCredentials?: {
|
|
295
|
+
tokenUrl: string;
|
|
296
|
+
refreshUrl?: string;
|
|
297
|
+
scopes: {
|
|
298
|
+
[scope: string]: string;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
authorizationCode?: {
|
|
302
|
+
authorizationUrl: string;
|
|
303
|
+
tokenUrl: string;
|
|
304
|
+
refreshUrl?: string;
|
|
305
|
+
scopes: {
|
|
306
|
+
[scope: string]: string;
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
interface OpenIdSecurityScheme {
|
|
312
|
+
type: 'openIdConnect';
|
|
313
|
+
description?: string;
|
|
314
|
+
openIdConnectUrl: string;
|
|
315
|
+
}
|
|
316
|
+
interface TagObject {
|
|
317
|
+
name: string;
|
|
318
|
+
description?: string;
|
|
319
|
+
externalDocs?: ExternalDocumentationObject;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/shared/config/types.d.ts
|
|
324
|
+
interface ApiConfig {
|
|
325
|
+
/**
|
|
326
|
+
* swagger JSON 的路径 可以是 本地 可以是远程
|
|
327
|
+
*/
|
|
328
|
+
swaggerJSONPath: string;
|
|
329
|
+
/**
|
|
330
|
+
* 用在生成代码里快捷连接跳转到 swagger ui
|
|
331
|
+
* 必须携带 urls.primaryName 参数
|
|
332
|
+
* @example http://192.168.104.10:31082/swagger/?urls.primaryName=%E5%90%8E%E5%8F%B0%E7%AE%A1%E7%90%86%E7%9B%B8%E5%85%B3API
|
|
333
|
+
*/
|
|
334
|
+
swaggerUiUrl?: string;
|
|
335
|
+
/**
|
|
336
|
+
* 输出的文件夹路径
|
|
337
|
+
* @default "./src/apis"
|
|
338
|
+
*/
|
|
339
|
+
output?: string;
|
|
340
|
+
/**
|
|
341
|
+
* 配置`queryClient` 路径,导入的变量必须是命名为`queryClient`
|
|
342
|
+
* @example `import queryClient from '@/utils/request'`
|
|
343
|
+
* @example `import { queryClient } from '@/utils/request'`
|
|
344
|
+
* @example `import { xxClient as queryClient } from '@/utils/request'`
|
|
345
|
+
*/
|
|
346
|
+
queryClientImportPath?: string;
|
|
347
|
+
/**
|
|
348
|
+
* 配置`RequestBuilder` 路径,导入的变量必须是命名为`RequestBuilder`
|
|
349
|
+
* @example `import RequestBuilder from '@/utils/RequestBuilder'`
|
|
350
|
+
* @default `import { RequestBuilder } from '@dune2/tools/rq'`
|
|
351
|
+
*/
|
|
352
|
+
RequestBuilderImportPath?: string;
|
|
353
|
+
/**
|
|
354
|
+
* 是否启用ts,`true`会生成`.ts`文件,`false`会生成`.js`文件
|
|
355
|
+
* @default true
|
|
356
|
+
*/
|
|
357
|
+
enableTs?: boolean;
|
|
358
|
+
/**
|
|
359
|
+
* 响应的scheme转换,默认获取获取 data 字段,取不到回退到 scheme
|
|
360
|
+
* @default (schema) => schema.properties?.data ?? schema
|
|
361
|
+
*/
|
|
362
|
+
responseSchemaTransformer?: (schema: OpenAPIV3.SchemaObject) => any;
|
|
363
|
+
/**
|
|
364
|
+
* 生成代码完毕后执行的代码格式化命令
|
|
365
|
+
* 用户可自定义格式化工具及参数
|
|
366
|
+
* @default "oxfmt"
|
|
367
|
+
*/
|
|
368
|
+
codeFormatterCmd?: string;
|
|
369
|
+
/**
|
|
370
|
+
* url 转换器,可以是字符串,也可以是函数
|
|
371
|
+
*
|
|
372
|
+
* 字符串会被当成prefix, 会在url前面加上
|
|
373
|
+
*
|
|
374
|
+
* 函数会被当成转换器
|
|
375
|
+
*
|
|
376
|
+
* @tips 不会影响文件名,只会影响生成的代码里的url字段
|
|
377
|
+
*/
|
|
378
|
+
urlTransformer?: string | ((url: string) => string);
|
|
379
|
+
/**
|
|
380
|
+
* 配置 dereference 的参数
|
|
381
|
+
*/
|
|
382
|
+
dereferenceSwaggerConfig?: SwaggerParser.Options;
|
|
383
|
+
}
|
|
384
|
+
interface Config {
|
|
385
|
+
api?: ApiConfig[];
|
|
386
|
+
}
|
|
387
|
+
//#endregion
|
|
388
|
+
export { Config as n, ApiConfig as t };
|
|
389
|
+
//# sourceMappingURL=types-BRp2czbi.d.mts.map
|
package/package.json
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dune2/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/liaoyinglong/next-tools.git",
|
|
7
7
|
"directory": "packages/cli"
|
|
8
8
|
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"dune": "./dist/cli.mjs"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
9
15
|
"type": "module",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
10
17
|
"exports": {
|
|
11
18
|
".": {
|
|
12
19
|
"import": "./dist/index.mjs"
|
|
@@ -17,37 +24,26 @@
|
|
|
17
24
|
"./normalizeConfig": {
|
|
18
25
|
"import": "./dist/normalizeConfig.mjs"
|
|
19
26
|
},
|
|
20
|
-
"./prettier": {
|
|
21
|
-
"import": "./dist/prettier.mjs",
|
|
22
|
-
"require": "./dist/prettier.cjs"
|
|
23
|
-
},
|
|
24
27
|
"./package.json": "./package.json"
|
|
25
28
|
},
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"dune": "./dist/cli.mjs"
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
29
31
|
},
|
|
30
|
-
"files": [
|
|
31
|
-
"dist"
|
|
32
|
-
],
|
|
33
32
|
"dependencies": {
|
|
34
|
-
"@apidevtools/swagger-parser": "^12",
|
|
35
|
-
"cac": "^
|
|
36
|
-
"debug": "^4.3
|
|
33
|
+
"@apidevtools/swagger-parser": "^12.1.0",
|
|
34
|
+
"cac": "^7.0.0",
|
|
35
|
+
"debug": "^4.4.3",
|
|
37
36
|
"enquirer": "^2.3.6",
|
|
38
|
-
"es-toolkit": "^1",
|
|
39
|
-
"jiti": "^2.
|
|
37
|
+
"es-toolkit": "^1.44.0",
|
|
38
|
+
"jiti": "^2.6.1",
|
|
40
39
|
"json-schema-to-typescript": "15.0.3",
|
|
41
|
-
"p-map": "^7.0.
|
|
40
|
+
"p-map": "^7.0.4"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
|
-
"@types/debug": "^4.1.
|
|
43
|
+
"@types/debug": "^4.1.12",
|
|
45
44
|
"openapi-types": "^12.0.2",
|
|
46
|
-
"prettier": "^3",
|
|
47
|
-
"tsdown": "^0.
|
|
48
|
-
},
|
|
49
|
-
"publishConfig": {
|
|
50
|
-
"access": "public"
|
|
45
|
+
"prettier": "^3.8.1",
|
|
46
|
+
"tsdown": "^0.20.3"
|
|
51
47
|
},
|
|
52
48
|
"scripts": {
|
|
53
49
|
"build": "tsdown --splitting --clean",
|
package/readme.md
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-CxSOgXuG.mjs","names":[],"sources":["../src/shared/config/index.ts"],"sourcesContent":["import { createJiti } from \"jiti\";\nimport { normalizeConfig } from \"./normalizeConfig\";\nimport { Config } from \"./types\";\n\nexport * from \"./types\";\n\nexport function defineConfig<T extends Config = Config>(c: T) {\n return c;\n}\n\nexport const configName = \"dune.config.ts\";\n\nexport async function getConfig(): Promise<Config> {\n const cwd = process.cwd();\n const jiti = createJiti(cwd);\n\n const res = await jiti\n .import<Config>(`./${configName}`, {\n default: true,\n })\n .catch((err) => {\n console.warn(`can not find config file: ${configName} in ${cwd}`);\n console.warn(`please run \"dune init\" to create config file`);\n return {};\n });\n\n return normalizeConfig(res);\n}\n"],"mappings":";;;;AAMA,SAAgB,aAAwC,GAAM;AAC5D,QAAO;;AAGT,MAAa,aAAa;AAE1B,eAAsB,YAA6B;CACjD,MAAM,MAAM,QAAQ,KAAK;AAazB,QAAO,gBAVK,MAFC,WAAW,IAAI,CAGzB,OAAe,KAAK,cAAc,EACjC,SAAS,MACV,CAAC,CACD,OAAO,QAAQ;AACd,UAAQ,KAAK,6BAA6B,WAAW,MAAM,MAAM;AACjE,UAAQ,KAAK,+CAA+C;AAC5D,SAAO,EAAE;GACT,CAEuB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateApi-CxXqgeuk.mjs","names":[],"sources":["../src/shared/promptConfigEnable.ts","../src/commands/generateApi/index.ts"],"sourcesContent":["import enquirer from \"enquirer\";\nimport { ApiConfig } from \"./config\";\nconst { prompt } = enquirer;\n\ninterface Opt<T> {\n configArr: (T & { enabled?: boolean })[];\n getChoiceItem: (item: T) => {\n name: string;\n message?: string;\n value?: string;\n hint?: string;\n };\n checkIsEnabled: (enabledArr: string[], item: T) => boolean;\n}\n\nexport async function promptConfigEnable<T>(opt: Opt<T>) {\n const { configArr, getChoiceItem } = opt;\n // 只有一条配置的时候不用选择\n if (configArr.length <= 1) {\n return configArr;\n }\n\n const choices = [\n {\n name: \"全部\",\n message: \"全部\",\n choices: configArr.map((item) => {\n return getChoiceItem(item);\n }),\n },\n ];\n const res = await prompt<{ enabled: string[] }>({\n type: \"multiselect\",\n message: \"选择要生效的配置项\",\n // @ts-ignore\n hint: \"(空格选中,回车确认)\",\n name: \"enabled\",\n validate(value) {\n return value.length === 0 ? `至少选择一项` : true;\n },\n choices,\n });\n\n configArr.forEach((item) => {\n item.enabled = opt.checkIsEnabled(res.enabled, item);\n });\n\n return configArr.filter((c) => c.enabled);\n}\n\nexport function promptApiConfigEnable(configArr: ApiConfig[] | undefined) {\n return promptConfigEnable({\n configArr: configArr ?? [],\n getChoiceItem: (item) => {\n return {\n name: item.output!,\n hint: `swaggerJSONPath: ${item.swaggerJSONPath}`,\n };\n },\n checkIsEnabled: (enabledArr, item) => {\n return enabledArr.includes(item.output!);\n },\n });\n}\n","import SwaggerParser from \"@apidevtools/swagger-parser\";\nimport { camelCase, isPlainObject, merge } from \"es-toolkit\";\nimport { compile } from \"json-schema-to-typescript\";\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport fs from \"node:fs/promises\";\nimport { OpenAPIV3, type OpenAPI } from \"openapi-types\";\nimport * as os from \"os\";\nimport pMap from \"p-map\";\nimport path from \"path\";\nimport { createLogger } from \"../../shared\";\nimport { ApiConfig, getConfig } from \"../../shared/config\";\nimport { promptApiConfigEnable } from \"../../shared/promptConfigEnable\";\n\nconst log = createLogger(\"generateApi\");\n\nexport const asyncLocalStorage = new AsyncLocalStorage<{\n parsed: OpenAPIV3.Document;\n parser: SwaggerParser;\n}>();\n\nfunction isV3(doc: OpenAPI.Document | undefined): doc is OpenAPIV3.Document {\n if (doc) {\n return \"components\" in doc;\n }\n return false;\n}\n\nexport async function generateApi() {\n const config = await getConfig();\n const apiConfigs = await promptApiConfigEnable(config.api);\n\n for (const apiConfig of apiConfigs) {\n log.info(`清除旧的 api 文件:${apiConfig.output}`);\n await fs.rm(apiConfig.output!, { recursive: true, force: true });\n await fs.mkdir(apiConfig.output!, { recursive: true });\n }\n\n for (const apiConfig of apiConfigs) {\n log.info(\"开始解析 %s\", apiConfig.swaggerJSONPath);\n const dereferenceConfig = merge(\n {\n resolve: {\n http: {\n timeout: 30 * 1000,\n },\n },\n },\n apiConfig.dereferenceSwaggerConfig || {},\n );\n const parser = new SwaggerParser();\n\n const parsed = await parser.bundle(\n apiConfig.swaggerJSONPath,\n dereferenceConfig,\n );\n\n const state = {\n // only support v3\n parsed: parsed as OpenAPIV3.Document,\n parser,\n };\n await asyncLocalStorage.run(state, async () => {\n await pMap(\n Object.entries(parsed.paths!),\n async ([url, pathItemObject]) => {\n log.info(\"开始生成 %s\", url);\n if (pathItemObject) {\n await pMap(\n [\"get\", \"put\", \"post\", \"delete\", \"patch\"],\n async (method) => {\n const operationObject = pathItemObject[method];\n if (operationObject) {\n const code = await generateApiRequestCode({\n url: url,\n method: method,\n operationObject: operationObject,\n apiConfig,\n });\n const outputPath = path\n .join(\n apiConfig.output!,\n url,\n apiConfig.enableTs ? `${method}.ts` : `${method}.js`,\n )\n .replace(/:/g, \"_\");\n await fs.mkdir(path.dirname(outputPath), {\n recursive: true,\n });\n await fs.writeFile(outputPath, code);\n }\n },\n );\n }\n },\n );\n });\n if (apiConfig.codeFormatterCmd) {\n const { exec } = await import(\"child_process\");\n await new Promise<void>((resolve) => {\n exec(\n `${apiConfig.codeFormatterCmd} \"${apiConfig.output!}\"`,\n (error) => {\n if (error) {\n log.error(`Code formatting failed: ${error.message}`);\n } else {\n log.info(`Code formatting success`);\n }\n resolve();\n },\n );\n });\n }\n }\n\n log.info(\"generateApi Done\");\n}\n\n/**\n * 根据请求方法,生成请求代码\n */\nexport async function generateApiRequestCode(options: {\n url: string;\n method: string;\n operationObject: OpenAPIV3.OperationObject;\n apiConfig: ApiConfig;\n}): Promise<string> {\n const { method, operationObject, apiConfig } = options;\n\n const url = (() => {\n if (typeof apiConfig.urlTransformer === \"string\") {\n return `${apiConfig.urlTransformer}${options.url}`;\n }\n if (typeof apiConfig.urlTransformer === \"function\") {\n return apiConfig.urlTransformer(options.url);\n }\n return options.url;\n })();\n\n const seeUrl = apiConfig.swaggerUiUrl\n ? `${apiConfig.swaggerUiUrl}#/${encodeURIComponent(\n `${operationObject.tags?.join(\"/\") ?? \"\"}/${\n operationObject.operationId\n }`,\n )}`\n : \"\";\n\n // 生成的请求构造器的名称,需要使用原始 url\n let requestBuilderName = camelCase(`${options.url}_${method}_api`);\n\n // 判断是否有效的 js 变量\n if (!/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(requestBuilderName)) {\n // 不是有效的 js 变量,使用 _ + 数字\n requestBuilderName = `_${requestBuilderName}`;\n }\n\n //#region url 上参数 例如 /api/v1/users/{userId}\n const urlPathParams = getUrlPathParams(\n (operationObject.parameters as never) ?? [],\n );\n const urlPathParamsCode = urlPathParams.length\n ? `urlPathParams: ${JSON.stringify(urlPathParams)},`\n : \"\";\n //#endregion\n\n let code: string[] = [\n \"// do not edit this file manually, it will be overwritten by @dune2/cli\",\n apiConfig.RequestBuilderImportPath!,\n apiConfig.queryClientImportPath!,\n\n \"/**\",\n ` * ${operationObject.summary}`,\n ` * @tags ${operationObject.tags?.join(\",\")}`,\n seeUrl && ` * @see ${seeUrl}`,\n ` */`,\n ].filter(Boolean);\n\n // builder 代码\n let builderCode = `\\\nexport const ${requestBuilderName} = new RequestBuilder({\n url: '${url}',\n method: '${method}',\n ${urlPathParamsCode}\n ${apiConfig.queryClientImportPath ? \"queryClient,\" : \"\"}\n});`\n // 移除空行\n .replace(/,\\n\\s*}/, \",\" + os.EOL + \"}\");\n if (apiConfig.enableTs) {\n builderCode = builderCode.replace(\n \"new RequestBuilder(\",\n `new RequestBuilder<${requestBuilderName}.Req, ${requestBuilderName}.Res>(`,\n );\n }\n code.push(builderCode);\n\n if (apiConfig.enableTs) {\n const [requestParamsTypeCode, responseParamsTypeCode] = await Promise.all([\n // 请求参数类型\n compileRequestParams(operationObject),\n // 响应参数类型\n compileResponseParams(operationObject, apiConfig),\n ]);\n\n code.push(`\nexport namespace ${requestBuilderName} {\n ${requestParamsTypeCode.code}\n \n ${responseParamsTypeCode}\n};`);\n }\n\n return code.join(os.EOL);\n}\n\nfunction getUrlPathParams(parameters: OpenAPIV3.ParameterObject[]) {\n return parameters\n .filter((item) => item.in === \"path\")\n .map((item) => item.name);\n}\n\n/**\n * 这个方法还不完善,只能处理简单的请求参数\n */\nasync function compileRequestParams(\n operationObject: OpenAPIV3.OperationObject,\n) {\n const store = asyncLocalStorage.getStore();\n const schemaOrRefObject = (() => {\n if (operationObject.requestBody) {\n if (\"$ref\" in operationObject.requestBody) {\n return operationObject.requestBody;\n }\n return operationObject.requestBody.content[\"application/json\"].schema;\n }\n if (operationObject.parameters) {\n const extraProperties = {};\n const parameters: OpenAPIV3.ParameterObject[] = [];\n (operationObject.parameters as OpenAPIV3.ParameterObject[]).forEach(\n (item) => {\n if (![\"query\", \"path\"].includes(item.in)) {\n return;\n }\n if (\n item.schema &&\n \"type\" in item.schema &&\n item.schema.type === \"object\"\n ) {\n // swagger get 请求上 有些参数是 object 类型 应该拍平\n Object.assign(\n extraProperties,\n (item.schema as OpenAPIV3.SchemaObject).properties || {},\n );\n } else {\n parameters.push(item);\n }\n },\n );\n // 必填参数中忽略 分页相关的参数\n const required = parameters\n .filter(\n (p) =>\n p.required && ![\"pageNum\", \"pageSize\", \"count\"].includes(p.name),\n )\n .map((p) => p.name);\n const properties = Object.fromEntries(\n parameters\n // 后端 swagger 可能出现没有 schema 的情况,这里过滤掉\n .filter((p) => !!p.schema)\n .map((p) => {\n const schema = p.schema;\n return [\n p.name,\n {\n ...schema,\n description: p.description,\n // enum: schema.enum ?? [],\n },\n ];\n }),\n );\n return {\n required,\n type: \"object\",\n properties: { ...properties, ...extraProperties },\n };\n }\n })();\n\n const finalSchema = isPlainObject(schemaOrRefObject)\n ? Object.assign(\n {\n components: store?.parsed.components,\n },\n \"$ref\" in schemaOrRefObject\n ? store?.parser.$refs.get(schemaOrRefObject.$ref)\n : schemaOrRefObject,\n )\n : void 0;\n\n let code = \"\";\n if (finalSchema) {\n try {\n code = await compile(finalSchema as never, \"Req\", {\n bannerComment: \"\",\n ignoreMinAndMaxItems: !!1,\n additionalProperties: false,\n unknownAny: false,\n // format: false,\n });\n } catch (e) {\n log.error(\"生成请求参数类型失败,请检查 %o\", {\n summary: operationObject.summary,\n message: e.message,\n operationId: operationObject.operationId,\n });\n }\n }\n\n return {\n code: code || \"export type Req = any;\",\n };\n}\n\nasync function compileResponseParams(\n operationObject: OpenAPIV3.OperationObject,\n apiConfig: ApiConfig,\n) {\n const store = asyncLocalStorage.getStore();\n\n function resolveSchema(\n arg:\n | OpenAPIV3.ReferenceObject\n | OpenAPIV3.ResponseObject\n | OpenAPIV3.MediaTypeObject\n | undefined,\n ) {\n if (!arg) return;\n\n if (\"content\" in arg) {\n const temp = arg.content?.[\"application/json\"] || arg.content?.[\"*/*\"];\n return resolveSchema(temp?.schema);\n }\n\n let schema = apiConfig.responseSchemaTransformer!(arg as never) as\n | OpenAPIV3.ReferenceObject\n | OpenAPIV3.SchemaObject;\n if (\"$ref\" in schema) {\n return resolveSchema(store?.parser.$refs.get(schema.$ref) as never);\n }\n return schema;\n }\n const schemaObject = resolveSchema(operationObject.responses[\"200\"]);\n const finalSchema = schemaObject\n ? Object.assign(\n {\n components: store?.parsed.components,\n },\n schemaObject,\n )\n : void 0;\n\n let code = \"\";\n if (finalSchema) {\n try {\n code = await compile(finalSchema, \"Res\", {\n bannerComment: \"\",\n ignoreMinAndMaxItems: !!1,\n additionalProperties: false,\n unknownAny: false,\n // format: false,\n });\n } catch (e) {\n log.error(\"转换响应参数类型失败,请检查 %o\", {\n summary: operationObject.summary,\n error: e.message,\n operationId: operationObject.operationId,\n });\n }\n } else {\n log.error(\"responseSchemaTransformer 返回值为空,请检查\");\n }\n\n return code ? code : \"export type Res = any;\";\n}\n"],"mappings":";;;;;;;;;;;;;AAEA,MAAM,EAAE,WAAW;AAanB,eAAsB,mBAAsB,KAAa;CACvD,MAAM,EAAE,WAAW,kBAAkB;AAErC,KAAI,UAAU,UAAU,EACtB,QAAO;CAYT,MAAM,MAAM,MAAM,OAA8B;EAC9C,MAAM;EACN,SAAS;EAET,MAAM;EACN,MAAM;EACN,SAAS,OAAO;AACd,UAAO,MAAM,WAAW,IAAI,WAAW;;EAEzC,SAlBc,CACd;GACE,MAAM;GACN,SAAS;GACT,SAAS,UAAU,KAAK,SAAS;AAC/B,WAAO,cAAc,KAAK;KAC1B;GACH,CACF;EAWA,CAAC;AAEF,WAAU,SAAS,SAAS;AAC1B,OAAK,UAAU,IAAI,eAAe,IAAI,SAAS,KAAK;GACpD;AAEF,QAAO,UAAU,QAAQ,MAAM,EAAE,QAAQ;;AAG3C,SAAgB,sBAAsB,WAAoC;AACxE,QAAO,mBAAmB;EACxB,WAAW,aAAa,EAAE;EAC1B,gBAAgB,SAAS;AACvB,UAAO;IACL,MAAM,KAAK;IACX,MAAM,oBAAoB,KAAK;IAChC;;EAEH,iBAAiB,YAAY,SAAS;AACpC,UAAO,WAAW,SAAS,KAAK,OAAQ;;EAE3C,CAAC;;;;;ACjDJ,MAAM,MAAM,aAAa,cAAc;AAEvC,MAAa,oBAAoB,IAAI,mBAGjC;AASJ,eAAsB,cAAc;CAElC,MAAM,aAAa,MAAM,uBADV,MAAM,WAAW,EACsB,IAAI;AAE1D,MAAK,MAAM,aAAa,YAAY;AAClC,MAAI,KAAK,eAAe,UAAU,SAAS;AAC3C,QAAM,GAAG,GAAG,U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"initConfig-Cu0d5qZ8.mjs","names":[],"sources":["../src/commands/initConfig.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"path\";\nimport { createLogger } from \"../shared\";\nimport { configName } from \"../shared/config\";\n\nconst log = createLogger(\"initConfig\");\n\nconst tpl = `\\\nimport { defineConfig } from \"@dune2/cli\";\n\nexport default defineConfig({\n i18n: [],\n api: [],\n});`;\n\nexport const initConfig = async () => {\n const configPath = path.join(process.cwd(), configName);\n log.info(`config file path: ${configPath}`);\n if (\n await fs\n .access(configPath)\n .then(() => true)\n .catch(() => false)\n ) {\n log.info(`config file already exists, skip`);\n return;\n }\n await fs.writeFile(configPath, tpl);\n log.info(`config file created`);\n};\n"],"mappings":";;;;;;AAKA,MAAM,MAAM,aAAa,aAAa;AAEtC,MAAM,MAAM;;;;;;;AAQZ,MAAa,aAAa,YAAY;CACpC,MAAM,aAAa,KAAK,KAAK,QAAQ,KAAK,EAAE,WAAW;AACvD,KAAI,KAAK,qBAAqB,aAAa;AAC3C,KACE,MAAM,GACH,OAAO,WAAW,CAClB,WAAW,KAAK,CAChB,YAAY,MAAM,EACrB;AACA,MAAI,KAAK,mCAAmC;AAC5C;;AAEF,OAAM,GAAG,UAAU,YAAY,IAAI;AACnC,KAAI,KAAK,sBAAsB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interactive-CG86IvnG.mjs","names":["command"],"sources":["../src/commands/interactive.ts"],"sourcesContent":["import { cli, createLogger } from \"../shared\";\nimport enquirer from \"enquirer\";\nconst { prompt } = enquirer;\n\nconst log = createLogger(\"interactive\");\n\nexport const interactive = async (args: any) => {\n const commands = cli.commands.filter((command) => {\n if (command.name) {\n return !command.name.startsWith(\"@@\") && command.name !== \"interactive\";\n }\n return false;\n });\n\n const commandMap = new Map<string, typeof commands[number]>();\n const res = await prompt<{ command: string }>({\n type: \"autocomplete\",\n name: \"command\",\n message: \"选择要执行的命令:\",\n choices: commands.map((command) => {\n commandMap.set(command.name, command);\n return {\n name: command.name,\n value: command.name,\n message: command.description,\n hint: `等同命令 ${cli.name} ${command.name}`,\n };\n }),\n });\n const command = commandMap.get(res.command);\n if (!command) {\n log.error(\"未找到命令 %s\", res.command);\n return;\n }\n command.commandAction?.apply(cli, args);\n};\n"],"mappings":";;;;AAEA,MAAM,EAAE,WAAW;AAEnB,MAAM,MAAM,aAAa,cAAc;AAEvC,MAAa,cAAc,OAAO,SAAc;;CAC9C,MAAM,WAAW,IAAI,SAAS,QAAQ,cAAY;AAChD,MAAIA,UAAQ,KACV,QAAO,CAACA,UAAQ,KAAK,WAAW,KAAK,IAAIA,UAAQ,SAAS;AAE5D,SAAO;GACP;CAEF,MAAM,6BAAa,IAAI,KAAsC;CAC7D,MAAM,MAAM,MAAM,OAA4B;EAC5C,MAAM;EACN,MAAM;EACN,SAAS;EACT,SAAS,SAAS,KAAK,cAAY;AACjC,cAAW,IAAIA,UAAQ,MAAMA,UAAQ;AACrC,UAAO;IACL,MAAMA,UAAQ;IACd,OAAOA,UAAQ;IACf,SAASA,UAAQ;IACjB,MAAM,QAAQ,IAAI,KAAK,GAAGA,UAAQ;IACnC;IACD;EACH,CAAC;CACF,MAAM,UAAU,WAAW,IAAI,IAAI,QAAQ;AAC3C,KAAI,CAAC,SAAS;AACZ,MAAI,MAAM,YAAY,IAAI,QAAQ;AAClC;;AAEF,kCAAQ,qFAAe,MAAM,KAAK,KAAK"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
|
|
3
|
-
//#region src/shared/config/normalizeConfig.ts
|
|
4
|
-
function normalizeConfig(config) {
|
|
5
|
-
config.cwd ??= process.cwd();
|
|
6
|
-
config.cacheDir ??= path.join(config.cwd, "node_modules/.cache/dune-cli");
|
|
7
|
-
config.api ??= [];
|
|
8
|
-
config.api = config.api.map(apiConfigNormalizer);
|
|
9
|
-
return config;
|
|
10
|
-
}
|
|
11
|
-
function apiConfigNormalizer(item) {
|
|
12
|
-
item.output ??= "./src/apis";
|
|
13
|
-
item.RequestBuilderImportPath ??= `import { RequestBuilder } from '@dune2/tools/rq';`;
|
|
14
|
-
item.enableTs ??= true;
|
|
15
|
-
item.enabled ??= true;
|
|
16
|
-
item.codeFormatterCmd ??= "prettier --write";
|
|
17
|
-
item.responseSchemaTransformer ??= (schema) => {
|
|
18
|
-
var _schema$properties;
|
|
19
|
-
return ((_schema$properties = schema.properties) === null || _schema$properties === void 0 ? void 0 : _schema$properties.data) ?? schema;
|
|
20
|
-
};
|
|
21
|
-
return item;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { normalizeConfig as n, apiConfigNormalizer as t };
|
|
26
|
-
//# sourceMappingURL=normalizeConfig-Dx193DW8.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalizeConfig-Dx193DW8.mjs","names":[],"sources":["../src/shared/config/normalizeConfig.ts"],"sourcesContent":["import path from \"path\";\nimport { ApiConfig, Config } from \"./types\";\nexport function normalizeConfig(config: Config): Config {\n config.cwd ??= process.cwd();\n config.cacheDir ??= path.join(config.cwd, \"node_modules/.cache/dune-cli\");\n\n //#region api 配置标准化\n config.api ??= [];\n config.api = config.api.map(apiConfigNormalizer);\n //#endregion\n return config;\n}\nexport function apiConfigNormalizer(item: ApiConfig) {\n item.output ??= \"./src/apis\";\n item.RequestBuilderImportPath ??= `import { RequestBuilder } from '@dune2/tools/rq';`;\n item.enableTs ??= true;\n item.enabled ??= true;\n item.codeFormatterCmd ??= \"prettier --write\";\n item.responseSchemaTransformer ??= (schema) =>\n schema.properties?.data ?? schema;\n return item;\n}\n"],"mappings":";;;AAEA,SAAgB,gBAAgB,QAAwB;AACtD,QAAO,QAAQ,QAAQ,KAAK;AAC5B,QAAO,aAAa,KAAK,KAAK,OAAO,KAAK,+BAA+B;AAGzE,QAAO,QAAQ,EAAE;AACjB,QAAO,MAAM,OAAO,IAAI,IAAI,oBAAoB;AAEhD,QAAO;;AAET,SAAgB,oBAAoB,MAAiB;AACnD,MAAK,WAAW;AAChB,MAAK,6BAA6B;AAClC,MAAK,aAAa;AAClB,MAAK,YAAY;AACjB,MAAK,qBAAqB;AAC1B,MAAK,+BAA+B,WAClC;;uCAAO,oFAAY,SAAQ;;AAC7B,QAAO"}
|