@duraxis/nestjs 0.3.0 → 0.5.0

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,35 @@
1
1
  # @duraxis/nestjs changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6377fde: Add framework-independent configuration and owned database/ORM factories, bounded decorated-entity discovery, and shared NestJS/CLI schema resolution. Initialize projects with one source-root configuration and direct AST-guided AppModule integration. Support static inspection/mutation, centralized named connections, registry-free generators and source/compiled deployments without runtime CLI dependencies. Use shared typed configuration across runtime and CLI, standard Nest feature modules, and authenticated encrypted cursors. Document storage, migration, discovery and lifecycle contracts.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [6377fde]
12
+ - @duraxis/core@0.5.0
13
+ - @duraxis/orm@0.5.0
14
+ - @duraxis/storage@0.2.1
15
+
16
+ ## 0.4.0
17
+
18
+ ### Minor Changes
19
+
20
+ - a4bed1c: Harden bounded production pilots with hierarchical resource admission, query and transaction deadlines, tracked pending I/O, bounded materialization, weighted caches, incremental listings and journal replay, and verified single-owner garbage collection.
21
+
22
+ Breaking pre-1.0 changes: Core requires bounded-read adapter capabilities; resource limits now reject oversized work; destructive S3 GC fails closed; encrypted expiring v3 cursors replace signed database cursors. Restart pagination and provision stable encryption keys. Tenant context checks strengthen application isolation but do not authorize raw storage access.
23
+
24
+ Add conservative commit reconciliation and bounded atomic idempotency receipts without callback retries. Preserve manifest CAS, physical persistence formats and migration checksum identities. See docs/PRODUCTION-HARDENING.md for defaults, deployment constraints, receipt retention and remaining index/FK accounting limitations.
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [a4bed1c]
29
+ - @duraxis/core@0.4.0
30
+ - @duraxis/storage@0.2.0
31
+ - @duraxis/orm@0.4.0
32
+
3
33
  ## 0.3.0
4
34
 
5
35
  ### Minor Changes
@@ -64,7 +94,7 @@
64
94
 
65
95
  ### Patch Changes
66
96
 
67
- - a447bb5: Activate declarative transactions automatically for standard Nest class providers using application-scoped property injection. Preserve provider identity and support singleton, transient and request scopes, lifecycle calls after injection, inherited metadata and self-invocation. Deprecate the transactional registration helpers while retaining their named-connection defaults for migration. Self-invocation now honors inner transaction boundaries; constructor-time transactions remain unsupported and are documented explicitly.
97
+ - a447bb5: Activate declarative transactions automatically for standard Nest class providers using application-scoped property injection. Preserve provider identity and support singleton, transient and request scopes, lifecycle calls after injection, inherited metadata and self-invocation. Self-invocation now honors inner transaction boundaries; constructor-time transactions remain unsupported and are documented explicitly.
68
98
 
69
99
  ## 0.1.1
70
100
 
package/README.md CHANGED
@@ -130,14 +130,9 @@ estáticos e substituição de métodos após a injeção não são suportados.
130
130
  aguarda transações em andamento e rejeita novas transações; depois de remover a conexão, chamadas
131
131
  decoradas falham com `TransactionManagerNotFoundError`.
132
132
 
133
- ### Migração
134
-
135
- `forTransactionalFeature(entities, providers, connectionName)` e
136
- `forTransactionalProviders(providers, connectionName)` estão depreciados e continuam disponíveis
137
- para migração. Troque-os por `forFeature(entities, connectionName)` e mova os serviços para
138
- `providers` do módulo consumidor. Para conexões nomeadas, explicite `connectionName` no decorator.
139
- A remoção dos métodos antigos fica para uma versão incompatível futura. Chamadas por `this` agora
140
- aplicam as opções transacionais do método interno, inclusive propagação e regras de rollback.
133
+ Declare serviços em `providers` do módulo consumidor e registre entidades com `forFeature`.
134
+ Para conexões nomeadas, explicite `connectionName` no decorator transacional. Chamadas por
135
+ `this` aplicam as opções do método interno, inclusive propagação e regras de rollback.
141
136
 
