@flowgram.ai/variable-core 0.1.24 → 0.1.26
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 +157 -147
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +529 -547
- package/dist/index.d.ts +529 -547
- package/dist/index.js +176 -167
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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
6
|
import * as react from 'react';
|
|
7
7
|
|
|
@@ -10,6 +10,164 @@ declare const VariableContainerModule: ContainerModule;
|
|
|
10
10
|
declare const VariableEngineProvider: unique symbol;
|
|
11
11
|
type VariableEngineProvider = () => VariableEngine;
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 作用域输出
|
|
15
|
+
*/
|
|
16
|
+
declare class ScopeOutputData {
|
|
17
|
+
readonly scope: Scope;
|
|
18
|
+
protected variableTable: IVariableTable;
|
|
19
|
+
protected memo: {
|
|
20
|
+
<T>(key: string | symbol, fn: () => T): T;
|
|
21
|
+
clear: (key?: (string | symbol) | undefined) => void;
|
|
22
|
+
};
|
|
23
|
+
get variableEngine(): VariableEngine;
|
|
24
|
+
get globalVariableTable(): IVariableTable;
|
|
25
|
+
get onDataChange(): _flowgram_ai_utils.Event<void>;
|
|
26
|
+
get onAnyVariableChange(): (observer: (changedVariable: VariableDeclaration<any>) => void) => _flowgram_ai_utils.Disposable;
|
|
27
|
+
protected _hasChanges: boolean;
|
|
28
|
+
constructor(scope: Scope);
|
|
29
|
+
/**
|
|
30
|
+
* Scope Output Variable Declarations
|
|
31
|
+
*/
|
|
32
|
+
get variables(): VariableDeclaration[];
|
|
33
|
+
/**
|
|
34
|
+
* Output Variable Keys
|
|
35
|
+
*/
|
|
36
|
+
get variableKeys(): string[];
|
|
37
|
+
addVariableToTable(variable: VariableDeclaration): void;
|
|
38
|
+
removeVariableFromTable(key: string): void;
|
|
39
|
+
getVariableByKey(key: string): VariableDeclaration<any> | undefined;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
notifyCoversChange(): void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 作用域可用变量
|
|
48
|
+
*/
|
|
49
|
+
declare class ScopeAvailableData {
|
|
50
|
+
readonly scope: Scope;
|
|
51
|
+
protected memo: {
|
|
52
|
+
<T>(key: string | symbol, fn: () => T): T;
|
|
53
|
+
clear: (key?: (string | symbol) | undefined) => void;
|
|
54
|
+
};
|
|
55
|
+
get globalVariableTable(): IVariableTable;
|
|
56
|
+
protected refresh$: Subject<void>;
|
|
57
|
+
protected _variables: VariableDeclaration[];
|
|
58
|
+
refresh(): void;
|
|
59
|
+
/**
|
|
60
|
+
* 监听
|
|
61
|
+
*/
|
|
62
|
+
protected variables$: Observable<VariableDeclaration[]>;
|
|
63
|
+
protected anyVariableChange$: Observable<VariableDeclaration>;
|
|
64
|
+
/**
|
|
65
|
+
* 监听任意变量变化
|
|
66
|
+
* @param observer 监听器,变量变化时会吐出值
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
|
|
70
|
+
/**
|
|
71
|
+
* 监听变量列表变化
|
|
72
|
+
* @param observer
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
|
|
76
|
+
protected onDataChangeEmitter: Emitter<VariableDeclaration<any>[]>;
|
|
77
|
+
/**
|
|
78
|
+
* 监听变量列表变化 + 任意子变量变化
|
|
79
|
+
*/
|
|
80
|
+
onDataChange: _flowgram_ai_utils.Event<VariableDeclaration<any>[]>;
|
|
81
|
+
constructor(scope: Scope);
|
|
82
|
+
/**
|
|
83
|
+
* 获取可消费变量
|
|
84
|
+
*/
|
|
85
|
+
get variables(): VariableDeclaration[];
|
|
86
|
+
/**
|
|
87
|
+
* 获取可访问的变量 keys
|
|
88
|
+
*/
|
|
89
|
+
get variableKeys(): string[];
|
|
90
|
+
/**
|
|
91
|
+
* 返回依赖的作用域
|
|
92
|
+
*/
|
|
93
|
+
get depScopes(): Scope[];
|
|
94
|
+
/**
|
|
95
|
+
* 通过 keyPath 找到可用变量
|
|
96
|
+
* @param keyPath
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
getByKeyPath(keyPath?: string[]): VariableDeclaration | Property | undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type Observer<ActionType extends GlobalEventActionType = GlobalEventActionType> = (action: ActionType) => void;
|
|
103
|
+
declare class ScopeEventData {
|
|
104
|
+
readonly scope: Scope;
|
|
105
|
+
event$: Subject<GlobalEventActionType>;
|
|
106
|
+
dispatch<ActionType extends GlobalEventActionType = GlobalEventActionType>(action: ActionType): void;
|
|
107
|
+
subscribe<ActionType extends GlobalEventActionType = GlobalEventActionType>(observer: Observer<ActionType>): Disposable;
|
|
108
|
+
on<ActionType extends GlobalEventActionType = GlobalEventActionType>(type: ActionType['type'], observer: Observer<ActionType>): Disposable;
|
|
109
|
+
constructor(scope: Scope);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface IScopeConstructor {
|
|
113
|
+
new (options: {
|
|
114
|
+
id: string | symbol;
|
|
115
|
+
variableEngine: VariableEngine;
|
|
116
|
+
meta?: Record<string, any>;
|
|
117
|
+
}): Scope;
|
|
118
|
+
}
|
|
119
|
+
declare class Scope<ScopeMeta extends Record<string, any> = Record<string, any>> {
|
|
120
|
+
/**
|
|
121
|
+
* Scope 唯一索引
|
|
122
|
+
*/
|
|
123
|
+
readonly id: string | symbol;
|
|
124
|
+
/**
|
|
125
|
+
* Scope 依赖变量引擎
|
|
126
|
+
*/
|
|
127
|
+
readonly variableEngine: VariableEngine;
|
|
128
|
+
/**
|
|
129
|
+
* 作用域的基本元信息,包括作用域所在节点及一些 flag 信息,上层业务可以额外扩展
|
|
130
|
+
*/
|
|
131
|
+
readonly meta: ScopeMeta;
|
|
132
|
+
/**
|
|
133
|
+
* 作用域 AST 根节点
|
|
134
|
+
* - Map<formItemKey, formItemValue>
|
|
135
|
+
*/
|
|
136
|
+
readonly ast: MapNode;
|
|
137
|
+
/**
|
|
138
|
+
* 可用变量数据管理
|
|
139
|
+
*/
|
|
140
|
+
readonly available: ScopeAvailableData;
|
|
141
|
+
/**
|
|
142
|
+
* 输出变量数据管理
|
|
143
|
+
*/
|
|
144
|
+
readonly output: ScopeOutputData;
|
|
145
|
+
/**
|
|
146
|
+
* 作用域事件管理
|
|
147
|
+
*/
|
|
148
|
+
readonly event: ScopeEventData;
|
|
149
|
+
/**
|
|
150
|
+
* 数据缓存
|
|
151
|
+
*/
|
|
152
|
+
protected memo: {
|
|
153
|
+
<T>(key: string | symbol, fn: () => T): T;
|
|
154
|
+
clear: (key?: (string | symbol) | undefined) => void;
|
|
155
|
+
};
|
|
156
|
+
toDispose: DisposableCollection;
|
|
157
|
+
constructor(options: {
|
|
158
|
+
id: string | symbol;
|
|
159
|
+
variableEngine: VariableEngine;
|
|
160
|
+
meta?: ScopeMeta;
|
|
161
|
+
});
|
|
162
|
+
refreshCovers(): void;
|
|
163
|
+
refreshDeps(): void;
|
|
164
|
+
get depScopes(): Scope[];
|
|
165
|
+
get coverScopes(): Scope[];
|
|
166
|
+
dispose(): void;
|
|
167
|
+
onDispose: _flowgram_ai_utils.Event<void>;
|
|
168
|
+
get disposed(): boolean;
|
|
169
|
+
}
|
|
170
|
+
|
|
13
171
|
/**
|
|
14
172
|
* 作用域依赖关系管理数据结构
|
|
15
173
|
* - ScopeOrder 可能存在多种实现方式,因此采取抽象类的方式,具体的实现由子类实现
|
|
@@ -31,26 +189,6 @@ declare abstract class ScopeChain {
|
|
|
31
189
|
get onDispose(): Event<void>;
|
|
32
190
|
}
|
|
33
191
|
|
|
34
|
-
declare enum ASTNodeFlags {
|
|
35
|
-
None = 0,
|
|
36
|
-
/**
|
|
37
|
-
* 变量字段
|
|
38
|
-
*/
|
|
39
|
-
VariableField = 1,
|
|
40
|
-
/**
|
|
41
|
-
* 表达式
|
|
42
|
-
*/
|
|
43
|
-
Expression = 4,
|
|
44
|
-
/**
|
|
45
|
-
* 变量类型
|
|
46
|
-
*/
|
|
47
|
-
BasicType = 8,
|
|
48
|
-
DrilldownType = 16,
|
|
49
|
-
EnumerateType = 32,
|
|
50
|
-
UnionType = 64,
|
|
51
|
-
VariableType = 120
|
|
52
|
-
}
|
|
53
|
-
|
|
54
192
|
interface ASTNodeRegistry<JSON extends ASTNodeJSON = any, InjectOpts = any> {
|
|
55
193
|
kind: string;
|
|
56
194
|
new (params: CreateASTParams, injectOpts: InjectOpts): ASTNode<JSON>;
|
|
@@ -186,72 +324,197 @@ declare abstract class ASTNode<JSON extends ASTNodeJSON = any, InjectOpts = any>
|
|
|
186
324
|
[key: string]: unknown;
|
|
187
325
|
}
|
|
188
326
|
|
|
327
|
+
type ASTKindType = string;
|
|
328
|
+
type Identifier = string;
|
|
329
|
+
interface ASTNodeJSON {
|
|
330
|
+
kind?: ASTKindType;
|
|
331
|
+
key?: Identifier;
|
|
332
|
+
[key: string]: any;
|
|
333
|
+
}
|
|
189
334
|
/**
|
|
190
|
-
*
|
|
335
|
+
* 核心 AST 节点类型
|
|
191
336
|
*/
|
|
192
|
-
|
|
193
|
-
order?: number;
|
|
194
|
-
};
|
|
195
|
-
declare class VariableDeclaration<VariableMeta = any> extends BaseVariableField<VariableMeta> {
|
|
196
|
-
static kind: string;
|
|
197
|
-
protected _order: number;
|
|
198
|
-
get order(): number;
|
|
199
|
-
constructor(params: CreateASTParams);
|
|
337
|
+
declare enum ASTKind {
|
|
200
338
|
/**
|
|
201
|
-
*
|
|
339
|
+
* 类型相关
|
|
340
|
+
* - 内部默认实现一套基于 JSON 类型的类型 AST 节点
|
|
202
341
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
342
|
+
String = "String",
|
|
343
|
+
Number = "Number",
|
|
344
|
+
Integer = "Integer",
|
|
345
|
+
Boolean = "Boolean",
|
|
346
|
+
Object = "Object",
|
|
347
|
+
Array = "Array",
|
|
348
|
+
Map = "Map",
|
|
349
|
+
Union = "Union",
|
|
350
|
+
Any = "Any",
|
|
351
|
+
CustomType = "CustomType",
|
|
209
352
|
/**
|
|
210
|
-
*
|
|
353
|
+
* 声明
|
|
211
354
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
type VariableDeclarationListChangeAction = GlobalEventActionType<'VariableListChange', {
|
|
216
|
-
prev: VariableDeclaration[];
|
|
217
|
-
next: VariableDeclaration[];
|
|
218
|
-
}, VariableDeclarationList>;
|
|
219
|
-
declare class VariableDeclarationList extends ASTNode<VariableDeclarationListJSON> {
|
|
220
|
-
static kind: string;
|
|
221
|
-
declarationTable: Map<string, VariableDeclaration>;
|
|
222
|
-
declarations: VariableDeclaration[];
|
|
223
|
-
fromJSON({ declarations, startOrder }: VariableDeclarationListJSON): void;
|
|
224
|
-
toJSON(): ASTNodeJSON;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
|
|
228
|
-
key: string;
|
|
229
|
-
};
|
|
230
|
-
declare class Property<VariableMeta = any> extends BaseVariableField<VariableMeta> {
|
|
231
|
-
static kind: string;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
|
|
235
|
-
flags: number;
|
|
355
|
+
Property = "Property",
|
|
356
|
+
VariableDeclaration = "VariableDeclaration",
|
|
357
|
+
VariableDeclarationList = "VariableDeclarationList",
|
|
236
358
|
/**
|
|
237
|
-
*
|
|
238
|
-
* @param targetTypeJSON
|
|
359
|
+
* 表达式
|
|
239
360
|
*/
|
|
240
|
-
|
|
361
|
+
KeyPathExpression = "KeyPathExpression",
|
|
362
|
+
EnumerateExpression = "EnumerateExpression",
|
|
363
|
+
ExpressionList = "ExpressionList",
|
|
241
364
|
/**
|
|
242
|
-
*
|
|
243
|
-
* @param keyPath
|
|
365
|
+
* 通用 AST 节点
|
|
244
366
|
*/
|
|
245
|
-
|
|
246
|
-
|
|
367
|
+
ListNode = "ListNode",
|
|
368
|
+
DataNode = "DataNode",
|
|
369
|
+
MapNode = "MapNode"
|
|
247
370
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
fromJSON(): void;
|
|
371
|
+
interface CreateASTParams {
|
|
372
|
+
scope: Scope;
|
|
373
|
+
key?: Identifier;
|
|
374
|
+
parent?: ASTNode;
|
|
253
375
|
}
|
|
254
|
-
|
|
376
|
+
type ASTNodeJSONOrKind = string | ASTNodeJSON;
|
|
377
|
+
type ObserverOrNext<T> = Partial<Observer$1<T>> | ((value: T) => void);
|
|
378
|
+
interface SubscribeConfig<This, Data> {
|
|
379
|
+
debounceAnimation?: boolean;
|
|
380
|
+
triggerOnInit?: boolean;
|
|
381
|
+
selector?: (curr: This) => Data;
|
|
382
|
+
}
|
|
383
|
+
type GetKindJSON<KindType extends string, JSON extends ASTNodeJSON> = {
|
|
384
|
+
kind: KindType;
|
|
385
|
+
key?: Identifier;
|
|
386
|
+
} & JSON;
|
|
387
|
+
type GetKindJSONOrKind<KindType extends string, JSON extends ASTNodeJSON> = ({
|
|
388
|
+
kind: KindType;
|
|
389
|
+
key?: Identifier;
|
|
390
|
+
} & JSON) | KindType;
|
|
391
|
+
interface GlobalEventActionType<Type = string, Payload = any, AST extends ASTNode = ASTNode> {
|
|
392
|
+
type: Type;
|
|
393
|
+
payload?: Payload;
|
|
394
|
+
ast?: AST;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
type DataInjector = () => Record<string, any>;
|
|
398
|
+
declare class ASTRegisters {
|
|
399
|
+
protected injectors: Map<ASTKindType, DataInjector>;
|
|
400
|
+
protected astMap: Map<ASTKindType, ASTNodeRegistry>;
|
|
401
|
+
/**
|
|
402
|
+
* 核心 AST 节点注册
|
|
403
|
+
*/
|
|
404
|
+
constructor();
|
|
405
|
+
/**
|
|
406
|
+
* 创建 AST 节点
|
|
407
|
+
* @param param 创建参数
|
|
408
|
+
* @returns
|
|
409
|
+
*/
|
|
410
|
+
createAST<ReturnNode extends ASTNode = ASTNode>(json: ASTNodeJSON, { parent, scope }: CreateASTParams): ReturnNode;
|
|
411
|
+
/**
|
|
412
|
+
* 根据 AST 节点类型获取节点 Registry
|
|
413
|
+
* @param kind
|
|
414
|
+
* @returns
|
|
415
|
+
*/
|
|
416
|
+
getASTRegistryByKind(kind: ASTKindType): ASTNodeRegistry<any, any> | undefined;
|
|
417
|
+
/**
|
|
418
|
+
* 注册 AST 节点
|
|
419
|
+
* @param ASTNode
|
|
420
|
+
* @param injector
|
|
421
|
+
*/
|
|
422
|
+
registerAST(ASTNode: ASTNodeRegistry, injector?: DataInjector): void;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
declare enum ASTNodeFlags {
|
|
426
|
+
None = 0,
|
|
427
|
+
/**
|
|
428
|
+
* 变量字段
|
|
429
|
+
*/
|
|
430
|
+
VariableField = 1,
|
|
431
|
+
/**
|
|
432
|
+
* 表达式
|
|
433
|
+
*/
|
|
434
|
+
Expression = 4,
|
|
435
|
+
/**
|
|
436
|
+
* 变量类型
|
|
437
|
+
*/
|
|
438
|
+
BasicType = 8,
|
|
439
|
+
DrilldownType = 16,
|
|
440
|
+
EnumerateType = 32,
|
|
441
|
+
UnionType = 64,
|
|
442
|
+
VariableType = 120
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* 通用数据 AST 节点,无子节点
|
|
447
|
+
*/
|
|
448
|
+
declare class DataNode<Data = any> extends ASTNode {
|
|
449
|
+
static kind: string;
|
|
450
|
+
protected _data: Data;
|
|
451
|
+
get data(): Data;
|
|
452
|
+
fromJSON(json: Data): void;
|
|
453
|
+
toJSON(): {
|
|
454
|
+
kind: ASTKind;
|
|
455
|
+
} & Data;
|
|
456
|
+
partialUpdate(nextData: Data): void;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
interface ListNodeJSON {
|
|
460
|
+
list: ASTNodeJSON[];
|
|
461
|
+
}
|
|
462
|
+
declare class ListNode extends ASTNode<ListNodeJSON> {
|
|
463
|
+
static kind: string;
|
|
464
|
+
protected _list: ASTNode[];
|
|
465
|
+
get list(): ASTNode[];
|
|
466
|
+
fromJSON({ list }: ListNodeJSON): void;
|
|
467
|
+
toJSON(): ASTNodeJSON;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
interface MapNodeJSON {
|
|
471
|
+
map: [string, ASTNodeJSON][];
|
|
472
|
+
}
|
|
473
|
+
declare class MapNode extends ASTNode<MapNodeJSON> {
|
|
474
|
+
static kind: string;
|
|
475
|
+
protected map: Map<string, ASTNode>;
|
|
476
|
+
fromJSON({ map }: MapNodeJSON): void;
|
|
477
|
+
toJSON(): ASTNodeJSON;
|
|
478
|
+
/**
|
|
479
|
+
* 往 Map 中设置 ASTNode
|
|
480
|
+
* @param key ASTNode 的索引,
|
|
481
|
+
* @param json
|
|
482
|
+
*/
|
|
483
|
+
set<Node extends ASTNode = ASTNode>(key: string, nextJSON: ASTNodeJSON): Node;
|
|
484
|
+
/**
|
|
485
|
+
* 移除指定 ASTNode
|
|
486
|
+
* @param key
|
|
487
|
+
*/
|
|
488
|
+
remove(key: string): void;
|
|
489
|
+
/**
|
|
490
|
+
* 获取 ASTNode
|
|
491
|
+
* @param key
|
|
492
|
+
* @returns
|
|
493
|
+
*/
|
|
494
|
+
get(key: string): ASTNode | undefined;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
|
|
498
|
+
flags: number;
|
|
499
|
+
/**
|
|
500
|
+
* 类型是否一致,节点有额外信息判断,请参考 extraTypeInfoEqual
|
|
501
|
+
* @param targetTypeJSON
|
|
502
|
+
*/
|
|
503
|
+
isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
|
|
504
|
+
/**
|
|
505
|
+
* 可下钻类型需实现
|
|
506
|
+
* @param keyPath
|
|
507
|
+
*/
|
|
508
|
+
getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
|
|
509
|
+
toJSON(): ASTNodeJSON;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
declare class StringType extends BaseType {
|
|
513
|
+
flags: ASTNodeFlags;
|
|
514
|
+
static kind: string;
|
|
515
|
+
fromJSON(): void;
|
|
516
|
+
}
|
|
517
|
+
|
|
255
518
|
declare class IntegerType extends BaseType {
|
|
256
519
|
flags: ASTNodeFlags;
|
|
257
520
|
static kind: string;
|
|
@@ -307,6 +570,13 @@ declare class MapType extends BaseType<MapJSON> {
|
|
|
307
570
|
toJSON(): ASTNodeJSON;
|
|
308
571
|
}
|
|
309
572
|
|
|
573
|
+
type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
|
|
574
|
+
key: string;
|
|
575
|
+
};
|
|
576
|
+
declare class Property<VariableMeta = any> extends BaseVariableField<VariableMeta> {
|
|
577
|
+
static kind: string;
|
|
578
|
+
}
|
|
579
|
+
|
|
310
580
|
interface ObjectJSON<VariableMeta = any> {
|
|
311
581
|
/**
|
|
312
582
|
* Object 的 properties 一定是 Property 类型,因此业务可以不用填 kind
|
|
@@ -360,7 +630,7 @@ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts
|
|
|
360
630
|
/**
|
|
361
631
|
* 获取全局变量表,方便表达式获取引用变量
|
|
362
632
|
*/
|
|
363
|
-
get globalVariableTable():
|
|
633
|
+
get globalVariableTable(): IVariableTable;
|
|
364
634
|
/**
|
|
365
635
|
* 父变量字段,通过由近而远的方式进行排序
|
|
366
636
|
*/
|
|
@@ -373,444 +643,186 @@ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts
|
|
|
373
643
|
/**
|
|
374
644
|
* 表达式返回的数据类型
|
|
375
645
|
*/
|
|
376
|
-
abstract returnType: BaseType | undefined;
|
|
377
|
-
/**
|
|
378
|
-
* 引用变量
|
|
379
|
-
*/
|
|
380
|
-
protected _refs: ExpressionRefs;
|
|
381
|
-
get refs(): ExpressionRefs;
|
|
382
|
-
protected refreshRefs$: Subject<void>;
|
|
383
|
-
/**
|
|
384
|
-
* 刷新变量引用
|
|
385
|
-
*/
|
|
386
|
-
refreshRefs(): void;
|
|
387
|
-
/**
|
|
388
|
-
* 监听引用变量变化
|
|
389
|
-
* 监听 [a.b.c] -> [a.b]
|
|
390
|
-
*/
|
|
391
|
-
refs$: Observable<ExpressionRefs>;
|
|
392
|
-
constructor(params: CreateASTParams, opts?: InjectOpts);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
interface ExpressionListJSON {
|
|
396
|
-
expressions: ASTNodeJSON[];
|
|
397
|
-
}
|
|
398
|
-
declare class ExpressionList extends ASTNode<ExpressionListJSON> {
|
|
399
|
-
static kind: string;
|
|
400
|
-
expressions: ASTNode[];
|
|
401
|
-
fromJSON({ expressions }: ExpressionListJSON): void;
|
|
402
|
-
toJSON(): ASTNodeJSON;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
interface KeyPathExpressionJSON$1 {
|
|
406
|
-
keyPath: string[];
|
|
407
|
-
}
|
|
408
|
-
declare class KeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON$1> extends BaseExpression<CustomPathJSON> {
|
|
409
|
-
static kind: string;
|
|
410
|
-
protected _keyPath: string[];
|
|
411
|
-
get keyPath(): string[];
|
|
412
|
-
getRefFields(): BaseVariableField[];
|
|
413
|
-
get returnType(): BaseType | undefined;
|
|
414
|
-
/**
|
|
415
|
-
* 业务重改该方法可快速定制自己的 Path 表达式
|
|
416
|
-
* - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
|
|
417
|
-
* @param json 业务定义的 Path 表达式
|
|
418
|
-
* @returns
|
|
419
|
-
*/
|
|
420
|
-
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
421
|
-
fromJSON(json: CustomPathJSON): void;
|
|
422
|
-
constructor(params: CreateASTParams, opts: any);
|
|
423
|
-
toJSON(): ASTNodeJSON;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
interface EnumerateExpressionJSON {
|
|
427
|
-
enumerateFor: ASTNodeJSON;
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* 遍历表达式,对列表进行遍历,获取遍历后的变量类型
|
|
431
|
-
*/
|
|
432
|
-
declare class EnumerateExpression extends BaseExpression<EnumerateExpressionJSON> {
|
|
433
|
-
static kind: string;
|
|
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;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
interface KeyPathExpressionJSON {
|
|
443
|
-
keyPath: string[];
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* 新版 KeyPathExpressionV2,相比旧版:
|
|
447
|
-
* - returnType 拷贝新一份,避免引用问题
|
|
448
|
-
* - 引入成环检测
|
|
449
|
-
*/
|
|
450
|
-
declare class KeyPathExpressionV2<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON> extends BaseExpression<CustomPathJSON> {
|
|
451
|
-
static kind: string;
|
|
452
|
-
protected _keyPath: string[];
|
|
453
|
-
get keyPath(): string[];
|
|
454
|
-
getRefFields(): BaseVariableField[];
|
|
455
|
-
_returnType: BaseType;
|
|
456
|
-
get returnType(): BaseType<any, any>;
|
|
457
|
-
/**
|
|
458
|
-
* 业务重改该方法可快速定制自己的 Path 表达式
|
|
459
|
-
* - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
|
|
460
|
-
* @param json 业务定义的 Path 表达式
|
|
461
|
-
* @returns
|
|
462
|
-
*/
|
|
463
|
-
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
464
|
-
fromJSON(json: CustomPathJSON): void;
|
|
465
|
-
getReturnTypeJSONByRef(_ref: BaseVariableField | undefined): ASTNodeJSON | undefined;
|
|
466
|
-
protected prevRefTypeHash: string | undefined;
|
|
467
|
-
constructor(params: CreateASTParams, opts: any);
|
|
468
|
-
toJSON(): ASTNodeJSON;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
/**
|
|
472
|
-
* 声明类 AST 节点
|
|
473
|
-
*/
|
|
474
|
-
type BaseVariableFieldJSON<VariableMeta = any> = {
|
|
475
|
-
key?: Identifier;
|
|
476
|
-
type?: ASTNodeJSONOrKind;
|
|
477
|
-
initializer?: ASTNodeJSON;
|
|
478
|
-
meta?: VariableMeta;
|
|
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;
|
|
485
|
-
/**
|
|
486
|
-
* 父变量字段,通过由近而远的方式进行排序
|
|
487
|
-
*/
|
|
488
|
-
get parentFields(): BaseVariableField[];
|
|
489
|
-
get meta(): VariableMeta;
|
|
490
|
-
get type(): BaseType;
|
|
491
|
-
get initializer(): BaseExpression | undefined;
|
|
492
|
-
/**
|
|
493
|
-
* 解析 VariableDeclarationJSON 从而生成变量声明节点
|
|
494
|
-
*/
|
|
495
|
-
fromJSON({ type, initializer, meta }: BaseVariableFieldJSON<VariableMeta>): void;
|
|
496
|
-
updateType(type: BaseVariableFieldJSON['type']): void;
|
|
497
|
-
updateInitializer(nextInitializer?: BaseVariableFieldJSON['initializer']): void;
|
|
498
|
-
updateMeta(nextMeta: VariableMeta): void;
|
|
499
|
-
/**
|
|
500
|
-
* 根据 keyPath 去找下钻的变量字段
|
|
501
|
-
* @param keyPath
|
|
502
|
-
* @returns
|
|
503
|
-
*/
|
|
504
|
-
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
505
|
-
/**
|
|
506
|
-
* 监听类型变化
|
|
507
|
-
* @param observer
|
|
508
|
-
* @returns
|
|
509
|
-
*/
|
|
510
|
-
onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
|
|
511
|
-
/**
|
|
512
|
-
* 转换为 JSON
|
|
513
|
-
* @returns
|
|
514
|
-
*/
|
|
515
|
-
toJSON(): BaseVariableFieldJSON<VariableMeta> & {
|
|
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>;
|
|
526
|
-
/**
|
|
527
|
-
* 监听任意变量变化
|
|
528
|
-
* @param observer 监听器,变量变化时会吐出值
|
|
529
|
-
* @returns
|
|
530
|
-
*/
|
|
531
|
-
onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
|
|
532
|
-
/**
|
|
533
|
-
* 列表或者任意变量变化
|
|
534
|
-
* @param observer
|
|
535
|
-
*/
|
|
536
|
-
onAnyChange(observer: () => void): DisposableCollection;
|
|
537
|
-
onDataChange: _flowgram_ai_utils.Event<void>;
|
|
538
|
-
protected _version: number;
|
|
539
|
-
fireChange(): void;
|
|
540
|
-
get version(): number;
|
|
541
|
-
constructor(parentTable?: VariableTable | undefined);
|
|
542
|
-
get variables(): VariableDeclaration[];
|
|
543
|
-
get variableKeys(): string[];
|
|
544
|
-
/**
|
|
545
|
-
* 根据 keyPath 找到对应的变量,或 Property 节点
|
|
546
|
-
* @param keyPath
|
|
547
|
-
* @returns
|
|
548
|
-
*/
|
|
549
|
-
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
550
|
-
/**
|
|
551
|
-
* 根据 key 值找到相应的变量
|
|
552
|
-
* @param key
|
|
553
|
-
* @returns
|
|
554
|
-
*/
|
|
555
|
-
getVariableByKey(key: string): VariableDeclaration<any> | undefined;
|
|
556
|
-
/**
|
|
557
|
-
* 往 variableTable 添加输出变量
|
|
558
|
-
* @param variable
|
|
559
|
-
*/
|
|
560
|
-
addVariableToTable(variable: VariableDeclaration): void;
|
|
561
|
-
/**
|
|
562
|
-
* 从 variableTable 中移除变量
|
|
563
|
-
* @param key
|
|
564
|
-
*/
|
|
565
|
-
removeVariableFromTable(key: string): void;
|
|
566
|
-
dispose(): void;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* 作用域输出
|
|
571
|
-
*/
|
|
572
|
-
declare class ScopeOutputData {
|
|
573
|
-
readonly scope: Scope;
|
|
574
|
-
protected variableTable: VariableTable;
|
|
575
|
-
protected memo: {
|
|
576
|
-
<T>(key: string | symbol, fn: () => T): T;
|
|
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[];
|
|
589
|
-
/**
|
|
590
|
-
* 输出的变量 keys
|
|
591
|
-
*/
|
|
592
|
-
get variableKeys(): string[];
|
|
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;
|
|
613
|
-
/**
|
|
614
|
-
* 监听
|
|
615
|
-
*/
|
|
616
|
-
protected variables$: Observable<VariableDeclaration[]>;
|
|
617
|
-
protected anyVariableChange$: Observable<VariableDeclaration>;
|
|
618
|
-
/**
|
|
619
|
-
* 监听任意变量变化
|
|
620
|
-
* @param observer 监听器,变量变化时会吐出值
|
|
621
|
-
* @returns
|
|
622
|
-
*/
|
|
623
|
-
onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
|
|
624
|
-
/**
|
|
625
|
-
* 监听变量列表变化
|
|
626
|
-
* @param observer
|
|
627
|
-
* @returns
|
|
628
|
-
*/
|
|
629
|
-
onVariableListChange(observer: (variables: VariableDeclaration[]) => void): Disposable;
|
|
630
|
-
protected onDataChangeEmitter: Emitter<VariableDeclaration<any>[]>;
|
|
631
|
-
/**
|
|
632
|
-
* 监听变量列表变化 + 任意子变量变化
|
|
633
|
-
*/
|
|
634
|
-
onDataChange: _flowgram_ai_utils.Event<VariableDeclaration<any>[]>;
|
|
635
|
-
constructor(scope: Scope);
|
|
636
|
-
/**
|
|
637
|
-
* 获取可消费变量
|
|
638
|
-
*/
|
|
639
|
-
get variables(): VariableDeclaration[];
|
|
640
|
-
/**
|
|
641
|
-
* 获取可访问的变量 keys
|
|
642
|
-
*/
|
|
643
|
-
get variableKeys(): string[];
|
|
644
|
-
/**
|
|
645
|
-
* 返回依赖的作用域
|
|
646
|
-
*/
|
|
647
|
-
get depScopes(): Scope[];
|
|
648
|
-
/**
|
|
649
|
-
* 通过 keyPath 找到可用变量
|
|
650
|
-
* @param keyPath
|
|
651
|
-
* @returns
|
|
652
|
-
*/
|
|
653
|
-
getByKeyPath(keyPath?: string[]): VariableDeclaration | Property | undefined;
|
|
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 {
|
|
677
|
-
/**
|
|
678
|
-
* 类型相关
|
|
679
|
-
* - 内部默认实现一套基于 JSON 类型的类型 AST 节点
|
|
680
|
-
*/
|
|
681
|
-
String = "String",
|
|
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",
|
|
691
|
-
/**
|
|
692
|
-
* 声明
|
|
693
|
-
*/
|
|
694
|
-
Property = "Property",
|
|
695
|
-
VariableDeclaration = "VariableDeclaration",
|
|
696
|
-
VariableDeclarationList = "VariableDeclarationList",
|
|
697
|
-
/**
|
|
698
|
-
* 表达式
|
|
699
|
-
*/
|
|
700
|
-
KeyPathExpression = "KeyPathExpression",
|
|
701
|
-
EnumerateExpression = "EnumerateExpression",
|
|
702
|
-
ExpressionList = "ExpressionList",
|
|
703
|
-
/**
|
|
704
|
-
* 通用 AST 节点
|
|
705
|
-
*/
|
|
706
|
-
ListNode = "ListNode",
|
|
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;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
type DataInjector = () => Record<string, any>;
|
|
737
|
-
declare class ASTRegisters {
|
|
738
|
-
protected injectors: Map<ASTKindType, DataInjector>;
|
|
739
|
-
protected astMap: Map<ASTKindType, ASTNodeRegistry>;
|
|
740
|
-
/**
|
|
741
|
-
* 核心 AST 节点注册
|
|
742
|
-
*/
|
|
743
|
-
constructor();
|
|
646
|
+
abstract returnType: BaseType | undefined;
|
|
744
647
|
/**
|
|
745
|
-
*
|
|
746
|
-
* @param param 创建参数
|
|
747
|
-
* @returns
|
|
648
|
+
* 引用变量
|
|
748
649
|
*/
|
|
749
|
-
|
|
650
|
+
protected _refs: ExpressionRefs;
|
|
651
|
+
get refs(): ExpressionRefs;
|
|
652
|
+
protected refreshRefs$: Subject<void>;
|
|
750
653
|
/**
|
|
751
|
-
*
|
|
752
|
-
* @param kind
|
|
753
|
-
* @returns
|
|
654
|
+
* 刷新变量引用
|
|
754
655
|
*/
|
|
755
|
-
|
|
656
|
+
refreshRefs(): void;
|
|
756
657
|
/**
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
* @param injector
|
|
658
|
+
* 监听引用变量变化
|
|
659
|
+
* 监听 [a.b.c] -> [a.b]
|
|
760
660
|
*/
|
|
761
|
-
|
|
661
|
+
refs$: Observable<ExpressionRefs>;
|
|
662
|
+
constructor(params: CreateASTParams, opts?: InjectOpts);
|
|
762
663
|
}
|
|
763
664
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
declare class
|
|
665
|
+
interface ExpressionListJSON {
|
|
666
|
+
expressions: ASTNodeJSON[];
|
|
667
|
+
}
|
|
668
|
+
declare class ExpressionList extends ASTNode<ExpressionListJSON> {
|
|
768
669
|
static kind: string;
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
toJSON(): {
|
|
773
|
-
kind: ASTKind;
|
|
774
|
-
} & Data;
|
|
775
|
-
partialUpdate(nextData: Data): void;
|
|
670
|
+
expressions: ASTNode[];
|
|
671
|
+
fromJSON({ expressions }: ExpressionListJSON): void;
|
|
672
|
+
toJSON(): ASTNodeJSON;
|
|
776
673
|
}
|
|
777
674
|
|
|
778
|
-
interface
|
|
779
|
-
|
|
675
|
+
interface KeyPathExpressionJSON$1 {
|
|
676
|
+
keyPath: string[];
|
|
780
677
|
}
|
|
781
|
-
declare class
|
|
678
|
+
declare class KeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON$1> extends BaseExpression<CustomPathJSON> {
|
|
782
679
|
static kind: string;
|
|
783
|
-
protected
|
|
784
|
-
get
|
|
785
|
-
|
|
680
|
+
protected _keyPath: string[];
|
|
681
|
+
get keyPath(): string[];
|
|
682
|
+
getRefFields(): BaseVariableField[];
|
|
683
|
+
get returnType(): BaseType | undefined;
|
|
684
|
+
/**
|
|
685
|
+
* 业务重改该方法可快速定制自己的 Path 表达式
|
|
686
|
+
* - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
|
|
687
|
+
* @param json 业务定义的 Path 表达式
|
|
688
|
+
* @returns
|
|
689
|
+
*/
|
|
690
|
+
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
691
|
+
fromJSON(json: CustomPathJSON): void;
|
|
692
|
+
constructor(params: CreateASTParams, opts: any);
|
|
786
693
|
toJSON(): ASTNodeJSON;
|
|
787
694
|
}
|
|
788
695
|
|
|
789
|
-
interface
|
|
790
|
-
|
|
696
|
+
interface EnumerateExpressionJSON {
|
|
697
|
+
enumerateFor: ASTNodeJSON;
|
|
791
698
|
}
|
|
792
|
-
|
|
699
|
+
/**
|
|
700
|
+
* 遍历表达式,对列表进行遍历,获取遍历后的变量类型
|
|
701
|
+
*/
|
|
702
|
+
declare class EnumerateExpression extends BaseExpression<EnumerateExpressionJSON> {
|
|
793
703
|
static kind: string;
|
|
794
|
-
protected
|
|
795
|
-
|
|
704
|
+
protected _enumerateFor: BaseExpression | undefined;
|
|
705
|
+
get enumerateFor(): BaseExpression<any, any> | undefined;
|
|
706
|
+
get returnType(): BaseType | undefined;
|
|
707
|
+
getRefFields(): [];
|
|
708
|
+
fromJSON({ enumerateFor: expression }: EnumerateExpressionJSON): void;
|
|
796
709
|
toJSON(): ASTNodeJSON;
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
interface KeyPathExpressionJSON {
|
|
713
|
+
keyPath: string[];
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* 新版 KeyPathExpressionV2,相比旧版:
|
|
717
|
+
* - returnType 拷贝新一份,避免引用问题
|
|
718
|
+
* - 引入成环检测
|
|
719
|
+
*/
|
|
720
|
+
declare class KeyPathExpressionV2<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON> extends BaseExpression<CustomPathJSON> {
|
|
721
|
+
static kind: string;
|
|
722
|
+
protected _keyPath: string[];
|
|
723
|
+
get keyPath(): string[];
|
|
724
|
+
getRefFields(): BaseVariableField[];
|
|
725
|
+
_returnType: BaseType;
|
|
726
|
+
get returnType(): BaseType<any, any>;
|
|
797
727
|
/**
|
|
798
|
-
*
|
|
799
|
-
*
|
|
800
|
-
* @param json
|
|
728
|
+
* 业务重改该方法可快速定制自己的 Path 表达式
|
|
729
|
+
* - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
|
|
730
|
+
* @param json 业务定义的 Path 表达式
|
|
731
|
+
* @returns
|
|
801
732
|
*/
|
|
802
|
-
|
|
733
|
+
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
734
|
+
fromJSON(json: CustomPathJSON): void;
|
|
735
|
+
getReturnTypeJSONByRef(_ref: BaseVariableField | undefined): ASTNodeJSON | undefined;
|
|
736
|
+
protected prevRefTypeHash: string | undefined;
|
|
737
|
+
constructor(params: CreateASTParams, opts: any);
|
|
738
|
+
toJSON(): ASTNodeJSON;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* 声明类 AST 节点
|
|
743
|
+
*/
|
|
744
|
+
type BaseVariableFieldJSON<VariableMeta = any> = {
|
|
745
|
+
key?: Identifier;
|
|
746
|
+
type?: ASTNodeJSONOrKind;
|
|
747
|
+
initializer?: ASTNodeJSON;
|
|
748
|
+
meta?: VariableMeta;
|
|
749
|
+
};
|
|
750
|
+
declare abstract class BaseVariableField<VariableMeta = any> extends ASTNode<BaseVariableFieldJSON<VariableMeta>> {
|
|
751
|
+
flags: ASTNodeFlags;
|
|
752
|
+
protected _type?: BaseType;
|
|
753
|
+
protected _meta: VariableMeta;
|
|
754
|
+
protected _initializer?: BaseExpression;
|
|
803
755
|
/**
|
|
804
|
-
*
|
|
805
|
-
* @param key
|
|
756
|
+
* 父变量字段,通过由近而远的方式进行排序
|
|
806
757
|
*/
|
|
807
|
-
|
|
758
|
+
get parentFields(): BaseVariableField[];
|
|
759
|
+
get meta(): VariableMeta;
|
|
760
|
+
get type(): BaseType;
|
|
761
|
+
get initializer(): BaseExpression | undefined;
|
|
808
762
|
/**
|
|
809
|
-
*
|
|
810
|
-
|
|
763
|
+
* 解析 VariableDeclarationJSON 从而生成变量声明节点
|
|
764
|
+
*/
|
|
765
|
+
fromJSON({ type, initializer, meta }: BaseVariableFieldJSON<VariableMeta>): void;
|
|
766
|
+
updateType(type: BaseVariableFieldJSON['type']): void;
|
|
767
|
+
updateInitializer(nextInitializer?: BaseVariableFieldJSON['initializer']): void;
|
|
768
|
+
updateMeta(nextMeta: VariableMeta): void;
|
|
769
|
+
/**
|
|
770
|
+
* 根据 keyPath 去找下钻的变量字段
|
|
771
|
+
* @param keyPath
|
|
811
772
|
* @returns
|
|
812
773
|
*/
|
|
813
|
-
|
|
774
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
775
|
+
/**
|
|
776
|
+
* 监听类型变化
|
|
777
|
+
* @param observer
|
|
778
|
+
* @returns
|
|
779
|
+
*/
|
|
780
|
+
onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
|
|
781
|
+
/**
|
|
782
|
+
* 转换为 JSON
|
|
783
|
+
* @returns
|
|
784
|
+
*/
|
|
785
|
+
toJSON(): BaseVariableFieldJSON<VariableMeta> & {
|
|
786
|
+
kind: string;
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* 声明类 AST 节点
|
|
792
|
+
*/
|
|
793
|
+
type VariableDeclarationJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
|
|
794
|
+
order?: number;
|
|
795
|
+
};
|
|
796
|
+
declare class VariableDeclaration<VariableMeta = any> extends BaseVariableField<VariableMeta> {
|
|
797
|
+
static kind: string;
|
|
798
|
+
protected _order: number;
|
|
799
|
+
get order(): number;
|
|
800
|
+
constructor(params: CreateASTParams);
|
|
801
|
+
/**
|
|
802
|
+
* 解析 VariableDeclarationJSON 从而生成变量声明节点
|
|
803
|
+
*/
|
|
804
|
+
fromJSON({ order, ...rest }: VariableDeclarationJSON<VariableMeta>): void;
|
|
805
|
+
updateOrder(order?: number): void;
|
|
806
|
+
onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
interface VariableDeclarationListJSON<VariableMeta = any> {
|
|
810
|
+
/**
|
|
811
|
+
* declarations 一定是 VariableDeclaration 类型,因此业务可以不用填 kind
|
|
812
|
+
*/
|
|
813
|
+
declarations?: VariableDeclarationJSON<VariableMeta>[];
|
|
814
|
+
startOrder?: number;
|
|
815
|
+
}
|
|
816
|
+
type VariableDeclarationListChangeAction = GlobalEventActionType<'VariableListChange', {
|
|
817
|
+
prev: VariableDeclaration[];
|
|
818
|
+
next: VariableDeclaration[];
|
|
819
|
+
}, VariableDeclarationList>;
|
|
820
|
+
declare class VariableDeclarationList extends ASTNode<VariableDeclarationListJSON> {
|
|
821
|
+
static kind: string;
|
|
822
|
+
declarationTable: Map<string, VariableDeclaration>;
|
|
823
|
+
declarations: VariableDeclaration[];
|
|
824
|
+
fromJSON({ declarations, startOrder }: VariableDeclarationListJSON): void;
|
|
825
|
+
toJSON(): ASTNodeJSON;
|
|
814
826
|
}
|
|
815
827
|
|
|
816
828
|
declare namespace ASTFactory {
|
|
@@ -943,62 +955,23 @@ declare function isMatchAST<TargetASTNode extends ASTNode>(node?: ASTNode, targe
|
|
|
943
955
|
new (...args: any[]): TargetASTNode;
|
|
944
956
|
}): node is TargetASTNode;
|
|
945
957
|
|
|
946
|
-
declare class Scope<ScopeMeta extends Record<string, any> = Record<string, any>> {
|
|
947
|
-
/**
|
|
948
|
-
* Scope 唯一索引
|
|
949
|
-
*/
|
|
950
|
-
readonly id: string;
|
|
951
|
-
/**
|
|
952
|
-
* Scope 依赖变量引擎
|
|
953
|
-
*/
|
|
954
|
-
readonly variableEngine: VariableEngine;
|
|
955
|
-
/**
|
|
956
|
-
* 作用域的基本元信息,包括作用域所在节点及一些 flag 信息,上层业务可以额外扩展
|
|
957
|
-
*/
|
|
958
|
-
readonly meta: ScopeMeta;
|
|
959
|
-
/**
|
|
960
|
-
* 作用域 AST 根节点
|
|
961
|
-
* - Map<formItemKey, formItemValue>
|
|
962
|
-
*/
|
|
963
|
-
readonly ast: MapNode;
|
|
964
|
-
/**
|
|
965
|
-
* 可用变量数据管理
|
|
966
|
-
*/
|
|
967
|
-
readonly available: ScopeAvailableData;
|
|
968
|
-
/**
|
|
969
|
-
* 输出变量数据管理
|
|
970
|
-
*/
|
|
971
|
-
readonly output: ScopeOutputData;
|
|
972
|
-
/**
|
|
973
|
-
* 作用域事件管理
|
|
974
|
-
*/
|
|
975
|
-
readonly event: ScopeEventData;
|
|
976
|
-
/**
|
|
977
|
-
* 数据缓存
|
|
978
|
-
*/
|
|
979
|
-
protected memo: {
|
|
980
|
-
<T>(key: string | symbol, fn: () => T): T;
|
|
981
|
-
clear: (key?: (string | symbol) | undefined) => void;
|
|
982
|
-
};
|
|
983
|
-
toDispose: DisposableCollection;
|
|
984
|
-
constructor(options: {
|
|
985
|
-
id: string;
|
|
986
|
-
variableEngine: VariableEngine;
|
|
987
|
-
meta?: ScopeMeta;
|
|
988
|
-
});
|
|
989
|
-
refreshCovers(): void;
|
|
990
|
-
refreshDeps(): void;
|
|
991
|
-
get depScopes(): Scope[];
|
|
992
|
-
get coverScopes(): Scope[];
|
|
993
|
-
dispose(): void;
|
|
994
|
-
onDispose: _flowgram_ai_utils.Event<void>;
|
|
995
|
-
get disposed(): boolean;
|
|
996
|
-
}
|
|
997
|
-
|
|
998
958
|
interface ScopeChangeAction {
|
|
999
959
|
type: 'add' | 'delete' | 'update' | 'available';
|
|
1000
960
|
scope: Scope;
|
|
1001
961
|
}
|
|
962
|
+
interface IVariableTable extends Disposable {
|
|
963
|
+
parentTable?: IVariableTable;
|
|
964
|
+
onDataChange: Event<void>;
|
|
965
|
+
version: number;
|
|
966
|
+
variables: VariableDeclaration[];
|
|
967
|
+
variableKeys: string[];
|
|
968
|
+
fireChange(): void;
|
|
969
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
970
|
+
getVariableByKey(key: string): VariableDeclaration | undefined;
|
|
971
|
+
dispose(): void;
|
|
972
|
+
onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
|
|
973
|
+
onAnyChange(observer: () => void): Disposable;
|
|
974
|
+
}
|
|
1002
975
|
|
|
1003
976
|
declare class VariableEngine implements Disposable {
|
|
1004
977
|
readonly chain: ScopeChain;
|
|
@@ -1008,19 +981,28 @@ declare class VariableEngine implements Disposable {
|
|
|
1008
981
|
<T>(key: string | symbol, fn: () => T): T;
|
|
1009
982
|
clear: (key?: (string | symbol) | undefined) => void;
|
|
1010
983
|
};
|
|
1011
|
-
protected scopeMap: Map<string, Scope<Record<string, any>>>;
|
|
984
|
+
protected scopeMap: Map<string | symbol, Scope<Record<string, any>>>;
|
|
1012
985
|
globalEvent$: Subject<GlobalEventActionType>;
|
|
1013
986
|
protected onScopeChangeEmitter: Emitter<ScopeChangeAction>;
|
|
1014
|
-
globalVariableTable:
|
|
987
|
+
globalVariableTable: IVariableTable;
|
|
1015
988
|
onScopeChange: _flowgram_ai_utils.Event<ScopeChangeAction>;
|
|
1016
989
|
private readonly containerProvider;
|
|
1017
990
|
get container(): interfaces.Container;
|
|
1018
991
|
constructor(chain: ScopeChain, // 作用域依赖关系偏序集
|
|
1019
992
|
astRegisters: ASTRegisters);
|
|
1020
993
|
dispose(): void;
|
|
1021
|
-
getScopeById(scopeId: string): Scope | undefined;
|
|
1022
|
-
removeScopeById(scopeId: string): void;
|
|
1023
|
-
|
|
994
|
+
getScopeById(scopeId: string | symbol): Scope | undefined;
|
|
995
|
+
removeScopeById(scopeId: string | symbol): void;
|
|
996
|
+
/**
|
|
997
|
+
* Get Scope, if Scope exists and type is same, will use it directly
|
|
998
|
+
* @param id scope id
|
|
999
|
+
* @param meta scope meta, defined by user
|
|
1000
|
+
* @param ScopeConstructor scope constructor, default is Scope. you can extends Scope to create your own scope
|
|
1001
|
+
* @returns
|
|
1002
|
+
*/
|
|
1003
|
+
createScope(id: string | symbol, meta?: Record<string, any>, options?: {
|
|
1004
|
+
ScopeConstructor?: IScopeConstructor;
|
|
1005
|
+
}): Scope;
|
|
1024
1006
|
getAllScopes({ sort, }?: {
|
|
1025
1007
|
sort?: boolean;
|
|
1026
1008
|
}): Scope[];
|
|
@@ -1062,4 +1044,4 @@ declare class VariableFieldKeyRenameService {
|
|
|
1062
1044
|
dispose(): void;
|
|
1063
1045
|
}
|
|
1064
1046
|
|
|
1065
|
-
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, ExpressionList, type ExpressionListJSON, type GetKindJSON, type GetKindJSONOrKind, type GlobalEventActionType, IntegerType, KeyPathExpression, type KeyPathExpressionJSON$1 as KeyPathExpressionJSON, KeyPathExpressionV2, 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,
|
|
1047
|
+
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, ExpressionList, type ExpressionListJSON, type GetKindJSON, type GetKindJSONOrKind, type GlobalEventActionType, type IVariableTable, IntegerType, KeyPathExpression, type KeyPathExpressionJSON$1 as KeyPathExpressionJSON, KeyPathExpressionV2, 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, injectToAST, isMatchAST, postConstructAST, useAvailableVariables, useCurrentScope, useScopeAvailable, useScopeContext };
|