Socket
Socket
Sign inDemoInstall

@effect/rpc

Package Overview
Dependencies
Maintainers
3
Versions
262
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/rpc - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

4

internal/client.js

@@ -9,7 +9,7 @@ "use strict";

var _Error = /*#__PURE__*/require("@effect/rpc/Error");
var _Resolver = /*#__PURE__*/require("@effect/rpc/Resolver");
var _Schema = /*#__PURE__*/require("@effect/rpc/Schema");
var codec = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/rpc/internal/codec"));
var resolverInternal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/rpc/internal/resolver"));
var schemaInternal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/rpc/internal/schema"));
var _Resolver = /*#__PURE__*/require("@effect/rpc/Resolver");
var _Schema = /*#__PURE__*/require("@effect/rpc/Schema");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

@@ -16,0 +16,0 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

@@ -23,3 +23,3 @@ "use strict";

const decodeEffect = schema => {
const decode = Schema.parseEffect(schema);
const decode = Schema.parse(schema);
return input => Effect.mapError(decode(input), error => (0, _Error.RpcDecodeFailure)({

@@ -40,3 +40,3 @@ errors: error.errors

const encodeEffect = schema => {
const encode = Schema.encodeEffect(schema);
const encode = Schema.encode(schema);
return (input, options) => Effect.mapError(encode(input, options), error => (0, _Error.RpcEncodeFailure)({

@@ -43,0 +43,0 @@ errors: error.errors

@@ -47,3 +47,5 @@ "use strict";

/** @internal */
const makeWithSchema = send => Resolver.makeBatched(requests => Effect.catchAll(_ => Effect.forEachDiscard(requests, request => Request.fail(request, _)))(Effect.flatMap(responses => Effect.forEachWithIndex(requests, (request, index) => {
const makeWithSchema = send => Resolver.makeBatched(requests => Effect.catchAll(_ => Effect.forEach(requests, request => Request.fail(request, _), {
discard: true
}))(Effect.flatMap(responses => Effect.forEach(requests, (request, index) => {
const response = responses[index];

@@ -50,0 +52,0 @@ return Request.complete(request, response._tag === "Success" ? Exit.succeed(response.value) : Exit.fail(response.error));

@@ -0,2 +1,7 @@

type JsonArray = ReadonlyArray<Json>;
type JsonObject = {
readonly [key: string]: Json;
};
export type Json = null | boolean | number | string | JsonArray | JsonObject;
export {};
//# sourceMappingURL=schema.d.ts.map

@@ -40,3 +40,2 @@ "use strict";

_tag: "ExternalSpan",
name: request.spanName,
spanId: request.spanId,

@@ -46,12 +45,18 @@ traceId: request.traceId,

}
})(Either.match(error => Effect.succeed({
_tag: "Error",
error
}), Effect.map(Either.match(error => ({
_tag: "Error",
error
}), value => ({
_tag: "Success",
value
}))))(Either.map(({
})(Effect.match({
onFailure: error => ({
_tag: "Error",
error
}),
onSuccess: Either.match({
onLeft: error => ({
_tag: "Error",
error
}),
onRight: value => ({
_tag: "Success",
value
})
})
})(Effect.flatMap(({
codecs,

@@ -63,18 +68,24 @@ handler,

if (request._tag === "__setup" && contextRef && scope) {
return Effect.provideService(_Scope.Scope, scope)(Effect.either(Effect.as(null)(Effect.flatMap(Option.match(() => Effect.tap(_ => Ref.set(contextRef, Option.some(_)))(Layer.isLayer(effect) ? Layer.build(effect) : effect), () => Effect.unit()))(Ref.get(contextRef)))));
return Effect.provideService(_Scope.Scope, scope)(Effect.either(Effect.as(null)(Effect.flatMap(Option.match({
onNone: () => Effect.tap(_ => Ref.set(contextRef, Option.some(_)))(Layer.isLayer(effect) ? Layer.build(effect) : effect),
onSome: () => Effect.unit
}))(Ref.get(contextRef)))));
}
return Effect.catchAll(_ => Effect.succeed(Either.flatMap(codecs.error(_), Either.left)))(Effect.map(codecs.output)(contextRef ? Effect.flatMap(Option.match(() => Effect.fail((0, _Error.RpcTransportError)({
error: "__setup not called"
})), ctx => Effect.provideSomeContext(effect, ctx)))(Ref.get(contextRef)) : effect));
})(Either.bind("input", ({
return Effect.catchAll(_ => Effect.succeed(Either.flatMap(codecs.error(_), Either.left)))(Effect.map(codecs.output)(contextRef ? Effect.flatMap(Option.match({
onNone: () => Effect.fail((0, _Error.RpcTransportError)({
error: "__setup not called"
})),
onSome: ctx => Effect.provideSomeContext(effect, ctx)
}))(Ref.get(contextRef)) : effect));
})(Effect.bind("input", ({
codecs
}) => codecs.input ? codecs.input(request.input) : Either.right(null))(Either.bind("handler", () => Either.fromNullable(handlerMap[request._tag], () => (0, _Error.RpcNotFound)({
}) => codecs.input ? codecs.input(request.input) : Either.right(null))(Effect.bind("handler", () => Either.fromNullable(handlerMap[request._tag], () => (0, _Error.RpcNotFound)({
method: request._tag
})))(Either.bind("codecs", () => Either.fromNullable(codecsMap[request._tag], () => (0, _Error.RpcNotFound)({
})))(Effect.bind("codecs", () => Either.fromNullable(codecsMap[request._tag], () => (0, _Error.RpcNotFound)({
method: request._tag ?? ""
})))(Either.Do()))))));
})))(Effect.Do))))));
if (!hasSetup) {
return handler();
}
return Effect.map(Effect.zip(Ref.make(Option.none()), Effect.scope()), ([contextRef, scope]) => handler(contextRef, scope));
return Effect.map(Effect.zip(Ref.make(Option.none()), Effect.scope), ([contextRef, scope]) => handler(contextRef, scope));
};

@@ -109,3 +120,5 @@ /** @internal */

const handler = handleSingle(router);
const run = handler => u => Array.isArray(u) ? Effect.allPar(u.map(handler)) : Effect.die(new Error("expected an array of requests"));
const run = handler => u => Array.isArray(u) ? Effect.all(u.map(handler), {
concurrency: "unbounded"
}) : Effect.die(new Error("expected an array of requests"));
if (Effect.isEffect(handler)) {

@@ -112,0 +125,0 @@ return Effect.map(handler, run);

{
"name": "@effect/rpc",
"version": "0.3.1",
"version": "0.3.2",
"license": "MIT",

@@ -10,5 +10,5 @@ "repository": {

"dependencies": {
"@effect/data": "^0.12.10",
"@effect/io": "^0.29.2",
"@effect/schema": "^0.23.0"
"@effect/data": "^0.17.1",
"@effect/io": "^0.37.1",
"@effect/schema": "^0.32.0"
},

@@ -15,0 +15,0 @@ "publishConfig": {

/**
* @since 1.0.0
*/
import type { Context, Tag } from "@effect/data/Context";
import type { LazyArg } from "@effect/data/Function";
import type { Effect } from "@effect/io/Effect";
import type { Layer } from "@effect/io/Layer";
import type { RpcSchema, RpcService } from "@effect/rpc/Schema";
import type { RpcUndecodedClient } from "@effect/rpc/Server";
import type { Context, Tag } from "@effect/data/Context";
import type { LazyArg } from "@effect/data/Function";
import type { Layer } from "@effect/io/Layer";
/**

@@ -11,0 +11,0 @@ * @category handler models

@@ -5,2 +5,4 @@ /**

import type { Context } from "@effect/data/Context";
import * as internal from "@effect/rpc/internal/schema";
import type { Json } from "@effect/rpc/internal/schema";
import type { RpcRequest } from "@effect/rpc/Resolver";

@@ -195,3 +197,3 @@ import * as Schema from "@effect/schema/Schema";

*/
export declare const make: <S extends RpcService.Definition>(schema: S) => RpcService.Simplify<RpcService.Validate<"Schema.Json", Schema.Json, S>, never, never>;
export declare const make: <S extends RpcService.Definition>(schema: S) => RpcService.Simplify<RpcService.Validate<"Schema.Json", internal.Json, S>, never, never>;
/**

@@ -204,4 +206,4 @@ * Add a service level error, which can then be used with `Router.provideServiceEffect`.

export declare const withServiceError: {
<EI extends Schema.Json, E>(error: Schema.Schema<EI, E>): <S extends RpcService.DefinitionWithId>(self: S) => RpcService.WithId<S, EI | RpcService.ErrorsFrom<S>, E | RpcService.Errors<S>>;
<S extends RpcService.DefinitionWithId, EI extends Schema.Json, E>(self: S, error: Schema.Schema<EI, E>): RpcService.WithId<S, EI | RpcService.ErrorsFrom<S>, E | RpcService.Errors<S>>;
<EI extends Json, E>(error: Schema.Schema<EI, E>): <S extends RpcService.DefinitionWithId>(self: S) => RpcService.WithId<S, EI | RpcService.ErrorsFrom<S>, E | RpcService.Errors<S>>;
<S extends RpcService.DefinitionWithId, EI extends Json, E>(self: S, error: Schema.Schema<EI, E>): RpcService.WithId<S, EI | RpcService.ErrorsFrom<S>, E | RpcService.Errors<S>>;
};

@@ -208,0 +210,0 @@ /**

@@ -21,5 +21,5 @@ "use strict";

const withConstructor = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => {
const validate = Schema.validate(self);
const validate = Schema.validateSync(self);
const validateEither = Schema.validateEither(self);
const validateEffect = Schema.validateEffect(self);
const validateEffect = Schema.validate(self);
const validateOption = Schema.validateOption(self);

@@ -26,0 +26,0 @@ function make(input) {

@@ -11,3 +11,3 @@ /**

import type { RpcHandler, RpcHandlers, RpcRouter } from "@effect/rpc/Router";
import type { RpcRequestSchema, RpcService, RpcSchema } from "@effect/rpc/Schema";
import type { RpcRequestSchema, RpcSchema, RpcService } from "@effect/rpc/Schema";
/**

@@ -14,0 +14,0 @@ * @category constructors

@@ -6,6 +6,6 @@ /**

import type { RpcError } from "@effect/rpc/Error"
import * as internal from "@effect/rpc/internal/client"
import type { RpcResolver } from "@effect/rpc/Resolver"
import type { RpcSchema, RpcService } from "@effect/rpc/Schema"
import type { UndecodedRpcResponse } from "@effect/rpc/Server"
import * as internal from "@effect/rpc/internal/client"

@@ -25,20 +25,16 @@ /**

infer O
>
? (input: I) => Effect<R, RpcError | SE | E, O>
: C extends RpcSchema.NoError<infer _II, infer I, infer _IO, infer O>
? (input: I) => Effect<R, RpcError | SE, O>
: C extends RpcSchema.NoInput<infer _IE, infer E, infer _IO, infer O>
? Effect<R, RpcError | SE | E, O>
: C extends RpcSchema.NoInputNoError<infer _IO, infer O>
? Effect<R, RpcError | SE, O>
> ? (input: I) => Effect<R, RpcError | SE | E, O>
: C extends RpcSchema.NoError<infer _II, infer I, infer _IO, infer O> ? (input: I) => Effect<R, RpcError | SE, O>
: C extends RpcSchema.NoInput<infer _IE, infer E, infer _IO, infer O> ? Effect<R, RpcError | SE | E, O>
: C extends RpcSchema.NoInputNoError<infer _IO, infer O> ? Effect<R, RpcError | SE, O>
: never
type RpcClientRpcs<S extends RpcService.DefinitionWithId, R, SE = never> = {
readonly [K in Exclude<
keyof S,
"__setup"
>]: S[K] extends RpcService.DefinitionWithId
? RpcClientRpcs<S[K], R, SE | RpcService.Errors<S>>
: S[K] extends RpcSchema.Any
? Rpc<S[K], R, SE | RpcService.Errors<S>>
readonly [
K in Exclude<
keyof S,
"__setup"
>
]: S[K] extends RpcService.DefinitionWithId ? RpcClientRpcs<S[K], R, SE | RpcService.Errors<S>>
: S[K] extends RpcSchema.Any ? Rpc<S[K], R, SE | RpcService.Errors<S>>
: never

@@ -53,15 +49,17 @@ }

*/
export type RpcClient<S extends RpcService.DefinitionWithId, R> = RpcClientRpcs<
S,
R
> & {
_schemas: S
_unsafeDecode: <
M extends RpcService.Methods<S>,
O extends UndecodedRpcResponse<M, any>,
>(
method: M,
output: O,
) => O extends UndecodedRpcResponse<M, infer O> ? O : never
}
export type RpcClient<S extends RpcService.DefinitionWithId, R> =
& RpcClientRpcs<
S,
R
>
& {
_schemas: S
_unsafeDecode: <
M extends RpcService.Methods<S>,
O extends UndecodedRpcResponse<M, any>
>(
method: M,
output: O
) => O extends UndecodedRpcResponse<M, infer O> ? O : never
}
/**

@@ -85,3 +83,3 @@ * @category models

init: RpcSchema.Input<S["__setup"]>,
options?: RpcClientOptions,
options?: RpcClientOptions
): Effect<

@@ -94,3 +92,3 @@ never,

schemas: S,
options?: RpcClientOptions,
options?: RpcClientOptions
): RpcClient<S, RpcResolver<never>>

@@ -110,3 +108,3 @@ } = internal.make

| RpcResolver<never>
| Effect<any, never, RpcResolver<never>>,
| Effect<any, never, RpcResolver<never>>
>(

@@ -116,3 +114,3 @@ schemas: S,

init: RpcSchema.Input<S["__setup"]>,
options?: RpcClientOptions | undefined,
options?: RpcClientOptions | undefined
): Effect<

@@ -123,4 +121,3 @@ never,

S,
[Resolver] extends [Effect<any, any, any>]
? Effect.Context<Resolver>
[Resolver] extends [Effect<any, any, any>] ? Effect.Context<Resolver>
: never

@@ -133,13 +130,12 @@ >

| RpcResolver<never>
| Effect<any, never, RpcResolver<never>>,
| Effect<any, never, RpcResolver<never>>
>(
schemas: S,
resolver: Resolver,
options?: RpcClientOptions | undefined,
options?: RpcClientOptions | undefined
): RpcClient<
S,
[Resolver] extends [Effect<any, any, any>]
? Effect.Context<Resolver>
[Resolver] extends [Effect<any, any, any>] ? Effect.Context<Resolver>
: never
>
} = internal.makeWithResolver

@@ -30,5 +30,5 @@ /**

_tag: Schema.literal("RpcNotFound"),
method: Schema.string,
method: Schema.string
}),
"RpcNotFound",
"RpcNotFound"
)

@@ -56,5 +56,5 @@

_tag: Schema.literal("RpcDecodeFailure"),
errors: Schema.nonEmptyArray(Schema.any),
errors: Schema.nonEmptyArray(Schema.any)
}),
"RpcDecodeFailure",
"RpcDecodeFailure"
)

@@ -82,5 +82,5 @@

_tag: Schema.literal("RpcEncodeFailure"),
errors: Schema.nonEmptyArray(Schema.any),
errors: Schema.nonEmptyArray(Schema.any)
}),
"RpcEncodeFailure",
"RpcEncodeFailure"
)

@@ -108,5 +108,5 @@

_tag: Schema.literal("RpcTransportError"),
error: Schema.unknown,
error: Schema.unknown
}),
"RpcTransportError",
"RpcTransportError"
)

@@ -132,3 +132,3 @@

RpcNotFound,
RpcTransportError,
RpcTransportError
)

@@ -5,8 +5,8 @@ import { pipe } from "@effect/data/Function"

import { RpcError } from "@effect/rpc/Error"
import * as codec from "@effect/rpc/internal/codec"
import * as resolverInternal from "@effect/rpc/internal/resolver"
import * as schemaInternal from "@effect/rpc/internal/schema"
import { RpcResolver } from "@effect/rpc/Resolver"
import type { RpcSchema, RpcService } from "@effect/rpc/Schema"
import { RpcServiceErrorId, RpcServiceId } from "@effect/rpc/Schema"
import * as codec from "@effect/rpc/internal/codec"
import * as resolverInternal from "@effect/rpc/internal/resolver"
import * as schemaInternal from "@effect/rpc/internal/schema"
import type * as Schema from "@effect/schema/Schema"

@@ -32,7 +32,7 @@

serviceErrors: ReadonlyArray<Schema.Schema<any>> = [],
prefix = "",
prefix = ""
): client.RpcClient<S, never> => {
serviceErrors = [
...serviceErrors,
schemas[RpcServiceErrorId] as Schema.Schema<any>,
schemas[RpcServiceErrorId] as Schema.Schema<any>
]

@@ -43,20 +43,19 @@

...acc,
[method]:
RpcServiceId in codec
? makeRecursive(
codec,
transport,
options,
serviceErrors,
`${prefix}${method}.`,
)
: makeRpc(
transport,
serviceErrors,
codec,
`${prefix}${method}`,
options,
),
[method]: RpcServiceId in codec
? makeRecursive(
codec,
transport,
options,
serviceErrors,
`${prefix}${method}.`
)
: makeRpc(
transport,
serviceErrors,
codec,
`${prefix}${method}`,
options
)
}),
{} as any,
{} as any
)

@@ -71,3 +70,3 @@ }

| RpcResolver<never>
| Effect.Effect<any, never, RpcResolver<never>>,
| Effect.Effect<any, never, RpcResolver<never>>
>(

@@ -77,3 +76,3 @@ schemas: S,

init: RpcService.SetupInput<S>,
options?: client.RpcClientOptions,
options?: client.RpcClientOptions
): Effect.Effect<

@@ -84,4 +83,3 @@ never,

S,
[Resolver] extends [Effect.Effect<any, any, any>]
? Effect.Effect.Context<Resolver>
[Resolver] extends [Effect.Effect<any, any, any>] ? Effect.Effect.Context<Resolver>
: never

@@ -94,11 +92,10 @@ >

| RpcResolver<never>
| Effect.Effect<any, never, RpcResolver<never>>,
| Effect.Effect<any, never, RpcResolver<never>>
>(
schemas: S,
resolver: Resolver,
options?: client.RpcClientOptions,
options?: client.RpcClientOptions
): client.RpcClient<
S,
[Resolver] extends [Effect.Effect<any, any, any>]
? Effect.Effect.Context<Resolver>
[Resolver] extends [Effect.Effect<any, any, any>] ? Effect.Effect.Context<Resolver>
: never

@@ -110,3 +107,3 @@ >

initOrOptions?: unknown,
options?: client.RpcClientOptions,
options?: client.RpcClientOptions
) => {

@@ -118,3 +115,3 @@ const hasSetup = "__setup" in schemas

_schemas: schemas,
_unsafeDecode: unsafeDecode(schemas),
_unsafeDecode: unsafeDecode(schemas)
}

@@ -134,3 +131,3 @@

init: RpcService.SetupInput<S>,
options?: client.RpcClientOptions,
options?: client.RpcClientOptions
): Effect.Effect<

@@ -143,3 +140,3 @@ never,

schemas: S,
options?: client.RpcClientOptions,
options?: client.RpcClientOptions
): client.RpcClient<S, RpcResolver<never>>

@@ -149,3 +146,3 @@ } = (

initOrOptions?: unknown,
options?: client.RpcClientOptions,
options?: client.RpcClientOptions
) => makeWithResolver(schemas, RpcResolver, initOrOptions, options) as any

@@ -158,10 +155,9 @@

method: string,
{ spanPrefix = "RpcClient" }: client.RpcClientOptions,
{ spanPrefix = "RpcClient" }: client.RpcClientOptions
): client.Rpc<S, never, never> => {
const errorSchemas =
"error" in schema
? [RpcError, schema.error, ...serviceErrors]
: [RpcError, ...serviceErrors]
const errorSchemas = "error" in schema
? [RpcError, schema.error, ...serviceErrors]
: [RpcError, ...serviceErrors]
const parseError = codec.decodeEffect(
schemaInternal.schemasToUnion(errorSchemas),
schemaInternal.schemasToUnion(errorSchemas)
)

@@ -186,14 +182,13 @@ const parseOutput = codec.decodeEffect(schema.output)

spanId: span.spanId,
traceId: span.traceId,
traceId: span.traceId
},
hash,
schema,
schema
}),
resolver,
),
resolver
)
),
Effect.flatMap(parseOutput),
Effect.catchAll((e) => Effect.flatMap(parseError(e), Effect.fail)),
),
)
Effect.catchAll((e) => Effect.flatMap(parseError(e), Effect.fail))
))
}) as any

@@ -212,13 +207,12 @@ }

spanId: span.spanId,
traceId: span.traceId,
traceId: span.traceId
},
hash,
schema,
schema
}),
resolver,
resolver
),
Effect.flatMap(parseOutput),
Effect.catchAll((e) => Effect.flatMap(parseError(e), Effect.fail)),
),
) as any
Effect.catchAll((e) => Effect.flatMap(parseError(e), Effect.fail))
)) as any
}
import * as Either from "@effect/data/Either"
import { pipe } from "@effect/data/Function"
import * as Effect from "@effect/io/Effect"
import { RpcEncodeFailure, RpcDecodeFailure } from "@effect/rpc/Error"
import { RpcDecodeFailure, RpcEncodeFailure } from "@effect/rpc/Error"
import type { ParseOptions } from "@effect/schema/AST"

@@ -12,5 +12,3 @@ import * as Schema from "@effect/schema/Schema"

return (input: unknown): Either.Either<RpcDecodeFailure, A> =>
Either.mapLeft(decode(input), (error) =>
RpcDecodeFailure({ errors: error.errors }),
)
Either.mapLeft(decode(input), (error) => RpcDecodeFailure({ errors: error.errors }))
}

@@ -20,7 +18,5 @@

export const decodeEffect = <I, A>(schema: Schema.Schema<I, A>) => {
const decode = Schema.parseEffect(schema)
const decode = Schema.parse(schema)
return (input: unknown): Effect.Effect<never, RpcDecodeFailure, A> =>
Effect.mapError(decode(input), (error) =>
RpcDecodeFailure({ errors: error.errors }),
)
Effect.mapError(decode(input), (error) => RpcDecodeFailure({ errors: error.errors }))
}

@@ -30,8 +26,8 @@

export const encode: <I, A>(
schema: Schema.Schema<I, A>,
schema: Schema.Schema<I, A>
) => (
input: A,
options?: ParseOptions | undefined,
options?: ParseOptions | undefined
) => Either.Either<RpcEncodeFailure, I> = <I, A>(
schema: Schema.Schema<I, A>,
schema: Schema.Schema<I, A>
) => {

@@ -43,3 +39,3 @@ const encode = Schema.encodeEither(schema)

encode(input, options),
Either.mapLeft((error) => RpcEncodeFailure({ errors: error.errors })),
Either.mapLeft((error) => RpcEncodeFailure({ errors: error.errors }))
)

@@ -50,15 +46,13 @@ }

export const encodeEffect: <I, A>(
schema: Schema.Schema<I, A>,
schema: Schema.Schema<I, A>
) => (
input: A,
options?: ParseOptions | undefined,
options?: ParseOptions | undefined
) => Effect.Effect<never, RpcEncodeFailure, I> = <I, A>(
schema: Schema.Schema<I, A>,
schema: Schema.Schema<I, A>
) => {
const encode = Schema.encodeEffect(schema)
const encode = Schema.encode(schema)
return (input: A, options?: ParseOptions | undefined) =>
Effect.mapError(encode(input, options), (error) =>
RpcEncodeFailure({ errors: error.errors }),
)
Effect.mapError(encode(input, options), (error) => RpcEncodeFailure({ errors: error.errors }))
}

@@ -9,4 +9,4 @@ import * as Equal from "@effect/data/Equal"

import type { RpcError, RpcTransportError } from "@effect/rpc/Error"
import { decodeEffect } from "@effect/rpc/internal/codec"
import type * as resolver from "@effect/rpc/Resolver"
import { decodeEffect } from "@effect/rpc/internal/codec"
import * as Schema from "@effect/schema/Schema"

@@ -17,3 +17,3 @@

_E: (_: never) => _,
_A: (_: never) => _,
_A: (_: never) => _
},

@@ -25,3 +25,3 @@ [Hash.symbol](this: resolver.RpcRequest) {

return this.hash === that.hash
},
}
}

@@ -33,3 +33,3 @@

input: unknown,
spanPrefix: string,
spanPrefix: string
): number =>

@@ -40,3 +40,3 @@ pipe(

Hash.combine(Hash.hash(input)),
Hash.optimize,
Hash.optimize
)

@@ -48,3 +48,3 @@

never
> = function (args) {
> = function(args) {
return Object.setPrototypeOf(args, requestProto)

@@ -56,8 +56,8 @@ }

_tag: Schema.literal("Success"),
value: Schema.unknown,
value: Schema.unknown
}),
Schema.struct({
_tag: Schema.literal("Error"),
error: Schema.unknown as Schema.Schema<RpcError>,
}),
error: Schema.unknown as Schema.Schema<RpcError>
})
)

@@ -71,4 +71,4 @@

send: (
requests: ReadonlyArray<resolver.RpcRequest>,
) => Effect.Effect<R, RpcTransportError, unknown>,
requests: ReadonlyArray<resolver.RpcRequest>
) => Effect.Effect<R, RpcTransportError, unknown>
): resolver.RpcResolver<R> =>

@@ -80,3 +80,3 @@ Resolver.makeBatched<R, resolver.RpcRequest>((requests) =>

Effect.flatMap((responses) =>
Effect.forEachWithIndex(requests, (request, index) => {
Effect.forEach(requests, (request, index) => {
const response = responses[index]

@@ -87,10 +87,12 @@ return Request.complete(

? Exit.succeed(response.value)
: Exit.fail(response.error),
: Exit.fail(response.error)
)
}),
})
),
Effect.catchAll((_) =>
Effect.forEachDiscard(requests, (request) => Request.fail(request, _)),
),
),
Effect.forEach(requests, (request) => Request.fail(request, _), {
discard: true
})
)
)
)

@@ -101,6 +103,5 @@

send: (
requests: ReadonlyArray<resolver.RpcRequest.Payload>,
) => Effect.Effect<R, RpcTransportError, unknown>,
): resolver.RpcResolver<R> =>
makeWithSchema((requests) => send(requests.map((_) => _.payload)))
requests: ReadonlyArray<resolver.RpcRequest.Payload>
) => Effect.Effect<R, RpcTransportError, unknown>
): resolver.RpcResolver<R> => makeWithSchema((requests) => send(requests.map((_) => _.payload)))

@@ -110,4 +111,4 @@ /** @internal */

send: (
request: resolver.RpcRequest,
) => Effect.Effect<R, RpcTransportError, unknown>,
request: resolver.RpcRequest
) => Effect.Effect<R, RpcTransportError, unknown>
): resolver.RpcResolver<R> =>

@@ -121,5 +122,5 @@ Resolver.fromFunctionEffect<R, resolver.RpcRequest>((request) =>

? Effect.succeed(response.value)
: Effect.fail(response.error),
),
),
: Effect.fail(response.error)
)
)
)

@@ -130,5 +131,4 @@

send: (
request: resolver.RpcRequest.Payload,
) => Effect.Effect<R, RpcTransportError, unknown>,
): resolver.RpcResolver<R> =>
makeSingleWithSchema((request) => send(request.payload))
request: resolver.RpcRequest.Payload
) => Effect.Effect<R, RpcTransportError, unknown>
): resolver.RpcResolver<R> => makeSingleWithSchema((request) => send(request.payload))

@@ -6,5 +6,5 @@ import type { Tag } from "@effect/data/Context"

import * as Layer from "@effect/io/Layer"
import { makeUndecodedClient } from "@effect/rpc/internal/server"
import type { RpcHandler, RpcHandlers, RpcRouter } from "@effect/rpc/Router"
import type { RpcService } from "@effect/rpc/Schema"
import { makeUndecodedClient } from "@effect/rpc/internal/server"

@@ -14,10 +14,10 @@ /** @internal */

S extends RpcService.DefinitionWithId,
H extends RpcHandlers.FromService<S>,
H extends RpcHandlers.FromService<S>
>(
schema: S,
handlers: H,
optionsPartial: Partial<RpcRouter.Options> = {},
optionsPartial: Partial<RpcRouter.Options> = {}
): RpcRouter<S, H> => {
const options: RpcRouter.Options = {
spanPrefix: optionsPartial.spanPrefix ?? "RpcServer",
spanPrefix: optionsPartial.spanPrefix ?? "RpcServer"
}

@@ -28,3 +28,3 @@ return {

undecoded: makeUndecodedClient(schema, handlers, options),
options,
options
}

@@ -36,3 +36,3 @@ }

tag: Tag<any, any>,
effect: Effect.Effect<any, any, any>,
effect: Effect.Effect<any, any, any>
) =>

@@ -42,11 +42,11 @@ Effect.isEffect(handler)

: (input: any) => {
const effectOrLayer = (handler as Function)(input)
return Effect.provideServiceEffect(
Layer.isLayer(effectOrLayer)
? Layer.build(effectOrLayer)
: effectOrLayer,
tag,
effect,
)
}
const effectOrLayer = (handler as Function)(input)
return Effect.provideServiceEffect(
Layer.isLayer(effectOrLayer)
? Layer.build(effectOrLayer)
: effectOrLayer,
tag,
effect
)
}

@@ -59,6 +59,6 @@ /** @internal */

R,
E extends RpcService.Errors<Router["schema"]>,
E extends RpcService.Errors<Router["schema"]>
>(
tag: T,
effect: Effect.Effect<R, E, Tag.Service<T>>,
effect: Effect.Effect<R, E, Tag.Service<T>>
): (self: Router) => RpcRouter.Provide<Router, Tag.Identifier<T>, R, E>

@@ -69,7 +69,7 @@ <

R,
E extends RpcService.Errors<Router["schema"]>,
E extends RpcService.Errors<Router["schema"]>
>(
self: Router,
tag: T,
effect: Effect.Effect<R, E, Tag.Service<T>>,
effect: Effect.Effect<R, E, Tag.Service<T>>
): RpcRouter.Provide<Router, Tag.Identifier<T>, R, E>

@@ -81,3 +81,3 @@ } = dual(

tag: T,
effect: Effect.Effect<R, E, Tag.Service<T>>,
effect: Effect.Effect<R, E, Tag.Service<T>>
): RpcRouter.Provide<Router, Tag.Identifier<T>, R, E> => {

@@ -90,7 +90,7 @@ return {

? [method, provideServiceEffect(handler as any, tag, effect)]
: [method, provideHandlerEffect(handler, tag, effect)],
),
),
: [method, provideHandlerEffect(handler, tag, effect)]
)
)
} as any
},
}
)

