@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.ts CHANGED
@@ -23,8 +23,8 @@ type PathMode = 'file' | 'directory';
23
23
  declare function getPathMode(path: string | undefined | null): PathMode;
24
24
  declare function read(path: string): Promise<string>;
25
25
 
26
- type FunctionParamsAst = {
27
- name: string;
26
+ type FunctionParamsAST = {
27
+ name?: string;
28
28
  type?: string;
29
29
  /**
30
30
  * @default true
@@ -35,12 +35,24 @@ type FunctionParamsAst = {
35
35
  */
36
36
  enabled?: boolean;
37
37
  default?: string;
38
+ } | {
39
+ name?: never;
40
+ type: string;
41
+ /**
42
+ * @default true
43
+ */
44
+ required?: boolean;
45
+ /**
46
+ * @default true
47
+ */
48
+ enabled?: boolean;
49
+ default?: string;
38
50
  };
39
51
  /**
40
52
  * Convert an string array to a string of parameters that can be used inside a function
41
53
  * The parameter name is converted to `camelcase`
42
54
  */
43
- declare function createFunctionParams(data: FunctionParamsAst[]): string;
55
+ declare function createFunctionParams(ast: FunctionParamsAST[]): string;
44
56
 
45
57
  declare function nameSorter<T extends {
46
58
  name: string;
@@ -71,6 +83,7 @@ declare class Queue {
71
83
  run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
72
84
  runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
73
85
  get hasJobs(): boolean;
86
+ get count(): number;
74
87
  private work;
75
88
  }
76
89
 
@@ -292,6 +305,15 @@ declare class FileManager {
292
305
  read(...params: Parameters<typeof read>): Promise<string>;
293
306
  }
294
307
 
308
+ declare class EventEmitter<TEvents extends Record<string, any>> {
309
+ constructor();
310
+ private emitter;
311
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
312
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
313
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
314
+ removeAll(): void;
315
+ }
316
+
295
317
  declare class PluginError extends Error {
296
318
  pluginManager: PluginManager;
297
319
  cause: Error;
@@ -334,11 +356,11 @@ type Events = {
334
356
  declare class PluginManager {
335
357
  plugins: KubbPlugin[];
336
358
  readonly fileManager: FileManager;
359
+ readonly eventEmitter: EventEmitter<Events>;
360
+ readonly queue: Queue;
361
+ readonly executed: Executer[];
362
+ readonly logger: Logger;
337
363
  private readonly core;
338
- queue: Queue;
339
- executed: Executer[];
340
- logger: Logger;
341
- private eventEmitter;
342
364
  constructor(config: KubbConfig, options: Options$1);
343
365
  resolvePath: (params: ResolvePathParams) => OptionalPath;
344
366
  resolveName: (params: ResolveNameParams) => string;
@@ -656,17 +678,18 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
656
678
  options?: TOptions;
657
679
  };
658
680
  type ResolveNameParams = {
681
+ name: string;
659
682
  /**
660
683
  * When set, resolvePath will only call resolvePath of the name of the plugin set here.
661
684
  * If not defined it will fall back on the resolvePath of the core plugin.
662
685
  */
663
686
  pluginName?: string;
664
- name: string;
665
687
  };
666
688
  type PluginContext<TOptions = Record<string, unknown>> = {
667
689
  config: KubbConfig;
668
690
  cache: Cache<PluginCache>;
669
691
  fileManager: FileManager;
692
+ pluginManager: PluginManager;
670
693
  addFile: (...file: File[]) => Promise<File[]>;
671
694
  resolvePath: (params: ResolvePathParams<TOptions>) => OptionalPath;
672
695
  resolveName: (params: ResolveNameParams) => string;
@@ -686,6 +709,9 @@ declare const LogLevel: {
686
709
  readonly debug: "debug";
687
710
  };
688
711
  type LogLevel = keyof typeof LogLevel;
712
+ type AppMeta = {
713
+ pluginManager: PluginManager;
714
+ };
689
715
 
690
716
  type BuildOptions = {
691
717
  config: PluginContext['config'];
@@ -711,6 +737,7 @@ declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOpti
711
737
  type Options = {
712
738
  config: PluginContext['config'];
713
739
  fileManager: FileManager;
740
+ pluginManager: PluginManager;
714
741
  resolvePath: PluginContext['resolvePath'];
715
742
  resolveName: PluginContext['resolveName'];
716
743
  logger: PluginContext['logger'];
@@ -737,4 +764,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
737
764
  abstract build(schema: TInput, name: string, description?: string): TOutput;
738
765
  }
739
766
 
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 };
767
+ export { AppMeta, 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, URLObject, 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 };
package/dist/index.js CHANGED
@@ -1,21 +1,20 @@
1
- import { createRequire } from 'module';
1
+ import mod, { createRequire } from 'module';
2
2
  import pc3 from 'picocolors';
3
3
  export { default as pc } from 'picocolors';
4
- import crypto from 'node:crypto';
5
- import pathParser2 from 'node:path';
4
+ import crypto from 'crypto';
5
+ import pathParser2 from 'path';
6
6
  import fs, { remove } from 'fs-extra';
7
7
  import { switcher } from 'js-runtime';
8
8
  import { camelCase, camelCaseTransformMerge } from 'change-case';
9
9
  import { orderBy } from 'natural-orderby';
10
- import { performance } from 'node:perf_hooks';
10
+ import { performance } from 'perf_hooks';
11
11
  import dirTree from 'directory-tree';
12
- import mod from 'node:module';
13
- import os from 'node:os';
14
- import { pathToFileURL } from 'node:url';
12
+ import os from 'os';
13
+ import { pathToFileURL } from 'url';
15
14
  import seedrandom from 'seedrandom';
16
15
  import { createImportDeclaration, print, createExportDeclaration } from '@kubb/ts-codegen';
17
16
  import isEqual from 'lodash.isequal';
18
- import { EventEmitter as EventEmitter$1 } from 'node:events';
17
+ import { EventEmitter as EventEmitter$1 } from 'events';
19
18
 
20
19
  createRequire(import.meta.url);
21
20
 
@@ -128,9 +127,13 @@ var reader = switcher(
128
127
  async function read(path) {
129
128
  return reader(path);
130
129
  }
131
- function createFunctionParams(data) {
132
- const sortedData = orderBy(data, [(v) => v.default, (v) => v.required ?? true], ["desc", "desc"]);
130
+ function createFunctionParams(ast) {
131
+ const sortedData = orderBy(ast, [(v) => !v.default, (v) => v.required ?? true], ["desc", "desc"]);
133
132
  return sortedData.filter(({ enabled = true }) => enabled).reduce((acc, { name, type, required = true, ...rest }) => {
133
+ if (!name) {
134
+ acc.push(`${type}${rest.default ? ` = ${rest.default}` : ""}`);
135
+ return acc;
136
+ }
134
137
  const parameterName = camelCase(name, { delimiter: "", transform: camelCaseTransformMerge });
135
138
  if (type) {
136
139
  if (required) {
@@ -219,6 +222,9 @@ var Queue = class {
219
222
  get hasJobs() {
220
223
  return this.workerCount > 0 || this.queue.length > 0;
221
224
  }
225
+ get count() {
226
+ return this.workerCount;
227
+ }
222
228
  work() {
223
229
  if (this.workerCount >= this.maxParallel) {
224
230
  return;
@@ -372,7 +378,11 @@ function renderTemplate(template, data = void 0) {
372
378
  }
373
379
  const matches = template.match(/{{(.*?)}}/g);
374
380
  return matches?.reduce((prev, curr) => {
375
- const value = data[curr.split(/{{|}}/).filter(Boolean)[0].trim()];
381
+ const index = curr.split(/{{|}}/).filter(Boolean)[0]?.trim();
382
+ if (index === void 0) {
383
+ return prev;
384
+ }
385
+ const value = data[index];
376
386
  if (value === void 0) {
377
387
  return prev;
378
388
  }
@@ -776,14 +786,16 @@ function combineFiles(files) {
776
786
  const prevIndex = acc.findIndex((item) => item.path === curr.path);
777
787
  if (prevIndex !== -1) {
778
788
  const prev = acc[prevIndex];
779
- acc[prevIndex] = {
780
- ...curr,
781
- source: prev.source && curr.source ? `${prev.source}
789
+ if (prev) {
790
+ acc[prevIndex] = {
791
+ ...curr,
792
+ source: prev.source && curr.source ? `${prev.source}
782
793
  ${curr.source}` : "",
783
- imports: [...prev.imports || [], ...curr.imports || []],
784
- exports: [...prev.exports || [], ...curr.exports || []],
785
- env: { ...prev.env || {}, ...curr.env || {} }
786
- };
794
+ imports: [...prev.imports || [], ...curr.imports || []],
795
+ exports: [...prev.exports || [], ...curr.exports || []],
796
+ env: { ...prev.env || {}, ...curr.env || {} }
797
+ };
798
+ }
787
799
  } else {
788
800
  acc.push(curr);
789
801
  }
@@ -1026,7 +1038,7 @@ function createPlugin(factory) {
1026
1038
  }
1027
1039
  var pluginName = "core";
1028
1040
  var definePlugin = createPlugin((options) => {
1029
- const { fileManager, resolvePath, resolveName, logger } = options;
1041
+ const { fileManager, pluginManager, resolvePath, resolveName, logger } = options;
1030
1042
  return {
1031
1043
  name: pluginName,
1032
1044
  options,
@@ -1040,6 +1052,7 @@ var definePlugin = createPlugin((options) => {
1040
1052
  },
1041
1053
  logger,
1042
1054
  fileManager,
1055
+ pluginManager,
1043
1056
  async addFile(...files) {
1044
1057
  return Promise.all(
1045
1058
  files.map((file) => {
@@ -1068,6 +1081,9 @@ var definePlugin = createPlugin((options) => {
1068
1081
  };
1069
1082
  });
1070
1083
  var EventEmitter = class {
1084
+ constructor() {
1085
+ this.emitter.setMaxListeners(100);
1086
+ }
1071
1087
  emitter = new EventEmitter$1();
1072
1088
  emit(eventName, ...eventArg) {
1073
1089
  this.emitter.emit(eventName, ...eventArg);
@@ -1078,6 +1094,9 @@ var EventEmitter = class {
1078
1094
  off(eventName, handler) {
1079
1095
  this.emitter.off(eventName, handler);
1080
1096
  }
1097
+ removeAll() {
1098
+ this.emitter.removeAllListeners();
1099
+ }
1081
1100
  };
1082
1101
 
1083
1102
  // src/managers/pluginManager/ParallelPluginError.ts
@@ -1145,11 +1164,11 @@ var hooks = Object.keys(hookNames);
1145
1164
  var PluginManager = class {
1146
1165
  plugins;
1147
1166
  fileManager;
1148
- core;
1167
+ eventEmitter = new EventEmitter();
1149
1168
  queue;
1150
1169
  executed = [];
1151
1170
  logger;
1152
- eventEmitter = new EventEmitter();
1171
+ core;
1153
1172
  constructor(config, options) {
1154
1173
  this.logger = options.logger;
1155
1174
  this.queue = new Queue(100, options.debug);
@@ -1157,6 +1176,7 @@ var PluginManager = class {
1157
1176
  const core = definePlugin({
1158
1177
  config,
1159
1178
  logger: this.logger,
1179
+ pluginManager: this,
1160
1180
  fileManager: this.fileManager,
1161
1181
  resolvePath: this.resolvePath.bind(this),
1162
1182
  resolveName: this.resolveName.bind(this),