@base44-preview/sdk 0.8.28-pr.174.de9ee36 → 0.8.29-pr.176.30c5ce1

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.
@@ -130,7 +130,7 @@ export interface AuthModule {
130
130
  *
131
131
  * You can update `role` and any [custom fields](/developers/backend/resources/entities/user-schema#custom-fields) defined in your
132
132
  * User entity schema.
133
- * The `role` value must match one of the defined options.
133
+ * The `role` value must be either `'user'` or `'admin'`.
134
134
  * <Note>
135
135
  * The following fields are read-only and can't be changed with this method:
136
136
  * `id`, `email`, `full_name`, `created_date`, `updated_date`, and `created_by`.
@@ -1,5 +1,6 @@
1
1
  import { io } from "socket.io-client";
2
2
  import { getAccessToken } from "./auth-utils.js";
3
+ const ROOM_LEAVE_GRACE_MS = 250;
3
4
  function initializeSocket(config, handlers) {
4
5
  var _a;
5
6
  const socket = io(config.serverUrl, {
@@ -33,13 +34,17 @@ function initializeSocket(config, handlers) {
33
34
  export function RoomsSocket({ config }) {
34
35
  let currentConfig = { ...config };
35
36
  const roomsToListeners = {};
37
+ const pendingRoomLeaves = {};
36
38
  const handlers = {
37
39
  connect: async () => {
38
40
  const promises = [];
39
41
  Object.keys(roomsToListeners).forEach((room) => {
40
- joinRoom(room);
41
42
  const listeners = getListeners(room);
42
- listeners === null || listeners === void 0 ? void 0 : listeners.forEach(({ connect }) => {
43
+ if (listeners.length === 0) {
44
+ return;
45
+ }
46
+ joinRoom(room);
47
+ listeners.forEach(({ connect }) => {
43
48
  const promise = async () => connect === null || connect === void 0 ? void 0 : connect();
44
49
  promises.push(promise());
45
50
  });
@@ -88,20 +93,49 @@ export function RoomsSocket({ config }) {
88
93
  return (_a = handlers.update_model) === null || _a === void 0 ? void 0 : _a.call(handlers, { room, data: dataStr });
89
94
  }
90
95
  function getListeners(room) {
91
- return roomsToListeners[room];
96
+ var _a;
97
+ return (_a = roomsToListeners[room]) !== null && _a !== void 0 ? _a : [];
98
+ }
99
+ function cancelPendingRoomLeave(room) {
100
+ const pendingLeave = pendingRoomLeaves[room];
101
+ if (!pendingLeave) {
102
+ return;
103
+ }
104
+ clearTimeout(pendingLeave);
105
+ delete pendingRoomLeaves[room];
106
+ }
107
+ function scheduleRoomLeave(room) {
108
+ cancelPendingRoomLeave(room);
109
+ pendingRoomLeaves[room] = setTimeout(() => {
110
+ var _a, _b;
111
+ delete pendingRoomLeaves[room];
112
+ if (((_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
113
+ return;
114
+ }
115
+ leaveRoom(room);
116
+ delete roomsToListeners[room];
117
+ }, ROOM_LEAVE_GRACE_MS);
92
118
  }
93
119
  const subscribeToRoom = (room, handlers) => {
94
- if (!roomsToListeners[room]) {
120
+ if (roomsToListeners[room]) {
121
+ cancelPendingRoomLeave(room);
122
+ }
123
+ else {
95
124
  joinRoom(room);
96
125
  roomsToListeners[room] = [];
97
126
  }
98
127
  roomsToListeners[room].push(handlers);
128
+ let unsubscribed = false;
99
129
  return () => {
100
130
  var _a, _b;
131
+ if (unsubscribed) {
132
+ return;
133
+ }
134
+ unsubscribed = true;
101
135
  roomsToListeners[room] =
102
136
  (_b = (_a = roomsToListeners[room]) === null || _a === void 0 ? void 0 : _a.filter((listener) => listener !== handlers)) !== null && _b !== void 0 ? _b : [];
103
137
  if (roomsToListeners[room].length === 0) {
104
- leaveRoom(room);
138
+ scheduleRoomLeave(room);
105
139
  }
106
140
  };
107
141
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.28-pr.174.de9ee36",
3
+ "version": "0.8.29-pr.176.30c5ce1",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",