@@ -100,6 +100,7 @@

export const provideServiceSync: {
<T extends Tag<any, any>>(tag: T, service: LazyArg<Tag.Service<T>>): <
Router extends RpcRouter.Base,
>(
self: Router,
<T extends Tag<any, any>>(
tag: T,
service: LazyArg<Tag.Service<T>>
): <Router extends RpcRouter.Base>(
self: Router
) => RpcRouter.Provide<Router, Tag.Identifier<T>, never, never>

@@ -109,3 +110,3 @@ <Router extends RpcRouter.Base, T extends Tag<any, any>>(

tag: T,
service: LazyArg<Tag.Service<T>>,
service: LazyArg<Tag.Service<T>>
): RpcRouter.Provide<Router, Tag.Identifier<T>, never, never>

@@ -117,5 +118,4 @@ } = dual(

tag: T,
service: LazyArg<Tag.Service<T>>,
): RpcRouter.Provide<Router, Tag.Identifier<T>, never, never> =>
provideServiceEffect(self, tag, Effect.sync(service)),
service: LazyArg<Tag.Service<T>>
): RpcRouter.Provide<Router, Tag.Identifier<T>, never, never> => provideServiceEffect(self, tag, Effect.sync(service))
)

@@ -125,6 +125,7 @@

export const provideService: {
<T extends Tag<any, any>>(tag: T, service: Tag.Service<T>): <
Router extends RpcRouter.Base,
>(
self: Router,
<T extends Tag<any, any>>(
tag: T,
service: Tag.Service<T>
): <Router extends RpcRouter.Base>(
self: Router
) => RpcRouter.Provide<Router, Tag.Identifier<T>, never, never>

@@ -134,3 +135,3 @@ <Router extends RpcRouter.Base, T extends Tag<any, any>>(

tag: T,
service: Tag.Service<T>,
service: Tag.Service<T>
): RpcRouter.Provide<Router, Tag.Identifier<T>, never, never>

@@ -142,5 +143,5 @@ } = dual(

tag: T,
service: Tag.Service<T>,
service: Tag.Service<T>
): RpcRouter.Provide<Router, Tag.Identifier<T>, never, never> =>
provideServiceEffect(self, tag, Effect.succeed(service)),
provideServiceEffect(self, tag, Effect.succeed(service))
)
import { dual, identity } from "@effect/data/Function"
import type * as Effect from "@effect/io/Effect"
import type { RpcEncodeFailure } from "@effect/rpc/Error"
import { decode, encode, encodeEffect } from "@effect/rpc/internal/codec"
import type * as schema from "@effect/rpc/Schema"
import { decode, encode, encodeEffect } from "@effect/rpc/internal/codec"
import * as Schema from "@effect/schema/Schema"
type JsonArray = ReadonlyArray<Json>
type JsonObject = { readonly [key: string]: Json }
export type Json = null | boolean | number | string | JsonArray | JsonObject
/** @internal */
export const RpcServiceId: schema.RpcServiceId = Symbol.for(
"@effect/rpc/Schema/RpcService",
"@effect/rpc/Schema/RpcService"
) as schema.RpcServiceId

