summaryrefslogtreecommitdiff
path: root/shared/apps-common/src/jet/prefetched-intents/types.ts
blob: b44a14be02009ebe6397afe7ee58d9ed93e77150 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { Intent } from '@jet/environment/dispatching';

export interface PrefetchedIntent {
    intent: Intent<unknown>;
    data: unknown;
}

export function isPrefetchedIntents(v: unknown): v is PrefetchedIntent[] {
    return Array.isArray(v) && v.every(isPrefetchedIntent);
}

function isPrefetchedIntent(v: unknown): v is PrefetchedIntent {
    return hasIntentAndData(v) && isIntent(v.intent);
}

function hasIntentAndData(v: unknown): v is HasIntentAndData {
    return v !== null && typeof v === 'object' && 'intent' in v && 'data' in v;
}

interface HasIntentAndData {
    intent: unknown;
    data: unknown;
}

function isIntent(v: unknown): v is Intent<unknown> {
    return v !== null && typeof v === 'object' && '$kind' in v;
}