@whaly/connector-sdk 0.3.5 → 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
@@ -1133,6 +1133,7 @@ var Stream = class {
1133
1133
  // Private sync methods:
1134
1134
  async _syncRecords(parent) {
1135
1135
  let rowsSent = 0;
1136
+ const dryRunLimit = isDryRun() ? getDryRunLimit() : void 0;
1136
1137
  let recordSyncedMetrics = [];
1137
1138
  if (this.rowsSyncedMetricsConf.isEnabled() === true) {
1138
1139
  recordSyncedMetrics = getCounterMetrics(
@@ -1174,6 +1175,10 @@ var Stream = class {
1174
1175
  metric.increment();
1175
1176
  });
1176
1177
  rowsSent += 1;
1178
+ if (dryRunLimit !== void 0 && rowsSent >= dryRunLimit) {
1179
+ logger.info(`\u{1F6D1} Stream: ${this.streamId} - DRY_RUN_LIMIT reached (${dryRunLimit} records), stopping.`);
1180
+ break;
1181
+ }
1177
1182
  if (rowsSent % 1e3 === 0) {
1178
1183
  const percentStr = this.totalRows ? ` (${Math.round(rowsSent / this.totalRows * 100)}%)` : "";
1179
1184
  logger.info(`\u23F3 Stream: ${this.streamId} - ${rowsSent} records synced so far...${percentStr}`);
@@ -2199,11 +2204,12 @@ var ITarget = class _ITarget {
2199
2204
  streamState.setSchema(schema);
2200
2205
  streamState.setCompiledValidateFn(this.ajv.compile({ type: "object", properties: schema }));
2201
2206
  const streamReplicationMethod = this.streams[streamId]?.getReplicationMethod();
2202
- if (message.keyProperties.length === 0 && streamReplicationMethod !== "APPEND" /* APPEND */) {
2207
+ if (message.keyProperties.length === 0 && streamReplicationMethod === "INCREMENTAL" /* INCREMENTAL */) {
2203
2208
  throw new Error(`StreamId: ${message.stream} - \`key_properties\` field is required and can't be empty in SCHEMA message.
2204
2209
  Received SCHEMA message: ${JSON.stringify(message)}`);
2205
2210
  }
2206
2211
  streamState.setKeyProperties(message.keyProperties);
2212
+ dbSync.renamedColumnStore.computeColumnNameForStream(streamId, schema);
2207
2213
  if (!isDryRun()) {
2208
2214
  await dbSync.updateSchemaInWarehouse(schema, message.keyProperties);
2209
2215
  const {
@@ -2966,26 +2972,41 @@ var FileStream = class extends Stream {
2966
2972
  */
2967
2973
  async *_getRecords() {
2968
2974
  let total = 0;
2975
+ const cachedExcelData = [];
2976
+ let schemaEmitted = await this.getSchema() !== void 0;
2969
2977
  for (const filePath of this.localFilePaths) {
2970
2978
  if (this.config.format === "EXCEL" /* EXCEL */) {
2971
2979
  const data = await extractExcelRows(filePath, this.config.excel);
2980
+ cachedExcelData.push(data);
2972
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
+ }
2973
2993
  } else if (this.config.format === "CSV" /* CSV */) {
2974
2994
  total += await countCsvLines(filePath);
2975
2995
  }
2976
2996
  }
2977
2997
  this.totalRows = total;
2978
- for (const filePath of this.localFilePaths) {
2979
- if (this.config.format === "EXCEL" /* EXCEL */) {
2980
- const data = await extractExcelRows(filePath, this.config.excel);
2998
+ if (this.config.format === "EXCEL" /* EXCEL */) {
2999
+ for (const data of cachedExcelData) {
2981
3000
  for (const row of data) {
2982
3001
  yield row;
2983
3002
  }
2984
- } else if (this.config.format === "CSV" /* CSV */) {
3003
+ }
3004
+ } else if (this.config.format === "CSV" /* CSV */) {
3005
+ for (const filePath of this.localFilePaths) {
2985
3006
  yield* rowGeneratorFromCsv(filePath, this.config.csv);
2986
- } else {
2987
- throw new Error(`FileStream: Unsupported format for stream ${this.streamId}`);
2988
3007
  }
3008
+ } else {
3009
+ throw new Error(`FileStream: Unsupported format for stream ${this.streamId}`);
2989
3010
  }
2990
3011
  }
2991
3012
  };
@@ -4082,6 +4103,12 @@ var BigQueryDBSync = class extends StreamWarehouseSyncService {
4082
4103
  });
4083
4104
  };
4084
4105
  getReplaceQueries = () => {
4106
+ if (this.primaryKeys.length === 0) {
4107
+ return [
4108
+ `TRUNCATE TABLE ${this.sqlTableId};`,
4109
+ ...this.getAppendQueries()
4110
+ ];
4111
+ }
4085
4112
  return [
4086
4113
  `TRUNCATE TABLE ${this.sqlTableId};`,
4087
4114
  ...this.getMergeQueries()