@flowgram.ai/variable-core 0.1.30 → 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/esm/index.js +210 -77
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +81 -13
- package/dist/index.d.ts +81 -13
- package/dist/index.js +237 -104
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/esm/index.js
CHANGED
|
@@ -217,7 +217,7 @@ var ASTKind = /* @__PURE__ */ ((ASTKind2) => {
|
|
|
217
217
|
ASTKind2["VariableDeclarationList"] = "VariableDeclarationList";
|
|
218
218
|
ASTKind2["KeyPathExpression"] = "KeyPathExpression";
|
|
219
219
|
ASTKind2["EnumerateExpression"] = "EnumerateExpression";
|
|
220
|
-
ASTKind2["
|
|
220
|
+
ASTKind2["WrapArrayExpression"] = "WrapArrayExpression";
|
|
221
221
|
ASTKind2["ListNode"] = "ListNode";
|
|
222
222
|
ASTKind2["DataNode"] = "DataNode";
|
|
223
223
|
ASTKind2["MapNode"] = "MapNode";
|
|
@@ -552,6 +552,106 @@ var ASTNode = class _ASTNode {
|
|
|
552
552
|
}
|
|
553
553
|
};
|
|
554
554
|
|
|
555
|
+
// src/ast/factory.ts
|
|
556
|
+
import { get } from "lodash";
|
|
557
|
+
var ASTFactory;
|
|
558
|
+
((ASTFactory2) => {
|
|
559
|
+
ASTFactory2.createString = () => ({ kind: "String" /* String */ });
|
|
560
|
+
ASTFactory2.createNumber = () => ({ kind: "Number" /* Number */ });
|
|
561
|
+
ASTFactory2.createBoolean = () => ({ kind: "Boolean" /* Boolean */ });
|
|
562
|
+
ASTFactory2.createInteger = () => ({ kind: "Integer" /* Integer */ });
|
|
563
|
+
ASTFactory2.createObject = (json) => ({
|
|
564
|
+
kind: "Object" /* Object */,
|
|
565
|
+
...json
|
|
566
|
+
});
|
|
567
|
+
ASTFactory2.createArray = (json) => ({
|
|
568
|
+
kind: "Array" /* Array */,
|
|
569
|
+
...json
|
|
570
|
+
});
|
|
571
|
+
ASTFactory2.createMap = (json) => ({
|
|
572
|
+
kind: "Map" /* Map */,
|
|
573
|
+
...json
|
|
574
|
+
});
|
|
575
|
+
ASTFactory2.createUnion = (json) => ({
|
|
576
|
+
kind: "Union" /* Union */,
|
|
577
|
+
...json
|
|
578
|
+
});
|
|
579
|
+
ASTFactory2.createCustomType = (json) => ({
|
|
580
|
+
kind: "CustomType" /* CustomType */,
|
|
581
|
+
...json
|
|
582
|
+
});
|
|
583
|
+
ASTFactory2.createVariableDeclaration = (json) => ({
|
|
584
|
+
kind: "VariableDeclaration" /* VariableDeclaration */,
|
|
585
|
+
...json
|
|
586
|
+
});
|
|
587
|
+
ASTFactory2.createProperty = (json) => ({
|
|
588
|
+
kind: "Property" /* Property */,
|
|
589
|
+
...json
|
|
590
|
+
});
|
|
591
|
+
ASTFactory2.createVariableDeclarationList = (json) => ({
|
|
592
|
+
kind: "VariableDeclarationList" /* VariableDeclarationList */,
|
|
593
|
+
...json
|
|
594
|
+
});
|
|
595
|
+
ASTFactory2.createEnumerateExpression = (json) => ({
|
|
596
|
+
kind: "EnumerateExpression" /* EnumerateExpression */,
|
|
597
|
+
...json
|
|
598
|
+
});
|
|
599
|
+
ASTFactory2.createKeyPathExpression = (json) => ({
|
|
600
|
+
kind: "KeyPathExpression" /* KeyPathExpression */,
|
|
601
|
+
...json
|
|
602
|
+
});
|
|
603
|
+
ASTFactory2.createWrapArrayExpression = (json) => ({
|
|
604
|
+
kind: "WrapArrayExpression" /* WrapArrayExpression */,
|
|
605
|
+
...json
|
|
606
|
+
});
|
|
607
|
+
function createTypeASTFromSchema(jsonSchema) {
|
|
608
|
+
const { type, extra } = jsonSchema || {};
|
|
609
|
+
const { weak = false } = extra || {};
|
|
610
|
+
if (!type) {
|
|
611
|
+
return void 0;
|
|
612
|
+
}
|
|
613
|
+
switch (type) {
|
|
614
|
+
case "object":
|
|
615
|
+
if (weak) {
|
|
616
|
+
return { kind: "Object" /* Object */, weak: true };
|
|
617
|
+
}
|
|
618
|
+
return ASTFactory2.createObject({
|
|
619
|
+
properties: Object.entries(jsonSchema.properties || {}).sort((a, b) => (get(a?.[1], "extra.index") || 0) - (get(b?.[1], "extra.index") || 0)).map(([key, _property]) => ({
|
|
620
|
+
key,
|
|
621
|
+
type: createTypeASTFromSchema(_property),
|
|
622
|
+
meta: { description: _property.description }
|
|
623
|
+
}))
|
|
624
|
+
});
|
|
625
|
+
case "array":
|
|
626
|
+
if (weak) {
|
|
627
|
+
return { kind: "Array" /* Array */, weak: true };
|
|
628
|
+
}
|
|
629
|
+
return ASTFactory2.createArray({
|
|
630
|
+
items: createTypeASTFromSchema(jsonSchema.items)
|
|
631
|
+
});
|
|
632
|
+
case "map":
|
|
633
|
+
if (weak) {
|
|
634
|
+
return { kind: "Map" /* Map */, weak: true };
|
|
635
|
+
}
|
|
636
|
+
return ASTFactory2.createMap({
|
|
637
|
+
valueType: createTypeASTFromSchema(jsonSchema.additionalProperties)
|
|
638
|
+
});
|
|
639
|
+
case "string":
|
|
640
|
+
return ASTFactory2.createString();
|
|
641
|
+
case "number":
|
|
642
|
+
return ASTFactory2.createNumber();
|
|
643
|
+
case "boolean":
|
|
644
|
+
return ASTFactory2.createBoolean();
|
|
645
|
+
case "integer":
|
|
646
|
+
return ASTFactory2.createInteger();
|
|
647
|
+
default:
|
|
648
|
+
return ASTFactory2.createCustomType({ typeName: type });
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
ASTFactory2.createTypeASTFromSchema = createTypeASTFromSchema;
|
|
652
|
+
ASTFactory2.create = (targetType, json) => ({ kind: targetType.kind, ...json });
|
|
653
|
+
})(ASTFactory || (ASTFactory = {}));
|
|
654
|
+
|
|
555
655
|
// src/ast/type/base-type.ts
|
|
556
656
|
var BaseType = class extends ASTNode {
|
|
557
657
|
constructor() {
|
|
@@ -559,7 +659,7 @@ var BaseType = class extends ASTNode {
|
|
|
559
659
|
this.flags = 8 /* BasicType */;
|
|
560
660
|
}
|
|
561
661
|
/**
|
|
562
|
-
*
|
|
662
|
+
* 类型是否一致
|
|
563
663
|
* @param targetTypeJSON
|
|
564
664
|
*/
|
|
565
665
|
isTypeEqual(targetTypeJSONOrKind) {
|
|
@@ -578,11 +678,37 @@ var BaseType = class extends ASTNode {
|
|
|
578
678
|
getByKeyPath(keyPath = []) {
|
|
579
679
|
throw new Error(`Get By Key Path is not implemented for Type: ${this.kind}`);
|
|
580
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Get AST JSON for current base type
|
|
683
|
+
* @returns
|
|
684
|
+
*/
|
|
581
685
|
toJSON() {
|
|
582
686
|
return {
|
|
583
687
|
kind: this.kind
|
|
584
688
|
};
|
|
585
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* Get Standard JSON Schema for current base type
|
|
692
|
+
* @returns
|
|
693
|
+
*/
|
|
694
|
+
toJSONSchema() {
|
|
695
|
+
return {
|
|
696
|
+
type: this.kind.toLowerCase()
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Check if the type is equal with json schema
|
|
701
|
+
*/
|
|
702
|
+
isEqualWithJSONSchema(schema) {
|
|
703
|
+
if (Array.isArray(schema)) {
|
|
704
|
+
return this.isTypeEqual(
|
|
705
|
+
ASTFactory.createUnion({
|
|
706
|
+
types: schema.map((_schema) => ASTFactory.createTypeASTFromSchema(_schema)).filter(Boolean)
|
|
707
|
+
})
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
return this.isTypeEqual(ASTFactory.createTypeASTFromSchema(schema));
|
|
711
|
+
}
|
|
586
712
|
};
|
|
587
713
|
|
|
588
714
|
// src/ast/type/array.ts
|
|
@@ -642,6 +768,11 @@ var StringType = class extends BaseType {
|
|
|
642
768
|
}
|
|
643
769
|
fromJSON() {
|
|
644
770
|
}
|
|
771
|
+
toJSONSchema() {
|
|
772
|
+
return {
|
|
773
|
+
type: "string"
|
|
774
|
+
};
|
|
775
|
+
}
|
|
645
776
|
};
|
|
646
777
|
StringType.kind = "String" /* String */;
|
|
647
778
|
|
|
@@ -653,6 +784,11 @@ var IntegerType = class extends BaseType {
|
|
|
653
784
|
}
|
|
654
785
|
fromJSON() {
|
|
655
786
|
}
|
|
787
|
+
toJSONSchema() {
|
|
788
|
+
return {
|
|
789
|
+
type: "integer"
|
|
790
|
+
};
|
|
791
|
+
}
|
|
656
792
|
};
|
|
657
793
|
IntegerType.kind = "Integer" /* Integer */;
|
|
658
794
|
|
|
@@ -660,6 +796,11 @@ IntegerType.kind = "Integer" /* Integer */;
|
|
|
660
796
|
var BooleanType = class extends BaseType {
|
|
661
797
|
fromJSON() {
|
|
662
798
|
}
|
|
799
|
+
toJSONSchema() {
|
|
800
|
+
return {
|
|
801
|
+
type: "boolean"
|
|
802
|
+
};
|
|
803
|
+
}
|
|
663
804
|
};
|
|
664
805
|
BooleanType.kind = "Boolean" /* Boolean */;
|
|
665
806
|
|
|
@@ -667,6 +808,11 @@ BooleanType.kind = "Boolean" /* Boolean */;
|
|
|
667
808
|
var NumberType = class extends BaseType {
|
|
668
809
|
fromJSON() {
|
|
669
810
|
}
|
|
811
|
+
toJSONSchema() {
|
|
812
|
+
return {
|
|
813
|
+
type: "number"
|
|
814
|
+
};
|
|
815
|
+
}
|
|
670
816
|
};
|
|
671
817
|
NumberType.kind = "Number" /* Number */;
|
|
672
818
|
|
|
@@ -713,6 +859,12 @@ var MapType = class extends BaseType {
|
|
|
713
859
|
valueType: this.valueType?.toJSON()
|
|
714
860
|
};
|
|
715
861
|
}
|
|
862
|
+
toJSONSchema() {
|
|
863
|
+
return {
|
|
864
|
+
type: "map",
|
|
865
|
+
additionalProperties: this.valueType?.toJSONSchema()
|
|
866
|
+
};
|
|
867
|
+
}
|
|
716
868
|
};
|
|
717
869
|
// public flags: ASTNodeFlags = ASTNodeFlags.DrilldownType | ASTNodeFlags.EnumerateType;
|
|
718
870
|
MapType.kind = "Map" /* Map */;
|
|
@@ -804,6 +956,15 @@ var ObjectType = class extends BaseType {
|
|
|
804
956
|
return sourceProperty && sourceProperty.key === targetProperty.key && sourceProperty.type?.isTypeEqual(targetProperty?.type);
|
|
805
957
|
});
|
|
806
958
|
}
|
|
959
|
+
toJSONSchema() {
|
|
960
|
+
return {
|
|
961
|
+
type: "object",
|
|
962
|
+
properties: this.properties.reduce((acc, _property) => {
|
|
963
|
+
acc[_property.key] = _property.type?.toJSONSchema();
|
|
964
|
+
return acc;
|
|
965
|
+
}, {})
|
|
966
|
+
};
|
|
967
|
+
}
|
|
807
968
|
};
|
|
808
969
|
ObjectType.kind = "Object" /* Object */;
|
|
809
970
|
|
|
@@ -827,6 +988,11 @@ var CustomType = class extends BaseType {
|
|
|
827
988
|
}
|
|
828
989
|
return targetTypeJSON?.kind === this.kind && targetTypeJSON?.typeName === this.typeName;
|
|
829
990
|
}
|
|
991
|
+
toJSONSchema() {
|
|
992
|
+
return {
|
|
993
|
+
type: this._typeName
|
|
994
|
+
};
|
|
995
|
+
}
|
|
830
996
|
};
|
|
831
997
|
CustomType.kind = "CustomType" /* CustomType */;
|
|
832
998
|
|
|
@@ -913,29 +1079,6 @@ var BaseExpression = class extends ASTNode {
|
|
|
913
1079
|
}
|
|
914
1080
|
};
|
|
915
1081
|
|
|
916
|
-
// src/ast/expression/expression-list.ts
|
|
917
|
-
var ExpressionList = class extends ASTNode {
|
|
918
|
-
fromJSON({ expressions }) {
|
|
919
|
-
this.expressions = expressions.map((_expression, idx) => {
|
|
920
|
-
const prevExpression = this.expressions[idx];
|
|
921
|
-
if (prevExpression.kind !== _expression.kind) {
|
|
922
|
-
prevExpression.dispose();
|
|
923
|
-
this.fireChange();
|
|
924
|
-
return this.createChildNode(_expression);
|
|
925
|
-
}
|
|
926
|
-
prevExpression.fromJSON(_expression);
|
|
927
|
-
return prevExpression;
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
toJSON() {
|
|
931
|
-
return {
|
|
932
|
-
kind: "ExpressionList" /* ExpressionList */,
|
|
933
|
-
properties: this.expressions.map((_expression) => _expression.toJSON())
|
|
934
|
-
};
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
ExpressionList.kind = "ExpressionList" /* ExpressionList */;
|
|
938
|
-
|
|
939
1082
|
// src/ast/expression/keypath-expression.ts
|
|
940
1083
|
import { shallowEqual as shallowEqual3 } from "fast-equals";
|
|
941
1084
|
var KeyPathExpression = class extends BaseExpression {
|
|
@@ -1117,6 +1260,46 @@ var KeyPathExpressionV2 = class extends BaseExpression {
|
|
|
1117
1260
|
};
|
|
1118
1261
|
KeyPathExpressionV2.kind = "KeyPathExpression" /* KeyPathExpression */;
|
|
1119
1262
|
|
|
1263
|
+
// src/ast/expression/wrap-array-expression.ts
|
|
1264
|
+
var WrapArrayExpression = class extends BaseExpression {
|
|
1265
|
+
get wrapFor() {
|
|
1266
|
+
return this._wrapFor;
|
|
1267
|
+
}
|
|
1268
|
+
get returnType() {
|
|
1269
|
+
return this._returnType;
|
|
1270
|
+
}
|
|
1271
|
+
refreshReturnType() {
|
|
1272
|
+
const childReturnTypeJSON = this.wrapFor?.returnType?.toJSON();
|
|
1273
|
+
this.updateChildNodeByKey("_returnType", {
|
|
1274
|
+
kind: "Array" /* Array */,
|
|
1275
|
+
items: childReturnTypeJSON
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
getRefFields() {
|
|
1279
|
+
return [];
|
|
1280
|
+
}
|
|
1281
|
+
fromJSON({ wrapFor: expression }) {
|
|
1282
|
+
this.updateChildNodeByKey("_wrapFor", expression);
|
|
1283
|
+
}
|
|
1284
|
+
toJSON() {
|
|
1285
|
+
return {
|
|
1286
|
+
kind: "WrapArrayExpression" /* WrapArrayExpression */,
|
|
1287
|
+
wrapFor: this.wrapFor?.toJSON()
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
init() {
|
|
1291
|
+
this.toDispose.push(
|
|
1292
|
+
this.subscribe(this.refreshReturnType, {
|
|
1293
|
+
selector: (curr) => curr.wrapFor?.returnType
|
|
1294
|
+
})
|
|
1295
|
+
);
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
WrapArrayExpression.kind = "WrapArrayExpression" /* WrapArrayExpression */;
|
|
1299
|
+
__decorateClass([
|
|
1300
|
+
postConstructAST()
|
|
1301
|
+
], WrapArrayExpression.prototype, "init", 1);
|
|
1302
|
+
|
|
1120
1303
|
// src/ast/declaration/base-variable-field.ts
|
|
1121
1304
|
import { shallowEqual as shallowEqual5 } from "fast-equals";
|
|
1122
1305
|
var BaseVariableField = class extends ASTNode {
|
|
@@ -1423,7 +1606,7 @@ var ASTRegisters = class {
|
|
|
1423
1606
|
this.registerAST(VariableDeclarationList);
|
|
1424
1607
|
this.registerAST(KeyPathExpression);
|
|
1425
1608
|
this.registerAST(EnumerateExpression);
|
|
1426
|
-
this.registerAST(
|
|
1609
|
+
this.registerAST(WrapArrayExpression);
|
|
1427
1610
|
this.registerAST(MapNode);
|
|
1428
1611
|
this.registerAST(DataNode);
|
|
1429
1612
|
}
|
|
@@ -1479,56 +1662,6 @@ ASTRegisters = __decorateClass([
|
|
|
1479
1662
|
injectable2()
|
|
1480
1663
|
], ASTRegisters);
|
|
1481
1664
|
|
|
1482
|
-
// src/ast/factory.ts
|
|
1483
|
-
var ASTFactory;
|
|
1484
|
-
((ASTFactory2) => {
|
|
1485
|
-
ASTFactory2.createString = () => ({ kind: "String" /* String */ });
|
|
1486
|
-
ASTFactory2.createNumber = () => ({ kind: "Number" /* Number */ });
|
|
1487
|
-
ASTFactory2.createBoolean = () => ({ kind: "Boolean" /* Boolean */ });
|
|
1488
|
-
ASTFactory2.createInteger = () => ({ kind: "Integer" /* Integer */ });
|
|
1489
|
-
ASTFactory2.createObject = (json) => ({
|
|
1490
|
-
kind: "Object" /* Object */,
|
|
1491
|
-
...json
|
|
1492
|
-
});
|
|
1493
|
-
ASTFactory2.createArray = (json) => ({
|
|
1494
|
-
kind: "Array" /* Array */,
|
|
1495
|
-
...json
|
|
1496
|
-
});
|
|
1497
|
-
ASTFactory2.createMap = (json) => ({
|
|
1498
|
-
kind: "Map" /* Map */,
|
|
1499
|
-
...json
|
|
1500
|
-
});
|
|
1501
|
-
ASTFactory2.createUnion = (json) => ({
|
|
1502
|
-
kind: "Union" /* Union */,
|
|
1503
|
-
...json
|
|
1504
|
-
});
|
|
1505
|
-
ASTFactory2.createCustomType = (json) => ({
|
|
1506
|
-
kind: "CustomType" /* CustomType */,
|
|
1507
|
-
...json
|
|
1508
|
-
});
|
|
1509
|
-
ASTFactory2.createVariableDeclaration = (json) => ({
|
|
1510
|
-
kind: "VariableDeclaration" /* VariableDeclaration */,
|
|
1511
|
-
...json
|
|
1512
|
-
});
|
|
1513
|
-
ASTFactory2.createProperty = (json) => ({
|
|
1514
|
-
kind: "Property" /* Property */,
|
|
1515
|
-
...json
|
|
1516
|
-
});
|
|
1517
|
-
ASTFactory2.createVariableDeclarationList = (json) => ({
|
|
1518
|
-
kind: "VariableDeclarationList" /* VariableDeclarationList */,
|
|
1519
|
-
...json
|
|
1520
|
-
});
|
|
1521
|
-
ASTFactory2.createEnumerateExpression = (json) => ({
|
|
1522
|
-
kind: "EnumerateExpression" /* EnumerateExpression */,
|
|
1523
|
-
...json
|
|
1524
|
-
});
|
|
1525
|
-
ASTFactory2.createKeyPathExpression = (json) => ({
|
|
1526
|
-
kind: "KeyPathExpression" /* KeyPathExpression */,
|
|
1527
|
-
...json
|
|
1528
|
-
});
|
|
1529
|
-
ASTFactory2.create = (targetType, json) => ({ kind: targetType.kind, ...json });
|
|
1530
|
-
})(ASTFactory || (ASTFactory = {}));
|
|
1531
|
-
|
|
1532
1665
|
// src/scope/datas/scope-output-data.ts
|
|
1533
1666
|
var ScopeOutputData = class {
|
|
1534
1667
|
constructor(scope) {
|
|
@@ -2064,7 +2197,6 @@ export {
|
|
|
2064
2197
|
CustomType,
|
|
2065
2198
|
DataNode,
|
|
2066
2199
|
EnumerateExpression,
|
|
2067
|
-
ExpressionList,
|
|
2068
2200
|
IntegerType,
|
|
2069
2201
|
KeyPathExpression,
|
|
2070
2202
|
KeyPathExpressionV2,
|
|
@@ -2085,6 +2217,7 @@ export {
|
|
|
2085
2217
|
VariableEngine,
|
|
2086
2218
|
VariableEngineProvider,
|
|
2087
2219
|
VariableFieldKeyRenameService,
|
|
2220
|
+
WrapArrayExpression,
|
|
2088
2221
|
injectToAST,
|
|
2089
2222
|
isMatchAST,
|
|
2090
2223
|
postConstructAST,
|