Comparing version 0.0.11 to 0.0.12
@@ -16,3 +16,2 @@ "use strict"; | ||
const utils_1 = require("../utils"); | ||
const di_1 = require("../di"); | ||
class CrudError extends Error { | ||
@@ -36,3 +35,3 @@ constructor(type, resource, detail) { | ||
} | ||
getEntityManager(context) { return di_1.DI.em; } | ||
getEntityManager(context) { return context.em; } | ||
getRouteMaps() { | ||
@@ -431,3 +430,3 @@ return Object.assign(Object.assign({}, super.getRouteMaps()), { index: { method: 'get', path: '/' }, createOne: { method: 'post', path: '/' }, getOne: { method: 'get', path: this.options.resourceKeyPath }, updateOne: { method: 'post', path: this.options.resourceKeyPath }, deleteOne: { method: 'delete', path: this.options.resourceKeyPath } }); | ||
// Retry by fallback to default's session em. | ||
const found = em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query) || di_1.DI.em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query); | ||
const found = em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query); | ||
if (found) { | ||
@@ -434,0 +433,0 @@ // mark dirty |
@@ -39,3 +39,3 @@ "use strict"; | ||
ctx.orm = di_1.DI.orm; | ||
ctx.em = di_1.DI.orm.em.fork(); | ||
ctx.em = di_1.DI.orm.em; | ||
await next(); | ||
@@ -42,0 +42,0 @@ }); |
@@ -10,3 +10,2 @@ import { Utils, wrap } from '@mikro-orm/core'; | ||
import { ClientErrorCode, KobpError, ServerErrorCode } from '../utils'; | ||
import { DI } from '../di'; | ||
export class CrudError extends Error { | ||
@@ -29,3 +28,3 @@ constructor(type, resource, detail) { | ||
} | ||
getEntityManager(context) { return DI.em; } | ||
getEntityManager(context) { return context.em; } | ||
getRouteMaps() { | ||
@@ -424,3 +423,3 @@ return Object.assign(Object.assign({}, super.getRouteMaps()), { index: { method: 'get', path: '/' }, createOne: { method: 'post', path: '/' }, getOne: { method: 'get', path: this.options.resourceKeyPath }, updateOne: { method: 'post', path: this.options.resourceKeyPath }, deleteOne: { method: 'delete', path: this.options.resourceKeyPath } }); | ||
// Retry by fallback to default's session em. | ||
const found = em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query) || DI.em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query); | ||
const found = em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query); | ||
if (found) { | ||
@@ -427,0 +426,0 @@ // mark dirty |
@@ -33,3 +33,3 @@ import { MikroORM, RequestContext } from '@mikro-orm/core'; | ||
ctx.orm = DI.orm; | ||
ctx.em = DI.orm.em.fork(); | ||
ctx.em = DI.orm.em; | ||
await next(); | ||
@@ -36,0 +36,0 @@ }); |
{ | ||
"name": "kobp", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Koa Boilerplate with MikroORM", | ||
@@ -5,0 +5,0 @@ "main": "lib/cjs/index.js", |
@@ -16,3 +16,2 @@ import type { Populate } from '@mikro-orm/core' | ||
import { ClientErrorCode, KobpError, ServerErrorCode } from '../utils' | ||
import { DI } from '../di' | ||
import { Middleware } from 'koa' | ||
@@ -172,3 +171,3 @@ | ||
protected getEntityManager(context: KobpServiceContext): EntityManager { return DI.em as EntityManager } | ||
protected getEntityManager(context: KobpServiceContext): EntityManager { return context.em as EntityManager } | ||
@@ -622,3 +621,3 @@ public getRouteMaps(): RouteMap { | ||
// Retry by fallback to default's session em. | ||
const found = em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query) || DI.em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query) | ||
const found = em.getUnitOfWork().tryGetById(relationshipForThisKey.type, query) | ||
if (found) { | ||
@@ -625,0 +624,0 @@ // mark dirty |
@@ -46,3 +46,3 @@ import type Router from 'koa-router' | ||
ctx.orm = DI.orm | ||
ctx.em = DI.orm.em.fork() as any | ||
ctx.em = DI.orm.em | ||
await next() | ||
@@ -49,0 +49,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
412476
3707