@kubb/core 5.15.1 → 5.15.3

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
@@ -53,6 +53,10 @@ type PossiblePromise<T> = Promise<T> | T;
53
53
  * ```
54
54
  */
55
55
  type LiteralUnion<T extends Base, Base = string> = T | (Base & {});
56
+ /**
57
+ * Union of the values of an object type, such as `ValueOf<typeof nodeKinds>` for an `as const` table.
58
+ */
59
+ type ValueOf<T> = T[keyof T];
56
60
  /**
57
61
  * Converts a resolved {@link FileNode} into the final source string that gets
58
62
  * written to disk. Kubb ships with TypeScript and TSX parsers. Add your own
@@ -344,7 +348,7 @@ declare const diagnosticCode: { readonly [K in keyof typeof diagnosticCatalog]:
344
348
  /**
345
349
  * Union of the stable {@link diagnosticCode} values.
346
350
  */
347
- type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode];
351
+ type DiagnosticCode = ValueOf<typeof diagnosticCode>;
348
352
  /**
349
353
  * How {@link format} renders a diagnostic.
350
354
  */
@@ -508,7 +512,7 @@ type ReporterContext = {
508
512
  * Output verbosity. Use the `logLevel` constants exported from `@kubb/core`
509
513
  * (`silent`, `error`, `warn`, `info`, `verbose`).
510
514
  */
511
- logLevel: (typeof logLevel)[keyof typeof logLevel];
515
+ logLevel: ValueOf<typeof logLevel>;
512
516
  };
513
517
  /**
514
518
  * Host-facing reporter, as installed onto a run. Unlike a Logger (the live TUI view), a reporter
@@ -821,12 +825,6 @@ export declare class Hookable<THooks extends { [K in keyof THooks]: Array<unknow
821
825
  * ```
822
826
  */
823
827
  listenerCount<THookName extends keyof THooks & string>(hookName: THookName): number;
824
- /**
825
- * No-op kept for callers written against the `EventEmitter`-backed version. Listeners are unbounded.
826
- *
827
- * @deprecated There is no listener ceiling anymore.
828
- */
829
- setMaxListeners(_max: number): void;
830
828
  /**
831
829
  * Removes all listeners from every hook channel.
832
830
  *
@@ -909,6 +907,7 @@ declare class FileManager {
909
907
  * memory rather than holding every source, while still overlapping each file's write with the
910
908
  * next file's parse. Files finish in whatever order they parse, so each finished file flushes the
911
909
  * run of finished files ahead of it as one `kubb:files:processing:update`, keeping rows in input order.
910
+ * Each parsed source goes out once on `kubb:file:processed`, so listeners read it without the pool holding it.
912
911
  *
913
912
  * A file the storage already holds is skipped, so a rebuild that generates identical output
914
913
  * writes nothing and leaves every mtime where it was. `kubb:files:processing:end` lists the
@@ -991,7 +990,7 @@ export declare class KubbDriver {
991
990
  /** Reads `plugin.resolver`, falling back to a fresh default for a name that is not a registered plugin. */
992
991
  getResolver<TName extends PluginName>(pluginName: TName): ResolvePluginOptions<TName>['resolver'];
993
992
  memo<TKey extends MemoKey, TValue extends MemoValue<TKey>>(key: TKey, compute: () => TValue): TValue;
994
- getContext<TOptions extends PluginType>(plugin: NormalizedPlugin<TOptions>): Omit<GeneratorContext<TOptions>, 'options' | 'cache'>;
993
+ getContext<TOptions extends PluginType>(plugin: NormalizedPlugin<TOptions>): Omit<GeneratorContext<TOptions>, 'options'>;
995
994
  getPlugin<TName extends PluginName>(pluginName: TName): Plugin<ResolvePluginOptions<TName>> | undefined;
996
995
  /**
997
996
  * Like `getPlugin` but throws a descriptive error when the plugin is not found.
@@ -1402,13 +1401,14 @@ declare global {
1402
1401
  'kubb:hook:start': [ctx: KubbHookStartContext];
1403
1402
  'kubb:hook:line': [ctx: KubbHookLineContext];
1404
1403
  'kubb:hook:end': [ctx: KubbHookEndContext];
1405
- 'kubb:info': [ctx: KubbInfoContext];
1404
+ 'kubb:info': [ctx: KubbMessageContext];
1406
1405
  'kubb:error': [ctx: KubbErrorContext];
1407
- 'kubb:success': [ctx: KubbSuccessContext];
1408
- 'kubb:warn': [ctx: KubbWarnContext];
1406
+ 'kubb:success': [ctx: KubbMessageContext];
1407
+ 'kubb:warn': [ctx: KubbMessageContext];
1409
1408
  'kubb:diagnostic': [ctx: KubbDiagnosticContext];
1410
1409
  'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext];
1411
1410
  'kubb:files:processing:update': [ctx: KubbFilesProcessingUpdateContext];
1411
+ 'kubb:file:processed': [ctx: KubbFileProcessedContext];
1412
1412
  'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext];
1413
1413
  'kubb:plugin:start': [ctx: KubbPluginStartContext];
1414
1414
  'kubb:plugin:end': [ctx: KubbPluginEndContext];
@@ -1557,9 +1557,6 @@ export type KubbMessageContext = {
1557
1557
  */
