MCPcopy
hub / github.com/prisma/prisma / deepCloneValue

Function deepCloneValue

packages/client/src/runtime/utils/deepCloneArgs.ts:46–90  ·  view source on GitHub ↗
(x: JsInputValue)

Source from the content-addressed store, hash-verified

44
45// based on https://github.com/lukeed/klona/blob/v2.0.6/src/index.js
46function deepCloneValue(x: JsInputValue): JsInputValue {
47 if (typeof x !== 'object' || x == null || isObjectEnumValue(x) || isFieldRef(x) || isSkip(x)) {
48 return x
49 }
50
51 if (isDecimalJsLike(x)) {
52 return new Decimal(x.toFixed())
53 }
54
55 if (isDate(x)) {
56 return new Date(+x)
57 }
58
59 if (ArrayBuffer.isView(x)) {
60 return x.slice(0)
61 }
62
63 if (Array.isArray(x)) {
64 let k = x.length
65 let copy
66 for (copy = Array(k); k--; ) {
67 copy[k] = deepCloneValue(x[k])
68 }
69 return copy
70 }
71
72 if (typeof x === 'object') {
73 const copy = {}
74 for (const k in x) {
75 if (k === '__proto__') {
76 Object.defineProperty(copy, k, {
77 value: deepCloneValue(x[k]),
78 configurable: true,
79 enumerable: true,
80 writable: true,
81 })
82 } else {
83 copy[k] = deepCloneValue(x[k])
84 }
85 }
86 return copy
87 }
88
89 assertNever(x, 'Unknown value')
90}

Callers 1

deepCloneArgsFunction · 0.85

Calls 8

isObjectEnumValueFunction · 0.90
isFieldRefFunction · 0.90
isSkipFunction · 0.90
isDecimalJsLikeFunction · 0.90
isDateFunction · 0.90
assertNeverFunction · 0.90
toFixedMethod · 0.80
sliceMethod · 0.45

Tested by

no test coverage detected