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

Add pagination support #369

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@pariti:registry=https://europe-west2-npm.pkg.dev/platform-development-347309/pariti-platform-npm/
//europe-west2-npm.pkg.dev/platform-development-347309/pariti-platform-npm/:always-auth=true
5 changes: 3 additions & 2 deletions build/airtable.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ module.exports = objectToQueryParamString;

},{"lodash/isArray":79,"lodash/isNil":85,"lodash/keys":93}],12:[function(require,module,exports){
"use strict";
module.exports = "0.11.6";
module.exports = "0.11.6-pariti";

},{}],13:[function(require,module,exports){
"use strict";
Expand Down Expand Up @@ -608,6 +608,7 @@ function eachPage(pageCallback, done) {
var records = result.records.map(function (recordJson) {
return new record_1.default(_this._table, null, recordJson);
});
records.offset = result.offset;
pageCallback(records, next);
}
});
Expand Down Expand Up @@ -653,7 +654,7 @@ exports.paramValidators = {
filterByFormula: typecheck_1.default(isString_1.default, 'the value for `filterByFormula` should be a string'),
maxRecords: typecheck_1.default(isNumber_1.default, 'the value for `maxRecords` should be a number'),
pageSize: typecheck_1.default(isNumber_1.default, 'the value for `pageSize` should be a number'),
offset: typecheck_1.default(isNumber_1.default, 'the value for `offset` should be a number'),
offset: typecheck_1.default(isString_1.default, 'the value for `offset` should be a string'),
sort: typecheck_1.default(typecheck_1.default.isArrayOf(function (obj) {
return (isPlainObject_1.default(obj) &&
isString_1.default(obj.field) &&
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "airtable",
"version": "0.11.6",
"name": "@pariti/airtable",
"version": "0.11.6-pariti",
"license": "MIT",
"homepage": "https://github.com/airtable/airtable.js",
"repository": "git://github.com/airtable/airtable.js.git",
Expand All @@ -11,7 +11,8 @@
"format": "prettier --write '**/*.[j|t]s'",
"test": "jest --env node --coverage --no-cache",
"test-unit": "jest --env node",
"prepare": "rm -rf lib/* && rm -f build/airtable.browser.js && tsc && cp lib/airtable.js lib/tmp_airtable.js && grunt browserify && rm lib/tmp_airtable.js"
"prepare": "rm -rf lib/* && rm -f build/airtable.browser.js && tsc && cp lib/airtable.js lib/tmp_airtable.js && grunt browserify && rm lib/tmp_airtable.js",
"artifactregistry-login": "npx google-artifactregistry-auth"
},
"dependencies": {
"@types/node": ">=8.0.0 <15",
Expand Down
1 change: 1 addition & 0 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ function eachPage<TFields extends FieldSet>(
const records = result.records.map(recordJson => {
return new Record(this._table, null, recordJson);
});
records.offset = result.offset;

pageCallback(records, next);
}
Expand Down
4 changes: 2 additions & 2 deletions src/query_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const paramValidators = {

pageSize: check(isNumber, 'the value for `pageSize` should be a number'),

offset: check(isNumber, 'the value for `offset` should be a number'),
offset: check(isString, 'the value for `offset` should be a string'),

sort: check(
check.isArrayOf((obj): obj is {field: string; direction?: 'asc' | 'desc'} => {
Expand Down Expand Up @@ -67,7 +67,7 @@ export interface QueryParams<TFields> {
filterByFormula?: string;
maxRecords?: number;
pageSize?: number;
offset?: number;
offset?: string;
sort?: SortParameter<TFields>[];
view?: string;
cellFormat?: 'json' | 'string';
Expand Down
11 changes: 10 additions & 1 deletion src/records.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import Record from './record';
import {FieldSet} from './field_set';

export type Records<TFields extends FieldSet> = ReadonlyArray<Record<TFields>>;
export interface ResultMetadata {
offset: string
}

/**
* Note: This type is used as the result of queries, but did not originally contain metadata such as the offset field
* required for pagination. We've kept the array type here for compatibility but somewhat hackily annotated it with
* additional properties.
*/
export type Records<TFields extends FieldSet> = ReadonlyArray<Record<TFields>> & ResultMetadata;
3 changes: 2 additions & 1 deletion test/test_files/airtable.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ function eachPage(pageCallback, done) {
var records = result.records.map(function (recordJson) {
return new record_1.default(_this._table, null, recordJson);
});
records.offset = result.offset;
pageCallback(records, next);
}
});
Expand Down Expand Up @@ -653,7 +654,7 @@ exports.paramValidators = {
filterByFormula: typecheck_1.default(isString_1.default, 'the value for `filterByFormula` should be a string'),
maxRecords: typecheck_1.default(isNumber_1.default, 'the value for `maxRecords` should be a number'),
pageSize: typecheck_1.default(isNumber_1.default, 'the value for `pageSize` should be a number'),
offset: typecheck_1.default(isNumber_1.default, 'the value for `offset` should be a number'),
offset: typecheck_1.default(isString_1.default, 'the value for `offset` should be a string'),
sort: typecheck_1.default(typecheck_1.default.isArrayOf(function (obj) {
return (isPlainObject_1.default(obj) &&
isString_1.default(obj.field) &&
Expand Down