chore(workflows-sdk, utils): Prevent unnecessary serialization (#13413)
* chore(workflows-sdk, utils): Prevent unnecessary serialization * Create poor-mugs-cheat.md
This commit is contained in:
1 parent
bd571aca82
commit
55a35e4721
5 files changed
+31
-11
No files matched your search
@@ -58,6 +58,7 @@ export * from "./object-to-string-path"
|
||||
export * from "./omit-deep"
|
||||
export * from "./optional-numeric-serializer"
|
||||
export * from "./parse-cors-origins"
|
||||
export * from "./parse-stringify-if-necessary"
|
||||
export * from "./partition-array"
|
||||
export * from "./pick-deep"
|
||||
export * from "./pick-value-from-object"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { isDefined } from "./is-defined"
|
||||
|
||||
/**
|
||||
* Only apply JSON.parse JSON.stringify when we have objects, arrays, dates, etc..
|
||||
* @param result
|
||||
* @returns
|
||||
*/
|
||||
export function parseStringifyIfNecessary(result: unknown) {
|
||||
if (typeof result !== "object") {
|
||||
return result
|
||||
}
|
||||
|
||||
const strResult = JSON.stringify(result)
|
||||
if (isDefined(strResult)) {
|
||||
return JSON.parse(strResult)
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
deepCopy,
|
||||
isDefined,
|
||||
OrchestrationUtils,
|
||||
parseStringifyIfNecessary,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
@@ -83,8 +83,5 @@ export async function resolveValue(input, transactionContext) {
|
||||
? await resolveProperty(copiedInput, transactionContext)
|
||||
: await unwrapInput(copiedInput, {})
|
||||
|
||||
const strResult = JSON.stringify(result) // Symbols return undefined
|
||||
if (isDefined(strResult)) {
|
||||
return JSON.parse(strResult)
|
||||
}
|
||||
return parseStringifyIfNecessary(result)
|
||||
}
|
||||
Reference in new issue
Block a user