@whaly/connector-sdk 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2972,26 +2972,41 @@ var FileStream = class extends Stream {
2972
2972
  */
2973
2973
  async *_getRecords() {
2974
2974
  let total = 0;
2975
+ const cachedExcelData = [];
2976
+ let schemaEmitted = await this.getSchema() !== void 0;
2975
2977
  for (const filePath of this.localFilePaths) {
2976
2978
  if (this.config.format === "EXCEL" /* EXCEL */) {
2977
2979
  const data = await extractExcelRows(filePath, this.config.excel);
2980
+ cachedExcelData.push(data);
2978
2981
  total += data.length;
2982
+ if (!schemaEmitted && data.length > 0) {
2983
+ const properties = Object.fromEntries(
2984
+ Object.keys(data[0]).map((k) => [k, { type: ["null", "string"] }])
2985
+ );
2986
+ await this.target.schema(new SchemaMessage({
2987
+ stream: this.streamId,
2988
+ schema: { type: "object", properties },
2989
+ keyProperties: this.primaryKey
2990
+ }));
2991
+ schemaEmitted = true;
2992
+ }
2979
2993
  } else if (this.config.format === "CSV" /* CSV */) {
2980
2994
  total += await countCsvLines(filePath);
2981
2995
  }
2982
2996
  }
2983
2997
  this.totalRows = total;
2984
- for (const filePath of this.localFilePaths) {
2985
- if (this.config.format === "EXCEL" /* EXCEL */) {
2986
- const data = await extractExcelRows(filePath, this.config.excel);
2998
+ if (this.config.format === "EXCEL" /* EXCEL */) {
2999
+ for (const data of cachedExcelData) {
2987
3000
  for (const row of data) {
2988
3001
  yield row;
2989
3002
  }
2990
- } else if (this.config.format === "CSV" /* CSV */) {
3003
+ }
3004
+ } else if (this.config.format === "CSV" /* CSV */) {
3005
+ for (const filePath of this.localFilePaths) {
2991
3006
  yield* rowGeneratorFromCsv(filePath, this.config.csv);
2992
- } else {
2993
- throw new Error(`FileStream: Unsupported format for stream ${this.streamId}`);
2994
3007
  }
3008
+ } else {
3009
+ throw new Error(`FileStream: Unsupported format for stream ${this.streamId}`);
2995
3010
  }
2996
3011
  }
2997
3012
  };