-
Notifications
You must be signed in to change notification settings - Fork 58
Make WrappedFunction curry type info #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
function generateBaseCloudEvent<EventType extends CloudEvent<unknown>>( | ||
cloudFunction: CloudFunction<EventType> | ||
): EventType { | ||
// TODO: Consider refactoring so that we don't use this utility function. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
import { alertsBillingOnPlanUpdatePublished } from './alerts/billing-on-plan-update-published'; | ||
import { eventarcOnCustomEventPublished } from './eventarc/eventarc-on-custom-event-published'; | ||
import { pubsubOnMessagePublished } from './pubsub/pubsub-on-message-published'; | ||
import { storageV1 } from './storage'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be a new file here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/cloudevent/partials/partials.ts:14:27 - error TS2307: Cannot find module './storage' or its corresponding type declarations.
14 import { storageV1 } from './storage';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Added missing file back.
cloudFunction: CloudFunctionV2<T> | ||
): WrappedV2Function<T>; | ||
|
||
export function wrap<T, V extends CloudEvent<unknown>>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this function overloading much better than what I did earlier 🐢
Sorry that the formatter made a bunch of changes. The majority of the impactful changes here are that the wrapped function types keep the type info of the functions that they wrap. This also required us a fix to the
CloudFunction
type because it is now generic based on an EventType rather than event data so that we can keep type info for subtypes of CloudEvent.I'd like to eventually look at refactoring this to have fewer places where we have
any
. I think we might want to have three pieces:function baseEvent<T>(): Omit<CloudEvent<any>, 'data'>
that returns what you have today. Then in each partial you do the combination ofbaseEvent
with per-event type overrides (e.g. bucket for Storage) and the partial data. By putting the event construction lower in the stack we can make sure data is referentially correct (e.g. the StorageEvent.bucket matches the StorageEvent.data.bucket)