formlab-mcp 0.7.14 → 0.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server.json +2 -2
- package/tools/lab.js +4 -2
- package/vendor/cost.js +62 -11
- package/vendor/nesting.js +4 -0
- package/vendor/nutrition-label.js +3 -2
- package/vendor/theoretical-params.js +11 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.15",
|
|
4
4
|
"mcpName": "io.github.juliu1980/formlab-mcp",
|
|
5
5
|
"description": "Read-only Model Context Protocol server for FormLab. Lets Claude and other MCP clients read and analyze your FormLab data, from a local export file or your live cloud workspace.",
|
|
6
6
|
"homepage": "https://formvix.com/mcp",
|
package/server.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.juliu1980/formlab-mcp",
|
|
4
4
|
"description": "Read-only MCP server for FormLab formulation data: a local export file or your live cloud workspace.",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.15",
|
|
6
6
|
"websiteUrl": "https://formvix.com/mcp",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "formlab-mcp",
|
|
11
|
-
"version": "0.7.
|
|
11
|
+
"version": "0.7.15",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
package/tools/lab.js
CHANGED
|
@@ -394,7 +394,7 @@ const list_batches = {
|
|
|
394
394
|
const get_batch = {
|
|
395
395
|
definition: {
|
|
396
396
|
name: 'get_batch',
|
|
397
|
-
description: 'Get full details for a single batch including the raw lots it drew (lotsUsed: lot number, quantity, and the status of each lot now, with holdReason for a lot on hold), hold (now) and holdHistory (every hold with its release: when, by whom, and the note, e.g. "Released with lot ETH-1"), certificates (each Certificate of Analysis as issued and saved: number, when, by whom, customer, PO, verdict, override reason, the results it printed; a shipment\'s coaNumber names the one it went with; a voided one has voided, voidedAt, voidedBy, voidReason, and the shipment coaVoided), its actual composition (as-prepared, when logged), child samples, lineage (parent / sub-blend parents), and — treating the batch as a finished-goods lot — its storage `location` and finished-goods `stockLedger` (shipments out + adjustments; on-hand = produced − sample pulls − sub-batch draws + Σ ledger). Plus finished-product density + actual volume (measured directly or derived as actual mass ÷ measured density — never summed from per-ingredient volumes). Accepts internal id or UID. Also returns `theoreticalParameters` computed on the batch as made (its actual composition when logged — `basis: "actual"` — else the recipe of its formula), with the batch parameter list when it overrides the one on the formula; same fields as get_formulation. `reactiveBalance` is the same as get_formulation\'s, on what was weighed (basis "as weighed"), e.g. a soap batch\'s superfat and lye excess.',
|
|
397
|
+
description: 'Get full details for a single batch including the raw lots it drew (lotsUsed: lot number, quantity, and the status of each lot now, with holdReason for a lot on hold), hold (now) and holdHistory (every hold with its release: when, by whom, and the note, e.g. "Released with lot ETH-1"), certificates (each Certificate of Analysis as issued and saved: number, when, by whom, customer, PO, verdict, override reason, the results it printed; a shipment\'s coaNumber names the one it went with; a voided one has voided, voidedAt, voidedBy, voidReason, and the shipment coaVoided; a shipment sent a corrected CoA lists the voided ones it replaced in coaReplaced), its actual composition (as-prepared, when logged), child samples, lineage (parent / sub-blend parents), and — treating the batch as a finished-goods lot — its storage `location` and finished-goods `stockLedger` (shipments out + adjustments; on-hand = produced − sample pulls − sub-batch draws + Σ ledger). Plus finished-product density + actual volume (measured directly or derived as actual mass ÷ measured density — never summed from per-ingredient volumes). Accepts internal id or UID. Also returns `theoreticalParameters` computed on the batch as made (its actual composition when logged — `basis: "actual"` — else the recipe of its formula), with the batch parameter list when it overrides the one on the formula; same fields as get_formulation. `reactiveBalance` is the same as get_formulation\'s, on what was weighed (basis "as weighed"), e.g. a soap batch\'s superfat and lye excess.',
|
|
398
398
|
inputSchema: {
|
|
399
399
|
type: 'object',
|
|
400
400
|
properties: {
|
|
@@ -444,7 +444,9 @@ const get_batch = {
|
|
|
444
444
|
...(Array.isArray(e.qcOpen) && e.qcOpen.length ? { shippedWithQcOpen: e.qcOpen, qcReason: e.qcReason || null } : {}),
|
|
445
445
|
// 2 Dec: the CoA it went with (null = none issued), and no ingredient lots recorded. Older shipments carry neither.
|
|
446
446
|
// 0.7.12: the saved certificate it went with (its number in certificates).
|
|
447
|
-
...(e.kind === 'shipment' && e.coaId ? (() => { const c = (Array.isArray(b.coas) ? b.coas : []).find(x => x && x.id === e.coaId) || {}; return { coaNumber: c.n ?? null, ...(c.voidedAt ? { coaVoided: true } : {})
|
|
447
|
+
...(e.kind === 'shipment' && e.coaId ? (() => { const c = (Array.isArray(b.coas) ? b.coas : []).find(x => x && x.id === e.coaId) || {}; return { coaNumber: c.n ?? null, ...(c.voidedAt ? { coaVoided: true } : {}),
|
|
448
|
+
// 0.7.15: the certificates this shipment's CoA replaced (voided ones), by number.
|
|
449
|
+
...(Array.isArray(e.coaReplaced) && e.coaReplaced.length ? { coaReplaced: e.coaReplaced.map(p => ((b.coas || []).find(x => x && x.id === p.id) || {}).n ?? null) } : {}) }; })() : {}),
|
|
448
450
|
...(e.kind === 'shipment' && 'coaAt' in e ? { coaIssuedAt: e.coaAt || null, ...(e.coaCustomer ? { coaCustomer: e.coaCustomer } : {}), ...(e.coaPo ? { coaPo: e.coaPo } : {}), noLotsRecorded: !!e.noLots } : {}),
|
|
449
451
|
})),
|
|
450
452
|
shippedQty: (Array.isArray(b.stockLedger) ? b.stockLedger : []).reduce((s, e) => e.kind === 'shipment' ? s + Math.abs(parseFloat(e.delta) || 0) : s, 0),
|
package/vendor/cost.js
CHANGED
|
@@ -873,6 +873,31 @@ function flProductUnits(f, batchKg, count) {
|
|
|
873
873
|
}
|
|
874
874
|
return 1;
|
|
875
875
|
}
|
|
876
|
+
// Parts Not mixed in that sit inside sub-formulas (a gift set of two candles: two wicks), for fKg of formula f: each
|
|
877
|
+
// sub-formula's share of f by mass, over the weight of one of its pieces, × its counted rows; and on down (12-04). f's
|
|
878
|
+
// own counted rows are the caller's (flCountedAside). → { draws: [{ ingredientId, pieces, row, sub }], unresolved:
|
|
879
|
+
// [{ formulationId, name }] } — unresolved: a sub-formula with counted parts but no weight for one piece (no fill).
|
|
880
|
+
function flNestedCounted(f, fKg, _depth, _out, _path) {
|
|
881
|
+
const out = _out || { draws: [], unresolved: [] };
|
|
882
|
+
const depth = _depth || 0, path = _path || [f && f.id];
|
|
883
|
+
if (!f || !(fKg > 0) || depth > 6 || typeof _rowWtFractionsWithin !== 'function') return out;
|
|
884
|
+
const comp = (Array.isArray(f.composition) ? f.composition : []).filter(c => c && (c.ingredientId || c.formulationId));
|
|
885
|
+
const fr = _rowWtFractionsWithin(f, []);
|
|
886
|
+
comp.forEach((c, i) => {
|
|
887
|
+
if (!c.formulationId || c.ingredientId || !(fr[i] > 0) || path.includes(c.formulationId)) return;
|
|
888
|
+
const sub = (typeof flFindById === 'function') ? flFindById('formulations', c.formulationId) : (db.formulations || []).find(x => x.id === c.formulationId);
|
|
889
|
+
if (!sub || sub.deleted) return;
|
|
890
|
+
const subKg = fKg * fr[i];
|
|
891
|
+
const aside = flCountedAside(sub.composition || []);
|
|
892
|
+
if (aside.size) {
|
|
893
|
+
const g = flOnePieceGrams(sub);
|
|
894
|
+
if (!(g > 0)) out.unresolved.push({ formulationId: sub.id, name: sub.name || sub.uid || 'sub-formula' });
|
|
895
|
+
else aside.forEach(r => out.draws.push({ ingredientId: r.ingredientId, pieces: parseFloat(r.amount) * subKg / (g / 1000), row: r, sub }));
|
|
896
|
+
}
|
|
897
|
+
flNestedCounted(sub, subKg, depth + 1, out, path.concat(sub.id));
|
|
898
|
+
});
|
|
899
|
+
return out;
|
|
900
|
+
}
|
|
876
901
|
// A recipe's rows without its Not mixed in parts, in any unit: an as-prepared "0.5 g" of wick is still not part of the
|
|
877
902
|
// mix (27f). All rows marked (a kit) keeps them all.
|
|
878
903
|
function flMixRows(comp) {
|
|
@@ -898,8 +923,21 @@ function flOnePieceGrams(f) {
|
|
|
898
923
|
}
|
|
899
924
|
// A recipe row counted in pieces ("1 wick"), as kg through its ingredient's weight per piece. Null for any other row,
|
|
900
925
|
// or a piece row whose ingredient has no weight per piece (it stays unpriced and unscaled, as before).
|
|
926
|
+
// A sub-formula row counted in pieces (2 candles in a gift set, 12 dough balls) weighs its sub-formula's one piece
|
|
927
|
+
// (flOnePieceGrams: the fill, or a recipe written by weight); null when that isn't known, or in a loop (12-04).
|
|
928
|
+
const _flPieceSubStack = new Set();
|
|
901
929
|
function flPieceRowKg(c) {
|
|
902
|
-
if (!c || !
|
|
930
|
+
if (!c || !flIsPieceUnit(c.unit)) return null;
|
|
931
|
+
if (c.formulationId && !c.ingredientId) {
|
|
932
|
+
const amt = parseFloat(c.amount);
|
|
933
|
+
if (!isFinite(amt) || amt < 0 || _flPieceSubStack.has(c.formulationId)) return null;
|
|
934
|
+
const sub = (typeof flFindById === 'function') ? flFindById('formulations', c.formulationId) : (db.formulations || []).find(f => f.id === c.formulationId);
|
|
935
|
+
if (!sub || sub.deleted || typeof flOnePieceGrams !== 'function') return null;
|
|
936
|
+
_flPieceSubStack.add(c.formulationId);
|
|
937
|
+
try { const g = flOnePieceGrams(sub); return (g != null && isFinite(g) && g > 0) ? amt * g / 1000 : null; }
|
|
938
|
+
finally { _flPieceSubStack.delete(c.formulationId); }
|
|
939
|
+
}
|
|
940
|
+
if (!c.ingredientId) return null;
|
|
903
941
|
const amt = parseFloat(c.amount);
|
|
904
942
|
if (!isFinite(amt) || amt < 0) return null;
|
|
905
943
|
const ing = (typeof flFindById === 'function') ? flFindById('ingredients', c.ingredientId) : (db.ingredients || []).find(i => i.id === c.ingredientId);
|
|
@@ -1202,12 +1240,24 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1202
1240
|
if (_seen.has(subF.id)) { missing.push({ reason: 'cycle detected', row: c }); continue; }
|
|
1203
1241
|
const subRes = computeFormulationCost(subF, displayCcy, 'kg', _seen);
|
|
1204
1242
|
const subDensity = (typeof _rolledUpDensity === 'function') ? _rolledUpDensity(subF) : null;
|
|
1243
|
+
// Its parts Not mixed in (a candle's wick) are priced per piece of it, outside its per-kg cost. Inside a parent
|
|
1244
|
+
// they go by mass: per piece ÷ the weight of one piece, so a gift set of two candles pays for two wicks (12-04).
|
|
1245
|
+
const subMissing = (subRes.missing || []).slice();
|
|
1246
|
+
let countedPerKg = 0;
|
|
1247
|
+
if (flCountedAside(subF.composition || []).size) {
|
|
1248
|
+
const g = typeof flOnePieceGrams === 'function' ? flOnePieceGrams(subF) : null;
|
|
1249
|
+
(subRes.countedUnpriced || []).forEach(ing => subMissing.push({ reason: 'no price per piece (counted per piece)', ingredient: ing }));
|
|
1250
|
+
if (!(g > 0)) subMissing.push({ reason: 'set a fill to count its parts per piece', subFormula: subF });
|
|
1251
|
+
else if (subRes.countedPerPiece != null) countedPerKg = subRes.countedPerPiece / (g / 1000);
|
|
1252
|
+
}
|
|
1253
|
+
const perKgAll = (subRes.perKg != null && isFinite(subRes.perKg)) ? subRes.perKg + countedPerKg : subRes.perKg;
|
|
1205
1254
|
subResolve.set(c, {
|
|
1206
1255
|
subFormula: subF,
|
|
1207
|
-
perKgDisplay:
|
|
1208
|
-
perKgOwn:
|
|
1256
|
+
perKgDisplay: perKgAll, // $/kg in displayCcy, its counted parts included
|
|
1257
|
+
perKgOwn: perKgAll, // already converted
|
|
1258
|
+
countedPerKg, // of which its parts per piece
|
|
1209
1259
|
density: subDensity, // kg/L, may be null
|
|
1210
|
-
missing:
|
|
1260
|
+
missing: subMissing,
|
|
1211
1261
|
basisOk: subRes.basisOk,
|
|
1212
1262
|
});
|
|
1213
1263
|
}
|
|
@@ -1333,7 +1383,7 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1333
1383
|
// A counted part's cost for one piece of product (1 wick at $0.12), in the display currency: a price per piece times
|
|
1334
1384
|
// the count, or a price per kg (or L) through the weight per piece. Null when it can't be priced (3 Dec).
|
|
1335
1385
|
let countedPerPiece = 0;
|
|
1336
|
-
const countedUnpriced = [];
|
|
1386
|
+
const countedUnpriced = [], countedRows = []; // countedRows: each counted row's cost per piece of product (the split, 12-04)
|
|
1337
1387
|
const _countedRowCost = (ing, c) => {
|
|
1338
1388
|
if (!ing.cost || ing.cost.value == null || ing.cost.value === '') return null;
|
|
1339
1389
|
const v = parseFloat(ing.cost.value), n = parseFloat(c.amount);
|
|
@@ -1385,8 +1435,8 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1385
1435
|
const amount = parseFloat(c.amount);
|
|
1386
1436
|
if (flBadAmount(c.amount, c.unit)) { missing.push({ reason: `bad amount (${flBadAmount(c.amount, c.unit)})`, subFormula: sub.subFormula }); continue; }
|
|
1387
1437
|
if (!isFinite(amount)) { missing.push({ reason: 'no amount', subFormula: sub.subFormula }); continue; }
|
|
1388
|
-
const kind = classifyUnit((c.unit || 'wt%').toLowerCase());
|
|
1389
|
-
if (kind === 'unknown') { missing.push({ reason: `unsupported composition unit "${c.unit}"`, subFormula: sub.subFormula }); continue; }
|
|
1438
|
+
const kind = flPieceRowKg(c) != null ? 'mass-abs' : classifyUnit((c.unit || 'wt%').toLowerCase());
|
|
1439
|
+
if (kind === 'unknown') { missing.push({ reason: flIsPieceUnit(c.unit) ? `set a fill (or a recipe by weight) on ${sub.subFormula.name || 'the sub-formula'} to cost "${c.unit}"` : `unsupported composition unit "${c.unit}"`, subFormula: sub.subFormula }); continue; }
|
|
1390
1440
|
const perKgDisplay = sub.perKgDisplay;
|
|
1391
1441
|
let contribution = null;
|
|
1392
1442
|
if (kind === 'wt-frac') {
|
|
@@ -1413,7 +1463,7 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1413
1463
|
}
|
|
1414
1464
|
totalPerKg += contribution;
|
|
1415
1465
|
totalPct += amount;
|
|
1416
|
-
breakdown.push({
|
|
1466
|
+
breakdown.push({ row: c,
|
|
1417
1467
|
subFormula: sub.subFormula, ingredient: null,
|
|
1418
1468
|
amount, unit: c.unit || 'wt%',
|
|
1419
1469
|
perKgOwn: sub.perKgOwn, perKgDisplay,
|
|
@@ -1446,7 +1496,7 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1446
1496
|
|
|
1447
1497
|
if (_aside.has(c)) { // counted beside a % recipe: outside the per-kg cost (flCountedAside); priced per piece of product
|
|
1448
1498
|
const cc = _countedRowCost(ing, c);
|
|
1449
|
-
if (cc == null) countedUnpriced.push(ing); else countedPerPiece += cc;
|
|
1499
|
+
if (cc == null) countedUnpriced.push(ing); else { countedPerPiece += cc; countedRows.push({ row: c, ingredient: ing, perPiece: cc }); }
|
|
1450
1500
|
continue;
|
|
1451
1501
|
}
|
|
1452
1502
|
const kind = flPieceRowKg(c) != null ? 'mass-abs' : classifyUnit(unit);
|
|
@@ -1459,7 +1509,7 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1459
1509
|
if (auto.ok) {
|
|
1460
1510
|
totalPerKg += auto.contribution;
|
|
1461
1511
|
totalPct += amount;
|
|
1462
|
-
breakdown.push({
|
|
1512
|
+
breakdown.push({ row: c,
|
|
1463
1513
|
ingredient: ing, amount, unit: c.unit || 'wt%',
|
|
1464
1514
|
perKgOwn: auto.perKgOwn, perKgDisplay: auto.perKgDisplay,
|
|
1465
1515
|
contribution: auto.contribution,
|
|
@@ -1487,7 +1537,7 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1487
1537
|
}
|
|
1488
1538
|
}
|
|
1489
1539
|
const stale = perBasisContribution == null;
|
|
1490
|
-
breakdown.push({
|
|
1540
|
+
breakdown.push({ row: c,
|
|
1491
1541
|
ingredient: ing, amount, unit: c.unit || 'wt%',
|
|
1492
1542
|
perKgOwn: null, perKgDisplay: null,
|
|
1493
1543
|
contribution: stale ? 0 : perBasisContribution,
|
|
@@ -1585,6 +1635,7 @@ function computeFormulationCost(formulation, displayCcy, basisUnit, _seen) {
|
|
|
1585
1635
|
// when there are none, or one of them has no usable price (countedUnpriced names it).
|
|
1586
1636
|
countedPerPiece: _aside.size && !countedUnpriced.length ? countedPerPiece : null,
|
|
1587
1637
|
countedUnpriced,
|
|
1638
|
+
countedRows,
|
|
1588
1639
|
};
|
|
1589
1640
|
}
|
|
1590
1641
|
|
package/vendor/nesting.js
CHANGED
|
@@ -351,6 +351,10 @@ function _rowWtFractionsWithin(f, unresolved) {
|
|
|
351
351
|
if (kinds[i] === 'vol') return amt; // treat as relative volume (best-effort)
|
|
352
352
|
// A row that can't be weighed (a piece with no weight per piece, an unknown unit) is named, not dropped in silence:
|
|
353
353
|
// the rest would otherwise read as 100% (3 Dec, Designer). A part not mixed in (a wick) is no share of the mix.
|
|
354
|
+
// A sub-formula counted in pieces with no weight for one (no fill, a % recipe) is named the same way (12-04).
|
|
355
|
+
if (kinds[i] === 'unknown' && c.formulationId && !c.ingredientId && typeof flIsPieceUnit === 'function' && flIsPieceUnit(c.unit)) {
|
|
356
|
+
unresolved && unresolved.push({ reason: 'no-weight', formulationId: c.formulationId, unit: c.unit || '' });
|
|
357
|
+
}
|
|
354
358
|
if (kinds[i] === 'unknown' && c.ingredientId) {
|
|
355
359
|
const pc = typeof flIsPieceUnit === 'function' && flIsPieceUnit(c.unit);
|
|
356
360
|
const ing = db.ingredients.find(x => x.id === c.ingredientId);
|
|
@@ -680,9 +680,10 @@ function flNlTabHtml(f) {
|
|
|
680
680
|
}
|
|
681
681
|
const c = flNlCompute(f);
|
|
682
682
|
if (!c.ok) {
|
|
683
|
-
|
|
684
|
-
//
|
|
683
|
+
// Pieces (12-04): a weight per piece, or Not mixed in for a part outside the food. The advice says what to
|
|
684
|
+
// set, so the names drop their bracketed reason (Jun, 12-04: "shorten the label message").
|
|
685
685
|
const pcs = typeof flNeedsPieceText === 'function' && flNeedsPieceText(c.needsDensity);
|
|
686
|
+
const who = [...new Set((c.needsDensity || []).map(n => pcs ? String(n).replace(/ \((?:no weight per piece|pieces in a % recipe)\)$/, '') : n))].slice(0, 6).join(', ');
|
|
686
687
|
return `<div class="card"><div class="card-body"><div class="nl-note warn nl-keep">No label yet. ${pcs ? `Can't weigh ${esc(who)}: set a weight per piece, or tick Not mixed in.` : `Add a density to ${esc(who) || 'the rows measured by volume'}.`}</div></div></div>`;
|
|
687
688
|
}
|
|
688
689
|
const st = _nlSettings(f);
|
|
@@ -593,7 +593,10 @@ function _tpBuildRows(composition) {
|
|
|
593
593
|
const rx = (sub && typeof flRxSubViewFields === 'function') ? flRxSubViewFields(sub) : {};
|
|
594
594
|
// Per-field rules (Jun, 28 Oct): the fields that add up by mass roll up too (_tpSubRollup).
|
|
595
595
|
const roll = sub ? _tpSubRollup(sub) : { fields: {}, units: {} };
|
|
596
|
-
|
|
596
|
+
// Counted in pieces (2 candles): weighed through the sub-formula's one piece, like an ingredient's (12-04).
|
|
597
|
+
const pc = typeof flIsPieceUnit === 'function' && flIsPieceUnit(c.unit);
|
|
598
|
+
const pieceKg = pc && typeof flPieceRowKg === 'function' ? flPieceRowKg(c) : null;
|
|
599
|
+
rows.push({ ...base, ing: _tpCiView({ _isSubFormula: true, ...roll.fields, ...rx }), _cfUnits: roll.units, _srcSub: c.formulationId, _subName: (sub && sub.name) || 'sub-formula', ...(pc ? { _piece: true, _pieceKg: pieceKg } : {}) });
|
|
597
600
|
}
|
|
598
601
|
});
|
|
599
602
|
// ABSOLUTE rows (a batch's as-prepared composition: 215.9 g water, 6.6 mL
|
|
@@ -614,9 +617,10 @@ function _tpBuildRows(composition) {
|
|
|
614
617
|
const unweighed = [];
|
|
615
618
|
if (pieces.length && pieces.length < rows.length) {
|
|
616
619
|
const pct = rows.some(r => !r._piece && /^(wt\s*%|%|w\/w|vol\s*%)/i.test(String(r.unit || 'wt%').trim()));
|
|
620
|
+
const nm = r => (r.ing && r.ing._isSubFormula ? r._subName : r.ing && r.ing.name) || '(unnamed)';
|
|
617
621
|
pieces.forEach(r => {
|
|
618
|
-
if (pct) unweighed.push((r
|
|
619
|
-
else if (r._pieceKg == null) unweighed.push((r
|
|
622
|
+
if (pct) unweighed.push(nm(r) + _TP_PIECE_PCT);
|
|
623
|
+
else if (r._pieceKg == null) unweighed.push(nm(r) + _TP_PIECE_NOWT);
|
|
620
624
|
});
|
|
621
625
|
}
|
|
622
626
|
const abs = rows.filter(r => isM(r.unit) || isV(r.unit) || (r._piece && r._pieceKg != null && !unweighed.length));
|
|
@@ -715,10 +719,12 @@ function _tpHarmonizeUnits(rows) {
|
|
|
715
719
|
// with an amount has a number for it, in one unit: a premix with a solvent missing its solids is still "not
|
|
716
720
|
// counted", as before. Not rolled: density (by volume), Tg, HLB, purity, cost, text fields. Nested premixes roll up
|
|
717
721
|
// through _tpBuildRows; a cycle rolls up nothing.
|
|
718
|
-
const _TP_MASS_UNIT = /^(%|wt\s*%|%\s*w\/w|w\/w\s*%?|g\s*\/\s*100\s*g|mg\s*\/\s*100\s*g|[µu]g\s*\/\s*100\s*g|g\s*\/\s*kg|mg\s*\/\s*kg|ppm|ppb|mg\s*koh\s*\/\s*g|meq\s*\/\s*g|mmol\s*\/\s*g)$/i;
|
|
722
|
+
const _TP_MASS_UNIT = /^(%|wt\s*%|%\s*w\/w|w\/w\s*%?|g\s*\/\s*100\s*g|mg\s*\/\s*100\s*g|[µu]g\s*\/\s*100\s*g|g\s*\/\s*kg|mg\s*\/\s*kg|ppm|ppb|mg\s*koh\s*\/\s*g|meq\s*\/\s*g|mmol\s*\/\s*g|k?(?:cal|j)\s*\/\s*(?:100\s*)?(?:g|kg))$/i;
|
|
723
|
+
// Energy per mass (kcal/100 g, kJ/100 g …) adds by mass too: a premix's calories reach the parent's label (12-04).
|
|
724
|
+
// Before, a cookie made 80 % from a dough premix lost the dough's calories, and the label rebuilt them from protein.
|
|
719
725
|
const _TP_MASS_NAMES = new Set(['solids', 'nv', 'nv %', 'nv%', 'non-volatiles', 'nonvolatiles', 'protein', 'fat', 'carb', 'carbs', 'carbohydrate', 'sugar', 'sugars', 'sodium', 'salt', 'fiber', 'fibre', 'ash', 'moisture',
|
|
720
726
|
'sat_fat', 'trans_fat', 'added_sugar', 'cholesterol', 'calcium', 'iron', 'potassium', 'vit_d', 'atwater',
|
|
721
|
-
'volume', 'pigmentvolume', 'dryvolume', 'volatileorganic', 'voc %']); // per gram, so they add by mass (PVC, VOC through a premix)
|
|
727
|
+
'volume', 'pigmentvolume', 'dryvolume', 'volatileorganic', 'voc %', 'energy', 'calories', 'kcal']); // per gram, so they add by mass (PVC, VOC through a premix)
|
|
722
728
|
const _TP_NOT_ROLLED = new Set(['density', 'mw', 'cost', 'purity', 'stock', 'reorder', 'tg', 'hlb', 'taxonid']);
|
|
723
729
|
const _tpSubStack = new Set();
|
|
724
730
|
// Inside _tpWithSubMemo each premix rolls up once: a Solve rebuilds the same rows ~80 times with only the top-level
|