xstate 6.0.0-alpha.39 → 6.0.0-alpha.40

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.
@@ -439,6 +439,10 @@ class StateMachine {
439
439
  /** The machine's own version. */
440
440
  this.version = void 0;
441
441
  this.schemas = void 0;
442
+ /** Standard Schema for snapshots persisted by this machine version. */
443
+ this.snapshotSchema = void 0;
444
+ /** Standard Schema for complete events accepted by this machine version. */
445
+ this.eventSchema = void 0;
442
446
  this.sources = void 0;
443
447
  /** Runtime options for machine execution. */
444
448
  this.options = void 0;
@@ -469,6 +473,134 @@ class StateMachine {
469
473
  };
470
474
  this.version = this.config.version;
471
475
  this.schemas = this.config.schemas;
476
+ this.snapshotSchema = {
477
+ '~standard': {
478
+ version: 1,
479
+ vendor: 'xstate',
480
+ validate: async value => {
481
+ if (value === null || typeof value !== 'object') {
482
+ return {
483
+ issues: [{
484
+ message: 'Expected a persisted snapshot.'
485
+ }]
486
+ };
487
+ }
488
+ const snapshot = {
489
+ historyValue: {},
490
+ timers: {},
491
+ ...value
492
+ };
493
+ const contextSchema = this.schemas?.context;
494
+ let context = snapshot.context;
495
+ if (contextSchema) {
496
+ const result = await contextSchema['~standard'].validate(context);
497
+ if (result.issues) {
498
+ return {
499
+ issues: [{
500
+ message: `Invalid context for machine '${this.id}' version '${this.version}': ${result.issues[0]?.message}`
501
+ }]
502
+ };
503
+ }
504
+ context = result.value;
505
+ }
506
+ for (const key of ['value', 'children']) {
507
+ if (!(key in snapshot)) {
508
+ return {
509
+ issues: [{
510
+ message: `Persisted snapshot is missing '${key}'.`
511
+ }]
512
+ };
513
+ }
514
+ }
515
+ if (!['active', 'done', 'error', 'stopped'].includes(snapshot.status)) {
516
+ return {
517
+ issues: [{
518
+ message: 'Persisted snapshot has invalid status.'
519
+ }]
520
+ };
521
+ }
522
+ for (const key of ['children', 'historyValue', 'timers']) {
523
+ if (snapshot[key] === null || typeof snapshot[key] !== 'object' || Array.isArray(snapshot[key])) {
524
+ return {
525
+ issues: [{
526
+ message: `Persisted snapshot has invalid '${key}'.`
527
+ }]
528
+ };
529
+ }
530
+ }
531
+ try {
532
+ this.resolveState({
533
+ value: snapshot.value,
534
+ context
535
+ });
536
+ } catch (error) {
537
+ return {
538
+ issues: [{
539
+ message: error instanceof Error ? error.message : 'Persisted snapshot has invalid state value.'
540
+ }]
541
+ };
542
+ }
543
+ return {
544
+ value: {
545
+ ...snapshot,
546
+ context
547
+ }
548
+ };
549
+ }
550
+ }
551
+ };
552
+ this.eventSchema = {
553
+ '~standard': {
554
+ version: 1,
555
+ vendor: 'xstate',
556
+ validate: async value => {
557
+ if (value === null || typeof value !== 'object' || typeof value.type !== 'string') {
558
+ return {
559
+ issues: [{
560
+ message: 'Expected an event object.'
561
+ }]
562
+ };
563
+ }
564
+ const event = value;
565
+ const eventSchemas = this.schemas?.events;
566
+ const isFrameworkEvent = event.type.startsWith('xstate.') || event.type.startsWith('@xstate.');
567
+ const schema = eventSchemas && Object.hasOwn(eventSchemas, event.type) ? eventSchemas[event.type] : undefined;
568
+ if (eventSchemas && !schema && !isFrameworkEvent) {
569
+ return {
570
+ issues: [{
571
+ message: `Unknown event '${event.type}' for machine '${this.id}' version '${this.version}'.`
572
+ }]
573
+ };
574
+ }
575
+ if (!schema) {
576
+ return {
577
+ value: event
578
+ };
579
+ }
580
+ const {
581
+ type,
582
+ ...payload
583
+ } = event;
584
+ const result = await schema['~standard'].validate(payload);
585
+ if (result.issues) {
586
+ return result;
587
+ }
588
+ if (result.value === null || typeof result.value !== 'object') {
589
+ return {
590
+ issues: [{
591
+ message: 'Expected an event payload.'
592
+ }]
593
+ };
594
+ }
595
+ return {
596
+ value: {
597
+ ...result.value,
598
+ type
599
+ }
600
+ };
601
+ }
602
+ }
603
+ };
472
604
  this.internalEventDescriptors = this.config.internalEvents ?? [];
473
605
  this.options = {
474
606
  maxIterations: Infinity,
@@ -437,6 +437,10 @@ class StateMachine {
437
437
  /** The machine's own version. */
438
438
  this.version = void 0;
439
439
  this.schemas = void 0;
440
+ /** Standard Schema for snapshots persisted by this machine version. */
441
+ this.snapshotSchema = void 0;
442
+ /** Standard Schema for complete events accepted by this machine version. */
443
+ this.eventSchema = void 0;
440
444
  this.sources = void 0;
441
445
  /** Runtime options for machine execution. */
442
446
  this.options = void 0;
@@ -467,6 +471,134 @@ class StateMachine {
467
471
  };
468
472
  this.version = this.config.version;
469
473
  this.schemas = this.config.schemas;
474
+ this.snapshotSchema = {
475
+ '~standard': {
476
+ version: 1,
477
+ vendor: 'xstate',
478
+ validate: async value => {
479
+ if (value === null || typeof value !== 'object') {
480
+ return {
481
+ issues: [{
482
+ message: 'Expected a persisted snapshot.'
483
+ }]
484
+ };
485
+ }
486
+ const snapshot = {
487
+ historyValue: {},
488
+ timers: {},
489
+ ...value
490
+ };
491
+ const contextSchema = this.schemas?.context;
492
+ let context = snapshot.context;
493
+ if (contextSchema) {
494
+ const result = await contextSchema['~standard'].validate(context);
495
+ if (result.issues) {
496
+ return {
497
+ issues: [{
498
+ message: `Invalid context for machine '${this.id}' version '${this.version}': ${result.issues[0]?.message}`
499
+ }]
500
+ };
501
+ }
502
+ context = result.value;
503
+ }
504
+ for (const key of ['value', 'children']) {
505
+ if (!(key in snapshot)) {
506
+ return {
507
+ issues: [{
508
+ message: `Persisted snapshot is missing '${key}'.`
509
+ }]
510
+ };
511
+ }
512
+ }
513
+ if (!['active', 'done', 'error', 'stopped'].includes(snapshot.status)) {
514
+ return {
515
+ issues: [{
516
+ message: 'Persisted snapshot has invalid status.'
517
+ }]
518
+ };
519
+ }
520
+ for (const key of ['children', 'historyValue', 'timers']) {
521
+ if (snapshot[key] === null || typeof snapshot[key] !== 'object' || Array.isArray(snapshot[key])) {
522
+ return {
523
+ issues: [{
524
+ message: `Persisted snapshot has invalid '${key}'.`
525
+ }]
526
+ };
527
+ }
528
+ }
529
+ try {
530
+ this.resolveState({
531
+ value: snapshot.value,
532
+ context
533
+ });
534
+ } catch (error) {
535
+ return {
536
+ issues: [{
537
+ message: error instanceof Error ? error.message : 'Persisted snapshot has invalid state value.'
538
+ }]
539
+ };
540
+ }
541
+ return {
542
+ value: {
543
+ ...snapshot,
544
+ context
545
+ }
546
+ };
547
+ }
548
+ }
549
+ };
550
+ this.eventSchema = {
551
+ '~standard': {
552
+ version: 1,
553
+ vendor: 'xstate',
554
+ validate: async value => {
555
+ if (value === null || typeof value !== 'object' || typeof value.type !== 'string') {
556
+ return {
557
+ issues: [{
558
+ message: 'Expected an event object.'
559
+ }]
560
+ };
561
+ }
562
+ const event = value;
563
+ const eventSchemas = this.schemas?.events;
564
+ const isFrameworkEvent = event.type.startsWith('xstate.') || event.type.startsWith('@xstate.');
565
+ const schema = eventSchemas && Object.hasOwn(eventSchemas, event.type) ? eventSchemas[event.type] : undefined;
566
+ if (eventSchemas && !schema && !isFrameworkEvent) {
567
+ return {
568
+ issues: [{
569
+ message: `Unknown event '${event.type}' for machine '${this.id}' version '${this.version}'.`
570
+ }]
571
+ };
572
+ }
573
+ if (!schema) {
574
+ return {
575
+ value: event
576
+ };
577
+ }
578
+ const {
579
+ type,
580
+ ...payload
581
+ } = event;
582
+ const result = await schema['~standard'].validate(payload);
583
+ if (result.issues) {
584
+ return result;
585
+ }
586
+ if (result.value === null || typeof result.value !== 'object') {
587
+ return {
588
+ issues: [{
589
+ message: 'Expected an event payload.'
590
+ }]
591
+ };
592
+ }
593
+ return {
594
+ value: {
595
+ ...result.value,
596
+ type
597
+ }
598
+ };
599
+ }
600
+ }
601
+ };
470
602
  this.internalEventDescriptors = this.config.internalEvents ?? [];
471
603
  this.options = {
472
604
  maxIterations: Infinity,
@@ -457,6 +457,10 @@ class StateMachine {
457
457
  /** The machine's own version. */
458
458
  this.version = void 0;
459
459
  this.schemas = void 0;
460
+ /** Standard Schema for snapshots persisted by this machine version. */
461
+ this.snapshotSchema = void 0;
462
+ /** Standard Schema for complete events accepted by this machine version. */
463
+ this.eventSchema = void 0;
460
464
  this.sources = void 0;
461
465
  /** Runtime options for machine execution. */
462
466
  this.options = void 0;
@@ -498,6 +502,134 @@ class StateMachine {
498
502
  }
499
503
  this.version = this.config.version;
500
504
  this.schemas = this.config.schemas;
505
+ this.snapshotSchema = {
506
+ '~standard': {
507
+ version: 1,
508
+ vendor: 'xstate',
509
+ validate: async value => {
510
+ if (value === null || typeof value !== 'object') {
511
+ return {
512
+ issues: [{
513
+ message: 'Expected a persisted snapshot.'
514
+ }]
515
+ };
516
+ }
517
+ const snapshot = {
518
+ historyValue: {},
519
+ timers: {},
520
+ ...value
521
+ };
522
+ const contextSchema = this.schemas?.context;
523
+ let context = snapshot.context;
524
+ if (contextSchema) {
525
+ const result = await contextSchema['~standard'].validate(context);
526
+ if (result.issues) {
527
+ return {
528
+ issues: [{
529
+ message: `Invalid context for machine '${this.id}' version '${this.version}': ${result.issues[0]?.message}`
530
+ }]
531
+ };
532
+ }
533
+ context = result.value;
534
+ }
535
+ for (const key of ['value', 'children']) {
536
+ if (!(key in snapshot)) {
537
+ return {
538
+ issues: [{
539
+ message: `Persisted snapshot is missing '${key}'.`
540
+ }]
541
+ };
542
+ }
543
+ }
544
+ if (!['active', 'done', 'error', 'stopped'].includes(snapshot.status)) {
545
+ return {
546
+ issues: [{
547
+ message: 'Persisted snapshot has invalid status.'
548
+ }]
549
+ };
550
+ }
551
+ for (const key of ['children', 'historyValue', 'timers']) {
552
+ if (snapshot[key] === null || typeof snapshot[key] !== 'object' || Array.isArray(snapshot[key])) {
553
+ return {
554
+ issues: [{
555
+ message: `Persisted snapshot has invalid '${key}'.`
556
+ }]
557
+ };
558
+ }
559
+ }
560
+ try {
561
+ this.resolveState({
562
+ value: snapshot.value,
563
+ context
564
+ });
565
+ } catch (error) {
566
+ return {
567
+ issues: [{
568
+ message: error instanceof Error ? error.message : 'Persisted snapshot has invalid state value.'
569
+ }]
570
+ };
571
+ }
572
+ return {
573
+ value: {
574
+ ...snapshot,
575
+ context
576
+ }
577
+ };
578
+ }
579
+ }
580
+ };
581
+ this.eventSchema = {
582
+ '~standard': {
583
+ version: 1,
584
+ vendor: 'xstate',
585
+ validate: async value => {
586
+ if (value === null || typeof value !== 'object' || typeof value.type !== 'string') {
587
+ return {
588
+ issues: [{
589
+ message: 'Expected an event object.'
590
+ }]
591
+ };
592
+ }
593
+ const event = value;
594
+ const eventSchemas = this.schemas?.events;
595
+ const isFrameworkEvent = event.type.startsWith('xstate.') || event.type.startsWith('@xstate.');
596
+ const schema = eventSchemas && Object.hasOwn(eventSchemas, event.type) ? eventSchemas[event.type] : undefined;
597
+ if (eventSchemas && !schema && !isFrameworkEvent) {
598
+ return {
599
+ issues: [{
600
+ message: `Unknown event '${event.type}' for machine '${this.id}' version '${this.version}'.`
601
+ }]
602
+ };
603
+ }
604
+ if (!schema) {
605
+ return {
606
+ value: event
607
+ };
608
+ }
609
+ const {
610
+ type,
611
+ ...payload
612
+ } = event;
613
+ const result = await schema['~standard'].validate(payload);
614
+ if (result.issues) {
615
+ return result;
616
+ }
617
+ if (result.value === null || typeof result.value !== 'object') {
618
+ return {
619
+ issues: [{
620
+ message: 'Expected an event payload.'
621
+ }]
622
+ };
623
+ }
624
+ return {
625
+ value: {
626
+ ...result.value,
627
+ type
628
+ }
629
+ };
630
+ }
631
+ }
632
+ };
501
633
  this.internalEventDescriptors = this.config.internalEvents ?? [];
502
634
  this.options = {
503
635
  maxIterations: Infinity,
@@ -455,6 +455,10 @@ class StateMachine {
455
455
  /** The machine's own version. */
456
456
  this.version = void 0;
457
457
  this.schemas = void 0;
458
+ /** Standard Schema for snapshots persisted by this machine version. */
459
+ this.snapshotSchema = void 0;
460
+ /** Standard Schema for complete events accepted by this machine version. */
461
+ this.eventSchema = void 0;
458
462
  this.sources = void 0;
459
463
  /** Runtime options for machine execution. */
460
464
  this.options = void 0;
@@ -496,6 +500,134 @@ class StateMachine {
496
500
  }
497
501
  this.version = this.config.version;
498
502
  this.schemas = this.config.schemas;
503
+ this.snapshotSchema = {
504
+ '~standard': {
505
+ version: 1,
506
+ vendor: 'xstate',
507
+ validate: async value => {
508
+ if (value === null || typeof value !== 'object') {
509
+ return {
510
+ issues: [{
511
+ message: 'Expected a persisted snapshot.'
512
+ }]
513
+ };
514
+ }
515
+ const snapshot = {
516
+ historyValue: {},
517
+ timers: {},
518
+ ...value
519
+ };
520
+ const contextSchema = this.schemas?.context;
521
+ let context = snapshot.context;
522
+ if (contextSchema) {
523
+ const result = await contextSchema['~standard'].validate(context);
524
+ if (result.issues) {
525
+ return {
526
+ issues: [{
527
+ message: `Invalid context for machine '${this.id}' version '${this.version}': ${result.issues[0]?.message}`
528
+ }]
529
+ };
530
+ }
531
+ context = result.value;
532
+ }
533
+ for (const key of ['value', 'children']) {
534
+ if (!(key in snapshot)) {
535
+ return {
536
+ issues: [{
537
+ message: `Persisted snapshot is missing '${key}'.`
538
+ }]
539
+ };
540
+ }
541
+ }
542
+ if (!['active', 'done', 'error', 'stopped'].includes(snapshot.status)) {
543
+ return {
544
+ issues: [{
545
+ message: 'Persisted snapshot has invalid status.'
546
+ }]
547
+ };
548
+ }
549
+ for (const key of ['children', 'historyValue', 'timers']) {
550
+ if (snapshot[key] === null || typeof snapshot[key] !== 'object' || Array.isArray(snapshot[key])) {
551
+ return {
552
+ issues: [{
553
+ message: `Persisted snapshot has invalid '${key}'.`
554
+ }]
555
+ };
556
+ }
557
+ }
558
+ try {
559
+ this.resolveState({
560
+ value: snapshot.value,
561
+ context
562
+ });
563
+ } catch (error) {
564
+ return {
565
+ issues: [{
566
+ message: error instanceof Error ? error.message : 'Persisted snapshot has invalid state value.'
567
+ }]
568
+ };
569
+ }
570
+ return {
571
+ value: {
572
+ ...snapshot,
573
+ context
574
+ }
575
+ };
576
+ }
577
+ }
578
+ };
579
+ this.eventSchema = {
580
+ '~standard': {
581
+ version: 1,
582
+ vendor: 'xstate',
583
+ validate: async value => {
584
+ if (value === null || typeof value !== 'object' || typeof value.type !== 'string') {
585
+ return {
586
+ issues: [{
587
+ message: 'Expected an event object.'
588
+ }]
589
+ };
590
+ }
591
+ const event = value;
592
+ const eventSchemas = this.schemas?.events;
593
+ const isFrameworkEvent = event.type.startsWith('xstate.') || event.type.startsWith('@xstate.');
594
+ const schema = eventSchemas && Object.hasOwn(eventSchemas, event.type) ? eventSchemas[event.type] : undefined;
595
+ if (eventSchemas && !schema && !isFrameworkEvent) {
596
+ return {
597
+ issues: [{
598
+ message: `Unknown event '${event.type}' for machine '${this.id}' version '${this.version}'.`
599
+ }]
600
+ };
601
+ }
602
+ if (!schema) {
603
+ return {
604
+ value: event
605
+ };
606
+ }
607
+ const {
608
+ type,
609
+ ...payload
610
+ } = event;
611
+ const result = await schema['~standard'].validate(payload);
612
+ if (result.issues) {
613
+ return result;
614
+ }
615
+ if (result.value === null || typeof result.value !== 'object') {
616
+ return {
617
+ issues: [{
618
+ message: 'Expected an event payload.'
619
+ }]
620
+ };
621
+ }
622
+ return {
623
+ value: {
624
+ ...result.value,
625
+ type
626
+ }
627
+ };
628
+ }
629
+ }
630
+ };
499
631
  this.internalEventDescriptors = this.config.internalEvents ?? [];
500
632
  this.options = {
501
633
  maxIterations: Infinity,
@@ -5,6 +5,8 @@ import { AnyActorSystem } from "./system.js";
5
5
  import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActorLogic, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EmittedFrom, EventObject, EventFromLogic, ExecutableActionObjectFromLogic, HistoryValue, InputFrom, IsAny, MachineContext, MetaObject, OutputFrom, Snapshot, SnapshotFrom, StateValue, StateSchema, SnapshotStatus } from "./types.js";
6
6
  import { AnyMachineSchemas, Sources, Next_MachineConfig, MachineOptions } from "./types.v6.js";
7
7
  import type { ActorLogicValidator } from "./validation.types.js";
8
+ import type { StandardSchemaV1 } from "./schema.types.js";
9
+ import type { PersistedMachineSnapshot } from "./machineVersion.types.js";
8
10
  type CompatibleProvidedActorSource<TExpected extends AnyActorLogic, TActual extends AnyActorLogic> = IsAny<TActual> extends true ? TActual : [OutputFrom<TActual>] extends [OutputFrom<TExpected>] ? [Omit<SnapshotFrom<TActual>, 'input'>] extends [
9
11
  Omit<SnapshotFrom<TExpected>, 'input'>
10
12
  ] ? [InputFrom<TExpected>] extends [InputFrom<TActual>] ? [EventFromLogic<TExpected>] extends [EventFromLogic<TActual>] ? [EmittedFrom<TActual>] extends [EmittedFrom<TExpected>] ? TActual : never : never : never : never : never;
@@ -21,6 +23,12 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
21
23
  /** The machine's own version. */
22
24
  version?: string;
23
25
  schemas: AnyMachineSchemas | undefined;
26
+ /** Standard Schema for snapshots persisted by this machine version. */
27
+ readonly snapshotSchema: StandardSchemaV1<unknown, Snapshot<unknown> & PersistedMachineSnapshot & {
28
+ context: TContext;
29
+ }>;
30
+ /** Standard Schema for complete events accepted by this machine version. */
31
+ readonly eventSchema: StandardSchemaV1<unknown, TEvent>;
24
32
  sources: Sources;
25
33
  /** Runtime options for machine execution. */
26
34
  options: MachineOptions;
@@ -47,7 +55,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
47
55
  actors?: TProvidedActorMap & ProvidedActors<TActorMap, TProvidedActorMap>;
48
56
  guards?: Partial<TGuardMap>;
49
57
  delays?: Partial<TDelayMap>;
50
- }): StateMachine<TContext, TEvent, TChildren, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig, TActionMap, TActorMap, TGuardMap, TDelayMap>;
58
+ }): this;
51
59
  resolveState(config: {
52
60
  value: StateValue;
53
61
  context?: TContext;
@@ -1,6 +1,6 @@
1
1
  import { symbolObservable } from "./symbolObservable.js";
2
2
  import { AnyActorSystem, Clock } from "./system.js";
3
- import type { ActorTrigger, AnyActor, AnyActorLogic, EmittedFrom, EventFromLogic, SendableEventFromLogic, InputFrom, Snapshot, SnapshotFrom, Readable } from "./types.js";
3
+ import type { ActorTrigger, AnyActor, AnyActorLogic, EmittedFrom, EventFromLogic, SendableEventFromLogic, InputFrom, PersistedSnapshotFor, Snapshot, SnapshotFrom, Readable } from "./types.js";
4
4
  import { ActorOptions, ActorInstance, ActorRef, InteropSubscribable, Observer, Subscription } from "./types.js";
5
5
  export declare const $$ACTOR_TYPE = 1;
6
6
  export declare enum ProcessingStatus {
@@ -172,7 +172,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
172
172
  * Can be restored with {@link ActorOptions.state}
173
173
  * @see https://stately.ai/docs/persistence
174
174
  */
175
- getPersistedSnapshot(): Snapshot<unknown>;
175
+ getPersistedSnapshot(): Snapshot<unknown> & PersistedSnapshotFor<TLogic>;
176
176
  [symbolObservable](): InteropSubscribable<SnapshotFrom<TLogic>>;
177
177
  /**
178
178
  * Read an actor’s snapshot synchronously.
@@ -7,7 +7,7 @@ export { createMachineFromConfig } from "./createMachineFromConfig.js";
7
7
  export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, TransitionJSON } from "./createMachineFromConfig.js";
8
8
  export { machineConfigToJSON, serializeMachine, type CodeExpression } from "./serialize.js";
9
9
  export { mapState } from "./mapState.js";
10
- export { machineVersions, type AdaptEventsOptions, type EventAdapterHandlers, type EventHistorySource, type MigrateSnapshotOptions, type MachineVersionsOptions, type ParsedPersistedSnapshot, type PersistedMachineIdentity, type PersistedSnapshotDataFrom, type PersistedSnapshotSource, type SnapshotMigrationHandlers, type PersistedSnapshotFrom } from "./machineVersions.js";
10
+ export { machineVersions, type AdaptEventsOptions, type EventAdapterHandlers, type EventHistorySource, type MigrateSnapshotOptions, type MachineEventSchema, type MachineSnapshotSchema, type MachineVersionsOptions, type MachineVersionDescriptor, type ParsedPersistedSnapshot, type PersistedMachineIdentity, type PersistedMachineSnapshot, type PersistedSnapshotDataFrom, type PersistedSnapshotSource, type SnapshotMigrationHandlers, type PersistedSnapshotFrom } from "./machineVersions.js";
11
11
  export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
12
12
  export type { ActorValidationBoundary, ActorValidationEventOrigin, ActorValidationRequest, ActorLogicValidator } from "./validation.types.js";
13
13
  export { createSystem, setup } from "./setup.js";
@@ -0,0 +1,37 @@
1
+ import type { StandardSchemaV1 } from "./schema.types.js";
2
+ import type { EventObject, Snapshot } from "./types.js";
3
+ /** Durable machine snapshot fields that a historical snapshot schema describes. */
4
+ export type PersistedMachineSnapshot = {
5
+ status: Snapshot<unknown>['status'];
6
+ output?: unknown;
7
+ error?: unknown;
8
+ value: unknown;
9
+ context: unknown;
10
+ children: Record<string, unknown>;
11
+ historyValue: Record<string, unknown>;
12
+ timers: Record<string, unknown>;
13
+ _nextActorId?: number;
14
+ _nextTimerId?: number;
15
+ stateInputs?: Record<string, Record<string, unknown>>;
16
+ machine?: {
17
+ id: string;
18
+ version: string;
19
+ };
20
+ version?: string;
21
+ [key: string]: unknown;
22
+ };
23
+ /** A Standard Schema for a complete persisted machine snapshot. */
24
+ export type MachineSnapshotSchema = StandardSchemaV1<unknown, PersistedMachineSnapshot>;
25
+ /** A Standard Schema for a complete persisted event object. */
26
+ export type MachineEventSchema = StandardSchemaV1<unknown, EventObject>;
27
+ /** Schema-backed capabilities for one machine version. */
28
+ export type MachineVersionDescriptor = {
29
+ id: string;
30
+ version: string;
31
+ } & ({
32
+ snapshotSchema: MachineSnapshotSchema;
33
+ eventSchema?: MachineEventSchema;
34
+ } | {
35
+ snapshotSchema?: MachineSnapshotSchema;
36
+ eventSchema: MachineEventSchema;
37
+ });