@acorex/core 7.17.20 → 7.17.22

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 (59) hide show
  1. package/esm2022/config/lib/configs.service.mjs +3 -3
  2. package/esm2022/dateTime/lib/calendar.service.mjs +3 -3
  3. package/esm2022/dateTime/lib/datetime-formatter.mjs +6 -6
  4. package/esm2022/dateTime/lib/datetime.class.mjs +6 -2
  5. package/esm2022/dateTime/lib/datetime.module.mjs +4 -4
  6. package/esm2022/dateTime/lib/datetime.pipe.mjs +3 -3
  7. package/esm2022/events/lib/event.service.mjs +3 -3
  8. package/esm2022/file/lib/file-size-formatter.mjs +3 -3
  9. package/esm2022/file/lib/file.module.mjs +4 -4
  10. package/esm2022/file/lib/file.service.mjs +3 -3
  11. package/esm2022/format/lib/format.module.mjs +4 -4
  12. package/esm2022/format/lib/format.pipe.mjs +3 -3
  13. package/esm2022/format/lib/format.service.mjs +6 -6
  14. package/esm2022/image/lib/image.service.mjs +3 -3
  15. package/esm2022/pipes/lib/safe/safe.pipe.mjs +3 -3
  16. package/esm2022/platform/lib/platform.service.mjs +3 -3
  17. package/esm2022/storage/cookie-storage.service.mjs +3 -3
  18. package/esm2022/storage/local-storage.service.mjs +3 -3
  19. package/esm2022/storage/session-storage.service.mjs +3 -3
  20. package/esm2022/translation/lib/translation.module.mjs +4 -4
  21. package/esm2022/translation/lib/translator.pipe.mjs +3 -3
  22. package/esm2022/utils/lib/auto-unsubscribe.mjs +3 -3
  23. package/esm2022/validation/acorex-core-validation.mjs +5 -0
  24. package/esm2022/validation/index.mjs +12 -0
  25. package/esm2022/validation/lib/rules/callback-rule.mjs +19 -0
  26. package/esm2022/validation/lib/rules/length-rule.mjs +15 -0
  27. package/esm2022/validation/lib/rules/maxlength-rule.mjs +15 -0
  28. package/esm2022/validation/lib/rules/minlength-rule.mjs +15 -0
  29. package/esm2022/validation/lib/rules/regex-rule.mjs +17 -0
  30. package/esm2022/validation/lib/rules/required-rule.mjs +24 -0
  31. package/esm2022/validation/lib/validation.mjs +2 -0
  32. package/esm2022/validation/lib/validation.module.mjs +41 -0
  33. package/esm2022/validation/lib/validation.service.mjs +71 -0
  34. package/fesm2022/acorex-core-config.mjs +3 -3
  35. package/fesm2022/acorex-core-dateTime.mjs +21 -17
  36. package/fesm2022/acorex-core-dateTime.mjs.map +1 -1
  37. package/fesm2022/acorex-core-events.mjs +3 -3
  38. package/fesm2022/acorex-core-file.mjs +10 -10
  39. package/fesm2022/acorex-core-format.mjs +13 -13
  40. package/fesm2022/acorex-core-image.mjs +3 -3
  41. package/fesm2022/acorex-core-pipes.mjs +3 -3
  42. package/fesm2022/acorex-core-platform.mjs +3 -3
  43. package/fesm2022/acorex-core-storage.mjs +9 -9
  44. package/fesm2022/acorex-core-translation.mjs +7 -7
  45. package/fesm2022/acorex-core-utils.mjs +3 -3
  46. package/fesm2022/acorex-core-validation.mjs +214 -0
  47. package/fesm2022/acorex-core-validation.mjs.map +1 -0
  48. package/package.json +7 -1
  49. package/validation/README.md +3 -0
  50. package/validation/index.d.ts +9 -0
  51. package/validation/lib/rules/callback-rule.d.ts +20 -0
  52. package/validation/lib/rules/length-rule.d.ts +14 -0
  53. package/validation/lib/rules/maxlength-rule.d.ts +13 -0
  54. package/validation/lib/rules/minlength-rule.d.ts +13 -0
  55. package/validation/lib/rules/regex-rule.d.ts +13 -0
  56. package/validation/lib/rules/required-rule.d.ts +12 -0
  57. package/validation/lib/validation.d.ts +19 -0
  58. package/validation/lib/validation.module.d.ts +13 -0
  59. package/validation/lib/validation.service.d.ts +27 -0
@@ -209,10 +209,10 @@ class AXPlatform {
209
209
  // init functions
210
210
  this._setFullHeightRatio();
211
211
  }
