@trpc/server
Version:
1,329 lines (1,326 loc) • 85.2 kB
text/typescript
import { Observable, inferObservableValue } from "./index.d-BiUz7kM_.cjs";
//#region src/unstable-core-do-not-import/types.d.ts
/**
* ================================
* Useful utility types that doesn't have anything to do with tRPC in particular
* ================================
*/
/**
* @public
*/
type Maybe<TType> = TType | null | undefined;
/**
* @internal
* @see https://github.com/ianstormtaylor/superstruct/blob/7973400cd04d8ad92bbdc2b6f35acbfb3c934079/src/utils.ts#L323-L325
*/
type Simplify<TType> = TType extends any[] | Date ? TType : { [K in keyof TType]: TType[K] };
/**
* @public
*/
type Dict<TType> = Record<string, TType | undefined>;
/**
* @public
*/
type MaybePromise<TType> = Promise<TType> | TType;
type FilterKeys<TObj extends object, TFilter> = { [TKey in keyof TObj]: TObj[TKey] extends TFilter ? TKey : never }[keyof TObj];
/**
* @internal
*/
type Result$1<TType, TErr = unknown> = {
ok: true;
value: TType;
} | {
ok: false;
error: TErr;
};
/**
* @internal
*/
type Filter<TObj extends object, TFilter> = Pick<TObj, FilterKeys<TObj, TFilter>>;
/**
* Unwrap return type if the type is a function (sync or async), else use the type as is
* @internal
*/
type Unwrap<TType> = TType extends ((...args: any[]) => infer R) ? Awaited<R> : TType;
/**
* Makes the object recursively optional
* @internal
*/
type DeepPartial<TObject> = TObject extends object ? { [P in keyof TObject]?: DeepPartial<TObject[P]> } : TObject;
/**
* Omits the key without removing a potential union
* @internal
*/
type DistributiveOmit<TObj, TKey extends keyof any> = TObj extends any ? Omit<TObj, TKey> : never;
/**
* See https://github.com/microsoft/TypeScript/issues/41966#issuecomment-758187996
* Fixes issues with iterating over keys of objects with index signatures.
* Without this, iterations over keys of objects with index signatures will lose
* type information about the keys and only the index signature will remain.
* @internal
*/
type WithoutIndexSignature<TObj> = { [K in keyof TObj as string extends K ? never : number extends K ? never : K]: TObj[K] };
/**
* @internal
* Overwrite properties in `TType` with properties in `TWith`
* Only overwrites properties when the type to be overwritten
* is an object. Otherwise it will just use the type from `TWith`.
*/
type Overwrite<TType, TWith> = TWith extends any ? TType extends object ? { [K in keyof WithoutIndexSignature<TType> | keyof WithoutIndexSignature<TWith>]: K extends keyof TWith ? TWith[K] : K extends keyof TType ? TType[K] : never } & (string extends keyof TWith ? {
[key: string]: TWith[string];
} : number extends keyof TWith ? {
[key: number]: TWith[number];
} : {}) : TWith : never;
/**
* @internal
*/
type ValidateShape<TActualShape, TExpectedShape> = TActualShape extends TExpectedShape ? Exclude<keyof TActualShape, keyof TExpectedShape> extends never ? TActualShape : TExpectedShape : never;
/**
* @internal
*/
type PickFirstDefined<TType, TPick> = undefined extends TType ? undefined extends TPick ? never : TPick : TType;
type KeyFromValue<TValue, TType extends Record<PropertyKey, PropertyKey>> = { [K in keyof TType]: TValue extends TType[K] ? K : never }[keyof TType];
type InvertKeyValue<TType extends Record<PropertyKey, PropertyKey>> = { [TValue in TType[keyof TType]]: KeyFromValue<TValue, TType> };
/**
* ================================
* tRPC specific types
* ================================
*/
/**
* @internal
*/
type IntersectionError<TKey extends string> = `The property '${TKey}' in your router collides with a built-in method, rename this router or procedure on your backend.`;
/**
* @internal
*/
type ProtectedIntersection<TType, TWith> = keyof TType & keyof TWith extends never ? TType & TWith : IntersectionError<string & keyof TType & keyof TWith>;
/**
* @internal
* Returns the raw input type of a procedure
*/
type GetRawInputFn = () => Promise<unknown>;
declare const _errorSymbol: unique symbol;
type ErrorSymbol = typeof _errorSymbol;
type TypeError<TMessage extends string> = TMessage & {
_: typeof _errorSymbol;
};
type ValueOf<TObj> = TObj[keyof TObj];
type coerceAsyncIterableToArray<TValue> = TValue extends AsyncIterable<infer $Inferred> ? $Inferred[] : TValue;
/**
* @internal
* Infers the type of the value yielded by an async iterable
*/
type inferAsyncIterableYield<T> = T extends AsyncIterable<infer U> ? U : T;
//#endregion
//#region src/unstable-core-do-not-import/rpc/codes.d.ts
/**
* JSON-RPC 2.0 Error codes
*
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
* For tRPC we're copying the last digits of HTTP 4XX errors.
*/
declare const TRPC_ERROR_CODES_BY_KEY: {
/**
* Invalid JSON was received by the server.
* An error occurred on the server while parsing the JSON text.
*/
readonly PARSE_ERROR: -32700;
/**
* The JSON sent is not a valid Request object.
*/
readonly BAD_REQUEST: -32600;
readonly INTERNAL_SERVER_ERROR: -32603;
readonly NOT_IMPLEMENTED: -32603;
readonly BAD_GATEWAY: -32603;
readonly SERVICE_UNAVAILABLE: -32603;
readonly GATEWAY_TIMEOUT: -32603;
readonly UNAUTHORIZED: -32001;
readonly PAYMENT_REQUIRED: -32002;
readonly FORBIDDEN: -32003;
readonly NOT_FOUND: -32004;
readonly METHOD_NOT_SUPPORTED: -32005;
readonly TIMEOUT: -32008;
readonly CONFLICT: -32009;
readonly PRECONDITION_FAILED: -32012;
readonly PAYLOAD_TOO_LARGE: -32013;
readonly UNSUPPORTED_MEDIA_TYPE: -32015;
readonly UNPROCESSABLE_CONTENT: -32022;
readonly TOO_MANY_REQUESTS: -32029;
readonly CLIENT_CLOSED_REQUEST: -32099;
};
declare const TRPC_ERROR_CODES_BY_NUMBER: InvertKeyValue<typeof TRPC_ERROR_CODES_BY_KEY>;
type TRPC_ERROR_CODE_NUMBER = ValueOf<typeof TRPC_ERROR_CODES_BY_KEY>;
type TRPC_ERROR_CODE_KEY = keyof typeof TRPC_ERROR_CODES_BY_KEY;
/**
* tRPC error codes that are considered retryable
* With out of the box SSE, the client will reconnect when these errors are encountered
*/
declare const retryableRpcCodes: TRPC_ERROR_CODE_NUMBER[];
//# sourceMappingURL=codes.d.ts.map
//#endregion
//#region src/unstable-core-do-not-import/error/TRPCError.d.ts
declare function getCauseFromUnknown(cause: unknown): Error | undefined;
declare function getTRPCErrorFromUnknown(cause: unknown): TRPCError;
declare class TRPCError extends Error {
readonly cause?: Error;
readonly code: "PARSE_ERROR" | "BAD_REQUEST" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_SUPPORTED" | "TIMEOUT" | "CONFLICT" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "UNSUPPORTED_MEDIA_TYPE" | "UNPROCESSABLE_CONTENT" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST";
constructor(opts: {
message?: string;
code: TRPC_ERROR_CODE_KEY;
cause?: unknown;
});
}
//# sourceMappingURL=TRPCError.d.ts.map
//#endregion
//#region src/vendor/standard-schema-v1/spec.d.ts
/**
*
* @see https://github.com/standard-schema/standard-schema/blob/main/packages/spec/src/index.ts
*/
/** The Standard Schema interface. */
interface StandardSchemaV1<Input = unknown, Output = Input> {
/** The Standard Schema properties. */
readonly '~standard': StandardSchemaV1.Props<Input, Output>;
}
declare namespace StandardSchemaV1 {
/** The Standard Schema properties interface. */
interface Props<Input = unknown, Output = Input> {
/** The version number of the standard. */
readonly version: 1;
/** The vendor name of the schema library. */
readonly vendor: string;
/** Validates unknown input values. */
readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
/** Inferred types associated with the schema. */
readonly types?: Types<Input, Output> | undefined;
}
/** The result interface of the validate function. */
type Result<Output> = SuccessResult<Output> | FailureResult;
/** The result interface if validation succeeds. */
interface SuccessResult<Output> {
/** The typed output value. */
readonly value: Output;
/** The non-existent issues. */
readonly issues?: undefined;
}
/** The result interface if validation fails. */
interface FailureResult {
/** The issues of failed validation. */
readonly issues: ReadonlyArray<Issue>;
}
/** The issue interface of the failure output. */
interface Issue {
/** The error message of the issue. */
readonly message: string;
/** The path of the issue, if any. */
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
}
/** The path segment interface of the issue. */
interface PathSegment {
/** The key representing a path segment. */
readonly key: PropertyKey;
}
/** The Standard Schema types interface. */
interface Types<Input = unknown, Output = Input> {
/** The input type of the schema. */
readonly input: Input;
/** The output type of the schema. */
readonly output: Output;
}
/** Infers the input type of a Standard Schema. */
type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
/** Infers the output type of a Standard Schema. */
type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
}
//# sourceMappingURL=spec.d.ts.map
//#endregion
//#region src/unstable-core-do-not-import/parser.d.ts
type ParserZodEsque<TInput, TParsedInput> = {
_input: TInput;
_output: TParsedInput;
};
type ParserValibotEsque<TInput, TParsedInput> = {
schema: {
_types?: {
input: TInput;
output: TParsedInput;
};
};
};
type ParserArkTypeEsque<TInput, TParsedInput> = {
inferIn: TInput;
infer: TParsedInput;
};
type ParserStandardSchemaEsque<TInput, TParsedInput> = StandardSchemaV1<TInput, TParsedInput>;
type ParserMyZodEsque<TInput> = {
parse: (input: any) => TInput;
};
type ParserSuperstructEsque<TInput> = {
create: (input: unknown) => TInput;
};
type ParserCustomValidatorEsque<TInput> = (input: unknown) => Promise<TInput> | TInput;
type ParserYupEsque<TInput> = {
validateSync: (input: unknown) => TInput;
};
type ParserScaleEsque<TInput> = {
assert(value: unknown): asserts value is TInput;
};
type ParserWithoutInput<TInput> = ParserCustomValidatorEsque<TInput> | ParserMyZodEsque<TInput> | ParserScaleEsque<TInput> | ParserSuperstructEsque<TInput> | ParserYupEsque<TInput>;
type ParserWithInputOutput<TInput, TParsedInput> = ParserZodEsque<TInput, TParsedInput> | ParserValibotEsque<TInput, TParsedInput> | ParserArkTypeEsque<TInput, TParsedInput> | ParserStandardSchemaEsque<TInput, TParsedInput>;
type Parser = ParserWithInputOutput<any, any> | ParserWithoutInput<any>;
type inferParser<TParser extends Parser> = TParser extends ParserWithInputOutput<infer $TIn, infer $TOut> ? {
in: $TIn;
out: $TOut;
} : TParser extends ParserWithoutInput<infer $InOut> ? {
in: $InOut;
out: $InOut;
} : never;
type ParseFn<TType> = (value: unknown) => Promise<TType> | TType;
declare function getParseFn<TType>(procedureParser: Parser): ParseFn<TType>;
//# sourceMappingURL=parser.d.ts.map
//#endregion
//#region src/unstable-core-do-not-import/middleware.d.ts
/** @internal */
declare const middlewareMarker: "middlewareMarker" & {
__brand: "middlewareMarker";
};
type MiddlewareMarker = typeof middlewareMarker;
interface MiddlewareResultBase {
/**
* All middlewares should pass through their `next()`'s output.
* Requiring this marker makes sure that can't be forgotten at compile-time.
*/
readonly marker: MiddlewareMarker;
}
interface MiddlewareOKResult<_TContextOverride> extends MiddlewareResultBase {
ok: true;
data: unknown;
}
interface MiddlewareErrorResult<_TContextOverride> extends MiddlewareResultBase {
ok: false;
error: TRPCError;
}
/**
* @internal
*/
type MiddlewareResult<_TContextOverride> = MiddlewareErrorResult<_TContextOverride> | MiddlewareOKResult<_TContextOverride>;
/**
* @internal
*/
interface MiddlewareBuilder<TContext, TMeta, TContextOverrides, TInputOut> {
/**
* Create a new builder based on the current middleware builder
*/
unstable_pipe<$ContextOverridesOut>(fn: MiddlewareFunction<TContext, TMeta, TContextOverrides, $ContextOverridesOut, TInputOut> | MiddlewareBuilder<Overwrite<TContext, TContextOverrides>, TMeta, $ContextOverridesOut, TInputOut>): MiddlewareBuilder<TContext, TMeta, Overwrite<TContextOverrides, $ContextOverridesOut>, TInputOut>;
/**
* List of middlewares within this middleware builder
*/
_middlewares: MiddlewareFunction<TContext, TMeta, TContextOverrides, object, TInputOut>[];
}
/**
* @internal
*/
type MiddlewareFunction<TContext, TMeta, TContextOverridesIn, $ContextOverridesOut, TInputOut> = {
(opts: {
ctx: Simplify<Overwrite<TContext, TContextOverridesIn>>;
type: ProcedureType;
path: string;
input: TInputOut;
getRawInput: GetRawInputFn;
meta: TMeta | undefined;
signal: AbortSignal | undefined;
next: {
(): Promise<MiddlewareResult<TContextOverridesIn>>;
<$ContextOverride>(opts: {
ctx?: $ContextOverride;
input?: unknown;
}): Promise<MiddlewareResult<$ContextOverride>>;
(opts: {
getRawInput: GetRawInputFn;
}): Promise<MiddlewareResult<TContextOverridesIn>>;
};
}): Promise<MiddlewareResult<$ContextOverridesOut>>;
_type?: string | undefined;
};
type AnyMiddlewareFunction = MiddlewareFunction<any, any, any, any, any>;
type AnyMiddlewareBuilder = MiddlewareBuilder<any, any, any, any>;
/**
* @internal
*/
declare function createMiddlewareFactory<TContext, TMeta, TInputOut = unknown>(): <$ContextOverrides>(fn: MiddlewareFunction<TContext, TMeta, object, $ContextOverrides, TInputOut>) => MiddlewareBuilder<TContext, TMeta, $ContextOverrides, TInputOut>;
/**
* Create a standalone middleware
* @see https://trpc.io/docs/v11/server/middlewares#experimental-standalone-middlewares
* @deprecated use `.concat()` instead
*/
declare const experimental_standaloneMiddleware: <TCtx extends {
ctx?: object;
meta?: object;
input?: unknown;
}>() => {
create: <$ContextOverrides>(fn: MiddlewareFunction<TCtx extends {
ctx: infer T extends object;
} ? T : any, TCtx extends {
meta: infer T_1 extends object;
} ? T_1 : object, object, $ContextOverrides, TCtx extends {
input: infer T_2;
} ? T_2 : unknown>) => MiddlewareBuilder<TCtx extends {
ctx: infer T extends object;
} ? T : any, TCtx extends {
meta: infer T_1 extends object;
} ? T_1 : object, $ContextOverrides, TCtx extends {
input: infer T_2;
} ? T_2 : unknown>;
};
/**
* @internal
* Please note, `trpc-openapi` uses this function.
*/
declare function createInputMiddleware<TInput>(parse: ParseFn<TInput>): AnyMiddlewareFunction;
/**
* @internal
*/
declare function createOutputMiddleware<TOutput>(parse: ParseFn<TOutput>): AnyMiddlewareFunction;
//#endregion
//#region src/unstable-core-do-not-import/stream/tracked.d.ts
declare const trackedSymbol: unique symbol;
type TrackedId = string & {
__brand: 'TrackedId';
};
type TrackedEnvelope<TData> = [TrackedId, TData, typeof trackedSymbol];
type TrackedData<TData> = {
/**
* The id of the message to keep track of in case the connection gets lost
*/
id: string;
/**
* The data field of the message - this can be anything
*/
data: TData;
};
/**
* Produce a typed server-sent event message
* @deprecated use `tracked(id, data)` instead
*/
declare function sse<TData>(event: {
id: string;
data: TData;
}): TrackedEnvelope<TData>;
declare function isTrackedEnvelope<TData>(value: unknown): value is TrackedEnvelope<TData>;
/**
* Automatically track an event so that it can be resumed from a given id if the connection is lost
*/
declare function tracked<TData>(id: string, data: TData): TrackedEnvelope<TData>;
type inferTrackedOutput<TData> = TData extends TrackedEnvelope<infer $Data> ? TrackedData<$Data> : TData;
//#endregion
//#region src/unstable-core-do-not-import/utils.d.ts
/** @internal */
type UnsetMarker = 'unsetMarker' & {
__brand: 'unsetMarker';
};
/**
* Ensures there are no duplicate keys when building a procedure.
* @internal
*/
declare function mergeWithoutOverrides<TType extends Record<string, unknown>>(obj1: TType, ...objs: Partial<TType>[]): TType;
/**
* Check that value is object
* @internal
*/
declare function isObject(value: unknown): value is Record<string, unknown>;
type AnyFn = ((...args: any[]) => unknown) & Record<keyof any, unknown>;
declare function isFunction(fn: unknown): fn is AnyFn;
/**
* Create an object without inheriting anything from `Object.prototype`
* @internal
*/
declare function omitPrototype<TObj extends Record<string, unknown>>(obj: TObj): TObj;
declare function isAsyncIterable<TValue>(value: unknown): value is AsyncIterable<TValue>;
/**
* Run an IIFE
*/
declare const run: <TValue>(fn: () => TValue) => TValue;
declare function noop(): void;
declare function identity<T>(it: T): T;
/**
* Generic runtime assertion function. Throws, if the condition is not `true`.
*
* Can be used as a slightly less dangerous variant of type assertions. Code
* mistakes would be revealed at runtime then (hopefully during testing).
*/
declare function assert(condition: boolean, msg?: string): asserts condition;
declare function sleep(ms?: number): Promise<void>;
/**
* Ponyfill for
* [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
*/
declare function abortSignalsAnyPonyfill(signals: AbortSignal[]): AbortSignal;
//#endregion
//#region src/unstable-core-do-not-import/procedureBuilder.d.ts
type IntersectIfDefined<TType, TWith> = TType extends UnsetMarker ? TWith : TWith extends UnsetMarker ? TType : Simplify<TType & TWith>;
type DefaultValue<TValue, TFallback> = TValue extends UnsetMarker ? TFallback : TValue;
type inferAsyncIterable<TOutput> = TOutput extends AsyncIterable<infer $Yield, infer $Return, infer $Next> ? {
yield: $Yield;
return: $Return;
next: $Next;
} : never;
type inferSubscriptionOutput<TOutput> = TOutput extends AsyncIterable<any> ? AsyncIterable<inferTrackedOutput<inferAsyncIterable<TOutput>['yield']>, inferAsyncIterable<TOutput>['return'], inferAsyncIterable<TOutput>['next']> : TypeError<'Subscription output could not be inferred'>;
type CallerOverride<TContext> = (opts: {
args: unknown[];
invoke: (opts: ProcedureCallOptions<TContext>) => Promise<unknown>;
_def: AnyProcedure['_def'];
}) => Promise<unknown>;
type ProcedureBuilderDef<TMeta> = {
procedure: true;
inputs: Parser[];
output?: Parser;
meta?: TMeta;
resolver?: ProcedureBuilderResolver;
middlewares: AnyMiddlewareFunction[];
/**
* @deprecated use `type` instead
*/
mutation?: boolean;
/**
* @deprecated use `type` instead
*/
query?: boolean;
/**
* @deprecated use `type` instead
*/
subscription?: boolean;
type?: ProcedureType;
caller?: CallerOverride<unknown>;
};
type AnyProcedureBuilderDef = ProcedureBuilderDef<any>;
/**
* Procedure resolver options (what the `.query()`, `.mutation()`, and `.subscription()` functions receive)
* @internal
*/
interface ProcedureResolverOptions<TContext, _TMeta, TContextOverridesIn, TInputOut> {
ctx: Simplify<Overwrite<TContext, TContextOverridesIn>>;
input: TInputOut extends UnsetMarker ? undefined : TInputOut;
/**
* The AbortSignal of the request
*/
signal: AbortSignal | undefined;
}
/**
* A procedure resolver
*/
type ProcedureResolver<TContext, TMeta, TContextOverrides, TInputOut, TOutputParserIn, $Output> = (opts: ProcedureResolverOptions<TContext, TMeta, TContextOverrides, TInputOut>) => MaybePromise<DefaultValue<TOutputParserIn, $Output>>;
type AnyProcedureBuilder = ProcedureBuilder<any, any, any, any, any, any, any, any>;
/**
* Infer the context type from a procedure builder
* Useful to create common helper functions for different procedures
*/
type inferProcedureBuilderResolverOptions<TProcedureBuilder extends AnyProcedureBuilder> = TProcedureBuilder extends ProcedureBuilder<infer TContext, infer TMeta, infer TContextOverrides, infer _TInputIn, infer TInputOut, infer _TOutputIn, infer _TOutputOut, infer _TCaller> ? ProcedureResolverOptions<TContext, TMeta, TContextOverrides, TInputOut extends UnsetMarker ? unknown : TInputOut extends object ? Simplify<TInputOut & {
/**
* Extra input params might have been added by a `.input()` further down the chain
*/
[keyAddedByInputCallFurtherDown: string]: unknown;
}> : TInputOut> : never;
interface ProcedureBuilder<TContext, TMeta, TContextOverrides, TInputIn, TInputOut, TOutputIn, TOutputOut, TCaller extends boolean> {
/**
* Add an input parser to the procedure.
* @see https://trpc.io/docs/v11/server/validators
*/
input<$Parser extends Parser>(schema: TInputOut extends UnsetMarker ? $Parser : inferParser<$Parser>['out'] extends Record<string, unknown> | undefined ? TInputOut extends Record<string, unknown> | undefined ? undefined extends inferParser<$Parser>['out'] ? undefined extends TInputOut ? $Parser : TypeError<'Cannot chain an optional parser to a required parser'> : $Parser : TypeError<'All input parsers did not resolve to an object'> : TypeError<'All input parsers did not resolve to an object'>): ProcedureBuilder<TContext, TMeta, TContextOverrides, IntersectIfDefined<TInputIn, inferParser<$Parser>['in']>, IntersectIfDefined<TInputOut, inferParser<$Parser>['out']>, TOutputIn, TOutputOut, TCaller>;
/**
* Add an output parser to the procedure.
* @see https://trpc.io/docs/v11/server/validators
*/
output<$Parser extends Parser>(schema: $Parser): ProcedureBuilder<TContext, TMeta, TContextOverrides, TInputIn, TInputOut, IntersectIfDefined<TOutputIn, inferParser<$Parser>['in']>, IntersectIfDefined<TOutputOut, inferParser<$Parser>['out']>, TCaller>;
/**
* Add a meta data to the procedure.
* @see https://trpc.io/docs/v11/server/metadata
*/
meta(meta: TMeta): ProcedureBuilder<TContext, TMeta, TContextOverrides, TInputIn, TInputOut, TOutputIn, TOutputOut, TCaller>;
/**
* Add a middleware to the procedure.
* @see https://trpc.io/docs/v11/server/middlewares
*/
use<$ContextOverridesOut>(fn: MiddlewareBuilder<Overwrite<TContext, TContextOverrides>, TMeta, $ContextOverridesOut, TInputOut> | MiddlewareFunction<TContext, TMeta, TContextOverrides, $ContextOverridesOut, TInputOut>): ProcedureBuilder<TContext, TMeta, Overwrite<TContextOverrides, $ContextOverridesOut>, TInputIn, TInputOut, TOutputIn, TOutputOut, TCaller>;
/**
* @deprecated use {@link concat} instead
*/
unstable_concat<$Context, $Meta, $ContextOverrides, $InputIn, $InputOut, $OutputIn, $OutputOut>(builder: Overwrite<TContext, TContextOverrides> extends $Context ? TMeta extends $Meta ? ProcedureBuilder<$Context, $Meta, $ContextOverrides, $InputIn, $InputOut, $OutputIn, $OutputOut, TCaller> : TypeError<'Meta mismatch'> : TypeError<'Context mismatch'>): ProcedureBuilder<TContext, TMeta, Overwrite<TContextOverrides, $ContextOverrides>, IntersectIfDefined<TInputIn, $InputIn>, IntersectIfDefined<TInputOut, $InputOut>, IntersectIfDefined<TOutputIn, $OutputIn>, IntersectIfDefined<TOutputOut, $OutputOut>, TCaller>;
/**
* Combine two procedure builders
*/
concat<$Context, $Meta, $ContextOverrides, $InputIn, $InputOut, $OutputIn, $OutputOut>(builder: Overwrite<TContext, TContextOverrides> extends $Context ? TMeta extends $Meta ? ProcedureBuilder<$Context, $Meta, $ContextOverrides, $InputIn, $InputOut, $OutputIn, $OutputOut, TCaller> : TypeError<'Meta mismatch'> : TypeError<'Context mismatch'>): ProcedureBuilder<TContext, TMeta, Overwrite<TContextOverrides, $ContextOverrides>, IntersectIfDefined<TInputIn, $InputIn>, IntersectIfDefined<TInputOut, $InputOut>, IntersectIfDefined<TOutputIn, $OutputIn>, IntersectIfDefined<TOutputOut, $OutputOut>, TCaller>;
/**
* Query procedure
* @see https://trpc.io/docs/v11/concepts#vocabulary
*/
query<$Output>(resolver: ProcedureResolver<TContext, TMeta, TContextOverrides, TInputOut, TOutputIn, $Output>): TCaller extends true ? (input: DefaultValue<TInputIn, void>) => Promise<DefaultValue<TOutputOut, $Output>> : QueryProcedure<{
input: DefaultValue<TInputIn, void>;
output: DefaultValue<TOutputOut, $Output>;
meta: TMeta;
}>;
/**
* Mutation procedure
* @see https://trpc.io/docs/v11/concepts#vocabulary
*/
mutation<$Output>(resolver: ProcedureResolver<TContext, TMeta, TContextOverrides, TInputOut, TOutputIn, $Output>): TCaller extends true ? (input: DefaultValue<TInputIn, void>) => Promise<DefaultValue<TOutputOut, $Output>> : MutationProcedure<{
input: DefaultValue<TInputIn, void>;
output: DefaultValue<TOutputOut, $Output>;
meta: TMeta;
}>;
/**
* Subscription procedure
* @see https://trpc.io/docs/v11/server/subscriptions
*/
subscription<$Output extends AsyncIterable<any, void, any>>(resolver: ProcedureResolver<TContext, TMeta, TContextOverrides, TInputOut, TOutputIn, $Output>): TCaller extends true ? TypeError<'Not implemented'> : SubscriptionProcedure<{
input: DefaultValue<TInputIn, void>;
output: inferSubscriptionOutput<DefaultValue<TOutputOut, $Output>>;
meta: TMeta;
}>;
/**
* @deprecated Using subscriptions with an observable is deprecated. Use an async generator instead.
* This feature will be removed in v12 of tRPC.
* @see https://trpc.io/docs/v11/server/subscriptions
*/
subscription<$Output extends Observable<any, any>>(resolver: ProcedureResolver<TContext, TMeta, TContextOverrides, TInputOut, TOutputIn, $Output>): TCaller extends true ? TypeError<'Not implemented'> : LegacyObservableSubscriptionProcedure<{
input: DefaultValue<TInputIn, void>;
output: inferObservableValue<DefaultValue<TOutputOut, $Output>>;
meta: TMeta;
}>;
/**
* Overrides the way a procedure is invoked
* Do not use this unless you know what you're doing - this is an experimental API
*/
experimental_caller(caller: CallerOverride<TContext>): ProcedureBuilder<TContext, TMeta, TContextOverrides, TInputIn, TInputOut, TOutputIn, TOutputOut, true>;
/**
* @internal
*/
_def: ProcedureBuilderDef<TMeta>;
}
type ProcedureBuilderResolver = (opts: ProcedureResolverOptions<any, any, any, any>) => Promise<unknown>;
declare function createBuilder<TContext, TMeta>(initDef?: Partial<AnyProcedureBuilderDef>): ProcedureBuilder<TContext, TMeta, object, UnsetMarker, UnsetMarker, UnsetMarker, UnsetMarker, false>;
/**
* @internal
*/
interface ProcedureCallOptions<TContext> {
ctx: TContext;
getRawInput: GetRawInputFn;
input?: unknown;
path: string;
type: ProcedureType;
signal: AbortSignal | undefined;
}
//#endregion
//#region src/unstable-core-do-not-import/procedure.d.ts
declare const procedureTypes: readonly ["query", "mutation", "subscription"];
/**
* @public
*/
type ProcedureType = (typeof procedureTypes)[number];
interface BuiltProcedureDef {
meta: unknown;
input: unknown;
output: unknown;
}
/**
*
* @internal
*/
interface Procedure<TType extends ProcedureType, TDef extends BuiltProcedureDef> {
_def: {
/**
* These are just types, they can't be used at runtime
* @internal
*/
$types: {
input: TDef['input'];
output: TDef['output'];
};
procedure: true;
type: TType;
/**
* @internal
* Meta is not inferrable on individual procedures, only on the router
*/
meta: unknown;
experimental_caller: boolean;
/**
* The input parsers for the procedure
*/
inputs: Parser[];
};
meta: TDef['meta'];
/**
* @internal
*/
(opts: ProcedureCallOptions<unknown>): Promise<TDef['output']>;
}
interface QueryProcedure<TDef extends BuiltProcedureDef> extends Procedure<'query', TDef> {}
interface MutationProcedure<TDef extends BuiltProcedureDef> extends Procedure<'mutation', TDef> {}
interface SubscriptionProcedure<TDef extends BuiltProcedureDef> extends Procedure<'subscription', TDef> {}
/**
* @deprecated
*/
interface LegacyObservableSubscriptionProcedure<TDef extends BuiltProcedureDef> extends SubscriptionProcedure<TDef> {
_observable: true;
}
type AnyQueryProcedure = QueryProcedure<any>;
type AnyMutationProcedure = MutationProcedure<any>;
type AnySubscriptionProcedure = SubscriptionProcedure<any> | LegacyObservableSubscriptionProcedure<any>;
type AnyProcedure = AnyQueryProcedure | AnyMutationProcedure | AnySubscriptionProcedure;
type inferProcedureInput<TProcedure extends AnyProcedure> = undefined extends inferProcedureParams<TProcedure>['$types']['input'] ? void | inferProcedureParams<TProcedure>['$types']['input'] : inferProcedureParams<TProcedure>['$types']['input'];
type inferProcedureParams<TProcedure> = TProcedure extends AnyProcedure ? TProcedure['_def'] : never;
type inferProcedureOutput<TProcedure> = inferProcedureParams<TProcedure>['$types']['output'];
/**
* @internal
*/
interface ErrorHandlerOptions<TContext> {
error: TRPCError;
type: ProcedureType | 'unknown';
path: string | undefined;
input: unknown;
ctx: TContext | undefined;
}
//#endregion
//#region src/unstable-core-do-not-import/http/types.d.ts
/**
* @deprecated use `Headers` instead, this will be removed in v12
*/
type HTTPHeaders = Dict<string[] | string>;
interface ResponseMeta {
status?: number;
headers?: Headers | HTTPHeaders;
}
/**
* @internal
*/
type ResponseMetaFn<TRouter extends AnyRouter> = (opts: {
data: TRPCResponse<unknown, inferRouterError<TRouter>>[];
ctx?: inferRouterContext<TRouter>;
/**
* The different tRPC paths requested
* @deprecated use `info` instead, this will be removed in v12
**/
paths: readonly string[] | undefined;
info: TRPCRequestInfo | undefined;
type: ProcedureType | 'unknown';
errors: TRPCError[];
/**
* `true` if the `ResponseMeta` is being generated without knowing the response data (e.g. for streamed requests).
*/
eagerGeneration: boolean;
}) => ResponseMeta;
/**
* Base interface for anything using HTTP
*/
interface HTTPBaseHandlerOptions<TRouter extends AnyRouter, TRequest> extends BaseHandlerOptions<TRouter, TRequest> {
/**
* Add handler to be called before response is sent to the user
* Useful for setting cache headers
* @see https://trpc.io/docs/v11/caching
*/
responseMeta?: ResponseMetaFn<TRouter>;
}
type TRPCAcceptHeader = 'application/jsonl';
interface TRPCRequestInfoProcedureCall {
path: string;
/**
* Read the raw input (deduped and memoized)
*/
getRawInput: () => Promise<unknown>;
/**
* Get already parsed inputs - won't trigger reading the body or parsing the inputs
*/
result: () => unknown;
/**
* The procedure being called, `null` if not found
* @internal
*/
procedure: AnyProcedure | null;
}
/**
* Information about the incoming request
* @public
*/
interface TRPCRequestInfo {
/**
* The `trpc-accept` header
*/
accept: TRPCAcceptHeader | null;
/**
* The type of the request
*/
type: ProcedureType | 'unknown';
/**
* If the content type handler has detected that this is a batch call
*/
isBatchCall: boolean;
/**
* The calls being made
*/
calls: TRPCRequestInfoProcedureCall[];
/**
* Connection params when using `httpSubscriptionLink` or `createWSClient`
*/
connectionParams: Dict<string> | null;
/**
* Signal when the request is aborted
* Can be used to abort async operations during the request, e.g. `fetch()`-requests
*/
signal: AbortSignal;
/**
* The URL of the request if available
*/
url: URL | null;
}
/**
* Inner createContext function for `resolveResponse` used to forward `TRPCRequestInfo` to `createContext`
* @internal
*/
type ResolveHTTPRequestOptionsContextFn<TRouter extends AnyRouter> = (opts: {
info: TRPCRequestInfo;
}) => Promise<inferRouterContext<TRouter>>;
interface HTTPErrorHandlerOptions<TRouter extends AnyRouter, TRequest> extends ErrorHandlerOptions<inferRouterContext<TRouter>> {
req: TRequest;
}
/**
* @internal
*/
type HTTPErrorHandler<TRouter extends AnyRouter, TRequest> = (opts: HTTPErrorHandlerOptions<TRouter, TRequest>) => void;
/**
* Base interface for any response handler
* @internal
*/
interface BaseHandlerOptions<TRouter extends AnyRouter, TRequest> {
onError?: HTTPErrorHandler<TRouter, TRequest>;
/**
* @deprecated use `allowBatching` instead, this will be removed in v12
*/
batching?: {
/**
* @default true
*/
enabled: boolean;
};
router: TRouter;
/**
* Allow method override - will skip the method check
* @default false
*/
allowMethodOverride?: boolean;
/**
* Allow request batching
* @default true
*/
allowBatching?: boolean;
}
//#endregion
//#region src/unstable-core-do-not-import/rpc/envelopes.d.ts
/**
* Error response
*/
interface TRPCErrorShape<TData extends object = object> {
code: TRPC_ERROR_CODE_NUMBER;
message: string;
data: TData;
}
/**
* JSON-RPC 2.0 Specification
*/
declare namespace JSONRPC2 {
type RequestId = number | string | null;
/**
* All requests/responses extends this shape
*/
interface BaseEnvelope {
id?: RequestId;
jsonrpc?: '2.0';
}
interface BaseRequest<TMethod extends string = string> extends BaseEnvelope {
method: TMethod;
}
interface Request<TMethod extends string = string, TParams = unknown> extends BaseRequest<TMethod> {
params: TParams;
}
interface ResultResponse<TResult = unknown> extends BaseEnvelope {
result: TResult;
}
interface ErrorResponse<TError extends TRPCErrorShape = TRPCErrorShape> extends BaseEnvelope {
error: TError;
}
}
interface TRPCRequest extends JSONRPC2.Request<ProcedureType, {
path: string;
input: unknown;
/**
* The last event id that the client received
*/
lastEventId?: string;
}> {}
interface TRPCResult<TData = unknown> {
data: TData;
type?: 'data';
/**
* The id of the message to keep track of in case of a reconnect
*/
id?: string;
}
interface TRPCSuccessResponse<TData> extends JSONRPC2.ResultResponse<TRPCResult<TData>> {}
interface TRPCErrorResponse<TError extends TRPCErrorShape = TRPCErrorShape> extends JSONRPC2.ErrorResponse<TError> {}
type TRPCResponse<TData = unknown, TError extends TRPCErrorShape = TRPCErrorShape> = TRPCErrorResponse<TError> | TRPCSuccessResponse<TData>;
type TRPCRequestMessage = TRPCRequest & {
id: JSONRPC2.RequestId;
};
/**
* The client asked the server to unsubscribe
*/
interface TRPCSubscriptionStopNotification extends JSONRPC2.BaseRequest<'subscription.stop'> {
id: null;
}
/**
* The client's outgoing request types
*/
type TRPCClientOutgoingRequest = TRPCSubscriptionStopNotification;
/**
* The client's sent messages shape
*/
type TRPCClientOutgoingMessage = TRPCRequestMessage | (JSONRPC2.BaseRequest<'subscription.stop'> & {
id: JSONRPC2.RequestId;
});
interface TRPCResultMessage<TData> extends JSONRPC2.ResultResponse<{
type: 'started';
data?: never;
} | {
type: 'stopped';
data?: never;
} | TRPCResult<TData>> {}
type TRPCResponseMessage<TData = unknown, TError extends TRPCErrorShape = TRPCErrorShape> = {
id: JSONRPC2.RequestId;
} & (TRPCErrorResponse<TError> | TRPCResultMessage<TData>);
/**
* The server asked the client to reconnect - useful when restarting/redeploying service
*/
interface TRPCReconnectNotification extends JSONRPC2.BaseRequest<'reconnect'> {
id: JSONRPC2.RequestId;
}
/**
* The client's incoming request types
*/
type TRPCClientIncomingRequest = TRPCReconnectNotification;
/**
* The client's received messages shape
*/
type TRPCClientIncomingMessage<TResult = unknown, TError extends TRPCErrorShape = TRPCErrorShape> = TRPCClientIncomingRequest | TRPCResponseMessage<TResult, TError>;
/**
* The client sends connection params - always sent as the first message
*/
interface TRPCConnectionParamsMessage extends JSONRPC2.BaseRequest<'connectionParams'> {
data: TRPCRequestInfo['connectionParams'];
}
//# sourceMappingURL=envelopes.d.ts.map
//#endregion
//#region src/unstable-core-do-not-import/transformer.d.ts
/**
* @public
*/
interface DataTransformer {
serialize: (object: any) => any;
deserialize: (object: any) => any;
}
interface InputDataTransformer extends DataTransformer {
/**
* This function runs **on the client** before sending the data to the server.
*/
serialize: (object: any) => any;
/**
* This function runs **on the server** to transform the data before it is passed to the resolver
*/
deserialize: (object: any) => any;
}
interface OutputDataTransformer extends DataTransformer {
/**
* This function runs **on the server** before sending the data to the client.
*/
serialize: (object: any) => any;
/**
* This function runs **only on the client** to transform the data sent from the server.
*/
deserialize: (object: any) => any;
}
/**
* @public
*/
interface CombinedDataTransformer {
/**
* Specify how the data sent from the client to the server should be transformed.
*/
input: InputDataTransformer;
/**
* Specify how the data sent from the server to the client should be transformed.
*/
output: OutputDataTransformer;
}
/**
* @public
*/
type CombinedDataTransformerClient = {
input: Pick<CombinedDataTransformer['input'], 'serialize'>;
output: Pick<CombinedDataTransformer['output'], 'deserialize'>;
};
/**
* @public
*/
type DataTransformerOptions = CombinedDataTransformer | DataTransformer;
/**
* @internal
*/
declare function getDataTransformer(transformer: DataTransformerOptions): CombinedDataTransformer;
/**
* @internal
*/
declare const defaultTransformer: CombinedDataTransformer;
/**
* Takes a unserialized `TRPCResponse` and serializes it with the router's transformers
**/
declare function transformTRPCResponse<TResponse extends TRPCResponse | TRPCResponse[] | TRPCResponseMessage | TRPCResponseMessage[]>(config: RootConfig<AnyRootTypes>, itemOrItems: TResponse): TRPCSuccessResponse<unknown> | TRPCErrorResponse<TRPCErrorShape<object>> | ({
id: JSONRPC2.RequestId;
} & TRPCResultMessage<unknown>) | (TRPCResponse | TRPCResponseMessage)[];
/** @internal */
declare function transformResultInner<TRouter extends AnyRouter, TOutput>(response: TRPCResponse<TOutput, inferRouterError<TRouter>> | TRPCResponseMessage<TOutput, inferRouterError<TRouter>>, transformer: DataTransformer): {
readonly ok: false;
readonly error: {
readonly error: inferRouterError<TRouter>;
readonly id?: JSONRPC2.RequestId;
readonly jsonrpc?: "2.0";
} | {
readonly error: inferRouterError<TRouter>;
readonly id: string | number | null;
readonly jsonrpc?: "2.0";
};
readonly result?: undefined;
} | {
readonly ok: true;
readonly result: {
type: "started";
data?: never;
} | {
type: "stopped";
data?: never;
} | TRPCResult<TOutput>;
readonly error?: undefined;
};
/**
* Transforms and validates that the result is a valid TRPCResponse
* @internal
*/
declare function transformResult<TRouter extends AnyRouter, TOutput>(response: TRPCResponse<TOutput, inferRouterError<TRouter>> | TRPCResponseMessage<TOutput, inferRouterError<TRouter>>, transformer: DataTransformer): ReturnType<typeof transformResultInner>;
//#endregion
//#region src/unstable-core-do-not-import/rpc/parseTRPCMessage.d.ts
/** @public */
declare function parseTRPCMessage(obj: unknown, transformer: CombinedDataTransformer): TRPCClientOutgoingMessage;
//# sourceMappingURL=parseTRPCMessage.d.ts.map
//#endregion
//#region src/unstable-core-do-not-import/error/formatter.d.ts
/**
* @internal
*/
type ErrorFormatter<TContext, TShape extends TRPCErrorShape> = (opts: {
error: TRPCError;
type: ProcedureType | 'unknown';
path: string | undefined;
input: unknown;
ctx: TContext | undefined;
shape: DefaultErrorShape;
}) => TShape;
/**
* @internal
*/
type DefaultErrorData = {
code: TRPC_ERROR_CODE_KEY;
httpStatus: number;
/**
* Path to the procedure that threw the error
*/
path?: string;
/**
* Stack trace of the error (only in development)
*/
stack?: string;
};
/**
* @internal
*/
interface DefaultErrorShape extends TRPCErrorShape<DefaultErrorData> {
message: string;
code: TRPC_ERROR_CODE_NUMBER;
}
declare const defaultFormatter: ErrorFormatter<any, any>;
//# sourceMappingURL=formatter.d.ts.map
//#endregion
//#region src/unstable-core-do-not-import/stream/jsonl.d.ts
/**
* A subset of the standard ReadableStream properties needed by tRPC internally.
* @see ReadableStream from lib.dom.d.ts
*/
type WebReadableStreamEsque = {
getReader: () => ReadableStreamDefaultReader<Uint8Array>;
};
type NodeJSReadableStreamEsque = {
on(eventName: string | symbol, listener: (...args: any[]) => void): NodeJSReadableStreamEsque;
};
declare const CHUNK_VALUE_TYPE_PROMISE = 0;
type CHUNK_VALUE_TYPE_PROMISE = typeof CHUNK_VALUE_TYPE_PROMISE;
declare const CHUNK_VALUE_TYPE_ASYNC_ITERABLE = 1;
type CHUNK_VALUE_TYPE_ASYNC_ITERABLE = typeof CHUNK_VALUE_TYPE_ASYNC_ITERABLE;
declare const PROMISE_STATUS_FULFILLED = 0;
type PROMISE_STATUS_FULFILLED = typeof PROMISE_STATUS_FULFILLED;
declare const PROMISE_STATUS_REJECTED = 1;
type PROMISE_STATUS_REJECTED = typeof PROMISE_STATUS_REJECTED;
declare const ASYNC_ITERABLE_STATUS_RETURN = 0;
type ASYNC_ITERABLE_STATUS_RETURN = typeof ASYNC_ITERABLE_STATUS_RETURN;
declare const ASYNC_ITERABLE_STATUS_YIELD = 1;
type ASYNC_ITERABLE_STATUS_YIELD = typeof ASYNC_ITERABLE_STATUS_YIELD;
declare const ASYNC_ITERABLE_STATUS_ERROR = 2;
type ASYNC_ITERABLE_STATUS_ERROR = typeof ASYNC_ITERABLE_STATUS_ERROR;
type ChunkDefinitionKey = null | number | string;
type ChunkIndex = number & {
__chunkIndex: true;
};
type ChunkValueType = CHUNK_VALUE_TYPE_PROMISE | CHUNK_VALUE_TYPE_ASYNC_ITERABLE;
type ChunkDefinition = [key: ChunkDefinitionKey, type: ChunkValueType, chunkId: ChunkIndex];
type EncodedValue = [[unknown] | [], ...ChunkDefinition[]];
type PromiseChunk = [chunkIndex: ChunkIndex, status: PROMISE_STATUS_FULFILLED, value: EncodedValue] | [chunkIndex: ChunkIndex, status: PROMISE_STATUS_REJECTED, error: unknown];
type IterableChunk = [chunkIndex: ChunkIndex, status: ASYNC_ITERABLE_STATUS_RETURN, value: EncodedValue] | [chunkIndex: ChunkIndex, status: ASYNC_ITERABLE_STATUS_YIELD, value: EncodedValue] | [chunkIndex: ChunkIndex, status: ASYNC_ITERABLE_STATUS_ERROR, error: unknown];
type ChunkData = PromiseChunk | IterableChunk;
declare function isPromise(value: unknown): value is Promise<unknown>;
type Serialize$2 = (value: any) => any;
type Deserialize$1 = (value: any) => any;
type PathArray = readonly (string | number)[];
type ProducerOnError = (opts: {
error: unknown;
path: PathArray;
}) => void;
interface JSONLProducerOptions {
serialize?: Serialize$2;
data: Record<string, unknown> | unknown[];
onError?: ProducerOnError;
formatError?: (opts: {
error: unknown;
path: PathArray;
}) => unknown;
maxDepth?: number;
/**
* Interval in milliseconds to send a ping to the client to keep the connection alive
* This will be sent as a whitespace character
* @default undefined
*/
pingMs?: number;
}
/**
* JSON Lines stream producer
* @see https://jsonlines.org/
*/
declare function jsonlStreamProducer(opts: JSONLProducerOptions): ReadableStream<Uint8Array<ArrayBufferLike>>;
type ConsumerOnError = (opts: {
error: unknown;
}) => void;
/**
* JSON Lines stream consumer
* @see https://jsonlines.org/
*/
declare function jsonlStreamConsumer<THead>(opts: {
from: NodeJSReadableStreamEsque | WebReadableStreamEsque;
deserialize?: Deserialize$1;
onError?: ConsumerOnError;
formatError?: (opts: {
error: unknown;
}) => Error;
/**
* This `AbortController` will be triggered when there are no more listeners to the stream.
*/
abortController: AbortController;
}): Promise<readonly [Awaited<THead>, {
getOrCreate: (chunkId: ChunkIndex) => {
enqueue: (v: ChunkData) => void;
close: () => void;
closed: boolean;
getReaderResource: () => ReadableStreamDefaultReader<ChunkData> & Disposable;
error: (reason: unknown) => void;
};
isEmpty: () => boolean;
cancelAll: (reason: unknown) => void;
}]>;
//#endregion
//#region src/unstable-core-do-not-import/stream/sse.types.d.ts
/**
* @internal
*/
declare namespace EventSourceLike {
export interface InitDict {
withCredentials?: boolean;
}
export interface MessageEvent extends Event {
data: any;
lastEventId?: string;
}
export interface Event {}
type EventSourceListenerLike = (event: Event) => void;
export type AnyConstructorLike<TInit extends InitDict> = new (url: string, eventSourceInitDict?: TInit) => Instance;
export interface Instance {
readonly CLOSED: number;
readonly CONNECTING: number;
readonly OPEN: number;
addEventListener(type: string, listener: EventSourceListenerLike): void;
removeEventListener(type: string, listener: EventSourceListenerLike): void;
close: () => void;
readyState: number;
}
export type AnyConstructor = AnyConstructorLike<any>;
export type ListenerOf<T extends AnyConstructor> = Parameters<InstanceType<T>['addEventListener']>[1];
export type EventOf<T extends AnyConstructor> = Parameters<ListenerOf<T>>[0];
export type InitDictOf<T extends AnyConstructor> = ConstructorParameters<T>[1];
export {};
}
//# sourceMappingURL=sse.types.d.ts.map
//#endregion
//#region src/unstable-core-do-not-import/stream/sse.d.ts
type Serialize$1 = (value: any) => any;
type Deserialize = (value: any) => any;
/**
* @internal
*/
interface SSEPingOptions {
/**
* Enable ping comments sent from the server
* @default false
*/
enabled: boolean;
/**
* Interval in milliseconds
* @default 1000
*/
intervalMs?: number;
}
interface SSEClientOptions {
/**
* Timeout and reconnect after inactivity in milliseconds
* @default undefined
*/
reconnectAfterInactivityMs?: number;
}
interface SSEStreamProducerOptions<TValue = unknown> {
serialize?: Serialize$1;
data: AsyncIterable<TValue>;
maxDepth?: number;
ping?: SSEPingOptions;
/**
* Maximum duration in milliseconds for the request before ending the stream
* @default undefined
*/
maxDurationMs?: number;
/**
* End the request immediately after data is sent
* Only useful for serverless runtimes that do not support streaming responses
* @default false
*/
emitAndEndImmediately?: boolean;
formatError?: (opts: {
error: unknown;
}) => unknown;
/**
* Client-specific options - these will be sent to the client as part of the first message
* @default {}
*/
client?: SSEClientOptions;
}
/**
*
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
*/
declare function sseStreamProducer<TValue = unknown>(opts: SSEStreamProducerOptions<TValue>): ReadableStream<Uint8Array<ArrayBufferLike>>;
interface ConsumerStreamResultBase<TConfig extends ConsumerConfig> {
eventSource: InstanceType<TConfig['EventSource']> | null;
}
interface ConsumerStreamResultData<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
type: 'data';
data: inferTrackedOutput<TConfig['data']>;
}
interface ConsumerStreamResultError<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
type: 'serialized-error';
error: TConfig['error'];
}
interface ConsumerStreamResultConnecting<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
type: 'connecting';
event: EventSourceLike.EventOf<TConfig['EventSource']> | null;
}
interface ConsumerStreamResultTimeout<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
type: 'timeout';
ms: number;
}
interface ConsumerStreamResultPing<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
type: 'ping';
}
interface ConsumerStreamResultConnected<TConfig extends ConsumerConfig> extends ConsumerStreamResultBase<TConfig> {
type: 'connected';
options: SSEClientOptions;
}
type ConsumerStreamResult<TConfig extends ConsumerConfig> = ConsumerStreamResultData<TConfig> | ConsumerStreamResultError<TConfig> | ConsumerStreamResultConnecting<TConfig> | ConsumerStreamResultTimeout<TConfig> | ConsumerStreamResultPing<TConfig> | ConsumerStreamResultConnected<TConfig>;
interface SSEStreamConsumerOptions<TConfig extends ConsumerConfig> {
url: () => MaybePromise<string>;
init: () => MaybePromise<EventSourceLike.InitDictOf<TConfig['EventSource']>> | undefined;
signal: AbortSignal;
deserialize?: Deserialize;
EventSource: TConfig['EventSource'];
}
interface ConsumerConfig {
data: unknown;
error: unknown;
EventSource: EventSourceLike.AnyConstructor;
}
/**
* @see https://html.spec.whatwg.org/multipage/server-sent-events.html
*/
declare function sseStreamConsumer<TConfig extends ConsumerConfig>(opts: SSEStreamConsumerOptions<TConfig>): AsyncIterable<ConsumerStreamResult<TConfig>>;
declare const sseHeaders: {
readonly 'Content-Type': "text/event-stream";
readonly 'Cache-Control': "no-cache, no-transform";
readonly 'X-Accel-Buffering': "no";
readonly Connection: "keep-alive";
};
//#endregion
//#region src/unstable-core-do-not-import/rootConfig.d.ts
/**
* The initial generics that are used in the init function
* @internal
*/
interface RootTypes {
ctx: object;
meta: object;
errorShape: DefaultErrorShape;
transformer: boolean;
}
/**
* The default check to see if we're in a server
*/
declare const isServerDefault: boolean;
/**
* The tRPC root config
* @internal
*/
interface RootConfig<TTypes extends RootTypes> {
/**
* The types that are used in the config
* @internal
*/
$types: TTypes;
/**
* Use a data transformer
* @see https://trpc.io/docs/v11/data-transformers
*/
transformer: CombinedDataTransformer;
/**
* Use custom error formatting
* @see https://trpc.io/docs/v11/error-formatting
*/
errorFormatter: ErrorFormatter<TTypes['ctx'], TTypes['errorShape']>;
/**
* Allow `@trpc/server` to run in non