batch

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package batch owns the execution-neutral, bounded exact-set contract for update-many and delete-many. It deliberately separates the sentinel capture query from every write: an executor cannot obtain write statements until it has proved that the complete authorized set fits the configured limit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorizationColumn

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

func (AuthorizationColumn) Alias

func (column AuthorizationColumn) Alias() string

func (AuthorizationColumn) FieldID

func (column AuthorizationColumn) FieldID() policyir.FieldID

type AuthorizedRow

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

func NewAuthorizedRow

func NewAuthorizedRow(before mutationdecode.Row, grants ...FieldGrant) (AuthorizedRow, error)

func (AuthorizedRow) Before

func (row AuthorizedRow) Before() mutationdecode.Row

func (AuthorizedRow) Grants

func (row AuthorizedRow) Grants() []FieldGrant

type Binding

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

Binding is one immutable positional argument. Batch programs intentionally contain static values only; captured identity values are encoded into the prepared program and never accepted from a second caller-controlled source.

func (Binding) Value

func (binding Binding) Value() any

type Cardinality

type Cardinality uint8
const (
	AtMostSentinelRows Cardinality = iota + 1
	ExactlyCapturedRows
)

type Error

type Error struct {
	Code   ErrorCode
	Model  policyir.ModelID
	Field  policyir.FieldID
	Detail string
	Cause  error
}

func (*Error) Error

func (failure *Error) Error() string

func (*Error) Unwrap

func (failure *Error) Unwrap() error

type ErrorCode

type ErrorCode string
const (
	CodeInput     ErrorCode = "P4_BATCH_INPUT"
	CodeSchema    ErrorCode = "P4_BATCH_SCHEMA"
	CodeProvider  ErrorCode = "P4_BATCH_PROVIDER"
	CodeLimit     ErrorCode = "P4_BATCH_LIMIT_EXCEEDED"
	CodeSet       ErrorCode = "P4_BATCH_SET_MISMATCH"
	CodeIdentity  ErrorCode = "P4_BATCH_IDENTITY_CHANGE"
	CodeForbidden ErrorCode = "P4_BATCH_FORBIDDEN"
)

type FactSpec

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

FactSpec is the exact runtime seam for one ordered fact. Event and causation IDs remain runtime-owned; the batch kernel fixes action, images, and ordinal.

func (FactSpec) Action

func (fact FactSpec) Action() mutationir.FactAction

func (FactSpec) After

func (fact FactSpec) After() (mutationdecode.Row, bool)

func (FactSpec) Before

func (fact FactSpec) Before() mutationdecode.Row

func (FactSpec) Ordinal

func (fact FactSpec) Ordinal() uint32

type FieldGrant

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

FieldGrant is one SQL-evaluated authorization decision from the locked pre-image. Callers cannot substitute a condition or a post-write value here; an executor must decode the AuthorizationColumns emitted by the prepared AuthorizePreImage statement.

func NewFieldGrant

func NewFieldGrant(field policyir.FieldID, granted bool) (FieldGrant, error)

func (FieldGrant) FieldID

func (grant FieldGrant) FieldID() policyir.FieldID

func (FieldGrant) Granted

func (grant FieldGrant) Granted() bool

type Prepared

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

func (Prepared) Count

func (prepared Prepared) Count() int64

func (Prepared) FactRequirement

func (prepared Prepared) FactRequirement() mutationir.FactRequirement

func (Prepared) Operation

func (prepared Prepared) Operation() mutationir.Operation

func (Prepared) Statements

func (prepared Prepared) Statements() []Statement

func (Prepared) Verify

func (prepared Prepared) Verify(applied, after []mutationdecode.Row, factOrdinalBase uint32) (Verification, error)

Verify consumes provider-decoded complete images only after every prepared statement met its exact cardinality. It verifies set equality again by primary identity, reorders results to capture order, computes truthful diffs, and allocates one fact specification per captured row.

func (Prepared) VerifyAuthorized

func (prepared Prepared) VerifyAuthorized(authorized []AuthorizedRow, applied, after []mutationdecode.Row, factOrdinalBase uint32) (Verification, error)

