(params: Dictionary)
| 65 | * @internal |
| 66 | */ |
| 67 | export function processDecoratorParameters<T>(params: Dictionary): T { |
| 68 | const keys = Object.keys(params); |
| 69 | const values = Object.values(params); |
| 70 | |
| 71 | if (!Utils.isPlainObject(values[0])) { |
| 72 | const lastKey = keys[keys.length - 1]; |
| 73 | const last = params[lastKey]; |
| 74 | delete params[lastKey]; |
| 75 | |
| 76 | return { ...last, ...params }; |
| 77 | } |
| 78 | |
| 79 | // validate only first parameter is used if its an option object |
| 80 | const empty = (v: unknown) => v == null || (Utils.isPlainObject(v) && !Utils.hasObjectKeys(v)); |
| 81 | if (values.slice(1).some(v => !empty(v))) { |
| 82 | throw new Error( |
| 83 | 'Mixing first decorator parameter as options object with other parameters is forbidden. ' + |
| 84 | 'If you want to use the options parameter at first position, provide all options inside it.', |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | return values[0] as T; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Validate there is only one property decorator. This disallows using `@Property()` together with e.g. `@ManyToOne()` |
no test coverage detected