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

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
@@ -455,11 +455,11 @@ function trimExtName(text) {
455
455
  * @example
456
456
  * ```ts
457
457
  * const schema = createSchema({ type: 'string' })
458
- * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | undefined
458
+ * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
459
459
  * ```
460
460
  */
461
461
  function narrowSchema(node, type) {
462
- return node?.type === type ? node : void 0;
462
+ return node?.type === type ? node : null;
463
463
  }
464
464
  function isKind(kind) {
465
465
  return (node) => node.kind === kind;
@@ -750,7 +750,7 @@ function transform(node, options) {
750
750
  /**
751
751
  * Runs a depth-first synchronous collection pass.
752
752
  *
753
- * Non-`undefined` values returned by visitor callbacks are appended to the result.
753
+ * Non-`null` values returned by visitor callbacks are appended to the result.
754
754
  *
755
755
  * @example
756
756
  * ```ts
@@ -794,7 +794,7 @@ function* collectLazy(node, options) {
794
794
  v = visitor.response?.(node, { parent });
795
795
  break;
796
796
  }
797
- if (v !== void 0) yield v;
797
+ if (v != null) yield v;
798
798
  for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
799
799
  ...options,
800
800
  parent: node
@@ -993,7 +993,7 @@ function createOperationParams(node, options) {
993
993
  }));
994
994
  } else {
995
995
  if (pathParams.length) if (pathParamsType === "inlineSpread") {
996
- const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]) ?? void 0;
996
+ const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]);
997
997
  params.push(createFunctionParameter({
998
998
  name: pathName,
999
999
  type: spreadType ? wrapType(spreadType) : void 0,
@@ -1069,13 +1069,13 @@ function buildGroupParam({ name, node, params, groupType, resolver, wrapType })
1069
1069
  }
1070
1070
  /**
1071
1071
  * Derives a {@link ParamGroupType} from the resolver's group method.
1072
- * Returns `undefined` when the group name equals the individual param name (no real group).
1072
+ * Returns `null` when the group name equals the individual param name (no real group).
1073
1073
  */
1074
1074
  function resolveGroupType({ node, params, groupMethod, resolver }) {
1075
- if (!params.length) return;
1075
+ if (!params.length) return null;
1076
1076
  const firstParam = params[0];
1077
1077
  const groupName = groupMethod.call(resolver, node, firstParam);
1078
- if (groupName === resolver.resolveParamName(node, firstParam)) return;
1078
+ if (groupName === resolver.resolveParamName(node, firstParam)) return null;
1079
1079
  const allOptional = params.every((p) => !p.required);
1080
1080
  return {
1081
1081
  type: createParamsType({
@@ -1268,7 +1268,7 @@ function extractStringsFromNodes(nodes) {
1268
1268
  /**
1269
1269
  * Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
1270
1270
  *
1271
- * Returns `undefined` for non-ref nodes or when no name can be resolved. Use this to get a schema's
1271
+ * Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's
1272
1272
  * identifier for type definitions or error messages.
1273
1273
  *
1274
1274
  * @example
@@ -1278,9 +1278,9 @@ function extractStringsFromNodes(nodes) {
1278
1278
  * ```
1279
1279
  */
1280
1280
  function resolveRefName(node) {
1281
- if (!node || node.type !== "ref") return void 0;
1282
- if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? void 0;
1283
- return node.name ?? node.schema?.name ?? void 0;
1281
+ if (!node || node.type !== "ref") return null;
1282
+ if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
1283
+ return node.name ?? node.schema?.name ?? null;
1284
1284
  }
1285
1285
  /**
1286
1286
  * Collects every named schema referenced (transitively) from a node via ref edges.
@@ -1416,9 +1416,9 @@ function findCircularSchemas(schemas) {
1416
1416
  function containsCircularRef(node, { circularSchemas, excludeName }) {
1417
1417
  if (!node || circularSchemas.size === 0) return false;
1418
1418
  for (const _ of collectLazy(node, { schema(child) {
1419
- if (child.type !== "ref") return void 0;
1419
+ if (child.type !== "ref") return null;
1420
1420
  const name = resolveRefName(child);
1421
- return name && name !== excludeName && circularSchemas.has(name) ? true : void 0;
1421
+ return name && name !== excludeName && circularSchemas.has(name) ? true : null;
1422
1422
  } })) return true;
1423
1423
  return false;
1424
1424
  }
@@ -2120,7 +2120,7 @@ function createPrinterFactory(getKey) {
2120
2120
  options: resolvedOptions,
2121
2121
  transform: (node) => {
2122
2122
  const key = getKey(node);
2123
- if (key === void 0) return null;
2123
+ if (key === null) return null;
2124
2124
  const handler = nodes[key];
2125
2125
  if (!handler) return null;
2126
2126
  return handler.call(context, node);
@@ -2157,10 +2157,10 @@ function enumPropName(parentName, propName, enumSuffix) {
2157
2157
  function collectImports({ node, nameMapping, resolve }) {
2158
2158
  return collect(node, { schema(schemaNode) {
2159
2159
  const schemaRef = narrowSchema(schemaNode, "ref");
2160
- if (!schemaRef?.ref) return;
2160
+ if (!schemaRef?.ref) return null;
2161
2161
  const rawName = extractRefName(schemaRef.ref);
2162
2162
  const result = resolve(nameMapping.get(rawName) ?? rawName);
2163
- if (!result) return;
2163
+ if (!result) return null;
2164
2164
  return result;
2165
2165
  } });
2166
2166
  }
@@ -2266,7 +2266,7 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
2266
2266
  const enumNode = narrowSchema(propNode, "enum");
2267
2267
  if (enumNode?.primitive === "boolean") return {
2268
2268
  ...propNode,
2269
- name: void 0
2269
+ name: null
2270
2270
  };
2271
2271
  if (enumNode) return {
2272
2272
  ...propNode,