|
| 1 | +--- |
| 2 | +"@gusto/baerly-storage": minor |
| 3 | +--- |
| 4 | + |
| 5 | +Fix `Path<T>` walking `Array.prototype` for optional array fields; export |
| 6 | +`PredicateArg` / `Predicate` / `Collection` for consumers |
| 7 | + |
| 8 | +**Bug fix — optional array fields no longer poison predicate types** |
| 9 | + |
| 10 | +`Path<T>` (the dotted-path key type behind `Predicate<T>` / `.where(...)`) |
| 11 | +descended into `Array.prototype` when a field was an **optional** array. For a |
| 12 | +field `tags?: string[]`, the field type is `string[] | undefined`, and the |
| 13 | +`undefined` arm defeated the array-is-a-leaf check — so the path walker |
| 14 | +recursed into the array's methods and synthesized bogus keys like |
| 15 | +`` `tags.map.${string}` `` typed `undefined`. |
| 16 | + |
| 17 | +Required array fields (`tags: string[]`) were unaffected; only the optional |
| 18 | +form triggered it. |
| 19 | + |
| 20 | +The visible symptom: registering **any** collection with an optional array |
| 21 | +field (e.g. a Zod `z.array(z.string()).optional()`) broke structural |
| 22 | +assignability of a bound `Db<Config>` / `BaerlyClient<Config>` to a hand-rolled |
| 23 | +interface whose `collection(name: string)` takes a runtime string — because the |
| 24 | +generic collapses the row to the union of every row, and the synthetic |
| 25 | +`undefined`-typed prototype path made every index-signature predicate object |
| 26 | +non-assignable. Collections that never touched the array field were still |
| 27 | +affected. |
| 28 | + |
| 29 | +The fix runs the leaf test on `NonNullable<T[K]>`, so an optional array |
| 30 | +terminates path recursion exactly like a required one. `Path<{ tags?: string[] |
| 31 | +}>` is now `"tags"`, with no `Array.prototype` members. |
| 32 | + |
| 33 | +**New public exports** |
| 34 | + |
| 35 | +- `PredicateArg` and `Predicate` are now exported from `@gusto/baerly-storage`. |
| 36 | +- `PredicateArg` is now exported from `@gusto/baerly-storage/client` (which |
| 37 | + already exported `ClientCollection` and `Predicate`). The client handle type |
| 38 | + remains `ClientCollection`; the in-process `Collection` type is exported only |
| 39 | + from the root `@gusto/baerly-storage` entry, since the client's HTTP handle |
| 40 | + is structurally distinct (read-only `.where(...)`, `TerminalOptions`). |
| 41 | + |
| 42 | +These let consumers name the `.where(...)` argument and predicate types |
| 43 | +directly instead of hand-rolling a structural interface to accept a `Db` or a |
| 44 | +`BaerlyClient`. |
| 45 | + |
| 46 | +**Migration** |
| 47 | + |
| 48 | +- No action required. Both changes are additive; existing typed call sites are |
| 49 | + unaffected. |
| 50 | +- If you hand-rolled a structural `collection(name: string)` shim to read |
| 51 | + collections by a runtime-computed name, you can now either import the real |
| 52 | + types, or narrow at the boundary with |
| 53 | + `(db as Db<UnboundConfig>).collection(name)` to open the row to |
| 54 | + `DocumentData` for dynamic names. |
0 commit comments