@valbuild/core 0.13.8 → 0.14.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/declarations/src/expr/eval.d.ts +6 -6
- package/dist/declarations/src/expr/index.d.ts +3 -3
- package/dist/declarations/src/expr/parser.d.ts +2 -2
- package/dist/declarations/src/fetchVal.d.ts +2 -2
- package/dist/declarations/src/fp/index.d.ts +3 -3
- package/dist/declarations/src/fp/result.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +23 -22
- package/dist/declarations/src/initSchema.d.ts +25 -25
- package/dist/declarations/src/initVal.d.ts +7 -13
- package/dist/declarations/src/module.d.ts +10 -10
- package/dist/declarations/src/patch/deref.d.ts +3 -3
- package/dist/declarations/src/patch/index.d.ts +6 -6
- package/dist/declarations/src/patch/json.d.ts +2 -2
- package/dist/declarations/src/patch/operation.d.ts +2 -2
- package/dist/declarations/src/patch/ops.d.ts +1 -1
- package/dist/declarations/src/patch/parse.d.ts +3 -3
- package/dist/declarations/src/patch/patch.d.ts +3 -3
- package/dist/declarations/src/patch/util.d.ts +2 -2
- package/dist/declarations/src/schema/array.d.ts +3 -3
- package/dist/declarations/src/schema/boolean.d.ts +2 -2
- package/dist/declarations/src/schema/i18n.d.ts +3 -3
- package/dist/declarations/src/schema/image.d.ts +3 -3
- package/dist/declarations/src/schema/index.d.ts +14 -14
- package/dist/declarations/src/schema/literal.d.ts +2 -2
- package/dist/declarations/src/schema/number.d.ts +2 -2
- package/dist/declarations/src/schema/object.d.ts +3 -3
- package/dist/declarations/src/schema/oneOf.d.ts +5 -5
- package/dist/declarations/src/schema/richtext.d.ts +3 -3
- package/dist/declarations/src/schema/string.d.ts +2 -2
- package/dist/declarations/src/schema/union.d.ts +5 -5
- package/dist/declarations/src/selector/array.d.ts +5 -5
- package/dist/declarations/src/selector/boolean.d.ts +1 -1
- package/dist/declarations/src/selector/file.d.ts +1 -1
- package/dist/declarations/src/selector/i18n.d.ts +3 -3
- package/dist/declarations/src/selector/index.d.ts +17 -17
- package/dist/declarations/src/selector/number.d.ts +1 -1
- package/dist/declarations/src/selector/object.d.ts +2 -2
- package/dist/declarations/src/selector/primitive.d.ts +3 -3
- package/dist/declarations/src/selector/remote.d.ts +2 -2
- package/dist/declarations/src/selector/string.d.ts +1 -1
- package/dist/declarations/src/source/file.d.ts +2 -2
- package/dist/declarations/src/source/i18n.d.ts +2 -2
- package/dist/declarations/src/source/index.d.ts +4 -4
- package/dist/declarations/src/source/remote.d.ts +4 -4
- package/dist/declarations/src/source/richtext.d.ts +2 -2
- package/dist/declarations/src/val/array.d.ts +3 -3
- package/dist/declarations/src/val/index.d.ts +9 -9
- package/dist/declarations/src/val/object.d.ts +3 -3
- package/dist/declarations/src/val/primitive.d.ts +3 -3
- package/dist/{index-296cb2b6.esm.js → index-06df0a5b.esm.js} +1 -1
- package/dist/valbuild-core.cjs.dev.js +140 -144
- package/dist/valbuild-core.cjs.prod.js +140 -144
- package/dist/valbuild-core.esm.js +142 -146
- package/expr/dist/valbuild-core-expr.esm.js +1 -1
- package/package.json +1 -1
- package/src/expr/eval.test.ts +2 -3
- package/src/expr/parser.test.ts +1 -1
- package/src/expr/repl.ts +1 -2
- package/src/index.ts +3 -2
- package/src/initVal.ts +1 -21
- package/src/selector/selector.test.ts +1 -1
- package/dist/declarations/src/expr/tokenizer.d.ts +0 -7
- package/dist/declarations/src/selector/SelectorProxy.d.ts +0 -7
@@ -693,146 +693,6 @@ function initSchema(locales) {
|
|
693
693
|
};
|
694
694
|
}
|
695
695
|
|
696
|
-
function fetchVal(selector, locale) {
|
697
|
-
return Promise.resolve(getVal(selector));
|
698
|
-
}
|
699
|
-
function getVal(selector,
|
700
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
701
|
-
locale) {
|
702
|
-
return newValProxy(serializedValOfSelectorSource(selector));
|
703
|
-
}
|
704
|
-
|
705
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
706
|
-
function isArrayOrArraySelector(child) {
|
707
|
-
if (expr_dist_valbuildCoreExpr.isSelector(child)) {
|
708
|
-
return createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) === "object" && createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) !== null && Array.isArray(child[expr_dist_valbuildCoreExpr.SourceOrExpr]);
|
709
|
-
}
|
710
|
-
return Array.isArray(child);
|
711
|
-
}
|
712
|
-
|
713
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
714
|
-
function isObjectOrObjectSelector(child) {
|
715
|
-
if (expr_dist_valbuildCoreExpr.isSelector(child)) {
|
716
|
-
return createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) === "object" && createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) !== null && !Array.isArray(child[expr_dist_valbuildCoreExpr.SourceOrExpr]);
|
717
|
-
}
|
718
|
-
return createClass._typeof(child) === "object";
|
719
|
-
}
|
720
|
-
function serializedValOfSelectorSource(selector) {
|
721
|
-
var wrappedSelector = expr_dist_valbuildCoreExpr.newSelectorProxy(selector); // NOTE: we do this if call-site uses a literal with selectors inside
|
722
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
723
|
-
function rec(child) {
|
724
|
-
var isArray = isArrayOrArraySelector(child);
|
725
|
-
var isObject = isObjectOrObjectSelector(child);
|
726
|
-
if (isArray) {
|
727
|
-
var array = expr_dist_valbuildCoreExpr.SourceOrExpr in child ? child[expr_dist_valbuildCoreExpr.SourceOrExpr] : child;
|
728
|
-
var valPath = expr_dist_valbuildCoreExpr.Path in child ? child[expr_dist_valbuildCoreExpr.Path] : undefined;
|
729
|
-
return {
|
730
|
-
val: array.map(function (item, i) {
|
731
|
-
return rec(expr_dist_valbuildCoreExpr.isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
732
|
-
? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath, i)));
|
733
|
-
}),
|
734
|
-
valPath: valPath
|
735
|
-
};
|
736
|
-
} else if (isObject) {
|
737
|
-
var obj = expr_dist_valbuildCoreExpr.SourceOrExpr in child ? child[expr_dist_valbuildCoreExpr.SourceOrExpr] : child;
|
738
|
-
var _valPath = expr_dist_valbuildCoreExpr.Path in child ? child[expr_dist_valbuildCoreExpr.Path] : undefined;
|
739
|
-
return {
|
740
|
-
val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
|
741
|
-
var _ref2 = createClass._slicedToArray(_ref, 2),
|
742
|
-
key = _ref2[0],
|
743
|
-
value = _ref2[1];
|
744
|
-
return [key, rec(expr_dist_valbuildCoreExpr.isSelector(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
745
|
-
? value : expr_dist_valbuildCoreExpr.newSelectorProxy(value, expr_dist_valbuildCoreExpr.createValPathOfItem(_valPath, key)))];
|
746
|
-
})),
|
747
|
-
valPath: _valPath
|
748
|
-
};
|
749
|
-
} else if (expr_dist_valbuildCoreExpr.isSelector(child)) {
|
750
|
-
return {
|
751
|
-
val: rec(child[expr_dist_valbuildCoreExpr.SourceOrExpr]),
|
752
|
-
valPath: child[expr_dist_valbuildCoreExpr.Path]
|
753
|
-
};
|
754
|
-
} else {
|
755
|
-
return child;
|
756
|
-
}
|
757
|
-
}
|
758
|
-
return rec(wrappedSelector);
|
759
|
-
}
|
760
|
-
function strip(value) {
|
761
|
-
var val = expr_dist_valbuildCoreExpr.isSerializedVal(value) ? value.val : value;
|
762
|
-
switch (createClass._typeof(val)) {
|
763
|
-
case "function":
|
764
|
-
case "symbol":
|
765
|
-
throw Error("Invalid val type: ".concat(createClass._typeof(val)));
|
766
|
-
case "object":
|
767
|
-
if (val === null) {
|
768
|
-
return null;
|
769
|
-
} else if (Array.isArray(val)) {
|
770
|
-
return val.map(strip);
|
771
|
-
} else {
|
772
|
-
return Object.fromEntries(Object.entries(val).map(function (_ref3) {
|
773
|
-
var _ref4 = createClass._slicedToArray(_ref3, 2),
|
774
|
-
key = _ref4[0],
|
775
|
-
value = _ref4[1];
|
776
|
-
return [key, value && strip(value)];
|
777
|
-
}));
|
778
|
-
}
|
779
|
-
// intentional fallthrough
|
780
|
-
// eslint-disable-next-line no-fallthrough
|
781
|
-
default:
|
782
|
-
return val;
|
783
|
-
}
|
784
|
-
}
|
785
|
-
function newValProxy(val) {
|
786
|
-
var _ref5;
|
787
|
-
var source = val.val;
|
788
|
-
switch (createClass._typeof(source)) {
|
789
|
-
case "function":
|
790
|
-
case "symbol":
|
791
|
-
throw Error("Invalid val type: ".concat(createClass._typeof(source)));
|
792
|
-
case "object":
|
793
|
-
if (source !== null) {
|
794
|
-
// Handles both objects and arrays!
|
795
|
-
return new Proxy(source, {
|
796
|
-
has: function has(target, prop) {
|
797
|
-
if (prop === "val") {
|
798
|
-
return true;
|
799
|
-
}
|
800
|
-
if (prop === expr_dist_valbuildCoreExpr.Path) {
|
801
|
-
return true;
|
802
|
-
}
|
803
|
-
return hasOwn(target, prop);
|
804
|
-
},
|
805
|
-
get: function get(target, prop) {
|
806
|
-
if (prop === expr_dist_valbuildCoreExpr.Path) {
|
807
|
-
return val.valPath;
|
808
|
-
}
|
809
|
-
if (prop === "val") {
|
810
|
-
return strip(val);
|
811
|
-
}
|
812
|
-
if (Array.isArray(target) && prop === "length") {
|
813
|
-
return target.length;
|
814
|
-
}
|
815
|
-
if (hasOwn(source, prop)) {
|
816
|
-
var _Reflect$get$valPath, _Reflect$get;
|
817
|
-
return newValProxy({
|
818
|
-
val: Reflect.get(target, prop).val,
|
819
|
-
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : expr_dist_valbuildCoreExpr.createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
820
|
-
});
|
821
|
-
}
|
822
|
-
return Reflect.get(target, prop);
|
823
|
-
}
|
824
|
-
});
|
825
|
-
}
|
826
|
-
// intentional fallthrough
|
827
|
-
// eslint-disable-next-line no-fallthrough
|
828
|
-
default:
|
829
|
-
return _ref5 = {}, expr_dist_valbuildCoreExpr._defineProperty(_ref5, expr_dist_valbuildCoreExpr.Path, val.valPath), expr_dist_valbuildCoreExpr._defineProperty(_ref5, "val", val.val), _ref5;
|
830
|
-
}
|
831
|
-
}
|
832
|
-
function hasOwn(obj, prop) {
|
833
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
834
|
-
}
|
835
|
-
|
836
696
|
/**
|
837
697
|
* Remote sources cannot include other remote sources.
|
838
698
|
*/
|
@@ -878,11 +738,9 @@ var initVal = function initVal(options) {
|
|
878
738
|
i18n: i18n,
|
879
739
|
remote: remote,
|
880
740
|
getPath: expr_dist_valbuildCoreExpr.getValPath,
|
881
|
-
key: expr_dist_valbuildCoreExpr.getValPath,
|
882
741
|
file: expr_dist_valbuildCoreExpr.file,
|
883
742
|
richtext: richtext
|
884
743
|
},
|
885
|
-
fetchVal: fetchVal,
|
886
744
|
s: s
|
887
745
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
888
746
|
};
|
@@ -893,11 +751,9 @@ var initVal = function initVal(options) {
|
|
893
751
|
content: content,
|
894
752
|
remote: remote,
|
895
753
|
getPath: expr_dist_valbuildCoreExpr.getValPath,
|
896
|
-
key: expr_dist_valbuildCoreExpr.getValPath,
|
897
754
|
file: expr_dist_valbuildCoreExpr.file,
|
898
755
|
richtext: richtext
|
899
756
|
},
|
900
|
-
fetchVal: fetchVal,
|
901
757
|
s: expr_dist_valbuildCoreExpr._objectSpread2(expr_dist_valbuildCoreExpr._objectSpread2({}, s), {}, {
|
902
758
|
i18n: undefined
|
903
759
|
})
|
@@ -1016,6 +872,146 @@ function derefPatch(patch, document, ops$1) {
|
|
1016
872
|
});
|
1017
873
|
}
|
1018
874
|
|
875
|
+
function fetchVal(selector, locale) {
|
876
|
+
return Promise.resolve(getVal(selector));
|
877
|
+
}
|
878
|
+
function getVal(selector,
|
879
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
880
|
+
locale) {
|
881
|
+
return newValProxy(serializedValOfSelectorSource(selector));
|
882
|
+
}
|
883
|
+
|
884
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
885
|
+
function isArrayOrArraySelector(child) {
|
886
|
+
if (expr_dist_valbuildCoreExpr.isSelector(child)) {
|
887
|
+
return createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) === "object" && createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) !== null && Array.isArray(child[expr_dist_valbuildCoreExpr.SourceOrExpr]);
|
888
|
+
}
|
889
|
+
return Array.isArray(child);
|
890
|
+
}
|
891
|
+
|
892
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
893
|
+
function isObjectOrObjectSelector(child) {
|
894
|
+
if (expr_dist_valbuildCoreExpr.isSelector(child)) {
|
895
|
+
return createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) === "object" && createClass._typeof(child[expr_dist_valbuildCoreExpr.SourceOrExpr]) !== null && !Array.isArray(child[expr_dist_valbuildCoreExpr.SourceOrExpr]);
|
896
|
+
}
|
897
|
+
return createClass._typeof(child) === "object";
|
898
|
+
}
|
899
|
+
function serializedValOfSelectorSource(selector) {
|
900
|
+
var wrappedSelector = expr_dist_valbuildCoreExpr.newSelectorProxy(selector); // NOTE: we do this if call-site uses a literal with selectors inside
|
901
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
902
|
+
function rec(child) {
|
903
|
+
var isArray = isArrayOrArraySelector(child);
|
904
|
+
var isObject = isObjectOrObjectSelector(child);
|
905
|
+
if (isArray) {
|
906
|
+
var array = expr_dist_valbuildCoreExpr.SourceOrExpr in child ? child[expr_dist_valbuildCoreExpr.SourceOrExpr] : child;
|
907
|
+
var valPath = expr_dist_valbuildCoreExpr.Path in child ? child[expr_dist_valbuildCoreExpr.Path] : undefined;
|
908
|
+
return {
|
909
|
+
val: array.map(function (item, i) {
|
910
|
+
return rec(expr_dist_valbuildCoreExpr.isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
911
|
+
? item : expr_dist_valbuildCoreExpr.newSelectorProxy(item, expr_dist_valbuildCoreExpr.createValPathOfItem(valPath, i)));
|
912
|
+
}),
|
913
|
+
valPath: valPath
|
914
|
+
};
|
915
|
+
} else if (isObject) {
|
916
|
+
var obj = expr_dist_valbuildCoreExpr.SourceOrExpr in child ? child[expr_dist_valbuildCoreExpr.SourceOrExpr] : child;
|
917
|
+
var _valPath = expr_dist_valbuildCoreExpr.Path in child ? child[expr_dist_valbuildCoreExpr.Path] : undefined;
|
918
|
+
return {
|
919
|
+
val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
|
920
|
+
var _ref2 = createClass._slicedToArray(_ref, 2),
|
921
|
+
key = _ref2[0],
|
922
|
+
value = _ref2[1];
|
923
|
+
return [key, rec(expr_dist_valbuildCoreExpr.isSelector(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
924
|
+
? value : expr_dist_valbuildCoreExpr.newSelectorProxy(value, expr_dist_valbuildCoreExpr.createValPathOfItem(_valPath, key)))];
|
925
|
+
})),
|
926
|
+
valPath: _valPath
|
927
|
+
};
|
928
|
+
} else if (expr_dist_valbuildCoreExpr.isSelector(child)) {
|
929
|
+
return {
|
930
|
+
val: rec(child[expr_dist_valbuildCoreExpr.SourceOrExpr]),
|
931
|
+
valPath: child[expr_dist_valbuildCoreExpr.Path]
|
932
|
+
};
|
933
|
+
} else {
|
934
|
+
return child;
|
935
|
+
}
|
936
|
+
}
|
937
|
+
return rec(wrappedSelector);
|
938
|
+
}
|
939
|
+
function strip(value) {
|
940
|
+
var val = expr_dist_valbuildCoreExpr.isSerializedVal(value) ? value.val : value;
|
941
|
+
switch (createClass._typeof(val)) {
|
942
|
+
case "function":
|
943
|
+
case "symbol":
|
944
|
+
throw Error("Invalid val type: ".concat(createClass._typeof(val)));
|
945
|
+
case "object":
|
946
|
+
if (val === null) {
|
947
|
+
return null;
|
948
|
+
} else if (Array.isArray(val)) {
|
949
|
+
return val.map(strip);
|
950
|
+
} else {
|
951
|
+
return Object.fromEntries(Object.entries(val).map(function (_ref3) {
|
952
|
+
var _ref4 = createClass._slicedToArray(_ref3, 2),
|
953
|
+
key = _ref4[0],
|
954
|
+
value = _ref4[1];
|
955
|
+
return [key, value && strip(value)];
|
956
|
+
}));
|
957
|
+
}
|
958
|
+
// intentional fallthrough
|
959
|
+
// eslint-disable-next-line no-fallthrough
|
960
|
+
default:
|
961
|
+
return val;
|
962
|
+
}
|
963
|
+
}
|
964
|
+
function newValProxy(val) {
|
965
|
+
var _ref5;
|
966
|
+
var source = val.val;
|
967
|
+
switch (createClass._typeof(source)) {
|
968
|
+
case "function":
|
969
|
+
case "symbol":
|
970
|
+
throw Error("Invalid val type: ".concat(createClass._typeof(source)));
|
971
|
+
case "object":
|
972
|
+
if (source !== null) {
|
973
|
+
// Handles both objects and arrays!
|
974
|
+
return new Proxy(source, {
|
975
|
+
has: function has(target, prop) {
|
976
|
+
if (prop === "val") {
|
977
|
+
return true;
|
978
|
+
}
|
979
|
+
if (prop === expr_dist_valbuildCoreExpr.Path) {
|
980
|
+
return true;
|
981
|
+
}
|
982
|
+
return hasOwn(target, prop);
|
983
|
+
},
|
984
|
+
get: function get(target, prop) {
|
985
|
+
if (prop === expr_dist_valbuildCoreExpr.Path) {
|
986
|
+
return val.valPath;
|
987
|
+
}
|
988
|
+
if (prop === "val") {
|
989
|
+
return strip(val);
|
990
|
+
}
|
991
|
+
if (Array.isArray(target) && prop === "length") {
|
992
|
+
return target.length;
|
993
|
+
}
|
994
|
+
if (hasOwn(source, prop)) {
|
995
|
+
var _Reflect$get$valPath, _Reflect$get;
|
996
|
+
return newValProxy({
|
997
|
+
val: Reflect.get(target, prop).val,
|
998
|
+
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : expr_dist_valbuildCoreExpr.createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
999
|
+
});
|
1000
|
+
}
|
1001
|
+
return Reflect.get(target, prop);
|
1002
|
+
}
|
1003
|
+
});
|
1004
|
+
}
|
1005
|
+
// intentional fallthrough
|
1006
|
+
// eslint-disable-next-line no-fallthrough
|
1007
|
+
default:
|
1008
|
+
return _ref5 = {}, expr_dist_valbuildCoreExpr._defineProperty(_ref5, expr_dist_valbuildCoreExpr.Path, val.valPath), expr_dist_valbuildCoreExpr._defineProperty(_ref5, "val", val.val), _ref5;
|
1009
|
+
}
|
1010
|
+
}
|
1011
|
+
function hasOwn(obj, prop) {
|
1012
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
1013
|
+
}
|
1014
|
+
|
1019
1015
|
var Internal = {
|
1020
1016
|
convertImageSource: expr_dist_valbuildCoreExpr.convertImageSource,
|
1021
1017
|
getSchema: expr_dist_valbuildCoreExpr.getSchema,
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { _ as _inherits, a as _createSuper, S as Schema, g as getValPath, n as newSelectorProxy, b as SourceOrExpr, E as Expr, I as ImageSchema, c as _objectSpread2, d as _defineProperty, V as VAL_EXTENSION, i as image,
|
2
|
-
export { F as FILE_REF_PROP, G as GenericSelector, S as Schema, V as VAL_EXTENSION, p as expr } from './index-
|
1
|
+
import { _ as _inherits, a as _createSuper, S as Schema, g as getValPath, n as newSelectorProxy, b as SourceOrExpr, E as Expr, I as ImageSchema, c as _objectSpread2, d as _defineProperty, V as VAL_EXTENSION, i as image, f as file, e as isFile, F as FILE_REF_PROP, P as Path, h as createValPathOfItem, j as isSelector, k as isSerializedVal, l as convertImageSource, m as getSchema, o as isVal } from './index-06df0a5b.esm.js';
|
2
|
+
export { F as FILE_REF_PROP, G as GenericSelector, S as Schema, V as VAL_EXTENSION, p as expr } from './index-06df0a5b.esm.js';
|
3
3
|
import { _ as _classCallCheck, a as _createClass, b as _typeof, c as _slicedToArray, d as _toConsumableArray } from './createClass-012eebbf.esm.js';
|
4
4
|
import { _ as _createForOfIteratorHelper, i as isErr, a as isOk, e as err, o as ok } from './result-b96df128.esm.js';
|
5
5
|
import { P as PatchError } from './ops-6fae92a1.esm.js';
|
@@ -690,146 +690,6 @@ function initSchema(locales) {
|
|
690
690
|
};
|
691
691
|
}
|
692
692
|
|
693
|
-
function fetchVal(selector, locale) {
|
694
|
-
return Promise.resolve(getVal(selector));
|
695
|
-
}
|
696
|
-
function getVal(selector,
|
697
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
698
|
-
locale) {
|
699
|
-
return newValProxy(serializedValOfSelectorSource(selector));
|
700
|
-
}
|
701
|
-
|
702
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
703
|
-
function isArrayOrArraySelector(child) {
|
704
|
-
if (isSelector(child)) {
|
705
|
-
return _typeof(child[SourceOrExpr]) === "object" && _typeof(child[SourceOrExpr]) !== null && Array.isArray(child[SourceOrExpr]);
|
706
|
-
}
|
707
|
-
return Array.isArray(child);
|
708
|
-
}
|
709
|
-
|
710
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
711
|
-
function isObjectOrObjectSelector(child) {
|
712
|
-
if (isSelector(child)) {
|
713
|
-
return _typeof(child[SourceOrExpr]) === "object" && _typeof(child[SourceOrExpr]) !== null && !Array.isArray(child[SourceOrExpr]);
|
714
|
-
}
|
715
|
-
return _typeof(child) === "object";
|
716
|
-
}
|
717
|
-
function serializedValOfSelectorSource(selector) {
|
718
|
-
var wrappedSelector = newSelectorProxy(selector); // NOTE: we do this if call-site uses a literal with selectors inside
|
719
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
720
|
-
function rec(child) {
|
721
|
-
var isArray = isArrayOrArraySelector(child);
|
722
|
-
var isObject = isObjectOrObjectSelector(child);
|
723
|
-
if (isArray) {
|
724
|
-
var array = SourceOrExpr in child ? child[SourceOrExpr] : child;
|
725
|
-
var valPath = Path in child ? child[Path] : undefined;
|
726
|
-
return {
|
727
|
-
val: array.map(function (item, i) {
|
728
|
-
return rec(isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
729
|
-
? item : newSelectorProxy(item, createValPathOfItem(valPath, i)));
|
730
|
-
}),
|
731
|
-
valPath: valPath
|
732
|
-
};
|
733
|
-
} else if (isObject) {
|
734
|
-
var obj = SourceOrExpr in child ? child[SourceOrExpr] : child;
|
735
|
-
var _valPath = Path in child ? child[Path] : undefined;
|
736
|
-
return {
|
737
|
-
val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
|
738
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
739
|
-
key = _ref2[0],
|
740
|
-
value = _ref2[1];
|
741
|
-
return [key, rec(isSelector(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
742
|
-
? value : newSelectorProxy(value, createValPathOfItem(_valPath, key)))];
|
743
|
-
})),
|
744
|
-
valPath: _valPath
|
745
|
-
};
|
746
|
-
} else if (isSelector(child)) {
|
747
|
-
return {
|
748
|
-
val: rec(child[SourceOrExpr]),
|
749
|
-
valPath: child[Path]
|
750
|
-
};
|
751
|
-
} else {
|
752
|
-
return child;
|
753
|
-
}
|
754
|
-
}
|
755
|
-
return rec(wrappedSelector);
|
756
|
-
}
|
757
|
-
function strip(value) {
|
758
|
-
var val = isSerializedVal(value) ? value.val : value;
|
759
|
-
switch (_typeof(val)) {
|
760
|
-
case "function":
|
761
|
-
case "symbol":
|
762
|
-
throw Error("Invalid val type: ".concat(_typeof(val)));
|
763
|
-
case "object":
|
764
|
-
if (val === null) {
|
765
|
-
return null;
|
766
|
-
} else if (Array.isArray(val)) {
|
767
|
-
return val.map(strip);
|
768
|
-
} else {
|
769
|
-
return Object.fromEntries(Object.entries(val).map(function (_ref3) {
|
770
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
771
|
-
key = _ref4[0],
|
772
|
-
value = _ref4[1];
|
773
|
-
return [key, value && strip(value)];
|
774
|
-
}));
|
775
|
-
}
|
776
|
-
// intentional fallthrough
|
777
|
-
// eslint-disable-next-line no-fallthrough
|
778
|
-
default:
|
779
|
-
return val;
|
780
|
-
}
|
781
|
-
}
|
782
|
-
function newValProxy(val) {
|
783
|
-
var _ref5;
|
784
|
-
var source = val.val;
|
785
|
-
switch (_typeof(source)) {
|
786
|
-
case "function":
|
787
|
-
case "symbol":
|
788
|
-
throw Error("Invalid val type: ".concat(_typeof(source)));
|
789
|
-
case "object":
|
790
|
-
if (source !== null) {
|
791
|
-
// Handles both objects and arrays!
|
792
|
-
return new Proxy(source, {
|
793
|
-
has: function has(target, prop) {
|
794
|
-
if (prop === "val") {
|
795
|
-
return true;
|
796
|
-
}
|
797
|
-
if (prop === Path) {
|
798
|
-
return true;
|
799
|
-
}
|
800
|
-
return hasOwn(target, prop);
|
801
|
-
},
|
802
|
-
get: function get(target, prop) {
|
803
|
-
if (prop === Path) {
|
804
|
-
return val.valPath;
|
805
|
-
}
|
806
|
-
if (prop === "val") {
|
807
|
-
return strip(val);
|
808
|
-
}
|
809
|
-
if (Array.isArray(target) && prop === "length") {
|
810
|
-
return target.length;
|
811
|
-
}
|
812
|
-
if (hasOwn(source, prop)) {
|
813
|
-
var _Reflect$get$valPath, _Reflect$get;
|
814
|
-
return newValProxy({
|
815
|
-
val: Reflect.get(target, prop).val,
|
816
|
-
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
817
|
-
});
|
818
|
-
}
|
819
|
-
return Reflect.get(target, prop);
|
820
|
-
}
|
821
|
-
});
|
822
|
-
}
|
823
|
-
// intentional fallthrough
|
824
|
-
// eslint-disable-next-line no-fallthrough
|
825
|
-
default:
|
826
|
-
return _ref5 = {}, _defineProperty(_ref5, Path, val.valPath), _defineProperty(_ref5, "val", val.val), _ref5;
|
827
|
-
}
|
828
|
-
}
|
829
|
-
function hasOwn(obj, prop) {
|
830
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
831
|
-
}
|
832
|
-
|
833
693
|
/**
|
834
694
|
* Remote sources cannot include other remote sources.
|
835
695
|
*/
|
@@ -875,11 +735,9 @@ var initVal = function initVal(options) {
|
|
875
735
|
i18n: i18n,
|
876
736
|
remote: remote,
|
877
737
|
getPath: getValPath,
|
878
|
-
key: getValPath,
|
879
738
|
file: file,
|
880
739
|
richtext: richtext
|
881
740
|
},
|
882
|
-
fetchVal: fetchVal,
|
883
741
|
s: s
|
884
742
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
885
743
|
};
|
@@ -890,11 +748,9 @@ var initVal = function initVal(options) {
|
|
890
748
|
content: content,
|
891
749
|
remote: remote,
|
892
750
|
getPath: getValPath,
|
893
|
-
key: getValPath,
|
894
751
|
file: file,
|
895
752
|
richtext: richtext
|
896
753
|
},
|
897
|
-
fetchVal: fetchVal,
|
898
754
|
s: _objectSpread2(_objectSpread2({}, s), {}, {
|
899
755
|
i18n: undefined
|
900
756
|
})
|
@@ -1013,6 +869,146 @@ function derefPatch(patch, document, ops) {
|
|
1013
869
|
});
|
1014
870
|
}
|
1015
871
|
|
872
|
+
function fetchVal(selector, locale) {
|
873
|
+
return Promise.resolve(getVal(selector));
|
874
|
+
}
|
875
|
+
function getVal(selector,
|
876
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
877
|
+
locale) {
|
878
|
+
return newValProxy(serializedValOfSelectorSource(selector));
|
879
|
+
}
|
880
|
+
|
881
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
882
|
+
function isArrayOrArraySelector(child) {
|
883
|
+
if (isSelector(child)) {
|
884
|
+
return _typeof(child[SourceOrExpr]) === "object" && _typeof(child[SourceOrExpr]) !== null && Array.isArray(child[SourceOrExpr]);
|
885
|
+
}
|
886
|
+
return Array.isArray(child);
|
887
|
+
}
|
888
|
+
|
889
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
890
|
+
function isObjectOrObjectSelector(child) {
|
891
|
+
if (isSelector(child)) {
|
892
|
+
return _typeof(child[SourceOrExpr]) === "object" && _typeof(child[SourceOrExpr]) !== null && !Array.isArray(child[SourceOrExpr]);
|
893
|
+
}
|
894
|
+
return _typeof(child) === "object";
|
895
|
+
}
|
896
|
+
function serializedValOfSelectorSource(selector) {
|
897
|
+
var wrappedSelector = newSelectorProxy(selector); // NOTE: we do this if call-site uses a literal with selectors inside
|
898
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
899
|
+
function rec(child) {
|
900
|
+
var isArray = isArrayOrArraySelector(child);
|
901
|
+
var isObject = isObjectOrObjectSelector(child);
|
902
|
+
if (isArray) {
|
903
|
+
var array = SourceOrExpr in child ? child[SourceOrExpr] : child;
|
904
|
+
var valPath = Path in child ? child[Path] : undefined;
|
905
|
+
return {
|
906
|
+
val: array.map(function (item, i) {
|
907
|
+
return rec(isSelector(item) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
908
|
+
? item : newSelectorProxy(item, createValPathOfItem(valPath, i)));
|
909
|
+
}),
|
910
|
+
valPath: valPath
|
911
|
+
};
|
912
|
+
} else if (isObject) {
|
913
|
+
var obj = SourceOrExpr in child ? child[SourceOrExpr] : child;
|
914
|
+
var _valPath = Path in child ? child[Path] : undefined;
|
915
|
+
return {
|
916
|
+
val: obj !== null && Object.fromEntries(Object.entries(obj).map(function (_ref) {
|
917
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
918
|
+
key = _ref2[0],
|
919
|
+
value = _ref2[1];
|
920
|
+
return [key, rec(isSelector(value) // NOTE: We do this since selectors currently do not create selectors of items unless specifically required.
|
921
|
+
? value : newSelectorProxy(value, createValPathOfItem(_valPath, key)))];
|
922
|
+
})),
|
923
|
+
valPath: _valPath
|
924
|
+
};
|
925
|
+
} else if (isSelector(child)) {
|
926
|
+
return {
|
927
|
+
val: rec(child[SourceOrExpr]),
|
928
|
+
valPath: child[Path]
|
929
|
+
};
|
930
|
+
} else {
|
931
|
+
return child;
|
932
|
+
}
|
933
|
+
}
|
934
|
+
return rec(wrappedSelector);
|
935
|
+
}
|
936
|
+
function strip(value) {
|
937
|
+
var val = isSerializedVal(value) ? value.val : value;
|
938
|
+
switch (_typeof(val)) {
|
939
|
+
case "function":
|
940
|
+
case "symbol":
|
941
|
+
throw Error("Invalid val type: ".concat(_typeof(val)));
|
942
|
+
case "object":
|
943
|
+
if (val === null) {
|
944
|
+
return null;
|
945
|
+
} else if (Array.isArray(val)) {
|
946
|
+
return val.map(strip);
|
947
|
+
} else {
|
948
|
+
return Object.fromEntries(Object.entries(val).map(function (_ref3) {
|
949
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
950
|
+
key = _ref4[0],
|
951
|
+
value = _ref4[1];
|
952
|
+
return [key, value && strip(value)];
|
953
|
+
}));
|
954
|
+
}
|
955
|
+
// intentional fallthrough
|
956
|
+
// eslint-disable-next-line no-fallthrough
|
957
|
+
default:
|
958
|
+
return val;
|
959
|
+
}
|
960
|
+
}
|
961
|
+
function newValProxy(val) {
|
962
|
+
var _ref5;
|
963
|
+
var source = val.val;
|
964
|
+
switch (_typeof(source)) {
|
965
|
+
case "function":
|
966
|
+
case "symbol":
|
967
|
+
throw Error("Invalid val type: ".concat(_typeof(source)));
|
968
|
+
case "object":
|
969
|
+
if (source !== null) {
|
970
|
+
// Handles both objects and arrays!
|
971
|
+
return new Proxy(source, {
|
972
|
+
has: function has(target, prop) {
|
973
|
+
if (prop === "val") {
|
974
|
+
return true;
|
975
|
+
}
|
976
|
+
if (prop === Path) {
|
977
|
+
return true;
|
978
|
+
}
|
979
|
+
return hasOwn(target, prop);
|
980
|
+
},
|
981
|
+
get: function get(target, prop) {
|
982
|
+
if (prop === Path) {
|
983
|
+
return val.valPath;
|
984
|
+
}
|
985
|
+
if (prop === "val") {
|
986
|
+
return strip(val);
|
987
|
+
}
|
988
|
+
if (Array.isArray(target) && prop === "length") {
|
989
|
+
return target.length;
|
990
|
+
}
|
991
|
+
if (hasOwn(source, prop)) {
|
992
|
+
var _Reflect$get$valPath, _Reflect$get;
|
993
|
+
return newValProxy({
|
994
|
+
val: Reflect.get(target, prop).val,
|
995
|
+
valPath: (_Reflect$get$valPath = (_Reflect$get = Reflect.get(target, prop)) === null || _Reflect$get === void 0 ? void 0 : _Reflect$get.valPath) !== null && _Reflect$get$valPath !== void 0 ? _Reflect$get$valPath : createValPathOfItem(val.valPath, Array.isArray(target) ? Number(prop) : prop)
|
996
|
+
});
|
997
|
+
}
|
998
|
+
return Reflect.get(target, prop);
|
999
|
+
}
|
1000
|
+
});
|
1001
|
+
}
|
1002
|
+
// intentional fallthrough
|
1003
|
+
// eslint-disable-next-line no-fallthrough
|
1004
|
+
default:
|
1005
|
+
return _ref5 = {}, _defineProperty(_ref5, Path, val.valPath), _defineProperty(_ref5, "val", val.val), _ref5;
|
1006
|
+
}
|
1007
|
+
}
|
1008
|
+
function hasOwn(obj, prop) {
|
1009
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
1010
|
+
}
|
1011
|
+
|
1016
1012
|
var Internal = {
|
1017
1013
|
convertImageSource: convertImageSource,
|
1018
1014
|
getSchema: getSchema,
|
@@ -1,3 +1,3 @@
|
|
1
|
-
export { C as Call, E as Expr, N as NilSym, r as StringLiteral, s as StringTemplate, t as Sym, u as evaluate, q as parse } from '../../dist/index-
|
1
|
+
export { C as Call, E as Expr, N as NilSym, r as StringLiteral, s as StringTemplate, t as Sym, u as evaluate, q as parse } from '../../dist/index-06df0a5b.esm.js';
|
2
2
|
import '../../dist/createClass-012eebbf.esm.js';
|
3
3
|
import '../../dist/result-b96df128.esm.js';
|
package/package.json
CHANGED
package/src/expr/eval.test.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
import { pipe, result } from "
|
1
|
+
import { pipe, result } from "../fp";
|
2
2
|
import { Path } from "../selector";
|
3
|
-
import {
|
3
|
+
import { selectorToVal } from "../selector/SelectorProxy";
|
4
4
|
import { Source } from "../source";
|
5
|
-
import { SourcePath } from "../val";
|
6
5
|
import { evaluate } from "./eval";
|
7
6
|
import { parse } from "./parser";
|
8
7
|
|
package/src/expr/parser.test.ts
CHANGED
package/src/expr/repl.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import * as repl from "repl";
|
2
2
|
import { result, pipe } from "../../fp";
|
3
|
-
import {
|
4
|
-
import { SourcePath } from "../val";
|
3
|
+
import { selectorToVal } from "../selector/SelectorProxy";
|
5
4
|
import { evaluate } from "./eval";
|
6
5
|
import { parse } from "./parser";
|
7
6
|
|