@dative-gpi/foundation-shared-domain 0.0.101 → 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 CHANGED
@@ -1 +1,2 @@
1
- export * from "./models";
1
+ export * from "./models";
2
+ export * from "./tools";
@@ -1,20 +1,20 @@
1
- import { DatesTools } from "../../tools";
1
+ import { utcToEpoch } from "../../tools";
2
2
 
3
3
  export class AuthTokenInfos {
4
- id: string | null;
5
- token: string;
6
- dateMax: number | null;
4
+ id: string | null;
5
+ token: string;
6
+ dateMax: number | null;
7
7
 
8
- constructor(params: AuthTokenInfosDTO) {
9
- this.id = params.id;
10
- this.token = params.token;
11
- this.dateMax = params.dateMax ?
12
- DatesTools.utcToEpoch(params.dateMax) : null;
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
- id: string | null;
18
- token: string;
19
- dateMax: string | null;
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
+ }
@@ -1,7 +1,7 @@
1
1
  export enum ConnectivityStatus {
2
- None = 0,
3
- Connected = 1,
4
- PartiallyConnected = 2,
5
- AlmostOffline = 3,
6
- Offline = 4
2
+ None = 0,
3
+ Connected = 1,
4
+ PartiallyConnected = 2,
5
+ AlmostOffline = 3,
6
+ Offline = 4
7
7
  }
@@ -1,4 +1,4 @@
1
1
  export * from "./alertEnums";
2
2
  export * from "./dashboardEnums";
3
- export * from "./deviceEnums";
4
- export * from "./sharedEnums";
3
+ export * from "./dateEnums";
4
+ export * from "./deviceEnums";
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.101",
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": "8ab763942b592e5d46dc629ca95e80cfb7729400"
15
+ "gitHead": "d2534b5fa79d557769bcdfd5da4b8dffa0f42c3e"
16
16
  }
@@ -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
- return date.substring(0, 19) + "Z";
8
+ return date.substring(0, 19) + "Z";
5
9
  };
6
10
 
7
- const isoTimeFormat = (timeZone: boolean = false): string => {
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 DatesTools = {
12
- utcToEpoch: (value: string): number => {
13
- return parse(removeArtifacts(value), isoTimeFormat(true), new Date()).getTime();
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
  };
@@ -1,10 +0,0 @@
1
- export enum Days {
2
- Monday = 0,
3
- Tuesday = 1,
4
- Wednesday = 2,
5
- Thursday = 3,
6
- Friday = 4,
7
- Saturday = 5,
8
- Sunday = 6,
9
- AllDays = 7
10
- }