Class DataObjectsTrait

The DataObjectsTrait is used to enable a specified property of a vertex to to be parsed for html objects, if the html objects have been defined as part of the trait configuration (see below) an edge will be added to the targeted vertex, below is an example of a HTML Object that can be parsed by this Trait and defines two data objects that can be managed.

Example HTML:

<object
data-klarity-widget-type="mention"
data-klarity-widget-data="{'id':'aebe2fcc-e69c-8a64-819d-f370f3988ece'}">
</object>

Usage:

traits:
- type: data_objects
targetProperty:
- body
typeAttributeName: data-klarity-widget-type
dataAttributeName: data-klarity-widget-data
objects:
- dataObjectType: mention
edgeType: mentions
targetVertexType: User
- dataObjectType: answer
edgeType: usesAnswer
targetVertexType: Answer
- dataObjectType: hashtag
edgeType: hasTag
targetVertexType: Tag
targetVertexFilter: vocabulary.machine_name:hashtag

Hierarchy

Constructors

Properties

Trait instance configuration.

_dataAttributeName?: string
_dataSourceWrapper: DataSourceWrapper
_edges?: string[]
_global: boolean = false

Whether this is a global (not bound to any specific schema item) trait instance.

_objects?: DataObjectConfig[]
_schemaManager: SchemaManager
_targetProperties?: {
    property: string;
    rawProperty: string;
    subProperty?: string;
}[]
_targetVertexFilters?: string[]
_targetVertices?: string[]
_type?: "data_objects"

Trait type.

_typeAttributeName?: string
_types?: string[]

Methods

  • This function is used to validate the target and add the defined edge between the current entity and the target.

    Parameters

    • traitData: TraitDataObject<unknown, Record<string, any>, Promise<any>>
    • item: any
    • context: KosmosUserContext<object>
    • targetId: string
    • targetType: string
    • targetProperty: PropertyObject

    Returns Promise<void>

  • This method is used to extract the html objects which have been included in filedData string. It returns a map of arrays of the data contained in the string.

    Parameters

    • Optional fieldData: string

    Returns any[]

  • This function is used to retrieve the argument property and checks if a sub property has been defined and return that in a list for each defined property.

    Parameters

    Returns PropertyObject[]

  • This function is used to retrieve the argument property and checks if a sub property has been defined and return that.

    Parameters

    • traitData: TraitDataObject<unknown, Record<string, any>, Promise<any>>
    • property: string
    • Optional subProperty: string

    Returns undefined | string

  • This function is used to get a list of defined edges that exist between the source entity and the target entity type.

    Parameters

    • traitData: TraitDataObject<unknown, Record<string, any>, Promise<any>>
    • item: any
    • property: string

    Returns Promise<any[]>

  • This function is the preCreate and will be called before the entity is created, to prevent the preUpdate and postUpdate being called on a create (which can happen due to interaction with other traits).

    Parameters

    Returns void

  • This method is triggered when a trait callback has been activated

    Type Parameters

    • RT = any

    • Payload = any

    Parameters

    • callbackName: string

      This is the name of the callback function to call.

    • datasourceWrapper: DataSourceWrapper

      References to the Graph Hanlder

    • data: TraitDataObject<RT, Payload, Promise<any>>

      Request data passed along as part of the request.

    Returns Promise<RT>

  • This function is used to check that a defined edge exists between the source entity and the target exists and to then delete the edge.

    Parameters

    Returns Promise<void>

Generated using TypeDoc