Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update types to be consistent with documentation #244

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/TodoistApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import {
Comment,
} from './types/entities'
import {
AddCommentArgs,
AddLabelArgs,
AddProjectArgs,
AddSectionArgs,
AddProjectCommentArgs,
AddTaskArgs,
AddTaskCommentArgs,
GetProjectCommentsArgs,
GetTaskCommentsArgs,
GetTasksArgs,
Expand All @@ -24,6 +23,7 @@ import {
UpdateSectionArgs,
UpdateTaskArgs,
QuickAddTaskArgs,
GetSharedLabelsArgs,
RenameSharedLabelArgs,
RemoveSharedLabelArgs,
} from './types/requests'
Expand Down Expand Up @@ -398,12 +398,13 @@ export class TodoistApi {
return isSuccess(response)
}

async getSharedLabels(): Promise<string[]> {
async getSharedLabels(args?: GetSharedLabelsArgs): Promise<string[]> {
const response = await request<string[]>(
'GET',
this.restApiBase,
ENDPOINT_REST_LABELS_SHARED,
this.authToken,
args,
)

return response.data
Expand Down Expand Up @@ -453,10 +454,7 @@ export class TodoistApi {
return validateComment(response.data)
}

async addComment(
args: AddTaskCommentArgs | AddProjectCommentArgs,
requestId?: string,
): Promise<Comment> {
async addComment(args: AddCommentArgs, requestId?: string): Promise<Comment> {
const response = await request<Comment>(
'POST',
this.restApiBase,
Expand Down
4 changes: 2 additions & 2 deletions src/authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('authentication', () => {

const successfulTokenResponse = {
accessToken: 'AToken',
state: 'AState',
tokenType: 'Bearer',
}

test('calls request with expected values', async () => {
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('authentication', () => {
test('throws error if token not present in response', async () => {
const missingTokenResponse = {
accessToken: undefined,
state: 'AState',
tokenType: undefined,
}

setupRestClientMock(missingTokenResponse)
Expand Down
2 changes: 1 addition & 1 deletion src/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Permission =

export type AuthTokenResponse = {
accessToken: string
state: string
tokenType: string
}

export type AuthTokenRequestArgs = {
Expand Down
4 changes: 4 additions & 0 deletions src/types/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const DueDate = Record({
Partial({
datetime: String.Or(Null),
timezone: String.Or(Null),
lang: String.Or(Null),
}),
)

Expand Down Expand Up @@ -93,6 +94,9 @@ export const Project = Record({

export type Project = Static<typeof Project>

// This allows us to accept any string during validation, but provide intellisense for the two possible values in request args
export type ProjectViewStyle = 'list' | 'board'

export const Section = Record({
id: String,
order: Int,
Expand Down
57 changes: 28 additions & 29 deletions src/types/requests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RequireAllOrNone } from 'type-fest'
import type { Duration } from './entities'
import type { RequireAllOrNone, RequireOneOrNone, RequireExactlyOne } from 'type-fest'
import type { Duration, ProjectViewStyle } from './entities'

export type AddTaskArgs = {
content: string
Expand All @@ -10,15 +10,17 @@ export type AddTaskArgs = {
order?: number
labels?: string[]
priority?: number
dueString?: string
dueLang?: string
assigneeId?: string
dueString?: string
} & RequireOneOrNone<{
dueDate?: string
dueDatetime?: string
assigneeId?: string
} & RequireAllOrNone<{
duration?: Duration['amount']
durationUnit?: Duration['unit']
}>
}> &
RequireAllOrNone<{
duration?: Duration['amount']
durationUnit?: Duration['unit']
}>

export type QuickAddTaskArgs = {
text: string
Expand All @@ -41,17 +43,17 @@ export type UpdateTaskArgs = {
description?: string
labels?: string[]
priority?: number
dueString?: string | null
dueLang?: string | null
dueDate?: string | null
dueDatetime?: string | null
assigneeId?: string | null
} & RequireAllOrNone<{
duration?: Duration['amount']
durationUnit?: Duration['unit']
}>

export type ProjectViewStyle = 'list' | 'board'
dueString?: string
} & RequireOneOrNone<{
dueDate?: string
dueDatetime?: string
}> &
RequireAllOrNone<{
duration?: Duration['amount']
durationUnit?: Duration['unit']
}>

export type AddProjectArgs = {
name: string
Expand Down Expand Up @@ -102,30 +104,27 @@ export type GetProjectCommentsArgs = {
taskId?: never
}

type AddCommentArgs = {
export type AddCommentArgs = {
content: string
attachment?: {
fileName?: string
fileUrl: string
fileType?: string
resourceType?: string
}
}

export type AddTaskCommentArgs = AddCommentArgs & {
taskId: string
projectId?: never
}

export type AddProjectCommentArgs = AddCommentArgs & {
projectId: string
taskId?: never
}
} & RequireExactlyOne<{
taskId?: string
projectId?: string
}>

export type UpdateCommentArgs = {
content: string
}

export type GetSharedLabelsArgs = {
omitPersonal?: boolean
}

export type RenameSharedLabelArgs = {
name: string
newName: string
Expand Down