Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | 3x 22x 1x 21x 3x 8x 2x 6x 3x 5x 1x 4x 3x 3x 2x 1x 1x 3x 5x 3x 6x 5x 5x 5x 3x 1x 2x 3x 3x 1x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 6x 1x 2x 3x 4x 4x 1x 3x 1x 2x 3x 2x 2x 1x 1x 3x 2x 2x 1x 1x | import type {
CreateTaskRequest,
MonthStatsRequest,
ReorderTasksRequest,
ResizeWindowRequest,
StartTimerRequest,
UpdateTaskRequest,
WindowDragRequest
} from '@shared/contracts'
import { isPlainObject } from '@shared/settingsValidation'
const requireObject = (value: unknown, channel: string): Record<string, unknown> => {
if (!isPlainObject(value)) {
throw new Error(`${channel} request must be an object`)
}
return value
}
const requireNonEmptyString = (value: unknown, label: string): string => {
if (typeof value !== 'string' || value.trim().length === 0) {
throw new Error(`${label} must be a non-empty string`)
}
return value
}
const requireString = (value: unknown, label: string): string => {
if (typeof value !== 'string') {
throw new Error(`${label} must be a string`)
}
return value
}
export const getOptionalTaskId = (value: unknown, channel: string): string | null => {
if (value === null) return null
if (typeof value !== 'string' || value.trim().length === 0) {
throw new Error(`${channel} taskId must be a non-empty string or null`)
}
return value
}
export const getTaskId = (value: unknown, channel: string): string =>
requireNonEmptyString(value, `${channel} id`)
export const getStartTimerRequest = (value: unknown): StartTimerRequest => {
if (value === undefined) return {}
const request = requireObject(value, 'timer.start')
const result: StartTimerRequest = {}
if (Object.prototype.hasOwnProperty.call(request, 'phase')) {
if (request.phase !== 'focus' && request.phase !== 'shortBreak' && request.phase !== 'longBreak') {
throw new Error('timer.start phase is invalid')
}
result.phase = request.phase
}
Eif (Object.prototype.hasOwnProperty.call(request, 'taskId')) {
if (request.taskId !== null && typeof request.taskId !== 'string') {
throw new Error('timer.start taskId must be a string or null')
}
result.taskId = request.taskId
}
return result
}
export const getCreateTaskRequest = (value: unknown): CreateTaskRequest => {
const request = requireObject(value, 'tasks.create')
return { title: requireString(request.title, 'tasks.create title') }
}
export const getUpdateTaskRequest = (value: unknown): UpdateTaskRequest => {
const request = requireObject(value, 'tasks.update')
return {
id: requireNonEmptyString(request.id, 'tasks.update id'),
title: requireString(request.title, 'tasks.update title')
}
}
export const getReorderTasksRequest = (value: unknown): ReorderTasksRequest => {
const request = requireObject(value, 'tasks.reorder')
if (!Array.isArray(request.ids) || !request.ids.every((id) => typeof id === 'string')) {
throw new Error('tasks.reorder ids must contain only strings')
}
return { ids: request.ids }
}
export const getMonthStatsRequest = (value: unknown): MonthStatsRequest => {
const request = requireObject(value, 'stats.getMonth')
if (!Number.isInteger(request.year)) {
throw new Error('stats.getMonth year must be an integer')
}
if (!Number.isInteger(request.month) || Number(request.month) < 1 || Number(request.month) > 12) {
throw new Error('stats.getMonth month must be between 1 and 12')
}
return { year: Number(request.year), month: Number(request.month) }
}
export const getResizeWindowRequest = (value: unknown): ResizeWindowRequest => {
const request = requireObject(value, 'system.resizeWindow')
if (
typeof request.width !== 'number' ||
typeof request.height !== 'number' ||
!Number.isFinite(request.width) ||
!Number.isFinite(request.height) ||
request.width <= 0 ||
request.height <= 0
) {
throw new Error('system.resizeWindow width and height must be finite positive numbers')
}
return { width: request.width, height: request.height }
}
export const getWindowDragRequest = (value: unknown): WindowDragRequest => {
const request = requireObject(value, 'system.windowDrag')
if (
typeof request.pointerScreenX !== 'number' ||
typeof request.pointerScreenY !== 'number' ||
!Number.isFinite(request.pointerScreenX) ||
!Number.isFinite(request.pointerScreenY)
) {
throw new Error('system.windowDrag coordinates must be finite numbers')
}
return { pointerScreenX: request.pointerScreenX, pointerScreenY: request.pointerScreenY }
}
|