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,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`],
}

View File

@@ -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"
}
}

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
*/

View File

@@ -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"
]
}

View File

@@ -1,8 +0,0 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": ["node_modules", "dist"],
"compilerOptions": {
"sourceMap": true
}
}

View File

@@ -6744,22 +6744,22 @@ __metadata:
"@mikro-orm/core": 5.9.7
"@mikro-orm/migrations": 5.9.7
"@mikro-orm/postgresql": 5.9.7
"@types/express": ^4.17.17
"@swc/jest": ^0.2.36
"@types/express": ^4.17.21
awilix: ^8.0.1
bignumber.js: ^9.1.2
cross-env: ^5.2.1
dotenv: ^16.4.5
dotenv-expand: ^11.0.6
expect-type: ^0.19.0
express: ^4.18.2
expect-type: ^0.20.0
express: ^4.21.0
jest: ^29.7.0
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
rimraf: ^5.0.1
ts-jest: ^29.1.1
typescript: ^5.1.6
typescript: ^5.6.2
ulid: ^2.3.0
languageName: unknown
linkType: soft
@@ -13643,7 +13643,7 @@ __metadata:
languageName: node
linkType: hard
"@types/express@npm:*, @types/express@npm:^4.17.17, @types/express@npm:^4.7.0":
"@types/express@npm:*, @types/express@npm:^4.17.17, @types/express@npm:^4.17.21, @types/express@npm:^4.7.0":
version: 4.17.21
resolution: "@types/express@npm:4.17.21"
dependencies:
@@ -20003,13 +20003,6 @@ __metadata:
languageName: node
linkType: hard
"expect-type@npm:^0.19.0":
version: 0.19.0
resolution: "expect-type@npm:0.19.0"
checksum: 0a7305021c3e37bf024ce01f0a141de109435ac4225457c35fbd649a0d8cdc19b9078185fd9aaa9ebb136a88c5065d27a60883ab0f961ddc281c11851ed18097
languageName: node
linkType: hard
"expect-type@npm:^0.20.0":
version: 0.20.0
resolution: "expect-type@npm:0.20.0"
@@ -20169,6 +20162,45 @@ __metadata:
languageName: node
linkType: hard
"express@npm:^4.21.0":
version: 4.21.0
resolution: "express@npm:4.21.0"
dependencies:
accepts: ~1.3.8
array-flatten: 1.1.1
body-parser: 1.20.3
content-disposition: 0.5.4
content-type: ~1.0.4
cookie: 0.6.0
cookie-signature: 1.0.6
debug: 2.6.9
depd: 2.0.0
encodeurl: ~2.0.0
escape-html: ~1.0.3
etag: ~1.8.1
finalhandler: 1.3.1
fresh: 0.5.2
http-errors: 2.0.0
merge-descriptors: 1.0.3
methods: ~1.1.2
on-finished: 2.4.1
parseurl: ~1.3.3
path-to-regexp: 0.1.10
proxy-addr: ~2.0.7
qs: 6.13.0
range-parser: ~1.2.1
safe-buffer: 5.2.1
send: 0.19.0
serve-static: 1.16.2
setprototypeof: 1.2.0
statuses: 2.0.1
type-is: ~1.6.18
utils-merge: 1.0.1
vary: ~1.1.2
checksum: 4cf7ca328f3fdeb720f30ccb2ea7708bfa7d345f9cc460b64a82bf1b2c91e5b5852ba15a9a11b2a165d6089acf83457fc477dc904d59cd71ed34c7a91762c6cc
languageName: node
linkType: hard
"extend@npm:^3.0.0, extend@npm:~3.0.2":
version: 3.0.2
resolution: "extend@npm:3.0.2"
@@ -20526,6 +20558,21 @@ __metadata:
languageName: node
linkType: hard
"finalhandler@npm:1.3.1":
version: 1.3.1
resolution: "finalhandler@npm:1.3.1"
dependencies:
debug: 2.6.9
encodeurl: ~2.0.0
escape-html: ~1.0.3
on-finished: 2.4.1
parseurl: ~1.3.3
statuses: 2.0.1
unpipe: ~1.0.0
checksum: d38035831865a49b5610206a3a9a9aae4e8523cbbcd01175d0480ffbf1278c47f11d89be3ca7f617ae6d94f29cf797546a4619cd84dd109009ef33f12f69019f
languageName: node
linkType: hard
"finalhandler@npm:~1.1.2":
version: 1.1.2
resolution: "finalhandler@npm:1.1.2"
@@ -27057,13 +27104,20 @@ __metadata:
languageName: node
linkType: hard
"pg-connection-string@npm:^2.6.2, pg-connection-string@npm:^2.6.4":
"pg-connection-string@npm:^2.6.2":
version: 2.6.4
resolution: "pg-connection-string@npm:2.6.4"
checksum: 0d0b617df0fc6507bf6a94bdcd56c7a305788a1402d69bff9773350947c8f525d6d8136128065370749a3325e99658ae40fbdcce620fb8e60126181f0591a6a6
languageName: node
linkType: hard
"pg-connection-string@npm:^2.7.0":
version: 2.7.0
resolution: "pg-connection-string@npm:2.7.0"
checksum: 50a1496a1c858f9495d78a2c7a66d93ef3602e718aff2953bb5738f3ea616d7f727f32fc20513c9bed127650cd14c1ddc7b458396f4000e689d4b64c65c5c51e
languageName: node
linkType: hard
"pg-god@npm:^1.0.12":
version: 1.0.12
resolution: "pg-god@npm:1.0.12"
@@ -30278,6 +30332,18 @@ __metadata:
languageName: node
linkType: hard
"serve-static@npm:1.16.2":
version: 1.16.2
resolution: "serve-static@npm:1.16.2"
dependencies:
encodeurl: ~2.0.0
escape-html: ~1.0.3
parseurl: ~1.3.3
send: 0.19.0
checksum: 528fff6f5e12d0c5a391229ad893910709bc51b5705962b09404a1d813857578149b8815f35d3ee5752f44cd378d0f31669d4b1d7e2d11f41e08283d5134bd1f
languageName: node
linkType: hard
"set-blocking@npm:^2.0.0":
version: 2.0.0
resolution: "set-blocking@npm:2.0.0"