-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathshared.mts
More file actions
65 lines (60 loc) · 2.86 KB
/
shared.mts
File metadata and controls
65 lines (60 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (C) 2025 Bryan A. Jones.
//
// This file is part of the CodeChat Editor. The CodeChat Editor is free
// software: you can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// The CodeChat Editor is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// the CodeChat Editor. If not, see
// [http://www.gnu.org/licenses](http://www.gnu.org/licenses).
//
// `shared.mts` -- Shared definitions
// =============================================
//
// The time, in ms, to wait between the last user edit and sending updated data
// to the Server.
export const auto_update_timeout_ms = 300;
// Produce a whole random number. Fractional numbers aren't consistently
// converted to the same number across JavaScript and Rust. Note that the mantissa of a JavaScript `Number`
// is 53 bits per the
// [docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#number_encoding).
// To be certain, also floor the result.
export const rand = () => Math.floor(Math.random() * 2 ** 53);
// ### Message types
//
// These mirror the same definitions in the Rust webserver, so that the two can
// exchange messages. All these files are build by running `cargo test
// export_bindings`.
import { EditorMessageContents } from "./rust-types/EditorMessageContents.js";
import { EditorMessage } from "./rust-types/EditorMessage.js";
import { CodeChatForWeb } from "./rust-types/CodeChatForWeb.js";
import { CodeMirrorDiffable } from "./rust-types/CodeMirrorDiffable.js";
import { CodeMirror } from "./rust-types/CodeMirror.js";
import { StringDiff } from "./rust-types/StringDiff.js";
import { CodeMirrorDocBlockTuple } from "./rust-types/CodeMirrorDocBlockTuple.js";
import { UpdateMessageContents } from "./rust-types/UpdateMessageContents.js";
import { ResultOkTypes } from "./rust-types/ResultOkTypes.js";
import { ResultErrTypes } from "./rust-types/ResultErrTypes.js";
// Manually define this, since `ts-rs` can't export `webserver.MessageResult`.
type MessageResult = { Ok: ResultOkTypes } | { Err: ResultErrTypes };
// Modified from [SO](https://stackoverflow.com/a/79050131). If the value is a
// string, use it; otherwise, assume it's a dict and use its key.
type KeysOfRustEnum<T> = T extends T ? (T extends string ? T : keyof T) : never;
export type {
CodeMirror,
CodeMirrorDiffable,
CodeMirrorDocBlockTuple,
CodeChatForWeb,
EditorMessage,
EditorMessageContents,
KeysOfRustEnum,
MessageResult,
StringDiff,
UpdateMessageContents,
};