@kubb/plugin-ts 5.0.0-alpha.11 → 5.0.0-alpha.13

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 (57) hide show
  1. package/dist/Type-C8EHVKjc.js +663 -0
  2. package/dist/Type-C8EHVKjc.js.map +1 -0
  3. package/dist/Type-DrOq6-nh.cjs +680 -0
  4. package/dist/Type-DrOq6-nh.cjs.map +1 -0
  5. package/dist/casing-Cp-jbC_k.js +84 -0
  6. package/dist/casing-Cp-jbC_k.js.map +1 -0
  7. package/dist/casing-D2uQKLWS.cjs +144 -0
  8. package/dist/casing-D2uQKLWS.cjs.map +1 -0
  9. package/dist/components.cjs +3 -2
  10. package/dist/components.d.ts +41 -9
  11. package/dist/components.js +2 -2
  12. package/dist/generators-CX3cSSdF.cjs +551 -0
  13. package/dist/generators-CX3cSSdF.cjs.map +1 -0
  14. package/dist/generators-dCqW0ECC.js +547 -0
  15. package/dist/generators-dCqW0ECC.js.map +1 -0
  16. package/dist/generators.cjs +2 -3
  17. package/dist/generators.d.ts +3 -503
  18. package/dist/generators.js +2 -2
  19. package/dist/index.cjs +135 -4
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.ts +2 -41
  22. package/dist/index.js +134 -2
  23. package/dist/index.js.map +1 -0
  24. package/dist/resolvers-CH7hINyz.js +181 -0
  25. package/dist/resolvers-CH7hINyz.js.map +1 -0
  26. package/dist/resolvers-ebHaaCyw.cjs +191 -0
  27. package/dist/resolvers-ebHaaCyw.cjs.map +1 -0
  28. package/dist/resolvers.cjs +4 -0
  29. package/dist/resolvers.d.ts +51 -0
  30. package/dist/resolvers.js +2 -0
  31. package/dist/{types-mSXmB8WU.d.ts → types-BSRhtbGl.d.ts} +80 -57
  32. package/package.json +12 -5
  33. package/src/components/{v2/Enum.tsx → Enum.tsx} +27 -11
  34. package/src/components/Type.tsx +24 -141
  35. package/src/components/index.ts +1 -0
  36. package/src/generators/index.ts +0 -1
  37. package/src/generators/typeGenerator.tsx +204 -413
  38. package/src/generators/utils.ts +300 -0
  39. package/src/index.ts +0 -1
  40. package/src/plugin.ts +81 -126
  41. package/src/printer.ts +20 -6
  42. package/src/resolvers/index.ts +2 -0
  43. package/src/{resolverTs.ts → resolvers/resolverTs.ts} +26 -2
  44. package/src/resolvers/resolverTsLegacy.ts +85 -0
  45. package/src/types.ts +75 -52
  46. package/dist/components-CRu8IKY3.js +0 -729
  47. package/dist/components-CRu8IKY3.js.map +0 -1
  48. package/dist/components-DeNDKlzf.cjs +0 -982
  49. package/dist/components-DeNDKlzf.cjs.map +0 -1
  50. package/dist/plugin-CJ29AwE2.cjs +0 -1320
  51. package/dist/plugin-CJ29AwE2.cjs.map +0 -1
  52. package/dist/plugin-D60XNJSD.js +0 -1267
  53. package/dist/plugin-D60XNJSD.js.map +0 -1
  54. package/src/components/v2/Type.tsx +0 -59
  55. package/src/generators/v2/typeGenerator.tsx +0 -167
  56. package/src/generators/v2/utils.ts +0 -140
  57. package/src/parser.ts +0 -389
@@ -1,509 +1,9 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as PluginTs } from "./types-mSXmB8WU.js";
2
+ import { n as PluginTs } from "./types-BSRhtbGl.js";
3
3
  import * as _kubb_core0 from "@kubb/core";
