-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
47 lines (38 loc) · 1.95 KB
/
api.ts
File metadata and controls
47 lines (38 loc) · 1.95 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Resource } from './resource'
import { getFunctionName } from '../annotations/classes/functionName'
import { defineMetadata, getMetadata, constants, getClassConfigValue } from '../annotations'
const { CLASS_ENVIRONMENTKEY, CLASS_CLASSCONFIGKEY, PARAMETER_PARAMKEY } = constants
export class Api extends Resource {
constructor(...params) {
super();
}
public async init(): Promise<any> {
}
public static onDefineInjectTo(target, targetKey, parameterIndex: number) {
super.onDefineInjectTo(target, targetKey, parameterIndex)
const configEnvironmentKey = getClassConfigValue('injectServiceCopyMetadataKey', this)
if (configEnvironmentKey) {
const injectKeyConfig = (getMetadata(configEnvironmentKey, this) || [])
.map(c => { return { ...c, injected: true } })
const keyConfig = getMetadata(configEnvironmentKey, target) || []
defineMetadata(configEnvironmentKey, [...keyConfig, ...injectKeyConfig], target);
}
const targetTkey = 'handle'
const injectedDefinitions: any[] = (getMetadata(PARAMETER_PARAMKEY, this) || [])
.filter(p => p.type === 'inject')
for (const { serviceType, targetKey, parameterIndex } of injectedDefinitions) {
if (typeof serviceType.onDefineInjectTo === 'function') {
serviceType.onDefineInjectTo(target, targetTkey, parameterIndex)
}
}
}
public static toEventSource(target: Function) {
const environmentKey = getClassConfigValue('injectServiceEventSourceKey', this)
if (environmentKey) {
const metadataCollection = getMetadata(environmentKey, target) || []
const eventSourceConfigs = (getMetadata(environmentKey, this) || [])
.map(config => { return { ...config, eventSource: true } })
defineMetadata(environmentKey, [...metadataCollection, ...eventSourceConfigs], target)
}
}
}