@statelyai/inspect
Advanced tools
Comparing version 0.2.5 to 0.3.0
# @statelyai/inspect | ||
## 0.3.0 | ||
### Minor Changes | ||
- [#24](https://github.com/statelyai/inspect/pull/24) [`9cfc0b3`](https://github.com/statelyai/inspect/commit/9cfc0b3d8f6703de46dd030fe271f2516e36d1d1) Thanks [@davidkpiano](https://github.com/davidkpiano)! - The `serialize` option will now pre-serialize the event using `superjson` before the custom serialization. | ||
## 0.2.5 | ||
@@ -4,0 +10,0 @@ |
@@ -88,3 +88,3 @@ import { InspectionEvent, Snapshot, AnyActorRef, AnyEventObject, Observer, Subscribable } from 'xstate'; | ||
filter?: (event: StatelyInspectionEvent) => boolean; | ||
serialize?: (event: StatelyInspectionEvent) => StatelyInspectionEvent; | ||
serialize?: (event: StatelyInspectionEvent, originalEvent: StatelyInspectionEvent) => StatelyInspectionEvent; | ||
/** | ||
@@ -91,0 +91,0 @@ * Whether to automatically start the inspector. |
@@ -69,3 +69,3 @@ "use strict"; | ||
name: "@statelyai/inspect", | ||
version: "0.2.5", | ||
version: "0.3.0", | ||
description: "Inspection utilities for state, actors, workflows, and state machines.", | ||
@@ -115,2 +115,3 @@ main: "dist/index.js", | ||
var import_safe_stable_stringify = __toESM(require("safe-stable-stringify")); | ||
var import_superjson = require("superjson"); | ||
function getRoot(actorRef) { | ||
@@ -127,2 +128,7 @@ let marker = actorRef; | ||
} | ||
var defaultInspectorOptions = { | ||
filter: () => true, | ||
serialize: (event) => (0, import_superjson.serialize)(event).json, | ||
autoStart: true | ||
}; | ||
function createInspector(adapter, options) { | ||
@@ -133,3 +139,4 @@ function sendAdapter(event) { | ||
} | ||
const serializedEvent = options?.serialize?.(event) ?? event; | ||
const preSerializedEvent = defaultInspectorOptions.serialize(event, event); | ||
const serializedEvent = options?.serialize?.(preSerializedEvent, event) ?? preSerializedEvent; | ||
adapter.send(serializedEvent); | ||
@@ -376,3 +383,10 @@ } | ||
this.deferredEvents.forEach((event2) => { | ||
const serializedEvent = this.options.serialize(event2); | ||
const preSerializedEvent = defaultInspectorOptions.serialize( | ||
event2, | ||
event2 | ||
); | ||
const serializedEvent = this.options.serialize( | ||
preSerializedEvent, | ||
event2 | ||
); | ||
this.targetWindow?.postMessage(serializedEvent, "*"); | ||
@@ -395,3 +409,7 @@ }); | ||
} else if (this.status === "connected") { | ||
const serializedEvent = this.options.serialize(event); | ||
const preSerializedEvent = defaultInspectorOptions.serialize( | ||
event, | ||
event | ||
); | ||
const serializedEvent = this.options.serialize(preSerializedEvent, event); | ||
this.targetWindow?.postMessage(serializedEvent, "*"); | ||
@@ -405,3 +423,3 @@ } | ||
var import_partysocket = __toESM(require("partysocket")); | ||
var import_superjson = require("superjson"); | ||
var import_superjson2 = require("superjson"); | ||
var import_uuid = require("uuid"); | ||
@@ -434,3 +452,3 @@ var isDevMode = false; | ||
const skyEvent = apiKey ? { apiKey, ...event } : event; | ||
socket.send((0, import_superjson.stringify)(skyEvent)); | ||
socket.send((0, import_superjson2.stringify)(skyEvent)); | ||
} | ||
@@ -444,3 +462,3 @@ }); | ||
const skyEvent = apiKey ? { apiKey, ...event } : event; | ||
socket.send((0, import_superjson.stringify)(skyEvent)); | ||
socket.send((0, import_superjson2.stringify)(skyEvent)); | ||
} | ||
@@ -476,3 +494,10 @@ }); | ||
this.deferredEvents.forEach((inspectionEvent) => { | ||
const serializedEvent = this.options.serialize(inspectionEvent); | ||
const preSerializedEvent = defaultInspectorOptions.serialize( | ||
inspectionEvent, | ||
inspectionEvent | ||
); | ||
const serializedEvent = this.options.serialize( | ||
preSerializedEvent, | ||
inspectionEvent | ||
); | ||
this.ws.send((0, import_safe_stable_stringify2.default)(serializedEvent)); | ||
@@ -479,0 +504,0 @@ }); |
@@ -14,3 +14,3 @@ { | ||
"name": "@statelyai/inspect", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"description": "Inspection utilities for state, actors, workflows, and state machines.", | ||
@@ -32,6 +32,2 @@ "main": "dist/index.js", | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"packageManager": "pnpm@8.11.0", | ||
"scripts": { | ||
@@ -41,2 +37,3 @@ "build": "tsup src/index.ts --dts", | ||
"test": "vitest", | ||
"prepublishOnly": "tsup src/index.ts --dts", | ||
"changeset": "changeset", | ||
@@ -46,3 +43,7 @@ "release": "changeset publish", | ||
"dev": "yarn build && ./scripts/dev.sh" | ||
} | ||
} | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"packageManager": "pnpm@8.11.0" | ||
} |
import safeStringify from 'fast-safe-stringify'; | ||
import { AnyEventObject, Observer, Subscribable, toObserver } from 'xstate'; | ||
import { InspectorOptions, createInspector } from './createInspector'; | ||
import { | ||
InspectorOptions, | ||
createInspector, | ||
defaultInspectorOptions, | ||
} from './createInspector'; | ||
import { Adapter, Inspector, StatelyInspectionEvent } from './types'; | ||
@@ -168,3 +172,10 @@ import { UselessAdapter } from './useless'; | ||
this.deferredEvents.forEach((event) => { | ||
const serializedEvent = this.options.serialize(event); | ||
const preSerializedEvent = defaultInspectorOptions.serialize( | ||
event, | ||
event | ||
); | ||
const serializedEvent = this.options.serialize( | ||
preSerializedEvent, | ||
event | ||
); | ||
this.targetWindow?.postMessage(serializedEvent, '*'); | ||
@@ -188,3 +199,7 @@ }); | ||
} else if (this.status === 'connected') { | ||
const serializedEvent = this.options.serialize(event); | ||
const preSerializedEvent = defaultInspectorOptions.serialize( | ||
event, | ||
event | ||
); | ||
const serializedEvent = this.options.serialize(preSerializedEvent, event); | ||
this.targetWindow?.postMessage(serializedEvent, '*'); | ||
@@ -191,0 +206,0 @@ } |
@@ -64,3 +64,3 @@ import { expect, test } from 'vitest'; | ||
"event": { | ||
"input": undefined, | ||
"input": null, | ||
"type": "xstate.init", | ||
@@ -67,0 +67,0 @@ }, |
@@ -14,2 +14,3 @@ import { | ||
import safeStringify from 'safe-stable-stringify'; | ||
import { serialize } from 'superjson'; | ||
@@ -37,3 +38,6 @@ function getRoot(actorRef: AnyActorRef) { | ||
filter?: (event: StatelyInspectionEvent) => boolean; | ||
serialize?: (event: StatelyInspectionEvent) => StatelyInspectionEvent; | ||
serialize?: ( | ||
event: StatelyInspectionEvent, | ||
originalEvent: StatelyInspectionEvent | ||
) => StatelyInspectionEvent; | ||
/** | ||
@@ -49,3 +53,4 @@ * Whether to automatically start the inspector. | ||
filter: () => true, | ||
serialize: (event) => event, | ||
serialize: (event) => | ||
serialize(event).json as unknown as StatelyInspectionEvent, | ||
autoStart: true, | ||
@@ -63,6 +68,7 @@ }; | ||
} | ||
const serializedEvent = options?.serialize?.(event) ?? event; | ||
// idleCallback(() => { | ||
const preSerializedEvent = defaultInspectorOptions.serialize(event, event); | ||
const serializedEvent = | ||
options?.serialize?.(preSerializedEvent, event) ?? preSerializedEvent; | ||
adapter.send(serializedEvent); | ||
// }) | ||
} | ||
@@ -69,0 +75,0 @@ const inspector: Inspector<TAdapter> = { |
@@ -1,2 +0,6 @@ | ||
import { InspectorOptions, createInspector } from './createInspector'; | ||
import { | ||
InspectorOptions, | ||
createInspector, | ||
defaultInspectorOptions, | ||
} from './createInspector'; | ||
import { Adapter, StatelyInspectionEvent } from './types'; | ||
@@ -35,3 +39,10 @@ import WebSocket from 'isomorphic-ws'; | ||
this.deferredEvents.forEach((inspectionEvent) => { | ||
const serializedEvent = this.options.serialize(inspectionEvent); | ||
const preSerializedEvent = defaultInspectorOptions.serialize( | ||
inspectionEvent, | ||
inspectionEvent | ||
); | ||
const serializedEvent = this.options.serialize( | ||
preSerializedEvent, | ||
inspectionEvent | ||
); | ||
this.ws.send(safeStringify(serializedEvent)); | ||
@@ -38,0 +49,0 @@ }); |
76819
1912