From 1dcbfc761dcf5fe05a7726759425e69de18d95f7 Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 28 Nov 2024 22:02:05 +0000 Subject: [PATCH] Remove webxdc.d.ts and refer to the documentation for downloading it --- .github/workflows/simulator_types.yml | 23 ---- README.md | 15 +-- webxdc.d.ts | 166 -------------------------- 3 files changed, 2 insertions(+), 202 deletions(-) delete mode 100644 .github/workflows/simulator_types.yml delete mode 100644 webxdc.d.ts diff --git a/.github/workflows/simulator_types.yml b/.github/workflows/simulator_types.yml deleted file mode 100644 index be25baf..0000000 --- a/.github/workflows/simulator_types.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Are types and sim in sync? - -on: - push: - branches: [master] - pull_request: - branches: [master] - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Use Node.js 14.x - uses: actions/setup-node@v1 - with: - node-version: 14.x - - name: install typescript - run: | - npm i -g typescript - - name: check if simulator (webxdc.js) and types (webxdc.d.ts) are in sync - run: | - tsc --noEmit --allowJs --lib es2016,dom webxdc.js diff --git a/README.md b/README.md index 793abfe..4e48573 100644 --- a/README.md +++ b/README.md @@ -37,20 +37,9 @@ Alternatively, use the more advanced [webxdc-dev](https://github.com/webxdc/webx ### Type-checking and completion -If you are using VSCode you can have autocompletion and type-checking even without using TypeScript by adding these two lines to your JavaScript source files: +If you want to have type-checking and autocompletion you can use [@webxdc/types](https://github.com/webxdc/webxdc-types/) package. +Refer to https://webxdc.org/docs/faq/typing.html and https://github.com/webxdc/webxdc-types/ README for the documentation on setting it up. -```js -//@ts-check -/** @typedef {import('./webxdc').Webxdc} Webxdc */ -``` - -Without VSCode you need to install TypeScript and then run the check manually. - -```sh -npm -g typescript -tsc --noEmit --allowJs --lib es2016,dom webxdc.js # to check if types and simulator are in sync -tsc --noEmit --allowJs --lib es2016,dom your_js_file.js -``` ### Developing in Safari diff --git a/webxdc.d.ts b/webxdc.d.ts deleted file mode 100644 index fa7c2a2..0000000 --- a/webxdc.d.ts +++ /dev/null @@ -1,166 +0,0 @@ -//@ts-check - -// This file originates from -// https://github.com/webxdc/webxdc_docs/blob/master/webxdc.d.ts - -type SendingStatusUpdate = { - /** the payload, deserialized json: - * any javascript primitive, array or object. */ - payload: T; - /** optional, short, informational message that will be added to the chat, - * eg. "Alice voted" or "Bob scored 123 in MyGame"; - * usually only one line of text is shown, - * use this option sparingly to not spam the chat. */ - info?: string; - /** optional, if the Webxdc creates a document, you can set this to the name of the document; - * do not set if the Webxdc does not create a document */ - document?: string; - /** optional, short text, shown beside the icon; - * it is recommended to use some aggregated value, - * eg. "8 votes", "Highscore: 123" */ - summary?: string; -}; - -type ReceivedStatusUpdate = { - /** the payload, deserialized json */ - payload: T; - /** the serial number of this update. Serials are larger than 0 and newer serials have higher numbers */ - serial: number; - /** the maximum serial currently known */ - max_serial: number; - /** optional, short, informational message. */ - info?: string; - /** optional, if the Webxdc creates a document, this is the name of the document; - * not set if the Webxdc does not create a document */ - document?: string; - /** optional, short text, shown beside the webxdc's icon. */ - summary?: string; -}; - -type XDCFile = { - /** name of the file, including extension */ - name: string; -} & ( - | { - /** Blob, also accepts inherit types like File */ - blob: Blob; - } - | { - /** base64 encoded file data */ - base64: string; - } - | { - /** text for textfile, will be encoded as utf8 */ - plainText: string; - } -); - -type SendOptions = - | { - file: XDCFile; - text?: string; - } - | { - file?: XDCFile; - text: string; - }; - -/** - * A listener for realtime data. - */ -export class RealtimeListener { - private listener: (data: Uint8Array) => void - private trashed: boolean - - /* Whether the realtime channel was left */ - is_trashed(): boolean - /* Receive data from the realtime channel */ - receive(data: Uint8Array): void - /* Set a listener for the realtime channel */ - setListener(listener: (data: Uint8Array) => void): void - /* Send data over the realtime channel */ - send(data: Uint8Array): void - /* Leave the realtime channel */ - leave(): void -} - -interface Webxdc { - /** Returns the peer's own address. - * This is esp. useful if you want to differ between different peers - just send the address along with the payload, - * and, if needed, compare the payload addresses against selfAddr() later on. */ - selfAddr: string; - /** Returns the peer's own name. This is name chosen by the user in their settings, if there is nothing set, that defaults to the peer's address. */ - selfName: string; - /** - * set a listener for new status updates. - * The "serial" specifies the last serial that you know about (defaults to 0). - * Note that own status updates, that you send with {@link sendUpdate}, also trigger this method - * @returns promise that resolves when the listener has processed all the update messages known at the time when `setUpdateListener` was called. - * */ - setUpdateListener( - cb: (statusUpdate: ReceivedStatusUpdate) => void, - serial?: number - ): Promise; - - /** - * Join a realtime channel. - */ - joinRealtimeChannel(): RealtimeListener; - - /** - * @deprecated See {@link setUpdateListener|`setUpdateListener()`}. - */ - getAllUpdates(): Promise[]>; - /** - * Webxdc are usually shared in a chat and run independently on each peer. To get a shared status, the peers use sendUpdate() to send updates to each other. - * @param update status update to send - * @param description short, human-readable description what this update is about. this is shown eg. as a fallback text in an email program. - */ - sendUpdate(update: SendingStatusUpdate, description: string): void; - /** - * Send a message with file, text or both to a chat. - * Asks user to what Chat to send the message to. - * May exit the xdc, please save your app state before calling this function. - * @param message - * @returns promise that may not resolve (because the xdc closes) and is rejected on error. - */ - sendToChat(message: SendOptions): Promise; - /** - * Asks the user to choose files. - * This either opens a normal file picker (like ``) or an integrated Filepicker if the ui has implemented it. - * This custom file picker should show files that were recently send or received in chats, - * but also show a button to open the normal file picker. - */ - importFiles(filter: { - /** - * Only show files with these extensions. - * All extensions need to start with a dot and have the format `.ext`. */ - extensions?: string[]; - /** - * Mime types as in https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept#unique_file_type_specifiers - * Specifying a mime type requires to list all typical extensions as well. - */ - mimeTypes?: string[]; - /** Whether to allow multiple files to be selected, false by default */ - multiple?: boolean; - }): Promise; -} - -////////// ANCHOR: global -declare global { - interface Window { - webxdc: Webxdc; - } -} -////////// ANCHOR_END: global - -export { SendingStatusUpdate, ReceivedStatusUpdate, Webxdc, XDCFile }; - -/* Types for the Simulator */ -declare global { - interface Window { - addXdcPeer: () => void; - clearXdcStorage: () => void; - alterXdcApp: () => void; - } -}