Mirror of https://github.com/roostorg/coop
github.com/roostorg/coop
1import {
2 ScalarTypes,
3 type ScalarType,
4 type TaggedScalar,
5} from '@roostorg/types';
6
7import { type NormalizedItemData } from '../../services/itemProcessingService/index.js';
8import { type ItemType } from '../../services/moderationConfigService/index.js';
9import { hasOwn } from '../../utils/misc.js';
10
11export type TaggedItemData = Readonly<{
12 itemType: ItemType;
13 data: NormalizedItemData;
14}>;
15
16// We don't do `it: unknown` because our check here is really only precise enough
17// to distinguish TaggedContent from a few other types.
18export function isTaggedItemData(
19 it: TaggedItemData | TaggedScalar<ScalarType> | unknown[],
20): it is TaggedItemData {
21 return hasOwn(it, 'itemType');
22}
23
24export function isTranscribableType(
25 it: ScalarType,
26): it is ScalarTypes['AUDIO'] | ScalarTypes['VIDEO'] {
27 return it === ScalarTypes.AUDIO || it === ScalarTypes.VIDEO;
28}
29
30export function isTextValue<T extends ScalarType>(
31 it: TaggedScalar<T>,
32): it is TaggedScalar<T & ScalarTypes['STRING']> {
33 return it.type === ScalarTypes.STRING;
34}
35
36export function isTranscribableValue<T extends ScalarType>(
37 it: TaggedScalar<T>,
38): it is TaggedScalar<T & (ScalarTypes['AUDIO'] | ScalarTypes['VIDEO'])> {
39 return isTranscribableType(it.type);
40}