Mirror of https://github.com/roostorg/coop github.com/roostorg/coop
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 557ff54b2b435e5f1e789c6a8a4e1bebf2d7deb6 45 lines 1.3 kB view raw
1import _ from 'lodash'; 2import { type Opaque, type UnwrapOpaque } from 'type-fest'; 3 4import { instantiateOpaqueType } from '../../utils/typescript-types.js'; 5import { 6 type ItemType, 7 type ItemTypeIdentifier, 8} from '../moderationConfigService/index.js'; 9import { type ItemSubmission } from './makeItemSubmission.js'; 10 11const { omit } = _; 12 13export type ItemSubmissionWithTypeIdentifier<Type extends ItemType = ItemType> = 14 Opaque< 15 Omit<UnwrapOpaque<ItemSubmission<Type>>, 'itemType'> & { 16 itemTypeIdentifier: ItemTypeIdentifier; 17 }, 18 'ItemSubmissionWithTypeIdentifier' 19 >; 20 21export function itemSubmissionToItemSubmissionWithTypeIdentifier( 22 it: ItemSubmission, 23) { 24 return instantiateOpaqueType<ItemSubmissionWithTypeIdentifier>({ 25 ...omit(it, 'itemType'), 26 itemTypeIdentifier: { 27 id: it.itemType.id, 28 version: it.itemType.version, 29 schemaVariant: it.itemType.schemaVariant, 30 }, 31 }); 32} 33 34export function itemSubmissionWithTypeIdentifierToItemSubmission< 35 T extends ItemType = ItemType, 36>(it: ItemSubmissionWithTypeIdentifier, type: T) { 37 return instantiateOpaqueType<ItemSubmission<T>>({ 38 submissionId: it.submissionId, 39 submissionTime: it.submissionTime, 40 itemId: it.itemId, 41 creator: it.creator, 42 data: it.data, 43 itemType: type, 44 }); 45}