Skip to content

Commit

Permalink
feat: aggregate into table uses metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsenta committed Sep 6, 2023
1 parent 84cfbb1 commit 660ff7a
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions aggregate-into-table.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require("fs");

const TestMetadata = "TestMetadata";
const METADATA_TEST_GROUP = "group";
const METADATA_IPIP = "ipip";

// retrieve the list of input files from the command line
const files = process.argv.slice(2);
Expand All @@ -10,13 +12,18 @@ const inputs = files.map((file) => {
return JSON.parse(fs.readFileSync(file, 'utf8'));
});

// merge all the unique keys from all the inputs
// merge all the unique keys & metadata from all the inputs
let keys = new Set();
const metadata = {}
inputs.forEach((input) => {
Object.keys(input).forEach((key) => {
keys.add(key);

// add metadata keys (do not care about different metadatas for now)
metadata[key] = { ...metadata[key], ...input[key]["meta"] || {} };
});
});

keys.delete(TestMetadata); // Extract TestMetadata which is a special case
keys = Array.from(keys).sort();

Expand All @@ -26,8 +33,18 @@ const columns = [];
// add the leading column ("gateway", "version", "key1", "key2", ... "keyN")
const leading = ["gateway", "version"];
keys.forEach((key) => {
const m = metadata[key];

// Skip the "Test" prefix
const niceKey = key.replace(/^Test/, '');
let niceKey = key.replace(/^Test/, '');

niceKey = m[METADATA_TEST_GROUP] || niceKey;

// Add ipip link if available
if (m[METADATA_IPIP]) {
niceKey = `[${niceKey}](https://specs.ipfs.tech/ipips/${m[METADATA_IPIP]})`;
}

leading.push(niceKey);
});
columns.push(leading);
Expand Down

0 comments on commit 660ff7a

Please sign in to comment.