@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.js CHANGED
@@ -3113,26 +3113,41 @@ var FileStream = class extends Stream {
3113
3113
  */
3114
3114
  async *_getRecords() {
3115
3115
  let total = 0;
3116
+ const cachedExcelData = [];
3117
+ let schemaEmitted = await this.getSchema() !== void 0;
3116
3118
  for (const filePath of this.localFilePaths) {
3117
3119
  if (this.config.format === "EXCEL" /* EXCEL */) {
3118
3120
  const data = await extractExcelRows(filePath, this.config.excel);
3121
+ cachedExcelData.push(data);
3119
3122
  total += data.length;
3123
+ if (!schemaEmitted && data.length > 0) {
3124
+ const properties = Object.fromEntries(
3125
+ Object.keys(data[0]).map((k) => [k, { type: ["null", "string"] }])
3126
+ );
3127
+ await this.target.schema(new SchemaMessage({
3128
+ stream: this.streamId,
3129
+ schema: { type: "object", properties },
3130
+ keyProperties: this.primaryKey
3131
+ }));
3132
+ schemaEmitted = true;
3133
+ }
3120
3134
  } else if (this.config.format === "CSV" /* CSV */) {
3121
3135
  total += await countCsvLines(filePath);
3122
3136
  }
3123
3137
  }
3124
3138
  this.totalRows = total;
3125
- for (const filePath of this.localFilePaths) {
3126
- if (this.config.format === "EXCEL" /* EXCEL */) {
3127
- const data = await extractExcelRows(filePath, this.config.excel);
3139
+ if (this.config.format === "EXCEL" /* EXCEL */) {
3140
+ for (const data of cachedExcelData) {
3128
3141
  for (const row of data) {
3129
3142
  yield row;
3130
3143
  }
3131
- } else if (this.config.format === "CSV" /* CSV */) {
3144
+ }
3145
+ } else if (this.config.format === "CSV" /* CSV */) {
3146
+ for (const filePath of this.localFilePaths) {
3132
3147
  yield* rowGeneratorFromCsv(filePath, this.config.csv);
3133
- } else {
3134
- throw new Error(`FileStream: Unsupported format for stream ${this.streamId}`);
3135
3148
  }
3149
+ } else {
3150
+ throw new Error(`FileStream: Unsupported format for stream ${this.streamId}`);
3136
3151
  }
3137
3152
  }
3138
3153
  };