bellboy 8.7.2 → 8.7.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/lib/utils.d.ts CHANGED
@@ -6,12 +6,15 @@ export declare function closeDbConnection(databaseConfig: IDbConnection): Promis
6
6
  export declare function getValueFromJSONChunk(): Transform;
7
7
  export declare function removeCircularReferencesFromChunk(): Transform;
8
8
  export declare function getDelimitedGenerator({ readStream, hasHeader, }: {
9
- readStream: any;
9
+ readStream: AsyncIterable<{
10
+ raw: string;
11
+ record: string[];
12
+ }>;
10
13
  hasHeader: boolean;
11
14
  }): () => AsyncGenerator<{
12
15
  header: string[];
13
16
  arr: string[];
14
- obj: any;
17
+ obj: Record<string, string> | undefined;
15
18
  row: string;
16
19
  }, void, unknown>;
17
20
  export declare function applyHttpAuthorization(connection: AxiosRequestConfig, authorizationRequest?: AuthorizationRequest): Promise<void>;
package/lib/utils.js CHANGED
@@ -125,17 +125,34 @@ function removeCircularReferencesFromChunk() {
125
125
  }
126
126
  function getDelimitedGenerator({ readStream, hasHeader, }) {
127
127
  let header = [];
128
- const processRow = ({ raw, record }) => {
129
- if (hasHeader && !header.length) {
130
- header = record.map((x) => x.trim());
128
+ const makeUniqueHeader = (names) => {
129
+ const counts = new Map();
130
+ const seen = new Map();
131
+ for (const n of names) {
132
+ const base = n.trim();
133
+ counts.set(base, (counts.get(base) ?? 0) + 1);
131
134
  }
132
- else {
133
- let obj;
134
- if (header.length) {
135
- obj = Object.fromEntries(header.map((x, i) => [x, record[i]]));
135
+ return names.map((n) => {
136
+ const base = n.trim();
137
+ const total = counts.get(base) ?? 0;
138
+ if (total <= 1) {
139
+ return base;
136
140
  }
137
- return { header, arr: record, obj, row: raw };
141
+ const idx = (seen.get(base) ?? 0) + 1;
142
+ seen.set(base, idx);
143
+ return `${base} (${idx})`;
144
+ });
145
+ };
146
+ const processRow = ({ raw, record }) => {
147
+ if (hasHeader && header.length === 0) {
148
+ header = makeUniqueHeader(record);
149
+ return undefined;
150
+ }
151
+ let obj;
152
+ if (header.length) {
153
+ obj = Object.fromEntries(header.map((key, i) => [key, record[i]]));
138
154
  }
155
+ return { header, arr: record, obj, row: raw };
139
156
  };
140
157
  const generator = async function* () {
141
158
  for await (const row of readStream) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bellboy",
3
- "version": "8.7.2",
3
+ "version": "8.7.4",
4
4
  "description": "Highly performant JavaScript data stream ETL engine.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "async-mqtt": "2.2.1",
55
- "axios": "1.7.7",
55
+ "axios": "1.8.4",
56
56
  "claviz-node-firebird": "2.0.1",
57
57
  "csv": "6.0.5",
58
58
  "iconv-lite": "0.6.3",