Utils
Index
Constructors
Properties
Methods
- absolutePath
- asArray
- callCompiledFunction
- className
- copy
- createFunction
- defaultValue
- detectTsNode
- diff
- dropUndefinedProperties
- dynamicImport
- dynamicImportProvider
- equals
- extractEnumValues
- extractPK
- fileURLToPath
- findDuplicates
- flatten
- getCompositeKeyHash
- getCompositeKeyValue
- getGlobalStorage
- getORMVersion
- getObjectKeysSize
- getObjectType
- getOrderedPrimaryKeys
- getParamNames
- getPrimaryKeyCond
- getPrimaryKeyCondFromArray
- getPrimaryKeyHash
- getPrimaryKeyValues
- getRootEntity
- hasNestedKey
- hasObjectKeys
- hash
- isCollection
- isDefined
- isEmpty
- isEntity
- isEntityClass
- isGroupOperator
- isNotObject
- isNumber
- isObject
- isObjectID
- isOperator
- isPlainObject
- isPrimaryKey
- isString
- lookupPathFromDecorator
- merge
- mergeConfig
- normalizePath
- pathExists
- propertyDecoratorReturnValue
- randomInt
- relativePath
- removeDuplicates
- renameKey
- requireFrom
- runIfNotEmpty
- runSerial
- setDynamicImportProvider
- setPayloadProperty
- splitPrimaryKeys
- stripRelativePath
- tryRequire
- unique
- unwrapProperty
Constructors
constructor
Returns Utils
Properties
staticreadonlyPK_SEPARATOR
Methods
staticabsolutePath
Parameters
path: string
baseDir: string = ...
Returns string
staticasArray
Normalize the argument to always be an array.
Type parameters
- T
Parameters
optionaldata: T | readonly T[]
strict: boolean = false
Returns T[]
staticcallCompiledFunction
Type parameters
- T: unknown[]
- R
Parameters
fn: (...args: T) => R
rest...args: T
Returns R
staticclassName
Gets string name of given class.
Type parameters
- T
Parameters
classOrName: EntityName<T>
Returns string
staticcopy
Creates deep copy of given object.
Type parameters
- T
Parameters
entity: T
respectCustomCloneMethod: boolean = true
Returns T
staticcreateFunction
Parameters
context: Map<string, any>
code: string
Returns any
staticdefaultValue
Type parameters
- T: Dictionary
Parameters
prop: T
option: keyof T
defaultValue: any
Returns void
staticdetectTsNode
Tries to detect
ts-node
runtime.Returns boolean
staticdiff
Computes difference between two objects, ignoring items missing in
b
.Parameters
a: Dictionary
b: Dictionary
Returns Record<string | number, any>
staticdropUndefinedProperties
Removes
undefined
properties (recursively) so they are not saved as nullsType parameters
- T = Dictionary | unknown[]
Parameters
o: any
optionalvalue: null
visited: Set<unknown> = ...
Returns void
staticdynamicImport
Hack to keep dynamic imports even when compiling to CJS. We can't use it always, as it would break ts-node.
Type parameters
- T = any
Parameters
id: string
Returns Promise<T>
staticdynamicImportProvider
Parameters
id: string
Returns Promise<any>
staticequals
Checks if arguments are deeply (but not strictly) equal.
Parameters
a: any
b: any
Returns boolean
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.Type parameters
- T
Parameters
data: any
optionalmeta: EntityMetadata<T>
strict: boolean = false
Returns null | string | Primary<T>
staticfileURLToPath
Parameters
url: string | URL
Returns string
staticfindDuplicates
Type parameters
- T
Parameters
items: T[]
Returns T[]
staticflatten
Type parameters
- T
Parameters
arrays: T[][]
Returns T[]
staticgetCompositeKeyHash
Type parameters
- T
Parameters
data: EntityData<T>
meta: EntityMetadata<T>
convertCustomTypes: boolean = false
optionalplatform: Platform
flat: boolean = false
Returns string
staticgetCompositeKeyValue
Type parameters
- T
Parameters
data: EntityData<T>
meta: EntityMetadata<T>
convertCustomTypes: boolean | convertToDatabaseValue | convertToJSValue = false
optionalplatform: Platform
Returns Primary<T>
staticgetGlobalStorage
Parameters
namespace: string
Returns Dictionary
staticgetORMVersion
Returns string
staticgetObjectKeysSize
Returns the number of properties on
obj
. This is 20x faster than Object.keys(obj).length.Parameters
object: Dictionary
Returns number
staticgetObjectType
Gets the type of the argument.
Parameters
value: any
Returns string
staticgetOrderedPrimaryKeys
Type parameters
- T
Parameters
id: Primary<T> | Record<string, Primary<T>>
meta: EntityMetadata<T>
Returns Primary<T>[]
staticgetParamNames
Returns array of functions argument names. Uses
escaya
for source code analysis.Parameters
func: string | { toString: any }
toString:
optionalmethodName: string
Returns string[]
staticgetPrimaryKeyCond
Type parameters
- T
Parameters
entity: T
primaryKeys: string[]
Returns null | Record<string, Primary<T>>
staticgetPrimaryKeyCondFromArray
Type parameters
- T
Parameters
pks: Primary<T>[]
meta: EntityMetadata<T>
Returns Record<string, Primary<T>>
staticgetPrimaryKeyHash
Parameters
pks: (string | Buffer)[]
Returns string
staticgetPrimaryKeyValues
Type parameters
- T
Parameters
entity: T
primaryKeys: string[]
allowScalar: boolean = false
convertCustomTypes: boolean = false
Returns any
staticgetRootEntity
Parameters
metadata: IMetadataStorage
meta: EntityMetadata<any>
Returns EntityMetadata<any>
statichasNestedKey
Parameters
object: unknown
key: string
Returns boolean
statichasObjectKeys
Returns true if
obj
has at least one property. This is 20x faster than Object.keys(obj).length.Parameters
object: Dictionary
Returns boolean
statichash
Parameters
data: string
optionallength: number
Returns string
staticisCollection
Type parameters
- T: object
- O: object = object
Parameters
item: any
Returns item is Collection<T, O>
staticisDefined
Checks if the argument is not undefined
Type parameters
- T = Record<string, unknown>
Parameters
data: any
Returns data is T
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.
Type parameters
- T = unknown
Parameters
data: any
allowReference: boolean = false
Returns data is T
staticisEntityClass
Checks whether given object is an entity instance.
Type parameters
- T = unknown
Parameters
data: any
allowReference: boolean = false
Returns data is EntityClass<T>
staticisGroupOperator
Parameters
key: string
Returns boolean
staticisNotObject
Checks if the argument is instance of
Object
, but not one of the blacklisted types. Returns false for arrays.Type parameters
- T = Dictionary
Parameters
o: any
not: any[]
Returns o is T
staticisNumber
Checks if the argument is number
Type parameters
- T = number
Parameters
s: any
Returns s is T
staticisObject
Checks if the argument is instance of
Object
. Returns false for arrays.Type parameters
- T = Dictionary
Parameters
o: any
Returns o is T
staticisObjectID
Checks whether the argument is ObjectId instance
Parameters
key: any
Returns boolean
staticisOperator
Parameters
key: string
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 Dictionary
staticisPrimaryKey
Checks whether the argument looks like primary key (string, number or ObjectId).
Type parameters
- T
Parameters
key: any
allowComposite: boolean = false
Returns key is Primary<T>
staticisString
Checks if the argument is string
Parameters
s: any
Returns s is string
staticlookupPathFromDecorator
Uses some dark magic to get source path to caller where decorator is used. Analyses stack trace of error created inside the function call.
Parameters
name: string
optionalstack: string[]
Returns string
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
undefined
values.Parameters
target: any
rest...sources: any[]
Returns any
staticnormalizePath
Resolves and normalizes a series of path parts relative to each preceeding part. If any part is a
file:
URL, it is converted to a local path. If any part is an absolute path, it replaces preceeding paths (similar topath.resolve
in NodeJS). Trailing directory separators are removed, and all directory separators are converted to POSIX-style separators (/
).Parameters
rest...parts: string[]
Returns string
staticpathExists
Parameters
path: string
options: GlobbyOptions = {}
Returns Promise<boolean>
staticpropertyDecoratorReturnValue
Returns any
staticrandomInt
Parameters
min: number
max: number
Returns number
staticrelativePath
Determines the relative path between two paths. If either path is a
file:
URL, it is converted to a local path.Parameters
path: string
relativeTo: string
Returns string
staticremoveDuplicates
Type parameters
- T
Parameters
items: T[]
Returns T[]
staticrenameKey
Renames object key, keeps order of properties.
Type parameters
- T
Parameters
payload: T
from: string | keyof T
to: string
Returns void
staticrequireFrom
Require a module from a specific location
Type parameters
- T: Dictionary
Parameters
id: string
The module to require
optionalfrom: string = ...
Location to start the node resolution
Returns T
staticrunIfNotEmpty
Parameters
clause: () => any
data: any
Returns void
staticrunSerial
Executes the
cb
promise serially on every element of theitems
array and returns array of resolved values.Type parameters
- T = any
- U = any
Parameters
items: Iterable<U>
cb: (item: U) => Promise<T>
Returns Promise<T[]>
staticsetDynamicImportProvider
Parameters
provider: (id: string) => Promise<unknown>
Returns void
staticsetPayloadProperty
Type parameters
- T
Parameters
entity: EntityDictionary<T>
meta: EntityMetadata<T>
prop: EntityProperty<T>
value: unknown
idx: number[] = []
Returns void
staticsplitPrimaryKeys
Parameters
key: string
Returns string[]
staticstripRelativePath
Parameters
str: string
Returns string
statictryRequire
Type parameters
- T: Dictionary = any
Parameters
__namedParameters: { allowError?: string; from?: string; module: string; warning: string }
optionalallowError: string
optionalfrom: string
module: string
warning: string
Returns undefined | T
staticunique
Gets array without duplicates.
Type parameters
- T = string
Parameters
items: T[]
Returns T[]
staticunwrapProperty
Type parameters
- T
Parameters
entity: T
meta: EntityMetadata<T>
prop: EntityProperty<T>
payload: boolean = false
Returns [unknown, number[]][]
Computes the absolute path to for the given path relative to the provided base directory. If either
path
orbaseDir
arefile:
URLs, they are converted to local paths.