Skip to content

Commit 2f22e9e

Browse files
chore(docs): use top-level-await in example snippets
1 parent 425627d commit 2f22e9e

1 file changed

Lines changed: 17 additions & 29 deletions

File tree

README.md

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@ const client = new Grid({
2727
apiKey: "YOUR_API_KEY",
2828
});
2929

30-
async function main() {
31-
const response = await client.workbooks.query('YOUR_WORKBOOK_ID', {
32-
read: ['A1', 'Sheet2!B3', '=SUM(A1:A4)'],
33-
});
34-
35-
console.log(response.read);
36-
}
30+
const response = await client.workbooks.query('YOUR_WORKBOOK_ID', {
31+
read: ['A1', 'Sheet2!B3', '=SUM(A1:A4)'],
32+
});
3733

38-
main();
34+
console.log(response.read);
3935
```
4036

4137
### Request & Response types
@@ -48,12 +44,8 @@ import Grid from '@grid-is/api';
4844

4945
const client = new Grid();
5046

51-
async function main() {
52-
const params: Grid.WorkbookQueryParams = { read: ['A1', 'Sheet2!B3', '=SUM(A1:A4)'] };
53-
const response: Grid.WorkbookQueryResponse = await client.workbooks.query('YOUR_WORKBOOK_ID', params);
54-
}
55-
56-
main();
47+
const params: Grid.WorkbookQueryParams = { read: ['A1', 'Sheet2!B3', '=SUM(A1:A4)'] };
48+
const response: Grid.WorkbookQueryResponse = await client.workbooks.query('YOUR_WORKBOOK_ID', params);
5749
```
5850

5951
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
@@ -95,21 +87,17 @@ a subclass of `APIError` will be thrown:
9587

9688
<!-- prettier-ignore -->
9789
```ts
98-
async function main() {
99-
const response = await client.workbooks
100-
.query('YOUR_WORKBOOK_ID', { read: ['A1', 'Sheet2!B3', '=SUM(A1:A4)'] })
101-
.catch(async (err) => {
102-
if (err instanceof Grid.APIError) {
103-
console.log(err.status); // 400
104-
console.log(err.name); // BadRequestError
105-
console.log(err.headers); // {server: 'nginx', ...}
106-
} else {
107-
throw err;
108-
}
109-
});
110-
}
111-
112-
main();
90+
const response = await client.workbooks
91+
.query('YOUR_WORKBOOK_ID', { read: ['A1', 'Sheet2!B3', '=SUM(A1:A4)'] })
92+
.catch(async (err) => {
93+
if (err instanceof Grid.APIError) {
94+
console.log(err.status); // 400
95+
console.log(err.name); // BadRequestError
96+
console.log(err.headers); // {server: 'nginx', ...}
97+
} else {
98+
throw err;
99+
}
100+
});
113101
```
114102

115103
Error codes are as follows:

0 commit comments

Comments
 (0)