Skip to content

Commit

Permalink
#65: add versions to common helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
mohit-s96 committed May 13, 2024
1 parent 4ec4b10 commit d10fdfe
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 };
Expand Down Expand Up @@ -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')
Expand All @@ -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;
Expand Down

0 comments on commit d10fdfe

Please sign in to comment.