@whaly/connector-sdk 0.3.2 → 0.3.4
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.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +17 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1550,6 +1550,9 @@ var MissingSchemaError = class extends Error {
|
|
|
1550
1550
|
}
|
|
1551
1551
|
};
|
|
1552
1552
|
|
|
1553
|
+
// src/sdk/models/target/models.ts
|
|
1554
|
+
var DEFAULT_SYNCED_AT_COLUMN = "_wly_synced_at";
|
|
1555
|
+
|
|
1553
1556
|
// src/sdk/models/target/record.ts
|
|
1554
1557
|
var removeParasiteProperties = (record, schema) => {
|
|
1555
1558
|
const schemaKeys = Object.keys(schema);
|
|
@@ -1560,10 +1563,10 @@ var removeParasiteProperties = (record, schema) => {
|
|
|
1560
1563
|
});
|
|
1561
1564
|
return record;
|
|
1562
1565
|
};
|
|
1563
|
-
var addWhalyFields = (record, batchDate) => {
|
|
1566
|
+
var addWhalyFields = (record, batchDate, columnName = DEFAULT_SYNCED_AT_COLUMN) => {
|
|
1564
1567
|
return {
|
|
1565
1568
|
...record,
|
|
1566
|
-
|
|
1569
|
+
[columnName]: batchDate
|
|
1567
1570
|
};
|
|
1568
1571
|
};
|
|
1569
1572
|
|
|
@@ -1832,6 +1835,8 @@ import Bluebird3 from "bluebird";
|
|
|
1832
1835
|
var semaphore = new Semaphore(1);
|
|
1833
1836
|
var ITarget = class _ITarget {
|
|
1834
1837
|
config;
|
|
1838
|
+
syncedAtColumnName;
|
|
1839
|
+
syncedAtColumnUseLegacyStringType;
|
|
1835
1840
|
schemaHooks;
|
|
1836
1841
|
syncTime;
|
|
1837
1842
|
stateProvider;
|
|
@@ -1847,6 +1852,8 @@ var ITarget = class _ITarget {
|
|
|
1847
1852
|
ajv;
|
|
1848
1853
|
constructor(config, stateProvider) {
|
|
1849
1854
|
this.config = config;
|
|
1855
|
+
this.syncedAtColumnName = config.syncedAtColumnName ?? DEFAULT_SYNCED_AT_COLUMN;
|
|
1856
|
+
this.syncedAtColumnUseLegacyStringType = config.syncedAtColumnUseLegacyStringType ?? false;
|
|
1850
1857
|
this.stateProvider = stateProvider;
|
|
1851
1858
|
this.schemaHooks = [];
|
|
1852
1859
|
this.streams = {};
|
|
@@ -1867,8 +1874,8 @@ var ITarget = class _ITarget {
|
|
|
1867
1874
|
analyzeSchemaChanges = (previousSchema, newSchema, streamId) => {
|
|
1868
1875
|
const changes = [];
|
|
1869
1876
|
let hasBreakingChanges = false;
|
|
1870
|
-
const prevColumns = new Set(Object.keys(previousSchema).filter((col) =>
|
|
1871
|
-
const newColumns = new Set(Object.keys(newSchema).filter((col) =>
|
|
1877
|
+
const prevColumns = new Set(Object.keys(previousSchema).filter((col) => col !== this.syncedAtColumnName));
|
|
1878
|
+
const newColumns = new Set(Object.keys(newSchema).filter((col) => col !== this.syncedAtColumnName));
|
|
1872
1879
|
for (const columnName of newColumns) {
|
|
1873
1880
|
if (!prevColumns.has(columnName)) {
|
|
1874
1881
|
changes.push(`Added column '${columnName}'`);
|
|
@@ -1926,7 +1933,7 @@ var ITarget = class _ITarget {
|
|
|
1926
1933
|
return;
|
|
1927
1934
|
}
|
|
1928
1935
|
const recordWithoutParasiteProperties = removeParasiteProperties(record, schema);
|
|
1929
|
-
const recordWithWhalyFields = addWhalyFields(recordWithoutParasiteProperties, stream.getBatchDate());
|
|
1936
|
+
const recordWithWhalyFields = addWhalyFields(recordWithoutParasiteProperties, stream.getBatchDate(), this.syncedAtColumnName);
|
|
1930
1937
|
const validateFn = stream.getCompiledValidateFn();
|
|
1931
1938
|
if (validateFn && !validateFn(recordWithWhalyFields)) {
|
|
1932
1939
|
throw new SchemaValidationError(`Stream: ${streamId} - Record is not valid according to schema.
|
|
@@ -2009,10 +2016,7 @@ var ITarget = class _ITarget {
|
|
|
2009
2016
|
throw new MissingSchemaError(`Stream: ${streamId} - Received SCHEMA message before stream state was initialized.`, streamId);
|
|
2010
2017
|
}
|
|
2011
2018
|
const schema = flattenSchema(streamId, message.schema);
|
|
2012
|
-
schema["
|
|
2013
|
-
format: "date-time",
|
|
2014
|
-
type: ["null", "string"]
|
|
2015
|
-
};
|
|
2019
|
+
schema[this.syncedAtColumnName] = this.syncedAtColumnUseLegacyStringType ? { type: ["null", "string"] } : { format: "date-time", type: ["null", "string"] };
|
|
2016
2020
|
const dbSync = streamState.getDbSync();
|
|
2017
2021
|
Object.keys(schema).forEach((fieldUnsafeKey) => {
|
|
2018
2022
|
const fieldDef = schema[fieldUnsafeKey];
|
|
@@ -2514,7 +2518,6 @@ async function* rowGeneratorFromCsv(path2, fileConfig) {
|
|
|
2514
2518
|
csvOptions.headers = false;
|
|
2515
2519
|
}
|
|
2516
2520
|
const csvStream = csv(csvOptions);
|
|
2517
|
-
const syncedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2518
2521
|
let initialReadStream;
|
|
2519
2522
|
let finalInputStream;
|
|
2520
2523
|
const encodingToUse = fileConfig.encoding ? fileConfig.encoding.toLowerCase() : null;
|
|
@@ -2529,7 +2532,7 @@ async function* rowGeneratorFromCsv(path2, fileConfig) {
|
|
|
2529
2532
|
try {
|
|
2530
2533
|
for await (const row of Readable.from(csvStream)) {
|
|
2531
2534
|
if (!isGeneratorConfigArray) {
|
|
2532
|
-
const rowData =
|
|
2535
|
+
const rowData = {};
|
|
2533
2536
|
for (const key of configKeys) {
|
|
2534
2537
|
const keyGenerator = fileConfig.fields[key.trim()];
|
|
2535
2538
|
if (!keyGenerator) continue;
|
|
@@ -2539,7 +2542,7 @@ async function* rowGeneratorFromCsv(path2, fileConfig) {
|
|
|
2539
2542
|
yield rowData;
|
|
2540
2543
|
} else {
|
|
2541
2544
|
const rowKeys = Object.keys(row);
|
|
2542
|
-
const rowData =
|
|
2545
|
+
const rowData = {};
|
|
2543
2546
|
for (let i = 0; i < rowKeys.length; i++) {
|
|
2544
2547
|
const keyGenerator = fileConfig.fields[i];
|
|
2545
2548
|
if (!keyGenerator) continue;
|
|
@@ -2842,7 +2845,6 @@ async function processFileStreams(entries, tapState, target) {
|
|
|
2842
2845
|
var CsvExtractionConfigBuilder = class _CsvExtractionConfigBuilder {
|
|
2843
2846
|
_separator = ",";
|
|
2844
2847
|
_encoding;
|
|
2845
|
-
_addSyncedAtColumn;
|
|
2846
2848
|
_fields;
|
|
2847
2849
|
_fieldsMode;
|
|
2848
2850
|
_replicationMethod;
|
|
@@ -2858,10 +2860,6 @@ var CsvExtractionConfigBuilder = class _CsvExtractionConfigBuilder {
|
|
|
2858
2860
|
this._encoding = enc;
|
|
2859
2861
|
return this;
|
|
2860
2862
|
}
|
|
2861
|
-
addSyncedAtColumn(enabled = true) {
|
|
2862
|
-
this._addSyncedAtColumn = enabled;
|
|
2863
|
-
return this;
|
|
2864
|
-
}
|
|
2865
2863
|
fieldsFromDict(mapping) {
|
|
2866
2864
|
if (this._fieldsMode === "array") {
|
|
2867
2865
|
throw new Error("Cannot use fieldsFromDict after fieldsFromArray");
|
|
@@ -2903,9 +2901,6 @@ var CsvExtractionConfigBuilder = class _CsvExtractionConfigBuilder {
|
|
|
2903
2901
|
if (this._encoding !== void 0) {
|
|
2904
2902
|
config.encoding = this._encoding;
|
|
2905
2903
|
}
|
|
2906
|
-
if (this._addSyncedAtColumn !== void 0) {
|
|
2907
|
-
config.addSyncedAtColumn = this._addSyncedAtColumn;
|
|
2908
|
-
}
|
|
2909
2904
|
return config;
|
|
2910
2905
|
}
|
|
2911
2906
|
buildStreamConfig(streamId) {
|
|
@@ -3791,6 +3786,7 @@ export {
|
|
|
3791
3786
|
CounterMetric,
|
|
3792
3787
|
CsvExtractionConfigBuilder,
|
|
3793
3788
|
DEFAULT_MAX_CONCURRENT_STREAMS,
|
|
3789
|
+
DEFAULT_SYNCED_AT_COLUMN,
|
|
3794
3790
|
EXECUTION_TIME_METRIC_NAME,
|
|
3795
3791
|
ExcelExtractionConfigBuilder,
|
|
3796
3792
|
FileFormat,
|