@kubb/ast 5.0.0-beta.2 → 5.0.0-beta.20

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.ts CHANGED
@@ -1120,6 +1120,10 @@ type SchemaNodeBase = BaseNode & {
1120
1120
  * For example, this is `'string'` for a `uuid` schema.
1121
1121
  */
1122
1122
  primitive?: PrimitiveSchemaType;
1123
+ /**
1124
+ * Schema `format` value.
1125
+ */
1126
+ format?: string;
1123
1127
  };
1124
1128
  /**
1125
1129
  * Object schema with ordered properties.
@@ -1826,32 +1830,62 @@ type OutputNode = BaseNode & {
1826
1830
  //#endregion
1827
1831
  //#region src/nodes/root.d.ts
1828
1832
  /**
1829
- * Basic metadata for an API document.
1830
- * Adapters fill fields that exist in their source format.
1833
+ * Metadata for an API document, populated by the adapter and available to every generator.
1834
+ *
1835
+ * All fields are plain JSON-serializable values — no `Set`, no `Map`, no class instances.
1836
+ * Computed fields (`circularNames`, `enumNames`) are pre-calculated once during the adapter
1837
+ * pre-scan so generators never need to iterate the full schema list themselves.
1831
1838
  *
1832
1839
  * @example
1833
1840
  * ```ts
1834
- * const meta: InputMeta = { title: 'Pet API', version: '1.0.0' }
1841
+ * const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://petstore.swagger.io/v2', circularNames: [], enumNames: [] }
1835
1842
  * ```
1836
1843
  */
1837
1844
  type InputMeta = {
1838
1845
  /**
1839
- * API title (from `info.title` in OAS/AsyncAPI).
1846
+ * API title from `info.title` in the source document.
1840
1847
  */
1841
1848
  title?: string;
1842
1849
  /**
1843
- * API description (from `info.description` in OAS/AsyncAPI).
1850
+ * API description from `info.description` in the source document.
1844
1851
  */
1845
1852
  description?: string;
1846
1853
  /**
1847
- * API version string (from `info.version` in OAS/AsyncAPI).
1854
+ * API version string from `info.version` in the source document.
1848
1855
  */
1849
1856
  version?: string;
1850
1857
  /**
1851
- * Resolved API base URL.
1852
- * For OpenAPI and AsyncAPI, this comes from the selected server URL.
1858
+ * Resolved base URL from the first matching server entry in the source document.
1853
1859
  */
1854
1860
  baseURL?: string;
1861
+ /**
1862
+ * Names of schemas that participate in a circular reference chain.
1863
+ * Computed once during the adapter pre-scan — use this instead of calling
1864
+ * `findCircularSchemas` per generator call.
1865
+ *
1866
+ * Convert to a `Set` once at the start of a generator, not per-schema,
1867
+ * to keep lookup O(1) without repeated allocations.
1868
+ *
1869
+ * @example Wrap a circular schema in z.lazy()
1870
+ * ```ts
1871
+ * const circular = new Set(meta.circularNames)
1872
+ * if (circular.has(schema.name)) { ... }
1873
+ * ```
1874
+ */
1875
+ circularNames: readonly string[];
1876
+ /**
1877
+ * Names of schemas whose type is `enum`.
1878
+ * Computed once during the adapter pre-scan — use this instead of filtering
1879
+ * schemas per generator call.
1880
+ *
1881
+ * Convert to a `Set` once at the start of a generator when you need repeated
1882
+ * membership checks, rather than calling `.includes()` per schema.
1883
+ *
1884
+ * @example Check if a referenced schema is an enum
1885
+ * `const enums = new Set(meta.enumNames)`
1886
+ * `const isEnum = enums.has(schemaName)`
1887
+ */
1888
+ enumNames: readonly string[];
1855
1889
  };
1856
1890
  /**
1857
1891
  * Input AST node that contains all schemas and operations for one API document.
@@ -1880,7 +1914,38 @@ type InputNode = BaseNode & {
1880
1914
  */
1881
1915
  operations: Array<OperationNode>;
