@fluojs/drizzle 1.0.0-beta.2 → 1.0.0-beta.4
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 +15 -2
- package/README.md +15 -2
- package/dist/database.d.ts +3 -0
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +62 -7
- package/dist/module.d.ts +3 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +8 -3
- package/dist/tokens.d.ts +2 -0
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.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
|
@@ -90,6 +90,10 @@ await this.db.transaction(async () => {
|
|
|
90
90
|
});
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
중첩 호출은 활성 transaction boundary를 재사용합니다. 이미 boundary가 활성화되어 있는데 중첩 호출이 transaction option을 전달하면, 기존 transaction을 조용히 바꾸지 않고 해당 중첩 option을 거부합니다.
|
|
94
|
+
|
|
95
|
+
`database.transaction(...)`을 사용할 수 없고 `strictTransactions`가 `false`이면 `transaction()`과 `requestTransaction()`은 직접 실행으로 fallback합니다. 요청 범위 호출은 이 경우에도 `AbortSignal`을 존중합니다.
|
|
96
|
+
|
|
93
97
|
### 인터셉터 기반 요청 단위 트랜잭션
|
|
94
98
|
|
|
95
99
|
```ts
|
|
@@ -103,12 +107,16 @@ class UsersController {}
|
|
|
103
107
|
### 종료와 상태 계약
|
|
104
108
|
|
|
105
109
|
`DrizzleTransactionInterceptor`는 각 HTTP 요청을 `DrizzleDatabase.requestTransaction(...)`으로 실행합니다. 애플리케이션 종료 중에는 `DrizzleDatabase`가 아직 활성 상태인 요청 트랜잭션을 abort하고, 해당 transaction callback이 settle되거나 rollback될 때까지 기다린 뒤 선택적 `dispose(database)` hook을 실행합니다. 이 순서는 pool이나 외부 관리 리소스를 닫기 전에 driver가 rollback/cleanup 작업을 끝낼 수 있게 보장합니다.
|
|
110
|
+
기존 수동 transaction boundary 안에서 열린 중첩 `requestTransaction(...)` 호출도 shutdown tracking에 참여하므로, 두 번째 Drizzle transaction을 열지 않으면서 shutdown이 해당 호출을 abort하고 drain한 뒤 `dispose(database)`를 실행합니다.
|
|
111
|
+
종료가 시작된 뒤 새 `requestTransaction(...)` 호출은 거부되므로, 종료 boundary를 지난 뒤 시작되는 늦은 요청 트랜잭션보다 dispose가 먼저 실행되는 상황을 방지합니다.
|
|
112
|
+
요청 callback이 완료된 뒤 underlying Drizzle transaction runner가 commit 또는 rollback을 끝내기 전에 request signal이 abort되면, `requestTransaction(...)`은 먼저 해당 runner가 settle될 때까지 기다린 다음 abort reason으로 reject합니다. 이 동작은 Drizzle cleanup을 request cancellation과 직렬화하면서, 완료된 callback 결과를 반환하는 대신 늦은 request abort를 caller에게 드러냅니다.
|
|
106
113
|
|
|
107
114
|
`createDrizzlePlatformStatusSnapshot(...)`과 `DrizzleDatabase.createPlatformStatusSnapshot()`은 같은 계약을 진단 surface에 노출합니다.
|
|
108
115
|
|
|
109
116
|
- Drizzle이 종료 중이거나 중지된 상태이면, 또는 `strictTransactions`가 켜져 있는데 `database.transaction(...)` 지원이 없으면 `readiness.status`는 `not-ready`입니다.
|
|
110
117
|
- 요청 트랜잭션을 drain하는 종료 중에는 `health.status`가 `degraded`이고, dispose 이후에는 `unhealthy`입니다.
|
|
111
118
|
- `details.activeRequestTransactions`, `details.lifecycleState`, `details.strictTransactions`, `details.supportsTransaction`은 현재 요청 트랜잭션과 트랜잭션 지원 상태를 설명합니다.
|
|
119
|
+
- `details.transactionContext: 'als'`는 요청 및 service transaction boundary가 사용하는 async-local transaction context를 나타냅니다.
|
|
112
120
|
- `ownership.externallyManaged: true`와 `ownership.ownsResources: false`는 이 패키지가 설정된 dispose hook은 실행하지만 underlying driver resource의 소유권을 주장하지 않는다는 뜻입니다.
|
|
113
121
|
|
|
114
122
|
## 수동 모듈 구성
|
|
@@ -136,13 +144,18 @@ defineModule(ManualDrizzleModule, {
|
|
|
136
144
|
- `DrizzleModule.forRoot(options)` / `DrizzleModule.forRootAsync(options)`
|
|
137
145
|
- `DrizzleDatabase`
|
|
138
146
|
- `DrizzleTransactionInterceptor`
|
|
139
|
-
- `DRIZZLE_DATABASE`, `DRIZZLE_DISPOSE`, `DRIZZLE_OPTIONS`
|
|
147
|
+
- `DRIZZLE_DATABASE`, `DRIZZLE_DISPOSE`, `DRIZZLE_HANDLE_PROVIDER`, `DRIZZLE_OPTIONS`
|
|
140
148
|
- `createDrizzlePlatformStatusSnapshot(...)`
|
|
149
|
+
- `DrizzleDatabaseLike`
|
|
150
|
+
- `DrizzleModuleOptions`
|
|
151
|
+
- `DrizzleHandleProvider`
|
|
152
|
+
|
|
153
|
+
`DRIZZLE_HANDLE_PROVIDER`는 lifecycle-aware `DrizzleDatabase` wrapper를 가리키는 alias token입니다. `@fluojs/terminus` 같은 health integration은 이 token을 통해 raw database ping으로 fallback하기 전에 `createPlatformStatusSnapshot()`을 읽습니다.
|
|
141
154
|
|
|
142
155
|
### `DrizzleModule`
|
|
143
156
|
|
|
144
157
|
- `DrizzleModule.forRoot(options)` / `DrizzleModule.forRootAsync(options)`
|
|
145
|
-
- `forRootAsync(...)`는 `
|
|
158
|
+
- `forRootAsync(...)`는 database/dispose/transaction 설정을 factory에서 반환하는 DI-aware Drizzle 옵션을 받습니다. provider를 전역으로 노출해야 할 때는 최상위 async 등록 옵션에 `global`을 전달하세요.
|
|
146
159
|
- `strictTransactions: true`를 설정하면 transaction 지원이 없는 database handle에서 예외를 던집니다.
|
|
147
160
|
|
|
148
161
|
## 관련 패키지
|
package/README.md
CHANGED
|
@@ -90,6 +90,10 @@ await this.db.transaction(async () => {
|
|
|
90
90
|
});
|
|
91
91
|
```
|
|
92
92
|
|
|
93
|
+
Nested calls reuse the active transaction boundary. If a nested call passes transaction options while a boundary is already active, the package rejects those nested options instead of silently changing the existing transaction.
|
|
94
|
+
|
|
95
|
+
When `database.transaction(...)` is unavailable and `strictTransactions` is `false`, `transaction()` and `requestTransaction()` fall back to direct execution; request-scoped calls still honor `AbortSignal`.
|
|
96
|
+
|
|
93
97
|
### Request-scoped transactions with an interceptor
|
|
94
98
|
|
|
95
99
|
```ts
|
|
@@ -103,12 +107,16 @@ class UsersController {}
|
|
|
103
107
|
### Shutdown and status contracts
|
|
104
108
|
|
|
105
109
|
`DrizzleTransactionInterceptor` runs each HTTP request through `DrizzleDatabase.requestTransaction(...)`. During application shutdown, `DrizzleDatabase` aborts any still-active request transaction, waits for its transaction callback to settle or roll back, and only then runs the optional `dispose(database)` hook. This ordering lets drivers finish rollback/cleanup work before pools or externally managed resources are closed.
|
|
110
|
+
Nested `requestTransaction(...)` calls opened inside an existing manual transaction boundary also join shutdown tracking, so shutdown aborts and drains them before `dispose(database)` runs without opening a second Drizzle transaction.
|
|
111
|
+
New `requestTransaction(...)` calls are rejected once shutdown begins, so disposal cannot overtake a late request transaction that starts after the shutdown boundary is crossed.
|
|
112
|
+
If the request signal aborts after the request callback has completed but before the underlying Drizzle transaction runner finishes committing or rolling back, `requestTransaction(...)` waits for that runner to settle first and then rejects with the abort reason. This keeps Drizzle cleanup serialized with request cancellation while making the late request abort visible to the caller instead of returning the completed callback result.
|
|
106
113
|
|
|
107
114
|
`createDrizzlePlatformStatusSnapshot(...)` and `DrizzleDatabase.createPlatformStatusSnapshot()` expose the same contract to diagnostics surfaces:
|
|
108
115
|
|
|
109
116
|
- `readiness.status` is `not-ready` while Drizzle is shutting down or stopped, and when `strictTransactions` is enabled without `database.transaction(...)` support.
|
|
110
117
|
- `health.status` is `degraded` while request transactions are draining during shutdown and `unhealthy` after disposal.
|
|
111
118
|
- `details.activeRequestTransactions`, `details.lifecycleState`, `details.strictTransactions`, and `details.supportsTransaction` describe the current request transaction and transaction-capability state.
|
|
119
|
+
- `details.transactionContext: 'als'` identifies the async-local transaction context used by request and service transaction boundaries.
|
|
112
120
|
- `ownership.externallyManaged: true` and `ownership.ownsResources: false` mean the package runs your configured dispose hook but does not claim ownership of the underlying driver resources.
|
|
113
121
|
|
|
114
122
|
## Manual Module Composition
|
|
@@ -136,13 +144,18 @@ defineModule(ManualDrizzleModule, {
|
|
|
136
144
|
- `DrizzleModule.forRoot(options)` / `DrizzleModule.forRootAsync(options)`
|
|
137
145
|
- `DrizzleDatabase`
|
|
138
146
|
- `DrizzleTransactionInterceptor`
|
|
139
|
-
- `DRIZZLE_DATABASE`, `DRIZZLE_DISPOSE`, `DRIZZLE_OPTIONS`
|
|
147
|
+
- `DRIZZLE_DATABASE`, `DRIZZLE_DISPOSE`, `DRIZZLE_HANDLE_PROVIDER`, `DRIZZLE_OPTIONS`
|
|
140
148
|
- `createDrizzlePlatformStatusSnapshot(...)`
|
|
149
|
+
- `DrizzleDatabaseLike`
|
|
150
|
+
- `DrizzleModuleOptions`
|
|
151
|
+
- `DrizzleHandleProvider`
|
|
152
|
+
|
|
153
|
+
`DRIZZLE_HANDLE_PROVIDER` is an alias token for the lifecycle-aware `DrizzleDatabase` wrapper. Health integrations such as `@fluojs/terminus` use this token to read `createPlatformStatusSnapshot()` before falling back to raw database pings.
|
|
141
154
|
|
|
142
155
|
### `DrizzleModule`
|
|
143
156
|
|
|
144
157
|
- `DrizzleModule.forRoot(options)` / `DrizzleModule.forRootAsync(options)`
|
|
145
|
-
- `forRootAsync(...)` accepts `
|
|
158
|
+
- `forRootAsync(...)` accepts DI-aware Drizzle options whose factory returns the database/dispose/transaction settings; pass `global` on the top-level async registration when the providers should be visible globally.
|
|
146
159
|
- Supports `strictTransactions: true` to throw if transaction support is missing.
|
|
147
160
|
|
|
148
161
|
## Related Packages
|
package/dist/database.d.ts
CHANGED
|
@@ -64,7 +64,10 @@ export declare class DrizzleDatabase<TDatabase extends DrizzleDatabaseLike<TTran
|
|
|
64
64
|
requestTransaction<T>(fn: () => Promise<T>, signal?: AbortSignal, options?: TTransactionOptions): Promise<T>;
|
|
65
65
|
private executeTransaction;
|
|
66
66
|
private executeRequestTransaction;
|
|
67
|
+
private executeNestedRequestTransaction;
|
|
67
68
|
private executeRequestFallback;
|
|
69
|
+
private assertRequestTransactionsAvailable;
|
|
70
|
+
private throwIfRequestAborted;
|
|
68
71
|
private trackActiveRequestTransaction;
|
|
69
72
|
private untrackActiveRequestTransaction;
|
|
70
73
|
private resolveTransactionRunner;
|
package/dist/database.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAK7D,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAsBpB,KAAK,qBAAqB,GAAG;IAC3B,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAQF;;;;;;GAMG;AACH,qBACa,eAAe,CAC1B,SAAS,SAAS,mBAAmB,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,EAChF,oBAAoB,GAAG,SAAS,EAChC,mBAAmB,GAAG,OAAO,CAC7B,YAAW,qBAAqB,CAAC,SAAS,EAAE,oBAAoB,EAAE,mBAAmB,CAAC,EAAE,qBAAqB;IAO3G,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAPlC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqE;IAClG,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAuC;IACjF,OAAO,CAAC,cAAc,CAAkD;gBAGrD,QAAQ,EAAE,SAAS,EACnB,OAAO,CAAC,GAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,aAAA,EACvD,eAAe,GAAE,qBAAqD;IAGzF;;;;;;;;;OASG;IACH,OAAO,IAAI,SAAS,GAAG,oBAAoB;IAI3C,qGAAqG;IAC/F,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB5C,yFAAyF;IACzF,4BAA4B;IAS5B;;;;;;;;;;;;;OAaG;IACG,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;IAIrF;;;;;;;;;;;;OAYG;IACG,kBAAkB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;YAIpG,kBAAkB;YAmDlB,yBAAyB;YA8BzB,+BAA+B;YAqC/B,sBAAsB;IAkBpC,OAAO,CAAC,kCAAkC;IAM1C,OAAO,CAAC,qBAAqB;IAM7B,OAAO,CAAC,6BAA6B;IAIrC,OAAO,CAAC,+BAA+B;IAIvC,OAAO,CAAC,wBAAwB;CAWjC"}
|
package/dist/database.js
CHANGED
|
@@ -5,12 +5,13 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
|
5
5
|
function _setFunctionName(e, t, n) { "symbol" == typeof t && (t = (t = t.description) ? "[" + t + "]" : ""); try { Object.defineProperty(e, "name", { configurable: !0, value: n ? n + " " + t : t }); } catch (e) {} return e; }
|
|
6
6
|
function _checkInRHS(e) { if (Object(e) !== e) throw TypeError("right-hand side of 'in' should be an object, got " + (null !== e ? typeof e : "null")); return e; }
|
|
7
7
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
8
|
-
import { createRequestAbortContext, raceWithAbort, trackActiveRequestTransaction, untrackActiveRequestTransaction } from '@fluojs/runtime';
|
|
8
|
+
import { createAbortError, createRequestAbortContext, raceWithAbort, trackActiveRequestTransaction, untrackActiveRequestTransaction } from '@fluojs/runtime';
|
|
9
9
|
import { Inject } from '@fluojs/core';
|
|
10
10
|
import { DRIZZLE_DATABASE, DRIZZLE_DISPOSE, DRIZZLE_OPTIONS } from './tokens.js';
|
|
11
11
|
import { createDrizzlePlatformStatusSnapshot } from './status.js';
|
|
12
12
|
const TRANSACTION_NOT_SUPPORTED_ERROR = 'Transaction not supported: Drizzle database does not implement transaction.';
|
|
13
13
|
const NESTED_TRANSACTION_OPTIONS_NOT_SUPPORTED_ERROR = 'Nested Drizzle transaction options are not supported because the active transaction context is reused.';
|
|
14
|
+
const REQUEST_TRANSACTION_UNAVAILABLE_ERROR = 'Drizzle request transactions are not available during shutdown.';
|
|
14
15
|
let _DrizzleDatabase;
|
|
15
16
|
/**
|
|
16
17
|
* Transaction-aware Drizzle wrapper that integrates request scoping and shutdown handling with the Fluo runtime.
|
|
@@ -45,7 +46,7 @@ class DrizzleDatabase {
|
|
|
45
46
|
* @returns The transaction-scoped database inside an active boundary, or the root database outside one.
|
|
46
47
|
*/
|
|
47
48
|
current() {
|
|
48
|
-
return this.transactions.getStore() ?? this.database;
|
|
49
|
+
return this.transactions.getStore()?.database ?? this.database;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
52
|
/** Aborts active request transactions, waits for settlement, then runs the optional dispose hook. */
|
|
@@ -111,8 +112,8 @@ class DrizzleDatabase {
|
|
|
111
112
|
if (options !== undefined) {
|
|
112
113
|
throw new Error(NESTED_TRANSACTION_OPTIONS_NOT_SUPPORTED_ERROR);
|
|
113
114
|
}
|
|
114
|
-
if (requestScoped
|
|
115
|
-
return
|
|
115
|
+
if (requestScoped) {
|
|
116
|
+
return this.executeNestedRequestTransaction(current, fn, signal);
|
|
116
117
|
}
|
|
117
118
|
return fn();
|
|
118
119
|
}
|
|
@@ -124,30 +125,84 @@ class DrizzleDatabase {
|
|
|
124
125
|
return fn();
|
|
125
126
|
}
|
|
126
127
|
if (!requestScoped) {
|
|
127
|
-
|
|
128
|
+
const deferredRequestTransactionHandles = new Set();
|
|
129
|
+
try {
|
|
130
|
+
return await transactionRunner(transactionDatabase => this.transactions.run({
|
|
131
|
+
database: transactionDatabase,
|
|
132
|
+
deferredRequestTransactionHandles
|
|
133
|
+
}, fn), options);
|
|
134
|
+
} finally {
|
|
135
|
+
for (const handle of deferredRequestTransactionHandles) {
|
|
136
|
+
this.untrackActiveRequestTransaction(handle);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
128
139
|
}
|
|
129
140
|
return this.executeRequestTransaction(transactionRunner, fn, options, signal);
|
|
130
141
|
}
|
|
131
142
|
async executeRequestTransaction(transactionRunner, fn, options, signal) {
|
|
143
|
+
this.assertRequestTransactionsAvailable();
|
|
132
144
|
const abortContext = createRequestAbortContext(signal);
|
|
133
145
|
const active = this.trackActiveRequestTransaction(abortContext.controller);
|
|
134
146
|
try {
|
|
135
|
-
|
|
147
|
+
const result = await transactionRunner(transactionDatabase => this.transactions.run({
|
|
148
|
+
database: transactionDatabase,
|
|
149
|
+
requestAbortSignal: abortContext.signal
|
|
150
|
+
}, () => raceWithAbort(fn, abortContext.signal)), options);
|
|
151
|
+
this.throwIfRequestAborted(abortContext.signal);
|
|
152
|
+
return result;
|
|
136
153
|
} finally {
|
|
137
154
|
abortContext.cleanup();
|
|
138
155
|
this.untrackActiveRequestTransaction(active);
|
|
139
156
|
}
|
|
140
157
|
}
|
|
158
|
+
async executeNestedRequestTransaction(current, fn, signal) {
|
|
159
|
+
if (current.requestAbortSignal) {
|
|
160
|
+
if (signal) {
|
|
161
|
+
return raceWithAbort(fn, signal);
|
|
162
|
+
}
|
|
163
|
+
return fn();
|
|
164
|
+
}
|
|
165
|
+
this.assertRequestTransactionsAvailable();
|
|
166
|
+
const abortContext = createRequestAbortContext(signal);
|
|
167
|
+
const active = this.trackActiveRequestTransaction(abortContext.controller);
|
|
168
|
+
current.deferredRequestTransactionHandles?.add(active);
|
|
169
|
+
try {
|
|
170
|
+
const result = await this.transactions.run({
|
|
171
|
+
database: current.database,
|
|
172
|
+
requestAbortSignal: abortContext.signal
|
|
173
|
+
}, () => raceWithAbort(fn, abortContext.signal));
|
|
174
|
+
this.throwIfRequestAborted(abortContext.signal);
|
|
175
|
+
return result;
|
|
176
|
+
} finally {
|
|
177
|
+
abortContext.cleanup();
|
|
178
|
+
if (!current.deferredRequestTransactionHandles) {
|
|
179
|
+
this.untrackActiveRequestTransaction(active);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
141
183
|
async executeRequestFallback(fn, signal) {
|
|
184
|
+
this.assertRequestTransactionsAvailable();
|
|
142
185
|
const abortContext = createRequestAbortContext(signal);
|
|
143
186
|
const active = this.trackActiveRequestTransaction(abortContext.controller);
|
|
144
187
|
try {
|
|
145
|
-
|
|
188
|
+
const result = await raceWithAbort(fn, abortContext.signal);
|
|
189
|
+
this.throwIfRequestAborted(abortContext.signal);
|
|
190
|
+
return result;
|
|
146
191
|
} finally {
|
|
147
192
|
abortContext.cleanup();
|
|
148
193
|
this.untrackActiveRequestTransaction(active);
|
|
149
194
|
}
|
|
150
195
|
}
|
|
196
|
+
assertRequestTransactionsAvailable() {
|
|
197
|
+
if (this.lifecycleState !== 'ready') {
|
|
198
|
+
throw new Error(REQUEST_TRANSACTION_UNAVAILABLE_ERROR);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
throwIfRequestAborted(signal) {
|
|
202
|
+
if (signal.aborted) {
|
|
203
|
+
throw createAbortError(signal.reason);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
151
206
|
trackActiveRequestTransaction(controller) {
|
|
152
207
|
return trackActiveRequestTransaction(this.activeRequestTransactions, controller);
|
|
153
208
|
}
|
package/dist/module.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AsyncModuleOptions } from '@fluojs/core';
|
|
2
2
|
import { type ModuleType } from '@fluojs/runtime';
|
|
3
3
|
import type { DrizzleDatabaseLike, DrizzleModuleOptions } from './types.js';
|
|
4
|
+
type DrizzleAsyncModuleOptions<TDatabase extends DrizzleDatabaseLike<TTransactionDatabase, TTransactionOptions>, TTransactionDatabase, TTransactionOptions> = AsyncModuleOptions<Omit<DrizzleModuleOptions<TDatabase, TTransactionDatabase, TTransactionOptions>, 'global'>> & Pick<DrizzleModuleOptions<TDatabase, TTransactionDatabase, TTransactionOptions>, 'global'>;
|
|
4
5
|
/**
|
|
5
6
|
* Module entrypoint for wiring a Drizzle database into the Fluo runtime lifecycle.
|
|
6
7
|
*/
|
|
@@ -8,6 +9,7 @@ export declare class DrizzleModule {
|
|
|
8
9
|
/** Creates a module definition from static Drizzle options. */
|
|
9
10
|
static forRoot<TDatabase extends DrizzleDatabaseLike<TTransactionDatabase, TTransactionOptions>, TTransactionDatabase = TDatabase, TTransactionOptions = unknown>(options: DrizzleModuleOptions<TDatabase, TTransactionDatabase, TTransactionOptions>): ModuleType;
|
|
10
11
|
/** Creates a module definition from DI-aware async Drizzle options. */
|
|
11
|
-
static forRootAsync<TDatabase extends DrizzleDatabaseLike<TTransactionDatabase, TTransactionOptions>, TTransactionDatabase = TDatabase, TTransactionOptions = unknown>(options:
|
|
12
|
+
static forRootAsync<TDatabase extends DrizzleDatabaseLike<TTransactionDatabase, TTransactionOptions>, TTransactionDatabase = TDatabase, TTransactionOptions = unknown>(options: DrizzleAsyncModuleOptions<TDatabase, TTransactionDatabase, TTransactionOptions>): ModuleType;
|
|
12
13
|
}
|
|
14
|
+
export {};
|
|
13
15
|
//# 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;AAEvD,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,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;AAEvD,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAKhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAc5E,KAAK,yBAAyB,CAC5B,SAAS,SAAS,mBAAmB,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,EAChF,oBAAoB,EACpB,mBAAmB,IACjB,kBAAkB,CAAC,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,oBAAoB,EAAE,mBAAmB,CAAC,EAAE,QAAQ,CAAC,CAAC,GAChH,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,oBAAoB,EAAE,mBAAmB,CAAC,EAAE,QAAQ,CAAC,CAAC;AAoI7F;;GAEG;AACH,qBAAa,aAAa;IACxB,+DAA+D;IAC/D,MAAM,CAAC,OAAO,CACZ,SAAS,SAAS,mBAAmB,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,EAChF,oBAAoB,GAAG,SAAS,EAChC,mBAAmB,GAAG,OAAO,EAC7B,OAAO,EAAE,oBAAoB,CAAC,SAAS,EAAE,oBAAoB,EAAE,mBAAmB,CAAC,GAAG,UAAU;IAIlG,uEAAuE;IACvE,MAAM,CAAC,YAAY,CACjB,SAAS,SAAS,mBAAmB,CAAC,oBAAoB,EAAE,mBAAmB,CAAC,EAChF,oBAAoB,GAAG,SAAS,EAChC,mBAAmB,GAAG,OAAO,EAC7B,OAAO,EAAE,yBAAyB,CAAC,SAAS,EAAE,oBAAoB,EAAE,mBAAmB,CAAC,GAAG,UAAU;CAGxG"}
|
package/dist/module.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { defineModule } from '@fluojs/runtime';
|
|
2
2
|
import { DrizzleDatabase } from './database.js';
|
|
3
|
-
import { DRIZZLE_DATABASE, DRIZZLE_DISPOSE, DRIZZLE_OPTIONS } from './tokens.js';
|
|
3
|
+
import { DRIZZLE_DATABASE, DRIZZLE_DISPOSE, DRIZZLE_HANDLE_PROVIDER, DRIZZLE_OPTIONS } from './tokens.js';
|
|
4
4
|
import { DrizzleTransactionInterceptor } from './transaction.js';
|
|
5
5
|
const DRIZZLE_NORMALIZED_OPTIONS = Symbol('fluo.drizzle.normalized-options');
|
|
6
|
-
const DRIZZLE_MODULE_EXPORTS = [DrizzleDatabase, DrizzleTransactionInterceptor];
|
|
6
|
+
const DRIZZLE_MODULE_EXPORTS = [DrizzleDatabase, DrizzleTransactionInterceptor, DRIZZLE_HANDLE_PROVIDER];
|
|
7
7
|
function normalizeDrizzleModuleOptions(options) {
|
|
8
8
|
return {
|
|
9
9
|
...options,
|
|
@@ -28,7 +28,10 @@ function createDrizzleRuntimeProviders(normalizedOptionsProvider) {
|
|
|
28
28
|
inject: [DRIZZLE_NORMALIZED_OPTIONS],
|
|
29
29
|
provide: DRIZZLE_OPTIONS,
|
|
30
30
|
useFactory: options => createRuntimeOptionsProviderValue(options.strictTransactions)
|
|
31
|
-
}, DrizzleDatabase,
|
|
31
|
+
}, DrizzleDatabase, {
|
|
32
|
+
provide: DRIZZLE_HANDLE_PROVIDER,
|
|
33
|
+
useExisting: DrizzleDatabase
|
|
34
|
+
}, DrizzleTransactionInterceptor];
|
|
32
35
|
}
|
|
33
36
|
function createMemoizedDrizzleOptionsResolver(options) {
|
|
34
37
|
let cachedResult;
|
|
@@ -56,6 +59,7 @@ function buildDrizzleModule(options) {
|
|
|
56
59
|
class DrizzleRootModuleDefinition {}
|
|
57
60
|
return defineModule(DrizzleRootModuleDefinition, {
|
|
58
61
|
exports: DRIZZLE_MODULE_EXPORTS,
|
|
62
|
+
global: options.global ?? false,
|
|
59
63
|
providers: createDrizzleRuntimeProviders({
|
|
60
64
|
provide: DRIZZLE_NORMALIZED_OPTIONS,
|
|
61
65
|
useValue: normalizeDrizzleModuleOptions(options)
|
|
@@ -66,6 +70,7 @@ function buildDrizzleModuleAsync(options) {
|
|
|
66
70
|
class DrizzleAsyncModuleDefinition {}
|
|
67
71
|
return defineModule(DrizzleAsyncModuleDefinition, {
|
|
68
72
|
exports: DRIZZLE_MODULE_EXPORTS,
|
|
73
|
+
global: options.global ?? false,
|
|
69
74
|
providers: createDrizzleProvidersAsync(options)
|
|
70
75
|
});
|
|
71
76
|
}
|
package/dist/tokens.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Dependency-injection token for the raw Drizzle database handle. */
|
|
2
2
|
export declare const DRIZZLE_DATABASE: unique symbol;
|
|
3
|
+
/** Dependency-injection token for the lifecycle-aware Drizzle database wrapper. */
|
|
4
|
+
export declare const DRIZZLE_HANDLE_PROVIDER: unique symbol;
|
|
3
5
|
/** Dependency-injection token for the optional Drizzle shutdown dispose hook. */
|
|
4
6
|
export declare const DRIZZLE_DISPOSE: unique symbol;
|
|
5
7
|
/** Dependency-injection token for normalized Drizzle runtime options. */
|
package/dist/tokens.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,eAAsC,CAAC;AACpE,iFAAiF;AACjF,eAAO,MAAM,eAAe,eAAqC,CAAC;AAClE,yEAAyE;AACzE,eAAO,MAAM,eAAe,eAAqC,CAAC"}
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,eAAO,MAAM,gBAAgB,eAAsC,CAAC;AACpE,mFAAmF;AACnF,eAAO,MAAM,uBAAuB,eAA6C,CAAC;AAClF,iFAAiF;AACjF,eAAO,MAAM,eAAe,eAAqC,CAAC;AAClE,yEAAyE;AACzE,eAAO,MAAM,eAAe,eAAqC,CAAC"}
|
package/dist/tokens.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Dependency-injection token for the raw Drizzle database handle. */
|
|
2
2
|
export const DRIZZLE_DATABASE = Symbol.for('fluo.drizzle.database');
|
|
3
|
+
/** Dependency-injection token for the lifecycle-aware Drizzle database wrapper. */
|
|
4
|
+
export const DRIZZLE_HANDLE_PROVIDER = Symbol.for('fluo.drizzle.handle-provider');
|
|
3
5
|
/** Dependency-injection token for the optional Drizzle shutdown dispose hook. */
|
|
4
6
|
export const DRIZZLE_DISPOSE = Symbol.for('fluo.drizzle.dispose');
|
|
5
7
|
/** Dependency-injection token for normalized Drizzle runtime options. */
|
package/dist/types.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface DrizzleModuleOptions<TDatabase extends DrizzleDatabaseLike<TTra
|
|
|
22
22
|
database: TDatabase;
|
|
23
23
|
/** Optional shutdown hook used to close pools or driver resources during application shutdown. */
|
|
24
24
|
dispose?: (database: TDatabase) => MaybePromise<void>;
|
|
25
|
+
/** Whether Drizzle providers should be visible globally. Defaults to `false`. */
|
|
26
|
+
global?: boolean;
|
|
25
27
|
/**
|
|
26
28
|
* Throws when transaction helpers are used against a database that does not expose `transaction(...)`.
|
|
27
29
|
*
|
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,KAAK,0BAA0B,CAAC,oBAAoB,EAAE,OAAO,IAAI,CAAC,QAAQ,EAAE,oBAAoB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtH,KAAK,wBAAwB,CAAC,oBAAoB,EAAE,mBAAmB,IAAI,CAAC,CAAC,EAC3E,QAAQ,EAAE,0BAA0B,CAAC,oBAAoB,EAAE,CAAC,CAAC,EAC7D,OAAO,CAAC,EAAE,mBAAmB,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AE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7G;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACjF"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"transaction",
|
|
10
10
|
"als"
|
|
11
11
|
],
|
|
12
|
-
"version": "1.0.0-beta.
|
|
12
|
+
"version": "1.0.0-beta.4",
|
|
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/core": "^1.0.0-beta.
|
|
40
|
-
"@fluojs/http": "^1.0.0-beta.
|
|
41
|
-
"@fluojs/di": "^1.0.0-beta.
|
|
42
|
-
"@fluojs/runtime": "^1.0.0-beta.
|
|
39
|
+
"@fluojs/core": "^1.0.0-beta.5",
|
|
40
|
+
"@fluojs/http": "^1.0.0-beta.10",
|
|
41
|
+
"@fluojs/di": "^1.0.0-beta.7",
|
|
42
|
+
"@fluojs/runtime": "^1.0.0-beta.12"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"drizzle-orm": ">=0.30.0"
|