Utils
Index
Constructors
Properties
Methods
- asArray
- callCompiledFunction
- className
- copy
- createFunction
- defaultValue
- detectTypeScriptSupport
- dropUndefinedProperties
- entries
- equals
- extractChildElements
- extractEnumValues
- extractPK
- findDuplicates
- flatten
- getCompositeKeyHash
- getCompositeKeyValue
- getConstructorParams
- getObjectKeysSize
- getObjectQueryKeys
- getObjectType
- getOrderedPrimaryKeys
- getORMVersion
- getPrimaryKeyCond
- getPrimaryKeyCondFromArray
- getPrimaryKeyHash
- getPrimaryKeyValues
- hash
- hasNestedKey
- hasObjectKeys
- isCollection
- isEmpty
- isEntity
- isIterable
- isObject
- isOperator
- isPlainObject
- isPrimaryKey
- isScalarReference
- keys
- mapFlatCompositePrimaryKey
- merge
- mergeConfig
- primaryKeyToObject
- randomInt
- removeDuplicates
- renameKey
- runIfNotEmpty
- runSerial
- setPayloadProperty
- splitPrimaryKeys
- tryImport
- unique
- unwrapProperty
- values
- xor
Constructors
constructor
Returns Utils
Properties
staticreadonlyPK_SEPARATOR
Methods
staticasArray
Parameters
optionaldata: T | readonly T[] | Iterable<T, any, any>
strict: boolean = false
Returns T[]
staticcallCompiledFunction
Parameters
fn: (...args) => R
rest...args: T
Returns R
staticclassName
Gets string name of given class.
Parameters
classOrName: string | EntityName<T>
Returns string
staticcopy
Creates deep copy of given object.
Parameters
entity: T
respectCustomCloneMethod: boolean = true
Returns T
staticcreateFunction
Parameters
context: Map<string, any>
code: string
Returns any
staticdefaultValue
Parameters
prop: T
option: keyof T
defaultValue: any
Returns void
staticdetectTypeScriptSupport
Tries to detect TypeScript support.
Returns boolean
staticdropUndefinedProperties
Removes
undefinedproperties (recursively) so they are not saved as nullsParameters
o: any
optionalvalue: null
visited: Set<unknown> = ...
Returns void
staticentries
Parameters
obj: T
Returns [keyof T, T[keyof T]][]
staticequals
Checks if arguments are deeply (but not strictly) equal.
Parameters
a: any
b: any
Returns boolean
staticextractChildElements
Parameters
items: string[]
prefix: string
optionalallSymbol: string
Returns string[]
staticextractEnumValues
Extracts all possible values of a TS enum. Works with both string and numeric enums.
Parameters
target: Dictionary
Returns (string | number)[]
staticextractPK
Extracts primary key from
data. Accepts objects or primary keys directly.Parameters
data: any
optionalmeta: EntityMetadata<T, EntityCtor<T>>
strict: boolean = false
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
Parameters
items: T[]
Returns T[]
staticflatten
Parameters
arrays: T[][]
Returns T[]
staticgetCompositeKeyHash
Parameters
data: EntityData<T>
meta: EntityMetadata<T, EntityCtor<T>>
convertCustomTypes: boolean = false
optionalplatform: Platform
flat: boolean = false
Returns string
staticgetCompositeKeyValue
Parameters
data: EntityData<T>
meta: EntityMetadata<T, EntityCtor<T>>
convertCustomTypes: boolean | convertToDatabaseValue | convertToJSValue = false
optionalplatform: Platform
Returns Primary<T>
staticgetConstructorParams
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
Returns the number of properties on
obj. This is 20x faster than Object.keys(obj).length.Parameters
object: Dictionary
Returns number
staticgetObjectQueryKeys
Parameters
obj: T
Returns (K | RawQueryFragmentSymbol)[]
staticgetObjectType
Gets the type of the argument.
Parameters
value: any
Returns string
staticgetOrderedPrimaryKeys
Parameters
id: Primary<T> | Record<string, Primary<T>>
meta: EntityMetadata<T, EntityCtor<T>>
optionalplatform: Platform
convertCustomTypes: boolean = false
allowScalar: boolean = false
Returns Primary<T>[]
staticgetORMVersion
Returns string
staticgetPrimaryKeyCond
staticgetPrimaryKeyCondFromArray
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
Parameters
pks: (string | Date | Buffer<ArrayBufferLike>)[]
Returns string
staticgetPrimaryKeyValues
Parameters
entity: T
meta: EntityMetadata<T, EntityCtor<T>>
allowScalar: boolean = false
convertCustomTypes: boolean = false
Returns any
statichash
Parameters
data: string
optionallength: number
Returns string
statichasNestedKey
Parameters
object: unknown
key: string
Returns boolean
statichasObjectKeys
Returns true if
objhas at least one property. This is 20x faster than Object.keys(obj).length.Parameters
object: Dictionary
Returns boolean
staticisCollection
Parameters
item: any
Returns item is Collection<T, O>
staticisEmpty
Checks whether the argument is empty (array without items, object without keys or falsy value).
Parameters
data: any
Returns boolean
staticisEntity
Checks whether given object is an entity instance.
Parameters
data: any
allowReference: boolean = false
Returns data is T & {}
staticisIterable
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
Checks if the argument is instance of
Object. Returns false for arrays.Parameters
o: any
Returns o is T
staticisOperator
Parameters
key: PropertyKey
includeGroupOperators: boolean = true
Returns boolean
staticisPlainObject
Checks whether the value is POJO (e.g.
{ foo: 'bar' }, and not instance ofFoo)Parameters
value: any
Returns value is T
staticisPrimaryKey
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
Parameters
obj: T
Returns keyof T[]
staticmapFlatCompositePrimaryKey
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
Merges all sources into the target recursively.
Parameters
target: any
rest...sources: any[]
Returns any
staticmergeConfig
Merges all sources into the target recursively. Ignores
undefinedvalues.Parameters
target: T
rest...sources: Dictionary[]
Returns T
staticprimaryKeyToObject
Parameters
meta: EntityMetadata<T, EntityCtor<T>>
primaryKey: T | Primary<T>
optionalvisible: keyof T[]
Returns T
staticrandomInt
Parameters
min: number
max: number
Returns number
staticremoveDuplicates
Parameters
items: T[]
Returns T[]
staticrenameKey
Renames object key, keeps order of properties.
Parameters
payload: T
from: string | keyof T
to: string
Returns void
staticrunIfNotEmpty
Parameters
clause: () => any
data: any
Returns void
staticrunSerial
Executes the
cbpromise serially on every element of theitemsarray and returns array of resolved values.Parameters
items: Iterable<U, any, any>
cb: (item) => Promise<T>
Returns Promise<T[]>
staticsetPayloadProperty
Parameters
entity: EntityDictionary<T>
meta: EntityMetadata<T, EntityCtor<T>>
prop: EntityProperty<T, any>
value: unknown
idx: number[]
Returns void
staticsplitPrimaryKeys
Parameters
key: string
Returns EntityKey<T>[]
statictryImport
Parameters
__namedParameters: { module: string; warning?: string }
module: string
optionalwarning: string
Returns Promise<undefined | T>
staticunique
Gets array without duplicates.
Parameters
items: T[]
Returns T[]
staticunwrapProperty
Parameters
entity: T
meta: EntityMetadata<T, EntityCtor<T>>
prop: EntityProperty<T, any>
payload: boolean = false
Returns [unknown, number[]][]
staticvalues
Parameters
obj: T
Returns T[keyof T][]
staticxor
Parameters
a: boolean
b: boolean
Returns boolean
Normalize the argument to always be an array.