xstate 5.13.1 → 5.14.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.
Files changed (39) hide show
  1. package/actions/dist/xstate-actions.cjs.js +2 -2
  2. package/actions/dist/xstate-actions.development.cjs.js +2 -2
  3. package/actions/dist/xstate-actions.development.esm.js +2 -2
  4. package/actions/dist/xstate-actions.esm.js +2 -2
  5. package/actions/dist/xstate-actions.umd.min.js +1 -1
  6. package/actions/dist/xstate-actions.umd.min.js.map +1 -1
  7. package/actors/dist/xstate-actors.cjs.js +18 -15
  8. package/actors/dist/xstate-actors.development.cjs.js +18 -15
  9. package/actors/dist/xstate-actors.development.esm.js +18 -15
  10. package/actors/dist/xstate-actors.esm.js +18 -15
  11. package/actors/dist/xstate-actors.umd.min.js +1 -1
  12. package/actors/dist/xstate-actors.umd.min.js.map +1 -1
  13. package/dist/declarations/src/actors/callback.d.ts +4 -3
  14. package/dist/declarations/src/actors/index.d.ts +1 -1
  15. package/dist/declarations/src/actors/observable.d.ts +9 -7
  16. package/dist/declarations/src/actors/promise.d.ts +5 -4
  17. package/dist/declarations/src/actors/transition.d.ts +1 -1
  18. package/dist/declarations/src/createActor.d.ts +2 -2
  19. package/dist/declarations/src/system.d.ts +2 -2
  20. package/dist/declarations/src/types.d.ts +16 -13
  21. package/dist/{log-d06dd00b.development.cjs.js → log-505687fd.development.cjs.js} +1 -1
  22. package/dist/{log-5b14d850.cjs.js → log-7ae0ddf8.cjs.js} +1 -1
  23. package/dist/{log-c447a931.esm.js → log-b87cb6bd.esm.js} +1 -1
  24. package/dist/{log-b3b03961.development.esm.js → log-c943e6aa.development.esm.js} +1 -1
  25. package/dist/{raise-bf7a8462.development.cjs.js → raise-0cd7e521.development.cjs.js} +138 -130
  26. package/dist/{raise-150d5679.development.esm.js → raise-0f400094.development.esm.js} +138 -130
  27. package/dist/{raise-f406edbd.esm.js → raise-4e39e875.esm.js} +138 -130
  28. package/dist/{raise-ff8990f7.cjs.js → raise-f79d2832.cjs.js} +138 -130
  29. package/dist/xstate.cjs.js +2 -2
  30. package/dist/xstate.development.cjs.js +2 -2
  31. package/dist/xstate.development.esm.js +4 -4
  32. package/dist/xstate.esm.js +4 -4
  33. package/dist/xstate.umd.min.js +1 -1
  34. package/dist/xstate.umd.min.js.map +1 -1
  35. package/guards/dist/xstate-guards.cjs.js +1 -1
  36. package/guards/dist/xstate-guards.development.cjs.js +1 -1
  37. package/guards/dist/xstate-guards.development.esm.js +1 -1
  38. package/guards/dist/xstate-guards.esm.js +1 -1
  39. package/package.json +1 -1
