Debian Codegraph @

ent/schema/dsse.go

raw
1 // Copyright 2022 The Archivista Contributors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package schema
16
17 import (
18 "time"
19
20 "entgo.io/contrib/entgql"
21 "entgo.io/ent"
22 "entgo.io/ent/schema"
23 "entgo.io/ent/schema/edge"
24 "entgo.io/ent/schema/field"
25 "github.com/google/uuid"
26 )
27
28 // Dsse represents some metadata about an archived DSSE envelope
29 type Dsse struct {
30 ent.Schema
31 }
32
33 // Fields of the Statement.
34 func (Dsse) Fields() []ent.Field {
35 return []ent.Field{
36 field.UUID("id", uuid.UUID{}).Default(uuid.New).Immutable().Unique(),
37 field.Time("created_at").Default(time.Now).Immutable().Optional().Nillable().Annotations(entgql.OrderField("CREATED_AT")),
38 field.String("gitoid_sha256").NotEmpty().Unique(),
39 field.String("payload_type").NotEmpty(),
40 }
41 }
42
43 // Edges of the Statement.
44 func (Dsse) Edges() []ent.Edge {
45 return []ent.Edge{
46 edge.To("statement", Statement.Type).Unique(),
47 edge.To("signatures", Signature.Type),
48 edge.To("payload_digests", PayloadDigest.Type),
49 }
50 }
51
52 func (Dsse) Annotations() []schema.Annotation {
53 return []schema.Annotation{
54 entgql.RelayConnection(),
55 entgql.QueryField(),
56 }
57 }