@buka/nestjs-kit 4.3.4 → 4.3.5

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.3.5](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.3.4...v4.3.5) (2026-06-02)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 修复ManyToMany和OneToMany立刻获取type数据导致的循环引用报错问题 ([c2c44c1](https://github.com/buka-ltd/npm.nestjs-kit/commit/c2c44c1d3e5d7ac2110f480f303fc9123a73087e))
9
+
3
10
  ## [4.3.4](https://github.com/buka-ltd/npm.nestjs-kit/compare/v4.3.3...v4.3.4) (2026-05-27)
4
11
 
5
12
 
package/dist/index.js CHANGED
@@ -2782,6 +2782,21 @@ function resolveEntityType(entityRef, eager) {
2782
2782
  if (!cls) return Object;
2783
2783
  return eager ? cls : PrimaryKeyType(cls);
2784
2784
  }
2785
+ /**
2786
+ * 为 Swagger schema 解析实体类引用。始终返回完整实体类(非 PrimaryKeyType),
2787
+ * 保证 `$ref` 指向正确注册的 schema。
2788
+ *
2789
+ * 返回函数形式以支持延迟求值,避免装饰器执行时的循环引用问题。
2790
+ */
2791
+ function resolveEntitySchemaType(entityRef) {
2792
+ return () => {
2793
+ if (!entityRef) return Object;
2794
+ const result = entityRef();
2795
+ const entityName = Array.isArray(result) ? result[0] : result;
2796
+ if (!entityName) return Object;
2797
+ return resolveEntityClass(entityName) || Object;
2798
+ };
2799
+ }
2785
2800
  //#endregion
2786
2801
  //#region src/modules/mikro-orm/decorators/cardinality/many-to-one.cardinality.ts
2787
2802
  /**
@@ -2894,8 +2909,8 @@ function OneToMany(options) {
2894
2909
  },
2895
2910
  schema: {
2896
2911
  description: options.comment,
2897
- type: "array",
2898
- items: { $ref: (0, _nestjs_swagger.getSchemaPath)(type()) }
2912
+ type: resolveEntitySchemaType(entityRef),
2913
+ isArray: true
2899
2914
  }
2900
2915
  })(target, propertyKey);
2901
2916
  };
@@ -2935,8 +2950,8 @@ function ManyToMany(entity, mappedBy, options) {
2935
2950
  },
2936
2951
  schema: {
2937
2952
  description: resolvedOptions?.comment,
2938
- type: "array",
2939
- items: { $ref: (0, _nestjs_swagger.getSchemaPath)(type()) }
2953
+ type: resolveEntitySchemaType(entityRef),
2954
+ isArray: true
2940
2955
  }
2941
2956
  })(target, propertyKey);
2942
2957
  };