Skip to content

Commit

Permalink
refactor(grpc-sdk): sdk function params as object option (#1115)
Browse files Browse the repository at this point in the history
* refactor(grpc-sdk): sdk function params as object option

* refactor(grpc-sdk): sdk function params as object option

* refactor(grpc-sdk): change logic & make only optional params an object

* fix(grpc-sdk): undefined types & missing spreads
  • Loading branch information
ChrisPdgn authored Aug 30, 2024
1 parent 20ad77f commit d3b126b
Show file tree
Hide file tree
Showing 9 changed files with 579 additions and 109 deletions.
313 changes: 257 additions & 56 deletions libraries/grpc-sdk/src/modules/database/index.ts

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions libraries/grpc-sdk/src/modules/database/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export type FindOneOptions = {
select?: string;
populate?: string | string[];
userId?: string;
scope?: string;
};

export type FindManyOptions = {
select?: string;
skip?: number;
limit?: number;
sort?: { [field: string]: -1 | 1 } | string[] | string;
populate?: string | string[];
userId?: string;
scope?: string;
};
55 changes: 48 additions & 7 deletions libraries/grpc-sdk/src/modules/pushNotifications/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ConduitModule } from '../../classes/index.js';
import { PushNotificationsDefinition } from '../../protoUtils/index.js';
import {
PushNotificationsDefinition,
SendNotificationResponse,
} from '../../protoUtils/index.js';
import { SendNotificationOptions } from './types';
import { isNil } from 'lodash';

export class PushNotifications extends ConduitModule<typeof PushNotificationsDefinition> {
constructor(
Expand Down Expand Up @@ -37,13 +42,31 @@ export class PushNotifications extends ConduitModule<typeof PushNotificationsDef
body?: string,
data?: string,
platform?: string,
): Promise<SendNotificationResponse>;

sendNotification(
sendTo: string,
title: string,
options?: SendNotificationOptions,
): Promise<SendNotificationResponse>;

sendNotification(
sendTo: string,
title: string,
bodyOrOptions?: string | SendNotificationOptions,
data?: string,
platform?: string,
) {
let options: SendNotificationOptions;
if (typeof bodyOrOptions === 'string' || isNil(bodyOrOptions)) {
options = { body: bodyOrOptions, data, platform };
} else {
options = bodyOrOptions;
}
return this.client!.sendNotification({
sendTo,
title,
body,
data,
platform,
...options,
});
}

Expand All @@ -63,13 +86,31 @@ export class PushNotifications extends ConduitModule<typeof PushNotificationsDef
body?: string,
data?: string,
platform?: string,
): Promise<SendNotificationResponse>;

sendNotificationToManyDevices(
sendTo: string[],
title: string,
options?: SendNotificationOptions,
): Promise<SendNotificationResponse>;

sendNotificationToManyDevices(
sendTo: string[],
title: string,
bodyOrOptions?: string | SendNotificationOptions,
data?: string,
platform?: string,
) {
let options: SendNotificationOptions;
if (typeof bodyOrOptions === 'string' || isNil(bodyOrOptions)) {
options = { body: bodyOrOptions, data, platform };
} else {
options = bodyOrOptions;
}
return this.client!.sendNotificationToManyDevices({
sendTo,
title,
body,
data,
platform,
...options,
});
}
}
5 changes: 5 additions & 0 deletions libraries/grpc-sdk/src/modules/pushNotifications/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type SendNotificationOptions = {
body?: string;
data?: string;
platform?: string;
};
Loading

0 comments on commit d3b126b

Please sign in to comment.