From 55cdc2069224cbb7d3fbb7d9b6396036456c5bfc Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Wed, 4 Dec 2024 14:11:21 +0100 Subject: [PATCH 1/3] move store to the framework --- apps/events/src/routes/playground.tsx | 2 +- apps/events/src/types.ts | 12 ------------ packages/graph-framework/package.json | 10 ++++++---- packages/graph-framework/src/index.tsx | 1 + .../lib => packages/graph-framework/src}/store.ts | 14 ++++++++++++-- pnpm-lock.yaml | 13 ++++++++++++- 6 files changed, 32 insertions(+), 20 deletions(-) rename {apps/events/src/lib => packages/graph-framework/src}/store.ts (93%) diff --git a/apps/events/src/routes/playground.tsx b/apps/events/src/routes/playground.tsx index 44a3edaf..1d4008f8 100644 --- a/apps/events/src/routes/playground.tsx +++ b/apps/events/src/routes/playground.tsx @@ -36,6 +36,7 @@ import { encryptMessage, generateId, serialize, + store, } from '@graphprotocol/graph-framework'; import { AutomergeApp } from '@/components/automerge-app'; @@ -44,7 +45,6 @@ import { DebugSpaceEvents } from '@/components/debug-space-events'; import { DebugSpaceState } from '@/components/debug-space-state'; import { Button } from '@/components/ui/button'; import { assertExhaustive } from '@/lib/assertExhaustive'; -import { store } from '@/lib/store'; const availableAccounts = [ { diff --git a/apps/events/src/types.ts b/apps/events/src/types.ts index a3e63175..b4984090 100644 --- a/apps/events/src/types.ts +++ b/apps/events/src/types.ts @@ -1,15 +1,3 @@ -import type { SpaceEvent, SpaceState } from '@graphprotocol/graph-framework'; - -export type SpaceStorageEntry = { - id: string; - events: SpaceEvent[]; - state: SpaceState | undefined; - keys: { id: string; key: string }[]; - updates: Uint8Array[]; - lastUpdateClock: number; - automergeDocumentId: string; -}; - export interface Doc { count: number; } diff --git a/packages/graph-framework/package.json b/packages/graph-framework/package.json index ce4975cb..c97d01d6 100644 --- a/packages/graph-framework/package.json +++ b/packages/graph-framework/package.json @@ -69,11 +69,13 @@ "jsdom": "^25.0.1" }, "dependencies": { - "@graph-framework/utils": "workspace:*", - "@graph-framework/space-events": "workspace:*", "@graph-framework/identity": "workspace:*", - "@graph-framework/schema": "workspace:*", + "@graph-framework/key": "workspace:*", "@graph-framework/messages": "workspace:*", - "@graph-framework/key": "workspace:*" + "@graph-framework/schema": "workspace:*", + "@graph-framework/space-events": "workspace:*", + "@graph-framework/utils": "workspace:*", + "@xstate/store": "^2.6.1", + "xstate": "^5.19.0" } } diff --git a/packages/graph-framework/src/index.tsx b/packages/graph-framework/src/index.tsx index 4c7acbfb..16cf169c 100644 --- a/packages/graph-framework/src/index.tsx +++ b/packages/graph-framework/src/index.tsx @@ -4,3 +4,4 @@ export * from './exports/messages.js'; export * from './exports/schema.js'; export * from './exports/space-events.js'; export * from './exports/utils.js'; +export * from './store.js'; diff --git a/apps/events/src/lib/store.ts b/packages/graph-framework/src/store.ts similarity index 93% rename from apps/events/src/lib/store.ts rename to packages/graph-framework/src/store.ts index 191bdcff..83286f8e 100644 --- a/apps/events/src/lib/store.ts +++ b/packages/graph-framework/src/store.ts @@ -1,6 +1,16 @@ -import type { SpaceEvent, SpaceState, Updates } from '@graphprotocol/graph-framework'; +import type { Updates } from '@graph-framework/messages'; +import type { SpaceEvent, SpaceState } from '@graph-framework/space-events'; import { createStore } from '@xstate/store'; -import type { SpaceStorageEntry } from '../types'; + +export type SpaceStorageEntry = { + id: string; + events: SpaceEvent[]; + state: SpaceState | undefined; + keys: { id: string; key: string }[]; + updates: Uint8Array[]; + lastUpdateClock: number; + automergeDocumentId: string; +}; interface StoreContext { spaces: SpaceStorageEntry[]; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 296a4118..b093ad01 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -232,9 +232,15 @@ importers: '@graph-framework/utils': specifier: workspace:* version: link:../graph-framework-utils + '@xstate/store': + specifier: ^2.6.1 + version: 2.6.1(react@18.3.1) react: specifier: ^18 version: 18.3.1 + xstate: + specifier: ^5.19.0 + version: 5.19.0 devDependencies: '@automerge/automerge': specifier: ^2.2.8 @@ -5062,6 +5068,9 @@ packages: xstate@5.18.1: resolution: {integrity: sha512-m02IqcCQbaE/kBQLunwub/5i8epvkD2mFutnL17Oeg1eXTShe1sRF4D5mhv1dlaFO4vbW5gRGRhraeAD5c938g==} + xstate@5.19.0: + resolution: {integrity: sha512-Juh1MjeRaVWr1IRxXYvQMMRFMrei6vq6+AfP6Zk9D9YV0ZuvubN0aM6s2ITwUrq+uWtP1NTO8kOZmsM/IqeOiQ==} + xtend@4.0.2: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} @@ -5183,7 +5192,7 @@ snapshots: tiny-typed-emitter: 2.1.0 ts-node: 10.9.2(@swc/core@1.7.26(@swc/helpers@0.5.13))(@types/node@22.9.0)(typescript@5.6.3) uuid: 9.0.1 - xstate: 5.18.1 + xstate: 5.19.0 transitivePeerDependencies: - '@swc/core' - '@swc/wasm' @@ -10564,6 +10573,8 @@ snapshots: xstate@5.18.1: {} + xstate@5.19.0: {} + xtend@4.0.2: {} y18n@4.0.3: {} From 806ddb00e2b00598798b42760aaa4443d83b72c1 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Wed, 4 Dec 2024 14:47:07 +0100 Subject: [PATCH 2/3] use node 22 for the CI --- .github/workflows/tests-and-checks.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests-and-checks.yml b/.github/workflows/tests-and-checks.yml index 0ecefbf8..b6647384 100644 --- a/.github/workflows/tests-and-checks.yml +++ b/.github/workflows/tests-and-checks.yml @@ -11,6 +11,10 @@ jobs: - uses: pnpm/action-setup@v3 with: version: 9 + - uses: actions/setup-node@v4 + with: + node-version-file: "package.json" + cache: "pnpm" - name: Install dependencies run: pnpm install --frozen-lockfile - name: Generate Prisma Client From c896858fa5aee4fb3d545b793eecce9d4d99f649 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Wed, 4 Dec 2024 16:08:41 +0100 Subject: [PATCH 3/3] move code to the framework --- apps/events/package.json | 2 - .../src/components/debug-invitations.tsx | 25 +- apps/events/src/routes/playground.tsx | 442 ++------------- packages/graph-framework/package.json | 14 +- .../graph-framework/src}/assertExhaustive.ts | 0 packages/graph-framework/src/core.tsx | 501 ++++++++++++++++++ packages/graph-framework/src/index.tsx | 1 + pnpm-lock.yaml | 50 +- 8 files changed, 603 insertions(+), 432 deletions(-) rename {apps/events/src/lib => packages/graph-framework/src}/assertExhaustive.ts (100%) create mode 100644 packages/graph-framework/src/core.tsx diff --git a/apps/events/package.json b/apps/events/package.json index 671fece7..92f219be 100644 --- a/apps/events/package.json +++ b/apps/events/package.json @@ -19,9 +19,7 @@ "dependencies": { "@automerge/automerge": "^v2.2.9-alpha.3", "@automerge/automerge-repo": "^2.0.0-alpha.14", - "@automerge/automerge-repo-network-websocket": "^2.0.0-alpha.14", "@automerge/automerge-repo-react-hooks": "^2.0.0-alpha.14", - "@automerge/automerge-repo-storage-indexeddb": "^2.0.0-alpha.14", "@noble/hashes": "^1.5.0", "@privy-io/react-auth": "^1.88.4", "@radix-ui/react-avatar": "^1.1.1", diff --git a/apps/events/src/components/debug-invitations.tsx b/apps/events/src/components/debug-invitations.tsx index 2118f441..a9d07a83 100644 --- a/apps/events/src/components/debug-invitations.tsx +++ b/apps/events/src/components/debug-invitations.tsx @@ -4,10 +4,24 @@ import { Button } from './ui/button'; type Props = { invitations: Invitation[]; - accept: (invitation: Invitation) => void; + encryptionPublicKey: string; + encryptionPrivateKey: string; + signaturePrivateKey: string; + accept: (params: { + encryptionPublicKey: string; + encryptionPrivateKey: string; + signaturePrivateKey: string; + invitation: Invitation; + }) => Promise; }; -export function DebugInvitations({ invitations, accept }: Props) { +export function DebugInvitations({ + invitations, + accept, + encryptionPublicKey, + encryptionPrivateKey, + signaturePrivateKey, +}: Props) { return (
    {invitations.map((invitation) => { @@ -16,7 +30,12 @@ export function DebugInvitations({ invitations, accept }: Props) {
    {JSON.stringify(invitation, null, 2)}