dollarshaveclub / cloudworker

Run Cloudflare Worker scripts locally
MIT License
516 stars 89 forks source link

Can't enter a list of strings as JSON #137

Open ydesai-opendoor opened 4 years ago

ydesai-opendoor commented 4 years ago

I am trying to add a list of strings into the Cloudflare KV Store as json via cloudworker with this command cloudflare --kv-set CONFIG.SAMPLE_CONFIG=["92887"]. When I do this the quotes are stripped so that when I read the Config via CONFIG.get('SAMPLE_CONFIG', 'json'); I am returned [92887] which is a list of ints not strings. I tried escaping the quotes and that didn't work also.

I also tried cloudflare --kv-set CONFIG.SAMPLE_CONFIG=["test"] putting in an actual string that cannot be interpreted as an integer. When doing this reading the config via CONFIG.get('SAMPLE_CONFIG', 'json'); fails because the JSON is not parsable, and reading the value as text via CONFIG.get('SAMPLE_CONFIG', 'json'); returns "[test]" as one string which is not valid json because test is not in quotes.

Is it possible to support list of strings as a valid input into cloudflare KV Store.

ydesai-opendoor commented 4 years ago
SyntaxError: Unexpected token e in JSON at position 2
    at JSON.parse (<anonymous>)
    at KeyValueStore.get (*s/@dollarshaveclub/cloudworker/lib/kv.js:49:37)
    at evalmachine.<anonymous>:3131:44
    at Generator.next (<anonymous>)
    at evalmachine.<anonymous>:2980:71
    at new Promise (<anonymous>)
    at __awaiter (evalmachine.<anonymous>:2976:12)
    at proxyHomesPage (evalmachine.<anonymous>:3124:12)
    at Object.handler (evalmachine.<anonymous>:3511:25)
    at evalmachine.<anonymous>:5116:51

This is the JSON Parse error when I try and call CONFIG.get('SAMPLE_CONFIG', 'json') when SAMPLE_CONFIG is set via cloudflare --kv-set CONFIG.SAMPLE_CONFIG=[\"test\"] the quotes around test I suspect are just getting stripped