chore: Cleanup utils package (#9238)

Fixes: FRMW-2712

Old PR: https://github.com/medusajs/medusa/pull/9234 Closed because of incorrect branch naming

Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
Harminder Virk
2024-09-23 16:07:58 +05:30
committed by GitHub
parent 79e3578932
commit 97e003ef4f
17 changed files with 138 additions and 75 deletions

View File

@@ -1,4 +1,4 @@
import { partitionArray } from "../../../dist"
import { partitionArray } from "../../index"
describe("partitionArray", function () {
it("should split array according to predicate", function () {

View File

@@ -2,7 +2,6 @@
import { objectFromStringPath } from "./object-from-string-path"
type Order = {
[key: string]: "ASC" | "DESC" | Order
}
@@ -42,7 +41,7 @@ function buildRelationsOrSelect(collection: string[]): Selects | Relations {
* }
* @param orderBy
*/
export function buildOrder<T>(orderBy: { [k: string]: "ASC" | "DESC" }): Order {
export function buildOrder(orderBy: { [k: string]: "ASC" | "DESC" }): Order {
const output: Order = {}
const orderKeys = Object.keys(orderBy)

View File

@@ -3,5 +3,5 @@ export function toCamelCase(str: string): string {
? str
: str
.toLowerCase()
.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase())
.replace(/[^a-zA-Z0-9]+(.)/g, (_, chr) => chr.toUpperCase())
}

View File

@@ -180,8 +180,7 @@ describe("mikroOrmRepository", () => {
it("should successfully create a flat entity", async () => {
const entity1 = { id: "1", title: "en1", amount: 100 }
const { entities: resp, performedActions } =
await manager1().upsertWithReplace([entity1])
const { performedActions } = await manager1().upsertWithReplace([entity1])
expect(performedActions).toEqual({
created: {

View File

@@ -5,7 +5,7 @@ describe("Array property", () => {
test("should create an array property type", () => {
const property = new ArrayProperty()
expectTypeOf(property["$dataType"]).toEqualTypeOf<[]>()
expectTypeOf(property["$dataType"]).toEqualTypeOf<string[]>()
expect(property.parse("codes")).toEqual({
fieldName: "codes",
dataType: {

View File

@@ -11,10 +11,6 @@ import { HasOne } from "../../relations/has-one"
import { ManyToMany as DmlManyToMany } from "../../relations/many-to-many"
import { parseEntityName } from "../entity-builder/parse-entity-name"
type Context = {
MANY_TO_MANY_TRACKED_RELATIONS: Record<string, boolean>
}
function defineRelationships(
modelName: string,
relationship: RelationshipMetadata,

View File

@@ -8,7 +8,7 @@ describe("MessageAggregator", function () {
it("should group messages by any given group of keys", function () {
const aggregator = new MessageAggregator()
aggregator.save({
eventName: "ProductVariant.created",
name: "ProductVariant.created",
metadata: {
source: "Product",
action: "created",
@@ -18,7 +18,7 @@ describe("MessageAggregator", function () {
data: { id: 999 },
})
aggregator.save({
eventName: "Product.created",
name: "Product.created",
metadata: {
source: "Product",
action: "created",
@@ -28,7 +28,7 @@ describe("MessageAggregator", function () {
data: { id: 1 },
})
aggregator.save({
eventName: "ProductVariant.created",
name: "ProductVariant.created",
metadata: {
source: "Product",
action: "created",
@@ -38,7 +38,7 @@ describe("MessageAggregator", function () {
data: { id: 222 },
})
aggregator.save({
eventName: "ProductType.detached",
name: "ProductType.detached",
metadata: {
source: "Product",
action: "detached",
@@ -48,7 +48,7 @@ describe("MessageAggregator", function () {
data: { id: 333 },
})
aggregator.save({
eventName: "ProductVariant.updated",
name: "ProductVariant.updated",
metadata: {
source: "Product",
action: "updated",
@@ -59,7 +59,7 @@ describe("MessageAggregator", function () {
})
const format = {
groupBy: ["eventName", "metadata.object", "metadata.action"],
groupBy: ["name", "metadata.object", "metadata.action"],
sortBy: {
"metadata.object": ["ProductType", "ProductVariant", "Product"],
"data.id": "asc",
@@ -74,7 +74,7 @@ describe("MessageAggregator", function () {
expect(allGroups[0]).toEqual([
{
eventName: "ProductType.detached",
name: "ProductType.detached",
metadata: {
source: "Product",
action: "detached",
@@ -87,7 +87,7 @@ describe("MessageAggregator", function () {
expect(allGroups[1]).toEqual([
{
eventName: "ProductVariant.updated",
name: "ProductVariant.updated",
metadata: {
source: "Product",
action: "updated",
@@ -100,7 +100,7 @@ describe("MessageAggregator", function () {
expect(allGroups[2]).toEqual([
{
eventName: "ProductVariant.created",
name: "ProductVariant.created",
metadata: {
source: "Product",
action: "created",
@@ -110,7 +110,7 @@ describe("MessageAggregator", function () {
data: { id: 222 },
},
{
eventName: "ProductVariant.created",
name: "ProductVariant.created",
metadata: {
source: "Product",
action: "created",
@@ -123,7 +123,7 @@ describe("MessageAggregator", function () {
expect(allGroups[3]).toEqual([
{
eventName: "Product.created",
name: "Product.created",
metadata: {
source: "Product",
action: "created",

View File

@@ -70,7 +70,7 @@ describe.skip("Revert migrations", () => {
const results = await migrations.revert()
const orm = await MikroORM.init(config)
const usersTableExists = await orm.em.getKnex().schema.hasTable("user")
const usersTableExists = await orm.em["getKnex"]().schema.hasTable("user")
await orm.close()
expect(results).toHaveLength(1)
@@ -171,7 +171,7 @@ describe.skip("Revert migrations", () => {
expect(migrations.revert()).rejects.toThrow(/.*Migration.*/)
const orm = await MikroORM.init(config)
const usersTableExists = await orm.em.getKnex().schema.hasTable("user")
const usersTableExists = await orm.em["getKnex"]().schema.hasTable("user")
await orm.close()
expect(usersTableExists).toEqual(true)

View File

@@ -70,7 +70,7 @@ describe.skip("Run migrations", () => {
const results = await migrations.run()
const orm = await MikroORM.init(config)
const usersTableExists = await orm.em.getKnex().schema.hasTable("user")
const usersTableExists = await orm.em["getKnex"]().schema.hasTable("user")
await orm.close()
expect(results).toHaveLength(1)
@@ -168,7 +168,7 @@ describe.skip("Run migrations", () => {
expect(migrations.run()).rejects.toThrow(/.*Migration.*/)
const orm = await MikroORM.init(config)
const usersTableExists = await orm.em.getKnex().schema.hasTable("user")
const usersTableExists = await orm.em["getKnex"]().schema.hasTable("user")
await orm.close()

View File

@@ -67,6 +67,7 @@ describe("Internal Module Service Factory", () => {
const instance = new compositeIMedusaInternalService(containerMock)
// @ts-expect-error
const err = await instance.retrieve().catch((e) => e)
expect(err.message).toBe("compositeModel - id, name must be defined")
})

View File

@@ -525,7 +525,7 @@ export function MedusaService<
buildMethodNamesFromModel(name, config as TModels[keyof TModels]),
])
for (let [modelName, model, modelMethods] of modelsMethods) {
for (let [modelName, , modelMethods] of modelsMethods) {
Object.entries(modelMethods).forEach(([method, methodName]) => {
buildAndAssignMethodImpl(
AbstractModuleService_.prototype,

View File

@@ -34,10 +34,6 @@ type UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true
? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]>
: [T, ...A]
type Reverse<T extends unknown[], R extends unknown[] = []> = ReturnType<
T extends [infer F, ...infer L] ? () => Reverse<L, [F, ...R]> : () => R
>
/**
* End of utils
*/