@flowgram.ai/variable-core 0.1.0-alpha.2 → 0.1.0-alpha.21
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/dist/esm/index.js +1117 -425
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +1799 -520
- package/dist/index.d.ts +1799 -520
- package/dist/index.js +1182 -483
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/README.md +0 -24
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,331 @@
|
|
|
1
1
|
import { ContainerModule, interfaces } from 'inversify';
|
|
2
2
|
import * as _flowgram_ai_utils from '@flowgram.ai/utils';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Disposable, Emitter, DisposableCollection, Event } from '@flowgram.ai/utils';
|
|
4
|
+
import { Subject, Observable, BehaviorSubject, Observer as Observer$1 } from 'rxjs';
|
|
5
5
|
export { Observer } from 'rxjs';
|
|
6
|
-
import
|
|
6
|
+
import React from 'react';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
10
|
+
* SPDX-License-Identifier: MIT
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An InversifyJS container module that binds all the necessary services for the variable engine.
|
|
15
|
+
* This module sets up the dependency injection for the core components of the variable engine.
|
|
16
|
+
*/
|
|
8
17
|
declare const VariableContainerModule: ContainerModule;
|
|
9
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
21
|
+
* SPDX-License-Identifier: MIT
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A provider for dynamically obtaining the `VariableEngine` instance.
|
|
26
|
+
* This is used to prevent circular dependencies when injecting `VariableEngine`.
|
|
27
|
+
*/
|
|
10
28
|
declare const VariableEngineProvider: unique symbol;
|
|
11
29
|
type VariableEngineProvider = () => VariableEngine;
|
|
12
30
|
|
|
13
31
|
/**
|
|
14
|
-
*
|
|
15
|
-
|
|
32
|
+
* Manages the output variables of a scope.
|
|
33
|
+
*/
|
|
34
|
+
declare class ScopeOutputData {
|
|
35
|
+
readonly scope: Scope;
|
|
36
|
+
protected variableTable: IVariableTable;
|
|
37
|
+
protected memo: {
|
|
38
|
+
<T>(key: string | symbol, fn: () => T): T;
|
|
39
|
+
clear: (key?: string | symbol) => void;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The variable engine instance.
|
|
43
|
+
*/
|
|
44
|
+
get variableEngine(): VariableEngine;
|
|
45
|
+
/**
|
|
46
|
+
* The global variable table from the variable engine.
|
|
47
|
+
*/
|
|
48
|
+
get globalVariableTable(): IVariableTable;
|
|
49
|
+
/**
|
|
50
|
+
* The current version of the output data, which increments on each change.
|
|
51
|
+
*/
|
|
52
|
+
get version(): number;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated use onListOrAnyVarChange instead
|
|
55
|
+
*/
|
|
56
|
+
get onDataChange(): _flowgram_ai_utils.Event<void>;
|
|
57
|
+
/**
|
|
58
|
+
* An event that fires when the list of output variables changes.
|
|
59
|
+
*/
|
|
60
|
+
get onVariableListChange(): (observer: (variables: VariableDeclaration[]) => void) => _flowgram_ai_utils.Disposable;
|
|
61
|
+
/**
|
|
62
|
+
* An event that fires when any output variable's value changes.
|
|
63
|
+
*/
|
|
64
|
+
get onAnyVariableChange(): (observer: (changedVariable: VariableDeclaration) => void) => _flowgram_ai_utils.Disposable;
|
|
65
|
+
/**
|
|
66
|
+
* An event that fires when the output variable list changes or any variable's value is updated.
|
|
67
|
+
*/
|
|
68
|
+
get onListOrAnyVarChange(): (observer: () => void) => _flowgram_ai_utils.Disposable;
|
|
69
|
+
protected _hasChanges: boolean;
|
|
70
|
+
constructor(scope: Scope);
|
|
71
|
+
/**
|
|
72
|
+
* The output variable declarations of the scope, sorted by order.
|
|
73
|
+
*/
|
|
74
|
+
get variables(): VariableDeclaration[];
|
|
75
|
+
/**
|
|
76
|
+
* The keys of the output variables.
|
|
77
|
+
*/
|
|
78
|
+
get variableKeys(): string[];
|
|
79
|
+
protected addVariableToTable(variable: VariableDeclaration): void;
|
|
80
|
+
protected removeVariableFromTable(key: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves a variable declaration by its key.
|
|
83
|
+
* @param key The key of the variable.
|
|
84
|
+
* @returns The `VariableDeclaration` or `undefined` if not found.
|
|
85
|
+
*/
|
|
86
|
+
getVariableByKey(key: string): VariableDeclaration<any> | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Notifies the covering scopes that the available variables have changed.
|
|
89
|
+
*/
|
|
90
|
+
notifyCoversChange(): void;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Manages the available variables within a scope.
|
|
95
|
+
*/
|
|
96
|
+
declare class ScopeAvailableData {
|
|
97
|
+
readonly scope: Scope;
|
|
98
|
+
protected memo: {
|
|
99
|
+
<T>(key: string | symbol, fn: () => T): T;
|
|
100
|
+
clear: (key?: string | symbol) => void;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The global variable table from the variable engine.
|
|
104
|
+
*/
|
|
105
|
+
get globalVariableTable(): IVariableTable;
|
|
106
|
+
protected _version: number;
|
|
107
|
+
protected refresh$: Subject<void>;
|
|
108
|
+
protected _variables: VariableDeclaration[];
|
|
109
|
+
/**
|
|
110
|
+
* The current version of the available data, which increments on each change.
|
|
111
|
+
*/
|
|
112
|
+
get version(): number;
|
|
113
|
+
protected bumpVersion(): void;
|
|
114
|
+
/**
|
|
115
|
+
* Refreshes the list of available variables.
|
|
116
|
+
* This should be called when the dependencies of the scope change.
|
|
117
|
+
*/
|
|
118
|
+
refresh(): void;
|
|
119
|
+
/**
|
|
120
|
+
* An observable that emits when the list of available variables changes.
|
|
121
|
+
*/
|
|
122
|
+
protected variables$: Observable<VariableDeclaration[]>;
|
|
123
|
+
/**
|
|
124
|
+
* An observable that emits when any variable in the available list changes its value.
|
|
125
|
+
*/
|
|
126
|
+
protected anyVariableChange$: Observable<VariableDeclaration>;
|
|
127
|
+
/**
|
|
128
|
+
* Subscribes to changes in any variable's value in the available list.
|
|
129
|
+
* @param observer A function to be called with the changed variable.
|
|
130
|
+
* @returns A disposable to unsubscribe from the changes.
|
|
131
|
+
*/
|
|
132
|
+
onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
|
|
133
|
+
/**
|
|
134
|
+
* Subscribes to changes in the list of available variables.
|
|
135
|
+
* @param observer A function to be called with the new list of variables.
|
|
136
|
+
* @returns A disposable to unsubscribe from the changes.
|
|
137
|
+
*/
|
|
138
|
+
onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
|
|
139
|
+
/**
|
|
140
|
+
* @deprecated
|
|
141
|
+
*/
|
|
142
|
+
protected onDataChangeEmitter: Emitter<VariableDeclaration<any>[]>;
|
|
143
|
+
protected onListOrAnyVarChangeEmitter: Emitter<VariableDeclaration<any>[]>;
|
|
144
|
+
/**
|
|
145
|
+
* @deprecated use available.onListOrAnyVarChange instead
|
|
146
|
+
*/
|
|
147
|
+
onDataChange: _flowgram_ai_utils.Event<VariableDeclaration<any>[]>;
|
|
148
|
+
/**
|
|
149
|
+
* An event that fires when the variable list changes or any variable's value is updated.
|
|
150
|
+
*/
|
|
151
|
+
onListOrAnyVarChange: _flowgram_ai_utils.Event<VariableDeclaration<any>[]>;
|
|
152
|
+
constructor(scope: Scope);
|
|
153
|
+
/**
|
|
154
|
+
* Gets the list of available variables.
|
|
155
|
+
*/
|
|
156
|
+
get variables(): VariableDeclaration[];
|
|
157
|
+
/**
|
|
158
|
+
* Gets the keys of the available variables.
|
|
159
|
+
*/
|
|
160
|
+
get variableKeys(): string[];
|
|
161
|
+
/**
|
|
162
|
+
* Gets the dependency scopes.
|
|
163
|
+
*/
|
|
164
|
+
get depScopes(): Scope[];
|
|
165
|
+
/**
|
|
166
|
+
* Retrieves a variable field by its key path from the available variables.
|
|
167
|
+
* @param keyPath The key path to the variable field.
|
|
168
|
+
* @returns The found `BaseVariableField` or `undefined`.
|
|
169
|
+
*/
|
|
170
|
+
getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* Tracks changes to a variable field by its key path.
|
|
173
|
+
* This includes changes to its type, value, or any nested properties.
|
|
174
|
+
* @param keyPath The key path to the variable field to track.
|
|
175
|
+
* @param cb The callback to execute when the variable changes.
|
|
176
|
+
* @param opts Configuration options for the subscription.
|
|
177
|
+
* @returns A disposable to unsubscribe from the tracking.
|
|
178
|
+
*/
|
|
179
|
+
trackByKeyPath<Data = BaseVariableField | undefined>(keyPath: string[] | undefined, cb: (variable?: Data) => void, opts?: SubscribeConfig<BaseVariableField | undefined, Data>): Disposable;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
184
|
+
* SPDX-License-Identifier: MIT
|
|
185
|
+
*/
|
|
186
|
+
|
|
187
|
+
type Observer<ActionType extends GlobalEventActionType = GlobalEventActionType> = (action: ActionType) => void;
|
|
188
|
+
/**
|
|
189
|
+
* Manages global events within a scope.
|
|
190
|
+
*/
|
|
191
|
+
declare class ScopeEventData {
|
|
192
|
+
readonly scope: Scope;
|
|
193
|
+
event$: Subject<GlobalEventActionType>;
|
|
194
|
+
/**
|
|
195
|
+
* Dispatches a global event.
|
|
196
|
+
* @param action The event action to dispatch.
|
|
197
|
+
*/
|
|
198
|
+
dispatch<ActionType extends GlobalEventActionType = GlobalEventActionType>(action: ActionType): void;
|
|
199
|
+
/**
|
|
200
|
+
* Subscribes to all global events.
|
|
201
|
+
* @param observer The observer function to call with the event action.
|
|
202
|
+
* @returns A disposable to unsubscribe from the events.
|
|
203
|
+
*/
|
|
204
|
+
subscribe<ActionType extends GlobalEventActionType = GlobalEventActionType>(observer: Observer<ActionType>): Disposable;
|
|
205
|
+
/**
|
|
206
|
+
* Subscribes to a specific type of global event.
|
|
207
|
+
* @param type The type of the event to subscribe to.
|
|
208
|
+
* @param observer The observer function to call with the event action.
|
|
209
|
+
* @returns A disposable to unsubscribe from the event.
|
|
210
|
+
*/
|
|
211
|
+
on<ActionType extends GlobalEventActionType = GlobalEventActionType>(type: ActionType['type'], observer: Observer<ActionType>): Disposable;
|
|
212
|
+
constructor(scope: Scope);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Interface for the Scope constructor.
|
|
217
|
+
*/
|
|
218
|
+
interface IScopeConstructor {
|
|
219
|
+
new (options: {
|
|
220
|
+
id: string | symbol;
|
|
221
|
+
variableEngine: VariableEngine;
|
|
222
|
+
meta?: Record<string, any>;
|
|
223
|
+
}): Scope;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Represents a variable scope, which manages its own set of variables and their lifecycle.
|
|
227
|
+
* - `scope.output` represents the variables declared within this scope.
|
|
228
|
+
* - `scope.available` represents all variables accessible from this scope, including those from parent scopes.
|
|
229
|
+
*/
|
|
230
|
+
declare class Scope<ScopeMeta extends Record<string, any> = Record<string, any>> {
|
|
231
|
+
/**
|
|
232
|
+
* A unique identifier for the scope.
|
|
233
|
+
*/
|
|
234
|
+
readonly id: string | symbol;
|
|
235
|
+
/**
|
|
236
|
+
* The variable engine instance this scope belongs to.
|
|
237
|
+
*/
|
|
238
|
+
readonly variableEngine: VariableEngine;
|
|
239
|
+
/**
|
|
240
|
+
* Metadata associated with the scope, which can be extended by higher-level business logic.
|
|
241
|
+
*/
|
|
242
|
+
readonly meta: ScopeMeta;
|
|
243
|
+
/**
|
|
244
|
+
* The root AST node for this scope, which is a MapNode.
|
|
245
|
+
* It stores various data related to the scope, such as `outputs`.
|
|
246
|
+
*/
|
|
247
|
+
readonly ast: MapNode;
|
|
248
|
+
/**
|
|
249
|
+
* Manages the available variables for this scope.
|
|
250
|
+
*/
|
|
251
|
+
readonly available: ScopeAvailableData;
|
|
252
|
+
/**
|
|
253
|
+
* Manages the output variables for this scope.
|
|
254
|
+
*/
|
|
255
|
+
readonly output: ScopeOutputData;
|
|
256
|
+
/**
|
|
257
|
+
* Manages event dispatching and handling for this scope.
|
|
258
|
+
*/
|
|
259
|
+
readonly event: ScopeEventData;
|
|
260
|
+
/**
|
|
261
|
+
* A memoization utility for caching computed values.
|
|
262
|
+
*/
|
|
263
|
+
protected memo: {
|
|
264
|
+
<T>(key: string | symbol, fn: () => T): T;
|
|
265
|
+
clear: (key?: string | symbol) => void;
|
|
266
|
+
};
|
|
267
|
+
toDispose: DisposableCollection;
|
|
268
|
+
constructor(options: {
|
|
269
|
+
id: string | symbol;
|
|
270
|
+
variableEngine: VariableEngine;
|
|
271
|
+
meta?: ScopeMeta;
|
|
272
|
+
});
|
|
273
|
+
/**
|
|
274
|
+
* Refreshes the covering scopes.
|
|
275
|
+
*/
|
|
276
|
+
refreshCovers(): void;
|
|
277
|
+
/**
|
|
278
|
+
* Refreshes the dependency scopes and the available variables.
|
|
279
|
+
*/
|
|
280
|
+
refreshDeps(): void;
|
|
281
|
+
/**
|
|
282
|
+
* Gets the scopes that this scope depends on.
|
|
283
|
+
*/
|
|
284
|
+
get depScopes(): Scope[];
|
|
285
|
+
/**
|
|
286
|
+
* Gets the scopes that are covered by this scope.
|
|
287
|
+
*/
|
|
288
|
+
get coverScopes(): Scope[];
|
|
289
|
+
/**
|
|
290
|
+
* Disposes of the scope and its resources.
|
|
291
|
+
* This will also trigger updates in dependent and covering scopes.
|
|
292
|
+
*/
|
|
293
|
+
dispose(): void;
|
|
294
|
+
onDispose: _flowgram_ai_utils.Event<void>;
|
|
295
|
+
get disposed(): boolean;
|
|
296
|
+
/**
|
|
297
|
+
* Sets a variable in the scope with the default key 'outputs'.
|
|
298
|
+
*
|
|
299
|
+
* @param json The JSON representation of the AST node to set.
|
|
300
|
+
* @returns The created or updated AST node.
|
|
301
|
+
*/
|
|
302
|
+
setVar<Node extends ASTNode = ASTNode>(json: ASTNodeJSON): Node;
|
|
303
|
+
/**
|
|
304
|
+
* Sets a variable in the scope with a specified key.
|
|
305
|
+
*
|
|
306
|
+
* @param key The key of the variable to set.
|
|
307
|
+
* @param json The JSON representation of the AST node to set.
|
|
308
|
+
* @returns The created or updated AST node.
|
|
309
|
+
*/
|
|
310
|
+
setVar<Node extends ASTNode = ASTNode>(key: string, json: ASTNodeJSON): Node;
|
|
311
|
+
/**
|
|
312
|
+
* Retrieves a variable from the scope by its key.
|
|
313
|
+
*
|
|
314
|
+
* @param key The key of the variable to retrieve. Defaults to 'outputs'.
|
|
315
|
+
* @returns The AST node for the variable, or `undefined` if not found.
|
|
316
|
+
*/
|
|
317
|
+
getVar<Node extends ASTNode = ASTNode>(key?: string): Node | undefined;
|
|
318
|
+
/**
|
|
319
|
+
* Clears a variable from the scope by its key.
|
|
320
|
+
*
|
|
321
|
+
* @param key The key of the variable to clear. Defaults to 'outputs'.
|
|
322
|
+
*/
|
|
323
|
+
clearVar(key?: string): void;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Manages the dependency relationships between scopes.
|
|
328
|
+
* This is an abstract class, and specific implementations determine how the scope order is managed.
|
|
16
329
|
*/
|
|
17
330
|
declare abstract class ScopeChain {
|
|
18
331
|
readonly toDispose: DisposableCollection;
|
|
@@ -20,982 +333,1948 @@ declare abstract class ScopeChain {
|
|
|
20
333
|
get variableEngine(): VariableEngine;
|
|
21
334
|
constructor();
|
|
22
335
|
/**
|
|
23
|
-
*
|
|
336
|
+
* Refreshes the dependency and coverage relationships for all scopes.
|
|
24
337
|
*/
|
|
25
338
|
refreshAllChange(): void;
|
|
26
|
-
abstract getDeps(scope: Scope): Scope[];
|
|
27
|
-
abstract getCovers(scope: Scope): Scope[];
|
|
28
|
-
abstract sortAll(): Scope[];
|
|
29
|
-
dispose(): void;
|
|
30
|
-
get disposed(): boolean;
|
|
31
|
-
get onDispose(): Event<void>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
declare enum ASTNodeFlags {
|
|
35
|
-
None = 0,
|
|
36
339
|
/**
|
|
37
|
-
*
|
|
340
|
+
* Gets the dependency scopes for a given scope.
|
|
341
|
+
* @param scope The scope to get dependencies for.
|
|
342
|
+
* @returns An array of dependency scopes.
|
|
38
343
|
*/
|
|
39
|
-
|
|
344
|
+
abstract getDeps(scope: Scope): Scope[];
|
|
40
345
|
/**
|
|
41
|
-
*
|
|
346
|
+
* Gets the covering scopes for a given scope.
|
|
347
|
+
* @param scope The scope to get covers for.
|
|
348
|
+
* @returns An array of covering scopes.
|
|
42
349
|
*/
|
|
43
|
-
|
|
350
|
+
abstract getCovers(scope: Scope): Scope[];
|
|
44
351
|
/**
|
|
45
|
-
*
|
|
352
|
+
* Sorts all scopes based on their dependency relationships.
|
|
353
|
+
* @returns A sorted array of all scopes.
|
|
46
354
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
VariableType = 120
|
|
355
|
+
abstract sortAll(): Scope[];
|
|
356
|
+
dispose(): void;
|
|
357
|
+
get disposed(): boolean;
|
|
358
|
+
get onDispose(): Event<void>;
|
|
52
359
|
}
|
|
53
360
|
|
|
54
|
-
interface ASTNodeRegistry<JSON extends ASTNodeJSON = any
|
|
361
|
+
interface ASTNodeRegistry<JSON extends ASTNodeJSON = any> {
|
|
55
362
|
kind: string;
|
|
56
|
-
new (params: CreateASTParams, injectOpts:
|
|
363
|
+
new (params: CreateASTParams, injectOpts: any): ASTNode<JSON>;
|
|
57
364
|
}
|
|
58
|
-
|
|
365
|
+
/**
|
|
366
|
+
* An `ASTNode` represents a fundamental unit of variable information within the system's Abstract Syntax Tree.
|
|
367
|
+
* It can model various constructs, for example:
|
|
368
|
+
* - **Declarations**: `const a = 1`
|
|
369
|
+
* - **Expressions**: `a.b.c`
|
|
370
|
+
* - **Types**: `number`, `string`, `boolean`
|
|
371
|
+
*
|
|
372
|
+
* Here is some characteristic of ASTNode:
|
|
373
|
+
* - **Tree-like Structure**: ASTNodes can be nested to form a tree, representing complex variable structures.
|
|
374
|
+
* - **Extendable**: New features can be added by extending the base ASTNode class.
|
|
375
|
+
* - **Reactive**: Changes in an ASTNode's value trigger events, enabling reactive programming patterns.
|
|
376
|
+
* - **Serializable**: ASTNodes can be converted to and from a JSON format (ASTNodeJSON) for storage or transmission.
|
|
377
|
+
*/
|
|
378
|
+
declare abstract class ASTNode<JSON extends ASTNodeJSON = any> implements Disposable {
|
|
59
379
|
/**
|
|
60
380
|
* @deprecated
|
|
61
|
-
*
|
|
381
|
+
* Get the injected options for the ASTNode.
|
|
62
382
|
*
|
|
63
|
-
*
|
|
383
|
+
* Please use `@injectToAst(XXXService) declare xxxService: XXXService` to achieve external dependency injection.
|
|
64
384
|
*/
|
|
65
|
-
readonly opts?:
|
|
385
|
+
readonly opts?: any;
|
|
66
386
|
/**
|
|
67
|
-
*
|
|
68
|
-
* -
|
|
387
|
+
* The unique identifier of the ASTNode, which is **immutable**.
|
|
388
|
+
* - Immutable: Once assigned, the key cannot be changed.
|
|
389
|
+
* - Automatically generated if not specified, and cannot be changed as well.
|
|
390
|
+
* - If a new key needs to be generated, the current ASTNode should be destroyed and a new ASTNode should be generated.
|
|
69
391
|
*/
|
|
70
392
|
readonly key: Identifier;
|
|
71
393
|
/**
|
|
72
|
-
*
|
|
394
|
+
* The kind of the ASTNode.
|
|
73
395
|
*/
|
|
74
396
|
static readonly kind: ASTKindType;
|
|
75
397
|
/**
|
|
76
|
-
*
|
|
398
|
+
* Node flags, used to record some flag information.
|
|
77
399
|
*/
|
|
78
400
|
readonly flags: number;
|
|
79
401
|
/**
|
|
80
|
-
*
|
|
402
|
+
* The scope in which the ASTNode is located.
|
|
81
403
|
*/
|
|
82
404
|
readonly scope: Scope;
|
|
83
405
|
/**
|
|
84
|
-
*
|
|
406
|
+
* The parent ASTNode.
|
|
85
407
|
*/
|
|
86
408
|
readonly parent: ASTNode | undefined;
|
|
87
409
|
/**
|
|
88
|
-
*
|
|
410
|
+
* The version number of the ASTNode, which increments by 1 each time `fireChange` is called.
|
|
89
411
|
*/
|
|
90
|
-
|
|
412
|
+
protected _version: number;
|
|
91
413
|
/**
|
|
92
|
-
*
|
|
414
|
+
* Update lock.
|
|
415
|
+
* - When set to `true`, `fireChange` will not trigger any events.
|
|
416
|
+
* - This is useful when multiple updates are needed, and you want to avoid multiple triggers.
|
|
93
417
|
*/
|
|
94
418
|
changeLocked: boolean;
|
|
95
419
|
/**
|
|
96
|
-
*
|
|
420
|
+
* Parameters related to batch updates.
|
|
97
421
|
*/
|
|
98
422
|
private _batch;
|
|
99
423
|
/**
|
|
100
|
-
* AST
|
|
101
|
-
* -
|
|
424
|
+
* AST node change Observable events, implemented based on RxJS.
|
|
425
|
+
* - Emits the current ASTNode value upon subscription.
|
|
426
|
+
* - Emits a new value whenever `fireChange` is called.
|
|
102
427
|
*/
|
|
103
428
|
readonly value$: BehaviorSubject<ASTNode>;
|
|
104
429
|
/**
|
|
105
|
-
*
|
|
430
|
+
* Child ASTNodes.
|
|
106
431
|
*/
|
|
107
|
-
protected _children: Set<ASTNode<any
|
|
432
|
+
protected _children: Set<ASTNode<any>>;
|
|
108
433
|
/**
|
|
109
|
-
*
|
|
434
|
+
* List of disposal handlers for the ASTNode.
|
|
110
435
|
*/
|
|
111
436
|
readonly toDispose: DisposableCollection;
|
|
112
437
|
/**
|
|
113
|
-
*
|
|
438
|
+
* Callback triggered upon disposal.
|
|
114
439
|
*/
|
|
115
440
|
onDispose: _flowgram_ai_utils.Event<void>;
|
|
116
441
|
/**
|
|
117
|
-
*
|
|
118
|
-
* @param createParams
|
|
119
|
-
* @param injectOptions
|
|
442
|
+
* Constructor.
|
|
443
|
+
* @param createParams Necessary parameters for creating an ASTNode.
|
|
444
|
+
* @param injectOptions Dependency injection for various modules.
|
|
120
445
|
*/
|
|
121
|
-
constructor({ key, parent, scope }: CreateASTParams, opts?:
|
|
446
|
+
constructor({ key, parent, scope }: CreateASTParams, opts?: any);
|
|
122
447
|
/**
|
|
123
|
-
*
|
|
448
|
+
* The type of the ASTNode.
|
|
124
449
|
*/
|
|
125
450
|
get kind(): string;
|
|
126
451
|
/**
|
|
127
|
-
*
|
|
128
|
-
* @param json AST JSON
|
|
452
|
+
* Parses AST JSON data.
|
|
453
|
+
* @param json AST JSON data.
|
|
129
454
|
*/
|
|
130
455
|
abstract fromJSON(json: JSON): void;
|
|
131
456
|
/**
|
|
132
|
-
*
|
|
457
|
+
* Gets all child ASTNodes of the current ASTNode.
|
|
133
458
|
*/
|
|
134
459
|
get children(): ASTNode[];
|
|
135
460
|
/**
|
|
136
|
-
*
|
|
461
|
+
* Serializes the current ASTNode to ASTNodeJSON.
|
|
137
462
|
* @returns
|
|
138
463
|
*/
|
|
139
|
-
toJSON():
|
|
464
|
+
abstract toJSON(): JSON;
|
|
140
465
|
/**
|
|
141
|
-
*
|
|
142
|
-
* @param json
|
|
466
|
+
* Creates a child ASTNode.
|
|
467
|
+
* @param json The AST JSON of the child ASTNode.
|
|
143
468
|
* @returns
|
|
144
469
|
*/
|
|
145
470
|
protected createChildNode<ChildNode extends ASTNode = ASTNode>(json: ASTNodeJSON): ChildNode;
|
|
146
471
|
/**
|
|
147
|
-
*
|
|
148
|
-
* @param keyInThis
|
|
472
|
+
* Updates a child ASTNode, quickly implementing the consumption logic for child ASTNode updates.
|
|
473
|
+
* @param keyInThis The specified key on the current object.
|
|
149
474
|
*/
|
|
150
475
|
protected updateChildNodeByKey(keyInThis: keyof this, nextJSON?: ASTNodeJSON): void;
|
|
151
476
|
/**
|
|
152
|
-
*
|
|
153
|
-
* @param updater
|
|
477
|
+
* Batch updates the ASTNode, merging all `fireChange` calls within the batch function into one.
|
|
478
|
+
* @param updater The batch function.
|
|
154
479
|
* @returns
|
|
155
480
|
*/
|
|
156
481
|
protected withBatchUpdate<ParamTypes extends any[], ReturnType>(updater: (...args: ParamTypes) => ReturnType): (...args: ParamTypes) => ReturnType;
|
|
157
482
|
/**
|
|
158
|
-
*
|
|
483
|
+
* Triggers an update for the current node.
|
|
159
484
|
*/
|
|
160
485
|
fireChange(): void;
|
|
161
486
|
/**
|
|
162
|
-
*
|
|
163
|
-
* -
|
|
487
|
+
* The version value of the ASTNode.
|
|
488
|
+
* - You can used to check whether ASTNode are updated.
|
|
164
489
|
*/
|
|
165
490
|
get version(): number;
|
|
166
491
|
/**
|
|
167
|
-
*
|
|
492
|
+
* The unique hash value of the ASTNode.
|
|
493
|
+
* - It will update when the ASTNode is updated.
|
|
494
|
+
* - You can used to check two ASTNode are equal.
|
|
168
495
|
*/
|
|
169
496
|
get hash(): string;
|
|
170
497
|
/**
|
|
171
|
-
*
|
|
172
|
-
* @param observer
|
|
173
|
-
* @param selector
|
|
498
|
+
* Listens for changes to the ASTNode.
|
|
499
|
+
* @param observer The listener callback.
|
|
500
|
+
* @param selector Listens for specified data.
|
|
174
501
|
* @returns
|
|
175
502
|
*/
|
|
176
503
|
subscribe<Data = this>(observer: ObserverOrNext<Data>, { selector, debounceAnimation, triggerOnInit }?: SubscribeConfig<this, Data>): Disposable;
|
|
504
|
+
/**
|
|
505
|
+
* Dispatches a global event for the current ASTNode.
|
|
506
|
+
* @param event The global event.
|
|
507
|
+
*/
|
|
177
508
|
dispatchGlobalEvent<ActionType extends GlobalEventActionType = GlobalEventActionType>(event: Omit<ActionType, 'ast'>): void;
|
|
178
509
|
/**
|
|
179
|
-
*
|
|
510
|
+
* Disposes the ASTNode.
|
|
180
511
|
*/
|
|
181
512
|
dispose(): void;
|
|
182
513
|
get disposed(): boolean;
|
|
183
514
|
/**
|
|
184
|
-
*
|
|
515
|
+
* Extended information of the ASTNode.
|
|
185
516
|
*/
|
|
186
517
|
[key: string]: unknown;
|
|
187
518
|
}
|
|
188
519
|
|
|
189
520
|
/**
|
|
190
|
-
*
|
|
521
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
522
|
+
* SPDX-License-Identifier: MIT
|
|
191
523
|
*/
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
constructor(params: CreateASTParams);
|
|
524
|
+
|
|
525
|
+
type ASTKindType = string;
|
|
526
|
+
type Identifier = string;
|
|
527
|
+
/**
|
|
528
|
+
* ASTNodeJSON is the JSON representation of an ASTNode.
|
|
529
|
+
*/
|
|
530
|
+
interface ASTNodeJSON {
|
|
200
531
|
/**
|
|
201
|
-
*
|
|
532
|
+
* Kind is the type of the AST node.
|
|
202
533
|
*/
|
|
203
|
-
|
|
204
|
-
updateOrder(order?: number): void;
|
|
205
|
-
onTypeChange(observer: (type: ASTNode | undefined) => void): Disposable;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
interface VariableDeclarationListJSON<VariableMeta = any> {
|
|
534
|
+
kind?: ASTKindType;
|
|
209
535
|
/**
|
|
210
|
-
*
|
|
536
|
+
* Key is the unique identifier of the node.
|
|
537
|
+
* If not provided, the node will generate a default key value.
|
|
211
538
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
539
|
+
key?: Identifier;
|
|
540
|
+
[key: string]: any;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Core AST node types.
|
|
544
|
+
*/
|
|
545
|
+
declare enum ASTKind {
|
|
546
|
+
/**
|
|
547
|
+
* # Type-related.
|
|
548
|
+
* - A set of type AST nodes based on JSON types is implemented internally by default.
|
|
549
|
+
*/
|
|
550
|
+
/**
|
|
551
|
+
* String type.
|
|
552
|
+
*/
|
|
553
|
+
String = "String",
|
|
554
|
+
/**
|
|
555
|
+
* Number type.
|
|
556
|
+
*/
|
|
557
|
+
Number = "Number",
|
|
558
|
+
/**
|
|
559
|
+
* Integer type.
|
|
560
|
+
*/
|
|
561
|
+
Integer = "Integer",
|
|
562
|
+
/**
|
|
563
|
+
* Boolean type.
|
|
564
|
+
*/
|
|
565
|
+
Boolean = "Boolean",
|
|
566
|
+
/**
|
|
567
|
+
* Object type.
|
|
568
|
+
*/
|
|
569
|
+
Object = "Object",
|
|
570
|
+
/**
|
|
571
|
+
* Array type.
|
|
572
|
+
*/
|
|
573
|
+
Array = "Array",
|
|
574
|
+
/**
|
|
575
|
+
* Map type.
|
|
576
|
+
*/
|
|
577
|
+
Map = "Map",
|
|
578
|
+
/**
|
|
579
|
+
* Union type.
|
|
580
|
+
* Commonly used for type checking, generally not exposed to the business.
|
|
581
|
+
*/
|
|
582
|
+
Union = "Union",
|
|
583
|
+
/**
|
|
584
|
+
* Any type.
|
|
585
|
+
* Commonly used for business logic.
|
|
586
|
+
*/
|
|
587
|
+
Any = "Any",
|
|
588
|
+
/**
|
|
589
|
+
* Custom type.
|
|
590
|
+
* For business-defined types.
|
|
591
|
+
*/
|
|
592
|
+
CustomType = "CustomType",
|
|
593
|
+
/**
|
|
594
|
+
* # Declaration-related.
|
|
595
|
+
*/
|
|
596
|
+
/**
|
|
597
|
+
* Field definition for Object drill-down.
|
|
598
|
+
*/
|
|
599
|
+
Property = "Property",
|
|
600
|
+
/**
|
|
601
|
+
* Variable declaration.
|
|
602
|
+
*/
|
|
603
|
+
VariableDeclaration = "VariableDeclaration",
|
|
604
|
+
/**
|
|
605
|
+
* Variable declaration list.
|
|
606
|
+
*/
|
|
607
|
+
VariableDeclarationList = "VariableDeclarationList",
|
|
608
|
+
/**
|
|
609
|
+
* # Expression-related.
|
|
610
|
+
*/
|
|
611
|
+
/**
|
|
612
|
+
* Access fields on variables through the path system.
|
|
613
|
+
*/
|
|
614
|
+
KeyPathExpression = "KeyPathExpression",
|
|
615
|
+
/**
|
|
616
|
+
* Iterate over specified data.
|
|
617
|
+
*/
|
|
618
|
+
EnumerateExpression = "EnumerateExpression",
|
|
619
|
+
/**
|
|
620
|
+
* Wrap with Array Type.
|
|
621
|
+
*/
|
|
622
|
+
WrapArrayExpression = "WrapArrayExpression",
|
|
623
|
+
/**
|
|
624
|
+
* # General-purpose AST nodes.
|
|
625
|
+
*/
|
|
626
|
+
/**
|
|
627
|
+
* General-purpose List<ASTNode> storage node.
|
|
628
|
+
*/
|
|
629
|
+
ListNode = "ListNode",
|
|
630
|
+
/**
|
|
631
|
+
* General-purpose data storage node.
|
|
632
|
+
*/
|
|
633
|
+
DataNode = "DataNode",
|
|
634
|
+
/**
|
|
635
|
+
* General-purpose Map<string, ASTNode> storage node.
|
|
636
|
+
*/
|
|
637
|
+
MapNode = "MapNode"
|
|
638
|
+
}
|
|
639
|
+
interface CreateASTParams {
|
|
640
|
+
scope: Scope;
|
|
641
|
+
key?: Identifier;
|
|
642
|
+
parent?: ASTNode;
|
|
643
|
+
}
|
|
644
|
+
type ASTNodeJSONOrKind = string | ASTNodeJSON;
|
|
645
|
+
type ObserverOrNext<T> = Partial<Observer$1<T>> | ((value: T) => void);
|
|
646
|
+
interface SubscribeConfig<This, Data> {
|
|
647
|
+
debounceAnimation?: boolean;
|
|
648
|
+
triggerOnInit?: boolean;
|
|
649
|
+
selector?: (curr: This) => Data;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* TypeUtils to get the JSON representation of an AST node with a specific kind.
|
|
653
|
+
*/
|
|
654
|
+
type GetKindJSON<KindType extends string, JSON extends ASTNodeJSON> = {
|
|
655
|
+
kind: KindType;
|
|
656
|
+
key?: Identifier;
|
|
657
|
+
} & JSON;
|
|
658
|
+
/**
|
|
659
|
+
* TypeUtils to get the JSON representation of an AST node with a specific kind or just the kind string.
|
|
660
|
+
*/
|
|
661
|
+
type GetKindJSONOrKind<KindType extends string, JSON extends ASTNodeJSON> = ({
|
|
662
|
+
kind: KindType;
|
|
663
|
+
key?: Identifier;
|
|
664
|
+
} & JSON) | KindType;
|
|
665
|
+
/**
|
|
666
|
+
* Global event action type.
|
|
667
|
+
* - Global event might be dispatched from `ASTNode` or `Scope`.
|
|
668
|
+
*/
|
|
669
|
+
interface GlobalEventActionType<Type = string, Payload = any, AST extends ASTNode = ASTNode> {
|
|
670
|
+
type: Type;
|
|
671
|
+
payload?: Payload;
|
|
672
|
+
ast?: AST;
|
|
225
673
|
}
|
|
226
674
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
675
|
+
/**
|
|
676
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
677
|
+
* SPDX-License-Identifier: MIT
|
|
678
|
+
*/
|
|
679
|
+
|
|
680
|
+
type DataInjector = () => Record<string, any>;
|
|
681
|
+
/**
|
|
682
|
+
* Register the AST node to the engine.
|
|
683
|
+
*/
|
|
684
|
+
declare class ASTRegisters {
|
|
685
|
+
/**
|
|
686
|
+
* @deprecated Please use `@injectToAst(XXXService) declare xxxService: XXXService` to achieve external dependency injection.
|
|
687
|
+
*/
|
|
688
|
+
protected injectors: Map<ASTKindType, DataInjector>;
|
|
689
|
+
protected astMap: Map<ASTKindType, ASTNodeRegistry>;
|
|
690
|
+
/**
|
|
691
|
+
* Core AST node registration.
|
|
692
|
+
*/
|
|
693
|
+
constructor();
|
|
694
|
+
/**
|
|
695
|
+
* Creates an AST node.
|
|
696
|
+
* @param param Creation parameters.
|
|
697
|
+
* @returns
|
|
698
|
+
*/
|
|
699
|
+
createAST<ReturnNode extends ASTNode = ASTNode>(json: ASTNodeJSON, { parent, scope }: CreateASTParams): ReturnNode;
|
|
700
|
+
/**
|
|
701
|
+
* Gets the node Registry by AST node type.
|
|
702
|
+
* @param kind
|
|
703
|
+
* @returns
|
|
704
|
+
*/
|
|
705
|
+
getASTRegistryByKind(kind: ASTKindType): ASTNodeRegistry<any> | undefined;
|
|
706
|
+
/**
|
|
707
|
+
* Registers an AST node.
|
|
708
|
+
* @param ASTNode
|
|
709
|
+
*/
|
|
710
|
+
registerAST(ASTNode: ASTNodeRegistry,
|
|
711
|
+
/**
|
|
712
|
+
* @deprecated Please use `@injectToAst(XXXService) declare xxxService: XXXService` to achieve external dependency injection.
|
|
713
|
+
*/
|
|
714
|
+
injector?: DataInjector): void;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
719
|
+
* SPDX-License-Identifier: MIT
|
|
720
|
+
*/
|
|
721
|
+
/**
|
|
722
|
+
* ASTNode flags. Stored in the `flags` property of the `ASTNode`.
|
|
723
|
+
*/
|
|
724
|
+
declare enum ASTNodeFlags {
|
|
725
|
+
/**
|
|
726
|
+
* None.
|
|
727
|
+
*/
|
|
728
|
+
None = 0,
|
|
729
|
+
/**
|
|
730
|
+
* Variable Field.
|
|
731
|
+
*/
|
|
732
|
+
VariableField = 1,
|
|
733
|
+
/**
|
|
734
|
+
* Expression.
|
|
735
|
+
*/
|
|
736
|
+
Expression = 4,
|
|
737
|
+
/**
|
|
738
|
+
* # Variable Type Flags
|
|
739
|
+
*/
|
|
740
|
+
/**
|
|
741
|
+
* Basic type.
|
|
742
|
+
*/
|
|
743
|
+
BasicType = 8,
|
|
744
|
+
/**
|
|
745
|
+
* Drillable variable type.
|
|
746
|
+
*/
|
|
747
|
+
DrilldownType = 16,
|
|
748
|
+
/**
|
|
749
|
+
* Enumerable variable type.
|
|
750
|
+
*/
|
|
751
|
+
EnumerateType = 32,
|
|
752
|
+
/**
|
|
753
|
+
* Composite type, currently not in use.
|
|
754
|
+
*/
|
|
755
|
+
UnionType = 64,
|
|
756
|
+
/**
|
|
757
|
+
* Variable type.
|
|
758
|
+
*/
|
|
759
|
+
VariableType = 120
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
/**
|
|
763
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
764
|
+
* SPDX-License-Identifier: MIT
|
|
765
|
+
*/
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Represents a general data node with no child nodes.
|
|
769
|
+
*/
|
|
770
|
+
declare class DataNode<Data = any> extends ASTNode {
|
|
231
771
|
static kind: string;
|
|
772
|
+
protected _data: Data;
|
|
773
|
+
/**
|
|
774
|
+
* The data of the node.
|
|
775
|
+
*/
|
|
776
|
+
get data(): Data;
|
|
777
|
+
/**
|
|
778
|
+
* Deserializes the `DataNodeJSON` to the `DataNode`.
|
|
779
|
+
* @param json The `DataNodeJSON` to deserialize.
|
|
780
|
+
*/
|
|
781
|
+
fromJSON(json: Data): void;
|
|
782
|
+
/**
|
|
783
|
+
* Serialize the `DataNode` to `DataNodeJSON`.
|
|
784
|
+
* @returns The JSON representation of `DataNode`.
|
|
785
|
+
*/
|
|
786
|
+
toJSON(): {
|
|
787
|
+
kind: ASTKind;
|
|
788
|
+
} & Data;
|
|
789
|
+
/**
|
|
790
|
+
* Partially update the data of the node.
|
|
791
|
+
* @param nextData The data to be updated.
|
|
792
|
+
*/
|
|
793
|
+
partialUpdate(nextData: Data): void;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
798
|
+
* SPDX-License-Identifier: MIT
|
|
799
|
+
*/
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* ASTNodeJSON representation of `ListNode`
|
|
803
|
+
*/
|
|
804
|
+
interface ListNodeJSON {
|
|
805
|
+
/**
|
|
806
|
+
* The list of nodes.
|
|
807
|
+
*/
|
|
808
|
+
list: ASTNodeJSON[];
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Represents a list of nodes.
|
|
812
|
+
*/
|
|
813
|
+
declare class ListNode extends ASTNode<ListNodeJSON> {
|
|
814
|
+
static kind: string;
|
|
815
|
+
protected _list: ASTNode[];
|
|
816
|
+
/**
|
|
817
|
+
* The list of nodes.
|
|
818
|
+
*/
|
|
819
|
+
get list(): ASTNode[];
|
|
820
|
+
/**
|
|
821
|
+
* Deserializes the `ListNodeJSON` to the `ListNode`.
|
|
822
|
+
* @param json The `ListNodeJSON` to deserialize.
|
|
823
|
+
*/
|
|
824
|
+
fromJSON({ list }: ListNodeJSON): void;
|
|
825
|
+
/**
|
|
826
|
+
* Serialize the `ListNode` to `ListNodeJSON`.
|
|
827
|
+
* @returns The JSON representation of `ListNode`.
|
|
828
|
+
*/
|
|
829
|
+
toJSON(): {
|
|
830
|
+
kind: ASTKind;
|
|
831
|
+
list: any[];
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/**
|
|
836
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
837
|
+
* SPDX-License-Identifier: MIT
|
|
838
|
+
*/
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* ASTNodeJSON representation of `MapNode`
|
|
842
|
+
*/
|
|
843
|
+
interface MapNodeJSON {
|
|
844
|
+
/**
|
|
845
|
+
* The map of nodes.
|
|
846
|
+
*/
|
|
847
|
+
map: [string, ASTNodeJSON][];
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Represents a map of nodes.
|
|
851
|
+
*/
|
|
852
|
+
declare class MapNode extends ASTNode<MapNodeJSON> {
|
|
853
|
+
static kind: string;
|
|
854
|
+
protected map: Map<string, ASTNode>;
|
|
855
|
+
/**
|
|
856
|
+
* Deserializes the `MapNodeJSON` to the `MapNode`.
|
|
857
|
+
* @param json The `MapNodeJSON` to deserialize.
|
|
858
|
+
*/
|
|
859
|
+
fromJSON({ map }: MapNodeJSON): void;
|
|
860
|
+
/**
|
|
861
|
+
* Serialize the `MapNode` to `MapNodeJSON`.
|
|
862
|
+
* @returns The JSON representation of `MapNode`.
|
|
863
|
+
*/
|
|
864
|
+
toJSON(): {
|
|
865
|
+
kind: ASTKind;
|
|
866
|
+
map: [string, ASTNode<any>][];
|
|
867
|
+
};
|
|
868
|
+
/**
|
|
869
|
+
* Set a node in the map.
|
|
870
|
+
* @param key The key of the node.
|
|
871
|
+
* @param nextJSON The JSON representation of the node.
|
|
872
|
+
* @returns The node instance.
|
|
873
|
+
*/
|
|
874
|
+
set<Node extends ASTNode = ASTNode>(key: string, nextJSON: ASTNodeJSON): Node;
|
|
875
|
+
/**
|
|
876
|
+
* Remove a node from the map.
|
|
877
|
+
* @param key The key of the node.
|
|
878
|
+
*/
|
|
879
|
+
remove(key: string): void;
|
|
880
|
+
/**
|
|
881
|
+
* Get a node from the map.
|
|
882
|
+
* @param key The key of the node.
|
|
883
|
+
* @returns The node instance if found, otherwise `undefined`.
|
|
884
|
+
*/
|
|
885
|
+
get<Node extends ASTNode = ASTNode>(key: string): Node | undefined;
|
|
232
886
|
}
|
|
233
887
|
|
|
234
|
-
|
|
888
|
+
/**
|
|
889
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
890
|
+
* SPDX-License-Identifier: MIT
|
|
891
|
+
*/
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Base class for all types.
|
|
895
|
+
*
|
|
896
|
+
* All other types should extend this class.
|
|
897
|
+
*/
|
|
898
|
+
declare abstract class BaseType<JSON extends ASTNodeJSON = any> extends ASTNode<JSON> {
|
|
235
899
|
flags: number;
|
|
236
900
|
/**
|
|
237
|
-
*
|
|
238
|
-
* @param
|
|
901
|
+
* Check if the current type is equal to the target type.
|
|
902
|
+
* @param targetTypeJSONOrKind The type to compare with.
|
|
903
|
+
* @returns `true` if the types are equal, `false` otherwise.
|
|
239
904
|
*/
|
|
240
905
|
isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
|
|
241
906
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
907
|
+
* Get a variable field by key path.
|
|
908
|
+
*
|
|
909
|
+
* This method should be implemented by drillable types.
|
|
910
|
+
* @param keyPath The key path to search for.
|
|
911
|
+
* @returns The variable field if found, otherwise `undefined`.
|
|
244
912
|
*/
|
|
245
913
|
getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
|
|
246
|
-
toJSON(): ASTNodeJSON;
|
|
247
914
|
}
|
|
248
915
|
|
|
249
|
-
|
|
916
|
+
/**
|
|
917
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
918
|
+
* SPDX-License-Identifier: MIT
|
|
919
|
+
*/
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* ASTNodeJSON representation of the `StringType`.
|
|
923
|
+
*/
|
|
924
|
+
interface StringJSON {
|
|
925
|
+
/**
|
|
926
|
+
* see https://json-schema.org/understanding-json-schema/reference/type#format
|
|
927
|
+
*/
|
|
928
|
+
format?: string;
|
|
929
|
+
}
|
|
930
|
+
declare class StringType extends BaseType<StringJSON> {
|
|
250
931
|
flags: ASTNodeFlags;
|
|
251
932
|
static kind: string;
|
|
252
|
-
|
|
933
|
+
protected _format?: string;
|
|
934
|
+
/**
|
|
935
|
+
* see https://json-schema.org/understanding-json-schema/reference/string#format
|
|
936
|
+
*/
|
|
937
|
+
get format(): string | undefined;
|
|
938
|
+
/**
|
|
939
|
+
* Deserialize the `StringJSON` to the `StringType`.
|
|
940
|
+
*
|
|
941
|
+
* @param json StringJSON representation of the `StringType`.
|
|
942
|
+
*/
|
|
943
|
+
fromJSON(json?: StringJSON): void;
|
|
944
|
+
/**
|
|
945
|
+
* Serialize the `StringType` to `StringJSON`.
|
|
946
|
+
* @returns The JSON representation of `StringType`.
|
|
947
|
+
*/
|
|
948
|
+
toJSON(): {
|
|
949
|
+
format: string | undefined;
|
|
950
|
+
};
|
|
253
951
|
}
|
|
254
952
|
|
|
953
|
+
/**
|
|
954
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
955
|
+
* SPDX-License-Identifier: MIT
|
|
956
|
+
*/
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Represents an integer type.
|
|
960
|
+
*/
|
|
255
961
|
declare class IntegerType extends BaseType {
|
|
256
962
|
flags: ASTNodeFlags;
|
|
257
963
|
static kind: string;
|
|
964
|
+
/**
|
|
965
|
+
* Deserializes the `IntegerJSON` to the `IntegerType`.
|
|
966
|
+
* @param json The `IntegerJSON` to deserialize.
|
|
967
|
+
*/
|
|
258
968
|
fromJSON(): void;
|
|
969
|
+
toJSON(): {};
|
|
259
970
|
}
|
|
260
971
|
|
|
972
|
+
/**
|
|
973
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
974
|
+
* SPDX-License-Identifier: MIT
|
|
975
|
+
*/
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Represents a boolean type.
|
|
979
|
+
*/
|
|
261
980
|
declare class BooleanType extends BaseType {
|
|
262
981
|
static kind: string;
|
|
982
|
+
/**
|
|
983
|
+
* Deserializes the `BooleanJSON` to the `BooleanType`.
|
|
984
|
+
* @param json The `BooleanJSON` to deserialize.
|
|
985
|
+
*/
|
|
263
986
|
fromJSON(): void;
|
|
987
|
+
toJSON(): {};
|
|
264
988
|
}
|
|
265
989
|
|
|
990
|
+
/**
|
|
991
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
992
|
+
* SPDX-License-Identifier: MIT
|
|
993
|
+
*/
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Represents a number type.
|
|
997
|
+
*/
|
|
266
998
|
declare class NumberType extends BaseType {
|
|
267
999
|
static kind: string;
|
|
1000
|
+
/**
|
|
1001
|
+
* Deserializes the `NumberJSON` to the `NumberType`.
|
|
1002
|
+
* @param json The `NumberJSON` to deserialize.
|
|
1003
|
+
*/
|
|
268
1004
|
fromJSON(): void;
|
|
1005
|
+
toJSON(): {};
|
|
269
1006
|
}
|
|
270
1007
|
|
|
1008
|
+
/**
|
|
1009
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1010
|
+
* SPDX-License-Identifier: MIT
|
|
1011
|
+
*/
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* ASTNodeJSON representation of `ArrayType`
|
|
1015
|
+
*/
|
|
271
1016
|
interface ArrayJSON {
|
|
1017
|
+
/**
|
|
1018
|
+
* The type of the items in the array.
|
|
1019
|
+
*/
|
|
272
1020
|
items?: ASTNodeJSONOrKind;
|
|
273
1021
|
}
|
|
1022
|
+
/**
|
|
1023
|
+
* Represents an array type.
|
|
1024
|
+
*/
|
|
274
1025
|
declare class ArrayType extends BaseType<ArrayJSON> {
|
|
275
1026
|
flags: ASTNodeFlags;
|
|
276
1027
|
static kind: string;
|
|
1028
|
+
/**
|
|
1029
|
+
* The type of the items in the array.
|
|
1030
|
+
*/
|
|
277
1031
|
items: BaseType;
|
|
1032
|
+
/**
|
|
1033
|
+
* Deserializes the `ArrayJSON` to the `ArrayType`.
|
|
1034
|
+
* @param json The `ArrayJSON` to deserialize.
|
|
1035
|
+
*/
|
|
278
1036
|
fromJSON({ items }: ArrayJSON): void;
|
|
1037
|
+
/**
|
|
1038
|
+
* Whether the items type can be drilled down.
|
|
1039
|
+
*/
|
|
279
1040
|
get canDrilldownItems(): boolean;
|
|
1041
|
+
/**
|
|
1042
|
+
* Get a variable field by key path.
|
|
1043
|
+
* @param keyPath The key path to search for.
|
|
1044
|
+
* @returns The variable field if found, otherwise `undefined`.
|
|
1045
|
+
*/
|
|
280
1046
|
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
1047
|
+
/**
|
|
1048
|
+
* Check if the current type is equal to the target type.
|
|
1049
|
+
* @param targetTypeJSONOrKind The type to compare with.
|
|
1050
|
+
* @returns `true` if the types are equal, `false` otherwise.
|
|
1051
|
+
*/
|
|
281
1052
|
isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
|
|
282
1053
|
/**
|
|
283
|
-
* Array
|
|
284
|
-
* @param targetTypeJSON
|
|
285
|
-
* @returns
|
|
1054
|
+
* Array strong comparison.
|
|
1055
|
+
* @param targetTypeJSON The type to compare with.
|
|
1056
|
+
* @returns `true` if the types are equal, `false` otherwise.
|
|
286
1057
|
*/
|
|
287
1058
|
protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
|
|
288
|
-
|
|
1059
|
+
/**
|
|
1060
|
+
* Serialize the `ArrayType` to `ArrayJSON`
|
|
1061
|
+
* @returns The JSON representation of `ArrayType`.
|
|
1062
|
+
*/
|
|
1063
|
+
toJSON(): {
|
|
1064
|
+
kind: ASTKind;
|
|
1065
|
+
items: any;
|
|
1066
|
+
};
|
|
289
1067
|
}
|
|
290
1068
|
|
|
1069
|
+
/**
|
|
1070
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1071
|
+
* SPDX-License-Identifier: MIT
|
|
1072
|
+
*/
|
|
1073
|
+
|
|
1074
|
+
/**
|
|
1075
|
+
* ASTNodeJSON representation of `MapType`
|
|
1076
|
+
*/
|
|
291
1077
|
interface MapJSON {
|
|
1078
|
+
/**
|
|
1079
|
+
* The type of the keys in the map.
|
|
1080
|
+
*/
|
|
292
1081
|
keyType?: ASTNodeJSONOrKind;
|
|
1082
|
+
/**
|
|
1083
|
+
* The type of the values in the map.
|
|
1084
|
+
*/
|
|
293
1085
|
valueType?: ASTNodeJSONOrKind;
|
|
294
1086
|
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Represents a map type.
|
|
1089
|
+
*/
|
|
295
1090
|
declare class MapType extends BaseType<MapJSON> {
|
|
296
1091
|
static kind: string;
|
|
1092
|
+
/**
|
|
1093
|
+
* The type of the keys in the map.
|
|
1094
|
+
*/
|
|
297
1095
|
keyType: BaseType;
|
|
1096
|
+
/**
|
|
1097
|
+
* The type of the values in the map.
|
|
1098
|
+
*/
|
|
298
1099
|
valueType: BaseType;
|
|
1100
|
+
/**
|
|
1101
|
+
* Deserializes the `MapJSON` to the `MapType`.
|
|
1102
|
+
* @param json The `MapJSON` to deserialize.
|
|
1103
|
+
*/
|
|
299
1104
|
fromJSON({ keyType, valueType }: MapJSON): void;
|
|
1105
|
+
/**
|
|
1106
|
+
* Check if the current type is equal to the target type.
|
|
1107
|
+
* @param targetTypeJSONOrKind The type to compare with.
|
|
1108
|
+
* @returns `true` if the types are equal, `false` otherwise.
|
|
1109
|
+
*/
|
|
300
1110
|
isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
|
|
301
1111
|
/**
|
|
302
|
-
* Map
|
|
303
|
-
* @param targetTypeJSON
|
|
304
|
-
* @returns
|
|
1112
|
+
* Map strong comparison.
|
|
1113
|
+
* @param targetTypeJSON The type to compare with.
|
|
1114
|
+
* @returns `true` if the types are equal, `false` otherwise.
|
|
305
1115
|
*/
|
|
306
1116
|
protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
|
|
307
|
-
|
|
1117
|
+
/**
|
|
1118
|
+
* Serialize the node to a JSON object.
|
|
1119
|
+
* @returns The JSON representation of the node.
|
|
1120
|
+
*/
|
|
1121
|
+
toJSON(): {
|
|
1122
|
+
kind: ASTKind;
|
|
1123
|
+
keyType: any;
|
|
1124
|
+
valueType: any;
|
|
1125
|
+
};
|
|
308
1126
|
}
|
|
309
1127
|
|
|
1128
|
+
/**
|
|
1129
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1130
|
+
* SPDX-License-Identifier: MIT
|
|
1131
|
+
*/
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* ASTNodeJSON representation of the `Property`.
|
|
1135
|
+
*/
|
|
1136
|
+
type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta>;
|
|
1137
|
+
/**
|
|
1138
|
+
* `Property` is a variable field that represents a property of a `ObjectType`.
|
|
1139
|
+
*/
|
|
1140
|
+
declare class Property<VariableMeta = any> extends BaseVariableField<VariableMeta> {
|
|
1141
|
+
static kind: string;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* ASTNodeJSON representation of `ObjectType`
|
|
1146
|
+
*/
|
|
310
1147
|
interface ObjectJSON<VariableMeta = any> {
|
|
311
1148
|
/**
|
|
312
|
-
*
|
|
1149
|
+
* The properties of the object.
|
|
1150
|
+
*
|
|
1151
|
+
* The `properties` of an Object must be of type `Property`, so the business can omit the `kind` field.
|
|
313
1152
|
*/
|
|
314
1153
|
properties?: PropertyJSON<VariableMeta>[];
|
|
315
1154
|
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Action type for object properties change.
|
|
1157
|
+
*/
|
|
316
1158
|
type ObjectPropertiesChangeAction = GlobalEventActionType<'ObjectPropertiesChange', {
|
|
317
1159
|
prev: Property[];
|
|
318
1160
|
next: Property[];
|
|
319
1161
|
}, ObjectType>;
|
|
1162
|
+
/**
|
|
1163
|
+
* Represents an object type.
|
|
1164
|
+
*/
|
|
320
1165
|
declare class ObjectType extends BaseType<ObjectJSON> {
|
|
321
1166
|
flags: ASTNodeFlags;
|
|
322
1167
|
static kind: string;
|
|
1168
|
+
/**
|
|
1169
|
+
* A map of property keys to `Property` instances.
|
|
1170
|
+
*/
|
|
323
1171
|
propertyTable: Map<string, Property>;
|
|
1172
|
+
/**
|
|
1173
|
+
* An array of `Property` instances.
|
|
1174
|
+
*/
|
|
324
1175
|
properties: Property[];
|
|
1176
|
+
/**
|
|
1177
|
+
* Deserializes the `ObjectJSON` to the `ObjectType`.
|
|
1178
|
+
* @param json The `ObjectJSON` to deserialize.
|
|
1179
|
+
*/
|
|
325
1180
|
fromJSON({ properties }: ObjectJSON): void;
|
|
326
|
-
toJSON(): ASTNodeJSON;
|
|
327
1181
|
/**
|
|
328
|
-
*
|
|
329
|
-
* @
|
|
330
|
-
|
|
1182
|
+
* Serialize the `ObjectType` to `ObjectJSON`.
|
|
1183
|
+
* @returns The JSON representation of `ObjectType`.
|
|
1184
|
+
*/
|
|
1185
|
+
toJSON(): {
|
|
1186
|
+
properties: BaseVariableFieldJSON<any>[];
|
|
1187
|
+
};
|
|
1188
|
+
/**
|
|
1189
|
+
* Get a variable field by key path.
|
|
1190
|
+
* @param keyPath The key path to search for.
|
|
1191
|
+
* @returns The variable field if found, otherwise `undefined`.
|
|
331
1192
|
*/
|
|
332
1193
|
getByKeyPath(keyPath: string[]): Property | undefined;
|
|
1194
|
+
/**
|
|
1195
|
+
* Check if the current type is equal to the target type.
|
|
1196
|
+
* @param targetTypeJSONOrKind The type to compare with.
|
|
1197
|
+
* @returns `true` if the types are equal, `false` otherwise.
|
|
1198
|
+
*/
|
|
333
1199
|
isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
|
|
334
1200
|
/**
|
|
335
|
-
* Object
|
|
336
|
-
* @param targetTypeJSON
|
|
337
|
-
* @returns
|
|
1201
|
+
* Object type strong comparison.
|
|
1202
|
+
* @param targetTypeJSON The type to compare with.
|
|
1203
|
+
* @returns `true` if the types are equal, `false` otherwise.
|
|
338
1204
|
*/
|
|
339
1205
|
protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
|
|
340
1206
|
}
|
|
341
1207
|
|
|
1208
|
+
/**
|
|
1209
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1210
|
+
* SPDX-License-Identifier: MIT
|
|
1211
|
+
*/
|
|
1212
|
+
|
|
1213
|
+
/**
|
|
1214
|
+
* ASTNodeJSON representation of `UnionType`, which union multiple `BaseType`.
|
|
1215
|
+
*/
|
|
342
1216
|
interface UnionJSON {
|
|
343
1217
|
types?: ASTNodeJSONOrKind[];
|
|
344
1218
|
}
|
|
345
1219
|
|
|
1220
|
+
/**
|
|
1221
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1222
|
+
* SPDX-License-Identifier: MIT
|
|
1223
|
+
*/
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* ASTNodeJSON representation of `CustomType`
|
|
1227
|
+
*/
|
|
1228
|
+
interface CustomTypeJSON {
|
|
1229
|
+
/**
|
|
1230
|
+
* The name of the custom type.
|
|
1231
|
+
*/
|
|
1232
|
+
typeName: string;
|
|
1233
|
+
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Represents a custom type.
|
|
1236
|
+
*/
|
|
1237
|
+
declare class CustomType extends BaseType<CustomTypeJSON> {
|
|
1238
|
+
static kind: string;
|
|
1239
|
+
protected _typeName: string;
|
|
1240
|
+
/**
|
|
1241
|
+
* The name of the custom type.
|
|
1242
|
+
*/
|
|
1243
|
+
get typeName(): string;
|
|
1244
|
+
/**
|
|
1245
|
+
* Deserializes the `CustomTypeJSON` to the `CustomType`.
|
|
1246
|
+
* @param json The `CustomTypeJSON` to deserialize.
|
|
1247
|
+
*/
|
|
1248
|
+
fromJSON(json: CustomTypeJSON): void;
|
|
1249
|
+
/**
|
|
1250
|
+
* Check if the current type is equal to the target type.
|
|
1251
|
+
* @param targetTypeJSONOrKind The type to compare with.
|
|
1252
|
+
* @returns `true` if the types are equal, `false` otherwise.
|
|
1253
|
+
*/
|
|
1254
|
+
isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
|
|
1255
|
+
toJSON(): {
|
|
1256
|
+
typeName: string;
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1262
|
+
* SPDX-License-Identifier: MIT
|
|
1263
|
+
*/
|
|
1264
|
+
|
|
346
1265
|
type ExpressionRefs = (BaseVariableField | undefined)[];
|
|
347
|
-
|
|
1266
|
+
/**
|
|
1267
|
+
* Base class for all expressions.
|
|
1268
|
+
*
|
|
1269
|
+
* All other expressions should extend this class.
|
|
1270
|
+
*/
|
|
1271
|
+
declare abstract class BaseExpression<JSON extends ASTNodeJSON = any> extends ASTNode<JSON> {
|
|
348
1272
|
flags: ASTNodeFlags;
|
|
349
1273
|
/**
|
|
350
|
-
*
|
|
1274
|
+
* Get the global variable table, which is used to access referenced variables.
|
|
351
1275
|
*/
|
|
352
|
-
get globalVariableTable():
|
|
1276
|
+
get globalVariableTable(): IVariableTable;
|
|
353
1277
|
/**
|
|
354
|
-
*
|
|
1278
|
+
* Parent variable fields, sorted from closest to farthest.
|
|
355
1279
|
*/
|
|
356
1280
|
get parentFields(): BaseVariableField[];
|
|
357
1281
|
/**
|
|
358
|
-
*
|
|
359
|
-
*
|
|
1282
|
+
* Get the variable fields referenced by the expression.
|
|
1283
|
+
*
|
|
1284
|
+
* This method should be implemented by subclasses.
|
|
1285
|
+
* @returns An array of referenced variable fields.
|
|
360
1286
|
*/
|
|
361
1287
|
abstract getRefFields(): ExpressionRefs;
|
|
362
1288
|
/**
|
|
363
|
-
*
|
|
1289
|
+
* The return type of the expression.
|
|
364
1290
|
*/
|
|
365
1291
|
abstract returnType: BaseType | undefined;
|
|
366
1292
|
/**
|
|
367
|
-
*
|
|
1293
|
+
* The variable fields referenced by the expression.
|
|
368
1294
|
*/
|
|
369
1295
|
protected _refs: ExpressionRefs;
|
|
1296
|
+
/**
|
|
1297
|
+
* The variable fields referenced by the expression.
|
|
1298
|
+
*/
|
|
370
1299
|
get refs(): ExpressionRefs;
|
|
371
1300
|
protected refreshRefs$: Subject<void>;
|
|
372
1301
|
/**
|
|
373
|
-
*
|
|
1302
|
+
* Refresh the variable references.
|
|
374
1303
|
*/
|
|
375
1304
|
refreshRefs(): void;
|
|
376
1305
|
/**
|
|
377
|
-
*
|
|
378
|
-
* 监听 [a.b.c] -> [a.b]
|
|
1306
|
+
* An observable that emits the referenced variable fields when they change.
|
|
379
1307
|
*/
|
|
380
1308
|
refs$: Observable<ExpressionRefs>;
|
|
381
|
-
constructor(params: CreateASTParams, opts?:
|
|
1309
|
+
constructor(params: CreateASTParams, opts?: any);
|
|
382
1310
|
}
|
|
383
1311
|
|
|
384
|
-
|
|
385
|
-
|
|
1312
|
+
/**
|
|
1313
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1314
|
+
* SPDX-License-Identifier: MIT
|
|
1315
|
+
*/
|
|
1316
|
+
|
|
1317
|
+
/**
|
|
1318
|
+
* ASTNodeJSON representation of `EnumerateExpression`
|
|
1319
|
+
*/
|
|
1320
|
+
interface EnumerateExpressionJSON {
|
|
1321
|
+
/**
|
|
1322
|
+
* The expression to be enumerated.
|
|
1323
|
+
*/
|
|
1324
|
+
enumerateFor: ASTNodeJSON;
|
|
386
1325
|
}
|
|
387
|
-
|
|
1326
|
+
/**
|
|
1327
|
+
* Represents an enumeration expression, which iterates over a list and returns the type of the enumerated variable.
|
|
1328
|
+
*/
|
|
1329
|
+
declare class EnumerateExpression extends BaseExpression<EnumerateExpressionJSON> {
|
|
388
1330
|
static kind: string;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
1331
|
+
protected _enumerateFor: BaseExpression | undefined;
|
|
1332
|
+
/**
|
|
1333
|
+
* The expression to be enumerated.
|
|
1334
|
+
*/
|
|
1335
|
+
get enumerateFor(): BaseExpression<any> | undefined;
|
|
1336
|
+
/**
|
|
1337
|
+
* The return type of the expression.
|
|
1338
|
+
*/
|
|
1339
|
+
get returnType(): BaseType | undefined;
|
|
1340
|
+
/**
|
|
1341
|
+
* Get the variable fields referenced by the expression.
|
|
1342
|
+
* @returns An empty array, as this expression does not reference any variables.
|
|
1343
|
+
*/
|
|
1344
|
+
getRefFields(): [];
|
|
1345
|
+
/**
|
|
1346
|
+
* Deserializes the `EnumerateExpressionJSON` to the `EnumerateExpression`.
|
|
1347
|
+
* @param json The `EnumerateExpressionJSON` to deserialize.
|
|
1348
|
+
*/
|
|
1349
|
+
fromJSON({ enumerateFor: expression }: EnumerateExpressionJSON): void;
|
|
1350
|
+
/**
|
|
1351
|
+
* Serialize the `EnumerateExpression` to `EnumerateExpressionJSON`.
|
|
1352
|
+
* @returns The JSON representation of `EnumerateExpression`.
|
|
1353
|
+
*/
|
|
1354
|
+
toJSON(): {
|
|
1355
|
+
kind: ASTKind;
|
|
1356
|
+
enumerateFor: any;
|
|
1357
|
+
};
|
|
392
1358
|
}
|
|
393
1359
|
|
|
1360
|
+
/**
|
|
1361
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1362
|
+
* SPDX-License-Identifier: MIT
|
|
1363
|
+
*/
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* ASTNodeJSON representation of `KeyPathExpression`
|
|
1367
|
+
*/
|
|
394
1368
|
interface KeyPathExpressionJSON$1 {
|
|
1369
|
+
/**
|
|
1370
|
+
* The key path of the variable.
|
|
1371
|
+
*/
|
|
395
1372
|
keyPath: string[];
|
|
396
1373
|
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Represents a key path expression, which is used to reference a variable by its key path.
|
|
1376
|
+
*
|
|
1377
|
+
* This is the V2 of `KeyPathExpression`, with the following improvements:
|
|
1378
|
+
* - `returnType` is copied to a new instance to avoid reference issues.
|
|
1379
|
+
* - Circular reference detection is introduced.
|
|
1380
|
+
*/
|
|
397
1381
|
declare class KeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON$1> extends BaseExpression<CustomPathJSON> {
|
|
398
1382
|
static kind: string;
|
|
399
1383
|
protected _keyPath: string[];
|
|
1384
|
+
protected _rawPathJson: CustomPathJSON;
|
|
1385
|
+
/**
|
|
1386
|
+
* The key path of the variable.
|
|
1387
|
+
*/
|
|
400
1388
|
get keyPath(): string[];
|
|
1389
|
+
/**
|
|
1390
|
+
* Get the variable fields referenced by the expression.
|
|
1391
|
+
* @returns An array of referenced variable fields.
|
|
1392
|
+
*/
|
|
401
1393
|
getRefFields(): BaseVariableField[];
|
|
402
|
-
get returnType(): BaseType | undefined;
|
|
403
1394
|
/**
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
|
|
1395
|
+
* The return type of the expression.
|
|
1396
|
+
*
|
|
1397
|
+
* A new `returnType` node is generated directly, instead of reusing the existing one, to ensure that different key paths do not point to the same field.
|
|
1398
|
+
*/
|
|
1399
|
+
_returnType: BaseType;
|
|
1400
|
+
/**
|
|
1401
|
+
* The return type of the expression.
|
|
1402
|
+
*/
|
|
1403
|
+
get returnType(): BaseType<any>;
|
|
1404
|
+
/**
|
|
1405
|
+
* Parse the business-defined path expression into a key path.
|
|
1406
|
+
*
|
|
1407
|
+
* Businesses can quickly customize their own path expressions by modifying this method.
|
|
1408
|
+
* @param json The path expression defined by the business.
|
|
1409
|
+
* @returns The key path.
|
|
408
1410
|
*/
|
|
409
1411
|
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
1412
|
+
/**
|
|
1413
|
+
* Deserializes the `KeyPathExpressionJSON` to the `KeyPathExpression`.
|
|
1414
|
+
* @param json The `KeyPathExpressionJSON` to deserialize.
|
|
1415
|
+
*/
|
|
410
1416
|
fromJSON(json: CustomPathJSON): void;
|
|
1417
|
+
/**
|
|
1418
|
+
* Get the return type JSON by reference.
|
|
1419
|
+
* @param _ref The referenced variable field.
|
|
1420
|
+
* @returns The JSON representation of the return type.
|
|
1421
|
+
*/
|
|
1422
|
+
getReturnTypeJSONByRef(_ref: BaseVariableField | undefined): ASTNodeJSON | undefined;
|
|
411
1423
|
constructor(params: CreateASTParams, opts: any);
|
|
412
|
-
|
|
1424
|
+
/**
|
|
1425
|
+
* Serialize the `KeyPathExpression` to `KeyPathExpressionJSON`.
|
|
1426
|
+
* @returns The JSON representation of `KeyPathExpression`.
|
|
1427
|
+
*/
|
|
1428
|
+
toJSON(): CustomPathJSON;
|
|
413
1429
|
}
|
|
414
1430
|
|
|
415
|
-
interface EnumerateExpressionJSON {
|
|
416
|
-
enumerateFor: ASTNodeJSON;
|
|
417
|
-
}
|
|
418
1431
|
/**
|
|
419
|
-
*
|
|
1432
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1433
|
+
* SPDX-License-Identifier: MIT
|
|
420
1434
|
*/
|
|
421
|
-
declare class EnumerateExpression extends BaseExpression<EnumerateExpressionJSON> {
|
|
422
|
-
static kind: string;
|
|
423
|
-
protected _enumerateFor: BaseExpression | undefined;
|
|
424
|
-
get enumerateFor(): BaseExpression<any, any> | undefined;
|
|
425
|
-
get returnType(): BaseType | undefined;
|
|
426
|
-
getRefFields(): [];
|
|
427
|
-
fromJSON({ enumerateFor: expression }: EnumerateExpressionJSON): void;
|
|
428
|
-
toJSON(): ASTNodeJSON;
|
|
429
|
-
}
|
|
430
1435
|
|
|
1436
|
+
/**
|
|
1437
|
+
* ASTNodeJSON representation of `KeyPathExpression`
|
|
1438
|
+
*/
|
|
431
1439
|
interface KeyPathExpressionJSON {
|
|
1440
|
+
/**
|
|
1441
|
+
* The key path of the variable.
|
|
1442
|
+
*/
|
|
432
1443
|
keyPath: string[];
|
|
433
1444
|
}
|
|
434
1445
|
/**
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
* - 引入成环检测
|
|
1446
|
+
* @deprecated Use `KeyPathExpression` instead.
|
|
1447
|
+
* Represents a key path expression, which is used to reference a variable by its key path.
|
|
438
1448
|
*/
|
|
439
|
-
declare class
|
|
1449
|
+
declare class LegacyKeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON> extends BaseExpression<CustomPathJSON> {
|
|
440
1450
|
static kind: string;
|
|
441
1451
|
protected _keyPath: string[];
|
|
442
|
-
|
|
443
|
-
getRefFields(): BaseVariableField[];
|
|
444
|
-
_returnType: BaseType;
|
|
445
|
-
get returnType(): BaseType<any, any>;
|
|
1452
|
+
protected _rawPathJson: CustomPathJSON;
|
|
446
1453
|
/**
|
|
447
|
-
*
|
|
448
|
-
* - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
|
|
449
|
-
* @param json 业务定义的 Path 表达式
|
|
450
|
-
* @returns
|
|
1454
|
+
* The key path of the variable.
|
|
451
1455
|
*/
|
|
452
|
-
|
|
453
|
-
fromJSON(json: CustomPathJSON): void;
|
|
454
|
-
getReturnTypeJSONByRef(_ref: BaseVariableField | undefined): ASTNodeJSON | undefined;
|
|
455
|
-
protected prevRefTypeHash: string | undefined;
|
|
456
|
-
constructor(params: CreateASTParams, opts: any);
|
|
457
|
-
toJSON(): ASTNodeJSON;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* 声明类 AST 节点
|
|
462
|
-
*/
|
|
463
|
-
type BaseVariableFieldJSON<VariableMeta = any> = {
|
|
464
|
-
key?: Identifier;
|
|
465
|
-
type?: ASTNodeJSONOrKind;
|
|
466
|
-
initializer?: ASTNodeJSON;
|
|
467
|
-
meta?: VariableMeta;
|
|
468
|
-
};
|
|
469
|
-
declare abstract class BaseVariableField<VariableMeta = any> extends ASTNode<BaseVariableFieldJSON<VariableMeta>> {
|
|
470
|
-
flags: ASTNodeFlags;
|
|
471
|
-
protected _type?: BaseType;
|
|
472
|
-
protected _meta: VariableMeta;
|
|
473
|
-
protected _initializer?: BaseExpression;
|
|
1456
|
+
get keyPath(): string[];
|
|
474
1457
|
/**
|
|
475
|
-
*
|
|
1458
|
+
* Get the variable fields referenced by the expression.
|
|
1459
|
+
* @returns An array of referenced variable fields.
|
|
476
1460
|
*/
|
|
477
|
-
|
|
478
|
-
get meta(): VariableMeta;
|
|
479
|
-
get type(): BaseType;
|
|
480
|
-
get initializer(): BaseExpression | undefined;
|
|
1461
|
+
getRefFields(): BaseVariableField[];
|
|
481
1462
|
/**
|
|
482
|
-
*
|
|
1463
|
+
* The return type of the expression.
|
|
483
1464
|
*/
|
|
484
|
-
|
|
485
|
-
updateType(type: BaseVariableFieldJSON['type']): void;
|
|
486
|
-
updateInitializer(nextInitializer?: BaseVariableFieldJSON['initializer']): void;
|
|
487
|
-
updateMeta(nextMeta: VariableMeta): void;
|
|
1465
|
+
get returnType(): BaseType | undefined;
|
|
488
1466
|
/**
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
1467
|
+
* Parse the business-defined path expression into a key path.
|
|
1468
|
+
*
|
|
1469
|
+
* Businesses can quickly customize their own path expressions by modifying this method.
|
|
1470
|
+
* @param json The path expression defined by the business.
|
|
1471
|
+
* @returns The key path.
|
|
492
1472
|
*/
|
|
493
|
-
|
|
1473
|
+
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
494
1474
|
/**
|
|
495
|
-
*
|
|
496
|
-
* @param
|
|
497
|
-
* @returns
|
|
1475
|
+
* Deserializes the `KeyPathExpressionJSON` to the `KeyPathExpression`.
|
|
1476
|
+
* @param json The `KeyPathExpressionJSON` to deserialize.
|
|
498
1477
|
*/
|
|
499
|
-
|
|
1478
|
+
fromJSON(json: CustomPathJSON): void;
|
|
1479
|
+
constructor(params: CreateASTParams, opts: any);
|
|
500
1480
|
/**
|
|
501
|
-
*
|
|
502
|
-
* @returns
|
|
1481
|
+
* Serialize the `KeyPathExpression` to `KeyPathExpressionJSON`.
|
|
1482
|
+
* @returns The JSON representation of `KeyPathExpression`.
|
|
503
1483
|
*/
|
|
504
|
-
toJSON():
|
|
505
|
-
kind: string;
|
|
506
|
-
};
|
|
1484
|
+
toJSON(): CustomPathJSON;
|
|
507
1485
|
}
|
|
508
1486
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
* @returns
|
|
519
|
-
*/
|
|
520
|
-
onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
|
|
1487
|
+
/**
|
|
1488
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1489
|
+
* SPDX-License-Identifier: MIT
|
|
1490
|
+
*/
|
|
1491
|
+
|
|
1492
|
+
/**
|
|
1493
|
+
* ASTNodeJSON representation of `WrapArrayExpression`
|
|
1494
|
+
*/
|
|
1495
|
+
interface WrapArrayExpressionJSON {
|
|
521
1496
|
/**
|
|
522
|
-
*
|
|
523
|
-
* @param observer
|
|
1497
|
+
* The expression to be wrapped.
|
|
524
1498
|
*/
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
1499
|
+
wrapFor: ASTNodeJSON;
|
|
1500
|
+
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Represents a wrap expression, which wraps an expression with an array.
|
|
1503
|
+
*/
|
|
1504
|
+
declare class WrapArrayExpression extends BaseExpression<WrapArrayExpressionJSON> {
|
|
1505
|
+
static kind: string;
|
|
1506
|
+
protected _wrapFor: BaseExpression | undefined;
|
|
1507
|
+
protected _returnType: BaseType | undefined;
|
|
533
1508
|
/**
|
|
534
|
-
*
|
|
535
|
-
* @param keyPath
|
|
536
|
-
* @returns
|
|
1509
|
+
* The expression to be wrapped.
|
|
537
1510
|
*/
|
|
538
|
-
|
|
1511
|
+
get wrapFor(): BaseExpression<any> | undefined;
|
|
539
1512
|
/**
|
|
540
|
-
*
|
|
541
|
-
* @param key
|
|
542
|
-
* @returns
|
|
1513
|
+
* The return type of the expression.
|
|
543
1514
|
*/
|
|
544
|
-
|
|
1515
|
+
get returnType(): BaseType | undefined;
|
|
545
1516
|
/**
|
|
546
|
-
*
|
|
547
|
-
* @param variable
|
|
1517
|
+
* Refresh the return type of the expression.
|
|
548
1518
|
*/
|
|
549
|
-
|
|
1519
|
+
refreshReturnType(): void;
|
|
550
1520
|
/**
|
|
551
|
-
*
|
|
552
|
-
* @
|
|
1521
|
+
* Get the variable fields referenced by the expression.
|
|
1522
|
+
* @returns An empty array, as this expression does not reference any variables.
|
|
553
1523
|
*/
|
|
554
|
-
|
|
555
|
-
dispose(): void;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* 作用域输出
|
|
560
|
-
*/
|
|
561
|
-
declare class ScopeOutputData {
|
|
562
|
-
readonly scope: Scope;
|
|
563
|
-
protected variableTable: VariableTable;
|
|
564
|
-
protected memo: {
|
|
565
|
-
<T>(key: string | symbol, fn: () => T): T;
|
|
566
|
-
clear: (key?: (string | symbol) | undefined) => void;
|
|
567
|
-
};
|
|
568
|
-
get variableEngine(): VariableEngine;
|
|
569
|
-
get globalVariableTable(): VariableTable;
|
|
570
|
-
get onDataChange(): _flowgram_ai_utils.Event<void>;
|
|
571
|
-
get onAnyVariableChange(): (observer: (changedVariable: VariableDeclaration<any>) => void) => _flowgram_ai_utils.Disposable;
|
|
572
|
-
protected _hasChanges: boolean;
|
|
573
|
-
constructor(scope: Scope);
|
|
1524
|
+
getRefFields(): [];
|
|
574
1525
|
/**
|
|
575
|
-
*
|
|
1526
|
+
* Deserializes the `WrapArrayExpressionJSON` to the `WrapArrayExpression`.
|
|
1527
|
+
* @param json The `WrapArrayExpressionJSON` to deserialize.
|
|
576
1528
|
*/
|
|
577
|
-
|
|
1529
|
+
fromJSON({ wrapFor: expression }: WrapArrayExpressionJSON): void;
|
|
578
1530
|
/**
|
|
579
|
-
*
|
|
1531
|
+
* Serialize the `WrapArrayExpression` to `WrapArrayExpressionJSON`.
|
|
1532
|
+
* @returns The JSON representation of `WrapArrayExpression`.
|
|
580
1533
|
*/
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
notifyCoversChange(): void;
|
|
1534
|
+
toJSON(): {
|
|
1535
|
+
kind: ASTKind;
|
|
1536
|
+
wrapFor: any;
|
|
1537
|
+
};
|
|
1538
|
+
protected init(): void;
|
|
587
1539
|
}
|
|
588
1540
|
|
|
589
1541
|
/**
|
|
590
|
-
*
|
|
1542
|
+
* ASTNodeJSON representation of `BaseVariableField`
|
|
591
1543
|
*/
|
|
592
|
-
|
|
593
|
-
readonly scope: Scope;
|
|
594
|
-
protected memo: {
|
|
595
|
-
<T>(key: string | symbol, fn: () => T): T;
|
|
596
|
-
clear: (key?: (string | symbol) | undefined) => void;
|
|
597
|
-
};
|
|
598
|
-
get globalVariableTable(): VariableTable;
|
|
599
|
-
protected refresh$: Subject<void>;
|
|
600
|
-
protected _variables: VariableDeclaration[];
|
|
601
|
-
refresh(): void;
|
|
1544
|
+
interface BaseVariableFieldJSON<VariableMeta = any> extends ASTNodeJSON {
|
|
602
1545
|
/**
|
|
603
|
-
*
|
|
1546
|
+
* key of the variable field
|
|
1547
|
+
* - For `VariableDeclaration`, the key should be global unique.
|
|
1548
|
+
* - For `Property`, the key is the property name.
|
|
604
1549
|
*/
|
|
605
|
-
|
|
606
|
-
protected anyVariableChange$: Observable<VariableDeclaration>;
|
|
1550
|
+
key: Identifier;
|
|
607
1551
|
/**
|
|
608
|
-
*
|
|
609
|
-
*
|
|
610
|
-
* @returns
|
|
1552
|
+
* type of the variable field, similar to js code:
|
|
1553
|
+
* `const v: string`
|
|
611
1554
|
*/
|
|
612
|
-
|
|
1555
|
+
type?: ASTNodeJSONOrKind;
|
|
613
1556
|
/**
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
1557
|
+
* initializer of the variable field, similar to js code:
|
|
1558
|
+
* `const v = 'hello'`
|
|
1559
|
+
*
|
|
1560
|
+
* with initializer, the type of field will be inferred from the initializer.
|
|
617
1561
|
*/
|
|
618
|
-
|
|
619
|
-
protected onDataChangeEmitter: Emitter<VariableDeclaration<any>[]>;
|
|
1562
|
+
initializer?: ASTNodeJSON;
|
|
620
1563
|
/**
|
|
621
|
-
*
|
|
1564
|
+
* meta data of the variable field, you cans store information like `title`, `icon`, etc.
|
|
622
1565
|
*/
|
|
623
|
-
|
|
624
|
-
|
|
1566
|
+
meta?: VariableMeta;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Variable Field abstract class, which is the base class for `VariableDeclaration` and `Property`
|
|
1570
|
+
*
|
|
1571
|
+
* - `VariableDeclaration` is used to declare a variable in a block scope.
|
|
1572
|
+
* - `Property` is used to declare a property in an object.
|
|
1573
|
+
*/
|
|
1574
|
+
declare abstract class BaseVariableField<VariableMeta = any> extends ASTNode<BaseVariableFieldJSON<VariableMeta>> {
|
|
1575
|
+
flags: ASTNodeFlags;
|
|
1576
|
+
protected _type?: BaseType;
|
|
1577
|
+
protected _meta: VariableMeta;
|
|
1578
|
+
protected _initializer?: BaseExpression;
|
|
625
1579
|
/**
|
|
626
|
-
*
|
|
1580
|
+
* Parent variable fields, sorted from closest to farthest
|
|
627
1581
|
*/
|
|
628
|
-
get
|
|
1582
|
+
get parentFields(): BaseVariableField[];
|
|
629
1583
|
/**
|
|
630
|
-
*
|
|
1584
|
+
* KeyPath of the variable field, sorted from farthest to closest
|
|
631
1585
|
*/
|
|
632
|
-
get
|
|
1586
|
+
get keyPath(): string[];
|
|
633
1587
|
/**
|
|
634
|
-
*
|
|
1588
|
+
* Metadata of the variable field, you cans store information like `title`, `icon`, etc.
|
|
635
1589
|
*/
|
|
636
|
-
get
|
|
1590
|
+
get meta(): VariableMeta;
|
|
637
1591
|
/**
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
* @returns
|
|
1592
|
+
* Type of the variable field, similar to js code:
|
|
1593
|
+
* `const v: string`
|
|
641
1594
|
*/
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
type Observer<ActionType extends GlobalEventActionType = GlobalEventActionType> = (action: ActionType) => void;
|
|
646
|
-
declare class ScopeEventData {
|
|
647
|
-
readonly scope: Scope;
|
|
648
|
-
event$: Subject<GlobalEventActionType>;
|
|
649
|
-
dispatch<ActionType extends GlobalEventActionType = GlobalEventActionType>(action: ActionType): void;
|
|
650
|
-
subscribe<ActionType extends GlobalEventActionType = GlobalEventActionType>(observer: Observer<ActionType>): Disposable;
|
|
651
|
-
on<ActionType extends GlobalEventActionType = GlobalEventActionType>(type: ActionType['type'], observer: Observer<ActionType>): Disposable;
|
|
652
|
-
constructor(scope: Scope);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
type ASTKindType = string;
|
|
656
|
-
type Identifier = string;
|
|
657
|
-
interface ASTNodeJSON {
|
|
658
|
-
kind?: ASTKindType;
|
|
659
|
-
key?: Identifier;
|
|
660
|
-
[key: string]: any;
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* 核心 AST 节点类型
|
|
664
|
-
*/
|
|
665
|
-
declare enum ASTKind {
|
|
1595
|
+
get type(): BaseType;
|
|
666
1596
|
/**
|
|
667
|
-
*
|
|
668
|
-
*
|
|
1597
|
+
* Initializer of the variable field, similar to js code:
|
|
1598
|
+
* `const v = 'hello'`
|
|
1599
|
+
*
|
|
1600
|
+
* with initializer, the type of field will be inferred from the initializer.
|
|
669
1601
|
*/
|
|
670
|
-
|
|
671
|
-
Number = "Number",
|
|
672
|
-
Integer = "Integer",
|
|
673
|
-
Boolean = "Boolean",
|
|
674
|
-
Object = "Object",
|
|
675
|
-
Array = "Array",
|
|
676
|
-
Map = "Map",
|
|
677
|
-
Union = "Union",
|
|
678
|
-
Any = "Any",
|
|
1602
|
+
get initializer(): BaseExpression | undefined;
|
|
679
1603
|
/**
|
|
680
|
-
*
|
|
1604
|
+
* The global unique hash of the field, and will be changed when the field is updated.
|
|
681
1605
|
*/
|
|
682
|
-
|
|
683
|
-
VariableDeclaration = "VariableDeclaration",
|
|
684
|
-
VariableDeclarationList = "VariableDeclarationList",
|
|
1606
|
+
get hash(): string;
|
|
685
1607
|
/**
|
|
686
|
-
*
|
|
1608
|
+
* Deserialize the `BaseVariableFieldJSON` to the `BaseVariableField`.
|
|
1609
|
+
* @param json ASTJSON representation of `BaseVariableField`
|
|
687
1610
|
*/
|
|
688
|
-
|
|
689
|
-
EnumerateExpression = "EnumerateExpression",
|
|
690
|
-
ExpressionList = "ExpressionList",
|
|
1611
|
+
fromJSON({ type, initializer, meta }: Omit<BaseVariableFieldJSON<VariableMeta>, 'key'>): void;
|
|
691
1612
|
/**
|
|
692
|
-
*
|
|
1613
|
+
* Update the type of the variable field
|
|
1614
|
+
* @param type type ASTJSON representation of Type
|
|
693
1615
|
*/
|
|
694
|
-
|
|
695
|
-
DataNode = "DataNode",
|
|
696
|
-
MapNode = "MapNode"
|
|
697
|
-
}
|
|
698
|
-
interface CreateASTParams {
|
|
699
|
-
scope: Scope;
|
|
700
|
-
key?: Identifier;
|
|
701
|
-
parent?: ASTNode;
|
|
702
|
-
}
|
|
703
|
-
type ASTNodeJSONOrKind = string | ASTNodeJSON;
|
|
704
|
-
type ObserverOrNext<T> = Partial<Observer$1<T>> | ((value: T) => void);
|
|
705
|
-
interface SubscribeConfig<This, Data> {
|
|
706
|
-
debounceAnimation?: boolean;
|
|
707
|
-
triggerOnInit?: boolean;
|
|
708
|
-
selector?: (curr: This) => Data;
|
|
709
|
-
}
|
|
710
|
-
type GetKindJSON<KindType extends string, JSON extends ASTNodeJSON> = {
|
|
711
|
-
kind: KindType;
|
|
712
|
-
key?: Identifier;
|
|
713
|
-
} & JSON;
|
|
714
|
-
type GetKindJSONOrKind<KindType extends string, JSON extends ASTNodeJSON> = ({
|
|
715
|
-
kind: KindType;
|
|
716
|
-
key?: Identifier;
|
|
717
|
-
} & JSON) | KindType;
|
|
718
|
-
interface GlobalEventActionType<Type = string, Payload = any, AST extends ASTNode = ASTNode> {
|
|
719
|
-
type: Type;
|
|
720
|
-
payload?: Payload;
|
|
721
|
-
ast?: AST;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
type DataInjector = () => Record<string, any>;
|
|
725
|
-
declare class ASTRegisters {
|
|
726
|
-
protected injectors: Map<ASTKindType, DataInjector>;
|
|
727
|
-
protected astMap: Map<ASTKindType, ASTNodeRegistry>;
|
|
1616
|
+
updateType(type: BaseVariableFieldJSON['type']): void;
|
|
728
1617
|
/**
|
|
729
|
-
*
|
|
1618
|
+
* Update the initializer of the variable field
|
|
1619
|
+
* @param nextInitializer initializer ASTJSON representation of Expression
|
|
730
1620
|
*/
|
|
731
|
-
|
|
1621
|
+
updateInitializer(nextInitializer?: BaseVariableFieldJSON['initializer']): void;
|
|
1622
|
+
/**
|
|
1623
|
+
* Update the meta data of the variable field
|
|
1624
|
+
* @param nextMeta meta data of the variable field
|
|
1625
|
+
*/
|
|
1626
|
+
updateMeta(nextMeta: VariableMeta): void;
|
|
732
1627
|
/**
|
|
733
|
-
*
|
|
734
|
-
*
|
|
1628
|
+
* Get the variable field by keyPath, similar to js code:
|
|
1629
|
+
* `v.a.b`
|
|
1630
|
+
* @param keyPath
|
|
735
1631
|
* @returns
|
|
736
1632
|
*/
|
|
737
|
-
|
|
1633
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
738
1634
|
/**
|
|
739
|
-
*
|
|
740
|
-
* @param
|
|
1635
|
+
* Subscribe to type change of the variable field
|
|
1636
|
+
* @param observer
|
|
741
1637
|
* @returns
|
|
742
1638
|
*/
|
|
743
|
-
|
|
1639
|
+
onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
|
|
744
1640
|
/**
|
|
745
|
-
*
|
|
746
|
-
* @
|
|
747
|
-
* @param injector
|
|
1641
|
+
* Serialize the variable field to JSON
|
|
1642
|
+
* @returns ASTNodeJSON representation of `BaseVariableField`
|
|
748
1643
|
*/
|
|
749
|
-
|
|
1644
|
+
toJSON(): BaseVariableFieldJSON<VariableMeta>;
|
|
750
1645
|
}
|
|
751
1646
|
|
|
752
1647
|
/**
|
|
753
|
-
*
|
|
1648
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1649
|
+
* SPDX-License-Identifier: MIT
|
|
754
1650
|
*/
|
|
755
|
-
declare class DataNode<Data = any> extends ASTNode {
|
|
756
|
-
static kind: string;
|
|
757
|
-
protected _data: Data;
|
|
758
|
-
get data(): Data;
|
|
759
|
-
fromJSON(json: Data): void;
|
|
760
|
-
toJSON(): {
|
|
761
|
-
kind: ASTKind;
|
|
762
|
-
} & Data;
|
|
763
|
-
partialUpdate(nextData: Data): void;
|
|
764
|
-
}
|
|
765
1651
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
1652
|
+
/**
|
|
1653
|
+
* ASTNodeJSON representation of the `VariableDeclaration`.
|
|
1654
|
+
*/
|
|
1655
|
+
type VariableDeclarationJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
|
|
1656
|
+
/**
|
|
1657
|
+
* Variable sorting order, which is used to sort variables in `scope.outputs.variables`
|
|
1658
|
+
*/
|
|
1659
|
+
order?: number;
|
|
1660
|
+
};
|
|
1661
|
+
/**
|
|
1662
|
+
* `VariableDeclaration` is a variable field that represents a variable declaration.
|
|
1663
|
+
*/
|
|
1664
|
+
declare class VariableDeclaration<VariableMeta = any> extends BaseVariableField<VariableMeta> {
|
|
770
1665
|
static kind: string;
|
|
771
|
-
protected
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
1666
|
+
protected _order: number;
|
|
1667
|
+
/**
|
|
1668
|
+
* Variable sorting order, which is used to sort variables in `scope.outputs.variables`
|
|
1669
|
+
*/
|
|
1670
|
+
get order(): number;
|
|
1671
|
+
constructor(params: CreateASTParams);
|
|
1672
|
+
/**
|
|
1673
|
+
* Deserialize the `VariableDeclarationJSON` to the `VariableDeclaration`.
|
|
1674
|
+
*/
|
|
1675
|
+
fromJSON({ order, ...rest }: Omit<VariableDeclarationJSON<VariableMeta>, 'key'>): void;
|
|
1676
|
+
/**
|
|
1677
|
+
* Update the sorting order of the variable declaration.
|
|
1678
|
+
* @param order Variable sorting order. Default is 0.
|
|
1679
|
+
*/
|
|
1680
|
+
updateOrder(order?: number): void;
|
|
1681
|
+
/**
|
|
1682
|
+
* Serialize the `VariableDeclaration` to `VariableDeclarationJSON`.
|
|
1683
|
+
* @returns The JSON representation of `VariableDeclaration`.
|
|
1684
|
+
*/
|
|
1685
|
+
toJSON(): VariableDeclarationJSON<VariableMeta>;
|
|
775
1686
|
}
|
|
776
1687
|
|
|
777
|
-
|
|
778
|
-
|
|
1688
|
+
/**
|
|
1689
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1690
|
+
* SPDX-License-Identifier: MIT
|
|
1691
|
+
*/
|
|
1692
|
+
|
|
1693
|
+
interface VariableDeclarationListJSON<VariableMeta = any> {
|
|
1694
|
+
/**
|
|
1695
|
+
* `declarations` must be of type `VariableDeclaration`, so the business can omit the `kind` field.
|
|
1696
|
+
*/
|
|
1697
|
+
declarations?: VariableDeclarationJSON<VariableMeta>[];
|
|
1698
|
+
/**
|
|
1699
|
+
* The starting order number for variables.
|
|
1700
|
+
*/
|
|
1701
|
+
startOrder?: number;
|
|
779
1702
|
}
|
|
780
|
-
|
|
1703
|
+
type VariableDeclarationListChangeAction = GlobalEventActionType<'VariableListChange', {
|
|
1704
|
+
prev: VariableDeclaration[];
|
|
1705
|
+
next: VariableDeclaration[];
|
|
1706
|
+
}, VariableDeclarationList>;
|
|
1707
|
+
declare class VariableDeclarationList extends ASTNode<VariableDeclarationListJSON> {
|
|
781
1708
|
static kind: string;
|
|
782
|
-
protected map: Map<string, ASTNode>;
|
|
783
|
-
fromJSON({ map }: MapNodeJSON): void;
|
|
784
|
-
toJSON(): ASTNodeJSON;
|
|
785
1709
|
/**
|
|
786
|
-
*
|
|
787
|
-
* @param key ASTNode 的索引,
|
|
788
|
-
* @param json
|
|
1710
|
+
* Map of variable declarations, keyed by variable name.
|
|
789
1711
|
*/
|
|
790
|
-
|
|
1712
|
+
declarationTable: Map<string, VariableDeclaration>;
|
|
791
1713
|
/**
|
|
792
|
-
*
|
|
793
|
-
* @param key
|
|
1714
|
+
* Variable declarations, sorted by `order`.
|
|
794
1715
|
*/
|
|
795
|
-
|
|
1716
|
+
declarations: VariableDeclaration[];
|
|
796
1717
|
/**
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
*
|
|
1718
|
+
* Deserialize the `VariableDeclarationListJSON` to the `VariableDeclarationList`.
|
|
1719
|
+
* - VariableDeclarationListChangeAction will be dispatched after deserialization.
|
|
1720
|
+
*
|
|
1721
|
+
* @param declarations Variable declarations.
|
|
1722
|
+
* @param startOrder The starting order number for variables. Default is 0.
|
|
1723
|
+
*/
|
|
1724
|
+
fromJSON({ declarations, startOrder }: VariableDeclarationListJSON): void;
|
|
1725
|
+
/**
|
|
1726
|
+
* Serialize the `VariableDeclarationList` to the `VariableDeclarationListJSON`.
|
|
1727
|
+
* @returns ASTJSON representation of `VariableDeclarationList`
|
|
800
1728
|
*/
|
|
801
|
-
|
|
1729
|
+
toJSON(): {
|
|
1730
|
+
kind: ASTKind;
|
|
1731
|
+
declarations: VariableDeclarationJSON<any>[];
|
|
1732
|
+
};
|
|
802
1733
|
}
|
|
803
1734
|
|
|
1735
|
+
/**
|
|
1736
|
+
* Variable-core ASTNode factories.
|
|
1737
|
+
*/
|
|
804
1738
|
declare namespace ASTFactory {
|
|
805
1739
|
/**
|
|
806
|
-
*
|
|
807
|
-
|
|
1740
|
+
* Type-related factories.
|
|
1741
|
+
*/
|
|
1742
|
+
/**
|
|
1743
|
+
* Creates a `String` type node.
|
|
808
1744
|
*/
|
|
809
|
-
const createString: () => {
|
|
1745
|
+
const createString: (json?: StringJSON) => {
|
|
1746
|
+
format?: string;
|
|
810
1747
|
kind: ASTKind;
|
|
811
1748
|
};
|
|
1749
|
+
/**
|
|
1750
|
+
* Creates a `Number` type node.
|
|
1751
|
+
*/
|
|
812
1752
|
const createNumber: () => {
|
|
813
1753
|
kind: ASTKind;
|
|
814
1754
|
};
|
|
1755
|
+
/**
|
|
1756
|
+
* Creates a `Boolean` type node.
|
|
1757
|
+
*/
|
|
815
1758
|
const createBoolean: () => {
|
|
816
1759
|
kind: ASTKind;
|
|
817
1760
|
};
|
|
1761
|
+
/**
|
|
1762
|
+
* Creates an `Integer` type node.
|
|
1763
|
+
*/
|
|
818
1764
|
const createInteger: () => {
|
|
819
1765
|
kind: ASTKind;
|
|
820
1766
|
};
|
|
1767
|
+
/**
|
|
1768
|
+
* Creates an `Object` type node.
|
|
1769
|
+
*/
|
|
821
1770
|
const createObject: (json: ObjectJSON) => {
|
|
822
1771
|
properties?: PropertyJSON<any>[] | undefined;
|
|
823
1772
|
kind: ASTKind;
|
|
824
1773
|
};
|
|
1774
|
+
/**
|
|
1775
|
+
* Creates an `Array` type node.
|
|
1776
|
+
*/
|
|
825
1777
|
const createArray: (json: ArrayJSON) => {
|
|
826
|
-
items?: ASTNodeJSONOrKind
|
|
1778
|
+
items?: ASTNodeJSONOrKind;
|
|
827
1779
|
kind: ASTKind;
|
|
828
1780
|
};
|
|
1781
|
+
/**
|
|
1782
|
+
* Creates a `Map` type node.
|
|
1783
|
+
*/
|
|
829
1784
|
const createMap: (json: MapJSON) => {
|
|
830
|
-
keyType?: ASTNodeJSONOrKind
|
|
831
|
-
valueType?: ASTNodeJSONOrKind
|
|
1785
|
+
keyType?: ASTNodeJSONOrKind;
|
|
1786
|
+
valueType?: ASTNodeJSONOrKind;
|
|
832
1787
|
kind: ASTKind;
|
|
833
1788
|
};
|
|
1789
|
+
/**
|
|
1790
|
+
* Creates a `Union` type node.
|
|
1791
|
+
*/
|
|
834
1792
|
const createUnion: (json: UnionJSON) => {
|
|
835
|
-
types?: ASTNodeJSONOrKind[]
|
|
1793
|
+
types?: ASTNodeJSONOrKind[];
|
|
1794
|
+
kind: ASTKind;
|
|
1795
|
+
};
|
|
1796
|
+
/**
|
|
1797
|
+
* Creates a `CustomType` node.
|
|
1798
|
+
*/
|
|
1799
|
+
const createCustomType: (json: CustomTypeJSON) => {
|
|
1800
|
+
typeName: string;
|
|
836
1801
|
kind: ASTKind;
|
|
837
1802
|
};
|
|
838
1803
|
/**
|
|
839
|
-
*
|
|
1804
|
+
* Declaration-related factories.
|
|
1805
|
+
*/
|
|
1806
|
+
/**
|
|
1807
|
+
* Creates a `VariableDeclaration` node.
|
|
840
1808
|
*/
|
|
841
1809
|
const createVariableDeclaration: <VariableMeta = any>(json: VariableDeclarationJSON<VariableMeta>) => {
|
|
842
|
-
key
|
|
843
|
-
type?: ASTNodeJSONOrKind
|
|
844
|
-
initializer?: ASTNodeJSON
|
|
1810
|
+
key: Identifier;
|
|
1811
|
+
type?: ASTNodeJSONOrKind;
|
|
1812
|
+
initializer?: ASTNodeJSON;
|
|
845
1813
|
meta?: VariableMeta | undefined;
|
|
846
|
-
|
|
847
|
-
|
|
1814
|
+
kind: ASTKindType;
|
|
1815
|
+
order?: number;
|
|
848
1816
|
};
|
|
1817
|
+
/**
|
|
1818
|
+
* Creates a `Property` node.
|
|
1819
|
+
*/
|
|
849
1820
|
const createProperty: <VariableMeta = any>(json: PropertyJSON<VariableMeta>) => {
|
|
850
|
-
key:
|
|
851
|
-
type?: ASTNodeJSONOrKind
|
|
852
|
-
initializer?: ASTNodeJSON
|
|
1821
|
+
key: Identifier;
|
|
1822
|
+
type?: ASTNodeJSONOrKind;
|
|
1823
|
+
initializer?: ASTNodeJSON;
|
|
853
1824
|
meta?: VariableMeta | undefined;
|
|
854
|
-
kind:
|
|
1825
|
+
kind: ASTKindType;
|
|
855
1826
|
};
|
|
1827
|
+
/**
|
|
1828
|
+
* Creates a `VariableDeclarationList` node.
|
|
1829
|
+
*/
|
|
856
1830
|
const createVariableDeclarationList: (json: VariableDeclarationListJSON) => {
|
|
857
1831
|
declarations?: VariableDeclarationJSON<any>[] | undefined;
|
|
858
|
-
startOrder?: number
|
|
1832
|
+
startOrder?: number;
|
|
859
1833
|
kind: ASTKind;
|
|
860
1834
|
};
|
|
861
1835
|
/**
|
|
862
|
-
*
|
|
1836
|
+
* Expression-related factories.
|
|
1837
|
+
*/
|
|
1838
|
+
/**
|
|
1839
|
+
* Creates an `EnumerateExpression` node.
|
|
863
1840
|
*/
|
|
864
1841
|
const createEnumerateExpression: (json: EnumerateExpressionJSON) => {
|
|
865
1842
|
enumerateFor: ASTNodeJSON;
|
|
866
1843
|
kind: ASTKind;
|
|
867
1844
|
};
|
|
1845
|
+
/**
|
|
1846
|
+
* Creates a `KeyPathExpression` node.
|
|
1847
|
+
*/
|
|
868
1848
|
const createKeyPathExpression: (json: KeyPathExpressionJSON$1) => {
|
|
869
1849
|
keyPath: string[];
|
|
870
1850
|
kind: ASTKind;
|
|
871
1851
|
};
|
|
1852
|
+
/**
|
|
1853
|
+
* Creates a `WrapArrayExpression` node.
|
|
1854
|
+
*/
|
|
1855
|
+
const createWrapArrayExpression: (json: WrapArrayExpressionJSON) => {
|
|
1856
|
+
wrapFor: ASTNodeJSON;
|
|
1857
|
+
kind: ASTKind;
|
|
1858
|
+
};
|
|
1859
|
+
/**
|
|
1860
|
+
* Create by AST Class.
|
|
1861
|
+
*/
|
|
1862
|
+
/**
|
|
1863
|
+
* Creates Type-Safe ASTNodeJSON object based on the provided AST class.
|
|
1864
|
+
*
|
|
1865
|
+
* @param targetType Target ASTNode class.
|
|
1866
|
+
* @param json The JSON data for the node.
|
|
1867
|
+
* @returns The ASTNode JSON object.
|
|
1868
|
+
*/
|
|
1869
|
+
const create: <JSON extends ASTNodeJSON>(targetType: {
|
|
1870
|
+
kind: string;
|
|
1871
|
+
new (...args: any[]): ASTNode<JSON>;
|
|
1872
|
+
}, json: JSON) => {
|
|
1873
|
+
kind: string;
|
|
1874
|
+
} & JSON;
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
/**
|
|
1878
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1879
|
+
* SPDX-License-Identifier: MIT
|
|
1880
|
+
*/
|
|
1881
|
+
|
|
1882
|
+
/**
|
|
1883
|
+
* Variable-core ASTNode matchers.
|
|
1884
|
+
*
|
|
1885
|
+
* - Typescript code inside if statement will be type guarded.
|
|
1886
|
+
*/
|
|
1887
|
+
declare namespace ASTMatch {
|
|
1888
|
+
/**
|
|
1889
|
+
* # Type-related matchers.
|
|
1890
|
+
*/
|
|
1891
|
+
/**
|
|
1892
|
+
* Check if the node is a `StringType`.
|
|
1893
|
+
*/
|
|
1894
|
+
const isString: (node?: ASTNode) => node is StringType;
|
|
1895
|
+
/**
|
|
1896
|
+
* Check if the node is a `NumberType`.
|
|
1897
|
+
*/
|
|
1898
|
+
const isNumber: (node?: ASTNode) => node is NumberType;
|
|
1899
|
+
/**
|
|
1900
|
+
* Check if the node is a `BooleanType`.
|
|
1901
|
+
*/
|
|
1902
|
+
const isBoolean: (node?: ASTNode) => node is BooleanType;
|
|
1903
|
+
/**
|
|
1904
|
+
* Check if the node is a `IntegerType`.
|
|
1905
|
+
*/
|
|
1906
|
+
const isInteger: (node?: ASTNode) => node is IntegerType;
|
|
1907
|
+
/**
|
|
1908
|
+
* Check if the node is a `ObjectType`.
|
|
1909
|
+
*/
|
|
1910
|
+
const isObject: (node?: ASTNode) => node is ObjectType;
|
|
1911
|
+
/**
|
|
1912
|
+
* Check if the node is a `ArrayType`.
|
|
1913
|
+
*/
|
|
1914
|
+
const isArray: (node?: ASTNode) => node is ArrayType;
|
|
1915
|
+
/**
|
|
1916
|
+
* Check if the node is a `MapType`.
|
|
1917
|
+
*/
|
|
1918
|
+
const isMap: (node?: ASTNode) => node is MapType;
|
|
1919
|
+
/**
|
|
1920
|
+
* Check if the node is a `CustomType`.
|
|
1921
|
+
*/
|
|
1922
|
+
const isCustomType: (node?: ASTNode) => node is CustomType;
|
|
1923
|
+
/**
|
|
1924
|
+
* # Declaration-related matchers.
|
|
1925
|
+
*/
|
|
1926
|
+
/**
|
|
1927
|
+
* Check if the node is a `VariableDeclaration`.
|
|
1928
|
+
*/
|
|
1929
|
+
const isVariableDeclaration: <VariableMeta = any>(node?: ASTNode) => node is VariableDeclaration<VariableMeta>;
|
|
1930
|
+
/**
|
|
1931
|
+
* Check if the node is a `Property`.
|
|
1932
|
+
*/
|
|
1933
|
+
const isProperty: <VariableMeta = any>(node?: ASTNode) => node is Property<VariableMeta>;
|
|
1934
|
+
/**
|
|
1935
|
+
* Check if the node is a `BaseVariableField`.
|
|
1936
|
+
*/
|
|
1937
|
+
const isBaseVariableField: (node?: ASTNode) => node is BaseVariableField;
|
|
1938
|
+
/**
|
|
1939
|
+
* Check if the node is a `VariableDeclarationList`.
|
|
1940
|
+
*/
|
|
1941
|
+
const isVariableDeclarationList: (node?: ASTNode) => node is VariableDeclarationList;
|
|
1942
|
+
/**
|
|
1943
|
+
* # Expression-related matchers.
|
|
1944
|
+
*/
|
|
1945
|
+
/**
|
|
1946
|
+
* Check if the node is a `EnumerateExpression`.
|
|
1947
|
+
*/
|
|
1948
|
+
const isEnumerateExpression: (node?: ASTNode) => node is EnumerateExpression;
|
|
1949
|
+
/**
|
|
1950
|
+
* Check if the node is a `WrapArrayExpression`.
|
|
1951
|
+
*/
|
|
1952
|
+
const isWrapArrayExpression: (node?: ASTNode) => node is WrapArrayExpression;
|
|
1953
|
+
/**
|
|
1954
|
+
* Check if the node is a `KeyPathExpression`.
|
|
1955
|
+
*/
|
|
1956
|
+
const isKeyPathExpression: (node?: ASTNode) => node is KeyPathExpression;
|
|
1957
|
+
/**
|
|
1958
|
+
* Check ASTNode Match by ASTClass
|
|
1959
|
+
*
|
|
1960
|
+
* @param node ASTNode to be checked.
|
|
1961
|
+
* @param targetType Target ASTNode class.
|
|
1962
|
+
* @returns Whether the node is of the target type.
|
|
1963
|
+
*/
|
|
1964
|
+
function is<TargetASTNode extends ASTNode>(node?: ASTNode, targetType?: {
|
|
1965
|
+
kind: string;
|
|
1966
|
+
new (...args: any[]): TargetASTNode;
|
|
1967
|
+
}): node is TargetASTNode;
|
|
872
1968
|
}
|
|
873
1969
|
|
|
1970
|
+
/**
|
|
1971
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1972
|
+
* SPDX-License-Identifier: MIT
|
|
1973
|
+
*/
|
|
1974
|
+
|
|
874
1975
|
declare const injectToAST: (serviceIdentifier: interfaces.ServiceIdentifier) => (target: any, propertyKey: string) => any;
|
|
875
1976
|
declare const postConstructAST: () => (target: any, propertyKey: string) => void;
|
|
876
1977
|
|
|
1978
|
+
/**
|
|
1979
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1980
|
+
* SPDX-License-Identifier: MIT
|
|
1981
|
+
*/
|
|
1982
|
+
|
|
1983
|
+
/**
|
|
1984
|
+
* isMatchAST is same as ASTMatch.is
|
|
1985
|
+
* @param node
|
|
1986
|
+
* @param targetType
|
|
1987
|
+
* @returns
|
|
1988
|
+
*/
|
|
877
1989
|
declare function isMatchAST<TargetASTNode extends ASTNode>(node?: ASTNode, targetType?: {
|
|
878
1990
|
kind: string;
|
|
879
1991
|
new (...args: any[]): TargetASTNode;
|
|
880
1992
|
}): node is TargetASTNode;
|
|
881
1993
|
|
|
882
|
-
|
|
1994
|
+
/**
|
|
1995
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1996
|
+
* SPDX-License-Identifier: MIT
|
|
1997
|
+
*/
|
|
1998
|
+
|
|
1999
|
+
/**
|
|
2000
|
+
* Action type for scope changes.
|
|
2001
|
+
*/
|
|
2002
|
+
interface ScopeChangeAction {
|
|
2003
|
+
type: 'add' | 'delete' | 'update' | 'available';
|
|
2004
|
+
scope: Scope;
|
|
2005
|
+
}
|
|
2006
|
+
/**
|
|
2007
|
+
* Interface for a variable table.
|
|
2008
|
+
*/
|
|
2009
|
+
interface IVariableTable extends Disposable {
|
|
883
2010
|
/**
|
|
884
|
-
*
|
|
2011
|
+
* The parent variable table.
|
|
885
2012
|
*/
|
|
886
|
-
|
|
2013
|
+
parentTable?: IVariableTable;
|
|
887
2014
|
/**
|
|
888
|
-
*
|
|
2015
|
+
* @deprecated Use `onVariableListChange` or `onAnyVariableChange` instead.
|
|
889
2016
|
*/
|
|
890
|
-
|
|
2017
|
+
onDataChange: Event<void>;
|
|
891
2018
|
/**
|
|
892
|
-
*
|
|
2019
|
+
* The current version of the variable table.
|
|
893
2020
|
*/
|
|
894
|
-
|
|
2021
|
+
version: number;
|
|
895
2022
|
/**
|
|
896
|
-
*
|
|
897
|
-
* - Map<formItemKey, formItemValue>
|
|
2023
|
+
* The list of variables in the table.
|
|
898
2024
|
*/
|
|
899
|
-
|
|
2025
|
+
variables: VariableDeclaration[];
|
|
900
2026
|
/**
|
|
901
|
-
*
|
|
2027
|
+
* The keys of the variables in the table.
|
|
902
2028
|
*/
|
|
903
|
-
|
|
2029
|
+
variableKeys: string[];
|
|
904
2030
|
/**
|
|
905
|
-
*
|
|
2031
|
+
* Fires a change event.
|
|
906
2032
|
*/
|
|
907
|
-
|
|
2033
|
+
fireChange(): void;
|
|
908
2034
|
/**
|
|
909
|
-
*
|
|
2035
|
+
* Gets a variable or property by its key path.
|
|
2036
|
+
* @param keyPath The key path to the variable or property.
|
|
2037
|
+
* @returns The found `BaseVariableField` or `undefined`.
|
|
910
2038
|
*/
|
|
911
|
-
|
|
2039
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
912
2040
|
/**
|
|
913
|
-
*
|
|
2041
|
+
* Gets a variable by its key.
|
|
2042
|
+
* @param key The key of the variable.
|
|
2043
|
+
* @returns The found `VariableDeclaration` or `undefined`.
|
|
2044
|
+
*/
|
|
2045
|
+
getVariableByKey(key: string): VariableDeclaration | undefined;
|
|
2046
|
+
/**
|
|
2047
|
+
* Disposes the variable table.
|
|
914
2048
|
*/
|
|
915
|
-
protected memo: {
|
|
916
|
-
<T>(key: string | symbol, fn: () => T): T;
|
|
917
|
-
clear: (key?: (string | symbol) | undefined) => void;
|
|
918
|
-
};
|
|
919
|
-
toDispose: DisposableCollection;
|
|
920
|
-
constructor(options: {
|
|
921
|
-
id: string;
|
|
922
|
-
variableEngine: VariableEngine;
|
|
923
|
-
meta?: ScopeMeta;
|
|
924
|
-
});
|
|
925
|
-
refreshCovers(): void;
|
|
926
|
-
refreshDeps(): void;
|
|
927
|
-
get depScopes(): Scope[];
|
|
928
|
-
get coverScopes(): Scope[];
|
|
929
2049
|
dispose(): void;
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
2050
|
+
/**
|
|
2051
|
+
* Subscribes to changes in the variable list.
|
|
2052
|
+
* @param observer The observer function.
|
|
2053
|
+
* @returns A disposable to unsubscribe.
|
|
2054
|
+
*/
|
|
2055
|
+
onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
|
|
2056
|
+
/**
|
|
2057
|
+
* Subscribes to changes in any variable's value.
|
|
2058
|
+
* @param observer The observer function.
|
|
2059
|
+
* @returns A disposable to unsubscribe.
|
|
2060
|
+
*/
|
|
2061
|
+
onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
|
|
2062
|
+
/**
|
|
2063
|
+
* Subscribes to both variable list changes and any variable's value changes.
|
|
2064
|
+
* @param observer The observer function.
|
|
2065
|
+
* @returns A disposable to unsubscribe.
|
|
2066
|
+
*/
|
|
2067
|
+
onListOrAnyVarChange(observer: () => void): Disposable;
|
|
937
2068
|
}
|
|
938
2069
|
|
|
2070
|
+
/**
|
|
2071
|
+
* The core of the variable engine system.
|
|
2072
|
+
* It manages scopes, variables, and events within the system.
|
|
2073
|
+
*/
|
|
939
2074
|
declare class VariableEngine implements Disposable {
|
|
2075
|
+
/**
|
|
2076
|
+
* The scope chain, which manages the dependency relationships between scopes.
|
|
2077
|
+
*/
|
|
940
2078
|
readonly chain: ScopeChain;
|
|
2079
|
+
/**
|
|
2080
|
+
* The registry for all AST node types.
|
|
2081
|
+
*/
|
|
941
2082
|
readonly astRegisters: ASTRegisters;
|
|
942
2083
|
protected toDispose: DisposableCollection;
|
|
943
2084
|
protected memo: {
|
|
944
2085
|
<T>(key: string | symbol, fn: () => T): T;
|
|
945
|
-
clear: (key?:
|
|
2086
|
+
clear: (key?: string | symbol) => void;
|
|
946
2087
|
};
|
|
947
|
-
protected scopeMap: Map<string, Scope<Record<string, any>>>;
|
|
2088
|
+
protected scopeMap: Map<string | symbol, Scope<Record<string, any>>>;
|
|
2089
|
+
/**
|
|
2090
|
+
* A rxjs subject that emits global events occurring within the variable engine.
|
|
2091
|
+
*/
|
|
948
2092
|
globalEvent$: Subject<GlobalEventActionType>;
|
|
949
2093
|
protected onScopeChangeEmitter: Emitter<ScopeChangeAction>;
|
|
950
|
-
|
|
2094
|
+
/**
|
|
2095
|
+
* A table containing all global variables.
|
|
2096
|
+
*/
|
|
2097
|
+
globalVariableTable: IVariableTable;
|
|
2098
|
+
/**
|
|
2099
|
+
* An event that fires whenever a scope is added, updated, or deleted.
|
|
2100
|
+
*/
|
|
951
2101
|
onScopeChange: _flowgram_ai_utils.Event<ScopeChangeAction>;
|
|
952
2102
|
private readonly containerProvider;
|
|
2103
|
+
/**
|
|
2104
|
+
* The Inversify container instance.
|
|
2105
|
+
*/
|
|
953
2106
|
get container(): interfaces.Container;
|
|
954
|
-
constructor(
|
|
2107
|
+
constructor(
|
|
2108
|
+
/**
|
|
2109
|
+
* The scope chain, which manages the dependency relationships between scopes.
|
|
2110
|
+
*/
|
|
2111
|
+
chain: ScopeChain,
|
|
2112
|
+
/**
|
|
2113
|
+
* The registry for all AST node types.
|
|
2114
|
+
*/
|
|
955
2115
|
astRegisters: ASTRegisters);
|
|
2116
|
+
/**
|
|
2117
|
+
* Disposes of all resources used by the variable engine.
|
|
2118
|
+
*/
|
|
956
2119
|
dispose(): void;
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
2120
|
+
/**
|
|
2121
|
+
* Retrieves a scope by its unique identifier.
|
|
2122
|
+
* @param scopeId The ID of the scope to retrieve.
|
|
2123
|
+
* @returns The scope if found, otherwise undefined.
|
|
2124
|
+
*/
|
|
2125
|
+
getScopeById(scopeId: string | symbol): Scope | undefined;
|
|
2126
|
+
/**
|
|
2127
|
+
* Removes a scope by its unique identifier and disposes of it.
|
|
2128
|
+
* @param scopeId The ID of the scope to remove.
|
|
2129
|
+
*/
|
|
2130
|
+
removeScopeById(scopeId: string | symbol): void;
|
|
2131
|
+
/**
|
|
2132
|
+
* Creates a new scope or retrieves an existing one if the ID and type match.
|
|
2133
|
+
* @param id The unique identifier for the scope.
|
|
2134
|
+
* @param meta Optional metadata for the scope, defined by the user.
|
|
2135
|
+
* @param options Options for creating the scope.
|
|
2136
|
+
* @param options.ScopeConstructor The constructor to use for creating the scope. Defaults to `Scope`.
|
|
2137
|
+
* @returns The created or existing scope.
|
|
2138
|
+
*/
|
|
2139
|
+
createScope(id: string | symbol, meta?: Record<string, any>, options?: {
|
|
2140
|
+
ScopeConstructor?: IScopeConstructor;
|
|
2141
|
+
}): Scope;
|
|
2142
|
+
/**
|
|
2143
|
+
* Retrieves all scopes currently managed by the engine.
|
|
2144
|
+
* @param options Options for retrieving the scopes.
|
|
2145
|
+
* @param options.sort Whether to sort the scopes based on their dependency chain.
|
|
2146
|
+
* @returns An array of all scopes.
|
|
2147
|
+
*/
|
|
960
2148
|
getAllScopes({ sort, }?: {
|
|
961
2149
|
sort?: boolean;
|
|
962
2150
|
}): Scope[];
|
|
2151
|
+
/**
|
|
2152
|
+
* Fires a global event to be broadcast to all listeners.
|
|
2153
|
+
* @param event The global event to fire.
|
|
2154
|
+
*/
|
|
963
2155
|
fireGlobalEvent(event: GlobalEventActionType): void;
|
|
2156
|
+
/**
|
|
2157
|
+
* Subscribes to a specific type of global event.
|
|
2158
|
+
* @param type The type of the event to listen for.
|
|
2159
|
+
* @param observer A function to be called when the event is observed.
|
|
2160
|
+
* @returns A disposable object to unsubscribe from the event.
|
|
2161
|
+
*/
|
|
964
2162
|
onGlobalEvent<ActionType extends GlobalEventActionType = GlobalEventActionType>(type: ActionType['type'], observer: (action: ActionType) => void): Disposable;
|
|
965
2163
|
}
|
|
966
2164
|
|
|
2165
|
+
/**
|
|
2166
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
2167
|
+
* SPDX-License-Identifier: MIT
|
|
2168
|
+
*/
|
|
2169
|
+
|
|
967
2170
|
interface ScopeContextProps {
|
|
968
2171
|
scope: Scope;
|
|
969
2172
|
}
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
2173
|
+
/**
|
|
2174
|
+
* ScopeProvider provides the scope to its children via context.
|
|
2175
|
+
*/
|
|
2176
|
+
declare const ScopeProvider: (props: React.PropsWithChildren<{
|
|
2177
|
+
/**
|
|
2178
|
+
* scope used in the context
|
|
2179
|
+
*/
|
|
2180
|
+
scope?: Scope;
|
|
2181
|
+
/**
|
|
2182
|
+
* @deprecated use scope prop instead, this is kept for backward compatibility
|
|
2183
|
+
*/
|
|
2184
|
+
value?: ScopeContextProps;
|
|
2185
|
+
}>) => React.JSX.Element;
|
|
2186
|
+
/**
|
|
2187
|
+
* useCurrentScope returns the scope provided by ScopeProvider.
|
|
2188
|
+
* @returns
|
|
2189
|
+
*/
|
|
2190
|
+
declare const useCurrentScope: <Strict extends boolean = false>(params?: {
|
|
2191
|
+
/**
|
|
2192
|
+
* whether to throw error when no scope in ScopeProvider is found
|
|
2193
|
+
*/
|
|
2194
|
+
strict: Strict;
|
|
2195
|
+
}) => Strict extends true ? Scope : Scope | undefined;
|
|
973
2196
|
|
|
974
2197
|
/**
|
|
975
|
-
*
|
|
2198
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
2199
|
+
* SPDX-License-Identifier: MIT
|
|
976
2200
|
*/
|
|
977
|
-
declare function useScopeAvailable(): ScopeAvailableData;
|
|
978
2201
|
|
|
979
2202
|
/**
|
|
2203
|
+
* Get the available variables in the current scope.
|
|
980
2204
|
* 获取作用域的可访问变量
|
|
2205
|
+
*
|
|
2206
|
+
* @returns the available variables in the current scope
|
|
2207
|
+
*/
|
|
2208
|
+
declare function useScopeAvailable(params?: {
|
|
2209
|
+
autoRefresh?: boolean;
|
|
2210
|
+
}): ScopeAvailableData;
|
|
2211
|
+
|
|
2212
|
+
/**
|
|
2213
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
2214
|
+
* SPDX-License-Identifier: MIT
|
|
2215
|
+
*/
|
|
2216
|
+
|
|
2217
|
+
/**
|
|
2218
|
+
* Get available variable list in the current scope.
|
|
2219
|
+
*
|
|
2220
|
+
* - If no scope, return global variable list.
|
|
2221
|
+
* - The hook is reactive to variable list or any variables change.
|
|
981
2222
|
*/
|
|
982
2223
|
declare function useAvailableVariables(): VariableDeclaration[];
|
|
983
2224
|
|
|
2225
|
+
/**
|
|
2226
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
2227
|
+
* SPDX-License-Identifier: MIT
|
|
2228
|
+
*/
|
|
2229
|
+
|
|
2230
|
+
/**
|
|
2231
|
+
* Get output variable list in the current scope.
|
|
2232
|
+
*
|
|
2233
|
+
* - The hook is reactive to variable list or any variables change.
|
|
2234
|
+
*/
|
|
2235
|
+
declare function useOutputVariables(): VariableDeclaration[];
|
|
2236
|
+
|
|
984
2237
|
interface RenameInfo {
|
|
985
2238
|
before: BaseVariableField;
|
|
986
2239
|
after: BaseVariableField;
|
|
987
2240
|
}
|
|
2241
|
+
/**
|
|
2242
|
+
* This service is responsible for detecting when a variable field's key is renamed.
|
|
2243
|
+
* It listens for changes in variable declaration lists and object properties, and
|
|
2244
|
+
* determines if a change constitutes a rename operation.
|
|
2245
|
+
*/
|
|
988
2246
|
declare class VariableFieldKeyRenameService {
|
|
989
2247
|
variableEngine: VariableEngine;
|
|
990
2248
|
toDispose: DisposableCollection;
|
|
991
2249
|
renameEmitter: Emitter<RenameInfo>;
|
|
2250
|
+
/**
|
|
2251
|
+
* Emits events for fields that are disposed of during a list change, but not renamed.
|
|
2252
|
+
* This helps distinguish between a field that was truly removed and one that was renamed.
|
|
2253
|
+
*/
|
|
992
2254
|
disposeInListEmitter: Emitter<BaseVariableField<any>>;
|
|
2255
|
+
/**
|
|
2256
|
+
* An event that fires when a variable field key is successfully renamed.
|
|
2257
|
+
*/
|
|
993
2258
|
onRename: _flowgram_ai_utils.Event<RenameInfo>;
|
|
2259
|
+
/**
|
|
2260
|
+
* An event that fires when a field is removed from a list (and not part of a rename).
|
|
2261
|
+
*/
|
|
994
2262
|
onDisposeInList: _flowgram_ai_utils.Event<BaseVariableField<any>>;
|
|
2263
|
+
/**
|
|
2264
|
+
* Handles changes in a list of fields to detect rename operations.
|
|
2265
|
+
* @param ast The AST node where the change occurred.
|
|
2266
|
+
* @param prev The list of fields before the change.
|
|
2267
|
+
* @param next The list of fields after the change.
|
|
2268
|
+
*/
|
|
995
2269
|
handleFieldListChange(ast?: ASTNode, prev?: BaseVariableField[], next?: BaseVariableField[]): void;
|
|
2270
|
+
/**
|
|
2271
|
+
* Notifies listeners about fields that were removed from a list.
|
|
2272
|
+
* @param prev The list of fields before the change.
|
|
2273
|
+
* @param next The list of fields after the change.
|
|
2274
|
+
*/
|
|
996
2275
|
notifyFieldsDispose(prev?: BaseVariableField[], next?: BaseVariableField[]): void;
|
|
997
2276
|
init(): void;
|
|
998
2277
|
dispose(): void;
|
|
999
2278
|
}
|
|
1000
2279
|
|
|
1001
|
-
export { ASTFactory, ASTKind, ASTNode, ASTNodeFlags, type ASTNodeJSON, type ASTNodeRegistry, ASTRegisters, ArrayType, BaseExpression, BaseType, BaseVariableField, BooleanType, type CreateASTParams,
|
|
2280
|
+
export { ASTFactory, ASTKind, ASTMatch, ASTNode, ASTNodeFlags, type ASTNodeJSON, type ASTNodeRegistry, ASTRegisters, ArrayType, BaseExpression, BaseType, BaseVariableField, BooleanType, type CreateASTParams, CustomType, type CustomTypeJSON, DataNode, EnumerateExpression, type EnumerateExpressionJSON, type GetKindJSON, type GetKindJSONOrKind, type GlobalEventActionType, type IVariableTable, IntegerType, KeyPathExpression, type KeyPathExpressionJSON$1 as KeyPathExpressionJSON, LegacyKeyPathExpression, ListNode, type ListNodeJSON, MapNode, type MapNodeJSON, MapType, NumberType, type ObjectJSON, type ObjectPropertiesChangeAction, ObjectType, Property, type PropertyJSON, Scope, ScopeChain, ScopeOutputData, ScopeProvider, StringType, type UnionJSON, VariableContainerModule, VariableDeclaration, type VariableDeclarationJSON, VariableDeclarationList, type VariableDeclarationListChangeAction, type VariableDeclarationListJSON, VariableEngine, VariableEngineProvider, VariableFieldKeyRenameService, WrapArrayExpression, type WrapArrayExpressionJSON, injectToAST, isMatchAST, postConstructAST, useAvailableVariables, useCurrentScope, useOutputVariables, useScopeAvailable };
|