@medusajs/product 0.3.8 → 0.3.9-next-20240208080225

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.
Files changed (49) hide show
  1. package/dist/joiner-config.js +16 -51
  2. package/dist/models/product-category.d.ts +2 -1
  3. package/dist/models/product-category.js +9 -0
  4. package/dist/models/product-collection.d.ts +2 -1
  5. package/dist/models/product-collection.js +9 -0
  6. package/dist/models/product-image.d.ts +2 -1
  7. package/dist/models/product-image.js +9 -0
  8. package/dist/models/product-option-value.d.ts +2 -1
  9. package/dist/models/product-option-value.js +10 -1
  10. package/dist/models/product-option.d.ts +1 -0
  11. package/dist/models/product-option.js +9 -0
  12. package/dist/models/product-tag.d.ts +2 -1
  13. package/dist/models/product-tag.js +9 -0
  14. package/dist/models/product-type.d.ts +1 -0
  15. package/dist/models/product-type.js +9 -0
  16. package/dist/models/product-variant.d.ts +2 -1
  17. package/dist/models/product-variant.js +9 -0
  18. package/dist/models/product.d.ts +3 -2
  19. package/dist/models/product.js +11 -2
  20. package/dist/repositories/product-image.d.ts +4 -30
  21. package/dist/repositories/product-image.js +1 -1
  22. package/dist/repositories/product.d.ts +8 -31
  23. package/dist/repositories/product.js +3 -8
  24. package/dist/scripts/bin/run-seed.js +0 -0
  25. package/dist/services/index.d.ts +0 -2
  26. package/dist/services/index.js +1 -5
  27. package/dist/services/product-collection.d.ts +8 -14
  28. package/dist/services/product-collection.js +11 -6
  29. package/dist/services/product-module-service.d.ts +48 -49
  30. package/dist/services/product-module-service.js +45 -418
  31. package/dist/services/product-option.d.ts +4 -12
  32. package/dist/services/product-option.js +1 -1
  33. package/dist/services/product-tag.d.ts +4 -12
  34. package/dist/services/product-tag.js +1 -1
  35. package/dist/services/product-type.d.ts +4 -12
  36. package/dist/services/product-type.js +1 -1
  37. package/dist/services/product-variant.d.ts +3 -10
  38. package/dist/services/product-variant.js +2 -4
  39. package/dist/services/product.d.ts +4 -12
  40. package/dist/services/product.js +1 -1
  41. package/dist/types/index.d.ts +0 -1
  42. package/dist/types/index.js +0 -1
  43. package/package.json +4 -4
  44. package/dist/services/product-image.d.ts +0 -17
  45. package/dist/services/product-image.js +0 -11
  46. package/dist/services/product-option-value.d.ts +0 -18
  47. package/dist/services/product-option-value.js +0 -11
  48. package/dist/types/repositories.d.ts +0 -43
  49. package/dist/types/repositories.js +0 -2
