@swirls/looms 0.15.0 → 0.16.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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @swirls/looms
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8775cea: `@swirls/looms/react` can keep a run's events on the device. Pass `cache={indexedDbEventCache()}` to `LoomsProvider`, or `cache` to `createLoomsStore`: the store keeps the run's durable events, starts from them the next time it opens, and downloads only what was appended since. Ephemeral events are never kept, and a cache that turns out to be ahead of the host's log is dropped. `EventCache` is the interface to implement for other storage, and `memoryEventCache()` is one for tests.
8
+
9
+ The store also reports timings. Pass an `observer` to `LoomsProvider` or `createLoomsStore` to be told when a store has caught up (`store.synced`, with how long it took and how many events came from the cache), when its connection status changes, and how long each commit took to be acknowledged, confirmed, or to fail.
10
+
11
+ Actor hosts and `LoomsDurableObject` accept the runtime's `observer`, so a run hosted in a cell or a Durable Object can report its wakes, appends, snapshots and effect attempts.
12
+
3
13
  ## 0.15.0
4
14
 
5
15
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  import { type AnyRuntimeModule, type DefinitionResolver, type EventInput, type EventStore, type EventStoreTrimCoverage, type LaunchRunArgs, type RunAttributeFields, type RunLauncher, type RunState, type RunStatusSnapshot, type SnapshotStore } from '@swirls/looms/core';
2
- import { type Authorize, type EffectWorker, type LoomsRuntime, type RunSignalOptions, type StartResult, type StartRunArgs, type WakeScheduler } from '@swirls/looms/runtime';
2
+ import { type Authorize, type EffectWorker, type LoomsRuntime, type RunSignalOptions, type StartResult, type StartRunArgs, type WakeScheduler, type RuntimeObserver } from '@swirls/looms/runtime';
3
3
  export interface ActorCellOptions<TModules extends readonly AnyRuntimeModule[] = readonly AnyRuntimeModule[]> {
4
4
  readonly runId: string;
5
5
  readonly store: EventStore;
@@ -28,6 +28,8 @@ export interface ActorCellOptions<TModules extends readonly AnyRuntimeModule[] =
28
28
  readonly worker?: EffectWorker;
29
29
  /** Declared run attributes. See `CreateRuntimeOptions`. */
30
30
  readonly attributes?: RunAttributeFields;
31
+ /** Told about wakes, appends, snapshots and effect attempts. See `CreateRuntimeOptions`. */
32
+ readonly observer?: RuntimeObserver;
31
33
  }
32
34
  export interface ActorCell<TModules extends readonly AnyRuntimeModule[] = readonly AnyRuntimeModule[]> {
33
35
  readonly runId: string;
@@ -22,6 +22,7 @@ export function createActorCell(options) {
22
22
  snapshotStore: options.snapshotStore,
23
23
  trimAfterSnapshot: options.trimAfterSnapshot,
24
24
  attributes: options.attributes,
25
+ observer: options.observer,
25
26
  });
26
27
  const provide = (effect) => Effect.runPromise(Effect.provideService(effect, EventStoreTag, store));
27
28
  const fetchHandler = createFetchHandler({ runtime, store, authorize: options.authorize });
@@ -1,5 +1,5 @@
1
1
  import type { AnyRuntimeModule, DefinitionResolver, EventInput, EventStore, EventStoreTrimCoverage, RunAttributeFields, RunLauncher, RunState, SnapshotStore } from '@swirls/looms/core';
2
- import { type Authorize, type RunSignalOptions, type StartResult, type StartRunArgs } from '@swirls/looms/runtime';
2
+ import { type Authorize, type RunSignalOptions, type StartResult, type StartRunArgs, type RuntimeObserver } from '@swirls/looms/runtime';
3
3
  import { type ActorCell } from './cell';
