refactor(types): Align configuration and fixes (#9240)
RESOLVES FRMW-2712 **What** Refactor types packages to use the latest configuration of typescript and fixes issues
This commit is contained in:
committed by
GitHub
parent
94e07c8da0
commit
8ec323b1da
@@ -1,17 +1,24 @@
|
||||
module.exports = {
|
||||
moduleNameMapper: {},
|
||||
transform: {
|
||||
"^.+\\.[jt]s$": [
|
||||
"@swc/jest",
|
||||
{
|
||||
jsc: {
|
||||
parser: { syntax: "typescript", decorators: true },
|
||||
transform: { decoratorMetadata: true },
|
||||
parser: {
|
||||
syntax: "typescript",
|
||||
decorators: true,
|
||||
},
|
||||
transform: {
|
||||
useDefineForClassFields: false,
|
||||
legacyDecorator: true,
|
||||
decoratorMetadata: true,
|
||||
},
|
||||
target: "ES2021",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
testPathIgnorePatterns: [`dist/`, `node_modules/`],
|
||||
testEnvironment: `node`,
|
||||
moduleFileExtensions: [`js`, `ts`],
|
||||
modulePathIgnorePatterns: ["dist/"],
|
||||
}
|
||||
|
||||
@@ -4,22 +4,33 @@
|
||||
"description": "Medusa Types definition",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"export": {
|
||||
".": "./dist/index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/medusajs/medusa",
|
||||
"directory": "packages/types"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
"node": ">=20"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"!dist/**/__tests__",
|
||||
"!dist/**/__fixtures__",
|
||||
"!dist/**/__mocks__"
|
||||
],
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsc --build",
|
||||
"watch": "tsc --build --watch",
|
||||
"test": "exit 0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"awilix": "^8.0.1",
|
||||
"bignumber.js": "^9.1.2",
|
||||
@@ -27,13 +38,8 @@
|
||||
"expect-type": "^0.20.0",
|
||||
"ioredis": "^5.4.1",
|
||||
"rimraf": "^5.0.1",
|
||||
"typescript": "^5.1.6",
|
||||
"typescript": "^5.6.2",
|
||||
"vite": "^5.2.11",
|
||||
"winston": "^3.8.2"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "rimraf dist && tsc -p tsconfig.spec.json --noEmit && tsc -p tsconfig.build.json",
|
||||
"watch": "tsc --build --watch",
|
||||
"test": "exit 0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
// TODO: The intent is to manage fields picking from a object, not to act upon at the moment and just keeping it here for reference.
|
||||
|
||||
import { Prettify } from "./common"
|
||||
|
||||
type Split<S extends string, D extends string> = string extends S
|
||||
? string[]
|
||||
: S extends ""
|
||||
? []
|
||||
: S extends `${infer T}${D}${infer U}`
|
||||
? [T, ...Split<U, D>]
|
||||
: [S]
|
||||
|
||||
type NestedPickHelper<T, Path extends string[]> = Path extends [
|
||||
infer First,
|
||||
...infer Rest
|
||||
]
|
||||
? First extends keyof T
|
||||
? Rest extends string[]
|
||||
? Rest["length"] extends 0
|
||||
? T[First]
|
||||
: T[First] extends Array<infer Item>
|
||||
? {
|
||||
[K in keyof Item as Rest[0] extends "*"
|
||||
? K
|
||||
: K extends Rest[number]
|
||||
? K
|
||||
: never]: Item[K] extends object
|
||||
? NestedPickHelper<Item[K], Rest>
|
||||
: Item[K] extends Array<infer Item>
|
||||
? NestedPickHelper<Item, Rest>
|
||||
: Rest[0] extends "*"
|
||||
? Item[K]
|
||||
: K extends Rest[number]
|
||||
? Item[K]
|
||||
: never
|
||||
}[]
|
||||
: T[First] extends object
|
||||
? {
|
||||
[K in keyof T[First] as Rest[0] extends "*"
|
||||
? K
|
||||
: K extends Rest[number]
|
||||
? K
|
||||
: never]: T[First][K] extends object
|
||||
? NestedPickHelper<T[First], Rest>
|
||||
: T[First][K] extends Array<infer Item>
|
||||
? NestedPickHelper<Item, Rest>
|
||||
: Rest[0] extends "*"
|
||||
? T[First][K]
|
||||
: K extends Rest[number]
|
||||
? T[First][K]
|
||||
: never
|
||||
}
|
||||
: First extends "*"
|
||||
? {
|
||||
[K in keyof T]: T[K]
|
||||
}
|
||||
: {
|
||||
[K in keyof T[First] as K extends Rest[number]
|
||||
? K
|
||||
: never]: NestedPickHelper<T[First], Rest>
|
||||
}
|
||||
: never
|
||||
: First extends `${infer ArrayKey}[${infer Index}]`
|
||||
? ArrayKey extends keyof T
|
||||
? T[ArrayKey] extends (infer U)[]
|
||||
? NestedPickHelper<U, Rest & string[]>
|
||||
: never
|
||||
: never
|
||||
: First extends "*"
|
||||
? T
|
||||
: never
|
||||
: T
|
||||
|
||||
type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (
|
||||
x: infer I
|
||||
) => void
|
||||
? I
|
||||
: never
|
||||
|
||||
export type NestedPickFirstIteration<T, Props extends string[]> = {
|
||||
[P in Props[number] as Split<P, ".">[0] & string]: NestedPickHelper<
|
||||
T,
|
||||
Split<P, ".">
|
||||
>
|
||||
}
|
||||
|
||||
type NestedPick<T, Props extends string[]> = {
|
||||
[K in keyof NestedPickFirstIteration<T, Props>]: Prettify<
|
||||
NestedPickFirstIteration<T, Props>[K] extends Array<infer V>
|
||||
? UnionToIntersection<V>[]
|
||||
: UnionToIntersection<NestedPickFirstIteration<T, Props>[K]>
|
||||
>
|
||||
}
|
||||
|
||||
type Obj = {
|
||||
id: string
|
||||
title: string
|
||||
variant: {
|
||||
id: string
|
||||
description: string
|
||||
}
|
||||
options: { id: string; value: string }[]
|
||||
extra: {
|
||||
detail: {
|
||||
name: string
|
||||
info: {
|
||||
data: string
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Test = NestedPick<
|
||||
Obj,
|
||||
[
|
||||
"id",
|
||||
"variant.description",
|
||||
"variant.id",
|
||||
"options.id",
|
||||
"options.value",
|
||||
"extra.detail.info.data"
|
||||
]
|
||||
>
|
||||
|
||||
const test: Test = {
|
||||
id: "test",
|
||||
variant: {
|
||||
description: "test",
|
||||
id: "test",
|
||||
},
|
||||
options: [
|
||||
{
|
||||
id: "test",
|
||||
value: "test",
|
||||
},
|
||||
],
|
||||
extra: {
|
||||
detail: {
|
||||
info: {
|
||||
data: "test",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
import { OperatorMap } from "../../dal"
|
||||
import { ClaimReason, OrderClaimType, ReturnDTO } from "../../order"
|
||||
import { ClaimReason, OrderClaimType } from "../../order"
|
||||
import { BigNumberRawValue } from "../../totals"
|
||||
import { FindParams } from "../common"
|
||||
import { BaseOrder, BaseOrderShippingMethod, BaseOrderTransaction } from "../order/common"
|
||||
import {
|
||||
BaseOrder,
|
||||
BaseOrderShippingMethod,
|
||||
BaseOrderTransaction,
|
||||
} from "../order/common"
|
||||
import { BaseReturn } from "../return/common"
|
||||
|
||||
export interface BaseClaimItem {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import { BaseCollection, BaseCollectionListParams } from "../common"
|
||||
import { BaseCollection } from "../common"
|
||||
|
||||
export interface StoreCollection extends BaseCollection {}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
BasePaymentCollectionFilters,
|
||||
BasePaymentProviderFilters,
|
||||
BasePaymentSessionFilters,
|
||||
} from "../common"
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { BaseFilterable, OperatorMap } from "../../../dal";
|
||||
import { FindParams } from "../../common";
|
||||
import {
|
||||
BaseRegionCountryFilters,
|
||||
BaseRegionFilters,
|
||||
} from "../common"
|
||||
import { BaseFilterable, OperatorMap } from "../../../dal"
|
||||
import { FindParams } from "../../common"
|
||||
import { BaseRegionCountryFilters } from "../common"
|
||||
|
||||
export interface AdminRegionFilters extends FindParams, BaseFilterable<AdminRegionFilters> {
|
||||
export interface AdminRegionFilters
|
||||
extends FindParams,
|
||||
BaseFilterable<AdminRegionFilters> {
|
||||
q?: string
|
||||
id?: string | string[]
|
||||
currency_code?: string | string[]
|
||||
@@ -14,4 +13,4 @@ export interface AdminRegionFilters extends FindParams, BaseFilterable<AdminRegi
|
||||
updated_at?: OperatorMap<string>
|
||||
deleted_at?: OperatorMap<string>
|
||||
}
|
||||
export interface AdminRegionCountryFilters extends BaseRegionCountryFilters {}
|
||||
export interface AdminRegionCountryFilters extends BaseRegionCountryFilters {}
|
||||
|
||||
@@ -16,13 +16,3 @@ export interface CreateOrderShipmentWorkflowInput {
|
||||
no_notification?: boolean
|
||||
metadata?: MetadataType
|
||||
}
|
||||
|
||||
interface CreateOrderDeliveryItem {
|
||||
id: string
|
||||
quantity: BigNumberInput
|
||||
}
|
||||
|
||||
export interface CreateOrderDeliveryWorkflowInput {
|
||||
order_id: string
|
||||
fulfillment_id: string
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src"],
|
||||
"exclude": [
|
||||
"dist",
|
||||
"src/**/__tests__",
|
||||
"src/**/__mocks__",
|
||||
"src/**/__fixtures__",
|
||||
"node_modules"
|
||||
],
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"noUnusedLocals": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"sourceMap": true,
|
||||
"noImplicitReturns": true,
|
||||
"strictNullChecks": true,
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src", "integration-tests"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"compilerOptions": {
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user