@duraxis/nestjs 0.4.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 +14 -1
- package/README.md +9 -8
- package/dist/duraxis.interfaces.d.ts +2 -2
- package/dist/duraxis.module.d.ts +4 -7
- package/dist/index.cjs +130 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +132 -109
- package/dist/index.js.map +1 -1
- package/dist/transactions/transactional.instrumentation.d.ts +0 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
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
|
+
|
|
3
16
|
## 0.4.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -81,7 +94,7 @@
|
|
|
81
94
|
|
|
82
95
|
### Patch Changes
|
|
83
96
|
|
|
84
|
-
- 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.
|
|
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.
|
|
85
98
|
|
|
86
99
|
## 0.1.1
|
|
87
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
|
-
|
|
134
|
-
|
|
135
|
-
`
|
|
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
|
|
|
@@ -161,3 +156,9 @@ successful validation; use staged compatible schema releases for rolling upgrade
|
|
|
161
156
|
## Production resource and lifecycle limits
|
|
162
157
|
|
|
163
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 {};
|
package/dist/duraxis.module.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import type { DynamicModule
|
|
2
|
-
import type
|
|
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";
|
|
@@ -660,72 +660,25 @@ var TransactionManager = class {
|
|
|
660
660
|
if (options.connectionName != null) normalizeDuraxisConnectionName(options.connectionName);
|
|
661
661
|
}
|
|
662
662
|
};
|
|
663
|
-
// src/
|
|
664
|
-
var
|
|
665
|
-
function
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
"onModuleInit",
|
|
681
|
-
"onApplicationBootstrap",
|
|
682
|
-
"onModuleDestroy",
|
|
683
|
-
"beforeApplicationShutdown",
|
|
684
|
-
"onApplicationShutdown"
|
|
685
|
-
]);
|
|
686
|
-
function injectTransactionManagers(prototype) {
|
|
687
|
-
if (injectablePrototypes.has(prototype)) return;
|
|
688
|
-
injectablePrototypes.add(prototype);
|
|
689
|
-
Object.defineProperty(prototype, MANAGERS, { set(managers) {
|
|
690
|
-
bindings.set(this, managers);
|
|
691
|
-
instrumentTransactionalMethods(this);
|
|
692
|
-
} });
|
|
693
|
-
(0, _nestjs_common.Inject)(TransactionManagerRegistry)(prototype, MANAGERS);
|
|
694
|
-
}
|
|
695
|
-
function setTransactionalDefaultConnection(instance, name) {
|
|
696
|
-
defaultConnections.set(instance, name);
|
|
697
|
-
}
|
|
698
|
-
function wrapTransactionalMethod(method, property) {
|
|
699
|
-
if (wrappers.has(method)) return method;
|
|
700
|
-
const wrapped = function(...arguments_) {
|
|
701
|
-
const methodName = `${this.constructor.name}.${String(property)}`;
|
|
702
|
-
const managers = bindings.get(this);
|
|
703
|
-
if (!managers) throw new TransactionalProviderNotReadyError(methodName);
|
|
704
|
-
const options = transactionalOptions(this, wrapped) ?? {};
|
|
705
|
-
const name = normalizeDuraxisConnectionName(options.connectionName ?? defaultConnections.get(this));
|
|
706
|
-
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"
|
|
707
680
|
};
|
|
708
|
-
for (const key of Reflect.getOwnMetadataKeys(method)) Reflect.defineMetadata(key, Reflect.getOwnMetadata(key, method), wrapped);
|
|
709
|
-
wrappers.add(wrapped);
|
|
710
|
-
return wrapped;
|
|
711
|
-
}
|
|
712
|
-
function instrumentTransactionalMethods(target) {
|
|
713
|
-
const visited = /* @__PURE__ */ new Set();
|
|
714
|
-
for (let prototype = target; prototype && prototype != Object.prototype; prototype = Object.getPrototypeOf(prototype)) for (const property of Reflect.ownKeys(prototype)) {
|
|
715
|
-
if (visited.has(property)) continue;
|
|
716
|
-
visited.add(property);
|
|
717
|
-
if (property == "constructor" || LIFECYCLE_METHODS.has(property)) continue;
|
|
718
|
-
const descriptor = Object.getOwnPropertyDescriptor(prototype, property);
|
|
719
|
-
const method = descriptor?.value;
|
|
720
|
-
if (typeof method != "function" || !transactionalOptions(target, method)) continue;
|
|
721
|
-
if (wrappers.has(method)) continue;
|
|
722
|
-
Object.defineProperty(target, property, {
|
|
723
|
-
...descriptor,
|
|
724
|
-
value: wrapTransactionalMethod(method, property)
|
|
725
|
-
});
|
|
726
|
-
}
|
|
727
681
|
}
|
|
728
|
-
// src/duraxis.module.ts
|
|
729
682
|
function rootProviders(name, optionsProvider) {
|
|
730
683
|
const connectionToken = getDuraxisConnectionToken(name);
|
|
731
684
|
const ormToken = getDuraxisOrmToken(name);
|
|
@@ -795,25 +748,10 @@ function rootModule(name, providers, imports = []) {
|
|
|
795
748
|
]
|
|
796
749
|
};
|
|
797
750
|
}
|
|
798
|
-
function featureModule(entities,
|
|
751
|
+
function featureModule(entities, connectionName) {
|
|
799
752
|
const name = normalizeDuraxisConnectionName(connectionName);
|
|
800
753
|
const uniqueEntities = [...new Set(entities)];
|
|
801
|
-
const uniqueServices = [...new Set(services)];
|
|
802
754
|
const repositoryProviders = uniqueEntities.map((entity) => repositoryProvider(entity, name));
|
|
803
|
-
const serviceProviders = uniqueServices.flatMap((service) => {
|
|
804
|
-
return [{
|
|
805
|
-
provide: service,
|
|
806
|
-
useClass: service,
|
|
807
|
-
scope: _nestjs_common.Scope.DEFAULT
|
|
808
|
-
}, {
|
|
809
|
-
provide: Symbol(`${service.name} default transaction connection`),
|
|
810
|
-
inject: [service],
|
|
811
|
-
useFactory: (instance) => {
|
|
812
|
-
setTransactionalDefaultConnection(instance, name);
|
|
813
|
-
return name;
|
|
814
|
-
}
|
|
815
|
-
}];
|
|
816
|
-
});
|
|
817
755
|
let DuraxisFeatureEntitiesMarker = class DuraxisFeatureEntitiesMarker {};
|
|
818
756
|
DuraxisFeatureEntitiesMarker = __decorate([DuraxisFeatureEntities({
|
|
819
757
|
connectionName: name,
|
|
@@ -821,12 +759,8 @@ function featureModule(entities, services, connectionName) {
|
|
|
821
759
|
})], DuraxisFeatureEntitiesMarker);
|
|
822
760
|
return {
|
|
823
761
|
module: DuraxisModule,
|
|
824
|
-
providers: [
|
|
825
|
-
|
|
826
|
-
...repositoryProviders,
|
|
827
|
-
...serviceProviders
|
|
828
|
-
],
|
|
829
|
-
exports: [...repositoryProviders.map((provider) => provider.provide), ...uniqueServices]
|
|
762
|
+
providers: [DuraxisFeatureEntitiesMarker, ...repositoryProviders],
|
|
763
|
+
exports: [...repositoryProviders.map((provider) => provider.provide)]
|
|
830
764
|
};
|
|
831
765
|
}
|
|
832
766
|
function repositoryProvider(entity, connectionName) {
|
|
@@ -836,16 +770,41 @@ function repositoryProvider(entity, connectionName) {
|
|
|
836
770
|
useFactory: (orm) => orm.getRepository(entity)
|
|
837
771
|
};
|
|
838
772
|
}
|
|
839
|
-
var DuraxisModule = class DuraxisModule {
|
|
773
|
+
var DuraxisModule = _DuraxisModule = class DuraxisModule {
|
|
840
774
|
static forRoot(options) {
|
|
841
|
-
|
|
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);
|
|
842
801
|
const connectionOptions = {
|
|
843
|
-
driver:
|
|
844
|
-
...
|
|
845
|
-
...
|
|
846
|
-
...
|
|
847
|
-
...
|
|
848
|
-
...
|
|
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 }
|
|
849
808
|
};
|
|
850
809
|
return rootModule(name, rootProviders(name, {
|
|
851
810
|
provide: getDuraxisOptionsToken(name),
|
|
@@ -856,23 +815,26 @@ var DuraxisModule = class DuraxisModule {
|
|
|
856
815
|
const name = normalizeDuraxisConnectionName(options.name);
|
|
857
816
|
return rootModule(name, rootProviders(name, {
|
|
858
817
|
provide: getDuraxisOptionsToken(name),
|
|
859
|
-
inject: options.inject
|
|
860
|
-
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
|
+
}
|
|
861
831
|
}), options.imports);
|
|
862
832
|
}
|
|
863
833
|
static forFeature(entities, connectionName) {
|
|
864
|
-
return featureModule(entities,
|
|
865
|
-
}
|
|
866
|
-
/** @deprecated Use forFeature(entities, connectionName) and regular module providers. */
|
|
867
|
-
static forTransactionalFeature(entities, providers, connectionName) {
|
|
868
|
-
return featureModule(entities, providers, connectionName);
|
|
869
|
-
}
|
|
870
|
-
/** @deprecated Declare services in the consuming module's providers array. */
|
|
871
|
-
static forTransactionalProviders(providers, connectionName) {
|
|
872
|
-
return featureModule([], providers, connectionName);
|
|
834
|
+
return featureModule(entities, connectionName);
|
|
873
835
|
}
|
|
874
836
|
};
|
|
875
|
-
DuraxisModule = __decorate([(0, _nestjs_common.Module)({})], DuraxisModule);
|
|
837
|
+
DuraxisModule = _DuraxisModule = __decorate([(0, _nestjs_common.Module)({})], DuraxisModule);
|
|
876
838
|
// src/duraxis.decorators.ts
|
|
877
839
|
function InjectDuraxisRepository(entity, connectionName) {
|
|
878
840
|
return (0, _nestjs_common.Inject)(getDuraxisRepositoryToken(entity, connectionName));
|
|
@@ -886,6 +848,67 @@ function InjectDuraxisDatabase(connectionName) {
|
|
|
886
848
|
function InjectDuraxisTransactionManager(connectionName) {
|
|
887
849
|
return (0, _nestjs_common.Inject)(getDuraxisTransactionManagerToken(connectionName));
|
|
888
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
|
+
}
|
|
889
912
|
// src/transactions/transactional.decorator.ts
|
|
890
913
|
function Transactional(options = {}) {
|
|
891
914
|
return (target, _propertyKey, descriptor) => {
|