@kubb/ast 5.0.0-beta.108 → 5.0.0-beta.109

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
@@ -30,28 +30,6 @@ declare function isHttpOperationNode(node: OperationNode): node is HttpOperation
30
30
  */
31
31
  declare function optionality(schema: SchemaNode, required: boolean): SchemaNode;
32
32
  //#endregion
33
- //#region src/utils/combineFileMembers.d.ts
34
- /**
35
- * Deduplicates `SourceNode` objects by `name + isExportable + isTypeOnly`, keeping the first of each
36
- * key. Unnamed sources fall back to their extracted node strings as the name part of the key. Returns
37
- * the deduplicated array in original order.
38
- */
39
- declare function combineSources(sources: Array<SourceNode>): Array<SourceNode>;
40
- /**
41
- * Deduplicates and merges `ExportNode` objects by path and type.
42
- *
43
- * Named exports with the same path and `isTypeOnly` flag have their names merged into a single export.
44
- * Non-array exports are deduplicated by exact identity. Returns a sorted, deduplicated array.
45
- */
46
- declare function combineExports(exports: Array<ExportNode>): Array<ExportNode>;
47
- /**
48
- * Deduplicates and merges `ImportNode` objects, filtering out unused imports.
49
- *
50
- * Retains imports that are referenced in `source` or re-exported. Imports with the same path and
51
- * `isTypeOnly` flag have their names merged. Returns a sorted, deduplicated, filtered array.
52
- */
53
- declare function combineImports(imports: Array<ImportNode>, exports: Array<ExportNode>, source?: string): Array<ImportNode>;
54
- //#endregion
55
33
  //#region src/utils/extractStringsFromNodes.d.ts
56
34
  /**
57
35
  * Extracts all string content from a `CodeNode` tree recursively.
@@ -240,8 +218,8 @@ declare const nodeDefs: (NodeDef<InputNode, Partial<Omit<InputNode, "kind">>> |
240
218
  type: "ipv6";
241
219
  }) | ScalarSchemaNode, "kind">> | NodeDef<PropertyNode, UserPropertyNode> | NodeDef<ParameterNode, Pick<ParameterNode, "schema" | "name" | "in"> & Partial<Omit<ParameterNode, "schema" | "kind" | "name" | "in">>> | NodeDef<ConstNode, Omit<ConstNode, "kind">> | NodeDef<TypeNode, Omit<TypeNode, "kind">> | NodeDef<FunctionNode, Omit<FunctionNode, "kind">> | NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">> | NodeDef<TextNode, string> | NodeDef<BreakNode, void> | NodeDef<JsxNode, string> | NodeDef<ImportNode, Omit<ImportNode, "kind">> | NodeDef<ExportNode, Omit<ExportNode, "kind">> | NodeDef<SourceNode, Omit<SourceNode, "kind">> | NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>)[];
242
220
  declare namespace exports_d_exports {
243
- export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, 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, arrowFunctionDef, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
221
+ export { ArraySchemaNode, ArrowFunctionNode, BreakNode, CodeNode, ConstNode, ContentNode, DateSchemaNode, DatetimeSchemaNode, DistributiveOmit, Enforce, EnumSchemaNode, ExportNode, FileNode, FunctionNode, GenericOperationNode, HttpMethod, HttpOperationNode, ImportNode, InferSchemaNode, InputMeta, InputNode, IntersectionSchemaNode, JSDocNode, JsxNode, Macro, Node, NodeDef, NodeKind, NumberSchemaNode, ObjectSchemaNode, OperationNode, OutputNode, 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, arrowFunctionDef, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
244
222
  }
245
223
  //#endregion
246
- export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, 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, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
224
+ export { type ArraySchemaNode, type ArrowFunctionNode, type BreakNode, type CodeNode, type ConstNode, type ContentNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type Enforce, type EnumSchemaNode, type ExportNode, type FileNode, type FunctionNode, type GenericOperationNode, type HttpMethod, type HttpOperationNode, type ImportNode, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type JSDocNode, type JsxNode, type Macro, type Node, type NodeDef, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, 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, applyMacros, arrowFunctionDef, exports_d_exports as ast, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_d_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
247
225
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -425,6 +425,17 @@ function extractStringsFromNodes(nodes) {
425
425
  }
426
426
  //#endregion
427
427
  //#region src/utils/combineFileMembers.ts
428
+ const IDENTIFIER_RUN = /[\w$]+/g;
429
+ /**
430
+ * How many imports a file needs before indexing the source beats scanning it once per name.
431
+ */
432
+ const INDEX_ABOVE_IMPORTS = 128;
433
+ /**
434
+ * Every unbroken run of identifier characters in the source.
435
+ */
436
+ function collectIdentifiers(source) {
437
+ return new Set(source.match(IDENTIFIER_RUN));
438
+ }
428
439
  function sourceKey(source) {
429
440
  return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`;
430
441
  }
@@ -519,7 +530,8 @@ function combineExports(exports) {
519
530
  */
520
531
  function combineImports(imports, exports, source) {
521
532
  const exportedNames = new Set(exports.flatMap((e) => Array.isArray(e.name) ? e.name : e.name ? [e.name] : []));
522
- const isUsed = (importName) => !source || source.includes(importName) || exportedNames.has(importName);
533
+ const identifiers = source && imports.length > INDEX_ABOVE_IMPORTS ? collectIdentifiers(source) : null;
534
+ const isUsed = (importName) => !source || identifiers?.has(importName) || source.includes(importName) || exportedNames.has(importName);
523
535
  const importNameMemo = /* @__PURE__ */ new Map();
524
536
  const canonicalizeName = (n) => {
525
537
  if (typeof n === "string") return n;
@@ -1549,9 +1561,6 @@ var exports_exports = /* @__PURE__ */ __exportAll({
1549
1561
  collectImportedRefNames: () => collectImportedRefNames,
1550
1562
  collectSync: () => collectSync,
1551
1563
  collectUsedSchemaNames: () => collectUsedSchemaNames,
1552
- combineExports: () => combineExports,
1553
- combineImports: () => combineImports,
1554
- combineSources: () => combineSources,
1555
1564
  composeMacros: () => composeMacros,
1556
1565
  constDef: () => constDef,
1557
1566
  contentDef: () => contentDef,
@@ -1587,6 +1596,6 @@ var exports_exports = /* @__PURE__ */ __exportAll({
1587
1596
  typeDef: () => typeDef
1588
1597
  });
1589
1598
  //#endregion
1590
- export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
1599
+ export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, collect, collectImportedRefNames, collectSync, collectUsedSchemaNames, composeMacros, constDef, contentDef, createPrinter, defineMacro, defineNode, exportDef, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, findCircularSchemasFromGraph, functionDef, importDef, inputDef, isHttpOperationNode, jsxDef, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, resolveRefName, responseDef, schemaDef, schemaTypes, sourceDef, textDef, transform, typeDef };
1591
1600
 
1592
1601
  //# sourceMappingURL=index.js.map