-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsns.ts
More file actions
29 lines (24 loc) · 1.04 KB
/
sns.ts
File metadata and controls
29 lines (24 loc) · 1.04 KB
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
import { CLASS_SNSCONFIGURATIONKEY } from '../constants'
import { getMetadata, defineMetadata } from '../metadata'
import { applyTemplates } from '../templates'
import { environment } from './environment'
export const sns = (snsConfig?: {
topicName?: string,
environmentKey?: string,
exists?: boolean
}) => (target: Function) => {
let snsDefinitions = getMetadata(CLASS_SNSCONFIGURATIONKEY, target) || [];
snsConfig = snsConfig || {}
snsConfig.topicName = snsConfig.topicName || `%ClassName%-topic`
snsConfig.environmentKey = snsConfig.environmentKey || `%ClassName%_SNS_TOPICNAME`
const { templatedKey, templatedValue } = applyTemplates(snsConfig.environmentKey, snsConfig.topicName, target)
snsDefinitions.push({
...snsConfig,
environmentKey: templatedKey,
topicName: templatedValue,
definedBy: target.name
})
defineMetadata(CLASS_SNSCONFIGURATIONKEY, [...snsDefinitions], target)
const environmentSetter = environment(templatedKey, templatedValue)
environmentSetter(target)
}