storage

package
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteViewPrefixes added in v0.0.24

func DeleteViewPrefixes(ctx jsutil.AsyncContext, prefixes []string, store Area) error

DeleteViewPrefixes deletes all storage entries for views with the given prefixes.

Types

type Area

type Area interface {
	// Set stores new data in storage. data is a map of key-value pairs to
	// be stored. If a key already exists, it will be overwritten.
	Set(ctx jsutil.AsyncContext, data map[string]js.Value) error

	// Get reads all the data items currently stored. The data returned is a
	// map of key-value pairs, with each representing a distinct item from
	// storage.
	Get(ctx jsutil.AsyncContext) (map[string]js.Value, error)

	// Delete removes the items from storage with the specified keys. If a
	// key is not found in storage, it will be silently ignored (i.e., no
	// error will be returned).
	Delete(ctx jsutil.AsyncContext, keys []string) error
}

Area implementations provide access to underlying storage. The interface is a simplified subset of the StorageArea API:

https://developer.chrome.com/docs/extensions/reference/storage/#type-StorageArea

func DefaultSession

func DefaultSession() Area

DefaultSession returns an Area that can store and retrieve in-memory data. The data is not written to disk. See:

https://developer.chrome.com/docs/extensions/reference/storage/#property-session

func DefaultSync

func DefaultSync() Area

DefaultSync returns an Area that can store and retrieve data that is synced between the user's devices. See:

https://developer.chrome.com/docs/extensions/reference/storage/#property-sync

type Big

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

Big supports storing and retrieving keys and values of arbitrary sizes. Items that fit within the per-item quota are stored normally; larger ones are split into multiple chunks.

Overall storage quota still applies, but this bypasses the per-item quotas.

Big implements the Area interface.

func NewBig

func NewBig(maxItemBytes int, store Area) *Big

func (*Big) Delete

func (b *Big) Delete(ctx jsutil.AsyncContext, keys []string) error

See PersistentStore.Delete().

func (*Big) Get

func (b *Big) Get(ctx jsutil.AsyncContext) (map[string]js.Value, error)

See PersistentStore.Get().

func (*Big) Set

func (b *Big) Set(ctx jsutil.AsyncContext, data map[string]js.Value) error

See PersistentStore.Set().

type Raw

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

Raw supports storing and retrieving data using Chrome's Storage API.

Raw implements the Area interface.

func NewRaw

func NewRaw(area js.Value) *Raw

NewRaw returns a Raw for storing and retrieving data. The specified area must point to an object implmenting the StorageArea API.

func (*Raw) Delete

func (r *Raw) Delete(ctx jsutil.AsyncContext, keys []string) error

Delete implements Area.Delete().

func (*Raw) Get

func (r *Raw) Get(ctx jsutil.AsyncContext) (map[string]js.Value, error)

Get implements Area.Get().

func (*Raw) Set

func (r *Raw) Set(ctx jsutil.AsyncContext, data map[string]js.Value) error

Set implements Area.Set().

type Typed

type Typed[V any] struct {
	// contains filtered or unexported fields
}

Typed reads and writes typed values. They are serialized upon writing, and deserialized upon reading. If deserialization fails for a given value, it is ignored.

func NewTyped

func NewTyped[V any](store Area, keyPrefix []string) *Typed[V]

NewTyped returns a new Typed using the underlying persistent store. keyPrefix is the prefix used to distinguish values from others in the same underlying store; multiple may be supplied to support migration scenarios.

func (*Typed[V]) Delete

func (t *Typed[V]) Delete(ctx jsutil.AsyncContext, test func(v *V) bool) error

Delete removes the value that matches the supplied test function. If multiple values match, all matching values are removed.

func (*Typed[V]) Read

func (t *Typed[V]) Read(ctx jsutil.AsyncContext, test func(v *V) bool) (*V, error)

Read returns a single value that matches the supplied test function. If multiple values match, only the first is returned. If the value is not found, a nil value is returned.

func (*Typed[V]) ReadAll

func (t *Typed[V]) ReadAll(ctx jsutil.AsyncContext) ([]*V, error)

ReadAll returns all the stored values.

func (*Typed[V]) Write

func (t *Typed[V]) Write(ctx jsutil.AsyncContext, value *V) error

Write writes a new value to storage.

type View

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

View supports storing and retrieving keys and values with particular key prefix. This allows multiple usages of the same underlying datastore, without them trampling on each other.

It is the caller's responsibility to supply unique key prefixes as required.

func NewView

func NewView(prefixes []string, store Area) *View

NewView returns a view of a storage area with a given set of key prefixes.

func (*View) Delete

func (v *View) Delete(ctx jsutil.AsyncContext, keys []string) error

Delete implements Area.Delete().

func (*View) Get

func (v *View) Get(ctx jsutil.AsyncContext) (map[string]js.Value, error)

Get implements Area.Get().

func (*View) Set

func (v *View) Set(ctx jsutil.AsyncContext, data map[string]js.Value) error

Set implements Area.Set().

Directories

Path Synopsis
Package testing implements utilities to support storage testing.
Package testing implements utilities to support storage testing.

Jump to

Keyboard shortcuts

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