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:
co-authored by
Adrien de Peretti
parent
79e3578932
commit
97e003ef4f
@@ -1,13 +1,24 @@
|
||||
module.exports = {
|
||||
transform: {
|
||||
"^.+\\.[jt]s?$": [
|
||||
"ts-jest",
|
||||
"^.+\\.[jt]s$": [
|
||||
"@swc/jest",
|
||||
{
|
||||
tsconfig: "tsconfig.spec.json",
|
||||
isolatedModules: true,
|
||||
jsc: {
|
||||
parser: {
|
||||
syntax: "typescript",
|
||||
decorators: true,
|
||||
},
|
||||
transform: {
|
||||
useDefineForClassFields: false,
|
||||
legacyDecorator: true,
|
||||
decoratorMetadata: true,
|
||||
},
|
||||
target: "ES2021",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
testPathIgnorePatterns: [`dist/`, `node_modules/`],
|
||||
testEnvironment: `node`,
|
||||
moduleFileExtensions: [`js`, `ts`],
|
||||
}
|
||||
|
||||
@@ -3,32 +3,37 @@
|
||||
"version": "1.11.9",
|
||||
"description": "Medusa utilities functions shared by Medusa core and Modules",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"exports": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/medusajs/medusa",
|
||||
"directory": "packages/utils"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
"node": ">=20.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"!dist/**/__tests__",
|
||||
"!dist/**/__mocks__",
|
||||
"!dist/**/__fixtures__"
|
||||
],
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.17",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"@types/express": "^4.17.21",
|
||||
"cross-env": "^5.2.1",
|
||||
"expect-type": "^0.19.0",
|
||||
"express": "^4.18.2",
|
||||
"expect-type": "^0.20.0",
|
||||
"express": "^4.21.0",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.1.6"
|
||||
"typescript": "^5.6.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
@@ -40,15 +45,15 @@
|
||||
"dotenv": "^16.4.5",
|
||||
"dotenv-expand": "^11.0.6",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"pg": "^8.12.0",
|
||||
"pg-connection-string": "^2.6.4",
|
||||
"pg": "^8.13.0",
|
||||
"pg-connection-string": "^2.7.0",
|
||||
"pluralize": "^8.0.0",
|
||||
"ulid": "^2.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsc --build",
|
||||
"watch": "tsc --build --watch",
|
||||
"test": "jest --silent --bail --maxWorkers=50% --forceExit --testPathIgnorePatterns='/integration-tests/' -- src/**/__tests__/**/*.ts",
|
||||
"test": "jest --silent=false --bail --maxWorkers=50% --forceExit --testPathIgnorePatterns='/integration-tests/' -- src/**/__tests__/**/*.ts",
|
||||
"test:integration": "jest --silent --bail --runInBand --forceExit -- src/**/integration-tests/__tests__/**/*.ts"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { partitionArray } from "../../../dist"
|
||||
import { partitionArray } from "../../index"
|
||||
|
||||
describe("partitionArray", function () {
|
||||
it("should split array according to predicate", function () {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
+1
-2
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
+2
-2
@@ -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()
|
||||
|
||||
|
||||
@@ -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")
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"outDir": "./dist",
|
||||
"esModuleInterop": true,
|
||||
"declaration": true,
|
||||
"noUnusedLocals": true,
|
||||
"declarationMap": true,
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
@@ -12,19 +13,16 @@
|
||||
"experimentalDecorators": true,
|
||||
"sourceMap": true,
|
||||
"noImplicitReturns": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"noImplicitThis": true,
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"downlevelIteration": true
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": [
|
||||
"dist",
|
||||
"./src/**/__tests__",
|
||||
"./src/**/__mocks__",
|
||||
"./src/**/__fixtures__",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"compilerOptions": {
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user