@effect-weegigs/restate-core
v0.2.0
Published
SDK-free contract layer for @effect-weegigs/restate: Api definitions, Schema-codec serdes, and the typed-error envelope
Readme
@effect-weegigs/restate-core
The SDK-free contract layer shared by @effect-weegigs/restate (the server package) and @effect-weegigs/restate-client (the ingress client): Api contract definitions, the Schema-codec Serde, and the typed-error envelope.
You rarely install this package directly — both surface packages re-export its modules. It exists so the two can agree on contracts and wire conventions without sharing a dependency on the server SDK: restate-core depends only on effect and the types in @restatedev/restate-sdk-core, which keeps restate-client's dependency closure free of the server SDK and safe to bundle in any environment (Node services, browsers, edge runtimes).
Installation
pnpm add @effect-weegigs/restate-core effectnpm install @effect-weegigs/restate-core effecteffect is a peer dependency.
Modules
Api— definition-first contracts for Restate services, virtual objects, and workflows. A definition is pure contract — name, kind, and per-handler input/output/errorSchemas — from which the server builder, the in-handler client, and the ingress client all derive. A definition with no implementation is itself the typed client for a Restate service written in another language.import * as Api from "@effect-weegigs/restate-core/Api" import * as Schema from "effect/Schema" const UserApi = Api.service("UserService", { signup: Api.handler({ input: Schema.Struct({ email: Schema.String }), output: Schema.Struct({ welcomed: Schema.Boolean }), errors: [UserExists] }) })Serde— an Effect Schema codecSerdefor the Restate boundary that runs the full codec in BOTH directions (Schema.encodeSyncon serialize,Schema.decodeUnknownSyncon deserialize), so transformation schemas likeSchema.DateFromStringandSchema.OptionFromNullOrround-trip the wire correctly. Codec failures throw the SDK-freeSerdeError(400 for payloads that don't decode, 500 for values that don't encode);RawBytesmarks verbatim binary payloads for webhook-style handlers.Errors— the typed-error envelope: a declaredSchema.TaggedErrorcrosses the wire and the journal as{ _tag, ...fields }JSON in a status-422 terminal error message, anddecodeEnvelope/decodeDeclaredrehydrate the typed instance on the other side via the declared union.
The server package adapts Serde.SerdeError to the Restate SDK's
TerminalError at the boundary where serdes are handed to SDK machinery, and
supplies the encoding half of the error envelope — that half needs the SDK's
TerminalError class identity, which is exactly what this package avoids
depending on.
