Skip to content

Commit

Permalink
Ignore undefined options (#21)
Browse files Browse the repository at this point in the history
* Ignore undefined options

Instead of crashing, silently filter them out since undefined is allowed.

* 1.2.0
  • Loading branch information
pspeter3 authored Feb 21, 2021
1 parent 923d574 commit 933f455
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "airtable-lite",
"version": "1.1.0",
"version": "1.2.0",
"description": "Light weight type safe Airtable API client",
"type": "module",
"main": "./dist/index.cjs",
Expand Down
14 changes: 14 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ describe("Airtable", () => {
expect(offset).toBeUndefined();
});

it("should handle undefined correctly", async () => {
fetchMock.mockResponseOnce(async (req) => {
const url = new URL(req.url);
expect(Array.from(url.searchParams.keys())).toHaveLength(0);
return JSON.stringify({ records: [] });
});
const client = new Airtable<Example>("", "", "Examples");
const { records, offset } = await client.select({
maxRecords: undefined,
});
expect(records).toHaveLength(0);
expect(offset).toBeUndefined();
});

it("should infer types correctly", async () => {
const client = new Airtable<Example>("", "", "Examples");
const records: ReadonlyArray<AirtableRecord<Example>> = [];
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class Airtable<T> implements AirtableClient<T> {
const url = this._createURL();
if (options !== undefined) {
for (const [key, value] of Object.entries(options)) {
if (value === undefined) {
continue;
}
switch (key) {
case "fields": {
for (const field of value as ReadonlyArray<string>) {
Expand Down

0 comments on commit 933f455

Please sign in to comment.