vsrepo 1.1.8 → 1.2.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.
|
@@ -488,6 +488,34 @@ export type UpsertWithRelations<T, M extends Prisma.ModelName, TRelations> =
|
|
|
488
488
|
[K in Extract<keyof TRelations, keyof T>]?: RelationPayload<T[K], TRelations[K], M, K>;
|
|
489
489
|
};
|
|
490
490
|
|
|
491
|
+
type ExtractNestedUpdateInput<M extends Prisma.ModelName, K extends PropertyKey> =
|
|
492
|
+
NonNullable<ExtractUnionProp<PrismaModelInputs<M>['updateInput'], K>> extends { update?: infer U }
|
|
493
|
+
? (
|
|
494
|
+
Exclude<U, any[]> extends infer Obj
|
|
495
|
+
? Obj extends { where: any, data: infer D }
|
|
496
|
+
? Exclude<D, any[]>
|
|
497
|
+
: Obj
|
|
498
|
+
: never
|
|
499
|
+
)
|
|
500
|
+
: never;
|
|
501
|
+
|
|
502
|
+
type RelationUpdatePayload<TField, TRelationConfig, M extends Prisma.ModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
|
|
503
|
+
? (ExtractNestedUpdateInput<M, K>)[]
|
|
504
|
+
: NonNullable<TField> extends object
|
|
505
|
+
? ExtractNestedUpdateInput<M, K> | (TRelationConfig extends { mode: 'oto'; restriction: 'set' } | { mode: 'mto'; nullAble: true } ? null : never)
|
|
506
|
+
: never;
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Payload aceito pelo `patch` quando o repository possui relações configuradas.
|
|
510
|
+
*
|
|
511
|
+
* Substitui os campos relacionais pelo formato compatível com os modos
|
|
512
|
+
* configurados em `relations` para fluxos de Update.
|
|
513
|
+
*/
|
|
514
|
+
export type UpdateWithRelations<T, M extends Prisma.ModelName, TRelations> =
|
|
515
|
+
DistributiveOmit<PrismaModelInputs<M>['updateInput'], keyof TRelations> & {
|
|
516
|
+
[K in Extract<keyof TRelations, keyof T>]?: RelationUpdatePayload<T[K], TRelations[K], M, K>;
|
|
517
|
+
};
|
|
518
|
+
|
|
491
519
|
type InjectedSave<
|
|
492
520
|
T, M extends Prisma.ModelName, Config, C extends BuildConfig<any> | undefined,
|
|
493
521
|
TSelects = ExtractSelectModels<Config>,
|
|
@@ -514,7 +542,7 @@ type InjectedPatch<
|
|
|
514
542
|
TSelects = ExtractSelectModels<Config>,
|
|
515
543
|
TDefault = ExtractDefaultSelect<Config>,
|
|
516
544
|
TPk = ExtractPkName<T, Config>,
|
|
517
|
-
|
|
545
|
+
TRelations = ExtractRelations<Config>
|
|
518
546
|
> = C extends { baseMethods: { patch: { active: false } } } ? {} : {
|
|
519
547
|
/**
|
|
520
548
|
* Atualiza parcialmente (patch) um registro existente pela chave primária (PK), aceita os campos de relações definidas nas `relations`.
|
|
@@ -524,11 +552,11 @@ type InjectedPatch<
|
|
|
524
552
|
* @returns O registro atualizado refinado conforme a entrada.
|
|
525
553
|
*/
|
|
526
554
|
patch<
|
|
527
|
-
O extends
|
|
555
|
+
O extends UpdateWithRelations<T, M, TRelations>,
|
|
528
556
|
S extends keyof TSelects | false = ResolveMethodDefaultSelect<Config, C, 'patch', TSelects>
|
|
529
557
|
>(
|
|
530
558
|
pk: T[TPk extends keyof T ? TPk : never],
|
|
531
|
-
obj: O &
|
|
559
|
+
obj: O & UpdateWithRelations<T, M, TRelations>,
|
|
532
560
|
options?: MethodOptions<S>
|
|
533
561
|
): Promise<RefineSaveResult<ResolveCurrentReturn<M, TSelects, S, TDefault>, O>>;
|
|
534
562
|
};
|
|
@@ -913,7 +913,9 @@ export class VSRepository {
|
|
|
913
913
|
}
|
|
914
914
|
} else {
|
|
915
915
|
prismaArgs.create[key] = { create: field };
|
|
916
|
-
prismaArgs.update[key] =
|
|
916
|
+
prismaArgs.update[key] = relationRestriction === 'add' ?
|
|
917
|
+
{ create: field } :
|
|
918
|
+
{ upsert: { create: field, update: field } };
|
|
917
919
|
}
|
|
918
920
|
}
|
|
919
921
|
} else if(Array.isArray(field)) {
|
|
@@ -1251,7 +1253,9 @@ export class VSRepository {
|
|
|
1251
1253
|
};
|
|
1252
1254
|
}
|
|
1253
1255
|
} else {
|
|
1254
|
-
prismaArgs.data[key] =
|
|
1256
|
+
prismaArgs.data[key] = relationRestriction === 'add' ?
|
|
1257
|
+
{ create: field } :
|
|
1258
|
+
{ upsert: { create: field, update: field } };
|
|
1255
1259
|
}
|
|
1256
1260
|
}
|
|
1257
1261
|
} else if(Array.isArray(field)) {
|
package/package.json
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vsrepo",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Uma biblioteca de repository pattern para Prisma",
|
|
5
|
-
"homepage": "https://github.com/jaobrabo123/VSRepository#readme",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/jaobrabo123/VSRepository.git"
|
|
9
|
-
},
|
|
10
|
-
"main": "./VSRepository/index.js",
|
|
11
|
-
"types": "./VSRepository/index.d.ts",
|
|
12
|
-
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"types": "./VSRepository/index.d.ts",
|
|
15
|
-
"import": "./VSRepository/index.js",
|
|
16
|
-
"require": "./VSRepository/index.js"
|
|
17
|
-
},
|
|
18
|
-
"./VSRepository": {
|
|
19
|
-
"types": "./VSRepository/VSRepository.d.ts",
|
|
20
|
-
"import": "./VSRepository/VSRepository.js",
|
|
21
|
-
"require": "./VSRepository/VSRepository.js"
|
|
22
|
-
},
|
|
23
|
-
"./VSRepoError": {
|
|
24
|
-
"types": "./VSRepository/VSRepoError.d.ts",
|
|
25
|
-
"import": "./VSRepository/VSRepoError.js",
|
|
26
|
-
"require": "./VSRepository/VSRepoError.js"
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"type": "module",
|
|
30
|
-
"files": [
|
|
31
|
-
"VSRepository",
|
|
32
|
-
"scripts"
|
|
33
|
-
],
|
|
34
|
-
"bin": {
|
|
35
|
-
"vsrepo": "scripts/configure-prisma-import.mjs"
|
|
36
|
-
},
|
|
37
|
-
"engines": {
|
|
38
|
-
"node": ">=18"
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"vsrepo": "node ./scripts/configure-prisma-import.mjs",
|
|
42
|
-
"configure:prisma-import": "node ./scripts/configure-prisma-import.mjs"
|
|
43
|
-
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"prisma",
|
|
46
|
-
"repository",
|
|
47
|
-
"orm",
|
|
48
|
-
"typescript",
|
|
49
|
-
"vsrepo",
|
|
50
|
-
"vsrepository"
|
|
51
|
-
],
|
|
52
|
-
"author": "João Pedro Azevedo Freire Mecenas",
|
|
53
|
-
"license": "MIT",
|
|
54
|
-
"peerDependencies": {
|
|
55
|
-
"@prisma/client": "^7.8.0"
|
|
56
|
-
},
|
|
57
|
-
"devDependencies": {
|
|
58
|
-
"@paralleldrive/cuid2": "^3.3.0",
|
|
59
|
-
"@prisma/adapter-pg": "^7.8.0",
|
|
60
|
-
"@prisma/client": "^7.8.0",
|
|
61
|
-
"@types/node": "^25.6.0",
|
|
62
|
-
"dotenv": "^17.4.2",
|
|
63
|
-
"prisma": "^7.8.0",
|
|
64
|
-
"tsx": "^4.22.3",
|
|
65
|
-
"typescript": "^6.0.3"
|
|
66
|
-
},
|
|
67
|
-
"dependencies": {
|
|
68
|
-
"zod": "^4.4.3"
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "vsrepo",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Uma biblioteca de repository pattern para Prisma",
|
|
5
|
+
"homepage": "https://github.com/jaobrabo123/VSRepository#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/jaobrabo123/VSRepository.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "./VSRepository/index.js",
|
|
11
|
+
"types": "./VSRepository/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./VSRepository/index.d.ts",
|
|
15
|
+
"import": "./VSRepository/index.js",
|
|
16
|
+
"require": "./VSRepository/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./VSRepository": {
|
|
19
|
+
"types": "./VSRepository/VSRepository.d.ts",
|
|
20
|
+
"import": "./VSRepository/VSRepository.js",
|
|
21
|
+
"require": "./VSRepository/VSRepository.js"
|
|
22
|
+
},
|
|
23
|
+
"./VSRepoError": {
|
|
24
|
+
"types": "./VSRepository/VSRepoError.d.ts",
|
|
25
|
+
"import": "./VSRepository/VSRepoError.js",
|
|
26
|
+
"require": "./VSRepository/VSRepoError.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"files": [
|
|
31
|
+
"VSRepository",
|
|
32
|
+
"scripts"
|
|
33
|
+
],
|
|
34
|
+
"bin": {
|
|
35
|
+
"vsrepo": "scripts/configure-prisma-import.mjs"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"vsrepo": "node ./scripts/configure-prisma-import.mjs",
|
|
42
|
+
"configure:prisma-import": "node ./scripts/configure-prisma-import.mjs"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"prisma",
|
|
46
|
+
"repository",
|
|
47
|
+
"orm",
|
|
48
|
+
"typescript",
|
|
49
|
+
"vsrepo",
|
|
50
|
+
"vsrepository"
|
|
51
|
+
],
|
|
52
|
+
"author": "João Pedro Azevedo Freire Mecenas",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"@prisma/client": "^7.8.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@paralleldrive/cuid2": "^3.3.0",
|
|
59
|
+
"@prisma/adapter-pg": "^7.8.0",
|
|
60
|
+
"@prisma/client": "^7.8.0",
|
|
61
|
+
"@types/node": "^25.6.0",
|
|
62
|
+
"dotenv": "^17.4.2",
|
|
63
|
+
"prisma": "^7.8.0",
|
|
64
|
+
"tsx": "^4.22.3",
|
|
65
|
+
"typescript": "^6.0.3"
|
|
66
|
+
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"zod": "^4.4.3"
|
|
69
|
+
}
|
|
70
|
+
}
|