lib/adapter/serialize.js
// Traverse data and await values from all promises
Traverse data and await values from all promises
Traverse data and await values from all promises
async function unpromise(data) {
  if (typeof data !== 'object' || data === null || data instanceof Date) {
    return data
  } else if (typeof data.then === 'function') {
    try {
      return await data 
    } catch (err) {
      return undefined 
    }
  } else if (Array.isArray(data)) {
    const ret = []
    for (const value of data) {
      ret.push(await unpromise(value))
    }
    return ret
  } else {
    const ret = {}
    for (const key in data) {
      ret[key] = await unpromise(data[key])
    }
    return ret
  }
}
async function unpromise ( data ) { if ( typeof data !== 'object' || data === null || data instanceof Date ) { return data } else if ( typeof data . then === 'function' ) { try { return await data } catch ( err ) { return undefined } } else if ( Array . isArray ( data ) ) { const ret = [ ] for ( const value of data ) { ret . push ( await unpromise ( value ) ) } return ret } else { const ret = { } for ( const key in data ) { ret [ key ] = await unpromise ( data [ key ] ) } return ret } }
Traverse data and await values from all promises
Traverse data and await values from all promises
// Await promise // Disregard rejects