@systemfsoftware/effect-daemon-spec 0.1.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.
@@ -0,0 +1,338 @@
1
+ import { Cause, Context, Duration, Effect, Layer, Metric, Option, Schedule, Schema, Scope, Stream } from "effect";
2
+
3
+ //#region src/backoff.d.ts
4
+ declare const cappedBackoff: (base: Duration.DurationInput, cap: Duration.DurationInput) => Schedule.Schedule<Duration.Duration>;
5
+ //#endregion
6
+ //#region src/daemon-health.schema.d.ts
7
+ declare const DynamicLimitExceeded_base: Schema.TaggedErrorClass<DynamicLimitExceeded, "DynamicLimitExceeded", {
8
+ readonly _tag: Schema.tag<"DynamicLimitExceeded">;
9
+ } & {
10
+ limit: Schema.filter<typeof Schema.Int>;
11
+ }>;
12
+ declare class DynamicLimitExceeded extends DynamicLimitExceeded_base {}
13
+ //#endregion
14
+ //#region src/daemon-health.d.ts
15
+ interface DaemonHealth {
16
+ readonly name: string;
17
+ readonly ready: Effect.Latch;
18
+ readonly healthy: Effect.Latch;
19
+ readonly paused: Effect.Latch;
20
+ }
21
+ interface SupervisorHealth {
22
+ readonly name: string;
23
+ readonly ready: Effect.Latch;
24
+ readonly healthy: Effect.Latch;
25
+ readonly paused: Effect.Latch;
26
+ readonly children: ReadonlyArray<DaemonHealth | SupervisorHealth>;
27
+ }
28
+ interface DynamicHandle<Args, R = never> {
29
+ readonly health: SupervisorHealth;
30
+ readonly startChild: (args: Args) => Effect.Effect<ChildRef, DynamicLimitExceeded, R>;
31
+ readonly stopChild: (ref: Pick<ChildRef, 'id'>) => Effect.Effect<void>;
32
+ readonly count: Effect.Effect<number>;
33
+ }
34
+ type ChildRef = {
35
+ readonly id: number;
36
+ readonly removed: Effect.Effect<void>;
37
+ };
38
+ //#endregion
39
+ //#region src/daemon-metrics.d.ts
40
+ declare const supervisorRestartsCounter: Metric.Metric.Counter<number>;
41
+ declare const supervisorExhaustionsCounter: Metric.Metric.Counter<number>;
42
+ declare const supervisorChildrenGauge: Metric.Metric.Gauge<number>;
43
+ declare const healthStateGauge: Metric.Metric.Gauge<number>;
44
+ //#endregion
45
+ //#region src/daemon-policy.schema.d.ts
46
+ declare const IntensityConfig: Schema.Struct<{
47
+ restarts: Schema.filter<typeof Schema.Int>;
48
+ window: typeof Schema.DurationFromSelf;
49
+ }>;
50
+ type IntensityConfig = typeof IntensityConfig.Type;
51
+ declare const IntensityTypeId: unique symbol;
52
+ type IntensityTypeId = typeof IntensityTypeId;
53
+ declare const BoundedIntensity_base: Schema.TaggedClass<BoundedIntensity, "Bounded", {
54
+ readonly _tag: Schema.tag<"Bounded">;
55
+ } & Readonly<{
56
+ restarts: Schema.filter<typeof Schema.Int>;
57
+ window: typeof Schema.DurationFromSelf;
58
+ }>>;
59
+ declare class BoundedIntensity extends BoundedIntensity_base {
60
+ readonly [IntensityTypeId]: symbol;
61
+ }
62
+ declare const UnboundedIntensity_base: Schema.TaggedClass<UnboundedIntensity, "Unbounded", {
63
+ readonly _tag: Schema.tag<"Unbounded">;
64
+ }>;
65
+ declare class UnboundedIntensity extends UnboundedIntensity_base {
66
+ readonly [IntensityTypeId]: symbol;
67
+ }
68
+ declare const Intensity: Schema.Union<[typeof BoundedIntensity, typeof UnboundedIntensity]>;
69
+ type Intensity = typeof Intensity.Type;
70
+ declare const ChildPolicyConfig_base: Schema.Class<ChildPolicyConfig, {
71
+ restart: Schema.optional<Schema.Literal<["permanent", "transient", "temporary"]>>;
72
+ intensity: Schema.optional<Schema.Struct<{
73
+ restarts: Schema.filter<typeof Schema.Int>;
74
+ window: typeof Schema.DurationFromSelf;
75
+ }>>;
76
+ }, Schema.Struct.Encoded<{
77
+ restart: Schema.optional<Schema.Literal<["permanent", "transient", "temporary"]>>;
78
+ intensity: Schema.optional<Schema.Struct<{
79
+ restarts: Schema.filter<typeof Schema.Int>;
80
+ window: typeof Schema.DurationFromSelf;
81
+ }>>;
82
+ }>, never, {
83
+ readonly intensity?: {
84
+ readonly restarts: number;
85
+ readonly window: import("effect/Duration").Duration;
86
+ } | undefined;
87
+ } & {
88
+ readonly restart?: "permanent" | "temporary" | "transient" | undefined;
89
+ }, {}, {}>;
90
+ declare class ChildPolicyConfig extends ChildPolicyConfig_base {}
91
+ declare const LockPolicyConfig_base: Schema.Class<LockPolicyConfig, {
92
+ mode: Schema.optional<Schema.Literal<["none", "required", "optional"]>>;
93
+ key: Schema.optional<typeof Schema.String>;
94
+ }, Schema.Struct.Encoded<{
95
+ mode: Schema.optional<Schema.Literal<["none", "required", "optional"]>>;
96
+ key: Schema.optional<typeof Schema.String>;
97
+ }>, never, {
98
+ readonly key?: string | undefined;
99
+ } & {
100
+ readonly mode?: "none" | "optional" | "required" | undefined;
101
+ }, {}, {}>;
102
+ declare class LockPolicyConfig extends LockPolicyConfig_base {}
103
+ declare const TickPolicyConfig_base: Schema.Class<TickPolicyConfig, {
104
+ spanName: Schema.optional<typeof Schema.String>;
105
+ tickTimeout: typeof Schema.DurationFromSelf;
106
+ startLogLevel: Schema.optional<Schema.Literal<["debug", "info"]>>;
107
+ }, Schema.Struct.Encoded<{
108
+ spanName: Schema.optional<typeof Schema.String>;
109
+ tickTimeout: typeof Schema.DurationFromSelf;
110
+ startLogLevel: Schema.optional<Schema.Literal<["debug", "info"]>>;
111
+ }>, never, {
112
+ readonly spanName?: string | undefined;
113
+ } & {
114
+ readonly startLogLevel?: "debug" | "info" | undefined;
115
+ } & {
116
+ readonly tickTimeout: import("effect/Duration").Duration;
117
+ }, {}, {}>;
118
+ declare class TickPolicyConfig extends TickPolicyConfig_base {}
119
+ //#endregion
120
+ //#region src/daemon-reporter.d.ts
121
+ interface DaemonReporterService {
122
+ readonly onRestart: (name: string, cause: Cause.Cause<never>) => Effect.Effect<void>;
123
+ readonly onExhausted: (name: string, cause: Cause.Cause<never>) => Effect.Effect<void>;
124
+ }
125
+ declare const DaemonReporter_base: Context.TagClass<DaemonReporter, "@systemfsoftware/effect-daemon-spec/daemon-reporter/DaemonReporter", DaemonReporterService>;
126
+ declare class DaemonReporter extends DaemonReporter_base {
127
+ static readonly Noop: Layer.Layer<DaemonReporter>;
128
+ }
129
+ //#endregion
130
+ //#region src/supervision-preset.d.ts
131
+ interface SupervisionPolicy {
132
+ readonly intensity: Intensity;
133
+ readonly backoff: Schedule.Schedule<Duration.Duration>;
134
+ readonly cooldown: Duration.DurationInput;
135
+ }
136
+ interface SupervisionConfig {
137
+ readonly backoffBase: Duration.DurationInput;
138
+ readonly intensity: Intensity;
139
+ readonly cooldown: Duration.DurationInput;
140
+ }
141
+ declare const LeaderConfig_base: Context.ReferenceClass<LeaderConfig, "@systemfsoftware/effect-daemon-spec/LeaderConfig", SupervisionConfig>;
142
+ declare class LeaderConfig extends LeaderConfig_base {}
143
+ declare const WorkerConfig_base: Context.ReferenceClass<WorkerConfig, "@systemfsoftware/effect-daemon-spec/WorkerConfig", SupervisionConfig>;
144
+ declare class WorkerConfig extends WorkerConfig_base {}
145
+ declare const TaskConfig_base: Context.ReferenceClass<TaskConfig, "@systemfsoftware/effect-daemon-spec/TaskConfig", SupervisionConfig>;
146
+ declare class TaskConfig extends TaskConfig_base {}
147
+ declare const Supervision: {
148
+ readonly leader: (cap: Duration.DurationInput) => Effect.Effect<SupervisionPolicy>;
149
+ readonly worker: (cap: Duration.DurationInput) => Effect.Effect<SupervisionPolicy>;
150
+ readonly task: (budget: Duration.DurationInput) => Effect.Effect<SupervisionPolicy>;
151
+ readonly custom: (policy: SupervisionPolicy) => Effect.Effect<SupervisionPolicy>;
152
+ };
153
+ //#endregion
154
+ //#region src/daemon-spec.d.ts
155
+ declare const WorkerTypeId: unique symbol;
156
+ type WorkerTypeId = typeof WorkerTypeId;
157
+ declare const SupervisorTypeId: unique symbol;
158
+ type SupervisorTypeId = typeof SupervisorTypeId;
159
+ declare const DynamicSpecTypeId: unique symbol;
160
+ type DynamicSpecTypeId = typeof DynamicSpecTypeId;
161
+ type LockConfig = {
162
+ mode: 'none';
163
+ } | {
164
+ mode: 'optional';
165
+ key: string;
166
+ } | {
167
+ mode: 'required';
168
+ key: string;
169
+ acquireRetryBackoff: Schedule.Schedule<Duration.Duration>;
170
+ };
171
+ interface TickPolicyHooks {
172
+ readonly spanAttributes?: Effect.Effect<Record<string, string | number | boolean>>;
173
+ readonly innerRetry?: Schedule.Schedule<unknown>;
174
+ readonly trackDuration?: Metric.Metric.Histogram<Duration.Duration>;
175
+ }
176
+ interface ReporterPolicyHooks {
177
+ readonly onRestart?: (cause: Cause.Cause<never>) => Effect.Effect<void>;
178
+ readonly onExhausted?: (cause: Cause.Cause<never>) => Effect.Effect<void>;
179
+ }
180
+ type PollLoop<E, R> = {
181
+ readonly _tag: 'Poll';
182
+ readonly gate: Effect.Effect<Option.Option<Effect.Effect<void, E, R>>, E, R>;
183
+ readonly interval: Duration.DurationInput;
184
+ };
185
+ type StreamLoop<E, R> = {
186
+ readonly _tag: 'Stream';
187
+ readonly stream: Stream.Stream<unknown, E, R>;
188
+ };
189
+ type SubscriptionLoop<E, R> = {
190
+ readonly _tag: 'Subscription';
191
+ readonly acquire: Effect.Effect<void, E, R>;
192
+ };
193
+ type LoopShape<E, R> = PollLoop<E, R> | StreamLoop<E, R> | SubscriptionLoop<E, R>;
194
+ interface Worker<E, R, L extends LockConfig = LockConfig> {
195
+ readonly [WorkerTypeId]: WorkerTypeId;
196
+ readonly name: string;
197
+ readonly loop: LoopShape<E, R>;
198
+ readonly child: typeof ChildPolicyConfig.Type;
199
+ readonly tick: typeof TickPolicyConfig.Type;
200
+ readonly tickHooks: TickPolicyHooks;
201
+ readonly lock: L;
202
+ }
203
+ interface Supervisor<E, R, L extends LockConfig = LockConfig> {
204
+ readonly [SupervisorTypeId]: SupervisorTypeId;
205
+ readonly name: string;
206
+ readonly strategy: 'one_for_one' | 'one_for_all' | 'rest_for_one';
207
+ readonly children: ReadonlyArray<Worker<E, R> | Supervisor<E, R>>;
208
+ readonly supervision: Effect.Effect<SupervisionPolicy>;
209
+ readonly lock: L;
210
+ readonly reporter: ReporterPolicyHooks;
211
+ }
212
+ interface DynamicSpec<E, R, Args> {
213
+ readonly [DynamicSpecTypeId]: DynamicSpecTypeId;
214
+ readonly name: string;
215
+ readonly child: (args: Args) => Worker<E, R>;
216
+ readonly maxChildren: number;
217
+ }
218
+ type Child<E, R> = Worker<E, R> | Supervisor<E, R>;
219
+ declare const isWorker: <E, R>(x: Child<E, R>) => x is Worker<E, R>;
220
+ declare const isSupervisor: <E, R>(x: Child<E, R>) => x is Supervisor<E, R>;
221
+ //#endregion
222
+ //#region src/daemon.d.ts
223
+ interface CommonOpts<L extends LockConfig> {
224
+ readonly name: string;
225
+ readonly child?: typeof ChildPolicyConfig.Type;
226
+ readonly tick: typeof TickPolicyConfig.Type;
227
+ readonly tickHooks?: TickPolicyHooks;
228
+ readonly lock: L;
229
+ }
230
+ type PollOpts<A, E, R, L extends LockConfig> = CommonOpts<L> & {
231
+ readonly interval: Duration.DurationInput;
232
+ } & ({
233
+ readonly prereq?: undefined;
234
+ readonly work: Effect.Effect<A, E, R>;
235
+ } | {
236
+ readonly prereq: Effect.Effect<Option.Option<A>, E, R>;
237
+ readonly work: (data: A) => Effect.Effect<void, E, R>;
238
+ });
239
+ declare const poll: <A, E, R, L extends LockConfig>(opts: PollOpts<A, E, R, L>) => Worker<E, R, L>;
240
+ declare const stream: <A, E, R, L extends LockConfig>(opts: CommonOpts<L> & {
241
+ readonly stream: Stream.Stream<A, E, R>;
242
+ }) => Worker<E, R, L>;
243
+ declare const subscription: <A, E, R, L extends LockConfig>(opts: CommonOpts<L> & {
244
+ readonly acquire: Effect.Effect<A, E, R>;
245
+ }) => Worker<E, R, L>;
246
+ declare const Daemon: {
247
+ readonly poll: <A, E, R, L extends LockConfig>(opts: PollOpts<A, E, R, L>) => Worker<E, R, L>;
248
+ readonly stream: <A, E, R, L extends LockConfig>(opts: CommonOpts<L> & {
249
+ readonly stream: Stream.Stream<A, E, R>;
250
+ }) => Worker<E, R, L>;
251
+ readonly subscription: <A, E, R, L extends LockConfig>(opts: CommonOpts<L> & {
252
+ readonly acquire: Effect.Effect<A, E, R>;
253
+ }) => Worker<E, R, L>;
254
+ };
255
+ //#endregion
256
+ //#region src/leader-lock.schema.d.ts
257
+ declare const LeaderLockNotAcquired_base: Schema.TaggedErrorClass<LeaderLockNotAcquired, "LeaderLockNotAcquired", {
258
+ readonly _tag: Schema.tag<"LeaderLockNotAcquired">;
259
+ } & {
260
+ key: typeof Schema.String;
261
+ }>;
262
+ declare class LeaderLockNotAcquired extends LeaderLockNotAcquired_base {}
263
+ declare const LeaderLockInfraError_base: Schema.TaggedErrorClass<LeaderLockInfraError, "LeaderLockInfraError", {
264
+ readonly _tag: Schema.tag<"LeaderLockInfraError">;
265
+ } & {
266
+ key: typeof Schema.String;
267
+ cause: typeof Schema.Unknown;
268
+ }>;
269
+ declare class LeaderLockInfraError extends LeaderLockInfraError_base {}
270
+ type LeaderLockAcquireError = LeaderLockNotAcquired | LeaderLockInfraError;
271
+ //#endregion
272
+ //#region src/leader-lock.d.ts
273
+ interface LeaderLockService {
274
+ readonly withLock: <A, E, R>(key: string, self: Effect.Effect<A, E, R>) => Effect.Effect<Option.Option<A>, E | LeaderLockInfraError, R>;
275
+ }
276
+ declare const LeaderLock_base: Context.TagClass<LeaderLock, "@systemfsoftware/effect-daemon-spec/leader-lock/LeaderLock", LeaderLockService>;
277
+ declare class LeaderLock extends LeaderLock_base {
278
+ static readonly Noop: Layer.Layer<LeaderLock>;
279
+ }
280
+ interface LeaderLockOptions {
281
+ readonly key: string;
282
+ readonly mode: 'required' | 'optional';
283
+ }
284
+ declare const withLeaderLock: {
285
+ (options: LeaderLockOptions): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A | void, E | LeaderLockAcquireError, R | LeaderLock>;
286
+ <A, E, R>(self: Effect.Effect<A, E, R>, options: LeaderLockOptions): Effect.Effect<A | void, E | LeaderLockAcquireError, R | LeaderLock>;
287
+ };
288
+ //#endregion
289
+ //#region src/lock-primitive.schema.d.ts
290
+ declare const LockPrimitiveError_base: Schema.TaggedErrorClass<LockPrimitiveError, "LockPrimitiveError", {
291
+ readonly _tag: Schema.tag<"LockPrimitiveError">;
292
+ } & {
293
+ key: typeof Schema.String;
294
+ cause: typeof Schema.Unknown;
295
+ }>;
296
+ declare class LockPrimitiveError extends LockPrimitiveError_base {}
297
+ //#endregion
298
+ //#region src/lock-primitive.d.ts
299
+ interface LockPrimitiveService {
300
+ readonly tryAcquire: (key: string) => Effect.Effect<boolean, LockPrimitiveError, Scope.Scope>;
301
+ }
302
+ declare const LockPrimitive_base: Context.TagClass<LockPrimitive, "@systemfsoftware/effect-daemon-spec/lock-primitive/LockPrimitive", LockPrimitiveService>;
303
+ declare class LockPrimitive extends LockPrimitive_base {}
304
+ declare const LeaderLockFromPrimitive: Layer.Layer<LeaderLock, never, LockPrimitive>;
305
+ //#endregion
306
+ //#region src/run.d.ts
307
+ declare function worker<E, R>(w: Worker<E, R, {
308
+ mode: 'none';
309
+ }>): Effect.Effect<DaemonHealth, never, R | DaemonReporter | Scope.Scope>;
310
+ declare function worker<E, R>(w: Worker<E, R, LockConfig>): Effect.Effect<DaemonHealth, never, R | LeaderLock | DaemonReporter | Scope.Scope>;
311
+ declare function supervisor<E, R>(s: Supervisor<E, R, {
312
+ mode: 'none';
313
+ }>): Effect.Effect<SupervisorHealth, never, R | DaemonReporter | Scope.Scope>;
314
+ declare function supervisor<E, R>(s: Supervisor<E, R, LockConfig>): Effect.Effect<SupervisorHealth, never, R | LeaderLock | DaemonReporter | Scope.Scope>;
315
+ declare const run: {
316
+ readonly worker: typeof worker;
317
+ readonly supervisor: typeof supervisor;
318
+ readonly dynamic: <E, R, Args>(spec: DynamicSpec<E, R, Args>) => Effect.Effect<DynamicHandle<Args, R | LeaderLock | DaemonReporter | Scope.Scope>, never, R | LeaderLock | DaemonReporter | Scope.Scope>;
319
+ };
320
+ //#endregion
321
+ //#region src/supervisor.d.ts
322
+ interface SupervisorOpts<E, R, L extends LockConfig> {
323
+ readonly name: string;
324
+ readonly children: ReadonlyArray<Child<E, R>>;
325
+ readonly supervision: Effect.Effect<SupervisionPolicy>;
326
+ readonly lock: L;
327
+ readonly reporter?: ReporterPolicyHooks;
328
+ }
329
+ declare const oneForOne: <E, R, L extends LockConfig = LockConfig>(opts: SupervisorOpts<E, R, L>) => Supervisor<E, R, L>;
330
+ declare const oneForAll: <E, R, L extends LockConfig = LockConfig>(opts: SupervisorOpts<E, R, L>) => Supervisor<E, R, L>;
331
+ declare const restForOne: <E, R, L extends LockConfig = LockConfig>(opts: SupervisorOpts<E, R, L>) => Supervisor<E, R, L>;
332
+ declare const dynamic: <E, R, Args>(opts: {
333
+ readonly name: string;
334
+ readonly child: (args: Args) => Worker<E, R>;
335
+ readonly maxChildren?: number;
336
+ }) => DynamicSpec<E, R, Args>;
337
+ //#endregion
338
+ export { BoundedIntensity, Child, ChildPolicyConfig, ChildRef, CommonOpts, Daemon, DaemonHealth, DaemonReporter, DaemonReporterService, DynamicHandle, DynamicLimitExceeded, DynamicSpec, DynamicSpecTypeId, Intensity, IntensityConfig, IntensityTypeId, LeaderConfig, LeaderLock, type LeaderLockAcquireError, LeaderLockFromPrimitive, LeaderLockInfraError, LeaderLockNotAcquired, LeaderLockOptions, LeaderLockService, LockConfig, LockPolicyConfig, LockPrimitive, LockPrimitiveError, LockPrimitiveService, LoopShape, PollLoop, PollOpts, ReporterPolicyHooks, StreamLoop, SubscriptionLoop, Supervision, SupervisionConfig, SupervisionPolicy, Supervisor, SupervisorHealth, type SupervisorOpts, SupervisorTypeId, TaskConfig, TickPolicyConfig, TickPolicyHooks, UnboundedIntensity, Worker, WorkerConfig, WorkerTypeId, cappedBackoff, dynamic, healthStateGauge, isSupervisor, isWorker, oneForAll, oneForOne, poll, restForOne, run, stream, subscription, supervisor, supervisorChildrenGauge, supervisorExhaustionsCounter, supervisorRestartsCounter, withLeaderLock, worker };