MCPcopy Index your code
hub / github.com/anomalyco/models.dev / applyOmit

Function applyOmit

packages/core/src/sync/index.ts:522–563  ·  view source on GitHub ↗
(target: Record<string, unknown>, paths: string[])

Source from the content-addressed store, hash-verified

520}
521
522function applyOmit(target: Record<string, unknown>, paths: string[]) {
523 omitLoop: for (const omit of paths) {
524 const parts = omit.split(".");
525 const parents: Array<{ value: Record<string, unknown>; key: string }> = [];
526 let current = target;
527
528 for (const part of parts.slice(0, -1)) {
529 const next = current[part];
530 if (
531 next === undefined ||
532 next === null ||
533 typeof next !== "object" ||
534 Array.isArray(next)
535 ) {
536 continue omitLoop;
537 }
538 parents.push({ value: current, key: part });
539 current = next as Record<string, unknown>;
540 }
541
542 const lastPart = parts.at(-1);
543 if (lastPart === undefined || !(lastPart in current)) continue;
544
545 delete current[lastPart];
546
547 for (let index = parents.length - 1; index >= 0; index--) {
548 const parent = parents[index];
549 if (parent === undefined) continue;
550 const value = parent.value[parent.key];
551 if (
552 value === null ||
553 value === undefined ||
554 typeof value !== "object" ||
555 Array.isArray(value) ||
556 Object.keys(value).length > 0
557 ) {
558 break;
559 }
560 delete parent.value[parent.key];
561 }
562 }
563}
564
565async function tomlFiles(root: string, dir = "") {
566 const result: Array<{ file: string; symlink: boolean }> = [];

Callers 1

resolveBaseModelFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected