Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultBuildNodeKeyFunc(node ls.Node) (string, bool, error)
- func Export(node ls.Node, options ExportOptions) (jsonom.Node, error)
- func GetBuildNodeKeyBySchemaNodeFunc(f func(schemaNode, docNode ls.Node) (string, bool, error)) func(ls.Node) (string, bool, error)
- func GetBuildNodeKeyExprFunc(closure gl.Closure) func(ls.Node) (string, bool, error)
- func IngestBytes(ingester *Ingester, baseID string, input []byte) (ls.Node, error)
- func IngestStream(ingester *Ingester, baseID string, input io.Reader) (ls.Node, error)
- type CompiledEntity
- type Entity
- type ErrCyclicSchema
- type ErrInvalidBooleanValue
- type ErrValueExpected
- type ExportOptions
- type ImportedEntity
- type Ingester
Constants ¶
const JSON = "https://json.org#"
Variables ¶
var ArrayTypeTerm = ls.NewTerm(JSON+"array", false, false, ls.OverrideComposition, nil)
var BooleanTypeTerm = ls.NewTerm(JSON+"boolean", false, false, ls.OverrideComposition, nil)
var IntegerTypeTerm = ls.NewTerm(JSON+"integer", false, false, ls.OverrideComposition, nil)
var NumberTypeTerm = ls.NewTerm(JSON+"number", false, false, ls.OverrideComposition, nil)
var ObjectTypeTerm = ls.NewTerm(JSON+"object", false, false, ls.OverrideComposition, nil)
var StringTypeTerm = ls.NewTerm(JSON+"string", false, false, ls.OverrideComposition, nil)
Functions ¶
func DefaultBuildNodeKeyFunc ¶
DefaultBuildNodeKeyFunc returns the attribute name term property from the node if it exists. If not, it looks at the attributeName of the node reached by instanceOf edge. If none found it return false
func Export ¶
Export the document subtree to the target. The returned result is OM, which respects element ordering
func GetBuildNodeKeyBySchemaNodeFunc ¶
func GetBuildNodeKeyBySchemaNodeFunc(f func(schemaNode, docNode ls.Node) (string, bool, error)) func(ls.Node) (string, bool, error)
GetBuildNodeKeyBySchemaNodeFunc returns a function that gets the schema node and the doc node. If the doc node does not have a schema node, it is not exported. The function `f` should decide what key to use
func GetBuildNodeKeyExprFunc ¶
GetBuildNodeKeyExprFunc returns a function that builds node keys using an expression. The expression should be a closure getting a node argument
func IngestBytes ¶
IngestBytes ingests JSON bytes
Types ¶
type CompiledEntity ¶
type CompiledEntity struct {
Entity
Schema *jsonschema.Schema
}
CompiledEntity contains the JSON schema for the entity
func Compile ¶
func Compile(entities []Entity) ([]CompiledEntity, error)
Compile all entities as a single unit.
func CompileWith ¶
func CompileWith(compiler *jsonschema.Compiler, entities []Entity) ([]CompiledEntity, error)
CompileWith compiles all entities as a single unit using the given compiler
type Entity ¶
type Entity struct {
Name string `json:"name"`
Ref string `json:"ref"`
ID string `json:"id"`
SchemaName string `json:"schema"`
}
Entity gives an entity name to a location in a schema
func (Entity) GetEntityName ¶
GetEntityName returns the ID if name is empty
type ErrCyclicSchema ¶
type ErrCyclicSchema struct {
Loop []*jsonschema.Schema
}
func (ErrCyclicSchema) Error ¶
func (e ErrCyclicSchema) Error() string
type ErrInvalidBooleanValue ¶
func (ErrInvalidBooleanValue) Error ¶
func (e ErrInvalidBooleanValue) Error() string
type ErrValueExpected ¶
type ErrValueExpected struct {
NodeID string
}
func (ErrValueExpected) Error ¶
func (e ErrValueExpected) Error() string
type ExportOptions ¶
type ExportOptions struct {
// BuildNodeKeyFunc builds a node key from the node
BuildNodeKeyFunc func(ls.Node) (string, bool, error)
// If ExportTypeProperty is set, exports "@type" properties that
// have non-LS related types
ExportTypeProperty bool
}
ExportOptions are used to produce the output from the document
func (ExportOptions) BuildNodeKey ¶
type ImportedEntity ¶
type ImportedEntity struct {
Entity CompiledEntity
Layer *ls.Layer `json:"-"`
}
func CompileAndImport ¶
func CompileAndImport(entities []Entity) ([]ImportedEntity, error)
CompileAndImport compiles the given entities and imports them as layers
func Import ¶
func Import(entities []CompiledEntity) ([]ImportedEntity, error)
Import a JSON schema
A JSON schema may include many object definitions. This import algorithm creates a schema for each entity.
type Ingester ¶
Ingester converts a JSON object model into a graph using a schema