makeAdapter function infrastructure

Last updated: 2026-03-01T23:25:47.092Z

Metrics

LOC: 36 Complexity: 5 Params: 4

Signature

makeAdapter( name: AdapterName, selector: string, opts: { matches?: boolean; fillResult?: boolean; fillThrows?: boolean; field?: Partial<FormField>; } = {}, ): : CustomComponentAdapter

Source Code

function makeAdapter(
  name: AdapterName,
  selector: string,
  opts: {
    matches?: boolean;
    fillResult?: boolean;
    fillThrows?: boolean;
    field?: Partial<FormField>;
  } = {},
): CustomComponentAdapter {
  const el = document.createElement("div");
  const field: FormField = {
    element: el,
    selector: `[data-${name}]`,
    category: "unknown",
    fieldType: "unknown",
    label: name,
    name: "",
    id: "",
    placeholder: "",
    required: false,
    contextSignals: "",
    adapterName: name,
    ...(opts.field ?? {}),
  };

  return {
    name,
    selector,
    matches: vi.fn().mockReturnValue(opts.matches ?? true),
    buildField: vi.fn().mockReturnValue(field),
    fill: opts.fillThrows
      ? vi.fn().mockRejectedValue(new Error("fill error"))
      : vi.fn().mockResolvedValue(opts.fillResult ?? true),
  };
}

Dependencies (Outgoing)

graph LR makeAdapter["makeAdapter"] registerAdapter["registerAdapter"] getAdapter["getAdapter"] detectCustomComponents["detectCustomComponents"] fillCustomComponent["fillCustomComponent"] CustomComponentAdapter["CustomComponentAdapter"] AdapterName["AdapterName"] FormField["FormField"] makeField["makeField"] makeAdapter -->|uses| registerAdapter makeAdapter -->|uses| getAdapter makeAdapter -->|uses| detectCustomComponents makeAdapter -->|uses| fillCustomComponent makeAdapter -->|uses| CustomComponentAdapter makeAdapter -->|uses| AdapterName makeAdapter -->|uses| FormField makeAdapter -->|calls| makeAdapter makeAdapter -->|calls| makeField style makeAdapter fill:#dbeafe,stroke:#2563eb,stroke-width:2px click makeAdapter "7cbe03be6bdb4b2d.html" click registerAdapter "c75eea7abc579cb7.html" click getAdapter "fb0f4a5fd9ac2a4b.html" click detectCustomComponents "e93e9888463f9367.html" click fillCustomComponent "fb27203fbaa0cd9b.html" click CustomComponentAdapter "dc86c1894fa368f3.html" click AdapterName "0d92b308ac346887.html" click FormField "85cdbded927c91b0.html" click makeField "156337e1a0616358.html"

Impact (Incoming)

graph LR makeAdapter["makeAdapter"] makeAdapter -->|calls| makeAdapter style makeAdapter fill:#dbeafe,stroke:#2563eb,stroke-width:2px click makeAdapter "7cbe03be6bdb4b2d.html"
SourceType
makeAdapter calls