@vsrepo/prisma7-adapter 1.1.0 → 1.1.1
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/dist/prisma7.adapter.d.ts +2 -1
- package/dist/prisma7.adapter.js +2 -0
- package/dist/validators/adapter-config.schema.d.ts +10 -2
- package/dist/validators/relation.schema.d.ts +10 -2
- package/dist/validators/relation.schema.js +2 -2
- package/dist/validators/validate-prisma-client.validator.d.ts +14 -0
- package/dist/validators/validate-prisma-client.validator.js +27 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AdapterMethodOptions, AdapterQueryOptions, CountResult, DeepPartial, NumericKeys, VSRepoAdapter, VSRepoWhere } from "vsrepo";
|
|
2
2
|
import { VSRepoPrisma7AdapterConfig } from "./types/adapter-config.type";
|
|
3
|
+
import { Prisma7ClientLike } from "./types/prisma7-client-like.type";
|
|
3
4
|
/**
|
|
4
5
|
* `VSRepoAdapter` implementation for Prisma 7. Translates every method of the
|
|
5
6
|
* adapter contract into Prisma Client calls, resolving `VSRepoWhere`/`Ordering`/
|
|
@@ -23,7 +24,7 @@ export declare class VSRepoPrisma7Adapter<T> extends VSRepoAdapter<T> {
|
|
|
23
24
|
private readonly pkName;
|
|
24
25
|
private readonly relations?;
|
|
25
26
|
private readonly logger;
|
|
26
|
-
constructor(prisma:
|
|
27
|
+
constructor(prisma: Prisma7ClientLike, config: VSRepoPrisma7AdapterConfig<T>);
|
|
27
28
|
private getPrismaRepository;
|
|
28
29
|
/** Resolves the "read" part of a Prisma arg: select/include/orderBy/pagination. */
|
|
29
30
|
private resolveReadArg;
|
package/dist/prisma7.adapter.js
CHANGED
|
@@ -10,6 +10,7 @@ const data_parser_1 = require("./parsers/data.parser");
|
|
|
10
10
|
const merge_entities_resolver_1 = require("./resolvers/merge-entities.resolver");
|
|
11
11
|
const map_prisma_error_resolver_1 = require("./resolvers/map-prisma-error.resolver");
|
|
12
12
|
const validate_adapter_config_validator_1 = require("./validators/validate-adapter-config.validator");
|
|
13
|
+
const validate_prisma_client_validator_1 = require("./validators/validate-prisma-client.validator");
|
|
13
14
|
/**
|
|
14
15
|
* `VSRepoAdapter` implementation for Prisma 7. Translates every method of the
|
|
15
16
|
* adapter contract into Prisma Client calls, resolving `VSRepoWhere`/`Ordering`/
|
|
@@ -37,6 +38,7 @@ class VSRepoPrisma7Adapter extends vsrepo_1.VSRepoAdapter {
|
|
|
37
38
|
super();
|
|
38
39
|
this.prisma = prisma;
|
|
39
40
|
const validated = (0, validate_adapter_config_validator_1.validateAdapterConfig)(config);
|
|
41
|
+
(0, validate_prisma_client_validator_1.validatePrismaClient)(prisma, validated.tableName);
|
|
40
42
|
this.tableName = validated.tableName;
|
|
41
43
|
this.pkName = validated.pkName;
|
|
42
44
|
this.relations = validated.relations;
|
|
@@ -3,12 +3,20 @@ import { VSLogLevel } from "vsrepo";
|
|
|
3
3
|
export declare const adapterConfigSchema: v.ObjectSchema<{
|
|
4
4
|
readonly tableName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
5
5
|
readonly pkName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
6
|
-
readonly relations: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.StrictObjectSchema<{
|
|
6
|
+
readonly relations: v.OptionalSchema<v.RecordSchema<v.StringSchema<undefined>, v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
7
7
|
readonly mode: v.PicklistSchema<["otm", "mtm", "mto", "oto"], undefined>;
|
|
8
8
|
readonly restriction: v.PicklistSchema<["set", "add"], undefined>;
|
|
9
9
|
readonly pk: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
10
10
|
readonly nullable: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
11
|
-
}, undefined>,
|
|
11
|
+
}, undefined>, v.PartialCheckAction<{
|
|
12
|
+
mode: "mtm" | "mto" | "otm" | "oto";
|
|
13
|
+
restriction: "add" | "set";
|
|
14
|
+
pk: string;
|
|
15
|
+
nullable?: boolean | undefined;
|
|
16
|
+
}, readonly [readonly ["nullable"], readonly ["mode"]], {
|
|
17
|
+
mode: "mtm" | "mto" | "otm" | "oto";
|
|
18
|
+
nullable?: boolean | undefined;
|
|
19
|
+
}, "'nullable: true' is only valid for 'mto' relations; 'otm', 'mtm' and 'oto' relations do not support 'nullable'.">]>, undefined>, undefined>;
|
|
12
20
|
readonly logLevel: v.OptionalSchema<v.EnumSchema<typeof VSLogLevel, undefined>, undefined>;
|
|
13
21
|
readonly logSlowThresholdMs: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.GtValueAction<number, 0, undefined>]>, undefined>;
|
|
14
22
|
}, undefined>;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
2
|
/** Espelha o shape de `Relation`, incluindo os dois nomes de `nullable` da v1. */
|
|
3
|
-
export declare const relationSchema: v.StrictObjectSchema<{
|
|
3
|
+
export declare const relationSchema: v.SchemaWithPipe<readonly [v.StrictObjectSchema<{
|
|
4
4
|
readonly mode: v.PicklistSchema<["otm", "mtm", "mto", "oto"], undefined>;
|
|
5
5
|
readonly restriction: v.PicklistSchema<["set", "add"], undefined>;
|
|
6
6
|
readonly pk: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
7
7
|
readonly nullable: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
8
|
-
}, undefined
|
|
8
|
+
}, undefined>, v.PartialCheckAction<{
|
|
9
|
+
mode: "mtm" | "mto" | "otm" | "oto";
|
|
10
|
+
restriction: "add" | "set";
|
|
11
|
+
pk: string;
|
|
12
|
+
nullable?: boolean | undefined;
|
|
13
|
+
}, readonly [readonly ["nullable"], readonly ["mode"]], {
|
|
14
|
+
mode: "mtm" | "mto" | "otm" | "oto";
|
|
15
|
+
nullable?: boolean | undefined;
|
|
16
|
+
}, "'nullable: true' is only valid for 'mto' relations; 'otm', 'mtm' and 'oto' relations do not support 'nullable'.">]>;
|
|
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.relationSchema = void 0;
|
|
37
37
|
const v = __importStar(require("valibot"));
|
|
38
38
|
/** Espelha o shape de `Relation`, incluindo os dois nomes de `nullable` da v1. */
|
|
39
|
-
exports.relationSchema = v.strictObject({
|
|
39
|
+
exports.relationSchema = v.pipe(v.strictObject({
|
|
40
40
|
mode: v.picklist(["otm", "mtm", "mto", "oto"]),
|
|
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
|
-
});
|
|
44
|
+
}), v.partialCheck([["nullable"], ["mode"]], input => !(input.nullable === true && input.mode !== "mto"), "'nullable: true' is only valid for 'mto' relations; 'otm', 'mtm' and 'oto' relations do not support 'nullable'."));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Valida o client Prisma passado como primeiro argumento do construtor do
|
|
3
|
+
* `VSRepoPrisma7Adapter`. Roda depois da config já ter sido validada (usa o
|
|
4
|
+
* `tableName` validado), e falha cedo — com um `VSRepoAdapterError` claro —
|
|
5
|
+
* em vez de deixar o adapter quebrar mais tarde, na primeira query, com um
|
|
6
|
+
* erro genérico de runtime (`Cannot read properties of undefined`, etc.):
|
|
7
|
+
*
|
|
8
|
+
* - `prisma` não pode ser `null`/`undefined` (code `MISSING_DB_CLIENT`);
|
|
9
|
+
* - `prisma[tableName]` precisa existir como delegate (ex. `prisma.user`
|
|
10
|
+
* para `tableName: "user"`) (code `MODEL_NOT_FOUND`), pegando erros de
|
|
11
|
+
* digitação em `tableName` — ou um `tableName` que não corresponde a
|
|
12
|
+
* nenhum model do schema Prisma — no construtor, não numa query.
|
|
13
|
+
*/
|
|
14
|
+
export declare function validatePrismaClient(prisma: unknown, tableName: string): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePrismaClient = validatePrismaClient;
|
|
4
|
+
const vsrepo_1 = require("vsrepo");
|
|
5
|
+
/**
|
|
6
|
+
* Valida o client Prisma passado como primeiro argumento do construtor do
|
|
7
|
+
* `VSRepoPrisma7Adapter`. Roda depois da config já ter sido validada (usa o
|
|
8
|
+
* `tableName` validado), e falha cedo — com um `VSRepoAdapterError` claro —
|
|
9
|
+
* em vez de deixar o adapter quebrar mais tarde, na primeira query, com um
|
|
10
|
+
* erro genérico de runtime (`Cannot read properties of undefined`, etc.):
|
|
11
|
+
*
|
|
12
|
+
* - `prisma` não pode ser `null`/`undefined` (code `MISSING_DB_CLIENT`);
|
|
13
|
+
* - `prisma[tableName]` precisa existir como delegate (ex. `prisma.user`
|
|
14
|
+
* para `tableName: "user"`) (code `MODEL_NOT_FOUND`), pegando erros de
|
|
15
|
+
* digitação em `tableName` — ou um `tableName` que não corresponde a
|
|
16
|
+
* nenhum model do schema Prisma — no construtor, não numa query.
|
|
17
|
+
*/
|
|
18
|
+
function validatePrismaClient(prisma, tableName) {
|
|
19
|
+
if (prisma === null || prisma === undefined) {
|
|
20
|
+
throw new vsrepo_1.VSRepoAdapterError("Missing Prisma client: the first constructor argument (prisma) is null/undefined.", vsrepo_1.AdapterErrorCode.MISSING_DB_CLIENT, null);
|
|
21
|
+
}
|
|
22
|
+
const delegate = prisma[tableName];
|
|
23
|
+
if (typeof delegate !== "object" || delegate === null) {
|
|
24
|
+
throw new vsrepo_1.VSRepoAdapterError(`Invalid constructor config (tableName): no delegate found for '${tableName}' on the provided Prisma client ` +
|
|
25
|
+
`(expected 'prisma.${tableName}' to exist — check that '${tableName}' matches a model name generated by Prisma).`, vsrepo_1.AdapterErrorCode.MODEL_NOT_FOUND, null);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vsrepo/prisma7-adapter",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
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": {
|