( value: unknown, options: CompactExecutionPayloadOptions, state: CompactState, depth = 0 )
| 66 | } |
| 67 | |
| 68 | async function compactValue( |
| 69 | value: unknown, |
| 70 | options: CompactExecutionPayloadOptions, |
| 71 | state: CompactState, |
| 72 | depth = 0 |
| 73 | ): Promise<unknown> { |
| 74 | if (!value || typeof value !== 'object') { |
| 75 | const measured = getJsonAndSize(value) |
| 76 | if (measured && measured.size > (options.thresholdBytes ?? LARGE_VALUE_THRESHOLD_BYTES)) { |
| 77 | if (options.rejectLargeValues) { |
| 78 | throw largeValueLimitError(options, measured.size) |
| 79 | } |
| 80 | return options.preserveRoot && depth === 0 |
| 81 | ? value |
| 82 | : storeLargeValue(value, measured.json, measured.size, options) |
| 83 | } |
| 84 | return value |
| 85 | } |
| 86 | |
| 87 | if (isLargeValueRef(value)) { |
| 88 | return value |
| 89 | } |
| 90 | |
| 91 | if (isLargeArrayManifest(value)) { |
| 92 | const measured = getJsonAndSize(value) |
| 93 | if (measured && measured.size > (options.thresholdBytes ?? LARGE_VALUE_THRESHOLD_BYTES)) { |
| 94 | if (options.rejectLargeValues) { |
| 95 | throw largeValueLimitError(options, measured.size) |
| 96 | } |
| 97 | return storeLargeValue(value, measured.json, measured.size, options) |
| 98 | } |
| 99 | return value |
| 100 | } |
| 101 | |
| 102 | if (isUserFileWithMetadata(value) && !options.preserveUserFileBase64) { |
| 103 | return stripUserFileBase64(value) |
| 104 | } |
| 105 | |
| 106 | if (state.seen.has(value)) { |
| 107 | return value |
| 108 | } |
| 109 | state.seen.add(value) |
| 110 | |
| 111 | const compacted = await compactEntries(value, options, state, depth) |
| 112 | |
| 113 | const measured = getJsonAndSize(compacted) |
| 114 | if (measured && measured.size > (options.thresholdBytes ?? LARGE_VALUE_THRESHOLD_BYTES)) { |
| 115 | if (options.rejectLargeValues) { |
| 116 | throw largeValueLimitError(options, measured.size) |
| 117 | } |
| 118 | |
| 119 | if (Array.isArray(compacted) && (canPersistDurably(options) || options.requireDurable)) { |
| 120 | return createLargeArrayManifest(compacted, { ...options, requireDurable: true }) |
| 121 | } |
| 122 | |
| 123 | if (options.preserveRoot && depth === 0) { |
| 124 | return compacted |
| 125 | } |
no test coverage detected