1882
1916
  /**
1883
- * Optional document metadata populated by the adapter.
1917
+ * Document metadata populated by the adapter.
1918
+ */
1919
+ meta: InputMeta;
1920
+ };
1921
+ /**
1922
+ * Streaming variant of `InputNode` for memory-efficient processing of large API specs.
1923
+ *
1924
+ * `schemas` and `operations` are `AsyncIterable` rather than arrays — each `for await`
1925
+ * loop creates a fresh parse pass from the cached in-memory document, so multiple
1926
+ * consumers (plugins) can iterate independently without keeping all nodes in memory.
1927
+ *
1928
+ * @example
1929
+ * ```ts
1930
+ * for await (const schema of inputStreamNode.schemas) {
1931
+ * // only this one SchemaNode is live here; previous ones are GC-eligible
1932
+ * }
1933
+ * ```
1934
+ */
1935
+ type InputStreamNode = {
1936
+ kind: 'Input';
1937
+ /**
1938
+ * Lazily parsed schema nodes. Each `for await` creates a fresh parse pass, so
1939
+ * multiple plugins can iterate independently without sharing state.
1940
+ */
1941
+ schemas: AsyncIterable<SchemaNode>;
1942
+ /**
1943
+ * Lazily parsed operation nodes. Each `for await` creates a fresh parse pass, so
1944
+ * multiple plugins can iterate independently without sharing state.
1945
+ */
1946
+ operations: AsyncIterable<OperationNode>;
1947
+ /**
1948
+ * Document metadata available immediately, before the first yielded node.
1884
1949
  */
1885
1950
  meta?: InputMeta;
1886
1951
  };
