ARK-Builders / ark-core

The core of the ARK framework
MIT License
4 stars 4 forks source link

`fs-storage`: Update FileStorage format #38

Closed kirillt closed 6 months ago

kirillt commented 6 months ago

We have mixed format now:

$ cargo run --example cli write /tmp/test a:1,b:2

$ cat /tmp/test | jq
version 2
{"a":"1","b":"2"}

This makes the format not so ergonomic, power users need to perform extra step to remove the header:

$ tail -1 /tmp/test | jq 
{
  "a": "1",
  "b": "2"
}

It's better to complete transition to JSON.

Option 1: "Flat syntax"

If we declare version in the mapping itself, we'd need to handle it as a special field before reading the entries:

{
    "a":"1",
    "b":"2",
    "version":"3"
}

Can it cause problems when we expect non-string keys in the storage? E.g. with the following storage:

{
    "1":"a",
    "2":"b",
    "version":"3"
}

Option 2: "Nested syntax"

We can use the nested JSON structure, where top-level always consists of 2 fields: version, and entries. The latter lists all key-values inside:

{
    "version":"3",
    "entries": {
        "1":"a",
        "2":"b"
    }
}

This format is explicit, no type inconsistencies but the format is more verbose.

tareknaser commented 6 months ago

I prefer the second option, nested syntax. It seems very clear to me also a user might include a key-value pair where the key is the word "version"

tareknaser commented 6 months ago

It'll also make data extraction easier since we won't have to exclude the entry with the key "version"