From c00abe993ec1b736a796731675cd33f13e7a5a7b Mon Sep 17 00:00:00 2001 From: Mohit Srivastava Date: Thu, 14 Dec 2023 20:51:08 +0530 Subject: [PATCH] #44: updated the process for calculating advertised counts to include expansions (#45) --- lib/common.js | 52 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/lib/common.js b/lib/common.js index dcc15ed..0731697 100644 --- a/lib/common.js +++ b/lib/common.js @@ -3,6 +3,9 @@ const fs = require('fs/promises'); const CURRENT_DD_VERSION = '1.7'; const STANDARD_NAME_ANNOTATION_TERM = 'RESO.OData.Metadata.StandardName'; const DD_WIKI_URL_TERM = 'RESO.DDWikiUrl'; +const FIELDS = 'fields'; +const LOOKUPS = 'lookups'; +const EXPANSIONS = 'expansions'; const buildAnnotationMap = (annotations = []) => annotations.reduce((acc, { term, value }) => { @@ -177,28 +180,55 @@ const getAdvertisedCountPerResourcesByType = ({ fields, lookups }) => { const idxLookups = getIdxLookups(fields, lookups); for (const [key, value] of Object.entries(reducedFields)) { advertisedCount[key] = { fields: {}, lookups: {} }; - advertisedCount[key]['fields'] = { total: 0, reso: 0, idx: 0, local: 0 }; - advertisedCount[key]['lookups'] = { total: 0, reso: 0, idx: 0, local: 0 }; + advertisedCount[key][FIELDS] = { total: 0, reso: 0, idx: 0, local: 0 }; + advertisedCount[key][LOOKUPS] = { total: 0, reso: 0, idx: 0, local: 0 }; + const lookupsCollection = []; for (const field of value) { - advertisedCount[key]['fields'].total++; + if (field.isExpansion) { + if (!advertisedCount[key]?.expansions) { + advertisedCount[key][EXPANSIONS] = {}; + } + if (!advertisedCount[key]?.expansions?.[field.typeName]) { + advertisedCount[key][EXPANSIONS][field.typeName] = {}; + } + if (!advertisedCount[key]?.expansions?.[field.typeName]?.[FIELDS]) { + advertisedCount[key].expansions[field.typeName][FIELDS] = { total: 0, reso: 0, idx: 0, local: 0 }; + } + if (!advertisedCount[key]?.expansions?.[field.typeName]?.[LOOKUPS]) { + advertisedCount[key].expansions[field.typeName][LOOKUPS] = { total: 0, reso: 0, idx: 0, local: 0 }; + } + } + const advertisedField = field.isExpansion ? advertisedCount[key].expansions[field.typeName][FIELDS] : advertisedCount[key][FIELDS]; + advertisedField.total++; if (field.standardRESO) { - advertisedCount[key]['fields'].reso++; + advertisedField.reso++; if (field?.payloads?.includes('IDX')) { - advertisedCount[key]['fields'].idx++; + advertisedField.idx++; } } else { - advertisedCount[key]['fields'].local++; + advertisedField.local++; } //collect lookup on single pass if (!field?.type.startsWith('Edm.')) { - lookupsCollection.push(...lookups.filter(lookup => lookup.lookupName === field.type)); + if (field.isExpansion) { + lookupsCollection.push( + ...lookups + .filter(lookup => lookup.lookupName === field.type) + .map(l => ({ ...l, isExpansion: true, resourceName: field.typeName })) + ); + } else { + lookupsCollection.push(...lookups.filter(lookup => lookup.lookupName === field.type)); + } } } for (const lookup of lookupsCollection) { - advertisedCount[key]['lookups'].total++; + const advertisedLookup = lookup.isExpansion + ? advertisedCount[key].expansions[lookup.resourceName][LOOKUPS] + : advertisedCount[key][LOOKUPS]; + advertisedLookup.total++; if (lookup.standardRESO) { - advertisedCount[key]['lookups'].reso++; + advertisedLookup.reso++; if ( idxLookups.some( idxLookup => @@ -206,10 +236,10 @@ const getAdvertisedCountPerResourcesByType = ({ fields, lookups }) => { (idxLookup.lookupValue === lookup.lookupValue || idxLookup?.annotations?.[0]?.value === lookup?.annotations?.[0]?.value) ) ) { - advertisedCount[key]['lookups'].idx++; + advertisedLookup.idx++; } } else { - advertisedCount[key]['lookups'].local++; + advertisedLookup.local++; } } }