EdgeAIG's picture
download
raw
5.44 kB
/**
* Schema-aware `RequestResolver` helpers for SQL-backed data loading.
*
* This module represents each lookup or mutation as a `SqlRequest` and batches
* concurrent requests into SQL operations. Request payloads are encoded with the
* request schema before `execute` is called, and returned rows are decoded with
* the result schema before requests are completed. It provides ordered,
* grouped, id-based, and side-effect-only resolver constructors, and keeps
* batches separated by the active SQL transaction connection.
*
* @since 4.0.0
*/
import * as Arr from "../../Array.ts";
import * as Cause from "../../Cause.ts";
import * as Effect from "../../Effect.ts";
import * as Request from "../../Request.ts";
import * as RequestResolver from "../../RequestResolver.ts";
import * as Schema from "../../Schema.ts";
import type * as Types from "../../Types.ts";
import { ResultLengthMismatch } from "./SqlError.ts";
/**
* Request type used by SQL request resolvers, carrying the input payload
* together with the resolver's result, error, and environment types.
*
* @category requests
* @since 4.0.0
*/
export interface SqlRequest<In, A, E, R> extends Request.Request<A, E | Schema.SchemaError, R> {
readonly payload: In;
}
/**
* Runs a payload as a `SqlRequest` through a request resolver, either directly
* with a payload and resolver or curried by resolver.
*
* @category requests
* @since 4.0.0
*/
export declare const request: {
/**
* Runs a payload as a `SqlRequest` through a request resolver, either directly
* with a payload and resolver or curried by resolver.
*
* @category requests
* @since 4.0.0
*/
<In, A, E, R>(resolver: RequestResolver.RequestResolver<SqlRequest<In, A, E, R>>): (payload: In) => Effect.Effect<A, E | Schema.SchemaError, R>;
/**
* Runs a payload as a `SqlRequest` through a request resolver, either directly
* with a payload and resolver or curried by resolver.
*
* @category requests
* @since 4.0.0
*/
<In, A, E, R>(payload: In, resolver: RequestResolver.RequestResolver<SqlRequest<In, A, E, R>>): Effect.Effect<A, E | Schema.SchemaError, R>;
};
/**
* Constructs a `SqlRequest` from a payload. Equality and hashing are based on
* the payload so equal requests can be batched and deduplicated.
*
* @category requests
* @since 4.0.0
*/
export declare const SqlRequest: <In, A, E, R>(payload: In) => SqlRequest<In, A, E, R>;
/**
* Creates a resolver for a SQL query with a request schema and a result schema.
*
* **Details**
*
* The request schema is used to validate the input of the query, and the result
* schema is used to validate the output of the query. Results are mapped to the
* requests in order, so the length of the results must match the length of the
* requests.
*
* @category resolvers
* @since 4.0.0
*/
export declare const ordered: <Req extends Schema.Top, Res extends Schema.Top, _, E, R>(options: {
readonly Request: Req;
readonly Result: Res;
readonly execute: (requests: Arr.NonEmptyArray<Req["Encoded"]>) => Effect.Effect<ReadonlyArray<_>, E, R>;
}) => RequestResolver.RequestResolver<SqlRequest<Req["Type"], Res["Type"], E | ResultLengthMismatch, Req["EncodingServices"] | Res["DecodingServices"] | R>>;
/**
* Creates a batched SQL request resolver that encodes requests, decodes result
* rows, groups decoded results by matching request and result keys, and fails a
* request with `NoSuchElementError` when no result group exists.
*
* @category resolvers
* @since 4.0.0
*/
export declare const grouped: <Req extends Schema.Top, Res extends Schema.Top, K, Row, E, R>(options: {
readonly Request: Req;
readonly RequestGroupKey: (request: Req["Type"]) => K;
readonly Result: Res;
readonly ResultGroupKey: (result: Res["Type"], row: Types.NoInfer<Row>) => K;
readonly execute: (requests: Arr.NonEmptyArray<Req["Encoded"]>) => Effect.Effect<ReadonlyArray<Row>, E, R>;
}) => RequestResolver.RequestResolver<SqlRequest<Req["Type"], Arr.NonEmptyArray<Res["Type"]>, E | Schema.SchemaError | Cause.NoSuchElementError, Req["EncodingServices"] | Res["DecodingServices"] | R>>;
/**
* Creates a batched resolver that fetches rows for encoded ids, decodes
* results, completes each matching request using `ResultId`, and fails missing
* ids with `NoSuchElementError`.
*
* @category resolvers
* @since 4.0.0
*/
export declare const findById: <Id extends Schema.Top, Res extends Schema.Top, Row, E, R>(options: {
readonly Id: Id;
readonly Result: Res;
readonly ResultId: (result: Res["Type"], row: Types.NoInfer<Row>) => Id["Type"];
readonly execute: (requests: Arr.NonEmptyArray<Id["Encoded"]>) => Effect.Effect<ReadonlyArray<Row>, E, R>;
}) => RequestResolver.RequestResolver<SqlRequest<Id["Type"], Res["Type"], E | Schema.SchemaError | Cause.NoSuchElementError, Id["EncodingServices"] | Res["DecodingServices"] | R>>;
declare const void_: <Req extends Schema.Top, _, E, R>(options: {
readonly Request: Req;
readonly execute: (requests: Arr.NonEmptyArray<Req["Encoded"]>) => Effect.Effect<ReadonlyArray<_>, E, R>;
}) => RequestResolver.RequestResolver<SqlRequest<Req["Type"], void, E | Schema.SchemaError, Req["EncodingServices"] | R>>;
export {
/**
* Create a resolver that performs side effects.
*
* @category resolvers
* @since 4.0.0
*/
void_ as void };
//# sourceMappingURL=SqlResolver.d.ts.map

Xet Storage Details

Size:
5.44 kB
·
Xet hash:
09b51413fb96b62032e929385215faa734d1e9ccbc7e57ab00e5f442222cb1d3

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.