Class: PayloadWalkerWithDeduplication\<T\>
Gala Launchpad SDK 9.0.0-rc.5 / index / PayloadWalkerWithDeduplication
Class: PayloadWalkerWithDeduplication<T>
Defined in: packages/launchpad-sdk/dist/utils/websocket-patterns.d.ts:158
Payload Walker with Deduplication
Recursively walks through object payloads to extract events while deduplicating by a key (e.g., transactionId, eventId). Prevents duplicate processing of the same event across multiple payload traversals.
Used to find events nested at various depths in WebSocket payloads.
Features:
- Recursive depth limiting (prevents DoS from circular structures)
- WeakSet tracking to prevent infinite loops on circular references
- Configurable deduplication key
- Callback-based event processing
Example
// Test case: Recursive payload walking with deduplication
const walker = new PayloadWalkerWithDeduplication<{ id: string; value: number }>(
(obj) => {
// Extraction predicate: return event if found
return obj.id && obj.value ? { id: obj.id, value: obj.value } : null;
},
(event) => event.id // Deduplication key
);
// First walk - extracts new events
const events1 = walker.walk({
Data: { id: 'e1', value: 100 },
nested: { id: 'e2', value: 200 }
});
console.assert(events1.length === 2);
// Second walk - skips already seen events
const events2 = walker.walk({
Data: { id: 'e1', value: 999 }, // Already seen, skipped
other: { id: 'e3', value: 300 } // New, included
});
console.assert(events2.length === 1);
console.assert(events2[0].id === 'e3');
// Reset deduplication to reprocess all events
walker.reset();
const events3 = walker.walk({ Data: { id: 'e1', value: 100 } });
console.assert(events3.length === 1); // e1 is processed again
Since
6.6.0
Type Parameters
T
T
Event type being extracted
Constructors
Constructor
new PayloadWalkerWithDeduplication<
T>(extractor,dedupeKeyFn,maxDepth?):PayloadWalkerWithDeduplication<T>
Defined in: packages/launchpad-sdk/dist/utils/websocket-patterns.d.ts:163
Parameters
extractor
(obj) => T | null
dedupeKeyFn
(event) => string
maxDepth?
number
Returns
PayloadWalkerWithDeduplication<T>
Methods
getSeenCount()
getSeenCount():
number
Defined in: packages/launchpad-sdk/dist/utils/websocket-patterns.d.ts:180
Get count of deduplicated events
Returns
number
Number of unique events seen so far
reset()
reset():
void
Defined in: packages/launchpad-sdk/dist/utils/websocket-patterns.d.ts:174
Reset deduplication state to reprocess all events
Returns
void
walk()
walk(
payload):T[]
Defined in: packages/launchpad-sdk/dist/utils/websocket-patterns.d.ts:170
Walk through a payload and extract events
Parameters
payload
unknown
Root object to traverse
Returns
T[]
Array of extracted events not previously seen