@@ -7,13 +7,13 @@ export function csvCellContentFormatter(str: string): string {
|
||||
return str
|
||||
}
|
||||
|
||||
const formatterStr = str.replace(doubleQuoteRegexp, '""')
|
||||
const formatterStr = str.replace(doubleQuoteRegexp, `""`)
|
||||
|
||||
return `"${formatterStr}"`
|
||||
}
|
||||
|
||||
export function csvRevertCellContentFormatter(str: string): string {
|
||||
if (str.startsWith('"')) {
|
||||
if (str.startsWith(`"`)) {
|
||||
str = str.substring(1, str.length - 1)
|
||||
}
|
||||
return str
|
||||
|
||||
@@ -8,4 +8,4 @@ export const isPast = (date: Date | null) => {
|
||||
export const isFuture = (date: Date | null) => {
|
||||
const now = new Date()
|
||||
return isDate(date) && date > now
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ export const formatException = (err): Error => {
|
||||
MedusaError.Types.DUPLICATE_ERROR,
|
||||
`${err.table.charAt(0).toUpperCase()}${err.table.slice(
|
||||
1
|
||||
)} with ${err.detail
|
||||
.slice(4)
|
||||
.replace(/[()=]/g, (s) => (s === "=" ? " " : ""))}`
|
||||
)} with ${err.detail.slice(4).replace(/[()=]/g, (s) => {
|
||||
return s === "=" ? " " : ""
|
||||
})}`
|
||||
)
|
||||
case PostgresError.FOREIGN_KEY_ERROR: {
|
||||
const matches =
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Column, ColumnOptions, Entity, EntityOptions } from "typeorm"
|
||||
import { featureFlagRouter } from "../loaders/feature-flags"
|
||||
|
||||
/**
|
||||
* If that file is required in a non node environment then the setImmediate timer does not exists.
|
||||
* This can happen when a client package require a server based package and that one of the import
|
||||
* require to import that file which is using the setImmediate.
|
||||
* In order to take care of those cases, the setImmediate timer will use the one provided by the api (node)
|
||||
* if possible and will provide a mock in a browser like environment.
|
||||
*/
|
||||
/**
|
||||
* If that file is required in a non node environment then the setImmediate timer does not exists.
|
||||
* This can happen when a client package require a server based package and that one of the import
|
||||
* require to import that file which is using the setImmediate.
|
||||
* In order to take care of those cases, the setImmediate timer will use the one provided by the api (node)
|
||||
* if possible and will provide a mock in a browser like environment.
|
||||
*/
|
||||
let setImmediate_
|
||||
try {
|
||||
setImmediate_ = setImmediate
|
||||
@@ -15,7 +15,7 @@ try {
|
||||
console.warn(
|
||||
"[feature-flag-decorator.ts] setImmediate will use a mock, this happen when this file is required in a browser environment and should not impact you"
|
||||
)
|
||||
setImmediate_ = ((callback: () => void | Promise<void>) => callback())
|
||||
setImmediate_ = (callback: () => void | Promise<void>) => callback()
|
||||
}
|
||||
|
||||
export function FeatureFlagColumn(
|
||||
|
||||
@@ -11,6 +11,6 @@ export function generateEntityId(idProperty: string, prefix?: string): string {
|
||||
}
|
||||
|
||||
const id = ulid()
|
||||
prefix = prefix ? `${prefix}_` : ''
|
||||
prefix = prefix ? `${prefix}_` : ""
|
||||
return `${prefix}${id}`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ export function getRetrieveConfig<TModel extends BaseEntity>(
|
||||
): FindConfig<TModel> {
|
||||
let includeFields: (keyof TModel)[] = []
|
||||
if (isDefined(fields)) {
|
||||
includeFields = Array.from(new Set([...fields, "id"])).map((field) =>
|
||||
typeof field === "string" ? field.trim() : field
|
||||
) as (keyof TModel)[]
|
||||
includeFields = Array.from(new Set([...fields, "id"])).map((field) => {
|
||||
return typeof field === "string" ? field.trim() : field
|
||||
}) as (keyof TModel)[]
|
||||
}
|
||||
|
||||
let expandFields: string[] = []
|
||||
|
||||
@@ -6,3 +6,4 @@ export * from "./remove-undefined-properties"
|
||||
export * from "./is-defined"
|
||||
export * from "./calculate-price-tax-amount"
|
||||
export * from "./csv-cell-content-formatter"
|
||||
export * from "./exception-formatter"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
export function isDefined<T = undefined | unknown>(val: T): val is (T extends undefined ? never : T) {
|
||||
export function isDefined<T = undefined | unknown>(
|
||||
val: T
|
||||
): val is T extends undefined ? never : T {
|
||||
return typeof val !== "undefined"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isDefined } from "./is-defined";
|
||||
import { isDefined } from "./is-defined"
|
||||
|
||||
export function removeUndefinedProperties<T extends object>(inputObj: T): T {
|
||||
const removeProperties = (obj: T) => {
|
||||
@@ -23,21 +23,26 @@ function removeUndefinedDeeply(input: unknown): any {
|
||||
if (input === null || input === "null") {
|
||||
return null
|
||||
} else if (Array.isArray(input)) {
|
||||
return input.map((item) => {
|
||||
return removeUndefinedDeeply(item)
|
||||
}).filter(v => isDefined(v))
|
||||
} else if (Object.prototype.toString.call(input) === '[object Date]') {
|
||||
return input
|
||||
.map((item) => {
|
||||
return removeUndefinedDeeply(item)
|
||||
})
|
||||
.filter((v) => isDefined(v))
|
||||
} else if (Object.prototype.toString.call(input) === "[object Date]") {
|
||||
return input
|
||||
} else if (typeof input === "object") {
|
||||
return Object.keys(input).reduce((acc: Record<string, unknown>, key: string) => {
|
||||
if (typeof input[key] === "undefined") {
|
||||
return acc
|
||||
}
|
||||
acc[key] = removeUndefinedDeeply(input[key])
|
||||
return acc
|
||||
}, {})
|
||||
return Object.keys(input).reduce(
|
||||
(acc: Record<string, unknown>, key: string) => {
|
||||
if (typeof input[key] === "undefined") {
|
||||
return acc
|
||||
}
|
||||
acc[key] = removeUndefinedDeeply(input[key])
|
||||
return acc
|
||||
},
|
||||
{}
|
||||
)
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* Confirms whether a given raw id is valid. Fails if the provided
|
||||
* id is null or undefined. The validate function takes an optional config
|
||||
* param, to support checking id prefix and length.
|
||||
* @param rawId - the id to validate.
|
||||
* @param config - optional config
|
||||
* @returns the rawId given that nothing failed
|
||||
*/
|
||||
* Confirms whether a given raw id is valid. Fails if the provided
|
||||
* id is null or undefined. The validate function takes an optional config
|
||||
* param, to support checking id prefix and length.
|
||||
* @param rawId - the id to validate.
|
||||
* @param config - optional config
|
||||
* @returns the rawId given that nothing failed
|
||||
*/
|
||||
import { MedusaError } from "medusa-core-utils/dist"
|
||||
|
||||
export function validateId(
|
||||
@@ -38,4 +38,4 @@ export function validateId(
|
||||
}
|
||||
|
||||
return rawId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
export const transformDate = ({ value }): Date =>
|
||||
!isNaN(Date.parse(value)) ? new Date(value) : new Date(Number(value) * 1000)
|
||||
export const transformDate = ({ value }): Date => {
|
||||
return !isNaN(Date.parse(value))
|
||||
? new Date(value)
|
||||
: new Date(Number(value) * 1000)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,6 @@ async function typeValidator(
|
||||
}
|
||||
|
||||
export function IsType(types: any[], validationOptions?: ValidationOptions) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
return function (object: Object, propertyName: string): void {
|
||||
registerDecorator({
|
||||
name: "IsType",
|
||||
|
||||
Reference in New Issue
Block a user