Open History to see the last commit
1// Disposable local visual fixture. Never imported by the deployed entry point.
2import { PGlite } from "@electric-sql/pglite";
3import { serve } from "@hono/node-server";
4import { loadWebAssets } from "./web-assets.js";
5import { readFile } from "node:fs/promises";
6import { randomUUID } from "node:crypto";
7import { createApp } from "../src/app.js";
8import { ingest, type Database } from "../src/database.js";
9import { recordSchema } from "../src/protocol.js";
10const pg = new PGlite();
11await pg.exec(await readFile("migrations/001_jol.sql", "utf8"));
12const db: Database = {
13 query: (s, v) => pg.query(s, v),
14 transaction: (f) =>
15 pg.transaction((q) => f({ query: (s, v) => q.query(s, v) })),
16};
17const device = randomUUID(),
18 exp = randomUUID(),
19 photo = randomUUID() + ".jpg",
20 authURL = "https://fixture.example/neondb/auth";
21await db.query(
22 "INSERT INTO jol_devices(id,owner_id,name,credential_hash,remote_enabled,last_seen) VALUES($1,$2,'My Mac','fixture',true,now())",
23 [device, authURL + "|preview-user"],
24);
25const make = (event: string, rest: object) =>
26 recordSchema.parse({
27 version: 1,
28 id: randomUUID(),
29 date: Date.now(),
30 event,
31 ...rest,
32 });
33await ingest(db, device, exp, 1, [
34 make("created", {
35 expedition: {
36 id: exp,
37 date: Date.now(),
38 title: "The Paper Cliffs of Possibility",
39 },
40 }),
41 make("entry", {
42 entry: {
43 id: randomUUID(),
44 date: Date.now(),
45 kind: "request",
46 text: "Open a new document and write a small poem about your adventure.",
47 details: "",
48 },
49 }),
50 make("entry", {
51 entry: {
52 id: randomUUID(),
53 date: Date.now(),
54 kind: "response",
55 text: "I found the document window tucked beneath a rather impressive toolbar. A short climb, a careful landing, and I’m ready to put pen to paper.",
56 details:
57 "Observed the active document window. The next physical action is to reach its text area.",
58 },
59 }),
60 make("entry", {
61 entry: {
62 id: randomUUID(),
63 date: Date.now(),
64 kind: "activity",
65 text: "One explorer. A whole desktop of possibility.",
66 details: "Synthetic visual fixture; no screen was captured.",
67 photo,
68 },
69 }),
70 make("entry", {
71 entry: {
72 id: randomUUID(),
73 date: Date.now(),
74 kind: "response",
75 text: "The poem is safely on the page. I shall keep this photograph as proof that even a small explorer can get a little writing done.",
76 details: "",
77 },
78 }),
79 make("state", {
80 status: "Ready for your next direction",
81 isRunning: false,
82 isFinished: false,
83 }),
84]);
85await db.query(
86 "INSERT INTO jol_assets(device_id,expedition_id,filename,object_key) VALUES($1,$2,$3,'fixture-photo')",
87 [device, exp, photo],
88);
89const assets = await loadWebAssets("dist/web-fixture/client");
90const image = await readFile("../Jerry/Resources/AppIcon.png");
91const app = createApp({
92 db,
93 config: {
94 origin: "http://127.0.0.1:8788",
95 instanceID: randomUUID(),
96 name: "JOL preview",
97 authURL,
98 jwksURL: authURL + "/jwks",
99 clientID: "fixture",
100 databaseName: "postgres",
101 },
102 authenticate: async () => ({
103 id: authURL + "|preview-user",
104 expires: Date.now() + 60_000,
105 }),
106 assets,
107});
108serve(
109 {
110 hostname: "127.0.0.1",
111 port: 8788,
112 fetch: (request) =>
113 new URL(request.url).pathname.includes("/photos/")
114 ? new Response(image, { headers: { "Content-Type": "image/png" } })
115 : app.fetch(request),
116 },
117 () => console.log("Disposable JOL preview: http://127.0.0.1:8788"),
118);