Skip to main content
Version: Next

Utils

Index

Constructors

constructor

Properties

staticreadonlyPK_SEPARATOR

PK_SEPARATOR: ~~~ = '~~~'

Methods

staticasArray

  • asArray<T>(data, strict): T[]
  • Normalize the argument to always be an array.


    Parameters

    • optionaldata: T | readonly T[] | Iterable<T, any, any>
    • strict: boolean = false

    Returns T[]

staticcallCompiledFunction

  • callCompiledFunction<T, R>(fn, ...args): R
  • Parameters

    • fn: (...args) => R
      • rest...args: T

      Returns R

    staticclassName

    • className<T>(classOrName): string
    • Gets string name of given class.


      Parameters

      Returns string

    staticcopy

    • copy<T>(entity, respectCustomCloneMethod): T
    • Creates deep copy of given object.


      Parameters

      • entity: T
      • respectCustomCloneMethod: boolean = true

      Returns T

    staticcreateFunction

    • createFunction(context, code): any
    • Parameters

      • context: Map<string, any>
      • code: string

      Returns any

    staticdefaultValue

    • defaultValue<T>(prop, option, defaultValue): void
    • Parameters

      • prop: T
      • option: keyof T
      • defaultValue: any

      Returns void

    staticdetectTypeScriptSupport

    • detectTypeScriptSupport(): boolean
    • Tries to detect TypeScript support.


      Returns boolean

    staticdropUndefinedProperties

    • dropUndefinedProperties(o, value, visited): void
    • Removes undefined properties (recursively) so they are not saved as nulls


      Parameters

      • o: any
      • optionalvalue: null
      • visited: Set<unknown> = ...

      Returns void

    staticentries

    • entries<T>(obj): [keyof T, T[keyof T]][]
    • Parameters

      • obj: T

      Returns [keyof T, T[keyof T]][]

    staticequals

    • equals(a, b): boolean
    • Checks if arguments are deeply (but not strictly) equal.


      Parameters

      • a: any
      • b: any

      Returns boolean

    staticextractChildElements

    • extractChildElements(items, prefix, allSymbol): string[]
    • Parameters

      • items: string[]
      • prefix: string
      • optionalallSymbol: string

      Returns string[]

    staticextractEnumValues

    • extractEnumValues(target): (string | number)[]
    • Extracts all possible values of a TS enum. Works with both string and numeric enums.


      Parameters

      Returns (string | number)[]

    staticextractPK

    • extractPK<T>(data, meta, strict): null | string | (T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T)
    • Extracts primary key from data. Accepts objects or primary keys directly.


      Parameters

      Returns null | string | (T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T)

    staticfindDuplicates

    • findDuplicates<T>(items): T[]
    • Parameters

      • items: T[]

      Returns T[]

    staticflatten

    • flatten<T>(arrays): T[]
    • Parameters

      • arrays: T[][]

      Returns T[]

    staticgetCompositeKeyHash

    • getCompositeKeyHash<T>(data, meta, convertCustomTypes, platform, flat): string

    staticgetCompositeKeyValue

    • getCompositeKeyValue<T>(data, meta, convertCustomTypes, platform): Primary<T>

    staticgetConstructorParams

    • getConstructorParams(func): undefined | string[]
    • Returns array of functions argument names. Uses basic regex for source code analysis, might not work with advanced syntax.


      Parameters

      • func: { toString: any }
        • toString:

      Returns undefined | string[]

    staticgetObjectKeysSize

    • getObjectKeysSize(object): number

    staticgetObjectQueryKeys

    staticgetObjectType

    • getObjectType(value): string
    • Gets the type of the argument.


      Parameters

      • value: any

      Returns string

    staticgetOrderedPrimaryKeys

    • getOrderedPrimaryKeys<T>(id, meta, platform, convertCustomTypes, allowScalar): Primary<T>[]

    staticgetORMVersion

    • getORMVersion(): string
    • Returns string

    staticgetPrimaryKeyCond

    • getPrimaryKeyCond<T>(entity, primaryKeys): null | Record<string, Primary<T>>
    • Parameters

      Returns null | Record<string, Primary<T>>

    staticgetPrimaryKeyCondFromArray

    • getPrimaryKeyCondFromArray<T>(pks, meta): Record<string, T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T>
    • Parameters

      • pks: (T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T)[]
      • meta: EntityMetadata<T, EntityCtor<T>>

      Returns Record<string, T extends { [PrimaryKeyProp]?: PK } ? PK extends undefined ? Omit<T<T>, typeof PrimaryKeyProp> : PK extends keyof T<T> ? ReadonlyPrimary<UnwrapPrimary<T<T>[PK<PK>]>> : PK extends keyof T<T>[] ? ReadonlyPrimary<PrimaryPropToType<T<T>, PK<PK>>> : PK : T extends { _id?: PK } ? string | ReadonlyPrimary<PK> : T extends { id?: PK } ? ReadonlyPrimary<PK> : T extends { uuid?: PK } ? ReadonlyPrimary<PK> : T>

    staticgetPrimaryKeyHash

    • getPrimaryKeyHash(pks): string
    • Parameters

      • pks: (string | Date | Buffer<ArrayBufferLike>)[]

      Returns string

    staticgetPrimaryKeyValues

    • getPrimaryKeyValues<T>(entity, meta, allowScalar, convertCustomTypes): any
    • Parameters

      Returns any

    statichash

    • hash(data, length): string
    • Parameters

      • data: string
      • optionallength: number

      Returns string

    statichasNestedKey

    • hasNestedKey(object, key): boolean
    • Parameters

      • object: unknown
      • key: string

      Returns boolean

    statichasObjectKeys

    • hasObjectKeys(object): boolean

    staticisCollection

    • isCollection<T, O>(item): item is Collection<T, O>
    • Parameters

      • item: any

      Returns item is Collection<T, O>

    staticisEmpty

    • isEmpty(data): boolean
    • Checks whether the argument is empty (array without items, object without keys or falsy value).


      Parameters

      • data: any

      Returns boolean

    staticisEntity

    • isEntity<T>(data, allowReference): data is T & {}
    • Checks whether given object is an entity instance.


      Parameters

      • data: any
      • allowReference: boolean = false

      Returns data is T & {}

    staticisIterable

    • isIterable<T>(value): value is Iterable<T, any, any>
    • Checks if the value is iterable, but considers strings and buffers as not iterable.


      Parameters

      • value: unknown

      Returns value is Iterable<T, any, any>

    staticisObject

    • isObject<T>(o): o is T
    • Checks if the argument is instance of Object. Returns false for arrays.


      Parameters

      • o: any

      Returns o is T

    staticisOperator

    • isOperator(key, includeGroupOperators): boolean
    • Parameters

      • key: PropertyKey
      • includeGroupOperators: boolean = true

      Returns boolean

    staticisPlainObject

    • isPlainObject<T>(value): value is T
    • Checks whether the value is POJO (e.g. { foo: 'bar' }, and not instance of Foo)


      Parameters

      • value: any

      Returns value is T

    staticisPrimaryKey

    • isPrimaryKey<T>(key, allowComposite): key is Primary<T>
    • Checks whether the argument looks like primary key (string, number or ObjectId).


      Parameters

      • key: any
      • allowComposite: boolean = false

      Returns key is Primary<T>

    staticisScalarReference

    • Checks whether given object is a scalar reference.


      Parameters

      • data: any
      • allowReference: boolean = false

      Returns data is ScalarReference<any>

    statickeys

    • keys<T>(obj): keyof T[]
    • Parameters

      • obj: T

      Returns keyof T[]

    staticmapFlatCompositePrimaryKey

    • mapFlatCompositePrimaryKey(fk, prop, fieldNames, idx): any
    • Maps nested FKs from [1, 2, 3] to [1, [2, 3]].


      Parameters

      • fk: any[]
      • prop: EntityProperty<any, any>
      • fieldNames: string[] = prop.fieldNames
      • idx: number = 0

      Returns any

    staticmerge

    • merge(target, ...sources): any
    • Merges all sources into the target recursively.


      Parameters

      • target: any
      • rest...sources: any[]

      Returns any

    staticmergeConfig

    • mergeConfig<T>(target, ...sources): T
    • Merges all sources into the target recursively. Ignores undefined values.


      Parameters

      Returns T

    staticprimaryKeyToObject

    • primaryKeyToObject<T>(meta, primaryKey, visible): T

    staticrandomInt

    • randomInt(min, max): number
    • Parameters

      • min: number
      • max: number

      Returns number

    staticremoveDuplicates

    • removeDuplicates<T>(items): T[]
    • Parameters

      • items: T[]

      Returns T[]

    staticrenameKey

    • renameKey<T>(payload, from, to): void
    • Renames object key, keeps order of properties.


      Parameters

      • payload: T
      • from: string | keyof T
      • to: string

      Returns void

    staticrunIfNotEmpty

    • runIfNotEmpty(clause, data): void
    • Parameters

      • clause: () => any
        • data: any

        Returns void

      staticrunSerial

      • runSerial<T, U>(items, cb): Promise<T[]>
      • Executes the cb promise serially on every element of the items array and returns array of resolved values.


        Parameters

        • items: Iterable<U, any, any>
        • cb: (item) => Promise<T>

          Returns Promise<T[]>

        staticsetPayloadProperty

        • setPayloadProperty<T>(entity, meta, prop, value, idx): void

        staticsplitPrimaryKeys

        statictryImport

        • tryImport<T>(__namedParameters): Promise<undefined | T>
        • Parameters

          • __namedParameters: { module: string; warning?: string }
            • module: string
            • optionalwarning: string

          Returns Promise<undefined | T>

        staticunique

        • unique<T>(items): T[]
        • Gets array without duplicates.


          Parameters

          • items: T[]

          Returns T[]

        staticunwrapProperty

        • unwrapProperty<T>(entity, meta, prop, payload): [unknown, number[]][]

        staticvalues

        • values<T>(obj): T[keyof T][]
        • Parameters

          • obj: T

          Returns T[keyof T][]

        staticxor

        • xor(a, b): boolean
        • Parameters

          • a: boolean
          • b: boolean

          Returns boolean