-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hard-coded the allowed role and server registation for question command
- Loading branch information
1 parent
da3cfc6
commit 8f3b49d
Showing
4 changed files
with
54 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export function handleBigInts(obj: any, seen = new WeakSet()): any { | ||
if (typeof obj === 'bigint') { | ||
return obj.toString(); // Convert BigInt to a string | ||
} else if (Array.isArray(obj)) { | ||
return obj.map((item) => handleBigInts(item, seen)); // Process arrays element-wise | ||
} else if (typeof obj === 'object' && obj !== null) { | ||
if (seen.has(obj)) { | ||
// If we've seen this object before, don't process it again | ||
return; | ||
} | ||
seen.add(obj); // Mark this object as seen | ||
|
||
const result: any = {}; | ||
for (const [key, value] of Object.entries(obj)) { | ||
result[key] = handleBigInts(value, seen); // Recursively process nested objects | ||
} | ||
return result; | ||
} | ||
return obj; // Return the value unchanged if it's neither an object nor a BigInt | ||
} | ||
|
||
|
||
export function removeCircularReferences(obj: any, parent = null) { | ||
const seenObjects = new WeakMap(); | ||
|
||
function detect(obj: any, parent: any) { | ||
if (obj && typeof obj === 'object') { | ||
if (seenObjects.has(obj)) { | ||
return '[Circular]'; | ||
} | ||
seenObjects.set(obj, true); | ||
|
||
Object.keys(obj).forEach(key => { | ||
if (typeof obj[key] === 'object' && obj[key] !== null) { | ||
if (parent === obj[key]) { | ||
obj[key] = '[Circular]'; | ||
} else { | ||
detect(obj[key], obj); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
detect(obj, parent); | ||
return obj; | ||
} |