@acorex/core 7.17.19 → 7.17.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/config/lib/configs.service.mjs +3 -3
- package/esm2022/dateTime/lib/calendar.service.mjs +3 -3
- package/esm2022/dateTime/lib/datetime-formatter.mjs +6 -6
- package/esm2022/dateTime/lib/datetime.class.mjs +6 -2
- package/esm2022/dateTime/lib/datetime.module.mjs +4 -4
- package/esm2022/dateTime/lib/datetime.pipe.mjs +3 -3
- package/esm2022/events/lib/event.service.mjs +3 -3
- package/esm2022/file/lib/file-size-formatter.mjs +3 -3
- package/esm2022/file/lib/file.module.mjs +4 -4
- package/esm2022/file/lib/file.service.mjs +3 -3
- package/esm2022/format/lib/format.module.mjs +4 -4
- package/esm2022/format/lib/format.pipe.mjs +3 -3
- package/esm2022/format/lib/format.service.mjs +6 -6
- package/esm2022/image/lib/image.service.mjs +3 -3
- package/esm2022/pipes/lib/safe/safe.pipe.mjs +3 -3
- package/esm2022/platform/lib/platform.service.mjs +3 -3
- package/esm2022/storage/cookie-storage.service.mjs +3 -3
- package/esm2022/storage/local-storage.service.mjs +3 -3
- package/esm2022/storage/session-storage.service.mjs +3 -3
- package/esm2022/translation/lib/translation.module.mjs +4 -4
- package/esm2022/translation/lib/translator.pipe.mjs +3 -3
- package/esm2022/utils/lib/auto-unsubscribe.mjs +3 -3
- package/esm2022/validation/acorex-core-validation.mjs +5 -0
- package/esm2022/validation/index.mjs +6 -0
- package/esm2022/validation/lib/regex-validator.mjs +17 -0
- package/esm2022/validation/lib/required-validator.mjs +24 -0
- package/esm2022/validation/lib/validation.mjs +2 -0
- package/esm2022/validation/lib/validation.module.mjs +37 -0
- package/esm2022/validation/lib/validation.service.mjs +71 -0
- package/fesm2022/acorex-core-config.mjs +3 -3
- package/fesm2022/acorex-core-dateTime.mjs +21 -17
- package/fesm2022/acorex-core-dateTime.mjs.map +1 -1
- package/fesm2022/acorex-core-events.mjs +3 -3
- package/fesm2022/acorex-core-file.mjs +10 -10
- package/fesm2022/acorex-core-format.mjs +13 -13
- package/fesm2022/acorex-core-image.mjs +3 -3
- package/fesm2022/acorex-core-pipes.mjs +3 -3
- package/fesm2022/acorex-core-platform.mjs +3 -3
- package/fesm2022/acorex-core-storage.mjs +9 -9
- package/fesm2022/acorex-core-translation.mjs +7 -7
- package/fesm2022/acorex-core-utils.mjs +3 -3
- package/fesm2022/acorex-core-validation.mjs +150 -0
- package/fesm2022/acorex-core-validation.mjs.map +1 -0
- package/package.json +7 -1
- package/validation/README.md +3 -0
- package/validation/index.d.ts +5 -0
- package/validation/lib/regex-validator.d.ts +8 -0
- package/validation/lib/required-validator.d.ts +7 -0
- package/validation/lib/validation.d.ts +18 -0
- package/validation/lib/validation.module.d.ts +13 -0
- 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.
|
213
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.
|
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.
|
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.
|
185
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.
|
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.
|
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.
|
211
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.
|
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.
|
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.
|
231
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.
|
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.
|
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.
|
51
|
-
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "17.0.
|
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.
|
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.
|
60
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.
|
61
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.
|
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.
|
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.
|
34
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.
|
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.
|
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,150 @@
|
|
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 AXRegexValidator {
|
7
|
+
get name() {
|
8
|
+
return 'regex';
|
9
|
+
}
|
10
|
+
validate(context) {
|
11
|
+
// Convert string pattern to RegExp if necessary
|
12
|
+
const regexPattern = typeof context.pattern === 'string' ? new RegExp(context.pattern) : context.pattern;
|
13
|
+
const isValid = regexPattern.test(context.value);
|
14
|
+
return {
|
15
|
+
name: this.name,
|
16
|
+
result: isValid,
|
17
|
+
message: isValid ? '' : `The value does not match the pattern ${regexPattern}.`,
|
18
|
+
value: context.value
|
19
|
+
};
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
class AXRequiredValidator {
|
24
|
+
get name() {
|
25
|
+
return 'required';
|
26
|
+
}
|
27
|
+
validate(context) {
|
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(context.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: context.value
|
42
|
+
};
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
class AXValidationRegistryService {
|
47
|
+
constructor() {
|
48
|
+
this.plugins = [];
|
49
|
+
}
|
50
|
+
register(...plugin) {
|
51
|
+
this.plugins.push(...plugin.filter(p => !this.plugins.some(c => c.name == p.name)));
|
52
|
+
}
|
53
|
+
get validators() {
|
54
|
+
return this.plugins;
|
55
|
+
}
|
56
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRegistryService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
57
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRegistryService, providedIn: 'root' }); }
|
58
|
+
}
|
59
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationRegistryService, decorators: [{
|
60
|
+
type: Injectable,
|
61
|
+
args: [{
|
62
|
+
providedIn: 'root'
|
63
|
+
}]
|
64
|
+
}] });
|
65
|
+
class AXValidationService {
|
66
|
+
constructor(pluginRegistry) {
|
67
|
+
this.pluginRegistry = pluginRegistry;
|
68
|
+
}
|
69
|
+
validate(name, context) {
|
70
|
+
const validator = this.pluginRegistry.validators.find((c) => c.name == name);
|
71
|
+
if (!validator) {
|
72
|
+
return {
|
73
|
+
name: name,
|
74
|
+
result: false,
|
75
|
+
message: AXTranslator.get('validation.messages.invalid-rull-name'),
|
76
|
+
value: context.value
|
77
|
+
};
|
78
|
+
}
|
79
|
+
return validator.validate(context);
|
80
|
+
}
|
81
|
+
chain(value) {
|
82
|
+
return new AXValidationRuleChain(this, value);
|
83
|
+
}
|
84
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationService, deps: [{ token: AXValidationRegistryService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
85
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationService, providedIn: 'root' }); }
|
86
|
+
}
|
87
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationService, decorators: [{
|
88
|
+
type: Injectable,
|
89
|
+
args: [{ providedIn: 'root' }]
|
90
|
+
}], ctorParameters: () => [{ type: AXValidationRegistryService }] });
|
91
|
+
class AXValidationRuleChain {
|
92
|
+
constructor(validationService, initialValue) {
|
93
|
+
this.validationService = validationService;
|
94
|
+
this.initialValue = initialValue;
|
95
|
+
this.rules = [];
|
96
|
+
this.validationSummary = { result: true, rules: [] };
|
97
|
+
}
|
98
|
+
addRule(name, context) {
|
99
|
+
this.rules.push({ name, context: { ...context, value: this.initialValue } });
|
100
|
+
return this;
|
101
|
+
}
|
102
|
+
async execute() {
|
103
|
+
for (const rule of this.rules) {
|
104
|
+
const result = await this.validationService.validate(rule.name, rule.context);
|
105
|
+
this.validationSummary.rules.push(result);
|
106
|
+
if (!result.result) {
|
107
|
+
this.validationSummary.result = false;
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return this.validationSummary;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
class AXValidationModule {
|
115
|
+
static forRoot(config) {
|
116
|
+
return {
|
117
|
+
ngModule: AXValidationModule,
|
118
|
+
providers: [
|
119
|
+
{
|
120
|
+
provide: APP_INITIALIZER,
|
121
|
+
useFactory: (pluginRegistry) => () => {
|
122
|
+
if (config?.validators?.length)
|
123
|
+
pluginRegistry.register(...config.validators);
|
124
|
+
},
|
125
|
+
deps: [AXValidationRegistryService],
|
126
|
+
multi: true
|
127
|
+
}
|
128
|
+
]
|
129
|
+
};
|
130
|
+
}
|
131
|
+
constructor(pluginRegistry) {
|
132
|
+
pluginRegistry.register(new AXRegexValidator(), new AXRequiredValidator());
|
133
|
+
}
|
134
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationModule, deps: [{ token: AXValidationRegistryService }], target: i0.ɵɵFactoryTarget.NgModule }); }
|
135
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.0.8", ngImport: i0, type: AXValidationModule }); }
|
136
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationModule }); }
|
137
|
+
}
|
138
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.0.8", ngImport: i0, type: AXValidationModule, decorators: [{
|
139
|
+
type: NgModule,
|
140
|
+
args: [{
|
141
|
+
imports: [],
|
142
|
+
}]
|
143
|
+
}], ctorParameters: () => [{ type: AXValidationRegistryService }] });
|
144
|
+
|
145
|
+
/**
|
146
|
+
* Generated bundle index. Do not edit.
|
147
|
+
*/
|
148
|
+
|
149
|
+
export { AXRegexValidator, AXRequiredValidator, AXValidationModule, AXValidationRegistryService, AXValidationService };
|
150
|
+
//# sourceMappingURL=acorex-core-validation.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"acorex-core-validation.mjs","sources":["../../../../libs/core/validation/src/lib/regex-validator.ts","../../../../libs/core/validation/src/lib/required-validator.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, AXValidationRuleResult } from \"./validation\";\n\nexport class AXRegexValidator implements AXValidationRule {\n\n get name(): string {\n return 'regex';\n }\n\n validate(context: { value: string, pattern: string | RegExp }): AXValidationRuleResult {\n // Convert string pattern to RegExp if necessary\n const regexPattern = typeof context.pattern === 'string' ? new RegExp(context.pattern) : context.pattern;\n\n const isValid = regexPattern.test(context.value);\n return {\n name: this.name,\n result: isValid,\n message: isValid ? '' : `The value does not match the pattern ${regexPattern}.`,\n value: context.value\n };\n }\n\n}","import { find, isArray, isEmpty, isNull, isNumber, isString, isUndefined } from \"lodash-es\";\nimport { AXValidationRule, AXValidationRuleResult } from \"./validation\";\n\nexport class AXRequiredValidator implements AXValidationRule {\n\n get name(): string {\n return 'required';\n }\n\n validate(context: { 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(context.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: context.value\n };\n }\n}","import { Injectable } from \"@angular/core\";\nimport { AXValidationRule, AXValidationContext, 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(name: string, context: AXValidationContext): AXValidationRuleResult | Promise<AXValidationRuleResult> {\n const validator = this.pluginRegistry.validators.find((c) => c.name == name);\n if (!validator) {\n return {\n name: name,\n result: false,\n message: AXTranslator.get('validation.messages.invalid-rull-name'),\n value: context.value\n };\n }\n return validator.validate(context);\n }\n\n\n chain(value: unknown) {\n return new AXValidationRuleChain(this, value);\n }\n}\n\nclass AXValidationRuleChain {\n private rules: { name: string, context: AXValidationContext }[] = [];\n private validationSummary: AXValidationSummary = { result: true, rules: [] };\n\n constructor(private validationService: AXValidationService, private initialValue: unknown) { }\n\n addRule(name: string, context?: Omit<AXValidationContext, 'value'>): AXValidationRuleChain {\n this.rules.push({ name, context: { ...context, value: this.initialValue } });\n return this;\n }\n\n async execute(): Promise<AXValidationSummary> {\n for (const rule of this.rules) {\n const result = await this.validationService.validate(rule.name, rule.context);\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 { AXRegexValidator } from './regex-validator';\nimport { AXRequiredValidator } from './required-validator';\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(new AXRegexValidator(), new AXRequiredValidator())\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["i1.AXValidationRegistryService"],"mappings":";;;;;MAEa,gBAAgB,CAAA;AAEzB,IAAA,IAAI,IAAI,GAAA;AACJ,QAAA,OAAO,OAAO,CAAC;KAClB;AAED,IAAA,QAAQ,CAAC,OAAoD,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,iBAAA;AACJ,aAAA;SACJ,CAAC;KACL;AAED,IAAA,WAAA,CAAY,cAA2C,EAAA;QACnD,cAAc,CAAC,QAAQ,CAAC,IAAI,gBAAgB,EAAE,EAAE,IAAI,mBAAmB,EAAE,CAAC,CAAA;KAC7E;8GArBQ,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;;;ACTD;;AAEG;;;;"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@acorex/core",
|
3
|
-
"version": "7.17.
|
3
|
+
"version": "7.17.21",
|
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,18 @@
|
|
1
|
+
export interface AXValidationContext {
|
2
|
+
value: unknown;
|
3
|
+
[key: string]: unknown;
|
4
|
+
}
|
5
|
+
export interface AXValidationRule {
|
6
|
+
get name(): string;
|
7
|
+
validate(context: AXValidationContext): AXValidationRuleResult | Promise<AXValidationRuleResult>;
|
8
|
+
}
|
9
|
+
export interface AXValidationRuleResult {
|
10
|
+
name: string;
|
11
|
+
value?: unknown;
|
12
|
+
message?: string;
|
13
|
+
result: boolean;
|
14
|
+
}
|
15
|
+
export interface AXValidationSummary {
|
16
|
+
result: boolean;
|
17
|
+
rules: AXValidationRuleResult[];
|
18
|
+
}
|
@@ -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, AXValidationContext, 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(name: string, context: AXValidationContext): AXValidationRuleResult | Promise<AXValidationRuleResult>;
|
14
|
+
chain(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(name: string, context?: Omit<AXValidationContext, 'value'>): AXValidationRuleChain;
|
25
|
+
execute(): Promise<AXValidationSummary>;
|
26
|
+
}
|
27
|
+
export {};
|