dom

package
v0.0.0-...-86a089b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2019 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package dom provides code for domain model declaration and registration.

Models are the primary focus of this package, they are used to define the bits, enum and object schema types as well as service contracts. In addition to the schema type information, models hold meta data for display, indexing, constraints and other application relevant aspects.

Models are always part of a named schema and multiple schemas are usually represented and used as a project. A model can refer to models in other previously declared schemas within a project.

Models should be used for any data that crosses environments, such as persisted data used in both the database and program environment or protocol data used to communicate between processes.

Models, schemas and projects have a JSON representations that can be sent to clients. Models can have basic validation hints, but more detailed display and form logic should always use another layer.

Easy filtering of all project parts is important for hiding irrelevant or restricted data in different environments or even on a per-connection basis to hide sensitive information for roles without permission.

Models need to describe references to establish model and schema dependencies. The project might be a good place to collect some facts about model and schema references.

Using models to describe service contracts and their arguments documents the service and lets us automatically read and route requests, and generally generate code based on it.

Index

Constants

View Source
const (
	RelA1 Rel = 1 << iota // one a
	RelAN                 // many a
	RelB1                 // one b
	RelBN                 // many b

	RelEmbed   // b embedded in a
	RelRelax   // relaxed integrity checks, b might not yet be declared
	RelInter   // relation has an intermediate model, optionally with extra data
	RelReverse // reversed relation

	Rel11  = RelA1 | RelB1 // one a to one b
	Rel1N  = RelA1 | RelBN // one a to many b
	RelN1  = RelAN | RelB1 // many a to one b
	RelNN  = RelAN | RelBN // many a to many b
	RelR11 = Rel11 | RelReverse
	RelRN1 = Rel1N | RelReverse
	RelR1N = RelN1 | RelReverse
	RelRNN = RelNN | RelReverse
)

Variables

View Source
var Env = exp.Builtin{
	utl.StrLib.Lookup(),
	utl.TimeLib.Lookup(),
	std.Core, std.Decl,
}

Functions

func Read

func Read(r io.Reader, env exp.Env, pr *Project) error

Types

type Bit

type Bit uint64

Bit is a bit set used for a number of field options.

const (
	BitOpt Bit = 1 << iota
	BitPK
	BitIdx
	BitUniq
	BitOrdr
	BitAuto
	BitRO
)

func (Bit) Bits

func (Bit) Bits() map[string]int64

type Common

type Common struct {
	Name  string    `json:"name,omitempty"`
	Extra *lit.Dict `json:"extra,omitempty"`
}

Common represents the common name and version of model, schema or project nodes.

func (*Common) Key

func (c *Common) Key() string

type ConstElem

type ConstElem struct {
	*typ.Const
	*Elem
}

type Elem

type Elem struct {
	Bits  Bit       `json:"bits,omitempty"`
	Extra *lit.Dict `json:"extra,omitempty"`
	Ref   string    `json:"ref,omitempty"`
}

Elem holds additional information for either constants or type paramters.

type FieldElem

type FieldElem struct {
	*typ.Param
	*Elem
}

type Index

type Index struct {
	Name   string   `json:"name,omitempty"`
	Keys   []string `json:"keys"`
	Unique bool     `json:"unique,omitempty"`
}

Index represents a record model index, mainly used for databases.

type Model

type Model struct {
	Common
	Type   typ.Type `json:"type"`
	Elems  []*Elem  `json:"elems,omitempty"`
	Object *Object  `json:"object,omitempty"`
	Schema string   `json:"schema,omitempty"`
}

Model represents either a bits, enum or record type and has extra domain information.

func (*Model) Const

func (m *Model) Const(key string) ConstElem

Const returns a constant element for key or nil.

func (*Model) Field

func (m *Model) Field(key string) FieldElem

Field returns a field element for key or nil.

func (*Model) FromDict

func (m *Model) FromDict(d *lit.Dict) (err error)

func (*Model) Qual

func (m *Model) Qual() string

func (*Model) Qualified

func (m *Model) Qualified() string

func (*Model) String

func (m *Model) String() string

func (*Model) WriteBfr

func (m *Model) WriteBfr(b *bfr.Ctx) error

type ModelEnv

type ModelEnv struct {
	*SchemaEnv
	Model *Model
}

ModelEnv wraps a schema env and resolves previously declared fields or constants.

