import { getItemResources } from "@esri/arcgis-rest-portal";
import { versionMetadataFromResource } from "./_internal/versionMetadataFromResource";
/**
 * Returns an array containing the versions of the specified item
 * @param id
 * @param requestOptions
 * @returns
 */
export async function searchVersions(id, requestOptions) {
    const resources = await getItemResources(id, Object.assign(Object.assign({}, requestOptions), { params: { sortField: "created", sortOrder: "desc" } }));
    // the resources api does not support q - so we fetch all of them and do the filtering here
    return (resources.resources
        // filter out any that do not look like hubVersion_<id>/version.json
        .filter((resource) => resource.resource.match(/^hubVersion_[a-zA-Z0-9_\s]*\/version.json/))
        // transform the resouce into a version metadata object
        .map(versionMetadataFromResource));
}
//# sourceMappingURL=searchVersions.js.map