/
wkof.d.ts
executable file
·692 lines (643 loc) · 22.3 KB
/
wkof.d.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
type SrsName = 'lock' | 'init' | 'appr1' | 'appr2' | 'appr3' | 'appr4' | 'guru1' | 'guru2' | 'mast' | 'enli' | 'burn'
type SrsNumber = -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
type SubjectType = 'vocabulary' | 'kanji' | 'radical' | 'kana_vocabulary'
type SubjectTypeString =
| `${SubjectType}`
| `${SubjectType},${SubjectType}`
| `${SubjectType},${SubjectType},${SubjectType}`
type SubjectTypeShort = 'voc' | 'kan' | 'rad'
type SubjectTypeShortString =
| `${SubjectTypeShort}`
| `${SubjectTypeShort},${SubjectTypeShort}`
| `${SubjectTypeShort},${SubjectTypeShort},${SubjectTypeShort}`
type IsoDateString = `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`
declare namespace Core {
type FileCache = {
dir: {
[key: string]: {
added: IsoDateString
last_loaded: IsoDateString
}
}
save: (name: string, content: string | { [key: string]: any }) => Promise<string>
load: (name: string) => Promise<string | { [key: string]: any }>
delete: (name: string | RegExp) => Promise<undefined>
clear: () => Promise<undefined>
}
export type Module = {
version: {
value: string
compare_to: (needed_version: string) => 'older' | 'same' | 'newer'
}
include: (modules: string) => Promise<{ loaded: string[]; failed: string[] }>
ready: (modules: string) => Promise<'ready'>
get_state: (state_var: string) => any
set_state: (state_var: string, value: any) => void
wait_state: (
state_var: string,
value: any,
callback: (new_value: any, prev_value: any) => void,
persistent: boolean,
) => void
on: (event: string, callback: () => void) => void
trigger: (event: string) => undefined
support_files: { [key: string]: string }
load_file: (url: string, use_cache?: boolean) => Promise<any>
load_script: (url: string, use_cache?: boolean) => Promise<string | undefined>
load_css: (url: string, use_cache?: boolean) => Promise<string | undefined>
file_cache: FileCache
}
}
declare namespace Apiv2 {
type ApiEndpoint =
| 'assignments'
| 'level_progressions'
| 'resets'
| 'reviews'
| 'review_statistics'
| 'spaced_repetition_systems'
| 'study_materials'
| 'subjects'
| 'summary'
| 'user'
| 'voice_actors'
type Defaults = {
/**
* @remark Comma separated list of integers
*/
ids?: string
updated_after?: IsoDateString
}
type LevelProgressions = {} & Defaults
type Resets = {} & Defaults
type SpacedRepetitionSystems = {} & Defaults
type VoiceActors = {} & Defaults
type Assignments = {
available_after?: IsoDateString
available_before?: IsoDateString
burned?: boolean
hidden?: boolean
/**
* @remark Value not needed
*/
immediately_available_for_lessons?: any
/**
* @remark Value not needed
*/
immediately_available_for_review?: any
/**
* @remark Value not needed
*/
in_review?: any
/**
* @remark Comma separated list of integers
*/
levels?: string
/**
* @remark Comma separated list of integers
*/
srs_stages?: string
started?: boolean
/**
* @remark Comma separated list of integers
*/
subject_ids?: string
subject_types?: SubjectTypeString
unlocked?: boolean
} & Defaults
type Reviews = {
assignment_id?: number
created_at?: IsoDateString
ending_srs_stage?: number
incorrect_meaning_answers?: number
incorrect_reading_answers?: number
spaced_repetition_system_id?: number
starting_srs_stage?: number
subject_id?: number
}
type ReviewStatistics = {
percentages_greater_than?: number
percentages_less_than?: number
/**
* @remark Comma separated list of integers
*/
subject_ids?: string
} & Defaults
type StudyMaterials = {
hidden?: boolean
/**
* @remark Comma separated list of integers
*/
subject_ids?: string
subject_types?: SubjectTypeString
} & Defaults
type Subjects = {
types?: SubjectTypeString
/**
* @remark Comma separated list of slugs
*/
slugs?: string
/**
* @remark Comma separated list of levels
*/
levels?: string
hidden?: boolean
} & Defaults
type Filter =
| Assignments
| LevelProgressions
| Resets
| Reviews
| ReviewStatistics
| SpacedRepetitionSystems
| StudyMaterials
| Subjects
| VoiceActors
type FetchEndpointOptions = {
progress_callback?: (endpoint_name: ApiEndpoint, first_new: number, so_far: number, total: number) => void
last_update?: Date | IsoDateString
filters?: Filter
}
type GetEndpointOptions = {
progress_callback?: (endpoint_name: ApiEndpoint, first_new: number, so_far: number, total: number) => void
force_update?: boolean
}
type User = {
apikey: string
current_vacation_started_at: null | IsoDateString
id: string
level: number
preferences: {
default_voice_actor: number
extra_study_autoplay_audio: boolean
lessons_autoplay_audio: boolean
lessons_batch_size: number
lessons_presentation_order: string
reviews_autoplay_audio: boolean
reviews_display_srs_indicator: boolean
wanikani_compatibility_mode: boolean
}
profile_url: string
started_at: IsoDateString
subscription: {
active: boolean
max_level_granted: number
period_ends_at: null | IsoDateString
type: string
}
username: string
}
export type Module = {
Apiv2: {
user: string
key: string
fetch_endpoint: (endpoint_name: ApiEndpoint, options?: FetchEndpointOptions) => Promise<any>
get_endpoint: (endpoint_name: ApiEndpoint, options?: GetEndpointOptions) => Promise<any>
clear_cache: (include_non_user?: boolean) => Promise<undefined>
apiv2_is_valid_apikey_format: (apikey: string) => boolean
spoof: (key: string) => void
}
user: User
}
}
declare namespace ItemData {
type IndexOptions =
| 'level'
| 'item_type'
| 'reading'
| 'slug'
| 'srs_stage'
| 'srs_stage_name'
| 'subject_id'
| string
type Item = {
url: string
object: SubjectType
id: number
data_updated_at: IsoDateString
data: {
auxiliary_meanings: {
meaning: string
type: 'whitelist' | 'blacklist'
}[]
characters: string
character_images?: {
content_type: string
url: string
metadata: {
color?: string
dimensions?: `${number}x${number}`
style_name?: string
inline_styles?: boolean
}
}[]
component_subject_ids: number[]
context_sentences: {
en: string
ja: string
}[]
created_at: IsoDateString
document_url: string
hidden_at: null | IsoDateString
lesson_position: number
level: number
meaning_hint?: string
meaning_mnemonic: string
meanings: {
accepted_answer: boolean
meaning: string
primary: boolean
}[]
parts_of_speech: string[]
pronunciation_audios: {
url: string
metadata: {
gender: string
pronunciation: string
source_id: number
voice_actor_id: number
voice_actor_name: string
voice_description: string
}
content_type: string
}[]
reading_hint?: string
reading_mnemonic: string
readings: {
accepted_answer: boolean
primary: boolean
reading: string
type?: 'kunyomi' | 'onyomi' | 'nanori'
}[]
slug: string
spaced_repetition_system_id: number
}
assignments?: {
available_at: null | IsoDateString
burned_at: null | IsoDateString
created_at: IsoDateString
hidden: boolean
passed_at: null | IsoDateString
resurrected_at: null | IsoDateString
/**
* @remark 0 = init, 1 = appr1, etc
*/
srs_stage: SrsNumber
started_at: null | IsoDateString
subject_id: number
subject_type: SubjectType
unlocked_at: string
}
review_statistics?: {
created_at: IsoDateString
hidden: boolean
meaning_correct: number
meaning_current_streak: number
meaning_incorrect: number
meaning_max_streak: number
percentage_correct: number
reading_correct: number
reading_current_streak: number
reading_incorrect: number
reading_max_streak: number
subject_id: number
subject_type: SubjectType
}
study_materials?: {
created_at: IsoDateString
hidden: boolean
reading_note?: string
meaning_note?: string
subject_id: number
subject_type: SubjectType
meaning_synonyms: string[]
}
}
type FilterCanInvert<T> = T | { value: T; invert: boolean }
namespace GetItems {
type Endpoint = 'subjects' | 'assignments' | 'review_statistics' | 'study_materials'
type EndpointString =
| `${Endpoint}`
| `${Endpoint},${Endpoint}`
| `${Endpoint},${Endpoint},${Endpoint}`
| `${Endpoint},${Endpoint},${Endpoint},${Endpoint}`
type Options = {
[key: string]: any
assignments?: boolean
review_statistics?: boolean
study_materials?: boolean
include_hidden?: boolean
}
type Filters = {
[key: string]: FilterCanInvert<any>
item_type?: FilterCanInvert<SubjectTypeShortString | SubjectTypeShort[]>
/**
* @remark A comma separated list of Wanikani levels or level ranges
*/
level?: FilterCanInvert<string>
/**
* @remark String is comma separated list of possible values
*/
srs?: FilterCanInvert<string | (SrsName | SrsNumber)[]>
have_burned?: FilterCanInvert<boolean>
}
type SourceConfig = {
options?: Options
filters?: Filters
}
type Config = EndpointString | { [key: string]: SourceConfig }
}
namespace Registry {
type Filter<T> = {
type: string
default: T
label?: string
hover_tip?: string
placeholder?: T
content?: { [key: string]: any }
no_ui?: boolean
filter_func: (filter_value: T, item: Item) => boolean
filter_value_map?: (filter_value: any) => T
set_options?: (options: GetItems.Options) => void
}
type Registry = {
sources: {
[key: string]: {
description: string
fetcher: (...any) => Promise<{ [key: string]: any }>
filters: { [key: string]: Filter<any> }
options: { [key: string]: any }
}
wk_items: {
description: 'Wanikani'
fetcher: (
config: GetItems.SourceConfig,
options: Apiv2.GetEndpointOptions,
) => Promise<{ [key: string]: Item }>
filters: {
[key: string]: Filter<any>
have_burned: {
type: 'checkbox'
default: true
label: 'Have burned'
hover_tip: 'Filter items by whether they have ever been burned.\n * If checked, select burned items (including resurrected)\n * If unchecked, select items that have never been burned'
filter_func: (filter_value: boolean, item: Item) => boolean
set_options: (options: GetItems.Options) => void
} & Filter<any>
item_type: {
type: 'multi'
default: []
label: 'Item type'
hover_tip: 'Filter by item type (radical, kanji, vocabulary)'
content: {
radical: 'Radicals'
kanji: 'Kanji'
vocabulary: 'Vocabulary'
}
filter_value_map: (filter_value: SubjectTypeShort[] | SubjectTypeShortString) => {
[key: string]: boolean
}
filter_func: (filter_value: { [key: string]: boolean }, item: Item) => boolean
} & Filter<any>
level: {
type: 'text'
default: ''
label: 'SRS Level'
hover_tip: 'Filter by Wanikani level\nExamples:\n"*" (All levels)\n"1..3,5" (Levels 1 through 3, and level 5)\n"1..-1" (From level 1 to your current level minus 1)\n"-5..+0" (Your current level and previous 5 levels)\n"+1" (Your next level)'
placeholder: '(e.g. "1..3,5")'
filter_value_map: (filter_value: string) => { [key: number]: boolean }
filter_func: (filter_value: { [key: number]: boolean }, item: Item) => boolean
} & Filter<any>
srs: {
type: 'multi'
default: []
label: 'SRS Level'
hover_tip: 'Filter by SRS level (Apprentice 1, Apprentice 2, ..., Burn)'
content: {
appr1: 'Apprentice 1'
appr2: 'Apprentice 2'
appr3: 'Apprentice 3'
appr4: 'Apprentice 4'
burn: 'Burned'
enli: 'Enlightened'
guru1: 'Guru 1'
guru2: 'Guru 2'
init: 'Initiate (Lesson Queue)'
lock: 'Locked'
mast: 'Master'
}
filter_value_map: (filter_value: string | SrsName[]) => { [key: string]: boolean }
filter_func: (filter_value: { [key: string]: boolean }, item: Item) => boolean
set_options: (options: GetItems.Options) => void
} & Filter<any>
}
options: {
assignments: {
type: 'checkbox'
label: 'Assignments'
default: false
hover_tip: 'Include the "/assignments" endpoint (SRS status, burn status, progress dates)'
}
review_statistics: {
type: 'checkbox'
label: 'Review Statistics'
default: false
hover_tip: 'Include the "/review_statistics" endpoint:\n * Per-item review count\n *Correct/incorrect count\n * Longest streak'
}
study_materials: {
type: 'checkbox'
label: 'Study Materials'
default: false
hover_tip: 'Include the "/study_materials" endpoint:\n * User synonyms\n * User notes'
}
}
}
}
indices: {
[key: string]: (items: Item[]) => { [key: string]: Item[] | Item }
item_type: (items: Item[]) => { [key: string]: Item[] }
level: (items: Item[]) => { [key: string]: Item[] }
reading: (items: Item[]) => { [key: string]: Item[] }
slug: (items: Item[]) => { [key: string]: Item[] | Item }
srs_stage: (items: Item[]) => { [key: string]: Item[] }
srs_stage_name: (items: Item[]) => { [key: string]: Item[] }
subject_id: (items: Item[]) => { [key: string]: Item[] }
}
}
}
export type Module = {
ItemData: {
get_items: (config?: GetItems.Config) => Promise<Item[]>
get_index: <T = Item[] | Item>(items: Item[], index_name: IndexOptions) => { [key: string]: T }
registry: Registry.Registry
pause_ready_event: (value: boolean) => void
}
}
}
declare namespace Menu {
export type Module = {
Menu: {
insert_script_link: (config: {
name: string
submenu?: string
title: string
class?: string
on_click: (event: any) => void
}) => void
}
}
}
declare namespace Settings {
type OnChange = (name: string, value: any, config: Component) => void
type Validate = (value: any, config: Component) => boolean | string | { valid: boolean; msg: string }
type ComponentDefaults = {
label?: string
hover_tip?: string
full_width?: boolean
validate?: Validate
on_change?: OnChange
path?: string
refresh_on_change?: boolean
}
type Section = {
type: 'section'
label?: string
}
type Divider = {
type: 'divider'
}
type Group = {
type: 'group'
label?: string
content: { [key: string]: Component }
}
type List = {
type: 'list'
size?: number
content: { [key: string]: string }
} & ({ multi?: false; default?: string } | { multi?: true; default: { [key: string]: boolean } }) &
ComponentDefaults
type Dropdown = {
type: 'dropdown'
default?: string
content: { [key: string]: string }
} & ComponentDefaults
type Checkbox = {
type: 'checkbox'
default?: boolean
} & ComponentDefaults
type Input = {
type: 'input'
subtype?: string
default: string
} & ComponentDefaults
type Number = {
type: 'number'
placeholder?: string
default?: number
min?: number
max?: number
} & ComponentDefaults
type Text = {
type: 'text'
default?: string
placeholder?: string
match?: RegExp
} & ComponentDefaults
type Color = {
type: 'color'
default?: string
} & ComponentDefaults
type Button = {
type: 'button'
text?: string
on_click: (name: string, config: Component, on_change: () => void) => void
} & ComponentDefaults
type Html = {
type: 'html'
label?: string
html: string
}
type Page = {
type: 'page'
label: string
hover_tip?: string
content: { [key: string]: Component }
}
type Tabset = {
type: 'tabset'
content: { [key: string]: Page }
}
type Component =
| Tabset
| Page
| Section
| Divider
| Group
| List
| Dropdown
| Checkbox
| Input
| Number
| Text
| Color
| Button
| Html
type Dialog = {
open: () => Promise<undefined>
load: () => Promise<{ [key: string]: any }>
save: () => Promise<undefined>
refresh: () => void
background: {
open: () => void
close: () => void
}
close: (save_pending_changes?: boolean) => void
cancel: () => void
}
type Config = {
script_id: string
title: string
autosave?: boolean
background?: boolean
no_bkgd?: boolean
/**
* @param dialog jQuery DOM element of dialog box
*/
pre_open?: (dialog: JQuery) => void
on_save?: (settings: { [key: string]: any }) => void
on_cancel?: (settings: { [key: string]: any }) => void
on_close?: (settings: { [key: string]: any }) => void
on_change?: OnChange
on_refresh?: (settings: { [key: string]: any }) => void
content: { [key: string]: Component }
}
export type Module = {
Settings: {
new (config: Config): Dialog
save: (script_id: string) => Promise<undefined>
load: (script_id: string, defaults?: { [key: string]: any }) => Promise<{ [key: string]: any }>
}
settings: {
[key: string]: {
[key: string]: any
}
}
}
}
declare namespace Progress {
export type Module = {
Progress: {
update: (progress: { name: string; label: string; value: number; max: number }) => void
}
}
}
/**
* @remark To include modules use WKOF & Module
*/
export type WKOF = Core.Module
export type Apiv2 = Apiv2.Module
export type ItemData = ItemData.Module
export type Menu = Menu.Module
export type Settings = Settings.Module
export type Progress = Progress.Module