@kubb/core 1.15.0-canary.20231026T131818 → 1.15.0-canary.20231026T182312

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/utils.cjs CHANGED
@@ -44,6 +44,37 @@ var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
44
44
  var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
45
45
  var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
46
46
 
47
+ var __accessCheck = (obj, member, msg) => {
48
+ if (!member.has(obj))
49
+ throw TypeError("Cannot " + msg);
50
+ };
51
+ var __privateGet = (obj, member, getter) => {
52
+ __accessCheck(obj, member, "read from private field");
53
+ return getter ? getter.call(obj) : member.get(obj);
54
+ };
55
+ var __privateAdd = (obj, member, value) => {
56
+ if (member.has(obj))
57
+ throw TypeError("Cannot add the same private member more than once");
58
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
59
+ };
60
+ var __privateSet = (obj, member, value, setter) => {
61
+ __accessCheck(obj, member, "write to private field");
62
+ setter ? setter.call(obj, value) : member.set(obj, value);
63
+ return value;
64
+ };
65
+ var __privateWrapper = (obj, member, setter, getter) => ({
66
+ set _(value) {
67
+ __privateSet(obj, member, value, setter);
68
+ },
69
+ get _() {
70
+ return __privateGet(obj, member, getter);
71
+ }
72
+ });
73
+ var __privateMethod = (obj, member, method) => {
74
+ __accessCheck(obj, member, "access private method");
75
+ return method;
76
+ };
77
+
47
78
  // src/utils/cache.ts
48
79
  function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
