A big week in the arsd repo

Posted 2019-07-08

I spent the last week writing a lot of D code. My new framework in cgi.d is now operational, though it still isn't quite done (notably, the timing system isn't done yet!). In this post, I'll briefly describe some of the new stuff.

Core D Development Statistics

In the community

Community announcements

See more at the announce forum.

What Adam is working on

If you follow the arsd repo on github, well first, good luck deciphering my absurd commit messages lol, but second, you'll have seen a lot of activity recently. A few new modules have been added, and some existing web stuff got bug fixes and new features.

  • adrdox got some bug fixes, like links from the view source page and some external links breaking in multi-threaded mode.
  • arsd.http2, version 2 my http 1.1 implementation, got support for newer versions of the OpenSSL library, now used by default. Use -version=older_openssl if you still need to link to an older one.
  • arsd.jsvar, my Javascript-like var type for D, and script.d, my little embedded scripting language, got sundry bugfixes. Notably, script.d was missing the ternary operator! lol
  • arsd.dom, my HTML DOM implementation, now has some @scriptable tags, making it more compatible with the aforementioned jsvar and script modules.
  • arsd.database, arsd.postgres, and arsd.sqlite got a few minor additions and bug fixes, mostly to support the new modules.
  • arsd.database_generation is a new module with helper functions to generate database code. Specifically, you can define a bunch of structs with annotations and it generates some basic SQL for them, like create table statements, and other functions can do some select, update, and insert queries, similar to a bare-bones ORM. It uses some amusing hacks to type check stuff passed to it.
    1 struct Foo {
    2 	@PrimaryKey Serial id;
    3 }
    4 struct Bar {
    5 	@PrimaryKey Serial id;
    6 	@ForeignKey!(Foo.id) int foo_id;
    7 	int other;
    8 }
    10 db.find!Foo(1).children!Bar.where!(other => 4).execute(db);
    11 // that lambda over there is syntax abuse, but it checks your name at least!
  • arsd.webtemplate is a new module that combines arsd.dom and arsd.script in support of arsd.cgi.
    1 <main>
    2 	<p>This is my <%= name %> template.</p>
    3 	<for-each over="items" as="item">
    4 		<%= item.value %>
    5 	</for-each>
    6 </main>
  • And, of course, the biggest changes are in arsd.cgi, with my new web framework actually starting to come together. I've spent fairly little time on the REST object stuff, instead focusing on getting the ApiObject bits to functionality in support of my new project.

    It can now automatically pass Cgi and Session!T objects to functions as-needed. You can define your own types to get this treatment too, or do @ifCalledFromWeb!func on individual parameters to always set them to a particular value if called from the web. The idea here is to encourage you to write more functional style code which is usable from the web as well as from other parts of the code directly for easy reuse and testing.

    Speaking of testing, arsd.cgi.CgiTester is a helper class for issuing mock requests with mock sessions to a request handler. Using this and dom.d, I made a recursive auto-tester for my new project in under one screen of code!

    The session server now also works on non-Linux posix systems, though not super well (I just replaced epoll with poll on those systems. My goal here was to make it work for individual developers testing on their own machines rather than anything resembling production, and this is good enough for that, so it will probably stay this way for a long time.)

    The arsd.cgi.WebPresenter class is also growing into actual use. Its exception handling gives a fairly usable screen, highlighting on the information that a developer will most likely need, and being expandable - like with the new webtemplate objects.

There's still a lot for me to do on all this, but it was nice to spend a week actually on D again!

I tend to work in bursts punctuating long lulls, so I don't know when I'll get back to do another big push like this, but hopefully I'll at least have time to write more details about it all next week.