|
1 | 1 | import { DateTime } from "luxon"; |
2 | 2 |
|
3 | | -// A data provider provides a queryFn and a select function. The result of |
4 | | -// queryFn should be serializable and deserializable with JSON.stringify. THis |
5 | | -// means types like Date will not work, as they will be serialised to a string |
6 | | -// but not deserialised back to a Date. |
7 | | - |
8 | | -type LongOrShortString = { |
| 3 | +export type LongOrShortString = { |
9 | 4 | short: string; |
10 | 5 | long?: string; |
11 | 6 | }; |
12 | 7 |
|
13 | | -type Period = { |
| 8 | +export type Period = { |
14 | 9 | start: DateTime; |
15 | 10 | end: DateTime; |
16 | 11 | teacher?: LongOrShortString; |
17 | 12 | name?: LongOrShortString; |
18 | 13 | location?: LongOrShortString; |
19 | 14 | }; |
20 | 15 |
|
21 | | -export interface DataProvider { |
| 16 | +export const ContentEncodings = ["html", "markdown"] as const; |
| 17 | +export type ContentEncoding = typeof ContentEncodings[number]; |
| 18 | + |
| 19 | +export type Notice<TAudience> = { |
| 20 | + date: DateTime; |
| 21 | + title: string; |
| 22 | + content: string; |
| 23 | + content_encoding: ContentEncoding; |
| 24 | + audiences: TAudience[]; |
| 25 | + author: string; |
| 26 | +}; |
| 27 | + |
| 28 | +// Fetch output must be serialisable to JSON |
| 29 | +export interface DataProvider<TAudience> { |
22 | 30 | activate(): void; |
23 | 31 | deactivate(): void; |
24 | 32 | isActivated(): boolean; |
25 | 33 |
|
26 | | - // Returns a scan-on barcode if applicable |
27 | | - barcode?(): Promise<string>; |
| 34 | + config: { |
| 35 | + name: LongOrShortString; |
| 36 | + description: LongOrShortString; |
| 37 | + }; |
| 38 | + |
| 39 | + barcode?: { |
| 40 | + fetch: () => Promise<unknown>; |
| 41 | + parse: (data: unknown) => string; |
| 42 | + }; |
| 43 | + |
| 44 | + // Day Timetable |
| 45 | + dtt?: { |
| 46 | + fetch: (date: DateTime) => Promise<unknown>; |
| 47 | + parse: (data: unknown) => Period[]; |
| 48 | + }; |
| 49 | + |
| 50 | + cycle?: { |
| 51 | + fetch: () => Promise<unknown>; |
| 52 | + parse: (data: unknown) => Period[]; |
| 53 | + }; |
| 54 | + |
| 55 | + notices?: { |
| 56 | + fetch: () => Promise<unknown>; |
| 57 | + parse: (data: unknown) => Notice<TAudience>[]; |
| 58 | + }; |
| 59 | + |
| 60 | + newsletter?: { |
| 61 | + newsletterDownloadUrl: string; |
| 62 | + }; |
28 | 63 | } |
0 commit comments