| /** | |
| * Middleware services for the unstable RPC runtime. | |
| * | |
| * A middleware service wraps server handler execution and can also install a | |
| * client-side wrapper for generated clients. Its metadata records the services | |
| * provided to downstream handlers, the services required by the middleware | |
| * implementation, the schema for server-visible failures, the client-only error | |
| * type, and whether generated clients must require the matching client layer. | |
| * | |
| * @since 4.0.0 | |
| */ | |
| import * as Context from "../../Context.js"; | |
| import * as Effect from "../../Effect.js"; | |
| import * as Layer from "../../Layer.js"; | |
| import * as Schema from "../../Schema.js"; | |
| import { Scope } from "../../Scope.js"; | |
| /** | |
| * The runtime type id used to attach and inspect RPC middleware metadata. | |
| * | |
| * @category type IDs | |
| * @since 4.0.0 | |
| */ | |
| export const TypeId = "~effect/rpc/RpcMiddleware"; | |
| /** | |
| * Creates a typed RPC middleware service class, with optional service | |
| * requirements, provided services, error schema, and client-side requirement | |
| * metadata. | |
| * | |
| * @category constructors | |
| * @since 4.0.0 | |
| */ | |
| export const Service = () => (id, options) => { | |
| const Err = globalThis.Error; | |
| const limit = Err.stackTraceLimit; | |
| Err.stackTraceLimit = 2; | |
| const creationError = new Err(); | |
| Err.stackTraceLimit = limit; | |
| function ServiceClass() {} | |
| const ServiceClass_ = ServiceClass; | |
| Object.setPrototypeOf(ServiceClass, Object.getPrototypeOf(Context.Service(id))); | |
| ServiceClass.key = id; | |
| Object.defineProperty(ServiceClass, "stack", { | |
| get() { | |
| return creationError.stack; | |
| } | |
| }); | |
| ServiceClass_[TypeId] = TypeId; | |
| ServiceClass_.error = options?.error ?? Schema.Never; | |
| ServiceClass_.requiredForClient = options?.requiredForClient ?? false; | |
| return ServiceClass; | |
| }; | |
| /** | |
| * Provides the client-side implementation for an RPC middleware service, | |
| * capturing the layer's environment and merging it into each middleware | |
| * invocation. | |
| * | |
| * @category client | |
| * @since 4.0.0 | |
| */ | |
| export const layerClient = (tag, service) => Layer.effectContext(Effect.gen(function* () { | |
| const services = (yield* Effect.context()).pipe(Context.omit(Scope)); | |
| const middleware = Effect.isEffect(service) ? yield* service : service; | |
| return Context.makeUnsafe(new Map([[`${tag.key}/Client`, options => Effect.updateContext(middleware(options), requestContext => Context.merge(services, requestContext))]])); | |
| })); | |
| //# sourceMappingURL=RpcMiddleware.js.map |
Xet Storage Details
- Size:
- 2.43 kB
- Xet hash:
- 2387a6eb75bdef71093287cf3146148269af2c085c7a015a9ea9b3548ff56732
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.