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

Function listWalk

packages/effect/src/ui/Query.ts:4765–4846  ·  view source on GitHub ↗
(
  env: CacheEnv,
  def: QueryDef,
  args: unknown,
  logKey: () => string,
  build: Build,
  base: ReadonlyArray<unknown>,
  target: () => number,
  onPage: (page: number, cursor: Schema.Json | undefined) => void
)

Source from the content-addressed store, hash-verified

4763}
4764
4765const listWalk = (
4766 env: CacheEnv,
4767 def: QueryDef,
4768 args: unknown,
4769 logKey: () => string,
4770 build: Build,
4771 base: ReadonlyArray<unknown>,
4772 target: () => number,
4773 onPage: (page: number, cursor: Schema.Json | undefined) => void
4774): Effect.Effect<WalkOutcome, any> =>
4775 Effect.suspend(() => {
4776 const list = def.list!
4777 const pages = base.slice()
4778 const used = new Set<string>()
4779 let repeated = false
4780 const ended = (hasMore: boolean): Effect.Effect<WalkOutcome> =>
4781 Effect.succeed({
4782 pages,
4783 hasMore,
4784 failedAt: undefined,
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)

Callers 1

Query.tsFile · 0.85

Calls 4

sliceMethod · 0.80
stepFunction · 0.70
endedFunction · 0.70
nextMethod · 0.65

Tested by

no test coverage detected