chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:34:48 +08:00
commit 77bb5bf71f
3762 changed files with 353249 additions and 0 deletions
@@ -0,0 +1,3 @@
export const reverseScale = (value: number, min: number, max: number) => max - _clamp(value, min, max) + min
const _clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value))
@@ -0,0 +1,2 @@
export * from './response-mapping'
export * from './request-mapping'
@@ -0,0 +1,38 @@
import { Task as TodoistTask, AddTaskArgs, UpdateTaskArgs } from '@doist/todoist-api-typescript'
import { CreateTaskRequest, Task, UpdateTaskRequest } from '../types'
import { reverseScale } from './common/math-utils'
export namespace RequestMapping {
const MAX_PRIORITY = 1
const MIN_PRIORITY = 4
export const mapCreateTask = (task: CreateTaskRequest): AddTaskArgs => ({
content: task.content,
description: task.description,
projectId: task.projectId,
sectionId: task.sectionId,
parentId: task.parentTaskId,
order: task.positionWithinParent,
labels: task.labels,
priority: _mapPriority(task.priority ?? MIN_PRIORITY),
dueString: task.dueDate,
assigneeId: task.assignee,
..._mapDuration(task.duration),
})
export const mapUpdateTask = (task: UpdateTaskRequest): UpdateTaskArgs => ({
content: task.content,
description: task.description,
labels: task.labels,
priority: _mapPriority(task.priority ?? MIN_PRIORITY),
dueString: task.dueDate,
assigneeId: task.assignee,
..._mapDuration(task.duration),
})
const _mapPriority = (priority: Task['priority']): TodoistTask['priority'] =>
reverseScale(priority, MIN_PRIORITY, MAX_PRIORITY)
const _mapDuration = (duration: Task['duration']) =>
duration ? { duration: duration.amount, durationUnit: duration.unit } : {}
}
@@ -0,0 +1,72 @@
import {
Task as TodoistTask,
Project as TodoistProject,
Comment as TodoistComment,
Section as TodoistSection,
} from '@doist/todoist-api-typescript'
import * as entities from 'definitions/entities'
import { Task, Project, Comment, PickRequired, Section } from '../types'
import { reverseScale } from './common/math-utils'
export namespace ResponseMapping {
const MAX_PRIORITY = 4
const MIN_PRIORITY = 1
export const mapTask = (todoistTask: TodoistTask): Task => ({
id: todoistTask.id,
content: todoistTask.content,
description: todoistTask.description,
priority: mapPriority(todoistTask.priority),
projectId: todoistTask.projectId,
parentTaskId: todoistTask.parentId ?? undefined,
isCompleted: todoistTask.isCompleted,
labels: todoistTask.labels,
createdAt: todoistTask.createdAt,
dueDate: _mapDueDate(todoistTask.due),
isRecurringDueDate: todoistTask.due?.isRecurring ?? false,
createdBy: todoistTask.creatorId,
assignee: todoistTask.assigneeId ?? undefined,
assigner: todoistTask.assignerId ?? undefined,
numberOfComments: todoistTask.commentCount,
positionWithinParent: todoistTask.order,
webUrl: todoistTask.url,
duration: todoistTask.duration ?? undefined,
sectionId: todoistTask.sectionId ?? undefined,
})
export const mapProject = (todoistProject: TodoistProject): Project => ({
id: todoistProject.id,
name: todoistProject.name,
parentProjectId: todoistProject.parentId ?? undefined,
positionWithinParent: todoistProject.order,
color: _mapColor(todoistProject.color),
isFavorite: todoistProject.isFavorite,
isInboxProject: todoistProject.isInboxProject,
isShared: todoistProject.isShared,
isTeamInbox: todoistProject.isTeamInbox,
numberOfComments: todoistProject.commentCount,
webUrl: todoistProject.url,
})
export const mapSection = (todoistSection: TodoistSection): Section => ({
id: todoistSection.id,
name: todoistSection.name,
projectId: todoistSection.projectId,
positionWithinParent: todoistSection.order,
})
export const mapTaskComment = (todoistComment: TodoistComment): Comment & PickRequired<Comment, 'taskId'> => ({
id: todoistComment.id,
postedAt: todoistComment.postedAt,
content: todoistComment.content,
taskId: todoistComment.taskId as string,
})
export const mapPriority = (priority: TodoistTask['priority']): Task['priority'] =>
reverseScale(priority, MIN_PRIORITY, MAX_PRIORITY)
const _mapDueDate = (dueDate: TodoistTask['due']) => dueDate?.datetime ?? dueDate?.date
const _mapColor = (color: TodoistProject['color']): Project['color'] =>
entities.Color.names.includes(color as Project['color']) ? (color as Project['color']) : 'charcoal'
}