Skip to content

Commit 6b422ea

Browse files
authored
Merge pull request #61 from webxdc/adb/use-webxdc-types-package
use webxdc types package
2 parents b8976d0 + fd72951 commit 6b422ea

File tree

10 files changed

+46
-115
lines changed

10 files changed

+46
-115
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ release date when you use `npm version` (see `README.md`).
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- use `@webxdc/types` instead of own types declaration
13+
1014
## [0.18.0][] - 2024-11-16
1115

1216
### Changed

TODO.md

-5
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@
5959
port: for instance, if you open an instance again the server doesn't know to
6060
clear it first, because it thinks it already been cleared previously.
6161

62-
## Webxdc development
63-
64-
- Make typescript types for webxdc available as a standalone package so that
65-
developers can use this in their own projects.
66-
6762
## Other
6863

6964
- Update webxdc specification based on what I learned about it.

backend/instance.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import expressWs from "express-ws";
22
import { WebSocket, Server } from "ws";
33

4-
import { JsonValue, ReceivedUpdate } from "../types/webxdc";
4+
import { ReceivedStatusUpdate } from "@webxdc/types";
55
import { createProcessor, IProcessor, WebXdcMulti, OnMessage } from "./message";
66
import { Location } from "./location";
77
import { createPeer, InjectExpress } from "./app";
@@ -17,7 +17,7 @@ export type Options = {
1717

1818
type SendUpdateMessage = {
1919
type: "sendUpdate";
20-
update: ReceivedUpdate<JsonValue>;
20+
update: ReceivedStatusUpdate<any>;
2121
descr: string;
2222
};
2323

backend/message.ts

+15-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import type {
2-
Update,
3-
JsonValue,
4-
ReceivedUpdate,
5-
SendUpdate,
6-
} from "../types/webxdc";
2+
ReceivedStatusUpdate,
3+
SendingStatusUpdate,
4+
Webxdc,
5+
} from "@webxdc/types";
76
import type { Message } from "../types/message";
87
import { getColorForId } from "./color";
98

109
type UpdateListenerMulti = (
11-
updates: [ReceivedUpdate<JsonValue>, string][],
10+
updates: [ReceivedStatusUpdate<any>, string][],
1211
) => boolean;
1312

1413
type ClearListener = () => boolean;
@@ -23,10 +22,10 @@ type Connect = (
2322

2423
export type WebXdcMulti = {
2524
connect: Connect;
26-
sendUpdate: SendUpdate<JsonValue>;
25+
sendUpdate: Webxdc<any>["sendUpdate"];
2726
};
2827

29-
export type UpdateDescr = [ReceivedUpdate<JsonValue>, string];
28+
export type UpdateDescr = [ReceivedStatusUpdate<any>, string];
3029

3130
export type OnMessage = (message: Message) => void;
3231

@@ -47,7 +46,7 @@ class Client implements WebXdcMulti {
4746
public id: string,
4847
) {}
4948

50-
sendUpdate(update: Update<JsonValue>, descr: string): void {
49+
sendUpdate(update: SendingStatusUpdate<any>, descr: string): void {
5150
this.processor.distribute(this.id, update, descr);
5251
}
5352

@@ -103,7 +102,7 @@ class Client implements WebXdcMulti {
103102
this.clear();
104103
}
105104

106-
receiveUpdate(update: ReceivedUpdate<JsonValue>, descr: string) {
105+
receiveUpdate(update: ReceivedStatusUpdate<any>, descr: string) {
107106
if (this.updateListener == null || this.updateSerial == null) {
108107
return;
109108
}
@@ -154,9 +153,13 @@ class Processor implements IProcessor {
154153
this.clients.splice(client_index, 1);
155154
}
156155

157-
distribute(instanceId: string, update: Update<JsonValue>, descr: string) {
156+
distribute(
157+
instanceId: string,
158+
update: SendingStatusUpdate<any>,
159+
descr: string,
160+
) {
158161
this.currentSerial++;
159-
const receivedUpdate: ReceivedUpdate<JsonValue> = {
162+
const receivedUpdate: ReceivedStatusUpdate<any> = {
160163
...update,
161164
serial: this.currentSerial,
162165
max_serial: this.updates.length + 1,

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@types/node": "^18.0.0",
5555
"@types/node-fetch": "^2.6.2",
5656
"@types/wait-on": "^5.3.1",
57+
"@webxdc/types": "^2.0.0",
5758
"babel-loader": "^8.2.5",
5859
"babel-preset-solid": "~1.5.0",
5960
"concurrently": "^7.2.2",

sim/create.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { WebXdc, JsonValue, ReceivedUpdate } from "../types/webxdc";
1+
import { WebXdc, ReceivedStatusUpdate } from "@webxdc/types";
22

33
type UpdatesMessage = {
44
type: "updates";
5-
updates: ReceivedUpdate<JsonValue>[];
5+
updates: ReceivedStatusUpdate<any>[];
66
};
77

88
type ClearMessage = {
@@ -30,7 +30,7 @@ export type TransportMessageCallback = (message: Message) => void;
3030
export type TransportConnectCallback = () => void;
3131

3232
export type Transport = {
33-
send(data: JsonValue): void;
33+
send(data: any): void;
3434
onMessage(callback: TransportMessageCallback): void;
3535
onConnect(callback: TransportConnectCallback): void;
3636
clear(): void;
@@ -45,10 +45,10 @@ type Log = (...args: any[]) => void;
4545
export function createWebXdc(
4646
transport: Transport,
4747
log: Log = () => {},
48-
): WebXdc {
48+
): WebXdc<any> {
4949
let resolveUpdateListenerPromise: (() => void) | null = null;
5050

51-
const webXdc: WebXdc = {
51+
const webXdc: WebXdc<any> = {
5252
sendUpdate: (update, descr) => {
5353
transport.send({ type: "sendUpdate", update, descr });
5454
log("send", { update, descr });
@@ -177,7 +177,7 @@ export function createWebXdc(
177177
...(filters.mimeTypes || []),
178178
].join(",");
179179
element.multiple = filters.multiple || false;
180-
const promise = new Promise((resolve, _reject) => {
180+
const promise: Promise<File[]> = new Promise((resolve, _reject) => {
181181
element.onchange = (_ev) => {
182182
console.log("element.files", element.files);
183183
const files = Array.from(element.files || []);

sim/webxdc.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { JsonValue, WebXdc } from "../types/webxdc";
1+
import { WebXdc } from "@webxdc/types";
22
import {
33
Transport,
44
TransportMessageCallback,
@@ -25,7 +25,7 @@ export class DevServerTransport implements Transport {
2525
});
2626
}
2727

28-
send(data: JsonValue): void {
28+
send(data: any): void {
2929
this.socket.send(JSON.stringify(data));
3030
}
3131

@@ -99,7 +99,7 @@ export class DevServerTransport implements Transport {
9999
}
100100
}
101101

102-
function getWebXdc(): WebXdc {
102+
function getWebXdc(): WebXdc<any> {
103103
return (window as any).webxdc;
104104
}
105105

types/message.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReceivedUpdate, JsonValue } from "./webxdc";
1+
import { ReceivedStatusUpdate } from "@webxdc/types";
22

33
export type InstanceMessage = {
44
instanceId: string;
@@ -7,7 +7,7 @@ export type InstanceMessage = {
77
};
88

99
export type BaseUpdateMessage = {
10-
update: ReceivedUpdate<JsonValue>;
10+
update: ReceivedStatusUpdate<any>;
1111
descr: string;
1212
} & InstanceMessage;
1313

types/webxdc.ts

-85
This file was deleted.

0 commit comments

Comments
 (0)