@pluv/io 0.18.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +16 -16
- package/CHANGELOG.md +15 -0
- package/dist/index.js +38 -75
- package/dist/index.mjs +38 -75
- package/package.json +8 -8
- package/src/version.generated.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/io@0.
|
|
2
|
+
> @pluv/io@0.20.0 build /home/runner/work/pluv/pluv/packages/io
|
|
3
3
|
> pnpm run version && tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
> @pluv/io@0.
|
|
6
|
+
> @pluv/io@0.20.0 version /home/runner/work/pluv/pluv/packages/io
|
|
7
7
|
> genversion ./src/version.generated.ts --esm
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
CLI Building entry: src/index.ts
|
|
10
|
+
CLI Using tsconfig: tsconfig.json
|
|
11
|
+
CLI tsup v8.1.0
|
|
12
|
+
CLI Target: es6
|
|
13
|
+
ESM Build start
|
|
14
|
+
CJS Build start
|
|
15
|
+
CJS dist/index.js 34.58 KB
|
|
16
|
+
CJS ⚡️ Build success in 165ms
|
|
17
|
+
ESM dist/index.mjs 32.42 KB
|
|
18
|
+
ESM ⚡️ Build success in 166ms
|
|
19
|
+
DTS Build start
|
|
20
|
+
DTS ⚡️ Build success in 2412ms
|
|
21
|
+
DTS dist/index.d.mts 21.67 KB
|
|
22
|
+
DTS dist/index.d.ts 21.67 KB
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @pluv/io
|
|
2
2
|
|
|
3
|
+
## 0.20.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [9492085]
|
|
8
|
+
- @pluv/crdt@0.20.0
|
|
9
|
+
- @pluv/types@0.20.0
|
|
10
|
+
|
|
11
|
+
## 0.19.0
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- @pluv/crdt@0.19.0
|
|
16
|
+
- @pluv/types@0.19.0
|
|
17
|
+
|
|
3
18
|
## 0.18.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -116,8 +116,7 @@ var Persistance = class extends AbstractPersistance {
|
|
|
116
116
|
deleteUser(room, connectionId) {
|
|
117
117
|
return __async(this, null, function* () {
|
|
118
118
|
const users = this._users.get(room);
|
|
119
|
-
if (!users)
|
|
120
|
-
return;
|
|
119
|
+
if (!users) return;
|
|
121
120
|
users.delete(connectionId);
|
|
122
121
|
if (!users.size) {
|
|
123
122
|
yield this.deleteUsers(room);
|
|
@@ -146,8 +145,7 @@ var Persistance = class extends AbstractPersistance {
|
|
|
146
145
|
}
|
|
147
146
|
getUsers(room) {
|
|
148
147
|
const users = this._users.get(room);
|
|
149
|
-
if (!users)
|
|
150
|
-
return Promise.resolve([]);
|
|
148
|
+
if (!users) return Promise.resolve([]);
|
|
151
149
|
return Promise.resolve(Array.from(users.values()));
|
|
152
150
|
}
|
|
153
151
|
setStorageState(room, state) {
|
|
@@ -178,8 +176,7 @@ var PubSub = class extends AbstractPubSub {
|
|
|
178
176
|
publish(roomName, payload) {
|
|
179
177
|
return __async(this, null, function* () {
|
|
180
178
|
const subject = this._subjects.get(roomName);
|
|
181
|
-
if (!subject)
|
|
182
|
-
return;
|
|
179
|
+
if (!subject) return;
|
|
183
180
|
Promise.resolve(subject.next(payload));
|
|
184
181
|
});
|
|
185
182
|
}
|
|
@@ -197,11 +194,9 @@ var PubSub = class extends AbstractPubSub {
|
|
|
197
194
|
unsubscribe(subscriptionId) {
|
|
198
195
|
var _a;
|
|
199
196
|
const [roomName, unsubscribe] = (_a = this._unsubscriptions.get(subscriptionId)) != null ? _a : [];
|
|
200
|
-
if (!roomName || !unsubscribe)
|
|
201
|
-
return;
|
|
197
|
+
if (!roomName || !unsubscribe) return;
|
|
202
198
|
const refs = this._subscriptionsRefs.get(roomName);
|
|
203
|
-
if (!refs)
|
|
204
|
-
return;
|
|
199
|
+
if (!refs) return;
|
|
205
200
|
if (refs.length === 1) {
|
|
206
201
|
this._subjects.delete(roomName);
|
|
207
202
|
this._subscriptionsRefs.delete(roomName);
|
|
@@ -287,8 +282,7 @@ var PluvProcedure = class _PluvProcedure {
|
|
|
287
282
|
}
|
|
288
283
|
broadcast(resolver) {
|
|
289
284
|
const { broadcast } = this.config;
|
|
290
|
-
if (!!broadcast)
|
|
291
|
-
throw new Error("Broadcast was already defined for this procedure");
|
|
285
|
+
if (!!broadcast) throw new Error("Broadcast was already defined for this procedure");
|
|
292
286
|
return new _PluvProcedure(__spreadProps(__spreadValues({}, this.config), {
|
|
293
287
|
broadcast: resolver
|
|
294
288
|
}));
|
|
@@ -298,16 +292,14 @@ var PluvProcedure = class _PluvProcedure {
|
|
|
298
292
|
}
|
|
299
293
|
self(resolver) {
|
|
300
294
|
const { self } = this.config;
|
|
301
|
-
if (!!self)
|
|
302
|
-
throw new Error("Self was already defined for this procedure");
|
|
295
|
+
if (!!self) throw new Error("Self was already defined for this procedure");
|
|
303
296
|
return new _PluvProcedure(__spreadProps(__spreadValues({}, this.config), {
|
|
304
297
|
self: resolver
|
|
305
298
|
}));
|
|
306
299
|
}
|
|
307
300
|
sync(resolver) {
|
|
308
301
|
const { sync } = this.config;
|
|
309
|
-
if (!!sync)
|
|
310
|
-
throw new Error("Sync was already defined for this procedure");
|
|
302
|
+
if (!!sync) throw new Error("Sync was already defined for this procedure");
|
|
311
303
|
return new _PluvProcedure(__spreadProps(__spreadValues({}, this.config), {
|
|
312
304
|
sync: resolver
|
|
313
305
|
}));
|
|
@@ -388,8 +380,7 @@ var IORoom = class {
|
|
|
388
380
|
this._listeners = {
|
|
389
381
|
onDestroy: (event) => onDestroy == null ? void 0 : onDestroy(event)
|
|
390
382
|
};
|
|
391
|
-
if (authorize2)
|
|
392
|
-
this._authorize = authorize2;
|
|
383
|
+
if (authorize2) this._authorize = authorize2;
|
|
393
384
|
}
|
|
394
385
|
get _events() {
|
|
395
386
|
return this._router._events;
|
|
@@ -408,8 +399,7 @@ var IORoom = class {
|
|
|
408
399
|
getSize() {
|
|
409
400
|
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
410
401
|
return Array.from(this._sessions.values()).reduce((count, session) => {
|
|
411
|
-
if (session.quit)
|
|
412
|
-
return count;
|
|
402
|
+
if (session.quit) return count;
|
|
413
403
|
return currentTime - session.timers.ping > PING_TIMEOUT_MS ? count : count + 1;
|
|
414
404
|
}, 0);
|
|
415
405
|
}
|
|
@@ -418,8 +408,7 @@ var IORoom = class {
|
|
|
418
408
|
var _b;
|
|
419
409
|
const _a = options, { token } = _a, _platformEventContext = __objRest(_a, ["token"]);
|
|
420
410
|
const platformEventContext = _platformEventContext;
|
|
421
|
-
if (!this._uninitialize)
|
|
422
|
-
yield this._initialize();
|
|
411
|
+
if (!this._uninitialize) yield this._initialize();
|
|
423
412
|
const user = yield this._getAuthorizedUser(token, options);
|
|
424
413
|
const sessionId = this._platform.randomUUID();
|
|
425
414
|
const pluvWs = this._platform.convertWebSocket(webSocket, {
|
|
@@ -514,10 +503,8 @@ var IORoom = class {
|
|
|
514
503
|
return __async(this, null, function* () {
|
|
515
504
|
var _a;
|
|
516
505
|
const ioAuthorize = this._getIOAuthorize(context);
|
|
517
|
-
if (!ioAuthorize)
|
|
518
|
-
|
|
519
|
-
if (!token)
|
|
520
|
-
return null;
|
|
506
|
+
if (!ioAuthorize) return null;
|
|
507
|
+
if (!token) return null;
|
|
521
508
|
const payload = yield authorize({
|
|
522
509
|
platform: this._platform,
|
|
523
510
|
secret: ioAuthorize.secret
|
|
@@ -547,8 +534,7 @@ var IORoom = class {
|
|
|
547
534
|
}
|
|
548
535
|
_getProcedureInputs(message) {
|
|
549
536
|
const procedure = this._getProcedure(message);
|
|
550
|
-
if (!procedure)
|
|
551
|
-
return message.data;
|
|
537
|
+
if (!procedure) return message.data;
|
|
552
538
|
return procedure.config.input ? procedure.config.input.parse(message.data) : message.data;
|
|
553
539
|
}
|
|
554
540
|
_initialize() {
|
|
@@ -584,8 +570,7 @@ var IORoom = class {
|
|
|
584
570
|
}
|
|
585
571
|
_onClose(session, callback) {
|
|
586
572
|
return () => {
|
|
587
|
-
if (!this._uninitialize)
|
|
588
|
-
return;
|
|
573
|
+
if (!this._uninitialize) return;
|
|
589
574
|
session.quit = true;
|
|
590
575
|
this._logDebug(`${import_kleur.default.blue(`(Unregistering connection for room ${this.id}:`)} ${session.id}`);
|
|
591
576
|
this._sessions.delete(session.id);
|
|
@@ -602,8 +587,7 @@ var IORoom = class {
|
|
|
602
587
|
const size = this.getSize();
|
|
603
588
|
this._logDebug(`${import_kleur.default.blue(`Unregistered connection for room ${this.id}:`)} ${session.id}`);
|
|
604
589
|
this._logDebug(`${import_kleur.default.blue(`Room ${this.id} size:`)} ${size}`);
|
|
605
|
-
if (size)
|
|
606
|
-
return;
|
|
590
|
+
if (size) return;
|
|
607
591
|
(_a = this._uninitialize) == null ? void 0 : _a.call(this);
|
|
608
592
|
});
|
|
609
593
|
};
|
|
@@ -618,18 +602,15 @@ var IORoom = class {
|
|
|
618
602
|
session,
|
|
619
603
|
sessions: this._sessions
|
|
620
604
|
};
|
|
621
|
-
if (!this._uninitialize)
|
|
622
|
-
return;
|
|
605
|
+
if (!this._uninitialize) return;
|
|
623
606
|
if (session.quit) {
|
|
624
607
|
session.webSocket.close(1011, "WebSocket broken.");
|
|
625
608
|
return;
|
|
626
609
|
}
|
|
627
610
|
const message = this._parseMessage(event);
|
|
628
|
-
if (!message)
|
|
629
|
-
return;
|
|
611
|
+
if (!message) return;
|
|
630
612
|
const procedure = this._getProcedure(message);
|
|
631
|
-
if (!procedure)
|
|
632
|
-
return;
|
|
613
|
+
if (!procedure) return;
|
|
633
614
|
let inputs;
|
|
634
615
|
try {
|
|
635
616
|
inputs = this._getProcedureInputs(message);
|
|
@@ -679,12 +660,9 @@ var IORoom = class {
|
|
|
679
660
|
_parseMessage(message) {
|
|
680
661
|
try {
|
|
681
662
|
const parsed = this._platform.parseData(message.data);
|
|
682
|
-
if (typeof parsed !== "object")
|
|
683
|
-
|
|
684
|
-
if (typeof parsed.
|
|
685
|
-
return null;
|
|
686
|
-
if (typeof parsed.data !== "object")
|
|
687
|
-
return null;
|
|
663
|
+
if (typeof parsed !== "object") return null;
|
|
664
|
+
if (typeof parsed.type !== "string") return null;
|
|
665
|
+
if (typeof parsed.data !== "object") return null;
|
|
688
666
|
return parsed;
|
|
689
667
|
} catch (e) {
|
|
690
668
|
return null;
|
|
@@ -724,11 +702,9 @@ var IORoom = class {
|
|
|
724
702
|
}
|
|
725
703
|
_sendSelfMessage(message, sender) {
|
|
726
704
|
const senderId = sender == null ? void 0 : sender.id;
|
|
727
|
-
if (!senderId)
|
|
728
|
-
return;
|
|
705
|
+
if (!senderId) return;
|
|
729
706
|
const session = this._sessions.get(senderId);
|
|
730
|
-
if (!session)
|
|
731
|
-
return;
|
|
707
|
+
if (!session) return;
|
|
732
708
|
session.webSocket.sendMessage(__spreadValues({
|
|
733
709
|
connectionId: sender.id,
|
|
734
710
|
room: this.id,
|
|
@@ -738,8 +714,7 @@ var IORoom = class {
|
|
|
738
714
|
_sendSyncMessage(message, sender) {
|
|
739
715
|
var _a;
|
|
740
716
|
const senderId = sender == null ? void 0 : sender.id;
|
|
741
|
-
if (!senderId)
|
|
742
|
-
return;
|
|
717
|
+
if (!senderId) return;
|
|
743
718
|
const context = {
|
|
744
719
|
context: this._context,
|
|
745
720
|
doc: this._doc,
|
|
@@ -748,8 +723,7 @@ var IORoom = class {
|
|
|
748
723
|
sessions: this._sessions
|
|
749
724
|
};
|
|
750
725
|
const resolver = (_a = this._getProcedure(message)) == null ? void 0 : _a.config.sync;
|
|
751
|
-
if (!resolver)
|
|
752
|
-
return;
|
|
726
|
+
if (!resolver) return;
|
|
753
727
|
let inputs;
|
|
754
728
|
try {
|
|
755
729
|
inputs = this._getProcedureInputs(message);
|
|
@@ -757,8 +731,7 @@ var IORoom = class {
|
|
|
757
731
|
return;
|
|
758
732
|
}
|
|
759
733
|
Promise.resolve(resolver(inputs, context)).then((output) => {
|
|
760
|
-
if (!output)
|
|
761
|
-
return;
|
|
734
|
+
if (!output) return;
|
|
762
735
|
Object.keys(output).forEach((type) => {
|
|
763
736
|
var _a2, _b;
|
|
764
737
|
const data = (_a2 = output[type]) != null ? _a2 : {};
|
|
@@ -776,7 +749,7 @@ var IORoom = class {
|
|
|
776
749
|
};
|
|
777
750
|
|
|
778
751
|
// src/version.generated.ts
|
|
779
|
-
var version = "0.
|
|
752
|
+
var version = "0.20.0";
|
|
780
753
|
|
|
781
754
|
// src/PluvServer.ts
|
|
782
755
|
var PluvServer = class {
|
|
@@ -799,10 +772,8 @@ var PluvServer = class {
|
|
|
799
772
|
this._debug = debug;
|
|
800
773
|
this._platform = platform;
|
|
801
774
|
this._router = router != null ? router : null;
|
|
802
|
-
if (authorize2)
|
|
803
|
-
|
|
804
|
-
if (context)
|
|
805
|
-
this._context = context;
|
|
775
|
+
if (authorize2) this._authorize = authorize2;
|
|
776
|
+
if (context) this._context = context;
|
|
806
777
|
this._listeners = {
|
|
807
778
|
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
808
779
|
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event)
|
|
@@ -833,8 +804,7 @@ var PluvServer = class {
|
|
|
833
804
|
}
|
|
834
805
|
const platform = this._platform;
|
|
835
806
|
const oldRoom = this._rooms.get(room);
|
|
836
|
-
if (oldRoom)
|
|
837
|
-
return oldRoom;
|
|
807
|
+
if (oldRoom) return oldRoom;
|
|
838
808
|
const roomContext = __spreadValues(__spreadValues({}, this._context), platformRoomContext);
|
|
839
809
|
const newRoom = new IORoom(room, {
|
|
840
810
|
authorize: (_b = this._authorize) != null ? _b : void 0,
|
|
@@ -872,8 +842,7 @@ var PluvServer = class {
|
|
|
872
842
|
_purgeEmptyRooms() {
|
|
873
843
|
const rooms = Array.from(this._rooms.entries());
|
|
874
844
|
rooms.forEach(([id, room]) => {
|
|
875
|
-
if (room.getSize())
|
|
876
|
-
return;
|
|
845
|
+
if (room.getSize()) return;
|
|
877
846
|
this._rooms.delete(id);
|
|
878
847
|
});
|
|
879
848
|
}
|
|
@@ -899,8 +868,7 @@ var PluvIO = class {
|
|
|
899
868
|
}),
|
|
900
869
|
$INITIALIZE_SESSION: this.procedure.broadcast((data, { session }) => {
|
|
901
870
|
const presence = data == null ? void 0 : data.presence;
|
|
902
|
-
if (!session)
|
|
903
|
-
return {};
|
|
871
|
+
if (!session) return {};
|
|
904
872
|
session.presence = presence;
|
|
905
873
|
return {
|
|
906
874
|
$USER_JOINED: {
|
|
@@ -928,16 +896,14 @@ var PluvIO = class {
|
|
|
928
896
|
return { $STORAGE_RECEIVED: { state } };
|
|
929
897
|
})),
|
|
930
898
|
$PING: this.procedure.self((data, { session }) => {
|
|
931
|
-
if (!session)
|
|
932
|
-
return {};
|
|
899
|
+
if (!session) return {};
|
|
933
900
|
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
934
901
|
session.timers.ping = currentTime;
|
|
935
902
|
return { $PONG: {} };
|
|
936
903
|
}),
|
|
937
904
|
$UPDATE_PRESENCE: this.procedure.broadcast((data, { session }) => {
|
|
938
905
|
const presence = data == null ? void 0 : data.presence;
|
|
939
|
-
if (!session)
|
|
940
|
-
return {};
|
|
906
|
+
if (!session) return {};
|
|
941
907
|
session.presence = Object.assign(/* @__PURE__ */ Object.create(null), session.presence, presence);
|
|
942
908
|
return { $PRESENCE_UPDATED: { presence } };
|
|
943
909
|
}),
|
|
@@ -976,12 +942,9 @@ var PluvIO = class {
|
|
|
976
942
|
this._crdt = crdt;
|
|
977
943
|
this._debug = debug;
|
|
978
944
|
this._platform = platform;
|
|
979
|
-
if (authorize2)
|
|
980
|
-
|
|
981
|
-
if (
|
|
982
|
-
this._context = context;
|
|
983
|
-
if (getInitialStorage)
|
|
984
|
-
this._getInitialStorage = getInitialStorage;
|
|
945
|
+
if (authorize2) this._authorize = authorize2;
|
|
946
|
+
if (context) this._context = context;
|
|
947
|
+
if (getInitialStorage) this._getInitialStorage = getInitialStorage;
|
|
985
948
|
this._listeners = {
|
|
986
949
|
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
987
950
|
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event)
|
package/dist/index.mjs
CHANGED
|
@@ -75,8 +75,7 @@ var Persistance = class extends AbstractPersistance {
|
|
|
75
75
|
deleteUser(room, connectionId) {
|
|
76
76
|
return __async(this, null, function* () {
|
|
77
77
|
const users = this._users.get(room);
|
|
78
|
-
if (!users)
|
|
79
|
-
return;
|
|
78
|
+
if (!users) return;
|
|
80
79
|
users.delete(connectionId);
|
|
81
80
|
if (!users.size) {
|
|
82
81
|
yield this.deleteUsers(room);
|
|
@@ -105,8 +104,7 @@ var Persistance = class extends AbstractPersistance {
|
|
|
105
104
|
}
|
|
106
105
|
getUsers(room) {
|
|
107
106
|
const users = this._users.get(room);
|
|
108
|
-
if (!users)
|
|
109
|
-
return Promise.resolve([]);
|
|
107
|
+
if (!users) return Promise.resolve([]);
|
|
110
108
|
return Promise.resolve(Array.from(users.values()));
|
|
111
109
|
}
|
|
112
110
|
setStorageState(room, state) {
|
|
@@ -137,8 +135,7 @@ var PubSub = class extends AbstractPubSub {
|
|
|
137
135
|
publish(roomName, payload) {
|
|
138
136
|
return __async(this, null, function* () {
|
|
139
137
|
const subject = this._subjects.get(roomName);
|
|
140
|
-
if (!subject)
|
|
141
|
-
return;
|
|
138
|
+
if (!subject) return;
|
|
142
139
|
Promise.resolve(subject.next(payload));
|
|
143
140
|
});
|
|
144
141
|
}
|
|
@@ -156,11 +153,9 @@ var PubSub = class extends AbstractPubSub {
|
|
|
156
153
|
unsubscribe(subscriptionId) {
|
|
157
154
|
var _a;
|
|
158
155
|
const [roomName, unsubscribe] = (_a = this._unsubscriptions.get(subscriptionId)) != null ? _a : [];
|
|
159
|
-
if (!roomName || !unsubscribe)
|
|
160
|
-
return;
|
|
156
|
+
if (!roomName || !unsubscribe) return;
|
|
161
157
|
const refs = this._subscriptionsRefs.get(roomName);
|
|
162
|
-
if (!refs)
|
|
163
|
-
return;
|
|
158
|
+
if (!refs) return;
|
|
164
159
|
if (refs.length === 1) {
|
|
165
160
|
this._subjects.delete(roomName);
|
|
166
161
|
this._subscriptionsRefs.delete(roomName);
|
|
@@ -246,8 +241,7 @@ var PluvProcedure = class _PluvProcedure {
|
|
|
246
241
|
}
|
|
247
242
|
broadcast(resolver) {
|
|
248
243
|
const { broadcast } = this.config;
|
|
249
|
-
if (!!broadcast)
|
|
250
|
-
throw new Error("Broadcast was already defined for this procedure");
|
|
244
|
+
if (!!broadcast) throw new Error("Broadcast was already defined for this procedure");
|
|
251
245
|
return new _PluvProcedure(__spreadProps(__spreadValues({}, this.config), {
|
|
252
246
|
broadcast: resolver
|
|
253
247
|
}));
|
|
@@ -257,16 +251,14 @@ var PluvProcedure = class _PluvProcedure {
|
|
|
257
251
|
}
|
|
258
252
|
self(resolver) {
|
|
259
253
|
const { self } = this.config;
|
|
260
|
-
if (!!self)
|
|
261
|
-
throw new Error("Self was already defined for this procedure");
|
|
254
|
+
if (!!self) throw new Error("Self was already defined for this procedure");
|
|
262
255
|
return new _PluvProcedure(__spreadProps(__spreadValues({}, this.config), {
|
|
263
256
|
self: resolver
|
|
264
257
|
}));
|
|
265
258
|
}
|
|
266
259
|
sync(resolver) {
|
|
267
260
|
const { sync } = this.config;
|
|
268
|
-
if (!!sync)
|
|
269
|
-
throw new Error("Sync was already defined for this procedure");
|
|
261
|
+
if (!!sync) throw new Error("Sync was already defined for this procedure");
|
|
270
262
|
return new _PluvProcedure(__spreadProps(__spreadValues({}, this.config), {
|
|
271
263
|
sync: resolver
|
|
272
264
|
}));
|
|
@@ -347,8 +339,7 @@ var IORoom = class {
|
|
|
347
339
|
this._listeners = {
|
|
348
340
|
onDestroy: (event) => onDestroy == null ? void 0 : onDestroy(event)
|
|
349
341
|
};
|
|
350
|
-
if (authorize2)
|
|
351
|
-
this._authorize = authorize2;
|
|
342
|
+
if (authorize2) this._authorize = authorize2;
|
|
352
343
|
}
|
|
353
344
|
get _events() {
|
|
354
345
|
return this._router._events;
|
|
@@ -367,8 +358,7 @@ var IORoom = class {
|
|
|
367
358
|
getSize() {
|
|
368
359
|
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
369
360
|
return Array.from(this._sessions.values()).reduce((count, session) => {
|
|
370
|
-
if (session.quit)
|
|
371
|
-
return count;
|
|
361
|
+
if (session.quit) return count;
|
|
372
362
|
return currentTime - session.timers.ping > PING_TIMEOUT_MS ? count : count + 1;
|
|
373
363
|
}, 0);
|
|
374
364
|
}
|
|
@@ -377,8 +367,7 @@ var IORoom = class {
|
|
|
377
367
|
var _b;
|
|
378
368
|
const _a = options, { token } = _a, _platformEventContext = __objRest(_a, ["token"]);
|
|
379
369
|
const platformEventContext = _platformEventContext;
|
|
380
|
-
if (!this._uninitialize)
|
|
381
|
-
yield this._initialize();
|
|
370
|
+
if (!this._uninitialize) yield this._initialize();
|
|
382
371
|
const user = yield this._getAuthorizedUser(token, options);
|
|
383
372
|
const sessionId = this._platform.randomUUID();
|
|
384
373
|
const pluvWs = this._platform.convertWebSocket(webSocket, {
|
|
@@ -473,10 +462,8 @@ var IORoom = class {
|
|
|
473
462
|
return __async(this, null, function* () {
|
|
474
463
|
var _a;
|
|
475
464
|
const ioAuthorize = this._getIOAuthorize(context);
|
|
476
|
-
if (!ioAuthorize)
|
|
477
|
-
|
|
478
|
-
if (!token)
|
|
479
|
-
return null;
|
|
465
|
+
if (!ioAuthorize) return null;
|
|
466
|
+
if (!token) return null;
|
|
480
467
|
const payload = yield authorize({
|
|
481
468
|
platform: this._platform,
|
|
482
469
|
secret: ioAuthorize.secret
|
|
@@ -506,8 +493,7 @@ var IORoom = class {
|
|
|
506
493
|
}
|
|
507
494
|
_getProcedureInputs(message) {
|
|
508
495
|
const procedure = this._getProcedure(message);
|
|
509
|
-
if (!procedure)
|
|
510
|
-
return message.data;
|
|
496
|
+
if (!procedure) return message.data;
|
|
511
497
|
return procedure.config.input ? procedure.config.input.parse(message.data) : message.data;
|
|
512
498
|
}
|
|
513
499
|
_initialize() {
|
|
@@ -543,8 +529,7 @@ var IORoom = class {
|
|
|
543
529
|
}
|
|
544
530
|
_onClose(session, callback) {
|
|
545
531
|
return () => {
|
|
546
|
-
if (!this._uninitialize)
|
|
547
|
-
return;
|
|
532
|
+
if (!this._uninitialize) return;
|
|
548
533
|
session.quit = true;
|
|
549
534
|
this._logDebug(`${colors.blue(`(Unregistering connection for room ${this.id}:`)} ${session.id}`);
|
|
550
535
|
this._sessions.delete(session.id);
|
|
@@ -561,8 +546,7 @@ var IORoom = class {
|
|
|
561
546
|
const size = this.getSize();
|
|
562
547
|
this._logDebug(`${colors.blue(`Unregistered connection for room ${this.id}:`)} ${session.id}`);
|
|
563
548
|
this._logDebug(`${colors.blue(`Room ${this.id} size:`)} ${size}`);
|
|
564
|
-
if (size)
|
|
565
|
-
return;
|
|
549
|
+
if (size) return;
|
|
566
550
|
(_a = this._uninitialize) == null ? void 0 : _a.call(this);
|
|
567
551
|
});
|
|
568
552
|
};
|
|
@@ -577,18 +561,15 @@ var IORoom = class {
|
|
|
577
561
|
session,
|
|
578
562
|
sessions: this._sessions
|
|
579
563
|
};
|
|
580
|
-
if (!this._uninitialize)
|
|
581
|
-
return;
|
|
564
|
+
if (!this._uninitialize) return;
|
|
582
565
|
if (session.quit) {
|
|
583
566
|
session.webSocket.close(1011, "WebSocket broken.");
|
|
584
567
|
return;
|
|
585
568
|
}
|
|
586
569
|
const message = this._parseMessage(event);
|
|
587
|
-
if (!message)
|
|
588
|
-
return;
|
|
570
|
+
if (!message) return;
|
|
589
571
|
const procedure = this._getProcedure(message);
|
|
590
|
-
if (!procedure)
|
|
591
|
-
return;
|
|
572
|
+
if (!procedure) return;
|
|
592
573
|
let inputs;
|
|
593
574
|
try {
|
|
594
575
|
inputs = this._getProcedureInputs(message);
|
|
@@ -638,12 +619,9 @@ var IORoom = class {
|
|
|
638
619
|
_parseMessage(message) {
|
|
639
620
|
try {
|
|
640
621
|
const parsed = this._platform.parseData(message.data);
|
|
641
|
-
if (typeof parsed !== "object")
|
|
642
|
-
|
|
643
|
-
if (typeof parsed.
|
|
644
|
-
return null;
|
|
645
|
-
if (typeof parsed.data !== "object")
|
|
646
|
-
return null;
|
|
622
|
+
if (typeof parsed !== "object") return null;
|
|
623
|
+
if (typeof parsed.type !== "string") return null;
|
|
624
|
+
if (typeof parsed.data !== "object") return null;
|
|
647
625
|
return parsed;
|
|
648
626
|
} catch (e) {
|
|
649
627
|
return null;
|
|
@@ -683,11 +661,9 @@ var IORoom = class {
|
|
|
683
661
|
}
|
|
684
662
|
_sendSelfMessage(message, sender) {
|
|
685
663
|
const senderId = sender == null ? void 0 : sender.id;
|
|
686
|
-
if (!senderId)
|
|
687
|
-
return;
|
|
664
|
+
if (!senderId) return;
|
|
688
665
|
const session = this._sessions.get(senderId);
|
|
689
|
-
if (!session)
|
|
690
|
-
return;
|
|
666
|
+
if (!session) return;
|
|
691
667
|
session.webSocket.sendMessage(__spreadValues({
|
|
692
668
|
connectionId: sender.id,
|
|
693
669
|
room: this.id,
|
|
@@ -697,8 +673,7 @@ var IORoom = class {
|
|
|
697
673
|
_sendSyncMessage(message, sender) {
|
|
698
674
|
var _a;
|
|
699
675
|
const senderId = sender == null ? void 0 : sender.id;
|
|
700
|
-
if (!senderId)
|
|
701
|
-
return;
|
|
676
|
+
if (!senderId) return;
|
|
702
677
|
const context = {
|
|
703
678
|
context: this._context,
|
|
704
679
|
doc: this._doc,
|
|
@@ -707,8 +682,7 @@ var IORoom = class {
|
|
|
707
682
|
sessions: this._sessions
|
|
708
683
|
};
|
|
709
684
|
const resolver = (_a = this._getProcedure(message)) == null ? void 0 : _a.config.sync;
|
|
710
|
-
if (!resolver)
|
|
711
|
-
return;
|
|
685
|
+
if (!resolver) return;
|
|
712
686
|
let inputs;
|
|
713
687
|
try {
|
|
714
688
|
inputs = this._getProcedureInputs(message);
|
|
@@ -716,8 +690,7 @@ var IORoom = class {
|
|
|
716
690
|
return;
|
|
717
691
|
}
|
|
718
692
|
Promise.resolve(resolver(inputs, context)).then((output) => {
|
|
719
|
-
if (!output)
|
|
720
|
-
return;
|
|
693
|
+
if (!output) return;
|
|
721
694
|
Object.keys(output).forEach((type) => {
|
|
722
695
|
var _a2, _b;
|
|
723
696
|
const data = (_a2 = output[type]) != null ? _a2 : {};
|
|
@@ -735,7 +708,7 @@ var IORoom = class {
|
|
|
735
708
|
};
|
|
736
709
|
|
|
737
710
|
// src/version.generated.ts
|
|
738
|
-
var version = "0.
|
|
711
|
+
var version = "0.20.0";
|
|
739
712
|
|
|
740
713
|
// src/PluvServer.ts
|
|
741
714
|
var PluvServer = class {
|
|
@@ -758,10 +731,8 @@ var PluvServer = class {
|
|
|
758
731
|
this._debug = debug;
|
|
759
732
|
this._platform = platform;
|
|
760
733
|
this._router = router != null ? router : null;
|
|
761
|
-
if (authorize2)
|
|
762
|
-
|
|
763
|
-
if (context)
|
|
764
|
-
this._context = context;
|
|
734
|
+
if (authorize2) this._authorize = authorize2;
|
|
735
|
+
if (context) this._context = context;
|
|
765
736
|
this._listeners = {
|
|
766
737
|
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
767
738
|
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event)
|
|
@@ -792,8 +763,7 @@ var PluvServer = class {
|
|
|
792
763
|
}
|
|
793
764
|
const platform = this._platform;
|
|
794
765
|
const oldRoom = this._rooms.get(room);
|
|
795
|
-
if (oldRoom)
|
|
796
|
-
return oldRoom;
|
|
766
|
+
if (oldRoom) return oldRoom;
|
|
797
767
|
const roomContext = __spreadValues(__spreadValues({}, this._context), platformRoomContext);
|
|
798
768
|
const newRoom = new IORoom(room, {
|
|
799
769
|
authorize: (_b = this._authorize) != null ? _b : void 0,
|
|
@@ -831,8 +801,7 @@ var PluvServer = class {
|
|
|
831
801
|
_purgeEmptyRooms() {
|
|
832
802
|
const rooms = Array.from(this._rooms.entries());
|
|
833
803
|
rooms.forEach(([id, room]) => {
|
|
834
|
-
if (room.getSize())
|
|
835
|
-
return;
|
|
804
|
+
if (room.getSize()) return;
|
|
836
805
|
this._rooms.delete(id);
|
|
837
806
|
});
|
|
838
807
|
}
|
|
@@ -858,8 +827,7 @@ var PluvIO = class {
|
|
|
858
827
|
}),
|
|
859
828
|
$INITIALIZE_SESSION: this.procedure.broadcast((data, { session }) => {
|
|
860
829
|
const presence = data == null ? void 0 : data.presence;
|
|
861
|
-
if (!session)
|
|
862
|
-
return {};
|
|
830
|
+
if (!session) return {};
|
|
863
831
|
session.presence = presence;
|
|
864
832
|
return {
|
|
865
833
|
$USER_JOINED: {
|
|
@@ -887,16 +855,14 @@ var PluvIO = class {
|
|
|
887
855
|
return { $STORAGE_RECEIVED: { state } };
|
|
888
856
|
})),
|
|
889
857
|
$PING: this.procedure.self((data, { session }) => {
|
|
890
|
-
if (!session)
|
|
891
|
-
return {};
|
|
858
|
+
if (!session) return {};
|
|
892
859
|
const currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
893
860
|
session.timers.ping = currentTime;
|
|
894
861
|
return { $PONG: {} };
|
|
895
862
|
}),
|
|
896
863
|
$UPDATE_PRESENCE: this.procedure.broadcast((data, { session }) => {
|
|
897
864
|
const presence = data == null ? void 0 : data.presence;
|
|
898
|
-
if (!session)
|
|
899
|
-
return {};
|
|
865
|
+
if (!session) return {};
|
|
900
866
|
session.presence = Object.assign(/* @__PURE__ */ Object.create(null), session.presence, presence);
|
|
901
867
|
return { $PRESENCE_UPDATED: { presence } };
|
|
902
868
|
}),
|
|
@@ -935,12 +901,9 @@ var PluvIO = class {
|
|
|
935
901
|
this._crdt = crdt;
|
|
936
902
|
this._debug = debug;
|
|
937
903
|
this._platform = platform;
|
|
938
|
-
if (authorize2)
|
|
939
|
-
|
|
940
|
-
if (
|
|
941
|
-
this._context = context;
|
|
942
|
-
if (getInitialStorage)
|
|
943
|
-
this._getInitialStorage = getInitialStorage;
|
|
904
|
+
if (authorize2) this._authorize = authorize2;
|
|
905
|
+
if (context) this._context = context;
|
|
906
|
+
if (getInitialStorage) this._getInitialStorage = getInitialStorage;
|
|
944
907
|
this._listeners = {
|
|
945
908
|
onRoomDeleted: (event) => onRoomDeleted == null ? void 0 : onRoomDeleted(event),
|
|
946
909
|
onStorageUpdated: (event) => onStorageUpdated == null ? void 0 : onStorageUpdated(event)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/io",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "@pluv/io server-side websocket manager",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,20 +17,20 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@panva/hkdf": "^1.
|
|
21
|
-
"jose": "^5.3
|
|
20
|
+
"@panva/hkdf": "^1.2.1",
|
|
21
|
+
"jose": "^5.6.3",
|
|
22
22
|
"kleur": "^4.1.5",
|
|
23
23
|
"wonka": "^6.3.4",
|
|
24
|
-
"@pluv/crdt": "^0.
|
|
25
|
-
"@pluv/types": "^0.
|
|
24
|
+
"@pluv/crdt": "^0.20.0",
|
|
25
|
+
"@pluv/types": "^0.20.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^8.57.0",
|
|
29
29
|
"genversion": "^3.2.0",
|
|
30
|
-
"tsup": "^8.0
|
|
30
|
+
"tsup": "^8.1.0",
|
|
31
31
|
"typescript": "^5.4.5",
|
|
32
|
-
"@pluv/tsconfig": "^0.
|
|
33
|
-
"eslint-config-pluv": "^0.
|
|
32
|
+
"@pluv/tsconfig": "^0.20.0",
|
|
33
|
+
"eslint-config-pluv": "^0.20.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "pnpm run version && tsup src/index.ts --format esm,cjs --dts",
|
package/src/version.generated.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '0.20.0'
|