|
1 | 1 | # @evolu/common |
2 | 2 |
|
| 3 | +## 6.0.1-preview.20 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- eec5d8e: Add Task, async helpers, and concurrency primitives |
| 8 | + - `Task<T, E>` - Lazy, cancellable Promise that returns typed Result instead of throwing |
| 9 | + - `toTask()` - Convert async functions to Tasks with AbortSignal support |
| 10 | + - `wait()` - Delay execution with Duration strings (e.g., "5m", "2h 30m") |
| 11 | + - `timeout()` - Add timeout behavior to any Task |
| 12 | + - `retry()` - Retry failed operations with exponential backoff and jitter |
| 13 | + - `createSemaphore()` - Limit concurrent operations to a specified count |
| 14 | + - `createMutex()` - Ensure mutual exclusion (one operation at a time) |
| 15 | + |
| 16 | + **Duration Support:** |
| 17 | + - Type-safe duration strings with compile-time validation |
| 18 | + - Support for milliseconds, seconds, minutes, hours, and days |
| 19 | + - Logical combinations like "1h 30m" or "2s 500ms" |
| 20 | + |
| 21 | + Tasks provide precise type safety for cancellation - AbortError is only included in the error union when an AbortSignal is actually provided. All operations are designed to work together seamlessly for complex async workflows. |
| 22 | + |
| 23 | + ## Examples |
| 24 | + |
| 25 | + ### toTask |
| 26 | + |
| 27 | + ```ts |
| 28 | + // Convert an async function to a Task<Result<T, E>> with AbortSignal support |
| 29 | + const fetchTask = (url: string) => |
| 30 | + toTask((context) => |
| 31 | + tryAsync( |
| 32 | + () => fetch(url, { signal: context?.signal ?? null }) |
| 33 | + (error) => ({ type: "FetchError", error }), |
| 34 | + ), |
| 35 | + ); |
| 36 | + |
| 37 | + const result = await fetchTask("/api")(/* optional: { signal } */); |
| 38 | + ``` |
| 39 | + |
| 40 | + ### wait |
| 41 | + |
| 42 | + ```ts |
| 43 | + // Delay for a duration string or NonNegativeInt milliseconds |
| 44 | + await wait("50ms")(); |
| 45 | + ``` |
| 46 | + |
| 47 | + ### timeout |
| 48 | + |
| 49 | + ```ts |
| 50 | + const slow = toTask(async () => ok("done")); |
| 51 | + const withTimeout = timeout("200ms", slow); |
| 52 | + const r = await withTimeout(); // Result<string, TimeoutError> |
| 53 | + ``` |
| 54 | + |
| 55 | + ### retry |
| 56 | + |
| 57 | + ```ts |
| 58 | + interface FetchError { |
| 59 | + readonly type: "FetchError"; |
| 60 | + readonly error: unknown; |
| 61 | + } |
| 62 | + const task = fetchTask("/api"); |
| 63 | + const withRetry = retry({ retries: PositiveInt.orThrow(3) }, task); |
| 64 | + const r = await withRetry(); // Result<Response, FetchError | RetryError<FetchError>> |
| 65 | + ``` |
| 66 | + |
| 67 | + ### createSemaphore |
| 68 | + |
| 69 | + ```ts |
| 70 | + const semaphore = createSemaphore(3); |
| 71 | + const run = (i: number) => |
| 72 | + semaphore.withPermit(() => wait("50ms")().then(() => i)); |
| 73 | + const results = await Promise.all([1, 2, 3, 4, 5].map(run)); // [1,2,3,4,5] |
| 74 | + ``` |
| 75 | + |
| 76 | + ### createMutex |
| 77 | + |
| 78 | + ```ts |
| 79 | + const mutex = createMutex(); |
| 80 | + const seq = (i: number) => |
| 81 | + mutex.withLock(async () => { |
| 82 | + await wait("10ms")(); |
| 83 | + return i; |
| 84 | + }); |
| 85 | + const results = await Promise.all([1, 2, 3].map(seq)); // executes one at a time |
| 86 | + ``` |
| 87 | + |
| 88 | +- eec5d8e: Replace Mnemonic with OwnerSecret |
| 89 | + |
| 90 | + OwnerSecret is the fundamental cryptographic primitive from which all owner keys are derived via SLIP-21. Mnemonic is just a representation of this underlying entropy. This change makes the type system more accurate and the cryptographic relationships clearer. |
| 91 | + |
| 92 | +- eec5d8e: Replace NanoID with Evolu Id |
| 93 | + |
| 94 | + Evolu now uses its own ID format instead of NanoID: |
| 95 | + - **Evolu Id**: 16 random bytes from a cryptographically secure random generator, encoded as 22-character Base64Url string (128 bits of entropy) |
| 96 | + - **Breaking change**: ID format changes from 21 to 22 characters |
| 97 | + - **Why**: Provides standard binary serialization (16 bytes), more entropy than NanoID (128 bits vs ~126 bits), and native Base64Url encoding support across platforms |
| 98 | + |
| 99 | + See the `Id` type documentation for detailed design rationale comparing to NanoID, UUID v4, and UUID v7. |
| 100 | + |
| 101 | +- eec5d8e: Replace `subscribeAppOwner` and `getAppOwner` with `appOwner` promise |
| 102 | + |
| 103 | + The app owner is now accessed via a promise (`evolu.appOwner`) instead of subscription-based methods. This simplifies the API and aligns with modern async patterns. |
| 104 | + |
| 105 | + **Breaking changes:** |
| 106 | + - Removed `evolu.subscribeAppOwner()` and `evolu.getAppOwner()` |
| 107 | + - Removed `useAppOwner()` hook from `@evolu/react` |
| 108 | + - Added `evolu.appOwner` promise that resolves to `AppOwner` |
| 109 | + - Updated `appOwnerState()` in `@evolu/svelte` to return promise-based state |
| 110 | + |
| 111 | + **Migration:** |
| 112 | + |
| 113 | + ```ts |
| 114 | + // Before |
| 115 | + const unsubscribe = evolu.subscribeAppOwner(() => { |
| 116 | + const owner = evolu.getAppOwner(); |
| 117 | + }); |
| 118 | + |
| 119 | + // After |
| 120 | + const owner = await evolu.appOwner; |
| 121 | + ``` |
| 122 | + |
| 123 | + For React, use the `use` hook: |
| 124 | + |
| 125 | + ```ts |
| 126 | + // Before |
| 127 | + import { useAppOwner } from "@evolu/react"; |
| 128 | + const appOwner = useAppOwner(); |
| 129 | + |
| 130 | + // After |
| 131 | + import { use } from "react"; |
| 132 | + const evolu = useEvolu(); |
| 133 | + const appOwner = use(evolu.appOwner); |
| 134 | + ``` |
| 135 | + |
| 136 | +- eec5d8e: # Transport-Based Configuration System |
| 137 | + |
| 138 | + # Transport-Based Configuration System |
| 139 | + |
| 140 | + **BREAKING CHANGE**: Replaced `syncUrl` with flexible `transport` property supporting single transport or array of transports for multiple sync endpoints. |
| 141 | + |
| 142 | + ## What Changed |
| 143 | + - **Removed** `syncUrl` property from Evolu config |
| 144 | + - **Added** `transport` property accepting a single `Transport` object or array of `Transport` objects |
| 145 | + - **Added** `Transport` type union with initial WebSocket support |
| 146 | + - **Updated** sync system to support Nostr-style relay pools with simultaneous connections |
| 147 | + - **Updated** all examples and documentation to use new transport configuration |
| 148 | + |
| 149 | + ## Migration Guide |
| 150 | + |
| 151 | + **Before:** |
| 152 | + |
| 153 | + ```ts |
| 154 | + const evolu = createEvolu(deps)(Schema, { |
| 155 | + syncUrl: "wss://relay.example.com", |
| 156 | + }); |
| 157 | + ``` |
| 158 | + |
| 159 | + **After (single transport):** |
| 160 | + |
| 161 | + ```ts |
| 162 | + const evolu = createEvolu(deps)(Schema, { |
| 163 | + transport: { type: "WebSocket", url: "wss://relay.example.com" }, |
| 164 | + }); |
| 165 | + ``` |
| 166 | + |
| 167 | + **After (multiple transports):** |
| 168 | + |
| 169 | + ```ts |
| 170 | + const evolu = createEvolu(deps)(Schema, { |
| 171 | + transport: [ |
| 172 | + { type: "WebSocket", url: "wss://relay1.example.com" }, |
| 173 | + { type: "WebSocket", url: "wss://relay2.example.com" }, |
| 174 | + ], |
| 175 | + }); |
| 176 | + ``` |
| 177 | + |
| 178 | + ## Benefits |
| 179 | + - **Single or multiple relay support**: Use one transport for simplicity or multiple for redundancy |
| 180 | + - **Intuitive API**: Singular property name that accepts both single item and array |
| 181 | + - **Future extensibility**: Ready for upcoming transport types (FetchRelay, Bluetooth, LocalNetwork) |
| 182 | + - **Nostr-style resilience**: Messages broadcast to all connected relays simultaneously when using arrays |
| 183 | + - **Type safety**: Full TypeScript support for transport configurations |
| 184 | + |
| 185 | + ## Future Transport Types |
| 186 | + |
| 187 | + The new system is designed to support upcoming transport types: |
| 188 | + - `FetchRelay`: HTTP-based polling for environments without WebSocket support |
| 189 | + - `Bluetooth`: P2P sync for offline collaboration |
| 190 | + - `LocalNetwork`: LAN/mesh sync for local networks |
| 191 | + |
| 192 | + ## Technical Details |
| 193 | + - Single transports are automatically normalized to arrays internally |
| 194 | + - CRDT messages are sent to all connected transports simultaneously |
| 195 | + - Duplicate message handling relies on CRDT idempotency (no deduplication needed) |
| 196 | + - WebSocket connections auto-reconnect independently |
| 197 | + - Backwards compatibility removed (preview version breaking change) |
| 198 | + |
| 199 | + This change provides an intuitive API that scales from simple single-transport setups to complex multi-transport configurations, positioning Evolu for a more resilient, multi-transport future. |
| 200 | + |
3 | 201 | ## 6.0.1-preview.19 |
4 | 202 |
|
5 | 203 | ### Patch Changes |
|
0 commit comments