|
| 1 | +interface ExtendableEvent extends Event { |
| 2 | + waitUntil(fn: Promise<any>): void; |
| 3 | +} |
| 4 | + |
| 5 | +interface PushSubscriptionChangeEvent extends ExtendableEvent { |
| 6 | + readonly newSubscription?: PushSubscription; |
| 7 | + readonly oldSubscription?: PushSubscription; |
| 8 | +} |
| 9 | + |
| 10 | +// Client API |
| 11 | + |
| 12 | +declare class Client { |
| 13 | + frameType: ClientFrameType; |
| 14 | + id: string; |
| 15 | + url: string; |
| 16 | + focused: boolean; |
| 17 | + |
| 18 | + focus(): void; |
| 19 | + |
| 20 | + postMessage(message: any): void; |
| 21 | +} |
| 22 | + |
| 23 | +interface Clients { |
| 24 | + claim(): Promise<any>; |
| 25 | + |
| 26 | + get(id: string): Promise<Client>; |
| 27 | + |
| 28 | + matchAll(options?: ClientMatchOptions): Promise<Client[]>; |
| 29 | + |
| 30 | + openWindow(url: string): Promise<void>; |
| 31 | +} |
| 32 | + |
| 33 | +interface ClientMatchOptions { |
| 34 | + includeUncontrolled?: boolean; |
| 35 | + type?: ClientMatchTypes; |
| 36 | +} |
| 37 | + |
| 38 | +interface WindowClient { |
| 39 | + focused: boolean; |
| 40 | + visibilityState: WindowClientState; |
| 41 | + |
| 42 | + focus(): Promise<WindowClient>; |
| 43 | + |
| 44 | + navigate(url: string): Promise<WindowClient>; |
| 45 | +} |
| 46 | + |
| 47 | +type ClientFrameType = 'auxiliary' | 'top-level' | 'nested' | 'none'; |
| 48 | +type ClientMatchTypes = 'window' | 'worker' | 'sharedworker' | 'all'; |
| 49 | +type WindowClientState = 'hidden' | 'visible' | 'prerender' | 'unloaded'; |
| 50 | + |
| 51 | +// Fetch API |
| 52 | + |
| 53 | +interface FetchEvent extends ExtendableEvent { |
| 54 | + clientId: string | null; |
| 55 | + request: Request; |
| 56 | + |
| 57 | + respondWith(response: Promise<Response> | Response): Promise<Response>; |
| 58 | +} |
| 59 | + |
| 60 | +interface InstallEvent extends ExtendableEvent { |
| 61 | + activeWorker: ServiceWorker; |
| 62 | +} |
| 63 | + |
| 64 | +interface ActivateEvent extends ExtendableEvent {} |
| 65 | + |
| 66 | +// Notification API |
| 67 | + |
| 68 | +interface NotificationEvent extends ExtendableEvent { |
| 69 | + action: string; |
| 70 | + notification: Notification; |
| 71 | +} |
| 72 | + |
| 73 | +// Push API |
| 74 | + |
| 75 | +interface PushEvent extends ExtendableEvent { |
| 76 | + data: PushMessageData; |
| 77 | +} |
| 78 | + |
| 79 | +interface PushMessageData { |
| 80 | + arrayBuffer(): ArrayBuffer; |
| 81 | + |
| 82 | + blob(): Blob; |
| 83 | + |
| 84 | + json(): any; |
| 85 | + |
| 86 | + text(): string; |
| 87 | +} |
| 88 | + |
| 89 | +// Sync API |
| 90 | + |
| 91 | +interface SyncEvent extends ExtendableEvent { |
| 92 | + lastChance: boolean; |
| 93 | + tag: string; |
| 94 | +} |
| 95 | + |
| 96 | +interface ExtendableMessageEvent extends ExtendableEvent { |
| 97 | + data: any; |
| 98 | + source: Client | object; |
| 99 | +} |
| 100 | + |
| 101 | +// ServiceWorkerGlobalScope |
| 102 | + |
| 103 | +interface ServiceWorkerGlobalScope { |
| 104 | + __WB_DISABLE_DEV_LOGS: boolean; |
| 105 | + |
| 106 | + caches: CacheStorage; |
| 107 | + clients: Clients; |
| 108 | + registration: ServiceWorkerRegistration; |
| 109 | + |
| 110 | + addEventListener( |
| 111 | + event: 'activate', |
| 112 | + fn: (event?: ExtendableEvent) => any, |
| 113 | + ): void; |
| 114 | + |
| 115 | + addEventListener( |
| 116 | + event: 'message', |
| 117 | + fn: (event?: ExtendableMessageEvent) => any, |
| 118 | + ): void; |
| 119 | + |
| 120 | + addEventListener(event: 'fetch', fn: (event?: FetchEvent) => any): void; |
| 121 | + |
| 122 | + addEventListener( |
| 123 | + event: 'install', |
| 124 | + fn: (event?: ExtendableEvent) => any, |
| 125 | + ): void; |
| 126 | + |
| 127 | + addEventListener(event: 'push', fn: (event?: PushEvent) => any): void; |
| 128 | + |
| 129 | + addEventListener( |
| 130 | + event: 'notificationclick', |
| 131 | + fn: (event?: NotificationEvent) => any, |
| 132 | + ): void; |
| 133 | + |
| 134 | + addEventListener(event: 'sync', fn: (event?: SyncEvent) => any): void; |
| 135 | + |
| 136 | + fetch(request: Request | string): Promise<Response>; |
| 137 | + |
| 138 | + skipWaiting(): Promise<void>; |
| 139 | +} |
0 commit comments