@statelyai/sdk 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/dist/{graphToXStateTS-DOaLOySy.mjs → graphToXStateTS-DV62vO_d.mjs} +4 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{inspect-BLlM3qKf.d.mts → inspect-CZ8iLJR7.d.mts} +8 -10
- package/dist/inspect.d.mts +1 -1
- package/dist/inspect.mjs +50 -34
- package/dist/sync.mjs +23 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,10 +85,11 @@ Stream live actor-system state to the Stately inspector over WebSockets, with su
|
|
|
85
85
|
import { createActor } from 'xstate';
|
|
86
86
|
import { createStatelyInspector } from '@statelyai/sdk';
|
|
87
87
|
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
const actor = createActor(machine);
|
|
89
|
+
const inspector = createStatelyInspector({ autoOpen: true });
|
|
90
|
+
|
|
91
|
+
inspector.inspect(actor);
|
|
92
|
+
actor.start();
|
|
92
93
|
```
|
|
93
94
|
|
|
94
95
|
### CLI and sync
|
|
@@ -4668,6 +4668,7 @@ function deepSimplify(config) {
|
|
|
4668
4668
|
return config;
|
|
4669
4669
|
}
|
|
4670
4670
|
function buildMeta(meta, color) {
|
|
4671
|
+
if (isCodeExpression(meta)) return meta;
|
|
4671
4672
|
const result = {};
|
|
4672
4673
|
if (meta) {
|
|
4673
4674
|
for (const [k, v] of Object.entries(meta)) if (v !== void 0 && v !== null) result[k] = v;
|
|
@@ -4675,6 +4676,9 @@ function buildMeta(meta, color) {
|
|
|
4675
4676
|
if (color) result["@statelyai.color"] = color;
|
|
4676
4677
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
4677
4678
|
}
|
|
4679
|
+
function isCodeExpression(value) {
|
|
4680
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value) && value["@type"] === "code" && typeof value.expr === "string");
|
|
4681
|
+
}
|
|
4678
4682
|
/** Format event param — supports { type: string } (new) and plain string (legacy) */
|
|
4679
4683
|
function formatEventParam(event) {
|
|
4680
4684
|
if (event && typeof event === "object" && "type" in event) return formatInlineObject(event);
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import { CommentsConfig, EmbedEventHandler, EmbedEventMap, EmbedEventName, Embed
|
|
|
3
3
|
import { AssetUploadAdapter, AssetUploadContext, AssetUploadRequest, CreateS3AssetUploadAdapterOptions, CreateSupabaseAssetUploadAdapterOptions, S3UploadTarget, SupabaseStorageClient, createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
|
|
4
4
|
import { AssetConfig, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.mjs";
|
|
5
5
|
import { C as EventTypeData, E as JSONSchema7, S as DigraphNodeConfig, T as CodeGenGraph, _ as studioMachineConverter, a as StatelyGraphData, b as DigraphConfig, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, o as StatelyGuard, r as StatelyEdgeData, t as StatelyAction, v as toStudioMachine, w as StateNodeJSONData, x as DigraphEdgeConfig, y as DigraphAction } from "./graph-GeuH-mFK.mjs";
|
|
6
|
-
import { a as ManualActorOptions, c as createPostMessageTransport, i as InspectorEvents, l as createWebSocketTransport, n as CreateInspectorOptions, o as createStatelyInspector, r as Inspector, s as Transport, t as AdoptedActor } from "./inspect-
|
|
6
|
+
import { a as ManualActorOptions, c as createPostMessageTransport, i as InspectorEvents, l as createWebSocketTransport, n as CreateInspectorOptions, o as createStatelyInspector, r as Inspector, s as Transport, t as AdoptedActor } from "./inspect-CZ8iLJR7.mjs";
|
|
7
7
|
import { ConnectedRepo, CreateMachineFromDefinitionInput, CreateMachineFromTemplateInput, CreateMachineInput, CreateMachineTemplate, CreateProjectInput, EnsureProjectInput, ExtractMachinesResponse, ExtractedMachine, GetMachineOptions, ProjectData, ProjectMachine, ProjectVisibility, RepoType, StudioApiError, StudioClient, StudioClientOptions, StudioMachineRecord, UpdateMachineInput, VerifyApiKeyResponse, XStateVersion, createStatelyClient } from "./studio.mjs";
|
|
8
8
|
import { PlanSyncOptions, PullSyncResult, PushLocalMachineLinksResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary } from "./sync.mjs";
|
|
9
9
|
import { ActionLocation, GraphPatch } from "./patchTypes.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./
|
|
|
4
4
|
import { createStatelyInspector } from "./inspect.mjs";
|
|
5
5
|
import { StudioApiError, createStatelyClient } from "./studio.mjs";
|
|
6
6
|
import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
|
|
7
|
-
import { S as upsertStatelyPragma, a as graphToMachineConfig, b as findStatelyPragmaAttachments, c as serializeJS, i as jsonSchemaToTSType, n as contextSchemaToTSType, o as RawCode, r as eventsSchemaToTSType, s as raw, t as graphToXStateTS, x as getStatelyPragma } from "./graphToXStateTS-
|
|
7
|
+
import { S as upsertStatelyPragma, a as graphToMachineConfig, b as findStatelyPragmaAttachments, c as serializeJS, i as jsonSchemaToTSType, n as contextSchemaToTSType, o as RawCode, r as eventsSchemaToTSType, s as raw, t as graphToXStateTS, x as getStatelyPragma } from "./graphToXStateTS-DV62vO_d.mjs";
|
|
8
8
|
import { fromStudioMachine, studioMachineConverter, toStudioMachine } from "./graph.mjs";
|
|
9
9
|
|
|
10
10
|
export { RawCode, StatelyApiError, StudioApiError, contextSchemaToTSType, createPostMessageTransport, createS3AssetUploadAdapter, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createSupabaseAssetUploadAdapter, createWebSocketTransport, eventsSchemaToTSType, findStatelyPragmaAttachments, fromStudioMachine, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
|
|
@@ -120,19 +120,13 @@ interface ManualActorOptions {
|
|
|
120
120
|
systemId?: string;
|
|
121
121
|
}
|
|
122
122
|
interface CreateInspectorOptions {
|
|
123
|
-
/**
|
|
124
|
-
* Root xstate actor to adopt. The inspector walks its `system`.
|
|
125
|
-
* Omit this for manual-only mode where you call `.actor()` / `.snapshot()`.
|
|
126
|
-
*/
|
|
127
|
-
actor?: any;
|
|
128
123
|
/** WebSocket URL of the devtools server. Default: `'ws://localhost:4242'`. */
|
|
129
124
|
url?: string;
|
|
130
125
|
/** Auto-open browser to visualizer. Default: `true`. */
|
|
131
126
|
autoOpen?: boolean;
|
|
132
127
|
/**
|
|
133
|
-
* Relay session id. Defaults to
|
|
134
|
-
*
|
|
135
|
-
* iframe connects with.
|
|
128
|
+
* Relay session id. Defaults to a random id. This is the `?session=<id>`
|
|
129
|
+
* value the viz iframe connects with.
|
|
136
130
|
*/
|
|
137
131
|
sessionId?: string;
|
|
138
132
|
/** Display name for this system in the visualizer. */
|
|
@@ -148,7 +142,7 @@ interface CreateInspectorOptions {
|
|
|
148
142
|
* `actor.logic.config`. Return `null` for non-machine actors.
|
|
149
143
|
*/
|
|
150
144
|
extractMachineConfig?: (actor: any) => unknown;
|
|
151
|
-
/** Selected actor id to focus on first. Defaults to the root
|
|
145
|
+
/** Selected actor id to focus on first. Defaults to the first inspected root. */
|
|
152
146
|
selectedActorId?: string;
|
|
153
147
|
/** Panel layout forwarded into the system init message. */
|
|
154
148
|
panels?: {
|
|
@@ -171,6 +165,10 @@ interface Inspector {
|
|
|
171
165
|
readonly actors: ReadonlyMap<string, AdoptedActor>;
|
|
172
166
|
/** The relay sessionId this inspector registered under. */
|
|
173
167
|
readonly sessionId: string;
|
|
168
|
+
/** Adopt an xstate actor system. Existing actors are backfilled immediately. */
|
|
169
|
+
inspect(actor: any): {
|
|
170
|
+
unsubscribe(): void;
|
|
171
|
+
};
|
|
174
172
|
/** Subscribe to lifecycle / error events. Returns an unsubscribe function. */
|
|
175
173
|
on<E extends EventName>(event: E, handler: Handler<E>): () => void;
|
|
176
174
|
off<E extends EventName>(event: E, handler: Handler<E>): void;
|
|
@@ -201,6 +199,6 @@ interface Inspector {
|
|
|
201
199
|
/** Tear down the WebSocket + xstate subscription. */
|
|
202
200
|
destroy(): void;
|
|
203
201
|
}
|
|
204
|
-
declare function createStatelyInspector(options
|
|
202
|
+
declare function createStatelyInspector(options?: CreateInspectorOptions): Inspector;
|
|
205
203
|
//#endregion
|
|
206
204
|
export { ManualActorOptions as a, createPostMessageTransport as c, InspectorEvents as i, createWebSocketTransport as l, CreateInspectorOptions as n, createStatelyInspector as o, Inspector as r, Transport as s, AdoptedActor as t };
|
package/dist/inspect.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap } from "./protocol.mjs";
|
|
2
|
-
import { a as ManualActorOptions, i as InspectorEvents, n as CreateInspectorOptions, o as createStatelyInspector, r as Inspector, s as Transport, t as AdoptedActor } from "./inspect-
|
|
2
|
+
import { a as ManualActorOptions, i as InspectorEvents, n as CreateInspectorOptions, o as createStatelyInspector, r as Inspector, s as Transport, t as AdoptedActor } from "./inspect-CZ8iLJR7.mjs";
|
|
3
3
|
export { AdoptedActor, CreateInspectorOptions, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, Inspector, InspectorEvents, ManualActorOptions, Transport, createStatelyInspector };
|
package/dist/inspect.mjs
CHANGED
|
@@ -10,12 +10,10 @@ let nextManualId = 0;
|
|
|
10
10
|
function generateSessionId() {
|
|
11
11
|
return `manual-${Date.now()}-${nextManualId++}`;
|
|
12
12
|
}
|
|
13
|
-
function createStatelyInspector(options) {
|
|
14
|
-
const { url = "ws://localhost:4242", autoOpen = true,
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const sessionId = options.sessionId ?? rootActorId;
|
|
18
|
-
const displayName = name ?? (root ? `system:${root.id}` : "system:manual");
|
|
13
|
+
function createStatelyInspector(options = {}) {
|
|
14
|
+
const { url = "ws://localhost:4242", autoOpen = true, name, serializeSnapshot = defaultSerializeSnapshot, extractMachineConfig = defaultExtractMachineConfig, selectedActorId, panels, theme, readOnly, depth, transport: injectedTransport } = options;
|
|
15
|
+
const sessionId = options.sessionId ?? generateSessionId();
|
|
16
|
+
const displayName = name ?? "system:manual";
|
|
19
17
|
let destroyed = false;
|
|
20
18
|
let initSent = false;
|
|
21
19
|
const pendingMessages = [];
|
|
@@ -92,7 +90,7 @@ function createStatelyInspector(options) {
|
|
|
92
90
|
return null;
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
|
-
function toEntry(actorRef) {
|
|
93
|
+
function toEntry(actorRef, rootActorId) {
|
|
96
94
|
return {
|
|
97
95
|
actorId: actorRef.sessionId,
|
|
98
96
|
parentActorId: actorRef._parent?.sessionId ?? null,
|
|
@@ -116,22 +114,23 @@ function createStatelyInspector(options) {
|
|
|
116
114
|
* Walk the actor tree and populate the local `actors` map. Idempotent —
|
|
117
115
|
* existing entries stay in place but have their snapshot refreshed.
|
|
118
116
|
*/
|
|
119
|
-
function backfillActorTree(actorRef) {
|
|
117
|
+
function backfillActorTree(actorRef, rootActorId) {
|
|
120
118
|
const existing = actors.get(actorRef.sessionId);
|
|
121
|
-
const entry = existing ?? toEntry(actorRef);
|
|
119
|
+
const entry = existing ?? toEntry(actorRef, rootActorId);
|
|
122
120
|
if (existing) existing.snapshot = snapshotValue(actorRef);
|
|
123
121
|
else actors.set(entry.actorId, entry);
|
|
124
122
|
emitRegisterOnce(entry);
|
|
125
123
|
const children = actorRef.getSnapshot()?.children ?? {};
|
|
126
|
-
for (const child of Object.values(children)) if (child) backfillActorTree(child);
|
|
124
|
+
for (const child of Object.values(children)) if (child) backfillActorTree(child, rootActorId);
|
|
127
125
|
}
|
|
126
|
+
const inspectedRoots = /* @__PURE__ */ new Map();
|
|
128
127
|
function sendInit() {
|
|
129
|
-
|
|
128
|
+
for (const [rootActorId, { actor }] of inspectedRoots) backfillActorTree(actor, rootActorId);
|
|
130
129
|
send({
|
|
131
130
|
type: "@statelyai.system.init",
|
|
132
131
|
mode: "inspecting",
|
|
133
132
|
actors: Array.from(actors.values()).map(toSystemEntry),
|
|
134
|
-
selectedActorId: selectedActorId ??
|
|
133
|
+
selectedActorId: selectedActorId ?? inspectedRoots.keys().next().value ?? sessionId,
|
|
135
134
|
...theme && { theme },
|
|
136
135
|
...readOnly !== void 0 && { readOnly },
|
|
137
136
|
...depth !== void 0 && { depth },
|
|
@@ -141,9 +140,9 @@ function createStatelyInspector(options) {
|
|
|
141
140
|
});
|
|
142
141
|
initSent = true;
|
|
143
142
|
}
|
|
144
|
-
function handleActor(actorRef) {
|
|
143
|
+
function handleActor(actorRef, rootActorId) {
|
|
145
144
|
if (actors.has(actorRef.sessionId)) return;
|
|
146
|
-
const entry = toEntry(actorRef);
|
|
145
|
+
const entry = toEntry(actorRef, rootActorId);
|
|
147
146
|
actors.set(entry.actorId, entry);
|
|
148
147
|
if (!initSent) return;
|
|
149
148
|
send({
|
|
@@ -156,8 +155,8 @@ function createStatelyInspector(options) {
|
|
|
156
155
|
});
|
|
157
156
|
emitRegisterOnce(entry);
|
|
158
157
|
}
|
|
159
|
-
function handleSnapshot(actorRef, snapshot, triggeringEvent) {
|
|
160
|
-
if (!actors.has(actorRef.sessionId)) handleActor(actorRef);
|
|
158
|
+
function handleSnapshot(actorRef, snapshot, triggeringEvent, rootActorId) {
|
|
159
|
+
if (!actors.has(actorRef.sessionId)) handleActor(actorRef, rootActorId);
|
|
161
160
|
const entry = actors.get(actorRef.sessionId);
|
|
162
161
|
if (!entry) return;
|
|
163
162
|
const serialized = serializeSnapshot(snapshot);
|
|
@@ -183,28 +182,43 @@ function createStatelyInspector(options) {
|
|
|
183
182
|
emitLocal("stopped", { actorId: entry.actorId });
|
|
184
183
|
}
|
|
185
184
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
185
|
+
function inspectActor(actor) {
|
|
186
|
+
const root = actor;
|
|
187
|
+
const rootActorId = root.sessionId;
|
|
188
|
+
const existing = inspectedRoots.get(rootActorId);
|
|
189
|
+
if (existing) return existing.subscription;
|
|
190
|
+
const subscription = root.system.inspect((inspectionEvent) => {
|
|
191
|
+
if (destroyed) return;
|
|
192
|
+
switch (inspectionEvent.type) {
|
|
193
|
+
case "@xstate.actor":
|
|
194
|
+
handleActor(inspectionEvent.actorRef, rootActorId);
|
|
195
|
+
break;
|
|
196
|
+
case "@xstate.event":
|
|
197
|
+
if (inspectionEvent.sourceRef) pendingEventSource.set(inspectionEvent.actorRef.sessionId, inspectionEvent.sourceRef.sessionId);
|
|
198
|
+
break;
|
|
199
|
+
case "@xstate.snapshot":
|
|
200
|
+
handleSnapshot(inspectionEvent.actorRef, inspectionEvent.snapshot, inspectionEvent.event, rootActorId);
|
|
201
|
+
break;
|
|
202
|
+
default: break;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
inspectedRoots.set(rootActorId, {
|
|
206
|
+
actor: root,
|
|
207
|
+
subscription
|
|
208
|
+
});
|
|
209
|
+
backfillActorTree(root, rootActorId);
|
|
210
|
+
if (initSent) sendInit();
|
|
211
|
+
return { unsubscribe() {
|
|
212
|
+
subscription.unsubscribe();
|
|
213
|
+
inspectedRoots.delete(rootActorId);
|
|
214
|
+
} };
|
|
215
|
+
}
|
|
202
216
|
function manualRegister(id, opts) {
|
|
203
217
|
if (actors.has(id)) return;
|
|
204
218
|
const entry = {
|
|
205
219
|
actorId: id,
|
|
206
220
|
parentActorId: opts?.parent ?? null,
|
|
207
|
-
rootId:
|
|
221
|
+
rootId: sessionId,
|
|
208
222
|
id,
|
|
209
223
|
systemId: opts?.systemId,
|
|
210
224
|
snapshot: opts?.snapshot ?? null,
|
|
@@ -252,6 +266,7 @@ function createStatelyInspector(options) {
|
|
|
252
266
|
get sessionId() {
|
|
253
267
|
return sessionId;
|
|
254
268
|
},
|
|
269
|
+
inspect: inspectActor,
|
|
255
270
|
on(event, handler) {
|
|
256
271
|
if (!localListeners[event]) localListeners[event] = /* @__PURE__ */ new Set();
|
|
257
272
|
localListeners[event].add(handler);
|
|
@@ -273,12 +288,13 @@ function createStatelyInspector(options) {
|
|
|
273
288
|
if (destroyed) return;
|
|
274
289
|
destroyed = true;
|
|
275
290
|
try {
|
|
276
|
-
subscription
|
|
291
|
+
for (const { subscription } of inspectedRoots.values()) subscription.unsubscribe();
|
|
277
292
|
} catch {}
|
|
278
293
|
if (ownsTransport) transport.destroy();
|
|
279
294
|
exportManager.clear("Inspector destroyed");
|
|
280
295
|
events.clear();
|
|
281
296
|
actors.clear();
|
|
297
|
+
inspectedRoots.clear();
|
|
282
298
|
pendingMessages.length = 0;
|
|
283
299
|
for (const set of Object.values(localListeners)) set?.clear();
|
|
284
300
|
}
|
package/dist/sync.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createStatelyClient } from "./studio.mjs";
|
|
2
|
-
import { S as upsertStatelyPragma, _ as string, b as findStatelyPragmaAttachments, d as boolean, f as discriminatedUnion, g as record, h as object, l as _enum, m as number, p as literal, t as graphToXStateTS, u as array, v as union, x as getStatelyPragma, y as unknown } from "./graphToXStateTS-
|
|
2
|
+
import { S as upsertStatelyPragma, _ as string, b as findStatelyPragmaAttachments, d as boolean, f as discriminatedUnion, g as record, h as object, l as _enum, m as number, p as literal, t as graphToXStateTS, u as array, v as union, x as getStatelyPragma, y as unknown } from "./graphToXStateTS-DV62vO_d.mjs";
|
|
3
3
|
import { fromStudioMachine, toStudioMachine } from "./graph.mjs";
|
|
4
4
|
import * as ts$1 from "typescript";
|
|
5
5
|
import ts from "typescript";
|
|
@@ -839,6 +839,7 @@ function deepSimplify(config) {
|
|
|
839
839
|
return config;
|
|
840
840
|
}
|
|
841
841
|
function buildMeta(meta, color) {
|
|
842
|
+
if (isCodeExpression(meta)) return meta;
|
|
842
843
|
const result = {};
|
|
843
844
|
if (meta) {
|
|
844
845
|
for (const [k, v] of Object.entries(meta)) if (v !== void 0 && v !== null) result[k] = v;
|
|
@@ -846,6 +847,9 @@ function buildMeta(meta, color) {
|
|
|
846
847
|
if (color) result["@statelyai.color"] = color;
|
|
847
848
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
848
849
|
}
|
|
850
|
+
function isCodeExpression(value) {
|
|
851
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value) && value["@type"] === "code" && typeof value.expr === "string");
|
|
852
|
+
}
|
|
849
853
|
/** Format event param — supports { type: string } (new) and plain string (legacy) */
|
|
850
854
|
function formatEventParam(event) {
|
|
851
855
|
if (event && typeof event === "object" && "type" in event) return formatInlineObject(event);
|
|
@@ -1003,7 +1007,7 @@ function actionCodeExpression(expr, source) {
|
|
|
1003
1007
|
}]
|
|
1004
1008
|
};
|
|
1005
1009
|
}
|
|
1006
|
-
function inlineCodeExpression(expr) {
|
|
1010
|
+
function inlineCodeExpression$1(expr) {
|
|
1007
1011
|
return {
|
|
1008
1012
|
"@type": "code",
|
|
1009
1013
|
lang: "ts",
|
|
@@ -1021,7 +1025,7 @@ function serializeGuard(guard, asTypeRef) {
|
|
|
1021
1025
|
type: guard.type,
|
|
1022
1026
|
params: guard.params
|
|
1023
1027
|
} : { type: guard.type };
|
|
1024
|
-
return guard.code ? inlineCodeExpression(guard.code) : guard;
|
|
1028
|
+
return guard.code ? inlineCodeExpression$1(guard.code) : guard;
|
|
1025
1029
|
}
|
|
1026
1030
|
/**
|
|
1027
1031
|
* Converts a built-in xstate ActionItem to a code expression directive,
|
|
@@ -1034,7 +1038,7 @@ function serializeActionItem(action) {
|
|
|
1034
1038
|
const builtInAction = XSTATE_BUILT_IN_ACTIONS[type];
|
|
1035
1039
|
return actionCodeExpression(emitBuiltInAction(type, params), builtInAction);
|
|
1036
1040
|
}
|
|
1037
|
-
if (exprCode) return inlineCodeExpression(exprCode);
|
|
1041
|
+
if (exprCode) return inlineCodeExpression$1(exprCode);
|
|
1038
1042
|
if (!params || Object.keys(params).length === 0) return { type };
|
|
1039
1043
|
return {
|
|
1040
1044
|
type,
|
|
@@ -1633,6 +1637,10 @@ function propertyContext(parent, key) {
|
|
|
1633
1637
|
v6: parent.v6,
|
|
1634
1638
|
actionValue: true
|
|
1635
1639
|
};
|
|
1640
|
+
if (key === "meta") return {
|
|
1641
|
+
v6: parent.v6,
|
|
1642
|
+
metaValue: true
|
|
1643
|
+
};
|
|
1636
1644
|
if (parent.transitionValue && key === "to") return {
|
|
1637
1645
|
v6: parent.v6,
|
|
1638
1646
|
transitionValue: true
|
|
@@ -1943,6 +1951,13 @@ function inlineAction(fn) {
|
|
|
1943
1951
|
}
|
|
1944
1952
|
};
|
|
1945
1953
|
}
|
|
1954
|
+
function inlineCodeExpression(expr) {
|
|
1955
|
+
return {
|
|
1956
|
+
"@type": "code",
|
|
1957
|
+
lang: "ts",
|
|
1958
|
+
expr
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1946
1961
|
function normalizeFunctionAction(fn, bindings) {
|
|
1947
1962
|
if (ts.isArrowFunction(fn) && !ts.isBlock(fn.body)) return inlineAction(fn);
|
|
1948
1963
|
if (!fn.body || !ts.isBlock(fn.body)) return inlineAction(fn);
|
|
@@ -2003,7 +2018,7 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
|
|
|
2003
2018
|
if (ts.isIdentifier(node)) {
|
|
2004
2019
|
if (node.text === "undefined") return void 0;
|
|
2005
2020
|
const binding = bindings.get(node.text);
|
|
2006
|
-
return binding ? expressionToValue(binding, bindings, context, depth + 1) : node.text;
|
|
2021
|
+
return binding ? expressionToValue(binding, bindings, context, depth + 1) : context.metaValue ? inlineCodeExpression(node.getText()) : node.text;
|
|
2007
2022
|
}
|
|
2008
2023
|
if (ts.isObjectLiteralExpression(node)) return objectLiteralToValue(node, bindings, context, depth);
|
|
2009
2024
|
if (ts.isArrayLiteralExpression(node)) {
|
|
@@ -2011,17 +2026,19 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
|
|
|
2011
2026
|
return context.actionValue ? values.flat() : values;
|
|
2012
2027
|
}
|
|
2013
2028
|
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
2029
|
+
if (context.metaValue) return inlineCodeExpression(node.getText());
|
|
2014
2030
|
if (context.v6 && context.transitionValue) return normalizeFunctionTransition(node, bindings, depth);
|
|
2015
2031
|
if (context.v6 && context.actionValue) return normalizeFunctionAction(node, bindings);
|
|
2016
2032
|
return node.getText();
|
|
2017
2033
|
}
|
|
2018
2034
|
if (ts.isCallExpression(node)) {
|
|
2035
|
+
if (context.metaValue) return inlineCodeExpression(node.getText());
|
|
2019
2036
|
if (context.actionValue) return inlineAction(node);
|
|
2020
2037
|
const callee = node.expression.getText();
|
|
2021
2038
|
const type = callee.includes(".") ? callee.split(".").pop() : callee;
|
|
2022
2039
|
return { type: type === "assign" ? "xstate.assign" : type };
|
|
2023
2040
|
}
|
|
2024
|
-
return node.getText();
|
|
2041
|
+
return context.metaValue ? inlineCodeExpression(node.getText()) : node.getText();
|
|
2025
2042
|
}
|
|
2026
2043
|
function collectBindings$1(file) {
|
|
2027
2044
|
const bindings = /* @__PURE__ */ new Map();
|