@oneuptime/common 7.0.2976 → 7.0.2981

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 (123) hide show
  1. package/Models/AnalyticsModels/AnalyticsBaseModel/CommonModel.ts +8 -7
  2. package/Models/DatabaseModels/Monitor.ts +36 -0
  3. package/Server/API/BaseAnalyticsAPI.ts +2 -6
  4. package/Server/Infrastructure/Postgres/SchemaMigrations/1724078044172-MigrationName.ts +23 -0
  5. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +2 -0
  6. package/Server/Services/AnalyticsDatabaseService.ts +2 -2
  7. package/Server/Services/DatabaseService.ts +2 -2
  8. package/Server/Services/MonitorService.ts +9 -0
  9. package/Server/Services/ProjectService.ts +16 -2
  10. package/Server/Services/StatusPageHeaderLinkService.ts +1 -1
  11. package/Server/Types/AnalyticsDatabase/QueryHelper.ts +8 -7
  12. package/Server/Types/Database/Query.ts +6 -20
  13. package/Server/Types/Database/QueryHelper.ts +59 -42
  14. package/Server/Types/Database/QueryUtil.ts +8 -7
  15. package/Server/Utils/AnalyticsDatabase/StatementGenerator.ts +1 -1
  16. package/Tests/Types/Database/CompareBase.test.ts +6 -6
  17. package/Tests/Types/Database/Date.test.ts +1 -1
  18. package/Tests/Types/Database/EqualToOrNull.test.ts +14 -8
  19. package/Tests/Types/Database/InBetween.test.ts +8 -8
  20. package/Tests/Types/Database/NotEqual.test.ts +2 -2
  21. package/Types/BaseDatabase/AggregateBy.ts +1 -1
  22. package/Types/BaseDatabase/EqualToOrNull.ts +12 -16
  23. package/Types/BaseDatabase/GreaterThan.ts +8 -6
  24. package/Types/BaseDatabase/GreaterThanOrEqual.ts +10 -6
  25. package/Types/BaseDatabase/InBetween.ts +21 -23
  26. package/Types/BaseDatabase/Includes.ts +2 -2
  27. package/Types/BaseDatabase/IsNull.ts +3 -2
  28. package/Types/BaseDatabase/LessThan.ts +8 -6
  29. package/Types/BaseDatabase/LessThanOrEqual.ts +10 -6
  30. package/Types/BaseDatabase/NotEqual.ts +10 -17
  31. package/Types/BaseDatabase/NotNull.ts +3 -2
  32. package/Types/BaseDatabase/Query.ts +17 -6
  33. package/Types/BaseDatabase/QueryOperator.ts +11 -0
  34. package/Types/BaseDatabase/Search.ts +12 -10
  35. package/Types/Database/CompareBase.ts +10 -6
  36. package/Types/Database/Date.ts +1 -1
  37. package/Types/Date.ts +3 -1
  38. package/Types/Domain.ts +1 -1
  39. package/Types/JSON.ts +17 -16
  40. package/Types/JSONFunctions.ts +3 -2
  41. package/UI/Components/Date/StartAndEndDate.tsx +6 -8
  42. package/UI/Components/Filters/DateFilter.tsx +6 -3
  43. package/UI/Components/Filters/FilterViewer.tsx +3 -1
  44. package/UI/Components/Filters/JSONFilter.tsx +4 -1
  45. package/UI/Components/Filters/Types/FilterData.ts +1 -1
  46. package/UI/Components/HeaderAlert/HeaderModelAlert.tsx +1 -1
  47. package/UI/Components/ModelFilter/Filter.ts +1 -1
  48. package/UI/Components/ModelList/ModelList.tsx +1 -1
  49. package/UI/Components/ModelListModal/ModelListModal.tsx +1 -1
  50. package/UI/Components/ModelProgress/ModelProgress.tsx +1 -1
  51. package/UI/Components/ModelTable/AnalyticsModelTable.tsx +1 -1
  52. package/UI/Components/ModelTable/BaseModelTable.tsx +1 -1
  53. package/UI/Components/ModelTable/ModelTable.tsx +1 -1
  54. package/UI/Components/SideMenu/CountModelSideMenuItem.tsx +1 -1
  55. package/UI/Utils/AnalyticsModelAPI/AnalyticsModelAPI.ts +1 -1
  56. package/UI/Utils/ModelAPI/ModelAPI.ts +1 -1
  57. package/UI/Utils/Realtime.ts +1 -1
  58. package/Utils/CronTime.ts +1 -0
  59. package/build/dist/Models/AnalyticsModels/AnalyticsBaseModel/CommonModel.js.map +1 -1
  60. package/build/dist/Models/DatabaseModels/Monitor.js +36 -0
  61. package/build/dist/Models/DatabaseModels/Monitor.js.map +1 -1
  62. package/build/dist/Server/API/BaseAnalyticsAPI.js.map +1 -1
  63. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724078044172-MigrationName.js +14 -0
  64. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1724078044172-MigrationName.js.map +1 -0
  65. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +2 -0
  66. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  67. package/build/dist/Server/Services/AnalyticsDatabaseService.js +2 -2
  68. package/build/dist/Server/Services/AnalyticsDatabaseService.js.map +1 -1
  69. package/build/dist/Server/Services/DatabaseService.js.map +1 -1
  70. package/build/dist/Server/Services/MonitorService.js +7 -0
  71. package/build/dist/Server/Services/MonitorService.js.map +1 -1
  72. package/build/dist/Server/Services/ProjectService.js +15 -2
  73. package/build/dist/Server/Services/ProjectService.js.map +1 -1
  74. package/build/dist/Server/Services/StatusPageHeaderLinkService.js.map +1 -1
  75. package/build/dist/Server/Types/AnalyticsDatabase/QueryHelper.js.map +1 -1
  76. package/build/dist/Server/Types/Database/QueryHelper.js.map +1 -1
  77. package/build/dist/Server/Types/Database/QueryUtil.js.map +1 -1
  78. package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js +1 -1
  79. package/build/dist/Server/Utils/AnalyticsDatabase/StatementGenerator.js.map +1 -1
  80. package/build/dist/Tests/Types/Database/CompareBase.test.js.map +1 -1
  81. package/build/dist/Tests/Types/Database/EqualToOrNull.test.js.map +1 -1
  82. package/build/dist/Tests/Types/Database/InBetween.test.js.map +1 -1
  83. package/build/dist/Tests/Types/Database/NotEqual.test.js.map +1 -1
  84. package/build/dist/Types/BaseDatabase/EqualToOrNull.js +4 -10
  85. package/build/dist/Types/BaseDatabase/EqualToOrNull.js.map +1 -1
  86. package/build/dist/Types/BaseDatabase/GreaterThan.js.map +1 -1
  87. package/build/dist/Types/BaseDatabase/GreaterThanOrEqual.js.map +1 -1
  88. package/build/dist/Types/BaseDatabase/InBetween.js +2 -2
  89. package/build/dist/Types/BaseDatabase/InBetween.js.map +1 -1
  90. package/build/dist/Types/BaseDatabase/Includes.js +2 -2
  91. package/build/dist/Types/BaseDatabase/Includes.js.map +1 -1
  92. package/build/dist/Types/BaseDatabase/IsNull.js +2 -2
  93. package/build/dist/Types/BaseDatabase/IsNull.js.map +1 -1
  94. package/build/dist/Types/BaseDatabase/LessThan.js.map +1 -1
  95. package/build/dist/Types/BaseDatabase/LessThanOrEqual.js.map +1 -1
  96. package/build/dist/Types/BaseDatabase/NotEqual.js +4 -11
  97. package/build/dist/Types/BaseDatabase/NotEqual.js.map +1 -1
  98. package/build/dist/Types/BaseDatabase/NotNull.js +2 -2
  99. package/build/dist/Types/BaseDatabase/NotNull.js.map +1 -1
  100. package/build/dist/Types/BaseDatabase/QueryOperator.js +7 -0
  101. package/build/dist/Types/BaseDatabase/QueryOperator.js.map +1 -0
  102. package/build/dist/Types/BaseDatabase/Search.js +2 -2
  103. package/build/dist/Types/BaseDatabase/Search.js.map +1 -1
  104. package/build/dist/Types/Database/CompareBase.js +2 -2
  105. package/build/dist/Types/Database/CompareBase.js.map +1 -1
  106. package/build/dist/Types/Date.js.map +1 -1
  107. package/build/dist/Types/Domain.js +1 -1
  108. package/build/dist/Types/Domain.js.map +1 -1
  109. package/build/dist/Types/JSON.js.map +1 -1
  110. package/build/dist/Types/JSONFunctions.js.map +1 -1
  111. package/build/dist/UI/Components/Date/StartAndEndDate.js.map +1 -1
  112. package/build/dist/UI/Components/Filters/DateFilter.js.map +1 -1
  113. package/build/dist/UI/Components/Filters/FilterViewer.js.map +1 -1
  114. package/build/dist/UI/Components/Filters/JSONFilter.js.map +1 -1
  115. package/build/dist/UI/Utils/AnalyticsModelAPI/AnalyticsModelAPI.js.map +1 -1
  116. package/build/dist/UI/Utils/ModelAPI/ModelAPI.js.map +1 -1
  117. package/build/dist/UI/Utils/Realtime.js.map +1 -1
  118. package/build/dist/Utils/CronTime.js +1 -0
  119. package/build/dist/Utils/CronTime.js.map +1 -1
  120. package/package.json +2 -2
  121. package/UI/Utils/BaseDatabase/Query.ts +0 -25
  122. package/build/dist/UI/Utils/BaseDatabase/Query.js +0 -2
  123. package/build/dist/UI/Utils/BaseDatabase/Query.js.map +0 -1