@@ -15,3 +19,3 @@

export const RpcServiceErrorId: schema.RpcServiceErrorId = Symbol.for(
"@effect/rpc/Schema/RpcServiceErrorId",
"@effect/rpc/Schema/RpcServiceErrorId"
) as schema.RpcServiceErrorId

@@ -21,3 +25,3 @@

export const schemasToUnion = (
schemas: ReadonlyArray<Schema.Schema<any>>,
schemas: ReadonlyArray<Schema.Schema<any>>
): Schema.Schema<any> => {

@@ -34,47 +38,46 @@ schemas = schemas.filter((s) => s !== (Schema.never as any))

/** @internal */
export const methodSchemaTransform =
<A>(
f: (schema: {
input?: Schema.Schema<any>
output: Schema.Schema<any>
error: Schema.Schema<any>
}) => A,
) =>
<S extends schema.RpcService.DefinitionWithId>(
schemas: S,
serviceErrors: ReadonlyArray<Schema.Schema<any>> = [],
prefix = "",
): Record<string, A> => {
serviceErrors = [
...serviceErrors,
schemas[RpcServiceErrorId] as Schema.Schema<any>,
]
export const methodSchemaTransform = <A>(
f: (schema: {
input?: Schema.Schema<any>
output: Schema.Schema<any>
error: Schema.Schema<any>
}) => A
) =>
<S extends schema.RpcService.DefinitionWithId>(
schemas: S,
serviceErrors: ReadonlyArray<Schema.Schema<any>> = [],
prefix = ""
): Record<string, A> => {
serviceErrors = [
...serviceErrors,
schemas[RpcServiceErrorId] as Schema.Schema<any>
]
return Object.entries(schemas).reduce((acc, [method, schema]) => {
if (RpcServiceId in schema) {
return {
...acc,
...methodSchemaTransform(f)(
schema,
serviceErrors,
`${prefix}${method}.`,
),
}
}
const errorSchemas = schema.error
? [schema.error, ...serviceErrors]
: serviceErrors
return Object.entries(schemas).reduce((acc, [method, schema]) => {
if (RpcServiceId in schema) {
return {
...acc,
[`${prefix}${method}`]: f({
input: "input" in schema ? schema.input : undefined,
output: schema.output,
error: schemasToUnion(errorSchemas),
}),
...methodSchemaTransform(f)(
schema,
serviceErrors,
`${prefix}${method}.`
)
}
}, {})
}
}
const errorSchemas = schema.error
? [schema.error, ...serviceErrors]
: serviceErrors
return {
...acc,
[`${prefix}${method}`]: f({
input: "input" in schema ? schema.input : undefined,
output: schema.output,
error: schemasToUnion(errorSchemas)
})
}
}, {})
}
/** @internal */

@@ -87,3 +90,3 @@ export const methodSchemas = methodSchemaTransform(identity)

output: encode(schema.output),
error: encode(schema.error),
error: encode(schema.error)
}))

