Skip to content

Commit 9e2dab6

Browse files
committedApr 27, 2024·
add better typings for server code
1 parent 12608bd commit 9e2dab6

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed
 

‎bin/utils.cjs

+7-7
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ class WSSharedDoc extends Y.Doc {
142142
this.awareness.on('update', awarenessChangeHandler)
143143
this.on('update', /** @type {any} */ (updateHandler))
144144
if (isCallbackSet) {
145-
this.on('update', debounce(
145+
this.on('update', /** @type {any} */ (debounce(
146146
callbackHandler,
147147
CALLBACK_DEBOUNCE_WAIT,
148148
{ maxWait: CALLBACK_DEBOUNCE_MAXWAIT }
149-
))
149+
)))
150150
}
151151
this.whenInitialized = contentInitializor(this)
152152
}
@@ -233,15 +233,15 @@ const closeConn = (doc, conn) => {
233233

234234
/**
235235
* @param {WSSharedDoc} doc
236-
* @param {any} conn
236+
* @param {import('ws').WebSocket} conn
237237
* @param {Uint8Array} m
238238
*/
239239
const send = (doc, conn, m) => {
240240
if (conn.readyState !== wsReadyStateConnecting && conn.readyState !== wsReadyStateOpen) {
241241
closeConn(doc, conn)
242242
}
243243
try {
244-
conn.send(m, /** @param {any} err */ err => { err != null && closeConn(doc, conn) })
244+
conn.send(m, {}, err => { err != null && closeConn(doc, conn) })
245245
} catch (e) {
246246
closeConn(doc, conn)
247247
}
@@ -250,11 +250,11 @@ const send = (doc, conn, m) => {
250250
const pingTimeout = 30000
251251

252252
/**
253-
* @param {any} conn
254-
* @param {any} req
253+
* @param {import('ws').WebSocket} conn
254+
* @param {import('http').IncomingMessage} req
255255
* @param {any} opts
256256
*/
257-
exports.setupWSConnection = (conn, req, { docName = req.url.slice(1).split('?')[0], gc = true } = {}) => {
257+
exports.setupWSConnection = (conn, req, { docName = (req.url || '').slice(1).split('?')[0], gc = true } = {}) => {
258258
conn.binaryType = 'arraybuffer'
259259
// get doc, initialize if it does not exist yet
260260
const doc = getYDoc(docName, gc)

‎package-lock.json

+16
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
@@ -64,6 +64,7 @@
6464
"y-protocols": "^1.0.5"
6565
},
6666
"devDependencies": {
67+
"@types/lodash.debounce": "^4.0.9",
6768
"@types/node": "^18.15.0",
6869
"@types/ws": "^8.5.10",
6970
"rollup": "^3.19.1",

0 commit comments

Comments
 (0)
Please sign in to comment.