Skip to content

Commit

Permalink
Add update database to client (#170)
Browse files Browse the repository at this point in the history
* Add update database to client

* Fix typo

* Change response to Database

* Use the same type for both select and multi select options
  • Loading branch information
kiranpandit authored Aug 12, 2021
1 parent 6d78b48 commit dd115f4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ import {
BlocksUpdateParameters,
BlocksUpdateResponse,
blocksUpdate,
databasesUpdate,
DatabasesUpdateParameters,
DatabasesUpdateResponse,
} from "./api-endpoints"
import nodeFetch from "node-fetch"
import {
Expand Down Expand Up @@ -320,6 +323,21 @@ export default class Client {
auth: args?.auth,
})
},

/**
* Update a database
*/
update: (
args: WithAuth<DatabasesUpdateParameters>
): Promise<DatabasesUpdateResponse> => {
return this.request<DatabasesUpdateResponse>({
path: databasesUpdate.path(args),
method: databasesUpdate.method,
query: pick(args, databasesUpdate.queryParams),
body: pick(args, databasesUpdate.bodyParams),
auth: args?.auth,
})
},
}

public readonly pages = {
Expand Down
34 changes: 33 additions & 1 deletion src/api-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
PropertySchema,
RichTextInput,
UpdateBlock,
UpdatePropertySchema,
} from "./api-types"

// TODO: type assertions to verify that each interface is synchronized to the list of keys in the runtime value below.
Expand Down Expand Up @@ -267,7 +268,7 @@ export interface DatabasesCreateParameters
extends DatabasesCreatePathParameters,
DatabasesCreateQueryParameters,
DatabasesCreateBodyParameters {}
export interface DatabasesCreateResponse extends BlockBase {}
export interface DatabasesCreateResponse extends Database {}

export const databasesCreate = {
method: "post",
Expand All @@ -277,6 +278,37 @@ export const databasesCreate = {
path: () => `databases`,
} as const

/*
* databases.update()
*/

interface DatabasesUpdatePathParameters {
database_id: string
}
interface DatabasesUpdateQueryParameters {}

export type UpdatePropertySchemaMap = {
[propertyName: string]: UpdatePropertySchema
}
interface DatabasesUpdateBodyParameters {
properties?: UpdatePropertySchemaMap
title?: RichTextInput[]
}

export interface DatabasesUpdateParameters
extends DatabasesUpdatePathParameters,
DatabasesUpdateQueryParameters,
DatabasesUpdateBodyParameters {}
export interface DatabasesUpdateResponse extends Database {}

export const databasesUpdate = {
method: "patch",
pathParams: ["database_id"],
queryParams: [],
bodyParams: ["properties", "title"],
path: (d: DatabasesUpdatePathParameters) => `databases/${d.database_id}`,
} as const

/*
* pages.retrieve()
*/
Expand Down
24 changes: 24 additions & 0 deletions src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1040,3 +1040,27 @@ export interface LastEditedTimePropertySchema {
export interface LastEditedByPropertySchema {
last_edited_by: Record<string, never>
}

/*
* Update database property schema (input)
*/
export interface RenamePropertySchema {
name: string
}

type UpdateSelectOptionSchema = SelectOptionSchema | SelectOption

export interface UpdateSelectPropertySchema {
select: { options?: UpdateSelectOptionSchema[] }
}

export interface UpdateMultiSelectPropertySchema {
multi_select: { options?: UpdateSelectOptionSchema[] }
}

export type UpdatePropertySchema =
| PropertySchema
| UpdateSelectPropertySchema
| UpdateMultiSelectPropertySchema
| RenamePropertySchema
| null

0 comments on commit dd115f4

Please sign in to comment.