@flowgram.ai/variable-core 0.1.0-alpha.3 → 0.1.0-alpha.31
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 +1086 -425
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +1783 -529
- package/dist/index.d.ts +1783 -529
- package/dist/index.js +1152 -485
- package/dist/index.js.map +1 -1
- package/package.json +15 -15
- package/README.md +0 -24
package/dist/index.d.ts
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,1007 +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 {
|
|
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> {
|
|
231
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
|
+
*/
|
|
346
1228
|
interface CustomTypeJSON {
|
|
1229
|
+
/**
|
|
1230
|
+
* The name of the custom type.
|
|
1231
|
+
*/
|
|
347
1232
|
typeName: string;
|
|
348
1233
|
}
|
|
1234
|
+
/**
|
|
1235
|
+
* Represents a custom type.
|
|
1236
|
+
*/
|
|
349
1237
|
declare class CustomType extends BaseType<CustomTypeJSON> {
|
|
350
1238
|
static kind: string;
|
|
351
1239
|
protected _typeName: string;
|
|
1240
|
+
/**
|
|
1241
|
+
* The name of the custom type.
|
|
1242
|
+
*/
|
|
352
1243
|
get typeName(): string;
|
|
1244
|
+
/**
|
|
1245
|
+
* Deserializes the `CustomTypeJSON` to the `CustomType`.
|
|
1246
|
+
* @param json The `CustomTypeJSON` to deserialize.
|
|
1247
|
+
*/
|
|
353
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
|
+
*/
|
|
354
1254
|
isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
|
|
1255
|
+
toJSON(): {
|
|
1256
|
+
typeName: string;
|
|
1257
|
+
};
|
|
355
1258
|
}
|
|
356
1259
|
|
|
1260
|
+
/**
|
|
1261
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1262
|
+
* SPDX-License-Identifier: MIT
|
|
1263
|
+
*/
|
|
1264
|
+
|
|
357
1265
|
type ExpressionRefs = (BaseVariableField | undefined)[];
|
|
358
|
-
|
|
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> {
|
|
359
1272
|
flags: ASTNodeFlags;
|
|
360
1273
|
/**
|
|
361
|
-
*
|
|
1274
|
+
* Get the global variable table, which is used to access referenced variables.
|
|
362
1275
|
*/
|
|
363
|
-
get globalVariableTable():
|
|
1276
|
+
get globalVariableTable(): IVariableTable;
|
|
364
1277
|
/**
|
|
365
|
-
*
|
|
1278
|
+
* Parent variable fields, sorted from closest to farthest.
|
|
366
1279
|
*/
|
|
367
1280
|
get parentFields(): BaseVariableField[];
|
|
368
1281
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
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.
|
|
371
1286
|
*/
|
|
372
1287
|
abstract getRefFields(): ExpressionRefs;
|
|
373
1288
|
/**
|
|
374
|
-
*
|
|
1289
|
+
* The return type of the expression.
|
|
375
1290
|
*/
|
|
376
1291
|
abstract returnType: BaseType | undefined;
|
|
377
1292
|
/**
|
|
378
|
-
*
|
|
1293
|
+
* The variable fields referenced by the expression.
|
|
379
1294
|
*/
|
|
380
1295
|
protected _refs: ExpressionRefs;
|
|
1296
|
+
/**
|
|
1297
|
+
* The variable fields referenced by the expression.
|
|
1298
|
+
*/
|
|
381
1299
|
get refs(): ExpressionRefs;
|
|
382
1300
|
protected refreshRefs$: Subject<void>;
|
|
383
1301
|
/**
|
|
384
|
-
*
|
|
1302
|
+
* Refresh the variable references.
|
|
385
1303
|
*/
|
|
386
1304
|
refreshRefs(): void;
|
|
387
1305
|
/**
|
|
388
|
-
*
|
|
389
|
-
* 监听 [a.b.c] -> [a.b]
|
|
1306
|
+
* An observable that emits the referenced variable fields when they change.
|
|
390
1307
|
*/
|
|
391
1308
|
refs$: Observable<ExpressionRefs>;
|
|
392
|
-
constructor(params: CreateASTParams, opts?:
|
|
1309
|
+
constructor(params: CreateASTParams, opts?: any);
|
|
393
1310
|
}
|
|
394
1311
|
|
|
395
|
-
|
|
396
|
-
|
|
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;
|
|
397
1325
|
}
|
|
398
|
-
|
|
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> {
|
|
399
1330
|
static kind: string;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
+
};
|
|
403
1358
|
}
|
|
404
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
|
+
*/
|
|
405
1368
|
interface KeyPathExpressionJSON$1 {
|
|
1369
|
+
/**
|
|
1370
|
+
* The key path of the variable.
|
|
1371
|
+
*/
|
|
406
1372
|
keyPath: string[];
|
|
407
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
|
+
*/
|
|
408
1381
|
declare class KeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON$1> extends BaseExpression<CustomPathJSON> {
|
|
409
1382
|
static kind: string;
|
|
410
1383
|
protected _keyPath: string[];
|
|
1384
|
+
protected _rawPathJson: CustomPathJSON;
|
|
1385
|
+
/**
|
|
1386
|
+
* The key path of the variable.
|
|
1387
|
+
*/
|
|
411
1388
|
get keyPath(): string[];
|
|
1389
|
+
/**
|
|
1390
|
+
* Get the variable fields referenced by the expression.
|
|
1391
|
+
* @returns An array of referenced variable fields.
|
|
1392
|
+
*/
|
|
412
1393
|
getRefFields(): BaseVariableField[];
|
|
413
|
-
get returnType(): BaseType | undefined;
|
|
414
1394
|
/**
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
|
|
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.
|
|
419
1410
|
*/
|
|
420
1411
|
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
1412
|
+
/**
|
|
1413
|
+
* Deserializes the `KeyPathExpressionJSON` to the `KeyPathExpression`.
|
|
1414
|
+
* @param json The `KeyPathExpressionJSON` to deserialize.
|
|
1415
|
+
*/
|
|
421
1416
|
fromJSON(json: CustomPathJSON): void;
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
protected _enumerateFor: BaseExpression | undefined;
|
|
435
|
-
get enumerateFor(): BaseExpression<any, any> | undefined;
|
|
436
|
-
get returnType(): BaseType | undefined;
|
|
437
|
-
getRefFields(): [];
|
|
438
|
-
fromJSON({ enumerateFor: expression }: EnumerateExpressionJSON): void;
|
|
439
|
-
toJSON(): ASTNodeJSON;
|
|
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;
|
|
1423
|
+
constructor(params: CreateASTParams, opts: any);
|
|
1424
|
+
/**
|
|
1425
|
+
* Serialize the `KeyPathExpression` to `KeyPathExpressionJSON`.
|
|
1426
|
+
* @returns The JSON representation of `KeyPathExpression`.
|
|
1427
|
+
*/
|
|
1428
|
+
toJSON(): CustomPathJSON;
|
|
440
1429
|
}
|
|
441
1430
|
|
|
1431
|
+
/**
|
|
1432
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1433
|
+
* SPDX-License-Identifier: MIT
|
|
1434
|
+
*/
|
|
1435
|
+
|
|
1436
|
+
/**
|
|
1437
|
+
* ASTNodeJSON representation of `KeyPathExpression`
|
|
1438
|
+
*/
|
|
442
1439
|
interface KeyPathExpressionJSON {
|
|
1440
|
+
/**
|
|
1441
|
+
* The key path of the variable.
|
|
1442
|
+
*/
|
|
443
1443
|
keyPath: string[];
|
|
444
1444
|
}
|
|
445
1445
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
* - 引入成环检测
|
|
1446
|
+
* @deprecated Use `KeyPathExpression` instead.
|
|
1447
|
+
* Represents a key path expression, which is used to reference a variable by its key path.
|
|
449
1448
|
*/
|
|
450
|
-
declare class
|
|
1449
|
+
declare class LegacyKeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON> extends BaseExpression<CustomPathJSON> {
|
|
451
1450
|
static kind: string;
|
|
452
1451
|
protected _keyPath: string[];
|
|
1452
|
+
protected _rawPathJson: CustomPathJSON;
|
|
1453
|
+
/**
|
|
1454
|
+
* The key path of the variable.
|
|
1455
|
+
*/
|
|
453
1456
|
get keyPath(): string[];
|
|
1457
|
+
/**
|
|
1458
|
+
* Get the variable fields referenced by the expression.
|
|
1459
|
+
* @returns An array of referenced variable fields.
|
|
1460
|
+
*/
|
|
454
1461
|
getRefFields(): BaseVariableField[];
|
|
455
|
-
_returnType: BaseType;
|
|
456
|
-
get returnType(): BaseType<any, any>;
|
|
457
1462
|
/**
|
|
458
|
-
*
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
1463
|
+
* The return type of the expression.
|
|
1464
|
+
*/
|
|
1465
|
+
get returnType(): BaseType | undefined;
|
|
1466
|
+
/**
|
|
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.
|
|
462
1472
|
*/
|
|
463
1473
|
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
1474
|
+
/**
|
|
1475
|
+
* Deserializes the `KeyPathExpressionJSON` to the `KeyPathExpression`.
|
|
1476
|
+
* @param json The `KeyPathExpressionJSON` to deserialize.
|
|
1477
|
+
*/
|
|
464
1478
|
fromJSON(json: CustomPathJSON): void;
|
|
465
|
-
getReturnTypeJSONByRef(_ref: BaseVariableField | undefined): ASTNodeJSON | undefined;
|
|
466
|
-
protected prevRefTypeHash: string | undefined;
|
|
467
1479
|
constructor(params: CreateASTParams, opts: any);
|
|
468
|
-
|
|
1480
|
+
/**
|
|
1481
|
+
* Serialize the `KeyPathExpression` to `KeyPathExpressionJSON`.
|
|
1482
|
+
* @returns The JSON representation of `KeyPathExpression`.
|
|
1483
|
+
*/
|
|
1484
|
+
toJSON(): CustomPathJSON;
|
|
469
1485
|
}
|
|
470
1486
|
|
|
471
1487
|
/**
|
|
472
|
-
*
|
|
1488
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1489
|
+
* SPDX-License-Identifier: MIT
|
|
473
1490
|
*/
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
};
|
|
480
|
-
declare abstract class BaseVariableField<VariableMeta = any> extends ASTNode<BaseVariableFieldJSON<VariableMeta>> {
|
|
481
|
-
flags: ASTNodeFlags;
|
|
482
|
-
protected _type?: BaseType;
|
|
483
|
-
protected _meta: VariableMeta;
|
|
484
|
-
protected _initializer?: BaseExpression;
|
|
1491
|
+
|
|
1492
|
+
/**
|
|
1493
|
+
* ASTNodeJSON representation of `WrapArrayExpression`
|
|
1494
|
+
*/
|
|
1495
|
+
interface WrapArrayExpressionJSON {
|
|
485
1496
|
/**
|
|
486
|
-
*
|
|
1497
|
+
* The expression to be wrapped.
|
|
487
1498
|
*/
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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;
|
|
492
1508
|
/**
|
|
493
|
-
*
|
|
1509
|
+
* The expression to be wrapped.
|
|
494
1510
|
*/
|
|
495
|
-
|
|
496
|
-
updateType(type: BaseVariableFieldJSON['type']): void;
|
|
497
|
-
updateInitializer(nextInitializer?: BaseVariableFieldJSON['initializer']): void;
|
|
498
|
-
updateMeta(nextMeta: VariableMeta): void;
|
|
1511
|
+
get wrapFor(): BaseExpression<any> | undefined;
|
|
499
1512
|
/**
|
|
500
|
-
*
|
|
501
|
-
* @param keyPath
|
|
502
|
-
* @returns
|
|
1513
|
+
* The return type of the expression.
|
|
503
1514
|
*/
|
|
504
|
-
|
|
1515
|
+
get returnType(): BaseType | undefined;
|
|
505
1516
|
/**
|
|
506
|
-
*
|
|
507
|
-
* @param observer
|
|
508
|
-
* @returns
|
|
1517
|
+
* Refresh the return type of the expression.
|
|
509
1518
|
*/
|
|
510
|
-
|
|
1519
|
+
refreshReturnType(): void;
|
|
511
1520
|
/**
|
|
512
|
-
*
|
|
513
|
-
* @returns
|
|
1521
|
+
* Get the variable fields referenced by the expression.
|
|
1522
|
+
* @returns An empty array, as this expression does not reference any variables.
|
|
514
1523
|
*/
|
|
515
|
-
|
|
516
|
-
kind: string;
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
declare class VariableTable implements Disposable {
|
|
521
|
-
parentTable?: VariableTable | undefined;
|
|
522
|
-
protected table: Map<string, VariableDeclaration>;
|
|
523
|
-
protected onDataChangeEmitter: Emitter<void>;
|
|
524
|
-
protected variables$: Subject<VariableDeclaration[]>;
|
|
525
|
-
protected anyVariableChange$: Observable<VariableDeclaration>;
|
|
1524
|
+
getRefFields(): [];
|
|
526
1525
|
/**
|
|
527
|
-
*
|
|
528
|
-
* @param
|
|
529
|
-
* @returns
|
|
1526
|
+
* Deserializes the `WrapArrayExpressionJSON` to the `WrapArrayExpression`.
|
|
1527
|
+
* @param json The `WrapArrayExpressionJSON` to deserialize.
|
|
530
1528
|
*/
|
|
531
|
-
|
|
1529
|
+
fromJSON({ wrapFor: expression }: WrapArrayExpressionJSON): void;
|
|
532
1530
|
/**
|
|
533
|
-
*
|
|
534
|
-
* @
|
|
1531
|
+
* Serialize the `WrapArrayExpression` to `WrapArrayExpressionJSON`.
|
|
1532
|
+
* @returns The JSON representation of `WrapArrayExpression`.
|
|
535
1533
|
*/
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
1534
|
+
toJSON(): {
|
|
1535
|
+
kind: ASTKind;
|
|
1536
|
+
wrapFor: any;
|
|
1537
|
+
};
|
|
1538
|
+
protected init(): void;
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
/**
|
|
1542
|
+
* ASTNodeJSON representation of `BaseVariableField`
|
|
1543
|
+
*/
|
|
1544
|
+
interface BaseVariableFieldJSON<VariableMeta = any> extends ASTNodeJSON {
|
|
544
1545
|
/**
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
1546
|
+
* key of the variable field
|
|
1547
|
+
* - For `VariableDeclaration`, the key should be global unique.
|
|
1548
|
+
* - For `Property`, the key is the property name.
|
|
548
1549
|
*/
|
|
549
|
-
|
|
1550
|
+
key: Identifier;
|
|
550
1551
|
/**
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
* @returns
|
|
1552
|
+
* type of the variable field, similar to js code:
|
|
1553
|
+
* `const v: string`
|
|
554
1554
|
*/
|
|
555
|
-
|
|
1555
|
+
type?: ASTNodeJSONOrKind;
|
|
556
1556
|
/**
|
|
557
|
-
*
|
|
558
|
-
*
|
|
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.
|
|
559
1561
|
*/
|
|
560
|
-
|
|
1562
|
+
initializer?: ASTNodeJSON;
|
|
561
1563
|
/**
|
|
562
|
-
*
|
|
563
|
-
* @param key
|
|
1564
|
+
* meta data of the variable field, you cans store information like `title`, `icon`, etc.
|
|
564
1565
|
*/
|
|
565
|
-
|
|
566
|
-
dispose(): void;
|
|
1566
|
+
meta?: VariableMeta;
|
|
567
1567
|
}
|
|
568
|
-
|
|
569
1568
|
/**
|
|
570
|
-
*
|
|
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.
|
|
571
1573
|
*/
|
|
572
|
-
declare class
|
|
573
|
-
|
|
574
|
-
protected
|
|
575
|
-
protected
|
|
576
|
-
|
|
577
|
-
clear: (key?: (string | symbol) | undefined) => void;
|
|
578
|
-
};
|
|
579
|
-
get variableEngine(): VariableEngine;
|
|
580
|
-
get globalVariableTable(): VariableTable;
|
|
581
|
-
get onDataChange(): _flowgram_ai_utils.Event<void>;
|
|
582
|
-
get onAnyVariableChange(): (observer: (changedVariable: VariableDeclaration<any>) => void) => _flowgram_ai_utils.Disposable;
|
|
583
|
-
protected _hasChanges: boolean;
|
|
584
|
-
constructor(scope: Scope);
|
|
585
|
-
/**
|
|
586
|
-
* 作用域输出变量
|
|
587
|
-
*/
|
|
588
|
-
get variables(): VariableDeclaration[];
|
|
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;
|
|
589
1579
|
/**
|
|
590
|
-
*
|
|
1580
|
+
* Parent variable fields, sorted from closest to farthest
|
|
591
1581
|
*/
|
|
592
|
-
get
|
|
593
|
-
addVariableToTable(variable: VariableDeclaration): void;
|
|
594
|
-
setHasChanges(): void;
|
|
595
|
-
removeVariableFromTable(key: string): void;
|
|
596
|
-
getVariableByKey(key: string): VariableDeclaration<any> | undefined;
|
|
597
|
-
notifyCoversChange(): void;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* 作用域可用变量
|
|
602
|
-
*/
|
|
603
|
-
declare class ScopeAvailableData {
|
|
604
|
-
readonly scope: Scope;
|
|
605
|
-
protected memo: {
|
|
606
|
-
<T>(key: string | symbol, fn: () => T): T;
|
|
607
|
-
clear: (key?: (string | symbol) | undefined) => void;
|
|
608
|
-
};
|
|
609
|
-
get globalVariableTable(): VariableTable;
|
|
610
|
-
protected refresh$: Subject<void>;
|
|
611
|
-
protected _variables: VariableDeclaration[];
|
|
612
|
-
refresh(): void;
|
|
1582
|
+
get parentFields(): BaseVariableField[];
|
|
613
1583
|
/**
|
|
614
|
-
*
|
|
1584
|
+
* KeyPath of the variable field, sorted from farthest to closest
|
|
615
1585
|
*/
|
|
616
|
-
|
|
617
|
-
protected anyVariableChange$: Observable<VariableDeclaration>;
|
|
1586
|
+
get keyPath(): string[];
|
|
618
1587
|
/**
|
|
619
|
-
*
|
|
620
|
-
* @param observer 监听器,变量变化时会吐出值
|
|
621
|
-
* @returns
|
|
1588
|
+
* Metadata of the variable field, you cans store information like `title`, `icon`, etc.
|
|
622
1589
|
*/
|
|
623
|
-
|
|
1590
|
+
get meta(): VariableMeta;
|
|
624
1591
|
/**
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
* @returns
|
|
1592
|
+
* Type of the variable field, similar to js code:
|
|
1593
|
+
* `const v: string`
|
|
628
1594
|
*/
|
|
629
|
-
|
|
630
|
-
protected onDataChangeEmitter: Emitter<VariableDeclaration<any>[]>;
|
|
1595
|
+
get type(): BaseType;
|
|
631
1596
|
/**
|
|
632
|
-
*
|
|
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.
|
|
633
1601
|
*/
|
|
634
|
-
|
|
635
|
-
constructor(scope: Scope);
|
|
1602
|
+
get initializer(): BaseExpression | undefined;
|
|
636
1603
|
/**
|
|
637
|
-
*
|
|
1604
|
+
* The global unique hash of the field, and will be changed when the field is updated.
|
|
638
1605
|
*/
|
|
639
|
-
get
|
|
1606
|
+
get hash(): string;
|
|
640
1607
|
/**
|
|
641
|
-
*
|
|
1608
|
+
* Deserialize the `BaseVariableFieldJSON` to the `BaseVariableField`.
|
|
1609
|
+
* @param json ASTJSON representation of `BaseVariableField`
|
|
642
1610
|
*/
|
|
643
|
-
|
|
1611
|
+
fromJSON({ type, initializer, meta }: Omit<BaseVariableFieldJSON<VariableMeta>, 'key'>): void;
|
|
644
1612
|
/**
|
|
645
|
-
*
|
|
1613
|
+
* Update the type of the variable field
|
|
1614
|
+
* @param type type ASTJSON representation of Type
|
|
646
1615
|
*/
|
|
647
|
-
|
|
1616
|
+
updateType(type: BaseVariableFieldJSON['type']): void;
|
|
648
1617
|
/**
|
|
649
|
-
*
|
|
650
|
-
* @param
|
|
651
|
-
* @returns
|
|
1618
|
+
* Update the initializer of the variable field
|
|
1619
|
+
* @param nextInitializer initializer ASTJSON representation of Expression
|
|
652
1620
|
*/
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
type Observer<ActionType extends GlobalEventActionType = GlobalEventActionType> = (action: ActionType) => void;
|
|
657
|
-
declare class ScopeEventData {
|
|
658
|
-
readonly scope: Scope;
|
|
659
|
-
event$: Subject<GlobalEventActionType>;
|
|
660
|
-
dispatch<ActionType extends GlobalEventActionType = GlobalEventActionType>(action: ActionType): void;
|
|
661
|
-
subscribe<ActionType extends GlobalEventActionType = GlobalEventActionType>(observer: Observer<ActionType>): Disposable;
|
|
662
|
-
on<ActionType extends GlobalEventActionType = GlobalEventActionType>(type: ActionType['type'], observer: Observer<ActionType>): Disposable;
|
|
663
|
-
constructor(scope: Scope);
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
type ASTKindType = string;
|
|
667
|
-
type Identifier = string;
|
|
668
|
-
interface ASTNodeJSON {
|
|
669
|
-
kind?: ASTKindType;
|
|
670
|
-
key?: Identifier;
|
|
671
|
-
[key: string]: any;
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* 核心 AST 节点类型
|
|
675
|
-
*/
|
|
676
|
-
declare enum ASTKind {
|
|
1621
|
+
updateInitializer(nextInitializer?: BaseVariableFieldJSON['initializer']): void;
|
|
677
1622
|
/**
|
|
678
|
-
*
|
|
679
|
-
*
|
|
1623
|
+
* Update the meta data of the variable field
|
|
1624
|
+
* @param nextMeta meta data of the variable field
|
|
680
1625
|
*/
|
|
681
|
-
|
|
682
|
-
Number = "Number",
|
|
683
|
-
Integer = "Integer",
|
|
684
|
-
Boolean = "Boolean",
|
|
685
|
-
Object = "Object",
|
|
686
|
-
Array = "Array",
|
|
687
|
-
Map = "Map",
|
|
688
|
-
Union = "Union",
|
|
689
|
-
Any = "Any",
|
|
690
|
-
CustomType = "CustomType",
|
|
1626
|
+
updateMeta(nextMeta: VariableMeta): void;
|
|
691
1627
|
/**
|
|
692
|
-
*
|
|
1628
|
+
* Get the variable field by keyPath, similar to js code:
|
|
1629
|
+
* `v.a.b`
|
|
1630
|
+
* @param keyPath
|
|
1631
|
+
* @returns
|
|
693
1632
|
*/
|
|
694
|
-
|
|
695
|
-
VariableDeclaration = "VariableDeclaration",
|
|
696
|
-
VariableDeclarationList = "VariableDeclarationList",
|
|
1633
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
697
1634
|
/**
|
|
698
|
-
*
|
|
1635
|
+
* Subscribe to type change of the variable field
|
|
1636
|
+
* @param observer
|
|
1637
|
+
* @returns
|
|
699
1638
|
*/
|
|
700
|
-
|
|
701
|
-
EnumerateExpression = "EnumerateExpression",
|
|
702
|
-
ExpressionList = "ExpressionList",
|
|
1639
|
+
onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
|
|
703
1640
|
/**
|
|
704
|
-
*
|
|
1641
|
+
* Serialize the variable field to JSON
|
|
1642
|
+
* @returns ASTNodeJSON representation of `BaseVariableField`
|
|
705
1643
|
*/
|
|
706
|
-
|
|
707
|
-
DataNode = "DataNode",
|
|
708
|
-
MapNode = "MapNode"
|
|
709
|
-
}
|
|
710
|
-
interface CreateASTParams {
|
|
711
|
-
scope: Scope;
|
|
712
|
-
key?: Identifier;
|
|
713
|
-
parent?: ASTNode;
|
|
714
|
-
}
|
|
715
|
-
type ASTNodeJSONOrKind = string | ASTNodeJSON;
|
|
716
|
-
type ObserverOrNext<T> = Partial<Observer$1<T>> | ((value: T) => void);
|
|
717
|
-
interface SubscribeConfig<This, Data> {
|
|
718
|
-
debounceAnimation?: boolean;
|
|
719
|
-
triggerOnInit?: boolean;
|
|
720
|
-
selector?: (curr: This) => Data;
|
|
721
|
-
}
|
|
722
|
-
type GetKindJSON<KindType extends string, JSON extends ASTNodeJSON> = {
|
|
723
|
-
kind: KindType;
|
|
724
|
-
key?: Identifier;
|
|
725
|
-
} & JSON;
|
|
726
|
-
type GetKindJSONOrKind<KindType extends string, JSON extends ASTNodeJSON> = ({
|
|
727
|
-
kind: KindType;
|
|
728
|
-
key?: Identifier;
|
|
729
|
-
} & JSON) | KindType;
|
|
730
|
-
interface GlobalEventActionType<Type = string, Payload = any, AST extends ASTNode = ASTNode> {
|
|
731
|
-
type: Type;
|
|
732
|
-
payload?: Payload;
|
|
733
|
-
ast?: AST;
|
|
1644
|
+
toJSON(): BaseVariableFieldJSON<VariableMeta>;
|
|
734
1645
|
}
|
|
735
1646
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
1647
|
+
/**
|
|
1648
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1649
|
+
* SPDX-License-Identifier: MIT
|
|
1650
|
+
*/
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* ASTNodeJSON representation of the `VariableDeclaration`.
|
|
1654
|
+
*/
|
|
1655
|
+
type VariableDeclarationJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
|
|
740
1656
|
/**
|
|
741
|
-
*
|
|
1657
|
+
* Variable sorting order, which is used to sort variables in `scope.outputs.variables`
|
|
742
1658
|
*/
|
|
743
|
-
|
|
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> {
|
|
1665
|
+
static kind: string;
|
|
1666
|
+
protected _order: number;
|
|
744
1667
|
/**
|
|
745
|
-
*
|
|
746
|
-
* @param param 创建参数
|
|
747
|
-
* @returns
|
|
1668
|
+
* Variable sorting order, which is used to sort variables in `scope.outputs.variables`
|
|
748
1669
|
*/
|
|
749
|
-
|
|
1670
|
+
get order(): number;
|
|
1671
|
+
constructor(params: CreateASTParams);
|
|
750
1672
|
/**
|
|
751
|
-
*
|
|
752
|
-
* @param kind
|
|
753
|
-
* @returns
|
|
1673
|
+
* Deserialize the `VariableDeclarationJSON` to the `VariableDeclaration`.
|
|
754
1674
|
*/
|
|
755
|
-
|
|
1675
|
+
fromJSON({ order, ...rest }: Omit<VariableDeclarationJSON<VariableMeta>, 'key'>): void;
|
|
756
1676
|
/**
|
|
757
|
-
*
|
|
758
|
-
* @param
|
|
759
|
-
* @param injector
|
|
1677
|
+
* Update the sorting order of the variable declaration.
|
|
1678
|
+
* @param order Variable sorting order. Default is 0.
|
|
760
1679
|
*/
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
declare class DataNode<Data = any> extends ASTNode {
|
|
768
|
-
static kind: string;
|
|
769
|
-
protected _data: Data;
|
|
770
|
-
get data(): Data;
|
|
771
|
-
fromJSON(json: Data): void;
|
|
772
|
-
toJSON(): {
|
|
773
|
-
kind: ASTKind;
|
|
774
|
-
} & Data;
|
|
775
|
-
partialUpdate(nextData: Data): void;
|
|
1680
|
+
updateOrder(order?: number): void;
|
|
1681
|
+
/**
|
|
1682
|
+
* Serialize the `VariableDeclaration` to `VariableDeclarationJSON`.
|
|
1683
|
+
* @returns The JSON representation of `VariableDeclaration`.
|
|
1684
|
+
*/
|
|
1685
|
+
toJSON(): VariableDeclarationJSON<VariableMeta>;
|
|
776
1686
|
}
|
|
777
1687
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
static kind: string;
|
|
783
|
-
protected _list: ASTNode[];
|
|
784
|
-
get list(): ASTNode[];
|
|
785
|
-
fromJSON({ list }: ListNodeJSON): void;
|
|
786
|
-
toJSON(): ASTNodeJSON;
|
|
787
|
-
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1690
|
+
* SPDX-License-Identifier: MIT
|
|
1691
|
+
*/
|
|
788
1692
|
|
|
789
|
-
interface
|
|
790
|
-
|
|
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;
|
|
791
1702
|
}
|
|
792
|
-
|
|
1703
|
+
type VariableDeclarationListChangeAction = GlobalEventActionType<'VariableListChange', {
|
|
1704
|
+
prev: VariableDeclaration[];
|
|
1705
|
+
next: VariableDeclaration[];
|
|
1706
|
+
}, VariableDeclarationList>;
|
|
1707
|
+
declare class VariableDeclarationList extends ASTNode<VariableDeclarationListJSON> {
|
|
793
1708
|
static kind: string;
|
|
794
|
-
protected map: Map<string, ASTNode>;
|
|
795
|
-
fromJSON({ map }: MapNodeJSON): void;
|
|
796
|
-
toJSON(): ASTNodeJSON;
|
|
797
1709
|
/**
|
|
798
|
-
*
|
|
799
|
-
* @param key ASTNode 的索引,
|
|
800
|
-
* @param json
|
|
1710
|
+
* Map of variable declarations, keyed by variable name.
|
|
801
1711
|
*/
|
|
802
|
-
|
|
1712
|
+
declarationTable: Map<string, VariableDeclaration>;
|
|
803
1713
|
/**
|
|
804
|
-
*
|
|
805
|
-
* @param key
|
|
1714
|
+
* Variable declarations, sorted by `order`.
|
|
806
1715
|
*/
|
|
807
|
-
|
|
1716
|
+
declarations: VariableDeclaration[];
|
|
808
1717
|
/**
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
*
|
|
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.
|
|
812
1723
|
*/
|
|
813
|
-
|
|
1724
|
+
fromJSON({ declarations, startOrder }: VariableDeclarationListJSON): void;
|
|
1725
|
+
/**
|
|
1726
|
+
* Serialize the `VariableDeclarationList` to the `VariableDeclarationListJSON`.
|
|
1727
|
+
* @returns ASTJSON representation of `VariableDeclarationList`
|
|
1728
|
+
*/
|
|
1729
|
+
toJSON(): {
|
|
1730
|
+
kind: ASTKind;
|
|
1731
|
+
declarations: VariableDeclarationJSON<any>[];
|
|
1732
|
+
};
|
|
814
1733
|
}
|
|
815
1734
|
|
|
1735
|
+
/**
|
|
1736
|
+
* Variable-core ASTNode factories.
|
|
1737
|
+
*/
|
|
816
1738
|
declare namespace ASTFactory {
|
|
817
1739
|
/**
|
|
818
|
-
*
|
|
819
|
-
|
|
1740
|
+
* Type-related factories.
|
|
1741
|
+
*/
|
|
1742
|
+
/**
|
|
1743
|
+
* Creates a `String` type node.
|
|
820
1744
|
*/
|
|
821
|
-
const createString: () => {
|
|
1745
|
+
const createString: (json?: StringJSON) => {
|
|
1746
|
+
format?: string;
|
|
822
1747
|
kind: ASTKind;
|
|
823
1748
|
};
|
|
1749
|
+
/**
|
|
1750
|
+
* Creates a `Number` type node.
|
|
1751
|
+
*/
|
|
824
1752
|
const createNumber: () => {
|
|
825
1753
|
kind: ASTKind;
|
|
826
1754
|
};
|
|
1755
|
+
/**
|
|
1756
|
+
* Creates a `Boolean` type node.
|
|
1757
|
+
*/
|
|
827
1758
|
const createBoolean: () => {
|
|
828
1759
|
kind: ASTKind;
|
|
829
1760
|
};
|
|
1761
|
+
/**
|
|
1762
|
+
* Creates an `Integer` type node.
|
|
1763
|
+
*/
|
|
830
1764
|
const createInteger: () => {
|
|
831
1765
|
kind: ASTKind;
|
|
832
1766
|
};
|
|
1767
|
+
/**
|
|
1768
|
+
* Creates an `Object` type node.
|
|
1769
|
+
*/
|
|
833
1770
|
const createObject: (json: ObjectJSON) => {
|
|
834
1771
|
properties?: PropertyJSON<any>[] | undefined;
|
|
835
1772
|
kind: ASTKind;
|
|
836
1773
|
};
|
|
1774
|
+
/**
|
|
1775
|
+
* Creates an `Array` type node.
|
|
1776
|
+
*/
|
|
837
1777
|
const createArray: (json: ArrayJSON) => {
|
|
838
|
-
items?: ASTNodeJSONOrKind
|
|
1778
|
+
items?: ASTNodeJSONOrKind;
|
|
839
1779
|
kind: ASTKind;
|
|
840
1780
|
};
|
|
1781
|
+
/**
|
|
1782
|
+
* Creates a `Map` type node.
|
|
1783
|
+
*/
|
|
841
1784
|
const createMap: (json: MapJSON) => {
|
|
842
|
-
keyType?: ASTNodeJSONOrKind
|
|
843
|
-
valueType?: ASTNodeJSONOrKind
|
|
1785
|
+
keyType?: ASTNodeJSONOrKind;
|
|
1786
|
+
valueType?: ASTNodeJSONOrKind;
|
|
844
1787
|
kind: ASTKind;
|
|
845
1788
|
};
|
|
1789
|
+
/**
|
|
1790
|
+
* Creates a `Union` type node.
|
|
1791
|
+
*/
|
|
846
1792
|
const createUnion: (json: UnionJSON) => {
|
|
847
|
-
types?: ASTNodeJSONOrKind[]
|
|
1793
|
+
types?: ASTNodeJSONOrKind[];
|
|
848
1794
|
kind: ASTKind;
|
|
849
1795
|
};
|
|
1796
|
+
/**
|
|
1797
|
+
* Creates a `CustomType` node.
|
|
1798
|
+
*/
|
|
850
1799
|
const createCustomType: (json: CustomTypeJSON) => {
|
|
851
1800
|
typeName: string;
|
|
852
1801
|
kind: ASTKind;
|
|
853
1802
|
};
|
|
854
1803
|
/**
|
|
855
|
-
*
|
|
1804
|
+
* Declaration-related factories.
|
|
1805
|
+
*/
|
|
1806
|
+
/**
|
|
1807
|
+
* Creates a `VariableDeclaration` node.
|
|
856
1808
|
*/
|
|
857
1809
|
const createVariableDeclaration: <VariableMeta = any>(json: VariableDeclarationJSON<VariableMeta>) => {
|
|
858
|
-
key
|
|
859
|
-
type?: ASTNodeJSONOrKind
|
|
860
|
-
initializer?: ASTNodeJSON
|
|
1810
|
+
key: Identifier;
|
|
1811
|
+
type?: ASTNodeJSONOrKind;
|
|
1812
|
+
initializer?: ASTNodeJSON;
|
|
861
1813
|
meta?: VariableMeta | undefined;
|
|
862
|
-
|
|
863
|
-
|
|
1814
|
+
kind: ASTKindType;
|
|
1815
|
+
order?: number;
|
|
864
1816
|
};
|
|
1817
|
+
/**
|
|
1818
|
+
* Creates a `Property` node.
|
|
1819
|
+
*/
|
|
865
1820
|
const createProperty: <VariableMeta = any>(json: PropertyJSON<VariableMeta>) => {
|
|
866
|
-
key:
|
|
867
|
-
type?: ASTNodeJSONOrKind
|
|
868
|
-
initializer?: ASTNodeJSON
|
|
1821
|
+
key: Identifier;
|
|
1822
|
+
type?: ASTNodeJSONOrKind;
|
|
1823
|
+
initializer?: ASTNodeJSON;
|
|
869
1824
|
meta?: VariableMeta | undefined;
|
|
870
|
-
kind:
|
|
1825
|
+
kind: ASTKindType;
|
|
871
1826
|
};
|
|
1827
|
+
/**
|
|
1828
|
+
* Creates a `VariableDeclarationList` node.
|
|
1829
|
+
*/
|
|
872
1830
|
const createVariableDeclarationList: (json: VariableDeclarationListJSON) => {
|
|
873
1831
|
declarations?: VariableDeclarationJSON<any>[] | undefined;
|
|
874
|
-
startOrder?: number
|
|
1832
|
+
startOrder?: number;
|
|
875
1833
|
kind: ASTKind;
|
|
876
1834
|
};
|
|
877
1835
|
/**
|
|
878
|
-
*
|
|
1836
|
+
* Expression-related factories.
|
|
1837
|
+
*/
|
|
1838
|
+
/**
|
|
1839
|
+
* Creates an `EnumerateExpression` node.
|
|
879
1840
|
*/
|
|
880
1841
|
const createEnumerateExpression: (json: EnumerateExpressionJSON) => {
|
|
881
1842
|
enumerateFor: ASTNodeJSON;
|
|
882
1843
|
kind: ASTKind;
|
|
883
1844
|
};
|
|
1845
|
+
/**
|
|
1846
|
+
* Creates a `KeyPathExpression` node.
|
|
1847
|
+
*/
|
|
884
1848
|
const createKeyPathExpression: (json: KeyPathExpressionJSON$1) => {
|
|
885
1849
|
keyPath: string[];
|
|
886
1850
|
kind: ASTKind;
|
|
887
1851
|
};
|
|
888
1852
|
/**
|
|
889
|
-
*
|
|
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.
|
|
890
1868
|
*/
|
|
891
|
-
const create: <
|
|
892
|
-
new (...args: any[]): ASTNode<JSON_1, any>;
|
|
1869
|
+
const create: <JSON extends ASTNodeJSON>(targetType: {
|
|
893
1870
|
kind: string;
|
|
894
|
-
|
|
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?: {
|
|
895
1965
|
kind: string;
|
|
896
|
-
|
|
1966
|
+
new (...args: any[]): TargetASTNode;
|
|
1967
|
+
}): node is TargetASTNode;
|
|
897
1968
|
}
|
|
898
1969
|
|
|
1970
|
+
/**
|
|
1971
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
1972
|
+
* SPDX-License-Identifier: MIT
|
|
1973
|
+
*/
|
|
1974
|
+
|
|
899
1975
|
declare const injectToAST: (serviceIdentifier: interfaces.ServiceIdentifier) => (target: any, propertyKey: string) => any;
|
|
900
1976
|
declare const postConstructAST: () => (target: any, propertyKey: string) => void;
|
|
901
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
|
+
*/
|
|
902
1989
|
declare function isMatchAST<TargetASTNode extends ASTNode>(node?: ASTNode, targetType?: {
|
|
903
1990
|
kind: string;
|
|
904
1991
|
new (...args: any[]): TargetASTNode;
|
|
905
1992
|
}): node is TargetASTNode;
|
|
906
1993
|
|
|
907
|
-
|
|
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 {
|
|
908
2010
|
/**
|
|
909
|
-
*
|
|
2011
|
+
* The parent variable table.
|
|
910
2012
|
*/
|
|
911
|
-
|
|
2013
|
+
parentTable?: IVariableTable;
|
|
912
2014
|
/**
|
|
913
|
-
*
|
|
2015
|
+
* @deprecated Use `onVariableListChange` or `onAnyVariableChange` instead.
|
|
914
2016
|
*/
|
|
915
|
-
|
|
2017
|
+
onDataChange: Event<void>;
|
|
916
2018
|
/**
|
|
917
|
-
*
|
|
2019
|
+
* The current version of the variable table.
|
|
918
2020
|
*/
|
|
919
|
-
|
|
2021
|
+
version: number;
|
|
920
2022
|
/**
|
|
921
|
-
*
|
|
922
|
-
* - Map<formItemKey, formItemValue>
|
|
2023
|
+
* The list of variables in the table.
|
|
923
2024
|
*/
|
|
924
|
-
|
|
2025
|
+
variables: VariableDeclaration[];
|
|
925
2026
|
/**
|
|
926
|
-
*
|
|
2027
|
+
* The keys of the variables in the table.
|
|
927
2028
|
*/
|
|
928
|
-
|
|
2029
|
+
variableKeys: string[];
|
|
929
2030
|
/**
|
|
930
|
-
*
|
|
2031
|
+
* Fires a change event.
|
|
931
2032
|
*/
|
|
932
|
-
|
|
2033
|
+
fireChange(): void;
|
|
933
2034
|
/**
|
|
934
|
-
*
|
|
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`.
|
|
935
2038
|
*/
|
|
936
|
-
|
|
2039
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
937
2040
|
/**
|
|
938
|
-
*
|
|
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.
|
|
939
2048
|
*/
|
|
940
|
-
protected memo: {
|
|
941
|
-
<T>(key: string | symbol, fn: () => T): T;
|
|
942
|
-
clear: (key?: (string | symbol) | undefined) => void;
|
|
943
|
-
};
|
|
944
|
-
toDispose: DisposableCollection;
|
|
945
|
-
constructor(options: {
|
|
946
|
-
id: string;
|
|
947
|
-
variableEngine: VariableEngine;
|
|
948
|
-
meta?: ScopeMeta;
|
|
949
|
-
});
|
|
950
|
-
refreshCovers(): void;
|
|
951
|
-
refreshDeps(): void;
|
|
952
|
-
get depScopes(): Scope[];
|
|
953
|
-
get coverScopes(): Scope[];
|
|
954
2049
|
dispose(): void;
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
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;
|
|
962
2068
|
}
|
|
963
2069
|
|
|
2070
|
+
/**
|
|
2071
|
+
* The core of the variable engine system.
|
|
2072
|
+
* It manages scopes, variables, and events within the system.
|
|
2073
|
+
*/
|
|
964
2074
|
declare class VariableEngine implements Disposable {
|
|
2075
|
+
/**
|
|
2076
|
+
* The scope chain, which manages the dependency relationships between scopes.
|
|
2077
|
+
*/
|
|
965
2078
|
readonly chain: ScopeChain;
|
|
2079
|
+
/**
|
|
2080
|
+
* The registry for all AST node types.
|
|
2081
|
+
*/
|
|
966
2082
|
readonly astRegisters: ASTRegisters;
|
|
967
2083
|
protected toDispose: DisposableCollection;
|
|
968
2084
|
protected memo: {
|
|
969
2085
|
<T>(key: string | symbol, fn: () => T): T;
|
|
970
|
-
clear: (key?:
|
|
2086
|
+
clear: (key?: string | symbol) => void;
|
|
971
2087
|
};
|
|
972
|
-
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
|
+
*/
|
|
973
2092
|
globalEvent$: Subject<GlobalEventActionType>;
|
|
974
2093
|
protected onScopeChangeEmitter: Emitter<ScopeChangeAction>;
|
|
975
|
-
|
|
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
|
+
*/
|
|
976
2101
|
onScopeChange: _flowgram_ai_utils.Event<ScopeChangeAction>;
|
|
977
2102
|
private readonly containerProvider;
|
|
2103
|
+
/**
|
|
2104
|
+
* The Inversify container instance.
|
|
2105
|
+
*/
|
|
978
2106
|
get container(): interfaces.Container;
|
|
979
|
-
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
|
+
*/
|
|
980
2115
|
astRegisters: ASTRegisters);
|
|
2116
|
+
/**
|
|
2117
|
+
* Disposes of all resources used by the variable engine.
|
|
2118
|
+
*/
|
|
981
2119
|
dispose(): void;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
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
|
+
*/
|
|
985
2148
|
getAllScopes({ sort, }?: {
|
|
986
2149
|
sort?: boolean;
|
|
987
2150
|
}): Scope[];
|
|
2151
|
+
/**
|
|
2152
|
+
* Fires a global event to be broadcast to all listeners.
|
|
2153
|
+
* @param event The global event to fire.
|
|
2154
|
+
*/
|
|
988
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
|
+
*/
|
|
989
2162
|
onGlobalEvent<ActionType extends GlobalEventActionType = GlobalEventActionType>(type: ActionType['type'], observer: (action: ActionType) => void): Disposable;
|
|
990
2163
|
}
|
|
991
2164
|
|
|
2165
|
+
/**
|
|
2166
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
2167
|
+
* SPDX-License-Identifier: MIT
|
|
2168
|
+
*/
|
|
2169
|
+
|
|
992
2170
|
interface ScopeContextProps {
|
|
993
2171
|
scope: Scope;
|
|
994
2172
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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;
|
|
998
2196
|
|
|
999
2197
|
/**
|
|
1000
|
-
*
|
|
2198
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
2199
|
+
* SPDX-License-Identifier: MIT
|
|
1001
2200
|
*/
|
|
1002
|
-
declare function useScopeAvailable(): ScopeAvailableData;
|
|
1003
2201
|
|
|
1004
2202
|
/**
|
|
2203
|
+
* Get the available variables in the current scope.
|
|
1005
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.
|
|
1006
2222
|
*/
|
|
1007
2223
|
declare function useAvailableVariables(): VariableDeclaration[];
|
|
1008
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
|
+
|
|
1009
2237
|
interface RenameInfo {
|
|
1010
2238
|
before: BaseVariableField;
|
|
1011
2239
|
after: BaseVariableField;
|
|
1012
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
|
+
*/
|
|
1013
2246
|
declare class VariableFieldKeyRenameService {
|
|
1014
2247
|
variableEngine: VariableEngine;
|
|
1015
2248
|
toDispose: DisposableCollection;
|
|
1016
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
|
+
*/
|
|
1017
2254
|
disposeInListEmitter: Emitter<BaseVariableField<any>>;
|
|
2255
|
+
/**
|
|
2256
|
+
* An event that fires when a variable field key is successfully renamed.
|
|
2257
|
+
*/
|
|
1018
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
|
+
*/
|
|
1019
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
|
+
*/
|
|
1020
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
|
+
*/
|
|
1021
2275
|
notifyFieldsDispose(prev?: BaseVariableField[], next?: BaseVariableField[]): void;
|
|
1022
2276
|
init(): void;
|
|
1023
2277
|
dispose(): void;
|
|
1024
2278
|
}
|
|
1025
2279
|
|
|
1026
|
-
export { ASTFactory, ASTKind, ASTNode, ASTNodeFlags, type ASTNodeJSON, type ASTNodeRegistry, ASTRegisters, ArrayType, BaseExpression, BaseType, BaseVariableField, BooleanType, type CreateASTParams, CustomType, type CustomTypeJSON, DataNode, EnumerateExpression, type EnumerateExpressionJSON,
|
|
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 };
|