sam-goodwin / punchcard

Type-safe AWS infrastructure.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to differentiate Firehose destinations, i.e. toS3DeliveryStream

sam-goodwin opened this issue · comments

commented

As per #26

For the toX methods, we are adopting the convention to{ServiceName}{Resource}. This works well, except for Firehose Delivery Streams, where there are many targets (S3, Elastic, Redshift, Splunk, etc.).

Currently, there is only support for S3 with toS3DeliveryStream. How do we want to differentiate these going forward?

maybe accept a class instantiated somewhere else as a parameter, then act accordingly, like a strategy pattern. this way there could be more classes added in the future without adding extra resources, treat those as subresources? would need to shift things around a bit though

commented

Yep - totally agree.

That's what Collectors are:

(oops, loos like some comments need to be renamed from Enumerable):

/**
* Collects data from an `Enumerable`.
*
* @param T type of collected result
* @param E source enumerable
*/
export interface Collector<T, E extends Stream<any, any, any, any>> {
/**
* Create constructs to collect data from the enumerable an
*/
collect(scope: core.Construct, id: string, enumerable: E): T
}

toS3Deliverystream is a wrapper around S3DeliveryStreamCollector

/**
* Collects data from an `Enumerable` into S3 via a Firehose Delivery Stream.
*
* @param props stream properties
*/
export function toS3DeliveryStream<T extends Type<any>>(props: S3DeliveryStreamForType<T>): S3DeliveryStreamCollector<T, any> {
return new S3DeliveryStreamCollector<T, any>(props);
}

hmm I see, I guess that would be an edge case to be more than a simple factory method then. maybe use an overloaded toS3DeliveryStream? the props would need to be split for that to be type safe, or try to infer from the parameters (thinking mostly for TS, tbh)

commented

Oh, good idea! Yeah, we could distinguish the return type based on the input type.

Something like:

// return type is CollectedElasticSearchDomain (or something)
stream.toFirehoseDeliveryStream({
  elasticSearchIndex: 'my-index-name', 
  elasticSearchDomain: myDomain // optional, one might be created automatically? Is that craziness?
});

Punchcard is only for TS :)