hook

package
v1.12.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FixedError

func FixedError(err error) ent.Hook

FixedError is a hook returning a fixed error.

func If

func If(hk ent.Hook, cond Condition) ent.Hook

If executes the given hook under condition.

hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))

func On

func On(hk ent.Hook, op ent.Op) ent.Hook

On executes the given hook only for the given operation.

hook.On(Log, ent.Delete|ent.Create)

func Reject

func Reject(op ent.Op) ent.Hook

Reject returns a hook that rejects all operations that match op.

func (T) Hooks() []ent.Hook {
	return []ent.Hook{
		Reject(ent.Delete|ent.Update),
	}
}

func Unless

func Unless(hk ent.Hook, op ent.Op) ent.Hook

Unless skips the given hook only for the given operation.

hook.Unless(Log, ent.Update|ent.UpdateOne)

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain acts as a list of hooks and is effectively immutable. Once created, it will always hold the same set of hooks in the same order.

func NewChain

func NewChain(hooks ...ent.Hook) Chain

NewChain creates a new chain of hooks.

func (Chain) Append

func (c Chain) Append(hooks ...ent.Hook) Chain

Append extends a chain, adding the specified hook as the last ones in the mutation flow.

func (Chain) Extend

func (c Chain) Extend(chain Chain) Chain

Extend extends a chain, adding the specified chain as the last ones in the mutation flow.

func (Chain) Hook

func (c Chain) Hook() ent.Hook

Hook chains the list of hooks and returns the final hook.

type CodeSourceFileFunc

type CodeSourceFileFunc func(context.Context, *ent.CodeSourceFileMutation) (ent.Value, error)

The CodeSourceFileFunc type is an adapter to allow the use of ordinary function as CodeSourceFile mutator.

func (CodeSourceFileFunc) Mutate

Mutate calls f(ctx, m).

type Condition

type Condition func(context.Context, ent.Mutation) bool

Condition is a hook condition function.

func And

func And(first, second Condition, rest ...Condition) Condition

And groups conditions with the AND operator.

func HasAddedFields

func HasAddedFields(field string, fields ...string) Condition

HasAddedFields is a condition validating `.AddedField` on fields.

func HasClearedFields

func HasClearedFields(field string, fields ...string) Condition

HasClearedFields is a condition validating `.FieldCleared` on fields.

func HasFields

func HasFields(field string, fields ...string) Condition

HasFields is a condition validating `.Field` on fields.

func HasOp

func HasOp(op ent.Op) Condition

HasOp is a condition testing mutation operation.

func Not

func Not(cond Condition) Condition

Not negates a given condition.

func Or

func Or(first, second Condition, rest ...Condition) Condition

Or groups conditions with the OR operator.

type DepsUsageEvidenceFunc

type DepsUsageEvidenceFunc func(context.Context, *ent.DepsUsageEvidenceMutation) (ent.Value, error)

The DepsUsageEvidenceFunc type is an adapter to allow the use of ordinary function as DepsUsageEvidence mutator.

func (DepsUsageEvidenceFunc) Mutate

Mutate calls f(ctx, m).

type ReportDependencyFunc added in v1.12.0

type ReportDependencyFunc func(context.Context, *ent.ReportDependencyMutation) (ent.Value, error)

The ReportDependencyFunc type is an adapter to allow the use of ordinary function as ReportDependency mutator.

func (ReportDependencyFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportDependencyGraphFunc added in v1.12.0

type ReportDependencyGraphFunc func(context.Context, *ent.ReportDependencyGraphMutation) (ent.Value, error)

The ReportDependencyGraphFunc type is an adapter to allow the use of ordinary function as ReportDependencyGraph mutator.

func (ReportDependencyGraphFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportLicenseFunc added in v1.12.0

type ReportLicenseFunc func(context.Context, *ent.ReportLicenseMutation) (ent.Value, error)

The ReportLicenseFunc type is an adapter to allow the use of ordinary function as ReportLicense mutator.

func (ReportLicenseFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportMalwareFunc added in v1.12.0

type ReportMalwareFunc func(context.Context, *ent.ReportMalwareMutation) (ent.Value, error)

The ReportMalwareFunc type is an adapter to allow the use of ordinary function as ReportMalware mutator.

func (ReportMalwareFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportPackageFunc added in v1.12.0

type ReportPackageFunc func(context.Context, *ent.ReportPackageMutation) (ent.Value, error)

The ReportPackageFunc type is an adapter to allow the use of ordinary function as ReportPackage mutator.

func (ReportPackageFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportPackageManifestFunc added in v1.12.0

type ReportPackageManifestFunc func(context.Context, *ent.ReportPackageManifestMutation) (ent.Value, error)

The ReportPackageManifestFunc type is an adapter to allow the use of ordinary function as ReportPackageManifest mutator.

func (ReportPackageManifestFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportProjectFunc added in v1.12.0

type ReportProjectFunc func(context.Context, *ent.ReportProjectMutation) (ent.Value, error)

The ReportProjectFunc type is an adapter to allow the use of ordinary function as ReportProject mutator.

func (ReportProjectFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportScorecardCheckFunc added in v1.12.0

type ReportScorecardCheckFunc func(context.Context, *ent.ReportScorecardCheckMutation) (ent.Value, error)

The ReportScorecardCheckFunc type is an adapter to allow the use of ordinary function as ReportScorecardCheck mutator.

func (ReportScorecardCheckFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportScorecardFunc added in v1.12.0

type ReportScorecardFunc func(context.Context, *ent.ReportScorecardMutation) (ent.Value, error)

The ReportScorecardFunc type is an adapter to allow the use of ordinary function as ReportScorecard mutator.

func (ReportScorecardFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportSlsaProvenanceFunc added in v1.12.0

type ReportSlsaProvenanceFunc func(context.Context, *ent.ReportSlsaProvenanceMutation) (ent.Value, error)

The ReportSlsaProvenanceFunc type is an adapter to allow the use of ordinary function as ReportSlsaProvenance mutator.

func (ReportSlsaProvenanceFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

type ReportVulnerabilityFunc added in v1.12.0

type ReportVulnerabilityFunc func(context.Context, *ent.ReportVulnerabilityMutation) (ent.Value, error)

The ReportVulnerabilityFunc type is an adapter to allow the use of ordinary function as ReportVulnerability mutator.

func (ReportVulnerabilityFunc) Mutate added in v1.12.0

Mutate calls f(ctx, m).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL