Skip to content

Commit 2b2902a

Browse files
Add support for recordMetadata param (#370)
Co-authored-by: Blake Thomson <blake.thomson@airtable.com>
1 parent 2d36eb6 commit 2b2902a

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

build/airtable.browser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ exports.paramValidators = {
671671
return isString_1.default(method) && ['get', 'post'].includes(method);
672672
}, 'the value for `method` should be "get" or "post"'),
673673
returnFieldsByFieldId: typecheck_1.default(isBoolean_1.default, 'the value for `returnFieldsByFieldId` should be a boolean'),
674+
recordMetadata: typecheck_1.default(typecheck_1.default.isArrayOf(isString_1.default), 'the value for `recordMetadata` should be an array of strings'),
674675
};
675676
exports.URL_CHARACTER_LENGTH_LIMIT = 15000;
676677
exports.shouldListRecordsParamBePassedAsParameter = function (paramName) {
@@ -698,6 +699,9 @@ var Record = /** @class */ (function () {
698699
function Record(table, recordId, recordJson) {
699700
this._table = table;
700701
this.id = recordId || recordJson.id;
702+
if (recordJson) {
703+
this.commentCount = recordJson.commentCount;
704+
}
701705
this.setRawJson(recordJson);
702706
this.save = callback_to_promise_1.default(save, this);
703707
this.patchUpdate = callback_to_promise_1.default(patchUpdate, this);

src/query_params.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ export const paramValidators = {
4949
isBoolean,
5050
'the value for `returnFieldsByFieldId` should be a boolean'
5151
),
52+
53+
recordMetadata: check(
54+
check.isArrayOf(isString),
55+
'the value for `recordMetadata` should be an array of strings'
56+
),
57+
5258
};
5359

5460
export const URL_CHARACTER_LENGTH_LIMIT = 15000;
@@ -75,4 +81,5 @@ export interface QueryParams<TFields> {
7581
userLocale?: string;
7682
method?: string;
7783
returnFieldsByFieldId?: boolean;
84+
recordMetadata?: string[];
7885
}

src/record.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Record<TFields extends FieldSet> {
3030
_rawJson: RecordJson;
3131

3232
readonly id: string;
33+
readonly commentCount?: number;
3334
fields: TFields;
3435

3536
readonly save: RecordActionMethod<TFields>;
@@ -44,6 +45,9 @@ class Record<TFields extends FieldSet> {
4445
constructor(table: Table<TFields>, recordId: string, recordJson?: RecordJson) {
4546
this._table = table;
4647
this.id = recordId || recordJson.id;
48+
if (recordJson) {
49+
this.commentCount = recordJson.commentCount;
50+
}
4751
this.setRawJson(recordJson);
4852

4953
this.save = callbackToPromise(save, this);

src/record_data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface RecordData<TFields> {
22
id: string;
33
fields: TFields;
4+
commentCount?: number;
45
}

test/select.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,15 @@ describe('record selection', function() {
319319
testExpressApp.set('handler override', function(req, res) {
320320
expect(req.method).toBe('GET');
321321
expect(req.url).toBe(
322-
'/v0/app123/Table?maxRecords=50&sort%5B0%5D%5Bfield%5D=Name&sort%5B0%5D%5Bdirection%5D=desc&cellFormat=json&returnFieldsByFieldId=true'
322+
'/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'
323323
);
324324
res.json({
325325
records: [
326326
{
327327
id: 'recordA',
328328
fields: {Name: 'Rebecca'},
329329
createdTime: '2020-04-20T16:20:00.000Z',
330+
commentCount: 0,
330331
},
331332
],
332333
offset: 'offsetABC',
@@ -341,11 +342,13 @@ describe('record selection', function() {
341342
sort: [{field: 'Name', direction: 'desc'}],
342343
cellFormat: 'json',
343344
returnFieldsByFieldId: true,
345+
recordMetadata: ['commentCount'],
344346
})
345347
.eachPage(function page(records) {
346348
records.forEach(function(record) {
347349
expect(record.id).toBe('recordA');
348350
expect(record.get('Name')).toBe('Rebecca');
351+
expect(record.commentCount).toBe(0);
349352
});
350353
done();
351354
});

test/test_files/airtable.browser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ exports.paramValidators = {
671671
return isString_1.default(method) && ['get', 'post'].includes(method);
672672
}, 'the value for `method` should be "get" or "post"'),
673673
returnFieldsByFieldId: typecheck_1.default(isBoolean_1.default, 'the value for `returnFieldsByFieldId` should be a boolean'),
674+
recordMetadata: typecheck_1.default(typecheck_1.default.isArrayOf(isString_1.default), 'the value for `recordMetadata` should be an array of strings'),
674675
};
675676
exports.URL_CHARACTER_LENGTH_LIMIT = 15000;
676677
exports.shouldListRecordsParamBePassedAsParameter = function (paramName) {
@@ -698,6 +699,9 @@ var Record = /** @class */ (function () {
698699
function Record(table, recordId, recordJson) {
699700
this._table = table;
700701
this.id = recordId || recordJson.id;
702+
if (recordJson) {
703+
this.commentCount = recordJson.commentCount;
704+
}
701705
this.setRawJson(recordJson);
702706
this.save = callback_to_promise_1.default(save, this);
703707
this.patchUpdate = callback_to_promise_1.default(patchUpdate, this);

0 commit comments

Comments
 (0)