/
enumtyperegistry.ts
38 lines (27 loc) · 1.55 KB
/
enumtyperegistry.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
import { getCustomAttribute, htmlEncode, isEnum, notifyError } from "../base";
import { EnumKeyAttribute } from "./attributes";
import { Exception } from "../q";
import { commonTypeRegistry } from "./commontyperegistry";
export namespace EnumTypeRegistry {
let registry = commonTypeRegistry(
isEnum,
type => getCustomAttribute(type, EnumKeyAttribute, false)?.value,null);
export function get(key: string): Function {
var type = registry.tryGet(key);
if (type)
return type;
var message = `Can't find "${htmlEncode(key)}" enum type!
If you have recently defined this enum type in server side code, make sure your project builds successfully and run "dotnet sergen t".
Also verify there is such an enum type under the project root namespace, and its namespace parts start with capital letters like MyProject.MyModule.MyEnum.
If using ES modules, make sure the enum type is registered with Serenity.registerEnum('MyProject.MyModule.MyDialog') with the full name of your enum type and "side-effect-import" this enum from the current "page.ts/grid.ts/dialog.ts file (import "./path/to/MyEnum.ts").
After applying fixes, build and run "node ./tsbuild.js" (or "tsc" if using namespaces) from the project folder.`;
notifyError(message.replace(/\r?\n\r?\n/g, '<br/><br/>'), '', { escapeHtml: false, timeOut: 5000 });
throw new Exception(message);
}
export function reset() {
registry.reset();
}
export function tryGet(key: string) {
return registry.tryGet(key);
}
}