@aneuhold/core-ts-db-lib 3.0.2 → 4.0.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 (116) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/lib/browser.d.ts +19 -16
  3. package/lib/browser.d.ts.map +1 -1
  4. package/lib/browser.js +10 -12
  5. package/lib/browser.js.map +1 -1
  6. package/lib/browser.ts +46 -36
  7. package/lib/documents/BaseDocument.d.ts +22 -9
  8. package/lib/documents/BaseDocument.d.ts.map +1 -1
  9. package/lib/documents/BaseDocument.js +16 -7
  10. package/lib/documents/BaseDocument.js.map +1 -1
  11. package/lib/documents/BaseDocument.ts +27 -7
  12. package/lib/documents/common/ApiKey.d.ts +8 -25
  13. package/lib/documents/common/ApiKey.d.ts.map +1 -1
  14. package/lib/documents/common/ApiKey.js +7 -36
  15. package/lib/documents/common/ApiKey.js.map +1 -1
  16. package/lib/documents/common/ApiKey.ts +11 -41
  17. package/lib/documents/common/User.d.ts +25 -31
  18. package/lib/documents/common/User.d.ts.map +1 -1
  19. package/lib/documents/common/User.js +22 -39
  20. package/lib/documents/common/User.js.map +1 -1
  21. package/lib/documents/common/User.ts +29 -53
  22. package/lib/documents/dashboard/NonogramKatanaItem.d.ts +18 -27
  23. package/lib/documents/dashboard/NonogramKatanaItem.d.ts.map +1 -1
  24. package/lib/documents/dashboard/NonogramKatanaItem.js +17 -31
  25. package/lib/documents/dashboard/NonogramKatanaItem.js.map +1 -1
  26. package/lib/documents/dashboard/NonogramKatanaItem.ts +21 -45
  27. package/lib/documents/dashboard/NonogramKatanaUpgrade.d.ts +16 -41
  28. package/lib/documents/dashboard/NonogramKatanaUpgrade.d.ts.map +1 -1
  29. package/lib/documents/dashboard/NonogramKatanaUpgrade.js +17 -43
  30. package/lib/documents/dashboard/NonogramKatanaUpgrade.js.map +1 -1
  31. package/lib/documents/dashboard/NonogramKatanaUpgrade.ts +21 -55
  32. package/lib/documents/dashboard/Task.d.ts +73 -97
  33. package/lib/documents/dashboard/Task.d.ts.map +1 -1
  34. package/lib/documents/dashboard/Task.js +38 -80
  35. package/lib/documents/dashboard/Task.js.map +1 -1
  36. package/lib/documents/dashboard/Task.ts +71 -111
  37. package/lib/documents/dashboard/UserConfig.d.ts +49 -69
  38. package/lib/documents/dashboard/UserConfig.d.ts.map +1 -1
  39. package/lib/documents/dashboard/UserConfig.js +31 -51
  40. package/lib/documents/dashboard/UserConfig.js.map +1 -1
  41. package/lib/documents/dashboard/UserConfig.ts +41 -87
  42. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.d.ts +5 -0
  43. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.d.ts.map +1 -1
  44. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.js +5 -0
  45. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.js.map +1 -1
  46. package/lib/embedded-types/dashboard/nonogramKatanaItem/ItemName.ts +7 -0
  47. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.d.ts +5 -0
  48. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.d.ts.map +1 -1
  49. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.js +5 -0
  50. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.js.map +1 -1
  51. package/lib/embedded-types/dashboard/nonogramKatanaUpgrade/UpgradeName.ts +7 -0
  52. package/lib/embedded-types/dashboard/task/FilterSettings.d.ts +69 -41
  53. package/lib/embedded-types/dashboard/task/FilterSettings.d.ts.map +1 -1
  54. package/lib/embedded-types/dashboard/task/FilterSettings.js +29 -36
  55. package/lib/embedded-types/dashboard/task/FilterSettings.js.map +1 -1
  56. package/lib/embedded-types/dashboard/task/FilterSettings.ts +51 -74
  57. package/lib/embedded-types/dashboard/task/RecurrenceInfo.d.ts +74 -52
  58. package/lib/embedded-types/dashboard/task/RecurrenceInfo.d.ts.map +1 -1
  59. package/lib/embedded-types/dashboard/task/RecurrenceInfo.js +66 -28
  60. package/lib/embedded-types/dashboard/task/RecurrenceInfo.js.map +1 -1
  61. package/lib/embedded-types/dashboard/task/RecurrenceInfo.ts +83 -77
  62. package/lib/embedded-types/dashboard/task/SortSettings.d.ts +61 -42
  63. package/lib/embedded-types/dashboard/task/SortSettings.d.ts.map +1 -1
  64. package/lib/embedded-types/dashboard/task/SortSettings.js +34 -31
  65. package/lib/embedded-types/dashboard/task/SortSettings.js.map +1 -1
  66. package/lib/embedded-types/dashboard/task/SortSettings.ts +66 -61
  67. package/lib/embedded-types/dashboard/userConfig/Tags.d.ts +18 -11
  68. package/lib/embedded-types/dashboard/userConfig/Tags.d.ts.map +1 -1
  69. package/lib/embedded-types/dashboard/userConfig/Tags.js +15 -1
  70. package/lib/embedded-types/dashboard/userConfig/Tags.js.map +1 -1
  71. package/lib/embedded-types/dashboard/userConfig/Tags.ts +21 -9
  72. package/lib/schemas/required-refs/RequiredUserId.d.ts +9 -5
  73. package/lib/schemas/required-refs/RequiredUserId.d.ts.map +1 -1
  74. package/lib/schemas/required-refs/RequiredUserId.js +9 -4
  75. package/lib/schemas/required-refs/RequiredUserId.js.map +1 -1
  76. package/lib/schemas/required-refs/RequiredUserId.ts +13 -4
  77. package/lib/services/DocumentService.d.ts +1 -1
  78. package/lib/services/DocumentService.d.ts.map +1 -1
  79. package/lib/services/DocumentService.js +0 -1
  80. package/lib/services/DocumentService.js.map +1 -1
  81. package/lib/services/DocumentService.ts +1 -1
  82. package/lib/services/dashboard/Task/TaskRecurrenceService.d.ts +4 -4
  83. package/lib/services/dashboard/Task/TaskRecurrenceService.d.ts.map +1 -1
  84. package/lib/services/dashboard/Task/TaskRecurrenceService.js +3 -4
  85. package/lib/services/dashboard/Task/TaskRecurrenceService.js.map +1 -1
  86. package/lib/services/dashboard/Task/TaskRecurrenceService.ts +8 -5
  87. package/lib/services/dashboard/Task/TaskService.d.ts +1 -2
  88. package/lib/services/dashboard/Task/TaskService.d.ts.map +1 -1
  89. package/lib/services/dashboard/Task/TaskService.js +0 -1
  90. package/lib/services/dashboard/Task/TaskService.js.map +1 -1
  91. package/lib/services/dashboard/Task/TaskService.ts +1 -2
  92. package/lib/services/dashboard/Task/TaskSortService.d.ts.map +1 -1
  93. package/lib/services/dashboard/Task/TaskSortService.js +0 -1
  94. package/lib/services/dashboard/Task/TaskSortService.js.map +1 -1
  95. package/lib/services/dashboard/Task/TaskSortService.ts +1 -2
  96. package/package.json +10 -10
  97. package/lib/documents/BaseDocumentWithType.d.ts +0 -8
  98. package/lib/documents/BaseDocumentWithType.d.ts.map +0 -1
  99. package/lib/documents/BaseDocumentWithType.js +0 -7
  100. package/lib/documents/BaseDocumentWithType.js.map +0 -1
  101. package/lib/documents/BaseDocumentWithType.ts +0 -8
  102. package/lib/schemas/type-guards/commonTypeGuards.d.ts +0 -36
  103. package/lib/schemas/type-guards/commonTypeGuards.d.ts.map +0 -1
  104. package/lib/schemas/type-guards/commonTypeGuards.js +0 -46
  105. package/lib/schemas/type-guards/commonTypeGuards.js.map +0 -1
  106. package/lib/schemas/type-guards/commonTypeGuards.ts +0 -49
  107. package/lib/schemas/validators/DocumentValidator.d.ts +0 -9
  108. package/lib/schemas/validators/DocumentValidator.d.ts.map +0 -1
  109. package/lib/schemas/validators/DocumentValidator.js +0 -2
  110. package/lib/schemas/validators/DocumentValidator.js.map +0 -1
  111. package/lib/schemas/validators/DocumentValidator.ts +0 -9
  112. package/lib/schemas/validators/ValidateUtil.d.ts +0 -122
  113. package/lib/schemas/validators/ValidateUtil.d.ts.map +0 -1
  114. package/lib/schemas/validators/ValidateUtil.js +0 -216
  115. package/lib/schemas/validators/ValidateUtil.js.map +0 -1
  116. package/lib/schemas/validators/ValidateUtil.ts +0 -240
