telejson icon indicating copy to clipboard operation
telejson copied to clipboard

Option to not replace duplicated objects/arrays/values with "_duplicate_["lorem"]" unless is in a circular dependency

Open robertdumitrescu opened this issue 3 years ago • 4 comments

Well, exactly like my title says, it would be nice to have an option to not replace duplicated objects/arrays and so on unless a circular dependency is detected.

robertdumitrescu avatar Nov 12 '20 01:11 robertdumitrescu

Need more context. Do you have a repro repo you can share?

shilman avatar Nov 12 '20 06:11 shilman

Hey, thanks for getting so quickly back to me.

So I have this config object:

{
    "layout": "pass",
    "level": {
            "weight": 40000,
            "color": "red"
        },
    "minLevelWeight": 40000,
    "levelsDefinitions": {
        "error": {
            "weight": 40000,
            "color": "red"
        },
        "fatal": {
            "weight": 50000,
            "color": "magenta"
        },
        "off": {
            "weight": 1.7976931348623157e+308,
            "color": "grey"
        }
    },
    "logs": [],
    "levelsCollector": {
        "error": [],
        "fatal": [],
        "off": []
    },
    "tagsCollector": {},
    "trackingIdsCollector": {},
    "trackingIds": [],
    "getLocation": true
}

If you put that through

Telejson.stringify(object, {space: 4})

You end up with:

{
    "layout": "pass",
    "level": {
        "weight": 40000,
        "color": "red"
    },
    "minLevelWeight": 40000,
    "levelsDefinitions": {
        "error": "_duplicate_[\"level\"]",
        "fatal": {
            "weight": 50000,
            "color": "magenta"
        },
        "off": {
            "weight": 1.7976931348623157e+308,
            "color": "grey"
        }
    },
    "logs": [],
    "levelsCollector": {
        "error": [],
        "fatal": [],
        "off": []
    },
    "tagsCollector": {},
    "trackingIdsCollector": {},
    "trackingIds": [],
    "getLocation": true
}

Notice the _duplicate_[\"level\"] and that is being replaced in a non-circular dependency context. So, it would be nice to have an option to not replace it with the string, unless is a circular dependency context. That way can be used very easily in unit/integration tests fixtures/assertions.

robertdumitrescu avatar Nov 12 '20 08:11 robertdumitrescu

Any update on this?

robertdumitrescu avatar Jun 04 '22 13:06 robertdumitrescu

Can we at least have a configuration level for this? Basically consider it circular if it repeats more than X times within the same circular path?

robertdumitrescu avatar Nov 06 '23 01:11 robertdumitrescu