@vielzeug/clockwork 2.1.0 → 2.2.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/README.md CHANGED
@@ -51,7 +51,6 @@ actor.dispose();
51
51
  | `machine.createActor(options?)` | Create an owned runtime actor |
52
52
  | `Actor` | Runtime resource with a readonly snapshot, subscriptions, and disposal |
53
53
  | `ClockworkError` | Validation error with stable `code` |
54
- | `debugActor(actor, options?)` | Observe committed actor snapshots from `/devtools` |
55
54
 
56
55
  ## Async invokes and timers
57
56
 
@@ -84,23 +83,22 @@ const loader = defineMachine<{ data: string }, Event>()({
84
83
  });
85
84
  ```
86
85
 
87
- ## Devtools
86
+ ## Observability
88
87
 
89
- `debugActor(actor, options?)` observes committed snapshots with `console.debug`. It does not modify actor behavior or trace dispatches and runtime errors.
88
+ `actor.subscribe(listener)` observes committed snapshots. It does not modify actor behavior or trace dispatches and runtime errors.
90
89
 
91
90
  ```ts
92
91
  import { defineMachine } from '@vielzeug/clockwork';
93
- import { debugActor } from '@vielzeug/clockwork/devtools';
94
92
 
95
93
  const machine = defineMachine<Record<string, never>, { type: 'NEXT' }>()({
96
94
  initial: 'idle',
97
95
  states: { idle: { on: { NEXT: { target: 'idle' } } } },
98
96
  });
99
97
  const actor = machine.createActor();
100
- const stopDebugging = debugActor(actor);
98
+ const stop = actor.subscribe((snapshot) => console.debug(snapshot.state));
101
99
 
102
100
  actor.send({ type: 'NEXT' });
103
- stopDebugging();
101
+ stop();
104
102
  actor.dispose();
105
103
  ```
106
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielzeug/clockwork",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Framework-neutral typed finite state machines with pure transitions and actors",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,20 +22,9 @@
22
22
  "import": "./dist/index.js",
23
23
  "require": "./dist/index.cjs",
24
24
  "types": "./dist/index.d.ts"
25
- },
26
- "./devtools": {
27
- "import": "./dist/devtools.js",
28
- "require": "./dist/devtools.cjs",
29
- "types": "./dist/devtools.d.ts"
30
- }
31
- },
32
- "typesVersions": {
33
- "*": {
34
- "devtools": [
35
- "dist/devtools.d.ts"
36
- ]
37
25
  }
38
26
  },
27
+ "sideEffects": false,
39
28
  "publishConfig": {
40
29
  "access": "public",
41
30
  "registry": "https://registry.npmjs.org/"
package/dist/devtools.cjs DELETED
@@ -1,2 +0,0 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=(e,t={})=>{let n=t.logger??(e=>console.debug(`[clockwork] snapshot`,e));return e.subscribe(e=>{try{n(e)}catch{}})};exports.debugActor=e;
2
- //# sourceMappingURL=devtools.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devtools.cjs","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["import type { Actor, MachineEvent, MachineSnapshot } from './types.js';\n\nexport type DebugActorOptions<State extends string, Context extends Record<string, unknown>> = {\n readonly logger?: (snapshot: MachineSnapshot<State, Context>) => void;\n};\n\n/**\n * Observes committed actor snapshots with `console.debug` without changing actor behavior.\n * Import from `@vielzeug/clockwork/devtools` so this development-only observability stays opt-in.\n */\nexport const debugActor = <State extends string, Context extends Record<string, unknown>, Event extends MachineEvent>(\n actor: Actor<State, Context, Event>,\n options: DebugActorOptions<State, Context> = {},\n): (() => void) => {\n const logger =\n options.logger ?? ((snapshot: MachineSnapshot<State, Context>) => console.debug('[clockwork] snapshot', snapshot));\n\n return actor.subscribe((snapshot) => {\n try {\n logger(snapshot);\n } catch {\n // Observability must not affect the actor's error policy.\n }\n });\n};\n"],"mappings":"mEAUA,IAAa,GACX,EACA,EAA6C,CAAC,IAC7B,CACjB,IAAM,EACJ,EAAQ,SAAY,GAA8C,QAAQ,MAAM,uBAAwB,CAAQ,GAElH,OAAO,EAAM,UAAW,GAAa,CACnC,GAAI,CACF,EAAO,CAAQ,CACjB,MAAQ,CAER,CACF,CAAC,CACH"}
@@ -1,10 +0,0 @@
1
- import type { Actor, MachineEvent, MachineSnapshot } from './types.js';
2
- export type DebugActorOptions<State extends string, Context extends Record<string, unknown>> = {
3
- readonly logger?: (snapshot: MachineSnapshot<State, Context>) => void;
4
- };
5
- /**
6
- * Observes committed actor snapshots with `console.debug` without changing actor behavior.
7
- * Import from `@vielzeug/clockwork/devtools` so this development-only observability stays opt-in.
8
- */
9
- export declare const debugActor: <State extends string, Context extends Record<string, unknown>, Event extends MachineEvent>(actor: Actor<State, Context, Event>, options?: DebugActorOptions<State, Context>) => (() => void);
10
- //# sourceMappingURL=devtools.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devtools.d.ts","sourceRoot":"","sources":["../src/devtools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEvE,MAAM,MAAM,iBAAiB,CAAC,KAAK,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC7F,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACvE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,SAAS,MAAM,EAAE,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,SAAS,YAAY,EAClH,OAAO,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EACnC,UAAS,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAM,KAC9C,CAAC,MAAM,IAAI,CAWb,CAAC"}
package/dist/devtools.js DELETED
@@ -1,13 +0,0 @@
1
- //#region src/devtools.ts
2
- var e = (e, t = {}) => {
3
- let n = t.logger ?? ((e) => console.debug("[clockwork] snapshot", e));
4
- return e.subscribe((e) => {
5
- try {
6
- n(e);
7
- } catch {}
8
- });
9
- };
10
- //#endregion
11
- export { e as debugActor };
12
-
13
- //# sourceMappingURL=devtools.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"devtools.js","names":[],"sources":["../src/devtools.ts"],"sourcesContent":["import type { Actor, MachineEvent, MachineSnapshot } from './types.js';\n\nexport type DebugActorOptions<State extends string, Context extends Record<string, unknown>> = {\n readonly logger?: (snapshot: MachineSnapshot<State, Context>) => void;\n};\n\n/**\n * Observes committed actor snapshots with `console.debug` without changing actor behavior.\n * Import from `@vielzeug/clockwork/devtools` so this development-only observability stays opt-in.\n */\nexport const debugActor = <State extends string, Context extends Record<string, unknown>, Event extends MachineEvent>(\n actor: Actor<State, Context, Event>,\n options: DebugActorOptions<State, Context> = {},\n): (() => void) => {\n const logger =\n options.logger ?? ((snapshot: MachineSnapshot<State, Context>) => console.debug('[clockwork] snapshot', snapshot));\n\n return actor.subscribe((snapshot) => {\n try {\n logger(snapshot);\n } catch {\n // Observability must not affect the actor's error policy.\n }\n });\n};\n"],"mappings":";AAUA,IAAa,KACX,GACA,IAA6C,CAAC,MAC7B;CACjB,IAAM,IACJ,EAAQ,YAAY,MAA8C,QAAQ,MAAM,wBAAwB,CAAQ;CAElH,OAAO,EAAM,WAAW,MAAa;EACnC,IAAI;GACF,EAAO,CAAQ;EACjB,QAAQ,CAER;CACF,CAAC;AACH"}