everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
27 lines (26 loc) • 1.04 kB
JavaScript
//#region src/services/resolution/unknown-keys.ts
function innerShape(node, depth = 0) {
if (depth > 4 || !node || typeof node !== "object") return void 0;
const candidate = node;
if (candidate.shape && typeof candidate.shape === "object") return candidate.shape;
if (typeof candidate.unwrap === "function") return innerShape(candidate.unwrap(), depth + 1);
if (typeof candidate.getter === "function") return innerShape(candidate.getter(), depth + 1);
}
function collectUnknownKeys(value, schema, prefix = "") {
const shape = innerShape(schema);
if (!shape || !value || typeof value !== "object" || Array.isArray(value)) return [];
const unknown = [];
for (const key of Object.keys(value)) {
const path = prefix ? `${prefix}.${key}` : key;
const declared = shape[key];
if (!declared) {
unknown.push(path);
continue;
}
if (innerShape(declared)) unknown.push(...collectUnknownKeys(value[key], declared, path));
}
return unknown;
}
//#endregion
export { collectUnknownKeys };
//# sourceMappingURL=unknown-keys.mjs.map