@statelyai/sdk 0.34.1 → 0.35.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 +32 -26
- package/dist/assetStorage.d.mts +1 -1
- package/dist/auth.d.mts +14 -1
- package/dist/bin.mjs +1 -3
- package/dist/editor-sync-types-DNFk7Xtj.d.mts +53 -0
- package/dist/editorHostProtocol.d.mts +197 -0
- package/dist/{editorHostProtocol-B2_t3Le7.mjs → editorHostProtocol.mjs} +1 -1
- package/dist/embed.d.mts +3 -3
- package/dist/embed.mjs +2 -2
- package/dist/{graph-Ciocekxl.d.mts → graph-B6xUxqR5.d.mts} +1 -1
- package/dist/graph.d.mts +1 -1
- package/dist/{index-DZivqh0u.d.mts → index-CoxF4Saw.d.mts} +36 -252
- package/dist/index.d.mts +8 -31
- package/dist/index.mjs +5 -9
- package/dist/{inspect-BbvfH0Q1.d.mts → inspect-DCdu0ST3.d.mts} +1 -1
- package/dist/{inspect-DW30GMge.mjs → inspect-GSXRhzOx.mjs} +48 -32
- package/dist/inspect.d.mts +2 -2
- package/dist/inspect.mjs +2 -2
- package/dist/patchTypes.d.mts +1 -1
- package/dist/{protocol-B7q2lWj_.d.mts → protocol-nOWsz3UV.d.mts} +3 -3
- package/dist/protocol.d.mts +1 -1
- package/dist/relay.d.mts +1 -1
- package/dist/relay.mjs +40 -1
- package/dist/{studio-CKdEPGKY.d.mts → studio-3ujfe2z0.d.mts} +2 -2
- package/dist/{openapi-BTDjYWXd.mjs → studio-Bn3alVku.mjs} +637 -1
- package/dist/studio.d.mts +1 -1
- package/dist/studio.mjs +2 -2
- package/dist/{version-BEfUEyPL.mjs → version-DECst76A.mjs} +1 -1
- package/package.json +21 -17
- package/dist/auth-CVFc85uF.d.mts +0 -15
- package/dist/dist-NJFkDQjK.mjs +0 -8134
- package/dist/editor-sync-types-D7YYz6fb.d.mts +0 -98
- package/dist/editorHostSession-Bj5YcijC.mjs +0 -912
- package/dist/editorHostSession-DBLSyHJs.d.mts +0 -325
- package/dist/editorHostSession.d.mts +0 -2
- package/dist/editorHostSession.mjs +0 -6
- package/dist/statelyPragma-YtVaBuIe.mjs +0 -102
- package/dist/studio-BZP6DaIO.mjs +0 -638
- package/dist/sync.d.mts +0 -86
- package/dist/sync.mjs +0 -4646
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import { Q as ProjectEmbedMachine, an as EmbedPanelConfig, lt as ProjectWorkspaceConfig } from "./protocol-B7q2lWj_.mjs";
|
|
2
|
-
import { a as EditorSyncParseRequest, d as EditorSyncTextReplacement, f as MachineSourceLocations, i as EditorSyncApplyResponse, n as EditorSyncAccess, o as EditorSyncParseResponse, r as EditorSyncApplyRequest, s as EditorSyncSourceDocument, t as EditorCapabilities } from "./editor-sync-types-D7YYz6fb.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/editorHostProtocol.d.ts
|
|
5
|
-
declare const EDITOR_PROTOCOL_VERSION = 1;
|
|
6
|
-
type EditorHostDiagnostic = {
|
|
7
|
-
id: string;
|
|
8
|
-
code: string;
|
|
9
|
-
phase: 'initialize' | 'save' | 'update' | 'export';
|
|
10
|
-
timestamp: string;
|
|
11
|
-
details?: Record<string, unknown>;
|
|
12
|
-
};
|
|
13
|
-
type EditorHostExportFormat = 'xstate-v6' | 'xstate' | 'async' | 'xstate-json' | 'xgraph' | 'digraph' | 'd2' | 'mermaid' | 'redux' | 'zustand' | 'asl-json' | 'asl-yaml' | 'scxml';
|
|
14
|
-
interface EditorHostValidationIssue {
|
|
15
|
-
nodeIds: string[];
|
|
16
|
-
edgeIds: string[];
|
|
17
|
-
level: 'info' | 'warning' | 'error';
|
|
18
|
-
message: string;
|
|
19
|
-
}
|
|
20
|
-
type EditorHostInboundMessage = {
|
|
21
|
-
type: '@statelyai.ready';
|
|
22
|
-
version?: string;
|
|
23
|
-
protocolVersion?: number;
|
|
24
|
-
} | {
|
|
25
|
-
type: '@statelyai.loaded';
|
|
26
|
-
graph: unknown;
|
|
27
|
-
machineId?: string;
|
|
28
|
-
sourceLocations?: MachineSourceLocations;
|
|
29
|
-
} | {
|
|
30
|
-
type: '@statelyai.change';
|
|
31
|
-
graph: unknown;
|
|
32
|
-
machineConfig: unknown;
|
|
33
|
-
machineId?: string;
|
|
34
|
-
patches?: unknown[];
|
|
35
|
-
sourceLocations?: MachineSourceLocations;
|
|
36
|
-
} | {
|
|
37
|
-
type: '@statelyai.save';
|
|
38
|
-
requestId?: string;
|
|
39
|
-
graph: unknown;
|
|
40
|
-
machineConfig: unknown;
|
|
41
|
-
machineId?: string;
|
|
42
|
-
patches?: unknown[];
|
|
43
|
-
validations?: EditorHostValidationIssue[];
|
|
44
|
-
sourceLocations?: MachineSourceLocations;
|
|
45
|
-
sourceUpdateStrategy?: 'preserve' | 'rewrite';
|
|
46
|
-
} | {
|
|
47
|
-
type: '@statelyai.refresh';
|
|
48
|
-
machineId?: string;
|
|
49
|
-
} | {
|
|
50
|
-
type: '@statelyai.retrieved';
|
|
51
|
-
requestId: string;
|
|
52
|
-
data: unknown;
|
|
53
|
-
machineId?: string;
|
|
54
|
-
} | {
|
|
55
|
-
type: '@statelyai.error';
|
|
56
|
-
code: string;
|
|
57
|
-
message: string;
|
|
58
|
-
machineId?: string;
|
|
59
|
-
requestId?: string;
|
|
60
|
-
diagnostic?: EditorHostDiagnostic;
|
|
61
|
-
} | {
|
|
62
|
-
type: '@statelyai.clipboardRead';
|
|
63
|
-
requestId: string;
|
|
64
|
-
} | {
|
|
65
|
-
type: '@statelyai.clipboardWrite';
|
|
66
|
-
requestId: string;
|
|
67
|
-
text: string;
|
|
68
|
-
} | {
|
|
69
|
-
type: '@statelyai.project.machineSelected';
|
|
70
|
-
machineId: string;
|
|
71
|
-
} | {
|
|
72
|
-
type: '@statelyai.project.workspaceAction';
|
|
73
|
-
actionId: string;
|
|
74
|
-
projectId?: string;
|
|
75
|
-
machineId?: string;
|
|
76
|
-
data?: unknown;
|
|
77
|
-
} | {
|
|
78
|
-
type: '@statelyai.project.workspaceOpenChanged';
|
|
79
|
-
open: boolean;
|
|
80
|
-
};
|
|
81
|
-
interface EditorHostInitOptions {
|
|
82
|
-
settings?: Record<string, unknown>;
|
|
83
|
-
panels?: EmbedPanelConfig[];
|
|
84
|
-
/** @deprecated Use `panels`. */
|
|
85
|
-
leftPanels?: string[];
|
|
86
|
-
/** @deprecated Use `panels`. */
|
|
87
|
-
rightPanels?: string[];
|
|
88
|
-
/** @deprecated Use `panels[].initiallyOpen`. */
|
|
89
|
-
activePanels?: string[];
|
|
90
|
-
unsavedIndicator?: {
|
|
91
|
-
enabled?: boolean;
|
|
92
|
-
mode?: 'structural' | 'all';
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
type EditorHostOutboundMessage = {
|
|
96
|
-
type: '@statelyai.init';
|
|
97
|
-
machine: unknown;
|
|
98
|
-
format?: string;
|
|
99
|
-
mode?: 'editing' | 'viewing';
|
|
100
|
-
theme?: 'light' | 'dark';
|
|
101
|
-
readOnly?: boolean;
|
|
102
|
-
readOnlyReason?: 'free-plan' | 'access-unverified';
|
|
103
|
-
capabilities?: EditorCapabilities;
|
|
104
|
-
sourceLocations?: MachineSourceLocations;
|
|
105
|
-
settings?: Record<string, unknown>;
|
|
106
|
-
panels?: EmbedPanelConfig[]; /** @deprecated Use `panels`. */
|
|
107
|
-
leftPanels?: string[]; /** @deprecated Use `panels`. */
|
|
108
|
-
rightPanels?: string[]; /** @deprecated Use `panels[].initiallyOpen`. */
|
|
109
|
-
activePanels?: string[];
|
|
110
|
-
unsavedIndicator?: {
|
|
111
|
-
enabled?: boolean;
|
|
112
|
-
mode?: 'structural' | 'all';
|
|
113
|
-
};
|
|
114
|
-
} | {
|
|
115
|
-
type: '@statelyai.project.init';
|
|
116
|
-
machines: ProjectEmbedMachine[];
|
|
117
|
-
chrome?: {
|
|
118
|
-
header?: boolean;
|
|
119
|
-
};
|
|
120
|
-
currentMachineId?: string;
|
|
121
|
-
mode?: 'editing' | 'viewing';
|
|
122
|
-
theme?: 'light' | 'dark';
|
|
123
|
-
readOnly?: boolean;
|
|
124
|
-
readOnlyReason?: 'free-plan' | 'access-unverified';
|
|
125
|
-
capabilities?: EditorCapabilities;
|
|
126
|
-
projectWorkspace?: ProjectWorkspaceConfig;
|
|
127
|
-
projectWorkspaceOpen?: boolean;
|
|
128
|
-
settings?: Record<string, unknown>;
|
|
129
|
-
panels?: EmbedPanelConfig[];
|
|
130
|
-
unsavedIndicator?: {
|
|
131
|
-
enabled?: boolean;
|
|
132
|
-
mode?: 'structural' | 'all';
|
|
133
|
-
};
|
|
134
|
-
} | {
|
|
135
|
-
type: '@statelyai.project.update';
|
|
136
|
-
machines: ProjectEmbedMachine[];
|
|
137
|
-
source?: 'external';
|
|
138
|
-
currentMachineId?: string;
|
|
139
|
-
projectWorkspace?: ProjectWorkspaceConfig;
|
|
140
|
-
projectWorkspaceOpen?: boolean;
|
|
141
|
-
} | {
|
|
142
|
-
type: '@statelyai.project.selectMachine';
|
|
143
|
-
machineId: string;
|
|
144
|
-
} | {
|
|
145
|
-
type: '@statelyai.setApiKey';
|
|
146
|
-
apiKey: string;
|
|
147
|
-
} | {
|
|
148
|
-
type: '@statelyai.handshake';
|
|
149
|
-
protocolVersion: number;
|
|
150
|
-
client?: {
|
|
151
|
-
name: string;
|
|
152
|
-
version: string;
|
|
153
|
-
};
|
|
154
|
-
} | {
|
|
155
|
-
type: '@statelyai.update';
|
|
156
|
-
machine: unknown;
|
|
157
|
-
format?: string;
|
|
158
|
-
machineId?: string;
|
|
159
|
-
sourceLocations?: MachineSourceLocations;
|
|
160
|
-
} | {
|
|
161
|
-
type: '@statelyai.saved';
|
|
162
|
-
requestId?: string;
|
|
163
|
-
graph: unknown;
|
|
164
|
-
machineId?: string;
|
|
165
|
-
} | {
|
|
166
|
-
type: '@statelyai.retrieve';
|
|
167
|
-
requestId: string;
|
|
168
|
-
format: EditorHostExportFormat;
|
|
169
|
-
machineId?: string;
|
|
170
|
-
} | {
|
|
171
|
-
type: '@statelyai.toast';
|
|
172
|
-
message: string;
|
|
173
|
-
toastType?: 'success' | 'error' | 'info' | 'warning';
|
|
174
|
-
id?: string;
|
|
175
|
-
machineId?: string;
|
|
176
|
-
} | {
|
|
177
|
-
type: '@statelyai.toast.dismiss';
|
|
178
|
-
id: string;
|
|
179
|
-
machineId?: string;
|
|
180
|
-
} | {
|
|
181
|
-
type: '@statelyai.error';
|
|
182
|
-
code: string;
|
|
183
|
-
message: string;
|
|
184
|
-
machineId?: string;
|
|
185
|
-
requestId?: string;
|
|
186
|
-
diagnostic?: EditorHostDiagnostic;
|
|
187
|
-
} | {
|
|
188
|
-
type: '@statelyai.clipboardReadResponse';
|
|
189
|
-
requestId: string;
|
|
190
|
-
text: string;
|
|
191
|
-
} | {
|
|
192
|
-
type: '@statelyai.clipboardWriteResponse';
|
|
193
|
-
requestId: string;
|
|
194
|
-
ok: boolean;
|
|
195
|
-
};
|
|
196
|
-
//#endregion
|
|
197
|
-
//#region src/editorHostSession.d.ts
|
|
198
|
-
interface EditorSyncBackend {
|
|
199
|
-
parse(request: EditorSyncParseRequest): Promise<EditorSyncParseResponse>;
|
|
200
|
-
apply(request: EditorSyncApplyRequest): Promise<EditorSyncApplyResponse>;
|
|
201
|
-
}
|
|
202
|
-
interface RemoteEditorSyncBackendOptions {
|
|
203
|
-
editorUrl: string;
|
|
204
|
-
apiKey?: string;
|
|
205
|
-
fetch?: typeof globalThis.fetch;
|
|
206
|
-
}
|
|
207
|
-
declare class EditorSyncError extends Error {
|
|
208
|
-
readonly status: number;
|
|
209
|
-
readonly code: string | undefined;
|
|
210
|
-
constructor(message: string, status: number, code?: string);
|
|
211
|
-
}
|
|
212
|
-
declare function createRemoteEditorSyncBackend(options: RemoteEditorSyncBackendOptions): EditorSyncBackend;
|
|
213
|
-
declare function fetchEditorSyncAccess(options: RemoteEditorSyncBackendOptions): Promise<EditorSyncAccess>;
|
|
214
|
-
interface EditorSourceHost {
|
|
215
|
-
rootUri: string;
|
|
216
|
-
rootFileName: string;
|
|
217
|
-
rootDir: string;
|
|
218
|
-
/** Zero-based machine occurrence within the root source document. */
|
|
219
|
-
machineIndex?: number;
|
|
220
|
-
collectDocuments(extraUris?: readonly string[]): Promise<EditorSyncSourceDocument[]>;
|
|
221
|
-
applyReplacements(replacements: EditorSyncTextReplacement[], rootUri: string): Promise<string[]>;
|
|
222
|
-
saveDocuments?(uris: string[]): Promise<void>;
|
|
223
|
-
watchSavedDocuments?(listener: (uri: string) => void | Promise<void>): {
|
|
224
|
-
dispose(): void;
|
|
225
|
-
};
|
|
226
|
-
watchChangedDocuments?(listener: (uri: string) => void): {
|
|
227
|
-
dispose(): void;
|
|
228
|
-
};
|
|
229
|
-
getPreserveStatelyMetadata?(uri: string): boolean;
|
|
230
|
-
}
|
|
231
|
-
interface EditorHostSessionOptions {
|
|
232
|
-
sourceUpdateStrategy?: 'preserve' | 'rewrite';
|
|
233
|
-
source: EditorSourceHost;
|
|
234
|
-
sync: EditorSyncBackend;
|
|
235
|
-
send(message: EditorHostOutboundMessage): void;
|
|
236
|
-
access?: EditorSyncAccess;
|
|
237
|
-
apiKey?: string;
|
|
238
|
-
getTheme?(): 'light' | 'dark';
|
|
239
|
-
showError?(message: string): void;
|
|
240
|
-
readClipboard?(): Promise<string>;
|
|
241
|
-
writeClipboard?(text: string): Promise<void>;
|
|
242
|
-
init?: EditorHostInitOptions;
|
|
243
|
-
client?: {
|
|
244
|
-
name: string;
|
|
245
|
-
version: string;
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
type SaveReminderState = {
|
|
249
|
-
shown: boolean;
|
|
250
|
-
};
|
|
251
|
-
type SelfEditState = {
|
|
252
|
-
count: number;
|
|
253
|
-
};
|
|
254
|
-
declare class EditorHostSession {
|
|
255
|
-
private options;
|
|
256
|
-
private saveReminderState;
|
|
257
|
-
private selfEditState;
|
|
258
|
-
private editorProtocolState;
|
|
259
|
-
private currentGraph;
|
|
260
|
-
private lastPersistedGraph;
|
|
261
|
-
private currentFormat;
|
|
262
|
-
private currentSourceLocations;
|
|
263
|
-
private access;
|
|
264
|
-
private watchedSourceUris;
|
|
265
|
-
private watcher;
|
|
266
|
-
private changeWatcher;
|
|
267
|
-
private retrieveRequestCount;
|
|
268
|
-
private pendingRetrievals;
|
|
269
|
-
constructor(options: EditorHostSessionOptions, saveReminderState?: SaveReminderState, selfEditState?: SelfEditState);
|
|
270
|
-
dispose(): void;
|
|
271
|
-
notifySavedDocument(uri?: string): Promise<void>;
|
|
272
|
-
receive(message: EditorHostInboundMessage): Promise<void>;
|
|
273
|
-
private initialize;
|
|
274
|
-
private save;
|
|
275
|
-
private isExternalSourceDocument;
|
|
276
|
-
private handleSavedDocument;
|
|
277
|
-
private reportSourceSyncError;
|
|
278
|
-
private updateWatchedSourceUris;
|
|
279
|
-
private getSerializedPayload;
|
|
280
|
-
private requestSerialized;
|
|
281
|
-
private resolveRetrieved;
|
|
282
|
-
}
|
|
283
|
-
interface EditorHostWorkspaceMachine {
|
|
284
|
-
id: string;
|
|
285
|
-
name?: string;
|
|
286
|
-
sourceReference?: string;
|
|
287
|
-
source: EditorSourceHost;
|
|
288
|
-
}
|
|
289
|
-
type EditorHostWorkspaceSessionOptions = Omit<EditorHostSessionOptions, 'source' | 'send'> & {
|
|
290
|
-
machines: EditorHostWorkspaceMachine[];
|
|
291
|
-
send(message: EditorHostOutboundMessage): void;
|
|
292
|
-
currentMachineId?: string;
|
|
293
|
-
workspaceName?: string;
|
|
294
|
-
projectWorkspaceOpen?: boolean;
|
|
295
|
-
showHeader?: boolean;
|
|
296
|
-
};
|
|
297
|
-
/**
|
|
298
|
-
* Runs one source-sync session per discovered machine while presenting the
|
|
299
|
-
* editor's project/workspace protocol as a single surface.
|
|
300
|
-
*/
|
|
301
|
-
declare class EditorHostWorkspaceSession {
|
|
302
|
-
private options;
|
|
303
|
-
private children;
|
|
304
|
-
private machineDefinitions;
|
|
305
|
-
private initialMessages;
|
|
306
|
-
private selectedMachineId;
|
|
307
|
-
private sentHandshake;
|
|
308
|
-
private sentApiKey;
|
|
309
|
-
private initialized;
|
|
310
|
-
private projectWorkspaceOpen;
|
|
311
|
-
private retrieveRequestCount;
|
|
312
|
-
private pendingRetrievals;
|
|
313
|
-
private saveReminderStates;
|
|
314
|
-
private selfEditStates;
|
|
315
|
-
constructor(options: EditorHostWorkspaceSessionOptions);
|
|
316
|
-
receive(message: EditorHostInboundMessage): Promise<void>;
|
|
317
|
-
selectMachine(machineId: string): void;
|
|
318
|
-
dispose(): void;
|
|
319
|
-
private handleChildMessage;
|
|
320
|
-
private flushProjectInit;
|
|
321
|
-
private getProjectMachines;
|
|
322
|
-
private getProjectWorkspace;
|
|
323
|
-
}
|
|
324
|
-
//#endregion
|
|
325
|
-
export { EditorHostOutboundMessage as _, EditorHostWorkspaceSessionOptions as a, EditorSyncError as c, fetchEditorSyncAccess as d, EDITOR_PROTOCOL_VERSION as f, EditorHostInitOptions as g, EditorHostInboundMessage as h, EditorHostWorkspaceSession as i, RemoteEditorSyncBackendOptions as l, EditorHostExportFormat as m, EditorHostSessionOptions as n, EditorSourceHost as o, EditorHostDiagnostic as p, EditorHostWorkspaceMachine as r, EditorSyncBackend as s, EditorHostSession as t, createRemoteEditorSyncBackend as u, EditorHostValidationIssue as v };
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { _ as EditorHostOutboundMessage, a as EditorHostWorkspaceSessionOptions, c as EditorSyncError, d as fetchEditorSyncAccess, f as EDITOR_PROTOCOL_VERSION, g as EditorHostInitOptions, h as EditorHostInboundMessage, i as EditorHostWorkspaceSession, l as RemoteEditorSyncBackendOptions, m as EditorHostExportFormat, n as EditorHostSessionOptions, o as EditorSourceHost, p as EditorHostDiagnostic, r as EditorHostWorkspaceMachine, s as EditorSyncBackend, t as EditorHostSession, u as createRemoteEditorSyncBackend, v as EditorHostValidationIssue } from "./editorHostSession-DBLSyHJs.mjs";
|
|
2
|
-
export { EDITOR_PROTOCOL_VERSION, EditorHostDiagnostic, EditorHostExportFormat, EditorHostInboundMessage, EditorHostInitOptions, EditorHostOutboundMessage, EditorHostSession, EditorHostSessionOptions, EditorHostValidationIssue, EditorHostWorkspaceMachine, EditorHostWorkspaceSession, EditorHostWorkspaceSessionOptions, EditorSourceHost, EditorSyncBackend, EditorSyncError, RemoteEditorSyncBackendOptions, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import "./openapi-BTDjYWXd.mjs";
|
|
2
|
-
import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-B2_t3Le7.mjs";
|
|
3
|
-
import { a as fetchEditorSyncAccess, i as createRemoteEditorSyncBackend, n as EditorHostWorkspaceSession, r as EditorSyncError, t as EditorHostSession } from "./editorHostSession-Bj5YcijC.mjs";
|
|
4
|
-
import "./dist-NJFkDQjK.mjs";
|
|
5
|
-
|
|
6
|
-
export { EDITOR_PROTOCOL_VERSION, EditorHostSession, EditorHostWorkspaceSession, EditorSyncError, createRemoteEditorSyncBackend, fetchEditorSyncAccess };
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
//#region src/statelyPragma.ts
|
|
4
|
-
function findStatelyPragmaAttachments(sourceText, fileName = "machine.ts") {
|
|
5
|
-
const sourceFile = ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.Latest, true, getScriptKind(fileName));
|
|
6
|
-
const attachments = [];
|
|
7
|
-
const visit = (node) => {
|
|
8
|
-
if (ts.isCallExpression(node) && isCreateMachineExpression(node.expression)) {
|
|
9
|
-
const attachNode = findAttachNode(node);
|
|
10
|
-
if (attachNode) attachments.push({
|
|
11
|
-
machineStart: getMachineExpressionStart(node.expression, sourceFile),
|
|
12
|
-
attachStart: attachNode.getStart(sourceFile),
|
|
13
|
-
pragma: findAttachedStatelyPragma(sourceText, attachNode)
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
ts.forEachChild(node, visit);
|
|
17
|
-
};
|
|
18
|
-
visit(sourceFile);
|
|
19
|
-
return attachments;
|
|
20
|
-
}
|
|
21
|
-
function getStatelyPragma(sourceText, fileName = "machine.ts", machineIndex = 0) {
|
|
22
|
-
return findStatelyPragmaAttachments(sourceText, fileName)[machineIndex]?.pragma;
|
|
23
|
-
}
|
|
24
|
-
function upsertStatelyPragma(sourceText, id, options = {}) {
|
|
25
|
-
const attachment = findStatelyPragmaAttachments(sourceText, options.fileName ?? "machine.ts")[options.machineIndex ?? 0];
|
|
26
|
-
if (!attachment) return sourceText;
|
|
27
|
-
const lineEnding = options.lineEnding ?? detectLineEnding(sourceText);
|
|
28
|
-
const canonicalComment = `// @statelyai id=${id}`;
|
|
29
|
-
if (attachment.pragma) return sourceText.slice(0, attachment.pragma.start) + canonicalComment + sourceText.slice(attachment.pragma.end);
|
|
30
|
-
const insertText = `${getIndentationAtOffset(sourceText, attachment.attachStart)}${canonicalComment}${lineEnding}`;
|
|
31
|
-
return sourceText.slice(0, attachment.attachStart) + insertText + sourceText.slice(attachment.attachStart);
|
|
32
|
-
}
|
|
33
|
-
function findAttachedStatelyPragma(sourceText, node) {
|
|
34
|
-
const comments = ts.getLeadingCommentRanges(sourceText, node.getFullStart()) ?? [];
|
|
35
|
-
for (let index = comments.length - 1; index >= 0; index -= 1) {
|
|
36
|
-
const comment = comments[index];
|
|
37
|
-
const parsed = parseStatelyPragma(sourceText, comment.pos, comment.end);
|
|
38
|
-
if (parsed) return parsed;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function parseStatelyPragma(sourceText, start, end) {
|
|
42
|
-
const match = normalizeCommentContent(sourceText.slice(start, end)).match(/^@statelyai(?:\s+(.*))?$/s);
|
|
43
|
-
if (!match) return;
|
|
44
|
-
const fields = parseFields(match[1] ?? "");
|
|
45
|
-
return {
|
|
46
|
-
tag: "@statelyai",
|
|
47
|
-
id: fields.id,
|
|
48
|
-
fields,
|
|
49
|
-
start,
|
|
50
|
-
end
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function normalizeCommentContent(rawComment) {
|
|
54
|
-
if (rawComment.startsWith("//")) return rawComment.slice(2).trim();
|
|
55
|
-
if (rawComment.startsWith("/*")) return rawComment.slice(2, rawComment.endsWith("*/") ? -2 : void 0).split(/\r?\n/).map((line) => line.replace(/^\s*\*\s?/, "")).join(" ").trim();
|
|
56
|
-
return rawComment.trim();
|
|
57
|
-
}
|
|
58
|
-
function parseFields(input) {
|
|
59
|
-
const fields = {};
|
|
60
|
-
for (const token of input.split(/\s+/)) {
|
|
61
|
-
if (!token) continue;
|
|
62
|
-
const equalsIndex = token.indexOf("=");
|
|
63
|
-
if (equalsIndex <= 0) continue;
|
|
64
|
-
const key = token.slice(0, equalsIndex);
|
|
65
|
-
const value = token.slice(equalsIndex + 1);
|
|
66
|
-
if (!key || !value) continue;
|
|
67
|
-
fields[key] = value;
|
|
68
|
-
}
|
|
69
|
-
return fields;
|
|
70
|
-
}
|
|
71
|
-
function findAttachNode(node) {
|
|
72
|
-
let current = node;
|
|
73
|
-
while (current?.parent) {
|
|
74
|
-
if (ts.isVariableStatement(current.parent) || ts.isExpressionStatement(current.parent) || ts.isExportAssignment(current.parent)) return current.parent;
|
|
75
|
-
current = current.parent;
|
|
76
|
-
}
|
|
77
|
-
return current;
|
|
78
|
-
}
|
|
79
|
-
function isCreateMachineExpression(expression) {
|
|
80
|
-
const isMachineFactoryName = (name) => name === "createMachine" || name === "createMachineFromConfig";
|
|
81
|
-
return ts.isIdentifier(expression) && isMachineFactoryName(expression.text) || ts.isPropertyAccessExpression(expression) && isMachineFactoryName(expression.name.text);
|
|
82
|
-
}
|
|
83
|
-
function getMachineExpressionStart(expression, sourceFile) {
|
|
84
|
-
if (ts.isPropertyAccessExpression(expression)) return expression.name.getStart(sourceFile);
|
|
85
|
-
return expression.getStart(sourceFile);
|
|
86
|
-
}
|
|
87
|
-
function getIndentationAtOffset(sourceText, offset) {
|
|
88
|
-
const lineStart = sourceText.lastIndexOf("\n", Math.max(0, offset - 1)) + 1;
|
|
89
|
-
return sourceText.slice(lineStart, offset).match(/^[ \t]*/)?.[0] ?? "";
|
|
90
|
-
}
|
|
91
|
-
function detectLineEnding(sourceText) {
|
|
92
|
-
return sourceText.includes("\r\n") ? "\r\n" : "\n";
|
|
93
|
-
}
|
|
94
|
-
function getScriptKind(fileName) {
|
|
95
|
-
if (fileName.endsWith(".tsx")) return ts.ScriptKind.TSX;
|
|
96
|
-
if (fileName.endsWith(".jsx")) return ts.ScriptKind.JSX;
|
|
97
|
-
if (fileName.endsWith(".js")) return ts.ScriptKind.JS;
|
|
98
|
-
return ts.ScriptKind.TS;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
|
-
export { getStatelyPragma as n, upsertStatelyPragma as r, findStatelyPragmaAttachments as t };
|