@nu-art/ts-common 0.201.23 → 0.201.25

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/db/types.d.ts CHANGED
@@ -30,6 +30,7 @@ export type DBDef<T extends DB_Object, Ks extends keyof T = Default_UniqueKey> =
30
30
  entityName: string;
31
31
  lockKeys?: (keyof T)[];
32
32
  uniqueKeys?: Ks[];
33
+ upgradeChunksSize?: number;
33
34
  /**
34
35
  * First item in the array is the latest version. Last item in the array is the oldest version.
35
36
  */
@@ -16,11 +16,11 @@ export type ReadOptions<T extends Partial<StringMap> = {}> = {
16
16
  quote?: string;
17
17
  headers?: string[];
18
18
  };
19
- export type ReadPropsMap<K extends TS_Object = TS_Object> = {
20
- [s: string]: keyof K;
19
+ export type ReadPropsMap<T extends TS_Object = TS_Object> = {
20
+ [s: string]: keyof T;
21
21
  };
22
- export type WritePropsMap<K extends TS_Object = TS_Object> = {
23
- [P in keyof K]: string;
22
+ export type WritePropsMap<T extends TS_Object = TS_Object> = {
23
+ [P in keyof T]: string;
24
24
  };
25
25
  declare class CSVModule_Class extends Module<Config> {
26
26
  private csvExporter;
@@ -30,11 +30,11 @@ declare class CSVModule_Class extends Module<Config> {
30
30
  updateExporterSettings(options: Options): void;
31
31
  export<T>(items: T[], returnCsv?: boolean): any;
32
32
  saveToFile<T extends TS_Object>(outputFile: string, items: T[], columnsToProps?: WritePropsMap<T>): Promise<void>;
33
- readCsvFromFile<T extends Partial<StringMap>>(inputFile: string, readOptions?: ReadOptions): Promise<T[]>;
34
- readCsvFromBuffer<T extends Partial<StringMap>>(buffer: Buffer, readOptions?: ReadOptions): Promise<T[]>;
35
- readCsvFromStream<T extends Partial<StringMap>>(stream: Readable, readOptions?: ReadOptions): Promise<T[]>;
36
- forEachCsvRowFromStreamAsync<T extends Partial<StringMap>>(stream: Readable, callback: (instance: T) => Promise<void>, readOptions?: ReadOptions, queueCount?: number): Promise<void>;
37
- forEachCsvRowFromStreamSync<T extends Partial<StringMap>>(stream: Readable, callback: (instance: T, index: number) => void, readOptions?: ReadOptions): Promise<void>;
33
+ readCsvFromFile<T extends TS_Object>(inputFile: string, readOptions?: ReadOptions<T>): Promise<T[]>;
34
+ readCsvFromBuffer<T extends TS_Object>(buffer: Buffer, readOptions?: ReadOptions<T>): Promise<T[]>;
35
+ readCsvFromStream<T extends TS_Object>(stream: Readable, readOptions?: ReadOptions<T>): Promise<T[]>;
36
+ forEachCsvRowFromStreamAsync<T extends TS_Object>(stream: Readable, callback: (instance: T) => Promise<void>, readOptions?: ReadOptions, queueCount?: number): Promise<void>;
37
+ forEachCsvRowFromStreamSync<T extends TS_Object>(stream: Readable, callback: (instance: T, index: number) => void, readOptions?: ReadOptions): Promise<void>;
38
38
  private createReadParserOptions;
39
39
  }
40
40
  export declare const CSVModule: CSVModule_Class;
@@ -131,7 +131,7 @@ class CSVModule_Class extends module_1.Module {
131
131
  return {
132
132
  mapHeaders: (args) => {
133
133
  var _a, _b;
134
- return (_b = (_a = readOptions.columnsToProps) === null || _a === void 0 ? void 0 : _a[args.header]) !== null && _b !== void 0 ? _b : args.header;
134
+ return ((_b = (_a = readOptions.columnsToProps) === null || _a === void 0 ? void 0 : _a[args.header]) !== null && _b !== void 0 ? _b : args.header);
135
135
  },
136
136
  mapValues: (args) => {
137
137
  var _a;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/ts-common",
3
- "version": "0.201.23",
3
+ "version": "0.201.25",
4
4
  "description": "js and ts infra",
5
5
  "keywords": [
6
6
  "TacB0sS",
@@ -75,6 +75,25 @@ export declare function sortArray<T>(array: T[], map?: keyof T | (keyof T)[] | (
75
75
  * "splits" array into given size of chunks and then does "action" on chunk and return to array of actions on chunks +-
76
76
  * */
77
77
  export declare function batchAction<T extends any = any, R extends any = any>(arr: T[], chunk: number, action: (elements: T[]) => Promise<R | R[]>): Promise<R[]>;
78
+ /**
79
+ * Processes an array of promise-returning tasks sequentially.
80
+ *
81
+ * @typeParam T - The type of resolved value of the promises.
82
+ * @returns A promise that resolves to an array of resolved values.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * let tasks = [
87
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(1), 1000)),
88
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(2), 500)),
89
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(3), 1500))
90
+ * ];
91
+ *
92
+ * Promise_all_sequentially(tasks).then(console.log); // [1, 2, 3]
93
+ * ```
94
+ * @param promises
95
+ */
96
+ export declare function Promise_all_sequentially<T>(promises: Array<() => Promise<T>>): Promise<T[]>;
78
97
  export declare function batchActionParallel<T extends any = any, R extends any = any>(arr: T[], chunk: number, action: (elements: T[]) => Promise<R | R[]>): Promise<R[]>;
79
98
  /**
80
99
  * Returns a flat array from an array of arrays.
@@ -26,7 +26,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
26
26
  });
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.flatArray = exports.batchActionParallel = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
29
+ exports.arrayIncludesAny = exports.firstElement = exports.lastElement = exports.asOptionalArray = exports.asArray = exports.generateArray = exports.toggleInArray = exports.groupArrayBy = exports.flatArray = exports.batchActionParallel = exports.Promise_all_sequentially = exports.batchAction = exports.sortArray = exports.reduceToMap = exports.arrayToMap = exports.filterFalsy = exports.filterInstances = exports.filterDuplicates = exports.findDuplicates = exports.filterAsync = exports.toggleElementInArray = exports.addItemToArrayAtIndex = exports.addItemToArray = exports.removeFromArrayByIndex = exports.removeFromArray = exports.removeItemFromArray = exports.filterInOut = void 0;
30
30
  const tools_1 = require("./tools");
31
31
  const object_tools_1 = require("./object-tools");
32
32
  function filterInOut(input, filter) {
@@ -188,6 +188,34 @@ function batchAction(arr, chunk, action) {
188
188
  });
189
189
  }
190
190
  exports.batchAction = batchAction;
191
+ /**
192
+ * Processes an array of promise-returning tasks sequentially.
193
+ *
194
+ * @typeParam T - The type of resolved value of the promises.
195
+ * @returns A promise that resolves to an array of resolved values.
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * let tasks = [
200
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(1), 1000)),
201
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(2), 500)),
202
+ * () => new Promise<number>(resolve => setTimeout(() => resolve(3), 1500))
203
+ * ];
204
+ *
205
+ * Promise_all_sequentially(tasks).then(console.log); // [1, 2, 3]
206
+ * ```
207
+ * @param promises
208
+ */
209
+ function Promise_all_sequentially(promises) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const results = [];
212
+ for (const promise of promises) {
213
+ results.push(yield promise());
214
+ }
215
+ return results;
216
+ });
217
+ }
218
+ exports.Promise_all_sequentially = Promise_all_sequentially;
191
219
  function batchActionParallel(arr, chunk, action) {
192
220
  return __awaiter(this, void 0, void 0, function* () {
193
221
  const promises = [];