func (*ModelEnv) Get

func (r *ModelEnv) Get(sym string) *exp.Def

type ModelRef

type ModelRef struct {
	*Model
	Key string
}

ModelRef is a model pointer with an optional field key.

func (ModelRef) String

func (r ModelRef) String() string

type ModelRels

type ModelRels struct {
	*Model
	Out, In, Via []Relation
}

ModelRels contains outgoing, incoming, and intermediate relationships for a model.

func (ModelRels) String

func (r ModelRels) String() string

type Node

type Node interface {
	Qualified() string
	String() string
	WriteBfr(b *bfr.Ctx) error
}

type Object

type Object struct {
	Indices []*Index `json:"indices,omitempty"`
	OrderBy []string `json:"orderby,omitempty"`
}

Object holds data specific to object types for grouping.

type Project

type Project struct {
	Common
	Schemas []*Schema `json:"schemas"`
}

Project is a collection of schemas and is the central place for any extra project configuration.

The schema definition can either be declared as part of the project file, or included from an external schema file. Includes should have syntax to filtering the included schema definition.

Extra setting, usually include, but are not limited to, targets and output paths for code generation, paths to look for the project's manifest and history.

func (*Project) FromDict

func (p *Project) FromDict(d *lit.Dict) (err error)

func (*Project) Model

func (p *Project) Model(key string) *Model

Model returns a model for the qualified key or nil.

func (*Project) Qualified

func (p *Project) Qualified() string

func (*Project) Schema

func (p *Project) Schema(key string) *Schema

Schema returns a schema for key or nil.

func (*Project) String

func (p *Project) String() string

func (*Project) WriteBfr

func (p *Project) WriteBfr(b *bfr.Ctx) error

type ProjectEnv

type ProjectEnv struct {
	*Project
	// contains filtered or unexported fields
}

ProjectEnv is a root environment that allows schema declaration or model resolution.

func FindEnv

func FindEnv(env exp.Env) *ProjectEnv

func NewEnv

func NewEnv(parent exp.Env, project *Project) *ProjectEnv

func (*ProjectEnv) Get

func (s *ProjectEnv) Get(sym string) *exp.Def

func (*ProjectEnv) Parent

func (s *ProjectEnv) Parent() exp.Env

func (*ProjectEnv) Supports

func (s *ProjectEnv) Supports(x byte) bool

type Rel

type Rel uint64

Rel is a bit-set describing the kind of relationship between two models referred to as a and b.

type Relation

type Relation struct {
	Rel
	A, B, Via ModelRef
}

Relation links two models a and b, optionally via a third intermediate model.

func (Relation) String

func (r Relation) String() string

type Relations

type Relations map[string]*ModelRels

Relations maps qualified model names to a collection of all relations for that model.

func Relate

func Relate(pro *Project) (Relations, error)

Relate collects and returns all relations between the models in the given project or an error.

type Schema

type Schema struct {
	Common
	Path   string   `json:"path,omitempty"`
	Use    []string `json:"use,omitempty"`
	Models []*Model `json:"models"`
}

Schema is a namespace for models.

func Execute

func Execute(env exp.Env, r io.Reader) (*Schema, error)

func ExecuteString

func ExecuteString(env exp.Env, s string) (*Schema, error)

func (*Schema) FromDict

func (s *Schema) FromDict(d *lit.Dict) (err error)

func (*Schema) Model

func (s *Schema) Model(key string) *Model

Model returns a model for key or nil.

func (*Schema) Qualified

func (s *Schema) Qualified() string

func (*Schema) String

func (s *Schema) String() string

func (*Schema) WriteBfr

func (s *Schema) WriteBfr(b *bfr.Ctx) error

type SchemaEnv

type SchemaEnv struct {
	Schema *Schema
	// contains filtered or unexported fields
}

SchemaEnv is used inside schema definitions and resolves previously declared models.

func (*SchemaEnv) Get

func (r *SchemaEnv) Get(sym string) *exp.Def

func (*SchemaEnv) Parent

func (s *SchemaEnv) Parent() exp.Env

func (*SchemaEnv) Supports

func (s *SchemaEnv) Supports(x byte) bool

Directories

Path Synopsis
Package domtest has default schemas and helpers for testing.
Package domtest has default schemas and helpers for testing.

Jump to

Keyboard shortcuts

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