@instantdb/core 0.22.131 → 0.22.132

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instantdb/core",
3
- "version": "0.22.131",
3
+ "version": "0.22.132",
4
4
  "description": "Instant's core local abstraction",
5
5
  "homepage": "https://github.com/instantdb/instant/tree/main/client/packages/core",
6
6
  "repository": {
@@ -53,7 +53,7 @@
53
53
  "dependencies": {
54
54
  "mutative": "^1.0.10",
55
55
  "uuid": "^11.1.0",
56
- "@instantdb/version": "0.22.131"
56
+ "@instantdb/version": "0.22.132"
57
57
  },
58
58
  "scripts": {
59
59
  "test": "vitest",
package/src/Reactor.js CHANGED
@@ -251,7 +251,7 @@ export default class Reactor {
251
251
  /** @type BroadcastChannel | undefined */
252
252
  _broadcastChannel;
253
253
 
254
- /** @type {Record<string, {isConnected: boolean; error: any}>} */
254
+ /** @type {Record<string, {roomType: string; isConnected: boolean; error: any}>} */
255
255
  _rooms = {};
256
256
  /** @type {Record<string, boolean>} */
257
257
  _roomsPendingLeave = {};
@@ -618,7 +618,8 @@ export default class Reactor {
618
618
 
619
619
  for (const roomId of Object.keys(this._rooms)) {
620
620
  const enqueuedUserPresence = this._presence[roomId]?.result?.user;
621
- this._tryJoinRoom(roomId, enqueuedUserPresence);
621
+ const roomType = this._rooms[roomId]?.roomType;
622
+ this._tryJoinRoom(roomType, roomId, enqueuedUserPresence);
622
623
  }
623
624
  break;
624
625
  }
@@ -2227,15 +2228,17 @@ export default class Reactor {
2227
2228
  // Rooms
2228
2229
 
2229
2230
  /**
2231
+ * @param {string} roomType
2230
2232
  * @param {string} roomId
2231
2233
  * @param {any | null | undefined} [initialPresence] -- initial presence data to send when joining the room
2232
2234
  * @returns () => void
2233
2235
  */
2234
- joinRoom(roomId, initialPresence) {
2236
+ joinRoom(roomType, roomId, initialPresence) {
2235
2237
  let needsToSendJoin = false;
2236
2238
  if (!this._rooms[roomId]) {
2237
2239
  needsToSendJoin = true;
2238
2240
  this._rooms[roomId] = {
2241
+ roomType,
2239
2242
  isConnected: false,
2240
2243
  error: undefined,
2241
2244
  };
@@ -2250,7 +2253,7 @@ export default class Reactor {
2250
2253
  }
2251
2254
 
2252
2255
  if (needsToSendJoin) {
2253
- this._tryJoinRoom(roomId, initialPresence);
2256
+ this._tryJoinRoom(roomType, roomId, initialPresence);
2254
2257
  }
2255
2258
 
2256
2259
  return () => {
@@ -2326,8 +2329,13 @@ export default class Reactor {
2326
2329
  });
2327
2330
  }
2328
2331
 
2329
- _tryJoinRoom(roomId, data) {
2330
- this._trySendAuthed(uuid(), { op: 'join-room', 'room-id': roomId, data });
2332
+ _tryJoinRoom(roomType, roomId, data) {
2333
+ this._trySendAuthed(uuid(), {
2334
+ op: 'join-room',
2335
+ 'room-type': roomType,
2336
+ 'room-id': roomId,
2337
+ data,
2338
+ });
2331
2339
  delete this._roomsPendingLeave[roomId];
2332
2340
  }
2333
2341
 
@@ -2345,6 +2353,7 @@ export default class Reactor {
2345
2353
  // TODO: look into typing again
2346
2354
  subscribePresence(roomType, roomId, opts, cb) {
2347
2355
  const leaveRoom = this.joinRoom(
2356
+ roomType,
2348
2357
  roomId,
2349
2358
  // Oct 28, 2025
2350
2359
  // Note: initialData is deprecated.
@@ -2459,8 +2468,8 @@ export default class Reactor {
2459
2468
  });
2460
2469
  }
2461
2470
 
2462
- subscribeTopic(roomId, topic, cb) {
2463
- const leaveRoom = this.joinRoom(roomId);
2471
+ subscribeTopic(roomType, roomId, topic, cb) {
2472
+ const leaveRoom = this.joinRoom(roomType, roomId);
2464
2473
 
2465
2474
  this._broadcastSubs[roomId] = this._broadcastSubs[roomId] || {};
2466
2475
  this._broadcastSubs[roomId][topic] =
package/src/index.ts CHANGED
@@ -689,19 +689,23 @@ class InstantCoreDatabase<
689
689
  * unsubscribeTopic();
690
690
  * room.leaveRoom();
691
691
  */
692
- joinRoom<RoomType extends keyof RoomsOf<Schema>>(
692
+ joinRoom<RoomType extends string & keyof RoomsOf<Schema>>(
693
693
  roomType: RoomType = '_defaultRoomType' as RoomType,
694
694
  roomId: string = '_defaultRoomId',
695
695
  opts?: {
696
696
  initialPresence?: Partial<PresenceOf<Schema, RoomType>>;
697
697
  },
698
698
  ): RoomHandle<PresenceOf<Schema, RoomType>, TopicsOf<Schema, RoomType>> {
699
- const leaveRoom = this._reactor.joinRoom(roomId, opts?.initialPresence);
699
+ const leaveRoom = this._reactor.joinRoom(
700
+ roomType,
701
+ roomId,
702
+ opts?.initialPresence,
703
+ );
700
704
 
701
705
  return {
702
706
  leaveRoom,
703
707
  subscribeTopic: (topic, onEvent) =>
704
- this._reactor.subscribeTopic(roomId, topic, onEvent),
708
+ this._reactor.subscribeTopic(roomType, roomId, topic, onEvent),
705
709
  subscribePresence: (opts, onChange) =>
706
710
  this._reactor.subscribePresence(roomType, roomId, opts, onChange),
707
711
  publishTopic: (topic, data) =>