From 53fcac40b52432be4deebf325662dea7ec0081d4 Mon Sep 17 00:00:00 2001 From: nadhifikbarw Date: Fri, 27 Dec 2024 16:32:12 +0700 Subject: [PATCH] fix: bad opts passing --- src/comment-query.ts | 10 ++++++---- src/query.ts | 10 ++++++---- src/record.ts | 5 +---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/comment-query.ts b/src/comment-query.ts index 1c2c3fd..d0799c7 100644 --- a/src/comment-query.ts +++ b/src/comment-query.ts @@ -23,7 +23,7 @@ export class AirtableCommentQuery { ) { this.table = table; this.recordId = recordId; - if (this.opts) this.opts = opts; + if (opts) this.opts = opts; } async firstPage() { @@ -74,9 +74,11 @@ export class AirtableCommentQuery { { query, async onEachPage(ctx) { - const pageComments = ctx.response?.comments || []; - for (const data of pageComments) { - comments.push(new AirtableComment(table, recordId, data)); + if (ctx.response?.comments) { + const pageComments = ctx.response.comments; + for (const data of pageComments) { + comments.push(new AirtableComment(table, recordId, data)); + } } return true; }, diff --git a/src/query.ts b/src/query.ts index cf58022..0296e85 100644 --- a/src/query.ts +++ b/src/query.ts @@ -17,7 +17,7 @@ export class AirtableQuery { constructor(table: AirtableTable, opts?: ListRecordsOptions) { this.table = table; - if (this.opts) this.opts = opts; + if (opts) this.opts = opts; } // TODO: support iterator timeout scenario @@ -67,9 +67,11 @@ export class AirtableQuery { body, method: "POST", async onEachPage(ctx) { - const pageRecords = ctx.response?.records || []; - for (const data of pageRecords) { - records.push(AirtableRecord.fromData(table, data)); + if (ctx.response?.records) { + const pageRecords = ctx.response.records; + for (const data of pageRecords) { + records.push(AirtableRecord.fromData(table, data)); + } } return true; }, diff --git a/src/record.ts b/src/record.ts index 01d1a40..205e89c 100644 --- a/src/record.ts +++ b/src/record.ts @@ -51,10 +51,7 @@ export class AirtableRecord< data: RecordData ) { const rec = new AirtableRecord(table, data.id); - rec._data = data; - rec.fields = data.fields; - rec.createdTime = new Date(data.createdTime); - if (data.commentCount) rec.commentCount = data.commentCount; + rec.setData(data); return rec; }