import type * as FunctionSpec from "@confect/core/FunctionSpec"; import type * as GroupSpec from "@confect/core/GroupSpec"; import * as MiddlewareSpec from "@confect/core/MiddlewareSpec"; import type { FunctionType } from "convex/server"; import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import type * as Auth from "./Auth"; import type * as DatabaseReader from "./DatabaseReader"; import type * as DatabaseSchema from "./DatabaseSchema"; import type * as Handler from "./Handler"; import type { ExecutionMetadata } from "./ExecutionMetadata"; import type { RequestMetadata } from "./RequestMetadata"; import type { TransactionMetadata } from "./TransactionMetadata"; import type * as MutationRunner from "./MutationRunner"; import type * as QueryRunner from "./QueryRunner"; import type { QueryTransactionContext } from "./QueryTransactionContext"; import type * as Scheduler from "./Scheduler"; import type { Storage } from "./Storage"; import type * as StorageReader from "./StorageReader"; import type * as StorageWriter from "./StorageWriter"; /** * Marker service produced by providing a middleware's implementation to a * group's impl layer. `GroupImpl.make` requires one per middleware attached to * the group's spec (via {@link FromGroupSpec}), so `GroupImpl.finalize`'s `RIn = * never` bound rejects a group that attaches a middleware but never provides * its implementation—the exact mechanism used for `FunctionImpl`s. */ export interface MiddlewareImpl { readonly middlewareKey: MiddlewareKey; } export declare const MiddlewareImpl: ({ middlewareKey, }: { middlewareKey: MiddlewareKey; }) => Context.Service, MiddlewareImpl>; export type FromGroupSpec = GroupSpec.MiddlewareSpecs | FunctionSpec.MiddlewareSpecs> extends infer MiddlewareSpec_ ? MiddlewareSpec_ extends MiddlewareSpec.AnyMiddlewareSpec ? MiddlewareImpl> : never : never; export type FunctionTypeServices = FunctionType_ extends "query" ? Handler.QueryServices : FunctionType_ extends "mutation" ? Handler.MutationServices : FunctionType_ extends "action" ? Handler.ActionServices : never; /** * The services a single middleware implementation may use: the set-theoretic * intersection of the ctx-service unions of the middleware's declared * `functionTypes`, so one implementation is valid in every runtime it can be * invoked in. Enumerated by hand rather than derived with * `Exclude`/`Extract`—several ctx services are structurally typed (e.g. the raw * `GenericQueryCtx`/`GenericMutationCtx` tags), so conditional-type set * arithmetic over them is not reliable. */ export type CommonServices = [FunctionTypes] extends ["query"] ? Handler.QueryServices : [FunctionTypes] extends ["mutation"] ? Handler.MutationServices : [FunctionTypes] extends ["action"] ? Handler.ActionServices : [FunctionTypes] extends ["query" | "mutation"] ? QueryMutationCommonServices : [FunctionTypes] extends ["mutation" | "action"] ? MutationActionCommonServices : AllFunctionTypesCommonServices; type QueryMutationCommonServices = DatabaseReader.DatabaseReader | Auth.Auth | ExecutionMetadata | TransactionMetadata | QueryTransactionContext | Storage | StorageReader.StorageReader | QueryRunner.QueryRunner; type MutationActionCommonServices = Auth.Auth | ExecutionMetadata | RequestMetadata | Scheduler.Scheduler | Storage | StorageReader.StorageReader | StorageWriter.StorageWriter | QueryRunner.QueryRunner | MutationRunner.MutationRunner; type AllFunctionTypesCommonServices = Auth.Auth | ExecutionMetadata | Storage | StorageReader.StorageReader | QueryRunner.QueryRunner; /** * Provide a middleware's implementation with a single strategy shared by every * function type the middleware declares. The implementation's environment is * bounded by {@link CommonServices}—the intersection of the declared * functionTypes' ctx services—plus the middleware's declared `requires`, which * middleware running earlier in the chain provide. Reach for * {@link makeByFunctionType} when one strategy can't fit all declared * functionTypes (the usual case for database-touching middleware attached to * actions). * * Like `FunctionImpl.make`, `databaseSchema` is a type-level carrier only. */ export declare const make: (_databaseSchema: DatabaseSchema_, middlewareSpec: MiddlewareSpec_, impl: MiddlewareSpec.MiddlewareImpl, MiddlewareSpec.Error, CommonServices> | MiddlewareSpec.Requires, MiddlewareSpec.Options>) => Layer.Layer>>; /** * Provide a middleware's implementation with one strategy per declared function * type. Each entry may use that function type's full ctx-service union—the * recommended shape for database-touching middleware that also covers actions: * use `DatabaseReader`/`DatabaseWriter` in queries and mutations, and * `runQuery` of an internal query in actions. */ export declare const makeByFunctionType: (_databaseSchema: DatabaseSchema_, middlewareSpec: MiddlewareSpec_, impls: { readonly [FunctionType_ in MiddlewareSpec.FunctionTypes]: MiddlewareSpec.MiddlewareImpl, MiddlewareSpec.Error, FunctionTypeServices | MiddlewareSpec.Requires, MiddlewareSpec.Options>; }) => Layer.Layer>>; /** * Sugar over {@link make} for the flagship "run something, provide a service" * shape: run `effect` before the rest of the chain and provide its result under * `tag` (the runtime tag for the middleware's type-level `provides` service, * passed explicitly since the spec class only knows it at the type level). */ export declare const provides: (databaseSchema: DatabaseSchema_, middlewareSpec: MiddlewareSpec_, tag: Context.Key, Shape>, effect: Effect.Effect, CommonServices> | MiddlewareSpec.Requires>) => Layer.Layer>>; export {}; //# sourceMappingURL=MiddlewareImpl.d.ts.map