@@ -95,3 +98,3 @@

output: decode(schema.output),
error: decode(schema.error),
error: decode(schema.error)
}))

@@ -102,3 +105,3 @@

schemas: S,
prefix = "",
prefix = ""
): Record<

@@ -112,3 +115,3 @@ string,

...acc,
...inputEncodeMap(schema, `${prefix}${method}.`),
...inputEncodeMap(schema, `${prefix}${method}.`)
}

@@ -121,3 +124,3 @@ } else if (!("input" in schema)) {

...acc,
[`${prefix}${method}`]: encodeEffect(Schema.to(schema.input)),
[`${prefix}${method}`]: encodeEffect(Schema.to(schema.input))
}

@@ -128,6 +131,6 @@ }, {})

export const withServiceError: {
<EI extends Schema.Json, E>(error: Schema.Schema<EI, E>): <
S extends schema.RpcService.DefinitionWithId,
>(
self: S,
<EI extends Json, E>(
error: Schema.Schema<EI, E>
): <S extends schema.RpcService.DefinitionWithId>(
self: S
) => schema.RpcService.WithId<

@@ -138,5 +141,5 @@ S,

>
<S extends schema.RpcService.DefinitionWithId, EI extends Schema.Json, E>(
<S extends schema.RpcService.DefinitionWithId, EI extends Json, E>(
self: S,
error: Schema.Schema<EI, E>,
error: Schema.Schema<EI, E>
): schema.RpcService.WithId<

@@ -149,5 +152,5 @@ S,

2,
<S extends schema.RpcService.DefinitionWithId, EI extends Schema.Json, E>(
<S extends schema.RpcService.DefinitionWithId, EI extends Json, E>(
self: S,
error: Schema.Schema<EI, E>,
error: Schema.Schema<EI, E>
): schema.RpcService.WithId<

@@ -161,5 +164,5 @@ S,

self[RpcServiceErrorId] as any,
error,
]),
}),
error
])
})
)

@@ -9,23 +9,10 @@ import * as Context from "@effect/data/Context"

import { Scope } from "@effect/io/Scope"
import * as Tracer from "@effect/io/Tracer"
import {
RpcNotFound,
RpcTransportError,
type RpcEncodeFailure,
type RpcError,
} from "@effect/rpc/Error"
import type * as Tracer from "@effect/io/Tracer"
import { type RpcEncodeFailure, type RpcError, RpcNotFound, RpcTransportError } from "@effect/rpc/Error"
import * as codec from "@effect/rpc/internal/codec"
import { inputEncodeMap, methodCodecs, methodSchemas } from "@effect/rpc/internal/schema"
import type { RpcRequest, RpcResponse } from "@effect/rpc/Resolver"
import type { RpcHandler, RpcHandlers, RpcRouter } from "@effect/rpc/Router"
import type {
RpcRequestSchema,
RpcSchema,
RpcService,
} from "@effect/rpc/Schema"
import type { RpcRequestSchema, RpcSchema, RpcService } from "@effect/rpc/Schema"
import type { RpcUndecodedClient } from "@effect/rpc/Server"
import * as codec from "@effect/rpc/internal/codec"
import {
inputEncodeMap,
methodCodecs,
methodSchemas,
} from "@effect/rpc/internal/schema"
import * as Schema from "@effect/schema/Schema"