142
137
  Veja a [decisão de arquitetura](../../docs/NESTJS_TRANSACTIONS.md) para a análise do ciclo de vida.
143
138
 
@@ -157,3 +152,13 @@ For S3, coordinate application writers separately: manifest CAS prevents competi
157
152
  publications but does not put application replicas into maintenance mode. Stop
158
153
  older incompatible replicas before migration and start compatible versions after
159
154
  successful validation; use staged compatible schema releases for rolling upgrades.
155
+
156
+ ## Production resource and lifecycle limits
157
+
158
+ See the [production hardening guide](../../docs/PRODUCTION-HARDENING.md) for bounded defaults, cancellation, verified maintenance, tenant trust boundaries, encrypted cursors, upgrade instructions and remaining pilot limitations. Core rejects storage adapters without bounded-read capability; destructive shared-storage garbage collection is unsupported.
159
+
160
+ ## CLI project setup
161
+
162
+ Run `npx --package @duraxis/cli@latest duraxis init` to generate one source-root configuration. NestJS AppModule integration is automatic; standalone applications call the public runtime factories. See the [shared configuration API and examples](../../docs/CLI-SETUP.md) and [setup guide](../../docs/CLI-SETUP.md).
163
+
164
+ `DuraxisModule.forRoot(config)` also accepts Core shared configuration, including a named connections map. Located filesystem discovery is compared with existing feature registrations and mismatches fail explicitly. Existing feature-only `autoLoadEntities`, `forRootAsync`, injection tokens, transaction APIs and resource ownership remain compatible. Use explicit connection names for named repository/transaction injection.
@@ -1,5 +1,5 @@
1
1
  import type { InjectionToken, ModuleMetadata } from "@nestjs/common";
2
- import type { DuraxisDatabaseOptions } from "@duraxis/core";
2
+ import type { DuraxisDatabaseOptions, DuraxisConnectionOptions } from "@duraxis/core";
3
3
  import type { DuraxisOrmOptions, EntityClass } from "@duraxis/orm";
4
4
  import type { StorageDriver } from "@duraxis/storage";
5
5
  export type DuraxisDriverFactory = () => StorageDriver | Promise<StorageDriver>;