4
4
  export interface LocalActorHostOptions<TModules extends readonly AnyRuntimeModule[] = readonly AnyRuntimeModule[]> {
5
5
  readonly createStore: (runId: string) => EventStore | Promise<EventStore>;
@@ -8,6 +8,8 @@ export interface LocalActorHostOptions<TModules extends readonly AnyRuntimeModul
8
8
  readonly definitionResolver?: DefinitionResolver;
9
9
  /** Declared run attributes. See `CreateRuntimeOptions`. */
10
10
  readonly attributes?: RunAttributeFields;
11
+ /** Told about wakes, appends, snapshots and effect attempts. See `CreateRuntimeOptions`. */
12
+ readonly observer?: RuntimeObserver;
11
13
  readonly snapshotStore?: SnapshotStore;
12
14
  readonly snapshotEvery?: number;
13
15
  readonly maxWakeIterations?: number;
@@ -60,6 +60,7 @@ export function createLocalActorHost(options) {
60
60
  modules: options.modules,
61
61
  definitionResolver: options.definitionResolver,
62
62
  attributes: options.attributes,
63
+ observer: options.observer,
63
64
  snapshotStore: options.snapshotStore,
64
65
  snapshotEvery: options.snapshotEvery,
65
66
  maxWakeIterations: options.maxWakeIterations,
@@ -9,32 +9,6 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
9
9
  }[];
10
10
  readonly schema?: import("effect/Schema").Json | undefined;
11
11
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
12
- readonly type: "approval.decided";
13
- readonly payload: {
14
- readonly approvalId: string;
15
- readonly actionId: string;
16
- readonly outcome: "approve" | "reject";
17
- readonly payload?: import("effect/Schema").Json | undefined;
18
- };
19
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
20
- readonly type: "approval.requested";
21
- readonly payload: {
22
- readonly approvalId: string;
23
- readonly title: string;
24
- readonly description?: string | undefined;
25
- readonly actions: readonly {
26
- readonly id: string;
27
- readonly label: string;
28
- readonly outcome: "approve" | "reject";
29
- }[];
30
- readonly schema?: import("effect/Schema").Json | undefined;
31
- };
32
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
33
- readonly type: "approval.timed_out";
34
- readonly payload: {
35
- readonly approvalId: string;
36
- };
37
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
38
12
  readonly type: "runtime.child.close.requested";
39
13
  readonly payload: {
40
14
  readonly policy: "terminate" | "wait";
@@ -280,4 +254,30 @@ export declare const requestApprovalEffect: NoInfer<import("@swirls/looms/core")
280
254
  readonly payload: import("effect/Schema").Json;
281
255
  };
282
256
  };
257
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
258
+ readonly type: "approval.decided";
259
+ readonly payload: {
260
+ readonly approvalId: string;
261
+ readonly actionId: string;
262
+ readonly outcome: "approve" | "reject";
263
+ readonly payload?: import("effect/Schema").Json | undefined;
264
+ };
265
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
266
+ readonly type: "approval.requested";
267
+ readonly payload: {
268
+ readonly approvalId: string;
269
+ readonly title: string;
270
+ readonly description?: string | undefined;
271
+ readonly actions: readonly {
272
+ readonly id: string;
273
+ readonly label: string;
274
+ readonly outcome: "approve" | "reject";
275
+ }[];
276
+ readonly schema?: import("effect/Schema").Json | undefined;
277
+ };
278
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
279
+ readonly type: "approval.timed_out";
280
+ readonly payload: {
281
+ readonly approvalId: string;
282
+ };
283
283
  })>>;
@@ -32,32 +32,6 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
32
32
  }[];
33
33
  readonly schema?: import("effect/Schema").Json | undefined;
34
34
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
35
- readonly type: "approval.decided";
36
- readonly payload: {
37
- readonly approvalId: string;
38
- readonly actionId: string;
39
- readonly outcome: "approve" | "reject";
40
- readonly payload?: import("effect/Schema").Json | undefined;
41
- };
42
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
43
- readonly type: "approval.requested";
44
- readonly payload: {
45
- readonly approvalId: string;
46
- readonly title: string;
47
- readonly description?: string | undefined;
48
- readonly actions: readonly {
49
- readonly id: string;
50
- readonly label: string;
51
- readonly outcome: "approve" | "reject";
52
- }[];
53
- readonly schema?: import("effect/Schema").Json | undefined;
54
- };
55
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
56
- readonly type: "approval.timed_out";
57
- readonly payload: {
58
- readonly approvalId: string;
59
- };
60
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
61
35
  readonly type: "runtime.child.close.requested";
62
36
  readonly payload: {
63
37
  readonly policy: "terminate" | "wait";
@@ -303,6 +277,32 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
303
277
  readonly payload: import("effect/Schema").Json;
304
278
  };
305
279
  };
280
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
281
+ readonly type: "approval.decided";
282
+ readonly payload: {
283
+ readonly approvalId: string;
284
+ readonly actionId: string;
285
+ readonly outcome: "approve" | "reject";
286
+ readonly payload?: import("effect/Schema").Json | undefined;
287
+ };
288
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
289
+ readonly type: "approval.requested";
290
+ readonly payload: {
291
+ readonly approvalId: string;
292
+ readonly title: string;
293
+ readonly description?: string | undefined;
294
+ readonly actions: readonly {
295
+ readonly id: string;
296
+ readonly label: string;
297
+ readonly outcome: "approve" | "reject";
298
+ }[];
299
+ readonly schema?: import("effect/Schema").Json | undefined;
300
+ };
301
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
302
+ readonly type: "approval.timed_out";
303
+ readonly payload: {
304
+ readonly approvalId: string;
305
+ };
306
306
  })>;
