MCPcopy Create free account
hub / github.com/Effect-TS/effect / getIndexSignatureKeys

Function getIndexSignatureKeys

packages/effect/src/SchemaAST.ts:2645–2671  ·  view source on GitHub ↗
(
  input: { readonly [x: PropertyKey]: unknown },
  parameter: IndexSignatureParameter,
  options: ParseOptions = defaultParseOptions
)

Source from the content-addressed store, hash-verified

2643 * @internal
2644 */
2645export function getIndexSignatureKeys(
2646 input: { readonly [x: PropertyKey]: unknown },
2647 parameter: IndexSignatureParameter,
2648 options: ParseOptions = defaultParseOptions
2649): ReadonlyArray<PropertyKey> {
2650 let stringKeys: ReadonlyArray<string> | undefined
2651 let symbolKeys: ReadonlyArray<symbol> | undefined
2652
2653 function go(parameter: AST): ReadonlyArray<PropertyKey> {
2654 switch (parameter._tag) {
2655 case "String":
2656 case "TemplateLiteral":
2657 return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchPart(k, options) !== undefined)
2658 case "Number":
2659 return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchKey(k, options) !== undefined)
2660 case "Symbol":
2661 return (symbolKeys ??= Object.getOwnPropertySymbols(input)).filter((k) =>
2662 Object.prototype.propertyIsEnumerable.call(input, k) && parameter.matchKey(k, options) !== undefined
2663 )
2664 case "Union":
2665 return [...new Set(parameter.types.flatMap(go))]
2666 default:
2667 return []
2668 }
2669 }
2670 return go(parameterFromPropertyKey(toEncoded(parameter)))
2671}
2672
2673/**
2674 * Represents a named property within an {@link Objects} node.

Callers 1

makeFallbackMethod · 0.85

Calls 2

goFunction · 0.70
toEncodedFunction · 0.70

Tested by

no test coverage detected