registry

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package registry is the Gx component registry format (REQ-REG-01). A registry is static HTTP: an index.json and one items/<name>.json per item. Build turns a source folder of items into that shape; Validate checks it against the JSON Schema.

Index

Constants

View Source
const BaseDir = ".gx/base"

BaseDir is the committed base snapshot directory (REQ-REG-02).

View Source
const DefaultRoot = "ui"

DefaultRoot is the published target root that Dir replaces.

View Source
const RegistryImport = "github.com/alternayte/gx/registry/"

RegistryImport is the import prefix of the official registry source. An installed item rewrites it to the app module path (REQ-REG-05).

Variables

This section is empty.

Functions

func Lint

func Lint(src string, props PropReader) ([]string, error)

Lint checks every source item of a registry against REQ-REG-06: each item has a USAGE.md with usage examples, a do and don't section and a keyboard spec table, every component has a fixtures file, and every prop has a description. It returns one finding per violation.

func Merge

func Merge(base, local, upstream string) (string, bool)

Merge merges a local edit and an upstream edit of one file against their base (REQ-REG-03). It returns the merged text and whether a conflict wrote markers.

The merge is line-based. A region that only one side changed takes that side. A region both sides changed takes the change when the two texts are equal and writes conflict markers otherwise.

func SaveLock

func SaveLock(root string, lock Lock) error

SaveLock merges the registry section into gx.lock without touching other sections.

func Schema

func Schema() ([]byte, error)

Schema returns the JSON Schema of one registry item (REQ-REG-01).

func ValidateItem

func ValidateItem(item Item) error

ValidateItem checks one item against the format rules (REQ-REG-01).

func ValidateRegistry

func ValidateRegistry(dir string) error

ValidateRegistry reads a published registry and checks every item and the index (REQ-REG-01).

Types

type Change

type Change struct {
	// Target is the published target path of the file.
	Target string
	// Status is unchanged, local, upstream, merged, conflict,
	// upstream-added, upstream-removed or local-removed.
	Status string
}

Change is the state of one file in gx diff or gx update (REQ-REG-03).

type File

type File struct {
	// Path is the path inside the item source.
	Path string `json:"path"`
	// Target is the path inside the app, relative to the module root.
	Target string `json:"target"`
	// Content is the file text.
	Content string `json:"content"`
	// SHA256 is the hex digest of Content.
	SHA256 string `json:"sha256"`
}

File is one file of an item.

type Index

type Index struct {
	Items []Summary `json:"items"`
}

Index is the registry index.json (REQ-REG-01).

func Build

func Build(src, out string) (Index, error)

Build reads every item folder under src (a folder with gx-item.json and USAGE.md) and writes the published registry into out: index.json and items/<name>.json (REQ-REG-01).

type Installer

type Installer struct {
	// Root is the app module root that holds gx.toml and gx.lock.
	Root string
	// Source is the registry base: an http(s) URL or a directory that
	// holds index.json and items/ (REQ-REG-01).
	Source string
	// Dir is the app directory the published DefaultRoot maps to. Empty
	// keeps DefaultRoot.
	Dir string
	// Headers are "name: value" strings sent with every HTTP request
	// (REQ-REG-04).
	Headers []string
	// Client is the HTTP client, or a client with a 30 s timeout.
	Client *http.Client
}

Installer installs published registry items into an app (REQ-REG-02).

func (*Installer) Add

func (in *Installer) Add(name, version string) ([]Item, error)

Add fetches one item and its dependency closure, verifies every file hash (SI-09), writes the files, stores the base snapshots and records the items in gx.lock. It returns the items in install order, dependencies first.

func (*Installer) Diff

func (in *Installer) Diff(name string) ([]Change, error)

Diff reports the local, base and upstream state of one installed item (REQ-REG-03).

func (*Installer) Index

func (in *Installer) Index() (Index, error)

Index reads the index of the registry: one summary per item (REQ-REG-01).

func (*Installer) Update

func (in *Installer) Update(name, version string) ([]Change, bool, error)

Update merges the current registry version into one installed item (REQ-REG-03). A clean change takes the upstream text, a local-only change stays, and a region both sides changed writes conflict markers and is reported. The base snapshot and gx.lock move to the upstream version either way, so a second update is a no-op.

type Item

type Item struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Description string `json:"description"`
	// Kind is "component", "block" or "theme".
	Kind                 string   `json:"kind"`
	Files                []File   `json:"files"`
	RegistryDependencies []string `json:"registryDependencies,omitempty"`
	IconPacks            []string `json:"iconPacks,omitempty"`
	JSPins               []string `json:"jsPins,omitempty"`
	RequiredTokens       []string `json:"requiredTokens,omitempty"`
	// Usage is the USAGE.md of the item.
	Usage string `json:"usage"`
}

Item is one published registry item (REQ-REG-01).

func Find

func Find(dir, name string) (Item, error)

Find returns one item of a published registry.

func LoadSnapshot

func LoadSnapshot(root, name, version string) (Item, error)

LoadSnapshot reads the base snapshot of one installed version (REQ-REG-02).

type Lock

type Lock struct {
	Items map[string]LockItem `json:"items"`
}

Lock is the registry section of gx.lock (REQ-REG-02).

func LoadLock

func LoadLock(root string) (Lock, error)

LoadLock reads the registry section of gx.lock.

type LockItem

type LockItem struct {
	Version string `json:"version"`
	// Files maps the installed app path to the sha256 of its bytes.
	Files map[string]string `json:"files"`
}

LockItem is one installed item.

type Manifest

type Manifest struct {
	Name                 string   `json:"name"`
	Version              string   `json:"version"`
	Description          string   `json:"description"`
	Kind                 string   `json:"kind"`
	Files                []Target `json:"files"`
	RegistryDependencies []string `json:"registryDependencies,omitempty"`
	IconPacks            []string `json:"iconPacks,omitempty"`
	JSPins               []string `json:"jsPins,omitempty"`
	RequiredTokens       []string `json:"requiredTokens,omitempty"`
}

Manifest is the source gx-item.json of one item folder (REQ-REG-01).

type PropDoc

type PropDoc struct {
	Name string
	Doc  string
}

PropDoc is one prop of a component file with its description.

type PropReader

type PropReader func(path string, src []byte) ([]PropDoc, error)

PropReader reads the props block of one .gx file. The caller passes the parser: this package installs items and must not depend on the compiler, which runs commands (SI-09).

type Summary

type Summary struct {
	Name        string `json:"name"`
	Version     string `json:"version"`
	Description string `json:"description"`
	Kind        string `json:"kind"`
}

Summary is one line of the index.

type Target

type Target struct {
	Path   string `json:"path"`
	Target string `json:"target"`
}

Target names one source file and its app path.

Jump to

Keyboard shortcuts

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