MCPcopy Index your code
hub / github.com/Effect-TS/effect / getIndexedEntries

Function getIndexedEntries

packages/effect/src/internal/configProvider.ts:755–799  ·  view source on GitHub ↗
(
  config: JsonMap
)

Source from the content-addressed store, hash-verified

753}
754
755const getIndexedEntries = (
756 config: JsonMap
757): ReadonlyArray<[path: ReadonlyArray<KeyComponent>, value: string]> => {
758 const loopAny = (
759 path: ReadonlyArray<KeyComponent>,
760 value: string | number | boolean | JsonMap | JsonArray | null
761 ): ReadonlyArray<[path: ReadonlyArray<KeyComponent>, value: string]> => {
762 if (typeof value === "string") {
763 return Arr.make([path, value] as [ReadonlyArray<KeyComponent>, string])
764 }
765 if (typeof value === "number" || typeof value === "boolean") {
766 return Arr.make([path, String(value)] as [ReadonlyArray<KeyComponent>, string])
767 }
768 if (Arr.isArray(value)) {
769 return loopArray(path, value)
770 }
771 if (typeof value === "object" && value !== null) {
772 return loopObject(path, value)
773 }
774 return Arr.empty<[ReadonlyArray<KeyComponent>, string]>()
775 }
776 const loopArray = (
777 path: ReadonlyArray<KeyComponent>,
778 values: JsonArray
779 ): ReadonlyArray<[path: ReadonlyArray<KeyComponent>, value: string]> =>
780 Arr.match(values, {
781 onEmpty: () => Arr.make([path, "<nil>"] as [ReadonlyArray<KeyComponent>, string]),
782 onNonEmpty: Arr.flatMap((value, index) => loopAny(Arr.append(path, keyIndex(index)), value))
783 })
784 const loopObject = (
785 path: ReadonlyArray<KeyComponent>,
786 value: JsonMap
787 ): ReadonlyArray<[path: ReadonlyArray<KeyComponent>, value: string]> =>
788 Object.entries(value)
789 .filter(([, value]) => Predicate.isNotNullable(value))
790 .flatMap(([key, value]) => {
791 const newPath = Arr.append(path, keyName(key))
792 const result = loopAny(newPath, value)
793 if (Arr.isEmptyReadonlyArray(result)) {
794 return Arr.make([newPath, ""] as [ReadonlyArray<KeyComponent>, string])
795 }
796 return result
797 })
798 return loopObject(Arr.empty(), config)
799}

Callers 1

fromJsonFunction · 0.85

Calls 1

loopObjectFunction · 0.85

Tested by

no test coverage detected