Commit 61a1e59
authored
feat: Add the FDv2 data system and expose it through configuration (#310)
## What this adds
The piece that ties the FDv2 building blocks together and turns them on:
`FDv2DataSystem`, the manager routing that applies FDv2 payloads, and
the configuration that opts in. This completes the FDv2 work in
`common_client` — everything below the public Flutter API.
- **`FDv2DataSystem`** composes the data source factories the
`DataSourceManager` consumes. It owns the state that must outlive any
single orchestrator: the current selector and the context it belongs to.
A fresh orchestrator is built per connection-mode switch and per
identify; the selector survives mode switches (initializers are skipped
when a selector is already held) but resets when the context changes,
since a selector is specific to one context. `buildFactories()` returns
factories for streaming, polling, and background — offline has no data
source and is handled by the manager directly. Custom connection modes
from config replace the built-in definitions by name.
- **`DataSourceManager` payload routing.** The `PayloadEvent` case — a
no-op placeholder in the orchestrator PR — now applies the change set
through `handlePayload` and completes the pending identify, the same way
`DataEvent` does for FDv1.
- **Configuration & exposure.** `DataSystemConfig` (providing it, even
empty, opts into FDv2); `LDCommonConfig.dataSystem`; `LDCommonClient`
constructs an `FDv2DataSystem` and installs its factories when
`dataSystem` is configured, otherwise the FDv1 sources run unchanged;
and the new public types are exported.
When `dataSystem` is absent the FDv1 path is byte-for-byte unchanged, so
existing behavior is unaffected.
## Testing
- `DataSourceManager` test: a `PayloadEvent` is applied through
`handlePayload`, marks the source valid, and completes identify (a
dropped/no-op payload would leave identify hanging — this distinguishes
the real routing from the placeholder).
- `FDv2DataSystem` tests: `buildFactories` exposes
streaming/polling/background and not offline; each factory builds a
fresh data source per call; a custom connection mode replaces the
built-in definition.
- `DataSystemConfig` default (no custom modes).
- Full `common_client` suite passes; `flutter_client_sdk` (the dependent
package) analyzes and tests clean against these changes.
- End-to-end behavior of the wired data system is exercised by the FDv2
contract tests, which land with the contract-service changes in a later
PR (and pass on the integration branch today).
SDK-2186
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **High Risk**
> Touches core flag acquisition, identify completion,
connection-mode/offline behavior, and persistence read paths; incorrect
timing could leave identifies hanging or serve stale flags, though FDv1
remains unchanged when `dataSystem` is unset.
>
> **Overview**
> Opts the SDK into **FDv2** when `LDCommonConfig.dataSystem` is set
(even empty), exports `DataSystemConfig` / `ConnectionModeId` and
mode-definition types, and keeps the FDv1 path when `dataSystem` is
absent.
>
> **`FDv2DataSystem`** builds per-mode orchestrator factories
(streaming, polling, background, **offline** as a real cache-only
pipeline), holds the **selector** across mode switches, and applies
`connectionModes` overrides. **`FDv2DataManager`** clears the selector
on each identify and maps `waitForNetworkResults` to cached vs fresh
availability; FDv1 still loads cache at identify via
**`FDv1DataManager`**.
>
> **`DataSourceManager`** applies **`PayloadEvent`** through
`handlePayload`, sets **valid** on applied online payloads (including
no-change restores), does not promote valid in offline mode, and
completes identify on first applied data (cached) or
**`InitializedEvent`** (fresh). **`InitializedEvent`** and orchestrator
init semantics separate cache hits from network-ready state. Cache loads
use **`readCached`** without touching the store until the pipeline
applies payloads.
>
> Adds an **FDv1 fallback** synchronizer (FDv1 poll → FDv2 change sets)
with loop guards when already on fallback.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
194eae7. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent eb9a35f commit 61a1e59
26 files changed
Lines changed: 1316 additions & 76 deletions
File tree
- packages/common_client
- lib
- src
- config
- data_sources
- fdv2
- flag_manager
- test
- data_sources
- fdv2
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
9 | 24 | | |
10 | 25 | | |
11 | 26 | | |
| |||
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
34 | 41 | | |
35 | 42 | | |
36 | 43 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
| |||
Lines changed: 59 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
16 | 28 | | |
17 | 29 | | |
18 | 30 | | |
| |||
38 | 50 | | |
39 | 51 | | |
40 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
41 | 58 | | |
42 | 59 | | |
43 | 60 | | |
| |||
61 | 78 | | |
62 | 79 | | |
63 | 80 | | |
64 | | - | |
| 81 | + | |
| 82 | + | |
65 | 83 | | |
| 84 | + | |
66 | 85 | | |
67 | 86 | | |
68 | 87 | | |
| |||
92 | 111 | | |
93 | 112 | | |
94 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
95 | 127 | | |
96 | 128 | | |
97 | 129 | | |
| |||
126 | 158 | | |
127 | 159 | | |
128 | 160 | | |
129 | | - | |
130 | 161 | | |
131 | 162 | | |
132 | 163 | | |
| |||
146 | 177 | | |
147 | 178 | | |
148 | 179 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 180 | + | |
| 181 | + | |
158 | 182 | | |
159 | | - | |
160 | | - | |
161 | 183 | | |
162 | 184 | | |
163 | | - | |
164 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
165 | 209 | | |
166 | 210 | | |
167 | 211 | | |
| |||
0 commit comments