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 docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| Field | Type | Description |
|---|---|---|
| `persistence` | `{ dbName: string, passphrase?: string }` | Enable IndexedDB persistence. A `passphrase` turns on AES-GCM encryption at rest |
| `remote` | `{ url: string, clientId?: string, ticket?: string, username?: string, password?: string }` | Enable MQTT sync. `url` is a `ws://`/`wss://` MQTT endpoint; `ticket` is a JWT for MQTT v5 enhanced auth; `username`/`password` drive classic MQTT password auth |
| `remote` | `{ url: string, clientId?: string, ticket?: string, username?: string, password?: string, autoConnect?: boolean }` | Enable MQTT sync. `url` is a `ws://`/`wss://` MQTT endpoint; `ticket` is a JWT for MQTT v5 enhanced auth; `username`/`password` drive classic MQTT password auth. `autoConnect` (default `true`) → set `false` to skip the connect on `initialize()` and drive it yourself via `reconnect(url, ticket)`, the usual pattern when the JWT is minted dynamically per connection |

## Scope model

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
}
},
"dependencies": {
"@laboverwire/stitch-wasm": "^0.2.2"
"@laboverwire/stitch-wasm": "^0.3.0"
},
"peerDependencies": {
"react": "^19.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface RemoteConfig {
ticket?: string;
username?: string;
password?: string;
autoConnect?: boolean;
}

export interface StoreOptions {
Expand Down
46 changes: 46 additions & 0 deletions tests/integration/auto-connect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { afterEach, describe, it, expect, vi } from 'vitest';
import { createStore } from '../../src/store.ts';
import { projectTaskConfig, uniqueDbName } from '../helpers/fixtures.ts';
import type { RemoteConfig, Store } from '../../src/types.ts';

const UNROUTABLE = 'ws://127.0.0.1:49871';

describe('remote.autoConnect', () => {
const stores: Store[] = [];

afterEach(async () => {
while (stores.length > 0) {
const store = stores.pop();
if (store) await store.destroy();
}
});

function open(remote: RemoteConfig): Store {
const store = createStore(projectTaskConfig(), {
persistence: { dbName: uniqueDbName() },
remote,
});
stores.push(store);
return store;
}

it('autoConnect:false does not start a connection on initialize', async () => {
const store = open({ url: UNROUTABLE, autoConnect: false });
await store.initialize();

await new Promise((resolve) => setTimeout(resolve, 150));

expect(store.connectionStatus).not.toBe('connecting');
expect(store.connectionStatus).not.toBe('connected');
expect(store.isReconnecting).toBe(false);
expect(store.hasRemote).toBe(true);
});

it('default (autoConnect omitted) starts the connection on initialize', async () => {
const store = open({ url: UNROUTABLE });
await store.initialize();

await vi.waitFor(() => expect(store.connectionStatus).toBe('connecting'));
expect(store.hasRemote).toBe(true);
});
});