producedview

package
v1.128.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package producedview holds the read-side views over the producer relation (#1569): what one script has produced, and which script producers still exist.

The relation in internal/producedby is deliberately keyless in both directions -- no foreign key to scripts, to portal assets or to resources -- so that deleting any of them leaves the record of what wrote what standing. The cost of that is exactly what this package pays: a row names an id, and a surface that wants to display it has to resolve that id against what exists now, and be able to say when nothing does.

It sits apart from the surfaces that render it because both ends need it and they live in different places: the file end is served by the portal's producer routes, the script end beside the script routes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetNames

type AssetNames interface {
	GetByIDs(ctx context.Context, ids []string) (map[string]*portaldomain.Asset, error)
}

AssetNames resolves asset ids to the assets they name, in one read.

type Item

type Item struct {
	// TargetKind is "asset" or "resource"; TargetID is the id within that kind.
	TargetKind string `json:"target_kind"`
	TargetID   string `json:"target_id"`
	// Name is what the file is called now, empty when it no longer exists.
	Name string `json:"name,omitempty"`
	// Created marks a file this producer brought into existence, as against one
	// it has only changed since.
	Created      bool      `json:"created"`
	FirstWriteAt time.Time `json:"first_write_at"`
	LastWriteAt  time.Time `json:"last_write_at"`
	WriteCount   int       `json:"write_count"`
	// LastVersion is the file version this producer last wrote, or zero for a
	// file whose kind does not number its writes.
	LastVersion int `json:"last_version"`
	// Deleted reports a file that has since been removed. The row stays: that
	// this producer wrote it is still true, and somebody deciding whether to
	// retire a script needs to see what it wrote that is already gone.
	Deleted bool `json:"deleted,omitempty"`
}

Item is one file a producer has produced or modified.

type Reader

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

Reader composes the producer relation with what the ids in it resolve to now.

Every collaborator is optional. A deployment with no asset store leaves an asset row unnamed rather than unlisted: that this script wrote something is the fact the list exists to report, and not being able to say what it is called is a smaller loss than dropping the row.

func New

func New(producers producedby.Store, assets AssetNames, resources ResourceNames, scripts ScriptLookup) *Reader

New builds the reader, or nil when there is no producer record to read.

func (*Reader) Names

func (r *Reader) Names(ctx context.Context, ids []string) (map[string]string, error)

Names resolves script ids to the names those scripts carry now. An id absent from the result is a script that no longer exists.

A lookup that fails is reported as an error rather than as a missing script: a database that is briefly unavailable must not make every producer read as deleted.

func (*Reader) Produced

func (r *Reader) Produced(ctx context.Context, scriptID string, limit int) ([]Item, error)

Produced lists everything one script has produced or modified, most recently written first.

type ResourceNames

type ResourceNames interface {
	Get(ctx context.Context, id string) (*resource.Resource, error)
}

ResourceNames resolves one resource id to its record.

type ScriptLookup

type ScriptLookup interface {
	GetByID(ctx context.Context, id string) (*script.Script, error)
}

ScriptLookup resolves one script id to its record. A nil record with a nil error is the store's not-found contract and means the script is gone.

Jump to

Keyboard shortcuts

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