@spooky-sync/core 0.0.1-canary.287 → 0.0.1-canary.288

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1752,8 +1752,8 @@ function selfAllowlistedVariant(flag, userId) {
1752
1752
 
1753
1753
  //#endregion
1754
1754
  //#region src/modules/devtools/index.ts
1755
- const CORE_VERSION = "0.0.1-canary.287";
1756
- const WASM_VERSION = "0.0.1-canary.287";
1755
+ const CORE_VERSION = "0.0.1-canary.288";
1756
+ const WASM_VERSION = "0.0.1-canary.288";
1757
1757
  const SURREAL_VERSION = "3.0.3";
1758
1758
  var DevToolsService = class DevToolsService {
1759
1759
  eventsHistory = [];
@@ -12507,6 +12507,8 @@ var TabsCoordinator = class {
12507
12507
  this.enqueue(async () => {
12508
12508
  if (this.role === "leader") await this.teardownLeader();
12509
12509
  else if (this.role === "follower") this.teardownFollower("bucket switch");
12510
+ this.setRole("solo");
12511
+ this.leaderTabId = null;
12510
12512
  this.bucketId = bucketId;
12511
12513
  const timeout = setTimeout(() => {
12512
12514
  this.startResolve = null;
@@ -14011,7 +14013,7 @@ function createTabsCoordinator(config, s, host) {
14011
14013
  return new TabsCoordinator({
14012
14014
  tabId: s.tabId,
14013
14015
  fingerprint: computeTabsFingerprint({
14014
- coreVersion: "0.0.1-canary.287",
14016
+ coreVersion: "0.0.1-canary.288",
14015
14017
  schemaHash: hash53(config.schemaSurql),
14016
14018
  endpoint: config.database.endpoint ?? "",
14017
14019
  namespace: config.database.namespace,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spooky-sync/core",
3
- "version": "0.0.1-canary.287",
3
+ "version": "0.0.1-canary.288",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -75,8 +75,8 @@
75
75
  }
76
76
  },
77
77
  "dependencies": {
78
- "@spooky-sync/query-builder": "0.0.1-canary.287",
79
- "@spooky-sync/ssp-wasm": "0.0.1-canary.287",
78
+ "@spooky-sync/query-builder": "0.0.1-canary.288",
79
+ "@spooky-sync/ssp-wasm": "0.0.1-canary.288",
80
80
  "@sqlite.org/sqlite-wasm": "3.53.0-build1",
81
81
  "@surrealdb/wasm": "^3.0.3",
82
82
  "blurhash": "^2.0.5",
@@ -362,4 +362,25 @@ describe('TabsCoordinator integration', () => {
362
362
  await b.coordinator.stop();
363
363
  await a.coordinator.stop();
364
364
  });
365
+
366
+ it('signs in from an anonymous leader into a user bucket another tab already leads', async () => {
367
+ const signedIn = makeCoordinator('signed-in', {
368
+ // The real hook awaits a worker RPC. FakePort does not buffer messages
369
+ // before onmessage is set, so let the joining tab bind its sync port.
370
+ async exposeClientPort() { await flush(20); },
371
+ });
372
+ const signingIn = makeCoordinator('signing-in');
373
+ try {
374
+ await signedIn.coordinator.start('user1');
375
+ await signingIn.coordinator.start('anon');
376
+
377
+ await expect(signingIn.coordinator.moveToBucket('user1')).resolves.toBe('follower');
378
+ expect(signingIn.log.adoptAttached.map((s) => s.bucketId)).toEqual(['user1']);
379
+ expect(signingIn.log.released).toBe(1);
380
+ expect(signingIn.coordinator.leaderTabId).toBe('signed-in');
381
+ } finally {
382
+ await signingIn.coordinator.stop();
383
+ await signedIn.coordinator.stop();
384
+ }
385
+ }, 20_000);
365
386
  });
@@ -369,6 +369,11 @@ export class TabsCoordinator {
369
369
  // us from the old namespace and re-elects there.
370
370
  if (this.role === 'leader') await this.teardownLeader();
371
371
  else if (this.role === 'follower') this.teardownFollower('bucket switch');
372
+ // Ownership ended with the old bucket. Keeping `leader` here makes
373
+ // attachToLeader reject the new bucket's follower ports when another
374
+ // tab already owns it, leaving sign-in waiting until a reload.
375
+ this.setRole('solo');
376
+ this.leaderTabId = null;
372
377
  this.bucketId = bucketId;
373
378
  const timeout = setTimeout(() => {
374
379
  this.startResolve = null;