Skip to content

Commit

Permalink
tests for flatten, tests for missing args, rename fixtures to _fixtur…
Browse files Browse the repository at this point in the history
…es, aliasing on populate
  • Loading branch information
Arro committed Jan 25, 2022
1 parent 512610b commit d705c97
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 102 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# airtable-json

A clean way to get Airtable data into JavaScript.

## Motivation

This library exists to serve people with the following situation:
Expand Down Expand Up @@ -145,8 +147,21 @@ will result in something like this:
]
```

## Populate Arguments

Populate accepts an object for its args.

| Arg | Type | Description |
| ------- | ------- | ----------------------------------------------------------- |
| local | string | column name of the primary table |
| other | string | table name of the matched data |
| flatten | boolean | transform from array to object, comprised of the first item |
| as | string | rename the populated field to a different name |

## Todo

- Recursive populate
- when declaring populate, can just pass in one name if they're the same
- delete backreference from populate
- one object created, ala aws-sdk, where you declare auth_key etc
- stop using 'things' as variable names, confusing
3 changes: 2 additions & 1 deletion jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
moduleNameMapper: {
"#src/(.*)": "<rootDir>/src/$1",
"#test/(.*)": "<rootDir>/test/$1"
}
},
collectCoverageFrom: ["src/**/*.js"]
}
157 changes: 79 additions & 78 deletions package-lock.json

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

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "airtable-json",
"version": "2.0.0",
"description": "get airtable records, but just in raw json form",
"version": "2.1.0",
"description": "A clean way to get Airtable data into JavaScript.",
"author": "Phil Deschaine",
"license": "MIT",
"main": "dist/airtable-json.js",
Expand All @@ -22,14 +22,14 @@
},
"devDependencies": {
"@babel/cli": "^7.16.8",
"@babel/core": "^7.16.10",
"@babel/core": "^7.16.12",
"@babel/eslint-parser": "^7.16.5",
"@babel/preset-env": "^7.16.10",
"@babel/preset-env": "^7.16.11",
"@babel/register": "^7.16.9",
"cross-env": "^7.0.3",
"dotenv": "^14.2.0",
"dotenv": "^14.3.0",
"eslint": "^8.7.0",
"eslint-plugin-jest": "^25.7.0",
"eslint-plugin-jest": "^26.0.0",
"jest": "^27.4.7",
"nock": "^13.2.2",
"prettier": "^2.5.1"
Expand Down
18 changes: 16 additions & 2 deletions src/airtable-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const airtableJson = async ({
populate = [],
filter
}) => {
if (!base_name) {
throw "You need to pass in a base_name"
}
if (base_name?.length !== 17) {
throw "base_name should be exactly 17 characters"
}
airtable.configure({ apiKey: auth_key })
const base = airtable.base(base_name)

Expand All @@ -30,8 +36,16 @@ const airtableJson = async ({
fetchNextPage()
})

for (const { local, other } of populate) {
things = await handlePopulate({ auth_key, base_name, local, other, things })
for (const { local, other, flatten, as } of populate) {
things = await handlePopulate({
auth_key,
base_name,
local,
other,
things,
flatten,
as
})
}

return things
Expand Down
Loading

0 comments on commit d705c97

Please sign in to comment.