patch

package
v1.0.0-beta.232 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

README

Subscription patches

Patches are typed, ordered transformations of a SubscriptionSpec. They let subscription workflows express a change to desired state before the core service materializes that state.

Patches do not persist subscription rows, schedule entitlements, or create billing artifacts.

Patch contract

Every patch provides:

  • an operation such as add, remove, stretch, or unschedule
  • a SpecPath identifying the affected phase, item key, or item version
  • validation of its own input
  • an ApplyTo transformation over the spec

Paths express logical subscription identity:

/phases/{phaseKey}
/phases/{phaseKey}/items/{itemKey}
/phases/{phaseKey}/items/{itemKey}/idx/{version}

Use an item-version path only when the operation addresses that exact version. An operation that selects or mutates the relevant version itself belongs at the item path.

Effective time and ordering

ApplyContext.CurrentTime is the command's resolved effective time, not necessarily wall-clock time. Patch rules use it to protect past phases and items and to decide which item version is active.

Patches are applied in order. A later patch sees the spec produced by earlier ones, so valid workflows may deliberately remove an item before adding its replacement. The complete spec is validated after application.

Adding an item to the current phase closes the active version of the same item key and appends a new version. Its relative start is derived from the effective time when the patch does not provide one. Future-phase additions must not silently replace an existing item.

Phase stretch and removal can shift later phase offsets. They must preserve phase ordering and cannot erase a phase by collapsing its duration.

Error meaning

  • validation errors mean the patch or resulting spec is structurally invalid
  • forbidden errors mean the requested edit would change protected historical state
  • conflict errors mean the patch is individually meaningful but incompatible with the surrounding spec or another requested change

The workflow layer maps these errors for callers and passes the resulting complete spec to the subscription service.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PatchAddItem

type PatchAddItem struct {
	PhaseKey    string
	ItemKey     string
	CreateInput subscription.SubscriptionItemSpec
}

func (PatchAddItem) ApplyTo

func (PatchAddItem) FieldDescriptor

func (a PatchAddItem) FieldDescriptor() *models.FieldDescriptor

func (PatchAddItem) Op

func (PatchAddItem) Path

func (PatchAddItem) Validate

func (a PatchAddItem) Validate() error

func (PatchAddItem) Value

func (PatchAddItem) ValueAsAny

func (a PatchAddItem) ValueAsAny() any

type PatchAddPhase

type PatchAddPhase struct {
	PhaseKey    string
	CreateInput subscription.CreateSubscriptionPhaseInput
}

func (PatchAddPhase) ApplyTo

func (PatchAddPhase) Op

func (PatchAddPhase) Path

func (PatchAddPhase) Validate

func (a PatchAddPhase) Validate() error

func (PatchAddPhase) Value

func (PatchAddPhase) ValueAsAny

func (a PatchAddPhase) ValueAsAny() any

type PatchRemoveItem

type PatchRemoveItem struct {
	PhaseKey string
	ItemKey  string
}

func (PatchRemoveItem) ApplyTo

RemoveItem removes the last version for the provided key

func (PatchRemoveItem) Op

func (PatchRemoveItem) Path

func (PatchRemoveItem) Validate

func (r PatchRemoveItem) Validate() error

type PatchRemovePhase

type PatchRemovePhase struct {
	PhaseKey    string
	RemoveInput subscription.RemoveSubscriptionPhaseInput
}

func (PatchRemovePhase) ApplyTo

func (PatchRemovePhase) Op

func (PatchRemovePhase) Path

func (PatchRemovePhase) Validate

func (r PatchRemovePhase) Validate() error

func (PatchRemovePhase) Value

func (PatchRemovePhase) ValueAsAny

func (r PatchRemovePhase) ValueAsAny() any

type PatchStretchPhase

type PatchStretchPhase struct {
	PhaseKey string
	// Signed duration
	Duration datetime.ISODuration
}

func (PatchStretchPhase) ApplyTo

func (PatchStretchPhase) Op

func (PatchStretchPhase) Path

func (PatchStretchPhase) Validate

func (p PatchStretchPhase) Validate() error

func (PatchStretchPhase) Value

func (PatchStretchPhase) ValueAsAny

func (p PatchStretchPhase) ValueAsAny() any

type PatchUnscheduleEdit

type PatchUnscheduleEdit struct{}

func (PatchUnscheduleEdit) ApplyTo

"Unscheduling an edit" is a concept that might intuitively makes sense for clients: 1. Making some edit to a subscription 2. You want to do another edit 3. Your edit discards the previous edit

However, this is not really a behavior that makes sense from a server perspective. The compromise we make is that, for most cases, when a client wants to unschedule an edit, all they really want to do is get rid of any future changes to the subscription.

As editing future phases doesn't create multiple versions of the items (see AddItem and RemoveItem), we only tackle editing the current phase.

UnscheduleEdit simply removes all scheduled versions of the items in the current phase.

func (PatchUnscheduleEdit) Op

func (PatchUnscheduleEdit) Path

func (PatchUnscheduleEdit) Validate

func (p PatchUnscheduleEdit) Validate() error

Jump to

Keyboard shortcuts

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