@xstate/inspect
Advanced tools
Comparing version 0.6.0 to 0.6.5
# @xstate/inspect | ||
## 0.6.5 | ||
### Patch Changes | ||
- [#3198](https://github.com/statelyai/xstate/pull/3198) [`09e2130df`](https://github.com/statelyai/xstate/commit/09e2130dff80815c10df38496a761fe8ae0d9f6e) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue that prevented some states from being sent correctly to the inspector when serializable values hold references to objects throwing on `toJSON` property access (like `obj.toJSON`). This property is accessed by the native algorithm before the value gets passed to the custom `serializer`. Because of a bug we couldn't correctly serialize such values even when a custom `serializer` was implemented that was meant to replace it in a custom way from within its parent's level. | ||
* [#3199](https://github.com/statelyai/xstate/pull/3199) [`f3d63147d`](https://github.com/statelyai/xstate/commit/f3d63147d36791344d55fa9c945af32daeefa2fa) Thanks [@Andarist](https://github.com/Andarist)! - Fixed an issue that caused sending the same event multiple times to the inspector for restarted services. | ||
- [#3076](https://github.com/statelyai/xstate/pull/3076) [`34f3d9be7`](https://github.com/statelyai/xstate/commit/34f3d9be74d2bd9db51b2db06c5a65d980aec9c4) Thanks [@SimeonC](https://github.com/SimeonC)! - Fixed an issue with "maximum call stack size exceeded" errors being thrown when registering a machine with a very deep object in its context despite using a serializer capable of replacing such an object. | ||
## 0.6.4 | ||
### Patch Changes | ||
- [#3144](https://github.com/statelyai/xstate/pull/3144) [`e08030faf`](https://github.com/statelyai/xstate/commit/e08030faf00e2bcb192040b6ba04178ecf057509) Thanks [@lecepin](https://github.com/lecepin)! - Added UMD build for this package that is available in the `dist` directory in the published package. | ||
* [#3144](https://github.com/statelyai/xstate/pull/3144) [`e08030faf`](https://github.com/statelyai/xstate/commit/e08030faf00e2bcb192040b6ba04178ecf057509) Thanks [@lecepin](https://github.com/lecepin)! - Added proper `peerDependency` on XState. It was incorrectly omitted from the `package.json` of this package. | ||
## 0.6.3 | ||
### Patch Changes | ||
- [#3089](https://github.com/statelyai/xstate/pull/3089) [`862697e29`](https://github.com/statelyai/xstate/commit/862697e2990934d46050580d7e09c749d09d8426) Thanks [@Andarist](https://github.com/Andarist)! - Fixed compatibility with Skypack by exporting some shared utilities from root entry of XState and consuming them directly in other packages (this avoids accessing those things using deep imports and thus it avoids creating those compatibility problems). | ||
## 0.6.2 | ||
### Patch Changes | ||
- [#2957](https://github.com/statelyai/xstate/pull/2957) [`8550ddda7`](https://github.com/statelyai/xstate/commit/8550ddda73e2ad291e19173d7fa8d13e3336fbb9) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The repository links have been updated from `github.com/davidkpiano` to `github.com/statelyai`. | ||
## 0.6.1 | ||
### Patch Changes | ||
- [#2907](https://github.com/statelyai/xstate/pull/2907) [`3a8eb6574`](https://github.com/statelyai/xstate/commit/3a8eb6574db51c3d02c900561be87a48fd9a973c) Thanks [@rossng](https://github.com/rossng)! - Fix crash when sending circular state objects (#2373). | ||
## 0.6.0 | ||
@@ -7,3 +43,3 @@ | ||
- [#2640](https://github.com/statelyai/xstate/pull/2640) [`c73dfd655`](https://github.com/statelyai/xstate/commit/c73dfd655525546e59f00d0be88b80ab71239427) Thanks [@davidkpiano](https://github.com/davidkpiano)! - A serializer can now be specified as an option for `inspect(...)` in the `.serialize` property. It should be a [replacer function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter): | ||
- [#2640](https://github.com/statelyai/xstate/pull/2640) [`c73dfd655`](https://github.com/statelyai/xstate/commit/c73dfd655525546e59f00d0be88b80ab71239427) Thanks [@davidkpiano](https://github.com/statelyai)! - A serializer can now be specified as an option for `inspect(...)` in the `.serialize` property. It should be a [replacer function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter): | ||
@@ -65,3 +101,3 @@ ```js | ||
- [`d9282107`](https://github.com/davidkpiano/xstate/commit/d9282107b931b867d9cd297ede71b55fe11eb74d) [#1800](https://github.com/davidkpiano/xstate/pull/1800) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Fixed a bug where services were not being registered by the inspect client, affecting the ability to send events to inspected services. | ||
- [`d9282107`](https://github.com/statelyai/xstate/commit/d9282107b931b867d9cd297ede71b55fe11eb74d) [#1800](https://github.com/statelyai/xstate/pull/1800) Thanks [@davidkpiano](https://github.com/statelyai)! - Fixed a bug where services were not being registered by the inspect client, affecting the ability to send events to inspected services. | ||
@@ -72,3 +108,3 @@ ## 0.4.0 | ||
- [`63ba888e`](https://github.com/davidkpiano/xstate/commit/63ba888e19bd2b72f9aad2c9cd36cde297e0ffe5) [#1770](https://github.com/davidkpiano/xstate/pull/1770) Thanks [@davidkpiano](https://github.com/davidkpiano)! - It is now easier for developers to create their own XState inspectors, and even inspect services offline. | ||
- [`63ba888e`](https://github.com/statelyai/xstate/commit/63ba888e19bd2b72f9aad2c9cd36cde297e0ffe5) [#1770](https://github.com/statelyai/xstate/pull/1770) Thanks [@davidkpiano](https://github.com/statelyai)! - It is now easier for developers to create their own XState inspectors, and even inspect services offline. | ||
@@ -136,3 +172,3 @@ A **receiver** is an actor that receives inspector events from a source, such as `"service.register"`, `"service.state"`, `"service.event"`, etc. This update includes two receivers: | ||
- [`a473205d`](https://github.com/davidkpiano/xstate/commit/a473205d214563033cd250094d2344113755bd8b) [#1699](https://github.com/davidkpiano/xstate/pull/1699) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `@xstate/inspect` tool now uses [`fast-safe-stringify`](https://www.npmjs.com/package/fast-safe-stringify) for internal JSON stringification of machines, states, and events when regular `JSON.stringify()` fails (e.g., due to circular structures). | ||
- [`a473205d`](https://github.com/statelyai/xstate/commit/a473205d214563033cd250094d2344113755bd8b) [#1699](https://github.com/statelyai/xstate/pull/1699) Thanks [@davidkpiano](https://github.com/statelyai)! - The `@xstate/inspect` tool now uses [`fast-safe-stringify`](https://www.npmjs.com/package/fast-safe-stringify) for internal JSON stringification of machines, states, and events when regular `JSON.stringify()` fails (e.g., due to circular structures). | ||
@@ -143,2 +179,2 @@ ## 0.2.0 | ||
- [`1725333a`](https://github.com/davidkpiano/xstate/commit/1725333a6edcc5c1e178228aa869c907d3907be5) [#1599](https://github.com/davidkpiano/xstate/pull/1599) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `@xstate/inspect` package is now built with Rollup which has fixed an issue with TypeScript compiler inserting references to `this` in the top-level scope of the output modules and thus making it harder for some tools (like Rollup) to re-bundle dist files as `this` in modules (as they are always in strict mode) is `undefined`. | ||
- [`1725333a`](https://github.com/statelyai/xstate/commit/1725333a6edcc5c1e178228aa869c907d3907be5) [#1599](https://github.com/statelyai/xstate/pull/1599) Thanks [@davidkpiano](https://github.com/statelyai)! - The `@xstate/inspect` package is now built with Rollup which has fixed an issue with TypeScript compiler inserting references to `this` in the top-level scope of the output modules and thus making it harder for some tools (like Rollup) to re-bundle dist files as `this` in modules (as they are always in strict mode) is `undefined`. |
@@ -27,2 +27,14 @@ /*! ***************************************************************************** | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function __values(o) { | ||
@@ -40,2 +52,2 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
export { __assign, __values }; | ||
export { __assign, __rest, __values }; |
@@ -1,3 +0,2 @@ | ||
import { Interpreter, EventObject } from 'xstate'; | ||
import { XStateDevInterface } from 'xstate/lib/devTools'; | ||
import { EventObject, Interpreter, XStateDevInterface } from 'xstate'; | ||
import type { Inspector, InspectorOptions, InspectReceiver, WebSocketReceiverOptions, WindowReceiverOptions } from './types'; | ||
@@ -7,3 +6,3 @@ export declare const serviceMap: Map<string, Interpreter<any, any, EventObject, { | ||
context: any; | ||
}>>; | ||
}, import("xstate").TypegenDisabled>>; | ||
export declare function createDevTools(): XStateDevInterface; | ||
@@ -10,0 +9,0 @@ export declare function inspect(options?: InspectorOptions): Inspector | undefined; |
import { __assign } from './_virtual/_tslib.js'; | ||
import { interpret } from 'xstate'; | ||
import { toSCXMLEvent, toEventObject, toObserver } from 'xstate/lib/utils'; | ||
import { interpret, toSCXMLEvent, toEventObject, toObserver, toActorRef } from 'xstate'; | ||
import { createInspectMachine } from './inspectMachine.js'; | ||
import { stringifyMachine, stringifyState } from './serialize.js'; | ||
import { getLazy, stringify, isReceiverEvent, parseReceiverEvent } from './utils.js'; | ||
import { stringifyMachine, stringifyState } from './serialize.js'; | ||
import { createInspectMachine } from './inspectMachine.js'; | ||
@@ -54,2 +53,3 @@ var serviceMap = new Map(); | ||
}; | ||
var patchedInterpreters = new Set(); | ||
function inspect(options) { | ||
@@ -110,14 +110,17 @@ var _a = getFinalOptions(options), iframe = _a.iframe, url = _a.url, devTools = _a.devTools; | ||
}); | ||
// monkey-patch service.send so that we know when an event was sent | ||
// to a service *before* it is processed, since other events might occur | ||
// while the sent one is being processed, which throws the order off | ||
var originalSend = service.send.bind(service); | ||
service.send = function inspectSend(event, payload) { | ||
inspectService.send({ | ||
type: 'service.event', | ||
event: stringifyWithSerializer(toSCXMLEvent(toEventObject(event, payload))), | ||
sessionId: service.sessionId | ||
}); | ||
return originalSend(event, payload); | ||
}; | ||
if (!patchedInterpreters.has(service)) { | ||
patchedInterpreters.add(service); | ||
// monkey-patch service.send so that we know when an event was sent | ||
// to a service *before* it is processed, since other events might occur | ||
// while the sent one is being processed, which throws the order off | ||
var originalSend_1 = service.send.bind(service); | ||
service.send = function inspectSend(event, payload) { | ||
inspectService.send({ | ||
type: 'service.event', | ||
event: stringifyWithSerializer(toSCXMLEvent(toEventObject(event, payload))), | ||
sessionId: service.sessionId | ||
}); | ||
return originalSend_1(event, payload); | ||
}; | ||
} | ||
service.subscribe(function (state) { | ||
@@ -185,3 +188,3 @@ // filter out synchronous notification from within `.start()` call | ||
ownWindow.addEventListener('message', handler); | ||
var actorRef = { | ||
var actorRef = toActorRef({ | ||
id: 'xstate.windowReceiver', | ||
@@ -210,3 +213,3 @@ send: function (event) { | ||
} | ||
}; | ||
}); | ||
actorRef.send({ | ||
@@ -222,3 +225,3 @@ type: 'xstate.inspecting' | ||
var latestEvent; | ||
var actorRef = { | ||
var actorRef = toActorRef({ | ||
id: 'xstate.webSocketReceiver', | ||
@@ -240,3 +243,3 @@ send: function (event) { | ||
} | ||
}; | ||
}); | ||
ws.onopen = function () { | ||
@@ -243,0 +246,0 @@ actorRef.send({ |
@@ -1,3 +0,2 @@ | ||
import { ActorRef } from 'xstate'; | ||
import { XStateDevInterface } from 'xstate/lib/devTools'; | ||
import { ActorRef, XStateDevInterface } from 'xstate'; | ||
import { ReceiverEvent, Replacer } from './types'; | ||
@@ -25,5 +24,3 @@ export declare type InspectMachineEvent = ReceiverEvent | { | ||
}; | ||
}, import("xstate").ActionObject<{ | ||
client?: Pick<ActorRef<any, any>, "send"> | undefined; | ||
}, InspectMachineEvent>>; | ||
}, import("xstate").BaseActionObject, import("xstate").ServiceMap, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, InspectMachineEvent, import("xstate").BaseActionObject, import("xstate").ServiceMap>>; | ||
//# sourceMappingURL=inspectMachine.d.ts.map |
@@ -1,6 +0,6 @@ | ||
import { State, StateMachine } from 'xstate'; | ||
import { AnyState, AnyStateMachine } from 'xstate'; | ||
import { Replacer } from './types'; | ||
export declare function selectivelyStringify<T extends object>(value: T, keys: Array<keyof T>, replacer?: Replacer): string; | ||
export declare function stringifyState(state: State<any, any>, replacer?: Replacer): string; | ||
export declare function stringifyMachine(machine: StateMachine<any, any, any>, replacer?: Replacer): string; | ||
export declare function stringifyState(state: AnyState, replacer?: Replacer): string; | ||
export declare function stringifyMachine(machine: AnyStateMachine, replacer?: Replacer): string; | ||
//# sourceMappingURL=serialize.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { __assign, __values } from './_virtual/_tslib.js'; | ||
import { __assign, __values, __rest } from './_virtual/_tslib.js'; | ||
import { stringify } from './utils.js'; | ||
@@ -24,8 +24,9 @@ | ||
function stringifyState(state, replacer) { | ||
return selectivelyStringify(state, ['context', 'event', '_event'], replacer); | ||
state.machine; state.configuration; state.history; var stateToStringify = __rest(state, ["machine", "configuration", "history"]); | ||
return selectivelyStringify(stateToStringify, ['context', 'event', '_event'], replacer); | ||
} | ||
function stringifyMachine(machine, replacer) { | ||
return selectivelyStringify(machine, ['context'], replacer); | ||
return selectivelyStringify(machine.definition, ['context'], replacer); | ||
} | ||
export { selectivelyStringify, stringifyMachine, stringifyState }; |
@@ -1,6 +0,6 @@ | ||
import type { ActorRef, Interpreter, SCXML, State, StateMachine } from 'xstate'; | ||
import { XStateDevInterface } from 'xstate/lib/devTools'; | ||
import type { ActorRef, AnyInterpreter, AnyState, AnyStateMachine, SCXML } from 'xstate'; | ||
import { XStateDevInterface } from 'xstate'; | ||
import { InspectMachineEvent } from './inspectMachine'; | ||
export declare type MaybeLazy<T> = T | (() => T); | ||
export declare type ServiceListener = (service: Interpreter<any>) => void; | ||
export declare type ServiceListener = (service: AnyInterpreter) => void; | ||
export declare type Replacer = (key: string, value: any) => any; | ||
@@ -13,3 +13,3 @@ export interface InspectorOptions { | ||
} | ||
export interface Inspector extends ActorRef<InspectMachineEvent, State<any, any, any>> { | ||
export interface Inspector extends ActorRef<InspectMachineEvent, AnyState> { | ||
/** | ||
@@ -55,4 +55,4 @@ * Disconnects the inspector. | ||
type: 'service.register'; | ||
machine: StateMachine<any, any, any>; | ||
state: State<any, any>; | ||
machine: AnyStateMachine; | ||
state: AnyState; | ||
id: string; | ||
@@ -67,3 +67,3 @@ sessionId: string; | ||
type: 'service.state'; | ||
state: State<any, any>; | ||
state: AnyState; | ||
sessionId: string; | ||
@@ -70,0 +70,0 @@ } | { |
@@ -1,2 +0,2 @@ | ||
import { State } from 'xstate'; | ||
import { AnyState } from 'xstate'; | ||
import { ParsedReceiverEvent, ReceiverEvent } from './types'; | ||
@@ -6,4 +6,4 @@ export declare function getLazy<T>(value: T): T extends () => infer R ? R : T; | ||
export declare function isReceiverEvent(event: any): event is ReceiverEvent; | ||
export declare function parseState(stateJSON: string): State<any, any>; | ||
export declare function parseState(stateJSON: string): AnyState; | ||
export declare function parseReceiverEvent(event: ReceiverEvent): ParsedReceiverEvent; | ||
//# sourceMappingURL=utils.d.ts.map |
import { __assign } from './_virtual/_tslib.js'; | ||
import safeStringify from 'fast-safe-stringify'; | ||
import { createMachine, State } from 'xstate'; | ||
import safeStringify from 'fast-safe-stringify'; | ||
@@ -5,0 +5,0 @@ function getLazy(value) { |
@@ -31,2 +31,14 @@ 'use strict'; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function __values(o) { | ||
@@ -44,2 +56,3 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
exports.__rest = __rest; | ||
exports.__values = __values; |
@@ -1,3 +0,2 @@ | ||
import { Interpreter, EventObject } from 'xstate'; | ||
import { XStateDevInterface } from 'xstate/lib/devTools'; | ||
import { EventObject, Interpreter, XStateDevInterface } from 'xstate'; | ||
import type { Inspector, InspectorOptions, InspectReceiver, WebSocketReceiverOptions, WindowReceiverOptions } from './types'; | ||
@@ -7,3 +6,3 @@ export declare const serviceMap: Map<string, Interpreter<any, any, EventObject, { | ||
context: any; | ||
}>>; | ||
}, import("xstate").TypegenDisabled>>; | ||
export declare function createDevTools(): XStateDevInterface; | ||
@@ -10,0 +9,0 @@ export declare function inspect(options?: InspectorOptions): Inspector | undefined; |
@@ -7,6 +7,5 @@ 'use strict'; | ||
var xstate = require('xstate'); | ||
var utils$1 = require('xstate/lib/utils'); | ||
var inspectMachine = require('./inspectMachine.js'); | ||
var serialize = require('./serialize.js'); | ||
var utils = require('./utils.js'); | ||
var serialize = require('./serialize.js'); | ||
var inspectMachine = require('./inspectMachine.js'); | ||
@@ -59,2 +58,3 @@ var serviceMap = new Map(); | ||
}; | ||
var patchedInterpreters = new Set(); | ||
function inspect(options) { | ||
@@ -115,14 +115,17 @@ var _a = getFinalOptions(options), iframe = _a.iframe, url = _a.url, devTools = _a.devTools; | ||
}); | ||
// monkey-patch service.send so that we know when an event was sent | ||
// to a service *before* it is processed, since other events might occur | ||
// while the sent one is being processed, which throws the order off | ||
var originalSend = service.send.bind(service); | ||
service.send = function inspectSend(event, payload) { | ||
inspectService.send({ | ||
type: 'service.event', | ||
event: stringifyWithSerializer(utils$1.toSCXMLEvent(utils$1.toEventObject(event, payload))), | ||
sessionId: service.sessionId | ||
}); | ||
return originalSend(event, payload); | ||
}; | ||
if (!patchedInterpreters.has(service)) { | ||
patchedInterpreters.add(service); | ||
// monkey-patch service.send so that we know when an event was sent | ||
// to a service *before* it is processed, since other events might occur | ||
// while the sent one is being processed, which throws the order off | ||
var originalSend_1 = service.send.bind(service); | ||
service.send = function inspectSend(event, payload) { | ||
inspectService.send({ | ||
type: 'service.event', | ||
event: stringifyWithSerializer(xstate.toSCXMLEvent(xstate.toEventObject(event, payload))), | ||
sessionId: service.sessionId | ||
}); | ||
return originalSend_1(event, payload); | ||
}; | ||
} | ||
service.subscribe(function (state) { | ||
@@ -162,3 +165,3 @@ // filter out synchronous notification from within `.start()` call | ||
subscribe: function (next, onError, onComplete) { | ||
var observer = utils$1.toObserver(next, onError, onComplete); | ||
var observer = xstate.toObserver(next, onError, onComplete); | ||
listeners.add(observer); | ||
@@ -191,3 +194,3 @@ observer.next(inspectService.state); | ||
ownWindow.addEventListener('message', handler); | ||
var actorRef = { | ||
var actorRef = xstate.toActorRef({ | ||
id: 'xstate.windowReceiver', | ||
@@ -201,3 +204,3 @@ send: function (event) { | ||
subscribe: function (next, onError, onComplete) { | ||
var observer = utils$1.toObserver(next, onError, onComplete); | ||
var observer = xstate.toObserver(next, onError, onComplete); | ||
observers.add(observer); | ||
@@ -217,3 +220,3 @@ return { | ||
} | ||
}; | ||
}); | ||
actorRef.send({ | ||
@@ -229,3 +232,3 @@ type: 'xstate.inspecting' | ||
var latestEvent; | ||
var actorRef = { | ||
var actorRef = xstate.toActorRef({ | ||
id: 'xstate.webSocketReceiver', | ||
@@ -236,3 +239,3 @@ send: function (event) { | ||
subscribe: function (next, onError, onComplete) { | ||
var observer = utils$1.toObserver(next, onError, onComplete); | ||
var observer = xstate.toObserver(next, onError, onComplete); | ||
observers.add(observer); | ||
@@ -248,3 +251,3 @@ return { | ||
} | ||
}; | ||
}); | ||
ws.onopen = function () { | ||
@@ -251,0 +254,0 @@ actorRef.send({ |
@@ -1,3 +0,2 @@ | ||
import { ActorRef } from 'xstate'; | ||
import { XStateDevInterface } from 'xstate/lib/devTools'; | ||
import { ActorRef, XStateDevInterface } from 'xstate'; | ||
import { ReceiverEvent, Replacer } from './types'; | ||
@@ -25,5 +24,3 @@ export declare type InspectMachineEvent = ReceiverEvent | { | ||
}; | ||
}, import("xstate").ActionObject<{ | ||
client?: Pick<ActorRef<any, any>, "send"> | undefined; | ||
}, InspectMachineEvent>>; | ||
}, import("xstate").BaseActionObject, import("xstate").ServiceMap, import("xstate").ResolveTypegenMeta<import("xstate").TypegenDisabled, InspectMachineEvent, import("xstate").BaseActionObject, import("xstate").ServiceMap>>; | ||
//# sourceMappingURL=inspectMachine.d.ts.map |
@@ -1,6 +0,6 @@ | ||
import { State, StateMachine } from 'xstate'; | ||
import { AnyState, AnyStateMachine } from 'xstate'; | ||
import { Replacer } from './types'; | ||
export declare function selectivelyStringify<T extends object>(value: T, keys: Array<keyof T>, replacer?: Replacer): string; | ||
export declare function stringifyState(state: State<any, any>, replacer?: Replacer): string; | ||
export declare function stringifyMachine(machine: StateMachine<any, any, any>, replacer?: Replacer): string; | ||
export declare function stringifyState(state: AnyState, replacer?: Replacer): string; | ||
export declare function stringifyMachine(machine: AnyStateMachine, replacer?: Replacer): string; | ||
//# sourceMappingURL=serialize.d.ts.map |
@@ -28,6 +28,7 @@ 'use strict'; | ||
function stringifyState(state, replacer) { | ||
return selectivelyStringify(state, ['context', 'event', '_event'], replacer); | ||
state.machine; state.configuration; state.history; var stateToStringify = _tslib.__rest(state, ["machine", "configuration", "history"]); | ||
return selectivelyStringify(stateToStringify, ['context', 'event', '_event'], replacer); | ||
} | ||
function stringifyMachine(machine, replacer) { | ||
return selectivelyStringify(machine, ['context'], replacer); | ||
return selectivelyStringify(machine.definition, ['context'], replacer); | ||
} | ||
@@ -34,0 +35,0 @@ |
@@ -7,5 +7,4 @@ 'use strict'; | ||
var xstate = require('xstate'); | ||
var utils$1 = require('xstate/lib/utils'); | ||
var inspectMachine = require('./inspectMachine.js'); | ||
var utils = require('./utils.js'); | ||
var inspectMachine = require('./inspectMachine.js'); | ||
@@ -42,3 +41,3 @@ var services = new Set(); | ||
var inspectService = xstate.interpret(inspectMachine.createInspectMachine(globalThis.__xstate__, options)).start(); | ||
var client = { | ||
var client = xstate.toActorRef({ | ||
id: '@@xstate/ws-client', | ||
@@ -56,3 +55,3 @@ send: function (event) { | ||
getSnapshot: function () { return undefined; } | ||
}; | ||
}); | ||
server.on('connection', function connection(wsClient) { | ||
@@ -87,3 +86,3 @@ wsClient.on('message', function incoming(data, isBinary) { | ||
type: 'service.event', | ||
event: utils.stringify(utils$1.toSCXMLEvent(utils$1.toEventObject(event, payload))), | ||
event: utils.stringify(xstate.toSCXMLEvent(xstate.toEventObject(event, payload))), | ||
sessionId: service.sessionId | ||
@@ -106,11 +105,4 @@ }); | ||
}); | ||
service.subscribe(function (state) { | ||
inspectService.send({ | ||
type: 'service.state', | ||
state: JSON.stringify(state), | ||
sessionId: service.sessionId | ||
}); | ||
}); | ||
}); | ||
var inspector = { | ||
var inspector = xstate.toActorRef({ | ||
id: '@@xstate/inspector', | ||
@@ -130,3 +122,3 @@ send: function (event) { | ||
getSnapshot: function () { return undefined; } | ||
}; | ||
}); | ||
server.on('close', function () { | ||
@@ -133,0 +125,0 @@ inspectService.stop(); |
@@ -1,6 +0,6 @@ | ||
import type { ActorRef, Interpreter, SCXML, State, StateMachine } from 'xstate'; | ||
import { XStateDevInterface } from 'xstate/lib/devTools'; | ||
import type { ActorRef, AnyInterpreter, AnyState, AnyStateMachine, SCXML } from 'xstate'; | ||
import { XStateDevInterface } from 'xstate'; | ||
import { InspectMachineEvent } from './inspectMachine'; | ||
export declare type MaybeLazy<T> = T | (() => T); | ||
export declare type ServiceListener = (service: Interpreter<any>) => void; | ||
export declare type ServiceListener = (service: AnyInterpreter) => void; | ||
export declare type Replacer = (key: string, value: any) => any; | ||
@@ -13,3 +13,3 @@ export interface InspectorOptions { | ||
} | ||
export interface Inspector extends ActorRef<InspectMachineEvent, State<any, any, any>> { | ||
export interface Inspector extends ActorRef<InspectMachineEvent, AnyState> { | ||
/** | ||
@@ -55,4 +55,4 @@ * Disconnects the inspector. | ||
type: 'service.register'; | ||
machine: StateMachine<any, any, any>; | ||
state: State<any, any>; | ||
machine: AnyStateMachine; | ||
state: AnyState; | ||
id: string; | ||
@@ -67,3 +67,3 @@ sessionId: string; | ||
type: 'service.state'; | ||
state: State<any, any>; | ||
state: AnyState; | ||
sessionId: string; | ||
@@ -70,0 +70,0 @@ } | { |
@@ -1,2 +0,2 @@ | ||
import { State } from 'xstate'; | ||
import { AnyState } from 'xstate'; | ||
import { ParsedReceiverEvent, ReceiverEvent } from './types'; | ||
@@ -6,4 +6,4 @@ export declare function getLazy<T>(value: T): T extends () => infer R ? R : T; | ||
export declare function isReceiverEvent(event: any): event is ReceiverEvent; | ||
export declare function parseState(stateJSON: string): State<any, any>; | ||
export declare function parseState(stateJSON: string): AnyState; | ||
export declare function parseReceiverEvent(event: ReceiverEvent): ParsedReceiverEvent; | ||
//# sourceMappingURL=utils.d.ts.map |
@@ -6,4 +6,4 @@ 'use strict'; | ||
var _tslib = require('./_virtual/_tslib.js'); | ||
var safeStringify = require('fast-safe-stringify'); | ||
var xstate = require('xstate'); | ||
var safeStringify = require('fast-safe-stringify'); | ||
@@ -22,3 +22,3 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
catch (e) { | ||
return safeStringify__default['default'](value, replacer); | ||
return safeStringify__default["default"](value, replacer); | ||
} | ||
@@ -25,0 +25,0 @@ } |
{ | ||
"name": "@xstate/inspect", | ||
"version": "0.6.0", | ||
"version": "0.6.5", | ||
"description": "XState inspection utilities", | ||
@@ -15,3 +15,3 @@ "keywords": [ | ||
"author": "David Khourshid <davidkpiano@gmail.com>", | ||
"homepage": "https://github.com/davidkpiano/xstate/tree/main/packages/xstate-inspect#readme", | ||
"homepage": "https://github.com/statelyai/xstate/tree/main/packages/xstate-inspect#readme", | ||
"license": "MIT", | ||
@@ -26,7 +26,8 @@ "main": "lib/index.js", | ||
"es/**/*.js", | ||
"es/**/*.d.ts" | ||
"es/**/*.d.ts", | ||
"dist/**/*.js" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://git@github.com/davidkpiano/xstate.git" | ||
"url": "git+ssh://git@github.com/statelyai/xstate.git" | ||
}, | ||
@@ -37,10 +38,14 @@ "scripts": { | ||
"build": "rollup -c", | ||
"prepublish": "npm run build" | ||
"prepare": "npm run build" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/davidkpiano/xstate/issues" | ||
"url": "https://github.com/statelyai/xstate/issues" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-node-resolve": "^11.0.1", | ||
"@types/ws": "^8.2.2", | ||
"rollup": "^2.35.1", | ||
"rollup": "^2.69.0", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^5.1.2", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
@@ -53,3 +58,4 @@ "typescript": "^4.5.2", | ||
"@types/ws": "^8.0.0", | ||
"ws": "^8.0.0" | ||
"ws": "^8.0.0", | ||
"xstate": "^4.31.0" | ||
}, | ||
@@ -62,4 +68,4 @@ "peerDependenciesMeta": { | ||
"dependencies": { | ||
"fast-safe-stringify": "^2.0.7" | ||
"fast-safe-stringify": "^2.1.1" | ||
} | ||
} |
@@ -28,2 +28,10 @@ # @xstate/inspect | ||
**Via CDN** | ||
```html | ||
<script src="https://unpkg.com/@xstate/inspect/dist/xstate-inspect.umd.min.js"></script> | ||
``` | ||
By using the global variable `XStateInspect` | ||
2. Import it at the beginning of your project, before any other code is called: | ||
@@ -49,2 +57,3 @@ | ||
const service = interpret(someMachine, { devTools: true }); | ||
service.start(); | ||
``` |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
77477
31
1411
58
4
10
2
+ Addedxstate@4.38.3(transitive)
Updatedfast-safe-stringify@^2.1.1