@kubb/core 2.0.0-alpha.1 → 2.0.0-canary.20231029T125324

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.cjs CHANGED
@@ -713,6 +713,9 @@ var BarrelManager = class {
713
713
  _options = new WeakMap();
714
714
 
715
715
  // src/FileManager.ts
716
+ exports.KubbFile = void 0;
717
+ ((KubbFile2) => {
718
+ })(exports.KubbFile || (exports.KubbFile = {}));
716
719
  var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
717
720
  var _FileManager = class _FileManager {
718
721
  constructor(options) {
@@ -1230,21 +1233,34 @@ var definePlugin = createPlugin((options) => {
1230
1233
 
1231
1234
  // src/utils/executeStrategies.ts
1232
1235
  function hookSeq(promises) {
1233
- return promises.reduce(
1236
+ return promises.filter(Boolean).reduce(
1234
1237
  (promise, func) => {
1235
- if (!func || typeof func !== "function") {
1238
+ if (typeof func !== "function") {
1236
1239
  throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
1237
1240
  }
1238
- return promise.then((result) => {
1239
- const calledFunc = func();
1241
+ return promise.then((state) => {
1242
+ const calledFunc = func(state);
1240
1243
  if (calledFunc) {
1241
- return calledFunc.then(Array.prototype.concat.bind(result));
1244
+ return calledFunc.then(Array.prototype.concat.bind(state));
1242
1245
  }
1243
1246
  });
1244
1247
  },
1245
1248
  Promise.resolve([])
1246
1249
  );
1247
1250
  }
1251
+ function hookFirst(promises, nullCheck = (state) => state !== null) {
1252
+ let promise = Promise.resolve(null);
1253
+ for (const func of promises.filter(Boolean)) {
1254
+ promise = promise.then((state) => {
1255
+ if (nullCheck(state)) {
1256
+ return state;
1257
+ }
1258
+ const calledFunc = func(state);
1259
+ return calledFunc;
1260
+ });
1261
+ }
1262
+ return promise;
1263
+ }
1248
1264
 
1249
1265
  // src/PromiseManager.ts
1250
1266
  var _options2;
@@ -1258,6 +1274,9 @@ var PromiseManager = class {
1258
1274
  if (strategy === "seq") {
1259
1275
  return hookSeq(promises);
1260
1276
  }
1277
+ if (strategy === "first") {
1278
+ return hookFirst(promises, __privateGet(this, _options2).nullCheck);
1279
+ }
1261
1280
  throw new Error(`${strategy} not implemented`);
1262
1281
  }
1263
1282
  };
@@ -1344,7 +1363,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1344
1363
  this.logger = options.logger;
1345
1364
  this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
1346
1365
  this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
1347
- __privateSet(this, _promiseManager, new PromiseManager());
1366
+ __privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
1348
1367
  const plugins = config.plugins || [];
1349
1368
  const core = definePlugin({
1350
1369
  config,
@@ -1401,20 +1420,15 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1401
1420
  /**
1402
1421
  * Chains, first non-null result stops and returns
1403
1422
  */
1404
- hookFirst({
1423
+ async hookFirst({
1405
1424
  hookName,
1406
1425
  parameters,
1407
1426
  skipped
1408
1427
  }) {
1409
- let promise = Promise.resolve(null);
1410
- for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1411
- if (skipped && skipped.has(plugin)) {
1412
- continue;
1413
- }
1414
- promise = promise.then(async (parseResult) => {
1415
- if (parseResult?.result != null) {
1416
- return parseResult;
1417
- }
1428
+ const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).filter((plugin) => {
1429
+ return skipped ? skipped.has(plugin) : true;
1430
+ }).map((plugin) => {
1431
+ return async () => {
1418
1432
  const value = await __privateMethod(this, _execute, execute_fn).call(this, {
1419
1433
  strategy: "hookFirst",
1420
1434
  hookName,
@@ -1427,9 +1441,9 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1427
1441
  result: value
1428
1442
  }
1429
1443
  );
1430
- });
1431
- }
1432
- return promise;
1444
+ };
1445
+ });
1446
+ return __privateGet(this, _promiseManager).run("first", promises);
1433
1447
  }
1434
1448
  /**
1435
1449
  * Chains, first non-null result stops and returns
@@ -1511,7 +1525,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1511
1525
  /**
1512
1526
  * Chains plugins
1513
1527
  */
1514
- hookSeq({ hookName, parameters }) {
1528
+ async hookSeq({ hookName, parameters }) {
1515
1529
  const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
1516
1530
  return () => __privateMethod(this, _execute, execute_fn).call(this, {
1517
1531
  strategy: "hookSeq",