@seniorsistemas/hcm-clocking-event-rule-nodejs 0.35.0

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 (128) hide show
  1. package/.github/copilot-instructions.md +11 -0
  2. package/.github/workflows/release.yaml +10 -0
  3. package/.gitlab-ci.yml +68 -0
  4. package/CHANGELOG.md +274 -0
  5. package/README.doc.md +658 -0
  6. package/README.md +117 -0
  7. package/assets/favicon.ico +0 -0
  8. package/catalog-info.yaml +19 -0
  9. package/jest.config.js +17 -0
  10. package/package.json +48 -0
  11. package/prompt.md +15 -0
  12. package/run_build_win.bat +1 -0
  13. package/run_link.bat +3 -0
  14. package/run_test.bat +1 -0
  15. package/sonar-project.properties +21 -0
  16. package/src/data/changes/changes.ts +92 -0
  17. package/src/data/context/context.ts +251 -0
  18. package/src/data/context/contextReference.ts +376 -0
  19. package/src/data/contract/contract.ts +272 -0
  20. package/src/data/dataset/database.ts +130 -0
  21. package/src/data/dataset/dataset.ts +275 -0
  22. package/src/data/definition/timeEvaluationSituationDefinitionHistory.ts +1425 -0
  23. package/src/data/employee/employee.ts +434 -0
  24. package/src/data/foundation/companyBranch.ts +66 -0
  25. package/src/data/foundation/costCenter.ts +47 -0
  26. package/src/data/foundation/employer.ts +35 -0
  27. package/src/data/foundation/employmentRelationship.ts +63 -0
  28. package/src/data/foundation/holiday.ts +84 -0
  29. package/src/data/foundation/holidayGroup.ts +47 -0
  30. package/src/data/foundation/jobPosition.ts +73 -0
  31. package/src/data/foundation/person.ts +35 -0
  32. package/src/data/foundation/situation.ts +301 -0
  33. package/src/data/foundation/syndicate.ts +244 -0
  34. package/src/data/foundation/workschedule.ts +688 -0
  35. package/src/data/foundation/workshift.ts +647 -0
  36. package/src/data/foundation/workshiftBase.ts +113 -0
  37. package/src/data/histories/companyBranchHistory.ts +128 -0
  38. package/src/data/histories/costCenterHistory.ts +114 -0
  39. package/src/data/histories/employmentRelationshipHistory.ts +116 -0
  40. package/src/data/histories/histories.ts +419 -0
  41. package/src/data/histories/jobPositionHistory.ts +117 -0
  42. package/src/data/histories/leaveHistory.ts +227 -0
  43. package/src/data/histories/timeEvaluationHistory.ts +191 -0
  44. package/src/data/histories/workshiftHistory.ts +66 -0
  45. package/src/data/hourBank/hourBank.ts +43 -0
  46. package/src/data/hourBank/hourBankAccount.ts +77 -0
  47. package/src/data/log/log.ts +38 -0
  48. package/src/data/schedules/bridge.ts +84 -0
  49. package/src/data/schedules/compensation.ts +332 -0
  50. package/src/data/schedules/overtimeAuthorization.ts +174 -0
  51. package/src/data/schedules/readiness.ts +150 -0
  52. package/src/data/schedules/schedules.ts +398 -0
  53. package/src/data/schedules/workscheduleChange.ts +91 -0
  54. package/src/data/schedules/workshiftChange.ts +76 -0
  55. package/src/data/timeEvaluation/adjustmentReason.ts +46 -0
  56. package/src/data/timeEvaluation/clockingEvent.ts +198 -0
  57. package/src/data/timeEvaluation/estimatedHours.ts +245 -0
  58. package/src/data/timeEvaluation/interval.ts +568 -0
  59. package/src/data/timeEvaluation/separatedHours.ts +134 -0
  60. package/src/data/timeEvaluation/timeEvaluation.ts +1540 -0
  61. package/src/data/timeEvaluation/timeEvaluationSituation.ts +154 -0
  62. package/src/data/user/user.ts +44 -0
  63. package/src/index.ts +60 -0
  64. package/src/test/builder/bridgeBuilder.builder.ts +28 -0
  65. package/src/test/builder/clockingEvent.builder.ts +49 -0
  66. package/src/test/builder/companyBranchHistoryBuilder.ts +29 -0
  67. package/src/test/builder/compensation.builder.ts +84 -0
  68. package/src/test/builder/contextReference.builder.ts +69 -0
  69. package/src/test/builder/costCenterHistoryBuilder.ts +29 -0
  70. package/src/test/builder/database.builder.ts +21 -0
  71. package/src/test/builder/datasetBuilder.ts +111 -0
  72. package/src/test/builder/dateIntervalBuilder.ts +25 -0
  73. package/src/test/builder/employee.builder.ts +91 -0
  74. package/src/test/builder/employmentRelationshipBuilder.ts +35 -0
  75. package/src/test/builder/employmentRelationshipHistoryBuilder.ts +29 -0
  76. package/src/test/builder/historiesBuilder.ts +56 -0
  77. package/src/test/builder/holiday.builder.ts +44 -0
  78. package/src/test/builder/hourBankAccountBuilder.ts +77 -0
  79. package/src/test/builder/hourBankBuilder.ts +32 -0
  80. package/src/test/builder/interval.builder.ts +113 -0
  81. package/src/test/builder/jobPositionHistoryBuilder.ts +29 -0
  82. package/src/test/builder/overtimeAuthorization.builder.ts +42 -0
  83. package/src/test/builder/readinessBuilder.builder.ts +57 -0
  84. package/src/test/builder/schedules.builder.ts +126 -0
  85. package/src/test/builder/situation.builder.ts +59 -0
  86. package/src/test/builder/syndicate.builder.ts +96 -0
  87. package/src/test/builder/syndicateHistoryBuilder.ts +33 -0
  88. package/src/test/builder/timeEvaluation.builder.ts +138 -0
  89. package/src/test/builder/timeEvaluationHistory.builder.ts +49 -0
  90. package/src/test/builder/timeEvaluationSituation.builder.ts +34 -0
  91. package/src/test/builder/workschedule.builder.ts +96 -0
  92. package/src/test/builder/workshift.builder.ts +179 -0
  93. package/src/test/builder/workshiftBuilder.ts +55 -0
  94. package/src/test/data/clockingEvent.spec.ts +56 -0
  95. package/src/test/data/context.spec.ts +176 -0
  96. package/src/test/data/currentUser.spec.ts +11 -0
  97. package/src/test/data/dataset.spec.ts +144 -0
  98. package/src/test/data/employee/employee.spec.ts +20 -0
  99. package/src/test/data/employmentRelationship/employmentRelationship.spec.ts +48 -0
  100. package/src/test/data/estimatedHours/estimatedHours.spec.ts +96 -0
  101. package/src/test/data/histories/costCenterHistory.spec.ts +32 -0
  102. package/src/test/data/histories/histories.spec.ts +306 -0
  103. package/src/test/data/holyday.spec.ts +89 -0
  104. package/src/test/data/hourBank/hourBank.spec.ts +48 -0
  105. package/src/test/data/hourBank/hourBankAccount.spec.ts +32 -0
  106. package/src/test/data/schedules/bridge.spec.ts +13 -0
  107. package/src/test/data/schedules/compesation.spect.ts +89 -0
  108. package/src/test/data/schedules/overtimeAuthorization.spec.ts +52 -0
  109. package/src/test/data/schedules/readiness.spec.ts +64 -0
  110. package/src/test/data/schedules/schedules.spec.ts +134 -0
  111. package/src/test/data/schedules/workscheduleChange.spec.ts +21 -0
  112. package/src/test/data/syndicate/syndicate.spec.ts +51 -0
  113. package/src/test/data/timeEvaluation.spec.ts +1057 -0
  114. package/src/test/data/timeEvaluationDefinition.spec.ts +144 -0
  115. package/src/test/data/workschedule/workschedule.spec.ts +194 -0
  116. package/src/test/data/workshift/workshift.spec.ts +79 -0
  117. package/src/test/utils/date.utils.spec.ts +198 -0
  118. package/src/test/utils/dateIntervalUtils.spec.ts +210 -0
  119. package/src/test/utils/object.utils.spec.ts +83 -0
  120. package/src/utils/dateIntervalUtils.ts +284 -0
  121. package/src/utils/dateUtils.ts +456 -0
  122. package/src/utils/decompressGzipLambda.ts +15 -0
  123. package/src/utils/object.utils.ts +156 -0
  124. package/trivy/vulnerabilities_scan.json +1160 -0
  125. package/tsconfig.json +32 -0
  126. package/tsconfig.spec.json +21 -0
  127. package/tslint.json +92 -0
  128. package/typedoc.json +22 -0
