everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
40 lines (39 loc) • 1.15 kB
JavaScript
//#region src/registry-use.ts
function listComposableSections(config) {
const source = config;
const sections = [];
for (const key of [
"host",
"ui",
"api",
"auth"
]) if (source.app?.[key]) sections.push(`app.${key}`);
for (const key of Object.keys(source.plugins ?? {})) sections.push(`plugins.${key}`);
return sections;
}
function applyRegistrySections(local, remote, sections) {
const available = listComposableSections(remote);
const unknown = sections.filter((section) => !available.includes(section));
if (unknown.length > 0) throw new Error(`Unknown section(s): ${unknown.join(", ")}. Available: ${available.join(", ")}`);
const merged = structuredClone(local);
for (const section of sections) if (section.startsWith("app.")) {
const key = section.slice(4);
merged.app = {
...merged.app,
[key]: remote.app?.[key]
};
} else {
const key = section.slice(8);
merged.plugins = {
...merged.plugins,
[key]: remote.plugins?.[key]
};
}
return {
config: merged,
applied: sections
};
}
//#endregion
export { applyRegistrySections, listComposableSections };
//# sourceMappingURL=registry-use.mjs.map