patwasalinguist
patwasalinguist
Explore posts from servers
DDeno
Created by patwasalinguist on 8/29/2023 in #help
Deno KV: Should I expect 'value too large' errors inserting a JSON file with kv.set?
I was trying out kv and quickly ran into something I found surprising;
let kv = await Deno.openKv('omg.db')

let hieroglyphsJSON = await Deno.readTextFile('./hieroglyphs.json')
let hieroglyphs = JSON.parse(hieroglyphsJSON)

kv.set(["hieroglyphs"], hieroglyphs)
let kv = await Deno.openKv('omg.db')

let hieroglyphsJSON = await Deno.readTextFile('./hieroglyphs.json')
let hieroglyphs = JSON.parse(hieroglyphsJSON)

kv.set(["hieroglyphs"], hieroglyphs)
hieroglyphs.json is not huge (360K), and yet I get this error:
$ deno run --unstable --allow-write --allow-read kv.js
error: Uncaught (in promise) TypeError: value too large (max 65536 bytes)
kv.set(["hieroglyphs"], hieroglyphs)
^
at Kv.set (ext:deno_kv/01_db.ts:87:41)
at file:///Users/me/kv.js:8:4
at eventLoopTick (ext:core/01_core.js:183:11)
$ deno run --unstable --allow-write --allow-read kv.js
error: Uncaught (in promise) TypeError: value too large (max 65536 bytes)
kv.set(["hieroglyphs"], hieroglyphs)
^
at Kv.set (ext:deno_kv/01_db.ts:87:41)
at file:///Users/me/kv.js:8:4
at eventLoopTick (ext:core/01_core.js:183:11)
I feel like I’m missing something obvious; am I trying to do something kv wasn’t designed for? TIA
6 replies
DDeno
Created by patwasalinguist on 5/29/2023 in #help
Possible to deploy the chat example to deno deploy?
I would like to try running this demo on deno deploy: https://deno.com/[email protected]/examples/chat_app However, I have seen somewhere that deploy doesn't suport websockets. Is this currently the case? Is it possbile to run this with deploy? thanks
10 replies
DDeno
Created by patwasalinguist on 5/12/2023 in #help
Checking for circular module dependencies?
Hi, I’m wondering if there is some way to detect whether there are circular dependencies in a set of modules. Ideally, it might look something like this:
let detectCircularDependencies = fileNames => { … }

// then i'd call

detectCircularDependencies('./a.js', './b.js', './c.js')
Circular dependency found: a.js > b.js > c.js > a.js
let detectCircularDependencies = fileNames => { … }

// then i'd call

detectCircularDependencies('./a.js', './b.js', './c.js')
Circular dependency found: a.js > b.js > c.js > a.js
Or something like that.
1 replies
DDeno
Created by patwasalinguist on 5/9/2023 in #help
Is inspecting import.meta.url a reliable way to distinguish browser and deno contexts?
I have been trying to figure out a good pattern to import JSON that will work whether called in deno or the browser. This is what I was thinking:
let data

if(import.meta.url.startsWith('file')){ // we’re in deno
let jsonstring = await Deno.readTextFile('delete.json')
data = JSON.parse(jsonstring)
} else if(import.meta.url.startsWith('http')){ // we’re in the browser
let response = await fetch('delete.json')
data = await response.json()
}

export {data}
let data

if(import.meta.url.startsWith('file')){ // we’re in deno
let jsonstring = await Deno.readTextFile('delete.json')
data = JSON.parse(jsonstring)
} else if(import.meta.url.startsWith('http')){ // we’re in the browser
let response = await fetch('delete.json')
data = await response.json()
}

export {data}
I would welcome advice as to whether this is a good approach to this problem. thanks 🙏
11 replies