@flowgram.ai/variable-core 0.1.31 → 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.
package/dist/index.d.mts CHANGED
@@ -360,7 +360,7 @@ declare enum ASTKind {
360
360
  */
361
361
  KeyPathExpression = "KeyPathExpression",
362
362
  EnumerateExpression = "EnumerateExpression",
363
- ExpressionList = "ExpressionList",
363
+ WrapArrayExpression = "WrapArrayExpression",
364
364
  /**
365
365
  * 通用 AST 节点
366
366
  */
@@ -494,10 +494,33 @@ declare class MapNode extends ASTNode<MapNodeJSON> {
494
494
  get(key: string): ASTNode | undefined;
495
495
  }
496
496
 
497
+ declare namespace VarJSONSchema {
498
+ type BasicType = 'boolean' | 'string' | 'integer' | 'number' | 'object' | 'array' | 'map';
499
+ interface ISchema<T = string> {
500
+ type?: T;
501
+ default?: any;
502
+ title?: string;
503
+ description?: string;
504
+ enum?: (string | number)[];
505
+ properties?: Record<string, ISchema<T>>;
506
+ additionalProperties?: ISchema<T>;
507
+ items?: ISchema<T>;
508
+ required?: string[];
509
+ $ref?: string;
510
+ extra?: {
511
+ index?: number;
512
+ weak?: boolean;
513
+ formComponent?: string;
514
+ [key: string]: any;
515
+ };
516
+ }
517
+ type IBasicSchema = ISchema<BasicType>;
518
+ }
519
+
497
520
  declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
498
521
  flags: number;
499
522
  /**
500
- * 类型是否一致,节点有额外信息判断,请参考 extraTypeInfoEqual
523
+ * 类型是否一致
501
524
  * @param targetTypeJSON
502
525
  */
503
526
  isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
@@ -506,29 +529,46 @@ declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any
506
529
  * @param keyPath
507
530
  */
508
531
  getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
532
+ /**
533
+ * Get AST JSON for current base type
534
+ * @returns
535
+ */
509
536
  toJSON(): ASTNodeJSON;
537
+ /**
538
+ * Get Standard JSON Schema for current base type
539
+ * @returns
540
+ */
541
+ toJSONSchema(): VarJSONSchema.ISchema;
542
+ /**
543
+ * Check if the type is equal with json schema
544
+ */
545
+ isEqualWithJSONSchema(schema: VarJSONSchema.ISchema | VarJSONSchema.ISchema[]): boolean;
510
546
  }
511
547
 
512
548
  declare class StringType extends BaseType {
513
549
  flags: ASTNodeFlags;
514
550
  static kind: string;
515
551
  fromJSON(): void;
552
+ toJSONSchema(): VarJSONSchema.ISchema;
516
553
  }
517
554
 
518
555
  declare class IntegerType extends BaseType {
519
556
  flags: ASTNodeFlags;
520
557
  static kind: string;
521
558
  fromJSON(): void;
559
+ toJSONSchema(): VarJSONSchema.ISchema;
522
560
  }
523
561
 
524
562
  declare class BooleanType extends BaseType {
525
563
  static kind: string;
526
564
  fromJSON(): void;
565
+ toJSONSchema(): VarJSONSchema.ISchema;
527
566
  }
528
567
 
529
568
  declare class NumberType extends BaseType {
530
569
  static kind: string;
531
570
  fromJSON(): void;
571
+ toJSONSchema(): VarJSONSchema.ISchema;
532
572
  }
533
573
 
