MCPcopy Create free account
hub / github.com/Snapchat/Valdi / dispatchMessage

Method dispatchMessage

npm_modules/cli/src/utils/daemonClient.ts:184–233  ·  view source on GitHub ↗
(msg: Record<string, unknown>)

Source from the content-addressed store, hash-verified

182 reject: (err: Error) => void;
183}
184
185interface PendingPayloadRequest extends PendingRequest {
186 maxPayloadBytes: number;
187}
188
189const MAX_DAEMON_TRACE_EVENT_COUNT = 10_000;
190const MAX_DAEMON_TRACE_NAME_BYTES = 2048;
191const MAX_DAEMON_TRACE_CONTEXT_ID_BYTES = 4096;
192const MAX_DAEMON_TRACE_ERROR_BYTES = 64 * 1024;
193
194function isRecord(value: unknown): value is Record<string, unknown> {
195 return value !== null && typeof value === 'object' && !Array.isArray(value);
196}
197
198function isPerformanceTraceMessageType(value: unknown): boolean {
199 return (
200 value === DaemonMsgType.PERFORMANCE_TRACE_STATUS_REQUEST ||
201 value === DaemonMsgType.PERFORMANCE_TRACE_STATUS_RESPONSE ||
202 value === DaemonMsgType.PERFORMANCE_TRACE_START_REQUEST ||
203 value === DaemonMsgType.PERFORMANCE_TRACE_START_RESPONSE ||
204 value === DaemonMsgType.PERFORMANCE_TRACE_STOP_REQUEST ||
205 value === DaemonMsgType.PERFORMANCE_TRACE_STOP_RESPONSE
206 );
207}
208
209function isPerformanceTraceRequestType(value: DaemonMsgType): boolean {
210 return (
211 value === DaemonMsgType.PERFORMANCE_TRACE_STATUS_REQUEST ||
212 value === DaemonMsgType.PERFORMANCE_TRACE_START_REQUEST ||
213 value === DaemonMsgType.PERFORMANCE_TRACE_STOP_REQUEST
214 );
215}
216
217function assertOptionalFiniteNumber(body: Record<string, unknown>, key: string): void {
218 const value = body[key];
219 if (value !== undefined && (typeof value !== 'number' || !Number.isFinite(value))) {
220 throw new TypeError(`Valdi runtime trace response has an invalid ${key}.`);
221 }
222}
223
224function assertOptionalBoundedString(
225 body: Record<string, unknown>,
226 key: string,
227 maximumBytes: number,
228 allowEmpty: boolean,
229): void {
230 const value = body[key];
231 if (
232 value !== undefined &&
233 (typeof value !== 'string' ||
234 (!allowEmpty && value.length === 0) ||
235 Buffer.byteLength(value, 'utf8') > maximumBytes)
236 ) {

Callers 1

drainBufferMethod · 0.95

Calls 10

encodePacketFunction · 0.85
keysMethod · 0.65
writeMethod · 0.65
resolveMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65
StringClass · 0.50
findMethod · 0.45
parseMethod · 0.45
rejectMethod · 0.45

Tested by

no test coverage detected