Fix JSDoc (#171)
[poolifier.git] / src / utility-types.ts
... / ...
CommitLineData
1import type { Worker } from 'cluster'
2import type { MessagePort } from 'worker_threads'
3import type { KillBehavior } from './worker/worker-options'
4
5/**
6 * Make all properties in T non-readonly
7 */
8export type Draft<T> = { -readonly [P in keyof T]?: T[P] }
9
10/**
11 * Serializable primitive JSON value.
12 */
13export type JSONPrimitive = number | boolean | string | null
14/**
15 * Serializable JSON value.
16 */
17// eslint-disable-next-line no-use-before-define
18export type JSONValue = JSONPrimitive | JSONArray | JSONObject
19/**
20 * Serializable JSON object.
21 */
22export type JSONObject = { [k: string]: JSONValue }
23/**
24 * Serializable JSON array.
25 */
26export type JSONArray = Array<JSONValue>
27
28/**
29 * Message object that is passed between worker and main worker.
30 */
31export interface MessageValue<
32 Data = unknown,
33 MainWorker extends Worker | MessagePort | unknown = unknown
34> {
35 /**
36 * Input data that will be passed to the worker.
37 */
38 readonly data?: Data
39 /**
40 * ID of the message.
41 */
42 readonly id?: number
43 /**
44 * Kill code.
45 */
46 readonly kill?: KillBehavior | 1
47 /**
48 * Error.
49 */
50 readonly error?: string
51 /**
52 * Reference to main worker.
53 *
54 * _Only for internal use_
55 */
56 readonly parent?: MainWorker
57}