@fluojs/mongoose 1.0.0-beta.2 → 1.0.0-beta.3
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/README.ko.md +18 -12
- package/README.md +8 -1
- package/dist/module.d.ts +3 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +2 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
package/README.ko.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<p><a href="./README.md"><kbd>English</kbd></a> <strong><kbd>한국어</kbd></strong></p>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
세션 인지형 트랜잭션 처리와 라이프사이클 친화적인 외부 연결 관리를 제공하는 fluo용 Mongoose 통합 패키지입니다.
|
|
6
6
|
|
|
7
7
|
## 목차
|
|
8
8
|
|
|
@@ -19,15 +19,14 @@ fluo 애플리케이션을 위한 Mongoose 라이프사이클 및 세션 기반
|
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
21
|
pnpm add @fluojs/mongoose
|
|
22
|
-
# mongoose도 함께 설치되어 있어야 합니다.
|
|
23
22
|
pnpm add mongoose
|
|
24
23
|
```
|
|
25
24
|
|
|
26
25
|
## 사용 시점
|
|
27
26
|
|
|
28
|
-
- Mongoose를
|
|
29
|
-
-
|
|
30
|
-
-
|
|
27
|
+
- Mongoose를 나머지 애플리케이션과 같은 DI 및 라이프사이클 모델에 연결하고 싶을 때.
|
|
28
|
+
- 모든 서비스에서 MongoDB 세션과 트랜잭션을 임시 배관 코드 없이 하나의 wrapper로 다루고 싶을 때.
|
|
29
|
+
- 요청 범위 트랜잭션을 interceptor로 명시적으로 켜고 싶을 때.
|
|
31
30
|
|
|
32
31
|
## 빠른 시작
|
|
33
32
|
|
|
@@ -51,6 +50,8 @@ const connection = mongoose.createConnection('mongodb://localhost:27017/test');
|
|
|
51
50
|
class AppModule {}
|
|
52
51
|
```
|
|
53
52
|
|
|
53
|
+
`MongooseModule.forRootAsync(...)`는 주입된 의존성과 동기 또는 비동기로 옵션을 반환하는 `useFactory`를 지원합니다. provider를 전역으로 노출해야 할 때는 최상위 async 등록 옵션에 `global`을 전달하세요. 해석된 옵션은 모듈 인스턴스 안에서 재사용되므로 연결 설정과 dispose hook이 모든 provider에서 일관되게 유지됩니다.
|
|
54
|
+
|
|
54
55
|
## 라이프사이클과 종료
|
|
55
56
|
|
|
56
57
|
`MongooseModule`은 `MongooseConnection`을 fluo 애플리케이션 라이프사이클에 등록합니다. 이 패키지는 원본 Mongoose 연결을 직접 생성하거나 소유하지 않습니다. 애플리케이션 종료 시 외부 연결을 닫아야 한다면 `dispose` 훅을 전달하세요.
|
|
@@ -61,7 +62,7 @@ class AppModule {}
|
|
|
61
62
|
2. 해당 Mongoose 세션은 `abortTransaction()`과 `endSession()` 정리를 끝냅니다.
|
|
62
63
|
3. 설정한 `dispose(connection)` 훅은 활성 요청 트랜잭션이 모두 settled된 뒤에만 실행됩니다.
|
|
63
64
|
|
|
64
|
-
`createMongoosePlatformStatusSnapshot(...)`은 트래픽 처리 중에는 `ready`, 요청 트랜잭션 drain 중에는 `shutting-down`, dispose 훅 완료 뒤에는 `stopped`를 보고합니다. 수동 `transaction()`도 요청 범위 트랜잭션과 같은 명시적 세션 계약을 사용하므로, 트랜잭션에 참여해야 하는 Mongoose 모델 작업에는 repository 코드가 `conn.currentSession()`을 전달해야 합니다.
|
|
65
|
+
`createMongoosePlatformStatusSnapshot(...)`은 트래픽 처리 중에는 `ready`, 요청 트랜잭션 drain 중에는 `shutting-down`, dispose 훅 완료 뒤에는 `stopped`를 보고합니다. 상태 details에는 `sessionStrategy`, `transactionContext: 'als'`, 리소스 소유권, strict/session 지원 진단이 포함됩니다. 수동 `transaction()`도 요청 범위 트랜잭션과 같은 명시적 세션 계약을 사용하므로, 트랜잭션에 참여해야 하는 Mongoose 모델 작업에는 repository 코드가 `conn.currentSession()`을 전달해야 합니다.
|
|
65
66
|
|
|
66
67
|
## 공통 패턴
|
|
67
68
|
|
|
@@ -84,7 +85,7 @@ export class UserRepository {
|
|
|
84
85
|
|
|
85
86
|
### 수동 트랜잭션과 세션
|
|
86
87
|
|
|
87
|
-
`conn.transaction()
|
|
88
|
+
`conn.transaction()`으로 세션 경계를 만들고, Mongoose 모델 작업에는 세션을 명시적으로 전달합니다.
|
|
88
89
|
|
|
89
90
|
```typescript
|
|
90
91
|
await this.conn.transaction(async () => {
|
|
@@ -96,9 +97,11 @@ await this.conn.transaction(async () => {
|
|
|
96
97
|
});
|
|
97
98
|
```
|
|
98
99
|
|
|
99
|
-
|
|
100
|
+
감싼 연결이 `startSession()`을 구현하지 않으면 트랜잭션은 기본적으로 직접 실행으로 fallback합니다. fallback 대신 예외를 던지려면 `strictTransactions: true`를 설정합니다. 이때 오류 메시지는 `Transaction not supported: Mongoose connection does not implement startSession.`입니다.
|
|
101
|
+
|
|
102
|
+
### 요청 범위 트랜잭션
|
|
100
103
|
|
|
101
|
-
컨트롤러나 메서드에 `MongooseTransactionInterceptor`를 적용하면 전체 요청을
|
|
104
|
+
컨트롤러나 메서드에 `MongooseTransactionInterceptor`를 적용하면 전체 요청을 MongoDB 세션으로 감쌉니다.
|
|
102
105
|
|
|
103
106
|
```typescript
|
|
104
107
|
import { UseInterceptors } from '@fluojs/http';
|
|
@@ -108,6 +111,8 @@ import { MongooseTransactionInterceptor } from '@fluojs/mongoose';
|
|
|
108
111
|
class UserController {}
|
|
109
112
|
```
|
|
110
113
|
|
|
114
|
+
HTTP interceptor 밖에서 같은 request-aware transaction boundary가 필요하다면 `MongooseConnection.requestTransaction(...)`을 직접 사용할 수 있습니다. 중첩된 service transaction은 활성 session boundary를 재사용합니다.
|
|
115
|
+
|
|
111
116
|
## 공개 API
|
|
112
117
|
|
|
113
118
|
- `MongooseModule.forRoot(options)` / `MongooseModule.forRootAsync(options)`
|
|
@@ -122,6 +127,7 @@ class UserController {}
|
|
|
122
127
|
- `MongooseModuleOptions<TConnection>`
|
|
123
128
|
- `MongooseConnectionLike`
|
|
124
129
|
- `MongooseSessionLike`
|
|
130
|
+
- `MongooseHandleProvider`
|
|
125
131
|
|
|
126
132
|
## 관련 패키지
|
|
127
133
|
|
|
@@ -131,6 +137,6 @@ class UserController {}
|
|
|
131
137
|
|
|
132
138
|
## 예제 소스
|
|
133
139
|
|
|
134
|
-
- `packages/mongoose/src/vertical-slice.test.ts
|
|
135
|
-
- `packages/mongoose/src/module.test.ts
|
|
136
|
-
- `packages/mongoose/src/public-api.test.ts
|
|
140
|
+
- `packages/mongoose/src/vertical-slice.test.ts`
|
|
141
|
+
- `packages/mongoose/src/module.test.ts`
|
|
142
|
+
- `packages/mongoose/src/public-api.test.ts`
|
package/README.md
CHANGED
|
@@ -48,6 +48,8 @@ const connection = mongoose.createConnection('mongodb://localhost:27017/test');
|
|
|
48
48
|
class AppModule {}
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
`MongooseModule.forRootAsync(...)` accepts injected dependencies and a `useFactory` that may return options synchronously or asynchronously. Pass `global` on the top-level async registration when the providers should be visible globally. The resolved options are reused for the module instance, so connection setup and disposal hooks stay consistent across all providers.
|
|
52
|
+
|
|
51
53
|
## Lifecycle and Shutdown
|
|
52
54
|
|
|
53
55
|
`MongooseModule` registers `MongooseConnection` with the fluo application lifecycle. The package does not create or own the raw Mongoose connection for you; pass a `dispose` hook when the application should close that external connection during shutdown.
|
|
@@ -58,7 +60,7 @@ Shutdown preserves request transaction cleanup order:
|
|
|
58
60
|
2. Their Mongoose sessions finish `abortTransaction()` and `endSession()` cleanup.
|
|
59
61
|
3. The configured `dispose(connection)` hook runs only after active request transactions have settled.
|
|
60
62
|
|
|
61
|
-
`createMongoosePlatformStatusSnapshot(...)` reports `ready` while serving traffic, `shutting-down` while request transactions are draining, and `stopped` after the dispose hook completes. Manual `transaction()` calls still use the same explicit-session contract as request-scoped transactions: repository code must pass `conn.currentSession()` into Mongoose model operations that participate in the transaction.
|
|
63
|
+
`createMongoosePlatformStatusSnapshot(...)` reports `ready` while serving traffic, `shutting-down` while request transactions are draining, and `stopped` after the dispose hook completes. The status details include `sessionStrategy`, `transactionContext: 'als'`, resource ownership, and strict/session support diagnostics. Manual `transaction()` calls still use the same explicit-session contract as request-scoped transactions: repository code must pass `conn.currentSession()` into Mongoose model operations that participate in the transaction.
|
|
62
64
|
|
|
63
65
|
## Common Patterns
|
|
64
66
|
|
|
@@ -88,6 +90,8 @@ await this.conn.transaction(async () => {
|
|
|
88
90
|
});
|
|
89
91
|
```
|
|
90
92
|
|
|
93
|
+
If the wrapped connection does not implement `startSession()`, transactions fall back to direct execution by default. Set `strictTransactions: true` to throw `Transaction not supported: Mongoose connection does not implement startSession.` instead of falling back.
|
|
94
|
+
|
|
91
95
|
### Request-scoped transactions
|
|
92
96
|
|
|
93
97
|
```ts
|
|
@@ -98,6 +102,8 @@ import { MongooseTransactionInterceptor } from '@fluojs/mongoose';
|
|
|
98
102
|
class UserController {}
|
|
99
103
|
```
|
|
100
104
|
|
|
105
|
+
Use `MongooseConnection.requestTransaction(...)` directly when you need the same request-aware transaction boundary outside an HTTP interceptor. Nested service transactions reuse the active session boundary.
|
|
106
|
+
|
|
101
107
|
## Public API
|
|
102
108
|
|
|
103
109
|
- `MongooseModule.forRoot(options)` / `MongooseModule.forRootAsync(options)`
|
|
@@ -112,6 +118,7 @@ class UserController {}
|
|
|
112
118
|
- `MongooseModuleOptions<TConnection>`
|
|
113
119
|
- `MongooseConnectionLike`
|
|
114
120
|
- `MongooseSessionLike`
|
|
121
|
+
- `MongooseHandleProvider`
|
|
115
122
|
|
|
116
123
|
## Related Packages
|
|
117
124
|
|
package/dist/module.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { AsyncModuleOptions } from '@fluojs/core';
|
|
|
2
2
|
import type { Provider } from '@fluojs/di';
|
|
3
3
|
import { type ModuleType } from '@fluojs/runtime';
|
|
4
4
|
import type { MongooseConnectionLike, MongooseModuleOptions } from './types.js';
|
|
5
|
+
type MongooseAsyncModuleOptions<TConnection extends MongooseConnectionLike> = AsyncModuleOptions<Omit<MongooseModuleOptions<TConnection>, 'global'>> & Pick<MongooseModuleOptions<TConnection>, 'global'>;
|
|
5
6
|
/**
|
|
6
7
|
* Creates Mongoose providers for manual module composition.
|
|
7
8
|
*
|
|
@@ -16,6 +17,7 @@ export declare class MongooseModule {
|
|
|
16
17
|
/** Creates a module definition from static Mongoose options. */
|
|
17
18
|
static forRoot<TConnection extends MongooseConnectionLike>(options: MongooseModuleOptions<TConnection>): ModuleType;
|
|
18
19
|
/** Creates a module definition from DI-aware async Mongoose options. */
|
|
19
|
-
static forRootAsync<TConnection extends MongooseConnectionLike>(options:
|
|
20
|
+
static forRootAsync<TConnection extends MongooseConnectionLike>(options: MongooseAsyncModuleOptions<TConnection>): ModuleType;
|
|
20
21
|
}
|
|
22
|
+
export {};
|
|
21
23
|
//# sourceMappingURL=module.d.ts.map
|
package/dist/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKhE,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKhE,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAahF,KAAK,0BAA0B,CAAC,WAAW,SAAS,sBAAsB,IAAI,kBAAkB,CAC9F,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,CACnD,GAAG,IAAI,CAAC,qBAAqB,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,CAAC;AAiFvD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,SAAS,sBAAsB,EAChF,OAAO,EAAE,qBAAqB,CAAC,WAAW,CAAC,GAC1C,QAAQ,EAAE,CAOZ;AA0BD;;GAEG;AACH,qBAAa,cAAc;IACzB,gEAAgE;IAChE,MAAM,CAAC,OAAO,CAAC,WAAW,SAAS,sBAAsB,EAAE,OAAO,EAAE,qBAAqB,CAAC,WAAW,CAAC,GAAG,UAAU;IAInH,wEAAwE;IACxE,MAAM,CAAC,YAAY,CAAC,WAAW,SAAS,sBAAsB,EAC5D,OAAO,EAAE,0BAA0B,CAAC,WAAW,CAAC,GAC/C,UAAU;CAGd"}
|
package/dist/module.js
CHANGED
|
@@ -70,6 +70,7 @@ function buildMongooseModule(options) {
|
|
|
70
70
|
class MongooseRootModuleDefinition {}
|
|
71
71
|
return defineModule(MongooseRootModuleDefinition, {
|
|
72
72
|
exports: MONGOOSE_MODULE_EXPORTS,
|
|
73
|
+
global: options.global ?? false,
|
|
73
74
|
providers: createMongooseProviders(options)
|
|
74
75
|
});
|
|
75
76
|
}
|
|
@@ -77,6 +78,7 @@ function buildMongooseModuleAsync(options) {
|
|
|
77
78
|
class MongooseAsyncModuleDefinition {}
|
|
78
79
|
return defineModule(MongooseAsyncModuleDefinition, {
|
|
79
80
|
exports: MONGOOSE_MODULE_EXPORTS,
|
|
81
|
+
global: options.global ?? false,
|
|
80
82
|
providers: createMongooseProvidersAsync(options)
|
|
81
83
|
});
|
|
82
84
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface MongooseModuleOptions<TConnection extends MongooseConnectionLik
|
|
|
27
27
|
connection: TConnection;
|
|
28
28
|
/** Optional shutdown hook used to close the connection or surrounding driver resources. */
|
|
29
29
|
dispose?: (connection: TConnection) => MaybePromise<void>;
|
|
30
|
+
/** Whether Mongoose providers should be visible globally. Defaults to `false`. */
|
|
31
|
+
global?: boolean;
|
|
30
32
|
/**
|
|
31
33
|
* Throws when transaction helpers are used against a connection that does not implement `startSession()`.
|
|
32
34
|
*
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,YAAY,CAAC,IAAI,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC/C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IACvC,iBAAiB,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IACxC,gBAAgB,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IACvC,UAAU,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,qBAAqB,CAAC,WAAW,SAAS,sBAAsB,GAAG,sBAAsB;IACxG,kFAAkF;IAClF,UAAU,EAAE,WAAW,CAAC;IACxB,2FAA2F;IAC3F,OAAO,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IAC1D;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB,CAAC,WAAW,SAAS,sBAAsB,GAAG,sBAAsB;IACzG,uFAAuF;IACvF,OAAO,IAAI,WAAW,CAAC;IACvB,2FAA2F;IA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zG,uFAAuF;IACvF,OAAO,IAAI,WAAW,CAAC;IACvB,2FAA2F;IAC3F,cAAc,IAAI,mBAAmB,GAAG,SAAS,CAAC;IAClD;;;;;OAKG;IACH,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD;;;;;;OAMG;IACH,kBAAkB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC/E"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"transaction",
|
|
10
10
|
"odm"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.0-beta.
|
|
12
|
+
"version": "1.0.0-beta.3",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@fluojs/
|
|
40
|
-
"@fluojs/
|
|
41
|
-
"@fluojs/
|
|
42
|
-
"@fluojs/runtime": "^1.0.0-beta.
|
|
39
|
+
"@fluojs/http": "^1.0.0-beta.10",
|
|
40
|
+
"@fluojs/di": "^1.0.0-beta.6",
|
|
41
|
+
"@fluojs/core": "^1.0.0-beta.4",
|
|
42
|
+
"@fluojs/runtime": "^1.0.0-beta.11"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"mongoose": ">=7.0.0"
|