@kubb/plugin-ts 5.0.0-alpha.2 → 5.0.0-alpha.21

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 (76) hide show
  1. package/dist/Type-B6fo0gSk.js +120 -0
  2. package/dist/Type-B6fo0gSk.js.map +1 -0
  3. package/dist/Type-oFwUfkZv.cjs +131 -0
  4. package/dist/Type-oFwUfkZv.cjs.map +1 -0
  5. package/dist/builderTs-Cd3juc2G.cjs +120 -0
  6. package/dist/builderTs-Cd3juc2G.cjs.map +1 -0
  7. package/dist/builderTs-DausqHpc.js +116 -0
  8. package/dist/builderTs-DausqHpc.js.map +1 -0
  9. package/dist/builders.cjs +3 -0
  10. package/dist/builders.d.ts +8 -0
  11. package/dist/builders.js +2 -0
  12. package/dist/casing-BJHFg-zZ.js +84 -0
  13. package/dist/casing-BJHFg-zZ.js.map +1 -0
  14. package/dist/casing-DHfdqpLi.cjs +107 -0
  15. package/dist/casing-DHfdqpLi.cjs.map +1 -0
  16. package/dist/chunk-ByKO4r7w.cjs +38 -0
  17. package/dist/components.cjs +3 -2
  18. package/dist/components.d.ts +40 -11
  19. package/dist/components.js +2 -2
  20. package/dist/generators-ByK18qUn.js +551 -0
  21. package/dist/generators-ByK18qUn.js.map +1 -0
  22. package/dist/generators-aSsiTfUO.cjs +563 -0
  23. package/dist/generators-aSsiTfUO.cjs.map +1 -0
  24. package/dist/generators.cjs +3 -2
  25. package/dist/generators.d.ts +7 -492
  26. package/dist/generators.js +2 -2
  27. package/dist/index.cjs +148 -3
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +146 -1
  31. package/dist/index.js.map +1 -0
  32. package/dist/printerTs-BgZucv4T.js +559 -0
  33. package/dist/printerTs-BgZucv4T.js.map +1 -0
  34. package/dist/printerTs-CFXc_LpP.cjs +595 -0
  35. package/dist/printerTs-CFXc_LpP.cjs.map +1 -0
  36. package/dist/printers.cjs +3 -0
  37. package/dist/printers.d.ts +75 -0
  38. package/dist/printers.js +2 -0
  39. package/dist/resolverTsLegacy-DLl854-P.js +185 -0
  40. package/dist/resolverTsLegacy-DLl854-P.js.map +1 -0
  41. package/dist/resolverTsLegacy-sJ16Iqrl.cjs +196 -0
  42. package/dist/resolverTsLegacy-sJ16Iqrl.cjs.map +1 -0
  43. package/dist/resolvers.cjs +4 -0
  44. package/dist/resolvers.d.ts +52 -0
  45. package/dist/resolvers.js +2 -0
  46. package/dist/types-BcyuFDn9.d.ts +344 -0
  47. package/package.json +27 -8
  48. package/src/builders/builderTs.ts +92 -0
  49. package/src/builders/index.ts +1 -0
  50. package/src/components/Enum.tsx +83 -0
  51. package/src/components/Type.tsx +24 -145
  52. package/src/components/index.ts +1 -0
  53. package/src/constants.ts +29 -0
  54. package/src/factory.ts +14 -48
  55. package/src/generators/index.ts +1 -0
  56. package/src/generators/typeGenerator.tsx +119 -403
  57. package/src/generators/typeGeneratorLegacy.tsx +345 -0
  58. package/src/plugin.ts +80 -122
  59. package/src/presets.ts +26 -0
  60. package/src/printers/index.ts +1 -0
  61. package/src/printers/printerTs.ts +389 -0
  62. package/src/resolvers/index.ts +2 -0
  63. package/src/resolvers/resolverTs.ts +107 -0
  64. package/src/resolvers/resolverTsLegacy.ts +87 -0
  65. package/src/types.ts +261 -72
  66. package/dist/components-9wydyqUx.cjs +0 -848
  67. package/dist/components-9wydyqUx.cjs.map +0 -1
  68. package/dist/components-LmqJfxMv.js +0 -721
  69. package/dist/components-LmqJfxMv.js.map +0 -1
  70. package/dist/plugin-CNkzbtpl.cjs +0 -508
  71. package/dist/plugin-CNkzbtpl.cjs.map +0 -1
  72. package/dist/plugin-DoLrDl9P.js +0 -476
  73. package/dist/plugin-DoLrDl9P.js.map +0 -1
  74. package/dist/types-BpeKGgCn.d.ts +0 -170
  75. package/src/parser.ts +0 -396
  76. package/src/printer.ts +0 -221