212
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXPlatform, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
213
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXPlatform, providedIn: 'root' }); }
212
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXPlatform, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
213
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXPlatform, providedIn: 'root' }); }
214
214
  }
215
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXPlatform, decorators: [{
215
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXPlatform, decorators: [{
216
216
  type: Injectable,
217
217
  args: [{
218
218
  providedIn: 'root',
@@ -181,10 +181,10 @@ class AXCookieStorageService {
181
181
  }
182
182
  }
183
183
  }
184
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXCookieStorageService, deps: [{ token: DOCUMENT }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
185
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXCookieStorageService }); }
184
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXCookieStorageService, deps: [{ token: DOCUMENT }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
185
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXCookieStorageService }); }
186
186
  }
187
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXCookieStorageService, decorators: [{
187
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXCookieStorageService, decorators: [{
188
188
  type: Injectable
189
189
  }], ctorParameters: () => [{ type: Document, decorators: [{
190
190
  type: Inject,
@@ -207,10 +207,10 @@ class AXLocalStorageService {
207
207
  removeItem(key) {
208
208
  return localStorage.removeItem(key);
209
209
  }
210
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXLocalStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
211
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXLocalStorageService }); }
210
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXLocalStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
211
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXLocalStorageService }); }
212
212
  }
213
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXLocalStorageService, decorators: [{
213
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXLocalStorageService, decorators: [{
214
214
  type: Injectable
215
215
  }] });
216
216
 
@@ -227,10 +227,10 @@ class AXSessionStorageService {
227
227
  removeItem(key) {
228
228
  return sessionStorage.removeItem(key);
229
229
  }
230
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXSessionStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
231
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXSessionStorageService }); }
230
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXSessionStorageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
231
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXSessionStorageService }); }
232
232
  }
233
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXSessionStorageService, decorators: [{
233
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXSessionStorageService, decorators: [{
234
234
  type: Injectable
235
235
  }] });
236
236
 
@@ -47,20 +47,20 @@ class AXTranslatorPipe {
47
47
  transform(value, arg1, arg2) {
48
48
  return AXTranslator.get(value, arg1, arg2);
49
49
  }
50
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXTranslatorPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
51
- static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.0.7", ngImport: i0, type: AXTranslatorPipe, name: "trans" }); }
50
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
51
+ static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorPipe, name: "trans" }); }
52
52
  }
53
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXTranslatorPipe, decorators: [{
53
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslatorPipe, decorators: [{
54
54
  type: Pipe,
55
55
  args: [{ name: 'trans', pure: true }]
56
56
  }] });
57
57
 
58
58
  class AXTranslationModule {
59
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXTranslationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
60
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.7", ngImport: i0, type: AXTranslationModule, declarations: [AXTranslatorPipe], exports: [AXTranslatorPipe] }); }
61
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXTranslationModule }); }
59
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
60
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule, declarations: [AXTranslatorPipe], exports: [AXTranslatorPipe] }); }
61
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule }); }
62
62
  }
63
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXTranslationModule, decorators: [{
63
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXTranslationModule, decorators: [{
64
64
  type: NgModule,
65
65
  args: [{
66
66
  imports: [],
@@ -30,10 +30,10 @@ class AXUnsubscriber {
30
30
  ngOnDestroy() {
31
31
  this.unsubscribe();
32
32
  }
33
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXUnsubscriber, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
34
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXUnsubscriber }); }
33
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXUnsubscriber, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
34
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXUnsubscriber }); }
35
35
  }
36
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.7", ngImport: i0, type: AXUnsubscriber, decorators: [{
36
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXUnsubscriber, decorators: [{
37
37
  type: Injectable
38
38
  }] });
39
39
 
