MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / wrap

Function wrap

packages/core/src/entity/wrap.ts:17–30  ·  view source on GitHub ↗
(
  entity: T & Dictionary,
  preferHelper = false,
)

Source from the content-addressed store, hash-verified

15 * use `preferHelper = true` to have access to the internal `__` properties like `__meta` or `__em`
16 */
17export function wrap<T extends object>(
18 entity: T & Dictionary,
19 preferHelper = false,
20): IWrappedEntity<T> | IWrappedEntityInternal<T> {
21 if (!entity) {
22 return entity;
23 }
24
25 if (entity.__baseEntity && !preferHelper) {
26 return entity as unknown as IWrappedEntity<T>;
27 }
28
29 return entity.__helper ?? entity;
30}
31
32/**
33 * wraps entity type with WrappedEntity internal properties and helpers like init/isInitialized/populated/toJSON

Calls

no outgoing calls

Tested by 12

createEntitiesFunction · 0.72
constructorMethod · 0.72
createBooksWithTagsFunction · 0.72
createBooksWithTagsFunction · 0.72
constructorMethod · 0.72
createBooksWithTagsFunction · 0.72
createEntitiesFunction · 0.72
assertFunction · 0.72
beforeUpdateMethod · 0.40
beforeDeleteMethod · 0.40
beforeUpdateMethod · 0.40
beforeDeleteMethod · 0.40