@kubb/ast 5.13.1 → 5.14.0

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
@@ -1,5 +1,29 @@
1
1
  //#endregion
2
2
  //#region src/constants.d.ts
3
+ /**
4
+ * Node kind discriminators used by every AST node (for example `node.kind === nodeKinds.text`).
5
+ */
6
+ export declare const nodeKinds: {
7
+ readonly input: 'Input';
8
+ readonly operation: 'Operation';
9
+ readonly schema: 'Schema';
10
+ readonly property: 'Property';
11
+ readonly parameter: 'Parameter';
12
+ readonly response: 'Response';
13
+ readonly requestBody: 'RequestBody';
14
+ readonly content: 'Content';
15
+ readonly type: 'Type';
16
+ readonly file: 'File';
17
+ readonly import: 'Import';
18
+ readonly export: 'Export';
19
+ readonly source: 'Source';
20
+ readonly const: 'Const';
21
+ readonly function: 'Function';
22
+ readonly arrowFunction: 'ArrowFunction';
23
+ readonly text: 'Text';
24
+ readonly break: 'Break';
25
+ readonly jsx: 'Jsx';
26
+ };
3
27
  /**
4
28
  * Traversal depth for AST visitor utilities.
5
29
  *
@@ -1659,6 +1683,13 @@ type SourceNode = BaseNode & {
1659
1683
  * Include this source in barrel/index file generation.
1660
1684
  */
1661
1685
  isIndexable?: boolean | null;
1686
+ /**
1687
+ * Marks the source as a definition that importing files absorb instead of import. `expression` is
1688
+ * the declaration's right-hand side, such as `{ body: Pet }`.
1689
+ */
1690
+ inline?: {
1691
+ expression: string;
1692
+ } | null;
1662
1693
  /**
1663
1694
  * Child nodes that make up this source fragment, in DOM order.
1664
1695
  * Use a {@link TextNode} for raw string content.
@@ -1974,7 +2005,7 @@ declare namespace index_d_exports$1 {
1974
2005
  * ```ts
1975
2006
  * function getKind(node: Node): string {
1976
2007
  * switch (node.kind) {
1977
- * case 'Input':
2008
+ * case nodeKinds.input:
1978
2009
  * return 'input'
1979
2010
  * default:
1980
2011
  * return 'other'
@@ -2499,6 +2530,53 @@ export declare function createPrinter<T extends PrinterFactoryOptions = PrinterF
2499
2530
  */
2500
2531
  export declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
2501
2532
  //#endregion
2533
+ //#region src/utils/inline.d.ts
2534
+ /**
2535
+ * Whether every source of `file` is inline. Other files absorb such a file, so it is never written.
2536
+ */
2537
+ export declare function isVirtualFile(file: FileNode): boolean;
2538
+ type InlineFilesResult = {
2539
+ /**
2540
+ * Files that imported an inline name, rewritten to hold its definition.
2541
+ */
2542
+ files: Array<FileNode>;
2543
+ /**
2544
+ * Paths of the virtual files, which are not written.
2545
+ */
2546
+ virtualPaths: Array<string>;
2547
+ /**
2548
+ * One message per name that could not be inlined.
2549
+ */
2550
+ problems: Array<{
2551
+ path: string;
2552
+ message: string;
2553
+ }>;
2554
+ };
2555
+ /**
2556
+ * The language-specific half of {@link inlineFiles}, supplied by the parser that prints the file.
2557
+ */
2558
+ type InlineLanguage = {
2559
+ /**
2560
+ * Swaps in what `replace` returns for every identifier in `text` that references a name, skipping strings and comments.
2561
+ */
2562
+ replaceIdentifiers(text: string, replace: (name: string) => string | undefined): string;
2563
+ /**
2564
+ * Makes `expression` safe to put where a name was, such as `(A | B)` in TypeScript.
2565
+ */
2566
+ wrap(expression: string): string;
2567
+ };
2568
+ type InlineFilesOptions = {
2569
+ /**
2570
+ * The inline support for a file's language, or `undefined` when it has none.
2571
+ */
2572
+ language: (file: FileNode) => InlineLanguage | undefined;
2573
+ };
2574
+ /**
2575
+ * Replaces every name a file imports from a virtual file (see {@link isVirtualFile}) with that name's
2576
+ * `inline.expression`, until no inline names are left. The definitions' own imports move to the importing file.
2577
+ */
2578
+ export declare function inlineFiles(files: ReadonlyArray<FileNode>, { language }: InlineFilesOptions): InlineFilesResult;
2579
+ //#endregion
2502
2580
  //#region src/utils/refs.d.ts
