-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.ts
50 lines (44 loc) · 1.45 KB
/
example.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { optionDefinition } from '@addonlib/addonlib';
import AbstractMedia from '../AbstractMedia';
import { basicMediaDetails } from '../mediaTypes';
import AbstractMediaSource from '../source/AbstractMediaSource';
import {
mediaSourceFetchOption,
mediaSourceFetchResult,
mediaSourceSettings,
} from '../source/mediaSourceTypes';
type MyMediaDetails = { description: string } & basicMediaDetails;
class MyMedia<
T extends MyMediaDetails = MyMediaDetails
> extends AbstractMedia<T> {}
type myMediaSourceFetchOption = { title: string } & mediaSourceFetchOption;
class MyMediaSource<
T extends mediaSourceSettings = mediaSourceSettings,
U extends myMediaSourceFetchOption = myMediaSourceFetchOption,
V extends mediaSourceFetchResult = mediaSourceFetchResult
> extends AbstractMediaSource<T, U, V> {
public fetch(options: U): Promise<V> {
return Promise.resolve({
content: [
new MyMedia({
title: options.title,
description: 'description of ' + options.title,
id: 'id-' + options.title,
}),
],
} as unknown as V);
}
public getFetchOptionsDefinition(): Promise<optionDefinition<U>> {
return Promise.resolve({
title: {
type: 'string',
required: true,
},
} as unknown as optionDefinition<U>);
}
}
const myMediaSource = new MyMediaSource();
myMediaSource
.fetch({ title: 'wantedTitle' })
.then((res) => res.content)
.then((content) => console.log(content));