Feat(modules-sdk,inventory,stock-location): modules isolated connection (#3329)

* feat: scoped container for modules
This commit is contained in:
Carlos R. L. Rodrigues authored and GitHub committed 2023-03-15 12:09:45 -03:00
1 parent 8e78c533c4
commit 77d46220c2
65 files changed
+1116 -1011

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
module.exports = {
globals: {
"ts-jest": {
tsConfig: "tsconfig.json",
isolatedModules: false,
},
},
transform: {
"^.+\\.[jt]s?$": "ts-jest",
},
testEnvironment: `node`,
moduleFileExtensions: [`js`, `ts`],
}
+35
View File
@@ -0,0 +1,35 @@
{
"name": "@medusajs/utils",
"version": "0.0.1",
"description": "Medusa utilities functions shared by Medusa core and Modules",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "https://github.com/medusajs/medusa",
"directory": "packages/utils"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist"
],
"author": "Medusa",
"license": "MIT",
"devDependencies": {
"@medusajs/types": "*",
"cross-env": "^5.2.1",
"jest": "^25.5.4",
"ts-jest": "^25.5.1",
"typeorm": "^0.3.11",
"typescript": "^4.4.4"
},
"peerDependencies": {
"@medusajs/types": "^0.0.1"
},
"scripts": {
"prepare": "cross-env NODE_ENV=production yarn run build",
"build": "tsc --build",
"test": "jest --passWithNoTests src"
}
}
@@ -0,0 +1,19 @@
export function MedusaContext() {
return function (
target: any,
propertyKey: string | symbol,
parameterIndex: number
) {
if (!target.MedusaContext_) {
target.MedusaContext_ = {}
}
if (propertyKey in target.MedusaContext_) {
throw new Error(
`Only one MedusaContext is allowed on method "${String(propertyKey)}".`
)
}
target.MedusaContext_[propertyKey] = parameterIndex
}
}
+2
View File
@@ -0,0 +1,2 @@
export * from "./context-parameter"
export * from "./inject-entity-manager"
@@ -0,0 +1,37 @@
import { SharedContext } from "@medusajs/types"
export function InjectEntityManager(
managerProperty = "manager_"
): MethodDecorator {
return function (
target: any,
propertyKey: string | symbol,
descriptor: any
): void {
if (!target.MedusaContext_) {
throw new Error(
`To apply @InjectEntityManager you have to flag a parameter using @MedusaContext`
)
}
const originalMethod = descriptor.value
const argIndex = target.MedusaContext_[propertyKey]
descriptor.value = async function (...args: any[]) {
const context: SharedContext = args[argIndex] ?? {}
if (context?.transactionManager) {
return await originalMethod.apply(this, args)
}
return await this[managerProperty].transaction(
async (transactionManager) => {
args[argIndex] = args[argIndex] ?? {}
args[argIndex].transactionManager = transactionManager
return await originalMethod.apply(this, args)
}
)
}
}
}
+1
View File
@@ -0,0 +1 @@
export * from "./decorators"
+27
View File
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"lib": ["es2020"],
"target": "es2020",
"outDir": "./dist",
"esModuleInterop": true,
"declaration": true,
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"allowJs": true,
"skipLibCheck": true
},
"include": ["src"],
"exclude": [
"dist",
"./src/**/__tests__",
"./src/**/__mocks__",
"node_modules"
]
}