MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / _handleRequest

Method _handleRequest

apps/realtime-server/src/sockets.ts:167–229  ·  view source on GitHub ↗
(decoder: decoding.Decoder)

Source from the content-addressed store, hash-verified

165 }
166 }
167 private async _handleRequest(decoder: decoding.Decoder) {
168 // Gather commands
169
170 const firstCommandId = decoding.readVarUint(decoder);
171
172 const commandCount = decoding.readVarUint(decoder);
173
174 let commands: RealtimeCommand[] = [];
175
176 for (let i = 0; i < commandCount; i++) {
177 const commandType = decoding.readVarUint(decoder);
178 const commandArgs = unpack(decoding.readVarUint8Array(decoder));
179
180 commands.push({
181 id: firstCommandId + i,
182 type: commandType,
183 args: commandArgs,
184 });
185 }
186
187 // Execute commands and gather results
188
189 const promises: PromiseLike<any>[] = [];
190
191 for (const command of commands) {
192 promises.push(this._handleCommand(command));
193 }
194
195 const results = await Promise.allSettled(promises);
196
197 if (this._dataNotificationBuffer.length > 0) {
198 this._flushDataNotificationBuffer();
199 }
200
201 // Encode and send response
202
203 commands = commands.filter(
204 (command) => command.type === RealtimeCommandType.HGET,
205 );
206
207 if (commands.length === 0) {
208 return;
209 }
210
211 const encoder = encoding.createEncoder();
212
213 encoding.writeVarUint(encoder, RealtimeServerMessageType.RESPONSE);
214
215 encoding.writeVarUint(encoder, commands.length);
216
217 for (const command of commands) {
218 const commandIndex = command.id - firstCommandId;
219
220 encoding.writeVarUint(encoder, command.id);
221
222 encoding.writeVarUint8Array(
223 encoder,
224 pack((results[commandIndex] as any).value),

Callers 1

_handleMessageMethod · 0.95

Calls 2

_handleCommandMethod · 0.95
sendMethod · 0.80

Tested by

no test coverage detected