@medusajs/utils 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decorators/context-parameter.d.ts +1 -0
- package/dist/decorators/context-parameter.js +16 -0
- package/dist/decorators/context-parameter.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +19 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/inject-entity-manager.d.ts +1 -0
- package/dist/decorators/inject-entity-manager.js +25 -0
- package/dist/decorators/inject-entity-manager.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function MedusaContext(): (target: any, propertyKey: string | symbol, parameterIndex: number) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MedusaContext = void 0;
|
|
4
|
+
function MedusaContext() {
|
|
5
|
+
return function (target, propertyKey, parameterIndex) {
|
|
6
|
+
if (!target.MedusaContext_) {
|
|
7
|
+
target.MedusaContext_ = {};
|
|
8
|
+
}
|
|
9
|
+
if (propertyKey in target.MedusaContext_) {
|
|
10
|
+
throw new Error(`Only one MedusaContext is allowed on method "${String(propertyKey)}".`);
|
|
11
|
+
}
|
|
12
|
+
target.MedusaContext_[propertyKey] = parameterIndex;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.MedusaContext = MedusaContext;
|
|
16
|
+
//# sourceMappingURL=context-parameter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-parameter.js","sourceRoot":"","sources":["../../src/decorators/context-parameter.ts"],"names":[],"mappings":";;;AAAA,SAAgB,aAAa;IAC3B,OAAO,UACL,MAAW,EACX,WAA4B,EAC5B,cAAsB;QAEtB,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;YAC1B,MAAM,CAAC,cAAc,GAAG,EAAE,CAAA;SAC3B;QAED,IAAI,WAAW,IAAI,MAAM,CAAC,cAAc,EAAE;YACxC,MAAM,IAAI,KAAK,CACb,gDAAgD,MAAM,CAAC,WAAW,CAAC,IAAI,CACxE,CAAA;SACF;QAED,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,GAAG,cAAc,CAAA;IACrD,CAAC,CAAA;AACH,CAAC;AAlBD,sCAkBC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./context-parameter"), exports);
|
|
18
|
+
__exportStar(require("./inject-entity-manager"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAmC;AACnC,0DAAuC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function InjectEntityManager(managerProperty?: string): MethodDecorator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectEntityManager = void 0;
|
|
4
|
+
function InjectEntityManager(managerProperty = "manager_") {
|
|
5
|
+
return function (target, propertyKey, descriptor) {
|
|
6
|
+
if (!target.MedusaContext_) {
|
|
7
|
+
throw new Error(`To apply @InjectEntityManager you have to flag a parameter using @MedusaContext`);
|
|
8
|
+
}
|
|
9
|
+
const originalMethod = descriptor.value;
|
|
10
|
+
const argIndex = target.MedusaContext_[propertyKey];
|
|
11
|
+
descriptor.value = async function (...args) {
|
|
12
|
+
const context = args[argIndex] ?? {};
|
|
13
|
+
if (context?.transactionManager) {
|
|
14
|
+
return await originalMethod.apply(this, args);
|
|
15
|
+
}
|
|
16
|
+
return await this[managerProperty].transaction(async (transactionManager) => {
|
|
17
|
+
args[argIndex] = args[argIndex] ?? {};
|
|
18
|
+
args[argIndex].transactionManager = transactionManager;
|
|
19
|
+
return await originalMethod.apply(this, args);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.InjectEntityManager = InjectEntityManager;
|
|
25
|
+
//# sourceMappingURL=inject-entity-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-entity-manager.js","sourceRoot":"","sources":["../../src/decorators/inject-entity-manager.ts"],"names":[],"mappings":";;;AAEA,SAAgB,mBAAmB,CACjC,eAAe,GAAG,UAAU;IAE5B,OAAO,UACL,MAAW,EACX,WAA4B,EAC5B,UAAe;QAEf,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;YAC1B,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAA;SACF;QAED,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAA;QAEvC,MAAM,QAAQ,GAAG,MAAM,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;QACnD,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;YAC/C,MAAM,OAAO,GAAkB,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;YAEnD,IAAI,OAAO,EAAE,kBAAkB,EAAE;gBAC/B,OAAO,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;aAC9C;YAED,OAAO,MAAM,IAAI,CAAC,eAAe,CAAC,CAAC,WAAW,CAC5C,KAAK,EAAE,kBAAkB,EAAE,EAAE;gBAC3B,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;gBACrC,IAAI,CAAC,QAAQ,CAAC,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;gBAEtD,OAAO,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YAC/C,CAAC,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AAlCD,kDAkCC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./decorators";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./decorators"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@medusajs/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Medusa utilities functions shared by Medusa core and Modules",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/medusajs/medusa",
|
|
9
|
+
"directory": "packages/utils"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"author": "Medusa",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@medusajs/types": "*",
|
|
21
|
+
"cross-env": "^5.2.1",
|
|
22
|
+
"jest": "^25.5.4",
|
|
23
|
+
"ts-jest": "^25.5.1",
|
|
24
|
+
"typeorm": "^0.3.11",
|
|
25
|
+
"typescript": "^4.4.4"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@medusajs/types": "^0.0.1"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"prepare": "cross-env NODE_ENV=production yarn run build",
|
|
32
|
+
"build": "tsc --build",
|
|
33
|
+
"test": "jest --passWithNoTests src"
|
|
34
|
+
}
|
|
35
|
+
}
|