Setting the file. One moment.
Subchapter 38.1
lib/limit-recovery.js
JavaScript12 lines3 KB
'use strict';
const fs = require('node:fs/promises');
const path = require('node:path');
const crypto = require('node:crypto');
const STORES_PRODUCT_TAGS_MAX = 100;
const STORES_SKU_MAX = 40;
function truncate(value, limit, sourceId) { const chars = Array.from(String(value || '')); if (chars.length <= limit) return String(value || ''); const suffix = `-${crypto.createHash('sha256').update(
function normalizeProduct({ sourceId, sku, tagIds = [] }) { const recoveries = []; const uniqueTags = [...new Set(tagIds)].slice(0, STORES_PRODUCT_TAGS_MAX); if (tagIds.length > uniqueTags.length) recoveries.push({ code: 'stores_product_tag_count', field: 'tags.publicTags.tagIds', action: 'capped'
async function appendRecoveries(projectDir, adapter, sourceId, recoveries) { if (!recoveries.length) return; const file = path.join(projectDir, 'execution', 'quick-limit-recoveries.ndjson'); await fs.mkdir(path.dirname(file), { recursive: true }); await fs.appendFile(file, recoveries.
function recordRecoveredRecord(summary, recoveries) { if (!recoveries.length) return; summary.recovered = (summary.recovered || 0) + 1; summary.recoveryCounts ||= {}; for (const item of recoveries) summary.recoveryCounts[item.code] = (summary.recoveryCounts[item.code] || 0) + 1; }
async function writeFinalReport(projectDir, summary) { const file = path.join(projectDir, 'execution', 'quick-mode-final-report.md'); const rows = Object.entries(summary.recoveryCounts || {}).map(([code, count]) => `- ${code}: ${count}`).join('
module.exports = { STORES_PRODUCT_TAGS_MAX, STORES_SKU_MAX, truncate, normalizeProduct, appendRecoveries, recordRecoveredRecord, writeFinalReport };