@kubb/ast 5.0.0-beta.54 → 5.0.0-beta.55

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.cjs CHANGED
@@ -1,8 +1,25 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_utils = require("./utils-CMRZrT-w.cjs");
2
+ const require_utils = require("./utils-cdQ6Pzyi.cjs");
3
3
  let node_crypto = require("node:crypto");
4
4
  let node_path = require("node:path");
5
5
  node_path = require_utils.__toESM(node_path, 1);
6
+ //#region ../../internals/utils/src/fs.ts
7
+ /**
8
+ * Strips the file extension from a path or file name.
9
+ * Only removes the last `.ext` segment when the dot is not part of a directory name.
10
+ *
11
+ * @example
12
+ * trimExtName('petStore.ts') // 'petStore'
13
+ * trimExtName('/src/models/pet.ts') // '/src/models/pet'
14
+ * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
15
+ * trimExtName('noExtension') // 'noExtension'
16
+ */
17
+ function trimExtName(text) {
18
+ const dotIndex = text.lastIndexOf(".");
19
+ if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
20
+ return text;
21
+ }
22
+ //#endregion
6
23
  //#region ../../internals/utils/src/promise.ts
7
24
  /**
8
25
  * Wraps `factory` with a keyed cache backed by the provided store.
@@ -1055,7 +1072,7 @@ function createInput(overrides = {}) {
1055
1072
  };
1056
1073
  }
1057
1074
  /**
1058
- * Creates an `InputStreamNode` from pre-built `AsyncIterable` sources.
1075
+ * Creates a streaming `InputNode<true>` from pre-built `AsyncIterable` sources.
1059
1076
  *
1060
1077
  * @example
1061
1078
  * ```ts
@@ -1482,7 +1499,7 @@ function createFile(input) {
1482
1499
  kind: "File",
1483
1500
  ...input,
1484
1501
  id: (0, node_crypto.hash)("sha256", input.path, "hex"),
1485
- name: require_utils.trimExtName(input.baseName),
1502
+ name: trimExtName(input.baseName),
1486
1503
  extname,
1487
1504
  imports: resolvedImports,
1488
1505
  exports: resolvedExports,
@@ -1678,9 +1695,7 @@ function createJsx(value) {
1678
1695
  //#endregion
1679
1696
  //#region src/signature.ts
1680
1697
  /**
1681
- * The shape-affecting flags shared by every node kind: base primitive, format, and `nullable`.
1682
- * Documentation and usage-slot flags (`optional`/`nullish`/`readOnly`/`writeOnly`) are
1683
- * intentionally excluded, they describe the property slot, not the type.
1698
+ * The flags shared by every node kind that affect its type: `primitive`, `format`, `nullable`.
1684
1699
  */
