@mantaq/sugar 0.0.2 → 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.
package/README.md CHANGED
@@ -89,7 +89,7 @@ import { events } from "@mantaq/sugar";
89
89
 
90
90
  const e = events("fetch", "resolve", "fail");
91
91
 
92
- e.fetch.create(); // { id: "fetch" }
92
+ e.fetch.create(); // { type: "fetch" }
93
93
  e.resolve.is(emittedEvent); // boolean
94
94
 
95
95
  const actor = new Actor({
@@ -203,7 +203,7 @@ map.kill("child1");
203
203
 
204
204
  ```ts
205
205
  map.spawn("child1", () => createChild());
206
- map.spawn("child1", () => createChild()); // overwrites silently — previous child lost
206
+ map.spawn("child1", () => createChild()); // warns, aborts the previous child, replaces
207
207
  ```
208
208
 
209
209
  `ensure()` is idempotent — safe to call repeatedly. `spawn()` always replaces.
@@ -217,8 +217,8 @@ import { withPromise } from "@mantaq/sugar";
217
217
 
218
218
  // Correct — abort-aware
219
219
  withPromise(fetchData(), input.signal, input.emit, {
220
- success: (data) => ({ id: "loaded", data }),
221
- error: (err) => ({ id: "loadFailed", error: String(err) }),
220
+ success: (data) => ({ type: "loaded", payload: data }),
221
+ error: (err) => ({ type: "loadFailed", payload: String(err) }),
222
222
  });
223
223
  ```
224
224
 
@@ -227,14 +227,14 @@ withPromise(fetchData(), input.signal, input.emit, {
227
227
  ```ts
228
228
  fetchData()
229
229
  .then((data) => {
230
- input.emit({ id: "loaded", data }); // fires even if actor destroyed
230
+ input.emit({ type: "loaded", payload: data }); // fires even if actor destroyed
231
231
  })
232
232
  .catch((err) => {
233
- input.emit({ id: "loadFailed", error: String(err) }); // same problem
233
+ input.emit({ type: "loadFailed", payload: String(err) }); // same problem
234
234
  });
235
235
  ```
236
236
 
237
- `withPromise` checks `isAborted(signal)` before each emit. Manual chains fire events into destroyed actors.
237
+ `withPromise` checks `signal.aborted` before each emit. Manual chains fire events into destroyed actors.
238
238
 
239
239
  ## Helpers
240
240
 
@@ -302,7 +302,7 @@ Send an event to every key in an `ActorMap` (or any `SendableMap`):
302
302
  ```ts
303
303
  import { broadcast } from "@mantaq/sugar";
304
304
 
305
- broadcast(map, { id: "ping" });
305
+ broadcast(map, { type: "ping" });
306
306
  ```
307
307
 
308
308
  Works with `ActorMap` or any object implementing `{ keys(): string[]; send(key, event): void }`.
@@ -344,7 +344,7 @@ Batch-create `EventRef`s as a typed record:
344
344
  import { events } from "@mantaq/sugar";
345
345
 
346
346
  const e = events("click", "submit");
347
- e.click.create(); // { id: "click" }
347
+ e.click.create(); // { type: "click" }
348
348
  e.click.is(emittedEvent); // boolean
349
349
  ```
350
350
 
@@ -356,8 +356,8 @@ Bridge a promise into actor events. Emits `success` on resolve, `error` on rejec
356
356
  import { withPromise } from "@mantaq/sugar";
357
357
 
358
358
  withPromise(fetchData(), input.signal, input.emit, {
359
- success: (data) => ({ id: "loaded", data }),
360
- error: (err) => ({ id: "loadFailed", error: String(err) }),
359
+ success: (data) => ({ type: "loaded", payload: data }),
360
+ error: (err) => ({ type: "loadFailed", payload: String(err) }),
361
361
  });
362
362
  ```
363
363
 
@@ -368,7 +368,7 @@ Schedule a timeout event through the actor's clock. Aborts cleanly if the actor
368
368
  ```ts
369
369
  import { withTimeout } from "@mantaq/sugar";
370
370
 
371
- withTimeout(5000, input, () => ({ id: "timeout", reason: "exceeded" }));
371
+ withTimeout(5000, input, () => ({ type: "timeout", payload: { reason: "exceeded" } }));
372
372
  ```
373
373
 
374
374
  ## Migration from Core
package/dist/index.d.mts CHANGED
@@ -6,8 +6,8 @@ declare function matches(actor: {
6
6
  //#endregion
7
7
  //#region src/transitions/broadcast.d.ts
8
8
  type EventLike = {
9
- id: string;
10
- [key: string]: unknown;
9
+ type: string;
10
+ payload?: unknown;
11
11
  };
12
12
  type SendableEvent = AnyEventRef | EventLike;
13
13
  interface SendableMap<T extends SendableEvent = SendableEvent> {
@@ -38,17 +38,17 @@ declare function events<T extends string>(...names: T[]): { [K in T]: EventRef<K
38
38
  //#endregion
39
39
  //#region src/effects/promise.d.ts
40
40
  type EmitFn = (event: {
41
- id: string;
42
- [key: string]: unknown;
41
+ type: string;
42
+ payload?: unknown;
43
43
  }) => void;
44
44
  declare function withPromise<T>(promise: Promise<T>, signal: AbortSignal, emit: EmitFn, events: {
45
45
  success: (data: T) => {
46
- id: string;
47
- [key: string]: unknown;
46
+ type: string;
47
+ payload?: unknown;
48
48
  };
49
49
  error: (err: unknown) => {
50
- id: string;
51
- [key: string]: unknown;
50
+ type: string;
51
+ payload?: unknown;
52
52
  };
53
53
  }): void;
54
54
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mantaq/sugar",
3
- "version": "0.0.2",
3
+ "version": "0.1.0",
4
4
  "description": "Userland sugar for mantaq actors — matches, effect helpers, transition utilities.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,8 +20,8 @@
20
20
  "access": "public"
21
21
  },
22
22
  "dependencies": {
23
- "@mantaq/core": "0.0.2",
24
- "@mantaq/utils": "0.0.1"
23
+ "@mantaq/core": "0.1.0",
24
+ "@mantaq/utils": "0.0.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@stryker-mutator/core": "^9",