@futdevpro/fsm-dynamo 1.9.39 → 1.9.41

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.
Files changed (43) hide show
  1. package/build/_collections/utils/array.util.d.ts +7 -2
  2. package/build/_collections/utils/array.util.d.ts.map +1 -1
  3. package/build/_collections/utils/array.util.js +50 -5
  4. package/build/_collections/utils/array.util.js.map +1 -1
  5. package/build/_collections/utils/log.util.d.ts +3 -3
  6. package/build/_collections/utils/log.util.d.ts.map +1 -1
  7. package/build/_collections/utils/log.util.js.map +1 -1
  8. package/build/_collections/utils/math/vector2.util.d.ts +1 -0
  9. package/build/_collections/utils/math/vector2.util.d.ts.map +1 -1
  10. package/build/_collections/utils/math/vector2.util.js +3 -0
  11. package/build/_collections/utils/math/vector2.util.js.map +1 -1
  12. package/build/_collections/utils/{shared.static-service.d.ts → shared.util.d.ts} +23 -2
  13. package/build/_collections/utils/shared.util.d.ts.map +1 -0
  14. package/build/_collections/utils/{shared.static-service.js → shared.util.js} +45 -17
  15. package/build/_collections/utils/shared.util.js.map +1 -0
  16. package/build/_collections/utils/time.util.d.ts +1 -0
  17. package/build/_collections/utils/time.util.d.ts.map +1 -1
  18. package/build/_collections/utils/time.util.js +30 -0
  19. package/build/_collections/utils/time.util.js.map +1 -1
  20. package/build/_models/control-models/error.control-model.d.ts +1 -0
  21. package/build/_models/control-models/error.control-model.d.ts.map +1 -1
  22. package/build/_models/control-models/error.control-model.js +110 -63
  23. package/build/_models/control-models/error.control-model.js.map +1 -1
  24. package/build/_models/control-models/error.control-model.spec.js +26 -10
  25. package/build/_models/control-models/error.control-model.spec.js.map +1 -1
  26. package/build/index.d.ts +2 -3
  27. package/build/index.d.ts.map +1 -1
  28. package/build/index.js +2 -3
  29. package/build/index.js.map +1 -1
  30. package/futdevpro-fsm-dynamo-01.09.41.tgz +0 -0
  31. package/package.json +3 -2
  32. package/spec/support/jasmine.json +8 -0
  33. package/src/_collections/utils/array.util.ts +69 -5
  34. package/src/_collections/utils/log.util.ts +3 -3
  35. package/src/_collections/utils/math/vector2.util.ts +4 -0
  36. package/src/_collections/utils/{shared.static-service.ts → shared.util.ts} +63 -16
  37. package/src/_collections/utils/time.util.ts +23 -0
  38. package/src/_models/control-models/error.control-model.spec.ts +45 -13
  39. package/src/_models/control-models/error.control-model.ts +150 -67
  40. package/src/index.ts +2 -3
  41. package/build/_collections/utils/shared.static-service.d.ts.map +0 -1
  42. package/build/_collections/utils/shared.static-service.js.map +0 -1
  43. package/futdevpro-fsm-dynamo-01.09.39.tgz +0 -0
@@ -50,11 +50,11 @@ export class DyFM_Array {
50
50
  }
51
51
 
52
52
  static last<T>(array: T[]): T {
53
- return array.length ? array[array.length - 1] : null;
53
+ return array?.length ? array[array.length - 1] : null;
54
54
  }
55
55
 
56
56
  static lastString(array: string): string {
57
- return array.length ? array[array.length - 1] : null;
57
+ return array?.length ? array[array.length - 1] : null;
58
58
  }
59
59
 
60
60
  static remove<T>(array: T[], element: T): T[] {
@@ -104,7 +104,7 @@ export class DyFM_Array {
104
104
  pageSize,
105
105
  total: array.length,
106
106
  totalPageCount: Math.ceil(array.length / pageSize),
107
- items: this.page(array, pageIndex, pageSize)
107
+ items: this.page(array, pageIndex, pageSize),
108
108
  };
109
109
  }
