Skip to content

Commit e13ce35

Browse files
committed
add replication to wrapped interface
1 parent 2919853 commit e13ce35

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@types/uuid": "^8.3.3",
3535
"@types/ws": "^8.2.0",
3636
"rimraf": "^3.0.2",
37+
"type-fest": "^2.5.4",
3738
"typescript": "^4.5.2",
3839
"xo": "^0.46.4"
3940
},

src/client/client.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import EventEmitter from 'eventemitter3'
22
import WebSocket from 'isomorphic-ws'
33
import type { MessageEvent } from 'isomorphic-ws'
44
import type { Buffer } from 'node:buffer'
5+
import type { SetOptional } from 'type-fest'
56
import { deserializeMessage, serializeMessage } from '../codec.js'
67
import { Instruction } from '../index.js'
78
import type { Message, Vector3 } from '../interfaces.js'
9+
import { Replication } from '../worldql-fb/index.js'
810
import type { ClientEvents as Events, MessagePayload } from './interfaces.js'
911

1012
export interface ClientOptions {
@@ -100,7 +102,9 @@ export class Client extends EventEmitter<Events> {
100102
}
101103
// #endregion
102104

103-
public sendRawMessage(message: Readonly<Message>): void {
105+
public sendRawMessage(
106+
message: Readonly<SetOptional<Message, 'replication'>>
107+
): void {
104108
if (!this.connected) {
105109
throw new Error('cannot send messages before client is connected')
106110
}
@@ -109,7 +113,12 @@ export class Client extends EventEmitter<Events> {
109113
throw new Error('cannot send messages before client is ready')
110114
}
111115

112-
const data = serializeMessage(message, this._uuid!)
116+
const messageWithDefaults: Readonly<Message> = {
117+
replication: Replication.ExceptSelf,
118+
...message,
119+
}
120+
121+
const data = serializeMessage(messageWithDefaults, this._uuid!)
113122
this._ws!.send(data)
114123
}
115124

src/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Instruction } from './worldql-fb/index.js'
1+
import { Instruction, Replication } from './worldql-fb/index.js'
22

33
export interface Vector3 {
44
x: number
@@ -26,6 +26,7 @@ export interface Message {
2626
instruction: Instruction
2727
parameter?: string
2828
worldName: string
29+
replication: Replication
2930
records?: Record[]
3031
entities?: Entity[]
3132
position?: Vector3

yarn.lock

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@
315315
dependencies:
316316
"@types/node" "*"
317317

318-
"@typescript-eslint/eslint-plugin@*":
318+
"@typescript-eslint/eslint-plugin@^5.2.0":
319319
version "5.4.0"
320320
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.4.0.tgz#05e711a2e7b68342661fde61bccbd1531c19521a"
321321
integrity sha512-9/yPSBlwzsetCsGEn9j24D8vGQgJkOTr4oMLas/w886ZtzKIs1iyoqFrwsX2fqYEeUwsdBpC21gcjRGo57u0eg==
@@ -341,7 +341,7 @@
341341
eslint-scope "^5.1.1"
342342
eslint-utils "^3.0.0"
343343

344-
"@typescript-eslint/parser@*":
344+
"@typescript-eslint/parser@^5.2.0":
345345
version "5.4.0"
346346
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.4.0.tgz#3aa83ce349d66e39b84151f6d5464928044ca9e3"
347347
integrity sha512-JoB41EmxiYpaEsRwpZEYAJ9XQURPFer8hpkIW9GiaspVLX8oqbqNM8P4EP8HOZg96yaALiLEVWllA2E8vwsIKw==
@@ -827,7 +827,7 @@ eslint-config-prettier@^8.3.0:
827827
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz#f7471b20b6fe8a9a9254cc684454202886a2dd7a"
828828
integrity sha512-BgZuLUSeKzvlL/VUjx/Yb787VQ26RU3gGjA3iiFvdsp/2bMfVIWUVP7tjxtjS0e+HP409cPlPvNkQloz8C91ew==
829829

830-
eslint-config-xo-typescript@*:
830+
eslint-config-xo-typescript@^0.47.1:
831831
version "0.47.1"
832832
resolved "https://registry.yarnpkg.com/eslint-config-xo-typescript/-/eslint-config-xo-typescript-0.47.1.tgz#87b5865d8a3428fa26cc8dc3146ef4f712dfed46"
833833
integrity sha512-BkbzIltZCWp8QLekKJKG8zJ/ZGezD8Z9FaJ+hJ5PrAVUGkIPmxXLLEHCKS3ax7oOqZLYQiG+jyKfQDIEdTQgbg==
@@ -2671,6 +2671,11 @@ type-fest@^1.0.1, type-fest@^1.2.1, type-fest@^1.2.2:
26712671
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-1.4.0.tgz#e9fb813fe3bf1744ec359d55d1affefa76f14be1"
26722672
integrity sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==
26732673

2674+
type-fest@^2.5.4:
2675+
version "2.5.4"
2676+
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-2.5.4.tgz#1613bf29a172ff1c66c29325466af9096fe505b5"
2677+
integrity sha512-zyPomVvb6u7+gJ/GPYUH6/nLDNiTtVOqXVUHtxFv5PmZQh6skgfeRtFYzWC01T5KeNWNIx5/0P111rKFLlkFvA==
2678+
26742679
typescript@^4.4.4, typescript@^4.5.2:
26752680
version "4.5.2"
26762681
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.2.tgz#8ac1fba9f52256fdb06fb89e4122fa6a346c2998"

0 commit comments

Comments
 (0)