This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validators.ts
86 lines (76 loc) · 3.36 KB
/
validators.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { Service } from '../../../container';
import { Metadata, DecoratorType, ServiceArgumentsInternal } from '../../../decorators/module/module.interfaces';
@Service()
export class ModuleValidators {
validateEmpty(m, original: ServiceArgumentsInternal, type: DecoratorType) {
if (!m) {
const requiredType = type.charAt(0).toUpperCase() + type.slice(1);
throw new Error(`
${original.metadata.raw}
-> @Module: ${original.metadata.moduleName}
-> @Module hash: ${original.metadata.moduleHash}
--> Maybe you forgot to import some ${requiredType} inside ${original.metadata.moduleName} ?
Hint: run ts-lint again, looks like imported ${requiredType} is undefined or null inside ${original.metadata.moduleName}
`);
}
}
genericWrongPluggableError(m, original: ServiceArgumentsInternal, type: DecoratorType) {
if (m.metadata.type !== type) {
const moduleType = m.metadata.type.charAt(0).toUpperCase() + m.metadata.type.slice(1);
const requiredType = type.charAt(0).toUpperCase() + type.slice(1);
throw new Error(`
${original.metadata.raw}
-> @Module: '${original.metadata.moduleName}'
-> @Module hash: '${original.metadata.moduleHash}'
--> @${moduleType} '${m.metadata.moduleName}' provided, where expected class decorated with '@${requiredType}' instead,
-> @Hint: please provide class with @Service decorator or remove ${m.metadata.moduleName} class
`);
}
}
validateImports(m, original: ServiceArgumentsInternal) {
if (m.metadata.type !== 'module') {
throw new Error(`
${original.metadata.raw}
-> @Module: '${original.metadata.moduleName}'
-> @Module hash: '${original.metadata.moduleHash}'
--> @${m.metadata.type.charAt(0).toUpperCase() + m.metadata.type.slice(1)} '${m.originalName}' provided, where expected class decorated with '@Module' instead,
-> @Hint: please provide class with @Module decorator or remove ${m.originalName} from imports
`);
}
}
validateServices(m, original: ServiceArgumentsInternal) {
this.validateEmpty(m, original, 'service');
if (m.provide) {
return;
}
this.genericWrongPluggableError(m, original, 'service');
}
validatePlugin(m, original: ServiceArgumentsInternal) {
this.validateEmpty(m, original, 'plugin');
if (m.provide) {
return;
}
this.genericWrongPluggableError(m, original, 'plugin');
}
validateController(m, original: ServiceArgumentsInternal) {
this.validateEmpty(m, original, 'controller');
if (m.provide) {
return;
}
this.genericWrongPluggableError(m, original, 'controller');
}
validateEffect(m, original: ServiceArgumentsInternal) {
this.validateEmpty(m, original, 'effect');
if (m.provide) {
return;
}
this.genericWrongPluggableError(m, original, 'effect');
}
validateComponent(m, original: ServiceArgumentsInternal) {
this.validateEmpty(m, original, 'component');
if (m.provide) {
return;
}
this.genericWrongPluggableError(m, original, 'component');
}
}