pomdtr
Markdown to html (with github styling)
Extract vals infos (author, name, version) from a val url (either from esm.town
or val.town
).
Example usage:
const {owner, name} = extractValInfo(import.meta.url)
Also returns a unique slug for the val: <author>/<name>
HTTP Client
Attach a postman-like http client to your vals, with bookmarks and history support
Usage
Wrap your http handler in an the httpClient middleware.
Create valimport {httpClient} from "https://esm.town/v/pomdtr/http_client"
export default httpClient((req) => {
return new Response("Hello World!")
})
The http client will be shown on the root.
Adding bookmarks
You might want to bookmark some requests you need often. You can do it by passing a bookmark list as a middleware option:
Create valimport {httpClient} from "https://esm.town/v/pomdtr/http_client"
export default httpClient((req) => {
return new Response("Hello World!")
}, {
bookmarks: [
{
"label": "Dummy Request",
"request": new Request("https://dummyjson.com/products")
}
]})
Customizing the client path
Create valimport {httpClient} from "https://esm.town/v/pomdtr/http_client"
export default httpClient((req) => {
return new Response("Hello World!")
}, {
path: "/http-client"
})
TODO
- fix syntax highlighting on successive request
- allow to prefill the initial request
SQL Template Tag
Port of blakeembrey/sql-template-tag for usage in val.town.
Usage
import { sqlite } from "https://esm.town/v/std/sqlite"
import { sql, zip } from "https://esm.town/v/pomdtr/sql"
const query = sql`SELECT * FROM books WHERE author = ${author}`;
console.log(query.sql) // => "SELECT * FROM books WHERE author = ?"
console.log(query.args) // => [author]
const res = await sqlite.execute(query)
console.table(zip(res))
For advanced usage (ex: nesting queries), refer to the project readme.
Val Town Adapter for lowdb
@std/blob is used as a lowdb sync.
See @pomdtr/lowdb_example for example usage.
Generate a sunbeam form from a val
sunbeam fetch 'https://pomdtr-valform.express.val.run/pomdtr.add' | sunbeam
CodeMirror Web Component
Available Attributes
- language
- readonly
- code
- theme
API
You can access the code using the code
property:
Val Town CDN
If you only want to get the source of a val, you should use https://esm.town/ instead.
Usage
curl https://pomdtr-cdn.web.val.run/<author>/<name>.<extension>[?v=<version>]
To see the code of this val, use https://pomdtr-cdn.web.val.run/pomdtr/cdn.ts
Examples
Fetching the val code
$ curl https://pomdtr-cdn.web.val.run/pomdtr/add.tsx
You can also use js
, jsx
and ts
extension (only the content-type change, there is no transpilation).
Fetching private val
Pass an api token as an username
$ curl "https://<token>@pomdtr-cdn.web.val.run/pomdtr/privateVal.ts"
Fetching the val README
$ curl https://pomdtr-cdn.web.val.run/pomdtr/add.md
Getting an image
$ curl https://pomdtr-cdn.web.val.run/pomdtr/add.png
Fetching a specific version of a val
$ curl https://pomdtr-cdn.web.val.run/pomdtr/cdn.ts?v=66
You need to be authenticated to use this method.
Fetching the val metadata
$ curl https://pomdtr-cdn.web.val.run/pomdtr/add.json
Test Explorer
Click on the play button next to list items to run them.
Usage
-
Fork this val
-
Create new tests in any of vals (and export them) (see @pomdtr/example_test)
Create valimport { assertEquals } from "https://deno.land/std@0.216.0/assert/mod.ts";
import { Test } from "https://esm.town/v/<account>/test_explorer";
export const exampleTestSuccess = new Test(() => {
assertEquals(1 + 1, 2);
});
export const exampleTestFailure = new Test(() => {
assertEquals(1 + 1, 3);
});
- Go to
https://<account>-test_explorer.web.val.run
to run your test- click on the val name to go to the val the tests are originating from
- click on the test name to run it
ℹ️ You probably want to protect your test explorer behind an authentication middleware like @pomdtr/basicAuth
Discovery mechanism
In order to define a test, the user need to import the Test class from https://val.town/v/<account>/Test
.
So we can use the api to search for vals containing the https://val.town/v/<account>/Test
string to locate the vals containing tests.
Next, we need to extract the tests from the val exports. We use exported instanceof Test
to filter them (at some point we will probably use static analysis for this).
TODO
- persist test results in sqlite
- Improve styling (help welcome ❤️)
- View logs in a modal
- Batch http requests
Val Town Basic Auth
Add basic auth on top of any http val
Usage
Wrap your HTTP handler in the basicAuth
middleware.
import { basicAuth } from "https://esm.town/v/pomdtr/basicAuth";
function handler(req: Request) {
return new Response("You are authenticated!");
}
export default basicAuth(handler);
To authenticate, paste an api token in the password prompt.