TenantAtlas/apps/platform/.pnpm-store/v10/files/d8/6befb68017efe3f10b23b0c5b4fcd97d570e0293b9a7bdf8f73d9f441a43f296959b7eeae4eb601fe5d0d087c072438d6d8e32d7f75a6ed2a3fcb8d0fc068f
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

94 lines
3.5 KiB
Plaintext

import { Observable } from '../Observable';
import { EmptyError } from '../util/EmptyError';
import { OperatorFunction, TruthyTypesOf } from '../types';
import { filter } from './filter';
import { take } from './take';
import { defaultIfEmpty } from './defaultIfEmpty';
import { throwIfEmpty } from './throwIfEmpty';
import { identity } from '../util/identity';
export function first<T, D = T>(predicate?: null, defaultValue?: D): OperatorFunction<T, T | D>;
export function first<T>(predicate: BooleanConstructor): OperatorFunction<T, TruthyTypesOf<T>>;
export function first<T, D>(predicate: BooleanConstructor, defaultValue: D): OperatorFunction<T, TruthyTypesOf<T> | D>;
export function first<T, S extends T>(
predicate: (value: T, index: number, source: Observable<T>) => value is S,
defaultValue?: S
): OperatorFunction<T, S>;
export function first<T, S extends T, D>(
predicate: (value: T, index: number, source: Observable<T>) => value is S,
defaultValue: D
): OperatorFunction<T, S | D>;
export function first<T, D = T>(
predicate: (value: T, index: number, source: Observable<T>) => boolean,
defaultValue?: D
): OperatorFunction<T, T | D>;
/**
* Emits only the first value (or the first value that meets some condition)
* emitted by the source Observable.
*
* <span class="informal">Emits only the first value. Or emits only the first
* value that passes some test.</span>
*
* ![](first.png)
*
* If called with no arguments, `first` emits the first value of the source
* Observable, then completes. If called with a `predicate` function, `first`
* emits the first value of the source that matches the specified condition. Emits an error
* notification if `defaultValue` was not provided and a matching element is not found.
*
* ## Examples
*
* Emit only the first click that happens on the DOM
*
* ```ts
* import { fromEvent, first } from 'rxjs';
*
* const clicks = fromEvent(document, 'click');
* const result = clicks.pipe(first());
* result.subscribe(x => console.log(x));
* ```
*
* Emits the first click that happens on a DIV
*
* ```ts
* import { fromEvent, first } from 'rxjs';
*
* const div = document.createElement('div');
* div.style.cssText = 'width: 200px; height: 200px; background: #09c;';
* document.body.appendChild(div);
*
* const clicks = fromEvent(document, 'click');
* const result = clicks.pipe(first(ev => (<HTMLElement>ev.target).tagName === 'DIV'));
* result.subscribe(x => console.log(x));
* ```
*
* @see {@link filter}
* @see {@link find}
* @see {@link take}
* @see {@link last}
*
* @throws {EmptyError} Delivers an `EmptyError` to the Observer's `error`
* callback if the Observable completes before any `next` notification was sent.
* This is how `first()` is different from `take(1)` which completes instead.
*
* @param predicate An optional function called with each item to test for condition
* matching.
* @param defaultValue The default value emitted in case no valid value was found on
* the source.
* @return A function that returns an Observable that emits the first item that
* matches the condition.
*/
export function first<T, D>(
predicate?: ((value: T, index: number, source: Observable<T>) => boolean) | null,
defaultValue?: D
): OperatorFunction<T, T | D> {
const hasDefaultValue = arguments.length >= 2;
return (source: Observable<T>) =>
source.pipe(
predicate ? filter((v, i) => predicate(v, i, source)) : identity,
take(1),
hasDefaultValue ? defaultIfEmpty(defaultValue!) : throwIfEmpty(() => new EmptyError())
);
}