{"size": 1106, "ext": "js", "max_stars_repo_path": "dist/util/alloy.js", "max_stars_repo_name": "alloy-js/R2", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "dist/util/alloy.js", "max_issues_repo_name": "alloy-js/R2", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "dist/util/alloy.js", "max_forks_repo_name": "alloy-js/R2", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.9756097561, "max_line_length": 74, "alphanum_fraction": 0.5018083183}
import { AlloyInstance } from 'alloy-ts';
import { relation } from '../core/relation';
import { set } from '../core/set';
function alloyData(instance) {
    instance = typeof instance === 'string'
        ? new AlloyInstance(instance)
        : instance;
    const sets = instance
        .signatures()
        .map((sig) => {
        return {
            id: sig.id(),
            set: set(sig.atoms(true)),
            signature: sig
        };
    });
    const getSet = (signature) => {
        const set = sets.find(set => set.signature === signature);
        if (!set)
            throw Error('Cannot build Alloy dataset: invalid Alloy data');
        return set.set;
    };
    const rels = instance.fields().map((fld) => {
        const types = fld.types().map(getSet);
        const rel = relation(types);
        fld.tuples().forEach((tuple) => {
            rel.add(tuple.atoms());
        });
        return {
            id: fld.id(),
            relation: rel,
            field: fld
        };
    });
    return {
        sets: sets,
        relations: rels
    };
}
export { alloyData };