VerifyAuthorized consumes the SQL-evaluated grants captured from every AuthorizePreImage statement. The locked rows are the before side of the exact logical diff. A false or missing grant matters only when that exact diff says the corresponding caller-authored field actually changed.

type Program

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

Program contains only the capture phase. PrepareCaptured is the sole bridge to write SQL and enforces the +1 sentinel before producing any statement.

func Render

func Render(plan mutationir.Plan, registry *schema.Registry, provider policyir.Provider, capabilities policysql.CapabilityProof) (Program, error)

Render creates the only statement that may run before the batch bound is known. The capture uses the planner's complete action constraint, declared primary-key order, and a MaxRows+1 sentinel. It is SQL-only and performs no evaluation in Go.

func (Program) CaptureStatement

func (program Program) CaptureStatement() Statement

func (Program) MaxRows

func (program Program) MaxRows() uint32

func (Program) ModelID

func (program Program) ModelID() policyir.ModelID

func (Program) Operation

func (program Program) Operation() mutationir.Operation

func (Program) PrepareCaptured

func (program Program) PrepareCaptured(rows []mutationdecode.Row) (Prepared, error)

PrepareCaptured is intentionally a value-receiving phase boundary. If the capture contains the +1 sentinel it returns LIMIT_EXCEEDED and no Prepared value, so no caller can obtain a truncated write program.

func (Program) PrimaryKey

func (program Program) PrimaryKey() []policyir.FieldID

func (Program) Provider

func (program Program) Provider() policyir.Provider

func (Program) SemanticIndexed added in v0.3.0

func (program Program) SemanticIndexed() bool

SemanticIndexed carries the plan's registry-derived decision that a write to this model must be recorded for semantic re-embedding.

func (Program) SentinelRows

func (program Program) SentinelRows() uint32

func (Program) TransactionRequirement

func (program Program) TransactionRequirement() TransactionRequirement

type ResultColumn

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

func (ResultColumn) Alias

func (column ResultColumn) Alias() string

func (ResultColumn) FieldID

func (column ResultColumn) FieldID() policyir.FieldID

type Role

type Role uint8
const (
	CaptureExactSet Role = iota + 1
	AuthorizePreImage
	ApplyUpdate
	ApplyDelete
	RehydrateAfterImage
)

type RowVerification

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

func (RowVerification) After

func (row RowVerification) After() (mutationdecode.Row, bool)

func (RowVerification) AuthoredChangedFields

func (row RowVerification) AuthoredChangedFields() []policyir.FieldID

func (RowVerification) Before

func (row RowVerification) Before() mutationdecode.Row

func (RowVerification) Ordinal

func (row RowVerification) Ordinal() uint32

func (RowVerification) RequiredFieldAuthorizations

func (row RowVerification) RequiredFieldAuthorizations() []mutationir.FieldAuthorization

type Statement

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

func (Statement) AuthorizationColumns

func (statement Statement) AuthorizationColumns() []AuthorizationColumn

func (Statement) Bindings

func (statement Statement) Bindings() []Binding

func (Statement) Cardinality

func (statement Statement) Cardinality() Cardinality

func (Statement) Columns

func (statement Statement) Columns() []ResultColumn

func (Statement) ExpectedRows

func (statement Statement) ExpectedRows() uint32

func (Statement) Role

func (statement Statement) Role() Role

func (Statement) SQL

func (statement Statement) SQL() string

type TransactionRequirement

type TransactionRequirement uint8
const (
	PostgreSQLTransaction TransactionRequirement = iota + 1
	// SQLiteImmediateTransaction requires write intent before Capture executes.
	// That is what stabilizes the captured set on SQLite; a deferred transaction
	// is not an implementation of this contract.
	SQLiteImmediateTransaction
)

type Verification

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

func (Verification) Count

func (verification Verification) Count() int64

func (Verification) Facts

func (verification Verification) Facts() []FactSpec

func (Verification) Rows

func (verification Verification) Rows() []RowVerification

Jump to

Keyboard shortcuts

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