diff --git a/flake.lock b/flake.lock index 6f45589..7c23c26 100644 --- a/flake.lock +++ b/flake.lock @@ -159,11 +159,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1681202837, - "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", "owner": "numtide", "repo": "flake-utils", - "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", "type": "github" }, "original": { @@ -207,11 +207,11 @@ ] }, "locked": { - "lastModified": 1703255365, - "narHash": "sha256-Rhez/oZISXBUt2nBdjFUv1c7435GEY5AyDQx5Kn47hk=", + "lastModified": 1707287589, + "narHash": "sha256-5+PKdLExrZS31F5gcm0HxKt82g2rAuEkGEJz6vGOwaw=", "owner": "holochain", "repo": "holochain", - "rev": "ecb2576372a2bbc05985725e7f1558029871cc72", + "rev": "5d75871802ff96ca0404c71ee330098f5d2fe38f", "type": "github" }, "original": { @@ -223,16 +223,16 @@ "holochain_2": { "flake": false, "locked": { - "lastModified": 1702563980, - "narHash": "sha256-FreX9/2dj2/gxyj/1MmaZkmFKnrTUrHtH1/FD9sfE/M=", + "lastModified": 1707245081, + "narHash": "sha256-l9WHMlD9IDuEv/N/3WDCsP3XLUUnZFrOBEZjbWnC+/Y=", "owner": "holochain", "repo": "holochain", - "rev": "adaed11bd637ae8ff4ffa216558aea226cc87a0c", + "rev": "0a3b2408b2d6482b913b9f0faf58a39b567f763a", "type": "github" }, "original": { "owner": "holochain", - "ref": "holochain-0.2.4", + "ref": "holochain-0.2.6", "repo": "holochain", "type": "github" } @@ -240,16 +240,16 @@ "lair": { "flake": false, "locked": { - "lastModified": 1691746070, - "narHash": "sha256-CHsTI4yIlkfnYWx2sNgzAoDBvKTLIChybzyJNbB1sMU=", + "lastModified": 1706550351, + "narHash": "sha256-psVjtb+zj0pZnHTj1xNP2pGBd5Ua1cSwdOAdYdUe3yQ=", "owner": "holochain", "repo": "lair", - "rev": "6ab41b60744515f1760669db6fc5272298a5f324", + "rev": "b11e65eff11c8ac3bf938607946f5c7201298a65", "type": "github" }, "original": { "owner": "holochain", - "ref": "lair_keystore-v0.3.0", + "ref": "lair_keystore-v0.4.2", "repo": "lair", "type": "github" } @@ -288,11 +288,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1703013332, - "narHash": "sha256-+tFNwMvlXLbJZXiMHqYq77z/RfmpfpiI3yjL6o/Zo9M=", + "lastModified": 1707092692, + "narHash": "sha256-ZbHsm+mGk/izkWtT4xwwqz38fdlwu7nUUKXTOmm4SyE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "54aac082a4d9bb5bbc5c4e899603abfb76a3f6d6", + "rev": "faf912b086576fd1a15fca610166c98d47bc667e", "type": "github" }, "original": { @@ -393,11 +393,11 @@ ] }, "locked": { - "lastModified": 1703211258, - "narHash": "sha256-ye9HcJ9WH/QCq6R4GC3FvLnIDpa2Kje4nXya9j/mhA4=", + "lastModified": 1707271822, + "narHash": "sha256-/DZsoPH5GBzOpVEGz5PgJ7vh8Q6TcrJq5u8FcBjqAfI=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "b8c487832712f4e3e6f9e81b70e6654eb907abfc", + "rev": "7a94fe7690d2bdfe1aab475382a505e14dc114a6", "type": "github" }, "original": { @@ -409,11 +409,11 @@ "scaffolding": { "flake": false, "locked": { - "lastModified": 1695674679, - "narHash": "sha256-IwgQbgitUo61ZXYSXBAro5ThfYy/yMGmzZGTb3c6sT0=", + "lastModified": 1705076186, + "narHash": "sha256-O914XeBuFulky5RqTOvsog+fbO12v0ppW+mIdO6lvKU=", "owner": "holochain", "repo": "scaffolding", - "rev": "821439b8dd49d5ce594be04c4720df25e88a4dbc", + "rev": "42e025fe23ac0b4cd659d95e6752d2d300a8d076", "type": "github" }, "original": { @@ -447,11 +447,11 @@ }, "locked": { "dir": "versions/0_2", - "lastModified": 1703255365, - "narHash": "sha256-Rhez/oZISXBUt2nBdjFUv1c7435GEY5AyDQx5Kn47hk=", + "lastModified": 1707287589, + "narHash": "sha256-5+PKdLExrZS31F5gcm0HxKt82g2rAuEkGEJz6vGOwaw=", "owner": "holochain", "repo": "holochain", - "rev": "ecb2576372a2bbc05985725e7f1558029871cc72", + "rev": "5d75871802ff96ca0404c71ee330098f5d2fe38f", "type": "github" }, "original": { diff --git a/package-lock.json b/package-lock.json index 239608b..6aabb27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1531,12 +1531,12 @@ } }, "node_modules/@holochain-open-dev/stores": { - "version": "0.8.9", - "resolved": "https://registry.npmjs.org/@holochain-open-dev/stores/-/stores-0.8.9.tgz", - "integrity": "sha512-Au7mAL0ZIZbeH8MFZFky12wo3UXsUX+3LO3+LydzJBqw9jqtm7epM4kr5lQZfivkm0tMtAXpYWi/lBqd14wI1w==", + "version": "0.8.11", + "resolved": "https://registry.npmjs.org/@holochain-open-dev/stores/-/stores-0.8.11.tgz", + "integrity": "sha512-f6Khq0cZYuVql7NnEz61Roq0sUWfpkpOA75qxcbIOVghc66gnV9VXDtB67iCi4MYffkmKSUU654TOfjFB/kvQQ==", "dependencies": { "@alenaksu/json-viewer": "^2.0.1", - "@holochain-open-dev/utils": "^0.16.2", + "@holochain-open-dev/utils": "^0.16.5", "@holochain/client": "^0.16.6", "@scoped-elements/cytoscape": "^0.2.0", "@shoelace-style/shoelace": "^2.11.2", @@ -1598,9 +1598,9 @@ } }, "node_modules/@holochain-open-dev/utils": { - "version": "0.16.3", - "resolved": "https://registry.npmjs.org/@holochain-open-dev/utils/-/utils-0.16.3.tgz", - "integrity": "sha512-mmn3Lo3bQAdPaPFUfjYj64CH/G5ywOuC9zFbF9XqZO3MyMsqWmvIJjVmgEDDCKQ8s/lMEUyZhhEOTLbhEw1Y5w==", + "version": "0.16.5", + "resolved": "https://registry.npmjs.org/@holochain-open-dev/utils/-/utils-0.16.5.tgz", + "integrity": "sha512-sLP0a+v2osR7ra8ZYadLrmSdzBV3rEl/1qKlnY2PEWJ014KK4MVC08FyJ5hu4JSzeZMhEEUkB3AELuONvcGhHA==", "dependencies": { "@holochain/client": "^0.16.2", "@msgpack/msgpack": "^2.7.2", @@ -8144,8 +8144,8 @@ "name": "@holochain-syn/store", "version": "0.11.1", "dependencies": { - "@holochain-open-dev/stores": "^0.8.9", - "@holochain-open-dev/utils": "^0.16.3", + "@holochain-open-dev/stores": "^0.8.11", + "@holochain-open-dev/utils": "^0.16.5", "@holochain-syn/client": "^0.11.1", "@holochain/client": "^0.16.1", "@msgpack/msgpack": "^2.7.2", diff --git a/packages/store/package.json b/packages/store/package.json index 1b58207..d53fd91 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -1,6 +1,6 @@ { "name": "@holochain-syn/store", - "version": "0.11.1", + "version": "0.11.2", "main": "./dist/index.js", "types": "./dist/index.d.ts", "type": "module", @@ -16,8 +16,8 @@ "build:watch": "tsc -w --preserveWatchOutput" }, "dependencies": { - "@holochain-open-dev/stores": "^0.8.9", - "@holochain-open-dev/utils": "^0.16.3", + "@holochain-open-dev/stores": "^0.8.11", + "@holochain-open-dev/utils": "^0.16.5", "@holochain-syn/client": "^0.11.1", "@holochain/client": "^0.16.1", "@msgpack/msgpack": "^2.7.2", diff --git a/packages/store/src/session-store.ts b/packages/store/src/session-store.ts index 979d9fd..dbac21c 100644 --- a/packages/store/src/session-store.ts +++ b/packages/store/src/session-store.ts @@ -601,6 +601,7 @@ export class SessionStore implements SliceStore { for (const interval of this.intervals) { clearInterval(interval); } + this.onLeave(); } private handleNewParticipant(participant: AgentPubKey) { diff --git a/packages/store/src/workspace-store.ts b/packages/store/src/workspace-store.ts index 72ad251..cd653f3 100644 --- a/packages/store/src/workspace-store.ts +++ b/packages/store/src/workspace-store.ts @@ -2,6 +2,7 @@ import { AsyncReadable, AsyncStatus, derived, + deriveStore, liveLinksStore, pipe, retryUntilSuccess, @@ -177,6 +178,24 @@ export class WorkspaceStore { ) ); + /** + * Keeps an up to date copy of the state of the session if there is an active one, + * or the latest snapshot if there isn't a session + */ + latestState: AsyncReadable = deriveStore(this.session, session => { + if (session) + return derived( + session.state, + s => + ({ + status: 'complete', + value: s, + } as AsyncStatus) + ); + + return this.latestSnapshot; + }); + /** * Joins the real-time collaborative session for this workspace * This will connect to all the active peers and start to synchronize with them diff --git a/tests/src/lib/syn-store.test.ts b/tests/src/lib/syn-store.test.ts index f4268b2..1f15938 100644 --- a/tests/src/lib/syn-store.test.ts +++ b/tests/src/lib/syn-store.test.ts @@ -163,6 +163,14 @@ test('SynStore, DocumentStore, WorkspaceStore and SessionStore work', async () = assert.equal(participants.active.length, 1); + let latestState = await toPromise(aliceWorkspaceStore.latestState); + + assert.deepEqual(latestState, state); + await aliceSessionStore.leaveSession(); + + latestState = await toPromise(aliceWorkspaceStore.latestState); + + assert.deepEqual(latestState, state); }); });