| 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 |
"entgo.io/ent" |
| 19 |
"entgo.io/ent/schema/edge" |
| 20 |
"entgo.io/ent/schema/field" |
| 21 |
"entgo.io/ent/schema/index" |
| 22 |
"github.com/google/uuid" |
| 23 |
) |
| 24 |
|
| 25 |
// PayloadDigest represents the digest of the payload of a DSSE envelope |
| 26 |
type PayloadDigest struct { |
| 27 |
ent.Schema |
| 28 |
} |
| 29 |
|
| 30 |
// Fields of the Digest. |
| 31 |
func (PayloadDigest) Fields() []ent.Field { |
| 32 |
return []ent.Field{ |
| 33 |
field.UUID("id", uuid.UUID{}).Default(uuid.New).Immutable().Unique(), |
| 34 |
field.String("algorithm").NotEmpty(), |
| 35 |
field.String("value").NotEmpty(), |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
// Edges of the Digest. |
| 40 |
func (PayloadDigest) Edges() []ent.Edge { |
| 41 |
return []ent.Edge{ |
| 42 |
edge.From("dsse", Dsse.Type). |
| 43 |
Ref("payload_digests"). |
| 44 |
Unique(), |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
func (PayloadDigest) Indexes() []ent.Index { |
| 49 |
return []ent.Index{ |
| 50 |
index.Fields("value"), |
| 51 |
} |
| 52 |
} |