1685
1700
  function flagsDescriptor(node) {
1686
1701
  return `${node.primitive ?? ""};${node.format ?? ""};${node.nullable ? 1 : 0}`;
@@ -1753,9 +1768,8 @@ const rangeFields = [{
1753
1768
  prefix: "mx"
1754
1769
  }];
1755
1770
  /**
1756
- * Maps each schema node `type` to the ordered list of shape-contributing fields.
1757
- * Node types absent from this map (scalar types like boolean, null, any, etc.) fall
1758
- * back to `${type}|${flags}` with no additional fields.
1771
+ * Maps each node `type` to its ordered shape-contributing fields. Types absent from the map
1772
+ * (boolean, null, any, and other scalars) fall back to `${type}|${flags}`.
1759
1773
  */
1760
1774
  const SHAPE_KEYS = {
1761
1775
  object: [
@@ -1892,9 +1906,8 @@ function serializeShapeField(field, node, record) {
1892
1906
  }
1893
1907
  }
1894
1908
  /**
1895
- * Builds the local, shape-only descriptor for a node: its kind, flags, constraints, and its
1896
- * children's signatures. {@link signatureOf} hashes this string. Children contribute their
1897
- * fixed-length signature rather than their own full descriptor, which keeps the result bounded.
1909
+ * Builds the local shape descriptor that {@link signatureOf} hashes: the node's kind, flags,
1910
+ * constraints, and its children's signatures.
1898
1911
  */
1899
1912
  function describeShape(node) {
1900
1913
  const flags = flagsDescriptor(node);
@@ -1906,22 +1919,23 @@ function describeShape(node) {
1906
1919
  return parts.join("|");
1907
1920
  }
1908
1921
  /**
1909
- * Persistent hash-consing cache: `SchemaNode` signature digest, keyed by node identity.
1910
- *
1911
- * A `WeakMap` so entries are released once the node is garbage-collected, and so a node hashed
1912
- * during dedupe planning is not re-hashed when the same tree is rewritten during streaming
1913
- * (where `schemaSignature` and `applyDedupe` would otherwise each walk it from scratch). Reuse
1914
- * across calls is sound because a signature depends only on a node's content, and schema nodes
1915
- * are immutable once created, transforms allocate new objects rather than mutating in place.
1922
+ * Node digest cache, keyed by identity. A `WeakMap` so entries die with the node, and so a tree
1923
+ * hashed during dedupe planning is not walked again when it is rewritten during streaming. Reuse
1924
+ * is safe because a signature depends only on content, and nodes are immutable once created.
1916
1925
  */
1917
1926
  const signatureCache = /* @__PURE__ */ new WeakMap();
1918
1927
  /**
1919
- * Hash-consing: each node's signature is a fixed-length digest of its local shape plus its
1920
- * children's digests (a Merkle hash). Children contribute their 64-char hash instead of their
1921
- * full nested descriptor, so a signature stays bounded regardless of subtree depth, and the
1922
- * digest is identical across calls because it depends only on content, never on traversal
1923
- * order. This keeps the keys built during planning consistent with the ones recomputed later
1924
- * during streaming. {@link signatureCache} memoizes node → digest across every computation.
1928
+ * Computes a deterministic, shape-only signature (a content hash) for a schema node. Two schemas
1929
+ * share a signature when they are structurally identical, ignoring documentation (`name`, `title`,
1930
+ * `description`, `example`, `default`, `deprecated`) and usage-slot flags (`optional`, `nullish`,
1931
+ * `readOnly`, `writeOnly`). `nullable` is kept because it changes the produced type, and `ref`
1932
+ * nodes compare by target name, which also terminates on circular shapes.
1933
+ *
1934
+ * @example Two enums with different descriptions share a signature
1935
+ * ```ts
1936
+ * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
1937
+ * signatureOf(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
1938
+ * ```
1925
1939
  */
1926
1940
  function signatureOf(node) {
1927
1941
  const cached = signatureCache.get(node);
@@ -1930,24 +1944,6 @@ function signatureOf(node) {
1930
1944
  signatureCache.set(node, signature);
1931
1945
  return signature;
1932
1946
  }
1933
- /**
1934
- * Computes a deterministic, shape-only signature (a fixed-length content hash) for a schema node.
1935
- *
1936
- * Two schemas share a signature when they are structurally identical, ignoring
1937
- * documentation (`name`, `title`, `description`, `example`, `default`, `deprecated`)
1938
- * and usage-slot flags (`optional`, `nullish`, `readOnly`, `writeOnly`). `nullable`
1939
- * is kept because it changes the produced type. `ref` nodes compare by target name,
1940
- * which also keeps the algorithm terminating on circular shapes.
1941
- *
1942
- * @example Two enums with different descriptions share a signature
1943
- * ```ts
1944
- * schemaSignature(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'], description: 'x' })) ===
1945
- * schemaSignature(createSchema({ type: 'enum', primitive: 'string', enumValues: ['a', 'b'] }))
1946
- * ```
1947
- */
1948
- function schemaSignature(node) {
1949
- return signatureOf(node);
1950
- }
1951
1947
  //#endregion
1952
1948
  //#region src/dedupe.ts
1953
1949
  /**
@@ -2081,9 +2077,8 @@ function buildDedupePlan(roots, options) {
2081
2077
  //#endregion
2082
2078
  //#region src/dialect.ts
2083
2079
  /**
2084
- * Identity helper that types a {@link SchemaDialect} for an adapter. Like
2085
- * `defineParser`, it adds no runtime behavior, it pins the dialect's type for
2086
- * inference and gives adapter authors a discoverable anchor.
2080
+ * Types a {@link SchemaDialect} for an adapter. Adds no runtime behavior and only pins the
2081
+ * dialect's type for inference.
2087
2082
  *
2088
2083
  * @example
2089
2084
  * ```ts
@@ -2101,38 +2096,6 @@ function defineSchemaDialect(dialect) {
2101
2096
  return dialect;
2102
2097
  }
2103
2098
  //#endregion
2104
- //#region src/dispatch.ts
2105
- /**
2106
- * Walks an ordered list of {@link DispatchRule}s and returns the first node produced.
2107
- *
2108
- * This is the shared backbone for spec adapters (OpenAPI today, AsyncAPI and others later).
2109
- * The contract an adapter follows is intentionally minimal:
2110
- *
2111
- * context → [rule.match → rule.convert] → node
2112
- *
2113
- * An adapter derives a context from a source spec node, then declares an ordered table of
2114
- * rules mapping spec shapes onto Kubb AST nodes. To add support for a new spec, write a new
2115
- * context type and a new rules table, the traversal here is reused unchanged.
2116
- *
2117
- * Order is significant: earlier rules win, so list higher-precedence or more specific shapes
2118
- * first (e.g. composition keywords before plain `type`). A rule whose `match` returns `true`
2119
- * may still `convert` to `null` to defer to later rules. When no rule produces a node this
2120
- * returns `null`, leaving the caller to apply its own fallback.
2121
- *
2122
- * @example
2123
- * ```ts
2124
- * const node = dispatch(schemaRules, schemaContext) ?? createSchema({ type: fallbackType })
2125
- * ```
2126
- */
2127
- function dispatch(rules, context) {
2128
- for (const rule of rules) {
2129
- if (!rule.match(context)) continue;
2130
- const node = rule.convert(context);
2131
- if (node !== null && node !== void 0) return node;
2132
- }
2133
- return null;
2134
- }
2135
- //#endregion
2136
2099
  //#region src/printer.ts
2137
2100
  /**
2138
2101
  * Defines a schema printer: a function that takes a `SchemaNode` and emits
@@ -2210,21 +2173,6 @@ function createPrinterFactory(getKey) {
2210
2173
  };
2211
2174
  }
2212
2175
  //#endregion
2213
- //#region src/resolvers.ts
2214
- /**
2215
- * Collects import entries for all `ref` schema nodes in `node`.
2216
- */
2217
- function collectImports({ node, nameMapping, resolve }) {
2218
- return collect(node, { schema(schemaNode) {
2219
- const schemaRef = narrowSchema(schemaNode, "ref");
2220
- if (!schemaRef?.ref) return null;
2221
- const rawName = require_utils.extractRefName(schemaRef.ref);
2222
- const result = resolve(nameMapping.get(rawName) ?? rawName);
2223
- if (!result) return null;
2224
- return result;
2225
- } });
2226
- }
2227
- //#endregion
2228
2176
  //#region src/transformers.ts
2229
2177
  /**
2230
2178
  * Replaces a discriminator property's schema with a string enum of allowed values.
@@ -2336,7 +2284,6 @@ exports.applyDedupe = applyDedupe;
2336
2284
  exports.buildDedupePlan = buildDedupePlan;
2337
2285
  exports.caseParams = caseParams;
2338
2286
  exports.collect = collect;
2339
- exports.collectImports = collectImports;
2340
2287
  exports.collectUsedSchemaNames = collectUsedSchemaNames;
2341
2288
  exports.containsCircularRef = containsCircularRef;
2342
2289
  exports.createArrowFunction = createArrowFunction;
@@ -2367,7 +2314,6 @@ exports.createText = createText;
2367
2314
  exports.createType = createType;
2368
2315
  exports.definePrinter = definePrinter;
2369
2316
  exports.defineSchemaDialect = defineSchemaDialect;
2370
- exports.dispatch = dispatch;
2371
2317
  exports.extractStringsFromNodes = extractStringsFromNodes;
2372
2318
  exports.findCircularSchemas = findCircularSchemas;
2373
2319
  exports.httpMethods = require_utils.httpMethods;
@@ -2379,10 +2325,10 @@ exports.isSchemaNode = isSchemaNode;
2379
2325
  exports.isStringType = isStringType;
2380
2326
  exports.mergeAdjacentObjectsLazy = mergeAdjacentObjectsLazy;
2381
2327
  exports.narrowSchema = narrowSchema;
2382
- exports.schemaSignature = schemaSignature;
2383
2328
  exports.schemaTypes = require_utils.schemaTypes;
2384
2329
  exports.setDiscriminatorEnum = setDiscriminatorEnum;
2385
2330
  exports.setEnumName = setEnumName;
2331
+ exports.signatureOf = signatureOf;
2386
2332
  exports.simplifyUnion = simplifyUnion;
2387
2333
  exports.syncOptionality = syncOptionality;
2388
2334
  exports.syncSchemaRef = syncSchemaRef;