diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 4241c17..829d632 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules dist -*~ \ No newline at end of file +*~ +.direnv diff --git a/backend/app.ts b/backend/app.ts index a0e1365..80d8c95 100644 --- a/backend/app.ts +++ b/backend/app.ts @@ -84,7 +84,7 @@ export function createFrontend( app.post("/fake-update", (req, res) => { const instanceId = Array.from(instances.instances.keys())[0]; const instance = instances.instances.get(instanceId); - instance?.webXdc.sendUpdate({ payload: req.body }, "fake update"); + instance?.webXdc.sendUpdate({ payload: req.body }, ""); res.json({ status: "ok", }); diff --git a/backend/instance.ts b/backend/instance.ts index 5a7f57f..d751d86 100644 --- a/backend/instance.ts +++ b/backend/instance.ts @@ -19,7 +19,6 @@ export type Options = { type SendUpdateMessage = { type: "sendUpdate"; update: ReceivedStatusUpdate; - descr: string; }; type SetUpdateListenerMessage = { @@ -125,7 +124,7 @@ export class Instances { const parsed = JSON.parse(msg); // XXX should validate parsed if (isSendUpdateMessage(parsed)) { - instance.webXdc.sendUpdate(parsed.update, parsed.descr); + instance.webXdc.sendUpdate(parsed.update, ""); } else if (isSetUpdateListenerMessage(parsed)) { instance.webXdc.connect( (updates) => { @@ -133,7 +132,7 @@ export class Instances { wss, JSON.stringify({ type: "updates", - updates: updates.map(([update]) => update), + updates: updates.map((update) => update), }), ); }, diff --git a/backend/message.test.ts b/backend/message.test.ts index f6a1ec0..3f462eb 100644 --- a/backend/message.test.ts +++ b/backend/message.test.ts @@ -1,5 +1,6 @@ -import { createProcessor, UpdateDescr } from "./message"; +import { createProcessor } from "./message"; import type { Message } from "../types/message"; +import { ReceivedStatusUpdate } from "@webxdc/types"; // a little helper to let us track messages for testing purposes function track(): [() => Message[], (message: Message) => void] { @@ -19,17 +20,17 @@ test("distribute to self", () => { const processor = createProcessor(onMessage); const client0 = processor.createClient("3001"); - const client0Heard: UpdateDescr[] = []; + const client0Heard: ReceivedStatusUpdate[] = []; client0.connect((updates) => { client0Heard.push(...updates); return true; }, 0); - client0.sendUpdate({ payload: "Hello" }, "update"); + client0.sendUpdate({ payload: "Hello" }, ""); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], + { payload: "Hello", serial: 1, max_serial: 1 }, ]); expect(prepare(getMessages())).toEqual([ @@ -43,13 +44,11 @@ test("distribute to self", () => { serial: 1, max_serial: 1, }, - descr: "update", }, { type: "received", update: { payload: "Hello", serial: 1, max_serial: 1 }, instanceId: "3001", - descr: "update", }, ]); }); @@ -60,8 +59,8 @@ test("distribute to self and other", () => { const client0 = processor.createClient("3001"); const client1 = processor.createClient("3002"); - const client0Heard: UpdateDescr[] = []; - const client1Heard: UpdateDescr[] = []; + const client0Heard: ReceivedStatusUpdate[] = []; + const client1Heard: ReceivedStatusUpdate[] = []; client0.connect((updates) => { client0Heard.push(...updates); @@ -73,15 +72,15 @@ test("distribute to self and other", () => { return true; }, 0); - client0.sendUpdate({ payload: "Hello" }, "update"); - client1.sendUpdate({ payload: "Bye" }, "update 2"); + client0.sendUpdate({ payload: "Hello" }, ""); + client1.sendUpdate({ payload: "Bye" }, ""); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); expect(client1Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); expect(prepare(getMessages())).toEqual([ @@ -93,37 +92,31 @@ test("distribute to self and other", () => { type: "sent", instanceId: "3001", update: { payload: "Hello", serial: 1, max_serial: 1 }, - descr: "update", }, { type: "received", update: { payload: "Hello", serial: 1, max_serial: 1 }, instanceId: "3001", - descr: "update", }, { type: "received", update: { payload: "Hello", serial: 1, max_serial: 1 }, instanceId: "3002", - descr: "update", }, { type: "sent", instanceId: "3002", update: { payload: "Bye", serial: 2, max_serial: 2 }, - descr: "update 2", }, { type: "received", update: { payload: "Bye", serial: 2, max_serial: 2 }, instanceId: "3001", - descr: "update 2", }, { type: "received", update: { payload: "Bye", serial: 2, max_serial: 2 }, instanceId: "3002", - descr: "update 2", }, ]); }); @@ -133,8 +126,8 @@ test("setUpdateListener serial should skip older", () => { const client0 = processor.createClient("3001"); const client1 = processor.createClient("3002"); - const client0Heard: UpdateDescr[] = []; - const client1Heard: UpdateDescr[] = []; + const client0Heard: ReceivedStatusUpdate[] = []; + const client1Heard: ReceivedStatusUpdate[] = []; client0.connect((updates) => { client0Heard.push(...updates); @@ -146,14 +139,14 @@ test("setUpdateListener serial should skip older", () => { return true; }, 1); - client0.sendUpdate({ payload: "Hello" }, "update"); - client0.sendUpdate({ payload: "Bye" }, "update 2"); + client0.sendUpdate({ payload: "Hello" }, ""); + client0.sendUpdate({ payload: "Bye" }, ""); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); expect(client1Heard).toMatchObject([ - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Bye", serial: 2, max_serial: 2 }, ]); }); @@ -163,20 +156,20 @@ test("other starts listening later", () => { const client0 = processor.createClient("3001"); const client1 = processor.createClient("3002"); - const client0Heard: UpdateDescr[] = []; - const client1Heard: UpdateDescr[] = []; + const client0Heard: ReceivedStatusUpdate[] = []; + const client1Heard: ReceivedStatusUpdate[] = []; client0.connect((updates) => { client0Heard.push(...updates); return true; }, 0); - client0.sendUpdate({ payload: "Hello" }, "update"); - client0.sendUpdate({ payload: "Bye" }, "update 2"); + client0.sendUpdate({ payload: "Hello" }, ""); + client0.sendUpdate({ payload: "Bye" }, ""); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); // we only join later, so we haven't heard a thing yet expect(client1Heard).toMatchObject([]); @@ -187,12 +180,12 @@ test("other starts listening later", () => { }, 0); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); expect(client1Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 2 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 2 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); expect(prepare(getMessages())).toEqual([ @@ -202,25 +195,21 @@ test("other starts listening later", () => { type: "sent", instanceId: "3001", update: { payload: "Hello", serial: 1, max_serial: 1 }, - descr: "update", }, { type: "received", update: { payload: "Hello", serial: 1, max_serial: 1 }, instanceId: "3001", - descr: "update", }, { type: "sent", instanceId: "3001", update: { payload: "Bye", serial: 2, max_serial: 2 }, - descr: "update 2", }, { type: "received", update: { payload: "Bye", serial: 2, max_serial: 2 }, instanceId: "3001", - descr: "update 2", }, { type: "connect", instanceId: "3002" }, { type: "clear", instanceId: "3002" }, @@ -228,13 +217,11 @@ test("other starts listening later", () => { type: "received", update: { payload: "Hello", serial: 1, max_serial: 2 }, instanceId: "3002", - descr: "update", }, { type: "received", update: { payload: "Bye", serial: 2, max_serial: 2 }, instanceId: "3002", - descr: "update 2", }, ]); }); @@ -243,20 +230,20 @@ test("client is created later and needs to catch up", () => { const processor = createProcessor(); const client0 = processor.createClient("3001"); - const client0Heard: UpdateDescr[] = []; - const client1Heard: UpdateDescr[] = []; + const client0Heard: ReceivedStatusUpdate[] = []; + const client1Heard: ReceivedStatusUpdate[] = []; client0.connect((updates) => { client0Heard.push(...updates); return true; }, 0); - client0.sendUpdate({ payload: "Hello" }, "update"); - client0.sendUpdate({ payload: "Bye" }, "update 2"); + client0.sendUpdate({ payload: "Hello" }, ""); + client0.sendUpdate({ payload: "Bye" }, ""); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); // we only join later, so we haven't heard a thing yet @@ -269,12 +256,12 @@ test("client is created later and needs to catch up", () => { }, 0); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); expect(client1Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 2 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 2 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); }); @@ -283,19 +270,19 @@ test("other starts listening later but is partially caught up", () => { const client0 = processor.createClient("3001"); const client1 = processor.createClient("3002"); - const client0Heard: UpdateDescr[] = []; - const client1Heard: UpdateDescr[] = []; + const client0Heard: ReceivedStatusUpdate[] = []; + const client1Heard: ReceivedStatusUpdate[] = []; client0.connect((updates) => { client0Heard.push(...updates); return true; }, 0); - client0.sendUpdate({ payload: "Hello" }, "update"); - client0.sendUpdate({ payload: "Bye" }, "update 2"); + client0.sendUpdate({ payload: "Hello" }, ""); + client0.sendUpdate({ payload: "Bye" }, ""); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); // we only join later, so we haven't heard a thing yet expect(client1Heard).toMatchObject([]); @@ -307,11 +294,11 @@ test("other starts listening later but is partially caught up", () => { }, 1); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, ]); expect(client1Heard).toMatchObject([ - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Bye", serial: 2, max_serial: 2 }, ]); }); @@ -470,8 +457,8 @@ test("connect with clear means we get no catchup if no new updates", () => { const processor = createProcessor(); const client0 = processor.createClient("3001"); - const client0Heard: (UpdateDescr | string)[] = []; - const client1Heard: (UpdateDescr | string)[] = []; + const client0Heard: (ReceivedStatusUpdate | string)[] = []; + const client1Heard: (ReceivedStatusUpdate | string)[] = []; client0.connect( (updates) => { @@ -485,16 +472,16 @@ test("connect with clear means we get no catchup if no new updates", () => { }, ); - client0.sendUpdate({ payload: "Hello" }, "update"); - client0.sendUpdate({ payload: "Bye" }, "update 2"); + client0.sendUpdate({ payload: "Hello" }, ""); + client0.sendUpdate({ payload: "Bye" }, ""); // now we clear processor.clear(); expect(client0Heard).toMatchObject([ "cleared", - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, "cleared", ]); @@ -516,8 +503,8 @@ test("connect with clear means we get no catchup if no new updates", () => { expect(client0Heard).toMatchObject([ "cleared", - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, "cleared", ]); expect(client1Heard).toMatchObject(["cleared"]); @@ -528,8 +515,8 @@ test("connect with clear means catchup only with updates after clear", () => { const processor = createProcessor(onMessage); const client0 = processor.createClient("3001"); - const client0Heard: (UpdateDescr | string)[] = []; - const client1Heard: (UpdateDescr | string)[] = []; + const client0Heard: (ReceivedStatusUpdate | string)[] = []; + const client1Heard: (ReceivedStatusUpdate | string)[] = []; client0.connect( (updates) => { @@ -543,20 +530,20 @@ test("connect with clear means catchup only with updates after clear", () => { }, ); - client0.sendUpdate({ payload: "Hello" }, "update"); - client0.sendUpdate({ payload: "Bye" }, "update 2"); + client0.sendUpdate({ payload: "Hello" }, ""); + client0.sendUpdate({ payload: "Bye" }, ""); processor.clear(); // the aftermath update, which the newly connecting client should get - client0.sendUpdate({ payload: "Aftermath" }, "update 3"); + client0.sendUpdate({ payload: "Aftermath" }, ""); expect(client0Heard).toMatchObject([ "cleared", - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, "cleared", - [{ payload: "Aftermath", serial: 1, max_serial: 1 }, "update 3"], + { payload: "Aftermath", serial: 1, max_serial: 1 }, ]); // we only join later, so we haven't heard a thing yet @@ -577,14 +564,14 @@ test("connect with clear means catchup only with updates after clear", () => { expect(client0Heard).toMatchObject([ "cleared", - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], - [{ payload: "Bye", serial: 2, max_serial: 2 }, "update 2"], + { payload: "Hello", serial: 1, max_serial: 1 }, + { payload: "Bye", serial: 2, max_serial: 2 }, "cleared", - [{ payload: "Aftermath", serial: 1, max_serial: 1 }, "update 3"], + { payload: "Aftermath", serial: 1, max_serial: 1 }, ]); expect(client1Heard).toMatchObject([ "cleared", - [{ payload: "Aftermath", serial: 1, max_serial: 1 }, "update 3"], + { payload: "Aftermath", serial: 1, max_serial: 1 }, ]); expect(getMessages()).toMatchObject([ @@ -594,38 +581,32 @@ test("connect with clear means catchup only with updates after clear", () => { type: "sent", instanceId: "3001", update: { payload: "Hello", serial: 1, max_serial: 1 }, - descr: "update", }, { type: "received", update: { payload: "Hello", serial: 1, max_serial: 1 }, instanceId: "3001", - descr: "update", }, { type: "sent", instanceId: "3001", update: { payload: "Bye", serial: 2, max_serial: 2 }, - descr: "update 2", }, { type: "received", update: { payload: "Bye", serial: 2, max_serial: 2 }, instanceId: "3001", - descr: "update 2", }, { type: "clear", instanceId: "3001" }, { type: "sent", instanceId: "3001", update: { payload: "Aftermath", serial: 1, max_serial: 1 }, - descr: "update 3", }, { type: "received", update: { payload: "Aftermath", serial: 1, max_serial: 1 }, instanceId: "3001", - descr: "update 3", }, { type: "connect", instanceId: "3002" }, { type: "clear", instanceId: "3002" }, @@ -633,7 +614,6 @@ test("connect with clear means catchup only with updates after clear", () => { type: "received", instanceId: "3002", update: { payload: "Aftermath", serial: 1, max_serial: 1 }, - descr: "update 3", }, ]); }); @@ -644,8 +624,8 @@ test("distribute to self and other, but other was disconnected", () => { const client0 = processor.createClient("3001"); const client1 = processor.createClient("3002"); - const client0Heard: UpdateDescr[] = []; - const client1Heard: UpdateDescr[] = []; + const client0Heard: ReceivedStatusUpdate[] = []; + const client1Heard: ReceivedStatusUpdate[] = []; client0.connect((updates) => { client0Heard.push(...updates); @@ -657,9 +637,9 @@ test("distribute to self and other, but other was disconnected", () => { return false; }, 0); - client0.sendUpdate({ payload: "Hello" }, "update"); + client0.sendUpdate({ payload: "Hello" }, ""); expect(client0Heard).toMatchObject([ - [{ payload: "Hello", serial: 1, max_serial: 1 }, "update"], + { payload: "Hello", serial: 1, max_serial: 1 }, ]); expect(client1Heard).toMatchObject([]); @@ -672,13 +652,11 @@ test("distribute to self and other, but other was disconnected", () => { type: "sent", instanceId: "3001", update: { payload: "Hello", serial: 1, max_serial: 1 }, - descr: "update", }, { type: "received", update: { payload: "Hello", serial: 1, max_serial: 1 }, instanceId: "3001", - descr: "update", }, ]); }); @@ -747,7 +725,7 @@ test("instanceColor", () => { return true; }, 0); - client0.sendUpdate({ payload: "Hello" }, "update"); + client0.sendUpdate({ payload: "Hello" }, ""); const instanceColors = getMessages().map((message) => message.instanceColor); expect(instanceColors).toEqual([ @@ -789,7 +767,7 @@ test("timestamp", async () => { await waitFor(10); - client0.sendUpdate({ payload: "Hello" }, "update"); + client0.sendUpdate({ payload: "Hello" }, ""); await waitFor(10); diff --git a/backend/message.ts b/backend/message.ts index 573ab89..cab5fc2 100644 --- a/backend/message.ts +++ b/backend/message.ts @@ -6,9 +6,7 @@ import type { import type { Message } from "../types/message"; import { getColorForId } from "./color"; -type UpdateListenerMulti = ( - updates: [ReceivedStatusUpdate, string][], -) => boolean; +type UpdateListenerMulti = (updates: ReceivedStatusUpdate[]) => boolean; type ClearListener = () => boolean; type DeleteListener = () => boolean; @@ -25,8 +23,6 @@ export type WebXdcMulti = { sendUpdate: Webxdc["sendUpdate"]; }; -export type UpdateDescr = [ReceivedStatusUpdate, string]; - export type OnMessage = (message: Message) => void; export interface IProcessor { @@ -46,8 +42,8 @@ class Client implements WebXdcMulti { public id: string, ) {} - sendUpdate(update: SendingStatusUpdate, descr: string): void { - this.processor.distribute(this.id, update, descr); + sendUpdate(update: SendingStatusUpdate, _descr: ""): void { + this.processor.distribute(this.id, update); } connect( @@ -74,17 +70,16 @@ class Client implements WebXdcMulti { } return hasReceived; }); - const updateListener = (updates: UpdateDescr[]) => { + const updateListener = (updates: ReceivedStatusUpdate[]) => { const hasReceived = listener(updates); if (hasReceived) { - for (const [update, descr] of updates) { + for (const update of updates) { this.processor.onMessage({ type: "received", update: update, instanceId: this.id, instanceColor: getColorForId(this.id), timestamp: Date.now(), - descr, }); } } @@ -102,7 +97,7 @@ class Client implements WebXdcMulti { this.clear(); } - receiveUpdate(update: ReceivedStatusUpdate, descr: string) { + receiveUpdate(update: ReceivedStatusUpdate) { if (this.updateListener == null || this.updateSerial == null) { return; } @@ -110,7 +105,7 @@ class Client implements WebXdcMulti { if (update.serial <= this.updateSerial) { return; } - this.updateListener([[update, descr]]); + this.updateListener([update]); } clear() { @@ -136,7 +131,7 @@ class Client implements WebXdcMulti { class Processor implements IProcessor { clients: Client[] = []; currentSerial: number = 0; - updates: UpdateDescr[] = []; + updates: ReceivedStatusUpdate[] = []; clearInstanceIds: Set = new Set(); constructor(public onMessage: OnMessage) {} @@ -153,28 +148,23 @@ class Processor implements IProcessor { this.clients.splice(client_index, 1); } - distribute( - instanceId: string, - update: SendingStatusUpdate, - descr: string, - ) { + distribute(instanceId: string, update: SendingStatusUpdate) { this.currentSerial++; const receivedUpdate: ReceivedStatusUpdate = { ...update, serial: this.currentSerial, max_serial: this.updates.length + 1, }; - this.updates.push([receivedUpdate, descr]); + this.updates.push(receivedUpdate); this.onMessage({ type: "sent", instanceId: instanceId, instanceColor: getColorForId(instanceId), update: receivedUpdate, timestamp: Date.now(), - descr, }); for (const client of this.clients) { - client.receiveUpdate(receivedUpdate, descr); + client.receiveUpdate(receivedUpdate); } } @@ -192,10 +182,7 @@ class Processor implements IProcessor { updateListener( this.updates .slice(serial) - .map(([update, descr]) => [ - { ...update, max_serial: maxSerial }, - descr, - ]), + .map((update) => ({ ...update, max_serial: maxSerial })), ); } } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e7ea89c --- /dev/null +++ b/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1731676054, + "narHash": "sha256-OZiZ3m8SCMfh3B6bfGC/Bm4x3qc1m2SVEAlkV6iY7Yg=", + "rev": "5e4fbfb6b3de1aa2872b76d49fafc942626e2add", + "revCount": 708622, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.708622%2Brev-5e4fbfb6b3de1aa2872b76d49fafc942626e2add/0193363c-ab27-7bbd-af1d-3e6093ed5e2d/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.%2A.tar.gz" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f32f02c --- /dev/null +++ b/flake.nix @@ -0,0 +1,20 @@ +{ + description = "A Nix-flake-based Node.js development environment"; + + inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; + + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in + { + devShells = forEachSupportedSystem ({ pkgs }: { + default = pkgs.mkShell { + packages = with pkgs; [ nodejs nodePackages.typescript-language-server ]; + }; + }); + }; +} diff --git a/package-lock.json b/package-lock.json index 2f95e6c..dd434f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "@types/node": "^18.0.0", "@types/node-fetch": "^2.6.2", "@types/wait-on": "^5.3.1", - "@webxdc/types": "^2.0.0", + "@webxdc/types": "^2.0.1", "babel-loader": "^8.2.5", "babel-preset-solid": "~1.5.0", "concurrently": "^7.2.2", @@ -3759,10 +3759,11 @@ } }, "node_modules/@webxdc/types": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@webxdc/types/-/types-2.0.0.tgz", - "integrity": "sha512-gtddNq2PsUZZwESXOjpI3sHG185fm7QXEolm9sWVIM1iV0sD4Zs8jLL1MKjuYn04/WuX8jVDKDGBDv4qLimhlA==", - "dev": true + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@webxdc/types/-/types-2.1.2.tgz", + "integrity": "sha512-oklcyHvUXqCS5JwbPVaN8tt7nSB8ffRmyrUlVt0HeSn4kDyNE46oKSbw3KtrDzl530KHnm67LfcK/AjWbBoXUA==", + "dev": true, + "license": "unlicense" }, "node_modules/@xtuc/ieee754": { "version": "1.2.0", @@ -13889,9 +13890,9 @@ "requires": {} }, "@webxdc/types": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@webxdc/types/-/types-2.0.0.tgz", - "integrity": "sha512-gtddNq2PsUZZwESXOjpI3sHG185fm7QXEolm9sWVIM1iV0sD4Zs8jLL1MKjuYn04/WuX8jVDKDGBDv4qLimhlA==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@webxdc/types/-/types-2.1.2.tgz", + "integrity": "sha512-oklcyHvUXqCS5JwbPVaN8tt7nSB8ffRmyrUlVt0HeSn4kDyNE46oKSbw3KtrDzl530KHnm67LfcK/AjWbBoXUA==", "dev": true }, "@xtuc/ieee754": { diff --git a/package.json b/package.json index 3c11f16..5ce88d6 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,10 @@ "name": "Martijn Faassen", "email": "faassen@startifact.com", "url": "http://blog.startifact.com" + }, + { + "name": "Sebastian Klähn", + "email": "info@sebastian-klaehn.de" } ], "files": [ @@ -54,7 +58,7 @@ "@types/node": "^18.0.0", "@types/node-fetch": "^2.6.2", "@types/wait-on": "^5.3.1", - "@webxdc/types": "^2.0.0", + "@webxdc/types": "^2.0.1", "babel-loader": "^8.2.5", "babel-preset-solid": "~1.5.0", "concurrently": "^7.2.2", diff --git a/sim/create.ts b/sim/create.ts index 1445970..aa60079 100644 --- a/sim/create.ts +++ b/sim/create.ts @@ -1,4 +1,4 @@ -import { WebXdc, ReceivedStatusUpdate } from "@webxdc/types"; +import { Webxdc, ReceivedStatusUpdate } from "@webxdc/types"; type UpdatesMessage = { type: "updates"; @@ -45,13 +45,13 @@ type Log = (...args: any[]) => void; export function createWebXdc( transport: Transport, log: Log = () => {}, -): WebXdc { +): Webxdc { let resolveUpdateListenerPromise: (() => void) | null = null; - const webXdc: WebXdc = { - sendUpdate: (update, descr) => { - transport.send({ type: "sendUpdate", update, descr }); - log("send", { update, descr }); + const webXdc: Webxdc = { + sendUpdate: (update: any) => { + transport.send({ type: "sendUpdate", update }); + log("send", { update }); }, setUpdateListener: (listener, serial = 0): Promise => { transport.onMessage((message) => { diff --git a/sim/webxdc.test.ts b/sim/webxdc.test.ts index 7a198d6..8847cd9 100644 --- a/sim/webxdc.test.ts +++ b/sim/webxdc.test.ts @@ -27,15 +27,15 @@ class FakeTransport implements Transport { send(data: any) { if (data.type === "sendUpdate") { - const { update, descr } = data; - this.client.sendUpdate(update, descr); + const { update } = data; + this.client.sendUpdate(update, ""); } else if (data.type === "setUpdateListener") { this.client.connect( (updates) => { if (this.messageCallback != null) { this.messageCallback({ type: "updates", - updates: updates.map(([update]) => update), + updates, }); } return true; @@ -106,7 +106,7 @@ test("webxdc sends", async () => { }, 0); fakeTransport.connect(); await promise; - webXdc.sendUpdate({ payload: "hello" }, "sent 1"); + webXdc.sendUpdate({ payload: "hello" }, ""); expect(updates).toEqual([ { payload: "hello", @@ -148,7 +148,7 @@ test("webxdc distributes", async () => { fakeTransportB.connect(); await promiseB; - webXdcA.sendUpdate({ payload: "hello" }, "sent 1"); + webXdcA.sendUpdate({ payload: "hello" }, ""); expect(updatesA).toEqual([ { payload: "hello", diff --git a/sim/webxdc.ts b/sim/webxdc.ts index f7739a8..7d0130b 100644 --- a/sim/webxdc.ts +++ b/sim/webxdc.ts @@ -1,4 +1,4 @@ -import { WebXdc } from "@webxdc/types"; +import { Webxdc } from "@webxdc/types"; import { Transport, TransportMessageCallback, @@ -114,7 +114,7 @@ export class DevServerTransport implements Transport { } } -function getWebXdc(): WebXdc { +function getWebXdc(): Webxdc { return (window as any).webxdc; } diff --git a/types/message.ts b/types/message.ts index 46f7801..123c228 100644 --- a/types/message.ts +++ b/types/message.ts @@ -8,7 +8,6 @@ export type InstanceMessage = { export type BaseUpdateMessage = { update: ReceivedStatusUpdate; - descr: string; } & InstanceMessage; export type UpdateMessage =