@vsrepo/prisma7-adapter 1.1.3 → 1.1.5
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.md +11 -11
- package/README.pt-BR.md +11 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/parsers/data.parser.d.ts +5 -2
- package/dist/parsers/data.parser.js +25 -13
- package/dist/parsers/data.parser.js.map +1 -1
- package/dist/types/prisma7-client-like.type.d.ts +1 -0
- package/dist/types/prisma7-orm-types.type.d.ts +2 -2
- package/dist/types/relation.type.d.ts +5 -2
- package/dist/validators/adapter-config.schema.d.ts +1 -1
- package/dist/validators/relation.schema.d.ts +1 -1
- package/dist/validators/relation.schema.js +1 -1
- package/dist/validators/relation.schema.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,17 +54,17 @@ Both `vsrepo` and `@vsrepo/prisma7-adapter` are published to npm and ready to us
|
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
56
|
import { VSRepository, VSLogLevel } from "vsrepo";
|
|
57
|
-
import {
|
|
57
|
+
import { Prisma7Adapter, Prisma7OrmTypes } from "@vsrepo/prisma7-adapter";
|
|
58
58
|
import { Prisma, PrismaClient } from "./generated/prisma/client";
|
|
59
59
|
import { prisma } from "./prisma";
|
|
60
60
|
|
|
61
61
|
type User = Prisma.UserGetPayload<{ include: { posts: true } }>;
|
|
62
|
-
type MyOrmTypes = Prisma7OrmTypes<PrismaClient
|
|
62
|
+
type MyOrmTypes = Prisma7OrmTypes<PrismaClient>;
|
|
63
63
|
|
|
64
64
|
class UserRepository extends VSRepository<User, string, MyOrmTypes> {
|
|
65
65
|
constructor() {
|
|
66
66
|
super({
|
|
67
|
-
adapter: new
|
|
67
|
+
adapter: new Prisma7Adapter(prisma, {
|
|
68
68
|
tableName: "user",
|
|
69
69
|
pkName: "id",
|
|
70
70
|
relations: {
|
|
@@ -84,12 +84,12 @@ const user = await userRepository.get({ id: "..." }, { relations: { posts: true
|
|
|
84
84
|
|
|
85
85
|
Here the `relations` you pass in the method `options` — shaped like `{ field: true }` — is transformed into a Prisma `include` by the adapter (see [`relations` in method options (read)](#relations-in-method-options-read)). If you supply `select`, the `relations`/`include` is ignored. Don't confuse it with the constructor-config `relations`, which describes how relation fields are resolved in write payloads — the difference is explained in [The two `relations`](#the-two-relations).
|
|
86
86
|
|
|
87
|
-
`Prisma7OrmTypes<DB
|
|
87
|
+
`Prisma7OrmTypes<DB>` ties `VSRepository`'s `getDbClient()`/`transaction()` return types to your real, generated Prisma types — see [Transactions](#transactions).
|
|
88
88
|
|
|
89
89
|
## Constructor config
|
|
90
90
|
|
|
91
91
|
```typescript
|
|
92
|
-
new
|
|
92
|
+
new Prisma7Adapter(prisma, {
|
|
93
93
|
tableName: "user", // required — the Prisma Client model/delegate name, as in `prisma.user`
|
|
94
94
|
pkName: "id", // required — the entity's primary key field name
|
|
95
95
|
relations: { ... }, // optional — see "relations in the constructor (write)" below
|
|
@@ -97,7 +97,7 @@ new VSRepoPrisma7Adapter(prisma, {
|
|
|
97
97
|
});
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
The config is validated with [valibot](https://valibot.dev/) — an invalid `tableName`/`pkName`/`relations`/`logLevel` throws a `
|
|
100
|
+
The config is validated with [valibot](https://valibot.dev/) — an invalid `tableName`/`pkName`/`relations`/`logLevel` throws a `VSRepoAdapterError` naming the offending field.
|
|
101
101
|
|
|
102
102
|
## Relations
|
|
103
103
|
|
|
@@ -107,7 +107,7 @@ The name `relations` appears in **two different places** in the API, with **diff
|
|
|
107
107
|
|
|
108
108
|
| | `relations` in the **constructor** | `relations` in **method options** |
|
|
109
109
|
| --- | --- | --- |
|
|
110
|
-
| Where you define it | `new
|
|
110
|
+
| Where you define it | `new Prisma7Adapter(prisma, { relations: ... })` | `repository.get(where, { relations: ... })` — and other methods |
|
|
111
111
|
| Shape | One **config object** per field: `{ mode, restriction, pk, nullable? }` | One **`true`/sub-object** per field: `{ posts: true }` |
|
|
112
112
|
| Purpose | **Write** — when a `create`/`update`/`upsert`/`save`/`merge` payload contains a relation field, tells the adapter how to turn it into a Prisma nested write (`create`/`connectOrCreate`/`upsert`/`disconnect`/`deleteMany`/`set`) | **Read** — eager loading: which relations to fetch alongside the result (becomes a Prisma `include`) |
|
|
113
113
|
| Consumed by | `parsePrismaWriteData` / `mergeEntities` (write resolvers) | `parsePrismaInclude` (via `resolveReadArg`) |
|
|
@@ -147,12 +147,12 @@ Cardinality of the relation, from the point of view of the entity that owns the
|
|
|
147
147
|
Controls how `save`/`update`/`upsert` handle relation items that already exist (matched by `pk`) and, for to-many relations, items that were **not** included in the payload:
|
|
148
148
|
|
|
149
149
|
- **`"add"`** — only creates/connects/upserts the items you send. Existing items that aren't in the payload are left untouched.
|
|
150
|
-
- **`"set"`** — same as `"add"`, but also removes what wasn't sent: for `otm` it runs a `deleteMany` on the items missing from the array; for `mtm` it resets the join (`set: []`) before reconnecting; for `oto`/`mto` sending `null` disconnects
|
|
150
|
+
- **`"set"`** — same as `"add"`, but also removes what wasn't sent: for `otm` it runs a `deleteMany` on the items missing from the array; for `mtm` it resets the join (`set: []`) before reconnecting; for `oto`/`mto` with `nullable: true`, sending `null` deletes/disconnects the relation (see below).
|
|
151
151
|
|
|
152
152
|
#### `pk` and `nullable`
|
|
153
153
|
|
|
154
154
|
- **`pk`** — the field used to identify an existing related record. An item **with** `pk` in the payload becomes a `connectOrCreate`/`upsert`; an item **without** it becomes a plain `create`.
|
|
155
|
-
- **`nullable`** —
|
|
155
|
+
- **`nullable`** — relevant for `oto`/`mto` to-one relations. When `true`, sending `null` for the field resolves to `disconnect` on update (`delete` instead for `oto` with `restriction: "set"` — an `oto` side can't just be "disconnected", the owned row is removed). When omitted/`false`, sending `null` for a to-one relation throws a `VSRepoAdapterError` (code `INVALID_DATA`) telling you the relation is not nullable.
|
|
156
156
|
|
|
157
157
|
#### How each write method resolves relations
|
|
158
158
|
|
|
@@ -160,7 +160,7 @@ Controls how `save`/`update`/`upsert` handle relation items that already exist (
|
|
|
160
160
|
| --- | --- |
|
|
161
161
|
| `create` | `create`/`connectOrCreate` only (no upsert — there's nothing to update yet) |
|
|
162
162
|
| `update` / `upsert` (`update` half) / `save` (upsert branch) | Full resolution: `create`/`connectOrCreate`/`upsert`/`disconnect`/`delete`/`deleteMany`/`set`, per `mode`/`restriction` |
|
|
163
|
-
| `createMany` / `createManyReturning` / `updateMany` / `updateManyReturning` | Not supported — throws a `
|
|
163
|
+
| `createMany` / `createManyReturning` / `updateMany` / `updateManyReturning` | Not supported — throws a `VSRepoAdapterError` naming the offending field if the payload contains a configured relation |
|
|
164
164
|
|
|
165
165
|
### `relations` in method options (read)
|
|
166
166
|
|
|
@@ -225,7 +225,7 @@ const mostExpensive = await productRepository.max("price");
|
|
|
225
225
|
|
|
226
226
|
## `createMany`/`createManyReturning`/`updateMany`/`updateManyReturning` don't support nested writes
|
|
227
227
|
|
|
228
|
-
`createMany`, `createManyReturning`, `updateMany` and `updateManyReturning` only accept scalar fields in their `data`. If your payload includes a field configured in `relations` (regardless of its value), the adapter throws a `
|
|
228
|
+
`createMany`, `createManyReturning`, `updateMany` and `updateManyReturning` only accept scalar fields in their `data`. If your payload includes a field configured in `relations` (regardless of its value), the adapter throws a `VSRepoAdapterError` naming the offending field. For a full nested write, use `create`/`update`/`save` one record at a time, or wrap several `save` calls in a `saveMany`/`transaction`.
|
|
229
229
|
|
|
230
230
|
> Note on return order: `createManyReturning` don't guarantee the returned records follow the order of the input payload (`objs`). Their result comes from a second `findMany` (re-querying the inserted/updated rows by primary key), so the order is only guaranteed when you pass `order` in the options.
|
|
231
231
|
|
package/README.pt-BR.md
CHANGED
|
@@ -54,17 +54,17 @@ Tanto o `vsrepo` quanto o `@vsrepo/prisma7-adapter` já foram publicados no npm
|
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
56
|
import { VSRepository, VSLogLevel } from "vsrepo";
|
|
57
|
-
import {
|
|
57
|
+
import { Prisma7Adapter, Prisma7OrmTypes } from "@vsrepo/prisma7-adapter";
|
|
58
58
|
import { Prisma, PrismaClient } from "./generated/prisma/client";
|
|
59
59
|
import { prisma } from "./prisma";
|
|
60
60
|
|
|
61
61
|
type User = Prisma.UserGetPayload<{ include: { posts: true } }>;
|
|
62
|
-
type MyOrmTypes = Prisma7OrmTypes<PrismaClient
|
|
62
|
+
type MyOrmTypes = Prisma7OrmTypes<PrismaClient>;
|
|
63
63
|
|
|
64
64
|
class UserRepository extends VSRepository<User, string, MyOrmTypes> {
|
|
65
65
|
constructor() {
|
|
66
66
|
super({
|
|
67
|
-
adapter: new
|
|
67
|
+
adapter: new Prisma7Adapter(prisma, {
|
|
68
68
|
tableName: "user",
|
|
69
69
|
pkName: "id",
|
|
70
70
|
relations: {
|
|
@@ -84,12 +84,12 @@ const user = await userRepository.get({ id: "..." }, { relations: { posts: true
|
|
|
84
84
|
|
|
85
85
|
Aqui, o `relations` passado no `options` do método — com a forma `{ campo: true }` — é transformado num `include` do Prisma pelo adapter (ver [`relations` nas options (leitura)](#relations-nas-options-leitura)). Se você fornecer `select`, o `relations`/`include` é ignorado. Não confunda com o `relations` da config do construtor (que descreve como campos de relação são resolvidos em escritas) — a diferença é explicada em [Os dois `relations`](#os-dois-relations).
|
|
86
86
|
|
|
87
|
-
`Prisma7OrmTypes<DB
|
|
87
|
+
`Prisma7OrmTypes<DB>` amarra os tipos de retorno de `getDbClient()`/`transaction()` do `VSRepository` aos seus tipos reais e gerados do Prisma — ver [Transactions](#transactions).
|
|
88
88
|
|
|
89
89
|
## Config do construtor
|
|
90
90
|
|
|
91
91
|
```typescript
|
|
92
|
-
new
|
|
92
|
+
new Prisma7Adapter(prisma, {
|
|
93
93
|
tableName: "user", // obrigatório — nome do model/delegate do Prisma Client, como em `prisma.user`
|
|
94
94
|
pkName: "id", // obrigatório — nome do campo de primary key da entidade
|
|
95
95
|
relations: { ... }, // opcional — ver "relations no construtor (escrita)" abaixo
|
|
@@ -97,7 +97,7 @@ new VSRepoPrisma7Adapter(prisma, {
|
|
|
97
97
|
});
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
A config é validada com [valibot](https://valibot.dev/) — um `tableName`/`pkName`/`relations`/`logLevel` inválido lança um `
|
|
100
|
+
A config é validada com [valibot](https://valibot.dev/) — um `tableName`/`pkName`/`relations`/`logLevel` inválido lança um `VSRepoAdapterError` apontando o campo problemático.
|
|
101
101
|
|
|
102
102
|
## Relations
|
|
103
103
|
|
|
@@ -107,7 +107,7 @@ O nome `relations` aparece em **dois lugares diferentes** da API, com **formas e
|
|
|
107
107
|
|
|
108
108
|
| | `relations` no **construtor** | `relations` nas **options** |
|
|
109
109
|
| --- | --- | --- |
|
|
110
|
-
| Onde você define | `new
|
|
110
|
+
| Onde você define | `new Prisma7Adapter(prisma, { relations: ... })` | `repository.get(where, { relations: ... })` — e demais métodos |
|
|
111
111
|
| Formato | Um objeto de **configuração** por campo: `{ mode, restriction, pk, nullable? }` | Um objeto por campo **só com `true` ou sub-objeto**: `{ posts: true }` |
|
|
112
112
|
| Propósito | **Escrita** — quando um payload de `create`/`update`/`upsert`/`save`/`merge` tem campo de relação, diz como transformá-lo num nested write do Prisma (`create`/`connectOrCreate`/`upsert`/`disconnect`/`deleteMany`/`set`) | **Leitura** — eager loading: quais relations trazer junto no resultado (vira um `include` do Prisma) |
|
|
113
113
|
| Quem consome | `parsePrismaWriteData` / `mergeEntities` (resolvers de escrita) | `parsePrismaInclude` (via `resolveReadArg`) |
|
|
@@ -147,12 +147,12 @@ Cardinalidade da relation, do ponto de vista da entidade dona do campo:
|
|
|
147
147
|
Controla como `save`/`update`/`upsert` tratam itens de relação que já existem (casados pela `pk`) e, pra relations to-many, itens que **não** vieram no payload:
|
|
148
148
|
|
|
149
149
|
- **`"add"`** — só cria/conecta/faz upsert dos itens enviados. Itens já existentes que não estão no payload permanecem intocados.
|
|
150
|
-
- **`"set"`** — igual a `"add"`, mas também remove o que não foi enviado: em `otm` roda um `deleteMany` nos itens que faltam no array; em `mtm` reseta o vínculo (`set: []`) antes de reconectar; em `oto`/`mto` enviar `null` desconecta
|
|
150
|
+
- **`"set"`** — igual a `"add"`, mas também remove o que não foi enviado: em `otm` roda um `deleteMany` nos itens que faltam no array; em `mtm` reseta o vínculo (`set: []`) antes de reconectar; em `oto`/`mto` com `nullable: true`, enviar `null` apaga/desconecta a relation (ver abaixo).
|
|
151
151
|
|
|
152
152
|
#### `pk` e `nullable`
|
|
153
153
|
|
|
154
154
|
- **`pk`** — o campo usado pra identificar um registro relacionado já existente. Um item **com** `pk` no payload vira um `connectOrCreate`/`upsert`; um item **sem** `pk` vira um `create` simples.
|
|
155
|
-
- **`nullable`** —
|
|
155
|
+
- **`nullable`** — relevante pras relações to-one `oto`/`mto`. Quando `true`, enviar `null` no campo resolve pra `disconnect` no update (`delete` no caso de `oto` com `restriction: "set"` — um lado `oto` não dá só pra "desconectar", a linha possuída é removida). Quando omitido/`false`, enviar `null` numa relação to-one lança um `VSRepoAdapterError` (code `INVALID_DATA`) avisando que a relation não é nullable.
|
|
156
156
|
|
|
157
157
|
#### Como cada método de escrita resolve relations
|
|
158
158
|
|
|
@@ -160,7 +160,7 @@ Controla como `save`/`update`/`upsert` tratam itens de relação que já existem
|
|
|
160
160
|
| --- | --- |
|
|
161
161
|
| `create` | Só `create`/`connectOrCreate` (sem upsert — ainda não existe nada pra atualizar) |
|
|
162
162
|
| `update` / `upsert` (metade do `update`) / `save` (branch de upsert) | Resolução completa: `create`/`connectOrCreate`/`upsert`/`disconnect`/`delete`/`deleteMany`/`set`, conforme `mode`/`restriction` |
|
|
163
|
-
| `createMany` / `createManyReturning` / `updateMany` / `updateManyReturning` | Não suportado — lança um `
|
|
163
|
+
| `createMany` / `createManyReturning` / `updateMany` / `updateManyReturning` | Não suportado — lança um `VSRepoAdapterError` apontando o campo problemático se o payload tiver uma relation configurada |
|
|
164
164
|
|
|
165
165
|
### `relations` nas options (leitura)
|
|
166
166
|
|
|
@@ -225,7 +225,7 @@ const mostExpensive = await productRepository.max("price");
|
|
|
225
225
|
|
|
226
226
|
## `createMany`/`createManyReturning`/`updateMany`/`updateManyReturning` não suportam nested writes
|
|
227
227
|
|
|
228
|
-
`createMany`, `createManyReturning`, `updateMany` e `updateManyReturning` só aceitam campos escalares no `data`. Se seu payload incluir um campo configurado em `relations` (independente do valor), o adapter lança um `
|
|
228
|
+
`createMany`, `createManyReturning`, `updateMany` e `updateManyReturning` só aceitam campos escalares no `data`. Se seu payload incluir um campo configurado em `relations` (independente do valor), o adapter lança um `VSRepoAdapterError` apontando o campo problemático. Pra um nested write completo, use `create`/`update`/`save` registro por registro, ou envolva várias chamadas de `save` num `saveMany`/`transaction`.
|
|
229
229
|
|
|
230
230
|
> Nota sobre a ordem de retorno: `createManyReturning` não garante que os registros devolvidos seguem a ordem do payload de entrada (`objs`). O resultado vem de um segundo `findMany` (re-buscando as linhas inseridas/atualizadas pela primary key), então a ordem só é garantida quando você passa `order` nas options.
|
|
231
231
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { VSRepoPrisma7Adapter } from "./prisma7.adapter";
|
|
1
|
+
export { VSRepoPrisma7Adapter, VSRepoPrisma7Adapter as Prisma7Adapter } from "./prisma7.adapter";
|
|
2
2
|
export type { Relation } from "./types/relation.type";
|
|
3
3
|
export type { Prisma7OrmTypes } from "./types/prisma7-orm-types.type";
|
|
4
4
|
export type { Prisma7ClientLike } from "./types/prisma7-client-like.type";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VSRepoPrisma7Adapter = void 0;
|
|
3
|
+
exports.Prisma7Adapter = exports.VSRepoPrisma7Adapter = void 0;
|
|
4
4
|
var prisma7_adapter_1 = require("./prisma7.adapter");
|
|
5
5
|
Object.defineProperty(exports, "VSRepoPrisma7Adapter", { enumerable: true, get: function () { return prisma7_adapter_1.VSRepoPrisma7Adapter; } });
|
|
6
|
+
Object.defineProperty(exports, "Prisma7Adapter", { enumerable: true, get: function () { return prisma7_adapter_1.VSRepoPrisma7Adapter; } });
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAiG;AAAxF,uHAAA,oBAAoB,OAAA;AAAE,iHAAA,oBAAoB,OAAkB"}
|
|
@@ -13,8 +13,11 @@
|
|
|
13
13
|
* update, a não ser que `restriction: "add"`, que usa só `create`)
|
|
14
14
|
* - to-one com PK no valor enviado -> `connectOrCreate` (e
|
|
15
15
|
* `upsert` no update, a não ser que `restriction: "add"`)
|
|
16
|
-
* - to-one enviado como `null`
|
|
17
|
-
* `restriction: "set"`) ou `disconnect` (`
|
|
16
|
+
* - to-one enviado como `null` com `nullable` -> `delete` (`oto` +
|
|
17
|
+
* `restriction: "set"`) ou `disconnect` (`oto` com `restriction: "add"` /
|
|
18
|
+
* `mto`; um `oto` não "desconecta" no `update`, a linha possuída é apagada)
|
|
19
|
+
* - to-one enviado como `null` sem `nullable` -> lança `VSRepoAdapterError`
|
|
20
|
+
* (code `INVALID_DATA`)
|
|
18
21
|
* - to-many (`otm`/`mtm`) — itens são separados entre "com PK" e "sem PK":
|
|
19
22
|
* os sem PK viram `create`, os com PK viram `connectOrCreate` no create e
|
|
20
23
|
* `upsert` no update; com `restriction: "set"`, itens de `otm` que não
|
|
@@ -14,8 +14,11 @@
|
|
|
14
14
|
* update, a não ser que `restriction: "add"`, que usa só `create`)
|
|
15
15
|
* - to-one com PK no valor enviado -> `connectOrCreate` (e
|
|
16
16
|
* `upsert` no update, a não ser que `restriction: "add"`)
|
|
17
|
-
* - to-one enviado como `null`
|
|
18
|
-
* `restriction: "set"`) ou `disconnect` (`
|
|
17
|
+
* - to-one enviado como `null` com `nullable` -> `delete` (`oto` +
|
|
18
|
+
* `restriction: "set"`) ou `disconnect` (`oto` com `restriction: "add"` /
|
|
19
|
+
* `mto`; um `oto` não "desconecta" no `update`, a linha possuída é apagada)
|
|
20
|
+
* - to-one enviado como `null` sem `nullable` -> lança `VSRepoAdapterError`
|
|
21
|
+
* (code `INVALID_DATA`)
|
|
19
22
|
* - to-many (`otm`/`mtm`) — itens são separados entre "com PK" e "sem PK":
|
|
20
23
|
* os sem PK viram `create`, os com PK viram `connectOrCreate` no create e
|
|
21
24
|
* `upsert` no update; com `restriction: "set"`, itens de `otm` que não
|
|
@@ -28,6 +31,7 @@
|
|
|
28
31
|
*/
|
|
29
32
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
33
|
exports.parsePrismaWriteData = parsePrismaWriteData;
|
|
34
|
+
const vsrepo_1 = require("vsrepo");
|
|
31
35
|
function omitKey(item, key) {
|
|
32
36
|
const clone = { ...item };
|
|
33
37
|
delete clone[key];
|
|
@@ -43,16 +47,20 @@ function splitByPk(items, pk) {
|
|
|
43
47
|
}
|
|
44
48
|
function parseToOneRelation(field, relation) {
|
|
45
49
|
if (field === null) {
|
|
46
|
-
if (relation.
|
|
47
|
-
|
|
50
|
+
if (!relation.nullable) {
|
|
51
|
+
throw new vsrepo_1.VSRepoAdapterError(`You cannot provide null for a to-one relation when it is not nullable.`, vsrepo_1.AdapterErrorCode.INVALID_DATA, null);
|
|
48
52
|
}
|
|
49
|
-
if (relation.mode === "
|
|
53
|
+
if (relation.mode === "oto") {
|
|
54
|
+
if (relation.restriction === "set") {
|
|
55
|
+
return { update: { delete: true } };
|
|
56
|
+
}
|
|
50
57
|
return { update: { disconnect: true } };
|
|
51
58
|
}
|
|
52
|
-
|
|
59
|
+
// relation.mode === "mto"
|
|
60
|
+
return { update: { disconnect: true } };
|
|
53
61
|
}
|
|
54
62
|
const pkValue = field[relation.pk];
|
|
55
|
-
if (pkValue ==
|
|
63
|
+
if (pkValue == undefined) {
|
|
56
64
|
return {
|
|
57
65
|
create: { create: field },
|
|
58
66
|
update: relation.restriction === "add"
|
|
@@ -80,11 +88,13 @@ function parseToManyRelation(field, relation) {
|
|
|
80
88
|
where: { [relation.pk]: item[relation.pk] },
|
|
81
89
|
create: item,
|
|
82
90
|
}));
|
|
83
|
-
const upsert =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
const upsert = relation.mode === "mtm"
|
|
92
|
+
? undefined
|
|
93
|
+
: withPk.map(item => ({
|
|
94
|
+
where: { [relation.pk]: item[relation.pk] },
|
|
95
|
+
create: item,
|
|
96
|
+
update: omitKey(item, relation.pk),
|
|
97
|
+
}));
|
|
88
98
|
const create = { create: withoutPk, connectOrCreate };
|
|
89
99
|
if (relation.restriction === "add") {
|
|
90
100
|
return {
|
|
@@ -99,7 +109,9 @@ function parseToManyRelation(field, relation) {
|
|
|
99
109
|
update: relation.mode === "mtm"
|
|
100
110
|
? { set: [], create: withoutPk, connectOrCreate }
|
|
101
111
|
: {
|
|
102
|
-
deleteMany: {
|
|
112
|
+
deleteMany: {
|
|
113
|
+
[relation.pk]: { notIn: withPk.map(item => item[relation.pk]) },
|
|
114
|
+
},
|
|
103
115
|
create: withoutPk,
|
|
104
116
|
upsert,
|
|
105
117
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.parser.js","sourceRoot":"","sources":["../../src/parsers/data.parser.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"data.parser.js","sourceRoot":"","sources":["../../src/parsers/data.parser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;AAEH,mCAA8D;AAU9D,SAAS,OAAO,CAAC,IAAiB,EAAE,GAAW;IAC3C,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC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AC,EAAE,CAAC;QAC7C,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAElC,MAAM,QAAQ,GAAI,SAAqC,EAAE,CAAC,GAAG,CAA6B,CAAC;QAE3F,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACpB,IAAI,GAAG,KAAK,MAAM;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACxC,SAAS;QACb,CAAC;QAED,IAAI,QAAQ,CAAC,IAAI,KAAK,KAAK,IAAI,QAAQ,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACrD,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAA2B,EAAE,QAAQ,CAAC,CAAC;YACzE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;YAC7D,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;gBAAE,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;YAC7D,SAAS;QACb,CAAC;QAED,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAsB,EAAE,QAAQ,CAAC,CAAC;QACrE,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -13,7 +13,7 @@ import { Prisma7ClientLike } from "./prisma7-client-like.type";
|
|
|
13
13
|
*
|
|
14
14
|
* @publicApi
|
|
15
15
|
*/
|
|
16
|
-
export type Prisma7OrmTypes<DB extends Prisma7ClientLike, TX extends Omit<Prisma7ClientLike, "$on"
|
|
16
|
+
export type Prisma7OrmTypes<DB extends Prisma7ClientLike, TX extends Omit<Prisma7ClientLike, "$on"> | undefined = undefined> = {
|
|
17
17
|
dbClient: DB;
|
|
18
|
-
dbTransaction: TX;
|
|
18
|
+
dbTransaction: TX extends undefined ? Parameters<Parameters<NonNullable<DB["$transaction"]>>[0]>[0] : TX;
|
|
19
19
|
};
|
|
@@ -13,8 +13,11 @@
|
|
|
13
13
|
* - `pk`: name of the field used as the identifier of the related record,
|
|
14
14
|
* used to decide between `create` (no pk in the payload) and
|
|
15
15
|
* `connectOrCreate`/`upsert` (pk present).
|
|
16
|
-
* - `nullable`: for `mto` relations, whether the field accepts being set
|
|
17
|
-
* `null`
|
|
16
|
+
* - `nullable`: for `oto`/`mto` relations, whether the field accepts being set
|
|
17
|
+
* to `null`. When `true`, sending `null` on update resolves to `delete`
|
|
18
|
+
* (`oto` + `restriction: "set"`) or `disconnect` (`oto` + `restriction:
|
|
19
|
+
* "add"`, and `mto`). When `false`/omitted, sending `null` for a to-one
|
|
20
|
+
* relation throws a `VSRepoAdapterError` (code `INVALID_DATA`).
|
|
18
21
|
*
|
|
19
22
|
* @publicApi
|
|
20
23
|
*/
|
|
@@ -16,7 +16,7 @@ export declare const adapterConfigSchema: v.ObjectSchema<{
|
|
|
16
16
|
}, readonly [readonly ["nullable"], readonly ["mode"]], {
|
|
17
17
|
mode: "mtm" | "mto" | "otm" | "oto";
|
|
18
18
|
nullable?: boolean | undefined;
|
|
19
|
-
}, "'nullable: true' is only valid for 'mto' relations; 'otm'
|
|
19
|
+
}, "'nullable: true' is only valid for 'mto' and 'oto' relations; 'otm' and 'mtm' relations do not support 'nullable'.">]>, undefined>, undefined>;
|
|
20
20
|
readonly logLevel: v.OptionalSchema<v.EnumSchema<typeof VSLogLevel, undefined>, undefined>;
|
|
21
21
|
readonly logSlowThresholdMs: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.GtValueAction<number, 0, undefined>]>, undefined>;
|
|
22
22
|
}, undefined>;
|
|
@@ -13,4 +13,4 @@ export declare const relationSchema: v.SchemaWithPipe<readonly [v.StrictObjectSc
|
|
|
13
13
|
}, readonly [readonly ["nullable"], readonly ["mode"]], {
|
|
14
14
|
mode: "mtm" | "mto" | "otm" | "oto";
|
|
15
15
|
nullable?: boolean | undefined;
|
|
16
|
-
}, "'nullable: true' is only valid for 'mto' relations; 'otm'
|
|
16
|
+
}, "'nullable: true' is only valid for 'mto' and 'oto' relations; 'otm' and 'mtm' relations do not support 'nullable'.">]>;
|
|
@@ -41,5 +41,5 @@ exports.relationSchema = v.pipe(v.strictObject({
|
|
|
41
41
|
restriction: v.picklist(["set", "add"]),
|
|
42
42
|
pk: v.pipe(v.string(), v.minLength(1)),
|
|
43
43
|
nullable: v.optional(v.boolean()),
|
|
44
|
-
}), v.partialCheck([["nullable"], ["mode"]], input => !(input.nullable === true && input.mode !== "mto"), "'nullable: true' is only valid for 'mto' relations; 'otm'
|
|
44
|
+
}), v.partialCheck([["nullable"], ["mode"]], input => !(input.nullable === true && input.mode !== "mto" && input.mode !== "oto"), "'nullable: true' is only valid for 'mto' and 'oto' relations; 'otm' and 'mtm' relations do not support 'nullable'."));
|
|
45
45
|
//# sourceMappingURL=relation.schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relation.schema.js","sourceRoot":"","sources":["../../src/validators/relation.schema.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAY,CAAC,oCAAgB;AAE7B,kFAAkF;AACrE,QAAA,cAAc,GAAG,CAAC,CAAC,IAAI,CAChC,CAAC,CAAC,YAAY,CAAC;IACX,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9C,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACvC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vsrepo/prisma7-adapter",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "VSRepository adapter implementation backed by Prisma 7, translating every VSRepository operation into Prisma Client calls.",
|
|
5
5
|
"homepage": "https://github.com/jaobrabo123/VSRepoPrisma7Adapter#readme",
|
|
6
6
|
"repository": {
|