task-h.5.3
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
PDFME_STATIC_LABEL_FIELD_KEYS,
|
||||
createSqlClient,
|
||||
extractTemplateFields,
|
||||
getActiveTemplateVersions,
|
||||
@@ -40,6 +41,17 @@ async function main() {
|
||||
const mappedKeys = getEffectiveMappedKeys(fields, mappings);
|
||||
const fieldNames = new Set(fields.map((field) => field.name).filter(Boolean));
|
||||
const schemaTokens = [...new Set(fields.flatMap((field) => field.tokens))].sort();
|
||||
const tableFieldCoverage = fields
|
||||
.filter((field) => field.type === 'table' && field.name)
|
||||
.map((field) => {
|
||||
const mapping = mappings.find((candidate) => candidate.placeholderKey === field.name) ?? null;
|
||||
return {
|
||||
fieldName: field.name,
|
||||
hasMapping: Boolean(mapping),
|
||||
sourcePath: mapping?.sourcePath ?? null,
|
||||
dataType: mapping?.dataType ?? null
|
||||
};
|
||||
});
|
||||
const coverage = schemaTokens.map((token) => {
|
||||
const mapping =
|
||||
mappings.find((candidate) => candidate.placeholderKey === token) ??
|
||||
@@ -61,17 +73,31 @@ async function main() {
|
||||
};
|
||||
});
|
||||
const unmappedFields = coverage.filter((item) => item.classification === 'unmapped_field');
|
||||
const invalidTableMappings = tableFieldCoverage.filter(
|
||||
(item) =>
|
||||
item.fieldName === 'quotation_price_data' &&
|
||||
(!item.hasMapping ||
|
||||
item.sourcePath !== 'pdfme.quotation_price_data' ||
|
||||
item.dataType !== 'table')
|
||||
);
|
||||
const orphanMappings = mappings
|
||||
.filter(
|
||||
(mapping) =>
|
||||
!schemaTokens.includes(mapping.placeholderKey) &&
|
||||
!fieldNames.has(mapping.placeholderKey) &&
|
||||
mapping.placeholderKey !== 'items_table'
|
||||
mapping.placeholderKey !== 'items_table'
|
||||
)
|
||||
.map((mapping) => ({
|
||||
placeholderKey: mapping.placeholderKey,
|
||||
sourcePath: mapping.sourcePath
|
||||
}));
|
||||
const missingStaticLabelMappings = [...PDFME_STATIC_LABEL_FIELD_KEYS].filter((fieldName) => {
|
||||
if (!fieldNames.has(fieldName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !mappings.some((mapping) => mapping.placeholderKey === fieldName);
|
||||
});
|
||||
const tableMapping = mappings.find((mapping) => mapping.placeholderKey === 'items_table') ?? null;
|
||||
const tableColumns = tableMapping
|
||||
? columns
|
||||
@@ -83,6 +109,8 @@ async function main() {
|
||||
: [];
|
||||
const status = summarizeIssues([
|
||||
unmappedFields.length ? 'FAIL' : 'PASS',
|
||||
invalidTableMappings.length ? 'FAIL' : 'PASS',
|
||||
missingStaticLabelMappings.length ? 'FAIL' : 'PASS',
|
||||
orphanMappings.length ? 'WARNING' : 'PASS'
|
||||
]);
|
||||
|
||||
@@ -92,7 +120,9 @@ async function main() {
|
||||
organizationId: template.organizationId,
|
||||
tokenCount: schemaTokens.length,
|
||||
coverage,
|
||||
tableFieldCoverage,
|
||||
unmappedFields,
|
||||
missingStaticLabelMappings,
|
||||
orphanMappings,
|
||||
tableColumns,
|
||||
status
|
||||
|
||||
Reference in New Issue
Block a user