2503
2581
  /** Returns the last segment of a `$ref` pointer, for example `'Pet'` for `#/components/schemas/Pet`. */
2504
2582
  export declare function refName(ref: string): string;
@@ -2750,8 +2828,8 @@ type ParserOptions = {
2750
2828
  enumSuffix: 'enum' | (string & {});
2751
2829
  };
2752
2830
  declare namespace index_d_exports {
2753
- export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InputMeta, InputNode, InputSecurityScheme, InputServer, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, composeMacros, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$1 as factory, findCircularSchemas, findCircularSchemasFromGraph, findSchema, forEachChild, forEachSchema, getSchemaLiteralValues, inferDiscriminatorPropertyName, isBareRef, isHttpOperationNode, mergeRefWithSchema, narrowSchema, optionality, refName, resolveRef, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
2831
+ export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InlineLanguage, InputMeta, InputNode, InputSecurityScheme, InputServer, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, composeMacros, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$1 as factory, findCircularSchemas, findCircularSchemasFromGraph, findSchema, forEachChild, forEachSchema, getSchemaLiteralValues, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, isVirtualFile, mergeRefWithSchema, narrowSchema, nodeKinds, optionality, refName, resolveRef, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
2754
2832
  }
2755
2833
  //#endregion
2756
- export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InputMeta, type InputNode, type InputSecurityScheme, type InputServer, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as factory };
2834
+ export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InlineLanguage, type InputMeta, type InputNode, type InputSecurityScheme, type InputServer, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as factory };
2757
2835
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,29 @@
1
1
  //#endregion
2
2
  //#region src/constants.d.ts
3
+ /**
4
+ * Node kind discriminators used by every AST node (for example `node.kind === nodeKinds.text`).
5
+ */
6
+ export declare const nodeKinds: {
7
+ readonly input: 'Input';
8
+ readonly operation: 'Operation';
9
+ readonly schema: 'Schema';
10
+ readonly property: 'Property';
11
+ readonly parameter: 'Parameter';
12
+ readonly response: 'Response';
13
+ readonly requestBody: 'RequestBody';
14
+ readonly content: 'Content';
15
+ readonly type: 'Type';
16
+ readonly file: 'File';
17
+ readonly import: 'Import';
18
+ readonly export: 'Export';
19
+ readonly source: 'Source';
20
+ readonly const: 'Const';
21
+ readonly function: 'Function';
22
+ readonly arrowFunction: 'ArrowFunction';
23
+ readonly text: 'Text';
24
+ readonly break: 'Break';
25
+ readonly jsx: 'Jsx';
26
+ };
3
27
  /**
4
28
  * Traversal depth for AST visitor utilities.
5
29
  *
@@ -1659,6 +1683,13 @@ type SourceNode = BaseNode & {
1659
1683
  * Include this source in barrel/index file generation.
1660
1684
  */
1661
1685
  isIndexable?: boolean | null;
1686
+ /**
1687
+ * Marks the source as a definition that importing files absorb instead of import. `expression` is
1688
+ * the declaration's right-hand side, such as `{ body: Pet }`.
1689
+ */
1690
+ inline?: {
1691
+ expression: string;
1692
+ } | null;
1662
1693
  /**
1663
1694
  * Child nodes that make up this source fragment, in DOM order.
1664
1695
  * Use a {@link TextNode} for raw string content.
@@ -1974,7 +2005,7 @@ declare namespace index_d_exports$1 {
1974
2005
  * ```ts
1975
2006
  * function getKind(node: Node): string {
1976
2007
  * switch (node.kind) {
1977
- * case 'Input':
2008
+ * case nodeKinds.input:
1978
2009
  * return 'input'
1979
2010
  * default:
1980
2011
  * return 'other'
@@ -2499,6 +2530,53 @@ export declare function createPrinter<T extends PrinterFactoryOptions = PrinterF
2499
2530
  */
2500
2531
  export declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
2501
2532
  //#endregion
