-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDependency.js
46 lines (42 loc) · 1.15 KB
/
Dependency.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const DynamoTable = require('./DynamoTable')
const DynamoStream = require('./DynamoStream')
const ElasticsearchIndex = require('./ElasticsearchIndex')
const S3Bucket = require('./S3Bucket')
const KinesisStream = require('./KinesisStream')
const Dependency = {}
/**
* @name Dependency.teardown
*
* @synopsis
* ```coffeescript [specscript]
* teardown(
* dependency DynamoTable|DynamoStream
* |ElasticsearchIndex|S3Bucket
* |KinesisStream
* ) -> Promise<>
* ```
*/
Dependency.teardown = async function teardown(dependency) {
if (dependency == null) {
// noop
}
else if (dependency.constructor == DynamoTable) {
await dependency.delete()
}
else if (dependency.constructor == DynamoStream) {
dependency.close()
}
else if (dependency.constructor == ElasticsearchIndex) {
await dependency.delete()
}
else if (dependency.constructor == S3Bucket) {
await dependency.deleteAllObjects()
await dependency.delete()
}
else if (dependency.constructor == KinesisStream) {
dependency.close()
await dependency.delete()
}
dependency?.timers?.forEach(clearInterval)
}
module.exports = Dependency