registry

package
v0.0.0-...-1efff26 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FILTER_PRESENT = iota + 1
	FILTER_ABSENT
	FILTER_EQUAL
	FILTER_NOT_EQUAL
)
View Source
const (
	FOR_READ = iota + 1
	FOR_WRITE
)

For entity.AccessMode

View Source
const ANCESTOR_TBD = "$TBD"
View Source
const DOCVIEW_BASE = "#"
View Source
const HTML_EXP = "▾" // Expanded json symbol for HTML output
View Source
const HTML_MIN = "▸" // Minimized json symbol for HTML output

Variables

View Source
var DB *sql.DB
View Source
var DBHOST = "localhost"
View Source
var DBPASSWORD = "password"
View Source
var DBPORT = "3306"
View Source
var DBUSER = "root"
View Source
var DB_InitFunc func()
View Source
var DB_Name = ""
View Source
var DefaultDiscardWriter = &DiscardWriter{}
View Source
var DefaultRegDbSID string
View Source
var MAX_PROPNAME = 255
View Source
var MAX_VARCHAR = 4096
View Source
var PProfFilter = &FilterPProf{}
View Source
var PropsFuncs = []*Attribute{
	{
		Name: "specversion",
		// contains filtered or unexported fields
	},
	{
		Name: "id",
		// contains filtered or unexported fields
	},
	{
		Name: "versionid",
		// contains filtered or unexported fields
	},
	{
		Name: "self",
		// contains filtered or unexported fields
	},

	{
		Name: "xid",
		// contains filtered or unexported fields
	},
	{
		Name: "xref",
		// contains filtered or unexported fields
	},
	{
		Name: "epoch",
		// contains filtered or unexported fields
	},
	{
		Name: "name",
		// contains filtered or unexported fields
	},
	{
		Name: "isdefault",
		// contains filtered or unexported fields
	},
	{
		Name: "description",
		// contains filtered or unexported fields
	},
	{
		Name: "documentation",
		// contains filtered or unexported fields
	},
	{
		Name: "labels",
		// contains filtered or unexported fields
	},
	{
		Name: "createdat",
		// contains filtered or unexported fields
	},
	{
		Name: "modifiedat",
		// contains filtered or unexported fields
	},
	{
		Name: "$extensions",
		// contains filtered or unexported fields
	},
	{
		Name: "capabilities",
		// contains filtered or unexported fields
	},
	{
		Name: "model",
		// contains filtered or unexported fields
	},
	{
		Name: "modelsource",
		// contains filtered or unexported fields
	},
	{
		Name: "readonly",
		// contains filtered or unexported fields
	},
	{
		Name: "compatibility",
		// contains filtered or unexported fields
	},
	{
		Name: "compatibilityauthority",
		// contains filtered or unexported fields
	},
	{
		Name: "deprecated",
		// contains filtered or unexported fields
	},
	{
		Name: "ancestor",
		// contains filtered or unexported fields
	},
	{
		Name: "contenttype",
		// contains filtered or unexported fields
	},
	{
		Name: "$extensions",
		// contains filtered or unexported fields
	},
	{
		Name: "$space",
		// contains filtered or unexported fields
	},

	{
		Name: "$RESOURCEurl",
		// contains filtered or unexported fields
	},
	{
		Name: "$RESOURCEproxyurl",
		// contains filtered or unexported fields
	},
	{
		Name: "$RESOURCE",
		// contains filtered or unexported fields
	},
	{
		Name: "$RESOURCEbase64",
		// contains filtered or unexported fields
	},
	{
		Name: "$space",
		// contains filtered or unexported fields
	},
	{
		Name: "metaurl",
		// contains filtered or unexported fields
	},
	{
		Name: "meta",
		// contains filtered or unexported fields
	},
	{
		Name: "$space",
		// contains filtered or unexported fields
	},
	{
		Name: "defaultversionid",
		// contains filtered or unexported fields
	},
	{
		Name: "defaultversionurl",
		// contains filtered or unexported fields
	},
	{
		Name: "defaultversionsticky",
		// contains filtered or unexported fields
	},
	{
		Name: "$space",
		// contains filtered or unexported fields
	},
	{
		Name: "$COLLECTIONS",
		// contains filtered or unexported fields
	},
}

This data will be merged into OrderedSpecProps during init(). We can't put them directly into OrderedSpecProps because the client doesn't need them, or have access to the RequestInfo

View Source
var SupportedFormats = map[string]FormatChecker{}
View Source
var TXs = map[string]*Tx{}

Active transaction - mainly for debugging and testing

View Source
var TXsMutex = sync.RWMutex{}
View Source
var VersionModes = map[string]VersionMode{
	"manual":    (*ManualVersionMode)(nil),
	"createdat": (*CreatedatVersionMode)(nil),
}

Functions

func (*Entity) AddCalcProps

func (e *Entity) AddCalcProps(info *RequestInfo) map[string]any

