feat(inventory-next, types): inventory module conversion (#6596)
* init * create new interface * prep integration tests * update denpencies * inventory service partial tests * finalize integration tests * add events * align events * adjust inventory level reservation levels * add test validating reserved quantity after reseration item update * fix nits * rename to inventory-next * update yarn.lock * remove changelog * remove fixtures * remove unused files * ready for review * Update packages/inventory-next/package.json Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * pr feedback * add tests and docs for partition-array util * remote decorators from private method * fix unit tests * add migrations * add foreign keys * fix build --------- Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
@@ -12,4 +12,5 @@ export * as PromotionUtils from "./promotion"
|
||||
export * as SearchUtils from "./search"
|
||||
export * as ShippingProfileUtils from "./shipping"
|
||||
export * as UserUtils from "./user"
|
||||
export * as InventoryUtils from "./inventory"
|
||||
export * as ApiKeyUtils from "./api-key"
|
||||
|
||||
12
packages/utils/src/common/__tests__/partition-array.spec.ts
Normal file
12
packages/utils/src/common/__tests__/partition-array.spec.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { partitionArray } from "../../../dist"
|
||||
|
||||
describe("partitionArray", function () {
|
||||
it("should split array according to predicate", function () {
|
||||
const res = partitionArray([1, 2, 3, 4, 5], (x) => x % 2 === 0)
|
||||
|
||||
expect(res).toEqual([
|
||||
[2, 4],
|
||||
[1, 3, 5],
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -32,6 +32,7 @@ export * from "./medusa-container"
|
||||
export * from "./object-from-string-path"
|
||||
export * from "./object-to-string-path"
|
||||
export * from "./optional-numeric-serializer"
|
||||
export * from "./partition-array"
|
||||
export * from "./pick-deep"
|
||||
export * from "./pick-value-from-object"
|
||||
export * from "./plurailze"
|
||||
|
||||
30
packages/utils/src/common/partition-array.ts
Normal file
30
packages/utils/src/common/partition-array.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Partitions an array into two arrays based on a predicate function
|
||||
|
||||
* @example
|
||||
* const result = partitionArray([1, 2, 3, 4, 5], (x) => x % 2 === 0)
|
||||
*
|
||||
* console.log(result)
|
||||
*
|
||||
* // output: [[2, 4], [1, 3, 5]]
|
||||
*
|
||||
* @param {T} input input array of type T
|
||||
* @param {(T) => boolean} predicate function to use when split array elements
|
||||
*/
|
||||
export const partitionArray = <T>(
|
||||
input: T[],
|
||||
predicate: (T) => boolean
|
||||
): [T[], T[]] => {
|
||||
return input.reduce(
|
||||
([pos, neg], currentElement) => {
|
||||
if (predicate(currentElement)) {
|
||||
pos.push(currentElement)
|
||||
} else {
|
||||
neg.push(currentElement)
|
||||
}
|
||||
|
||||
return [pos, neg]
|
||||
},
|
||||
[[], []] as [T[], T[]]
|
||||
)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ export enum CommonEvents {
|
||||
CREATED = "created",
|
||||
UPDATED = "updated",
|
||||
DELETED = "deleted",
|
||||
RESTORED = "restored",
|
||||
ATTACHED = "attached",
|
||||
DETACHED = "detached",
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ export * from "./event-bus"
|
||||
export * from "./exceptions"
|
||||
export * from "./feature-flags"
|
||||
export * from "./fulfillment"
|
||||
export * from "./inventory"
|
||||
export * from "./modules-sdk"
|
||||
export * from "./orchestration"
|
||||
export * from "./order"
|
||||
|
||||
14
packages/utils/src/inventory/events.ts
Normal file
14
packages/utils/src/inventory/events.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { CommonEvents } from "../event-bus"
|
||||
|
||||
export const InventoryEvents = {
|
||||
created: "inventory-item." + CommonEvents.CREATED,
|
||||
updated: "inventory-item." + CommonEvents.UPDATED,
|
||||
deleted: "inventory-item." + CommonEvents.DELETED,
|
||||
restored: "inventory-item." + CommonEvents.RESTORED,
|
||||
reservation_item_created: "reservation-item." + CommonEvents.CREATED,
|
||||
reservation_item_updated: "reservation-item." + CommonEvents.UPDATED,
|
||||
reservation_item_deleted: "reservation-item." + CommonEvents.DELETED,
|
||||
inventory_level_deleted: "inventory-level." + CommonEvents.DELETED,
|
||||
inventory_level_created: "inventory-level." + CommonEvents.CREATED,
|
||||
inventory_level_updated: "inventory-level." + CommonEvents.UPDATED,
|
||||
}
|
||||
1
packages/utils/src/inventory/index.ts
Normal file
1
packages/utils/src/inventory/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./events"
|
||||
@@ -6,10 +6,11 @@ import {
|
||||
ModuleServiceInitializeOptions,
|
||||
RepositoryService,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { asClass } from "awilix"
|
||||
import { internalModuleServiceFactory } from "../internal-module-service-factory"
|
||||
import { lowerCaseFirst } from "../../common"
|
||||
import { mikroOrmBaseRepositoryFactory } from "../../dal"
|
||||
import { internalModuleServiceFactory } from "../internal-module-service-factory"
|
||||
|
||||
type RepositoryLoaderOptions = {
|
||||
moduleModels: Record<string, any>
|
||||
|
||||
Reference in New Issue
Block a user