@flowgram-vue/variable-core 0.2.0

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