chore(order): dml (#10292)

* ../../core/types/src/dml/index.ts

* ../../core/types/src/dml/index.ts

* fix: relationships mapping

* handle nullable foreign keys types

* handle nullable foreign keys types

* handle nullable foreign keys types

* continue to update product category repository

* fix all product category repositories issues

* fix product category service types

* fix product module service types

* fix product module service types

* fix repository template type

* refactor: use a singleton DMLToMikroORM factory instance

Since the MikroORM MetadataStorage is global, we will also have to turn DML
to MikroORM entities conversion use a global bucket as well

* refactor: update product module to use DML in tests

* wip: tests

* WIP product linkable fixes

* continue type fixing and start test fixing

* test: fix more tests

* fix repository

* fix pivot table computaion + fix mikro orm repository

* fix many to many management and configuration

* fix many to many management and configuration

* fix many to many management and configuration

* update product tag relation configuration

* Introduce experimental dml hooks to fix some issues with categories

* more fixes

* fix product tests

* add missing id prefixes

* fix product category handle management

* test: fix more failing tests

* test: make it all green

* test: fix breaking tests

* fix: build issues

* fix: build issues

* fix: more breaking tests

* refactor: fix issues after merge

* refactor: fix issues after merge

* refactor: surpress types error

* test: fix DML failing tests

* improve many to many inference + tests

* Wip fix columns from product entity

* remove product model before create hook and manage handle validation and transformation at the service level

* test: fix breaking unit tests

* fix: product module service to not update handle on product update

* fix define link and joiner config

* test: fix joiner config test

* test: fix joiner config test

* fix joiner config primary keys

* Fix joiner config builder

* Fix joiner config builder

* test: remove only modifier from test

* refactor: remove hooks usage from product collection

* refactor: remove hooks usage from product-option

* refactor: remove hooks usage for computing category handle

* refactor: remove hooks usage from productCategory model

* refactor: remove hooks from DML

* refactor: remove cruft

* order dml

* cleanup

* re add foerign key indexes

* wip

* chore: remove unused types

* wip

* changes

* rm raw

* autoincrement

* wip

* rel

* refactor: cleanup

* migration and models configuration adjustments

* cleanup

* number searchable

* fix random ordering

* fix

* test: fix product-category tests

* test: update breaking DML tests

* test: array assertion to not care about ordering

* fix: temporarily apply id ordering for products

* types

* wip

* WIP type improvements

* update order models

* partially fix types temporarely

* rel

* fix: recursive type issue

* improve type inference breaks

* improve type inference breaks

* update models

* rm nullable

* default value

* repository

* update default value handling

* fix unit tests

* WIP

* toMikroORM

* fix relations

* cascades

* fix

* experimental dml hooks

* rm migration

* serial

* nullable autoincrement

* fix model

* model changes

* fix one to one DML

* order test

* fix addresses

* fix unit tests

* Re align dml entity name inference

* update model table name config

* update model table name config

* revert

* update return relation

* WIP

* hasOne

* models

* fix

* model

* initial commit

* cart service

* order module

* utils unit test

* index engine

* changeset

* merge

* fix hasOne with fk

* update

* free text filter per entity

* tests

* prod category

* property string many to many

* fix big number

* link modules migration set names

* merge

* shipping option rules

* serializer

* unit test

* fix test mikro orm init

* fix test mikro orm init

* Maintain merge object properties

* fix test mikro orm init

* prevent unit test from connecting to db

* wip

* fix test

* fix test

* link test

* schema

* models

* auto increment

* hook

* model hooks

* order

* wip

* orm version

* request return field

* fix return configuration on order model

* workflows

* core flows

* unit test

* test

* base repo

* test

* base repo

* test fix

* inventory move

* locking inventory

* test

* free text fix

* rm timeout mock

* migrate fulfillment values

* v6.4.3

* cleanup

* link-modules update sql

* revert test

* remove fake timers

---------

Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
Co-authored-by: Harminder Virk <virk.officials@gmail.com>
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-01-21 08:04:47 -05:00
1 parent 05c8a67d8e
commit cc73802ab3
178 files changed
+5731 -7120

No files matched your search

@@ -722,57 +722,11 @@ describe("IndexModuleService", function () {
it("should consume all deleted events and delete the index entries", async () => {
const indexEntries = await manager.find(toMikroORMEntity(IndexData), {})
const indexRelationEntries = await manager.find(
toMikroORMEntity(IndexRelation),
{},
{
populate: ["parent", "child"],
}
toMikroORMEntity(IndexRelation)
)
expect(indexEntries).toHaveLength(3)
expect(indexRelationEntries).toHaveLength(2)
const linkIndexEntry = indexEntries.find((entry) => {
return (
entry.name === "LinkProductVariantPriceSet" && entry.id === linkId
)
})!
const priceSetIndexEntry = indexEntries.find((entry) => {
return entry.name === "PriceSet" && entry.id === priceSetId
})!
const priceIndexEntry = indexEntries.find((entry) => {
return entry.name === "Price" && entry.id === priceId
})!
const linkPriceSetIndexRelationEntry = indexRelationEntries.find(
(entry) => {
return (
entry.parent_id === linkId &&
entry.parent_name === "LinkProductVariantPriceSet" &&
entry.child_id === priceSetId &&
entry.child_name === "PriceSet"
)
}
)!
expect(linkPriceSetIndexRelationEntry.parent).toEqual(linkIndexEntry)
expect(linkPriceSetIndexRelationEntry.child).toEqual(priceSetIndexEntry)
const priceSetPriceIndexRelationEntry = indexRelationEntries.find(
(entry) => {
return (
entry.parent_id === priceSetId &&
entry.parent_name === "PriceSet" &&
entry.child_id === priceId &&
entry.child_name === "Price"
)
}
)!
expect(priceSetPriceIndexRelationEntry.parent).toEqual(priceSetIndexEntry)
expect(priceSetPriceIndexRelationEntry.child).toEqual(priceIndexEntry)
})
})
})
+13 -13
View File
@@ -30,19 +30,19 @@
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
"test": "jest --passWithNoTests ./src",
"test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.ts",
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
},
"devDependencies": {
"@medusajs/framework": "^2.3.1",
"@medusajs/test-utils": "^2.3.1",
"@mikro-orm/cli": "5.9.7",
"@mikro-orm/core": "5.9.7",
"@mikro-orm/knex": "5.9.7",
"@mikro-orm/migrations": "5.9.7",
"@mikro-orm/postgresql": "5.9.7",
"@mikro-orm/cli": "6.4.3",
"@mikro-orm/core": "6.4.3",
"@mikro-orm/knex": "6.4.3",
"@mikro-orm/migrations": "6.4.3",
"@mikro-orm/postgresql": "6.4.3",
"@swc/core": "^1.7.28",
"@swc/jest": "^0.2.36",
"jest": "^29.7.0",
@@ -52,10 +52,10 @@
},
"peerDependencies": {
"@medusajs/framework": "^2.0.0",
"@mikro-orm/core": "5.9.7",
"@mikro-orm/knex": "5.9.7",
"@mikro-orm/migrations": "5.9.7",
"@mikro-orm/postgresql": "5.9.7",
"@mikro-orm/core": "6.4.3",
"@mikro-orm/knex": "6.4.3",
"@mikro-orm/migrations": "6.4.3",
"@mikro-orm/postgresql": "6.4.3",
"awilix": "^8.0.1"
}
}
@@ -120,11 +120,11 @@
"columns": {
"id": {
"name": "id",
"type": "number",
"type": "serial",
"unsigned": true,
"autoincrement": true,
"primary": true,
"nullable": false,
"nullable": true,
"mappedType": "integer"
},
"pivot": {
@@ -145,8 +145,8 @@
"nullable": false,
"mappedType": "text"
},
"child_name": {
"name": "child_name",
"parent_id": {
"name": "parent_id",
"type": "text",
"unsigned": false,
"autoincrement": false,
@@ -154,8 +154,8 @@
"nullable": false,
"mappedType": "text"
},
"parent_id": {
"name": "parent_id",
"child_name": {
"name": "child_name",
"type": "text",
"unsigned": false,
"autoincrement": false,
@@ -1,20 +1,10 @@
import { model } from "@medusajs/framework/utils"
import IndexRelation from "./index-relation"
const IndexData = model
.define("IndexData", {
id: model.text().primaryKey(),
name: model.text().primaryKey(),
data: model.json().default({}),
parents: model.manyToMany(() => IndexData, {
mappedBy: "children",
pivotEntity: () => IndexRelation,
joinColumn: ["child_id", "child_name"],
inverseJoinColumn: ["parent_id", "parent_name"],
}),
children: model.manyToMany(() => IndexData, {
mappedBy: "parents",
}),
})
.indexes([
{
@@ -1,16 +1,11 @@
import { model } from "@medusajs/framework/utils"
import IndexData from "./index-data"
const IndexRelation = model.define("IndexRelation", {
id: model.autoincrement().primaryKey(),
pivot: model.text(),
parent_name: model.text(),
parent_id: model.text().index("IDX_index_relation_parent_id"),
child_name: model.text(),
parent: model.belongsTo(() => IndexData, {
mappedBy: "parents",
}),
child: model.belongsTo(() => IndexData, {
mappedBy: "children",
}),
child_id: model.text().index("IDX_index_relation_child_id"),
})
export default IndexRelation
@@ -403,7 +403,9 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
child_name: entity,
pivot: `${parentEntity}-${entity}`,
})
indexRelationRepository.persist(parentIndexRelationEntry)
indexRelationRepository
.getEntityManager()
.persist(parentIndexRelationEntry)
}
}
}
@@ -628,10 +630,9 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
pivot: `${entity}-${childEntityName}`,
})
indexRelationRepository.persist([
parentIndexRelationEntry,
childIndexRelationEntry,
])
indexRelationRepository
.getEntityManager()
.persist([parentIndexRelationEntry, childIndexRelationEntry])
}
}