Skip to content

Commit

Permalink
js: Allow iterator and date list params to be null (#1519)
Browse files Browse the repository at this point in the history
Since these are commonly gotten from a previous API response, which
actually returns nulls for them, rather than leaving out the fields (the
response types used to have wrong typings w.r.t. that).

Part of svix/monorepo-private#9393.
  • Loading branch information
svix-jplatte authored Nov 14, 2024
2 parents 384decf + fefb886 commit db5cb1b
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions javascript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Authentication {
}

interface ListOptions {
iterator?: string;
iterator?: string | null;
limit?: number;
}

Expand All @@ -208,8 +208,8 @@ export interface OperationalWebhookEndpointListOptions extends ListOptions {
}

export interface EndpointStatsOptions {
since?: Date;
until?: Date;
since?: Date | null;
until?: Date | null;
}

export type IntegrationListOptions = ListOptions;
Expand All @@ -221,8 +221,8 @@ export interface EventTypeListOptions extends ListOptions {

export interface MessageListOptions extends ListOptions {
eventTypes?: string[];
before?: Date;
after?: Date;
before?: Date | null;
after?: Date | null;
channel?: string;
withContent?: boolean;
tag?: string;
Expand All @@ -231,8 +231,8 @@ export interface MessageListOptions extends ListOptions {
export interface MessageAttemptListOptions extends ListOptions {
status?: MessageStatus;
eventTypes?: string[];
before?: Date;
after?: Date;
before?: Date | null;
after?: Date | null;
statusCodeClass?: StatusCodeClass;
channel?: string;
withContent?: boolean;
Expand All @@ -255,7 +255,8 @@ class Application {
}

public list(options?: ApplicationListOptions): Promise<ListResponseApplicationOut> {
return this.api.v1ApplicationList({ ...options });
const iterator = options?.iterator ?? undefined;
return this.api.v1ApplicationList({ ...options, iterator });
}

public create(
Expand Down Expand Up @@ -307,7 +308,8 @@ class Endpoint {
appId: string,
options?: EndpointListOptions
): Promise<ListResponseEndpointOut> {
return this.api.v1EndpointList({ appId, ...options });
const iterator = options?.iterator ?? undefined;
return this.api.v1EndpointList({ appId, ...options, iterator });
}

public create(
Expand Down Expand Up @@ -480,6 +482,8 @@ class Endpoint {
appId,
endpointId,
...options,
since: options?.since ?? undefined,
until: options?.until ?? undefined,
});
}

Expand Down Expand Up @@ -544,7 +548,8 @@ class EventType {
}

public list(options?: EventTypeListOptions): Promise<ListResponseEventTypeOut> {
return this.api.v1EventTypeList({ ...options });
const iterator = options?.iterator ?? undefined;
return this.api.v1EventTypeList({ ...options, iterator });
}

public get(eventTypeName: string): Promise<EventTypeOut> {
Expand Down Expand Up @@ -598,7 +603,8 @@ class Integration {
appId: string,
options?: IntegrationListOptions
): Promise<ListResponseIntegrationOut> {
return this.api.v1IntegrationList({ appId, ...options });
const iterator = options?.iterator ?? undefined;
return this.api.v1IntegrationList({ appId, ...options, iterator });
}

public create(
Expand Down Expand Up @@ -667,7 +673,13 @@ class Message {
appId: string,
options?: MessageListOptions
): Promise<ListResponseMessageOut> {
return this.api.v1MessageList({ appId, ...options });
return this.api.v1MessageList({
appId,
...options,
iterator: options?.iterator ?? undefined,
before: options?.before ?? undefined,
after: options?.after ?? undefined,
});
}

public create(
Expand Down Expand Up @@ -714,6 +726,9 @@ class MessageAttempt {
appId,
msgId,
...options,
iterator: options?.iterator ?? undefined,
before: options?.before ?? undefined,
after: options?.after ?? undefined,
});
}

Expand All @@ -726,6 +741,9 @@ class MessageAttempt {
appId,
endpointId,
...options,
iterator: options?.iterator ?? undefined,
before: options?.before ?? undefined,
after: options?.after ?? undefined,
});
}

Expand Down Expand Up @@ -764,6 +782,9 @@ class MessageAttempt {
appId,
endpointId,
...options,
iterator: options?.iterator ?? undefined,
before: options?.before ?? undefined,
after: options?.after ?? undefined,
});
}

Expand All @@ -776,6 +797,7 @@ class MessageAttempt {
appId,
msgId,
...options,
iterator: options?.iterator ?? undefined,
});
}

Expand All @@ -790,6 +812,9 @@ class MessageAttempt {
msgId,
endpointId,
...options,
iterator: options?.iterator ?? undefined,
before: options?.before ?? undefined,
after: options?.after ?? undefined,
});
}

Expand All @@ -812,9 +837,8 @@ class BackgroundTask {
public listByEndpoint(
options?: BackgroundTaskListOptions
): Promise<ListResponseBackgroundTaskOut> {
return this.api.listBackgroundTasks({
...options,
});
const iterator = options?.iterator ?? undefined;
return this.api.listBackgroundTasks({ ...options, iterator });
}

public get(taskId: string): Promise<BackgroundTaskOut> {
Expand Down Expand Up @@ -996,7 +1020,8 @@ class OperationalWebhookEndpoint {
public list(
options?: OperationalWebhookEndpointListOptions,
): Promise<ListResponseOperationalWebhookEndpointOut> {
return this.api.listOperationalWebhookEndpoints({ ...options });
const iterator = options?.iterator ?? undefined;
return this.api.listOperationalWebhookEndpoints({ ...options, iterator });
}

public create(
Expand Down

0 comments on commit db5cb1b

Please sign in to comment.