sourcemap

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package sourcemap reads and prunes private, manifest-owned release artifacts. It exposes no HTTP route, uploader, fetcher or background worker. Applications authorize reads and keep Directory outside their public tree. Build publishers must coordinate with pruning and publish immutable release directories: filesystem metadata checks detect changes but cannot make deletion atomic with outside writers.

The compatible build layout is Directory/release/portal/manifest.json plus map files in that same portal directory. The manifest is JSON with string "release" and "portal" fields and an "assets" object mapping "_assets/basename.js" to a single map filename. Segments are 1..128 ASCII letters, digits, dots, underscores or hyphens, start with a letter or digit, and never contain "..". Maps are opaque bytes; this package neither parses nor rewrites their source content.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset string

Asset is an exact portal/_assets/basename path. Read validates even cast values.

func ParseAsset

func ParseAsset(text string) (Asset, error)

ParseAsset validates a literal asset path without URL decoding or normalization.

Example
package main

import (
	"fmt"

	"github.com/weiloon1234/Foundry-Go/telemetry/sourcemap"
)

func main() {
	asset, err := sourcemap.ParseAsset("admin/_assets/app-abc.js")
	fmt.Println(asset, err)
}
Output:
admin/_assets/app-abc.js <nil>

type Config

type Config struct {
	Directory    string
	Release      telemetry.Release
	Portals      []telemetry.Portal
	MaxBytes     int
	Retention    time.Duration
	StorageBytes int64
	Clock        clock.Clock
}

Config declares a private build directory and explicit bounds. Empty Directory disables filesystem access. MaxBytes is 1..10 MiB; Retention is 1h..30d; StorageBytes is MaxBytes..1 GiB. Portals contains 1..32 distinct segments. Clock is required, borrowed, and invoked only by Prune. Release is protected from pruning; historical releases remain readable.

type Map

type Map struct {
	Release telemetry.Release
	Asset   Asset
	Data    []byte
}

Map owns a fresh byte slice containing the build's opaque source map.

type PruneResult

type PruneResult struct {
	Releases int
	Bytes    int64
}

PruneResult counts completely removed releases and their inventoried bytes. An error can accompany partial progress; never blindly retry a failed deletion.

type Store

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

Store retains an immutable configuration snapshot and no open files. Its zero value is unusable; construct one with New.

func New

func New(config Config) (*Store, error)

New validates and snapshots configuration without filesystem or clock I/O.

Example
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/weiloon1234/Foundry-Go/clock"
	"github.com/weiloon1234/Foundry-Go/telemetry"
	"github.com/weiloon1234/Foundry-Go/telemetry/sourcemap"
)

func main() {
	store, err := sourcemap.New(sourcemap.Config{
		Directory:    "", // Disabled until the application supplies its private build root.
		Release:      telemetry.Release("release-1"),
		Portals:      []telemetry.Portal{"admin"},
		MaxBytes:     10 << 20,
		Retention:    30 * 24 * time.Hour,
		StorageBytes: 1 << 30,
		Clock:        clock.System{},
	})
	if err != nil {
		panic(err)
	}
	result, err := store.Prune(context.Background())
	fmt.Println(result.Releases, result.Bytes, err)
}
Output:
0 0 <nil>

func (*Store) Prune

func (s *Store) Prune(ctx context.Context) (result PruneResult, err error)

Prune removes the oldest owned releases until retention and storage bounds are met, always preserving Config.Release. Unknown files/portals preserve an entire release. Missing roots are harmless. Malformed artifacts fail closed. Storage accounting includes only fully owned releases; unrelated files are not managed. Inventories allow 1024 root entries, 32 portals per release, 1024 files per portal, and 65536 total entries. Exceeding a bound fails before any deletion. Active-release cap excess returns a Conflict fault with any completed progress.

func (*Store) Read

func (s *Store) Read(ctx context.Context, release telemetry.Release, asset Asset) (out Map, err error)

Read returns a manifest-selected map from a configured portal. Missing artifacts retain os.ErrNotExist; malformed or unsafe artifacts return framework faults. Reads are bounded to 128 KiB for manifests and MaxBytes for maps, with context checks between reads. Cancellation cannot interrupt an in-flight OS operation.

Jump to

Keyboard shortcuts

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