@statelyai/sdk 0.23.1 → 0.25.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 +8 -2
- package/dist/embed.d.mts +5 -2
- package/dist/embed.mjs +17 -2
- package/dist/{graph-1fwR0Ynl.d.mts → graph-BGUND7ZF.d.mts} +1 -1
- package/dist/graph.d.mts +1 -1
- package/dist/{index-D_pO_Pr8.d.mts → index-DuvCSThi.d.mts} +6 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/{inspect-CWFYJT9G.mjs → inspect-QlXh72hZ.mjs} +1 -1
- package/dist/inspect.mjs +2 -2
- package/dist/patchTypes.d.mts +1 -1
- package/dist/protocol.d.mts +14 -8
- package/dist/{statelyPragma-0djA1cnm.mjs → statelyPragma-B-axv279.mjs} +356 -42
- package/dist/{studio-CkrbMK00.d.mts → studio-erXbdakn.d.mts} +1 -1
- package/dist/studio.d.mts +1 -1
- package/dist/sync.d.mts +2 -2
- package/dist/sync.mjs +1 -1
- package/dist/{version-DX-_ZovM.mjs → version-BfcJU2pO.mjs} +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -45,6 +45,10 @@ embed.init({
|
|
|
45
45
|
});
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
The embed `apiKey` is sent to the iframe over `postMessage` after the editor
|
|
49
|
+
handshake; it is not included in the iframe URL. Call `embed.setApiKey(token)`
|
|
50
|
+
when the host refreshes the access token.
|
|
51
|
+
|
|
48
52
|
Use `viewMode: 'list'` on `createStatelyEmbed` to add `?view=list` to the
|
|
49
53
|
iframe URL, or subscribe to `viewModeChanged` when the user switches views.
|
|
50
54
|
|
|
@@ -99,16 +103,18 @@ status and protocol error code metadata so hosts can refresh credentials and
|
|
|
99
103
|
retry once without depending on response-message text.
|
|
100
104
|
Hosts keep ownership of files, credentials, UI, and transport adapters.
|
|
101
105
|
|
|
106
|
+
<!-- supported editor export formats from packages/editor/src/formatConfig.ts -->
|
|
107
|
+
|
|
102
108
|
Key capabilities:
|
|
103
109
|
|
|
104
110
|
- **Mount or attach** to any container element or existing iframe
|
|
105
111
|
- **Two-way sync** - push machine configs in, get changes and saves back via event callbacks
|
|
106
|
-
- **Export** to multiple formats: XState v5, XState JSON, Mermaid, Redux, Zustand, ASL, SCXML, and more
|
|
112
|
+
- **Export** to multiple formats: XState v5, XState v6 alpha, XState JSON, Mermaid, Redux, Zustand, ASL, SCXML, and more
|
|
107
113
|
- **Access policies** for read-only, no-export, no-AI, shallow-viewer embeds
|
|
108
114
|
- **Reference documents** supplied as ordered, read-only Markdown, code, or text
|
|
109
115
|
- **Comments** via Liveblocks integration (optional)
|
|
110
116
|
- **Asset uploads** with built-in S3 and Supabase adapters, or bring your own upload handler
|
|
111
|
-
- **Runtime settings** - toggle color mode, grid, snap lines,
|
|
117
|
+
- **Runtime settings** - toggle color mode, grid, snap lines, and view mode on the fly
|
|
112
118
|
|
|
113
119
|
### Resource API client
|
|
114
120
|
|
package/dist/embed.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as ProfileManifest } from "./index-
|
|
2
|
-
import { i as StatelyGraph } from "./graph-
|
|
1
|
+
import { i as ProfileManifest } from "./index-DuvCSThi.mjs";
|
|
2
|
+
import { i as StatelyGraph } from "./graph-BGUND7ZF.mjs";
|
|
3
3
|
import { CapabilityDeniedEvent, CommentsConfig, EditorCapabilities, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedExtensionsManifest, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, InitOptions, MachineInitOptions, MachineSourceLocations, ProjectEmbedMachine, ProjectWorkspaceAction, ProjectWorkspaceActionIcon, ProjectWorkspaceCapabilities, ProjectWorkspaceConfig, ProjectWorkspaceMachine, ProjectWorkspaceProject, UploadResult } from "./protocol.mjs";
|
|
4
4
|
import { AssetUploadAdapter } from "./assetStorage.mjs";
|
|
5
5
|
|
|
@@ -71,6 +71,7 @@ type EmbedFormatDefinition = {
|
|
|
71
71
|
};
|
|
72
72
|
interface StatelyEmbedOptions extends Partial<MachineInitOptions> {
|
|
73
73
|
baseUrl: string;
|
|
74
|
+
/** Access token sent to the iframe over the embed protocol. */
|
|
74
75
|
apiKey?: string;
|
|
75
76
|
/** Initial canvas view. Also reflected in the iframe URL as `?view=`. */
|
|
76
77
|
viewMode?: 'graph' | 'list';
|
|
@@ -115,6 +116,8 @@ interface StatelyEmbed {
|
|
|
115
116
|
attach(iframe: HTMLIFrameElement): void;
|
|
116
117
|
/** Create an iframe and mount it into a container element. */
|
|
117
118
|
mount(container: HTMLElement): HTMLIFrameElement;
|
|
119
|
+
/** Update the access token used by the iframe. */
|
|
120
|
+
setApiKey(apiKey: string): void;
|
|
118
121
|
/** Send init message (queued if iframe not ready yet). */
|
|
119
122
|
init(options: InitOptions): void;
|
|
120
123
|
/** Update the machine (shorthand for update message). */
|
package/dist/embed.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-
|
|
1
|
+
import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-BfcJU2pO.mjs";
|
|
2
2
|
import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/embed.ts
|
|
@@ -25,10 +25,13 @@ function assertExtensionCall(value) {
|
|
|
25
25
|
if ((value.method === "export" || value.method === "validate") && !isEmbedGraph(payload.graph)) throw new Error("Invalid extension graph payload.");
|
|
26
26
|
if (value.method === "validate" && payload.revision !== void 0 && typeof payload.revision !== "number") throw new Error("Invalid extension revision payload.");
|
|
27
27
|
}
|
|
28
|
+
function normalizeApiKey(apiKey) {
|
|
29
|
+
return apiKey?.trim() || void 0;
|
|
30
|
+
}
|
|
28
31
|
function buildEmbedUrl(options) {
|
|
29
32
|
const base = options.baseUrl.replace(/\/+$/, "") + "/embed";
|
|
30
33
|
const url = new URL(base);
|
|
31
|
-
if (options.apiKey) url.searchParams.set("
|
|
34
|
+
if (normalizeApiKey(options.apiKey)) url.searchParams.set("auth", "message");
|
|
32
35
|
if (options.viewMode) url.searchParams.set("view", options.viewMode);
|
|
33
36
|
return url.toString();
|
|
34
37
|
}
|
|
@@ -113,6 +116,7 @@ function createStatelyEmbed(options) {
|
|
|
113
116
|
let ownedIframe = false;
|
|
114
117
|
let destroyed = false;
|
|
115
118
|
let editorProtocolCompatible;
|
|
119
|
+
let apiKey = normalizeApiKey(options.apiKey);
|
|
116
120
|
const pendingMessages = [];
|
|
117
121
|
const events = createEventRegistry();
|
|
118
122
|
const profiles = new Map((options.profiles ?? []).map((profile) => [profile.profile, profile]));
|
|
@@ -141,6 +145,12 @@ function createStatelyEmbed(options) {
|
|
|
141
145
|
transport.send(msg);
|
|
142
146
|
}
|
|
143
147
|
}
|
|
148
|
+
function sendApiKey() {
|
|
149
|
+
if (apiKey) send({
|
|
150
|
+
type: "@statelyai.setApiKey",
|
|
151
|
+
apiKey
|
|
152
|
+
});
|
|
153
|
+
}
|
|
144
154
|
function formatContext(profile) {
|
|
145
155
|
const namespace = profile.namespace ?? /^(@[^/]+)\//.exec(profile.profile)?.[1];
|
|
146
156
|
if (!namespace) throw new Error(`Profile ${profile.profile} has no namespace.`);
|
|
@@ -231,6 +241,7 @@ function createStatelyEmbed(options) {
|
|
|
231
241
|
}
|
|
232
242
|
});
|
|
233
243
|
} else editorProtocolCompatible = true;
|
|
244
|
+
sendApiKey();
|
|
234
245
|
flush();
|
|
235
246
|
if (uploadAsset) send({
|
|
236
247
|
type: "@statelyai.uploadCapabilities",
|
|
@@ -411,6 +422,10 @@ function createStatelyEmbed(options) {
|
|
|
411
422
|
setupTransport(el);
|
|
412
423
|
return el;
|
|
413
424
|
},
|
|
425
|
+
setApiKey(nextApiKey) {
|
|
426
|
+
apiKey = normalizeApiKey(nextApiKey);
|
|
427
|
+
sendApiKey();
|
|
428
|
+
},
|
|
414
429
|
init(opts) {
|
|
415
430
|
send(toInitMessage("machine" in opts ? {
|
|
416
431
|
...opts,
|
package/dist/graph.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as studioMachineConverter, a as StatelyGraphData, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, n as StatelyActorImplementation, o as StatelyGuard, p as StudioEventTypeData, r as StatelyEdgeData, s as StatelyImplementation, t as StatelyAction, u as StatelyTagImplementation, v as toStudioMachine } from "./graph-
|
|
1
|
+
import { _ as studioMachineConverter, a as StatelyGraphData, c as StatelyInvoke, d as StudioAction, f as StudioEdge, g as fromStudioMachine, h as StudioNode, i as StatelyGraph, l as StatelyNodeData, m as StudioMachine, n as StatelyActorImplementation, o as StatelyGuard, p as StudioEventTypeData, r as StatelyEdgeData, s as StatelyImplementation, t as StatelyAction, u as StatelyTagImplementation, v as toStudioMachine } from "./graph-BGUND7ZF.mjs";
|
|
2
2
|
export { StatelyAction, StatelyActorImplementation, StatelyEdgeData, StatelyGraph, StatelyGraphData, StatelyGuard, StatelyImplementation, StatelyInvoke, StatelyNodeData, StatelyTagImplementation, StudioAction, StudioEdge, StudioEventTypeData, StudioMachine, StudioNode, fromStudioMachine, studioMachineConverter, toStudioMachine };
|
|
@@ -2731,6 +2731,8 @@ interface CodeExpression {
|
|
|
2731
2731
|
interface CodeImport {
|
|
2732
2732
|
package: string;
|
|
2733
2733
|
import: string;
|
|
2734
|
+
/** Local binding name when it differs from the imported name. */
|
|
2735
|
+
local?: string;
|
|
2734
2736
|
importKind?: 'named' | 'default' | 'namespace';
|
|
2735
2737
|
version?: string;
|
|
2736
2738
|
}
|
|
@@ -2791,6 +2793,7 @@ interface CodeGenImplementation {
|
|
|
2791
2793
|
code?: {
|
|
2792
2794
|
body: string;
|
|
2793
2795
|
lang?: string;
|
|
2796
|
+
imports?: CodeImport[];
|
|
2794
2797
|
} | null;
|
|
2795
2798
|
}
|
|
2796
2799
|
interface CodeGenActorImplementation {
|
|
@@ -2803,6 +2806,7 @@ interface CodeGenActorImplementation {
|
|
|
2803
2806
|
code?: {
|
|
2804
2807
|
body: string;
|
|
2805
2808
|
lang?: string;
|
|
2809
|
+
imports?: CodeImport[];
|
|
2806
2810
|
} | null;
|
|
2807
2811
|
}
|
|
2808
2812
|
interface CodeGenGraphData {
|
|
@@ -2938,6 +2942,7 @@ interface XStateTSOptions extends MachineConfigOptions {
|
|
|
2938
2942
|
exportStyle?: 'named' | 'default' | 'none';
|
|
2939
2943
|
targetLanguage?: 'typescript' | 'javascript';
|
|
2940
2944
|
xstateVersion?: 5 | 6;
|
|
2945
|
+
xstateV6SchemaFormat?: 'types' | 'zod';
|
|
2941
2946
|
}
|
|
2942
2947
|
declare function graphToXStateTS(graph: CodeGenGraph, options?: XStateTSOptions): string; //#endregion
|
|
2943
2948
|
//#region src/jsonSchemaToTSType.d.ts
|
|
@@ -2952,6 +2957,6 @@ declare function contextSchemaToTSType(context: Record<string, JSONSchema7> | nu
|
|
|
2952
2957
|
* Each key is the event type name, value describes the payload properties.
|
|
2953
2958
|
*/
|
|
2954
2959
|
declare function eventsSchemaToTSType(events: Record<string, JSONSchema7> | null | undefined): string | null; //#endregion
|
|
2955
|
-
//#region src/
|
|
2960
|
+
//#region src/jsonSchemaToZod.d.ts
|
|
2956
2961
|
//#endregion
|
|
2957
2962
|
export { output as A, ZodNumber as C, ZodString as D, ZodRecord as E, ZodUnion as O, ZodNullable as S, ZodOptional as T, GraphPatch as _, RawCode as a, ZodEnum as b, eventsSchemaToTSType as c, jsonSchemaToTSType as d, raw as f, EditorStateType as g, CanvasColor as h, ProfileManifest as i, $strip as j, ZodUnknown as k, graphToMachineConfig as l, ActionLocation as m, CodeGenGraph as n, XStateTSOptions as o, serializeJS as p, MachineConfigOptions as r, contextSchemaToTSType as s, CodeExpression as t, graphToXStateTS as u, ImplementationSourceType as v, ZodObject as w, ZodLiteral as x, ZodArray as y };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { StatelyApiClientOptions, StatelyApiError, StatelyApiUrlOptions, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
|
|
2
|
-
import { _ as GraphPatch, a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, f as raw, l as graphToMachineConfig, m as ActionLocation, n as CodeGenGraph, o as XStateTSOptions, p as serializeJS, r as MachineConfigOptions, s as contextSchemaToTSType, u as graphToXStateTS } from "./index-
|
|
3
|
-
import { C as EventTypeData, S as DigraphNodeConfig, _ 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-
|
|
2
|
+
import { _ as GraphPatch, a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, f as raw, l as graphToMachineConfig, m as ActionLocation, n as CodeGenGraph, o as XStateTSOptions, p as serializeJS, r as MachineConfigOptions, s as contextSchemaToTSType, u as graphToXStateTS } from "./index-DuvCSThi.mjs";
|
|
3
|
+
import { C as EventTypeData, S as DigraphNodeConfig, _ 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-BGUND7ZF.mjs";
|
|
4
4
|
import { CapabilityDeniedCapability, CapabilityDeniedEvent, CommentsConfig, EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, EditorCapabilities, EmbedDocument, EmbedDocumentLanguage, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, InitOptions, InspectionAction, InspectionSentEvent, InspectionTakenTransition, ProjectEmbedMachine, ProjectWorkspaceAction, ProjectWorkspaceActionIcon, ProjectWorkspaceCapabilities, ProjectWorkspaceConfig, ProjectWorkspaceMachine, ProjectWorkspaceProject, UploadResult, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
|
|
5
5
|
import { AssetUploadAdapter, AssetUploadContext, AssetUploadRequest, CreateS3AssetUploadAdapterOptions, CreateSupabaseAssetUploadAdapterOptions, S3UploadTarget, SupabaseStorageClient, createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
|
|
6
6
|
import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-B0ZTKri2.mjs";
|
|
7
7
|
import { c as fetchEditorSyncAccess, d as EditorHostInboundMessage, f as EditorHostInitOptions, i as EditorSyncBackend, l as EDITOR_PROTOCOL_VERSION, m as EditorHostValidationIssue, n as EditorHostSessionOptions, o as RemoteEditorSyncBackendOptions, p as EditorHostOutboundMessage, r as EditorSourceHost, s as createRemoteEditorSyncBackend, t as EditorHostSession, u as EditorHostExportFormat } from "./editorHostSession-DTXKcLhR.mjs";
|
|
8
8
|
import { AssetConfig, EmbedEntity, EmbedFormatContext, EmbedFormatDefinition, EmbedGraph, EmbedProfileDefinition, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.mjs";
|
|
9
9
|
import { _ as createWebSocketTransport, a as InspectedTransition, c as InspectorDiscoveryEntry, d as ManualActorOptions, f as createInspector, g as createPostMessageTransport, h as TransportFailure, i as InspectedSnapshot, l as InspectorEvents, m as Transport, n as CreateInspectorOptions, o as Inspector, p as createStatelyInspector, r as InspectedEvent, s as InspectorConnection, t as AdoptedActor, u as InspectorInspectionEvent } from "./inspect-Br_vS_lK.mjs";
|
|
10
|
-
import { A as Machine, C as StudioMachineRecord, D as VerifyApiKeyResponse, E as UpdateProjectInput, F as ProjectVisibility, I as VerifyResult, L as XStateVersion, M as Project, N as ProjectMachineSummary, O as createStatelyClient, P as ProjectSummary, R as ResourceErrorCode, S as StudioClientOptions, T as UpdateMachineInput, _ as ProjectMachine, a as CreateMachineTemplate, b as StudioApiErrorOptions, c as EnsureProjectInput, d as ExtractedMachine, f as GetMachineOptions, g as ProjectData, h as LegacyUpdateMachineInput, i as CreateMachineInput, j as MachineVersion, k as ExtractedMachines, l as ExtractMachinesInput, m as LegacyProjectVisibility, n as CreateMachineFromDefinitionInput, o as CreateProjectInput, r as CreateMachineFromTemplateInput, s as DEFAULT_STATELY_BASE_URL, t as ConnectedRepo, u as ExtractMachinesResponse, v as RepoType, w as StudioRequestOptions, x as StudioClient, y as StudioApiError } from "./studio-
|
|
10
|
+
import { A as Machine, C as StudioMachineRecord, D as VerifyApiKeyResponse, E as UpdateProjectInput, F as ProjectVisibility, I as VerifyResult, L as XStateVersion, M as Project, N as ProjectMachineSummary, O as createStatelyClient, P as ProjectSummary, R as ResourceErrorCode, S as StudioClientOptions, T as UpdateMachineInput, _ as ProjectMachine, a as CreateMachineTemplate, b as StudioApiErrorOptions, c as EnsureProjectInput, d as ExtractedMachine, f as GetMachineOptions, g as ProjectData, h as LegacyUpdateMachineInput, i as CreateMachineInput, j as MachineVersion, k as ExtractedMachines, l as ExtractMachinesInput, m as LegacyProjectVisibility, n as CreateMachineFromDefinitionInput, o as CreateProjectInput, r as CreateMachineFromTemplateInput, s as DEFAULT_STATELY_BASE_URL, t as ConnectedRepo, u as ExtractMachinesResponse, v as RepoType, w as StudioRequestOptions, x as StudioClient, y as StudioApiError } from "./studio-erXbdakn.mjs";
|
|
11
11
|
import { OAuthAuthorizationServerMetadata, OAuthClientRegistrationResponse, OAuthProtectedResourceMetadata, OAuthTokenResponse, PkcePair, buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
|
|
12
12
|
import { PlanSyncOptions, PullSyncResult, PushLocalMachineLinksResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary } from "./sync.mjs";
|
|
13
13
|
import { CreateInspectionRelayOptions, InspectionRelay, InspectionRelayEffect, InspectionRelayPeer, InspectionRelayRole, InspectionRelaySnapshot, createInspectionRelay } from "./relay.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "./openapi-BTDjYWXd.mjs";
|
|
2
2
|
import { EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
|
|
3
|
-
import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-
|
|
3
|
+
import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-BfcJU2pO.mjs";
|
|
4
4
|
import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
|
|
5
5
|
import { createStatelyEmbed } from "./embed.mjs";
|
|
6
6
|
import { i as fetchEditorSyncAccess, r as createRemoteEditorSyncBackend, t as EditorHostSession } from "./editorHostSession-BwS-EiBJ.mjs";
|
|
7
7
|
import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-iNSHtNmP.mjs";
|
|
8
|
-
import { a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, l as graphToMachineConfig, m as serializeJS, n as getStatelyPragma, o as contextSchemaToTSType, p as raw, r as upsertStatelyPragma, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-
|
|
8
|
+
import { a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, l as graphToMachineConfig, m as serializeJS, n as getStatelyPragma, o as contextSchemaToTSType, p as raw, r as upsertStatelyPragma, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-B-axv279.mjs";
|
|
9
9
|
import { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
|
|
10
|
-
import { n as createStatelyInspector, t as createInspector } from "./inspect-
|
|
10
|
+
import { n as createStatelyInspector, t as createInspector } from "./inspect-QlXh72hZ.mjs";
|
|
11
11
|
import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
|
|
12
12
|
import { buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
|
|
13
13
|
import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { INSPECTION_PROTOCOL_VERSION, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
|
|
2
|
-
import { a as createEventRegistry, i as createWebSocketTransport, n as inspectionRuntime, o as createPendingExportManager, t as SDK_VERSION } from "./version-
|
|
2
|
+
import { a as createEventRegistry, i as createWebSocketTransport, n as inspectionRuntime, o as createPendingExportManager, t as SDK_VERSION } from "./version-BfcJU2pO.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/openBrowser.ts
|
|
5
5
|
async function openBrowser(url) {
|
package/dist/inspect.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./version-
|
|
2
|
-
import { n as createStatelyInspector, t as createInspector } from "./inspect-
|
|
1
|
+
import "./version-BfcJU2pO.mjs";
|
|
2
|
+
import { n as createStatelyInspector, t as createInspector } from "./inspect-QlXh72hZ.mjs";
|
|
3
3
|
|
|
4
4
|
export { createInspector, createStatelyInspector };
|
package/dist/patchTypes.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as GraphPatch, g as EditorStateType, h as CanvasColor, m as ActionLocation, v as ImplementationSourceType } from "./index-
|
|
1
|
+
import { _ as GraphPatch, g as EditorStateType, h as CanvasColor, m as ActionLocation, v as ImplementationSourceType } from "./index-DuvCSThi.mjs";
|
|
2
2
|
export { type ActionLocation, type CanvasColor, type EditorStateType, type GraphPatch, type ImplementationSourceType };
|
package/dist/protocol.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as ProfileManifest } from "./index-
|
|
2
|
-
import { i as StatelyGraph } from "./graph-
|
|
1
|
+
import { i as ProfileManifest } from "./index-DuvCSThi.mjs";
|
|
2
|
+
import { i as StatelyGraph } from "./graph-BGUND7ZF.mjs";
|
|
3
3
|
import { c as EditorSyncSourceLocation, f as MachineSourceLocations$1, l as EditorSyncSourceRange, t as EditorCapabilities$1, u as EditorSyncStateSourceLocation } from "./editor-sync-types-C-zWaaVk.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/protocol.d.ts
|
|
@@ -65,12 +65,10 @@ interface ProjectWorkspaceCapabilities {
|
|
|
65
65
|
deleteMachine?: ProjectWorkspaceAction;
|
|
66
66
|
setRootMachine?: ProjectWorkspaceAction;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
interface ProjectWorkspaceConfig {
|
|
70
|
-
/** Visible projects; pass one entry when embedding a single project. */
|
|
71
|
-
projects: ProjectWorkspaceProject[];
|
|
68
|
+
interface ProjectWorkspaceConfigBase {
|
|
72
69
|
defaultProjectId?: string;
|
|
73
|
-
|
|
70
|
+
/** Optional navigation action shown above the workspace. Set to null to hide it. */
|
|
71
|
+
backAction?: ProjectWorkspaceAction | null;
|
|
74
72
|
userAvatarUrl?: string;
|
|
75
73
|
machineSelectionDisabled?: boolean;
|
|
76
74
|
/** Optional host-backed operations for the built-in workspace controls. */
|
|
@@ -81,6 +79,14 @@ interface ProjectWorkspaceConfig {
|
|
|
81
79
|
projectActions?: Record<string, ProjectWorkspaceAction[]>;
|
|
82
80
|
machineActions?: Record<string, ProjectWorkspaceAction[]>;
|
|
83
81
|
}
|
|
82
|
+
/** Serializable workspace tree rendered by project-mode embeds. */
|
|
83
|
+
type ProjectWorkspaceConfig = (ProjectWorkspaceConfigBase & {
|
|
84
|
+
/** Single-project mode: hides project CRUD and flattens its machines. */project: ProjectWorkspaceProject;
|
|
85
|
+
projects?: never;
|
|
86
|
+
}) | (ProjectWorkspaceConfigBase & {
|
|
87
|
+
/** Multi-project mode: renders a collapsible project tree. */projects: ProjectWorkspaceProject[];
|
|
88
|
+
project?: never;
|
|
89
|
+
});
|
|
84
90
|
declare const EMBED_DOCUMENT_LANGUAGES: readonly ["markdown", "typescript", "javascript", "json", "xml", "mermaid", "text"];
|
|
85
91
|
type EmbedDocumentLanguage = (typeof EMBED_DOCUMENT_LANGUAGES)[number];
|
|
86
92
|
declare const EMBED_DOCUMENT_LIMITS: {
|
|
@@ -278,7 +284,7 @@ interface MachineInitOptions {
|
|
|
278
284
|
* - `enabled` — whether to show the pill at all. Defaults to `false`.
|
|
279
285
|
* - `mode` — `'structural'` (default) only triggers on graph-structural
|
|
280
286
|
* changes (state/transition/action/invoke/schema edits). Pure visual
|
|
281
|
-
* changes like drag-to-position, color, and
|
|
287
|
+
* changes like drag-to-position, color, and layout are ignored.
|
|
282
288
|
* `'all'` triggers on any graph change.
|
|
283
289
|
*/
|
|
284
290
|
unsavedIndicator?: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { a as discriminatedUnion, c as object, d as union, f as unknown, i as custom, l as record, n as array, o as literal, r as boolean, s as number, t as _enum, u as string } from "./openapi-BTDjYWXd.mjs";
|
|
2
2
|
import ts from "typescript";
|
|
3
|
+
import "xstate";
|
|
3
4
|
import "xstate/graph";
|
|
4
5
|
|
|
5
6
|
//#region ../../node_modules/.pnpm/js-yaml@4.2.0/node_modules/js-yaml/dist/js-yaml.mjs
|
|
@@ -2881,8 +2882,8 @@ function graphToMachineConfig(graph, options = {}) {
|
|
|
2881
2882
|
id: inv.invocationId ?? inv.id,
|
|
2882
2883
|
...inv.registryKey ? { registryKey: inv.registryKey } : void 0,
|
|
2883
2884
|
...inv.timeout !== void 0 ? { timeout: inv.timeout } : void 0,
|
|
2884
|
-
...inv.input ? { input: inv.input } : void 0,
|
|
2885
|
-
...inv.output ? { output: inv.output } : void 0
|
|
2885
|
+
...inv.input !== void 0 ? { input: inv.input } : void 0,
|
|
2886
|
+
...inv.output !== void 0 ? { output: inv.output } : void 0
|
|
2886
2887
|
})) } : void 0,
|
|
2887
2888
|
...node.data.output !== void 0 ? { output: node.data.output } : void 0,
|
|
2888
2889
|
...tags?.length ? { tags: tags.map(tagToString) } : void 0,
|
|
@@ -3436,88 +3437,117 @@ function schemasObjectToValue(node) {
|
|
|
3436
3437
|
return result;
|
|
3437
3438
|
}
|
|
3438
3439
|
function propertyContext(parent, key) {
|
|
3440
|
+
const inherited = parent.imports ? { imports: parent.imports } : {};
|
|
3441
|
+
if (parent.machineValue && (key === "actors" || key === "actorSources")) return {
|
|
3442
|
+
...inherited,
|
|
3443
|
+
v6: parent.v6,
|
|
3444
|
+
implementationMap: true
|
|
3445
|
+
};
|
|
3439
3446
|
if (parent.setupValue && (key === "actions" || key === "guards" || key === "actors" || key === "delays")) return {
|
|
3447
|
+
...inherited,
|
|
3440
3448
|
v6: parent.v6,
|
|
3441
3449
|
implementationMap: true
|
|
3442
3450
|
};
|
|
3443
3451
|
if (parent.implementationMap) return {
|
|
3452
|
+
...inherited,
|
|
3444
3453
|
v6: parent.v6,
|
|
3445
3454
|
implementationValue: true
|
|
3446
3455
|
};
|
|
3447
3456
|
if (parent.effectArgumentValue) return {
|
|
3457
|
+
...inherited,
|
|
3448
3458
|
v6: parent.v6,
|
|
3449
3459
|
effectArgumentValue: true
|
|
3450
3460
|
};
|
|
3451
3461
|
if (parent.invokeValue && key === "src") return {
|
|
3462
|
+
...inherited,
|
|
3452
3463
|
v6: parent.v6,
|
|
3453
3464
|
actorSourceValue: true
|
|
3454
3465
|
};
|
|
3455
3466
|
if (parent.transitionMap) return {
|
|
3467
|
+
...inherited,
|
|
3456
3468
|
v6: parent.v6,
|
|
3457
3469
|
transitionValue: true
|
|
3458
3470
|
};
|
|
3459
3471
|
if (parent.transitionValue && key === "actions") return {
|
|
3472
|
+
...inherited,
|
|
3460
3473
|
v6: parent.v6,
|
|
3461
3474
|
actionValue: true
|
|
3462
3475
|
};
|
|
3463
3476
|
if (parent.transitionValue && key === "context") return {
|
|
3477
|
+
...inherited,
|
|
3464
3478
|
v6: parent.v6,
|
|
3465
3479
|
assignmentMap: true,
|
|
3466
3480
|
transitionContext: true
|
|
3467
3481
|
};
|
|
3468
3482
|
if (key === "context") return {
|
|
3483
|
+
...inherited,
|
|
3469
3484
|
v6: parent.v6,
|
|
3470
3485
|
machineContextValue: true
|
|
3471
3486
|
};
|
|
3472
3487
|
if (parent.transitionValue && key === "target") return {
|
|
3488
|
+
...inherited,
|
|
3473
3489
|
v6: parent.v6,
|
|
3474
3490
|
targetValue: true
|
|
3475
3491
|
};
|
|
3476
3492
|
if (parent.assignmentMap) return {
|
|
3493
|
+
...inherited,
|
|
3477
3494
|
v6: parent.v6,
|
|
3478
3495
|
assignmentValue: true
|
|
3479
3496
|
};
|
|
3480
3497
|
if (key === "meta") return {
|
|
3498
|
+
...inherited,
|
|
3481
3499
|
v6: parent.v6,
|
|
3482
3500
|
metaValue: true
|
|
3483
3501
|
};
|
|
3484
3502
|
if (parent.transitionValue && key === "to") return {
|
|
3503
|
+
...inherited,
|
|
3485
3504
|
v6: parent.v6,
|
|
3486
3505
|
transitionValue: true
|
|
3487
3506
|
};
|
|
3488
3507
|
if (key === "entry" || key === "exit") return {
|
|
3508
|
+
...inherited,
|
|
3489
3509
|
v6: parent.v6,
|
|
3490
3510
|
actionValue: true
|
|
3491
3511
|
};
|
|
3492
3512
|
if (key === "input" || key === "output") return {
|
|
3513
|
+
...inherited,
|
|
3493
3514
|
v6: parent.v6,
|
|
3494
3515
|
ioValue: true
|
|
3495
3516
|
};
|
|
3496
3517
|
if (parent.ioValue || parent.ioPropertyValue) return {
|
|
3518
|
+
...inherited,
|
|
3497
3519
|
v6: parent.v6,
|
|
3498
3520
|
ioPropertyValue: true
|
|
3499
3521
|
};
|
|
3500
3522
|
if (key === "invoke") return {
|
|
3523
|
+
...inherited,
|
|
3501
3524
|
v6: parent.v6,
|
|
3502
3525
|
invokeValue: true
|
|
3503
3526
|
};
|
|
3504
3527
|
if (key === "timeout") return {
|
|
3528
|
+
...inherited,
|
|
3505
3529
|
v6: parent.v6,
|
|
3506
3530
|
timeoutValue: true
|
|
3507
3531
|
};
|
|
3508
3532
|
if (key === "route") return {
|
|
3533
|
+
...inherited,
|
|
3509
3534
|
v6: parent.v6,
|
|
3510
3535
|
routeValue: true
|
|
3511
3536
|
};
|
|
3512
3537
|
if (key === "on" || key === "after") return {
|
|
3538
|
+
...inherited,
|
|
3513
3539
|
v6: parent.v6,
|
|
3514
3540
|
transitionMap: true
|
|
3515
3541
|
};
|
|
3516
3542
|
if (key === "always" || key === "choice" || key === "onDone" || key === "onError" || key === "onSnapshot" || key === "onTimeout") return {
|
|
3543
|
+
...inherited,
|
|
3517
3544
|
v6: parent.v6,
|
|
3518
3545
|
transitionValue: true
|
|
3519
3546
|
};
|
|
3520
|
-
return {
|
|
3547
|
+
return {
|
|
3548
|
+
...inherited,
|
|
3549
|
+
v6: parent.v6
|
|
3550
|
+
};
|
|
3521
3551
|
}
|
|
3522
3552
|
function fallbackFunctionTransition(fn) {
|
|
3523
3553
|
return { meta: {
|
|
@@ -3531,7 +3561,7 @@ function conditionText(cond) {
|
|
|
3531
3561
|
function simplifyConditions(conds) {
|
|
3532
3562
|
const seen = /* @__PURE__ */ new Set();
|
|
3533
3563
|
return conds.filter((cond) => {
|
|
3534
|
-
if (cond.negated) return false;
|
|
3564
|
+
if (cond.negated && !cond.preserveNegation) return false;
|
|
3535
3565
|
const key = conditionText(cond);
|
|
3536
3566
|
if (seen.has(key)) return false;
|
|
3537
3567
|
seen.add(key);
|
|
@@ -3755,18 +3785,21 @@ function statementBranches(statements, bindings, enqName, prefixes = [{
|
|
|
3755
3785
|
...prefix,
|
|
3756
3786
|
conds: [...prefix.conds, { text: cond }]
|
|
3757
3787
|
}]);
|
|
3788
|
+
const thenHasEffectiveTransition = thenBranches.every((branch) => branch.result !== void 0 && branch.result !== null || branch.actions.length > 0);
|
|
3758
3789
|
const elseStatements = statement.elseStatement ? ts.isBlock(statement.elseStatement) ? statement.elseStatement.statements : [statement.elseStatement] : [];
|
|
3759
3790
|
const elseBranches = elseStatements.length > 0 ? statementBranches(elseStatements, scopedBindings, enqName, [{
|
|
3760
3791
|
...prefix,
|
|
3761
3792
|
conds: [...prefix.conds, {
|
|
3762
3793
|
text: cond,
|
|
3763
|
-
negated: true
|
|
3794
|
+
negated: true,
|
|
3795
|
+
preserveNegation: !thenHasEffectiveTransition
|
|
3764
3796
|
}]
|
|
3765
3797
|
}]) : [{
|
|
3766
3798
|
...prefix,
|
|
3767
3799
|
conds: [...prefix.conds, {
|
|
3768
3800
|
text: cond,
|
|
3769
|
-
negated: true
|
|
3801
|
+
negated: true,
|
|
3802
|
+
preserveNegation: !thenHasEffectiveTransition
|
|
3770
3803
|
}]
|
|
3771
3804
|
}];
|
|
3772
3805
|
for (const branch of [...thenBranches, ...elseBranches]) if ("result" in branch) done.push(branch);
|
|
@@ -3877,13 +3910,34 @@ function enqueueAction(fn) {
|
|
|
3877
3910
|
}
|
|
3878
3911
|
};
|
|
3879
3912
|
}
|
|
3880
|
-
function inlineCodeExpression(expr) {
|
|
3913
|
+
function inlineCodeExpression(expr, imports) {
|
|
3881
3914
|
return {
|
|
3882
3915
|
"@type": "code",
|
|
3883
3916
|
lang: "ts",
|
|
3884
|
-
expr
|
|
3917
|
+
expr,
|
|
3918
|
+
...imports?.length ? { imports } : {}
|
|
3885
3919
|
};
|
|
3886
3920
|
}
|
|
3921
|
+
function codeImportsForExpression(expression, imports) {
|
|
3922
|
+
if (!imports?.size) return void 0;
|
|
3923
|
+
const sourceImports = imports;
|
|
3924
|
+
const file = sourceFile(`(${expression})`);
|
|
3925
|
+
const found = /* @__PURE__ */ new Map();
|
|
3926
|
+
const expressionNode = file.statements[0] && ts.isExpressionStatement(file.statements[0]) ? file.statements[0].expression : void 0;
|
|
3927
|
+
function visit(node) {
|
|
3928
|
+
if (expressionNode && ts.isIdentifier(node) && sourceImports.has(node.text) && !isShadowedWithinExpression(node, expressionNode)) {
|
|
3929
|
+
const parent = node.parent;
|
|
3930
|
+
if (ts.isPropertyAccessExpression(parent) && parent.name === node || ts.isPropertyAssignment(parent) && parent.name === node) {
|
|
3931
|
+
ts.forEachChild(node, visit);
|
|
3932
|
+
return;
|
|
3933
|
+
}
|
|
3934
|
+
found.set(node.text, sourceImports.get(node.text));
|
|
3935
|
+
}
|
|
3936
|
+
ts.forEachChild(node, visit);
|
|
3937
|
+
}
|
|
3938
|
+
visit(file);
|
|
3939
|
+
return found.size ? [...found.values()] : void 0;
|
|
3940
|
+
}
|
|
3887
3941
|
function normalizeFunctionAction(fn, _bindings) {
|
|
3888
3942
|
return enqueueAction(fn);
|
|
3889
3943
|
}
|
|
@@ -3948,10 +4002,13 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
|
|
|
3948
4002
|
if (context.implementationValue) {
|
|
3949
4003
|
if (ts.isIdentifier(node)) {
|
|
3950
4004
|
const binding = bindings.get(node.text);
|
|
3951
|
-
if (binding)
|
|
4005
|
+
if (binding) {
|
|
4006
|
+
const code = ts.isFunctionDeclaration(binding) ? binding.getText() : unwrapExpression(binding).getText();
|
|
4007
|
+
return inlineCodeExpression(code, codeImportsForExpression(code, context.imports));
|
|
4008
|
+
}
|
|
3952
4009
|
return;
|
|
3953
4010
|
}
|
|
3954
|
-
return inlineCodeExpression(node.getText());
|
|
4011
|
+
return inlineCodeExpression(node.getText(), codeImportsForExpression(node.getText(), context.imports));
|
|
3955
4012
|
}
|
|
3956
4013
|
if (context.machineContextValue && (ts.isArrowFunction(node) || ts.isFunctionExpression(node))) return inlineCodeExpression(node.getText());
|
|
3957
4014
|
if (context.targetValue) {
|
|
@@ -4018,7 +4075,8 @@ function expressionToValue(expression, bindings, context = {}, depth = 0) {
|
|
|
4018
4075
|
}
|
|
4019
4076
|
return expressionToValue(binding, bindings, context, depth + 1);
|
|
4020
4077
|
}
|
|
4021
|
-
|
|
4078
|
+
const imported = context.imports?.get(node.text);
|
|
4079
|
+
return imported ? inlineCodeExpression(node.text, [imported]) : context.metaValue ? inlineCodeExpression(node.getText()) : node.text;
|
|
4022
4080
|
}
|
|
4023
4081
|
if (ts.isObjectLiteralExpression(node)) return objectLiteralToValue(node, bindings, context, depth);
|
|
4024
4082
|
if (ts.isArrayLiteralExpression(node)) {
|
|
@@ -4075,6 +4133,26 @@ function collectBindings(file) {
|
|
|
4075
4133
|
}
|
|
4076
4134
|
return bindings;
|
|
4077
4135
|
}
|
|
4136
|
+
function collectSourceImports(file) {
|
|
4137
|
+
const imports = /* @__PURE__ */ new Map();
|
|
4138
|
+
for (const statement of file.statements) {
|
|
4139
|
+
if (!ts.isImportDeclaration(statement)) continue;
|
|
4140
|
+
const moduleSpecifier = statement.moduleSpecifier;
|
|
4141
|
+
if (!ts.isStringLiteral(moduleSpecifier)) continue;
|
|
4142
|
+
const namedBindings = statement.importClause?.namedBindings;
|
|
4143
|
+
if (!namedBindings || !ts.isNamedImports(namedBindings)) continue;
|
|
4144
|
+
for (const element of namedBindings.elements) {
|
|
4145
|
+
const imported = element.propertyName?.text ?? element.name.text;
|
|
4146
|
+
imports.set(element.name.text, {
|
|
4147
|
+
package: moduleSpecifier.text,
|
|
4148
|
+
import: imported,
|
|
4149
|
+
local: imported === element.name.text ? void 0 : element.name.text,
|
|
4150
|
+
importKind: "named"
|
|
4151
|
+
});
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
return imports;
|
|
4155
|
+
}
|
|
4078
4156
|
function isCreateMachineCall(node) {
|
|
4079
4157
|
const expression = node.expression;
|
|
4080
4158
|
if (ts.isIdentifier(expression)) return isMachineFactoryName(expression.text);
|
|
@@ -4173,6 +4251,7 @@ function xstateSourceToConfig(source, options = {}) {
|
|
|
4173
4251
|
function extractXStateMachineConfigs(source, options = {}) {
|
|
4174
4252
|
const file = sourceFile(source);
|
|
4175
4253
|
const bindings = collectBindings(file);
|
|
4254
|
+
const imports = collectSourceImports(file);
|
|
4176
4255
|
const found = [];
|
|
4177
4256
|
const profile = options.profile === "auto" || !options.profile ? detectXStateSourceProfile(source) : options.profile;
|
|
4178
4257
|
function visit(node) {
|
|
@@ -4182,12 +4261,17 @@ function extractXStateMachineConfigs(source, options = {}) {
|
|
|
4182
4261
|
}
|
|
4183
4262
|
const arg = node.arguments[0];
|
|
4184
4263
|
if (!arg) return;
|
|
4185
|
-
const value = expressionToValue(arg, bindings, {
|
|
4264
|
+
const value = expressionToValue(arg, bindings, {
|
|
4265
|
+
v6: profile === "xstate-v6-alpha",
|
|
4266
|
+
machineValue: true,
|
|
4267
|
+
imports
|
|
4268
|
+
});
|
|
4186
4269
|
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
4187
4270
|
const setupArg = setupCallForCreateMachine(node, bindings)?.arguments[0];
|
|
4188
4271
|
const setupValue = setupArg ? expressionToValue(setupArg, bindings, {
|
|
4189
4272
|
v6: profile === "xstate-v6-alpha",
|
|
4190
|
-
setupValue: true
|
|
4273
|
+
setupValue: true,
|
|
4274
|
+
imports
|
|
4191
4275
|
}) : null;
|
|
4192
4276
|
const setupRecord = setupValue && typeof setupValue === "object" && !Array.isArray(setupValue) ? Object.fromEntries(Object.entries(setupValue).filter(([, item]) => !(item && typeof item === "object" && !Array.isArray(item) && Object.keys(item).length === 0))) : {};
|
|
4193
4277
|
found.push({
|
|
@@ -4231,7 +4315,7 @@ function objectType(schema) {
|
|
|
4231
4315
|
const required = getRequiredKeys(schema);
|
|
4232
4316
|
return `{ ${Object.entries(props).map(([key, def]) => {
|
|
4233
4317
|
const type = jsonSchemaToTSType(resolveDef(def));
|
|
4234
|
-
return `${key}${isRequiredProperty(key, def, required) ? "" : "?"}: ${type}`;
|
|
4318
|
+
return `${key}${isRequiredProperty$1(key, def, required) ? "" : "?"}: ${type}`;
|
|
4235
4319
|
}).join("; ")} }`;
|
|
4236
4320
|
}
|
|
4237
4321
|
function resolveDef(def) {
|
|
@@ -4262,7 +4346,7 @@ function eventsSchemaToTSType(events) {
|
|
|
4262
4346
|
const required = getRequiredKeys(schema);
|
|
4263
4347
|
const extraProps = Object.entries(props).filter(([k]) => k !== "type").map(([key, def]) => {
|
|
4264
4348
|
const type = jsonSchemaToTSType(resolveDef(def));
|
|
4265
|
-
return `${key}${isRequiredProperty(key, def, required) ? "" : "?"}: ${type}`;
|
|
4349
|
+
return `${key}${isRequiredProperty$1(key, def, required) ? "" : "?"}: ${type}`;
|
|
4266
4350
|
});
|
|
4267
4351
|
if (extraProps.length === 0) return `{ type: '${eventType}' }`;
|
|
4268
4352
|
return `{ type: '${eventType}'; ${extraProps.join("; ")} }`;
|
|
@@ -4271,13 +4355,138 @@ function eventsSchemaToTSType(events) {
|
|
|
4271
4355
|
function getRequiredKeys(schema) {
|
|
4272
4356
|
return new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
4273
4357
|
}
|
|
4274
|
-
function isRequiredProperty(key, def, required) {
|
|
4358
|
+
function isRequiredProperty$1(key, def, required) {
|
|
4275
4359
|
if (required.has(key)) return true;
|
|
4276
4360
|
return typeof def === "object" && def !== null && def.required === true;
|
|
4277
4361
|
}
|
|
4362
|
+
function jsonSchemaToZod(schema) {
|
|
4363
|
+
if (!schema) return "z.unknown()";
|
|
4364
|
+
if (schema.enum) return enumToZod(schema.enum);
|
|
4365
|
+
if (schema.const !== void 0) return `z.literal(${serializeJS(schema.const)})`;
|
|
4366
|
+
if (schema.oneOf) return xorToZod(schema.oneOf);
|
|
4367
|
+
if (schema.anyOf) return unionToZod(schema.anyOf);
|
|
4368
|
+
if (schema.allOf) {
|
|
4369
|
+
const schemas = schema.allOf.map(definitionToZod);
|
|
4370
|
+
if (schemas.length === 0) return "z.unknown()";
|
|
4371
|
+
return schemas.slice(1).reduce((result, next) => `z.intersection(${result}, ${next})`, schemas[0]);
|
|
4372
|
+
}
|
|
4373
|
+
if (Array.isArray(schema.type)) return unionToZod(schema.type.map((type) => ({
|
|
4374
|
+
...schema,
|
|
4375
|
+
type
|
|
4376
|
+
})));
|
|
4377
|
+
if (schema.type === "array") {
|
|
4378
|
+
const items = schema.items;
|
|
4379
|
+
let result;
|
|
4380
|
+
if (Array.isArray(items)) result = `z.tuple(${serializeJS(items.map((item) => raw(definitionToZod(item))))})`;
|
|
4381
|
+
else result = `z.array(${definitionToZod(items)})`;
|
|
4382
|
+
return applyArrayConstraints(result, schema);
|
|
4383
|
+
}
|
|
4384
|
+
if (schema.type === "object" || schema.properties) return objectToZod(schema);
|
|
4385
|
+
if (schema.type) return primitiveToZod(schema, schema.type);
|
|
4386
|
+
return "z.unknown()";
|
|
4387
|
+
}
|
|
4388
|
+
/** Build a required object schema from the graph's context property map. */
|
|
4389
|
+
function contextSchemaToZod(context) {
|
|
4390
|
+
if (!context || Object.keys(context).length === 0) return null;
|
|
4391
|
+
return `z.object(${serializeJS(Object.fromEntries(Object.entries(context).map(([key, schema]) => [key, raw(jsonSchemaToZod(schema))])))})`;
|
|
4392
|
+
}
|
|
4393
|
+
/** Build an event payload schema without duplicating the discriminant. */
|
|
4394
|
+
function eventSchemaToZod(schema) {
|
|
4395
|
+
const properties = schema.properties ?? {};
|
|
4396
|
+
const payloadProperties = Object.fromEntries(Object.entries(properties).filter(([key]) => key !== "type"));
|
|
4397
|
+
return jsonSchemaToZod({
|
|
4398
|
+
...schema,
|
|
4399
|
+
properties: payloadProperties,
|
|
4400
|
+
required: Array.isArray(schema.required) ? schema.required.filter((key) => key !== "type") : void 0
|
|
4401
|
+
});
|
|
4402
|
+
}
|
|
4403
|
+
function objectToZod(schema) {
|
|
4404
|
+
const properties = schema.properties ?? {};
|
|
4405
|
+
const required = new Set(Array.isArray(schema.required) ? schema.required : []);
|
|
4406
|
+
let result = `z.object(${serializeJS(Object.fromEntries(Object.entries(properties).map(([key, definition]) => {
|
|
4407
|
+
return [key, raw(`${definitionToZod(definition)}${isRequiredProperty(key, definition, required) ? "" : ".optional()"}`)];
|
|
4408
|
+
})))})`;
|
|
4409
|
+
if (schema.additionalProperties === false) result += ".strict()";
|
|
4410
|
+
else if (schema.additionalProperties === true || schema.additionalProperties === void 0) result += ".passthrough()";
|
|
4411
|
+
else if (schema.additionalProperties) result += `.catchall(${jsonSchemaToZod(schema.additionalProperties)})`;
|
|
4412
|
+
return result;
|
|
4413
|
+
}
|
|
4414
|
+
function primitiveToZod(schema, type) {
|
|
4415
|
+
let result;
|
|
4416
|
+
switch (type) {
|
|
4417
|
+
case "string":
|
|
4418
|
+
result = "z.string()";
|
|
4419
|
+
if (schema.format === "email") result += ".email()";
|
|
4420
|
+
if (schema.format === "uri" || schema.format === "url") result += ".url()";
|
|
4421
|
+
if (schema.format === "uuid") result += ".uuid()";
|
|
4422
|
+
if (schema.format === "date-time") result += ".datetime({ offset: true })";
|
|
4423
|
+
if (typeof schema.minLength === "number") result += `.min(${schema.minLength})`;
|
|
4424
|
+
if (typeof schema.maxLength === "number") result += `.max(${schema.maxLength})`;
|
|
4425
|
+
if (schema.pattern) result += `.regex(new RegExp(${serializeJS(schema.pattern)}))`;
|
|
4426
|
+
break;
|
|
4427
|
+
case "number":
|
|
4428
|
+
case "integer":
|
|
4429
|
+
result = "z.number()";
|
|
4430
|
+
if (type === "integer") result += ".int()";
|
|
4431
|
+
if (typeof schema.minimum === "number") result += `.min(${schema.minimum})`;
|
|
4432
|
+
if (typeof schema.maximum === "number") result += `.max(${schema.maximum})`;
|
|
4433
|
+
if (typeof schema.exclusiveMinimum === "number") result += `.gt(${schema.exclusiveMinimum})`;
|
|
4434
|
+
if (typeof schema.exclusiveMaximum === "number") result += `.lt(${schema.exclusiveMaximum})`;
|
|
4435
|
+
if (typeof schema.multipleOf === "number") result += `.multipleOf(${schema.multipleOf})`;
|
|
4436
|
+
break;
|
|
4437
|
+
case "boolean":
|
|
4438
|
+
result = "z.boolean()";
|
|
4439
|
+
break;
|
|
4440
|
+
case "null":
|
|
4441
|
+
result = "z.null()";
|
|
4442
|
+
break;
|
|
4443
|
+
case "object":
|
|
4444
|
+
result = objectToZod(schema);
|
|
4445
|
+
break;
|
|
4446
|
+
default:
|
|
4447
|
+
result = "z.unknown()";
|
|
4448
|
+
break;
|
|
4449
|
+
}
|
|
4450
|
+
if (schema.default !== void 0) result += `.default(${serializeJS(schema.default)})`;
|
|
4451
|
+
return result;
|
|
4452
|
+
}
|
|
4453
|
+
function applyArrayConstraints(result, schema) {
|
|
4454
|
+
if (typeof schema.minItems === "number") result += `.min(${schema.minItems})`;
|
|
4455
|
+
if (typeof schema.maxItems === "number") result += `.max(${schema.maxItems})`;
|
|
4456
|
+
return result;
|
|
4457
|
+
}
|
|
4458
|
+
function enumToZod(values) {
|
|
4459
|
+
if (values.length === 0) return "z.never()";
|
|
4460
|
+
if (values.every((value) => typeof value === "string")) {
|
|
4461
|
+
if (values.length === 1) return `z.literal(${serializeJS(values[0])})`;
|
|
4462
|
+
return `z.enum(${serializeJS(values)})`;
|
|
4463
|
+
}
|
|
4464
|
+
return unionToZod(values.map((value) => ({ const: value })));
|
|
4465
|
+
}
|
|
4466
|
+
function unionToZod(definitions) {
|
|
4467
|
+
const schemas = definitions.map(definitionToZod);
|
|
4468
|
+
if (schemas.length === 0) return "z.never()";
|
|
4469
|
+
if (schemas.length === 1) return schemas[0];
|
|
4470
|
+
return `z.union(${serializeJS(schemas.map((schema) => raw(schema)))})`;
|
|
4471
|
+
}
|
|
4472
|
+
function xorToZod(definitions) {
|
|
4473
|
+
const schemas = definitions.map(definitionToZod);
|
|
4474
|
+
if (schemas.length === 0) return "z.never()";
|
|
4475
|
+
if (schemas.length === 1) return schemas[0];
|
|
4476
|
+
return `z.xor(${serializeJS(schemas.map((schema) => raw(schema)))})`;
|
|
4477
|
+
}
|
|
4478
|
+
function definitionToZod(definition) {
|
|
4479
|
+
if (definition === false) return "z.never()";
|
|
4480
|
+
if (definition === true || definition === void 0) return "z.unknown()";
|
|
4481
|
+
return jsonSchemaToZod(definition);
|
|
4482
|
+
}
|
|
4483
|
+
function isRequiredProperty(key, definition, required) {
|
|
4484
|
+
if (required.has(key)) return true;
|
|
4485
|
+
return typeof definition === "object" && definition !== null && definition.required === true;
|
|
4486
|
+
}
|
|
4278
4487
|
function graphToXStateTS(graph, options = {}) {
|
|
4279
4488
|
const inferredXStateVersion = isXStateV6ProfileRef(graph.data.profile ?? "xstate-v5") ? 6 : 5;
|
|
4280
|
-
const { exportStyle = "named", targetLanguage = "typescript", xstateVersion = inferredXStateVersion, ...configOptions } = options;
|
|
4489
|
+
const { exportStyle = "named", targetLanguage = "typescript", xstateVersion = inferredXStateVersion, xstateV6SchemaFormat = "types", ...configOptions } = options;
|
|
4281
4490
|
const schemas = graph.data.schemas;
|
|
4282
4491
|
const impls = filterInlineImplementations(graph.data.implementations);
|
|
4283
4492
|
const supportsTypeSyntax = targetLanguage === "typescript";
|
|
@@ -4286,10 +4495,11 @@ function graphToXStateTS(graph, options = {}) {
|
|
|
4286
4495
|
const hasGuards = !!impls?.guards.length;
|
|
4287
4496
|
const hasActors = !!impls?.actors.length;
|
|
4288
4497
|
const hasDelays = !!impls?.delays.length;
|
|
4289
|
-
const hasSetup = hasSchemas || hasActions || hasGuards || hasActors || hasDelays;
|
|
4498
|
+
const hasSetup = xstateVersion === 6 || hasSchemas || hasActions || hasGuards || hasActors || hasDelays;
|
|
4290
4499
|
const builtInActions = getUsedBuiltInActions(graph, xstateVersion);
|
|
4291
4500
|
const actorSourceImports = getActorSourceImports(graph);
|
|
4292
4501
|
const implementationImports = getImplementationImports(impls);
|
|
4502
|
+
const codeImports = getCodeExpressionImports(graph);
|
|
4293
4503
|
const imports = buildImports({
|
|
4294
4504
|
hasSetup,
|
|
4295
4505
|
hasActors,
|
|
@@ -4297,14 +4507,18 @@ function graphToXStateTS(graph, options = {}) {
|
|
|
4297
4507
|
builtInActions,
|
|
4298
4508
|
actorSourceImports,
|
|
4299
4509
|
implementationImports,
|
|
4300
|
-
|
|
4510
|
+
codeImports,
|
|
4511
|
+
xstateVersion,
|
|
4512
|
+
usesTypes: xstateVersion === 6 && supportsTypeSyntax && hasSchemas && xstateV6SchemaFormat === "types",
|
|
4513
|
+
usesZod: xstateVersion === 6 && hasSchemas && xstateV6SchemaFormat === "zod"
|
|
4301
4514
|
});
|
|
4302
4515
|
const machineConfig = xstateVersion === 6 ? toV6MachineConfig(graphToMachineConfig(graph, configOptions)) : toV5MachineConfig(graphToMachineConfig(graph, configOptions));
|
|
4303
4516
|
let machineExpr;
|
|
4304
4517
|
if (hasSetup) {
|
|
4305
4518
|
const setupObj = buildSetupObject(schemas, impls, {
|
|
4306
4519
|
includeTypeSyntax: supportsTypeSyntax,
|
|
4307
|
-
xstateVersion
|
|
4520
|
+
xstateVersion,
|
|
4521
|
+
xstateV6SchemaFormat
|
|
4308
4522
|
});
|
|
4309
4523
|
const configStr = serializeJS(machineConfig, 2);
|
|
4310
4524
|
machineExpr = `setup(${serializeJS(setupObj, 0)}).createMachine(${configStr})`;
|
|
@@ -4408,7 +4622,9 @@ function toV6TransitionValue(value) {
|
|
|
4408
4622
|
if (Array.isArray(value)) return buildV6TransitionFunction(value) ?? value.map((item) => toV6TransitionValue(item));
|
|
4409
4623
|
if (!value || typeof value !== "object") return value;
|
|
4410
4624
|
const transition = value;
|
|
4411
|
-
if (transition.
|
|
4625
|
+
if (transition.matches !== void 0) return buildV6TransitionFunction([transition]) ?? mapV6MachineConfig(transition);
|
|
4626
|
+
if (transition.guard) return buildV6TransitionFunction([transition]) ?? mapV6MachineConfig(transition);
|
|
4627
|
+
if (transition.description || transition.input !== void 0) return mapV6MachineConfig(transition);
|
|
4412
4628
|
const target = transition.target;
|
|
4413
4629
|
const context = transition.context;
|
|
4414
4630
|
const actionsValue = transition.actions;
|
|
@@ -4424,7 +4640,20 @@ function toV6TransitionValue(value) {
|
|
|
4424
4640
|
}
|
|
4425
4641
|
function guardCondition(value) {
|
|
4426
4642
|
const expression = inlineExpr(value);
|
|
4427
|
-
if (!expression)
|
|
4643
|
+
if (!expression) {
|
|
4644
|
+
if (value === void 0) return { condition: "true" };
|
|
4645
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
4646
|
+
const guard = value;
|
|
4647
|
+
if (typeof guard.type === "string") {
|
|
4648
|
+
const params = guard.params === void 0 ? "" : `, ${serializeJS(guard.params)}`;
|
|
4649
|
+
return {
|
|
4650
|
+
condition: `guards[${serializeJS(guard.type)}]({ context, event }${params})`,
|
|
4651
|
+
firstParam: "{ context, event, guards }"
|
|
4652
|
+
};
|
|
4653
|
+
}
|
|
4654
|
+
}
|
|
4655
|
+
return null;
|
|
4656
|
+
}
|
|
4428
4657
|
const arrow = expression.indexOf("=>");
|
|
4429
4658
|
if (arrow < 0) return null;
|
|
4430
4659
|
const params = expression.slice(0, arrow).trim();
|
|
@@ -4432,13 +4661,28 @@ function guardCondition(value) {
|
|
|
4432
4661
|
if (body.startsWith("{")) return null;
|
|
4433
4662
|
return {
|
|
4434
4663
|
condition: body,
|
|
4664
|
+
callCondition: `(${expression})({ context, event, input, output, actions, guards, children, self, system })`,
|
|
4435
4665
|
firstParam: params.startsWith("(") && params.endsWith(")") ? params.slice(1, -1).trim() : params
|
|
4436
4666
|
};
|
|
4437
4667
|
}
|
|
4668
|
+
function matchesCondition(value) {
|
|
4669
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
4670
|
+
const entries = Object.entries(value);
|
|
4671
|
+
if (entries.length === 0) return "true";
|
|
4672
|
+
return entries.map(([key, expected]) => `Object.is(event[${serializeJS(key)}], ${serializeJS(expected)})`).join(" && ");
|
|
4673
|
+
}
|
|
4674
|
+
function combineConditions(match, guard) {
|
|
4675
|
+
if (!match || match === "true") return guard;
|
|
4676
|
+
if (guard === "true") return match;
|
|
4677
|
+
return `${match} && (${guard})`;
|
|
4678
|
+
}
|
|
4438
4679
|
const V6_ARG_BINDINGS = [
|
|
4439
4680
|
"context",
|
|
4440
4681
|
"event",
|
|
4682
|
+
"input",
|
|
4683
|
+
"output",
|
|
4441
4684
|
"actions",
|
|
4685
|
+
"guards",
|
|
4442
4686
|
"children",
|
|
4443
4687
|
"self",
|
|
4444
4688
|
"system"
|
|
@@ -4527,7 +4771,8 @@ function buildV6TransitionFunction(transitions) {
|
|
|
4527
4771
|
for (const item of transitions) {
|
|
4528
4772
|
if (!item || typeof item !== "object" || Array.isArray(item)) return;
|
|
4529
4773
|
const transition = item;
|
|
4530
|
-
|
|
4774
|
+
const match = transition.matches === void 0 ? void 0 : matchesCondition(transition.matches);
|
|
4775
|
+
if (match === null) return;
|
|
4531
4776
|
const guard = guardCondition(transition.guard);
|
|
4532
4777
|
if (!guard) return;
|
|
4533
4778
|
if (guard.firstParam) {
|
|
@@ -4538,25 +4783,35 @@ function buildV6TransitionFunction(transitions) {
|
|
|
4538
4783
|
const effects = (Array.isArray(actionValue) ? actionValue : actionValue === void 0 ? [] : [actionValue]).map(actionToV6Effect);
|
|
4539
4784
|
if (effects.some((effect) => !effect)) return;
|
|
4540
4785
|
const rendered = renderV6Effects(effects.filter((effect) => Boolean(effect)), transition.context === void 0 ? void 0 : serializeJS(unwrapTemplateExpressions(transition.context)));
|
|
4541
|
-
const
|
|
4786
|
+
const effectiveReturnValue = buildV6TransitionReturnValue({
|
|
4542
4787
|
target: typeof transition.target === "string" ? transition.target : void 0,
|
|
4543
4788
|
reenter: transition.reenter === true,
|
|
4544
|
-
meta: transition.meta
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
const body = [...rendered.statements.map(formatV6Statement), `return ${
|
|
4789
|
+
meta: transition.meta,
|
|
4790
|
+
input: transition.input
|
|
4791
|
+
}, rendered.contextValue) ?? "{}";
|
|
4792
|
+
const body = [...rendered.statements.map(formatV6Statement), `return ${effectiveReturnValue};`];
|
|
4548
4793
|
if (body.length === 0) return;
|
|
4549
4794
|
branches.push({
|
|
4550
|
-
condition: guard.condition,
|
|
4795
|
+
condition: combineConditions(match, guard.condition),
|
|
4796
|
+
callCondition: guard.callCondition ? combineConditions(match, guard.callCondition) : void 0,
|
|
4551
4797
|
body
|
|
4552
4798
|
});
|
|
4553
4799
|
}
|
|
4554
4800
|
if (branches.length === 0) return;
|
|
4555
|
-
const generated = branches.flatMap((branch) => branch.body).join("\n");
|
|
4556
|
-
|
|
4801
|
+
const generated = branches.flatMap((branch) => [branch.condition, ...branch.body]).join("\n");
|
|
4802
|
+
let renderedBranches = branches;
|
|
4803
|
+
let merged = mergeV6FirstParam(authoredFirstParam, inferV6ArgBindings(generated));
|
|
4804
|
+
if (!merged) {
|
|
4805
|
+
if (branches.some((branch) => !branch.callCondition)) return;
|
|
4806
|
+
renderedBranches = branches.map((branch) => ({
|
|
4807
|
+
...branch,
|
|
4808
|
+
condition: branch.callCondition
|
|
4809
|
+
}));
|
|
4810
|
+
merged = mergeV6FirstParam(void 0, inferV6ArgBindings(`${renderedBranches.map((branch) => branch.condition).join("\n")}\n${generated}`));
|
|
4811
|
+
}
|
|
4557
4812
|
if (!merged) return;
|
|
4558
4813
|
const lines = merged.prelude.map((statement) => ` ${statement}`);
|
|
4559
|
-
for (const branch of
|
|
4814
|
+
for (const branch of renderedBranches) if (branch.condition === "true") lines.push(...branch.body.map((line) => ` ${line}`));
|
|
4560
4815
|
else {
|
|
4561
4816
|
lines.push(` if (${branch.condition}) {`);
|
|
4562
4817
|
lines.push(...branch.body.map((line) => ` ${line}`));
|
|
@@ -4612,12 +4867,13 @@ function unwrapTemplateExpressions(value) {
|
|
|
4612
4867
|
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, unwrapTemplateExpressions(item)]));
|
|
4613
4868
|
}
|
|
4614
4869
|
function buildV6TransitionReturnValue(transition, contextValue) {
|
|
4615
|
-
if (!transition.reenter && !transition.meta && !contextValue) return transition.target ? `{ target: ${serializeJS(transition.target)} }` : void 0;
|
|
4870
|
+
if (!transition.reenter && !transition.meta && !contextValue && transition.input === void 0) return transition.target ? `{ target: ${serializeJS(transition.target)} }` : void 0;
|
|
4616
4871
|
return serializeJS({
|
|
4617
4872
|
target: transition.target,
|
|
4618
4873
|
reenter: transition.reenter ? true : void 0,
|
|
4619
4874
|
meta: transition.meta,
|
|
4620
|
-
context: contextValue ? raw(contextValue) : void 0
|
|
4875
|
+
context: contextValue ? raw(contextValue) : void 0,
|
|
4876
|
+
input: transition.input === void 0 ? void 0 : unwrapTemplateExpressions(transition.input)
|
|
4621
4877
|
});
|
|
4622
4878
|
}
|
|
4623
4879
|
function mapMachineActionFields(value, mapActions) {
|
|
@@ -4740,7 +4996,7 @@ function actionOptions(params, consumedKeys) {
|
|
|
4740
4996
|
const rest = Object.fromEntries(Object.entries(params).filter(([key, value]) => !consumedKeys.includes(key) && value !== void 0));
|
|
4741
4997
|
return Object.keys(rest).length ? `, ${serializeJS(rest)}` : "";
|
|
4742
4998
|
}
|
|
4743
|
-
function buildImports({ hasSetup, hasActors, actors, builtInActions, actorSourceImports, implementationImports, usesTypes }) {
|
|
4999
|
+
function buildImports({ hasSetup, hasActors, actors, builtInActions, actorSourceImports, implementationImports, codeImports, xstateVersion, usesTypes, usesZod }) {
|
|
4744
5000
|
const xstateImports = [];
|
|
4745
5001
|
if (hasSetup) xstateImports.push("setup");
|
|
4746
5002
|
else xstateImports.push("createMachine");
|
|
@@ -4749,9 +5005,51 @@ function buildImports({ hasSetup, hasActors, actors, builtInActions, actorSource
|
|
|
4749
5005
|
for (const name of implementationImports) xstateImports.push(name);
|
|
4750
5006
|
if (usesTypes) xstateImports.push("types");
|
|
4751
5007
|
if (hasActors) {
|
|
4752
|
-
if (actors.length > 0) xstateImports.push("fromPromise");
|
|
5008
|
+
if (actors.length > 0) xstateImports.push(xstateVersion === 6 ? "createAsyncLogic" : "fromPromise");
|
|
5009
|
+
}
|
|
5010
|
+
const externalImports = /* @__PURE__ */ new Map();
|
|
5011
|
+
for (const codeImport of codeImports) {
|
|
5012
|
+
const specifier = codeImport.local && codeImport.local !== codeImport.import ? `${codeImport.import} as ${codeImport.local}` : codeImport.import;
|
|
5013
|
+
if (codeImport.package === "xstate") {
|
|
5014
|
+
if ((codeImport.importKind ?? "named") === "named") xstateImports.push(specifier);
|
|
5015
|
+
continue;
|
|
5016
|
+
}
|
|
5017
|
+
if ((codeImport.importKind ?? "named") !== "named") continue;
|
|
5018
|
+
const names = externalImports.get(codeImport.package) ?? /* @__PURE__ */ new Set();
|
|
5019
|
+
names.add(specifier);
|
|
5020
|
+
externalImports.set(codeImport.package, names);
|
|
5021
|
+
}
|
|
5022
|
+
const imports = [`import { ${[...new Set(xstateImports)].join(", ")} } from 'xstate';`];
|
|
5023
|
+
for (const [packageName, names] of externalImports) imports.push(`import { ${[...names].sort().join(", ")} } from '${packageName}';`);
|
|
5024
|
+
if (usesZod && !externalImports.get("zod")?.has("z")) imports.push("import { z } from 'zod';");
|
|
5025
|
+
return imports.join("\n");
|
|
5026
|
+
}
|
|
5027
|
+
function getCodeExpressionImports(graph) {
|
|
5028
|
+
const imports = /* @__PURE__ */ new Map();
|
|
5029
|
+
function visit(value) {
|
|
5030
|
+
if (!value || typeof value !== "object") return;
|
|
5031
|
+
if (Array.isArray(value)) {
|
|
5032
|
+
value.forEach(visit);
|
|
5033
|
+
return;
|
|
5034
|
+
}
|
|
5035
|
+
const record = value;
|
|
5036
|
+
if (Array.isArray(record.imports)) for (const item of record.imports) {
|
|
5037
|
+
if (!item || typeof item !== "object") continue;
|
|
5038
|
+
const candidate = item;
|
|
5039
|
+
if (typeof candidate.package !== "string" || typeof candidate.import !== "string") continue;
|
|
5040
|
+
const key = `${candidate.package}:${candidate.import}:${candidate.local ?? ""}:${candidate.importKind ?? "named"}`;
|
|
5041
|
+
imports.set(key, {
|
|
5042
|
+
package: candidate.package,
|
|
5043
|
+
import: candidate.import,
|
|
5044
|
+
local: candidate.local,
|
|
5045
|
+
importKind: candidate.importKind,
|
|
5046
|
+
version: candidate.version
|
|
5047
|
+
});
|
|
5048
|
+
}
|
|
5049
|
+
Object.values(record).forEach(visit);
|
|
4753
5050
|
}
|
|
4754
|
-
|
|
5051
|
+
visit(graph);
|
|
5052
|
+
return [...imports.values()];
|
|
4755
5053
|
}
|
|
4756
5054
|
const XSTATE_ACTOR_LOGIC_HELPERS = new Set([
|
|
4757
5055
|
"createMachine",
|
|
@@ -4814,7 +5112,10 @@ function buildSetupObject(schemas, impls, options) {
|
|
|
4814
5112
|
}
|
|
4815
5113
|
if (impls?.actions.length) setup.actions = buildActionsBlock(impls.actions, options);
|
|
4816
5114
|
if (impls?.guards.length) setup.guards = buildGuardsBlock(impls.guards, options);
|
|
4817
|
-
if (impls?.actors.length) setup.actors = buildActorsBlock(impls.actors,
|
|
5115
|
+
if (impls?.actors.length) setup.actors = buildActorsBlock(impls.actors, {
|
|
5116
|
+
...options,
|
|
5117
|
+
xstateVersion: options.xstateVersion
|
|
5118
|
+
});
|
|
4818
5119
|
if (impls?.delays.length) setup.delays = buildDelaysBlock(impls.delays);
|
|
4819
5120
|
return setup;
|
|
4820
5121
|
}
|
|
@@ -4830,7 +5131,9 @@ function buildTypesBlock(schemas, options) {
|
|
|
4830
5131
|
return Object.keys(types).length > 0 ? types : void 0;
|
|
4831
5132
|
}
|
|
4832
5133
|
function buildV6SchemasBlock(schemas, options) {
|
|
4833
|
-
if (!schemas
|
|
5134
|
+
if (!schemas) return void 0;
|
|
5135
|
+
if (options.xstateV6SchemaFormat === "zod") return buildV6ZodSchemasBlock(schemas);
|
|
5136
|
+
if (!options.includeTypeSyntax) return void 0;
|
|
4834
5137
|
const result = {};
|
|
4835
5138
|
const contextType = contextSchemaToTSType(schemas.context);
|
|
4836
5139
|
if (contextType) result.context = raw(`types<${contextType}>()`);
|
|
@@ -4839,6 +5142,16 @@ function buildV6SchemasBlock(schemas, options) {
|
|
|
4839
5142
|
if (schemas.output) result.output = raw(`types<${jsonSchemaToTSType(schemas.output)}>()`);
|
|
4840
5143
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
4841
5144
|
}
|
|
5145
|
+
function buildV6ZodSchemasBlock(schemas) {
|
|
5146
|
+
if (!schemas) return void 0;
|
|
5147
|
+
const result = {};
|
|
5148
|
+
const contextSchema = contextSchemaToZod(schemas.context);
|
|
5149
|
+
if (contextSchema) result.context = raw(contextSchema);
|
|
5150
|
+
if (schemas.events && Object.keys(schemas.events).length > 0) result.events = Object.fromEntries(Object.entries(schemas.events).map(([eventType, schema]) => [eventType, raw(eventSchemaToZod(schema))]));
|
|
5151
|
+
if (schemas.input) result.input = raw(jsonSchemaToZod(schemas.input));
|
|
5152
|
+
if (schemas.output) result.output = raw(jsonSchemaToZod(schemas.output));
|
|
5153
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
5154
|
+
}
|
|
4842
5155
|
function eventPayloadSchemaToTSType(schema) {
|
|
4843
5156
|
const props = schema.properties ?? {};
|
|
4844
5157
|
const payloadProps = Object.fromEntries(Object.entries(props).filter(([key]) => key !== "type"));
|
|
@@ -4885,6 +5198,7 @@ function buildGuardsBlock(guards, options) {
|
|
|
4885
5198
|
}
|
|
4886
5199
|
function buildActorsBlock(actors, options) {
|
|
4887
5200
|
const block = {};
|
|
5201
|
+
const actorFactory = options.xstateVersion === 6 ? "createAsyncLogic" : "fromPromise";
|
|
4888
5202
|
for (const actor of actors) if (actor.code?.body) {
|
|
4889
5203
|
const inlineExpression = getActorLogicExpression(actor.code.body);
|
|
4890
5204
|
if (inlineExpression) {
|
|
@@ -4893,12 +5207,12 @@ function buildActorsBlock(actors, options) {
|
|
|
4893
5207
|
}
|
|
4894
5208
|
const functionExpression = stripExportDefault(actor.code.body);
|
|
4895
5209
|
if (isCompleteFunctionExpression(functionExpression)) {
|
|
4896
|
-
block[actor.name] = raw(`
|
|
5210
|
+
block[actor.name] = raw(options.xstateVersion === 6 ? `${actorFactory}({ run: ${functionExpression} })` : `${actorFactory}(${functionExpression})`);
|
|
4897
5211
|
continue;
|
|
4898
5212
|
}
|
|
4899
5213
|
const inputType = options.includeTypeSyntax && hasSchemaProperties(actor.inputSchema) ? `: ${jsonSchemaToTSType(actor.inputSchema)}` : "";
|
|
4900
|
-
block[actor.name] = raw(`
|
|
4901
|
-
} else block[actor.name] = raw(`
|
|
5214
|
+
block[actor.name] = raw(options.xstateVersion === 6 ? `${actorFactory}({ run: async ({ input }${inputType ? `: { input${inputType} }` : ""}) => {\n ${dedent(actor.code.body)}\n} })` : `${actorFactory}(async ({ input }${inputType ? `: { input${inputType} }` : ""}) => {\n ${dedent(actor.code.body)}\n})`);
|
|
5215
|
+
} else block[actor.name] = raw(options.xstateVersion === 6 ? `${actorFactory}({ run: async ({ input }) => {\n // TODO: implement ${actor.name}\n} })` : `${actorFactory}(async ({ input }) => {\n // TODO: implement ${actor.name}\n})`);
|
|
4902
5216
|
return block;
|
|
4903
5217
|
}
|
|
4904
5218
|
function getActorLogicExpression(code) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as output, C as ZodNumber, D as ZodString, E as ZodRecord, O as ZodUnion, S as ZodNullable, T as ZodOptional, b as ZodEnum, j as $strip, k as ZodUnknown, w as ZodObject, x as ZodLiteral, y as ZodArray } from "./index-
|
|
1
|
+
import { A as output, C as ZodNumber, D as ZodString, E as ZodRecord, O as ZodUnion, S as ZodNullable, T as ZodOptional, b as ZodEnum, j as $strip, k as ZodUnknown, w as ZodObject, x as ZodLiteral, y as ZodArray } from "./index-DuvCSThi.mjs";
|
|
2
2
|
import { n as StatelyCredential, t as StatelyAuthMode } from "./auth-B0ZTKri2.mjs";
|
|
3
3
|
|
|
4
4
|
//#region ../api-contract/dist/errors.d.mts
|
package/dist/studio.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { A as Machine, C as StudioMachineRecord, D as VerifyApiKeyResponse, E as UpdateProjectInput, F as ProjectVisibility, I as VerifyResult, L as XStateVersion, M as Project, N as ProjectMachineSummary, O as createStatelyClient, P as ProjectSummary, R as ResourceErrorCode, S as StudioClientOptions, T as UpdateMachineInput, _ as ProjectMachine, a as CreateMachineTemplate, b as StudioApiErrorOptions, c as EnsureProjectInput, d as ExtractedMachine, f as GetMachineOptions, g as ProjectData, h as LegacyUpdateMachineInput, i as CreateMachineInput, j as MachineVersion, k as ExtractedMachines, l as ExtractMachinesInput, m as LegacyProjectVisibility, n as CreateMachineFromDefinitionInput, o as CreateProjectInput, p as LegacyExtractMachinesOptions, r as CreateMachineFromTemplateInput, s as DEFAULT_STATELY_BASE_URL, t as ConnectedRepo, u as ExtractMachinesResponse, v as RepoType, w as StudioRequestOptions, x as StudioClient, y as StudioApiError } from "./studio-
|
|
1
|
+
import { A as Machine, C as StudioMachineRecord, D as VerifyApiKeyResponse, E as UpdateProjectInput, F as ProjectVisibility, I as VerifyResult, L as XStateVersion, M as Project, N as ProjectMachineSummary, O as createStatelyClient, P as ProjectSummary, R as ResourceErrorCode, S as StudioClientOptions, T as UpdateMachineInput, _ as ProjectMachine, a as CreateMachineTemplate, b as StudioApiErrorOptions, c as EnsureProjectInput, d as ExtractedMachine, f as GetMachineOptions, g as ProjectData, h as LegacyUpdateMachineInput, i as CreateMachineInput, j as MachineVersion, k as ExtractedMachines, l as ExtractMachinesInput, m as LegacyProjectVisibility, n as CreateMachineFromDefinitionInput, o as CreateProjectInput, p as LegacyExtractMachinesOptions, r as CreateMachineFromTemplateInput, s as DEFAULT_STATELY_BASE_URL, t as ConnectedRepo, u as ExtractMachinesResponse, v as RepoType, w as StudioRequestOptions, x as StudioClient, y as StudioApiError } from "./studio-erXbdakn.mjs";
|
|
2
2
|
export { ConnectedRepo, CreateMachineFromDefinitionInput, CreateMachineFromTemplateInput, CreateMachineInput, CreateMachineTemplate, CreateProjectInput, DEFAULT_STATELY_BASE_URL, EnsureProjectInput, ExtractMachinesInput, ExtractMachinesResponse, ExtractedMachine, ExtractedMachines, GetMachineOptions, LegacyExtractMachinesOptions, LegacyProjectVisibility, LegacyUpdateMachineInput, Machine, MachineVersion, Project, ProjectData, ProjectMachine, ProjectMachineSummary, ProjectSummary, ProjectVisibility, RepoType, ResourceErrorCode, StudioApiError, StudioApiErrorOptions, StudioClient, StudioClientOptions, StudioMachineRecord, StudioRequestOptions, UpdateMachineInput, UpdateProjectInput, VerifyApiKeyResponse, VerifyResult, XStateVersion, createStatelyClient };
|
package/dist/sync.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { b as DigraphConfig, i as StatelyGraph } from "./graph-
|
|
2
|
-
import { C as StudioMachineRecord, L as XStateVersion, g as ProjectData, o as CreateProjectInput, x as StudioClient } from "./studio-
|
|
1
|
+
import { b as DigraphConfig, i as StatelyGraph } from "./graph-BGUND7ZF.mjs";
|
|
2
|
+
import { C as StudioMachineRecord, L as XStateVersion, g as ProjectData, o as CreateProjectInput, x as StudioClient } from "./studio-erXbdakn.mjs";
|
|
3
3
|
import { GraphDiff } from "@statelyai/graph";
|
|
4
4
|
|
|
5
5
|
//#region src/sync.d.ts
|
package/dist/sync.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./openapi-BTDjYWXd.mjs";
|
|
2
2
|
import { r as createStatelyClient } from "./studio-iNSHtNmP.mjs";
|
|
3
|
-
import { f as normalizeMachineProfile, h as xstateSourceToConfig, i as INLINE_EXPRESSION_DIRECTIVE_FIELDS, m as serializeJS, n as getStatelyPragma, r as upsertStatelyPragma, s as detectXStateSourceProfile, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-
|
|
3
|
+
import { f as normalizeMachineProfile, h as xstateSourceToConfig, i as INLINE_EXPRESSION_DIRECTIVE_FIELDS, m as serializeJS, n as getStatelyPragma, r as upsertStatelyPragma, s as detectXStateSourceProfile, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-B-axv279.mjs";
|
|
4
4
|
import { fromStudioMachine, toStudioMachine } from "./graph.mjs";
|
|
5
5
|
import * as ts$1 from "typescript";
|
|
6
6
|
import ts from "typescript";
|
|
@@ -333,7 +333,7 @@ function createWebSocketTransport(options) {
|
|
|
333
333
|
|
|
334
334
|
//#endregion
|
|
335
335
|
//#region src/version.ts
|
|
336
|
-
const SDK_VERSION = "0.
|
|
336
|
+
const SDK_VERSION = "0.25.0";
|
|
337
337
|
function inspectionRuntime() {
|
|
338
338
|
if (typeof window !== "undefined") return "browser";
|
|
339
339
|
if (typeof process !== "undefined" && process.versions?.node) return "node";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"stately-sdk": "./dist/bin.mjs"
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"jsdom": "^27.4.0",
|
|
94
94
|
"tsdown": "0.21.0-beta.2",
|
|
95
95
|
"vitest": "^3.2.4",
|
|
96
|
-
"@statelyai/api-contract": "0.3.
|
|
97
|
-
"@statelyai/graph-tools": "0.
|
|
96
|
+
"@statelyai/api-contract": "0.3.9",
|
|
97
|
+
"@statelyai/graph-tools": "0.3.0"
|
|
98
98
|
},
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=22.4"
|