in src/changes/utils.ts [56:129]
export function getPontSpecByProcessType(
specDiffs: PontSpecWithMods,
processType: "untracked" | "staged",
stagedChanges: StagedChange[],
): PontSpecWithMods {
const changedDiffs = {
...specDiffs,
mods: (specDiffs.mods || []).map((mod) => {
const apis = (mod.interfaces || []).filter((api) => (api as any).diffType && (api as any).diffType !== "equal");
return { ...mod, interfaces: apis } as Mod;
}),
definitions: removeMapKeys(specDiffs.definitions, (name) => {
const struct = specDiffs.definitions[name];
if (struct?.diffType && struct?.diffType !== "equal") {
return false;
}
return true;
}),
};
const filterApi = (api: PontAPI, modName: string | Symbol) => {
const hasStaged = stagedChanges.find((change) =>
StagedChange.checkIsEqual(change, {
metaType: MetaType.API,
apiName: api.name,
modName,
specName: specDiffs.name,
}),
);
if (hasStaged && processType === "staged") {
return true;
} else if (!hasStaged && processType === "untracked") {
return true;
}
return false;
};
const mapMod = (mod: Mod): Mod | false => {
const apis = mod.interfaces.filter((api) => filterApi(api, mod.name));
if (apis.length) {
return {
...mod,
interfaces: apis,
};
}
return false;
};
const filterStruct = (struct: PontJsonSchema) => {
const hasStaged = stagedChanges.find((change) =>
StagedChange.checkIsEqual(change, {
metaType: MetaType.Struct,
structName: struct.name,
specName: specDiffs.name,
}),
);
if ((hasStaged && processType === "staged") || (!hasStaged && processType === "untracked")) {
return true;
}
return false;
};
const newDefs = removeMapKeys(changedDiffs.definitions, (name) => {
if (filterStruct(changedDiffs.definitions?.[name])) {
return false;
}
return true;
});
return {
...changedDiffs,
mods: (changedDiffs?.mods || []).map(mapMod as any).filter((id) => id) as any,
definitions: newDefs,
};
}