From d10fdfe84f422dd1c5fe96e59cfa15972b2b3911 Mon Sep 17 00:00:00 2001 From: mohit-s96 Date: Mon, 13 May 2024 20:45:30 +0530 Subject: [PATCH] #65: add versions to common helpers --- lib/common.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/common.js b/lib/common.js index 0731697..3fc9142 100644 --- a/lib/common.js +++ b/lib/common.js @@ -138,12 +138,12 @@ const getStandardResources = version => { return resources; }; -const getFieldDetails = async (fieldName, resourceName) => { - return getStandardMetadata().fields.find(field => field?.fieldName === fieldName && field?.resourceName === resourceName); +const getFieldDetails = async (fieldName, resourceName, version = CURRENT_DD_VERSION) => { + return getStandardMetadata(version).fields.find(field => field?.fieldName === fieldName && field?.resourceName === resourceName); }; -const getIdxLookups = (fields, lookups) => { - const standardMetadata = getStandardMetadata(); +const getIdxLookups = (fields, lookups, version = CURRENT_DD_VERSION) => { + const standardMetadata = getStandardMetadata(version); const iDXDataTypes = ['String List, Multi', 'String List,Multi', 'String List, Single', 'String List,Single']; const iDXLookupFields = fields.filter(field => standardMetadata.fields.some( @@ -170,14 +170,14 @@ const getIdxLookups = (fields, lookups) => { const getLastPart = (str, char) => str.substr(str.lastIndexOf(char) + 1); -const getAdvertisedCountPerResourcesByType = ({ fields, lookups }) => { +const getAdvertisedCountPerResourcesByType = ({ fields, lookups, version }) => { const reducedFields = fields.reduce(function (r, a) { r[a.resourceName] = r[a.resourceName] || []; r[a.resourceName].push(a); return r; }, Object.create(null)); const advertisedCount = {}; - const idxLookups = getIdxLookups(fields, lookups); + const idxLookups = getIdxLookups(fields, lookups, version); for (const [key, value] of Object.entries(reducedFields)) { advertisedCount[key] = { fields: {}, lookups: {} }; advertisedCount[key][FIELDS] = { total: 0, reso: 0, idx: 0, local: 0 }; @@ -246,8 +246,8 @@ const getAdvertisedCountPerResourcesByType = ({ fields, lookups }) => { return advertisedCount; }; -const getIdxCounts = (fields, lookups) => { - const standardMetadata = getStandardMetadata(); +const getIdxCounts = (fields, lookups, version = CURRENT_DD_VERSION) => { + const standardMetadata = getStandardMetadata(version); const idxFields = fields.filter(field => standardMetadata.fields.some( x => x.resourceName === field.resourceName && x.fieldName === field.fieldName && x?.payloads?.includes('IDX') @@ -264,13 +264,13 @@ const getIdxCounts = (fields, lookups) => { /* iDXLookups lookups of unique IDX fields with any of types ["String List, Single", String List, Multi] */ - const iDXLookups = getIdxLookups(fields, lookups); + const iDXLookups = getIdxLookups(fields, lookups, version); const iDXLookupsCount = iDXLookups.length; return { iDXFieldsCount, iDXResourcesCount, iDXLookupsCount }; }; -const getFieldsCount = fields => { - const standardMetadata = getStandardMetadata(); +const getFieldsCount = (fields, version = CURRENT_DD_VERSION) => { + const standardMetadata = getStandardMetadata(version); const standardFieldsCount = fields.filter(field => standardMetadata.fields.some(x => x.resourceName === field.resourceName && x.fieldName === field.fieldName) ).length;