@@ -16,30 +16,31 @@ import { AirtableTableDao } from '../airtableTableDao.js'
1616
1717export const AIRTABLE_CONNECTOR_REMOTE = Symbol ( 'AIRTABLE_CONNECTOR_JSON' )
1818
19- export class AirtableRemoteConnector < BASE = any > implements AirtableConnector < BASE > {
19+ export class AirtableRemoteConnector <
20+ BASE extends Record < keyof BASE , AirtableRecord [ ] > ,
21+ > implements AirtableConnector < BASE > {
2022 constructor ( private airtableLib : AirtableLib ) { }
2123
2224 readonly TYPE = AIRTABLE_CONNECTOR_REMOTE
2325
2426 async fetch ( baseDaoCfg : AirtableBaseDaoCfg < BASE > , opt : AirtableDaoOptions = { } ) : Promise < BASE > {
2527 const { tableCfgMap } = baseDaoCfg
2628
27- const base = { } as BASE
29+ const base : Record < string , AirtableRecord [ ] > = { }
2830
2931 await pMap (
3032 Object . keys ( tableCfgMap ) ,
3133 async tableName => {
32- ; ( base as any ) [ tableName ] = await this . getTableDao (
33- baseDaoCfg ,
34- tableName as keyof BASE ,
35- ) . getRecords ( opt )
34+ base [ tableName ] = await this . getTableDao ( baseDaoCfg , tableName as keyof BASE ) . getRecords (
35+ opt ,
36+ )
3637 } ,
3738 {
3839 concurrency : opt . concurrency || 4 ,
3940 } ,
4041 )
4142
42- return base
43+ return base as BASE
4344 }
4445
4546 /**
@@ -71,7 +72,7 @@ export class AirtableRemoteConnector<BASE = any> implements AirtableConnector<BA
7172
7273 // One-by-one to preserve order
7374 await pMap (
74- base [ tableName ] as any as AirtableRecord [ ] ,
75+ base [ tableName ] ,
7576 async _r => {
7677 const oldId = _r . airtableId
7778
@@ -112,7 +113,7 @@ export class AirtableRemoteConnector<BASE = any> implements AirtableConnector<BA
112113 async tableName => {
113114 const dao = this . getTableDao ( baseDaoCfg , tableName )
114115
115- const records = ( base [ tableName ] as any as AirtableRecord [ ] )
116+ const records = base [ tableName ]
116117 // Only records with non-empty array values
117118 . filter ( r => Object . values ( r ) . some ( v => isArrayOfLinks ( v ) ) )
118119
@@ -124,7 +125,7 @@ export class AirtableRemoteConnector<BASE = any> implements AirtableConnector<BA
124125 let patch : AirtableRecord = _filterObject ( r , ( _k , v ) => isArrayOfLinks ( v ) )
125126 // console.log({patch1: patch})
126127 // use idMap
127- patch = _mapValues ( patch , ( _k , v ) => ( v as any as string [ ] ) . map ( oldId => idMap [ oldId ] ) )
128+ patch = _mapValues ( patch , ( _k , v ) => ( v as any ) . map ( ( oldId : string ) => idMap [ oldId ] ) )
128129 // console.log({patch2: patch})
129130 await dao . updateRecord ( idMap [ airtableId ] ! , patch , opt )
130131 } ,
0 commit comments