Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snyk] Upgrade xstate from 5.14.0 to 5.15.0 #1730

Conversation

madhavilosetty-intel
Copy link
Contributor

snyk-top-banner

Snyk has created this PR to upgrade xstate from 5.14.0 to 5.15.0.

ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.


  • The recommended version is 1 version ahead of your current version.

  • The recommended version was released on 21 days ago.

Release notes
Package name: xstate
  • 5.15.0 - 2024-07-13

    Minor Changes

    • #4976 452bce71e Thanks @ with-heart! - Added exports for actor logic-specific ActorRef types: CallbackActorRef, ObservableActorRef, PromiseActorRef, and TransitionActorRef.

      Each type represents ActorRef narrowed to the corresponding type of logic (the type of self within the actor's logic):

      • CallbackActorRef: actor created by fromCallback

        import { fromCallback, createActor } from 'xstate';

        /** The events the actor receives. /
        type Event = { type: 'someEvent' };
        /
        * The actor's input. */
        type Input = { name: string };

        /** Actor logic that logs whenever it receives an event of type someEvent. */
        const logic = fromCallback<Event, Input>(({ self, input, receive }) => {
        self;
        // ^? CallbackActorRef<Event, Input>

        receive((event) => {
        if (event.type === 'someEvent') {
        console.log(<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">input</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>: received "someEvent" event);
        // logs 'myActor: received "someEvent" event'
        }
        });
        });

        const actor = createActor(logic, { input: { name: 'myActor' } });
        // ^? CallbackActorRef<Event, Input>

      • ObservableActorRef: actor created by fromObservable and fromEventObservable

        import { fromObservable, createActor } from 'xstate';
        import { interval } from 'rxjs';

        /** The type of the value observed by the actor's logic. /
        type Context = number;
        /
        * The actor's input. */
        type Input = { period?: number };

        /**
        * Actor logic that observes a number incremented every input.period
        * milliseconds (default: 1_000).
        */
        const logic = fromObservable<Context, Input>(({ input, self }) => {
        self;
        // ^? ObservableActorRef<Event, Input>

        return interval(input.period ?? 1_000);
        });

        const actor = createActor(logic, { input: { period: 2_000 } });
        // ^? ObservableActorRef<Event, Input>

      • PromiseActorRef: actor created by fromPromise

        import { fromPromise, createActor } from 'xstate';

        /** The actor's resolved output. /
        type Output = string;
        /
        * The actor's input. */
        type Input = { message: string };

        /** Actor logic that fetches the url of an image of a cat saying input.message. */
        const logic = fromPromise<Output, Input>(async ({ input, self }) => {
        self;
        // ^? PromiseActorRef<Output, Input>

        const data = await fetch(https://cataas.com/cat/says/<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">input</span><span class="pl-kos">.</span><span class="pl-c1">message</span><span class="pl-kos">}</span></span>);
        const url = await data.json();
        return url;
        });

        const actor = createActor(logic, { input: { message: 'hello world' } });
        // ^? PromiseActorRef<Output, Input>

      • TransitionActorRef: actor created by fromTransition

        import { fromTransition, createActor, type AnyActorSystem } from 'xstate';

        /** The actor's stored context. /
        type Context = {
        /
        * The current count. /
        count: number;
        /
        * The amount to increase count by. /
        step: number;
        };
        /
        * The events the actor receives. /
        type Event = { type: 'increment' };
        /
        * The actor's input. */
        type Input = { step?: number };

        /**
        * Actor logic that increments count by step when it receives an event of
        * type increment.
        */
        const logic = fromTransition<Context, Event, AnyActorSystem, Input>(
        (state, event, actorScope) => {
        actorScope.self;
        // ^? TransitionActorRef<Context, Event>

        <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">event</span><span class="pl-kos">.</span><span class="pl-c1">type</span> <span class="pl-c1">===</span> <span class="pl-s">'increment'</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-k">return</span> <span class="pl-kos">{</span>
            ...<span class="pl-s1">state</span><span class="pl-kos">,</span>
            <span class="pl-c1">count</span>: <span class="pl-s1">state</span><span class="pl-kos">.</span><span class="pl-c1">count</span> <span class="pl-c1">+</span> <span class="pl-s1">state</span><span class="pl-kos">.</span><span class="pl-c1">step</span>
          <span class="pl-kos">}</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
        <span class="pl-k">return</span> <span class="pl-s1">state</span><span class="pl-kos">;</span>
        

        },
        ({ input, self }) => {
        self;
        // ^? TransitionActorRef<Context, Event>

        <span class="pl-k">return</span> <span class="pl-kos">{</span>
          <span class="pl-c1">count</span>: <span class="pl-c1">0</span><span class="pl-kos">,</span>
          <span class="pl-c1">step</span>: <span class="pl-s1">input</span><span class="pl-kos">.</span><span class="pl-c1">step</span> <span class="pl-c1">??</span> <span class="pl-c1">1</span>
        <span class="pl-kos">}</span><span class="pl-kos">;</span>
        

        }
        );

        const actor = createActor(logic, { input: { step: 10 } });
        // ^? TransitionActorRef<Context, Event>

    • #4949 8aa4c2b90 Thanks @ davidkpiano! - The TypeGen-related types have been removed from XState, simplifying the internal types without affecting normal XState usage.

  • 5.14.0 - 2024-06-22

    Minor Changes

    • #4936 c58b36dc3 Thanks @ davidkpiano! - Inspecting an actor system via actor.system.inspect(ev => …) now accepts a function or observer, and returns a subscription:

      const actor = createActor(someMachine);

      const sub = actor.system.inspect((inspectionEvent) => {
      console.log(inspectionEvent);
      });

      // Inspection events will be logged
      actor.start();
      actor.send({ type: 'anEvent' });

      // ...

      sub.unsubscribe();

      // Will no longer log inspection events
      actor.send({ type: 'someEvent' });

    • #4942 9caaa1f70 Thanks @ boneskull! - DoneActorEvent and ErrorActorEvent now contain property actorId, which refers to the ID of the actor the event refers to.

    • #4935 2ac08b700 Thanks @ davidkpiano! - All actor logic creators now support emitting events:

      Promise actors

      const logic = fromPromise(async ({ emit }) => {
        // ...
        emit({
          type: 'emitted',
          msg: 'hello'
        });
        // ...
      });

      Transition actors

      const logic = fromTransition((state, event, { emit }) => {
        // ...
        emit({
          type: 'emitted',
          msg: 'hello'
        });
        // ...
        return state;
      }, {});

      Observable actors

      const logic = fromObservable(({ emit }) => {
      // ...

      emit({
      type: 'emitted',
      msg: 'hello'
      });

      // ...
      });

      Callback actors

      const logic = fromCallback(({ emit }) => {
        // ...
        emit({
          type: 'emitted',
          msg: 'hello'
        });
        // ...
      });

    Patch Changes

    • #4929 417f35a11 Thanks @ boneskull! - Expose type UnknownActorRef for use when calling getSnapshot() on an unknown ActorRef.
from xstate GitHub release notes

Important

  • Check the changes in this PR to ensure they won't cause issues with your project.
  • This PR was automatically created by Snyk using the credentials of a real user.

Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs.

For more information:

Snyk has created this PR to upgrade xstate from 5.14.0 to 5.15.0.

See this package in npm:
xstate

See this project in Snyk:
https://app.snyk.io/org/mlosetty-intel/project/ab1aa78c-1f6c-4e29-8f8e-86f4aea2fe81?utm_source=github&utm_medium=referral&page=upgrade-pr
@rjbrache rjbrache closed this Aug 6, 2024
@rsdmike rsdmike deleted the snyk-upgrade-31d285340adc348b9db92ecf2fab72af branch December 16, 2024 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants