Debian Codegraph @

ent/mutation.go

raw
1 // Code generated by ent, DO NOT EDIT.
2
3 package ent
4
5 import (
6 "context"
7 "errors"
8 "fmt"
9 "sync"
10 "time"
11
12 "entgo.io/ent"
13 "entgo.io/ent/dialect/sql"
14 "github.com/google/uuid"
15 "github.com/in-toto/archivista/ent/attestation"
16 "github.com/in-toto/archivista/ent/attestationcollection"
17 "github.com/in-toto/archivista/ent/attestationpolicy"
18 "github.com/in-toto/archivista/ent/dsse"
19 "github.com/in-toto/archivista/ent/payloaddigest"
20 "github.com/in-toto/archivista/ent/predicate"
21 "github.com/in-toto/archivista/ent/signature"
22 "github.com/in-toto/archivista/ent/statement"
23 "github.com/in-toto/archivista/ent/subject"
24 "github.com/in-toto/archivista/ent/subjectdigest"
25 "github.com/in-toto/archivista/ent/timestamp"
26 )
27
28 const (
29 // Operation types.
30 OpCreate = ent.OpCreate
31 OpDelete = ent.OpDelete
32 OpDeleteOne = ent.OpDeleteOne
33 OpUpdate = ent.OpUpdate
34 OpUpdateOne = ent.OpUpdateOne
35
36 // Node types.
37 TypeAttestation = "Attestation"
38 TypeAttestationCollection = "AttestationCollection"
39 TypeAttestationPolicy = "AttestationPolicy"
40 TypeDsse = "Dsse"
41 TypePayloadDigest = "PayloadDigest"
42 TypeSignature = "Signature"
43 TypeStatement = "Statement"
44 TypeSubject = "Subject"
45 TypeSubjectDigest = "SubjectDigest"
46 TypeTimestamp = "Timestamp"
47 )
48
49 // AttestationMutation represents an operation that mutates the Attestation nodes in the graph.
50 type AttestationMutation struct {
51 config
52 op Op
53 typ string
54 id *uuid.UUID
55 _type *string
56 clearedFields map[string]struct{}
57 attestation_collection *uuid.UUID
58 clearedattestation_collection bool
59 done bool
60 oldValue func(context.Context) (*Attestation, error)
61 predicates []predicate.Attestation
62 }
63
64 var _ ent.Mutation = (*AttestationMutation)(nil)
65
66 // attestationOption allows management of the mutation configuration using functional options.
67 type attestationOption func(*AttestationMutation)
68
69 // newAttestationMutation creates new mutation for the Attestation entity.
70 func newAttestationMutation(c config, op Op, opts ...attestationOption) *AttestationMutation {
71 m := &AttestationMutation{
72 config: c,
73 op: op,
74 typ: TypeAttestation,
75 clearedFields: make(map[string]struct{}),
76 }
77 for _, opt := range opts {
78 opt(m)
79 }
80 return m
81 }
82
83 // withAttestationID sets the ID field of the mutation.
84 func withAttestationID(id uuid.UUID) attestationOption {
85 return func(m *AttestationMutation) {
86 var (
87 err error
88 once sync.Once
89 value *Attestation
90 )
91 m.oldValue = func(ctx context.Context) (*Attestation, error) {
92 once.Do(func() {
93 if m.done {
94 err = errors.New("querying old values post mutation is not allowed")
95 } else {
96 value, err = m.Client().Attestation.Get(ctx, id)
97 }
98 })
99 return value, err
100 }
101 m.id = &id
102 }
103 }
104
105 // withAttestation sets the old Attestation of the mutation.
106 func withAttestation(node *Attestation) attestationOption {
107 return func(m *AttestationMutation) {
108 m.oldValue = func(context.Context) (*Attestation, error) {
109 return node, nil
110 }
111 m.id = &node.ID
112 }
113 }
114
115 // Client returns a new `ent.Client` from the mutation. If the mutation was
116 // executed in a transaction (ent.Tx), a transactional client is returned.
117 func (m AttestationMutation) Client() *Client {
118 client := &Client{config: m.config}
119 client.init()
120 return client
121 }
122
123 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
124 // it returns an error otherwise.
125 func (m AttestationMutation) Tx() (*Tx, error) {
126 if _, ok := m.driver.(*txDriver); !ok {
127 return nil, errors.New("ent: mutation is not running in a transaction")
128 }
129 tx := &Tx{config: m.config}
130 tx.init()
131 return tx, nil
132 }
133
134 // SetID sets the value of the id field. Note that this
135 // operation is only accepted on creation of Attestation entities.
136 func (m *AttestationMutation) SetID(id uuid.UUID) {
137 m.id = &id
138 }
139
140 // ID returns the ID value in the mutation. Note that the ID is only available
141 // if it was provided to the builder or after it was returned from the database.
142 func (m *AttestationMutation) ID() (id uuid.UUID, exists bool) {
143 if m.id == nil {
144 return
145 }
146 return *m.id, true
147 }
148
149 // IDs queries the database and returns the entity ids that match the mutation's predicate.
150 // That means, if the mutation is applied within a transaction with an isolation level such
151 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
152 // or updated by the mutation.
153 func (m *AttestationMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
154 switch {
155 case m.op.Is(OpUpdateOne | OpDeleteOne):
156 id, exists := m.ID()
157 if exists {
158 return []uuid.UUID{id}, nil
159 }
160 fallthrough
161 case m.op.Is(OpUpdate | OpDelete):
162 return m.Client().Attestation.Query().Where(m.predicates...).IDs(ctx)
163 default:
164 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
165 }
166 }
167
168 // SetType sets the "type" field.
169 func (m *AttestationMutation) SetType(s string) {
170 m._type = &s
171 }
172
173 // GetType returns the value of the "type" field in the mutation.
174 func (m *AttestationMutation) GetType() (r string, exists bool) {
175 v := m._type
176 if v == nil {
177 return
178 }
179 return *v, true
180 }
181
182 // OldType returns the old "type" field's value of the Attestation entity.
183 // If the Attestation object wasn't provided to the builder, the object is fetched from the database.
184 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
185 func (m *AttestationMutation) OldType(ctx context.Context) (v string, err error) {
186 if !m.op.Is(OpUpdateOne) {
187 return v, errors.New("OldType is only allowed on UpdateOne operations")
188 }
189 if m.id == nil || m.oldValue == nil {
190 return v, errors.New("OldType requires an ID field in the mutation")
191 }
192 oldValue, err := m.oldValue(ctx)
193 if err != nil {
194 return v, fmt.Errorf("querying old value for OldType: %w", err)
195 }
196 return oldValue.Type, nil
197 }
198
199 // ResetType resets all changes to the "type" field.
200 func (m *AttestationMutation) ResetType() {
201 m._type = nil
202 }
203
204 // SetAttestationCollectionID sets the "attestation_collection" edge to the AttestationCollection entity by id.
205 func (m *AttestationMutation) SetAttestationCollectionID(id uuid.UUID) {
206 m.attestation_collection = &id
207 }
208
209 // ClearAttestationCollection clears the "attestation_collection" edge to the AttestationCollection entity.
210 func (m *AttestationMutation) ClearAttestationCollection() {
211 m.clearedattestation_collection = true
212 }
213
214 // AttestationCollectionCleared reports if the "attestation_collection" edge to the AttestationCollection entity was cleared.
215 func (m *AttestationMutation) AttestationCollectionCleared() bool {
216 return m.clearedattestation_collection
217 }
218
219 // AttestationCollectionID returns the "attestation_collection" edge ID in the mutation.
220 func (m *AttestationMutation) AttestationCollectionID() (id uuid.UUID, exists bool) {
221 if m.attestation_collection != nil {
222 return *m.attestation_collection, true
223 }
224 return
225 }
226
227 // AttestationCollectionIDs returns the "attestation_collection" edge IDs in the mutation.
228 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
229 // AttestationCollectionID instead. It exists only for internal usage by the builders.
230 func (m *AttestationMutation) AttestationCollectionIDs() (ids []uuid.UUID) {
231 if id := m.attestation_collection; id != nil {
232 ids = append(ids, *id)
233 }
234 return
235 }
236
237 // ResetAttestationCollection resets all changes to the "attestation_collection" edge.
238 func (m *AttestationMutation) ResetAttestationCollection() {
239 m.attestation_collection = nil
240 m.clearedattestation_collection = false
241 }
242
243 // Where appends a list predicates to the AttestationMutation builder.
244 func (m *AttestationMutation) Where(ps ...predicate.Attestation) {
245 m.predicates = append(m.predicates, ps...)
246 }
247
248 // WhereP appends storage-level predicates to the AttestationMutation builder. Using this method,
249 // users can use type-assertion to append predicates that do not depend on any generated package.
250 func (m *AttestationMutation) WhereP(ps ...func(*sql.Selector)) {
251 p := make([]predicate.Attestation, len(ps))
252 for i := range ps {
253 p[i] = ps[i]
254 }
255 m.Where(p...)
256 }
257
258 // Op returns the operation name.
259 func (m *AttestationMutation) Op() Op {
260 return m.op
261 }
262
263 // SetOp allows setting the mutation operation.
264 func (m *AttestationMutation) SetOp(op Op) {
265 m.op = op
266 }
267
268 // Type returns the node type of this mutation (Attestation).
269 func (m *AttestationMutation) Type() string {
270 return m.typ
271 }
272
273 // Fields returns all fields that were changed during this mutation. Note that in
274 // order to get all numeric fields that were incremented/decremented, call
275 // AddedFields().
276 func (m *AttestationMutation) Fields() []string {
277 fields := make([]string, 0, 1)
278 if m._type != nil {
279 fields = append(fields, attestation.FieldType)
280 }
281 return fields
282 }
283
284 // Field returns the value of a field with the given name. The second boolean
285 // return value indicates that this field was not set, or was not defined in the
286 // schema.
287 func (m *AttestationMutation) Field(name string) (ent.Value, bool) {
288 switch name {
289 case attestation.FieldType:
290 return m.GetType()
291 }
292 return nil, false
293 }
294
295 // OldField returns the old value of the field from the database. An error is
296 // returned if the mutation operation is not UpdateOne, or the query to the
297 // database failed.
298 func (m *AttestationMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
299 switch name {
300 case attestation.FieldType:
301 return m.OldType(ctx)
302 }
303 return nil, fmt.Errorf("unknown Attestation field %s", name)
304 }
305
306 // SetField sets the value of a field with the given name. It returns an error if
307 // the field is not defined in the schema, or if the type mismatched the field
308 // type.
309 func (m *AttestationMutation) SetField(name string, value ent.Value) error {
310 switch name {
311 case attestation.FieldType:
312 v, ok := value.(string)
313 if !ok {
314 return fmt.Errorf("unexpected type %T for field %s", value, name)
315 }
316 m.SetType(v)
317 return nil
318 }
319 return fmt.Errorf("unknown Attestation field %s", name)
320 }
321
322 // AddedFields returns all numeric fields that were incremented/decremented during
323 // this mutation.
324 func (m *AttestationMutation) AddedFields() []string {
325 return nil
326 }
327
328 // AddedField returns the numeric value that was incremented/decremented on a field
329 // with the given name. The second boolean return value indicates that this field
330 // was not set, or was not defined in the schema.
331 func (m *AttestationMutation) AddedField(name string) (ent.Value, bool) {
332 return nil, false
333 }
334
335 // AddField adds the value to the field with the given name. It returns an error if
336 // the field is not defined in the schema, or if the type mismatched the field
337 // type.
338 func (m *AttestationMutation) AddField(name string, value ent.Value) error {
339 switch name {
340 }
341 return fmt.Errorf("unknown Attestation numeric field %s", name)
342 }
343
344 // ClearedFields returns all nullable fields that were cleared during this
345 // mutation.
346 func (m *AttestationMutation) ClearedFields() []string {
347 return nil
348 }
349
350 // FieldCleared returns a boolean indicating if a field with the given name was
351 // cleared in this mutation.
352 func (m *AttestationMutation) FieldCleared(name string) bool {
353 _, ok := m.clearedFields[name]
354 return ok
355 }
356
357 // ClearField clears the value of the field with the given name. It returns an
358 // error if the field is not defined in the schema.
359 func (m *AttestationMutation) ClearField(name string) error {
360 return fmt.Errorf("unknown Attestation nullable field %s", name)
361 }
362
363 // ResetField resets all changes in the mutation for the field with the given name.
364 // It returns an error if the field is not defined in the schema.
365 func (m *AttestationMutation) ResetField(name string) error {
366 switch name {
367 case attestation.FieldType:
368 m.ResetType()
369 return nil
370 }
371 return fmt.Errorf("unknown Attestation field %s", name)
372 }
373
374 // AddedEdges returns all edge names that were set/added in this mutation.
375 func (m *AttestationMutation) AddedEdges() []string {
376 edges := make([]string, 0, 1)
377 if m.attestation_collection != nil {
378 edges = append(edges, attestation.EdgeAttestationCollection)
379 }
380 return edges
381 }
382
383 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
384 // name in this mutation.
385 func (m *AttestationMutation) AddedIDs(name string) []ent.Value {
386 switch name {
387 case attestation.EdgeAttestationCollection:
388 if id := m.attestation_collection; id != nil {
389 return []ent.Value{*id}
390 }
391 }
392 return nil
393 }
394
395 // RemovedEdges returns all edge names that were removed in this mutation.
396 func (m *AttestationMutation) RemovedEdges() []string {
397 edges := make([]string, 0, 1)
398 return edges
399 }
400
401 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
402 // the given name in this mutation.
403 func (m *AttestationMutation) RemovedIDs(name string) []ent.Value {
404 return nil
405 }
406
407 // ClearedEdges returns all edge names that were cleared in this mutation.
408 func (m *AttestationMutation) ClearedEdges() []string {
409 edges := make([]string, 0, 1)
410 if m.clearedattestation_collection {
411 edges = append(edges, attestation.EdgeAttestationCollection)
412 }
413 return edges
414 }
415
416 // EdgeCleared returns a boolean which indicates if the edge with the given name
417 // was cleared in this mutation.
418 func (m *AttestationMutation) EdgeCleared(name string) bool {
419 switch name {
420 case attestation.EdgeAttestationCollection:
421 return m.clearedattestation_collection
422 }
423 return false
424 }
425
426 // ClearEdge clears the value of the edge with the given name. It returns an error
427 // if that edge is not defined in the schema.
428 func (m *AttestationMutation) ClearEdge(name string) error {
429 switch name {
430 case attestation.EdgeAttestationCollection:
431 m.ClearAttestationCollection()
432 return nil
433 }
434 return fmt.Errorf("unknown Attestation unique edge %s", name)
435 }
436
437 // ResetEdge resets all changes to the edge with the given name in this mutation.
438 // It returns an error if the edge is not defined in the schema.
439 func (m *AttestationMutation) ResetEdge(name string) error {
440 switch name {
441 case attestation.EdgeAttestationCollection:
442 m.ResetAttestationCollection()
443 return nil
444 }
445 return fmt.Errorf("unknown Attestation edge %s", name)
446 }
447
448 // AttestationCollectionMutation represents an operation that mutates the AttestationCollection nodes in the graph.
449 type AttestationCollectionMutation struct {
450 config
451 op Op
452 typ string
453 id *uuid.UUID
454 name *string
455 clearedFields map[string]struct{}
456 attestations map[uuid.UUID]struct{}
457 removedattestations map[uuid.UUID]struct{}
458 clearedattestations bool
459 statement *uuid.UUID
460 clearedstatement bool
461 done bool
462 oldValue func(context.Context) (*AttestationCollection, error)
463 predicates []predicate.AttestationCollection
464 }
465
466 var _ ent.Mutation = (*AttestationCollectionMutation)(nil)
467
468 // attestationcollectionOption allows management of the mutation configuration using functional options.
469 type attestationcollectionOption func(*AttestationCollectionMutation)
470
471 // newAttestationCollectionMutation creates new mutation for the AttestationCollection entity.
472 func newAttestationCollectionMutation(c config, op Op, opts ...attestationcollectionOption) *AttestationCollectionMutation {
473 m := &AttestationCollectionMutation{
474 config: c,
475 op: op,
476 typ: TypeAttestationCollection,
477 clearedFields: make(map[string]struct{}),
478 }
479 for _, opt := range opts {
480 opt(m)
481 }
482 return m
483 }
484
485 // withAttestationCollectionID sets the ID field of the mutation.
486 func withAttestationCollectionID(id uuid.UUID) attestationcollectionOption {
487 return func(m *AttestationCollectionMutation) {
488 var (
489 err error
490 once sync.Once
491 value *AttestationCollection
492 )
493 m.oldValue = func(ctx context.Context) (*AttestationCollection, error) {
494 once.Do(func() {
495 if m.done {
496 err = errors.New("querying old values post mutation is not allowed")
497 } else {
498 value, err = m.Client().AttestationCollection.Get(ctx, id)
499 }
500 })
501 return value, err
502 }
503 m.id = &id
504 }
505 }
506
507 // withAttestationCollection sets the old AttestationCollection of the mutation.
508 func withAttestationCollection(node *AttestationCollection) attestationcollectionOption {
509 return func(m *AttestationCollectionMutation) {
510 m.oldValue = func(context.Context) (*AttestationCollection, error) {
511 return node, nil
512 }
513 m.id = &node.ID
514 }
515 }
516
517 // Client returns a new `ent.Client` from the mutation. If the mutation was
518 // executed in a transaction (ent.Tx), a transactional client is returned.
519 func (m AttestationCollectionMutation) Client() *Client {
520 client := &Client{config: m.config}
521 client.init()
522 return client
523 }
524
525 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
526 // it returns an error otherwise.
527 func (m AttestationCollectionMutation) Tx() (*Tx, error) {
528 if _, ok := m.driver.(*txDriver); !ok {
529 return nil, errors.New("ent: mutation is not running in a transaction")
530 }
531 tx := &Tx{config: m.config}
532 tx.init()
533 return tx, nil
534 }
535
536 // SetID sets the value of the id field. Note that this
537 // operation is only accepted on creation of AttestationCollection entities.
538 func (m *AttestationCollectionMutation) SetID(id uuid.UUID) {
539 m.id = &id
540 }
541
542 // ID returns the ID value in the mutation. Note that the ID is only available
543 // if it was provided to the builder or after it was returned from the database.
544 func (m *AttestationCollectionMutation) ID() (id uuid.UUID, exists bool) {
545 if m.id == nil {
546 return
547 }
548 return *m.id, true
549 }
550
551 // IDs queries the database and returns the entity ids that match the mutation's predicate.
552 // That means, if the mutation is applied within a transaction with an isolation level such
553 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
554 // or updated by the mutation.
555 func (m *AttestationCollectionMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
556 switch {
557 case m.op.Is(OpUpdateOne | OpDeleteOne):
558 id, exists := m.ID()
559 if exists {
560 return []uuid.UUID{id}, nil
561 }
562 fallthrough
563 case m.op.Is(OpUpdate | OpDelete):
564 return m.Client().AttestationCollection.Query().Where(m.predicates...).IDs(ctx)
565 default:
566 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
567 }
568 }
569
570 // SetName sets the "name" field.
571 func (m *AttestationCollectionMutation) SetName(s string) {
572 m.name = &s
573 }
574
575 // Name returns the value of the "name" field in the mutation.
576 func (m *AttestationCollectionMutation) Name() (r string, exists bool) {
577 v := m.name
578 if v == nil {
579 return
580 }
581 return *v, true
582 }
583
584 // OldName returns the old "name" field's value of the AttestationCollection entity.
585 // If the AttestationCollection object wasn't provided to the builder, the object is fetched from the database.
586 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
587 func (m *AttestationCollectionMutation) OldName(ctx context.Context) (v string, err error) {
588 if !m.op.Is(OpUpdateOne) {
589 return v, errors.New("OldName is only allowed on UpdateOne operations")
590 }
591 if m.id == nil || m.oldValue == nil {
592 return v, errors.New("OldName requires an ID field in the mutation")
593 }
594 oldValue, err := m.oldValue(ctx)
595 if err != nil {
596 return v, fmt.Errorf("querying old value for OldName: %w", err)
597 }
598 return oldValue.Name, nil
599 }
600
601 // ResetName resets all changes to the "name" field.
602 func (m *AttestationCollectionMutation) ResetName() {
603 m.name = nil
604 }
605
606 // AddAttestationIDs adds the "attestations" edge to the Attestation entity by ids.
607 func (m *AttestationCollectionMutation) AddAttestationIDs(ids ...uuid.UUID) {
608 if m.attestations == nil {
609 m.attestations = make(map[uuid.UUID]struct{})
610 }
611 for i := range ids {
612 m.attestations[ids[i]] = struct{}{}
613 }
614 }
615
616 // ClearAttestations clears the "attestations" edge to the Attestation entity.
617 func (m *AttestationCollectionMutation) ClearAttestations() {
618 m.clearedattestations = true
619 }
620
621 // AttestationsCleared reports if the "attestations" edge to the Attestation entity was cleared.
622 func (m *AttestationCollectionMutation) AttestationsCleared() bool {
623 return m.clearedattestations
624 }
625
626 // RemoveAttestationIDs removes the "attestations" edge to the Attestation entity by IDs.
627 func (m *AttestationCollectionMutation) RemoveAttestationIDs(ids ...uuid.UUID) {
628 if m.removedattestations == nil {
629 m.removedattestations = make(map[uuid.UUID]struct{})
630 }
631 for i := range ids {
632 delete(m.attestations, ids[i])
633 m.removedattestations[ids[i]] = struct{}{}
634 }
635 }
636
637 // RemovedAttestations returns the removed IDs of the "attestations" edge to the Attestation entity.
638 func (m *AttestationCollectionMutation) RemovedAttestationsIDs() (ids []uuid.UUID) {
639 for id := range m.removedattestations {
640 ids = append(ids, id)
641 }
642 return
643 }
644
645 // AttestationsIDs returns the "attestations" edge IDs in the mutation.
646 func (m *AttestationCollectionMutation) AttestationsIDs() (ids []uuid.UUID) {
647 for id := range m.attestations {
648 ids = append(ids, id)
649 }
650 return
651 }
652
653 // ResetAttestations resets all changes to the "attestations" edge.
654 func (m *AttestationCollectionMutation) ResetAttestations() {
655 m.attestations = nil
656 m.clearedattestations = false
657 m.removedattestations = nil
658 }
659
660 // SetStatementID sets the "statement" edge to the Statement entity by id.
661 func (m *AttestationCollectionMutation) SetStatementID(id uuid.UUID) {
662 m.statement = &id
663 }
664
665 // ClearStatement clears the "statement" edge to the Statement entity.
666 func (m *AttestationCollectionMutation) ClearStatement() {
667 m.clearedstatement = true
668 }
669
670 // StatementCleared reports if the "statement" edge to the Statement entity was cleared.
671 func (m *AttestationCollectionMutation) StatementCleared() bool {
672 return m.clearedstatement
673 }
674
675 // StatementID returns the "statement" edge ID in the mutation.
676 func (m *AttestationCollectionMutation) StatementID() (id uuid.UUID, exists bool) {
677 if m.statement != nil {
678 return *m.statement, true
679 }
680 return
681 }
682
683 // StatementIDs returns the "statement" edge IDs in the mutation.
684 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
685 // StatementID instead. It exists only for internal usage by the builders.
686 func (m *AttestationCollectionMutation) StatementIDs() (ids []uuid.UUID) {
687 if id := m.statement; id != nil {
688 ids = append(ids, *id)
689 }
690 return
691 }
692
693 // ResetStatement resets all changes to the "statement" edge.
694 func (m *AttestationCollectionMutation) ResetStatement() {
695 m.statement = nil
696 m.clearedstatement = false
697 }
698
699 // Where appends a list predicates to the AttestationCollectionMutation builder.
700 func (m *AttestationCollectionMutation) Where(ps ...predicate.AttestationCollection) {
701 m.predicates = append(m.predicates, ps...)
702 }
703
704 // WhereP appends storage-level predicates to the AttestationCollectionMutation builder. Using this method,
705 // users can use type-assertion to append predicates that do not depend on any generated package.
706 func (m *AttestationCollectionMutation) WhereP(ps ...func(*sql.Selector)) {
707 p := make([]predicate.AttestationCollection, len(ps))
708 for i := range ps {
709 p[i] = ps[i]
710 }
711 m.Where(p...)
712 }
713
714 // Op returns the operation name.
715 func (m *AttestationCollectionMutation) Op() Op {
716 return m.op
717 }
718
719 // SetOp allows setting the mutation operation.
720 func (m *AttestationCollectionMutation) SetOp(op Op) {
721 m.op = op
722 }
723
724 // Type returns the node type of this mutation (AttestationCollection).
725 func (m *AttestationCollectionMutation) Type() string {
726 return m.typ
727 }
728
729 // Fields returns all fields that were changed during this mutation. Note that in
730 // order to get all numeric fields that were incremented/decremented, call
731 // AddedFields().
732 func (m *AttestationCollectionMutation) Fields() []string {
733 fields := make([]string, 0, 1)
734 if m.name != nil {
735 fields = append(fields, attestationcollection.FieldName)
736 }
737 return fields
738 }
739
740 // Field returns the value of a field with the given name. The second boolean
741 // return value indicates that this field was not set, or was not defined in the
742 // schema.
743 func (m *AttestationCollectionMutation) Field(name string) (ent.Value, bool) {
744 switch name {
745 case attestationcollection.FieldName:
746 return m.Name()
747 }
748 return nil, false
749 }
750
751 // OldField returns the old value of the field from the database. An error is
752 // returned if the mutation operation is not UpdateOne, or the query to the
753 // database failed.
754 func (m *AttestationCollectionMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
755 switch name {
756 case attestationcollection.FieldName:
757 return m.OldName(ctx)
758 }
759 return nil, fmt.Errorf("unknown AttestationCollection field %s", name)
760 }
761
762 // SetField sets the value of a field with the given name. It returns an error if
763 // the field is not defined in the schema, or if the type mismatched the field
764 // type.
765 func (m *AttestationCollectionMutation) SetField(name string, value ent.Value) error {
766 switch name {
767 case attestationcollection.FieldName:
768 v, ok := value.(string)
769 if !ok {
770 return fmt.Errorf("unexpected type %T for field %s", value, name)
771 }
772 m.SetName(v)
773 return nil
774 }
775 return fmt.Errorf("unknown AttestationCollection field %s", name)
776 }
777
778 // AddedFields returns all numeric fields that were incremented/decremented during
779 // this mutation.
780 func (m *AttestationCollectionMutation) AddedFields() []string {
781 return nil
782 }
783
784 // AddedField returns the numeric value that was incremented/decremented on a field
785 // with the given name. The second boolean return value indicates that this field
786 // was not set, or was not defined in the schema.
787 func (m *AttestationCollectionMutation) AddedField(name string) (ent.Value, bool) {
788 return nil, false
789 }
790
791 // AddField adds the value to the field with the given name. It returns an error if
792 // the field is not defined in the schema, or if the type mismatched the field
793 // type.
794 func (m *AttestationCollectionMutation) AddField(name string, value ent.Value) error {
795 switch name {
796 }
797 return fmt.Errorf("unknown AttestationCollection numeric field %s", name)
798 }
799
800 // ClearedFields returns all nullable fields that were cleared during this
801 // mutation.
802 func (m *AttestationCollectionMutation) ClearedFields() []string {
803 return nil
804 }
805
806 // FieldCleared returns a boolean indicating if a field with the given name was
807 // cleared in this mutation.
808 func (m *AttestationCollectionMutation) FieldCleared(name string) bool {
809 _, ok := m.clearedFields[name]
810 return ok
811 }
812
813 // ClearField clears the value of the field with the given name. It returns an
814 // error if the field is not defined in the schema.
815 func (m *AttestationCollectionMutation) ClearField(name string) error {
816 return fmt.Errorf("unknown AttestationCollection nullable field %s", name)
817 }
818
819 // ResetField resets all changes in the mutation for the field with the given name.
820 // It returns an error if the field is not defined in the schema.
821 func (m *AttestationCollectionMutation) ResetField(name string) error {
822 switch name {
823 case attestationcollection.FieldName:
824 m.ResetName()
825 return nil
826 }
827 return fmt.Errorf("unknown AttestationCollection field %s", name)
828 }
829
830 // AddedEdges returns all edge names that were set/added in this mutation.
831 func (m *AttestationCollectionMutation) AddedEdges() []string {
832 edges := make([]string, 0, 2)
833 if m.attestations != nil {
834 edges = append(edges, attestationcollection.EdgeAttestations)
835 }
836 if m.statement != nil {
837 edges = append(edges, attestationcollection.EdgeStatement)
838 }
839 return edges
840 }
841
842 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
843 // name in this mutation.
844 func (m *AttestationCollectionMutation) AddedIDs(name string) []ent.Value {
845 switch name {
846 case attestationcollection.EdgeAttestations:
847 ids := make([]ent.Value, 0, len(m.attestations))
848 for id := range m.attestations {
849 ids = append(ids, id)
850 }
851 return ids
852 case attestationcollection.EdgeStatement:
853 if id := m.statement; id != nil {
854 return []ent.Value{*id}
855 }
856 }
857 return nil
858 }
859
860 // RemovedEdges returns all edge names that were removed in this mutation.
861 func (m *AttestationCollectionMutation) RemovedEdges() []string {
862 edges := make([]string, 0, 2)
863 if m.removedattestations != nil {
864 edges = append(edges, attestationcollection.EdgeAttestations)
865 }
866 return edges
867 }
868
869 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
870 // the given name in this mutation.
871 func (m *AttestationCollectionMutation) RemovedIDs(name string) []ent.Value {
872 switch name {
873 case attestationcollection.EdgeAttestations:
874 ids := make([]ent.Value, 0, len(m.removedattestations))
875 for id := range m.removedattestations {
876 ids = append(ids, id)
877 }
878 return ids
879 }
880 return nil
881 }
882
883 // ClearedEdges returns all edge names that were cleared in this mutation.
884 func (m *AttestationCollectionMutation) ClearedEdges() []string {
885 edges := make([]string, 0, 2)
886 if m.clearedattestations {
887 edges = append(edges, attestationcollection.EdgeAttestations)
888 }
889 if m.clearedstatement {
890 edges = append(edges, attestationcollection.EdgeStatement)
891 }
892 return edges
893 }
894
895 // EdgeCleared returns a boolean which indicates if the edge with the given name
896 // was cleared in this mutation.
897 func (m *AttestationCollectionMutation) EdgeCleared(name string) bool {
898 switch name {
899 case attestationcollection.EdgeAttestations:
900 return m.clearedattestations
901 case attestationcollection.EdgeStatement:
902 return m.clearedstatement
903 }
904 return false
905 }
906
907 // ClearEdge clears the value of the edge with the given name. It returns an error
908 // if that edge is not defined in the schema.
909 func (m *AttestationCollectionMutation) ClearEdge(name string) error {
910 switch name {
911 case attestationcollection.EdgeStatement:
912 m.ClearStatement()
913 return nil
914 }
915 return fmt.Errorf("unknown AttestationCollection unique edge %s", name)
916 }
917
918 // ResetEdge resets all changes to the edge with the given name in this mutation.
919 // It returns an error if the edge is not defined in the schema.
920 func (m *AttestationCollectionMutation) ResetEdge(name string) error {
921 switch name {
922 case attestationcollection.EdgeAttestations:
923 m.ResetAttestations()
924 return nil
925 case attestationcollection.EdgeStatement:
926 m.ResetStatement()
927 return nil
928 }
929 return fmt.Errorf("unknown AttestationCollection edge %s", name)
930 }
931
932 // AttestationPolicyMutation represents an operation that mutates the AttestationPolicy nodes in the graph.
933 type AttestationPolicyMutation struct {
934 config
935 op Op
936 typ string
937 id *uuid.UUID
938 name *string
939 clearedFields map[string]struct{}
940 statement *uuid.UUID
941 clearedstatement bool
942 done bool
943 oldValue func(context.Context) (*AttestationPolicy, error)
944 predicates []predicate.AttestationPolicy
945 }
946
947 var _ ent.Mutation = (*AttestationPolicyMutation)(nil)
948
949 // attestationpolicyOption allows management of the mutation configuration using functional options.
950 type attestationpolicyOption func(*AttestationPolicyMutation)
951
952 // newAttestationPolicyMutation creates new mutation for the AttestationPolicy entity.
953 func newAttestationPolicyMutation(c config, op Op, opts ...attestationpolicyOption) *AttestationPolicyMutation {
954 m := &AttestationPolicyMutation{
955 config: c,
956 op: op,
957 typ: TypeAttestationPolicy,
958 clearedFields: make(map[string]struct{}),
959 }
960 for _, opt := range opts {
961 opt(m)
962 }
963 return m
964 }
965
966 // withAttestationPolicyID sets the ID field of the mutation.
967 func withAttestationPolicyID(id uuid.UUID) attestationpolicyOption {
968 return func(m *AttestationPolicyMutation) {
969 var (
970 err error
971 once sync.Once
972 value *AttestationPolicy
973 )
974 m.oldValue = func(ctx context.Context) (*AttestationPolicy, error) {
975 once.Do(func() {
976 if m.done {
977 err = errors.New("querying old values post mutation is not allowed")
978 } else {
979 value, err = m.Client().AttestationPolicy.Get(ctx, id)
980 }
981 })
982 return value, err
983 }
984 m.id = &id
985 }
986 }
987
988 // withAttestationPolicy sets the old AttestationPolicy of the mutation.
989 func withAttestationPolicy(node *AttestationPolicy) attestationpolicyOption {
990 return func(m *AttestationPolicyMutation) {
991 m.oldValue = func(context.Context) (*AttestationPolicy, error) {
992 return node, nil
993 }
994 m.id = &node.ID
995 }
996 }
997
998 // Client returns a new `ent.Client` from the mutation. If the mutation was
999 // executed in a transaction (ent.Tx), a transactional client is returned.
1000 func (m AttestationPolicyMutation) Client() *Client {
1001 client := &Client{config: m.config}
1002 client.init()
1003 return client
1004 }
1005
1006 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
1007 // it returns an error otherwise.
1008 func (m AttestationPolicyMutation) Tx() (*Tx, error) {
1009 if _, ok := m.driver.(*txDriver); !ok {
1010 return nil, errors.New("ent: mutation is not running in a transaction")
1011 }
1012 tx := &Tx{config: m.config}
1013 tx.init()
1014 return tx, nil
1015 }
1016
1017 // SetID sets the value of the id field. Note that this
1018 // operation is only accepted on creation of AttestationPolicy entities.
1019 func (m *AttestationPolicyMutation) SetID(id uuid.UUID) {
1020 m.id = &id
1021 }
1022
1023 // ID returns the ID value in the mutation. Note that the ID is only available
1024 // if it was provided to the builder or after it was returned from the database.
1025 func (m *AttestationPolicyMutation) ID() (id uuid.UUID, exists bool) {
1026 if m.id == nil {
1027 return
1028 }
1029 return *m.id, true
1030 }
1031
1032 // IDs queries the database and returns the entity ids that match the mutation's predicate.
1033 // That means, if the mutation is applied within a transaction with an isolation level such
1034 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
1035 // or updated by the mutation.
1036 func (m *AttestationPolicyMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
1037 switch {
1038 case m.op.Is(OpUpdateOne | OpDeleteOne):
1039 id, exists := m.ID()
1040 if exists {
1041 return []uuid.UUID{id}, nil
1042 }
1043 fallthrough
1044 case m.op.Is(OpUpdate | OpDelete):
1045 return m.Client().AttestationPolicy.Query().Where(m.predicates...).IDs(ctx)
1046 default:
1047 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
1048 }
1049 }
1050
1051 // SetName sets the "name" field.
1052 func (m *AttestationPolicyMutation) SetName(s string) {
1053 m.name = &s
1054 }
1055
1056 // Name returns the value of the "name" field in the mutation.
1057 func (m *AttestationPolicyMutation) Name() (r string, exists bool) {
1058 v := m.name
1059 if v == nil {
1060 return
1061 }
1062 return *v, true
1063 }
1064
1065 // OldName returns the old "name" field's value of the AttestationPolicy entity.
1066 // If the AttestationPolicy object wasn't provided to the builder, the object is fetched from the database.
1067 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
1068 func (m *AttestationPolicyMutation) OldName(ctx context.Context) (v string, err error) {
1069 if !m.op.Is(OpUpdateOne) {
1070 return v, errors.New("OldName is only allowed on UpdateOne operations")
1071 }
1072 if m.id == nil || m.oldValue == nil {
1073 return v, errors.New("OldName requires an ID field in the mutation")
1074 }
1075 oldValue, err := m.oldValue(ctx)
1076 if err != nil {
1077 return v, fmt.Errorf("querying old value for OldName: %w", err)
1078 }
1079 return oldValue.Name, nil
1080 }
1081
1082 // ResetName resets all changes to the "name" field.
1083 func (m *AttestationPolicyMutation) ResetName() {
1084 m.name = nil
1085 }
1086
1087 // SetStatementID sets the "statement" edge to the Statement entity by id.
1088 func (m *AttestationPolicyMutation) SetStatementID(id uuid.UUID) {
1089 m.statement = &id
1090 }
1091
1092 // ClearStatement clears the "statement" edge to the Statement entity.
1093 func (m *AttestationPolicyMutation) ClearStatement() {
1094 m.clearedstatement = true
1095 }
1096
1097 // StatementCleared reports if the "statement" edge to the Statement entity was cleared.
1098 func (m *AttestationPolicyMutation) StatementCleared() bool {
1099 return m.clearedstatement
1100 }
1101
1102 // StatementID returns the "statement" edge ID in the mutation.
1103 func (m *AttestationPolicyMutation) StatementID() (id uuid.UUID, exists bool) {
1104 if m.statement != nil {
1105 return *m.statement, true
1106 }
1107 return
1108 }
1109
1110 // StatementIDs returns the "statement" edge IDs in the mutation.
1111 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
1112 // StatementID instead. It exists only for internal usage by the builders.
1113 func (m *AttestationPolicyMutation) StatementIDs() (ids []uuid.UUID) {
1114 if id := m.statement; id != nil {
1115 ids = append(ids, *id)
1116 }
1117 return
1118 }
1119
1120 // ResetStatement resets all changes to the "statement" edge.
1121 func (m *AttestationPolicyMutation) ResetStatement() {
1122 m.statement = nil
1123 m.clearedstatement = false
1124 }
1125
1126 // Where appends a list predicates to the AttestationPolicyMutation builder.
1127 func (m *AttestationPolicyMutation) Where(ps ...predicate.AttestationPolicy) {
1128 m.predicates = append(m.predicates, ps...)
1129 }
1130
1131 // WhereP appends storage-level predicates to the AttestationPolicyMutation builder. Using this method,
1132 // users can use type-assertion to append predicates that do not depend on any generated package.
1133 func (m *AttestationPolicyMutation) WhereP(ps ...func(*sql.Selector)) {
1134 p := make([]predicate.AttestationPolicy, len(ps))
1135 for i := range ps {
1136 p[i] = ps[i]
1137 }
1138 m.Where(p...)
1139 }
1140
1141 // Op returns the operation name.
1142 func (m *AttestationPolicyMutation) Op() Op {
1143 return m.op
1144 }
1145
1146 // SetOp allows setting the mutation operation.
1147 func (m *AttestationPolicyMutation) SetOp(op Op) {
1148 m.op = op
1149 }
1150
1151 // Type returns the node type of this mutation (AttestationPolicy).
1152 func (m *AttestationPolicyMutation) Type() string {
1153 return m.typ
1154 }
1155
1156 // Fields returns all fields that were changed during this mutation. Note that in
1157 // order to get all numeric fields that were incremented/decremented, call
1158 // AddedFields().
1159 func (m *AttestationPolicyMutation) Fields() []string {
1160 fields := make([]string, 0, 1)
1161 if m.name != nil {
1162 fields = append(fields, attestationpolicy.FieldName)
1163 }
1164 return fields
1165 }
1166
1167 // Field returns the value of a field with the given name. The second boolean
1168 // return value indicates that this field was not set, or was not defined in the
1169 // schema.
1170 func (m *AttestationPolicyMutation) Field(name string) (ent.Value, bool) {
1171 switch name {
1172 case attestationpolicy.FieldName:
1173 return m.Name()
1174 }
1175 return nil, false
1176 }
1177
1178 // OldField returns the old value of the field from the database. An error is
1179 // returned if the mutation operation is not UpdateOne, or the query to the
1180 // database failed.
1181 func (m *AttestationPolicyMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
1182 switch name {
1183 case attestationpolicy.FieldName:
1184 return m.OldName(ctx)
1185 }
1186 return nil, fmt.Errorf("unknown AttestationPolicy field %s", name)
1187 }
1188
1189 // SetField sets the value of a field with the given name. It returns an error if
1190 // the field is not defined in the schema, or if the type mismatched the field
1191 // type.
1192 func (m *AttestationPolicyMutation) SetField(name string, value ent.Value) error {
1193 switch name {
1194 case attestationpolicy.FieldName:
1195 v, ok := value.(string)
1196 if !ok {
1197 return fmt.Errorf("unexpected type %T for field %s", value, name)
1198 }
1199 m.SetName(v)
1200 return nil
1201 }
1202 return fmt.Errorf("unknown AttestationPolicy field %s", name)
1203 }
1204
1205 // AddedFields returns all numeric fields that were incremented/decremented during
1206 // this mutation.
1207 func (m *AttestationPolicyMutation) AddedFields() []string {
1208 return nil
1209 }
1210
1211 // AddedField returns the numeric value that was incremented/decremented on a field
1212 // with the given name. The second boolean return value indicates that this field
1213 // was not set, or was not defined in the schema.
1214 func (m *AttestationPolicyMutation) AddedField(name string) (ent.Value, bool) {
1215 return nil, false
1216 }
1217
1218 // AddField adds the value to the field with the given name. It returns an error if
1219 // the field is not defined in the schema, or if the type mismatched the field
1220 // type.
1221 func (m *AttestationPolicyMutation) AddField(name string, value ent.Value) error {
1222 switch name {
1223 }
1224 return fmt.Errorf("unknown AttestationPolicy numeric field %s", name)
1225 }
1226
1227 // ClearedFields returns all nullable fields that were cleared during this
1228 // mutation.
1229 func (m *AttestationPolicyMutation) ClearedFields() []string {
1230 return nil
1231 }
1232
1233 // FieldCleared returns a boolean indicating if a field with the given name was
1234 // cleared in this mutation.
1235 func (m *AttestationPolicyMutation) FieldCleared(name string) bool {
1236 _, ok := m.clearedFields[name]
1237 return ok
1238 }
1239
1240 // ClearField clears the value of the field with the given name. It returns an
1241 // error if the field is not defined in the schema.
1242 func (m *AttestationPolicyMutation) ClearField(name string) error {
1243 return fmt.Errorf("unknown AttestationPolicy nullable field %s", name)
1244 }
1245
1246 // ResetField resets all changes in the mutation for the field with the given name.
1247 // It returns an error if the field is not defined in the schema.
1248 func (m *AttestationPolicyMutation) ResetField(name string) error {
1249 switch name {
1250 case attestationpolicy.FieldName:
1251 m.ResetName()
1252 return nil
1253 }
1254 return fmt.Errorf("unknown AttestationPolicy field %s", name)
1255 }
1256
1257 // AddedEdges returns all edge names that were set/added in this mutation.
1258 func (m *AttestationPolicyMutation) AddedEdges() []string {
1259 edges := make([]string, 0, 1)
1260 if m.statement != nil {
1261 edges = append(edges, attestationpolicy.EdgeStatement)
1262 }
1263 return edges
1264 }
1265
1266 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
1267 // name in this mutation.
1268 func (m *AttestationPolicyMutation) AddedIDs(name string) []ent.Value {
1269 switch name {
1270 case attestationpolicy.EdgeStatement:
1271 if id := m.statement; id != nil {
1272 return []ent.Value{*id}
1273 }
1274 }
1275 return nil
1276 }
1277
1278 // RemovedEdges returns all edge names that were removed in this mutation.
1279 func (m *AttestationPolicyMutation) RemovedEdges() []string {
1280 edges := make([]string, 0, 1)
1281 return edges
1282 }
1283
1284 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
1285 // the given name in this mutation.
1286 func (m *AttestationPolicyMutation) RemovedIDs(name string) []ent.Value {
1287 return nil
1288 }
1289
1290 // ClearedEdges returns all edge names that were cleared in this mutation.
1291 func (m *AttestationPolicyMutation) ClearedEdges() []string {
1292 edges := make([]string, 0, 1)
1293 if m.clearedstatement {
1294 edges = append(edges, attestationpolicy.EdgeStatement)
1295 }
1296 return edges
1297 }
1298
1299 // EdgeCleared returns a boolean which indicates if the edge with the given name
1300 // was cleared in this mutation.
1301 func (m *AttestationPolicyMutation) EdgeCleared(name string) bool {
1302 switch name {
1303 case attestationpolicy.EdgeStatement:
1304 return m.clearedstatement
1305 }
1306 return false
1307 }
1308
1309 // ClearEdge clears the value of the edge with the given name. It returns an error
1310 // if that edge is not defined in the schema.
1311 func (m *AttestationPolicyMutation) ClearEdge(name string) error {
1312 switch name {
1313 case attestationpolicy.EdgeStatement:
1314 m.ClearStatement()
1315 return nil
1316 }
1317 return fmt.Errorf("unknown AttestationPolicy unique edge %s", name)
1318 }
1319
1320 // ResetEdge resets all changes to the edge with the given name in this mutation.
1321 // It returns an error if the edge is not defined in the schema.
1322 func (m *AttestationPolicyMutation) ResetEdge(name string) error {
1323 switch name {
1324 case attestationpolicy.EdgeStatement:
1325 m.ResetStatement()
1326 return nil
1327 }
1328 return fmt.Errorf("unknown AttestationPolicy edge %s", name)
1329 }
1330
1331 // DsseMutation represents an operation that mutates the Dsse nodes in the graph.
1332 type DsseMutation struct {
1333 config
1334 op Op
1335 typ string
1336 id *uuid.UUID
1337 created_at *time.Time
1338 gitoid_sha256 *string
1339 payload_type *string
1340 clearedFields map[string]struct{}
1341 statement *uuid.UUID
1342 clearedstatement bool
1343 signatures map[uuid.UUID]struct{}
1344 removedsignatures map[uuid.UUID]struct{}
1345 clearedsignatures bool
1346 payload_digests map[uuid.UUID]struct{}
1347 removedpayload_digests map[uuid.UUID]struct{}
1348 clearedpayload_digests bool
1349 done bool
1350 oldValue func(context.Context) (*Dsse, error)
1351 predicates []predicate.Dsse
1352 }
1353
1354 var _ ent.Mutation = (*DsseMutation)(nil)
1355
1356 // dsseOption allows management of the mutation configuration using functional options.
1357 type dsseOption func(*DsseMutation)
1358
1359 // newDsseMutation creates new mutation for the Dsse entity.
1360 func newDsseMutation(c config, op Op, opts ...dsseOption) *DsseMutation {
1361 m := &DsseMutation{
1362 config: c,
1363 op: op,
1364 typ: TypeDsse,
1365 clearedFields: make(map[string]struct{}),
1366 }
1367 for _, opt := range opts {
1368 opt(m)
1369 }
1370 return m
1371 }
1372
1373 // withDsseID sets the ID field of the mutation.
1374 func withDsseID(id uuid.UUID) dsseOption {
1375 return func(m *DsseMutation) {
1376 var (
1377 err error
1378 once sync.Once
1379 value *Dsse
1380 )
1381 m.oldValue = func(ctx context.Context) (*Dsse, error) {
1382 once.Do(func() {
1383 if m.done {
1384 err = errors.New("querying old values post mutation is not allowed")
1385 } else {
1386 value, err = m.Client().Dsse.Get(ctx, id)
1387 }
1388 })
1389 return value, err
1390 }
1391 m.id = &id
1392 }
1393 }
1394
1395 // withDsse sets the old Dsse of the mutation.
1396 func withDsse(node *Dsse) dsseOption {
1397 return func(m *DsseMutation) {
1398 m.oldValue = func(context.Context) (*Dsse, error) {
1399 return node, nil
1400 }
1401 m.id = &node.ID
1402 }
1403 }
1404
1405 // Client returns a new `ent.Client` from the mutation. If the mutation was
1406 // executed in a transaction (ent.Tx), a transactional client is returned.
1407 func (m DsseMutation) Client() *Client {
1408 client := &Client{config: m.config}
1409 client.init()
1410 return client
1411 }
1412
1413 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
1414 // it returns an error otherwise.
1415 func (m DsseMutation) Tx() (*Tx, error) {
1416 if _, ok := m.driver.(*txDriver); !ok {
1417 return nil, errors.New("ent: mutation is not running in a transaction")
1418 }
1419 tx := &Tx{config: m.config}
1420 tx.init()
1421 return tx, nil
1422 }
1423
1424 // SetID sets the value of the id field. Note that this
1425 // operation is only accepted on creation of Dsse entities.
1426 func (m *DsseMutation) SetID(id uuid.UUID) {
1427 m.id = &id
1428 }
1429
1430 // ID returns the ID value in the mutation. Note that the ID is only available
1431 // if it was provided to the builder or after it was returned from the database.
1432 func (m *DsseMutation) ID() (id uuid.UUID, exists bool) {
1433 if m.id == nil {
1434 return
1435 }
1436 return *m.id, true
1437 }
1438
1439 // IDs queries the database and returns the entity ids that match the mutation's predicate.
1440 // That means, if the mutation is applied within a transaction with an isolation level such
1441 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
1442 // or updated by the mutation.
1443 func (m *DsseMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
1444 switch {
1445 case m.op.Is(OpUpdateOne | OpDeleteOne):
1446 id, exists := m.ID()
1447 if exists {
1448 return []uuid.UUID{id}, nil
1449 }
1450 fallthrough
1451 case m.op.Is(OpUpdate | OpDelete):
1452 return m.Client().Dsse.Query().Where(m.predicates...).IDs(ctx)
1453 default:
1454 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
1455 }
1456 }
1457
1458 // SetCreatedAt sets the "created_at" field.
1459 func (m *DsseMutation) SetCreatedAt(t time.Time) {
1460 m.created_at = &t
1461 }
1462
1463 // CreatedAt returns the value of the "created_at" field in the mutation.
1464 func (m *DsseMutation) CreatedAt() (r time.Time, exists bool) {
1465 v := m.created_at
1466 if v == nil {
1467 return
1468 }
1469 return *v, true
1470 }
1471
1472 // OldCreatedAt returns the old "created_at" field's value of the Dsse entity.
1473 // If the Dsse object wasn't provided to the builder, the object is fetched from the database.
1474 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
1475 func (m *DsseMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
1476 if !m.op.Is(OpUpdateOne) {
1477 return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
1478 }
1479 if m.id == nil || m.oldValue == nil {
1480 return v, errors.New("OldCreatedAt requires an ID field in the mutation")
1481 }
1482 oldValue, err := m.oldValue(ctx)
1483 if err != nil {
1484 return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
1485 }
1486 return oldValue.CreatedAt, nil
1487 }
1488
1489 // ClearCreatedAt clears the value of the "created_at" field.
1490 func (m *DsseMutation) ClearCreatedAt() {
1491 m.created_at = nil
1492 m.clearedFields[dsse.FieldCreatedAt] = struct{}{}
1493 }
1494
1495 // CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
1496 func (m *DsseMutation) CreatedAtCleared() bool {
1497 _, ok := m.clearedFields[dsse.FieldCreatedAt]
1498 return ok
1499 }
1500
1501 // ResetCreatedAt resets all changes to the "created_at" field.
1502 func (m *DsseMutation) ResetCreatedAt() {
1503 m.created_at = nil
1504 delete(m.clearedFields, dsse.FieldCreatedAt)
1505 }
1506
1507 // SetGitoidSha256 sets the "gitoid_sha256" field.
1508 func (m *DsseMutation) SetGitoidSha256(s string) {
1509 m.gitoid_sha256 = &s
1510 }
1511
1512 // GitoidSha256 returns the value of the "gitoid_sha256" field in the mutation.
1513 func (m *DsseMutation) GitoidSha256() (r string, exists bool) {
1514 v := m.gitoid_sha256
1515 if v == nil {
1516 return
1517 }
1518 return *v, true
1519 }
1520
1521 // OldGitoidSha256 returns the old "gitoid_sha256" field's value of the Dsse entity.
1522 // If the Dsse object wasn't provided to the builder, the object is fetched from the database.
1523 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
1524 func (m *DsseMutation) OldGitoidSha256(ctx context.Context) (v string, err error) {
1525 if !m.op.Is(OpUpdateOne) {
1526 return v, errors.New("OldGitoidSha256 is only allowed on UpdateOne operations")
1527 }
1528 if m.id == nil || m.oldValue == nil {
1529 return v, errors.New("OldGitoidSha256 requires an ID field in the mutation")
1530 }
1531 oldValue, err := m.oldValue(ctx)
1532 if err != nil {
1533 return v, fmt.Errorf("querying old value for OldGitoidSha256: %w", err)
1534 }
1535 return oldValue.GitoidSha256, nil
1536 }
1537
1538 // ResetGitoidSha256 resets all changes to the "gitoid_sha256" field.
1539 func (m *DsseMutation) ResetGitoidSha256() {
1540 m.gitoid_sha256 = nil
1541 }
1542
1543 // SetPayloadType sets the "payload_type" field.
1544 func (m *DsseMutation) SetPayloadType(s string) {
1545 m.payload_type = &s
1546 }
1547
1548 // PayloadType returns the value of the "payload_type" field in the mutation.
1549 func (m *DsseMutation) PayloadType() (r string, exists bool) {
1550 v := m.payload_type
1551 if v == nil {
1552 return
1553 }
1554 return *v, true
1555 }
1556
1557 // OldPayloadType returns the old "payload_type" field's value of the Dsse entity.
1558 // If the Dsse object wasn't provided to the builder, the object is fetched from the database.
1559 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
1560 func (m *DsseMutation) OldPayloadType(ctx context.Context) (v string, err error) {
1561 if !m.op.Is(OpUpdateOne) {
1562 return v, errors.New("OldPayloadType is only allowed on UpdateOne operations")
1563 }
1564 if m.id == nil || m.oldValue == nil {
1565 return v, errors.New("OldPayloadType requires an ID field in the mutation")
1566 }
1567 oldValue, err := m.oldValue(ctx)
1568 if err != nil {
1569 return v, fmt.Errorf("querying old value for OldPayloadType: %w", err)
1570 }
1571 return oldValue.PayloadType, nil
1572 }
1573
1574 // ResetPayloadType resets all changes to the "payload_type" field.
1575 func (m *DsseMutation) ResetPayloadType() {
1576 m.payload_type = nil
1577 }
1578
1579 // SetStatementID sets the "statement" edge to the Statement entity by id.
1580 func (m *DsseMutation) SetStatementID(id uuid.UUID) {
1581 m.statement = &id
1582 }
1583
1584 // ClearStatement clears the "statement" edge to the Statement entity.
1585 func (m *DsseMutation) ClearStatement() {
1586 m.clearedstatement = true
1587 }
1588
1589 // StatementCleared reports if the "statement" edge to the Statement entity was cleared.
1590 func (m *DsseMutation) StatementCleared() bool {
1591 return m.clearedstatement
1592 }
1593
1594 // StatementID returns the "statement" edge ID in the mutation.
1595 func (m *DsseMutation) StatementID() (id uuid.UUID, exists bool) {
1596 if m.statement != nil {
1597 return *m.statement, true
1598 }
1599 return
1600 }
1601
1602 // StatementIDs returns the "statement" edge IDs in the mutation.
1603 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
1604 // StatementID instead. It exists only for internal usage by the builders.
1605 func (m *DsseMutation) StatementIDs() (ids []uuid.UUID) {
1606 if id := m.statement; id != nil {
1607 ids = append(ids, *id)
1608 }
1609 return
1610 }
1611
1612 // ResetStatement resets all changes to the "statement" edge.
1613 func (m *DsseMutation) ResetStatement() {
1614 m.statement = nil
1615 m.clearedstatement = false
1616 }
1617
1618 // AddSignatureIDs adds the "signatures" edge to the Signature entity by ids.
1619 func (m *DsseMutation) AddSignatureIDs(ids ...uuid.UUID) {
1620 if m.signatures == nil {
1621 m.signatures = make(map[uuid.UUID]struct{})
1622 }
1623 for i := range ids {
1624 m.signatures[ids[i]] = struct{}{}
1625 }
1626 }
1627
1628 // ClearSignatures clears the "signatures" edge to the Signature entity.
1629 func (m *DsseMutation) ClearSignatures() {
1630 m.clearedsignatures = true
1631 }
1632
1633 // SignaturesCleared reports if the "signatures" edge to the Signature entity was cleared.
1634 func (m *DsseMutation) SignaturesCleared() bool {
1635 return m.clearedsignatures
1636 }
1637
1638 // RemoveSignatureIDs removes the "signatures" edge to the Signature entity by IDs.
1639 func (m *DsseMutation) RemoveSignatureIDs(ids ...uuid.UUID) {
1640 if m.removedsignatures == nil {
1641 m.removedsignatures = make(map[uuid.UUID]struct{})
1642 }
1643 for i := range ids {
1644 delete(m.signatures, ids[i])
1645 m.removedsignatures[ids[i]] = struct{}{}
1646 }
1647 }
1648
1649 // RemovedSignatures returns the removed IDs of the "signatures" edge to the Signature entity.
1650 func (m *DsseMutation) RemovedSignaturesIDs() (ids []uuid.UUID) {
1651 for id := range m.removedsignatures {
1652 ids = append(ids, id)
1653 }
1654 return
1655 }
1656
1657 // SignaturesIDs returns the "signatures" edge IDs in the mutation.
1658 func (m *DsseMutation) SignaturesIDs() (ids []uuid.UUID) {
1659 for id := range m.signatures {
1660 ids = append(ids, id)
1661 }
1662 return
1663 }
1664
1665 // ResetSignatures resets all changes to the "signatures" edge.
1666 func (m *DsseMutation) ResetSignatures() {
1667 m.signatures = nil
1668 m.clearedsignatures = false
1669 m.removedsignatures = nil
1670 }
1671
1672 // AddPayloadDigestIDs adds the "payload_digests" edge to the PayloadDigest entity by ids.
1673 func (m *DsseMutation) AddPayloadDigestIDs(ids ...uuid.UUID) {
1674 if m.payload_digests == nil {
1675 m.payload_digests = make(map[uuid.UUID]struct{})
1676 }
1677 for i := range ids {
1678 m.payload_digests[ids[i]] = struct{}{}
1679 }
1680 }
1681
1682 // ClearPayloadDigests clears the "payload_digests" edge to the PayloadDigest entity.
1683 func (m *DsseMutation) ClearPayloadDigests() {
1684 m.clearedpayload_digests = true
1685 }
1686
1687 // PayloadDigestsCleared reports if the "payload_digests" edge to the PayloadDigest entity was cleared.
1688 func (m *DsseMutation) PayloadDigestsCleared() bool {
1689 return m.clearedpayload_digests
1690 }
1691
1692 // RemovePayloadDigestIDs removes the "payload_digests" edge to the PayloadDigest entity by IDs.
1693 func (m *DsseMutation) RemovePayloadDigestIDs(ids ...uuid.UUID) {
1694 if m.removedpayload_digests == nil {
1695 m.removedpayload_digests = make(map[uuid.UUID]struct{})
1696 }
1697 for i := range ids {
1698 delete(m.payload_digests, ids[i])
1699 m.removedpayload_digests[ids[i]] = struct{}{}
1700 }
1701 }
1702
1703 // RemovedPayloadDigests returns the removed IDs of the "payload_digests" edge to the PayloadDigest entity.
1704 func (m *DsseMutation) RemovedPayloadDigestsIDs() (ids []uuid.UUID) {
1705 for id := range m.removedpayload_digests {
1706 ids = append(ids, id)
1707 }
1708 return
1709 }
1710
1711 // PayloadDigestsIDs returns the "payload_digests" edge IDs in the mutation.
1712 func (m *DsseMutation) PayloadDigestsIDs() (ids []uuid.UUID) {
1713 for id := range m.payload_digests {
1714 ids = append(ids, id)
1715 }
1716 return
1717 }
1718
1719 // ResetPayloadDigests resets all changes to the "payload_digests" edge.
1720 func (m *DsseMutation) ResetPayloadDigests() {
1721 m.payload_digests = nil
1722 m.clearedpayload_digests = false
1723 m.removedpayload_digests = nil
1724 }
1725
1726 // Where appends a list predicates to the DsseMutation builder.
1727 func (m *DsseMutation) Where(ps ...predicate.Dsse) {
1728 m.predicates = append(m.predicates, ps...)
1729 }
1730
1731 // WhereP appends storage-level predicates to the DsseMutation builder. Using this method,
1732 // users can use type-assertion to append predicates that do not depend on any generated package.
1733 func (m *DsseMutation) WhereP(ps ...func(*sql.Selector)) {
1734 p := make([]predicate.Dsse, len(ps))
1735 for i := range ps {
1736 p[i] = ps[i]
1737 }
1738 m.Where(p...)
1739 }
1740
1741 // Op returns the operation name.
1742 func (m *DsseMutation) Op() Op {
1743 return m.op
1744 }
1745
1746 // SetOp allows setting the mutation operation.
1747 func (m *DsseMutation) SetOp(op Op) {
1748 m.op = op
1749 }
1750
1751 // Type returns the node type of this mutation (Dsse).
1752 func (m *DsseMutation) Type() string {
1753 return m.typ
1754 }
1755
1756 // Fields returns all fields that were changed during this mutation. Note that in
1757 // order to get all numeric fields that were incremented/decremented, call
1758 // AddedFields().
1759 func (m *DsseMutation) Fields() []string {
1760 fields := make([]string, 0, 3)
1761 if m.created_at != nil {
1762 fields = append(fields, dsse.FieldCreatedAt)
1763 }
1764 if m.gitoid_sha256 != nil {
1765 fields = append(fields, dsse.FieldGitoidSha256)
1766 }
1767 if m.payload_type != nil {
1768 fields = append(fields, dsse.FieldPayloadType)
1769 }
1770 return fields
1771 }
1772
1773 // Field returns the value of a field with the given name. The second boolean
1774 // return value indicates that this field was not set, or was not defined in the
1775 // schema.
1776 func (m *DsseMutation) Field(name string) (ent.Value, bool) {
1777 switch name {
1778 case dsse.FieldCreatedAt:
1779 return m.CreatedAt()
1780 case dsse.FieldGitoidSha256:
1781 return m.GitoidSha256()
1782 case dsse.FieldPayloadType:
1783 return m.PayloadType()
1784 }
1785 return nil, false
1786 }
1787
1788 // OldField returns the old value of the field from the database. An error is
1789 // returned if the mutation operation is not UpdateOne, or the query to the
1790 // database failed.
1791 func (m *DsseMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
1792 switch name {
1793 case dsse.FieldCreatedAt:
1794 return m.OldCreatedAt(ctx)
1795 case dsse.FieldGitoidSha256:
1796 return m.OldGitoidSha256(ctx)
1797 case dsse.FieldPayloadType:
1798 return m.OldPayloadType(ctx)
1799 }
1800 return nil, fmt.Errorf("unknown Dsse field %s", name)
1801 }
1802
1803 // SetField sets the value of a field with the given name. It returns an error if
1804 // the field is not defined in the schema, or if the type mismatched the field
1805 // type.
1806 func (m *DsseMutation) SetField(name string, value ent.Value) error {
1807 switch name {
1808 case dsse.FieldCreatedAt:
1809 v, ok := value.(time.Time)
1810 if !ok {
1811 return fmt.Errorf("unexpected type %T for field %s", value, name)
1812 }
1813 m.SetCreatedAt(v)
1814 return nil
1815 case dsse.FieldGitoidSha256:
1816 v, ok := value.(string)
1817 if !ok {
1818 return fmt.Errorf("unexpected type %T for field %s", value, name)
1819 }
1820 m.SetGitoidSha256(v)
1821 return nil
1822 case dsse.FieldPayloadType:
1823 v, ok := value.(string)
1824 if !ok {
1825 return fmt.Errorf("unexpected type %T for field %s", value, name)
1826 }
1827 m.SetPayloadType(v)
1828 return nil
1829 }
1830 return fmt.Errorf("unknown Dsse field %s", name)
1831 }
1832
1833 // AddedFields returns all numeric fields that were incremented/decremented during
1834 // this mutation.
1835 func (m *DsseMutation) AddedFields() []string {
1836 return nil
1837 }
1838
1839 // AddedField returns the numeric value that was incremented/decremented on a field
1840 // with the given name. The second boolean return value indicates that this field
1841 // was not set, or was not defined in the schema.
1842 func (m *DsseMutation) AddedField(name string) (ent.Value, bool) {
1843 return nil, false
1844 }
1845
1846 // AddField adds the value to the field with the given name. It returns an error if
1847 // the field is not defined in the schema, or if the type mismatched the field
1848 // type.
1849 func (m *DsseMutation) AddField(name string, value ent.Value) error {
1850 switch name {
1851 }
1852 return fmt.Errorf("unknown Dsse numeric field %s", name)
1853 }
1854
1855 // ClearedFields returns all nullable fields that were cleared during this
1856 // mutation.
1857 func (m *DsseMutation) ClearedFields() []string {
1858 var fields []string
1859 if m.FieldCleared(dsse.FieldCreatedAt) {
1860 fields = append(fields, dsse.FieldCreatedAt)
1861 }
1862 return fields
1863 }
1864
1865 // FieldCleared returns a boolean indicating if a field with the given name was
1866 // cleared in this mutation.
1867 func (m *DsseMutation) FieldCleared(name string) bool {
1868 _, ok := m.clearedFields[name]
1869 return ok
1870 }
1871
1872 // ClearField clears the value of the field with the given name. It returns an
1873 // error if the field is not defined in the schema.
1874 func (m *DsseMutation) ClearField(name string) error {
1875 switch name {
1876 case dsse.FieldCreatedAt:
1877 m.ClearCreatedAt()
1878 return nil
1879 }
1880 return fmt.Errorf("unknown Dsse nullable field %s", name)
1881 }
1882
1883 // ResetField resets all changes in the mutation for the field with the given name.
1884 // It returns an error if the field is not defined in the schema.
1885 func (m *DsseMutation) ResetField(name string) error {
1886 switch name {
1887 case dsse.FieldCreatedAt:
1888 m.ResetCreatedAt()
1889 return nil
1890 case dsse.FieldGitoidSha256:
1891 m.ResetGitoidSha256()
1892 return nil
1893 case dsse.FieldPayloadType:
1894 m.ResetPayloadType()
1895 return nil
1896 }
1897 return fmt.Errorf("unknown Dsse field %s", name)
1898 }
1899
1900 // AddedEdges returns all edge names that were set/added in this mutation.
1901 func (m *DsseMutation) AddedEdges() []string {
1902 edges := make([]string, 0, 3)
1903 if m.statement != nil {
1904 edges = append(edges, dsse.EdgeStatement)
1905 }
1906 if m.signatures != nil {
1907 edges = append(edges, dsse.EdgeSignatures)
1908 }
1909 if m.payload_digests != nil {
1910 edges = append(edges, dsse.EdgePayloadDigests)
1911 }
1912 return edges
1913 }
1914
1915 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
1916 // name in this mutation.
1917 func (m *DsseMutation) AddedIDs(name string) []ent.Value {
1918 switch name {
1919 case dsse.EdgeStatement:
1920 if id := m.statement; id != nil {
1921 return []ent.Value{*id}
1922 }
1923 case dsse.EdgeSignatures:
1924 ids := make([]ent.Value, 0, len(m.signatures))
1925 for id := range m.signatures {
1926 ids = append(ids, id)
1927 }
1928 return ids
1929 case dsse.EdgePayloadDigests:
1930 ids := make([]ent.Value, 0, len(m.payload_digests))
1931 for id := range m.payload_digests {
1932 ids = append(ids, id)
1933 }
1934 return ids
1935 }
1936 return nil
1937 }
1938
1939 // RemovedEdges returns all edge names that were removed in this mutation.
1940 func (m *DsseMutation) RemovedEdges() []string {
1941 edges := make([]string, 0, 3)
1942 if m.removedsignatures != nil {
1943 edges = append(edges, dsse.EdgeSignatures)
1944 }
1945 if m.removedpayload_digests != nil {
1946 edges = append(edges, dsse.EdgePayloadDigests)
1947 }
1948 return edges
1949 }
1950
1951 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
1952 // the given name in this mutation.
1953 func (m *DsseMutation) RemovedIDs(name string) []ent.Value {
1954 switch name {
1955 case dsse.EdgeSignatures:
1956 ids := make([]ent.Value, 0, len(m.removedsignatures))
1957 for id := range m.removedsignatures {
1958 ids = append(ids, id)
1959 }
1960 return ids
1961 case dsse.EdgePayloadDigests:
1962 ids := make([]ent.Value, 0, len(m.removedpayload_digests))
1963 for id := range m.removedpayload_digests {
1964 ids = append(ids, id)
1965 }
1966 return ids
1967 }
1968 return nil
1969 }
1970
1971 // ClearedEdges returns all edge names that were cleared in this mutation.
1972 func (m *DsseMutation) ClearedEdges() []string {
1973 edges := make([]string, 0, 3)
1974 if m.clearedstatement {
1975 edges = append(edges, dsse.EdgeStatement)
1976 }
1977 if m.clearedsignatures {
1978 edges = append(edges, dsse.EdgeSignatures)
1979 }
1980 if m.clearedpayload_digests {
1981 edges = append(edges, dsse.EdgePayloadDigests)
1982 }
1983 return edges
1984 }
1985
1986 // EdgeCleared returns a boolean which indicates if the edge with the given name
1987 // was cleared in this mutation.
1988 func (m *DsseMutation) EdgeCleared(name string) bool {
1989 switch name {
1990 case dsse.EdgeStatement:
1991 return m.clearedstatement
1992 case dsse.EdgeSignatures:
1993 return m.clearedsignatures
1994 case dsse.EdgePayloadDigests:
1995 return m.clearedpayload_digests
1996 }
1997 return false
1998 }
1999
2000 // ClearEdge clears the value of the edge with the given name. It returns an error
2001 // if that edge is not defined in the schema.
2002 func (m *DsseMutation) ClearEdge(name string) error {
2003 switch name {
2004 case dsse.EdgeStatement:
2005 m.ClearStatement()
2006 return nil
2007 }
2008 return fmt.Errorf("unknown Dsse unique edge %s", name)
2009 }
2010
2011 // ResetEdge resets all changes to the edge with the given name in this mutation.
2012 // It returns an error if the edge is not defined in the schema.
2013 func (m *DsseMutation) ResetEdge(name string) error {
2014 switch name {
2015 case dsse.EdgeStatement:
2016 m.ResetStatement()
2017 return nil
2018 case dsse.EdgeSignatures:
2019 m.ResetSignatures()
2020 return nil
2021 case dsse.EdgePayloadDigests:
2022 m.ResetPayloadDigests()
2023 return nil
2024 }
2025 return fmt.Errorf("unknown Dsse edge %s", name)
2026 }
2027
2028 // PayloadDigestMutation represents an operation that mutates the PayloadDigest nodes in the graph.
2029 type PayloadDigestMutation struct {
2030 config
2031 op Op
2032 typ string
2033 id *uuid.UUID
2034 algorithm *string
2035 value *string
2036 clearedFields map[string]struct{}
2037 dsse *uuid.UUID
2038 cleareddsse bool
2039 done bool
2040 oldValue func(context.Context) (*PayloadDigest, error)
2041 predicates []predicate.PayloadDigest
2042 }
2043
2044 var _ ent.Mutation = (*PayloadDigestMutation)(nil)
2045
2046 // payloaddigestOption allows management of the mutation configuration using functional options.
2047 type payloaddigestOption func(*PayloadDigestMutation)
2048
2049 // newPayloadDigestMutation creates new mutation for the PayloadDigest entity.
2050 func newPayloadDigestMutation(c config, op Op, opts ...payloaddigestOption) *PayloadDigestMutation {
2051 m := &PayloadDigestMutation{
2052 config: c,
2053 op: op,
2054 typ: TypePayloadDigest,
2055 clearedFields: make(map[string]struct{}),
2056 }
2057 for _, opt := range opts {
2058 opt(m)
2059 }
2060 return m
2061 }
2062
2063 // withPayloadDigestID sets the ID field of the mutation.
2064 func withPayloadDigestID(id uuid.UUID) payloaddigestOption {
2065 return func(m *PayloadDigestMutation) {
2066 var (
2067 err error
2068 once sync.Once
2069 value *PayloadDigest
2070 )
2071 m.oldValue = func(ctx context.Context) (*PayloadDigest, error) {
2072 once.Do(func() {
2073 if m.done {
2074 err = errors.New("querying old values post mutation is not allowed")
2075 } else {
2076 value, err = m.Client().PayloadDigest.Get(ctx, id)
2077 }
2078 })
2079 return value, err
2080 }
2081 m.id = &id
2082 }
2083 }
2084
2085 // withPayloadDigest sets the old PayloadDigest of the mutation.
2086 func withPayloadDigest(node *PayloadDigest) payloaddigestOption {
2087 return func(m *PayloadDigestMutation) {
2088 m.oldValue = func(context.Context) (*PayloadDigest, error) {
2089 return node, nil
2090 }
2091 m.id = &node.ID
2092 }
2093 }
2094
2095 // Client returns a new `ent.Client` from the mutation. If the mutation was
2096 // executed in a transaction (ent.Tx), a transactional client is returned.
2097 func (m PayloadDigestMutation) Client() *Client {
2098 client := &Client{config: m.config}
2099 client.init()
2100 return client
2101 }
2102
2103 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
2104 // it returns an error otherwise.
2105 func (m PayloadDigestMutation) Tx() (*Tx, error) {
2106 if _, ok := m.driver.(*txDriver); !ok {
2107 return nil, errors.New("ent: mutation is not running in a transaction")
2108 }
2109 tx := &Tx{config: m.config}
2110 tx.init()
2111 return tx, nil
2112 }
2113
2114 // SetID sets the value of the id field. Note that this
2115 // operation is only accepted on creation of PayloadDigest entities.
2116 func (m *PayloadDigestMutation) SetID(id uuid.UUID) {
2117 m.id = &id
2118 }
2119
2120 // ID returns the ID value in the mutation. Note that the ID is only available
2121 // if it was provided to the builder or after it was returned from the database.
2122 func (m *PayloadDigestMutation) ID() (id uuid.UUID, exists bool) {
2123 if m.id == nil {
2124 return
2125 }
2126 return *m.id, true
2127 }
2128
2129 // IDs queries the database and returns the entity ids that match the mutation's predicate.
2130 // That means, if the mutation is applied within a transaction with an isolation level such
2131 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
2132 // or updated by the mutation.
2133 func (m *PayloadDigestMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
2134 switch {
2135 case m.op.Is(OpUpdateOne | OpDeleteOne):
2136 id, exists := m.ID()
2137 if exists {
2138 return []uuid.UUID{id}, nil
2139 }
2140 fallthrough
2141 case m.op.Is(OpUpdate | OpDelete):
2142 return m.Client().PayloadDigest.Query().Where(m.predicates...).IDs(ctx)
2143 default:
2144 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
2145 }
2146 }
2147
2148 // SetAlgorithm sets the "algorithm" field.
2149 func (m *PayloadDigestMutation) SetAlgorithm(s string) {
2150 m.algorithm = &s
2151 }
2152
2153 // Algorithm returns the value of the "algorithm" field in the mutation.
2154 func (m *PayloadDigestMutation) Algorithm() (r string, exists bool) {
2155 v := m.algorithm
2156 if v == nil {
2157 return
2158 }
2159 return *v, true
2160 }
2161
2162 // OldAlgorithm returns the old "algorithm" field's value of the PayloadDigest entity.
2163 // If the PayloadDigest object wasn't provided to the builder, the object is fetched from the database.
2164 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
2165 func (m *PayloadDigestMutation) OldAlgorithm(ctx context.Context) (v string, err error) {
2166 if !m.op.Is(OpUpdateOne) {
2167 return v, errors.New("OldAlgorithm is only allowed on UpdateOne operations")
2168 }
2169 if m.id == nil || m.oldValue == nil {
2170 return v, errors.New("OldAlgorithm requires an ID field in the mutation")
2171 }
2172 oldValue, err := m.oldValue(ctx)
2173 if err != nil {
2174 return v, fmt.Errorf("querying old value for OldAlgorithm: %w", err)
2175 }
2176 return oldValue.Algorithm, nil
2177 }
2178
2179 // ResetAlgorithm resets all changes to the "algorithm" field.
2180 func (m *PayloadDigestMutation) ResetAlgorithm() {
2181 m.algorithm = nil
2182 }
2183
2184 // SetValue sets the "value" field.
2185 func (m *PayloadDigestMutation) SetValue(s string) {
2186 m.value = &s
2187 }
2188
2189 // Value returns the value of the "value" field in the mutation.
2190 func (m *PayloadDigestMutation) Value() (r string, exists bool) {
2191 v := m.value
2192 if v == nil {
2193 return
2194 }
2195 return *v, true
2196 }
2197
2198 // OldValue returns the old "value" field's value of the PayloadDigest entity.
2199 // If the PayloadDigest object wasn't provided to the builder, the object is fetched from the database.
2200 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
2201 func (m *PayloadDigestMutation) OldValue(ctx context.Context) (v string, err error) {
2202 if !m.op.Is(OpUpdateOne) {
2203 return v, errors.New("OldValue is only allowed on UpdateOne operations")
2204 }
2205 if m.id == nil || m.oldValue == nil {
2206 return v, errors.New("OldValue requires an ID field in the mutation")
2207 }
2208 oldValue, err := m.oldValue(ctx)
2209 if err != nil {
2210 return v, fmt.Errorf("querying old value for OldValue: %w", err)
2211 }
2212 return oldValue.Value, nil
2213 }
2214
2215 // ResetValue resets all changes to the "value" field.
2216 func (m *PayloadDigestMutation) ResetValue() {
2217 m.value = nil
2218 }
2219
2220 // SetDsseID sets the "dsse" edge to the Dsse entity by id.
2221 func (m *PayloadDigestMutation) SetDsseID(id uuid.UUID) {
2222 m.dsse = &id
2223 }
2224
2225 // ClearDsse clears the "dsse" edge to the Dsse entity.
2226 func (m *PayloadDigestMutation) ClearDsse() {
2227 m.cleareddsse = true
2228 }
2229
2230 // DsseCleared reports if the "dsse" edge to the Dsse entity was cleared.
2231 func (m *PayloadDigestMutation) DsseCleared() bool {
2232 return m.cleareddsse
2233 }
2234
2235 // DsseID returns the "dsse" edge ID in the mutation.
2236 func (m *PayloadDigestMutation) DsseID() (id uuid.UUID, exists bool) {
2237 if m.dsse != nil {
2238 return *m.dsse, true
2239 }
2240 return
2241 }
2242
2243 // DsseIDs returns the "dsse" edge IDs in the mutation.
2244 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
2245 // DsseID instead. It exists only for internal usage by the builders.
2246 func (m *PayloadDigestMutation) DsseIDs() (ids []uuid.UUID) {
2247 if id := m.dsse; id != nil {
2248 ids = append(ids, *id)
2249 }
2250 return
2251 }
2252
2253 // ResetDsse resets all changes to the "dsse" edge.
2254 func (m *PayloadDigestMutation) ResetDsse() {
2255 m.dsse = nil
2256 m.cleareddsse = false
2257 }
2258
2259 // Where appends a list predicates to the PayloadDigestMutation builder.
2260 func (m *PayloadDigestMutation) Where(ps ...predicate.PayloadDigest) {
2261 m.predicates = append(m.predicates, ps...)
2262 }
2263
2264 // WhereP appends storage-level predicates to the PayloadDigestMutation builder. Using this method,
2265 // users can use type-assertion to append predicates that do not depend on any generated package.
2266 func (m *PayloadDigestMutation) WhereP(ps ...func(*sql.Selector)) {
2267 p := make([]predicate.PayloadDigest, len(ps))
2268 for i := range ps {
2269 p[i] = ps[i]
2270 }
2271 m.Where(p...)
2272 }
2273
2274 // Op returns the operation name.
2275 func (m *PayloadDigestMutation) Op() Op {
2276 return m.op
2277 }
2278
2279 // SetOp allows setting the mutation operation.
2280 func (m *PayloadDigestMutation) SetOp(op Op) {
2281 m.op = op
2282 }
2283
2284 // Type returns the node type of this mutation (PayloadDigest).
2285 func (m *PayloadDigestMutation) Type() string {
2286 return m.typ
2287 }
2288
2289 // Fields returns all fields that were changed during this mutation. Note that in
2290 // order to get all numeric fields that were incremented/decremented, call
2291 // AddedFields().
2292 func (m *PayloadDigestMutation) Fields() []string {
2293 fields := make([]string, 0, 2)
2294 if m.algorithm != nil {
2295 fields = append(fields, payloaddigest.FieldAlgorithm)
2296 }
2297 if m.value != nil {
2298 fields = append(fields, payloaddigest.FieldValue)
2299 }
2300 return fields
2301 }
2302
2303 // Field returns the value of a field with the given name. The second boolean
2304 // return value indicates that this field was not set, or was not defined in the
2305 // schema.
2306 func (m *PayloadDigestMutation) Field(name string) (ent.Value, bool) {
2307 switch name {
2308 case payloaddigest.FieldAlgorithm:
2309 return m.Algorithm()
2310 case payloaddigest.FieldValue:
2311 return m.Value()
2312 }
2313 return nil, false
2314 }
2315
2316 // OldField returns the old value of the field from the database. An error is
2317 // returned if the mutation operation is not UpdateOne, or the query to the
2318 // database failed.
2319 func (m *PayloadDigestMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
2320 switch name {
2321 case payloaddigest.FieldAlgorithm:
2322 return m.OldAlgorithm(ctx)
2323 case payloaddigest.FieldValue:
2324 return m.OldValue(ctx)
2325 }
2326 return nil, fmt.Errorf("unknown PayloadDigest field %s", name)
2327 }
2328
2329 // SetField sets the value of a field with the given name. It returns an error if
2330 // the field is not defined in the schema, or if the type mismatched the field
2331 // type.
2332 func (m *PayloadDigestMutation) SetField(name string, value ent.Value) error {
2333 switch name {
2334 case payloaddigest.FieldAlgorithm:
2335 v, ok := value.(string)
2336 if !ok {
2337 return fmt.Errorf("unexpected type %T for field %s", value, name)
2338 }
2339 m.SetAlgorithm(v)
2340 return nil
2341 case payloaddigest.FieldValue:
2342 v, ok := value.(string)
2343 if !ok {
2344 return fmt.Errorf("unexpected type %T for field %s", value, name)
2345 }
2346 m.SetValue(v)
2347 return nil
2348 }
2349 return fmt.Errorf("unknown PayloadDigest field %s", name)
2350 }
2351
2352 // AddedFields returns all numeric fields that were incremented/decremented during
2353 // this mutation.
2354 func (m *PayloadDigestMutation) AddedFields() []string {
2355 return nil
2356 }
2357
2358 // AddedField returns the numeric value that was incremented/decremented on a field
2359 // with the given name. The second boolean return value indicates that this field
2360 // was not set, or was not defined in the schema.
2361 func (m *PayloadDigestMutation) AddedField(name string) (ent.Value, bool) {
2362 return nil, false
2363 }
2364
2365 // AddField adds the value to the field with the given name. It returns an error if
2366 // the field is not defined in the schema, or if the type mismatched the field
2367 // type.
2368 func (m *PayloadDigestMutation) AddField(name string, value ent.Value) error {
2369 switch name {
2370 }
2371 return fmt.Errorf("unknown PayloadDigest numeric field %s", name)
2372 }
2373
2374 // ClearedFields returns all nullable fields that were cleared during this
2375 // mutation.
2376 func (m *PayloadDigestMutation) ClearedFields() []string {
2377 return nil
2378 }
2379
2380 // FieldCleared returns a boolean indicating if a field with the given name was
2381 // cleared in this mutation.
2382 func (m *PayloadDigestMutation) FieldCleared(name string) bool {
2383 _, ok := m.clearedFields[name]
2384 return ok
2385 }
2386
2387 // ClearField clears the value of the field with the given name. It returns an
2388 // error if the field is not defined in the schema.
2389 func (m *PayloadDigestMutation) ClearField(name string) error {
2390 return fmt.Errorf("unknown PayloadDigest nullable field %s", name)
2391 }
2392
2393 // ResetField resets all changes in the mutation for the field with the given name.
2394 // It returns an error if the field is not defined in the schema.
2395 func (m *PayloadDigestMutation) ResetField(name string) error {
2396 switch name {
2397 case payloaddigest.FieldAlgorithm:
2398 m.ResetAlgorithm()
2399 return nil
2400 case payloaddigest.FieldValue:
2401 m.ResetValue()
2402 return nil
2403 }
2404 return fmt.Errorf("unknown PayloadDigest field %s", name)
2405 }
2406
2407 // AddedEdges returns all edge names that were set/added in this mutation.
2408 func (m *PayloadDigestMutation) AddedEdges() []string {
2409 edges := make([]string, 0, 1)
2410 if m.dsse != nil {
2411 edges = append(edges, payloaddigest.EdgeDsse)
2412 }
2413 return edges
2414 }
2415
2416 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
2417 // name in this mutation.
2418 func (m *PayloadDigestMutation) AddedIDs(name string) []ent.Value {
2419 switch name {
2420 case payloaddigest.EdgeDsse:
2421 if id := m.dsse; id != nil {
2422 return []ent.Value{*id}
2423 }
2424 }
2425 return nil
2426 }
2427
2428 // RemovedEdges returns all edge names that were removed in this mutation.
2429 func (m *PayloadDigestMutation) RemovedEdges() []string {
2430 edges := make([]string, 0, 1)
2431 return edges
2432 }
2433
2434 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
2435 // the given name in this mutation.
2436 func (m *PayloadDigestMutation) RemovedIDs(name string) []ent.Value {
2437 return nil
2438 }
2439
2440 // ClearedEdges returns all edge names that were cleared in this mutation.
2441 func (m *PayloadDigestMutation) ClearedEdges() []string {
2442 edges := make([]string, 0, 1)
2443 if m.cleareddsse {
2444 edges = append(edges, payloaddigest.EdgeDsse)
2445 }
2446 return edges
2447 }
2448
2449 // EdgeCleared returns a boolean which indicates if the edge with the given name
2450 // was cleared in this mutation.
2451 func (m *PayloadDigestMutation) EdgeCleared(name string) bool {
2452 switch name {
2453 case payloaddigest.EdgeDsse:
2454 return m.cleareddsse
2455 }
2456 return false
2457 }
2458
2459 // ClearEdge clears the value of the edge with the given name. It returns an error
2460 // if that edge is not defined in the schema.
2461 func (m *PayloadDigestMutation) ClearEdge(name string) error {
2462 switch name {
2463 case payloaddigest.EdgeDsse:
2464 m.ClearDsse()
2465 return nil
2466 }
2467 return fmt.Errorf("unknown PayloadDigest unique edge %s", name)
2468 }
2469
2470 // ResetEdge resets all changes to the edge with the given name in this mutation.
2471 // It returns an error if the edge is not defined in the schema.
2472 func (m *PayloadDigestMutation) ResetEdge(name string) error {
2473 switch name {
2474 case payloaddigest.EdgeDsse:
2475 m.ResetDsse()
2476 return nil
2477 }
2478 return fmt.Errorf("unknown PayloadDigest edge %s", name)
2479 }
2480
2481 // SignatureMutation represents an operation that mutates the Signature nodes in the graph.
2482 type SignatureMutation struct {
2483 config
2484 op Op
2485 typ string
2486 id *uuid.UUID
2487 key_id *string
2488 signature *string
2489 clearedFields map[string]struct{}
2490 dsse *uuid.UUID
2491 cleareddsse bool
2492 timestamps map[uuid.UUID]struct{}
2493 removedtimestamps map[uuid.UUID]struct{}
2494 clearedtimestamps bool
2495 done bool
2496 oldValue func(context.Context) (*Signature, error)
2497 predicates []predicate.Signature
2498 }
2499
2500 var _ ent.Mutation = (*SignatureMutation)(nil)
2501
2502 // signatureOption allows management of the mutation configuration using functional options.
2503 type signatureOption func(*SignatureMutation)
2504
2505 // newSignatureMutation creates new mutation for the Signature entity.
2506 func newSignatureMutation(c config, op Op, opts ...signatureOption) *SignatureMutation {
2507 m := &SignatureMutation{
2508 config: c,
2509 op: op,
2510 typ: TypeSignature,
2511 clearedFields: make(map[string]struct{}),
2512 }
2513 for _, opt := range opts {
2514 opt(m)
2515 }
2516 return m
2517 }
2518
2519 // withSignatureID sets the ID field of the mutation.
2520 func withSignatureID(id uuid.UUID) signatureOption {
2521 return func(m *SignatureMutation) {
2522 var (
2523 err error
2524 once sync.Once
2525 value *Signature
2526 )
2527 m.oldValue = func(ctx context.Context) (*Signature, error) {
2528 once.Do(func() {
2529 if m.done {
2530 err = errors.New("querying old values post mutation is not allowed")
2531 } else {
2532 value, err = m.Client().Signature.Get(ctx, id)
2533 }
2534 })
2535 return value, err
2536 }
2537 m.id = &id
2538 }
2539 }
2540
2541 // withSignature sets the old Signature of the mutation.
2542 func withSignature(node *Signature) signatureOption {
2543 return func(m *SignatureMutation) {
2544 m.oldValue = func(context.Context) (*Signature, error) {
2545 return node, nil
2546 }
2547 m.id = &node.ID
2548 }
2549 }
2550
2551 // Client returns a new `ent.Client` from the mutation. If the mutation was
2552 // executed in a transaction (ent.Tx), a transactional client is returned.
2553 func (m SignatureMutation) Client() *Client {
2554 client := &Client{config: m.config}
2555 client.init()
2556 return client
2557 }
2558
2559 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
2560 // it returns an error otherwise.
2561 func (m SignatureMutation) Tx() (*Tx, error) {
2562 if _, ok := m.driver.(*txDriver); !ok {
2563 return nil, errors.New("ent: mutation is not running in a transaction")
2564 }
2565 tx := &Tx{config: m.config}
2566 tx.init()
2567 return tx, nil
2568 }
2569
2570 // SetID sets the value of the id field. Note that this
2571 // operation is only accepted on creation of Signature entities.
2572 func (m *SignatureMutation) SetID(id uuid.UUID) {
2573 m.id = &id
2574 }
2575
2576 // ID returns the ID value in the mutation. Note that the ID is only available
2577 // if it was provided to the builder or after it was returned from the database.
2578 func (m *SignatureMutation) ID() (id uuid.UUID, exists bool) {
2579 if m.id == nil {
2580 return
2581 }
2582 return *m.id, true
2583 }
2584
2585 // IDs queries the database and returns the entity ids that match the mutation's predicate.
2586 // That means, if the mutation is applied within a transaction with an isolation level such
2587 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
2588 // or updated by the mutation.
2589 func (m *SignatureMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
2590 switch {
2591 case m.op.Is(OpUpdateOne | OpDeleteOne):
2592 id, exists := m.ID()
2593 if exists {
2594 return []uuid.UUID{id}, nil
2595 }
2596 fallthrough
2597 case m.op.Is(OpUpdate | OpDelete):
2598 return m.Client().Signature.Query().Where(m.predicates...).IDs(ctx)
2599 default:
2600 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
2601 }
2602 }
2603
2604 // SetKeyID sets the "key_id" field.
2605 func (m *SignatureMutation) SetKeyID(s string) {
2606 m.key_id = &s
2607 }
2608
2609 // KeyID returns the value of the "key_id" field in the mutation.
2610 func (m *SignatureMutation) KeyID() (r string, exists bool) {
2611 v := m.key_id
2612 if v == nil {
2613 return
2614 }
2615 return *v, true
2616 }
2617
2618 // OldKeyID returns the old "key_id" field's value of the Signature entity.
2619 // If the Signature object wasn't provided to the builder, the object is fetched from the database.
2620 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
2621 func (m *SignatureMutation) OldKeyID(ctx context.Context) (v string, err error) {
2622 if !m.op.Is(OpUpdateOne) {
2623 return v, errors.New("OldKeyID is only allowed on UpdateOne operations")
2624 }
2625 if m.id == nil || m.oldValue == nil {
2626 return v, errors.New("OldKeyID requires an ID field in the mutation")
2627 }
2628 oldValue, err := m.oldValue(ctx)
2629 if err != nil {
2630 return v, fmt.Errorf("querying old value for OldKeyID: %w", err)
2631 }
2632 return oldValue.KeyID, nil
2633 }
2634
2635 // ResetKeyID resets all changes to the "key_id" field.
2636 func (m *SignatureMutation) ResetKeyID() {
2637 m.key_id = nil
2638 }
2639
2640 // SetSignature sets the "signature" field.
2641 func (m *SignatureMutation) SetSignature(s string) {
2642 m.signature = &s
2643 }
2644
2645 // Signature returns the value of the "signature" field in the mutation.
2646 func (m *SignatureMutation) Signature() (r string, exists bool) {
2647 v := m.signature
2648 if v == nil {
2649 return
2650 }
2651 return *v, true
2652 }
2653
2654 // OldSignature returns the old "signature" field's value of the Signature entity.
2655 // If the Signature object wasn't provided to the builder, the object is fetched from the database.
2656 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
2657 func (m *SignatureMutation) OldSignature(ctx context.Context) (v string, err error) {
2658 if !m.op.Is(OpUpdateOne) {
2659 return v, errors.New("OldSignature is only allowed on UpdateOne operations")
2660 }
2661 if m.id == nil || m.oldValue == nil {
2662 return v, errors.New("OldSignature requires an ID field in the mutation")
2663 }
2664 oldValue, err := m.oldValue(ctx)
2665 if err != nil {
2666 return v, fmt.Errorf("querying old value for OldSignature: %w", err)
2667 }
2668 return oldValue.Signature, nil
2669 }
2670
2671 // ResetSignature resets all changes to the "signature" field.
2672 func (m *SignatureMutation) ResetSignature() {
2673 m.signature = nil
2674 }
2675
2676 // SetDsseID sets the "dsse" edge to the Dsse entity by id.
2677 func (m *SignatureMutation) SetDsseID(id uuid.UUID) {
2678 m.dsse = &id
2679 }
2680
2681 // ClearDsse clears the "dsse" edge to the Dsse entity.
2682 func (m *SignatureMutation) ClearDsse() {
2683 m.cleareddsse = true
2684 }
2685
2686 // DsseCleared reports if the "dsse" edge to the Dsse entity was cleared.
2687 func (m *SignatureMutation) DsseCleared() bool {
2688 return m.cleareddsse
2689 }
2690
2691 // DsseID returns the "dsse" edge ID in the mutation.
2692 func (m *SignatureMutation) DsseID() (id uuid.UUID, exists bool) {
2693 if m.dsse != nil {
2694 return *m.dsse, true
2695 }
2696 return
2697 }
2698
2699 // DsseIDs returns the "dsse" edge IDs in the mutation.
2700 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
2701 // DsseID instead. It exists only for internal usage by the builders.
2702 func (m *SignatureMutation) DsseIDs() (ids []uuid.UUID) {
2703 if id := m.dsse; id != nil {
2704 ids = append(ids, *id)
2705 }
2706 return
2707 }
2708
2709 // ResetDsse resets all changes to the "dsse" edge.
2710 func (m *SignatureMutation) ResetDsse() {
2711 m.dsse = nil
2712 m.cleareddsse = false
2713 }
2714
2715 // AddTimestampIDs adds the "timestamps" edge to the Timestamp entity by ids.
2716 func (m *SignatureMutation) AddTimestampIDs(ids ...uuid.UUID) {
2717 if m.timestamps == nil {
2718 m.timestamps = make(map[uuid.UUID]struct{})
2719 }
2720 for i := range ids {
2721 m.timestamps[ids[i]] = struct{}{}
2722 }
2723 }
2724
2725 // ClearTimestamps clears the "timestamps" edge to the Timestamp entity.
2726 func (m *SignatureMutation) ClearTimestamps() {
2727 m.clearedtimestamps = true
2728 }
2729
2730 // TimestampsCleared reports if the "timestamps" edge to the Timestamp entity was cleared.
2731 func (m *SignatureMutation) TimestampsCleared() bool {
2732 return m.clearedtimestamps
2733 }
2734
2735 // RemoveTimestampIDs removes the "timestamps" edge to the Timestamp entity by IDs.
2736 func (m *SignatureMutation) RemoveTimestampIDs(ids ...uuid.UUID) {
2737 if m.removedtimestamps == nil {
2738 m.removedtimestamps = make(map[uuid.UUID]struct{})
2739 }
2740 for i := range ids {
2741 delete(m.timestamps, ids[i])
2742 m.removedtimestamps[ids[i]] = struct{}{}
2743 }
2744 }
2745
2746 // RemovedTimestamps returns the removed IDs of the "timestamps" edge to the Timestamp entity.
2747 func (m *SignatureMutation) RemovedTimestampsIDs() (ids []uuid.UUID) {
2748 for id := range m.removedtimestamps {
2749 ids = append(ids, id)
2750 }
2751 return
2752 }
2753
2754 // TimestampsIDs returns the "timestamps" edge IDs in the mutation.
2755 func (m *SignatureMutation) TimestampsIDs() (ids []uuid.UUID) {
2756 for id := range m.timestamps {
2757 ids = append(ids, id)
2758 }
2759 return
2760 }
2761
2762 // ResetTimestamps resets all changes to the "timestamps" edge.
2763 func (m *SignatureMutation) ResetTimestamps() {
2764 m.timestamps = nil
2765 m.clearedtimestamps = false
2766 m.removedtimestamps = nil
2767 }
2768
2769 // Where appends a list predicates to the SignatureMutation builder.
2770 func (m *SignatureMutation) Where(ps ...predicate.Signature) {
2771 m.predicates = append(m.predicates, ps...)
2772 }
2773
2774 // WhereP appends storage-level predicates to the SignatureMutation builder. Using this method,
2775 // users can use type-assertion to append predicates that do not depend on any generated package.
2776 func (m *SignatureMutation) WhereP(ps ...func(*sql.Selector)) {
2777 p := make([]predicate.Signature, len(ps))
2778 for i := range ps {
2779 p[i] = ps[i]
2780 }
2781 m.Where(p...)
2782 }
2783
2784 // Op returns the operation name.
2785 func (m *SignatureMutation) Op() Op {
2786 return m.op
2787 }
2788
2789 // SetOp allows setting the mutation operation.
2790 func (m *SignatureMutation) SetOp(op Op) {
2791 m.op = op
2792 }
2793
2794 // Type returns the node type of this mutation (Signature).
2795 func (m *SignatureMutation) Type() string {
2796 return m.typ
2797 }
2798
2799 // Fields returns all fields that were changed during this mutation. Note that in
2800 // order to get all numeric fields that were incremented/decremented, call
2801 // AddedFields().
2802 func (m *SignatureMutation) Fields() []string {
2803 fields := make([]string, 0, 2)
2804 if m.key_id != nil {
2805 fields = append(fields, signature.FieldKeyID)
2806 }
2807 if m.signature != nil {
2808 fields = append(fields, signature.FieldSignature)
2809 }
2810 return fields
2811 }
2812
2813 // Field returns the value of a field with the given name. The second boolean
2814 // return value indicates that this field was not set, or was not defined in the
2815 // schema.
2816 func (m *SignatureMutation) Field(name string) (ent.Value, bool) {
2817 switch name {
2818 case signature.FieldKeyID:
2819 return m.KeyID()
2820 case signature.FieldSignature:
2821 return m.Signature()
2822 }
2823 return nil, false
2824 }
2825
2826 // OldField returns the old value of the field from the database. An error is
2827 // returned if the mutation operation is not UpdateOne, or the query to the
2828 // database failed.
2829 func (m *SignatureMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
2830 switch name {
2831 case signature.FieldKeyID:
2832 return m.OldKeyID(ctx)
2833 case signature.FieldSignature:
2834 return m.OldSignature(ctx)
2835 }
2836 return nil, fmt.Errorf("unknown Signature field %s", name)
2837 }
2838
2839 // SetField sets the value of a field with the given name. It returns an error if
2840 // the field is not defined in the schema, or if the type mismatched the field
2841 // type.
2842 func (m *SignatureMutation) SetField(name string, value ent.Value) error {
2843 switch name {
2844 case signature.FieldKeyID:
2845 v, ok := value.(string)
2846 if !ok {
2847 return fmt.Errorf("unexpected type %T for field %s", value, name)
2848 }
2849 m.SetKeyID(v)
2850 return nil
2851 case signature.FieldSignature:
2852 v, ok := value.(string)
2853 if !ok {
2854 return fmt.Errorf("unexpected type %T for field %s", value, name)
2855 }
2856 m.SetSignature(v)
2857 return nil
2858 }
2859 return fmt.Errorf("unknown Signature field %s", name)
2860 }
2861
2862 // AddedFields returns all numeric fields that were incremented/decremented during
2863 // this mutation.
2864 func (m *SignatureMutation) AddedFields() []string {
2865 return nil
2866 }
2867
2868 // AddedField returns the numeric value that was incremented/decremented on a field
2869 // with the given name. The second boolean return value indicates that this field
2870 // was not set, or was not defined in the schema.
2871 func (m *SignatureMutation) AddedField(name string) (ent.Value, bool) {
2872 return nil, false
2873 }
2874
2875 // AddField adds the value to the field with the given name. It returns an error if
2876 // the field is not defined in the schema, or if the type mismatched the field
2877 // type.
2878 func (m *SignatureMutation) AddField(name string, value ent.Value) error {
2879 switch name {
2880 }
2881 return fmt.Errorf("unknown Signature numeric field %s", name)
2882 }
2883
2884 // ClearedFields returns all nullable fields that were cleared during this
2885 // mutation.
2886 func (m *SignatureMutation) ClearedFields() []string {
2887 return nil
2888 }
2889
2890 // FieldCleared returns a boolean indicating if a field with the given name was
2891 // cleared in this mutation.
2892 func (m *SignatureMutation) FieldCleared(name string) bool {
2893 _, ok := m.clearedFields[name]
2894 return ok
2895 }
2896
2897 // ClearField clears the value of the field with the given name. It returns an
2898 // error if the field is not defined in the schema.
2899 func (m *SignatureMutation) ClearField(name string) error {
2900 return fmt.Errorf("unknown Signature nullable field %s", name)
2901 }
2902
2903 // ResetField resets all changes in the mutation for the field with the given name.
2904 // It returns an error if the field is not defined in the schema.
2905 func (m *SignatureMutation) ResetField(name string) error {
2906 switch name {
2907 case signature.FieldKeyID:
2908 m.ResetKeyID()
2909 return nil
2910 case signature.FieldSignature:
2911 m.ResetSignature()
2912 return nil
2913 }
2914 return fmt.Errorf("unknown Signature field %s", name)
2915 }
2916
2917 // AddedEdges returns all edge names that were set/added in this mutation.
2918 func (m *SignatureMutation) AddedEdges() []string {
2919 edges := make([]string, 0, 2)
2920 if m.dsse != nil {
2921 edges = append(edges, signature.EdgeDsse)
2922 }
2923 if m.timestamps != nil {
2924 edges = append(edges, signature.EdgeTimestamps)
2925 }
2926 return edges
2927 }
2928
2929 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
2930 // name in this mutation.
2931 func (m *SignatureMutation) AddedIDs(name string) []ent.Value {
2932 switch name {
2933 case signature.EdgeDsse:
2934 if id := m.dsse; id != nil {
2935 return []ent.Value{*id}
2936 }
2937 case signature.EdgeTimestamps:
2938 ids := make([]ent.Value, 0, len(m.timestamps))
2939 for id := range m.timestamps {
2940 ids = append(ids, id)
2941 }
2942 return ids
2943 }
2944 return nil
2945 }
2946
2947 // RemovedEdges returns all edge names that were removed in this mutation.
2948 func (m *SignatureMutation) RemovedEdges() []string {
2949 edges := make([]string, 0, 2)
2950 if m.removedtimestamps != nil {
2951 edges = append(edges, signature.EdgeTimestamps)
2952 }
2953 return edges
2954 }
2955
2956 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
2957 // the given name in this mutation.
2958 func (m *SignatureMutation) RemovedIDs(name string) []ent.Value {
2959 switch name {
2960 case signature.EdgeTimestamps:
2961 ids := make([]ent.Value, 0, len(m.removedtimestamps))
2962 for id := range m.removedtimestamps {
2963 ids = append(ids, id)
2964 }
2965 return ids
2966 }
2967 return nil
2968 }
2969
2970 // ClearedEdges returns all edge names that were cleared in this mutation.
2971 func (m *SignatureMutation) ClearedEdges() []string {
2972 edges := make([]string, 0, 2)
2973 if m.cleareddsse {
2974 edges = append(edges, signature.EdgeDsse)
2975 }
2976 if m.clearedtimestamps {
2977 edges = append(edges, signature.EdgeTimestamps)
2978 }
2979 return edges
2980 }
2981
2982 // EdgeCleared returns a boolean which indicates if the edge with the given name
2983 // was cleared in this mutation.
2984 func (m *SignatureMutation) EdgeCleared(name string) bool {
2985 switch name {
2986 case signature.EdgeDsse:
2987 return m.cleareddsse
2988 case signature.EdgeTimestamps:
2989 return m.clearedtimestamps
2990 }
2991 return false
2992 }
2993
2994 // ClearEdge clears the value of the edge with the given name. It returns an error
2995 // if that edge is not defined in the schema.
2996 func (m *SignatureMutation) ClearEdge(name string) error {
2997 switch name {
2998 case signature.EdgeDsse:
2999 m.ClearDsse()
3000 return nil
3001 }
3002 return fmt.Errorf("unknown Signature unique edge %s", name)
3003 }
3004
3005 // ResetEdge resets all changes to the edge with the given name in this mutation.
3006 // It returns an error if the edge is not defined in the schema.
3007 func (m *SignatureMutation) ResetEdge(name string) error {
3008 switch name {
3009 case signature.EdgeDsse:
3010 m.ResetDsse()
3011 return nil
3012 case signature.EdgeTimestamps:
3013 m.ResetTimestamps()
3014 return nil
3015 }
3016 return fmt.Errorf("unknown Signature edge %s", name)
3017 }
3018
3019 // StatementMutation represents an operation that mutates the Statement nodes in the graph.
3020 type StatementMutation struct {
3021 config
3022 op Op
3023 typ string
3024 id *uuid.UUID
3025 predicate *string
3026 clearedFields map[string]struct{}
3027 subjects map[uuid.UUID]struct{}
3028 removedsubjects map[uuid.UUID]struct{}
3029 clearedsubjects bool
3030 policy *uuid.UUID
3031 clearedpolicy bool
3032 attestation_collections *uuid.UUID
3033 clearedattestation_collections bool
3034 dsse map[uuid.UUID]struct{}
3035 removeddsse map[uuid.UUID]struct{}
3036 cleareddsse bool
3037 done bool
3038 oldValue func(context.Context) (*Statement, error)
3039 predicates []predicate.Statement
3040 }
3041
3042 var _ ent.Mutation = (*StatementMutation)(nil)
3043
3044 // statementOption allows management of the mutation configuration using functional options.
3045 type statementOption func(*StatementMutation)
3046
3047 // newStatementMutation creates new mutation for the Statement entity.
3048 func newStatementMutation(c config, op Op, opts ...statementOption) *StatementMutation {
3049 m := &StatementMutation{
3050 config: c,
3051 op: op,
3052 typ: TypeStatement,
3053 clearedFields: make(map[string]struct{}),
3054 }
3055 for _, opt := range opts {
3056 opt(m)
3057 }
3058 return m
3059 }
3060
3061 // withStatementID sets the ID field of the mutation.
3062 func withStatementID(id uuid.UUID) statementOption {
3063 return func(m *StatementMutation) {
3064 var (
3065 err error
3066 once sync.Once
3067 value *Statement
3068 )
3069 m.oldValue = func(ctx context.Context) (*Statement, error) {
3070 once.Do(func() {
3071 if m.done {
3072 err = errors.New("querying old values post mutation is not allowed")
3073 } else {
3074 value, err = m.Client().Statement.Get(ctx, id)
3075 }
3076 })
3077 return value, err
3078 }
3079 m.id = &id
3080 }
3081 }
3082
3083 // withStatement sets the old Statement of the mutation.
3084 func withStatement(node *Statement) statementOption {
3085 return func(m *StatementMutation) {
3086 m.oldValue = func(context.Context) (*Statement, error) {
3087 return node, nil
3088 }
3089 m.id = &node.ID
3090 }
3091 }
3092
3093 // Client returns a new `ent.Client` from the mutation. If the mutation was
3094 // executed in a transaction (ent.Tx), a transactional client is returned.
3095 func (m StatementMutation) Client() *Client {
3096 client := &Client{config: m.config}
3097 client.init()
3098 return client
3099 }
3100
3101 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
3102 // it returns an error otherwise.
3103 func (m StatementMutation) Tx() (*Tx, error) {
3104 if _, ok := m.driver.(*txDriver); !ok {
3105 return nil, errors.New("ent: mutation is not running in a transaction")
3106 }
3107 tx := &Tx{config: m.config}
3108 tx.init()
3109 return tx, nil
3110 }
3111
3112 // SetID sets the value of the id field. Note that this
3113 // operation is only accepted on creation of Statement entities.
3114 func (m *StatementMutation) SetID(id uuid.UUID) {
3115 m.id = &id
3116 }
3117
3118 // ID returns the ID value in the mutation. Note that the ID is only available
3119 // if it was provided to the builder or after it was returned from the database.
3120 func (m *StatementMutation) ID() (id uuid.UUID, exists bool) {
3121 if m.id == nil {
3122 return
3123 }
3124 return *m.id, true
3125 }
3126
3127 // IDs queries the database and returns the entity ids that match the mutation's predicate.
3128 // That means, if the mutation is applied within a transaction with an isolation level such
3129 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
3130 // or updated by the mutation.
3131 func (m *StatementMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
3132 switch {
3133 case m.op.Is(OpUpdateOne | OpDeleteOne):
3134 id, exists := m.ID()
3135 if exists {
3136 return []uuid.UUID{id}, nil
3137 }
3138 fallthrough
3139 case m.op.Is(OpUpdate | OpDelete):
3140 return m.Client().Statement.Query().Where(m.predicates...).IDs(ctx)
3141 default:
3142 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
3143 }
3144 }
3145
3146 // SetPredicate sets the "predicate" field.
3147 func (m *StatementMutation) SetPredicate(s string) {
3148 m.predicate = &s
3149 }
3150
3151 // Predicate returns the value of the "predicate" field in the mutation.
3152 func (m *StatementMutation) Predicate() (r string, exists bool) {
3153 v := m.predicate
3154 if v == nil {
3155 return
3156 }
3157 return *v, true
3158 }
3159
3160 // OldPredicate returns the old "predicate" field's value of the Statement entity.
3161 // If the Statement object wasn't provided to the builder, the object is fetched from the database.
3162 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
3163 func (m *StatementMutation) OldPredicate(ctx context.Context) (v string, err error) {
3164 if !m.op.Is(OpUpdateOne) {
3165 return v, errors.New("OldPredicate is only allowed on UpdateOne operations")
3166 }
3167 if m.id == nil || m.oldValue == nil {
3168 return v, errors.New("OldPredicate requires an ID field in the mutation")
3169 }
3170 oldValue, err := m.oldValue(ctx)
3171 if err != nil {
3172 return v, fmt.Errorf("querying old value for OldPredicate: %w", err)
3173 }
3174 return oldValue.Predicate, nil
3175 }
3176
3177 // ResetPredicate resets all changes to the "predicate" field.
3178 func (m *StatementMutation) ResetPredicate() {
3179 m.predicate = nil
3180 }
3181
3182 // AddSubjectIDs adds the "subjects" edge to the Subject entity by ids.
3183 func (m *StatementMutation) AddSubjectIDs(ids ...uuid.UUID) {
3184 if m.subjects == nil {
3185 m.subjects = make(map[uuid.UUID]struct{})
3186 }
3187 for i := range ids {
3188 m.subjects[ids[i]] = struct{}{}
3189 }
3190 }
3191
3192 // ClearSubjects clears the "subjects" edge to the Subject entity.
3193 func (m *StatementMutation) ClearSubjects() {
3194 m.clearedsubjects = true
3195 }
3196
3197 // SubjectsCleared reports if the "subjects" edge to the Subject entity was cleared.
3198 func (m *StatementMutation) SubjectsCleared() bool {
3199 return m.clearedsubjects
3200 }
3201
3202 // RemoveSubjectIDs removes the "subjects" edge to the Subject entity by IDs.
3203 func (m *StatementMutation) RemoveSubjectIDs(ids ...uuid.UUID) {
3204 if m.removedsubjects == nil {
3205 m.removedsubjects = make(map[uuid.UUID]struct{})
3206 }
3207 for i := range ids {
3208 delete(m.subjects, ids[i])
3209 m.removedsubjects[ids[i]] = struct{}{}
3210 }
3211 }
3212
3213 // RemovedSubjects returns the removed IDs of the "subjects" edge to the Subject entity.
3214 func (m *StatementMutation) RemovedSubjectsIDs() (ids []uuid.UUID) {
3215 for id := range m.removedsubjects {
3216 ids = append(ids, id)
3217 }
3218 return
3219 }
3220
3221 // SubjectsIDs returns the "subjects" edge IDs in the mutation.
3222 func (m *StatementMutation) SubjectsIDs() (ids []uuid.UUID) {
3223 for id := range m.subjects {
3224 ids = append(ids, id)
3225 }
3226 return
3227 }
3228
3229 // ResetSubjects resets all changes to the "subjects" edge.
3230 func (m *StatementMutation) ResetSubjects() {
3231 m.subjects = nil
3232 m.clearedsubjects = false
3233 m.removedsubjects = nil
3234 }
3235
3236 // SetPolicyID sets the "policy" edge to the AttestationPolicy entity by id.
3237 func (m *StatementMutation) SetPolicyID(id uuid.UUID) {
3238 m.policy = &id
3239 }
3240
3241 // ClearPolicy clears the "policy" edge to the AttestationPolicy entity.
3242 func (m *StatementMutation) ClearPolicy() {
3243 m.clearedpolicy = true
3244 }
3245
3246 // PolicyCleared reports if the "policy" edge to the AttestationPolicy entity was cleared.
3247 func (m *StatementMutation) PolicyCleared() bool {
3248 return m.clearedpolicy
3249 }
3250
3251 // PolicyID returns the "policy" edge ID in the mutation.
3252 func (m *StatementMutation) PolicyID() (id uuid.UUID, exists bool) {
3253 if m.policy != nil {
3254 return *m.policy, true
3255 }
3256 return
3257 }
3258
3259 // PolicyIDs returns the "policy" edge IDs in the mutation.
3260 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
3261 // PolicyID instead. It exists only for internal usage by the builders.
3262 func (m *StatementMutation) PolicyIDs() (ids []uuid.UUID) {
3263 if id := m.policy; id != nil {
3264 ids = append(ids, *id)
3265 }
3266 return
3267 }
3268
3269 // ResetPolicy resets all changes to the "policy" edge.
3270 func (m *StatementMutation) ResetPolicy() {
3271 m.policy = nil
3272 m.clearedpolicy = false
3273 }
3274
3275 // SetAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by id.
3276 func (m *StatementMutation) SetAttestationCollectionsID(id uuid.UUID) {
3277 m.attestation_collections = &id
3278 }
3279
3280 // ClearAttestationCollections clears the "attestation_collections" edge to the AttestationCollection entity.
3281 func (m *StatementMutation) ClearAttestationCollections() {
3282 m.clearedattestation_collections = true
3283 }
3284
3285 // AttestationCollectionsCleared reports if the "attestation_collections" edge to the AttestationCollection entity was cleared.
3286 func (m *StatementMutation) AttestationCollectionsCleared() bool {
3287 return m.clearedattestation_collections
3288 }
3289
3290 // AttestationCollectionsID returns the "attestation_collections" edge ID in the mutation.
3291 func (m *StatementMutation) AttestationCollectionsID() (id uuid.UUID, exists bool) {
3292 if m.attestation_collections != nil {
3293 return *m.attestation_collections, true
3294 }
3295 return
3296 }
3297
3298 // AttestationCollectionsIDs returns the "attestation_collections" edge IDs in the mutation.
3299 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
3300 // AttestationCollectionsID instead. It exists only for internal usage by the builders.
3301 func (m *StatementMutation) AttestationCollectionsIDs() (ids []uuid.UUID) {
3302 if id := m.attestation_collections; id != nil {
3303 ids = append(ids, *id)
3304 }
3305 return
3306 }
3307
3308 // ResetAttestationCollections resets all changes to the "attestation_collections" edge.
3309 func (m *StatementMutation) ResetAttestationCollections() {
3310 m.attestation_collections = nil
3311 m.clearedattestation_collections = false
3312 }
3313
3314 // AddDsseIDs adds the "dsse" edge to the Dsse entity by ids.
3315 func (m *StatementMutation) AddDsseIDs(ids ...uuid.UUID) {
3316 if m.dsse == nil {
3317 m.dsse = make(map[uuid.UUID]struct{})
3318 }
3319 for i := range ids {
3320 m.dsse[ids[i]] = struct{}{}
3321 }
3322 }
3323
3324 // ClearDsse clears the "dsse" edge to the Dsse entity.
3325 func (m *StatementMutation) ClearDsse() {
3326 m.cleareddsse = true
3327 }
3328
3329 // DsseCleared reports if the "dsse" edge to the Dsse entity was cleared.
3330 func (m *StatementMutation) DsseCleared() bool {
3331 return m.cleareddsse
3332 }
3333
3334 // RemoveDsseIDs removes the "dsse" edge to the Dsse entity by IDs.
3335 func (m *StatementMutation) RemoveDsseIDs(ids ...uuid.UUID) {
3336 if m.removeddsse == nil {
3337 m.removeddsse = make(map[uuid.UUID]struct{})
3338 }
3339 for i := range ids {
3340 delete(m.dsse, ids[i])
3341 m.removeddsse[ids[i]] = struct{}{}
3342 }
3343 }
3344
3345 // RemovedDsse returns the removed IDs of the "dsse" edge to the Dsse entity.
3346 func (m *StatementMutation) RemovedDsseIDs() (ids []uuid.UUID) {
3347 for id := range m.removeddsse {
3348 ids = append(ids, id)
3349 }
3350 return
3351 }
3352
3353 // DsseIDs returns the "dsse" edge IDs in the mutation.
3354 func (m *StatementMutation) DsseIDs() (ids []uuid.UUID) {
3355 for id := range m.dsse {
3356 ids = append(ids, id)
3357 }
3358 return
3359 }
3360
3361 // ResetDsse resets all changes to the "dsse" edge.
3362 func (m *StatementMutation) ResetDsse() {
3363 m.dsse = nil
3364 m.cleareddsse = false
3365 m.removeddsse = nil
3366 }
3367
3368 // Where appends a list predicates to the StatementMutation builder.
3369 func (m *StatementMutation) Where(ps ...predicate.Statement) {
3370 m.predicates = append(m.predicates, ps...)
3371 }
3372
3373 // WhereP appends storage-level predicates to the StatementMutation builder. Using this method,
3374 // users can use type-assertion to append predicates that do not depend on any generated package.
3375 func (m *StatementMutation) WhereP(ps ...func(*sql.Selector)) {
3376 p := make([]predicate.Statement, len(ps))
3377 for i := range ps {
3378 p[i] = ps[i]
3379 }
3380 m.Where(p...)
3381 }
3382
3383 // Op returns the operation name.
3384 func (m *StatementMutation) Op() Op {
3385 return m.op
3386 }
3387
3388 // SetOp allows setting the mutation operation.
3389 func (m *StatementMutation) SetOp(op Op) {
3390 m.op = op
3391 }
3392
3393 // Type returns the node type of this mutation (Statement).
3394 func (m *StatementMutation) Type() string {
3395 return m.typ
3396 }
3397
3398 // Fields returns all fields that were changed during this mutation. Note that in
3399 // order to get all numeric fields that were incremented/decremented, call
3400 // AddedFields().
3401 func (m *StatementMutation) Fields() []string {
3402 fields := make([]string, 0, 1)
3403 if m.predicate != nil {
3404 fields = append(fields, statement.FieldPredicate)
3405 }
3406 return fields
3407 }
3408
3409 // Field returns the value of a field with the given name. The second boolean
3410 // return value indicates that this field was not set, or was not defined in the
3411 // schema.
3412 func (m *StatementMutation) Field(name string) (ent.Value, bool) {
3413 switch name {
3414 case statement.FieldPredicate:
3415 return m.Predicate()
3416 }
3417 return nil, false
3418 }
3419
3420 // OldField returns the old value of the field from the database. An error is
3421 // returned if the mutation operation is not UpdateOne, or the query to the
3422 // database failed.
3423 func (m *StatementMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
3424 switch name {
3425 case statement.FieldPredicate:
3426 return m.OldPredicate(ctx)
3427 }
3428 return nil, fmt.Errorf("unknown Statement field %s", name)
3429 }
3430
3431 // SetField sets the value of a field with the given name. It returns an error if
3432 // the field is not defined in the schema, or if the type mismatched the field
3433 // type.
3434 func (m *StatementMutation) SetField(name string, value ent.Value) error {
3435 switch name {
3436 case statement.FieldPredicate:
3437 v, ok := value.(string)
3438 if !ok {
3439 return fmt.Errorf("unexpected type %T for field %s", value, name)
3440 }
3441 m.SetPredicate(v)
3442 return nil
3443 }
3444 return fmt.Errorf("unknown Statement field %s", name)
3445 }
3446
3447 // AddedFields returns all numeric fields that were incremented/decremented during
3448 // this mutation.
3449 func (m *StatementMutation) AddedFields() []string {
3450 return nil
3451 }
3452
3453 // AddedField returns the numeric value that was incremented/decremented on a field
3454 // with the given name. The second boolean return value indicates that this field
3455 // was not set, or was not defined in the schema.
3456 func (m *StatementMutation) AddedField(name string) (ent.Value, bool) {
3457 return nil, false
3458 }
3459
3460 // AddField adds the value to the field with the given name. It returns an error if
3461 // the field is not defined in the schema, or if the type mismatched the field
3462 // type.
3463 func (m *StatementMutation) AddField(name string, value ent.Value) error {
3464 switch name {
3465 }
3466 return fmt.Errorf("unknown Statement numeric field %s", name)
3467 }
3468
3469 // ClearedFields returns all nullable fields that were cleared during this
3470 // mutation.
3471 func (m *StatementMutation) ClearedFields() []string {
3472 return nil
3473 }
3474
3475 // FieldCleared returns a boolean indicating if a field with the given name was
3476 // cleared in this mutation.
3477 func (m *StatementMutation) FieldCleared(name string) bool {
3478 _, ok := m.clearedFields[name]
3479 return ok
3480 }
3481
3482 // ClearField clears the value of the field with the given name. It returns an
3483 // error if the field is not defined in the schema.
3484 func (m *StatementMutation) ClearField(name string) error {
3485 return fmt.Errorf("unknown Statement nullable field %s", name)
3486 }
3487
3488 // ResetField resets all changes in the mutation for the field with the given name.
3489 // It returns an error if the field is not defined in the schema.
3490 func (m *StatementMutation) ResetField(name string) error {
3491 switch name {
3492 case statement.FieldPredicate:
3493 m.ResetPredicate()
3494 return nil
3495 }
3496 return fmt.Errorf("unknown Statement field %s", name)
3497 }
3498
3499 // AddedEdges returns all edge names that were set/added in this mutation.
3500 func (m *StatementMutation) AddedEdges() []string {
3501 edges := make([]string, 0, 4)
3502 if m.subjects != nil {
3503 edges = append(edges, statement.EdgeSubjects)
3504 }
3505 if m.policy != nil {
3506 edges = append(edges, statement.EdgePolicy)
3507 }
3508 if m.attestation_collections != nil {
3509 edges = append(edges, statement.EdgeAttestationCollections)
3510 }
3511 if m.dsse != nil {
3512 edges = append(edges, statement.EdgeDsse)
3513 }
3514 return edges
3515 }
3516
3517 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
3518 // name in this mutation.
3519 func (m *StatementMutation) AddedIDs(name string) []ent.Value {
3520 switch name {
3521 case statement.EdgeSubjects:
3522 ids := make([]ent.Value, 0, len(m.subjects))
3523 for id := range m.subjects {
3524 ids = append(ids, id)
3525 }
3526 return ids
3527 case statement.EdgePolicy:
3528 if id := m.policy; id != nil {
3529 return []ent.Value{*id}
3530 }
3531 case statement.EdgeAttestationCollections:
3532 if id := m.attestation_collections; id != nil {
3533 return []ent.Value{*id}
3534 }
3535 case statement.EdgeDsse:
3536 ids := make([]ent.Value, 0, len(m.dsse))
3537 for id := range m.dsse {
3538 ids = append(ids, id)
3539 }
3540 return ids
3541 }
3542 return nil
3543 }
3544
3545 // RemovedEdges returns all edge names that were removed in this mutation.
3546 func (m *StatementMutation) RemovedEdges() []string {
3547 edges := make([]string, 0, 4)
3548 if m.removedsubjects != nil {
3549 edges = append(edges, statement.EdgeSubjects)
3550 }
3551 if m.removeddsse != nil {
3552 edges = append(edges, statement.EdgeDsse)
3553 }
3554 return edges
3555 }
3556
3557 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
3558 // the given name in this mutation.
3559 func (m *StatementMutation) RemovedIDs(name string) []ent.Value {
3560 switch name {
3561 case statement.EdgeSubjects:
3562 ids := make([]ent.Value, 0, len(m.removedsubjects))
3563 for id := range m.removedsubjects {
3564 ids = append(ids, id)
3565 }
3566 return ids
3567 case statement.EdgeDsse:
3568 ids := make([]ent.Value, 0, len(m.removeddsse))
3569 for id := range m.removeddsse {
3570 ids = append(ids, id)
3571 }
3572 return ids
3573 }
3574 return nil
3575 }
3576
3577 // ClearedEdges returns all edge names that were cleared in this mutation.
3578 func (m *StatementMutation) ClearedEdges() []string {
3579 edges := make([]string, 0, 4)
3580 if m.clearedsubjects {
3581 edges = append(edges, statement.EdgeSubjects)
3582 }
3583 if m.clearedpolicy {
3584 edges = append(edges, statement.EdgePolicy)
3585 }
3586 if m.clearedattestation_collections {
3587 edges = append(edges, statement.EdgeAttestationCollections)
3588 }
3589 if m.cleareddsse {
3590 edges = append(edges, statement.EdgeDsse)
3591 }
3592 return edges
3593 }
3594
3595 // EdgeCleared returns a boolean which indicates if the edge with the given name
3596 // was cleared in this mutation.
3597 func (m *StatementMutation) EdgeCleared(name string) bool {
3598 switch name {
3599 case statement.EdgeSubjects:
3600 return m.clearedsubjects
3601 case statement.EdgePolicy:
3602 return m.clearedpolicy
3603 case statement.EdgeAttestationCollections:
3604 return m.clearedattestation_collections
3605 case statement.EdgeDsse:
3606 return m.cleareddsse
3607 }
3608 return false
3609 }
3610
3611 // ClearEdge clears the value of the edge with the given name. It returns an error
3612 // if that edge is not defined in the schema.
3613 func (m *StatementMutation) ClearEdge(name string) error {
3614 switch name {
3615 case statement.EdgePolicy:
3616 m.ClearPolicy()
3617 return nil
3618 case statement.EdgeAttestationCollections:
3619 m.ClearAttestationCollections()
3620 return nil
3621 }
3622 return fmt.Errorf("unknown Statement unique edge %s", name)
3623 }
3624
3625 // ResetEdge resets all changes to the edge with the given name in this mutation.
3626 // It returns an error if the edge is not defined in the schema.
3627 func (m *StatementMutation) ResetEdge(name string) error {
3628 switch name {
3629 case statement.EdgeSubjects:
3630 m.ResetSubjects()
3631 return nil
3632 case statement.EdgePolicy:
3633 m.ResetPolicy()
3634 return nil
3635 case statement.EdgeAttestationCollections:
3636 m.ResetAttestationCollections()
3637 return nil
3638 case statement.EdgeDsse:
3639 m.ResetDsse()
3640 return nil
3641 }
3642 return fmt.Errorf("unknown Statement edge %s", name)
3643 }
3644
3645 // SubjectMutation represents an operation that mutates the Subject nodes in the graph.
3646 type SubjectMutation struct {
3647 config
3648 op Op
3649 typ string
3650 id *uuid.UUID
3651 created_at *time.Time
3652 name *string
3653 clearedFields map[string]struct{}
3654 subject_digests map[uuid.UUID]struct{}
3655 removedsubject_digests map[uuid.UUID]struct{}
3656 clearedsubject_digests bool
3657 statement *uuid.UUID
3658 clearedstatement bool
3659 done bool
3660 oldValue func(context.Context) (*Subject, error)
3661 predicates []predicate.Subject
3662 }
3663
3664 var _ ent.Mutation = (*SubjectMutation)(nil)
3665
3666 // subjectOption allows management of the mutation configuration using functional options.
3667 type subjectOption func(*SubjectMutation)
3668
3669 // newSubjectMutation creates new mutation for the Subject entity.
3670 func newSubjectMutation(c config, op Op, opts ...subjectOption) *SubjectMutation {
3671 m := &SubjectMutation{
3672 config: c,
3673 op: op,
3674 typ: TypeSubject,
3675 clearedFields: make(map[string]struct{}),
3676 }
3677 for _, opt := range opts {
3678 opt(m)
3679 }
3680 return m
3681 }
3682
3683 // withSubjectID sets the ID field of the mutation.
3684 func withSubjectID(id uuid.UUID) subjectOption {
3685 return func(m *SubjectMutation) {
3686 var (
3687 err error
3688 once sync.Once
3689 value *Subject
3690 )
3691 m.oldValue = func(ctx context.Context) (*Subject, error) {
3692 once.Do(func() {
3693 if m.done {
3694 err = errors.New("querying old values post mutation is not allowed")
3695 } else {
3696 value, err = m.Client().Subject.Get(ctx, id)
3697 }
3698 })
3699 return value, err
3700 }
3701 m.id = &id
3702 }
3703 }
3704
3705 // withSubject sets the old Subject of the mutation.
3706 func withSubject(node *Subject) subjectOption {
3707 return func(m *SubjectMutation) {
3708 m.oldValue = func(context.Context) (*Subject, error) {
3709 return node, nil
3710 }
3711 m.id = &node.ID
3712 }
3713 }
3714
3715 // Client returns a new `ent.Client` from the mutation. If the mutation was
3716 // executed in a transaction (ent.Tx), a transactional client is returned.
3717 func (m SubjectMutation) Client() *Client {
3718 client := &Client{config: m.config}
3719 client.init()
3720 return client
3721 }
3722
3723 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
3724 // it returns an error otherwise.
3725 func (m SubjectMutation) Tx() (*Tx, error) {
3726 if _, ok := m.driver.(*txDriver); !ok {
3727 return nil, errors.New("ent: mutation is not running in a transaction")
3728 }
3729 tx := &Tx{config: m.config}
3730 tx.init()
3731 return tx, nil
3732 }
3733
3734 // SetID sets the value of the id field. Note that this
3735 // operation is only accepted on creation of Subject entities.
3736 func (m *SubjectMutation) SetID(id uuid.UUID) {
3737 m.id = &id
3738 }
3739
3740 // ID returns the ID value in the mutation. Note that the ID is only available
3741 // if it was provided to the builder or after it was returned from the database.
3742 func (m *SubjectMutation) ID() (id uuid.UUID, exists bool) {
3743 if m.id == nil {
3744 return
3745 }
3746 return *m.id, true
3747 }
3748
3749 // IDs queries the database and returns the entity ids that match the mutation's predicate.
3750 // That means, if the mutation is applied within a transaction with an isolation level such
3751 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
3752 // or updated by the mutation.
3753 func (m *SubjectMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
3754 switch {
3755 case m.op.Is(OpUpdateOne | OpDeleteOne):
3756 id, exists := m.ID()
3757 if exists {
3758 return []uuid.UUID{id}, nil
3759 }
3760 fallthrough
3761 case m.op.Is(OpUpdate | OpDelete):
3762 return m.Client().Subject.Query().Where(m.predicates...).IDs(ctx)
3763 default:
3764 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
3765 }
3766 }
3767
3768 // SetCreatedAt sets the "created_at" field.
3769 func (m *SubjectMutation) SetCreatedAt(t time.Time) {
3770 m.created_at = &t
3771 }
3772
3773 // CreatedAt returns the value of the "created_at" field in the mutation.
3774 func (m *SubjectMutation) CreatedAt() (r time.Time, exists bool) {
3775 v := m.created_at
3776 if v == nil {
3777 return
3778 }
3779 return *v, true
3780 }
3781
3782 // OldCreatedAt returns the old "created_at" field's value of the Subject entity.
3783 // If the Subject object wasn't provided to the builder, the object is fetched from the database.
3784 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
3785 func (m *SubjectMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) {
3786 if !m.op.Is(OpUpdateOne) {
3787 return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
3788 }
3789 if m.id == nil || m.oldValue == nil {
3790 return v, errors.New("OldCreatedAt requires an ID field in the mutation")
3791 }
3792 oldValue, err := m.oldValue(ctx)
3793 if err != nil {
3794 return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
3795 }
3796 return oldValue.CreatedAt, nil
3797 }
3798
3799 // ClearCreatedAt clears the value of the "created_at" field.
3800 func (m *SubjectMutation) ClearCreatedAt() {
3801 m.created_at = nil
3802 m.clearedFields[subject.FieldCreatedAt] = struct{}{}
3803 }
3804
3805 // CreatedAtCleared returns if the "created_at" field was cleared in this mutation.
3806 func (m *SubjectMutation) CreatedAtCleared() bool {
3807 _, ok := m.clearedFields[subject.FieldCreatedAt]
3808 return ok
3809 }
3810
3811 // ResetCreatedAt resets all changes to the "created_at" field.
3812 func (m *SubjectMutation) ResetCreatedAt() {
3813 m.created_at = nil
3814 delete(m.clearedFields, subject.FieldCreatedAt)
3815 }
3816
3817 // SetName sets the "name" field.
3818 func (m *SubjectMutation) SetName(s string) {
3819 m.name = &s
3820 }
3821
3822 // Name returns the value of the "name" field in the mutation.
3823 func (m *SubjectMutation) Name() (r string, exists bool) {
3824 v := m.name
3825 if v == nil {
3826 return
3827 }
3828 return *v, true
3829 }
3830
3831 // OldName returns the old "name" field's value of the Subject entity.
3832 // If the Subject object wasn't provided to the builder, the object is fetched from the database.
3833 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
3834 func (m *SubjectMutation) OldName(ctx context.Context) (v string, err error) {
3835 if !m.op.Is(OpUpdateOne) {
3836 return v, errors.New("OldName is only allowed on UpdateOne operations")
3837 }
3838 if m.id == nil || m.oldValue == nil {
3839 return v, errors.New("OldName requires an ID field in the mutation")
3840 }
3841 oldValue, err := m.oldValue(ctx)
3842 if err != nil {
3843 return v, fmt.Errorf("querying old value for OldName: %w", err)
3844 }
3845 return oldValue.Name, nil
3846 }
3847
3848 // ResetName resets all changes to the "name" field.
3849 func (m *SubjectMutation) ResetName() {
3850 m.name = nil
3851 }
3852
3853 // AddSubjectDigestIDs adds the "subject_digests" edge to the SubjectDigest entity by ids.
3854 func (m *SubjectMutation) AddSubjectDigestIDs(ids ...uuid.UUID) {
3855 if m.subject_digests == nil {
3856 m.subject_digests = make(map[uuid.UUID]struct{})
3857 }
3858 for i := range ids {
3859 m.subject_digests[ids[i]] = struct{}{}
3860 }
3861 }
3862
3863 // ClearSubjectDigests clears the "subject_digests" edge to the SubjectDigest entity.
3864 func (m *SubjectMutation) ClearSubjectDigests() {
3865 m.clearedsubject_digests = true
3866 }
3867
3868 // SubjectDigestsCleared reports if the "subject_digests" edge to the SubjectDigest entity was cleared.
3869 func (m *SubjectMutation) SubjectDigestsCleared() bool {
3870 return m.clearedsubject_digests
3871 }
3872
3873 // RemoveSubjectDigestIDs removes the "subject_digests" edge to the SubjectDigest entity by IDs.
3874 func (m *SubjectMutation) RemoveSubjectDigestIDs(ids ...uuid.UUID) {
3875 if m.removedsubject_digests == nil {
3876 m.removedsubject_digests = make(map[uuid.UUID]struct{})
3877 }
3878 for i := range ids {
3879 delete(m.subject_digests, ids[i])
3880 m.removedsubject_digests[ids[i]] = struct{}{}
3881 }
3882 }
3883
3884 // RemovedSubjectDigests returns the removed IDs of the "subject_digests" edge to the SubjectDigest entity.
3885 func (m *SubjectMutation) RemovedSubjectDigestsIDs() (ids []uuid.UUID) {
3886 for id := range m.removedsubject_digests {
3887 ids = append(ids, id)
3888 }
3889 return
3890 }
3891
3892 // SubjectDigestsIDs returns the "subject_digests" edge IDs in the mutation.
3893 func (m *SubjectMutation) SubjectDigestsIDs() (ids []uuid.UUID) {
3894 for id := range m.subject_digests {
3895 ids = append(ids, id)
3896 }
3897 return
3898 }
3899
3900 // ResetSubjectDigests resets all changes to the "subject_digests" edge.
3901 func (m *SubjectMutation) ResetSubjectDigests() {
3902 m.subject_digests = nil
3903 m.clearedsubject_digests = false
3904 m.removedsubject_digests = nil
3905 }
3906
3907 // SetStatementID sets the "statement" edge to the Statement entity by id.
3908 func (m *SubjectMutation) SetStatementID(id uuid.UUID) {
3909 m.statement = &id
3910 }
3911
3912 // ClearStatement clears the "statement" edge to the Statement entity.
3913 func (m *SubjectMutation) ClearStatement() {
3914 m.clearedstatement = true
3915 }
3916
3917 // StatementCleared reports if the "statement" edge to the Statement entity was cleared.
3918 func (m *SubjectMutation) StatementCleared() bool {
3919 return m.clearedstatement
3920 }
3921
3922 // StatementID returns the "statement" edge ID in the mutation.
3923 func (m *SubjectMutation) StatementID() (id uuid.UUID, exists bool) {
3924 if m.statement != nil {
3925 return *m.statement, true
3926 }
3927 return
3928 }
3929
3930 // StatementIDs returns the "statement" edge IDs in the mutation.
3931 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
3932 // StatementID instead. It exists only for internal usage by the builders.
3933 func (m *SubjectMutation) StatementIDs() (ids []uuid.UUID) {
3934 if id := m.statement; id != nil {
3935 ids = append(ids, *id)
3936 }
3937 return
3938 }
3939
3940 // ResetStatement resets all changes to the "statement" edge.
3941 func (m *SubjectMutation) ResetStatement() {
3942 m.statement = nil
3943 m.clearedstatement = false
3944 }
3945
3946 // Where appends a list predicates to the SubjectMutation builder.
3947 func (m *SubjectMutation) Where(ps ...predicate.Subject) {
3948 m.predicates = append(m.predicates, ps...)
3949 }
3950
3951 // WhereP appends storage-level predicates to the SubjectMutation builder. Using this method,
3952 // users can use type-assertion to append predicates that do not depend on any generated package.
3953 func (m *SubjectMutation) WhereP(ps ...func(*sql.Selector)) {
3954 p := make([]predicate.Subject, len(ps))
3955 for i := range ps {
3956 p[i] = ps[i]
3957 }
3958 m.Where(p...)
3959 }
3960
3961 // Op returns the operation name.
3962 func (m *SubjectMutation) Op() Op {
3963 return m.op
3964 }
3965
3966 // SetOp allows setting the mutation operation.
3967 func (m *SubjectMutation) SetOp(op Op) {
3968 m.op = op
3969 }
3970
3971 // Type returns the node type of this mutation (Subject).
3972 func (m *SubjectMutation) Type() string {
3973 return m.typ
3974 }
3975
3976 // Fields returns all fields that were changed during this mutation. Note that in
3977 // order to get all numeric fields that were incremented/decremented, call
3978 // AddedFields().
3979 func (m *SubjectMutation) Fields() []string {
3980 fields := make([]string, 0, 2)
3981 if m.created_at != nil {
3982 fields = append(fields, subject.FieldCreatedAt)
3983 }
3984 if m.name != nil {
3985 fields = append(fields, subject.FieldName)
3986 }
3987 return fields
3988 }
3989
3990 // Field returns the value of a field with the given name. The second boolean
3991 // return value indicates that this field was not set, or was not defined in the
3992 // schema.
3993 func (m *SubjectMutation) Field(name string) (ent.Value, bool) {
3994 switch name {
3995 case subject.FieldCreatedAt:
3996 return m.CreatedAt()
3997 case subject.FieldName:
3998 return m.Name()
3999 }
4000 return nil, false
4001 }
4002
4003 // OldField returns the old value of the field from the database. An error is
4004 // returned if the mutation operation is not UpdateOne, or the query to the
4005 // database failed.
4006 func (m *SubjectMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
4007 switch name {
4008 case subject.FieldCreatedAt:
4009 return m.OldCreatedAt(ctx)
4010 case subject.FieldName:
4011 return m.OldName(ctx)
4012 }
4013 return nil, fmt.Errorf("unknown Subject field %s", name)
4014 }
4015
4016 // SetField sets the value of a field with the given name. It returns an error if
4017 // the field is not defined in the schema, or if the type mismatched the field
4018 // type.
4019 func (m *SubjectMutation) SetField(name string, value ent.Value) error {
4020 switch name {
4021 case subject.FieldCreatedAt:
4022 v, ok := value.(time.Time)
4023 if !ok {
4024 return fmt.Errorf("unexpected type %T for field %s", value, name)
4025 }
4026 m.SetCreatedAt(v)
4027 return nil
4028 case subject.FieldName:
4029 v, ok := value.(string)
4030 if !ok {
4031 return fmt.Errorf("unexpected type %T for field %s", value, name)
4032 }
4033 m.SetName(v)
4034 return nil
4035 }
4036 return fmt.Errorf("unknown Subject field %s", name)
4037 }
4038
4039 // AddedFields returns all numeric fields that were incremented/decremented during
4040 // this mutation.
4041 func (m *SubjectMutation) AddedFields() []string {
4042 return nil
4043 }
4044
4045 // AddedField returns the numeric value that was incremented/decremented on a field
4046 // with the given name. The second boolean return value indicates that this field
4047 // was not set, or was not defined in the schema.
4048 func (m *SubjectMutation) AddedField(name string) (ent.Value, bool) {
4049 return nil, false
4050 }
4051
4052 // AddField adds the value to the field with the given name. It returns an error if
4053 // the field is not defined in the schema, or if the type mismatched the field
4054 // type.
4055 func (m *SubjectMutation) AddField(name string, value ent.Value) error {
4056 switch name {
4057 }
4058 return fmt.Errorf("unknown Subject numeric field %s", name)
4059 }
4060
4061 // ClearedFields returns all nullable fields that were cleared during this
4062 // mutation.
4063 func (m *SubjectMutation) ClearedFields() []string {
4064 var fields []string
4065 if m.FieldCleared(subject.FieldCreatedAt) {
4066 fields = append(fields, subject.FieldCreatedAt)
4067 }
4068 return fields
4069 }
4070
4071 // FieldCleared returns a boolean indicating if a field with the given name was
4072 // cleared in this mutation.
4073 func (m *SubjectMutation) FieldCleared(name string) bool {
4074 _, ok := m.clearedFields[name]
4075 return ok
4076 }
4077
4078 // ClearField clears the value of the field with the given name. It returns an
4079 // error if the field is not defined in the schema.
4080 func (m *SubjectMutation) ClearField(name string) error {
4081 switch name {
4082 case subject.FieldCreatedAt:
4083 m.ClearCreatedAt()
4084 return nil
4085 }
4086 return fmt.Errorf("unknown Subject nullable field %s", name)
4087 }
4088
4089 // ResetField resets all changes in the mutation for the field with the given name.
4090 // It returns an error if the field is not defined in the schema.
4091 func (m *SubjectMutation) ResetField(name string) error {
4092 switch name {
4093 case subject.FieldCreatedAt:
4094 m.ResetCreatedAt()
4095 return nil
4096 case subject.FieldName:
4097 m.ResetName()
4098 return nil
4099 }
4100 return fmt.Errorf("unknown Subject field %s", name)
4101 }
4102
4103 // AddedEdges returns all edge names that were set/added in this mutation.
4104 func (m *SubjectMutation) AddedEdges() []string {
4105 edges := make([]string, 0, 2)
4106 if m.subject_digests != nil {
4107 edges = append(edges, subject.EdgeSubjectDigests)
4108 }
4109 if m.statement != nil {
4110 edges = append(edges, subject.EdgeStatement)
4111 }
4112 return edges
4113 }
4114
4115 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
4116 // name in this mutation.
4117 func (m *SubjectMutation) AddedIDs(name string) []ent.Value {
4118 switch name {
4119 case subject.EdgeSubjectDigests:
4120 ids := make([]ent.Value, 0, len(m.subject_digests))
4121 for id := range m.subject_digests {
4122 ids = append(ids, id)
4123 }
4124 return ids
4125 case subject.EdgeStatement:
4126 if id := m.statement; id != nil {
4127 return []ent.Value{*id}
4128 }
4129 }
4130 return nil
4131 }
4132
4133 // RemovedEdges returns all edge names that were removed in this mutation.
4134 func (m *SubjectMutation) RemovedEdges() []string {
4135 edges := make([]string, 0, 2)
4136 if m.removedsubject_digests != nil {
4137 edges = append(edges, subject.EdgeSubjectDigests)
4138 }
4139 return edges
4140 }
4141
4142 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
4143 // the given name in this mutation.
4144 func (m *SubjectMutation) RemovedIDs(name string) []ent.Value {
4145 switch name {
4146 case subject.EdgeSubjectDigests:
4147 ids := make([]ent.Value, 0, len(m.removedsubject_digests))
4148 for id := range m.removedsubject_digests {
4149 ids = append(ids, id)
4150 }
4151 return ids
4152 }
4153 return nil
4154 }
4155
4156 // ClearedEdges returns all edge names that were cleared in this mutation.
4157 func (m *SubjectMutation) ClearedEdges() []string {
4158 edges := make([]string, 0, 2)
4159 if m.clearedsubject_digests {
4160 edges = append(edges, subject.EdgeSubjectDigests)
4161 }
4162 if m.clearedstatement {
4163 edges = append(edges, subject.EdgeStatement)
4164 }
4165 return edges
4166 }
4167
4168 // EdgeCleared returns a boolean which indicates if the edge with the given name
4169 // was cleared in this mutation.
4170 func (m *SubjectMutation) EdgeCleared(name string) bool {
4171 switch name {
4172 case subject.EdgeSubjectDigests:
4173 return m.clearedsubject_digests
4174 case subject.EdgeStatement:
4175 return m.clearedstatement
4176 }
4177 return false
4178 }
4179
4180 // ClearEdge clears the value of the edge with the given name. It returns an error
4181 // if that edge is not defined in the schema.
4182 func (m *SubjectMutation) ClearEdge(name string) error {
4183 switch name {
4184 case subject.EdgeStatement:
4185 m.ClearStatement()
4186 return nil
4187 }
4188 return fmt.Errorf("unknown Subject unique edge %s", name)
4189 }
4190
4191 // ResetEdge resets all changes to the edge with the given name in this mutation.
4192 // It returns an error if the edge is not defined in the schema.
4193 func (m *SubjectMutation) ResetEdge(name string) error {
4194 switch name {
4195 case subject.EdgeSubjectDigests:
4196 m.ResetSubjectDigests()
4197 return nil
4198 case subject.EdgeStatement:
4199 m.ResetStatement()
4200 return nil
4201 }
4202 return fmt.Errorf("unknown Subject edge %s", name)
4203 }
4204
4205 // SubjectDigestMutation represents an operation that mutates the SubjectDigest nodes in the graph.
4206 type SubjectDigestMutation struct {
4207 config
4208 op Op
4209 typ string
4210 id *uuid.UUID
4211 algorithm *string
4212 value *string
4213 clearedFields map[string]struct{}
4214 subject *uuid.UUID
4215 clearedsubject bool
4216 done bool
4217 oldValue func(context.Context) (*SubjectDigest, error)
4218 predicates []predicate.SubjectDigest
4219 }
4220
4221 var _ ent.Mutation = (*SubjectDigestMutation)(nil)
4222
4223 // subjectdigestOption allows management of the mutation configuration using functional options.
4224 type subjectdigestOption func(*SubjectDigestMutation)
4225
4226 // newSubjectDigestMutation creates new mutation for the SubjectDigest entity.
4227 func newSubjectDigestMutation(c config, op Op, opts ...subjectdigestOption) *SubjectDigestMutation {
4228 m := &SubjectDigestMutation{
4229 config: c,
4230 op: op,
4231 typ: TypeSubjectDigest,
4232 clearedFields: make(map[string]struct{}),
4233 }
4234 for _, opt := range opts {
4235 opt(m)
4236 }
4237 return m
4238 }
4239
4240 // withSubjectDigestID sets the ID field of the mutation.
4241 func withSubjectDigestID(id uuid.UUID) subjectdigestOption {
4242 return func(m *SubjectDigestMutation) {
4243 var (
4244 err error
4245 once sync.Once
4246 value *SubjectDigest
4247 )
4248 m.oldValue = func(ctx context.Context) (*SubjectDigest, error) {
4249 once.Do(func() {
4250 if m.done {
4251 err = errors.New("querying old values post mutation is not allowed")
4252 } else {
4253 value, err = m.Client().SubjectDigest.Get(ctx, id)
4254 }
4255 })
4256 return value, err
4257 }
4258 m.id = &id
4259 }
4260 }
4261
4262 // withSubjectDigest sets the old SubjectDigest of the mutation.
4263 func withSubjectDigest(node *SubjectDigest) subjectdigestOption {
4264 return func(m *SubjectDigestMutation) {
4265 m.oldValue = func(context.Context) (*SubjectDigest, error) {
4266 return node, nil
4267 }
4268 m.id = &node.ID
4269 }
4270 }
4271
4272 // Client returns a new `ent.Client` from the mutation. If the mutation was
4273 // executed in a transaction (ent.Tx), a transactional client is returned.
4274 func (m SubjectDigestMutation) Client() *Client {
4275 client := &Client{config: m.config}
4276 client.init()
4277 return client
4278 }
4279
4280 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
4281 // it returns an error otherwise.
4282 func (m SubjectDigestMutation) Tx() (*Tx, error) {
4283 if _, ok := m.driver.(*txDriver); !ok {
4284 return nil, errors.New("ent: mutation is not running in a transaction")
4285 }
4286 tx := &Tx{config: m.config}
4287 tx.init()
4288 return tx, nil
4289 }
4290
4291 // SetID sets the value of the id field. Note that this
4292 // operation is only accepted on creation of SubjectDigest entities.
4293 func (m *SubjectDigestMutation) SetID(id uuid.UUID) {
4294 m.id = &id
4295 }
4296
4297 // ID returns the ID value in the mutation. Note that the ID is only available
4298 // if it was provided to the builder or after it was returned from the database.
4299 func (m *SubjectDigestMutation) ID() (id uuid.UUID, exists bool) {
4300 if m.id == nil {
4301 return
4302 }
4303 return *m.id, true
4304 }
4305
4306 // IDs queries the database and returns the entity ids that match the mutation's predicate.
4307 // That means, if the mutation is applied within a transaction with an isolation level such
4308 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
4309 // or updated by the mutation.
4310 func (m *SubjectDigestMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
4311 switch {
4312 case m.op.Is(OpUpdateOne | OpDeleteOne):
4313 id, exists := m.ID()
4314 if exists {
4315 return []uuid.UUID{id}, nil
4316 }
4317 fallthrough
4318 case m.op.Is(OpUpdate | OpDelete):
4319 return m.Client().SubjectDigest.Query().Where(m.predicates...).IDs(ctx)
4320 default:
4321 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
4322 }
4323 }
4324
4325 // SetAlgorithm sets the "algorithm" field.
4326 func (m *SubjectDigestMutation) SetAlgorithm(s string) {
4327 m.algorithm = &s
4328 }
4329
4330 // Algorithm returns the value of the "algorithm" field in the mutation.
4331 func (m *SubjectDigestMutation) Algorithm() (r string, exists bool) {
4332 v := m.algorithm
4333 if v == nil {
4334 return
4335 }
4336 return *v, true
4337 }
4338
4339 // OldAlgorithm returns the old "algorithm" field's value of the SubjectDigest entity.
4340 // If the SubjectDigest object wasn't provided to the builder, the object is fetched from the database.
4341 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
4342 func (m *SubjectDigestMutation) OldAlgorithm(ctx context.Context) (v string, err error) {
4343 if !m.op.Is(OpUpdateOne) {
4344 return v, errors.New("OldAlgorithm is only allowed on UpdateOne operations")
4345 }
4346 if m.id == nil || m.oldValue == nil {
4347 return v, errors.New("OldAlgorithm requires an ID field in the mutation")
4348 }
4349 oldValue, err := m.oldValue(ctx)
4350 if err != nil {
4351 return v, fmt.Errorf("querying old value for OldAlgorithm: %w", err)
4352 }
4353 return oldValue.Algorithm, nil
4354 }
4355
4356 // ResetAlgorithm resets all changes to the "algorithm" field.
4357 func (m *SubjectDigestMutation) ResetAlgorithm() {
4358 m.algorithm = nil
4359 }
4360
4361 // SetValue sets the "value" field.
4362 func (m *SubjectDigestMutation) SetValue(s string) {
4363 m.value = &s
4364 }
4365
4366 // Value returns the value of the "value" field in the mutation.
4367 func (m *SubjectDigestMutation) Value() (r string, exists bool) {
4368 v := m.value
4369 if v == nil {
4370 return
4371 }
4372 return *v, true
4373 }
4374
4375 // OldValue returns the old "value" field's value of the SubjectDigest entity.
4376 // If the SubjectDigest object wasn't provided to the builder, the object is fetched from the database.
4377 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
4378 func (m *SubjectDigestMutation) OldValue(ctx context.Context) (v string, err error) {
4379 if !m.op.Is(OpUpdateOne) {
4380 return v, errors.New("OldValue is only allowed on UpdateOne operations")
4381 }
4382 if m.id == nil || m.oldValue == nil {
4383 return v, errors.New("OldValue requires an ID field in the mutation")
4384 }
4385 oldValue, err := m.oldValue(ctx)
4386 if err != nil {
4387 return v, fmt.Errorf("querying old value for OldValue: %w", err)
4388 }
4389 return oldValue.Value, nil
4390 }
4391
4392 // ResetValue resets all changes to the "value" field.
4393 func (m *SubjectDigestMutation) ResetValue() {
4394 m.value = nil
4395 }
4396
4397 // SetSubjectID sets the "subject" edge to the Subject entity by id.
4398 func (m *SubjectDigestMutation) SetSubjectID(id uuid.UUID) {
4399 m.subject = &id
4400 }
4401
4402 // ClearSubject clears the "subject" edge to the Subject entity.
4403 func (m *SubjectDigestMutation) ClearSubject() {
4404 m.clearedsubject = true
4405 }
4406
4407 // SubjectCleared reports if the "subject" edge to the Subject entity was cleared.
4408 func (m *SubjectDigestMutation) SubjectCleared() bool {
4409 return m.clearedsubject
4410 }
4411
4412 // SubjectID returns the "subject" edge ID in the mutation.
4413 func (m *SubjectDigestMutation) SubjectID() (id uuid.UUID, exists bool) {
4414 if m.subject != nil {
4415 return *m.subject, true
4416 }
4417 return
4418 }
4419
4420 // SubjectIDs returns the "subject" edge IDs in the mutation.
4421 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
4422 // SubjectID instead. It exists only for internal usage by the builders.
4423 func (m *SubjectDigestMutation) SubjectIDs() (ids []uuid.UUID) {
4424 if id := m.subject; id != nil {
4425 ids = append(ids, *id)
4426 }
4427 return
4428 }
4429
4430 // ResetSubject resets all changes to the "subject" edge.
4431 func (m *SubjectDigestMutation) ResetSubject() {
4432 m.subject = nil
4433 m.clearedsubject = false
4434 }
4435
4436 // Where appends a list predicates to the SubjectDigestMutation builder.
4437 func (m *SubjectDigestMutation) Where(ps ...predicate.SubjectDigest) {
4438 m.predicates = append(m.predicates, ps...)
4439 }
4440
4441 // WhereP appends storage-level predicates to the SubjectDigestMutation builder. Using this method,
4442 // users can use type-assertion to append predicates that do not depend on any generated package.
4443 func (m *SubjectDigestMutation) WhereP(ps ...func(*sql.Selector)) {
4444 p := make([]predicate.SubjectDigest, len(ps))
4445 for i := range ps {
4446 p[i] = ps[i]
4447 }
4448 m.Where(p...)
4449 }
4450
4451 // Op returns the operation name.
4452 func (m *SubjectDigestMutation) Op() Op {
4453 return m.op
4454 }
4455
4456 // SetOp allows setting the mutation operation.
4457 func (m *SubjectDigestMutation) SetOp(op Op) {
4458 m.op = op
4459 }
4460
4461 // Type returns the node type of this mutation (SubjectDigest).
4462 func (m *SubjectDigestMutation) Type() string {
4463 return m.typ
4464 }
4465
4466 // Fields returns all fields that were changed during this mutation. Note that in
4467 // order to get all numeric fields that were incremented/decremented, call
4468 // AddedFields().
4469 func (m *SubjectDigestMutation) Fields() []string {
4470 fields := make([]string, 0, 2)
4471 if m.algorithm != nil {
4472 fields = append(fields, subjectdigest.FieldAlgorithm)
4473 }
4474 if m.value != nil {
4475 fields = append(fields, subjectdigest.FieldValue)
4476 }
4477 return fields
4478 }
4479
4480 // Field returns the value of a field with the given name. The second boolean
4481 // return value indicates that this field was not set, or was not defined in the
4482 // schema.
4483 func (m *SubjectDigestMutation) Field(name string) (ent.Value, bool) {
4484 switch name {
4485 case subjectdigest.FieldAlgorithm:
4486 return m.Algorithm()
4487 case subjectdigest.FieldValue:
4488 return m.Value()
4489 }
4490 return nil, false
4491 }
4492
4493 // OldField returns the old value of the field from the database. An error is
4494 // returned if the mutation operation is not UpdateOne, or the query to the
4495 // database failed.
4496 func (m *SubjectDigestMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
4497 switch name {
4498 case subjectdigest.FieldAlgorithm:
4499 return m.OldAlgorithm(ctx)
4500 case subjectdigest.FieldValue:
4501 return m.OldValue(ctx)
4502 }
4503 return nil, fmt.Errorf("unknown SubjectDigest field %s", name)
4504 }
4505
4506 // SetField sets the value of a field with the given name. It returns an error if
4507 // the field is not defined in the schema, or if the type mismatched the field
4508 // type.
4509 func (m *SubjectDigestMutation) SetField(name string, value ent.Value) error {
4510 switch name {
4511 case subjectdigest.FieldAlgorithm:
4512 v, ok := value.(string)
4513 if !ok {
4514 return fmt.Errorf("unexpected type %T for field %s", value, name)
4515 }
4516 m.SetAlgorithm(v)
4517 return nil
4518 case subjectdigest.FieldValue:
4519 v, ok := value.(string)
4520 if !ok {
4521 return fmt.Errorf("unexpected type %T for field %s", value, name)
4522 }
4523 m.SetValue(v)
4524 return nil
4525 }
4526 return fmt.Errorf("unknown SubjectDigest field %s", name)
4527 }
4528
4529 // AddedFields returns all numeric fields that were incremented/decremented during
4530 // this mutation.
4531 func (m *SubjectDigestMutation) AddedFields() []string {
4532 return nil
4533 }
4534
4535 // AddedField returns the numeric value that was incremented/decremented on a field
4536 // with the given name. The second boolean return value indicates that this field
4537 // was not set, or was not defined in the schema.
4538 func (m *SubjectDigestMutation) AddedField(name string) (ent.Value, bool) {
4539 return nil, false
4540 }
4541
4542 // AddField adds the value to the field with the given name. It returns an error if
4543 // the field is not defined in the schema, or if the type mismatched the field
4544 // type.
4545 func (m *SubjectDigestMutation) AddField(name string, value ent.Value) error {
4546 switch name {
4547 }
4548 return fmt.Errorf("unknown SubjectDigest numeric field %s", name)
4549 }
4550
4551 // ClearedFields returns all nullable fields that were cleared during this
4552 // mutation.
4553 func (m *SubjectDigestMutation) ClearedFields() []string {
4554 return nil
4555 }
4556
4557 // FieldCleared returns a boolean indicating if a field with the given name was
4558 // cleared in this mutation.
4559 func (m *SubjectDigestMutation) FieldCleared(name string) bool {
4560 _, ok := m.clearedFields[name]
4561 return ok
4562 }
4563
4564 // ClearField clears the value of the field with the given name. It returns an
4565 // error if the field is not defined in the schema.
4566 func (m *SubjectDigestMutation) ClearField(name string) error {
4567 return fmt.Errorf("unknown SubjectDigest nullable field %s", name)
4568 }
4569
4570 // ResetField resets all changes in the mutation for the field with the given name.
4571 // It returns an error if the field is not defined in the schema.
4572 func (m *SubjectDigestMutation) ResetField(name string) error {
4573 switch name {
4574 case subjectdigest.FieldAlgorithm:
4575 m.ResetAlgorithm()
4576 return nil
4577 case subjectdigest.FieldValue:
4578 m.ResetValue()
4579 return nil
4580 }
4581 return fmt.Errorf("unknown SubjectDigest field %s", name)
4582 }
4583
4584 // AddedEdges returns all edge names that were set/added in this mutation.
4585 func (m *SubjectDigestMutation) AddedEdges() []string {
4586 edges := make([]string, 0, 1)
4587 if m.subject != nil {
4588 edges = append(edges, subjectdigest.EdgeSubject)
4589 }
4590 return edges
4591 }
4592
4593 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
4594 // name in this mutation.
4595 func (m *SubjectDigestMutation) AddedIDs(name string) []ent.Value {
4596 switch name {
4597 case subjectdigest.EdgeSubject:
4598 if id := m.subject; id != nil {
4599 return []ent.Value{*id}
4600 }
4601 }
4602 return nil
4603 }
4604
4605 // RemovedEdges returns all edge names that were removed in this mutation.
4606 func (m *SubjectDigestMutation) RemovedEdges() []string {
4607 edges := make([]string, 0, 1)
4608 return edges
4609 }
4610
4611 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
4612 // the given name in this mutation.
4613 func (m *SubjectDigestMutation) RemovedIDs(name string) []ent.Value {
4614 return nil
4615 }
4616
4617 // ClearedEdges returns all edge names that were cleared in this mutation.
4618 func (m *SubjectDigestMutation) ClearedEdges() []string {
4619 edges := make([]string, 0, 1)
4620 if m.clearedsubject {
4621 edges = append(edges, subjectdigest.EdgeSubject)
4622 }
4623 return edges
4624 }
4625
4626 // EdgeCleared returns a boolean which indicates if the edge with the given name
4627 // was cleared in this mutation.
4628 func (m *SubjectDigestMutation) EdgeCleared(name string) bool {
4629 switch name {
4630 case subjectdigest.EdgeSubject:
4631 return m.clearedsubject
4632 }
4633 return false
4634 }
4635
4636 // ClearEdge clears the value of the edge with the given name. It returns an error
4637 // if that edge is not defined in the schema.
4638 func (m *SubjectDigestMutation) ClearEdge(name string) error {
4639 switch name {
4640 case subjectdigest.EdgeSubject:
4641 m.ClearSubject()
4642 return nil
4643 }
4644 return fmt.Errorf("unknown SubjectDigest unique edge %s", name)
4645 }
4646
4647 // ResetEdge resets all changes to the edge with the given name in this mutation.
4648 // It returns an error if the edge is not defined in the schema.
4649 func (m *SubjectDigestMutation) ResetEdge(name string) error {
4650 switch name {
4651 case subjectdigest.EdgeSubject:
4652 m.ResetSubject()
4653 return nil
4654 }
4655 return fmt.Errorf("unknown SubjectDigest edge %s", name)
4656 }
4657
4658 // TimestampMutation represents an operation that mutates the Timestamp nodes in the graph.
4659 type TimestampMutation struct {
4660 config
4661 op Op
4662 typ string
4663 id *uuid.UUID
4664 _type *string
4665 timestamp *time.Time
4666 clearedFields map[string]struct{}
4667 signature *uuid.UUID
4668 clearedsignature bool
4669 done bool
4670 oldValue func(context.Context) (*Timestamp, error)
4671 predicates []predicate.Timestamp
4672 }
4673
4674 var _ ent.Mutation = (*TimestampMutation)(nil)
4675
4676 // timestampOption allows management of the mutation configuration using functional options.
4677 type timestampOption func(*TimestampMutation)
4678
4679 // newTimestampMutation creates new mutation for the Timestamp entity.
4680 func newTimestampMutation(c config, op Op, opts ...timestampOption) *TimestampMutation {
4681 m := &TimestampMutation{
4682 config: c,
4683 op: op,
4684 typ: TypeTimestamp,
4685 clearedFields: make(map[string]struct{}),
4686 }
4687 for _, opt := range opts {
4688 opt(m)
4689 }
4690 return m
4691 }
4692
4693 // withTimestampID sets the ID field of the mutation.
4694 func withTimestampID(id uuid.UUID) timestampOption {
4695 return func(m *TimestampMutation) {
4696 var (
4697 err error
4698 once sync.Once
4699 value *Timestamp
4700 )
4701 m.oldValue = func(ctx context.Context) (*Timestamp, error) {
4702 once.Do(func() {
4703 if m.done {
4704 err = errors.New("querying old values post mutation is not allowed")
4705 } else {
4706 value, err = m.Client().Timestamp.Get(ctx, id)
4707 }
4708 })
4709 return value, err
4710 }
4711 m.id = &id
4712 }
4713 }
4714
4715 // withTimestamp sets the old Timestamp of the mutation.
4716 func withTimestamp(node *Timestamp) timestampOption {
4717 return func(m *TimestampMutation) {
4718 m.oldValue = func(context.Context) (*Timestamp, error) {
4719 return node, nil
4720 }
4721 m.id = &node.ID
4722 }
4723 }
4724
4725 // Client returns a new `ent.Client` from the mutation. If the mutation was
4726 // executed in a transaction (ent.Tx), a transactional client is returned.
4727 func (m TimestampMutation) Client() *Client {
4728 client := &Client{config: m.config}
4729 client.init()
4730 return client
4731 }
4732
4733 // Tx returns an `ent.Tx` for mutations that were executed in transactions;
4734 // it returns an error otherwise.
4735 func (m TimestampMutation) Tx() (*Tx, error) {
4736 if _, ok := m.driver.(*txDriver); !ok {
4737 return nil, errors.New("ent: mutation is not running in a transaction")
4738 }
4739 tx := &Tx{config: m.config}
4740 tx.init()
4741 return tx, nil
4742 }
4743
4744 // SetID sets the value of the id field. Note that this
4745 // operation is only accepted on creation of Timestamp entities.
4746 func (m *TimestampMutation) SetID(id uuid.UUID) {
4747 m.id = &id
4748 }
4749
4750 // ID returns the ID value in the mutation. Note that the ID is only available
4751 // if it was provided to the builder or after it was returned from the database.
4752 func (m *TimestampMutation) ID() (id uuid.UUID, exists bool) {
4753 if m.id == nil {
4754 return
4755 }
4756 return *m.id, true
4757 }
4758
4759 // IDs queries the database and returns the entity ids that match the mutation's predicate.
4760 // That means, if the mutation is applied within a transaction with an isolation level such
4761 // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
4762 // or updated by the mutation.
4763 func (m *TimestampMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
4764 switch {
4765 case m.op.Is(OpUpdateOne | OpDeleteOne):
4766 id, exists := m.ID()
4767 if exists {
4768 return []uuid.UUID{id}, nil
4769 }
4770 fallthrough
4771 case m.op.Is(OpUpdate | OpDelete):
4772 return m.Client().Timestamp.Query().Where(m.predicates...).IDs(ctx)
4773 default:
4774 return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
4775 }
4776 }
4777
4778 // SetType sets the "type" field.
4779 func (m *TimestampMutation) SetType(s string) {
4780 m._type = &s
4781 }
4782
4783 // GetType returns the value of the "type" field in the mutation.
4784 func (m *TimestampMutation) GetType() (r string, exists bool) {
4785 v := m._type
4786 if v == nil {
4787 return
4788 }
4789 return *v, true
4790 }
4791
4792 // OldType returns the old "type" field's value of the Timestamp entity.
4793 // If the Timestamp object wasn't provided to the builder, the object is fetched from the database.
4794 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
4795 func (m *TimestampMutation) OldType(ctx context.Context) (v string, err error) {
4796 if !m.op.Is(OpUpdateOne) {
4797 return v, errors.New("OldType is only allowed on UpdateOne operations")
4798 }
4799 if m.id == nil || m.oldValue == nil {
4800 return v, errors.New("OldType requires an ID field in the mutation")
4801 }
4802 oldValue, err := m.oldValue(ctx)
4803 if err != nil {
4804 return v, fmt.Errorf("querying old value for OldType: %w", err)
4805 }
4806 return oldValue.Type, nil
4807 }
4808
4809 // ResetType resets all changes to the "type" field.
4810 func (m *TimestampMutation) ResetType() {
4811 m._type = nil
4812 }
4813
4814 // SetTimestamp sets the "timestamp" field.
4815 func (m *TimestampMutation) SetTimestamp(t time.Time) {
4816 m.timestamp = &t
4817 }
4818
4819 // Timestamp returns the value of the "timestamp" field in the mutation.
4820 func (m *TimestampMutation) Timestamp() (r time.Time, exists bool) {
4821 v := m.timestamp
4822 if v == nil {
4823 return
4824 }
4825 return *v, true
4826 }
4827
4828 // OldTimestamp returns the old "timestamp" field's value of the Timestamp entity.
4829 // If the Timestamp object wasn't provided to the builder, the object is fetched from the database.
4830 // An error is returned if the mutation operation is not UpdateOne, or the database query fails.
4831 func (m *TimestampMutation) OldTimestamp(ctx context.Context) (v time.Time, err error) {
4832 if !m.op.Is(OpUpdateOne) {
4833 return v, errors.New("OldTimestamp is only allowed on UpdateOne operations")
4834 }
4835 if m.id == nil || m.oldValue == nil {
4836 return v, errors.New("OldTimestamp requires an ID field in the mutation")
4837 }
4838 oldValue, err := m.oldValue(ctx)
4839 if err != nil {
4840 return v, fmt.Errorf("querying old value for OldTimestamp: %w", err)
4841 }
4842 return oldValue.Timestamp, nil
4843 }
4844
4845 // ResetTimestamp resets all changes to the "timestamp" field.
4846 func (m *TimestampMutation) ResetTimestamp() {
4847 m.timestamp = nil
4848 }
4849
4850 // SetSignatureID sets the "signature" edge to the Signature entity by id.
4851 func (m *TimestampMutation) SetSignatureID(id uuid.UUID) {
4852 m.signature = &id
4853 }
4854
4855 // ClearSignature clears the "signature" edge to the Signature entity.
4856 func (m *TimestampMutation) ClearSignature() {
4857 m.clearedsignature = true
4858 }
4859
4860 // SignatureCleared reports if the "signature" edge to the Signature entity was cleared.
4861 func (m *TimestampMutation) SignatureCleared() bool {
4862 return m.clearedsignature
4863 }
4864
4865 // SignatureID returns the "signature" edge ID in the mutation.
4866 func (m *TimestampMutation) SignatureID() (id uuid.UUID, exists bool) {
4867 if m.signature != nil {
4868 return *m.signature, true
4869 }
4870 return
4871 }
4872
4873 // SignatureIDs returns the "signature" edge IDs in the mutation.
4874 // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
4875 // SignatureID instead. It exists only for internal usage by the builders.
4876 func (m *TimestampMutation) SignatureIDs() (ids []uuid.UUID) {
4877 if id := m.signature; id != nil {
4878 ids = append(ids, *id)
4879 }
4880 return
4881 }
4882
4883 // ResetSignature resets all changes to the "signature" edge.
4884 func (m *TimestampMutation) ResetSignature() {
4885 m.signature = nil
4886 m.clearedsignature = false
4887 }
4888
4889 // Where appends a list predicates to the TimestampMutation builder.
4890 func (m *TimestampMutation) Where(ps ...predicate.Timestamp) {
4891 m.predicates = append(m.predicates, ps...)
4892 }
4893
4894 // WhereP appends storage-level predicates to the TimestampMutation builder. Using this method,
4895 // users can use type-assertion to append predicates that do not depend on any generated package.
4896 func (m *TimestampMutation) WhereP(ps ...func(*sql.Selector)) {
4897 p := make([]predicate.Timestamp, len(ps))
4898 for i := range ps {
4899 p[i] = ps[i]
4900 }
4901 m.Where(p...)
4902 }
4903
4904 // Op returns the operation name.
4905 func (m *TimestampMutation) Op() Op {
4906 return m.op
4907 }
4908
4909 // SetOp allows setting the mutation operation.
4910 func (m *TimestampMutation) SetOp(op Op) {
4911 m.op = op
4912 }
4913
4914 // Type returns the node type of this mutation (Timestamp).
4915 func (m *TimestampMutation) Type() string {
4916 return m.typ
4917 }
4918
4919 // Fields returns all fields that were changed during this mutation. Note that in
4920 // order to get all numeric fields that were incremented/decremented, call
4921 // AddedFields().
4922 func (m *TimestampMutation) Fields() []string {
4923 fields := make([]string, 0, 2)
4924 if m._type != nil {
4925 fields = append(fields, timestamp.FieldType)
4926 }
4927 if m.timestamp != nil {
4928 fields = append(fields, timestamp.FieldTimestamp)
4929 }
4930 return fields
4931 }
4932
4933 // Field returns the value of a field with the given name. The second boolean
4934 // return value indicates that this field was not set, or was not defined in the
4935 // schema.
4936 func (m *TimestampMutation) Field(name string) (ent.Value, bool) {
4937 switch name {
4938 case timestamp.FieldType:
4939 return m.GetType()
4940 case timestamp.FieldTimestamp:
4941 return m.Timestamp()
4942 }
4943 return nil, false
4944 }
4945
4946 // OldField returns the old value of the field from the database. An error is
4947 // returned if the mutation operation is not UpdateOne, or the query to the
4948 // database failed.
4949 func (m *TimestampMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
4950 switch name {
4951 case timestamp.FieldType:
4952 return m.OldType(ctx)
4953 case timestamp.FieldTimestamp:
4954 return m.OldTimestamp(ctx)
4955 }
4956 return nil, fmt.Errorf("unknown Timestamp field %s", name)
4957 }
4958
4959 // SetField sets the value of a field with the given name. It returns an error if
4960 // the field is not defined in the schema, or if the type mismatched the field
4961 // type.
4962 func (m *TimestampMutation) SetField(name string, value ent.Value) error {
4963 switch name {
4964 case timestamp.FieldType:
4965 v, ok := value.(string)
4966 if !ok {
4967 return fmt.Errorf("unexpected type %T for field %s", value, name)
4968 }
4969 m.SetType(v)
4970 return nil
4971 case timestamp.FieldTimestamp:
4972 v, ok := value.(time.Time)
4973 if !ok {
4974 return fmt.Errorf("unexpected type %T for field %s", value, name)
4975 }
4976 m.SetTimestamp(v)
4977 return nil
4978 }
4979 return fmt.Errorf("unknown Timestamp field %s", name)
4980 }
4981
4982 // AddedFields returns all numeric fields that were incremented/decremented during
4983 // this mutation.
4984 func (m *TimestampMutation) AddedFields() []string {
4985 return nil
4986 }
4987
4988 // AddedField returns the numeric value that was incremented/decremented on a field
4989 // with the given name. The second boolean return value indicates that this field
4990 // was not set, or was not defined in the schema.
4991 func (m *TimestampMutation) AddedField(name string) (ent.Value, bool) {
4992 return nil, false
4993 }
4994
4995 // AddField adds the value to the field with the given name. It returns an error if
4996 // the field is not defined in the schema, or if the type mismatched the field
4997 // type.
4998 func (m *TimestampMutation) AddField(name string, value ent.Value) error {
4999 switch name {
5000 }
5001 return fmt.Errorf("unknown Timestamp numeric field %s", name)
5002 }
5003
5004 // ClearedFields returns all nullable fields that were cleared during this
5005 // mutation.
5006 func (m *TimestampMutation) ClearedFields() []string {
5007 return nil
5008 }
5009
5010 // FieldCleared returns a boolean indicating if a field with the given name was
5011 // cleared in this mutation.
5012 func (m *TimestampMutation) FieldCleared(name string) bool {
5013 _, ok := m.clearedFields[name]
5014 return ok
5015 }
5016
5017 // ClearField clears the value of the field with the given name. It returns an
5018 // error if the field is not defined in the schema.
5019 func (m *TimestampMutation) ClearField(name string) error {
5020 return fmt.Errorf("unknown Timestamp nullable field %s", name)
5021 }
5022
5023 // ResetField resets all changes in the mutation for the field with the given name.
5024 // It returns an error if the field is not defined in the schema.
5025 func (m *TimestampMutation) ResetField(name string) error {
5026 switch name {
5027 case timestamp.FieldType:
5028 m.ResetType()
5029 return nil
5030 case timestamp.FieldTimestamp:
5031 m.ResetTimestamp()
5032 return nil
5033 }
5034 return fmt.Errorf("unknown Timestamp field %s", name)
5035 }
5036
5037 // AddedEdges returns all edge names that were set/added in this mutation.
5038 func (m *TimestampMutation) AddedEdges() []string {
5039 edges := make([]string, 0, 1)
5040 if m.signature != nil {
5041 edges = append(edges, timestamp.EdgeSignature)
5042 }
5043 return edges
5044 }
5045
5046 // AddedIDs returns all IDs (to other nodes) that were added for the given edge
5047 // name in this mutation.
5048 func (m *TimestampMutation) AddedIDs(name string) []ent.Value {
5049 switch name {
5050 case timestamp.EdgeSignature:
5051 if id := m.signature; id != nil {
5052 return []ent.Value{*id}
5053 }
5054 }
5055 return nil
5056 }
5057
5058 // RemovedEdges returns all edge names that were removed in this mutation.
5059 func (m *TimestampMutation) RemovedEdges() []string {
5060 edges := make([]string, 0, 1)
5061 return edges
5062 }
5063
5064 // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
5065 // the given name in this mutation.
5066 func (m *TimestampMutation) RemovedIDs(name string) []ent.Value {
5067 return nil
5068 }
5069
5070 // ClearedEdges returns all edge names that were cleared in this mutation.
5071 func (m *TimestampMutation) ClearedEdges() []string {
5072 edges := make([]string, 0, 1)
5073 if m.clearedsignature {
5074 edges = append(edges, timestamp.EdgeSignature)
5075 }
5076 return edges
5077 }
5078
5079 // EdgeCleared returns a boolean which indicates if the edge with the given name
5080 // was cleared in this mutation.
5081 func (m *TimestampMutation) EdgeCleared(name string) bool {
5082 switch name {
5083 case timestamp.EdgeSignature:
5084 return m.clearedsignature
5085 }
5086 return false
5087 }
5088
5089 // ClearEdge clears the value of the edge with the given name. It returns an error
5090 // if that edge is not defined in the schema.
5091 func (m *TimestampMutation) ClearEdge(name string) error {
5092 switch name {
5093 case timestamp.EdgeSignature:
5094 m.ClearSignature()
5095 return nil
5096 }
5097 return fmt.Errorf("unknown Timestamp unique edge %s", name)
5098 }
5099
5100 // ResetEdge resets all changes to the edge with the given name in this mutation.
5101 // It returns an error if the edge is not defined in the schema.
5102 func (m *TimestampMutation) ResetEdge(name string) error {
5103 switch name {
5104 case timestamp.EdgeSignature:
5105 m.ResetSignature()
5106 return nil
5107 }
5108 return fmt.Errorf("unknown Timestamp edge %s", name)
5109 }