Skip to content

Commit

Permalink
Add support for recordMetadata param (#370)
Browse files Browse the repository at this point in the history
Co-authored-by: Blake Thomson <[email protected]>
  • Loading branch information
marks and BlakeThomson-at committed May 16, 2023
1 parent 2d36eb6 commit 2b2902a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build/airtable.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ exports.paramValidators = {
return isString_1.default(method) && ['get', 'post'].includes(method);
}, 'the value for `method` should be "get" or "post"'),
returnFieldsByFieldId: typecheck_1.default(isBoolean_1.default, 'the value for `returnFieldsByFieldId` should be a boolean'),
recordMetadata: typecheck_1.default(typecheck_1.default.isArrayOf(isString_1.default), 'the value for `recordMetadata` should be an array of strings'),
};
exports.URL_CHARACTER_LENGTH_LIMIT = 15000;
exports.shouldListRecordsParamBePassedAsParameter = function (paramName) {
Expand Down Expand Up @@ -698,6 +699,9 @@ var Record = /** @class */ (function () {
function Record(table, recordId, recordJson) {
this._table = table;
this.id = recordId || recordJson.id;
if (recordJson) {
this.commentCount = recordJson.commentCount;
}
this.setRawJson(recordJson);
this.save = callback_to_promise_1.default(save, this);
this.patchUpdate = callback_to_promise_1.default(patchUpdate, this);
Expand Down
7 changes: 7 additions & 0 deletions src/query_params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export const paramValidators = {
isBoolean,
'the value for `returnFieldsByFieldId` should be a boolean'
),

recordMetadata: check(
check.isArrayOf(isString),
'the value for `recordMetadata` should be an array of strings'
),

};

export const URL_CHARACTER_LENGTH_LIMIT = 15000;
Expand All @@ -75,4 +81,5 @@ export interface QueryParams<TFields> {
userLocale?: string;
method?: string;
returnFieldsByFieldId?: boolean;
recordMetadata?: string[];
}
4 changes: 4 additions & 0 deletions src/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Record<TFields extends FieldSet> {
_rawJson: RecordJson;

readonly id: string;
readonly commentCount?: number;
fields: TFields;

readonly save: RecordActionMethod<TFields>;
Expand All @@ -44,6 +45,9 @@ class Record<TFields extends FieldSet> {
constructor(table: Table<TFields>, recordId: string, recordJson?: RecordJson) {
this._table = table;
this.id = recordId || recordJson.id;
if (recordJson) {
this.commentCount = recordJson.commentCount;
}
this.setRawJson(recordJson);

this.save = callbackToPromise(save, this);
Expand Down
1 change: 1 addition & 0 deletions src/record_data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface RecordData<TFields> {
id: string;
fields: TFields;
commentCount?: number;
}
5 changes: 4 additions & 1 deletion test/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,15 @@ describe('record selection', function() {
testExpressApp.set('handler override', function(req, res) {
expect(req.method).toBe('GET');
expect(req.url).toBe(
'/v0/app123/Table?maxRecords=50&sort%5B0%5D%5Bfield%5D=Name&sort%5B0%5D%5Bdirection%5D=desc&cellFormat=json&returnFieldsByFieldId=true'
'/v0/app123/Table?maxRecords=50&sort%5B0%5D%5Bfield%5D=Name&sort%5B0%5D%5Bdirection%5D=desc&cellFormat=json&returnFieldsByFieldId=true&recordMetadata%5B%5D=commentCount'
);
res.json({
records: [
{
id: 'recordA',
fields: {Name: 'Rebecca'},
createdTime: '2020-04-20T16:20:00.000Z',
commentCount: 0,
},
],
offset: 'offsetABC',
Expand All @@ -341,11 +342,13 @@ describe('record selection', function() {
sort: [{field: 'Name', direction: 'desc'}],
cellFormat: 'json',
returnFieldsByFieldId: true,
recordMetadata: ['commentCount'],
})
.eachPage(function page(records) {
records.forEach(function(record) {
expect(record.id).toBe('recordA');
expect(record.get('Name')).toBe('Rebecca');
expect(record.commentCount).toBe(0);
});
done();
});
Expand Down
4 changes: 4 additions & 0 deletions test/test_files/airtable.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ exports.paramValidators = {
return isString_1.default(method) && ['get', 'post'].includes(method);
}, 'the value for `method` should be "get" or "post"'),
returnFieldsByFieldId: typecheck_1.default(isBoolean_1.default, 'the value for `returnFieldsByFieldId` should be a boolean'),
recordMetadata: typecheck_1.default(typecheck_1.default.isArrayOf(isString_1.default), 'the value for `recordMetadata` should be an array of strings'),
};
exports.URL_CHARACTER_LENGTH_LIMIT = 15000;
exports.shouldListRecordsParamBePassedAsParameter = function (paramName) {
Expand Down Expand Up @@ -698,6 +699,9 @@ var Record = /** @class */ (function () {
function Record(table, recordId, recordJson) {
this._table = table;
this.id = recordId || recordJson.id;
if (recordJson) {
this.commentCount = recordJson.commentCount;
}
this.setRawJson(recordJson);
this.save = callback_to_promise_1.default(save, this);
this.patchUpdate = callback_to_promise_1.default(patchUpdate, this);
Expand Down

0 comments on commit 2b2902a

Please sign in to comment.