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

#65: Update helper methods with version #66

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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 }) => {
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
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);
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
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);
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
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
13 changes: 6 additions & 7 deletions lib/process-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const {
getMetadata,
getStandardMetadata,
} = require('./common');
const standardMetadata = getStandardMetadata();
const CURRENT_REFERENCE_METADATA_REPORT_JSON = getMetadata();

const ANNOTATION_TERM_STANDARD_NAME = 'RESO.OData.Metadata.StandardName';

Expand All @@ -22,31 +20,32 @@ const processMetadataReport = (
metadataReportJson
) => {
const { fields, lookups, ...reportInfo } = metadataReportJson;
const standardMetadata = getStandardMetadata(reportInfo.version);

const referenceLookups = lookups?.filter(
(x) => !isReferencePlaceholderValue(x)
);

const transformedMetadataReportJson = {
...reportInfo,
fields: getTransformedFields(fields),
fields: getTransformedFields(fields, standardMetadata),
lookups: getTransformedLookups(metadataReportJson),
};

return {
...transformedMetadataReportJson,
...getFieldsCount(fields),
...getFieldsCount(fields, reportInfo.version),
...getResourcesCount(fields),
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
...getLookupsCount(transformedMetadataReportJson.lookups),
mohit-s96 marked this conversation as resolved.
Show resolved Hide resolved
...getIdxCounts(fields, referenceLookups),
...getIdxCounts(fields, referenceLookups, reportInfo.version),
advertised: getAdvertisedCountPerResourcesByType(
transformedMetadataReportJson
),
};
};

//TODO: convert to use a map instead
const getTransformedFields = (fields = []) => {
const getTransformedFields = (fields = [], standardMetadata = { fields: [] }) => {
return fields.map((field) => {
return {
...field,
Expand Down Expand Up @@ -216,7 +215,7 @@ const isReferencePlaceholderValue = ({ lookupValue = '' }) =>
const getTransformedLookups = (metadataReportJson = {}) => {
if (!metadataReportJson?.lookups) return [];

const referenceMetadataJson = CURRENT_REFERENCE_METADATA_REPORT_JSON;
const referenceMetadataJson = getMetadata(metadataReportJson.version);
const referenceFieldMap = buildFieldMap(referenceMetadataJson);

//remove placeholder values added to the reference metadata for open enumerations without values
Expand Down
Loading