There are times I think JavaScript (and Node.js) do deserve their reputation…
(Ok, ok, I don’t, but what is this, really?)
“Date.prototype.toISOString called on incompatible receiver [object Date]”
*smh*
So in case anyone was following this: it appears that built-in objects like Date in JavaScript have some internal magic (read: inconsistencies)* that means you can’t proxy them as you would normally.
More info: https://codeberg.org/small-tech/jsdb/issues/5
Not sure if this is fixable in #JSDB. The “solution” might be to discourage use of Date objects and instead persist timestamps. Which is, quite frankly, a pain in the ass.
I’ll keep looking for a workaround…
* internal slots
Right, implemented workaround for JavaScript’s Proxy / Date object incompatibility in JavaScript Database (JSDB)¹ and released in version 3.0.2².
Calling methods on persisted Date objects read back into memory now works as it should.
Workaround (diff): https://codeberg.org/small-tech/jsdb/commit/9e039e76f7a149df2fa7ecbbf626f813e44c0ab2
3.0.2 update (diff): https://codeberg.org/small-tech/jsdb/commit/f212566f8da4327d0b91d81e8cc6f5058ce63c47
Kudos to Pravin Divraniya for https://stackoverflow.com/a/57958494
¹ https://codeberg.org/small-tech/jsdb
² https://www.npmjs.com/package/@small-tech/jsdb