Requests.ts overview

Batched reads over the stores’ tables for application code: concurrent Effect.requests in one batch window collapse into one WHERE … IN (…). layer builds the shared resolvers, since Effect batches per resolver instance. There is no write path and no cache.

Example

import { Effect, Layer } from "effect"
import * as Drizzle from "@thomasfosterau/effect-auth-drizzle"

const program = Effect.forEach(userIds, Drizzle.Requests.getUser, {
  concurrency: "unbounded"
}) // one SELECT ... WHERE id IN (...), however many ids

program.pipe(Effect.provide(Drizzle.Requests.layer().pipe(Layer.provide(Drizzle.Database.databaseLayer(db)))))

Exports Grouped by Category


utils

AuthRequests (class)

The shared resolvers behind the request constructors in this module.

Signature

declare class AuthRequests

Source

getIdentifierByValue

Resolve an identifier by its (type, value) pair, batched with every other concurrent pair lookup. None on a miss.

Signature

declare const getIdentifierByValue: (
  type: Auth.Identifier.IdentifierType,
  value: string
) => Effect.Effect<Option.Option<Auth.Identifier.Identifier>, Auth.Errors.AuthError, AuthRequests>

Source

getSession

Read a session by id (the SHA-256 hash of the bearer token), batched with every other concurrent session read. None on a miss.

Signature

declare const getSession: (
  id: string
) => Effect.Effect<Option.Option<Auth.Types.Session>, Auth.Errors.AuthError, AuthRequests>

Source

getUser

Read a user by id, batched with every other concurrent user read. None on a miss.

Signature

declare const getUser: (
  id: string
) => Effect.Effect<Option.Option<Auth.Types.User>, Auth.Errors.AuthError, AuthRequests>

Source

layer

The batched read interface, on top of DrizzleDatabase.

Independent of the store layers: provide either, or both. Batching is scoped to this layer’s lifetime, since that is what owns the resolver instances.

Signature

declare const layer: (schema?: SchemaInput) => Layer.Layer<AuthRequests, never, DrizzleDatabase>

Source

listIdentifiersByUser

List a user’s identifiers (oldest first), batched with every other concurrent list. [] for a user with none.

Signature

declare const listIdentifiersByUser: (
  userId: string
) => Effect.Effect<ReadonlyArray<Auth.Identifier.Identifier>, Auth.Errors.AuthError, AuthRequests>

Source

make

Build the resolver set over the ambient DrizzleDatabase.

Signature

declare const make: (schema?: SchemaInput) => Effect.Effect<typeof AuthRequests.Service, never, DrizzleDatabase>

Source


This site uses Just the Docs, a documentation theme for Jekyll.