49
80
  return {
@@ -75,9 +106,8 @@ async function clean(path2) {
75
106
  return fs2.remove(path2);
76
107
  }
77
108
  var FunctionParams = class {
78
- type;
79
- items = [];
80
109
  constructor(type) {
110
+ this.items = [];
81
111
  this.type = type;
82
112
  return this;
83
113
  }
@@ -166,88 +196,97 @@ function isPromiseFulfilledResult(result) {
166
196
  function isPromiseRejectedResult(result) {
167
197
  return result.status === "rejected";
168
198
  }
199
+ var _emitter;
169
200
  var EventEmitter = class {
170
201
  constructor() {
171
- this.#emitter.setMaxListeners(100);
202
+ __privateAdd(this, _emitter, new events.EventEmitter());
203
+ __privateGet(this, _emitter).setMaxListeners(100);
172
204
  }
173
- #emitter = new events.EventEmitter();
174
205
  emit(eventName, ...eventArg) {
175
- this.#emitter.emit(eventName, ...eventArg);
206
+ __privateGet(this, _emitter).emit(eventName, ...eventArg);
176
207
  }
177
208
  on(eventName, handler) {
178
- this.#emitter.on(eventName, handler);
209
+ __privateGet(this, _emitter).on(eventName, handler);
179
210
  }
180
211
  off(eventName, handler) {
181
- this.#emitter.off(eventName, handler);
212
+ __privateGet(this, _emitter).off(eventName, handler);
182
213
  }
183
214
  removeAll() {
184
- this.#emitter.removeAllListeners();
215
+ __privateGet(this, _emitter).removeAllListeners();
185
216
  }
186
217
  };
218
+ _emitter = new WeakMap();
187
219
 
188
220
  // src/utils/Queue.ts
221
+ var _queue, _workerCount, _maxParallel, _debug, _work, work_fn;
189
222
  var Queue = class {
190
- #queue = [];
191
- eventEmitter = new EventEmitter();
192
- #workerCount = 0;
193
- #maxParallel;
194
- #debug = false;
195
223
  constructor(maxParallel, debug = false) {
196
- this.#maxParallel = maxParallel;
197
- this.#debug = debug;
224
+ __privateAdd(this, _work);
225
+ __privateAdd(this, _queue, []);
226
+ this.eventEmitter = new EventEmitter();
227
+ __privateAdd(this, _workerCount, 0);
228
+ __privateAdd(this, _maxParallel, void 0);
229
+ __privateAdd(this, _debug, false);
230
+ __privateSet(this, _maxParallel, maxParallel);
231
+ __privateSet(this, _debug, debug);
198
232
  }
199
233
  run(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
200
234
  return new Promise((resolve2, reject) => {
201
235
  const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
202
236
  options.controller?.signal.addEventListener("abort", () => {
203
- this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
237
+ __privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
204
238
  reject("Aborted");
205
239
  });
206
- this.#queue.push(item);
207
- this.#work();
240
+ __privateGet(this, _queue).push(item);
241
+ __privateMethod(this, _work, work_fn).call(this);
208
242
  });
209
243
  }
210
244
  runSync(job, options = { controller: new AbortController(), name: crypto__default.default.randomUUID(), description: "" }) {
211
245
  new Promise((resolve2, reject) => {
212
246
  const item = { reject, resolve: resolve2, job, name: options.name, description: options.description || options.name };
213
247
  options.controller?.signal.addEventListener("abort", () => {
214
- this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name);
248
+ __privateSet(this, _queue, __privateGet(this, _queue).filter((queueItem) => queueItem.name === item.name));
215
249
  });
216
- this.#queue.push(item);
217
- this.#work();
250
+ __privateGet(this, _queue).push(item);
251
+ __privateMethod(this, _work, work_fn).call(this);
218
252
  });
219
253
  }
220
254
  get hasJobs() {
221
- return this.#workerCount > 0 || this.#queue.length > 0;
255
+ return __privateGet(this, _workerCount) > 0 || __privateGet(this, _queue).length > 0;
222
256
  }
223
257
  get count() {
224
- return this.#workerCount;
258
+ return __privateGet(this, _workerCount);
225
259
  }
226
- #work() {
227
- if (this.#workerCount >= this.#maxParallel) {
228
- return;
260
+ };
261
+ _queue = new WeakMap();
262
+ _workerCount = new WeakMap();
263
+ _maxParallel = new WeakMap();
264
+ _debug = new WeakMap();
265
+ _work = new WeakSet();
266
+ work_fn = function() {
267
+ if (__privateGet(this, _workerCount) >= __privateGet(this, _maxParallel)) {
268
+ return;
269
+ }
270
+ __privateWrapper(this, _workerCount)._++;
271
+ let entry;
272
+ while (entry = __privateGet(this, _queue).shift()) {
273
+ const { reject, resolve: resolve2, job, name, description } = entry;
274
+ if (__privateGet(this, _debug)) {
275
+ perf_hooks.performance.mark(name + "_start");
229
276
  }
230
- this.#workerCount++;
231
- let entry;
232
- while (entry = this.#queue.shift()) {
233
- const { reject, resolve: resolve2, job, name, description } = entry;
234
- if (this.#debug) {
235
- perf_hooks.performance.mark(name + "_start");
277
+ job().then((result) => {
278
+ this.eventEmitter.emit("jobDone", result);
279
+ resolve2(result);
280
+ if (__privateGet(this, _debug)) {
281
+ perf_hooks.performance.mark(name + "_stop");
282
+ perf_hooks.performance.measure(description, name + "_start", name + "_stop");
236
283
  }
237
- job().then((result) => {
238
- this.eventEmitter.emit("jobDone", result);
239
- resolve2(result);
240
- if (this.#debug) {
241
- perf_hooks.performance.mark(name + "_stop");
242
- perf_hooks.performance.measure(description, name + "_start", name + "_stop");
243
- }
244
- }).catch((err) => {
245
- this.eventEmitter.emit("jobFailed", err);
246
- reject(err);
247
- });
248
- }
249
- this.#workerCount--;
284
+ }).catch((err) => {
285
+ this.eventEmitter.emit("jobFailed", err);
286
+ reject(err);
287
+ });
250
288
  }
289
+ __privateWrapper(this, _workerCount)._--;
251
290
  };
252
291
  var defaultColours = ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
253
292
  function randomColour(text, colours = defaultColours) {
@@ -623,14 +662,15 @@ async function write(data, path2) {
623
662
  }
624
663
  return writer(path2, data.trim());
625
664
  }
665
+ var _options;
626
666
  var BarrelManager = class {
627
- #options = {};
628
667
  constructor(options = {}) {
629
- this.#options = options;
668
+ __privateAdd(this, _options, {});
669
+ __privateSet(this, _options, options);
630
670
  return this;
631
671
  }
632
672
  getIndexes(root, extName) {
633
- const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = this.#options;
673
+ const { treeNode = {}, isTypeOnly, filter, map, output, includeExt } = __privateGet(this, _options);
634
674
  const extMapper = {
635
675
  ".ts": {
636
676
  extensions: /\.ts/,
@@ -699,50 +739,47 @@ var BarrelManager = class {
699
739
  return map ? filteredFiles.map(map) : filteredFiles;
700
740
  }
701
741
  };
742
+ _options = new WeakMap();
702
743
 
703
744
  // src/FileManager.ts
704
- var FileManager = class _FileManager {
705
- #cache = /* @__PURE__ */ new Map();
706
- #task;
707
- #isWriting = false;
708
- /**
709
- * Timeout between writes
710
- */
711
- #timeout = 0;
712
- #queue;
745
+ var _cache, _task, _isWriting, _timeout, _queue2, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
746
+ var _FileManager = class _FileManager {
713
747
  constructor(options) {
748
+ __privateAdd(this, _validate);
749
+ __privateAdd(this, _add);
750
+ __privateAdd(this, _addOrAppend);
751
+ __privateAdd(this, _cache, /* @__PURE__ */ new Map());
752
+ __privateAdd(this, _task, void 0);
753
+ __privateAdd(this, _isWriting, false);
754
+ /**
755
+ * Timeout between writes
756
+ */
757
+ __privateAdd(this, _timeout, 0);
758
+ __privateAdd(this, _queue2, void 0);
714
759
  if (options) {
715
- this.#task = options.task;
716
- this.#queue = options.queue;
717
- this.#timeout = options.timeout || 0;
760
+ __privateSet(this, _task, options.task);
761
+ __privateSet(this, _queue2, options.queue);
762
+ __privateSet(this, _timeout, options.timeout || 0);
718
763
  }
719
764
  return this;
720
765
  }
721
766
  get files() {
722
767
  const files = [];
723
- this.#cache.forEach((item) => {
768
+ __privateGet(this, _cache).forEach((item) => {
724
769
  files.push(...item.flat(1));
725
770
  });
726
771
  return files;
727
772
  }
728
773
  get isExecuting() {
729
- return this.#queue?.hasJobs ?? this.#isWriting ?? false;
730
- }
731
- #validate(file) {
732
- if (!file.validate) {
733
- return;
734
- }
735
- if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
736
- throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
737
- }
774
+ return __privateGet(this, _queue2)?.hasJobs ?? __privateGet(this, _isWriting) ?? false;
738
775
  }
739
776
  async add(...files) {
740
777
  const promises = files.map((file) => {
741
- this.#validate(file);
778
+ __privateMethod(this, _validate, validate_fn).call(this, file);
742
779
  if (file.override) {
743
- return this.#add(file);
780
+ return __privateMethod(this, _add, add_fn).call(this, file);
744
781
  }
745
- return this.#addOrAppend(file);
782
+ return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, file);
746
783
  });
747
784
  const resolvedFiles = await Promise.all(promises);
748
785
  if (files.length > 1) {
@@ -750,36 +787,6 @@ var FileManager = class _FileManager {
750
787
  }
751
788
  return resolvedFiles[0];
752
789
  }
753
- async #add(file) {
754
- const controller = new AbortController();
755
- const resolvedFile = { id: crypto__default.default.randomUUID(), ...file };
756
- this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
757
- if (this.#queue) {
758
- await this.#queue.run(
759
- async () => {
760
- return this.#task?.(resolvedFile);
761
- },
762
- { controller }
763
- );
764
- }
765
- return resolvedFile;
766
- }
767
- async #addOrAppend(file) {
768
- const previousCaches = this.#cache.get(file.path);
769
- const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
770
- if (previousCache) {
771
- this.#cache.delete(previousCache.path);
772
- return this.#add({
773
- ...file,
774
- source: previousCache.source && file.source ? `${previousCache.source}
775
- ${file.source}` : "",
776
- imports: [...previousCache.imports || [], ...file.imports || []],
777
- exports: [...previousCache.exports || [], ...file.exports || []],
778
- env: { ...previousCache.env || {}, ...file.env || {} }
779
- });
780
- }
781
- return this.#add(file);
782
- }
783
790
  async addIndexes({ root, extName = ".ts", meta, options = {} }) {
784
791
  const barrelManager = new BarrelManager(options);
785
792
  const files = barrelManager.getIndexes(root, extName);
@@ -788,7 +795,7 @@ ${file.source}` : "",
788
795
  }
789
796
  return await Promise.all(
790
797
  files.map((file) => {
791
- return this.#addOrAppend({
798
+ return __privateMethod(this, _addOrAppend, addOrAppend_fn).call(this, {
792
799
  ...file,
793
800
  meta: meta ? meta : file.meta
794
801
  });
@@ -797,29 +804,29 @@ ${file.source}` : "",
797
804
  }
798
805
  getCacheByUUID(UUID) {
799
806
  let cache;
800
- this.#cache.forEach((files) => {
807
+ __privateGet(this, _cache).forEach((files) => {
801
808
  cache = files.find((item) => item.id === UUID);
802
809
  });
803
810
  return cache;
804
811
  }
805
812
  get(path2) {
806
- return this.#cache.get(path2);
813
+ return __privateGet(this, _cache).get(path2);
807
814
  }
808
815
  remove(path2) {
809
816
  const cacheItem = this.get(path2);
810
817
  if (!cacheItem) {
811
818
  return;
812
819
  }
813
- this.#cache.delete(path2);
820
+ __privateGet(this, _cache).delete(path2);
814
821
  }
815
822
  async write(...params) {
816
- if (!this.#isWriting) {
817
- this.#isWriting = true;
823
+ if (!__privateGet(this, _isWriting)) {
824
+ __privateSet(this, _isWriting, true);
818
825
  const text = await write(...params);
819
- this.#isWriting = false;
826
+ __privateSet(this, _isWriting, false);
820
827
  return text;
821
828
  }
822
- await timeout(this.#timeout);
829
+ await timeout(__privateGet(this, _timeout));
823
830
  return this.write(...params);
824
831
  }
825
832
  async read(...params) {
@@ -879,6 +886,54 @@ ${file.source}` : "",
879
886
  return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
880
887
  }
881
888
  };
889
+ _cache = new WeakMap();
890
+ _task = new WeakMap();
891
+ _isWriting = new WeakMap();
892
+ _timeout = new WeakMap();
893
+ _queue2 = new WeakMap();
894
+ _validate = new WeakSet();
895
+ validate_fn = function(file) {
896
+ if (!file.validate) {
897
+ return;
898
+ }
899
+ if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
900
+ throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
901
+ }
902
+ };
903
+ _add = new WeakSet();
904
+ add_fn = async function(file) {
905
+ const controller = new AbortController();
906
+ const resolvedFile = { id: crypto__default.default.randomUUID(), ...file };
907
+ __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
908
+ if (__privateGet(this, _queue2)) {
909
+ await __privateGet(this, _queue2).run(
910
+ async () => {
911
+ var _a;
912
+ return (_a = __privateGet(this, _task)) == null ? void 0 : _a.call(this, resolvedFile);
913
+ },
914
+ { controller }
915
+ );
916
+ }
917
+ return resolvedFile;
918
+ };
919
+ _addOrAppend = new WeakSet();
920
+ addOrAppend_fn = async function(file) {
921
+ const previousCaches = __privateGet(this, _cache).get(file.path);
922
+ const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
923
+ if (previousCache) {
924
+ __privateGet(this, _cache).delete(previousCache.path);
925
+ return __privateMethod(this, _add, add_fn).call(this, {
926
+ ...file,
927
+ source: previousCache.source && file.source ? `${previousCache.source}
928
+ ${file.source}` : "",
929
+ imports: [...previousCache.imports || [], ...file.imports || []],
930
+ exports: [...previousCache.exports || [], ...file.exports || []],
931
+ env: { ...previousCache.env || {}, ...file.env || {} }
932
+ });
933
+ }
934
+ return __privateMethod(this, _add, add_fn).call(this, file);
935
+ };
936
+ var FileManager = _FileManager;
882
937
  function combineExports(exports) {
883
938
  const combinedExports = naturalOrderby.orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce((prev, curr) => {
884
939
  const name = curr.name;
@@ -977,10 +1032,8 @@ function getEnvSource(source, env) {
977
1032
 
978
1033
  // src/utils/TreeNode.ts
979
1034
  var TreeNode = class _TreeNode {
980
- data;
981
- parent;
982
- children = [];
983
1035
  constructor(data, parent) {
1036
+ this.children = [];
984
1037
  this.data = data;
985
1038
  this.parent = parent;
986
1039
  return this;
@@ -1084,7 +1137,6 @@ function setUniqueName(originalName, data) {
1084
1137
  return originalName;
1085
1138
  }
1086
1139
  var URLPath = class {
1087
- path;
1088
1140
  constructor(path2) {
1089
1141
  this.path = path2;
1090
1142
  return this;