{"size": 2673, "ext": "js", "max_stars_repo_path": "dist/storage/rest.js", "max_stars_repo_name": "datavisyn/tdp_core", "max_stars_repo_stars_event_min_datetime": "2017-11-09T15:48:31.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-26T16:38:52.000Z", "max_issues_repo_path": "dist/storage/rest.js", "max_issues_repo_name": "datavisyn/tdp_core", "max_issues_repo_issues_event_min_datetime": "2017-09-01T13:40:23.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-29T13:59:37.000Z", "max_forks_repo_path": "dist/storage/rest.js", "max_forks_repo_name": "datavisyn/tdp_core", "max_forks_repo_forks_event_min_datetime": "2017-11-09T15:50:32.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-19T19:23:14.000Z"}
{"max_stars_count": 4, "max_issues_count": 341, "max_forks_count": 4, "avg_line_length": 46.8947368421, "max_line_length": 142, "alphanum_fraction": 0.6438458661}
import { IDTypeManager, ParseRangeUtils, UserSession, Ajax, AppContext, Permission } from 'phovea_core';
import { RestBaseUtils } from '../base/rest';
import { ENamedSetType } from './interfaces';
export class RestStorageUtils {
    static listNamedSets(idType = null) {
        const args = idType ? { idType: IDTypeManager.getInstance().resolveIdType(idType).id } : {};
        return AppContext.getInstance().getAPIJSON(`${RestStorageUtils.REST_NAMESPACE}/namedsets/`, args).then((sets) => {
            // default value
            sets.forEach((s) => s.type = s.type || ENamedSetType.NAMEDSET);
            return sets;
        });
    }
    static listNamedSetsAsOptions(idType = null) {
        return RestStorageUtils.listNamedSets(idType).then((namedSets) => namedSets.map((d) => ({ name: d.name, value: d.id })));
    }
    static saveNamedSet(name, idType, ids, subType, description = '', sec) {
        const data = Object.assign({
            name,
            type: ENamedSetType.NAMEDSET,
            creator: UserSession.getInstance().currentUserNameOrAnonymous(),
            permissions: Permission.ALL_READ_NONE,
            idType: IDTypeManager.getInstance().resolveIdType(idType).id,
            ids: ParseRangeUtils.parseRangeLike(ids).toString(),
            subTypeKey: subType.key,
            subTypeValue: subType.value,
            description
        }, sec);
        return AppContext.getInstance().sendAPI(`${RestStorageUtils.REST_NAMESPACE}/namedsets/`, data, 'POST');
    }
    static deleteNamedSet(id) {
        return AppContext.getInstance().sendAPI(`${RestStorageUtils.REST_NAMESPACE}/namedset/${id}`, {}, 'DELETE');
    }
    static editNamedSet(id, data) {
        return AppContext.getInstance().sendAPI(`${RestStorageUtils.REST_NAMESPACE}/namedset/${id}`, data, 'PUT').then((s) => {
            s.type = s.type || ENamedSetType.NAMEDSET;
            return s;
        });
    }
    /**
     * get the content of an uploaded attachment
     * @param {string} id the attachment id
     * @returns {Promise<object>} the data
     */
    static getAttachment(id) {
        return AppContext.getInstance().getAPIJSON(`${RestStorageUtils.REST_NAMESPACE}/attachment/${id}`);
    }
    /**
     * uploads an attachment file to the TDP server
     * @param {Object} data
     * @returns {Promise<string>} a promise with the attachment id
     */
    static addAttachment(data) {
        return Ajax.send(AppContext.getInstance().api2absURL(`${RestStorageUtils.REST_NAMESPACE}/attachment/`), data, 'POST', 'text', 'json');
    }
}
RestStorageUtils.REST_NAMESPACE = `${RestBaseUtils.REST_NAMESPACE}/storage`;
//# sourceMappingURL=rest.js.map