Skip to main content

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?

protected optional _objectFactory?: ObjectFactory

Defined in: service-core/src/models/RepoUtils.ts:105


aclUtils?

protected optional aclUtils?: ACLUtils

Defined in: service-core/src/models/RepoUtils.ts:108


cache?

protected optional cache?: 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

protected config: any

Defined in: service-core/src/models/RepoUtils.ts:114


connectionManager?

protected optional connectionManager?: 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

protected logger: any

Defined in: service-core/src/models/RepoUtils.ts:123


modelClass

protected modelClass: any

Defined in: service-core/src/models/RepoUtils.ts:125


notificationUtils?

protected optional notificationUtils?: NotificationUtils

Defined in: service-core/src/models/RepoUtils.ts:128


repo?

optional repo?: 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

protected trustedRoles: 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?

RepoFindOptions

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?

RepoCreateOptions

Returns

Promise<T>


delete()

delete(uid, options): Promise<void>

Defined in: service-core/src/models/RepoUtils.ts:620

Parameters

uid

string

options

RepoDeleteOptions

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?

RepoFindOptions

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?

RepoFindOptions

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?

RepoFindOptions

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()

protected getTransaction(options?): TransactionInfo | undefined

Defined in: service-core/src/models/RepoUtils.ts:1028

Returns the current transactional session information, if present.

Parameters

options?

RepoOperationOptions

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()

protected init(): 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

RepoFindOptions

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?

RepoUpdateOptions<T>

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?

RepoOperationOptions

The optional set of arguments that can be passed to perform additonal checks.

Returns

Promise<void>