@@ -35,3 +22,3 @@

handlers: H,
prefix = "",
prefix = ""
): Record<string, RpcHandler.Any> =>

@@ -42,3 +29,3 @@ Object.entries(handlers).reduce((acc, [method, definition]) => {

...acc,
...schemaHandlersMap(definition.handlers, `${prefix}${method}.`),
...schemaHandlersMap(definition.handlers, `${prefix}${method}.`)
}

@@ -51,7 +38,9 @@ }

export const handleSingle: {
<R extends RpcRouter.WithSetup>(router: R): Effect.Effect<
<R extends RpcRouter.WithSetup>(
router: R
): Effect.Effect<
Scope,
never,
(
request: unknown,
request: unknown
) => Effect.Effect<

@@ -66,4 +55,6 @@ Exclude<

>
<R extends RpcRouter.WithoutSetup>(router: R): (
request: unknown,
<R extends RpcRouter.WithoutSetup>(
router: R
): (
request: unknown
) => Effect.Effect<

@@ -79,96 +70,88 @@ Exclude<RpcHandlers.Services<R["handlers"]>, Tracer.Span>,

const handler =
(contextRef?: Ref.Ref<Option.Option<Context.Context<unknown>>>, scope?: Scope) =>
(request: RpcRequest.Payload) =>
pipe(
Either.Do(),
Either.bind("codecs", () =>
Either.fromNullable(codecsMap[request._tag], () =>
RpcNotFound({ method: request._tag ?? "" }),
),
),
Either.bind("handler", () =>
Either.fromNullable(handlerMap[request._tag], () =>
RpcNotFound({ method: request._tag }),
),
),
Either.bind("input", ({ codecs }) =>
codecs.input ? codecs.input(request.input) : Either.right(null),
),
Either.map(({ codecs, handler, input }) => {
const effect: Effect.Effect<any, unknown, unknown> = Effect.isEffect(
handler,
const handler = (
contextRef?: Ref.Ref<Option.Option<Context.Context<unknown>>>,
scope?: Scope
) =>
(request: RpcRequest.Payload) =>
pipe(
Effect.Do,
Effect.bind("codecs", () =>
Either.fromNullable(codecsMap[request._tag], () => RpcNotFound({ method: request._tag ?? "" }))),
Effect.bind("handler", () =>
Either.fromNullable(handlerMap[request._tag], () =>
RpcNotFound({ method: request._tag }))),
Effect.bind("input", ({ codecs }) =>
codecs.input ? codecs.input(request.input) : Either.right(null)),
Effect.flatMap(({ codecs, handler, input }) => {
const effect: Effect.Effect<any, unknown, unknown> = Effect.isEffect(
handler
)
? handler
: (handler as any)(input)
? handler
: (handler as any)(input)
if (request._tag === "__setup" && contextRef && scope) {
return pipe(
Ref.get(contextRef),
Effect.flatMap(
Option.match(
() =>
pipe(
Layer.isLayer(effect) ? Layer.build(effect) : effect,
Effect.tap((_) => Ref.set(contextRef, Option.some(_))),
),
() => Effect.unit(),
),
),
Effect.as(null),
Effect.either,
Effect.provideService(Scope, scope),
) as Effect.Effect<any, never, Either.Either<RpcError, unknown>>
}
if (request._tag === "__setup" && contextRef && scope) {
return pipe(
contextRef
? pipe(
Ref.get(contextRef),
Effect.flatMap(
Option.match(
() =>
Effect.fail(
RpcTransportError({ error: "__setup not called" }),
),
(ctx) => Effect.provideSomeContext(effect, ctx),
),
Ref.get(contextRef),
Effect.flatMap(
Option.match({
onNone: () =>
pipe(
Layer.isLayer(effect) ? Layer.build(effect) : effect,
Effect.tap((_) =>
Ref.set(contextRef, Option.some(_))
)
),
)
: effect,
Effect.map(codecs.output),
Effect.catchAll((_) =>
Effect.succeed(Either.flatMap(codecs.error(_), Either.left)),
onSome: () => Effect.unit
})
),
Effect.as(null),
Effect.either,
Effect.provideService(Scope, scope)
) as Effect.Effect<any, never, Either.Either<RpcError, unknown>>
}
return pipe(
contextRef
? pipe(
Ref.get(contextRef),
Effect.flatMap(
Option.match({
onNone: () =>
Effect.fail(
RpcTransportError({ error: "__setup not called" })
),
onSome: (ctx) => Effect.provideSomeContext(effect, ctx)
})
)
)
: effect,
Effect.map(codecs.output),
Effect.catchAll((_) => Effect.succeed(Either.flatMap(codecs.error(_), Either.left)))
) as Effect.Effect<any, never, Either.Either<RpcError, unknown>>
}),
Effect.match({
onFailure: (error) => ({
_tag: "Error",
error
}),
Either.match(
(error) =>
Effect.succeed({
_tag: "Error",
error,
} as RpcResponse),
Effect.map(
Either.match(
(error): RpcResponse => ({
_tag: "Error",
error,
}),
(value): RpcResponse => ({
_tag: "Success",
value,
}),
),
),
),
Effect.withSpan(`${router.options.spanPrefix}.${request._tag}`, {
parent: {
_tag: "ExternalSpan",
name: request.spanName,
spanId: request.spanId,
traceId: request.traceId,
context: Context.empty(),
},
}),
)
onSuccess: Either.match({
onLeft: (error): RpcResponse => ({
_tag: "Error",
error
}),
onRight: (value): RpcResponse => ({
_tag: "Success",
value
})
})
}),
Effect.withSpan(`${router.options.spanPrefix}.${request._tag}`, {
parent: {
_tag: "ExternalSpan",
spanId: request.spanId,
traceId: request.traceId,
context: Context.empty()
}
})
)

@@ -180,4 +163,4 @@ if (!hasSetup) {

return Effect.map(
Effect.zip(Ref.make(Option.none()), Effect.scope()),
([contextRef, scope]) => handler(contextRef, scope),
Effect.zip(Ref.make(Option.none()), Effect.scope),
([contextRef, scope]) => handler(contextRef, scope)
)

@@ -188,7 +171,9 @@ }

export const handleSingleWithSchema: {
<R extends RpcRouter.WithSetup>(router: R): Effect.Effect<
<R extends RpcRouter.WithSetup>(
router: R
): Effect.Effect<
Scope,
never,
(
request: unknown,
request: unknown
) => Effect.Effect<

@@ -203,4 +188,6 @@ Exclude<

>
<R extends RpcRouter.WithoutSetup>(router: R): (
request: unknown,
<R extends RpcRouter.WithoutSetup>(
router: R
): (
request: unknown
) => Effect.Effect<

@@ -215,13 +202,12 @@ Exclude<RpcHandlers.Services<R["handlers"]>, Tracer.Span>,

const run =
(
handle: (
request: unknown,
) => Effect.Effect<unknown, unknown, RpcResponse>,
) =>
(request: RpcRequest.Payload) =>
Effect.map(handle(request), (response) => [
response,
Option.fromNullable(schemaMap[request._tag]),
])
const run = (
handle: (
request: unknown
) => Effect.Effect<unknown, unknown, RpcResponse>
) =>
(request: RpcRequest.Payload) =>
Effect.map(handle(request), (response) => [
response,
Option.fromNullable(schemaMap[request._tag])
])

@@ -238,10 +224,10 @@ if (Effect.isEffect(handler)) {

S extends RpcService.DefinitionWithId,
H extends RpcHandlers.FromService<S>,
H extends RpcHandlers.FromService<S>
>(
schema: S,
handlers: H,
optionsPartial: Partial<RpcRouter.Options> = {},
optionsPartial: Partial<RpcRouter.Options> = {}
): RpcRouter<S, H> => {
const options: RpcRouter.Options = {
spanPrefix: optionsPartial.spanPrefix ?? "RpcServer",
spanPrefix: optionsPartial.spanPrefix ?? "RpcServer"
}

@@ -252,3 +238,3 @@ return {

undecoded: makeUndecodedClient(schema, handlers, options),
options,
options
}

@@ -259,7 +245,9 @@ }

export const handler: {
<R extends RpcRouter.WithSetup>(router: R): Effect.Effect<
<R extends RpcRouter.WithSetup>(
router: R
): Effect.Effect<
Scope,
never,
(
request: unknown,
request: unknown
) => Effect.Effect<

@@ -274,4 +262,6 @@ Exclude<

>
<R extends RpcRouter.WithoutSetup>(router: R): (
request: unknown,
<R extends RpcRouter.WithoutSetup>(
router: R
): (
request: unknown
) => Effect.Effect<

@@ -285,8 +275,6 @@ Exclude<RpcHandlers.Services<R["handlers"]>, Tracer.Span>,

const run =
(handler: () => Effect.Effect<unknown, unknown, RpcResponse>) =>
(u: Array<unknown>) =>
Array.isArray(u)
? Effect.allPar(u.map(handler))
: Effect.die(new Error("expected an array of requests"))
const run = (handler: () => Effect.Effect<unknown, unknown, RpcResponse>) => (u: Array<unknown>) =>
Array.isArray(u)
? Effect.all(u.map(handler), { concurrency: "unbounded" })
: Effect.die(new Error("expected an array of requests"))

@@ -306,6 +294,6 @@ if (Effect.isEffect(handler)) {

return <Req extends RpcRequestSchema.To<R["schema"]>>(
request: Req,
): Req extends { _tag: infer M }
? RpcHandler.FromMethod<R["handlers"], M, Tracer.Span, RpcEncodeFailure>
: never => {
request: Req
): Req extends { _tag: infer M } ? RpcHandler.FromMethod<R["handlers"], M, Tracer.Span, RpcEncodeFailure>
: never =>
{
const handler = handlerMap[(request as RpcRequest.Payload)._tag]

@@ -318,5 +306,5 @@ if (Effect.isEffect(handler)) {

inputEncoders[(request as RpcRequest.Payload)._tag](
(request as RpcRequest.Payload).input,
(request as RpcRequest.Payload).input
),
handler as any,
handler as any
) as any

@@ -329,7 +317,7 @@ }

S extends RpcService.DefinitionWithId,
H extends RpcHandlers.FromService<S>,
H extends RpcHandlers.FromService<S>
>(
schemas: S,
handlers: H,
options: RpcRouter.Options,
options: RpcRouter.Options
): RpcUndecodedClient<H> =>

@@ -344,4 +332,4 @@ Object.entries(handlers as RpcHandlers).reduce(

definition.handlers as any,
options,
),
options
)
}

@@ -358,4 +346,4 @@ }

Effect.flatMap(codec.encode(schema.output)),
Effect.withSpan(`${options.spanPrefix}.undecoded.${method}`),
),
Effect.withSpan(`${options.spanPrefix}.undecoded.${method}`)
)
}

@@ -374,7 +362,7 @@ }

Effect.flatMap(encodeOutput),
Effect.withSpan(`${options.spanPrefix}.undecoded.${method}`),
),
Effect.withSpan(`${options.spanPrefix}.undecoded.${method}`)
)
}
},
{} as any,
{} as any
)

@@ -9,4 +9,4 @@ /**

import type { RpcError, RpcTransportError } from "@effect/rpc/Error"
import * as internal from "@effect/rpc/internal/resolver"
import type { RpcSchema } from "@effect/rpc/Schema"
import * as internal from "@effect/rpc/internal/resolver"

@@ -17,4 +17,3 @@ /**

*/
export interface RpcResolver<R>
extends Resolver.RequestResolver<RpcRequest, R> {}
export interface RpcResolver<R> extends Resolver.RequestResolver<RpcRequest, R> {}

@@ -26,3 +25,3 @@ /**

export const RpcResolver = Tag<RpcResolver<never>>(
Symbol.for("@effect/rpc/RpcResolver"),
Symbol.for("@effect/rpc/RpcResolver")
)

@@ -116,4 +115,4 @@

send: (
requests: ReadonlyArray<RpcRequest.Payload>,
) => Effect.Effect<R, RpcTransportError, unknown>,
requests: ReadonlyArray<RpcRequest.Payload>
) => Effect.Effect<R, RpcTransportError, unknown>
) => RpcResolver<R> = internal.make

@@ -127,4 +126,4 @@

send: (
requests: ReadonlyArray<RpcRequest>,
) => Effect.Effect<R, RpcTransportError, unknown>,
requests: ReadonlyArray<RpcRequest>
) => Effect.Effect<R, RpcTransportError, unknown>
) => RpcResolver<R> = internal.makeWithSchema

@@ -138,4 +137,4 @@

send: (
request: RpcRequest.Payload,
) => Effect.Effect<R, RpcTransportError, unknown>,
request: RpcRequest.Payload
) => Effect.Effect<R, RpcTransportError, unknown>
) => RpcResolver<R> = internal.makeSingle

@@ -148,3 +147,3 @@

export const makeSingleWithSchema: <R>(
send: (request: RpcRequest) => Effect.Effect<R, RpcTransportError, unknown>,
send: (request: RpcRequest) => Effect.Effect<R, RpcTransportError, unknown>
) => RpcResolver<R> = internal.makeSingleWithSchema
/**
* @since 1.0.0
*/
import type { Context, Tag } from "@effect/data/Context"
import type { LazyArg } from "@effect/data/Function"
import type { Effect } from "@effect/io/Effect"
import type { Layer } from "@effect/io/Layer"
import * as internal from "@effect/rpc/internal/router"
import type { RpcSchema, RpcService } from "@effect/rpc/Schema"
import type { RpcUndecodedClient } from "@effect/rpc/Server"
import * as internal from "@effect/rpc/internal/router"
import type { Context, Tag } from "@effect/data/Context"
import type { LazyArg } from "@effect/data/Function"
import type { Layer } from "@effect/io/Layer"

@@ -60,10 +60,6 @@ /**

infer O
>
? IO<any, E, I, O>
: C extends RpcSchema.NoError<infer _II, infer I, infer _IO, infer O>
? IO<any, never, I, O>
: C extends RpcSchema.NoInput<infer _IE, infer E, infer _IO, infer O>
? NoInput<any, E, O>
: C extends RpcSchema.NoInputNoError<infer _IO, infer O>
? NoInput<any, never, O>
> ? IO<any, E, I, O>
: C extends RpcSchema.NoError<infer _II, infer I, infer _IO, infer O> ? IO<any, never, I, O>
: C extends RpcSchema.NoInput<infer _IE, infer E, infer _IO, infer O> ? NoInput<any, E, O>
: C extends RpcSchema.NoInputNoError<infer _IO, infer O> ? NoInput<any, never, O>
: never

@@ -82,9 +78,6 @@

infer O
>
? O extends Context<infer A>
? IO<any, E, I, Context<A>> | IOLayer<any, E, I, A>
: never
> ? O extends Context<infer A> ? IO<any, E, I, Context<A>> | IOLayer<any, E, I, A>
: never
: C extends RpcSchema.NoError<infer _II, infer I, infer _IO, infer O>
? O extends Context<infer A>
? IO<any, never, I, Context<A>> | IOLayer<any, never, I, A>
? O extends Context<infer A> ? IO<any, never, I, Context<A>> | IOLayer<any, never, I, A>
: never

@@ -100,4 +93,3 @@ : never

[M, any]
> extends [infer _M, infer T]
? T
> extends [infer _M, infer T] ? T
: never

@@ -110,4 +102,3 @@ }

*/
export interface RpcHandlers
extends Record<string, RpcHandler.Any | { handlers: RpcHandlers }> {}
export interface RpcHandlers extends Record<string, RpcHandler.Any | { handlers: RpcHandlers }> {}

@@ -123,10 +114,9 @@ /**

export type FromService<S extends RpcService.DefinitionWithId> = {
readonly [K in Extract<
keyof S,
string
>]: S[K] extends RpcService.DefinitionWithId
? { handlers: FromService<S[K]> }
: S[K] extends RpcSchema.Any
? K extends "__setup"
? RpcHandler.FromSetupSchema<S[K]>
readonly [
K in Extract<
keyof S,
string
>
]: S[K] extends RpcService.DefinitionWithId ? { handlers: FromService<S[K]> }
: S[K] extends RpcSchema.Any ? K extends "__setup" ? RpcHandler.FromSetupSchema<S[K]>
: RpcHandler.FromSchema<S[K]>

@@ -141,6 +131,4 @@ : never

export type Services<H extends RpcHandlers> = {
[M in keyof H]: H[M] extends { readonly handlers: RpcHandlers }
? Services<H[M]["handlers"]>
: H[M] extends RpcHandler<infer R, infer _E, infer _I, infer _O>
? R
[M in keyof H]: H[M] extends { readonly handlers: RpcHandlers } ? Services<H[M]["handlers"]>
: H[M] extends RpcHandler<infer R, infer _E, infer _I, infer _O> ? R
: never

@@ -154,6 +142,4 @@ }[keyof H]

export type Error<H extends RpcHandlers> = {
[M in keyof H]: H[M] extends { readonly handlers: RpcHandlers }
? Services<H[M]["handlers"]>
: H[M] extends RpcHandler<infer _R, infer E, infer _I, infer _O>
? E
[M in keyof H]: H[M] extends { readonly handlers: RpcHandlers } ? Services<H[M]["handlers"]>
: H[M] extends RpcHandler<infer _R, infer E, infer _I, infer _O> ? E
: never

@@ -168,10 +154,8 @@ }[keyof H]

readonly [K in keyof H]: K extends string
? H[K] extends { handlers: RpcHandlers }
? Map<H[K]["handlers"], XR, E2, `${P}${K}.`>
: H[K] extends RpcHandler.IO<infer R, infer E, infer _I, infer O>
? H[K] extends { handlers: RpcHandlers } ? Map<H[K]["handlers"], XR, E2, `${P}${K}.`>
: H[K] extends RpcHandler.IO<infer R, infer E, infer _I, infer O>
? [`${P}${K}`, Effect<Exclude<R, XR>, E | E2, O>]
: H[K] extends Effect<infer R, infer E, infer O>
? [`${P}${K}`, Effect<Exclude<R, XR>, E | E2, O>]
: never
: H[K] extends Effect<infer R, infer E, infer O> ? [`${P}${K}`, Effect<Exclude<R, XR>, E | E2, O>]
: never
: never
}[keyof H]

@@ -186,3 +170,3 @@ }

S extends RpcService.DefinitionWithId,
H extends RpcHandlers,
H extends RpcHandlers
> extends RpcRouter.Base {

@@ -247,21 +231,18 @@ readonly handlers: H

: Router["handlers"][M] extends RpcHandler.IO<
infer R,
infer E,
infer I,
infer O
>
? RpcHandler.IO<Exclude<R, XR> | PR, E | PE, I, O>
infer R,
infer E,
infer I,
infer O
> ? RpcHandler.IO<Exclude<R, XR> | PR, E | PE, I, O>
: Router["handlers"][M] extends RpcHandler.IOLayer<
infer R,
infer E,
infer I,
infer O
>
? RpcHandler.IOLayer<Exclude<R, XR> | PR, E | PE, I, O>
infer R,
infer E,
infer I,
infer O
> ? RpcHandler.IOLayer<Exclude<R, XR> | PR, E | PE, I, O>
: Router["handlers"][M] extends RpcHandler.NoInput<
infer R,
infer E,
infer O
>
? RpcHandler.NoInput<Exclude<R, XR> | PR, E | PE, O>
infer R,
infer E,
infer O
> ? RpcHandler.NoInput<Exclude<R, XR> | PR, E | PE, O>
: never

@@ -275,4 +256,9 @@ }

*/
export type SetupServices<R extends WithSetup> =
R["handlers"]["__setup"] extends RpcHandler.IOLayer<
export type SetupServices<R extends WithSetup> = R["handlers"]["__setup"] extends RpcHandler.IOLayer<
infer _R,
infer _E,
infer _I,
infer O
> ? O
: R["handlers"]["__setup"] extends RpcHandler.IO<
infer _R,

@@ -282,14 +268,5 @@ infer _E,

infer O
>
? O
: R["handlers"]["__setup"] extends RpcHandler.IO<
infer _R,
infer _E,
infer _I,
infer O
>
? O extends Context<infer Env>
? Env
: never
> ? O extends Context<infer Env> ? Env
: never
: never
}

