principal.ts
This file
Path
packages/protocol/src/principal.ts
33 lines · 900 bytes · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake it
12345678910111213141516171819202122232425262728293031323334import { Context, Schema } from "effect";import { RpcMiddleware } from "effect/rpc";
import { Handle } from "./ids.ts";
export const Person = Schema.TaggedStruct("Person", { handle: Handle });
export type Person = typeof Person.Type;
export const Anonymous = Schema.TaggedStruct("Anonymous", {});
export type Anonymous = typeof Anonymous.Type;
export const Principal = Schema.Union([Person, Anonymous]).pipe( Schema.toTaggedUnion("_tag"));
export type Principal = typeof Principal.Type;
export class CurrentPrincipal extends Context.Service< CurrentPrincipal, Principal>()("protocol/CurrentPrincipal") {}
export class Unauthenticated extends Schema.TaggedError<Unauthenticated>()( "Unauthenticated", {}) {}
export class Authenticated extends RpcMiddleware.Service< Authenticated, { provides: CurrentPrincipal }>()("protocol/Authenticated", { error: Unauthenticated }) {}