307
307
  }, {}, {
308
308
  pendingApprovals: import("@swirls/looms/core").ProjectionDefinition<{
@@ -346,32 +346,6 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
346
346
  }[];
347
347
  readonly schema?: import("effect/Schema").Json | undefined;
348
348
  }, never, (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
349
- readonly type: "approval.decided";
350
- readonly payload: {
351
- readonly approvalId: string;
352
- readonly actionId: string;
353
- readonly outcome: "approve" | "reject";
354
- readonly payload?: import("effect/Schema").Json | undefined;
355
- };
356
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
357
- readonly type: "approval.requested";
358
- readonly payload: {
359
- readonly approvalId: string;
360
- readonly title: string;
361
- readonly description?: string | undefined;
362
- readonly actions: readonly {
363
- readonly id: string;
364
- readonly label: string;
365
- readonly outcome: "approve" | "reject";
366
- }[];
367
- readonly schema?: import("effect/Schema").Json | undefined;
368
- };
369
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
370
- readonly type: "approval.timed_out";
371
- readonly payload: {
372
- readonly approvalId: string;
373
- };
374
- }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
375
349
  readonly type: "runtime.child.close.requested";
376
350
  readonly payload: {
377
351
  readonly policy: "terminate" | "wait";
@@ -617,6 +591,32 @@ export declare function approval(): import("@swirls/looms/core").RuntimeModule<"
617
591
  readonly payload: import("effect/Schema").Json;
618
592
  };
619
593
  };
594
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
595
+ readonly type: "approval.decided";
596
+ readonly payload: {
597
+ readonly approvalId: string;
598
+ readonly actionId: string;
599
+ readonly outcome: "approve" | "reject";
600
+ readonly payload?: import("effect/Schema").Json | undefined;
601
+ };
602
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
603
+ readonly type: "approval.requested";
604
+ readonly payload: {
605
+ readonly approvalId: string;
606
+ readonly title: string;
607
+ readonly description?: string | undefined;
608
+ readonly actions: readonly {
609
+ readonly id: string;
610
+ readonly label: string;
611
+ readonly outcome: "approve" | "reject";
612
+ }[];
613
+ readonly schema?: import("effect/Schema").Json | undefined;
614
+ };
615
+ }) | (Omit<import("@swirls/looms/core").EventInput, "payload" | "type"> & {
616
+ readonly type: "approval.timed_out";
617
+ readonly payload: {
618
+ readonly approvalId: string;
619
+ };
620
620
  })>;
621
621
  };
622
622
  readonly threads: {};
@@ -1,7 +1,7 @@
1
1
  import { DurableObject } from 'cloudflare:workers';
2
2
  import { type AnyRuntimeModule, type DefinitionResolver, type EventInput, type BlobStore, type EventStoreTrimCoverage, type LaunchRunArgs, type RunAttributeFields, type RunLauncher, type RunState, type RunStatusSnapshot } from '@swirls/looms/core';
3
3
  import type { Projector } from '@swirls/looms/projectors';
4
- import { type Authorize, type EffectWorker, type RunSignalOptions, type StartResult, type StartRunArgs } from '@swirls/looms/runtime';
4
+ import { type Authorize, type EffectWorker, type RunSignalOptions, type StartResult, type StartRunArgs, type RuntimeObserver } from '@swirls/looms/runtime';
5
5
  import { type DeleteTerminalRunStorageOptions } from './delete-terminal-run-storage';
6
6
  export interface LoomsDurableObjectConfig {
7
7
  readonly modules: readonly AnyRuntimeModule[];
@@ -9,6 +9,8 @@ export interface LoomsDurableObjectConfig {
9
9
  readonly definitionResolver?: DefinitionResolver;
10
10
  /** Declared run attributes. Pass the same declaration to the replica. */
11
11
  readonly attributes?: RunAttributeFields;
12
+ /** Told about wakes, appends, snapshots and effect attempts. See `CreateRuntimeOptions`. */
13
+ readonly observer?: RuntimeObserver;
12
14
  readonly projectors?: readonly Projector[];
13
15
  /** Content-addressed store for event and snapshot JSON over the inline byte limits. */
14
16
  readonly blobs?: BlobStore;
@@ -54,6 +54,7 @@ export class LoomsDurableObject extends DurableObject {
54
54
  modules: config.modules,
55
55
  definitionResolver: config.definitionResolver,
56
56
  attributes: config.attributes,
57
+ observer: config.observer,
57
58
  snapshotEvery: config.snapshotEvery,
58
59
  maxWakeIterations: config.maxWakeIterations,
59
60
  livenessLeaseMs: config.livenessLeaseMs,