query

package
v1.1.68-test Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 3 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Specialize

func Specialize(ordProp string, props, rels []string) *validate.Rule

Specialize builds the per-kind Query rule — the port of catalog.ts specializeQuerySchema (L20-43). A registered kind does not validate against the generic Query schema: its `property`, `rel` and `sort.by` are narrowed to what that kind actually exposes, `kind` becomes required, and `spec.sort` gains a default of the kind's natural order.

Doing it in the SCHEMA rather than as a post-validation check is what produces Joi's `any.only` error naming the alternatives ("must be one of [name, id, …]") instead of a bespoke sentence. The caller gets the list of properties they could have used, which is the whole point of the message.

props/rels are ORDERED: the order reaches the user as the order of the valids in that message, and TS's comes from Object.keys() over the registration literal.

Types

type Query

type Query struct {
	Kind    base.Kind     `json:"kind,omitzero"`
	Context *QueryContext `json:"context,omitzero" validate:"readOnly"`
	Fetch   QueryFetch    `json:"fetch,omitzero" validate:"default=items,optional"`
	Spec    *Spec         `json:"spec,omitzero"`
}

type QueryContext

type QueryContext map[string]any

type QueryFetch

type QueryFetch string
const (
	QueryFetchLinks QueryFetch = "links"
	QueryFetchItems QueryFetch = "items"
)

func (QueryFetch) EnumValues

func (QueryFetch) EnumValues() []string

EnumValues ports `Joi.string().valid('links','items')` (query.ts fetch).

type QueryResult

type QueryResult struct {
	Kind     QueryResultKind `json:"kind,omitzero"`
	ItemKind base.Kind       `json:"itemKind,omitzero"`
	Items    []any           `json:"items"`
	Links    []base.Link     `json:"links"`
	Query    *Query          `json:"query,omitzero"`
}

type QueryResultKind

type QueryResultKind string
const (
	QueryResultKindQueryresult QueryResultKind = "queryresult"
)

type Spec

type Spec struct {
	Match SpecMatch `json:"match,omitzero" validate:"trim,default=all"`
	Terms []Term    `json:"terms,omitzero"`
	Sort  *SpecSort `json:"sort,omitzero"`
}

type SpecMatch

type SpecMatch string
const (
	SpecMatchAll  SpecMatch = "all"
	SpecMatchAny  SpecMatch = "any"
	SpecMatchNone SpecMatch = "none"
)

func (SpecMatch) EnumValues

func (SpecMatch) EnumValues() []string

EnumValues ports `Joi.string().valid('all','any','none')` (query.ts match).

type SpecSort

type SpecSort struct {
	By    string        `json:"by" validate:"required"`
	Order SpecSortOrder `json:"order,omitzero" validate:"default=asc"`
}

type SpecSortOrder

type SpecSortOrder string
const (
	SpecSortOrderAsc  SpecSortOrder = "asc"
	SpecSortOrderDesc SpecSortOrder = "desc"
)

func (SpecSortOrder) EnumValues

func (SpecSortOrder) EnumValues() []string

EnumValues ports `Joi.string().valid('asc','desc')` (query.ts sort.order).

type Term

type Term struct {
	Op       TermOp    `json:"op,omitzero" validate:"trim,default=="`
	Property string    `json:"property,omitzero" validate:"trim"`
	Rel      string    `json:"rel,omitzero" validate:"trim"`
	Tag      string    `json:"tag,omitzero" validate:"trim"`
	Value    TermValue `json:"value,omitzero"`
}

func (Term) ValidationRule

func (Term) ValidationRule() *validate.Rule

ValidationRule ports the Term object rule (query.ts:6-37): the tagged fields plus the value presence/type rules, the xor, and the tag-value coercion.

type TermOp

type TermOp string
const (
	TermOpEq        TermOp = "="
	TermOpGt        TermOp = ">"
	TermOpGte       TermOp = ">="
	TermOpLt        TermOp = "<"
	TermOpLte       TermOp = "<="
	TermOpNe        TermOp = "!="
	TermOpMatch     TermOp = "~"
	TermOpRegex     TermOp = "=~"
	TermOpExists    TermOp = "exists"
	TermOpNotExists TermOp = "!exists"
	TermOpContains  TermOp = "contains"
)

func (TermOp) EnumValues

func (TermOp) EnumValues() []string

EnumValues ports the Term.op `Joi.string().valid(...)` enum (query.ts:7-10), in Joi's declaration order so the "must be one of [...]" message matches.

type TermValue

type TermValue any //ts:string | number | boolean | Date

TermValue is a scalar match value: string | number | boolean | date (RFC3339). Go has no union type; kept any-backed, referenced by name.

Jump to

Keyboard shortcuts

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