@eleven-am/pondsocket 0.1.173 → 0.1.174

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.
@@ -46,12 +46,12 @@ class DistributedManager extends manager_1.Manager {
46
46
  return this.broadcast(message);
47
47
  }
48
48
  setAssigns(userId, data) {
49
- this.processAssignsData(manager_1.ActionTypes.CREATE, userId, data);
50
- __classPrivateFieldGet(this, _DistributedManager_client, "f").publishAssignsChange(userId, data);
49
+ const assigns = this.processAssignsData(manager_1.ActionTypes.CREATE, userId, data);
50
+ __classPrivateFieldGet(this, _DistributedManager_client, "f").publishAssignsChange(userId, assigns);
51
51
  }
52
52
  updateAssigns(userId, data) {
53
- this.processAssignsData(manager_1.ActionTypes.UPDATE, userId, data);
54
- __classPrivateFieldGet(this, _DistributedManager_client, "f").publishAssignsChange(userId, data);
53
+ const assigns = this.processAssignsData(manager_1.ActionTypes.UPDATE, userId, data);
54
+ __classPrivateFieldGet(this, _DistributedManager_client, "f").publishAssignsChange(userId, assigns);
55
55
  }
56
56
  removeAssigns(userId) {
57
57
  this.processAssignsData(manager_1.ActionTypes.DELETE, userId, null);
@@ -50,32 +50,16 @@ class Manager {
50
50
  get userIds() {
51
51
  return new Set(this.assignsCache.keys());
52
52
  }
53
- /**
54
- * @desc Initializes the data manager
55
- * @param unsubscribe - The callback to call when the manager is closed
56
- */
57
53
  initialize(unsubscribe) {
58
54
  __classPrivateFieldSet(this, _Manager_onClose, unsubscribe, "f");
59
55
  return Promise.resolve();
60
56
  }
61
- /**
62
- * @desc Returns the presence of a user
63
- * @param userId - The id of the user
64
- */
65
57
  getPresence(userId) {
66
58
  return this.presenceCache.get(userId) || null;
67
59
  }
68
- /**
69
- * @desc Returns all the presence
70
- */
71
60
  getAllPresence() {
72
61
  return new Map(this.presenceCache);
73
62
  }
74
- /**
75
- * @desc Creates or updates the presence of a user
76
- * @param userId - The id of the user
77
- * @param data - The presence data
78
- */
79
63
  upsertPresence(userId, data) {
80
64
  if (this.presenceCache.has(userId)) {
81
65
  this.updatePresence(userId, data);
@@ -84,22 +68,12 @@ class Manager {
84
68
  this.trackPresence(userId, data);
85
69
  }
86
70
  }
87
- /**
88
- * @desc Returns the assigns of a user
89
- * @param userId - The id of the user
90
- */
91
71
  getAssigns(userId) {
92
72
  return this.assignsCache.get(userId) || null;
93
73
  }
94
- /**
95
- * @desc Returns all the assigns
96
- */
97
74
  getAllAssigns() {
98
75
  return new Map(this.assignsCache);
99
76
  }
100
- /**
101
- * @desc Closes the data manager
102
- */
103
77
  close() {
104
78
  var _a;
105
79
  this.publisher.close();
@@ -109,12 +83,6 @@ class Manager {
109
83
  this.userSubscriptions.clear();
110
84
  (_a = __classPrivateFieldGet(this, _Manager_onClose, "f")) === null || _a === void 0 ? void 0 : _a.call(this);
111
85
  }
112
- /**
113
- * @desc Subscribes to incoming messages
114
- * @param userId - The id of the user
115
- * @param assigns - The assigns of the user
116
- * @param onMessage - The callback to call when a message is received
117
- */
118
86
  addUser(userId, assigns, onMessage) {
119
87
  this.setAssigns(userId, assigns);
120
88
  const subscription = this.publisher.subscribe((_a) => {
@@ -125,10 +93,6 @@ class Manager {
125
93
  });
126
94
  this.userSubscriptions.set(userId, subscription);
127
95
  }
128
- /**
129
- * @desc Unsubscribes from incoming messages
130
- * @param userId - The id of the user
131
- */
132
96
  removeUser(userId) {
133
97
  var _a;
134
98
  const userData = this.getUserData(userId);
@@ -141,10 +105,6 @@ class Manager {
141
105
  }
142
106
  return userData;
143
107
  }
144
- /**
145
- * @desc Returns the data of a user
146
- * @param userId - The id of the user
147
- */
148
108
  getUserData(userId) {
149
109
  const presence = this.getPresence(userId);
150
110
  const assigns = this.getAssigns(userId);
@@ -159,15 +119,8 @@ class Manager {
159
119
  id: userId,
160
120
  };
161
121
  }
162
- /**
163
- * @desc Processes presence data
164
- * @param action - The action to perform
165
- * @param userId - The id of the user
166
- * @param data - The presence data
167
- */
168
122
  processPresenceData(action, userId, data) {
169
- const current = data ? data : this.presenceCache.get(userId);
170
- __classPrivateFieldGet(this, _Manager_instances, "m", _Manager_processData).call(this, this.presenceCache, DataTypes.PRESENCE, action, userId, data);
123
+ const current = __classPrivateFieldGet(this, _Manager_instances, "m", _Manager_processData).call(this, this.presenceCache, DataTypes.PRESENCE, action, userId, data);
171
124
  const total = Array.from(this.presenceCache.values());
172
125
  const userIds = Array.from(this.presenceCache.keys());
173
126
  const event = action === ActionTypes.CREATE ? pondsocket_common_1.PresenceEventTypes.JOIN : action === ActionTypes.UPDATE ? pondsocket_common_1.PresenceEventTypes.UPDATE : pondsocket_common_1.PresenceEventTypes.LEAVE;
@@ -183,14 +136,8 @@ class Manager {
183
136
  },
184
137
  };
185
138
  }
186
- /**
187
- * @desc Processes assigns data
188
- * @param action - The action to perform
189
- * @param userId - The id of the user
190
- * @param data - The assigns data
191
- */
192
139
  processAssignsData(action, userId, data) {
193
- __classPrivateFieldGet(this, _Manager_instances, "m", _Manager_processData).call(this, this.assignsCache, DataTypes.ASSIGNS, action, userId, data);
140
+ return __classPrivateFieldGet(this, _Manager_instances, "m", _Manager_processData).call(this, this.assignsCache, DataTypes.ASSIGNS, action, userId, data);
194
141
  }
195
142
  }
196
143
  exports.Manager = Manager;
@@ -210,10 +157,12 @@ _Manager_onClose = new WeakMap(), _Manager_instances = new WeakSet(), _Manager_p
210
157
  const code = 400;
211
158
  throw new httpError_1.HttpError(code, message);
212
159
  }
160
+ const current = cache.get(userId);
213
161
  if (data) {
214
- cache.set(userId, data);
215
- }
216
- else {
217
- cache.delete(userId);
162
+ const updated = Object.assign(Object.assign({}, current), data);
163
+ cache.set(userId, updated);
164
+ return updated;
218
165
  }
166
+ cache.delete(userId);
167
+ return current || {};
219
168
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.173",
3
+ "version": "0.1.174",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",