@forklaunch/core 1.6.4 → 1.6.6

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.
@@ -1283,20 +1283,34 @@ function wrapEmWithTenantContext(em, tenantId) {
1283
1283
  if (tenantId) {
1284
1284
  em.setFilterParams("tenant", { tenantId });
1285
1285
  }
1286
- return new Proxy(em, {
1286
+ const proxy = new Proxy(em, {
1287
1287
  get(target, prop, receiver) {
1288
1288
  const value = Reflect.get(target, prop, receiver);
1289
1289
  if (typeof value !== "function") {
1290
1290
  return value;
1291
1291
  }
1292
1292
  return function tenantBoundMethod(...args) {
1293
- return withEncryptionContext(
1293
+ const result = withEncryptionContext(
1294
1294
  tenantId,
1295
1295
  () => value.apply(target, args)
1296
1296
  );
1297
+ return rebind(result, target, proxy, tenantId);
1297
1298
  };
1298
1299
  }
1299
1300
  });
1301
+ return proxy;
1302
+ }
1303
+ function rebind(result, target, proxy, tenantId) {
1304
+ if (result === target) {
1305
+ return proxy;
1306
+ }
1307
+ if (isEntityManager(result) && result !== proxy) {
1308
+ return wrapEmWithTenantContext(result, tenantId);
1309
+ }
1310
+ return result;
1311
+ }
1312
+ function isEntityManager(value) {
1313
+ return typeof value === "object" && value !== null && "fork" in value && typeof value.fork === "function" && "flush" in value && typeof value.flush === "function" && "persist" in value && typeof value.persist === "function";
1300
1314
  }
1301
1315
  // Annotate the CommonJS export names for ESM import in node:
1302
1316
  0 && (module.exports = {