@questwork/q-utilities 0.1.32 → 0.1.34
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/q-utilities.cjs +4838 -11
- package/dist/q-utilities.d.ts +245 -0
- package/dist/q-utilities.esm.js +3766 -1988
- package/dist/q-utilities.iife.js +4840 -11
- package/dist/q-utilities.umd.js +4841 -10
- package/package.json +1 -1
- package/.github/workflows/publish.yml +0 -60
- package/BEST_PRACTICES.md +0 -217
- package/BUILDING_JS_TS_LIBRARY.md +0 -321
- package/dist/q-utilities.cjs.map +0 -1
- package/dist/q-utilities.esm.js.map +0 -1
- package/dist/q-utilities.iife.js.map +0 -1
- package/dist/q-utilities.umd.js.map +0 -1
- package/eslint.config.js +0 -3
- package/tests/runtime-test.js +0 -563
- package/tsconfig.json +0 -28
- package/vite.config.js +0 -73
- package/vitest.config.js +0 -9
package/dist/q-utilities.d.ts
CHANGED
|
@@ -103,6 +103,33 @@ export declare function changeCreatorOwner(that: any, { source, target }: {
|
|
|
103
103
|
target: any;
|
|
104
104
|
}): any;
|
|
105
105
|
|
|
106
|
+
export declare class CheckResult {
|
|
107
|
+
dataSets: DataSet[];
|
|
108
|
+
constructor(opts?: CheckResultOptions);
|
|
109
|
+
addDataSet(dataSet: DataSet): void;
|
|
110
|
+
getDataSetByName(name: string): DataSet | undefined;
|
|
111
|
+
getSummary(): DataSetSummaryItem[];
|
|
112
|
+
getDuplicatedDetails(): DetailsResultItem[];
|
|
113
|
+
getIgnoredDetails(): DetailsResultItem[];
|
|
114
|
+
getInvalidDetails(): DetailsResultItem[];
|
|
115
|
+
getValidDetails(): Record<string, DataWrapper[]>;
|
|
116
|
+
hasInvalidData(): boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare interface CheckResultConfig {
|
|
120
|
+
hidden?: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
declare interface CheckResultOptions {
|
|
124
|
+
dataSets: DataSet[] | undefined;
|
|
125
|
+
getDataSetByName(name: string): DataSet | undefined;
|
|
126
|
+
getSummary(): DataSetSummaryItem[];
|
|
127
|
+
getIgnoredDetails(): DetailsResultItem[];
|
|
128
|
+
getInvalidDetails(): DetailsResultItem[];
|
|
129
|
+
getDuplicatedDetails(): DetailsResultItem[];
|
|
130
|
+
getValidDetails(): Record<string, DataWrapper[]>;
|
|
131
|
+
}
|
|
132
|
+
|
|
106
133
|
export declare function concatStringByArray(arrTemplate: any, data: any): any;
|
|
107
134
|
|
|
108
135
|
export declare class ConsoleLog extends QLog {
|
|
@@ -122,6 +149,103 @@ declare function customHandler({ responseHelper, handler, ignoreError }: {
|
|
|
122
149
|
ignoreError?: boolean;
|
|
123
150
|
}): (reqOrCtx: any, resOrNext: any, nextInExpress: any) => Promise<any>;
|
|
124
151
|
|
|
152
|
+
declare class DataSet {
|
|
153
|
+
name: string;
|
|
154
|
+
data?: Array<DataWrapper>;
|
|
155
|
+
checkResultConfig: CheckResultConfig;
|
|
156
|
+
saveResultConfig: SaveResultConfig;
|
|
157
|
+
constructor(opts?: any);
|
|
158
|
+
add(data: DataWrapper): DataSetOptions;
|
|
159
|
+
getExistedData(): Array<DataWrapper>;
|
|
160
|
+
getInvalidData(): Array<DataWrapper>;
|
|
161
|
+
getNotExistedData(): Array<DataWrapper>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
declare interface DataSetOptions {
|
|
165
|
+
name: string;
|
|
166
|
+
data?: Array<DataWrapper>;
|
|
167
|
+
checkResultConfig?: CheckResultConfig;
|
|
168
|
+
saveResultConfig?: SaveResultConfig;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
declare interface DataSetSummary {
|
|
172
|
+
total: number;
|
|
173
|
+
ignored: number;
|
|
174
|
+
valid: number;
|
|
175
|
+
invalid: number;
|
|
176
|
+
duplicated: number;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
declare interface DataSetSummaryItem {
|
|
180
|
+
name: string;
|
|
181
|
+
hidden: boolean;
|
|
182
|
+
summary: DataSetSummary;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
declare interface DataSourceConfig {
|
|
186
|
+
name?: string;
|
|
187
|
+
checkExisted?: (params: {
|
|
188
|
+
dataSet: DataSet;
|
|
189
|
+
ctx: Record<string, any>;
|
|
190
|
+
}) => Promise<DataSet>;
|
|
191
|
+
converter?: (value: any) => any;
|
|
192
|
+
isIgnore?: (value: any) => any;
|
|
193
|
+
primaryKeys?: string[];
|
|
194
|
+
notExistBehavior: 'INSERT' | 'SKIP';
|
|
195
|
+
existBehavior: 'UPDATE' | 'SKIP';
|
|
196
|
+
handleData?: (params: {
|
|
197
|
+
dataSet: DataSet;
|
|
198
|
+
dataSource: DataSourceConfig;
|
|
199
|
+
ctx: Record<string, any>;
|
|
200
|
+
}) => Promise<DataSet>;
|
|
201
|
+
headerConfigs: HeaderConfig[];
|
|
202
|
+
checkResultConfig?: CheckResultConfig;
|
|
203
|
+
saveResultConfig?: SaveResultConfig;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
declare class DataWrapper {
|
|
207
|
+
data: Record<string, any>;
|
|
208
|
+
errorLogs?: Array<Log>;
|
|
209
|
+
ignoreLog?: Log;
|
|
210
|
+
rawData: Record<string, any>;
|
|
211
|
+
rowIndex: number;
|
|
212
|
+
status?: Status_2;
|
|
213
|
+
transformedData: Record<string, any>;
|
|
214
|
+
constructor(opts: DataWrapperOptions);
|
|
215
|
+
addError(detail: Log): DataWrapper;
|
|
216
|
+
addInsertError(msg: string): DataWrapper;
|
|
217
|
+
addUpdateError(msg: string): DataWrapper;
|
|
218
|
+
isValid(): boolean;
|
|
219
|
+
setIgnoreLog(detail: Log): DataWrapper;
|
|
220
|
+
setData(data: Record<string, any>): DataWrapper;
|
|
221
|
+
setExisted(): DataWrapper;
|
|
222
|
+
setFailed(): DataWrapper;
|
|
223
|
+
setInserted(): DataWrapper;
|
|
224
|
+
setRawData(rawData: Record<string, any>): DataWrapper;
|
|
225
|
+
setSkipped(): DataWrapper;
|
|
226
|
+
setStatus(status: keyof typeof DATAWRAPPER_STATUS): DataWrapper;
|
|
227
|
+
setTransformedData(transformedData: Record<string, any>): DataWrapper;
|
|
228
|
+
setUpdated(): DataWrapper;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
declare const DATAWRAPPER_STATUS: {
|
|
232
|
+
EXISTED: string;
|
|
233
|
+
FAILED: string;
|
|
234
|
+
INSERTED: string;
|
|
235
|
+
SKIPPED: string;
|
|
236
|
+
UPDATED: string;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
declare interface DataWrapperOptions {
|
|
240
|
+
data?: Record<string, any>;
|
|
241
|
+
errorLogs?: Array<Log>;
|
|
242
|
+
ignoreLog?: Log;
|
|
243
|
+
rawData?: Record<string, any>;
|
|
244
|
+
rowIndex: number;
|
|
245
|
+
status?: Status_2;
|
|
246
|
+
transformedData?: Record<string, any>;
|
|
247
|
+
}
|
|
248
|
+
|
|
125
249
|
declare const _default: {
|
|
126
250
|
ApiResponse: typeof models.ApiResponse;
|
|
127
251
|
makeApiResponse: typeof models.makeApiResponse;
|
|
@@ -219,6 +343,8 @@ declare const _default: {
|
|
|
219
343
|
displayName(user: any, options: any): any;
|
|
220
344
|
downloadFileByUrl: typeof helpers.downloadFileByUrl;
|
|
221
345
|
escapeRegex(string: any): string;
|
|
346
|
+
ExcelImportHelper: typeof helpers.ExcelImportHelper;
|
|
347
|
+
CheckResult: typeof helpers.CheckResult;
|
|
222
348
|
expressHelper: {
|
|
223
349
|
customHandler: customHandler;
|
|
224
350
|
findAllResult: findAllResult;
|
|
@@ -292,6 +418,12 @@ declare const _default: {
|
|
|
292
418
|
};
|
|
293
419
|
export default _default;
|
|
294
420
|
|
|
421
|
+
declare interface DetailsResultItem {
|
|
422
|
+
name: string;
|
|
423
|
+
hidden: boolean;
|
|
424
|
+
logs: Log[];
|
|
425
|
+
}
|
|
426
|
+
|
|
295
427
|
/**
|
|
296
428
|
* Detects and reports hidden/control characters in a string without modifying it.
|
|
297
429
|
* @param {string} input - The string to analyze.
|
|
@@ -339,6 +471,36 @@ export declare interface ErrorDetailOptions {
|
|
|
339
471
|
|
|
340
472
|
export declare function escapeRegex(string: any): string;
|
|
341
473
|
|
|
474
|
+
declare interface ExcelDataItem {
|
|
475
|
+
worksheetName: string;
|
|
476
|
+
headers: string[];
|
|
477
|
+
data: ExcelDataRow[];
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
declare interface ExcelDataRow {
|
|
481
|
+
[key: string]: any;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export declare class ExcelImportHelper {
|
|
485
|
+
static check(params: {
|
|
486
|
+
config: ImportConfig;
|
|
487
|
+
excelData: ExcelDataItem[];
|
|
488
|
+
context?: Record<string, any>;
|
|
489
|
+
}): Promise<CheckResultOptions>;
|
|
490
|
+
private static createExcelRow;
|
|
491
|
+
private static getRawDataFromHeaders;
|
|
492
|
+
private static isIgnore;
|
|
493
|
+
private static checkDuplicated;
|
|
494
|
+
private static transform;
|
|
495
|
+
private static convert;
|
|
496
|
+
static save(params: {
|
|
497
|
+
result?: CheckResult;
|
|
498
|
+
config?: ImportConfig;
|
|
499
|
+
data?: ExcelDataItem[];
|
|
500
|
+
context?: Record<string, any>;
|
|
501
|
+
}): Promise<SaveResult>;
|
|
502
|
+
}
|
|
503
|
+
|
|
342
504
|
export declare namespace expressHelper {
|
|
343
505
|
export { customHandler };
|
|
344
506
|
export { findAllResult };
|
|
@@ -386,6 +548,12 @@ export declare function getValueByKeys(keys: any, data: any): any;
|
|
|
386
548
|
|
|
387
549
|
export declare function groupArrayByKey(arr: any, key: any): any;
|
|
388
550
|
|
|
551
|
+
declare interface HeaderConfig {
|
|
552
|
+
name: string;
|
|
553
|
+
required?: boolean;
|
|
554
|
+
transform?: (value: any) => any;
|
|
555
|
+
}
|
|
556
|
+
|
|
389
557
|
declare namespace helpers {
|
|
390
558
|
export {
|
|
391
559
|
authorize,
|
|
@@ -399,6 +567,8 @@ declare namespace helpers {
|
|
|
399
567
|
displayName,
|
|
400
568
|
downloadFileByUrl,
|
|
401
569
|
escapeRegex,
|
|
570
|
+
ExcelImportHelper,
|
|
571
|
+
CheckResult,
|
|
402
572
|
expressHelper,
|
|
403
573
|
extractEmails,
|
|
404
574
|
formatDate,
|
|
@@ -434,6 +604,13 @@ declare function hideSensitiveFields(aggregation: any, { query }?: {
|
|
|
434
604
|
query?: {};
|
|
435
605
|
}): void;
|
|
436
606
|
|
|
607
|
+
declare interface ImportConfig {
|
|
608
|
+
beforeCheck?: (value: any) => any;
|
|
609
|
+
beforeSave?: (value: any) => any;
|
|
610
|
+
name: string;
|
|
611
|
+
worksheets: WorksheetConfig[];
|
|
612
|
+
}
|
|
613
|
+
|
|
437
614
|
export declare function init(_class: any, options: any): any;
|
|
438
615
|
|
|
439
616
|
export declare function initFromArray(_class: any, arr: any): any[];
|
|
@@ -482,6 +659,13 @@ export declare class KeyValueObject {
|
|
|
482
659
|
|
|
483
660
|
declare type KnownErrorCode = keyof typeof ERROR_CODES;
|
|
484
661
|
|
|
662
|
+
declare interface Log {
|
|
663
|
+
rowIndex: number;
|
|
664
|
+
column: string;
|
|
665
|
+
message: string;
|
|
666
|
+
type: string;
|
|
667
|
+
}
|
|
668
|
+
|
|
485
669
|
export declare class LogRecord {
|
|
486
670
|
constructor(options?: {});
|
|
487
671
|
data: any;
|
|
@@ -757,6 +941,51 @@ export declare function sanitizeText(input: string, options?: {
|
|
|
757
941
|
debug?: boolean;
|
|
758
942
|
}): string;
|
|
759
943
|
|
|
944
|
+
declare class SaveResult {
|
|
945
|
+
dataSets: DataSet[];
|
|
946
|
+
constructor(opt?: any);
|
|
947
|
+
addDataSet(dataSet: DataSet): this;
|
|
948
|
+
getSaveDetails(): SaveResultDetailItem[];
|
|
949
|
+
getSaveSummary(): SaveResultSummaryItem[];
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
declare interface SaveResultConfig {
|
|
953
|
+
hidden?: boolean;
|
|
954
|
+
returnDetail?: {
|
|
955
|
+
failed: boolean;
|
|
956
|
+
skipped: boolean;
|
|
957
|
+
inserted: boolean;
|
|
958
|
+
updated: boolean;
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
declare interface SaveResultDetail {
|
|
963
|
+
failed: DataWrapper[] | null;
|
|
964
|
+
inserted: DataWrapper[] | null;
|
|
965
|
+
skipped: DataWrapper[] | null;
|
|
966
|
+
updated: DataWrapper[] | null;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
declare interface SaveResultDetailItem {
|
|
970
|
+
name: string;
|
|
971
|
+
hidden: boolean;
|
|
972
|
+
details: SaveResultDetail;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
declare interface SaveResultSummary {
|
|
976
|
+
failed: number;
|
|
977
|
+
inserted: number;
|
|
978
|
+
skipped: number;
|
|
979
|
+
total: number;
|
|
980
|
+
updated: number;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
declare interface SaveResultSummaryItem {
|
|
984
|
+
name: string;
|
|
985
|
+
hidden: boolean;
|
|
986
|
+
summary: SaveResultSummary;
|
|
987
|
+
}
|
|
988
|
+
|
|
760
989
|
export declare class Service {
|
|
761
990
|
static get _classname(): string;
|
|
762
991
|
static get _superclass(): string;
|
|
@@ -814,6 +1043,14 @@ export declare class Status {
|
|
|
814
1043
|
update(update: any): this;
|
|
815
1044
|
}
|
|
816
1045
|
|
|
1046
|
+
declare interface Status_2 {
|
|
1047
|
+
existed?: number;
|
|
1048
|
+
failed?: number;
|
|
1049
|
+
inserted?: number;
|
|
1050
|
+
skipped?: number;
|
|
1051
|
+
updated?: number;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
817
1054
|
export declare class StatusDocument extends Status {
|
|
818
1055
|
archived: any;
|
|
819
1056
|
completed: any;
|
|
@@ -1032,4 +1269,12 @@ declare interface WebAppResponseOptions {
|
|
|
1032
1269
|
success?: boolean;
|
|
1033
1270
|
}
|
|
1034
1271
|
|
|
1272
|
+
declare interface WorksheetConfig {
|
|
1273
|
+
name: string;
|
|
1274
|
+
headerRow?: number;
|
|
1275
|
+
dataStartRow?: number;
|
|
1276
|
+
dataEndRow?: number;
|
|
1277
|
+
dataSources: DataSourceConfig[];
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1035
1280
|
export { }
|