Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/hypergraph-react/src/HypergraphAppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SpaceEvents.SpaceState, SpaceEvents.ApplyError> =
await Effect.runPromiseExit(SpaceEvents.applyEvent({ state, event }));
if (Exit.isSuccess(applyEventResult)) {
state = applyEventResult.value;
} else {
console.log('Failed to apply event', applyEventResult);
}
}

Expand Down
7 changes: 2 additions & 5 deletions packages/hypergraph/src/space-events/apply-event.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -20,10 +20,7 @@ type Params = {

const decodeSpaceEvent = Schema.decodeUnknownEither(SpaceEvent);

export const applyEvent = ({
state,
event: rawEvent,
}: Params): Effect.Effect<SpaceState, ParseError | VerifySignatureError | InvalidEventError> => {
export const applyEvent = ({ state, event: rawEvent }: Params): Effect.Effect<SpaceState, ApplyError> => {
const decodedEvent = decodeSpaceEvent(rawEvent);
if (decodedEvent._tag === 'Left') {
return decodedEvent.left;
Expand Down
3 changes: 3 additions & 0 deletions packages/hypergraph/src/space-events/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ParseError } from 'effect/ParseResult';
import * as Schema from 'effect/Schema';
import { SignatureWithRecovery } from '../types.js';

Expand Down Expand Up @@ -101,3 +102,5 @@ export class VerifySignatureError {
export class InvalidEventError {
readonly _tag = 'InvalidEventError';
}

export type ApplyError = ParseError | VerifySignatureError | InvalidEventError;
Loading