Class: RepoUtils<T>
Defined in: service-core/src/models/RepoUtils.ts:103
Type Parameters
T
T extends BaseEntity | SimpleEntity
Constructors
Constructor
new RepoUtils<
T>(modelClass,repo?):RepoUtils<T>
Defined in: service-core/src/models/RepoUtils.ts:136
Parameters
modelClass
any
repo?
Repository<T> | MongoRepository<T>
Returns
RepoUtils<T>
Properties
_objectFactory?
protectedoptional_objectFactory?:ObjectFactory
Defined in: service-core/src/models/RepoUtils.ts:105
aclUtils?
protectedoptionalaclUtils?:ACLUtils
Defined in: service-core/src/models/RepoUtils.ts:108
cache?
protectedoptionalcache?:RedisCache<T>
Defined in: service-core/src/models/RepoUtils.ts:111
The store that will be used as a 2nd level cache for all cacheable models.
config
protectedconfig:any
Defined in: service-core/src/models/RepoUtils.ts:114
connectionManager?
protectedoptionalconnectionManager?:ConnectionManager
Defined in: service-core/src/models/RepoUtils.ts:117
defaultACLUid
defaultACLUid:
string=""
Defined in: service-core/src/models/RepoUtils.ts:120
The unique identifier of the default ACL for the model type.
logger
protectedlogger:any
Defined in: service-core/src/models/RepoUtils.ts:123
modelClass
protectedmodelClass:any
Defined in: service-core/src/models/RepoUtils.ts:125
notificationUtils?
protectedoptionalnotificationUtils?:NotificationUtils
Defined in: service-core/src/models/RepoUtils.ts:128
repo?
optionalrepo?:Repository<T> |MongoRepository<T>
Defined in: service-core/src/models/RepoUtils.ts:131
The model class associated with the controller to perform operations against.
trustedRoles
protectedtrustedRoles:string[]
Defined in: service-core/src/models/RepoUtils.ts:134
Methods
count()
count(
query,options?):Promise<number>
Defined in: service-core/src/models/RepoUtils.ts:266
Parameters
query
any
options?
Returns
Promise<number>
create()
create(
obj,options?):Promise<T>
Defined in: service-core/src/models/RepoUtils.ts:453
Stores a new record of the provided object in the datasource. Performs pre-processing, permission checks against the class ACL, cache seeding, telemetry recording and push notifications.
Parameters
obj
Partial<T>
The object to store.
options?
Returns
Promise<T>
delete()
delete(
uid,options):Promise<void>
Defined in: service-core/src/models/RepoUtils.ts:620
Parameters
uid
string
options
Returns
Promise<void>
exists()
exists(
id,options?):Promise<number>
Defined in: service-core/src/models/RepoUtils.ts:361
Determines whether an object with the given unique identifier (and, optionally, a specific version) exists
in the datasource. Respects record-level ACLs the same way count() does.
Parameters
id
string
The unique identifier of the object to check for.
options?
The additional options to consider, such as version and the requesting user.
Returns
Promise<number>
find()
find(
query,options?):Promise<T[]>
Defined in: service-core/src/models/RepoUtils.ts:718
Retrieves an array of objects from the datasource matching the given search query. This function will first attempt to look up the results in the cache. Also checks ACLs for READ permission.
Parameters
query
any
The constructed search query to run.
options?
The additional options to consider during the search.
Returns
Promise<T[]>
findOne()
findOne(
id,options?):Promise<T|undefined>
Defined in: service-core/src/models/RepoUtils.ts:838
Retrieves the object with the given id from either the cache or the database. If retrieving from the database the cache is populated to speed up subsequent requests.
Parameters
id
string
The unique identifier of the object to retrieve.
options?
The additional options to consider during the search.
Returns
Promise<T | undefined>
getClassType()
getClassType(
obj):any
Defined in: service-core/src/models/RepoUtils.ts:1002
Returns the class type (constructor) for the given object. This uses the _fqn or _type property of obj to
identify the class. If neither property is defined modelClass is assumed.
Parameters
obj
any
The object whose class type to look up.
Returns
any
The class type (constructor) associated with the given object.
getDefaultACL()
getDefaultACL():
AccessControlList|undefined
Defined in: service-core/src/models/RepoUtils.ts:931
Returns the default access control list governing the model type. Returning a value of undefined will grant
full acccess to any user (including unauthenticated anonymous users).
Returns
AccessControlList | undefined
getTransaction()
protectedgetTransaction(options?):TransactionInfo|undefined
Defined in: service-core/src/models/RepoUtils.ts:1028
Returns the current transactional session information, if present.
Parameters
options?
Returns
TransactionInfo | undefined
hashQuery()
hashQuery(
query):string
Defined in: service-core/src/models/RepoUtils.ts:977
Hashes the given query object to a unique string.
Parameters
query
any
The query object to hash.
Returns
string
init()
protectedinit():Promise<void>
Defined in: service-core/src/models/RepoUtils.ts:142
Returns
Promise<void>
instantiateObject()
instantiateObject(
obj,clazz?):T
Defined in: service-core/src/models/RepoUtils.ts:1035
Creates a new instance of obj scoped to the correct model class or sub-class.
Parameters
obj
any
clazz?
any
Returns
T
searchIdQuery()
searchIdQuery(
id,version?,includeDeleted?):any
Defined in: service-core/src/models/RepoUtils.ts:1052
Search for existing object based on passed in id and version and product uid.
The result of this function is compatible with all Repository.find() functions.
Parameters
id
string
version?
string | number
includeDeleted?
boolean = true
Set to false to exclude soft-deleted RecoverableBaseEntity records from matching.
Defaults to true; pass false when the result is exposed directly to an API client (e.g. findOne, exists)
so a soft-deleted record isn't returned as if it still existed.
Returns
any
truncate()
truncate(
query,options):Promise<void>
Defined in: service-core/src/models/RepoUtils.ts:1063
Parameters
query
any
options
Returns
Promise<void>
update()
update(
obj,existing,options?):Promise<T>
Defined in: service-core/src/models/RepoUtils.ts:1165
Parameters
obj
Partial<T>
existing
T
options?
Returns
Promise<T>
validate()
validate(
objs,options?):Promise<void>
Defined in: service-core/src/models/RepoUtils.ts:1372
Performs validation on the object(s) provided. This function first calls ObjectUtils.validate() to check
any class level defined validation functions. Second, it scans for any properties with the @Reference
decorator and attempts to verify that an existing object for the given reference ID is valid.
Parameters
objs
Partial<T> | Partial<T>[]
The object(s) to validate.
options?
The optional set of arguments that can be passed to perform additonal checks.
Returns
Promise<void>