Class AliasTrait

The URLAlias module manages the lifecycle of an entity's URL aliases. Lifecycle hooks such as:

  • preCreate
  • postCreate
  • preUpdate
  • postUpdate
  • postDelete

It provides granular control over alias creation, updates, and deletion. This ensures that each alias remains associated with its intended content while providing flexibility for dynamic URL restructuring.

Usage:

traits:
- type: alias
field: url_alias

Hierarchy

Constructors

Properties

Trait instance configuration.

_dataSourceWrapper: DataSourceWrapper
_global: boolean = false

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

_graphqlSchemaManager: GraphQLSchemaManager
_runtimeConfig: RuntimeConfig
_schemaManager: SchemaManager
_type?: "alias"

Trait type.

field: undefined | string
logger: Logger
tablename: string

Methods

  • This internal function is used to retrieve an alias for a tenant

    Returns

    Parameters

    • tenant: string

      This is the users tenant id.

    • alias: string

      This is the url alias.

    Returns Promise<boolean>

  • This internal function is used to create an alias for a tenant.

    Returns

    Parameters

    • tenant: string

      This is the users tenant id.

    • alias: string

      This is the url alias.

    • uuid: string

      This is the uuid of the entity.

    • type: string

      This is the type of the entity.

    Returns Promise<void>

  • This internal function is used to delete all aliases for a specified entity uuid, its used a DynamoDB GSI to find all the aliases for the entity.

    Parameters

    • tenant: string

      This is the users tenant id.

    • uuid: string

      This is the uuid of the entity.

    Returns Promise<void>

  • Extracts the URL part from a string in the format 'uuid#url'.

    Returns

    • The extracted URL part of the input string. If the input string does not contain '#', it returns an empty string.

    Parameters

    • inputString: string

      The input string containing a UUID and a URL separated by '#'.

    Returns string

  • This internal function is used to retrieve an alias for a tenant

    Returns

    Parameters

    • tenant: string

      This is the users tenant id.

    • uuid: string

      This is the id of the entity.

    Returns Promise<undefined | string>

  • This internal function is used to validate the path of the alias.

    Returns

    boolean

    Parameters

    • path: string

      The path to validate.

    Returns boolean

  • If the alias field has been updated then a new create the Alias entry

    Returns

    Parameters

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

      Used by traits for non user accessible entities

    • item: Record<string, any>

      The item being updated.

    • _legacyDatasourceWrapper: DataSourceWrapper

      Not used

    • context: KosmosUserContext<object>

      The user context.

    Returns Promise<void>

  • Check if the alias has been populated, skip if empty, if not then ensure that the new alias does not conflict with existing ones.

    • Validate the format and structure of the alias to make sure it conforms to your desired pattern.

    • Check the DynamoDB table to ensure the alias doesn't already exist for the current tenant.

    Parameters

    Returns Promise<void>

  • Check if the alias field has been changed, if so:

    • Validate the format and structure of the alias to make sure it conforms to your desired pattern.

    • Check the DynamoDB table to ensure the alias doesn't already exist for the current tenant.

    Returns

    Parameters

    Returns Promise<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 as a resolver for the alias field.

    NOTE: This function is not used in the current implementation. It's currently disabled as the postView hook is used to populate the alias, this is due to how the AncestorTrait retrieves data via the findVertex function.

    Parameters

    Returns Promise<null | string>

Generated using TypeDoc