1558
1558
  info?: string;
1559
1559
  };
1560
- export type KubbInfoContext = KubbMessageContext;
1561
- export type KubbSuccessContext = KubbMessageContext;
1562
- export type KubbWarnContext = KubbMessageContext;
1563
1560
  export type KubbErrorContext = {
1564
1561
  /**
1565
1562
  * The caught error.
@@ -1616,6 +1613,12 @@ export type KubbFilesProcessingUpdateContext = {
1616
1613
  */
1617
1614
  files: Array<KubbFileProcessingUpdate>;
1618
1615
  };
1616
+ export type KubbFileProcessedContext = {
1617
+ /** The file that was just parsed and handed to the storage. */
1618
+ file: FileNode;
1619
+ /** The parsed content handed to the storage, before it trims the content or an output pass such as a formatter rewrites it. */
1620
+ source: string;
1621
+ };
1619
1622
  export type KubbFilesProcessingEndContext = {
1620
1623
  /**
1621
1624
  * All files that were serialized in this batch.
@@ -2044,36 +2047,6 @@ export declare class Diagnostics {
2044
2047
  */
2045
2048
  static format: typeof format;
2046
2049
  }
2047
- /**
2048
- * Per-node memo shared by every plugin that generates from the same schema or operation node in
2049
- * one generate pass. The driver creates one `NodeCache` per node during the walk and hands the
2050
- * same instance to each plugin's generator context, so work derived purely from the node (its
2051
- * resolved name, imports, parameters) is computed by the first plugin that needs it and reused by
2052
- * the rest instead of being recomputed per plugin.
2053
- *
2054
- * Keys are namespaced by convention (`'plugin-ts:imports'`) so two plugins caching different
2055
- * derivations of the same node never collide.
2056
- *
2057
- * @example Fill on first read, reuse afterwards
2058
- * ```ts
2059
- * const imports = ctx.cache.ensureItem('plugin-ts:imports', () => ctx.resolver.imports({ node, root, output }))
2060
- * ```
2061
- */
2062
- type NodeCache = {
2063
- /**
2064
- * Returns the value stored under `key`, or `undefined` when nothing is stored yet.
2065
- */
2066
- readItem<TValue>(key: string): TValue | undefined;
2067
- /**
2068
- * Stores `value` under `key`, overwriting any previous value, and returns it.
2069
- */
2070
- writeItem<TValue>(key: string, value: TValue): TValue;
2071
- /**
2072
- * Returns the value stored under `key`, computing and storing it with `factory` on the first
2073
- * call. Later calls with the same key return the stored value without running `factory` again.
2074
- */
2075
- ensureItem<TValue>(key: string, factory: () => TValue): TValue;
2076
- };
2077
2050
  /**
2078
2051
  * Context passed to a generator's `schema`, `operation`, and `operations` methods.
2079
2052
  *
@@ -2169,8 +2142,8 @@ type GeneratorContext<TOptions extends PluginType = PluginType> = {
2169
2142
  */
2170
2143
  adapter: Adapter;
2171
2144
  /**
2172
- * Document metadata from the adapter: title, version, base URL, and pre-computed
2173
- * schema index fields (`circularNames`, `enumNames`).
2145
+ * Document metadata from the adapter: title, version, base URL, servers, and security schemes.
2146
+ * Derive schema indexes such as circular or enum names with `memo`.
2174
2147
  */
2175
2148
  meta: InputMeta;
2176
2149
  /**
@@ -2178,15 +2151,9 @@ type GeneratorContext<TOptions extends PluginType = PluginType> = {
2178
2151
  */
2179
2152
  options: TOptions['resolvedOptions'];
