Commit 33973ed
authored
fix(toolsets): add accountIds option to StackOneToolSetConfig (#252)
* feat(toolsets): add accountIds option to StackOneToolSetConfig
Allow passing multiple account IDs when initialising StackOneToolSet
via the constructor, eliminating the need to call setAccounts()
separately after instantiation.
- Add accountIds property to StackOneToolSetConfig interface with
JSDoc documentation
- Initialise accountIds from config in constructor
- Update constructor JSDoc to reflect support for multiple account IDs
This change enables a more ergonomic API for multi-account setups:
```typescript
const toolset = new StackOneToolSet({
apiKey: 'key',
accountIds: ['acc1', 'acc2', 'acc3'],
});
```
Closes #251
* test(toolsets): add tests for accountIds constructor option
Add comprehensive tests verifying the new accountIds configuration:
- Test initialising with multiple account IDs from constructor
- Test default empty array when accountIds not provided
- Test coexistence of accountId and accountIds in constructor
- Test fetchTools uses constructor accountIds when present
- Test setAccounts() overrides constructor accountIds
These tests ensure accountIds from the constructor integrates
correctly with existing setAccounts() and fetchTools() behaviours.
* refactor(toolsets): use MergeExclusive for mutually exclusive account options
Use type-fest's MergeExclusive to enforce that either accountId (single)
or accountIds (multiple) can be provided, but not both simultaneously.
This improves type safety by catching invalid configurations at compile
time rather than runtime. The API now clearly communicates the intended
usage pattern through the type system.
Before (both allowed - confusing behaviour):
```typescript
new StackOneToolSet({
accountId: 'acc1',
accountIds: ['acc2', 'acc3'], // Which takes precedence?
});
```
After (type error - clear contract):
```typescript
// Valid: single account
new StackOneToolSet({ accountId: 'acc1' });
// Valid: multiple accounts
new StackOneToolSet({ accountIds: ['acc1', 'acc2'] });
// Type error: cannot use both
new StackOneToolSet({ accountId: 'acc1', accountIds: ['acc2'] });
```
* test(toolsets): update tests for MergeExclusive account config
Update test to verify that the type system enforces mutual exclusivity
between accountId and accountIds. Replace the test that allowed both
with a new test demonstrating the correct API usage patterns.
- Test single accountId configuration works correctly
- Test multiple accountIds configuration works correctly
- Document that combining both is a type error (prevented at compile time)
* test(toolsets): add type-level tests for StackOneToolSetConfig
Add comprehensive type tests using vitest's expectTypeOf to verify
the MergeExclusive behaviour of account configuration options:
- Test that accountId alone is valid
- Test that accountIds alone is valid
- Test that neither is valid (optional)
- Test that both together is rejected by the type system
- Verify accountId is typed as string | undefined
- Verify accountIds is typed as string[] | undefined
* refactor(toolset): use simplifyDeep
* feat(toolsets): add runtime validation for mutually exclusive account options
Add runtime check to throw ToolSetConfigError when both accountId and
accountIds are provided simultaneously. This protects JavaScript users
and scenarios where TypeScript is bypassed (e.g., using 'as any').
The validation uses != null to check for both null and undefined in a
single comparison, ensuring the error is thrown regardless of how the
invalid configuration is constructed.
* test(toolsets): add runtime validation test for mutually exclusive accounts
Add test to verify ToolSetConfigError is thrown when both accountId and
accountIds are provided at runtime. Uses 'as never' to bypass TypeScript
type checking and simulate JavaScript usage scenarios.1 parent b5defd8 commit 33973ed
3 files changed
+201
-5
lines changed| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
86 | 151 | | |
87 | 152 | | |
88 | 153 | | |
| |||
283 | 348 | | |
284 | 349 | | |
285 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
286 | 396 | | |
287 | 397 | | |
288 | 398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
92 | 121 | | |
93 | | - | |
| 122 | + | |
94 | 123 | | |
95 | | - | |
96 | 124 | | |
97 | 125 | | |
98 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
99 | 133 | | |
100 | 134 | | |
101 | 135 | | |
| |||
137 | 171 | | |
138 | 172 | | |
139 | 173 | | |
140 | | - | |
141 | | - | |
| 174 | + | |
| 175 | + | |
142 | 176 | | |
143 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
144 | 185 | | |
145 | 186 | | |
146 | 187 | | |
| |||
176 | 217 | | |
177 | 218 | | |
178 | 219 | | |
| 220 | + | |
179 | 221 | | |
180 | 222 | | |
181 | 223 | | |
| |||
0 commit comments