@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.js +34 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1274,6 +1274,7 @@ var Stream = class {
|
|
|
1274
1274
|
// Private sync methods:
|
|
1275
1275
|
async _syncRecords(parent) {
|
|
1276
1276
|
let rowsSent = 0;
|
|
1277
|
+
const dryRunLimit = isDryRun() ? getDryRunLimit() : void 0;
|
|
1277
1278
|
let recordSyncedMetrics = [];
|
|
1278
1279
|
if (this.rowsSyncedMetricsConf.isEnabled() === true) {
|
|
1279
1280
|
recordSyncedMetrics = getCounterMetrics(
|
|
@@ -1315,6 +1316,10 @@ var Stream = class {
|
|
|
1315
1316
|
metric.increment();
|
|
1316
1317
|
});
|
|
1317
1318
|
rowsSent += 1;
|
|
1319
|
+
if (dryRunLimit !== void 0 && rowsSent >= dryRunLimit) {
|
|
1320
|
+
logger.info(`\u{1F6D1} Stream: ${this.streamId} - DRY_RUN_LIMIT reached (${dryRunLimit} records), stopping.`);
|
|
1321
|
+
break;
|
|
1322
|
+
}
|
|
1318
1323
|
if (rowsSent % 1e3 === 0) {
|
|
1319
1324
|
const percentStr = this.totalRows ? ` (${Math.round(rowsSent / this.totalRows * 100)}%)` : "";
|
|
1320
1325
|
logger.info(`\u23F3 Stream: ${this.streamId} - ${rowsSent} records synced so far...${percentStr}`);
|
|
@@ -2340,11 +2345,12 @@ var ITarget = class _ITarget {
|
|
|
2340
2345
|
streamState.setSchema(schema);
|
|
2341
2346
|
streamState.setCompiledValidateFn(this.ajv.compile({ type: "object", properties: schema }));
|
|
2342
2347
|
const streamReplicationMethod = this.streams[streamId]?.getReplicationMethod();
|
|
2343
|
-
if (message.keyProperties.length === 0 && streamReplicationMethod
|
|
2348
|
+
if (message.keyProperties.length === 0 && streamReplicationMethod === "INCREMENTAL" /* INCREMENTAL */) {
|
|
2344
2349
|
throw new Error(`StreamId: ${message.stream} - \`key_properties\` field is required and can't be empty in SCHEMA message.
|
|
2345
2350
|
Received SCHEMA message: ${JSON.stringify(message)}`);
|
|
2346
2351
|
}
|
|
2347
2352
|
streamState.setKeyProperties(message.keyProperties);
|
|
2353
|
+
dbSync.renamedColumnStore.computeColumnNameForStream(streamId, schema);
|
|
2348
2354
|
if (!isDryRun()) {
|
|
2349
2355
|
await dbSync.updateSchemaInWarehouse(schema, message.keyProperties);
|
|
2350
2356
|
const {
|
|
@@ -3107,26 +3113,41 @@ var FileStream = class extends Stream {
|
|
|
3107
3113
|
*/
|
|
3108
3114
|
async *_getRecords() {
|
|
3109
3115
|
let total = 0;
|
|
3116
|
+
const cachedExcelData = [];
|
|
3117
|
+
let schemaEmitted = await this.getSchema() !== void 0;
|
|
3110
3118
|
for (const filePath of this.localFilePaths) {
|
|
3111
3119
|
if (this.config.format === "EXCEL" /* EXCEL */) {
|
|
3112
3120
|
const data = await extractExcelRows(filePath, this.config.excel);
|
|
3121
|
+
cachedExcelData.push(data);
|
|
3113
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
|
+
}
|
|
3114
3134
|
} else if (this.config.format === "CSV" /* CSV */) {
|
|
3115
3135
|
total += await countCsvLines(filePath);
|
|
3116
3136
|
}
|
|
3117
3137
|
}
|
|
3118
3138
|
this.totalRows = total;
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
const data = await extractExcelRows(filePath, this.config.excel);
|
|
3139
|
+
if (this.config.format === "EXCEL" /* EXCEL */) {
|
|
3140
|
+
for (const data of cachedExcelData) {
|
|
3122
3141
|
for (const row of data) {
|
|
3123
3142
|
yield row;
|
|
3124
3143
|
}
|
|
3125
|
-
}
|
|
3144
|
+
}
|
|
3145
|
+
} else if (this.config.format === "CSV" /* CSV */) {
|
|
3146
|
+
for (const filePath of this.localFilePaths) {
|
|
3126
3147
|
yield* rowGeneratorFromCsv(filePath, this.config.csv);
|
|
3127
|
-
} else {
|
|
3128
|
-
throw new Error(`FileStream: Unsupported format for stream ${this.streamId}`);
|
|
3129
3148
|
}
|
|
3149
|
+
} else {
|
|
3150
|
+
throw new Error(`FileStream: Unsupported format for stream ${this.streamId}`);
|
|
3130
3151
|
}
|
|
3131
3152
|
}
|
|
3132
3153
|
};
|
|
@@ -4223,6 +4244,12 @@ var BigQueryDBSync = class extends StreamWarehouseSyncService {
|
|
|
4223
4244
|
});
|
|
4224
4245
|
};
|
|
4225
4246
|
getReplaceQueries = () => {
|
|
4247
|
+
if (this.primaryKeys.length === 0) {
|
|
4248
|
+
return [
|
|
4249
|
+
`TRUNCATE TABLE ${this.sqlTableId};`,
|
|
4250
|
+
...this.getAppendQueries()
|
|
4251
|
+
];
|
|
4252
|
+
}
|
|
4226
4253
|
return [
|
|
4227
4254
|
`TRUNCATE TABLE ${this.sqlTableId};`,
|
|
4228
4255
|
...this.getMergeQueries()
|