@questwork/q-utilities 0.1.34 → 0.1.35

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.
@@ -106,13 +106,31 @@ export declare function changeCreatorOwner(that: any, { source, target }: {
106
106
  export declare class CheckResult {
107
107
  dataSets: DataSet[];
108
108
  constructor(opts?: CheckResultOptions);
109
+ static init(opts?: CheckResultOptions): CheckResult | null;
110
+ static initFromArray(arr?: any[]): Array<CheckResult>;
111
+ static initOnlyValidFromArray(arr?: any[]): Array<CheckResult>;
109
112
  addDataSet(dataSet: DataSet): void;
110
113
  getDataSetByName(name: string): DataSet | undefined;
114
+ getAllSummary(): {
115
+ summary: DataSetSummaryItem[];
116
+ };
111
117
  getSummary(): DataSetSummaryItem[];
112
118
  getDuplicatedDetails(): DetailsResultItem[];
113
119
  getIgnoredDetails(): DetailsResultItem[];
114
120
  getInvalidDetails(): DetailsResultItem[];
115
121
  getValidDetails(): Record<string, DataWrapper[]>;
122
+ getAllDetails(): {
123
+ details: {
124
+ ignoredDetails: DetailsResultItem[];
125
+ invalidDetails: DetailsResultItem[];
126
+ duplicatedDetails: DetailsResultItem[];
127
+ };
128
+ };
129
+ getDetails(): {
130
+ ignoredDetails: DetailsResultItem[];
131
+ invalidDetails: DetailsResultItem[];
132
+ duplicatedDetails: DetailsResultItem[];
133
+ };
116
134
  hasInvalidData(): boolean;
117
135
  }
118
136
 
@@ -152,13 +170,23 @@ declare function customHandler({ responseHelper, handler, ignoreError }: {
152
170
  declare class DataSet {
153
171
  name: string;
154
172
  data?: Array<DataWrapper>;
173
+ orphanData: Array<DataWrapper>;
155
174
  checkResultConfig: CheckResultConfig;
156
175
  saveResultConfig: SaveResultConfig;
176
+ orphanBehavior?: 'DELETE' | 'KEEP' | null;
177
+ notExistBehavior?: 'INSERT' | 'SKIP';
178
+ existBehavior?: 'UPDATE' | 'SKIP';
157
179
  constructor(opts?: any);
180
+ static init(opts?: DataSet): DataSet | null;
181
+ static initFromArray(arr?: any[]): Array<DataSet>;
182
+ static initOnlyValidFromArray(arr?: any[]): Array<DataSet>;
158
183
  add(data: DataWrapper): DataSetOptions;
159
184
  getExistedData(): Array<DataWrapper>;
160
185
  getInvalidData(): Array<DataWrapper>;
161
186
  getNotExistedData(): Array<DataWrapper>;
187
+ getSkipData(): Array<DataWrapper>;
188
+ addOrphan(data: Record<string, any>): DataSet;
189
+ getOrphanData(): Array<DataWrapper>;
162
190
  }
163
191
 
164
192
  declare interface DataSetOptions {
@@ -166,6 +194,9 @@ declare interface DataSetOptions {
166
194
  data?: Array<DataWrapper>;
167
195
  checkResultConfig?: CheckResultConfig;
168
196
  saveResultConfig?: SaveResultConfig;
197
+ orphanBehavior?: 'DELETE' | 'KEEP' | null;
198
+ notExistBehavior?: 'INSERT' | 'SKIP';
199
+ existBehavior?: 'UPDATE' | 'SKIP';
169
200
  }
170
201
 
171
202
  declare interface DataSetSummary {
@@ -188,11 +219,16 @@ declare interface DataSourceConfig {
188
219
  dataSet: DataSet;
189
220
  ctx: Record<string, any>;
190
221
  }) => Promise<DataSet>;
222
+ checkOrphans?: (params: {
223
+ dataSet: DataSet;
224
+ ctx: Record<string, any>;
225
+ }) => Promise<void>;
191
226
  converter?: (value: any) => any;
192
227
  isIgnore?: (value: any) => any;
193
228
  primaryKeys?: string[];
194
229
  notExistBehavior: 'INSERT' | 'SKIP';
195
230
  existBehavior: 'UPDATE' | 'SKIP';
231
+ orphanBehavior?: 'DELETE' | 'KEEP';
196
232
  handleData?: (params: {
197
233
  dataSet: DataSet;
198
234
  dataSource: DataSourceConfig;
@@ -205,30 +241,46 @@ declare interface DataSourceConfig {
205
241
 
206
242
  declare class DataWrapper {
207
243
  data: Record<string, any>;
208
- errorLogs?: Array<Log>;
209
- ignoreLog?: Log;
244
+ logs: Array<Log>;
210
245
  rawData: Record<string, any>;
211
246
  rowIndex: number;
212
247
  status?: Status_2;
213
248
  transformedData: Record<string, any>;
214
249
  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;
250
+ static init(opts?: DataWrapperOptions): DataWrapper | null;
251
+ static initFromArray(arr?: any[]): Array<DataWrapper>;
252
+ static initOnlyValidFromArray(arr?: any[]): Array<DataWrapper>;
253
+ get errorLogs(): Array<Log>;
254
+ get ignoreLog(): Log | undefined;
255
+ addLog(detail: LogInput): DataWrapper;
256
+ addError(detail: LogInput): DataWrapper;
257
+ addOrphanDeleteError(msg?: string): DataWrapper;
258
+ addInsertError(msg?: string): DataWrapper;
259
+ addUpdateError(msg?: string): DataWrapper;
260
+ addDuplicatedLog(msg?: string): DataWrapper;
261
+ addSkippedLog(msg?: string): DataWrapper;
262
+ addIgnoreLog(msg?: string): DataWrapper;
263
+ addInsertedLog(msg?: string): DataWrapper;
264
+ addUpdatedLog(msg?: string): DataWrapper;
265
+ addOrphanDeletedLog(msg?: string): DataWrapper;
266
+ isCheckValid(): boolean;
267
+ isIgnored(): boolean;
268
+ isDuplicated(): boolean;
269
+ hasErrors(): boolean;
270
+ setStatus(status: keyof typeof DATAWRAPPER_STATUS): DataWrapper;
221
271
  setExisted(): DataWrapper;
222
272
  setFailed(): DataWrapper;
223
273
  setInserted(): DataWrapper;
224
- setRawData(rawData: Record<string, any>): DataWrapper;
225
274
  setSkipped(): DataWrapper;
226
- setStatus(status: keyof typeof DATAWRAPPER_STATUS): DataWrapper;
227
- setTransformedData(transformedData: Record<string, any>): DataWrapper;
228
275
  setUpdated(): DataWrapper;
276
+ setOrphanDeleted(): DataWrapper;
277
+ setData(data: Record<string, any>): DataWrapper;
278
+ setRawData(rawData: Record<string, any>): DataWrapper;
279
+ setTransformedData(transformedData: Record<string, any>): DataWrapper;
229
280
  }
230
281
 
231
282
  declare const DATAWRAPPER_STATUS: {
283
+ ORPHAN_DELETED: string;
232
284
  EXISTED: string;
233
285
  FAILED: string;
234
286
  INSERTED: string;
@@ -238,10 +290,9 @@ declare const DATAWRAPPER_STATUS: {
238
290
 
239
291
  declare interface DataWrapperOptions {
240
292
  data?: Record<string, any>;
241
- errorLogs?: Array<Log>;
242
- ignoreLog?: Log;
293
+ logs?: Array<Log>;
243
294
  rawData?: Record<string, any>;
244
- rowIndex: number;
295
+ rowIndex?: number;
245
296
  status?: Status_2;
246
297
  transformedData?: Record<string, any>;
247
298
  }
@@ -302,7 +353,9 @@ declare const _default: {
302
353
  QMeta: typeof models.QMeta;
303
354
  Repo: typeof models.Repo;
304
355
  makeService: typeof models.makeService;
356
+ makeServiceBulkWrite: typeof models.makeServiceBulkWrite;
305
357
  Service: typeof models.Service;
358
+ ServiceBulkWrite: typeof models.ServiceBulkWrite;
306
359
  ActionRecord: typeof models.ActionRecord;
307
360
  Status: typeof models.Status;
308
361
  StatusDocument: typeof models.StatusDocument;
@@ -345,6 +398,20 @@ declare const _default: {
345
398
  escapeRegex(string: any): string;
346
399
  ExcelImportHelper: typeof helpers.ExcelImportHelper;
347
400
  CheckResult: typeof helpers.CheckResult;
401
+ LOG_TYPE: {
402
+ readonly IGNORE: "IGNORE";
403
+ readonly DUPLICATED: "DUPLICATED";
404
+ readonly REQUIRED_ERROR: "REQUIRED_ERROR";
405
+ readonly TRANSFORM_ERROR: "TRANSFORM_ERROR";
406
+ readonly CONVERT_ERROR: "CONVERT_ERROR";
407
+ readonly ORPHAN_DELETE_ERROR: "ORPHAN_DELETE_ERROR";
408
+ readonly INSERT_ERROR: "INSERT_ERROR";
409
+ readonly UPDATE_ERROR: "UPDATE_ERROR";
410
+ readonly SKIPPED: "SKIPPED";
411
+ readonly INSERTED: "INSERTED";
412
+ readonly UPDATED: "UPDATED";
413
+ readonly ORPHAN_DELETED: "ORPHAN_DELETED";
414
+ };
348
415
  expressHelper: {
349
416
  customHandler: customHandler;
350
417
  findAllResult: findAllResult;
@@ -490,6 +557,7 @@ export declare class ExcelImportHelper {
490
557
  private static createExcelRow;
491
558
  private static getRawDataFromHeaders;
492
559
  private static isIgnore;
560
+ private static checkRequired;
493
561
  private static checkDuplicated;
494
562
  private static transform;
495
563
  private static convert;
@@ -569,6 +637,7 @@ declare namespace helpers {
569
637
  escapeRegex,
570
638
  ExcelImportHelper,
571
639
  CheckResult,
640
+ LOG_TYPE,
572
641
  expressHelper,
573
642
  extractEmails,
574
643
  formatDate,
@@ -663,7 +732,28 @@ declare interface Log {
663
732
  rowIndex: number;
664
733
  column: string;
665
734
  message: string;
666
- type: string;
735
+ type: LogType;
736
+ }
737
+
738
+ export declare const LOG_TYPE: {
739
+ readonly IGNORE: "IGNORE";
740
+ readonly DUPLICATED: "DUPLICATED";
741
+ readonly REQUIRED_ERROR: "REQUIRED_ERROR";
742
+ readonly TRANSFORM_ERROR: "TRANSFORM_ERROR";
743
+ readonly CONVERT_ERROR: "CONVERT_ERROR";
744
+ readonly ORPHAN_DELETE_ERROR: "ORPHAN_DELETE_ERROR";
745
+ readonly INSERT_ERROR: "INSERT_ERROR";
746
+ readonly UPDATE_ERROR: "UPDATE_ERROR";
747
+ readonly SKIPPED: "SKIPPED";
748
+ readonly INSERTED: "INSERTED";
749
+ readonly UPDATED: "UPDATED";
750
+ readonly ORPHAN_DELETED: "ORPHAN_DELETED";
751
+ };
752
+
753
+ declare interface LogInput {
754
+ column: string;
755
+ message: string;
756
+ type: LogType;
667
757
  }
668
758
 
669
759
  export declare class LogRecord {
@@ -679,6 +769,8 @@ export declare class LogRecord {
679
769
  serialize(): any;
680
770
  }
681
771
 
772
+ declare type LogType = typeof LOG_TYPE[keyof typeof LOG_TYPE];
773
+
682
774
  export declare function makeApiResponse({ repo, result }: {
683
775
  repo: any;
684
776
  result: any;
@@ -688,6 +780,10 @@ export declare function makeService({ repo }: {
688
780
  repo: any;
689
781
  }): Service;
690
782
 
783
+ export declare function makeServiceBulkWrite({ repo }: {
784
+ repo: any;
785
+ }): ServiceBulkWrite;
786
+
691
787
  export declare function mergeArraysByKey(arr1: any, arr2: any): {
692
788
  key: any;
693
789
  value: any;
@@ -713,7 +809,9 @@ declare namespace models {
713
809
  QMeta,
714
810
  Repo,
715
811
  makeService,
812
+ makeServiceBulkWrite,
716
813
  Service,
814
+ ServiceBulkWrite,
717
815
  ActionRecord,
718
816
  Status,
719
817
  StatusDocument,
@@ -739,6 +837,17 @@ export declare namespace objectHelper {
739
837
  export { set };
740
838
  }
741
839
 
840
+ declare interface OrphanDetail {
841
+ deleted: DataWrapper[];
842
+ failed: DataWrapper[];
843
+ }
844
+
845
+ declare interface OrphanSummary {
846
+ total: number;
847
+ deleted: number;
848
+ failed: number;
849
+ }
850
+
742
851
  export declare function padZeros(num: any, minLength?: number): any;
743
852
 
744
853
  export declare function pMap(iterable: any, mapper: any, { concurrency, stopOnError, signal, }?: {
@@ -899,6 +1008,11 @@ export declare class Repo {
899
1008
  get queryOptions(): any;
900
1009
  get saveOptions(): any;
901
1010
  init(options: any): any;
1011
+ bulkWriteDocs({ operations, config, systemLog }: {
1012
+ operations: any;
1013
+ config: any;
1014
+ systemLog: any;
1015
+ }): Promise<any>;
902
1016
  deleteOne({ id }: {
903
1017
  id: any;
904
1018
  }): Promise<any>;
@@ -945,8 +1059,110 @@ declare class SaveResult {
945
1059
  dataSets: DataSet[];
946
1060
  constructor(opt?: any);
947
1061
  addDataSet(dataSet: DataSet): this;
1062
+ getAllDetails(): {
1063
+ details: {
1064
+ failed: {
1065
+ name: string;
1066
+ hidden: boolean;
1067
+ logs: any[];
1068
+ }[];
1069
+ skipped: {
1070
+ name: string;
1071
+ hidden: boolean;
1072
+ logs: any[];
1073
+ }[];
1074
+ inserted: {
1075
+ name: string;
1076
+ hidden: boolean;
1077
+ logs: any[];
1078
+ }[];
1079
+ updated: {
1080
+ name: string;
1081
+ hidden: boolean;
1082
+ logs: any[];
1083
+ }[];
1084
+ };
1085
+ orphanDetails: {
1086
+ deleted: any[];
1087
+ failed: any[];
1088
+ };
1089
+ };
1090
+ getDetails(): {
1091
+ failed: {
1092
+ name: string;
1093
+ hidden: boolean;
1094
+ logs: any[];
1095
+ }[];
1096
+ skipped: {
1097
+ name: string;
1098
+ hidden: boolean;
1099
+ logs: any[];
1100
+ }[];
1101
+ inserted: {
1102
+ name: string;
1103
+ hidden: boolean;
1104
+ logs: any[];
1105
+ }[];
1106
+ updated: {
1107
+ name: string;
1108
+ hidden: boolean;
1109
+ logs: any[];
1110
+ }[];
1111
+ };
1112
+ getFailedDetails(): {
1113
+ name: string;
1114
+ hidden: boolean;
1115
+ logs: any[];
1116
+ }[];
1117
+ getSkippedDetails(): {
1118
+ name: string;
1119
+ hidden: boolean;
1120
+ logs: any[];
1121
+ }[];
1122
+ getInsertedDetails(): {
1123
+ name: string;
1124
+ hidden: boolean;
1125
+ logs: any[];
1126
+ }[];
1127
+ getUpdatedDetails(): {
1128
+ name: string;
1129
+ hidden: boolean;
1130
+ logs: any[];
1131
+ }[];
1132
+ getOrphanDetails(): {
1133
+ deleted: any[];
1134
+ failed: any[];
1135
+ };
1136
+ getOrphanFailedDetails(): any[];
1137
+ getOrphanDeletedDetails(): any[];
948
1138
  getSaveDetails(): SaveResultDetailItem[];
949
1139
  getSaveSummary(): SaveResultSummaryItem[];
1140
+ getAllSummary(): {
1141
+ summary: {
1142
+ name: string;
1143
+ hidden: boolean;
1144
+ summary: {
1145
+ total: number;
1146
+ failed: number;
1147
+ inserted: number;
1148
+ skipped: number;
1149
+ updated: number;
1150
+ };
1151
+ }[];
1152
+ orphanSummary: any[];
1153
+ };
1154
+ getSummary(): {
1155
+ name: string;
1156
+ hidden: boolean;
1157
+ summary: {
1158
+ total: number;
1159
+ failed: number;
1160
+ inserted: number;
1161
+ skipped: number;
1162
+ updated: number;
1163
+ };
1164
+ }[];
1165
+ getOrphanSummary(): any[];
950
1166
  }
951
1167
 
952
1168
  declare interface SaveResultConfig {
@@ -956,6 +1172,7 @@ declare interface SaveResultConfig {
956
1172
  skipped: boolean;
957
1173
  inserted: boolean;
958
1174
  updated: boolean;
1175
+ orphanDeleted?: boolean;
959
1176
  };
960
1177
  }
961
1178
 
@@ -969,6 +1186,7 @@ declare interface SaveResultDetail {
969
1186
  declare interface SaveResultDetailItem {
970
1187
  name: string;
971
1188
  hidden: boolean;
1189
+ orphanDetails: OrphanDetail | null;
972
1190
  details: SaveResultDetail;
973
1191
  }
974
1192
 
@@ -983,6 +1201,7 @@ declare interface SaveResultSummary {
983
1201
  declare interface SaveResultSummaryItem {
984
1202
  name: string;
985
1203
  hidden: boolean;
1204
+ orphanSummary: OrphanSummary | null;
986
1205
  summary: SaveResultSummary;
987
1206
  }
988
1207
 
@@ -1021,6 +1240,13 @@ export declare class Service {
1021
1240
  }>;
1022
1241
  }
1023
1242
 
1243
+ export declare class ServiceBulkWrite extends Service {
1244
+ bulkWriteDocs({ operations, config }: {
1245
+ operations: any;
1246
+ config: any;
1247
+ }): Promise<any>;
1248
+ }
1249
+
1024
1250
  export declare function setId(id: any): any;
1025
1251
 
1026
1252
  export declare function shuffleArray(array: any): any[];
@@ -1044,6 +1270,7 @@ export declare class Status {
1044
1270
  }
1045
1271
 
1046
1272
  declare interface Status_2 {
1273
+ orphanDeleted?: number;
1047
1274
  existed?: number;
1048
1275
  failed?: number;
1049
1276
  inserted?: number;
@@ -1275,6 +1502,7 @@ declare interface WorksheetConfig {
1275
1502
  dataStartRow?: number;
1276
1503
  dataEndRow?: number;
1277
1504
  dataSources: DataSourceConfig[];
1505
+ rowIndexKey?: string;
1278
1506
  }
1279
1507
 
1280
1508
  export { }