xstate 6.0.0-beta.1 → 6.0.0-beta.3
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 +4 -2
- package/dist/{createActor-cbe3abac.esm.js → createActor-49ea55ba.esm.js} +259 -47
- package/dist/{createActor-25900f76.cjs.js → createActor-73aa92ba.cjs.js} +261 -46
- package/dist/{createActor-551369be.development.esm.js → createActor-a085b20b.development.esm.js} +260 -48
- package/dist/{createActor-a49ae0ce.development.cjs.js → createActor-dfb6b790.development.cjs.js} +262 -47
- package/dist/declarations/src/createActor.d.ts +3 -1
- package/dist/declarations/src/createMachine.d.ts +6 -3
- package/dist/declarations/src/durable/index.d.ts +43 -8
- package/dist/declarations/src/effectDescriptor.d.ts +2 -2
- package/dist/declarations/src/fsm.d.ts +7 -7
- package/dist/declarations/src/machineVersion.types.d.ts +2 -2
- package/dist/declarations/src/setup.d.ts +2 -2
- package/dist/declarations/src/systemTransition.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +4 -2
- package/dist/declarations/src/types.v6.d.ts +37 -2
- package/dist/{effectDescriptor-2fa27c54.cjs.js → effectDescriptor-3402f63e.cjs.js} +5 -5
- package/dist/{effectDescriptor-d8b0f749.esm.js → effectDescriptor-65821048.development.esm.js} +5 -5
- package/dist/{effectDescriptor-321a8ce9.development.esm.js → effectDescriptor-72c62058.esm.js} +5 -5
- package/dist/{effectDescriptor-f73da4ec.development.cjs.js → effectDescriptor-d0ea44ad.development.cjs.js} +5 -5
- package/dist/{machineSchemas-b5736804.development.esm.js → legacySnapshot-11aba2d2.development.esm.js} +117 -3
- package/dist/{machineSchemas-6d96bef4.development.cjs.js → legacySnapshot-2e2c1d3b.development.cjs.js} +118 -2
- package/dist/{machineSchemas-88d01821.cjs.js → legacySnapshot-a85dfbe2.cjs.js} +117 -1
- package/dist/{machineSchemas-45c21bc2.esm.js → legacySnapshot-fffe81a0.esm.js} +116 -2
- package/dist/xstate-actors.cjs.js +30 -5
- package/dist/xstate-actors.development.cjs.js +30 -5
- package/dist/xstate-actors.development.esm.js +31 -6
- package/dist/xstate-actors.esm.js +31 -6
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-durable.cjs.js +120 -10
- package/dist/xstate-durable.development.cjs.js +120 -10
- package/dist/xstate-durable.development.esm.js +120 -10
- package/dist/xstate-durable.esm.js +120 -10
- package/dist/xstate-durable.umd.min.js +1 -1
- package/dist/xstate-durable.umd.min.js.map +1 -1
- package/dist/xstate-fsm.cjs.js +61 -31
- package/dist/xstate-fsm.development.cjs.js +61 -31
- package/dist/xstate-fsm.development.esm.js +61 -31
- package/dist/xstate-fsm.esm.js +61 -31
- package/dist/xstate-fsm.umd.min.js +1 -1
- package/dist/xstate-fsm.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +1 -1
- package/dist/xstate-graph.development.cjs.js +1 -1
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-persist.cjs.js +23 -12
- package/dist/xstate-persist.development.cjs.js +23 -12
- package/dist/xstate-persist.development.esm.js +17 -6
- package/dist/xstate-persist.esm.js +17 -6
- package/dist/xstate-persist.umd.min.js +1 -1
- package/dist/xstate-persist.umd.min.js.map +1 -1
- package/dist/xstate-validation.cjs.js +1 -1
- package/dist/xstate-validation.development.cjs.js +1 -1
- package/dist/xstate-validation.development.esm.js +1 -1
- package/dist/xstate-validation.esm.js +1 -1
- package/dist/xstate.cjs.js +86 -56
- package/dist/xstate.development.cjs.js +86 -56
- package/dist/xstate.development.esm.js +76 -46
- package/dist/xstate.esm.js +76 -46
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/docs/actor-logic.md +1 -1
- package/docs/api-stability.json +335 -305
- package/docs/backend-workflows.md +3 -3
- package/docs/durable-execution.md +72 -48
- package/docs/errors.md +2 -2
- package/docs/examples.md +34 -34
- package/docs/faq.md +1 -1
- package/docs/fsm.md +54 -10
- package/docs/guards.md +1 -1
- package/docs/index.md +2 -1
- package/docs/inspect-actor-systems.md +20 -3
- package/docs/inspection.md +5 -1
- package/docs/invoke.md +36 -4
- package/docs/migrate-inspector.md +141 -0
- package/docs/persistence.md +16 -10
- package/docs/serialization.md +1 -1
- package/docs/setup-and-provide.md +3 -3
- package/docs/spawn.md +1 -1
- package/docs/system-transitions.md +8 -6
- package/docs/transitions.md +5 -1
- package/docs/tutorial.md +5 -5
- package/docs/typescript.md +9 -0
- package/docs/xstate-v5-to-v6.md +23 -21
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
3
|
+
var createActor = require('./createActor-dfb6b790.development.cjs.js');
|
|
4
4
|
var validation = require('./validation-f2714a35.development.cjs.js');
|
|
5
5
|
|
|
6
6
|
var isDevelopment = true;
|
|
@@ -131,7 +131,7 @@ class StateNode {
|
|
|
131
131
|
this.machine = options._machine;
|
|
132
132
|
if (this.parent && createActor.hasUnescapedDot(this.key)) {
|
|
133
133
|
throw new Error(// The suggestion is written as a JS string literal.
|
|
134
|
-
`State key "${this.key}" contains "."
|
|
134
|
+
`State key "${this.key}" contains ".". Nest the states or escape it as "${this.key.replaceAll(/(?<!\\)\./g, '\\\\.')}".` );
|
|
135
135
|
}
|
|
136
136
|
this.path = this.parent ? this.parent.path.concat(this.key) : [];
|
|
137
137
|
const firstStateKey = this.config.states ? Object.keys(this.config.states)[0] : undefined;
|
|
@@ -674,6 +674,15 @@ class StateMachine {
|
|
|
674
674
|
/** @internal */
|
|
675
675
|
this.idMap = new Map();
|
|
676
676
|
this.root = void 0;
|
|
677
|
+
/**
|
|
678
|
+
* Returns the machine itself, never a Proxy wrapped around it (a function
|
|
679
|
+
* member is not wrapped by reactive proxies, so it still closes over the raw
|
|
680
|
+
* instance). Persistence resolves state nodes through it, matching the
|
|
681
|
+
* bound `transition` / `getInitialSnapshot`.
|
|
682
|
+
*
|
|
683
|
+
* @internal
|
|
684
|
+
*/
|
|
685
|
+
this._raw = () => this;
|
|
677
686
|
/**
|
|
678
687
|
* The machine's `id`, or the empty string when the config declares none.
|
|
679
688
|
* The root state node has this id; a machine without one has no `#id` root.
|
|
@@ -1370,10 +1379,117 @@ function eventSchema(machine) {
|
|
|
1370
1379
|
}));
|
|
1371
1380
|
}
|
|
1372
1381
|
|
|
1382
|
+
// TODO(v7): remove this module and its callers. It reads snapshots written by
|
|
1383
|
+
// 6.0.0-beta.1, which used `$`- and `_`-prefixed field names that stores such
|
|
1384
|
+
// as Convex reject. Snapshots are written with the new names only.
|
|
1385
|
+
|
|
1386
|
+
// Legacy marker key -> [new key, other keys the marker object may have].
|
|
1387
|
+
const markers = {
|
|
1388
|
+
$actor: ['@actor', ['incarnation']],
|
|
1389
|
+
$error: ['@error', ['message']],
|
|
1390
|
+
$stateNode: ['@stateNode', []],
|
|
1391
|
+
$systemMapper: ['@systemMapper', []]
|
|
1392
|
+
};
|
|
1393
|
+
const fields = {
|
|
1394
|
+
_stateInputs: 'stateInputs',
|
|
1395
|
+
_nextTimerId: 'nextTimerId',
|
|
1396
|
+
_nextActorIds: 'nextActorIds'
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
// Persisted snapshots are JSON; live objects (actors, state nodes, errors)
|
|
1400
|
+
// are left alone.
|
|
1401
|
+
function isPlain(value) {
|
|
1402
|
+
if (!value || typeof value !== 'object') return false;
|
|
1403
|
+
const proto = Object.getPrototypeOf(value);
|
|
1404
|
+
return proto === Object.prototype || proto === null || Array.isArray(value);
|
|
1405
|
+
}
|
|
1406
|
+
function renameMarkers(value, allowed) {
|
|
1407
|
+
if (!isPlain(value)) return value;
|
|
1408
|
+
if (Array.isArray(value)) {
|
|
1409
|
+
const items = value.map(item => renameMarkers(item, allowed));
|
|
1410
|
+
return items.some((item, i) => item !== value[i]) ? items : value;
|
|
1411
|
+
}
|
|
1412
|
+
const keys = Object.keys(value);
|
|
1413
|
+
const legacy = keys.find(key => allowed.includes(key));
|
|
1414
|
+
if (legacy && typeof value[legacy] === 'string' && keys.every(key => key === legacy || markers[legacy][1].includes(key))) {
|
|
1415
|
+
const {
|
|
1416
|
+
[legacy]: name,
|
|
1417
|
+
...rest
|
|
1418
|
+
} = value;
|
|
1419
|
+
return {
|
|
1420
|
+
[markers[legacy][0]]: name,
|
|
1421
|
+
...rest
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
let copy;
|
|
1425
|
+
for (const key of keys) {
|
|
1426
|
+
const item = renameMarkers(value[key], allowed);
|
|
1427
|
+
if (item !== value[key]) (copy ??= {
|
|
1428
|
+
...value
|
|
1429
|
+
})[key] = item;
|
|
1430
|
+
}
|
|
1431
|
+
return copy ?? value;
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// beta.1 always wrote `_nextTimerId` on machine snapshots. Current snapshots
|
|
1435
|
+
// write `nextTimerId`, so marker-shaped data in them is left alone.
|
|
1436
|
+
function isLegacyEnvelope(envelope) {
|
|
1437
|
+
return isPlain(envelope) && '_nextTimerId' in envelope && !('nextTimerId' in envelope);
|
|
1438
|
+
}
|
|
1439
|
+
function renameFields(envelope) {
|
|
1440
|
+
// A live machine snapshot keeps its `_`-prefixed in-memory fields.
|
|
1441
|
+
if (!isPlain(envelope) || typeof envelope.matches === 'function') return envelope;
|
|
1442
|
+
let copy;
|
|
1443
|
+
for (const [legacy, name] of Object.entries(fields)) {
|
|
1444
|
+
if (legacy in envelope && !(name in envelope)) {
|
|
1445
|
+
const {
|
|
1446
|
+
[legacy]: value,
|
|
1447
|
+
...rest
|
|
1448
|
+
} = copy ?? envelope;
|
|
1449
|
+
copy = {
|
|
1450
|
+
...rest,
|
|
1451
|
+
[name]: value
|
|
1452
|
+
};
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
return copy ?? envelope;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
/** Upgrades a persisted machine snapshot written by 6.0.0-beta.1. */
|
|
1459
|
+
function upgradeLegacyPersistedSnapshot(snapshot) {
|
|
1460
|
+
if (snapshot?.machine && typeof snapshot.matches === 'function') return snapshot;
|
|
1461
|
+
if (!isLegacyEnvelope(snapshot)) return snapshot;
|
|
1462
|
+
return renameMarkers(renameFields(snapshot), ['$actor']);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
/** Upgrades a `systemTransition` snapshot written by 6.0.0-beta.1. */
|
|
1466
|
+
function upgradeLegacySystemSnapshot(snapshot) {
|
|
1467
|
+
const actors = Object.values(snapshot?.actors ?? {});
|
|
1468
|
+
if (!actors.some(actor => isLegacyEnvelope(actor?.snapshot))) return snapshot;
|
|
1469
|
+
const upgraded = renameMarkers(snapshot, Object.keys(markers));
|
|
1470
|
+
if (!upgraded?.actors) return upgraded;
|
|
1471
|
+
let renamed;
|
|
1472
|
+
for (const [address, actor] of Object.entries(upgraded.actors)) {
|
|
1473
|
+
const data = renameFields(actor?.snapshot);
|
|
1474
|
+
if (data !== actor?.snapshot) (renamed ??= {
|
|
1475
|
+
...upgraded.actors
|
|
1476
|
+
})[address] = {
|
|
1477
|
+
...actor,
|
|
1478
|
+
snapshot: data
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
return renamed ? {
|
|
1482
|
+
...upgraded,
|
|
1483
|
+
actors: renamed
|
|
1484
|
+
} : upgraded;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1373
1487
|
exports.InvalidSnapshotError = InvalidSnapshotError;
|
|
1374
1488
|
exports.StateMachine = StateMachine;
|
|
1375
1489
|
exports.StateNode = StateNode;
|
|
1376
1490
|
exports.eventSchema = eventSchema;
|
|
1377
1491
|
exports.historicalEventSchema = historicalEventSchema;
|
|
1378
1492
|
exports.snapshotSchema = snapshotSchema;
|
|
1493
|
+
exports.upgradeLegacyPersistedSnapshot = upgradeLegacyPersistedSnapshot;
|
|
1494
|
+
exports.upgradeLegacySystemSnapshot = upgradeLegacySystemSnapshot;
|
|
1379
1495
|
exports.validatePersistedSnapshot = validatePersistedSnapshot;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
3
|
+
var createActor = require('./createActor-73aa92ba.cjs.js');
|
|
4
4
|
var validation = require('./validation-4561b43c.cjs.js');
|
|
5
5
|
|
|
6
6
|
var isDevelopment = false;
|
|
@@ -605,6 +605,15 @@ class StateMachine {
|
|
|
605
605
|
/** @internal */
|
|
606
606
|
this.idMap = new Map();
|
|
607
607
|
this.root = void 0;
|
|
608
|
+
/**
|
|
609
|
+
* Returns the machine itself, never a Proxy wrapped around it (a function
|
|
610
|
+
* member is not wrapped by reactive proxies, so it still closes over the raw
|
|
611
|
+
* instance). Persistence resolves state nodes through it, matching the
|
|
612
|
+
* bound `transition` / `getInitialSnapshot`.
|
|
613
|
+
*
|
|
614
|
+
* @internal
|
|
615
|
+
*/
|
|
616
|
+
this._raw = () => this;
|
|
608
617
|
/**
|
|
609
618
|
* The machine's `id`, or the empty string when the config declares none.
|
|
610
619
|
* The root state node has this id; a machine without one has no `#id` root.
|
|
@@ -1291,10 +1300,117 @@ function eventSchema(machine) {
|
|
|
1291
1300
|
}));
|
|
1292
1301
|
}
|
|
1293
1302
|
|
|
1303
|
+
// TODO(v7): remove this module and its callers. It reads snapshots written by
|
|
1304
|
+
// 6.0.0-beta.1, which used `$`- and `_`-prefixed field names that stores such
|
|
1305
|
+
// as Convex reject. Snapshots are written with the new names only.
|
|
1306
|
+
|
|
1307
|
+
// Legacy marker key -> [new key, other keys the marker object may have].
|
|
1308
|
+
const markers = {
|
|
1309
|
+
$actor: ['@actor', ['incarnation']],
|
|
1310
|
+
$error: ['@error', ['message']],
|
|
1311
|
+
$stateNode: ['@stateNode', []],
|
|
1312
|
+
$systemMapper: ['@systemMapper', []]
|
|
1313
|
+
};
|
|
1314
|
+
const fields = {
|
|
1315
|
+
_stateInputs: 'stateInputs',
|
|
1316
|
+
_nextTimerId: 'nextTimerId',
|
|
1317
|
+
_nextActorIds: 'nextActorIds'
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
// Persisted snapshots are JSON; live objects (actors, state nodes, errors)
|
|
1321
|
+
// are left alone.
|
|
1322
|
+
function isPlain(value) {
|
|
1323
|
+
if (!value || typeof value !== 'object') return false;
|
|
1324
|
+
const proto = Object.getPrototypeOf(value);
|
|
1325
|
+
return proto === Object.prototype || proto === null || Array.isArray(value);
|
|
1326
|
+
}
|
|
1327
|
+
function renameMarkers(value, allowed) {
|
|
1328
|
+
if (!isPlain(value)) return value;
|
|
1329
|
+
if (Array.isArray(value)) {
|
|
1330
|
+
const items = value.map(item => renameMarkers(item, allowed));
|
|
1331
|
+
return items.some((item, i) => item !== value[i]) ? items : value;
|
|
1332
|
+
}
|
|
1333
|
+
const keys = Object.keys(value);
|
|
1334
|
+
const legacy = keys.find(key => allowed.includes(key));
|
|
1335
|
+
if (legacy && typeof value[legacy] === 'string' && keys.every(key => key === legacy || markers[legacy][1].includes(key))) {
|
|
1336
|
+
const {
|
|
1337
|
+
[legacy]: name,
|
|
1338
|
+
...rest
|
|
1339
|
+
} = value;
|
|
1340
|
+
return {
|
|
1341
|
+
[markers[legacy][0]]: name,
|
|
1342
|
+
...rest
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
let copy;
|
|
1346
|
+
for (const key of keys) {
|
|
1347
|
+
const item = renameMarkers(value[key], allowed);
|
|
1348
|
+
if (item !== value[key]) (copy ??= {
|
|
1349
|
+
...value
|
|
1350
|
+
})[key] = item;
|
|
1351
|
+
}
|
|
1352
|
+
return copy ?? value;
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
// beta.1 always wrote `_nextTimerId` on machine snapshots. Current snapshots
|
|
1356
|
+
// write `nextTimerId`, so marker-shaped data in them is left alone.
|
|
1357
|
+
function isLegacyEnvelope(envelope) {
|
|
1358
|
+
return isPlain(envelope) && '_nextTimerId' in envelope && !('nextTimerId' in envelope);
|
|
1359
|
+
}
|
|
1360
|
+
function renameFields(envelope) {
|
|
1361
|
+
// A live machine snapshot keeps its `_`-prefixed in-memory fields.
|
|
1362
|
+
if (!isPlain(envelope) || typeof envelope.matches === 'function') return envelope;
|
|
1363
|
+
let copy;
|
|
1364
|
+
for (const [legacy, name] of Object.entries(fields)) {
|
|
1365
|
+
if (legacy in envelope && !(name in envelope)) {
|
|
1366
|
+
const {
|
|
1367
|
+
[legacy]: value,
|
|
1368
|
+
...rest
|
|
1369
|
+
} = copy ?? envelope;
|
|
1370
|
+
copy = {
|
|
1371
|
+
...rest,
|
|
1372
|
+
[name]: value
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
return copy ?? envelope;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/** Upgrades a persisted machine snapshot written by 6.0.0-beta.1. */
|
|
1380
|
+
function upgradeLegacyPersistedSnapshot(snapshot) {
|
|
1381
|
+
if (snapshot?.machine && typeof snapshot.matches === 'function') return snapshot;
|
|
1382
|
+
if (!isLegacyEnvelope(snapshot)) return snapshot;
|
|
1383
|
+
return renameMarkers(renameFields(snapshot), ['$actor']);
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/** Upgrades a `systemTransition` snapshot written by 6.0.0-beta.1. */
|
|
1387
|
+
function upgradeLegacySystemSnapshot(snapshot) {
|
|
1388
|
+
const actors = Object.values(snapshot?.actors ?? {});
|
|
1389
|
+
if (!actors.some(actor => isLegacyEnvelope(actor?.snapshot))) return snapshot;
|
|
1390
|
+
const upgraded = renameMarkers(snapshot, Object.keys(markers));
|
|
1391
|
+
if (!upgraded?.actors) return upgraded;
|
|
1392
|
+
let renamed;
|
|
1393
|
+
for (const [address, actor] of Object.entries(upgraded.actors)) {
|
|
1394
|
+
const data = renameFields(actor?.snapshot);
|
|
1395
|
+
if (data !== actor?.snapshot) (renamed ??= {
|
|
1396
|
+
...upgraded.actors
|
|
1397
|
+
})[address] = {
|
|
1398
|
+
...actor,
|
|
1399
|
+
snapshot: data
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
return renamed ? {
|
|
1403
|
+
...upgraded,
|
|
1404
|
+
actors: renamed
|
|
1405
|
+
} : upgraded;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1294
1408
|
exports.InvalidSnapshotError = InvalidSnapshotError;
|
|
1295
1409
|
exports.StateMachine = StateMachine;
|
|
1296
1410
|
exports.StateNode = StateNode;
|
|
1297
1411
|
exports.eventSchema = eventSchema;
|
|
1298
1412
|
exports.historicalEventSchema = historicalEventSchema;
|
|
1299
1413
|
exports.snapshotSchema = snapshotSchema;
|
|
1414
|
+
exports.upgradeLegacyPersistedSnapshot = upgradeLegacyPersistedSnapshot;
|
|
1415
|
+
exports.upgradeLegacySystemSnapshot = upgradeLegacySystemSnapshot;
|
|
1300
1416
|
exports.validatePersistedSnapshot = validatePersistedSnapshot;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a0 as resolveRegisteredActorSource, a1 as allocateChildId, a2 as assertChildIdFree, a3 as reserveChildId, a4 as hasUnescapedDot, x as xstateError, a5 as STATE_DELIMITER, a6 as mapValues, t as toArray, a7 as createInvokeId, a8 as getDelayedTransitions, a9 as getCandidates, aa as evaluateCandidate, ab as formatTransition, ac as NULL_EVENT, ad as toTransitionConfigArray, ae as matchesActorSession, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, af as describeMachine, o as isSerializedActorRef, ag as formatRouteTransitions, ah as resolveStateValue, e as createMachineSnapshot, ai as isInFinalState, aj as createInertActorScope, ak as setInertActorScopeSnapshot, S as createDeadLetterEffect, al as beginSpawnAllocation, am as attachSnapshotActorRef, an as macrostep, ao as isInertActorScope, ap as setSnapshotActorRef, aq as cloneMachineSnapshot, ar as transitionNode, as as XSTATE_TIMER, m as matchesEventDescriptor, at as getTransitionResult, au as hasEffect, av as createErrorPlatformEvent, aw as withActorSelf, ax as resolveActionsWithContext, ay as takeSpawnAllocationCounters, az as mergeActorIdCounters, R as createInitEvent, aA as createSpawnEffect, aB as initialMicrostep, aC as createStartEffect, aD as isStateId, aE as getPersistedSnapshot, aF as detachedScopes, h as createActor } from './createActor-49ea55ba.esm.js';
|
|
2
2
|
import { a as assertValid } from './validation-05f1d517.esm.js';
|
|
3
3
|
|
|
4
4
|
var isDevelopment = false;
|
|
@@ -603,6 +603,15 @@ class StateMachine {
|
|
|
603
603
|
/** @internal */
|
|
604
604
|
this.idMap = new Map();
|
|
605
605
|
this.root = void 0;
|
|
606
|
+
/**
|
|
607
|
+
* Returns the machine itself, never a Proxy wrapped around it (a function
|
|
608
|
+
* member is not wrapped by reactive proxies, so it still closes over the raw
|
|
609
|
+
* instance). Persistence resolves state nodes through it, matching the
|
|
610
|
+
* bound `transition` / `getInitialSnapshot`.
|
|
611
|
+
*
|
|
612
|
+
* @internal
|
|
613
|
+
*/
|
|
614
|
+
this._raw = () => this;
|
|
606
615
|
/**
|
|
607
616
|
* The machine's `id`, or the empty string when the config declares none.
|
|
608
617
|
* The root state node has this id; a machine without one has no `#id` root.
|
|
@@ -1289,4 +1298,109 @@ function eventSchema(machine) {
|
|
|
1289
1298
|
}));
|
|
1290
1299
|
}
|
|
1291
1300
|
|
|
1292
|
-
|
|
1301
|
+
// TODO(v7): remove this module and its callers. It reads snapshots written by
|
|
1302
|
+
// 6.0.0-beta.1, which used `$`- and `_`-prefixed field names that stores such
|
|
1303
|
+
// as Convex reject. Snapshots are written with the new names only.
|
|
1304
|
+
|
|
1305
|
+
// Legacy marker key -> [new key, other keys the marker object may have].
|
|
1306
|
+
const markers = {
|
|
1307
|
+
$actor: ['@actor', ['incarnation']],
|
|
1308
|
+
$error: ['@error', ['message']],
|
|
1309
|
+
$stateNode: ['@stateNode', []],
|
|
1310
|
+
$systemMapper: ['@systemMapper', []]
|
|
1311
|
+
};
|
|
1312
|
+
const fields = {
|
|
1313
|
+
_stateInputs: 'stateInputs',
|
|
1314
|
+
_nextTimerId: 'nextTimerId',
|
|
1315
|
+
_nextActorIds: 'nextActorIds'
|
|
1316
|
+
};
|
|
1317
|
+
|
|
1318
|
+
// Persisted snapshots are JSON; live objects (actors, state nodes, errors)
|
|
1319
|
+
// are left alone.
|
|
1320
|
+
function isPlain(value) {
|
|
1321
|
+
if (!value || typeof value !== 'object') return false;
|
|
1322
|
+
const proto = Object.getPrototypeOf(value);
|
|
1323
|
+
return proto === Object.prototype || proto === null || Array.isArray(value);
|
|
1324
|
+
}
|
|
1325
|
+
function renameMarkers(value, allowed) {
|
|
1326
|
+
if (!isPlain(value)) return value;
|
|
1327
|
+
if (Array.isArray(value)) {
|
|
1328
|
+
const items = value.map(item => renameMarkers(item, allowed));
|
|
1329
|
+
return items.some((item, i) => item !== value[i]) ? items : value;
|
|
1330
|
+
}
|
|
1331
|
+
const keys = Object.keys(value);
|
|
1332
|
+
const legacy = keys.find(key => allowed.includes(key));
|
|
1333
|
+
if (legacy && typeof value[legacy] === 'string' && keys.every(key => key === legacy || markers[legacy][1].includes(key))) {
|
|
1334
|
+
const {
|
|
1335
|
+
[legacy]: name,
|
|
1336
|
+
...rest
|
|
1337
|
+
} = value;
|
|
1338
|
+
return {
|
|
1339
|
+
[markers[legacy][0]]: name,
|
|
1340
|
+
...rest
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
let copy;
|
|
1344
|
+
for (const key of keys) {
|
|
1345
|
+
const item = renameMarkers(value[key], allowed);
|
|
1346
|
+
if (item !== value[key]) (copy ??= {
|
|
1347
|
+
...value
|
|
1348
|
+
})[key] = item;
|
|
1349
|
+
}
|
|
1350
|
+
return copy ?? value;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// beta.1 always wrote `_nextTimerId` on machine snapshots. Current snapshots
|
|
1354
|
+
// write `nextTimerId`, so marker-shaped data in them is left alone.
|
|
1355
|
+
function isLegacyEnvelope(envelope) {
|
|
1356
|
+
return isPlain(envelope) && '_nextTimerId' in envelope && !('nextTimerId' in envelope);
|
|
1357
|
+
}
|
|
1358
|
+
function renameFields(envelope) {
|
|
1359
|
+
// A live machine snapshot keeps its `_`-prefixed in-memory fields.
|
|
1360
|
+
if (!isPlain(envelope) || typeof envelope.matches === 'function') return envelope;
|
|
1361
|
+
let copy;
|
|
1362
|
+
for (const [legacy, name] of Object.entries(fields)) {
|
|
1363
|
+
if (legacy in envelope && !(name in envelope)) {
|
|
1364
|
+
const {
|
|
1365
|
+
[legacy]: value,
|
|
1366
|
+
...rest
|
|
1367
|
+
} = copy ?? envelope;
|
|
1368
|
+
copy = {
|
|
1369
|
+
...rest,
|
|
1370
|
+
[name]: value
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
return copy ?? envelope;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
/** Upgrades a persisted machine snapshot written by 6.0.0-beta.1. */
|
|
1378
|
+
function upgradeLegacyPersistedSnapshot(snapshot) {
|
|
1379
|
+
if (snapshot?.machine && typeof snapshot.matches === 'function') return snapshot;
|
|
1380
|
+
if (!isLegacyEnvelope(snapshot)) return snapshot;
|
|
1381
|
+
return renameMarkers(renameFields(snapshot), ['$actor']);
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
/** Upgrades a `systemTransition` snapshot written by 6.0.0-beta.1. */
|
|
1385
|
+
function upgradeLegacySystemSnapshot(snapshot) {
|
|
1386
|
+
const actors = Object.values(snapshot?.actors ?? {});
|
|
1387
|
+
if (!actors.some(actor => isLegacyEnvelope(actor?.snapshot))) return snapshot;
|
|
1388
|
+
const upgraded = renameMarkers(snapshot, Object.keys(markers));
|
|
1389
|
+
if (!upgraded?.actors) return upgraded;
|
|
1390
|
+
let renamed;
|
|
1391
|
+
for (const [address, actor] of Object.entries(upgraded.actors)) {
|
|
1392
|
+
const data = renameFields(actor?.snapshot);
|
|
1393
|
+
if (data !== actor?.snapshot) (renamed ??= {
|
|
1394
|
+
...upgraded.actors
|
|
1395
|
+
})[address] = {
|
|
1396
|
+
...actor,
|
|
1397
|
+
snapshot: data
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
return renamed ? {
|
|
1401
|
+
...upgraded,
|
|
1402
|
+
actors: renamed
|
|
1403
|
+
} : upgraded;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
export { InvalidSnapshotError as I, StateMachine as S, StateNode as a, upgradeLegacyPersistedSnapshot as b, eventSchema as e, historicalEventSchema as h, snapshotSchema as s, upgradeLegacySystemSnapshot as u, validatePersistedSnapshot as v };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var createActor = require('./createActor-
|
|
5
|
+
var createActor = require('./createActor-73aa92ba.cjs.js');
|
|
6
6
|
var validation = require('./validation-4561b43c.cjs.js');
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
@@ -253,6 +253,7 @@ function createStepLogic(config) {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
const instanceStates = /* #__PURE__ */new WeakMap();
|
|
256
|
+
const XSTATE_CALLBACK_SEND_BACK = 'xstate.callback.sendBack';
|
|
256
257
|
|
|
257
258
|
/** @public */
|
|
258
259
|
|
|
@@ -372,8 +373,10 @@ function createCallbackLogic(callbackOrConfig) {
|
|
|
372
373
|
const callback = typeof callbackOrConfig === 'function' ? callbackOrConfig : callbackOrConfig.run;
|
|
373
374
|
const schemas = typeof callbackOrConfig === 'function' ? undefined : callbackOrConfig.schemas;
|
|
374
375
|
const validator = typeof callbackOrConfig === 'function' ? undefined : callbackOrConfig.validator;
|
|
375
|
-
|
|
376
|
-
validator
|
|
376
|
+
const logic = createStepLogic({
|
|
377
|
+
validator: validator && {
|
|
378
|
+
check: request => request.kind === 'event' && request.event.type === XSTATE_CALLBACK_SEND_BACK ? undefined : validator.check(request)
|
|
379
|
+
},
|
|
377
380
|
schemas,
|
|
378
381
|
context: undefined,
|
|
379
382
|
run: (args, enq) => {
|
|
@@ -383,6 +386,10 @@ function createCallbackLogic(callbackOrConfig) {
|
|
|
383
386
|
self,
|
|
384
387
|
system
|
|
385
388
|
} = args;
|
|
389
|
+
if (event.type === XSTATE_CALLBACK_SEND_BACK) {
|
|
390
|
+
enq.sendBack(event.event);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
386
393
|
const emit = args.emit;
|
|
387
394
|
const callbackState = instanceStates.get(self);
|
|
388
395
|
callbackState?.receivers?.forEach(receiver => receiver(event));
|
|
@@ -402,7 +409,10 @@ function createCallbackLogic(callbackOrConfig) {
|
|
|
402
409
|
}
|
|
403
410
|
const parent = self._parent;
|
|
404
411
|
if (parent) {
|
|
405
|
-
system._relay(self,
|
|
412
|
+
system._relay(self, self, {
|
|
413
|
+
type: XSTATE_CALLBACK_SEND_BACK,
|
|
414
|
+
event
|
|
415
|
+
});
|
|
406
416
|
}
|
|
407
417
|
},
|
|
408
418
|
receive: listener => {
|
|
@@ -419,6 +429,10 @@ function createCallbackLogic(callbackOrConfig) {
|
|
|
419
429
|
});
|
|
420
430
|
}
|
|
421
431
|
});
|
|
432
|
+
Object.assign(logic, {
|
|
433
|
+
isInternalEventType: eventType => eventType === XSTATE_CALLBACK_SEND_BACK
|
|
434
|
+
});
|
|
435
|
+
return logic;
|
|
422
436
|
}
|
|
423
437
|
|
|
424
438
|
const XSTATE_OBSERVABLE_NEXT = 'xstate.observable.next';
|
|
@@ -667,6 +681,11 @@ function createEventObservableLogic(lazyObservableOrConfig) {
|
|
|
667
681
|
return [state, []];
|
|
668
682
|
}
|
|
669
683
|
switch (event.type) {
|
|
684
|
+
case XSTATE_OBSERVABLE_NEXT:
|
|
685
|
+
{
|
|
686
|
+
const parent = actorScope.self._parent;
|
|
687
|
+
return [state, parent ? [createActor.createSendToEffect(actorScope, parent, event.data)] : []];
|
|
688
|
+
}
|
|
670
689
|
case XSTATE_OBSERVABLE_ERROR:
|
|
671
690
|
return createActor.finalizeTransitionResult(actorScope, state, [{
|
|
672
691
|
...state,
|
|
@@ -732,7 +751,10 @@ function createEventObservableLogic(lazyObservableOrConfig) {
|
|
|
732
751
|
}).subscribe({
|
|
733
752
|
next: value => {
|
|
734
753
|
if (self._parent) {
|
|
735
|
-
system._relay(self, self
|
|
754
|
+
system._relay(self, self, {
|
|
755
|
+
type: XSTATE_OBSERVABLE_NEXT,
|
|
756
|
+
data: value
|
|
757
|
+
});
|
|
736
758
|
}
|
|
737
759
|
},
|
|
738
760
|
error: err => {
|
|
@@ -757,6 +779,9 @@ function createEventObservableLogic(lazyObservableOrConfig) {
|
|
|
757
779
|
_subscription: undefined
|
|
758
780
|
})
|
|
759
781
|
};
|
|
782
|
+
Object.assign(logic, {
|
|
783
|
+
isInternalEventType: eventType => eventType === XSTATE_OBSERVABLE_NEXT || eventType === XSTATE_OBSERVABLE_ERROR || eventType === XSTATE_OBSERVABLE_COMPLETE
|
|
784
|
+
});
|
|
760
785
|
return logic;
|
|
761
786
|
}
|
|
762
787
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var createActor = require('./createActor-
|
|
5
|
+
var createActor = require('./createActor-dfb6b790.development.cjs.js');
|
|
6
6
|
var validation = require('./validation-f2714a35.development.cjs.js');
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
@@ -253,6 +253,7 @@ function createStepLogic(config) {
|
|
|
253
253
|
}
|
|
254
254
|
|
|
255
255
|
const instanceStates = /* #__PURE__ */new WeakMap();
|
|
256
|
+
const XSTATE_CALLBACK_SEND_BACK = 'xstate.callback.sendBack';
|
|
256
257
|
|
|
257
258
|
/** @public */
|
|
258
259
|
|
|
@@ -372,8 +373,10 @@ function createCallbackLogic(callbackOrConfig) {
|
|
|
372
373
|
const callback = typeof callbackOrConfig === 'function' ? callbackOrConfig : callbackOrConfig.run;
|
|
373
374
|
const schemas = typeof callbackOrConfig === 'function' ? undefined : callbackOrConfig.schemas;
|
|
374
375
|
const validator = typeof callbackOrConfig === 'function' ? undefined : callbackOrConfig.validator;
|
|
375
|
-
|
|
376
|
-
validator
|
|
376
|
+
const logic = createStepLogic({
|
|
377
|
+
validator: validator && {
|
|
378
|
+
check: request => request.kind === 'event' && request.event.type === XSTATE_CALLBACK_SEND_BACK ? undefined : validator.check(request)
|
|
379
|
+
},
|
|
377
380
|
schemas,
|
|
378
381
|
context: undefined,
|
|
379
382
|
run: (args, enq) => {
|
|
@@ -383,6 +386,10 @@ function createCallbackLogic(callbackOrConfig) {
|
|
|
383
386
|
self,
|
|
384
387
|
system
|
|
385
388
|
} = args;
|
|
389
|
+
if (event.type === XSTATE_CALLBACK_SEND_BACK) {
|
|
390
|
+
enq.sendBack(event.event);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
386
393
|
const emit = args.emit;
|
|
387
394
|
const callbackState = instanceStates.get(self);
|
|
388
395
|
callbackState?.receivers?.forEach(receiver => receiver(event));
|
|
@@ -402,7 +409,10 @@ function createCallbackLogic(callbackOrConfig) {
|
|
|
402
409
|
}
|
|
403
410
|
const parent = self._parent;
|
|
404
411
|
if (parent) {
|
|
405
|
-
system._relay(self,
|
|
412
|
+
system._relay(self, self, {
|
|
413
|
+
type: XSTATE_CALLBACK_SEND_BACK,
|
|
414
|
+
event
|
|
415
|
+
});
|
|
406
416
|
}
|
|
407
417
|
},
|
|
408
418
|
receive: listener => {
|
|
@@ -419,6 +429,10 @@ function createCallbackLogic(callbackOrConfig) {
|
|
|
419
429
|
});
|
|
420
430
|
}
|
|
421
431
|
});
|
|
432
|
+
Object.assign(logic, {
|
|
433
|
+
isInternalEventType: eventType => eventType === XSTATE_CALLBACK_SEND_BACK
|
|
434
|
+
});
|
|
435
|
+
return logic;
|
|
422
436
|
}
|
|
423
437
|
|
|
424
438
|
const XSTATE_OBSERVABLE_NEXT = 'xstate.observable.next';
|
|
@@ -667,6 +681,11 @@ function createEventObservableLogic(lazyObservableOrConfig) {
|
|
|
667
681
|
return [state, []];
|
|
668
682
|
}
|
|
669
683
|
switch (event.type) {
|
|
684
|
+
case XSTATE_OBSERVABLE_NEXT:
|
|
685
|
+
{
|
|
686
|
+
const parent = actorScope.self._parent;
|
|
687
|
+
return [state, parent ? [createActor.createSendToEffect(actorScope, parent, event.data)] : []];
|
|
688
|
+
}
|
|
670
689
|
case XSTATE_OBSERVABLE_ERROR:
|
|
671
690
|
return createActor.finalizeTransitionResult(actorScope, state, [{
|
|
672
691
|
...state,
|
|
@@ -732,7 +751,10 @@ function createEventObservableLogic(lazyObservableOrConfig) {
|
|
|
732
751
|
}).subscribe({
|
|
733
752
|
next: value => {
|
|
734
753
|
if (self._parent) {
|
|
735
|
-
system._relay(self, self
|
|
754
|
+
system._relay(self, self, {
|
|
755
|
+
type: XSTATE_OBSERVABLE_NEXT,
|
|
756
|
+
data: value
|
|
757
|
+
});
|
|
736
758
|
}
|
|
737
759
|
},
|
|
738
760
|
error: err => {
|
|
@@ -757,6 +779,9 @@ function createEventObservableLogic(lazyObservableOrConfig) {
|
|
|
757
779
|
_subscription: undefined
|
|
758
780
|
})
|
|
759
781
|
};
|
|
782
|
+
Object.assign(logic, {
|
|
783
|
+
isInternalEventType: eventType => eventType === XSTATE_OBSERVABLE_NEXT || eventType === XSTATE_OBSERVABLE_ERROR || eventType === XSTATE_OBSERVABLE_COMPLETE
|
|
784
|
+
});
|
|
760
785
|
return logic;
|
|
761
786
|
}
|
|
762
787
|
|