@kubb/ast 5.0.0-beta.14 → 5.0.0-beta.15

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
@@ -1286,14 +1286,23 @@ function resolveRefName(node) {
1286
1286
  * }
1287
1287
  * ```
1288
1288
  */
1289
- function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
1290
- if (!node) return out;
1289
+ const schemaRefCache = /* @__PURE__ */ new WeakMap();
1290
+ function collectSchemaRefs(node) {
1291
+ const cached = schemaRefCache.get(node);
1292
+ if (cached) return cached;
1293
+ const refs = /* @__PURE__ */ new Set();
1291
1294
  collect(node, { schema(child) {
1292
1295
  if (child.type === "ref") {
1293
1296
  const name = resolveRefName(child);
1294
- if (name) out.add(name);
1297
+ if (name) refs.add(name);
1295
1298
  }
1296
1299
  } });
1300
+ schemaRefCache.set(node, refs);
1301
+ return refs;
1302
+ }
1303
+ function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
1304
+ if (!node) return out;
1305
+ for (const name of collectSchemaRefs(node)) out.add(name);
1297
1306
  return out;
1298
1307
  }
1299
1308
  /**
@@ -2164,23 +2173,27 @@ function setDiscriminatorEnum({ node, propertyName, values, enumName }) {
2164
2173
  * ])
2165
2174
  * ```
2166
2175
  */
2167
- function mergeAdjacentObjects(members) {
2168
- return members.reduce((acc, member) => {
2176
+ function* mergeAdjacentObjectsLazy(members) {
2177
+ let acc;
2178
+ for (const member of members) {
2169
2179
  const objectMember = narrowSchema(member, "object");
2170
- if (objectMember && !objectMember.name) {
2171
- const previous = acc.at(-1);
2172
- const previousObject = previous ? narrowSchema(previous, "object") : void 0;
2173
- if (previousObject && !previousObject.name) {
2174
- acc[acc.length - 1] = createSchema({
2175
- ...previousObject,
2176
- properties: [...previousObject.properties ?? [], ...objectMember.properties ?? []]
2180
+ if (objectMember && !objectMember.name && acc !== void 0) {
2181
+ const accObject = narrowSchema(acc, "object");
2182
+ if (accObject && !accObject.name) {
2183
+ acc = createSchema({
2184
+ ...accObject,
2185
+ properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
2177
2186
  });
2178
- return acc;
2187
+ continue;
2179
2188
  }
2180
2189
  }
2181
- acc.push(member);
2182
- return acc;
2183
- }, []);
2190
+ if (acc !== void 0) yield acc;
2191
+ acc = member;
2192
+ }
2193
+ if (acc !== void 0) yield acc;
2194
+ }
2195
+ function mergeAdjacentObjects(members) {
2196
+ return [...mergeAdjacentObjectsLazy(members)];
2184
2197
  }
2185
2198
  /**
2186
2199
  * Removes enum members that are covered by broader scalar primitives in the same union.
@@ -2269,6 +2282,7 @@ exports.isSchemaNode = isSchemaNode;
2269
2282
  exports.isStringType = isStringType;
2270
2283
  exports.mediaTypes = mediaTypes;
2271
2284
  exports.mergeAdjacentObjects = mergeAdjacentObjects;
2285
+ exports.mergeAdjacentObjectsLazy = mergeAdjacentObjectsLazy;
2272
2286
  exports.narrowSchema = narrowSchema;
2273
2287
  exports.nodeKinds = nodeKinds;
2274
2288
  exports.resolveRefName = resolveRefName;