@kubb/core 4.3.1 → 4.4.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/{URLPath-BYceu_vY.js → URLPath-Bpc_OJmh.js} +2 -3
- package/dist/{URLPath-BYceu_vY.js.map → URLPath-Bpc_OJmh.js.map} +1 -1
- package/dist/{URLPath-8WVzHBnA.cjs → URLPath-Bu6Wkco7.cjs} +6 -7
- package/dist/{URLPath-8WVzHBnA.cjs.map → URLPath-Bu6Wkco7.cjs.map} +1 -1
- package/dist/{chunk-CZg_9w7l.cjs → chunk-CUT6urMc.cjs} +0 -23
- package/dist/{fs-RSVoUw3S.cjs → fs-CM7ohZSu.cjs} +2 -2
- package/dist/{fs-RSVoUw3S.cjs.map → fs-CM7ohZSu.cjs.map} +1 -1
- package/dist/fs.cjs +2 -2
- package/dist/fs.d.ts +1 -1
- package/dist/hooks.cjs +6 -6
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +1 -1
- package/dist/hooks.d.ts +4 -4
- package/dist/hooks.js +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/{index-BTe91LHd.d.ts → index-DdO15F70.d.ts} +2 -3
- package/dist/index.cjs +46 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -11
- package/dist/index.d.ts +18 -14
- package/dist/index.js +40 -48
- package/dist/index.js.map +1 -1
- package/dist/{logger-BXL0YCrv.cjs → logger-C7JFdYpj.cjs} +4 -4
- package/dist/{logger-BXL0YCrv.cjs.map → logger-C7JFdYpj.cjs.map} +1 -1
- package/dist/{logger-BA-za85-.d.ts → logger-D_jvWsUF.d.ts} +1 -1
- package/dist/{logger-CDxSrFkR.js → logger-khF_Lft4.js} +2 -2
- package/dist/{logger-CDxSrFkR.js.map → logger-khF_Lft4.js.map} +1 -1
- package/dist/logger.cjs +2 -2
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +1 -1
- package/dist/{prompt-DBVnG4Me.js → prompt-CIpZjUDy.js} +1 -1
- package/dist/{prompt-DBVnG4Me.js.map → prompt-CIpZjUDy.js.map} +1 -1
- package/dist/{prompt-DgONOpPH.cjs → prompt-CgJLZzbf.cjs} +2 -2
- package/dist/{prompt-DgONOpPH.cjs.map → prompt-CgJLZzbf.cjs.map} +1 -1
- package/dist/transformers-BN5jfIAt.js +339 -0
- package/dist/transformers-BN5jfIAt.js.map +1 -0
- package/dist/transformers-BpnIvSiH.cjs +443 -0
- package/dist/transformers-BpnIvSiH.cjs.map +1 -0
- package/dist/transformers.cjs +7 -6
- package/dist/transformers.js +1 -3
- package/dist/{types-DPeNK0FO.d.ts → types-CCUiy4jG.d.ts} +43 -45
- package/dist/{types-BzI9JlV8.d.ts → types-ClXc6HFo.d.ts} +1 -1
- package/dist/{types-DNxlynJr.d.cts → types-EV6-sImo.d.cts} +40 -42
- package/dist/utils.cjs +7 -7
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +4 -6
- package/dist/utils.js.map +1 -1
- package/dist/{write-BJfM7G1_.cjs → write-BsFt8M9e.cjs} +2 -2
- package/dist/{write-BJfM7G1_.cjs.map → write-BsFt8M9e.cjs.map} +1 -1
- package/package.json +8 -14
- package/src/PluginManager.ts +3 -7
- package/src/build.ts +37 -41
- package/src/hooks/useMode.ts +1 -1
- package/src/hooks/usePlugin.ts +1 -1
- package/src/hooks/usePluginManager.ts +1 -1
- package/src/plugin.ts +10 -5
- package/src/types.ts +2 -1
- package/dist/acorn-BAVXZMtK.cjs +0 -5082
- package/dist/acorn-BAVXZMtK.cjs.map +0 -1
- package/dist/acorn-D-VhIOLw.js +0 -5080
- package/dist/acorn-D-VhIOLw.js.map +0 -1
- package/dist/angular-Bp0XO9db.cjs +0 -3631
- package/dist/angular-Bp0XO9db.cjs.map +0 -1
- package/dist/angular-Czhp4eq5.js +0 -3629
- package/dist/angular-Czhp4eq5.js.map +0 -1
- package/dist/babel-DCR_B4Qn.js +0 -10033
- package/dist/babel-DCR_B4Qn.js.map +0 -1
- package/dist/babel-NI0v59ga.cjs +0 -10035
- package/dist/babel-NI0v59ga.cjs.map +0 -1
- package/dist/casing-BSeq_teY.js +0 -100
- package/dist/casing-BSeq_teY.js.map +0 -1
- package/dist/casing-CP-9GGdK.cjs +0 -112
- package/dist/casing-CP-9GGdK.cjs.map +0 -1
- package/dist/chunk-1SJ2vVWa.js +0 -35
- package/dist/estree-C3BZPlpU.cjs +0 -6930
- package/dist/estree-C3BZPlpU.cjs.map +0 -1
- package/dist/estree-DU2NummP.js +0 -6926
- package/dist/estree-DU2NummP.js.map +0 -1
- package/dist/flow-CWUBUkoi.cjs +0 -52252
- package/dist/flow-CWUBUkoi.cjs.map +0 -1
- package/dist/flow-JiEbweKj.js +0 -52250
- package/dist/flow-JiEbweKj.js.map +0 -1
- package/dist/glimmer-CX9OqG1j.cjs +0 -7275
- package/dist/glimmer-CX9OqG1j.cjs.map +0 -1
- package/dist/glimmer-t9nWn9aE.js +0 -7271
- package/dist/glimmer-t9nWn9aE.js.map +0 -1
- package/dist/graphql-DjErlIi5.js +0 -1897
- package/dist/graphql-DjErlIi5.js.map +0 -1
- package/dist/graphql-GOxQAKxM.cjs +0 -1902
- package/dist/graphql-GOxQAKxM.cjs.map +0 -1
- package/dist/html-CWrdYAhQ.cjs +0 -6560
- package/dist/html-CWrdYAhQ.cjs.map +0 -1
- package/dist/html-_apcbx34.js +0 -6555
- package/dist/html-_apcbx34.js.map +0 -1
- package/dist/markdown-ckUc3Q6q.js +0 -6750
- package/dist/markdown-ckUc3Q6q.js.map +0 -1
- package/dist/markdown-pzqiRmft.cjs +0 -6755
- package/dist/markdown-pzqiRmft.cjs.map +0 -1
- package/dist/meriyah-BjnGqpUs.js +0 -8928
- package/dist/meriyah-BjnGqpUs.js.map +0 -1
- package/dist/meriyah-D_x7itbT.cjs +0 -8930
- package/dist/meriyah-D_x7itbT.cjs.map +0 -1
- package/dist/mocks.cjs +0 -16830
- package/dist/mocks.cjs.map +0 -1
- package/dist/mocks.d.cts +0 -13
- package/dist/mocks.d.ts +0 -13
- package/dist/mocks.js +0 -16818
- package/dist/mocks.js.map +0 -1
- package/dist/postcss-B_c2wbFu.cjs +0 -6689
- package/dist/postcss-B_c2wbFu.cjs.map +0 -1
- package/dist/postcss-v7BP6SZ-.js +0 -6684
- package/dist/postcss-v7BP6SZ-.js.map +0 -1
- package/dist/transformers-BH0KLJJP.cjs +0 -804
- package/dist/transformers-BH0KLJJP.cjs.map +0 -1
- package/dist/transformers-DzHGqYO2.js +0 -702
- package/dist/transformers-DzHGqYO2.js.map +0 -1
- package/dist/typescript-6kMN6Wqz.cjs +0 -23014
- package/dist/typescript-6kMN6Wqz.cjs.map +0 -1
- package/dist/typescript-B_IBfKSe.js +0 -23002
- package/dist/typescript-B_IBfKSe.js.map +0 -1
- package/dist/typescript-C5hce4HG.cjs +0 -4
- package/dist/typescript-Cas1XcNz.js +0 -3
- package/dist/yaml-BfWM_B73.js +0 -5209
- package/dist/yaml-BfWM_B73.js.map +0 -1
- package/dist/yaml-DZs6MhV1.cjs +0 -5215
- package/dist/yaml-DZs6MhV1.cjs.map +0 -1
- package/src/mocks/index.ts +0 -82
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import { a as Mode, i as File, n as BaseName, o as OptionalPath, r as Extname, s as ResolvedFile } from "./index-
|
|
2
|
-
import { n as Logger, o as EventEmitter } from "./logger-
|
|
3
|
-
import { t as PossiblePromise } from "./types-
|
|
4
|
-
import { FileManager } from "@kubb/fabric
|
|
1
|
+
import { a as Mode, i as File, n as BaseName, o as OptionalPath, r as Extname, s as ResolvedFile } from "./index-DdO15F70.js";
|
|
2
|
+
import { n as Logger, o as EventEmitter } from "./logger-D_jvWsUF.js";
|
|
3
|
+
import { t as PossiblePromise } from "./types-ClXc6HFo.js";
|
|
4
|
+
import { Fabric, FileManager } from "@kubb/react-fabric";
|
|
5
5
|
|
|
6
6
|
//#region src/PluginManager.d.ts
|
|
7
7
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
8
8
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
9
|
-
type Executer<H
|
|
9
|
+
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
10
10
|
message: string;
|
|
11
11
|
strategy: Strategy;
|
|
12
|
-
hookName: H
|
|
12
|
+
hookName: H;
|
|
13
13
|
plugin: Plugin;
|
|
14
14
|
parameters?: unknown[] | undefined;
|
|
15
15
|
output?: unknown;
|
|
16
16
|
};
|
|
17
|
-
type ParseResult<H
|
|
18
|
-
type SafeParseResult<H
|
|
17
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
18
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
19
19
|
result: Result;
|
|
20
20
|
plugin: Plugin;
|
|
21
21
|
};
|
|
22
22
|
type Options = {
|
|
23
|
+
fabric: Fabric;
|
|
23
24
|
logger: Logger;
|
|
24
25
|
/**
|
|
25
26
|
* @default Number.POSITIVE_INFINITY
|
|
@@ -31,20 +32,16 @@ type Events = {
|
|
|
31
32
|
executed: [executer: Executer];
|
|
32
33
|
error: [error: Error];
|
|
33
34
|
};
|
|
34
|
-
type GetFileProps<TOptions
|
|
35
|
+
type GetFileProps<TOptions = object> = {
|
|
35
36
|
name: string;
|
|
36
37
|
mode?: Mode;
|
|
37
38
|
extname: Extname;
|
|
38
39
|
pluginKey: Plugin['key'];
|
|
39
|
-
options?: TOptions
|
|
40
|
+
options?: TOptions;
|
|
40
41
|
};
|
|
41
42
|
declare class PluginManager {
|
|
42
43
|
#private;
|
|
43
44
|
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated do not use from pluginManager
|
|
46
|
-
*/
|
|
47
|
-
readonly fileManager: FileManager;
|
|
48
45
|
readonly events: EventEmitter<Events>;
|
|
49
46
|
readonly config: Config;
|
|
50
47
|
readonly executed: Array<Executer>;
|
|
@@ -283,11 +280,11 @@ TName extends string = string,
|
|
|
283
280
|
/**
|
|
284
281
|
* Options of the plugin.
|
|
285
282
|
*/
|
|
286
|
-
TOptions
|
|
283
|
+
TOptions extends object = object,
|
|
287
284
|
/**
|
|
288
285
|
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
289
286
|
*/
|
|
290
|
-
TResolvedOptions extends object = TOptions
|
|
287
|
+
TResolvedOptions extends object = TOptions,
|
|
291
288
|
/**
|
|
292
289
|
* Context that you want to expose to other plugins.
|
|
293
290
|
*/
|
|
@@ -301,24 +298,24 @@ TResolvePathOptions extends object = object> = {
|
|
|
301
298
|
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
302
299
|
*/
|
|
303
300
|
key: PluginKey<TName | string>;
|
|
304
|
-
options: TOptions
|
|
301
|
+
options: TOptions;
|
|
305
302
|
resolvedOptions: TResolvedOptions;
|
|
306
303
|
context: TContext;
|
|
307
304
|
resolvePathOptions: TResolvePathOptions;
|
|
308
305
|
};
|
|
309
306
|
type PluginKey<TName> = [name: TName, identifier?: string | number];
|
|
310
307
|
type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
|
|
311
|
-
type UserPlugin<TOptions
|
|
308
|
+
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
312
309
|
/**
|
|
313
310
|
* Unique name used for the plugin
|
|
314
311
|
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
315
312
|
* @example @kubb/typescript
|
|
316
313
|
*/
|
|
317
|
-
name: TOptions
|
|
314
|
+
name: TOptions['name'];
|
|
318
315
|
/**
|
|
319
316
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
320
317
|
*/
|
|
321
|
-
options: TOptions
|
|
318
|
+
options: TOptions['resolvedOptions'];
|
|
322
319
|
/**
|
|
323
320
|
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
324
321
|
* Can be used to validate dependent plugins.
|
|
@@ -328,24 +325,24 @@ type UserPlugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
328
325
|
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
329
326
|
*/
|
|
330
327
|
post?: Array<string>;
|
|
331
|
-
} & (TOptions
|
|
328
|
+
} & (TOptions['context'] extends never ? {
|
|
332
329
|
context?: never;
|
|
333
330
|
} : {
|
|
334
|
-
context: (this: TOptions
|
|
331
|
+
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
335
332
|
});
|
|
336
|
-
type UserPluginWithLifeCycle<TOptions
|
|
333
|
+
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
337
334
|
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>;
|
|
338
|
-
type Plugin<TOptions
|
|
335
|
+
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
339
336
|
/**
|
|
340
337
|
* Unique name used for the plugin
|
|
341
338
|
* @example @kubb/typescript
|
|
342
339
|
*/
|
|
343
|
-
name: TOptions
|
|
340
|
+
name: TOptions['name'];
|
|
344
341
|
/**
|
|
345
342
|
* Internal key used when a developer uses more than one of the same plugin
|
|
346
343
|
* @private
|
|
347
344
|
*/
|
|
348
|
-
key: TOptions
|
|
345
|
+
key: TOptions['key'];
|
|
349
346
|
/**
|
|
350
347
|
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
351
348
|
* Can be used to validate dependent plugins.
|
|
@@ -358,49 +355,49 @@ type Plugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
358
355
|
/**
|
|
359
356
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
360
357
|
*/
|
|
361
|
-
options: TOptions
|
|
362
|
-
} & (TOptions
|
|
358
|
+
options: TOptions['resolvedOptions'];
|
|
359
|
+
} & (TOptions['context'] extends never ? {
|
|
363
360
|
context?: never;
|
|
364
361
|
} : {
|
|
365
|
-
context: TOptions
|
|
362
|
+
context: TOptions['context'];
|
|
366
363
|
});
|
|
367
|
-
type PluginWithLifeCycle<TOptions
|
|
368
|
-
type PluginLifecycle<TOptions
|
|
364
|
+
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
365
|
+
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
369
366
|
/**
|
|
370
367
|
* Start of the lifecycle of a plugin.
|
|
371
368
|
* @type hookParallel
|
|
372
369
|
*/
|
|
373
|
-
buildStart?: (this: PluginContext<TOptions
|
|
370
|
+
buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
|
|
374
371
|
/**
|
|
375
372
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
376
373
|
* Options can als be included.
|
|
377
374
|
* @type hookFirst
|
|
378
375
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
379
376
|
*/
|
|
380
|
-
resolvePath?: (this: PluginContext<TOptions
|
|
377
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
|
|
381
378
|
/**
|
|
382
379
|
* Resolve to a name based on a string.
|
|
383
380
|
* Useful when converting to PascalCase or camelCase.
|
|
384
381
|
* @type hookFirst
|
|
385
382
|
* @example ('pet') => 'Pet'
|
|
386
383
|
*/
|
|
387
|
-
resolveName?: (this: PluginContext<TOptions
|
|
384
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
388
385
|
/**
|
|
389
386
|
* End of the plugin lifecycle.
|
|
390
387
|
* @type hookParallel
|
|
391
388
|
*/
|
|
392
|
-
buildEnd?: (this: PluginContext<TOptions
|
|
389
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
393
390
|
};
|
|
394
391
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
395
|
-
type PluginParameter<H
|
|
396
|
-
type ResolvePathParams<TOptions
|
|
392
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
393
|
+
type ResolvePathParams<TOptions = object> = {
|
|
397
394
|
pluginKey?: Plugin['key'];
|
|
398
395
|
baseName: BaseName;
|
|
399
396
|
mode?: Mode;
|
|
400
397
|
/**
|
|
401
398
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
402
399
|
*/
|
|
403
|
-
options?: TOptions
|
|
400
|
+
options?: TOptions;
|
|
404
401
|
};
|
|
405
402
|
type ResolveNameParams = {
|
|
406
403
|
name: string;
|
|
@@ -413,7 +410,8 @@ type ResolveNameParams = {
|
|
|
413
410
|
*/
|
|
414
411
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
415
412
|
};
|
|
416
|
-
type PluginContext<TOptions
|
|
413
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
414
|
+
fabric: Fabric;
|
|
417
415
|
config: Config;
|
|
418
416
|
/**
|
|
419
417
|
* @deprecated
|
|
@@ -421,7 +419,7 @@ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOption
|
|
|
421
419
|
fileManager: FileManager;
|
|
422
420
|
pluginManager: PluginManager;
|
|
423
421
|
addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
|
|
424
|
-
resolvePath: (params: ResolvePathParams<TOptions
|
|
422
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
|
|
425
423
|
resolveName: (params: ResolveNameParams) => string;
|
|
426
424
|
logger: Logger;
|
|
427
425
|
/**
|
|
@@ -431,12 +429,12 @@ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOption
|
|
|
431
429
|
/**
|
|
432
430
|
* Current plugin
|
|
433
431
|
*/
|
|
434
|
-
plugin: Plugin<TOptions
|
|
432
|
+
plugin: Plugin<TOptions>;
|
|
435
433
|
};
|
|
436
434
|
/**
|
|
437
435
|
* Specify the export location for the files and define the behavior of the output
|
|
438
436
|
*/
|
|
439
|
-
type Output<TOptions
|
|
437
|
+
type Output<TOptions> = {
|
|
440
438
|
/**
|
|
441
439
|
* Path to the output folder or file that will contain the generated code
|
|
442
440
|
*/
|
|
@@ -449,11 +447,11 @@ type Output<TOptions$1> = {
|
|
|
449
447
|
/**
|
|
450
448
|
* Add a banner text in the beginning of every file
|
|
451
449
|
*/
|
|
452
|
-
banner?: string | ((options: TOptions
|
|
450
|
+
banner?: string | ((options: TOptions) => string);
|
|
453
451
|
/**
|
|
454
452
|
* Add a footer text in the beginning of every file
|
|
455
453
|
*/
|
|
456
|
-
footer?: string | ((options: TOptions
|
|
454
|
+
footer?: string | ((options: TOptions) => string);
|
|
457
455
|
};
|
|
458
456
|
type GroupContext = {
|
|
459
457
|
group: string;
|
|
@@ -470,4 +468,4 @@ type Group = {
|
|
|
470
468
|
};
|
|
471
469
|
//#endregion
|
|
472
470
|
export { ResolvePathParams as _, InputData as a, UserPluginWithLifeCycle as b, Plugin as c, PluginKey as d, PluginLifecycle as f, ResolveNameParams as g, PluginWithLifeCycle as h, Group as i, PluginContext as l, PluginParameter as m, Config as n, InputPath as o, PluginLifecycleHooks as p, GetPluginFactoryOptions as r, Output as s, BarrelType as t, PluginFactoryOptions as u, UserConfig as v, PluginManager as x, UserPlugin as y };
|
|
473
|
-
//# sourceMappingURL=types-
|
|
471
|
+
//# sourceMappingURL=types-CCUiy4jG.d.ts.map
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { a as Mode, i as File, n as BaseName, o as OptionalPath, r as Extname, s as ResolvedFile } from "./index-BmQIxvw0.cjs";
|
|
2
2
|
import { n as Logger, o as EventEmitter } from "./logger-DpoDtxfo.cjs";
|
|
3
3
|
import { t as PossiblePromise } from "./types-C3ea5qNG.cjs";
|
|
4
|
-
import { FileManager } from "@kubb/fabric
|
|
4
|
+
import { Fabric, FileManager } from "@kubb/react-fabric";
|
|
5
5
|
|
|
6
6
|
//#region src/PluginManager.d.ts
|
|
7
7
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
8
8
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
9
|
-
type Executer<H
|
|
9
|
+
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
10
10
|
message: string;
|
|
11
11
|
strategy: Strategy;
|
|
12
|
-
hookName: H
|
|
12
|
+
hookName: H;
|
|
13
13
|
plugin: Plugin;
|
|
14
14
|
parameters?: unknown[] | undefined;
|
|
15
15
|
output?: unknown;
|
|
16
16
|
};
|
|
17
|
-
type ParseResult<H
|
|
18
|
-
type SafeParseResult<H
|
|
17
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
18
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
19
19
|
result: Result;
|
|
20
20
|
plugin: Plugin;
|
|
21
21
|
};
|
|
22
22
|
type Options = {
|
|
23
|
+
fabric: Fabric;
|
|
23
24
|
logger: Logger;
|
|
24
25
|
/**
|
|
25
26
|
* @default Number.POSITIVE_INFINITY
|
|
@@ -31,20 +32,16 @@ type Events = {
|
|
|
31
32
|
executed: [executer: Executer];
|
|
32
33
|
error: [error: Error];
|
|
33
34
|
};
|
|
34
|
-
type GetFileProps<TOptions
|
|
35
|
+
type GetFileProps<TOptions = object> = {
|
|
35
36
|
name: string;
|
|
36
37
|
mode?: Mode;
|
|
37
38
|
extname: Extname;
|
|
38
39
|
pluginKey: Plugin['key'];
|
|
39
|
-
options?: TOptions
|
|
40
|
+
options?: TOptions;
|
|
40
41
|
};
|
|
41
42
|
declare class PluginManager {
|
|
42
43
|
#private;
|
|
43
44
|
readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
|
|
44
|
-
/**
|
|
45
|
-
* @deprecated do not use from pluginManager
|
|
46
|
-
*/
|
|
47
|
-
readonly fileManager: FileManager;
|
|
48
45
|
readonly events: EventEmitter<Events>;
|
|
49
46
|
readonly config: Config;
|
|
50
47
|
readonly executed: Array<Executer>;
|
|
@@ -283,11 +280,11 @@ TName extends string = string,
|
|
|
283
280
|
/**
|
|
284
281
|
* Options of the plugin.
|
|
285
282
|
*/
|
|
286
|
-
TOptions
|
|
283
|
+
TOptions extends object = object,
|
|
287
284
|
/**
|
|
288
285
|
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
289
286
|
*/
|
|
290
|
-
TResolvedOptions extends object = TOptions
|
|
287
|
+
TResolvedOptions extends object = TOptions,
|
|
291
288
|
/**
|
|
292
289
|
* Context that you want to expose to other plugins.
|
|
293
290
|
*/
|
|
@@ -301,24 +298,24 @@ TResolvePathOptions extends object = object> = {
|
|
|
301
298
|
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
302
299
|
*/
|
|
303
300
|
key: PluginKey<TName | string>;
|
|
304
|
-
options: TOptions
|
|
301
|
+
options: TOptions;
|
|
305
302
|
resolvedOptions: TResolvedOptions;
|
|
306
303
|
context: TContext;
|
|
307
304
|
resolvePathOptions: TResolvePathOptions;
|
|
308
305
|
};
|
|
309
306
|
type PluginKey<TName> = [name: TName, identifier?: string | number];
|
|
310
307
|
type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
|
|
311
|
-
type UserPlugin<TOptions
|
|
308
|
+
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
312
309
|
/**
|
|
313
310
|
* Unique name used for the plugin
|
|
314
311
|
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
315
312
|
* @example @kubb/typescript
|
|
316
313
|
*/
|
|
317
|
-
name: TOptions
|
|
314
|
+
name: TOptions['name'];
|
|
318
315
|
/**
|
|
319
316
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
320
317
|
*/
|
|
321
|
-
options: TOptions
|
|
318
|
+
options: TOptions['resolvedOptions'];
|
|
322
319
|
/**
|
|
323
320
|
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
324
321
|
* Can be used to validate dependent plugins.
|
|
@@ -328,24 +325,24 @@ type UserPlugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
328
325
|
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
329
326
|
*/
|
|
330
327
|
post?: Array<string>;
|
|
331
|
-
} & (TOptions
|
|
328
|
+
} & (TOptions['context'] extends never ? {
|
|
332
329
|
context?: never;
|
|
333
330
|
} : {
|
|
334
|
-
context: (this: TOptions
|
|
331
|
+
context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
|
|
335
332
|
});
|
|
336
|
-
type UserPluginWithLifeCycle<TOptions
|
|
333
|
+
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
337
334
|
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>;
|
|
338
|
-
type Plugin<TOptions
|
|
335
|
+
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
339
336
|
/**
|
|
340
337
|
* Unique name used for the plugin
|
|
341
338
|
* @example @kubb/typescript
|
|
342
339
|
*/
|
|
343
|
-
name: TOptions
|
|
340
|
+
name: TOptions['name'];
|
|
344
341
|
/**
|
|
345
342
|
* Internal key used when a developer uses more than one of the same plugin
|
|
346
343
|
* @private
|
|
347
344
|
*/
|
|
348
|
-
key: TOptions
|
|
345
|
+
key: TOptions['key'];
|
|
349
346
|
/**
|
|
350
347
|
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
351
348
|
* Can be used to validate dependent plugins.
|
|
@@ -358,49 +355,49 @@ type Plugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
358
355
|
/**
|
|
359
356
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
360
357
|
*/
|
|
361
|
-
options: TOptions
|
|
362
|
-
} & (TOptions
|
|
358
|
+
options: TOptions['resolvedOptions'];
|
|
359
|
+
} & (TOptions['context'] extends never ? {
|
|
363
360
|
context?: never;
|
|
364
361
|
} : {
|
|
365
|
-
context: TOptions
|
|
362
|
+
context: TOptions['context'];
|
|
366
363
|
});
|
|
367
|
-
type PluginWithLifeCycle<TOptions
|
|
368
|
-
type PluginLifecycle<TOptions
|
|
364
|
+
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
365
|
+
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
369
366
|
/**
|
|
370
367
|
* Start of the lifecycle of a plugin.
|
|
371
368
|
* @type hookParallel
|
|
372
369
|
*/
|
|
373
|
-
buildStart?: (this: PluginContext<TOptions
|
|
370
|
+
buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
|
|
374
371
|
/**
|
|
375
372
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
376
373
|
* Options can als be included.
|
|
377
374
|
* @type hookFirst
|
|
378
375
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
379
376
|
*/
|
|
380
|
-
resolvePath?: (this: PluginContext<TOptions
|
|
377
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
|
|
381
378
|
/**
|
|
382
379
|
* Resolve to a name based on a string.
|
|
383
380
|
* Useful when converting to PascalCase or camelCase.
|
|
384
381
|
* @type hookFirst
|
|
385
382
|
* @example ('pet') => 'Pet'
|
|
386
383
|
*/
|
|
387
|
-
resolveName?: (this: PluginContext<TOptions
|
|
384
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
388
385
|
/**
|
|
389
386
|
* End of the plugin lifecycle.
|
|
390
387
|
* @type hookParallel
|
|
391
388
|
*/
|
|
392
|
-
buildEnd?: (this: PluginContext<TOptions
|
|
389
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
393
390
|
};
|
|
394
391
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
395
|
-
type PluginParameter<H
|
|
396
|
-
type ResolvePathParams<TOptions
|
|
392
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
393
|
+
type ResolvePathParams<TOptions = object> = {
|
|
397
394
|
pluginKey?: Plugin['key'];
|
|
398
395
|
baseName: BaseName;
|
|
399
396
|
mode?: Mode;
|
|
400
397
|
/**
|
|
401
398
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
402
399
|
*/
|
|
403
|
-
options?: TOptions
|
|
400
|
+
options?: TOptions;
|
|
404
401
|
};
|
|
405
402
|
type ResolveNameParams = {
|
|
406
403
|
name: string;
|
|
@@ -413,7 +410,8 @@ type ResolveNameParams = {
|
|
|
413
410
|
*/
|
|
414
411
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
415
412
|
};
|
|
416
|
-
type PluginContext<TOptions
|
|
413
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
414
|
+
fabric: Fabric;
|
|
417
415
|
config: Config;
|
|
418
416
|
/**
|
|
419
417
|
* @deprecated
|
|
@@ -421,7 +419,7 @@ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOption
|
|
|
421
419
|
fileManager: FileManager;
|
|
422
420
|
pluginManager: PluginManager;
|
|
423
421
|
addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
|
|
424
|
-
resolvePath: (params: ResolvePathParams<TOptions
|
|
422
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
|
|
425
423
|
resolveName: (params: ResolveNameParams) => string;
|
|
426
424
|
logger: Logger;
|
|
427
425
|
/**
|
|
@@ -431,12 +429,12 @@ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOption
|
|
|
431
429
|
/**
|
|
432
430
|
* Current plugin
|
|
433
431
|
*/
|
|
434
|
-
plugin: Plugin<TOptions
|
|
432
|
+
plugin: Plugin<TOptions>;
|
|
435
433
|
};
|
|
436
434
|
/**
|
|
437
435
|
* Specify the export location for the files and define the behavior of the output
|
|
438
436
|
*/
|
|
439
|
-
type Output<TOptions
|
|
437
|
+
type Output<TOptions> = {
|
|
440
438
|
/**
|
|
441
439
|
* Path to the output folder or file that will contain the generated code
|
|
442
440
|
*/
|
|
@@ -449,11 +447,11 @@ type Output<TOptions$1> = {
|
|
|
449
447
|
/**
|
|
450
448
|
* Add a banner text in the beginning of every file
|
|
451
449
|
*/
|
|
452
|
-
banner?: string | ((options: TOptions
|
|
450
|
+
banner?: string | ((options: TOptions) => string);
|
|
453
451
|
/**
|
|
454
452
|
* Add a footer text in the beginning of every file
|
|
455
453
|
*/
|
|
456
|
-
footer?: string | ((options: TOptions
|
|
454
|
+
footer?: string | ((options: TOptions) => string);
|
|
457
455
|
};
|
|
458
456
|
type GroupContext = {
|
|
459
457
|
group: string;
|
|
@@ -470,4 +468,4 @@ type Group = {
|
|
|
470
468
|
};
|
|
471
469
|
//#endregion
|
|
472
470
|
export { ResolvePathParams as _, InputData as a, UserPluginWithLifeCycle as b, Plugin as c, PluginKey as d, PluginLifecycle as f, ResolveNameParams as g, PluginWithLifeCycle as h, Group as i, PluginContext as l, PluginParameter as m, Config as n, InputPath as o, PluginLifecycleHooks as p, GetPluginFactoryOptions as r, Output as s, BarrelType as t, PluginFactoryOptions as u, UserConfig as v, PluginManager as x, UserPlugin as y };
|
|
473
|
-
//# sourceMappingURL=types-
|
|
471
|
+
//# sourceMappingURL=types-EV6-sImo.d.cts.map
|
package/dist/utils.cjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-
|
|
2
|
-
const require_transformers = require('./transformers-
|
|
3
|
-
const require_URLPath = require('./URLPath-
|
|
4
|
-
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const require_transformers = require('./transformers-BpnIvSiH.cjs');
|
|
3
|
+
const require_URLPath = require('./URLPath-Bu6Wkco7.cjs');
|
|
4
|
+
let natural_orderby = require("natural-orderby");
|
|
5
|
+
natural_orderby = require_chunk.__toESM(natural_orderby);
|
|
5
6
|
|
|
6
7
|
//#region src/utils/Cache.ts
|
|
7
8
|
var Cache = class {
|
|
@@ -29,7 +30,6 @@ var Cache = class {
|
|
|
29
30
|
|
|
30
31
|
//#endregion
|
|
31
32
|
//#region src/utils/FunctionParams.ts
|
|
32
|
-
var import_main = /* @__PURE__ */ require_chunk.__toESM(require_transformers.require_main(), 1);
|
|
33
33
|
/**
|
|
34
34
|
* @deprecated
|
|
35
35
|
*/
|
|
@@ -53,7 +53,7 @@ var FunctionParams = class FunctionParams {
|
|
|
53
53
|
return this;
|
|
54
54
|
}
|
|
55
55
|
static #orderItems(items) {
|
|
56
|
-
return (0,
|
|
56
|
+
return (0, natural_orderby.orderBy)(items.filter(Boolean), [(v) => {
|
|
57
57
|
if (Array.isArray(v)) return;
|
|
58
58
|
return !v.default;
|
|
59
59
|
}, (v) => {
|
|
@@ -68,7 +68,7 @@ var FunctionParams = class FunctionParams {
|
|
|
68
68
|
acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
69
69
|
return acc;
|
|
70
70
|
}
|
|
71
|
-
const parameterName = name.startsWith("{") ? name :
|
|
71
|
+
const parameterName = name.startsWith("{") ? name : require_transformers.camelCase(name);
|
|
72
72
|
if (type) if (required) acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ""}`);
|
|
73
73
|
else acc.push(`${parameterName}?: ${type}`);
|
|
74
74
|
else acc.push(`${parameterName}`);
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":["#buffer","#items","#orderItems","#addParams","camelCase","type: string[]","name: string[]","item"],"sources":["../src/utils/Cache.ts","../src/utils/FunctionParams.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/timeout.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n async get(key: string): Promise<T | null> {\n return this.#buffer.get(key) ?? null\n }\n\n async set(key: string, value: T): Promise<void> {\n this.#buffer.set(key, value)\n }\n\n async delete(key: string): Promise<void> {\n this.#buffer.delete(key)\n }\n\n async clear(): Promise<void> {\n this.#buffer.clear()\n }\n\n async keys(): Promise<string[]> {\n return [...this.#buffer.keys()]\n }\n\n async values(): Promise<T[]> {\n return [...this.#buffer.values()]\n }\n\n async flush(): Promise<void> {\n // No-op for base cache\n }\n}\n","import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n/**\n * @deprecated\n */\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\n\n/**\n * @deprecated\n */\nexport class FunctionParams {\n #items: Array<FunctionParamsAST | FunctionParamsAST[]> = []\n constructor() {\n return this\n }\n\n get items(): FunctionParamsAST[] {\n return this.#items.flat()\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => {\n this.#items.push(it)\n })\n return this\n }\n this.#items.push(item)\n\n return this\n }\n static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {\n return orderBy(\n items.filter(Boolean),\n [\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return !v.default\n },\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return v.required ?? true\n },\n ],\n ['desc', 'desc'],\n )\n }\n\n static #addParams(acc: string[], item: FunctionParamsAST) {\n const { enabled = true, name, type, required = true, ...rest } = item\n\n if (!enabled) {\n return acc\n }\n\n if (!name) {\n // when name is not se we will use TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }\n\n static toObject(items: FunctionParamsAST[]): FunctionParamsAST {\n let type: string[] = []\n let name: string[] = []\n\n const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true\n const required = items.every((item) => item.required) ?? true\n\n items.forEach((item) => {\n name = FunctionParams.#addParams(name, { ...item, type: undefined })\n if (items.some((item) => item.type)) {\n type = FunctionParams.#addParams(type, item)\n }\n })\n\n return {\n name: `{ ${name.join(', ')} }`,\n type: type.length ? `{ ${type.join('; ')} }` : undefined,\n enabled,\n required,\n }\n }\n\n static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {\n const sortedData = FunctionParams.#orderItems(items)\n\n return sortedData\n .reduce((acc, item) => {\n if (Array.isArray(item)) {\n if (item.length <= 0) {\n return acc\n }\n const subItems = FunctionParams.#orderItems(item) as FunctionParamsAST[]\n const objectItem = FunctionParams.toObject(subItems)\n\n return FunctionParams.#addParams(acc, objectItem)\n }\n\n return FunctionParams.#addParams(acc, item)\n }, [] as string[])\n .join(', ')\n }\n\n toObject(): FunctionParamsAST {\n const items = FunctionParams.#orderItems(this.#items).flat()\n\n return FunctionParams.toObject(items)\n }\n\n toString(): string {\n const items = FunctionParams.#orderItems(this.#items)\n\n return FunctionParams.toString(items)\n }\n}\n","import type { PossiblePromise } from './types.ts'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":["#buffer","#items","#orderItems","#addParams","camelCase","type: string[]","name: string[]","item"],"sources":["../src/utils/Cache.ts","../src/utils/FunctionParams.ts","../src/utils/promise.ts","../src/utils/renderTemplate.ts","../src/utils/timeout.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n async get(key: string): Promise<T | null> {\n return this.#buffer.get(key) ?? null\n }\n\n async set(key: string, value: T): Promise<void> {\n this.#buffer.set(key, value)\n }\n\n async delete(key: string): Promise<void> {\n this.#buffer.delete(key)\n }\n\n async clear(): Promise<void> {\n this.#buffer.clear()\n }\n\n async keys(): Promise<string[]> {\n return [...this.#buffer.keys()]\n }\n\n async values(): Promise<T[]> {\n return [...this.#buffer.values()]\n }\n\n async flush(): Promise<void> {\n // No-op for base cache\n }\n}\n","import { orderBy } from 'natural-orderby'\n\nimport { camelCase } from '../transformers/casing.ts'\n\ntype FunctionParamsASTWithoutType = {\n name?: string\n type?: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n\ntype FunctionParamsASTWithType = {\n name?: never\n type: string\n /**\n * @default true\n */\n required?: boolean\n /**\n * @default true\n */\n enabled?: boolean\n default?: string\n}\n/**\n * @deprecated\n */\nexport type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType\n\n/**\n * @deprecated\n */\nexport class FunctionParams {\n #items: Array<FunctionParamsAST | FunctionParamsAST[]> = []\n constructor() {\n return this\n }\n\n get items(): FunctionParamsAST[] {\n return this.#items.flat()\n }\n\n add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams {\n if (!item) {\n return this\n }\n\n if (Array.isArray(item)) {\n item.filter(Boolean).forEach((it) => {\n this.#items.push(it)\n })\n return this\n }\n this.#items.push(item)\n\n return this\n }\n static #orderItems(items: Array<FunctionParamsAST | FunctionParamsAST[]>) {\n return orderBy(\n items.filter(Boolean),\n [\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return !v.default\n },\n (v) => {\n if (Array.isArray(v)) {\n return undefined\n }\n return v.required ?? true\n },\n ],\n ['desc', 'desc'],\n )\n }\n\n static #addParams(acc: string[], item: FunctionParamsAST) {\n const { enabled = true, name, type, required = true, ...rest } = item\n\n if (!enabled) {\n return acc\n }\n\n if (!name) {\n // when name is not se we will use TypeScript generics\n acc.push(`${type}${rest.default ? ` = ${rest.default}` : ''}`)\n\n return acc\n }\n // TODO check whey we still need the camelcase here\n const parameterName = name.startsWith('{') ? name : camelCase(name)\n\n if (type) {\n if (required) {\n acc.push(`${parameterName}: ${type}${rest.default ? ` = ${rest.default}` : ''}`)\n } else {\n acc.push(`${parameterName}?: ${type}`)\n }\n } else {\n acc.push(`${parameterName}`)\n }\n\n return acc\n }\n\n static toObject(items: FunctionParamsAST[]): FunctionParamsAST {\n let type: string[] = []\n let name: string[] = []\n\n const enabled = items.every((item) => item.enabled) ? items.at(0)?.enabled : true\n const required = items.every((item) => item.required) ?? true\n\n items.forEach((item) => {\n name = FunctionParams.#addParams(name, { ...item, type: undefined })\n if (items.some((item) => item.type)) {\n type = FunctionParams.#addParams(type, item)\n }\n })\n\n return {\n name: `{ ${name.join(', ')} }`,\n type: type.length ? `{ ${type.join('; ')} }` : undefined,\n enabled,\n required,\n }\n }\n\n static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string {\n const sortedData = FunctionParams.#orderItems(items)\n\n return sortedData\n .reduce((acc, item) => {\n if (Array.isArray(item)) {\n if (item.length <= 0) {\n return acc\n }\n const subItems = FunctionParams.#orderItems(item) as FunctionParamsAST[]\n const objectItem = FunctionParams.toObject(subItems)\n\n return FunctionParams.#addParams(acc, objectItem)\n }\n\n return FunctionParams.#addParams(acc, item)\n }, [] as string[])\n .join(', ')\n }\n\n toObject(): FunctionParamsAST {\n const items = FunctionParams.#orderItems(this.#items).flat()\n\n return FunctionParams.toObject(items)\n }\n\n toString(): string {\n const items = FunctionParams.#orderItems(this.#items)\n\n return FunctionParams.toString(items)\n }\n}\n","import type { PossiblePromise } from './types.ts'\n\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return !!result && typeof (result as Promise<unknown>)?.then === 'function'\n}\n\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","export function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data: TData | undefined = undefined): string {\n if (!data || !Object.keys(data).length) {\n return template.replace(/{{(.*?)}}/g, '')\n }\n\n const matches = template.match(/{{(.*?)}}/g)\n\n return (\n matches?.reduce((prev, curr) => {\n const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim()\n if (index === undefined) {\n return prev\n }\n const value = data[index]\n\n if (value === undefined) {\n return prev\n }\n\n return prev\n .replace(curr, () => {\n if (typeof value === 'boolean') {\n return `${value.toString()}` || 'false'\n }\n\n return (value as string) || ''\n })\n .trim()\n }, template) || ''\n )\n}\n","export async function timeout(ms: number): Promise<unknown> {\n return new Promise((resolve) => {\n setTimeout(() => {\n resolve(true)\n }, ms)\n })\n}\n"],"mappings":"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"}
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as camelCase } from "./casing-BSeq_teY.js";
|
|
1
|
+
import { m as camelCase } from "./transformers-BN5jfIAt.js";
|
|
2
|
+
import { n as getUniqueName, r as setUniqueName, t as URLPath } from "./URLPath-Bpc_OJmh.js";
|
|
3
|
+
import { orderBy } from "natural-orderby";
|
|
5
4
|
|
|
6
5
|
//#region src/utils/Cache.ts
|
|
7
6
|
var Cache = class {
|
|
@@ -29,7 +28,6 @@ var Cache = class {
|
|
|
29
28
|
|
|
30
29
|
//#endregion
|
|
31
30
|
//#region src/utils/FunctionParams.ts
|
|
32
|
-
var import_main = /* @__PURE__ */ __toESM(require_main(), 1);
|
|
33
31
|
/**
|
|
34
32
|
* @deprecated
|
|
35
33
|
*/
|
|
@@ -53,7 +51,7 @@ var FunctionParams = class FunctionParams {
|
|
|
53
51
|
return this;
|
|
54
52
|
}
|
|
55
53
|
static #orderItems(items) {
|
|
56
|
-
return
|
|
54
|
+
return orderBy(items.filter(Boolean), [(v) => {
|
|
57
55
|
if (Array.isArray(v)) return;
|
|
58
56
|
return !v.default;
|
|
59
57
|
}, (v) => {
|