@fluojs/prisma 1.0.0-beta.4 → 1.0.0-beta.6
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 +23 -2
- package/README.md +25 -2
- package/dist/service.d.ts +4 -0
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +72 -5
- package/dist/status.js +2 -2
- package/dist/tokens.d.ts +5 -2
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +5 -2
- package/package.json +6 -6
package/README.ko.md
CHANGED
|
@@ -14,6 +14,7 @@ fluo 애플리케이션을 위한 Prisma 라이프사이클 및 ALS 기반 트
|
|
|
14
14
|
- [여러 클라이언트를 위한 이름 있는 등록](#여러-클라이언트를-위한-이름-있는-등록)
|
|
15
15
|
- [수동 트랜잭션](#수동-트랜잭션)
|
|
16
16
|
- [자동 요청 트랜잭션](#자동-요청-트랜잭션)
|
|
17
|
+
- [종료와 status 계약](#종료와-status-계약)
|
|
17
18
|
- [비동기 설정과 격리](#비동기-설정과-격리)
|
|
18
19
|
- [수동 모듈 조합](#수동-모듈-조합)
|
|
19
20
|
- [공개 API 개요](#공개-api-개요)
|
|
@@ -114,6 +115,8 @@ await this.prisma.transaction(async () => {
|
|
|
114
115
|
});
|
|
115
116
|
```
|
|
116
117
|
|
|
118
|
+
이미 활성 트랜잭션 컨텍스트가 있는 상태에서 `transaction()`을 호출하면 `PrismaService`는 중첩 Prisma 트랜잭션을 새로 열지 않고 활성 트랜잭션 클라이언트를 재사용합니다. 중첩 호출에는 isolation level 같은 트랜잭션 옵션을 전달하면 안 됩니다. 활성 컨텍스트에서 옵션을 제공하면 ambient transaction을 재사용하는 동안 호출자의 의도를 조용히 버리지 않도록 예외로 거부합니다.
|
|
119
|
+
|
|
117
120
|
### 자동 요청 트랜잭션
|
|
118
121
|
|
|
119
122
|
컨트롤러나 메서드에 `PrismaTransactionInterceptor`를 적용하면 전체 요청을 자동으로 트랜잭션으로 감쌉니다.
|
|
@@ -133,6 +136,18 @@ class UserController {
|
|
|
133
136
|
|
|
134
137
|
`PrismaTransactionInterceptor`는 기본 이름 없는 `PrismaService`를 대상으로 합니다. 이름 있는 다중 클라이언트 등록에서는 해당 이름의 `PrismaService`를 주입한 뒤 필요한 위치에서 명시적으로 `transaction()` / `requestTransaction()` 경계를 여세요.
|
|
135
138
|
|
|
139
|
+
### 종료와 status 계약
|
|
140
|
+
|
|
141
|
+
`PrismaService.requestTransaction(...)`은 정상 serving 전과 중에는 사용할 수 있지만, 애플리케이션 종료가 시작된 뒤에는 새 요청 범위 트랜잭션을 거부합니다. 종료 중에는 열린 요청 트랜잭션을 abort하고, 바깥 트랜잭션 경계가 settle될 때까지 추적한 뒤, 모두 drain한 다음 `$disconnect()`를 실행합니다. 기존 수동 `transaction(...)` 경계 안에서 열린 중첩 `requestTransaction(...)` 호출도 여기에 포함됩니다. 이 호출은 ambient Prisma transaction client를 재사용하고, 바깥 경계가 끝날 때까지 `details.activeRequestTransactions`에 남으며, 두 번째 Prisma 트랜잭션을 열지 않습니다.
|
|
142
|
+
|
|
143
|
+
`createPrismaPlatformStatusSnapshot(...)`와 `PrismaService.createPlatformStatusSnapshot()`은 같은 라이프사이클 계약을 진단 surface에 노출합니다.
|
|
144
|
+
|
|
145
|
+
- `readiness.status`는 Prisma가 종료 중이거나 stopped 상태일 때, 그리고 `strictTransactions`가 켜져 있는데 `$transaction(...)`을 지원하지 않을 때 `not-ready`입니다.
|
|
146
|
+
- `health.status`는 종료 중 요청 트랜잭션을 drain하는 동안 `degraded`, disconnect 이후 `unhealthy`입니다.
|
|
147
|
+
- `details.activeRequestTransactions`, `details.lifecycleState`, `details.strictTransactions`, `details.supportsTransaction`, `details.transactionAbortSignalSupport`는 현재 요청 트랜잭션과 트랜잭션 capability 상태를 설명합니다.
|
|
148
|
+
- `details.transactionContext: 'als'`는 요청 및 서비스 트랜잭션 경계가 사용하는 async-local transaction context를 식별합니다.
|
|
149
|
+
- `ownership.externallyManaged: false`와 `ownership.ownsResources: true`는 패키지가 fluo 애플리케이션 라이프사이클 안에서 등록된 클라이언트의 `$connect()` / `$disconnect()` lifecycle hook을 소유한다는 의미입니다.
|
|
150
|
+
|
|
136
151
|
### 비동기 설정과 격리
|
|
137
152
|
|
|
138
153
|
주입된 설정이나 다른 비동기 소스에서 Prisma 클라이언트를 만들어야 할 때는 `PrismaModule.forRootAsync(...)`를 사용하세요. 비동기 factory는 애플리케이션 컨테이너마다 한 번 resolve되며, 테스트나 여러 앱을 띄우는 프로세스에서 같은 모듈 정의를 재사용하더라도 별도 bootstrap 사이에서 공유되지 않습니다.
|
|
@@ -188,14 +203,19 @@ defineModule(ManualPrismaModule, {
|
|
|
188
203
|
- `current(): TClient | PrismaTransactionClient<TClient>`
|
|
189
204
|
- 현재 컨텍스트에 맞는 트랜잭션 클라이언트 또는 루트 클라이언트를 반환합니다.
|
|
190
205
|
- `transaction(fn, options?): Promise<T>`
|
|
191
|
-
- 대화형 트랜잭션 내에서 함수를 실행합니다.
|
|
206
|
+
- 대화형 트랜잭션 내에서 함수를 실행합니다. 이미 트랜잭션 컨텍스트가 활성화되어 있으면 callback은 그 컨텍스트를 재사용하며, 새 Prisma 트랜잭션 경계가 열리지 않기 때문에 중첩 트랜잭션 옵션은 거부됩니다.
|
|
192
207
|
- `requestTransaction(fn, signal?, options?): Promise<T>`
|
|
193
|
-
- HTTP 요청 라이프사이클에 특화된 트랜잭션 경계를 실행합니다. Abort를 인식하고, shutdown 중에는 disconnect 전에 열린 요청 트랜잭션을 drain하며, Prisma client가 `signal` 옵션을 거부하면 해당 옵션 없이 재시도합니다.
|
|
208
|
+
- HTTP 요청 라이프사이클에 특화된 트랜잭션 경계를 실행합니다. Abort를 인식하고, shutdown 중에는 disconnect 전에 열린 요청 트랜잭션을 drain하며, Prisma client가 `signal` 옵션을 거부하면 해당 옵션 없이 재시도합니다. `transaction()`과 마찬가지로 중첩 호출은 활성 트랜잭션 컨텍스트를 재사용하고, 트랜잭션 설정을 조용히 무시하지 않도록 중첩 옵션을 거부합니다.
|
|
194
209
|
|
|
195
210
|
### `PRISMA_CLIENT` (Token)
|
|
196
211
|
|
|
197
212
|
원시 `PrismaClient` 인스턴스를 위한 주입 토큰입니다.
|
|
198
213
|
|
|
214
|
+
### `PRISMA_OPTIONS` (Token)
|
|
215
|
+
|
|
216
|
+
`PrismaService`가 소비하는 공개 런타임 옵션을 위한 주입 토큰이며, 현재 형태는 `{ strictTransactions: boolean }`입니다.
|
|
217
|
+
이는 등록 identity, client ownership, visibility metadata까지 담는 패키지 내부 정규화 모듈 옵션 토큰보다 의도적으로 좁은 표면이며, 그 내부 토큰은 공개 API가 아닙니다.
|
|
218
|
+
|
|
199
219
|
### 플랫폼 status
|
|
200
220
|
|
|
201
221
|
- `createPrismaPlatformStatusSnapshot(input)`: Prisma readiness, health, ownership, ALS 기반 transaction context를 보고하는 persistence platform status snapshot을 생성합니다.
|
|
@@ -207,6 +227,7 @@ defineModule(ManualPrismaModule, {
|
|
|
207
227
|
- `getPrismaServiceToken(name?)`
|
|
208
228
|
|
|
209
229
|
이 헬퍼들은 `name`이 없으면 기본 이름 없는 토큰을 반환하고, `name`이 있으면 해당 등록 전용 토큰을 반환합니다.
|
|
230
|
+
이 헬퍼가 이름 있는 등록을 대상으로 삼는 공개 방법이며, 정규화 모듈 옵션 토큰 같은 내부 구현 토큰은 의도적으로 export하지 않습니다.
|
|
210
231
|
|
|
211
232
|
### 관련 export 타입
|
|
212
233
|
|
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Prisma lifecycle and ALS-backed transaction context for fluo applications. Conne
|
|
|
14
14
|
- [Named Registrations for Multiple Clients](#named-registrations-for-multiple-clients)
|
|
15
15
|
- [Manual Transactions](#manual-transactions)
|
|
16
16
|
- [Automatic Request Transactions](#automatic-request-transactions)
|
|
17
|
+
- [Shutdown and Status Contracts](#shutdown-and-status-contracts)
|
|
17
18
|
- [Async Configuration and Isolation](#async-configuration-and-isolation)
|
|
18
19
|
- [Manual Module Composition](#manual-module-composition)
|
|
19
20
|
- [Public API Overview](#public-api-overview)
|
|
@@ -114,6 +115,8 @@ await this.prisma.transaction(async () => {
|
|
|
114
115
|
});
|
|
115
116
|
```
|
|
116
117
|
|
|
118
|
+
When `transaction()` is called while a transaction context is already active, `PrismaService` reuses the active transaction client instead of opening a nested Prisma transaction. Nested calls must not pass transaction options such as isolation levels; providing options in an active context is rejected so the package does not silently drop caller intent while reusing the ambient transaction.
|
|
119
|
+
|
|
117
120
|
### Automatic Request Transactions
|
|
118
121
|
|
|
119
122
|
Apply the `PrismaTransactionInterceptor` to a controller or method to wrap the entire request in a transaction automatically.
|
|
@@ -133,6 +136,18 @@ class UserController {
|
|
|
133
136
|
|
|
134
137
|
`PrismaTransactionInterceptor` targets the default unnamed `PrismaService`. For named multi-client registrations, inject the corresponding named `PrismaService` and open explicit `transaction()` / `requestTransaction()` boundaries where needed.
|
|
135
138
|
|
|
139
|
+
### Shutdown and Status Contracts
|
|
140
|
+
|
|
141
|
+
`PrismaService.requestTransaction(...)` is available before and during normal serving, but new request-scoped transactions are rejected once application shutdown has started. During shutdown, open request transactions are aborted, tracked until their outer transaction boundary has settled, and drained before `$disconnect()` runs. This includes nested `requestTransaction(...)` calls opened inside an existing manual `transaction(...)` boundary: they reuse the ambient Prisma transaction client, stay visible in `details.activeRequestTransactions` until the outer boundary finishes, and do not open a second Prisma transaction.
|
|
142
|
+
|
|
143
|
+
`createPrismaPlatformStatusSnapshot(...)` and `PrismaService.createPlatformStatusSnapshot()` expose the same lifecycle contract to diagnostics surfaces:
|
|
144
|
+
|
|
145
|
+
- `readiness.status` is `not-ready` while Prisma is shutting down or stopped, and when `strictTransactions` is enabled without `$transaction(...)` support.
|
|
146
|
+
- `health.status` is `degraded` while request transactions are draining during shutdown and `unhealthy` after disconnect.
|
|
147
|
+
- `details.activeRequestTransactions`, `details.lifecycleState`, `details.strictTransactions`, `details.supportsTransaction`, and `details.transactionAbortSignalSupport` describe the current request transaction and transaction-capability state.
|
|
148
|
+
- `details.transactionContext: 'als'` identifies the async-local transaction context used by request and service transaction boundaries.
|
|
149
|
+
- `ownership.externallyManaged: false` and `ownership.ownsResources: true` mean the package owns the registered client's `$connect()` / `$disconnect()` lifecycle hooks inside the fluo application lifecycle.
|
|
150
|
+
|
|
136
151
|
### Async Configuration and Isolation
|
|
137
152
|
|
|
138
153
|
Use `PrismaModule.forRootAsync(...)` when the Prisma client must be created from injected configuration or another async source. The async factory is resolved once per application container and is not shared across separate bootstraps, even when the same module definition is reused in tests or multi-app processes.
|
|
@@ -188,14 +203,20 @@ defineModule(ManualPrismaModule, {
|
|
|
188
203
|
- `current(): TClient | PrismaTransactionClient<TClient>`
|
|
189
204
|
- Returns the ambient transaction client or the root client.
|
|
190
205
|
- `transaction(fn, options?): Promise<T>`
|
|
191
|
-
- Runs a function within an interactive transaction.
|
|
206
|
+
- Runs a function within an interactive transaction. If a transaction context is already active, the callback reuses that context; nested transaction options are rejected because no new Prisma transaction boundary is opened.
|
|
192
207
|
- `requestTransaction(fn, signal?, options?): Promise<T>`
|
|
193
|
-
- Specialized transaction boundary for HTTP request lifecycles. It is abort-aware, drains during shutdown before disconnect, and retries without `signal` when a Prisma client rejects that option.
|
|
208
|
+
- Specialized transaction boundary for HTTP request lifecycles. It is abort-aware, drains during shutdown before disconnect, and retries without `signal` when a Prisma client rejects that option. Like `transaction()`, nested calls reuse the active transaction context and reject nested options to avoid silently ignoring transaction settings.
|
|
194
209
|
|
|
195
210
|
### `PRISMA_CLIENT` (Token)
|
|
196
211
|
|
|
197
212
|
Injectable token for the raw `PrismaClient` instance.
|
|
198
213
|
|
|
214
|
+
### `PRISMA_OPTIONS` (Token)
|
|
215
|
+
|
|
216
|
+
Injectable token for the public runtime options consumed by `PrismaService`, currently `{ strictTransactions: boolean }`.
|
|
217
|
+
This is intentionally narrower than the package's internal normalized module-options token, which also carries registration
|
|
218
|
+
identity, client ownership, and visibility metadata and is not part of the public API.
|
|
219
|
+
|
|
199
220
|
### Platform status
|
|
200
221
|
|
|
201
222
|
- `createPrismaPlatformStatusSnapshot(input)`: Creates a persistence platform status snapshot that reports Prisma readiness, health, ownership, and ALS-backed transaction context.
|
|
@@ -207,6 +228,8 @@ Injectable token for the raw `PrismaClient` instance.
|
|
|
207
228
|
- `getPrismaServiceToken(name?)`
|
|
208
229
|
|
|
209
230
|
These helpers return the default unnamed token when `name` is omitted and a registration-specific token when `name` is provided.
|
|
231
|
+
They are the public way to target named registrations; internal implementation tokens such as the normalized module-options
|
|
232
|
+
token are deliberately not exported.
|
|
210
233
|
|
|
211
234
|
### Related exported types
|
|
212
235
|
|
package/dist/service.d.ts
CHANGED
|
@@ -77,6 +77,10 @@ export declare class PrismaService<TClient extends PrismaClientLike<TTransaction
|
|
|
77
77
|
* error type/message depends on the runtime abort implementation.
|
|
78
78
|
*/
|
|
79
79
|
requestTransaction<T>(fn: () => Promise<T>, signal?: AbortSignal, options?: TTransactionOptions): Promise<T>;
|
|
80
|
+
private runWithRequestTransactionClient;
|
|
81
|
+
private runNestedRequestTransaction;
|
|
82
|
+
private assertRequestTransactionsAvailable;
|
|
83
|
+
private throwIfRequestAborted;
|
|
80
84
|
private runRequestTransactionWithAbortSignal;
|
|
81
85
|
private canAttemptTransactionAbortSignalOption;
|
|
82
86
|
private runTransactionWithAbortSignalFallback;
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAK3E,OAAO,KAAK,EACV,4BAA4B,EAC5B,6BAA6B,EAC7B,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAMpB,UAAU,oBAAoB;IAC5B,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAoBD;;;;;;GAMG;AACH,qBACa,aAAa,CACxB,OAAO,SAAS,gBAAgB,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,EACzE,kBAAkB,GAAG,4BAA4B,CAAC,OAAO,CAAC,EAC1D,mBAAmB,GAAG,6BAA6B,CAAC,OAAO,CAAC,CAE5D,YAAW,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,CAAC,EAAE,YAAY,EAAE,qBAAqB;IAQpH,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAPjC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmE;IAChG,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAuC;IACjF,OAAO,CAAC,6BAA6B,CAA4C;IACjF,OAAO,CAAC,cAAc,CAAgE;gBAGnE,MAAM,EAAE,OAAO,EACf,cAAc,GAAE,oBAAoD;IAGvF;;;;;;;;;OASG;IACH,OAAO,IAAI,OAAO,GAAG,kBAAkB;YAIzB,wBAAwB;IAuChC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ7B,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB5C;;;;OAIG;IACH,4BAA4B;IAY5B;;;;;;;;;;;;;;;;;OAiBG;IACG,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;IAQrF;;;;;;;;;;;;;;;;;;OAkBG;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;YAkCpG,+BAA+B;YAuB/B,2BAA2B;IAqCzC,OAAO,CAAC,kCAAkC;IAM1C,OAAO,CAAC,qBAAqB;IAM7B,OAAO,CAAC,oCAAoC;IAY5C,OAAO,CAAC,sCAAsC;YAYhC,qCAAqC;IAyBnD,OAAO,CAAC,6BAA6B;IAUrC,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,0BAA0B;IAWlC,OAAO,CAAC,6BAA6B;IAIrC,OAAO,CAAC,+BAA+B;CAGxC"}
|
package/dist/service.js
CHANGED
|
@@ -5,11 +5,12 @@ 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 { createPrismaPlatformStatusSnapshot } from './status.js';
|
|
11
11
|
import { PRISMA_CLIENT, PRISMA_OPTIONS } from './tokens.js';
|
|
12
12
|
const NESTED_TRANSACTION_OPTIONS_NOT_SUPPORTED_ERROR = 'Nested Prisma transaction options are not supported because the active transaction context is reused.';
|
|
13
|
+
const REQUEST_TRANSACTION_UNAVAILABLE_ERROR = 'Prisma request transactions are not available during shutdown.';
|
|
13
14
|
let _PrismaService;
|
|
14
15
|
/**
|
|
15
16
|
* Prisma runtime facade that owns lifecycle hooks and transaction context access.
|
|
@@ -44,7 +45,7 @@ class PrismaService {
|
|
|
44
45
|
* @returns The request/transaction-scoped client when a transaction is active; otherwise the root client.
|
|
45
46
|
*/
|
|
46
47
|
current() {
|
|
47
|
-
return this.transactions.getStore() ?? this.client;
|
|
48
|
+
return this.transactions.getStore()?.client ?? this.client;
|
|
48
49
|
}
|
|
49
50
|
async runWithTransactionClient(fn, run, options) {
|
|
50
51
|
if (this.transactions.getStore()) {
|
|
@@ -59,7 +60,17 @@ class PrismaService {
|
|
|
59
60
|
}
|
|
60
61
|
return fn();
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
+
const deferredRequestTransactionHandles = new Set();
|
|
64
|
+
try {
|
|
65
|
+
return await run(transactionClient => this.transactions.run({
|
|
66
|
+
client: transactionClient,
|
|
67
|
+
deferredRequestTransactionHandles
|
|
68
|
+
}, fn), options);
|
|
69
|
+
} finally {
|
|
70
|
+
for (const handle of deferredRequestTransactionHandles) {
|
|
71
|
+
this.untrackActiveRequestTransaction(handle);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
63
74
|
}
|
|
64
75
|
async onModuleInit() {
|
|
65
76
|
if (typeof this.client.$connect === 'function') {
|
|
@@ -138,16 +149,72 @@ class PrismaService {
|
|
|
138
149
|
* error type/message depends on the runtime abort implementation.
|
|
139
150
|
*/
|
|
140
151
|
async requestTransaction(fn, signal, options) {
|
|
152
|
+
const current = this.transactions.getStore();
|
|
153
|
+
if (current) {
|
|
154
|
+
if (options !== undefined) {
|
|
155
|
+
throw new Error(NESTED_TRANSACTION_OPTIONS_NOT_SUPPORTED_ERROR);
|
|
156
|
+
}
|
|
157
|
+
return this.runNestedRequestTransaction(current, fn, signal);
|
|
158
|
+
}
|
|
159
|
+
this.assertRequestTransactionsAvailable();
|
|
141
160
|
const abortContext = createRequestAbortContext(signal);
|
|
142
161
|
const active = this.trackActiveRequestTransaction(abortContext.controller);
|
|
143
|
-
const transactionPromise = this.runWithTransactionClient(() => raceWithAbort(fn, abortContext.signal), (callback, transactionOptions) => this.runRequestTransactionWithAbortSignal(callback, abortContext.signal, transactionOptions), options);
|
|
144
162
|
try {
|
|
145
|
-
|
|
163
|
+
const result = await this.runWithRequestTransactionClient(() => raceWithAbort(fn, abortContext.signal), (callback, transactionOptions) => this.runRequestTransactionWithAbortSignal(callback, abortContext.signal, transactionOptions), options, abortContext.signal);
|
|
164
|
+
this.throwIfRequestAborted(abortContext.signal);
|
|
165
|
+
return result;
|
|
146
166
|
} finally {
|
|
147
167
|
abortContext.cleanup();
|
|
148
168
|
this.untrackActiveRequestTransaction(active);
|
|
149
169
|
}
|
|
150
170
|
}
|
|
171
|
+
async runWithRequestTransactionClient(fn, run, options, signal) {
|
|
172
|
+
if (typeof this.client.$transaction !== 'function') {
|
|
173
|
+
if (this.serviceOptions.strictTransactions) {
|
|
174
|
+
throw new Error('Transaction not supported: Prisma client does not implement $transaction.');
|
|
175
|
+
}
|
|
176
|
+
return fn();
|
|
177
|
+
}
|
|
178
|
+
return run(transactionClient => this.transactions.run({
|
|
179
|
+
client: transactionClient,
|
|
180
|
+
requestAbortSignal: signal
|
|
181
|
+
}, fn), options);
|
|
182
|
+
}
|
|
183
|
+
async runNestedRequestTransaction(current, fn, signal) {
|
|
184
|
+
if (current.requestAbortSignal) {
|
|
185
|
+
if (signal) {
|
|
186
|
+
return raceWithAbort(fn, signal);
|
|
187
|
+
}
|
|
188
|
+
return fn();
|
|
189
|
+
}
|
|
190
|
+
this.assertRequestTransactionsAvailable();
|
|
191
|
+
const abortContext = createRequestAbortContext(signal);
|
|
192
|
+
const active = this.trackActiveRequestTransaction(abortContext.controller);
|
|
193
|
+
current.deferredRequestTransactionHandles?.add(active);
|
|
194
|
+
try {
|
|
195
|
+
const result = await this.transactions.run({
|
|
196
|
+
client: current.client,
|
|
197
|
+
requestAbortSignal: abortContext.signal
|
|
198
|
+
}, () => raceWithAbort(fn, abortContext.signal));
|
|
199
|
+
this.throwIfRequestAborted(abortContext.signal);
|
|
200
|
+
return result;
|
|
201
|
+
} finally {
|
|
202
|
+
abortContext.cleanup();
|
|
203
|
+
if (!current.deferredRequestTransactionHandles) {
|
|
204
|
+
this.untrackActiveRequestTransaction(active);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
assertRequestTransactionsAvailable() {
|
|
209
|
+
if (this.lifecycleState === 'shutting-down' || this.lifecycleState === 'stopped') {
|
|
210
|
+
throw new Error(REQUEST_TRANSACTION_UNAVAILABLE_ERROR);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
throwIfRequestAborted(signal) {
|
|
214
|
+
if (signal.aborted) {
|
|
215
|
+
throw createAbortError(signal.reason);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
151
218
|
runRequestTransactionWithAbortSignal(callback, signal, options) {
|
|
152
219
|
if (!this.canAttemptTransactionAbortSignalOption(options)) {
|
|
153
220
|
return this.client.$transaction(callback, options);
|
package/dist/status.js
CHANGED
|
@@ -63,8 +63,8 @@ export function createPrismaPlatformStatusSnapshot(input) {
|
|
|
63
63
|
},
|
|
64
64
|
health: createHealth(input),
|
|
65
65
|
ownership: {
|
|
66
|
-
externallyManaged:
|
|
67
|
-
ownsResources:
|
|
66
|
+
externallyManaged: false,
|
|
67
|
+
ownsResources: true
|
|
68
68
|
},
|
|
69
69
|
readiness: createReadiness(input)
|
|
70
70
|
};
|
package/dist/tokens.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Token } from '@fluojs/core';
|
|
2
2
|
/** Dependency-injection token for the raw Prisma client handle. */
|
|
3
3
|
export declare const PRISMA_CLIENT: unique symbol;
|
|
4
|
-
/** Dependency-injection token for
|
|
4
|
+
/** Dependency-injection token for public Prisma runtime options, such as strict transaction mode. */
|
|
5
5
|
export declare const PRISMA_OPTIONS: unique symbol;
|
|
6
6
|
/**
|
|
7
7
|
* Returns the DI token for the raw Prisma client bound to a registration name.
|
|
@@ -11,7 +11,10 @@ export declare const PRISMA_OPTIONS: unique symbol;
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function getPrismaClientToken(name?: string): Token;
|
|
13
13
|
/**
|
|
14
|
-
* Returns the DI token for
|
|
14
|
+
* Returns the DI token for the public Prisma runtime options bound to a registration name.
|
|
15
|
+
*
|
|
16
|
+
* This token resolves the `PRISMA_OPTIONS` public surface consumed by `PrismaService`.
|
|
17
|
+
* Normalized module options remain internal implementation details.
|
|
15
18
|
*
|
|
16
19
|
* @param name Optional registration name. Omit it to target the default unnamed Prisma registration.
|
|
17
20
|
* @returns The token that resolves the matching Prisma 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,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,mEAAmE;AACnE,eAAO,MAAM,aAAa,eAAmC,CAAC;AAC9D,
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,mEAAmE;AACnE,eAAO,MAAM,aAAa,eAAmC,CAAC;AAC9D,qGAAqG;AACrG,eAAO,MAAM,cAAc,eAAoC,CAAC;AAgBhE;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAMzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAM1D;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAM1D"}
|
package/dist/tokens.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Dependency-injection token for the raw Prisma client handle. */
|
|
2
2
|
export const PRISMA_CLIENT = Symbol.for('fluo.prisma.client');
|
|
3
|
-
/** Dependency-injection token for
|
|
3
|
+
/** Dependency-injection token for public Prisma runtime options, such as strict transaction mode. */
|
|
4
4
|
export const PRISMA_OPTIONS = Symbol.for('fluo.prisma.options');
|
|
5
5
|
function normalizePrismaRegistrationName(name) {
|
|
6
6
|
if (name === undefined) {
|
|
@@ -25,7 +25,10 @@ export function getPrismaClientToken(name) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Returns the DI token for
|
|
28
|
+
* Returns the DI token for the public Prisma runtime options bound to a registration name.
|
|
29
|
+
*
|
|
30
|
+
* This token resolves the `PRISMA_OPTIONS` public surface consumed by `PrismaService`.
|
|
31
|
+
* Normalized module options remain internal implementation details.
|
|
29
32
|
*
|
|
30
33
|
* @param name Optional registration name. Omit it to target the default unnamed Prisma registration.
|
|
31
34
|
* @returns The token that resolves the matching Prisma runtime options.
|
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.6",
|
|
13
13
|
"private": false,
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@fluojs/core": "^1.0.0-beta.
|
|
40
|
-
"@fluojs/
|
|
41
|
-
"@fluojs/
|
|
42
|
-
"@fluojs/
|
|
43
|
-
"@fluojs/
|
|
39
|
+
"@fluojs/core": "^1.0.0-beta.6",
|
|
40
|
+
"@fluojs/validation": "^1.0.0-beta.4",
|
|
41
|
+
"@fluojs/http": "^1.0.0-beta.11",
|
|
42
|
+
"@fluojs/di": "^1.0.0-beta.8",
|
|
43
|
+
"@fluojs/runtime": "^1.0.0-beta.12"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@prisma/client": ">=5.0.0"
|