@@ -303,7 +280,7 @@

S extends RpcService.DefinitionWithId,
H extends RpcHandlers.FromService<S>,
H extends RpcHandlers.FromService<S>
>(
schema: S,
handlers: H,
options?: Partial<RpcRouter.Options>,
options?: Partial<RpcRouter.Options>
) => RpcRouter<S, H> = internal.make

@@ -316,6 +293,7 @@

export const provideService: {
<T extends Tag<any, any>>(tag: T, service: Tag.Service<T>): <
Router extends RpcRouter.Base,
>(
self: Router,
<T extends Tag<any, any>>(
tag: T,
service: Tag.Service<T>
): <Router extends RpcRouter.Base>(
self: Router
) => RpcRouter.Provide<Router, Tag.Identifier<T>, never, never>

@@ -325,3 +303,3 @@ <Router extends RpcRouter.Base, T extends Tag<any, any>>(

tag: T,
service: Tag.Service<T>,
service: Tag.Service<T>
): RpcRouter.Provide<Router, Tag.Identifier<T>, never, never>

@@ -339,6 +317,6 @@ } = internal.provideService

R,
E extends RpcService.Errors<Router["schema"]>,
E extends RpcService.Errors<Router["schema"]>
>(
tag: T,
effect: Effect<R, E, Tag.Service<T>>,
effect: Effect<R, E, Tag.Service<T>>
): (self: Router) => RpcRouter.Provide<Router, Tag.Identifier<T>, R, E>

@@ -349,7 +327,7 @@ <

R,
E extends RpcService.Errors<Router["schema"]>,
E extends RpcService.Errors<Router["schema"]>
>(
self: Router,
tag: T,
effect: Effect<R, E, Tag.Service<T>>,
effect: Effect<R, E, Tag.Service<T>>
): RpcRouter.Provide<Router, Tag.Identifier<T>, R, E>

@@ -363,6 +341,7 @@ } = internal.provideServiceEffect

