Changeset View
Changeset View
Standalone View
Standalone View
web/types/worker-types.js
// @flow | // @flow | ||||
import type { ClientDBStoreOperations } from 'lib/types/store-ops-types.js'; | import type { | ||||
ClientDBStore, | |||||
ClientDBStoreOperations, | |||||
} from 'lib/types/store-ops-types.js'; | |||||
// The types of messages sent from app to worker | // The types of messages sent from app to worker | ||||
export const workerRequestMessageTypes = Object.freeze({ | export const workerRequestMessageTypes = Object.freeze({ | ||||
PING: 0, | PING: 0, | ||||
INIT: 1, | INIT: 1, | ||||
GENERATE_DATABASE_ENCRYPTION_KEY: 2, | GENERATE_DATABASE_ENCRYPTION_KEY: 2, | ||||
PROCESS_STORE_OPERATIONS: 3, | PROCESS_STORE_OPERATIONS: 3, | ||||
GET_CLIENT_STORE: 4, | |||||
}); | }); | ||||
export type PingWorkerRequestMessage = { | export type PingWorkerRequestMessage = { | ||||
+type: 0, | +type: 0, | ||||
+text: string, | +text: string, | ||||
}; | }; | ||||
export type InitWorkerRequestMessage = { | export type InitWorkerRequestMessage = { | ||||
+type: 1, | +type: 1, | ||||
+sqljsFilePath: string, | +sqljsFilePath: string, | ||||
+sqljsFilename: ?string, | +sqljsFilename: ?string, | ||||
}; | }; | ||||
export type GenerateDatabaseEncryptionKeyRequestMessage = { | export type GenerateDatabaseEncryptionKeyRequestMessage = { | ||||
+type: 2, | +type: 2, | ||||
}; | }; | ||||
export type ProcessStoreOperationsRequestMessage = { | export type ProcessStoreOperationsRequestMessage = { | ||||
+type: 3, | +type: 3, | ||||
+storeOperations: ClientDBStoreOperations, | +storeOperations: ClientDBStoreOperations, | ||||
}; | }; | ||||
export type GetClientStoreRequestMessage = { | |||||
+type: 4, | |||||
}; | |||||
export type WorkerRequestMessage = | export type WorkerRequestMessage = | ||||
| PingWorkerRequestMessage | | PingWorkerRequestMessage | ||||
| InitWorkerRequestMessage | | InitWorkerRequestMessage | ||||
| GenerateDatabaseEncryptionKeyRequestMessage | | GenerateDatabaseEncryptionKeyRequestMessage | ||||
| ProcessStoreOperationsRequestMessage; | | ProcessStoreOperationsRequestMessage | ||||
| GetClientStoreRequestMessage; | |||||
export type WorkerRequestProxyMessage = { | export type WorkerRequestProxyMessage = { | ||||
+id: number, | +id: number, | ||||
+message: WorkerRequestMessage, | +message: WorkerRequestMessage, | ||||
}; | }; | ||||
// The types of messages sent from worker to app | // The types of messages sent from worker to app | ||||
export const workerResponseMessageTypes = Object.freeze({ | export const workerResponseMessageTypes = Object.freeze({ | ||||
PONG: 0, | PONG: 0, | ||||
CLIENT_STORE: 1, | |||||
}); | }); | ||||
export type PongWorkerResponseMessage = { | export type PongWorkerResponseMessage = { | ||||
+type: 0, | +type: 0, | ||||
+text: string, | +text: string, | ||||
}; | }; | ||||
export type WorkerResponseMessage = PongWorkerResponseMessage; | export type ClientStoreResponseMessage = { | ||||
+type: 1, | |||||
+store: ClientDBStore, | |||||
}; | |||||
export type WorkerResponseMessage = | |||||
| PongWorkerResponseMessage | |||||
| ClientStoreResponseMessage; | |||||
export type WorkerResponseProxyMessage = { | export type WorkerResponseProxyMessage = { | ||||
+id?: number, | +id?: number, | ||||
+message?: WorkerResponseMessage, | +message?: WorkerResponseMessage, | ||||
+error?: Error, | +error?: Error, | ||||
}; | }; | ||||
// SharedWorker types | // SharedWorker types | ||||
export type SharedWorkerMessageEvent = MessageEvent & { | export type SharedWorkerMessageEvent = MessageEvent & { | ||||
+ports: $ReadOnlyArray<MessagePort>, | +ports: $ReadOnlyArray<MessagePort>, | ||||
... | ... | ||||
}; | }; |