()
| 23 | }; |
| 24 | |
| 25 | export const newAirtablePlugin = () => { |
| 26 | const pluginClient = { |
| 27 | ...newUnimplementedDestination(), |
| 28 | plugin: null as unknown as Plugin, |
| 29 | spec: null as unknown as Spec, |
| 30 | client: null as unknown as AirtableClient | null, |
| 31 | allTables: null as unknown as Table[], |
| 32 | close: () => Promise.resolve(), |
| 33 | tables: ({ tables, skipTables, skipDependentTables }: TableOptions) => { |
| 34 | const { allTables } = pluginClient; |
| 35 | const filtered = filterTables(allTables, tables, skipTables, skipDependentTables); |
| 36 | return Promise.resolve(filtered); |
| 37 | }, |
| 38 | sync: (options: SyncOptions) => { |
| 39 | const { client, allTables, plugin } = pluginClient; |
| 40 | |
| 41 | if (client === null) { |
| 42 | return Promise.reject(new Error('Client not initialized')); |
| 43 | } |
| 44 | |
| 45 | const logger = plugin.getLogger(); |
| 46 | const { |
| 47 | spec: { concurrency }, |
| 48 | } = pluginClient; |
| 49 | |
| 50 | const { stream, tables, skipTables, skipDependentTables, deterministicCQId } = options; |
| 51 | const filtered = filterTables(allTables, tables, skipTables, skipDependentTables); |
| 52 | |
| 53 | return sync({ |
| 54 | logger, |
| 55 | client, |
| 56 | stream, |
| 57 | tables: filtered, |
| 58 | deterministicCQId, |
| 59 | concurrency, |
| 60 | }); |
| 61 | }, |
| 62 | }; |
| 63 | |
| 64 | const newClient: NewClientFunction = async (logger, spec, { noConnection }) => { |
| 65 | pluginClient.client = { id: () => 'airtable' }; |
| 66 | if (noConnection) { |
| 67 | pluginClient.allTables = []; |
| 68 | return pluginClient; |
| 69 | } |
| 70 | pluginClient.spec = parseSpec(spec); |
| 71 | pluginClient.allTables = await getTables( |
| 72 | logger, |
| 73 | pluginClient.spec.apiKey, |
| 74 | pluginClient.spec.endpointUrl, |
| 75 | pluginClient.spec.concurrency, |
| 76 | ); |
| 77 | |
| 78 | return pluginClient; |
| 79 | }; |
| 80 | |
| 81 | pluginClient.plugin = newPlugin('airtable', version, newClient, { |
| 82 | kind: 'source', |
no test coverage detected