MCPcopy Create free account
hub / github.com/clawbot7/cli-gateway / extractDeepStringArrayByKeys

Function extractDeepStringArrayByKeys

src/channels/discord.ts:883–933  ·  view source on GitHub ↗
(root: unknown, keys: string[])

Source from the content-addressed store, hash-verified

881}
882
883function extractDeepStringArrayByKeys(root: unknown, keys: string[]): string[] {
884 const wanted = new Set(
885 keys
886 .map((item) => normalizePermissionKey(item))
887 .filter(Boolean),
888 );
889 if (wanted.size === 0) return [];
890
891 for (const node of iteratePermissionNodes(root)) {
892 if (!node || typeof node !== 'object' || Array.isArray(node)) continue;
893 const record = node as Record<string, unknown>;
894
895 for (const [rawKey, rawValue] of Object.entries(record)) {
896 const normalizedKey = normalizePermissionKey(rawKey);
897 const value = parseJsonContainer(rawValue);
898 if (wanted.has(normalizedKey)) {
899 const direct = coercePermissionStringArray(value);
900 if (direct.length > 0) return direct;
901
902 const single = coercePermissionString(value);
903 if (single) return [single];
904 }
905
906 if (
907 (normalizedKey === 'name' ||
908 normalizedKey === 'key' ||
909 normalizedKey === 'field') &&
910 typeof value === 'string'
911 ) {
912 const namedKey = normalizePermissionKey(value);
913 if (!wanted.has(namedKey)) continue;
914
915 const pairValue = parseJsonContainer(
916 record.value ??
917 record.val ??
918 record.argument ??
919 record.arg ??
920 record.content,
921 );
922
923 const pairArray = coercePermissionStringArray(pairValue);
924 if (pairArray.length > 0) return pairArray;
925
926 const pairSingle = coercePermissionString(pairValue);
927 if (pairSingle) return [pairSingle];
928 }
929 }
930 }
931
932 return [];
933}
934
935function* iteratePermissionNodes(root: unknown): Generator<unknown> {
936 const queue: unknown[] = [parseJsonContainer(root)];

Callers 1

extractStringArrayFunction · 0.70

Calls 5

normalizePermissionKeyFunction · 0.70
iteratePermissionNodesFunction · 0.70
parseJsonContainerFunction · 0.70
coercePermissionStringFunction · 0.70

Tested by

no test coverage detected