@kubb/core 1.2.4 → 1.3.1

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.js CHANGED
@@ -164,13 +164,30 @@ var Queue = class {
164
164
  this.maxParallel = maxParallel;
165
165
  this.debug = debug;
166
166
  }
167
- run(task, options = { name: crypto.randomUUID(), description: "" }) {
167
+ run(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
168
168
  return new Promise((resolve, reject) => {
169
- const item = { reject, resolve, task, name: options.name, description: options.description || options.name };
169
+ const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
170
+ options.controller?.signal.addEventListener("abort", () => {
171
+ this.queue = this.queue.filter((queueItem) => queueItem.name === item.name);
172
+ reject("Aborted");
173
+ });
174
+ this.queue.push(item);
175
+ this.work();
176
+ });
177
+ }
178
+ runSync(job, options = { controller: new AbortController(), name: crypto.randomUUID(), description: "" }) {
179
+ new Promise((resolve, reject) => {
180
+ const item = { reject, resolve, job, name: options.name, description: options.description || options.name };
181
+ options.controller?.signal.addEventListener("abort", () => {
182
+ this.queue = this.queue.filter((queueItem) => queueItem.name === item.name);
183
+ });
170
184
  this.queue.push(item);
171
185
  this.work();
172
186
  });
173
187
  }
188
+ get hasJobs() {
189
+ return this.workerCount > 0 || this.queue.length > 0;
190
+ }
174
191
  work() {
175
192
  if (this.workerCount >= this.maxParallel) {
176
193
  return;
@@ -178,11 +195,11 @@ var Queue = class {
178
195
  this.workerCount++;
179
196
  let entry;
180
197
  while (entry = this.queue.shift()) {
181
- const { reject, resolve, task, name, description } = entry;
198
+ const { reject, resolve, job, name, description } = entry;
182
199
  if (this.debug) {
183
200
  performance.mark(name + "_start");
184
201
  }
185
- task().then((result) => {
202
+ job().then((result) => {
186
203
  resolve(result);
187
204
  if (this.debug) {
188
205
  performance.mark(name + "_stop");
@@ -616,7 +633,7 @@ var URLPath = class {
616
633
  return false;
617
634
  }
618
635
  };
619
- function writeIndexes(root, options = {}) {
636
+ function getIndexes(root, options = {}) {
620
637
  const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
621
638
  if (!tree) {
622
639
  return null;
@@ -802,13 +819,24 @@ var FileManager = class {
802
819
  });
803
820
  return files;
804
821
  }
822
+ get isExecuting() {
823
+ return this.queue?.hasJobs ?? false;
824
+ }
805
825
  async add(file) {
826
+ const controller = new AbortController();
806
827
  const resolvedFile = { id: crypto.randomUUID(), ...file };
807
- this.cache.set(resolvedFile.path, [resolvedFile]);
828
+ this.cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
808
829
  if (this.queue) {
809
- await this.queue.run(async () => {
810
- await this.task?.(resolvedFile);
811
- });
830
+ try {
831
+ await this.queue.run(
832
+ async () => {
833
+ return this.task?.(resolvedFile);
834
+ },
835
+ { controller }
836
+ );
837
+ } catch {
838
+ return resolvedFile;
839
+ }
812
840
  }
813
841
  return resolvedFile;
814
842
  }
@@ -820,6 +848,7 @@ var FileManager = class {
820
848
  if (sourceAlreadyExists) {
821
849
  return Promise.resolve(previousCache);
822
850
  }
851
+ previousCache.cancel?.();
823
852
  this.cache.delete(previousCache.path);
824
853
  return this.add({
825
854
  ...file,
@@ -1027,7 +1056,7 @@ var PluginManager = class {
1027
1056
  eventEmitter = new EventEmitter();
1028
1057
  constructor(config, options) {
1029
1058
  this.logger = options.logger;
1030
- this.queue = new Queue(100, options.debug);
1059
+ this.queue = new Queue(50, options.debug);
1031
1060
  this.fileManager = new FileManager({ task: options.task, queue: this.queue });
1032
1061
  const core = definePlugin({
1033
1062
  config,
@@ -1485,6 +1514,6 @@ var SchemaGenerator = class extends Generator {
1485
1514
  // src/index.ts
1486
1515
  var src_default = build;
1487
1516
 
1488
- export { FileManager, Generator, LogLevel, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, canLogHierarchy, clean, combineFiles, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defaultColours, defineConfig, extensions, getEncodedText, getFileSource, getLocation, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, importModule, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, pluginName as name, nameSorter, normalizeDirectory, objectToParameters, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueId, validatePlugins, write, writeIndexes };
1517
+ export { FileManager, Generator, LogLevel, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, canLogHierarchy, clean, combineFiles, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defaultColours, defineConfig, extensions, getEncodedText, getFileSource, getIndexes, getLocation, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, importModule, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, pluginName as name, nameSorter, normalizeDirectory, objectToParameters, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueId, validatePlugins, write };
1489
1518
  //# sourceMappingURL=out.js.map
1490
1519
  //# sourceMappingURL=index.js.map