@@ -256,45 +256,45 @@ export function createProfileChunkPayload(
256256 * - Presence of samples, stacks, frames
257257 * - Required metadata fields
258258 */
259- export function validateProfileChunk ( chunk : ProfileChunk ) : { valid : boolean ; reason ? : string } {
259+ export function validateProfileChunk ( chunk : ProfileChunk ) : { valid : true } | { reason : string } {
260260 try {
261261 // Required metadata
262262 if ( ! chunk || typeof chunk !== 'object' ) {
263- return { valid : false , reason : 'chunk is not an object' } ;
263+ return { reason : 'chunk is not an object' } ;
264264 }
265265
266266 // profiler_id and chunk_id must be 32 lowercase hex chars
267267 const isHex32 = ( val : unknown ) : boolean => typeof val === 'string' && / ^ [ a - f 0 - 9 ] { 32 } $ / . test ( val ) ;
268268 if ( ! isHex32 ( chunk . profiler_id ) ) {
269- return { valid : false , reason : 'missing or invalid profiler_id' } ;
269+ return { reason : 'missing or invalid profiler_id' } ;
270270 }
271271 if ( ! isHex32 ( chunk . chunk_id ) ) {
272- return { valid : false , reason : 'missing or invalid chunk_id' } ;
272+ return { reason : 'missing or invalid chunk_id' } ;
273273 }
274274
275275 if ( ! chunk . client_sdk ) {
276- return { valid : false , reason : 'missing client_sdk metadata' } ;
276+ return { reason : 'missing client_sdk metadata' } ;
277277 }
278278
279279 // Profile data must have frames, stacks, samples
280280 const profile = chunk . profile as { frames ?: unknown [ ] ; stacks ?: unknown [ ] ; samples ?: unknown [ ] } | undefined ;
281281 if ( ! profile ) {
282- return { valid : false , reason : 'missing profile data' } ;
282+ return { reason : 'missing profile data' } ;
283283 }
284284
285285 if ( ! Array . isArray ( profile . frames ) || ! profile . frames . length ) {
286- return { valid : false , reason : 'profile has no frames' } ;
286+ return { reason : 'profile has no frames' } ;
287287 }
288288 if ( ! Array . isArray ( profile . stacks ) || ! profile . stacks . length ) {
289- return { valid : false , reason : 'profile has no stacks' } ;
289+ return { reason : 'profile has no stacks' } ;
290290 }
291291 if ( ! Array . isArray ( profile . samples ) || ! profile . samples . length ) {
292- return { valid : false , reason : 'profile has no samples' } ;
292+ return { reason : 'profile has no samples' } ;
293293 }
294294
295295 return { valid : true } ;
296296 } catch ( e ) {
297- return { valid : false , reason : `unknown validation error: ${ e } ` } ;
297+ return { reason : `unknown validation error: ${ e } ` } ;
298298 }
299299}
300300
0 commit comments