Skip to content

Commit fc59a9c

Browse files
authored
chore: move complex response types to own exported types (#266)
1 parent 1211ded commit fc59a9c

File tree

4 files changed

+71
-43
lines changed

4 files changed

+71
-43
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@doist/todoist-api-typescript",
3-
"version": "4.0.0-alpha.1",
3+
"version": "4.0.0-alpha.2",
44
"description": "A typescript wrapper for the Todoist REST API.",
55
"author": "Doist developers",
66
"repository": "[email protected]:doist/todoist-api-typescript.git",

src/TodoistApi.ts

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import { String } from 'runtypes'
2-
import {
3-
Task,
4-
QuickAddTaskResponse,
5-
Project,
6-
Label,
7-
User,
8-
Section,
9-
Comment,
10-
} from './types/entities'
2+
import { Task, QuickAddTaskResponse, Project, Label, Section, Comment } from './types/entities'
113
import {
124
AddCommentArgs,
135
AddLabelArgs,
@@ -28,8 +20,15 @@ import {
2820
RemoveSharedLabelArgs,
2921
GetProjectsArgs,
3022
GetProjectCollaboratorsArgs,
31-
GetSections,
3223
GetLabelsArgs,
24+
GetLabelsResponse,
25+
GetTasksResponse,
26+
GetProjectsResponse,
27+
GetProjectCollaboratorsResponse,
28+
GetSectionsArgs,
29+
GetSectionsResponse,
30+
GetSharedLabelsResponse,
31+
GetCommentsResponse,
3332
} from './types/requests'
3433
import { request, isSuccess } from './restClient'
3534
import { getTaskFromQuickAddResponse } from './utils/taskConverters'
@@ -93,16 +92,16 @@ export class TodoistApi {
9392
return validateTask(response.data)
9493
}
9594

96-
async getTasks(args: GetTasksArgs = {}): Promise<{
97-
results: Task[]
98-
nextCursor: string | null
99-
}> {
95+
async getTasks(args: GetTasksArgs = {}): Promise<GetTasksResponse> {
10096
const {
10197
data: { results, nextCursor },
102-
} = await request<{
103-
results: Task[]
104-
nextCursor: string | null
105-
}>('GET', this.syncApiBase, ENDPOINT_REST_TASKS, this.authToken, args)
98+
} = await request<GetTasksResponse>(
99+
'GET',
100+
this.syncApiBase,
101+
ENDPOINT_REST_TASKS,
102+
this.authToken,
103+
args,
104+
)
106105

107106
return {
108107
results: validateTaskArray(results),
@@ -201,12 +200,10 @@ export class TodoistApi {
201200
return validateProject(response.data)
202201
}
203202

204-
async getProjects(
205-
args: GetProjectsArgs = {},
206-
): Promise<{ results: Project[]; nextCursor: string | null }> {
203+
async getProjects(args: GetProjectsArgs = {}): Promise<GetProjectsResponse> {
207204
const {
208205
data: { results, nextCursor },
209-
} = await request<{ results: Project[]; nextCursor: string | null }>(
206+
} = await request<GetProjectsResponse>(
210207
'GET',
211208
this.syncApiBase,
212209
ENDPOINT_REST_PROJECTS,
@@ -262,11 +259,11 @@ export class TodoistApi {
262259
async getProjectCollaborators(
263260
projectId: string,
264261
args: GetProjectCollaboratorsArgs = {},
265-
): Promise<{ results: User[]; nextCursor: string | null }> {
262+
): Promise<GetProjectCollaboratorsResponse> {
266263
String.check(projectId)
267264
const {
268265
data: { results, nextCursor },
269-
} = await request<{ results: User[]; nextCursor: string | null }>(
266+
} = await request<GetProjectCollaboratorsResponse>(
270267
'GET',
271268
this.syncApiBase,
272269
generatePath(ENDPOINT_REST_PROJECTS, projectId, ENDPOINT_REST_PROJECT_COLLABORATORS),
@@ -280,12 +277,10 @@ export class TodoistApi {
280277
}
281278
}
282279

283-
async getSections(
284-
args: GetSections,
285-
): Promise<{ results: Section[]; nextCursor: string | null }> {
280+
async getSections(args: GetSectionsArgs): Promise<GetSectionsResponse> {
286281
const {
287282
data: { results, nextCursor },
288-
} = await request<{ results: Section[]; nextCursor: string | null }>(
283+
} = await request<GetSectionsResponse>(
289284
'GET',
290285
this.syncApiBase,
291286
ENDPOINT_REST_SECTIONS,
@@ -368,12 +363,10 @@ export class TodoistApi {
368363
/**
369364
* Fetches the personal labels
370365
*/
371-
async getLabels(
372-
args: GetLabelsArgs = {},
373-
): Promise<{ results: Label[]; nextCursor: string | null }> {
366+
async getLabels(args: GetLabelsArgs = {}): Promise<GetLabelsResponse> {
374367
const {
375368
data: { results, nextCursor: nextCursor },
376-
} = await request<{ results: Label[]; nextCursor: string | null }>(
369+
} = await request<GetLabelsResponse>(
377370
'GET',
378371
this.syncApiBase,
379372
ENDPOINT_REST_LABELS,
@@ -435,12 +428,10 @@ export class TodoistApi {
435428
return isSuccess(response)
436429
}
437430

438-
async getSharedLabels(
439-
args?: GetSharedLabelsArgs,
440-
): Promise<{ results: string[]; nextCursor: string | null }> {
431+
async getSharedLabels(args?: GetSharedLabelsArgs): Promise<GetSharedLabelsResponse> {
441432
const {
442433
data: { results, nextCursor: nextCursor },
443-
} = await request<{ results: string[]; nextCursor: string | null }>(
434+
} = await request<GetSharedLabelsResponse>(
444435
'GET',
445436
this.syncApiBase,
446437
ENDPOINT_REST_LABELS_SHARED,
@@ -477,10 +468,10 @@ export class TodoistApi {
477468

478469
async getComments(
479470
args: GetTaskCommentsArgs | GetProjectCommentsArgs,
480-
): Promise<{ results: Comment[]; nextCursor: string | null }> {
471+
): Promise<GetCommentsResponse> {
481472
const {
482473
data: { results, nextCursor },
483-
} = await request<{ results: Comment[]; nextCursor: string | null }>(
474+
} = await request<GetCommentsResponse>(
484475
'GET',
485476
this.syncApiBase,
486477
ENDPOINT_REST_COMMENTS,

src/types/requests.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import type { RequireAllOrNone, RequireOneOrNone, RequireExactlyOne } from 'type-fest'
2-
import type { Duration, ProjectViewStyle } from './entities'
2+
import type {
3+
Comment,
4+
Duration,
5+
Label,
6+
Project,
7+
ProjectViewStyle,
8+
Section,
9+
Task,
10+
User,
11+
} from './entities'
312

413
export type AddTaskArgs = {
514
content: string
@@ -42,6 +51,10 @@ export type GetTasksArgs = {
4251
cursor?: string | null
4352
limit?: number
4453
}
54+
export type GetTasksResponse = {
55+
results: Task[]
56+
nextCursor: string | null
57+
}
4558

4659
export type UpdateTaskArgs = {
4760
content?: string
@@ -66,6 +79,10 @@ export type GetProjectsArgs = {
6679
cursor?: string | null
6780
limit?: number
6881
}
82+
export type GetProjectsResponse = {
83+
results: Project[]
84+
nextCursor: string | null
85+
}
6986

7087
export type AddProjectArgs = {
7188
name: string
@@ -86,12 +103,20 @@ export type GetProjectCollaboratorsArgs = {
86103
cursor?: string | null
87104
limit?: number
88105
}
106+
export type GetProjectCollaboratorsResponse = {
107+
results: User[]
108+
nextCursor: string | null
109+
}
89110

90-
export type GetSections = {
111+
export type GetSectionsArgs = {
91112
projectId: string | null
92113
cursor?: string | null
93114
limit?: number
94115
}
116+
export type GetSectionsResponse = {
117+
results: Section[]
118+
nextCursor: string | null
119+
}
95120

96121
export type AddSectionArgs = {
97122
name: string
@@ -107,6 +132,10 @@ export type GetLabelsArgs = {
107132
cursor?: string | null
108133
limit?: number
109134
}
135+
export type GetLabelsResponse = {
136+
results: Label[]
137+
nextCursor: string | null
138+
}
110139

111140
export type AddLabelArgs = {
112141
name: string
@@ -126,6 +155,10 @@ export type GetCommentsBaseArgs = {
126155
cursor?: string | null
127156
limit?: number
128157
}
158+
export type GetCommentsResponse = {
159+
results: Comment[]
160+
nextCursor: string | null
161+
}
129162

130163
export type GetTaskCommentsArgs = GetCommentsBaseArgs & {
131164
taskId: string
@@ -159,6 +192,10 @@ export type GetSharedLabelsArgs = {
159192
cursor?: string | null
160193
limit?: number
161194
}
195+
export type GetSharedLabelsResponse = {
196+
results: string[]
197+
nextCursor: string | null
198+
}
162199

163200
export type RenameSharedLabelArgs = {
164201
name: string

0 commit comments

Comments
 (0)