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