4
- import { Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
5
- import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
6
- import { FabricReactNode } from "@kubb/react-fabric/types";
7
- import { Fabric, KubbFile } from "@kubb/fabric-core/types";
8
4
 
9
- //#region ../../internals/utils/src/asyncEventEmitter.d.ts
10
- /** A function that can be registered as an event listener, synchronous or async. */
11
- type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
12
- /**
13
- * A typed EventEmitter that awaits all async listeners before resolving.
14
- * Wraps Node's `EventEmitter` with full TypeScript event-map inference.
15
- */
16
- declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
17
- #private;
18
- /**
19
- * `maxListener` controls the maximum number of listeners per event before Node emits a memory-leak warning.
20
- * @default 10
21
- */
22
- constructor(maxListener?: number);
23
- /**
24
- * Emits an event and awaits all registered listeners in parallel.
25
- * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
26
- */
27
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
28
- /** Registers a persistent listener for the given event. */
29
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
30
- /** Registers a one-shot listener that removes itself after the first invocation. */
31
- onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
32
- /** Removes a previously registered listener. */
33
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
34
- /** Removes all listeners from every event channel. */
35
- removeAll(): void;
36
- }
37
- //#endregion
38
- //#region ../plugin-oas/src/types.d.ts
39
- type GetOasOptions = {
40
- validate?: boolean;
41
- };
42
- type Context$2 = {
43
- getOas(options?: GetOasOptions): Promise<Oas>;
44
- getBaseURL(): Promise<string | undefined>;
45
- };
46
- declare global {
47
- namespace Kubb {
48
- interface PluginContext extends Context$2 {}
49
- }
50
- }
51
- /**
52
- * `propertyName` is the ref name + resolved with the nameResolver
53
- * @example import { Pet } from './Pet'
54
- *
55
- * `originalName` is the original name used(in PascalCase), only used to remove duplicates
56
- *
57
- * `pluginName` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
58
- * @example import a type(plugin-ts) for a mock file(swagger-faker)
59
- */
60
- type Ref = {
61
- propertyName: string;
62
- originalName: string;
63
- path: KubbFile.Path;
64
- pluginName?: string;
65
- };
66
- type Refs = Record<string, Ref>;
67
- type OperationSchema = {
68
- /**
69
- * Converted name, contains already `PathParams`, `QueryParams`, ...
70
- */
71
- name: string;
72
- schema: SchemaObject;
73
- operation?: Operation;
74
- /**
75
- * OperationName in PascalCase, only being used in OperationGenerator
76
- */
77
- operationName: string;
78
- description?: string;
79
- statusCode?: number;
80
- keys?: string[];
81
- keysToOmit?: string[];
82
- withData?: boolean;
83
- };
84
- type OperationSchemas = {
85
- pathParams?: OperationSchema & {
86
- keysToOmit?: never;
87
- };
88
- queryParams?: OperationSchema & {
89
- keysToOmit?: never;
90
- };
91
- headerParams?: OperationSchema & {
92
- keysToOmit?: never;
93
- };
94
- request?: OperationSchema;
95
- response: OperationSchema;
96
- responses: Array<OperationSchema>;
97
- statusCodes?: Array<OperationSchema>;
98
- errors?: Array<OperationSchema>;
99
- };
100
- type ByTag = {
101
- type: 'tag';
102
- pattern: string | RegExp;
103
- };
104
- type ByOperationId = {
105
- type: 'operationId';
106
- pattern: string | RegExp;
107
- };
108
- type ByPath = {
109
- type: 'path';
110
- pattern: string | RegExp;
111
- };
112
- type ByMethod = {
113
- type: 'method';
114
- pattern: HttpMethod | RegExp;
115
- };
116
- type BySchemaName = {
117
- type: 'schemaName';
118
- pattern: string | RegExp;
119
- };
120
- type ByContentType = {
121
- type: 'contentType';
122
- pattern: string | RegExp;
123
- };
124
- type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
125
- type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
126
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
127
- options: Partial<TOptions>;
128
- };
129
- //#endregion
130
- //#region ../plugin-oas/src/OperationGenerator.d.ts
131
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
132
- fabric: Fabric;
133
- oas: Oas;
134
- exclude: Array<Exclude> | undefined;
135
- include: Array<Include> | undefined;
136
- override: Array<Override<TOptions>> | undefined;
137
- contentType: contentType | undefined;
138
- driver: PluginDriver;
139
- events?: AsyncEventEmitter<KubbEvents>;
140
- /**
141
- * Current plugin
142
- */
143
- plugin: Plugin<TPluginOptions>;
144
- mode: KubbFile.Mode;
145
- UNSTABLE_NAMING?: true;
146
- };
147
- declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
148
- #private;
149
- constructor(options: TPluginOptions['resolvedOptions'], context: Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>);
150
- get options(): TPluginOptions['resolvedOptions'];
151
- set options(options: TPluginOptions['resolvedOptions']);
152
- get context(): Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>;
153
- getOptions(operation: Operation, method: HttpMethod): Partial<TPluginOptions['resolvedOptions']>;
154
- getSchemas(operation: Operation, {
155
- resolveName
156
- }?: {
157
- resolveName?: (name: string) => string;
158
- }): OperationSchemas;
159
- getOperations(): Promise<Array<{
160
- path: string;
161
- method: HttpMethod;
162
- operation: Operation;
163
- }>>;
164
- build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
165
- }
166
- //#endregion
167
- //#region ../plugin-oas/src/SchemaMapper.d.ts
168
- type SchemaKeywordMapper = {
169
- object: {
170
- keyword: 'object';
171
- args: {
172
- properties: {
173
- [x: string]: Schema[];
174
- };
175
- additionalProperties: Schema[];
176
- patternProperties?: Record<string, Schema[]>;
177
- strict?: boolean;
178
- };
179
- };
180
- url: {
181
- keyword: 'url';
182
- };
183
- readOnly: {
184
- keyword: 'readOnly';
185
- };
186
- writeOnly: {
187
- keyword: 'writeOnly';
188
- };
189
- uuid: {
190
- keyword: 'uuid';
191
- };
192
- email: {
193
- keyword: 'email';
194
- };
195
- firstName: {
196
- keyword: 'firstName';
197
- };
198
- lastName: {
199
- keyword: 'lastName';
200
- };
201
- phone: {
202
- keyword: 'phone';
203
- };
204
- password: {
205
- keyword: 'password';
206
- };
207
- date: {
208
- keyword: 'date';
209
- args: {
210
- type?: 'date' | 'string';
211
- };
212
- };
213
- time: {
214
- keyword: 'time';
215
- args: {
216
- type?: 'date' | 'string';
217
- };
218
- };
219
- datetime: {
220
- keyword: 'datetime';
221
- args: {
222
- offset?: boolean;
223
- local?: boolean;
224
- };
225
- };
226
- tuple: {
227
- keyword: 'tuple';
228
- args: {
229
- items: Schema[];
230
- min?: number;
231
- max?: number;
232
- rest?: Schema;
233
- };
234
- };
235
- array: {
236
- keyword: 'array';
237
- args: {
238
- items: Schema[];
239
- min?: number;
240
- max?: number;
241
- unique?: boolean;
242
- };
243
- };
244
- enum: {
245
- keyword: 'enum';
246
- args: {
247
- name: string;
248
- typeName: string;
249
- asConst: boolean;
250
- items: Array<{
251
- name: string | number;
252
- format: 'string' | 'number' | 'boolean';
253
- value?: string | number | boolean;
254
- }>;
255
- };
256
- };
257
- and: {
258
- keyword: 'and';
259
- args: Schema[];
260
- };
261
- const: {
262
- keyword: 'const';
263
- args: {
264
- name: string | number;
265
- format: 'string' | 'number' | 'boolean';
266
- value?: string | number | boolean;
267
- };
268
- };
269
- union: {
270
- keyword: 'union';
271
- args: Schema[];
272
- };
273
- ref: {
274
- keyword: 'ref';
275
- args: {
276
- name: string;
277
- $ref: string;
278
- /**
279
- * Full qualified path.
280
- */
281
- path: KubbFile.Path;
282
- /**
283
- * When true `File.Import` is used.
284
- * When false a reference is used inside the current file.
285
- */
286
- isImportable: boolean;
287
- };
288
- };
289
- matches: {
290
- keyword: 'matches';
291
- args?: string;
292
- };
293
- boolean: {
294
- keyword: 'boolean';
295
- };
296
- default: {
297
- keyword: 'default';
298
- args: string | number | boolean;
299
- };
300
- string: {
301
- keyword: 'string';
302
- };
303
- integer: {
304
- keyword: 'integer';
305
- };
306
- bigint: {
307
- keyword: 'bigint';
308
- };
309
- number: {
310
- keyword: 'number';
311
- };
312
- max: {
313
- keyword: 'max';
314
- args: number;
315
- };
316
- min: {
317
- keyword: 'min';
318
- args: number;
319
- };
320
- exclusiveMaximum: {
321
- keyword: 'exclusiveMaximum';
322
- args: number;
323
- };
324
- exclusiveMinimum: {
325
- keyword: 'exclusiveMinimum';
326
- args: number;
327
- };
328
- describe: {
329
- keyword: 'describe';
330
- args: string;
331
- };
332
- example: {
333
- keyword: 'example';
334
- args: string;
335
- };
336
- deprecated: {
337
- keyword: 'deprecated';
338
- };
339
- optional: {
340
- keyword: 'optional';
341
- };
342
- undefined: {
343
- keyword: 'undefined';
344
- };
345
- nullish: {
346
- keyword: 'nullish';
347
- };
348
- nullable: {
349
- keyword: 'nullable';
350
- };
351
- null: {
352
- keyword: 'null';
353
- };
354
- any: {
355
- keyword: 'any';
356
- };
357
- unknown: {
358
- keyword: 'unknown';
359
- };
360
- void: {
361
- keyword: 'void';
362
- };
363
- blob: {
364
- keyword: 'blob';
365
- };
366
- schema: {
367
- keyword: 'schema';
368
- args: {
369
- type: 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object';
370
- format?: string;
371
- };
372
- };
373
- name: {
374
- keyword: 'name';
375
- args: string;
376
- };
377
- catchall: {
378
- keyword: 'catchall';
379
- };
380
- interface: {
381
- keyword: 'interface';
382
- };
383
- };
384
- type Schema = {
385
- keyword: string;
386
- } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
387
- //#endregion
388
- //#region ../plugin-oas/src/SchemaGenerator.d.ts
389
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
390
- fabric: Fabric;
391
- oas: Oas;
392
- driver: PluginDriver;
393
- events?: AsyncEventEmitter<KubbEvents>;
394
- /**
395
- * Current plugin
396
- */
397
- plugin: Plugin<TPluginOptions>;
398
- mode: KubbFile.Mode;
399
- include?: Array<'schemas' | 'responses' | 'requestBodies'>;
400
- override: Array<Override<TOptions>> | undefined;
401
- contentType?: contentType;
402
- output?: string;
403
- };
404
- type SchemaGeneratorOptions = {
405
- dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
406
- integerType?: 'number' | 'bigint';
407
- unknownType: 'any' | 'unknown' | 'void';
408
- emptySchemaType: 'any' | 'unknown' | 'void';
409
- enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
410
- enumSuffix?: string;
411
- /**
412
- * @deprecated Will be removed in v5. Use `collisionDetection: true` instead to prevent enum name collisions.
413
- * When `collisionDetection` is enabled, the rootName-based approach eliminates the need for numeric suffixes.
414
- * @internal
415
- */
416
- usedEnumNames?: Record<string, number>;
417
- mapper?: Record<string, string>;
418
- typed?: boolean;
419
- transformers: {
420
- /**
421
- * Customize the names based on the type that is provided by the plugin.
422
- */
423
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
424
- /**
425
- * Receive schema and name(propertyName) and return Schema array.
426
- * Return `undefined` to fall through to default schema generation.
427
- * @beta
428
- */
429
- schema?: (schemaProps: SchemaProps$1, defaultSchemas: Schema[]) => Array<Schema> | undefined;
430
- };
431
- };
432
- type SchemaProps$1 = {
433
- schema: SchemaObject | null;
434
- name: string | null;
435
- parentName: string | null;
436
- rootName?: string | null;
437
- };
438
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> {
439
- #private;
440
- constructor(options: TOptions, context: Context<TOptions, TPluginOptions>);
441
- get options(): TOptions;
442
- set options(options: TOptions);
443
- get context(): Context<TOptions, TPluginOptions>;
444
- refs: Refs;
445
- /**
446
- * Creates a type node from a given schema.
447
- * Delegates to getBaseTypeFromSchema internally and
448
- * optionally adds a union with null.
449
- */
450
- parse(props: SchemaProps$1): Schema[];
451
- static deepSearch<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): Array<SchemaKeywordMapper[T]>;
452
- static find<T extends keyof SchemaKeywordMapper>(tree: Schema[] | undefined, keyword: T): SchemaKeywordMapper[T] | undefined;
453
- static combineObjects(tree: Schema[] | undefined): Schema[];
454
- build(...generators: Array<Generator$1<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
455
- }
456
- //#endregion
457
- //#region ../plugin-oas/src/generators/createGenerator.d.ts
458
- type CoreGenerator<TOptions extends PluginFactoryOptions> = {
459
- name: string;
460
- type: 'core';
461
- version: '1';
462
- operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
463
- operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
464
- schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
465
- };
466
- //#endregion
467
- //#region ../plugin-oas/src/generators/types.d.ts
468
- type OperationsProps<TOptions extends PluginFactoryOptions> = {
469
- config: Config;
470
- generator: Omit<OperationGenerator<TOptions>, 'build'>;
471
- plugin: Plugin<TOptions>;
472
- operations: Array<Operation>;
473
- };
474
- type OperationProps<TOptions extends PluginFactoryOptions> = {
475
- config: Config;
476
- generator: Omit<OperationGenerator<TOptions>, 'build'>;
477
- plugin: Plugin<TOptions>;
478
- operation: Operation;
479
- };
480
- type SchemaProps<TOptions extends PluginFactoryOptions> = {
481
- config: Config;
482
- generator: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
483
- plugin: Plugin<TOptions>;
484
- schema: {
485
- name: string;
486
- tree: Array<Schema>;
487
- value: SchemaObject;
488
- };
489
- };
490
- type Generator$1<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions> | Generator<TOptions>;
491
- //#endregion
492
- //#region ../plugin-oas/src/generators/createReactGenerator.d.ts
493
- type ReactGenerator<TOptions extends PluginFactoryOptions> = {
494
- name: string;
495
- type: 'react';
496
- version: '1';
497
- Operations: (props: OperationsProps<TOptions>) => FabricReactNode;
498
- Operation: (props: OperationProps<TOptions>) => FabricReactNode;
499
- Schema: (props: SchemaProps<TOptions>) => FabricReactNode;
500
- };
501
- //#endregion
502
5
  //#region src/generators/typeGenerator.d.ts
