benyap / firestore-backfire

Ultimate control over importing and exporting your Firestore data
https://www.npmjs.com/package/firestore-backfire
MIT License
25 stars 2 forks source link

Document how to use dataSourceFactory.createReader() and dataSourceFactory.createWriter() - example code is incorrect #418

Closed tohagan closed 1 year ago

tohagan commented 1 year ago

I've like to use your API with local files but your documentation does not explain how to do this. Its unclear from your code what is required for DefaultOptions & T

Note that my paths are computed so Typescript can't see the id prefix in case that's used.

  const writer = await dataSourceFactory.createWriter(exportFilePath, ???)

  const reader = await dataSourceFactory.createReader(importFilePath, ???)

Same issue for the other pre-registered readers and writers.

tohagan commented 1 year ago

For code example, Typescript reports

DataSourceFactory.d.ts(120, 22): An argument for 'options' was not provided.

// Import the default factory instance
import {
  dataSourceFactory,
  importFirestoreData,
  exportFirestoreData,
} from "firestore-backfire";

const path = "s3://my-bucket/exported-data.ndjson";
const reader = await dataSourceFactory.createReader(path);  // << Typescript wants an additional option
const writer = await dataSourceFactory.createWriter(path);  // << Typescript wants an additional option

// Use the reader and writer
await importFirestoreData(connection, reader, options);
await exportFirestoreData(connection, writer, options);
benyap commented 1 year ago

Hi @tohagan,

Thanks for raising this issue. You're right in that the code example is incorrect - there is an options object that is expected as a second argument to DataSourceFactory.createReader() and DataSourceFactory.createWriter(). I'll update the documentation to correct this issue 😊

If you're using the default dataSourceFactory instance from firestore-backfire, the options object follows the DataSourceOptions interface. These options are required to help firestore-backfire connect to your data sources, which would be either GCS or S3.

If you've created a custom DataSourceFactory instance and/or registered custom data sources, you'll need to pass the options that are required for your custom data source.

The signatures of DataSourceFactory.createReader() and DataSourceFactory.createWriter() are both generic to make them extensible should you wish to register custom data sources on the existing dataSourceFactory instance, which is why there is a generic T in the type signature. By default, DefaultOptions should simply be DataSourceOptions (see here).

Most IDEs should be able to provide you with the inferred type definition of the options object.

image

Hope this helps! Please let me know if you have any further questions.