@@ -36,92 +36,57 @@ exports.joinerConfig = {
36
36
  schema: schema_1.default,
37
37
  alias: [
38
38
  {
39
- name: "product",
40
- },
41
- {
42
- name: "products",
43
- },
44
- {
45
- name: "variant",
39
+ name: ["product", "products"],
46
40
  args: {
47
- methodSuffix: "Variants",
41
+ entity: "Product",
48
42
  },
49
43
  },
50
44
  {
51
- name: "variants",
45
+ name: ["variant", "variants"],
52
46
  args: {
47
+ entity: "ProductVariant",
53
48
  methodSuffix: "Variants",
54
49
  },
55
50
  },
56
51
  {
57
- name: "product_option",
58
- args: {
59
- methodSuffix: "Options",
60
- },
61
- },
62
- {
63
- name: "product_options",
52
+ name: ["product_option", "product_options"],
64
53
  args: {
54
+ entity: "ProductOption",
65
55
  methodSuffix: "Options",
66
56
  },
67
57
  },
68
58
  {
69
- name: "product_type",
59
+ name: ["product_type", "product_types"],
70
60
  args: {
61
+ entity: "ProductType",
71
62
  methodSuffix: "Types",
72
63
  },
73
64
  },
74
65
  {
75
- name: "product_types",
76
- args: {
77
- methodSuffix: "Types",
78
- },
79
- },
80
- {
81
- name: "product_image",
66
+ name: ["product_image", "product_images"],
82
67
  args: {
68
+ entity: "ProductImage",
83
69
  methodSuffix: "Images",
84
70
  },
85
71
  },
86
72
  {
87
- name: "product_images",
88
- args: {
89
- methodSuffix: "Images",
90
- },
91
- },
92
- {
93
- name: "product_tag",
73
+ name: ["product_tag", "product_tags"],
94
74
  args: {
75
+ entity: "ProductTag",
95
76
  methodSuffix: "Tags",
96
77
  },
97
78
  },
98
79
  {
99
- name: "product_tags",
100
- args: {
101
- methodSuffix: "Tags",
102
- },
103
- },
104
- {
105
- name: "product_collection",
80
+ name: ["product_collection", "product_collections"],
106
81
  args: {
82
+ entity: "ProductCollection",
107
83
  methodSuffix: "Collections",
108
84
  },
109
85
  },
110
86
  {
111
- name: "product_collections",
112
- args: {
113
- methodSuffix: "Collections",
114
- },
115
- },
116
- {
117
- name: "product_category",
118
- args: {
119
- methodSuffix: "Categories",
120
- },
121
- },
122
- {
123
- name: "product_categories",
87
+ name: ["product_category", "product_categories"],
124
88
  args: {
89
+ entity: "ProductCategory",
125
90
  methodSuffix: "Categories",
126
91
  },
127
92
  },
@@ -1,6 +1,6 @@
1
1
  import { Collection, EventArgs, OptionalProps } from "@mikro-orm/core";
2
- import Product from "./product";
3
2
  import { DAL } from "@medusajs/types";
3
+ import Product from "./product";
4
4
  type OptionalFields = DAL.SoftDeletableEntityDateColumns;
5
5
  declare class ProductCategory {
6
6
  [OptionalProps]?: OptionalFields;
@@ -18,6 +18,7 @@ declare class ProductCategory {
18
18
  created_at?: Date;
19
19
  updated_at?: Date;
20
20
  products: Collection<Product, object>;
21
+ onInit(): Promise<void>;
21
22
  onCreate(args: EventArgs<ProductCategory>): Promise<void>;
22
23
  }
23
24
  export default ProductCategory;
@@ -21,6 +21,9 @@ let ProductCategory = ProductCategory_1 = class ProductCategory {
21
21
  this.category_children = new core_1.Collection(this);
22
22
  this.products = new core_1.Collection(this);
23
23
  }
24
+ async onInit() {
25
+ this.id = (0, utils_1.generateEntityId)(this.id, "pcat");
26
+ }
24
27
  async onCreate(args) {
25
28
  this.id = (0, utils_1.generateEntityId)(this.id, "pcat");
26
29
  if (!this.handle) {
@@ -116,6 +119,12 @@ __decorate([
116
119
  (0, core_1.ManyToMany)(() => product_1.default, (product) => product.categories),
117
120
  __metadata("design:type", Object)
118
121
  ], ProductCategory.prototype, "products", void 0);
122
+ __decorate([
123
+ (0, core_1.OnInit)(),
124
+ __metadata("design:type", Function),
125
+ __metadata("design:paramtypes", []),
126
+ __metadata("design:returntype", Promise)
127
+ ], ProductCategory.prototype, "onInit", null);
119
128
  __decorate([
120
129
  (0, core_1.BeforeCreate)(),
121
130
  __metadata("design:type", Function),
@@ -1,6 +1,6 @@
1
1
  import { Collection, OptionalProps } from "@mikro-orm/core";
2
- import Product from "./product";
3
2
  import { DAL } from "@medusajs/types";
3
+ import Product from "./product";
4
4
  type OptionalRelations = "products";
5
5
  type OptionalFields = DAL.SoftDeletableEntityDateColumns;
6
6
  declare class ProductCollection {
@@ -13,6 +13,7 @@ declare class ProductCollection {
13
13
  created_at: Date;
14
14
  updated_at: Date;
15
15
  deleted_at?: Date;
16
+ onInit(): void;
16
17
  onCreate(): void;
17
18
  }
18
19
  export default ProductCollection;
@@ -19,6 +19,9 @@ let ProductCollection = class ProductCollection {
19
19
  constructor() {
20
20
  this.products = new core_1.Collection(this);
21
21
  }
22
+ onInit() {
23
+ this.id = (0, utils_1.generateEntityId)(this.id, "pcol");
24
+ }
22
25
  onCreate() {
23
26
  this.id = (0, utils_1.generateEntityId)(this.id, "pcol");
24
27
  if (!this.handle) {
@@ -72,6 +75,12 @@ __decorate([
72
75
  (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
73
76
  __metadata("design:type", Date)
74
77
  ], ProductCollection.prototype, "deleted_at", void 0);
78
+ __decorate([
79
+ (0, core_1.OnInit)(),
80
+ __metadata("design:type", Function),
81
+ __metadata("design:paramtypes", []),
82
+ __metadata("design:returntype", void 0)
83
+ ], ProductCollection.prototype, "onInit", null);
75
84
  __decorate([
76
85
  (0, core_1.BeforeCreate)(),
77
86
  __metadata("design:type", Function),
@@ -1,6 +1,6 @@
1
1
  import { Collection, OptionalProps } from "@mikro-orm/core";
2
- import Product from "./product";
3
2
  import { DAL } from "@medusajs/types";
3
+ import Product from "./product";
4
4
  type OptionalRelations = "products";
5
5
  type OptionalFields = DAL.SoftDeletableEntityDateColumns;
6
6
  declare class ProductImage {
@@ -12,6 +12,7 @@ declare class ProductImage {
12
12
  updated_at: Date;
13
13
  deleted_at?: Date;
14
14
  products: Collection<Product, object>;
15
+ onInit(): void;
15
16
  onCreate(): void;
16
17
  }
17
18
  export default ProductImage;
@@ -19,6 +19,9 @@ let ProductImage = class ProductImage {
19
19
  constructor() {
20
20
  this.products = new core_1.Collection(this);
21
21
  }
22
+ onInit() {
23
+ this.id = (0, utils_1.generateEntityId)(this.id, "img");
24
+ }
22
25
  onCreate() {
23
26
  this.id = (0, utils_1.generateEntityId)(this.id, "img");
24
27
  }
@@ -62,6 +65,12 @@ __decorate([
62
65
  (0, core_1.ManyToMany)(() => product_1.default, (product) => product.images),
63
66
  __metadata("design:type", Object)
64
67
  ], ProductImage.prototype, "products", void 0);
68
+ __decorate([
69
+ (0, core_1.OnInit)(),
70
+ __metadata("design:type", Function),
71
+ __metadata("design:paramtypes", []),
72
+ __metadata("design:returntype", void 0)
73
+ ], ProductImage.prototype, "onInit", null);
65
74
  __decorate([
66
75
  (0, core_1.BeforeCreate)(),
67
76
  __metadata("design:type", Function),
@@ -1,6 +1,6 @@
1
+ import { DAL } from "@medusajs/types";
1
2
  import { OptionalProps } from "@mikro-orm/core";
2
3
  import { ProductOption, ProductVariant } from "./index";
3
- import { DAL } from "@medusajs/types";
4
4
  type OptionalFields = "allow_backorder" | "manage_inventory" | "option_id" | "variant_id" | DAL.SoftDeletableEntityDateColumns;
5
5
  type OptionalRelations = "product" | "option" | "variant";
6
6
  declare class ProductOptionValue {
@@ -15,6 +15,7 @@ declare class ProductOptionValue {
15
15
  created_at: Date;
16
16
  updated_at: Date;
17
17
  deleted_at?: Date;
18
+ onInit(): void;
18
19
  beforeCreate(): void;
19
20
  }
20
21
  export default ProductOptionValue;
@@ -9,10 +9,13 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const utils_1 = require("@medusajs/utils");
12
13
  const core_1 = require("@mikro-orm/core");
13
14
  const index_1 = require("./index");
14
- const utils_1 = require("@medusajs/utils");
15
15
  let ProductOptionValue = class ProductOptionValue {
16
+ onInit() {
17
+ this.id = (0, utils_1.generateEntityId)(this.id, "optval");
18
+ }
16
19
  beforeCreate() {
17
20
  this.id = (0, utils_1.generateEntityId)(this.id, "optval");
18
21
  }
@@ -74,6 +77,12 @@ __decorate([
74
77
  (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
75
78
  __metadata("design:type", Date)
76
79
  ], ProductOptionValue.prototype, "deleted_at", void 0);
80
+ __decorate([
81
+ (0, core_1.OnInit)(),
82
+ __metadata("design:type", Function),
83
+ __metadata("design:paramtypes", []),
84
+ __metadata("design:returntype", void 0)
85
+ ], ProductOptionValue.prototype, "onInit", null);
77
86
  __decorate([
78
87
  (0, core_1.BeforeCreate)(),
79
88
  __metadata("design:type", Function),
@@ -15,6 +15,7 @@ declare class ProductOption {
15
15
  created_at: Date;
16
16
  updated_at: Date;
17
17
  deleted_at?: Date;
18
+ onInit(): void;
18
19
  beforeCreate(): void;
19
20
  }
20
21
  export default ProductOption;
@@ -20,6 +20,9 @@ let ProductOption = class ProductOption {
20
20
  constructor() {
21
21
  this.values = new core_1.Collection(this);
22
22
  }
23
+ onInit() {
24
+ this.id = (0, utils_1.generateEntityId)(this.id, "opt");
25
+ }
23
26
  beforeCreate() {
24
27
  this.id = (0, utils_1.generateEntityId)(this.id, "opt");
25
28
  }
@@ -76,6 +79,12 @@ __decorate([
76
79
  (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
77
80
  __metadata("design:type", Date)
78
81
  ], ProductOption.prototype, "deleted_at", void 0);
82
+ __decorate([
83
+ (0, core_1.OnInit)(),
84
+ __metadata("design:type", Function),
85
+ __metadata("design:paramtypes", []),
86
+ __metadata("design:returntype", void 0)
87
+ ], ProductOption.prototype, "onInit", null);
79
88
  __decorate([
80
89
  (0, core_1.BeforeCreate)(),
81
90
  __metadata("design:type", Function),
@@ -1,6 +1,6 @@
1
1
  import { Collection, OptionalProps } from "@mikro-orm/core";
2
- import Product from "./product";
3
2
  import { DAL } from "@medusajs/types";
3
+ import Product from "./product";
4
4
  type OptionalRelations = "products";
5
5
  type OptionalFields = DAL.SoftDeletableEntityDateColumns;
6
6
  declare class ProductTag {
@@ -12,6 +12,7 @@ declare class ProductTag {
12
12
  updated_at: Date;
13
13
  deleted_at?: Date;
14
14
  products: Collection<Product, object>;
15
+ onInit(): void;
15
16
  onCreate(): void;
16
17
  }
17
18
  export default ProductTag;
@@ -19,6 +19,9 @@ let ProductTag = class ProductTag {
19
19
  constructor() {
20
20
  this.products = new core_1.Collection(this);
21
21
  }
22
+ onInit() {
23
+ this.id = (0, utils_1.generateEntityId)(this.id, "ptag");
24
+ }
22
25
  onCreate() {
23
26
  this.id = (0, utils_1.generateEntityId)(this.id, "ptag");
24
27
  }
@@ -61,6 +64,12 @@ __decorate([
61
64
  (0, core_1.ManyToMany)(() => product_1.default, (product) => product.tags),
62
65
  __metadata("design:type", Object)
63
66
  ], ProductTag.prototype, "products", void 0);
67
+ __decorate([
68
+ (0, core_1.OnInit)(),
69
+ __metadata("design:type", Function),
70
+ __metadata("design:paramtypes", []),
71
+ __metadata("design:returntype", void 0)
72
+ ], ProductTag.prototype, "onInit", null);
64
73
  __decorate([
65
74
  (0, core_1.BeforeCreate)(),
66
75
  __metadata("design:type", Function),
@@ -9,6 +9,7 @@ declare class ProductType {
9
9
  created_at: Date;
10
10
  updated_at: Date;
11
11
  deleted_at?: Date;
12
+ onInit(): void;
12
13
  onCreate(): void;
13
14
  }
14
15
  export default ProductType;
@@ -12,6 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const core_1 = require("@mikro-orm/core");
13
13
  const utils_1 = require("@medusajs/utils");
14
14
  let ProductType = class ProductType {
15
+ onInit() {
16
+ this.id = (0, utils_1.generateEntityId)(this.id, "ptyp");
17
+ }
15
18
  onCreate() {
16
19
  this.id = (0, utils_1.generateEntityId)(this.id, "ptyp");
17
20
  }
@@ -50,6 +53,12 @@ __decorate([
50
53
  (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
51
54
  __metadata("design:type", Date)
52
55
  ], ProductType.prototype, "deleted_at", void 0);
56
+ __decorate([
57
+ (0, core_1.OnInit)(),
58
+ __metadata("design:type", Function),
59
+ __metadata("design:paramtypes", []),
60
+ __metadata("design:returntype", void 0)
61
+ ], ProductType.prototype, "onInit", null);
53
62
  __decorate([
54
63
  (0, core_1.BeforeCreate)(),
55
64
  __metadata("design:type", Function),
@@ -1,7 +1,7 @@
1
+ import { DAL } from "@medusajs/types";
1
2
  import { Collection, OptionalProps } from "@mikro-orm/core";
2
3
  import { Product } from ".";
3
4
  import ProductOptionValue from "./product-option-value";
4
- import { DAL } from "@medusajs/types";
5
5
  type OptionalFields = "allow_backorder" | "manage_inventory" | "product" | "product_id" | DAL.SoftDeletableEntityDateColumns;
6
6
  declare class ProductVariant {
7
7
  [OptionalProps]?: OptionalFields;
@@ -30,6 +30,7 @@ declare class ProductVariant {
30
30
  deleted_at?: Date;
31
31
  product: Product;
32
32
  options: Collection<ProductOptionValue, object>;
33
+ onInit(): void;
33
34
  onCreate(): void;
34
35
  }
35
36
  export default ProductVariant;
@@ -26,6 +26,9 @@ let ProductVariant = class ProductVariant {
26
26
  this.manage_inventory = true;
27
27
  this.options = new core_1.Collection(this);
28
28
  }
29
+ onInit() {
30
+ this.id = (0, utils_1.generateEntityId)(this.id, "variant");
31
+ }
29
32
  onCreate() {
30
33
  this.id = (0, utils_1.generateEntityId)(this.id, "variant");
31
34
  }
@@ -171,6 +174,12 @@ __decorate([
171
174
  }),
172
175
  __metadata("design:type", Object)
173
176
  ], ProductVariant.prototype, "options", void 0);
177
+ __decorate([
178
+ (0, core_1.OnInit)(),
179
+ __metadata("design:type", Function),
180
+ __metadata("design:paramtypes", []),
181
+ __metadata("design:returntype", void 0)
182
+ ], ProductVariant.prototype, "onInit", null);
174
183
  __decorate([
175
184
  (0, core_1.BeforeCreate)(),
176
185
  __metadata("design:type", Function),
@@ -1,13 +1,13 @@
1
1
  import { Collection, OptionalProps } from "@mikro-orm/core";
2
+ import { DAL } from "@medusajs/types";
2
3
  import { ProductUtils } from "@medusajs/utils";
3
4
  import ProductCategory from "./product-category";
4
5
  import ProductCollection from "./product-collection";
6
+ import ProductImage from "./product-image";
5
7
  import ProductOption from "./product-option";
6
8
  import ProductTag from "./product-tag";
7
9
  import ProductType from "./product-type";
8
10
  import ProductVariant from "./product-variant";
9
- import ProductImage from "./product-image";
10
- import { DAL } from "@medusajs/types";
11
11
  type OptionalRelations = "collection" | "type";
12
12
  type OptionalFields = "collection_id" | "type_id" | "is_giftcard" | "discountable" | DAL.SoftDeletableEntityDateColumns;
13
13
  declare class Product {
@@ -43,6 +43,7 @@ declare class Product {
43
43
  updated_at: Date;
44
44
  deleted_at?: Date;
45
45
  metadata?: Record<string, unknown> | null;
46
+ onInit(): void;
46
47
  beforeCreate(): void;
47
48
  }
48
49
  export default Product;
@@ -16,11 +16,11 @@ const core_1 = require("@mikro-orm/core");
16
16
  const utils_1 = require("@medusajs/utils");
17
17
  const product_category_1 = __importDefault(require("./product-category"));
18
18
  const product_collection_1 = __importDefault(require("./product-collection"));
19
+ const product_image_1 = __importDefault(require("./product-image"));
19
20
  const product_option_1 = __importDefault(require("./product-option"));
20
21
  const product_tag_1 = __importDefault(require("./product-tag"));
21
22
  const product_type_1 = __importDefault(require("./product-type"));
22
23
  const product_variant_1 = __importDefault(require("./product-variant"));
23
- const product_image_1 = __importDefault(require("./product-image"));
24
24
  let Product = class Product {
25
25
  constructor() {
26
26
  this.options = new core_1.Collection(this);
@@ -29,6 +29,9 @@ let Product = class Product {
29
29
  this.images = new core_1.Collection(this);
30
30
  this.categories = new core_1.Collection(this);
31
31
  }
32
+ onInit() {
33
+ this.id = (0, utils_1.generateEntityId)(this.id, "prod");
34
+ }
32
35
  beforeCreate() {
33
36
  this.id = (0, utils_1.generateEntityId)(this.id, "prod");
34
37
  if (!this.handle) {
@@ -163,7 +166,7 @@ __decorate([
163
166
  (0, core_1.ManyToMany)(() => product_category_1.default, "products", {
164
167
  owner: true,
165
168
  pivotTable: "product_category_product",
166
- cascade: ["soft-remove"],
169
+ // TODO: rm cascade: ["soft-remove"] as any,
167
170
  }),
168
171
  __metadata("design:type", Object)
169
172
  ], Product.prototype, "categories", void 0);
@@ -201,6 +204,12 @@ __decorate([
201
204
  (0, core_1.Property)({ columnType: "jsonb", nullable: true }),
202
205
  __metadata("design:type", Object)
203
206
  ], Product.prototype, "metadata", void 0);
207
+ __decorate([
208
+ (0, core_1.OnInit)(),
209
+ __metadata("design:type", Function),
210
+ __metadata("design:paramtypes", []),
211
+ __metadata("design:returntype", void 0)
212
+ ], Product.prototype, "onInit", null);
204
213
  __decorate([
205
214
  (0, core_1.BeforeCreate)(),
206
215
  __metadata("design:type", Function),
@@ -1,35 +1,9 @@
1
1
  import { Image } from "../models";
2
+ import { DALUtils } from "@medusajs/utils";
2
3
  import { Context } from "@medusajs/types";
3
- declare const ProductImageRepository_base: {
4
- new (...args: any[]): {
5
- create(data: any[], context?: Context | undefined): Promise<Image[]>;
6
- update(data: any[], context?: Context | undefined): Promise<Image[]>;
7
- delete(primaryKeyValues: string[] | object[], context?: Context | undefined): Promise<void>;
8
- find(options?: import("@medusajs/types").FindOptions<Image> | undefined, context?: Context | undefined): Promise<Image[]>;
9
- findAndCount(findOptions?: import("@medusajs/types").FindOptions<Image> | undefined, context?: Context | undefined): Promise<[Image[], number]>;
10
- upsert(data: any[], context?: Context | undefined): Promise<Image[]>;
11
- softDelete(idsOrFilter: string[] | {
12
- [x: string]: any;
13
- }, { transactionManager: manager }?: Context | undefined): Promise<[Image[], Record<string, unknown[]>]>;
14
- restore(idsOrFilter: string[] | {
15
- [x: string]: any;
16
- }, { transactionManager: manager }?: Context | undefined): Promise<[Image[], Record<string, unknown[]>]>;
17
- applyFreeTextSearchFilters<T>(findOptions: import("@medusajs/types").FindOptions<T & {
18
- q?: string | undefined;
19
- }>, retrieveConstraintsToApply: (q: string) => any[]): void;
20
- readonly manager_: any;
21
- getFreshManager<TManager = unknown>(): TManager;
22
- getActiveManager<TManager_1 = unknown>({ transactionManager, manager }?: Context | undefined): TManager_1;
23
- transaction<TManager_2 = unknown>(task: (transactionManager: TManager_2) => Promise<any>, options?: {
24
- isolationLevel?: string | undefined;
25
- enableNestedTransactions?: boolean | undefined;
26
- transaction?: TManager_2 | undefined;
27
- } | undefined): Promise<any>;
28
- serialize<TOutput extends object | object[]>(data: any, options?: any): Promise<TOutput>;
29
- };
30
- buildUniqueCompositeKeyValue(keys: string[], data: object): string;
31
- retrievePrimaryKeys(entity: import("@mikro-orm/core").EntityClass<Image> | import("@mikro-orm/core").EntitySchema<Image, never>): ("deleted_at" | "created_at" | "updated_at" | "id" | "onCreate" | "products" | "metadata" | "url")[];
32
- };
4
+ declare const ProductImageRepository_base: new ({ manager }: {
5
+ manager: any;
6
+ }) => DALUtils.MikroOrmBaseRepository<object>;
33
7
  export declare class ProductImageRepository extends ProductImageRepository_base {
34
8
  constructor(...args: any[]);
35
9
  upsert(urls: string[], context?: Context): Promise<Image[]>;
@@ -11,7 +11,7 @@ class ProductImageRepository extends utils_1.DALUtils.mikroOrmBaseRepositoryFact
11
11
  }
12
12
  async upsert(urls, context = {}) {
13
13
  const data = urls.map((url) => ({ url }));
14
- return await super.upsert(data, context);
14
+ return (await super.upsert(data, context));
15
15
  }
16
16
  }
17
17
  exports.ProductImageRepository = ProductImageRepository;
@@ -1,36 +1,10 @@
1
1
  import { Product } from "../models";
2
2
  import { Context, DAL, ProductTypes, WithRequiredProperty } from "@medusajs/types";
3
+ import { DALUtils } from "@medusajs/utils";
3
4
  import { ProductServiceTypes } from "../types/services";
4
- declare const ProductRepository_base: {
5
- new (...args: any[]): {
6
- create(data: any[], context?: Context | undefined): Promise<Product[]>;
7
- update(data: any[], context?: Context | undefined): Promise<Product[]>;
8
- delete(primaryKeyValues: string[] | object[], context?: Context | undefined): Promise<void>;
9
- find(options?: DAL.FindOptions<Product> | undefined, context?: Context | undefined): Promise<Product[]>;
10
- findAndCount(findOptions?: DAL.FindOptions<Product> | undefined, context?: Context | undefined): Promise<[Product[], number]>;
11
- upsert(data: any[], context?: Context | undefined): Promise<Product[]>;
12
- softDelete(idsOrFilter: string[] | {
13
- [x: string]: any;
14
- }, { transactionManager: manager }?: Context | undefined): Promise<[Product[], Record<string, unknown[]>]>;
15
- restore(idsOrFilter: string[] | {
16
- [x: string]: any;
17
- }, { transactionManager: manager }?: Context | undefined): Promise<[Product[], Record<string, unknown[]>]>;
18
- applyFreeTextSearchFilters<T>(findOptions: DAL.FindOptions<T & {
19
- q?: string | undefined;
20
- }>, retrieveConstraintsToApply: (q: string) => any[]): void;
21
- readonly manager_: any;
22
- getFreshManager<TManager = unknown>(): TManager;
23
- getActiveManager<TManager_1 = unknown>({ transactionManager, manager }?: Context | undefined): TManager_1;
24
- transaction<TManager_2 = unknown>(task: (transactionManager: TManager_2) => Promise<any>, options?: {
25
- isolationLevel?: string | undefined;
26
- enableNestedTransactions?: boolean | undefined;
27
- transaction?: TManager_2 | undefined;
28
- } | undefined): Promise<any>;
29
- serialize<TOutput extends object | object[]>(data: any, options?: any): Promise<TOutput>;
30
- };
31
- buildUniqueCompositeKeyValue(keys: string[], data: object): string;
32
- retrievePrimaryKeys(entity: import("@mikro-orm/core").EntityClass<Product> | import("@mikro-orm/core").EntitySchema<Product, never>): ("deleted_at" | "created_at" | "updated_at" | "id" | "description" | "handle" | "length" | "type" | "title" | "subtitle" | "is_giftcard" | "status" | "thumbnail" | "options" | "variants" | "weight" | "height" | "width" | "origin_country" | "hs_code" | "mid_code" | "material" | "collection_id" | "collection" | "type_id" | "tags" | "images" | "categories" | "discountable" | "external_id" | "metadata" | "beforeCreate")[];
33
- };
5
+ declare const ProductRepository_base: new ({ manager }: {
6
+ manager: any;
7
+ }) => DALUtils.MikroOrmBaseRepository<Product>;
34
8
  export declare class ProductRepository extends ProductRepository_base {
35
9
  constructor(...args: any[]);
36
10
  find(findOptions?: DAL.FindOptions<Product & {
@@ -46,7 +20,10 @@ export declare class ProductRepository extends ProductRepository_base {
46
20
  */
47
21
  protected mutateNotInCategoriesConstraints(findOptions?: DAL.FindOptions<Product>, context?: Context): Promise<void>;
48
22
  create(data: WithRequiredProperty<ProductTypes.CreateProductOnlyDTO, "status">[], context?: Context): Promise<Product[]>;
49
- update(data: WithRequiredProperty<ProductServiceTypes.UpdateProductDTO, "id">[], context?: Context): Promise<Product[]>;
23
+ update(data: {
24
+ entity: Product;
25
+ update: WithRequiredProperty<ProductServiceTypes.UpdateProductDTO, "id">;
26
+ }[], context?: Context): Promise<Product[]>;
50
27
  protected getFreeTextSearchConstraints(q: string): ({
51
28
  description: {
52
29
  $ilike: string;
@@ -62,7 +62,7 @@ class ProductRepository extends utils_1.DALUtils.mikroOrmBaseRepositoryFactory(_
62
62
  const typeIds = [];
63
63
  // TODO: use the getter method (getActiveManager)
64
64
  const manager = this.getActiveManager(context);
65
- data.forEach((productData) => {
65
+ data.forEach(({ update: productData }) => {
66
66
  categoryIds = categoryIds.concat(productData?.categories?.map((c) => c.id) || []);
67
67
  tagIds = tagIds.concat(productData?.tags?.map((c) => c.id) || []);
68
68
  if (productData.collection_id) {
@@ -72,11 +72,6 @@ class ProductRepository extends utils_1.DALUtils.mikroOrmBaseRepositoryFactory(_
72
72
  typeIds.push(productData.type_id);
73
73
  }
74
74
  });
75
- const productsToUpdate = await manager.find(_models_1.Product, {
76
- id: data.map((updateData) => updateData.id),
77
- }, {
78
- populate: ["tags", "categories"],
79
- });
80
75
  const collectionsToAssign = collectionIds.length
81
76
  ? await manager.find(_models_1.ProductCollection, {
82
77
  id: collectionIds,
@@ -101,8 +96,8 @@ class ProductRepository extends utils_1.DALUtils.mikroOrmBaseRepositoryFactory(_
101
96
  const tagsToAssignMap = new Map(tagsToAssign.map((tag) => [tag.id, tag]));
102
97
  const collectionsToAssignMap = new Map(collectionsToAssign.map((collection) => [collection.id, collection]));
103
98
  const typesToAssignMap = new Map(typesToAssign.map((type) => [type.id, type]));
104
- const productsToUpdateMap = new Map(productsToUpdate.map((product) => [product.id, product]));
105
- const products = await (0, utils_1.promiseAll)(data.map(async (updateData) => {
99
+ const productsToUpdateMap = new Map(data.map(({ entity }) => [entity.id, entity]));
100
+ const products = await (0, utils_1.promiseAll)(data.map(async ({ update: updateData }) => {
106
101
  const product = productsToUpdateMap.get(updateData.id);
107
102
  if (!product) {
108
103
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Product with id "${updateData.id}" not found`);
File without changes
@@ -6,5 +6,3 @@ export { default as ProductTagService } from "./product-tag";
6
6
  export { default as ProductVariantService } from "./product-variant";
7
7
  export { default as ProductTypeService } from "./product-type";
8
8
  export { default as ProductOptionService } from "./product-option";
9
- export { default as ProductImageService } from "./product-image";
10
- export { default as ProductOptionValueService } from "./product-option-value";
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ProductOptionValueService = exports.ProductImageService = exports.ProductOptionService = exports.ProductTypeService = exports.ProductVariantService = exports.ProductTagService = exports.ProductModuleService = exports.ProductCollectionService = exports.ProductCategoryService = exports.ProductService = void 0;
6
+ exports.ProductOptionService = exports.ProductTypeService = exports.ProductVariantService = exports.ProductTagService = exports.ProductModuleService = exports.ProductCollectionService = exports.ProductCategoryService = exports.ProductService = void 0;
7
7
  var product_1 = require("./product");
8
8
  Object.defineProperty(exports, "ProductService", { enumerable: true, get: function () { return __importDefault(product_1).default; } });
9
9
  var product_category_1 = require("./product-category");
@@ -20,7 +20,3 @@ var product_type_1 = require("./product-type");
20
20
  Object.defineProperty(exports, "ProductTypeService", { enumerable: true, get: function () { return __importDefault(product_type_1).default; } });
21
21
  var product_option_1 = require("./product-option");
22
22
  Object.defineProperty(exports, "ProductOptionService", { enumerable: true, get: function () { return __importDefault(product_option_1).default; } });
23
- var product_image_1 = require("./product-image");
24
- Object.defineProperty(exports, "ProductImageService", { enumerable: true, get: function () { return __importDefault(product_image_1).default; } });
25
- var product_option_value_1 = require("./product-option-value");
26
- Object.defineProperty(exports, "ProductOptionValueService", { enumerable: true, get: function () { return __importDefault(product_option_value_1).default; } });