534
574
  interface ArrayJSON {
@@ -568,6 +608,7 @@ declare class MapType extends BaseType<MapJSON> {
568
608
  */
569
609
  protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
570
610
  toJSON(): ASTNodeJSON;
611
+ toJSONSchema(): VarJSONSchema.ISchema;
571
612
  }
572
613
 
573
614
  type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
@@ -607,6 +648,7 @@ declare class ObjectType extends BaseType<ObjectJSON> {
607
648
  * @returns
608
649
  */
609
650
  protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
651
+ toJSONSchema(): VarJSONSchema.ISchema;
610
652
  }
611
653
 
612
654
  interface UnionJSON {
@@ -622,6 +664,7 @@ declare class CustomType extends BaseType<CustomTypeJSON> {
622
664
  get typeName(): string;
623
665
  fromJSON(json: CustomTypeJSON): void;
624
666
  isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
667
+ toJSONSchema(): VarJSONSchema.ISchema;
625
668
  }
626
669
 
627
670
  type ExpressionRefs = (BaseVariableField | undefined)[];
@@ -662,16 +705,6 @@ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts
662
705
  constructor(params: CreateASTParams, opts?: InjectOpts);
663
706
  }
664
707
 
665
- interface ExpressionListJSON {
666
- expressions: ASTNodeJSON[];
667
- }
668
- declare class ExpressionList extends ASTNode<ExpressionListJSON> {
669
- static kind: string;
670
- expressions: ASTNode[];
671
- fromJSON({ expressions }: ExpressionListJSON): void;
672
- toJSON(): ASTNodeJSON;
673
- }
674
-
675
708
  interface KeyPathExpressionJSON$1 {
676
709
  keyPath: string[];
677
710
  }
@@ -738,6 +771,25 @@ declare class KeyPathExpressionV2<CustomPathJSON extends ASTNodeJSON = KeyPathEx
738
771
  toJSON(): ASTNodeJSON;
739
772
  }
740
773
 
774
+ interface WrapArrayExpressionJSON {
775
+ wrapFor: ASTNodeJSON;
776
+ }
777
+ /**
778
+ * 遍历表达式,对列表进行遍历,获取遍历后的变量类型
779
+ */
780
+ declare class WrapArrayExpression extends BaseExpression<WrapArrayExpressionJSON> {
781
+ static kind: string;
782
+ protected _wrapFor: BaseExpression | undefined;
783
+ protected _returnType: BaseType | undefined;
784
+ get wrapFor(): BaseExpression<any, any> | undefined;
785
+ get returnType(): BaseType | undefined;
786
+ refreshReturnType(): void;
787
+ getRefFields(): [];
788
+ fromJSON({ wrapFor: expression }: WrapArrayExpressionJSON): void;
789
+ toJSON(): ASTNodeJSON;
790
+ protected init(): void;
791
+ }
792
+
741
793
  /**
742
794
  * 声明类 AST 节点
743
795
  */
@@ -897,6 +949,22 @@ declare namespace ASTFactory {
897
949
  keyPath: string[];
898
950
  kind: ASTKind;
899
951
  };
952
+ const createWrapArrayExpression: (json: WrapArrayExpressionJSON) => {
953
+ wrapFor: ASTNodeJSON;
954
+ kind: ASTKind;
955
+ };
956
+ /**
957
+ * Converts a JSON schema to an Abstract Syntax Tree (AST) representation.
958
+ * This function recursively processes the JSON schema and creates corresponding AST nodes.
959
+ *
960
+ * For more information on JSON Schema, refer to the official documentation:
961
+ * https://json-schema.org/
962
+ *
963
+ *
964
+ * @param jsonSchema - The JSON schema to convert.
965
+ * @returns An AST node representing the JSON schema, or undefined if the schema type is not recognized.
966
+ */
967
+ function createTypeASTFromSchema(jsonSchema: VarJSONSchema.ISchema): ASTNodeJSON | undefined;
900
968
  /**
901
969
  * 通过 AST Class 创建
902
970
  */
@@ -1044,4 +1112,4 @@ declare class VariableFieldKeyRenameService {
1044
1112
  dispose(): void;
1045
1113
  }
1046
1114
 
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 };
1115
+ 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, VarJSONSchema, VariableContainerModule, VariableDeclaration, type VariableDeclarationJSON, VariableDeclarationList, type VariableDeclarationListChangeAction, type VariableDeclarationListJSON, VariableEngine, VariableEngineProvider, VariableFieldKeyRenameService, WrapArrayExpression, type WrapArrayExpressionJSON, injectToAST, isMatchAST, postConstructAST, useAvailableVariables, useCurrentScope, useScopeAvailable, useScopeContext };
package/dist/index.d.ts CHANGED
@@ -360,7 +360,7 @@ declare enum ASTKind {
360
360
  */
361
361
  KeyPathExpression = "KeyPathExpression",
362
362
  EnumerateExpression = "EnumerateExpression",
363
- ExpressionList = "ExpressionList",
363
+ WrapArrayExpression = "WrapArrayExpression",
364
364
  /**
365
365
  * 通用 AST 节点
366
366
  */
@@ -494,10 +494,33 @@ declare class MapNode extends ASTNode<MapNodeJSON> {
494
494
  get(key: string): ASTNode | undefined;
495
495
  }
496
496
 
497
+ declare namespace VarJSONSchema {
498
+ type BasicType = 'boolean' | 'string' | 'integer' | 'number' | 'object' | 'array' | 'map';
499
+ interface ISchema<T = string> {
500
+ type?: T;
501
+ default?: any;
502
+ title?: string;
503
+ description?: string;
504
+ enum?: (string | number)[];
505
+ properties?: Record<string, ISchema<T>>;
506
+ additionalProperties?: ISchema<T>;
507
+ items?: ISchema<T>;
508
+ required?: string[];
509
+ $ref?: string;
510
+ extra?: {
511
+ index?: number;
512
+ weak?: boolean;
513
+ formComponent?: string;
514
+ [key: string]: any;
515
+ };
516
+ }
517
+ type IBasicSchema = ISchema<BasicType>;
518
+ }
519
+
497
520
  declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any> extends ASTNode<JSON, InjectOpts> {
498
521
  flags: number;
499
522
  /**
500
- * 类型是否一致,节点有额外信息判断,请参考 extraTypeInfoEqual
523
+ * 类型是否一致
501
524
  * @param targetTypeJSON
502
525
  */
503
526
  isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
@@ -506,29 +529,46 @@ declare abstract class BaseType<JSON extends ASTNodeJSON = any, InjectOpts = any
506
529
  * @param keyPath
507
530
  */
508
531
  getByKeyPath(keyPath?: string[]): BaseVariableField | undefined;
532
+ /**
533
+ * Get AST JSON for current base type
534
+ * @returns
535
+ */
509
536
  toJSON(): ASTNodeJSON;
537
+ /**
538
+ * Get Standard JSON Schema for current base type
539
+ * @returns
540
+ */
541
+ toJSONSchema(): VarJSONSchema.ISchema;
542
+ /**
543
+ * Check if the type is equal with json schema
544
+ */
545
+ isEqualWithJSONSchema(schema: VarJSONSchema.ISchema | VarJSONSchema.ISchema[]): boolean;
510
546
  }
511
547
 
512
548
  declare class StringType extends BaseType {
513
549
  flags: ASTNodeFlags;
514
550
  static kind: string;
515
551
  fromJSON(): void;
552
+ toJSONSchema(): VarJSONSchema.ISchema;
516
553
  }
517
554
 
518
555
  declare class IntegerType extends BaseType {
519
556
  flags: ASTNodeFlags;
520
557
  static kind: string;
521
558
  fromJSON(): void;
559
+ toJSONSchema(): VarJSONSchema.ISchema;
522
560
  }
523
561
 
524
562
  declare class BooleanType extends BaseType {
525
563
  static kind: string;
526
564
  fromJSON(): void;
565
+ toJSONSchema(): VarJSONSchema.ISchema;
527
566
  }
528
567
 
529
568
  declare class NumberType extends BaseType {
530
569
  static kind: string;
531
570
  fromJSON(): void;
571
+ toJSONSchema(): VarJSONSchema.ISchema;
532
572
  }
533
573
 
534
574
  interface ArrayJSON {
@@ -568,6 +608,7 @@ declare class MapType extends BaseType<MapJSON> {
568
608
  */
569
609
  protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
570
610
  toJSON(): ASTNodeJSON;
611
+ toJSONSchema(): VarJSONSchema.ISchema;
571
612
  }
572
613
 
573
614
  type PropertyJSON<VariableMeta = any> = BaseVariableFieldJSON<VariableMeta> & {
@@ -607,6 +648,7 @@ declare class ObjectType extends BaseType<ObjectJSON> {
607
648
  * @returns
608
649
  */
609
650
  protected customStrongEqual(targetTypeJSON: ASTNodeJSON): boolean;
651
+ toJSONSchema(): VarJSONSchema.ISchema;
610
652
  }
611
653
 
612
654
  interface UnionJSON {
@@ -622,6 +664,7 @@ declare class CustomType extends BaseType<CustomTypeJSON> {
622
664
  get typeName(): string;
623
665
  fromJSON(json: CustomTypeJSON): void;
624
666
  isTypeEqual(targetTypeJSONOrKind?: ASTNodeJSONOrKind): boolean;
667
+ toJSONSchema(): VarJSONSchema.ISchema;
625
668
  }
626
669
 
627
670
  type ExpressionRefs = (BaseVariableField | undefined)[];
@@ -662,16 +705,6 @@ declare abstract class BaseExpression<JSON extends ASTNodeJSON = any, InjectOpts
662
705
  constructor(params: CreateASTParams, opts?: InjectOpts);
663
706
  }
664
707
 
665
- interface ExpressionListJSON {
666
- expressions: ASTNodeJSON[];
667
- }
668
- declare class ExpressionList extends ASTNode<ExpressionListJSON> {
669
- static kind: string;
670
- expressions: ASTNode[];
671
- fromJSON({ expressions }: ExpressionListJSON): void;
672
- toJSON(): ASTNodeJSON;
673
- }
674
-
675
708
  interface KeyPathExpressionJSON$1 {
676
709
  keyPath: string[];
677
710
  }
@@ -738,6 +771,25 @@ declare class KeyPathExpressionV2<CustomPathJSON extends ASTNodeJSON = KeyPathEx
738
771
  toJSON(): ASTNodeJSON;
739
772
  }
740
773
 
774
+ interface WrapArrayExpressionJSON {
775
+ wrapFor: ASTNodeJSON;
776
+ }
777
+ /**
778
+ * 遍历表达式,对列表进行遍历,获取遍历后的变量类型
779
+ */
780
+ declare class WrapArrayExpression extends BaseExpression<WrapArrayExpressionJSON> {
781
+ static kind: string;
782
+ protected _wrapFor: BaseExpression | undefined;
783
+ protected _returnType: BaseType | undefined;
784
+ get wrapFor(): BaseExpression<any, any> | undefined;
785
+ get returnType(): BaseType | undefined;
786
+ refreshReturnType(): void;
787
+ getRefFields(): [];
788
+ fromJSON({ wrapFor: expression }: WrapArrayExpressionJSON): void;
789
+ toJSON(): ASTNodeJSON;
790
+ protected init(): void;
791
+ }
792
+
741
793
  /**
742
794
  * 声明类 AST 节点
743
795
  */
@@ -897,6 +949,22 @@ declare namespace ASTFactory {
897
949
  keyPath: string[];
898
950
  kind: ASTKind;
899
951
  };
952
+ const createWrapArrayExpression: (json: WrapArrayExpressionJSON) => {
953
+ wrapFor: ASTNodeJSON;
954
+ kind: ASTKind;
955
+ };
956
+ /**
957
+ * Converts a JSON schema to an Abstract Syntax Tree (AST) representation.
958
+ * This function recursively processes the JSON schema and creates corresponding AST nodes.
959
+ *
960
+ * For more information on JSON Schema, refer to the official documentation:
961
+ * https://json-schema.org/
962
+ *
963
+ *
964
+ * @param jsonSchema - The JSON schema to convert.
965
+ * @returns An AST node representing the JSON schema, or undefined if the schema type is not recognized.
966
+ */
967
+ function createTypeASTFromSchema(jsonSchema: VarJSONSchema.ISchema): ASTNodeJSON | undefined;
900
968
  /**
901
969
  * 通过 AST Class 创建
902
970
  */
@@ -1044,4 +1112,4 @@ declare class VariableFieldKeyRenameService {
1044
1112
  dispose(): void;
1045
1113
  }
1046
1114
 
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 };
1115
+ 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, VarJSONSchema, VariableContainerModule, VariableDeclaration, type VariableDeclarationJSON, VariableDeclarationList, type VariableDeclarationListChangeAction, type VariableDeclarationListJSON, VariableEngine, VariableEngineProvider, VariableFieldKeyRenameService, WrapArrayExpression, type WrapArrayExpressionJSON, injectToAST, isMatchAST, postConstructAST, useAvailableVariables, useCurrentScope, useScopeAvailable, useScopeContext };