21838: Add tags to unionize for easier saga usage
[arvados.git] / services / workbench2 / src / common / unionize.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { unionize as originalUnionize, SingleValueRec } from 'unionize';
6
7 export * from 'unionize';
8
9 type TagRecord<Record> = { [T in keyof Record]: T };
10
11 export function unionize<Record extends SingleValueRec>(record: Record) {
12     const tags = {} as TagRecord<Record>;
13     for (const tag in record) {
14         tags[tag] = tag;
15     }
16     return {...originalUnionize(record, {
17         tag: 'type',
18         value: 'payload'
19     }), tags};
20 }