@flowgram.ai/variable-core 0.1.0-alpha.6 → 0.1.0-alpha.8
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 +315 -241
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +546 -547
- package/dist/index.d.ts +546 -547
- package/dist/index.js +349 -276
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
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,74 +324,203 @@ 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
|
+
WrapArrayExpression = "WrapArrayExpression",
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
+
* 类型是否一致
|
|
501
|
+
* @param targetTypeJSON
|
|
502
|
+
*/
|
|
503
|
+
isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
|
|
504
|
+
/**
|
|
505
|
+
* 可下钻类型需实现
|
|
506
|
+
* @param keyPath
|
|
507
|
+
*/
|
|
508
|
+
getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
|
|
509
|
+
/**
|
|
510
|
+
* Get AST JSON for current base type
|
|
511
|
+
* @returns
|
|
512
|
+
*/
|
|
513
|
+
toJSON(): ASTNodeJSON;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
declare class StringType extends BaseType {
|
|
517
|
+
flags: ASTNodeFlags;
|
|
518
|
+
static kind: string;
|
|
519
|
+
fromJSON(): void;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
declare class IntegerType extends BaseType {
|
|
523
|
+
flags: ASTNodeFlags;
|
|
257
524
|
static kind: string;
|
|
258
525
|
fromJSON(): void;
|
|
259
526
|
}
|
|
@@ -307,6 +574,13 @@ declare class MapType extends BaseType<MapJSON> {
|
|
|
307
574
|
toJSON(): ASTNodeJSON;
|
|
308
575
|
}
|
|
309
576
|
|
|
577
|
+
type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
|
|
578
|
+
key: string;
|
|
579
|
+
};
|
|
580
|
+
declare class Property<VariableMeta = any> extends BaseVariableField<VariableMeta> {
|
|
581
|
+
static kind: string;
|
|
582
|
+
}
|
|
583
|
+
|
|
310
584
|
interface ObjectJSON<VariableMeta = any> {
|
|
311
585
|
/**
|
|
312
586
|
* Object 的 properties 一定是 Property 类型,因此业务可以不用填 kind
|
|
@@ -360,7 +634,7 @@ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts
|
|
|
360
634
|
/**
|
|
361
635
|
* 获取全局变量表,方便表达式获取引用变量
|
|
362
636
|
*/
|
|
363
|
-
get globalVariableTable():
|
|
637
|
+
get globalVariableTable(): IVariableTable;
|
|
364
638
|
/**
|
|
365
639
|
* 父变量字段,通过由近而远的方式进行排序
|
|
366
640
|
*/
|
|
@@ -371,446 +645,197 @@ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts
|
|
|
371
645
|
*/
|
|
372
646
|
abstract getRefFields(): ExpressionRefs;
|
|
373
647
|
/**
|
|
374
|
-
* 表达式返回的数据类型
|
|
375
|
-
*/
|
|
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>;
|
|
648
|
+
* 表达式返回的数据类型
|
|
649
|
+
*/
|
|
650
|
+
abstract returnType: BaseType | undefined;
|
|
740
651
|
/**
|
|
741
|
-
*
|
|
652
|
+
* 引用变量
|
|
742
653
|
*/
|
|
743
|
-
|
|
654
|
+
protected _refs: ExpressionRefs;
|
|
655
|
+
get refs(): ExpressionRefs;
|
|
656
|
+
protected refreshRefs$: Subject<void>;
|
|
744
657
|
/**
|
|
745
|
-
*
|
|
746
|
-
* @param param 创建参数
|
|
747
|
-
* @returns
|
|
658
|
+
* 刷新变量引用
|
|
748
659
|
*/
|
|
749
|
-
|
|
660
|
+
refreshRefs(): void;
|
|
750
661
|
/**
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
* @returns
|
|
662
|
+
* 监听引用变量变化
|
|
663
|
+
* 监听 [a.b.c] -> [a.b]
|
|
754
664
|
*/
|
|
755
|
-
|
|
665
|
+
refs$: Observable<ExpressionRefs>;
|
|
666
|
+
constructor(params: CreateASTParams, opts?: InjectOpts);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
interface KeyPathExpressionJSON$1 {
|
|
670
|
+
keyPath: string[];
|
|
671
|
+
}
|
|
672
|
+
declare class KeyPathExpression<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON$1> extends BaseExpression<CustomPathJSON> {
|
|
673
|
+
static kind: string;
|
|
674
|
+
protected _keyPath: string[];
|
|
675
|
+
get keyPath(): string[];
|
|
676
|
+
getRefFields(): BaseVariableField[];
|
|
677
|
+
get returnType(): BaseType | undefined;
|
|
756
678
|
/**
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
* @param
|
|
679
|
+
* 业务重改该方法可快速定制自己的 Path 表达式
|
|
680
|
+
* - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
|
|
681
|
+
* @param json 业务定义的 Path 表达式
|
|
682
|
+
* @returns
|
|
760
683
|
*/
|
|
761
|
-
|
|
684
|
+
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
685
|
+
fromJSON(json: CustomPathJSON): void;
|
|
686
|
+
constructor(params: CreateASTParams, opts: any);
|
|
687
|
+
toJSON(): ASTNodeJSON;
|
|
762
688
|
}
|
|
763
689
|
|
|
690
|
+
interface EnumerateExpressionJSON {
|
|
691
|
+
enumerateFor: ASTNodeJSON;
|
|
692
|
+
}
|
|
764
693
|
/**
|
|
765
|
-
*
|
|
694
|
+
* 遍历表达式,对列表进行遍历,获取遍历后的变量类型
|
|
766
695
|
*/
|
|
767
|
-
declare class
|
|
696
|
+
declare class EnumerateExpression extends BaseExpression<EnumerateExpressionJSON> {
|
|
768
697
|
static kind: string;
|
|
769
|
-
protected
|
|
770
|
-
get
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
partialUpdate(nextData: Data): void;
|
|
698
|
+
protected _enumerateFor: BaseExpression | undefined;
|
|
699
|
+
get enumerateFor(): BaseExpression<any, any> | undefined;
|
|
700
|
+
get returnType(): BaseType | undefined;
|
|
701
|
+
getRefFields(): [];
|
|
702
|
+
fromJSON({ enumerateFor: expression }: EnumerateExpressionJSON): void;
|
|
703
|
+
toJSON(): ASTNodeJSON;
|
|
776
704
|
}
|
|
777
705
|
|
|
778
|
-
interface
|
|
779
|
-
|
|
706
|
+
interface KeyPathExpressionJSON {
|
|
707
|
+
keyPath: string[];
|
|
780
708
|
}
|
|
781
|
-
|
|
709
|
+
/**
|
|
710
|
+
* 新版 KeyPathExpressionV2,相比旧版:
|
|
711
|
+
* - returnType 拷贝新一份,避免引用问题
|
|
712
|
+
* - 引入成环检测
|
|
713
|
+
*/
|
|
714
|
+
declare class KeyPathExpressionV2<CustomPathJSON extends ASTNodeJSON = KeyPathExpressionJSON> extends BaseExpression<CustomPathJSON> {
|
|
782
715
|
static kind: string;
|
|
783
|
-
protected
|
|
784
|
-
get
|
|
785
|
-
|
|
716
|
+
protected _keyPath: string[];
|
|
717
|
+
get keyPath(): string[];
|
|
718
|
+
getRefFields(): BaseVariableField[];
|
|
719
|
+
_returnType: BaseType;
|
|
720
|
+
get returnType(): BaseType<any, any>;
|
|
721
|
+
/**
|
|
722
|
+
* 业务重改该方法可快速定制自己的 Path 表达式
|
|
723
|
+
* - 只需要将业务的 Path 解析为变量系统的 KeyPath 即可
|
|
724
|
+
* @param json 业务定义的 Path 表达式
|
|
725
|
+
* @returns
|
|
726
|
+
*/
|
|
727
|
+
protected parseToKeyPath(json: CustomPathJSON): string[];
|
|
728
|
+
fromJSON(json: CustomPathJSON): void;
|
|
729
|
+
getReturnTypeJSONByRef(_ref: BaseVariableField | undefined): ASTNodeJSON | undefined;
|
|
730
|
+
protected prevRefTypeHash: string | undefined;
|
|
731
|
+
constructor(params: CreateASTParams, opts: any);
|
|
786
732
|
toJSON(): ASTNodeJSON;
|
|
787
733
|
}
|
|
788
734
|
|
|
789
|
-
interface
|
|
790
|
-
|
|
735
|
+
interface WrapArrayExpressionJSON {
|
|
736
|
+
wrapFor: ASTNodeJSON;
|
|
791
737
|
}
|
|
792
|
-
|
|
738
|
+
/**
|
|
739
|
+
* 遍历表达式,对列表进行遍历,获取遍历后的变量类型
|
|
740
|
+
*/
|
|
741
|
+
declare class WrapArrayExpression extends BaseExpression<WrapArrayExpressionJSON> {
|
|
793
742
|
static kind: string;
|
|
794
|
-
protected
|
|
795
|
-
|
|
743
|
+
protected _wrapFor: BaseExpression | undefined;
|
|
744
|
+
protected _returnType: BaseType | undefined;
|
|
745
|
+
get wrapFor(): BaseExpression<any, any> | undefined;
|
|
746
|
+
get returnType(): BaseType | undefined;
|
|
747
|
+
refreshReturnType(): void;
|
|
748
|
+
getRefFields(): [];
|
|
749
|
+
fromJSON({ wrapFor: expression }: WrapArrayExpressionJSON): void;
|
|
796
750
|
toJSON(): ASTNodeJSON;
|
|
751
|
+
protected init(): void;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* 声明类 AST 节点
|
|
756
|
+
*/
|
|
757
|
+
type BaseVariableFieldJSON<VariableMeta = any> = {
|
|
758
|
+
key?: Identifier;
|
|
759
|
+
type?: ASTNodeJSONOrKind;
|
|
760
|
+
initializer?: ASTNodeJSON;
|
|
761
|
+
meta?: VariableMeta;
|
|
762
|
+
};
|
|
763
|
+
declare abstract class BaseVariableField<VariableMeta = any> extends ASTNode<BaseVariableFieldJSON<VariableMeta>> {
|
|
764
|
+
flags: ASTNodeFlags;
|
|
765
|
+
protected _type?: BaseType;
|
|
766
|
+
protected _meta: VariableMeta;
|
|
767
|
+
protected _initializer?: BaseExpression;
|
|
797
768
|
/**
|
|
798
|
-
*
|
|
799
|
-
* @param key ASTNode 的索引,
|
|
800
|
-
* @param json
|
|
769
|
+
* 父变量字段,通过由近而远的方式进行排序
|
|
801
770
|
*/
|
|
802
|
-
|
|
771
|
+
get parentFields(): BaseVariableField[];
|
|
772
|
+
get meta(): VariableMeta;
|
|
773
|
+
get type(): BaseType;
|
|
774
|
+
get initializer(): BaseExpression | undefined;
|
|
803
775
|
/**
|
|
804
|
-
*
|
|
805
|
-
* @param key
|
|
776
|
+
* 解析 VariableDeclarationJSON 从而生成变量声明节点
|
|
806
777
|
*/
|
|
807
|
-
|
|
778
|
+
fromJSON({ type, initializer, meta }: BaseVariableFieldJSON<VariableMeta>): void;
|
|
779
|
+
updateType(type: BaseVariableFieldJSON['type']): void;
|
|
780
|
+
updateInitializer(nextInitializer?: BaseVariableFieldJSON['initializer']): void;
|
|
781
|
+
updateMeta(nextMeta: VariableMeta): void;
|
|
808
782
|
/**
|
|
809
|
-
*
|
|
810
|
-
* @param
|
|
783
|
+
* 根据 keyPath 去找下钻的变量字段
|
|
784
|
+
* @param keyPath
|
|
811
785
|
* @returns
|
|
812
786
|
*/
|
|
813
|
-
|
|
787
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
788
|
+
/**
|
|
789
|
+
* 监听类型变化
|
|
790
|
+
* @param observer
|
|
791
|
+
* @returns
|
|
792
|
+
*/
|
|
793
|
+
onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
|
|
794
|
+
/**
|
|
795
|
+
* 转换为 JSON
|
|
796
|
+
* @returns
|
|
797
|
+
*/
|
|
798
|
+
toJSON(): BaseVariableFieldJSON<VariableMeta> & {
|
|
799
|
+
kind: string;
|
|
800
|
+
};
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* 声明类 AST 节点
|
|
805
|
+
*/
|
|
806
|
+
type VariableDeclarationJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
|
|
807
|
+
order?: number;
|
|
808
|
+
};
|
|
809
|
+
declare class VariableDeclaration<VariableMeta = any> extends BaseVariableField<VariableMeta> {
|
|
810
|
+
static kind: string;
|
|
811
|
+
protected _order: number;
|
|
812
|
+
get order(): number;
|
|
813
|
+
constructor(params: CreateASTParams);
|
|
814
|
+
/**
|
|
815
|
+
* 解析 VariableDeclarationJSON 从而生成变量声明节点
|
|
816
|
+
*/
|
|
817
|
+
fromJSON({ order, ...rest }: VariableDeclarationJSON<VariableMeta>): void;
|
|
818
|
+
updateOrder(order?: number): void;
|
|
819
|
+
onTypeChange(observer: (type: ASTNode | undefined) => void): _flowgram_ai_utils.Disposable;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
interface VariableDeclarationListJSON<VariableMeta = any> {
|
|
823
|
+
/**
|
|
824
|
+
* declarations 一定是 VariableDeclaration 类型,因此业务可以不用填 kind
|
|
825
|
+
*/
|
|
826
|
+
declarations?: VariableDeclarationJSON<VariableMeta>[];
|
|
827
|
+
startOrder?: number;
|
|
828
|
+
}
|
|
829
|
+
type VariableDeclarationListChangeAction = GlobalEventActionType<'VariableListChange', {
|
|
830
|
+
prev: VariableDeclaration[];
|
|
831
|
+
next: VariableDeclaration[];
|
|
832
|
+
}, VariableDeclarationList>;
|
|
833
|
+
declare class VariableDeclarationList extends ASTNode<VariableDeclarationListJSON> {
|
|
834
|
+
static kind: string;
|
|
835
|
+
declarationTable: Map<string, VariableDeclaration>;
|
|
836
|
+
declarations: VariableDeclaration[];
|
|
837
|
+
fromJSON({ declarations, startOrder }: VariableDeclarationListJSON): void;
|
|
838
|
+
toJSON(): ASTNodeJSON;
|
|
814
839
|
}
|
|
815
840
|
|
|
816
841
|
declare namespace ASTFactory {
|
|
@@ -885,6 +910,10 @@ declare namespace ASTFactory {
|
|
|
885
910
|
keyPath: string[];
|
|
886
911
|
kind: ASTKind;
|
|
887
912
|
};
|
|
913
|
+
const createWrapArrayExpression: (json: WrapArrayExpressionJSON) => {
|
|
914
|
+
wrapFor: ASTNodeJSON;
|
|
915
|
+
kind: ASTKind;
|
|
916
|
+
};
|
|
888
917
|
/**
|
|
889
918
|
* 通过 AST Class 创建
|
|
890
919
|
*/
|
|
@@ -943,62 +972,23 @@ declare function isMatchAST<TargetASTNode extends ASTNode>(node?: ASTNode, targe
|
|
|
943
972
|
new (...args: any[]): TargetASTNode;
|
|
944
973
|
}): node is TargetASTNode;
|
|
945
974
|
|
|
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
975
|
interface ScopeChangeAction {
|
|
999
976
|
type: 'add' | 'delete' | 'update' | 'available';
|
|
1000
977
|
scope: Scope;
|
|
1001
978
|
}
|
|
979
|
+
interface IVariableTable extends Disposable {
|
|
980
|
+
parentTable?: IVariableTable;
|
|
981
|
+
onDataChange: Event<void>;
|
|
982
|
+
version: number;
|
|
983
|
+
variables: VariableDeclaration[];
|
|
984
|
+
variableKeys: string[];
|
|
985
|
+
fireChange(): void;
|
|
986
|
+
getByKeyPath(keyPath: string[]): BaseVariableField | undefined;
|
|
987
|
+
getVariableByKey(key: string): VariableDeclaration | undefined;
|
|
988
|
+
dispose(): void;
|
|
989
|
+
onAnyVariableChange(observer: (changedVariable: VariableDeclaration) => void): Disposable;
|
|
990
|
+
onAnyChange(observer: () => void): Disposable;
|
|
991
|
+
}
|
|
1002
992
|
|
|
1003
993
|
declare class VariableEngine implements Disposable {
|
|
1004
994
|
readonly chain: ScopeChain;
|
|
@@ -1008,19 +998,28 @@ declare class VariableEngine implements Disposable {
|
|
|
1008
998
|
<T>(key: string | symbol, fn: () => T): T;
|
|
1009
999
|
clear: (key?: (string | symbol) | undefined) => void;
|
|
1010
1000
|
};
|
|
1011
|
-
protected scopeMap: Map<string, Scope<Record<string, any>>>;
|
|
1001
|
+
protected scopeMap: Map<string | symbol, Scope<Record<string, any>>>;
|
|
1012
1002
|
globalEvent$: Subject<GlobalEventActionType>;
|
|
1013
1003
|
protected onScopeChangeEmitter: Emitter<ScopeChangeAction>;
|
|
1014
|
-
globalVariableTable:
|
|
1004
|
+
globalVariableTable: IVariableTable;
|
|
1015
1005
|
onScopeChange: _flowgram_ai_utils.Event<ScopeChangeAction>;
|
|
1016
1006
|
private readonly containerProvider;
|
|
1017
1007
|
get container(): interfaces.Container;
|
|
1018
1008
|
constructor(chain: ScopeChain, // 作用域依赖关系偏序集
|
|
1019
1009
|
astRegisters: ASTRegisters);
|
|
1020
1010
|
dispose(): void;
|
|
1021
|
-
getScopeById(scopeId: string): Scope | undefined;
|
|
1022
|
-
removeScopeById(scopeId: string): void;
|
|
1023
|
-
|
|
1011
|
+
getScopeById(scopeId: string | symbol): Scope | undefined;
|
|
1012
|
+
removeScopeById(scopeId: string | symbol): void;
|
|
1013
|
+
/**
|
|
1014
|
+
* Get Scope, if Scope exists and type is same, will use it directly
|
|
1015
|
+
* @param id scope id
|
|
1016
|
+
* @param meta scope meta, defined by user
|
|
1017
|
+
* @param ScopeConstructor scope constructor, default is Scope. you can extends Scope to create your own scope
|
|
1018
|
+
* @returns
|
|
1019
|
+
*/
|
|
1020
|
+
createScope(id: string | symbol, meta?: Record<string, any>, options?: {
|
|
1021
|
+
ScopeConstructor?: IScopeConstructor;
|
|
1022
|
+
}): Scope;
|
|
1024
1023
|
getAllScopes({ sort, }?: {
|
|
1025
1024
|
sort?: boolean;
|
|
1026
1025
|
}): Scope[];
|
|
@@ -1062,4 +1061,4 @@ declare class VariableFieldKeyRenameService {
|
|
|
1062
1061
|
dispose(): void;
|
|
1063
1062
|
}
|
|
1064
1063
|
|
|
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,
|
|
1064
|
+
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, 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, WrapArrayExpression, type WrapArrayExpressionJSON, injectToAST, isMatchAST, postConstructAST, useAvailableVariables, useCurrentScope, useScopeAvailable, useScopeContext };
|