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

Function step

packages/effect/src/ui/Query.ts:4787–4842  ·  view source on GitHub ↗
(
      cursor: Option.Option<unknown>,
      first: boolean
    )

Source from the content-addressed store, hash-verified

4785 cause: undefined
4786 })
4787 const step = (
4788 cursor: Option.Option<unknown>,
4789 first: boolean
4790 ): Effect.Effect<WalkOutcome, any> => {
4791 const index = pages.length
4792 if (Option.isSome(cursor)) {
4793 const key = cursorKey(list, cursor.value)
4794 if (key !== undefined) {
4795 if (used.has(key) && !repeated) {
4796 repeated = true
4797 const at = logKey()
4798 env.report(
4799 new PageRepeated({
4800 query: def.name,
4801 logKey: at,
4802 message: "[Query] a walk of " + quote(def.name) + " at " +
4803 at + " got page " + index +
4804 " with a cursor it already used. Check the list's next."
4805 })
4806 )
4807 }
4808 used.add(key)
4809 }
4810 }
4811 if (!first) {
4812 onPage(
4813 index,
4814 Option.isSome(cursor) ? logCursor(list, cursor.value) : undefined
4815 )
4816 }
4817 return Effect.flatMap(
4818 Effect.exit(build.fetcher(args, cursor)),
4819 (exit): Effect.Effect<WalkOutcome, any> => {
4820 if (exit._tag === "Failure") {
4821 if (
4822 Cause.hasDies(exit.cause) || !Cause.hasFails(exit.cause)
4823 ) return exit
4824 return Effect.succeed({
4825 pages,
4826 hasMore: true,
4827 failedAt: index,
4828 cause: failsOnly(exit.cause)
4829 })
4830 }
4831 return Effect.suspend(() => {
4832 const page = exit.value
4833 listCheckPage(env, def, logKey, page)
4834 pages.push(page)
4835 const next = list.next(page, pages)
4836 if (Option.isNone(next)) return ended(false)
4837 if (pages.length >= target()) return ended(true)
4838 return step(next, false)
4839 })
4840 }
4841 )
4842 }
4843 if (pages.length === 0) return step(Option.none(), true)
4844 const next = list.next(pages[pages.length - 1], pages)

Callers 8

listWalkFunction · 0.70
withRetryAfterFunction · 0.50
transcribeLiveBufferedFunction · 0.50
makeOpenDurationFunction · 0.50
PersistedQueue.tsFile · 0.50
retryableOnlyFunction · 0.50
TestClock.tsFile · 0.50
Activity.tsFile · 0.50

Calls 15

cursorKeyFunction · 0.85
logKeyFunction · 0.85
onPageFunction · 0.85
logCursorFunction · 0.85
failsOnlyFunction · 0.85
listCheckPageFunction · 0.85
exitMethod · 0.80
quoteFunction · 0.70
endedFunction · 0.70
hasMethod · 0.65
reportMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected