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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ pnpm prisma migrate dev # this will also generate the Prisma client

```sh
pnpm up --interactive --latest -r
```
```
4 changes: 1 addition & 3 deletions apps/events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@
"@automerge/automerge": "^v2.2.9-alpha.3",
"@automerge/automerge-repo": "^2.0.0-alpha.14",
"@automerge/automerge-repo-react-hooks": "^2.0.0-alpha.14",
"@graphprotocol/graph-framework": "workspace:*",
"@graphprotocol/hypergraph": "workspace:*",
"@noble/hashes": "^1.5.0",
"@privy-io/react-auth": "^1.88.4",
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-slot": "^1.1.0",
"@tanstack/react-router": "^1.62.1",
"@xmtp/react-sdk": "^9.0.0",
"@xmtp/xmtp-js": "^13.0.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"effect": "^3.12.2",
Expand Down
13 changes: 6 additions & 7 deletions apps/events/src/components/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { GraphLogin, useGraphLogin } from '@graph-framework/identity';
import type { Signer } from '@graph-framework/identity/types';
import { Identity } from '@graphprotocol/hypergraph';
import { PrivyProvider, usePrivy, useWallets } from '@privy-io/react-auth';
import { useRouter } from '@tanstack/react-router';
import { useEffect, useState } from 'react';

function DoGraphLogin() {
const { login } = useGraphLogin();
const { login } = Identity.useGraphLogin();
useEffect(() => {
console.log('Logging in to The Graph');
login();
Expand All @@ -16,7 +15,7 @@ function DoGraphLogin() {
function Auth({ children }: { children: React.ReactNode }) {
const { signMessage, authenticated } = usePrivy();
const { wallets } = useWallets();
const [signer, setSigner] = useState<Signer | null>(null);
const [signer, setSigner] = useState<Identity.Signer | null>(null);

useEffect(() => {
const getSigner = async () => {
Expand All @@ -43,10 +42,10 @@ function Auth({ children }: { children: React.ReactNode }) {
return (
<>
{signer && authenticated ? (
<GraphLogin storage={localStorage} signer={signer}>
<Identity.GraphLogin storage={localStorage} signer={signer}>
<DoGraphLogin />
{children}
</GraphLogin>
</Identity.GraphLogin>
) : (
children
)}
Expand Down Expand Up @@ -79,7 +78,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {

export function RequireAuth({ children }: { children: React.ReactNode }) {
const { authenticated } = usePrivy();
const { authenticated: graphAuthenticated } = useGraphLogin();
const { authenticated: graphAuthenticated } = Identity.useGraphLogin();
const router = useRouter();
if (!authenticated || !graphAuthenticated) {
router.navigate({
Expand Down
6 changes: 3 additions & 3 deletions apps/events/src/components/debug-invitations.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Invitation } from '@graphprotocol/graph-framework';
import type { Messages } from '@graphprotocol/hypergraph';

import { Button } from './ui/button';

type Props = {
invitations: Invitation[];
invitations: Messages.Invitation[];
accept: (params: {
invitation: Invitation;
invitation: Messages.Invitation;
}) => Promise<unknown>;
};

Expand Down
4 changes: 2 additions & 2 deletions apps/events/src/components/debug-space-events.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SpaceEvent } from '@graphprotocol/graph-framework';
import type { SpaceEvents } from '@graphprotocol/hypergraph';

export function DebugSpaceEvents({ events }: { events: SpaceEvent[] }) {
export function DebugSpaceEvents({ events }: { events: SpaceEvents.SpaceEvent[] }) {
return (
<ul className="text-xs">
{events.map((event) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/events/src/components/debug-space-state.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SpaceState } from '@graphprotocol/graph-framework';
import type { SpaceEvents } from '@graphprotocol/hypergraph';

export function DebugSpaceState(props: { state: SpaceState | undefined }) {
export function DebugSpaceState(props: { state: SpaceEvents.SpaceState | undefined }) {
return (
<div className="text-xs">
<pre>{JSON.stringify(props, null, 2)}</pre>
Expand Down
4 changes: 2 additions & 2 deletions apps/events/src/components/logout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useGraphLogin } from '@graph-framework/identity';
import { Identity } from '@graphprotocol/hypergraph';
import { usePrivy } from '@privy-io/react-auth';
import { useRouter } from '@tanstack/react-router';
import { Button } from './ui/button';

export function Logout() {
const { logout: graphLogout } = useGraphLogin();
const { logout: graphLogout } = Identity.useGraphLogin();
const { logout: privyLogout } = usePrivy();
const router = useRouter();
const disconnectWallet = () => {
Expand Down
10 changes: 5 additions & 5 deletions apps/events/src/components/todos-app.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useState } from 'react';

import { useCreateEntity, useDeleteEntity, useQuery, useUpdateEntity } from '@graph-framework/schema';
import { Schema } from '@graphprotocol/hypergraph';

import { Todo } from '../schema';
import { Button } from './ui/button';
import { Input } from './ui/input';

export const TodosApp = () => {
const todos = useQuery(Todo);
const createEntity = useCreateEntity(Todo);
const updateEntity = useUpdateEntity(Todo);
const deleteEntity = useDeleteEntity();
const todos = Schema.useQuery(Todo);
const createEntity = Schema.useCreateEntity(Todo);
const updateEntity = Schema.useUpdateEntity(Todo);
const deleteEntity = Schema.useDeleteEntity();
const [newTodoTitle, setNewTodoTitle] = useState('');

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/events/src/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from 'vitest';

test('hello', () => {
expect('Hello from graph-framework').toBe('Hello from graph-framework');
expect('Hello from hypergraph').toBe('Hello from hypergraph');
});
4 changes: 2 additions & 2 deletions apps/events/src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Logout } from '@/components/logout';
import { useGraphLogin } from '@graph-framework/identity';
import { Identity } from '@graphprotocol/hypergraph';
import { Link, Outlet, createRootRoute } from '@tanstack/react-router';
import { TanStackRouterDevtools } from '@tanstack/router-devtools';
import { CalendarDays } from 'lucide-react';

export const Route = createRootRoute({
component: () => {
const { authenticated } = useGraphLogin();
const { authenticated } = Identity.useGraphLogin();
return (
<>
<div className="flex flex-col min-h-screen">
Expand Down
4 changes: 2 additions & 2 deletions apps/events/src/routes/login.lazy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button } from '@/components/ui/button';
import { useGraphLogin } from '@graph-framework/identity';
import { Identity } from '@graphprotocol/hypergraph';
import { usePrivy } from '@privy-io/react-auth';
import { createLazyFileRoute, useRouter } from '@tanstack/react-router';
import { useEffect } from 'react';
Expand All @@ -12,7 +12,7 @@ function Login() {
const { ready, authenticated, login } = usePrivy();
// Disable login when Privy is not ready or the user is already authenticated
const disableLogin = !ready || (ready && authenticated);
const { authenticated: graphAuthenticated } = useGraphLogin();
const { authenticated: graphAuthenticated } = Identity.useGraphLogin();
const router = useRouter();
const redirectToPlayground = () => {
router.navigate({
Expand Down
17 changes: 5 additions & 12 deletions apps/events/src/routes/playground.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { createFileRoute } from '@tanstack/react-router';
import { useEffect, useState } from 'react';

import {
GraphFramework,
SpacesProvider,
store,
useGraphFramework,
useGraphLogin,
useSelector,
} from '@graphprotocol/graph-framework';
import { GraphFramework, Identity, Schema, store, useGraphFramework, useSelector } from '@graphprotocol/hypergraph';

import { DebugInvitations } from '@/components/debug-invitations';
import { DebugSpaceEvents } from '@/components/debug-space-events';
Expand Down Expand Up @@ -64,7 +57,7 @@ const App = ({
const { createSpace, listSpaces, listInvitations, invitations, acceptInvitation, subscribeToSpace, inviteToSpace } =
useGraphFramework();

const { isAuthenticated, getSessionToken, getIdentity } = useGraphLogin();
const { isAuthenticated, getSessionToken, getIdentity } = Identity.useGraphLogin();
useEffect(() => {
console.log('accountId: ', accountId);
console.log('Authenticated: ', isAuthenticated());
Expand Down Expand Up @@ -105,7 +98,7 @@ const App = ({
{spaces.map((space) => {
return (
<li key={space.id}>
<SpacesProvider defaultSpace={space.id}>
<Schema.SpacesProvider defaultSpace={space.id}>
<h3>Space id: {space.id}</h3>
<p>Keys:</p>
<pre className="text-xs">{JSON.stringify(space.keys)}</pre>
Expand Down Expand Up @@ -151,7 +144,7 @@ const App = ({
<h3>Events</h3>
<DebugSpaceEvents events={space.events} />
<hr />
</SpacesProvider>
</Schema.SpacesProvider>
</li>
);
})}
Expand All @@ -161,7 +154,7 @@ const App = ({
};

export const ChooseAccount = () => {
const { authenticated, getIdentity, getSessionToken } = useGraphLogin();
const { authenticated, getIdentity, getSessionToken } = Identity.useGraphLogin();
const [account, setAccount] = useState<{
accountId: string;
signaturePrivateKey: string;
Expand Down
10 changes: 5 additions & 5 deletions apps/events/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Model, Types } from '@graphprotocol/graph-framework';
import { Schema } from '@graphprotocol/hypergraph';

export class Todo extends Model.Class<Todo>('Todo')({
id: Model.Generated(Types.Text),
name: Types.Text,
completed: Types.Checkbox,
export class Todo extends Schema.Model.Class<Todo>('Todo')({
id: Schema.Model.Generated(Schema.Types.Text),
name: Schema.Types.Text,
completed: Schema.Types.Checkbox,
}) {}
16 changes: 2 additions & 14 deletions apps/events/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,8 @@
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@graphprotocol/graph-framework": ["../../packages/graph-framework/src/index.js"],
"@graphprotocol/graph-framework/*": ["../../packages/graph-framework/src/*.js"],
"@graph-framework/space-events": ["../../packages/graph-framework-space-events/src/index.js"],
"@graph-framework/space-events/*": ["../../packages/graph-framework-space-events/src/*.js"],
"@graph-framework/messages": ["../../packages/graph-framework-messages/src/index.js"],
"@graph-framework/messages/*": ["../../packages/graph-framework-messages/src/*.js"],
"@graph-framework/identity": ["../../packages/graph-framework-identity/src/index.js"],
"@graph-framework/identity/*": ["../../packages/graph-framework-identity/src/*.js"],
"@graph-framework/key": ["../../packages/graph-framework-key/src/index.js"],
"@graph-framework/key/*": ["../../packages/graph-framework-key/src/*.js"],
"@graph-framework/schema": ["../../packages/graph-framework-schema/src/index.js"],
"@graph-framework/schema/*": ["../../packages/graph-framework-schema/src/*.js"],
"@graph-framework/utils": ["../../packages/graph-framework-utils/src/index.js"],
"@graph-framework/utils/*": ["../../packages/graph-framework-utils/src/*.js"]
"@graphprotocol/hypergraph": ["../../packages/hypergraph/src/index.js"],
"@graphprotocol/hypergraph/*": ["../../packages/hypergraph/src/*.js"]
}
},
"include": ["src"]
Expand Down
16 changes: 2 additions & 14 deletions apps/events/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,8 @@
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"],
"@graphprotocol/graph-framework": ["../../packages/graph-framework/src/index.js"],
"@graphprotocol/graph-framework/*": ["../../packages/graph-framework/src/*.js"],
"@graph-framework/space-events": ["../../packages/graph-framework-space-events/src/index.js"],
"@graph-framework/space-events/*": ["../../packages/graph-framework-space-events/src/*.js"],
"@graph-framework/messages": ["../../packages/graph-framework-messages/src/index.js"],
"@graph-framework/messages/*": ["../../packages/graph-framework-messages/src/*.js"],
"@graph-framework/identity": ["../../packages/graph-framework-identity/src/index.js"],
"@graph-framework/identity/*": ["../../packages/graph-framework-identity/src/*.js"],
"@graph-framework/key": ["../../packages/graph-framework-key/src/index.js"],
"@graph-framework/key/*": ["../../packages/graph-framework-key/src/*.js"],
"@graph-framework/schema": ["../../packages/graph-framework-schema/src/index.js"],
"@graph-framework/schema/*": ["../../packages/graph-framework-schema/src/*.js"],
"@graph-framework/utils": ["../../packages/graph-framework-utils/src/index.js"],
"@graph-framework/utils/*": ["../../packages/graph-framework-utils/src/*.js"]
"@graphprotocol/hypergraph": ["../../packages/hypergraph/src/index.js"],
"@graphprotocol/hypergraph/*": ["../../packages/hypergraph/src/*.js"]
}
}
}
10 changes: 2 additions & 8 deletions apps/events/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';
import { TanStackRouterVite } from '@tanstack/router-plugin/vite';
import react from '@vitejs/plugin-react';
import path from 'node:path';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import topLevelAwait from 'vite-plugin-top-level-await';
Expand All @@ -23,13 +23,7 @@ export default defineConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@graphprotocol/graph-framework': path.resolve(__dirname, '../../packages/graph-framework/src'),
'@graph-framework/space-events': path.resolve(__dirname, '../../packages/graph-framework-space-events/src'),
'@graph-framework/utils': path.resolve(__dirname, '../../packages/graph-framework-utils/src'),
'@graph-framework/schema': path.resolve(__dirname, '../../packages/graph-framework-schema/src'),
'@graph-framework/identity': path.resolve(__dirname, '../../packages/graph-framework-identity/src'),
'@graph-framework/key': path.resolve(__dirname, '../../packages/graph-framework-key/src'),
'@graph-framework/messages': path.resolve(__dirname, '../../packages/graph-framework-messages/src'),
'@graphprotocol/hypergraph': path.resolve(__dirname, '../../packages/hypergraph/src'),
},
},
});
4 changes: 1 addition & 3 deletions apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"check:fix": "pnpm biome check --write src/*"
},
"dependencies": {
"@graph-framework/identity": "workspace:*",
"@graph-framework/messages": "workspace:*",
"@graph-framework/space-events": "workspace:*",
"@graphprotocol/hypergraph": "workspace:*",
"@noble/ciphers": "^1.0.0",
"@prisma/client": "5.22.0",
"cors": "^2.8.5",
Expand Down
11 changes: 5 additions & 6 deletions apps/server/src/handlers/applySpaceEvent.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Effect, Exit } from 'effect';

import type { KeyBoxWithKeyId } from '@graph-framework/messages';
import type { SpaceEvent } from '@graph-framework/space-events';
import { applyEvent } from '@graph-framework/space-events';
import type { Messages } from '@graphprotocol/hypergraph';
import { SpaceEvents } from '@graphprotocol/hypergraph';

import { prisma } from '../prisma.js';

type Params = {
accountId: string;
spaceId: string;
event: SpaceEvent;
keyBoxes: KeyBoxWithKeyId[];
event: SpaceEvents.SpaceEvent;
keyBoxes: Messages.KeyBoxWithKeyId[];
};

export async function applySpaceEvent({ accountId, spaceId, event, keyBoxes }: Params) {
Expand All @@ -37,7 +36,7 @@ export async function applySpaceEvent({ accountId, spaceId, event, keyBoxes }: P
orderBy: { counter: 'desc' },
});

const result = await Effect.runPromiseExit(applyEvent({ event, state: JSON.parse(lastEvent.state) }));
const result = await Effect.runPromiseExit(SpaceEvents.applyEvent({ event, state: JSON.parse(lastEvent.state) }));
if (Exit.isFailure(result)) {
console.log('Failed to apply event', result);
throw new Error('Invalid event');
Expand Down
11 changes: 6 additions & 5 deletions apps/server/src/handlers/createSpace.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Effect, Exit } from 'effect';

import type { KeyBox } from '@graph-framework/messages';
import { type CreateSpaceEvent, applyEvent } from '@graph-framework/space-events';
import type { Messages } from '@graphprotocol/hypergraph';

import { SpaceEvents } from '@graphprotocol/hypergraph';

import { prisma } from '../prisma.js';

type Params = {
accountId: string;
event: CreateSpaceEvent;
keyBox: KeyBox;
event: SpaceEvents.CreateSpaceEvent;
keyBox: Messages.KeyBox;
keyId: string;
};

export const createSpace = async ({ accountId, event, keyBox, keyId }: Params) => {
const result = await Effect.runPromiseExit(applyEvent({ event, state: undefined }));
const result = await Effect.runPromiseExit(SpaceEvents.applyEvent({ event, state: undefined }));
if (Exit.isFailure(result)) {
throw new Error('Invalid event');
}
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/handlers/listInvitations.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Schema } from 'effect';

import { SpaceState } from '@graph-framework/space-events';
import { SpaceEvents } from '@graphprotocol/hypergraph';

import { prisma } from '../prisma.js';

type Params = {
accountId: string;
};

const decodeSpaceState = Schema.decodeUnknownEither(SpaceState);
const decodeSpaceState = Schema.decodeUnknownEither(SpaceEvents.SpaceState);

export const listInvitations = async ({ accountId }: Params) => {
const result = await prisma.invitation.findMany({
Expand Down
Loading
Loading