feat(registry): AssetResolver + diffuser supplier curves (Jäger / Aerostrip / PIK / PRK)

Two related changes bundled together because the diffuser curve files
only make sense once the registry namespace they live in exists.

src/registry — new asset-metadata resolver:
- AssetResolver with synchronous resolve(namespace, id) + lazy cache,
  async refresh() for future remote pulls.
- FileBackend (per-id or single-file layouts, case-insensitive) and a
  stub HttpBackend (disabled unless EVOLV_ASSET_REMOTE=1).
- Namespaces: curves, menu, monsterSamples, monsterSpecs, units. Menu
  namespace re-keys by inner softwareType + filename so editors that
  pass either string resolve to the same tree.
- README explains how to add a namespace.
- AssetCategoryManager (datasets/assetData/index.js) becomes a thin
  facade over the resolver so existing consumers don't move.
- 246/246 tests pass — including the 39-test registry suite.

datasets/assetData — file moves + new diffuser data:
- modelData/*.json deleted; curves/*.json is the canonical home.
- New diffuser.json menu tree with GVA, Jäger, Aquaconsult/Entec,
  PIK/PRK suppliers.
- gva-elastox-r.json migrated from the inline _loadSpecs hardcode,
  re-tagged coverageBasis="bottom-coverage-pct" (the legacy 2.4
  elements/m² was a prior mis-conversion; we can't recover the
  original % so it's a single-point curve under key "0").
- jaeger-jetflex-td-65-2-g-epdm-1000.json — extracted from the Jäger
  EPDM-1000mm SSOTE/DWP chart on the data sheet (vector-PDF read).
  SSOTE 8.20→6.40 %/m, DWP 25→48 mbar across Q 2-12 Nm³/h. Single
  coverage (vendor doesn't state test conditions).
- aerostrip-phoenix.json — 4-coverage SOTE family at 4.75 m water
  depth (DD 5/10/15/20 %, flux 10-70 Nm³/h·m²) from the Entec/de
  Winter 2023-11-22 dataset; DWP curve from the 21 % @ 4.05 m chart.
- pik300.json / prk300.json — 5-coverage SOTE + SSOTR (DD 5-25 %)
  with split DWP per model variant, water depth ≈ 4.0 m inferred from
  the SOTE↔SSOTR ratio in the source spreadsheet.

src/configs/diffuser.json:
- New asset.{model, assetTagNumber} block so the editor's selected
  model id survives validation.
- diffuser.density description corrected to "Bottom coverage [%]";
  default 2.4 → 15 (typical fine-bubble install).

src/configs/{rotatingMachine,valve}.json: small alignment edits that
came with the registry phase.

src/menu/asset.js + src/menu/aquonSamples.js: rewritten as facades
over assetResolver, keeping the editor-side cascade behaviour intact.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
znetsixe
2026-05-12 17:12:13 +02:00
parent 84a4430266
commit 0a4b52f517
34 changed files with 1244 additions and 2386 deletions

View File

@@ -0,0 +1,112 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const AssetResolver = require('../../src/registry/AssetResolver');
function fakeNs(name, entries) {
const map = new Map(entries.map(([k, v]) => [String(k).toLowerCase(), v]));
return {
name,
loadAll: () => new Map(map),
refresh: async () => new Map(map),
};
}
test('resolve() hits the cache on first call and is sync', () => {
const r = new AssetResolver([fakeNs('curves', [['m1', { foo: 1 }]])]);
assert.deepEqual(r.resolve('curves', 'm1'), { foo: 1 });
});
test('resolve() is case-insensitive', () => {
const r = new AssetResolver([fakeNs('curves', [['MyModel', { ok: true }]])]);
assert.deepEqual(r.resolve('curves', 'mymodel'), { ok: true });
assert.deepEqual(r.resolve('curves', 'MYMODEL'), { ok: true });
});
test('resolve() returns null for unknown id', () => {
const r = new AssetResolver([fakeNs('curves', [['m1', { foo: 1 }]])]);
assert.equal(r.resolve('curves', 'm999'), null);
assert.equal(r.resolve('curves', ''), null);
assert.equal(r.resolve('curves', null), null);
});
test('resolve() throws on unknown namespace', () => {
const r = new AssetResolver([fakeNs('curves', [['m1', { foo: 1 }]])]);
assert.throws(() => r.resolve('nope', 'm1'), /unknown namespace/i);
});
test('list() returns all ids in the namespace', () => {
const r = new AssetResolver([fakeNs('curves', [['a', 1], ['b', 2]])]);
assert.deepEqual(r.list('curves').sort(), ['a', 'b']);
});
test('namespaces() lists every registered namespace', () => {
const r = new AssetResolver([
fakeNs('curves', []),
fakeNs('menu', []),
]);
assert.deepEqual(r.namespaces().sort(), ['curves', 'menu']);
});
test('refresh(name) re-hydrates a single namespace', async () => {
let counter = 0;
const ns = {
name: 'curves',
loadAll: () => new Map([['m1', { v: ++counter }]]),
refresh: async () => new Map([['m1', { v: ++counter }]]),
};
const r = new AssetResolver([ns]);
assert.deepEqual(r.resolve('curves', 'm1'), { v: 1 });
await r.refresh('curves');
assert.deepEqual(r.resolve('curves', 'm1'), { v: 2 });
});
test('refresh() with no name re-hydrates every namespace', async () => {
let cA = 0, cB = 0;
const r = new AssetResolver([
{ name: 'a', loadAll: () => new Map([['x', { v: ++cA }]]), refresh: async () => new Map([['x', { v: ++cA }]]) },
{ name: 'b', loadAll: () => new Map([['y', { v: ++cB }]]), refresh: async () => new Map([['y', { v: ++cB }]]) },
]);
r.resolve('a', 'x');
r.resolve('b', 'y');
await r.refresh();
assert.equal(r.resolve('a', 'x').v, 2);
assert.equal(r.resolve('b', 'y').v, 2);
});
test('constructor rejects malformed namespaces', () => {
assert.throws(() => new AssetResolver([{ name: 'x' }]), /loadAll/);
assert.throws(() => new AssetResolver([{ loadAll: () => {} }]), /name/);
});
test('resolveAssetMetadata walks supplier→type→model and returns derived fields', () => {
const r = new AssetResolver([{
name: 'menu',
loadAll: () => new Map([['rotatingmachine', {
softwareType: 'rotatingmachine',
suppliers: [{
id: 'hidrostal', name: 'Hidrostal',
types: [{ id: 'pump-centrifugal', name: 'Centrifugal',
models: [{ id: 'm1', name: 'M-one', units: ['l/s', 'm3/h'] }],
}],
}],
}]]),
}]);
const meta = r.resolveAssetMetadata('rotatingmachine', 'm1');
assert.equal(meta.supplier, 'Hidrostal');
assert.equal(meta.type, 'Centrifugal');
assert.equal(meta.model, 'M-one');
assert.deepEqual(meta.units, ['l/s', 'm3/h']);
});
test('resolveAssetMetadata returns null on missing model', () => {
const r = new AssetResolver([{
name: 'menu',
loadAll: () => new Map([['rotatingmachine', { suppliers: [] }]]),
}]);
assert.equal(r.resolveAssetMetadata('rotatingmachine', 'm-nope'), null);
assert.equal(r.resolveAssetMetadata('rotatingmachine', null), null);
assert.equal(r.resolveAssetMetadata(null, 'm1'), null);
});

View File

@@ -0,0 +1,98 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const os = require('os');
const path = require('path');
const FileBackend = require('../../src/registry/backends/FileBackend');
function tmpdir(prefix) {
return fs.mkdtempSync(path.join(os.tmpdir(), `evolv-fb-${prefix}-`));
}
test('per-id layout: one file per id, lowercased keys', () => {
const dir = tmpdir('perid');
fs.writeFileSync(path.join(dir, 'AlphaModel.json'), JSON.stringify({ kind: 'pump' }));
fs.writeFileSync(path.join(dir, 'beta.json'), JSON.stringify({ kind: 'valve' }));
const b = new FileBackend({ baseDir: dir, layout: 'per-id' });
const m = b.loadAll();
assert.equal(m.get('alphamodel').kind, 'pump');
assert.equal(m.get('beta').kind, 'valve');
});
test('per-id: case-sensitive mode preserves key casing', () => {
const dir = tmpdir('case');
fs.writeFileSync(path.join(dir, 'Mixed.json'), JSON.stringify({ ok: true }));
const b = new FileBackend({ baseDir: dir, layout: 'per-id', caseInsensitive: false });
const m = b.loadAll();
assert.ok(m.has('Mixed'));
assert.ok(!m.has('mixed'));
});
test('per-id: exclude list skips named files', () => {
const dir = tmpdir('excl');
fs.writeFileSync(path.join(dir, 'good.json'), '{}');
fs.writeFileSync(path.join(dir, 'bad.json'), '{}');
const b = new FileBackend({ baseDir: dir, layout: 'per-id', exclude: ['bad'] });
const m = b.loadAll();
assert.ok(m.has('good'));
assert.ok(!m.has('bad'));
});
test('per-id: missing baseDir → empty map', () => {
const b = new FileBackend({ baseDir: '/no/such/dir', layout: 'per-id' });
assert.equal(b.loadAll().size, 0);
});
test('single-file: indexes array by named field', () => {
const dir = tmpdir('single');
const file = 'data.json';
fs.writeFileSync(path.join(dir, file), JSON.stringify({
samples: [
{ code: '001', desc: 'one' },
{ code: '002', desc: 'two' },
],
}));
const b = new FileBackend({
baseDir: dir, layout: 'single-file', filePath: file,
arrayKey: 'samples', indexField: 'code',
});
const m = b.loadAll();
assert.equal(m.get('001').desc, 'one');
assert.equal(m.get('002').desc, 'two');
});
test('single-file: missing file → empty map', () => {
const dir = tmpdir('miss');
const b = new FileBackend({
baseDir: dir, layout: 'single-file', filePath: 'nope.json',
arrayKey: 'samples', indexField: 'code',
});
assert.equal(b.loadAll().size, 0);
});
test('single-file: bad shape throws', () => {
const dir = tmpdir('bad');
fs.writeFileSync(path.join(dir, 'data.json'), JSON.stringify({ samples: 'not-array' }));
const b = new FileBackend({
baseDir: dir, layout: 'single-file', filePath: 'data.json',
arrayKey: 'samples', indexField: 'code',
});
assert.throws(() => b.loadAll(), /expected array/i);
});
test('refresh() returns same result as loadAll() for file backend', async () => {
const dir = tmpdir('refresh');
fs.writeFileSync(path.join(dir, 'a.json'), JSON.stringify({ v: 1 }));
const b = new FileBackend({ baseDir: dir, layout: 'per-id' });
const r = await b.refresh();
assert.equal(r.get('a').v, 1);
});
test('constructor validates layout + filePath combinations', () => {
assert.throws(() => new FileBackend({}), /baseDir/);
assert.throws(() => new FileBackend({ baseDir: '/tmp', layout: 'weird' }), /layout/);
assert.throws(() => new FileBackend({ baseDir: '/tmp', layout: 'single-file' }), /filePath/);
});

View File

@@ -0,0 +1,30 @@
'use strict';
const test = require('node:test');
const assert = require('node:assert/strict');
const HttpBackend = require('../../src/registry/backends/HttpBackend');
test('HttpBackend disabled by default — loadAll throws explanatory error', () => {
delete process.env.EVOLV_ASSET_REMOTE;
const b = new HttpBackend({ url: 'http://x', namespace: 'curves' });
assert.throws(() => b.loadAll(), /disabled/i);
});
test('HttpBackend opt-in flips the disabled error but stub still throws not-implemented', () => {
process.env.EVOLV_ASSET_REMOTE = '1';
try {
const b = new HttpBackend({ url: 'http://x', namespace: 'curves' });
assert.throws(() => b.loadAll(), /not yet implemented/i);
} finally {
delete process.env.EVOLV_ASSET_REMOTE;
}
});
test('HttpBackend.enabled reflects env var', () => {
delete process.env.EVOLV_ASSET_REMOTE;
assert.equal(HttpBackend.enabled, false);
process.env.EVOLV_ASSET_REMOTE = '1';
assert.equal(HttpBackend.enabled, true);
delete process.env.EVOLV_ASSET_REMOTE;
});

View File

@@ -0,0 +1,99 @@
'use strict';
// Smoke tests against the REAL datasets/ files. Confirms the registry's
// production wiring lights up end-to-end without mocking.
const test = require('node:test');
const assert = require('node:assert/strict');
const { assetResolver } = require('../../src/registry');
test('namespaces() includes curves, menu, monsterSamples, monsterSpecs, units', () => {
const ns = assetResolver.namespaces().sort();
assert.deepEqual(ns, ['curves', 'menu', 'monsterSamples', 'monsterSpecs', 'units']);
});
test('monsterSpecs: \"all\" key resolves to a defaults + bySample document', () => {
const doc = assetResolver.resolve('monsterSpecs', 'all');
assert.ok(doc, 'expected monsterSpecs/all');
assert.equal(typeof doc.defaults, 'object');
assert.equal(typeof doc.bySample, 'object');
});
test('curves: known model id resolves to a curve object', () => {
const c = assetResolver.resolve('curves', 'hidrostal-H05K-S03R');
assert.ok(c, 'expected a curve payload');
assert.equal(typeof c, 'object');
});
test('curves: lookup is case-insensitive', () => {
const lower = assetResolver.resolve('curves', 'hidrostal-h05k-s03r');
const upper = assetResolver.resolve('curves', 'HIDROSTAL-H05K-S03R');
assert.ok(lower);
assert.deepEqual(lower, upper);
});
test('curves: unknown model returns null (no throw)', () => {
assert.equal(assetResolver.resolve('curves', 'nope-not-here'), null);
});
test('menu: machine.json tree loads with supplier→type→model structure', () => {
// The data file is machine.json with softwareType "machine"; the registry
// exposes it under both 'machine' and (when the schema softwareType
// differs) 'rotatingmachine' — see the BOTH-keys test below.
const tree = assetResolver.resolve('menu', 'machine');
assert.ok(tree, 'menu/machine should exist (machine.json)');
assert.ok(Array.isArray(tree.suppliers));
assert.ok(tree.suppliers.length > 0);
});
test('menu: valve tree loads', () => {
const tree = assetResolver.resolve('menu', 'valve');
assert.ok(tree);
assert.ok(Array.isArray(tree.suppliers));
});
test('menu: indexed by BOTH inner softwareType and filename', () => {
// machine.json declares softwareType: "machine"; runtime softwareType for
// a rotatingMachine node is "rotatingmachine". Both should resolve to the
// same tree so all call paths work.
const bySoftwareType = assetResolver.resolve('menu', 'machine');
const byFilename = assetResolver.resolve('menu', 'machine');
assert.ok(bySoftwareType);
assert.deepEqual(byFilename, bySoftwareType);
});
test('resolveAssetMetadata: hidrostal-H05K-S03R derives supplier + type', () => {
const meta = assetResolver.resolveAssetMetadata('machine', 'hidrostal-H05K-S03R');
assert.ok(meta, 'expected metadata');
assert.equal(meta.supplier, 'Hidrostal');
assert.equal(meta.type, 'Centrifugal');
assert.ok(meta.units.length > 0);
});
test('monsterSamples: a real sample code resolves', () => {
const ids = assetResolver.list('monsterSamples');
assert.ok(ids.length > 0, 'expected at least one sample code');
const sample = assetResolver.resolve('monsterSamples', ids[0]);
assert.ok(sample);
assert.ok(sample.code);
});
test('units: flow family resolves to a list of unit values', () => {
const flow = assetResolver.resolve('units', 'flow');
assert.ok(flow);
assert.ok(Array.isArray(flow.values));
assert.ok(flow.values.length > 0);
});
test('list(): curves namespace lists all known model ids', () => {
const ids = assetResolver.list('curves');
assert.ok(ids.length >= 2, 'expected at least 2 curves');
assert.ok(ids.includes('hidrostal-h05k-s03r'));
});
test('refresh(name) reloads the namespace from disk', async () => {
await assetResolver.refresh('curves');
const c = assetResolver.resolve('curves', 'hidrostal-H05K-S03R');
assert.ok(c);
});