@@ -0,0 +1,456 @@
1
+ const MINUTE_IN_MILI = 60000;
2
+ /**
3
+ * Enumeração para os dias da semana.
4
+ * @enum
5
+ */
6
+ export enum WeekDay {
7
+ /**
8
+ * Domingo.
9
+ */
10
+ SUNDAY = "SUNDAY",
11
+ /**
12
+ * Segunda-feira.
13
+ */
14
+ MONDAY = "MONDAY",
15
+ /**
16
+ * Terça-feira.
17
+ */
18
+ TUESDAY = "TUESDAY",
19
+ /**
20
+ * Quarta-feira.
21
+ */
22
+ WEDNESDAY = "WEDNESDAY",
23
+ /**
24
+ * Quinta-feira.
25
+ */
26
+ THURSDAY = "THURSDAY",
27
+ /**
28
+ * Sexta-feira.
29
+ */
30
+ FRIDAY = "FRIDAY",
31
+ /**
32
+ * Sábado.
33
+ */
34
+ SATURDAY = "SATURDAY"
35
+ }
36
+
37
+
38
+ /**
39
+ * Classe utilitária para trabalhar com datas.
40
+ */
41
+ export const DateUtils = {
42
+ /**
43
+ * Constante para menor data possível.
44
+ *
45
+ * @example
46
+ * ```javascript
47
+ * const minDate = DateUtils.MIN_DATE; // 1900-12-31
48
+ * ```
49
+ */
50
+ MIN_DATE: new Date("1900-12-31"),
51
+ /**
52
+ * Constante para maior data possível.
53
+ *
54
+ * @example
55
+ * ```javascript
56
+ * const maxDate = DateUtils.MAX_DATE; // 2099-12-31
57
+ * ```
58
+ *
59
+ */
60
+ MAX_DATE: new Date("2099-12-31"),
61
+ /**
62
+ * Compara diferença das datas em minutos.
63
+ *
64
+ * @example
65
+ * ```javascript
66
+ * const start = new Date("2024-01-01T00:00:00Z");
67
+ * const end = new Date("2024-01-01T01:00:00Z");
68
+ * const minutes = DateUtils.getDateInMinutes(start, end);
69
+ * console.log(minutes); // 60
70
+ * ```
71
+ *
72
+ * @param start Data inicial.
73
+ * @param end Data final.
74
+ *
75
+ * @returns Quantidade de minutos.
76
+ */
77
+ getDateInMinutes(start: Date, end: Date): number {
78
+
79
+ const diffMs = Math.abs(start.getTime() - end.getTime()); // Diferença em milissegundos.
80
+ return Math.floor(diffMs / (1000 * 60)); // Converter para minutos.
81
+
82
+ },
83
+ /**
84
+ * Criar um data conforme os parâmetros informados.
85
+ *
86
+ * @example
87
+ * ```javascript
88
+ * const date = DateUtils.of(2024, 1, 1);
89
+ * console.log(date); // 2024-01-01T00:00:00Z
90
+ * ```
91
+ *
92
+ * @param year Ano.
93
+ * @param month Mês.
94
+ * @param day Dia.
95
+ * @returns Date.
96
+ */
97
+ of(year: number, month: number, day: number): Date {
98
+ return new Date(`${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}T00:00:00Z`);;
99
+ },
100
+ /**
101
+ * Converte um string para no formato yyyy-MM-dd para um data.
102
+ *
103
+ * @example
104
+ * ```javascript
105
+ * const date = DateUtils.strIsoDateToDate("2024-01-01");
106
+ * console.log(date); // 2024-01-01T00:00:00Z
107
+ * ```
108
+ *
109
+ * @param date Data no formato yyyy-MM-dd.
110
+ * @return Data.
111
+ */
112
+ strIsoDateToDate(date: string): Date {
113
+ return new Date(`${date}T00:00:00Z`);
114
+ },
115
+ /**
116
+ * Converte uma data para um string no formato ISODate (yyyy-mm-dd).
117
+ *
118
+ * @example
119
+ * ```javascript
120
+ * const date = new Date("2024-01-01T00:00:00Z");
121
+ * const isoDateStr = DateUtils.dateToIsoDateStr(date);
122
+ * console.log(isoDateStr); // 2024-01-01
123
+ * ```
124
+ *
125
+ * @param date
126
+ * @returns
127
+ */
128
+ dateToIsoDateStr(date: Date): string{
129
+ return date.toISOString().split('T')[0];
130
+ },
131
+ /**
132
+ * Compara se a data oneDate é anterior a data otherDate.
133
+ *
134
+ * @example
135
+ * ```javascript
136
+ * const date1 = new Date("2024-01-01T00:00:00Z");
137
+ * const date2 = new Date("2024-01-02T00:00:00Z");
138
+ * const isBefore = DateUtils.isBefore(date1, date2);
139
+ * console.log(isBefore); // true
140
+ * ```
141
+ *
142
+ * @param oneDate Data 1.
143
+ * @param otherDate Data 2.
144
+ * @returns True se oneDate for anterior a otherDate.
145
+ */
146
+ isBefore(oneDate: Date, otherDate: Date): boolean {
147
+ return oneDate.getTime() < otherDate.getTime();
148
+ },
149
+ /**
150
+ * Verificar se a data oneDate é anterior ou igual a data otherDate.
151
+ *
152
+ * @example
153
+ * ```javascript
154
+ * const date1 = new Date("2024-01-01T00:00:00Z");
155
+ * const date2 = new Date("2024-01-01T00:00:00Z");
156
+ * const isBeforeOrEquals = DateUtils.isBeforeOrEquals(date1, date2);
157
+ * console.log(isBeforeOrEquals); // true
158
+ * ```
159
+ *
160
+ * @param oneDate Uma data.
161
+ * @param otherDate Outra data.
162
+ * @returns True se oneDate for anterior ou igual a otherDate.
163
+ */
164
+ isBeforeOrEquals(oneDate: Date, otherDate: Date): boolean {
165
+ return oneDate.getTime() <= otherDate.getTime();
166
+ },
167
+ /**
168
+ * Verificar se a data oneDate é posterior a data otherDate.
169
+ *
170
+ * @example
171
+ * ```javascript
172
+ * const date1 = new Date("2024-01-02T00:00:00Z");
173
+ * const date2 = new Date("2024-01-01T00:00:00Z");
174
+ * const isAfter = DateUtils.isAfter(date1, date2);
175
+ * console.log(isAfter); // true
176
+ * ```
177
+ *
178
+ * @param oneDate Uma data.
179
+ * @param otherDate Outra data.
180
+ * @returns True se oneDate for posterior a otherDate.
181
+ */
182
+ isAfter(oneDate: Date, otherDate: Date): boolean {
183
+ return oneDate.getTime() > otherDate.getTime();
184
+ },
185
+ /**
186
+ * Verificar se a data oneDate é posterior ou igual a data otherDate.
187
+ *
188
+ * @example
189
+ * ```javascript
190
+ * const date1 = new Date("2024-01-01T00:00:00Z");
191
+ * const date2 = new Date("2024-01-01T00:00:00Z");
192
+ * const isAfterOrEquals = DateUtils.isAfterOrEquals(date1, date2);
193
+ * console.log(isAfterOrEquals); // true
194
+ * ```
195
+ *
196
+ * @param oneDate Uma data.
197
+ * @param otherDate Outra data.
198
+ * @returns True se oneDate for posterior ou igual a otherDate.
199
+ */
200
+ isAfterOrEquals(oneDate: Date, otherDate: Date): boolean {
201
+ return oneDate.getTime() >= otherDate.getTime();
202
+ },
203
+ /**
204
+ * Compara a datas, retorna 0 se forem iguais, 1 se oneDate for maior que otherDate e -1 se oneDate for menor que otherDate.
205
+ *
206
+ * @example
207
+ * ```javascript
208
+ * const date1 = new Date("2024-01-01T00:00:00Z");
209
+ * const date2 = new Date("2024-01-02T00:00:00Z");
210
+ * const comparison = DateUtils.compareTo(date1, date2);
211
+ * console.log(comparison); // -1 (date1 é menor que date2)
212
+ * const date3 = new Date("2024-01-01T00:00:00Z");
213
+ * const comparison2 = DateUtils.compareTo(date1, date3);
214
+ * console.log(comparison2); // 0 (date1 é igual a date3)
215
+ * const date4 = new Date("2024-01-03T00:00:00Z");
216
+ * const comparison3 = DateUtils.compareTo(date1, date4);
217
+ * console.log(comparison3); // 1 (date1 é menor que date4)
218
+ * ```
219
+ *
220
+ *
221
+ * @param oneDate Uma data.
222
+ * @param otherDate Outra data.
223
+ * @returns 0 se forem iguais, 1 se oneDate for maior que otherDate e -1 se oneDate for menor que otherDate.
224
+ */
225
+ compareTo(oneDate: Date, otherDate: Date): number {
226
+ return oneDate.getTime() - otherDate.getTime();
227
+ },
228
+ /**
229
+ * Verifica se a data esta dentro do intervalor, incluindo as datas inicial e final.
230
+ *
231
+ * @example
232
+ * ```javascript
233
+ * const date = new Date("2024-01-01T00:00:00Z");
234
+ * const start = new Date("2024-01-01T00:00:00Z");
235
+ * const end = new Date("2024-01-02T00:00:00Z");
236
+ * const isBetween = DateUtils.between(date, start, end);
237
+ * console.log(isBetween); // true (date está entre start e end, inclusive).
238
+ * ```
239
+ *
240
+ * @param date Data a ser verificada.
241
+ * @param start Data inicial.
242
+ * @param end Data final.
243
+ * @returns True se a data esta dentro do intervalo.
244
+ */
245
+ between(date: Date, start: Date, end: Date): boolean {
246
+ return date.getTime() >= start.getTime() && date.getTime() <= end.getTime();
247
+ },
248
+ /**
249
+ * Verificar se as datas são iguais.
250
+ *
251
+ * @example
252
+ * ```javascript
253
+ * const date1 = new Date("2024-01-01T00:00:00Z");
254
+ * const date2 = new Date("2024-01-01T00:00:00Z");
255
+ * const isEqual = DateUtils.equals(date1, date2);
256
+ * console.log(isEqual); // true (date1 é igual a date2)
257
+ * const date3 = new Date("2024-01-02T00:00:00Z");
258
+ * const isEqual2 = DateUtils.equals(date1, date3);
259
+ * console.log(isEqual2); // false (date1 é diferente de date3)
260
+ * ```
261
+ *
262
+ * @param oneDate Uma data.
263
+ * @param otherDate Outra data.
264
+ * @returns True se forem iguais.
265
+ */
266
+ equals(oneDate: Date, otherDate: Date): boolean {
267
+ return oneDate.getTime() === otherDate.getTime();
268
+ },
269
+ /**
270
+ * Retorna o dia da semana de uma data.
271
+ *
272
+ * @example
273
+ * ```javascript
274
+ * const date = new Date("2024-01-01T00:00:00Z");
275
+ * const weekDay = DateUtils.getWeekDay(date);
276
+ * console.log(weekDay); // "TUESDAY" (dia da semana correspondente a 1 de janeiro de 2024).
277
+ * ```
278
+ *
279
+ * @param date Data.
280
+ * @returns Representação do dia da semana.
281
+ */
282
+ getWeekDay(date: Date): string {
283
+ const days: WeekDay[] = [
284
+ WeekDay.SUNDAY,
285
+ WeekDay.MONDAY,
286
+ WeekDay.TUESDAY,
287
+ WeekDay.WEDNESDAY,
288
+ WeekDay.THURSDAY,
289
+ WeekDay.FRIDAY,
290
+ WeekDay.SATURDAY
291
+
292
+ ];
293
+ return days[date.getDay()];
294
+ },
295
+ /**
296
+ * Retorna o dia da data.
297
+ *
298
+ * @example
299
+ * ```javascript
300
+ * const date = new Date("2024-01-01T00:00:00Z");
301
+ * const day = DateUtils.getDay(date);
302
+ * console.log(day); // 1 (dia do mês correspondente a 1 de janeiro de 2024).
303
+ * ```
304
+ *
305
+ * @param date Data.
306
+ * @returns
307
+ */
308
+ getDay(date: Date): number {
309
+ return date.getDate();
310
+ },
311
+ /**
312
+ * Retorna o mês da data.
313
+ * Ex.: Janeiro = 1, Fevereiro = 2, ....
314
+ *
315
+ * @example
316
+ * ```javascript
317
+ * const date = new Date("2024-01-02T00:00:00Z");
318
+ * const month = DateUtils.getMonth(date);
319
+ * console.log(month); // 1 (mês de janeiro).
320
+ * ```
321
+ *
322
+ * @param date Data.
323
+ * @returns
324
+ */
325
+ getMonth(date: Date): number {
326
+ return date.getMonth() + 1;
327
+ },
328
+ /**
329
+ * Retorna o ano da data.
330
+ * Ex.: 01/02/2034 = 2034
331
+ *
332
+ * @example
333
+ * ```javascript
334
+ * const date = new Date("2024-01-01T00:00:00Z");
335
+ * const year = DateUtils.getYear(date);
336
+ * console.log(year); // 2024 (ano correspondente a 1 de janeiro de 2024).
337
+ * ```
338
+ *
339
+ * @param date Data.
340
+ * @returns Ano da data.
341
+ */
342
+ getYear(date: Date): number {
343
+ return date.getFullYear();
344
+ },
345
+ /**
346
+ * Numero de dias de um mês.
347
+ * ex.: 01/01/2023 = 31, 06/04/2039 = 30
348
+ *
349
+ * @example
350
+ * ```javascript
351
+ * const date = new Date("2024-01-01T00:00:00Z");
352
+ * const daysInMonth = DateUtils.getNumberOfDaysInMonth(date);
353
+ * console.log(daysInMonth); // 31 (janeiro tem 31 dias).
354
+ * ```
355
+ *
356
+ * @param date Data.
357
+ * @returns Número de dias do mês.
358
+ */
359
+ getNumberOfDaysInMonth(date: Date): number {
360
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
361
+ },
362
+ /**
363
+ * Retorna a últida data do mês.
364
+ * Ex.: 03/01/2034 = 31/01/2034.
365
+ *
366
+ * @example
367
+ * ```javascript
368
+ * const date = new Date("2024-01-01T00:00:00Z");
369
+ * const lastDayOfMonth = DateUtils.getLastDayOfMonth(date);
370
+ * console.log(lastDayOfMonth); // 2024-01-31T00:00:00Z (último dia de janeiro de 2024).
371
+ * ```
372
+ *
373
+ * @param date Data.
374
+ * @returns Última data do mês.
375
+ */
376
+ getLastDayOfMonth(date: Date): Date {
377
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0);
378
+ },
379
+ /**
380
+ * Soma a quantidade de minutos de uma data.
381
+ * Ex.: 02/03/2024 08:00:00, somar 30 minutos, é igual a 02/03/2024 08:30:00.
382
+ *
383
+ * @example
384
+ * ```javascript
385
+ * const date = new Date("2024-03-02T08:00:00Z");
386
+ * const newDate = DateUtils.addMinutes(date, 30);
387
+ * console.log(newDate); // 2024-03-02T08:30:00Z (data com 30 minutos adicionados).
388
+ * ```
389
+ *
390
+ * @param date Data.
391
+ * @param minutes Quantidade minutos para somar.
392
+ * @returns Nova data com os minutos somados.
393
+ */
394
+ addMinutes(date: Date, minutes: number): Date {
395
+ return new Date(date.getTime() + minutes * MINUTE_IN_MILI);
396
+ },
397
+ /**
398
+ * Substrai a quantidade de minutos de uma data.
399
+ * Ex.: 02/03/2024 08:00:00, substrair 30 minutos, é igual a 02/03/2024 07:30:00.
400
+ *
401
+ * @example
402
+ * ```javascript
403
+ * const date = new Date("2024-03-02T08:00:00Z");
404
+ * const newDate = DateUtils.subMinutes(date, 30);
405
+ * console.log(newDate); // 2024-03-02T07:30:00Z (data com 30 minutos subtraídos).
406
+ * ```
407
+ *
408
+ * @param date Data.
409
+ * @param minutes Quantidade minutos para substrair.
410
+ * @returns Nova data com os minutos subtraídos.
411
+ */
412
+ subMinutes(date: Date, minutes: number): Date {
413
+ return new Date(date.getTime() - minutes * MINUTE_IN_MILI);
414
+ },
415
+ /**
416
+ * Retornar a quantidade dias entre duas datas.
417
+ * Ex.: 02/02/2034 -> 12/02/2034 = 10 dias.
418
+ *
419
+ * @example
420
+ * ```javascript
421
+ * const dateStart = new Date("2024-02-02T00:00:00Z");
422
+ * const dateEnd = new Date("2024-02-12T00:00:00Z");
423
+ * const days = DateUtils.days(dateStart, dateEnd);
424
+ * console.log(days); // 10 (dias entre 2 de fevereiro de 2024 e 12 de fevereiro de 2024).
425
+ * ```
426
+ *
427
+ * @param dateStart Data inicial.
428
+ * @param dateEnd Data final.
429
+ * @returns
430
+ */
431
+
432
+ days(dateStart: Date, dateEnd: Date): number {
433
+ const diffTime = dateEnd.getTime() - dateStart.getTime();
434
+ return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
435
+ },
436
+ /**
437
+ * Formata uma data no formato dd/MM/yyyy.
438
+ * Ex.: 2025-04-08 -> 08/04/2025.
439
+ *
440
+ * @example
441
+ * ```javascript
442
+ * const date = new Date("2025-04-08T00:00:00Z");
443
+ * const formattedDate = DateUtils.format(date);
444
+ * console.log(formattedDate); // "08/04/2025"
445
+ * ```
446
+ *
447
+ * @param date Data a ser formatada.
448
+ * @returns Data formatada como string.
449
+ */
450
+ format(date: Date): string {
451
+ const day = String(date.getDate()).padStart(2, '0');
452
+ const month = String(date.getMonth() + 1).padStart(2, '0');
453
+ const year = date.getFullYear();
454
+ return `${day}/${month}/${year}`;
455
+ },
456
+ };
@@ -0,0 +1,15 @@
1
+ import { gunzipSync, gzipSync } from 'zlib';
2
+
3
+ /**
4
+ * Função síncrona para descompactar dados GZIP.
5
+ * @param compressedPayload Buffer contendo dados comprimidos.
6
+ * @returns String com conteúdo descomprimido.
7
+ */
8
+ export function decompressGzipSync(compressedPayload: Buffer): string {
9
+ const decompressedBuffer = gunzipSync(compressedPayload);
10
+ return decompressedBuffer.toString('utf-8');
11
+ }
12
+
13
+ export function compressGzipSync(payload: string): Buffer {
14
+ return gzipSync(payload);
15
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Classe utilitária para trabalhar com objetos.
3
+ */
4
+ export const ObjectUtils = {
5
+ /**
6
+ * Compara se o objeto existe e não é vazio.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { ObjectUtils } from './object.utils';
11
+ * const obj = { key: 'value' };
12
+ * console.log(ObjectUtils.isObjectNotEmpty(obj)); // true
13
+ * const emptyObj = {};
14
+ * console.log(ObjectUtils.isObjectNotEmpty(emptyObj)); // false
15
+ * const nullObj = null;
16
+ * console.log(ObjectUtils.isObjectNotEmpty(nullObj)); // false
17
+ * const undefinedObj = undefined;
18
+ * console.log(ObjectUtils.isObjectNotEmpty(undefinedObj)); // false
19
+ * const str = "Hello";
20
+ * console.log(ObjectUtils.isObjectNotEmpty(str)); // false
21
+ * const num = 42;
22
+ * console.log(ObjectUtils.isObjectNotEmpty(num)); // false
23
+ * const arr = [1, 2, 3];
24
+ * console.log(ObjectUtils.isObjectNotEmpty(arr)); // true
25
+ * const emptyArr: any[] = [];
26
+ * console.log(ObjectUtils.isObjectNotEmpty(emptyArr)); // false
27
+ * const date = new Date();
28
+ * console.log(ObjectUtils.isObjectNotEmpty(date)); // true
29
+ * const emptyDate = new Date("");
30
+ * console.log(ObjectUtils.isObjectNotEmpty(emptyDate)); // false
31
+ * ```
32
+ *
33
+ * @param obj Objeto.
34
+ */
35
+ isObjectEmpty: (obj: any): boolean => {
36
+ return obj && typeof obj === "object" && Object.keys(obj).length === 0;
37
+ },
38
+ /**
39
+ * Verificar se é tipo Date.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * import { ObjectUtils } from './object.utils';
44
+ * const date = new Date();
45
+ * console.log(ObjectUtils.isDateInstance(date)); // true
46
+ * const notDate = "2024-01-01";
47
+ * console.log(ObjectUtils.isDateInstance(notDate)); // false
48
+ * const nullDate = null;
49
+ * console.log(ObjectUtils.isDateInstance(nullDate)); // false
50
+ * const undefinedDate = undefined;
51
+ * console.log(ObjectUtils.isDateInstance(undefinedDate)); // false
52
+ * const emptyObj = {};
53
+ * console.log(ObjectUtils.isDateInstance(emptyObj)); // false
54
+ * const emptyDate = new Date("");
55
+ * console.log(ObjectUtils.isDateInstance(emptyDate)); // false
56
+ * const arr = [1, 2, 3];
57
+ * console.log(ObjectUtils.isDateInstance(arr)); // false
58
+ * const emptyArr: any[] = [];
59
+ * console.log(ObjectUtils.isDateInstance(emptyArr)); // false
60
+ * const str = "Hello";
61
+ * console.log(ObjectUtils.isDateInstance(str)); // false
62
+ * const num = 42;
63
+ * console.log(ObjectUtils.isDateInstance(num)); // false
64
+ * const validDate = new Date("2024-01-01T00:00:00Z");
65
+ * console.log(ObjectUtils.isDateInstance(validDate)); // true
66
+ * const invalidDate = new Date("invalid date");
67
+ * console.log(ObjectUtils.isDateInstance(invalidDate)); // false
68
+ * ```
69
+ *
70
+ * @param obj Objeto.
71
+ * @returns
72
+ */
73
+ isDateInstance: (obj: any): boolean => {
74
+ return obj instanceof Date && !isNaN(obj.getTime());
75
+ },
76
+
77
+ /**
78
+ * Confirmar que o objeto recebido é uma Data, se o parâmetro for uma String deve converter para um tipo Date, caso for null, deve gerar um erro.
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * import { ObjectUtils } from './object.utils';
83
+ * const date = new Date("2024-01-01T00:00:00Z");
84
+ * console.log(ObjectUtils.toDateOrThrow(date)); // 2024-01-01T00:00:00Z
85
+ * const strDate = "2024-01-01";
86
+ * console.log(ObjectUtils.toDateOrThrow(strDate)); // 2024-01-01T00:00:00Z
87
+ * const invalidDate = "invalid date";
88
+ * console.log(ObjectUtils.toDateOrThrow(invalidDate)); // Error: O campo "date" não é uma data válida: invalid date
89
+ * const nullDate = null;
90
+ * console.log(ObjectUtils.toDateOrThrow(nullDate)); // Error: O campo "date" não é uma data válida: null
91
+ * const undefinedDate = undefined;
92
+ * console.log(ObjectUtils.toDateOrThrow(undefinedDate)); // Error: O campo "date" não é uma data válida: undefined
93
+ * ```
94
+ *
95
+ * @param value Objeto.
96
+ * @returns
97
+ */
98
+ toDateOrThrow: (value: unknown, fieldName = 'date'): Date => {
99
+ const dateOrNull = ObjectUtils.toDateOrNull(value);
100
+ if (dateOrNull !== null) {
101
+ return dateOrNull;
102
+ }
103
+ throw new Error(`O campo "${fieldName}" não é uma data válida: ${value}`);
104
+ },
105
+
106
+ /**
107
+ * Retorna um tipo Data se o tipo passado for data, caso for um string converte para data caso contrário retorna null.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * import { ObjectUtils } from './object.utils';
112
+ * const date = new Date("2024-01-01T00:00:00Z");
113
+ * console.log(ObjectUtils.toDateOrNull(date)); // 2024-01-01T00:00:00Z
114
+ * const strDate = "2024-01-01";
115
+ * console.log(ObjectUtils.toDateOrNull(strDate)); // 2024-01-01T00:00:00Z
116
+ * const invalidDate = "invalid date";
117
+ * console.log(ObjectUtils.toDateOrNull(invalidDate)); // null
118
+ * const nullDate = null;
119
+ * console.log(ObjectUtils.toDateOrNull(nullDate)); // null
120
+ * const undefinedDate = undefined;
121
+ * console.log(ObjectUtils.toDateOrNull(undefinedDate)); // null
122
+ * ```
123
+ * @param value Valor.
124
+ * @returns
125
+ */
126
+ toDateOrNull: (value: unknown): Date | null => {
127
+ if (value instanceof Date && !isNaN(value.getTime())) {
128
+ //return value;
129
+ return new Date(value.toISOString());
130
+ }
131
+
132
+ if (typeof value === 'string') {
133
+ // Regex para detectar data apenas (YYYY-MM-DD).
134
+ const dateOnlyRegex = /^\d{4}-\d{2}-\d{2}$/;
135
+
136
+ let utcValue: string;
137
+
138
+ if (dateOnlyRegex.test(value)) {
139
+ // Se for só data, adiciona hora e Z.
140
+ utcValue = `${value}T00:00:00Z`;
141
+ } else {
142
+ // Se já tiver offset ou Z, mantém.
143
+ const offsetOrZRegex = /(Z|[+-]\d{2}:\d{2})$/;
144
+ utcValue = offsetOrZRegex.exec(value) ? value : `${value}Z`;
145
+ }
146
+
147
+ const parsedDate = new Date(utcValue);
148
+
149
+ if (!isNaN(parsedDate.getTime())) {
150
+ return parsedDate;
151
+ }
152
+ }
153
+
154
+ return null;
155
+ }
156
+ };