@valbuild/shared 0.63.0 → 0.63.1
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.
@@ -8,6 +8,7 @@ export declare class ValStore {
|
|
8
8
|
private readonly drafts;
|
9
9
|
private readonly schema;
|
10
10
|
constructor(api: ValApi);
|
11
|
+
reloadPaths(paths: ModuleFilePath[]): Promise<void>;
|
11
12
|
reset(): Promise<void>;
|
12
13
|
getModule(path: ModuleFilePath, refetch?: boolean): Promise<result.Ok<{
|
13
14
|
source: Json;
|
@@ -1874,10 +1874,10 @@ var ValStore = /*#__PURE__*/function () {
|
|
1874
1874
|
this.schema = {};
|
1875
1875
|
}
|
1876
1876
|
_createClass(ValStore, [{
|
1877
|
-
key: "
|
1877
|
+
key: "reloadPaths",
|
1878
1878
|
value: function () {
|
1879
|
-
var
|
1880
|
-
var patches,
|
1879
|
+
var _reloadPaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(paths) {
|
1880
|
+
var patches, filteredPatches, data, _i, _Object$keys, pathS, path, _i2, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
|
1881
1881
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
1882
1882
|
while (1) switch (_context.prev = _context.next) {
|
1883
1883
|
case 0:
|
@@ -1892,14 +1892,21 @@ var ValStore = /*#__PURE__*/function () {
|
|
1892
1892
|
console.error("Val: failed to get patches", patches.error);
|
1893
1893
|
return _context.abrupt("return");
|
1894
1894
|
case 6:
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1895
|
+
filteredPatches = Object.entries(patches.value).flatMap(function (_ref) {
|
1896
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
1897
|
+
patchModuleFilePath = _ref2[0],
|
1898
|
+
mp = _ref2[1];
|
1899
|
+
if (paths.includes(patchModuleFilePath)) {
|
1900
|
+
return mp.map(function (p) {
|
1901
|
+
return p.patch_id;
|
1902
|
+
});
|
1903
|
+
} else {
|
1904
|
+
return [];
|
1905
|
+
}
|
1899
1906
|
});
|
1900
1907
|
_context.next = 9;
|
1901
1908
|
return this.api.putTree({
|
1902
|
-
patchIds:
|
1909
|
+
patchIds: filteredPatches
|
1903
1910
|
});
|
1904
1911
|
case 9:
|
1905
1912
|
data = _context.sent;
|
@@ -1921,7 +1928,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
1921
1928
|
}
|
1922
1929
|
}
|
1923
1930
|
} else {
|
1924
|
-
console.error("Val: failed to
|
1931
|
+
console.error("Val: failed to reload paths", paths, data.error);
|
1925
1932
|
}
|
1926
1933
|
case 13:
|
1927
1934
|
case "end":
|
@@ -1929,6 +1936,67 @@ var ValStore = /*#__PURE__*/function () {
|
|
1929
1936
|
}
|
1930
1937
|
}, _callee, this);
|
1931
1938
|
}));
|
1939
|
+
function reloadPaths(_x) {
|
1940
|
+
return _reloadPaths.apply(this, arguments);
|
1941
|
+
}
|
1942
|
+
return reloadPaths;
|
1943
|
+
}()
|
1944
|
+
}, {
|
1945
|
+
key: "reset",
|
1946
|
+
value: function () {
|
1947
|
+
var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
1948
|
+
var patches, allPatches, data, _i3, _Object$keys2, pathS, path, _i4, _Array$from2, _Array$from2$_i, subscriberId, subscriberModules;
|
1949
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
1950
|
+
while (1) switch (_context2.prev = _context2.next) {
|
1951
|
+
case 0:
|
1952
|
+
_context2.next = 2;
|
1953
|
+
return this.api.getPatches();
|
1954
|
+
case 2:
|
1955
|
+
patches = _context2.sent;
|
1956
|
+
if (!fp.result.isErr(patches)) {
|
1957
|
+
_context2.next = 6;
|
1958
|
+
break;
|
1959
|
+
}
|
1960
|
+
console.error("Val: failed to get patches", patches.error);
|
1961
|
+
return _context2.abrupt("return");
|
1962
|
+
case 6:
|
1963
|
+
allPatches = Object.values(patches.value).flatMap(function (mp) {
|
1964
|
+
return mp.map(function (p) {
|
1965
|
+
return p.patch_id;
|
1966
|
+
});
|
1967
|
+
});
|
1968
|
+
_context2.next = 9;
|
1969
|
+
return this.api.putTree({
|
1970
|
+
patchIds: allPatches
|
1971
|
+
});
|
1972
|
+
case 9:
|
1973
|
+
data = _context2.sent;
|
1974
|
+
_context2.next = 12;
|
1975
|
+
return this.initialize();
|
1976
|
+
case 12:
|
1977
|
+
if (fp.result.isOk(data)) {
|
1978
|
+
for (_i3 = 0, _Object$keys2 = Object.keys(data.value.modules); _i3 < _Object$keys2.length; _i3++) {
|
1979
|
+
pathS = _Object$keys2[_i3];
|
1980
|
+
path = pathS;
|
1981
|
+
this.drafts[path] = data.value.modules[path].source;
|
1982
|
+
this.emitEvent(path, this.drafts[path]);
|
1983
|
+
for (_i4 = 0, _Array$from2 = Array.from(this.subscribers.entries()); _i4 < _Array$from2.length; _i4++) {
|
1984
|
+
_Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), subscriberId = _Array$from2$_i[0], subscriberModules = _Array$from2$_i[1];
|
1985
|
+
if (subscriberModules[path]) {
|
1986
|
+
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
1987
|
+
this.emitChange(subscriberId);
|
1988
|
+
}
|
1989
|
+
}
|
1990
|
+
}
|
1991
|
+
} else {
|
1992
|
+
console.error("Val: failed to reset", data.error);
|
1993
|
+
}
|
1994
|
+
case 13:
|
1995
|
+
case "end":
|
1996
|
+
return _context2.stop();
|
1997
|
+
}
|
1998
|
+
}, _callee2, this);
|
1999
|
+
}));
|
1932
2000
|
function reset() {
|
1933
2001
|
return _reset.apply(this, arguments);
|
1934
2002
|
}
|
@@ -1937,37 +2005,37 @@ var ValStore = /*#__PURE__*/function () {
|
|
1937
2005
|
}, {
|
1938
2006
|
key: "getModule",
|
1939
2007
|
value: function () {
|
1940
|
-
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2008
|
+
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path) {
|
1941
2009
|
var refetch,
|
1942
2010
|
data,
|
1943
2011
|
fetchedSource,
|
1944
2012
|
schema,
|
1945
|
-
|
1946
|
-
return _regeneratorRuntime().wrap(function
|
1947
|
-
while (1) switch (
|
2013
|
+
_args3 = arguments;
|
2014
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
2015
|
+
while (1) switch (_context3.prev = _context3.next) {
|
1948
2016
|
case 0:
|
1949
|
-
refetch =
|
2017
|
+
refetch = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
|
1950
2018
|
if (!(!refetch && this.drafts[path] && this.schema[path])) {
|
1951
|
-
|
2019
|
+
_context3.next = 3;
|
1952
2020
|
break;
|
1953
2021
|
}
|
1954
|
-
return
|
2022
|
+
return _context3.abrupt("return", fp.result.ok({
|
1955
2023
|
source: this.drafts[path],
|
1956
2024
|
schema: this.schema[path]
|
1957
2025
|
}));
|
1958
2026
|
case 3:
|
1959
|
-
|
2027
|
+
_context3.next = 5;
|
1960
2028
|
return this.api.putTree({
|
1961
2029
|
treePath: path
|
1962
2030
|
});
|
1963
2031
|
case 5:
|
1964
|
-
data =
|
2032
|
+
data = _context3.sent;
|
1965
2033
|
if (!fp.result.isOk(data)) {
|
1966
|
-
|
2034
|
+
_context3.next = 26;
|
1967
2035
|
break;
|
1968
2036
|
}
|
1969
2037
|
if (data.value.modules[path]) {
|
1970
|
-
|
2038
|
+
_context3.next = 10;
|
1971
2039
|
break;
|
1972
2040
|
}
|
1973
2041
|
console.error("Val: could not find the module", {
|
@@ -1975,65 +2043,65 @@ var ValStore = /*#__PURE__*/function () {
|
|
1975
2043
|
moduleId: path,
|
1976
2044
|
data: data
|
1977
2045
|
});
|
1978
|
-
return
|
2046
|
+
return _context3.abrupt("return", fp.result.err({
|
1979
2047
|
message: "Could not fetch data.\nCould not find the module:\n" + path + "\n\nVerify that the val.modules file includes this module."
|
1980
2048
|
}));
|
1981
2049
|
case 10:
|
1982
2050
|
fetchedSource = data.value.modules[path].source;
|
1983
2051
|
schema = this.schema[path];
|
1984
2052
|
if (this.schema[path]) {
|
1985
|
-
|
2053
|
+
_context3.next = 17;
|
1986
2054
|
break;
|
1987
2055
|
}
|
1988
|
-
|
2056
|
+
_context3.next = 15;
|
1989
2057
|
return this.initialize();
|
1990
2058
|
case 15:
|
1991
2059
|
if (this.schema[path]) {
|
1992
|
-
|
2060
|
+
_context3.next = 17;
|
1993
2061
|
break;
|
1994
2062
|
}
|
1995
|
-
return
|
2063
|
+
return _context3.abrupt("return", fp.result.err({
|
1996
2064
|
message: "Path not found in schema. Verify that the module exists."
|
1997
2065
|
}));
|
1998
2066
|
case 17:
|
1999
2067
|
if (!(fetchedSource !== undefined)) {
|
2000
|
-
|
2068
|
+
_context3.next = 22;
|
2001
2069
|
break;
|
2002
2070
|
}
|
2003
2071
|
this.drafts[path] = fetchedSource;
|
2004
|
-
return
|
2072
|
+
return _context3.abrupt("return", fp.result.ok({
|
2005
2073
|
source: fetchedSource,
|
2006
2074
|
schema: schema
|
2007
2075
|
}));
|
2008
2076
|
case 22:
|
2009
2077
|
console.error("Val: could not find the module source");
|
2010
|
-
return
|
2078
|
+
return _context3.abrupt("return", fp.result.err({
|
2011
2079
|
message: "Could not fetch data. Verify that the module exists."
|
2012
2080
|
}));
|
2013
2081
|
case 24:
|
2014
|
-
|
2082
|
+
_context3.next = 33;
|
2015
2083
|
break;
|
2016
2084
|
case 26:
|
2017
2085
|
if (!(data.error.statusCode === 504)) {
|
2018
|
-
|
2086
|
+
_context3.next = 31;
|
2019
2087
|
break;
|
2020
2088
|
}
|
2021
2089
|
console.error("Val: timeout", data.error);
|
2022
|
-
return
|
2090
|
+
return _context3.abrupt("return", fp.result.err({
|
2023
2091
|
message: "Timed out while fetching data. Try again later."
|
2024
2092
|
}));
|
2025
2093
|
case 31:
|
2026
2094
|
console.error("Val: failed to get module", data.error);
|
2027
|
-
return
|
2095
|
+
return _context3.abrupt("return", fp.result.err({
|
2028
2096
|
message: "Could not fetch data. Verify that Val is correctly configured."
|
2029
2097
|
}));
|
2030
2098
|
case 33:
|
2031
2099
|
case "end":
|
2032
|
-
return
|
2100
|
+
return _context3.stop();
|
2033
2101
|
}
|
2034
|
-
},
|
2102
|
+
}, _callee3, this);
|
2035
2103
|
}));
|
2036
|
-
function getModule(
|
2104
|
+
function getModule(_x2) {
|
2037
2105
|
return _getModule.apply(this, arguments);
|
2038
2106
|
}
|
2039
2107
|
return getModule;
|
@@ -2041,12 +2109,12 @@ var ValStore = /*#__PURE__*/function () {
|
|
2041
2109
|
}, {
|
2042
2110
|
key: "applyPatch",
|
2043
2111
|
value: function () {
|
2044
|
-
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2045
|
-
var data, fetchedSource, _data$value$modules$p,
|
2046
|
-
return _regeneratorRuntime().wrap(function
|
2047
|
-
while (1) switch (
|
2112
|
+
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path, patchIds, patch) {
|
2113
|
+
var data, fetchedSource, _data$value$modules$p, _i5, _Array$from3, _Array$from3$_i, subscriberId, subscriberModules;
|
2114
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
2115
|
+
while (1) switch (_context4.prev = _context4.next) {
|
2048
2116
|
case 0:
|
2049
|
-
|
2117
|
+
_context4.next = 2;
|
2050
2118
|
return this.api.putTree({
|
2051
2119
|
treePath: path,
|
2052
2120
|
patchIds: patchIds,
|
@@ -2056,48 +2124,48 @@ var ValStore = /*#__PURE__*/function () {
|
|
2056
2124
|
}
|
2057
2125
|
});
|
2058
2126
|
case 2:
|
2059
|
-
data =
|
2127
|
+
data = _context4.sent;
|
2060
2128
|
if (!fp.result.isOk(data)) {
|
2061
|
-
|
2129
|
+
_context4.next = 16;
|
2062
2130
|
break;
|
2063
2131
|
}
|
2064
2132
|
fetchedSource = data.value.modules[path].source;
|
2065
2133
|
if (!(fetchedSource !== undefined)) {
|
2066
|
-
|
2134
|
+
_context4.next = 12;
|
2067
2135
|
break;
|
2068
2136
|
}
|
2069
2137
|
this.drafts[path] = fetchedSource;
|
2070
2138
|
this.emitEvent(path, fetchedSource);
|
2071
|
-
for (
|
2072
|
-
_Array$
|
2139
|
+
for (_i5 = 0, _Array$from3 = Array.from(this.subscribers.entries()); _i5 < _Array$from3.length; _i5++) {
|
2140
|
+
_Array$from3$_i = _slicedToArray(_Array$from3[_i5], 2), subscriberId = _Array$from3$_i[0], subscriberModules = _Array$from3$_i[1];
|
2073
2141
|
if (subscriberModules[path]) {
|
2074
2142
|
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
2075
2143
|
this.emitChange(subscriberId);
|
2076
2144
|
}
|
2077
2145
|
}
|
2078
|
-
return
|
2146
|
+
return _context4.abrupt("return", fp.result.ok(_defineProperty({}, path, {
|
2079
2147
|
patchIds: ((_data$value$modules$p = data.value.modules[path].patches) === null || _data$value$modules$p === void 0 ? void 0 : _data$value$modules$p.applied) || []
|
2080
2148
|
})));
|
2081
2149
|
case 12:
|
2082
2150
|
console.error("Val: could not patch");
|
2083
|
-
return
|
2151
|
+
return _context4.abrupt("return", fp.result.err({
|
2084
2152
|
message: "Val: could not fetch data. Verify that the module exists."
|
2085
2153
|
}));
|
2086
2154
|
case 14:
|
2087
|
-
|
2155
|
+
_context4.next = 18;
|
2088
2156
|
break;
|
2089
2157
|
case 16:
|
2090
2158
|
console.error("Val: failed to get module", data.error);
|
2091
|
-
return
|
2159
|
+
return _context4.abrupt("return", fp.result.err({
|
2092
2160
|
message: "Val: could not fetch data. Verify that Val is correctly configured."
|
2093
2161
|
}));
|
2094
2162
|
case 18:
|
2095
2163
|
case "end":
|
2096
|
-
return
|
2164
|
+
return _context4.stop();
|
2097
2165
|
}
|
2098
|
-
},
|
2166
|
+
}, _callee4, this);
|
2099
2167
|
}));
|
2100
|
-
function applyPatch(
|
2168
|
+
function applyPatch(_x3, _x4, _x5) {
|
2101
2169
|
return _applyPatch.apply(this, arguments);
|
2102
2170
|
}
|
2103
2171
|
return applyPatch;
|
@@ -2117,29 +2185,29 @@ var ValStore = /*#__PURE__*/function () {
|
|
2117
2185
|
}, {
|
2118
2186
|
key: "initialize",
|
2119
2187
|
value: function () {
|
2120
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2121
|
-
var data, paths,
|
2122
|
-
return _regeneratorRuntime().wrap(function
|
2123
|
-
while (1) switch (
|
2188
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
2189
|
+
var data, paths, _i6, _arr, moduleId, schema, msg;
|
2190
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
2191
|
+
while (1) switch (_context5.prev = _context5.next) {
|
2124
2192
|
case 0:
|
2125
|
-
|
2193
|
+
_context5.next = 2;
|
2126
2194
|
return this.api.getSchema({});
|
2127
2195
|
case 2:
|
2128
|
-
data =
|
2196
|
+
data = _context5.sent;
|
2129
2197
|
if (!fp.result.isOk(data)) {
|
2130
|
-
|
2198
|
+
_context5.next = 9;
|
2131
2199
|
break;
|
2132
2200
|
}
|
2133
2201
|
paths = [];
|
2134
|
-
for (
|
2135
|
-
moduleId = _arr[
|
2202
|
+
for (_i6 = 0, _arr = Object.keys(data.value.schemas); _i6 < _arr.length; _i6++) {
|
2203
|
+
moduleId = _arr[_i6];
|
2136
2204
|
schema = data.value.schemas[moduleId];
|
2137
2205
|
if (schema) {
|
2138
2206
|
paths.push(moduleId);
|
2139
2207
|
this.schema[moduleId] = schema;
|
2140
2208
|
}
|
2141
2209
|
}
|
2142
|
-
return
|
2210
|
+
return _context5.abrupt("return", fp.result.ok(paths));
|
2143
2211
|
case 9:
|
2144
2212
|
msg = "Failed to fetch content. ";
|
2145
2213
|
if (data.error.statusCode === 401) {
|
@@ -2147,7 +2215,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
2147
2215
|
} else {
|
2148
2216
|
msg += "Get a developer to verify that Val is correctly setup.";
|
2149
2217
|
}
|
2150
|
-
return
|
2218
|
+
return _context5.abrupt("return", fp.result.err({
|
2151
2219
|
message: msg,
|
2152
2220
|
details: {
|
2153
2221
|
fetchError: data.error
|
@@ -2155,9 +2223,9 @@ var ValStore = /*#__PURE__*/function () {
|
|
2155
2223
|
}));
|
2156
2224
|
case 12:
|
2157
2225
|
case "end":
|
2158
|
-
return
|
2226
|
+
return _context5.stop();
|
2159
2227
|
}
|
2160
|
-
},
|
2228
|
+
}, _callee5, this);
|
2161
2229
|
}));
|
2162
2230
|
function initialize() {
|
2163
2231
|
return _initialize.apply(this, arguments);
|
@@ -1874,10 +1874,10 @@ var ValStore = /*#__PURE__*/function () {
|
|
1874
1874
|
this.schema = {};
|
1875
1875
|
}
|
1876
1876
|
_createClass(ValStore, [{
|
1877
|
-
key: "
|
1877
|
+
key: "reloadPaths",
|
1878
1878
|
value: function () {
|
1879
|
-
var
|
1880
|
-
var patches,
|
1879
|
+
var _reloadPaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(paths) {
|
1880
|
+
var patches, filteredPatches, data, _i, _Object$keys, pathS, path, _i2, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
|
1881
1881
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
1882
1882
|
while (1) switch (_context.prev = _context.next) {
|
1883
1883
|
case 0:
|
@@ -1892,14 +1892,21 @@ var ValStore = /*#__PURE__*/function () {
|
|
1892
1892
|
console.error("Val: failed to get patches", patches.error);
|
1893
1893
|
return _context.abrupt("return");
|
1894
1894
|
case 6:
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1895
|
+
filteredPatches = Object.entries(patches.value).flatMap(function (_ref) {
|
1896
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
1897
|
+
patchModuleFilePath = _ref2[0],
|
1898
|
+
mp = _ref2[1];
|
1899
|
+
if (paths.includes(patchModuleFilePath)) {
|
1900
|
+
return mp.map(function (p) {
|
1901
|
+
return p.patch_id;
|
1902
|
+
});
|
1903
|
+
} else {
|
1904
|
+
return [];
|
1905
|
+
}
|
1899
1906
|
});
|
1900
1907
|
_context.next = 9;
|
1901
1908
|
return this.api.putTree({
|
1902
|
-
patchIds:
|
1909
|
+
patchIds: filteredPatches
|
1903
1910
|
});
|
1904
1911
|
case 9:
|
1905
1912
|
data = _context.sent;
|
@@ -1921,7 +1928,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
1921
1928
|
}
|
1922
1929
|
}
|
1923
1930
|
} else {
|
1924
|
-
console.error("Val: failed to
|
1931
|
+
console.error("Val: failed to reload paths", paths, data.error);
|
1925
1932
|
}
|
1926
1933
|
case 13:
|
1927
1934
|
case "end":
|
@@ -1929,6 +1936,67 @@ var ValStore = /*#__PURE__*/function () {
|
|
1929
1936
|
}
|
1930
1937
|
}, _callee, this);
|
1931
1938
|
}));
|
1939
|
+
function reloadPaths(_x) {
|
1940
|
+
return _reloadPaths.apply(this, arguments);
|
1941
|
+
}
|
1942
|
+
return reloadPaths;
|
1943
|
+
}()
|
1944
|
+
}, {
|
1945
|
+
key: "reset",
|
1946
|
+
value: function () {
|
1947
|
+
var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
1948
|
+
var patches, allPatches, data, _i3, _Object$keys2, pathS, path, _i4, _Array$from2, _Array$from2$_i, subscriberId, subscriberModules;
|
1949
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
1950
|
+
while (1) switch (_context2.prev = _context2.next) {
|
1951
|
+
case 0:
|
1952
|
+
_context2.next = 2;
|
1953
|
+
return this.api.getPatches();
|
1954
|
+
case 2:
|
1955
|
+
patches = _context2.sent;
|
1956
|
+
if (!fp.result.isErr(patches)) {
|
1957
|
+
_context2.next = 6;
|
1958
|
+
break;
|
1959
|
+
}
|
1960
|
+
console.error("Val: failed to get patches", patches.error);
|
1961
|
+
return _context2.abrupt("return");
|
1962
|
+
case 6:
|
1963
|
+
allPatches = Object.values(patches.value).flatMap(function (mp) {
|
1964
|
+
return mp.map(function (p) {
|
1965
|
+
return p.patch_id;
|
1966
|
+
});
|
1967
|
+
});
|
1968
|
+
_context2.next = 9;
|
1969
|
+
return this.api.putTree({
|
1970
|
+
patchIds: allPatches
|
1971
|
+
});
|
1972
|
+
case 9:
|
1973
|
+
data = _context2.sent;
|
1974
|
+
_context2.next = 12;
|
1975
|
+
return this.initialize();
|
1976
|
+
case 12:
|
1977
|
+
if (fp.result.isOk(data)) {
|
1978
|
+
for (_i3 = 0, _Object$keys2 = Object.keys(data.value.modules); _i3 < _Object$keys2.length; _i3++) {
|
1979
|
+
pathS = _Object$keys2[_i3];
|
1980
|
+
path = pathS;
|
1981
|
+
this.drafts[path] = data.value.modules[path].source;
|
1982
|
+
this.emitEvent(path, this.drafts[path]);
|
1983
|
+
for (_i4 = 0, _Array$from2 = Array.from(this.subscribers.entries()); _i4 < _Array$from2.length; _i4++) {
|
1984
|
+
_Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), subscriberId = _Array$from2$_i[0], subscriberModules = _Array$from2$_i[1];
|
1985
|
+
if (subscriberModules[path]) {
|
1986
|
+
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
1987
|
+
this.emitChange(subscriberId);
|
1988
|
+
}
|
1989
|
+
}
|
1990
|
+
}
|
1991
|
+
} else {
|
1992
|
+
console.error("Val: failed to reset", data.error);
|
1993
|
+
}
|
1994
|
+
case 13:
|
1995
|
+
case "end":
|
1996
|
+
return _context2.stop();
|
1997
|
+
}
|
1998
|
+
}, _callee2, this);
|
1999
|
+
}));
|
1932
2000
|
function reset() {
|
1933
2001
|
return _reset.apply(this, arguments);
|
1934
2002
|
}
|
@@ -1937,37 +2005,37 @@ var ValStore = /*#__PURE__*/function () {
|
|
1937
2005
|
}, {
|
1938
2006
|
key: "getModule",
|
1939
2007
|
value: function () {
|
1940
|
-
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2008
|
+
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path) {
|
1941
2009
|
var refetch,
|
1942
2010
|
data,
|
1943
2011
|
fetchedSource,
|
1944
2012
|
schema,
|
1945
|
-
|
1946
|
-
return _regeneratorRuntime().wrap(function
|
1947
|
-
while (1) switch (
|
2013
|
+
_args3 = arguments;
|
2014
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
2015
|
+
while (1) switch (_context3.prev = _context3.next) {
|
1948
2016
|
case 0:
|
1949
|
-
refetch =
|
2017
|
+
refetch = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
|
1950
2018
|
if (!(!refetch && this.drafts[path] && this.schema[path])) {
|
1951
|
-
|
2019
|
+
_context3.next = 3;
|
1952
2020
|
break;
|
1953
2021
|
}
|
1954
|
-
return
|
2022
|
+
return _context3.abrupt("return", fp.result.ok({
|
1955
2023
|
source: this.drafts[path],
|
1956
2024
|
schema: this.schema[path]
|
1957
2025
|
}));
|
1958
2026
|
case 3:
|
1959
|
-
|
2027
|
+
_context3.next = 5;
|
1960
2028
|
return this.api.putTree({
|
1961
2029
|
treePath: path
|
1962
2030
|
});
|
1963
2031
|
case 5:
|
1964
|
-
data =
|
2032
|
+
data = _context3.sent;
|
1965
2033
|
if (!fp.result.isOk(data)) {
|
1966
|
-
|
2034
|
+
_context3.next = 26;
|
1967
2035
|
break;
|
1968
2036
|
}
|
1969
2037
|
if (data.value.modules[path]) {
|
1970
|
-
|
2038
|
+
_context3.next = 10;
|
1971
2039
|
break;
|
1972
2040
|
}
|
1973
2041
|
console.error("Val: could not find the module", {
|
@@ -1975,65 +2043,65 @@ var ValStore = /*#__PURE__*/function () {
|
|
1975
2043
|
moduleId: path,
|
1976
2044
|
data: data
|
1977
2045
|
});
|
1978
|
-
return
|
2046
|
+
return _context3.abrupt("return", fp.result.err({
|
1979
2047
|
message: "Could not fetch data.\nCould not find the module:\n" + path + "\n\nVerify that the val.modules file includes this module."
|
1980
2048
|
}));
|
1981
2049
|
case 10:
|
1982
2050
|
fetchedSource = data.value.modules[path].source;
|
1983
2051
|
schema = this.schema[path];
|
1984
2052
|
if (this.schema[path]) {
|
1985
|
-
|
2053
|
+
_context3.next = 17;
|
1986
2054
|
break;
|
1987
2055
|
}
|
1988
|
-
|
2056
|
+
_context3.next = 15;
|
1989
2057
|
return this.initialize();
|
1990
2058
|
case 15:
|
1991
2059
|
if (this.schema[path]) {
|
1992
|
-
|
2060
|
+
_context3.next = 17;
|
1993
2061
|
break;
|
1994
2062
|
}
|
1995
|
-
return
|
2063
|
+
return _context3.abrupt("return", fp.result.err({
|
1996
2064
|
message: "Path not found in schema. Verify that the module exists."
|
1997
2065
|
}));
|
1998
2066
|
case 17:
|
1999
2067
|
if (!(fetchedSource !== undefined)) {
|
2000
|
-
|
2068
|
+
_context3.next = 22;
|
2001
2069
|
break;
|
2002
2070
|
}
|
2003
2071
|
this.drafts[path] = fetchedSource;
|
2004
|
-
return
|
2072
|
+
return _context3.abrupt("return", fp.result.ok({
|
2005
2073
|
source: fetchedSource,
|
2006
2074
|
schema: schema
|
2007
2075
|
}));
|
2008
2076
|
case 22:
|
2009
2077
|
console.error("Val: could not find the module source");
|
2010
|
-
return
|
2078
|
+
return _context3.abrupt("return", fp.result.err({
|
2011
2079
|
message: "Could not fetch data. Verify that the module exists."
|
2012
2080
|
}));
|
2013
2081
|
case 24:
|
2014
|
-
|
2082
|
+
_context3.next = 33;
|
2015
2083
|
break;
|
2016
2084
|
case 26:
|
2017
2085
|
if (!(data.error.statusCode === 504)) {
|
2018
|
-
|
2086
|
+
_context3.next = 31;
|
2019
2087
|
break;
|
2020
2088
|
}
|
2021
2089
|
console.error("Val: timeout", data.error);
|
2022
|
-
return
|
2090
|
+
return _context3.abrupt("return", fp.result.err({
|
2023
2091
|
message: "Timed out while fetching data. Try again later."
|
2024
2092
|
}));
|
2025
2093
|
case 31:
|
2026
2094
|
console.error("Val: failed to get module", data.error);
|
2027
|
-
return
|
2095
|
+
return _context3.abrupt("return", fp.result.err({
|
2028
2096
|
message: "Could not fetch data. Verify that Val is correctly configured."
|
2029
2097
|
}));
|
2030
2098
|
case 33:
|
2031
2099
|
case "end":
|
2032
|
-
return
|
2100
|
+
return _context3.stop();
|
2033
2101
|
}
|
2034
|
-
},
|
2102
|
+
}, _callee3, this);
|
2035
2103
|
}));
|
2036
|
-
function getModule(
|
2104
|
+
function getModule(_x2) {
|
2037
2105
|
return _getModule.apply(this, arguments);
|
2038
2106
|
}
|
2039
2107
|
return getModule;
|
@@ -2041,12 +2109,12 @@ var ValStore = /*#__PURE__*/function () {
|
|
2041
2109
|
}, {
|
2042
2110
|
key: "applyPatch",
|
2043
2111
|
value: function () {
|
2044
|
-
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2045
|
-
var data, fetchedSource, _data$value$modules$p,
|
2046
|
-
return _regeneratorRuntime().wrap(function
|
2047
|
-
while (1) switch (
|
2112
|
+
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path, patchIds, patch) {
|
2113
|
+
var data, fetchedSource, _data$value$modules$p, _i5, _Array$from3, _Array$from3$_i, subscriberId, subscriberModules;
|
2114
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
2115
|
+
while (1) switch (_context4.prev = _context4.next) {
|
2048
2116
|
case 0:
|
2049
|
-
|
2117
|
+
_context4.next = 2;
|
2050
2118
|
return this.api.putTree({
|
2051
2119
|
treePath: path,
|
2052
2120
|
patchIds: patchIds,
|
@@ -2056,48 +2124,48 @@ var ValStore = /*#__PURE__*/function () {
|
|
2056
2124
|
}
|
2057
2125
|
});
|
2058
2126
|
case 2:
|
2059
|
-
data =
|
2127
|
+
data = _context4.sent;
|
2060
2128
|
if (!fp.result.isOk(data)) {
|
2061
|
-
|
2129
|
+
_context4.next = 16;
|
2062
2130
|
break;
|
2063
2131
|
}
|
2064
2132
|
fetchedSource = data.value.modules[path].source;
|
2065
2133
|
if (!(fetchedSource !== undefined)) {
|
2066
|
-
|
2134
|
+
_context4.next = 12;
|
2067
2135
|
break;
|
2068
2136
|
}
|
2069
2137
|
this.drafts[path] = fetchedSource;
|
2070
2138
|
this.emitEvent(path, fetchedSource);
|
2071
|
-
for (
|
2072
|
-
_Array$
|
2139
|
+
for (_i5 = 0, _Array$from3 = Array.from(this.subscribers.entries()); _i5 < _Array$from3.length; _i5++) {
|
2140
|
+
_Array$from3$_i = _slicedToArray(_Array$from3[_i5], 2), subscriberId = _Array$from3$_i[0], subscriberModules = _Array$from3$_i[1];
|
2073
2141
|
if (subscriberModules[path]) {
|
2074
2142
|
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
2075
2143
|
this.emitChange(subscriberId);
|
2076
2144
|
}
|
2077
2145
|
}
|
2078
|
-
return
|
2146
|
+
return _context4.abrupt("return", fp.result.ok(_defineProperty({}, path, {
|
2079
2147
|
patchIds: ((_data$value$modules$p = data.value.modules[path].patches) === null || _data$value$modules$p === void 0 ? void 0 : _data$value$modules$p.applied) || []
|
2080
2148
|
})));
|
2081
2149
|
case 12:
|
2082
2150
|
console.error("Val: could not patch");
|
2083
|
-
return
|
2151
|
+
return _context4.abrupt("return", fp.result.err({
|
2084
2152
|
message: "Val: could not fetch data. Verify that the module exists."
|
2085
2153
|
}));
|
2086
2154
|
case 14:
|
2087
|
-
|
2155
|
+
_context4.next = 18;
|
2088
2156
|
break;
|
2089
2157
|
case 16:
|
2090
2158
|
console.error("Val: failed to get module", data.error);
|
2091
|
-
return
|
2159
|
+
return _context4.abrupt("return", fp.result.err({
|
2092
2160
|
message: "Val: could not fetch data. Verify that Val is correctly configured."
|
2093
2161
|
}));
|
2094
2162
|
case 18:
|
2095
2163
|
case "end":
|
2096
|
-
return
|
2164
|
+
return _context4.stop();
|
2097
2165
|
}
|
2098
|
-
},
|
2166
|
+
}, _callee4, this);
|
2099
2167
|
}));
|
2100
|
-
function applyPatch(
|
2168
|
+
function applyPatch(_x3, _x4, _x5) {
|
2101
2169
|
return _applyPatch.apply(this, arguments);
|
2102
2170
|
}
|
2103
2171
|
return applyPatch;
|
@@ -2117,29 +2185,29 @@ var ValStore = /*#__PURE__*/function () {
|
|
2117
2185
|
}, {
|
2118
2186
|
key: "initialize",
|
2119
2187
|
value: function () {
|
2120
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2121
|
-
var data, paths,
|
2122
|
-
return _regeneratorRuntime().wrap(function
|
2123
|
-
while (1) switch (
|
2188
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
2189
|
+
var data, paths, _i6, _arr, moduleId, schema, msg;
|
2190
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
2191
|
+
while (1) switch (_context5.prev = _context5.next) {
|
2124
2192
|
case 0:
|
2125
|
-
|
2193
|
+
_context5.next = 2;
|
2126
2194
|
return this.api.getSchema({});
|
2127
2195
|
case 2:
|
2128
|
-
data =
|
2196
|
+
data = _context5.sent;
|
2129
2197
|
if (!fp.result.isOk(data)) {
|
2130
|
-
|
2198
|
+
_context5.next = 9;
|
2131
2199
|
break;
|
2132
2200
|
}
|
2133
2201
|
paths = [];
|
2134
|
-
for (
|
2135
|
-
moduleId = _arr[
|
2202
|
+
for (_i6 = 0, _arr = Object.keys(data.value.schemas); _i6 < _arr.length; _i6++) {
|
2203
|
+
moduleId = _arr[_i6];
|
2136
2204
|
schema = data.value.schemas[moduleId];
|
2137
2205
|
if (schema) {
|
2138
2206
|
paths.push(moduleId);
|
2139
2207
|
this.schema[moduleId] = schema;
|
2140
2208
|
}
|
2141
2209
|
}
|
2142
|
-
return
|
2210
|
+
return _context5.abrupt("return", fp.result.ok(paths));
|
2143
2211
|
case 9:
|
2144
2212
|
msg = "Failed to fetch content. ";
|
2145
2213
|
if (data.error.statusCode === 401) {
|
@@ -2147,7 +2215,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
2147
2215
|
} else {
|
2148
2216
|
msg += "Get a developer to verify that Val is correctly setup.";
|
2149
2217
|
}
|
2150
|
-
return
|
2218
|
+
return _context5.abrupt("return", fp.result.err({
|
2151
2219
|
message: msg,
|
2152
2220
|
details: {
|
2153
2221
|
fetchError: data.error
|
@@ -2155,9 +2223,9 @@ var ValStore = /*#__PURE__*/function () {
|
|
2155
2223
|
}));
|
2156
2224
|
case 12:
|
2157
2225
|
case "end":
|
2158
|
-
return
|
2226
|
+
return _context5.stop();
|
2159
2227
|
}
|
2160
|
-
},
|
2228
|
+
}, _callee5, this);
|
2161
2229
|
}));
|
2162
2230
|
function initialize() {
|
2163
2231
|
return _initialize.apply(this, arguments);
|
@@ -1870,10 +1870,10 @@ var ValStore = /*#__PURE__*/function () {
|
|
1870
1870
|
this.schema = {};
|
1871
1871
|
}
|
1872
1872
|
_createClass(ValStore, [{
|
1873
|
-
key: "
|
1873
|
+
key: "reloadPaths",
|
1874
1874
|
value: function () {
|
1875
|
-
var
|
1876
|
-
var patches,
|
1875
|
+
var _reloadPaths = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(paths) {
|
1876
|
+
var patches, filteredPatches, data, _i, _Object$keys, pathS, path, _i2, _Array$from, _Array$from$_i, subscriberId, subscriberModules;
|
1877
1877
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
1878
1878
|
while (1) switch (_context.prev = _context.next) {
|
1879
1879
|
case 0:
|
@@ -1888,14 +1888,21 @@ var ValStore = /*#__PURE__*/function () {
|
|
1888
1888
|
console.error("Val: failed to get patches", patches.error);
|
1889
1889
|
return _context.abrupt("return");
|
1890
1890
|
case 6:
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1891
|
+
filteredPatches = Object.entries(patches.value).flatMap(function (_ref) {
|
1892
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
1893
|
+
patchModuleFilePath = _ref2[0],
|
1894
|
+
mp = _ref2[1];
|
1895
|
+
if (paths.includes(patchModuleFilePath)) {
|
1896
|
+
return mp.map(function (p) {
|
1897
|
+
return p.patch_id;
|
1898
|
+
});
|
1899
|
+
} else {
|
1900
|
+
return [];
|
1901
|
+
}
|
1895
1902
|
});
|
1896
1903
|
_context.next = 9;
|
1897
1904
|
return this.api.putTree({
|
1898
|
-
patchIds:
|
1905
|
+
patchIds: filteredPatches
|
1899
1906
|
});
|
1900
1907
|
case 9:
|
1901
1908
|
data = _context.sent;
|
@@ -1917,7 +1924,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
1917
1924
|
}
|
1918
1925
|
}
|
1919
1926
|
} else {
|
1920
|
-
console.error("Val: failed to
|
1927
|
+
console.error("Val: failed to reload paths", paths, data.error);
|
1921
1928
|
}
|
1922
1929
|
case 13:
|
1923
1930
|
case "end":
|
@@ -1925,6 +1932,67 @@ var ValStore = /*#__PURE__*/function () {
|
|
1925
1932
|
}
|
1926
1933
|
}, _callee, this);
|
1927
1934
|
}));
|
1935
|
+
function reloadPaths(_x) {
|
1936
|
+
return _reloadPaths.apply(this, arguments);
|
1937
|
+
}
|
1938
|
+
return reloadPaths;
|
1939
|
+
}()
|
1940
|
+
}, {
|
1941
|
+
key: "reset",
|
1942
|
+
value: function () {
|
1943
|
+
var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
1944
|
+
var patches, allPatches, data, _i3, _Object$keys2, pathS, path, _i4, _Array$from2, _Array$from2$_i, subscriberId, subscriberModules;
|
1945
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
1946
|
+
while (1) switch (_context2.prev = _context2.next) {
|
1947
|
+
case 0:
|
1948
|
+
_context2.next = 2;
|
1949
|
+
return this.api.getPatches();
|
1950
|
+
case 2:
|
1951
|
+
patches = _context2.sent;
|
1952
|
+
if (!result.isErr(patches)) {
|
1953
|
+
_context2.next = 6;
|
1954
|
+
break;
|
1955
|
+
}
|
1956
|
+
console.error("Val: failed to get patches", patches.error);
|
1957
|
+
return _context2.abrupt("return");
|
1958
|
+
case 6:
|
1959
|
+
allPatches = Object.values(patches.value).flatMap(function (mp) {
|
1960
|
+
return mp.map(function (p) {
|
1961
|
+
return p.patch_id;
|
1962
|
+
});
|
1963
|
+
});
|
1964
|
+
_context2.next = 9;
|
1965
|
+
return this.api.putTree({
|
1966
|
+
patchIds: allPatches
|
1967
|
+
});
|
1968
|
+
case 9:
|
1969
|
+
data = _context2.sent;
|
1970
|
+
_context2.next = 12;
|
1971
|
+
return this.initialize();
|
1972
|
+
case 12:
|
1973
|
+
if (result.isOk(data)) {
|
1974
|
+
for (_i3 = 0, _Object$keys2 = Object.keys(data.value.modules); _i3 < _Object$keys2.length; _i3++) {
|
1975
|
+
pathS = _Object$keys2[_i3];
|
1976
|
+
path = pathS;
|
1977
|
+
this.drafts[path] = data.value.modules[path].source;
|
1978
|
+
this.emitEvent(path, this.drafts[path]);
|
1979
|
+
for (_i4 = 0, _Array$from2 = Array.from(this.subscribers.entries()); _i4 < _Array$from2.length; _i4++) {
|
1980
|
+
_Array$from2$_i = _slicedToArray(_Array$from2[_i4], 2), subscriberId = _Array$from2$_i[0], subscriberModules = _Array$from2$_i[1];
|
1981
|
+
if (subscriberModules[path]) {
|
1982
|
+
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
1983
|
+
this.emitChange(subscriberId);
|
1984
|
+
}
|
1985
|
+
}
|
1986
|
+
}
|
1987
|
+
} else {
|
1988
|
+
console.error("Val: failed to reset", data.error);
|
1989
|
+
}
|
1990
|
+
case 13:
|
1991
|
+
case "end":
|
1992
|
+
return _context2.stop();
|
1993
|
+
}
|
1994
|
+
}, _callee2, this);
|
1995
|
+
}));
|
1928
1996
|
function reset() {
|
1929
1997
|
return _reset.apply(this, arguments);
|
1930
1998
|
}
|
@@ -1933,37 +2001,37 @@ var ValStore = /*#__PURE__*/function () {
|
|
1933
2001
|
}, {
|
1934
2002
|
key: "getModule",
|
1935
2003
|
value: function () {
|
1936
|
-
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2004
|
+
var _getModule = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(path) {
|
1937
2005
|
var refetch,
|
1938
2006
|
data,
|
1939
2007
|
fetchedSource,
|
1940
2008
|
schema,
|
1941
|
-
|
1942
|
-
return _regeneratorRuntime().wrap(function
|
1943
|
-
while (1) switch (
|
2009
|
+
_args3 = arguments;
|
2010
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
2011
|
+
while (1) switch (_context3.prev = _context3.next) {
|
1944
2012
|
case 0:
|
1945
|
-
refetch =
|
2013
|
+
refetch = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
|
1946
2014
|
if (!(!refetch && this.drafts[path] && this.schema[path])) {
|
1947
|
-
|
2015
|
+
_context3.next = 3;
|
1948
2016
|
break;
|
1949
2017
|
}
|
1950
|
-
return
|
2018
|
+
return _context3.abrupt("return", result.ok({
|
1951
2019
|
source: this.drafts[path],
|
1952
2020
|
schema: this.schema[path]
|
1953
2021
|
}));
|
1954
2022
|
case 3:
|
1955
|
-
|
2023
|
+
_context3.next = 5;
|
1956
2024
|
return this.api.putTree({
|
1957
2025
|
treePath: path
|
1958
2026
|
});
|
1959
2027
|
case 5:
|
1960
|
-
data =
|
2028
|
+
data = _context3.sent;
|
1961
2029
|
if (!result.isOk(data)) {
|
1962
|
-
|
2030
|
+
_context3.next = 26;
|
1963
2031
|
break;
|
1964
2032
|
}
|
1965
2033
|
if (data.value.modules[path]) {
|
1966
|
-
|
2034
|
+
_context3.next = 10;
|
1967
2035
|
break;
|
1968
2036
|
}
|
1969
2037
|
console.error("Val: could not find the module", {
|
@@ -1971,65 +2039,65 @@ var ValStore = /*#__PURE__*/function () {
|
|
1971
2039
|
moduleId: path,
|
1972
2040
|
data: data
|
1973
2041
|
});
|
1974
|
-
return
|
2042
|
+
return _context3.abrupt("return", result.err({
|
1975
2043
|
message: "Could not fetch data.\nCould not find the module:\n" + path + "\n\nVerify that the val.modules file includes this module."
|
1976
2044
|
}));
|
1977
2045
|
case 10:
|
1978
2046
|
fetchedSource = data.value.modules[path].source;
|
1979
2047
|
schema = this.schema[path];
|
1980
2048
|
if (this.schema[path]) {
|
1981
|
-
|
2049
|
+
_context3.next = 17;
|
1982
2050
|
break;
|
1983
2051
|
}
|
1984
|
-
|
2052
|
+
_context3.next = 15;
|
1985
2053
|
return this.initialize();
|
1986
2054
|
case 15:
|
1987
2055
|
if (this.schema[path]) {
|
1988
|
-
|
2056
|
+
_context3.next = 17;
|
1989
2057
|
break;
|
1990
2058
|
}
|
1991
|
-
return
|
2059
|
+
return _context3.abrupt("return", result.err({
|
1992
2060
|
message: "Path not found in schema. Verify that the module exists."
|
1993
2061
|
}));
|
1994
2062
|
case 17:
|
1995
2063
|
if (!(fetchedSource !== undefined)) {
|
1996
|
-
|
2064
|
+
_context3.next = 22;
|
1997
2065
|
break;
|
1998
2066
|
}
|
1999
2067
|
this.drafts[path] = fetchedSource;
|
2000
|
-
return
|
2068
|
+
return _context3.abrupt("return", result.ok({
|
2001
2069
|
source: fetchedSource,
|
2002
2070
|
schema: schema
|
2003
2071
|
}));
|
2004
2072
|
case 22:
|
2005
2073
|
console.error("Val: could not find the module source");
|
2006
|
-
return
|
2074
|
+
return _context3.abrupt("return", result.err({
|
2007
2075
|
message: "Could not fetch data. Verify that the module exists."
|
2008
2076
|
}));
|
2009
2077
|
case 24:
|
2010
|
-
|
2078
|
+
_context3.next = 33;
|
2011
2079
|
break;
|
2012
2080
|
case 26:
|
2013
2081
|
if (!(data.error.statusCode === 504)) {
|
2014
|
-
|
2082
|
+
_context3.next = 31;
|
2015
2083
|
break;
|
2016
2084
|
}
|
2017
2085
|
console.error("Val: timeout", data.error);
|
2018
|
-
return
|
2086
|
+
return _context3.abrupt("return", result.err({
|
2019
2087
|
message: "Timed out while fetching data. Try again later."
|
2020
2088
|
}));
|
2021
2089
|
case 31:
|
2022
2090
|
console.error("Val: failed to get module", data.error);
|
2023
|
-
return
|
2091
|
+
return _context3.abrupt("return", result.err({
|
2024
2092
|
message: "Could not fetch data. Verify that Val is correctly configured."
|
2025
2093
|
}));
|
2026
2094
|
case 33:
|
2027
2095
|
case "end":
|
2028
|
-
return
|
2096
|
+
return _context3.stop();
|
2029
2097
|
}
|
2030
|
-
},
|
2098
|
+
}, _callee3, this);
|
2031
2099
|
}));
|
2032
|
-
function getModule(
|
2100
|
+
function getModule(_x2) {
|
2033
2101
|
return _getModule.apply(this, arguments);
|
2034
2102
|
}
|
2035
2103
|
return getModule;
|
@@ -2037,12 +2105,12 @@ var ValStore = /*#__PURE__*/function () {
|
|
2037
2105
|
}, {
|
2038
2106
|
key: "applyPatch",
|
2039
2107
|
value: function () {
|
2040
|
-
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2041
|
-
var data, fetchedSource, _data$value$modules$p,
|
2042
|
-
return _regeneratorRuntime().wrap(function
|
2043
|
-
while (1) switch (
|
2108
|
+
var _applyPatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(path, patchIds, patch) {
|
2109
|
+
var data, fetchedSource, _data$value$modules$p, _i5, _Array$from3, _Array$from3$_i, subscriberId, subscriberModules;
|
2110
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
2111
|
+
while (1) switch (_context4.prev = _context4.next) {
|
2044
2112
|
case 0:
|
2045
|
-
|
2113
|
+
_context4.next = 2;
|
2046
2114
|
return this.api.putTree({
|
2047
2115
|
treePath: path,
|
2048
2116
|
patchIds: patchIds,
|
@@ -2052,48 +2120,48 @@ var ValStore = /*#__PURE__*/function () {
|
|
2052
2120
|
}
|
2053
2121
|
});
|
2054
2122
|
case 2:
|
2055
|
-
data =
|
2123
|
+
data = _context4.sent;
|
2056
2124
|
if (!result.isOk(data)) {
|
2057
|
-
|
2125
|
+
_context4.next = 16;
|
2058
2126
|
break;
|
2059
2127
|
}
|
2060
2128
|
fetchedSource = data.value.modules[path].source;
|
2061
2129
|
if (!(fetchedSource !== undefined)) {
|
2062
|
-
|
2130
|
+
_context4.next = 12;
|
2063
2131
|
break;
|
2064
2132
|
}
|
2065
2133
|
this.drafts[path] = fetchedSource;
|
2066
2134
|
this.emitEvent(path, fetchedSource);
|
2067
|
-
for (
|
2068
|
-
_Array$
|
2135
|
+
for (_i5 = 0, _Array$from3 = Array.from(this.subscribers.entries()); _i5 < _Array$from3.length; _i5++) {
|
2136
|
+
_Array$from3$_i = _slicedToArray(_Array$from3[_i5], 2), subscriberId = _Array$from3$_i[0], subscriberModules = _Array$from3$_i[1];
|
2069
2137
|
if (subscriberModules[path]) {
|
2070
2138
|
this.subscribers.set(subscriberId, _objectSpread2(_objectSpread2({}, subscriberModules), {}, _defineProperty({}, path, this.drafts[path])));
|
2071
2139
|
this.emitChange(subscriberId);
|
2072
2140
|
}
|
2073
2141
|
}
|
2074
|
-
return
|
2142
|
+
return _context4.abrupt("return", result.ok(_defineProperty({}, path, {
|
2075
2143
|
patchIds: ((_data$value$modules$p = data.value.modules[path].patches) === null || _data$value$modules$p === void 0 ? void 0 : _data$value$modules$p.applied) || []
|
2076
2144
|
})));
|
2077
2145
|
case 12:
|
2078
2146
|
console.error("Val: could not patch");
|
2079
|
-
return
|
2147
|
+
return _context4.abrupt("return", result.err({
|
2080
2148
|
message: "Val: could not fetch data. Verify that the module exists."
|
2081
2149
|
}));
|
2082
2150
|
case 14:
|
2083
|
-
|
2151
|
+
_context4.next = 18;
|
2084
2152
|
break;
|
2085
2153
|
case 16:
|
2086
2154
|
console.error("Val: failed to get module", data.error);
|
2087
|
-
return
|
2155
|
+
return _context4.abrupt("return", result.err({
|
2088
2156
|
message: "Val: could not fetch data. Verify that Val is correctly configured."
|
2089
2157
|
}));
|
2090
2158
|
case 18:
|
2091
2159
|
case "end":
|
2092
|
-
return
|
2160
|
+
return _context4.stop();
|
2093
2161
|
}
|
2094
|
-
},
|
2162
|
+
}, _callee4, this);
|
2095
2163
|
}));
|
2096
|
-
function applyPatch(
|
2164
|
+
function applyPatch(_x3, _x4, _x5) {
|
2097
2165
|
return _applyPatch.apply(this, arguments);
|
2098
2166
|
}
|
2099
2167
|
return applyPatch;
|
@@ -2113,29 +2181,29 @@ var ValStore = /*#__PURE__*/function () {
|
|
2113
2181
|
}, {
|
2114
2182
|
key: "initialize",
|
2115
2183
|
value: function () {
|
2116
|
-
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
2117
|
-
var data, paths,
|
2118
|
-
return _regeneratorRuntime().wrap(function
|
2119
|
-
while (1) switch (
|
2184
|
+
var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
2185
|
+
var data, paths, _i6, _arr, moduleId, schema, msg;
|
2186
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
2187
|
+
while (1) switch (_context5.prev = _context5.next) {
|
2120
2188
|
case 0:
|
2121
|
-
|
2189
|
+
_context5.next = 2;
|
2122
2190
|
return this.api.getSchema({});
|
2123
2191
|
case 2:
|
2124
|
-
data =
|
2192
|
+
data = _context5.sent;
|
2125
2193
|
if (!result.isOk(data)) {
|
2126
|
-
|
2194
|
+
_context5.next = 9;
|
2127
2195
|
break;
|
2128
2196
|
}
|
2129
2197
|
paths = [];
|
2130
|
-
for (
|
2131
|
-
moduleId = _arr[
|
2198
|
+
for (_i6 = 0, _arr = Object.keys(data.value.schemas); _i6 < _arr.length; _i6++) {
|
2199
|
+
moduleId = _arr[_i6];
|
2132
2200
|
schema = data.value.schemas[moduleId];
|
2133
2201
|
if (schema) {
|
2134
2202
|
paths.push(moduleId);
|
2135
2203
|
this.schema[moduleId] = schema;
|
2136
2204
|
}
|
2137
2205
|
}
|
2138
|
-
return
|
2206
|
+
return _context5.abrupt("return", result.ok(paths));
|
2139
2207
|
case 9:
|
2140
2208
|
msg = "Failed to fetch content. ";
|
2141
2209
|
if (data.error.statusCode === 401) {
|
@@ -2143,7 +2211,7 @@ var ValStore = /*#__PURE__*/function () {
|
|
2143
2211
|
} else {
|
2144
2212
|
msg += "Get a developer to verify that Val is correctly setup.";
|
2145
2213
|
}
|
2146
|
-
return
|
2214
|
+
return _context5.abrupt("return", result.err({
|
2147
2215
|
message: msg,
|
2148
2216
|
details: {
|
2149
2217
|
fetchError: data.error
|
@@ -2151,9 +2219,9 @@ var ValStore = /*#__PURE__*/function () {
|
|
2151
2219
|
}));
|
2152
2220
|
case 12:
|
2153
2221
|
case "end":
|
2154
|
-
return
|
2222
|
+
return _context5.stop();
|
2155
2223
|
}
|
2156
|
-
},
|
2224
|
+
}, _callee5, this);
|
2157
2225
|
}));
|
2158
2226
|
function initialize() {
|
2159
2227
|
return _initialize.apply(this, arguments);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/shared",
|
3
|
-
"version": "0.63.
|
3
|
+
"version": "0.63.1",
|
4
4
|
"private": false,
|
5
5
|
"description": "Val shared types and utilities",
|
6
6
|
"scripts": {
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"exports": true
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@valbuild/core": "~0.63.
|
32
|
+
"@valbuild/core": "~0.63.1",
|
33
33
|
"marked": "^9.0.3",
|
34
34
|
"zod": "^3.22.4"
|
35
35
|
},
|