@nathapp/nestjs-prisma 3.1.0 → 3.1.2
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +16 -0
- package/CLAUDE.md +111 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/prisma.constants.d.ts +1 -0
- package/dist/prisma.constants.js +5 -1
- package/dist/prisma.constants.js.map +1 -1
- package/dist/prisma.module.d.ts +1 -0
- package/dist/prisma.module.js +60 -10
- package/dist/prisma.module.js.map +1 -1
- package/dist/repository/abstract-prisma.repository.d.ts +51 -0
- package/dist/repository/abstract-prisma.repository.js +69 -0
- package/dist/repository/abstract-prisma.repository.js.map +1 -0
- package/dist/repository/index.d.ts +1 -0
- package/dist/repository/index.js +18 -0
- package/dist/repository/index.js.map +1 -0
- package/lib/index.ts +1 -0
- package/lib/prisma.constants.ts +31 -1
- package/lib/prisma.module.ts +85 -12
- package/lib/repository/abstract-prisma.repository.ts +120 -0
- package/lib/repository/index.ts +1 -0
- package/package.json +2 -2
- package/test/jest-test.json +4 -0
- package/test/multi-db-transaction.spec.ts +75 -0
- package/test/prisma.module.spec.ts +67 -1
- package/test/repository/abstract-prisma.repository.spec.ts +157 -0
- package/test/transparent-transaction.spec.ts +169 -2
- package/.turbo/turbo-test.log +0 -201
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @nathapp/nestjs-prisma
|
|
2
2
|
|
|
3
|
+
## 3.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cb97b64: fix typeorm and transactionManager issue
|
|
8
|
+
- Updated dependencies [cb97b64]
|
|
9
|
+
- @nathapp/nestjs-data@3.0.3
|
|
10
|
+
|
|
11
|
+
## 3.1.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- a448f5b: add irepository and abstract repository
|
|
16
|
+
- Updated dependencies [a448f5b]
|
|
17
|
+
- @nathapp/nestjs-data@3.0.2
|
|
18
|
+
|
|
3
19
|
## 3.1.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/CLAUDE.md
CHANGED
|
@@ -7,11 +7,119 @@ Prisma 6 wrapper with multi-database support.
|
|
|
7
7
|
- Build: `npx tsc`
|
|
8
8
|
|
|
9
9
|
## Architecture
|
|
10
|
-
- `PrismaModule.forRoot({
|
|
11
|
-
- `PrismaModule.forRoot({
|
|
12
|
-
- `PrismaService` wraps `PrismaClient` (composition, not inheritance) for multi-
|
|
10
|
+
- `PrismaModule.forRoot({ client })` — single database (default connection).
|
|
11
|
+
- `PrismaModule.forRoot({ name: 'dbA', client })` — named connection. Repeat the call for each DB.
|
|
12
|
+
- `PrismaService` wraps `PrismaClient` (composition, not inheritance) for multi-DB flexibility.
|
|
13
13
|
- Pagination uses `Page<T>` from `@nathapp/nestjs-common`.
|
|
14
14
|
|
|
15
|
+
## Portable Repository
|
|
16
|
+
|
|
17
|
+
`AbstractPrismaRepository<TDomain, TModel, TId>` implements
|
|
18
|
+
`IRepository<TDomain, TId>` from `@nathapp/nestjs-data`. Use it when services
|
|
19
|
+
should depend on the portable interface (decoupled from Prisma).
|
|
20
|
+
|
|
21
|
+
Note: PrismaModule's transparent transaction proxy already auto-routes
|
|
22
|
+
`prismaService.client.<model>.x()` to the active transaction client when
|
|
23
|
+
`transaction: true`. The abstract repo's value is the `IRepository` contract
|
|
24
|
+
(decoupling), not transaction wiring.
|
|
25
|
+
|
|
26
|
+
**Limitations:**
|
|
27
|
+
- Structurally assumes the primary key property is named `"id"`. Schemas using a
|
|
28
|
+
different PK name must bypass this base class.
|
|
29
|
+
- One `IRepository` instance points to one Prisma database. To share repositories
|
|
30
|
+
across databases, register one `forRoot` per DB and bind each repository to a
|
|
31
|
+
named tx manager — see "Multi-DB" below.
|
|
32
|
+
|
|
33
|
+
Wiring example:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
@Injectable()
|
|
37
|
+
export class PrismaUserRepository extends AbstractPrismaRepository<User, UserModel, string> {
|
|
38
|
+
constructor(@Inject(TRANSACTION_MANAGER) tx: ITransactionManager) { super(tx); }
|
|
39
|
+
protected modelDelegate(client: any) { return client.user; }
|
|
40
|
+
// ...mapper implementations
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Module:
|
|
44
|
+
providers: [
|
|
45
|
+
PrismaUserRepository,
|
|
46
|
+
{ provide: USER_REPOSITORY, useExisting: PrismaUserRepository },
|
|
47
|
+
]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Multi-DB
|
|
51
|
+
|
|
52
|
+
Multiple databases in one process are wired by repeating `PrismaModule.forRoot`
|
|
53
|
+
with different `name` values. Each call publishes a per-connection
|
|
54
|
+
`PrismaService` token (via `getPrismaToken(name)`) and a per-connection
|
|
55
|
+
transaction manager token (via `getPrismaTransactionManagerToken(name)`). The
|
|
56
|
+
**default** connection additionally aliases the global `TRANSACTION_MANAGER`
|
|
57
|
+
symbol from `@nathapp/nestjs-data`, so single-DB consumers do not change.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import {
|
|
61
|
+
PrismaModule,
|
|
62
|
+
PrismaService,
|
|
63
|
+
getPrismaToken,
|
|
64
|
+
getPrismaTransactionManagerToken,
|
|
65
|
+
} from '@nathapp/nestjs-prisma';
|
|
66
|
+
import { ITransactionManager } from '@nathapp/nestjs-data';
|
|
67
|
+
|
|
68
|
+
@Module({
|
|
69
|
+
imports: [
|
|
70
|
+
PrismaModule.forRoot({ name: 'dbA', client: PrismaClientA, transaction: true }),
|
|
71
|
+
PrismaModule.forRoot({ name: 'dbB', client: PrismaClientB, transaction: true }),
|
|
72
|
+
],
|
|
73
|
+
providers: [UserService, AccountService, UserRepository, AccountRepository],
|
|
74
|
+
})
|
|
75
|
+
export class AppModule {}
|
|
76
|
+
|
|
77
|
+
@Injectable()
|
|
78
|
+
export class UserRepository extends AbstractPrismaRepository<User, UserModel, string> {
|
|
79
|
+
constructor(@Inject(getPrismaTransactionManagerToken('dbA')) tx: ITransactionManager) {
|
|
80
|
+
super(tx);
|
|
81
|
+
}
|
|
82
|
+
protected modelDelegate(client: any) { return client.user; }
|
|
83
|
+
// ...mapper implementations
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Injectable()
|
|
87
|
+
export class UserService {
|
|
88
|
+
constructor(
|
|
89
|
+
@Inject(getPrismaTransactionManagerToken('dbA')) private readonly txA: ITransactionManager,
|
|
90
|
+
private readonly users: UserRepository,
|
|
91
|
+
) {}
|
|
92
|
+
|
|
93
|
+
async register(input: CreateUserInput) {
|
|
94
|
+
return this.txA.run(async () => {
|
|
95
|
+
// Wraps dbA writes only.
|
|
96
|
+
return this.users.create(input);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Atomicity boundary — read this carefully
|
|
103
|
+
|
|
104
|
+
A `tx.run()` on a named tx manager covers **only** that connection's writes. If
|
|
105
|
+
code inside `tx.run('dbA')` also writes to dbB (via a different repository
|
|
106
|
+
bound to a different tx manager), those dbB writes are **independent** — they
|
|
107
|
+
commit/roll back on their own. There is no 2PC, no distributed transaction, no
|
|
108
|
+
cross-DB atomicity.
|
|
109
|
+
|
|
110
|
+
**This is intentional.** Cross-DB consistency in microservices is solved with
|
|
111
|
+
sagas / outbox patterns, not transactions. If you find yourself wanting to wrap
|
|
112
|
+
two DBs in one `tx.run()`, the right answer is almost always to (a) move the
|
|
113
|
+
data so it lives in one DB, or (b) make the second write idempotent and use an
|
|
114
|
+
outbox / compensation pattern.
|
|
115
|
+
|
|
116
|
+
### Default connection convenience
|
|
117
|
+
|
|
118
|
+
For services that only ever talk to one DB, keep using
|
|
119
|
+
`@Inject(TRANSACTION_MANAGER)` from `@nathapp/nestjs-data`. It is registered as
|
|
120
|
+
an alias for `getPrismaTransactionManagerToken()` (the default connection)
|
|
121
|
+
automatically. No multi-DB token churn for single-DB code.
|
|
122
|
+
|
|
15
123
|
## Gotchas
|
|
16
124
|
- Error-case tests must use `await expect(module.compile()).rejects.toThrow()` — NestJS `compile()` eagerly instantiates providers.
|
|
17
125
|
- `prisma` is a peer dependency — consumers must install it.
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -25,4 +25,5 @@ __exportStar(require("./testing"), exports);
|
|
|
25
25
|
__exportStar(require("./errors/prisma-error.mapper"), exports);
|
|
26
26
|
__exportStar(require("./filter/prisma-exception.filter"), exports);
|
|
27
27
|
__exportStar(require("./transaction"), exports);
|
|
28
|
+
__exportStar(require("./repository"), exports);
|
|
28
29
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,4CAA0B;AAC1B,+DAA6C;AAC7C,mEAAiD;AACjD,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,kDAAgC;AAChC,mDAAiC;AACjC,qDAAmC;AACnC,kDAAgC;AAChC,+CAA6B;AAC7B,4CAA0B;AAC1B,+DAA6C;AAC7C,mEAAiD;AACjD,gDAA8B;AAC9B,+CAA6B"}
|
package/dist/prisma.constants.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPrismaToken = exports.PRISMA_MODULE_OPTIONS = exports.DEFAULT_PRISMA_CONNECTION = void 0;
|
|
3
|
+
exports.getPrismaTransactionManagerToken = exports.getPrismaToken = exports.PRISMA_MODULE_OPTIONS = exports.DEFAULT_PRISMA_CONNECTION = void 0;
|
|
4
4
|
exports.DEFAULT_PRISMA_CONNECTION = 'default';
|
|
5
5
|
exports.PRISMA_MODULE_OPTIONS = Symbol('PRISMA_MODULE_OPTIONS');
|
|
6
6
|
const getPrismaToken = (name) => name && name !== exports.DEFAULT_PRISMA_CONNECTION
|
|
7
7
|
? `PRISMA_SERVICE_${name}`
|
|
8
8
|
: 'PRISMA_SERVICE_DEFAULT';
|
|
9
9
|
exports.getPrismaToken = getPrismaToken;
|
|
10
|
+
const getPrismaTransactionManagerToken = (name) => name && name !== exports.DEFAULT_PRISMA_CONNECTION
|
|
11
|
+
? `PRISMA_TRANSACTION_MANAGER_${name}`
|
|
12
|
+
: 'PRISMA_TRANSACTION_MANAGER_DEFAULT';
|
|
13
|
+
exports.getPrismaTransactionManagerToken = getPrismaTransactionManagerToken;
|
|
10
14
|
//# sourceMappingURL=prisma.constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.constants.js","sourceRoot":"","sources":["../lib/prisma.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GAAG,SAAS,CAAC;AACtC,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"prisma.constants.js","sourceRoot":"","sources":["../lib/prisma.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GAAG,SAAS,CAAC;AACtC,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAY9D,MAAM,cAAc,GAAG,CAAC,IAAa,EAAU,EAAE,CACtD,IAAI,IAAI,IAAI,KAAK,iCAAyB;IACxC,CAAC,CAAC,kBAAkB,IAAI,EAAE;IAC1B,CAAC,CAAC,wBAAwB,CAAC;AAHlB,QAAA,cAAc,kBAGI;AAoBxB,MAAM,gCAAgC,GAAG,CAAC,IAAa,EAAU,EAAE,CACxE,IAAI,IAAI,IAAI,KAAK,iCAAyB;IACxC,CAAC,CAAC,8BAA8B,IAAI,EAAE;IACtC,CAAC,CAAC,oCAAoC,CAAC;AAH9B,QAAA,gCAAgC,oCAGF"}
|
package/dist/prisma.module.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ import type { PrismaModuleOptions, PrismaModuleAsyncOptions } from './prisma.int
|
|
|
3
3
|
export declare class PrismaModule {
|
|
4
4
|
static forRoot(options: PrismaModuleOptions): DynamicModule;
|
|
5
5
|
static forRootAsync(options: PrismaModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProvidersWithCtx;
|
|
6
7
|
private static createAsyncProviders;
|
|
7
8
|
}
|
package/dist/prisma.module.js
CHANGED
|
@@ -64,15 +64,23 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
if (transaction && capturedAls) {
|
|
67
|
+
const namedTxToken = (0, prisma_constants_1.getPrismaTransactionManagerToken)(name);
|
|
68
|
+
const isDefaultConnection = !name || name === 'default';
|
|
67
69
|
providers.push({
|
|
68
|
-
provide:
|
|
70
|
+
provide: namedTxToken,
|
|
69
71
|
useFactory: () => new prisma_transaction_manager_1.PrismaTransactionManager(originalClient, capturedAls),
|
|
70
72
|
inject: [connectionToken],
|
|
71
73
|
});
|
|
72
74
|
providers.push({
|
|
73
|
-
provide:
|
|
74
|
-
useExisting:
|
|
75
|
+
provide: prisma_transaction_manager_1.PrismaTransactionManager,
|
|
76
|
+
useExisting: namedTxToken,
|
|
75
77
|
});
|
|
78
|
+
if (isDefaultConnection) {
|
|
79
|
+
providers.push({
|
|
80
|
+
provide: nestjs_data_1.TRANSACTION_MANAGER,
|
|
81
|
+
useExisting: namedTxToken,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
76
84
|
}
|
|
77
85
|
return {
|
|
78
86
|
module: PrismaModule_1,
|
|
@@ -84,7 +92,8 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
84
92
|
static forRootAsync(options) {
|
|
85
93
|
const { isGlobal = true, name } = options;
|
|
86
94
|
const connectionToken = (0, prisma_constants_1.getPrismaToken)(name);
|
|
87
|
-
const
|
|
95
|
+
const ctx = {};
|
|
96
|
+
const asyncProviders = this.createAsyncProvidersWithCtx(options, connectionToken, ctx);
|
|
88
97
|
const providers = [...asyncProviders];
|
|
89
98
|
if (!name || name === 'default') {
|
|
90
99
|
providers.push({
|
|
@@ -92,6 +101,28 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
92
101
|
useExisting: connectionToken,
|
|
93
102
|
});
|
|
94
103
|
}
|
|
104
|
+
const namedTxToken = (0, prisma_constants_1.getPrismaTransactionManagerToken)(name);
|
|
105
|
+
const isDefaultConnection = !name || name === 'default';
|
|
106
|
+
providers.push({
|
|
107
|
+
provide: namedTxToken,
|
|
108
|
+
inject: [connectionToken, prisma_constants_1.PRISMA_MODULE_OPTIONS],
|
|
109
|
+
useFactory: (_service, opts) => {
|
|
110
|
+
if (!opts.transaction || !ctx.als || !ctx.originalClient) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return new prisma_transaction_manager_1.PrismaTransactionManager(ctx.originalClient, ctx.als);
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
providers.push({
|
|
117
|
+
provide: prisma_transaction_manager_1.PrismaTransactionManager,
|
|
118
|
+
useExisting: namedTxToken,
|
|
119
|
+
});
|
|
120
|
+
if (isDefaultConnection) {
|
|
121
|
+
providers.push({
|
|
122
|
+
provide: nestjs_data_1.TRANSACTION_MANAGER,
|
|
123
|
+
useExisting: namedTxToken,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
95
126
|
return {
|
|
96
127
|
module: PrismaModule_1,
|
|
97
128
|
global: isGlobal,
|
|
@@ -100,7 +131,7 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
100
131
|
exports: providers,
|
|
101
132
|
};
|
|
102
133
|
}
|
|
103
|
-
static
|
|
134
|
+
static createAsyncProvidersWithCtx(options, connectionToken, ctx) {
|
|
104
135
|
if (options.useFactory) {
|
|
105
136
|
return [
|
|
106
137
|
{
|
|
@@ -113,9 +144,9 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
113
144
|
useFactory: (moduleOptions) => {
|
|
114
145
|
const service = new prisma_service_1.PrismaService(moduleOptions);
|
|
115
146
|
if (moduleOptions.transaction) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
service.
|
|
147
|
+
ctx.als = new async_hooks_1.AsyncLocalStorage();
|
|
148
|
+
ctx.originalClient = service.client;
|
|
149
|
+
patchWithTransactionProxy(service, ctx.als);
|
|
119
150
|
}
|
|
120
151
|
return service;
|
|
121
152
|
},
|
|
@@ -136,7 +167,15 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
136
167
|
},
|
|
137
168
|
{
|
|
138
169
|
provide: connectionToken,
|
|
139
|
-
useFactory: (moduleOptions) =>
|
|
170
|
+
useFactory: (moduleOptions) => {
|
|
171
|
+
const service = new prisma_service_1.PrismaService(moduleOptions);
|
|
172
|
+
if (moduleOptions.transaction) {
|
|
173
|
+
ctx.als = new async_hooks_1.AsyncLocalStorage();
|
|
174
|
+
ctx.originalClient = service.client;
|
|
175
|
+
patchWithTransactionProxy(service, ctx.als);
|
|
176
|
+
}
|
|
177
|
+
return service;
|
|
178
|
+
},
|
|
140
179
|
inject: [prisma_constants_1.PRISMA_MODULE_OPTIONS],
|
|
141
180
|
},
|
|
142
181
|
];
|
|
@@ -150,13 +189,24 @@ let PrismaModule = PrismaModule_1 = class PrismaModule {
|
|
|
150
189
|
},
|
|
151
190
|
{
|
|
152
191
|
provide: connectionToken,
|
|
153
|
-
useFactory: (moduleOptions) =>
|
|
192
|
+
useFactory: (moduleOptions) => {
|
|
193
|
+
const service = new prisma_service_1.PrismaService(moduleOptions);
|
|
194
|
+
if (moduleOptions.transaction) {
|
|
195
|
+
ctx.als = new async_hooks_1.AsyncLocalStorage();
|
|
196
|
+
ctx.originalClient = service.client;
|
|
197
|
+
patchWithTransactionProxy(service, ctx.als);
|
|
198
|
+
}
|
|
199
|
+
return service;
|
|
200
|
+
},
|
|
154
201
|
inject: [prisma_constants_1.PRISMA_MODULE_OPTIONS],
|
|
155
202
|
},
|
|
156
203
|
];
|
|
157
204
|
}
|
|
158
205
|
throw new Error('Invalid PrismaModuleAsyncOptions: must provide useFactory, useClass, or useExisting');
|
|
159
206
|
}
|
|
207
|
+
static createAsyncProviders(options, connectionToken) {
|
|
208
|
+
return this.createAsyncProvidersWithCtx(options, connectionToken, {});
|
|
209
|
+
}
|
|
160
210
|
};
|
|
161
211
|
exports.PrismaModule = PrismaModule;
|
|
162
212
|
exports.PrismaModule = PrismaModule = PrismaModule_1 = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../lib/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,6CAAgD;AAChD,sDAA2D;AAE3D,qDAAiD;AACjD,yFAAoF;AACpF,
|
|
1
|
+
{"version":3,"file":"prisma.module.js","sourceRoot":"","sources":["../lib/prisma.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,6CAAgD;AAChD,sDAA2D;AAE3D,qDAAiD;AACjD,yFAAoF;AACpF,yDAA6G;AAC7G,6FAAoF;AAMpF,SAAS,yBAAyB,CAChC,aAA+B,EAC/B,GAAwC;IAExC,MAAM,cAAc,GAAG,aAAa,CAAC,MAAM,CAAC;IAC5C,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,cAAc,EAAE;QACtC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;YAChC,IAAI,QAAQ;gBAA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AZ,YAAY;IADxB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,YAAY,CAiOxB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { IPageResult, IRepository, ITransactionManager } from '@nathapp/nestjs-data';
|
|
2
|
+
import type { IPageOption } from '@nathapp/nestjs-common';
|
|
3
|
+
import { PrismaClientLike } from '../prisma.interfaces';
|
|
4
|
+
export interface PrismaModelDelegate<TModel, TId> {
|
|
5
|
+
findUnique(args: {
|
|
6
|
+
where: {
|
|
7
|
+
id: TId;
|
|
8
|
+
};
|
|
9
|
+
}): Promise<TModel | null>;
|
|
10
|
+
findFirst(args: {
|
|
11
|
+
where: any;
|
|
12
|
+
}): Promise<TModel | null>;
|
|
13
|
+
findMany(args: {
|
|
14
|
+
skip: number;
|
|
15
|
+
take: number;
|
|
16
|
+
where?: any;
|
|
17
|
+
}): Promise<TModel[]>;
|
|
18
|
+
count(args: {
|
|
19
|
+
where?: any;
|
|
20
|
+
}): Promise<number>;
|
|
21
|
+
create(args: {
|
|
22
|
+
data: any;
|
|
23
|
+
}): Promise<TModel>;
|
|
24
|
+
update(args: {
|
|
25
|
+
where: {
|
|
26
|
+
id: TId;
|
|
27
|
+
};
|
|
28
|
+
data: any;
|
|
29
|
+
}): Promise<TModel>;
|
|
30
|
+
delete(args: {
|
|
31
|
+
where: {
|
|
32
|
+
id: TId;
|
|
33
|
+
};
|
|
34
|
+
}): Promise<TModel>;
|
|
35
|
+
}
|
|
36
|
+
export declare abstract class AbstractPrismaRepository<TDomain, TModel, TId = string> implements IRepository<TDomain, TId> {
|
|
37
|
+
protected readonly tx: ITransactionManager;
|
|
38
|
+
constructor(tx: ITransactionManager);
|
|
39
|
+
protected abstract modelDelegate(client: PrismaClientLike): PrismaModelDelegate<TModel, TId>;
|
|
40
|
+
protected abstract toDomain(model: TModel): TDomain;
|
|
41
|
+
protected abstract toPersistenceCreate(domain: TDomain): any;
|
|
42
|
+
protected abstract toPersistenceUpdate(patch: Partial<TDomain>): any;
|
|
43
|
+
protected get model(): PrismaModelDelegate<TModel, TId>;
|
|
44
|
+
findById(id: TId): Promise<TDomain | null>;
|
|
45
|
+
findOne(criteria: Partial<TDomain>): Promise<TDomain | null>;
|
|
46
|
+
findAll(page: IPageOption): Promise<IPageResult<TDomain>>;
|
|
47
|
+
count(criteria?: Partial<TDomain>): Promise<number>;
|
|
48
|
+
create(input: TDomain): Promise<TDomain>;
|
|
49
|
+
update(id: TId, patch: Partial<TDomain>): Promise<TDomain>;
|
|
50
|
+
delete(id: TId): Promise<void>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.AbstractPrismaRepository = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const nestjs_data_1 = require("@nathapp/nestjs-data");
|
|
18
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
19
|
+
let AbstractPrismaRepository = class AbstractPrismaRepository {
|
|
20
|
+
constructor(tx) {
|
|
21
|
+
this.tx = tx;
|
|
22
|
+
}
|
|
23
|
+
get model() {
|
|
24
|
+
const client = this.tx.getClient();
|
|
25
|
+
return this.modelDelegate(client);
|
|
26
|
+
}
|
|
27
|
+
async findById(id) {
|
|
28
|
+
const m = await this.model.findUnique({ where: { id } });
|
|
29
|
+
return m ? this.toDomain(m) : null;
|
|
30
|
+
}
|
|
31
|
+
async findOne(criteria) {
|
|
32
|
+
const where = this.toPersistenceUpdate(criteria);
|
|
33
|
+
const m = await this.model.findFirst({ where });
|
|
34
|
+
return m ? this.toDomain(m) : null;
|
|
35
|
+
}
|
|
36
|
+
async findAll(page) {
|
|
37
|
+
const { skip, take } = (0, nestjs_common_1.resolvePageOption)(page);
|
|
38
|
+
const [rows, total] = await Promise.all([
|
|
39
|
+
this.model.findMany({ skip, take }),
|
|
40
|
+
this.model.count({ where: undefined }),
|
|
41
|
+
]);
|
|
42
|
+
return new nestjs_common_1.Page(page, total, rows.map((r) => this.toDomain(r)));
|
|
43
|
+
}
|
|
44
|
+
async count(criteria) {
|
|
45
|
+
if (!criteria)
|
|
46
|
+
return this.model.count({});
|
|
47
|
+
const where = this.toPersistenceUpdate(criteria);
|
|
48
|
+
return this.model.count({ where });
|
|
49
|
+
}
|
|
50
|
+
async create(input) {
|
|
51
|
+
const data = this.toPersistenceCreate(input);
|
|
52
|
+
const created = await this.model.create({ data });
|
|
53
|
+
return this.toDomain(created);
|
|
54
|
+
}
|
|
55
|
+
async update(id, patch) {
|
|
56
|
+
const data = this.toPersistenceUpdate(patch);
|
|
57
|
+
const updated = await this.model.update({ where: { id }, data });
|
|
58
|
+
return this.toDomain(updated);
|
|
59
|
+
}
|
|
60
|
+
async delete(id) {
|
|
61
|
+
await this.model.delete({ where: { id } });
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.AbstractPrismaRepository = AbstractPrismaRepository;
|
|
65
|
+
exports.AbstractPrismaRepository = AbstractPrismaRepository = __decorate([
|
|
66
|
+
__param(0, (0, common_1.Inject)(nestjs_data_1.TRANSACTION_MANAGER)),
|
|
67
|
+
__metadata("design:paramtypes", [Object])
|
|
68
|
+
], AbstractPrismaRepository);
|
|
69
|
+
//# sourceMappingURL=abstract-prisma.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-prisma.repository.js","sourceRoot":"","sources":["../../lib/repository/abstract-prisma.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwC;AACxC,sDAK8B;AAC9B,0DAAiE;AAqDjE,IAAsB,wBAAwB,GAA9C,MAAsB,wBAAwB;IAE5C,YAA4D,EAAuB;QAAvB,OAAE,GAAF,EAAE,CAAqB;IAAG,CAAC;IAWvF,IAAc,KAAK;QACjB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,SAAS,EAAoB,CAAC;QACrD,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,EAAO;QACpB,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QACzD,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAA0B;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QACjD,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAChD,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,OAA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AG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAO;QAClB,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAC7C,CAAC;CACF,CAAA;AA3DqB,4DAAwB;mCAAxB,wBAAwB;IAE/B,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;;GAFpB,wBAAwB,CA2D7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './abstract-prisma.repository';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./abstract-prisma.repository"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/repository/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C"}
|
package/lib/index.ts
CHANGED
package/lib/prisma.constants.ts
CHANGED
|
@@ -2,9 +2,39 @@ export const DEFAULT_PRISMA_CONNECTION = 'default';
|
|
|
2
2
|
export const PRISMA_MODULE_OPTIONS = Symbol('PRISMA_MODULE_OPTIONS');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Get the DI token for a named Prisma connection.
|
|
5
|
+
* Get the DI token for a named Prisma connection (the PrismaService).
|
|
6
|
+
*
|
|
7
|
+
* Single-DB:
|
|
8
|
+
* getPrismaToken() → 'PRISMA_SERVICE_DEFAULT'
|
|
9
|
+
* getPrismaToken('default') → 'PRISMA_SERVICE_DEFAULT'
|
|
10
|
+
*
|
|
11
|
+
* Multi-DB:
|
|
12
|
+
* getPrismaToken('dbA') → 'PRISMA_SERVICE_dbA'
|
|
6
13
|
*/
|
|
7
14
|
export const getPrismaToken = (name?: string): string =>
|
|
8
15
|
name && name !== DEFAULT_PRISMA_CONNECTION
|
|
9
16
|
? `PRISMA_SERVICE_${name}`
|
|
10
17
|
: 'PRISMA_SERVICE_DEFAULT';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get the DI token for a named Prisma connection's ITransactionManager.
|
|
21
|
+
*
|
|
22
|
+
* Pair this with `getPrismaToken(name)` — same logical name, two derived tokens:
|
|
23
|
+
*
|
|
24
|
+
* getPrismaToken('dbA') → 'PRISMA_SERVICE_dbA'
|
|
25
|
+
* getPrismaTransactionManagerToken('dbA') → 'PRISMA_TRANSACTION_MANAGER_dbA'
|
|
26
|
+
*
|
|
27
|
+
* For the default connection, the module also registers the global
|
|
28
|
+
* `TRANSACTION_MANAGER` symbol from `@nathapp/nestjs-data` as an alias, so
|
|
29
|
+
* single-DB consumers can keep using `@Inject(TRANSACTION_MANAGER)`.
|
|
30
|
+
*
|
|
31
|
+
* IMPORTANT — atomicity boundary:
|
|
32
|
+
* `tx.run()` on a named tx manager covers ONLY that connection's writes. Writes
|
|
33
|
+
* to a different connection from inside that callback are independent and will
|
|
34
|
+
* not roll back together. Cross-DB consistency requires sagas/outbox patterns,
|
|
35
|
+
* NOT this token. There is no distributed transaction support.
|
|
36
|
+
*/
|
|
37
|
+
export const getPrismaTransactionManagerToken = (name?: string): string =>
|
|
38
|
+
name && name !== DEFAULT_PRISMA_CONNECTION
|
|
39
|
+
? `PRISMA_TRANSACTION_MANAGER_${name}`
|
|
40
|
+
: 'PRISMA_TRANSACTION_MANAGER_DEFAULT';
|