This will add in the calculated properties into the entity. This will normally be called after a query using FullTree view and before we serialize the entity we need to add the non-DB-stored properties (meaning, the calculated ones. Note that we make a copy and don't touch the entity itself. Serializing an entity shouldn't have side-effects.

func (*Registry) AddGroup

func (reg *Registry) AddGroup(gType string, id string) (*Group, *XRError)

func (*Registry) AddGroupWithObject

func (reg *Registry) AddGroupWithObject(gType string, id string, obj Object) (*Group, *XRError)

func (*Group) AddResource

func (g *Group) AddResource(rType string, id string, vID string) (*Resource, *XRError)

func (*Group) AddResourceWithObject

func (g *Group) AddResourceWithObject(rType string, id string, vID string, obj Object, objIsVer bool) (*Resource, *XRError)

func (*Registry) AddToCache

func (r *Registry) AddToCache(e *Entity)

ONLY CALL FROM TESTS - NEVER IN PROD

func (*Resource) AddVersion

func (r *Resource) AddVersion(id string) (*Version, *XRError)

func (*Resource) AddVersionWithObject

func (r *Resource) AddVersionWithObject(id string, obj Object) (*Version, *XRError)

func (*Model) ApplyNewModel

func (m *Model) ApplyNewModel(newM *Model, src string) *XRError

func (*Model) ApplyNewModelFromJSON

func (m *Model) ApplyNewModelFromJSON(buf []byte) *XRError

func BuildURL

func BuildURL(info *RequestInfo, path string) string

func BuildURLNoUI

func BuildURLNoUI(info *RequestInfo, path string) string

func (*Resource) CheckAncestors

func (r *Resource) CheckAncestors() *XRError

func CheckAttrs

func CheckAttrs(obj map[string]any, source string) *XRError

We call this to verify that the top level attribute names are valid. We can't really do this during the Validation funcs because at that point in the process we may have added #xxx type of attribute names, and "#" isn't a valid char. And we need to make sure users don't try to pass in attributes that start with "#" to attack us. Now, one way around this is to move the system props (#xxx) into a separate map (out of Object and NewObject) but then we'd need to duplicate a lot of logic - but it might actually make for a cleaner design to keep system data out of the user data space, so worth considering in the future. I really would prefer to push this down in the stack though.

func (*Registry) Commit

func (r *Registry) Commit() *XRError

func CreateDB

func CreateDB(name string) error

func DBExists

func DBExists(name string) bool

func (*Meta) Delete

func (m *Meta) Delete() *XRError

func DeleteDB

func DeleteDB(name string) error

func (*Version) DeleteSetNextVersion

func (v *Version) DeleteSetNextVersion(nextVersionID string) *XRError

func Do

func Do(tx *Tx, cmd string, args ...interface{})

func DoCount

func DoCount(tx *Tx, num int, cmd string, args ...interface{})

func DoOne

func DoOne(tx *Tx, cmd string, args ...interface{})

func DoOneTwo

func DoOneTwo(tx *Tx, cmd string, args ...interface{})

func DoZeroOne

func DoZeroOne(tx *Tx, cmd string, args ...interface{})

func DoZeroTwo

func DoZeroTwo(tx *Tx, cmd string, args ...interface{})

func (*Resource) DumpOrderedVersions

func (r *Resource) DumpOrderedVersions()

func DumpTXs

func DumpTXs()

func DumpTimings

func DumpTimings() string

func (*Resource) EnsureCircularReferences

func (r *Resource) EnsureCircularReferences() *XRError

func (*Resource) EnsureCompat

func (r *Resource) EnsureCompat() *XRError

func (*Resource) EnsureLatest

func (r *Resource) EnsureLatest() *XRError

func (*Resource) EnsureMaxVersions

func (r *Resource) EnsureMaxVersions() *XRError

func (*Entity) EnsureNewObject

func (e *Entity) EnsureNewObject() bool

func (*Resource) EnsureSingleVersionRoot

func (r *Resource) EnsureSingleVersionRoot() *XRError

func ExtractIncomingObject

func ExtractIncomingObject(info *RequestInfo, body []byte) (Object, *XRError)

func (*Registry) FindGroup

func (reg *Registry) FindGroup(gType string, id string, anyCase bool, accessMode int) (*Group, *XRError)

func (*Resource) FindMeta

func (r *Resource) FindMeta(anyCase bool, accessMode int) (*Meta, *XRError)

func FindRegistry

func FindRegistry(tx *Tx, id string, accessMode int) (*Registry, *XRError)

BY UID

func FindRegistryBySID

func FindRegistryBySID(tx *Tx, sid string, accessMode int) (*Registry, *XRError)

func (*Group) FindResource

func (g *Group) FindResource(rType string, id string, anyCase bool, accessMode int) (*Resource, *XRError)

func (*Registry) FindResourceByXID

func (r *Registry) FindResourceByXID(xidStr string, path string) (*Resource, *XRError)

func (*Resource) FindVersion

func (r *Resource) FindVersion(id string, anyCase bool, accessMode int) (*Version, *XRError)

Maybe replace error with a panic? same for other finds??

func (*Registry) FindXIDGroup

func (r *Registry) FindXIDGroup(xidStr string, path string) (*Group, *XRError)

func (*Registry) FindXIDMeta

func (r *Registry) FindXIDMeta(xidStr string, path string) (*Meta, *XRError)

func (*Registry) FindXIDVersion

func (r *Registry) FindXIDVersion(xidStr string, path string) (*Version, *XRError)

func GenerateQuery

func GenerateQuery(reg *Registry, what string, paths []string, filters [][]*FilterExpr, docView bool, sortKey string) (string, []interface{}, *XRError)

sortKey = attribute name, -NAME means descending, no "-" means ascending

func GenerateUI

func GenerateUI(info *RequestInfo, data []byte) []byte

func (*Registry) Get

func (reg *Registry) Get(name string) any

func (*Entity) GetAsInt

func (e *Entity) GetAsInt(path string) int

func (*Entity) GetAsString

func (e *Entity) GetAsString(path string) string

func (*Entity) GetAttributes

func (e *Entity) GetAttributes(obj Object) Attributes

func (*Entity) GetBaseAttributes

func (e *Entity) GetBaseAttributes() Attributes

Returns the initial set of attributes defined for the entity.

func (*Resource) GetChildVersionIDs

func (r *Resource) GetChildVersionIDs(parentVID string) ([]string, *XRError)

func (*Version) GetChildren

func (v *Version) GetChildren() ([]*Version, *XRError)

func (*Entity) GetCollections

func (e *Entity) GetCollections() [][2]string

Array of plural/singular pairs

func (*Resource) GetDefault

func (r *Resource) GetDefault(accessMode int) (*Version, *XRError)

Maybe replace error with a panic?

func GetDefaultReg

func GetDefaultReg(tx *Tx) *Registry

func (*Entity) GetGroupModel

func (e *Entity) GetGroupModel() *GroupModel

func GetGroupModelInlines

func GetGroupModelInlines(gm *GroupModel) []string

func (*Resource) GetHasDocument

func (r *Resource) GetHasDocument() bool

func (*Resource) GetNewest

func (r *Resource) GetNewest() (*Version, *XRError)

func (*Resource) GetNewestVersionID

func (r *Resource) GetNewestVersionID() (string, *XRError)

func (*Resource) GetNumberOfVersions

func (r *Resource) GetNumberOfVersions() (int, *XRError)

func (*Resource) GetOrderedVersionIDs

func (r *Resource) GetOrderedVersionIDs() ([]*VersionAncestor, *XRError)

func (*Entity) GetOrigin

func (e *Entity) GetOrigin(path string) any

func (*Entity) GetPP

func (e *Entity) GetPP(pp *PropPath) any

func (*Resource) GetProblematicVersions

func (r *Resource) GetProblematicVersions() ([]*VersionAncestor, *XRError)

Return all versions whose 'ancestor' is ANCESTOR_TBD or points to a missing version (which include pointing to null). Note that the results is ordered so that we can process the ones with a missing Ancestor in oldest->newest order

func (*Entity) GetPropsOrdered

func (e *Entity) GetPropsOrdered() ([]*Attribute, map[string]*Attribute)

func GetRegistryModelInlines

func GetRegistryModelInlines(m *Model) []string

func GetRegistryNames

func GetRegistryNames() ([]string, *XRError)

func (*Entity) GetRequestInfo

func (e *Entity) GetRequestInfo() *RequestInfo

func (*Entity) GetResourceModel

func (e *Entity) GetResourceModel() *ResourceModel

func GetResourceModelInlines

func GetResourceModelInlines(rm *ResourceModel) []string

func (*Entity) GetResourceSingular

func (e *Entity) GetResourceSingular() string

func (*Resource) GetRootVersionIDs

func (r *Resource) GetRootVersionIDs() ([]string, *XRError)

func (*Registry) GetTx

func (r *Registry) GetTx() *Tx

func (*Resource) GetVersionIDs

func (r *Resource) GetVersionIDs() ([]string, *XRError)

func (*Resource) GetVersionMode

func (r *Resource) GetVersionMode() VersionMode

func GetVersionModelInlines

func GetVersionModelInlines(rm *ResourceModel) []string

func GetVersionSum

func GetVersionSum(version *Version) (int, *XRError)

func (*Resource) GetVersions

func (r *Resource) GetVersions() ([]*Version, *XRError)

func (*Resource) GetXref

func (r *Resource) GetXref() (string, *Resource, *XRError)

func GoToOurType

func GoToOurType(val any) string

func HTTPDelete

func HTTPDelete(info *RequestInfo) *XRError

func HTTPDeleteGroups

func HTTPDeleteGroups(info *RequestInfo) *XRError

func HTTPDeleteResources

func HTTPDeleteResources(info *RequestInfo) *XRError

func HTTPDeleteVersions

func HTTPDeleteVersions(info *RequestInfo) *XRError

func HTTPGETCapabilities

func HTTPGETCapabilities(info *RequestInfo) *XRError

func HTTPGETCapabilitiesOffered

func HTTPGETCapabilitiesOffered(info *RequestInfo) *XRError

func HTTPGETContent

func HTTPGETContent(info *RequestInfo) *XRError

func HTTPGETModel

func HTTPGETModel(info *RequestInfo) *XRError

func HTTPGETModelSource

func HTTPGETModelSource(info *RequestInfo) *XRError

func HTTPGet

func HTTPGet(info *RequestInfo) *XRError

func HTTPPUTCapabilities

func HTTPPUTCapabilities(info *RequestInfo) *XRError

func HTTPPUTModelSource

func HTTPPUTModelSource(info *RequestInfo) *XRError

func HTTPProxy

func HTTPProxy(w http.ResponseWriter, r *http.Request)

func HTTPPutPost

func HTTPPutPost(info *RequestInfo) *XRError

func HTTPWriteError

func HTTPWriteError(info *RequestInfo, errAny any)

func (*Resource) HasCircularAncestors

func (r *Resource) HasCircularAncestors() ([]string, *XRError)

func IsValidJson

func IsValidJson(buf []byte) error

func (*Resource) IsXref

func (r *Resource) IsXref() bool

func (*Version) JustDelete

func (v *Version) JustDelete() *XRError

JustDelete will delete the Version w/o any additional logic like "defaultversionid" manipulation. Used when xref on the Resource is set and we need to clear existing vers

func (*Meta) JustSet

func (m *Meta) JustSet(name string, val any) *XRError

func (*Resource) JustSetDefault

func (r *Resource) JustSetDefault(name string, val any) *XRError

func (*Resource) JustSetMeta

func (r *Resource) JustSetMeta(name string, val any) *XRError

func ListDBs

func ListDBs() ([]string, *XRError)

func (*Registry) LoadCapabilities

func (reg *Registry) LoadCapabilities() *Capabilities

func LoadEpochMap

func LoadEpochMap(info *RequestInfo) (EpochEntryMap, *XRError)

func LoadModel

func LoadModel(reg *Registry) *Model

func (*Registry) LoadModelFromFile

func (reg *Registry) LoadModelFromFile(file string) *XRError

func LoadRemoteRegistry

func LoadRemoteRegistry(host string) (*Registry, *XRError)

func (*Entity) Lock

func (e *Entity) Lock() bool

func (*Entity) MatchXID

func (e *Entity) MatchXID(str string, xid string, attr string) *XRError

If no match then return an error saying why

func (*Resource) MustFindMeta

func (r *Resource) MustFindMeta(anyCase bool, accessMode int) *Meta

func NewRegistry

func NewRegistry(tx *Tx, id string, regOpts ...RegOpt) (*Registry, *XRError)

func NewTx

func NewTx() (*Tx, *XRError)

func OpenDB

func OpenDB(name string) *XRError

func ParseRequest

func ParseRequest(tx *Tx, w http.ResponseWriter, r *http.Request) (*RequestInfo, *XRError)

func Path2Abstract

func Path2Abstract(path string) string

func PrepUpdateEntity

func PrepUpdateEntity(e *Entity) *XRError

func ProcessSetDefaultVersionIDFlag

func ProcessSetDefaultVersionIDFlag(info *RequestInfo, resource *Resource, version *Version) *XRError

Process the ?setdefaultversionid query parameter "resource" is the resource we're processing "version" is the version that was processed

func (*Entity) Query

func (e *Entity) Query(query string, args ...any) [][]any

func RawEntitiesFromQuery

func RawEntitiesFromQuery(tx *Tx, regID string, accessMode int, query string, args ...any) ([]*Entity, *XRError)

func RawEntityFromPath

func RawEntityFromPath(tx *Tx, regID string, path string, anyCase bool, accessMode int) (*Entity, *XRError)

func (*Entity) Refresh

func (e *Entity) Refresh(accessMode int) *XRError

Update the entity's Object - not the other props in Entity. Similar to RawEntityFromPath

func RegHTMLify

func RegHTMLify(buf []byte, proxyHost, targetHost string) ([]byte, int)

HTML, # of expands

func RegisterFormat

func RegisterFormat(name string, format FormatChecker)

func (*Entity) RemoveCollections

func (e *Entity) RemoveCollections(obj Object)

This will remove all Collection related attributes from the entity. While this is an Entity.Func, we allow callers to pass in the Object data to use instead of the e.Object/NewObject so that we'll use this Entity's Type (which tells us which collections it has), on the 'obj'. This is handy for cases where we need to remove the Resource's collections from a Version's Object - like on a PUT to /GROUPs/gID/RESOURECEs/rID where we're passing in what looks like a Resource entity, but we're really using it to create a Version

func RemoveResourceAttributes

func RemoveResourceAttributes(rm *ResourceModel, obj map[string]any)

Remove any attributes that appear on Resources but not Versions. Mainly used to prep an Obj that was directed at a Resource but will be used to update a Version

func RemoveVersionAttributes

func RemoveVersionAttributes(rm *ResourceModel, obj map[string]any)

Not used yet but if we ever support extensions for resourceattributes then we may need this

func ReplaceVariables

func ReplaceVariables(str string) string

func (*Registry) Rollback

func (r *Registry) Rollback() *XRError

func (*Entity) Save

func (e *Entity) Save() *XRError

func (*Registry) SaveAllAndCommit

func (r *Registry) SaveAllAndCommit() *XRError

func (*Registry) SaveCommitRefresh

func (r *Registry) SaveCommitRefresh() *XRError

ONLY CALL FROM TESTS - NEVER IN PROD

func (*Registry) SaveModel

func (reg *Registry) SaveModel() *XRError

func (*Model) SerializeForUser

func (m *Model) SerializeForUser() ([]byte, *XRError)

func (*Entity) SerializeProps

func (e *Entity) SerializeProps(info *RequestInfo,
	fn func(*Entity, *RequestInfo, string, any, *Attribute) *XRError) *XRError

This is used to serialize an Entity regardless of the format. This will:

  • Use AddCalcProps() to fill in any missing props (eg Entity's getFn())
  • Call that passed-in 'fn' to serialize each prop but in the right order as defined by the entity's GetPropsOrdered()

func SerializeQuery

func SerializeQuery(info *RequestInfo, resPaths map[string][]string,
	what string, filters [][]*FilterExpr) *XRError

func SerializeResourceContents

func SerializeResourceContents(jw *JsonWriter, e *Entity, info *RequestInfo, extra *string) *XRError

func (*Entity) SetDBProperty

func (e *Entity) SetDBProperty(pp *PropPath, val any) *XRError

This will save a single property/value in the DB. This assumes the caller is traversing the Object and splitting it into individual props

func (*Resource) SetDefault

func (r *Resource) SetDefault(newDefault *Version) *XRError

Only call this if you want things to be sticky (when not nil). Creating a new version should do this directly

func (*Resource) SetDefaultID

func (r *Resource) SetDefaultID(vID string) *XRError

Note will set sticky if vID != ""

func (*Entity) SetFromDBName

func (e *Entity) SetFromDBName(name string, val *string, propType string) *XRError

This is used to take a DB entry and update the current Entity's Object

func (*Entity) SetNewObject

func (e *Entity) SetNewObject(newObj map[string]any)

We use this just to make sure we can set NewObjectStack when we need to debug stuff

func (*Entity) SetPP

func (e *Entity) SetPP(pp *PropPath, val any) *XRError

This is really just an internal Setter used for testing. It'll set a property and then validate and save the entity in the DB

func (*Meta) SetSave

func (m *Meta) SetSave(name string, val any) *XRError

func (*Resource) SetSaveDefault

func (r *Resource) SetSaveDefault(name string, val any) *XRError

func (*Resource) SetSaveMeta

func (r *Resource) SetSaveMeta(name string, val any) *XRError

func (*Resource) SetSaveResource

func (r *Resource) SetSaveResource(name string, val any) *XRError

Should only ever be used for "id"

func (*Entity) ShowStack

func (e *Entity) ShowStack()

func SplitProp

func SplitProp(reg *Registry, path string) (string, string)

path.DB() -> abstract.Abstract() + propName.DB()

func SubQuery

func SubQuery(query string, args []interface{}) string

func (*Entity) ToString

func (e *Entity) ToString() string

func (*Entity) Touch

func (e *Entity) Touch() bool

func (*Registry) Update

func (reg *Registry) Update(obj Object, addType AddType) *XRError

func (*Registry) UpsertGroup

func (reg *Registry) UpsertGroup(gType string, id string) (*Group, bool, *XRError)

*Group, isNew, error

func (*Registry) UpsertGroupWithObject

func (reg *Registry) UpsertGroupWithObject(gType string, id string, obj Object, addType AddType) (*Group, bool, *XRError)

func (*Resource) UpsertMeta

func (r *Resource) UpsertMeta(mu *MetaUpsert) (*Meta, bool, *XRError)

returns *Meta, isNew, error "createVersion" means we should create a version if there isn't already one there. This will only happen when the client talks directly to "meta" w/o the surrounding Resource object. AND, for now, we only do it when we're removing the 'xref' attr. Other cases, the http layer would have already create the Resource and default version for us.

func (*Group) UpsertResource

func (g *Group) UpsertResource(ru *ResourceUpsert) (*Resource, bool, *XRError)

Return: *Resource, isNew, error

func (*Resource) UpsertVersion

func (r *Resource) UpsertVersion(id string) (*Version, bool, *XRError)

func (*Resource) UpsertVersionWithObject

func (r *Resource) UpsertVersionWithObject(vu *VersionUpsert) (*Version, bool, *XRError)

*Version, isNew, error

func (*Model) UserMarshal

func (m *Model) UserMarshal(prefix string, indent string) ([]byte, error)

func (*Entity) Validate

func (e *Entity) Validate() *XRError

Doesn't fully validate in the sense that it'll assume read-only fields are not worth checking since the server generated them. This is mainly used for validating input from a client. NOTE!!! This isn't a read-only operation. Normally it would be, but to avoid traversing the entity more than once, we will tweak things if needed. For example, if a missing attribute has a Default value then we'll add it.

func (*Entity) ValidateAndSave

func (e *Entity) ValidateAndSave() *XRError

func (*Entity) ValidateArray

func (e *Entity) ValidateArray(arrayAttr *Attribute, val any, path *PropPath) *XRError

func (*Entity) ValidateAttribute

func (e *Entity) ValidateAttribute(val any, attr *Attribute, path *PropPath) (*XRError, bool, any)

Return: error, haveReplaceValue, newValue

func (*Entity) ValidateMap

func (e *Entity) ValidateMap(val any, item *Item, path *PropPath) *XRError

func (*Entity) ValidateObject

func (e *Entity) ValidateObject(val any, namecharset string, origAttrs Attributes, path *PropPath) *XRError

This should be called after all type-specific calculated properties have been removed - such as collections

func (*Resource) ValidateResource

func (r *Resource) ValidateResource(onlyMetaChanged bool) *XRError

Run all constrait check on the Resource - see:

spec.md#resource-processing-algorithm

func (*Entity) ValidateScalar

func (e *Entity) ValidateScalar(val any, attr *Attribute, path *PropPath) (*XRError, bool, any)

returns: Error, haveReplacementValue, replacementValue

func (*Model) VerifyAndSave

func (m *Model) VerifyAndSave() *XRError

VerifyAndSave() should be called by automatically but there may be cases where someone would need to call it manually (e.g. setting an attribute's property - we should technically find a way to catch those cases so code above this shouldn't need to think about it

func (*ResourceModel) VerifyData

func (rm *ResourceModel) VerifyData() *XRError

func (*Entity) WasTouched

func (e *Entity) WasTouched() bool

func WildcardIt

func WildcardIt(str string) (string, bool)

func (*Resource) WillDelete

func (r *Resource) WillDelete(vID string) *XRError

func (*Registry) XID2Entity

func (r *Registry) XID2Entity(xidStr string, path string) (*Entity, *XRError)

Types

type AddType

type AddType int

Entity "add" options

const (
	ADD_ADD AddType = iota + 1
	ADD_UPDATE
	ADD_UPSERT
	ADD_PATCH // includes UPSERT
)

type BufferedWriter

type BufferedWriter struct {
	Info      *RequestInfo
	OldWriter HTTPWriter
	Headers   *map[string][]string
	Buffer    *bytes.Buffer
}

func NewBufferedWriter

func NewBufferedWriter(info *RequestInfo) *BufferedWriter

func (*BufferedWriter) AddHeader

func (bw *BufferedWriter) AddHeader(name, value string)

func (*BufferedWriter) Done

func (bw *BufferedWriter) Done()

func (*BufferedWriter) GetHeader

func (bw *BufferedWriter) GetHeader(name string) string

func (*BufferedWriter) GetHeaderValues

func (bw *BufferedWriter) GetHeaderValues(name string) []string

func (*BufferedWriter) SetHeader

func (bw *BufferedWriter) SetHeader(name, value string)

func (*BufferedWriter) Write

func (bw *BufferedWriter) Write(b []byte) (int, error)

type CreatedatVersionMode

type CreatedatVersionMode struct{}

func (*CreatedatVersionMode) CheckAncestors

func (vm *CreatedatVersionMode) CheckAncestors(r *Resource) *XRError

func (*CreatedatVersionMode) GetOrderedVersionIDs

func (vm *CreatedatVersionMode) GetOrderedVersionIDs(r *Resource) ([]*VersionAncestor, *XRError)

func (*CreatedatVersionMode) Name

func (vm *CreatedatVersionMode) Name() string

func (*CreatedatVersionMode) NewestVersionID

func (vm *CreatedatVersionMode) NewestVersionID(r *Resource) (string, *XRError)

func (*CreatedatVersionMode) WillDelete

func (vm *CreatedatVersionMode) WillDelete(r *Resource, vID string) *XRError

type DefaultWriter

type DefaultWriter struct {
	Info *RequestInfo
}

func (*DefaultWriter) AddHeader

func (dw *DefaultWriter) AddHeader(name string, value string)

func (*DefaultWriter) Done

func (dw *DefaultWriter) Done()

func (*DefaultWriter) GetHeader

func (dw *DefaultWriter) GetHeader(name string) string

func (*DefaultWriter) GetHeaderValues

func (dw *DefaultWriter) GetHeaderValues(name string) []string

func (*DefaultWriter) SetHeader

func (dw *DefaultWriter) SetHeader(name, value string)

func (*DefaultWriter) Write

func (dw *DefaultWriter) Write(b []byte) (int, error)

type DiscardWriter

type DiscardWriter struct{}

func (*DiscardWriter) AddHeader

func (dw *DiscardWriter) AddHeader(name, value string)

func (*DiscardWriter) Done

func (dw *DiscardWriter) Done()

func (*DiscardWriter) GetHeader

func (dw *DiscardWriter) GetHeader(name string) string

func (*DiscardWriter) GetHeaderValues

func (dw *DiscardWriter) GetHeaderValues(name string) []string

func (*DiscardWriter) SetHeader

func (dw *DiscardWriter) SetHeader(name, value string)

func (*DiscardWriter) Write

func (dw *DiscardWriter) Write(b []byte) (int, error)

type EntityExtensions

type EntityExtensions struct {
	AccessMode int // FOR_READ, FOR_WRITE
	// contains filtered or unexported fields
}

type EntitySetter

type EntitySetter interface {
	Get(name string) any
	JustSet(name string, val any) *XRError
	SetSave(name string, val any) *XRError
	Delete() *XRError
}

type EpochEntry

type EpochEntry map[string]any

type EpochEntryMap

type EpochEntryMap map[string]EpochEntry

type FilterExpr

type FilterExpr struct {
	// User provided
	Path     string // endpoints.id  TODO store a PropPath?
	Value    string // myEndpoint
	Operator int    // FILTER_PRESENT, ...

	// helpers
	Abstract string
	PropName string
}

type FilterPProf

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

func (*FilterPProf) Write

func (fp *FilterPProf) Write(p []byte) (n int, err error)

When dumping all processes, filter out the ones that aren't running our code and only show lines of interest to keep it small

type FormatChecker

type FormatChecker interface {
	IsValid(version *Version) *XRError
	IsCompatible(oldVersion, newVersion *Version) *XRError
}

type FormatJson

type FormatJson struct{}

func (FormatJson) IsCompatible

func (fp FormatJson) IsCompatible(oldVersion *Version, newVersion *Version) *XRError

func (FormatJson) IsValid

func (fp FormatJson) IsValid(version *Version) *XRError

type FormatNumbers

type FormatNumbers struct{}

func (FormatNumbers) IsCompatible

func (ft FormatNumbers) IsCompatible(oldVersion, newVersion *Version) *XRError

func (FormatNumbers) IsValid

func (ft FormatNumbers) IsValid(version *Version) *XRError

type FormatProtobuf

type FormatProtobuf struct{}

func (FormatProtobuf) IsCompatible

func (fp FormatProtobuf) IsCompatible(oldVersion *Version, newVersion *Version) *XRError

checks if both buffers are valid Protobuf schemas and whether newBuf is backwards compatible with oldBuf according to Protobuf wire compatibility rules.

func (FormatProtobuf) IsValid

func (fp FormatProtobuf) IsValid(version *Version) *XRError

IsValid checks if the version is a valid Protobuf schema syntax

type HTTPWriter

type HTTPWriter interface {
	Write([]byte) (int, error)
	SetHeader(string, string)
	AddHeader(string, string)
	GetHeader(string) string
	GetHeaderValues(string) []string
	Done()
}

func DefaultHTTPWriter

func DefaultHTTPWriter(info *RequestInfo) HTTPWriter

type Inline

type Inline struct {
	Path    string    // value from ?inline query param
	PP      *PropPath // PP for 'value'
	NonWild *PropPath // PP for value w/o .* if present, else nil
}

type JsonWriter

type JsonWriter struct {
	Entity *Entity // Current row in the DB results
	// contains filtered or unexported fields
}

func NewJsonWriter

func NewJsonWriter(info *RequestInfo, results *Result) *JsonWriter

func (*JsonWriter) Indent

func (jw *JsonWriter) Indent()

func (*JsonWriter) LoadCollections

func (jw *JsonWriter) LoadCollections(eType int)

func (*JsonWriter) NextEntity

func (jw *JsonWriter) NextEntity() (*Entity, *XRError)

func (*JsonWriter) OptPrintf

func (jw *JsonWriter) OptPrintf(format string, args ...any)

func (*JsonWriter) Outdent

func (jw *JsonWriter) Outdent()

func (*JsonWriter) Pop

func (jw *JsonWriter) Pop() *Entity

func (*JsonWriter) Print

func (jw *JsonWriter) Print(str string)

func (*JsonWriter) Printf

func (jw *JsonWriter) Printf(format string, args ...any)

func (*JsonWriter) Push

func (jw *JsonWriter) Push(e *Entity)

func (*JsonWriter) WriteCollection

func (jw *JsonWriter) WriteCollection() (int, *XRError)

func (*JsonWriter) WriteCollectionHeader

func (jw *JsonWriter) WriteCollectionHeader(extra string) (string, *XRError)

This is called WriteCollectionHeaders because it doesn't just write the collection, it also writes the COLLECTIONSurl and COLLECTIONscount headers/attributes. WriteCollection will do the actual processing of the entities in there.

func (*JsonWriter) WriteEmptyCollection

func (jw *JsonWriter) WriteEmptyCollection(hasXref bool, extra string, eType int, collName string) string

func (*JsonWriter) WriteEntity

func (jw *JsonWriter) WriteEntity() *XRError

func (*JsonWriter) WritePostCollections

func (jw *JsonWriter) WritePostCollections(hasXref bool, extra string, eType int) string

func (*JsonWriter) WritePreCollections

func (jw *JsonWriter) WritePreCollections(hasXref bool, extra string, plural string, eType int) string

type ManualVersionMode

type ManualVersionMode struct{}

func (*ManualVersionMode) CheckAncestors

func (vm *ManualVersionMode) CheckAncestors(r *Resource) *XRError

func (*ManualVersionMode) GetOrderedVersionIDs

func (vm *ManualVersionMode) GetOrderedVersionIDs(r *Resource) ([]*VersionAncestor, *XRError)

func (*ManualVersionMode) Name

func (vm *ManualVersionMode) Name() string

func (*ManualVersionMode) NewestVersionID

func (vm *ManualVersionMode) NewestVersionID(r *Resource) (string, *XRError)

func (*ManualVersionMode) WillDelete

func (vm *ManualVersionMode) WillDelete(r *Resource, vID string) *XRError

type MetaUpsert

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

type PageWriter

type PageWriter struct {
	Info      *RequestInfo
	OldWriter HTTPWriter
	Headers   *map[string][]string
	Buffer    *bytes.Buffer
}

func NewPageWriter

func NewPageWriter(info *RequestInfo) *PageWriter

func (*PageWriter) AddHeader

func (pw *PageWriter) AddHeader(name, value string)

func (*PageWriter) Done

func (pw *PageWriter) Done()

func (*PageWriter) GetHeader

func (pw *PageWriter) GetHeader(name string) string

func (*PageWriter) GetHeaderValues

func (pw *PageWriter) GetHeaderValues(name string) []string

func (*PageWriter) SetHeader

func (pw *PageWriter) SetHeader(name, value string)

func (*PageWriter) Write

func (pw *PageWriter) Write(b []byte) (int, error)

type RegOpt

type RegOpt string

type RequestInfo

type RequestInfo struct {
	Registry         *Registry
	BaseURL          string              // host+path to root of registry
	OriginalPath     string              // /GROUPs/gID...?inline...
	OriginalRequest  *http.Request       `json:"-"`
	OriginalResponse http.ResponseWriter `json:"-"`
	RootPath         string              // "", "model", "export", ...
	Parts            []string            // Split /GROUPS/gID of OriginalPath
	Root             string              // GROUPS/gID/..
	Abstract         string              // /GROUPS/RESOUCES (no IDs)
	GroupType        string
	GroupUID         string
	GroupModel       *GroupModel
	ResourceType     string
	ResourceUID      string
	ResourceModel    *ResourceModel
	VersionUID       string
	What             string            // Registry, Coll, Entity
	Flags            map[string]string // Query params (and str value, if there)
	Ignores          map[string]bool   // key=ignore-value
	Inlines          []*Inline
	Filters          [][]*FilterExpr // [OR][AND] filter=e,e(and) &(or) filter=e
	ShowDetails      bool            //	is $details present
	SortKey          string          // [-]AttrName  - => descending

	StatusCode int
	SentStatus bool
	HTTPWriter HTTPWriter `json:"-"`

	ProxyHost string
	ProxyPath string
	// contains filtered or unexported fields
}

func NewRequestInfo

func NewRequestInfo(w http.ResponseWriter, r *http.Request) *RequestInfo

func (*RequestInfo) APIEnabled

func (info *RequestInfo) APIEnabled(name string) bool

func (*RequestInfo) AddHeader

func (ri *RequestInfo) AddHeader(name, value string)

func (*RequestInfo) AddInline

func (info *RequestInfo) AddInline(path string) *XRError

func (*RequestInfo) DoDocView

func (info *RequestInfo) DoDocView() bool

func (*RequestInfo) FlagEnabled

func (info *RequestInfo) FlagEnabled(name string) bool

func (*RequestInfo) GetFlag

func (info *RequestInfo) GetFlag(name string) string

Get query parameter value

func (*RequestInfo) GetFlagValues

func (info *RequestInfo) GetFlagValues(name string) []string

func (*RequestInfo) GetHeader

func (ri *RequestInfo) GetHeader(name string) string

func (*RequestInfo) GetHeaderValues

func (ri *RequestInfo) GetHeaderValues(name string) []string

func (*RequestInfo) GetParts

func (info *RequestInfo) GetParts(num int) string

func (*RequestInfo) HasFlag

func (info *RequestInfo) HasFlag(name string) bool

func (*RequestInfo) HasIgnore

func (info *RequestInfo) HasIgnore(name string) bool

func (*RequestInfo) IsInlineSet

func (info *RequestInfo) IsInlineSet(entityPath string) bool

func (*RequestInfo) ParseFilters

func (info *RequestInfo) ParseFilters() *XRError

func (*RequestInfo) ParseRegistryURL

func (info *RequestInfo) ParseRegistryURL() *XRError

This will extract the "reg-xxx" part of the URL if there and choose the appropriate Registry to use. It'll update info's BaseURL based on reg- This will populate some initial stuff in the "info" struct too, like Registry.

func (*RequestInfo) ParseRequestPath

func (info *RequestInfo) ParseRequestPath() *XRError

func (*RequestInfo) ParseRequestURL

func (info *RequestInfo) ParseRequestURL() *XRError

func (*RequestInfo) SetHeader

func (ri *RequestInfo) SetHeader(name, value string)

func (*RequestInfo) ShouldInline

func (info *RequestInfo) ShouldInline(entityPath string) bool

func (*RequestInfo) Write

func (ri *RequestInfo) Write(b []byte) (int, error)

type ResourceUpsert

type ResourceUpsert struct {
	RType            string
	Id               string
	VID              string // "versionid" from json
	Obj              Object // json body
	AddType          AddType
	ObjIsVer         bool
	DefaultVersionID string // from ?setdefaultversionid
}

type Result

type Result struct {
	Data     []*any // One row
	TempData []any
	Reuse    bool

	AllRows [][]*any
	// contains filtered or unexported fields
}

func Query

func Query(tx *Tx, cmd string, args ...interface{}) *Result

func (*Result) Close

func (r *Result) Close()

func (*Result) NextRow

func (r *Result) NextRow() []*any

func (*Result) PullNextRow

func (r *Result) PullNextRow()

func (*Result) Push

func (r *Result) Push()

func (*Result) RetrieveAllRowsFromDB

func (r *Result) RetrieveAllRowsFromDB()

func (*Result) RetrieveNextRowFromDB

func (r *Result) RetrieveNextRowFromDB() bool

type Server

type Server struct {
	Port       int
	HTTPServer *http.Server
}

func NewServer

func NewServer(port int) *Server

func (*Server) Close

func (s *Server) Close()

func (*Server) Serve

func (s *Server) Serve()

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Start

func (s *Server) Start() *Server

type Tx

type Tx struct {
	Registry      *Registry
	CreateTime    string // use for entity timestamps too
	User          string
	RequestInfo   *RequestInfo
	ClearFullTree bool

	// Cache of entities this Tx is dealing with. Things can get funky if
	// we have more than one instance of the same entity in memory.
	// TODO DUG expand this to save all types, not just Versions.
	// Also, consider having Commit() just automatically call ValidateAndSave
	// for all entities in the Tx - then people don't need to call save
	// explicitly
	Cache map[string]*Entity // e.Path
	// contains filtered or unexported fields
}

Holds info about the current transaction. In a lot of ways this is similar to golang's Context in that it holds other info related to the current changes that are going on. Maybe one day convert this to a Context where Tx is just as apsect of it.

func (*Tx) AddGroup

func (tx *Tx) AddGroup(g *Group)

func (*Tx) AddMeta

func (tx *Tx) AddMeta(m *Meta)

func (*Tx) AddRegistry

func (tx *Tx) AddRegistry(r *Registry)

func (*Tx) AddResource

func (tx *Tx) AddResource(r *Resource)

func (*Tx) AddToCache

func (tx *Tx) AddToCache(e *Entity)

func (*Tx) AddVersion

func (tx *Tx) AddVersion(v *Version)

func (*Tx) Commit

func (tx *Tx) Commit() *XRError

func (*Tx) Conditional

func (tx *Tx) Conditional(xErr *XRError) *XRError

func (*Tx) DumpCache

func (tx *Tx) DumpCache()

func (*Tx) EraseCache

func (tx *Tx) EraseCache()

func (*Tx) GetGroup

func (tx *Tx) GetGroup(r *Registry, plural string, gID string) *Group

func (*Tx) GetMeta

func (tx *Tx) GetMeta(r *Resource) *Meta

func (*Tx) GetRegistry

func (tx *Tx) GetRegistry(rID string) *Registry

func (*Tx) GetResource

func (tx *Tx) GetResource(g *Group, plural string, rID string) *Resource

func (*Tx) GetVersion

func (tx *Tx) GetVersion(r *Resource, vID string) *Version

func (*Tx) IsCacheDirty

func (tx *Tx) IsCacheDirty() bool

func (*Tx) IsOpen

func (tx *Tx) IsOpen() bool

func (*Tx) NewTx

func (tx *Tx) NewTx() *XRError

It's ok for this to be called multiple times for the same Tx just to make sure we have an active transaction - it's a no-op at that point

func (*Tx) Prepare

func (tx *Tx) Prepare(query string) (*sql.Stmt, *XRError)

func (*Tx) RefreshFullTree

func (tx *Tx) RefreshFullTree()

func (*Tx) RemoveFromCache

func (tx *Tx) RemoveFromCache(e *Entity)

func (*Tx) Rollback

func (tx *Tx) Rollback() *XRError

func (*Tx) SaveAllAndCommit

func (tx *Tx) SaveAllAndCommit() *XRError

func (*Tx) SaveCommitRefresh

func (tx *Tx) SaveCommitRefresh() *XRError

Only call from tests

func (*Tx) String

func (tx *Tx) String() string

func (*Tx) Validate

func (tx *Tx) Validate(info *RequestInfo)

func (*Tx) WriteCache

func (tx *Tx) WriteCache(force bool) *XRError

type UserAttribute

type UserAttribute Attribute

func (*UserAttribute) MarshalJSON

func (ua *UserAttribute) MarshalJSON() ([]byte, error)

type UserGroupModel

type UserGroupModel GroupModel

func (*UserGroupModel) MarshalJSON

func (ug *UserGroupModel) MarshalJSON() ([]byte, error)

type UserModel

type UserModel Model

func (*UserModel) MarshalJSON

func (um *UserModel) MarshalJSON() ([]byte, error)

type UserResourceModel

type UserResourceModel ResourceModel

func (*UserResourceModel) MarshalJSON

func (ur *UserResourceModel) MarshalJSON() ([]byte, error)

type VersionAncestor

type VersionAncestor struct {
	VID       string
	Ancestor  string
	CreatedAt string
	Pos       string // 0-root, 1-middle, 2-leaf
}

type VersionMode

type VersionMode interface {
	Name() string
	CheckAncestors(r *Resource) *XRError
	NewestVersionID(r *Resource) (string, *XRError)
	WillDelete(r *Resource, vID string) *XRError
	GetOrderedVersionIDs(r *Resource) ([]*VersionAncestor, *XRError)
}

type VersionUpsert

type VersionUpsert struct {
	Id               string
	Obj              Object
	AddType          AddType
	More             bool
	DefaultVersionID string
}

Jump to

Keyboard shortcuts

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