@@ -1,216 +0,0 @@
1
- import { isOptionalArray, isOptionalBoolean, isOptionalNumber, isOptionalObject, isOptionalString } from '../type-guards/commonTypeGuards.js';
2
- /**
3
- * All the validators in this class will modify the parent object to the
4
- * default value if the field is not correct. If the field is optional, it
5
- * will update the value to be undefined if it is not correct.
6
- *
7
- * This class can be used to validate nested objects by using a field path
8
- * (e.g. 'projectAccess.dashboard'). If the field path is invalid, then
9
- * this class will not report an error, because it is assumed that the
10
- * parent of the field path will report the error.
11
- *
12
- * Document relations are not validated by this class. That is the job of the
13
- * Document's repository.
14
- */
15
- export default class Validate {
16
- errorsArray;
17
- parentObject;
18
- constructor(parentObject, errorsArray) {
19
- this.errorsArray = errorsArray;
20
- this.parentObject = parentObject;
21
- }
22
- /**
23
- * Validates if the field is an optional string.
24
- *
25
- * @param fieldName - The name of the field to validate.
26
- */
27
- optionalString(fieldName) {
28
- if (this.fieldPathIsValid(fieldName) && !isOptionalString(this.getField(fieldName))) {
29
- this.errorsArray.push(`${fieldName} must be a string or undefined`);
30
- this.deleteField(fieldName);
31
- }
32
- }
33
- /**
34
- * Validates if the field is an optional number.
35
- *
36
- * @param fieldName - The name of the field to validate.
37
- */
38
- optionalNumber(fieldName) {
39
- if (this.fieldPathIsValid(fieldName) && !isOptionalNumber(this.getField(fieldName))) {
40
- this.errorsArray.push(`${fieldName} must be a number or undefined`);
41
- this.deleteField(fieldName);
42
- }
43
- }
44
- /**
45
- * Validates if the field is an optional boolean.
46
- *
47
- * @param fieldName - The name of the field to validate.
48
- */
49
- optionalBoolean(fieldName) {
50
- if (this.fieldPathIsValid(fieldName) && !isOptionalBoolean(this.getField(fieldName))) {
51
- this.errorsArray.push(`${fieldName} must be a boolean or undefined`);
52
- this.deleteField(fieldName);
53
- }
54
- }
55
- /**
56
- * Validates if the field is an optional array.
57
- *
58
- * @param fieldName - The name of the field to validate.
59
- */
60
- optionalArray(fieldName) {
61
- if (this.fieldPathIsValid(fieldName) && !isOptionalArray(this.getField(fieldName))) {
62
- this.errorsArray.push(`${fieldName} must be an array or undefined`);
63
- this.deleteField(fieldName);
64
- }
65
- }
66
- /**
67
- * Validates if the field is an optional object.
68
- *
69
- * @param fieldName - The name of the field to validate.
70
- */
71
- optionalObject(fieldName) {
72
- if (this.fieldPathIsValid(fieldName) && !isOptionalObject(this.getField(fieldName))) {
73
- this.errorsArray.push(`${fieldName} must be an object or undefined`);
74
- this.deleteField(fieldName);
75
- }
76
- }
77
- /**
78
- * Validates if the field is a string.
79
- *
80
- * @param fieldName - The name of the field to validate.
81
- * @param defaultValue - The default value to set if validation fails.
82
- */
83
- string(fieldName, defaultValue) {
84
- if (this.fieldPathIsValid(fieldName) && typeof this.getField(fieldName) !== 'string') {
85
- this.errorsArray.push(`${fieldName} must be a string`);
86
- this.updateField(fieldName, defaultValue);
87
- }
88
- }
89
- /**
90
- * Validates if the field is an object.
91
- *
92
- * @param fieldName - The name of the field to validate.
93
- * @param defaultValue - The default value to set if validation fails.
94
- */
95
- object(fieldName, defaultValue) {
96
- if (this.fieldPathIsValid(fieldName) &&
97
- (Array.isArray(this.getField(fieldName)) || typeof this.getField(fieldName) !== 'object')) {
98
- this.errorsArray.push(`${fieldName} must be an object`);
99
- this.updateField(fieldName, defaultValue);
100
- }
101
- }
102
- /**
103
- * Validates if the field is a number.
104
- *
105
- * @param fieldName - The name of the field to validate.
106
- * @param defaultValue - The default value to set if validation fails.
107
- */
108
- number(fieldName, defaultValue) {
109
- if (this.fieldPathIsValid(fieldName) && typeof this.getField(fieldName) !== 'number') {
110
- this.errorsArray.push(`${fieldName} must be a number`);
111
- this.updateField(fieldName, defaultValue);
112
- }
113
- }
114
- /**
115
- * Validates if the field is a boolean.
116
- *
117
- * @param fieldName - The name of the field to validate.
118
- * @param defaultValue - The default value to set if validation fails.
119
- */
120
- boolean(fieldName, defaultValue) {
121
- if (this.fieldPathIsValid(fieldName) && typeof this.getField(fieldName) !== 'boolean') {
122
- this.errorsArray.push(`${fieldName} must be a boolean`);
123
- this.updateField(fieldName, defaultValue);
124
- }
125
- }
126
- /**
127
- * Validates if the field is an array.
128
- *
129
- * @param fieldName - The name of the field to validate.
130
- * @param defaultValue - The default value to set if validation fails.
131
- */
132
- array(fieldName, defaultValue) {
133
- if (this.fieldPathIsValid(fieldName) && !Array.isArray(this.getField(fieldName))) {
134
- this.errorsArray.push(`${fieldName} must be an array`);
135
- this.updateField(fieldName, defaultValue);
136
- }
137
- }
138
- /**
139
- * Checks if the provided field path is valid. In other words, if the
140
- * field path is of length 1, it always returns true. If the field path
141
- * is any longer than 1, it will check to make sure the final field is
142
- * defined in the parent object.
143
- *
144
- * The idea is that if the field path is invalid, then this class will
145
- * not report an error, because it is assumed that the parent of the field
146
- * path will report the error.
147
- *
148
- * @param fieldName - The name of the field to check.
149
- * @returns boolean - True if the field path is valid, false otherwise.
150
- */
151
- fieldPathIsValid(fieldName) {
152
- const fieldPath = fieldName.split('.');
153
- if (fieldPath.length === 1) {
154
- return true;
155
- }
156
- let currentObject = this.parentObject;
157
- for (let i = 0; i < fieldPath.length - 1; i += 1) {
158
- if (typeof currentObject[fieldPath[i]] !== 'object') {
159
- return false;
160
- }
161
- currentObject = currentObject[fieldPath[i]];
162
- }
163
- return true;
164
- }
165
- /**
166
- * Updates the field with the provided default value.
167
- *
168
- * @param fieldName - The name of the field to update.
169
- * @param defaultValue - The default value to set.
170
- */
171
- updateField(fieldName, defaultValue) {
172
- const fieldPath = fieldName.split('.');
173
- let currentObject = this.parentObject;
174
- fieldPath.forEach((field, index) => {
175
- if (index === fieldPath.length - 1) {
176
- currentObject[field] = defaultValue;
177
- }
178
- else {
179
- currentObject = currentObject[field];
180
- }
181
- });
182
- }
183
- /**
184
- * Retrieves the value of the field.
185
- *
186
- * @param fieldName - The name of the field to retrieve.
187
- * @returns unknown - The value of the field.
188
- */
189
- getField(fieldName) {
190
- const fieldPath = fieldName.split('.');
191
- let currentObject = this.parentObject;
192
- fieldPath.forEach((field) => {
193
- currentObject = currentObject[field];
194
- });
195
- return currentObject;
196
- }
197
- /**
198
- * Deletes the field from the parent object.
199
- *
200
- * @param fieldName - The name of the field to delete.
201
- */
202
- deleteField(fieldName) {
203
- const fieldPath = fieldName.split('.');
204
- let currentObject = this.parentObject;
205
- fieldPath.forEach((field, index) => {
206
- if (index === fieldPath.length - 1) {
207
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
208
- delete currentObject[field];
209
- }
210
- else {
211
- currentObject = currentObject[field];
212
- }
213
- });
214
- }
215
- }
216
- //# sourceMappingURL=ValidateUtil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ValidateUtil.js","sourceRoot":"","sources":["../../../src/schemas/validators/ValidateUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,oCAAoC,CAAC;AAI5C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAKjB;IAJV,YAAY,CAAkB;IAE9B,YACE,YAAoB,EACZ,WAAqB;QAArB,gBAAW,GAAX,WAAW,CAAU;QAE7B,IAAI,CAAC,YAAY,GAAG,YAA+B,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,SAAiB;QAC9B,IAAI,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACpF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,SAAS,gCAAgC,CAAC,CAAC;YACpE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,SAAiB;QAC9B,IAAI,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;YACpF,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,SAAS,gCAAgC,CAAC,CAAC;YACpE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC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AAG,YAAY,CAAC;YACtC,CAAC;iBAAM,CAAC;gBACN,aAAa,GAAG,aAAa,CAAC,KAAK,CAAoB,CAAC;YAC1D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACK,QAAQ,CAAC,SAAiB;QAChC,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YAC1B,aAAa,GAAG,aAAa,CAAC,KAAK,CAAoB,CAAC;QAC1D,CAAC,CAAC,CAAC;QACH,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACK,WAAW,CAAC,SAAiB;QACnC,MAAM,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,IAAI,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YACjC,IAAI,KAAK,KAAK,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,gEAAgE;gBAChE,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACN,aAAa,GAAG,aAAa,CAAC,KAAK,CAAoB,CAAC;YAC1D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -1,240 +0,0 @@
1
- import {
2
- isOptionalArray,
3
- isOptionalBoolean,
4
- isOptionalNumber,
5
- isOptionalObject,
6
- isOptionalString
7
- } from '../type-guards/commonTypeGuards.js';
8
-
9
- type IndexableObject = { [keyName: string]: unknown };
10
-
11
- /**
12
- * All the validators in this class will modify the parent object to the
13
- * default value if the field is not correct. If the field is optional, it
14
- * will update the value to be undefined if it is not correct.
15
- *
16
- * This class can be used to validate nested objects by using a field path
17
- * (e.g. 'projectAccess.dashboard'). If the field path is invalid, then
18
- * this class will not report an error, because it is assumed that the
19
- * parent of the field path will report the error.
20
- *
21
- * Document relations are not validated by this class. That is the job of the
22
- * Document's repository.
23
- */
24
- export default class Validate {
25
- parentObject: IndexableObject;
26
-
27
- constructor(
28
- parentObject: object,
29
- private errorsArray: string[]
30
- ) {
31
- this.parentObject = parentObject as IndexableObject;
32
- }
33
-
34
- /**
35
- * Validates if the field is an optional string.
36
- *
37
- * @param fieldName - The name of the field to validate.
38
- */
39
- optionalString(fieldName: string) {
40
- if (this.fieldPathIsValid(fieldName) && !isOptionalString(this.getField(fieldName))) {
41
- this.errorsArray.push(`${fieldName} must be a string or undefined`);
42
- this.deleteField(fieldName);
43
- }
44
- }
45
-
46
- /**
47
- * Validates if the field is an optional number.
48
- *
49
- * @param fieldName - The name of the field to validate.
50
- */
51
- optionalNumber(fieldName: string) {
52
- if (this.fieldPathIsValid(fieldName) && !isOptionalNumber(this.getField(fieldName))) {
53
- this.errorsArray.push(`${fieldName} must be a number or undefined`);
54
- this.deleteField(fieldName);
55
- }
56
- }
57
-
58
- /**
59
- * Validates if the field is an optional boolean.
60
- *
61
- * @param fieldName - The name of the field to validate.
62
- */
63
- optionalBoolean(fieldName: string) {
64
- if (this.fieldPathIsValid(fieldName) && !isOptionalBoolean(this.getField(fieldName))) {
65
- this.errorsArray.push(`${fieldName} must be a boolean or undefined`);
66
- this.deleteField(fieldName);
67
- }
68
- }
69
-
70
- /**
71
- * Validates if the field is an optional array.
72
- *
73
- * @param fieldName - The name of the field to validate.
74
- */
75
- optionalArray(fieldName: string) {
76
- if (this.fieldPathIsValid(fieldName) && !isOptionalArray(this.getField(fieldName))) {
77
- this.errorsArray.push(`${fieldName} must be an array or undefined`);
78
- this.deleteField(fieldName);
79
- }
80
- }
81
-
82
- /**
83
- * Validates if the field is an optional object.
84
- *
85
- * @param fieldName - The name of the field to validate.
86
- */
87
- optionalObject(fieldName: string) {
88
- if (this.fieldPathIsValid(fieldName) && !isOptionalObject(this.getField(fieldName))) {
89
- this.errorsArray.push(`${fieldName} must be an object or undefined`);
90
- this.deleteField(fieldName);
91
- }
92
- }
93
-
94
- /**
95
- * Validates if the field is a string.
96
- *
97
- * @param fieldName - The name of the field to validate.
98
- * @param defaultValue - The default value to set if validation fails.
99
- */
100
- string(fieldName: string, defaultValue: string) {
101
- if (this.fieldPathIsValid(fieldName) && typeof this.getField(fieldName) !== 'string') {
102
- this.errorsArray.push(`${fieldName} must be a string`);
103
- this.updateField(fieldName, defaultValue);
104
- }
105
- }
106
-
107
- /**
108
- * Validates if the field is an object.
109
- *
110
- * @param fieldName - The name of the field to validate.
111
- * @param defaultValue - The default value to set if validation fails.
112
- */
113
- object(fieldName: string, defaultValue: object) {
114
- if (
115
- this.fieldPathIsValid(fieldName) &&
116
- (Array.isArray(this.getField(fieldName)) || typeof this.getField(fieldName) !== 'object')
117
- ) {
118
- this.errorsArray.push(`${fieldName} must be an object`);
119
- this.updateField(fieldName, defaultValue);
120
- }
121
- }
122
-
123
- /**
124
- * Validates if the field is a number.
125
- *
126
- * @param fieldName - The name of the field to validate.
127
- * @param defaultValue - The default value to set if validation fails.
128
- */
129
- number(fieldName: string, defaultValue: number) {
130
- if (this.fieldPathIsValid(fieldName) && typeof this.getField(fieldName) !== 'number') {
131
- this.errorsArray.push(`${fieldName} must be a number`);
132
- this.updateField(fieldName, defaultValue);
133
- }
134
- }
135
-
136
- /**
137
- * Validates if the field is a boolean.
138
- *
139
- * @param fieldName - The name of the field to validate.
140
- * @param defaultValue - The default value to set if validation fails.
141
- */
142
- boolean(fieldName: string, defaultValue: boolean) {
143
- if (this.fieldPathIsValid(fieldName) && typeof this.getField(fieldName) !== 'boolean') {
144
- this.errorsArray.push(`${fieldName} must be a boolean`);
145
- this.updateField(fieldName, defaultValue);
146
- }
147
- }
148
-
149
- /**
150
- * Validates if the field is an array.
151
- *
152
- * @param fieldName - The name of the field to validate.
153
- * @param defaultValue - The default value to set if validation fails.
154
- */
155
- array(fieldName: string, defaultValue: unknown[]) {
156
- if (this.fieldPathIsValid(fieldName) && !Array.isArray(this.getField(fieldName))) {
157
- this.errorsArray.push(`${fieldName} must be an array`);
158
- this.updateField(fieldName, defaultValue);
159
- }
160
- }
161
-
162
- /**
163
- * Checks if the provided field path is valid. In other words, if the
164
- * field path is of length 1, it always returns true. If the field path
165
- * is any longer than 1, it will check to make sure the final field is
166
- * defined in the parent object.
167
- *
168
- * The idea is that if the field path is invalid, then this class will
169
- * not report an error, because it is assumed that the parent of the field
170
- * path will report the error.
171
- *
172
- * @param fieldName - The name of the field to check.
173
- * @returns boolean - True if the field path is valid, false otherwise.
174
- */
175
- private fieldPathIsValid(fieldName: string): boolean {
176
- const fieldPath = fieldName.split('.');
177
- if (fieldPath.length === 1) {
178
- return true;
179
- }
180
- let currentObject = this.parentObject;
181
- for (let i = 0; i < fieldPath.length - 1; i += 1) {
182
- if (typeof currentObject[fieldPath[i]] !== 'object') {
183
- return false;
184
- }
185
- currentObject = currentObject[fieldPath[i]] as IndexableObject;
186
- }
187
- return true;
188
- }
189
-
190
- /**
191
- * Updates the field with the provided default value.
192
- *
193
- * @param fieldName - The name of the field to update.
194
- * @param defaultValue - The default value to set.
195
- */
196
- private updateField(fieldName: string, defaultValue: unknown) {
197
- const fieldPath = fieldName.split('.');
198
- let currentObject = this.parentObject;
199
- fieldPath.forEach((field, index) => {
200
- if (index === fieldPath.length - 1) {
201
- currentObject[field] = defaultValue;
202
- } else {
203
- currentObject = currentObject[field] as IndexableObject;
204
- }
205
- });
206
- }
207
-
208
- /**
209
- * Retrieves the value of the field.
210
- *
211
- * @param fieldName - The name of the field to retrieve.
212
- * @returns unknown - The value of the field.
213
- */
214
- private getField(fieldName: string): unknown {
215
- const fieldPath = fieldName.split('.');
216
- let currentObject = this.parentObject;
217
- fieldPath.forEach((field) => {
218
- currentObject = currentObject[field] as IndexableObject;
219
- });
220
- return currentObject;
221
- }
222
-
223
- /**
224
- * Deletes the field from the parent object.
225
- *
226
- * @param fieldName - The name of the field to delete.
227
- */
228
- private deleteField(fieldName: string) {
229
- const fieldPath = fieldName.split('.');
230
- let currentObject = this.parentObject;
231
- fieldPath.forEach((field, index) => {
232
- if (index === fieldPath.length - 1) {
233
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
234
- delete currentObject[field];
235
- } else {
236
- currentObject = currentObject[field] as IndexableObject;
237
- }
238
- });
239
- }
240
- }