@@ -0,0 +1,214 @@
1
+ import { isNull, isUndefined, isString, isEmpty, isNumber, isArray, find } from 'lodash-es';
2
+ import * as i0 from '@angular/core';
3
+ import { Injectable, APP_INITIALIZER, NgModule } from '@angular/core';
4
+ import { AXTranslator } from '@acorex/core/translation';
5
+
6
+ class AXRegexValidationRule {
7
+ get name() {
8
+ return 'regex';
9
+ }
10
+ validate(value, options) {
11
+ // Convert string pattern to RegExp if necessary
12
+ const regexPattern = typeof options.pattern === 'string' ? new RegExp(options.pattern) : options.pattern;
13
+ const isValid = regexPattern.test(value);
14
+ return {
15
+ name: this.name,
16
+ result: isValid,
17
+ message: isValid ? '' : `The value does not match the pattern ${regexPattern}.`,
18
+ value: value
19
+ };
20
+ }
21
+ }
22
+
23
+ class AXRequiredValidationRule {
24
+ get name() {
25
+ return 'required';
26
+ }
27
+ validate(value) {
28
+ const rules = [
29
+ { test: val => isNull(val) || isUndefined(val) },
30
+ { test: val => isString(val) && isEmpty(val.trim()) },
31
+ { test: val => isNumber(val) && isNaN(val) },
32
+ { test: val => isArray(val) && isEmpty(val) }
33
+ ];
34
+ const failedRule = find(rules, rule => rule.test(value));
35
+ const isValid = !failedRule;
36
+ const message = failedRule ? "This filed is required" : null;
37
+ return {
38
+ name: this.name,
39
+ result: isValid,
40
+ message: message,
41
+ value
42
+ };
43
+ }
44
+ }
45
+
46
+ class AXCallbackValidationRule {
47
+ get name() {
48
+ return 'callback';
49
+ }
50
+ validate(value, options) {
51
+ const validationResult = options?.validate(value) || { result: false, message: "Invalid callback function" };
52
+ const createResult = (result) => ({
53
+ name: this.name,
54
+ result: result.result,
55
+ message: result.message || '',
56
+ value: value
57
+ });
58
+ if (validationResult instanceof Promise) {
59
+ return validationResult.then(createResult);
60
+ }
61
+ return createResult(validationResult);
62
+ }
63
+ }
64
+
65
+ class AXMinLengthValidationRule {
66
+ get name() {
67
+ return 'minLength';
68
+ }
69
+ validate(value, options) {
70
+ const isValid = value?.length >= options.value;
71
+ return {
72
+ name: this.name,
73
+ result: isValid,
74
+ message: isValid ? '' : `The value must be at least ${options.value} characters long.`,
75
+ value: value
76
+ };
77
+ }
78
+ }
79
+
80
+ class AXMaxLengthValidationRule {
81
+ get name() {
82
+ return 'maxLength';
83
+ }
84
+ validate(value, options) {
85
+ const isValid = value?.length <= options.value;
86
+ return {
87
+ name: this.name,
88
+ result: isValid,
89
+ message: isValid ? '' : `The value must not exceed ${options.value} characters.`,
90
+ value: value
91
+ };
92
+ }
93
+ }
94
+
95
+ class AXLengthValidationRule {
96
+ get name() {
97
+ return 'length';
98
+ }
99
+ validate(value, options) {
100
+ const isValid = value?.length >= options.min && value?.length <= options.max;
101
+ return {
102
+ name: this.name,
103
+ result: isValid,
104
+ message: isValid ? null : `The value must be between ${options.min} and ${options.max} chars`,
105
+ value: value
106
+ };
107
+ }
108
+ }
109
+
110
+ class AXValidationRegistryService {
111
+ constructor() {
112
+ this.plugins = [];
113
+ }
114
+ register(...plugin) {
115
+ this.plugins.push(...plugin.filter(p => !this.plugins.some(c => c.name == p.name)));
116
+ }
117
+ get validators() {
118
+ return this.plugins;
119
+ }
120
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRegistryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
121
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRegistryService, providedIn: 'root' }); }
122
+ }
123
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRegistryService, decorators: [{
124
+ type: Injectable,
125
+ args: [{
126
+ providedIn: 'root'
127
+ }]
128
+ }] });
129
+ class AXValidationService {
130
+ constructor(pluginRegistry) {
131
+ this.pluginRegistry = pluginRegistry;
132
+ }
133
+ validate(ruleName, value, options) {
134
+ const validator = this.pluginRegistry.validators.find((c) => c.name == ruleName);
135
+ if (!validator) {
136
+ return {
137
+ name: ruleName,
138
+ result: false,
139
+ message: AXTranslator.get('validation.messages.invalid-rull-name', { name: ruleName }),
140
+ value
141
+ };
142
+ }
143
+ return validator.validate(value, options);
144
+ }
145
+ ruleFor(value) {
146
+ return new AXValidationRuleChain(this, value);
147
+ }
148
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationService, deps: [{ token: AXValidationRegistryService }], target: i0.ɵɵFactoryTarget.Injectable }); }
149
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationService, providedIn: 'root' }); }
150
+ }
151
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationService, decorators: [{
152
+ type: Injectable,
153
+ args: [{ providedIn: 'root' }]
154
+ }], ctorParameters: () => [{ type: AXValidationRegistryService }] });
155
+ class AXValidationRuleChain {
156
+ constructor(validationService, initialValue) {
157
+ this.validationService = validationService;
158
+ this.initialValue = initialValue;
159
+ this.rules = [];
160
+ this.validationSummary = { result: true, rules: [] };
161
+ }
162
+ addRule(name, options) {
163
+ this.rules.push({ name, options });
164
+ return this;
165
+ }
166
+ async validate() {
167
+ for (const rule of this.rules) {
168
+ const result = await this.validationService.validate(rule.name, this.initialValue, rule.options);
169
+ this.validationSummary.rules.push(result);
170
+ if (!result.result) {
171
+ this.validationSummary.result = false;
172
+ }
173
+ }
174
+ return this.validationSummary;
175
+ }
176
+ }
177
+
178
+ class AXValidationModule {
179
+ static forRoot(config) {
180
+ return {
181
+ ngModule: AXValidationModule,
182
+ providers: [
183
+ {
184
+ provide: APP_INITIALIZER,
185
+ useFactory: (pluginRegistry) => () => {
186
+ if (config?.validators?.length)
187
+ pluginRegistry.register(...config.validators);
188
+ },
189
+ deps: [AXValidationRegistryService],
190
+ multi: true
191
+ }
192
+ ]
193
+ };
194
+ }
195
+ constructor(pluginRegistry) {
196
+ pluginRegistry.register(new AXRegexValidationRule(), new AXRequiredValidationRule(), new AXCallbackValidationRule(), new AXMinLengthValidationRule(), new AXMaxLengthValidationRule(), new AXLengthValidationRule());
197
+ }
198
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationModule, deps: [{ token: AXValidationRegistryService }], target: i0.ɵɵFactoryTarget.NgModule }); }
199
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXValidationModule }); }
200
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationModule }); }
201
+ }
202
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationModule, decorators: [{
203
+ type: NgModule,
204
+ args: [{
205
+ imports: [],
206
+ }]
207
+ }], ctorParameters: () => [{ type: AXValidationRegistryService }] });
208
+
209
+ /**
210
+ * Generated bundle index. Do not edit.
211
+ */
212
+
213
+ export { AXCallbackValidationRule, AXLengthValidationRule, AXMaxLengthValidationRule, AXMinLengthValidationRule, AXRegexValidationRule, AXRequiredValidationRule, AXValidationModule, AXValidationRegistryService, AXValidationService };
214
+ //# sourceMappingURL=acorex-core-validation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acorex-core-validation.mjs","sources":["../../../../libs/core/validation/src/lib/rules/regex-rule.ts","../../../../libs/core/validation/src/lib/rules/required-rule.ts","../../../../libs/core/validation/src/lib/rules/callback-rule.ts","../../../../libs/core/validation/src/lib/rules/minlength-rule.ts","../../../../libs/core/validation/src/lib/rules/maxlength-rule.ts","../../../../libs/core/validation/src/lib/rules/length-rule.ts","../../../../libs/core/validation/src/lib/validation.service.ts","../../../../libs/core/validation/src/lib/validation.module.ts","../../../../libs/core/validation/src/acorex-core-validation.ts"],"sourcesContent":["import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from \"../validation\";\n\n\nexport interface AXRegexValidationRuleOptions extends AXValidationRuleOptions {\n pattern: string | RegExp;\n}\n\n// Augment the AXValidationRuleOptionsMap\ndeclare module '../validation' {\n interface AXValidationRuleOptionsMap {\n 'regex': AXRegexValidationRuleOptions;\n }\n}\n\nexport class AXRegexValidationRule implements AXValidationRule {\n\n get name(): string {\n return 'regex';\n }\n\n validate(value: string, options: AXRegexValidationRuleOptions): AXValidationRuleResult {\n // Convert string pattern to RegExp if necessary\n const regexPattern = typeof options.pattern === 'string' ? new RegExp(options.pattern) : options.pattern;\n\n const isValid = regexPattern.test(value);\n return {\n name: this.name,\n result: isValid,\n message: isValid ? '' : `The value does not match the pattern ${regexPattern}.`,\n value: value\n };\n }\n\n}","import { find, isArray, isEmpty, isNull, isNumber, isString, isUndefined } from \"lodash-es\";\nimport { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from \"../validation\";\n\n\nexport interface AXRequiredValidationRuleOptions extends AXValidationRuleOptions {\n}\n\n// Augment the AXValidationRuleOptionsMap\ndeclare module '../validation' {\n interface AXValidationRuleOptionsMap {\n 'required': AXRequiredValidationRuleOptions;\n }\n}\n\nexport class AXRequiredValidationRule implements AXValidationRule {\n\n get name(): string {\n return 'required';\n }\n\n validate(value?: unknown): AXValidationRuleResult {\n const rules = [\n { test: val => isNull(val) || isUndefined(val) },\n { test: val => isString(val) && isEmpty(val.trim()) },\n { test: val => isNumber(val) && isNaN(val) },\n { test: val => isArray(val) && isEmpty(val) }\n ];\n\n const failedRule = find(rules, rule => rule.test(value));\n const isValid = !failedRule;\n const message = failedRule ? \"This filed is required\" : null;\n\n return {\n name: this.name,\n result: isValid,\n message: message,\n value\n };\n }\n}","import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from \"../validation\";\n\nexport type AXCallbackValidation<T> = (value: T) => Promise<{ result: boolean, message?: string }> | { result: boolean, message?: string };\n\nexport interface AXCallbackValidationRuleOptions<T> extends AXValidationRuleOptions {\n validate: AXCallbackValidation<T>\n}\n\n// Augment the AXValidationRuleOptionsMap\ndeclare module '../validation' {\n interface AXValidationRuleOptionsMap {\n 'callback': AXCallbackValidationRuleOptions<unknown>;\n }\n}\n\nexport class AXCallbackValidationRule<T> implements AXValidationRule {\n\n get name(): string {\n return 'callback';\n }\n\n validate(value: T, options: AXCallbackValidationRuleOptions<T>): AXValidationRuleResult | Promise<AXValidationRuleResult> {\n const validationResult = options?.validate(value) || { result: false, message: \"Invalid callback function\" };\n const createResult = (result: { result: boolean, message?: string }) => ({\n name: this.name,\n result: result.result,\n message: result.message || '',\n value: value\n });\n\n if (validationResult instanceof Promise) {\n return validationResult.then(createResult);\n }\n\n return createResult(validationResult);\n }\n}","import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from \"../validation\";\n\nexport interface AXMinLengthValidationRuleOptions extends AXValidationRuleOptions {\n value: number;\n}\n\ndeclare module '../validation' {\n interface AXValidationRuleOptionsMap {\n 'minLength': AXMinLengthValidationRuleOptions;\n }\n}\n\nexport class AXMinLengthValidationRule implements AXValidationRule {\n get name(): string {\n return 'minLength';\n }\n\n validate(value: string, options: AXMinLengthValidationRuleOptions): AXValidationRuleResult {\n const isValid = value?.length >= options.value;\n return {\n name: this.name,\n result: isValid,\n message: isValid ? '' : `The value must be at least ${options.value} characters long.`,\n value: value\n };\n }\n}","// ax-max-length-validation-rule.ts\nimport { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from \"../validation\";\n\nexport interface AXMaxLengthValidationRuleOptions extends AXValidationRuleOptions {\n value: number;\n}\n\ndeclare module '../validation' {\n interface AXValidationRuleOptionsMap {\n 'maxLength': AXMaxLengthValidationRuleOptions;\n }\n}\n\nexport class AXMaxLengthValidationRule implements AXValidationRule {\n get name(): string {\n return 'maxLength';\n }\n\n validate(value: string, options: AXMaxLengthValidationRuleOptions): AXValidationRuleResult {\n const isValid = value?.length <= options.value;\n return {\n name: this.name,\n result: isValid,\n message: isValid ? '' : `The value must not exceed ${options.value} characters.`,\n value: value\n };\n }\n}\n","// ax-max-length-validation-rule.ts\nimport { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from \"../validation\";\n\nexport interface AXLengthValidationRuleOptions extends AXValidationRuleOptions {\n min: number;\n max: number;\n}\n\ndeclare module '../validation' {\n interface AXValidationRuleOptionsMap {\n 'length': AXLengthValidationRuleOptions;\n }\n}\n\nexport class AXLengthValidationRule implements AXValidationRule {\n get name(): string {\n return 'length';\n }\n\n validate(value: string, options: AXLengthValidationRuleOptions): AXValidationRuleResult {\n const isValid = value?.length >= options.min && value?.length <= options.max;\n return {\n name: this.name,\n result: isValid,\n message: isValid ? null : `The value must be between ${options.min} and ${options.max} chars`,\n value: value\n };\n }\n}\n","import { Injectable } from \"@angular/core\";\nimport { AXValidationRule, AXValidationRuleOptions, AXValidationRuleOptionsMap, AXValidationRuleResult, AXValidationSummary } from \"./validation\";\nimport { AXTranslator } from \"@acorex/core/translation\";\n\n@Injectable({\n providedIn: 'root'\n})\nexport class AXValidationRegistryService {\n private plugins: AXValidationRule[] = [];\n\n register(...plugin: AXValidationRule[]) {\n this.plugins.push(...plugin.filter(p => !this.plugins.some(c => c.name == p.name)));\n }\n\n get validators(): AXValidationRule[] {\n return this.plugins;\n }\n}\n\n@Injectable({ providedIn: 'root' })\nexport class AXValidationService {\n constructor(\n private pluginRegistry: AXValidationRegistryService\n ) { }\n\n validate(ruleName: string, value: unknown, options?: AXValidationRuleOptions): AXValidationRuleResult | Promise<AXValidationRuleResult> {\n const validator = this.pluginRegistry.validators.find((c) => c.name == ruleName);\n if (!validator) {\n return {\n name: ruleName,\n result: false,\n message: AXTranslator.get('validation.messages.invalid-rull-name', { name: ruleName }),\n value\n };\n }\n return validator.validate(value, options);\n }\n\n\n ruleFor(value: unknown): AXValidationRuleChain {\n return new AXValidationRuleChain(this, value);\n }\n}\n\nclass AXValidationRuleChain {\n private rules: { name: string, options?: AXValidationRuleOptions }[] = [];\n private validationSummary: AXValidationSummary = { result: true, rules: [] };\n\n constructor(private validationService: AXValidationService, private initialValue: unknown) { }\n\n addRule<K extends keyof AXValidationRuleOptionsMap>(name: K, options?: AXValidationRuleOptionsMap[K]): AXValidationRuleChain {\n this.rules.push({ name, options });\n return this;\n }\n\n async validate(): Promise<AXValidationSummary> {\n for (const rule of this.rules) {\n const result = await this.validationService.validate(rule.name, this.initialValue, rule.options);\n this.validationSummary.rules.push(result);\n if (!result.result) {\n this.validationSummary.result = false;\n }\n }\n return this.validationSummary;\n }\n}\n","import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';\nimport { AXValidationRegistryService } from './validation.service';\nimport { AXValidationRule } from './validation';\nimport { AXRegexValidationRule } from './rules/regex-rule';\nimport { AXRequiredValidationRule } from './rules/required-rule';\nimport { AXCallbackValidationRule } from './rules/callback-rule';\nimport { AXMinLengthValidationRule } from './rules/minlength-rule';\nimport { AXMaxLengthValidationRule } from './rules/maxlength-rule';\nimport { AXLengthValidationRule } from './rules/length-rule';\n\n\n@NgModule({\n imports: [],\n})\nexport class AXValidationModule {\n\n static forRoot(config?: { validators?: AXValidationRule[] }): ModuleWithProviders<AXValidationModule> {\n return {\n ngModule: AXValidationModule,\n providers: [\n {\n provide: APP_INITIALIZER,\n useFactory: (pluginRegistry: AXValidationRegistryService) => () => {\n if (config?.validators?.length)\n pluginRegistry.register(...config.validators);\n },\n deps: [AXValidationRegistryService],\n multi: true\n }\n ]\n };\n }\n\n constructor(pluginRegistry: AXValidationRegistryService) {\n pluginRegistry.register(\n new AXRegexValidationRule(),\n new AXRequiredValidationRule(),\n new AXCallbackValidationRule(),\n new AXMinLengthValidationRule(),\n new AXMaxLengthValidationRule(),\n new AXLengthValidationRule(),\n )\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1.AXValidationRegistryService"],"mappings":";;;;;MAca,qBAAqB,CAAA;AAE9B,IAAA,IAAI,IAAI,GAAA;AACJ,QAAA,OAAO,OAAO,CAAC;KAClB;IAED,QAAQ,CAAC,KAAa,EAAE,OAAqC,EAAA;;QAEzD,MAAM,YAAY,GAAG,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;QAEzG,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;AACf,YAAA,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,OAAO,GAAG,EAAE,GAAG,CAAwC,qCAAA,EAAA,YAAY,CAAG,CAAA,CAAA;AAC/E,YAAA,KAAK,EAAE,KAAK;SACf,CAAC;KACL;AAEJ;;MCnBY,wBAAwB,CAAA;AAEjC,IAAA,IAAI,IAAI,GAAA;AACJ,QAAA,OAAO,UAAU,CAAC;KACrB;AAED,IAAA,QAAQ,CAAC,KAAe,EAAA;AACpB,QAAA,MAAM,KAAK,GAAG;AACV,YAAA,EAAE,IAAI,EAAE,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;AAChD,YAAA,EAAE,IAAI,EAAE,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE;AACrD,YAAA,EAAE,IAAI,EAAE,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,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B,IAAI,wBAAwB,EAAE,EAC9B,IAAI,wBAAwB,EAAE,EAC9B,IAAI,yBAAyB,EAAE,EAC/B,IAAI,yBAAyB,EAAE,EAC/B,IAAI,sBAAsB,EAAE,CAC/B,CAAA;KACJ;8GA5BQ,kBAAkB,EAAA,IAAA,EAAA,CAAA,EAAA,KAAA,EAAAA,2BAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA,EAAA;+GAAlB,kBAAkB,EAAA,CAAA,CAAA,EAAA;+GAAlB,kBAAkB,EAAA,CAAA,CAAA,EAAA;;2FAAlB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAH9B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACN,oBAAA,OAAO,EAAE,EAAE;AACd,iBAAA,CAAA;;;ACbD;;AAEG;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acorex/core",
3
- "version": "7.17.20",
3
+ "version": "7.17.22",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "@angular/common": ">=17.0.3",
@@ -104,6 +104,12 @@
104
104
  "esm2022": "./esm2022/utils/acorex-core-utils.mjs",