@@ -95,13 +95,15 @@ function createDoneStateEvent(id, output) {
95
95
  function createDoneActorEvent(invokeId, output) {
96
96
  return {
97
97
  type: `xstate.done.actor.${invokeId}`,
98
- output
98
+ output,
99
+ actorId: invokeId
99
100
  };
100
101
  }
101
102
  function createErrorActorEvent(id, error) {
102
103
  return {
103
104
  type: `xstate.error.actor.${id}`,
104
- error
105
+ error,
106
+ actorId: id
105
107
  };
106
108
  }
107
109
  function createInitEvent(input) {
@@ -126,134 +128,6 @@ function reportUnhandledError(err) {
126
128
 
127
129
  const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
128
130
 
129
- function createScheduledEventId(actorRef, id) {
130
- return `${actorRef.sessionId}.${id}`;
131
- }
132
- let idCounter = 0;
133
- function createSystem(rootActor, options) {
134
- const children = new Map();
135
- const keyedActors = new Map();
136
- const reverseKeyedActors = new WeakMap();
137
- const inspectionObservers = new Set();
138
- const timerMap = {};
139
- const {
140
- clock,
141
- logger
142
- } = options;
143
- const scheduler = {
144
- schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
145
- const scheduledEvent = {
146
- source,
147
- target,
148
- event,
149
- delay,
150
- id,
151
- startedAt: Date.now()
152
- };
153
- const scheduledEventId = createScheduledEventId(source, id);
154
- system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
155
- const timeout = clock.setTimeout(() => {
156
- delete timerMap[scheduledEventId];
157
- delete system._snapshot._scheduledEvents[scheduledEventId];
158
- system._relay(source, target, event);
159
- }, delay);
160
- timerMap[scheduledEventId] = timeout;
161
- },
162
- cancel: (source, id) => {
163
- const scheduledEventId = createScheduledEventId(source, id);
164
- const timeout = timerMap[scheduledEventId];
165
- delete timerMap[scheduledEventId];
166
- delete system._snapshot._scheduledEvents[scheduledEventId];
167
- clock.clearTimeout(timeout);
168
- },
169
- cancelAll: actorRef => {
170
- for (const scheduledEventId in system._snapshot._scheduledEvents) {
171
- const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
172
- if (scheduledEvent.source === actorRef) {
173
- scheduler.cancel(actorRef, scheduledEvent.id);
174
- }
175
- }
176
- }
177
- };
178
- const sendInspectionEvent = event => {
179
- if (!inspectionObservers.size) {
180
- return;
181
- }
182
- const resolvedInspectionEvent = {
183
- ...event,
184
- rootId: rootActor.sessionId
185
- };
186
- inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
187
- };
188
- const system = {
189
- _snapshot: {
190
- _scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
191
- },
192
- _bookId: () => `x:${idCounter++}`,
193
- _register: (sessionId, actorRef) => {
194
- children.set(sessionId, actorRef);
195
- return sessionId;
196
- },
197
- _unregister: actorRef => {
198
- children.delete(actorRef.sessionId);
199
- const systemId = reverseKeyedActors.get(actorRef);
200
- if (systemId !== undefined) {
201
- keyedActors.delete(systemId);
202
- reverseKeyedActors.delete(actorRef);
203
- }
204
- },
205
- get: systemId => {
206
- return keyedActors.get(systemId);
207
- },
208
- _set: (systemId, actorRef) => {
209
- const existing = keyedActors.get(systemId);
210
- if (existing && existing !== actorRef) {
211
- throw new Error(`Actor with system ID '${systemId}' already exists.`);
212
- }
213
- keyedActors.set(systemId, actorRef);
214
- reverseKeyedActors.set(actorRef, systemId);
215
- },
216
- inspect: observer => {
217
- inspectionObservers.add(observer);
218
- },
219
- _sendInspectionEvent: sendInspectionEvent,
220
- _relay: (source, target, event) => {
221
- system._sendInspectionEvent({
222
- type: '@xstate.event',
223
- sourceRef: source,
224
- actorRef: target,
225
- event
226
- });
227
- target._send(event);
228
- },
229
- scheduler,
230
- getSnapshot: () => {
231
- return {
232
- _scheduledEvents: {
233
- ...system._snapshot._scheduledEvents
234
- }
235
- };
236
- },
237
- start: () => {
238
- const scheduledEvents = system._snapshot._scheduledEvents;
239
- system._snapshot._scheduledEvents = {};
240
- for (const scheduledId in scheduledEvents) {
241
- const {
242
- source,
243
- target,
244
- event,
245
- delay,
246
- id
247
- } = scheduledEvents[scheduledId];
248
- scheduler.schedule(source, target, event, delay, id);
249
- }
250
- },
251
- _clock: clock,
252
- _logger: logger
253
- };
254
- return system;
255
- }
256
-
257
131
  function matchesState(parentStateId, childStateId) {
258
132
  const parentStateValue = toStateValue(parentStateId);
259
133
  const childStateValue = toStateValue(childStateId);
@@ -411,6 +285,140 @@ function getAllOwnEventDescriptors(snapshot) {
411
285
  return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
412
286
  }
413
287
 
288
+ function createScheduledEventId(actorRef, id) {
289
+ return `${actorRef.sessionId}.${id}`;
290
+ }
291
+ let idCounter = 0;
292
+ function createSystem(rootActor, options) {
293
+ const children = new Map();
294
+ const keyedActors = new Map();
295
+ const reverseKeyedActors = new WeakMap();
296
+ const inspectionObservers = new Set();
297
+ const timerMap = {};
298
+ const {
299
+ clock,
300
+ logger
301
+ } = options;
302
+ const scheduler = {
303
+ schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
304
+ const scheduledEvent = {
305
+ source,
306
+ target,
307
+ event,
308
+ delay,
309
+ id,
310
+ startedAt: Date.now()
311
+ };
312
+ const scheduledEventId = createScheduledEventId(source, id);
313
+ system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
314
+ const timeout = clock.setTimeout(() => {
315
+ delete timerMap[scheduledEventId];
316
+ delete system._snapshot._scheduledEvents[scheduledEventId];
317
+ system._relay(source, target, event);
318
+ }, delay);
319
+ timerMap[scheduledEventId] = timeout;
320
+ },
321
+ cancel: (source, id) => {
322
+ const scheduledEventId = createScheduledEventId(source, id);
323
+ const timeout = timerMap[scheduledEventId];
324
+ delete timerMap[scheduledEventId];
325
+ delete system._snapshot._scheduledEvents[scheduledEventId];
326
+ clock.clearTimeout(timeout);
327
+ },
328
+ cancelAll: actorRef => {
329
+ for (const scheduledEventId in system._snapshot._scheduledEvents) {
330
+ const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
331
+ if (scheduledEvent.source === actorRef) {
332
+ scheduler.cancel(actorRef, scheduledEvent.id);
333
+ }
334
+ }
335
+ }
336
+ };
337
+ const sendInspectionEvent = event => {
338
+ if (!inspectionObservers.size) {
339
+ return;
340
+ }
341
+ const resolvedInspectionEvent = {
342
+ ...event,
343
+ rootId: rootActor.sessionId
344
+ };
345
+ inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
346
+ };
347
+ const system = {
348
+ _snapshot: {
349
+ _scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
350
+ },
351
+ _bookId: () => `x:${idCounter++}`,
352
+ _register: (sessionId, actorRef) => {
353
+ children.set(sessionId, actorRef);
354
+ return sessionId;
355
+ },
356
+ _unregister: actorRef => {
357
+ children.delete(actorRef.sessionId);
358
+ const systemId = reverseKeyedActors.get(actorRef);
359
+ if (systemId !== undefined) {
360
+ keyedActors.delete(systemId);
361
+ reverseKeyedActors.delete(actorRef);
362
+ }
363
+ },
364
+ get: systemId => {
365
+ return keyedActors.get(systemId);
366
+ },
367
+ _set: (systemId, actorRef) => {
368
+ const existing = keyedActors.get(systemId);
369
+ if (existing && existing !== actorRef) {
370
+ throw new Error(`Actor with system ID '${systemId}' already exists.`);
371
+ }
372
+ keyedActors.set(systemId, actorRef);
373
+ reverseKeyedActors.set(actorRef, systemId);
374
+ },
375
+ inspect: observerOrFn => {
376
+ const observer = toObserver(observerOrFn);
377
+ inspectionObservers.add(observer);
378
+ return {
379
+ unsubscribe() {
380
+ inspectionObservers.delete(observer);
381
+ }
382
+ };
383
+ },
384
+ _sendInspectionEvent: sendInspectionEvent,
385
+ _relay: (source, target, event) => {
386
+ system._sendInspectionEvent({
387
+ type: '@xstate.event',
388
+ sourceRef: source,
389
+ actorRef: target,
390
+ event
391
+ });
392
+ target._send(event);
393
+ },
394
+ scheduler,
395
+ getSnapshot: () => {
396
+ return {
397
+ _scheduledEvents: {
398
+ ...system._snapshot._scheduledEvents
399
+ }
400
+ };
401
+ },
402
+ start: () => {
403
+ const scheduledEvents = system._snapshot._scheduledEvents;
404
+ system._snapshot._scheduledEvents = {};
405
+ for (const scheduledId in scheduledEvents) {
406
+ const {
407
+ source,
408
+ target,
409
+ event,
410
+ delay,
411
+ id
412
+ } = scheduledEvents[scheduledId];
413
+ scheduler.schedule(source, target, event, delay, id);
414
+ }
415
+ },
416
+ _clock: clock,
417
+ _logger: logger
418
+ };
419
+ return system;
420
+ }
421
+
414
422
  const $$ACTOR_TYPE = 1;
415
423
  // those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
416
424
  let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {
@@ -95,13 +95,15 @@ function createDoneStateEvent(id, output) {
95
95
  function createDoneActorEvent(invokeId, output) {
96
96
  return {
97
97
  type: `xstate.done.actor.${invokeId}`,
98
- output
98
+ output,
99
+ actorId: invokeId
99
100
  };
100
101
  }
101
102
  function createErrorActorEvent(id, error) {
102
103
  return {
103
104
  type: `xstate.error.actor.${id}`,
104
- error
105
+ error,
106
+ actorId: id
105
107
  };
106
108
  }
107
109
  function createInitEvent(input) {
@@ -126,134 +128,6 @@ function reportUnhandledError(err) {
126
128
 
127
129
  const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
128
130
 
129
- function createScheduledEventId(actorRef, id) {
130
- return `${actorRef.sessionId}.${id}`;
131
- }
132
- let idCounter = 0;
133
- function createSystem(rootActor, options) {
134
- const children = new Map();
135
- const keyedActors = new Map();
136
- const reverseKeyedActors = new WeakMap();
137
- const inspectionObservers = new Set();
138
- const timerMap = {};
139
- const {
140
- clock,
141
- logger
142
- } = options;
143
- const scheduler = {
144
- schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
145
- const scheduledEvent = {
146
- source,
147
- target,
148
- event,
149
- delay,
150
- id,
151
- startedAt: Date.now()
152
- };
153
- const scheduledEventId = createScheduledEventId(source, id);
154
- system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
155
- const timeout = clock.setTimeout(() => {
156
- delete timerMap[scheduledEventId];
157
- delete system._snapshot._scheduledEvents[scheduledEventId];
158
- system._relay(source, target, event);
159
- }, delay);
160
- timerMap[scheduledEventId] = timeout;
161
- },
162
- cancel: (source, id) => {
163
- const scheduledEventId = createScheduledEventId(source, id);
164
- const timeout = timerMap[scheduledEventId];
165
- delete timerMap[scheduledEventId];
166
- delete system._snapshot._scheduledEvents[scheduledEventId];
167
- clock.clearTimeout(timeout);
168
- },
169
- cancelAll: actorRef => {
170
- for (const scheduledEventId in system._snapshot._scheduledEvents) {
171
- const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
172
- if (scheduledEvent.source === actorRef) {
173
- scheduler.cancel(actorRef, scheduledEvent.id);
174
- }
175
- }
176
- }
177
- };
178
- const sendInspectionEvent = event => {
179
- if (!inspectionObservers.size) {
180
- return;
181
- }
182
- const resolvedInspectionEvent = {
183
- ...event,
184
- rootId: rootActor.sessionId
185
- };
186
- inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
187
- };
188
- const system = {
189
- _snapshot: {
190
- _scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
191
- },
192
- _bookId: () => `x:${idCounter++}`,
193
- _register: (sessionId, actorRef) => {
194
- children.set(sessionId, actorRef);
195
- return sessionId;
196
- },
197
- _unregister: actorRef => {
198
- children.delete(actorRef.sessionId);
199
- const systemId = reverseKeyedActors.get(actorRef);
200
- if (systemId !== undefined) {
201
- keyedActors.delete(systemId);
202
- reverseKeyedActors.delete(actorRef);
203
- }
204
- },
205
- get: systemId => {
206
- return keyedActors.get(systemId);
207
- },
208
- _set: (systemId, actorRef) => {
209
- const existing = keyedActors.get(systemId);
210
- if (existing && existing !== actorRef) {
211
- throw new Error(`Actor with system ID '${systemId}' already exists.`);
212
- }
213
- keyedActors.set(systemId, actorRef);
214
- reverseKeyedActors.set(actorRef, systemId);
215
- },
216
- inspect: observer => {
217
- inspectionObservers.add(observer);
218
- },
219
- _sendInspectionEvent: sendInspectionEvent,
220
- _relay: (source, target, event) => {
221
- system._sendInspectionEvent({
222
- type: '@xstate.event',
223
- sourceRef: source,
224
- actorRef: target,
225
- event
226
- });
227
- target._send(event);
228
- },
229
- scheduler,
230
- getSnapshot: () => {
231
- return {
232
- _scheduledEvents: {
233
- ...system._snapshot._scheduledEvents
234
- }
235
- };
236
- },
237
- start: () => {
238
- const scheduledEvents = system._snapshot._scheduledEvents;
239
- system._snapshot._scheduledEvents = {};
240
- for (const scheduledId in scheduledEvents) {
241
- const {
242
- source,
243
- target,
244
- event,
245
- delay,
246
- id
247
- } = scheduledEvents[scheduledId];
248
- scheduler.schedule(source, target, event, delay, id);
249
- }
250
- },
251
- _clock: clock,
252
- _logger: logger
253
- };
254
- return system;
255
- }
256
-
257
131
  function matchesState(parentStateId, childStateId) {
258
132
  const parentStateValue = toStateValue(parentStateId);
259
133
  const childStateValue = toStateValue(childStateId);
@@ -408,6 +282,140 @@ function getAllOwnEventDescriptors(snapshot) {
408
282
  return [...new Set([...snapshot._nodes.flatMap(sn => sn.ownEvents)])];
409
283
  }
410
284
 
285
+ function createScheduledEventId(actorRef, id) {
286
+ return `${actorRef.sessionId}.${id}`;
287
+ }
288
+ let idCounter = 0;
289
+ function createSystem(rootActor, options) {
290
+ const children = new Map();
291
+ const keyedActors = new Map();
292
+ const reverseKeyedActors = new WeakMap();
293
+ const inspectionObservers = new Set();
294
+ const timerMap = {};
295
+ const {
296
+ clock,
297
+ logger
298
+ } = options;
299
+ const scheduler = {
300
+ schedule: (source, target, event, delay, id = Math.random().toString(36).slice(2)) => {
301
+ const scheduledEvent = {
302
+ source,
303
+ target,
304
+ event,
305
+ delay,
306
+ id,
307
+ startedAt: Date.now()
308
+ };
309
+ const scheduledEventId = createScheduledEventId(source, id);
310
+ system._snapshot._scheduledEvents[scheduledEventId] = scheduledEvent;
311
+ const timeout = clock.setTimeout(() => {
312
+ delete timerMap[scheduledEventId];
313
+ delete system._snapshot._scheduledEvents[scheduledEventId];
314
+ system._relay(source, target, event);
315
+ }, delay);
316
+ timerMap[scheduledEventId] = timeout;
317
+ },
318
+ cancel: (source, id) => {
319
+ const scheduledEventId = createScheduledEventId(source, id);
320
+ const timeout = timerMap[scheduledEventId];
321
+ delete timerMap[scheduledEventId];
322
+ delete system._snapshot._scheduledEvents[scheduledEventId];
323
+ clock.clearTimeout(timeout);
324
+ },
325
+ cancelAll: actorRef => {
326
+ for (const scheduledEventId in system._snapshot._scheduledEvents) {
327
+ const scheduledEvent = system._snapshot._scheduledEvents[scheduledEventId];
328
+ if (scheduledEvent.source === actorRef) {
329
+ scheduler.cancel(actorRef, scheduledEvent.id);
330
+ }
331
+ }
332
+ }
333
+ };
334
+ const sendInspectionEvent = event => {
335
+ if (!inspectionObservers.size) {
336
+ return;
337
+ }
338
+ const resolvedInspectionEvent = {
339
+ ...event,
340
+ rootId: rootActor.sessionId
341
+ };
342
+ inspectionObservers.forEach(observer => observer.next?.(resolvedInspectionEvent));
343
+ };
344
+ const system = {
345
+ _snapshot: {
346
+ _scheduledEvents: (options?.snapshot && options.snapshot.scheduler) ?? {}
347
+ },
348
+ _bookId: () => `x:${idCounter++}`,
349
+ _register: (sessionId, actorRef) => {
350
+ children.set(sessionId, actorRef);
351
+ return sessionId;
352
+ },
353
+ _unregister: actorRef => {
354
+ children.delete(actorRef.sessionId);
355
+ const systemId = reverseKeyedActors.get(actorRef);
356
+ if (systemId !== undefined) {
357
+ keyedActors.delete(systemId);
358
+ reverseKeyedActors.delete(actorRef);
359
+ }
360
+ },
361
+ get: systemId => {
362
+ return keyedActors.get(systemId);
363
+ },
364
+ _set: (systemId, actorRef) => {
365
+ const existing = keyedActors.get(systemId);
366
+ if (existing && existing !== actorRef) {
367
+ throw new Error(`Actor with system ID '${systemId}' already exists.`);
368
+ }
369
+ keyedActors.set(systemId, actorRef);
370
+ reverseKeyedActors.set(actorRef, systemId);
371
+ },
372
+ inspect: observerOrFn => {
373
+ const observer = toObserver(observerOrFn);
374
+ inspectionObservers.add(observer);
375
+ return {
376
+ unsubscribe() {
377
+ inspectionObservers.delete(observer);
378
+ }
379
+ };
380
+ },
381
+ _sendInspectionEvent: sendInspectionEvent,
382
+ _relay: (source, target, event) => {
383
+ system._sendInspectionEvent({
384
+ type: '@xstate.event',
385
+ sourceRef: source,
386
+ actorRef: target,
387
+ event
388
+ });
389
+ target._send(event);
390
+ },
391
+ scheduler,
392
+ getSnapshot: () => {
393
+ return {
394
+ _scheduledEvents: {
395
+ ...system._snapshot._scheduledEvents
396
+ }
397
+ };
398
+ },
399
+ start: () => {
400
+ const scheduledEvents = system._snapshot._scheduledEvents;
401
+ system._snapshot._scheduledEvents = {};
402
+ for (const scheduledId in scheduledEvents) {
403
+ const {
404
+ source,
405
+ target,
406
+ event,
407
+ delay,
408
+ id
409
+ } = scheduledEvents[scheduledId];
410
+ scheduler.schedule(source, target, event, delay, id);
411
+ }
412
+ },
413
+ _clock: clock,
414
+ _logger: logger
415
+ };
416
+ return system;
417
+ }
418
+
411
419
  const $$ACTOR_TYPE = 1;
412
420
  // those values are currently used by @xstate/react directly so it's important to keep the assigned values in sync
413
421
  let ProcessingStatus = /*#__PURE__*/function (ProcessingStatus) {