@duraxis/nestjs 0.0.0-stage → 0.1.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 +4 -0
- package/LICENSE +15 -0
- package/README.md +94 -2
- package/dist/duraxis.connection.d.ts +18 -0
- package/dist/duraxis.decorators.d.ts +5 -0
- package/dist/duraxis.errors.d.ts +6 -0
- package/dist/duraxis.feature-discovery.d.ts +8 -0
- package/dist/duraxis.interfaces.d.ts +28 -0
- package/dist/duraxis.module.d.ts +10 -0
- package/dist/duraxis.registry.d.ts +8 -0
- package/dist/duraxis.tokens.d.ts +9 -0
- package/dist/index.cjs +849 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +813 -0
- package/dist/index.js.map +1 -0
- package/dist/transactions/transaction-aware.repository.d.ts +4 -0
- package/dist/transactions/transaction-context.manager.d.ts +18 -0
- package/dist/transactions/transaction-manager.registry.d.ts +7 -0
- package/dist/transactions/transaction.errors.d.ts +40 -0
- package/dist/transactions/transaction.manager.d.ts +29 -0
- package/dist/transactions/transaction.types.d.ts +30 -0
- package/dist/transactions/transactional.decorator.d.ts +6 -0
- package/dist/transactions/transactional.proxy.d.ts +4 -0
- package/package.json +69 -3
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 João Paulo Dias
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,95 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @duraxis/nestjs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Integração oficial entre Duraxis e NestJS. O pacote gerencia conexões, expõe banco/ORM por
|
|
4
|
+
injeção, cria repositórios por feature e aplica transações declarativas a providers.
|
|
5
|
+
|
|
6
|
+
## Instalação
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pnpm add @duraxis/nestjs @duraxis/orm @duraxis/core @duraxis/storage-memory
|
|
10
|
+
npm install @duraxis/nestjs @duraxis/orm @duraxis/core @duraxis/storage-memory
|
|
11
|
+
yarn add @duraxis/nestjs @duraxis/orm @duraxis/core @duraxis/storage-memory
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
O consumidor também deve ter `@nestjs/common` e `@nestjs/core` 10 ou 11, além dos peers normais
|
|
15
|
+
do Nest (`reflect-metadata` e `rxjs`). Importe `reflect-metadata` no bootstrap e habilite decorators
|
|
16
|
+
e emissão de metadados no TypeScript.
|
|
17
|
+
|
|
18
|
+
## `forRoot` e `forFeature`
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import "reflect-metadata";
|
|
22
|
+
import { Injectable, Module } from "@nestjs/common";
|
|
23
|
+
import { Column, Entity, PrimaryKey, type Repository } from "@duraxis/orm";
|
|
24
|
+
import { DuraxisModule, InjectDuraxisRepository, Transactional } from "@duraxis/nestjs";
|
|
25
|
+
import { MemoryStorageDriver } from "@duraxis/storage-memory";
|
|
26
|
+
|
|
27
|
+
@Entity("users")
|
|
28
|
+
class User {
|
|
29
|
+
@PrimaryKey()
|
|
30
|
+
id!: string;
|
|
31
|
+
|
|
32
|
+
@Column({ type: "string", required: true })
|
|
33
|
+
email!: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Injectable()
|
|
37
|
+
class UserService {
|
|
38
|
+
constructor(@InjectDuraxisRepository(User) private readonly users: Repository<User>) {}
|
|
39
|
+
|
|
40
|
+
@Transactional()
|
|
41
|
+
async create(id: string, email: string): Promise<void> {
|
|
42
|
+
await this.users.insert({ id, email });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@Module({
|
|
47
|
+
imports: [
|
|
48
|
+
DuraxisModule.forRoot({
|
|
49
|
+
driver: new MemoryStorageDriver(),
|
|
50
|
+
entities: [User],
|
|
51
|
+
schema: { mode: "create" },
|
|
52
|
+
}),
|
|
53
|
+
DuraxisModule.forTransactionalFeature([User], [UserService]),
|
|
54
|
+
],
|
|
55
|
+
})
|
|
56
|
+
export class AppModule {}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`forRoot` cria uma conexão global. `forFeature([Entity])` disponibiliza os repositórios somente
|
|
60
|
+
no módulo da feature. Conexões nomeadas usam o mesmo nome em `forRoot`, `forFeature` e nos
|
|
61
|
+
decorators de injeção.
|
|
62
|
+
|
|
63
|
+
## `forRootAsync` e `autoLoadEntities`
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
DuraxisModule.forRootAsync({
|
|
67
|
+
imports: [ConfigModule],
|
|
68
|
+
inject: [ConfigService],
|
|
69
|
+
useFactory: async (config: ConfigService) => ({
|
|
70
|
+
driver: await createDriver(config),
|
|
71
|
+
autoLoadEntities: true,
|
|
72
|
+
schema: { mode: "create" },
|
|
73
|
+
}),
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Com `autoLoadEntities: true`, entidades declaradas por `forFeature` ou
|
|
78
|
+
`forTransactionalFeature` para a mesma conexão são agregadas durante a inicialização. Sem essa
|
|
79
|
+
opção, elas também devem constar em `entities` no root.
|
|
80
|
+
|
|
81
|
+
## Injeção e transações
|
|
82
|
+
|
|
83
|
+
As APIs públicas incluem `InjectDuraxisRepository`, `InjectDuraxisOrm`,
|
|
84
|
+
`InjectDuraxisDatabase`, `InjectDuraxisTransactionManager` e seus geradores de token.
|
|
85
|
+
|
|
86
|
+
`@Transactional()` é aplicado por proxy: registre o provider com
|
|
87
|
+
`forTransactionalFeature(entities, providers)` ou
|
|
88
|
+
`forTransactionalProviders(providers)`. Métodos transacionais devem retornar `Promise`. A API
|
|
89
|
+
implementa propagação `REQUIRED`, `REQUIRES_NEW`, `SUPPORTS`, `MANDATORY`, `NOT_SUPPORTED` e
|
|
90
|
+
`NEVER`; `NESTED`, timeout e níveis além de `DEFAULT`/`SNAPSHOT` são rejeitados. `readOnly`,
|
|
91
|
+
`rollbackFor` e `noRollbackFor` também estão disponíveis.
|
|
92
|
+
|
|
93
|
+
Transações declarativas dependem de metadados e inicialização do Nest; o pacote não é marcado
|
|
94
|
+
como livre de efeitos colaterais. Ele não adiciona coordenação distribuída. Requer Node.js
|
|
95
|
+
22.12+.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OnApplicationShutdown, OnModuleDestroy } from "@nestjs/common";
|
|
2
|
+
import { DuraxisDatabase } from "@duraxis/core";
|
|
3
|
+
import { DuraxisORM } from "@duraxis/orm";
|
|
4
|
+
import type { DuraxisModuleOptions } from "./duraxis.interfaces.js";
|
|
5
|
+
export declare class DuraxisNestConnection implements OnModuleDestroy, OnApplicationShutdown {
|
|
6
|
+
#private;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly database: DuraxisDatabase;
|
|
9
|
+
readonly orm: DuraxisORM;
|
|
10
|
+
private readonly onClosed;
|
|
11
|
+
private constructor();
|
|
12
|
+
static create(name: string, options: DuraxisModuleOptions, onClosed?: () => void): Promise<DuraxisNestConnection>;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
setBeforeClose(callback: () => Promise<void>): void;
|
|
15
|
+
private closeResources;
|
|
16
|
+
onModuleDestroy(): Promise<void>;
|
|
17
|
+
onApplicationShutdown(): Promise<void>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EntityClass } from "@duraxis/orm";
|
|
2
|
+
export declare function InjectDuraxisRepository<TEntity extends object>(entity: EntityClass<TEntity>, connectionName?: string): ParameterDecorator & PropertyDecorator;
|
|
3
|
+
export declare function InjectDuraxisOrm(connectionName?: string): ParameterDecorator & PropertyDecorator;
|
|
4
|
+
export declare function InjectDuraxisDatabase(connectionName?: string): ParameterDecorator & PropertyDecorator;
|
|
5
|
+
export declare function InjectDuraxisTransactionManager(connectionName?: string): ParameterDecorator & PropertyDecorator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DiscoveryService } from "@nestjs/core";
|
|
2
|
+
import type { EntityClass } from "@duraxis/orm";
|
|
3
|
+
export interface DuraxisFeatureEntitiesMetadata {
|
|
4
|
+
readonly connectionName: string;
|
|
5
|
+
readonly entities: readonly EntityClass[];
|
|
6
|
+
}
|
|
7
|
+
export declare const DuraxisFeatureEntities: import("@nestjs/core").DiscoverableDecorator<DuraxisFeatureEntitiesMetadata>;
|
|
8
|
+
export declare function discoverFeatureEntities(discovery: DiscoveryService, connectionName: string): readonly EntityClass[];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { InjectionToken, ModuleMetadata } from "@nestjs/common";
|
|
2
|
+
import type { DuraxisDatabaseOptions } from "@duraxis/core";
|
|
3
|
+
import type { DuraxisOrmOptions, EntityClass } from "@duraxis/orm";
|
|
4
|
+
import type { StorageDriver } from "@duraxis/storage";
|
|
5
|
+
export type DuraxisDriverFactory = () => StorageDriver | Promise<StorageDriver>;
|
|
6
|
+
export interface DuraxisModuleOptions {
|
|
7
|
+
readonly driver: StorageDriver | DuraxisDriverFactory;
|
|
8
|
+
readonly entities?: readonly EntityClass[];
|
|
9
|
+
readonly autoLoadEntities?: boolean;
|
|
10
|
+
readonly database?: Omit<DuraxisDatabaseOptions, "storage">;
|
|
11
|
+
readonly schema?: DuraxisOrmOptions["schema"];
|
|
12
|
+
/**
|
|
13
|
+
* Defaults to true for a driver factory and false for a supplied driver instance.
|
|
14
|
+
*/
|
|
15
|
+
readonly closeStorage?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface DuraxisRootModuleOptions extends DuraxisModuleOptions {
|
|
18
|
+
readonly name?: string;
|
|
19
|
+
}
|
|
20
|
+
type InjectTokens<TArguments extends readonly unknown[]> = {
|
|
21
|
+
readonly [TIndex in keyof TArguments]: InjectionToken;
|
|
22
|
+
};
|
|
23
|
+
export interface DuraxisModuleAsyncOptions<TArguments extends readonly unknown[] = readonly unknown[]> extends Pick<ModuleMetadata, "imports"> {
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
readonly inject?: InjectTokens<TArguments>;
|
|
26
|
+
readonly useFactory: (...arguments_: TArguments) => DuraxisModuleOptions | Promise<DuraxisModuleOptions>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DynamicModule, Type } from "@nestjs/common";
|
|
2
|
+
import type { EntityClass } from "@duraxis/orm";
|
|
3
|
+
import type { DuraxisModuleAsyncOptions, DuraxisRootModuleOptions } from "./duraxis.interfaces.js";
|
|
4
|
+
export declare class DuraxisModule {
|
|
5
|
+
static forRoot(options: DuraxisRootModuleOptions): DynamicModule;
|
|
6
|
+
static forRootAsync<TArguments extends readonly unknown[]>(options: DuraxisModuleAsyncOptions<TArguments>): DynamicModule;
|
|
7
|
+
static forFeature(entities: readonly EntityClass[], connectionName?: string): DynamicModule;
|
|
8
|
+
static forTransactionalFeature(entities: readonly EntityClass[], providers: readonly Type<object>[], connectionName?: string): DynamicModule;
|
|
9
|
+
static forTransactionalProviders(providers: readonly Type<object>[], connectionName?: string): DynamicModule;
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DuraxisNestConnection } from "./duraxis.connection.js";
|
|
2
|
+
import type { DuraxisModuleOptions } from "./duraxis.interfaces.js";
|
|
3
|
+
export declare class DuraxisConnectionRegistry {
|
|
4
|
+
#private;
|
|
5
|
+
create(name: string, options: DuraxisModuleOptions): Promise<DuraxisNestConnection>;
|
|
6
|
+
}
|
|
7
|
+
export declare class DuraxisConnectionRegistryModule {
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { EntityClass } from "@duraxis/orm";
|
|
2
|
+
export declare const DEFAULT_DURAXIS_CONNECTION = "default";
|
|
3
|
+
export declare function normalizeDuraxisConnectionName(name?: string): string;
|
|
4
|
+
export declare function getDuraxisOrmToken(connectionName?: string): symbol;
|
|
5
|
+
export declare function getDuraxisDatabaseToken(connectionName?: string): symbol;
|
|
6
|
+
export declare function getDuraxisTransactionManagerToken(connectionName?: string): symbol;
|
|
7
|
+
export declare function getDuraxisRepositoryToken<TEntity extends object>(entity: EntityClass<TEntity>, connectionName?: string): symbol;
|
|
8
|
+
export declare function getDuraxisOptionsToken(connectionName?: string): symbol;
|
|
9
|
+
export declare function getDuraxisConnectionToken(connectionName?: string): symbol;
|