2180
2153
  /**
2181
- * Cache scoped to the node being generated, shared by every plugin that generates from that
2182
- * same node in the current pass. Use it to compute node-derived work (resolved names, imports,
2183
- * parameters) once and let the other plugins reuse it. For the `operations` batch call, where
2184
- * there is no single node, the cache is a fresh scratch scope for that call.
2185
- */
2186
- cache: NodeCache;
2187
- /**
2188
- * Cache for the whole build, shared by every plugin, where `cache` is one node and `resolver.memo` is one
2189
- * plugin. Prefix a key with the plugin name unless every plugin wants the same value.
2154
+ * Cache for the whole build, shared by every plugin, where `resolver.memo` is one plugin. Prefix a
2155
+ * key with the plugin name unless every plugin wants the same value, and name the node for
2156
+ * node-derived work, such as `plugin-ts:imports:${node.operationId}`.
2190
2157
  */
2191
2158
  memo: Memo;
2192
2159
  };
@@ -2780,36 +2747,33 @@ export declare function assertPluginOption({ plugin, option, value, allowed }: {
2780
2747
  value: unknown;
2781
2748
  allowed: ReadonlyArray<unknown>;
2782
2749
  }): void;
2783
- type ByTag = {
2784
- /**
2785
- * Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.
2786
- */
2787
- type: 'tag';
2788
- /**
2789
- * Tag name to match (case-sensitive). Can be a literal string or regex pattern.
2790
- */
2791
- pattern: string | RegExp;
2792
- };
2793
- type ByOperationId = {
2794
- /**
2795
- * Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.
2796
- */
2797
- type: 'operationId';
2798
- /**
2799
- * Operation ID to match (case-sensitive). Can be a literal string or regex pattern.
2800
- */
2801
- pattern: string | RegExp;
2802
- };
2803
- type ByPath = {
2750
+ /**
2751
+ * Pattern filter on one operation or schema field: a literal string or a regex, matched case-sensitive.
2752
+ * `tag` matches any of an operation's OpenAPI `tags`, `operationId` its id, `path` its full URL path,
2753
+ * `contentType` a request body content type, and `schemaName` a `#/components/schemas` name.
2754
+ */
2755
+ type ByPattern<T extends 'tag' | 'operationId' | 'path' | 'schemaName' | 'contentType'> = {
2804
2756
  /**
2805
- * Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
2757
+ * Field to match: `'tag'`, `'operationId'`, `'path'`, `'schemaName'`, or `'contentType'`.
2806
2758
  */
2807
- type: 'path';
2759
+ type: T;
2808
2760
  /**
2809
- * URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.
2761
+ * Literal value or regular expression the field must match.
2810
2762
  */
2811
2763
  pattern: string | RegExp;
2812
2764
  };
2765
+ /**
2766
+ * Filter by OpenAPI `tags`.
2767
+ */
2768
+ type ByTag = ByPattern<'tag'>;
2769
+ /**
2770
+ * Filter by OpenAPI `operationId`.
2771
+ */
2772
+ type ByOperationId = ByPattern<'operationId'>;
2773
+ /**
2774
+ * Filter by OpenAPI `path` (URL endpoint), matched against the full path.
2775
+ */
2776
+ type ByPath = ByPattern<'path'>;
2813
2777
  type ByMethod = {
2814
2778
  /**
2815
2779
  * Filter by HTTP method: `'GET'`, `'POST'`, `'PUT'`, `'PATCH'`, `'DELETE'`, `'HEAD'`, `'OPTIONS'`, `'TRACE'`, `'QUERY'`.
@@ -2821,26 +2785,14 @@ type ByMethod = {
2821
2785
  */
2822
2786
  pattern: HttpMethod | RegExp;
2823
2787
  };
2824
- type BySchemaName = {
2825
- /**
2826
- * Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.
2827
- */
2828
- type: 'schemaName';
2829
- /**
2830
- * Schema name to match (case-sensitive). Can be a literal string or regex pattern.
2831
- */
2832
- pattern: string | RegExp;
2833
- };
2834
- type ByContentType = {
2835
- /**
2836
- * Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.
2837
- */
2838
- type: 'contentType';
2839
- /**
2840
- * Content type to match (case-sensitive). Can be a literal string or regex pattern.
2841
- */
2842
- pattern: string | RegExp;
2843
- };
2788
+ /**
2789
+ * Filter by schema component name in `#/components/schemas`.
2790
+ */
2791
+ type BySchemaName = ByPattern<'schemaName'>;
2792
+ /**
2793
+ * Filter by request content type, such as `'application/json'`.
2794
+ */
2795
+ type ByContentType = ByPattern<'contentType'>;
2844
2796
  type ByExtension = {
2845
2797
  /** Filter operations by a vendor extension (`x-*` key) on the source operation. Does not apply to schemas. */
2846
2798
  type: 'extension';
@@ -3403,6 +3355,11 @@ type RunOutputPassesOptions = {
3403
3355
  * ```
3404
3356
  */
3405
3357
  export declare function runOutputPasses({ config, outputPath, hooks, signal }: RunOutputPassesOptions): Promise<Array<Diagnostic>>;
3358
+ /**
3359
+ * Whether anything runs over the output directory after the files are written. Only then can the
3360
+ * bytes on disk stop matching what Kubb wrote, which is what the manifest exists to track.
3361
+ */
3362
+ export declare function hasOutputPasses({ output, storage }: Pick<Config, 'output' | 'storage'>): boolean;
3406
3363
  type CreateKubbOptions = {
3407
3364
  /**
3408
3365
  * Receives Kubb lifecycle hooks for the run.
@@ -3937,5 +3894,5 @@ export declare function readInstalledPackages({ root, packages, resolveFrom }: {
3937
3894
  packages?: Iterable<string>;
3938
3895
  resolveFrom?: Array<string>;
3939
3896
  }): Promise<Array<InstalledPackage>>;
3940
- export type { Adapter, AdapterDefinition, AdapterFactory, AdapterFactoryOptions, AdapterSource, BannerMeta, CreateKubbOptions, Diagnostic, DiagnosticDoc, DiagnosticFormatOptions, DiagnosticKind, DiagnosticLocation, DiagnosticSeverity, Exclude$1 as Exclude, ExtensionDependencies, ExtensionDependency, ExtensionDependencyRecord, ExtensionFactory, ExtensionKind, ExtensionManifest, ExtensionManifestOption, ExtensionMeta, Filter, GenerateOptions, GenerateResult, GenerationResult, Generator, GeneratorContext, Group, HookResult, Include, InputKind, InstalledPackage, JSONValue, Kubb$1 as Kubb, KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, Memo, NodeCache, NormalizedPlugin, Output, OutputManifest, OutputMode, OutputOptions, Override, Parser, ParserDefinition, ParserFactory, PerformanceDiagnostic, Plugin, PluginDefinition, PluginFactory, PluginName, PluginType, ProblemCode, ProblemDiagnostic, RegistryArtifact, RegistryDetail, RegistryEntry, RegistryGuide, RegistryIndex, Renderer, RendererFactory, Reporter, ReporterContext, ReporterName, ReporterPluginFiles, ResolveBannerContext, ResolveBannerFile, ResolveFileOptions, ResolveImportsOptions, ResolveNameOptions, ResolveOptionsContext, ResolvePathOptions, ResolvePluginOptions, ResolverDefault, ResolverFile, ResolverFileParams, ResolverFilePathParams, ResolverPatch, ResolverPathParams, RunHookOptions, RunOutputPassesOptions, SerializedDiagnostic, Storage, SummaryRenderer, UpdateDiagnostic, UserReporter };
3897
+ export type { Adapter, AdapterDefinition, AdapterFactory, AdapterFactoryOptions, AdapterSource, BannerMeta, CreateKubbOptions, Diagnostic, DiagnosticDoc, DiagnosticFormatOptions, DiagnosticKind, DiagnosticLocation, DiagnosticSeverity, Exclude$1 as Exclude, ExtensionDependencies, ExtensionDependency, ExtensionDependencyRecord, ExtensionFactory, ExtensionKind, ExtensionManifest, ExtensionManifestOption, ExtensionMeta, Filter, GenerateOptions, GenerateResult, GenerationResult, Generator, GeneratorContext, Group, HookResult, Include, InputKind, InstalledPackage, JSONValue, Kubb$1 as Kubb, KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, Memo, NormalizedPlugin, Output, OutputManifest, OutputMode, OutputOptions, Override, Parser, ParserDefinition, ParserFactory, PerformanceDiagnostic, Plugin, PluginDefinition, PluginFactory, PluginName, PluginType, ProblemCode, ProblemDiagnostic, RegistryArtifact, RegistryDetail, RegistryEntry, RegistryGuide, RegistryIndex, Renderer, RendererFactory, Reporter, ReporterContext, ReporterName, ReporterPluginFiles, ResolveBannerContext, ResolveBannerFile, ResolveFileOptions, ResolveImportsOptions, ResolveNameOptions, ResolveOptionsContext, ResolvePathOptions, ResolvePluginOptions, ResolverDefault, ResolverFile, ResolverFileParams, ResolverFilePathParams, ResolverPatch, ResolverPathParams, RunHookOptions, RunOutputPassesOptions, SerializedDiagnostic, Storage, SummaryRenderer, UpdateDiagnostic, UserReporter };
3941
3898
  //# sourceMappingURL=index.d.cts.map