Options
All
  • Public
  • Public/Protected
  • All
Menu

Mygra

Index

Type aliases

ConnectionHandler

ConnectionHandler: (...args: any[]) => Promise<boolean>

Type declaration

    • (...args: any[]): Promise<boolean>
    • Parameters

      • Rest ...args: any[]

      Returns Promise<boolean>

CreateMigrationHandler

CreateMigrationHandler: (options: IMigrationOptions) => string

Type declaration

Event

Event: typeof EVENTS[number]

Events

Events: Record<keyof Event, ((...args: any[]) => void)[]>

MigrateDirection

MigrateDirection: "up" | "down"

Variables

Const APP_PKG

APP_PKG: Record<string, any> = ...

Const EVENTS

EVENTS: readonly ["created", "filtered", "loaded", "migration", "up", "down", "active", "revert"] = ...

Const MYGRA_CONFIG_DIR

MYGRA_CONFIG_DIR: string = ...

Const MYGRA_CONFIG_PATH

MYGRA_CONFIG_PATH: string = ...

Const MYGRA_DEFAULTS

MYGRA_DEFAULTS: IMygraConfig = ...

Const MYGRA_DEFAULT_PATH

MYGRA_DEFAULT_PATH: string = ...

Const PKG

PKG: Record<string, any> = ...

Functions

colorize

  • colorize(str: string, ...styles: keyof StylesType<any>[]): string
  • Colorizes a string with ansi colors.

    Parameters

    • str: string

      the string to be colorized.

    • Rest ...styles: keyof StylesType<any>[]

      the styles to be applied.

    Returns string

    a ansi colorized string.

colorizeError

  • colorizeError(err: Error): Error & { colorizedMessage: string; colorizedStack: string }
  • Makes errors more readable.

    Parameters

    • err: Error

      the error to addd colorization to.

    Returns Error & { colorizedMessage: string; colorizedStack: string }

defineActive

  • Helper to format the last or active migration for storage.

    Parameters

    Returns [string, MigrateDirection]

    a tuple containing last migration and direction.

defineReverts

findIndex

  • findIndex(values: string[], pattern: string | RegExp): number
  • Finds the index of a matched element in an array.

    Parameters

    • values: string[]

      the string values to inspect.

    • pattern: string | RegExp

      the pattern used for matching.

    Returns number

    the index of a matched element.

getBaseName

  • getBaseName(filepath: string, includeExt?: boolean): string
  • Gets the base name of a file path with or without file extension.

    Parameters

    • filepath: string

      the full path to the file.

    • includeExt: boolean = false

      when true the file extension is retained.

    Returns string

    the filename only from the specified path.

initConfig

  • initConfig<T>(name?: any, directory?: string): { defaults: (initDefaults?: Partial<T>) => void; directory: string; filename: string; fullpath: string; get: (key: string) => any; save: (noPrune?: boolean) => void; set: { (key: string, value: any): void; (obj: Partial<T>): any }; update: (obj: Partial<T>) => void; get props(): {} }
  • Type parameters

    • T: Record<string, any>

    Parameters

    • name: any = ...

      the name of the config to create.

    • directory: string = ...

      the directory where the config is to be stored.

    Returns { defaults: (initDefaults?: Partial<T>) => void; directory: string; filename: string; fullpath: string; get: (key: string) => any; save: (noPrune?: boolean) => void; set: { (key: string, value: any): void; (obj: Partial<T>): any }; update: (obj: Partial<T>) => void; get props(): {} }

    • defaults: (initDefaults?: Partial<T>) => void
        • (initDefaults?: Partial<T>): void
        • Initialize the configuration merging defaults.

          Parameters

          • initDefaults: Partial<T> = ...

          Returns void

    • directory: string
    • filename: string
    • fullpath: string
    • get: (key: string) => any
        • (key: string): any
        • Gets a key's value from config store.

          Parameters

          • key: string

            the get to get.

          Returns any

    • save: (noPrune?: boolean) => void
        • (noPrune?: boolean): void
        • Parameters

          • Optional noPrune: boolean

          Returns void

    • set: { (key: string, value: any): void; (obj: Partial<T>): any }
        • (key: string, value: any): void
        • (obj: Partial<T>): any
        • Sets key value in config store.

          Parameters

          • key: string

            the key to be set.

          • value: any

            the value to be set for key.

          Returns void

        • Sets all keys in the provided object.

          Parameters

          • obj: Partial<T>

            updates entire object.

          Returns any

    • update: (obj: Partial<T>) => void
        • (obj: Partial<T>): void
        • Updates config only for known keys.

          Parameters

          • obj: Partial<T>

            the config object to update from.

          Returns void

    • get props(): {}

isMatch

  • isMatch(value: string, pattern: string | RegExp): boolean
  • Inspects a string matching by supplied pattern.

    Parameters

    • value: string

      the value to inspect.

    • pattern: string | RegExp

      a pattern to check for matching.

    Returns boolean

    a boolean indicating if the value matches pattern.

isPromise

  • isPromise<T>(value: unknown): value is Promise<T>
  • Checks if the value is a promise.

    Type parameters

    • T = any

    Parameters

    • value: unknown

      the value to inspect as a promise.

    Returns value is Promise<T>

promisifyMigration

  • promisifyMigration(fn: (conn: any, cb?: (err?: Error, data?: any) => void) => any): (conn: any) => Promise<unknown>
  • Parameters

    • fn: (conn: any, cb?: (err?: Error, data?: any) => void) => any
        • (conn: any, cb?: (err?: Error, data?: any) => void): any
        • Parameters

          • conn: any
          • Optional cb: (err?: Error, data?: any) => void
              • (err?: Error, data?: any): void
              • Parameters

                • Optional err: Error
                • Optional data: any

                Returns void

          Returns any

    Returns (conn: any) => Promise<unknown>

      • (conn: any): Promise<unknown>
      • Parameters

        • conn: any

        Returns Promise<unknown>

readFileAsync

  • readFileAsync(path: string): Promise<string>
  • Reads a file asynchronously.

    Parameters

    • path: string

      the path to be read.

    Returns Promise<string>

    a file as string.

readJSONSync

  • readJSONSync<T>(path: string, defaults?: T): T
  • Reads JSON returning as a parsed object of specified type.

    Type parameters

    • T = Record<string, any>

    Parameters

    • path: string

      the path to be read.

    • defaults: T = ...

      defaults to use when not found.

    Returns T

    a JSON parsed object.

writeFileAsync

  • writeFileAsync(path: string, data: string | object): Promise<boolean>
  • Writes a file asynchronously.

    Parameters

    • path: string

      the path to write to.

    • data: string | object

      the data to be written.

    Returns Promise<boolean>

    a boolean indicating if successful write.

Generated using TypeDoc