Skip to content

Commit

Permalink
feat: change bucket notification type from enum to union (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
HomelessDinosaur authored May 15, 2023
2 parents dc7859c + 6044eea commit 95e7327
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
28 changes: 8 additions & 20 deletions src/api/storage/v0/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,7 @@ describe('bucket notification', () => {
});

beforeAll(async () => {
await bucket('test-bucket').on(
BucketNotificationType.Write,
'test.png',
mockFn
);
await bucket('test-bucket').on('write', 'test.png', mockFn);
});

it('should create a new FaasClient', () => {
Expand All @@ -464,7 +460,7 @@ describe('bucket notification', () => {
it('should provide Faas with BucketNotificationWorkerOptions', () => {
const expectedOpts = new BucketNotificationWorkerOptions(
'test-bucket',
BucketNotificationType.Write,
'write',
'test.png'
);
expect(faas.Faas).toBeCalledWith(expectedOpts);
Expand All @@ -481,11 +477,7 @@ describe('bucket notification', () => {
});

beforeAll(async () => {
await bucket('test-bucket').on(
BucketNotificationType.Delete,
'test.png',
mockFn
);
await bucket('test-bucket').on('delete', 'test.png', mockFn);
});

it('should create a new FaasClient', () => {
Expand All @@ -495,7 +487,7 @@ describe('bucket notification', () => {
it('should provide Faas with BucketNotificationWorkerOptions', () => {
const expectedOpts = new BucketNotificationWorkerOptions(
'test-bucket',
BucketNotificationType.Delete,
'delete',
'test.png'
);
expect(faas.Faas).toBeCalledWith(expectedOpts);
Expand Down Expand Up @@ -526,7 +518,7 @@ describe('file notification', () => {
let bucketResource: Bucket;
beforeAll(async () => {
bucketResource = bucket('test-bucket-create').for('reading');
await bucketResource.on(BucketNotificationType.Write, 'test.png', mockFn);
await bucketResource.on('write', 'test.png', mockFn);
});

afterAll(() => {
Expand All @@ -544,7 +536,7 @@ describe('file notification', () => {
it('should provide Faas with FileNotificationWorkerOptions', () => {
const expectedOpts = new FileNotificationWorkerOptions(
bucketResource,
BucketNotificationType.Write,
'write',
'test.png'
);
expect(faas.Faas).toBeCalledWith(expectedOpts);
Expand All @@ -559,11 +551,7 @@ describe('file notification', () => {
let bucketResource: Bucket;
beforeAll(async () => {
bucketResource = bucket('test-bucket-delete').for('reading');
await bucketResource.on(
BucketNotificationType.Delete,
'test.png',
mockFn
);
await bucketResource.on('delete', 'test.png', mockFn);
});

afterAll(() => {
Expand All @@ -581,7 +569,7 @@ describe('file notification', () => {
it('should provide Faas with FileNotificationWorkerOptions', () => {
const expectedOpts = new FileNotificationWorkerOptions(
bucketResource,
BucketNotificationType.Delete,
'delete',
'test.png'
);
expect(faas.Faas).toBeCalledWith(expectedOpts);
Expand Down
9 changes: 3 additions & 6 deletions src/resources/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ type BucketPermission = 'reading' | 'writing' | 'deleting';

const everything: BucketPermission[] = ['reading', 'writing', 'deleting'];

export enum BucketNotificationType {
Write,
Delete,
}
export type BucketNotificationType = 'write' | 'delete';

export class BucketNotificationWorkerOptions {
public readonly bucket: string;
Expand All @@ -57,9 +54,9 @@ export class BucketNotificationWorkerOptions {

static toGrpcEvent(notificationType: BucketNotificationType): 0 | 1 | 2 {
switch (notificationType) {
case BucketNotificationType.Write:
case 'write':
return ProtoBucketNotificationType.CREATED;
case BucketNotificationType.Delete:
case 'delete':
return ProtoBucketNotificationType.DELETED;
default:
throw new Error(`notification type ${notificationType} is unsupported`);
Expand Down

0 comments on commit 95e7327

Please sign in to comment.