toad.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
Mastodon server operated by David Troy, a tech pioneer and investigative journalist addressing threats to democracy. Thoughtful participation and discussion welcome.

Administered by:

Server stats:

227
active users

#jsdb

0 posts0 participants0 posts today

👋🤓 Goodbye Site.js, Hello Kitten!

I started working on creating a Small Web¹ server (a peer-to-peer Web server) six years ago² with Site.js.

Building Site.js was my first attempt. And it resulted in:

• Auto Encrypt (automatic Let’s Encrypt certificates): codeberg.org/small-tech/auto-e

• Auto Encrypt Localhost (automatic localhost TLS certificates): codeberg.org/small-tech/auto-e

• @small-tech/https (drop-in Node.js https module replacement with automatic TLS certs everywhere): codeberg.org/small-tech/https

• JSDB: In-process, in-memory JavaScript database that persists to append-only JavaScript logs: codeberg.org/small-tech/jsdb

As Site.js reached an evolutionary dead-end, and as I learned from my experiements with replicated data types that replicated data types are *not* a prerequisite for a decentralised web (actual topological decentralisation and ease of use are), I started writing a new server/platform called Kitten from scratch while still making use of the tried and tested modules listed above.

Last week, I switched over our last site using Site.js to Kitten and, with that, today I’ve sunset³ Site.js:

sitejs.org

For its successor, please see Kitten:

kitten.small-web.org

If you want to support our work at the Small Technology Foundation, please consider becoming a patron:

small-tech.org/fund-us

:kitten:💕

¹ ar.al/2024/06/24/small-web-com
² ar.al/2019/08/26/introducing-s
³ Using our instance of Look Over There!: look-over-there.small-web.org

🔒 New Kitten & JSDB Releases

Security fix, JSDB 6.0.1.

This is a critical update.

• JSDB¹ versions 6.0.0 and below suffer from potential data corruption/arbitrary code execution as string keys were not being sanitised in the same way string values were² (so this is relevant to you if you’re storing untrusted data as keys in your data structures in JSDB and/or Kitten databases without carrying out any of your own sanitisation at the application level).

• The latest Kitten release uses JSDB version 6.0.1. Your deployment servers will automatically update in the next few hours. On your development machines, please run `kitten update` in your terminal or use the Update feature in Kitten Settings from your browser.

• If you are using Kitten’s Database App Modules³ feature in your apps, you will have installed JSDB manually and you should update your installation to version 6.0.1.

¹ codeberg.org/small-tech/jsdb/
² codeberg.org/small-tech/jsdb/i
³ kitten.small-web.org/reference

Codeberg.orgjsdbA zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to a JavaScript transaction log.

New Kitten release

• Fixes #236¹: The data preview pages in Kitten’s settings how handle circular references in the deserialised data (which may contain your custom classes if that’s what you were persisting in the database).

kitten.small-web.org

:kitten:💕

PS. Those pages are very rudimentary at the moment and are good for getting quick visual overview of the data you’re persisting. For a fully interactive view, use Kitten’s interactive shell (REPL)² to explore your data until I’ve had a chance to implement a more comprehensive visual interface.

PPS. You persist data in Kitten using the built-in JavaScript Database (JSDB)³ (Or, of course, you can install and use any other database.)

¹ codeberg.org/kitten/app/issues
² kitten.small-web.org/reference
³ codeberg.org/small-tech/jsdb#j

While working on porting the Small Technology Foundation web site¹ to Kitten², I took the opportunity to pull out base Model and Collection classes that I’ll likely end up including in Kitten proper:

• Model: codeberg.org/small-tech/site/s
• Collection: codeberg.org/small-tech/site/s

To see them in use, here’s the base Posts class (with RSS generation) that extends Collection:
codeberg.org/small-tech/site/s

And here’s the concrete EventPosts collection class that extends Posts:
codeberg.org/small-tech/site/s

And the EventPost (showing an implementation of a calculated property):
codeberg.org/small-tech/site/s

So all this is possible (persisting and reading back typed model collections, etc.) thanks to JSDB¹ (JavaScript database), a zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database I wrote for the Small Web that persists to a JavaScript transaction log and is included as as first-class citizen in Kitten.

codeberg.org/small-tech/jsdb

And if you want to know how the magic mapping of classes happens, see the Database App Module:

codeberg.org/small-tech/site/s

PS. For a much gentler introduction to persistence in Kitten, see the Kitten Persistence tutorial:
kitten.small-web.org/tutorials

Enjoy! :kitten:💕

¹ small-tech.org
² kitten.small-web.org

Your web server having an interactive shell (REPL) where you can live update entries in your site/app’s database is pretty neat (if I do say so myself) :)

kitten.small-web.org/reference

(I’m porting the Small Technology Foundation site¹ from Site.js² – and hence from being a static site generated via Site.js’s integrated Hugo³ – to Kitten⁴. In the process, I’m creating an admin panel⁵ for the news, events, and videos sections, which will make them easier to update, and storing the data in Kitten’s internal JavaScript Database⁶.)

¹ small-tech.org
² sitejs.org
³ gohugo.io/
kitten.small-web.org
⁵ It’s trivial to create authenticated routes in Kitten. You just add a lock emoji (🔒) to the end of your route’s name. e.g., admin🔒.page.js or /admin🔒/index.page.js (see kitten.small-web.org/reference).
codeberg.org/small-tech/jsdb

