Constructs a new Client.
Optional
clientConfiguration: ClientConfigurationthe ClientConfiguration to apply. Defaults to recommended ClientConfiguraiton.
Optional
httpClient: HTTPClientThe underlying HTTPClient that will execute the actual HTTP calls. Defaults to recommended HTTPClient.
Return the ClientConfiguration of this client.
the last transaction time seen by this client, or undefined if this client has not seen a transaction time.
Sets the last transaction time of this client.
the last transaction timestamp to set, as microseconds since
the epoch. If ts
is less than the existing #lastTxnTs
value or is
undefined , then no change is made.
Creates an iterator to yield pages of data. If additional pages exist, the iterator will lazily fetch addition pages on each iteration. Pages will be retried in the event of a ThrottlingError up to the client's configured max_attempts, inclusive of the initial call.
The expected type of the items returned from Fauna on each iteration. T can be inferred if the provided query used a type parameter.
a Query or an existing fauna Set (Page or EmbeddedSet)
Optional
options: QueryOptionsa QueryOptions to apply to the queries. Optional.
A SetIterator that lazily fetches new pages of data on each iteration
const userIterator = await client.paginate(fql`
Users.all()
`);
for await (const users of userIterator) {
for (const user of users) {
// do something with each user
}
}
The SetIterator.flatten method can be used so the iterator yields items directly. Each item is fetched asynchronously and hides when additional pages are fetched.
const userIterator = await client.paginate(fql`
Users.all()
`);
for await (const user of userIterator.flatten()) {
// do something with each user
}
Queries Fauna. Queries will be retried in the event of a ThrottlingError up to the client's configured max_attempts, inclusive of the initial call.
The expected type of the response from Fauna. T can be inferred if the provided query used a type parameter.
a Query to execute in Fauna. Note, you can embed header fields in this object; if you do that there's no need to pass the headers parameter.
Optional
options: QueryOptionsoptional QueryOptions to apply on top of the request input. Values in this headers parameter take precedence over the same values in the ClientConfiguration.
Promise<QuerySuccess>.
ServiceError Fauna emitted an error. The ServiceError will be one of ServiceError's child classes if the error can be further categorized, or a concrete ServiceError if it cannot. You can use either the type, or the underlying httpStatus + code to determine the root cause.
ProtocolError the client a HTTP error not sent by Fauna.
NetworkError the client encountered a network issue connecting to Fauna.
A ClientError the client fails to submit the request
ClientClosedError if a query is issued after the client is closed. due to an internal error.
Initialize a streaming request to Fauna
The expected type of the response from Fauna. T can be inferred if the provided query used a type parameter.
Optional
options: Partial<StreamClientConfiguration>A StreamClient that which can be used to listen to a stream of events
const stream = client.stream(fql`MyCollection.all().toStream()`)
try {
for await (const event of stream) {
switch (event.type) {
case "update":
case "add":
case "remove":
console.log("Stream update:", event);
// ...
break;
}
}
} catch (error) {
// An error will be handled here if Fauna returns a terminal, "error" event, or
// if Fauna returns a non-200 response when trying to connect, or
// if the max number of retries on network errors is reached.
// ... handle fatal error
};
const stream = client.stream(fql`MyCollection.all().toStream()`)
stream.start(
function onEvent(event) {
switch (event.type) {
case "update":
case "add":
case "remove":
console.log("Stream update:", event);
// ...
break;
}
},
function onError(error) {
// An error will be handled here if Fauna returns a terminal, "error" event, or
// if Fauna returns a non-200 response when trying to connect, or
// if the max number of retries on network errors is reached.
// ... handle fatal error
}
);
Client for calling Fauna.