TenantAtlas/apps/platform/.pnpm-store/v10/files/62/b1b263b5a78fba2643d2bf6df838212bdee10900c16fc70812cdad9d98da27e6d83a3550e1f6a64ff6348af0dd4e39713b820df1b16aff2ef1019d72d6caf8
ahmido 1fec9c6f9d
Some checks failed
Main Confidence / confidence (push) Failing after 45s
feat: compress governance operator outcomes (#253)
## Summary
- introduce surface-aware compressed governance outcomes and reuse the shared truth/explanation seams for operator-first summaries
- apply the compressed outcome hierarchy across baseline, evidence, review, review-pack, canonical review/evidence, and artifact-oriented operation-run surfaces
- expand spec 214 fixtures and Pest coverage, and fix tenant-panel route assertions by generating explicit tenant-panel URLs in the affected Filament tests

## Validation
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- focused governance compression suite from `specs/214-governance-outcome-compression/quickstart.md` passed (`68` tests, `445` assertions)
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Filament/InventoryItemResourceTest.php tests/Feature/Filament/BackupSetUiEnforcementTest.php tests/Feature/Filament/RestoreRunUiEnforcementTest.php` passed (`18` tests, `81` assertions)

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #253
2026-04-19 12:30:36 +00:00

93 lines
3.2 KiB
Plaintext

import { ObservableInput, OperatorFunction } from '../types';
import { operate } from '../util/lift';
import { mergeInternals } from './mergeInternals';
/**
* Applies an accumulator function over the source Observable where the
* accumulator function itself returns an Observable, then each intermediate
* Observable returned is merged into the output Observable.
*
* <span class="informal">It's like {@link scan}, but the Observables returned
* by the accumulator are merged into the outer Observable.</span>
*
* The first parameter of the `mergeScan` is an `accumulator` function which is
* being called every time the source Observable emits a value. `mergeScan` will
* subscribe to the value returned by the `accumulator` function and will emit
* values to the subscriber emitted by inner Observable.
*
* The `accumulator` function is being called with three parameters passed to it:
* `acc`, `value` and `index`. The `acc` parameter is used as the state parameter
* whose value is initially set to the `seed` parameter (the second parameter
* passed to the `mergeScan` operator).
*
* `mergeScan` internally keeps the value of the `acc` parameter: as long as the
* source Observable emits without inner Observable emitting, the `acc` will be
* set to `seed`. The next time the inner Observable emits a value, `mergeScan`
* will internally remember it and it will be passed to the `accumulator`
* function as `acc` parameter the next time source emits.
*
* The `value` parameter of the `accumulator` function is the value emitted by the
* source Observable, while the `index` is a number which represent the order of the
* current emission by the source Observable. It starts with 0.
*
* The last parameter to the `mergeScan` is the `concurrent` value which defaults
* to Infinity. It represents the maximum number of inner Observable subscriptions
* at a time.
*
* ## Example
*
* Count the number of click events
*
* ```ts
* import { fromEvent, map, mergeScan, of } from 'rxjs';
*
* const click$ = fromEvent(document, 'click');
* const one$ = click$.pipe(map(() => 1));
* const seed = 0;
* const count$ = one$.pipe(
* mergeScan((acc, one) => of(acc + one), seed)
* );
*
* count$.subscribe(x => console.log(x));
*
* // Results:
* // 1
* // 2
* // 3
* // 4
* // ...and so on for each click
* ```
*
* @see {@link scan}
* @see {@link switchScan}
*
* @param accumulator The accumulator function called on each source value.
* @param seed The initial accumulation value.
* @param concurrent Maximum number of input Observables being subscribed to
* concurrently.
* @return A function that returns an Observable of the accumulated values.
*/
export function mergeScan<T, R>(
accumulator: (acc: R, value: T, index: number) => ObservableInput<R>,
seed: R,
concurrent = Infinity
): OperatorFunction<T, R> {
return operate((source, subscriber) => {
// The accumulated state.
let state = seed;
return mergeInternals(
source,
subscriber,
(value, index) => accumulator(state, value, index),
concurrent,
(value) => {
state = value;
},
false,
undefined,
() => (state = null!)
);
});
}