@vsrepo/prisma7-adapter 1.0.0
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/LICENSE +21 -0
- package/README.md +233 -0
- package/README.pt-BR.md +233 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/parsers/data.parser.d.ts +34 -0
- package/dist/parsers/data.parser.js +134 -0
- package/dist/parsers/include.parser.d.ts +3 -0
- package/dist/parsers/include.parser.js +16 -0
- package/dist/parsers/order-by.parser.d.ts +15 -0
- package/dist/parsers/order-by.parser.js +38 -0
- package/dist/parsers/select.parser.d.ts +3 -0
- package/dist/parsers/select.parser.js +16 -0
- package/dist/parsers/where.parser.d.ts +31 -0
- package/dist/parsers/where.parser.js +187 -0
- package/dist/prisma7.adapter.d.ts +125 -0
- package/dist/prisma7.adapter.js +505 -0
- package/dist/resolvers/map-prisma-error.resolver.d.ts +13 -0
- package/dist/resolvers/map-prisma-error.resolver.js +100 -0
- package/dist/resolvers/merge-entities.resolver.d.ts +19 -0
- package/dist/resolvers/merge-entities.resolver.js +73 -0
- package/dist/types/adapter-config.type.d.ts +22 -0
- package/dist/types/adapter-config.type.js +2 -0
- package/dist/types/adapter-relations.type.d.ts +16 -0
- package/dist/types/adapter-relations.type.js +2 -0
- package/dist/types/plain-object.type.d.ts +1 -0
- package/dist/types/plain-object.type.js +2 -0
- package/dist/types/prisma-arg-like.type.d.ts +14 -0
- package/dist/types/prisma-arg-like.type.js +2 -0
- package/dist/types/prisma-repository-like.type.d.ts +20 -0
- package/dist/types/prisma-repository-like.type.js +2 -0
- package/dist/types/prisma7-client-like.type.d.ts +19 -0
- package/dist/types/prisma7-client-like.type.js +2 -0
- package/dist/types/prisma7-orm-types.type.d.ts +19 -0
- package/dist/types/prisma7-orm-types.type.js +2 -0
- package/dist/types/relation.type.d.ts +26 -0
- package/dist/types/relation.type.js +2 -0
- package/dist/validators/adapter-config.schema.d.ts +13 -0
- package/dist/validators/adapter-config.schema.js +45 -0
- package/dist/validators/is-decimal.validator.d.ts +5 -0
- package/dist/validators/is-decimal.validator.js +10 -0
- package/dist/validators/is-plain-object.validator.d.ts +2 -0
- package/dist/validators/is-plain-object.validator.js +11 -0
- package/dist/validators/relation.schema.d.ts +8 -0
- package/dist/validators/relation.schema.js +44 -0
- package/dist/validators/validate-adapter-config.validator.d.ts +8 -0
- package/dist/validators/validate-adapter-config.validator.js +54 -0
- package/package.json +84 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Faz o merge profundo, EM MEMÓRIA (sem persistir nada no banco), de `result`
|
|
4
|
+
* (registro já encontrado) com `obj` (payload enviado) — réplica exata do
|
|
5
|
+
* comportamento do `merge` da v1: ele só busca o registro e devolve o merge,
|
|
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).
|
|
17
|
+
*/
|
|
18
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
19
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.mergeEntities = mergeEntities;
|
|
23
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
24
|
+
const is_plain_object_validator_1 = require("../validators/is-plain-object.validator");
|
|
25
|
+
function mergeToManyRelation(target, source, relationPk) {
|
|
26
|
+
const targetMap = new Map();
|
|
27
|
+
const targetWithoutPk = [];
|
|
28
|
+
for (const item of target) {
|
|
29
|
+
if (item[relationPk] !== undefined) {
|
|
30
|
+
targetMap.set(item[relationPk], item);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
targetWithoutPk.push(item);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const sourceWithoutPk = [];
|
|
37
|
+
for (const item of source) {
|
|
38
|
+
if (item[relationPk] === undefined) {
|
|
39
|
+
sourceWithoutPk.push(item);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const targetItem = targetMap.get(item[relationPk]);
|
|
43
|
+
targetMap.set(item[relationPk], targetItem ? (0, deepmerge_1.default)(targetItem, item) : item);
|
|
44
|
+
}
|
|
45
|
+
return [...targetMap.values(), ...targetWithoutPk, ...sourceWithoutPk];
|
|
46
|
+
}
|
|
47
|
+
function mergeEntities(result, obj, relations) {
|
|
48
|
+
if (!relations) {
|
|
49
|
+
return (0, deepmerge_1.default)(result, obj, {
|
|
50
|
+
arrayMerge: (target, source) => target.concat(source),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const merged = { ...result };
|
|
54
|
+
for (const [key, field] of Object.entries(obj)) {
|
|
55
|
+
if (field === undefined)
|
|
56
|
+
continue;
|
|
57
|
+
const relation = relations[key];
|
|
58
|
+
if (!relation) {
|
|
59
|
+
merged[key] = field;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if ((relation.mode === "oto" || relation.mode === "mto") && (0, is_plain_object_validator_1.isPlainObject)(merged[key])) {
|
|
63
|
+
merged[key] = field === null ? null : (0, deepmerge_1.default)(merged[key], field);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if ((relation.mode === "mtm" || relation.mode === "otm") && Array.isArray(merged[key])) {
|
|
67
|
+
merged[key] = mergeToManyRelation(merged[key], field, relation.pk);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
merged[key] = field;
|
|
71
|
+
}
|
|
72
|
+
return merged;
|
|
73
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { VSLogLevel } from "vsrepo";
|
|
2
|
+
import { AdapterRelations } from "./adapter-relations.type";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration accepted by `VSRepoPrisma7Adapter`'s constructor, as the
|
|
5
|
+
* second parameter.
|
|
6
|
+
*
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
export interface VSRepoPrisma7AdapterConfig<T = any> {
|
|
10
|
+
/** Name of the Prisma Client model/delegate (e.g. `"user"`, as in `prisma.user`). */
|
|
11
|
+
tableName: string;
|
|
12
|
+
/** Name of the entity's primary key field (e.g. `"id"`). */
|
|
13
|
+
pkName: keyof T;
|
|
14
|
+
/**
|
|
15
|
+
* The entity's relation configuration, needed by the `create`/`update`/`merge`
|
|
16
|
+
* parsers to correctly resolve relation fields (see `Relation`/`AdapterRelations`).
|
|
17
|
+
* Optional: without it, relation fields are passed through to Prisma as-is (raw).
|
|
18
|
+
*/
|
|
19
|
+
relations?: AdapterRelations<T>;
|
|
20
|
+
/** Minimum log level for the adapter's internal `VSLogger`. @default VSLogLevel.WARN */
|
|
21
|
+
logLevel?: VSLogLevel;
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RelationKeys } from "vsrepo";
|
|
2
|
+
import { Relation } from "./relation.type";
|
|
3
|
+
/**
|
|
4
|
+
* Relation configuration for entity `T`, used by the `create`/`update`/`merge`
|
|
5
|
+
* parsers to resolve relation fields according to the v1 behavior (see
|
|
6
|
+
* `Relation`).
|
|
7
|
+
*
|
|
8
|
+
* Keyed by the relation fields of `T` (`RelationKeys<T>`). Without this
|
|
9
|
+
* configuration (adapter built without `relations`), relation fields are
|
|
10
|
+
* passed through to Prisma as-is, with no special resolution.
|
|
11
|
+
*
|
|
12
|
+
* @publicApi
|
|
13
|
+
*/
|
|
14
|
+
export type AdapterRelations<T> = Partial<{
|
|
15
|
+
[P in RelationKeys<T>]: Relation<NonNullable<T[P]> extends Array<infer U> ? U : NonNullable<T[P]>>;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type PlainObject = Record<string, any>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PrismaArgLike {
|
|
2
|
+
where?: object;
|
|
3
|
+
select?: object;
|
|
4
|
+
include?: object;
|
|
5
|
+
data?: any;
|
|
6
|
+
create?: any;
|
|
7
|
+
update?: any;
|
|
8
|
+
orderBy?: object | object[];
|
|
9
|
+
skip?: number;
|
|
10
|
+
take?: number;
|
|
11
|
+
cursor?: object;
|
|
12
|
+
skipDuplicates?: boolean;
|
|
13
|
+
distinct?: any[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PrismaArgLike } from "./prisma-arg-like.type";
|
|
2
|
+
type AnyFn = (arg: PrismaArgLike) => Promise<any>;
|
|
3
|
+
/** `count` do Prisma resolve pra um `number` (na forma simples, sem `select` de agregação). */
|
|
4
|
+
type CountFn = (arg: PrismaArgLike) => Promise<number>;
|
|
5
|
+
export type PrismaRepositoryLike = {
|
|
6
|
+
findFirst: AnyFn;
|
|
7
|
+
findFirstOrThrow: AnyFn;
|
|
8
|
+
findMany: AnyFn;
|
|
9
|
+
create: AnyFn;
|
|
10
|
+
createMany: AnyFn;
|
|
11
|
+
createManyAndReturn: AnyFn;
|
|
12
|
+
update: AnyFn;
|
|
13
|
+
updateMany: AnyFn;
|
|
14
|
+
updateManyAndReturn: AnyFn;
|
|
15
|
+
upsert: AnyFn;
|
|
16
|
+
delete: AnyFn;
|
|
17
|
+
deleteMany: AnyFn;
|
|
18
|
+
count: CountFn;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal shape of a Prisma Client (or transaction client) required by the
|
|
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`).
|
|
10
|
+
*
|
|
11
|
+
* @publicApi
|
|
12
|
+
*/
|
|
13
|
+
export type Prisma7ClientLike = {
|
|
14
|
+
$executeRaw: any;
|
|
15
|
+
$executeRawUnsafe: any;
|
|
16
|
+
$queryRaw: any;
|
|
17
|
+
$queryRawUnsafe: any;
|
|
18
|
+
$on: any;
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Prisma7ClientLike } from "./prisma7-client-like.type";
|
|
2
|
+
/**
|
|
3
|
+
* Helper used to type a `VSRepository`'s `OrmTypes` generic when using
|
|
4
|
+
* `VSRepoPrisma7Adapter`, tying the repository's `getDbClient()`/`transaction()`
|
|
5
|
+
* return types to the real Prisma Client and transaction client types.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* type MyOrmTypes = Prisma7OrmTypes<PrismaClient, Prisma.TransactionClient>;
|
|
10
|
+
*
|
|
11
|
+
* class UserRepository extends VSRepository<User, string, MyOrmTypes> { ... }
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @publicApi
|
|
15
|
+
*/
|
|
16
|
+
export type Prisma7OrmTypes<DB extends Prisma7ClientLike, TX extends Omit<Prisma7ClientLike, "$on">> = {
|
|
17
|
+
dbClient: DB;
|
|
18
|
+
dbTransaction: TX;
|
|
19
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration of a single relation field, using the same shape the v1 of
|
|
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 `mto` relations, whether the field accepts being set to
|
|
17
|
+
* `null` (resolved as `disconnect`).
|
|
18
|
+
*
|
|
19
|
+
* @publicApi
|
|
20
|
+
*/
|
|
21
|
+
export interface Relation<T = any> {
|
|
22
|
+
mode: "otm" | "mtm" | "mto" | "oto";
|
|
23
|
+
restriction: "set" | "add";
|
|
24
|
+
pk: keyof T;
|
|
25
|
+
nullable?: boolean;
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { VSLogLevel } from "vsrepo";
|
|
3
|
+
export declare const adapterConfigSchema: v.ObjectSchema<{
|
|
4
|
+
readonly tableName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
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<{
|
|
7
|
+
readonly mode: v.PicklistSchema<["otm", "mtm", "mto", "oto"], undefined>;
|
|
8
|
+
readonly restriction: v.PicklistSchema<["set", "add"], undefined>;
|
|
9
|
+
readonly pk: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
10
|
+
readonly nullable: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
11
|
+
}, undefined>, undefined>, undefined>;
|
|
12
|
+
readonly logLevel: v.OptionalSchema<v.EnumSchema<typeof VSLogLevel, undefined>, undefined>;
|
|
13
|
+
}, undefined>;
|
|
@@ -0,0 +1,45 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.adapterConfigSchema = void 0;
|
|
37
|
+
const v = __importStar(require("valibot"));
|
|
38
|
+
const vsrepo_1 = require("vsrepo");
|
|
39
|
+
const relation_schema_1 = require("./relation.schema");
|
|
40
|
+
exports.adapterConfigSchema = v.object({
|
|
41
|
+
tableName: v.pipe(v.string(), v.minLength(1)),
|
|
42
|
+
pkName: v.pipe(v.string(), v.minLength(1)),
|
|
43
|
+
relations: v.optional(v.record(v.string(), relation_schema_1.relationSchema)),
|
|
44
|
+
logLevel: v.optional(v.enum(vsrepo_1.VSLogLevel)),
|
|
45
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDecimal = isDecimal;
|
|
4
|
+
function isDecimal(value) {
|
|
5
|
+
return (typeof value === "object" &&
|
|
6
|
+
value !== null &&
|
|
7
|
+
typeof value.toNumber === "function" &&
|
|
8
|
+
typeof value.toFixed === "function" &&
|
|
9
|
+
typeof value.toString === "function");
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isPlainObject = isPlainObject;
|
|
4
|
+
const is_decimal_validator_1 = require("./is-decimal.validator");
|
|
5
|
+
function isPlainObject(value) {
|
|
6
|
+
return (typeof value === "object" &&
|
|
7
|
+
value !== null &&
|
|
8
|
+
!Array.isArray(value) &&
|
|
9
|
+
!(value instanceof Date) &&
|
|
10
|
+
!(0, is_decimal_validator_1.isDecimal)(value));
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** Espelha o shape de `Relation`, incluindo os dois nomes de `nullable` da v1. */
|
|
3
|
+
export declare const relationSchema: v.StrictObjectSchema<{
|
|
4
|
+
readonly mode: v.PicklistSchema<["otm", "mtm", "mto", "oto"], undefined>;
|
|
5
|
+
readonly restriction: v.PicklistSchema<["set", "add"], undefined>;
|
|
6
|
+
readonly pk: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
|
|
7
|
+
readonly nullable: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
|
|
8
|
+
}, undefined>;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.relationSchema = void 0;
|
|
37
|
+
const v = __importStar(require("valibot"));
|
|
38
|
+
/** Espelha o shape de `Relation`, incluindo os dois nomes de `nullable` da v1. */
|
|
39
|
+
exports.relationSchema = v.strictObject({
|
|
40
|
+
mode: v.picklist(["otm", "mtm", "mto", "oto"]),
|
|
41
|
+
restriction: v.picklist(["set", "add"]),
|
|
42
|
+
pk: v.pipe(v.string(), v.minLength(1)),
|
|
43
|
+
nullable: v.optional(v.boolean()),
|
|
44
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VSRepoPrisma7AdapterConfig } from "../types/adapter-config.type";
|
|
2
|
+
/**
|
|
3
|
+
* Valida a config recebida pelo construtor do `VSRepoPrisma7Adapter` (`tableName`,
|
|
4
|
+
* `pkName`, `relations` opcional e `logLevel` opcional) com valibot, lançando
|
|
5
|
+
* `VSRepoAdapterError` (code `INVALID_ADAPTER_CONFIG`) com uma mensagem apontando
|
|
6
|
+
* o campo inválido.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateAdapterConfig<T>(config: unknown): VSRepoPrisma7AdapterConfig<T>;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.validateAdapterConfig = validateAdapterConfig;
|
|
37
|
+
const v = __importStar(require("valibot"));
|
|
38
|
+
const vsrepo_1 = require("vsrepo");
|
|
39
|
+
const adapter_config_schema_1 = require("./adapter-config.schema");
|
|
40
|
+
/**
|
|
41
|
+
* Valida a config recebida pelo construtor do `VSRepoPrisma7Adapter` (`tableName`,
|
|
42
|
+
* `pkName`, `relations` opcional e `logLevel` opcional) com valibot, lançando
|
|
43
|
+
* `VSRepoAdapterError` (code `INVALID_ADAPTER_CONFIG`) com uma mensagem apontando
|
|
44
|
+
* o campo inválido.
|
|
45
|
+
*/
|
|
46
|
+
function validateAdapterConfig(config) {
|
|
47
|
+
const parsed = v.safeParse(adapter_config_schema_1.adapterConfigSchema, config);
|
|
48
|
+
if (!parsed.success) {
|
|
49
|
+
const issue = parsed.issues[0];
|
|
50
|
+
const path = issue?.path?.length ? issue.path.map(p => String(p.key)).join(".") : "config";
|
|
51
|
+
throw new vsrepo_1.VSRepoAdapterError(`Invalid constructor config (${path}): ${issue?.message ?? "validation failed"}`, vsrepo_1.AdapterErrorCode.INVALID_ADAPTER_CONFIG, null);
|
|
52
|
+
}
|
|
53
|
+
return parsed.output;
|
|
54
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vsrepo/prisma7-adapter",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "VSRepository adapter implementation backed by Prisma 7, translating every VSRepository operation into Prisma Client calls.",
|
|
5
|
+
"homepage": "https://github.com/jaobrabo123/VSRepoPrisma7Adapter#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/jaobrabo123/VSRepoPrisma7Adapter.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"type": "commonjs",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"README.md",
|
|
23
|
+
"README.pt-BR.md"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"clean": "node -e \"fs.rmSync('dist',{recursive:true,force:true})\"",
|
|
30
|
+
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
31
|
+
"prepack": "npm run build",
|
|
32
|
+
"typecheck": "tsc --noEmit -p tsconfig.build.json",
|
|
33
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
|
34
|
+
"test:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
35
|
+
"test:types": "tsc --noEmit -p tests/tsconfig.json"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"prisma",
|
|
39
|
+
"prisma7",
|
|
40
|
+
"repository",
|
|
41
|
+
"orm",
|
|
42
|
+
"typescript",
|
|
43
|
+
"repository-pattern",
|
|
44
|
+
"vsrepo",
|
|
45
|
+
"vsrepository",
|
|
46
|
+
"adapter"
|
|
47
|
+
],
|
|
48
|
+
"author": "João Pedro Azevedo Freire Mecenas",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@prisma/client": "^7.10.0",
|
|
52
|
+
"vsrepo": "^2.0.0"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"deepmerge": "^4.3.1",
|
|
56
|
+
"valibot": "^1.4.2"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@babel/core": "^7.29.7",
|
|
60
|
+
"@babel/plugin-proposal-decorators": "^7.29.7",
|
|
61
|
+
"@babel/preset-env": "^7.29.7",
|
|
62
|
+
"@babel/preset-typescript": "^7.29.7",
|
|
63
|
+
"@jest/globals": "^30.5.0",
|
|
64
|
+
"@prisma/adapter-pg": "^7.10.0",
|
|
65
|
+
"@types/jest": "^30.0.0",
|
|
66
|
+
"@types/node": "^26.4.0",
|
|
67
|
+
"@types/pg": "^8.23.1",
|
|
68
|
+
"babel-jest": "^30.5.0",
|
|
69
|
+
"cross-env": "^10.1.0",
|
|
70
|
+
"dotenv": "^17.4.2",
|
|
71
|
+
"jest": "^30.5.0",
|
|
72
|
+
"pg": "^8.23.0",
|
|
73
|
+
"prisma": "^7.10.0",
|
|
74
|
+
"tsx": "^4.23.12",
|
|
75
|
+
"typescript": "^7.0.2"
|
|
76
|
+
},
|
|
77
|
+
"allowScripts": {
|
|
78
|
+
"prisma@7.10.0": true,
|
|
79
|
+
"@parcel/watcher@2.6.0": true,
|
|
80
|
+
"unrs-resolver@1.12.2": true,
|
|
81
|
+
"@prisma/engines@7.10.0": true,
|
|
82
|
+
"esbuild@0.28.2": true
|
|
83
|
+
}
|
|
84
|
+
}
|