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
|
module static-semantics/entities/generated-functions
imports
static-semantics/entities/annotations
static-semantics/types/built-ins
static-semantics/webdsl
static-semantics/webdsl-actions
static-semantics/webdsl-types
rules
/*
declare findEntity(<idType>) or loadEntity(<uuid>) based
on presence of `(id)` annotation and type
*/
defOk(, GeneratedDefinition(Generated(["loadOrFindEntity", entityName, loadName, findName, getUniqueName, isUniqueName, isUniqueIdName]))) :- { }
resolveType(s, entityName) == [(_, (_, t@ENTITY(_, s_ent)))],
declareLoadOrFindEntity(s, loadName, findName, getUniqueName, isUniqueName, isUniqueIdName, t, hasIdAnnotationB(s_ent)).
: scope * string * string * string * string * string * TYPE * BOOL
declareLoadOrFindEntity(, loadName, _, _, _, _, t, FALSE()) :-
declareFunction(s, loadName, GENERATED_ORIGIN(1), [uuid(s)], t).
declareLoadOrFindEntity(, _, findName, getUniqueName, isUniqueName, , , TRUE()) :- { }
bool == bool(s),
t == ENTITY(_, s_ent),
resolveAnnotationByAnno(s_ent, ID()) == [(_, (idName, _))],
idType == propertyType(s_ent, idName),
declareFunction(s, findName, GENERATED_ORIGIN(1), [idType], t),
declareFunction(s, getUniqueName, GENERATED_ORIGIN(1), [idType], t),
declareFunction(s, isUniqueName, GENERATED_ORIGIN(1), [t], bool),
declareFunction(s, isUniqueIdName, GENERATED_ORIGIN(1), [idType], bool),
declareFunction(s, isUniqueIdName, GENERATED_ORIGIN(2), [idType, t], bool).
rules
/*
declare findEntityByProperty and findEntityByPropertyLike if
the property is string-type compatible
*/
defOk(, GeneratedDefinition(Generated(["findEntityByProperty", entityName, propertyName, findByPropName, findByPropLikeName]))) :- { }
resolveType(s, entityName) == [(_, (_, entType@ENTITY(_, s_ent)))],
propType == propertyType(s_ent, propertyName),
declareFindEntityByProperty(s, findByPropName, findByPropLikeName, entType, propType, typeCompatibleB(propType, string(s))).
: scope * string * string * TYPE * TYPE * BOOL
declareFindEntityByProperty(_, _, _, _, _, FALSE()).
declareFindEntityByProperty(, findByPropName, findByPropLikeName, , , TRUE()) :-
declareFunction(s, findByPropName, PROP_ORIGIN(), [propType], LIST(entType)),
declareFunction(s, findByPropLikeName, PROP_ORIGIN(), [propType], LIST(entType)).
|