110
110
 
@@ -137,7 +137,7 @@ export class DyFM_Array {
137
137
  }
138
138
  }
139
139
 
140
- getRoundListOutboundIndex<T>(array: T[], index: number): T {
140
+ static getRoundListOutboundIndex<T>(array: T[], index: number): T {
141
141
  try {
142
142
  while (array.length <= index) {
143
143
  index -= array.length;
@@ -159,7 +159,71 @@ export class DyFM_Array {
159
159
  }
160
160
  }
161
161
 
162
- findDuplicates
162
+ static stringListHasMultiplications(stringList: string[]): boolean {
163
+ return stringList.some((str: string, index: number): boolean => {
164
+ return stringList.findIndex((strItem: string): boolean => strItem === str) !== index;
165
+ });
166
+ }
167
+
168
+ static filterStringMultiplications(stringList: string[]): string[] {
169
+ return stringList.filter((str: string, index: number): boolean => {
170
+ return stringList.findIndex((strItem: string): boolean => strItem === str) !== index;
171
+ });
172
+ }
173
+
174
+ static gatherStringMultiplications(stringList: string[]): string[][] {
175
+ const multiplications = [];
176
+
177
+ stringList.forEach((str: string, index: number): void => {
178
+ if (multiplications.find(
179
+ (multiplication: string[]): boolean => multiplication.includes(str))
180
+ ) {
181
+ return;
182
+ }
183
+
184
+ const sameStrings = stringList.filter((strItem: string): boolean => strItem === str);
185
+
186
+ if (sameStrings.length > 1) {
187
+ multiplications.push(sameStrings);
188
+ }
189
+ });
190
+
191
+ return multiplications;
192
+ }
193
+
194
+ static haveMultiplications<T extends object>(dataList: T[], byKey: string = '_id'): boolean {
195
+ return dataList.some((data: T, index: number): boolean => {
196
+ return dataList.findIndex(
197
+ (listItem: T): boolean => listItem[byKey] === data[byKey]
198
+ ) !== index;
199
+ });
200
+ }
201
+
202
+ static filterMultiplications<T extends object>(dataList: T[], byKey: string = '_id'): T[] {
203
+ return dataList.filter((data: T, index: number): boolean => {
204
+ return dataList.findIndex(
205
+ (listItem: T): boolean => listItem[byKey] === data[byKey]
206
+ ) !== index;
207
+ });
208
+ }
209
+
210
+ static gatherMultiplications<T extends object>(dataList: T[], byKey: string = '_id'): T[][] {
211
+ const multiplications = [];
212
+
213
+ dataList.forEach((data: T, index: number): void => {
214
+ if (multiplications.find((multiplication: T[]): boolean => multiplication.includes(data))) {
215
+ return;
216
+ }
217
+
218
+ const sameData = dataList.filter((listItem: T): boolean => listItem[byKey] === data[byKey]);
219
+
220
+ if (sameData.length > 1) {
221
+ multiplications.push(sameData);
222
+ }
223
+ });
224
+
225
+ return multiplications;
226
+ }
163
227
 
164
228
  }
165
229
 
@@ -200,11 +200,11 @@ export class DyFM_Log {
200
200
  static readonly H_success = DyFM_Log.highlightedSuccess;
201
201
 
202
202
  // eslint-disable-next-line max-len
203
- private static h_solid: string = '|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
203
+ private static readonly h_solid: string = '|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||';
204
204
  // eslint-disable-next-line max-len
205
- private static h_before: string = '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\';
205
+ private static readonly h_before: string = '\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\';
206
206
  // eslint-disable-next-line max-len
207
- private static h_after: string = '/////////////////////////////////////////////////////////////////////////////';
207
+ private static readonly h_after: string = '/////////////////////////////////////////////////////////////////////////////';
208
208
 
209
209
  static removeLogStyles(message: string): string {
210
210
  for (const styleKey of Object(DyFM_LogStyle)) {
@@ -285,6 +285,10 @@ export class DyFM_Vector2_Util implements DyFM_Vector2 {
285
285
  }
286
286
  getVector2 = this.get;
287
287
  toVector2 = this.get;
288
+
289
+ static clone(v: DyFM_Vector2): DyFM_Vector2 {
290
+ return { x: v.x, y: v.y };
291
+ }
288
292
  }
289
293
 
290
294
 
@@ -140,7 +140,7 @@ export class DyFM_Shared {
140
140
  * @param newData the object that that is needed to be updated
141
141
  * @param nestedListKey the location of nested dataList
142
142
  * @param nestIndexes path to the subject ect.: xData.listKey[1].listKey[4].listKey[0] will be [1, 4, 0]
143
- * @param dataToSet the actual value that will be setted on location
143
+ * @param dataToSet the actual value that will be seted on location
144
144
  * @returns modified data
145
145
  */
146
146
  static nestRecursiveListedData<T>(
@@ -165,35 +165,82 @@ export class DyFM_Shared {
165
165
  return newData;
166
166
  }
167
167
 
168
+ static readonly removeCirculation = this.resolveCirculation;
168
169
  /**
170
+ * THIS STILL NOT WORKING AS IT SHOULD
171
+ *
169
172
  * recursive function that returns mutated data structure,
170
173
  * with locations at which circular references are found
171
174
  */
172
175
  static resolveCirculation<T>(
173
176
  data: T,
174
- location: string[] = [ ('ROOT_' + data?.constructor?.name) ],
175
- objs: any[] = [ data ]
177
+ location: string[] = [ ('ROOT;' + data?.constructor?.name) ],
178
+ objs: any[] = [],
179
+ /* arrs: any[] = [] */
176
180
  ): any {
177
- if (!data || !Array.isArray(data) || typeof data !== 'object') {
181
+ if (!data || typeof data !== 'object') {
178
182
  return data;
183
+ } else if (objs.includes(data)) {
184
+ return 'CIRCULATION:' + location.join('.');
179
185
  }
180
186
 
181
- const newData = {};
182
-
187
+ let newData;
188
+
189
+ if (Array.isArray(data)) {
190
+ newData = [];
191
+ } else {
192
+ newData = {};
193
+ }
194
+
195
+ // using the utility that Object.keys will return array keys if the data is an array
183
196
  Object.keys(data).forEach((key: string): void => {
184
- if (typeof data[key] === 'object' || Array.isArray(data[key])) {
185
- if (objs.includes(data[key])) {
186
- newData[key] = 'CIRCULATION:' + location.join('.');
187
- } else {
188
- objs.push(data[key]);
189
- newData[key] = this.resolveCirculation(data[key], [ ...location, key ], objs);
190
- }
191
- } else {
192
- newData[key] = data[key];
193
- }
197
+ newData[key] = this.resolveCirculation(
198
+ data[key],
199
+ [ ...location, key ],
200
+ [ ...objs, data ]
201
+ );
194
202
  });
195
203
 
196
204
  return newData;
197
205
  }
198
206
 
207
+
208
+ /**
209
+ * looks for circular references in object
210
+ * returns duplicated object's all location paths and the object itself
211
+ *
212
+ * {
213
+ * object: any,
214
+ * pathsOfAllDuplications: string[],
215
+ * }[]
216
+ *
217
+ * paths are in a single string, separated by '.'
218
+ */
219
+ static findCirculations(
220
+ data: any,
221
+ location: string[] = [ ('ROOT;' + data?.constructor?.name) ],
222
+ objs: any[] = [],
223
+ duplications: { object: any, pathsOfAllDuplications: string[] }[] = []
224
+ ): { object: any, pathsOfAllDuplications: string[] }[] {
225
+ if (!data || typeof data !== 'object') {
226
+ return duplications;
227
+ } else if (objs.includes(data)) {
228
+ duplications.push({
229
+ object: data,
230
+ pathsOfAllDuplications: location,
231
+ });
232
+ }
233
+
234
+ Object.keys(data).forEach((key: string): void => {
235
+ this.findCirculations(
236
+ data[key],
237
+ [ ...location, key ],
238
+ [ ...objs, data ],
239
+ duplications
240
+ );
241
+ });
242
+
243
+ return duplications;
244
+ }
245
+
199
246
  }
@@ -3,6 +3,7 @@ import { day, hour, minute, month, second, week, year } from '../constants/times
3
3
  import { DyFM_Month } from '../../_enums/time/month.enum';
4
4
  import { DyFM_DayOfWeek } from '../../_enums/time/day-of-week.enum';
5
5
  import { DyFM_RelativeDate } from '../../_enums/time/relative-date.enum';
6
+ import { DyFM_Math } from './math/math.util';
6
7
 
7
8
  export type DyFM_T = DyFM_Time;
8
9
  export class DyFM_Time {
@@ -216,6 +217,28 @@ export class DyFM_Time {
216
217
  return year % 4 === 0;
217
218
  }
218
219
 
220
+ static getDurationString(duration: number): string {
221
+ if (duration === 0) {
222
+ return '0ms';
223
+ } else if (duration < second) {
224
+ return `${duration}ms`;
225
+ } else if (duration < minute) {
226
+ return `${DyFM_Math.round(duration / second)}s ${duration % second}ms`;
227
+ } else if (duration < hour) {
228
+ return `${DyFM_Math.round(duration / minute)}m ${DyFM_Math.round(duration % minute)}s`;
229
+ } else if (duration < day) {
230
+ return `${DyFM_Math.round(duration / hour)}h ${DyFM_Math.round(duration % hour)}m`;
231
+ } else if (duration < week) {
232
+ return `${DyFM_Math.round(duration / day)}d ${DyFM_Math.round(duration % day)}h`;
233
+ } else if (duration < month) {
234
+ return `${DyFM_Math.round(duration / week)}w ${DyFM_Math.round(duration % week)}d`;
235
+ } else if (duration < year) {
236
+ return `${DyFM_Math.round(duration / month)}m ${DyFM_Math.round(duration % month)}w`;
237
+ } else {
238
+ return `${DyFM_Math.round(duration / year)}y ${DyFM_Math.round(duration % year)}m`;
239
+ }
240
+ }
241
+
219
242
  static getTimeInShortestString(time: number): string {
220
243
  if (time % year === 0) {
221
244
  return `${time / year}y`;
@@ -4,6 +4,14 @@ import { DyFM_error_defaults } from '../../_collections/constants/error-defaults
4
4
  import { DyFM_Log } from '../../_collections/utils/log.util';
5
5
  import { DyFM_Error } from './error.control-model';
6
6
 
7
+ function testFormatter(any: any): any {
8
+ if (any instanceof Error) {
9
+ return any;
10
+ } else {
11
+ return `\n${JSON.stringify(any, null, 2)}\n`;
12
+ }
13
+ }
14
+
7
15
  describe('DyFM_Error;', (): void => {
8
16
  let error_base: Error;
9
17
  let error_0: DyFM_Error;
@@ -16,7 +24,7 @@ describe('DyFM_Error;', (): void => {
16
24
  const message_base: string = '-TEST ERROR: something failed!-';
17
25
  const message_1: string = 'TEST ERROR MSG (1)';
18
26
  const message_2: string = 'TEST ERROR MSG (2)';
19
- const message_selfDefined: string = 'error.control-model.spec.js:82:29';
27
+ const message_selfDefined: string = 'error.control-model.spec.js:89:29';
20
28
 
21
29
  const errorCode_0: string = 'ASD-ASD-001';
22
30
  const errorCode_1: string = 'ASD-ASD-002';
@@ -71,9 +79,9 @@ describe('DyFM_Error;', (): void => {
71
79
  ...error_stack_1,
72
80
  } as DyFM_Error;
73
81
  error_stack_withoutSubErrors_1.errors.forEach((error: DyFM_Error): any => {
74
- const subError = { ...error };
82
+ const subError = { ...error } as DyFM_Error;
75
83
 
76
- delete (subError as DyFM_Error).errors;
84
+ delete subError.errors;
77
85
 
78
86
  return subError;
79
87
  });
@@ -90,12 +98,13 @@ describe('DyFM_Error;', (): void => {
90
98
  error_stack_withoutSubErrors_2 = {
91
99
  ...error_stack_2,
92
100
  } as DyFM_Error;
93
- error_stack_withoutSubErrors_2.errors.map((error: DyFM_Error): any => {
94
- const subError = { ...error };
95
101
 
96
- delete (subError as DyFM_Error).errors;
102
+ error_stack_withoutSubErrors_2.errors = error_stack_withoutSubErrors_2.errors.map(
103
+ (error: DyFM_Error): any => ({ ...error })
104
+ );
97
105
 
98
- return subError;
106
+ error_stack_withoutSubErrors_2.errors.forEach((subError: DyFM_Error): any => {
107
+ delete subError.errors;
99
108
  });
100
109
 
101
110
  error_selfDefined = new DyFM_Error();
@@ -301,19 +310,25 @@ describe('DyFM_Error;', (): void => {
301
310
 
302
311
  describe('should have proper error;', (): void => {
303
312
  it('on error_0', (): void => {
304
- expect(error_0.error).toBe(error_base);
313
+ expect(testFormatter(error_0.error)).toBe(
314
+ testFormatter(error_base)
315
+ );
305
316
  });
306
317
 
307
318
  it('on error_stack_1', (): void => {
308
- expect(error_stack_1.error).toBe(error_base);
319
+ expect(testFormatter(error_stack_1.error)).toBe(
320
+ testFormatter(error_base)
321
+ );
309
322
  });
310
323
 
311
324
  it('on error_stack_2', (): void => {
312
- expect(error_stack_2.error).toBe(error_base);
325
+ expect(testFormatter(error_stack_2.error)).toBe(
326
+ testFormatter(error_base)
327
+ );
313
328
  });
314
329
 
315
330
  it('on self defined error', (): void => {
316
- expect(error_selfDefined.error).toBeDefined();
331
+ expect(testFormatter(error_selfDefined.error)).toBeDefined();
317
332
  });
318
333
  });
319
334
 
@@ -323,11 +338,28 @@ describe('DyFM_Error;', (): void => {
323
338
  });
324
339
 
325
340
  it('on error_stack_1', (): void => {
326
- expect(error_stack_1.errors).toEqual([ error_base, error_0 ]);
341
+ const error_0_withoutSubErrors = { ...error_0 } as DyFM_Error;
342
+
343
+ delete error_0_withoutSubErrors.errors;
344
+ delete error_0_withoutSubErrors.additionalContent;
345
+
346
+ expect(testFormatter(error_stack_1.errors)).toEqual(
347
+ testFormatter([ error_base, error_0_withoutSubErrors ])
348
+ );
327
349
  });
328
350
 
329
351
  it('on error_stack_2', (): void => {
330
- expect(error_stack_2.errors).toEqual([ error_base, error_0, error_stack_1 ]);
352
+ const error_0_withoutSubErrors = { ...error_0 } as DyFM_Error;
353
+ const error_stack_1_withoutSubErrors = { ...error_stack_1 } as DyFM_Error;
354
+
355
+ delete error_0_withoutSubErrors.errors;
356
+ delete error_0_withoutSubErrors.additionalContent;
357
+ delete error_stack_1_withoutSubErrors.errors;
358
+ delete error_stack_1_withoutSubErrors.additionalContent;
359
+
360
+ expect(testFormatter(error_stack_2.errors)).toEqual(
361
+ testFormatter([ error_base, error_0_withoutSubErrors, error_stack_1_withoutSubErrors ])
362
+ );
331
363
  });
332
364
 
333
365
  it('on self defined error', (): void => {