How to expose previously used values for a property included in a vault

Is there any function that returns a list with all the previously used values for a given property in my Vault? I have checked the API documentation, but I was not able to find any.

I want to create a QuickAdd macro that suggests those values, but I have not been able to find any function in the API documentation.

I did this. I get all the files from the vault. Then for each file I get the frontamatter from metadataCache. key is the name of the property I need. I put all the values into an array, then remove falsy values and flat the array (if key is a list property you get an array from frontMatter)

function getAllValuesForKey(key: string): string[] {
    const files = this.app.vault.getFiles();
    let values: string[] = [];
    files.forEach((file) => {
        const cache = this.app.metadataCache.getFileCache(file)?.frontmatter;
        values.push(cache?.[key]);
    });

    values = [...new Set(values.filter((v) => !!v).flat())];

    return values;
}

Performance wise is not too bad, it takes a few milliseconds to process a vault almost 600 files