UNPKG

inngest

Version:

Official SDK for Inngest.com. Inngest is the reliability layer for modern applications. Inngest combines durable execution, events, and queues into a zero-infra platform with built-in observability.

187 lines (186 loc) • 8.49 kB
import { StandardSchemaV1 } from "@standard-schema/spec"; import { z } from "zod/v3"; //#region src/components/realtime/types.d.ts declare namespace Realtime { type ChannelInput = string | Realtime.ChannelInstance; namespace Subscribe { interface Token<TChannel extends Realtime.ChannelInput = Realtime.ChannelInput, TTopics extends string[] = string[]> { key?: string | undefined; channel: TChannel; topics: TTopics; apiBaseUrl?: string; } interface ClientToken { key: string; apiBaseUrl?: string; } type InferTopicSubscribeData<TTopic> = TTopic extends Realtime.TopicConfig ? Realtime.InferTopicData<TTopic> : any; type StreamSubscription<TSubscribeToken extends Token = Token, TData extends Simplify<Token.InferMessage<TSubscribeToken>> = Simplify<Token.InferMessage<TSubscribeToken>>> = ReadableStream<TData> & { /** * Get a new readable stream from the subscription that delivers JSON chunks. * * The stream starts when this function is called and will not contain any * messages that were sent before this function was called. */ getJsonStream(): ReadableStream<TData>; /** * Get a new readable stream from the subscription that delivers * SSE-compatible chunks, which are compatible with the `EventSource` API * and generally used for streaming data from a server to the browser. * * The stream starts when this function is called and will not contain any * messages that were sent before this function was called. */ getEncodedStream(): ReadableStream<Uint8Array>; /** * Close the underlying subscription connection. */ close(reason?: string): void; /** * Alias for `close()` to match callback-style subscription semantics. */ unsubscribe(reason?: string): void; }; type Callback<TSubscribeToken extends Subscribe.Token = Subscribe.Token> = (message: Token.InferMessage<TSubscribeToken>) => MaybePromise<void>; type CallbackSubscription = { close(reason?: string): void; unsubscribe(reason?: string): void; }; namespace Token { type InferChannel<TToken extends Token> = TToken extends Token<infer IChannel, any> ? IChannel : Realtime.ChannelInput; type InferTopicData<TToken extends Token, TChannelTopics extends Record<string, unknown> = Channel.InferTopics<Token.InferChannel<TToken>>> = TToken extends Token<any, infer ITopics> ? { [K in ITopics[number]]: TChannelTopics[K] } : never; type InferMessage<TToken extends Token> = Simplify<Realtime.Message<Channel.InferId<Token.InferChannel<TToken>>, Token.InferTopicData<TToken>>>; } } const messageSchema: z.ZodEffects<z.ZodObject<{ channel: z.ZodOptional<z.ZodString>; topic: z.ZodOptional<z.ZodString>; data: z.ZodAny; run_id: z.ZodOptional<z.ZodString>; fn_id: z.ZodOptional<z.ZodString>; created_at: z.ZodEffects<z.ZodOptional<z.ZodString>, Date | undefined, string | undefined>; env_id: z.ZodOptional<z.ZodString>; stream_id: z.ZodOptional<z.ZodString>; kind: z.ZodEnum<["step", "run", "data", "ping", "pong", "closing", "event", "sub", "unsub", "datastream-start", "datastream-end", "chunk"]>; }, "strip", z.ZodTypeAny, { kind: "data" | "event" | "run" | "step" | "sub" | "ping" | "pong" | "closing" | "unsub" | "datastream-start" | "datastream-end" | "chunk"; channel?: string | undefined; data?: any; topic?: string | undefined; run_id?: string | undefined; fn_id?: string | undefined; created_at?: Date | undefined; env_id?: string | undefined; stream_id?: string | undefined; }, { kind: "data" | "event" | "run" | "step" | "sub" | "ping" | "pong" | "closing" | "unsub" | "datastream-start" | "datastream-end" | "chunk"; channel?: string | undefined; data?: any; topic?: string | undefined; run_id?: string | undefined; fn_id?: string | undefined; created_at?: string | undefined; env_id?: string | undefined; stream_id?: string | undefined; }>, { data: any; kind: "data" | "event" | "run" | "step" | "sub" | "ping" | "pong" | "closing" | "unsub" | "datastream-start" | "datastream-end" | "chunk"; channel?: string | undefined; topic?: string | undefined; run_id?: string | undefined; fn_id?: string | undefined; created_at?: Date | undefined; env_id?: string | undefined; stream_id?: string | undefined; }, { kind: "data" | "event" | "run" | "step" | "sub" | "ping" | "pong" | "closing" | "unsub" | "datastream-start" | "datastream-end" | "chunk"; channel?: string | undefined; data?: any; topic?: string | undefined; run_id?: string | undefined; fn_id?: string | undefined; created_at?: string | undefined; env_id?: string | undefined; stream_id?: string | undefined; }>; type Message<TChannelId extends string = string, TTopics extends Record<string, unknown> = Record<string, unknown>> = { [K in keyof TTopics]: { topic: K; channel: TChannelId; data: Subscribe.InferTopicSubscribeData<TTopics[K]>; runId?: string; fnId?: string; createdAt: Date; envId?: string; kind: "data"; } | { topic: K; channel: TChannelId; data: Subscribe.InferTopicSubscribeData<TTopics[K]>; runId?: string; fnId?: string; kind: "datastream-start" | "datastream-end" | "chunk"; streamId: string; stream: ReadableStream<Subscribe.InferTopicSubscribeData<TTopics[K]>>; } }[keyof TTopics] | { channel?: TChannelId; topic?: string; data: unknown; runId?: string; fnId?: string; createdAt: Date; envId?: string; kind: "run"; }; namespace Message { type Input<TChannelId extends string = string, TTopicId extends string = string, TData = any> = { channel: TChannelId; topic: TTopicId; data: TData; }; type Raw<TChannelId extends string = string, TTopics extends Record<string, unknown> = Record<string, unknown>> = { [K in keyof TTopics]: { topic?: K; stream_id?: string; data: Subscribe.InferTopicSubscribeData<TTopics[K]>; channel?: TChannelId; run_id?: string; fn_id?: string; created_at?: Date; env_id?: string; kind: "step" | "run" | "data" | "datastream-start" | "datastream-end" | "ping" | "pong" | "closing" | "event" | "sub" | "unsub" | "chunk"; } }[keyof TTopics]; } namespace Channel { type InferId<TChannel extends Realtime.ChannelInstance | Realtime.ChannelDef | string> = TChannel extends Realtime.ChannelInstance<infer IId, Realtime.TopicsConfig> ? IId : TChannel extends Realtime.ChannelDef<infer TNameFn, Realtime.TopicsConfig> ? ReturnType<TNameFn> : TChannel extends string ? TChannel : string; type InferTopics<TChannel extends Realtime.ChannelInstance | Realtime.ChannelDef | string> = TChannel extends Realtime.ChannelDef<infer _NameFn, infer ITopics> ? ITopics : TChannel extends Realtime.ChannelInstance<infer _Name, infer ITopics> ? ITopics : TChannel extends string ? Record<string, unknown> : Record<string, unknown>; } type TopicConfig = { schema: StandardSchemaV1; }; type TopicsConfig = Record<string, TopicConfig>; type InferTopicData<T extends TopicConfig> = T extends { schema: infer S extends StandardSchemaV1; } ? StandardSchemaV1.InferInput<S> : unknown; interface TopicRef<_TData = unknown> { channel: string; topic: string; config: TopicConfig; } type TopicAccessors<_TName extends string, TTopics extends TopicsConfig> = { [K in string & keyof TTopics]: TopicRef<InferTopicData<TTopics[K]>> }; type ChannelInstance<TName extends string = string, TTopics extends TopicsConfig = {}> = { name: TName; topics: TTopics; } & TopicAccessors<TName, TTopics>; type ChannelDef<TNameFn extends (...args: any[]) => string = (...args: any[]) => string, TTopics extends TopicsConfig = TopicsConfig> = ((...args: Parameters<TNameFn>) => ChannelInstance<ReturnType<TNameFn>, TTopics>) & { topics: TTopics; $params: Parameters<TNameFn>[0]; }; type TypedPublishFn = <TData>(topicRef: TopicRef<TData>, data: TData) => Promise<void>; } /** * Returns the given generic as either itself or a promise of itself. */ type MaybePromise<T> = T | Promise<T>; type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {}; //#endregion export { Realtime }; //# sourceMappingURL=types.d.cts.map