Class SchemaManager

SchemaManager class is responsible fo loading registered schemas and to validate data against those schemas.

Hierarchy

  • SchemaManager

Constructors

Properties

_graphSchema?: GraphYmlSchema
_namedEdges: NamedEdge[] = []
_onLoadConnectorsCallback?: ((connectors: QueryConnector[]) => void)

Type declaration

_queriesConnectors?: QueryConnector[]
_schemaBase: string
_schemaItemsLoadPromise?: Promise<void>
_schemaItemsNamesPromise: Record<SchemaItemType, undefined | Promise<string[]>> = ...
_schemaLoadPromise?: Promise<void>
_schemaLoaded: boolean = false
_schemas: SchemasByName = {}
_traitFactory: TraitFactoryCallback
_unionSchema?: SchemaUnion[]
_unionsByName?: Record<string, SchemaUnion>
_v: Validator

Methods

  • Parameters

    • edgeName: string
    • sourceType: string
    • destinationType: string
    • name: string
    • Optional edgeRelationshipName: string

    Returns void

  • Allow traits to alter the union schema.

    This is not a hook because it needs to be done before the traits are fully initialized and have tapped the hooks.

    It iterates over all trait instances on all schemas, and calls traitInstance.alterUnions(type, conf, schemaManager, unions) on each trait instance that has such a method. The pseudo-hook's parameters are documented on the TraitAlterUnions generic interface in Trait.ts.

    Returns void

  • This method is used to check if a vertex property is required, this is used by the GraphConnector to check if a property is required before it can be deleted.

    Returns

    Whether property is required.

    Parameters

    • type: string

      The name of the type

    • fieldname: string

      The name of the field of the entity.

    Returns boolean

  • Returns vertex relationship for a given query connector.

    Example of vertex relationship.

    { vertexName: "Pod", direction: "in/out", relationship: "hasParent", type: "oneToOne", required: true inverse:"", }

    Parameters

    • ownVertexName: string

      An own vertex name.

    • connector: QueryConnector
    • direction: "in" | "out"

      Direction of the edge to the vertex in/out.

    Returns null | VertexRelationship

  • Finalizes the schema and properties metadata for all schema items.

    TODO: Make this method protected, call it in loadSchemas(). TODO:

    See

    GraphQLSchemaManager.generateGraphQLSchemaString().

    Returns void

  • Get all the definitions needed for finding the ancestors of a vertex type.

    Returns an object with possible ancestor vertex types as keys, and their parent rule definition arrays as values.

    Parameters

    • vertex: string
    • known: string[] = []

    Returns ParentsDefinitions

  • Returns previously loaded schema item for a given item type.

    TODO: Make this method private, expose separate methods for edge and vertex instead.

    Returns

    The SchemaItem object.

    Type Parameters

    Parameters

    • type: string

      Item type.

    • strict: boolean = true

      throw an error if there is no such schema. Default is true.

    Returns SchemaItem<ItemType>

  • This method is used to get the plural of a vertex, it checks if one has been defined as part of the definition and if not we add an s

    Parameters

    • name: string

    Returns string

  • Returns a list of types that a union contains, otherwise undefined

    Returns

    The types that the union contains

    Parameters

    • name: string

      Name of the union to locate

    Returns undefined | [string, ...string[]]

  • This is used to find the Node relationships required for a node to be created, this is defined in the relationship as requried. see graph.json

    Parameters

    • vertexName: string

      Vertex / entity type label.

    • include: "inverse" | "both" | "direct" = 'direct'

      Whether to include inverse connections.

    Returns VertexRelationship[]

  • Initialize traits by calling the initializeTraits() method on each schema.

    Returns void

  • Returns a list of the Edge schemas names

    Deprecated

    use listSchemaItemsNames() instead.

    Returns Promise<string[]>

  • Retrieves a list of Edges on which a trait is enabled.

    Parameters

    • name: string

    Returns string[]

  • Return a list of the vertex schema as and array

    Deprecated

    use listSchemaItemsNames() instead.

    Returns Promise<string[]>

  • Retrieves a list of Vertices on which a trait is enabled.

    Parameters

    • name: string

    Returns string[]

  • This method is used to load the graph.yml file from the filesystem.

    The graph.yml file contains the allowed vertices and edges/releationships that can be added to the graph. The actual definitions of each vertex are described in a seperate JSON schema file as are the edges/releationships.

    Returns Promise<void>

  • Loads schemas configuration.

    This method should be called to initialize the schema manager.

    Returns Promise<void>

  • Set the union schema.

    Use this instead of just assigning the property to avoid breaking external references.

    Parameters

    Returns void

  • This method is used to validate json data against a named schema against and schema type.

    Parameters

    • schema_name: string

      Name of the schema to use for the validation.

    • data: any

      JSON data to be validated

    • schema_type: SchemaItemType

      The type of schema Edge/schema

    • action: SchemaValidationAction

      The action to perform.

    Returns boolean

  • This method is used to validate json data structure against the defined schema for the named edge.

    Throws

    Error if schema is not valid.

    Parameters

    • schema_name: string
    • data: any
    • action: SchemaValidationAction

    Returns boolean

  • This method is used to validate json data structure against the defined schema for the named vertex.

    Throws

    Error if schema is not valid.

    Parameters

    • schema_name: string
    • data: any
    • action: SchemaValidationAction

    Returns boolean

  • Checks if given vertex type matches expected vertex or enum schema type.

    Parameters

    • type: string

      vertex type name

    • expected: string

      expected vertex or union type

    Returns boolean

Generated using TypeDoc