EntityProxy
Constructors
toHttpApiGroup
Added in v1.0.0
Source
Derives an HttpApiGroup from an Entity.
Signature
declare function toHttpApiGroup<Name extends string, Type extends string, Rpcs extends Any>(name: Name, entity: Entity<Type, Rpcs>): HttpApiGroup<Name, ConvertHttpApi<Rpcs>>Example
import { ClusterSchema, Entity, EntityProxy, EntityProxyServer } from "@effect/cluster"import { HttpApi, HttpApiBuilder } from "@effect/platform"import { Rpc } from "@effect/rpc"import { Layer, Schema } from "effect"
export const Counter = Entity.make("Counter", [ Rpc.make("Increment", { payload: { id: Schema.String, amount: Schema.Number }, primaryKey: ({ id }) => id, success: Schema.Number })]).annotateRpcs(ClusterSchema.Persisted, true)
// Use EntityProxy.toHttpApiGroup to create a `HttpApiGroup` from the// Counter entityexport class MyApi extends HttpApi.make("api") .add( EntityProxy.toHttpApiGroup("counter", Counter) .prefix("/counter") ){}
// Use EntityProxyServer.layerHttpApi to create a layer that implements// the handlers for the HttpApiGroupconst ApiLayer = HttpApiBuilder.api(MyApi).pipe( Layer.provide(EntityProxyServer.layerHttpApi(MyApi, "counter", Counter)))toRpcGroup
Added in v1.0.0
Source
Derives an RpcGroup from an Entity.
Signature
declare function toRpcGroup<Type extends string, Rpcs extends Any>(entity: Entity<Type, Rpcs>): RpcGroup<ConvertRpcs<Rpcs, Type>>Example
import { ClusterSchema, Entity, EntityProxy, EntityProxyServer } from "@effect/cluster"import { Rpc, RpcServer } from "@effect/rpc"import { Layer, Schema } from "effect"
export const Counter = Entity.make("Counter", [ Rpc.make("Increment", { payload: { id: Schema.String, amount: Schema.Number }, primaryKey: ({ id }) => id, success: Schema.Number })]).annotateRpcs(ClusterSchema.Persisted, true)
// Use EntityProxy.toRpcGroup to create a `RpcGroup` from the Counter entityexport class MyRpcs extends EntityProxy.toRpcGroup(Counter) {}
// Use EntityProxyServer.layerRpcHandlers to create a layer that implements// the rpc handlersconst RpcServerLayer = RpcServer.layer(MyRpcs).pipe( Layer.provide(EntityProxyServer.layerRpcHandlers(Counter)))Other
ConvertHttpApi type
Added in v1.0.0
Source
Signature
type ConvertHttpApi<Rpcs extends Rpc.Any> = Rpcs extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? HttpApiEndpoint.HttpApiEndpoint<_Tag, "POST", { readonly entityId: string;}, never, _Payload["Type"], never, _Success["Type"], _Error["Type"] | MailboxFull | AlreadyProcessingMessage | PersistenceError, _Payload["Context"] | _Success["Context"], _Error["Context"]> | HttpApiEndpoint.HttpApiEndpoint<`${_Tag}Discard`, "POST", { readonly entityId: string;}, never, _Payload["Type"], never, void, MailboxFull | AlreadyProcessingMessage | PersistenceError> : neverConvertRpcs type
Added in v1.0.0
Source
Signature
type ConvertRpcs<Rpcs extends Rpc.Any, Prefix extends string> = Rpcs extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer _Middleware> ? Rpc.Rpc<`${Prefix}.${_Tag}`, Schema.Struct<{ entityId: typeof Schema.String; payload: _Payload;}>, _Success, Schema.Schema<_Error["Type"] | MailboxFull | AlreadyProcessingMessage | PersistenceError | _Error["Encoded"] | typeof MailboxFull["Encoded"] | typeof AlreadyProcessingMessage["Encoded"] | typeof PersistenceError["Encoded"], _Error["Context"]>> | Rpc.Rpc<`${Prefix}.${_Tag}Discard`, Schema.Struct<{ entityId: typeof Schema.String; payload: _Payload;}>, typeof Schema.Void, Schema.Union<[typeof MailboxFull, typeof AlreadyProcessingMessage, typeof PersistenceError]>> : never