provider

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserPath = "user"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ListProvider

type ListProvider[Q QueryRequest, L any] interface {
	// List fetches the configured collection path with the encoded query request and decodes the response as L.
	List(query Q, opts ...js.FetchOption) *Promise[L]
}

ListProvider fetches collection resources using a typed query request.

func NewListProvider

func NewListProvider[Q QueryRequest, L any](base *url.URL, path string) ListProvider[Q, L]

NewListProvider creates a new list provider with query type Q, list response type L, and a collection path.

type Promise

type Promise[T any] struct {
	// contains filtered or unexported fields
}

Promise represents a typed asynchronous result.

func (*Promise[T]) Done

func (p *Promise[T]) Done(fn func(T, error)) *Promise[T]

func (*Promise[T]) Wait

func (p *Promise[T]) Wait() (T, error)

type Provider

type Provider[K any, M any, R any] interface {
	// Get fetches key and decodes the response as R.
	Get(key K, opts ...js.FetchOption) *Promise[R]

	// Post marshals body as JSON, posts to the configured resource path, and decodes the response as R.
	Post(body M, opts ...js.FetchOption) *Promise[R]

	// Patch marshals body as JSON, patches key, and decodes the response as R.
	Patch(key K, body M, opts ...js.FetchOption) *Promise[R]

	// Delete sends a DELETE to key and decodes any response body as R.
	Delete(key K, opts ...js.FetchOption) *Promise[R]

	// Key derives the resource key from a response value.
	Key(value R) (K, error)
}

Provider fetches data from a remote source and returns typed async results.

func NewProvider

func NewProvider[K any, M any, R any](base *url.URL, path string, keyfn func(R) K) Provider[K, M, R]

NewProvider creates a new provider with key type K, meta type M, response type R, and a resource path.

type QueryRequest

type QueryRequest interface {
	Query() url.Values
}

QueryRequest represents a typed collection query that can be encoded into URL values.

type UserListProvider

type UserListProvider = ListProvider[schema.UserListRequest, schema.UserList]

UserListProvider is a concrete list provider for schema.User resources.

type UserProvider

type UserProvider struct {
	UserResourceProvider
	UserListProvider
}

func NewUserProvider

func NewUserProvider(base *url.URL) *UserProvider

NewUserProvider creates a provider for schema.User resources and collections.

type UserResourceProvider

type UserResourceProvider = Provider[schema.UserID, schema.UserMeta, schema.User]

UserResourceProvider is a concrete provider for schema.User resources.

Jump to

Keyboard shortcuts

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