@medusajs/product 0.4.0-snapshot-20240401141452 → 0.4.0-snapshot-20240402145055
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/migrations/{InitialSetup20240325200756.js → InitialSetup20240401153642.js} +42 -33
- package/dist/models/product-category.d.ts +2 -4
- package/dist/models/product-category.js +26 -9
- package/dist/models/product-collection.d.ts +1 -6
- package/dist/models/product-collection.js +10 -16
- package/dist/models/product-image.d.ts +1 -5
- package/dist/models/product-image.js +9 -1
- package/dist/models/product-option-value.d.ts +1 -6
- package/dist/models/product-option-value.js +1 -11
- package/dist/models/product-option.d.ts +1 -6
- package/dist/models/product-option.js +2 -11
- package/dist/models/product-tag.d.ts +1 -6
- package/dist/models/product-tag.js +10 -9
- package/dist/models/product-type.d.ts +0 -5
- package/dist/models/product-type.js +10 -9
- package/dist/models/product-variant-option.d.ts +0 -1
- package/dist/models/product-variant-option.js +3 -11
- package/dist/models/product-variant.d.ts +2 -6
- package/dist/models/product-variant.js +53 -33
- package/dist/models/product.d.ts +2 -7
- package/dist/models/product.js +31 -21
- package/dist/services/product-module-service.js +1 -0
- package/package.json +5 -5
- /package/dist/migrations/{InitialSetup20240325200756.d.ts → InitialSetup20240401153642.d.ts} +0 -0
@@ -4,62 +4,71 @@ exports.InitialSetup20240315083440 = void 0;
|
|
4
4
|
const migrations_1 = require("@mikro-orm/migrations");
|
5
5
|
class InitialSetup20240315083440 extends migrations_1.Migration {
|
6
6
|
async up() {
|
7
|
-
// TODO: These migrations that get generated don't even reflect the models, write by hand.
|
8
7
|
const productTables = await this.execute("select * from information_schema.tables where table_name = 'product' and table_schema = 'public'");
|
9
8
|
if (productTables.length > 0) {
|
10
9
|
// This is so we can still run the api tests, remove completely once that is not needed
|
11
10
|
this.addSql(`alter table "product_option_value" alter column "variant_id" drop not null;`);
|
12
11
|
this.addSql(`alter table "product_variant" alter column "inventory_quantity" drop not null;`);
|
12
|
+
this.addSql(`alter table "product_category" add column "deleted_at" timestamptz null;`);
|
13
13
|
}
|
14
|
-
|
15
|
-
this.addSql('create index if not exists "IDX_product_category_path" on "product_category" ("mpath");');
|
16
|
-
// TODO: Re-enable when we run the migration from v1
|
17
|
-
// this.addSql('alter table if exists "product_category" add constraint "IDX_product_category_handle" unique ("handle");');
|
18
|
-
this.addSql('create table if not exists "product_collection" ("id" text not null, "title" text not null, "handle" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_collection_pkey" primary key ("id"));');
|
19
|
-
this.addSql('create index if not exists "IDX_product_collection_deleted_at" on "product_collection" ("deleted_at");');
|
20
|
-
this.addSql('alter table if exists "product_collection" add constraint "IDX_product_collection_handle_unique" unique ("handle");');
|
21
|
-
this.addSql('create table if not exists "image" ("id" text not null, "url" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "image_pkey" primary key ("id"));');
|
22
|
-
this.addSql('create index if not exists "IDX_product_image_url" on "image" ("url");');
|
23
|
-
this.addSql('create index if not exists "IDX_product_image_deleted_at" on "image" ("deleted_at");');
|
24
|
-
this.addSql('create table if not exists "product_tag" ("id" text not null, "value" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_tag_pkey" primary key ("id"));');
|
25
|
-
this.addSql('create index if not exists "IDX_product_tag_deleted_at" on "product_tag" ("deleted_at");');
|
26
|
-
this.addSql('create table if not exists "product_type" ("id" text not null, "value" text not null, "metadata" json null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_type_pkey" primary key ("id"));');
|
27
|
-
this.addSql('create index if not exists "IDX_product_type_deleted_at" on "product_type" ("deleted_at");');
|
14
|
+
/* --- ENTITY TABLES AND INDICES --- */
|
28
15
|
this.addSql('create table if not exists "product" ("id" text not null, "title" text not null, "handle" text not null, "subtitle" text null, "description" text null, "is_giftcard" boolean not null default false, "status" text check ("status" in (\'draft\', \'proposed\', \'published\', \'rejected\')) not null, "thumbnail" text null, "weight" text null, "length" text null, "height" text null, "width" text null, "origin_country" text null, "hs_code" text null, "mid_code" text null, "material" text null, "collection_id" text null, "type_id" text null, "discountable" boolean not null default true, "external_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "metadata" jsonb null, constraint "product_pkey" primary key ("id"));');
|
29
|
-
this.addSql('create index if not exists "
|
16
|
+
this.addSql('create unique index if not exists "IDX_product_handle_unique" on "product" (handle) where deleted_at is null;');
|
17
|
+
this.addSql('create index if not exists "IDX_product_type_id" on "product" ("type_id") where deleted_at is null;');
|
18
|
+
this.addSql('create index if not exists "IDX_product_collection_id" on "product" ("collection_id") where deleted_at is null;');
|
30
19
|
this.addSql('create index if not exists "IDX_product_deleted_at" on "product" ("deleted_at");');
|
31
|
-
this.addSql('
|
20
|
+
this.addSql('create table if not exists "product_variant" ("id" text not null, "title" text not null, "sku" text null, "barcode" text null, "ean" text null, "upc" text null, "inventory_quantity" numeric not null default 100, "allow_backorder" boolean not null default false, "manage_inventory" boolean not null default true, "hs_code" text null, "origin_country" text null, "mid_code" text null, "material" text null, "weight" numeric null, "length" numeric null, "height" numeric null, "width" numeric null, "metadata" jsonb null, "variant_rank" numeric null default 0, "product_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_variant_pkey" primary key ("id"));');
|
21
|
+
this.addSql('create unique index if not exists "IDX_product_variant_ean_unique" on "product_variant" (ean) where deleted_at is null;');
|
22
|
+
this.addSql('create unique index if not exists "IDX_product_variant_upc_unique" on "product_variant" (upc) where deleted_at is null;');
|
23
|
+
this.addSql('create unique index if not exists "IDX_product_variant_sku_unique" on "product_variant" (sku) where deleted_at is null;');
|
24
|
+
this.addSql('create unique index if not exists "IDX_product_variant_barcode_unique" on "product_variant" (barcode) where deleted_at is null;');
|
25
|
+
this.addSql('create index if not exists "IDX_product_variant_product_id" on "product_variant" ("product_id") where deleted_at is null;');
|
26
|
+
this.addSql('create index if not exists "IDX_product_variant_deleted_at" on "product_variant" ("deleted_at");');
|
32
27
|
this.addSql('create table if not exists "product_option" ("id" text not null, "title" text not null, "product_id" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_option_pkey" primary key ("id"));');
|
28
|
+
this.addSql('create unique index if not exists "IDX_option_product_id_title_unique" on "product_option" (product_id, title) where deleted_at is null;');
|
33
29
|
this.addSql('create index if not exists "IDX_product_option_deleted_at" on "product_option" ("deleted_at");');
|
34
30
|
this.addSql('create table if not exists "product_option_value" ("id" text not null, "value" text not null, "option_id" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_option_value_pkey" primary key ("id"));');
|
35
|
-
this.addSql('create index if not exists "
|
31
|
+
this.addSql('create unique index if not exists "IDX_option_value_option_id_unique" on "product_option_value" (option_id, value) where deleted_at is null;');
|
36
32
|
this.addSql('create index if not exists "IDX_product_option_value_deleted_at" on "product_option_value" ("deleted_at");');
|
33
|
+
this.addSql('create table if not exists "product_variant_option" ("id" text not null, "option_value_id" text null, "variant_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_variant_option_pkey" primary key ("id"));');
|
34
|
+
this.addSql('create unique index if not exists "IDX_variant_option_option_value_unique" on "product_variant_option" (variant_id, option_value_id) where deleted_at is null;');
|
35
|
+
this.addSql('create index if not exists "IDX_product_variant_option_deleted_at" on "product_variant_option" ("deleted_at");');
|
36
|
+
this.addSql('create table if not exists "image" ("id" text not null, "url" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "image_pkey" primary key ("id"));');
|
37
|
+
this.addSql('create index if not exists "IDX_product_image_url" on "image" ("url") where deleted_at is null;');
|
38
|
+
this.addSql('create index if not exists "IDX_product_image_deleted_at" on "image" ("deleted_at");');
|
39
|
+
this.addSql('create table if not exists "product_tag" ("id" text not null, "value" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_tag_pkey" primary key ("id"));');
|
40
|
+
// TODO: We need to modify upsertWithReplace to handle unique constraints
|
41
|
+
// this.addSql('create unique index if not exists "IDX_tag_value_unique" on "product_tag" (value) where deleted_at is null;')
|
42
|
+
this.addSql('create index if not exists "IDX_product_tag_deleted_at" on "product_tag" ("deleted_at");');
|
43
|
+
this.addSql('create table if not exists "product_type" ("id" text not null, "value" text not null, "metadata" json null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_type_pkey" primary key ("id"));');
|
44
|
+
this.addSql('create unique index if not exists "IDX_type_value_unique" on "product_type" (value) where deleted_at is null;');
|
45
|
+
this.addSql('create index if not exists "IDX_product_type_deleted_at" on "product_type" ("deleted_at");');
|
46
|
+
this.addSql('create table if not exists "product_collection" ("id" text not null, "title" text not null, "handle" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_collection_pkey" primary key ("id"));');
|
47
|
+
this.addSql('create unique index if not exists "IDX_collection_handle_unique" on "product_collection" (handle) where deleted_at is null;');
|
48
|
+
this.addSql('create index if not exists "IDX_product_collection_deleted_at" on "product_collection" ("deleted_at");');
|
49
|
+
this.addSql('create table if not exists "product_category" ("id" text not null, "name" text not null, "description" text not null default \'\', "handle" text not null, "mpath" text not null, "is_active" boolean not null default false, "is_internal" boolean not null default false, "rank" numeric not null default 0, "parent_category_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_category_pkey" primary key ("id"));');
|
50
|
+
this.addSql('create unique index if not exists "IDX_category_handle_unique" on "product_category" (handle) where deleted_at is null;');
|
51
|
+
this.addSql('create index if not exists "IDX_product_category_path" on "product_category" ("mpath") where deleted_at is null;');
|
52
|
+
this.addSql('create index if not exists "IDX_product_category_deleted_at" on "product_collection" ("deleted_at");');
|
53
|
+
/* --- PIVOT TABLES --- */
|
37
54
|
this.addSql('create table if not exists "product_tags" ("product_id" text not null, "product_tag_id" text not null, constraint "product_tags_pkey" primary key ("product_id", "product_tag_id"));');
|
38
55
|
this.addSql('create table if not exists "product_images" ("product_id" text not null, "image_id" text not null, constraint "product_images_pkey" primary key ("product_id", "image_id"));');
|
39
56
|
this.addSql('create table if not exists "product_category_product" ("product_id" text not null, "product_category_id" text not null, constraint "product_category_product_pkey" primary key ("product_id", "product_category_id"));');
|
40
|
-
|
41
|
-
this.addSql('create index if not exists "IDX_product_variant_product_id" on "product_variant" ("product_id");');
|
42
|
-
this.addSql('create index if not exists "IDX_product_variant_deleted_at" on "product_variant" ("deleted_at");');
|
43
|
-
this.addSql('alter table if exists "product_variant" add constraint "IDX_product_variant_sku_unique" unique ("sku");');
|
44
|
-
this.addSql('alter table if exists "product_variant" add constraint "IDX_product_variant_barcode_unique" unique ("barcode");');
|
45
|
-
this.addSql('alter table if exists "product_variant" add constraint "IDX_product_variant_ean_unique" unique ("ean");');
|
46
|
-
this.addSql('alter table if exists "product_variant" add constraint "IDX_product_variant_upc_unique" unique ("upc");');
|
47
|
-
this.addSql('create table if not exists "product_variant_option" ("id" text not null, "option_value_id" text null, "variant_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_variant_option_pkey" primary key ("id"));');
|
48
|
-
this.addSql('create index if not exists "IDX_product_variant_option_deleted_at" on "product_variant_option" ("deleted_at");');
|
49
|
-
this.addSql('alter table if exists "product_category" add constraint "product_category_parent_category_id_foreign" foreign key ("parent_category_id") references "product_category" ("id") on update cascade on delete set null;');
|
57
|
+
/* --- FOREIGN KEYS AND CONSTRAINTS --- */
|
50
58
|
this.addSql('alter table if exists "product" add constraint "product_collection_id_foreign" foreign key ("collection_id") references "product_collection" ("id") on update cascade on delete set null;');
|
51
59
|
this.addSql('alter table if exists "product" add constraint "product_type_id_foreign" foreign key ("type_id") references "product_type" ("id") on update cascade on delete set null;');
|
60
|
+
this.addSql('alter table if exists "product_variant" add constraint "product_variant_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
52
61
|
this.addSql('alter table if exists "product_option" add constraint "product_option_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
53
62
|
this.addSql('alter table if exists "product_option_value" add constraint "product_option_value_option_id_foreign" foreign key ("option_id") references "product_option" ("id") on update cascade on delete cascade;');
|
54
|
-
this.addSql('alter table if exists "
|
55
|
-
this.addSql('alter table if exists "
|
63
|
+
this.addSql('alter table if exists "product_variant_option" add constraint "product_variant_option_option_value_id_foreign" foreign key ("option_value_id") references "product_option_value" ("id") on update cascade on delete cascade;');
|
64
|
+
this.addSql('alter table if exists "product_variant_option" add constraint "product_variant_option_variant_id_foreign" foreign key ("variant_id") references "product_variant" ("id") on update cascade on delete cascade;');
|
56
65
|
this.addSql('alter table if exists "product_images" add constraint "product_images_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
57
66
|
this.addSql('alter table if exists "product_images" add constraint "product_images_image_id_foreign" foreign key ("image_id") references "image" ("id") on update cascade on delete cascade;');
|
67
|
+
this.addSql('alter table if exists "product_tags" add constraint "product_tags_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
68
|
+
this.addSql('alter table if exists "product_tags" add constraint "product_tags_product_tag_id_foreign" foreign key ("product_tag_id") references "product_tag" ("id") on update cascade on delete cascade;');
|
58
69
|
this.addSql('alter table if exists "product_category_product" add constraint "product_category_product_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
59
70
|
this.addSql('alter table if exists "product_category_product" add constraint "product_category_product_product_category_id_foreign" foreign key ("product_category_id") references "product_category" ("id") on update cascade on delete cascade;');
|
60
|
-
this.addSql('alter table if exists "
|
61
|
-
this.addSql('alter table if exists "product_variant_option" add constraint "product_variant_option_option_value_id_foreign" foreign key ("option_value_id") references "product_option_value" ("id") on update cascade on delete set null;');
|
62
|
-
this.addSql('alter table if exists "product_variant_option" add constraint "product_variant_option_variant_id_foreign" foreign key ("variant_id") references "product_variant" ("id") on update cascade on delete set null;');
|
71
|
+
this.addSql('alter table if exists "product_category" add constraint "product_category_parent_category_id_foreign" foreign key ("parent_category_id") references "product_category" ("id") on update cascade on delete cascade;');
|
63
72
|
}
|
64
73
|
}
|
65
74
|
exports.InitialSetup20240315083440 = InitialSetup20240315083440;
|
@@ -1,9 +1,6 @@
|
|
1
|
-
import { Collection, EventArgs
|
2
|
-
import { DAL } from "@medusajs/types";
|
1
|
+
import { Collection, EventArgs } from "@mikro-orm/core";
|
3
2
|
import Product from "./product";
|
4
|
-
type OptionalFields = DAL.SoftDeletableEntityDateColumns;
|
5
3
|
declare class ProductCategory {
|
6
|
-
[OptionalProps]?: OptionalFields;
|
7
4
|
id: string;
|
8
5
|
name?: string;
|
9
6
|
description?: string;
|
@@ -17,6 +14,7 @@ declare class ProductCategory {
|
|
17
14
|
category_children: Collection<ProductCategory, object>;
|
18
15
|
created_at?: Date;
|
19
16
|
updated_at?: Date;
|
17
|
+
deleted_at?: Date;
|
20
18
|
products: Collection<Product, object>;
|
21
19
|
onInit(): Promise<void>;
|
22
20
|
onCreate(args: EventArgs<ProductCategory>): Promise<void>;
|
@@ -16,6 +16,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
const utils_1 = require("@medusajs/utils");
|
17
17
|
const core_1 = require("@mikro-orm/core");
|
18
18
|
const product_1 = __importDefault(require("./product"));
|
19
|
+
const categoryHandleIndexName = "IDX_category_handle_unique";
|
20
|
+
const categoryHandleIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
21
|
+
name: categoryHandleIndexName,
|
22
|
+
tableName: "product_category",
|
23
|
+
columns: ["handle"],
|
24
|
+
unique: true,
|
25
|
+
where: "deleted_at IS NULL",
|
26
|
+
});
|
27
|
+
const categoryMpathIndexName = "IDX_product_category_path";
|
28
|
+
const categoryMpathIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
29
|
+
name: categoryMpathIndexName,
|
30
|
+
tableName: "product_category",
|
31
|
+
columns: ["mpath"],
|
32
|
+
unique: false,
|
33
|
+
where: "deleted_at IS NULL",
|
34
|
+
});
|
35
|
+
categoryMpathIndexStatement.MikroORMIndex();
|
36
|
+
categoryHandleIndexStatement.MikroORMIndex();
|
19
37
|
let ProductCategory = ProductCategory_1 = class ProductCategory {
|
20
38
|
constructor() {
|
21
39
|
this.category_children = new core_1.Collection(this);
|
@@ -58,18 +76,10 @@ __decorate([
|
|
58
76
|
__metadata("design:type", String)
|
59
77
|
], ProductCategory.prototype, "description", void 0);
|
60
78
|
__decorate([
|
61
|
-
(0, core_1.Unique)({
|
62
|
-
name: "IDX_product_category_handle",
|
63
|
-
properties: ["handle"],
|
64
|
-
}),
|
65
79
|
(0, core_1.Property)({ columnType: "text", nullable: false }),
|
66
80
|
__metadata("design:type", String)
|
67
81
|
], ProductCategory.prototype, "handle", void 0);
|
68
82
|
__decorate([
|
69
|
-
(0, core_1.Index)({
|
70
|
-
name: "IDX_product_category_path",
|
71
|
-
properties: ["mpath"],
|
72
|
-
}),
|
73
83
|
(0, core_1.Property)({ columnType: "text", nullable: false }),
|
74
84
|
__metadata("design:type", String)
|
75
85
|
], ProductCategory.prototype, "mpath", void 0);
|
@@ -91,6 +101,7 @@ __decorate([
|
|
91
101
|
fieldName: "parent_category_id",
|
92
102
|
nullable: true,
|
93
103
|
mapToPk: true,
|
104
|
+
onDelete: "cascade",
|
94
105
|
}),
|
95
106
|
__metadata("design:type", Object)
|
96
107
|
], ProductCategory.prototype, "parent_category_id", void 0);
|
@@ -122,6 +133,11 @@ __decorate([
|
|
122
133
|
}),
|
123
134
|
__metadata("design:type", Date)
|
124
135
|
], ProductCategory.prototype, "updated_at", void 0);
|
136
|
+
__decorate([
|
137
|
+
(0, core_1.Index)({ name: "IDX_product_category_deleted_at" }),
|
138
|
+
(0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
|
139
|
+
__metadata("design:type", Date)
|
140
|
+
], ProductCategory.prototype, "deleted_at", void 0);
|
125
141
|
__decorate([
|
126
142
|
(0, core_1.ManyToMany)(() => product_1.default, (product) => product.categories),
|
127
143
|
__metadata("design:type", Object)
|
@@ -139,6 +155,7 @@ __decorate([
|
|
139
155
|
__metadata("design:returntype", Promise)
|
140
156
|
], ProductCategory.prototype, "onCreate", null);
|
141
157
|
ProductCategory = ProductCategory_1 = __decorate([
|
142
|
-
(0, core_1.Entity)({ tableName: "product_category" })
|
158
|
+
(0, core_1.Entity)({ tableName: "product_category" }),
|
159
|
+
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
143
160
|
], ProductCategory);
|
144
161
|
exports.default = ProductCategory;
|
@@ -1,10 +1,6 @@
|
|
1
|
-
import { Collection
|
2
|
-
import { DAL } from "@medusajs/types";
|
1
|
+
import { Collection } from "@mikro-orm/core";
|
3
2
|
import Product from "./product";
|
4
|
-
type OptionalRelations = "products";
|
5
|
-
type OptionalFields = DAL.SoftDeletableEntityDateColumns;
|
6
3
|
declare class ProductCollection {
|
7
|
-
[OptionalProps]?: OptionalRelations | OptionalFields;
|
8
4
|
id: string;
|
9
5
|
title: string;
|
10
6
|
handle?: string;
|
@@ -14,6 +10,5 @@ declare class ProductCollection {
|
|
14
10
|
updated_at: Date;
|
15
11
|
deleted_at?: Date;
|
16
12
|
onInit(): void;
|
17
|
-
onCreate(): void;
|
18
13
|
}
|
19
14
|
export default ProductCollection;
|
@@ -15,6 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const core_1 = require("@mikro-orm/core");
|
16
16
|
const utils_1 = require("@medusajs/utils");
|
17
17
|
const product_1 = __importDefault(require("./product"));
|
18
|
+
const collectionHandleIndexName = "IDX_collection_handle_unique";
|
19
|
+
const collectionHandleIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
20
|
+
name: collectionHandleIndexName,
|
21
|
+
tableName: "product_collection",
|
22
|
+
columns: ["handle"],
|
23
|
+
unique: true,
|
24
|
+
where: "deleted_at IS NULL",
|
25
|
+
});
|
26
|
+
collectionHandleIndexStatement.MikroORMIndex();
|
18
27
|
let ProductCollection = class ProductCollection {
|
19
28
|
constructor() {
|
20
29
|
this.products = new core_1.Collection(this);
|
@@ -25,12 +34,6 @@ let ProductCollection = class ProductCollection {
|
|
25
34
|
this.handle = (0, utils_1.kebabCase)(this.title);
|
26
35
|
}
|
27
36
|
}
|
28
|
-
onCreate() {
|
29
|
-
this.id = (0, utils_1.generateEntityId)(this.id, "pcol");
|
30
|
-
if (!this.handle && this.title) {
|
31
|
-
this.handle = (0, utils_1.kebabCase)(this.title);
|
32
|
-
}
|
33
|
-
}
|
34
37
|
};
|
35
38
|
__decorate([
|
36
39
|
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
@@ -42,10 +45,6 @@ __decorate([
|
|
42
45
|
], ProductCollection.prototype, "title", void 0);
|
43
46
|
__decorate([
|
44
47
|
(0, core_1.Property)({ columnType: "text" }),
|
45
|
-
(0, core_1.Unique)({
|
46
|
-
name: "IDX_product_collection_handle_unique",
|
47
|
-
properties: ["handle"],
|
48
|
-
}),
|
49
48
|
__metadata("design:type", String)
|
50
49
|
], ProductCollection.prototype, "handle", void 0);
|
51
50
|
__decorate([
|
@@ -80,16 +79,11 @@ __decorate([
|
|
80
79
|
], ProductCollection.prototype, "deleted_at", void 0);
|
81
80
|
__decorate([
|
82
81
|
(0, core_1.OnInit)(),
|
83
|
-
__metadata("design:type", Function),
|
84
|
-
__metadata("design:paramtypes", []),
|
85
|
-
__metadata("design:returntype", void 0)
|
86
|
-
], ProductCollection.prototype, "onInit", null);
|
87
|
-
__decorate([
|
88
82
|
(0, core_1.BeforeCreate)(),
|
89
83
|
__metadata("design:type", Function),
|
90
84
|
__metadata("design:paramtypes", []),
|
91
85
|
__metadata("design:returntype", void 0)
|
92
|
-
], ProductCollection.prototype, "
|
86
|
+
], ProductCollection.prototype, "onInit", null);
|
93
87
|
ProductCollection = __decorate([
|
94
88
|
(0, core_1.Entity)({ tableName: "product_collection" }),
|
95
89
|
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
@@ -1,10 +1,6 @@
|
|
1
|
-
import { Collection
|
2
|
-
import { DAL } from "@medusajs/types";
|
1
|
+
import { Collection } from "@mikro-orm/core";
|
3
2
|
import Product from "./product";
|
4
|
-
type OptionalRelations = "products";
|
5
|
-
type OptionalFields = DAL.SoftDeletableEntityDateColumns;
|
6
3
|
declare class ProductImage {
|
7
|
-
[OptionalProps]?: OptionalRelations | OptionalFields;
|
8
4
|
id: string;
|
9
5
|
url: string;
|
10
6
|
metadata?: Record<string, unknown> | null;
|
@@ -15,6 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const core_1 = require("@mikro-orm/core");
|
16
16
|
const utils_1 = require("@medusajs/utils");
|
17
17
|
const product_1 = __importDefault(require("./product"));
|
18
|
+
const imageUrlIndexName = "IDX_product_image_url";
|
19
|
+
const imageUrlIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
20
|
+
name: imageUrlIndexName,
|
21
|
+
tableName: "image",
|
22
|
+
columns: ["url"],
|
23
|
+
unique: false,
|
24
|
+
where: "deleted_at IS NULL",
|
25
|
+
});
|
26
|
+
imageUrlIndexStatement.MikroORMIndex();
|
18
27
|
let ProductImage = class ProductImage {
|
19
28
|
constructor() {
|
20
29
|
this.products = new core_1.Collection(this);
|
@@ -31,7 +40,6 @@ __decorate([
|
|
31
40
|
__metadata("design:type", String)
|
32
41
|
], ProductImage.prototype, "id", void 0);
|
33
42
|
__decorate([
|
34
|
-
(0, core_1.Index)({ name: "IDX_product_image_url" }),
|
35
43
|
(0, core_1.Property)({ columnType: "text" }),
|
36
44
|
__metadata("design:type", String)
|
37
45
|
], ProductImage.prototype, "url", void 0);
|
@@ -1,10 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import { Collection, OptionalProps } from "@mikro-orm/core";
|
1
|
+
import { Collection } from "@mikro-orm/core";
|
3
2
|
import { ProductOption, ProductVariantOption } from "./index";
|
4
|
-
type OptionalFields = "allow_backorder" | "manage_inventory" | "option_id" | DAL.SoftDeletableEntityDateColumns;
|
5
|
-
type OptionalRelations = "product" | "option" | "variant";
|
6
3
|
declare class ProductOptionValue {
|
7
|
-
[OptionalProps]?: OptionalFields | OptionalRelations;
|
8
4
|
id: string;
|
9
5
|
value: string;
|
10
6
|
option_id: string | null;
|
@@ -15,6 +11,5 @@ declare class ProductOptionValue {
|
|
15
11
|
updated_at: Date;
|
16
12
|
deleted_at?: Date;
|
17
13
|
onInit(): void;
|
18
|
-
beforeCreate(): void;
|
19
14
|
}
|
20
15
|
export default ProductOptionValue;
|
@@ -29,10 +29,6 @@ let ProductOptionValue = class ProductOptionValue {
|
|
29
29
|
this.id = (0, utils_1.generateEntityId)(this.id, "optval");
|
30
30
|
this.option_id ?? (this.option_id = this.option?.id ?? null);
|
31
31
|
}
|
32
|
-
beforeCreate() {
|
33
|
-
this.id = (0, utils_1.generateEntityId)(this.id, "optval");
|
34
|
-
this.option_id ?? (this.option_id = this.option?.id ?? null);
|
35
|
-
}
|
36
32
|
};
|
37
33
|
__decorate([
|
38
34
|
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
@@ -48,7 +44,6 @@ __decorate([
|
|
48
44
|
fieldName: "option_id",
|
49
45
|
mapToPk: true,
|
50
46
|
nullable: true,
|
51
|
-
index: "IDX_product_option_value_option_id",
|
52
47
|
onDelete: "cascade",
|
53
48
|
}),
|
54
49
|
__metadata("design:type", Object)
|
@@ -92,16 +87,11 @@ __decorate([
|
|
92
87
|
], ProductOptionValue.prototype, "deleted_at", void 0);
|
93
88
|
__decorate([
|
94
89
|
(0, core_1.OnInit)(),
|
95
|
-
__metadata("design:type", Function),
|
96
|
-
__metadata("design:paramtypes", []),
|
97
|
-
__metadata("design:returntype", void 0)
|
98
|
-
], ProductOptionValue.prototype, "onInit", null);
|
99
|
-
__decorate([
|
100
90
|
(0, core_1.BeforeCreate)(),
|
101
91
|
__metadata("design:type", Function),
|
102
92
|
__metadata("design:paramtypes", []),
|
103
93
|
__metadata("design:returntype", void 0)
|
104
|
-
], ProductOptionValue.prototype, "
|
94
|
+
], ProductOptionValue.prototype, "onInit", null);
|
105
95
|
ProductOptionValue = __decorate([
|
106
96
|
(0, core_1.Entity)({ tableName: "product_option_value" }),
|
107
97
|
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
@@ -1,11 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { Collection, OptionalProps } from "@mikro-orm/core";
|
1
|
+
import { Collection } from "@mikro-orm/core";
|
3
2
|
import { Product } from "./index";
|
4
3
|
import ProductOptionValue from "./product-option-value";
|
5
|
-
type OptionalRelations = "values" | "product" | DAL.SoftDeletableEntityDateColumns;
|
6
|
-
type OptionalFields = "product_id";
|
7
4
|
declare class ProductOption {
|
8
|
-
[OptionalProps]?: OptionalRelations | OptionalFields;
|
9
5
|
id: string;
|
10
6
|
title: string;
|
11
7
|
product_id: string | null;
|
@@ -16,6 +12,5 @@ declare class ProductOption {
|
|
16
12
|
updated_at: Date;
|
17
13
|
deleted_at?: Date;
|
18
14
|
onInit(): void;
|
19
|
-
beforeCreate(): void;
|
20
15
|
}
|
21
16
|
export default ProductOption;
|
@@ -33,10 +33,6 @@ let ProductOption = class ProductOption {
|
|
33
33
|
this.id = (0, utils_1.generateEntityId)(this.id, "opt");
|
34
34
|
this.product_id ?? (this.product_id = this.product?.id ?? null);
|
35
35
|
}
|
36
|
-
beforeCreate() {
|
37
|
-
this.id = (0, utils_1.generateEntityId)(this.id, "opt");
|
38
|
-
this.product_id ?? (this.product_id = this.product?.id ?? null);
|
39
|
-
}
|
40
36
|
};
|
41
37
|
__decorate([
|
42
38
|
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
@@ -65,7 +61,7 @@ __decorate([
|
|
65
61
|
], ProductOption.prototype, "product", void 0);
|
66
62
|
__decorate([
|
67
63
|
(0, core_1.OneToMany)(() => product_option_value_1.default, (value) => value.option, {
|
68
|
-
cascade: [core_1.Cascade.PERSIST,
|
64
|
+
cascade: [core_1.Cascade.PERSIST, "soft-remove"],
|
69
65
|
}),
|
70
66
|
__metadata("design:type", Object)
|
71
67
|
], ProductOption.prototype, "values", void 0);
|
@@ -97,16 +93,11 @@ __decorate([
|
|
97
93
|
], ProductOption.prototype, "deleted_at", void 0);
|
98
94
|
__decorate([
|
99
95
|
(0, core_1.OnInit)(),
|
100
|
-
__metadata("design:type", Function),
|
101
|
-
__metadata("design:paramtypes", []),
|
102
|
-
__metadata("design:returntype", void 0)
|
103
|
-
], ProductOption.prototype, "onInit", null);
|
104
|
-
__decorate([
|
105
96
|
(0, core_1.BeforeCreate)(),
|
106
97
|
__metadata("design:type", Function),
|
107
98
|
__metadata("design:paramtypes", []),
|
108
99
|
__metadata("design:returntype", void 0)
|
109
|
-
], ProductOption.prototype, "
|
100
|
+
], ProductOption.prototype, "onInit", null);
|
110
101
|
ProductOption = __decorate([
|
111
102
|
(0, core_1.Entity)({ tableName: "product_option" }),
|
112
103
|
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
@@ -1,10 +1,6 @@
|
|
1
|
-
import { Collection
|
2
|
-
import { DAL } from "@medusajs/types";
|
1
|
+
import { Collection } from "@mikro-orm/core";
|
3
2
|
import Product from "./product";
|
4
|
-
type OptionalRelations = "products";
|
5
|
-
type OptionalFields = DAL.SoftDeletableEntityDateColumns;
|
6
3
|
declare class ProductTag {
|
7
|
-
[OptionalProps]?: OptionalRelations | OptionalFields;
|
8
4
|
id: string;
|
9
5
|
value: string;
|
10
6
|
metadata?: Record<string, unknown> | null;
|
@@ -13,6 +9,5 @@ declare class ProductTag {
|
|
13
9
|
deleted_at?: Date;
|
14
10
|
products: Collection<Product, object>;
|
15
11
|
onInit(): void;
|
16
|
-
onCreate(): void;
|
17
12
|
}
|
18
13
|
export default ProductTag;
|
@@ -15,6 +15,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const core_1 = require("@mikro-orm/core");
|
16
16
|
const utils_1 = require("@medusajs/utils");
|
17
17
|
const product_1 = __importDefault(require("./product"));
|
18
|
+
const tagValueIndexName = "IDX_tag_value_unique";
|
19
|
+
const tagValueIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
20
|
+
name: tagValueIndexName,
|
21
|
+
tableName: "product_tag",
|
22
|
+
columns: ["value"],
|
23
|
+
unique: true,
|
24
|
+
where: "deleted_at IS NULL",
|
25
|
+
});
|
26
|
+
tagValueIndexStatement.MikroORMIndex();
|
18
27
|
let ProductTag = class ProductTag {
|
19
28
|
constructor() {
|
20
29
|
this.products = new core_1.Collection(this);
|
@@ -22,9 +31,6 @@ let ProductTag = class ProductTag {
|
|
22
31
|
onInit() {
|
23
32
|
this.id = (0, utils_1.generateEntityId)(this.id, "ptag");
|
24
33
|
}
|
25
|
-
onCreate() {
|
26
|
-
this.id = (0, utils_1.generateEntityId)(this.id, "ptag");
|
27
|
-
}
|
28
34
|
};
|
29
35
|
__decorate([
|
30
36
|
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
@@ -66,16 +72,11 @@ __decorate([
|
|
66
72
|
], ProductTag.prototype, "products", void 0);
|
67
73
|
__decorate([
|
68
74
|
(0, core_1.OnInit)(),
|
69
|
-
__metadata("design:type", Function),
|
70
|
-
__metadata("design:paramtypes", []),
|
71
|
-
__metadata("design:returntype", void 0)
|
72
|
-
], ProductTag.prototype, "onInit", null);
|
73
|
-
__decorate([
|
74
75
|
(0, core_1.BeforeCreate)(),
|
75
76
|
__metadata("design:type", Function),
|
76
77
|
__metadata("design:paramtypes", []),
|
77
78
|
__metadata("design:returntype", void 0)
|
78
|
-
], ProductTag.prototype, "
|
79
|
+
], ProductTag.prototype, "onInit", null);
|
79
80
|
ProductTag = __decorate([
|
80
81
|
(0, core_1.Entity)({ tableName: "product_tag" }),
|
81
82
|
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
@@ -1,8 +1,4 @@
|
|
1
|
-
import { OptionalProps } from "@mikro-orm/core";
|
2
|
-
import { DAL } from "@medusajs/types";
|
3
|
-
type OptionalFields = DAL.SoftDeletableEntityDateColumns;
|
4
1
|
declare class ProductType {
|
5
|
-
[OptionalProps]?: OptionalFields;
|
6
2
|
id: string;
|
7
3
|
value: string;
|
8
4
|
metadata?: Record<string, unknown> | null;
|
@@ -10,6 +6,5 @@ declare class ProductType {
|
|
10
6
|
updated_at: Date;
|
11
7
|
deleted_at?: Date;
|
12
8
|
onInit(): void;
|
13
|
-
onCreate(): void;
|
14
9
|
}
|
15
10
|
export default ProductType;
|
@@ -11,13 +11,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
const core_1 = require("@mikro-orm/core");
|
13
13
|
const utils_1 = require("@medusajs/utils");
|
14
|
+
const typeValueIndexName = "IDX_type_value_unique";
|
15
|
+
const typeValueIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
16
|
+
name: typeValueIndexName,
|
17
|
+
tableName: "product_type",
|
18
|
+
columns: ["value"],
|
19
|
+
unique: true,
|
20
|
+
where: "deleted_at IS NULL",
|
21
|
+
});
|
22
|
+
typeValueIndexStatement.MikroORMIndex();
|
14
23
|
let ProductType = class ProductType {
|
15
24
|
onInit() {
|
16
25
|
this.id = (0, utils_1.generateEntityId)(this.id, "ptyp");
|
17
26
|
}
|
18
|
-
onCreate() {
|
19
|
-
this.id = (0, utils_1.generateEntityId)(this.id, "ptyp");
|
20
|
-
}
|
21
27
|
};
|
22
28
|
__decorate([
|
23
29
|
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
@@ -55,16 +61,11 @@ __decorate([
|
|
55
61
|
], ProductType.prototype, "deleted_at", void 0);
|
56
62
|
__decorate([
|
57
63
|
(0, core_1.OnInit)(),
|
58
|
-
__metadata("design:type", Function),
|
59
|
-
__metadata("design:paramtypes", []),
|
60
|
-
__metadata("design:returntype", void 0)
|
61
|
-
], ProductType.prototype, "onInit", null);
|
62
|
-
__decorate([
|
63
64
|
(0, core_1.BeforeCreate)(),
|
64
65
|
__metadata("design:type", Function),
|
65
66
|
__metadata("design:paramtypes", []),
|
66
67
|
__metadata("design:returntype", void 0)
|
67
|
-
], ProductType.prototype, "
|
68
|
+
], ProductType.prototype, "onInit", null);
|
68
69
|
ProductType = __decorate([
|
69
70
|
(0, core_1.Entity)({ tableName: "product_type" }),
|
70
71
|
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
@@ -27,11 +27,6 @@ let ProductVariantOption = class ProductVariantOption {
|
|
27
27
|
this.variant_id ?? (this.variant_id = this.variant?.id ?? null);
|
28
28
|
this.option_value_id ?? (this.option_value_id = this.option_value?.id ?? null);
|
29
29
|
}
|
30
|
-
beforeCreate() {
|
31
|
-
this.id = (0, utils_1.generateEntityId)(this.id, "varopt");
|
32
|
-
this.variant_id ?? (this.variant_id = this.variant?.id ?? null);
|
33
|
-
this.option_value_id ?? (this.option_value_id = this.option_value?.id ?? null);
|
34
|
-
}
|
35
30
|
};
|
36
31
|
__decorate([
|
37
32
|
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
@@ -43,6 +38,7 @@ __decorate([
|
|
43
38
|
nullable: true,
|
44
39
|
fieldName: "option_value_id",
|
45
40
|
mapToPk: true,
|
41
|
+
onDelete: "cascade",
|
46
42
|
}),
|
47
43
|
__metadata("design:type", String)
|
48
44
|
], ProductVariantOption.prototype, "option_value_id", void 0);
|
@@ -59,6 +55,7 @@ __decorate([
|
|
59
55
|
nullable: true,
|
60
56
|
fieldName: "variant_id",
|
61
57
|
mapToPk: true,
|
58
|
+
onDelete: "cascade",
|
62
59
|
}),
|
63
60
|
__metadata("design:type", Object)
|
64
61
|
], ProductVariantOption.prototype, "variant_id", void 0);
|
@@ -93,16 +90,11 @@ __decorate([
|
|
93
90
|
], ProductVariantOption.prototype, "deleted_at", void 0);
|
94
91
|
__decorate([
|
95
92
|
(0, core_1.OnInit)(),
|
96
|
-
__metadata("design:type", Function),
|
97
|
-
__metadata("design:paramtypes", []),
|
98
|
-
__metadata("design:returntype", void 0)
|
99
|
-
], ProductVariantOption.prototype, "onInit", null);
|
100
|
-
__decorate([
|
101
93
|
(0, core_1.BeforeCreate)(),
|
102
94
|
__metadata("design:type", Function),
|
103
95
|
__metadata("design:paramtypes", []),
|
104
96
|
__metadata("design:returntype", void 0)
|
105
|
-
], ProductVariantOption.prototype, "
|
97
|
+
], ProductVariantOption.prototype, "onInit", null);
|
106
98
|
ProductVariantOption = __decorate([
|
107
99
|
(0, core_1.Entity)({ tableName: "product_variant_option" }),
|
108
100
|
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
@@ -1,10 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { Collection, OptionalProps } from "@mikro-orm/core";
|
1
|
+
import { Collection } from "@mikro-orm/core";
|
3
2
|
import { Product } from ".";
|
4
3
|
import ProductVariantOption from "./product-variant-option";
|
5
|
-
type OptionalFields = "allow_backorder" | "manage_inventory" | "product" | "product_id" | DAL.SoftDeletableEntityDateColumns;
|
6
4
|
declare class ProductVariant {
|
7
|
-
[OptionalProps]?: OptionalFields;
|
8
5
|
id: string;
|
9
6
|
title: string;
|
10
7
|
sku?: string | null;
|
@@ -26,11 +23,10 @@ declare class ProductVariant {
|
|
26
23
|
variant_rank?: number | null;
|
27
24
|
product_id: string | null;
|
28
25
|
product: Product | null;
|
26
|
+
options: Collection<ProductVariantOption, object>;
|
29
27
|
created_at: Date;
|
30
28
|
updated_at: Date;
|
31
29
|
deleted_at?: Date;
|
32
|
-
options: Collection<ProductVariantOption, object>;
|
33
30
|
onInit(): void;
|
34
|
-
onCreate(): void;
|
35
31
|
}
|
36
32
|
export default ProductVariant;
|
@@ -16,8 +16,54 @@ const utils_1 = require("@medusajs/utils");
|
|
16
16
|
const core_1 = require("@mikro-orm/core");
|
17
17
|
const _models_1 = require(".");
|
18
18
|
const product_variant_option_1 = __importDefault(require("./product-variant-option"));
|
19
|
+
const variantSkuIndexName = "IDX_product_variant_sku_unique";
|
20
|
+
const variantSkuIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
21
|
+
name: variantSkuIndexName,
|
22
|
+
tableName: "product_variant",
|
23
|
+
columns: ["sku"],
|
24
|
+
unique: true,
|
25
|
+
where: "deleted_at IS NULL",
|
26
|
+
});
|
27
|
+
const variantBarcodeIndexName = "IDX_product_variant_barcode_unique";
|
28
|
+
const variantBarcodeIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
29
|
+
name: variantBarcodeIndexName,
|
30
|
+
tableName: "product_variant",
|
31
|
+
columns: ["barcode"],
|
32
|
+
unique: true,
|
33
|
+
where: "deleted_at IS NULL",
|
34
|
+
});
|
35
|
+
const variantEanIndexName = "IDX_product_variant_ean_unique";
|
36
|
+
const variantEanIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
37
|
+
name: variantEanIndexName,
|
38
|
+
tableName: "product_variant",
|
39
|
+
columns: ["ean"],
|
40
|
+
unique: true,
|
41
|
+
where: "deleted_at IS NULL",
|
42
|
+
});
|
43
|
+
const variantUpcIndexName = "IDX_product_variant_upc_unique";
|
44
|
+
const variantUpcIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
45
|
+
name: variantUpcIndexName,
|
46
|
+
tableName: "product_variant",
|
47
|
+
columns: ["upc"],
|
48
|
+
unique: true,
|
49
|
+
where: "deleted_at IS NULL",
|
50
|
+
});
|
51
|
+
const variantProductIdIndexName = "IDX_product_variant_product_id";
|
52
|
+
const variantProductIdIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
53
|
+
name: variantProductIdIndexName,
|
54
|
+
tableName: "product_variant",
|
55
|
+
columns: ["product_id"],
|
56
|
+
unique: false,
|
57
|
+
where: "deleted_at IS NULL",
|
58
|
+
});
|
59
|
+
variantProductIdIndexStatement.MikroORMIndex();
|
60
|
+
variantSkuIndexStatement.MikroORMIndex();
|
61
|
+
variantBarcodeIndexStatement.MikroORMIndex();
|
62
|
+
variantEanIndexStatement.MikroORMIndex();
|
63
|
+
variantUpcIndexStatement.MikroORMIndex();
|
19
64
|
let ProductVariant = class ProductVariant {
|
20
65
|
constructor() {
|
66
|
+
// TODO: replace with BigNumber
|
21
67
|
// Note: Upon serialization, this turns to a string. This is on purpose, because you would loose
|
22
68
|
// precision if you cast numeric to JS number, as JS number is a float.
|
23
69
|
// Ref: https://github.com/mikro-orm/mikro-orm/issues/2295
|
@@ -30,10 +76,6 @@ let ProductVariant = class ProductVariant {
|
|
30
76
|
this.id = (0, utils_1.generateEntityId)(this.id, "variant");
|
31
77
|
this.product_id ?? (this.product_id = this.product?.id ?? null);
|
32
78
|
}
|
33
|
-
onCreate() {
|
34
|
-
this.id = (0, utils_1.generateEntityId)(this.id, "variant");
|
35
|
-
this.product_id ?? (this.product_id = this.product?.id ?? null);
|
36
|
-
}
|
37
79
|
};
|
38
80
|
__decorate([
|
39
81
|
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
@@ -45,34 +87,18 @@ __decorate([
|
|
45
87
|
], ProductVariant.prototype, "title", void 0);
|
46
88
|
__decorate([
|
47
89
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
48
|
-
(0, core_1.Unique)({
|
49
|
-
name: "IDX_product_variant_sku_unique",
|
50
|
-
properties: ["sku"],
|
51
|
-
}),
|
52
90
|
__metadata("design:type", Object)
|
53
91
|
], ProductVariant.prototype, "sku", void 0);
|
54
92
|
__decorate([
|
55
93
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
56
|
-
(0, core_1.Unique)({
|
57
|
-
name: "IDX_product_variant_barcode_unique",
|
58
|
-
properties: ["barcode"],
|
59
|
-
}),
|
60
94
|
__metadata("design:type", Object)
|
61
95
|
], ProductVariant.prototype, "barcode", void 0);
|
62
96
|
__decorate([
|
63
97
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
64
|
-
(0, core_1.Unique)({
|
65
|
-
name: "IDX_product_variant_ean_unique",
|
66
|
-
properties: ["ean"],
|
67
|
-
}),
|
68
98
|
__metadata("design:type", Object)
|
69
99
|
], ProductVariant.prototype, "ean", void 0);
|
70
100
|
__decorate([
|
71
101
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
72
|
-
(0, core_1.Unique)({
|
73
|
-
name: "IDX_product_variant_upc_unique",
|
74
|
-
properties: ["upc"],
|
75
|
-
}),
|
76
102
|
__metadata("design:type", Object)
|
77
103
|
], ProductVariant.prototype, "upc", void 0);
|
78
104
|
__decorate([
|
@@ -142,7 +168,6 @@ __decorate([
|
|
142
168
|
nullable: true,
|
143
169
|
onDelete: "cascade",
|
144
170
|
fieldName: "product_id",
|
145
|
-
index: "IDX_product_variant_product_id",
|
146
171
|
mapToPk: true,
|
147
172
|
}),
|
148
173
|
__metadata("design:type", Object)
|
@@ -154,6 +179,12 @@ __decorate([
|
|
154
179
|
}),
|
155
180
|
__metadata("design:type", Object)
|
156
181
|
], ProductVariant.prototype, "product", void 0);
|
182
|
+
__decorate([
|
183
|
+
(0, core_1.OneToMany)(() => product_variant_option_1.default, (variantOption) => variantOption.variant, {
|
184
|
+
cascade: [core_1.Cascade.PERSIST, "soft-remove"],
|
185
|
+
}),
|
186
|
+
__metadata("design:type", Object)
|
187
|
+
], ProductVariant.prototype, "options", void 0);
|
157
188
|
__decorate([
|
158
189
|
(0, core_1.Property)({
|
159
190
|
onCreate: () => new Date(),
|
@@ -176,24 +207,13 @@ __decorate([
|
|
176
207
|
(0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
|
177
208
|
__metadata("design:type", Date)
|
178
209
|
], ProductVariant.prototype, "deleted_at", void 0);
|
179
|
-
__decorate([
|
180
|
-
(0, core_1.OneToMany)(() => product_variant_option_1.default, (variantOption) => variantOption.variant, {
|
181
|
-
cascade: [core_1.Cascade.PERSIST, core_1.Cascade.REMOVE, "soft-remove"],
|
182
|
-
}),
|
183
|
-
__metadata("design:type", Object)
|
184
|
-
], ProductVariant.prototype, "options", void 0);
|
185
210
|
__decorate([
|
186
211
|
(0, core_1.OnInit)(),
|
187
|
-
__metadata("design:type", Function),
|
188
|
-
__metadata("design:paramtypes", []),
|
189
|
-
__metadata("design:returntype", void 0)
|
190
|
-
], ProductVariant.prototype, "onInit", null);
|
191
|
-
__decorate([
|
192
212
|
(0, core_1.BeforeCreate)(),
|
193
213
|
__metadata("design:type", Function),
|
194
214
|
__metadata("design:paramtypes", []),
|
195
215
|
__metadata("design:returntype", void 0)
|
196
|
-
], ProductVariant.prototype, "
|
216
|
+
], ProductVariant.prototype, "onInit", null);
|
197
217
|
ProductVariant = __decorate([
|
198
218
|
(0, core_1.Entity)({ tableName: "product_variant" }),
|
199
219
|
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
package/dist/models/product.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import { Collection
|
2
|
-
import { DAL } from "@medusajs/types";
|
1
|
+
import { Collection } from "@mikro-orm/core";
|
3
2
|
import { ProductUtils } from "@medusajs/utils";
|
4
3
|
import ProductCategory from "./product-category";
|
5
4
|
import ProductCollection from "./product-collection";
|
@@ -8,13 +7,10 @@ import ProductOption from "./product-option";
|
|
8
7
|
import ProductTag from "./product-tag";
|
9
8
|
import ProductType from "./product-type";
|
10
9
|
import ProductVariant from "./product-variant";
|
11
|
-
type OptionalRelations = "collection" | "type";
|
12
|
-
type OptionalFields = "collection_id" | "type_id" | "is_giftcard" | "discountable" | DAL.SoftDeletableEntityDateColumns;
|
13
10
|
declare class Product {
|
14
|
-
[OptionalProps]?: OptionalRelations | OptionalFields;
|
15
11
|
id: string;
|
16
12
|
title: string;
|
17
|
-
handle?: string
|
13
|
+
handle?: string;
|
18
14
|
subtitle?: string | null;
|
19
15
|
description?: string | null;
|
20
16
|
is_giftcard: boolean;
|
@@ -44,6 +40,5 @@ declare class Product {
|
|
44
40
|
deleted_at?: Date;
|
45
41
|
metadata?: Record<string, unknown> | null;
|
46
42
|
onInit(): void;
|
47
|
-
beforeCreate(): void;
|
48
43
|
}
|
49
44
|
export default Product;
|
package/dist/models/product.js
CHANGED
@@ -21,6 +21,33 @@ const product_option_1 = __importDefault(require("./product-option"));
|
|
21
21
|
const product_tag_1 = __importDefault(require("./product-tag"));
|
22
22
|
const product_type_1 = __importDefault(require("./product-type"));
|
23
23
|
const product_variant_1 = __importDefault(require("./product-variant"));
|
24
|
+
const productHandleIndexName = "IDX_product_handle_unique";
|
25
|
+
const productHandleIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
26
|
+
name: productHandleIndexName,
|
27
|
+
tableName: "product",
|
28
|
+
columns: ["handle"],
|
29
|
+
unique: true,
|
30
|
+
where: "deleted_at IS NULL",
|
31
|
+
});
|
32
|
+
const productTypeIndexName = "IDX_product_type_id";
|
33
|
+
const productTypeIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
34
|
+
name: productTypeIndexName,
|
35
|
+
tableName: "product",
|
36
|
+
columns: ["type_id"],
|
37
|
+
unique: false,
|
38
|
+
where: "deleted_at IS NULL",
|
39
|
+
});
|
40
|
+
const productCollectionIndexName = "IDX_product_collection_id";
|
41
|
+
const productCollectionIndexStatement = (0, utils_1.createPsqlIndexStatementHelper)({
|
42
|
+
name: productCollectionIndexName,
|
43
|
+
tableName: "product",
|
44
|
+
columns: ["collection_id"],
|
45
|
+
unique: false,
|
46
|
+
where: "deleted_at IS NULL",
|
47
|
+
});
|
48
|
+
productTypeIndexStatement.MikroORMIndex();
|
49
|
+
productCollectionIndexStatement.MikroORMIndex();
|
50
|
+
productHandleIndexStatement.MikroORMIndex();
|
24
51
|
let Product = class Product {
|
25
52
|
constructor() {
|
26
53
|
this.options = new core_1.Collection(this);
|
@@ -37,14 +64,6 @@ let Product = class Product {
|
|
37
64
|
this.handle = (0, utils_1.kebabCase)(this.title);
|
38
65
|
}
|
39
66
|
}
|
40
|
-
beforeCreate() {
|
41
|
-
this.id = (0, utils_1.generateEntityId)(this.id, "prod");
|
42
|
-
this.type_id ?? (this.type_id = this.type?.id ?? null);
|
43
|
-
this.collection_id ?? (this.collection_id = this.collection?.id ?? null);
|
44
|
-
if (!this.handle && this.title) {
|
45
|
-
this.handle = (0, utils_1.kebabCase)(this.title);
|
46
|
-
}
|
47
|
-
}
|
48
67
|
};
|
49
68
|
__decorate([
|
50
69
|
(0, core_1.PrimaryKey)({ columnType: "text" }),
|
@@ -56,11 +75,7 @@ __decorate([
|
|
56
75
|
], Product.prototype, "title", void 0);
|
57
76
|
__decorate([
|
58
77
|
(0, core_1.Property)({ columnType: "text" }),
|
59
|
-
(
|
60
|
-
name: "IDX_product_handle_unique",
|
61
|
-
properties: ["handle"],
|
62
|
-
}),
|
63
|
-
__metadata("design:type", Object)
|
78
|
+
__metadata("design:type", String)
|
64
79
|
], Product.prototype, "handle", void 0);
|
65
80
|
__decorate([
|
66
81
|
(0, core_1.Property)({ columnType: "text", nullable: true }),
|
@@ -133,6 +148,7 @@ __decorate([
|
|
133
148
|
nullable: true,
|
134
149
|
fieldName: "collection_id",
|
135
150
|
mapToPk: true,
|
151
|
+
onDelete: "set null",
|
136
152
|
}),
|
137
153
|
__metadata("design:type", Object)
|
138
154
|
], Product.prototype, "collection_id", void 0);
|
@@ -148,8 +164,8 @@ __decorate([
|
|
148
164
|
columnType: "text",
|
149
165
|
nullable: true,
|
150
166
|
fieldName: "type_id",
|
151
|
-
index: "IDX_product_type_id",
|
152
167
|
mapToPk: true,
|
168
|
+
onDelete: "set null",
|
153
169
|
}),
|
154
170
|
__metadata("design:type", Object)
|
155
171
|
], Product.prototype, "type_id", void 0);
|
@@ -172,7 +188,6 @@ __decorate([
|
|
172
188
|
(0, core_1.ManyToMany)(() => product_image_1.default, "products", {
|
173
189
|
owner: true,
|
174
190
|
pivotTable: "product_images",
|
175
|
-
index: "IDX_product_image_id",
|
176
191
|
joinColumn: "product_id",
|
177
192
|
inverseJoinColumn: "image_id",
|
178
193
|
}),
|
@@ -221,16 +236,11 @@ __decorate([
|
|
221
236
|
], Product.prototype, "metadata", void 0);
|
222
237
|
__decorate([
|
223
238
|
(0, core_1.OnInit)(),
|
224
|
-
__metadata("design:type", Function),
|
225
|
-
__metadata("design:paramtypes", []),
|
226
|
-
__metadata("design:returntype", void 0)
|
227
|
-
], Product.prototype, "onInit", null);
|
228
|
-
__decorate([
|
229
239
|
(0, core_1.BeforeCreate)(),
|
230
240
|
__metadata("design:type", Function),
|
231
241
|
__metadata("design:paramtypes", []),
|
232
242
|
__metadata("design:returntype", void 0)
|
233
|
-
], Product.prototype, "
|
243
|
+
], Product.prototype, "onInit", null);
|
234
244
|
Product = __decorate([
|
235
245
|
(0, core_1.Entity)({ tableName: "product" }),
|
236
246
|
(0, core_1.Filter)(utils_1.DALUtils.mikroOrmSoftDeletableFilterOptions)
|
@@ -66,6 +66,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
|
|
66
66
|
product_id: [...new Set(data.map((v) => v.product_id))],
|
67
67
|
}, {
|
68
68
|
take: null,
|
69
|
+
relations: ["values"],
|
69
70
|
}, sharedContext);
|
70
71
|
const productVariantsWithOptions = ProductModuleService.assignOptionsToVariants(data, productOptions);
|
71
72
|
return await this.productVariantService_.create(productVariantsWithOptions, sharedContext);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/product",
|
3
|
-
"version": "0.4.0-snapshot-
|
3
|
+
"version": "0.4.0-snapshot-20240402145055",
|
4
4
|
"description": "Medusa Product module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -41,7 +41,7 @@
|
|
41
41
|
"cross-env": "^5.2.1",
|
42
42
|
"faker": "^6.6.6",
|
43
43
|
"jest": "^29.6.3",
|
44
|
-
"medusa-test-utils": "1.1.44-snapshot-
|
44
|
+
"medusa-test-utils": "1.1.44-snapshot-20240402145055",
|
45
45
|
"pg-god": "^1.0.12",
|
46
46
|
"rimraf": "^3.0.2",
|
47
47
|
"ts-jest": "^29.1.1",
|
@@ -50,9 +50,9 @@
|
|
50
50
|
"typescript": "^5.1.6"
|
51
51
|
},
|
52
52
|
"dependencies": {
|
53
|
-
"@medusajs/modules-sdk": "1.12.11-snapshot-
|
54
|
-
"@medusajs/types": "1.12.0-snapshot-
|
55
|
-
"@medusajs/utils": "1.12.0-snapshot-
|
53
|
+
"@medusajs/modules-sdk": "1.12.11-snapshot-20240402145055",
|
54
|
+
"@medusajs/types": "1.12.0-snapshot-20240402145055",
|
55
|
+
"@medusajs/utils": "1.12.0-snapshot-20240402145055",
|
56
56
|
"@mikro-orm/core": "5.9.7",
|
57
57
|
"@mikro-orm/migrations": "5.9.7",
|
58
58
|
"@mikro-orm/postgresql": "5.9.7",
|
/package/dist/migrations/{InitialSetup20240325200756.d.ts → InitialSetup20240401153642.d.ts}
RENAMED
File without changes
|