Class: RepoUtils<T>
Defined in: service-core/src/models/RepoUtils.ts:91
Type Parameters
T
T extends BaseEntity | SimpleEntity
Constructors
Constructor
new RepoUtils<
T>(modelClass,repo?):RepoUtils<T>
Defined in: service-core/src/models/RepoUtils.ts:125
Parameters
modelClass
any
repo?
Repository<T> | MongoRepository<T>
Returns
RepoUtils<T>
Properties
aclUtils?
protectedoptionalaclUtils?:ACLUtils
Defined in: service-core/src/models/RepoUtils.ts:93
cacheClient?
protectedoptionalcacheClient?:Redis
Defined in: service-core/src/models/RepoUtils.ts:97
The redis client that will be used as a 2nd level cache for all cacheable models.
config
protectedconfig:any
Defined in: service-core/src/models/RepoUtils.ts:100
connectionManager?
protectedoptionalconnectionManager?:ConnectionManager
Defined in: service-core/src/models/RepoUtils.ts:103
defaultACLUid
defaultACLUid:
string=""
Defined in: service-core/src/models/RepoUtils.ts:106
The unique identifier of the default ACL for the model type.
logger
protectedlogger:any
Defined in: service-core/src/models/RepoUtils.ts:109
modelClass
protectedmodelClass:any
Defined in: service-core/src/models/RepoUtils.ts:111
notificationUtils?
protectedoptionalnotificationUtils?:NotificationUtils
Defined in: service-core/src/models/RepoUtils.ts:117
objectFactory?
protectedoptionalobjectFactory?:ObjectFactory
Defined in: service-core/src/models/RepoUtils.ts:114
repo?
optionalrepo?:Repository<T> |MongoRepository<T>
Defined in: service-core/src/models/RepoUtils.ts:120
The model class associated with the controller to perform operations against.
trustedRoles
protectedtrustedRoles:string[]
Defined in: service-core/src/models/RepoUtils.ts:123
Accessors
baseCacheKey
Get Signature
get baseCacheKey():
string
Defined in: service-core/src/models/RepoUtils.ts:201
The base key used to get or set data in the cache.
Returns
string
Methods
count()
count(
query,options?):Promise<number>
Defined in: service-core/src/models/RepoUtils.ts:205
Parameters
query
any
options?
Returns
Promise<number>
create()
create(
obj,options?):Promise<T>
Defined in: service-core/src/models/RepoUtils.ts:267
Stores a new record of the provided object in the datastore. 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:396
Parameters
uid
string
options
Returns
Promise<void>
find()
find(
query,options?):Promise<T[]>
Defined in: service-core/src/models/RepoUtils.ts:465
Retrieves an array of objects from the datastore 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:620
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:735
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:691
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
hashQuery()
hashQuery(
query):string
Defined in: service-core/src/models/RepoUtils.ts:710
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:131
Returns
Promise<void>
instantiateObject()
instantiateObject(
obj,clazz?):T
Defined in: service-core/src/models/RepoUtils.ts:760
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?):any
Defined in: service-core/src/models/RepoUtils.ts:773
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
Returns
any
truncate()
truncate(
query,options):Promise<void>
Defined in: service-core/src/models/RepoUtils.ts:782
Parameters
query
any
options
Returns
Promise<void>
update()
update(
obj,existing,options?):Promise<T>
Defined in: service-core/src/models/RepoUtils.ts:850
Parameters
obj
Partial<T>
existing
T
options?
Returns
Promise<T>
validate()
validate(
objs,options?):Promise<void>
Defined in: service-core/src/models/RepoUtils.ts:1013
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>