@@ -20,6 +20,6 @@ type InjectTokens<TArguments extends readonly unknown[]> = {
20
20
  export interface DuraxisModuleAsyncOptions<TArguments extends readonly unknown[] = readonly unknown[]> extends Pick<ModuleMetadata, "imports"> {
21
21
  readonly name?: string;
22
22
  readonly inject?: InjectTokens<TArguments>;
23
- readonly useFactory: (...arguments_: TArguments) => DuraxisModuleOptions | Promise<DuraxisModuleOptions>;
23
+ readonly useFactory: (...arguments_: TArguments) => DuraxisModuleOptions | DuraxisConnectionOptions | Promise<DuraxisModuleOptions | DuraxisConnectionOptions>;
24
24
  }
25
25
  export {};
@@ -1,12 +1,9 @@
1
- import type { DynamicModule, Type } from "@nestjs/common";
2
- import type { EntityClass } from "@duraxis/orm";
1
+ import type { DynamicModule } from "@nestjs/common";
2
+ import { type EntityClass } from "@duraxis/orm";
3
+ import { type DuraxisConfiguration } from "@duraxis/core";
3
4
  import type { DuraxisModuleAsyncOptions, DuraxisRootModuleOptions } from "./duraxis.interfaces.js";
4
5
  export declare class DuraxisModule {
5
- static forRoot(options: DuraxisRootModuleOptions): DynamicModule;
6
+ static forRoot(options: DuraxisRootModuleOptions | DuraxisConfiguration): DynamicModule;
6
7
  static forRootAsync<TArguments extends readonly unknown[]>(options: DuraxisModuleAsyncOptions<TArguments>): DynamicModule;
7
8
  static forFeature(entities: readonly EntityClass[], connectionName?: string): DynamicModule;
8
- /** @deprecated Use forFeature(entities, connectionName) and regular module providers. */
9
- static forTransactionalFeature(entities: readonly EntityClass[], providers: readonly Type<object>[], connectionName?: string): DynamicModule;
10
- /** @deprecated Declare services in the consuming module's providers array. */
11
- static forTransactionalProviders(providers: readonly Type<object>[], connectionName?: string): DynamicModule;
12
9
  }
package/dist/index.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _nestjs_common = require("@nestjs/common");
3
3
  let _nestjs_core = require("@nestjs/core");
4
- let _duraxis_core = require("@duraxis/core");
5
4
  let _duraxis_orm = require("@duraxis/orm");
5
+ let _duraxis_core = require("@duraxis/core");
6
6
  let node_async_hooks = require("node:async_hooks");
7
7
  // src/duraxis.tokens.ts
8
8
  var DEFAULT_DURAXIS_CONNECTION = "default";
@@ -462,6 +462,7 @@ var TransactionManager = class {
462
462
  #ormFacade;
463
463
  #accepting = true;
464
464
  #activePhysicalTransactions = 0;
465
+ #shutdown;
465
466
  #shutdownWaiters = /* @__PURE__ */ new Set();
466
467
  constructor(connectionName, connection, orm, contexts) {
467
468
  this.connectionName = connectionName;
@@ -548,10 +549,27 @@ var TransactionManager = class {
548
549
  rejectMixedTransaction() {
549
550
  throw new UnsupportedMixedTransactionError();
550
551
  }
551
- async shutdown() {
552
+ shutdown(timeoutMs = 3e4) {
552
553
  this.#accepting = false;
553
- if (this.#activePhysicalTransactions == 0) return;
554
- await new Promise((resolve) => this.#shutdownWaiters.add(resolve));
554
+ if (this.#activePhysicalTransactions == 0) return Promise.resolve();
555
+ if (this.#shutdown) return this.#shutdown;
556
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1) return Promise.reject(/* @__PURE__ */ new RangeError("Invalid transaction-manager shutdown deadline"));
557
+ this.#shutdown = new Promise((resolve, reject) => {
558
+ const complete = () => {
559
+ clearTimeout(timer);
560
+ this.#shutdownWaiters.delete(complete);
561
+ resolve();
562
+ };
563
+ const timer = setTimeout(() => {
564
+ this.#shutdownWaiters.delete(complete);
565
+ reject(/* @__PURE__ */ new Error("Transaction-manager shutdown deadline exceeded; active operations remain"));
566
+ }, timeoutMs);
567
+ this.#shutdownWaiters.add(complete);
568
+ });
569
+ this.#shutdown.catch(() => {
570
+ this.#shutdown = void 0;
571
+ });
572
+ return this.#shutdown;
555
573
  }
556
574
  async start(options, methodName, invocation) {
557
575
  if (!this.#accepting) throw new TransactionManagerShuttingDownError();
@@ -564,6 +582,11 @@ var TransactionManager = class {
564
582
  active: true,
565
583
  rollbackOnly: false
566
584
  };
585
+ const abort = () => {
586
+ physical.active = false;
587
+ physical.pending.clear();
588
+ };
589
+ manager.signal?.addEventListener("abort", abort, { once: true });
567
590
  const context = {
568
591
  physical,
569
592
  readOnly: options.readOnly ?? false,
@@ -591,6 +614,7 @@ var TransactionManager = class {
591
614
  });
592
615
  } finally {
593
616
  physical.active = false;
617
+ manager.signal?.removeEventListener("abort", abort);
594
618
  }
595
619
  });
596
620
  if (outcome.type == "committed-error") throw outcome.error;
@@ -636,72 +660,25 @@ var TransactionManager = class {
636
660
  if (options.connectionName != null) normalizeDuraxisConnectionName(options.connectionName);
637
661
  }
638
662
  };
639
- // src/transactions/transactional.metadata.ts
640
- var TRANSACTIONAL_METADATA = Symbol.for("@duraxis/nestjs/transactional");
641
- function transactionalOptions(instance, method) {
642
- const classOptions = Reflect.getMetadata(TRANSACTIONAL_METADATA, instance.constructor);
643
- const methodOptions = Reflect.getMetadata(TRANSACTIONAL_METADATA, method);
644
- return !classOptions && !methodOptions ? void 0 : {
645
- ...classOptions,
646
- ...methodOptions
647
- };
648
- }
649
- // src/transactions/transactional.instrumentation.ts
650
- var MANAGERS = Symbol("Duraxis transaction managers");
651
- var bindings = /* @__PURE__ */ new WeakMap();
652
- var defaultConnections = /* @__PURE__ */ new WeakMap();
653
- var injectablePrototypes = /* @__PURE__ */ new WeakSet();
654
- var wrappers = /* @__PURE__ */ new WeakSet();
655
- var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
656
- "onModuleInit",
657
- "onApplicationBootstrap",
658
- "onModuleDestroy",
659
- "beforeApplicationShutdown",
660
- "onApplicationShutdown"
661
- ]);
662
- function injectTransactionManagers(prototype) {
663
- if (injectablePrototypes.has(prototype)) return;
664
- injectablePrototypes.add(prototype);
665
- Object.defineProperty(prototype, MANAGERS, { set(managers) {
666
- bindings.set(this, managers);
667
- instrumentTransactionalMethods(this);
668
- } });
669
- (0, _nestjs_common.Inject)(TransactionManagerRegistry)(prototype, MANAGERS);
670
- }
671
- function setTransactionalDefaultConnection(instance, name) {
672
- defaultConnections.set(instance, name);
673
- }
674
- function wrapTransactionalMethod(method, property) {
675
- if (wrappers.has(method)) return method;
676
- const wrapped = function(...arguments_) {
677
- const methodName = `${this.constructor.name}.${String(property)}`;
678
- const managers = bindings.get(this);
679
- if (!managers) throw new TransactionalProviderNotReadyError(methodName);
680
- const options = transactionalOptions(this, wrapped) ?? {};
681
- const name = normalizeDuraxisConnectionName(options.connectionName ?? defaultConnections.get(this));
682
- return managers.get(name).execute(options, methodName, () => Reflect.apply(method, this, arguments_));
663
+ // src/duraxis.module.ts
664
+ var _DuraxisModule;
665
+ function isSharedConfiguration(options) {
666
+ return (0, _duraxis_core.isDuraxisConfiguration)(options) || "location" in options || "baseDirectory" in options || "migrations" in options || typeof options.autoLoadEntities === "object" || typeof options.entities === "function" || typeof options.driver === "function" && options.driver.length > 0;
667
+ }
668
+ async function sharedConnectionOptions(config, discovery, name) {
669
+ const normalized = (0, _duraxis_core.normalizeDuraxisConnection)(config);
670
+ const entities = await (0, _duraxis_orm.discoverEntities)(config);
671
+ const features = discoverFeatureEntities(discovery, name);
672
+ if (config.autoLoadEntities && features.length && (features.length !== entities.length || features.some((entity) => !entities.includes(entity)))) throw new Error(`Duraxis entity discovery differs from forFeature registrations for connection ${name}. Align feature registrations and configured directories.`);
673
+ const driver = config.driver;
674
+ return {
675
+ driver: typeof driver === "function" ? () => driver(normalized.context) : driver,
676
+ database: normalized.database,
677
+ schema: normalized.schema,
678
+ entities,
679
+ closeStorage: config.closeStorage ?? typeof driver === "function"
683
680
  };
684
- for (const key of Reflect.getOwnMetadataKeys(method)) Reflect.defineMetadata(key, Reflect.getOwnMetadata(key, method), wrapped);
685
- wrappers.add(wrapped);
686
- return wrapped;
687
- }
688
- function instrumentTransactionalMethods(target) {
689
- const visited = /* @__PURE__ */ new Set();
690
- for (let prototype = target; prototype && prototype != Object.prototype; prototype = Object.getPrototypeOf(prototype)) for (const property of Reflect.ownKeys(prototype)) {
691
- if (visited.has(property)) continue;
692
- visited.add(property);
693
- if (property == "constructor" || LIFECYCLE_METHODS.has(property)) continue;
694
- const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
695
- const method = descriptor?.value;
696
- if (typeof method != "function" || !transactionalOptions(target, method)) continue;
697
- if (wrappers.has(method)) continue;
698
- Object.defineProperty(target, property, {
699
- ...descriptor,
700
- value: wrapTransactionalMethod(method, property)
701
- });
702
- }
703
681
  }
704
- // src/duraxis.module.ts
705
682
  function rootProviders(name, optionsProvider) {
706
683
  const connectionToken = getDuraxisConnectionToken(name);
707
684
  const ormToken = getDuraxisOrmToken(name);
@@ -771,25 +748,10 @@ function rootModule(name, providers, imports = []) {
771
748
  ]
772
749
  };
773
750
  }
774
- function featureModule(entities, services, connectionName) {
751
+ function featureModule(entities, connectionName) {
775
752
  const name = normalizeDuraxisConnectionName(connectionName);
776
753
  const uniqueEntities = [...new Set(entities)];
777
- const uniqueServices = [...new Set(services)];
778
754
  const repositoryProviders = uniqueEntities.map((entity) => repositoryProvider(entity, name));
779
- const serviceProviders = uniqueServices.flatMap((service) => {
780
- return [{
781
- provide: service,
782
- useClass: service,
783
- scope: _nestjs_common.Scope.DEFAULT
784
- }, {
785
- provide: Symbol(`${service.name} default transaction connection`),
786
- inject: [service],
787
- useFactory: (instance) => {
788
- setTransactionalDefaultConnection(instance, name);
789
- return name;
790
- }
791
- }];
792
- });
793
755
  let DuraxisFeatureEntitiesMarker = class DuraxisFeatureEntitiesMarker {};
794
756
  DuraxisFeatureEntitiesMarker = __decorate([DuraxisFeatureEntities({
795
757
  connectionName: name,
@@ -797,12 +759,8 @@ function featureModule(entities, services, connectionName) {
797
759
  })], DuraxisFeatureEntitiesMarker);
798
760
  return {
799
761
  module: DuraxisModule,
800
- providers: [
801
- DuraxisFeatureEntitiesMarker,
802
- ...repositoryProviders,
803
- ...serviceProviders
804
- ],
805
- exports: [...repositoryProviders.map((provider) => provider.provide), ...uniqueServices]
762
+ providers: [DuraxisFeatureEntitiesMarker, ...repositoryProviders],
763
+ exports: [...repositoryProviders.map((provider) => provider.provide)]
806
764
  };
807
765
  }
808
766
  function repositoryProvider(entity, connectionName) {
@@ -812,16 +770,41 @@ function repositoryProvider(entity, connectionName) {
812
770
  useFactory: (orm) => orm.getRepository(entity)
813
771
  };
814
772
  }
815
- var DuraxisModule = class DuraxisModule {
773
+ var DuraxisModule = _DuraxisModule = class DuraxisModule {
816
774
  static forRoot(options) {
817
- const name = normalizeDuraxisConnectionName(options.name);
775
+ if ("connections" in options) {
776
+ (0, _duraxis_core.selectDuraxisConnection)(options);
777
+ return {
778
+ module: _DuraxisModule,
779
+ imports: Object.keys(options.connections).sort().map((name) => {
780
+ const selected = (0, _duraxis_core.selectDuraxisConnection)(options, name);
781
+ return _DuraxisModule.forRoot({
782
+ ...selected,
783
+ baseDirectory: selected.baseDirectory ?? (0, _duraxis_core.normalizeDuraxisConnection)(selected).context.root
784
+ });
785
+ }),
786
+ exports: [_DuraxisModule]
787
+ };
788
+ }
789
+ if (isSharedConfiguration(options)) {
790
+ const config = options;
791
+ (0, _duraxis_core.normalizeDuraxisConnection)(config);
792
+ const name = normalizeDuraxisConnectionName(config.name);
793
+ return rootModule(name, rootProviders(name, {
794
+ provide: getDuraxisOptionsToken(name),
795
+ inject: [_nestjs_core.DiscoveryService],
796
+ useFactory: (discovery) => sharedConnectionOptions(config, discovery, name)
797
+ }));
798
+ }
799
+ const rootOptions = options;
800
+ const name = normalizeDuraxisConnectionName(rootOptions.name);
818
801
  const connectionOptions = {
819
- driver: options.driver,
820
- ...options.entities == null ? {} : { entities: options.entities },
821
- ...options.autoLoadEntities == null ? {} : { autoLoadEntities: options.autoLoadEntities },
822
- ...options.database == null ? {} : { database: options.database },
823
- ...options.schema == null ? {} : { schema: options.schema },
824
- ...options.closeStorage == null ? {} : { closeStorage: options.closeStorage }
802
+ driver: rootOptions.driver,
803
+ ...rootOptions.entities == null ? {} : { entities: rootOptions.entities },
804
+ ...rootOptions.autoLoadEntities == null ? {} : { autoLoadEntities: rootOptions.autoLoadEntities },
805
+ ...rootOptions.database == null ? {} : { database: rootOptions.database },
806
+ ...rootOptions.schema == null ? {} : { schema: rootOptions.schema },
807
+ ...rootOptions.closeStorage == null ? {} : { closeStorage: rootOptions.closeStorage }
825
808
  };
826
809
  return rootModule(name, rootProviders(name, {
827
810
  provide: getDuraxisOptionsToken(name),
@@ -832,23 +815,26 @@ var DuraxisModule = class DuraxisModule {
832
815
  const name = normalizeDuraxisConnectionName(options.name);
833
816
  return rootModule(name, rootProviders(name, {
834
817
  provide: getDuraxisOptionsToken(name),
835
- inject: options.inject == null ? [] : [...options.inject],
836
- useFactory: options.useFactory
818
+ inject: [_nestjs_core.DiscoveryService, ...options.inject ?? []],
819
+ useFactory: async (discovery, ...args) => {
820
+ const config = await options.useFactory(...args);
821
+ if (isSharedConfiguration(config)) {
822
+ const shared = config;
823
+ if (shared.name && shared.name !== name) throw new Error("Async configuration connection name must match forRootAsync name");
824
+ return sharedConnectionOptions({
825
+ ...shared,
826
+ name
827
+ }, discovery, name);
828
+ }
829
+ return config;
830
+ }
837
831
  }), options.imports);
838
832
  }
839
833
  static forFeature(entities, connectionName) {
840
- return featureModule(entities, [], connectionName);
841
- }
842
- /** @deprecated Use forFeature(entities, connectionName) and regular module providers. */
843
- static forTransactionalFeature(entities, providers, connectionName) {
844
- return featureModule(entities, providers, connectionName);
845
- }
846
- /** @deprecated Declare services in the consuming module's providers array. */
847
- static forTransactionalProviders(providers, connectionName) {
848
- return featureModule([], providers, connectionName);
834
+ return featureModule(entities, connectionName);
849
835
  }
850
836
  };
851
- DuraxisModule = __decorate([(0, _nestjs_common.Module)({})], DuraxisModule);
837
+ DuraxisModule = _DuraxisModule = __decorate([(0, _nestjs_common.Module)({})], DuraxisModule);
852
838
  // src/duraxis.decorators.ts
853
839
  function InjectDuraxisRepository(entity, connectionName) {
854
840
  return (0, _nestjs_common.Inject)(getDuraxisRepositoryToken(entity, connectionName));
@@ -862,6 +848,67 @@ function InjectDuraxisDatabase(connectionName) {
862
848
  function InjectDuraxisTransactionManager(connectionName) {
863
849
  return (0, _nestjs_common.Inject)(getDuraxisTransactionManagerToken(connectionName));
864
850
  }
851
+ // src/transactions/transactional.metadata.ts
852
+ var TRANSACTIONAL_METADATA = Symbol.for("@duraxis/nestjs/transactional");
853
+ function transactionalOptions(instance, method) {
854
+ const classOptions = Reflect.getMetadata(TRANSACTIONAL_METADATA, instance.constructor);
855
+ const methodOptions = Reflect.getMetadata(TRANSACTIONAL_METADATA, method);
856
+ return !classOptions && !methodOptions ? void 0 : {
857
+ ...classOptions,
858
+ ...methodOptions
859
+ };
860
+ }
861
+ // src/transactions/transactional.instrumentation.ts
862
+ var MANAGERS = Symbol("Duraxis transaction managers");
863
+ var bindings = /* @__PURE__ */ new WeakMap();
864
+ var injectablePrototypes = /* @__PURE__ */ new WeakSet();
865
+ var wrappers = /* @__PURE__ */ new WeakSet();
866
+ var LIFECYCLE_METHODS = /* @__PURE__ */ new Set([
867
+ "onModuleInit",
868
+ "onApplicationBootstrap",
869
+ "onModuleDestroy",
870
+ "beforeApplicationShutdown",
871
+ "onApplicationShutdown"
872
+ ]);
873
+ function injectTransactionManagers(prototype) {
874
+ if (injectablePrototypes.has(prototype)) return;
875
+ injectablePrototypes.add(prototype);
876
+ Object.defineProperty(prototype, MANAGERS, { set(managers) {
877
+ bindings.set(this, managers);
878
+ instrumentTransactionalMethods(this);
879
+ } });
880
+ (0, _nestjs_common.Inject)(TransactionManagerRegistry)(prototype, MANAGERS);
881
+ }
882
+ function wrapTransactionalMethod(method, property) {
883
+ if (wrappers.has(method)) return method;
884
+ const wrapped = function(...arguments_) {
885
+ const methodName = `${this.constructor.name}.${String(property)}`;
886
+ const managers = bindings.get(this);
887
+ if (!managers) throw new TransactionalProviderNotReadyError(methodName);
888
+ const options = transactionalOptions(this, wrapped) ?? {};
889
+ const name = normalizeDuraxisConnectionName(options.connectionName);
890
+ return managers.get(name).execute(options, methodName, () => Reflect.apply(method, this, arguments_));
891
+ };
892
+ for (const key of Reflect.getOwnMetadataKeys(method)) Reflect.defineMetadata(key, Reflect.getOwnMetadata(key, method), wrapped);
893
+ wrappers.add(wrapped);
894
+ return wrapped;
895
+ }
896
+ function instrumentTransactionalMethods(target) {
897
+ const visited = /* @__PURE__ */ new Set();
898
+ for (let prototype = target; prototype && prototype != Object.prototype; prototype = Object.getPrototypeOf(prototype)) for (const property of Reflect.ownKeys(prototype)) {
899
+ if (visited.has(property)) continue;
900
+ visited.add(property);
901
+ if (property == "constructor" || LIFECYCLE_METHODS.has(property)) continue;
902
+ const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
903
+ const method = descriptor?.value;
904
+ if (typeof method != "function" || !transactionalOptions(target, method)) continue;
905
+ if (wrappers.has(method)) continue;
906
+ Object.defineProperty(target, property, {
907
+ ...descriptor,
908
+ value: wrapTransactionalMethod(method, property)
909
+ });
910
+ }
911
+ }
865
912
  // src/transactions/transactional.decorator.ts
866
913
  function Transactional(options = {}) {
867
914
  return (target, _propertyKey, descriptor) => {