@vsrepo/prisma7-adapter 1.3.2 → 2.0.0-dev
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/CHANGELOG.md +417 -0
- package/LICENSE +20 -20
- package/README.md +303 -299
- package/README.pt-BR.md +303 -299
- package/dist/constants/provider-capabilities.constant.d.ts +17 -0
- package/dist/constants/provider-capabilities.constant.js +27 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +1 -7
- package/dist/parsers/data.parser.d.ts +3 -33
- package/dist/parsers/data.parser.js +7 -45
- package/dist/parsers/include.parser.d.ts +1 -1
- package/dist/parsers/include.parser.js +3 -7
- package/dist/parsers/order-by.parser.d.ts +1 -10
- package/dist/parsers/order-by.parser.js +3 -16
- package/dist/parsers/select.parser.d.ts +1 -1
- package/dist/parsers/select.parser.js +3 -7
- package/dist/parsers/where.parser.d.ts +4 -29
- package/dist/parsers/where.parser.js +49 -148
- package/dist/prisma7.adapter.d.ts +104 -81
- package/dist/prisma7.adapter.js +329 -362
- package/dist/resolvers/map-prisma-error.resolver.d.ts +0 -11
- package/dist/resolvers/map-prisma-error.resolver.js +48 -72
- package/dist/resolvers/merge-entities.resolver.d.ts +11 -15
- package/dist/resolvers/merge-entities.resolver.js +29 -38
- package/dist/resolvers/resolve-provider.resolver.d.ts +2 -22
- package/dist/resolvers/resolve-provider.resolver.js +10 -33
- package/dist/types/adapter-config.type.d.ts +7 -12
- package/dist/types/adapter-config.type.js +1 -3
- package/dist/types/adapter-relations.type.d.ts +2 -2
- package/dist/types/adapter-relations.type.js +1 -3
- package/dist/types/plain-object.type.js +1 -3
- package/dist/types/prisma-arg-like.type.js +1 -3
- package/dist/types/prisma-client-models.type.d.ts +4 -4
- package/dist/types/prisma-client-models.type.js +1 -3
- package/dist/types/prisma-provider.type.d.ts +1 -1
- package/dist/types/prisma-provider.type.js +1 -3
- package/dist/types/prisma-repository-like.type.d.ts +1 -1
- package/dist/types/prisma-repository-like.type.js +1 -3
- package/dist/types/prisma7-client-like.type.d.ts +1 -8
- package/dist/types/prisma7-client-like.type.js +1 -3
- package/dist/types/prisma7-orm-types.type.d.ts +2 -2
- package/dist/types/prisma7-orm-types.type.js +1 -3
- package/dist/types/relation.type.d.ts +25 -19
- package/dist/types/relation.type.js +1 -3
- package/dist/validators/is-decimal.validator.d.ts +2 -5
- package/dist/validators/is-decimal.validator.js +3 -6
- package/dist/validators/is-plain-object.validator.d.ts +1 -1
- package/dist/validators/is-plain-object.validator.js +3 -7
- package/dist/validators/validate-prisma-client.validator.d.ts +1 -14
- package/dist/validators/validate-prisma-client.validator.js +7 -24
- package/package.json +108 -91
- package/dist/index.js.map +0 -1
- package/dist/parsers/data.parser.js.map +0 -1
- package/dist/parsers/include.parser.js.map +0 -1
- package/dist/parsers/order-by.parser.js.map +0 -1
- package/dist/parsers/select.parser.js.map +0 -1
- package/dist/parsers/where.parser.js.map +0 -1
- package/dist/prisma7.adapter.js.map +0 -1
- package/dist/resolvers/map-prisma-error.resolver.js.map +0 -1
- package/dist/resolvers/merge-entities.resolver.js.map +0 -1
- package/dist/resolvers/resolve-provider.resolver.js.map +0 -1
- package/dist/types/adapter-config.type.js.map +0 -1
- package/dist/types/adapter-relations.type.js.map +0 -1
- package/dist/types/plain-object.type.js.map +0 -1
- package/dist/types/prisma-arg-like.type.js.map +0 -1
- package/dist/types/prisma-client-models.type.js.map +0 -1
- package/dist/types/prisma-provider.type.js.map +0 -1
- package/dist/types/prisma-repository-like.type.js.map +0 -1
- package/dist/types/prisma7-client-like.type.js.map +0 -1
- package/dist/types/prisma7-orm-types.type.js.map +0 -1
- package/dist/types/relation.type.js.map +0 -1
- package/dist/validators/is-decimal.validator.js.map +0 -1
- package/dist/validators/is-plain-object.validator.js.map +0 -1
- package/dist/validators/validate-adapter-config.validator.d.ts +0 -8
- package/dist/validators/validate-adapter-config.validator.js +0 -78
- package/dist/validators/validate-adapter-config.validator.js.map +0 -1
- package/dist/validators/validate-prisma-client.validator.js.map +0 -1
|
@@ -1,13 +1,2 @@
|
|
|
1
1
|
import { VSRepoAdapterError } from "vsrepo";
|
|
2
|
-
/**
|
|
3
|
-
* Converts any error caught around a Prisma Client call into a
|
|
4
|
-
* `VSRepoAdapterError`, so `VSRepoPrisma7Adapter` never lets a raw Prisma (or
|
|
5
|
-
* other) error escape. Already-wrapped errors — e.g. bubbling up from a
|
|
6
|
-
* nested adapter call, such as `save` inside `saveMany`, or a config/usage
|
|
7
|
-
* error thrown by the adapter itself (see `stripRelationFields`) — are
|
|
8
|
-
* returned as-is instead of being wrapped a second time.
|
|
9
|
-
*
|
|
10
|
-
* @param error - The raw error caught around a Prisma Client call.
|
|
11
|
-
* @param operation - Name of the adapter method that failed, used in the message.
|
|
12
|
-
*/
|
|
13
2
|
export declare function mapPrismaError(error: unknown, operation: string): VSRepoAdapterError;
|
|
@@ -1,101 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapPrismaError = mapPrismaError;
|
|
4
|
-
const vsrepo_1 = require("vsrepo");
|
|
1
|
+
import { AdapterErrorCode, VSRepoAdapterError } from "vsrepo";
|
|
5
2
|
/**
|
|
6
3
|
* Maps a Prisma `PrismaClientKnownRequestError.code` (e.g. `"P2002"`) to a
|
|
7
4
|
* stable, adapter-agnostic `AdapterErrorCode`. Only codes an application is
|
|
8
5
|
* realistically expected to react to are listed here — anything else falls
|
|
9
6
|
* back to `AdapterErrorCode.UNKNOWN` in `mapPrismaError`.
|
|
10
7
|
*
|
|
11
|
-
* @see https://www.prisma.io/docs/orm/reference/error-reference
|
|
8
|
+
* @see https://www.prisma.io/docs/orm/v7/reference/error-reference
|
|
12
9
|
*/
|
|
13
10
|
const KNOWN_REQUEST_ERROR_CODE_MAP = {
|
|
14
11
|
// Connection / engine errors (P1xxx)
|
|
15
|
-
P1000:
|
|
16
|
-
P1001:
|
|
17
|
-
P1002:
|
|
18
|
-
P1008:
|
|
19
|
-
P1010:
|
|
20
|
-
P1011:
|
|
21
|
-
P1017:
|
|
12
|
+
P1000: AdapterErrorCode.INVALID_CREDENTIALS,
|
|
13
|
+
P1001: AdapterErrorCode.CONNECTION_FAILED,
|
|
14
|
+
P1002: AdapterErrorCode.TIMEOUT,
|
|
15
|
+
P1008: AdapterErrorCode.TIMEOUT,
|
|
16
|
+
P1010: AdapterErrorCode.ACCESS_DENIED,
|
|
17
|
+
P1011: AdapterErrorCode.CONNECTION_FAILED,
|
|
18
|
+
P1017: AdapterErrorCode.CONNECTION_CLOSED,
|
|
22
19
|
// Query engine errors (P2xxx)
|
|
23
|
-
P2000:
|
|
24
|
-
P2001:
|
|
25
|
-
P2002:
|
|
26
|
-
P2003:
|
|
27
|
-
P2004:
|
|
28
|
-
P2005:
|
|
29
|
-
P2006:
|
|
30
|
-
P2007:
|
|
31
|
-
P2010:
|
|
32
|
-
P2011:
|
|
33
|
-
P2012:
|
|
34
|
-
P2014:
|
|
35
|
-
P2015:
|
|
36
|
-
P2016:
|
|
37
|
-
P2017:
|
|
38
|
-
P2018:
|
|
39
|
-
P2019:
|
|
40
|
-
P2020:
|
|
41
|
-
P2021:
|
|
42
|
-
P2022:
|
|
43
|
-
P2023:
|
|
44
|
-
P2024:
|
|
45
|
-
P2025:
|
|
46
|
-
P2026:
|
|
47
|
-
P2028:
|
|
48
|
-
P2030:
|
|
49
|
-
P2031:
|
|
50
|
-
P2033:
|
|
51
|
-
P2034:
|
|
52
|
-
P2037:
|
|
20
|
+
P2000: AdapterErrorCode.VALUE_TOO_LONG,
|
|
21
|
+
P2001: AdapterErrorCode.NOT_FOUND,
|
|
22
|
+
P2002: AdapterErrorCode.UNIQUE_CONSTRAINT_VIOLATION,
|
|
23
|
+
P2003: AdapterErrorCode.FOREIGN_KEY_VIOLATION,
|
|
24
|
+
P2004: AdapterErrorCode.CONSTRAINT_VIOLATION,
|
|
25
|
+
P2005: AdapterErrorCode.CONVERSION_ERROR,
|
|
26
|
+
P2006: AdapterErrorCode.INVALID_DATA,
|
|
27
|
+
P2007: AdapterErrorCode.INVALID_DATA,
|
|
28
|
+
P2010: AdapterErrorCode.INVALID_QUERY,
|
|
29
|
+
P2011: AdapterErrorCode.NOT_NULL_VIOLATION,
|
|
30
|
+
P2012: AdapterErrorCode.INVALID_DATA,
|
|
31
|
+
P2014: AdapterErrorCode.CONSTRAINT_VIOLATION,
|
|
32
|
+
P2015: AdapterErrorCode.NOT_FOUND,
|
|
33
|
+
P2016: AdapterErrorCode.INVALID_QUERY,
|
|
34
|
+
P2017: AdapterErrorCode.NOT_FOUND,
|
|
35
|
+
P2018: AdapterErrorCode.NOT_FOUND,
|
|
36
|
+
P2019: AdapterErrorCode.INVALID_DATA,
|
|
37
|
+
P2020: AdapterErrorCode.CONVERSION_ERROR,
|
|
38
|
+
P2021: AdapterErrorCode.TABLE_OR_COLUMN_NOT_FOUND,
|
|
39
|
+
P2022: AdapterErrorCode.TABLE_OR_COLUMN_NOT_FOUND,
|
|
40
|
+
P2023: AdapterErrorCode.CONVERSION_ERROR,
|
|
41
|
+
P2024: AdapterErrorCode.CONNECTION_POOL_EXHAUSTED,
|
|
42
|
+
P2025: AdapterErrorCode.NOT_FOUND,
|
|
43
|
+
P2026: AdapterErrorCode.NOT_SUPPORTED,
|
|
44
|
+
P2028: AdapterErrorCode.TRANSACTION_CLOSED,
|
|
45
|
+
P2030: AdapterErrorCode.NOT_SUPPORTED,
|
|
46
|
+
P2031: AdapterErrorCode.NOT_SUPPORTED,
|
|
47
|
+
P2033: AdapterErrorCode.CONVERSION_ERROR,
|
|
48
|
+
P2034: AdapterErrorCode.TRANSACTION_CONFLICT,
|
|
49
|
+
P2037: AdapterErrorCode.CONNECTION_POOL_EXHAUSTED,
|
|
53
50
|
};
|
|
54
|
-
/**
|
|
55
|
-
* Reads the Prisma error class name (`PrismaClientKnownRequestError`,
|
|
56
|
-
* `PrismaClientInitializationError`, ...) off a caught error without
|
|
57
|
-
* importing `@prisma/client` — the adapter never imports concrete Prisma
|
|
58
|
-
* types (see `Prisma7ClientLike`), so this duck-types via `error.name`
|
|
59
|
-
* instead of using `instanceof`.
|
|
60
|
-
*/
|
|
61
51
|
function prismaErrorName(error) {
|
|
62
52
|
if (!(error instanceof Error))
|
|
63
53
|
return undefined;
|
|
64
54
|
return error.name || error.constructor?.name;
|
|
65
55
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* `VSRepoAdapterError`, so `VSRepoPrisma7Adapter` never lets a raw Prisma (or
|
|
69
|
-
* other) error escape. Already-wrapped errors — e.g. bubbling up from a
|
|
70
|
-
* nested adapter call, such as `save` inside `saveMany`, or a config/usage
|
|
71
|
-
* error thrown by the adapter itself (see `stripRelationFields`) — are
|
|
72
|
-
* returned as-is instead of being wrapped a second time.
|
|
73
|
-
*
|
|
74
|
-
* @param error - The raw error caught around a Prisma Client call.
|
|
75
|
-
* @param operation - Name of the adapter method that failed, used in the message.
|
|
76
|
-
*/
|
|
77
|
-
function mapPrismaError(error, operation) {
|
|
78
|
-
if (error instanceof vsrepo_1.VSRepoAdapterError)
|
|
56
|
+
export function mapPrismaError(error, operation) {
|
|
57
|
+
if (error instanceof VSRepoAdapterError)
|
|
79
58
|
return error;
|
|
80
59
|
const name = prismaErrorName(error);
|
|
81
60
|
const prismaError = error;
|
|
82
61
|
switch (name) {
|
|
83
62
|
case "PrismaClientKnownRequestError": {
|
|
84
|
-
const code = prismaError.code
|
|
85
|
-
|
|
86
|
-
: undefined;
|
|
87
|
-
return new vsrepo_1.VSRepoAdapterError(`'${operation}' failed (Prisma code: ${prismaError.code ?? "unknown"})`, code ?? vsrepo_1.AdapterErrorCode.UNKNOWN, error);
|
|
63
|
+
const code = prismaError.code ? KNOWN_REQUEST_ERROR_CODE_MAP[prismaError.code] : undefined;
|
|
64
|
+
return new VSRepoAdapterError(`'${operation}' failed (Prisma code: ${prismaError.code ?? "unknown"})`, code ?? AdapterErrorCode.UNKNOWN, error);
|
|
88
65
|
}
|
|
89
66
|
case "PrismaClientInitializationError":
|
|
90
|
-
return new
|
|
67
|
+
return new VSRepoAdapterError(`'${operation}' failed to initialize/connect to the database`, AdapterErrorCode.CONNECTION_FAILED, error);
|
|
91
68
|
case "PrismaClientRustPanicError":
|
|
92
|
-
return new
|
|
69
|
+
return new VSRepoAdapterError(`'${operation}' failed due to an internal Prisma engine panic`, AdapterErrorCode.INTERNAL, error);
|
|
93
70
|
case "PrismaClientValidationError":
|
|
94
|
-
return new
|
|
71
|
+
return new VSRepoAdapterError(`'${operation}' received invalid data/arguments`, AdapterErrorCode.INVALID_DATA, error);
|
|
95
72
|
case "PrismaClientUnknownRequestError":
|
|
96
|
-
return new
|
|
73
|
+
return new VSRepoAdapterError(`'${operation}' failed with an unrecognized Prisma error`, AdapterErrorCode.UNKNOWN, error);
|
|
97
74
|
default:
|
|
98
|
-
return new
|
|
75
|
+
return new VSRepoAdapterError(`'${operation}' failed: ${prismaError?.message ?? "unknown error"}`, AdapterErrorCode.UNKNOWN, error);
|
|
99
76
|
}
|
|
100
77
|
}
|
|
101
|
-
//# sourceMappingURL=map-prisma-error.resolver.js.map
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
+
import { AdapterRelations } from "../types/adapter-relations.type.js";
|
|
2
|
+
import { PlainObject } from "../types/plain-object.type.js";
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
* (registro já encontrado) com `obj` (payload enviado) — réplica exata do
|
|
4
|
-
* comportamento do `merge` da v1: ele só busca o registro e devolve o merge,
|
|
5
|
-
* quem decide o que fazer com o resultado (ex: chamar `save` depois) é quem
|
|
6
|
-
* chamou.
|
|
4
|
+
* Merges `obj` into `result` WITHOUT mutating either of them.
|
|
7
5
|
*
|
|
8
|
-
*
|
|
9
|
-
* `relations
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
6
|
+
* - Fields of `obj` that are `undefined` are ignored (they never erase a value).
|
|
7
|
+
* - Only the fields configured in `relations` are merged: a to-one relation
|
|
8
|
+
* has its fields merged with the existing related object (`null` clears it),
|
|
9
|
+
* and a to-many relation is merged item by item, matching them by the
|
|
10
|
+
* relation's `pk`.
|
|
11
|
+
* - Every other value — including objects and arrays that are not configured
|
|
12
|
+
* as relations, and the nested values of a merged related object — is
|
|
13
|
+
* replaced as a whole, never deep merged nor concatenated.
|
|
16
14
|
*/
|
|
17
|
-
import { AdapterRelations } from "../types/adapter-relations.type";
|
|
18
|
-
import { PlainObject } from "../types/plain-object.type";
|
|
19
15
|
export declare function mergeEntities<T extends PlainObject, U extends PlainObject>(result: T, obj: U, relations?: AdapterRelations<T>): U & T;
|
|
@@ -1,27 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { isPlainObject } from "../validators/is-plain-object.validator.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* quem decide o que fazer com o resultado (ex: chamar `save` depois) é quem
|
|
7
|
-
* chamou.
|
|
8
|
-
*
|
|
9
|
-
* Sem `relations`, é um deep merge padrão (arrays são concatenados). Com
|
|
10
|
-
* `relations`:
|
|
11
|
-
* - to-one (`oto`/`mto`) recebe merge direto (ou vira `null` se `obj` mandar
|
|
12
|
-
* `null` explicitamente)
|
|
13
|
-
* - to-many (`otm`/`mtm`) casa os itens de `result[key]` com os de `obj[key]`
|
|
14
|
-
* pela `pk` configurada: item com PK que bate -> merge entre os dois; item
|
|
15
|
-
* sem correspondente -> apenas adicionado. Itens existentes que não
|
|
16
|
-
* aparecem em `obj[key]` são mantidos (merge nunca remove nada).
|
|
3
|
+
* Shallow-merges `source` into a copy of `target`, skipping `undefined` values
|
|
4
|
+
* so they never erase an existing field. Values (objects, arrays, `Date`,
|
|
5
|
+
* `Decimal`...) are assigned by reference, never cloned nor merged.
|
|
17
6
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
function assignDefined(target, source) {
|
|
8
|
+
const merged = { ...target };
|
|
9
|
+
for (const [key, value] of Object.entries(source)) {
|
|
10
|
+
if (value !== undefined)
|
|
11
|
+
merged[key] = value;
|
|
12
|
+
}
|
|
13
|
+
return merged;
|
|
14
|
+
}
|
|
25
15
|
function mergeToManyRelation(target, source, relationPk) {
|
|
26
16
|
const targetMap = new Map();
|
|
27
17
|
const targetWithoutPk = [];
|
|
@@ -40,32 +30,34 @@ function mergeToManyRelation(target, source, relationPk) {
|
|
|
40
30
|
continue;
|
|
41
31
|
}
|
|
42
32
|
const targetItem = targetMap.get(item[relationPk]);
|
|
43
|
-
targetMap.set(item[relationPk], targetItem ? (
|
|
33
|
+
targetMap.set(item[relationPk], targetItem ? assignDefined(targetItem, item) : item);
|
|
44
34
|
}
|
|
45
35
|
return [...targetMap.values(), ...targetWithoutPk, ...sourceWithoutPk];
|
|
46
36
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Merges `obj` into `result` WITHOUT mutating either of them.
|
|
39
|
+
*
|
|
40
|
+
* - Fields of `obj` that are `undefined` are ignored (they never erase a value).
|
|
41
|
+
* - Only the fields configured in `relations` are merged: a to-one relation
|
|
42
|
+
* has its fields merged with the existing related object (`null` clears it),
|
|
43
|
+
* and a to-many relation is merged item by item, matching them by the
|
|
44
|
+
* relation's `pk`.
|
|
45
|
+
* - Every other value — including objects and arrays that are not configured
|
|
46
|
+
* as relations, and the nested values of a merged related object — is
|
|
47
|
+
* replaced as a whole, never deep merged nor concatenated.
|
|
48
|
+
*/
|
|
49
|
+
export function mergeEntities(result, obj, relations) {
|
|
58
50
|
const merged = { ...result };
|
|
59
51
|
for (const [key, field] of Object.entries(obj)) {
|
|
60
52
|
if (field === undefined)
|
|
61
53
|
continue;
|
|
62
|
-
const relation = relations[key];
|
|
54
|
+
const relation = relations?.[key];
|
|
63
55
|
if (!relation) {
|
|
64
56
|
merged[key] = field;
|
|
65
57
|
continue;
|
|
66
58
|
}
|
|
67
|
-
if ((relation.mode === "oto" || relation.mode === "mto") &&
|
|
68
|
-
merged[key] = field === null ? null : (
|
|
59
|
+
if ((relation.mode === "oto" || relation.mode === "mto") && isPlainObject(merged[key])) {
|
|
60
|
+
merged[key] = field === null ? null : assignDefined(merged[key], field);
|
|
69
61
|
continue;
|
|
70
62
|
}
|
|
71
63
|
if ((relation.mode === "mtm" || relation.mode === "otm") && Array.isArray(merged[key])) {
|
|
@@ -76,4 +68,3 @@ function mergeEntities(result, obj, relations) {
|
|
|
76
68
|
}
|
|
77
69
|
return merged;
|
|
78
70
|
}
|
|
79
|
-
//# sourceMappingURL=merge-entities.resolver.js.map
|
|
@@ -1,24 +1,4 @@
|
|
|
1
|
-
import { PrismaProvider } from "../types/prisma-provider.type";
|
|
1
|
+
import { PrismaProvider } from "../types/prisma-provider.type.js";
|
|
2
2
|
export declare const PRISMA_PROVIDERS: string[];
|
|
3
3
|
export declare const PrismaProvidersSet: Set<string>;
|
|
4
|
-
|
|
5
|
-
* Resolves the Prisma datasource provider of a Prisma Client, in the following
|
|
6
|
-
* precedence order:
|
|
7
|
-
*
|
|
8
|
-
* 1. `override` — the `provider` explicitly configured by the user in the
|
|
9
|
-
* adapter config (wins over everything);
|
|
10
|
-
* 2. `prisma._engineConfig?.activeProvider` — the schema provider baked into
|
|
11
|
-
* the generated client at compile time (e.g. `"postgresql"` from
|
|
12
|
-
* `datasource db { provider = "postgresql" }`). This is what Prisma itself
|
|
13
|
-
* uses internally to select the query compiler and validate the driver
|
|
14
|
-
* adapter, so it is the most reliable signal available — even though it is
|
|
15
|
-
* a private/underscored API, with no semver guarantee;
|
|
16
|
-
* 3. `prisma._engineConfig?.adapter?.provider` — the runtime driver adapter's
|
|
17
|
-
* declared provider (e.g. `"postgres"` for `PrismaPg`), as a secondary
|
|
18
|
-
* source when `activeProvider` isn't present.
|
|
19
|
-
*
|
|
20
|
-
* Returns `undefined` when none of the sources yield a known provider — the
|
|
21
|
-
* caller decides what to do with that (e.g. `getPlaceholder` throws a
|
|
22
|
-
* `NOT_SUPPORTED` error only when it actually needs to know the provider).
|
|
23
|
-
*/
|
|
24
|
-
export declare function resolveProvider(prisma: unknown, override?: PrismaProvider): PrismaProvider | undefined;
|
|
4
|
+
export declare function resolveProvider(prisma: unknown, override?: PrismaProvider): PrismaProvider;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.resolveProvider = resolveProvider;
|
|
5
|
-
exports.PRISMA_PROVIDERS = ["postgresql", "cockroachdb", "mysql", "sqlite", "sqlserver"];
|
|
6
|
-
exports.PrismaProvidersSet = new Set(exports.PRISMA_PROVIDERS);
|
|
1
|
+
import { AdapterErrorCode, VSRepoAdapterError } from "vsrepo";
|
|
2
|
+
export const PRISMA_PROVIDERS = ["postgresql", "cockroachdb", "mysql", "sqlite", "sqlserver"];
|
|
3
|
+
export const PrismaProvidersSet = new Set(PRISMA_PROVIDERS);
|
|
7
4
|
const ADAPTER_PROVIDER_TO_PRISMA_PROVIDER = {
|
|
8
5
|
postgres: "postgresql",
|
|
9
6
|
mysql: "mysql",
|
|
@@ -11,41 +8,21 @@ const ADAPTER_PROVIDER_TO_PRISMA_PROVIDER = {
|
|
|
11
8
|
sqlserver: "sqlserver",
|
|
12
9
|
};
|
|
13
10
|
function isPrismaProvider(value) {
|
|
14
|
-
return
|
|
11
|
+
return PrismaProvidersSet.has(value);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
* Resolves the Prisma datasource provider of a Prisma Client, in the following
|
|
18
|
-
* precedence order:
|
|
19
|
-
*
|
|
20
|
-
* 1. `override` — the `provider` explicitly configured by the user in the
|
|
21
|
-
* adapter config (wins over everything);
|
|
22
|
-
* 2. `prisma._engineConfig?.activeProvider` — the schema provider baked into
|
|
23
|
-
* the generated client at compile time (e.g. `"postgresql"` from
|
|
24
|
-
* `datasource db { provider = "postgresql" }`). This is what Prisma itself
|
|
25
|
-
* uses internally to select the query compiler and validate the driver
|
|
26
|
-
* adapter, so it is the most reliable signal available — even though it is
|
|
27
|
-
* a private/underscored API, with no semver guarantee;
|
|
28
|
-
* 3. `prisma._engineConfig?.adapter?.provider` — the runtime driver adapter's
|
|
29
|
-
* declared provider (e.g. `"postgres"` for `PrismaPg`), as a secondary
|
|
30
|
-
* source when `activeProvider` isn't present.
|
|
31
|
-
*
|
|
32
|
-
* Returns `undefined` when none of the sources yield a known provider — the
|
|
33
|
-
* caller decides what to do with that (e.g. `getPlaceholder` throws a
|
|
34
|
-
* `NOT_SUPPORTED` error only when it actually needs to know the provider).
|
|
35
|
-
*/
|
|
36
|
-
function resolveProvider(prisma, override) {
|
|
13
|
+
export function resolveProvider(prisma, override) {
|
|
37
14
|
if (override !== undefined) {
|
|
38
15
|
return override;
|
|
39
16
|
}
|
|
40
17
|
const engineConfig = prisma._engineConfig;
|
|
41
|
-
if (isPrismaProvider(engineConfig
|
|
18
|
+
if (typeof engineConfig?.activeProvider === "string" && isPrismaProvider(engineConfig.activeProvider)) {
|
|
42
19
|
return engineConfig.activeProvider;
|
|
43
20
|
}
|
|
44
21
|
const adapterProvider = engineConfig?.adapter?.provider;
|
|
45
|
-
if (typeof adapterProvider === "string" &&
|
|
46
|
-
adapterProvider in ADAPTER_PROVIDER_TO_PRISMA_PROVIDER) {
|
|
22
|
+
if (typeof adapterProvider === "string" && adapterProvider in ADAPTER_PROVIDER_TO_PRISMA_PROVIDER) {
|
|
47
23
|
return ADAPTER_PROVIDER_TO_PRISMA_PROVIDER[adapterProvider];
|
|
48
24
|
}
|
|
49
|
-
|
|
25
|
+
throw new VSRepoAdapterError(`Could not detect the Prisma datasource provider from the provided client. ` +
|
|
26
|
+
`Set the 'provider' option in the adapter config explicitly ` +
|
|
27
|
+
`(one of: ${PRISMA_PROVIDERS.join(", ")}).`, AdapterErrorCode.NOT_SUPPORTED, null);
|
|
50
28
|
}
|
|
51
|
-
//# sourceMappingURL=resolve-provider.resolver.js.map
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { VSLogLevel } from "vsrepo";
|
|
2
|
-
import { AdapterRelations } from "./adapter-relations.type";
|
|
3
|
-
import { Prisma7ClientLike } from "./prisma7-client-like.type";
|
|
4
|
-
import { PrismaClientModels } from "./prisma-client-models.type";
|
|
5
|
-
import { PrismaProvider } from "./prisma-provider.type";
|
|
2
|
+
import { AdapterRelations } from "./adapter-relations.type.js";
|
|
3
|
+
import { Prisma7ClientLike } from "./prisma7-client-like.type.js";
|
|
4
|
+
import { PrismaClientModels } from "./prisma-client-models.type.js";
|
|
5
|
+
import { PrismaProvider } from "./prisma-provider.type.js";
|
|
6
6
|
/**
|
|
7
7
|
* Configuration accepted by `VSRepoPrisma7Adapter`'s constructor, as the
|
|
8
8
|
* second parameter.
|
|
9
9
|
*
|
|
10
10
|
* @publicApi
|
|
11
11
|
*/
|
|
12
|
-
export interface
|
|
12
|
+
export interface Prisma7AdapterConfig<T = any, K extends Prisma7ClientLike = Prisma7ClientLike> {
|
|
13
13
|
/** Name of the Prisma Client model/delegate (e.g. `"user"`, as in `prisma.user`). */
|
|
14
|
-
|
|
14
|
+
modelName: [PrismaClientModels<K>] extends [never] ? string : PrismaClientModels<K>;
|
|
15
15
|
/** Name of the entity's primary key field (e.g. `"id"`). */
|
|
16
16
|
pkName: keyof T;
|
|
17
17
|
/**
|
|
18
|
-
* The entity's relation configuration, needed by the `create`/`update
|
|
18
|
+
* The entity's relation configuration, needed by the `create`/`update`
|
|
19
19
|
* parsers to correctly resolve relation fields (see `Relation`/`AdapterRelations`).
|
|
20
20
|
* Optional: without it, relation fields are passed through to Prisma as-is (raw).
|
|
21
21
|
*/
|
|
@@ -30,9 +30,4 @@ export interface VSRepoPrisma7AdapterConfig<T = any, K extends Prisma7ClientLike
|
|
|
30
30
|
provider?: PrismaProvider;
|
|
31
31
|
/** Minimum log level for the adapter's internal `VSLogger`. @default VSLogLevel.WARN */
|
|
32
32
|
logLevel?: VSLogLevel;
|
|
33
|
-
/**
|
|
34
|
-
* Duration (in ms) above which a finished operation is logged as `WARN`, flagging a potentially slow query, instead of the usual
|
|
35
|
-
* `DEBUG` line. Pass `false` to disable slow-operation warnings entirely (every operation is then only ever logged at `DEBUG`); `true` (or omitting the field) uses the default of 300ms.
|
|
36
|
-
*/
|
|
37
|
-
logSlowThresholdMs?: number | boolean;
|
|
38
33
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RelationKeys } from "vsrepo";
|
|
2
|
-
import { Relation } from "./relation.type";
|
|
2
|
+
import { Relation } from "./relation.type.js";
|
|
3
3
|
/**
|
|
4
|
-
* Relation configuration for entity `T`, used by the `create`/`update
|
|
4
|
+
* Relation configuration for entity `T`, used by the `create`/`update`
|
|
5
5
|
* parsers to resolve relation fields according to the v1 behavior (see
|
|
6
6
|
* `Relation`).
|
|
7
7
|
*
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Prisma7ClientLike } from "./prisma7-client-like.type";
|
|
1
|
+
import { Prisma7ClientLike } from "./prisma7-client-like.type.js";
|
|
2
2
|
/**
|
|
3
3
|
* Extracts the model/delegate names from a Prisma Client instance type,
|
|
4
4
|
* excluding all built-in `$`-prefixed methods (`$connect`, `$transaction`, etc.).
|
|
5
5
|
*
|
|
6
6
|
* The resulting union contains only the keys that represent actual Prisma model
|
|
7
7
|
* delegates (e.g. `"user"`, `"post"`, `"comment"`), enabling type-safe
|
|
8
|
-
* auto-complete when configuring `
|
|
8
|
+
* auto-complete when configuring `modelName` in `Prisma7AdapterConfig`.
|
|
9
9
|
*
|
|
10
10
|
* @template T - A Prisma Client type that extends `Prisma7ClientLike`.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
14
|
-
* import { PrismaClient } from "
|
|
14
|
+
* import { PrismaClient } from "../generated/prisma/client";
|
|
15
15
|
*
|
|
16
16
|
* // Resolves to: "user" | "post" | "comment" | ...
|
|
17
17
|
* type Models = PrismaClientModels<PrismaClient>;
|
|
@@ -19,4 +19,4 @@ import { Prisma7ClientLike } from "./prisma7-client-like.type";
|
|
|
19
19
|
*
|
|
20
20
|
* @publicApi
|
|
21
21
|
*/
|
|
22
|
-
export type PrismaClientModels<T extends Prisma7ClientLike> = Exclude<keyof T, "$connect" | "$disconnect" | "$executeRaw" | "$executeRawUnsafe" | "$extends" | "$on" | "$queryRaw" | "$queryRawUnsafe" | "$transaction" | symbol>;
|
|
22
|
+
export type PrismaClientModels<T extends Prisma7ClientLike> = Exclude<keyof T, "$connect" | "$disconnect" | "$executeRaw" | "$executeRawUnsafe" | "$extends" | "$on" | "$queryRaw" | "$queryRawUnsafe" | "$transaction" | symbol | number>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrismaArgLike } from "./prisma-arg-like.type";
|
|
1
|
+
import { PrismaArgLike } from "./prisma-arg-like.type.js";
|
|
2
2
|
type AnyFn = (arg: PrismaArgLike) => Promise<any>;
|
|
3
3
|
/** `count` do Prisma resolve pra um `number` (na forma simples, sem `select` de agregação). */
|
|
4
4
|
type CountFn = (arg: PrismaArgLike) => Promise<number>;
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* adapter for raw queries (`@QueryMethod`) and for telling a root client
|
|
4
|
-
* apart from an active transaction client.
|
|
5
|
-
*
|
|
6
|
-
* `$on` is only present on the root `PrismaClient` — Prisma's interactive
|
|
7
|
-
* transaction client doesn't expose it — so the adapter uses it to detect
|
|
8
|
-
* whether a `db` passed in `AdapterMethodOptions` is already a transaction
|
|
9
|
-
* (see `Prisma7OrmTypes`).
|
|
2
|
+
* Duck-typing for a PrismaClient.
|
|
10
3
|
*
|
|
11
4
|
* @publicApi
|
|
12
5
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Prisma7ClientLike } from "./prisma7-client-like.type";
|
|
1
|
+
import { Prisma7ClientLike } from "./prisma7-client-like.type.js";
|
|
2
2
|
/**
|
|
3
3
|
* Helper used to type a `VSRepository`'s `OrmTypes` generic when using
|
|
4
4
|
* `VSRepoPrisma7Adapter`, tying the repository's `getDbClient()`/`transaction()`
|
|
@@ -6,7 +6,7 @@ import { Prisma7ClientLike } from "./prisma7-client-like.type";
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
9
|
-
* type MyOrmTypes = Prisma7OrmTypes<PrismaClient
|
|
9
|
+
* type MyOrmTypes = Prisma7OrmTypes<PrismaClient>;
|
|
10
10
|
*
|
|
11
11
|
* class UserRepository extends VSRepository<User, string, MyOrmTypes> { ... }
|
|
12
12
|
* ```
|
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configuration of a single relation field
|
|
3
|
-
* VSRepository used.
|
|
4
|
-
*
|
|
5
|
-
* - `mode`: cardinality of the relation from the point of view of the entity
|
|
6
|
-
* that owns the field (`oto` = one-to-one, `mto` = many-to-one,
|
|
7
|
-
* `otm` = one-to-many, `mtm` = many-to-many).
|
|
8
|
-
* - `restriction`: how `save`/`update`/`upsert` handle to-many relations
|
|
9
|
-
* (`otm`/`mtm`) and to-one relations pointing to an already-existing record
|
|
10
|
-
* (matched by `pk`) — `"add"` only creates/connects the items that were
|
|
11
|
-
* sent (upsert per item), `"set"` also removes/disconnects whatever wasn't
|
|
12
|
-
* sent.
|
|
13
|
-
* - `pk`: name of the field used as the identifier of the related record,
|
|
14
|
-
* used to decide between `create` (no pk in the payload) and
|
|
15
|
-
* `connectOrCreate`/`upsert` (pk present).
|
|
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`).
|
|
2
|
+
* Configuration of a single relation field.
|
|
21
3
|
*
|
|
22
4
|
* @publicApi
|
|
23
5
|
*/
|
|
24
6
|
export interface Relation<T = any> {
|
|
7
|
+
/**
|
|
8
|
+
* Cardinality of the relation from the point of view of the entity
|
|
9
|
+
* that owns the field (`oto` = one-to-one, `mto` = many-to-one,
|
|
10
|
+
* `otm` = one-to-many, `mtm` = many-to-many).
|
|
11
|
+
*/
|
|
25
12
|
mode: "otm" | "mtm" | "mto" | "oto";
|
|
13
|
+
/**
|
|
14
|
+
* How `save`/`update`/`upsert` handle to-many relations
|
|
15
|
+
* (`otm`/`mtm`) and to-one relations pointing to an already-existing record
|
|
16
|
+
* (matched by `pk`) — `"add"` only creates/connects the items that were
|
|
17
|
+
* sent (upsert per item), `"set"` also removes/disconnects whatever wasn't
|
|
18
|
+
* sent.
|
|
19
|
+
*/
|
|
26
20
|
restriction: "set" | "add";
|
|
21
|
+
/**
|
|
22
|
+
* Name of the field used as the identifier of the related record,
|
|
23
|
+
* used to decide between `create` (no pk in the payload) and
|
|
24
|
+
* `connectOrCreate`/`upsert` (pk present).
|
|
25
|
+
*/
|
|
27
26
|
pk: keyof T;
|
|
27
|
+
/**
|
|
28
|
+
* For `oto`/`mto` relations, whether the field accepts being set
|
|
29
|
+
* to `null`. When `true`, sending `null` on update resolves to `delete`
|
|
30
|
+
* (`oto` + `restriction: "set"`) or `disconnect` (`oto` + `restriction:
|
|
31
|
+
* "add"`, and `mto`). When `false`/omitted, sending `null` for a to-one
|
|
32
|
+
* relation throws a `VSRepoAdapterError` (code `INVALID_DATA`).
|
|
33
|
+
*/
|
|
28
34
|
nullable?: boolean;
|
|
29
35
|
}
|