Changeset View
Changeset View
Standalone View
Standalone View
web/types/worker-types.js
// @flow | // @flow | ||||
import type { | import type { | ||||
ClientDBStore, | ClientDBStore, | ||||
ClientDBStoreOperations, | ClientDBStoreOperations, | ||||
} from 'lib/types/store-ops-types.js'; | } 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, | GET_CLIENT_STORE: 4, | ||||
SET_CURRENT_USER_ID: 5, | |||||
GET_CURRENT_USER_ID: 6, | |||||
}); | }); | ||||
export type PingWorkerRequestMessage = { | export type PingWorkerRequestMessage = { | ||||
+type: 0, | +type: 0, | ||||
+text: string, | +text: string, | ||||
}; | }; | ||||
export type InitWorkerRequestMessage = { | export type InitWorkerRequestMessage = { | ||||
Show All 10 Lines | export type ProcessStoreOperationsRequestMessage = { | ||||
+type: 3, | +type: 3, | ||||
+storeOperations: ClientDBStoreOperations, | +storeOperations: ClientDBStoreOperations, | ||||
}; | }; | ||||
export type GetClientStoreRequestMessage = { | export type GetClientStoreRequestMessage = { | ||||
+type: 4, | +type: 4, | ||||
}; | }; | ||||
export type SetCurrentUserIDRequestMessage = { | |||||
+type: 5, | |||||
+userID: string, | |||||
}; | |||||
export type GetCurrentUserIDRequestMessage = { | |||||
+type: 6, | |||||
}; | |||||
export type WorkerRequestMessage = | export type WorkerRequestMessage = | ||||
| PingWorkerRequestMessage | | PingWorkerRequestMessage | ||||
| InitWorkerRequestMessage | | InitWorkerRequestMessage | ||||
| GenerateDatabaseEncryptionKeyRequestMessage | | GenerateDatabaseEncryptionKeyRequestMessage | ||||
| ProcessStoreOperationsRequestMessage | | ProcessStoreOperationsRequestMessage | ||||
| GetClientStoreRequestMessage; | | GetClientStoreRequestMessage | ||||
| SetCurrentUserIDRequestMessage | |||||
| GetCurrentUserIDRequestMessage; | |||||
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, | CLIENT_STORE: 1, | ||||
GET_CURRENT_USER_ID: 2, | |||||
}); | }); | ||||
export type PongWorkerResponseMessage = { | export type PongWorkerResponseMessage = { | ||||
+type: 0, | +type: 0, | ||||
+text: string, | +text: string, | ||||
}; | }; | ||||
export type ClientStoreResponseMessage = { | export type ClientStoreResponseMessage = { | ||||
+type: 1, | +type: 1, | ||||
+store: ClientDBStore, | +store: ClientDBStore, | ||||
}; | }; | ||||
export type GetCurrentUserIDResponseMessage = { | |||||
+type: 2, | |||||
+userID: ?string, | |||||
}; | |||||
export type WorkerResponseMessage = | export type WorkerResponseMessage = | ||||
| PongWorkerResponseMessage | | PongWorkerResponseMessage | ||||
| ClientStoreResponseMessage; | | ClientStoreResponseMessage | ||||
| GetCurrentUserIDResponseMessage; | |||||
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>, | ||||
... | ... | ||||
}; | }; |