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
14 changes: 3 additions & 11 deletions apps/events/src/routes/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,10 @@ const App = ({
case 'space': {
let state: SpaceState | undefined = undefined;

// TODO fix typing
for (const event of response.events) {
if (state === undefined) {
const applyEventResult = await Effect.runPromiseExit(applyEvent({ event }));
if (Exit.isSuccess(applyEventResult)) {
state = applyEventResult.value;
}
} else {
const applyEventResult = await Effect.runPromiseExit(applyEvent({ event, state }));
if (Exit.isSuccess(applyEventResult)) {
state = applyEventResult.value;
}
const applyEventResult = await Effect.runPromiseExit(applyEvent({ state: undefined, event }));
if (Exit.isSuccess(applyEventResult)) {
state = applyEventResult.value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/handlers/createSpace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Params = {
};

export const createSpace = async ({ accountId, event, keyBox, keyId }: Params) => {
const result = await Effect.runPromiseExit(applyEvent({ event }));
const result = await Effect.runPromiseExit(applyEvent({ event, state: undefined }));
if (Exit.isFailure(result)) {
throw new Error('Invalid event');
}
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ webSocketServer.on('connection', async (webSocket: CustomWebSocket, request: Req
break;
}
case 'create-space-event': {
const applyEventResult = await Effect.runPromiseExit(applyEvent({ event: data.event }));
const applyEventResult = await Effect.runPromiseExit(applyEvent({ event: data.event, state: undefined }));
if (Exit.isSuccess(applyEventResult)) {
const space = await createSpace({ accountId, event: data.event, keyBox: data.keyBox, keyId: data.keyId });
const spaceWithEvents = await getSpace({ accountId, spaceId: space.id });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ it('should accept an invitation', async () => {
const { state3 } = await Effect.runPromise(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });
const spaceEvent2 = yield* createInvitation({
author,
previousEventHash: state.lastEventHash,
invitee,
});
const state2 = yield* applyEvent({ state, event: spaceEvent2 });
const state2 = yield* applyEvent({ event: spaceEvent2, state });
const spaceEvent3 = yield* acceptInvitation({
previousEventHash: state2.lastEventHash,
author: invitee,
});
const state3 = yield* applyEvent({ state: state2, event: spaceEvent3 });
const state3 = yield* applyEvent({ event: spaceEvent3, state: state2 });
return {
state3,
spaceEvent3,
Expand Down
12 changes: 6 additions & 6 deletions packages/graph-framework-space-events/src/apply-event.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ it('should fail in case of an invalid signature', async () => {

// @ts-expect-error
spaceEvent.author.signature = signature;
return yield* applyEvent({ event: spaceEvent });
return yield* applyEvent({ event: spaceEvent, state: undefined });
}),
);

Expand All @@ -46,10 +46,10 @@ it('should fail in case state is not provided for an event other than createSpac
const result = await Effect.runPromiseExit(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });

const spaceEvent2 = yield* createInvitation({ author, previousEventHash: state.lastEventHash, invitee });
return yield* applyEvent({ event: spaceEvent2 });
return yield* applyEvent({ event: spaceEvent2, state: undefined });
}),
);

Expand All @@ -66,13 +66,13 @@ it('should fail in case of an event is applied that is not based on the previous
const result = await Effect.runPromiseExit(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });

const spaceEvent2 = yield* createSpace({ author });
const state2 = yield* applyEvent({ state, event: spaceEvent2 });
const state2 = yield* applyEvent({ event: spaceEvent2, state });

const spaceEvent3 = yield* createInvitation({ author, previousEventHash: state.lastEventHash, invitee });
return yield* applyEvent({ state: state2, event: spaceEvent3 });
return yield* applyEvent({ event: spaceEvent3, state: state2 });
}),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/graph-framework-space-events/src/apply-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './types.js';

type Params = {
state?: SpaceState;
state: SpaceState | undefined;
event: SpaceEvent;
};

Expand Down
20 changes: 10 additions & 10 deletions packages/graph-framework-space-events/src/create-invitation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ it('should create an invitation', async () => {
const { spaceEvent2, state2 } = await Effect.runPromise(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });
const spaceEvent2 = yield* createInvitation({
author,
previousEventHash: state.lastEventHash,
invitee,
});
const state2 = yield* applyEvent({ state, event: spaceEvent2 });
const state2 = yield* applyEvent({ event: spaceEvent2, state });
return {
state2,
spaceEvent2,
Expand Down Expand Up @@ -65,13 +65,13 @@ it('should fail to invite the account twice', async () => {
const result = await Effect.runPromiseExit(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });
const spaceEvent2 = yield* createInvitation({
author,
previousEventHash: state.lastEventHash,
invitee,
});
const state2 = yield* applyEvent({ state, event: spaceEvent2 });
const state2 = yield* applyEvent({ event: spaceEvent2, state });
const spaceEvent3 = yield* createInvitation({
author,
previousEventHash: state.lastEventHash,
Expand All @@ -88,13 +88,13 @@ it('should fail to invite an account that is already a member', async () => {
const result = await Effect.runPromiseExit(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });
const spaceEvent2 = yield* createInvitation({
author,
previousEventHash: state.lastEventHash,
invitee: author, // inviting the author
});
yield* applyEvent({ state, event: spaceEvent2 });
yield* applyEvent({ event: spaceEvent2, state });
}),
);

Expand All @@ -105,24 +105,24 @@ it('should fail in case the author is not an admin', async () => {
const result = await Effect.runPromiseExit(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });
const spaceEvent2 = yield* createInvitation({
author,
previousEventHash: state.lastEventHash,
invitee,
});
const state2 = yield* applyEvent({ state, event: spaceEvent2 });
const state2 = yield* applyEvent({ event: spaceEvent2, state });
const spaceEvent3 = yield* acceptInvitation({
previousEventHash: state2.lastEventHash,
author: invitee,
});
const state3 = yield* applyEvent({ state: state2, event: spaceEvent3 });
const state3 = yield* applyEvent({ event: spaceEvent3, state: state2 });
const spaceEvent4 = yield* createInvitation({
author: invitee,
previousEventHash: state.lastEventHash,
invitee: invitee2,
});
yield* applyEvent({ state: state3, event: spaceEvent4 });
yield* applyEvent({ event: spaceEvent4, state: state3 });
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ it('should create a space state', async () => {
const state = await Effect.runPromise(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
return yield* applyEvent({ event: spaceEvent });
return yield* applyEvent({ event: spaceEvent, state: undefined });
}),
);

Expand Down
12 changes: 6 additions & 6 deletions packages/graph-framework-space-events/src/delete-space.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ it('should delete a space', async () => {
const state = await Effect.runPromise(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });
const spaceEvent2 = yield* deleteSpace({ author, id: state.id, previousEventHash: state.lastEventHash });
return yield* applyEvent({ state, event: spaceEvent2 });
return yield* applyEvent({ event: spaceEvent2, state });
}),
);

Expand All @@ -46,24 +46,24 @@ it('should fail in case the author is not an admin', async () => {
const result = await Effect.runPromiseExit(
Effect.gen(function* () {
const spaceEvent = yield* createSpace({ author });
const state = yield* applyEvent({ event: spaceEvent });
const state = yield* applyEvent({ event: spaceEvent, state: undefined });
const spaceEvent2 = yield* createInvitation({
author,
previousEventHash: state.lastEventHash,
invitee,
});
const state2 = yield* applyEvent({ state, event: spaceEvent2 });
const state2 = yield* applyEvent({ event: spaceEvent2, state });
const spaceEvent3 = yield* acceptInvitation({
previousEventHash: state2.lastEventHash,
author: invitee,
});
const state3 = yield* applyEvent({ state: state2, event: spaceEvent3 });
const state3 = yield* applyEvent({ event: spaceEvent3, state: state2 });
const spaceEvent4 = yield* deleteSpace({
author: invitee,
previousEventHash: state.lastEventHash,
id: state.id,
});
yield* applyEvent({ state: state3, event: spaceEvent4 });
yield* applyEvent({ event: spaceEvent4, state: state3 });
}),
);

Expand Down
Loading