Class: RepoUtils<T>
Defined in: service-core/src/models/RepoUtils.ts:179
Type Parameters
T
T extends BaseEntity | SimpleEntity
Constructors
Constructor
new RepoUtils<
T>(modelClass,repo?):RepoUtils<T>
Defined in: service-core/src/models/RepoUtils.ts:212
Parameters
modelClass
any
repo?
Repository<T> | MongoRepository<T>
Returns
RepoUtils<T>
Properties
_objectFactory?
protectedoptional_objectFactory?:ObjectFactory
Defined in: service-core/src/models/RepoUtils.ts:181
aclUtils?
protectedoptionalaclUtils?:ACLUtils
Defined in: service-core/src/models/RepoUtils.ts:184
cache?
protectedoptionalcache?:RedisCache<T>
Defined in: service-core/src/models/RepoUtils.ts:187
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:190
connectionManager?
protectedoptionalconnectionManager?:ConnectionManager
Defined in: service-core/src/models/RepoUtils.ts:193
defaultACLUid
defaultACLUid:
string=""
Defined in: service-core/src/models/RepoUtils.ts:196
The unique identifier of the default ACL for the model type.
logger
protectedlogger:any
Defined in: service-core/src/models/RepoUtils.ts:199
modelClass
protectedmodelClass:any
Defined in: service-core/src/models/RepoUtils.ts:201
notificationUtils?
protectedoptionalnotificationUtils?:NotificationUtils
Defined in: service-core/src/models/RepoUtils.ts:204
repo?
optionalrepo?:Repository<T> |MongoRepository<T>
Defined in: service-core/src/models/RepoUtils.ts:207
The model class associated with the controller to perform operations against.
trustedRoles
protectedtrustedRoles:string[]
Defined in: service-core/src/models/RepoUtils.ts:210
Methods
coerceDateProperties()
protectedcoerceDateProperties(obj,clazz):void
Defined in: service-core/src/models/RepoUtils.ts:1197
Converts every Date-typed property of obj that holds a string or number (e.g. an ISO 8601 string from a
JSON request body) to a real Date, in place. Without this a MongoDB document stores the string itself, and
date range queries (which compare against Date operands) never match it.
A property counts as Date-typed when its @Column declares an explicit date/time type, or otherwise when
TypeScript's emitted design:type is Date. TypeScript reflects a union-typed property (e.g. Date | null)
as Object, so such a property is only converted when its @Column sets type explicitly. Properties that
aren't @Columns are never touched.
Accepted values (anything else, including a Date column holding a boolean or an object, is a 400):
- an ISO 8601 date (
YYYY-MM-DD) or date-time (YYYY-MM-DDTHH:mm[:ss[.fff]],Tor a space), with a zone designator ofZ,±HH,±HHmmor±HH:mm. A date-time without a zone is read as UTC, never as the server's local time; - a finite number of epoch milliseconds between years 1 and 9999 whose magnitude is at least
1e11(a smaller number is ambiguous with epoch seconds). Numeric strings are not accepted; - a
Date,nullorundefined, which are left as they are.
A SQL date-only column (@Column({ type: "date" })) is validated as a YYYY-MM-DD string but kept as that
string: TypeORM writes a Date into such a column using the server's local calendar date, so converting it
would store the previous day on any server west of UTC. On MongoDB, which has no date-only type, it is
converted to midnight UTC like any other date.
Parameters
obj
any
The object whose properties to convert.
clazz
any
The model class describing obj.
Returns
void
Throws
ApiError INVALID_REQUEST (400) when a value isn't a valid date.
count()
count(
query,options?):Promise<number>
Defined in: service-core/src/models/RepoUtils.ts:469
Parameters
query
any
options?
Returns
Promise<number>
create()
create(
obj,options?):Promise<T>
Defined in: service-core/src/models/RepoUtils.ts:653
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:802
Parameters
uid
string
options
Returns
Promise<void>
exists()
exists(
id,options?):Promise<number>
Defined in: service-core/src/models/RepoUtils.ts:561
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:900
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:1010
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:1414
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:1343
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:1440
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:1389
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:218
Returns
Promise<void>
instantiateObject()
instantiateObject(
obj,clazz?):T
Defined in: service-core/src/models/RepoUtils.ts:1447
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:1464
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:1475
Parameters
query
any
options
Returns
Promise<void>
update()
update(
obj,existing,options?):Promise<T>
Defined in: service-core/src/models/RepoUtils.ts:1593
Parameters
obj
Partial<T>
existing
T
options?
Returns
Promise<T>
validate()
validate(
objs,options?):Promise<void>
Defined in: service-core/src/models/RepoUtils.ts:2096
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>