@kubb/core 1.11.0-canary.20231011T130347 → 1.11.0-canary.20231011T170015

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/index.d.cts DELETED
@@ -1,740 +0,0 @@
1
- import { DirectoryTreeOptions } from 'directory-tree';
2
- import { Ora } from 'ora';
3
- export { default as pc } from 'picocolors';
4
-
5
- declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
6
- declare function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T>;
7
- declare function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & {
8
- reason: T;
9
- };
10
-
11
- declare function write(data: string, path: string): Promise<void>;
12
-
13
- interface Cache<TStore extends object = object> {
14
- delete(id: keyof TStore): boolean;
15
- get(id: keyof TStore): TStore[keyof TStore] | null;
16
- has(id: keyof TStore): boolean;
17
- set(id: keyof TStore, value: unknown): void;
18
- }
19
- declare function createPluginCache<TStore extends PluginCache>(Store?: TStore): Cache<TStore>;
20
-
21
- declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
22
- type PathMode = 'file' | 'directory';
23
- declare function getPathMode(path: string | undefined | null): PathMode;
24
- declare function read(path: string): Promise<string>;
25
-
26
- type FunctionParamsAst = {
27
- name: string;
28
- type?: string;
29
- /**
30
- * @default true
31
- */
32
- required?: boolean;
33
- /**
34
- * @default true
35
- */
36
- enabled?: boolean;
37
- default?: string;
38
- };
39
- /**
40
- * Convert an string array to a string of parameters that can be used inside a function
41
- * The parameter name is converted to `camelcase`
42
- */
43
- declare function createFunctionParams(data: FunctionParamsAst[]): string;
44
-
45
- declare function nameSorter<T extends {
46
- name: string;
47
- }>(a: T, b: T): 0 | 1 | -1;
48
-
49
- declare function createJSDocBlockText({ comments }: {
50
- comments: Array<string>;
51
- }): string;
52
-
53
- declare function getUniqueName(originalName: string, data: Record<string, number>): string;
54
-
55
- declare function timeout(ms: number): Promise<unknown>;
56
-
57
- type QueueJob<T = unknown> = {
58
- (...args: unknown[]): Promise<T> | Promise<void>;
59
- };
60
- type RunOptions = {
61
- controller?: AbortController;
62
- name?: string;
63
- description?: string;
64
- };
65
- declare class Queue {
66
- private queue;
67
- private workerCount;
68
- private maxParallel;
69
- private debug;
70
- constructor(maxParallel: number, debug?: boolean);
71
- run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
72
- runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
73
- get hasJobs(): boolean;
74
- private work;
75
- }
76
-
77
- declare function escape(text?: string): string;
78
- /**
79
- * Escape all characters not included in SingleStringCharacters and DoubleStringCharacters on
80
- * @link http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
81
- * @link https://github.com/joliss/js-string-escape/blob/master/index.js
82
- */
83
- declare function jsStringEscape(input: any): string;
84
-
85
- declare function transformReservedWord(word: string): string;
86
-
87
- declare function combineCodes(codes: string[]): string;
88
-
89
- declare function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data?: TData | undefined): string;
90
-
91
- declare function clean(path: string): Promise<void>;
92
-
93
- type TreeNodeOptions = DirectoryTreeOptions;
94
- declare class TreeNode<T = unknown> {
95
- data: T;
96
- parent?: TreeNode<T>;
97
- children: Array<TreeNode<T>>;
98
- constructor(data: T, parent?: TreeNode<T>);
99
- addChild(data: T): TreeNode<T>;
100
- find(data?: T): TreeNode<T> | null;
101
- get leaves(): TreeNode<T>[];
102
- get root(): TreeNode<T>;
103
- forEach(callback: (treeNode: TreeNode<T>) => void): this;
104
- static build<T = unknown>(path: string, options?: TreeNodeOptions): TreeNode<T> | null;
105
- }
106
-
107
- declare const uniqueIdFactory: (counter: number) => (str?: string) => string;
108
-
109
- /**
110
- * Normalizes directories to have a trailing slash.
111
- * Resolve is pretty finicky -- if the directory name doesn't have
112
- * a trailing slash then it tries to look in the parent directory.
113
- * i.e., if the directory is "/usr/nzakas/foo" it will start the
114
- * search in /usr/nzakas. However, if the directory is "/user/nzakas/foo/",
115
- * then it will start the search in /user/nzakas/foo.
116
- * @param {string} directory The directory to check.
117
- * @returns {string} The normalized directory.
118
- */
119
- declare function normalizeDirectory(directory: string): string;
120
- declare function getLocation(path: string, cwd?: string): string;
121
- declare function importModule(path: string, cwd?: string): Promise<any | undefined>;
122
-
123
- declare const throttle: <R, A extends any[]>(fn: (...args: A) => R, delay: number) => [(...args: A) => R | undefined, () => void];
124
-
125
- declare class SummaryError extends Error {
126
- summary: string[];
127
- constructor(message: string, options: {
128
- cause: Error;
129
- summary?: string[];
130
- });
131
- }
132
-
133
- /**
134
- * Behaves as an Error to log a warning in the console(still stops the execution)
135
- */
136
- declare class Warning extends Error {
137
- constructor(message?: string, options?: {
138
- cause: Error;
139
- });
140
- }
141
-
142
- type LogType = 'error' | 'info' | 'warning';
143
- type Logger = {
144
- log: (message: string | null) => void;
145
- error: (message: string | null) => void;
146
- info: (message: string | null) => void;
147
- warn: (message: string | null) => void;
148
- spinner?: Ora;
149
- logs: string[];
150
- };
151
- declare function createLogger(spinner?: Ora): Logger;
152
-
153
- declare const defaultColours: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
154
- declare function randomColour(text?: string, colours?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
155
- declare function randomPicoColour(text?: string, colors?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
156
-
157
- type URLObject = {
158
- url: string;
159
- params?: Record<string, string>;
160
- };
161
- type ObjectOptions = {
162
- type?: 'path' | 'template';
163
- replacer?: (pathParam: string) => string;
164
- stringify?: boolean;
165
- };
166
- declare class URLPath {
167
- path: string;
168
- constructor(path: string);
169
- /**
170
- * Convert Swagger path to URLPath(syntax of Express)
171
- * @example /pet/{petId} => /pet/:petId
172
- */
173
- get URL(): string;
174
- get isUrl(): boolean;
175
- /**
176
- * Convert Swagger path to template literals/ template strings(camelcase)
177
- * @example /pet/{petId} => `/pet/${petId}`
178
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
179
- * @example /account/userID => `/account/${userId}`
180
- */
181
- get template(): string;
182
- get object(): URLObject | string;
183
- get params(): Record<string, string> | undefined;
184
- toObject(options?: ObjectOptions): URLObject | string;
185
- /**
186
- * Convert Swagger path to template literals/ template strings(camelcase)
187
- * @example /pet/{petId} => `/pet/${petId}`
188
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
189
- * @example /account/userID => `/account/${userId}`
190
- */
191
- toTemplateString(replacer?: (pathParam: string) => string): string;
192
- /**
193
- * Convert Swagger path to template literals/ template strings(camelcase)
194
- * @example /pet/{petId} => `/pet/${petId}`
195
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
196
- * @example /account/userID => `/account/${userId}`
197
- */
198
- static toTemplateString(path: string, replacer?: (pathParam: string) => string): string;
199
- getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined;
200
- static getParams(path: string, replacer?: (pathParam: string) => string): Record<string, string> | undefined;
201
- /**
202
- * Convert Swagger path to URLPath(syntax of Express)
203
- * @example /pet/{petId} => /pet/:petId
204
- */
205
- toURLPath(): string;
206
- static toURLPath(path: string): string;
207
- static toObject(path: string, { type, replacer, stringify }?: ObjectOptions): URLObject | string;
208
- static isURL(path: string): boolean;
209
- }
210
-
211
- type Import = {
212
- name: string | string[];
213
- path: string;
214
- isTypeOnly?: boolean;
215
- };
216
- type Export = {
217
- name?: string | string[];
218
- path: string;
219
- isTypeOnly?: boolean;
220
- asAlias?: boolean;
221
- };
222
- type UUID = string;
223
- type Source = string;
224
- type File<Meta extends {
225
- pluginName?: string;
226
- } = {
227
- pluginName?: string;
228
- }> = {
229
- /**
230
- * Name to be used to dynamicly create the fileName(based on input.path)
231
- */
232
- fileName: string;
233
- /**
234
- * Path will be full qualified path to a specified file
235
- */
236
- path: Path;
237
- source: Source;
238
- imports?: Import[];
239
- exports?: Export[];
240
- /**
241
- * This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
242
- * @default `false`
243
- */
244
- override?: boolean;
245
- meta?: Meta;
246
- /**
247
- * This will override `process.env[key]` inside the `source`, see `getFileSource`.
248
- */
249
- env?: NodeJS.ProcessEnv;
250
- };
251
- type ResolvedFile = File & {
252
- /**
253
- * crypto.randomUUID()
254
- */
255
- id: UUID;
256
- };
257
- type CacheItem = ResolvedFile & {
258
- cancel?: () => void;
259
- };
260
- type Status = 'new' | 'success' | 'removed';
261
-
262
- declare function getIndexes(root: string, options?: TreeNodeOptions): File[] | null;
263
- declare function combineFiles(files: Array<File | null>): File[];
264
- /**
265
- * Support for js, ts and tsx(React)
266
- */
267
- type Extension = '.ts' | '.js' | '.tsx';
268
- declare const extensions: Array<Extension>;
269
- declare function isExtensionAllowed(fileName: string): boolean;
270
- declare function combineExports(exports: Export[]): Export[];
271
- declare function combineImports(imports: Import[], exports: Export[], source: string): Import[];
272
- declare function createFileSource(file: File): string;
273
-
274
- declare class FileManager {
275
- private cache;
276
- private task?;
277
- private queue?;
278
- constructor(options?: {
279
- queue?: Queue;
280
- task?: QueueJob<ResolvedFile>;
281
- });
282
- get extensions(): Extension[];
283
- get files(): File[];
284
- get isExecuting(): boolean;
285
- add(file: File): Promise<ResolvedFile>;
286
- addOrAppend(file: File): Promise<ResolvedFile>;
287
- private append;
288
- getCacheByUUID(UUID: UUID): File | undefined;
289
- get(path: Path): File[] | undefined;
290
- remove(path: Path): void;
291
- write(...params: Parameters<typeof write>): Promise<void>;
292
- read(...params: Parameters<typeof read>): Promise<string>;
293
- }
294
-
295
- declare class PluginError extends Error {
296
- pluginManager: PluginManager;
297
- cause: Error;
298
- constructor(message: string, options: {
299
- cause: Error;
300
- pluginManager: PluginManager;
301
- });
302
- }
303
-
304
- /**
305
- * Get the type of the first argument in a function.
306
- * @example Arg0<(a: string, b: number) => void> -> string
307
- */
308
- type Argument0<H extends keyof PluginLifecycle> = Parameters<PluginLifecycle[H]>[0];
309
- type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
310
- type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
311
- strategy: Strategy;
312
- hookName: H;
313
- plugin: KubbPlugin;
314
- parameters?: unknown[] | undefined;
315
- output?: unknown;
316
- };
317
- type ParseResult<H extends PluginLifecycleHooks> = PluginLifecycle[H];
318
- type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
319
- result: Result;
320
- plugin: KubbPlugin;
321
- };
322
-
323
- declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, any, Record<string, unknown>>>];
324
- type Options$1 = {
325
- debug?: boolean;
326
- task: QueueJob<ResolvedFile>;
327
- logger: Logger;
328
- };
329
- type Events = {
330
- execute: [executer: Executer];
331
- executed: [executer: Executer];
332
- error: [pluginError: PluginError];
333
- };
334
- declare class PluginManager {
335
- plugins: KubbPlugin[];
336
- readonly fileManager: FileManager;
337
- private readonly core;
338
- queue: Queue;
339
- executed: Executer[];
340
- logger: Logger;
341
- private eventEmitter;
342
- constructor(config: KubbConfig, options: Options$1);
343
- resolvePath: (params: ResolvePathParams) => OptionalPath;
344
- resolveName: (params: ResolveNameParams) => string;
345
- on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
346
- /**
347
- *
348
- * Run only hook for a specific plugin name
349
- */
350
- hookForPlugin<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
351
- pluginName: string;
352
- hookName: H;
353
- parameters: Parameters<PluginLifecycle[H]>;
354
- }): Promise<ReturnType<ParseResult<H>> | null> | null;
355
- hookForPluginSync<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
356
- pluginName: string;
357
- hookName: H;
358
- parameters: Parameters<PluginLifecycle[H]>;
359
- }): ReturnType<ParseResult<H>> | null;
360
- /**
361
- *
362
- * Chains, first non-null result stops and returns
363
- */
364
- hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
365
- hookName: H;
366
- parameters: Parameters<PluginLifecycle[H]>;
367
- skipped?: ReadonlySet<KubbPlugin> | null;
368
- }): Promise<SafeParseResult<H>>;
369
- /**
370
- *
371
- * Chains, first non-null result stops and returns
372
- */
373
- hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
374
- hookName: H;
375
- parameters: Parameters<PluginLifecycle[H]>;
376
- skipped?: ReadonlySet<KubbPlugin> | null;
377
- }): SafeParseResult<H>;
378
- /**
379
- *
380
- * Parallel, runs all plugins
381
- */
382
- hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
383
- hookName: H;
384
- parameters?: Parameters<PluginLifecycle[H]> | undefined;
385
- }): Promise<Awaited<TOuput>[]>;
386
- /**
387
- *
388
- * Chains, reduces returned value, handling the reduced value as the first hook argument
389
- */
390
- hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
391
- hookName: H;
392
- parameters: Parameters<PluginLifecycle[H]>;
393
- reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) => PossiblePromise<Argument0<H> | null>;
394
- }): Promise<Argument0<H>>;
395
- /**
396
- * Chains plugins
397
- */
398
- hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: {
399
- hookName: H;
400
- parameters?: Parameters<PluginLifecycle[H]>;
401
- }): Promise<void>;
402
- private getSortedPlugins;
403
- getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin;
404
- private addExecutedToCallStack;
405
- /**
406
- * Run an async plugin hook and return the result.
407
- * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
408
- * @param args Arguments passed to the plugin hook.
409
- * @param plugin The actual pluginObject to run.
410
- */
411
- private execute;
412
- /**
413
- * Run a sync plugin hook and return the result.
414
- * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
415
- * @param args Arguments passed to the plugin hook.
416
- * @param plugin The acutal plugin
417
- * @param replaceContext When passed, the plugin context can be overridden.
418
- */
419
- private executeSync;
420
- private catcher;
421
- }
422
-
423
- declare class ValidationPluginError extends Error {
424
- }
425
- declare function getDependedPlugins<TPlugins extends KubbPlugin[]>(plugins: KubbPlugin[], dependedPluginNames: string | string[]): TPlugins;
426
-
427
- declare class ParallelPluginError extends Error {
428
- errors: PluginError[];
429
- pluginManager: PluginManager;
430
- constructor(message: string, options: {
431
- cause?: Error;
432
- errors: PluginError[];
433
- pluginManager: PluginManager;
434
- });
435
- findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
436
- }
437
-
438
- /**
439
- * @deprecated
440
- */
441
- interface Register {
442
- }
443
- type PossiblePromise<T> = Promise<T> | T;
444
- /**
445
- * Config used in `kubb.config.js`
446
- *
447
- * @example import { defineConfig } from '@kubb/core'
448
- * export default defineConfig({
449
- * ...
450
- * })
451
- */
452
- type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
453
- /**
454
- * Project root directory. Can be an absolute path, or a path relative from
455
- * the location of the config file itself.
456
- * @default process.cwd()
457
- */
458
- root?: string;
459
- /**
460
- * Plugin type can be KubbJSONPlugin or KubbPlugin
461
- * Example: ['@kubb/swagger', { output: false }]
462
- * Or: createSwagger({ output: false })
463
- */
464
- plugins?: KubbPlugin[] | KubbJSONPlugins[] | KubbObjectPlugins;
465
- };
466
- /**
467
- * Global/internal config used through out the full generation.
468
- */
469
- type KubbConfig = {
470
- /**
471
- * Project root directory. Can be an absolute path, or a path relative from
472
- * the location of the config file itself.
473
- * @default process.cwd()
474
- */
475
- root: string;
476
- input: {
477
- /**
478
- * Path to be used as the input. Can be an absolute path, or a path relative from
479
- * the defined root option.
480
- */
481
- path: string;
482
- };
483
- output: {
484
- /**
485
- * Path to be used to export all generated files. Can be an absolute path, or a path relative based of the defined root option.
486
- */
487
- path: string;
488
- /**
489
- * Remove previous generated files and folders.
490
- */
491
- clean?: boolean;
492
- /**
493
- * Enabled or disable the writing to the filesystem. This is being used for the playground.
494
- * @default true
495
- */
496
- write?: boolean;
497
- };
498
- /**
499
- * Array of Kubb plugins to use.
500
- * The plugin/package can forsee some options that you need to pass through.
501
- * Sometimes a plugin is depended on another plugin, if that's the case you will get an error back from the plugin you installed.
502
- */
503
- plugins?: KubbPlugin[];
504
- /**
505
- * Hooks that will be called when a specific action is triggered in Kubb.
506
- */
507
- hooks?: {
508
- /**
509
- * Hook that will be triggerend at the end of all executions.
510
- * Useful for running Prettier or ESLint to use your own linting structure.
511
- */
512
- done?: string | string[];
513
- };
514
- };
515
- type CLIOptions = {
516
- /**
517
- * Path to `kubb.config.js`
518
- */
519
- config?: string;
520
- /**
521
- * Watch changes on input
522
- */
523
- watch?: string;
524
- /**
525
- * Log level to report when using the CLI
526
- *
527
- * `silent` will hide all information that is not relevant
528
- *
529
- * `info` will show all information possible(not related to the PluginManager)
530
- *
531
- * `debug` will show all information possible(related to the PluginManager), handy for seeing logs
532
- * @default `silent`
533
- */
534
- logLevel?: LogLevel;
535
- };
536
- type BuildOutput = {
537
- files: FileManager['files'];
538
- pluginManager: PluginManager;
539
- };
540
- type KubbPluginKind = 'schema' | 'controller';
541
- type KubbJSONPlugins = [plugin: keyof Kubb.OptionsPlugins | (string & {}), options: Kubb.OptionsPlugins[keyof Kubb.OptionsPlugins]];
542
- type KubbObjectPlugin = keyof Kubb.OptionsPlugins;
543
- type KubbObjectPlugins = {
544
- [K in keyof Kubb.OptionsPlugins]: Kubb.OptionsPlugins[K] | object;
545
- };
546
- type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
547
- /**
548
- * Unique name used for the plugin
549
- * @example @kubb/typescript
550
- */
551
- name: PluginFactoryOptions['name'];
552
- /**
553
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
554
- */
555
- options?: TOptions['options'];
556
- /**
557
- * Kind/type for the plugin
558
- * Type 'schema' can be used for JSON schema's, TypeScript types, ...
559
- * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
560
- * @default undefined
561
- */
562
- kind?: KubbPluginKind;
563
- /**
564
- * Define an api that can be used by other plugins, see `PluginManager' where we convert from `KubbUserPlugin` to `KubbPlugin`(used when calling `createPlugin`).
565
- */
566
- api?: (this: Omit<PluginContext, 'addFile'>) => TOptions['api'];
567
- } & Partial<PluginLifecycle<TOptions>>;
568
- type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
569
- /**
570
- * Unique name used for the plugin
571
- * @example @kubb/typescript
572
- */
573
- name: PluginFactoryOptions['name'];
574
- /**
575
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
576
- */
577
- options?: TOptions['options'];
578
- /**
579
- * Kind/type for the plugin
580
- * Type 'schema' can be used for JSON schema's, TypeScript types, ...
581
- * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
582
- * @default undefined
583
- */
584
- kind?: KubbPluginKind;
585
- /**
586
- * Define an api that can be used by other plugins, see `PluginManager' where we convert from `KubbUserPlugin` to `KubbPlugin`(used when calling `createPlugin`).
587
- */
588
- api?: TOptions['api'];
589
- } & Partial<PluginLifecycle<TOptions>>;
590
- type PluginFactoryOptions<Name = string, Options = unknown, Nested extends boolean = false, API = any, resolvePathOptions = Record<string, unknown>> = {
591
- name: Name;
592
- options: Options;
593
- nested: Nested;
594
- api: API;
595
- resolvePathOptions: resolvePathOptions;
596
- };
597
- type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
598
- /**
599
- * Valdiate all plugins to see if their depended plugins are installed and configured.
600
- * @type hookParallel
601
- */
602
- validate: (this: Omit<PluginContext, 'addFile'>, plugins: KubbPlugin[]) => PossiblePromise<true>;
603
- /**
604
- * Start of the lifecycle of a plugin.
605
- * @type hookParallel
606
- */
607
- buildStart: (this: PluginContext, kubbConfig: KubbConfig) => PossiblePromise<void>;
608
- /**
609
- * Resolve to a Path based on a fileName(example: `./Pet.ts`) and directory(example: `./models`).
610
- * Options can als be included.
611
- * @type hookFirst
612
- * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
613
- */
614
- resolvePath: (this: PluginContext, fileName: string, directory?: string, options?: TOptions['resolvePathOptions']) => OptionalPath;
615
- /**
616
- * Resolve to a name based on a string.
617
- * Useful when converting to PascalCase or camelCase.
618
- * @type hookFirst
619
- * @example ('pet') => 'Pet'
620
- */
621
- resolveName: (this: PluginContext, name: string) => string;
622
- /**
623
- * Makes it possible to run async logic to override the path defined previously by `resolvePath`.
624
- * @type hookFirst
625
- */
626
- load: (this: Omit<PluginContext, 'addFile'>, path: Path) => PossiblePromise<TransformResult | null>;
627
- /**
628
- * Transform the source-code.
629
- * @type hookReduceArg0
630
- */
631
- transform: (this: Omit<PluginContext, 'addFile'>, source: string, path: Path) => PossiblePromise<TransformResult>;
632
- /**
633
- * Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
634
- * @type hookParallel
635
- */
636
- writeFile: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: Path) => PossiblePromise<void>;
637
- /**
638
- * End of the plugin lifecycle.
639
- * @type hookParallel
640
- */
641
- buildEnd: (this: PluginContext) => PossiblePromise<void>;
642
- };
643
- type PluginLifecycleHooks = keyof PluginLifecycle;
644
- type PluginCache = Record<string, [number, unknown]>;
645
- type ResolvePathParams<TOptions = Record<string, unknown>> = {
646
- /**
647
- * When set, resolvePath will only call resolvePath of the name of the plugin set here.
648
- * If not defined it will fall back on the resolvePath of the core plugin.
649
- */
650
- pluginName?: string;
651
- fileName: string;
652
- directory?: string | undefined;
653
- /**
654
- * Options to be passed to 'resolvePath' 3th parameter
655
- */
656
- options?: TOptions;
657
- };
658
- type ResolveNameParams = {
659
- /**
660
- * When set, resolvePath will only call resolvePath of the name of the plugin set here.
661
- * If not defined it will fall back on the resolvePath of the core plugin.
662
- */
663
- pluginName?: string;
664
- name: string;
665
- };
666
- type PluginContext<TOptions = Record<string, unknown>> = {
667
- config: KubbConfig;
668
- cache: Cache<PluginCache>;
669
- fileManager: FileManager;
670
- addFile: (...file: File[]) => Promise<File[]>;
671
- resolvePath: (params: ResolvePathParams<TOptions>) => OptionalPath;
672
- resolveName: (params: ResolveNameParams) => string;
673
- logger: Logger;
674
- plugins: KubbPlugin[];
675
- };
676
- type TransformResult = string | null;
677
- /**
678
- * @description Computing the name of a file or directory together with its position in relation to other directories traced back in a line to the root
679
- */
680
- type Path = string;
681
- type OptionalPath = Path | null | undefined;
682
- type FileName = string | null | undefined;
683
- declare const LogLevel: {
684
- readonly silent: "silent";
685
- readonly info: "info";
686
- readonly debug: "debug";
687
- };
688
- type LogLevel = keyof typeof LogLevel;
689
-
690
- type BuildOptions = {
691
- config: PluginContext['config'];
692
- /**
693
- * @default Logger without the spinner
694
- */
695
- logger?: Logger;
696
- logLevel?: LogLevel;
697
- };
698
- declare function build(options: BuildOptions): Promise<BuildOutput>;
699
-
700
- /**
701
- * Type helper to make it easier to use kubb.config.js
702
- * accepts a direct {@link KubbConfig} object, or a function that returns it.
703
- * The function receives a {@link ConfigEnv} object that exposes two properties:
704
- */
705
- declare function defineConfig(options: PossiblePromise<KubbUserConfig> | ((
706
- /** The options derived from the CLI flags */
707
- cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>)): typeof options;
708
-
709
- type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => T['nested'] extends true ? Array<KubbUserPlugin<T>> : KubbUserPlugin<T>;
710
- declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
711
- type Options = {
712
- config: PluginContext['config'];
713
- fileManager: FileManager;
714
- resolvePath: PluginContext['resolvePath'];
715
- resolveName: PluginContext['resolveName'];
716
- logger: PluginContext['logger'];
717
- getPlugins: () => KubbPlugin[];
718
- };
719
- type CorePluginOptions = PluginFactoryOptions<'core', Options, false, PluginContext>;
720
- declare const pluginName: CorePluginOptions['name'];
721
-
722
- /**
723
- * Abstract class that contains the building blocks for plugins to create their own Generator
724
- * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
725
- */
726
- declare abstract class Generator<TOptions extends object = object> {
727
- private _options;
728
- constructor(options?: TOptions);
729
- get options(): TOptions;
730
- abstract build(...params: unknown[]): unknown;
731
- }
732
-
733
- /**
734
- * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
735
- */
736
- declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {
737
- abstract build(schema: TInput, name: string, description?: string): TOutput;
738
- }
739
-
740
- export { Argument0, BuildOutput, CLIOptions, Cache, CacheItem, Executer, Export, Extension, File, FileManager, FileName, Generator, Import, KubbConfig, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogType, Logger, OptionalPath, ParallelPluginError, ParseResult, Path, PathMode, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Queue, QueueJob, Register, ResolveNameParams, ResolvePathParams, ResolvedFile, SafeParseResult, SchemaGenerator, Source, Status, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, URLPath, UUID, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createFunctionParams, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };