Skip to content

Commit

Permalink
Merge pull request #39 from statelyai/davidkpiano/xstate-5-18-1
Browse files Browse the repository at this point in the history
Update XState with ActorRefLike types
  • Loading branch information
davidkpiano authored Sep 23, 2024
2 parents 62d0c95 + 70430ee commit 7a8cb3e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-rocks-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@statelyai/inspect": patch
---

Update XState to 5.18.2
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"tsup": "^8.2.4",
"typescript": "^5.5.4",
"vitest": "^1.6.0",
"xstate": "^5.17.1"
"xstate": "^5.18.2"
},
"name": "@statelyai/inspect",
"version": "0.5.1",
Expand Down Expand Up @@ -36,7 +36,8 @@
"changeset": "changeset",
"release": "changeset publish",
"version": "changeset version",
"dev": "yarn build && ./scripts/dev.sh"
"dev": "yarn build && ./scripts/dev.sh",
"typecheck": "tsc --noEmit"
},
"publishConfig": {
"access": "public"
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions src/createInspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
StatelyInspectionEvent,
StatelySnapshotEvent,
Adapter,
ActorRefLikeWithData,
} from './types';
import { toEventObject } from './utils';
import { Inspector } from './types';
import {
AnyActorRef,
ActorRefLike,
AnyEventObject,
InspectionEvent,
MachineContext,
Expand All @@ -18,8 +19,8 @@ import pkg from '../package.json';
import { idleCallback } from './idleCallback';
import safeStringify from 'safe-stable-stringify';

function getRoot(actorRef: AnyActorRef) {
let marker: AnyActorRef | undefined = actorRef;
function getRoot(actorRef: ActorRefLike) {
let marker: ActorRefLikeWithData | undefined = actorRef;

do {
marker = marker._parent;
Expand All @@ -28,7 +29,7 @@ function getRoot(actorRef: AnyActorRef) {
return marker;
}

function getRootId(actorRefOrId: AnyActorRef | string): string | undefined {
function getRootId(actorRefOrId: ActorRefLike | string): string | undefined {
const rootActorRef =
typeof actorRefOrId === 'string'
? undefined
Expand Down Expand Up @@ -210,7 +211,7 @@ export function convertXStateEvent(
const actorRef = inspectionEvent.actorRef;
const logic = (actorRef as any)?.logic;
const definitionObject = logic?.config;
let name = actorRef.id;
let name = (actorRef as any).id;

// TODO: fix this in XState
if (name === actorRef.sessionId && definitionObject) {
Expand All @@ -237,7 +238,7 @@ export function convertXStateEvent(
createdAt: Date.now().toString(),
id: null as any,
rootId: inspectionEvent.rootId,
parentId: inspectionEvent.actorRef._parent?.sessionId,
parentId: (inspectionEvent.actorRef as any)._parent?.sessionId,
sessionId: inspectionEvent.actorRef.sessionId,
snapshot: inspectionEvent.actorRef.getSnapshot(),
} satisfies StatelyActorEvent;
Expand Down
15 changes: 10 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
AnyActorRef,
ActorRefLike,
AnyEventObject,
InspectionEvent,
Observer,
Expand Down Expand Up @@ -63,23 +63,23 @@ export interface Inspector<TAdapter extends Adapter> {
* Sends a snapshot inspection event. This represents the state of the actor.
*/
snapshot(
actor: AnyActorRef | string,
actor: ActorRefLikeWithData | string,
snapshot: InspectedSnapshot,
info?: { event?: AnyEventObject }
): void;
/**
* Sends an event inspection event. This represents the event that was sent to the actor.
*/
event(
actor: AnyActorRef | string,
actor: ActorRefLikeWithData | string,
event: AnyEventObject | string,
info?: { source?: AnyActorRef | string }
info?: { source?: ActorRefLikeWithData | string }
): void;
/**
* Sends an actor registration inspection event. This represents the actor that was created.
*/
actor(
actor: AnyActorRef | string,
actor: ActorRefLikeWithData | string,
snapshot?: InspectedSnapshot,
info?: {
definition?: string;
Expand Down Expand Up @@ -112,3 +112,8 @@ export interface Inspector<TAdapter extends Adapter> {
*/
inspect: Observer<InspectionEvent>;
}

export type ActorRefLikeWithData = ActorRefLike & {
_parent?: ActorRefLikeWithData;
id?: string;
};

0 comments on commit 7a8cb3e

Please sign in to comment.