@nu-art/ts-common 0.202.20 → 0.202.22
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 +1 -0
- package/modules/CSVModule.d.ts +3 -2
- package/modules/CSVModule.js +23 -3
- package/package.json +2 -1
- package/utils/date-time-tools.d.ts +4 -0
- package/utils/date-time-tools.js +2 -1
- package/utils/exception-tools.d.ts +0 -3
- package/utils/exception-tools.js +1 -8
- package/utils/types.d.ts +5 -0
package/db/types.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type Proto_DB_Object<T extends DB_Object, GeneratedKeys extends keyof T |
|
|
|
32
32
|
};
|
|
33
33
|
export type DBProto<P extends Proto_DB_Object<any, any, any, any, any>, ModifiableSubType = Omit<P['type'], P['generatedKeys'] | keyof DB_Object>, GeneratedSubType = SubsetObjectByKeys<P['type'], P['generatedKeys']>> = {
|
|
34
34
|
uiType: ModifiableSubType & Partial<GeneratedSubType> & Partial<DB_Object>;
|
|
35
|
+
preDbType: ModifiableSubType & Partial<GeneratedSubType>;
|
|
35
36
|
dbType: P['type'];
|
|
36
37
|
generatedPropsValidator: ValidatorTypeResolver<Omit<GeneratedSubType, keyof DB_Object>>;
|
|
37
38
|
modifiablePropsValidator: ValidatorTypeResolver<ModifiableSubType>;
|
package/modules/CSVModule.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { ExportToCsv, Options } from 'export-to-csv';
|
|
7
7
|
import { StringMap, TS_Object } from '../utils/types';
|
|
8
8
|
import { Module } from '../core/module';
|
|
9
|
-
import { Readable } from 'stream';
|
|
9
|
+
import { Readable, Transform } from 'stream';
|
|
10
10
|
type Config = {
|
|
11
11
|
options: Options;
|
|
12
12
|
};
|
|
@@ -34,7 +34,8 @@ declare class CSVModule_Class extends Module<Config> {
|
|
|
34
34
|
readCsvFromBuffer<T extends TS_Object>(buffer: Buffer, readOptions?: ReadOptions<T>): Promise<T[]>;
|
|
35
35
|
readCsvFromStream<T extends TS_Object>(stream: Readable, readOptions?: ReadOptions<T>): Promise<T[]>;
|
|
36
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>;
|
|
37
|
+
forEachCsvRowFromStreamSync<T extends TS_Object>(stream: Readable, callback: (instance: T, index: number, csvStream: Transform) => void, readOptions?: ReadOptions): Promise<void>;
|
|
38
|
+
forEachCsvRowFromStreamSync_FastCSV<T extends TS_Object>(stream: Readable, callback: (instance: T, index: number, stream: Readable) => void, readOptions?: ReadOptions): Promise<void>;
|
|
38
39
|
private createReadParserOptions;
|
|
39
40
|
}
|
|
40
41
|
export declare const CSVModule: CSVModule_Class;
|
package/modules/CSVModule.js
CHANGED
|
@@ -36,6 +36,7 @@ const module_1 = require("../core/module");
|
|
|
36
36
|
const stream_1 = require("stream");
|
|
37
37
|
const queue_1 = require("../utils/queue");
|
|
38
38
|
const csvParser = require("csv-parser");
|
|
39
|
+
const csv = require("fast-csv");
|
|
39
40
|
const DefaultConfig = {
|
|
40
41
|
options: {
|
|
41
42
|
fieldSeparator: ',',
|
|
@@ -116,14 +117,33 @@ class CSVModule_Class extends module_1.Module {
|
|
|
116
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
118
|
return new Promise((resolve, reject) => {
|
|
118
119
|
let rowIndex = 0;
|
|
120
|
+
const csvStream = csvParser(this.createReadParserOptions(readOptions));
|
|
119
121
|
stream
|
|
120
|
-
.pipe(
|
|
121
|
-
.on('data', (instance) => callback(instance, rowIndex
|
|
122
|
+
.pipe(csvStream)
|
|
123
|
+
.on('data', (instance) => callback(instance, rowIndex++, csvStream))
|
|
124
|
+
.on('error', (err) => reject(err))
|
|
125
|
+
.on('end', () => {
|
|
126
|
+
this.logInfo('read ended');
|
|
127
|
+
resolve();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
forEachCsvRowFromStreamSync_FastCSV(stream, callback, readOptions = {}) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
return new Promise((resolve, reject) => {
|
|
135
|
+
let rowIndex = 0;
|
|
136
|
+
const csvStream = csv.parse({ headers: true, trim: true });
|
|
137
|
+
csvStream
|
|
138
|
+
.on('data', (instance) => {
|
|
139
|
+
callback(instance, rowIndex++, csvStream);
|
|
140
|
+
})
|
|
122
141
|
.on('error', (err) => reject(err))
|
|
123
142
|
.on('end', () => {
|
|
124
143
|
this.logInfo('read ended');
|
|
125
144
|
resolve();
|
|
126
145
|
});
|
|
146
|
+
stream.pipe(csvStream);
|
|
127
147
|
});
|
|
128
148
|
});
|
|
129
149
|
}
|
|
@@ -139,7 +159,7 @@ class CSVModule_Class extends module_1.Module {
|
|
|
139
159
|
return mapValues !== null && mapValues !== void 0 ? mapValues : args.value;
|
|
140
160
|
},
|
|
141
161
|
quote: readOptions.quote || '"',
|
|
142
|
-
headers: readOptions.headers
|
|
162
|
+
headers: readOptions.headers,
|
|
143
163
|
};
|
|
144
164
|
}
|
|
145
165
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nu-art/ts-common",
|
|
3
|
-
"version": "0.202.
|
|
3
|
+
"version": "0.202.22",
|
|
4
4
|
"description": "js and ts infra",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TacB0sS",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"run-tests": "ts-mocha --timeout 5000 -p src/test/tsconfig.json src/test/run-all-tests.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"fast-csv": "^4.3.6",
|
|
35
36
|
"export-to-csv": "0.2.1",
|
|
36
37
|
"moment": "^2.24.0",
|
|
37
38
|
"node-forge": "^1.2.1",
|
|
@@ -35,5 +35,9 @@ export declare const DateTimeFormat: (format: string) => {
|
|
|
35
35
|
parse: (timestampAsString: string) => number;
|
|
36
36
|
format: (timestamp?: number) => string;
|
|
37
37
|
};
|
|
38
|
+
export declare const DateTimeFormat_yyyyMMDDTHHmmss: {
|
|
39
|
+
parse: (timestampAsString: string) => number;
|
|
40
|
+
format: (timestamp?: number) => string;
|
|
41
|
+
};
|
|
38
42
|
export declare function isSameDay(date1: Date, date2: Date): boolean;
|
|
39
43
|
export declare function deltaDays(d1: Date | number, d2: Date | number): number;
|
package/utils/date-time-tools.js
CHANGED
|
@@ -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.deltaDays = exports.isSameDay = exports.DateTimeFormat = exports.normalizeTimestamp = exports.parseTimeString = exports.formatTimestamp = exports.createReadableTimestampObject = exports.currentTimeMillisWithTimeZone = exports.currentLocalTimeMillis = exports.specificTimeTodayMillis = exports.currentTimeMillis = exports.auditBy = exports._clearInterval = exports._setInterval = exports._clearTimeout = exports._setTimeout = exports.sleep = exports.timeout = exports.Weekdays = exports.Format_YYYYMMDD_HHmmss = exports.Format_HHmmss_DDMMYYYY = exports.Year = exports.Week = exports.Day = exports.Hour = exports.Minute = exports.Second = void 0;
|
|
29
|
+
exports.deltaDays = exports.isSameDay = exports.DateTimeFormat_yyyyMMDDTHHmmss = exports.DateTimeFormat = exports.normalizeTimestamp = exports.parseTimeString = exports.formatTimestamp = exports.createReadableTimestampObject = exports.currentTimeMillisWithTimeZone = exports.currentLocalTimeMillis = exports.specificTimeTodayMillis = exports.currentTimeMillis = exports.auditBy = exports._clearInterval = exports._setInterval = exports._clearTimeout = exports._setTimeout = exports.sleep = exports.timeout = exports.Weekdays = exports.Format_YYYYMMDD_HHmmss = exports.Format_HHmmss_DDMMYYYY = exports.Year = exports.Week = exports.Day = exports.Hour = exports.Minute = exports.Second = void 0;
|
|
30
30
|
const moment_1 = require("moment");
|
|
31
31
|
const moment = require("moment");
|
|
32
32
|
exports.Second = 1000;
|
|
@@ -134,6 +134,7 @@ const DateTimeFormat = (format) => {
|
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
136
|
exports.DateTimeFormat = DateTimeFormat;
|
|
137
|
+
exports.DateTimeFormat_yyyyMMDDTHHmmss = (0, exports.DateTimeFormat)('YYYY-MM-DDTHH:mm:ss');
|
|
137
138
|
function isSameDay(date1, date2) {
|
|
138
139
|
return moment(date1).isSame(date2, 'day');
|
|
139
140
|
}
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
import { ApiException } from '../core/exceptions/exceptions';
|
|
2
|
-
import { ApiError_GeneralErrorMessage } from '../core/exceptions/types';
|
|
3
1
|
export declare function isCustomException(e: Error): boolean;
|
|
4
|
-
export declare function BadRequest(userMessage: string, debugMessage?: string, cause?: Error): ApiException<ApiError_GeneralErrorMessage>;
|
package/utils/exception-tools.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isCustomException = void 0;
|
|
4
4
|
const exceptions_1 = require("../core/exceptions/exceptions");
|
|
5
5
|
const allExceptions = [
|
|
6
6
|
exceptions_1.Exception,
|
|
@@ -17,10 +17,3 @@ function isCustomException(e) {
|
|
|
17
17
|
return allExceptions.some(exc => !!(0, exceptions_1.isErrorOfType)(e, exc));
|
|
18
18
|
}
|
|
19
19
|
exports.isCustomException = isCustomException;
|
|
20
|
-
function BadRequest(userMessage, debugMessage = userMessage, cause) {
|
|
21
|
-
return new exceptions_1.ApiException(400, debugMessage, cause).setErrorBody({
|
|
22
|
-
type: 'error-message',
|
|
23
|
-
data: { message: userMessage }
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.BadRequest = BadRequest;
|
package/utils/types.d.ts
CHANGED
|
@@ -204,3 +204,8 @@ export type ManipulateInnerPropValue<ObjectType, PropertyPath extends DotNotatio
|
|
|
204
204
|
} : never : {
|
|
205
205
|
[Prop in keyof ObjectType]: Prop extends PropertyPath ? NewValueType : ObjectType[Prop];
|
|
206
206
|
};
|
|
207
|
+
export type Exact<T> = {
|
|
208
|
+
[K in keyof T]: T[K];
|
|
209
|
+
} & {
|
|
210
|
+
[K: string]: never;
|
|
211
|
+
};
|