export const provideServiceSync: {
<T extends Tag<any, any>>(tag: T, service: LazyArg<Tag.Service<T>>): <
Router extends RpcRouter.Base,
>(
self: Router,
<T extends Tag<any, any>>(
tag: T,
service: LazyArg<Tag.Service<T>>
): <Router extends RpcRouter.Base>(
self: Router
) => RpcRouter.Provide<Router, Tag.Identifier<T>, never, never>

@@ -372,4 +351,4 @@ <Router extends RpcRouter.Base, T extends Tag<any, any>>(

tag: T,
service: LazyArg<Tag.Service<T>>,
service: LazyArg<Tag.Service<T>>
): RpcRouter.Provide<Router, Tag.Identifier<T>, never, never>
} = internal.provideServiceSync

@@ -5,4 +5,5 @@ /**

import type { Context } from "@effect/data/Context"
import * as internal from "@effect/rpc/internal/schema"
import type { Json } from "@effect/rpc/internal/schema"
import type { RpcRequest } from "@effect/rpc/Resolver"
import * as internal from "@effect/rpc/internal/schema"
import * as Schema from "@effect/schema/Schema"

@@ -76,4 +77,3 @@

readonly input: Schema.Schema<infer _I, infer A>
}
? A
} ? A
: never

@@ -87,4 +87,3 @@

readonly error: Schema.Schema<infer _I, infer A>
}
? A
} ? A
: never

@@ -98,4 +97,3 @@

readonly output: Schema.Schema<infer _I, infer A>
}
? A
} ? A
: never

@@ -132,4 +130,3 @@ }

*/
export interface Definition
extends Record<string, RpcSchema.Any | WithId<any, any, any>> {
export interface Definition extends Record<string, RpcSchema.Any | WithId<any, any, any>> {
__setup?:

@@ -221,6 +218,4 @@ | RpcSchema.IO<any, any, any, any, Context<any>, Context<any>>

export type Methods<S extends DefinitionWithId, P extends string = ``> = {
[M in keyof S]: M extends string
? S[M] extends DefinitionWithId
? Methods<S[M], `${P}${M}.`>
: `${P}${M}`
[M in keyof S]: M extends string ? S[M] extends DefinitionWithId ? Methods<S[M], `${P}${M}.`>
: `${P}${M}`
: never

@@ -236,30 +231,20 @@ }[keyof S]

V,
S extends RpcService.Definition,
S extends RpcService.Definition
> = {
readonly [K in keyof S]: K extends "__setup"
? S[K]
: S[K] extends DefinitionWithId
? Validate<VL, V, S[K]>
readonly [K in keyof S]: K extends "__setup" ? S[K]
: S[K] extends DefinitionWithId ? Validate<VL, V, S[K]>
: S[K] extends RpcSchema.IO<
infer IE,
infer _E,
infer II,
infer _I,
infer IO,
infer _O
>
? [IE | II | IO] extends [V]
? S[K]
infer IE,
infer _E,
infer II,
infer _I,
infer IO,
infer _O
> ? [IE | II | IO] extends [V] ? S[K]
: `schema input does not extend ${VL}`
: S[K] extends RpcSchema.NoError<infer II, infer _I, infer IO, infer _O>
? [II | IO] extends [V]
? S[K]
: S[K] extends RpcSchema.NoError<infer II, infer _I, infer IO, infer _O> ? [II | IO] extends [V] ? S[K]
: `schema input does not extend ${VL}`
: S[K] extends RpcSchema.NoInput<infer IE, infer _E, infer IO, infer _O>
? [IE | IO] extends [V]
? S[K]
: S[K] extends RpcSchema.NoInput<infer IE, infer _E, infer IO, infer _O> ? [IE | IO] extends [V] ? S[K]
: `schema input does not extend ${VL}`
: S[K] extends RpcSchema.NoInputNoError<infer IO, infer _O>
? [IO] extends [V]
? S[K]
: S[K] extends RpcSchema.NoInputNoError<infer IO, infer _O> ? [IO] extends [V] ? S[K]
: `schema input does not extend ${VL}`

@@ -276,9 +261,8 @@ : S[K]

EI,
E,
> = T extends infer S
? RpcService.WithId<
{ readonly [K in Exclude<keyof S, RpcServiceId>]: S[K] },
EI,
E
>
E
> = T extends infer S ? RpcService.WithId<
{ readonly [K in Exclude<keyof S, RpcServiceId>]: S[K] },
EI,
E
>
: never

@@ -291,11 +275,10 @@ }

*/
export const makeWith =
<VL extends string, V>() =>
<S extends RpcService.Definition>(
schema: S,
): RpcService.Simplify<RpcService.Validate<VL, V, S>, never, never> => ({
...(schema as any),
[RpcServiceId]: RpcServiceId,
[RpcServiceErrorId]: Schema.never,
})
export const makeWith = <VL extends string, V>() =>
<S extends RpcService.Definition>(
schema: S
): RpcService.Simplify<RpcService.Validate<VL, V, S>, never, never> => ({
...(schema as any),
[RpcServiceId]: RpcServiceId,
[RpcServiceErrorId]: Schema.never
})

@@ -308,3 +291,3 @@ /**

*/
export const make = makeWith<"Schema.Json", Schema.Json>()
export const make = makeWith<"Schema.Json", Json>()

@@ -318,6 +301,6 @@ /**

export const withServiceError: {
<EI extends Schema.Json, E>(error: Schema.Schema<EI, E>): <
S extends RpcService.DefinitionWithId,
>(
self: S,
<EI extends Json, E>(
error: Schema.Schema<EI, E>
): <S extends RpcService.DefinitionWithId>(
self: S
) => RpcService.WithId<

@@ -328,5 +311,5 @@ S,

>
<S extends RpcService.DefinitionWithId, EI extends Schema.Json, E>(
<S extends RpcService.DefinitionWithId, EI extends Json, E>(
self: S,
error: Schema.Schema<EI, E>,
error: Schema.Schema<EI, E>
): RpcService.WithId<

@@ -348,32 +331,26 @@ S,

export type From<S extends RpcService.Definition, P extends string = ""> = {
readonly [K in keyof S]: K extends string
? S[K] extends RpcService.DefinitionWithId
? To<S[K], `${P}${K}.`>
: S[K] extends RpcSchema.IO<
infer _IE,
infer _E,
infer II,
infer _I,
infer _IO,
infer _O
>
? { readonly _tag: `${P}${K}`; readonly input: II }
: S[K] extends RpcSchema.NoError<
infer II,
infer _I,
infer _IO,
infer _O
>
? { readonly _tag: `${P}${K}`; readonly input: II }
: S[K] extends RpcSchema.NoInput<
infer _IE,
infer _E,
infer _IO,
infer _O
>
? { readonly _tag: `${P}${K}` }
: S[K] extends RpcSchema.NoInputNoError<infer _IO, infer _O>
? { readonly _tag: `${P}${K}` }
: never
readonly [K in keyof S]: K extends string ? S[K] extends RpcService.DefinitionWithId ? To<S[K], `${P}${K}.`>
: S[K] extends RpcSchema.IO<
infer _IE,
infer _E,
infer II,
infer _I,
infer _IO,
infer _O
> ? { readonly _tag: `${P}${K}`; readonly input: II }
: S[K] extends RpcSchema.NoError<
infer II,
infer _I,
infer _IO,
infer _O
> ? { readonly _tag: `${P}${K}`; readonly input: II }
: S[K] extends RpcSchema.NoInput<
infer _IE,
infer _E,
infer _IO,
infer _O
> ? { readonly _tag: `${P}${K}` }
: S[K] extends RpcSchema.NoInputNoError<infer _IO, infer _O> ? { readonly _tag: `${P}${K}` }
: never
: never
}[keyof S]

@@ -386,32 +363,26 @@

export type To<S extends RpcService.Definition, P extends string = ""> = {
readonly [K in keyof S]: K extends string
? S[K] extends RpcService.DefinitionWithId
? To<S[K], `${P}${K}.`>
: S[K] extends RpcSchema.IO<
infer _IE,
infer _E,
infer _II,
infer I,
infer _IO,
infer _O
>
? RpcRequest.WithInput<`${P}${K}`, I>
: S[K] extends RpcSchema.NoError<
infer _II,
infer I,
infer _IO,
infer _O
>
? RpcRequest.WithInput<`${P}${K}`, I>
: S[K] extends RpcSchema.NoInput<
infer _IE,
infer _E,
infer _IO,
infer _O
>
? RpcRequest.NoInput<`${P}${K}`>
: S[K] extends RpcSchema.NoInputNoError<infer _IO, infer _O>
? RpcRequest.NoInput<`${P}${K}`>
: never
readonly [K in keyof S]: K extends string ? S[K] extends RpcService.DefinitionWithId ? To<S[K], `${P}${K}.`>
: S[K] extends RpcSchema.IO<
infer _IE,
infer _E,
infer _II,
infer I,
infer _IO,
infer _O
> ? RpcRequest.WithInput<`${P}${K}`, I>
: S[K] extends RpcSchema.NoError<
infer _II,
infer I,
infer _IO,
infer _O
> ? RpcRequest.WithInput<`${P}${K}`, I>
: S[K] extends RpcSchema.NoInput<
infer _IE,
infer _E,
infer _IO,
infer _O
> ? RpcRequest.NoInput<`${P}${K}`>
: S[K] extends RpcSchema.NoInputNoError<infer _IO, infer _O> ? RpcRequest.NoInput<`${P}${K}`>
: never
: never
}[keyof S]

@@ -423,6 +394,8 @@

*/
export type Schema<S extends RpcService.Definition> = Schema.Schema<
From<S>,
To<S>
> & {}
export type Schema<S extends RpcService.Definition> =
& Schema.Schema<
From<S>,
To<S>
>
& {}
}

@@ -441,3 +414,3 @@

export const makeRequestUnion = <S extends RpcService.Definition>(
schema: S,
schema: S
): RpcRequestSchema.Schema<S> =>

@@ -449,7 +422,7 @@ Schema.union(

? Schema.struct({
_tag: Schema.literal(tag),
input: schema.input as Schema.Schema<any, any>,
})
: Schema.struct({ _tag: Schema.literal(tag) }),
),
_tag: Schema.literal(tag),
input: schema.input as Schema.Schema<any, any>
})
: Schema.struct({ _tag: Schema.literal(tag) })
)
)

