diff --git a/packages/hypergraph-react/src/HypergraphAppContext.tsx b/packages/hypergraph-react/src/HypergraphAppContext.tsx index 428575be..58e5600f 100644 --- a/packages/hypergraph-react/src/HypergraphAppContext.tsx +++ b/packages/hypergraph-react/src/HypergraphAppContext.tsx @@ -354,9 +354,13 @@ export function HypergraphAppProvider({ let state: SpaceEvents.SpaceState | undefined = undefined; for (const event of response.events) { - const applyEventResult = await Effect.runPromiseExit(SpaceEvents.applyEvent({ state: undefined, event })); + // Not sure why but type inference doesn't work here + const applyEventResult: Exit.Exit = + await Effect.runPromiseExit(SpaceEvents.applyEvent({ state, event })); if (Exit.isSuccess(applyEventResult)) { state = applyEventResult.value; + } else { + console.log('Failed to apply event', applyEventResult); } } diff --git a/packages/hypergraph/src/space-events/apply-event.ts b/packages/hypergraph/src/space-events/apply-event.ts index b2085c1a..55e1bb46 100644 --- a/packages/hypergraph/src/space-events/apply-event.ts +++ b/packages/hypergraph/src/space-events/apply-event.ts @@ -1,10 +1,10 @@ import { secp256k1 } from '@noble/curves/secp256k1'; import { sha256 } from '@noble/hashes/sha256'; import { Effect, Schema } from 'effect'; -import type { ParseError } from 'effect/ParseResult'; import { canonicalize, stringToUint8Array } from '../utils/index.js'; import { hashEvent } from './hash-event.js'; import { + type ApplyError, InvalidEventError, SpaceEvent, type SpaceInvitation, @@ -20,10 +20,7 @@ type Params = { const decodeSpaceEvent = Schema.decodeUnknownEither(SpaceEvent); -export const applyEvent = ({ - state, - event: rawEvent, -}: Params): Effect.Effect => { +export const applyEvent = ({ state, event: rawEvent }: Params): Effect.Effect => { const decodedEvent = decodeSpaceEvent(rawEvent); if (decodedEvent._tag === 'Left') { return decodedEvent.left; diff --git a/packages/hypergraph/src/space-events/types.ts b/packages/hypergraph/src/space-events/types.ts index 3fe06568..5ff10126 100644 --- a/packages/hypergraph/src/space-events/types.ts +++ b/packages/hypergraph/src/space-events/types.ts @@ -1,3 +1,4 @@ +import type { ParseError } from 'effect/ParseResult'; import * as Schema from 'effect/Schema'; import { SignatureWithRecovery } from '../types.js'; @@ -101,3 +102,5 @@ export class VerifySignatureError { export class InvalidEventError { readonly _tag = 'InvalidEventError'; } + +export type ApplyError = ParseError | VerifySignatureError | InvalidEventError;