@statelyai/sdk 0.6.0 → 0.7.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 +68 -16
- package/dist/assetStorage.d.mts +73 -0
- package/dist/assetStorage.mjs +99 -0
- package/dist/cli.d.mts +34 -9
- package/dist/cli.mjs +327 -23
- package/dist/embed.d.mts +9 -2
- package/dist/embed.mjs +14 -8
- package/dist/graph.d.mts +1 -1
- package/dist/graph.mjs +9 -5
- package/dist/graphToXStateTS-Gzh0ZqbN.mjs +709 -0
- package/dist/index.d.mts +142 -7
- package/dist/index.mjs +4 -3
- package/dist/{inspect-DIxB2Tr3.d.mts → inspect-Bg9FTvb3.d.mts} +1 -1
- package/dist/inspect.d.mts +2 -2
- package/dist/inspect.mjs +1 -1
- package/dist/{protocol-CEbWQPYe.d.mts → protocol-DN4mH4jR.d.mts} +1 -2
- package/dist/studio.d.mts +7 -1
- package/dist/studio.mjs +7 -0
- package/dist/sync.d.mts +20 -2
- package/dist/sync.mjs +99 -7
- package/dist/{transport-C0eTgNNu.mjs → transport-C8UTS3Fa.mjs} +1 -1
- package/package.json +9 -4
- package/schemas/statelyai.schema.json +1 -1
- package/schemas/xstate-json.schema.json +214 -0
- package/dist/graphToXStateTS-CvXM8wHL.mjs +0 -344
- /package/dist/{graph-CB-ALrdk.d.mts → graph-DpBGHZwl.d.mts} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { StatelyApiClientOptions, StatelyApiError, StatelyApiUrlOptions, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
2
|
+
import { a as EmbedMode, c as ExportFormatMap, f as ProjectEmbedMachine, i as EmbedEventName, l as InitOptions, m as UploadResult, n as EmbedEventHandler, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat, t as CommentsConfig } from "./protocol-DN4mH4jR.mjs";
|
|
3
|
+
import { AssetUploadAdapter, AssetUploadContext, AssetUploadRequest, CreateS3AssetUploadAdapterOptions, CreateSupabaseAssetUploadAdapterOptions, S3UploadTarget, SupabaseStorageClient, createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
|
|
4
|
+
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";
|
|
5
|
+
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-DpBGHZwl.mjs";
|
|
6
|
+
import { PlanSyncOptions, PullSyncResult, PushLocalMachineLinksResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary } from "./sync.mjs";
|
|
6
7
|
import { AssetConfig, StatelyEmbed, StatelyEmbedOptions, createStatelyEmbed } from "./embed.mjs";
|
|
7
|
-
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-
|
|
8
|
+
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-Bg9FTvb3.mjs";
|
|
8
9
|
import { ActionLocation, GraphPatch } from "./patchTypes.mjs";
|
|
9
|
-
import { CodeGenGraph, MachineConfigOptions, RawCode, graphToMachineConfig, raw, serializeJS } from "@statelyai/graph-tools";
|
|
10
10
|
import { JSONSchema7 } from "json-schema";
|
|
11
|
+
import { UnknownMachineConfig } from "xstate";
|
|
11
12
|
|
|
12
13
|
//#region src/statelyPragma.d.ts
|
|
13
14
|
interface StatelyPragma {
|
|
@@ -31,12 +32,146 @@ declare function findStatelyPragmaAttachments(sourceText: string, fileName?: str
|
|
|
31
32
|
declare function getStatelyPragma(sourceText: string, fileName?: string, machineIndex?: number): StatelyPragma | undefined;
|
|
32
33
|
declare function upsertStatelyPragma(sourceText: string, id: string, options?: UpsertStatelyPragmaOptions): string;
|
|
33
34
|
//#endregion
|
|
35
|
+
//#region ../graph-tools/src/codegenTypes.d.ts
|
|
36
|
+
interface CodeGenAction {
|
|
37
|
+
type: string;
|
|
38
|
+
params?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
interface CodeGenGuard {
|
|
41
|
+
type: string;
|
|
42
|
+
code?: string;
|
|
43
|
+
params?: Record<string, unknown>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Serialized inline expression directive.
|
|
47
|
+
*
|
|
48
|
+
* Code generation treats this object as JavaScript/TypeScript source, not as a
|
|
49
|
+
* machine config object. It is used for fields such as invoke `input` and
|
|
50
|
+
* `output` where XState accepts mapper expressions.
|
|
51
|
+
*/
|
|
52
|
+
interface CodeExpression {
|
|
53
|
+
'@type': 'code';
|
|
54
|
+
lang: 'js' | 'ts';
|
|
55
|
+
expr: string;
|
|
56
|
+
}
|
|
57
|
+
interface CodeGenInvoke {
|
|
58
|
+
src: string;
|
|
59
|
+
id: string;
|
|
60
|
+
input?: Record<string, unknown> | CodeExpression;
|
|
61
|
+
output?: Record<string, unknown> | CodeExpression;
|
|
62
|
+
}
|
|
63
|
+
interface CodeGenNodeData {
|
|
64
|
+
nodeId?: string | null;
|
|
65
|
+
key: string;
|
|
66
|
+
type?: 'normal' | 'parallel' | 'final' | 'history' | null;
|
|
67
|
+
initialId?: string | null;
|
|
68
|
+
history?: 'shallow' | 'deep' | boolean;
|
|
69
|
+
entry?: CodeGenAction[];
|
|
70
|
+
exit?: CodeGenAction[];
|
|
71
|
+
invokes?: CodeGenInvoke[];
|
|
72
|
+
tags?: Array<string | {
|
|
73
|
+
name: string;
|
|
74
|
+
}>;
|
|
75
|
+
description?: string | null;
|
|
76
|
+
meta?: Record<string, unknown> | null;
|
|
77
|
+
color?: string;
|
|
78
|
+
parentId?: string | null;
|
|
79
|
+
temp?: boolean;
|
|
80
|
+
}
|
|
81
|
+
interface CodeGenEdgeData {
|
|
82
|
+
eventType: string;
|
|
83
|
+
transitionType?: 'normal' | 'targetless' | 'reenter';
|
|
84
|
+
guard?: CodeGenGuard | null;
|
|
85
|
+
actions?: CodeGenAction[];
|
|
86
|
+
description?: string | null;
|
|
87
|
+
color?: string;
|
|
88
|
+
meta?: Record<string, unknown> | null;
|
|
89
|
+
temp?: boolean;
|
|
90
|
+
}
|
|
91
|
+
interface CodeGenImplementation {
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
description?: string | null;
|
|
95
|
+
icon?: string;
|
|
96
|
+
paramsSchema?: JSONSchema7 | null;
|
|
97
|
+
code?: {
|
|
98
|
+
body: string;
|
|
99
|
+
lang?: string;
|
|
100
|
+
} | null;
|
|
101
|
+
}
|
|
102
|
+
interface CodeGenActorImplementation {
|
|
103
|
+
id: string;
|
|
104
|
+
name: string;
|
|
105
|
+
description?: string | null;
|
|
106
|
+
icon?: string;
|
|
107
|
+
inputSchema?: JSONSchema7 | null;
|
|
108
|
+
outputSchema?: JSONSchema7 | null;
|
|
109
|
+
code?: {
|
|
110
|
+
body: string;
|
|
111
|
+
lang?: string;
|
|
112
|
+
} | null;
|
|
113
|
+
}
|
|
114
|
+
interface CodeGenGraphData {
|
|
115
|
+
schemas?: {
|
|
116
|
+
context?: Record<string, JSONSchema7> | null;
|
|
117
|
+
events?: Record<string, JSONSchema7> | null;
|
|
118
|
+
input?: JSONSchema7 | null;
|
|
119
|
+
output?: JSONSchema7 | null;
|
|
120
|
+
} | null;
|
|
121
|
+
implementations?: {
|
|
122
|
+
actions: CodeGenImplementation[];
|
|
123
|
+
guards: CodeGenImplementation[];
|
|
124
|
+
actors: CodeGenActorImplementation[];
|
|
125
|
+
delays: CodeGenImplementation[];
|
|
126
|
+
} | null;
|
|
127
|
+
}
|
|
128
|
+
interface CodeGenNode {
|
|
129
|
+
id: string;
|
|
130
|
+
parentId?: string | null;
|
|
131
|
+
data: CodeGenNodeData;
|
|
132
|
+
}
|
|
133
|
+
interface CodeGenEdge {
|
|
134
|
+
id: string;
|
|
135
|
+
sourceId: string;
|
|
136
|
+
targetId: string;
|
|
137
|
+
data: CodeGenEdgeData;
|
|
138
|
+
}
|
|
139
|
+
interface CodeGenGraph {
|
|
140
|
+
id: string;
|
|
141
|
+
nodes: CodeGenNode[];
|
|
142
|
+
edges: CodeGenEdge[];
|
|
143
|
+
data: CodeGenGraphData;
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region ../graph-tools/src/graphToMachineConfig.d.ts
|
|
147
|
+
interface MachineConfigOptions {
|
|
148
|
+
showDescriptions?: boolean;
|
|
149
|
+
showMeta?: boolean;
|
|
150
|
+
}
|
|
151
|
+
declare function graphToMachineConfig(graph: CodeGenGraph, options?: MachineConfigOptions): UnknownMachineConfig;
|
|
152
|
+
//#endregion
|
|
34
153
|
//#region src/graphToXStateTS.d.ts
|
|
35
154
|
interface XStateTSOptions extends MachineConfigOptions {
|
|
36
155
|
exportStyle?: 'named' | 'default' | 'none';
|
|
37
156
|
}
|
|
38
157
|
declare function graphToXStateTS(graph: CodeGenGraph, options?: XStateTSOptions): string;
|
|
39
158
|
//#endregion
|
|
159
|
+
//#region ../graph-tools/src/serializeJS.d.ts
|
|
160
|
+
/**
|
|
161
|
+
* Serializes JavaScript values as JS source code (not JSON).
|
|
162
|
+
* - Unquoted keys for valid identifiers
|
|
163
|
+
* - Single-quoted strings
|
|
164
|
+
* - Omits undefined values
|
|
165
|
+
* - Supports RawCode for verbatim expressions
|
|
166
|
+
* - Supports inline expression directives for verbatim expressions
|
|
167
|
+
*/
|
|
168
|
+
declare class RawCode {
|
|
169
|
+
code: string;
|
|
170
|
+
constructor(code: string);
|
|
171
|
+
}
|
|
172
|
+
declare function raw(code: string): RawCode;
|
|
173
|
+
declare function serializeJS(value: unknown, indent?: number, step?: number): string;
|
|
174
|
+
//#endregion
|
|
40
175
|
//#region src/jsonSchemaToTSType.d.ts
|
|
41
176
|
declare function jsonSchemaToTSType(schema: JSONSchema7 | undefined | null): string;
|
|
42
177
|
/**
|
|
@@ -50,4 +185,4 @@ declare function contextSchemaToTSType(context: Record<string, JSONSchema7> | nu
|
|
|
50
185
|
*/
|
|
51
186
|
declare function eventsSchemaToTSType(events: Record<string, JSONSchema7> | null | undefined): string | null;
|
|
52
187
|
//#endregion
|
|
53
|
-
export { type ActionLocation, type AdoptedActor, type AssetConfig, type CodeGenGraph, type CommentsConfig, type ConnectedRepo, type CreateInspectorOptions, type CreateMachineFromDefinitionInput, type CreateMachineFromTemplateInput, type CreateMachineInput, type CreateMachineTemplate, type CreateProjectInput, type DigraphAction, type DigraphConfig, type DigraphEdgeConfig, type DigraphNodeConfig, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type EnsureProjectInput, type EventTypeData, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type ExtractMachinesResponse, type ExtractedMachine, type GetMachineOptions, type GraphPatch, type InitOptions, type Inspector, type InspectorEvents, type MachineConfigOptions, type ManualActorOptions, type PlanSyncOptions, type ProjectData, type ProjectEmbedMachine, type ProjectMachine, type ProjectVisibility, type PullSyncResult, type PushSyncOptions, type PushSyncProjectOptions, type PushSyncResult, RawCode, type RepoType, type ResolvedSyncInput, type StateNodeJSONData, type StatelyAction, type StatelyApiClientOptions, StatelyApiError, type StatelyApiUrlOptions, type StatelyEdgeData, type StatelyEmbed, type StatelyEmbedOptions, type StatelyGraph, type StatelyGraphData, type StatelyGuard, type StatelyInvoke, type StatelyNodeData, type StatelyPragma, type StatelyPragmaAttachment, type StudioAction, StudioApiError, type StudioClient, type StudioClientOptions, type StudioEdge, type StudioMachine, type StudioMachineRecord, type StudioNode, type SyncInputFormat, type SyncPlan, type SyncPlanSummary, type Transport, type UploadResult, type UpsertStatelyPragmaOptions, type VerifyApiKeyResponse, type XStateTSOptions, type XStateVersion, contextSchemaToTSType, createPostMessageTransport, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createWebSocketTransport, eventsSchemaToTSType, findStatelyPragmaAttachments, fromStudioMachine, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
|
|
188
|
+
export { type ActionLocation, type AdoptedActor, type AssetConfig, type AssetUploadAdapter, type AssetUploadContext, type AssetUploadRequest, type CodeGenGraph, type CommentsConfig, type ConnectedRepo, type CreateInspectorOptions, type CreateMachineFromDefinitionInput, type CreateMachineFromTemplateInput, type CreateMachineInput, type CreateMachineTemplate, type CreateProjectInput, type CreateS3AssetUploadAdapterOptions, type CreateSupabaseAssetUploadAdapterOptions, type DigraphAction, type DigraphConfig, type DigraphEdgeConfig, type DigraphNodeConfig, type EmbedEventHandler, type EmbedEventMap, type EmbedEventName, type EmbedMode, type EnsureProjectInput, type EventTypeData, type ExportCallOptions, type ExportFormat, type ExportFormatMap, type ExtractMachinesResponse, type ExtractedMachine, type GetMachineOptions, type GraphPatch, type InitOptions, type Inspector, type InspectorEvents, type MachineConfigOptions, type ManualActorOptions, type PlanSyncOptions, type ProjectData, type ProjectEmbedMachine, type ProjectMachine, type ProjectVisibility, type PullSyncResult, type PushLocalMachineLinksResult, type PushSyncOptions, type PushSyncProjectOptions, type PushSyncResult, RawCode, type RepoType, type ResolvedSyncInput, type S3UploadTarget, type StateNodeJSONData, type StatelyAction, type StatelyApiClientOptions, StatelyApiError, type StatelyApiUrlOptions, type StatelyEdgeData, type StatelyEmbed, type StatelyEmbedOptions, type StatelyGraph, type StatelyGraphData, type StatelyGuard, type StatelyInvoke, type StatelyNodeData, type StatelyPragma, type StatelyPragmaAttachment, type StudioAction, StudioApiError, type StudioClient, type StudioClientOptions, type StudioEdge, type StudioMachine, type StudioMachineRecord, type StudioNode, type SupabaseStorageClient, type SyncInputFormat, type SyncPlan, type SyncPlanSummary, type Transport, type UpdateMachineInput, type UploadResult, type UpsertStatelyPragmaOptions, type VerifyApiKeyResponse, type XStateTSOptions, type XStateVersion, contextSchemaToTSType, createPostMessageTransport, createS3AssetUploadAdapter, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createSupabaseAssetUploadAdapter, createWebSocketTransport, eventsSchemaToTSType, findStatelyPragmaAttachments, fromStudioMachine, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { n as createWebSocketTransport, t as createPostMessageTransport } from "./transport-
|
|
1
|
+
import { n as createWebSocketTransport, t as createPostMessageTransport } from "./transport-C8UTS3Fa.mjs";
|
|
2
2
|
import { createStatelyEmbed } from "./embed.mjs";
|
|
3
|
+
import { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
|
|
3
4
|
import { createStatelyInspector } from "./inspect.mjs";
|
|
4
5
|
import { StudioApiError, createStatelyClient } from "./studio.mjs";
|
|
5
6
|
import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
|
|
6
|
-
import { a as
|
|
7
|
+
import { a as graphToMachineConfig, c as serializeJS, d as upsertStatelyPragma, i as jsonSchemaToTSType, l as findStatelyPragmaAttachments, n as contextSchemaToTSType, o as RawCode, r as eventsSchemaToTSType, s as raw, t as graphToXStateTS, u as getStatelyPragma } from "./graphToXStateTS-Gzh0ZqbN.mjs";
|
|
7
8
|
import { fromStudioMachine, studioMachineConverter, toStudioMachine } from "./graph.mjs";
|
|
8
9
|
|
|
9
|
-
export { RawCode, StatelyApiError, StudioApiError, contextSchemaToTSType, createPostMessageTransport, createStatelyApiClient, createStatelyApiUrl, createStatelyClient, createStatelyEmbed, createStatelyInspector, createWebSocketTransport, eventsSchemaToTSType, findStatelyPragmaAttachments, fromStudioMachine, getStatelyPragma, graphToMachineConfig, graphToXStateTS, jsonSchemaToTSType, raw, serializeJS, studioMachineConverter, toStudioMachine, upsertStatelyPragma };
|
|
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 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as ExportFormatMap, o as ExportCallOptions, p as ProtocolMessage, r as EmbedEventMap, s as ExportFormat } from "./protocol-
|
|
1
|
+
import { c as ExportFormatMap, o as ExportCallOptions, p as ProtocolMessage, r as EmbedEventMap, s as ExportFormat } from "./protocol-DN4mH4jR.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/transport.d.ts
|
|
4
4
|
interface Transport {
|
package/dist/inspect.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as EmbedMode, c as ExportFormatMap, i as EmbedEventName, n as EmbedEventHandler, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat } from "./protocol-
|
|
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-
|
|
1
|
+
import { a as EmbedMode, c as ExportFormatMap, i as EmbedEventName, n as EmbedEventHandler, o as ExportCallOptions, r as EmbedEventMap, s as ExportFormat } from "./protocol-DN4mH4jR.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-Bg9FTvb3.mjs";
|
|
3
3
|
export { AdoptedActor, CreateInspectorOptions, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ExportCallOptions, ExportFormat, ExportFormatMap, Inspector, InspectorEvents, ManualActorOptions, Transport, createStatelyInspector };
|
package/dist/inspect.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as createPendingExportManager, n as createWebSocketTransport, r as createEventRegistry } from "./transport-
|
|
1
|
+
import { i as createPendingExportManager, n as createWebSocketTransport, r as createEventRegistry } from "./transport-C8UTS3Fa.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/inspect.ts
|
|
4
4
|
const defaultSerializeSnapshot = (snapshot) => ({
|
package/dist/studio.d.mts
CHANGED
|
@@ -75,6 +75,11 @@ interface CreateMachineFromTemplateInput {
|
|
|
75
75
|
xstateVersion?: XStateVersion;
|
|
76
76
|
}
|
|
77
77
|
type CreateMachineInput<TDefinition = Record<string, unknown>> = CreateMachineFromDefinitionInput<TDefinition> | CreateMachineFromTemplateInput;
|
|
78
|
+
interface UpdateMachineInput<TDefinition = Record<string, unknown>> {
|
|
79
|
+
id: string;
|
|
80
|
+
name?: string;
|
|
81
|
+
definition?: TDefinition;
|
|
82
|
+
}
|
|
78
83
|
interface StudioMachineRecord<TDefinition = Record<string, unknown>> {
|
|
79
84
|
id: string;
|
|
80
85
|
name: string;
|
|
@@ -99,6 +104,7 @@ interface StudioClient {
|
|
|
99
104
|
machines: {
|
|
100
105
|
create<TMachine = Record<string, unknown>>(input: CreateMachineInput<TMachine>): Promise<StudioMachineRecord<TMachine>>;
|
|
101
106
|
createMany<TMachine = Record<string, unknown>>(input: CreateMachineInput<TMachine>): Promise<Array<StudioMachineRecord<TMachine>>>;
|
|
107
|
+
update<TMachine = Record<string, unknown>>(input: UpdateMachineInput<TMachine>): Promise<StudioMachineRecord<TMachine>>;
|
|
102
108
|
get<TMachine = Record<string, unknown>>(machineId: string, options?: GetMachineOptions): Promise<TMachine>;
|
|
103
109
|
};
|
|
104
110
|
code: {
|
|
@@ -109,4 +115,4 @@ interface StudioClient {
|
|
|
109
115
|
}
|
|
110
116
|
declare function createStatelyClient(options?: StudioClientOptions): StudioClient;
|
|
111
117
|
//#endregion
|
|
112
|
-
export { ConnectedRepo, CreateMachineFromDefinitionInput, CreateMachineFromTemplateInput, CreateMachineInput, CreateMachineTemplate, CreateProjectInput, EnsureProjectInput, ExtractMachinesResponse, ExtractedMachine, GetMachineOptions, ProjectData, ProjectMachine, ProjectVisibility, RepoType, StudioApiError, StudioClient, StudioClientOptions, StudioMachineRecord, VerifyApiKeyResponse, XStateVersion, createStatelyClient };
|
|
118
|
+
export { ConnectedRepo, CreateMachineFromDefinitionInput, CreateMachineFromTemplateInput, CreateMachineInput, CreateMachineTemplate, CreateProjectInput, EnsureProjectInput, ExtractMachinesResponse, ExtractedMachine, GetMachineOptions, ProjectData, ProjectMachine, ProjectVisibility, RepoType, StudioApiError, StudioClient, StudioClientOptions, StudioMachineRecord, UpdateMachineInput, VerifyApiKeyResponse, XStateVersion, createStatelyClient };
|
package/dist/studio.mjs
CHANGED
|
@@ -102,6 +102,13 @@ function createStatelyClient(options = {}) {
|
|
|
102
102
|
async createMany(input) {
|
|
103
103
|
return [await this.create(input)];
|
|
104
104
|
},
|
|
105
|
+
update(input) {
|
|
106
|
+
return request(`/machines/${encodeURIComponent(input.id)}`, {
|
|
107
|
+
method: "PATCH",
|
|
108
|
+
headers: { "Content-Type": "application/json" },
|
|
109
|
+
body: JSON.stringify(input)
|
|
110
|
+
});
|
|
111
|
+
},
|
|
105
112
|
get(machineId, getOptions = {}) {
|
|
106
113
|
const search = new URLSearchParams();
|
|
107
114
|
if (getOptions.version) search.set("version", getOptions.version);
|
package/dist/sync.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CreateProjectInput, ProjectData, StudioClient, StudioMachineRecord, XStateVersion } from "./studio.mjs";
|
|
2
|
-
import { b as DigraphConfig, i as StatelyGraph } from "./graph-
|
|
2
|
+
import { b as DigraphConfig, i as StatelyGraph } from "./graph-DpBGHZwl.mjs";
|
|
3
3
|
import { GraphDiff } from "@statelyai/graph";
|
|
4
4
|
|
|
5
5
|
//#region src/sync.d.ts
|
|
@@ -52,8 +52,26 @@ interface PushSyncResult {
|
|
|
52
52
|
machine: StudioMachineRecord<DigraphConfig>;
|
|
53
53
|
outputPath?: string;
|
|
54
54
|
}
|
|
55
|
+
interface PushLocalMachineLinksResult {
|
|
56
|
+
sourcePath: string;
|
|
57
|
+
project: ProjectData;
|
|
58
|
+
created: Array<{
|
|
59
|
+
machineIndex: number;
|
|
60
|
+
machine: StudioMachineRecord<DigraphConfig>;
|
|
61
|
+
}>;
|
|
62
|
+
updated: Array<{
|
|
63
|
+
machineIndex: number;
|
|
64
|
+
machine: StudioMachineRecord<DigraphConfig>;
|
|
65
|
+
}>;
|
|
66
|
+
skipped: Array<{
|
|
67
|
+
machineIndex: number;
|
|
68
|
+
reason: string;
|
|
69
|
+
}>;
|
|
70
|
+
outputPath?: string;
|
|
71
|
+
}
|
|
72
|
+
declare function pushLocalMachineLinks(options: PushSyncOptions): Promise<PushLocalMachineLinksResult>;
|
|
55
73
|
declare function planSync(options: PlanSyncOptions): Promise<SyncPlan>;
|
|
56
74
|
declare function pullSync(options: PlanSyncOptions): Promise<PullSyncResult>;
|
|
57
75
|
declare function pushSync(options: PushSyncOptions): Promise<PushSyncResult>;
|
|
58
76
|
//#endregion
|
|
59
|
-
export { PlanSyncOptions, PullSyncResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary, planSync, pullSync, pushSync };
|
|
77
|
+
export { PlanSyncOptions, PullSyncResult, PushLocalMachineLinksResult, PushSyncOptions, PushSyncProjectOptions, PushSyncResult, ResolvedSyncInput, SyncInputFormat, SyncPlan, SyncPlanSummary, planSync, pullSync, pushLocalMachineLinks, pushSync };
|
package/dist/sync.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createStatelyClient } from "./studio.mjs";
|
|
2
|
-
import { d as upsertStatelyPragma, t as graphToXStateTS } from "./graphToXStateTS-
|
|
2
|
+
import { d as upsertStatelyPragma, l as findStatelyPragmaAttachments, t as graphToXStateTS, u as getStatelyPragma } from "./graphToXStateTS-Gzh0ZqbN.mjs";
|
|
3
3
|
import { fromStudioMachine, toStudioMachine } from "./graph.mjs";
|
|
4
4
|
import { getDiff, isEmptyDiff } from "@statelyai/graph";
|
|
5
5
|
import fs from "node:fs/promises";
|
|
@@ -186,6 +186,90 @@ function fromXStateConfig(config) {
|
|
|
186
186
|
data: {}
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
+
async function pushLocalMachineLinks(options) {
|
|
190
|
+
const client = options.client ?? createStatelyClient({
|
|
191
|
+
apiKey: options.apiKey,
|
|
192
|
+
baseUrl: options.baseUrl,
|
|
193
|
+
fetch: options.fetch
|
|
194
|
+
});
|
|
195
|
+
const sourcePath = path.resolve(options.cwd ?? process.cwd(), options.source);
|
|
196
|
+
const project = await resolvePushProject(client, sourcePath, options);
|
|
197
|
+
if (!project.projectVersionId) throw new Error("Resolved project is missing projectVersionId.");
|
|
198
|
+
const contents = await fs.readFile(sourcePath, "utf8");
|
|
199
|
+
const attachments = findStatelyPragmaAttachments(contents, sourcePath);
|
|
200
|
+
const extracted = await client.code.extractMachines(contents);
|
|
201
|
+
if (attachments.length === 0 || extracted.machines.length === 0) return {
|
|
202
|
+
sourcePath,
|
|
203
|
+
project,
|
|
204
|
+
created: [],
|
|
205
|
+
updated: [],
|
|
206
|
+
skipped: [{
|
|
207
|
+
machineIndex: 0,
|
|
208
|
+
reason: "No local machines were discovered in this file."
|
|
209
|
+
}]
|
|
210
|
+
};
|
|
211
|
+
if (attachments.length !== extracted.machines.length) return {
|
|
212
|
+
sourcePath,
|
|
213
|
+
project,
|
|
214
|
+
created: [],
|
|
215
|
+
updated: [],
|
|
216
|
+
skipped: [{
|
|
217
|
+
machineIndex: 0,
|
|
218
|
+
reason: "The local machine extractor did not align with the source attachments for this file."
|
|
219
|
+
}]
|
|
220
|
+
};
|
|
221
|
+
let nextContents = contents;
|
|
222
|
+
let outputPath;
|
|
223
|
+
const created = [];
|
|
224
|
+
const updated = [];
|
|
225
|
+
const skipped = [];
|
|
226
|
+
for (const [machineIndex, attachment] of attachments.entries()) {
|
|
227
|
+
const extractedMachine = extracted.machines[machineIndex];
|
|
228
|
+
if (!extractedMachine?.config) {
|
|
229
|
+
skipped.push({
|
|
230
|
+
machineIndex,
|
|
231
|
+
reason: "No extracted machine config was available for this source."
|
|
232
|
+
});
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (attachment.pragma?.id) {
|
|
236
|
+
const updatedMachine = await client.machines.update({
|
|
237
|
+
id: attachment.pragma.id,
|
|
238
|
+
definition: toStudioMachine(fromXStateConfig(extractedMachine.config))
|
|
239
|
+
});
|
|
240
|
+
updated.push({
|
|
241
|
+
machineIndex,
|
|
242
|
+
machine: updatedMachine
|
|
243
|
+
});
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const machine = await client.machines.create({
|
|
247
|
+
projectVersionId: project.projectVersionId,
|
|
248
|
+
definition: toStudioMachine(fromXStateConfig(extractedMachine.config)),
|
|
249
|
+
xstateVersion: Math.max(5, options.xstateVersion ?? 5)
|
|
250
|
+
});
|
|
251
|
+
nextContents = upsertStatelyPragma(nextContents, machine.id, {
|
|
252
|
+
fileName: sourcePath,
|
|
253
|
+
machineIndex
|
|
254
|
+
});
|
|
255
|
+
created.push({
|
|
256
|
+
machineIndex,
|
|
257
|
+
machine
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
if (nextContents !== contents) {
|
|
261
|
+
await fs.writeFile(sourcePath, nextContents, "utf8");
|
|
262
|
+
outputPath = sourcePath;
|
|
263
|
+
}
|
|
264
|
+
return {
|
|
265
|
+
sourcePath,
|
|
266
|
+
project,
|
|
267
|
+
created,
|
|
268
|
+
updated,
|
|
269
|
+
skipped,
|
|
270
|
+
...outputPath ? { outputPath } : {}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
189
273
|
async function resolveLocalFile(locator, options) {
|
|
190
274
|
const filePath = path.resolve(options.cwd ?? process.cwd(), locator);
|
|
191
275
|
const contents = await fs.readFile(filePath, "utf8");
|
|
@@ -350,12 +434,20 @@ async function pushSync(options) {
|
|
|
350
434
|
if (source.kind !== "local-file") throw new Error("pushSync currently requires a local source file.");
|
|
351
435
|
const sourcePath = source.locator;
|
|
352
436
|
const project = await resolvePushProject(client, sourcePath, options);
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
437
|
+
const existingMachineId = source.format === "xstate" ? getStatelyPragma(await fs.readFile(sourcePath, "utf8"), sourcePath)?.id : void 0;
|
|
438
|
+
let machine;
|
|
439
|
+
if (existingMachineId) machine = await client.machines.update({
|
|
440
|
+
id: existingMachineId,
|
|
441
|
+
definition: toStudioMachine(source.graph)
|
|
358
442
|
});
|
|
443
|
+
else {
|
|
444
|
+
if (!project.projectVersionId) throw new Error("Resolved project is missing projectVersionId.");
|
|
445
|
+
machine = await client.machines.create({
|
|
446
|
+
projectVersionId: project.projectVersionId,
|
|
447
|
+
definition: toStudioMachine(source.graph),
|
|
448
|
+
xstateVersion: options.xstateVersion ?? 5
|
|
449
|
+
});
|
|
450
|
+
}
|
|
359
451
|
let outputPath;
|
|
360
452
|
if (source.format === "xstate") {
|
|
361
453
|
const contents = await fs.readFile(sourcePath, "utf8");
|
|
@@ -374,4 +466,4 @@ async function pushSync(options) {
|
|
|
374
466
|
}
|
|
375
467
|
|
|
376
468
|
//#endregion
|
|
377
|
-
export { planSync, pullSync, pushSync };
|
|
469
|
+
export { planSync, pullSync, pushLocalMachineLinks, pushSync };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"bin": {
|
|
6
6
|
"statelyai": "./dist/cli.mjs"
|
|
@@ -49,15 +49,20 @@
|
|
|
49
49
|
"types": "./dist/api.d.mts",
|
|
50
50
|
"import": "./dist/api.mjs"
|
|
51
51
|
},
|
|
52
|
+
"./assetStorage": {
|
|
53
|
+
"types": "./dist/assetStorage.d.mts",
|
|
54
|
+
"import": "./dist/assetStorage.mjs"
|
|
55
|
+
},
|
|
52
56
|
"./statelyai.schema.json": "./schemas/statelyai.schema.json",
|
|
53
|
-
"./schemas/statelyai.schema.json": "./schemas/statelyai.schema.json"
|
|
57
|
+
"./schemas/statelyai.schema.json": "./schemas/statelyai.schema.json",
|
|
58
|
+
"./xstate-json.schema.json": "./schemas/xstate-json.schema.json",
|
|
59
|
+
"./schemas/xstate-json.schema.json": "./schemas/xstate-json.schema.json"
|
|
54
60
|
},
|
|
55
61
|
"dependencies": {
|
|
56
62
|
"@oclif/core": "^4.10.3",
|
|
57
63
|
"@statelyai/graph": "^0.9.0",
|
|
58
64
|
"typescript": "^5.9.3",
|
|
59
|
-
"xstate": "^5.0.0"
|
|
60
|
-
"@statelyai/graph-tools": "0.0.0"
|
|
65
|
+
"xstate": "^5.0.0"
|
|
61
66
|
},
|
|
62
67
|
"devDependencies": {
|
|
63
68
|
"@types/json-schema": "^7.0.15",
|