@effect/rpc
Advanced tools
Comparing version 0.26.10 to 0.26.11
@@ -8,3 +8,2 @@ "use strict"; | ||
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect")); | ||
var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Either")); | ||
var _Function = /*#__PURE__*/require("effect/Function"); | ||
@@ -42,10 +41,7 @@ var _Error = /*#__PURE__*/require("../Error.js"); | ||
const unsafeDecode = schemas => { | ||
const map = schemaInternal.methodClientCodecsEither(schemas); | ||
const map = schemaInternal.methodClientCodecs(schemas); | ||
return (method, output) => { | ||
const codec = map[method].output; | ||
const result = codec ? codec(output) : Either.right(void 0); | ||
if (result._tag !== "Left") { | ||
return result.right; | ||
} | ||
throw "unsafeDecode fail"; | ||
const result = codec ? codec(output) : Effect.succeed(void 0); | ||
return Effect.runSync(result); | ||
}; | ||
@@ -52,0 +48,0 @@ }; |
@@ -6,6 +6,5 @@ "use strict"; | ||
}); | ||
exports.encodeEither = exports.encode = exports.decodeEither = exports.decode = void 0; | ||
exports.encode = exports.decode = void 0; | ||
var Schema = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Schema")); | ||
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Effect")); | ||
var Either = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Either")); | ||
var _Error = /*#__PURE__*/require("../Error.js"); | ||
@@ -38,14 +37,4 @@ function _getRequireWildcardCache(e) { | ||
/** @internal */ | ||
const decodeEither = schema => { | ||
const decode = Schema.parseEither(schema); | ||
return input => Either.mapLeft(decode(input, { | ||
errors: "all" | ||
}), error => (0, _Error.RpcDecodeFailure)({ | ||
error: error.error | ||
})); | ||
}; | ||
/** @internal */ | ||
exports.decodeEither = decodeEither; | ||
const decode = schema => { | ||
const decode = Schema.parse(schema); | ||
const decode = Schema.decodeUnknown(schema); | ||
return input => Effect.mapError(decode(input, { | ||
@@ -67,13 +56,3 @@ errors: "all" | ||
}; | ||
/** @internal */ | ||
exports.encode = encode; | ||
const encodeEither = schema => { | ||
const encode = Schema.encodeEither(schema); | ||
return input => Either.mapLeft(encode(input, { | ||
errors: "all" | ||
}), error => (0, _Error.RpcEncodeFailure)({ | ||
error: error.error | ||
})); | ||
}; | ||
exports.encodeEither = encodeEither; | ||
//# sourceMappingURL=codec.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.withServiceError = exports.withHashString = exports.withHash = exports.schemasToUnion = exports.rawClientCodecs = exports.methodSchemas = exports.methodSchemaTransform = exports.methodCodecs = exports.methodClientCodecsEither = exports.methodClientCodecs = exports.hash = exports.RpcServiceId = exports.RpcServiceErrorId = exports.HashAnnotationId = void 0; | ||
exports.withServiceError = exports.withHashString = exports.withHash = exports.schemasToUnion = exports.rawClientCodecs = exports.methodSchemas = exports.methodSchemaTransform = exports.methodCodecs = exports.methodClientCodecs = exports.hash = exports.RpcServiceId = exports.RpcServiceErrorId = exports.HashAnnotationId = void 0; | ||
var AST = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/AST")); | ||
@@ -86,8 +86,2 @@ var Schema = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Schema")); | ||
/** @internal */ | ||
const methodClientCodecsEither = exports.methodClientCodecsEither = /*#__PURE__*/methodSchemaTransform(schema => ({ | ||
input: schema.input ? Codec.encodeEither(schema.input) : undefined, | ||
output: schema.output ? Codec.decodeEither(schema.output) : undefined, | ||
error: Codec.decodeEither(schema.error) | ||
})); | ||
/** @internal */ | ||
const rawClientCodecs = (schemas, prefix = "") => Object.entries(schemas).reduce((acc, [method, schema]) => { | ||
@@ -94,0 +88,0 @@ if (RpcServiceId in schema) { |
@@ -15,3 +15,3 @@ /** | ||
*/ | ||
export type Rpc<C extends RpcSchema.Any, R, SE> = C extends RpcSchema.IO<infer _IE, infer E, infer _II, infer I, infer _IO, 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.NoOutput<infer _IE, infer E, infer _II, infer I> ? (input: I) => Effect<R, RpcError | SE | E, void> : C extends RpcSchema.NoErrorNoOutput<infer _II, infer I> ? (input: I) => Effect<R, RpcError | SE, void> : 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; | ||
export type Rpc<C extends RpcSchema.Any, R, SE> = C extends RpcSchema.IO<infer RE, infer _IE, infer E, infer RI, infer _II, infer I, infer RO, infer _IO, infer O> ? (input: I) => Effect<R | RE | RI | RO, RpcError | SE | E, O> : C extends RpcSchema.NoError<infer RI, infer _II, infer I, infer RO, infer _IO, infer O> ? (input: I) => Effect<R | RI | RO, RpcError | SE, O> : C extends RpcSchema.NoOutput<infer RE, infer _IE, infer E, infer RI, infer _II, infer I> ? (input: I) => Effect<R | RE | RI, RpcError | SE | E, void> : C extends RpcSchema.NoErrorNoOutput<infer RI, infer _II, infer I> ? (input: I) => Effect<R | RI, RpcError | SE, void> : C extends RpcSchema.NoInput<infer RE, infer _IE, infer E, infer RO, infer _IO, infer O> ? Effect<R | RE | RO, RpcError | SE | E, O> : C extends RpcSchema.NoInputNoError<infer RO, infer _IO, infer O> ? Effect<R | RO, RpcError | SE, O> : never; | ||
type RpcClientRpcs<S extends RpcService.DefinitionWithId, R, SE = never, Depth extends ReadonlyArray<number> = []> = { | ||
@@ -18,0 +18,0 @@ readonly [K in Exclude<keyof S, "__setup">]: S[K] extends RpcService.DefinitionWithId ? Depth["length"] extends 3 ? never : RpcClientRpcs<S[K], R, SE | RpcService.Errors<S>, [0, ...Depth]> : S[K] extends RpcSchema.Any ? Rpc<S[K], R, SE | RpcService.Errors<S>> : never; |
@@ -76,3 +76,3 @@ /** | ||
*/ | ||
export declare const RpcError: Schema.Schema<RpcNotFound | RpcDecodeFailure | RpcEncodeFailure | RpcTransportError, RpcNotFound | RpcDecodeFailure | RpcEncodeFailure | RpcTransportError>; | ||
export declare const RpcError: Schema.Schema<never, RpcNotFound | RpcDecodeFailure | RpcEncodeFailure | RpcTransportError, RpcNotFound | RpcDecodeFailure | RpcEncodeFailure | RpcTransportError>; | ||
//# sourceMappingURL=Error.d.ts.map |
@@ -43,3 +43,3 @@ /** | ||
*/ | ||
type FromSchema<C extends RpcSchema.Any> = C extends RpcSchema.IO<infer _IE, infer E, infer _II, infer I, infer _IO, 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> : C extends RpcSchema.NoOutput<infer _IE, infer E, infer _II, infer I> ? IO<any, E, I, void> : C extends RpcSchema.NoErrorNoOutput<infer _II, infer I> ? IO<any, never, I, void> : never; | ||
type FromSchema<C extends RpcSchema.Any> = C extends RpcSchema.IO<infer _RE, infer _IE, infer E, infer _RI, infer _II, infer I, infer _RO, infer _IO, infer O> ? IO<any, E, I, O> : C extends RpcSchema.NoError<infer _RI, infer _II, infer I, infer _RO, infer _IO, infer O> ? IO<any, never, I, O> : C extends RpcSchema.NoInput<infer _RE, infer _IE, infer E, infer _RO, infer _IO, infer O> ? NoInput<any, E, O> : C extends RpcSchema.NoInputNoError<infer _RO, infer _IO, infer O> ? NoInput<any, never, O> : C extends RpcSchema.NoOutput<infer _RE, infer _IE, infer E, infer _RI, infer _II, infer I> ? IO<any, E, I, void> : C extends RpcSchema.NoErrorNoOutput<infer _RI, infer _II, infer I> ? IO<any, never, I, void> : never; | ||
/** | ||
@@ -49,3 +49,3 @@ * @category handler utils | ||
*/ | ||
type FromSetupSchema<C> = C extends RpcSchema.NoOutput<infer _IE, infer E, infer _II, infer I> ? IO<any, E, I, Context<any>> | IOLayer<any, E, I, any> : C extends RpcSchema.NoErrorNoOutput<infer _II, infer I> ? IO<any, never, I, Context<any>> | IOLayer<any, never, I, any> : never; | ||
type FromSetupSchema<C> = C extends RpcSchema.NoOutput<infer _RE, infer _IE, infer E, infer _RI, infer _II, infer I> ? IO<any, E, I, Context<any>> | IOLayer<any, E, I, any> : C extends RpcSchema.NoErrorNoOutput<infer _RI, infer _II, infer I> ? IO<any, never, I, Context<any>> | IOLayer<any, never, I, any> : never; | ||
/** | ||
@@ -167,3 +167,3 @@ * @category handler utils | ||
*/ | ||
type Services<R extends Base> = R extends WithSetup ? Exclude<RpcHandlers.Services<R["handlers"]>, SetupServices<R>> : RpcHandlers.Services<R["handlers"]>; | ||
type Services<R extends Base> = R extends WithSetup ? Exclude<RpcHandlers.Services<R["handlers"]> | RpcSchema.Context<R["schema"]>, SetupServices<R>> : RpcHandlers.Services<R["handlers"]> | RpcSchema.Context<R["schema"]>; | ||
/** | ||
@@ -170,0 +170,0 @@ * @category router utils |
@@ -6,3 +6,2 @@ /** | ||
import * as internal from "./internal/schema.js"; | ||
import type { Json } from "./internal/schema.js"; | ||
import type { RpcRequest } from "./Resolver.js"; | ||
@@ -17,6 +16,6 @@ /** | ||
*/ | ||
interface IO<IE, E, II, I, IO, O> { | ||
readonly input: Schema.Schema<II, I>; | ||
readonly output: Schema.Schema<IO, O>; | ||
readonly error: Schema.Schema<IE, E>; | ||
interface IO<RE, IE, E, RI, II, I, RO, IO, O> { | ||
readonly input: Schema.Schema<RI, II, I>; | ||
readonly output: Schema.Schema<RO, IO, O>; | ||
readonly error: Schema.Schema<RE, IE, E>; | ||
} | ||
@@ -27,5 +26,5 @@ /** | ||
*/ | ||
interface NoError<II, I, IO, O> { | ||
readonly input: Schema.Schema<II, I>; | ||
readonly output: Schema.Schema<IO, O>; | ||
interface NoError<RI, II, I, RO, IO, O> { | ||
readonly input: Schema.Schema<RI, II, I>; | ||
readonly output: Schema.Schema<RO, IO, O>; | ||
} | ||
@@ -36,5 +35,5 @@ /** | ||
*/ | ||
interface NoInput<IE, E, IO, O> { | ||
readonly output: Schema.Schema<IO, O>; | ||
readonly error: Schema.Schema<IE, E>; | ||
interface NoInput<RE, IE, E, RO, IO, O> { | ||
readonly output: Schema.Schema<RO, IO, O>; | ||
readonly error: Schema.Schema<RE, IE, E>; | ||
} | ||
@@ -45,4 +44,4 @@ /** | ||
*/ | ||
interface NoInputNoError<IO, O> { | ||
readonly output: Schema.Schema<IO, O>; | ||
interface NoInputNoError<RO, IO, O> { | ||
readonly output: Schema.Schema<RO, IO, O>; | ||
} | ||
@@ -53,5 +52,5 @@ /** | ||
*/ | ||
interface NoOutput<IE, E, II, I> { | ||
readonly input: Schema.Schema<II, I>; | ||
readonly error: Schema.Schema<IE, E>; | ||
interface NoOutput<RE, IE, E, RI, II, I> { | ||
readonly input: Schema.Schema<RI, II, I>; | ||
readonly error: Schema.Schema<RE, IE, E>; | ||
} | ||
@@ -62,4 +61,4 @@ /** | ||
*/ | ||
interface NoErrorNoOutput<II, I> { | ||
readonly input: Schema.Schema<II, I>; | ||
interface NoErrorNoOutput<RI, II, I> { | ||
readonly input: Schema.Schema<RI, II, I>; | ||
} | ||
@@ -70,3 +69,3 @@ /** | ||
*/ | ||
type Any = IO<any, any, any, any, any, any> | NoError<any, any, any, any> | NoInput<any, any, any, any> | NoInputNoError<any, any> | NoOutput<any, any, any, any> | NoErrorNoOutput<any, any>; | ||
type Any = IO<any, any, any, any, any, any, any, any, any> | NoError<any, any, any, any, any, any> | NoInput<any, any, any, any, any, any> | NoInputNoError<any, any, any> | NoOutput<any, any, any, any, any, any> | NoErrorNoOutput<any, any, any>; | ||
/** | ||
@@ -77,5 +76,5 @@ * @category models | ||
interface Base { | ||
readonly input?: Schema.Schema<any>; | ||
readonly output?: Schema.Schema<any>; | ||
readonly error: Schema.Schema<any>; | ||
readonly input?: Schema.Schema<any, any>; | ||
readonly output?: Schema.Schema<any, any>; | ||
readonly error: Schema.Schema<any, any>; | ||
} | ||
@@ -87,3 +86,3 @@ /** | ||
type Input<S> = S extends { | ||
readonly input: Schema.Schema<infer _I, infer A>; | ||
readonly input: Schema.Schema<infer _R, infer _I, infer A>; | ||
} ? A : never; | ||
@@ -95,3 +94,3 @@ /** | ||
type Error<S> = S extends { | ||
readonly error: Schema.Schema<infer _I, infer A>; | ||
readonly error: Schema.Schema<infer _R, infer _I, infer A>; | ||
} ? A : never; | ||
@@ -103,4 +102,15 @@ /** | ||
type Output<S> = S extends { | ||
readonly output: Schema.Schema<infer _I, infer A>; | ||
readonly output: Schema.Schema<infer _R, infer _I, infer A>; | ||
} ? A : never; | ||
/** | ||
* @category utils | ||
* @since 1.0.0 | ||
*/ | ||
type Context<S> = (S extends { | ||
readonly output: Schema.Schema<infer R, infer _I, infer _A>; | ||
} ? R : never) | (S extends { | ||
readonly input: Schema.Schema<infer R, infer _I, infer _A>; | ||
} ? R : never) | (S extends { | ||
readonly error: Schema.Schema<infer R, infer _I, infer _A>; | ||
} ? R : never); | ||
} | ||
@@ -140,3 +150,3 @@ /** | ||
readonly [RpcServiceId]: RpcServiceId; | ||
readonly [RpcServiceErrorId]: Schema.Schema<any, any> | Schema.Schema<never, never>; | ||
readonly [RpcServiceErrorId]: Schema.Schema<any, any, any> | Schema.Schema<any, never, never>; | ||
} | ||
@@ -154,5 +164,5 @@ /** | ||
*/ | ||
type WithId<S, EI, E> = S & { | ||
type WithId<S, R, EI, E> = S & { | ||
readonly [RpcServiceId]: RpcServiceId; | ||
readonly [RpcServiceErrorId]: Schema.Schema<EI, E>; | ||
readonly [RpcServiceErrorId]: Schema.Schema<R, EI, E>; | ||
}; | ||
@@ -173,2 +183,7 @@ /** | ||
*/ | ||
type Context<S extends DefinitionWithId> = Schema.Schema.Context<S[RpcServiceErrorId]>; | ||
/** | ||
* @category utils | ||
* @since 1.0.0 | ||
*/ | ||
type SetupInput<S extends DefinitionWithSetup> = RpcSchema.Input<S["__setup"]>; | ||
@@ -190,3 +205,7 @@ /** | ||
type Validate<VL extends string, V, S extends RpcService.Definition, Depth extends ReadonlyArray<number> = []> = { | ||
readonly [K in keyof S]: K extends "__setup" ? S[K] : S[K] extends DefinitionWithId ? Depth["length"] extends 3 ? never : Validate<VL, V, S[K], [0, ...Depth]> : S[K] extends RpcSchema.IO<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] : `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] : `schema input does not extend ${VL}` : S[K] extends RpcSchema.NoInputNoError<infer IO, infer _O> ? [IO] extends [V] ? S[K] : `schema input does not extend ${VL}` : S[K]; | ||
readonly [K in keyof S]: K extends "__setup" ? S[K] : S[K] extends DefinitionWithId ? Depth["length"] extends 3 ? never : Validate<VL, V, S[K], [0, ...Depth]> : S[K] extends RpcSchema.IO<infer _RE, infer IE, infer _E, infer _RI, infer II, infer _I, infer _RO, infer IO, infer _O> ? [IE | II | IO] extends [V] ? S[K] : `schema input does not extend ${VL}` : S[K] extends RpcSchema.NoError<infer _RI, infer II, infer _I, infer _RO, infer IO, infer _O> ? [ | ||
II | IO | ||
] extends [V] ? S[K] : `schema input does not extend ${VL}` : S[K] extends RpcSchema.NoInput<infer _RE, infer IE, infer _E, infer _RO, infer IO, infer _O> ? [ | ||
IE | IO | ||
] extends [V] ? S[K] : `schema input does not extend ${VL}` : S[K] extends RpcSchema.NoInputNoError<infer _RO, infer IO, infer _O> ? [IO] extends [V] ? S[K] : `schema input does not extend ${VL}` : S[K]; | ||
}; | ||
@@ -197,5 +216,5 @@ /** | ||
*/ | ||
type Simplify<T, EI, E> = T extends infer S ? RpcService.WithId<{ | ||
type Simplify<T, R, EI, E> = T extends infer S ? RpcService.WithId<{ | ||
readonly [K in Exclude<keyof S, RpcServiceId>]: S[K]; | ||
}, EI, E> : never; | ||
}, R, EI, E> : never; | ||
} | ||
@@ -206,3 +225,3 @@ /** | ||
*/ | ||
export declare const makeWith: <VL extends string, V>() => <const S extends RpcService.Definition>(schema: S) => RpcService.Simplify<RpcService.Validate<VL, V, S, []>, never, never>; | ||
export declare const makeWith: <VL extends string, V>() => <const S extends RpcService.Definition>(schema: S) => RpcService.Simplify<RpcService.Validate<VL, V, S, []>, never, never, never>; | ||
/** | ||
@@ -214,3 +233,3 @@ * Make a RPC service schema that can be encoded and decoded from JSON. | ||
*/ | ||
export declare const make: <const S extends RpcService.Definition>(schema: S) => RpcService.Simplify<RpcService.Validate<"Schema.Json", internal.Json, S, []>, never, never>; | ||
export declare const make: <const S extends RpcService.Definition>(schema: S) => RpcService.Simplify<RpcService.Validate<"Schema.Json", internal.Json, S, []>, never, never, never>; | ||
/** | ||
@@ -223,4 +242,4 @@ * Add a service level error, which can then be used with `Router.provideServiceEffect`. | ||
export declare const withServiceError: { | ||
<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>>; | ||
<R, EI extends internal.Json, E>(error: Schema.Schema<R, EI, E>): <S extends RpcService.DefinitionWithId>(self: S) => RpcService.WithId<S, R | Schema.Schema.Context<S[typeof RpcServiceErrorId]>, EI | Schema.Schema.From<S[typeof RpcServiceErrorId]>, E | Schema.Schema.To<S[typeof RpcServiceErrorId]>>; | ||
<S extends RpcService.DefinitionWithId, R, EI extends internal.Json, E>(self: S, error: Schema.Schema<R, EI, E>): RpcService.WithId<S, R | Schema.Schema.Context<S[typeof RpcServiceErrorId]>, EI | Schema.Schema.From<S[typeof RpcServiceErrorId]>, E | Schema.Schema.To<S[typeof RpcServiceErrorId]>>; | ||
}; | ||
@@ -235,11 +254,16 @@ /** | ||
*/ | ||
type From<S extends RpcService.Definition, P extends string = "", Depth extends ReadonlyArray<number> = []> = Extract<keyof S, string> extends infer K ? K extends Extract<keyof S, string> ? S[K] extends RpcService.DefinitionWithId ? Depth["length"] extends 3 ? never : From<S[K], `${P}${K}.`, [0, ...Depth]> : S[K] extends RpcSchema.IO<infer _IE, infer _E, infer II, infer _I, infer _IO, infer _O> ? { | ||
type Context<S extends RpcService.Definition, Depth extends ReadonlyArray<number> = []> = Extract<keyof S, string> extends infer K ? K extends Extract<keyof S, string> ? S[K] extends RpcService.DefinitionWithId ? Depth["length"] extends 3 ? never : Context<S[K], [0, ...Depth]> : S[K] extends RpcSchema.IO<infer RE, infer _IE, infer _E, infer RI, infer _II, infer _I, infer RO, infer _IO, infer _O> ? RE | RI | RO : S[K] extends RpcSchema.NoError<infer RI, infer _II, infer _I, infer RO, infer _IO, infer _O> ? RI | RO : S[K] extends RpcSchema.NoInput<infer RI, infer _IE, infer _E, infer RO, infer _IO, infer _O> ? RI | RO : S[K] extends RpcSchema.NoInputNoError<infer RO, infer _IO, infer _O> ? RO : never : never : never; | ||
/** | ||
* @category utils | ||
* @since 1.0.0 | ||
*/ | ||
type From<S extends RpcService.Definition, P extends string = "", Depth extends ReadonlyArray<number> = []> = Extract<keyof S, string> extends infer K ? K extends Extract<keyof S, string> ? S[K] extends RpcService.DefinitionWithId ? Depth["length"] extends 3 ? never : From<S[K], `${P}${K}.`, [0, ...Depth]> : S[K] extends RpcSchema.IO<infer _RE, infer _IE, infer _E, infer _RI, infer II, infer _I, infer _RO, infer _IO, infer _O> ? { | ||
readonly _tag: `${P}${K}`; | ||
readonly input: II; | ||
} : S[K] extends RpcSchema.NoError<infer II, infer _I, infer _IO, infer _O> ? { | ||
} : S[K] extends RpcSchema.NoError<infer _RI, infer II, infer _I, infer _RO, infer _IO, infer _O> ? { | ||
readonly _tag: `${P}${K}`; | ||
readonly input: II; | ||
} : S[K] extends RpcSchema.NoInput<infer _IE, infer _E, infer _IO, infer _O> ? { | ||
} : S[K] extends RpcSchema.NoInput<infer _RI, infer _IE, infer _E, infer _RO, infer _IO, infer _O> ? { | ||
readonly _tag: `${P}${K}`; | ||
} : S[K] extends RpcSchema.NoInputNoError<infer _IO, infer _O> ? { | ||
} : S[K] extends RpcSchema.NoInputNoError<infer _RO, infer _IO, infer _O> ? { | ||
readonly _tag: `${P}${K}`; | ||
@@ -251,3 +275,3 @@ } : never : never : never; | ||
*/ | ||
type To<S extends RpcService.Definition, P extends string = "", Depth extends ReadonlyArray<number> = []> = Extract<keyof S, string> extends infer K ? K extends Extract<keyof S, string> ? S[K] extends RpcService.DefinitionWithId ? Depth["length"] extends 3 ? never : To<S[K], `${P}${K}.`, [0, ...Depth]> : 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 : never; | ||
type To<S extends RpcService.Definition, P extends string = "", Depth extends ReadonlyArray<number> = []> = Extract<keyof S, string> extends infer K ? K extends Extract<keyof S, string> ? S[K] extends RpcService.DefinitionWithId ? Depth["length"] extends 3 ? never : To<S[K], `${P}${K}.`, [0, ...Depth]> : S[K] extends RpcSchema.IO<infer _RE, infer _IE, infer _E, infer _RI, infer _II, infer I, infer _RO, infer _IO, infer _O> ? RpcRequest.WithInput<`${P}${K}`, I> : S[K] extends RpcSchema.NoError<infer _RI, infer _II, infer I, infer _RO, infer _IO, infer _O> ? RpcRequest.WithInput<`${P}${K}`, I> : S[K] extends RpcSchema.NoInput<infer _RE, infer _IE, infer _E, infer _RO, infer _IO, infer _O> ? RpcRequest.NoInput<`${P}${K}`> : S[K] extends RpcSchema.NoInputNoError<infer _RO, infer _IO, infer _O> ? RpcRequest.NoInput<`${P}${K}`> : never : never : never; | ||
/** | ||
@@ -257,3 +281,3 @@ * @category models | ||
*/ | ||
type Schema<S extends RpcService.Definition> = Schema.Schema<From<S>, To<S>> & {}; | ||
type Schema<S extends RpcService.Definition> = Schema.Schema<Context<S>, From<S>, To<S>> & {}; | ||
} | ||
@@ -264,3 +288,3 @@ /** | ||
*/ | ||
export declare const makeRequestUnion: <S extends RpcService.Definition>(schema: S) => Schema.Schema<RpcRequestSchema.From<S, "", []>, RpcRequestSchema.To<S, "", []>>; | ||
export declare const makeRequestUnion: <S extends RpcService.Definition>(schema: S) => Schema.Schema<RpcRequestSchema.Context<S, []>, RpcRequestSchema.From<S, "", []>, RpcRequestSchema.To<S, "", []>>; | ||
/** | ||
@@ -281,4 +305,4 @@ * @category type ids | ||
export declare const withHash: { | ||
<A>(f: (a: A) => number): <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A>; | ||
<I, A>(self: Schema.Schema<I, A>, f: (a: A) => number): Schema.Schema<I, A>; | ||
<A>(f: (a: A) => number): <I, R>(self: Schema.Schema<R, I, A>) => Schema.Schema<R, I, A>; | ||
<R, I, A>(self: Schema.Schema<R, I, A>, f: (a: A) => number): Schema.Schema<R, I, A>; | ||
}; | ||
@@ -290,4 +314,4 @@ /** | ||
export declare const withHashString: { | ||
<A>(f: (a: A) => string): <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A>; | ||
<I, A>(self: Schema.Schema<I, A>, f: (a: A) => string): Schema.Schema<I, A>; | ||
<A>(f: (a: A) => string): <R, I>(self: Schema.Schema<R, I, A>) => Schema.Schema<R, I, A>; | ||
<R, I, A>(self: Schema.Schema<R, I, A>, f: (a: A) => string): Schema.Schema<R, I, A>; | ||
}; | ||
@@ -298,3 +322,3 @@ /** | ||
*/ | ||
export declare const hash: <I, A>(self: Schema.Schema<I, A>, value: A) => number; | ||
export declare const hash: <R, I, A>(self: Schema.Schema<R, I, A>, value: A) => number; | ||
//# sourceMappingURL=Schema.d.ts.map |
@@ -14,3 +14,3 @@ /** | ||
*/ | ||
export interface SchemaC<I, A, C> extends Schema.Schema<I, A> { | ||
export interface SchemaC<I, A, C> extends Schema.Schema<never, I, A> { | ||
(input: C): A; | ||
@@ -26,4 +26,4 @@ readonly either: (input: C) => Either<ParseError, A>; | ||
export declare const withConstructor: { | ||
<A, C>(f: (input: C) => A): <I>(self: Schema.Schema<I, A>) => SchemaC<I, A, C>; | ||
<I, A, C>(self: Schema.Schema<I, A>, f: (input: C) => A): SchemaC<I, A, C>; | ||
<A, C>(f: (input: C) => A): <I>(self: Schema.Schema<never, I, A>) => SchemaC<I, A, C>; | ||
<I, A, C>(self: Schema.Schema<never, I, A>, f: (input: C) => A): SchemaC<I, A, C>; | ||
}; | ||
@@ -34,3 +34,3 @@ /** | ||
*/ | ||
export declare const withConstructorSelf: <I, A>(self: Schema.Schema<I, A>) => SchemaC<I, A, A>; | ||
export declare const withConstructorSelf: <I, A>(self: Schema.Schema<never, I, A>) => SchemaC<I, A, A>; | ||
/** | ||
@@ -43,6 +43,6 @@ * @category combinators | ||
readonly _tag: string; | ||
}>(tag: A["_tag"]): <I>(self: Schema.Schema<I, A>) => SchemaC<I, A, Omit<A, "_tag">>; | ||
}>(tag: A["_tag"]): <I>(self: Schema.Schema<never, I, A>) => SchemaC<I, A, Omit<A, "_tag">>; | ||
<I, A extends { | ||
readonly _tag: string; | ||
}>(self: Schema.Schema<I, A>, tag: A["_tag"]): SchemaC<I, A, Omit<A, "_tag">>; | ||
}>(self: Schema.Schema<never, I, A>, tag: A["_tag"]): SchemaC<I, A, Omit<A, "_tag">>; | ||
}; | ||
@@ -56,6 +56,6 @@ /** | ||
readonly _tag: string; | ||
}>(tag: A["_tag"]): <I>(self: Schema.Schema<I, A>) => SchemaC<I, Data.Data<A>, Omit<A, "_tag">>; | ||
}>(tag: A["_tag"]): <I>(self: Schema.Schema<never, 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"]): SchemaC<I, Data.Data<A>, Omit<A, "_tag">>; | ||
}>(self: Schema.Schema<never, I, A>, tag: A["_tag"]): SchemaC<I, Data.Data<A>, Omit<A, "_tag">>; | ||
}; | ||
@@ -62,0 +62,0 @@ /** |
import * as Effect from "effect/Effect"; | ||
import * as Either from "effect/Either"; | ||
import { pipe } from "effect/Function"; | ||
@@ -10,10 +9,7 @@ import { RpcError } from "../Error.js"; | ||
const unsafeDecode = schemas => { | ||
const map = schemaInternal.methodClientCodecsEither(schemas); | ||
const map = schemaInternal.methodClientCodecs(schemas); | ||
return (method, output) => { | ||
const codec = map[method].output; | ||
const result = codec ? codec(output) : Either.right(void 0); | ||
if (result._tag !== "Left") { | ||
return result.right; | ||
} | ||
throw "unsafeDecode fail"; | ||
const result = codec ? codec(output) : Effect.succeed(void 0); | ||
return Effect.runSync(result); | ||
}; | ||
@@ -20,0 +16,0 @@ }; |
import * as Schema from "@effect/schema/Schema"; | ||
import * as Effect from "effect/Effect"; | ||
import * as Either from "effect/Either"; | ||
import { RpcDecodeFailure, RpcEncodeFailure } from "../Error.js"; | ||
/** @internal */ | ||
export const decodeEither = schema => { | ||
const decode = Schema.parseEither(schema); | ||
return input => Either.mapLeft(decode(input, { | ||
errors: "all" | ||
}), error => RpcDecodeFailure({ | ||
error: error.error | ||
})); | ||
}; | ||
/** @internal */ | ||
export const decode = schema => { | ||
const decode = Schema.parse(schema); | ||
const decode = Schema.decodeUnknown(schema); | ||
return input => Effect.mapError(decode(input, { | ||
@@ -32,11 +22,2 @@ errors: "all" | ||
}; | ||
/** @internal */ | ||
export const encodeEither = schema => { | ||
const encode = Schema.encodeEither(schema); | ||
return input => Either.mapLeft(encode(input, { | ||
errors: "all" | ||
}), error => RpcEncodeFailure({ | ||
error: error.error | ||
})); | ||
}; | ||
//# sourceMappingURL=codec.js.map |
@@ -52,8 +52,2 @@ import * as AST from "@effect/schema/AST"; | ||
/** @internal */ | ||
export const methodClientCodecsEither = /*#__PURE__*/methodSchemaTransform(schema => ({ | ||
input: schema.input ? Codec.encodeEither(schema.input) : undefined, | ||
output: schema.output ? Codec.decodeEither(schema.output) : undefined, | ||
error: Codec.decodeEither(schema.error) | ||
})); | ||
/** @internal */ | ||
export const rawClientCodecs = (schemas, prefix = "") => Object.entries(schemas).reduce((acc, [method, schema]) => { | ||
@@ -60,0 +54,0 @@ if (RpcServiceId in schema) { |
{ | ||
"name": "@effect/rpc", | ||
"version": "0.26.10", | ||
"version": "0.26.11", | ||
"description": "Functional programming in TypeScript", | ||
@@ -12,4 +12,4 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"@effect/schema": "^0.60.7", | ||
"effect": "^2.2.0" | ||
"@effect/schema": "^0.61.0", | ||
"effect": "^2.2.1" | ||
}, | ||
@@ -16,0 +16,0 @@ "main": "./dist/cjs/index.js", |
@@ -17,15 +17,21 @@ /** | ||
export type Rpc<C extends RpcSchema.Any, R, SE> = C extends RpcSchema.IO< | ||
infer RE, | ||
infer _IE, | ||
infer E, | ||
infer RI, | ||
infer _II, | ||
infer I, | ||
infer RO, | ||
infer _IO, | ||
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.NoOutput<infer _IE, infer E, infer _II, infer I> | ||
? (input: I) => Effect<R, RpcError | SE | E, void> | ||
: C extends RpcSchema.NoErrorNoOutput<infer _II, infer I> ? (input: I) => Effect<R, RpcError | SE, void> | ||
: 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 | RE | RI | RO, RpcError | SE | E, O> | ||
: C extends RpcSchema.NoError<infer RI, infer _II, infer I, infer RO, infer _IO, infer O> ? | ||
(input: I) => Effect<R | RI | RO, RpcError | SE, O> | ||
: C extends RpcSchema.NoOutput<infer RE, infer _IE, infer E, infer RI, infer _II, infer I> | ||
? (input: I) => Effect<R | RE | RI, RpcError | SE | E, void> | ||
: C extends RpcSchema.NoErrorNoOutput<infer RI, infer _II, infer I> ? | ||
(input: I) => Effect<R | RI, RpcError | SE, void> | ||
: C extends RpcSchema.NoInput<infer RE, infer _IE, infer E, infer RO, infer _IO, infer O> ? | ||
Effect<R | RE | RO, RpcError | SE | E, O> | ||
: C extends RpcSchema.NoInputNoError<infer RO, infer _IO, infer O> ? Effect<R | RO, RpcError | SE, O> | ||
: never | ||
@@ -32,0 +38,0 @@ |
import type * as Schema from "@effect/schema/Schema" | ||
import * as Effect from "effect/Effect" | ||
import * as Either from "effect/Either" | ||
import { pipe } from "effect/Function" | ||
@@ -15,12 +14,8 @@ import type * as client from "../Client.js" | ||
const unsafeDecode = <const S extends RpcService.DefinitionWithId>(schemas: S) => { | ||
const map = schemaInternal.methodClientCodecsEither(schemas) | ||
const map = schemaInternal.methodClientCodecs(schemas) | ||
return (method: RpcService.Methods<S>, output: unknown) => { | ||
const codec = map[method as string].output | ||
const result = codec ? codec(output) : Either.right(void 0) | ||
if (result._tag !== "Left") { | ||
return result.right as unknown | ||
} | ||
throw "unsafeDecode fail" | ||
const result = codec ? codec(output) : Effect.succeed(void 0) | ||
return Effect.runSync(result as any) | ||
} | ||
@@ -33,3 +28,3 @@ } | ||
options: client.RpcClientOptions, | ||
serviceErrors: ReadonlyArray<Schema.Schema<any>> = [], | ||
serviceErrors: ReadonlyArray<Schema.Schema<any, any>> = [], | ||
prefix = "" | ||
@@ -39,3 +34,3 @@ ): client.RpcClient<S, never> => { | ||
...serviceErrors, | ||
schemas[RpcServiceErrorId] as Schema.Schema<any> | ||
schemas[RpcServiceErrorId] as Schema.Schema<any, any> | ||
] | ||
@@ -118,3 +113,3 @@ | ||
resolver: RpcResolver<never>, | ||
serviceErrors: ReadonlyArray<Schema.Schema<any>>, | ||
serviceErrors: ReadonlyArray<Schema.Schema<any, any>>, | ||
schema: S, | ||
@@ -133,3 +128,3 @@ method: string, | ||
if ("input" in schema) { | ||
const encodeInput = codec.encode(schema.input as Schema.Schema<any>) | ||
const encodeInput = codec.encode(schema.input as Schema.Schema<any, any>) | ||
@@ -136,0 +131,0 @@ return ((input: any) => { |
import type { ParseOptions } from "@effect/schema/AST" | ||
import * as Schema from "@effect/schema/Schema" | ||
import * as Effect from "effect/Effect" | ||
import * as Either from "effect/Either" | ||
import { RpcDecodeFailure, RpcEncodeFailure } from "../Error.js" | ||
/** @internal */ | ||
export const decodeEither = <I, A>(schema: Schema.Schema<I, A>) => { | ||
const decode = Schema.parseEither(schema) | ||
return (input: unknown): Either.Either<RpcDecodeFailure, A> => | ||
Either.mapLeft(decode(input, { errors: "all" }), (error) => RpcDecodeFailure({ error: error.error })) | ||
} | ||
/** @internal */ | ||
export const decode = <I, A>(schema: Schema.Schema<I, A>) => { | ||
const decode = Schema.parse(schema) | ||
return (input: unknown): Effect.Effect<never, RpcDecodeFailure, A> => | ||
export const decode = <R, I, A>(schema: Schema.Schema<R, I, A>) => { | ||
const decode = Schema.decodeUnknown(schema) | ||
return (input: unknown): Effect.Effect<R, RpcDecodeFailure, A> => | ||
Effect.mapError(decode(input, { errors: "all" }), (error) => RpcDecodeFailure({ error: error.error })) | ||
@@ -22,6 +14,6 @@ } | ||
/** @internal */ | ||
export const encode: <I, A>( | ||
schema: Schema.Schema<I, A> | ||
) => (input: A, options?: ParseOptions | undefined) => Effect.Effect<never, RpcEncodeFailure, I> = <I, A>( | ||
schema: Schema.Schema<I, A> | ||
export const encode: <R, I, A>( | ||
schema: Schema.Schema<R, I, A> | ||
) => (input: A, options?: ParseOptions | undefined) => Effect.Effect<R, RpcEncodeFailure, I> = <R, I, A>( | ||
schema: Schema.Schema<R, I, A> | ||
) => { | ||
@@ -32,12 +24,1 @@ const encode = Schema.encode(schema) | ||
} | ||
/** @internal */ | ||
export const encodeEither: <I, A>( | ||
schema: Schema.Schema<I, A> | ||
) => (input: A, options?: ParseOptions | undefined) => Either.Either<RpcEncodeFailure, I> = <I, A>( | ||
schema: Schema.Schema<I, A> | ||
) => { | ||
const encode = Schema.encodeEither(schema) | ||
return (input: A) => | ||
Either.mapLeft(encode(input, { errors: "all" }), (error) => RpcEncodeFailure({ error: error.error })) | ||
} |
@@ -47,3 +47,3 @@ import * as Schema from "@effect/schema/Schema" | ||
const RpcResponse: Schema.Schema<resolver.RpcResponse> = Schema.union( | ||
const RpcResponse: Schema.Schema<never, resolver.RpcResponse> = Schema.union( | ||
Schema.struct({ | ||
@@ -55,3 +55,3 @@ _tag: Schema.literal("Success"), | ||
_tag: Schema.literal("Error"), | ||
error: Schema.unknown as Schema.Schema<RpcError> | ||
error: Schema.unknown as Schema.Schema<never, RpcError> | ||
}) | ||
@@ -58,0 +58,0 @@ ) |
@@ -27,4 +27,4 @@ import * as AST from "@effect/schema/AST" | ||
export const schemasToUnion = ( | ||
schemas: ReadonlyArray<Schema.Schema<any>> | ||
): Schema.Schema<any> => { | ||
schemas: ReadonlyArray<Schema.Schema<any, any>> | ||
): Schema.Schema<any, any> => { | ||
schemas = schemas.filter((s) => s !== (Schema.never as any)) | ||
@@ -42,5 +42,5 @@ | ||
f: (schema: { | ||
input?: Schema.Schema<any> | undefined | ||
output?: Schema.Schema<any> | undefined | ||
error: Schema.Schema<any> | ||
input?: Schema.Schema<any, any> | undefined | ||
output?: Schema.Schema<any, any> | undefined | ||
error: Schema.Schema<any, any> | ||
}) => A | ||
@@ -50,3 +50,3 @@ ) => | ||
schemas: S, | ||
serviceErrors: ReadonlyArray<Schema.Schema<any>> = [], | ||
serviceErrors: ReadonlyArray<Schema.Schema<any, any>> = [], | ||
prefix = "" | ||
@@ -56,3 +56,3 @@ ): Record<string, A> => { | ||
...serviceErrors, | ||
schemas[RpcServiceErrorId] as Schema.Schema<any> | ||
schemas[RpcServiceErrorId] as Schema.Schema<any, any> | ||
] | ||
@@ -105,9 +105,2 @@ | ||
/** @internal */ | ||
export const methodClientCodecsEither = methodSchemaTransform((schema) => ({ | ||
input: schema.input ? Codec.encodeEither(schema.input) : undefined, | ||
output: schema.output ? Codec.decodeEither(schema.output) : undefined, | ||
error: Codec.decodeEither(schema.error) | ||
})) | ||
/** @internal */ | ||
export const rawClientCodecs = <S extends schema.RpcService.DefinitionWithId>( | ||
@@ -144,4 +137,4 @@ schemas: S, | ||
export const withServiceError: { | ||
<EI extends Json, E>( | ||
error: Schema.Schema<EI, E> | ||
<R, EI extends Json, E>( | ||
error: Schema.Schema<R, EI, E> | ||
): <S extends schema.RpcService.DefinitionWithId>( | ||
@@ -151,10 +144,12 @@ self: S | ||
S, | ||
schema.RpcService.Context<S> | R, | ||
schema.RpcService.ErrorsFrom<S> | EI, | ||
schema.RpcService.Errors<S> | E | ||
> | ||
<S extends schema.RpcService.DefinitionWithId, EI extends Json, E>( | ||
<S extends schema.RpcService.DefinitionWithId, R, EI extends Json, E>( | ||
self: S, | ||
error: Schema.Schema<EI, E> | ||
error: Schema.Schema<R, EI, E> | ||
): schema.RpcService.WithId< | ||
S, | ||
schema.RpcService.Context<S> | R, | ||
schema.RpcService.ErrorsFrom<S> | EI, | ||
@@ -165,7 +160,8 @@ schema.RpcService.Errors<S> | E | ||
2, | ||
<S extends schema.RpcService.DefinitionWithId, EI extends Json, E>( | ||
<S extends schema.RpcService.DefinitionWithId, R, EI extends Json, E>( | ||
self: S, | ||
error: Schema.Schema<EI, E> | ||
error: Schema.Schema<R, EI, E> | ||
): schema.RpcService.WithId< | ||
S, | ||
schema.RpcService.Context<S> | R, | ||
schema.RpcService.ErrorsFrom<S> | EI, | ||
@@ -189,10 +185,10 @@ schema.RpcService.Errors<S> | E | ||
export const withHash: { | ||
<A>(f: (a: A) => number): <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A> | ||
<I, A>( | ||
self: Schema.Schema<I, A>, | ||
<A>(f: (a: A) => number): <I, R>(self: Schema.Schema<R, I, A>) => Schema.Schema<R, I, A> | ||
<R, I, A>( | ||
self: Schema.Schema<R, I, A>, | ||
f: (a: A) => number | ||
): Schema.Schema<I, A> | ||
): Schema.Schema<R, I, A> | ||
} = dual( | ||
2, | ||
<I, A>(self: Schema.Schema<I, A>, f: (a: A) => number) => Schema.annotations({ [HashAnnotationId]: f })(self) | ||
<R, I, A>(self: Schema.Schema<R, I, A>, f: (a: A) => number) => Schema.annotations({ [HashAnnotationId]: f })(self) | ||
) | ||
@@ -202,15 +198,15 @@ | ||
export const withHashString: { | ||
<A>(f: (a: A) => string): <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A> | ||
<I, A>( | ||
self: Schema.Schema<I, A>, | ||
<A>(f: (a: A) => string): <R, I>(self: Schema.Schema<R, I, A>) => Schema.Schema<R, I, A> | ||
<R, I, A>( | ||
self: Schema.Schema<R, I, A>, | ||
f: (a: A) => string | ||
): Schema.Schema<I, A> | ||
): Schema.Schema<R, I, A> | ||
} = dual( | ||
2, | ||
<I, A>(self: Schema.Schema<I, A>, f: (a: A) => string) => withHash(self, (_) => Hash.string(f(_))) | ||
<R, I, A>(self: Schema.Schema<R, I, A>, f: (a: A) => string) => withHash(self, (_) => Hash.string(f(_))) | ||
) | ||
/** @internal */ | ||
export const hash = <I, A>( | ||
self: Schema.Schema<I, A>, | ||
export const hash = <R, I, A>( | ||
self: Schema.Schema<R, I, A>, | ||
value: A | ||
@@ -217,0 +213,0 @@ ): number => |
@@ -54,14 +54,17 @@ /** | ||
export type FromSchema<C extends RpcSchema.Any> = C extends RpcSchema.IO< | ||
infer _RE, | ||
infer _IE, | ||
infer E, | ||
infer _RI, | ||
infer _II, | ||
infer I, | ||
infer _RO, | ||
infer _IO, | ||
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> | ||
: C extends RpcSchema.NoOutput<infer _IE, infer E, infer _II, infer I> ? IO<any, E, I, void> | ||
: C extends RpcSchema.NoErrorNoOutput<infer _II, infer I> ? IO<any, never, I, void> | ||
: C extends RpcSchema.NoError<infer _RI, infer _II, infer I, infer _RO, infer _IO, infer O> ? IO<any, never, I, O> | ||
: C extends RpcSchema.NoInput<infer _RE, infer _IE, infer E, infer _RO, infer _IO, infer O> ? NoInput<any, E, O> | ||
: C extends RpcSchema.NoInputNoError<infer _RO, infer _IO, infer O> ? NoInput<any, never, O> | ||
: C extends RpcSchema.NoOutput<infer _RE, infer _IE, infer E, infer _RI, infer _II, infer I> ? IO<any, E, I, void> | ||
: C extends RpcSchema.NoErrorNoOutput<infer _RI, infer _II, infer I> ? IO<any, never, I, void> | ||
: never | ||
@@ -74,8 +77,10 @@ | ||
export type FromSetupSchema<C> = C extends RpcSchema.NoOutput< | ||
infer _RE, | ||
infer _IE, | ||
infer E, | ||
infer _RI, | ||
infer _II, | ||
infer I | ||
> ? IO<any, E, I, Context<any>> | IOLayer<any, E, I, any> | ||
: C extends RpcSchema.NoErrorNoOutput<infer _II, infer I> | ||
: C extends RpcSchema.NoErrorNoOutput<infer _RI, infer _II, infer I> | ||
? IO<any, never, I, Context<any>> | IOLayer<any, never, I, any> | ||
@@ -280,4 +285,4 @@ : never | ||
export type Services<R extends Base> = R extends WithSetup | ||
? Exclude<RpcHandlers.Services<R["handlers"]>, SetupServices<R>> | ||
: RpcHandlers.Services<R["handlers"]> | ||
? Exclude<RpcHandlers.Services<R["handlers"]> | RpcSchema.Context<R["schema"]>, SetupServices<R>> | ||
: RpcHandlers.Services<R["handlers"]> | RpcSchema.Context<R["schema"]> | ||
@@ -284,0 +289,0 @@ /** |
@@ -17,6 +17,6 @@ /** | ||
*/ | ||
export interface IO<IE, E, II, I, IO, O> { | ||
readonly input: Schema.Schema<II, I> | ||
readonly output: Schema.Schema<IO, O> | ||
readonly error: Schema.Schema<IE, E> | ||
export interface IO<RE, IE, E, RI, II, I, RO, IO, O> { | ||
readonly input: Schema.Schema<RI, II, I> | ||
readonly output: Schema.Schema<RO, IO, O> | ||
readonly error: Schema.Schema<RE, IE, E> | ||
} | ||
@@ -28,5 +28,5 @@ | ||
*/ | ||
export interface NoError<II, I, IO, O> { | ||
readonly input: Schema.Schema<II, I> | ||
readonly output: Schema.Schema<IO, O> | ||
export interface NoError<RI, II, I, RO, IO, O> { | ||
readonly input: Schema.Schema<RI, II, I> | ||
readonly output: Schema.Schema<RO, IO, O> | ||
} | ||
@@ -38,5 +38,5 @@ | ||
*/ | ||
export interface NoInput<IE, E, IO, O> { | ||
readonly output: Schema.Schema<IO, O> | ||
readonly error: Schema.Schema<IE, E> | ||
export interface NoInput<RE, IE, E, RO, IO, O> { | ||
readonly output: Schema.Schema<RO, IO, O> | ||
readonly error: Schema.Schema<RE, IE, E> | ||
} | ||
@@ -48,4 +48,4 @@ | ||
*/ | ||
export interface NoInputNoError<IO, O> { | ||
readonly output: Schema.Schema<IO, O> | ||
export interface NoInputNoError<RO, IO, O> { | ||
readonly output: Schema.Schema<RO, IO, O> | ||
} | ||
@@ -57,5 +57,5 @@ | ||
*/ | ||
export interface NoOutput<IE, E, II, I> { | ||
readonly input: Schema.Schema<II, I> | ||
readonly error: Schema.Schema<IE, E> | ||
export interface NoOutput<RE, IE, E, RI, II, I> { | ||
readonly input: Schema.Schema<RI, II, I> | ||
readonly error: Schema.Schema<RE, IE, E> | ||
} | ||
@@ -67,4 +67,4 @@ | ||
*/ | ||
export interface NoErrorNoOutput<II, I> { | ||
readonly input: Schema.Schema<II, I> | ||
export interface NoErrorNoOutput<RI, II, I> { | ||
readonly input: Schema.Schema<RI, II, I> | ||
} | ||
@@ -77,8 +77,8 @@ | ||
export type Any = | ||
| IO<any, any, any, any, any, any> | ||
| NoError<any, any, any, any> | ||
| NoInput<any, any, any, any> | ||
| NoInputNoError<any, any> | ||
| NoOutput<any, any, any, any> | ||
| NoErrorNoOutput<any, any> | ||
| IO<any, any, any, any, any, any, any, any, any> | ||
| NoError<any, any, any, any, any, any> | ||
| NoInput<any, any, any, any, any, any> | ||
| NoInputNoError<any, any, any> | ||
| NoOutput<any, any, any, any, any, any> | ||
| NoErrorNoOutput<any, any, any> | ||
@@ -90,5 +90,5 @@ /** | ||
export interface Base { | ||
readonly input?: Schema.Schema<any> | ||
readonly output?: Schema.Schema<any> | ||
readonly error: Schema.Schema<any> | ||
readonly input?: Schema.Schema<any, any> | ||
readonly output?: Schema.Schema<any, any> | ||
readonly error: Schema.Schema<any, any> | ||
} | ||
@@ -101,3 +101,3 @@ | ||
export type Input<S> = S extends { | ||
readonly input: Schema.Schema<infer _I, infer A> | ||
readonly input: Schema.Schema<infer _R, infer _I, infer A> | ||
} ? A | ||
@@ -111,3 +111,3 @@ : never | ||
export type Error<S> = S extends { | ||
readonly error: Schema.Schema<infer _I, infer A> | ||
readonly error: Schema.Schema<infer _R, infer _I, infer A> | ||
} ? A | ||
@@ -120,6 +120,12 @@ : never | ||
*/ | ||
export type Output<S> = S extends { | ||
readonly output: Schema.Schema<infer _I, infer A> | ||
} ? A | ||
: never | ||
export type Output<S> = S extends { readonly output: Schema.Schema<infer _R, infer _I, infer A> } ? A : never | ||
/** | ||
* @category utils | ||
* @since 1.0.0 | ||
*/ | ||
export type Context<S> = | ||
| (S extends { readonly output: Schema.Schema<infer R, infer _I, infer _A> } ? R : never) | ||
| (S extends { readonly input: Schema.Schema<infer R, infer _I, infer _A> } ? R : never) | ||
| (S extends { readonly error: Schema.Schema<infer R, infer _I, infer _A> } ? R : never) | ||
} | ||
@@ -166,4 +172,4 @@ | ||
readonly [RpcServiceErrorId]: | ||
| Schema.Schema<any, any> | ||
| Schema.Schema<never, never> | ||
| Schema.Schema<any, any, any> | ||
| Schema.Schema<any, never, never> | ||
} | ||
@@ -183,5 +189,5 @@ | ||
*/ | ||
export type WithId<S, EI, E> = S & { | ||
export type WithId<S, R, EI, E> = S & { | ||
readonly [RpcServiceId]: RpcServiceId | ||
readonly [RpcServiceErrorId]: Schema.Schema<EI, E> | ||
readonly [RpcServiceErrorId]: Schema.Schema<R, EI, E> | ||
} | ||
@@ -209,2 +215,10 @@ | ||
*/ | ||
export type Context<S extends DefinitionWithId> = Schema.Schema.Context< | ||
S[RpcServiceErrorId] | ||
> | ||
/** | ||
* @category utils | ||
* @since 1.0.0 | ||
*/ | ||
export type SetupInput<S extends DefinitionWithSetup> = RpcSchema.Input< | ||
@@ -250,6 +264,9 @@ S["__setup"] | ||
: S[K] extends RpcSchema.IO< | ||
infer _RE, | ||
infer IE, | ||
infer _E, | ||
infer _RI, | ||
infer II, | ||
infer _I, | ||
infer _RO, | ||
infer IO, | ||
@@ -259,7 +276,9 @@ infer _O | ||
: `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 _RI, infer II, infer _I, infer _RO, 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 _RE, infer IE, infer _E, infer _RO, 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 _RO, infer IO, infer _O> ? [IO] extends [V] ? S[K] | ||
: `schema input does not extend ${VL}` | ||
@@ -275,2 +294,3 @@ : S[K] | ||
T, | ||
R, | ||
EI, | ||
@@ -280,2 +300,3 @@ E | ||
{ readonly [K in Exclude<keyof S, RpcServiceId>]: S[K] }, | ||
R, | ||
EI, | ||
@@ -294,3 +315,3 @@ E | ||
schema: S | ||
): RpcService.Simplify<RpcService.Validate<VL, V, S>, never, never> => ({ | ||
): RpcService.Simplify<RpcService.Validate<VL, V, S>, never, never, never> => ({ | ||
...(schema as any), | ||
@@ -316,4 +337,4 @@ [RpcServiceId]: RpcServiceId, | ||
export const withServiceError: { | ||
<EI extends Json, E>( | ||
error: Schema.Schema<EI, E> | ||
<R, EI extends internal.Json, E>( | ||
error: Schema.Schema<R, EI, E> | ||
): <S extends RpcService.DefinitionWithId>( | ||
@@ -323,12 +344,14 @@ self: S | ||
S, | ||
EI | RpcService.ErrorsFrom<S>, | ||
E | RpcService.Errors<S> | ||
R | Schema.Schema.Context<S[typeof RpcServiceErrorId]>, | ||
EI | Schema.Schema.From<S[typeof RpcServiceErrorId]>, | ||
E | Schema.Schema.To<S[typeof RpcServiceErrorId]> | ||
> | ||
<S extends RpcService.DefinitionWithId, EI extends Json, E>( | ||
<S extends RpcService.DefinitionWithId, R, EI extends internal.Json, E>( | ||
self: S, | ||
error: Schema.Schema<EI, E> | ||
error: Schema.Schema<R, EI, E> | ||
): RpcService.WithId< | ||
S, | ||
EI | RpcService.ErrorsFrom<S>, | ||
E | RpcService.Errors<S> | ||
R | Schema.Schema.Context<S[typeof RpcServiceErrorId]>, | ||
EI | Schema.Schema.From<S[typeof RpcServiceErrorId]>, | ||
E | Schema.Schema.To<S[typeof RpcServiceErrorId]> | ||
> | ||
@@ -345,2 +368,44 @@ } = internal.withServiceError | ||
*/ | ||
export type Context< | ||
S extends RpcService.Definition, | ||
Depth extends ReadonlyArray<number> = [] | ||
> = Extract<keyof S, string> extends infer K | ||
? K extends Extract<keyof S, string> ? | ||
S[K] extends RpcService.DefinitionWithId ? Depth["length"] extends 3 ? never : Context<S[K], [0, ...Depth]> | ||
: S[K] extends RpcSchema.IO< | ||
infer RE, | ||
infer _IE, | ||
infer _E, | ||
infer RI, | ||
infer _II, | ||
infer _I, | ||
infer RO, | ||
infer _IO, | ||
infer _O | ||
> ? RE | RI | RO | ||
: S[K] extends RpcSchema.NoError< | ||
infer RI, | ||
infer _II, | ||
infer _I, | ||
infer RO, | ||
infer _IO, | ||
infer _O | ||
> ? RI | RO | ||
: S[K] extends RpcSchema.NoInput< | ||
infer RI, | ||
infer _IE, | ||
infer _E, | ||
infer RO, | ||
infer _IO, | ||
infer _O | ||
> ? RI | RO | ||
: S[K] extends RpcSchema.NoInputNoError<infer RO, infer _IO, infer _O> ? RO | ||
: never | ||
: never | ||
: never | ||
/** | ||
* @category utils | ||
* @since 1.0.0 | ||
*/ | ||
export type From< | ||
@@ -355,6 +420,9 @@ S extends RpcService.Definition, | ||
: S[K] extends RpcSchema.IO< | ||
infer _RE, | ||
infer _IE, | ||
infer _E, | ||
infer _RI, | ||
infer II, | ||
infer _I, | ||
infer _RO, | ||
infer _IO, | ||
@@ -364,4 +432,6 @@ infer _O | ||
: S[K] extends RpcSchema.NoError< | ||
infer _RI, | ||
infer II, | ||
infer _I, | ||
infer _RO, | ||
infer _IO, | ||
@@ -371,8 +441,10 @@ infer _O | ||
: S[K] extends RpcSchema.NoInput< | ||
infer _RI, | ||
infer _IE, | ||
infer _E, | ||
infer _RO, | ||
infer _IO, | ||
infer _O | ||
> ? { readonly _tag: `${P}${K}` } | ||
: S[K] extends RpcSchema.NoInputNoError<infer _IO, infer _O> ? { readonly _tag: `${P}${K}` } | ||
: S[K] extends RpcSchema.NoInputNoError<infer _RO, infer _IO, infer _O> ? { readonly _tag: `${P}${K}` } | ||
: never | ||
@@ -395,6 +467,9 @@ : never | ||
: S[K] extends RpcSchema.IO< | ||
infer _RE, | ||
infer _IE, | ||
infer _E, | ||
infer _RI, | ||
infer _II, | ||
infer I, | ||
infer _RO, | ||
infer _IO, | ||
@@ -404,4 +479,6 @@ infer _O | ||
: S[K] extends RpcSchema.NoError< | ||
infer _RI, | ||
infer _II, | ||
infer I, | ||
infer _RO, | ||
infer _IO, | ||
@@ -411,8 +488,10 @@ infer _O | ||
: S[K] extends RpcSchema.NoInput< | ||
infer _RE, | ||
infer _IE, | ||
infer _E, | ||
infer _RO, | ||
infer _IO, | ||
infer _O | ||
> ? RpcRequest.NoInput<`${P}${K}`> | ||
: S[K] extends RpcSchema.NoInputNoError<infer _IO, infer _O> ? RpcRequest.NoInput<`${P}${K}`> | ||
: S[K] extends RpcSchema.NoInputNoError<infer _RO, infer _IO, infer _O> ? RpcRequest.NoInput<`${P}${K}`> | ||
: never | ||
@@ -427,6 +506,3 @@ : never | ||
export type Schema<S extends RpcService.Definition> = | ||
& Schema.Schema< | ||
From<S>, | ||
To<S> | ||
> | ||
& Schema.Schema<Context<S>, From<S>, To<S>> | ||
& {} | ||
@@ -444,7 +520,7 @@ } | ||
...Object.entries(schema).map( | ||
([tag, schema]): Schema.Schema<any, any> => | ||
([tag, schema]): Schema.Schema<any, any, any> => | ||
"input" in schema | ||
? Schema.struct({ | ||
_tag: Schema.literal(tag), | ||
input: schema.input as Schema.Schema<any, any> | ||
input: schema.input as Schema.Schema<any, any, any> | ||
}) | ||
@@ -472,4 +548,4 @@ : Schema.struct({ _tag: Schema.literal(tag) }) | ||
export const withHash: { | ||
<A>(f: (a: A) => number): <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A> | ||
<I, A>(self: Schema.Schema<I, A>, f: (a: A) => number): Schema.Schema<I, A> | ||
<A>(f: (a: A) => number): <I, R>(self: Schema.Schema<R, I, A>) => Schema.Schema<R, I, A> | ||
<R, I, A>(self: Schema.Schema<R, I, A>, f: (a: A) => number): Schema.Schema<R, I, A> | ||
} = internal.withHash | ||
@@ -482,4 +558,4 @@ | ||
export const withHashString: { | ||
<A>(f: (a: A) => string): <I>(self: Schema.Schema<I, A>) => Schema.Schema<I, A> | ||
<I, A>(self: Schema.Schema<I, A>, f: (a: A) => string): Schema.Schema<I, A> | ||
<A>(f: (a: A) => string): <R, I>(self: Schema.Schema<R, I, A>) => Schema.Schema<R, I, A> | ||
<R, I, A>(self: Schema.Schema<R, I, A>, f: (a: A) => string): Schema.Schema<R, I, A> | ||
} = internal.withHashString | ||
@@ -491,2 +567,2 @@ | ||
*/ | ||
export const hash: <I, A>(self: Schema.Schema<I, A>, value: A) => number = internal.hash | ||
export const hash: <R, I, A>(self: Schema.Schema<R, I, A>, value: A) => number = internal.hash |
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
export interface SchemaC<I, A, C> extends Schema.Schema<I, A> { | ||
export interface SchemaC<I, A, C> extends Schema.Schema<never, I, A> { | ||
(input: C): A | ||
@@ -29,8 +29,8 @@ readonly either: (input: C) => Either<ParseError, A> | ||
export const withConstructor: { | ||
<A, C>(f: (input: C) => A): <I>(self: Schema.Schema<I, A>) => SchemaC<I, A, C> | ||
<I, A, C>(self: Schema.Schema<I, A>, f: (input: C) => A): SchemaC<I, A, C> | ||
<A, C>(f: (input: C) => A): <I>(self: Schema.Schema<never, I, A>) => SchemaC<I, A, C> | ||
<I, A, C>(self: Schema.Schema<never, I, A>, f: (input: C) => A): SchemaC<I, A, C> | ||
} = dual( | ||
2, | ||
<I, A, C>( | ||
self: Schema.Schema<I, A>, | ||
self: Schema.Schema<never, I, A>, | ||
f: (input: C) => A | ||
@@ -66,3 +66,3 @@ ): SchemaC<I, A, C> => { | ||
export const withConstructorSelf = <I, A>( | ||
self: Schema.Schema<I, A> | ||
self: Schema.Schema<never, I, A> | ||
): SchemaC<I, A, A> => withConstructor(self, identity) | ||
@@ -77,6 +77,6 @@ | ||
tag: A["_tag"] | ||
): <I>(self: Schema.Schema<I, A>) => SchemaC<I, A, Omit<A, "_tag">> | ||
): <I>(self: Schema.Schema<never, I, A>) => SchemaC<I, A, Omit<A, "_tag">> | ||
<I, A extends { readonly _tag: string }>( | ||
self: Schema.Schema<I, A>, | ||
self: Schema.Schema<never, I, A>, | ||
tag: A["_tag"] | ||
@@ -87,3 +87,3 @@ ): SchemaC<I, A, Omit<A, "_tag">> | ||
<I, A extends { readonly _tag: string }>( | ||
self: Schema.Schema<I, A>, | ||
self: Schema.Schema<never, I, A>, | ||
tag: A["_tag"] | ||
@@ -107,6 +107,6 @@ ): SchemaC<I, A, Omit<A, "_tag">> => | ||
tag: A["_tag"] | ||
): <I>(self: Schema.Schema<I, A>) => SchemaC<I, Data.Data<A>, Omit<A, "_tag">> | ||
): <I>(self: Schema.Schema<never, 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>, | ||
self: Schema.Schema<never, I, A>, | ||
tag: A["_tag"] | ||
@@ -117,3 +117,3 @@ ): SchemaC<I, Data.Data<A>, Omit<A, "_tag">> | ||
<I extends Record<string, any>, A extends { readonly _tag: string }>( | ||
self: Schema.Schema<I, A>, | ||
self: Schema.Schema<never, I, A>, | ||
tag: A["_tag"] | ||
@@ -120,0 +120,0 @@ ): SchemaC<I, Data.Data<A>, Omit<A, "_tag">> => withConstructor(Schema.data(self), Data.tagged(tag) as any) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
299373
5172