@@ -52,7 +52,7 @@ function getDateRangeValue(
5252}
5353
5454/**
55- * Parse blending query key from time time dimension.
55+ * Parse blending query key from time dimension granularity .
5656 * @internal
5757 */
5858function getBlendingQueryKey (
@@ -77,7 +77,7 @@ function getBlendingQueryKey(
7777}
7878
7979/**
80- * Parse blending response key from time time dimension.
80+ * Parse blending response key from time dimension and granularity .
8181 * @internal
8282 */
8383function getBlendingResponseKey (
@@ -219,80 +219,64 @@ function getCompactRow(
219219
220220/**
221221 * Convert DB response object to the vanilla output format.
222- * @todo rewrite me please!
223222 * @internal
224223 */
225- function getVanilaRow (
224+ function getVanillaRow (
226225 aliasToMemberNameMap : AliasToMemberMap ,
227226 annotation : { [ member : string ] : ConfigItem } ,
228227 queryType : QueryType ,
229228 query : NormalizedQuery ,
230229 dbRow : { [ sqlAlias : string ] : DBResponseValue } ,
231230) : { [ member : string ] : DBResponsePrimitive } {
232- const row = R . pipe (
233- R . toPairs ,
234- R . map ( p => {
235- const memberName = aliasToMemberNameMap [ p [ 0 ] ] ;
231+ const row = Object
232+ . entries ( dbRow )
233+ . reduce ( ( acc , [ sqlAlias , value ] ) => {
234+ const memberName = aliasToMemberNameMap [ sqlAlias ] ;
236235 const annotationForMember = annotation [ memberName ] ;
236+
237237 if ( ! annotationForMember ) {
238238 throw new UserError (
239- `You requested hidden member: '${
240- p [ 0 ]
241- } '. Please make it visible using \`shown: true\`. ` +
242- 'Please note primaryKey fields are `shown: false` by ' +
243- 'default: https://cube.dev/docs/schema/reference/joins#' +
244- 'setting-a-primary-key.'
239+ `You requested hidden member: '${ sqlAlias } '. ` +
240+ 'Please make it visible using `shown: true`. ' +
241+ 'Please note primaryKey fields are `shown: false` by default: ' +
242+ 'https://cube.dev/docs/schema/reference/joins#setting-a-primary-key.'
245243 ) ;
246244 }
247- const transformResult = [
248- memberName ,
249- transformValue (
250- p [ 1 ] as DBResponseValue ,
251- annotationForMember . type
252- )
253- ] ;
245+
246+ const transformedValue = transformValue ( value as DBResponseValue , annotationForMember . type ) ;
254247 const path = memberName . split ( MEMBER_SEPARATOR ) ;
255248
249+ acc [ memberName ] = transformedValue ;
250+
256251 /**
257- * Time dimensions without granularity.
252+ * Handle time dimensions without granularity
258253 * @deprecated
259254 * @todo backward compatibility for referencing
260255 */
261- const memberNameWithoutGranularity =
262- [ path [ 0 ] , path [ 1 ] ] . join ( MEMBER_SEPARATOR ) ;
263- if (
264- path . length === 3 &&
265- ( query . dimensions || [ ] )
266- . indexOf ( memberNameWithoutGranularity ) === - 1
267- ) {
268- return [
269- transformResult ,
270- [
271- memberNameWithoutGranularity ,
272- transformResult [ 1 ]
273- ]
274- ] ;
256+ const memberNameWithoutGranularity = [ path [ 0 ] , path [ 1 ] ] . join ( MEMBER_SEPARATOR ) ;
257+ if ( path . length === 3 &&
258+ ( query . dimensions || [ ] ) . indexOf ( memberNameWithoutGranularity ) === - 1 ) {
259+ acc [ memberNameWithoutGranularity ] = transformedValue ;
275260 }
276261
277- return [ transformResult ] ;
278- } ) ,
279- // @ts -ignore
280- R . unnest ,
281- R . fromPairs
282- // @ts -ignore
283- ) ( dbRow ) ;
262+ return acc ;
263+ } , { } as { [ member : string ] : DBResponsePrimitive } ) ;
264+
284265 if ( queryType === QueryTypeEnum . COMPARE_DATE_RANGE_QUERY ) {
285266 return {
286267 ...row ,
287268 compareDateRange : getDateRangeValue ( query . timeDimensions )
288269 } ;
289- } else if ( queryType === QueryTypeEnum . BLENDING_QUERY ) {
270+ }
271+
272+ if ( queryType === QueryTypeEnum . BLENDING_QUERY ) {
290273 return {
291274 ...row ,
292275 [ getBlendingQueryKey ( query . timeDimensions ) ] :
293276 row [ getBlendingResponseKey ( query . timeDimensions ) ]
294277 } ;
295278 }
279+
296280 return row as { [ member : string ] : DBResponsePrimitive ; } ;
297281}
298282
@@ -337,7 +321,7 @@ function transformData({
337321 query . timeDimensions ,
338322 r ,
339323 )
340- : getVanilaRow (
324+ : getVanillaRow (
341325 aliasToMemberNameMap ,
342326 annotation ,
343327 queryType ,
@@ -371,7 +355,7 @@ export {
371355 getBlendingResponseKey ,
372356 getMembers ,
373357 getCompactRow ,
374- getVanilaRow ,
358+ getVanillaRow ,
375359 transformData ,
376360 transformValue ,
377361} ;
0 commit comments