Fetch.variables.paginatedFetchStream
fx-fetch / Fetch / paginatedFetchStream
Variable: paginatedFetchStream()
Section titled “Variable: paginatedFetchStream()”
constpaginatedFetchStream: {<A,E,R>(request,onResponse):Stream<A,FetchError|AbortError|NotAllowedError|NotOkError|E,Fetch|R>; <A,E,R>(onResponse): (request) =>Stream<A,FetchError|AbortError|NotAllowedError|NotOkError|E,Fetch|R>; }
Defined in: packages/fx-fetch/src/Fetch/paginatedFetchStream.ts:83
Call Signature
Section titled “Call Signature”<
A,E,R>(request,onResponse):Stream<A,FetchError|AbortError|NotAllowedError|NotOkError|E,Fetch|R>
Type Parameters
Section titled “Type Parameters”A
E
R
Parameters
Section titled “Parameters”request
Section titled “request”onResponse
Section titled “onResponse”OnResponse<A, E, R>
Returns
Section titled “Returns”Stream<A, FetchError | AbortError | NotAllowedError | NotOkError | E, Fetch | R>
0.1.0
Example
Section titled “Example”import { Effect, Option, Schema, Stream } from 'effect';import { Fetch, Request, Response } from 'fx-fetch';
class Person extends Schema.Class<Person>('Person')({ id: Schema.Number, name: Schema.NonEmptyString,}) { }
const PayloadSchema = Schema.Struct({ nextToken: Schema.String.pipe(Schema.optional), items: Person.pipe(Schema.Array),});
const request = Request.unsafeMake({ url: './persons' });
// ┌─── Stream.Stream<// │ Person[], // ◀︎── page emission// │ | Fetch.FetchError | Fetch.AbortError | Fetch.NotAllowedError | Response.NotOkError// │ | MalformedJsonError// │ | ParseError,// │ Fetch.Fetch// │ >// ▼const program = Fetch.paginatedFetchStream( request, Effect.fn(function* (lastResponse) { const payload = yield* Response.readJsonWithSchema(lastResponse, PayloadSchema);
const nextToken = Option.fromNullable(payload.nextToken); const nextRequest = nextToken.pipe( Option.map((token) => Request.setUrlSearchParam(request, 'token', token)) );
return { pageEmission: payload.items, // ◀︎── Person[] nextRequest, // ◀︎── Option.Option<Request.Request> }; }));Call Signature
Section titled “Call Signature”<
A,E,R>(onResponse): (request) =>Stream<A,FetchError|AbortError|NotAllowedError|NotOkError|E,Fetch|R>
Type Parameters
Section titled “Type Parameters”A
E
R
Parameters
Section titled “Parameters”onResponse
Section titled “onResponse”OnResponse<A, E, R>
Returns
Section titled “Returns”(
request):Stream<A,FetchError|AbortError|NotAllowedError|NotOkError|E,Fetch|R>
Parameters
Section titled “Parameters”request
Section titled “request”Returns
Section titled “Returns”Stream<A, FetchError | AbortError | NotAllowedError | NotOkError | E, Fetch | R>
0.1.0
Example
Section titled “Example”import { Effect, Option, Schema, Stream } from 'effect';import { Fetch, Request, Response } from 'fx-fetch';
class Person extends Schema.Class<Person>('Person')({ id: Schema.Number, name: Schema.NonEmptyString,}) { }
const PayloadSchema = Schema.Struct({ nextToken: Schema.String.pipe(Schema.optional), items: Person.pipe(Schema.Array),});
const request = Request.unsafeMake({ url: './persons' });
// ┌─── Stream.Stream<// │ Person[], // ◀︎── page emission// │ | Fetch.FetchError | Fetch.AbortError | Fetch.NotAllowedError | Response.NotOkError// │ | MalformedJsonError// │ | ParseError,// │ Fetch.Fetch// │ >// ▼const program = Fetch.paginatedFetchStream( request, Effect.fn(function* (lastResponse) { const payload = yield* Response.readJsonWithSchema(lastResponse, PayloadSchema);
const nextToken = Option.fromNullable(payload.nextToken); const nextRequest = nextToken.pipe( Option.map((token) => Request.setUrlSearchParam(request, 'token', token)) );
return { pageEmission: payload.items, // ◀︎── Person[] nextRequest, // ◀︎── Option.Option<Request.Request> }; }));0.1.0
Example
Section titled “Example”import { Effect, Option, Schema, Stream } from 'effect';import { Fetch, Request, Response } from 'fx-fetch';
class Person extends Schema.Class<Person>('Person')({ id: Schema.Number, name: Schema.NonEmptyString,}) { }
const PayloadSchema = Schema.Struct({ nextToken: Schema.String.pipe(Schema.optional), items: Person.pipe(Schema.Array),});
const request = Request.unsafeMake({ url: './persons' });
// ┌─── Stream.Stream<// │ Person[], // ◀︎── page emission// │ | Fetch.FetchError | Fetch.AbortError | Fetch.NotAllowedError | Response.NotOkError// │ | MalformedJsonError// │ | ParseError,// │ Fetch.Fetch// │ >// ▼const program = Fetch.paginatedFetchStream( request, Effect.fn(function* (lastResponse) { const payload = yield* Response.readJsonWithSchema(lastResponse, PayloadSchema);
const nextToken = Option.fromNullable(payload.nextToken); const nextRequest = nextToken.pipe( Option.map((token) => Request.setUrlSearchParam(request, 'token', token)) );
return { pageEmission: payload.items, // ◀︎── Person[] nextRequest, // ◀︎── Option.Option<Request.Request> }; }));