generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
template.go
97 lines (89 loc) · 2.41 KB
/
template.go
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
87
88
89
90
91
92
93
94
95
96
97
package schema
import (
"entgo.io/contrib/entgql"
"entgo.io/contrib/entoas"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
"github.com/datumforge/entx"
emixin "github.com/datumforge/entx/mixin"
"github.com/ogen-go/ogen"
"github.com/datumforge/datum/internal/ent/customtypes"
"github.com/datumforge/datum/internal/ent/enums"
"github.com/datumforge/datum/internal/ent/mixin"
)
// Template holds the schema definition for the Template entity
type Template struct {
ent.Schema
}
// Mixin of the Template
func (Template) Mixin() []ent.Mixin {
return []ent.Mixin{
emixin.AuditMixin{},
mixin.SoftDeleteMixin{},
emixin.IDMixin{},
emixin.TagMixin{},
OrgOwnerMixin{
Ref: "templates",
},
}
}
// Fields of the Template
func (Template) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Comment("the name of the template").
NotEmpty().
Annotations(
entgql.OrderField("name"),
),
field.Enum("template_type").
Comment("the type of the template, either a provided template or an implementation (document)").
GoType(enums.DocumentType("")).
Default(string(enums.Document)),
field.String("description").
Comment("the description of the template").
Optional(),
field.JSON("jsonconfig", customtypes.JSONObject{}).
Comment("the jsonschema object of the template").
Annotations(
entgql.Type("JSON"),
entoas.Schema(ogen.String().AsArray()),
),
field.JSON("uischema", customtypes.JSONObject{}).
Comment("the uischema for the template to render in the UI").
Annotations(
entgql.Type("JSON"),
entoas.Schema(ogen.String().AsArray()),
).
Optional(),
}
}
// Edges of the Template
func (Template) Edges() []ent.Edge {
return []ent.Edge{
edge.To("documents", DocumentData.Type).
Annotations(
entx.CascadeAnnotationField("Template"),
),
}
}
// Indexes of the Template
func (Template) Indexes() []ent.Index {
return []ent.Index{
// names should be unique, but ignore deleted names
index.Fields("name", "owner_id", "template_type").
Unique().Annotations(entsql.IndexWhere("deleted_at is NULL")),
}
}
// Annotations of the Template
func (Template) Annotations() []schema.Annotation {
return []schema.Annotation{
entgql.RelayConnection(),
entgql.QueryField(),
entgql.Mutations(entgql.MutationCreate(), (entgql.MutationUpdate())),
}
}