Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.

Commit 35efb4c

Browse files
committed
feat: add subscribe option types
1 parent d7f614c commit 35efb4c

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

lib/pubsub/subscribe.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
/* eslint-disable @typescript-eslint/ban-types */
2-
import {
3-
PubSubEvent,
4-
SubscribeArgs,
5-
SubscribeHandler,
6-
SubscribePsuedoIterable,
7-
SubscriptionDefinition,
8-
} from '../types'
1+
import { SubscribeArgs, SubscribeHandler, SubscribeOptions, SubscribePsuedoIterable, SubscriptionDefinition } from '../types'
92

103
/** Creates subscribe handler */
114
export const subscribe = (
@@ -15,12 +8,7 @@ export const subscribe = (
158
onSubscribe,
169
onComplete,
1710
onAfterSubscribe,
18-
}: {
19-
filter?: object | ((...args: SubscribeArgs) => object)
20-
onSubscribe?: (...args: SubscribeArgs) => void | Promise<void>
21-
onComplete?: (...args: SubscribeArgs) => void | Promise<void>
22-
onAfterSubscribe?: (...args: SubscribeArgs) => PubSubEvent | Promise<PubSubEvent> | undefined | Promise<undefined>
23-
} = {}): (...args: SubscribeArgs) => SubscribePsuedoIterable => {
11+
}: SubscribeOptions = {}): (...args: SubscribeArgs) => SubscribePsuedoIterable => {
2412
return (...args: SubscribeArgs) => {
2513
const handler = createHandler([{
2614
topic,
@@ -42,6 +30,7 @@ export const concat =
4230
createHandler( handlers.map((h) => h(...args).topicDefinitions).flat() )
4331

4432
const createHandler = (topicDefinitions: SubscriptionDefinition[]) => {
33+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4534
// eslint-disable-next-line require-yield
4635
const handler: any = function *() {
4736
throw new Error('Subscription handler should not have been called')

lib/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,10 @@ export interface ApiGatewayManagementApiSubset {
115115
postToConnection(input: { ConnectionId: string, Data: string }): { promise: () => Promise<void> }
116116
deleteConnection(input: { ConnectionId: string }): { promise: () => Promise<void> }
117117
}
118+
119+
export interface SubscribeOptions {
120+
filter?: object | ((...args: SubscribeArgs) => object)
121+
onSubscribe?: (...args: SubscribeArgs) => void | Promise<void>
122+
onComplete?: (...args: SubscribeArgs) => void | Promise<void>
123+
onAfterSubscribe?: (...args: SubscribeArgs) => PubSubEvent | Promise<PubSubEvent> | undefined | Promise<undefined>
124+
}

0 commit comments

Comments
 (0)