@kubb/core 2.0.0-canary.20231027T203719 → 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.d.cts CHANGED
@@ -58,6 +58,10 @@ declare namespace KubbFile {
58
58
  isTypeOnly?: boolean;
59
59
  asAlias?: boolean;
60
60
  };
61
+ const dataTagSymbol: unique symbol;
62
+ type DataTag<Type, Value> = Type & {
63
+ [dataTagSymbol]: Value;
64
+ };
61
65
  type UUID = string;
62
66
  type Source = string;
63
67
  type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
@@ -101,7 +105,7 @@ declare namespace KubbFile {
101
105
  env?: NodeJS.ProcessEnv;
102
106
  validate?: boolean;
103
107
  };
104
- type ResolvedFile = KubbFile.File & {
108
+ type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
105
109
  /**
106
110
  * @default crypto.randomUUID()
107
111
  */
@@ -669,14 +673,21 @@ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> =
669
673
  declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
670
674
  declare const pluginName = "core";
671
675
 
672
- type PromiseFunc<T, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
673
- type SeqOutput<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown> = ReturnType<NonNullable<TInput[number]>>;
674
- type Options = {};
675
- type Strategy = 'seq';
676
- declare class PromiseManager {
676
+ type PromiseFunc$1<T = unknown, T2 = never> = (state: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
677
+ type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
678
+ type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
679
+ type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
680
+ type Strategy = 'seq' | 'first';
681
+ type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : never;
682
+
683
+ type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
684
+ type Options<TState = any> = {
685
+ nullCheck?: (state: TState) => boolean;
686
+ };
687
+ declare class PromiseManager<TState = any> {
677
688
  #private;
678
- constructor(options?: Options);
679
- run<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown, TOutput = SeqOutput<TInput, TPromise>>(strategy: Strategy, promises: TInput): TOutput;
689
+ constructor(options?: Options<TState>);
690
+ run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
680
691
  }
681
692
 
682
693
  /**
package/dist/index.d.ts CHANGED
@@ -58,6 +58,10 @@ declare namespace KubbFile {
58
58
  isTypeOnly?: boolean;
59
59
  asAlias?: boolean;
60
60
  };
61
+ const dataTagSymbol: unique symbol;
62
+ type DataTag<Type, Value> = Type & {
63
+ [dataTagSymbol]: Value;
64
+ };
61
65
  type UUID = string;
62
66
  type Source = string;
63
67
  type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
@@ -101,7 +105,7 @@ declare namespace KubbFile {
101
105
  env?: NodeJS.ProcessEnv;
102
106
  validate?: boolean;
103
107
  };
104
- type ResolvedFile = KubbFile.File & {
108
+ type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
105
109
  /**
106
110
  * @default crypto.randomUUID()
107
111
  */
@@ -669,14 +673,21 @@ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> =
669
673
  declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
670
674
  declare const pluginName = "core";
671
675
 
672
- type PromiseFunc<T, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
673
- type SeqOutput<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown> = ReturnType<NonNullable<TInput[number]>>;
674
- type Options = {};
675
- type Strategy = 'seq';
676
- declare class PromiseManager {
676
+ type PromiseFunc$1<T = unknown, T2 = never> = (state: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
677
+ type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
678
+ type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
679
+ type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
680
+ type Strategy = 'seq' | 'first';
681
+ type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : never;
682
+
683
+ type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
684
+ type Options<TState = any> = {
685
+ nullCheck?: (state: TState) => boolean;
686
+ };
687
+ declare class PromiseManager<TState = any> {
677
688
  #private;
678
- constructor(options?: Options);
679
- run<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown, TOutput = SeqOutput<TInput, TPromise>>(strategy: Strategy, promises: TInput): TOutput;
689
+ constructor(options?: Options<TState>);
690
+ run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
680
691
  }
681
692
 
682
693
  /**
package/dist/index.js CHANGED
@@ -671,6 +671,9 @@ var BarrelManager = class {
671
671
  _options = new WeakMap();
672
672
 
673
673
  // src/FileManager.ts
674
+ var KubbFile;
675
+ ((KubbFile2) => {
676
+ })(KubbFile || (KubbFile = {}));
674
677
  var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
675
678
  var _FileManager = class _FileManager {
676
679
  constructor(options) {
@@ -1188,21 +1191,34 @@ var definePlugin = createPlugin((options) => {
1188
1191
 
1189
1192
  // src/utils/executeStrategies.ts
1190
1193
  function hookSeq(promises) {
1191
- return promises.reduce(
1194
+ return promises.filter(Boolean).reduce(
1192
1195
  (promise, func) => {
1193
- if (!func || typeof func !== "function") {
1196
+ if (typeof func !== "function") {
1194
1197
  throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
1195
1198
  }
1196
- return promise.then((result) => {
1197
- const calledFunc = func();
1199
+ return promise.then((state) => {
1200
+ const calledFunc = func(state);
1198
1201
  if (calledFunc) {
1199
- return calledFunc.then(Array.prototype.concat.bind(result));
1202
+ return calledFunc.then(Array.prototype.concat.bind(state));
1200
1203
  }
1201
1204
  });
1202
1205
  },
1203
1206
  Promise.resolve([])
1204
1207
  );
1205
1208
  }
1209
+ function hookFirst(promises, nullCheck = (state) => state !== null) {
1210
+ let promise = Promise.resolve(null);
1211
+ for (const func of promises.filter(Boolean)) {
1212
+ promise = promise.then((state) => {
1213
+ if (nullCheck(state)) {
1214
+ return state;
1215
+ }
1216
+ const calledFunc = func(state);
1217
+ return calledFunc;
1218
+ });
1219
+ }
1220
+ return promise;
1221
+ }
1206
1222
 
1207
1223
  // src/PromiseManager.ts
1208
1224
  var _options2;
@@ -1216,6 +1232,9 @@ var PromiseManager = class {
1216
1232
  if (strategy === "seq") {
1217
1233
  return hookSeq(promises);
1218
1234
  }
1235
+ if (strategy === "first") {
1236
+ return hookFirst(promises, __privateGet(this, _options2).nullCheck);
1237
+ }
1219
1238
  throw new Error(`${strategy} not implemented`);
1220
1239
  }
1221
1240
  };
@@ -1302,7 +1321,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1302
1321
  this.logger = options.logger;
1303
1322
  this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
1304
1323
  this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
1305
- __privateSet(this, _promiseManager, new PromiseManager());
1324
+ __privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
1306
1325
  const plugins = config.plugins || [];
1307
1326
  const core = definePlugin({
1308
1327
  config,
@@ -1359,20 +1378,15 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1359
1378
  /**
1360
1379
  * Chains, first non-null result stops and returns
1361
1380
  */
1362
- hookFirst({
1381
+ async hookFirst({
1363
1382
  hookName,
1364
1383
  parameters,
1365
1384
  skipped
1366
1385
  }) {
1367
- let promise = Promise.resolve(null);
1368
- for (const plugin of __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)) {
1369
- if (skipped && skipped.has(plugin)) {
1370
- continue;
1371
- }
1372
- promise = promise.then(async (parseResult) => {
1373
- if (parseResult?.result != null) {
1374
- return parseResult;
1375
- }
1386
+ const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).filter((plugin) => {
1387
+ return skipped ? skipped.has(plugin) : true;
1388
+ }).map((plugin) => {
1389
+ return async () => {
1376
1390
  const value = await __privateMethod(this, _execute, execute_fn).call(this, {
1377
1391
  strategy: "hookFirst",
1378
1392
  hookName,
@@ -1385,9 +1399,9 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1385
1399
  result: value
1386
1400
  }
1387
1401
  );
1388
- });
1389
- }
1390
- return promise;
1402
+ };
1403
+ });
1404
+ return __privateGet(this, _promiseManager).run("first", promises);
1391
1405
  }
1392
1406
  /**
1393
1407
  * Chains, first non-null result stops and returns
@@ -1469,7 +1483,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1469
1483
  /**
1470
1484
  * Chains plugins
1471
1485
  */
1472
- hookSeq({ hookName, parameters }) {
1486
+ async hookSeq({ hookName, parameters }) {
1473
1487
  const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
1474
1488
  return () => __privateMethod(this, _execute, execute_fn).call(this, {
1475
1489
  strategy: "hookSeq",
@@ -1916,6 +1930,6 @@ var SchemaGenerator = class extends Generator {
1916
1930
  // src/index.ts
1917
1931
  var src_default = build;
1918
1932
 
1919
- export { FileManager, Generator, PackageManager, ParallelPluginError, PluginError, PluginManager, PromiseManager, SchemaGenerator, SummaryError, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName };
1933
+ export { FileManager, Generator, KubbFile, PackageManager, ParallelPluginError, PluginError, PluginManager, PromiseManager, SchemaGenerator, SummaryError, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName };
1920
1934
  //# sourceMappingURL=out.js.map
1921
1935
  //# sourceMappingURL=index.js.map