503
- declare const typeGenerator: ReactGenerator<PluginTs>;
504
- //#endregion
505
- //#region src/generators/v2/typeGenerator.d.ts
506
- declare const typeGenerator$1: _kubb_core0.ReactGeneratorV2<PluginTs>;
6
+ declare const typeGenerator: _kubb_core0.ReactGeneratorV2<PluginTs>;
507
7
  //#endregion
508
- export { typeGenerator, typeGenerator$1 as typeGeneratorV2 };
8
+ export { typeGenerator };
509
9
  //# sourceMappingURL=generators.d.ts.map
@@ -1,2 +1,2 @@
1
- import { a as typeGenerator, r as typeGenerator$1 } from "./plugin-D60XNJSD.js";
2
- export { typeGenerator, typeGenerator$1 as typeGeneratorV2 };
1
+ import { t as typeGenerator } from "./generators-dCqW0ECC.js";
2
+ export { typeGenerator };
package/dist/index.cjs CHANGED
@@ -1,5 +1,136 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_plugin = require("./plugin-CJ29AwE2.cjs");
3
- exports.pluginTs = require_plugin.pluginTs;
4
- exports.pluginTsName = require_plugin.pluginTsName;
5
- exports.resolverTs = require_plugin.resolverTs;
2
+ const require_casing = require("./casing-D2uQKLWS.cjs");
3
+ const require_generators = require("./generators-CX3cSSdF.cjs");
4
+ const require_resolvers = require("./resolvers-ebHaaCyw.cjs");
5
+ let node_path = require("node:path");
6
+ node_path = require_casing.__toESM(node_path);
7
+ let _kubb_ast = require("@kubb/ast");
8
+ let _kubb_core = require("@kubb/core");
9
+ //#region src/plugin.ts
10
+ const pluginTsName = "plugin-ts";
11
+ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
12
+ const { output = {
13
+ path: "types",
14
+ barrelType: "named"
15
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", transformers = {}, paramsCasing, generators = [require_generators.typeGenerator].filter(Boolean), legacy = false } = options;
16
+ const baseResolver = legacy ? require_resolvers.resolverTsLegacy : require_resolvers.resolverTs;
17
+ const resolver = transformers?.name ? {
18
+ ...baseResolver,
19
+ default(name, type) {
20
+ const resolved = baseResolver.default(name, type);
21
+ return transformers.name(resolved, type) || resolved;
22
+ }
23
+ } : baseResolver;
24
+ let resolveNameWarning = false;
25
+ return {
26
+ name: pluginTsName,
27
+ options: {
28
+ output,
29
+ transformers,
30
+ optionalType,
31
+ arrayType,
32
+ enumType,
33
+ enumKeyCasing,
34
+ syntaxType,
35
+ group,
36
+ override,
37
+ paramsCasing,
38
+ legacy,
39
+ resolver,
40
+ baseResolver
41
+ },
42
+ resolvePath(baseName, pathMode, options) {
43
+ const root = node_path.default.resolve(this.config.root, this.config.output.path);
44
+ if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
45
+ /**
46
+ * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
47
+ * Other plugins then need to call addOrAppend instead of just add from the fileManager class
48
+ */
49
+ return node_path.default.resolve(root, output.path);
50
+ if (group && (options?.group?.path || options?.group?.tag)) {
51
+ const groupName = group?.name ? group.name : (ctx) => {
52
+ if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
53
+ return `${require_casing.camelCase(ctx.group)}Controller`;
54
+ };
55
+ return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
56
+ }
57
+ return node_path.default.resolve(root, output.path, baseName);
58
+ },
59
+ resolveName(name, type) {
60
+ if (!resolveNameWarning) {
61
+ this.driver.events.emit("warn", "Do not use resolveName for pluginTs, use resolverTs instead");
62
+ resolveNameWarning = true;
63
+ }
64
+ return resolver.default(name, type);
65
+ },
66
+ async install() {
67
+ const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this;
68
+ const root = node_path.default.resolve(config.root, config.output.path);
69
+ const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
70
+ if (!adapter) throw new Error("Plugin cannot work without adapter being set");
71
+ await openInStudio({ ast: true });
72
+ await (0, _kubb_ast.walk)(rootNode, {
73
+ async schema(schemaNode) {
74
+ const writeTasks = generators.map(async (generator) => {
75
+ if (generator.type === "react" && generator.version === "2") {
76
+ const options = resolver.resolveOptions(schemaNode, {
77
+ options: plugin.options,
78
+ exclude,
79
+ include,
80
+ override
81
+ });
82
+ if (options === null) return;
83
+ await (0, _kubb_core.renderSchema)(schemaNode, {
84
+ options,
85
+ adapter,
86
+ config,
87
+ fabric,
88
+ Component: generator.Schema,
89
+ plugin,
90
+ driver,
91
+ mode
92
+ });
93
+ }
94
+ });
95
+ await Promise.all(writeTasks);
96
+ },
97
+ async operation(operationNode) {
98
+ const writeTasks = generators.map(async (generator) => {
99
+ if (generator.type === "react" && generator.version === "2") {
100
+ const options = resolver.resolveOptions(operationNode, {
101
+ options: plugin.options,
102
+ exclude,
103
+ include,
104
+ override
105
+ });
106
+ if (options === null) return;
107
+ await (0, _kubb_core.renderOperation)(operationNode, {
108
+ options,
109
+ adapter,
110
+ config,
111
+ fabric,
112
+ Component: generator.Operation,
113
+ plugin,
114
+ driver,
115
+ mode
116
+ });
117
+ }
118
+ });
119
+ await Promise.all(writeTasks);
120
+ }
121
+ }, { depth: "shallow" });
122
+ const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
123
+ type: output.barrelType ?? "named",
124
+ root,
125
+ output,
126
+ meta: { pluginName: this.plugin.name }
127
+ });
128
+ await this.upsertFile(...barrelFiles);
129
+ }
130
+ };
131
+ });
132
+ //#endregion
133
+ exports.pluginTs = pluginTs;
134
+ exports.pluginTsName = pluginTsName;
135
+
136
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["typeGenerator","resolverTsLegacy","resolverTs","path","camelCase"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { walk } from '@kubb/ast'\nimport { createPlugin, type Group, getBarrelFiles, getMode, renderOperation, renderSchema } from '@kubb/core'\nimport { typeGenerator } from './generators/index.ts'\nimport { resolverTs, resolverTsLegacy } from './resolvers/index.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 transformers = {},\n paramsCasing,\n generators = [typeGenerator].filter(Boolean),\n legacy = false,\n } = options\n\n const baseResolver = legacy ? resolverTsLegacy : resolverTs\n\n // When a `transformers.name` callback is provided, wrap the resolver so that\n // every name produced by `default()` (and therefore by every helper that calls\n // `this.default(...)`) flows through the user's transformer.\n const resolver: typeof baseResolver = transformers?.name\n ? {\n ...baseResolver,\n default(name, type) {\n const resolved = baseResolver.default(name, type)\n\n return transformers.name!(resolved, type) || resolved\n },\n }\n : baseResolver\n\n let resolveNameWarning = false\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n optionalType,\n arrayType,\n enumType,\n enumKeyCasing,\n syntaxType,\n group,\n override,\n paramsCasing,\n legacy,\n resolver,\n baseResolver,\n },\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n if (!resolveNameWarning) {\n this.driver.events.emit('warn', 'Do not use resolveName for pluginTs, use resolverTs 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 const mode = getMode(path.resolve(root, 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(\n rootNode,\n {\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 mode,\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 mode,\n })\n }\n })\n\n await Promise.all(writeTasks)\n },\n },\n { depth: 'shallow' },\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":";;;;;;;;;AAQA,MAAa,eAAe;AAE5B,MAAa,YAAA,GAAA,WAAA,eAAmC,YAAY;CAC1D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,WAAW,WACX,gBAAgB,QAChB,eAAe,iBACf,YAAY,SACZ,aAAa,QACb,eAAe,EAAE,EACjB,cACA,aAAa,CAACA,mBAAAA,cAAc,CAAC,OAAO,QAAQ,EAC5C,SAAS,UACP;CAEJ,MAAM,eAAe,SAASC,kBAAAA,mBAAmBC,kBAAAA;CAKjD,MAAM,WAAgC,cAAc,OAChD;EACE,GAAG;EACH,QAAQ,MAAM,MAAM;GACl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