@g9tm/lynxcontrols-foundation 0.0.0-stage → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/collections.d.ts +16 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +40 -0
- package/dist/collections.js.map +1 -0
- package/dist/culture/calendar.d.ts +122 -0
- package/dist/culture/calendar.d.ts.map +1 -0
- package/dist/culture/calendar.js +379 -0
- package/dist/culture/calendar.js.map +1 -0
- package/dist/culture/culture.d.ts +91 -0
- package/dist/culture/culture.d.ts.map +1 -0
- package/dist/culture/culture.js +173 -0
- package/dist/culture/culture.js.map +1 -0
- package/dist/culture/date-format.d.ts +19 -0
- package/dist/culture/date-format.d.ts.map +1 -0
- package/dist/culture/date-format.js +101 -0
- package/dist/culture/date-format.js.map +1 -0
- package/dist/culture/digits.d.ts +29 -0
- package/dist/culture/digits.d.ts.map +1 -0
- package/dist/culture/digits.js +43 -0
- package/dist/culture/digits.js.map +1 -0
- package/dist/culture/duration.d.ts +38 -0
- package/dist/culture/duration.d.ts.map +1 -0
- package/dist/culture/duration.js +41 -0
- package/dist/culture/duration.js.map +1 -0
- package/dist/culture/index.d.ts +9 -0
- package/dist/culture/index.d.ts.map +1 -0
- package/dist/culture/index.js +8 -0
- package/dist/culture/numbers.d.ts +38 -0
- package/dist/culture/numbers.d.ts.map +1 -0
- package/dist/culture/numbers.js +64 -0
- package/dist/culture/numbers.js.map +1 -0
- package/dist/culture/relative-time.d.ts +50 -0
- package/dist/culture/relative-time.d.ts.map +1 -0
- package/dist/culture/relative-time.js +63 -0
- package/dist/culture/relative-time.js.map +1 -0
- package/dist/culture/strings.d.ts +145 -0
- package/dist/culture/strings.d.ts.map +1 -0
- package/dist/culture/strings.js +345 -0
- package/dist/culture/strings.js.map +1 -0
- package/dist/enums/index.d.ts +195 -0
- package/dist/enums/index.d.ts.map +1 -0
- package/dist/enums/index.js +130 -0
- package/dist/enums/index.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +21 -0
- package/dist/errors.js.map +1 -0
- package/dist/exec/diagnostics.d.ts +74 -0
- package/dist/exec/diagnostics.d.ts.map +1 -0
- package/dist/exec/diagnostics.js +73 -0
- package/dist/exec/diagnostics.js.map +1 -0
- package/dist/exec/index.d.ts +5 -0
- package/dist/exec/index.d.ts.map +1 -0
- package/dist/exec/index.js +4 -0
- package/dist/exec/options.d.ts +75 -0
- package/dist/exec/options.d.ts.map +1 -0
- package/dist/exec/options.js +107 -0
- package/dist/exec/options.js.map +1 -0
- package/dist/exec/safe-executor.d.ts +138 -0
- package/dist/exec/safe-executor.d.ts.map +1 -0
- package/dist/exec/safe-executor.js +401 -0
- package/dist/exec/safe-executor.js.map +1 -0
- package/dist/exec/trace.d.ts +59 -0
- package/dist/exec/trace.d.ts.map +1 -0
- package/dist/exec/trace.js +108 -0
- package/dist/exec/trace.js.map +1 -0
- package/dist/icons/generated/glyph-svg.d.ts +37 -0
- package/dist/icons/generated/glyph-svg.d.ts.map +1 -0
- package/dist/icons/generated/glyph-svg.js +33 -0
- package/dist/icons/generated/glyph-svg.js.map +1 -0
- package/dist/icons/glyph-slots.d.ts +79 -0
- package/dist/icons/glyph-slots.d.ts.map +1 -0
- package/dist/icons/glyph-slots.js +50 -0
- package/dist/icons/glyph-slots.js.map +1 -0
- package/dist/icons/glyph.d.ts +76 -0
- package/dist/icons/glyph.d.ts.map +1 -0
- package/dist/icons/glyph.js +42 -0
- package/dist/icons/glyph.js.map +1 -0
- package/dist/icons/icon-fonts.d.ts +55 -0
- package/dist/icons/icon-fonts.d.ts.map +1 -0
- package/dist/icons/icon-fonts.js +74 -0
- package/dist/icons/icon-fonts.js.map +1 -0
- package/dist/icons/icon.d.ts +102 -0
- package/dist/icons/icon.d.ts.map +1 -0
- package/dist/icons/icon.js +132 -0
- package/dist/icons/icon.js.map +1 -0
- package/dist/icons/index.d.ts +7 -0
- package/dist/icons/index.d.ts.map +1 -0
- package/dist/icons/index.js +6 -0
- package/dist/icons/svg.d.ts +28 -0
- package/dist/icons/svg.d.ts.map +1 -0
- package/dist/icons/svg.js +59 -0
- package/dist/icons/svg.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/services/abort.d.ts +31 -0
- package/dist/services/abort.d.ts.map +1 -0
- package/dist/services/abort.js +47 -0
- package/dist/services/abort.js.map +1 -0
- package/dist/services/clock.d.ts +35 -0
- package/dist/services/clock.d.ts.map +1 -0
- package/dist/services/clock.js +37 -0
- package/dist/services/clock.js.map +1 -0
- package/dist/services/contracts.d.ts +200 -0
- package/dist/services/contracts.d.ts.map +1 -0
- package/dist/services/contracts.js +37 -0
- package/dist/services/contracts.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +4 -0
- package/dist/services/preferences.d.ts +105 -0
- package/dist/services/preferences.d.ts.map +1 -0
- package/dist/services/preferences.js +253 -0
- package/dist/services/preferences.js.map +1 -0
- package/dist/theme/color.d.ts +94 -0
- package/dist/theme/color.d.ts.map +1 -0
- package/dist/theme/color.js +150 -0
- package/dist/theme/color.js.map +1 -0
- package/dist/theme/control-colors.d.ts +46 -0
- package/dist/theme/control-colors.d.ts.map +1 -0
- package/dist/theme/control-colors.js +46 -0
- package/dist/theme/control-colors.js.map +1 -0
- package/dist/theme/index.d.ts +5 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +4 -0
- package/dist/theme/theme.d.ts +88 -0
- package/dist/theme/theme.d.ts.map +1 -0
- package/dist/theme/theme.js +190 -0
- package/dist/theme/theme.js.map +1 -0
- package/dist/theme/variants.d.ts +33 -0
- package/dist/theme/variants.d.ts.map +1 -0
- package/dist/theme/variants.js +53 -0
- package/dist/theme/variants.js.map +1 -0
- package/dist/tokens/css-vars.d.ts +41 -0
- package/dist/tokens/css-vars.d.ts.map +1 -0
- package/dist/tokens/css-vars.js +55 -0
- package/dist/tokens/css-vars.js.map +1 -0
- package/dist/tokens/generated/metrics.d.ts +184 -0
- package/dist/tokens/generated/metrics.d.ts.map +1 -0
- package/dist/tokens/generated/metrics.js +349 -0
- package/dist/tokens/generated/metrics.js.map +1 -0
- package/dist/tokens/generated/palettes.d.ts +113 -0
- package/dist/tokens/generated/palettes.d.ts.map +1 -0
- package/dist/tokens/generated/palettes.js +391 -0
- package/dist/tokens/generated/palettes.js.map +1 -0
- package/dist/tokens/index.d.ts +5 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +4 -0
- package/dist/tokens/layout-metrics.d.ts +120 -0
- package/dist/tokens/layout-metrics.d.ts.map +1 -0
- package/dist/tokens/layout-metrics.js +111 -0
- package/dist/tokens/layout-metrics.js.map +1 -0
- package/docs/api.md +369 -0
- package/docs/foundation.md +370 -0
- package/docs/migration/Core.Controls.Shared.md +475 -0
- package/docs/migration/Core.Helpers.md +132 -0
- package/docs/migration/Core.Icons.md +135 -0
- package/docs/migration/Core.Localization.md +118 -0
- package/docs/migration/Core.Storage.md +54 -0
- package/docs/migration/Core.Theming.md +328 -0
- package/package.json +59 -4
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { G9StringKey } from '../culture/strings.js';
|
|
2
|
+
import { type G9AbortSignal } from '../services/abort.js';
|
|
3
|
+
import { type G9Clock } from '../services/clock.js';
|
|
4
|
+
import { type G9Diagnostics, type G9DiagnosticsReport } from './diagnostics.js';
|
|
5
|
+
import { type G9SafeExecutorOptions } from './options.js';
|
|
6
|
+
import { type G9OperationTrace } from './trace.js';
|
|
7
|
+
/** What a guarded action receives. */
|
|
8
|
+
export interface G9SafeRunContext {
|
|
9
|
+
/** Aborted on timeout, on the caller's signal, or when the executor is disposed (unmount). */
|
|
10
|
+
readonly signal: G9AbortSignal;
|
|
11
|
+
/** Step log for the "More details" report. */
|
|
12
|
+
readonly trace: G9OperationTrace;
|
|
13
|
+
readonly key: string;
|
|
14
|
+
readonly source: string;
|
|
15
|
+
}
|
|
16
|
+
/** A guarded action. It may be synchronous; it then runs inside `run()` itself when there is no delay. */
|
|
17
|
+
export type G9SafeAction<T> = (context: G9SafeRunContext) => T | PromiseLike<T>;
|
|
18
|
+
/**
|
|
19
|
+
* How a run ended. Expected outcomes are results (specs/03 §7); `failed` carries the error and the report that was
|
|
20
|
+
* routed to diagnostics, `onError` and the popup.
|
|
21
|
+
*/
|
|
22
|
+
export type G9SafeRunResult<T> = {
|
|
23
|
+
readonly status: 'completed';
|
|
24
|
+
readonly value: T;
|
|
25
|
+
} | {
|
|
26
|
+
readonly status: 'skipped';
|
|
27
|
+
readonly reason: 'throttled' | 'concurrent' | 'disposed';
|
|
28
|
+
} | {
|
|
29
|
+
readonly status: 'cancelled';
|
|
30
|
+
readonly reason: 'aborted' | 'disposed';
|
|
31
|
+
} | {
|
|
32
|
+
readonly status: 'failed';
|
|
33
|
+
/** `error`: the action threw; `timeout`: `timeoutMs` elapsed; `reported`: the action called `trace.fail`. */
|
|
34
|
+
readonly reason: 'error' | 'timeout' | 'reported';
|
|
35
|
+
/** The thrown value (a `G9Error` with code `safe-timeout` for a timeout); `undefined` for `reported`. */
|
|
36
|
+
readonly error: unknown;
|
|
37
|
+
readonly report: G9DiagnosticsReport;
|
|
38
|
+
};
|
|
39
|
+
/** What the host's error presenter shows (MAUI's error popup with OK and the optional "More details"). */
|
|
40
|
+
export interface G9ErrorPopupRequest {
|
|
41
|
+
readonly title: string;
|
|
42
|
+
readonly message: string;
|
|
43
|
+
/** Text of the closing button (the `Ok` string). */
|
|
44
|
+
readonly okText: string;
|
|
45
|
+
readonly source: string;
|
|
46
|
+
readonly diagnosticsText: string | null;
|
|
47
|
+
readonly exceptions: ReadonlyArray<unknown> | null;
|
|
48
|
+
/**
|
|
49
|
+
* Present only when a `diagnosticsHandler` is configured and `diagnosticsAvailable` (asked per popup) allows it.
|
|
50
|
+
* `open()` hands the report to the handler; it never rejects.
|
|
51
|
+
*/
|
|
52
|
+
readonly moreDetails: {
|
|
53
|
+
readonly text: string;
|
|
54
|
+
open(): Promise<void>;
|
|
55
|
+
} | null;
|
|
56
|
+
}
|
|
57
|
+
/** Busy state of an executor, for a control's spinner. */
|
|
58
|
+
export interface G9SafeExecutorSnapshot {
|
|
59
|
+
/** `'busy'` while at least one action runs (after its delay), `'disposed'` once disposed. */
|
|
60
|
+
readonly state: 'idle' | 'busy' | 'disposed';
|
|
61
|
+
/** Number of actions currently running. */
|
|
62
|
+
readonly running: number;
|
|
63
|
+
}
|
|
64
|
+
/** Timer functions; default the runtime's `setTimeout`/`clearTimeout`. */
|
|
65
|
+
export interface G9Timers {
|
|
66
|
+
setTimeout(callback: () => void, ms: number): unknown;
|
|
67
|
+
clearTimeout(handle: unknown): void;
|
|
68
|
+
}
|
|
69
|
+
/** Configuration of {@link createSafeExecutor}; the WP02 provider fills it from its services and settings. */
|
|
70
|
+
export interface G9SafeExecutorConfig {
|
|
71
|
+
/** Monotonic time for throttling and elapsed times, wall time for reports. Default: the system clock. */
|
|
72
|
+
readonly clock?: G9Clock;
|
|
73
|
+
/** Observation seam: started/completed/failed events and log lines. Default: none. */
|
|
74
|
+
readonly diagnostics?: G9Diagnostics;
|
|
75
|
+
/** Localised defaults for the popup (`Error`, `Ok`, `MoreDetails`, `UnexpectedError`). Default: English. */
|
|
76
|
+
readonly strings?: {
|
|
77
|
+
get(key: G9StringKey): string;
|
|
78
|
+
};
|
|
79
|
+
/** Shows the error popup; the run waits for it, as MAUI awaited its popup. Without it nothing can be shown. */
|
|
80
|
+
readonly showError?: (request: G9ErrorPopupRequest) => void | PromiseLike<void>;
|
|
81
|
+
/** The app's "More details" surface (MAUI `G9SafeCommand.DiagnosticsHandler`). */
|
|
82
|
+
readonly diagnosticsHandler?: (report: G9DiagnosticsReport) => void | PromiseLike<void>;
|
|
83
|
+
/** Per-popup gate for "More details" (MAUI `DiagnosticsAvailable`). Default: available. A throwing gate hides it. */
|
|
84
|
+
readonly diagnosticsAvailable?: () => boolean;
|
|
85
|
+
/** Executor-wide option defaults (applied over the MAUI defaults, under per-run options). */
|
|
86
|
+
readonly defaults?: G9SafeExecutorOptions;
|
|
87
|
+
readonly timers?: G9Timers;
|
|
88
|
+
}
|
|
89
|
+
/** Options of {@link G9SafeExecutor.showOperationError}. */
|
|
90
|
+
export interface G9ShowOperationErrorOptions {
|
|
91
|
+
readonly title?: string | null;
|
|
92
|
+
readonly diagnosticsText?: string | null;
|
|
93
|
+
readonly exceptions?: ReadonlyArray<unknown> | null;
|
|
94
|
+
readonly source?: string | null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The one guarded-execution state machine (MAUI `G9SafeCommand`, specs/03 §4): throttle and same-key concurrency
|
|
98
|
+
* guards, optional delay, busy reporting, trace, timeout, cancellation, error routing (diagnostics → `onError` → popup
|
|
99
|
+
* → optional rethrow, all after the guards are released). Every run settles its promise exactly once.
|
|
100
|
+
*/
|
|
101
|
+
export interface G9SafeExecutor {
|
|
102
|
+
/**
|
|
103
|
+
* Runs `action` under the guards. Per run: skipped (throttled, concurrent, disposed) → [delay] → `setBusy(true)`,
|
|
104
|
+
* `operationStarted` → action → `operationCompleted`, `setBusy(false)`, guards released → on failure:
|
|
105
|
+
* `operationFailed`, `onError` (errors and timeouts), popup (when enabled), rethrow (when enabled).
|
|
106
|
+
* Rejects only for invalid options (`G9Error` `safe-options`) or when `rethrow` is set and the action failed.
|
|
107
|
+
*/
|
|
108
|
+
run<T>(action: G9SafeAction<T>, options?: G9SafeExecutorOptions): Promise<G9SafeRunResult<T>>;
|
|
109
|
+
/** Fire-and-forget `run` (MAUI `RunSafe`): a rethrown error is logged, never left unobserved. */
|
|
110
|
+
runSafe(action: G9SafeAction<unknown>, options?: G9SafeExecutorOptions): void;
|
|
111
|
+
/** Shows an error through the presenter (MAUI `ShowOperationErrorAsync`). Blank messages show nothing. Never rejects. */
|
|
112
|
+
showOperationError(message: string, options?: G9ShowOperationErrorOptions): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* `true` when `key` may run now, recording the attempt (MAUI `TryThrottle`). Monotonic time, so a device-clock
|
|
115
|
+
* correction cannot disable buttons. Stale entries (older than a minute) are cleaned up.
|
|
116
|
+
* @throws {G9Error} `safe-options` for a blank key.
|
|
117
|
+
*/
|
|
118
|
+
tryThrottle(key: string, minIntervalMs?: number): boolean;
|
|
119
|
+
/** Clears throttle and in-flight state (MAUI `ResetThrottle`; testing, logout). */
|
|
120
|
+
resetThrottle(): void;
|
|
121
|
+
/** Whether a run with this key holds the concurrency guard. */
|
|
122
|
+
isRunning(key: string): boolean;
|
|
123
|
+
getSnapshot(): G9SafeExecutorSnapshot;
|
|
124
|
+
subscribe(listener: (snapshot: G9SafeExecutorSnapshot) => void): () => void;
|
|
125
|
+
/**
|
|
126
|
+
* Aborts every run (their promises settle at once as cancelled/disposed, busy is reset, `operationCompleted`
|
|
127
|
+
* fires) and makes later runs skip. A late completion of an aborted action is ignored. Idempotent.
|
|
128
|
+
*/
|
|
129
|
+
dispose(): void;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The runtime's timers, safe on every Lynx thread host (bundle-scope identifiers, not `globalThis` properties). Every G9
|
|
133
|
+
* timer goes through this or an injected {@link G9Timers}.
|
|
134
|
+
*/
|
|
135
|
+
export declare const g9RuntimeTimers: G9Timers;
|
|
136
|
+
/** Creates a {@link G9SafeExecutor}. One per control or screen; dispose it on unmount. */
|
|
137
|
+
export declare function createSafeExecutor(config?: G9SafeExecutorConfig): G9SafeExecutor;
|
|
138
|
+
//# sourceMappingURL=safe-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-executor.d.ts","sourceRoot":"","sources":["../../src/exec/safe-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,oBAAoB,CAAC;AAEnE,OAAO,EAA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AAO,CAAC,IAAI,CAAC,CAAC;IAC1F;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1D,mFAAmF;IACnF,aAAa,IAAI,IAAI,CAAC;IACtB,+DAA+D;IAC/D,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,WAAW,IAAI,sBAAsB,CAAC;IACtC,SAAS,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,sBAAsB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5E;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAWD;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,QAG5B,CAAC;AAoBH,0FAA0F;AAC1F,wBAAgB,kBAAkB,CAAC,MAAM,GAAE,oBAAyB,GAAG,cAAc,CAsYpF"}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { G9StringKey, g9EnglishStrings } from "../culture/strings.js";
|
|
2
|
+
import { G9Error } from "../errors.js";
|
|
3
|
+
import { createAbortController, createAbortError, isAbortError } from "../services/abort.js";
|
|
4
|
+
import { createSystemClock } from "../services/clock.js";
|
|
5
|
+
import { createDiagnosticsReport } from "./diagnostics.js";
|
|
6
|
+
import { g9DefaultSafeExecutorOptions, resolveExecutionDelay, resolveSafeExecutorOptions } from "./options.js";
|
|
7
|
+
import { createOperationTrace } from "./trace.js";
|
|
8
|
+
const CLEANUP_THRESHOLD_MS = 60000;
|
|
9
|
+
const g9RuntimeTimers = Object.freeze({
|
|
10
|
+
setTimeout: (callback, ms)=>setTimeout(callback, ms),
|
|
11
|
+
clearTimeout: (handle)=>clearTimeout(handle)
|
|
12
|
+
});
|
|
13
|
+
const defaultTimers = g9RuntimeTimers;
|
|
14
|
+
const englishStrings = {
|
|
15
|
+
get: (key)=>g9EnglishStrings[key]
|
|
16
|
+
};
|
|
17
|
+
function isThenable(value) {
|
|
18
|
+
return ('object' == typeof value || 'function' == typeof value) && null !== value && 'function' == typeof value.then;
|
|
19
|
+
}
|
|
20
|
+
function createSafeExecutor(config = {}) {
|
|
21
|
+
var _config_clock, _config_strings, _config_timers;
|
|
22
|
+
const clock = null != (_config_clock = config.clock) ? _config_clock : createSystemClock();
|
|
23
|
+
const diagnostics = config.diagnostics;
|
|
24
|
+
const strings = null != (_config_strings = config.strings) ? _config_strings : englishStrings;
|
|
25
|
+
const timers = null != (_config_timers = config.timers) ? _config_timers : defaultTimers;
|
|
26
|
+
const base = resolveSafeExecutorOptions(config.defaults, g9DefaultSafeExecutorOptions);
|
|
27
|
+
const throttleStamps = new Map();
|
|
28
|
+
const inFlight = new Set();
|
|
29
|
+
const active = new Set();
|
|
30
|
+
const listeners = new Set();
|
|
31
|
+
let lastCleanup = clock.monotonicNow();
|
|
32
|
+
let running = 0;
|
|
33
|
+
let disposed = false;
|
|
34
|
+
let snapshot = Object.freeze({
|
|
35
|
+
state: 'idle',
|
|
36
|
+
running: 0
|
|
37
|
+
});
|
|
38
|
+
const observe = (call)=>{
|
|
39
|
+
if (!diagnostics) return;
|
|
40
|
+
try {
|
|
41
|
+
call(diagnostics);
|
|
42
|
+
} catch {}
|
|
43
|
+
};
|
|
44
|
+
const text = (key)=>{
|
|
45
|
+
try {
|
|
46
|
+
const value = strings.get(key);
|
|
47
|
+
return 'string' == typeof value ? value : g9EnglishStrings[key];
|
|
48
|
+
} catch {
|
|
49
|
+
return g9EnglishStrings[key];
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const log = (level, message, source, key, error)=>{
|
|
53
|
+
observe((hub)=>hub.log({
|
|
54
|
+
level,
|
|
55
|
+
message,
|
|
56
|
+
...void 0 === source ? {} : {
|
|
57
|
+
source
|
|
58
|
+
},
|
|
59
|
+
...void 0 === key ? {} : {
|
|
60
|
+
key
|
|
61
|
+
},
|
|
62
|
+
...void 0 === error ? {} : {
|
|
63
|
+
error
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
};
|
|
67
|
+
const publish = ()=>{
|
|
68
|
+
const state = disposed ? 'disposed' : running > 0 ? 'busy' : 'idle';
|
|
69
|
+
if (snapshot.state === state && snapshot.running === running) return;
|
|
70
|
+
snapshot = Object.freeze({
|
|
71
|
+
state,
|
|
72
|
+
running
|
|
73
|
+
});
|
|
74
|
+
for (const listener of [
|
|
75
|
+
...listeners
|
|
76
|
+
])try {
|
|
77
|
+
listener(snapshot);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
log('error', 'Executor subscriber threw', void 0, void 0, error);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const safeSetBusy = (opts, busy)=>{
|
|
83
|
+
if (!opts.setBusy) return;
|
|
84
|
+
try {
|
|
85
|
+
opts.setBusy(busy);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
log('error', `setBusy(${busy}) callback failed`, opts.source, opts.throttleKey, error);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const isDiagnosticsAvailable = ()=>{
|
|
91
|
+
const gate = config.diagnosticsAvailable;
|
|
92
|
+
if (!gate) return true;
|
|
93
|
+
try {
|
|
94
|
+
return true === gate();
|
|
95
|
+
} catch (error) {
|
|
96
|
+
log('warning', 'Diagnostics availability gate threw; hiding the More details button', void 0, void 0, error);
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const showOperationError = async (message, options = {})=>{
|
|
101
|
+
if ('string' != typeof message || '' === message.trim()) return;
|
|
102
|
+
const present = config.showError;
|
|
103
|
+
if (!present) {
|
|
104
|
+
var _options_source;
|
|
105
|
+
log('warning', `No error presenter is configured; not shown: ${message}`, null != (_options_source = options.source) ? _options_source : void 0);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
var _options_source1, _options_diagnosticsText, _options_exceptions, _options_title;
|
|
110
|
+
const handler = config.diagnosticsHandler;
|
|
111
|
+
const source = null != (_options_source1 = options.source) ? _options_source1 : 'Unknown';
|
|
112
|
+
const diagnosticsText = null != (_options_diagnosticsText = options.diagnosticsText) ? _options_diagnosticsText : null;
|
|
113
|
+
const exceptions = null != (_options_exceptions = options.exceptions) ? _options_exceptions : null;
|
|
114
|
+
const moreDetails = handler && isDiagnosticsAvailable() ? {
|
|
115
|
+
text: text(G9StringKey.MoreDetails),
|
|
116
|
+
open: async ()=>{
|
|
117
|
+
try {
|
|
118
|
+
await handler(createDiagnosticsReport(source, message, diagnosticsText, exceptions));
|
|
119
|
+
} catch (error) {
|
|
120
|
+
log('error', 'Diagnostics handler threw', void 0, void 0, error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} : null;
|
|
124
|
+
await present(Object.freeze({
|
|
125
|
+
title: null != (_options_title = options.title) ? _options_title : text(G9StringKey.Error),
|
|
126
|
+
message,
|
|
127
|
+
okText: text(G9StringKey.Ok),
|
|
128
|
+
source,
|
|
129
|
+
diagnosticsText,
|
|
130
|
+
exceptions,
|
|
131
|
+
moreDetails
|
|
132
|
+
}));
|
|
133
|
+
} catch (error) {
|
|
134
|
+
log('error', 'Failed to show error popup', void 0, void 0, error);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const tryThrottle = (key, minIntervalMs)=>{
|
|
138
|
+
if ('string' != typeof key || '' === key.trim()) throw new G9Error('safe-options', 'Key cannot be empty.');
|
|
139
|
+
const interval = void 0 === minIntervalMs ? g9DefaultSafeExecutorOptions.throttleIntervalMs : resolveSafeExecutorOptions({
|
|
140
|
+
throttleIntervalMs: minIntervalMs
|
|
141
|
+
}).throttleIntervalMs;
|
|
142
|
+
const now = clock.monotonicNow();
|
|
143
|
+
const last = throttleStamps.get(key);
|
|
144
|
+
const allowed = void 0 === last || now - last >= interval;
|
|
145
|
+
if (allowed) throttleStamps.set(key, now);
|
|
146
|
+
if (now - lastCleanup > CLEANUP_THRESHOLD_MS) {
|
|
147
|
+
lastCleanup = now;
|
|
148
|
+
const threshold = now - CLEANUP_THRESHOLD_MS;
|
|
149
|
+
for (const [k, stamp] of throttleStamps)if (stamp < threshold) throttleStamps.delete(k);
|
|
150
|
+
}
|
|
151
|
+
return allowed;
|
|
152
|
+
};
|
|
153
|
+
async function report(opts, failure) {
|
|
154
|
+
const { source, throttleKey: key } = opts;
|
|
155
|
+
const hasError = 'reported' !== failure.reason;
|
|
156
|
+
const diagnosticsReport = createDiagnosticsReport(`${source}/${key}`, failure.userMessage, failure.diagnostics, hasError ? [
|
|
157
|
+
failure.error
|
|
158
|
+
] : []);
|
|
159
|
+
observe((hub)=>hub.raiseOperationFailed(diagnosticsReport));
|
|
160
|
+
if (hasError && opts.onError) try {
|
|
161
|
+
await opts.onError(failure.error);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
log('error', 'OnError callback failed', source, key, error);
|
|
164
|
+
}
|
|
165
|
+
if (opts.showErrorPopup) await showOperationError(failure.userMessage, {
|
|
166
|
+
title: opts.errorTitle,
|
|
167
|
+
diagnosticsText: failure.diagnostics,
|
|
168
|
+
source
|
|
169
|
+
});
|
|
170
|
+
if (hasError && opts.rethrow) throw failure.error;
|
|
171
|
+
return Object.freeze({
|
|
172
|
+
status: 'failed',
|
|
173
|
+
reason: failure.reason,
|
|
174
|
+
error: failure.error,
|
|
175
|
+
report: diagnosticsReport
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function run(action, options) {
|
|
179
|
+
var _opts_signal;
|
|
180
|
+
let opts;
|
|
181
|
+
try {
|
|
182
|
+
if ('function' != typeof action) throw new G9Error('safe-options', 'action must be a function.');
|
|
183
|
+
opts = resolveSafeExecutorOptions(options, base);
|
|
184
|
+
} catch (error) {
|
|
185
|
+
return Promise.reject(error);
|
|
186
|
+
}
|
|
187
|
+
const { source, throttleKey: key } = opts;
|
|
188
|
+
if (disposed) return Promise.resolve(Object.freeze({
|
|
189
|
+
status: 'skipped',
|
|
190
|
+
reason: 'disposed'
|
|
191
|
+
}));
|
|
192
|
+
if (null == (_opts_signal = opts.signal) ? void 0 : _opts_signal.aborted) return Promise.resolve(Object.freeze({
|
|
193
|
+
status: 'cancelled',
|
|
194
|
+
reason: 'aborted'
|
|
195
|
+
}));
|
|
196
|
+
if (opts.enableThrottle && !tryThrottle(key, opts.throttleIntervalMs)) {
|
|
197
|
+
log('debug', 'Operation skipped by throttle guard', source, key);
|
|
198
|
+
return Promise.resolve(Object.freeze({
|
|
199
|
+
status: 'skipped',
|
|
200
|
+
reason: 'throttled'
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
if (opts.preventConcurrentExecution) {
|
|
204
|
+
if (inFlight.has(key)) {
|
|
205
|
+
log('debug', 'Operation skipped by concurrent guard', source, key);
|
|
206
|
+
return Promise.resolve(Object.freeze({
|
|
207
|
+
status: 'skipped',
|
|
208
|
+
reason: 'concurrent'
|
|
209
|
+
}));
|
|
210
|
+
}
|
|
211
|
+
inFlight.add(key);
|
|
212
|
+
}
|
|
213
|
+
return new Promise((resolve, reject)=>{
|
|
214
|
+
var _opts_signal;
|
|
215
|
+
const controller = createAbortController();
|
|
216
|
+
const trace = createOperationTrace(key, source, {
|
|
217
|
+
clock,
|
|
218
|
+
log: (entry)=>observe((hub)=>hub.log(entry))
|
|
219
|
+
});
|
|
220
|
+
const context = Object.freeze({
|
|
221
|
+
signal: controller.signal,
|
|
222
|
+
trace,
|
|
223
|
+
key,
|
|
224
|
+
source
|
|
225
|
+
});
|
|
226
|
+
let phase = 'delaying';
|
|
227
|
+
let startedAt = 0;
|
|
228
|
+
let delayTimer = null;
|
|
229
|
+
let timeoutTimer = null;
|
|
230
|
+
const onExternalAbort = ()=>settle({
|
|
231
|
+
kind: 'cancelled',
|
|
232
|
+
reason: 'aborted'
|
|
233
|
+
});
|
|
234
|
+
const stopTimers = ()=>{
|
|
235
|
+
if (null !== delayTimer) timers.clearTimeout(delayTimer);
|
|
236
|
+
if (null !== timeoutTimer) timers.clearTimeout(timeoutTimer);
|
|
237
|
+
delayTimer = timeoutTimer = null;
|
|
238
|
+
};
|
|
239
|
+
function settle(outcome) {
|
|
240
|
+
var _opts_signal;
|
|
241
|
+
if ('settled' === phase) return;
|
|
242
|
+
const wasRunning = 'running' === phase;
|
|
243
|
+
phase = 'settled';
|
|
244
|
+
stopTimers();
|
|
245
|
+
null == (_opts_signal = opts.signal) || _opts_signal.removeEventListener('abort', onExternalAbort);
|
|
246
|
+
active.delete(abortRun);
|
|
247
|
+
if ('cancelled' === outcome.kind || 'failed' === outcome.kind && 'timeout' === outcome.failure.reason) {
|
|
248
|
+
var _ref;
|
|
249
|
+
var _opts_signal1;
|
|
250
|
+
controller.abort('failed' === outcome.kind ? outcome.failure.error : 'disposed' === outcome.reason ? createAbortError('The safe executor was disposed.') : null != (_ref = null == (_opts_signal1 = opts.signal) ? void 0 : _opts_signal1.reason) ? _ref : createAbortError());
|
|
251
|
+
}
|
|
252
|
+
if (wasRunning) {
|
|
253
|
+
observe((hub)=>hub.raiseOperationCompleted(source, key, clock.monotonicNow() - startedAt));
|
|
254
|
+
running--;
|
|
255
|
+
safeSetBusy(opts, false);
|
|
256
|
+
}
|
|
257
|
+
if (opts.preventConcurrentExecution) inFlight.delete(key);
|
|
258
|
+
publish();
|
|
259
|
+
if ('completed' === outcome.kind) resolve(Object.freeze({
|
|
260
|
+
status: 'completed',
|
|
261
|
+
value: outcome.value
|
|
262
|
+
}));
|
|
263
|
+
else if ('cancelled' === outcome.kind) {
|
|
264
|
+
log('disposed' === outcome.reason ? 'warning' : 'debug', `Operation cancelled (${outcome.reason})`, source, key);
|
|
265
|
+
resolve(Object.freeze({
|
|
266
|
+
status: 'cancelled',
|
|
267
|
+
reason: outcome.reason
|
|
268
|
+
}));
|
|
269
|
+
} else report(opts, outcome.failure).then(resolve, reject);
|
|
270
|
+
}
|
|
271
|
+
function abortRun(why) {
|
|
272
|
+
settle({
|
|
273
|
+
kind: 'cancelled',
|
|
274
|
+
reason: why
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
const buildReport = (error)=>{
|
|
278
|
+
try {
|
|
279
|
+
return trace.buildReport(error);
|
|
280
|
+
} catch {
|
|
281
|
+
return 'Failed to build diagnostics report.';
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
const onSuccess = (value)=>{
|
|
285
|
+
if ('running' !== phase) return;
|
|
286
|
+
const reported = trace.failure;
|
|
287
|
+
if (reported) {
|
|
288
|
+
var _reported_diagnostics;
|
|
289
|
+
settle({
|
|
290
|
+
kind: 'failed',
|
|
291
|
+
failure: {
|
|
292
|
+
reason: 'reported',
|
|
293
|
+
error: void 0,
|
|
294
|
+
userMessage: reported.userMessage,
|
|
295
|
+
diagnostics: null != (_reported_diagnostics = reported.diagnostics) ? _reported_diagnostics : buildReport()
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
} else settle({
|
|
299
|
+
kind: 'completed',
|
|
300
|
+
value
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
const onFailure = (error)=>{
|
|
304
|
+
var _opts_errorMessage;
|
|
305
|
+
if ('running' !== phase) return;
|
|
306
|
+
if (isAbortError(error)) return void settle({
|
|
307
|
+
kind: 'cancelled',
|
|
308
|
+
reason: 'aborted'
|
|
309
|
+
});
|
|
310
|
+
trace.error('Unhandled exception', error);
|
|
311
|
+
settle({
|
|
312
|
+
kind: 'failed',
|
|
313
|
+
failure: {
|
|
314
|
+
reason: 'error',
|
|
315
|
+
error,
|
|
316
|
+
userMessage: null != (_opts_errorMessage = opts.errorMessage) ? _opts_errorMessage : text(G9StringKey.UnexpectedError),
|
|
317
|
+
diagnostics: buildReport(error)
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
const start = ()=>{
|
|
322
|
+
delayTimer = null;
|
|
323
|
+
if ('delaying' !== phase) return;
|
|
324
|
+
phase = 'running';
|
|
325
|
+
running++;
|
|
326
|
+
safeSetBusy(opts, true);
|
|
327
|
+
publish();
|
|
328
|
+
observe((hub)=>hub.raiseOperationStarted(source, key));
|
|
329
|
+
startedAt = clock.monotonicNow();
|
|
330
|
+
if (null !== opts.timeoutMs) {
|
|
331
|
+
const timeoutMs = opts.timeoutMs;
|
|
332
|
+
timeoutTimer = timers.setTimeout(()=>{
|
|
333
|
+
var _opts_errorMessage;
|
|
334
|
+
timeoutTimer = null;
|
|
335
|
+
if ('running' !== phase) return;
|
|
336
|
+
const error = new G9Error('safe-timeout', `Operation '${source}/${key}' timed out after ${timeoutMs} ms.`);
|
|
337
|
+
trace.error('Operation timed out', error);
|
|
338
|
+
settle({
|
|
339
|
+
kind: 'failed',
|
|
340
|
+
failure: {
|
|
341
|
+
reason: 'timeout',
|
|
342
|
+
error,
|
|
343
|
+
userMessage: null != (_opts_errorMessage = opts.errorMessage) ? _opts_errorMessage : text(G9StringKey.UnexpectedError),
|
|
344
|
+
diagnostics: buildReport(error)
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}, timeoutMs);
|
|
348
|
+
}
|
|
349
|
+
let result;
|
|
350
|
+
try {
|
|
351
|
+
result = action(context);
|
|
352
|
+
} catch (error) {
|
|
353
|
+
onFailure(error);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (isThenable(result)) result.then(onSuccess, onFailure);
|
|
357
|
+
else onSuccess(result);
|
|
358
|
+
};
|
|
359
|
+
active.add(abortRun);
|
|
360
|
+
null == (_opts_signal = opts.signal) || _opts_signal.addEventListener('abort', onExternalAbort, {
|
|
361
|
+
once: true
|
|
362
|
+
});
|
|
363
|
+
const delay = resolveExecutionDelay(opts);
|
|
364
|
+
if (delay > 0) delayTimer = timers.setTimeout(start, delay);
|
|
365
|
+
else start();
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return {
|
|
369
|
+
run,
|
|
370
|
+
runSafe (action, options) {
|
|
371
|
+
run(action, options).then(void 0, (error)=>{
|
|
372
|
+
log('error', 'Fire-and-forget task failed', void 0, void 0, error);
|
|
373
|
+
});
|
|
374
|
+
},
|
|
375
|
+
showOperationError,
|
|
376
|
+
tryThrottle,
|
|
377
|
+
resetThrottle () {
|
|
378
|
+
throttleStamps.clear();
|
|
379
|
+
inFlight.clear();
|
|
380
|
+
},
|
|
381
|
+
isRunning: (key)=>inFlight.has(key),
|
|
382
|
+
getSnapshot: ()=>snapshot,
|
|
383
|
+
subscribe (listener) {
|
|
384
|
+
listeners.add(listener);
|
|
385
|
+
return ()=>{
|
|
386
|
+
listeners.delete(listener);
|
|
387
|
+
};
|
|
388
|
+
},
|
|
389
|
+
dispose () {
|
|
390
|
+
if (disposed) return;
|
|
391
|
+
disposed = true;
|
|
392
|
+
for (const abort of [
|
|
393
|
+
...active
|
|
394
|
+
])abort('disposed');
|
|
395
|
+
publish();
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
export { createSafeExecutor, g9RuntimeTimers };
|
|
400
|
+
|
|
401
|
+
//# sourceMappingURL=safe-executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec/safe-executor.js","sources":["../../src/exec/safe-executor.ts"],"sourcesContent":["import { G9StringKey, g9EnglishStrings } from '../culture/strings';\nimport { G9Error } from '../errors';\nimport { createAbortController, createAbortError, type G9AbortSignal, isAbortError } from '../services/abort';\nimport { createSystemClock, type G9Clock } from '../services/clock';\nimport { createDiagnosticsReport, type G9Diagnostics, type G9DiagnosticsReport, type G9LogLevel } from './diagnostics';\nimport {\n type G9ResolvedSafeExecutorOptions,\n type G9SafeExecutorOptions,\n g9DefaultSafeExecutorOptions,\n resolveExecutionDelay,\n resolveSafeExecutorOptions,\n} from './options';\nimport { createOperationTrace, type G9OperationTrace } from './trace';\n\n/** What a guarded action receives. */\nexport interface G9SafeRunContext {\n /** Aborted on timeout, on the caller's signal, or when the executor is disposed (unmount). */\n readonly signal: G9AbortSignal;\n /** Step log for the \"More details\" report. */\n readonly trace: G9OperationTrace;\n readonly key: string;\n readonly source: string;\n}\n\n/** A guarded action. It may be synchronous; it then runs inside `run()` itself when there is no delay. */\nexport type G9SafeAction<T> = (context: G9SafeRunContext) => T | PromiseLike<T>;\n\n/**\n * How a run ended. Expected outcomes are results (specs/03 §7); `failed` carries the error and the report that was\n * routed to diagnostics, `onError` and the popup.\n */\nexport type G9SafeRunResult<T> =\n | { readonly status: 'completed'; readonly value: T }\n | { readonly status: 'skipped'; readonly reason: 'throttled' | 'concurrent' | 'disposed' }\n | { readonly status: 'cancelled'; readonly reason: 'aborted' | 'disposed' }\n | {\n readonly status: 'failed';\n /** `error`: the action threw; `timeout`: `timeoutMs` elapsed; `reported`: the action called `trace.fail`. */\n readonly reason: 'error' | 'timeout' | 'reported';\n /** The thrown value (a `G9Error` with code `safe-timeout` for a timeout); `undefined` for `reported`. */\n readonly error: unknown;\n readonly report: G9DiagnosticsReport;\n };\n\n/** What the host's error presenter shows (MAUI's error popup with OK and the optional \"More details\"). */\nexport interface G9ErrorPopupRequest {\n readonly title: string;\n readonly message: string;\n /** Text of the closing button (the `Ok` string). */\n readonly okText: string;\n readonly source: string;\n readonly diagnosticsText: string | null;\n readonly exceptions: ReadonlyArray<unknown> | null;\n /**\n * Present only when a `diagnosticsHandler` is configured and `diagnosticsAvailable` (asked per popup) allows it.\n * `open()` hands the report to the handler; it never rejects.\n */\n readonly moreDetails: { readonly text: string; open(): Promise<void> } | null;\n}\n\n/** Busy state of an executor, for a control's spinner. */\nexport interface G9SafeExecutorSnapshot {\n /** `'busy'` while at least one action runs (after its delay), `'disposed'` once disposed. */\n readonly state: 'idle' | 'busy' | 'disposed';\n /** Number of actions currently running. */\n readonly running: number;\n}\n\n/** Timer functions; default the runtime's `setTimeout`/`clearTimeout`. */\nexport interface G9Timers {\n setTimeout(callback: () => void, ms: number): unknown;\n clearTimeout(handle: unknown): void;\n}\n\n/** Configuration of {@link createSafeExecutor}; the WP02 provider fills it from its services and settings. */\nexport interface G9SafeExecutorConfig {\n /** Monotonic time for throttling and elapsed times, wall time for reports. Default: the system clock. */\n readonly clock?: G9Clock;\n /** Observation seam: started/completed/failed events and log lines. Default: none. */\n readonly diagnostics?: G9Diagnostics;\n /** Localised defaults for the popup (`Error`, `Ok`, `MoreDetails`, `UnexpectedError`). Default: English. */\n readonly strings?: { get(key: G9StringKey): string };\n /** Shows the error popup; the run waits for it, as MAUI awaited its popup. Without it nothing can be shown. */\n readonly showError?: (request: G9ErrorPopupRequest) => void | PromiseLike<void>;\n /** The app's \"More details\" surface (MAUI `G9SafeCommand.DiagnosticsHandler`). */\n readonly diagnosticsHandler?: (report: G9DiagnosticsReport) => void | PromiseLike<void>;\n /** Per-popup gate for \"More details\" (MAUI `DiagnosticsAvailable`). Default: available. A throwing gate hides it. */\n readonly diagnosticsAvailable?: () => boolean;\n /** Executor-wide option defaults (applied over the MAUI defaults, under per-run options). */\n readonly defaults?: G9SafeExecutorOptions;\n readonly timers?: G9Timers;\n}\n\n/** Options of {@link G9SafeExecutor.showOperationError}. */\nexport interface G9ShowOperationErrorOptions {\n readonly title?: string | null;\n readonly diagnosticsText?: string | null;\n readonly exceptions?: ReadonlyArray<unknown> | null;\n readonly source?: string | null;\n}\n\n/**\n * The one guarded-execution state machine (MAUI `G9SafeCommand`, specs/03 §4): throttle and same-key concurrency\n * guards, optional delay, busy reporting, trace, timeout, cancellation, error routing (diagnostics → `onError` → popup\n * → optional rethrow, all after the guards are released). Every run settles its promise exactly once.\n */\nexport interface G9SafeExecutor {\n /**\n * Runs `action` under the guards. Per run: skipped (throttled, concurrent, disposed) → [delay] → `setBusy(true)`,\n * `operationStarted` → action → `operationCompleted`, `setBusy(false)`, guards released → on failure:\n * `operationFailed`, `onError` (errors and timeouts), popup (when enabled), rethrow (when enabled).\n * Rejects only for invalid options (`G9Error` `safe-options`) or when `rethrow` is set and the action failed.\n */\n run<T>(action: G9SafeAction<T>, options?: G9SafeExecutorOptions): Promise<G9SafeRunResult<T>>;\n /** Fire-and-forget `run` (MAUI `RunSafe`): a rethrown error is logged, never left unobserved. */\n runSafe(action: G9SafeAction<unknown>, options?: G9SafeExecutorOptions): void;\n /** Shows an error through the presenter (MAUI `ShowOperationErrorAsync`). Blank messages show nothing. Never rejects. */\n showOperationError(message: string, options?: G9ShowOperationErrorOptions): Promise<void>;\n /**\n * `true` when `key` may run now, recording the attempt (MAUI `TryThrottle`). Monotonic time, so a device-clock\n * correction cannot disable buttons. Stale entries (older than a minute) are cleaned up.\n * @throws {G9Error} `safe-options` for a blank key.\n */\n tryThrottle(key: string, minIntervalMs?: number): boolean;\n /** Clears throttle and in-flight state (MAUI `ResetThrottle`; testing, logout). */\n resetThrottle(): void;\n /** Whether a run with this key holds the concurrency guard. */\n isRunning(key: string): boolean;\n getSnapshot(): G9SafeExecutorSnapshot;\n subscribe(listener: (snapshot: G9SafeExecutorSnapshot) => void): () => void;\n /**\n * Aborts every run (their promises settle at once as cancelled/disposed, busy is reset, `operationCompleted`\n * fires) and makes later runs skip. A late completion of an aborted action is ignored. Idempotent.\n */\n dispose(): void;\n}\n\nconst CLEANUP_THRESHOLD_MS = 60_000;\n\n// The Lynx runtime passes `setTimeout` / `clearTimeout` into each bundle's wrapper scope: they are identifiers there,\n// NOT properties of `globalThis` (Lynxtron 0.0.28 window, 2026-10-05: `globalThis.setTimeout` undefined, so every timer\n// reached through `globalThis` threw and the page-loading cover never left). Referencing the identifiers works in Lynx,\n// in Lynxtron and in Node, and is resolved per call, so test fake timers still apply.\ndeclare const setTimeout: (callback: () => void, ms: number) => unknown;\ndeclare const clearTimeout: (handle: unknown) => void;\n\n/**\n * The runtime's timers, safe on every Lynx thread host (bundle-scope identifiers, not `globalThis` properties). Every G9\n * timer goes through this or an injected {@link G9Timers}.\n */\nexport const g9RuntimeTimers: G9Timers = Object.freeze({\n setTimeout: (callback: () => void, ms: number) => setTimeout(callback, ms),\n clearTimeout: (handle: unknown) => clearTimeout(handle),\n});\nconst defaultTimers: G9Timers = g9RuntimeTimers;\n\nconst englishStrings = { get: (key: G9StringKey) => g9EnglishStrings[key] };\n\nfunction isThenable<T>(value: unknown): value is PromiseLike<T> {\n return (\n (typeof value === 'object' || typeof value === 'function') &&\n value !== null &&\n typeof (value as { then?: unknown }).then === 'function'\n );\n}\n\ninterface Failure {\n readonly reason: 'error' | 'timeout' | 'reported';\n readonly error: unknown;\n readonly userMessage: string;\n readonly diagnostics: string;\n}\n\n/** Creates a {@link G9SafeExecutor}. One per control or screen; dispose it on unmount. */\nexport function createSafeExecutor(config: G9SafeExecutorConfig = {}): G9SafeExecutor {\n const clock = config.clock ?? createSystemClock();\n const diagnostics = config.diagnostics;\n const strings = config.strings ?? englishStrings;\n const timers = config.timers ?? defaultTimers;\n const base = resolveSafeExecutorOptions(config.defaults, g9DefaultSafeExecutorOptions);\n\n const throttleStamps = new Map<string, number>();\n const inFlight = new Set<string>();\n const active = new Set<(why: 'disposed') => void>();\n const listeners = new Set<(snapshot: G9SafeExecutorSnapshot) => void>();\n let lastCleanup = clock.monotonicNow();\n let running = 0;\n let disposed = false;\n let snapshot: G9SafeExecutorSnapshot = Object.freeze({ state: 'idle', running: 0 });\n\n // The hub and the strings may be app implementations; neither may stop a run from settling.\n const observe = (call: (hub: G9Diagnostics) => void) => {\n if (!diagnostics) return;\n try {\n call(diagnostics);\n } catch {\n // An observer must never break the operation it observes (MAUI G9Diagnostics rule).\n }\n };\n const text = (key: G9StringKey): string => {\n try {\n const value = strings.get(key);\n return typeof value === 'string' ? value : g9EnglishStrings[key];\n } catch {\n return g9EnglishStrings[key];\n }\n };\n\n const log = (level: G9LogLevel, message: string, source?: string, key?: string, error?: unknown) => {\n observe((hub) =>\n hub.log({\n level,\n message,\n ...(source === undefined ? {} : { source }),\n ...(key === undefined ? {} : { key }),\n ...(error === undefined ? {} : { error }),\n }),\n );\n };\n\n const publish = () => {\n const state = disposed ? 'disposed' : running > 0 ? 'busy' : 'idle';\n if (snapshot.state === state && snapshot.running === running) return;\n snapshot = Object.freeze({ state, running });\n for (const listener of [...listeners]) {\n try {\n listener(snapshot);\n } catch (error) {\n log('error', 'Executor subscriber threw', undefined, undefined, error);\n }\n }\n };\n\n const safeSetBusy = (opts: G9ResolvedSafeExecutorOptions, busy: boolean) => {\n if (!opts.setBusy) return;\n try {\n opts.setBusy(busy);\n } catch (error) {\n log('error', `setBusy(${busy}) callback failed`, opts.source, opts.throttleKey, error);\n }\n };\n\n const isDiagnosticsAvailable = () => {\n const gate = config.diagnosticsAvailable;\n if (!gate) return true;\n try {\n return gate() === true;\n } catch (error) {\n log(\n 'warning',\n 'Diagnostics availability gate threw; hiding the More details button',\n undefined,\n undefined,\n error,\n );\n return false;\n }\n };\n\n const showOperationError = async (message: string, options: G9ShowOperationErrorOptions = {}): Promise<void> => {\n if (typeof message !== 'string' || message.trim() === '') return;\n const present = config.showError;\n if (!present) {\n log('warning', `No error presenter is configured; not shown: ${message}`, options.source ?? undefined);\n return;\n }\n try {\n const handler = config.diagnosticsHandler;\n const source = options.source ?? 'Unknown';\n const diagnosticsText = options.diagnosticsText ?? null;\n const exceptions = options.exceptions ?? null;\n const moreDetails =\n handler && isDiagnosticsAvailable()\n ? {\n text: text(G9StringKey.MoreDetails),\n open: async () => {\n try {\n await handler(createDiagnosticsReport(source, message, diagnosticsText, exceptions));\n } catch (error) {\n // Consumer code inside a popup callback: a fault must not stall the popup queue.\n log('error', 'Diagnostics handler threw', undefined, undefined, error);\n }\n },\n }\n : null;\n await present(\n Object.freeze({\n title: options.title ?? text(G9StringKey.Error),\n message,\n okText: text(G9StringKey.Ok),\n source,\n diagnosticsText,\n exceptions,\n moreDetails,\n }),\n );\n } catch (error) {\n log('error', 'Failed to show error popup', undefined, undefined, error);\n }\n };\n\n const tryThrottle = (key: string, minIntervalMs?: number): boolean => {\n if (typeof key !== 'string' || key.trim() === '') throw new G9Error('safe-options', 'Key cannot be empty.');\n const interval =\n minIntervalMs === undefined\n ? g9DefaultSafeExecutorOptions.throttleIntervalMs\n : resolveSafeExecutorOptions({ throttleIntervalMs: minIntervalMs }).throttleIntervalMs;\n const now = clock.monotonicNow();\n const last = throttleStamps.get(key);\n const allowed = last === undefined || now - last >= interval;\n if (allowed) throttleStamps.set(key, now);\n if (now - lastCleanup > CLEANUP_THRESHOLD_MS) {\n lastCleanup = now;\n const threshold = now - CLEANUP_THRESHOLD_MS;\n for (const [k, stamp] of throttleStamps) if (stamp < threshold) throttleStamps.delete(k);\n }\n return allowed;\n };\n\n async function report<T>(opts: G9ResolvedSafeExecutorOptions, failure: Failure): Promise<G9SafeRunResult<T>> {\n // Guards are released before anything here, so a popup the user leaves open blocks no other run.\n const { source, throttleKey: key } = opts;\n const hasError = failure.reason !== 'reported';\n const diagnosticsReport = createDiagnosticsReport(\n `${source}/${key}`,\n failure.userMessage,\n failure.diagnostics,\n hasError ? [failure.error] : [],\n );\n observe((hub) => hub.raiseOperationFailed(diagnosticsReport));\n if (hasError && opts.onError) {\n try {\n await opts.onError(failure.error);\n } catch (error) {\n log('error', 'OnError callback failed', source, key, error);\n }\n }\n if (opts.showErrorPopup) {\n await showOperationError(failure.userMessage, {\n title: opts.errorTitle,\n diagnosticsText: failure.diagnostics,\n source,\n });\n }\n if (hasError && opts.rethrow) throw failure.error;\n return Object.freeze({\n status: 'failed',\n reason: failure.reason,\n error: failure.error,\n report: diagnosticsReport,\n });\n }\n\n function run<T>(action: G9SafeAction<T>, options?: G9SafeExecutorOptions): Promise<G9SafeRunResult<T>> {\n let opts: G9ResolvedSafeExecutorOptions;\n try {\n if (typeof action !== 'function') throw new G9Error('safe-options', 'action must be a function.');\n opts = resolveSafeExecutorOptions(options, base);\n } catch (error) {\n return Promise.reject(error);\n }\n const { source, throttleKey: key } = opts;\n if (disposed) return Promise.resolve(Object.freeze({ status: 'skipped', reason: 'disposed' }));\n if (opts.signal?.aborted) return Promise.resolve(Object.freeze({ status: 'cancelled', reason: 'aborted' }));\n if (opts.enableThrottle && !tryThrottle(key, opts.throttleIntervalMs)) {\n log('debug', 'Operation skipped by throttle guard', source, key);\n return Promise.resolve(Object.freeze({ status: 'skipped', reason: 'throttled' }));\n }\n if (opts.preventConcurrentExecution) {\n if (inFlight.has(key)) {\n log('debug', 'Operation skipped by concurrent guard', source, key);\n return Promise.resolve(Object.freeze({ status: 'skipped', reason: 'concurrent' }));\n }\n inFlight.add(key);\n }\n\n return new Promise<G9SafeRunResult<T>>((resolve, reject) => {\n const controller = createAbortController();\n const trace = createOperationTrace(key, source, {\n clock,\n log: (entry) => observe((hub) => hub.log(entry)),\n });\n const context: G9SafeRunContext = Object.freeze({ signal: controller.signal, trace, key, source });\n let phase: 'delaying' | 'running' | 'settled' = 'delaying';\n let startedAt = 0;\n let delayTimer: unknown = null;\n let timeoutTimer: unknown = null;\n\n const onExternalAbort = () => settle({ kind: 'cancelled', reason: 'aborted' });\n const stopTimers = () => {\n if (delayTimer !== null) timers.clearTimeout(delayTimer);\n if (timeoutTimer !== null) timers.clearTimeout(timeoutTimer);\n delayTimer = timeoutTimer = null;\n };\n\n type Outcome =\n | { kind: 'completed'; value: T }\n | { kind: 'cancelled'; reason: 'aborted' | 'disposed' }\n | { kind: 'failed'; failure: Failure };\n\n // The single exit: every path (completion, error, timeout, caller abort, dispose) comes through here once.\n function settle(outcome: Outcome) {\n if (phase === 'settled') return;\n const wasRunning = phase === 'running';\n phase = 'settled';\n stopTimers();\n opts.signal?.removeEventListener('abort', onExternalAbort);\n active.delete(abortRun);\n // Tell a still-running action to stop: cancellation and timeout leave it orphaned, its result ignored.\n if (outcome.kind === 'cancelled' || (outcome.kind === 'failed' && outcome.failure.reason === 'timeout')) {\n controller.abort(\n outcome.kind === 'failed'\n ? outcome.failure.error\n : outcome.reason === 'disposed'\n ? createAbortError('The safe executor was disposed.')\n : (opts.signal?.reason ?? createAbortError()),\n );\n }\n if (wasRunning) {\n // Emitted on every exit of a started run, so a host counting in-flight work can never leak a count.\n observe((hub) => hub.raiseOperationCompleted(source, key, clock.monotonicNow() - startedAt));\n running--;\n safeSetBusy(opts, false);\n }\n if (opts.preventConcurrentExecution) inFlight.delete(key);\n publish();\n if (outcome.kind === 'completed') {\n resolve(Object.freeze({ status: 'completed', value: outcome.value }));\n } else if (outcome.kind === 'cancelled') {\n log(\n outcome.reason === 'disposed' ? 'warning' : 'debug',\n `Operation cancelled (${outcome.reason})`,\n source,\n key,\n );\n resolve(Object.freeze({ status: 'cancelled', reason: outcome.reason }));\n } else {\n report<T>(opts, outcome.failure).then(resolve, reject);\n }\n }\n\n function abortRun(why: 'disposed') {\n settle({ kind: 'cancelled', reason: why });\n }\n\n const buildReport = (error?: unknown) => {\n try {\n return trace.buildReport(error);\n } catch {\n return 'Failed to build diagnostics report.';\n }\n };\n\n const onSuccess = (value: T) => {\n if (phase !== 'running') return; // Late completion after timeout, abort or dispose: ignored.\n const reported = trace.failure;\n if (reported) {\n settle({\n kind: 'failed',\n failure: {\n reason: 'reported',\n error: undefined,\n userMessage: reported.userMessage,\n diagnostics: reported.diagnostics ?? buildReport(),\n },\n });\n } else {\n settle({ kind: 'completed', value });\n }\n };\n\n const onFailure = (error: unknown) => {\n if (phase !== 'running') return;\n if (isAbortError(error)) {\n // MAUI treated OperationCanceledException as a quiet cancellation, not a failure.\n settle({ kind: 'cancelled', reason: 'aborted' });\n return;\n }\n trace.error('Unhandled exception', error);\n settle({\n kind: 'failed',\n failure: {\n reason: 'error',\n error,\n userMessage: opts.errorMessage ?? text(G9StringKey.UnexpectedError),\n diagnostics: buildReport(error),\n },\n });\n };\n\n const start = () => {\n delayTimer = null;\n if (phase !== 'delaying') return;\n phase = 'running';\n running++;\n safeSetBusy(opts, true);\n publish();\n observe((hub) => hub.raiseOperationStarted(source, key));\n startedAt = clock.monotonicNow();\n if (opts.timeoutMs !== null) {\n const timeoutMs = opts.timeoutMs;\n timeoutTimer = timers.setTimeout(() => {\n timeoutTimer = null;\n if (phase !== 'running') return;\n const error = new G9Error('safe-timeout', `Operation '${source}/${key}' timed out after ${timeoutMs} ms.`);\n trace.error('Operation timed out', error);\n settle({\n kind: 'failed',\n failure: {\n reason: 'timeout',\n error,\n userMessage: opts.errorMessage ?? text(G9StringKey.UnexpectedError),\n diagnostics: buildReport(error),\n },\n });\n }, timeoutMs);\n }\n let result: T | PromiseLike<T>;\n try {\n result = action(context);\n } catch (error) {\n onFailure(error);\n return;\n }\n if (isThenable<T>(result)) result.then(onSuccess, onFailure);\n else onSuccess(result);\n };\n\n active.add(abortRun);\n opts.signal?.addEventListener('abort', onExternalAbort, { once: true });\n const delay = resolveExecutionDelay(opts);\n if (delay > 0) delayTimer = timers.setTimeout(start, delay);\n else start();\n });\n }\n\n return {\n run,\n runSafe(action, options) {\n run(action, options).then(undefined, (error: unknown) => {\n log('error', 'Fire-and-forget task failed', undefined, undefined, error);\n });\n },\n showOperationError,\n tryThrottle,\n resetThrottle() {\n throttleStamps.clear();\n inFlight.clear();\n },\n isRunning: (key) => inFlight.has(key),\n getSnapshot: () => snapshot,\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n dispose() {\n if (disposed) return;\n disposed = true;\n for (const abort of [...active]) abort('disposed');\n publish();\n },\n };\n}\n"],"names":["CLEANUP_THRESHOLD_MS","g9RuntimeTimers","Object","callback","ms","setTimeout","handle","clearTimeout","defaultTimers","englishStrings","key","g9EnglishStrings","isThenable","value","createSafeExecutor","config","_config_clock","_config_strings","_config_timers","clock","createSystemClock","diagnostics","strings","timers","base","resolveSafeExecutorOptions","g9DefaultSafeExecutorOptions","throttleStamps","Map","inFlight","Set","active","listeners","lastCleanup","running","disposed","snapshot","observe","call","text","log","level","message","source","error","hub","undefined","publish","state","listener","safeSetBusy","opts","busy","isDiagnosticsAvailable","gate","showOperationError","options","present","_options_source","_options_source1","_options_diagnosticsText","_options_exceptions","_options_title","handler","diagnosticsText","exceptions","moreDetails","G9StringKey","createDiagnosticsReport","tryThrottle","minIntervalMs","G9Error","interval","now","last","allowed","threshold","k","stamp","report","failure","hasError","diagnosticsReport","run","action","_opts_signal","Promise","resolve","reject","controller","createAbortController","trace","createOperationTrace","entry","context","phase","startedAt","delayTimer","timeoutTimer","onExternalAbort","settle","stopTimers","outcome","wasRunning","abortRun","_opts_signal1","createAbortError","why","buildReport","onSuccess","reported","_reported_diagnostics","onFailure","_opts_errorMessage","isAbortError","start","timeoutMs","result","delay","resolveExecutionDelay","abort"],"mappings":";;;;;;;AAyIA,MAAMA,uBAAuB;AAatB,MAAMC,kBAA4BC,OAAO,MAAM,CAAC;IACrD,YAAY,CAACC,UAAsBC,KAAeC,WAAWF,UAAUC;IACvE,cAAc,CAACE,SAAoBC,aAAaD;AAClD;AACA,MAAME,gBAA0BP;AAEhC,MAAMQ,iBAAiB;IAAE,KAAK,CAACC,MAAqBC,gBAAgB,CAACD,IAAI;AAAC;AAE1E,SAASE,WAAcC,KAAc;IACnC,OACG,CAAiB,YAAjB,OAAOA,SAAsB,AAAiB,cAAjB,OAAOA,KAAmB,KACxDA,AAAU,SAAVA,SACA,AAA8C,cAA9C,OAAQA,MAA6B,IAAI;AAE7C;AAUO,SAASC,mBAAmBC,SAA+B,CAAC,CAAC;QACpDC,eAEEC,iBACDC;IAHf,MAAMC,QAAQ,QAAAH,CAAAA,gBAAAA,OAAO,KAAK,AAAD,IAAXA,gBAAgBI;IAC9B,MAAMC,cAAcN,OAAO,WAAW;IACtC,MAAMO,UAAU,QAAAL,CAAAA,kBAAAA,OAAO,OAAO,AAAD,IAAbA,kBAAkBR;IAClC,MAAMc,SAAS,QAAAL,CAAAA,iBAAAA,OAAO,MAAM,AAAD,IAAZA,iBAAiBV;IAChC,MAAMgB,OAAOC,2BAA2BV,OAAO,QAAQ,EAAEW;IAEzD,MAAMC,iBAAiB,IAAIC;IAC3B,MAAMC,WAAW,IAAIC;IACrB,MAAMC,SAAS,IAAID;IACnB,MAAME,YAAY,IAAIF;IACtB,IAAIG,cAAcd,MAAM,YAAY;IACpC,IAAIe,UAAU;IACd,IAAIC,WAAW;IACf,IAAIC,WAAmClC,OAAO,MAAM,CAAC;QAAE,OAAO;QAAQ,SAAS;IAAE;IAGjF,MAAMmC,UAAU,CAACC;QACf,IAAI,CAACjB,aAAa;QAClB,IAAI;YACFiB,KAAKjB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