formlab-mcp 0.7.13 → 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 +5 -3
- package/vendor/cost.js +62 -11
- package/vendor/nesting.js +4 -0
- package/vendor/nutrition-label.js +5 -2
- package/vendor/reactive.js +9 -3
- package/vendor/theoretical-params.js +41 -7
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),
|
|
@@ -457,7 +459,7 @@ const get_batch = {
|
|
|
457
459
|
number: c.n ?? null, issuedAt: c.issuedAt || null, issuedBy: c.issuedBy || '', product: c.product || '', customer: c.customer || '', po: c.po || '',
|
|
458
460
|
resultsUpTo: c.upTo || null, verdict: c.conforms === false ? 'does not conform' : c.untested ? 'not tested (override)' : c.conforms === true ? 'conforms' : 'reported',
|
|
459
461
|
...(c.override ? { overrideReason: c.override } : {}),
|
|
460
|
-
// 0.7.
|
|
462
|
+
// 0.7.14: a voided certificate stays, marked (never deleted).
|
|
461
463
|
...(c.voidedAt ? { voided: true, voidedAt: c.voidedAt, voidedBy: c.voidedBy || '', voidReason: c.voidReason || '' } : {}), ...(Array.isArray(c.notTested) && c.notTested.length ? { notTested: c.notTested } : {}),
|
|
462
464
|
results: (c.rows || []).map(r => ({ parameter: r.name, ...(r.cond ? { conditions: r.cond } : {}), value: r.value, unit: r.unit || '', spec: r.spec || null, status: r.status || 'reported', testReport: r.testUid || null, testDate: r.testDate || null, ...(r.doubt ? { inDoubt: r.doubt } : {}) })),
|
|
463
465
|
sourceReports: c.sources || [],
|
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,8 +680,11 @@ 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
|
+
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(', ');
|
|
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>`;
|
|
685
688
|
}
|
|
686
689
|
const st = _nlSettings(f);
|
|
687
690
|
const lines = flNlLines(f, c);
|
package/vendor/reactive.js
CHANGED
|
@@ -286,11 +286,17 @@ function _flRxUnitBasis(u) { u = String(u || '').trim().toLowerCase(); return /^
|
|
|
286
286
|
// Two checks: the rows as typed (% beside g, which _tpBuildRows turns into one wt% set), and as built (mL it couldn't
|
|
287
287
|
// convert for want of a density). A row with no unit takes any.
|
|
288
288
|
function flRxMixedUnits(comp) {
|
|
289
|
-
|
|
290
|
-
|
|
289
|
+
// A part Not mixed in (a wick) is outside the mix; a piece counts by its weight like grams (12-04). _tpBuildRows
|
|
290
|
+
// names a piece it can't weigh (needsDensity), and that is a mixed set too.
|
|
291
|
+
const pc = u => typeof flIsPieceUnit === 'function' && flIsPieceUnit(u);
|
|
292
|
+
const abs = u => (typeof isMassUnit === 'function' && isMassUnit(u)) || (typeof isVolUnit === 'function' && isVolUnit(u)) || pc(u);
|
|
293
|
+
const mix = typeof flMixRows === 'function' ? flMixRows(comp || []) : (comp || []);
|
|
294
|
+
const typed = new Set(mix.filter(c => c && (c.ingredientId || c.formulationId) && _flRxNum(c.amount) > 0)
|
|
291
295
|
.map(c => (abs(c.unit) ? 'abs' : _flRxUnitBasis(c.unit))).filter(Boolean));
|
|
292
296
|
if (typed.size > 1) return true;
|
|
293
|
-
const
|
|
297
|
+
const all = _flRxRows(comp);
|
|
298
|
+
if (all.needsDensity && all.needsDensity.length && typeof flNeedsPieceText === 'function' && flNeedsPieceText(all.needsDensity)) return true;
|
|
299
|
+
const built = all.filter(r => r && r.amount > 0);
|
|
294
300
|
// A row still in mL once built had no density, so none were made masses: an all-mL recipe multiplied millilitres
|
|
295
301
|
// by meq per gram (QA sweep, Jun 1 Nov: 100 mL of a 1.16 g/mL epoxy counted as 100 g).
|
|
296
302
|
if (typeof isVolUnit === 'function' && built.some(r => isVolUnit(r.unit))) return true;
|
|
@@ -558,6 +558,9 @@ function _tpEvaluateAll(params, rows) {
|
|
|
558
558
|
// standard fields, with numeric coercion when the string parses.
|
|
559
559
|
function _tpBuildRows(composition) {
|
|
560
560
|
const rows = [];
|
|
561
|
+
// A part marked Not mixed in (a wick, a jar) is no share of the mix in any unit (27f), so no expression, label
|
|
562
|
+
// or reactive sum reads it (12-04). A kit where every row is marked keeps them all.
|
|
563
|
+
if (typeof flMixRows === 'function') composition = flMixRows(composition || []);
|
|
561
564
|
(composition || []).forEach(c => {
|
|
562
565
|
if (!c) return;
|
|
563
566
|
const amount = parseFloat(c.amount);
|
|
@@ -575,7 +578,10 @@ function _tpBuildRows(composition) {
|
|
|
575
578
|
// math never reads it; _tpMissingInputs uses it to flag mixed units.
|
|
576
579
|
const _cfUnits = {};
|
|
577
580
|
((ing && ing.customFields) || []).forEach(f => { if (f && f.name && f.unit) _cfUnits[String(f.name).trim().toLowerCase()] = String(f.unit).trim(); });
|
|
578
|
-
|
|
581
|
+
// Counted in pieces (2 eggs): weighed through the ingredient's weight per piece, like grams (12-04).
|
|
582
|
+
const pc = typeof flIsPieceUnit === 'function' && flIsPieceUnit(c.unit);
|
|
583
|
+
const pieceKg = pc && typeof flPieceRowKg === 'function' ? flPieceRowKg(c) : null;
|
|
584
|
+
rows.push({ ...base, ing: _tpIngredientView(ing), _srcIng: ing || null, _cfUnits, ...(pc ? { _piece: true, _pieceKg: pieceKg } : {}) });
|
|
579
585
|
} else if (c.formulationId) {
|
|
580
586
|
// Sub-formula row: amount/role still meaningful, but no ing.* props.
|
|
581
587
|
// For chemistry-aware aggregations (NV, OHV, PVC), treat as opaque
|
|
@@ -587,7 +593,10 @@ function _tpBuildRows(composition) {
|
|
|
587
593
|
const rx = (sub && typeof flRxSubViewFields === 'function') ? flRxSubViewFields(sub) : {};
|
|
588
594
|
// Per-field rules (Jun, 28 Oct): the fields that add up by mass roll up too (_tpSubRollup).
|
|
589
595
|
const roll = sub ? _tpSubRollup(sub) : { fields: {}, units: {} };
|
|
590
|
-
|
|
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 } : {}) });
|
|
591
600
|
}
|
|
592
601
|
});
|
|
593
602
|
// ABSOLUTE rows (a batch's as-prepared composition: 215.9 g water, 6.6 mL
|
|
@@ -601,10 +610,26 @@ function _tpBuildRows(composition) {
|
|
|
601
610
|
// and any set where one absolute row can't resolve, are left untouched.
|
|
602
611
|
const isM = u => (typeof isMassUnit === 'function') && isMassUnit(u);
|
|
603
612
|
const isV = u => (typeof isVolUnit === 'function') && isVolUnit(u);
|
|
604
|
-
|
|
605
|
-
|
|
613
|
+
// Pieces: weighed ones join the absolute rows. One that can't be weighed (no weight per piece), or any piece in a
|
|
614
|
+
// % recipe (mixed basis), gives the expressions no value and is named, never read as 2 wt% (12-04). A set of
|
|
615
|
+
// nothing but unweighed pieces stays as typed.
|
|
616
|
+
const pieces = rows.filter(r => r._piece);
|
|
617
|
+
const unweighed = [];
|
|
618
|
+
if (pieces.length && pieces.length < rows.length) {
|
|
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)';
|
|
621
|
+
pieces.forEach(r => {
|
|
622
|
+
if (pct) unweighed.push(nm(r) + _TP_PIECE_PCT);
|
|
623
|
+
else if (r._pieceKg == null) unweighed.push(nm(r) + _TP_PIECE_NOWT);
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
const abs = rows.filter(r => isM(r.unit) || isV(r.unit) || (r._piece && r._pieceKg != null && !unweighed.length));
|
|
627
|
+
if (unweighed.length) {
|
|
628
|
+
Object.defineProperty(rows, 'needsDensity', { value: unweighed, enumerable: false });
|
|
629
|
+
} else if (abs.length && typeof massToKg === 'function' && typeof volToL === 'function') {
|
|
606
630
|
const noDensity = [];
|
|
607
631
|
const grams = abs.map(r => {
|
|
632
|
+
if (r._piece) return r._pieceKg * 1000;
|
|
608
633
|
if (isM(r.unit)) { const f = massToKg(r.unit); return (f != null) ? r.amount * f * 1000 : null; }
|
|
609
634
|
const L = volToL(r.unit);
|
|
610
635
|
let d = null;
|
|
@@ -624,7 +649,7 @@ function _tpBuildRows(composition) {
|
|
|
624
649
|
}
|
|
625
650
|
}
|
|
626
651
|
_tpHarmonizeUnits(rows);
|
|
627
|
-
rows.forEach(r => { delete r._srcIng; delete r._srcSub; });
|
|
652
|
+
rows.forEach(r => { delete r._srcIng; delete r._srcSub; delete r._piece; delete r._pieceKg; });
|
|
628
653
|
return rows;
|
|
629
654
|
}
|
|
630
655
|
|
|
@@ -694,10 +719,12 @@ function _tpHarmonizeUnits(rows) {
|
|
|
694
719
|
// with an amount has a number for it, in one unit: a premix with a solvent missing its solids is still "not
|
|
695
720
|
// counted", as before. Not rolled: density (by volume), Tg, HLB, purity, cost, text fields. Nested premixes roll up
|
|
696
721
|
// through _tpBuildRows; a cycle rolls up nothing.
|
|
697
|
-
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.
|
|
698
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',
|
|
699
726
|
'sat_fat', 'trans_fat', 'added_sugar', 'cholesterol', 'calcium', 'iron', 'potassium', 'vit_d', 'atwater',
|
|
700
|
-
'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)
|
|
701
728
|
const _TP_NOT_ROLLED = new Set(['density', 'mw', 'cost', 'purity', 'stock', 'reorder', 'tg', 'hlb', 'taxonid']);
|
|
702
729
|
const _tpSubStack = new Set();
|
|
703
730
|
// Inside _tpWithSubMemo each premix rolls up once: a Solve rebuilds the same rows ~80 times with only the top-level
|
|
@@ -1270,9 +1297,16 @@ function _tpMissingInputs(formula, rows) {
|
|
|
1270
1297
|
// The line for a parameter left without a value: mL rows need a density to count by mass.
|
|
1271
1298
|
function _tpNeedsDensityNote(names) {
|
|
1272
1299
|
const n = names.length;
|
|
1300
|
+
if (flNeedsPieceText(names)) return { text: `${flNeedsLead(names)}: ${names.slice(0, 2).join(', ')}${n > 2 ? ` +${n - 2} more` : ''}`,
|
|
1301
|
+
tip: `Pieces count by their weight per piece, in a recipe by weight. A part outside the mix: tick Not mixed in on the ingredient. ${names.join(', ')}.` };
|
|
1273
1302
|
return { text: `Needs a density: ${names.slice(0, 2).join(', ')}${n > 2 ? ` +${n - 2} more` : ''}`,
|
|
1274
1303
|
tip: `Rows in mL count by mass. Give ${n === 1 ? 'it' : 'these'} a density, or enter the recipe in g or %: ${names.join(', ')}.` };
|
|
1275
1304
|
}
|
|
1305
|
+
// Rows _tpBuildRows can't weigh: mL with no density (a bare name), or pieces (tagged with the reason, 12-04).
|
|
1306
|
+
const _TP_PIECE_NOWT = ' (no weight per piece)';
|
|
1307
|
+
const _TP_PIECE_PCT = ' (pieces in a % recipe)';
|
|
1308
|
+
function flNeedsPieceText(names) { return (names || []).some(n => String(n).endsWith(_TP_PIECE_NOWT) || String(n).endsWith(_TP_PIECE_PCT)); }
|
|
1309
|
+
function flNeedsLead(names) { return flNeedsPieceText(names) ? "Can't weigh" : 'Needs a density'; }
|
|
1276
1310
|
// One short line for the table (and its tooltip), '' when nothing is missing.
|
|
1277
1311
|
function _tpMissingNote(miss) {
|
|
1278
1312
|
if (!miss) return null;
|