@@ -34,7 +34,7 @@ /**

self: Schema.Schema<I, A>,
f: (input: C) => A,
f: (input: C) => A
): SchemaC<I, A, C> => {
const validate = Schema.validate(self)
const validate = Schema.validateSync(self)
const validateEither = Schema.validateEither(self)
const validateEffect = Schema.validateEffect(self)
const validateEffect = Schema.validate(self)
const validateOption = Schema.validateOption(self)

@@ -57,3 +57,3 @@

return make as any
},
}
)

@@ -66,3 +66,3 @@

export const withConstructorSelf = <I, A>(
self: Schema.Schema<I, A>,
self: Schema.Schema<I, A>
): SchemaC<I, A, A> => withConstructor(self, identity)

@@ -75,9 +75,9 @@

export const withConstructorTagged: {
<A extends { readonly _tag: string }>(tag: A["_tag"]): <I>(
self: Schema.Schema<I, A>,
) => SchemaC<I, A, Omit<A, "_tag">>
<A extends { readonly _tag: string }>(
tag: A["_tag"]
): <I>(self: Schema.Schema<I, A>) => SchemaC<I, A, Omit<A, "_tag">>
<I, A extends { readonly _tag: string }>(
self: Schema.Schema<I, A>,
tag: A["_tag"],
tag: A["_tag"]
): SchemaC<I, A, Omit<A, "_tag">>

@@ -88,3 +88,3 @@ } = dual(

self: Schema.Schema<I, A>,
tag: A["_tag"],
tag: A["_tag"]
): SchemaC<I, A, Omit<A, "_tag">> =>

@@ -96,5 +96,5 @@ withConstructor(

_tag: tag,
...input,
} as A),
),
...input
}) as A
)
)

@@ -107,9 +107,9 @@

export const withConstructorDataTagged: {
<A extends { readonly _tag: string }>(tag: A["_tag"]): <I>(
self: Schema.Schema<I, A>,
) => SchemaC<I, Data.Data<A>, Omit<A, "_tag">>
<A extends { readonly _tag: string }>(
tag: A["_tag"]
): <I>(self: Schema.Schema<I, A>) => SchemaC<I, Data.Data<A>, Omit<A, "_tag">>
<I extends Record<string, any>, A extends { readonly _tag: string }>(
self: Schema.Schema<I, A>,
tag: A["_tag"],
tag: A["_tag"]
): SchemaC<I, Data.Data<A>, Omit<A, "_tag">>

@@ -120,5 +120,4 @@ } = dual(

self: Schema.Schema<I, A>,
tag: A["_tag"],
): SchemaC<I, Data.Data<A>, Omit<A, "_tag">> =>
withConstructor(Schema.data(self), Data.tagged(tag) as any),
tag: A["_tag"]
): SchemaC<I, Data.Data<A>, Omit<A, "_tag">> => withConstructor(Schema.data(self), Data.tagged(tag) as any)
)

@@ -130,5 +129,2 @@

*/
export const withTo =
<A>() =>
<I, X extends A, C>(self: SchemaC<I, X, C>): SchemaC<I, A, C> =>
self as any
export const withTo = <A>() => <I, X extends A, C>(self: SchemaC<I, X, C>): SchemaC<I, A, C> => self as any

@@ -9,10 +9,6 @@ /**

import type { RpcDecodeFailure, RpcEncodeFailure } from "@effect/rpc/Error"
import * as internal from "@effect/rpc/internal/server"
import type { RpcResponse } from "@effect/rpc/Resolver"
import type { RpcHandler, RpcHandlers, RpcRouter } from "@effect/rpc/Router"
import type {
RpcRequestSchema,
RpcService,
RpcSchema,
} from "@effect/rpc/Schema"
import * as internal from "@effect/rpc/internal/server"
import type { RpcRequestSchema, RpcSchema, RpcService } from "@effect/rpc/Schema"

@@ -24,7 +20,9 @@ /**

export const handler: {
<R extends RpcRouter.WithSetup>(router: R): Effect<
<R extends RpcRouter.WithSetup>(
router: R
): Effect<
Scope,
never,
(
request: unknown,
request: unknown
) => Effect<

@@ -39,4 +37,6 @@ Exclude<

>
<R extends RpcRouter.WithoutSetup>(router: R): (
request: unknown,
<R extends RpcRouter.WithoutSetup>(
router: R
): (
request: unknown
) => Effect<

@@ -54,7 +54,6 @@ Exclude<RpcHandlers.Services<R["handlers"]>, Span>,

export const handlerRaw: <R extends RpcRouter.Base>(
router: R,
router: R
) => <Req extends RpcRequestSchema.To<R["schema"], "">>(
request: Req,
) => Req extends { _tag: infer M }
? RpcHandler.FromMethod<R["handlers"], M, Span, RpcEncodeFailure>
request: Req
) => Req extends { _tag: infer M } ? RpcHandler.FromMethod<R["handlers"], M, Span, RpcEncodeFailure>
: never = internal.handlerRaw as any

@@ -67,7 +66,9 @@

export const handleSingle: {
<R extends RpcRouter.WithSetup>(router: R): Effect<
<R extends RpcRouter.WithSetup>(
router: R
): Effect<
Scope,
never,
(
request: unknown,
request: unknown
) => Effect<

@@ -82,4 +83,6 @@ Exclude<

>
<R extends RpcRouter.WithoutSetup>(router: R): (
request: unknown,
<R extends RpcRouter.WithoutSetup>(
router: R
): (
request: unknown
) => Effect<

@@ -97,7 +100,9 @@ Exclude<RpcHandlers.Services<R["handlers"]>, Span>,

export const handleSingleWithSchema: {
<R extends RpcRouter.WithSetup>(router: R): Effect<
<R extends RpcRouter.WithSetup>(
router: R
): Effect<
Scope,
never,
(
request: unknown,
request: unknown
) => Effect<

@@ -112,4 +117,6 @@ Exclude<

>
<R extends RpcRouter.WithoutSetup>(router: R): (
request: unknown,
<R extends RpcRouter.WithoutSetup>(
router: R
): (
request: unknown
) => Effect<

@@ -138,7 +145,5 @@ Exclude<RpcHandlers.Services<R["handlers"]>, Span>,

handlers: RpcHandlers
}
? RpcUndecodedClient<H[K]["handlers"], `${P}${K}.`>
: H[K] extends RpcHandler.IO<infer R, infer E, infer I, infer O>
? (
input: I,
} ? RpcUndecodedClient<H[K]["handlers"], `${P}${K}.`>
: H[K] extends RpcHandler.IO<infer R, infer E, infer I, infer O> ? (
input: I
) => Effect<

@@ -149,4 +154,3 @@ Exclude<R, Span>,

>
: H[K] extends Effect<infer R, infer E, infer O>
? Effect<
: H[K] extends Effect<infer R, infer E, infer O> ? Effect<
Exclude<R, Span>,

@@ -165,7 +169,7 @@ E | RpcEncodeFailure | RpcDecodeFailure,

S extends RpcService.DefinitionWithId,
H extends RpcHandlers.FromService<S>,
H extends RpcHandlers.FromService<S>
>(
schemas: S,
handlers: H,
options: RpcRouter.Options,
options: RpcRouter.Options
) => RpcUndecodedClient<H> = internal.makeUndecodedClient

@@ -194,7 +198,5 @@

export interface RpcServerSingleWithSchema {
(request: unknown): Effect<
never,
never,
readonly [RpcResponse, Option<RpcSchema.Base>]
>
(
request: unknown
): Effect<never, never, readonly [RpcResponse, Option<RpcSchema.Base>]>
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc