/** * Generates OpenRPC 1.3.2 documents for Effect RPC contracts using the * canonical JSON codec. Generation requires neither handlers nor a server and * does not install discovery methods or change the transport. * * @stability unstable * @since 4.1.3 */ import * as Context from "../Context.ts"; import * as JsonSchema from "../JsonSchema.ts"; import * as Schema from "../Schema.ts"; import * as Rpc from "./Rpc.ts"; import type * as RpcGroup from "./RpcGroup.ts"; /** * OpenRPC document generated from an RPC group. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCSpec { readonly openrpc: "1.3.2"; readonly info: OpenRPCInfo; readonly servers?: ReadonlyArray | undefined; readonly methods: ReadonlyArray; readonly components: { readonly schemas: Readonly>; }; } /** * API identity and optional publication metadata. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCInfo { readonly title: string; readonly version: string; readonly description?: string | undefined; readonly termsOfService?: string | undefined; readonly contact?: { readonly name?: string; readonly url?: string; readonly email?: string; } | undefined; readonly license?: { readonly name: string; readonly url?: string; } | undefined; } /** * Named JSON-RPC endpoint and optional URL template variables. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCServer { readonly name: string; readonly url: string; readonly summary?: string | undefined; readonly description?: string | undefined; readonly variables?: Readonly | undefined; readonly description?: string | undefined; }>> | undefined; } /** * External documentation link attached to a method or tag. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCExternalDocs { readonly url: string; readonly description?: string | undefined; } /** * Named grouping metadata for an RPC method. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCTag { readonly name: string; readonly summary?: string | undefined; readonly description?: string | undefined; readonly externalDocs?: OpenRPCExternalDocs | undefined; } /** * Named encoded JSON value used in a method example. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCExample { readonly name: string; readonly value: Schema.Json; readonly summary?: string | undefined; readonly description?: string | undefined; } /** * Paired named parameters and result illustrating a successful RPC call. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCExamplePairing { readonly name: string; readonly params: ReadonlyArray; readonly result: OpenRPCExample; readonly summary?: string | undefined; readonly description?: string | undefined; } /** * JSON-RPC error metadata. The optional `data` is an example JSON value, not a * JSON Schema; the serializer sends the encoded Effect cause in this field. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCError { readonly code: number; readonly message: string; readonly data?: Schema.Json | undefined; } /** * Named parameter or result with its canonical encoded Draft 7 JSON Schema. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCContentDescriptor { readonly name: string; readonly schema: JsonSchema.JsonSchema; readonly required?: boolean | undefined; readonly summary?: string | undefined; readonly description?: string | undefined; readonly deprecated?: boolean | undefined; } /** * JSON-RPC method with named or positional parameters and optional Effect metadata. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCMethod { readonly name: string; readonly paramStructure: "by-name" | "by-position" | "either"; /** * Known named fields or the fixed positional prefix. Dynamic keys, rest * elements, and alternative shapes require `x-effect-params-schema`. */ readonly params: ReadonlyArray; /** * Success result, or terminal completion for a streamed method. */ readonly result: OpenRPCContentDescriptor; readonly summary?: string | undefined; readonly description?: string | undefined; readonly tags?: ReadonlyArray | undefined; readonly examples?: ReadonlyArray | undefined; readonly deprecated?: boolean | undefined; readonly externalDocs?: OpenRPCExternalDocs | undefined; readonly errors?: ReadonlyArray | undefined; /** * Complete encoded parameter schema, including relationships and open-ended * keys or positions that individual OpenRPC descriptors cannot express. */ readonly "x-effect-params-schema"?: JsonSchema.JsonSchema | undefined; readonly "x-effect-stream"?: OpenRPCEffectStream | undefined; } /** * Effect-specific metadata for streamed JSON-RPC responses. * * **Details** * * Responses marked `chunk: true` carry a `result` matching `chunkSchema`, whose * elements match `itemSchema`. The method's ordinary result descriptor describes * terminal completion. Failed exits carry an encoded cause matching `causeSchema` * in `error.data`. Control methods apply where the transport enables them. * * **Gotchas** * * This extension documents Effect's existing protocol; generic OpenRPC clients * do not automatically support its streaming or control messages. * * @stability unstable * @category models * @since 4.1.3 */ export interface OpenRPCEffectStream { readonly encoding: "effect-jsonrpc"; readonly itemSchema: JsonSchema.JsonSchema; readonly chunkSchema: JsonSchema.JsonSchema; readonly errorSchema: JsonSchema.JsonSchema; readonly causeSchema: JsonSchema.JsonSchema; readonly ackMethod: "@effect/rpc/Ack"; readonly interruptMethod: "@effect/rpc/Interrupt"; } declare const Summary_base: Context.ServiceClass; /** * OpenRPC annotation for setting a method summary or group default. * * @stability unstable * @category services * @since 4.1.3 */ export declare class Summary extends Summary_base { } declare const Description_base: Context.ServiceClass; /** * OpenRPC annotation for setting a method description or group default. * * @stability unstable * @category services * @since 4.1.3 */ export declare class Description extends Description_base { } declare const Tags_base: Context.ServiceClass; /** * OpenRPC annotation for setting method tags, replacing the group default list. * * @stability unstable * @category services * @since 4.1.3 */ export declare class Tags extends Tags_base { } declare const Examples_base: Context.ServiceClass; /** * OpenRPC annotation for setting encoded call examples, replacing the group default list. * * @stability unstable * @category services * @since 4.1.3 */ export declare class Examples extends Examples_base { } declare const Deprecated_base: Context.ServiceClass; /** * OpenRPC annotation for marking a method deprecated, overriding the group default. * * @stability unstable * @category services * @since 4.1.3 */ export declare class Deprecated extends Deprecated_base { } declare const ExternalDocs_base: Context.ServiceClass; /** * OpenRPC annotation for setting external documentation or a group default. * * @stability unstable * @category services * @since 4.1.3 */ export declare class ExternalDocs extends ExternalDocs_base { } declare const Errors_base: Context.ServiceClass; /** * OpenRPC annotation for specifying error metadata. When present, it replaces * the error metadata derived from literal `code` and `message` fields. Method * lists replace group lists. * * @stability unstable * @category services * @since 4.1.3 */ export declare class Errors extends Errors_base { } /** * Builds a `Context` containing OpenRPC annotations from the supplied options. * * **Details** * * Undefined entries are omitted. False values and empty lists are retained, so * method annotations can override group defaults without inheriting their values. * * **Example** (Overriding group documentation defaults) * * ```ts import.meta.vitest * import { OpenRpc, Rpc, RpcGroup } from "effect/rpc" * * const group = RpcGroup.make( * Rpc.make("Ping").annotateMerge(OpenRpc.annotations({ * summary: "Check availability", * deprecated: false, * tags: [] * })) * ).annotate(OpenRpc.Deprecated, true).annotate(OpenRpc.Tags, [{ name: "legacy" }]) * * const document = OpenRpc.fromRpcGroup(group, { * info: { title: "Health API", version: "1.0.0" } * }) * * document.methods[0].deprecated // => false * document.methods[0].tags // => [] * ``` * * @stability unstable * @category annotations * @since 4.1.3 */ export declare const annotations: (options: Pick) => Context.Context; /** * Generates an OpenRPC 1.3.2 document describing the canonical JSON encoding of * the final composed RPC group, including middleware failures. * * **Gotchas** * * Schema generation is best-effort, as in OpenAPI; Effect decoding remains the * authority for custom predicates and approximated constraints. Structured * payloads include `x-effect-params-schema` with the complete parameter schema, * and streams include `x-effect-stream`; both require Effect-aware tooling. * Scalar payloads and schemas that cannot be converted to Draft 7 throw. Errors * without literal codes and messages are omitted unless an `Errors` annotation * is set. Void and stream completion results have a JSON null result schema. * * **Example** (Documenting a user lookup) * * ```ts import.meta.vitest * import { Schema } from "effect" * import { OpenRpc, Rpc, RpcGroup } from "effect/rpc" * * const users = RpcGroup.make( * Rpc.make("GetUser", { * payload: { id: Schema.String }, * success: Schema.Struct({ id: Schema.String, name: Schema.String }), * error: Schema.Struct({ code: Schema.Literal(404), message: Schema.Literal("User not found") }) * }).annotate(OpenRpc.Description, "Look up a user by ID") * ) * * const document = OpenRpc.fromRpcGroup(users, { * info: { title: "Users API", version: "1.0.0" }, * servers: [{ name: "production", url: "https://example.com/rpc" }] * }) * * document.methods[0].params // => [{ name: "id", required: true, schema: { type: "string" } }] * document.methods[0].errors // => [{ code: 404, message: "User not found" }] * JSON.parse(JSON.stringify(document)).openrpc // => "1.3.2" * ``` * * **Example** (Describing a positional streaming call) * * ```ts import.meta.vitest * import { Schema } from "effect" * import { OpenRpc, Rpc, RpcGroup } from "effect/rpc" * * const group = RpcGroup.make(Rpc.make("Values", { * payload: Schema.Tuple([Schema.Int]), * success: Schema.NumberFromString, * stream: true * })) * const method = OpenRpc.fromRpcGroup(group, { * info: { title: "Values API", version: "1.0.0" } * }).methods[0] * * method.paramStructure // => "by-position" * method.params.map(({ name }) => name) // => ["0"] * method.result.schema // => { type: "null" } * method["x-effect-stream"]?.itemSchema // => { type: "string" } * ``` * * @stability unstable * @category constructors * @since 4.1.3 */ export declare function fromRpcGroup(group: RpcGroup.RpcGroup, options: { readonly info: OpenRPCInfo; readonly servers?: ReadonlyArray | undefined; }): OpenRPCSpec; export {}; //# sourceMappingURL=OpenRpc.d.ts.map