"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchVersions = searchVersions;
const arcgis_rest_portal_1 = require("@esri/arcgis-rest-portal");
const versionMetadataFromResource_1 = require("./_internal/versionMetadataFromResource");
/**
 * Returns an array containing the versions of the specified item
 * @param id
 * @param requestOptions
 * @returns
 */
async function searchVersions(id, requestOptions) {
    const resources = await (0, arcgis_rest_portal_1.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_1.versionMetadataFromResource));
}
//# sourceMappingURL=searchVersions.js.map