Commit 42bce60
feat(js): add JavaScript/TypeScript WASM evaluator package (#110)
## Summary
Adds a TypeScript wrapper package (`@openfeature/flagd-wasm-evaluator`)
for the flagd-evaluator WASM module, following the same architecture as
the Java, Go, and .NET packages.
- **`FlagEvaluator` class** with async `create()` factory that loads and
instantiates the WASM module
- **Three-tier evaluation**: pre-evaluated cache → indexed path with
context filtering → full fallback
- **Pre-allocated WASM buffers** (256KB flag key + 1MB context) to
minimize allocation overhead
- **Context key filtering**: only serialize fields referenced by
targeting rules
- **Host function wiring**: timestamp, random values, wbindgen stubs
with prefix matching
- **18 Vitest tests** covering static flags, targeting, caching, error
handling, typed variants, fractional operator
- **Comparison benchmarks** vs `json-logic-engine` v4.0.2 AOT across 4
scenarios (simple, targeting, context sweep, mixed workload)
### Package structure
```
js/
├── src/
│ ├── evaluator.ts # FlagEvaluator class (206 lines)
│ ├── wasm-runtime.ts # WASM loading, memory helpers (156 lines)
│ ├── context.ts # Context serialization + filtering (49 lines)
│ └── types.ts # EvaluationResult, UpdateStateResult types (27 lines)
├── tests/
│ └── evaluator.test.ts # 18 test cases (228 lines)
├── benchmarks/
│ ├── comparison.bench.ts # 4-scenario benchmark suite
│ └── old-resolver.ts # json-logic-engine baseline
├── Makefile # wasm, build, test, bench targets
├── package.json # @openfeature/flagd-wasm-evaluator
└── tsconfig.json # ES2022, NodeNext, strict
```
## Test plan
- [ ] `cd js && make test` — 18 Vitest tests pass
- [ ] `cd js && make bench` — comparison benchmarks run
- [ ] `cd js && npx tsc --noEmit` — TypeScript compiles cleanly
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 46e25ef commit 42bce60
13 files changed
Lines changed: 2817 additions & 31 deletions
File tree
- .github/workflows
- js
- benchmarks
- src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
| |||
114 | 117 | | |
115 | 118 | | |
116 | 119 | | |
117 | | - | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
136 | | - | |
137 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
138 | 188 | | |
139 | 189 | | |
140 | 190 | | |
141 | 191 | | |
142 | 192 | | |
143 | 193 | | |
144 | | - | |
145 | | - | |
146 | 194 | | |
147 | 195 | | |
148 | 196 | | |
| |||
153 | 201 | | |
154 | 202 | | |
155 | 203 | | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | 204 | | |
162 | 205 | | |
163 | 206 | | |
164 | 207 | | |
165 | 208 | | |
166 | 209 | | |
167 | 210 | | |
168 | | - | |
| 211 | + | |
169 | 212 | | |
170 | 213 | | |
171 | 214 | | |
172 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
173 | 250 | | |
174 | 251 | | |
175 | 252 | | |
| 253 | + | |
176 | 254 | | |
177 | 255 | | |
178 | 256 | | |
| |||
184 | 262 | | |
185 | 263 | | |
186 | 264 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
| 265 | + | |
| 266 | + | |
194 | 267 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 268 | + | |
| 269 | + | |
204 | 270 | | |
205 | 271 | | |
206 | 272 | | |
207 | 273 | | |
208 | | - | |
209 | | - | |
| 274 | + | |
| 275 | + | |
210 | 276 | | |
211 | 277 | | |
212 | 278 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 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 | + | |
0 commit comments