105
105
  "esm": "./esm2022/utils/acorex-core-utils.mjs",
106
106
  "default": "./fesm2022/acorex-core-utils.mjs"
107
+ },
108
+ "./validation": {
109
+ "types": "./validation/index.d.ts",
110
+ "esm2022": "./esm2022/validation/acorex-core-validation.mjs",
111
+ "esm": "./esm2022/validation/acorex-core-validation.mjs",
112
+ "default": "./fesm2022/acorex-core-validation.mjs"
107
113
  }
108
114
  },
109
115
  "dependencies": {
@@ -0,0 +1,3 @@
1
+ # @acorex/core/validation
2
+
3
+ Secondary entry point of `@acorex/core`. It can be used by importing from `@acorex/core/validation`.
@@ -0,0 +1,9 @@
1
+ export * from './lib/validation';
2
+ export * from './lib/rules/regex-rule';
3
+ export * from './lib/rules/required-rule';
4
+ export * from './lib/rules/callback-rule';
5
+ export * from './lib/rules/minlength-rule';
6
+ export * from './lib/rules/maxlength-rule';
7
+ export * from './lib/rules/length-rule';
8
+ export * from './lib/validation.service';
9
+ export * from './lib/validation.module';
@@ -0,0 +1,20 @@
1
+ import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from "../validation";
2
+ export type AXCallbackValidation<T> = (value: T) => Promise<{
3
+ result: boolean;
4
+ message?: string;
5
+ }> | {
6
+ result: boolean;
7
+ message?: string;
8
+ };
9
+ export interface AXCallbackValidationRuleOptions<T> extends AXValidationRuleOptions {
10
+ validate: AXCallbackValidation<T>;
11
+ }
12
+ declare module '../validation' {
13
+ interface AXValidationRuleOptionsMap {
14
+ 'callback': AXCallbackValidationRuleOptions<unknown>;
15
+ }
16
+ }
17
+ export declare class AXCallbackValidationRule<T> implements AXValidationRule {
18
+ get name(): string;
19
+ validate(value: T, options: AXCallbackValidationRuleOptions<T>): AXValidationRuleResult | Promise<AXValidationRuleResult>;
20
+ }
@@ -0,0 +1,14 @@
1
+ import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from "../validation";
2
+ export interface AXLengthValidationRuleOptions extends AXValidationRuleOptions {
3
+ min: number;
4
+ max: number;
5
+ }
6
+ declare module '../validation' {
7
+ interface AXValidationRuleOptionsMap {
8
+ 'length': AXLengthValidationRuleOptions;
9
+ }
10
+ }
11
+ export declare class AXLengthValidationRule implements AXValidationRule {
12
+ get name(): string;
13
+ validate(value: string, options: AXLengthValidationRuleOptions): AXValidationRuleResult;
14
+ }
@@ -0,0 +1,13 @@
1
+ import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from "../validation";
2
+ export interface AXMaxLengthValidationRuleOptions extends AXValidationRuleOptions {
3
+ value: number;
4
+ }
5
+ declare module '../validation' {
6
+ interface AXValidationRuleOptionsMap {
7
+ 'maxLength': AXMaxLengthValidationRuleOptions;
8
+ }
9
+ }
10
+ export declare class AXMaxLengthValidationRule implements AXValidationRule {
11
+ get name(): string;
12
+ validate(value: string, options: AXMaxLengthValidationRuleOptions): AXValidationRuleResult;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from "../validation";
2
+ export interface AXMinLengthValidationRuleOptions extends AXValidationRuleOptions {
3
+ value: number;
4
+ }
5
+ declare module '../validation' {
6
+ interface AXValidationRuleOptionsMap {
7
+ 'minLength': AXMinLengthValidationRuleOptions;
8
+ }
9
+ }
10
+ export declare class AXMinLengthValidationRule implements AXValidationRule {
11
+ get name(): string;
12
+ validate(value: string, options: AXMinLengthValidationRuleOptions): AXValidationRuleResult;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from "../validation";
2
+ export interface AXRegexValidationRuleOptions extends AXValidationRuleOptions {
3
+ pattern: string | RegExp;
4
+ }
5
+ declare module '../validation' {
6
+ interface AXValidationRuleOptionsMap {
7
+ 'regex': AXRegexValidationRuleOptions;
8
+ }
9
+ }
10
+ export declare class AXRegexValidationRule implements AXValidationRule {
11
+ get name(): string;
12
+ validate(value: string, options: AXRegexValidationRuleOptions): AXValidationRuleResult;
13
+ }
@@ -0,0 +1,12 @@
1
+ import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleResult } from "../validation";
2
+ export interface AXRequiredValidationRuleOptions extends AXValidationRuleOptions {
3
+ }
4
+ declare module '../validation' {
5
+ interface AXValidationRuleOptionsMap {
6
+ 'required': AXRequiredValidationRuleOptions;
7
+ }
8
+ }
9
+ export declare class AXRequiredValidationRule implements AXValidationRule {
10
+ get name(): string;
11
+ validate(value?: unknown): AXValidationRuleResult;
12
+ }
@@ -0,0 +1,19 @@
1
+ export interface AXValidationRuleOptions {
2
+ [key: string]: unknown;
3
+ }
4
+ export interface AXValidationRuleOptionsMap {
5
+ }
6
+ export interface AXValidationRule {
7
+ get name(): string;
8
+ validate(value: unknown, options?: AXValidationRuleOptions): AXValidationRuleResult | Promise<AXValidationRuleResult>;
9
+ }
10
+ export interface AXValidationRuleResult {
11
+ name: string;
12
+ value?: unknown;
13
+ message?: string | null;
14
+ result: boolean;
15
+ }
16
+ export interface AXValidationSummary {
17
+ result: boolean;
18
+ rules: AXValidationRuleResult[];
19
+ }
@@ -0,0 +1,13 @@
1
+ import { ModuleWithProviders } from '@angular/core';
2
+ import { AXValidationRegistryService } from './validation.service';
3
+ import { AXValidationRule } from './validation';
4
+ import * as i0 from "@angular/core";
5
+ export declare class AXValidationModule {
6
+ static forRoot(config?: {
7
+ validators?: AXValidationRule[];
8
+ }): ModuleWithProviders<AXValidationModule>;
9
+ constructor(pluginRegistry: AXValidationRegistryService);
10
+ static ɵfac: i0.ɵɵFactoryDeclaration<AXValidationModule, never>;
11
+ static ɵmod: i0.ɵɵNgModuleDeclaration<AXValidationModule, never, never, never>;
12
+ static ɵinj: i0.ɵɵInjectorDeclaration<AXValidationModule>;
13
+ }
@@ -0,0 +1,27 @@
1
+ import { AXValidationRule, AXValidationRuleOptions, AXValidationRuleOptionsMap, AXValidationRuleResult, AXValidationSummary } from "./validation";
2
+ import * as i0 from "@angular/core";
3
+ export declare class AXValidationRegistryService {
4
+ private plugins;
5
+ register(...plugin: AXValidationRule[]): void;
6
+ get validators(): AXValidationRule[];
7
+ static ɵfac: i0.ɵɵFactoryDeclaration<AXValidationRegistryService, never>;
8
+ static ɵprov: i0.ɵɵInjectableDeclaration<AXValidationRegistryService>;
9
+ }
10
+ export declare class AXValidationService {
11
+ private pluginRegistry;
12
+ constructor(pluginRegistry: AXValidationRegistryService);
13
+ validate(ruleName: string, value: unknown, options?: AXValidationRuleOptions): AXValidationRuleResult | Promise<AXValidationRuleResult>;
14
+ ruleFor(value: unknown): AXValidationRuleChain;
15
+ static ɵfac: i0.ɵɵFactoryDeclaration<AXValidationService, never>;
16
+ static ɵprov: i0.ɵɵInjectableDeclaration<AXValidationService>;
17
+ }
18
+ declare class AXValidationRuleChain {
19
+ private validationService;
20
+ private initialValue;
21
+ private rules;
22
+ private validationSummary;
23
+ constructor(validationService: AXValidationService, initialValue: unknown);
24
+ addRule<K extends keyof AXValidationRuleOptionsMap>(name: K, options?: AXValidationRuleOptionsMap[K]): AXValidationRuleChain;
25
+ validate(): Promise<AXValidationSummary>;
26
+ }
27
+ export {};