Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultBuildNodeKeyFunc(node graph.Node) (string, bool, error)
- func Export(node graph.Node, options ExportOptions) (jsonom.Node, error)
- func GetBuildNodeKeyBySchemaNodeFunc(f func(schemaNode, docNode graph.Node) (string, bool, error)) func(graph.Node) (string, bool, error)
- func IngestBytes(context *ls.Context, ingester *Ingester, baseID string, input []byte) (graph.Node, error)
- func IngestStream(context *ls.Context, ingester *Ingester, baseID string, input io.Reader) (graph.Node, error)
- type CompiledEntity
- type Entity
- type EntityLayer
- type ErrCyclicSchema
- type ErrInvalidBooleanValue
- type ErrValueExpected
- type ExportOptions
- type Ingester
Constants ¶
const JSON = "https://json.org#"
JSON namespace
const X_LS = "x-ls"
Variables ¶
var ( StringTypeTerm = ls.NewTerm(JSON, "string", false, false, ls.OverrideComposition, nil) NumberTypeTerm = ls.NewTerm(JSON, "number", false, false, ls.OverrideComposition, nil) IntegerTypeTerm = ls.NewTerm(JSON, "integer", false, false, ls.OverrideComposition, nil) BooleanTypeTerm = ls.NewTerm(JSON, "boolean", false, false, ls.OverrideComposition, nil) ObjectTypeTerm = ls.NewTerm(JSON, "object", false, false, ls.OverrideComposition, nil) ArrayTypeTerm = ls.NewTerm(JSON, "array", false, false, ls.OverrideComposition, nil) )
JSON related vocabulry
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 graph.Node) (string, bool, error)) func(graph.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
Types ¶
type CompiledEntity ¶
type CompiledEntity struct {
Entity
Schema *jsonschema.Schema
}
CompiledEntity contains the JSON schema for the entity
func CompileEntities ¶
func CompileEntities(entities ...Entity) ([]CompiledEntity, error)
CompileEntities compiles given entities
func CompileEntitiesWith ¶
func CompileEntitiesWith(compiler *jsonschema.Compiler, entities ...Entity) ([]CompiledEntity, error)
CompileEntitiesWith compiles all entities as a single json schema unit using the given compiler
type Entity ¶
type Entity struct {
// Reference to the schema
Ref string `json:"ref" bson:"ref" yaml:"ref"`
// ID of the entity
ID string `json:"id" bson:"id" yaml:"id"`
// ID of the layer that will be generated
LayerID string `json:"layerId" bson:"layerId" yaml:"layerId"`
}
Entity defines a location in the schema as an entity
func FindEntityByID ¶
FindEntityByID finds the entity by ID value
func FindEntityByRef ¶
FindEntityByRef finds the entity by ref value
type EntityLayer ¶
type EntityLayer struct {
Entity CompiledEntity
Layer *ls.Layer `json:"-"`
}
EntityLayer contains the layer for the entity
func BuildEntityGraph ¶
func BuildEntityGraph(typeTerm string, entities ...CompiledEntity) ([]EntityLayer, error)
BuildEntityGraph imports JSON schemas or overlays
A JSON schema may include many object definitions. This import algorithm creates a layer for each entity.
typeTerm should be either ls.SchemaTerm or ls.OverlayTerm
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(graph.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 Ingester ¶
Ingester converts a JSON object model into a graph using a schema
func (*Ingester) Ingest ¶
func (ingester *Ingester) Ingest(context *ls.Context, baseID string, input jsonom.Node) (graph.Node, error)
Ingest a json document using the schema. The output will have all input nodes associated with schema nodes. The ingested object is a single instance of an entity.
BaseID is the ID of the root object. All other attribute names are generated by appending the attribute path to baseID. BaseID is only used if the schema does not explicitly specify an ID