@directive-run/core 1.1.1 → 1.3.0
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/dist/adapter-utils.cjs +1 -1
- package/dist/adapter-utils.d.cts +1 -1
- package/dist/adapter-utils.d.ts +1 -1
- package/dist/adapter-utils.js +1 -1
- package/dist/chunk-DDUARSUH.cjs +7 -0
- package/dist/chunk-DDUARSUH.cjs.map +1 -0
- package/dist/chunk-FK7BD7XT.js +7 -0
- package/dist/chunk-FK7BD7XT.js.map +1 -0
- package/dist/chunk-GVVNFVEX.js +3 -0
- package/dist/chunk-GVVNFVEX.js.map +1 -0
- package/dist/chunk-JYGG4RIL.js +16 -0
- package/dist/chunk-JYGG4RIL.js.map +1 -0
- package/dist/chunk-RCCTZCZZ.cjs +3 -0
- package/dist/chunk-RCCTZCZZ.cjs.map +1 -0
- package/dist/chunk-U3DN2WML.cjs +16 -0
- package/dist/chunk-U3DN2WML.cjs.map +1 -0
- package/dist/{helpers-CroApnZa.d.cts → helpers-CCljEIsG.d.cts} +1 -1
- package/dist/{helpers-B8RS-sa_.d.ts → helpers-CfZCxxkR.d.ts} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +307 -8
- package/dist/index.d.ts +307 -8
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internals.cjs +1 -1
- package/dist/internals.d.cts +11 -4
- package/dist/internals.d.ts +11 -4
- package/dist/internals.js +1 -1
- package/dist/plugins/index.d.cts +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/{plugins-day_qfBB.d.cts → plugins-CLZ3xci0.d.cts} +124 -3
- package/dist/{plugins-day_qfBB.d.ts → plugins-CLZ3xci0.d.ts} +124 -3
- package/dist/system-F2QGHEG7.js +2 -0
- package/dist/{system-5OAYXJIG.js.map → system-F2QGHEG7.js.map} +1 -1
- package/dist/system-LZMEZBOA.cjs +2 -0
- package/dist/{system-4J3B25OD.cjs.map → system-LZMEZBOA.cjs.map} +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +37 -2
- package/dist/testing.d.ts +37 -2
- package/dist/testing.js +1 -1
- package/dist/testing.js.map +1 -1
- package/dist/worker.cjs +1 -1
- package/dist/worker.d.cts +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-2HKKISIL.js +0 -3
- package/dist/chunk-2HKKISIL.js.map +0 -1
- package/dist/chunk-4KFEHIIX.cjs +0 -3
- package/dist/chunk-4KFEHIIX.cjs.map +0 -1
- package/dist/chunk-KKHSUZA5.cjs +0 -2
- package/dist/chunk-KKHSUZA5.cjs.map +0 -1
- package/dist/chunk-L76IJROE.cjs +0 -16
- package/dist/chunk-L76IJROE.cjs.map +0 -1
- package/dist/chunk-LN4YQDLL.js +0 -2
- package/dist/chunk-LN4YQDLL.js.map +0 -1
- package/dist/chunk-WIMO6TQ3.js +0 -16
- package/dist/chunk-WIMO6TQ3.js.map +0 -1
- package/dist/system-4J3B25OD.cjs +0 -2
- package/dist/system-5OAYXJIG.js +0 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as SchemaType, D as DefinitionMeta, M as ModuleSchema, F as Facts, T as TypedDerivationsDef, a as TypedEventsDef, E as EffectsDef, b as TypedConstraintsDef, c as TypedResolversDef, d as ModuleHooks, C as CrossModuleDeps, e as CrossModuleDerivationsDef, f as CrossModuleEffectsDef, g as CrossModuleConstraintsDef, h as ModuleDef, i as CreateSystemOptionsSingle, j as SingleModuleSystem, k as ModulesMap, l as CreateSystemOptionsNamed, N as NamespacedSystem, P as Plugin, m as TraceOption, n as ErrorBoundaryConfig, R as RequirementWithId, o as Requirement, p as RequirementKeyFn } from './plugins-
|
|
2
|
-
export { A as AnySystem, B as BatchConfig, q as DirectiveError, r as DistributableSnapshot, s as DistributableSnapshotOptions, t as DynamicConstraintDef, u as DynamicEffectDef, v as DynamicResolverDef, w as FactsSnapshot, H as HistoryAPI, x as HistoryOption, y as HistoryState, I as InferDerivations, z as InferEvents, G as InferFacts, J as InferRequirementTypes, K as InferRequirements, L as InferSchemaType, O as InferSelectorState, Q as MetaAccessor, U as MetaMatch, V as ObservationEvent, W as RetryPolicy, X as Schema, Y as Snapshot, Z as System, _ as SystemConfig, $ as SystemInspection, a0 as SystemMode, a1 as SystemSnapshot, a2 as TraceEntry, a3 as isNamespacedSystem, a4 as isSingleModuleSystem } from './plugins-
|
|
3
|
-
export { D as DerivationDefWithMeta, t as typedConstraint, a as typedResolver } from './helpers-
|
|
1
|
+
import { S as SchemaType, D as DefinitionMeta, M as ModuleSchema, F as Facts, T as TypedDerivationsDef, a as TypedEventsDef, E as EffectsDef, b as TypedConstraintsDef, c as TypedResolversDef, d as ModuleHooks, C as CrossModuleDeps, e as CrossModuleDerivationsDef, f as CrossModuleEffectsDef, g as CrossModuleConstraintsDef, h as ModuleDef, i as CreateSystemOptionsSingle, j as SingleModuleSystem, k as ModulesMap, l as CreateSystemOptionsNamed, N as NamespacedSystem, P as Plugin, m as TraceOption, n as ErrorBoundaryConfig, R as RequirementWithId, o as Requirement, p as RequirementKeyFn } from './plugins-CLZ3xci0.cjs';
|
|
2
|
+
export { A as AnySystem, B as BatchConfig, q as DirectiveError, r as DistributableSnapshot, s as DistributableSnapshotOptions, t as DynamicConstraintDef, u as DynamicEffectDef, v as DynamicResolverDef, w as FactsSnapshot, H as HistoryAPI, x as HistoryOption, y as HistoryState, I as InferDerivations, z as InferEvents, G as InferFacts, J as InferRequirementTypes, K as InferRequirements, L as InferSchemaType, O as InferSelectorState, Q as MetaAccessor, U as MetaMatch, V as ObservationEvent, W as RetryPolicy, X as Schema, Y as Snapshot, Z as System, _ as SystemConfig, $ as SystemInspection, a0 as SystemMode, a1 as SystemSnapshot, a2 as TraceEntry, a3 as isNamespacedSystem, a4 as isSingleModuleSystem } from './plugins-CLZ3xci0.cjs';
|
|
3
|
+
export { D as DerivationDefWithMeta, t as typedConstraint, a as typedResolver } from './helpers-CCljEIsG.cjs';
|
|
4
4
|
export { D as DistributableSnapshotLike, S as SignedSnapshot, a as SnapshotDiff, b as SnapshotDiffEntry, d as diffSnapshots, i as isSignedSnapshot, c as isSnapshotExpired, s as shallowEqual, e as signSnapshot, v as validateSnapshot, f as verifySnapshotSignature } from './utils-BnQajqPu.cjs';
|
|
5
5
|
|
|
6
6
|
/** Brand symbol for branded types */
|
|
@@ -36,6 +36,21 @@ interface ChainableSchemaType<T> extends ExtendedSchemaType<T> {
|
|
|
36
36
|
/** Attach metadata for debugging and devtools. */
|
|
37
37
|
meta(meta: DefinitionMeta): ChainableSchemaType<T>;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Two-form union schema constructor.
|
|
41
|
+
*
|
|
42
|
+
* Hoisted out of the `t` object literal because the overload-cast pattern
|
|
43
|
+
* (`(impl) as { ovl1; ovl2 }`) inside an object literal triggers a TS
|
|
44
|
+
* declaration-emit "implicitly has type any" cycle. Annotating the const
|
|
45
|
+
* with the explicit overload type breaks the cycle so DTS can emit `t`'s
|
|
46
|
+
* shape without recursing through the runtime expression.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
type UnionFn = {
|
|
51
|
+
<T = unknown>(): ChainableSchemaType<T>;
|
|
52
|
+
<T extends SchemaType<unknown>[]>(...types: T): ChainableSchemaType<T[number] extends SchemaType<infer U> ? U : never>;
|
|
53
|
+
};
|
|
39
54
|
/**
|
|
40
55
|
* Schema type builders for defining fact types.
|
|
41
56
|
*
|
|
@@ -210,16 +225,38 @@ declare const t: {
|
|
|
210
225
|
/**
|
|
211
226
|
* Create a union schema type.
|
|
212
227
|
*
|
|
228
|
+
* **Two forms:**
|
|
229
|
+
* - `t.union(t.string(), t.number())` — variadic schema args; the runtime
|
|
230
|
+
* validator checks that the value matches at least one inner schema.
|
|
231
|
+
* - `t.union<string | number | boolean>()` — generic-only form with no
|
|
232
|
+
* schema args; the runtime validator accepts ANY value (mirrors
|
|
233
|
+
* {@link unknown} plus generic narrowing). Use this for polymorphic
|
|
234
|
+
* payloads where the union is too dynamic to enumerate as inner schemas
|
|
235
|
+
* (e.g. an `UPDATE_FIELD` event whose `value` may be `string | number |
|
|
236
|
+
* boolean | Date`).
|
|
237
|
+
*
|
|
238
|
+
* Chainable methods (`.validate`, `.transform`, `.default`, `.describe`,
|
|
239
|
+
* `.refine`, `.optional`, `.nullable`) work the same for both forms.
|
|
240
|
+
*
|
|
213
241
|
* @example
|
|
214
242
|
* ```typescript
|
|
215
|
-
* //
|
|
243
|
+
* // Variadic — runtime validation against inner schemas
|
|
216
244
|
* schema: { value: t.union(t.string(), t.number()) }
|
|
217
245
|
*
|
|
218
|
-
* //
|
|
219
|
-
* schema: {
|
|
246
|
+
* // Generic-only — type-only narrowing, runtime accepts any value
|
|
247
|
+
* schema: {
|
|
248
|
+
* payload: t.union<string | number | boolean>(),
|
|
249
|
+
* }
|
|
250
|
+
*
|
|
251
|
+
* // Add a custom predicate via .validate when you still want a runtime check
|
|
252
|
+
* schema: {
|
|
253
|
+
* strict: t.union<string | number>().validate(
|
|
254
|
+
* (v) => typeof v === "string" || typeof v === "number",
|
|
255
|
+
* ),
|
|
256
|
+
* }
|
|
220
257
|
* ```
|
|
221
258
|
*/
|
|
222
|
-
union
|
|
259
|
+
union: UnionFn;
|
|
223
260
|
/**
|
|
224
261
|
* Create a record schema type for dynamic key-value maps.
|
|
225
262
|
*
|
|
@@ -478,6 +515,15 @@ interface ModuleConfigWithDeps<M extends ModuleSchema, Deps extends CrossModuleD
|
|
|
478
515
|
* },
|
|
479
516
|
* },
|
|
480
517
|
* },
|
|
518
|
+
* hooks: {
|
|
519
|
+
* // Optional: observe resolver failures owned by this module.
|
|
520
|
+
* // Fires AFTER retries are exhausted and the engine has handled the error
|
|
521
|
+
* // (error boundary, plugin emit, retry decision). Use it as a side-channel
|
|
522
|
+
* // observer for module-local logging/telemetry — not for recovery.
|
|
523
|
+
* onResolverError: (error, requirement, ctx) => {
|
|
524
|
+
* console.warn(`[traffic-light] resolver failed for ${requirement.type}`, error);
|
|
525
|
+
* },
|
|
526
|
+
* },
|
|
481
527
|
* });
|
|
482
528
|
* ```
|
|
483
529
|
*
|
|
@@ -921,6 +967,259 @@ declare class RequirementSet {
|
|
|
921
967
|
};
|
|
922
968
|
}
|
|
923
969
|
|
|
970
|
+
/**
|
|
971
|
+
* SignalClock — injectable clock source for declarative timers (RFC 0001).
|
|
972
|
+
*
|
|
973
|
+
* The clock interface decouples Directive's timer primitives from any
|
|
974
|
+
* single time source. Production uses `realClock()`. Tests use
|
|
975
|
+
* `virtualClock()` which advances synchronously via `clock.advanceBy()`.
|
|
976
|
+
* Replay / dehydrate scenarios use a clock seeded from the recorded
|
|
977
|
+
* stream.
|
|
978
|
+
*
|
|
979
|
+
* Auto-detection: `defaultClock()` returns `virtualClock()` when running
|
|
980
|
+
* under Vitest (process.env.VITEST === 'true'), otherwise `realClock()`.
|
|
981
|
+
* Consumers can pass an explicit clock to `createSystem({ clock })` to
|
|
982
|
+
* override.
|
|
983
|
+
*
|
|
984
|
+
* @see ../../docs/rfcs/0001-t-timer.md
|
|
985
|
+
*/
|
|
986
|
+
/**
|
|
987
|
+
* Stable interface for any time source.
|
|
988
|
+
*/
|
|
989
|
+
interface SignalClock {
|
|
990
|
+
/** Current time, in milliseconds since the Unix epoch. */
|
|
991
|
+
now(): number;
|
|
992
|
+
/**
|
|
993
|
+
* Schedule a callback to fire after `ms` milliseconds. Returns a
|
|
994
|
+
* cancellation function. Implementations may queue callbacks or fire
|
|
995
|
+
* them on a tick boundary; the only contract is "fires no earlier
|
|
996
|
+
* than `ms` from now."
|
|
997
|
+
*/
|
|
998
|
+
setTimeout(cb: () => void, ms: number): () => void;
|
|
999
|
+
/**
|
|
1000
|
+
* (Test-only.) Synchronously advance the clock by `ms` milliseconds,
|
|
1001
|
+
* firing all scheduled callbacks whose deadlines fall within the
|
|
1002
|
+
* advanced window. Real clocks throw if called.
|
|
1003
|
+
*/
|
|
1004
|
+
advanceBy?(ms: number): void;
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Production clock — wraps `Date.now()` and `globalThis.setTimeout`.
|
|
1008
|
+
* No mocking, no virtualization.
|
|
1009
|
+
*/
|
|
1010
|
+
declare function realClock(): SignalClock;
|
|
1011
|
+
/**
|
|
1012
|
+
* Virtual clock — advances only when `advanceBy(ms)` is called. All
|
|
1013
|
+
* scheduled callbacks fire synchronously in order of their deadlines.
|
|
1014
|
+
*
|
|
1015
|
+
* Two scheduled callbacks at the same deadline fire in registration order.
|
|
1016
|
+
* Cancellation is O(1).
|
|
1017
|
+
*/
|
|
1018
|
+
declare function virtualClock(initialMs?: number): SignalClock;
|
|
1019
|
+
/**
|
|
1020
|
+
* Returns `realClock()` always.
|
|
1021
|
+
*
|
|
1022
|
+
* Earlier drafts auto-detected vitest (`process.env.VITEST === 'true'`)
|
|
1023
|
+
* and returned a `virtualClock()` in that environment. AE review
|
|
1024
|
+
* flagged this as a footgun: tests that legitimately need real time
|
|
1025
|
+
* (sleep-based debounce checks, real-`setTimeout`-bound integration
|
|
1026
|
+
* fixtures) silently received a virtual clock that never advanced
|
|
1027
|
+
* unless the test author called `advanceBy()`, producing apparent
|
|
1028
|
+
* deadlocks indistinguishable from genuine bugs. Auto-detection is
|
|
1029
|
+
* therefore opt-in.
|
|
1030
|
+
*
|
|
1031
|
+
* Use {@link virtualClock} explicitly in tests:
|
|
1032
|
+
*
|
|
1033
|
+
* ```ts
|
|
1034
|
+
* const clock = virtualClock(0);
|
|
1035
|
+
* const sys = createSystem({ module, clock });
|
|
1036
|
+
* clock.advanceBy(1_000);
|
|
1037
|
+
* ```
|
|
1038
|
+
*/
|
|
1039
|
+
declare function defaultClock(): SignalClock;
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* Timer fact — a runtime container that advances over time on a
|
|
1043
|
+
* SignalClock (RFC 0001 v0.1).
|
|
1044
|
+
*
|
|
1045
|
+
* Produced by `createTimerFact(clock, opts)`. Holds the durable state
|
|
1046
|
+
* (startedAtMs, pausedDurationMs, status) and exposes a control surface
|
|
1047
|
+
* (start, pause, resume, reset) plus reactive reads (elapsedMs,
|
|
1048
|
+
* remainingMs, status).
|
|
1049
|
+
*
|
|
1050
|
+
* v0.1 SCOPE: timer is a "thick fact" — a single object you store in a
|
|
1051
|
+
* regular Directive fact (e.g. `t.object<TimerFactState>()`). The
|
|
1052
|
+
* engine doesn't auto-tick it; the consumer is responsible for calling
|
|
1053
|
+
* `timer.tick()` when they want elapsedMs / remainingMs to update.
|
|
1054
|
+
* Typical wiring: a setInterval in the consumer that calls `timer.tick()`
|
|
1055
|
+
* and dispatches an event when status changes.
|
|
1056
|
+
*
|
|
1057
|
+
* v0.2 (deferred): true `t.timer({ms})` schema integration where the
|
|
1058
|
+
* engine subscribes to the clock and writes the fact deltas itself,
|
|
1059
|
+
* eliminating the consumer-side tick wiring.
|
|
1060
|
+
*
|
|
1061
|
+
* @see ../../docs/rfcs/0001-t-timer.md
|
|
1062
|
+
*/
|
|
1063
|
+
/**
|
|
1064
|
+
* Persistent timer state — JSON-roundtrippable, suitable for storing
|
|
1065
|
+
* inside a Directive fact.
|
|
1066
|
+
*/
|
|
1067
|
+
interface TimerFactState {
|
|
1068
|
+
/** Unix-ms when the timer last started or resumed. null = not running. */
|
|
1069
|
+
startedAtMs: number | null;
|
|
1070
|
+
/** Total ms accumulated while paused. */
|
|
1071
|
+
pausedDurationMs: number;
|
|
1072
|
+
/** ms when the timer was paused, if currently paused. null otherwise. */
|
|
1073
|
+
pausedAtMs: number | null;
|
|
1074
|
+
/**
|
|
1075
|
+
* - 'idle': not yet started, or reset.
|
|
1076
|
+
* - 'running': currently counting.
|
|
1077
|
+
* - 'paused': paused; pausedAtMs is set.
|
|
1078
|
+
* - 'completed': hit the deadline (countdown mode only).
|
|
1079
|
+
*/
|
|
1080
|
+
status: "idle" | "running" | "paused" | "completed";
|
|
1081
|
+
/** Number of times the timer has fired (repeat mode only). */
|
|
1082
|
+
repeats: number;
|
|
1083
|
+
}
|
|
1084
|
+
interface TimerFactOpts {
|
|
1085
|
+
/** Duration in ms. Countdown mode counts this down; up mode counts up to ∞. */
|
|
1086
|
+
ms: number;
|
|
1087
|
+
/**
|
|
1088
|
+
* - 'down' (default): counts down from `ms` to 0; status → 'completed' at 0.
|
|
1089
|
+
* - 'up': counts elapsed time; never completes.
|
|
1090
|
+
* - 'repeat': fires every `ms`; increments `repeats`; status stays 'running'.
|
|
1091
|
+
*/
|
|
1092
|
+
mode?: "down" | "up" | "repeat";
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Initial state for a newly-created timer. Pass this to your Directive
|
|
1096
|
+
* `init()` to seed the fact.
|
|
1097
|
+
*/
|
|
1098
|
+
declare function initialTimerState(): TimerFactState;
|
|
1099
|
+
/**
|
|
1100
|
+
* Compute elapsed ms for a given timer state at a given clock-now.
|
|
1101
|
+
* Pure function — no side effects, no reads beyond its inputs.
|
|
1102
|
+
*
|
|
1103
|
+
* @example
|
|
1104
|
+
* ```ts
|
|
1105
|
+
* const elapsed = elapsedMs(facts.countdown, clock.now());
|
|
1106
|
+
* if (elapsed >= 60_000) {
|
|
1107
|
+
* facts.countdown = { ...facts.countdown, status: 'completed' };
|
|
1108
|
+
* }
|
|
1109
|
+
* ```
|
|
1110
|
+
*/
|
|
1111
|
+
declare function elapsedMs(state: TimerFactState, nowMs: number): number;
|
|
1112
|
+
/**
|
|
1113
|
+
* Compute remaining ms for a countdown timer at a given clock-now.
|
|
1114
|
+
* Returns 0 if the timer has hit zero or hasn't started.
|
|
1115
|
+
*/
|
|
1116
|
+
declare function remainingMs(state: TimerFactState, nowMs: number, totalMs: number): number;
|
|
1117
|
+
/**
|
|
1118
|
+
* Transition: start an idle (or reset) timer.
|
|
1119
|
+
*
|
|
1120
|
+
* No-op if already running, paused, or completed (use `reset()` first).
|
|
1121
|
+
*/
|
|
1122
|
+
declare function startTimer(state: TimerFactState, nowMs: number): TimerFactState;
|
|
1123
|
+
/**
|
|
1124
|
+
* Transition: pause a running timer. Records the pause moment so a
|
|
1125
|
+
* later `resumeTimer()` can correctly extend pausedDurationMs.
|
|
1126
|
+
*
|
|
1127
|
+
* No-op if not running.
|
|
1128
|
+
*/
|
|
1129
|
+
declare function pauseTimer(state: TimerFactState, nowMs: number): TimerFactState;
|
|
1130
|
+
/**
|
|
1131
|
+
* Transition: resume a paused timer. Adds the time spent paused into
|
|
1132
|
+
* `pausedDurationMs` so elapsed/remaining math stays correct.
|
|
1133
|
+
*
|
|
1134
|
+
* No-op if not paused.
|
|
1135
|
+
*/
|
|
1136
|
+
declare function resumeTimer(state: TimerFactState, nowMs: number): TimerFactState;
|
|
1137
|
+
/**
|
|
1138
|
+
* Transition: reset a timer to idle. Loses all elapsed time + repeat
|
|
1139
|
+
* count. Equivalent to `initialTimerState()`.
|
|
1140
|
+
*/
|
|
1141
|
+
declare function resetTimer(): TimerFactState;
|
|
1142
|
+
/**
|
|
1143
|
+
* Transition: mark the timer completed. For countdown mode when
|
|
1144
|
+
* elapsed >= ms; for repeat mode when consumer wants to halt.
|
|
1145
|
+
*/
|
|
1146
|
+
declare function completeTimer(state: TimerFactState): TimerFactState;
|
|
1147
|
+
/**
|
|
1148
|
+
* Transition: register a repeat firing. Increments `repeats` and
|
|
1149
|
+
* advances `startedAtMs` by `ms` so the next interval lands at the
|
|
1150
|
+
* intended boundary (drift-free).
|
|
1151
|
+
*/
|
|
1152
|
+
declare function registerRepeat(state: TimerFactState, ms: number): TimerFactState;
|
|
1153
|
+
/**
|
|
1154
|
+
* Higher-level helper: given a timer state, total ms, and the current
|
|
1155
|
+
* clock, return whether the timer should transition to 'completed' (for
|
|
1156
|
+
* countdown mode) or fire a repeat (for repeat mode).
|
|
1157
|
+
*
|
|
1158
|
+
* Pure — does not mutate state. Returns a structured signal the consumer
|
|
1159
|
+
* applies via `completeTimer` / `registerRepeat`.
|
|
1160
|
+
*/
|
|
1161
|
+
declare function tickTimer(state: TimerFactState, nowMs: number, opts: TimerFactOpts): {
|
|
1162
|
+
kind: "no-op";
|
|
1163
|
+
} | {
|
|
1164
|
+
kind: "complete";
|
|
1165
|
+
} | {
|
|
1166
|
+
kind: "repeat";
|
|
1167
|
+
};
|
|
1168
|
+
/**
|
|
1169
|
+
* Bundle of helpers for one timer in one module — convenience for
|
|
1170
|
+
* callers who want a single import. Each method takes the current
|
|
1171
|
+
* state and clock-now, returns the next state. No mutation.
|
|
1172
|
+
*
|
|
1173
|
+
* @example
|
|
1174
|
+
* ```ts
|
|
1175
|
+
* import {
|
|
1176
|
+
* createSystem,
|
|
1177
|
+
* t,
|
|
1178
|
+
* realClock,
|
|
1179
|
+
* timerOps,
|
|
1180
|
+
* initialTimerState,
|
|
1181
|
+
* type TimerFactState,
|
|
1182
|
+
* } from '@directive-run/core';
|
|
1183
|
+
*
|
|
1184
|
+
* const clock = realClock();
|
|
1185
|
+
* const ops = timerOps({ ms: 60_000, mode: 'down' });
|
|
1186
|
+
*
|
|
1187
|
+
* createModule('countdown', {
|
|
1188
|
+
* schema: { facts: { state: t.object<TimerFactState>() }, events: { START: {} } },
|
|
1189
|
+
* init: (f) => { f.state = initialTimerState(); },
|
|
1190
|
+
* events: {
|
|
1191
|
+
* START: (f) => { f.state = ops.start(f.state, clock.now()); },
|
|
1192
|
+
* },
|
|
1193
|
+
* });
|
|
1194
|
+
*
|
|
1195
|
+
* // In the consumer (React, Node, edge), tick periodically:
|
|
1196
|
+
* setInterval(() => {
|
|
1197
|
+
* const signal = ops.tick(f.state, clock.now());
|
|
1198
|
+
* if (signal.kind === 'complete') {
|
|
1199
|
+
* sys.dispatch({ type: 'TIMEOUT' });
|
|
1200
|
+
* }
|
|
1201
|
+
* }, 100);
|
|
1202
|
+
* ```
|
|
1203
|
+
*/
|
|
1204
|
+
declare function timerOps(opts: TimerFactOpts): {
|
|
1205
|
+
initial: typeof initialTimerState;
|
|
1206
|
+
start: typeof startTimer;
|
|
1207
|
+
pause: typeof pauseTimer;
|
|
1208
|
+
resume: typeof resumeTimer;
|
|
1209
|
+
reset: typeof resetTimer;
|
|
1210
|
+
complete: typeof completeTimer;
|
|
1211
|
+
registerRepeat: (state: TimerFactState) => TimerFactState;
|
|
1212
|
+
tick: (state: TimerFactState, nowMs: number) => {
|
|
1213
|
+
kind: "no-op";
|
|
1214
|
+
} | {
|
|
1215
|
+
kind: "complete";
|
|
1216
|
+
} | {
|
|
1217
|
+
kind: "repeat";
|
|
1218
|
+
};
|
|
1219
|
+
elapsedMs: typeof elapsedMs;
|
|
1220
|
+
remainingMs: (state: TimerFactState, nowMs: number) => number;
|
|
1221
|
+
};
|
|
1222
|
+
|
|
924
1223
|
/**
|
|
925
1224
|
* @directive-run/core
|
|
926
1225
|
*
|
|
@@ -956,4 +1255,4 @@ declare const Backoff: {
|
|
|
956
1255
|
readonly Exponential: "exponential";
|
|
957
1256
|
};
|
|
958
1257
|
|
|
959
|
-
export { Backoff, type Branded, type ChainableSchemaType, CreateSystemOptionsNamed, CreateSystemOptionsSingle, CrossModuleDeps, DefinitionMeta, ErrorBoundaryConfig, type ExtendedSchemaType, Facts, type ModuleConfig, type ModuleConfigWithDeps, ModuleDef, ModuleHooks, ModuleSchema, ModulesMap, NamespacedSystem, Plugin, Requirement, RequirementSet, type RequirementTypeStatus, RequirementWithId, SchemaType, SingleModuleSystem, TraceOption, createModule, createModuleFactory, createRequirementStatusPlugin, createStatusHook, createSystem, createSystemWithStatus, forType, generateRequirementId, isRequirementType, req, t };
|
|
1258
|
+
export { Backoff, type Branded, type ChainableSchemaType, CreateSystemOptionsNamed, CreateSystemOptionsSingle, CrossModuleDeps, DefinitionMeta, ErrorBoundaryConfig, type ExtendedSchemaType, Facts, type ModuleConfig, type ModuleConfigWithDeps, ModuleDef, ModuleHooks, ModuleSchema, ModulesMap, NamespacedSystem, Plugin, Requirement, RequirementSet, type RequirementTypeStatus, RequirementWithId, SchemaType, type SignalClock, SingleModuleSystem, type TimerFactOpts, type TimerFactState, TraceOption, completeTimer, createModule, createModuleFactory, createRequirementStatusPlugin, createStatusHook, createSystem, createSystemWithStatus, defaultClock, elapsedMs, forType, generateRequirementId, initialTimerState, isRequirementType, pauseTimer, realClock, registerRepeat, remainingMs, req, resetTimer, resumeTimer, startTimer, t, tickTimer, timerOps, virtualClock };
|