-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Simulations): narrow down simulation payload types (#52)
* feat(Simulations): narrow down simulation payload types * refactor(Simulations): rename event map * fix(Simulations): Include scenarios in union * refactor(Simulations): rename DiscriminatedEventResponse
- Loading branch information
1 parent
46d9b2f
commit 5536e93
Showing
5 changed files
with
122 additions
and
30 deletions.
There are no files selected for viewing
14 changes: 5 additions & 9 deletions
14
src/resources/simulations/operations/create-simulation-request-body.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
|
||
import type { SimulationScenarioType } from '../../../enums'; | ||
import type { IEventName } from '../../../notifications'; | ||
import type { DiscriminatedSimulationEventResponse } from '../../../types'; | ||
|
||
export interface CreateSimulationRequestBody { | ||
interface BaseCreateSimulationRequestBody { | ||
notificationSettingId: string; | ||
type: IEventName | SimulationScenarioType; | ||
name: string; | ||
payload?: any; | ||
type: IEventName | SimulationScenarioType; | ||
} | ||
|
||
export type CreateSimulationRequestBody = DiscriminatedSimulationEventResponse<BaseCreateSimulationRequestBody>; |
21 changes: 10 additions & 11 deletions
21
src/resources/simulations/operations/update-simulation-request-body.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
/** | ||
* ! Autogenerated code ! | ||
* Do not make changes to this file. | ||
* Changes may be overwritten as part of auto-generation. | ||
*/ | ||
import type { Status } from '../../../enums'; | ||
import type { DiscriminatedSimulationEventResponse } from '../../../types'; | ||
|
||
import type { SimulationScenarioType, Status } from '../../../enums'; | ||
import type { IEventName } from '../../../notifications'; | ||
|
||
export interface UpdateSimulationRequestBody { | ||
interface BaseUpdateSimulationRequestBody { | ||
notificationSettingId?: string; | ||
name?: string; | ||
status?: Status; | ||
type?: IEventName | SimulationScenarioType; | ||
payload?: any; | ||
} | ||
|
||
type RawUpdateSimulationRequestBody = DiscriminatedSimulationEventResponse<BaseUpdateSimulationRequestBody>; | ||
|
||
// Map all properties to be optional | ||
export type UpdateSimulationRequestBody = { | ||
[Key in keyof RawUpdateSimulationRequestBody]?: RawUpdateSimulationRequestBody[Key]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import type { IEventName } from '../../notifications'; | ||
import { | ||
type AddressCreatedEvent, | ||
type AddressImportedEvent, | ||
type AddressUpdatedEvent, | ||
type AdjustmentCreatedEvent, | ||
type AdjustmentUpdatedEvent, | ||
type BusinessCreatedEvent, | ||
type BusinessImportedEvent, | ||
type BusinessUpdatedEvent, | ||
type CustomerCreatedEvent, | ||
type CustomerImportedEvent, | ||
type CustomerUpdatedEvent, | ||
type DiscountCreatedEvent, | ||
type DiscountImportedEvent, | ||
type DiscountUpdatedEvent, | ||
type PayoutCreatedEvent, | ||
type PayoutPaidEvent, | ||
type PriceCreatedEvent, | ||
type PriceImportedEvent, | ||
type PriceUpdatedEvent, | ||
type ProductCreatedEvent, | ||
type ProductImportedEvent, | ||
type ProductUpdatedEvent, | ||
type ReportCreatedEvent, | ||
type ReportUpdatedEvent, | ||
type SubscriptionActivatedEvent, | ||
type SubscriptionCanceledEvent, | ||
type SubscriptionCreatedEvent, | ||
type SubscriptionImportedEvent, | ||
type SubscriptionPastDueEvent, | ||
type SubscriptionPausedEvent, | ||
type SubscriptionResumedEvent, | ||
type SubscriptionTrialingEvent, | ||
type SubscriptionUpdatedEvent, | ||
type TransactionBilledEvent, | ||
type TransactionCanceledEvent, | ||
type TransactionCompletedEvent, | ||
type TransactionCreatedEvent, | ||
type TransactionPaidEvent, | ||
type TransactionPastDueEvent, | ||
type TransactionPaymentFailedEvent, | ||
type TransactionReadyEvent, | ||
type TransactionUpdatedEvent, | ||
} from '../../notifications/events'; | ||
|
||
interface SimulationEventPayloadMap { | ||
'address.created': AddressCreatedEvent; | ||
'address.updated': AddressUpdatedEvent; | ||
'address.imported': AddressImportedEvent; | ||
'adjustment.created': AdjustmentCreatedEvent; | ||
'adjustment.updated': AdjustmentUpdatedEvent; | ||
'business.created': BusinessCreatedEvent; | ||
'business.updated': BusinessUpdatedEvent; | ||
'business.imported': BusinessImportedEvent; | ||
'customer.created': CustomerCreatedEvent; | ||
'customer.updated': CustomerUpdatedEvent; | ||
'customer.imported': CustomerImportedEvent; | ||
'discount.created': DiscountCreatedEvent; | ||
'discount.updated': DiscountUpdatedEvent; | ||
'discount.imported': DiscountImportedEvent; | ||
'payout.created': PayoutCreatedEvent; | ||
'payout.paid': PayoutPaidEvent; | ||
'price.created': PriceCreatedEvent; | ||
'price.updated': PriceUpdatedEvent; | ||
'price.imported': PriceImportedEvent; | ||
'product.created': ProductCreatedEvent; | ||
'product.updated': ProductUpdatedEvent; | ||
'product.imported': ProductImportedEvent; | ||
'subscription.created': SubscriptionCreatedEvent; | ||
'subscription.past_due': SubscriptionPastDueEvent; | ||
'subscription.activated': SubscriptionActivatedEvent; | ||
'subscription.canceled': SubscriptionCanceledEvent; | ||
'subscription.imported': SubscriptionImportedEvent; | ||
'subscription.paused': SubscriptionPausedEvent; | ||
'subscription.resumed': SubscriptionResumedEvent; | ||
'subscription.trialing': SubscriptionTrialingEvent; | ||
'subscription.updated': SubscriptionUpdatedEvent; | ||
'transaction.billed': TransactionBilledEvent; | ||
'transaction.canceled': TransactionCanceledEvent; | ||
'transaction.completed': TransactionCompletedEvent; | ||
'transaction.created': TransactionCreatedEvent; | ||
'transaction.paid': TransactionPaidEvent; | ||
'transaction.past_due': TransactionPastDueEvent; | ||
'transaction.payment_failed': TransactionPaymentFailedEvent; | ||
'transaction.ready': TransactionReadyEvent; | ||
'transaction.updated': TransactionUpdatedEvent; | ||
'report.created': ReportCreatedEvent; | ||
'report.updated': ReportUpdatedEvent; | ||
subscription_creation: never; | ||
subscription_renewal: never; | ||
subscription_pause: never; | ||
subscription_resume: never; | ||
subscription_cancellation: never; | ||
} | ||
|
||
export type DiscriminatedSimulationEventResponse<Base> = { | ||
[K in keyof SimulationEventPayloadMap]: Base & { | ||
type: K; | ||
payload?: K extends IEventName ? Partial<SimulationEventPayloadMap[K]['data']> | null : null; | ||
}; | ||
}[keyof SimulationEventPayloadMap]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters