Repository URL to install this package:
|
Version:
0.6.0 ▾
|
gateway-proxy
/
usr
/
share
/
gateway-proxy
/
app
/
node_modules
/
furious-commander
/
src
/
aggregation.ts
|
|---|
import { Command } from './command'
const aggregationMetadataKey = Symbol('Aggregation')
export interface AggregationData {
command: string
property: string
}
export function findFirstAggregration(command: Command): AggregationData | null {
// eslint-disable-next-line guard-for-in
for (const key in command) {
const aggregation = getAggregation(command, key)
if (aggregation) {
return {
command: aggregation.join(' '),
property: key,
}
}
}
return null
}
/**
* Aggregate the aimed Command class provided by `cliPath` and assigns its value to the property
*
* @param cliPath chain of command class names until the desired class instance
*/
export function Aggregation(cliPath: string[]): PropertyDecorator {
return Reflect.metadata(aggregationMetadataKey, cliPath)
}
/**
* Get the aggregation metadata on the given property
*
* @param target Command instance
* @param propertyKey Property of the command instance
*
* @returns CLI path of the aggregated relation
*/
export function getAggregation<T extends Command, K extends Extract<keyof T, string>>(
target: T,
propertyKey: K,
): string[] {
return Reflect.getMetadata(aggregationMetadataKey, target, propertyKey)
}