@dative-gpi/foundation-shared-domain 0.0.100 → 0.0.102
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/index.ts +2 -1
- package/models/authTokens/authTokenInfos.ts +13 -13
- package/models/enums/applicationEnums.ts +0 -0
- package/models/enums/dateEnums.ts +43 -0
- package/models/enums/deviceEnums.ts +5 -5
- package/models/enums/index.ts +2 -2
- package/package.json +2 -2
- package/tools/datesTools.ts +70 -6
- package/models/enums/sharedEnums.ts +0 -10
package/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from "./models";
|
|
1
|
+
export * from "./models";
|
|
2
|
+
export * from "./tools";
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { utcToEpoch } from "../../tools";
|
|
2
2
|
|
|
3
3
|
export class AuthTokenInfos {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
id: string | null;
|
|
5
|
+
token: string;
|
|
6
|
+
dateMax: number | null;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
constructor(params: AuthTokenInfosDTO) {
|
|
9
|
+
this.id = params.id;
|
|
10
|
+
this.token = params.token;
|
|
11
|
+
this.dateMax = params.dateMax ?
|
|
12
|
+
utcToEpoch(params.dateMax) : null;
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export interface AuthTokenInfosDTO {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
id: string | null;
|
|
18
|
+
token: string;
|
|
19
|
+
dateMax: string | null;
|
|
20
20
|
}
|
|
File without changes
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export enum DateSetting {
|
|
2
|
+
None = 0,
|
|
3
|
+
PastHours = 1,
|
|
4
|
+
PastDays = 2,
|
|
5
|
+
PastWeeks = 3,
|
|
6
|
+
PastMonths = 4,
|
|
7
|
+
PastYears = 5,
|
|
8
|
+
CurrentHour = 6,
|
|
9
|
+
CurrentDay = 7,
|
|
10
|
+
CurrentWeek = 8,
|
|
11
|
+
CurrentMonth = 9,
|
|
12
|
+
CurrentYear = 10,
|
|
13
|
+
Expression = 11,
|
|
14
|
+
Pick = 12,
|
|
15
|
+
LastDay = 13,
|
|
16
|
+
LastWeek = 14,
|
|
17
|
+
LastMonth = 15,
|
|
18
|
+
LastYear = 16,
|
|
19
|
+
SinceLastDay = 17,
|
|
20
|
+
SinceLastWeek = 18,
|
|
21
|
+
SinceLastMonth = 19,
|
|
22
|
+
SinceLastYear = 20,
|
|
23
|
+
LastPeriod = 21,
|
|
24
|
+
MinutesBeforeAfter = 22,
|
|
25
|
+
HoursBeforeAfter = 23,
|
|
26
|
+
DaysBeforeAfter = 24,
|
|
27
|
+
WeeksBeforeAfter = 25,
|
|
28
|
+
MinutesBefore = 26,
|
|
29
|
+
HoursBefore = 27,
|
|
30
|
+
DaysBefore = 28,
|
|
31
|
+
WeeksBefore = 29
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export enum Days {
|
|
35
|
+
Monday = 0,
|
|
36
|
+
Tuesday = 1,
|
|
37
|
+
Wednesday = 2,
|
|
38
|
+
Thursday = 3,
|
|
39
|
+
Friday = 4,
|
|
40
|
+
Saturday = 5,
|
|
41
|
+
Sunday = 6,
|
|
42
|
+
AllDays = 7
|
|
43
|
+
}
|
package/models/enums/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dative-gpi/foundation-shared-domain",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.102",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"date-fns": "^3.6.0"
|
|
14
14
|
},
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "d2534b5fa79d557769bcdfd5da4b8dffa0f42c3e"
|
|
16
16
|
}
|
package/tools/datesTools.ts
CHANGED
|
@@ -1,15 +1,79 @@
|
|
|
1
1
|
import { parse } from "date-fns";
|
|
2
2
|
|
|
3
|
+
const BASE = ["now"];
|
|
4
|
+
const WIDGET = ["from", "to"];
|
|
5
|
+
const ALERT = ["alert", "alertstart", "alertend"];
|
|
6
|
+
|
|
3
7
|
const removeArtifacts = (date: string): string => {
|
|
4
|
-
|
|
8
|
+
return date.substring(0, 19) + "Z";
|
|
5
9
|
};
|
|
6
10
|
|
|
7
|
-
const
|
|
11
|
+
const fromExpression = (expression: string, variant: 'default' | 'before-after'): boolean => {
|
|
12
|
+
if (
|
|
13
|
+
/^\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}(:\d{2})?$/g.test(expression) ||
|
|
14
|
+
/^\d{4}-\d{2}-\d{2}[ |T]\d{2}:\d{2}(:\d{2})?$/g.test(expression)
|
|
15
|
+
) {
|
|
16
|
+
if (!isNaN(Date.parse(expression))) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
let variables = BASE.slice();
|
|
21
|
+
switch (variant) {
|
|
22
|
+
case "default": {
|
|
23
|
+
variables = variables.concat(WIDGET);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case "before-after": {
|
|
27
|
+
variables = variables.concat(ALERT);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
variables = variables.sort((a: string, b: string) => b.length - a.length);
|
|
32
|
+
for (let i = 0; i < variables.length; i++) {
|
|
33
|
+
if (expression.startsWith(variables[i])) {
|
|
34
|
+
expression = expression.substring(variables[i].length).replaceAll(" ", "");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
let match = /^(?:(?:([-+])(\d*))?(\w+))?(?:\/(\w))?/g.exec(expression);
|
|
38
|
+
while (match != null && !(match[0] == null || (match[0].match(/^ *$/) !== null))) {
|
|
39
|
+
let doSomething = false;
|
|
40
|
+
if (!(match[1] == null || (match[1].match(/^ *$/) !== null)) && !(match[3] == null || (match[3].match(/^ *$/) !== null))) {
|
|
41
|
+
if (!["-", "+"].includes(match[1])) {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
if (!variables.includes(match[3])) {
|
|
45
|
+
if (isNaN(parseInt(match[2])) || !["s", "m", "h", "d", "w", "M", "y"].includes(match[3])) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
doSomething = true;
|
|
50
|
+
}
|
|
51
|
+
if (!(match[4] == null || (match[4].match(/^ *$/) !== null))) {
|
|
52
|
+
if (!["s", "m", "h", "d", "w", "M", "y"].includes(match[4])) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
doSomething = true;
|
|
56
|
+
}
|
|
57
|
+
if (!doSomething) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
expression = expression.substring(match[0].length);
|
|
61
|
+
match = /(?:(?:([-+])(\d*))?(\w+))?(?:\/(\w))?/g.exec(expression);
|
|
62
|
+
}
|
|
63
|
+
if (expression.length) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const isoTimeFormat = (timeZone: boolean = false): string => {
|
|
8
70
|
return `yyyy-MM-dd'T'HH:mm:ss${timeZone ? "X" : ""}`;
|
|
9
71
|
};
|
|
10
72
|
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
73
|
+
export const utcToEpoch = (value: string): number => {
|
|
74
|
+
return parse(removeArtifacts(value), isoTimeFormat(true), new Date()).getTime();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const validateExpression = (expression: string, variant: "default" | "before-after"): boolean => {
|
|
78
|
+
return (fromExpression(expression!, variant));
|
|
15
79
|
};
|