@statelyai/inspect
Advanced tools
Comparing version 0.0.11 to 0.1.0
@@ -43,25 +43,19 @@ import { InspectionEvent, Snapshot, AnyActorRef, AnyEventObject, Observer, Subscribable } from 'xstate'; | ||
*/ | ||
snapshot: ({ actor, snapshot, event, }: { | ||
actor: AnyActorRef | string; | ||
snapshot: InspectedSnapshot; | ||
snapshot(actor: AnyActorRef | string, snapshot: InspectedSnapshot, info?: { | ||
event?: AnyEventObject; | ||
}) => void; | ||
}): void; | ||
/** | ||
* Sends an event inspection event. This represents the event that was sent to the actor. | ||
*/ | ||
event: ({ target, event, source, }: { | ||
target: AnyActorRef | string; | ||
event: AnyEventObject | string; | ||
event(actor: AnyActorRef | string, event: AnyEventObject | string, info?: { | ||
source?: AnyActorRef | string; | ||
}) => void; | ||
}): void; | ||
/** | ||
* Sends an actor registration inspection event. This represents the actor that was created. | ||
*/ | ||
actor: ({ actor, snapshot, definition, parentId, rootId, }: { | ||
actor: AnyActorRef | string; | ||
snapshot?: InspectedSnapshot; | ||
actor(actor: AnyActorRef | string, snapshot?: InspectedSnapshot, info?: { | ||
definition?: string; | ||
parentId?: string; | ||
rootId?: string; | ||
}) => void; | ||
}): void; | ||
/** | ||
@@ -68,0 +62,0 @@ * Starts the inspector. |
@@ -60,3 +60,3 @@ "use strict"; | ||
name: "@statelyai/inspect", | ||
version: "0.0.11", | ||
version: "0.1.0", | ||
description: "Inspection utilities for state, actors, workflows, and state machines.", | ||
@@ -105,4 +105,3 @@ main: "dist/index.js", | ||
adapter, | ||
actor: (info) => { | ||
const actorRef = info.actor; | ||
actor: (actorRef, snapshot, info) => { | ||
const sessionId = typeof actorRef === "string" ? actorRef : actorRef.sessionId; | ||
@@ -124,8 +123,8 @@ const definitionObject = actorRef?.logic?.config; | ||
definition, | ||
snapshot: info.snapshot ?? { status: "active" } | ||
snapshot: snapshot ?? { status: "active" } | ||
}); | ||
}, | ||
event(info) { | ||
const sessionId = typeof info.target === "string" ? info.target : info.target.sessionId; | ||
const sourceId = !info.source ? void 0 : typeof info.source === "string" ? info.source : info.source.sessionId; | ||
event(target, event, info) { | ||
const sessionId = typeof target === "string" ? target : target.sessionId; | ||
const sourceId = !info?.source ? void 0 : typeof info.source === "string" ? info.source : info.source.sessionId; | ||
adapter.send({ | ||
@@ -135,3 +134,3 @@ type: "@xstate.event", | ||
sessionId, | ||
event: toEventObject(info.event), | ||
event: toEventObject(event), | ||
id: Math.random().toString(), | ||
@@ -143,4 +142,4 @@ createdAt: Date.now().toString(), | ||
}, | ||
snapshot(info) { | ||
const sessionId = typeof info.actor === "string" ? info.actor : info.actor.sessionId; | ||
snapshot(actor, snapshot, info) { | ||
const sessionId = typeof actor === "string" ? actor : actor.sessionId; | ||
adapter.send({ | ||
@@ -150,5 +149,5 @@ type: "@xstate.snapshot", | ||
status: "active", | ||
...info.snapshot | ||
...snapshot | ||
}, | ||
event: info.event ?? { type: "" }, | ||
event: info?.event ?? { type: "" }, | ||
sessionId, | ||
@@ -155,0 +154,0 @@ id: null, |
@@ -11,3 +11,3 @@ { | ||
"name": "@statelyai/inspect", | ||
"version": "0.0.11", | ||
"version": "0.1.0", | ||
"description": "Inspection utilities for state, actors, workflows, and state machines.", | ||
@@ -14,0 +14,0 @@ "main": "dist/index.js", |
@@ -30,3 +30,3 @@ # Stately.ai Inspect | ||
**Browser inspector with anything:** | ||
**Browser inspector with _anything_:** | ||
@@ -40,29 +40,19 @@ ```ts | ||
inspector.actor({ | ||
actor: 'someActor', | ||
snapshot: { | ||
status: 'active', | ||
context: { | ||
/* any context data */ | ||
}, | ||
inspector.actor('someActor', { | ||
status: 'active', | ||
context: { | ||
/* any context data */ | ||
}, | ||
}); | ||
inspector.actor({ actor: 'anotherActor' }); | ||
inspector.actor('anotherActor'); | ||
inspector.event({ | ||
target: 'someActor', | ||
event: { type: 'hello' }, | ||
source: 'anotherActor', | ||
}); | ||
inspector.event('someActor', 'hello', { source: 'anotherActor' }); | ||
inspector.snapshot({ | ||
actor: 'anotherActor', | ||
snapshot: { | ||
status: 'active', | ||
context: { | ||
/* any context data */ | ||
}, | ||
inspector.snapshot('anotherActor', { | ||
status: 'active', | ||
context: { | ||
/* any context data */ | ||
}, | ||
}); | ||
``` |
@@ -116,23 +116,14 @@ import { expect, test } from 'vitest'; | ||
inspector.actor({ actor: 'test' }); | ||
inspector.actor({ | ||
actor: 'another', | ||
snapshot: { status: 'active', context: 10 }, | ||
}); | ||
inspector.event({ target: 'test', event: 'stringEvent' }); | ||
inspector.event({ | ||
target: 'another', | ||
event: { type: 'objectEvent' }, | ||
source: 'test', | ||
}); | ||
inspector.snapshot({ | ||
actor: 'test', | ||
snapshot: { status: 'active', context: 20 }, | ||
}); | ||
inspector.snapshot({ | ||
actor: 'another', | ||
snapshot: { status: 'done', context: { foo: 'bar' } }, | ||
event: { type: 'objectEvent' }, | ||
}); | ||
inspector.actor('test'); | ||
inspector.actor('another', { status: 'active', context: 10 }); | ||
inspector.event('test', 'stringEvent'); | ||
inspector.event('another', { type: 'objectEvent' }, { source: 'test' }); | ||
inspector.snapshot('test', { status: 'active', context: 20 }); | ||
inspector.snapshot( | ||
'another', | ||
{ status: 'done', context: { foo: 'bar' } }, | ||
{ event: { type: 'objectEvent' } } | ||
); | ||
expect(events.map(simplifyEvent)).toMatchInlineSnapshot(` | ||
@@ -195,5 +186,5 @@ [ | ||
inspector.actor({ actor: 'test' }); | ||
inspector.actor('test'); | ||
expect(events[0]._version).toEqual(pkg.version); | ||
}); |
@@ -55,4 +55,3 @@ import { | ||
adapter, | ||
actor: (info) => { | ||
const actorRef = info.actor; | ||
actor: (actorRef, snapshot, info) => { | ||
const sessionId = | ||
@@ -84,9 +83,8 @@ typeof actorRef === 'string' ? actorRef : actorRef.sessionId; | ||
definition, | ||
snapshot: info.snapshot ?? { status: 'active' }, | ||
snapshot: snapshot ?? { status: 'active' }, | ||
} satisfies StatelyActorEvent); | ||
}, | ||
event(info) { | ||
const sessionId = | ||
typeof info.target === 'string' ? info.target : info.target.sessionId; | ||
const sourceId = !info.source | ||
event(target, event, info) { | ||
const sessionId = typeof target === 'string' ? target : target.sessionId; | ||
const sourceId = !info?.source | ||
? undefined | ||
@@ -100,3 +98,3 @@ : typeof info.source === 'string' | ||
sessionId, | ||
event: toEventObject(info.event), | ||
event: toEventObject(event), | ||
id: Math.random().toString(), | ||
@@ -108,5 +106,4 @@ createdAt: Date.now().toString(), | ||
}, | ||
snapshot(info) { | ||
const sessionId = | ||
typeof info.actor === 'string' ? info.actor : info.actor.sessionId; | ||
snapshot(actor, snapshot, info) { | ||
const sessionId = typeof actor === 'string' ? actor : actor.sessionId; | ||
adapter.send({ | ||
@@ -116,5 +113,5 @@ type: '@xstate.snapshot', | ||
status: 'active', | ||
...info.snapshot, | ||
...snapshot, | ||
} as unknown as Snapshot<unknown>, | ||
event: info.event ?? { type: '' }, | ||
event: info?.event ?? { type: '' }, | ||
sessionId, | ||
@@ -121,0 +118,0 @@ id: null as any, |
@@ -65,39 +65,27 @@ import { | ||
*/ | ||
snapshot: ({ | ||
actor, | ||
snapshot, | ||
event, | ||
}: { | ||
actor: AnyActorRef | string; | ||
snapshot: InspectedSnapshot; | ||
event?: AnyEventObject; | ||
}) => void; | ||
snapshot( | ||
actor: AnyActorRef | string, | ||
snapshot: InspectedSnapshot, | ||
info?: { event?: AnyEventObject } | ||
): void; | ||
/** | ||
* Sends an event inspection event. This represents the event that was sent to the actor. | ||
*/ | ||
event: ({ | ||
target, | ||
event, | ||
source, | ||
}: { | ||
target: AnyActorRef | string; | ||
event: AnyEventObject | string; | ||
source?: AnyActorRef | string; | ||
}) => void; | ||
event( | ||
actor: AnyActorRef | string, | ||
event: AnyEventObject | string, | ||
info?: { source?: AnyActorRef | string } | ||
): void; | ||
/** | ||
* Sends an actor registration inspection event. This represents the actor that was created. | ||
*/ | ||
actor: ({ | ||
actor, | ||
snapshot, | ||
definition, | ||
parentId, | ||
rootId, | ||
}: { | ||
actor: AnyActorRef | string; | ||
snapshot?: InspectedSnapshot; | ||
definition?: string; | ||
parentId?: string; | ||
rootId?: string; | ||
}) => void; | ||
actor( | ||
actor: AnyActorRef | string, | ||
snapshot?: InspectedSnapshot, | ||
info?: { | ||
definition?: string; | ||
parentId?: string; | ||
rootId?: string; | ||
} | ||
): void; | ||
/** | ||
@@ -104,0 +92,0 @@ * Starts the inspector. |
@@ -1,2 +0,2 @@ | ||
import type { AnyEventObject } from 'xstate'; | ||
import type { AnyEventObject, AnyActorRef } from 'xstate'; | ||
@@ -10,1 +10,10 @@ export function toEventObject(event: AnyEventObject | string): AnyEventObject { | ||
} | ||
export function isActorRef(actorRef: any): actorRef is AnyActorRef { | ||
return ( | ||
typeof actorRef === 'object' && | ||
actorRef !== null && | ||
typeof actorRef.sessionId === 'string' && | ||
typeof actorRef.send === 'function' | ||
); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59486
1538
57