#Kitten#REPL#shell

Just updated the Database App Modules tutorial in the Kitten documentation to fix a few bugs, update to latest Kitten syntax, and improve the instructions:

kitten.small-web.org/tutorials

(Database app modules are special app modules¹ that let you create strongly-typed JavaScript databases² in your Small Web³ apps.)

Enjoy!

:kitten:💕

¹ kitten.small-web.org/reference
² codeberg.org/small-tech/jsdb#r
³ ar.al/2024/06/24/small-web-com

JSDB 6.0.0 released 🎉

Breaking change: Removes Symbol support…

… since we can’t properly serialise/deserialise symbols. Likely, this will not affect anyone as it’s so niche but it’s a major version bump anyway.

Also, the removal of Symbol support fixes a crash that occurs if you persist objects that extend EventEmitter when calling their removeAllListeners() methods. That’s much more important ;)

Full details: codeberg.org/small-tech/jsdb/s

Codeberg.orgjsdb/CHANGELOG.md at mainjsdb - A zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to a JavaScript transaction log.
Continued thread

… JSDB, by the way, is short for JavaScript Database, which is, umm, a JavaScript database.

It’s an in-process, in-memory database for Node.js for Small Web use that persists to an append-only JavaScript – not JSON, JavaScript – transaction log.

JSDB’s very easy to work with because you just use native JavaScript objects and they just automatically get persisted for you.

e.g., Here’s a quick 6-line Kitten app that persists a counter:

codeberg.org/kitten/app#using-

Just deployed a new Kitten¹ version 🎉

• Adds database backup and restore in your app’s Kitten settings page (/💕/settings)

• Upgrades version of JSDB from 4 to 5²

• You can emit and listen for events on the session object you get from `request.session` in your routes now.

¹ codeberg.org/kitten/app
² For migration notes, please see: codeberg.org/small-tech/jsdb#m

Watching The Doors live at The Hollywood Bowl (1968)¹ and hacking on Kitten² and Domain³.

All in all, not a bad way to spend a Saturday afternoon in my book.

(I’ve almost got database backup/restore working in Kitten and I’ve just finished porting Domain to the latest Kitten with JSDB 5⁴.)

¹ yewtu.be/watch?v=Q76QBhKHQGc
² codeberg.org/kitten/app
³ codeberg.org/domain/app
codeberg.org/small-tech/jsdb

Assign properties in a constructor’s parameter object (with defaults) to object being instantiated in JavaScript

codeberg.org/aral/gists/src/br

This is a little something I ended up playing around with this morning before figuring out how to do it (after spending far too much time down a rabbit hole with object destructuring when what I really needed was creative use of the spread operator).

(Useful for custom objects in JSDB 5 – codeberg.org/small-tech/jsdb#c)

Codeberg.orggists/assign-properties-in-a-constructors-parameter-object-with-defaults-to-object-being-instantiated-in-JavaScript.md at maingists - A place for me to post and share small, self-contained code snippets.
Continued thread

To really drive home the above 👆 point that 100% test coverage does not mean ‘bug free’, just found a bug in JSDB¹ 5.0.0 where running JSON.stringify() on a complex custom object (actually: the automatic Proxy of the custom object created by JSDB) results in an error.

Already have a failing test and about to implement fix.

(It’s at this point where the test harness is invaluable.)

¹ codeberg.org/small-tech/jsdb

Codeberg.orgjsdbA zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to a JavaScript transaction log.
Continued thread

Philosophically, JSDB – which writes out to native JavaScript logs – is very much the JavaScript version of SWX, the native data format for Flash that I released around 2007 (where data was written out in native SWF format). I have to say that I’m glad I didn’t have to reverse engineer SWF bytecode this time around :)

Here’s a video of a younger me doing an impromptu demo of SWX at some conference or other from 16 years ago.

m.youtube.com/watch?v=OM9qOADs

JSDB 5.0.0 published 🎉

• Custom classes must have a `constructor` that accepts a parameter object as its only argument. Constructors are run during deserialisation.

• Custom classes can now safely extend other classes (e.g., `EventEmitter`).

• Properties that begin with an underscore (`_`) are treated as private and ignored.

• Objects with null prototypes are supported. i.e., objects created with `Object.create(null, …)`.

Full details: codeberg.org/small-tech/jsdb#m

Codeberg.orgjsdbA zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to a JavaScript transaction log.

100% test coverage doesn’t mean your code’s bug free but it did just lead me to find and fix an issue in JavaScript Database (JSDB)¹ with a code path that wasn’t being hit that I would have otherwise missed because it was causing the relevant test to pass.

¹ JSDB is a zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to a JavaScript transaction log (an append-only log).

codeberg.org/small-tech/jsdb

Codeberg.orgjsdbA zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to a JavaScript transaction log.

Realised last night that JavaScript Database (JSDB) doesn’t run the constructor on persisted custom objects (codeberg.org/small-tech/jsdb#c) when deserialising them because I didn’t know that you apparently have to define your constructor manually when using Object.create().

Will fix it today but it’s something to watch out for if you’re using Object.create() directly.

For more info, see developer.mozilla.org/en-US/do

Codeberg.orgjsdbA zero-dependency, transparent, in-memory, streaming write-on-update JavaScript database for the Small Web that persists to a JavaScript transaction log.