// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "sync" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/in-toto/archivista/ent/attestation" "github.com/in-toto/archivista/ent/attestationcollection" "github.com/in-toto/archivista/ent/attestationpolicy" "github.com/in-toto/archivista/ent/dsse" "github.com/in-toto/archivista/ent/payloaddigest" "github.com/in-toto/archivista/ent/predicate" "github.com/in-toto/archivista/ent/signature" "github.com/in-toto/archivista/ent/statement" "github.com/in-toto/archivista/ent/subject" "github.com/in-toto/archivista/ent/subjectdigest" "github.com/in-toto/archivista/ent/timestamp" ) const ( // Operation types. OpCreate = ent.OpCreate OpDelete = ent.OpDelete OpDeleteOne = ent.OpDeleteOne OpUpdate = ent.OpUpdate OpUpdateOne = ent.OpUpdateOne // Node types. TypeAttestation = "Attestation" TypeAttestationCollection = "AttestationCollection" TypeAttestationPolicy = "AttestationPolicy" TypeDsse = "Dsse" TypePayloadDigest = "PayloadDigest" TypeSignature = "Signature" TypeStatement = "Statement" TypeSubject = "Subject" TypeSubjectDigest = "SubjectDigest" TypeTimestamp = "Timestamp" ) // AttestationMutation represents an operation that mutates the Attestation nodes in the graph. type AttestationMutation struct { config op Op typ string id *uuid.UUID _type *string clearedFields map[string]struct{} attestation_collection *uuid.UUID clearedattestation_collection bool done bool oldValue func(context.Context) (*Attestation, error) predicates []predicate.Attestation } var _ ent.Mutation = (*AttestationMutation)(nil) // attestationOption allows management of the mutation configuration using functional options. type attestationOption func(*AttestationMutation) // newAttestationMutation creates new mutation for the Attestation entity. func newAttestationMutation(c config, op Op, opts ...attestationOption) *AttestationMutation { m := &AttestationMutation{ config: c, op: op, typ: TypeAttestation, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withAttestationID sets the ID field of the mutation. func withAttestationID(id uuid.UUID) attestationOption { return func(m *AttestationMutation) { var ( err error once sync.Once value *Attestation ) m.oldValue = func(ctx context.Context) (*Attestation, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Attestation.Get(ctx, id) } }) return value, err } m.id = &id } } // withAttestation sets the old Attestation of the mutation. func withAttestation(node *Attestation) attestationOption { return func(m *AttestationMutation) { m.oldValue = func(context.Context) (*Attestation, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m AttestationMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m AttestationMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Attestation entities. func (m *AttestationMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *AttestationMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *AttestationMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Attestation.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetType sets the "type" field. func (m *AttestationMutation) SetType(s string) { m._type = &s } // GetType returns the value of the "type" field in the mutation. func (m *AttestationMutation) GetType() (r string, exists bool) { v := m._type if v == nil { return } return *v, true } // OldType returns the old "type" field's value of the Attestation entity. // If the Attestation object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AttestationMutation) OldType(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldType: %w", err) } return oldValue.Type, nil } // ResetType resets all changes to the "type" field. func (m *AttestationMutation) ResetType() { m._type = nil } // SetAttestationCollectionID sets the "attestation_collection" edge to the AttestationCollection entity by id. func (m *AttestationMutation) SetAttestationCollectionID(id uuid.UUID) { m.attestation_collection = &id } // ClearAttestationCollection clears the "attestation_collection" edge to the AttestationCollection entity. func (m *AttestationMutation) ClearAttestationCollection() { m.clearedattestation_collection = true } // AttestationCollectionCleared reports if the "attestation_collection" edge to the AttestationCollection entity was cleared. func (m *AttestationMutation) AttestationCollectionCleared() bool { return m.clearedattestation_collection } // AttestationCollectionID returns the "attestation_collection" edge ID in the mutation. func (m *AttestationMutation) AttestationCollectionID() (id uuid.UUID, exists bool) { if m.attestation_collection != nil { return *m.attestation_collection, true } return } // AttestationCollectionIDs returns the "attestation_collection" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // AttestationCollectionID instead. It exists only for internal usage by the builders. func (m *AttestationMutation) AttestationCollectionIDs() (ids []uuid.UUID) { if id := m.attestation_collection; id != nil { ids = append(ids, *id) } return } // ResetAttestationCollection resets all changes to the "attestation_collection" edge. func (m *AttestationMutation) ResetAttestationCollection() { m.attestation_collection = nil m.clearedattestation_collection = false } // Where appends a list predicates to the AttestationMutation builder. func (m *AttestationMutation) Where(ps ...predicate.Attestation) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the AttestationMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *AttestationMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Attestation, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *AttestationMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *AttestationMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Attestation). func (m *AttestationMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *AttestationMutation) Fields() []string { fields := make([]string, 0, 1) if m._type != nil { fields = append(fields, attestation.FieldType) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *AttestationMutation) Field(name string) (ent.Value, bool) { switch name { case attestation.FieldType: return m.GetType() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *AttestationMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case attestation.FieldType: return m.OldType(ctx) } return nil, fmt.Errorf("unknown Attestation field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *AttestationMutation) SetField(name string, value ent.Value) error { switch name { case attestation.FieldType: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetType(v) return nil } return fmt.Errorf("unknown Attestation field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *AttestationMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *AttestationMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *AttestationMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Attestation numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AttestationMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AttestationMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *AttestationMutation) ClearField(name string) error { return fmt.Errorf("unknown Attestation nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *AttestationMutation) ResetField(name string) error { switch name { case attestation.FieldType: m.ResetType() return nil } return fmt.Errorf("unknown Attestation field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AttestationMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.attestation_collection != nil { edges = append(edges, attestation.EdgeAttestationCollection) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *AttestationMutation) AddedIDs(name string) []ent.Value { switch name { case attestation.EdgeAttestationCollection: if id := m.attestation_collection; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *AttestationMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *AttestationMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AttestationMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedattestation_collection { edges = append(edges, attestation.EdgeAttestationCollection) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *AttestationMutation) EdgeCleared(name string) bool { switch name { case attestation.EdgeAttestationCollection: return m.clearedattestation_collection } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *AttestationMutation) ClearEdge(name string) error { switch name { case attestation.EdgeAttestationCollection: m.ClearAttestationCollection() return nil } return fmt.Errorf("unknown Attestation unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *AttestationMutation) ResetEdge(name string) error { switch name { case attestation.EdgeAttestationCollection: m.ResetAttestationCollection() return nil } return fmt.Errorf("unknown Attestation edge %s", name) } // AttestationCollectionMutation represents an operation that mutates the AttestationCollection nodes in the graph. type AttestationCollectionMutation struct { config op Op typ string id *uuid.UUID name *string clearedFields map[string]struct{} attestations map[uuid.UUID]struct{} removedattestations map[uuid.UUID]struct{} clearedattestations bool statement *uuid.UUID clearedstatement bool done bool oldValue func(context.Context) (*AttestationCollection, error) predicates []predicate.AttestationCollection } var _ ent.Mutation = (*AttestationCollectionMutation)(nil) // attestationcollectionOption allows management of the mutation configuration using functional options. type attestationcollectionOption func(*AttestationCollectionMutation) // newAttestationCollectionMutation creates new mutation for the AttestationCollection entity. func newAttestationCollectionMutation(c config, op Op, opts ...attestationcollectionOption) *AttestationCollectionMutation { m := &AttestationCollectionMutation{ config: c, op: op, typ: TypeAttestationCollection, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withAttestationCollectionID sets the ID field of the mutation. func withAttestationCollectionID(id uuid.UUID) attestationcollectionOption { return func(m *AttestationCollectionMutation) { var ( err error once sync.Once value *AttestationCollection ) m.oldValue = func(ctx context.Context) (*AttestationCollection, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().AttestationCollection.Get(ctx, id) } }) return value, err } m.id = &id } } // withAttestationCollection sets the old AttestationCollection of the mutation. func withAttestationCollection(node *AttestationCollection) attestationcollectionOption { return func(m *AttestationCollectionMutation) { m.oldValue = func(context.Context) (*AttestationCollection, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m AttestationCollectionMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m AttestationCollectionMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of AttestationCollection entities. func (m *AttestationCollectionMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *AttestationCollectionMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *AttestationCollectionMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().AttestationCollection.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *AttestationCollectionMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *AttestationCollectionMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the AttestationCollection entity. // If the AttestationCollection object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AttestationCollectionMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *AttestationCollectionMutation) ResetName() { m.name = nil } // AddAttestationIDs adds the "attestations" edge to the Attestation entity by ids. func (m *AttestationCollectionMutation) AddAttestationIDs(ids ...uuid.UUID) { if m.attestations == nil { m.attestations = make(map[uuid.UUID]struct{}) } for i := range ids { m.attestations[ids[i]] = struct{}{} } } // ClearAttestations clears the "attestations" edge to the Attestation entity. func (m *AttestationCollectionMutation) ClearAttestations() { m.clearedattestations = true } // AttestationsCleared reports if the "attestations" edge to the Attestation entity was cleared. func (m *AttestationCollectionMutation) AttestationsCleared() bool { return m.clearedattestations } // RemoveAttestationIDs removes the "attestations" edge to the Attestation entity by IDs. func (m *AttestationCollectionMutation) RemoveAttestationIDs(ids ...uuid.UUID) { if m.removedattestations == nil { m.removedattestations = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.attestations, ids[i]) m.removedattestations[ids[i]] = struct{}{} } } // RemovedAttestations returns the removed IDs of the "attestations" edge to the Attestation entity. func (m *AttestationCollectionMutation) RemovedAttestationsIDs() (ids []uuid.UUID) { for id := range m.removedattestations { ids = append(ids, id) } return } // AttestationsIDs returns the "attestations" edge IDs in the mutation. func (m *AttestationCollectionMutation) AttestationsIDs() (ids []uuid.UUID) { for id := range m.attestations { ids = append(ids, id) } return } // ResetAttestations resets all changes to the "attestations" edge. func (m *AttestationCollectionMutation) ResetAttestations() { m.attestations = nil m.clearedattestations = false m.removedattestations = nil } // SetStatementID sets the "statement" edge to the Statement entity by id. func (m *AttestationCollectionMutation) SetStatementID(id uuid.UUID) { m.statement = &id } // ClearStatement clears the "statement" edge to the Statement entity. func (m *AttestationCollectionMutation) ClearStatement() { m.clearedstatement = true } // StatementCleared reports if the "statement" edge to the Statement entity was cleared. func (m *AttestationCollectionMutation) StatementCleared() bool { return m.clearedstatement } // StatementID returns the "statement" edge ID in the mutation. func (m *AttestationCollectionMutation) StatementID() (id uuid.UUID, exists bool) { if m.statement != nil { return *m.statement, true } return } // StatementIDs returns the "statement" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // StatementID instead. It exists only for internal usage by the builders. func (m *AttestationCollectionMutation) StatementIDs() (ids []uuid.UUID) { if id := m.statement; id != nil { ids = append(ids, *id) } return } // ResetStatement resets all changes to the "statement" edge. func (m *AttestationCollectionMutation) ResetStatement() { m.statement = nil m.clearedstatement = false } // Where appends a list predicates to the AttestationCollectionMutation builder. func (m *AttestationCollectionMutation) Where(ps ...predicate.AttestationCollection) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the AttestationCollectionMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *AttestationCollectionMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.AttestationCollection, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *AttestationCollectionMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *AttestationCollectionMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (AttestationCollection). func (m *AttestationCollectionMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *AttestationCollectionMutation) Fields() []string { fields := make([]string, 0, 1) if m.name != nil { fields = append(fields, attestationcollection.FieldName) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *AttestationCollectionMutation) Field(name string) (ent.Value, bool) { switch name { case attestationcollection.FieldName: return m.Name() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *AttestationCollectionMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case attestationcollection.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown AttestationCollection field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *AttestationCollectionMutation) SetField(name string, value ent.Value) error { switch name { case attestationcollection.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil } return fmt.Errorf("unknown AttestationCollection field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *AttestationCollectionMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *AttestationCollectionMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *AttestationCollectionMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown AttestationCollection numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AttestationCollectionMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AttestationCollectionMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *AttestationCollectionMutation) ClearField(name string) error { return fmt.Errorf("unknown AttestationCollection nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *AttestationCollectionMutation) ResetField(name string) error { switch name { case attestationcollection.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown AttestationCollection field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AttestationCollectionMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.attestations != nil { edges = append(edges, attestationcollection.EdgeAttestations) } if m.statement != nil { edges = append(edges, attestationcollection.EdgeStatement) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *AttestationCollectionMutation) AddedIDs(name string) []ent.Value { switch name { case attestationcollection.EdgeAttestations: ids := make([]ent.Value, 0, len(m.attestations)) for id := range m.attestations { ids = append(ids, id) } return ids case attestationcollection.EdgeStatement: if id := m.statement; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *AttestationCollectionMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedattestations != nil { edges = append(edges, attestationcollection.EdgeAttestations) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *AttestationCollectionMutation) RemovedIDs(name string) []ent.Value { switch name { case attestationcollection.EdgeAttestations: ids := make([]ent.Value, 0, len(m.removedattestations)) for id := range m.removedattestations { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AttestationCollectionMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedattestations { edges = append(edges, attestationcollection.EdgeAttestations) } if m.clearedstatement { edges = append(edges, attestationcollection.EdgeStatement) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *AttestationCollectionMutation) EdgeCleared(name string) bool { switch name { case attestationcollection.EdgeAttestations: return m.clearedattestations case attestationcollection.EdgeStatement: return m.clearedstatement } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *AttestationCollectionMutation) ClearEdge(name string) error { switch name { case attestationcollection.EdgeStatement: m.ClearStatement() return nil } return fmt.Errorf("unknown AttestationCollection unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *AttestationCollectionMutation) ResetEdge(name string) error { switch name { case attestationcollection.EdgeAttestations: m.ResetAttestations() return nil case attestationcollection.EdgeStatement: m.ResetStatement() return nil } return fmt.Errorf("unknown AttestationCollection edge %s", name) } // AttestationPolicyMutation represents an operation that mutates the AttestationPolicy nodes in the graph. type AttestationPolicyMutation struct { config op Op typ string id *uuid.UUID name *string clearedFields map[string]struct{} statement *uuid.UUID clearedstatement bool done bool oldValue func(context.Context) (*AttestationPolicy, error) predicates []predicate.AttestationPolicy } var _ ent.Mutation = (*AttestationPolicyMutation)(nil) // attestationpolicyOption allows management of the mutation configuration using functional options. type attestationpolicyOption func(*AttestationPolicyMutation) // newAttestationPolicyMutation creates new mutation for the AttestationPolicy entity. func newAttestationPolicyMutation(c config, op Op, opts ...attestationpolicyOption) *AttestationPolicyMutation { m := &AttestationPolicyMutation{ config: c, op: op, typ: TypeAttestationPolicy, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withAttestationPolicyID sets the ID field of the mutation. func withAttestationPolicyID(id uuid.UUID) attestationpolicyOption { return func(m *AttestationPolicyMutation) { var ( err error once sync.Once value *AttestationPolicy ) m.oldValue = func(ctx context.Context) (*AttestationPolicy, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().AttestationPolicy.Get(ctx, id) } }) return value, err } m.id = &id } } // withAttestationPolicy sets the old AttestationPolicy of the mutation. func withAttestationPolicy(node *AttestationPolicy) attestationpolicyOption { return func(m *AttestationPolicyMutation) { m.oldValue = func(context.Context) (*AttestationPolicy, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m AttestationPolicyMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m AttestationPolicyMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of AttestationPolicy entities. func (m *AttestationPolicyMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *AttestationPolicyMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *AttestationPolicyMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().AttestationPolicy.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetName sets the "name" field. func (m *AttestationPolicyMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *AttestationPolicyMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the AttestationPolicy entity. // If the AttestationPolicy object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *AttestationPolicyMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *AttestationPolicyMutation) ResetName() { m.name = nil } // SetStatementID sets the "statement" edge to the Statement entity by id. func (m *AttestationPolicyMutation) SetStatementID(id uuid.UUID) { m.statement = &id } // ClearStatement clears the "statement" edge to the Statement entity. func (m *AttestationPolicyMutation) ClearStatement() { m.clearedstatement = true } // StatementCleared reports if the "statement" edge to the Statement entity was cleared. func (m *AttestationPolicyMutation) StatementCleared() bool { return m.clearedstatement } // StatementID returns the "statement" edge ID in the mutation. func (m *AttestationPolicyMutation) StatementID() (id uuid.UUID, exists bool) { if m.statement != nil { return *m.statement, true } return } // StatementIDs returns the "statement" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // StatementID instead. It exists only for internal usage by the builders. func (m *AttestationPolicyMutation) StatementIDs() (ids []uuid.UUID) { if id := m.statement; id != nil { ids = append(ids, *id) } return } // ResetStatement resets all changes to the "statement" edge. func (m *AttestationPolicyMutation) ResetStatement() { m.statement = nil m.clearedstatement = false } // Where appends a list predicates to the AttestationPolicyMutation builder. func (m *AttestationPolicyMutation) Where(ps ...predicate.AttestationPolicy) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the AttestationPolicyMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *AttestationPolicyMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.AttestationPolicy, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *AttestationPolicyMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *AttestationPolicyMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (AttestationPolicy). func (m *AttestationPolicyMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *AttestationPolicyMutation) Fields() []string { fields := make([]string, 0, 1) if m.name != nil { fields = append(fields, attestationpolicy.FieldName) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *AttestationPolicyMutation) Field(name string) (ent.Value, bool) { switch name { case attestationpolicy.FieldName: return m.Name() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *AttestationPolicyMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case attestationpolicy.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown AttestationPolicy field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *AttestationPolicyMutation) SetField(name string, value ent.Value) error { switch name { case attestationpolicy.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil } return fmt.Errorf("unknown AttestationPolicy field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *AttestationPolicyMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *AttestationPolicyMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *AttestationPolicyMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown AttestationPolicy numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *AttestationPolicyMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *AttestationPolicyMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *AttestationPolicyMutation) ClearField(name string) error { return fmt.Errorf("unknown AttestationPolicy nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *AttestationPolicyMutation) ResetField(name string) error { switch name { case attestationpolicy.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown AttestationPolicy field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *AttestationPolicyMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.statement != nil { edges = append(edges, attestationpolicy.EdgeStatement) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *AttestationPolicyMutation) AddedIDs(name string) []ent.Value { switch name { case attestationpolicy.EdgeStatement: if id := m.statement; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *AttestationPolicyMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *AttestationPolicyMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *AttestationPolicyMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedstatement { edges = append(edges, attestationpolicy.EdgeStatement) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *AttestationPolicyMutation) EdgeCleared(name string) bool { switch name { case attestationpolicy.EdgeStatement: return m.clearedstatement } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *AttestationPolicyMutation) ClearEdge(name string) error { switch name { case attestationpolicy.EdgeStatement: m.ClearStatement() return nil } return fmt.Errorf("unknown AttestationPolicy unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *AttestationPolicyMutation) ResetEdge(name string) error { switch name { case attestationpolicy.EdgeStatement: m.ResetStatement() return nil } return fmt.Errorf("unknown AttestationPolicy edge %s", name) } // DsseMutation represents an operation that mutates the Dsse nodes in the graph. type DsseMutation struct { config op Op typ string id *uuid.UUID created_at *time.Time gitoid_sha256 *string payload_type *string clearedFields map[string]struct{} statement *uuid.UUID clearedstatement bool signatures map[uuid.UUID]struct{} removedsignatures map[uuid.UUID]struct{} clearedsignatures bool payload_digests map[uuid.UUID]struct{} removedpayload_digests map[uuid.UUID]struct{} clearedpayload_digests bool done bool oldValue func(context.Context) (*Dsse, error) predicates []predicate.Dsse } var _ ent.Mutation = (*DsseMutation)(nil) // dsseOption allows management of the mutation configuration using functional options. type dsseOption func(*DsseMutation) // newDsseMutation creates new mutation for the Dsse entity. func newDsseMutation(c config, op Op, opts ...dsseOption) *DsseMutation { m := &DsseMutation{ config: c, op: op, typ: TypeDsse, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withDsseID sets the ID field of the mutation. func withDsseID(id uuid.UUID) dsseOption { return func(m *DsseMutation) { var ( err error once sync.Once value *Dsse ) m.oldValue = func(ctx context.Context) (*Dsse, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Dsse.Get(ctx, id) } }) return value, err } m.id = &id } } // withDsse sets the old Dsse of the mutation. func withDsse(node *Dsse) dsseOption { return func(m *DsseMutation) { m.oldValue = func(context.Context) (*Dsse, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m DsseMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m DsseMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Dsse entities. func (m *DsseMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *DsseMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *DsseMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Dsse.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCreatedAt sets the "created_at" field. func (m *DsseMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *DsseMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Dsse entity. // If the Dsse object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DsseMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ClearCreatedAt clears the value of the "created_at" field. func (m *DsseMutation) ClearCreatedAt() { m.created_at = nil m.clearedFields[dsse.FieldCreatedAt] = struct{}{} } // CreatedAtCleared returns if the "created_at" field was cleared in this mutation. func (m *DsseMutation) CreatedAtCleared() bool { _, ok := m.clearedFields[dsse.FieldCreatedAt] return ok } // ResetCreatedAt resets all changes to the "created_at" field. func (m *DsseMutation) ResetCreatedAt() { m.created_at = nil delete(m.clearedFields, dsse.FieldCreatedAt) } // SetGitoidSha256 sets the "gitoid_sha256" field. func (m *DsseMutation) SetGitoidSha256(s string) { m.gitoid_sha256 = &s } // GitoidSha256 returns the value of the "gitoid_sha256" field in the mutation. func (m *DsseMutation) GitoidSha256() (r string, exists bool) { v := m.gitoid_sha256 if v == nil { return } return *v, true } // OldGitoidSha256 returns the old "gitoid_sha256" field's value of the Dsse entity. // If the Dsse object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DsseMutation) OldGitoidSha256(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldGitoidSha256 is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldGitoidSha256 requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldGitoidSha256: %w", err) } return oldValue.GitoidSha256, nil } // ResetGitoidSha256 resets all changes to the "gitoid_sha256" field. func (m *DsseMutation) ResetGitoidSha256() { m.gitoid_sha256 = nil } // SetPayloadType sets the "payload_type" field. func (m *DsseMutation) SetPayloadType(s string) { m.payload_type = &s } // PayloadType returns the value of the "payload_type" field in the mutation. func (m *DsseMutation) PayloadType() (r string, exists bool) { v := m.payload_type if v == nil { return } return *v, true } // OldPayloadType returns the old "payload_type" field's value of the Dsse entity. // If the Dsse object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *DsseMutation) OldPayloadType(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPayloadType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPayloadType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPayloadType: %w", err) } return oldValue.PayloadType, nil } // ResetPayloadType resets all changes to the "payload_type" field. func (m *DsseMutation) ResetPayloadType() { m.payload_type = nil } // SetStatementID sets the "statement" edge to the Statement entity by id. func (m *DsseMutation) SetStatementID(id uuid.UUID) { m.statement = &id } // ClearStatement clears the "statement" edge to the Statement entity. func (m *DsseMutation) ClearStatement() { m.clearedstatement = true } // StatementCleared reports if the "statement" edge to the Statement entity was cleared. func (m *DsseMutation) StatementCleared() bool { return m.clearedstatement } // StatementID returns the "statement" edge ID in the mutation. func (m *DsseMutation) StatementID() (id uuid.UUID, exists bool) { if m.statement != nil { return *m.statement, true } return } // StatementIDs returns the "statement" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // StatementID instead. It exists only for internal usage by the builders. func (m *DsseMutation) StatementIDs() (ids []uuid.UUID) { if id := m.statement; id != nil { ids = append(ids, *id) } return } // ResetStatement resets all changes to the "statement" edge. func (m *DsseMutation) ResetStatement() { m.statement = nil m.clearedstatement = false } // AddSignatureIDs adds the "signatures" edge to the Signature entity by ids. func (m *DsseMutation) AddSignatureIDs(ids ...uuid.UUID) { if m.signatures == nil { m.signatures = make(map[uuid.UUID]struct{}) } for i := range ids { m.signatures[ids[i]] = struct{}{} } } // ClearSignatures clears the "signatures" edge to the Signature entity. func (m *DsseMutation) ClearSignatures() { m.clearedsignatures = true } // SignaturesCleared reports if the "signatures" edge to the Signature entity was cleared. func (m *DsseMutation) SignaturesCleared() bool { return m.clearedsignatures } // RemoveSignatureIDs removes the "signatures" edge to the Signature entity by IDs. func (m *DsseMutation) RemoveSignatureIDs(ids ...uuid.UUID) { if m.removedsignatures == nil { m.removedsignatures = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.signatures, ids[i]) m.removedsignatures[ids[i]] = struct{}{} } } // RemovedSignatures returns the removed IDs of the "signatures" edge to the Signature entity. func (m *DsseMutation) RemovedSignaturesIDs() (ids []uuid.UUID) { for id := range m.removedsignatures { ids = append(ids, id) } return } // SignaturesIDs returns the "signatures" edge IDs in the mutation. func (m *DsseMutation) SignaturesIDs() (ids []uuid.UUID) { for id := range m.signatures { ids = append(ids, id) } return } // ResetSignatures resets all changes to the "signatures" edge. func (m *DsseMutation) ResetSignatures() { m.signatures = nil m.clearedsignatures = false m.removedsignatures = nil } // AddPayloadDigestIDs adds the "payload_digests" edge to the PayloadDigest entity by ids. func (m *DsseMutation) AddPayloadDigestIDs(ids ...uuid.UUID) { if m.payload_digests == nil { m.payload_digests = make(map[uuid.UUID]struct{}) } for i := range ids { m.payload_digests[ids[i]] = struct{}{} } } // ClearPayloadDigests clears the "payload_digests" edge to the PayloadDigest entity. func (m *DsseMutation) ClearPayloadDigests() { m.clearedpayload_digests = true } // PayloadDigestsCleared reports if the "payload_digests" edge to the PayloadDigest entity was cleared. func (m *DsseMutation) PayloadDigestsCleared() bool { return m.clearedpayload_digests } // RemovePayloadDigestIDs removes the "payload_digests" edge to the PayloadDigest entity by IDs. func (m *DsseMutation) RemovePayloadDigestIDs(ids ...uuid.UUID) { if m.removedpayload_digests == nil { m.removedpayload_digests = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.payload_digests, ids[i]) m.removedpayload_digests[ids[i]] = struct{}{} } } // RemovedPayloadDigests returns the removed IDs of the "payload_digests" edge to the PayloadDigest entity. func (m *DsseMutation) RemovedPayloadDigestsIDs() (ids []uuid.UUID) { for id := range m.removedpayload_digests { ids = append(ids, id) } return } // PayloadDigestsIDs returns the "payload_digests" edge IDs in the mutation. func (m *DsseMutation) PayloadDigestsIDs() (ids []uuid.UUID) { for id := range m.payload_digests { ids = append(ids, id) } return } // ResetPayloadDigests resets all changes to the "payload_digests" edge. func (m *DsseMutation) ResetPayloadDigests() { m.payload_digests = nil m.clearedpayload_digests = false m.removedpayload_digests = nil } // Where appends a list predicates to the DsseMutation builder. func (m *DsseMutation) Where(ps ...predicate.Dsse) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the DsseMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *DsseMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Dsse, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *DsseMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *DsseMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Dsse). func (m *DsseMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *DsseMutation) Fields() []string { fields := make([]string, 0, 3) if m.created_at != nil { fields = append(fields, dsse.FieldCreatedAt) } if m.gitoid_sha256 != nil { fields = append(fields, dsse.FieldGitoidSha256) } if m.payload_type != nil { fields = append(fields, dsse.FieldPayloadType) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *DsseMutation) Field(name string) (ent.Value, bool) { switch name { case dsse.FieldCreatedAt: return m.CreatedAt() case dsse.FieldGitoidSha256: return m.GitoidSha256() case dsse.FieldPayloadType: return m.PayloadType() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *DsseMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case dsse.FieldCreatedAt: return m.OldCreatedAt(ctx) case dsse.FieldGitoidSha256: return m.OldGitoidSha256(ctx) case dsse.FieldPayloadType: return m.OldPayloadType(ctx) } return nil, fmt.Errorf("unknown Dsse field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *DsseMutation) SetField(name string, value ent.Value) error { switch name { case dsse.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case dsse.FieldGitoidSha256: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetGitoidSha256(v) return nil case dsse.FieldPayloadType: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPayloadType(v) return nil } return fmt.Errorf("unknown Dsse field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *DsseMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *DsseMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *DsseMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Dsse numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *DsseMutation) ClearedFields() []string { var fields []string if m.FieldCleared(dsse.FieldCreatedAt) { fields = append(fields, dsse.FieldCreatedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *DsseMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *DsseMutation) ClearField(name string) error { switch name { case dsse.FieldCreatedAt: m.ClearCreatedAt() return nil } return fmt.Errorf("unknown Dsse nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *DsseMutation) ResetField(name string) error { switch name { case dsse.FieldCreatedAt: m.ResetCreatedAt() return nil case dsse.FieldGitoidSha256: m.ResetGitoidSha256() return nil case dsse.FieldPayloadType: m.ResetPayloadType() return nil } return fmt.Errorf("unknown Dsse field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *DsseMutation) AddedEdges() []string { edges := make([]string, 0, 3) if m.statement != nil { edges = append(edges, dsse.EdgeStatement) } if m.signatures != nil { edges = append(edges, dsse.EdgeSignatures) } if m.payload_digests != nil { edges = append(edges, dsse.EdgePayloadDigests) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *DsseMutation) AddedIDs(name string) []ent.Value { switch name { case dsse.EdgeStatement: if id := m.statement; id != nil { return []ent.Value{*id} } case dsse.EdgeSignatures: ids := make([]ent.Value, 0, len(m.signatures)) for id := range m.signatures { ids = append(ids, id) } return ids case dsse.EdgePayloadDigests: ids := make([]ent.Value, 0, len(m.payload_digests)) for id := range m.payload_digests { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *DsseMutation) RemovedEdges() []string { edges := make([]string, 0, 3) if m.removedsignatures != nil { edges = append(edges, dsse.EdgeSignatures) } if m.removedpayload_digests != nil { edges = append(edges, dsse.EdgePayloadDigests) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *DsseMutation) RemovedIDs(name string) []ent.Value { switch name { case dsse.EdgeSignatures: ids := make([]ent.Value, 0, len(m.removedsignatures)) for id := range m.removedsignatures { ids = append(ids, id) } return ids case dsse.EdgePayloadDigests: ids := make([]ent.Value, 0, len(m.removedpayload_digests)) for id := range m.removedpayload_digests { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *DsseMutation) ClearedEdges() []string { edges := make([]string, 0, 3) if m.clearedstatement { edges = append(edges, dsse.EdgeStatement) } if m.clearedsignatures { edges = append(edges, dsse.EdgeSignatures) } if m.clearedpayload_digests { edges = append(edges, dsse.EdgePayloadDigests) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *DsseMutation) EdgeCleared(name string) bool { switch name { case dsse.EdgeStatement: return m.clearedstatement case dsse.EdgeSignatures: return m.clearedsignatures case dsse.EdgePayloadDigests: return m.clearedpayload_digests } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *DsseMutation) ClearEdge(name string) error { switch name { case dsse.EdgeStatement: m.ClearStatement() return nil } return fmt.Errorf("unknown Dsse unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *DsseMutation) ResetEdge(name string) error { switch name { case dsse.EdgeStatement: m.ResetStatement() return nil case dsse.EdgeSignatures: m.ResetSignatures() return nil case dsse.EdgePayloadDigests: m.ResetPayloadDigests() return nil } return fmt.Errorf("unknown Dsse edge %s", name) } // PayloadDigestMutation represents an operation that mutates the PayloadDigest nodes in the graph. type PayloadDigestMutation struct { config op Op typ string id *uuid.UUID algorithm *string value *string clearedFields map[string]struct{} dsse *uuid.UUID cleareddsse bool done bool oldValue func(context.Context) (*PayloadDigest, error) predicates []predicate.PayloadDigest } var _ ent.Mutation = (*PayloadDigestMutation)(nil) // payloaddigestOption allows management of the mutation configuration using functional options. type payloaddigestOption func(*PayloadDigestMutation) // newPayloadDigestMutation creates new mutation for the PayloadDigest entity. func newPayloadDigestMutation(c config, op Op, opts ...payloaddigestOption) *PayloadDigestMutation { m := &PayloadDigestMutation{ config: c, op: op, typ: TypePayloadDigest, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withPayloadDigestID sets the ID field of the mutation. func withPayloadDigestID(id uuid.UUID) payloaddigestOption { return func(m *PayloadDigestMutation) { var ( err error once sync.Once value *PayloadDigest ) m.oldValue = func(ctx context.Context) (*PayloadDigest, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().PayloadDigest.Get(ctx, id) } }) return value, err } m.id = &id } } // withPayloadDigest sets the old PayloadDigest of the mutation. func withPayloadDigest(node *PayloadDigest) payloaddigestOption { return func(m *PayloadDigestMutation) { m.oldValue = func(context.Context) (*PayloadDigest, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m PayloadDigestMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m PayloadDigestMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of PayloadDigest entities. func (m *PayloadDigestMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *PayloadDigestMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *PayloadDigestMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().PayloadDigest.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetAlgorithm sets the "algorithm" field. func (m *PayloadDigestMutation) SetAlgorithm(s string) { m.algorithm = &s } // Algorithm returns the value of the "algorithm" field in the mutation. func (m *PayloadDigestMutation) Algorithm() (r string, exists bool) { v := m.algorithm if v == nil { return } return *v, true } // OldAlgorithm returns the old "algorithm" field's value of the PayloadDigest entity. // If the PayloadDigest object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PayloadDigestMutation) OldAlgorithm(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAlgorithm is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAlgorithm requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAlgorithm: %w", err) } return oldValue.Algorithm, nil } // ResetAlgorithm resets all changes to the "algorithm" field. func (m *PayloadDigestMutation) ResetAlgorithm() { m.algorithm = nil } // SetValue sets the "value" field. func (m *PayloadDigestMutation) SetValue(s string) { m.value = &s } // Value returns the value of the "value" field in the mutation. func (m *PayloadDigestMutation) Value() (r string, exists bool) { v := m.value if v == nil { return } return *v, true } // OldValue returns the old "value" field's value of the PayloadDigest entity. // If the PayloadDigest object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *PayloadDigestMutation) OldValue(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldValue is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldValue requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldValue: %w", err) } return oldValue.Value, nil } // ResetValue resets all changes to the "value" field. func (m *PayloadDigestMutation) ResetValue() { m.value = nil } // SetDsseID sets the "dsse" edge to the Dsse entity by id. func (m *PayloadDigestMutation) SetDsseID(id uuid.UUID) { m.dsse = &id } // ClearDsse clears the "dsse" edge to the Dsse entity. func (m *PayloadDigestMutation) ClearDsse() { m.cleareddsse = true } // DsseCleared reports if the "dsse" edge to the Dsse entity was cleared. func (m *PayloadDigestMutation) DsseCleared() bool { return m.cleareddsse } // DsseID returns the "dsse" edge ID in the mutation. func (m *PayloadDigestMutation) DsseID() (id uuid.UUID, exists bool) { if m.dsse != nil { return *m.dsse, true } return } // DsseIDs returns the "dsse" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // DsseID instead. It exists only for internal usage by the builders. func (m *PayloadDigestMutation) DsseIDs() (ids []uuid.UUID) { if id := m.dsse; id != nil { ids = append(ids, *id) } return } // ResetDsse resets all changes to the "dsse" edge. func (m *PayloadDigestMutation) ResetDsse() { m.dsse = nil m.cleareddsse = false } // Where appends a list predicates to the PayloadDigestMutation builder. func (m *PayloadDigestMutation) Where(ps ...predicate.PayloadDigest) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the PayloadDigestMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *PayloadDigestMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.PayloadDigest, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *PayloadDigestMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *PayloadDigestMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (PayloadDigest). func (m *PayloadDigestMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *PayloadDigestMutation) Fields() []string { fields := make([]string, 0, 2) if m.algorithm != nil { fields = append(fields, payloaddigest.FieldAlgorithm) } if m.value != nil { fields = append(fields, payloaddigest.FieldValue) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *PayloadDigestMutation) Field(name string) (ent.Value, bool) { switch name { case payloaddigest.FieldAlgorithm: return m.Algorithm() case payloaddigest.FieldValue: return m.Value() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *PayloadDigestMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case payloaddigest.FieldAlgorithm: return m.OldAlgorithm(ctx) case payloaddigest.FieldValue: return m.OldValue(ctx) } return nil, fmt.Errorf("unknown PayloadDigest field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *PayloadDigestMutation) SetField(name string, value ent.Value) error { switch name { case payloaddigest.FieldAlgorithm: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAlgorithm(v) return nil case payloaddigest.FieldValue: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetValue(v) return nil } return fmt.Errorf("unknown PayloadDigest field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *PayloadDigestMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *PayloadDigestMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *PayloadDigestMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown PayloadDigest numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *PayloadDigestMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *PayloadDigestMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *PayloadDigestMutation) ClearField(name string) error { return fmt.Errorf("unknown PayloadDigest nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *PayloadDigestMutation) ResetField(name string) error { switch name { case payloaddigest.FieldAlgorithm: m.ResetAlgorithm() return nil case payloaddigest.FieldValue: m.ResetValue() return nil } return fmt.Errorf("unknown PayloadDigest field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *PayloadDigestMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.dsse != nil { edges = append(edges, payloaddigest.EdgeDsse) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *PayloadDigestMutation) AddedIDs(name string) []ent.Value { switch name { case payloaddigest.EdgeDsse: if id := m.dsse; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *PayloadDigestMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *PayloadDigestMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *PayloadDigestMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.cleareddsse { edges = append(edges, payloaddigest.EdgeDsse) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *PayloadDigestMutation) EdgeCleared(name string) bool { switch name { case payloaddigest.EdgeDsse: return m.cleareddsse } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *PayloadDigestMutation) ClearEdge(name string) error { switch name { case payloaddigest.EdgeDsse: m.ClearDsse() return nil } return fmt.Errorf("unknown PayloadDigest unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *PayloadDigestMutation) ResetEdge(name string) error { switch name { case payloaddigest.EdgeDsse: m.ResetDsse() return nil } return fmt.Errorf("unknown PayloadDigest edge %s", name) } // SignatureMutation represents an operation that mutates the Signature nodes in the graph. type SignatureMutation struct { config op Op typ string id *uuid.UUID key_id *string signature *string clearedFields map[string]struct{} dsse *uuid.UUID cleareddsse bool timestamps map[uuid.UUID]struct{} removedtimestamps map[uuid.UUID]struct{} clearedtimestamps bool done bool oldValue func(context.Context) (*Signature, error) predicates []predicate.Signature } var _ ent.Mutation = (*SignatureMutation)(nil) // signatureOption allows management of the mutation configuration using functional options. type signatureOption func(*SignatureMutation) // newSignatureMutation creates new mutation for the Signature entity. func newSignatureMutation(c config, op Op, opts ...signatureOption) *SignatureMutation { m := &SignatureMutation{ config: c, op: op, typ: TypeSignature, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withSignatureID sets the ID field of the mutation. func withSignatureID(id uuid.UUID) signatureOption { return func(m *SignatureMutation) { var ( err error once sync.Once value *Signature ) m.oldValue = func(ctx context.Context) (*Signature, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Signature.Get(ctx, id) } }) return value, err } m.id = &id } } // withSignature sets the old Signature of the mutation. func withSignature(node *Signature) signatureOption { return func(m *SignatureMutation) { m.oldValue = func(context.Context) (*Signature, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m SignatureMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m SignatureMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Signature entities. func (m *SignatureMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *SignatureMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *SignatureMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Signature.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetKeyID sets the "key_id" field. func (m *SignatureMutation) SetKeyID(s string) { m.key_id = &s } // KeyID returns the value of the "key_id" field in the mutation. func (m *SignatureMutation) KeyID() (r string, exists bool) { v := m.key_id if v == nil { return } return *v, true } // OldKeyID returns the old "key_id" field's value of the Signature entity. // If the Signature object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SignatureMutation) OldKeyID(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldKeyID is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldKeyID requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldKeyID: %w", err) } return oldValue.KeyID, nil } // ResetKeyID resets all changes to the "key_id" field. func (m *SignatureMutation) ResetKeyID() { m.key_id = nil } // SetSignature sets the "signature" field. func (m *SignatureMutation) SetSignature(s string) { m.signature = &s } // Signature returns the value of the "signature" field in the mutation. func (m *SignatureMutation) Signature() (r string, exists bool) { v := m.signature if v == nil { return } return *v, true } // OldSignature returns the old "signature" field's value of the Signature entity. // If the Signature object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SignatureMutation) OldSignature(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldSignature is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldSignature requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldSignature: %w", err) } return oldValue.Signature, nil } // ResetSignature resets all changes to the "signature" field. func (m *SignatureMutation) ResetSignature() { m.signature = nil } // SetDsseID sets the "dsse" edge to the Dsse entity by id. func (m *SignatureMutation) SetDsseID(id uuid.UUID) { m.dsse = &id } // ClearDsse clears the "dsse" edge to the Dsse entity. func (m *SignatureMutation) ClearDsse() { m.cleareddsse = true } // DsseCleared reports if the "dsse" edge to the Dsse entity was cleared. func (m *SignatureMutation) DsseCleared() bool { return m.cleareddsse } // DsseID returns the "dsse" edge ID in the mutation. func (m *SignatureMutation) DsseID() (id uuid.UUID, exists bool) { if m.dsse != nil { return *m.dsse, true } return } // DsseIDs returns the "dsse" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // DsseID instead. It exists only for internal usage by the builders. func (m *SignatureMutation) DsseIDs() (ids []uuid.UUID) { if id := m.dsse; id != nil { ids = append(ids, *id) } return } // ResetDsse resets all changes to the "dsse" edge. func (m *SignatureMutation) ResetDsse() { m.dsse = nil m.cleareddsse = false } // AddTimestampIDs adds the "timestamps" edge to the Timestamp entity by ids. func (m *SignatureMutation) AddTimestampIDs(ids ...uuid.UUID) { if m.timestamps == nil { m.timestamps = make(map[uuid.UUID]struct{}) } for i := range ids { m.timestamps[ids[i]] = struct{}{} } } // ClearTimestamps clears the "timestamps" edge to the Timestamp entity. func (m *SignatureMutation) ClearTimestamps() { m.clearedtimestamps = true } // TimestampsCleared reports if the "timestamps" edge to the Timestamp entity was cleared. func (m *SignatureMutation) TimestampsCleared() bool { return m.clearedtimestamps } // RemoveTimestampIDs removes the "timestamps" edge to the Timestamp entity by IDs. func (m *SignatureMutation) RemoveTimestampIDs(ids ...uuid.UUID) { if m.removedtimestamps == nil { m.removedtimestamps = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.timestamps, ids[i]) m.removedtimestamps[ids[i]] = struct{}{} } } // RemovedTimestamps returns the removed IDs of the "timestamps" edge to the Timestamp entity. func (m *SignatureMutation) RemovedTimestampsIDs() (ids []uuid.UUID) { for id := range m.removedtimestamps { ids = append(ids, id) } return } // TimestampsIDs returns the "timestamps" edge IDs in the mutation. func (m *SignatureMutation) TimestampsIDs() (ids []uuid.UUID) { for id := range m.timestamps { ids = append(ids, id) } return } // ResetTimestamps resets all changes to the "timestamps" edge. func (m *SignatureMutation) ResetTimestamps() { m.timestamps = nil m.clearedtimestamps = false m.removedtimestamps = nil } // Where appends a list predicates to the SignatureMutation builder. func (m *SignatureMutation) Where(ps ...predicate.Signature) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the SignatureMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *SignatureMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Signature, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *SignatureMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *SignatureMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Signature). func (m *SignatureMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SignatureMutation) Fields() []string { fields := make([]string, 0, 2) if m.key_id != nil { fields = append(fields, signature.FieldKeyID) } if m.signature != nil { fields = append(fields, signature.FieldSignature) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *SignatureMutation) Field(name string) (ent.Value, bool) { switch name { case signature.FieldKeyID: return m.KeyID() case signature.FieldSignature: return m.Signature() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *SignatureMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case signature.FieldKeyID: return m.OldKeyID(ctx) case signature.FieldSignature: return m.OldSignature(ctx) } return nil, fmt.Errorf("unknown Signature field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *SignatureMutation) SetField(name string, value ent.Value) error { switch name { case signature.FieldKeyID: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetKeyID(v) return nil case signature.FieldSignature: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetSignature(v) return nil } return fmt.Errorf("unknown Signature field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SignatureMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *SignatureMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *SignatureMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Signature numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *SignatureMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *SignatureMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *SignatureMutation) ClearField(name string) error { return fmt.Errorf("unknown Signature nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *SignatureMutation) ResetField(name string) error { switch name { case signature.FieldKeyID: m.ResetKeyID() return nil case signature.FieldSignature: m.ResetSignature() return nil } return fmt.Errorf("unknown Signature field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *SignatureMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.dsse != nil { edges = append(edges, signature.EdgeDsse) } if m.timestamps != nil { edges = append(edges, signature.EdgeTimestamps) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *SignatureMutation) AddedIDs(name string) []ent.Value { switch name { case signature.EdgeDsse: if id := m.dsse; id != nil { return []ent.Value{*id} } case signature.EdgeTimestamps: ids := make([]ent.Value, 0, len(m.timestamps)) for id := range m.timestamps { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SignatureMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedtimestamps != nil { edges = append(edges, signature.EdgeTimestamps) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *SignatureMutation) RemovedIDs(name string) []ent.Value { switch name { case signature.EdgeTimestamps: ids := make([]ent.Value, 0, len(m.removedtimestamps)) for id := range m.removedtimestamps { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SignatureMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.cleareddsse { edges = append(edges, signature.EdgeDsse) } if m.clearedtimestamps { edges = append(edges, signature.EdgeTimestamps) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *SignatureMutation) EdgeCleared(name string) bool { switch name { case signature.EdgeDsse: return m.cleareddsse case signature.EdgeTimestamps: return m.clearedtimestamps } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *SignatureMutation) ClearEdge(name string) error { switch name { case signature.EdgeDsse: m.ClearDsse() return nil } return fmt.Errorf("unknown Signature unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *SignatureMutation) ResetEdge(name string) error { switch name { case signature.EdgeDsse: m.ResetDsse() return nil case signature.EdgeTimestamps: m.ResetTimestamps() return nil } return fmt.Errorf("unknown Signature edge %s", name) } // StatementMutation represents an operation that mutates the Statement nodes in the graph. type StatementMutation struct { config op Op typ string id *uuid.UUID predicate *string clearedFields map[string]struct{} subjects map[uuid.UUID]struct{} removedsubjects map[uuid.UUID]struct{} clearedsubjects bool policy *uuid.UUID clearedpolicy bool attestation_collections *uuid.UUID clearedattestation_collections bool dsse map[uuid.UUID]struct{} removeddsse map[uuid.UUID]struct{} cleareddsse bool done bool oldValue func(context.Context) (*Statement, error) predicates []predicate.Statement } var _ ent.Mutation = (*StatementMutation)(nil) // statementOption allows management of the mutation configuration using functional options. type statementOption func(*StatementMutation) // newStatementMutation creates new mutation for the Statement entity. func newStatementMutation(c config, op Op, opts ...statementOption) *StatementMutation { m := &StatementMutation{ config: c, op: op, typ: TypeStatement, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withStatementID sets the ID field of the mutation. func withStatementID(id uuid.UUID) statementOption { return func(m *StatementMutation) { var ( err error once sync.Once value *Statement ) m.oldValue = func(ctx context.Context) (*Statement, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Statement.Get(ctx, id) } }) return value, err } m.id = &id } } // withStatement sets the old Statement of the mutation. func withStatement(node *Statement) statementOption { return func(m *StatementMutation) { m.oldValue = func(context.Context) (*Statement, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m StatementMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m StatementMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Statement entities. func (m *StatementMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *StatementMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *StatementMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Statement.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetPredicate sets the "predicate" field. func (m *StatementMutation) SetPredicate(s string) { m.predicate = &s } // Predicate returns the value of the "predicate" field in the mutation. func (m *StatementMutation) Predicate() (r string, exists bool) { v := m.predicate if v == nil { return } return *v, true } // OldPredicate returns the old "predicate" field's value of the Statement entity. // If the Statement object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *StatementMutation) OldPredicate(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldPredicate is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldPredicate requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldPredicate: %w", err) } return oldValue.Predicate, nil } // ResetPredicate resets all changes to the "predicate" field. func (m *StatementMutation) ResetPredicate() { m.predicate = nil } // AddSubjectIDs adds the "subjects" edge to the Subject entity by ids. func (m *StatementMutation) AddSubjectIDs(ids ...uuid.UUID) { if m.subjects == nil { m.subjects = make(map[uuid.UUID]struct{}) } for i := range ids { m.subjects[ids[i]] = struct{}{} } } // ClearSubjects clears the "subjects" edge to the Subject entity. func (m *StatementMutation) ClearSubjects() { m.clearedsubjects = true } // SubjectsCleared reports if the "subjects" edge to the Subject entity was cleared. func (m *StatementMutation) SubjectsCleared() bool { return m.clearedsubjects } // RemoveSubjectIDs removes the "subjects" edge to the Subject entity by IDs. func (m *StatementMutation) RemoveSubjectIDs(ids ...uuid.UUID) { if m.removedsubjects == nil { m.removedsubjects = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.subjects, ids[i]) m.removedsubjects[ids[i]] = struct{}{} } } // RemovedSubjects returns the removed IDs of the "subjects" edge to the Subject entity. func (m *StatementMutation) RemovedSubjectsIDs() (ids []uuid.UUID) { for id := range m.removedsubjects { ids = append(ids, id) } return } // SubjectsIDs returns the "subjects" edge IDs in the mutation. func (m *StatementMutation) SubjectsIDs() (ids []uuid.UUID) { for id := range m.subjects { ids = append(ids, id) } return } // ResetSubjects resets all changes to the "subjects" edge. func (m *StatementMutation) ResetSubjects() { m.subjects = nil m.clearedsubjects = false m.removedsubjects = nil } // SetPolicyID sets the "policy" edge to the AttestationPolicy entity by id. func (m *StatementMutation) SetPolicyID(id uuid.UUID) { m.policy = &id } // ClearPolicy clears the "policy" edge to the AttestationPolicy entity. func (m *StatementMutation) ClearPolicy() { m.clearedpolicy = true } // PolicyCleared reports if the "policy" edge to the AttestationPolicy entity was cleared. func (m *StatementMutation) PolicyCleared() bool { return m.clearedpolicy } // PolicyID returns the "policy" edge ID in the mutation. func (m *StatementMutation) PolicyID() (id uuid.UUID, exists bool) { if m.policy != nil { return *m.policy, true } return } // PolicyIDs returns the "policy" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // PolicyID instead. It exists only for internal usage by the builders. func (m *StatementMutation) PolicyIDs() (ids []uuid.UUID) { if id := m.policy; id != nil { ids = append(ids, *id) } return } // ResetPolicy resets all changes to the "policy" edge. func (m *StatementMutation) ResetPolicy() { m.policy = nil m.clearedpolicy = false } // SetAttestationCollectionsID sets the "attestation_collections" edge to the AttestationCollection entity by id. func (m *StatementMutation) SetAttestationCollectionsID(id uuid.UUID) { m.attestation_collections = &id } // ClearAttestationCollections clears the "attestation_collections" edge to the AttestationCollection entity. func (m *StatementMutation) ClearAttestationCollections() { m.clearedattestation_collections = true } // AttestationCollectionsCleared reports if the "attestation_collections" edge to the AttestationCollection entity was cleared. func (m *StatementMutation) AttestationCollectionsCleared() bool { return m.clearedattestation_collections } // AttestationCollectionsID returns the "attestation_collections" edge ID in the mutation. func (m *StatementMutation) AttestationCollectionsID() (id uuid.UUID, exists bool) { if m.attestation_collections != nil { return *m.attestation_collections, true } return } // AttestationCollectionsIDs returns the "attestation_collections" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // AttestationCollectionsID instead. It exists only for internal usage by the builders. func (m *StatementMutation) AttestationCollectionsIDs() (ids []uuid.UUID) { if id := m.attestation_collections; id != nil { ids = append(ids, *id) } return } // ResetAttestationCollections resets all changes to the "attestation_collections" edge. func (m *StatementMutation) ResetAttestationCollections() { m.attestation_collections = nil m.clearedattestation_collections = false } // AddDsseIDs adds the "dsse" edge to the Dsse entity by ids. func (m *StatementMutation) AddDsseIDs(ids ...uuid.UUID) { if m.dsse == nil { m.dsse = make(map[uuid.UUID]struct{}) } for i := range ids { m.dsse[ids[i]] = struct{}{} } } // ClearDsse clears the "dsse" edge to the Dsse entity. func (m *StatementMutation) ClearDsse() { m.cleareddsse = true } // DsseCleared reports if the "dsse" edge to the Dsse entity was cleared. func (m *StatementMutation) DsseCleared() bool { return m.cleareddsse } // RemoveDsseIDs removes the "dsse" edge to the Dsse entity by IDs. func (m *StatementMutation) RemoveDsseIDs(ids ...uuid.UUID) { if m.removeddsse == nil { m.removeddsse = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.dsse, ids[i]) m.removeddsse[ids[i]] = struct{}{} } } // RemovedDsse returns the removed IDs of the "dsse" edge to the Dsse entity. func (m *StatementMutation) RemovedDsseIDs() (ids []uuid.UUID) { for id := range m.removeddsse { ids = append(ids, id) } return } // DsseIDs returns the "dsse" edge IDs in the mutation. func (m *StatementMutation) DsseIDs() (ids []uuid.UUID) { for id := range m.dsse { ids = append(ids, id) } return } // ResetDsse resets all changes to the "dsse" edge. func (m *StatementMutation) ResetDsse() { m.dsse = nil m.cleareddsse = false m.removeddsse = nil } // Where appends a list predicates to the StatementMutation builder. func (m *StatementMutation) Where(ps ...predicate.Statement) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the StatementMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *StatementMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Statement, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *StatementMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *StatementMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Statement). func (m *StatementMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *StatementMutation) Fields() []string { fields := make([]string, 0, 1) if m.predicate != nil { fields = append(fields, statement.FieldPredicate) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *StatementMutation) Field(name string) (ent.Value, bool) { switch name { case statement.FieldPredicate: return m.Predicate() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *StatementMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case statement.FieldPredicate: return m.OldPredicate(ctx) } return nil, fmt.Errorf("unknown Statement field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *StatementMutation) SetField(name string, value ent.Value) error { switch name { case statement.FieldPredicate: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetPredicate(v) return nil } return fmt.Errorf("unknown Statement field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *StatementMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *StatementMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *StatementMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Statement numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *StatementMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *StatementMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *StatementMutation) ClearField(name string) error { return fmt.Errorf("unknown Statement nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *StatementMutation) ResetField(name string) error { switch name { case statement.FieldPredicate: m.ResetPredicate() return nil } return fmt.Errorf("unknown Statement field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *StatementMutation) AddedEdges() []string { edges := make([]string, 0, 4) if m.subjects != nil { edges = append(edges, statement.EdgeSubjects) } if m.policy != nil { edges = append(edges, statement.EdgePolicy) } if m.attestation_collections != nil { edges = append(edges, statement.EdgeAttestationCollections) } if m.dsse != nil { edges = append(edges, statement.EdgeDsse) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *StatementMutation) AddedIDs(name string) []ent.Value { switch name { case statement.EdgeSubjects: ids := make([]ent.Value, 0, len(m.subjects)) for id := range m.subjects { ids = append(ids, id) } return ids case statement.EdgePolicy: if id := m.policy; id != nil { return []ent.Value{*id} } case statement.EdgeAttestationCollections: if id := m.attestation_collections; id != nil { return []ent.Value{*id} } case statement.EdgeDsse: ids := make([]ent.Value, 0, len(m.dsse)) for id := range m.dsse { ids = append(ids, id) } return ids } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *StatementMutation) RemovedEdges() []string { edges := make([]string, 0, 4) if m.removedsubjects != nil { edges = append(edges, statement.EdgeSubjects) } if m.removeddsse != nil { edges = append(edges, statement.EdgeDsse) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *StatementMutation) RemovedIDs(name string) []ent.Value { switch name { case statement.EdgeSubjects: ids := make([]ent.Value, 0, len(m.removedsubjects)) for id := range m.removedsubjects { ids = append(ids, id) } return ids case statement.EdgeDsse: ids := make([]ent.Value, 0, len(m.removeddsse)) for id := range m.removeddsse { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *StatementMutation) ClearedEdges() []string { edges := make([]string, 0, 4) if m.clearedsubjects { edges = append(edges, statement.EdgeSubjects) } if m.clearedpolicy { edges = append(edges, statement.EdgePolicy) } if m.clearedattestation_collections { edges = append(edges, statement.EdgeAttestationCollections) } if m.cleareddsse { edges = append(edges, statement.EdgeDsse) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *StatementMutation) EdgeCleared(name string) bool { switch name { case statement.EdgeSubjects: return m.clearedsubjects case statement.EdgePolicy: return m.clearedpolicy case statement.EdgeAttestationCollections: return m.clearedattestation_collections case statement.EdgeDsse: return m.cleareddsse } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *StatementMutation) ClearEdge(name string) error { switch name { case statement.EdgePolicy: m.ClearPolicy() return nil case statement.EdgeAttestationCollections: m.ClearAttestationCollections() return nil } return fmt.Errorf("unknown Statement unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *StatementMutation) ResetEdge(name string) error { switch name { case statement.EdgeSubjects: m.ResetSubjects() return nil case statement.EdgePolicy: m.ResetPolicy() return nil case statement.EdgeAttestationCollections: m.ResetAttestationCollections() return nil case statement.EdgeDsse: m.ResetDsse() return nil } return fmt.Errorf("unknown Statement edge %s", name) } // SubjectMutation represents an operation that mutates the Subject nodes in the graph. type SubjectMutation struct { config op Op typ string id *uuid.UUID created_at *time.Time name *string clearedFields map[string]struct{} subject_digests map[uuid.UUID]struct{} removedsubject_digests map[uuid.UUID]struct{} clearedsubject_digests bool statement *uuid.UUID clearedstatement bool done bool oldValue func(context.Context) (*Subject, error) predicates []predicate.Subject } var _ ent.Mutation = (*SubjectMutation)(nil) // subjectOption allows management of the mutation configuration using functional options. type subjectOption func(*SubjectMutation) // newSubjectMutation creates new mutation for the Subject entity. func newSubjectMutation(c config, op Op, opts ...subjectOption) *SubjectMutation { m := &SubjectMutation{ config: c, op: op, typ: TypeSubject, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withSubjectID sets the ID field of the mutation. func withSubjectID(id uuid.UUID) subjectOption { return func(m *SubjectMutation) { var ( err error once sync.Once value *Subject ) m.oldValue = func(ctx context.Context) (*Subject, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Subject.Get(ctx, id) } }) return value, err } m.id = &id } } // withSubject sets the old Subject of the mutation. func withSubject(node *Subject) subjectOption { return func(m *SubjectMutation) { m.oldValue = func(context.Context) (*Subject, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m SubjectMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m SubjectMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Subject entities. func (m *SubjectMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *SubjectMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *SubjectMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Subject.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetCreatedAt sets the "created_at" field. func (m *SubjectMutation) SetCreatedAt(t time.Time) { m.created_at = &t } // CreatedAt returns the value of the "created_at" field in the mutation. func (m *SubjectMutation) CreatedAt() (r time.Time, exists bool) { v := m.created_at if v == nil { return } return *v, true } // OldCreatedAt returns the old "created_at" field's value of the Subject entity. // If the Subject object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SubjectMutation) OldCreatedAt(ctx context.Context) (v *time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldCreatedAt requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) } return oldValue.CreatedAt, nil } // ClearCreatedAt clears the value of the "created_at" field. func (m *SubjectMutation) ClearCreatedAt() { m.created_at = nil m.clearedFields[subject.FieldCreatedAt] = struct{}{} } // CreatedAtCleared returns if the "created_at" field was cleared in this mutation. func (m *SubjectMutation) CreatedAtCleared() bool { _, ok := m.clearedFields[subject.FieldCreatedAt] return ok } // ResetCreatedAt resets all changes to the "created_at" field. func (m *SubjectMutation) ResetCreatedAt() { m.created_at = nil delete(m.clearedFields, subject.FieldCreatedAt) } // SetName sets the "name" field. func (m *SubjectMutation) SetName(s string) { m.name = &s } // Name returns the value of the "name" field in the mutation. func (m *SubjectMutation) Name() (r string, exists bool) { v := m.name if v == nil { return } return *v, true } // OldName returns the old "name" field's value of the Subject entity. // If the Subject object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SubjectMutation) OldName(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldName is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldName requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldName: %w", err) } return oldValue.Name, nil } // ResetName resets all changes to the "name" field. func (m *SubjectMutation) ResetName() { m.name = nil } // AddSubjectDigestIDs adds the "subject_digests" edge to the SubjectDigest entity by ids. func (m *SubjectMutation) AddSubjectDigestIDs(ids ...uuid.UUID) { if m.subject_digests == nil { m.subject_digests = make(map[uuid.UUID]struct{}) } for i := range ids { m.subject_digests[ids[i]] = struct{}{} } } // ClearSubjectDigests clears the "subject_digests" edge to the SubjectDigest entity. func (m *SubjectMutation) ClearSubjectDigests() { m.clearedsubject_digests = true } // SubjectDigestsCleared reports if the "subject_digests" edge to the SubjectDigest entity was cleared. func (m *SubjectMutation) SubjectDigestsCleared() bool { return m.clearedsubject_digests } // RemoveSubjectDigestIDs removes the "subject_digests" edge to the SubjectDigest entity by IDs. func (m *SubjectMutation) RemoveSubjectDigestIDs(ids ...uuid.UUID) { if m.removedsubject_digests == nil { m.removedsubject_digests = make(map[uuid.UUID]struct{}) } for i := range ids { delete(m.subject_digests, ids[i]) m.removedsubject_digests[ids[i]] = struct{}{} } } // RemovedSubjectDigests returns the removed IDs of the "subject_digests" edge to the SubjectDigest entity. func (m *SubjectMutation) RemovedSubjectDigestsIDs() (ids []uuid.UUID) { for id := range m.removedsubject_digests { ids = append(ids, id) } return } // SubjectDigestsIDs returns the "subject_digests" edge IDs in the mutation. func (m *SubjectMutation) SubjectDigestsIDs() (ids []uuid.UUID) { for id := range m.subject_digests { ids = append(ids, id) } return } // ResetSubjectDigests resets all changes to the "subject_digests" edge. func (m *SubjectMutation) ResetSubjectDigests() { m.subject_digests = nil m.clearedsubject_digests = false m.removedsubject_digests = nil } // SetStatementID sets the "statement" edge to the Statement entity by id. func (m *SubjectMutation) SetStatementID(id uuid.UUID) { m.statement = &id } // ClearStatement clears the "statement" edge to the Statement entity. func (m *SubjectMutation) ClearStatement() { m.clearedstatement = true } // StatementCleared reports if the "statement" edge to the Statement entity was cleared. func (m *SubjectMutation) StatementCleared() bool { return m.clearedstatement } // StatementID returns the "statement" edge ID in the mutation. func (m *SubjectMutation) StatementID() (id uuid.UUID, exists bool) { if m.statement != nil { return *m.statement, true } return } // StatementIDs returns the "statement" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // StatementID instead. It exists only for internal usage by the builders. func (m *SubjectMutation) StatementIDs() (ids []uuid.UUID) { if id := m.statement; id != nil { ids = append(ids, *id) } return } // ResetStatement resets all changes to the "statement" edge. func (m *SubjectMutation) ResetStatement() { m.statement = nil m.clearedstatement = false } // Where appends a list predicates to the SubjectMutation builder. func (m *SubjectMutation) Where(ps ...predicate.Subject) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the SubjectMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *SubjectMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Subject, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *SubjectMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *SubjectMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Subject). func (m *SubjectMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SubjectMutation) Fields() []string { fields := make([]string, 0, 2) if m.created_at != nil { fields = append(fields, subject.FieldCreatedAt) } if m.name != nil { fields = append(fields, subject.FieldName) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *SubjectMutation) Field(name string) (ent.Value, bool) { switch name { case subject.FieldCreatedAt: return m.CreatedAt() case subject.FieldName: return m.Name() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *SubjectMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case subject.FieldCreatedAt: return m.OldCreatedAt(ctx) case subject.FieldName: return m.OldName(ctx) } return nil, fmt.Errorf("unknown Subject field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *SubjectMutation) SetField(name string, value ent.Value) error { switch name { case subject.FieldCreatedAt: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetCreatedAt(v) return nil case subject.FieldName: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetName(v) return nil } return fmt.Errorf("unknown Subject field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SubjectMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *SubjectMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *SubjectMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Subject numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *SubjectMutation) ClearedFields() []string { var fields []string if m.FieldCleared(subject.FieldCreatedAt) { fields = append(fields, subject.FieldCreatedAt) } return fields } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *SubjectMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *SubjectMutation) ClearField(name string) error { switch name { case subject.FieldCreatedAt: m.ClearCreatedAt() return nil } return fmt.Errorf("unknown Subject nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *SubjectMutation) ResetField(name string) error { switch name { case subject.FieldCreatedAt: m.ResetCreatedAt() return nil case subject.FieldName: m.ResetName() return nil } return fmt.Errorf("unknown Subject field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *SubjectMutation) AddedEdges() []string { edges := make([]string, 0, 2) if m.subject_digests != nil { edges = append(edges, subject.EdgeSubjectDigests) } if m.statement != nil { edges = append(edges, subject.EdgeStatement) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *SubjectMutation) AddedIDs(name string) []ent.Value { switch name { case subject.EdgeSubjectDigests: ids := make([]ent.Value, 0, len(m.subject_digests)) for id := range m.subject_digests { ids = append(ids, id) } return ids case subject.EdgeStatement: if id := m.statement; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SubjectMutation) RemovedEdges() []string { edges := make([]string, 0, 2) if m.removedsubject_digests != nil { edges = append(edges, subject.EdgeSubjectDigests) } return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *SubjectMutation) RemovedIDs(name string) []ent.Value { switch name { case subject.EdgeSubjectDigests: ids := make([]ent.Value, 0, len(m.removedsubject_digests)) for id := range m.removedsubject_digests { ids = append(ids, id) } return ids } return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SubjectMutation) ClearedEdges() []string { edges := make([]string, 0, 2) if m.clearedsubject_digests { edges = append(edges, subject.EdgeSubjectDigests) } if m.clearedstatement { edges = append(edges, subject.EdgeStatement) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *SubjectMutation) EdgeCleared(name string) bool { switch name { case subject.EdgeSubjectDigests: return m.clearedsubject_digests case subject.EdgeStatement: return m.clearedstatement } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *SubjectMutation) ClearEdge(name string) error { switch name { case subject.EdgeStatement: m.ClearStatement() return nil } return fmt.Errorf("unknown Subject unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *SubjectMutation) ResetEdge(name string) error { switch name { case subject.EdgeSubjectDigests: m.ResetSubjectDigests() return nil case subject.EdgeStatement: m.ResetStatement() return nil } return fmt.Errorf("unknown Subject edge %s", name) } // SubjectDigestMutation represents an operation that mutates the SubjectDigest nodes in the graph. type SubjectDigestMutation struct { config op Op typ string id *uuid.UUID algorithm *string value *string clearedFields map[string]struct{} subject *uuid.UUID clearedsubject bool done bool oldValue func(context.Context) (*SubjectDigest, error) predicates []predicate.SubjectDigest } var _ ent.Mutation = (*SubjectDigestMutation)(nil) // subjectdigestOption allows management of the mutation configuration using functional options. type subjectdigestOption func(*SubjectDigestMutation) // newSubjectDigestMutation creates new mutation for the SubjectDigest entity. func newSubjectDigestMutation(c config, op Op, opts ...subjectdigestOption) *SubjectDigestMutation { m := &SubjectDigestMutation{ config: c, op: op, typ: TypeSubjectDigest, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withSubjectDigestID sets the ID field of the mutation. func withSubjectDigestID(id uuid.UUID) subjectdigestOption { return func(m *SubjectDigestMutation) { var ( err error once sync.Once value *SubjectDigest ) m.oldValue = func(ctx context.Context) (*SubjectDigest, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().SubjectDigest.Get(ctx, id) } }) return value, err } m.id = &id } } // withSubjectDigest sets the old SubjectDigest of the mutation. func withSubjectDigest(node *SubjectDigest) subjectdigestOption { return func(m *SubjectDigestMutation) { m.oldValue = func(context.Context) (*SubjectDigest, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m SubjectDigestMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m SubjectDigestMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of SubjectDigest entities. func (m *SubjectDigestMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *SubjectDigestMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *SubjectDigestMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().SubjectDigest.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetAlgorithm sets the "algorithm" field. func (m *SubjectDigestMutation) SetAlgorithm(s string) { m.algorithm = &s } // Algorithm returns the value of the "algorithm" field in the mutation. func (m *SubjectDigestMutation) Algorithm() (r string, exists bool) { v := m.algorithm if v == nil { return } return *v, true } // OldAlgorithm returns the old "algorithm" field's value of the SubjectDigest entity. // If the SubjectDigest object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SubjectDigestMutation) OldAlgorithm(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldAlgorithm is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldAlgorithm requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldAlgorithm: %w", err) } return oldValue.Algorithm, nil } // ResetAlgorithm resets all changes to the "algorithm" field. func (m *SubjectDigestMutation) ResetAlgorithm() { m.algorithm = nil } // SetValue sets the "value" field. func (m *SubjectDigestMutation) SetValue(s string) { m.value = &s } // Value returns the value of the "value" field in the mutation. func (m *SubjectDigestMutation) Value() (r string, exists bool) { v := m.value if v == nil { return } return *v, true } // OldValue returns the old "value" field's value of the SubjectDigest entity. // If the SubjectDigest object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *SubjectDigestMutation) OldValue(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldValue is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldValue requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldValue: %w", err) } return oldValue.Value, nil } // ResetValue resets all changes to the "value" field. func (m *SubjectDigestMutation) ResetValue() { m.value = nil } // SetSubjectID sets the "subject" edge to the Subject entity by id. func (m *SubjectDigestMutation) SetSubjectID(id uuid.UUID) { m.subject = &id } // ClearSubject clears the "subject" edge to the Subject entity. func (m *SubjectDigestMutation) ClearSubject() { m.clearedsubject = true } // SubjectCleared reports if the "subject" edge to the Subject entity was cleared. func (m *SubjectDigestMutation) SubjectCleared() bool { return m.clearedsubject } // SubjectID returns the "subject" edge ID in the mutation. func (m *SubjectDigestMutation) SubjectID() (id uuid.UUID, exists bool) { if m.subject != nil { return *m.subject, true } return } // SubjectIDs returns the "subject" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // SubjectID instead. It exists only for internal usage by the builders. func (m *SubjectDigestMutation) SubjectIDs() (ids []uuid.UUID) { if id := m.subject; id != nil { ids = append(ids, *id) } return } // ResetSubject resets all changes to the "subject" edge. func (m *SubjectDigestMutation) ResetSubject() { m.subject = nil m.clearedsubject = false } // Where appends a list predicates to the SubjectDigestMutation builder. func (m *SubjectDigestMutation) Where(ps ...predicate.SubjectDigest) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the SubjectDigestMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *SubjectDigestMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.SubjectDigest, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *SubjectDigestMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *SubjectDigestMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (SubjectDigest). func (m *SubjectDigestMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *SubjectDigestMutation) Fields() []string { fields := make([]string, 0, 2) if m.algorithm != nil { fields = append(fields, subjectdigest.FieldAlgorithm) } if m.value != nil { fields = append(fields, subjectdigest.FieldValue) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *SubjectDigestMutation) Field(name string) (ent.Value, bool) { switch name { case subjectdigest.FieldAlgorithm: return m.Algorithm() case subjectdigest.FieldValue: return m.Value() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *SubjectDigestMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case subjectdigest.FieldAlgorithm: return m.OldAlgorithm(ctx) case subjectdigest.FieldValue: return m.OldValue(ctx) } return nil, fmt.Errorf("unknown SubjectDigest field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *SubjectDigestMutation) SetField(name string, value ent.Value) error { switch name { case subjectdigest.FieldAlgorithm: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetAlgorithm(v) return nil case subjectdigest.FieldValue: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetValue(v) return nil } return fmt.Errorf("unknown SubjectDigest field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *SubjectDigestMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *SubjectDigestMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *SubjectDigestMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown SubjectDigest numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *SubjectDigestMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *SubjectDigestMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *SubjectDigestMutation) ClearField(name string) error { return fmt.Errorf("unknown SubjectDigest nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *SubjectDigestMutation) ResetField(name string) error { switch name { case subjectdigest.FieldAlgorithm: m.ResetAlgorithm() return nil case subjectdigest.FieldValue: m.ResetValue() return nil } return fmt.Errorf("unknown SubjectDigest field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *SubjectDigestMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.subject != nil { edges = append(edges, subjectdigest.EdgeSubject) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *SubjectDigestMutation) AddedIDs(name string) []ent.Value { switch name { case subjectdigest.EdgeSubject: if id := m.subject; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *SubjectDigestMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *SubjectDigestMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *SubjectDigestMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedsubject { edges = append(edges, subjectdigest.EdgeSubject) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *SubjectDigestMutation) EdgeCleared(name string) bool { switch name { case subjectdigest.EdgeSubject: return m.clearedsubject } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *SubjectDigestMutation) ClearEdge(name string) error { switch name { case subjectdigest.EdgeSubject: m.ClearSubject() return nil } return fmt.Errorf("unknown SubjectDigest unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *SubjectDigestMutation) ResetEdge(name string) error { switch name { case subjectdigest.EdgeSubject: m.ResetSubject() return nil } return fmt.Errorf("unknown SubjectDigest edge %s", name) } // TimestampMutation represents an operation that mutates the Timestamp nodes in the graph. type TimestampMutation struct { config op Op typ string id *uuid.UUID _type *string timestamp *time.Time clearedFields map[string]struct{} signature *uuid.UUID clearedsignature bool done bool oldValue func(context.Context) (*Timestamp, error) predicates []predicate.Timestamp } var _ ent.Mutation = (*TimestampMutation)(nil) // timestampOption allows management of the mutation configuration using functional options. type timestampOption func(*TimestampMutation) // newTimestampMutation creates new mutation for the Timestamp entity. func newTimestampMutation(c config, op Op, opts ...timestampOption) *TimestampMutation { m := &TimestampMutation{ config: c, op: op, typ: TypeTimestamp, clearedFields: make(map[string]struct{}), } for _, opt := range opts { opt(m) } return m } // withTimestampID sets the ID field of the mutation. func withTimestampID(id uuid.UUID) timestampOption { return func(m *TimestampMutation) { var ( err error once sync.Once value *Timestamp ) m.oldValue = func(ctx context.Context) (*Timestamp, error) { once.Do(func() { if m.done { err = errors.New("querying old values post mutation is not allowed") } else { value, err = m.Client().Timestamp.Get(ctx, id) } }) return value, err } m.id = &id } } // withTimestamp sets the old Timestamp of the mutation. func withTimestamp(node *Timestamp) timestampOption { return func(m *TimestampMutation) { m.oldValue = func(context.Context) (*Timestamp, error) { return node, nil } m.id = &node.ID } } // Client returns a new `ent.Client` from the mutation. If the mutation was // executed in a transaction (ent.Tx), a transactional client is returned. func (m TimestampMutation) Client() *Client { client := &Client{config: m.config} client.init() return client } // Tx returns an `ent.Tx` for mutations that were executed in transactions; // it returns an error otherwise. func (m TimestampMutation) Tx() (*Tx, error) { if _, ok := m.driver.(*txDriver); !ok { return nil, errors.New("ent: mutation is not running in a transaction") } tx := &Tx{config: m.config} tx.init() return tx, nil } // SetID sets the value of the id field. Note that this // operation is only accepted on creation of Timestamp entities. func (m *TimestampMutation) SetID(id uuid.UUID) { m.id = &id } // ID returns the ID value in the mutation. Note that the ID is only available // if it was provided to the builder or after it was returned from the database. func (m *TimestampMutation) ID() (id uuid.UUID, exists bool) { if m.id == nil { return } return *m.id, true } // IDs queries the database and returns the entity ids that match the mutation's predicate. // That means, if the mutation is applied within a transaction with an isolation level such // as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated // or updated by the mutation. func (m *TimestampMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { switch { case m.op.Is(OpUpdateOne | OpDeleteOne): id, exists := m.ID() if exists { return []uuid.UUID{id}, nil } fallthrough case m.op.Is(OpUpdate | OpDelete): return m.Client().Timestamp.Query().Where(m.predicates...).IDs(ctx) default: return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) } } // SetType sets the "type" field. func (m *TimestampMutation) SetType(s string) { m._type = &s } // GetType returns the value of the "type" field in the mutation. func (m *TimestampMutation) GetType() (r string, exists bool) { v := m._type if v == nil { return } return *v, true } // OldType returns the old "type" field's value of the Timestamp entity. // If the Timestamp object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TimestampMutation) OldType(ctx context.Context) (v string, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldType is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldType requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldType: %w", err) } return oldValue.Type, nil } // ResetType resets all changes to the "type" field. func (m *TimestampMutation) ResetType() { m._type = nil } // SetTimestamp sets the "timestamp" field. func (m *TimestampMutation) SetTimestamp(t time.Time) { m.timestamp = &t } // Timestamp returns the value of the "timestamp" field in the mutation. func (m *TimestampMutation) Timestamp() (r time.Time, exists bool) { v := m.timestamp if v == nil { return } return *v, true } // OldTimestamp returns the old "timestamp" field's value of the Timestamp entity. // If the Timestamp object wasn't provided to the builder, the object is fetched from the database. // An error is returned if the mutation operation is not UpdateOne, or the database query fails. func (m *TimestampMutation) OldTimestamp(ctx context.Context) (v time.Time, err error) { if !m.op.Is(OpUpdateOne) { return v, errors.New("OldTimestamp is only allowed on UpdateOne operations") } if m.id == nil || m.oldValue == nil { return v, errors.New("OldTimestamp requires an ID field in the mutation") } oldValue, err := m.oldValue(ctx) if err != nil { return v, fmt.Errorf("querying old value for OldTimestamp: %w", err) } return oldValue.Timestamp, nil } // ResetTimestamp resets all changes to the "timestamp" field. func (m *TimestampMutation) ResetTimestamp() { m.timestamp = nil } // SetSignatureID sets the "signature" edge to the Signature entity by id. func (m *TimestampMutation) SetSignatureID(id uuid.UUID) { m.signature = &id } // ClearSignature clears the "signature" edge to the Signature entity. func (m *TimestampMutation) ClearSignature() { m.clearedsignature = true } // SignatureCleared reports if the "signature" edge to the Signature entity was cleared. func (m *TimestampMutation) SignatureCleared() bool { return m.clearedsignature } // SignatureID returns the "signature" edge ID in the mutation. func (m *TimestampMutation) SignatureID() (id uuid.UUID, exists bool) { if m.signature != nil { return *m.signature, true } return } // SignatureIDs returns the "signature" edge IDs in the mutation. // Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use // SignatureID instead. It exists only for internal usage by the builders. func (m *TimestampMutation) SignatureIDs() (ids []uuid.UUID) { if id := m.signature; id != nil { ids = append(ids, *id) } return } // ResetSignature resets all changes to the "signature" edge. func (m *TimestampMutation) ResetSignature() { m.signature = nil m.clearedsignature = false } // Where appends a list predicates to the TimestampMutation builder. func (m *TimestampMutation) Where(ps ...predicate.Timestamp) { m.predicates = append(m.predicates, ps...) } // WhereP appends storage-level predicates to the TimestampMutation builder. Using this method, // users can use type-assertion to append predicates that do not depend on any generated package. func (m *TimestampMutation) WhereP(ps ...func(*sql.Selector)) { p := make([]predicate.Timestamp, len(ps)) for i := range ps { p[i] = ps[i] } m.Where(p...) } // Op returns the operation name. func (m *TimestampMutation) Op() Op { return m.op } // SetOp allows setting the mutation operation. func (m *TimestampMutation) SetOp(op Op) { m.op = op } // Type returns the node type of this mutation (Timestamp). func (m *TimestampMutation) Type() string { return m.typ } // Fields returns all fields that were changed during this mutation. Note that in // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *TimestampMutation) Fields() []string { fields := make([]string, 0, 2) if m._type != nil { fields = append(fields, timestamp.FieldType) } if m.timestamp != nil { fields = append(fields, timestamp.FieldTimestamp) } return fields } // Field returns the value of a field with the given name. The second boolean // return value indicates that this field was not set, or was not defined in the // schema. func (m *TimestampMutation) Field(name string) (ent.Value, bool) { switch name { case timestamp.FieldType: return m.GetType() case timestamp.FieldTimestamp: return m.Timestamp() } return nil, false } // OldField returns the old value of the field from the database. An error is // returned if the mutation operation is not UpdateOne, or the query to the // database failed. func (m *TimestampMutation) OldField(ctx context.Context, name string) (ent.Value, error) { switch name { case timestamp.FieldType: return m.OldType(ctx) case timestamp.FieldTimestamp: return m.OldTimestamp(ctx) } return nil, fmt.Errorf("unknown Timestamp field %s", name) } // SetField sets the value of a field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *TimestampMutation) SetField(name string, value ent.Value) error { switch name { case timestamp.FieldType: v, ok := value.(string) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetType(v) return nil case timestamp.FieldTimestamp: v, ok := value.(time.Time) if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } m.SetTimestamp(v) return nil } return fmt.Errorf("unknown Timestamp field %s", name) } // AddedFields returns all numeric fields that were incremented/decremented during // this mutation. func (m *TimestampMutation) AddedFields() []string { return nil } // AddedField returns the numeric value that was incremented/decremented on a field // with the given name. The second boolean return value indicates that this field // was not set, or was not defined in the schema. func (m *TimestampMutation) AddedField(name string) (ent.Value, bool) { return nil, false } // AddField adds the value to the field with the given name. It returns an error if // the field is not defined in the schema, or if the type mismatched the field // type. func (m *TimestampMutation) AddField(name string, value ent.Value) error { switch name { } return fmt.Errorf("unknown Timestamp numeric field %s", name) } // ClearedFields returns all nullable fields that were cleared during this // mutation. func (m *TimestampMutation) ClearedFields() []string { return nil } // FieldCleared returns a boolean indicating if a field with the given name was // cleared in this mutation. func (m *TimestampMutation) FieldCleared(name string) bool { _, ok := m.clearedFields[name] return ok } // ClearField clears the value of the field with the given name. It returns an // error if the field is not defined in the schema. func (m *TimestampMutation) ClearField(name string) error { return fmt.Errorf("unknown Timestamp nullable field %s", name) } // ResetField resets all changes in the mutation for the field with the given name. // It returns an error if the field is not defined in the schema. func (m *TimestampMutation) ResetField(name string) error { switch name { case timestamp.FieldType: m.ResetType() return nil case timestamp.FieldTimestamp: m.ResetTimestamp() return nil } return fmt.Errorf("unknown Timestamp field %s", name) } // AddedEdges returns all edge names that were set/added in this mutation. func (m *TimestampMutation) AddedEdges() []string { edges := make([]string, 0, 1) if m.signature != nil { edges = append(edges, timestamp.EdgeSignature) } return edges } // AddedIDs returns all IDs (to other nodes) that were added for the given edge // name in this mutation. func (m *TimestampMutation) AddedIDs(name string) []ent.Value { switch name { case timestamp.EdgeSignature: if id := m.signature; id != nil { return []ent.Value{*id} } } return nil } // RemovedEdges returns all edge names that were removed in this mutation. func (m *TimestampMutation) RemovedEdges() []string { edges := make([]string, 0, 1) return edges } // RemovedIDs returns all IDs (to other nodes) that were removed for the edge with // the given name in this mutation. func (m *TimestampMutation) RemovedIDs(name string) []ent.Value { return nil } // ClearedEdges returns all edge names that were cleared in this mutation. func (m *TimestampMutation) ClearedEdges() []string { edges := make([]string, 0, 1) if m.clearedsignature { edges = append(edges, timestamp.EdgeSignature) } return edges } // EdgeCleared returns a boolean which indicates if the edge with the given name // was cleared in this mutation. func (m *TimestampMutation) EdgeCleared(name string) bool { switch name { case timestamp.EdgeSignature: return m.clearedsignature } return false } // ClearEdge clears the value of the edge with the given name. It returns an error // if that edge is not defined in the schema. func (m *TimestampMutation) ClearEdge(name string) error { switch name { case timestamp.EdgeSignature: m.ClearSignature() return nil } return fmt.Errorf("unknown Timestamp unique edge %s", name) } // ResetEdge resets all changes to the edge with the given name in this mutation. // It returns an error if the edge is not defined in the schema. func (m *TimestampMutation) ResetEdge(name string) error { switch name { case timestamp.EdgeSignature: m.ResetSignature() return nil } return fmt.Errorf("unknown Timestamp edge %s", name) }