how to differentiate Firehose destinations, i.e. toS3DeliveryStream
sam-goodwin opened this issue · comments
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
Yep - totally agree.
That's what Collectors
are:
(oops, loos like some comments need to be renamed from Enumerable):
punchcard/packages/punchcard/lib/stream/collector.ts
Lines 10 to 21 in 7a46089
toS3Deliverystream
is a wrapper around S3DeliveryStreamCollector
punchcard/packages/punchcard/lib/stream/collector.ts
Lines 45 to 52 in 7a46089
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)
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 :)