@@ -1,497 +1,12 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as PluginTs } from "./types-BpeKGgCn.js";
3
- import { AsyncEventEmitter, Config, FileMetaBase, Group, KubbEvents, Output, Plugin, PluginFactoryOptions, PluginManager, ResolveNameParams } from "@kubb/core";
4
- import { Fabric } from "@kubb/react-fabric";
5
- import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
6
- import { FabricReactNode } from "@kubb/react-fabric/types";
7
- import { OperationNode, SchemaNode } from "@kubb/ast/types";
8
- import { KubbFile } from "@kubb/fabric-core/types";
2
+ import { r as PluginTs } from "./types-BcyuFDn9.js";
3
+ import * as _kubb_core0 from "@kubb/core";
9
4
 
10
- //#region ../plugin-oas/src/types.d.ts
11
- type GetOasOptions = {
12
- validate?: boolean;
13
- };
14
- type Context$2 = {
15
- getOas(options?: GetOasOptions): Promise<Oas>;
16
- getBaseURL(): Promise<string | undefined>;
17
- };
18
- declare global {
19
- namespace Kubb {
20
- interface PluginContext extends Context$2 {}
21
- }
22
- }
23
- /**
24
- * `propertyName` is the ref name + resolved with the nameResolver
25
- * @example import { Pet } from './Pet'
26
- *
27
- * `originalName` is the original name used(in PascalCase), only used to remove duplicates
28
- *
29
- * `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
30
- * @example import a type(plugin-ts) for a mock file(swagger-faker)
31
- */
32
- type Ref = {
33
- propertyName: string;
34
- originalName: string;
35
- path: KubbFile.Path;
36
- pluginName?: string;
37
- };
38
- type Refs = Record<string, Ref>;
39
- type OperationSchema = {
40
- /**
41
- * Converted name, contains already `PathParams`, `QueryParams`, ...
42
- */
43
- name: string;
44
- schema: SchemaObject;
45
- operation?: Operation;
46
- /**
47
- * OperationName in PascalCase, only being used in OperationGenerator
48
- */
49
- operationName: string;
50
- description?: string;
51
- statusCode?: number;
52
- keys?: string[];
53
- keysToOmit?: string[];
54
- withData?: boolean;
55
- };
56
- type OperationSchemas = {
57
- pathParams?: OperationSchema & {
58
- keysToOmit?: never;
59
- };
60
- queryParams?: OperationSchema & {
61
- keysToOmit?: never;
62
- };
63
- headerParams?: OperationSchema & {
64
- keysToOmit?: never;
65
- };
66
- request?: OperationSchema;
67
- response: OperationSchema;
68
- responses: Array<OperationSchema>;
69
- statusCodes?: Array<OperationSchema>;
70
- errors?: Array<OperationSchema>;
71
- };
72
- type ByTag = {
73
- type: 'tag';
74
- pattern: string | RegExp;
75
- };
76
- type ByOperationId = {
77
- type: 'operationId';
78
- pattern: string | RegExp;
79
- };
80
- type ByPath = {
81
- type: 'path';
82
- pattern: string | RegExp;
83
- };
84
- type ByMethod = {
85
- type: 'method';
86
- pattern: HttpMethod | RegExp;
87
- };
88
- type BySchemaName = {
89
- type: 'schemaName';
90
- pattern: string | RegExp;
91
- };
92
- type ByContentType = {
93
- type: 'contentType';
94
- pattern: string | RegExp;
95
- };
96
- type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
97
- type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
98
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
99
- options: Partial<TOptions>;
100
- };
101
- //#endregion
102
- //#region ../plugin-oas/src/OperationGenerator.d.ts
103
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
104
- fabric: Fabric;
105
- oas: Oas;
106
- exclude: Array<Exclude> | undefined;
107
- include: Array<Include> | undefined;
108
- override: Array<Override<TOptions>> | undefined;
109
- contentType: contentType | undefined;
110
- pluginManager: PluginManager;
111
- events?: AsyncEventEmitter<KubbEvents>;
112
- /**
113
- * Current plugin
114
- */
115
- plugin: Plugin<TPluginOptions>;
116
- mode: KubbFile.Mode;
117
- UNSTABLE_NAMING?: true;
118
- };
119
- declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
120
- #private;
121
- constructor(options: TPluginOptions['resolvedOptions'], context: Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>);
122
- get options(): TPluginOptions['resolvedOptions'];
123
- set options(options: TPluginOptions['resolvedOptions']);
124
- get context(): Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>;
125
- getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']>;
126
- getSchemas(operation: Operation, {
127
- resolveName
128
- }?: {
129
- resolveName?: (name: string) => string;
130
- }): OperationSchemas;
131
- getOperations(): Promise<Array<{
132
- path: string;
133
- method: HttpMethod;
134
- operation: Operation;
135
- }>>;
136
- build(...generators: Array<Generator<TPluginOptions, Version>>): Promise<Array<KubbFile.File<TFileMeta>>>;
137
- }
138
- //#endregion
139
- //#region ../plugin-oas/src/SchemaMapper.d.ts
140
- type SchemaKeywordMapper = {
141
- object: {
142
- keyword: 'object';
143
- args: {
144
- properties: {
145
- [x: string]: Schema[];
146
- };
147
- additionalProperties: Schema[];
148
- patternProperties?: Record<string, Schema[]>;
149
- strict?: boolean;
150
- };
151
- };
152
- url: {
153
- keyword: 'url';
154
- };
155
- readOnly: {
156
- keyword: 'readOnly';
157
- };
158
- writeOnly: {
159
- keyword: 'writeOnly';
160
- };
161
- uuid: {
162
- keyword: 'uuid';
163
- };
164
- email: {
165
- keyword: 'email';
166
- };
167
- firstName: {
168
- keyword: 'firstName';
169
- };
170
- lastName: {
171
- keyword: 'lastName';
172
- };
173
- phone: {
174
- keyword: 'phone';
175
- };
176
- password: {
177
- keyword: 'password';
178
- };
179
- date: {
180
- keyword: 'date';
181
- args: {
182
- type?: 'date' | 'string';
183
- };
184
- };
185
- time: {
186
- keyword: 'time';
187
- args: {
188
- type?: 'date' | 'string';
189
- };
190
- };
191
- datetime: {
192
- keyword: 'datetime';
193
- args: {
194
- offset?: boolean;
195
- local?: boolean;
196
- };
197
- };
198
- tuple: {
199
- keyword: 'tuple';
200
- args: {
201
- items: Schema[];
202
- min?: number;
203
- max?: number;
204
- rest?: Schema;
205
- };
206
- };
207
- array: {
208
- keyword: 'array';
209
- args: {
210
- items: Schema[];
211
- min?: number;
212
- max?: number;
213
- unique?: boolean;
214
- };
215
- };
216
- enum: {
217
- keyword: 'enum';
218
- args: {
219
- name: string;
220
- typeName: string;
221
- asConst: boolean;
222
- items: Array<{
223
- name: string | number;
224
- format: 'string' | 'number' | 'boolean';
225
- value?: string | number | boolean;
226
- }>;
227
- };
228
- };
229
- and: {
230
- keyword: 'and';
231
- args: Schema[];
232
- };
233
- const: {
234
- keyword: 'const';
235
- args: {
236
- name: string | number;
237
- format: 'string' | 'number' | 'boolean';
238
- value?: string | number | boolean;
239
- };
240
- };
241
- union: {
242
- keyword: 'union';
243
- args: Schema[];
244
- };
245
- ref: {
246
- keyword: 'ref';
247
- args: {
248
- name: string;
249
- $ref: string;
250
- /**
251
- * Full qualified path.
252
- */
253
- path: KubbFile.Path;
254
- /**
255
- * When true `File.Import` is used.
256
- * When false a reference is used inside the current file.
257
- */
258
- isImportable: boolean;
259
- };
260
- };
261
- matches: {
262
- keyword: 'matches';
263
- args?: string;
264
- };
265
- boolean: {
266
- keyword: 'boolean';
267
- };
268
- default: {
269
- keyword: 'default';
270
- args: string | number | boolean;
271
- };
272
- string: {
273
- keyword: 'string';
274
- };
275
- integer: {
276
- keyword: 'integer';
277
- };
278
- bigint: {
279
- keyword: 'bigint';
280
- };
281
- number: {
282
- keyword: 'number';
283
- };
284
- max: {
285
- keyword: 'max';
286
- args: number;
287
- };
288
- min: {
289
- keyword: 'min';
290
- args: number;
291
- };
292
- exclusiveMaximum: {
293
- keyword: 'exclusiveMaximum';
294
- args: number;
295
- };
296
- exclusiveMinimum: {
297
- keyword: 'exclusiveMinimum';
298
- args: number;
299
- };
300
- describe: {
301
- keyword: 'describe';
302
- args: string;
303
- };
304
- example: {
305
- keyword: 'example';
306
- args: string;
307
- };
308
- deprecated: {
309
- keyword: 'deprecated';
310
- };
311
- optional: {
312
- keyword: 'optional';
313
- };
314
- undefined: {
315
- keyword: 'undefined';
316
- };
317
- nullish: {
318
- keyword: 'nullish';
319
- };
320
- nullable: {
321
- keyword: 'nullable';
322
- };
323
- null: {
324
- keyword: 'null';
325
- };
326
- any: {
327
- keyword: 'any';
328
- };
329
- unknown: {
330
- keyword: 'unknown';
331
- };
332
- void: {
333
- keyword: 'void';
334
- };
335
- blob: {
336
- keyword: 'blob';
337
- };
338
- schema: {
339
- keyword: 'schema';
340
- args: {
341
- type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
342
- format?: string;
343
- };
344
- };
345
- name: {
346
- keyword: 'name';
347
- args: string;
348
- };
349
- catchall: {
350
- keyword: 'catchall';
351
- };
352
- interface: {
353
- keyword: 'interface';
354
- };
355
- };
356
- type Schema = {
357
- keyword: string;
358
- } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
359
- //#endregion
360
- //#region ../plugin-oas/src/SchemaGenerator.d.ts
361
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
362
- fabric: Fabric;
363
- oas: Oas;
364
- pluginManager: PluginManager;
365
- events?: AsyncEventEmitter<KubbEvents>;
366
- /**
367
- * Current plugin
368
- */
369
- plugin: Plugin<TPluginOptions>;
370
- mode: KubbFile.Mode;
371
- include?: Array<'schemas' | 'responses' | 'requestBodies'>;
372
- override: Array<Override<TOptions>> | undefined;
373
- contentType?: contentType;
374
- output?: string;
375
- };
376
- type SchemaGeneratorOptions = {
377
- dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
378
- integerType?: 'number' | 'bigint';
379
- unknownType: 'any' | 'unknown' | 'void';
380
- emptySchemaType: 'any' | 'unknown' | 'void';
381
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
382
- enumSuffix?: string;
383
- /**
384
- * @deprecated Will be removed in v5. Use `collisionDetection: true` instead to prevent enum name collisions.
385
- * When `collisionDetection` is enabled, the rootName-based approach eliminates the need for numeric suffixes.
386
- * @internal
387
- */
388
- usedEnumNames?: Record<string, number>;
389
- mapper?: Record<string, string>;
390
- typed?: boolean;
391
- transformers: {
392
- /**
393
- * Customize the names based on the type that is provided by the plugin.
394
- */
395
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
396
- /**
397
- * Receive schema and name(propertyName) and return Schema array.
398
- * Return `undefined` to fall through to default schema generation.
399
- * @beta
400
- */
401
- schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Array<Schema> | undefined;
402
- };
403
- };
404
- type SchemaProps$1 = {
405
- schema: SchemaObject | null;
406
- name: string | null;
407
- parentName: string | null;
408
- rootName?: string | null;
409
- };
410
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
411
- #private;
412
- constructor(options: TOptions, context: Context<TOptions, TPluginOptions>);
413
- get options(): TOptions;
414
- set options(options: TOptions);
415
- get context(): Context<TOptions, TPluginOptions>;
416
- refs: Refs;
417
- /**
418
- * Creates a type node from a given schema.
419
- * Delegates to getBaseTypeFromSchema internally and
420
- * optionally adds a union with null.
421
- */
422
- parse(props: SchemaProps$1): Schema[];
423
- static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
424
- static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
425
- static combineObjects(tree: Schema[] | undefined): Schema[];
426
- build(...generators: Array<Generator<TPluginOptions, Version>>): Promise<Array<KubbFile.File<TFileMeta>>>;
427
- }
428
- //#endregion
429
- //#region ../plugin-oas/src/generators/createGenerator.d.ts
430
- type CoreGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
431
- name: string;
432
- type: 'core';
433
- version: TVersion;
434
- operations: (props: OperationsProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
435
- operation: (props: OperationProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
436
- schema: (props: SchemaProps<TOptions, TVersion>) => Promise<KubbFile.File[]>;
437
- };
438
- //#endregion
439
- //#region ../plugin-oas/src/generators/types.d.ts
440
- type Version = '1' | '2';
441
- type OperationsV1Props<TOptions extends PluginFactoryOptions> = {
442
- config: Config;
443
- generator: Omit<OperationGenerator<TOptions>, 'build'>;
444
- plugin: Plugin<TOptions>;
445
- operations: Array<Operation>;
446
- };
447
- type OperationsV2Props<TOptions extends PluginFactoryOptions> = {
448
- config: Config;
449
- plugin: Plugin<TOptions>;
450
- nodes: Array<OperationNode>;
451
- };
452
- type OperationV1Props<TOptions extends PluginFactoryOptions> = {
453
- config: Config;
454
- generator: Omit<OperationGenerator<TOptions>, 'build'>;
455
- plugin: Plugin<TOptions>;
456
- operation: Operation;
457
- };
458
- type OperationV2Props<TOptions extends PluginFactoryOptions> = {
459
- config: Config;
460
- plugin: Plugin<TOptions>;
461
- node: OperationNode;
462
- };
463
- type OperationsProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationsV2Props<TOptions> : OperationsV1Props<TOptions>;
464
- type OperationProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? OperationV2Props<TOptions> : OperationV1Props<TOptions>;
465
- type SchemaV1Props<TOptions extends PluginFactoryOptions> = {
466
- config: Config;
467
- generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
468
- plugin: Plugin<TOptions>;
469
- schema: {
470
- name: string;
471
- tree: Array<Schema>;
472
- value: SchemaObject;
473
- };
474
- };
475
- type SchemaV2Props<TOptions extends PluginFactoryOptions> = {
476
- config: Config;
477
- plugin: Plugin<TOptions>;
478
- node: SchemaNode;
479
- };
480
- type SchemaProps<TOptions extends PluginFactoryOptions, TVersion extends Version = '1'> = TVersion extends '2' ? SchemaV2Props<TOptions> : SchemaV1Props<TOptions>;
481
- type Generator<TOptions extends PluginFactoryOptions, TVersion extends Version = Version> = CoreGenerator<TOptions, TVersion> | ReactGenerator<TOptions, TVersion>;
482
- //#endregion
483
- //#region ../plugin-oas/src/generators/createReactGenerator.d.ts
484
- type ReactGenerator<TOptions extends PluginFactoryOptions, TVersion extends Version> = {
485
- name: string;
486
- type: 'react';
487
- version: TVersion;
488
- Operations: (props: OperationsProps<TOptions, TVersion>) => FabricReactNode;
489
- Operation: (props: OperationProps<TOptions, TVersion>) => FabricReactNode;
490
- Schema: (props: SchemaProps<TOptions, TVersion>) => FabricReactNode;
491
- };
492
- //#endregion
493
5
  //#region src/generators/typeGenerator.d.ts
494
- declare const typeGenerator: ReactGenerator<PluginTs, "1">;
6
+ declare const typeGenerator: _kubb_core0.ReactGeneratorV2<PluginTs>;
7
+ //#endregion
8
+ //#region src/generators/typeGeneratorLegacy.d.ts
9
+ declare const typeGeneratorLegacy: _kubb_core0.ReactGeneratorV2<PluginTs>;
495
10
  //#endregion
496
- export { typeGenerator };
11
+ export { typeGenerator, typeGeneratorLegacy };
497
12
  //# sourceMappingURL=generators.d.ts.map
@@ -1,2 +1,2 @@
1
- import { r as typeGenerator } from "./plugin-DoLrDl9P.js";
2
- export { typeGenerator };
1
+ import { n as typeGenerator, t as typeGeneratorLegacy } from "./generators-ByK18qUn.js";
2
+ export { typeGenerator, typeGeneratorLegacy };
package/dist/index.cjs CHANGED
@@ -1,4 +1,149 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_plugin = require("./plugin-CNkzbtpl.cjs");
3
- exports.pluginTs = require_plugin.pluginTs;
4
- exports.pluginTsName = require_plugin.pluginTsName;
2
+ const require_chunk = require("./chunk-ByKO4r7w.cjs");
3
+ const require_generators = require("./generators-aSsiTfUO.cjs");
4
+ const require_resolverTsLegacy = require("./resolverTsLegacy-sJ16Iqrl.cjs");
5
+ let node_path = require("node:path");
6
+ node_path = require_chunk.__toESM(node_path);
7
+ let _kubb_ast = require("@kubb/ast");
8
+ let _kubb_core = require("@kubb/core");
9
+ //#region src/presets.ts
10
+ const presets = (0, _kubb_core.definePresets)({
11
+ default: (0, _kubb_core.definePreset)("default", {
12
+ resolvers: [require_resolverTsLegacy.resolverTs],
13
+ generators: [require_generators.typeGenerator]
14
+ }),
15
+ kubbV4: (0, _kubb_core.definePreset)("kubbV4", {
16
+ resolvers: [require_resolverTsLegacy.resolverTsLegacy],
17
+ generators: [require_generators.typeGeneratorLegacy]
18
+ })
19
+ });
20
+ function getPreset(preset, { resolvers, transformers, generators }) {
21
+ return (0, _kubb_core.getPreset)({
22
+ preset,
23
+ presets,
24
+ resolvers: [require_resolverTsLegacy.resolverTs, ...resolvers ?? []],
25
+ transformers,
26
+ generators
27
+ });
28
+ }
29
+ //#endregion
30
+ //#region src/plugin.ts
31
+ const pluginTsName = "plugin-ts";
32
+ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
33
+ const { output = {
34
+ path: "types",
35
+ barrelType: "named"
36
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", paramsCasing, compatibilityPreset = "default", resolvers: userResolvers = [], transformers: userTransformers = [], generators: userGenerators = [] } = options;
37
+ const { resolver, transformers, generators } = getPreset(compatibilityPreset, {
38
+ resolvers: userResolvers,
39
+ transformers: userTransformers,
40
+ generators: userGenerators
41
+ });
42
+ let resolveNameWarning = false;
43
+ let resolvePathWarning = false;
44
+ return {
45
+ name: pluginTsName,
46
+ options: {
47
+ output,
48
+ optionalType,
49
+ group,
50
+ arrayType,
51
+ enumType,
52
+ enumKeyCasing,
53
+ syntaxType,
54
+ paramsCasing,
55
+ resolver,
56
+ transformers
57
+ },
58
+ resolvePath(baseName, pathMode, options) {
59
+ if (!resolvePathWarning) {
60
+ this.driver.events.emit("warn", "Do not use resolvePath for pluginTs, use resolverTs.resolvePath instead");
61
+ resolvePathWarning = true;
62
+ }
63
+ return resolver.resolvePath({
64
+ baseName,
65
+ pathMode,
66
+ tag: options?.group?.tag,
67
+ path: options?.group?.path
68
+ }, {
69
+ root: node_path.default.resolve(this.config.root, this.config.output.path),
70
+ output,
71
+ group
72
+ });
73
+ },
74
+ resolveName(name, type) {
75
+ if (!resolveNameWarning) {
76
+ this.driver.events.emit("warn", "Do not use resolveName for pluginTs, use resolverTs.default instead");
77
+ resolveNameWarning = true;
78
+ }
79
+ return resolver.default(name, type);
80
+ },
81
+ async install() {
82
+ const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this;
83
+ const root = node_path.default.resolve(config.root, config.output.path);
84
+ if (!adapter) throw new Error("Plugin cannot work without adapter being set");
85
+ await openInStudio({ ast: true });
86
+ await (0, _kubb_ast.walk)(rootNode, {
87
+ depth: "shallow",
88
+ async schema(schemaNode) {
89
+ const writeTasks = generators.map(async (generator) => {
90
+ if (generator.type === "react" && generator.version === "2") {
91
+ const options = resolver.resolveOptions(schemaNode, {
92
+ options: plugin.options,
93
+ exclude,
94
+ include,
95
+ override
96
+ });
97
+ if (options === null) return;
98
+ await (0, _kubb_core.renderSchema)(schemaNode, {
99
+ options,
100
+ adapter,
101
+ config,
102
+ fabric,
103
+ Component: generator.Schema,
104
+ plugin,
105
+ driver
106
+ });
107
+ }
108
+ });
109
+ await Promise.all(writeTasks);
110
+ },
111
+ async operation(operationNode) {
112
+ const writeTasks = generators.map(async (generator) => {
113
+ if (generator.type === "react" && generator.version === "2") {
114
+ const options = resolver.resolveOptions(operationNode, {
115
+ options: plugin.options,
116
+ exclude,
117
+ include,
118
+ override
119
+ });
120
+ if (options === null) return;
121
+ await (0, _kubb_core.renderOperation)(operationNode, {
122
+ options,
123
+ adapter,
124
+ config,
125
+ fabric,
126
+ Component: generator.Operation,
127
+ plugin,
128
+ driver
129
+ });
130
+ }
131
+ });
132
+ await Promise.all(writeTasks);
133
+ }
134
+ });
135
+ const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
136
+ type: output.barrelType ?? "named",
137
+ root,
138
+ output,
139
+ meta: { pluginName: this.plugin.name }
140
+ });
141
+ await this.upsertFile(...barrelFiles);
142
+ }
143
+ };
144
+ });
145
+ //#endregion
146
+ exports.pluginTs = pluginTs;
147
+ exports.pluginTsName = pluginTsName;
148
+
149
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["resolverTs","typeGenerator","resolverTsLegacy","typeGeneratorLegacy","path"],"sources":["../src/presets.ts","../src/plugin.ts"],"sourcesContent":["import type { Visitor } from '@kubb/ast/types'\nimport { type CompatibilityPreset, definePreset, definePresets, type Generator, getPreset as getCorePreset } from '@kubb/core'\nimport { typeGenerator, typeGeneratorLegacy } from './generators/index.ts'\nimport { resolverTs, resolverTsLegacy } from './resolvers/index.ts'\nimport type { PluginTs, ResolverTs } from './types.ts'\n\nexport const presets = definePresets<ResolverTs>({\n default: definePreset('default', { resolvers: [resolverTs], generators: [typeGenerator] }),\n kubbV4: definePreset('kubbV4', { resolvers: [resolverTsLegacy], generators: [typeGeneratorLegacy] }),\n})\n\ntype GetPresetOptions = {\n resolvers: Array<ResolverTs>\n transformers: Array<Visitor>\n generators: Array<Generator<PluginTs>>\n}\n\nexport function getPreset(preset: CompatibilityPreset, { resolvers, transformers, generators }: GetPresetOptions) {\n return getCorePreset({\n preset,\n presets,\n resolvers: [resolverTs, ...(resolvers ?? [])],\n transformers,\n generators,\n })\n}\n","import path from 'node:path'\nimport { walk } from '@kubb/ast'\nimport { createPlugin, getBarrelFiles, renderOperation, renderSchema } from '@kubb/core'\nimport { getPreset } from './presets.ts'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = createPlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumKeyCasing = 'none',\n optionalType = 'questionToken',\n arrayType = 'array',\n syntaxType = 'type',\n paramsCasing,\n compatibilityPreset = 'default',\n resolvers: userResolvers = [],\n transformers: userTransformers = [],\n generators: userGenerators = [],\n } = options\n\n const { resolver, transformers, generators } = getPreset(compatibilityPreset, {\n resolvers: userResolvers,\n transformers: userTransformers,\n generators: userGenerators,\n })\n\n let resolveNameWarning = false\n let resolvePathWarning = false\n\n return {\n name: pluginTsName,\n options: {\n output,\n optionalType,\n group,\n arrayType,\n enumType,\n enumKeyCasing,\n syntaxType,\n paramsCasing,\n resolver,\n transformers,\n },\n resolvePath(baseName, pathMode, options) {\n if (!resolvePathWarning) {\n this.driver.events.emit('warn', 'Do not use resolvePath for pluginTs, use resolverTs.resolvePath instead')\n resolvePathWarning = true\n }\n\n return resolver.resolvePath(\n { baseName, pathMode, tag: options?.group?.tag, path: options?.group?.path },\n { root: path.resolve(this.config.root, this.config.output.path), output, group },\n )\n },\n resolveName(name, type) {\n if (!resolveNameWarning) {\n this.driver.events.emit('warn', 'Do not use resolveName for pluginTs, use resolverTs.default instead')\n resolveNameWarning = true\n }\n\n return resolver.default(name, type)\n },\n async install() {\n const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this\n\n const root = path.resolve(config.root, config.output.path)\n\n if (!adapter) {\n throw new Error('Plugin cannot work without adapter being set')\n }\n\n await openInStudio({ ast: true })\n\n await walk(rootNode, {\n depth: 'shallow',\n async schema(schemaNode) {\n const writeTasks = generators.map(async (generator) => {\n if (generator.type === 'react' && generator.version === '2') {\n const options = resolver.resolveOptions(schemaNode, { options: plugin.options, exclude, include, override })\n\n if (options === null) {\n return\n }\n\n await renderSchema(schemaNode, {\n options,\n adapter,\n config,\n fabric,\n Component: generator.Schema,\n plugin,\n driver,\n })\n }\n })\n\n await Promise.all(writeTasks)\n },\n async operation(operationNode) {\n const writeTasks = generators.map(async (generator) => {\n if (generator.type === 'react' && generator.version === '2') {\n const options = resolver.resolveOptions(operationNode, { options: plugin.options, exclude, include, override })\n\n if (options === null) {\n return\n }\n\n await renderOperation(operationNode, {\n options,\n adapter,\n config,\n fabric,\n Component: generator.Operation,\n plugin,\n driver,\n })\n }\n })\n\n await Promise.all(writeTasks)\n },\n })\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":"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"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as PluginTs, t as Options } from "./types-BpeKGgCn.js";
2
+ import { n as Options, r as PluginTs } from "./types-BcyuFDn9.js";
3
3
  import * as _kubb_core0 from "@kubb/core";
4
4
 
5
5
  //#region src/plugin.d.ts