@@ -1,23 +1,23 @@
1
- import CompareBase from "../../../Types/Database/CompareBase";
1
+ import CompareBase, { CompareType } from "../../../Types/Database/CompareBase";
2
2
  import BadDataException from "../../../Types/Exception/BadDataException";
3
3
  import { describe, expect, it } from "@jest/globals";
4
4
 
5
5
  describe("CompareBase", () => {
6
6
  describe("toString", () => {
7
7
  it("should return string representation of value", () => {
8
- const compareBase: CompareBase = new CompareBase(10);
8
+ const compareBase: CompareBase<CompareType> = new CompareBase(10);
9
9
  expect(compareBase.toString()).toBe("10");
10
10
  });
11
11
  });
12
12
 
13
13
  describe("toNumber", () => {
14
14
  it("should return value as number if it is a number", () => {
15
- const compareBase: CompareBase = new CompareBase(10);
15
+ const compareBase: CompareBase<CompareType> = new CompareBase(10);
16
16
  expect(compareBase.toNumber()).toBe(10);
17
17
  });
18
18
 
19
19
  it("should throw BadDataException if value is not a number", () => {
20
- const compareBase: CompareBase = new CompareBase(new Date());
20
+ const compareBase: CompareBase<CompareType> = new CompareBase(new Date());
21
21
  expect(() => {
22
22
  return compareBase.toNumber();
23
23
  }).toThrow(BadDataException);
@@ -27,12 +27,12 @@ describe("CompareBase", () => {
27
27
  describe("toDate", () => {
28
28
  it("should return value as date object if it is a date object", () => {
29
29
  const date: Date = new Date();
30
- const compareBase: CompareBase = new CompareBase(date);
30
+ const compareBase: CompareBase<CompareType> = new CompareBase(date);
31
31
  expect(compareBase.toDate()).toBe(date);
32
32
  });
33
33
 
34
34
  it("should throw BadDataException if value is not a date object", () => {
35
- const compareBase: CompareBase = new CompareBase(10);
35
+ const compareBase: CompareBase<CompareType> = new CompareBase(10);
36
36
  expect(() => {
37
37
  return compareBase.toDate();
38
38
  }).toThrow(BadDataException);
@@ -73,7 +73,7 @@ describe("DatabaseDate", () => {
73
73
 
74
74
  it("should be a type of InBetween", () => {
75
75
  const inputDate: string = "2023-10-24T12:00:00Z";
76
- const result: InBetween =
76
+ const result: InBetween<string> =
77
77
  DatabaseDate.asDateStartOfTheDayEndOfTheDayForDatabaseQuery(inputDate);
78
78
  expect(result).toBeInstanceOf(InBetween);
79
79
  });
@@ -6,29 +6,35 @@ import { describe, expect, it } from "@jest/globals";
6
6
  describe("EqualToOrNull", () => {
7
7
  it("should create an EqualToOrNull object with a valid value", () => {
8
8
  const value: string = "oneuptime";
9
- const equalObj: EqualToOrNull = new EqualToOrNull(value);
9
+ const equalObj: EqualToOrNull<string> = new EqualToOrNull<string>(value);
10
10
  expect(equalObj.value).toBe(value);
11
11
  });
12
12
 
13
13
  it("should get the value property of an EqualToOrNull object", () => {
14
14
  const value: string = "oneuptime";
15
- const equalObj: EqualToOrNull = new EqualToOrNull(value);
15
+ const equalObj: EqualToOrNull<string> = new EqualToOrNull<string>(value);
16
16
  expect(equalObj.value).toBe(value);
17
17
  });
18
18
 
19
19
  it("should set the value property of an EqualToOrNull object", () => {
20
- const equalObj: EqualToOrNull = new EqualToOrNull("oldValue");
20
+ const equalObj: EqualToOrNull<string> = new EqualToOrNull<string>(
21
+ "oldValue",
22
+ );
21
23
  equalObj.value = "newValue";
22
24
  expect(equalObj.value).toBe("newValue");
23
25
  });
24
26
 
25
27
  it("should return the correct string representation using toString method", () => {
26
- const equalObj: EqualToOrNull = new EqualToOrNull("oneuptime");
28
+ const equalObj: EqualToOrNull<string> = new EqualToOrNull<string>(
29
+ "oneuptime",
30
+ );
27
31
  expect(equalObj.toString()).toBe("oneuptime");
28
32
  });
29
33
 
30
34
  it("should generate the correct JSON representation using toJSON method", () => {
31
- const equalObj: EqualToOrNull = new EqualToOrNull("oneuptime");
35
+ const equalObj: EqualToOrNull<string> = new EqualToOrNull<string>(
36
+ "oneuptime",
37
+ );
32
38
  const expectedJSON: JSONObject = {
33
39
  _type: "EqualToOrNull",
34
40
  value: "oneuptime",
@@ -41,7 +47,7 @@ describe("EqualToOrNull", () => {
41
47
  _type: "EqualToOrNull",
42
48
  value: "oneuptime",
43
49
  };
44
- const equalObj: EqualToOrNull = EqualToOrNull.fromJSON(jsonInput);
50
+ const equalObj: EqualToOrNull<string> = EqualToOrNull.fromJSON(jsonInput);
45
51
  expect(equalObj.value).toBe("oneuptime");
46
52
  });
47
53
 
@@ -56,7 +62,7 @@ describe("EqualToOrNull", () => {
56
62
  });
57
63
 
58
64
  it("should be a type of EqualToOrNull", () => {
59
- const equalObj: EqualToOrNull = new EqualToOrNull("oneuptime");
65
+ const equalObj: EqualToOrNull<string> = new EqualToOrNull("oneuptime");
60
66
  expect(equalObj).toBeInstanceOf(EqualToOrNull);
61
67
  });
62
68
 
@@ -65,7 +71,7 @@ describe("EqualToOrNull", () => {
65
71
  _type: "EqualToOrNull",
66
72
  value: null,
67
73
  };
68
- const equalObj: EqualToOrNull = EqualToOrNull.fromJSON(jsonInput);
74
+ const equalObj: EqualToOrNull<string> = EqualToOrNull.fromJSON(jsonInput);
69
75
  expect(equalObj.value).toBeNull();
70
76
  });
71
77
  });
@@ -7,7 +7,7 @@ describe("InBetween", () => {
7
7
  it("should create an InBetween object with valid start and end values", () => {
8
8
  const startValue: number = 10;
9
9
  const endValue: number = 20;
10
- const betweenObj: InBetween = new InBetween(startValue, endValue);
10
+ const betweenObj: InBetween<number> = new InBetween(startValue, endValue);
11
11
  expect(betweenObj.startValue).toBe(10);
12
12
  expect(betweenObj.endValue).toBe(20);
13
13
  });
@@ -15,7 +15,7 @@ describe("InBetween", () => {
15
15
  it("should generate the correct JSON representation using toJSON method", () => {
16
16
  const startValue: number = 10;
17
17
  const endValue: number = 20;
18
- const betweenObj: InBetween = new InBetween(startValue, endValue);
18
+ const betweenObj: InBetween<number> = new InBetween(startValue, endValue);
19
19
  const expectedJSON: JSONObject = {
20
20
  _type: "InBetween",
21
21
  startValue: 10,
@@ -30,7 +30,7 @@ describe("InBetween", () => {
30
30
  startValue: 10,
31
31
  endValue: 20,
32
32
  };
33
- const betweenObj: InBetween = InBetween.fromJSON(jsonInput);
33
+ const betweenObj: InBetween<number> = InBetween.fromJSON(jsonInput);
34
34
  expect(betweenObj.startValue).toBe(10);
35
35
  expect(betweenObj.endValue).toBe(20);
36
36
  });
@@ -49,33 +49,33 @@ describe("InBetween", () => {
49
49
  it("should return a string with start and end values matching", () => {
50
50
  const startValue: number = 15;
51
51
  const endValue: number = 15;
52
- const betweenObj: InBetween = new InBetween(startValue, endValue);
52
+ const betweenObj: InBetween<number> = new InBetween(startValue, endValue);
53
53
  expect(betweenObj.toString()).toBe("15");
54
54
  });
55
55
 
56
56
  it("should return a string with start and end values different", () => {
57
57
  const startValue: number = 10;
58
58
  const endValue: number = 20;
59
- const betweenObj: InBetween = new InBetween(startValue, endValue);
59
+ const betweenObj: InBetween<number> = new InBetween(startValue, endValue);
60
60
  expect(betweenObj.toString()).toBe("10 - 20");
61
61
  });
62
62
 
63
63
  it("should return the start value as a string", () => {
64
64
  const startValue: number = 10;
65
65
  const endValue: number = 20;
66
- const betweenObj: InBetween = new InBetween(startValue, endValue);
66
+ const betweenObj: InBetween<number> = new InBetween(startValue, endValue);
67
67
  expect(betweenObj.toStartValueString()).toBe("10");
68
68
  });
69
69
 
70
70
  it("should return the end value as a string", () => {
71
71
  const startValue: number = 10;
72
72
  const endValue: number = 20;
73
- const betweenObj: InBetween = new InBetween(startValue, endValue);
73
+ const betweenObj: InBetween<number> = new InBetween(startValue, endValue);
74
74
  expect(betweenObj.toEndValueString()).toBe("20");
75
75
  });
76
76
 
77
77
  it("should be a type of InBetween", () => {
78
- const inBetweenObj: InBetween = new InBetween(10, 15);
78
+ const inBetweenObj: InBetween<number> = new InBetween(10, 15);
79
79
  expect(inBetweenObj).toBeInstanceOf(InBetween);
80
80
  });
81
81
  });
@@ -5,14 +5,14 @@ describe("NotEqual", () => {
5
5
  describe("constructor", () => {
6
6
  it("should set the value property", () => {
7
7
  const value: string = "test";
8
- const notEqual: NotEqual = new NotEqual(value);
8
+ const notEqual: NotEqual<string> = new NotEqual(value);
9
9
  expect(notEqual.value).toBe(value);
10
10
  });
11
11
  });
12
12
  describe("toString", () => {
13
13
  it("should return the string value", () => {
14
14
  const value: string = "test";
15
- const notEqual: NotEqual = new NotEqual(value);
15
+ const notEqual: NotEqual<string> = new NotEqual(value);
16
16
  expect(notEqual.toString()).toBe(value);
17
17
  });
18
18
  });
@@ -5,7 +5,7 @@ import Sort from "./Sort";
5
5
 
6
6
  export default interface AggregateBy<TBaseModel extends GenericObject> {
7
7
  aggregateColumnName: keyof TBaseModel;
8
- aggregateBy: AggregationType;
8
+ aggregationType: AggregationType;
9
9
  // aggregationInterval?: AggregationInterval;
10
10
  aggregationTimestampColumnName: keyof TBaseModel;
11
11
  startTimestamp: Date;
@@ -1,35 +1,31 @@
1
+ import CompareBase, { CompareType } from "../Database/CompareBase";
1
2
  import BadDataException from "../Exception/BadDataException";
2
3
  import { JSONObject, ObjectType } from "../JSON";
3
- import SerializableObject from "../SerializableObject";
4
4
 
5
- export default class EqualToOrNull extends SerializableObject {
6
- private _value!: string;
7
- public get value(): string {
8
- return this._value;
9
- }
10
- public set value(v: string) {
11
- this._value = v;
12
- }
13
-
14
- public constructor(value: string) {
15
- super();
5
+ export default class EqualToOrNull<
6
+ T extends CompareType,
7
+ > extends CompareBase<T> {
8
+ public constructor(value: T) {
9
+ super(value);
16
10
  this.value = value;
17
11
  }
18
12
 
19
13
  public override toString(): string {
20
- return this.value;
14
+ return this.value.toString();
21
15
  }
22
16
 
23
17
  public override toJSON(): JSONObject {
24
18
  return {
25
19
  _type: ObjectType.EqualToOrNull,
26
- value: (this as EqualToOrNull).toString(),
20
+ value: (this as EqualToOrNull<T>).toString(),
27
21
  };
28
22
  }
29
23
 
30
- public static override fromJSON(json: JSONObject): EqualToOrNull {
24
+ public static override fromJSON<T extends CompareType>(
25
+ json: JSONObject,
26
+ ): EqualToOrNull<T> {
31
27
  if (json["_type"] === ObjectType.EqualToOrNull) {
32
- return new EqualToOrNull(json["value"] as string);
28
+ return new EqualToOrNull(json["value"] as T);
33
29
  }
34
30
 
35
31
  throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
@@ -1,22 +1,24 @@
1
- import CompareBase from "../Database/CompareBase";
1
+ import CompareBase, { CompareType } from "../Database/CompareBase";
2
2
  import BadDataException from "../Exception/BadDataException";
3
3
  import { JSONObject, ObjectType } from "../JSON";
4
4
 
5
- export default class GreaterThan extends CompareBase {
6
- public constructor(value: number | Date) {
5
+ export default class GreaterThan<T extends CompareType> extends CompareBase<T> {
6
+ public constructor(value: T) {
7
7
  super(value);
8
8
  }
9
9
 
10
10
  public override toJSON(): JSONObject {
11
11
  return {
12
12
  _type: ObjectType.GreaterThan,
13
- value: (this as GreaterThan).toString(),
13
+ value: (this as GreaterThan<T>).toString(),
14
14
  };
15
15
  }
16
16
 
17
- public static override fromJSON(json: JSONObject): GreaterThan {
17
+ public static override fromJSON<T extends CompareType>(
18
+ json: JSONObject,
19
+ ): GreaterThan<T> {
18
20
  if (json["_type"] === ObjectType.GreaterThan) {
19
- return new GreaterThan(json["value"] as number | Date);
21
+ return new GreaterThan(json["value"] as T);
20
22
  }
21
23
 
22
24
  throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
@@ -1,22 +1,26 @@
1
- import CompareBase from "../Database/CompareBase";
1
+ import CompareBase, { CompareType } from "../Database/CompareBase";
2
2
  import BadDataException from "../Exception/BadDataException";
3
3
  import { JSONObject, ObjectType } from "../JSON";
4
4
 
5
- export default class GreaterThanOrEqual extends CompareBase {
6
- public constructor(value: number | Date) {
5
+ export default class GreaterThanOrEqual<
6
+ T extends CompareType,
7
+ > extends CompareBase<T> {
8
+ public constructor(value: T) {
7
9
  super(value);
8
10
  }
9
11
 
10
12
  public override toJSON(): JSONObject {
11
13
  return {
12
14
  _type: ObjectType.GreaterThanOrEqual,
13
- value: (this as GreaterThanOrEqual).toString(),
15
+ value: (this as GreaterThanOrEqual<T>).toString(),
14
16
  };
15
17
  }
16
18
 
17
- public static override fromJSON(json: JSONObject): GreaterThanOrEqual {
19
+ public static override fromJSON<T extends CompareType>(
20
+ json: JSONObject,
21
+ ): GreaterThanOrEqual<T> {
18
22
  if (json["_type"] === ObjectType.GreaterThanOrEqual) {
19
- return new GreaterThanOrEqual(json["value"] as number | Date);
23
+ return new GreaterThanOrEqual<T>(json["value"] as T);
20
24
  }
21
25
 
22
26
  throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
@@ -1,29 +1,28 @@
1
1
  import OneUptimeDate from "../Date";
2
2
  import BadDataException from "../Exception/BadDataException";
3
3
  import { JSONObject, ObjectType } from "../JSON";
4
- import SerializableObject from "../SerializableObject";
4
+ import QueryOperator from "./QueryOperator";
5
5
 
6
- export default class InBetween extends SerializableObject {
7
- private _startValue!: number | Date | string;
8
- public get startValue(): number | Date | string {
6
+ export default class InBetween<
7
+ T extends number | Date | string,
8
+ > extends QueryOperator<T> {
9
+ private _startValue!: T;
10
+ public get startValue(): T {
9
11
  return this._startValue;
10
12
  }
11
- public set startValue(v: number | Date | string) {
13
+ public set startValue(v: T) {
12
14
  this._startValue = v;
13
15
  }
14
16
 
15
- private _endValue!: number | Date | string;
16
- public get endValue(): number | Date | string {
17
+ private _endValue!: T;
18
+ public get endValue(): T {
17
19
  return this._endValue;
18
20
  }
19
- public set endValue(v: number | Date | string) {
21
+ public set endValue(v: T) {
20
22
  this._endValue = v;
21
23
  }
22
24
 
23
- public constructor(
24
- startValue: number | Date | string,
25
- endValue: number | Date | string,
26
- ) {
25
+ public constructor(startValue: T, endValue: T) {
27
26
  super();
28
27
  this.startValue = startValue;
29
28
  this.endValue = endValue;
@@ -32,32 +31,31 @@ export default class InBetween extends SerializableObject {
32
31
  public override toJSON(): JSONObject {
33
32
  return {
34
33
  _type: ObjectType.InBetween,
35
- startValue: (this as InBetween).startValue,
36
- endValue: (this as InBetween).endValue,
34
+ startValue: (this as InBetween<T>).startValue,
35
+ endValue: (this as InBetween<T>).endValue,
37
36
  };
38
37
  }
39
38
 
40
- public static override fromJSON(json: JSONObject): InBetween {
39
+ public static override fromJSON<T extends number | Date | string>(
40
+ json: JSONObject,
41
+ ): InBetween<T> {
41
42
  if (json["_type"] === ObjectType.InBetween) {
42
- return new InBetween(
43
- json["startValue"] as number | Date | string,
44
- json["endValue"] as number | Date | string,
45
- );
43
+ return new InBetween(json["startValue"] as T, json["endValue"] as T);
46
44
  }
47
45
 
48
46
  throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
49
47
  }
50
48
 
51
49
  public override toString(): string {
52
- let startValue: number | Date | string = this.startValue;
53
- let endValue: number | Date | string = this.endValue;
50
+ let startValue: T = this.startValue;
51
+ let endValue: T = this.endValue;
54
52
 
55
53
  if (startValue instanceof Date) {
56
- startValue = OneUptimeDate.asDateForDatabaseQuery(startValue);
54
+ startValue = OneUptimeDate.asDateForDatabaseQuery(startValue) as T;
57
55
  }
58
56
 
59
57
  if (endValue instanceof Date) {
60
- endValue = OneUptimeDate.asDateForDatabaseQuery(endValue);
58
+ endValue = OneUptimeDate.asDateForDatabaseQuery(endValue) as T;
61
59
  }
62
60
 
63
61
  if (startValue.toString() === endValue.toString()) {
@@ -2,11 +2,11 @@ import BadDataException from "../Exception/BadDataException";
2
2
  import { JSONObject, ObjectType } from "../JSON";
3
3
  import JSONFunctions from "../JSONFunctions";
4
4
  import ObjectID from "../ObjectID";
5
- import SerializableObject from "../SerializableObject";
5
+ import QueryOperator from "./QueryOperator";
6
6
 
7
7
  export type IncludesType = Array<string> | Array<ObjectID> | Array<number>;
8
8
 
9
- export default class Includes extends SerializableObject {
9
+ export default class Includes extends QueryOperator<IncludesType> {
10
10
  private _values: IncludesType = [];
11
11
 
12
12
  public get values(): IncludesType {
@@ -1,8 +1,9 @@
1
1
  import BadDataException from "../Exception/BadDataException";
2
+ import GenericObject from "../GenericObject";
2
3
  import { JSONObject, ObjectType } from "../JSON";
3
- import SerializableObject from "../SerializableObject";
4
+ import QueryOperator from "./QueryOperator";
4
5
 
5
- export default class IsNull extends SerializableObject {
6
+ export default class IsNull extends QueryOperator<GenericObject> {
6
7
  public constructor() {
7
8
  super();
8
9
  }
@@ -1,22 +1,24 @@
1
- import CompareBase from "../Database/CompareBase";
1
+ import CompareBase, { CompareType } from "../Database/CompareBase";
2
2
  import BadDataException from "../Exception/BadDataException";
3
3
  import { JSONObject, ObjectType } from "../JSON";
4
4
 
5
- export default class LessThan extends CompareBase {
6
- public constructor(value: number | Date) {
5
+ export default class LessThan<T extends CompareType> extends CompareBase<T> {
6
+ public constructor(value: T) {
7
7
  super(value);
8
8
  }
9
9
 
10
10
  public override toJSON(): JSONObject {
11
11
  return {
12
12
  _type: ObjectType.LessThan,
13
- value: (this as LessThan).toString(),
13
+ value: (this as LessThan<T>).toString(),
14
14
  };
15
15
  }
16
16
 
17
- public static override fromJSON(json: JSONObject): LessThan {
17
+ public static override fromJSON<T extends CompareType>(
18
+ json: JSONObject,
19
+ ): LessThan<T> {
18
20
  if (json["_type"] === ObjectType.LessThan) {
19
- return new LessThan(json["value"] as number | Date);
21
+ return new LessThan(json["value"] as T);
20
22
  }
21
23
 
22
24
  throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
@@ -1,22 +1,26 @@
1
- import CompareBase from "../Database/CompareBase";
1
+ import CompareBase, { CompareType } from "../Database/CompareBase";
2
2
  import BadDataException from "../Exception/BadDataException";
3
3
  import { JSONObject, ObjectType } from "../JSON";
4
4
 
5
- export default class LessThanOrEqual extends CompareBase {
6
- public constructor(value: number | Date) {
5
+ export default class LessThanOrEqual<
6
+ T extends CompareType,
7
+ > extends CompareBase<T> {
8
+ public constructor(value: T) {
7
9
  super(value);
8
10
  }
9
11
 
10
12
  public override toJSON(): JSONObject {
11
13
  return {
12
14
  _type: ObjectType.LessThanOrEqual,
13
- value: (this as LessThanOrEqual).toString(),
15
+ value: (this as LessThanOrEqual<T>).toString(),
14
16
  };
15
17
  }
16
18
 
17
- public static override fromJSON(json: JSONObject): LessThanOrEqual {
19
+ public static override fromJSON<T extends CompareType>(
20
+ json: JSONObject,
21
+ ): LessThanOrEqual<T> {
18
22
  if (json["_type"] === ObjectType.LessThanOrEqual) {
19
- return new LessThanOrEqual(json["value"] as number | Date);
23
+ return new LessThanOrEqual<T>(json["value"] as T);
20
24
  }
21
25
 
22
26
  throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
@@ -1,35 +1,28 @@
1
+ import CompareBase, { CompareType } from "../Database/CompareBase";
1
2
  import BadDataException from "../Exception/BadDataException";
2
3
  import { JSONObject, ObjectType } from "../JSON";
3
- import SerializableObject from "../SerializableObject";
4
4
 
5
- export default class NotEqual extends SerializableObject {
6
- private _value!: string;
7
- public get value(): string {
8
- return this._value;
9
- }
10
- public set value(v: string) {
11
- this._value = v;
12
- }
13
-
14
- public constructor(value: string) {
15
- super();
16
- this.value = value;
5
+ export default class NotEqual<T extends CompareType> extends CompareBase<T> {
6
+ public constructor(value: T) {
7
+ super(value);
17
8
  }
18
9
 
19
10
  public override toString(): string {
20
- return this.value;
11
+ return this.value.toString();
21
12
  }
22
13
 
23
14
  public override toJSON(): JSONObject {
24
15
  return {
25
16
  _type: ObjectType.NotEqual,
26
- value: (this as NotEqual).toString(),
17
+ value: (this as NotEqual<T>).toString(),
27
18
  };
28
19
  }
29
20
 
30
- public static override fromJSON(json: JSONObject): NotEqual {
21
+ public static override fromJSON<T extends CompareType>(
22
+ json: JSONObject,
23
+ ): NotEqual<T> {
31
24
  if (json["_type"] === ObjectType.NotEqual) {
32
- return new NotEqual(json["value"] as string);
25
+ return new NotEqual(json["value"] as T);
33
26
  }
34
27
 
35
28
  throw new BadDataException("Invalid JSON: " + JSON.stringify(json));
@@ -1,8 +1,9 @@
1
1
  import BadDataException from "../Exception/BadDataException";
2
+ import GenericObject from "../GenericObject";
2
3
  import { JSONObject, ObjectType } from "../JSON";
3
- import SerializableObject from "../SerializableObject";
4
+ import QueryOperator from "./QueryOperator";
4
5
 
5
- export default class NotNull extends SerializableObject {
6
+ export default class NotNull extends QueryOperator<GenericObject> {
6
7
  public constructor() {
7
8
  super();
8
9
  }
@@ -1,12 +1,23 @@
1
1
  import GenericObject from "../GenericObject";
2
- import { JSONObject, JSONValue } from "../JSON";
2
+ import QueryOperator from "./QueryOperator";
3
3
 
4
- export type QueryPropertyOptions = JSONValue | JSONObject;
5
-
6
- export declare type QueryOptions<Entity> = {
7
- [P in keyof Entity]?: QueryPropertyOptions;
4
+ export declare type FindWhereProperty<Property extends GenericObject> =
5
+ | Property
6
+ | FindWhere<Property>
7
+ | QueryOperator<Property>
8
+ | undefined;
9
+ /**
10
+ * :
11
+ * Used for find operations.
12
+ */
13
+ export declare type FindWhere<Entity> = {
14
+ [P in keyof Entity]?: FindWhereProperty<NonNullable<Entity[P]>>;
8
15
  };
9
16
 
10
- type Query<TBaseModel extends GenericObject> = QueryOptions<TBaseModel>;
17
+ declare type Query<TBaseModel extends GenericObject> = FindWhere<TBaseModel>;
18
+
19
+ export declare type OrQuery<TBaseModel extends GenericObject> = Array<
20
+ Query<TBaseModel>
21
+ >;
11
22
 
12
23
  export default Query;
@@ -0,0 +1,11 @@
1
+ import GenericObject from "../GenericObject";
2
+ import { JSONObject } from "../JSON";
3
+ import SerializableObject from "../SerializableObject";
4
+
5
+ export default class QueryOperator<
6
+ T extends GenericObject,
7
+ > extends SerializableObject {
8
+ public override fromJSON(json: JSONObject): QueryOperator<T> {
9
+ return SerializableObject.fromJSON(json) as QueryOperator<T>;
10
+ }
11
+ }
@@ -1,37 +1,39 @@
1
1
  import BadDataException from "../Exception/BadDataException";
2
2
  import { JSONObject, ObjectType } from "../JSON";
3
- import SerializableObject from "../SerializableObject";
3
+ import QueryOperator from "./QueryOperator";
4
4
 
5
- export default class Search extends SerializableObject {
6
- private _searchValue!: string;
5
+ export default class Search<T extends string> extends QueryOperator<T> {
6
+ private _searchValue!: T;
7
7
 
8
- public get value(): string {
8
+ public get value(): T {
9
9
  return this._searchValue;
10
10
  }
11
11
 
12
- public set value(v: string) {
12
+ public set value(v: T) {
13
13
  this._searchValue = v;
14
14
  }
15
15
 
16
- public constructor(value: string) {
16
+ public constructor(value: T) {
17
17
  super();
18
18
  this.value = value;
19
19
  }
20
20
 
21
- public override toString(): string {
21
+ public override toString(): T {
22
22
  return this.value;
23
23
  }
24
24
 
25
25
  public override toJSON(): JSONObject {
26
26
  return {
27
27
  _type: ObjectType.Search,
28
- value: (this as Search).toString(),
28
+ value: (this as Search<T>).toString(),
29
29
  };
30
30
  }
31
31
 
32
- public static override fromJSON(json: JSONObject): Search {
32
+ public static override fromJSON<T extends string>(
33
+ json: JSONObject,
34
+ ): Search<T> {
33
35
  if (json["_type"] === ObjectType.Search) {
34
- return new Search((json["value"] as string) || "");
36
+ return new Search<T>((json["value"] as T) || ("" as T));
35
37
  }
36
38
 
37
39
  throw new BadDataException("Invalid JSON: " + JSON.stringify(json));