MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / paginate

Method paginate

integrations/replicate/src/index.ts:114–136  ·  view source on GitHub ↗

Paginate through a list of results.

(
    task: (key: string) => Promise<Page<T>>,
    key: IntegrationTaskKey,
    counter: number = 0
  )

Source from the content-addressed store, hash-verified

112
113 /** Paginate through a list of results. */
114 async *paginate<T>(
115 task: (key: string) => Promise<Page<T>>,
116 key: IntegrationTaskKey,
117 counter: number = 0
118 ): AsyncGenerator<T[]> {
119 const boundTask = task.bind(this as any);
120
121 const page = await boundTask(`${key}-${counter}`);
122 yield page.results;
123
124 if (page.next) {
125 const nextStep = counter++;
126
127 const nextPage = () => {
128 return this.request<Page<T>>(`${key}-${nextStep}`, {
129 route: page.next!,
130 options: { method: "GET" },
131 });
132 };
133
134 yield* this.paginate(nextPage, key, nextStep);
135 }
136 }
137
138 /** Auto-paginate and return all results. */
139 async getAll<T>(

Callers 2

getAllMethod · 0.95
replicate.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected