MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / effectLink

Function effectLink

src/ui-server/api/steps.ts:898–981  ·  view source on GitHub ↗
(
    step: StepRecord,
    fold: Fold,
    ref: { referenceName: string; referenceKind: 'calls' | 'instantiates'; line: number; column?: number },
    trigger: WireStepTrigger | null,
    fallbackArgs: string | null = null,
    requireReceiver = false,
    /** A site that is no call — a handler's `return "redirect:/x"` — arrives already classified. */
    preset: { effect: Effect; status: number | null } | null = null
  )

Source from the content-addressed store, hash-verified

896
897 /** One effect site: the call as written, what it passes, when, what fires it, and — for a response — the status. */
898 const effectLink = async (
899 step: StepRecord,
900 fold: Fold,
901 ref: { referenceName: string; referenceKind: 'calls' | 'instantiates'; line: number; column?: number },
902 trigger: WireStepTrigger | null,
903 fallbackArgs: string | null = null,
904 requireReceiver = false,
905 /** A site that is no call — a handler's `return "redirect:/x"` — arrives already classified. */
906 preset: { effect: Effect; status: number | null } | null = null
907 ): Promise<boolean> => {
908 const at = { line: ref.line, column: ref.column };
909 const site = preset ? null : await callAt(fold.node, { ...at, callee: ref.referenceName });
910 // The site read must be THIS call: its last segment is the reference's.
911 const last = (n: string) => n.replace(/\([^()]*\)/g, '').split(/[.:]/).pop() ?? n;
912 const usable = !!site && site.callee !== '' && last(site.callee) === last(ref.referenceName);
913 const text = usable ? site.callee : ref.referenceName;
914 if (requireReceiver && !/[.:>]/.test(text)) return false;
915 const args = usable ? site.args : fallbackArgs;
916 // The receiver's declared type counts only when the call leaves the
917 // index through it: a library's `Repository<Cat>`, or the project's own
918 // `OwnerRepository` interface whose `save` comes from Spring Data — never
919 // a project class that declares the method, which is a place to walk into.
920 let effect: Effect | null = preset?.effect ?? null;
921 if (!preset) {
922 const declared = await receiverTypeFor(fold.node, text);
923 const receiverType = declared && (await resolveByReceiver(fold.node, text)) === null ? declared : null;
924 effect = classifyEffect({
925 text,
926 kind: ref.referenceKind,
927 language: fold.node.language,
928 project,
929 receiverType,
930 args,
931 projectType: fold.node.language === 'swift' && (await declaresSwiftType(text)),
932 });
933 }
934 if (effect === null) return false;
935 // A reply's status, read before its box exists — the box is per outcome.
936 // `NextResponse.json(user, { status: 201 })`: the code sits in an object
937 // the abbreviation reduced to its keys; the site reader kept it. And a
938 // body-sending reply that sets none is a 200, so a success has a box of
939 // its own beside the 401's.
940 const status = preset
941 ? preset.status
942 : effect.category === 'response'
943 ? (responseStatus(text, args, ref.referenceKind) ?? (usable && typeof site.status === 'number' ? site.status : null) ?? implicitResponseStatus(text))
944 : null;
945 // What fires this call, read before its box is made: a call bound inside
946 // ANOTHER effect's arguments — the axios.delete in a confirm dialog's
947 // button — hangs off that box, one step deeper, not off the screen.
948 const fired = trigger ?? (await triggerAt(fold.node, at));
949 const from = fired?.of ? (firedByEffect(fold.node.id, at, fired.of) ?? step) : step;
950 const target = effectStep(fold.node, { referenceName: text, line: ref.line }, effect, from.depth + 1, status);
951 if (target === null) return true;
952 const guards = await guardsAt(fold.node, at);
953 const when = guardLabel(guards);
954 const wireSite: WireStepSite = { file: posix(fold.node.filePath), line: ref.line, text, when: '' };
955 if (args !== null) wireSite.args = args;

Callers 1

buildStepsFunction · 0.85

Calls 15

classifyEffectFunction · 0.90
responseStatusFunction · 0.90
implicitResponseStatusFunction · 0.90
guardLabelFunction · 0.90
lastFunction · 0.85
receiverTypeForFunction · 0.85
resolveByReceiverFunction · 0.85
declaresSwiftTypeFunction · 0.85
firedByEffectFunction · 0.85
effectStepFunction · 0.85
posixFunction · 0.85
decisionOfFunction · 0.85

Tested by

no test coverage detected