@@ -2092,6 +2157,15 @@ type CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {
2092
2157
  * ```
2093
2158
  */
2094
2159
  declare function createInput(overrides?: Partial<Omit<InputNode, 'kind'>>): InputNode;
2160
+ /**
2161
+ * Creates an `InputStreamNode` from pre-built `AsyncIterable` sources.
2162
+ *
2163
+ * @example
2164
+ * ```ts
2165
+ * const node = createStreamInput(schemasIterable, operationsIterable, { title: 'My API' })
2166
+ * ```
2167
+ */
2168
+ declare function createStreamInput(schemas: AsyncIterable<SchemaNode>, operations: AsyncIterable<OperationNode>, meta?: InputMeta): InputStreamNode;
2095
2169
  /**
2096
2170
  * Creates an `OutputNode` with a stable default for `files`.
2097
2171
  *
@@ -2901,6 +2975,7 @@ declare function setDiscriminatorEnum({
2901
2975
  * ])
2902
2976
  * ```
2903
2977
  */
2978
+ declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined>;
2904
2979
  declare function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode>;
2905
2980
  /**
2906
2981
  * Removes enum members that are covered by broader scalar primitives in the same union.
@@ -3170,6 +3245,7 @@ declare function transform(node: Node, options: TransformOptions): Node;
3170
3245
  * const values = collect(root, { depth: 'shallow', root: () => 'root' })
3171
3246
  * ```
3172
3247
  */
3248
+ declare function collectLazy<T>(node: Node, options: CollectOptions<T>): Generator<T, void, undefined>;
3173
3249
  declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
3174
3250
  //#endregion
3175
3251
  //#region src/utils.d.ts
@@ -3194,13 +3270,6 @@ declare function syncSchemaRef(node: SchemaNode): SchemaNode;
3194
3270
  * types, returns `true` only when `representation` is `'string'` rather than `'date'`.
3195
3271
  */
3196
3272
  declare function isStringType(node: SchemaNode): boolean;
3197
- /**
3198
- * Applies casing rules to parameter names and returns a new parameter array.
3199
- *
3200
- * Use this before passing parameters to schema builders so output property keys match
3201
- * the desired casing while preserving `OperationNode.parameters` for other consumers.
3202
- * The input array is not mutated. When `casing` is not set, the original array is returned unchanged.
3203
- */
3204
3273
  declare function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode>;
3205
3274
  /**
3206
3275
  * Creates a single-property object schema used as a discriminator literal.
@@ -3371,55 +3440,7 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
3371
3440
  * ```
3372
3441
  */
3373
3442
  declare function resolveRefName(node: SchemaNode | undefined): string | undefined;
3374
- /**
3375
- * Collects every named schema referenced (transitively) from a node via ref edges.
3376
- *
3377
- * Refs are followed by name only — the resolved `node.schema` is not traversed inline.
3378
- * Use this to determine schema dependencies, build reference graphs, or detect what schemas need to be emitted.
3379
- *
3380
- * @example Collect refs from a single schema
3381
- * ```ts
3382
- * const names = collectReferencedSchemaNames(petSchema)
3383
- * // → Set { 'Category', 'Tag' }
3384
- * ```
3385
- *
3386
- * @example Accumulate refs from multiple schemas into one set
3387
- * ```ts
3388
- * const out = new Set<string>()
3389
- * for (const schema of schemas) {
3390
- * collectReferencedSchemaNames(schema, out)
3391
- * }
3392
- * ```
3393
- */
3394
3443
  declare function collectReferencedSchemaNames(node: SchemaNode | undefined, out?: Set<string>): Set<string>;
3395
- /**
3396
- * Collects the names of all top-level schemas transitively used by a set of operations.
3397
- *
3398
- * An operation uses a schema when any of its parameters, request body content, or responses
3399
- * reference it — directly or indirectly through other named schemas.
3400
- * The walk is iterative and safe against reference cycles.
3401
- *
3402
- * Use this together with `include` filters to determine which schemas from `components/schemas`
3403
- * are reachable from the allowed operations, so that schemas used only by excluded operations
3404
- * are not generated.
3405
- *
3406
- * @example Only generate schemas referenced by included operations
3407
- * ```ts
3408
- * const includedOps = inputNode.operations.filter(op => resolver.resolveOptions(op, { options, include }) !== null)
3409
- * const allowed = collectUsedSchemaNames(includedOps, inputNode.schemas)
3410
- *
3411
- * for (const schema of inputNode.schemas) {
3412
- * if (schema.name && !allowed.has(schema.name)) continue
3413
- * // … generate schema
3414
- * }
3415
- * ```
3416
- *
3417
- * @example Check whether a specific schema is needed
3418
- * ```ts
3419
- * const allowed = collectUsedSchemaNames(includedOps, inputNode.schemas)
3420
- * allowed.has('OrderStatus') // false when no included operation references OrderStatus
3421
- * ```
3422
- */
3423
3444
  declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
3424
3445
  /**
3425
3446
  * Identifies all schemas that participate in circular dependency chains, including direct self-loops.
@@ -3447,5 +3468,5 @@ declare function containsCircularRef(node: SchemaNode | undefined, {
3447
3468
  excludeName?: string;
3448
3469
  }): boolean;
3449
3470
  //#endregion
3450
- export { type ArraySchemaNode, type ArrowFunctionNode, AsyncVisitor, type BaseNode, type BreakNode, type CodeNode, CollectOptions, CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, InferSchema, InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, OperationParamsResolver, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, ParentOf, ParserOptions, type PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, type PropertyNode, RefMap, type RefSchemaNode, type ResponseNode, ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, UserFileNode, Visitor, VisitorContext, VisitorDepth, WalkOptions, caseParams, childName, collect, collectImports, collectReferencedSchemaNames, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createText, createType, definePrinter, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
3471
+ export { type ArraySchemaNode, type ArrowFunctionNode, AsyncVisitor, type BaseNode, type BreakNode, type CodeNode, CollectOptions, CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, InferSchema, InferSchemaNode, type InputMeta, type InputNode, type InputStreamNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, OperationParamsResolver, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, ParentOf, ParserOptions, type PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, type PropertyNode, RefMap, type RefSchemaNode, type ResponseNode, ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, UserFileNode, Visitor, VisitorContext, VisitorDepth, WalkOptions, caseParams, childName, collect, collectImports, collectLazy, collectReferencedSchemaNames, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createStreamInput, createText, createType, definePrinter, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, mergeAdjacentObjectsLazy, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
3451
3472
  //# sourceMappingURL=index.d.ts.map