Skip to content

Commit 841871a

Browse files
committed
Release vintasend-prisma@0.11.1
1 parent c181631 commit 841871a

4 files changed

Lines changed: 60 additions & 17 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vintasend-prisma",
3-
"version": "0.11.0",
3+
"version": "0.11.1",
44
"description": "VintaSend Backend implementation for Prisma",
55
"main": "dist/index.js",
66
"scripts": {
@@ -21,7 +21,7 @@
2121
"dependencies": {
2222
"@prisma/client": "^7.4.2",
2323
"prisma": "^7.4.2",
24-
"vintasend": "^0.11.0"
24+
"vintasend": "^0.11.1"
2525
},
2626
"devDependencies": {
2727
"@biomejs/biome": "^2.4.5",

src/__tests__/prisma-notification-backend-attachments.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type {
33
BaseAttachmentManager,
44
NotificationAttachment,
55
} from 'vintasend';
6-
import { type Mock, type Mocked, vi } from 'vitest';
6+
import { beforeEach, describe, expect, it, type Mock, type Mocked, vi } from 'vitest';
77
import { PrismaNotificationBackendFactory } from '../index';
88
import type {
99
NotificationPrismaClientInterface,

src/__tests__/prisma-notification-backend.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
NotificationFilter,
55
NotificationOrderBy,
66
} from 'vintasend';
7-
import { type Mock, type Mocked, vi } from 'vitest';
7+
import { beforeEach, describe, expect, it, type Mock, type Mocked, vi } from 'vitest';
88
import { PrismaNotificationBackendFactory } from '../index';
99
import type {
1010
NotificationPrismaClientInterface,
@@ -905,8 +905,9 @@ describe('PrismaNotificationBackend', () => {
905905
const createMock = mockPrismaClient.notification.create as Mock;
906906
createMock.mockResolvedValue(invalidInput);
907907

908-
// @ts-expect-error - testing invalid input
909-
await expect(backend.persistNotification(invalidInput)).rejects.toThrow('Invalid JSON value');
908+
await expect(backend.persistNotification(invalidInput as any)).rejects.toThrow(
909+
'Invalid JSON value',
910+
);
910911
});
911912
});
912913

@@ -1088,8 +1089,9 @@ describe('PrismaNotificationBackend', () => {
10881089
const createMock = mockPrismaClient.notification.create as Mock;
10891090
createMock.mockResolvedValue(invalidInput);
10901091

1091-
// @ts-expect-error - testing invalid input
1092-
await expect(backend.persistNotification(invalidInput)).rejects.toThrow('Invalid JSON value');
1092+
await expect(backend.persistNotification(invalidInput as any)).rejects.toThrow(
1093+
'Invalid JSON value',
1094+
);
10931095
});
10941096

10951097
it('should handle missing user email in getUserEmailFromNotification', async () => {

src/prisma-notification-backend.ts

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,15 @@ type PrismaNotificationWhereInput<NotificationIdType, UserIdType> = {
144144
sentAt?: PrismaDateRangeFilter;
145145
};
146146

147-
export interface NotificationPrismaClientInterface<NotificationIdType, UserIdType> {
148-
$transaction<R>(
149-
fn: (prisma: NotificationPrismaClientInterface<NotificationIdType, UserIdType>) => Promise<R>,
150-
): Promise<R>;
147+
type AwaitedTuple<T extends readonly unknown[]> = {
148+
[K in keyof T]: Awaited<T[K]>;
149+
};
150+
151+
type PrismaTransactionOptions = {
152+
isolationLevel?: unknown;
153+
};
154+
155+
interface NotificationPrismaDelegates<NotificationIdType, UserIdType> {
151156
notification: {
152157
findMany(args?: {
153158
where?: PrismaNotificationWhereInput<NotificationIdType, UserIdType>;
@@ -232,6 +237,27 @@ export interface NotificationPrismaClientInterface<NotificationIdType, UserIdTyp
232237
};
233238
}
234239

240+
export interface NotificationPrismaTransactionClientInterface<NotificationIdType, UserIdType>
241+
extends NotificationPrismaDelegates<NotificationIdType, UserIdType> {}
242+
243+
export interface NotificationPrismaClientInterface<NotificationIdType, UserIdType> {
244+
$transaction: {
245+
<R>(
246+
fn: (
247+
prisma: NotificationPrismaTransactionClientInterface<NotificationIdType, UserIdType>,
248+
) => Promise<R>,
249+
options?: PrismaTransactionOptions,
250+
): Promise<R>;
251+
<P extends readonly unknown[]>(
252+
arg: [...P],
253+
options?: PrismaTransactionOptions,
254+
): Promise<AwaitedTuple<P>>;
255+
};
256+
}
257+
258+
export interface NotificationPrismaClientInterface<NotificationIdType, UserIdType>
259+
extends NotificationPrismaDelegates<NotificationIdType, UserIdType> {}
260+
235261
// cause typescript not to expand types and preserve names
236262
type NoExpand<T> = T extends unknown ? T : never;
237263

@@ -835,7 +861,10 @@ export class PrismaNotificationBackend<
835861
* @private
836862
*/
837863
private async getOrCreateFileRecordForUploadInTransaction(
838-
tx: NotificationPrismaClientInterface<Config['NotificationIdType'], Config['UserIdType']>,
864+
tx: NotificationPrismaTransactionClientInterface<
865+
Config['NotificationIdType'],
866+
Config['UserIdType']
867+
>,
839868
att: Extract<NotificationAttachment, { file: unknown }>,
840869
): Promise<AttachmentFileRecord> {
841870
const manager = this.getAttachmentManager();
@@ -866,7 +895,10 @@ export class PrismaNotificationBackend<
866895
* @private`
867896
*/
868897
private async createNotificationAttachmentLinkInTransaction(
869-
tx: NotificationPrismaClientInterface<Config['NotificationIdType'], Config['UserIdType']>,
898+
tx: NotificationPrismaTransactionClientInterface<
899+
Config['NotificationIdType'],
900+
Config['UserIdType']
901+
>,
870902
notificationId: Config['NotificationIdType'],
871903
fileId: string,
872904
description?: string | null,
@@ -885,7 +917,10 @@ export class PrismaNotificationBackend<
885917
* @private
886918
*/
887919
private async getAttachmentFileInTransaction(
888-
tx: NotificationPrismaClientInterface<Config['NotificationIdType'], Config['UserIdType']>,
920+
tx: NotificationPrismaTransactionClientInterface<
921+
Config['NotificationIdType'],
922+
Config['UserIdType']
923+
>,
889924
fileId: string,
890925
): Promise<AttachmentFileRecord | null> {
891926
const file = await tx.attachmentFile.findUnique({
@@ -902,7 +937,10 @@ export class PrismaNotificationBackend<
902937
* @private
903938
*/
904939
private async findAttachmentFileByChecksumInTransaction(
905-
tx: NotificationPrismaClientInterface<Config['NotificationIdType'], Config['UserIdType']>,
940+
tx: NotificationPrismaTransactionClientInterface<
941+
Config['NotificationIdType'],
942+
Config['UserIdType']
943+
>,
906944
checksum: string,
907945
): Promise<AttachmentFileRecord | null> {
908946
const file = await tx.attachmentFile.findUnique({
@@ -1613,7 +1651,10 @@ export class PrismaNotificationBackend<
16131651
* @private
16141652
*/
16151653
private async processAndStoreAttachmentsInTransaction(
1616-
tx: NotificationPrismaClientInterface<Config['NotificationIdType'], Config['UserIdType']>,
1654+
tx: NotificationPrismaTransactionClientInterface<
1655+
Config['NotificationIdType'],
1656+
Config['UserIdType']
1657+
>,
16171658
notificationId: Config['NotificationIdType'],
16181659
attachments: NotificationAttachment[],
16191660
): Promise<void> {

0 commit comments

Comments
 (0)