2533
+ //#region src/utils/inline.d.ts
2534
+ /**
2535
+ * Whether every source of `file` is inline. Other files absorb such a file, so it is never written.
2536
+ */
2537
+ export declare function isVirtualFile(file: FileNode): boolean;
2538
+ type InlineFilesResult = {
2539
+ /**
2540
+ * Files that imported an inline name, rewritten to hold its definition.
2541
+ */
2542
+ files: Array<FileNode>;
2543
+ /**
2544
+ * Paths of the virtual files, which are not written.
2545
+ */
2546
+ virtualPaths: Array<string>;
2547
+ /**
2548
+ * One message per name that could not be inlined.
2549
+ */
2550
+ problems: Array<{
2551
+ path: string;
2552
+ message: string;
2553
+ }>;
2554
+ };
2555
+ /**
2556
+ * The language-specific half of {@link inlineFiles}, supplied by the parser that prints the file.
2557
+ */
2558
+ type InlineLanguage = {
2559
+ /**
2560
+ * Swaps in what `replace` returns for every identifier in `text` that references a name, skipping strings and comments.
2561
+ */
2562
+ replaceIdentifiers(text: string, replace: (name: string) => string | undefined): string;
2563
+ /**
2564
+ * Makes `expression` safe to put where a name was, such as `(A | B)` in TypeScript.
2565
+ */
2566
+ wrap(expression: string): string;
2567
+ };
2568
+ type InlineFilesOptions = {
2569
+ /**
2570
+ * The inline support for a file's language, or `undefined` when it has none.
2571
+ */
2572
+ language: (file: FileNode) => InlineLanguage | undefined;
2573
+ };
2574
+ /**
2575
+ * Replaces every name a file imports from a virtual file (see {@link isVirtualFile}) with that name's
2576
+ * `inline.expression`, until no inline names are left. The definitions' own imports move to the importing file.
2577
+ */
2578
+ export declare function inlineFiles(files: ReadonlyArray<FileNode>, { language }: InlineFilesOptions): InlineFilesResult;
2579
+ //#endregion
2502
2580
  //#region src/utils/refs.d.ts
2503
2581
  /** Returns the last segment of a `$ref` pointer, for example `'Pet'` for `#/components/schemas/Pet`. */
2504
2582
  export declare function refName(ref: string): string;
@@ -2750,8 +2828,8 @@ type ParserOptions = {
2750
2828
  enumSuffix: 'enum' | (string & {});
2751
2829
  };
2752
2830
  declare namespace index_d_exports {
2753
- export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InputMeta, InputNode, InputSecurityScheme, InputServer, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, composeMacros, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$1 as factory, findCircularSchemas, findCircularSchemasFromGraph, findSchema, forEachChild, forEachSchema, getSchemaLiteralValues, inferDiscriminatorPropertyName, isBareRef, isHttpOperationNode, mergeRefWithSchema, narrowSchema, optionality, refName, resolveRef, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
2831
+ export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateOnlyTypeValue, DateSchemaNode, DateTimeTypeValue, DateTypeOptions, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InlineLanguage, InputMeta, InputNode, InputSecurityScheme, InputServer, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeKind, NotSchemaNode, NumberSchemaNode, ObjectSchemaNode, OperationNode, ParameterLocation, ParameterNode, ParameterStyle, ParentOf, ParserOptions, PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, PropertyNode, RefSchemaNode, RequestBodyNode, ResponseNode, ScalarSchemaNode, ScalarSchemaType, SchemaNode, SchemaNodeByType, SchemaType, SourceNode, StatusCode, StringSchemaNode, TextNode, TimeSchemaNode, TypeNode, UnionSchemaNode, UrlSchemaNode, UserFileNode, Visitor, VisitorContext, applyMacros, index_d_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, composeMacros, createPrinter, defineMacro, extractStringsFromNodes, index_d_exports$1 as factory, findCircularSchemas, findCircularSchemasFromGraph, findSchema, forEachChild, forEachSchema, getSchemaLiteralValues, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, isVirtualFile, mergeRefWithSchema, narrowSchema, nodeKinds, optionality, refName, resolveRef, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
2754
2832
  }
2755
2833
  //#endregion
2756
- export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InputMeta, type InputNode, type InputSecurityScheme, type InputServer, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as factory };
2834
+ export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateOnlyTypeValue, type DateSchemaNode, type DateTimeTypeValue, type DateTypeOptions, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InlineLanguage, type InputMeta, type InputNode, type InputSecurityScheme, type InputServer, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeKind, type NotSchemaNode, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type ParameterLocation, type ParameterNode, type ParameterStyle, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefSchemaNode, type RequestBodyNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type UserFileNode, type Visitor, type VisitorContext, index_d_exports as ast, index_d_exports$1 as factory };
2757
2835
  //# sourceMappingURL=index.d.ts.map