@medusajs/product 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/index.d.ts +8 -0
- package/dist/index.js +24 -0
- package/dist/initialize/index.d.ts +4 -0
- package/dist/initialize/index.js +11 -0
- package/dist/loaders/connection.d.ts +4 -0
- package/dist/loaders/connection.js +56 -0
- package/dist/loaders/container.d.ts +4 -0
- package/dist/loaders/container.js +76 -0
- package/dist/loaders/index.d.ts +2 -0
- package/dist/loaders/index.js +18 -0
- package/dist/migrations/Migration20230609132805.d.ts +4 -0
- package/dist/migrations/Migration20230609132805.js +42 -0
- package/dist/models/index.d.ts +6 -0
- package/dist/models/index.js +18 -0
- package/dist/models/product-category.d.ts +20 -0
- package/dist/models/product-category.js +123 -0
- package/dist/models/product-collection.d.ts +9 -0
- package/dist/models/product-collection.js +55 -0
- package/dist/models/product-option-value.d.ts +12 -0
- package/dist/models/product-option-value.js +59 -0
- package/dist/models/product-option.d.ts +14 -0
- package/dist/models/product-option.js +68 -0
- package/dist/models/product-tag.d.ts +11 -0
- package/dist/models/product-tag.js +55 -0
- package/dist/models/product-type.d.ts +8 -0
- package/dist/models/product-type.js +44 -0
- package/dist/models/product-variant.d.ts +34 -0
- package/dist/models/product-variant.js +162 -0
- package/dist/models/product.d.ts +43 -0
- package/dist/models/product.js +177 -0
- package/dist/module-definition.d.ts +2 -0
- package/dist/module-definition.js +44 -0
- package/dist/repositories/index.d.ts +5 -0
- package/dist/repositories/index.js +13 -0
- package/dist/repositories/product-category.d.ts +16 -0
- package/dist/repositories/product-category.js +86 -0
- package/dist/repositories/product-collection.d.ts +15 -0
- package/dist/repositories/product-collection.js +46 -0
- package/dist/repositories/product-tag.d.ts +15 -0
- package/dist/repositories/product-tag.js +46 -0
- package/dist/repositories/product-variant.d.ts +15 -0
- package/dist/repositories/product-variant.js +46 -0
- package/dist/repositories/product.d.ts +21 -0
- package/dist/repositories/product.js +72 -0
- package/dist/scripts/bin/run-migration-down.d.ts +2 -0
- package/dist/scripts/bin/run-migration-down.js +31 -0
- package/dist/scripts/bin/run-migration-up.d.ts +2 -0
- package/dist/scripts/bin/run-migration-up.js +31 -0
- package/dist/scripts/bin/run-seed.d.ts +2 -0
- package/dist/scripts/bin/run-seed.js +37 -0
- package/dist/scripts/index.d.ts +2 -0
- package/dist/scripts/index.js +18 -0
- package/dist/scripts/migration-down.d.ts +10 -0
- package/dist/scripts/migration-down.js +51 -0
- package/dist/scripts/migration-up.d.ts +10 -0
- package/dist/scripts/migration-up.js +51 -0
- package/dist/scripts/seed.d.ts +5 -0
- package/dist/scripts/seed.js +87 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.js +18 -0
- package/dist/services/product-category.d.ts +11 -0
- package/dist/services/product-category.js +18 -0
- package/dist/services/product-collection.d.ts +11 -0
- package/dist/services/product-collection.js +17 -0
- package/dist/services/product-module-service.d.ts +25 -0
- package/dist/services/product-module-service.js +36 -0
- package/dist/services/product-tag.d.ts +11 -0
- package/dist/services/product-tag.js +16 -0
- package/dist/services/product-variant.d.ts +11 -0
- package/dist/services/product-variant.js +13 -0
- package/dist/services/product.d.ts +15 -0
- package/dist/services/product.js +43 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/create-connection.d.ts +3 -0
- package/dist/utils/create-connection.js +35 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/load-database-config.d.ts +7 -0
- package/dist/utils/load-database-config.js +59 -0
- package/dist/utils/query/index.d.ts +6 -0
- package/dist/utils/query/index.js +35 -0
- package/package.json +62 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductCategoryRepository = exports.ProductCollectionRepository = exports.ProductVariantRepository = exports.ProductTagRepository = exports.ProductRepository = void 0;
|
|
4
|
+
var product_1 = require("./product");
|
|
5
|
+
Object.defineProperty(exports, "ProductRepository", { enumerable: true, get: function () { return product_1.ProductRepository; } });
|
|
6
|
+
var product_tag_1 = require("./product-tag");
|
|
7
|
+
Object.defineProperty(exports, "ProductTagRepository", { enumerable: true, get: function () { return product_tag_1.ProductTagRepository; } });
|
|
8
|
+
var product_variant_1 = require("./product-variant");
|
|
9
|
+
Object.defineProperty(exports, "ProductVariantRepository", { enumerable: true, get: function () { return product_variant_1.ProductVariantRepository; } });
|
|
10
|
+
var product_collection_1 = require("./product-collection");
|
|
11
|
+
Object.defineProperty(exports, "ProductCollectionRepository", { enumerable: true, get: function () { return product_collection_1.ProductCollectionRepository; } });
|
|
12
|
+
var product_category_1 = require("./product-category");
|
|
13
|
+
Object.defineProperty(exports, "ProductCategoryRepository", { enumerable: true, get: function () { return product_category_1.ProductCategoryRepository; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SqlEntityManager } from "@mikro-orm/postgresql";
|
|
2
|
+
import { ProductCategory } from "../models";
|
|
3
|
+
import { DAL, ProductCategoryTransformOptions } from "@medusajs/types";
|
|
4
|
+
export declare class ProductCategoryRepository implements DAL.RepositoryService<ProductCategory> {
|
|
5
|
+
protected readonly manager_: SqlEntityManager;
|
|
6
|
+
constructor({ manager }: {
|
|
7
|
+
manager: any;
|
|
8
|
+
});
|
|
9
|
+
find(findOptions?: DAL.FindOptions<ProductCategory>, transformOptions?: ProductCategoryTransformOptions, context?: {
|
|
10
|
+
transaction?: any;
|
|
11
|
+
}): Promise<ProductCategory[]>;
|
|
12
|
+
buildProductCategoriesWithDescendants(productCategories: ProductCategory[], findOptions?: DAL.FindOptions<ProductCategory>): Promise<ProductCategory[]>;
|
|
13
|
+
findAndCount(findOptions?: DAL.FindOptions<ProductCategory>, transformOptions?: ProductCategoryTransformOptions, context?: {
|
|
14
|
+
transaction?: any;
|
|
15
|
+
}): Promise<[ProductCategory[], number]>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ProductCategoryRepository = void 0;
|
|
7
|
+
const core_1 = require("@mikro-orm/core");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const _models_1 = require("../models");
|
|
10
|
+
const groupBy_1 = __importDefault(require("lodash/groupBy"));
|
|
11
|
+
class ProductCategoryRepository {
|
|
12
|
+
constructor({ manager }) {
|
|
13
|
+
this.manager_ = manager.fork();
|
|
14
|
+
}
|
|
15
|
+
async find(findOptions = { where: {} }, transformOptions = {}, context = {}) {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
18
|
+
const findOptions_ = { ...findOptions };
|
|
19
|
+
const { includeDescendantsTree } = transformOptions;
|
|
20
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
21
|
+
const fields = ((_a = findOptions_.options).fields ?? (_a.fields = []));
|
|
22
|
+
(_b = findOptions_.options).limit ?? (_b.limit = 15);
|
|
23
|
+
// Ref: Building descendants
|
|
24
|
+
// mpath and parent_category_id needs to be added to the query for the tree building to be done accurately
|
|
25
|
+
if (includeDescendantsTree) {
|
|
26
|
+
fields.indexOf("mpath") === -1 && fields.push("mpath");
|
|
27
|
+
fields.indexOf("parent_category_id") === -1 &&
|
|
28
|
+
fields.push("parent_category_id");
|
|
29
|
+
}
|
|
30
|
+
if (findOptions_.options.populate) {
|
|
31
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
32
|
+
}
|
|
33
|
+
if (context.transaction) {
|
|
34
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
35
|
+
}
|
|
36
|
+
Object.assign(findOptions_.options, {
|
|
37
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
38
|
+
});
|
|
39
|
+
const productCategories = await this.manager_.find(_models_1.ProductCategory, findOptions_.where, findOptions_.options);
|
|
40
|
+
if (!includeDescendantsTree) {
|
|
41
|
+
return productCategories;
|
|
42
|
+
}
|
|
43
|
+
return this.buildProductCategoriesWithDescendants(productCategories, findOptions_);
|
|
44
|
+
}
|
|
45
|
+
async buildProductCategoriesWithDescendants(productCategories, findOptions = { where: {} }) {
|
|
46
|
+
for (let productCategory of productCategories) {
|
|
47
|
+
const whereOptions = {
|
|
48
|
+
...findOptions.where,
|
|
49
|
+
mpath: {
|
|
50
|
+
$like: `${productCategory.mpath}%`,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
delete whereOptions.parent_category_id;
|
|
54
|
+
const descendantsForCategory = await this.manager_.find(_models_1.ProductCategory, whereOptions, findOptions.options);
|
|
55
|
+
const descendantsByParentId = (0, groupBy_1.default)(descendantsForCategory, (pc) => pc.parent_category_id);
|
|
56
|
+
const addChildrenToCategory = (category, children) => {
|
|
57
|
+
category.category_children = (children || []).map((categoryChild) => {
|
|
58
|
+
const moreChildren = descendantsByParentId[categoryChild.id] || [];
|
|
59
|
+
return addChildrenToCategory(categoryChild, moreChildren);
|
|
60
|
+
});
|
|
61
|
+
return category;
|
|
62
|
+
};
|
|
63
|
+
let children = descendantsByParentId[productCategory.id] || [];
|
|
64
|
+
productCategory = addChildrenToCategory(productCategory, children);
|
|
65
|
+
}
|
|
66
|
+
return productCategories;
|
|
67
|
+
}
|
|
68
|
+
async findAndCount(findOptions = { where: {} }, transformOptions = {}, context = {}) {
|
|
69
|
+
var _a;
|
|
70
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
71
|
+
const findOptions_ = { ...findOptions };
|
|
72
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
73
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
74
|
+
if (findOptions_.options.populate) {
|
|
75
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
76
|
+
}
|
|
77
|
+
if (context.transaction) {
|
|
78
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
79
|
+
}
|
|
80
|
+
Object.assign(findOptions_.options, {
|
|
81
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
82
|
+
});
|
|
83
|
+
return await this.manager_.findAndCount(_models_1.ProductCategory, findOptions_.where, findOptions_.options);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.ProductCategoryRepository = ProductCategoryRepository;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SqlEntityManager } from "@mikro-orm/postgresql";
|
|
2
|
+
import { ProductCollection } from "../models";
|
|
3
|
+
import { DAL } from "@medusajs/types";
|
|
4
|
+
export declare class ProductCollectionRepository implements DAL.RepositoryService {
|
|
5
|
+
protected readonly manager_: SqlEntityManager;
|
|
6
|
+
constructor({ manager }: {
|
|
7
|
+
manager: any;
|
|
8
|
+
});
|
|
9
|
+
find<T = ProductCollection>(findOptions?: DAL.FindOptions<T>, context?: {
|
|
10
|
+
transaction?: any;
|
|
11
|
+
}): Promise<T[]>;
|
|
12
|
+
findAndCount<T = ProductCollection>(findOptions?: DAL.FindOptions<T>, context?: {
|
|
13
|
+
transaction?: any;
|
|
14
|
+
}): Promise<[T[], number]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductCollectionRepository = void 0;
|
|
4
|
+
const _models_1 = require("../models");
|
|
5
|
+
const core_1 = require("@mikro-orm/core");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
class ProductCollectionRepository {
|
|
8
|
+
constructor({ manager }) {
|
|
9
|
+
this.manager_ = manager.fork();
|
|
10
|
+
}
|
|
11
|
+
async find(findOptions = { where: {} }, context = {}) {
|
|
12
|
+
var _a;
|
|
13
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
14
|
+
const findOptions_ = { ...findOptions };
|
|
15
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
16
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
17
|
+
if (findOptions_.options.populate) {
|
|
18
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
19
|
+
}
|
|
20
|
+
if (context.transaction) {
|
|
21
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
22
|
+
}
|
|
23
|
+
Object.assign(findOptions_.options, {
|
|
24
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
25
|
+
});
|
|
26
|
+
return (await this.manager_.find(_models_1.ProductCollection, findOptions_.where, findOptions_.options));
|
|
27
|
+
}
|
|
28
|
+
async findAndCount(findOptions = { where: {} }, context = {}) {
|
|
29
|
+
var _a;
|
|
30
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
31
|
+
const findOptions_ = { ...findOptions };
|
|
32
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
33
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
34
|
+
if (findOptions_.options.populate) {
|
|
35
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
36
|
+
}
|
|
37
|
+
if (context.transaction) {
|
|
38
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
39
|
+
}
|
|
40
|
+
Object.assign(findOptions_.options, {
|
|
41
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
42
|
+
});
|
|
43
|
+
return (await this.manager_.findAndCount(_models_1.ProductCollection, findOptions_.where, findOptions_.options));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ProductCollectionRepository = ProductCollectionRepository;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SqlEntityManager } from "@mikro-orm/postgresql";
|
|
2
|
+
import { ProductTag } from "../models";
|
|
3
|
+
import { DAL } from "@medusajs/types";
|
|
4
|
+
export declare class ProductTagRepository implements DAL.RepositoryService {
|
|
5
|
+
protected readonly manager_: SqlEntityManager;
|
|
6
|
+
constructor({ manager }: {
|
|
7
|
+
manager: any;
|
|
8
|
+
});
|
|
9
|
+
find<T = ProductTag>(findOptions?: DAL.FindOptions<T>, context?: {
|
|
10
|
+
transaction?: any;
|
|
11
|
+
}): Promise<T[]>;
|
|
12
|
+
findAndCount<T = ProductTag>(findOptions?: DAL.FindOptions<T>, context?: {
|
|
13
|
+
transaction?: any;
|
|
14
|
+
}): Promise<[T[], number]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductTagRepository = void 0;
|
|
4
|
+
const core_1 = require("@mikro-orm/core");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const _models_1 = require("../models");
|
|
7
|
+
class ProductTagRepository {
|
|
8
|
+
constructor({ manager }) {
|
|
9
|
+
this.manager_ = manager.fork();
|
|
10
|
+
}
|
|
11
|
+
async find(findOptions = { where: {} }, context = {}) {
|
|
12
|
+
var _a;
|
|
13
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
14
|
+
const findOptions_ = { ...findOptions };
|
|
15
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
16
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
17
|
+
if (findOptions_.options.populate) {
|
|
18
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
19
|
+
}
|
|
20
|
+
if (context.transaction) {
|
|
21
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
22
|
+
}
|
|
23
|
+
Object.assign(findOptions_.options, {
|
|
24
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
25
|
+
});
|
|
26
|
+
return (await this.manager_.find(_models_1.ProductTag, findOptions_.where, findOptions_.options));
|
|
27
|
+
}
|
|
28
|
+
async findAndCount(findOptions = { where: {} }, context = {}) {
|
|
29
|
+
var _a;
|
|
30
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
31
|
+
const findOptions_ = { ...findOptions };
|
|
32
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
33
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
34
|
+
if (findOptions_.options.populate) {
|
|
35
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
36
|
+
}
|
|
37
|
+
if (context.transaction) {
|
|
38
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
39
|
+
}
|
|
40
|
+
Object.assign(findOptions_.options, {
|
|
41
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
42
|
+
});
|
|
43
|
+
return (await this.manager_.findAndCount(_models_1.ProductTag, findOptions_.where, findOptions_.options));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ProductTagRepository = ProductTagRepository;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SqlEntityManager } from "@mikro-orm/postgresql";
|
|
2
|
+
import { ProductVariant } from "../models";
|
|
3
|
+
import { DAL } from "@medusajs/types";
|
|
4
|
+
export declare class ProductVariantRepository implements DAL.RepositoryService {
|
|
5
|
+
protected readonly manager_: SqlEntityManager;
|
|
6
|
+
constructor({ manager }: {
|
|
7
|
+
manager: any;
|
|
8
|
+
});
|
|
9
|
+
find<T = ProductVariant>(findOptions?: DAL.FindOptions<T>, context?: {
|
|
10
|
+
transaction?: any;
|
|
11
|
+
}): Promise<T[]>;
|
|
12
|
+
findAndCount<T = ProductVariant>(findOptions?: DAL.FindOptions<T>, context?: {
|
|
13
|
+
transaction?: any;
|
|
14
|
+
}): Promise<[T[], number]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductVariantRepository = void 0;
|
|
4
|
+
const core_1 = require("@mikro-orm/core");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const _models_1 = require("../models");
|
|
7
|
+
class ProductVariantRepository {
|
|
8
|
+
constructor({ manager }) {
|
|
9
|
+
this.manager_ = manager.fork();
|
|
10
|
+
}
|
|
11
|
+
async find(findOptions = { where: {} }, context = {}) {
|
|
12
|
+
var _a;
|
|
13
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
14
|
+
const findOptions_ = { ...findOptions };
|
|
15
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
16
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
17
|
+
if (findOptions_.options.populate) {
|
|
18
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
19
|
+
}
|
|
20
|
+
if (context.transaction) {
|
|
21
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
22
|
+
}
|
|
23
|
+
Object.assign(findOptions_.options, {
|
|
24
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
25
|
+
});
|
|
26
|
+
return (await this.manager_.find(_models_1.ProductVariant, findOptions_.where, findOptions_.options));
|
|
27
|
+
}
|
|
28
|
+
async findAndCount(findOptions = { where: {} }, context = {}) {
|
|
29
|
+
var _a;
|
|
30
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
31
|
+
const findOptions_ = { ...findOptions };
|
|
32
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
33
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
34
|
+
if (findOptions_.options.populate) {
|
|
35
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
36
|
+
}
|
|
37
|
+
if (context.transaction) {
|
|
38
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
39
|
+
}
|
|
40
|
+
Object.assign(findOptions_.options, {
|
|
41
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
42
|
+
});
|
|
43
|
+
return (await this.manager_.findAndCount(_models_1.ProductVariant, findOptions_.where, findOptions_.options));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ProductVariantRepository = ProductVariantRepository;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SqlEntityManager } from "@mikro-orm/postgresql";
|
|
2
|
+
import { Product } from "../models";
|
|
3
|
+
import { DAL } from "@medusajs/types";
|
|
4
|
+
export declare class ProductRepository implements DAL.RepositoryService<Product> {
|
|
5
|
+
protected readonly manager_: SqlEntityManager;
|
|
6
|
+
constructor({ manager }: {
|
|
7
|
+
manager: any;
|
|
8
|
+
});
|
|
9
|
+
find(findOptions?: DAL.FindOptions<Product>, context?: {
|
|
10
|
+
transaction?: any;
|
|
11
|
+
}): Promise<Product[]>;
|
|
12
|
+
findAndCount(findOptions?: DAL.FindOptions<Product>, context?: {
|
|
13
|
+
transaction?: any;
|
|
14
|
+
}): Promise<[Product[], number]>;
|
|
15
|
+
/**
|
|
16
|
+
* In order to be able to have a strict not in categories, and prevent a product
|
|
17
|
+
* to be return in the case it also belongs to other categories, we need to
|
|
18
|
+
* first find all products that are in the categories, and then exclude them
|
|
19
|
+
*/
|
|
20
|
+
private mutateNotInCategoriesConstraints;
|
|
21
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProductRepository = void 0;
|
|
4
|
+
const _models_1 = require("../models");
|
|
5
|
+
const core_1 = require("@mikro-orm/core");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
class ProductRepository {
|
|
8
|
+
constructor({ manager }) {
|
|
9
|
+
this.manager_ = manager.fork();
|
|
10
|
+
}
|
|
11
|
+
async find(findOptions = { where: {} }, context = {}) {
|
|
12
|
+
var _a;
|
|
13
|
+
// Spread is used to cssopy the options in case of manipulation to prevent side effects
|
|
14
|
+
const findOptions_ = { ...findOptions };
|
|
15
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
16
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
17
|
+
if (findOptions_.options.populate) {
|
|
18
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
19
|
+
}
|
|
20
|
+
if (context.transaction) {
|
|
21
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
22
|
+
}
|
|
23
|
+
Object.assign(findOptions_.options, {
|
|
24
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
25
|
+
});
|
|
26
|
+
await this.mutateNotInCategoriesConstraints(findOptions_);
|
|
27
|
+
return await this.manager_.find(_models_1.Product, findOptions_.where, findOptions_.options);
|
|
28
|
+
}
|
|
29
|
+
async findAndCount(findOptions = { where: {} }, context = {}) {
|
|
30
|
+
var _a;
|
|
31
|
+
// Spread is used to copy the options in case of manipulation to prevent side effects
|
|
32
|
+
const findOptions_ = { ...findOptions };
|
|
33
|
+
findOptions_.options ?? (findOptions_.options = {});
|
|
34
|
+
(_a = findOptions_.options).limit ?? (_a.limit = 15);
|
|
35
|
+
if (findOptions_.options.populate) {
|
|
36
|
+
(0, utils_1.deduplicateIfNecessary)(findOptions_.options.populate);
|
|
37
|
+
}
|
|
38
|
+
if (context.transaction) {
|
|
39
|
+
Object.assign(findOptions_.options, { ctx: context.transaction });
|
|
40
|
+
}
|
|
41
|
+
Object.assign(findOptions_.options, {
|
|
42
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
|
43
|
+
});
|
|
44
|
+
await this.mutateNotInCategoriesConstraints(findOptions_);
|
|
45
|
+
return await this.manager_.findAndCount(_models_1.Product, findOptions_.where, findOptions_.options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* In order to be able to have a strict not in categories, and prevent a product
|
|
49
|
+
* to be return in the case it also belongs to other categories, we need to
|
|
50
|
+
* first find all products that are in the categories, and then exclude them
|
|
51
|
+
*/
|
|
52
|
+
async mutateNotInCategoriesConstraints(findOptions = { where: {} }) {
|
|
53
|
+
if (findOptions.where.categories?.id?.["$nin"]) {
|
|
54
|
+
const productsInCategories = await this.manager_.find(_models_1.Product, {
|
|
55
|
+
categories: {
|
|
56
|
+
id: { $in: findOptions.where.categories.id["$nin"] },
|
|
57
|
+
},
|
|
58
|
+
}, {
|
|
59
|
+
fields: ["id"],
|
|
60
|
+
});
|
|
61
|
+
const productIds = productsInCategories.map((product) => product.id);
|
|
62
|
+
if (productIds.length) {
|
|
63
|
+
findOptions.where.id = { $nin: productIds };
|
|
64
|
+
delete findOptions.where.categories?.id;
|
|
65
|
+
if (Object.keys(findOptions.where.categories).length === 0) {
|
|
66
|
+
delete findOptions.where.categories;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.ProductRepository = ProductRepository;
|
|
@@ -0,0 +1,31 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const migration_down_1 = require("../migration-down");
|
|
27
|
+
exports.default = (async () => {
|
|
28
|
+
const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
|
|
29
|
+
config();
|
|
30
|
+
await (0, migration_down_1.revertMigration)();
|
|
31
|
+
})();
|
|
@@ -0,0 +1,31 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const migration_up_1 = require("../migration-up");
|
|
27
|
+
exports.default = (async () => {
|
|
28
|
+
const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
|
|
29
|
+
config();
|
|
30
|
+
await (0, migration_up_1.runMigrations)();
|
|
31
|
+
})();
|
|
@@ -0,0 +1,37 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const seed_1 = require("../seed");
|
|
27
|
+
const os_1 = require("os");
|
|
28
|
+
const args = process.argv;
|
|
29
|
+
const path = args.pop();
|
|
30
|
+
exports.default = (async () => {
|
|
31
|
+
const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
|
|
32
|
+
config();
|
|
33
|
+
if (!path) {
|
|
34
|
+
throw new Error(`filePath is required.${os_1.EOL}Example: node_modules/@medusajs/product/dist/scripts/bin/run-seed.js <filePath>`);
|
|
35
|
+
}
|
|
36
|
+
await (0, seed_1.run)({ path });
|
|
37
|
+
})();
|
|
@@ -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("./migration-up"), exports);
|
|
18
|
+
__exportStar(require("./migration-down"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoaderOptions } from "@medusajs/types";
|
|
2
|
+
import { ProductServiceInitializeCustomDataLayerOptions, ProductServiceInitializeOptions } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* This script is only valid for mikro orm managers. If a user provide a custom manager
|
|
5
|
+
* he is in charge of reverting the migrations.
|
|
6
|
+
* @param options
|
|
7
|
+
* @param logger
|
|
8
|
+
* @param moduleDeclaration
|
|
9
|
+
*/
|
|
10
|
+
export declare function revertMigration({ options, logger, }?: Pick<LoaderOptions<ProductServiceInitializeOptions | ProductServiceInitializeCustomDataLayerOptions>, "options" | "logger">): Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.revertMigration = void 0;
|
|
27
|
+
const utils_1 = require("../utils");
|
|
28
|
+
const ProductModels = __importStar(require("../models"));
|
|
29
|
+
/**
|
|
30
|
+
* This script is only valid for mikro orm managers. If a user provide a custom manager
|
|
31
|
+
* he is in charge of reverting the migrations.
|
|
32
|
+
* @param options
|
|
33
|
+
* @param logger
|
|
34
|
+
* @param moduleDeclaration
|
|
35
|
+
*/
|
|
36
|
+
async function revertMigration({ options, logger, } = {}) {
|
|
37
|
+
logger ?? (logger = console);
|
|
38
|
+
const dbData = (0, utils_1.loadDatabaseConfig)(options);
|
|
39
|
+
const entities = Object.values(ProductModels);
|
|
40
|
+
const orm = await (0, utils_1.createConnection)(dbData, entities);
|
|
41
|
+
try {
|
|
42
|
+
const migrator = orm.getMigrator();
|
|
43
|
+
await migrator.down();
|
|
44
|
+
logger?.info("Product module migration executed");
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
logger?.error(`Product module migration failed to run - Error: ${error}`);
|
|
48
|
+
}
|
|
49
|
+
await orm.close();
|
|
50
|
+
}
|
|
51
|
+
exports.revertMigration = revertMigration;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoaderOptions } from "@medusajs/types";
|
|
2
|
+
import { ProductServiceInitializeCustomDataLayerOptions, ProductServiceInitializeOptions } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* This script is only valid for mikro orm managers. If a user provide a custom manager
|
|
5
|
+
* he is in charge of running the migrations.
|
|
6
|
+
* @param options
|
|
7
|
+
* @param logger
|
|
8
|
+
* @param moduleDeclaration
|
|
9
|
+
*/
|
|
10
|
+
export declare function runMigrations({ options, logger, }?: Pick<LoaderOptions<ProductServiceInitializeOptions | ProductServiceInitializeCustomDataLayerOptions>, "options" | "logger">): Promise<void>;
|