Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#44: Add expansions to advertised counts #45

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -177,39 +180,66 @@ 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 =>
idxLookup.lookupName === lookup.lookupName &&
(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++;
}
}
}
Expand Down
Loading