diff --git a/packages/react-native/src/types/bom.js.flow b/packages/react-native/src/types/bom.js.flow index 942e0c9c0d9..ff6ffcffca3 100644 --- a/packages/react-native/src/types/bom.js.flow +++ b/packages/react-native/src/types/bom.js.flow @@ -352,7 +352,6 @@ declare class Navigator usb?: USB; maxTouchPoints: number; permissions: Permissions; - serviceWorker?: ServiceWorkerContainer; getGamepads?: () => Array; webkitGetGamepads?: Function; mozGetGamepads?: Function; @@ -929,84 +928,6 @@ declare class WebSocket extends EventTarget { CLOSED: 3; } -type WorkerOptions = { - type?: WorkerType, - credentials?: CredentialsType, - name?: string, - ... -}; - -declare class Worker extends EventTarget { - constructor( - stringUrl: string | TrustedScriptURL, - workerOptions?: WorkerOptions, - ): void; - onerror: null | ((ev: any) => mixed); - onmessage: null | ((ev: MessageEvent) => mixed); - onmessageerror: null | ((ev: MessageEvent) => mixed); - postMessage(message: any, ports?: any): void; - terminate(): void; -} - -declare class SharedWorker extends EventTarget { - constructor(stringUrl: string | TrustedScriptURL, name?: string): void; - constructor( - stringUrl: string | TrustedScriptURL, - workerOptions?: WorkerOptions, - ): void; - port: MessagePort; - onerror: (ev: any) => mixed; -} - -declare function importScripts(...urls: Array): void; - -declare class WorkerGlobalScope extends EventTarget { - self: this; - location: WorkerLocation; - navigator: WorkerNavigator; - close(): void; - importScripts(...urls: Array): void; - onerror: (ev: any) => mixed; - onlanguagechange: (ev: any) => mixed; - onoffline: (ev: any) => mixed; - ononline: (ev: any) => mixed; - onrejectionhandled: (ev: PromiseRejectionEvent) => mixed; - onunhandledrejection: (ev: PromiseRejectionEvent) => mixed; -} - -declare class DedicatedWorkerGlobalScope extends WorkerGlobalScope { - onmessage: (ev: MessageEvent) => mixed; - onmessageerror: (ev: MessageEvent) => mixed; - postMessage(message: any, transfer?: Iterable): void; -} - -declare class SharedWorkerGlobalScope extends WorkerGlobalScope { - name: string; - onconnect: (ev: MessageEvent) => mixed; -} - -declare class WorkerLocation { - origin: string; - protocol: string; - host: string; - hostname: string; - port: string; - pathname: string; - search: string; - hash: string; -} - -declare class WorkerNavigator - mixins - NavigatorID, - NavigatorLanguage, - NavigatorOnLine, - NavigatorConcurrentHardware, - NavigatorStorage -{ - permissions: Permissions; -} - // deprecated declare class XDomainRequest { timeout: number; diff --git a/packages/react-native/src/types/serviceworkers.js.flow b/packages/react-native/src/types/serviceworkers.js.flow deleted file mode 100644 index 7d5077988d1..00000000000 --- a/packages/react-native/src/types/serviceworkers.js.flow +++ /dev/null @@ -1,257 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @oncall flow - */ - -// https://github.com/flow-typed/flow-typed/blob/main/definitions/environments/serviceworkers/flow_v0.261.x-/serviceworkers.js - -type FrameType = 'auxiliary' | 'top-level' | 'nested' | 'none'; -type VisibilityState = 'hidden' | 'visible' | 'prerender' | 'unloaded'; - -declare class WindowClient extends Client { - visibilityState: VisibilityState; - focused: boolean; - focus(): Promise; - navigate(url: string): Promise; -} - -declare class Client { - id: string; - reserved: boolean; - url: string; - frameType: FrameType; - postMessage(message: any, transfer?: Iterator | Array): void; -} - -declare class ExtendableEvent extends Event { - waitUntil(f: Promise): void; -} - -type NotificationEvent$Init = { - ...Event$Init, - notification: Notification, - action?: string, - ... -}; - -declare class NotificationEvent extends ExtendableEvent { - constructor(type: string, eventInitDict?: NotificationEvent$Init): void; - +notification: Notification; - +action: string; -} - -type ForeignFetchOptions = { - scopes: Iterator, - origins: Iterator, - ... -}; - -declare class InstallEvent extends ExtendableEvent { - registerForeignFetch(options: ForeignFetchOptions): void; -} - -declare class FetchEvent extends ExtendableEvent { - request: Request; - clientId: string; - isReload: boolean; - respondWith(response: Response | Promise): void; - preloadResponse: Promise; -} - -type ClientType = 'window' | 'worker' | 'sharedworker' | 'all'; -type ClientQueryOptions = { - includeUncontrolled?: boolean, - includeReserved?: boolean, - type?: ClientType, - ... -}; - -declare class Clients { - get(id: string): Promise; - matchAll(options?: ClientQueryOptions): Promise>; - openWindow(url: string): Promise; - claim(): Promise; -} - -type ServiceWorkerState = - | 'installing' - | 'installed' - | 'activating' - | 'activated' - | 'redundant'; - -declare class ServiceWorker extends EventTarget { - scriptURL: string; - state: ServiceWorkerState; - - postMessage(message: any, transfer?: Iterator): void; - - onstatechange?: EventHandler; -} - -declare class NavigationPreloadState { - enabled: boolean; - headerValue: string; -} - -declare class NavigationPreloadManager { - enable: Promise; - disable: Promise; - setHeaderValue(value: string): Promise; - getState: Promise; -} - -type PushSubscriptionOptions = { - userVisibleOnly?: boolean, - applicationServerKey?: string | ArrayBuffer | $ArrayBufferView, - ... -}; - -declare class PushSubscriptionJSON { - endpoint: string; - expirationTime: number | null; - keys: {[string]: string, ...}; -} - -declare class PushSubscription { - +endpoint: string; - +expirationTime: number | null; - +options: PushSubscriptionOptions; - getKey(name: string): ArrayBuffer | null; - toJSON(): PushSubscriptionJSON; - unsubscribe(): Promise; -} - -declare class PushManager { - +supportedContentEncodings: Array; - subscribe(options?: PushSubscriptionOptions): Promise; - getSubscription(): Promise; - permissionState( - options?: PushSubscriptionOptions, - ): Promise<'granted' | 'denied' | 'prompt'>; -} - -type ServiceWorkerUpdateViaCache = 'imports' | 'all' | 'none'; - -type GetNotificationOptions = { - tag?: string, - ... -}; - -declare class ServiceWorkerRegistration extends EventTarget { - +installing: ?ServiceWorker; - +waiting: ?ServiceWorker; - +active: ?ServiceWorker; - +navigationPreload: NavigationPreloadManager; - +scope: string; - +updateViaCache: ServiceWorkerUpdateViaCache; - +pushManager: PushManager; - - getNotifications?: ( - filter?: GetNotificationOptions, - ) => Promise<$ReadOnlyArray>; - showNotification?: ( - title: string, - options?: NotificationOptions, - ) => Promise; - update(): Promise; - unregister(): Promise; - - onupdatefound?: EventHandler; -} - -type WorkerType = 'classic' | 'module'; - -type RegistrationOptions = { - scope?: string, - type?: WorkerType, - updateViaCache?: ServiceWorkerUpdateViaCache, - ... -}; - -declare class ServiceWorkerContainer extends EventTarget { - +controller: ?ServiceWorker; - +ready: Promise; - - getRegistration( - clientURL?: string, - ): Promise; - getRegistrations(): Promise>; - register( - scriptURL: string | TrustedScriptURL, - options?: RegistrationOptions, - ): Promise; - startMessages(): void; - - oncontrollerchange?: EventHandler; - onmessage?: EventHandler; - onmessageerror?: EventHandler; -} - -/** - * This feature has been removed from the Web standards. - */ -declare class ServiceWorkerMessageEvent extends Event { - data: any; - lastEventId: string; - origin: string; - ports: Array; - source: ?(ServiceWorker | MessagePort); -} - -declare class ExtendableMessageEvent extends ExtendableEvent { - data: any; - lastEventId: string; - origin: string; - ports: Array; - source: ?(ServiceWorker | MessagePort); -} - -type CacheQueryOptions = { - ignoreSearch?: boolean, - ignoreMethod?: boolean, - ignoreVary?: boolean, - cacheName?: string, - ... -}; - -declare class Cache { - match(request: RequestInfo, options?: CacheQueryOptions): Promise; - matchAll( - request: RequestInfo, - options?: CacheQueryOptions, - ): Promise>; - add(request: RequestInfo): Promise; - addAll(requests: Array): Promise; - put(request: RequestInfo, response: Response): Promise; - delete(request: RequestInfo, options?: CacheQueryOptions): Promise; - keys( - request?: RequestInfo, - options?: CacheQueryOptions, - ): Promise>; -} - -declare class CacheStorage { - match(request: RequestInfo, options?: CacheQueryOptions): Promise; - has(cacheName: string): Promise; - open(cacheName: string): Promise; - delete(cacheName: string): Promise; - keys(): Promise>; -} - -// Service worker global scope -// https://www.w3.org/TR/service-workers/#service-worker-global-scope -declare var clients: Clients; -declare var caches: CacheStorage; -declare var registration: ServiceWorkerRegistration; -declare function skipWaiting(): Promise; -declare var onactivate: ?EventHandler; -declare var oninstall: ?EventHandler; -declare var onfetch: ?EventHandler; -declare var onforeignfetch: ?EventHandler; -declare var onmessage: ?EventHandler;